driver-bitforce.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  1. /*
  2. * Copyright 2012 Luke Dashjr
  3. * Copyright 2012 Con Kolivas
  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 <limits.h>
  11. #include <pthread.h>
  12. #include <stdint.h>
  13. #include <stdio.h>
  14. #include <strings.h>
  15. #include <sys/time.h>
  16. #include <unistd.h>
  17. #include "config.h"
  18. #include "compat.h"
  19. #include "fpgautils.h"
  20. #include "miner.h"
  21. #define BITFORCE_SLEEP_MS 500
  22. #define BITFORCE_TIMEOUT_S 7
  23. #define BITFORCE_TIMEOUT_MS (BITFORCE_TIMEOUT_S * 1000)
  24. #define BITFORCE_LONG_TIMEOUT_S 25
  25. #define BITFORCE_LONG_TIMEOUT_MS (BITFORCE_LONG_TIMEOUT_S * 1000)
  26. #define BITFORCE_CHECK_INTERVAL_MS 10
  27. #define WORK_CHECK_INTERVAL_MS 50
  28. #define MAX_START_DELAY_US 100000
  29. #define tv_to_ms(tval) (tval.tv_sec * 1000 + tval.tv_usec / 1000)
  30. #define TIME_AVG_CONSTANT 8
  31. #define KNAME_WORK "full work"
  32. #define KNAME_RANGE "nonce range"
  33. struct device_api bitforce_api;
  34. // Code must deal with a timeout
  35. #define BFopen(devpath) serial_open(devpath, 0, 250, true)
  36. static void BFgets(char *buf, size_t bufLen, int fd)
  37. {
  38. do {
  39. buf[0] = '\0';
  40. --bufLen;
  41. } while (likely(bufLen && read(fd, buf, 1) == 1 && (buf++)[0] != '\n'));
  42. buf[0] = '\0';
  43. }
  44. static ssize_t BFwrite(int fd, const void *buf, ssize_t bufLen)
  45. {
  46. if ((bufLen) != write(fd, buf, bufLen))
  47. return 0;
  48. else
  49. return bufLen;
  50. }
  51. #define BFclose(fd) close(fd)
  52. static bool bitforce_detect_one(const char *devpath)
  53. {
  54. int fdDev = serial_open(devpath, 0, 10, true);
  55. struct cgpu_info *bitforce;
  56. char pdevbuf[0x100];
  57. char *s;
  58. applog(LOG_DEBUG, "BFL: Attempting to open %s", devpath);
  59. if (unlikely(fdDev == -1)) {
  60. applog(LOG_DEBUG, "BFL: Failed to open %s", devpath);
  61. return false;
  62. }
  63. BFwrite(fdDev, "ZGX", 3);
  64. BFgets(pdevbuf, sizeof(pdevbuf), fdDev);
  65. if (unlikely(!pdevbuf[0])) {
  66. applog(LOG_DEBUG, "BFL: Error reading/timeout (ZGX)");
  67. return 0;
  68. }
  69. BFclose(fdDev);
  70. if (unlikely(!strstr(pdevbuf, "SHA256"))) {
  71. applog(LOG_DEBUG, "BFL: Didn't recognise BitForce on %s", devpath);
  72. return false;
  73. }
  74. // We have a real BitForce!
  75. bitforce = calloc(1, sizeof(*bitforce));
  76. bitforce->api = &bitforce_api;
  77. bitforce->device_path = strdup(devpath);
  78. bitforce->deven = DEV_ENABLED;
  79. bitforce->threads = 1;
  80. /* Initially enable support for nonce range and disable it later if it
  81. * fails */
  82. if (opt_bfl_noncerange) {
  83. bitforce->nonce_range = true;
  84. bitforce->sleep_ms = BITFORCE_SLEEP_MS;
  85. bitforce->kname = KNAME_RANGE;
  86. } else {
  87. bitforce->sleep_ms = BITFORCE_SLEEP_MS * 5;
  88. bitforce->kname = KNAME_WORK;
  89. }
  90. if (likely((!memcmp(pdevbuf, ">>>ID: ", 7)) && (s = strstr(pdevbuf + 3, ">>>")))) {
  91. s[0] = '\0';
  92. bitforce->name = strdup(pdevbuf + 7);
  93. }
  94. mutex_init(&bitforce->device_mutex);
  95. return add_cgpu(bitforce);
  96. }
  97. static int bitforce_detect_auto(void)
  98. {
  99. return (serial_autodetect_udev (bitforce_detect_one, "BitFORCE*SHA256") ?:
  100. serial_autodetect_devserial(bitforce_detect_one, "BitFORCE_SHA256") ?:
  101. serial_autodetect_ftdi(bitforce_detect_one, "BitFORCE", "SHA256") ?:
  102. 0);
  103. }
  104. static void bitforce_detect(void)
  105. {
  106. serial_detect_auto(bitforce_api.dname, bitforce_detect_one, bitforce_detect_auto);
  107. }
  108. static void get_bitforce_statline_before(char *buf, struct cgpu_info *bitforce)
  109. {
  110. float gt = bitforce->temp;
  111. if (gt > 0)
  112. tailsprintf(buf, "%5.1fC ", gt);
  113. else
  114. tailsprintf(buf, " ", gt);
  115. tailsprintf(buf, " | ");
  116. }
  117. static bool bitforce_thread_prepare(struct thr_info *thr)
  118. {
  119. struct cgpu_info *bitforce = thr->cgpu;
  120. int fdDev = BFopen(bitforce->device_path);
  121. struct timeval now;
  122. if (unlikely(fdDev == -1)) {
  123. applog(LOG_ERR, "BFL%i: Failed to open %s", bitforce->device_id, bitforce->device_path);
  124. return false;
  125. }
  126. bitforce->device_fd = fdDev;
  127. applog(LOG_INFO, "BFL%i: Opened %s", bitforce->device_id, bitforce->device_path);
  128. gettimeofday(&now, NULL);
  129. get_datestamp(bitforce->init, &now);
  130. return true;
  131. }
  132. static void bitforce_clear_buffer(struct cgpu_info *bitforce)
  133. {
  134. int fdDev = bitforce->device_fd;
  135. char pdevbuf[0x100];
  136. int count = 0;
  137. if (!fdDev)
  138. return;
  139. applog(LOG_DEBUG, "BFL%i: Clearing read buffer", bitforce->device_id);
  140. mutex_lock(&bitforce->device_mutex);
  141. do {
  142. pdevbuf[0] = '\0';
  143. BFgets(pdevbuf, sizeof(pdevbuf), fdDev);
  144. } while (pdevbuf[0] && (++count < 10));
  145. mutex_unlock(&bitforce->device_mutex);
  146. }
  147. void bitforce_init(struct cgpu_info *bitforce)
  148. {
  149. const char *devpath = bitforce->device_path;
  150. int fdDev = bitforce->device_fd, retries = 0;
  151. char pdevbuf[0x100];
  152. char *s;
  153. applog(LOG_WARNING, "BFL%i: Re-initialising", bitforce->device_id);
  154. bitforce_clear_buffer(bitforce);
  155. mutex_lock(&bitforce->device_mutex);
  156. if (fdDev) {
  157. BFclose(fdDev);
  158. sleep(5);
  159. }
  160. bitforce->device_fd = 0;
  161. fdDev = BFopen(devpath);
  162. if (unlikely(fdDev == -1)) {
  163. mutex_unlock(&bitforce->device_mutex);
  164. applog(LOG_ERR, "BFL%i: Failed to open %s", bitforce->device_id, devpath);
  165. return;
  166. }
  167. do {
  168. BFwrite(fdDev, "ZGX", 3);
  169. BFgets(pdevbuf, sizeof(pdevbuf), fdDev);
  170. if (unlikely(!pdevbuf[0])) {
  171. mutex_unlock(&bitforce->device_mutex);
  172. applog(LOG_ERR, "BFL%i: Error reading/timeout (ZGX)", bitforce->device_id);
  173. return;
  174. }
  175. if (retries++)
  176. nmsleep(10);
  177. } while (!strstr(pdevbuf, "BUSY") && (retries * 10 < BITFORCE_TIMEOUT_MS));
  178. if (unlikely(!strstr(pdevbuf, "SHA256"))) {
  179. mutex_unlock(&bitforce->device_mutex);
  180. applog(LOG_ERR, "BFL%i: Didn't recognise BitForce on %s returned: %s", bitforce->device_id, devpath, pdevbuf);
  181. return;
  182. }
  183. if (likely((!memcmp(pdevbuf, ">>>ID: ", 7)) && (s = strstr(pdevbuf + 3, ">>>")))) {
  184. s[0] = '\0';
  185. bitforce->name = strdup(pdevbuf + 7);
  186. }
  187. bitforce->device_fd = fdDev;
  188. bitforce->sleep_ms = BITFORCE_SLEEP_MS;
  189. mutex_unlock(&bitforce->device_mutex);
  190. }
  191. static bool bitforce_get_temp(struct cgpu_info *bitforce)
  192. {
  193. int fdDev = bitforce->device_fd;
  194. char pdevbuf[0x100];
  195. char *s;
  196. if (!fdDev)
  197. return false;
  198. /* Do not try to get the temperature if we're polling for a result to
  199. * minimise the change of interleaved results */
  200. if (bitforce->polling)
  201. return true;
  202. /* It is not critical getting temperature so don't get stuck if we
  203. * can't grab the mutex here */
  204. if (mutex_trylock(&bitforce->device_mutex))
  205. return false;
  206. BFwrite(fdDev, "ZLX", 3);
  207. BFgets(pdevbuf, sizeof(pdevbuf), fdDev);
  208. mutex_unlock(&bitforce->device_mutex);
  209. if (unlikely(!pdevbuf[0])) {
  210. applog(LOG_ERR, "BFL%i: Error: Get temp returned empty string/timed out", bitforce->device_id);
  211. bitforce->hw_errors++;
  212. return false;
  213. }
  214. if ((!strncasecmp(pdevbuf, "TEMP", 4)) && (s = strchr(pdevbuf + 4, ':'))) {
  215. float temp = strtof(s + 1, NULL);
  216. if (temp > 0) {
  217. bitforce->temp = temp;
  218. if (unlikely(bitforce->cutofftemp > 0 && temp > bitforce->cutofftemp)) {
  219. applog(LOG_WARNING, "BFL%i: Hit thermal cutoff limit, disabling!", bitforce->device_id);
  220. bitforce->deven = DEV_RECOVER;
  221. bitforce->device_last_not_well = time(NULL);
  222. bitforce->device_not_well_reason = REASON_DEV_THERMAL_CUTOFF;
  223. bitforce->dev_thermal_cutoff_count++;
  224. }
  225. }
  226. } else {
  227. /* Use the temperature monitor as a kind of watchdog for when
  228. * our responses are out of sync and flush the buffer to
  229. * hopefully recover */
  230. applog(LOG_WARNING, "BFL%i: Garbled response probably throttling, clearing buffer", bitforce->device_id);
  231. /* Count throttling episodes as hardware errors */
  232. bitforce->hw_errors++;
  233. bitforce_clear_buffer(bitforce);
  234. return false;;
  235. }
  236. return true;
  237. }
  238. static bool bitforce_send_work(struct thr_info *thr, struct work *work)
  239. {
  240. struct cgpu_info *bitforce = thr->cgpu;
  241. int fdDev = bitforce->device_fd;
  242. unsigned char ob[70];
  243. char pdevbuf[0x100];
  244. char *s;
  245. if (!fdDev)
  246. return false;
  247. re_send:
  248. mutex_lock(&bitforce->device_mutex);
  249. if (bitforce->nonce_range)
  250. BFwrite(fdDev, "ZPX", 3);
  251. else
  252. BFwrite(fdDev, "ZDX", 3);
  253. BFgets(pdevbuf, sizeof(pdevbuf), fdDev);
  254. if (!pdevbuf[0] || !strncasecmp(pdevbuf, "B", 1)) {
  255. mutex_unlock(&bitforce->device_mutex);
  256. if (!restart_wait(WORK_CHECK_INTERVAL_MS))
  257. return false;
  258. goto re_send;
  259. } else if (unlikely(strncasecmp(pdevbuf, "OK", 2))) {
  260. mutex_unlock(&bitforce->device_mutex);
  261. if (bitforce->nonce_range) {
  262. applog(LOG_WARNING, "BFL%i: Does not support nonce range, disabling", bitforce->device_id);
  263. bitforce->nonce_range = false;
  264. bitforce->sleep_ms *= 5;
  265. bitforce->kname = KNAME_WORK;
  266. goto re_send;
  267. }
  268. applog(LOG_ERR, "BFL%i: Error: Send work reports: %s", bitforce->device_id, pdevbuf);
  269. return false;
  270. }
  271. sprintf((char *)ob, ">>>>>>>>");
  272. memcpy(ob + 8, work->midstate, 32);
  273. memcpy(ob + 8 + 32, work->data + 64, 12);
  274. if (!bitforce->nonce_range) {
  275. sprintf((char *)ob + 8 + 32 + 12, ">>>>>>>>");
  276. work->blk.nonce = bitforce->nonces = 0xffffffff;
  277. BFwrite(fdDev, ob, 60);
  278. } else {
  279. uint32_t *nonce;
  280. nonce = (uint32_t *)(ob + 8 + 32 + 12);
  281. *nonce = htobe32(work->blk.nonce);
  282. nonce = (uint32_t *)(ob + 8 + 32 + 12 + 4);
  283. /* Split work up into 1/5th nonce ranges */
  284. bitforce->nonces = 0x33333332;
  285. *nonce = htobe32(work->blk.nonce + bitforce->nonces);
  286. work->blk.nonce += bitforce->nonces + 1;
  287. sprintf((char *)ob + 8 + 32 + 12 + 8, ">>>>>>>>");
  288. BFwrite(fdDev, ob, 68);
  289. }
  290. BFgets(pdevbuf, sizeof(pdevbuf), fdDev);
  291. mutex_unlock(&bitforce->device_mutex);
  292. if (opt_debug) {
  293. s = bin2hex(ob + 8, 44);
  294. applog(LOG_DEBUG, "BFL%i: block data: %s", bitforce->device_id, s);
  295. free(s);
  296. }
  297. if (unlikely(!pdevbuf[0])) {
  298. applog(LOG_ERR, "BFL%i: Error: Send block data returned empty string/timed out", bitforce->device_id);
  299. return false;
  300. }
  301. if (unlikely(strncasecmp(pdevbuf, "OK", 2))) {
  302. applog(LOG_ERR, "BFL%i: Error: Send block data reports: %s", bitforce->device_id, pdevbuf);
  303. return false;
  304. }
  305. gettimeofday(&bitforce->work_start_tv, NULL);
  306. return true;
  307. }
  308. static inline int noisy_stale_wait(unsigned int mstime, struct work*work, bool checkend, struct cgpu_info*bitforce)
  309. {
  310. int rv = stale_wait(mstime, work, checkend);
  311. if (rv)
  312. applog(LOG_NOTICE, "BFL%i: Abandoning stale search to restart",
  313. bitforce->device_id);
  314. return rv;
  315. }
  316. #define noisy_stale_wait(mstime, work, checkend) noisy_stale_wait(mstime, work, checkend, bitforce)
  317. static int64_t bitforce_get_result(struct thr_info *thr, struct work *work)
  318. {
  319. struct cgpu_info *bitforce = thr->cgpu;
  320. int fdDev = bitforce->device_fd;
  321. unsigned int delay_time_ms;
  322. struct timeval elapsed;
  323. struct timeval now;
  324. char pdevbuf[0x100];
  325. char *pnoncebuf;
  326. uint32_t nonce;
  327. if (!fdDev)
  328. return -1;
  329. while (1) {
  330. mutex_lock(&bitforce->device_mutex);
  331. BFwrite(fdDev, "ZFX", 3);
  332. BFgets(pdevbuf, sizeof(pdevbuf), fdDev);
  333. mutex_unlock(&bitforce->device_mutex);
  334. gettimeofday(&now, NULL);
  335. timersub(&now, &bitforce->work_start_tv, &elapsed);
  336. if (elapsed.tv_sec >= BITFORCE_LONG_TIMEOUT_S) {
  337. applog(LOG_ERR, "BFL%i: took %dms - longer than %dms", bitforce->device_id,
  338. tv_to_ms(elapsed), BITFORCE_LONG_TIMEOUT_MS);
  339. return 0;
  340. }
  341. if (pdevbuf[0] && strncasecmp(pdevbuf, "B", 1)) /* BFL does not respond during throttling */
  342. break;
  343. /* if BFL is throttling, no point checking so quickly */
  344. delay_time_ms = (pdevbuf[0] ? BITFORCE_CHECK_INTERVAL_MS : 2 * WORK_CHECK_INTERVAL_MS);
  345. if (noisy_stale_wait(delay_time_ms, work, true))
  346. return 0;
  347. bitforce->wait_ms += delay_time_ms;
  348. }
  349. if (elapsed.tv_sec > BITFORCE_TIMEOUT_S) {
  350. applog(LOG_ERR, "BFL%i: took %dms - longer than %dms", bitforce->device_id,
  351. tv_to_ms(elapsed), BITFORCE_TIMEOUT_MS);
  352. bitforce->device_last_not_well = time(NULL);
  353. bitforce->device_not_well_reason = REASON_DEV_OVER_HEAT;
  354. bitforce->dev_over_heat_count++;
  355. /* If the device truly throttled, it didn't process the job and there
  356. * are no results. But check first, just in case we're wrong about it
  357. * throttling.
  358. */
  359. if (strncasecmp(pdevbuf, "NONCE-FOUND", 11))
  360. return 0;
  361. } else if (!strncasecmp(pdevbuf, "N", 1)) {/* Hashing complete (NONCE-FOUND or NO-NONCE) */
  362. /* Simple timing adjustment. Allow a few polls to cope with
  363. * OS timer delays being variably reliable. wait_ms will
  364. * always equal sleep_ms when we've waited greater than or
  365. * equal to the result return time.*/
  366. delay_time_ms = bitforce->sleep_ms;
  367. if (bitforce->wait_ms > bitforce->sleep_ms + (WORK_CHECK_INTERVAL_MS * 2))
  368. bitforce->sleep_ms += (bitforce->wait_ms - bitforce->sleep_ms) / 2;
  369. else if (bitforce->wait_ms == bitforce->sleep_ms) {
  370. if (bitforce->sleep_ms > WORK_CHECK_INTERVAL_MS)
  371. bitforce->sleep_ms -= WORK_CHECK_INTERVAL_MS;
  372. else if (bitforce->sleep_ms > BITFORCE_CHECK_INTERVAL_MS)
  373. bitforce->sleep_ms -= BITFORCE_CHECK_INTERVAL_MS;
  374. }
  375. if (delay_time_ms != bitforce->sleep_ms)
  376. applog(LOG_DEBUG, "BFL%i: Wait time changed to: %d, waited %u", bitforce->device_id, bitforce->sleep_ms, bitforce->wait_ms);
  377. /* Work out the average time taken. Float for calculation, uint for display */
  378. bitforce->avg_wait_f += (tv_to_ms(elapsed) - bitforce->avg_wait_f) / TIME_AVG_CONSTANT;
  379. bitforce->avg_wait_d = (unsigned int) (bitforce->avg_wait_f + 0.5);
  380. }
  381. applog(LOG_DEBUG, "BFL%i: waited %dms until %s", bitforce->device_id, bitforce->wait_ms, pdevbuf);
  382. if (!strncasecmp(&pdevbuf[2], "-", 1))
  383. return bitforce->nonces; /* No valid nonce found */
  384. else if (!strncasecmp(pdevbuf, "I", 1))
  385. return 0; /* Device idle */
  386. else if (strncasecmp(pdevbuf, "NONCE-FOUND", 11)) {
  387. bitforce->hw_errors++;
  388. applog(LOG_WARNING, "BFL%i: Error: Get result reports: %s", bitforce->device_id, pdevbuf);
  389. bitforce_clear_buffer(bitforce);
  390. return 0;
  391. }
  392. pnoncebuf = &pdevbuf[12];
  393. while (1) {
  394. hex2bin((void*)&nonce, pnoncebuf, 4);
  395. nonce = be32toh(nonce);
  396. if (unlikely(bitforce->nonce_range && (nonce >= work->blk.nonce ||
  397. (work->blk.nonce > 0 && nonce < work->blk.nonce - bitforce->nonces - 1)))) {
  398. applog(LOG_WARNING, "BFL%i: Disabling broken nonce range support", bitforce->device_id);
  399. bitforce->nonce_range = false;
  400. work->blk.nonce = 0xffffffff;
  401. bitforce->sleep_ms *= 5;
  402. bitforce->kname = KNAME_WORK;
  403. }
  404. submit_nonce(thr, work, nonce);
  405. if (strncmp(&pnoncebuf[8], ",", 1))
  406. break;
  407. pnoncebuf += 9;
  408. }
  409. return bitforce->nonces;
  410. }
  411. static void bitforce_shutdown(struct thr_info *thr)
  412. {
  413. struct cgpu_info *bitforce = thr->cgpu;
  414. BFclose(bitforce->device_fd);
  415. bitforce->device_fd = 0;
  416. }
  417. static void biforce_thread_enable(struct thr_info *thr)
  418. {
  419. struct cgpu_info *bitforce = thr->cgpu;
  420. bitforce_init(bitforce);
  421. }
  422. static int64_t bitforce_scanhash(struct thr_info *thr, struct work *work, int64_t __maybe_unused max_nonce)
  423. {
  424. struct cgpu_info *bitforce = thr->cgpu;
  425. int64_t ret;
  426. if (!bitforce_send_work(thr, work)) {
  427. if (thr->work_restart)
  428. return 0;
  429. sleep(opt_fail_pause);
  430. goto commerr;
  431. }
  432. if (noisy_stale_wait(bitforce->sleep_ms, work, true))
  433. return 0;
  434. bitforce->wait_ms = bitforce->sleep_ms;
  435. {
  436. bitforce->polling = true;
  437. ret = bitforce_get_result(thr, work);
  438. bitforce->polling = false;
  439. }
  440. if (ret == -1) {
  441. commerr:
  442. ret = 0;
  443. applog(LOG_ERR, "BFL%i: Comms error", bitforce->device_id);
  444. bitforce->device_last_not_well = time(NULL);
  445. bitforce->device_not_well_reason = REASON_DEV_COMMS_ERROR;
  446. bitforce->dev_comms_error_count++;
  447. bitforce->hw_errors++;
  448. BFclose(bitforce->device_fd);
  449. int fd = bitforce->device_fd = BFopen(bitforce->device_path);
  450. if (fd == -1) {
  451. applog(LOG_ERR, "BFL%i: Error reopening");
  452. return -1;
  453. }
  454. /* empty read buffer */
  455. bitforce_clear_buffer(bitforce);
  456. }
  457. return ret;
  458. }
  459. static bool bitforce_get_stats(struct cgpu_info *bitforce)
  460. {
  461. return bitforce_get_temp(bitforce);
  462. }
  463. static bool bitforce_thread_init(struct thr_info *thr)
  464. {
  465. struct cgpu_info *bitforce = thr->cgpu;
  466. unsigned int wait;
  467. /* Pause each new thread at least 100ms between initialising
  468. * so the devices aren't making calls all at the same time. */
  469. wait = thr->id * MAX_START_DELAY_US;
  470. applog(LOG_DEBUG, "BFL%i: Delaying start by %dms", bitforce->device_id, wait / 1000);
  471. usleep(wait);
  472. return true;
  473. }
  474. static struct api_data *bitforce_api_stats(struct cgpu_info *cgpu)
  475. {
  476. struct api_data *root = NULL;
  477. // Warning, access to these is not locked - but we don't really
  478. // care since hashing performance is way more important than
  479. // locking access to displaying API debug 'stats'
  480. // If locking becomes an issue for any of them, use copy_data=true also
  481. root = api_add_uint(root, "Sleep Time", &(cgpu->sleep_ms), false);
  482. root = api_add_uint(root, "Avg Wait", &(cgpu->avg_wait_d), false);
  483. return root;
  484. }
  485. struct device_api bitforce_api = {
  486. .dname = "bitforce",
  487. .name = "BFL",
  488. .api_detect = bitforce_detect,
  489. .get_api_stats = bitforce_api_stats,
  490. .reinit_device = bitforce_init,
  491. .get_statline_before = get_bitforce_statline_before,
  492. .get_stats = bitforce_get_stats,
  493. .thread_prepare = bitforce_thread_prepare,
  494. .thread_init = bitforce_thread_init,
  495. .scanhash = bitforce_scanhash,
  496. .thread_shutdown = bitforce_shutdown,
  497. .thread_enable = biforce_thread_enable
  498. };