driver-icarus.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221
  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. struct device_drv icarus_drv;
  205. /*
  206. #define ICA_BUFSIZ (0x200)
  207. 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)
  208. {
  209. int err;
  210. err = usb_transfer_read(icarus, request_type, bRequest, wValue, wIndex, buf, bufsiz, amount, cmd);
  211. applog(LOG_DEBUG, "%s: cgid %d %s got err %d",
  212. icarus->drv->name, icarus->cgminer_id,
  213. usb_cmdname(cmd), err);
  214. }
  215. */
  216. 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)
  217. {
  218. int err;
  219. err = usb_transfer_data(icarus, request_type, bRequest, wValue, wIndex, data, siz, cmd);
  220. applog(LOG_DEBUG, "%s: cgid %d %s got err %d",
  221. icarus->drv->name, icarus->cgminer_id,
  222. usb_cmdname(cmd), err);
  223. }
  224. #define transfer(icarus, request_type, bRequest, wValue, wIndex, cmd) \
  225. _transfer(icarus, request_type, bRequest, wValue, wIndex, NULL, 0, cmd)
  226. static void icarus_initialise(struct cgpu_info *icarus, int baud)
  227. {
  228. struct ICARUS_INFO *info = (struct ICARUS_INFO *)(icarus->device_data);
  229. uint16_t wValue, wIndex;
  230. enum sub_ident ident;
  231. int interface;
  232. if (icarus->usbinfo.nodev)
  233. return;
  234. usb_set_cps(icarus, baud / 10);
  235. usb_enable_cps(icarus);
  236. interface = _usb_interface(icarus, info->intinfo);
  237. ident = usb_ident(icarus);
  238. switch (ident) {
  239. case IDENT_BLT:
  240. case IDENT_LLT:
  241. case IDENT_CMR1:
  242. case IDENT_CMR2:
  243. usb_set_pps(icarus, BLT_PREF_PACKET);
  244. // Reset
  245. transfer(icarus, FTDI_TYPE_OUT, FTDI_REQUEST_RESET, FTDI_VALUE_RESET,
  246. interface, C_RESET);
  247. if (icarus->usbinfo.nodev)
  248. return;
  249. // Latency
  250. _usb_ftdi_set_latency(icarus, info->intinfo);
  251. if (icarus->usbinfo.nodev)
  252. return;
  253. // Set data control
  254. transfer(icarus, FTDI_TYPE_OUT, FTDI_REQUEST_DATA, FTDI_VALUE_DATA_BLT,
  255. interface, C_SETDATA);
  256. if (icarus->usbinfo.nodev)
  257. return;
  258. // default to BLT/LLT 115200
  259. wValue = FTDI_VALUE_BAUD_BLT;
  260. wIndex = FTDI_INDEX_BAUD_BLT;
  261. if (ident == IDENT_CMR1 || ident == IDENT_CMR2) {
  262. switch (baud) {
  263. case 115200:
  264. wValue = FTDI_VALUE_BAUD_CMR_115;
  265. wIndex = FTDI_INDEX_BAUD_CMR_115;
  266. break;
  267. case 57600:
  268. wValue = FTDI_VALUE_BAUD_CMR_57;
  269. wIndex = FTDI_INDEX_BAUD_CMR_57;
  270. break;
  271. default:
  272. quit(1, "icarus_intialise() invalid baud (%d) for Cairnsmore1", baud);
  273. break;
  274. }
  275. }
  276. // Set the baud
  277. transfer(icarus, FTDI_TYPE_OUT, FTDI_REQUEST_BAUD, wValue,
  278. (wIndex & 0xff00) | interface, C_SETBAUD);
  279. if (icarus->usbinfo.nodev)
  280. return;
  281. // Set Modem Control
  282. transfer(icarus, FTDI_TYPE_OUT, FTDI_REQUEST_MODEM, FTDI_VALUE_MODEM,
  283. interface, C_SETMODEM);
  284. if (icarus->usbinfo.nodev)
  285. return;
  286. // Set Flow Control
  287. transfer(icarus, FTDI_TYPE_OUT, FTDI_REQUEST_FLOW, FTDI_VALUE_FLOW,
  288. interface, C_SETFLOW);
  289. if (icarus->usbinfo.nodev)
  290. return;
  291. // Clear any sent data
  292. transfer(icarus, FTDI_TYPE_OUT, FTDI_REQUEST_RESET, FTDI_VALUE_PURGE_TX,
  293. interface, C_PURGETX);
  294. if (icarus->usbinfo.nodev)
  295. return;
  296. // Clear any received data
  297. transfer(icarus, FTDI_TYPE_OUT, FTDI_REQUEST_RESET, FTDI_VALUE_PURGE_RX,
  298. interface, C_PURGERX);
  299. break;
  300. case IDENT_ICA:
  301. usb_set_pps(icarus, ICA_PREF_PACKET);
  302. // Set Data Control
  303. transfer(icarus, PL2303_CTRL_OUT, PL2303_REQUEST_CTRL, PL2303_VALUE_CTRL,
  304. interface, C_SETDATA);
  305. if (icarus->usbinfo.nodev)
  306. return;
  307. // Set Line Control
  308. uint32_t ica_data[2] = { PL2303_VALUE_LINE0, PL2303_VALUE_LINE1 };
  309. _transfer(icarus, PL2303_CTRL_OUT, PL2303_REQUEST_LINE, PL2303_VALUE_LINE,
  310. interface, &ica_data[0], PL2303_VALUE_LINE_SIZE, C_SETLINE);
  311. if (icarus->usbinfo.nodev)
  312. return;
  313. // Vendor
  314. transfer(icarus, PL2303_VENDOR_OUT, PL2303_REQUEST_VENDOR, PL2303_VALUE_VENDOR,
  315. interface, C_VENDOR);
  316. break;
  317. case IDENT_AMU:
  318. usb_set_pps(icarus, AMU_PREF_PACKET);
  319. // Enable the UART
  320. transfer(icarus, CP210X_TYPE_OUT, CP210X_REQUEST_IFC_ENABLE,
  321. CP210X_VALUE_UART_ENABLE,
  322. interface, C_ENABLE_UART);
  323. if (icarus->usbinfo.nodev)
  324. return;
  325. // Set data control
  326. transfer(icarus, CP210X_TYPE_OUT, CP210X_REQUEST_DATA, CP210X_VALUE_DATA,
  327. interface, C_SETDATA);
  328. if (icarus->usbinfo.nodev)
  329. return;
  330. // Set the baud
  331. uint32_t data = CP210X_DATA_BAUD;
  332. _transfer(icarus, CP210X_TYPE_OUT, CP210X_REQUEST_BAUD, 0,
  333. interface, &data, sizeof(data), C_SETBAUD);
  334. break;
  335. default:
  336. quit(1, "icarus_intialise() called with invalid %s cgid %i ident=%d",
  337. icarus->drv->name, icarus->cgminer_id, ident);
  338. }
  339. info->initialised = true;
  340. }
  341. static void rev(unsigned char *s, size_t l)
  342. {
  343. size_t i, j;
  344. unsigned char t;
  345. for (i = 0, j = l - 1; i < j; i++, j--) {
  346. t = s[i];
  347. s[i] = s[j];
  348. s[j] = t;
  349. }
  350. }
  351. #define ICA_NONCE_ERROR -1
  352. #define ICA_NONCE_OK 0
  353. #define ICA_NONCE_RESTART 1
  354. #define ICA_NONCE_TIMEOUT 2
  355. 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)
  356. {
  357. struct ICARUS_INFO *info = (struct ICARUS_INFO *)(icarus->device_data);
  358. struct timeval read_start, read_finish;
  359. int err, amt;
  360. int rc = 0;
  361. int read_amount = ICARUS_READ_SIZE;
  362. bool first = true;
  363. cgtime(tv_start);
  364. while (true) {
  365. if (icarus->usbinfo.nodev)
  366. return ICA_NONCE_ERROR;
  367. cgtime(&read_start);
  368. err = usb_read_ii_timeout(icarus, info->intinfo,
  369. (char *)buf, read_amount, &amt,
  370. ICARUS_WAIT_TIMEOUT, C_GETRESULTS);
  371. cgtime(&read_finish);
  372. if (err < 0 && err != LIBUSB_ERROR_TIMEOUT) {
  373. applog(LOG_ERR, "%s%i: Comms error (rerr=%d amt=%d)",
  374. icarus->drv->name, icarus->device_id, err, amt);
  375. dev_error(icarus, REASON_DEV_COMMS_ERROR);
  376. return ICA_NONCE_ERROR;
  377. }
  378. if (first)
  379. copy_time(tv_finish, &read_finish);
  380. if (amt >= read_amount)
  381. return ICA_NONCE_OK;
  382. rc = SECTOMS(tdiff(&read_finish, tv_start));
  383. if (rc >= read_time) {
  384. if (amt > 0)
  385. applog(LOG_DEBUG, "Icarus Read: Timeout reading for %d ms", rc);
  386. else
  387. applog(LOG_DEBUG, "Icarus Read: No data for %d ms", rc);
  388. return ICA_NONCE_TIMEOUT;
  389. }
  390. if (thr && thr->work_restart) {
  391. if (opt_debug) {
  392. applog(LOG_DEBUG,
  393. "Icarus Read: Work restart at %d ms", rc);
  394. }
  395. return ICA_NONCE_RESTART;
  396. }
  397. if (amt > 0) {
  398. buf += amt;
  399. read_amount -= amt;
  400. first = false;
  401. }
  402. }
  403. }
  404. static const char *timing_mode_str(enum timing_mode timing_mode)
  405. {
  406. switch(timing_mode) {
  407. case MODE_DEFAULT:
  408. return MODE_DEFAULT_STR;
  409. case MODE_SHORT:
  410. return MODE_SHORT_STR;
  411. case MODE_LONG:
  412. return MODE_LONG_STR;
  413. case MODE_VALUE:
  414. return MODE_VALUE_STR;
  415. default:
  416. return MODE_UNKNOWN_STR;
  417. }
  418. }
  419. static void set_timing_mode(int this_option_offset, struct cgpu_info *icarus)
  420. {
  421. struct ICARUS_INFO *info = (struct ICARUS_INFO *)(icarus->device_data);
  422. enum sub_ident ident;
  423. double Hs;
  424. char buf[BUFSIZ+1];
  425. char *ptr, *comma, *eq;
  426. size_t max;
  427. int i;
  428. if (opt_icarus_timing == NULL)
  429. buf[0] = '\0';
  430. else {
  431. ptr = opt_icarus_timing;
  432. for (i = 0; i < this_option_offset; i++) {
  433. comma = strchr(ptr, ',');
  434. if (comma == NULL)
  435. break;
  436. ptr = comma + 1;
  437. }
  438. comma = strchr(ptr, ',');
  439. if (comma == NULL)
  440. max = strlen(ptr);
  441. else
  442. max = comma - ptr;
  443. if (max > BUFSIZ)
  444. max = BUFSIZ;
  445. strncpy(buf, ptr, max);
  446. buf[max] = '\0';
  447. }
  448. ident = usb_ident(icarus);
  449. switch (ident) {
  450. case IDENT_ICA:
  451. info->Hs = ICARUS_REV3_HASH_TIME;
  452. break;
  453. case IDENT_BLT:
  454. case IDENT_LLT:
  455. info->Hs = LANCELOT_HASH_TIME;
  456. break;
  457. case IDENT_AMU:
  458. info->Hs = ASICMINERUSB_HASH_TIME;
  459. break;
  460. case IDENT_CMR1:
  461. info->Hs = CAIRNSMORE1_HASH_TIME;
  462. break;
  463. case IDENT_CMR2:
  464. info->Hs = CAIRNSMORE2_HASH_TIME;
  465. break;
  466. default:
  467. quit(1, "Icarus get_options() called with invalid %s ident=%d",
  468. icarus->drv->name, ident);
  469. }
  470. info->read_time = 0;
  471. info->read_time_limit = 0; // 0 = no limit
  472. if (strcasecmp(buf, MODE_SHORT_STR) == 0) {
  473. // short
  474. info->read_time = ICARUS_READ_COUNT_TIMING;
  475. info->timing_mode = MODE_SHORT;
  476. info->do_icarus_timing = true;
  477. } else if (strncasecmp(buf, MODE_SHORT_STREQ, strlen(MODE_SHORT_STREQ)) == 0) {
  478. // short=limit
  479. info->read_time = ICARUS_READ_COUNT_TIMING;
  480. info->timing_mode = MODE_SHORT;
  481. info->do_icarus_timing = true;
  482. info->read_time_limit = atoi(&buf[strlen(MODE_SHORT_STREQ)]);
  483. if (info->read_time_limit < 0)
  484. info->read_time_limit = 0;
  485. if (info->read_time_limit > ICARUS_READ_TIME_LIMIT_MAX)
  486. info->read_time_limit = ICARUS_READ_TIME_LIMIT_MAX;
  487. } else if (strcasecmp(buf, MODE_LONG_STR) == 0) {
  488. // long
  489. info->read_time = ICARUS_READ_COUNT_TIMING;
  490. info->timing_mode = MODE_LONG;
  491. info->do_icarus_timing = true;
  492. } else if (strncasecmp(buf, MODE_LONG_STREQ, strlen(MODE_LONG_STREQ)) == 0) {
  493. // long=limit
  494. info->read_time = ICARUS_READ_COUNT_TIMING;
  495. info->timing_mode = MODE_LONG;
  496. info->do_icarus_timing = true;
  497. info->read_time_limit = atoi(&buf[strlen(MODE_LONG_STREQ)]);
  498. if (info->read_time_limit < 0)
  499. info->read_time_limit = 0;
  500. if (info->read_time_limit > ICARUS_READ_TIME_LIMIT_MAX)
  501. info->read_time_limit = ICARUS_READ_TIME_LIMIT_MAX;
  502. } else if ((Hs = atof(buf)) != 0) {
  503. // ns[=read_time]
  504. info->Hs = Hs / NANOSEC;
  505. info->fullnonce = info->Hs * (((double)0xffffffff) + 1);
  506. if ((eq = strchr(buf, '=')) != NULL)
  507. info->read_time = atoi(eq+1) * ICARUS_WAIT_TIMEOUT;
  508. if (info->read_time < ICARUS_READ_COUNT_MIN)
  509. info->read_time = SECTOMS(info->fullnonce) - ICARUS_READ_REDUCE;
  510. if (unlikely(info->read_time < ICARUS_READ_COUNT_MIN))
  511. info->read_time = ICARUS_READ_COUNT_MIN;
  512. info->timing_mode = MODE_VALUE;
  513. info->do_icarus_timing = false;
  514. } else {
  515. // Anything else in buf just uses DEFAULT mode
  516. info->fullnonce = info->Hs * (((double)0xffffffff) + 1);
  517. if ((eq = strchr(buf, '=')) != NULL)
  518. info->read_time = atoi(eq+1) * ICARUS_WAIT_TIMEOUT;
  519. if (info->read_time < ICARUS_READ_COUNT_MIN)
  520. info->read_time = SECTOMS(info->fullnonce) - ICARUS_READ_REDUCE;
  521. if (unlikely(info->read_time < ICARUS_READ_COUNT_MIN))
  522. info->read_time = ICARUS_READ_COUNT_MIN;
  523. info->timing_mode = MODE_DEFAULT;
  524. info->do_icarus_timing = false;
  525. }
  526. info->min_data_count = MIN_DATA_COUNT;
  527. // All values are in multiples of ICARUS_WAIT_TIMEOUT
  528. info->read_time_limit *= ICARUS_WAIT_TIMEOUT;
  529. applog(LOG_DEBUG, "%s: cgid %d Init: mode=%s read_time=%dms limit=%dms Hs=%e",
  530. icarus->drv->name, icarus->cgminer_id,
  531. timing_mode_str(info->timing_mode),
  532. info->read_time, info->read_time_limit, info->Hs);
  533. }
  534. static uint32_t mask(int work_division)
  535. {
  536. uint32_t nonce_mask = 0x7fffffff;
  537. // yes we can calculate these, but this way it's easy to see what they are
  538. switch (work_division) {
  539. case 1:
  540. nonce_mask = 0xffffffff;
  541. break;
  542. case 2:
  543. nonce_mask = 0x7fffffff;
  544. break;
  545. case 4:
  546. nonce_mask = 0x3fffffff;
  547. break;
  548. case 8:
  549. nonce_mask = 0x1fffffff;
  550. break;
  551. default:
  552. quit(1, "Invalid2 icarus-options for work_division (%d) must be 1, 2, 4 or 8", work_division);
  553. }
  554. return nonce_mask;
  555. }
  556. static void get_options(int this_option_offset, struct cgpu_info *icarus, int *baud, int *work_division, int *fpga_count)
  557. {
  558. char buf[BUFSIZ+1];
  559. char *ptr, *comma, *colon, *colon2;
  560. enum sub_ident ident;
  561. size_t max;
  562. int i, tmp;
  563. if (opt_icarus_options == NULL)
  564. buf[0] = '\0';
  565. else {
  566. ptr = opt_icarus_options;
  567. for (i = 0; i < this_option_offset; i++) {
  568. comma = strchr(ptr, ',');
  569. if (comma == NULL)
  570. break;
  571. ptr = comma + 1;
  572. }
  573. comma = strchr(ptr, ',');
  574. if (comma == NULL)
  575. max = strlen(ptr);
  576. else
  577. max = comma - ptr;
  578. if (max > BUFSIZ)
  579. max = BUFSIZ;
  580. strncpy(buf, ptr, max);
  581. buf[max] = '\0';
  582. }
  583. ident = usb_ident(icarus);
  584. switch (ident) {
  585. case IDENT_ICA:
  586. case IDENT_BLT:
  587. case IDENT_LLT:
  588. *baud = ICARUS_IO_SPEED;
  589. *work_division = 2;
  590. *fpga_count = 2;
  591. break;
  592. case IDENT_AMU:
  593. *baud = ICARUS_IO_SPEED;
  594. *work_division = 1;
  595. *fpga_count = 1;
  596. break;
  597. case IDENT_CMR1:
  598. *baud = ICARUS_IO_SPEED;
  599. *work_division = 2;
  600. *fpga_count = 2;
  601. break;
  602. case IDENT_CMR2:
  603. *baud = ICARUS_IO_SPEED;
  604. *work_division = 1;
  605. *fpga_count = 1;
  606. break;
  607. default:
  608. quit(1, "Icarus get_options() called with invalid %s ident=%d",
  609. icarus->drv->name, ident);
  610. }
  611. if (*buf) {
  612. colon = strchr(buf, ':');
  613. if (colon)
  614. *(colon++) = '\0';
  615. if (*buf) {
  616. tmp = atoi(buf);
  617. switch (tmp) {
  618. case 115200:
  619. *baud = 115200;
  620. break;
  621. case 57600:
  622. *baud = 57600;
  623. break;
  624. default:
  625. quit(1, "Invalid icarus-options for baud (%s) must be 115200 or 57600", buf);
  626. }
  627. }
  628. if (colon && *colon) {
  629. colon2 = strchr(colon, ':');
  630. if (colon2)
  631. *(colon2++) = '\0';
  632. if (*colon) {
  633. tmp = atoi(colon);
  634. if (tmp == 1 || tmp == 2 || tmp == 4 || tmp == 8) {
  635. *work_division = tmp;
  636. *fpga_count = tmp; // default to the same
  637. } else {
  638. quit(1, "Invalid icarus-options for work_division (%s) must be 1, 2, 4 or 8", colon);
  639. }
  640. }
  641. if (colon2 && *colon2) {
  642. tmp = atoi(colon2);
  643. if (tmp > 0 && tmp <= *work_division)
  644. *fpga_count = tmp;
  645. else {
  646. quit(1, "Invalid icarus-options for fpga_count (%s) must be >0 and <=work_division (%d)", colon2, *work_division);
  647. }
  648. }
  649. }
  650. }
  651. }
  652. static bool icarus_detect_one(struct libusb_device *dev, struct usb_find_devices *found)
  653. {
  654. int this_option_offset = ++option_offset;
  655. struct ICARUS_INFO *info;
  656. struct timeval tv_start, tv_finish;
  657. // Block 171874 nonce = (0xa2870100) = 0x000187a2
  658. // N.B. golden_ob MUST take less time to calculate
  659. // than the timeout set in icarus_open()
  660. // This one takes ~0.53ms on Rev3 Icarus
  661. const char golden_ob[] =
  662. "4679ba4ec99876bf4bfe086082b40025"
  663. "4df6c356451471139a3afa71e48f544a"
  664. "00000000000000000000000000000000"
  665. "0000000087320b1a1426674f2fa722ce";
  666. const char golden_nonce[] = "000187a2";
  667. const uint32_t golden_nonce_val = 0x000187a2;
  668. unsigned char ob_bin[64], nonce_bin[ICARUS_READ_SIZE];
  669. char *nonce_hex;
  670. int baud, uninitialised_var(work_division), uninitialised_var(fpga_count);
  671. struct cgpu_info *icarus;
  672. int ret, err, amount, tries;
  673. bool ok;
  674. icarus = usb_alloc_cgpu(&icarus_drv, 1);
  675. if (!usb_init(icarus, dev, found))
  676. goto shin;
  677. usb_buffer_enable(icarus);
  678. get_options(this_option_offset, icarus, &baud, &work_division, &fpga_count);
  679. hex2bin(ob_bin, golden_ob, sizeof(ob_bin));
  680. info = (struct ICARUS_INFO *)calloc(1, sizeof(struct ICARUS_INFO));
  681. if (unlikely(!info))
  682. quit(1, "Failed to malloc ICARUS_INFO");
  683. icarus->device_data = (void *)info;
  684. tries = 2;
  685. ok = false;
  686. while (!ok && tries-- > 0) {
  687. icarus_initialise(icarus, baud);
  688. err = usb_write(icarus, (char *)ob_bin, sizeof(ob_bin), &amount, C_SENDTESTWORK);
  689. if (err != LIBUSB_SUCCESS || amount != sizeof(ob_bin))
  690. continue;
  691. memset(nonce_bin, 0, sizeof(nonce_bin));
  692. ret = icarus_get_nonce(icarus, nonce_bin, &tv_start, &tv_finish, NULL, 100);
  693. if (ret != ICA_NONCE_OK)
  694. continue;
  695. nonce_hex = bin2hex(nonce_bin, sizeof(nonce_bin));
  696. if (strncmp(nonce_hex, golden_nonce, 8) == 0)
  697. ok = true;
  698. else {
  699. if (tries < 0) {
  700. applog(LOG_ERR,
  701. "Icarus Detect: "
  702. "Test failed at %s: get %s, should: %s",
  703. icarus->device_path, nonce_hex, golden_nonce);
  704. }
  705. }
  706. free(nonce_hex);
  707. }
  708. if (!ok)
  709. goto unshin;
  710. applog(LOG_DEBUG,
  711. "Icarus Detect: "
  712. "Test succeeded at %s: got %s",
  713. icarus->device_path, golden_nonce);
  714. /* We have a real Icarus! */
  715. if (!add_cgpu(icarus))
  716. goto unshin;
  717. update_usb_stats(icarus);
  718. applog(LOG_INFO, "%s%d: Found at %s",
  719. icarus->drv->name, icarus->device_id, icarus->device_path);
  720. applog(LOG_DEBUG, "%s%d: Init baud=%d work_division=%d fpga_count=%d",
  721. icarus->drv->name, icarus->device_id, baud, work_division, fpga_count);
  722. info->baud = baud;
  723. info->work_division = work_division;
  724. info->fpga_count = fpga_count;
  725. info->nonce_mask = mask(work_division);
  726. info->golden_hashes = (golden_nonce_val & info->nonce_mask) * fpga_count;
  727. timersub(&tv_finish, &tv_start, &(info->golden_tv));
  728. set_timing_mode(this_option_offset, icarus);
  729. if (usb_ident(icarus) == IDENT_CMR2) {
  730. int i;
  731. for (i = 1; i < icarus->usbdev->found->intinfo_count; i++) {
  732. struct cgpu_info *cgtmp;
  733. struct ICARUS_INFO *intmp;
  734. cgtmp = usb_copy_cgpu(icarus);
  735. if (!cgtmp) {
  736. applog(LOG_ERR, "%s%d: Init failed initinfo %d",
  737. icarus->drv->name, icarus->device_id, i);
  738. continue;
  739. }
  740. cgtmp->usbinfo.usbstat = USB_NOSTAT;
  741. intmp = (struct ICARUS_INFO *)malloc(sizeof(struct ICARUS_INFO));
  742. if (unlikely(!intmp))
  743. quit(1, "Failed2 to malloc ICARUS_INFO");
  744. cgtmp->device_data = (void *)intmp;
  745. // Initialise everything to match
  746. memcpy(intmp, info, sizeof(struct ICARUS_INFO));
  747. intmp->intinfo = i;
  748. icarus_initialise(cgtmp, baud);
  749. if (!add_cgpu(cgtmp)) {
  750. usb_uninit(cgtmp);
  751. free(intmp);
  752. continue;
  753. }
  754. update_usb_stats(cgtmp);
  755. }
  756. }
  757. return true;
  758. unshin:
  759. usb_uninit(icarus);
  760. free(info);
  761. icarus->device_data = NULL;
  762. shin:
  763. icarus = usb_free_cgpu(icarus);
  764. return false;
  765. }
  766. static void icarus_detect()
  767. {
  768. usb_detect(&icarus_drv, icarus_detect_one);
  769. }
  770. static bool icarus_prepare(__maybe_unused struct thr_info *thr)
  771. {
  772. // struct cgpu_info *icarus = thr->cgpu;
  773. return true;
  774. }
  775. static int64_t icarus_scanhash(struct thr_info *thr, struct work *work,
  776. __maybe_unused int64_t max_nonce)
  777. {
  778. struct cgpu_info *icarus = thr->cgpu;
  779. struct ICARUS_INFO *info = (struct ICARUS_INFO *)(icarus->device_data);
  780. int ret, err, amount;
  781. unsigned char ob_bin[64], nonce_bin[ICARUS_READ_SIZE];
  782. char *ob_hex;
  783. uint32_t nonce;
  784. int64_t hash_count;
  785. struct timeval tv_start, tv_finish, elapsed;
  786. struct timeval tv_history_start, tv_history_finish;
  787. double Ti, Xi;
  788. int curr_hw_errors, i;
  789. bool was_hw_error;
  790. struct ICARUS_HISTORY *history0, *history;
  791. int count;
  792. double Hs, W, fullnonce;
  793. int read_time;
  794. bool limited;
  795. int64_t estimate_hashes;
  796. uint32_t values;
  797. int64_t hash_count_range;
  798. // Device is gone
  799. if (icarus->usbinfo.nodev)
  800. return -1;
  801. if (!info->initialised)
  802. icarus_initialise(icarus, info->baud);
  803. elapsed.tv_sec = elapsed.tv_usec = 0;
  804. memset(ob_bin, 0, sizeof(ob_bin));
  805. memcpy(ob_bin, work->midstate, 32);
  806. memcpy(ob_bin + 52, work->data + 64, 12);
  807. rev(ob_bin, 32);
  808. rev(ob_bin + 52, 12);
  809. // We only want results for the work we are about to send
  810. usb_buffer_clear(icarus);
  811. err = usb_write_ii(icarus, info->intinfo, (char *)ob_bin, sizeof(ob_bin), &amount, C_SENDWORK);
  812. if (err < 0 || amount != sizeof(ob_bin)) {
  813. applog(LOG_ERR, "%s%i: Comms error (werr=%d amt=%d)",
  814. icarus->drv->name, icarus->device_id, err, amount);
  815. dev_error(icarus, REASON_DEV_COMMS_ERROR);
  816. icarus_initialise(icarus, info->baud);
  817. return 0;
  818. }
  819. if (opt_debug) {
  820. ob_hex = bin2hex(ob_bin, sizeof(ob_bin));
  821. applog(LOG_DEBUG, "%s%d: sent %s",
  822. icarus->drv->name, icarus->device_id, ob_hex);
  823. free(ob_hex);
  824. }
  825. /* Icarus will return 4 bytes (ICARUS_READ_SIZE) nonces or nothing */
  826. memset(nonce_bin, 0, sizeof(nonce_bin));
  827. ret = icarus_get_nonce(icarus, nonce_bin, &tv_start, &tv_finish, thr, info->read_time);
  828. if (ret == ICA_NONCE_ERROR)
  829. return 0;
  830. work->blk.nonce = 0xffffffff;
  831. // aborted before becoming idle, get new work
  832. if (ret == ICA_NONCE_TIMEOUT || ret == ICA_NONCE_RESTART) {
  833. timersub(&tv_finish, &tv_start, &elapsed);
  834. // ONLY up to just when it aborted
  835. // We didn't read a reply so we don't subtract ICARUS_READ_TIME
  836. estimate_hashes = ((double)(elapsed.tv_sec)
  837. + ((double)(elapsed.tv_usec))/((double)1000000)) / info->Hs;
  838. // If some Serial-USB delay allowed the full nonce range to
  839. // complete it can't have done more than a full nonce
  840. if (unlikely(estimate_hashes > 0xffffffff))
  841. estimate_hashes = 0xffffffff;
  842. if (opt_debug) {
  843. applog(LOG_DEBUG, "%s%d: no nonce = 0x%08lX hashes (%ld.%06lds)",
  844. icarus->drv->name, icarus->device_id,
  845. (long unsigned int)estimate_hashes,
  846. elapsed.tv_sec, elapsed.tv_usec);
  847. }
  848. return estimate_hashes;
  849. }
  850. memcpy((char *)&nonce, nonce_bin, sizeof(nonce_bin));
  851. nonce = htobe32(nonce);
  852. curr_hw_errors = icarus->hw_errors;
  853. submit_nonce(thr, work, nonce);
  854. was_hw_error = (curr_hw_errors > icarus->hw_errors);
  855. hash_count = (nonce & info->nonce_mask);
  856. hash_count++;
  857. hash_count *= info->fpga_count;
  858. #if 0
  859. // This appears to only return zero nonce values
  860. if (usb_buffer_size(icarus) > 3) {
  861. memcpy((char *)&nonce, icarus->usbdev->buffer, sizeof(nonce_bin));
  862. nonce = htobe32(nonce);
  863. applog(LOG_WARNING, "%s%d: attempting to submit 2nd nonce = 0x%08lX",
  864. icarus->drv->name, icarus->device_id,
  865. (long unsigned int)nonce);
  866. curr_hw_errors = icarus->hw_errors;
  867. submit_nonce(thr, work, nonce);
  868. was_hw_error = (curr_hw_errors > icarus->hw_errors);
  869. }
  870. #endif
  871. if (opt_debug || info->do_icarus_timing)
  872. timersub(&tv_finish, &tv_start, &elapsed);
  873. if (opt_debug) {
  874. applog(LOG_DEBUG, "%s%d: nonce = 0x%08x = 0x%08lX hashes (%ld.%06lds)",
  875. icarus->drv->name, icarus->device_id,
  876. nonce, (long unsigned int)hash_count,
  877. elapsed.tv_sec, elapsed.tv_usec);
  878. }
  879. // Ignore possible end condition values ... and hw errors
  880. // TODO: set limitations on calculated values depending on the device
  881. // to avoid crap values caused by CPU/Task Switching/Swapping/etc
  882. if (info->do_icarus_timing
  883. && !was_hw_error
  884. && ((nonce & info->nonce_mask) > END_CONDITION)
  885. && ((nonce & info->nonce_mask) < (info->nonce_mask & ~END_CONDITION))) {
  886. cgtime(&tv_history_start);
  887. history0 = &(info->history[0]);
  888. if (history0->values == 0)
  889. timeradd(&tv_start, &history_sec, &(history0->finish));
  890. Ti = (double)(elapsed.tv_sec)
  891. + ((double)(elapsed.tv_usec))/((double)1000000)
  892. - ((double)ICARUS_READ_TIME(info->baud));
  893. Xi = (double)hash_count;
  894. history0->sumXiTi += Xi * Ti;
  895. history0->sumXi += Xi;
  896. history0->sumTi += Ti;
  897. history0->sumXi2 += Xi * Xi;
  898. history0->values++;
  899. if (history0->hash_count_max < hash_count)
  900. history0->hash_count_max = hash_count;
  901. if (history0->hash_count_min > hash_count || history0->hash_count_min == 0)
  902. history0->hash_count_min = hash_count;
  903. if (history0->values >= info->min_data_count
  904. && timercmp(&tv_start, &(history0->finish), >)) {
  905. for (i = INFO_HISTORY; i > 0; i--)
  906. memcpy(&(info->history[i]),
  907. &(info->history[i-1]),
  908. sizeof(struct ICARUS_HISTORY));
  909. // Initialise history0 to zero for summary calculation
  910. memset(history0, 0, sizeof(struct ICARUS_HISTORY));
  911. // We just completed a history data set
  912. // So now recalc read_time based on the whole history thus we will
  913. // initially get more accurate until it completes INFO_HISTORY
  914. // total data sets
  915. count = 0;
  916. for (i = 1 ; i <= INFO_HISTORY; i++) {
  917. history = &(info->history[i]);
  918. if (history->values >= MIN_DATA_COUNT) {
  919. count++;
  920. history0->sumXiTi += history->sumXiTi;
  921. history0->sumXi += history->sumXi;
  922. history0->sumTi += history->sumTi;
  923. history0->sumXi2 += history->sumXi2;
  924. history0->values += history->values;
  925. if (history0->hash_count_max < history->hash_count_max)
  926. history0->hash_count_max = history->hash_count_max;
  927. if (history0->hash_count_min > history->hash_count_min || history0->hash_count_min == 0)
  928. history0->hash_count_min = history->hash_count_min;
  929. }
  930. }
  931. // All history data
  932. Hs = (history0->values*history0->sumXiTi - history0->sumXi*history0->sumTi)
  933. / (history0->values*history0->sumXi2 - history0->sumXi*history0->sumXi);
  934. W = history0->sumTi/history0->values - Hs*history0->sumXi/history0->values;
  935. hash_count_range = history0->hash_count_max - history0->hash_count_min;
  936. values = history0->values;
  937. // Initialise history0 to zero for next data set
  938. memset(history0, 0, sizeof(struct ICARUS_HISTORY));
  939. fullnonce = W + Hs * (((double)0xffffffff) + 1);
  940. read_time = SECTOMS(fullnonce) - ICARUS_READ_REDUCE;
  941. if (info->read_time_limit > 0 && read_time > info->read_time_limit) {
  942. read_time = info->read_time_limit;
  943. limited = true;
  944. } else
  945. limited = false;
  946. info->Hs = Hs;
  947. info->read_time = read_time;
  948. info->fullnonce = fullnonce;
  949. info->count = count;
  950. info->W = W;
  951. info->values = values;
  952. info->hash_count_range = hash_count_range;
  953. if (info->min_data_count < MAX_MIN_DATA_COUNT)
  954. info->min_data_count *= 2;
  955. else if (info->timing_mode == MODE_SHORT)
  956. info->do_icarus_timing = false;
  957. applog(LOG_WARNING, "%s%d Re-estimate: Hs=%e W=%e read_time=%dms%s fullnonce=%.3fs",
  958. icarus->drv->name, icarus->device_id, Hs, W, read_time,
  959. limited ? " (limited)" : "", fullnonce);
  960. }
  961. info->history_count++;
  962. cgtime(&tv_history_finish);
  963. timersub(&tv_history_finish, &tv_history_start, &tv_history_finish);
  964. timeradd(&tv_history_finish, &(info->history_time), &(info->history_time));
  965. }
  966. return hash_count;
  967. }
  968. static struct api_data *icarus_api_stats(struct cgpu_info *cgpu)
  969. {
  970. struct api_data *root = NULL;
  971. struct ICARUS_INFO *info = (struct ICARUS_INFO *)(cgpu->device_data);
  972. // Warning, access to these is not locked - but we don't really
  973. // care since hashing performance is way more important than
  974. // locking access to displaying API debug 'stats'
  975. // If locking becomes an issue for any of them, use copy_data=true also
  976. root = api_add_int(root, "read_time", &(info->read_time), false);
  977. root = api_add_int(root, "read_time_limit", &(info->read_time_limit), false);
  978. root = api_add_double(root, "fullnonce", &(info->fullnonce), false);
  979. root = api_add_int(root, "count", &(info->count), false);
  980. root = api_add_hs(root, "Hs", &(info->Hs), false);
  981. root = api_add_double(root, "W", &(info->W), false);
  982. root = api_add_uint(root, "total_values", &(info->values), false);
  983. root = api_add_uint64(root, "range", &(info->hash_count_range), false);
  984. root = api_add_uint64(root, "history_count", &(info->history_count), false);
  985. root = api_add_timeval(root, "history_time", &(info->history_time), false);
  986. root = api_add_uint(root, "min_data_count", &(info->min_data_count), false);
  987. root = api_add_uint(root, "timing_values", &(info->history[0].values), false);
  988. root = api_add_const(root, "timing_mode", timing_mode_str(info->timing_mode), false);
  989. root = api_add_bool(root, "is_timing", &(info->do_icarus_timing), false);
  990. root = api_add_int(root, "baud", &(info->baud), false);
  991. root = api_add_int(root, "work_division", &(info->work_division), false);
  992. root = api_add_int(root, "fpga_count", &(info->fpga_count), false);
  993. return root;
  994. }
  995. static void icarus_shutdown(__maybe_unused struct thr_info *thr)
  996. {
  997. // TODO: ?
  998. }
  999. struct device_drv icarus_drv = {
  1000. .drv_id = DRIVER_icarus,
  1001. .dname = "Icarus",
  1002. .name = "ICA",
  1003. .drv_detect = icarus_detect,
  1004. .get_api_stats = icarus_api_stats,
  1005. .thread_prepare = icarus_prepare,
  1006. .scanhash = icarus_scanhash,
  1007. .thread_shutdown = icarus_shutdown,
  1008. };