driver-bitfury.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654
  1. /*
  2. * Copyright 2013 bitfury
  3. * Copyright 2013 legkodymov
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a copy
  6. * of this software and associated documentation files (the "Software"), to deal
  7. * in the Software without restriction, including without limitation the rights
  8. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. * copies of the Software, and to permit persons to whom the Software is
  10. * furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included in
  13. * all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. * THE SOFTWARE.
  22. */
  23. #include "config.h"
  24. #include "miner.h"
  25. #include <unistd.h>
  26. #include <sha2.h>
  27. #include "deviceapi.h"
  28. #include "libbitfury.h"
  29. #include "util.h"
  30. #include "spidevc.h"
  31. #define GOLDEN_BACKLOG 5
  32. #define LINE_LEN 2048
  33. struct device_drv bitfury_drv;
  34. int calc_stat(time_t * stat_ts, time_t stat, struct timeval now);
  35. double shares_to_ghashes(int shares, int seconds);
  36. static
  37. int bitfury_autodetect()
  38. {
  39. RUNONCE(0);
  40. int chip_n;
  41. struct cgpu_info *bitfury_info;
  42. bitfury_info = calloc(1, sizeof(struct cgpu_info));
  43. bitfury_info->drv = &bitfury_drv;
  44. bitfury_info->threads = 1;
  45. applog(LOG_INFO, "INFO: bitfury_detect");
  46. spi_init();
  47. if (!sys_spi)
  48. return 0;
  49. chip_n = libbitfury_detectChips1(sys_spi);
  50. if (!chip_n) {
  51. applog(LOG_WARNING, "No Bitfury chips detected!");
  52. return 0;
  53. } else {
  54. applog(LOG_WARNING, "BITFURY: %d chips detected!", chip_n);
  55. }
  56. bitfury_info->procs = chip_n;
  57. add_cgpu(bitfury_info);
  58. return 1;
  59. }
  60. static void bitfury_detect(void)
  61. {
  62. noserial_detect_manual(&bitfury_drv, bitfury_autodetect);
  63. }
  64. void *bitfury_just_io(struct bitfury_device * const bitfury)
  65. {
  66. struct spi_port * const spi = bitfury->spi;
  67. const int chip = bitfury->fasync;
  68. void *rv;
  69. spi_clear_buf(spi);
  70. spi_emit_break(spi);
  71. spi_emit_fasync(spi, chip);
  72. rv = spi_emit_data(spi, 0x3000, &bitfury->atrvec[0], 19 * 4);
  73. spi_txrx(spi);
  74. return rv;
  75. }
  76. static
  77. void bitfury_debug_nonce_array(const struct cgpu_info * const proc, const char *msg, const uint32_t * const inp)
  78. {
  79. const struct bitfury_device * const bitfury = proc->device_data;
  80. const int active = bitfury->active;
  81. char s[((1 + 8) * 0x10) + 1];
  82. char *sp = s;
  83. for (int i = 0; i < 0x10; ++i)
  84. sp += sprintf(sp, "%c%08lx",
  85. (active == i) ? '>' : ' ',
  86. (unsigned long)bitfury_decnonce(inp[i]));
  87. applog(LOG_DEBUG, "%"PRIpreprv": %s%s (job=%08lx)",
  88. proc->proc_repr, msg, s, (unsigned long)inp[0x10]);
  89. }
  90. bool bitfury_init_oldbuf(struct cgpu_info * const proc)
  91. {
  92. struct bitfury_device * const bitfury = proc->device_data;
  93. uint32_t * const oldbuf = &bitfury->oldbuf[0];
  94. uint32_t * const buf = &bitfury->newbuf[0];
  95. const uint32_t *inp;
  96. int i, differ, tried = 0;
  97. inp = bitfury_just_io(bitfury);
  98. tryagain:
  99. if (tried > 3)
  100. {
  101. applog(LOG_ERR, "%"PRIpreprv": %s: Giving up after %d tries",
  102. proc->proc_repr, __func__, tried);
  103. bitfury->desync_counter = 99;
  104. return false;
  105. }
  106. ++tried;
  107. memcpy(buf, inp, 0x10 * 4);
  108. inp = bitfury_just_io(bitfury);
  109. differ = -1;
  110. for (i = 0; i < 0x10; ++i)
  111. {
  112. if (inp[i] != buf[i])
  113. {
  114. if (differ != -1)
  115. {
  116. applog(LOG_DEBUG, "%"PRIpreprv": %s: Second differ at %d; trying again",
  117. proc->proc_repr, __func__, i);
  118. goto tryagain;
  119. }
  120. differ = i;
  121. applog(LOG_DEBUG, "%"PRIpreprv": %s: Differ at %d",
  122. proc->proc_repr, __func__, i);
  123. }
  124. }
  125. if (-1 == differ)
  126. {
  127. applog(LOG_DEBUG, "%"PRIpreprv": %s: No differ found; trying again",
  128. proc->proc_repr, __func__);
  129. goto tryagain;
  130. }
  131. bitfury->active = differ;
  132. memcpy(&oldbuf[0], &inp[bitfury->active], 4 * (0x10 - bitfury->active));
  133. memcpy(&oldbuf[0x10 - bitfury->active], &inp[0], 4 * bitfury->active);
  134. bitfury->oldjob = inp[0x10];
  135. bitfury->desync_counter = 0;
  136. if (opt_debug)
  137. bitfury_debug_nonce_array(proc, "Init", inp);
  138. return true;
  139. }
  140. static
  141. bool bitfury_init(struct thr_info *thr)
  142. {
  143. struct cgpu_info *proc;
  144. struct bitfury_device *bitfury;
  145. for (proc = thr->cgpu; proc; proc = proc->next_proc)
  146. {
  147. bitfury = proc->device_data = malloc(sizeof(struct bitfury_device));
  148. *bitfury = (struct bitfury_device){
  149. .spi = sys_spi,
  150. .fasync = proc->proc_id,
  151. };
  152. bitfury_init_oldbuf(proc);
  153. }
  154. return true;
  155. }
  156. static
  157. bool bitfury_queue_full(struct cgpu_info *cgpu)
  158. {
  159. struct cgpu_info *proc;
  160. struct bitfury_device *bitfury;
  161. for (proc = cgpu; proc; proc = proc->next_proc)
  162. {
  163. bitfury = proc->device_data;
  164. if (bitfury->work)
  165. continue;
  166. bitfury->work = get_queued(cgpu);
  167. if (!bitfury->work)
  168. return false;
  169. work_to_payload(&bitfury->payload, bitfury->work);
  170. }
  171. return true;
  172. }
  173. int64_t bitfury_scanHash(struct thr_info *thr)
  174. {
  175. struct cgpu_info * const cgpu = thr->cgpu;
  176. struct bitfury_device * const sds = cgpu->device_data;
  177. struct cgpu_info *proc;
  178. struct thr_info *pthr;
  179. struct bitfury_device *bitfury;
  180. struct timeval now;
  181. char line[LINE_LEN];
  182. int short_stat = 10;
  183. int long_stat = 1800;
  184. int i;
  185. if (!bitfury_queue_full(cgpu))
  186. return 0;
  187. for (proc = cgpu; proc; proc = proc->next_proc)
  188. {
  189. const int chip = proc->proc_id;
  190. pthr = proc->thr[0];
  191. bitfury = proc->device_data;
  192. bitfury->job_switched = 0;
  193. payload_to_atrvec(bitfury->atrvec, &bitfury->payload);
  194. libbitfury_sendHashData1(chip, bitfury, pthr);
  195. }
  196. cgsleep_ms(5);
  197. cgtime(&now);
  198. for (proc = cgpu; proc; proc = proc->next_proc)
  199. {
  200. pthr = proc->thr[0];
  201. bitfury = proc->device_data;
  202. if (bitfury->job_switched) {
  203. int i,j;
  204. unsigned int * const res = bitfury->results;
  205. struct work * const work = bitfury->work;
  206. struct work * const owork = bitfury->owork;
  207. struct work * const o2work = bitfury->o2work;
  208. i = bitfury->results_n;
  209. for (j = i - 1; j >= 0; j--) {
  210. if (owork) {
  211. submit_nonce(pthr, owork, bswap_32(res[j]));
  212. bitfury->stat_ts[bitfury->stat_counter++] =
  213. now.tv_sec;
  214. if (bitfury->stat_counter == BITFURY_STAT_N) {
  215. bitfury->stat_counter = 0;
  216. }
  217. }
  218. if (o2work) {
  219. // TEST
  220. //submit_nonce(pthr, owork, bswap_32(res[j]));
  221. }
  222. }
  223. bitfury->results_n = 0;
  224. bitfury->job_switched = 0;
  225. if (bitfury->old_nonce && o2work) {
  226. submit_nonce(pthr, o2work, bswap_32(bitfury->old_nonce));
  227. i++;
  228. }
  229. if (bitfury->future_nonce) {
  230. submit_nonce(pthr, work, bswap_32(bitfury->future_nonce));
  231. i++;
  232. }
  233. if (o2work)
  234. work_completed(cgpu, o2work);
  235. bitfury->o2work = bitfury->owork;
  236. bitfury->owork = bitfury->work;
  237. bitfury->work = NULL;
  238. hashes_done2(pthr, 0xbd000000, NULL);
  239. }
  240. }
  241. if (now.tv_sec - sds->short_out_t > short_stat) {
  242. int shares_first = 0, shares_last = 0, shares_total = 0;
  243. char stat_lines[32][LINE_LEN] = {{0}};
  244. int len, k;
  245. double gh[32][8] = {{0}};
  246. double ghsum = 0, gh1h = 0, gh2h = 0;
  247. unsigned strange_counter = 0;
  248. for (proc = cgpu; proc; proc = proc->next_proc)
  249. {
  250. const int chip = proc->proc_id;
  251. bitfury = proc->device_data;
  252. int shares_found = calc_stat(bitfury->stat_ts, short_stat, now);
  253. double ghash;
  254. len = strlen(stat_lines[bitfury->slot]);
  255. ghash = shares_to_ghashes(shares_found, short_stat);
  256. gh[bitfury->slot][chip & 0x07] = ghash;
  257. snprintf(stat_lines[bitfury->slot] + len, LINE_LEN - len, "%.1f-%3.0f ", ghash, bitfury->mhz);
  258. if(sds->short_out_t && ghash < 0.5) {
  259. applog(LOG_WARNING, "Chip_id %d FREQ CHANGE", chip);
  260. send_freq(bitfury->spi, bitfury->slot, bitfury->fasync, bitfury->osc6_bits - 1);
  261. cgsleep_ms(1);
  262. send_freq(bitfury->spi, bitfury->slot, bitfury->fasync, bitfury->osc6_bits);
  263. }
  264. shares_total += shares_found;
  265. shares_first += chip < 4 ? shares_found : 0;
  266. shares_last += chip > 3 ? shares_found : 0;
  267. strange_counter += bitfury->strange_counter;
  268. bitfury->strange_counter = 0;
  269. }
  270. sprintf(line, "vvvvwww SHORT stat %ds: wwwvvvv", short_stat);
  271. applog(LOG_WARNING, "%s", line);
  272. sprintf(line, "stranges: %u", strange_counter);
  273. applog(LOG_WARNING, "%s", line);
  274. for(i = 0; i < 32; i++)
  275. if(strlen(stat_lines[i])) {
  276. len = strlen(stat_lines[i]);
  277. ghsum = 0;
  278. gh1h = 0;
  279. gh2h = 0;
  280. for(k = 0; k < 4; k++) {
  281. gh1h += gh[i][k];
  282. gh2h += gh[i][k+4];
  283. ghsum += gh[i][k] + gh[i][k+4];
  284. }
  285. snprintf(stat_lines[i] + len, LINE_LEN - len, "- %2.1f + %2.1f = %2.1f slot %i ", gh1h, gh2h, ghsum, i);
  286. applog(LOG_WARNING, "%s", stat_lines[i]);
  287. }
  288. sds->short_out_t = now.tv_sec;
  289. }
  290. if (now.tv_sec - sds->long_out_t > long_stat) {
  291. int shares_first = 0, shares_last = 0, shares_total = 0;
  292. char stat_lines[32][LINE_LEN] = {{0}};
  293. int len, k;
  294. double gh[32][8] = {{0}};
  295. double ghsum = 0, gh1h = 0, gh2h = 0;
  296. for (proc = cgpu; proc; proc = proc->next_proc)
  297. {
  298. const int chip = proc->proc_id;
  299. bitfury = proc->device_data;
  300. int shares_found = calc_stat(bitfury->stat_ts, long_stat, now);
  301. double ghash;
  302. len = strlen(stat_lines[bitfury->slot]);
  303. ghash = shares_to_ghashes(shares_found, long_stat);
  304. gh[bitfury->slot][chip & 0x07] = ghash;
  305. snprintf(stat_lines[bitfury->slot] + len, LINE_LEN - len, "%.1f-%3.0f ", ghash, bitfury->mhz);
  306. shares_total += shares_found;
  307. shares_first += chip < 4 ? shares_found : 0;
  308. shares_last += chip > 3 ? shares_found : 0;
  309. }
  310. sprintf(line, "!!!_________ LONG stat %ds: ___________!!!", long_stat);
  311. applog(LOG_WARNING, "%s", line);
  312. for(i = 0; i < 32; i++)
  313. if(strlen(stat_lines[i])) {
  314. len = strlen(stat_lines[i]);
  315. ghsum = 0;
  316. gh1h = 0;
  317. gh2h = 0;
  318. for(k = 0; k < 4; k++) {
  319. gh1h += gh[i][k];
  320. gh2h += gh[i][k+4];
  321. ghsum += gh[i][k] + gh[i][k+4];
  322. }
  323. snprintf(stat_lines[i] + len, LINE_LEN - len, "- %2.1f + %2.1f = %2.1f slot %i ", gh1h, gh2h, ghsum, i);
  324. applog(LOG_WARNING, "%s", stat_lines[i]);
  325. }
  326. sds->long_out_t = now.tv_sec;
  327. }
  328. return 0;
  329. }
  330. double shares_to_ghashes(int shares, int seconds) {
  331. return (double)shares / (double)seconds * 4.84387; //orig: 4.77628
  332. }
  333. int calc_stat(time_t * stat_ts, time_t stat, struct timeval now) {
  334. int j;
  335. int shares_found = 0;
  336. for(j = 0; j < BITFURY_STAT_N; j++) {
  337. if (now.tv_sec - stat_ts[j] < stat) {
  338. shares_found++;
  339. }
  340. }
  341. return shares_found;
  342. }
  343. bool bitfury_prepare(struct thr_info *thr)
  344. {
  345. struct cgpu_info *cgpu = thr->cgpu;
  346. get_now_datestamp(cgpu->init, sizeof(cgpu->init));
  347. applog(LOG_INFO, "INFO bitfury_prepare");
  348. return true;
  349. }
  350. void bitfury_shutdown(struct thr_info *thr) {
  351. struct cgpu_info *cgpu = thr->cgpu, *proc;
  352. struct bitfury_device *bitfury;
  353. applog(LOG_INFO, "INFO bitfury_shutdown");
  354. for (proc = cgpu; proc; proc = proc->next_proc)
  355. {
  356. bitfury = proc->device_data;
  357. send_shutdown(bitfury->spi, bitfury->slot, bitfury->fasync);
  358. }
  359. }
  360. bool bitfury_job_prepare(struct thr_info *thr, struct work *work, __maybe_unused uint64_t max_nonce)
  361. {
  362. struct cgpu_info * const proc = thr->cgpu;
  363. struct bitfury_device * const bitfury = proc->device_data;
  364. if (opt_debug)
  365. {
  366. char hex[153];
  367. bin2hex(hex, &work->data[0], 76);
  368. applog(LOG_DEBUG, "%"PRIpreprv": Preparing work %s",
  369. proc->proc_repr, hex);
  370. }
  371. work_to_payload(&bitfury->payload, work);
  372. payload_to_atrvec(bitfury->atrvec, &bitfury->payload);
  373. work->blk.nonce = 0xffffffff;
  374. return true;
  375. }
  376. static
  377. bool fudge_nonce(struct work * const work, uint32_t *nonce_p) {
  378. static const uint32_t offsets[] = {0, 0xffc00000, 0xff800000, 0x02800000, 0x02C00000, 0x00400000};
  379. uint32_t nonce;
  380. int i;
  381. if (unlikely(!work))
  382. return false;
  383. for (i = 0; i < 6; ++i)
  384. {
  385. nonce = *nonce_p + offsets[i];
  386. if (test_nonce(work, nonce, false))
  387. {
  388. *nonce_p = nonce;
  389. return true;
  390. }
  391. }
  392. return false;
  393. }
  394. void bitfury_noop_job_start(struct thr_info __maybe_unused * const thr)
  395. {
  396. }
  397. void bitfury_do_io(struct thr_info * const master_thr)
  398. {
  399. struct cgpu_info *proc;
  400. struct thr_info *thr;
  401. struct bitfury_device *bitfury;
  402. const uint32_t *inp;
  403. int n, i, j;
  404. bool newjob;
  405. uint32_t nonce;
  406. int n_chips = 0, lastchip;
  407. struct spi_port *spi = NULL;
  408. bool should_be_running;
  409. for (proc = master_thr->cgpu; proc; proc = proc->next_proc)
  410. ++n_chips;
  411. struct cgpu_info *procs[n_chips];
  412. void *rxbuf[n_chips];
  413. // NOTE: This code assumes:
  414. // 1) that chips on the same SPI bus are grouped together
  415. // 2) that chips are in sequential fasync order
  416. n_chips = 0;
  417. for (proc = master_thr->cgpu; proc; proc = proc->next_proc)
  418. {
  419. thr = proc->thr[0];
  420. bitfury = proc->device_data;
  421. should_be_running = (proc->deven == DEV_ENABLED && !thr->pause);
  422. if (should_be_running)
  423. {
  424. if (spi != bitfury->spi)
  425. {
  426. if (spi)
  427. spi_txrx(spi);
  428. spi = bitfury->spi;
  429. spi_clear_buf(spi);
  430. spi_emit_break(spi);
  431. lastchip = 0;
  432. }
  433. procs[n_chips] = proc;
  434. spi_emit_fasync(spi, bitfury->fasync - lastchip);
  435. lastchip = bitfury->fasync;
  436. rxbuf[n_chips] = spi_emit_data(spi, 0x3000, &bitfury->atrvec[0], 19 * 4);
  437. ++n_chips;
  438. }
  439. else
  440. if (thr->work /* is currently running */ && thr->busy_state != TBS_STARTING_JOB)
  441. ;//FIXME: shutdown chip
  442. }
  443. spi_txrx(spi);
  444. for (j = 0; j < n_chips; ++j)
  445. {
  446. proc = procs[j];
  447. thr = proc->thr[0];
  448. bitfury = proc->device_data;
  449. uint32_t * const newbuf = &bitfury->newbuf[0];
  450. uint32_t * const oldbuf = &bitfury->oldbuf[0];
  451. if (unlikely(bitfury->desync_counter == 99))
  452. {
  453. // TODO: use current rxbuf
  454. bitfury_init_oldbuf(proc);
  455. goto out;
  456. }
  457. inp = rxbuf[j];
  458. if (opt_debug)
  459. bitfury_debug_nonce_array(proc, "Read", inp);
  460. // To avoid dealing with wrap-around entirely, we rotate array so previous active uint32_t is at index 0
  461. memcpy(&newbuf[0], &inp[bitfury->active], 4 * (0x10 - bitfury->active));
  462. memcpy(&newbuf[0x10 - bitfury->active], &inp[0], 4 * bitfury->active);
  463. newjob = inp[0x10];
  464. if (newbuf[0xf] != oldbuf[0xf])
  465. {
  466. inc_hw_errors2(thr, NULL, NULL);
  467. if (unlikely(++bitfury->desync_counter >= 4))
  468. {
  469. applog(LOG_WARNING, "%"PRIpreprv": Previous nonce mismatch (4th try), recalibrating",
  470. proc->proc_repr);
  471. bitfury_init_oldbuf(proc);
  472. continue;
  473. }
  474. applog(LOG_DEBUG, "%"PRIpreprv": Previous nonce mismatch, ignoring response",
  475. proc->proc_repr);
  476. goto out;
  477. }
  478. else
  479. bitfury->desync_counter = 0;
  480. if (bitfury->oldjob != newjob && thr->next_work)
  481. {
  482. mt_job_transition(thr);
  483. // TODO: Delay morework until right before it's needed
  484. timer_set_now(&thr->tv_morework);
  485. job_start_complete(thr);
  486. }
  487. for (n = 0; newbuf[n] == oldbuf[n]; ++n)
  488. {
  489. if (unlikely(n >= 0xf))
  490. {
  491. inc_hw_errors2(thr, NULL, NULL);
  492. applog(LOG_DEBUG, "%"PRIpreprv": Full result match, reinitialising",
  493. proc->proc_repr);
  494. send_reinit(bitfury->spi, bitfury->slot, bitfury->fasync, bitfury->osc6_bits);
  495. bitfury->desync_counter = 99;
  496. goto out;
  497. }
  498. }
  499. if (n)
  500. {
  501. for (i = 0; i < n; ++i)
  502. {
  503. nonce = bitfury_decnonce(newbuf[i]);
  504. if (fudge_nonce(thr->work, &nonce))
  505. {
  506. applog(LOG_DEBUG, "%"PRIpreprv": nonce %x = %08lx (work=%p)",
  507. proc->proc_repr, i, (unsigned long)nonce, thr->work);
  508. submit_nonce(thr, thr->work, nonce);
  509. }
  510. else
  511. if (fudge_nonce(thr->prev_work, &nonce))
  512. {
  513. applog(LOG_DEBUG, "%"PRIpreprv": nonce %x = %08lx (prev work=%p)",
  514. proc->proc_repr, i, (unsigned long)nonce, thr->prev_work);
  515. submit_nonce(thr, thr->prev_work, nonce);
  516. }
  517. else
  518. {
  519. inc_hw_errors(thr, thr->work, nonce);
  520. ++bitfury->sample_hwe;
  521. }
  522. if (++bitfury->sample_tot >= 0x40 || bitfury->sample_hwe >= 8)
  523. {
  524. if (bitfury->sample_hwe >= 8)
  525. {
  526. applog(LOG_WARNING, "%"PRIpreprv": %d of the last %d results were bad, reinitialising",
  527. proc->proc_repr, bitfury->sample_hwe, bitfury->sample_tot);
  528. send_reinit(bitfury->spi, bitfury->slot, bitfury->fasync, bitfury->osc6_bits);
  529. bitfury->desync_counter = 99;
  530. }
  531. bitfury->sample_tot = bitfury->sample_hwe = 0;
  532. }
  533. }
  534. bitfury->active = (bitfury->active + n) % 0x10;
  535. }
  536. memcpy(&oldbuf[0], &newbuf[n], 4 * (0x10 - n));
  537. memcpy(&oldbuf[0x10 - n], &newbuf[0], 4 * n);
  538. bitfury->oldjob = newjob;
  539. out:
  540. continue;
  541. }
  542. timer_set_delay_from_now(&master_thr->tv_poll, 10000);
  543. }
  544. int64_t bitfury_job_process_results(struct thr_info *thr, struct work *work, bool stopping)
  545. {
  546. // Bitfury chips process only 768/1024 of the nonce range
  547. return 0xbd000000;
  548. }
  549. struct api_data *bitfury_api_device_status(const struct cgpu_info * const cgpu)
  550. {
  551. const struct bitfury_device * const bitfury = cgpu->device_data;
  552. struct api_data *root = NULL;
  553. int clock_bits = bitfury->osc6_bits;
  554. root = api_add_int(root, "Clock Bits", &clock_bits, true);
  555. return root;
  556. }
  557. struct device_drv bitfury_drv = {
  558. .dname = "bitfury_gpio",
  559. .name = "BFY",
  560. .drv_detect = bitfury_detect,
  561. .thread_prepare = bitfury_prepare,
  562. .thread_init = bitfury_init,
  563. .queue_full = bitfury_queue_full,
  564. .scanwork = bitfury_scanHash,
  565. .thread_shutdown = bitfury_shutdown,
  566. .minerloop = hash_queued_work,
  567. };