driver-icarus.c 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219
  1. /*
  2. * Copyright 2012-2013 Andrew Smith
  3. * Copyright 2012 Xiangfu <xiangfu@openmobilefree.com>
  4. * Copyright 2013 Con Kolivas <kernel@kolivas.org>
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the Free
  8. * Software Foundation; either version 3 of the License, or (at your option)
  9. * any later version. See COPYING for more details.
  10. */
  11. /*
  12. * Those code should be works fine with V2 and V3 bitstream of Icarus.
  13. * Operation:
  14. * No detection implement.
  15. * Input: 64B = 32B midstate + 20B fill bytes + last 12 bytes of block head.
  16. * Return: send back 32bits immediately when Icarus found a valid nonce.
  17. * no query protocol implemented here, if no data send back in ~11.3
  18. * seconds (full cover time on 32bit nonce range by 380MH/s speed)
  19. * just send another work.
  20. * Notice:
  21. * 1. Icarus will start calculate when you push a work to them, even they
  22. * are busy.
  23. * 2. The 2 FPGAs on Icarus will distribute the job, one will calculate the
  24. * 0 ~ 7FFFFFFF, another one will cover the 80000000 ~ FFFFFFFF.
  25. * 3. It's possible for 2 FPGAs both find valid nonce in the meantime, the 2
  26. * valid nonce will all be send back.
  27. * 4. Icarus will stop work when: a valid nonce has been found or 32 bits
  28. * nonce range is completely calculated.
  29. */
  30. #include <float.h>
  31. #include <limits.h>
  32. #include <pthread.h>
  33. #include <stdint.h>
  34. #include <stdio.h>
  35. #include <strings.h>
  36. #include <sys/time.h>
  37. #include <unistd.h>
  38. #include "config.h"
  39. #ifdef WIN32
  40. #include <windows.h>
  41. #endif
  42. #include "compat.h"
  43. #include "miner.h"
  44. #include "usbutils.h"
  45. // The serial I/O speed - Linux uses a define 'B115200' in bits/termios.h
  46. #define ICARUS_IO_SPEED 115200
  47. // The size of a successful nonce read
  48. #define ICARUS_READ_SIZE 4
  49. #define AMU_PREF_PACKET 256
  50. #define BLT_PREF_PACKET 512
  51. #define ICA_PREF_PACKET 256
  52. // Ensure the sizes are correct for the Serial read
  53. #if (ICARUS_READ_SIZE != 4)
  54. #error ICARUS_READ_SIZE must be 4
  55. #endif
  56. #define ASSERT1(condition) __maybe_unused static char sizeof_uint32_t_must_be_4[(condition)?1:-1]
  57. ASSERT1(sizeof(uint32_t) == 4);
  58. // TODO: USB? Different calculation? - see usbstats to work it out e.g. 1/2 of normal send time
  59. // or even use that number? 1/2
  60. // #define ICARUS_READ_TIME(baud) ((double)ICARUS_READ_SIZE * (double)8.0 / (double)(baud))
  61. // maybe 1ms?
  62. #define ICARUS_READ_TIME(baud) (0.001)
  63. // USB ms timeout to wait - user specified timeouts are multiples of this
  64. #define ICARUS_WAIT_TIMEOUT 100
  65. // Defined in multiples of ICARUS_WAIT_TIMEOUT
  66. // Must of course be greater than ICARUS_READ_COUNT_TIMING/ICARUS_WAIT_TIMEOUT
  67. // There's no need to have this bigger, since the overhead/latency of extra work
  68. // is pretty small once you get beyond a 10s nonce range time and 10s also
  69. // means that nothing slower than 429MH/s can go idle so most icarus devices
  70. // will always mine without idling
  71. #define ICARUS_READ_TIME_LIMIT_MAX 100
  72. // In timing mode: Default starting value until an estimate can be obtained
  73. // 5000 ms allows for up to a ~840MH/s device
  74. #define ICARUS_READ_COUNT_TIMING 5000
  75. #define ICARUS_READ_COUNT_MIN ICARUS_WAIT_TIMEOUT
  76. #define SECTOMS(s) ((int)((s) * 1000))
  77. // How many ms below the expected completion time to abort work
  78. // extra in case the last read is delayed
  79. #define ICARUS_READ_REDUCE ((int)(ICARUS_WAIT_TIMEOUT * 1.5))
  80. // For a standard Icarus REV3 (to 5 places)
  81. // Since this rounds up a the last digit - it is a slight overestimate
  82. // Thus the hash rate will be a VERY slight underestimate
  83. // (by a lot less than the displayed accuracy)
  84. // Minor inaccuracy of these numbers doesn't affect the work done,
  85. // only the displayed MH/s
  86. #define ICARUS_REV3_HASH_TIME 0.0000000026316
  87. #define LANCELOT_HASH_TIME 0.0000000025000
  88. #define ASICMINERUSB_HASH_TIME 0.0000000029761
  89. // TODO: What is it?
  90. #define CAIRNSMORE1_HASH_TIME 0.0000000027000
  91. // Per FPGA
  92. #define CAIRNSMORE2_HASH_TIME 0.0000000066600
  93. #define NANOSEC 1000000000.0
  94. // Icarus Rev3 doesn't send a completion message when it finishes
  95. // the full nonce range, so to avoid being idle we must abort the
  96. // work (by starting a new work item) shortly before it finishes
  97. //
  98. // Thus we need to estimate 2 things:
  99. // 1) How many hashes were done if the work was aborted
  100. // 2) How high can the timeout be before the Icarus is idle,
  101. // to minimise the number of work items started
  102. // We set 2) to 'the calculated estimate' - ICARUS_READ_REDUCE
  103. // to ensure the estimate ends before idle
  104. //
  105. // The simple calculation used is:
  106. // Tn = Total time in seconds to calculate n hashes
  107. // Hs = seconds per hash
  108. // Xn = number of hashes
  109. // W = code/usb overhead per work
  110. //
  111. // Rough but reasonable estimate:
  112. // Tn = Hs * Xn + W (of the form y = mx + b)
  113. //
  114. // Thus:
  115. // Line of best fit (using least squares)
  116. //
  117. // Hs = (n*Sum(XiTi)-Sum(Xi)*Sum(Ti))/(n*Sum(Xi^2)-Sum(Xi)^2)
  118. // W = Sum(Ti)/n - (Hs*Sum(Xi))/n
  119. //
  120. // N.B. W is less when aborting work since we aren't waiting for the reply
  121. // to be transferred back (ICARUS_READ_TIME)
  122. // Calculating the hashes aborted at n seconds is thus just n/Hs
  123. // (though this is still a slight overestimate due to code delays)
  124. //
  125. // Both below must be exceeded to complete a set of data
  126. // Minimum how long after the first, the last data point must be
  127. #define HISTORY_SEC 60
  128. // Minimum how many points a single ICARUS_HISTORY should have
  129. #define MIN_DATA_COUNT 5
  130. // The value MIN_DATA_COUNT used is doubled each history until it exceeds:
  131. #define MAX_MIN_DATA_COUNT 100
  132. static struct timeval history_sec = { HISTORY_SEC, 0 };
  133. // Store the last INFO_HISTORY data sets
  134. // [0] = current data, not yet ready to be included as an estimate
  135. // Each new data set throws the last old set off the end thus
  136. // keeping a ongoing average of recent data
  137. #define INFO_HISTORY 10
  138. struct ICARUS_HISTORY {
  139. struct timeval finish;
  140. double sumXiTi;
  141. double sumXi;
  142. double sumTi;
  143. double sumXi2;
  144. uint32_t values;
  145. uint32_t hash_count_min;
  146. uint32_t hash_count_max;
  147. };
  148. enum timing_mode { MODE_DEFAULT, MODE_SHORT, MODE_LONG, MODE_VALUE };
  149. static const char *MODE_DEFAULT_STR = "default";
  150. static const char *MODE_SHORT_STR = "short";
  151. static const char *MODE_SHORT_STREQ = "short=";
  152. static const char *MODE_LONG_STR = "long";
  153. static const char *MODE_LONG_STREQ = "long=";
  154. static const char *MODE_VALUE_STR = "value";
  155. static const char *MODE_UNKNOWN_STR = "unknown";
  156. struct ICARUS_INFO {
  157. int intinfo;
  158. // time to calculate the golden_ob
  159. uint64_t golden_hashes;
  160. struct timeval golden_tv;
  161. struct ICARUS_HISTORY history[INFO_HISTORY+1];
  162. uint32_t min_data_count;
  163. // seconds per Hash
  164. double Hs;
  165. // ms til we abort
  166. int read_time;
  167. // ms limit for (short=/long=) read_time
  168. int read_time_limit;
  169. enum timing_mode timing_mode;
  170. bool do_icarus_timing;
  171. double fullnonce;
  172. int count;
  173. double W;
  174. uint32_t values;
  175. uint64_t hash_count_range;
  176. // Determine the cost of history processing
  177. // (which will only affect W)
  178. uint64_t history_count;
  179. struct timeval history_time;
  180. // icarus-options
  181. int baud;
  182. int work_division;
  183. int fpga_count;
  184. uint32_t nonce_mask;
  185. bool initialised;
  186. };
  187. #define END_CONDITION 0x0000ffff
  188. // Looking for options in --icarus-timing and --icarus-options:
  189. //
  190. // Code increments this each time we start to look at a device
  191. // However, this means that if other devices are checked by
  192. // the Icarus code (e.g. Avalon only as at 20130517)
  193. // they will count in the option offset
  194. //
  195. // This, however, is deterministic so that's OK
  196. //
  197. // If we were to increment after successfully finding an Icarus
  198. // that would be random since an Icarus may fail and thus we'd
  199. // not be able to predict the option order
  200. //
  201. // Devices are checked in the order libusb finds them which is ?
  202. //
  203. static int option_offset = -1;
  204. /*
  205. #define ICA_BUFSIZ (0x200)
  206. static void transfer_read(struct cgpu_info *icarus, uint8_t request_type, uint8_t bRequest, uint16_t wValue, uint16_t wIndex, char *buf, int bufsiz, int *amount, enum usb_cmds cmd)
  207. {
  208. int err;
  209. err = usb_transfer_read(icarus, request_type, bRequest, wValue, wIndex, buf, bufsiz, amount, cmd);
  210. applog(LOG_DEBUG, "%s: cgid %d %s got err %d",
  211. icarus->drv->name, icarus->cgminer_id,
  212. usb_cmdname(cmd), err);
  213. }
  214. */
  215. static void _transfer(struct cgpu_info *icarus, uint8_t request_type, uint8_t bRequest, uint16_t wValue, uint16_t wIndex, uint32_t *data, int siz, enum usb_cmds cmd)
  216. {
  217. int err;
  218. err = usb_transfer_data(icarus, request_type, bRequest, wValue, wIndex, data, siz, cmd);
  219. applog(LOG_DEBUG, "%s: cgid %d %s got err %d",
  220. icarus->drv->name, icarus->cgminer_id,
  221. usb_cmdname(cmd), err);
  222. }
  223. #define transfer(icarus, request_type, bRequest, wValue, wIndex, cmd) \
  224. _transfer(icarus, request_type, bRequest, wValue, wIndex, NULL, 0, cmd)
  225. static void icarus_initialise(struct cgpu_info *icarus, int baud)
  226. {
  227. struct ICARUS_INFO *info = (struct ICARUS_INFO *)(icarus->device_data);
  228. uint16_t wValue, wIndex;
  229. enum sub_ident ident;
  230. int interface;
  231. if (icarus->usbinfo.nodev)
  232. return;
  233. usb_set_cps(icarus, baud / 10);
  234. usb_enable_cps(icarus);
  235. interface = _usb_interface(icarus, info->intinfo);
  236. ident = usb_ident(icarus);
  237. switch (ident) {
  238. case IDENT_BLT:
  239. case IDENT_LLT:
  240. case IDENT_CMR1:
  241. case IDENT_CMR2:
  242. usb_set_pps(icarus, BLT_PREF_PACKET);
  243. // Reset
  244. transfer(icarus, FTDI_TYPE_OUT, FTDI_REQUEST_RESET, FTDI_VALUE_RESET,
  245. interface, C_RESET);
  246. if (icarus->usbinfo.nodev)
  247. return;
  248. // Latency
  249. _usb_ftdi_set_latency(icarus, info->intinfo);
  250. if (icarus->usbinfo.nodev)
  251. return;
  252. // Set data control
  253. transfer(icarus, FTDI_TYPE_OUT, FTDI_REQUEST_DATA, FTDI_VALUE_DATA_BLT,
  254. interface, C_SETDATA);
  255. if (icarus->usbinfo.nodev)
  256. return;
  257. // default to BLT/LLT 115200
  258. wValue = FTDI_VALUE_BAUD_BLT;
  259. wIndex = FTDI_INDEX_BAUD_BLT;
  260. if (ident == IDENT_CMR1 || ident == IDENT_CMR2) {
  261. switch (baud) {
  262. case 115200:
  263. wValue = FTDI_VALUE_BAUD_CMR_115;
  264. wIndex = FTDI_INDEX_BAUD_CMR_115;
  265. break;
  266. case 57600:
  267. wValue = FTDI_VALUE_BAUD_CMR_57;
  268. wIndex = FTDI_INDEX_BAUD_CMR_57;
  269. break;
  270. default:
  271. quit(1, "icarus_intialise() invalid baud (%d) for Cairnsmore1", baud);
  272. break;
  273. }
  274. }
  275. // Set the baud
  276. transfer(icarus, FTDI_TYPE_OUT, FTDI_REQUEST_BAUD, wValue,
  277. (wIndex & 0xff00) | interface, C_SETBAUD);
  278. if (icarus->usbinfo.nodev)
  279. return;
  280. // Set Modem Control
  281. transfer(icarus, FTDI_TYPE_OUT, FTDI_REQUEST_MODEM, FTDI_VALUE_MODEM,
  282. interface, C_SETMODEM);
  283. if (icarus->usbinfo.nodev)
  284. return;
  285. // Set Flow Control
  286. transfer(icarus, FTDI_TYPE_OUT, FTDI_REQUEST_FLOW, FTDI_VALUE_FLOW,
  287. interface, C_SETFLOW);
  288. if (icarus->usbinfo.nodev)
  289. return;
  290. // Clear any sent data
  291. transfer(icarus, FTDI_TYPE_OUT, FTDI_REQUEST_RESET, FTDI_VALUE_PURGE_TX,
  292. interface, C_PURGETX);
  293. if (icarus->usbinfo.nodev)
  294. return;
  295. // Clear any received data
  296. transfer(icarus, FTDI_TYPE_OUT, FTDI_REQUEST_RESET, FTDI_VALUE_PURGE_RX,
  297. interface, C_PURGERX);
  298. break;
  299. case IDENT_ICA:
  300. usb_set_pps(icarus, ICA_PREF_PACKET);
  301. // Set Data Control
  302. transfer(icarus, PL2303_CTRL_OUT, PL2303_REQUEST_CTRL, PL2303_VALUE_CTRL,
  303. interface, C_SETDATA);
  304. if (icarus->usbinfo.nodev)
  305. return;
  306. // Set Line Control
  307. uint32_t ica_data[2] = { PL2303_VALUE_LINE0, PL2303_VALUE_LINE1 };
  308. _transfer(icarus, PL2303_CTRL_OUT, PL2303_REQUEST_LINE, PL2303_VALUE_LINE,
  309. interface, &ica_data[0], PL2303_VALUE_LINE_SIZE, C_SETLINE);
  310. if (icarus->usbinfo.nodev)
  311. return;
  312. // Vendor
  313. transfer(icarus, PL2303_VENDOR_OUT, PL2303_REQUEST_VENDOR, PL2303_VALUE_VENDOR,
  314. interface, C_VENDOR);
  315. break;
  316. case IDENT_AMU:
  317. usb_set_pps(icarus, AMU_PREF_PACKET);
  318. // Enable the UART
  319. transfer(icarus, CP210X_TYPE_OUT, CP210X_REQUEST_IFC_ENABLE,
  320. CP210X_VALUE_UART_ENABLE,
  321. interface, C_ENABLE_UART);
  322. if (icarus->usbinfo.nodev)
  323. return;
  324. // Set data control
  325. transfer(icarus, CP210X_TYPE_OUT, CP210X_REQUEST_DATA, CP210X_VALUE_DATA,
  326. interface, C_SETDATA);
  327. if (icarus->usbinfo.nodev)
  328. return;
  329. // Set the baud
  330. uint32_t data = CP210X_DATA_BAUD;
  331. _transfer(icarus, CP210X_TYPE_OUT, CP210X_REQUEST_BAUD, 0,
  332. interface, &data, sizeof(data), C_SETBAUD);
  333. break;
  334. default:
  335. quit(1, "icarus_intialise() called with invalid %s cgid %i ident=%d",
  336. icarus->drv->name, icarus->cgminer_id, ident);
  337. }
  338. info->initialised = true;
  339. }
  340. static void rev(unsigned char *s, size_t l)
  341. {
  342. size_t i, j;
  343. unsigned char t;
  344. for (i = 0, j = l - 1; i < j; i++, j--) {
  345. t = s[i];
  346. s[i] = s[j];
  347. s[j] = t;
  348. }
  349. }
  350. #define ICA_NONCE_ERROR -1
  351. #define ICA_NONCE_OK 0
  352. #define ICA_NONCE_RESTART 1
  353. #define ICA_NONCE_TIMEOUT 2
  354. static int icarus_get_nonce(struct cgpu_info *icarus, unsigned char *buf, struct timeval *tv_start, struct timeval *tv_finish, struct thr_info *thr, int read_time)
  355. {
  356. struct ICARUS_INFO *info = (struct ICARUS_INFO *)(icarus->device_data);
  357. struct timeval read_start, read_finish;
  358. int err, amt;
  359. int rc = 0;
  360. int read_amount = ICARUS_READ_SIZE;
  361. bool first = true;
  362. cgtime(tv_start);
  363. while (true) {
  364. if (icarus->usbinfo.nodev)
  365. return ICA_NONCE_ERROR;
  366. cgtime(&read_start);
  367. err = usb_read_ii_timeout(icarus, info->intinfo,
  368. (char *)buf, read_amount, &amt,
  369. ICARUS_WAIT_TIMEOUT, C_GETRESULTS);
  370. cgtime(&read_finish);
  371. if (err < 0 && err != LIBUSB_ERROR_TIMEOUT) {
  372. applog(LOG_ERR, "%s%i: Comms error (rerr=%d amt=%d)",
  373. icarus->drv->name, icarus->device_id, err, amt);
  374. dev_error(icarus, REASON_DEV_COMMS_ERROR);
  375. return ICA_NONCE_ERROR;
  376. }
  377. if (first)
  378. copy_time(tv_finish, &read_finish);
  379. if (amt >= read_amount)
  380. return ICA_NONCE_OK;
  381. rc = SECTOMS(tdiff(&read_finish, tv_start));
  382. if (rc >= read_time) {
  383. if (amt > 0)
  384. applog(LOG_DEBUG, "Icarus Read: Timeout reading for %d ms", rc);
  385. else
  386. applog(LOG_DEBUG, "Icarus Read: No data for %d ms", rc);
  387. return ICA_NONCE_TIMEOUT;
  388. }
  389. if (thr && thr->work_restart) {
  390. if (opt_debug) {
  391. applog(LOG_DEBUG,
  392. "Icarus Read: Work restart at %d ms", rc);
  393. }
  394. return ICA_NONCE_RESTART;
  395. }
  396. if (amt > 0) {
  397. buf += amt;
  398. read_amount -= amt;
  399. first = false;
  400. }
  401. }
  402. }
  403. static const char *timing_mode_str(enum timing_mode timing_mode)
  404. {
  405. switch(timing_mode) {
  406. case MODE_DEFAULT:
  407. return MODE_DEFAULT_STR;
  408. case MODE_SHORT:
  409. return MODE_SHORT_STR;
  410. case MODE_LONG:
  411. return MODE_LONG_STR;
  412. case MODE_VALUE:
  413. return MODE_VALUE_STR;
  414. default:
  415. return MODE_UNKNOWN_STR;
  416. }
  417. }
  418. static void set_timing_mode(int this_option_offset, struct cgpu_info *icarus)
  419. {
  420. struct ICARUS_INFO *info = (struct ICARUS_INFO *)(icarus->device_data);
  421. enum sub_ident ident;
  422. double Hs;
  423. char buf[BUFSIZ+1];
  424. char *ptr, *comma, *eq;
  425. size_t max;
  426. int i;
  427. if (opt_icarus_timing == NULL)
  428. buf[0] = '\0';
  429. else {
  430. ptr = opt_icarus_timing;
  431. for (i = 0; i < this_option_offset; i++) {
  432. comma = strchr(ptr, ',');
  433. if (comma == NULL)
  434. break;
  435. ptr = comma + 1;
  436. }
  437. comma = strchr(ptr, ',');
  438. if (comma == NULL)
  439. max = strlen(ptr);
  440. else
  441. max = comma - ptr;
  442. if (max > BUFSIZ)
  443. max = BUFSIZ;
  444. strncpy(buf, ptr, max);
  445. buf[max] = '\0';
  446. }
  447. ident = usb_ident(icarus);
  448. switch (ident) {
  449. case IDENT_ICA:
  450. info->Hs = ICARUS_REV3_HASH_TIME;
  451. break;
  452. case IDENT_BLT:
  453. case IDENT_LLT:
  454. info->Hs = LANCELOT_HASH_TIME;
  455. break;
  456. case IDENT_AMU:
  457. info->Hs = ASICMINERUSB_HASH_TIME;
  458. break;
  459. case IDENT_CMR1:
  460. info->Hs = CAIRNSMORE1_HASH_TIME;
  461. break;
  462. case IDENT_CMR2:
  463. info->Hs = CAIRNSMORE2_HASH_TIME;
  464. break;
  465. default:
  466. quit(1, "Icarus get_options() called with invalid %s ident=%d",
  467. icarus->drv->name, ident);
  468. }
  469. info->read_time = 0;
  470. info->read_time_limit = 0; // 0 = no limit
  471. if (strcasecmp(buf, MODE_SHORT_STR) == 0) {
  472. // short
  473. info->read_time = ICARUS_READ_COUNT_TIMING;
  474. info->timing_mode = MODE_SHORT;
  475. info->do_icarus_timing = true;
  476. } else if (strncasecmp(buf, MODE_SHORT_STREQ, strlen(MODE_SHORT_STREQ)) == 0) {
  477. // short=limit
  478. info->read_time = ICARUS_READ_COUNT_TIMING;
  479. info->timing_mode = MODE_SHORT;
  480. info->do_icarus_timing = true;
  481. info->read_time_limit = atoi(&buf[strlen(MODE_SHORT_STREQ)]);
  482. if (info->read_time_limit < 0)
  483. info->read_time_limit = 0;
  484. if (info->read_time_limit > ICARUS_READ_TIME_LIMIT_MAX)
  485. info->read_time_limit = ICARUS_READ_TIME_LIMIT_MAX;
  486. } else if (strcasecmp(buf, MODE_LONG_STR) == 0) {
  487. // long
  488. info->read_time = ICARUS_READ_COUNT_TIMING;
  489. info->timing_mode = MODE_LONG;
  490. info->do_icarus_timing = true;
  491. } else if (strncasecmp(buf, MODE_LONG_STREQ, strlen(MODE_LONG_STREQ)) == 0) {
  492. // long=limit
  493. info->read_time = ICARUS_READ_COUNT_TIMING;
  494. info->timing_mode = MODE_LONG;
  495. info->do_icarus_timing = true;
  496. info->read_time_limit = atoi(&buf[strlen(MODE_LONG_STREQ)]);
  497. if (info->read_time_limit < 0)
  498. info->read_time_limit = 0;
  499. if (info->read_time_limit > ICARUS_READ_TIME_LIMIT_MAX)
  500. info->read_time_limit = ICARUS_READ_TIME_LIMIT_MAX;
  501. } else if ((Hs = atof(buf)) != 0) {
  502. // ns[=read_time]
  503. info->Hs = Hs / NANOSEC;
  504. info->fullnonce = info->Hs * (((double)0xffffffff) + 1);
  505. if ((eq = strchr(buf, '=')) != NULL)
  506. info->read_time = atoi(eq+1) * ICARUS_WAIT_TIMEOUT;
  507. if (info->read_time < ICARUS_READ_COUNT_MIN)
  508. info->read_time = SECTOMS(info->fullnonce) - ICARUS_READ_REDUCE;
  509. if (unlikely(info->read_time < ICARUS_READ_COUNT_MIN))
  510. info->read_time = ICARUS_READ_COUNT_MIN;
  511. info->timing_mode = MODE_VALUE;
  512. info->do_icarus_timing = false;
  513. } else {
  514. // Anything else in buf just uses DEFAULT mode
  515. info->fullnonce = info->Hs * (((double)0xffffffff) + 1);
  516. if ((eq = strchr(buf, '=')) != NULL)
  517. info->read_time = atoi(eq+1) * ICARUS_WAIT_TIMEOUT;
  518. if (info->read_time < ICARUS_READ_COUNT_MIN)
  519. info->read_time = SECTOMS(info->fullnonce) - ICARUS_READ_REDUCE;
  520. if (unlikely(info->read_time < ICARUS_READ_COUNT_MIN))
  521. info->read_time = ICARUS_READ_COUNT_MIN;
  522. info->timing_mode = MODE_DEFAULT;
  523. info->do_icarus_timing = false;
  524. }
  525. info->min_data_count = MIN_DATA_COUNT;
  526. // All values are in multiples of ICARUS_WAIT_TIMEOUT
  527. info->read_time_limit *= ICARUS_WAIT_TIMEOUT;
  528. applog(LOG_DEBUG, "%s: cgid %d Init: mode=%s read_time=%dms limit=%dms Hs=%e",
  529. icarus->drv->name, icarus->cgminer_id,
  530. timing_mode_str(info->timing_mode),
  531. info->read_time, info->read_time_limit, info->Hs);
  532. }
  533. static uint32_t mask(int work_division)
  534. {
  535. uint32_t nonce_mask = 0x7fffffff;
  536. // yes we can calculate these, but this way it's easy to see what they are
  537. switch (work_division) {
  538. case 1:
  539. nonce_mask = 0xffffffff;
  540. break;
  541. case 2:
  542. nonce_mask = 0x7fffffff;
  543. break;
  544. case 4:
  545. nonce_mask = 0x3fffffff;
  546. break;
  547. case 8:
  548. nonce_mask = 0x1fffffff;
  549. break;
  550. default:
  551. quit(1, "Invalid2 icarus-options for work_division (%d) must be 1, 2, 4 or 8", work_division);
  552. }
  553. return nonce_mask;
  554. }
  555. static void get_options(int this_option_offset, struct cgpu_info *icarus, int *baud, int *work_division, int *fpga_count)
  556. {
  557. char buf[BUFSIZ+1];
  558. char *ptr, *comma, *colon, *colon2;
  559. enum sub_ident ident;
  560. size_t max;
  561. int i, tmp;
  562. if (opt_icarus_options == NULL)
  563. buf[0] = '\0';
  564. else {
  565. ptr = opt_icarus_options;
  566. for (i = 0; i < this_option_offset; i++) {
  567. comma = strchr(ptr, ',');
  568. if (comma == NULL)
  569. break;
  570. ptr = comma + 1;
  571. }
  572. comma = strchr(ptr, ',');
  573. if (comma == NULL)
  574. max = strlen(ptr);
  575. else
  576. max = comma - ptr;
  577. if (max > BUFSIZ)
  578. max = BUFSIZ;
  579. strncpy(buf, ptr, max);
  580. buf[max] = '\0';
  581. }
  582. ident = usb_ident(icarus);
  583. switch (ident) {
  584. case IDENT_ICA:
  585. case IDENT_BLT:
  586. case IDENT_LLT:
  587. *baud = ICARUS_IO_SPEED;
  588. *work_division = 2;
  589. *fpga_count = 2;
  590. break;
  591. case IDENT_AMU:
  592. *baud = ICARUS_IO_SPEED;
  593. *work_division = 1;
  594. *fpga_count = 1;
  595. break;
  596. case IDENT_CMR1:
  597. *baud = ICARUS_IO_SPEED;
  598. *work_division = 2;
  599. *fpga_count = 2;
  600. break;
  601. case IDENT_CMR2:
  602. *baud = ICARUS_IO_SPEED;
  603. *work_division = 1;
  604. *fpga_count = 1;
  605. break;
  606. default:
  607. quit(1, "Icarus get_options() called with invalid %s ident=%d",
  608. icarus->drv->name, ident);
  609. }
  610. if (*buf) {
  611. colon = strchr(buf, ':');
  612. if (colon)
  613. *(colon++) = '\0';
  614. if (*buf) {
  615. tmp = atoi(buf);
  616. switch (tmp) {
  617. case 115200:
  618. *baud = 115200;
  619. break;
  620. case 57600:
  621. *baud = 57600;
  622. break;
  623. default:
  624. quit(1, "Invalid icarus-options for baud (%s) must be 115200 or 57600", buf);
  625. }
  626. }
  627. if (colon && *colon) {
  628. colon2 = strchr(colon, ':');
  629. if (colon2)
  630. *(colon2++) = '\0';
  631. if (*colon) {
  632. tmp = atoi(colon);
  633. if (tmp == 1 || tmp == 2 || tmp == 4 || tmp == 8) {
  634. *work_division = tmp;
  635. *fpga_count = tmp; // default to the same
  636. } else {
  637. quit(1, "Invalid icarus-options for work_division (%s) must be 1, 2, 4 or 8", colon);
  638. }
  639. }
  640. if (colon2 && *colon2) {
  641. tmp = atoi(colon2);
  642. if (tmp > 0 && tmp <= *work_division)
  643. *fpga_count = tmp;
  644. else {
  645. quit(1, "Invalid icarus-options for fpga_count (%s) must be >0 and <=work_division (%d)", colon2, *work_division);
  646. }
  647. }
  648. }
  649. }
  650. }
  651. static bool icarus_detect_one(struct libusb_device *dev, struct usb_find_devices *found)
  652. {
  653. int this_option_offset = ++option_offset;
  654. struct ICARUS_INFO *info;
  655. struct timeval tv_start, tv_finish;
  656. // Block 171874 nonce = (0xa2870100) = 0x000187a2
  657. // N.B. golden_ob MUST take less time to calculate
  658. // than the timeout set in icarus_open()
  659. // This one takes ~0.53ms on Rev3 Icarus
  660. const char golden_ob[] =
  661. "4679ba4ec99876bf4bfe086082b40025"
  662. "4df6c356451471139a3afa71e48f544a"
  663. "00000000000000000000000000000000"
  664. "0000000087320b1a1426674f2fa722ce";
  665. const char golden_nonce[] = "000187a2";
  666. const uint32_t golden_nonce_val = 0x000187a2;
  667. unsigned char ob_bin[64], nonce_bin[ICARUS_READ_SIZE];
  668. char *nonce_hex;
  669. int baud, uninitialised_var(work_division), uninitialised_var(fpga_count);
  670. struct cgpu_info *icarus;
  671. int ret, err, amount, tries;
  672. bool ok;
  673. icarus = usb_alloc_cgpu(&icarus_drv, 1);
  674. if (!usb_init(icarus, dev, found))
  675. goto shin;
  676. usb_buffer_enable(icarus);
  677. get_options(this_option_offset, icarus, &baud, &work_division, &fpga_count);
  678. hex2bin(ob_bin, golden_ob, sizeof(ob_bin));
  679. info = (struct ICARUS_INFO *)calloc(1, sizeof(struct ICARUS_INFO));
  680. if (unlikely(!info))
  681. quit(1, "Failed to malloc ICARUS_INFO");
  682. icarus->device_data = (void *)info;
  683. tries = 2;
  684. ok = false;
  685. while (!ok && tries-- > 0) {
  686. icarus_initialise(icarus, baud);
  687. err = usb_write(icarus, (char *)ob_bin, sizeof(ob_bin), &amount, C_SENDTESTWORK);
  688. if (err != LIBUSB_SUCCESS || amount != sizeof(ob_bin))
  689. continue;
  690. memset(nonce_bin, 0, sizeof(nonce_bin));
  691. ret = icarus_get_nonce(icarus, nonce_bin, &tv_start, &tv_finish, NULL, 100);
  692. if (ret != ICA_NONCE_OK)
  693. continue;
  694. nonce_hex = bin2hex(nonce_bin, sizeof(nonce_bin));
  695. if (strncmp(nonce_hex, golden_nonce, 8) == 0)
  696. ok = true;
  697. else {
  698. if (tries < 0) {
  699. applog(LOG_ERR,
  700. "Icarus Detect: "
  701. "Test failed at %s: get %s, should: %s",
  702. icarus->device_path, nonce_hex, golden_nonce);
  703. }
  704. }
  705. free(nonce_hex);
  706. }
  707. if (!ok)
  708. goto unshin;
  709. applog(LOG_DEBUG,
  710. "Icarus Detect: "
  711. "Test succeeded at %s: got %s",
  712. icarus->device_path, golden_nonce);
  713. /* We have a real Icarus! */
  714. if (!add_cgpu(icarus))
  715. goto unshin;
  716. update_usb_stats(icarus);
  717. applog(LOG_INFO, "%s%d: Found at %s",
  718. icarus->drv->name, icarus->device_id, icarus->device_path);
  719. applog(LOG_DEBUG, "%s%d: Init baud=%d work_division=%d fpga_count=%d",
  720. icarus->drv->name, icarus->device_id, baud, work_division, fpga_count);
  721. info->baud = baud;
  722. info->work_division = work_division;
  723. info->fpga_count = fpga_count;
  724. info->nonce_mask = mask(work_division);
  725. info->golden_hashes = (golden_nonce_val & info->nonce_mask) * fpga_count;
  726. timersub(&tv_finish, &tv_start, &(info->golden_tv));
  727. set_timing_mode(this_option_offset, icarus);
  728. if (usb_ident(icarus) == IDENT_CMR2) {
  729. int i;
  730. for (i = 1; i < icarus->usbdev->found->intinfo_count; i++) {
  731. struct cgpu_info *cgtmp;
  732. struct ICARUS_INFO *intmp;
  733. cgtmp = usb_copy_cgpu(icarus);
  734. if (!cgtmp) {
  735. applog(LOG_ERR, "%s%d: Init failed initinfo %d",
  736. icarus->drv->name, icarus->device_id, i);
  737. continue;
  738. }
  739. cgtmp->usbinfo.usbstat = USB_NOSTAT;
  740. intmp = (struct ICARUS_INFO *)malloc(sizeof(struct ICARUS_INFO));
  741. if (unlikely(!intmp))
  742. quit(1, "Failed2 to malloc ICARUS_INFO");
  743. cgtmp->device_data = (void *)intmp;
  744. // Initialise everything to match
  745. memcpy(intmp, info, sizeof(struct ICARUS_INFO));
  746. intmp->intinfo = i;
  747. icarus_initialise(cgtmp, baud);
  748. if (!add_cgpu(cgtmp)) {
  749. usb_uninit(cgtmp);
  750. free(intmp);
  751. continue;
  752. }
  753. update_usb_stats(cgtmp);
  754. }
  755. }
  756. return true;
  757. unshin:
  758. usb_uninit(icarus);
  759. free(info);
  760. icarus->device_data = NULL;
  761. shin:
  762. icarus = usb_free_cgpu(icarus);
  763. return false;
  764. }
  765. static void icarus_detect(bool __maybe_unused hotplug)
  766. {
  767. usb_detect(&icarus_drv, icarus_detect_one);
  768. }
  769. static bool icarus_prepare(__maybe_unused struct thr_info *thr)
  770. {
  771. // struct cgpu_info *icarus = thr->cgpu;
  772. return true;
  773. }
  774. static int64_t icarus_scanhash(struct thr_info *thr, struct work *work,
  775. __maybe_unused int64_t max_nonce)
  776. {
  777. struct cgpu_info *icarus = thr->cgpu;
  778. struct ICARUS_INFO *info = (struct ICARUS_INFO *)(icarus->device_data);
  779. int ret, err, amount;
  780. unsigned char ob_bin[64], nonce_bin[ICARUS_READ_SIZE];
  781. char *ob_hex;
  782. uint32_t nonce;
  783. int64_t hash_count;
  784. struct timeval tv_start, tv_finish, elapsed;
  785. struct timeval tv_history_start, tv_history_finish;
  786. double Ti, Xi;
  787. int curr_hw_errors, i;
  788. bool was_hw_error;
  789. struct ICARUS_HISTORY *history0, *history;
  790. int count;
  791. double Hs, W, fullnonce;
  792. int read_time;
  793. bool limited;
  794. int64_t estimate_hashes;
  795. uint32_t values;
  796. int64_t hash_count_range;
  797. // Device is gone
  798. if (icarus->usbinfo.nodev)
  799. return -1;
  800. if (!info->initialised)
  801. icarus_initialise(icarus, info->baud);
  802. elapsed.tv_sec = elapsed.tv_usec = 0;
  803. memset(ob_bin, 0, sizeof(ob_bin));
  804. memcpy(ob_bin, work->midstate, 32);
  805. memcpy(ob_bin + 52, work->data + 64, 12);
  806. rev(ob_bin, 32);
  807. rev(ob_bin + 52, 12);
  808. // We only want results for the work we are about to send
  809. usb_buffer_clear(icarus);
  810. err = usb_write_ii(icarus, info->intinfo, (char *)ob_bin, sizeof(ob_bin), &amount, C_SENDWORK);
  811. if (err < 0 || amount != sizeof(ob_bin)) {
  812. applog(LOG_ERR, "%s%i: Comms error (werr=%d amt=%d)",
  813. icarus->drv->name, icarus->device_id, err, amount);
  814. dev_error(icarus, REASON_DEV_COMMS_ERROR);
  815. icarus_initialise(icarus, info->baud);
  816. return 0;
  817. }
  818. if (opt_debug) {
  819. ob_hex = bin2hex(ob_bin, sizeof(ob_bin));
  820. applog(LOG_DEBUG, "%s%d: sent %s",
  821. icarus->drv->name, icarus->device_id, ob_hex);
  822. free(ob_hex);
  823. }
  824. /* Icarus will return 4 bytes (ICARUS_READ_SIZE) nonces or nothing */
  825. memset(nonce_bin, 0, sizeof(nonce_bin));
  826. ret = icarus_get_nonce(icarus, nonce_bin, &tv_start, &tv_finish, thr, info->read_time);
  827. if (ret == ICA_NONCE_ERROR)
  828. return 0;
  829. work->blk.nonce = 0xffffffff;
  830. // aborted before becoming idle, get new work
  831. if (ret == ICA_NONCE_TIMEOUT || ret == ICA_NONCE_RESTART) {
  832. timersub(&tv_finish, &tv_start, &elapsed);
  833. // ONLY up to just when it aborted
  834. // We didn't read a reply so we don't subtract ICARUS_READ_TIME
  835. estimate_hashes = ((double)(elapsed.tv_sec)
  836. + ((double)(elapsed.tv_usec))/((double)1000000)) / info->Hs;
  837. // If some Serial-USB delay allowed the full nonce range to
  838. // complete it can't have done more than a full nonce
  839. if (unlikely(estimate_hashes > 0xffffffff))
  840. estimate_hashes = 0xffffffff;
  841. if (opt_debug) {
  842. applog(LOG_DEBUG, "%s%d: no nonce = 0x%08lX hashes (%ld.%06lds)",
  843. icarus->drv->name, icarus->device_id,
  844. (long unsigned int)estimate_hashes,
  845. elapsed.tv_sec, elapsed.tv_usec);
  846. }
  847. return estimate_hashes;
  848. }
  849. memcpy((char *)&nonce, nonce_bin, sizeof(nonce_bin));
  850. nonce = htobe32(nonce);
  851. curr_hw_errors = icarus->hw_errors;
  852. submit_nonce(thr, work, nonce);
  853. was_hw_error = (curr_hw_errors > icarus->hw_errors);
  854. hash_count = (nonce & info->nonce_mask);
  855. hash_count++;
  856. hash_count *= info->fpga_count;
  857. #if 0
  858. // This appears to only return zero nonce values
  859. if (usb_buffer_size(icarus) > 3) {
  860. memcpy((char *)&nonce, icarus->usbdev->buffer, sizeof(nonce_bin));
  861. nonce = htobe32(nonce);
  862. applog(LOG_WARNING, "%s%d: attempting to submit 2nd nonce = 0x%08lX",
  863. icarus->drv->name, icarus->device_id,
  864. (long unsigned int)nonce);
  865. curr_hw_errors = icarus->hw_errors;
  866. submit_nonce(thr, work, nonce);
  867. was_hw_error = (curr_hw_errors > icarus->hw_errors);
  868. }
  869. #endif
  870. if (opt_debug || info->do_icarus_timing)
  871. timersub(&tv_finish, &tv_start, &elapsed);
  872. if (opt_debug) {
  873. applog(LOG_DEBUG, "%s%d: nonce = 0x%08x = 0x%08lX hashes (%ld.%06lds)",
  874. icarus->drv->name, icarus->device_id,
  875. nonce, (long unsigned int)hash_count,
  876. elapsed.tv_sec, elapsed.tv_usec);
  877. }
  878. // Ignore possible end condition values ... and hw errors
  879. // TODO: set limitations on calculated values depending on the device
  880. // to avoid crap values caused by CPU/Task Switching/Swapping/etc
  881. if (info->do_icarus_timing
  882. && !was_hw_error
  883. && ((nonce & info->nonce_mask) > END_CONDITION)
  884. && ((nonce & info->nonce_mask) < (info->nonce_mask & ~END_CONDITION))) {
  885. cgtime(&tv_history_start);
  886. history0 = &(info->history[0]);
  887. if (history0->values == 0)
  888. timeradd(&tv_start, &history_sec, &(history0->finish));
  889. Ti = (double)(elapsed.tv_sec)
  890. + ((double)(elapsed.tv_usec))/((double)1000000)
  891. - ((double)ICARUS_READ_TIME(info->baud));
  892. Xi = (double)hash_count;
  893. history0->sumXiTi += Xi * Ti;
  894. history0->sumXi += Xi;
  895. history0->sumTi += Ti;
  896. history0->sumXi2 += Xi * Xi;
  897. history0->values++;
  898. if (history0->hash_count_max < hash_count)
  899. history0->hash_count_max = hash_count;
  900. if (history0->hash_count_min > hash_count || history0->hash_count_min == 0)
  901. history0->hash_count_min = hash_count;
  902. if (history0->values >= info->min_data_count
  903. && timercmp(&tv_start, &(history0->finish), >)) {
  904. for (i = INFO_HISTORY; i > 0; i--)
  905. memcpy(&(info->history[i]),
  906. &(info->history[i-1]),
  907. sizeof(struct ICARUS_HISTORY));
  908. // Initialise history0 to zero for summary calculation
  909. memset(history0, 0, sizeof(struct ICARUS_HISTORY));
  910. // We just completed a history data set
  911. // So now recalc read_time based on the whole history thus we will
  912. // initially get more accurate until it completes INFO_HISTORY
  913. // total data sets
  914. count = 0;
  915. for (i = 1 ; i <= INFO_HISTORY; i++) {
  916. history = &(info->history[i]);
  917. if (history->values >= MIN_DATA_COUNT) {
  918. count++;
  919. history0->sumXiTi += history->sumXiTi;
  920. history0->sumXi += history->sumXi;
  921. history0->sumTi += history->sumTi;
  922. history0->sumXi2 += history->sumXi2;
  923. history0->values += history->values;
  924. if (history0->hash_count_max < history->hash_count_max)
  925. history0->hash_count_max = history->hash_count_max;
  926. if (history0->hash_count_min > history->hash_count_min || history0->hash_count_min == 0)
  927. history0->hash_count_min = history->hash_count_min;
  928. }
  929. }
  930. // All history data
  931. Hs = (history0->values*history0->sumXiTi - history0->sumXi*history0->sumTi)
  932. / (history0->values*history0->sumXi2 - history0->sumXi*history0->sumXi);
  933. W = history0->sumTi/history0->values - Hs*history0->sumXi/history0->values;
  934. hash_count_range = history0->hash_count_max - history0->hash_count_min;
  935. values = history0->values;
  936. // Initialise history0 to zero for next data set
  937. memset(history0, 0, sizeof(struct ICARUS_HISTORY));
  938. fullnonce = W + Hs * (((double)0xffffffff) + 1);
  939. read_time = SECTOMS(fullnonce) - ICARUS_READ_REDUCE;
  940. if (info->read_time_limit > 0 && read_time > info->read_time_limit) {
  941. read_time = info->read_time_limit;
  942. limited = true;
  943. } else
  944. limited = false;
  945. info->Hs = Hs;
  946. info->read_time = read_time;
  947. info->fullnonce = fullnonce;
  948. info->count = count;
  949. info->W = W;
  950. info->values = values;
  951. info->hash_count_range = hash_count_range;
  952. if (info->min_data_count < MAX_MIN_DATA_COUNT)
  953. info->min_data_count *= 2;
  954. else if (info->timing_mode == MODE_SHORT)
  955. info->do_icarus_timing = false;
  956. applog(LOG_WARNING, "%s%d Re-estimate: Hs=%e W=%e read_time=%dms%s fullnonce=%.3fs",
  957. icarus->drv->name, icarus->device_id, Hs, W, read_time,
  958. limited ? " (limited)" : "", fullnonce);
  959. }
  960. info->history_count++;
  961. cgtime(&tv_history_finish);
  962. timersub(&tv_history_finish, &tv_history_start, &tv_history_finish);
  963. timeradd(&tv_history_finish, &(info->history_time), &(info->history_time));
  964. }
  965. return hash_count;
  966. }
  967. static struct api_data *icarus_api_stats(struct cgpu_info *cgpu)
  968. {
  969. struct api_data *root = NULL;
  970. struct ICARUS_INFO *info = (struct ICARUS_INFO *)(cgpu->device_data);
  971. // Warning, access to these is not locked - but we don't really
  972. // care since hashing performance is way more important than
  973. // locking access to displaying API debug 'stats'
  974. // If locking becomes an issue for any of them, use copy_data=true also
  975. root = api_add_int(root, "read_time", &(info->read_time), false);
  976. root = api_add_int(root, "read_time_limit", &(info->read_time_limit), false);
  977. root = api_add_double(root, "fullnonce", &(info->fullnonce), false);
  978. root = api_add_int(root, "count", &(info->count), false);
  979. root = api_add_hs(root, "Hs", &(info->Hs), false);
  980. root = api_add_double(root, "W", &(info->W), false);
  981. root = api_add_uint(root, "total_values", &(info->values), false);
  982. root = api_add_uint64(root, "range", &(info->hash_count_range), false);
  983. root = api_add_uint64(root, "history_count", &(info->history_count), false);
  984. root = api_add_timeval(root, "history_time", &(info->history_time), false);
  985. root = api_add_uint(root, "min_data_count", &(info->min_data_count), false);
  986. root = api_add_uint(root, "timing_values", &(info->history[0].values), false);
  987. root = api_add_const(root, "timing_mode", timing_mode_str(info->timing_mode), false);
  988. root = api_add_bool(root, "is_timing", &(info->do_icarus_timing), false);
  989. root = api_add_int(root, "baud", &(info->baud), false);
  990. root = api_add_int(root, "work_division", &(info->work_division), false);
  991. root = api_add_int(root, "fpga_count", &(info->fpga_count), false);
  992. return root;
  993. }
  994. static void icarus_shutdown(__maybe_unused struct thr_info *thr)
  995. {
  996. // TODO: ?
  997. }
  998. struct device_drv icarus_drv = {
  999. .drv_id = DRIVER_icarus,
  1000. .dname = "Icarus",
  1001. .name = "ICA",
  1002. .drv_detect = icarus_detect,
  1003. .get_api_stats = icarus_api_stats,
  1004. .thread_prepare = icarus_prepare,
  1005. .scanhash = icarus_scanhash,
  1006. .thread_shutdown = icarus_shutdown,
  1007. };