titan-asic.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507
  1. /*
  2. * Copyright 2014 Vitalii Demianets
  3. * Copyright 2014 KnCMiner
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License as published by the Free
  7. * Software Foundation; either version 3 of the License, or (at your option)
  8. * any later version. See COPYING for more details.
  9. */
  10. #include <zlib.h>
  11. #include "miner.h"
  12. #include "logging.h"
  13. #include "lowl-spi.h"
  14. #include "titan-asic.h"
  15. /* ASIC Command codes */
  16. #define KNC_ASIC_CMD_GETINFO 0x80
  17. #define KNC_ASIC_CMD_REPORT 0x82
  18. #define KNC_ASIC_CMD_SETWORK 0x81
  19. #define KNC_ASIC_CMD_SETWORK_URGENT 0x83
  20. #define KNC_ASIC_CMD_SETUP_CORE 0x87
  21. /* Error bits */
  22. #define ERR_SEND_CRC_FAIL (1 << 0)
  23. #define ERR_RCV_CRC_FAIL (1 << 1)
  24. #define ERR_BAD_RESPONSE (1 << 2)
  25. #define ERR_OTHER_ERR (1 << 31)
  26. #define CRC32_SIZE 4
  27. /* In SPI responses after crc goes trailer: status(1 byte) + address(3 bytes) */
  28. #define SPI_RESPONSE_TRAILER_SIZE 4
  29. #define RCV_STATUS_NOFLAGS 0x81
  30. #define RCV_STATUS_ACCEPTED_WORK (1 << 2)
  31. #define RCV_STATUS_SEND_CRC_BAD (1 << 5)
  32. /* send_size - size of send_buf, without crc
  33. * transfer_size - total size of transfer
  34. */
  35. static uint8_t * spi_transfer(struct spi_port * const spi, uint8_t *send_buf, int send_size, int transfer_size, int rcv_crc_data_len, uint32_t *errors, bool *work_accepted)
  36. {
  37. uint8_t *rxbuf, crcbuf[CRC32_SIZE];
  38. uint32_t crc;
  39. uint8_t rcv_status;
  40. int min_transfer_size = send_size + CRC32_SIZE + SPI_RESPONSE_TRAILER_SIZE;
  41. if (0 < rcv_crc_data_len) {
  42. if (min_transfer_size < (4 + rcv_crc_data_len + CRC32_SIZE + SPI_RESPONSE_TRAILER_SIZE))
  43. min_transfer_size = 4 + rcv_crc_data_len + CRC32_SIZE + SPI_RESPONSE_TRAILER_SIZE;
  44. }
  45. *errors = 0;
  46. *work_accepted = false;
  47. if (transfer_size < min_transfer_size) {
  48. exit_other_error:
  49. *errors |= ERR_OTHER_ERR;
  50. return NULL;
  51. }
  52. spi_clear_buf(spi);
  53. spi_emit_buf(spi, send_buf, send_size);
  54. crc = crc32(0, Z_NULL, 0);
  55. crc = crc32(crc, send_buf, send_size);
  56. *((uint32_t *)crcbuf) = htobe32(crc);
  57. spi_emit_buf(spi, crcbuf, CRC32_SIZE);
  58. spi_emit_nop(spi, transfer_size - spi_getbufsz(spi));
  59. if (!spi_txrx(spi))
  60. goto exit_other_error;
  61. rxbuf = spi_getrxbuf(spi);
  62. rcv_status = rxbuf[transfer_size - SPI_RESPONSE_TRAILER_SIZE];
  63. if (RCV_STATUS_NOFLAGS != (rcv_status & (~(RCV_STATUS_SEND_CRC_BAD | RCV_STATUS_ACCEPTED_WORK))))
  64. *errors |= ERR_BAD_RESPONSE;
  65. if (rcv_status & RCV_STATUS_SEND_CRC_BAD)
  66. *errors |= ERR_SEND_CRC_FAIL;
  67. if (0 < rcv_crc_data_len) {
  68. crc = crc32(0, Z_NULL, 0);
  69. crc = crc32(crc, rxbuf + 4, rcv_crc_data_len);
  70. memcpy(crcbuf, &rxbuf[4 + rcv_crc_data_len], CRC32_SIZE);
  71. if (crc != be32toh(*((uint32_t *)crcbuf)))
  72. *errors |= ERR_RCV_CRC_FAIL;
  73. }
  74. *work_accepted = ((0 == *errors) && (rcv_status & RCV_STATUS_ACCEPTED_WORK));
  75. #if 0
  76. {
  77. uint8_t *txbuf = spi_gettxbuf(spi);
  78. char str[8192];
  79. int i, n;
  80. n = 0;
  81. for (i = 0; i < transfer_size; ++i)
  82. n += sprintf(&str[n], i ? ",0x%02hhX" : "0x%02hhX", txbuf[i]);
  83. applog(LOG_NOTICE, "TX: %s", str);
  84. n = 0;
  85. for (i = 0; i < transfer_size; ++i)
  86. n += sprintf(&str[n], i ? ",0x%02hhX" : "0x%02hhX", rxbuf[i]);
  87. applog(LOG_NOTICE, "RX: %s", str);
  88. if (0 < rcv_crc_data_len)
  89. applog(LOG_NOTICE, "RX-CRC: 0x%08X", crc);
  90. }
  91. #endif
  92. return rxbuf;
  93. }
  94. /*
  95. * core_hint - which number of cores is expected. The function needs to know it to
  96. * calculate the SPI transfer size. It uses this hint for the first transfer.
  97. * If the first transfer fails, it assumes that it is because of wrong hint and
  98. * then tries to detect right number of cores from the first response.
  99. */
  100. bool knc_titan_spi_get_info(const char *repr, struct spi_port * const spi, struct titan_info_response *resp, int die, int core_hint)
  101. {
  102. uint8_t get_info_cmd[] = {KNC_ASIC_CMD_GETINFO, die, 0x00, 0x00};
  103. uint8_t *rxbuf;
  104. uint32_t errors;
  105. uint16_t revision;
  106. int transfer_size = 24 + ((core_hint + 3) / 4);
  107. int i, core;
  108. bool unused;
  109. for (i = 0; i < 3; ++i) {
  110. rxbuf = spi_transfer(spi, get_info_cmd, sizeof(get_info_cmd), transfer_size, transfer_size - 4 - CRC32_SIZE - SPI_RESPONSE_TRAILER_SIZE, &errors, &unused);
  111. if (NULL == rxbuf) {
  112. exit_unrec_error: applog(LOG_ERR, "%s[%d] knc_titan_spi_get_info: Unrecognized error", repr, die);
  113. return false;
  114. }
  115. if (errors != ERR_SEND_CRC_FAIL)
  116. break;
  117. /* If the only error is SEND_CRC, assume there was a communication error
  118. * and retry three times
  119. */
  120. }
  121. if (ERR_SEND_CRC_FAIL == errors) {
  122. applog(LOG_ERR, "%s[%d] knc_titan_spi_get_info: CRC error in Tx", repr, die);
  123. return false;
  124. }
  125. if (0 != errors) {
  126. /* It might be that we have different number of cores. Try to guess it
  127. * from partial response.
  128. */
  129. revision = (rxbuf[6] << 8) | rxbuf[7];
  130. if (KNC_TITAN_ASIC_REVISION != revision) {
  131. exit_bad_revision: applog(LOG_ERR, "%s[%d] knc_titan_spi_get_info: Bad revision 0x%04hX", repr, die, revision);
  132. return false;
  133. }
  134. resp->cores = (rxbuf[4] << 8) | rxbuf[5];
  135. if (resp->cores != core_hint) {
  136. applog(LOG_NOTICE, "%s[%d] core hint %d might be wrong, new guess is %d", repr, die, core_hint, resp->cores);
  137. transfer_size = 24 + ((resp->cores + 3) / 4);
  138. for (i = 0; i < 3; ++i) {
  139. rxbuf = spi_transfer(spi, get_info_cmd, sizeof(get_info_cmd), transfer_size, transfer_size - 4 - CRC32_SIZE - SPI_RESPONSE_TRAILER_SIZE, &errors, &unused);
  140. if (NULL == rxbuf)
  141. goto exit_unrec_error;
  142. if (errors != ERR_SEND_CRC_FAIL)
  143. break;
  144. /* If the only error is SEND_CRC, assume there was a communication error
  145. * and retry three times
  146. */
  147. }
  148. }
  149. }
  150. if (0 != errors) {
  151. applog(LOG_ERR, "%s[%d] knc_titan_spi_get_info: Communication failed, errors = 0x%X", repr, die, errors);
  152. return false;
  153. }
  154. revision = (rxbuf[6] << 8) | rxbuf[7];
  155. if (KNC_TITAN_ASIC_REVISION != revision)
  156. goto exit_bad_revision;
  157. resp->cores = (rxbuf[4] << 8) | rxbuf[5];
  158. resp->pll_state = *((uint64_t *)(&rxbuf[8]));
  159. for (core = 0; core < resp->cores; ) {
  160. uint8_t data = rxbuf[16 + (core / 4)];
  161. resp->want_work[core] = !!(data & (1 << 7));
  162. resp->have_report[core] = !!(data & (1 << 6));
  163. if (++core >= resp->cores)
  164. break;
  165. resp->want_work[core] = !!(data & (1 << 5));
  166. resp->have_report[core] = !!(data & (1 << 4));
  167. if (++core >= resp->cores)
  168. break;
  169. resp->want_work[core] = !!(data & (1 << 3));
  170. resp->have_report[core] = !!(data & (1 << 2));
  171. if (++core >= resp->cores)
  172. break;
  173. resp->want_work[core] = !!(data & (1 << 1));
  174. resp->have_report[core] = !!(data & (1 << 0));
  175. if (++core >= resp->cores)
  176. break;
  177. }
  178. return true;
  179. }
  180. static void knc_titan_parse_get_report(uint8_t *data, struct titan_report *report)
  181. {
  182. int i;
  183. report->flags = data[0];
  184. report->core_counter = data[1];
  185. report->slot_core = (data[2] >> 4) & 0x0F;
  186. for (i = 0; i < KNC_TITAN_NONCES_PER_REPORT; ++i) {
  187. report->nonces[i].slot = data[2 + i * 5] & 0x0F;
  188. report->nonces[i].nonce = ((uint32_t)data[2 + i * 5 + 1] << 24) |
  189. ((uint32_t)data[2 + i * 5 + 2] << 16) |
  190. ((uint32_t)data[2 + i * 5 + 3] << 8) |
  191. ((uint32_t)data[2 + i * 5 + 4]);
  192. }
  193. }
  194. bool knc_titan_set_work(const char *repr, struct spi_port * const spi, struct titan_report *report, int die, int core, int slot, struct work *work, bool urgent, bool *work_accepted)
  195. {
  196. #define SETWORK_CMD_SIZE (5 + BLOCK_HEADER_BYTES_WITHOUT_NONCE)
  197. uint8_t set_work_cmd_aligned[3 + SETWORK_CMD_SIZE] = {
  198. 0, 0, 0, /* three extra bytes for alignment */
  199. urgent ? KNC_ASIC_CMD_SETWORK_URGENT : KNC_ASIC_CMD_SETWORK,
  200. die,
  201. (core >> 8) & 0xFF,
  202. core & 0xFF,
  203. 0xF0 | (slot & 0x0F),
  204. /* next follows data. Thanks to the first three extra bytes it is 64bit-aligned */
  205. };
  206. const int send_size = sizeof(set_work_cmd_aligned) - 3;
  207. const int transfer_size = send_size + CRC32_SIZE + SPI_RESPONSE_TRAILER_SIZE;
  208. uint8_t *rxbuf;
  209. int i;
  210. uint32_t *src, *dst;
  211. uint32_t errors;
  212. if (NULL != work) {
  213. src = (uint32_t *)work->data;
  214. dst = (uint32_t *)(&set_work_cmd_aligned[3 + 5]);
  215. for (i = 0; i < (BLOCK_HEADER_BYTES_WITHOUT_NONCE / 4); ++i)
  216. dst[i] = htobe32(src[i]);
  217. } else {
  218. /* Empty work is allowed only for the "purge" (slot = 0) operation */
  219. if (0 != slot) {
  220. applog(LOG_ERR, "%s[%d:%d] knc_titan_set_work: Invalid work", repr, die, core);
  221. return false;
  222. }
  223. }
  224. rxbuf = spi_transfer(spi, &set_work_cmd_aligned[3], send_size, transfer_size, 2 + KNC_TITAN_NONCES_PER_REPORT * 5, &errors, work_accepted);
  225. if (NULL == rxbuf) {
  226. applog(LOG_ERR, "%s[%d:%d] knc_titan_set_work: Unrecognized error", repr, die, core);
  227. return false;
  228. }
  229. if (0 != errors) {
  230. applog(LOG_ERR, "%s[%d:%d] knc_titan_set_work: Communication failed, errors = 0x%X", repr, die, core, errors);
  231. return false;
  232. }
  233. knc_titan_parse_get_report(&rxbuf[4], report);
  234. return true;
  235. }
  236. bool knc_titan_get_report(const char *repr, struct spi_port * const spi, struct titan_report *report, int die, int core)
  237. {
  238. uint8_t get_report_cmd[] = {KNC_ASIC_CMD_REPORT, die, (core >> 8) & 0xFF, core & 0xFF};
  239. const int send_size = sizeof(get_report_cmd);
  240. const int transfer_size = send_size + 2 + KNC_TITAN_NONCES_PER_REPORT * 5 + CRC32_SIZE + SPI_RESPONSE_TRAILER_SIZE;
  241. uint8_t *rxbuf;
  242. uint32_t errors;
  243. bool unused;
  244. rxbuf = spi_transfer(spi, get_report_cmd, send_size, transfer_size, 2 + KNC_TITAN_NONCES_PER_REPORT * 5, &errors, &unused);
  245. if (NULL == rxbuf) {
  246. applog(LOG_ERR, "%s[%d:%d] knc_titan_get_report: Unrecognized error", repr, die, core);
  247. return false;
  248. }
  249. if (0 != errors) {
  250. applog(LOG_ERR, "%s[%d:%d] knc_titan_get_report: Communication failed, errors = 0x%X", repr, die, core, errors);
  251. return false;
  252. }
  253. knc_titan_parse_get_report(&rxbuf[4], report);
  254. return true;
  255. }
  256. bool knc_titan_setup_core(const char *repr, struct spi_port * const spi, struct titan_setup_core_params *params, int die, int core)
  257. {
  258. /* The size of command is the same as for set_work */
  259. uint8_t setup_core_cmd[SETWORK_CMD_SIZE] = {
  260. KNC_ASIC_CMD_SETUP_CORE,
  261. die,
  262. (core >> 8) & 0xFF,
  263. core & 0xFF,
  264. /* next follows padding and data */
  265. };
  266. const int send_size = sizeof(setup_core_cmd);
  267. const int transfer_size = send_size + CRC32_SIZE + SPI_RESPONSE_TRAILER_SIZE;
  268. uint8_t *rxbuf;
  269. uint32_t errors;
  270. bool unused;
  271. uint32_t *src, *dst;
  272. int i;
  273. struct titan_packed_core_params {
  274. /* WORD [0] */
  275. #if (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
  276. uint32_t padding :26;
  277. uint32_t bad_address_mask_0_6msb :6;
  278. #else
  279. uint32_t bad_address_mask_0_6msb :6;
  280. uint32_t padding :26;
  281. #endif
  282. /* WORD [1] */
  283. #if (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
  284. uint32_t bad_address_mask_0_4lsb :4;
  285. uint32_t bad_address_mask_1 :10;
  286. uint32_t bad_address_match_0 :10;
  287. uint32_t bad_address_match_1_8msb :8;
  288. #else
  289. uint32_t bad_address_match_1_8msb :8;
  290. uint32_t bad_address_match_0 :10;
  291. uint32_t bad_address_mask_1 :10;
  292. uint32_t bad_address_mask_0_4lsb :4;
  293. #endif
  294. /* WORD [2] */
  295. #if (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
  296. uint32_t bad_address_match_1_2lsb :2;
  297. uint32_t difficulty :6;
  298. uint32_t thread_enable :8;
  299. uint32_t thread_base_address_0 :10;
  300. uint32_t thread_base_address_1_6msb :6;
  301. #else
  302. uint32_t thread_base_address_1_6msb :6;
  303. uint32_t thread_base_address_0 :10;
  304. uint32_t thread_enable :8;
  305. uint32_t difficulty :6;
  306. uint32_t bad_address_match_1_2lsb :2;
  307. #endif
  308. /* WORD [3] */
  309. #if (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
  310. uint32_t thread_base_address_1_4lsb :4;
  311. uint32_t thread_base_address_2 :10;
  312. uint32_t thread_base_address_3 :10;
  313. uint32_t thread_base_address_4_8msb :8;
  314. #else
  315. uint32_t thread_base_address_4_8msb :8;
  316. uint32_t thread_base_address_3 :10;
  317. uint32_t thread_base_address_2 :10;
  318. uint32_t thread_base_address_1_4lsb :4;
  319. #endif
  320. /* WORD [4] */
  321. #if (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
  322. uint32_t thread_base_address_4_2lsb :2;
  323. uint32_t thread_base_address_5 :10;
  324. uint32_t thread_base_address_6 :10;
  325. uint32_t thread_base_address_7 :10;
  326. #else
  327. uint32_t thread_base_address_7 :10;
  328. uint32_t thread_base_address_6 :10;
  329. uint32_t thread_base_address_5 :10;
  330. uint32_t thread_base_address_4_2lsb :2;
  331. #endif
  332. /* WORD [5] */
  333. #if (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
  334. uint32_t lookup_gap_mask_0 :10;
  335. uint32_t lookup_gap_mask_1 :10;
  336. uint32_t lookup_gap_mask_2 :10;
  337. uint32_t lookup_gap_mask_3_2msb :2;
  338. #else
  339. uint32_t lookup_gap_mask_3_2msb :2;
  340. uint32_t lookup_gap_mask_2 :10;
  341. uint32_t lookup_gap_mask_1 :10;
  342. uint32_t lookup_gap_mask_0 :10;
  343. #endif
  344. /* WORD [6] */
  345. #if (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
  346. uint32_t lookup_gap_mask_3_8lsb :8;
  347. uint32_t lookup_gap_mask_4 :10;
  348. uint32_t lookup_gap_mask_5 :10;
  349. uint32_t lookup_gap_mask_6_4msb :4;
  350. #else
  351. uint32_t lookup_gap_mask_6_4msb :4;
  352. uint32_t lookup_gap_mask_5 :10;
  353. uint32_t lookup_gap_mask_4 :10;
  354. uint32_t lookup_gap_mask_3_8lsb :8;
  355. #endif
  356. /* WORD [7] */
  357. #if (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
  358. uint32_t lookup_gap_mask_6_6lsb :6;
  359. uint32_t lookup_gap_mask_7 :10;
  360. uint32_t N_mask_0 :10;
  361. uint32_t N_mask_1_6msb :6;
  362. #else
  363. uint32_t N_mask_1_6msb :6;
  364. uint32_t N_mask_0 :10;
  365. uint32_t lookup_gap_mask_7 :10;
  366. uint32_t lookup_gap_mask_6_6lsb :6;
  367. #endif
  368. /* WORD [8] */
  369. #if (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
  370. uint32_t N_mask_1_4lsb :4;
  371. uint32_t N_mask_2 :10;
  372. uint32_t N_mask_3 :10;
  373. uint32_t N_mask_4_8msb :8;
  374. #else
  375. uint32_t N_mask_4_8msb :8;
  376. uint32_t N_mask_3 :10;
  377. uint32_t N_mask_2 :10;
  378. uint32_t N_mask_1_4lsb :4;
  379. #endif
  380. /* WORD [9] */
  381. #if (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
  382. uint32_t N_mask_4_2lsb :2;
  383. uint32_t N_mask_5 :10;
  384. uint32_t N_mask_6 :10;
  385. uint32_t N_mask_7 :10;
  386. #else
  387. uint32_t N_mask_7 :10;
  388. uint32_t N_mask_6 :10;
  389. uint32_t N_mask_5 :10;
  390. uint32_t N_mask_4_2lsb :2;
  391. #endif
  392. /* WORD [10] */
  393. #if (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
  394. uint32_t N_shift_0 :4;
  395. uint32_t N_shift_1 :4;
  396. uint32_t N_shift_2 :4;
  397. uint32_t N_shift_3 :4;
  398. uint32_t N_shift_4 :4;
  399. uint32_t N_shift_5 :4;
  400. uint32_t N_shift_6 :4;
  401. uint32_t N_shift_7 :4;
  402. #else
  403. uint32_t N_shift_7 :4;
  404. uint32_t N_shift_6 :4;
  405. uint32_t N_shift_5 :4;
  406. uint32_t N_shift_4 :4;
  407. uint32_t N_shift_3 :4;
  408. uint32_t N_shift_2 :4;
  409. uint32_t N_shift_1 :4;
  410. uint32_t N_shift_0 :4;
  411. #endif
  412. /* WORD [11] */
  413. uint32_t nonce_top;
  414. /* WORD [12] */
  415. uint32_t nonce_bottom;
  416. } __attribute__((packed)) packed_params;
  417. packed_params.padding = 0;
  418. packed_params.bad_address_mask_0_6msb = (params->bad_address_mask[0] >> 4) & 0x03F;
  419. packed_params.bad_address_mask_0_4lsb = params->bad_address_mask[0] & 0x00F;
  420. packed_params.bad_address_mask_1 = params->bad_address_mask[1];
  421. packed_params.bad_address_match_0 = params->bad_address_match[0];
  422. packed_params.bad_address_match_1_8msb = (params->bad_address_match[1] >> 2) & 0x0FF;
  423. packed_params.bad_address_match_1_2lsb = params->bad_address_match[1] & 0x003;
  424. packed_params.difficulty = params->difficulty;
  425. packed_params.thread_enable = params->thread_enable;
  426. packed_params.thread_base_address_0 = params->thread_base_address[0];
  427. packed_params.thread_base_address_1_6msb = (params->thread_base_address[1] >> 4) & 0x03F;
  428. packed_params.thread_base_address_1_4lsb = params->thread_base_address[1] & 0x00F;
  429. packed_params.thread_base_address_2 = params->thread_base_address[2];
  430. packed_params.thread_base_address_3 = params->thread_base_address[3];
  431. packed_params.thread_base_address_4_8msb = (params->thread_base_address[4] >> 2) & 0x0FF;
  432. packed_params.thread_base_address_4_2lsb = params->thread_base_address[4] & 0x003;
  433. packed_params.thread_base_address_5 = params->thread_base_address[5];
  434. packed_params.thread_base_address_6 = params->thread_base_address[6];
  435. packed_params.thread_base_address_7 = params->thread_base_address[7];
  436. packed_params.lookup_gap_mask_0 = params->lookup_gap_mask[0];
  437. packed_params.lookup_gap_mask_1 = params->lookup_gap_mask[1];
  438. packed_params.lookup_gap_mask_2 = params->lookup_gap_mask[2];
  439. packed_params.lookup_gap_mask_3_2msb = (params->lookup_gap_mask[3] >> 8) & 0x003;
  440. packed_params.lookup_gap_mask_3_8lsb = params->lookup_gap_mask[3] & 0x0FF;
  441. packed_params.lookup_gap_mask_4 = params->lookup_gap_mask[4];
  442. packed_params.lookup_gap_mask_5 = params->lookup_gap_mask[5];
  443. packed_params.lookup_gap_mask_6_4msb = (params->lookup_gap_mask[6] >> 6) & 0x00F;
  444. packed_params.lookup_gap_mask_6_6lsb = params->lookup_gap_mask[6] & 0x03F;
  445. packed_params.lookup_gap_mask_7 = params->lookup_gap_mask[7];
  446. packed_params.N_mask_0 = params->N_mask[0];
  447. packed_params.N_mask_1_6msb = (params->N_mask[1] >> 4) & 0x03F;
  448. packed_params.N_mask_1_4lsb = params->N_mask[1] & 0x00F;
  449. packed_params.N_mask_2 = params->N_mask[2];
  450. packed_params.N_mask_3 = params->N_mask[3];
  451. packed_params.N_mask_4_8msb = (params->N_mask[4] >> 2) & 0x0FF;
  452. packed_params.N_mask_4_2lsb = params->N_mask[4] & 0x003;
  453. packed_params.N_mask_5 = params->N_mask[5];
  454. packed_params.N_mask_6 = params->N_mask[6];
  455. packed_params.N_mask_7 = params->N_mask[7];
  456. packed_params.N_shift_0 = params->N_shift[0];
  457. packed_params.N_shift_1 = params->N_shift[1];
  458. packed_params.N_shift_2 = params->N_shift[2];
  459. packed_params.N_shift_3 = params->N_shift[3];
  460. packed_params.N_shift_4 = params->N_shift[4];
  461. packed_params.N_shift_5 = params->N_shift[5];
  462. packed_params.N_shift_6 = params->N_shift[6];
  463. packed_params.N_shift_7 = params->N_shift[7];
  464. packed_params.nonce_top = params->nonce_top;
  465. packed_params.nonce_bottom = params->nonce_bottom;
  466. src = (uint32_t *)&packed_params;
  467. dst = (uint32_t *)(&setup_core_cmd[send_size - sizeof(packed_params)]);
  468. for (i = 0; i < (sizeof(packed_params) / 4); ++i)
  469. dst[i] = htobe32(src[i]);
  470. rxbuf = spi_transfer(spi, setup_core_cmd, send_size, transfer_size, 0, &errors, &unused);
  471. if (NULL == rxbuf) {
  472. applog(LOG_ERR, "%s[%d:%d] knc_titan_setup_core: Unrecognized error", repr, die, core);
  473. return false;
  474. }
  475. if (0 != errors) {
  476. applog(LOG_ERR, "%s[%d:%d] knc_titan_setup_core: Communication failed, errors = 0x%X", repr, die, core, errors);
  477. return false;
  478. }
  479. return true;
  480. }