driver-icarus.c 34 KB

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