driver-zeus.c 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217
  1. /*
  2. * Copyright 2013-2014 Con Kolivas <kernel@kolivas.org>
  3. * Copyright 2014 Zeus Integrated Systems Limited
  4. * Copyright 2014 Dominik Lehner
  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. #include "config.h"
  12. #include <pthread.h>
  13. #include <stdint.h>
  14. #include <stdio.h>
  15. #include <sys/time.h>
  16. #include <sys/types.h>
  17. #include <unistd.h>
  18. #ifndef WIN32
  19. #include <sys/select.h>
  20. #include <termios.h>
  21. #include <sys/stat.h>
  22. #include <fcntl.h>
  23. #ifndef O_CLOEXEC
  24. #define O_CLOEXEC 0
  25. #endif
  26. #else
  27. #include "compat.h"
  28. #include <windows.h>
  29. #include <io.h>
  30. #endif
  31. #include "miner.h"
  32. #include "usbutils.h"
  33. #include "fpgautils.h"
  34. #include "elist.h"
  35. #include "util.h"
  36. #include "driver-zeus.h"
  37. #define using_libusb(info) ((info)->using_libusb > 0)
  38. #define using_serial(info) ((info)->using_libusb == 0)
  39. // Configuration options
  40. extern bool opt_zeus_debug;
  41. extern int opt_zeus_chips_count; // number of Zeus chips chained together
  42. extern int opt_zeus_chip_clk; // frequency to run chips with
  43. extern bool opt_zeus_nocheck_golden; // bypass hashrate check
  44. //static int opt_zeus_chips_count_max = 1; // smallest power of 2 >= opt_zeus_chips_count
  45. // is currently auto-calculated
  46. // Index for device-specific options
  47. //static int option_offset = -1;
  48. // Unset upon first hotplug check
  49. static bool initial_startup_phase = true;
  50. static struct name_chip_map {
  51. char *model_name;
  52. int chips_count;
  53. } zeus_models[] = {
  54. { "Blizzard", 6 },
  55. //{ "Cyclone", 96 }, // model renamed??
  56. { "Hurricane X2", 48 },
  57. { "Hurricane X3", 64 },
  58. { "Thunder X2", 96 },
  59. { "Thunder X3", 128 },
  60. { NULL, 0 }
  61. };
  62. /************************************************************
  63. * Utility Functions
  64. ************************************************************/
  65. static void flush_uart(int fd)
  66. {
  67. #ifdef WIN32
  68. const HANDLE fh = (HANDLE)_get_osfhandle(fd);
  69. PurgeComm(fh, PURGE_RXCLEAR);
  70. #else
  71. tcflush(fd, TCIFLUSH);
  72. #endif
  73. }
  74. static int __maybe_unused flush_fd(int fd)
  75. {
  76. static char discard[10];
  77. return read(fd, discard, sizeof(discard));
  78. }
  79. static void rev(unsigned char *s, size_t l)
  80. {
  81. size_t i, j;
  82. unsigned char t;
  83. for (i = 0, j = l - 1; i < j; i++, j--) {
  84. t = s[i];
  85. s[i] = s[j];
  86. s[j] = t;
  87. }
  88. }
  89. static int log_2(int value)
  90. {
  91. int x = 0;
  92. while (value > 1) {
  93. value >>= 1;
  94. x++;
  95. }
  96. return x;
  97. }
  98. static uint32_t __maybe_unused chip_index(uint32_t value, int bit_num)
  99. {
  100. uint32_t newvalue = 0;
  101. int i;
  102. // isolate bits 19-28, then shift right to get the
  103. // highest bits that distinguish multiple chips
  104. value = (value & 0x1ff80000) >> (29 - bit_num);
  105. for (i = 0; i < bit_num; i++) {
  106. newvalue = newvalue << 1;
  107. newvalue += value & 0x01;
  108. value = value >> 1;
  109. }
  110. return newvalue;
  111. }
  112. static int lowest_pow2(int min)
  113. {
  114. int i;
  115. for (i = 1; i < 1024; i = i * 2) {
  116. if (min <= i){
  117. return i;
  118. }
  119. }
  120. return 1024;
  121. }
  122. static void notify_send_work_thread(struct cgpu_info *zeus)
  123. {
  124. struct ZEUS_INFO *info = zeus->device_data;
  125. cgsem_post(&info->wusem);
  126. }
  127. /************************************************************
  128. * I/O helper functions
  129. ************************************************************/
  130. #define zeus_serial_open_detect(devpath, baud, purge) serial_open_ex(devpath, baud, ZEUS_READ_FAULT_DECISECONDS, 0, purge, true)
  131. #define zeus_serial_open(devpath, baud, purge) serial_open_ex(devpath, baud, ZEUS_READ_FAULT_DECISECONDS, 0, purge, true)
  132. #define zeus_serial_close(fd) close(fd)
  133. static bool zeus_reopen(struct cgpu_info *zeus)
  134. {
  135. struct ZEUS_INFO *info = zeus->device_data;
  136. int try, fd = -1;
  137. if (!using_serial(info)) // sanity check
  138. return false;
  139. if (info->device_fd != -1) {
  140. applog(LOG_DEBUG, "Closing %s%d on %s (fd=%d)",
  141. zeus->drv->name, zeus->device_id, zeus->device_path, info->device_fd);
  142. zeus_serial_close(info->device_fd);
  143. info->device_fd = -1;
  144. cgsleep_ms(2000);
  145. }
  146. applog(LOG_DEBUG, "Attempting to open %s%d on %s",
  147. zeus->drv->name, zeus->device_id, zeus->device_path);
  148. for (try = 0; try < 3; ++try) {
  149. fd = zeus_serial_open(zeus->device_path, info->baud, true);
  150. if (likely(fd > -1))
  151. break;
  152. cgsleep_ms(3000);
  153. }
  154. if (unlikely(fd < 0)) {
  155. applog(LOG_ERR, "Failed to open %s%d on %s (%d attempts)",
  156. zeus->drv->name, zeus->device_id, zeus->device_path, try);
  157. return false;
  158. }
  159. info->device_fd = fd;
  160. applog(LOG_DEBUG, "Successfully opened %s%d on %s (%d attempts, fd=%d)",
  161. zeus->drv->name, zeus->device_id, zeus->device_path, try, info->device_fd);
  162. return true;
  163. }
  164. static int zeus_serial_write(int fd, const void *buf, size_t len)
  165. {
  166. ssize_t ret;
  167. size_t total = 0;
  168. #if ZEUS_PROTOCOL_DEBUG
  169. if (opt_zeus_debug) {
  170. char *hexstr;
  171. hexstr = bin2hex(buf, len);
  172. applog(LOG_DEBUG, "> %s", hexstr);
  173. free(hexstr);
  174. }
  175. #endif
  176. while (total < len) {
  177. #ifndef WIN32
  178. ret = write(fd, buf, len);
  179. #else
  180. ret = win32write(fd, buf, len);
  181. #endif
  182. if (ret < 0) {
  183. applog(LOG_ERR, "zeus_serial_write (%d): error on write: %s", fd, strerror(errno));
  184. return -1;
  185. }
  186. total += (size_t)ret;
  187. }
  188. return total;
  189. }
  190. static int zeus_serial_read(int fd, void *buf, size_t len, int read_count, struct timeval *tv_firstbyte)
  191. {
  192. ssize_t ret;
  193. size_t total = 0;
  194. int rc = 0;
  195. while (total < len) {
  196. #ifndef WIN32
  197. ret = read(fd, buf + total, len - total);
  198. #else
  199. ret = win32read(fd, buf + total, len - total);
  200. #endif
  201. if (ret < 0) {
  202. applog(LOG_ERR, "zeus_serial_read (%d): error on read: %s", fd, strerror(errno));
  203. return -1;
  204. }
  205. if (tv_firstbyte != NULL && total == 0)
  206. cgtime(tv_firstbyte);
  207. applog(LOG_DEBUG, "zeus_serial_read: read returned %d", (int)ret);
  208. if (ret == 0 && ++rc >= read_count)
  209. break;
  210. total += (size_t)ret;
  211. }
  212. #if ZEUS_PROTOCOL_DEBUG
  213. if (opt_zeus_debug) {
  214. char *hexstr;
  215. if (total > 0) {
  216. hexstr = bin2hex(buf, total);
  217. applog(LOG_DEBUG, "< %s", hexstr);
  218. free(hexstr);
  219. } else {
  220. applog(LOG_DEBUG, "< (no data)");
  221. }
  222. }
  223. #endif
  224. return total;
  225. }
  226. /************************************************************
  227. * Detection and setup
  228. ************************************************************/
  229. static unsigned char zeus_clk_to_freqcode(int clkfreq)
  230. {
  231. if (clkfreq > ZEUS_CLK_MAX) {
  232. applog(LOG_WARNING, "Clock frequency %d too high, resetting to %d",
  233. clkfreq, ZEUS_CLK_MAX);
  234. clkfreq = ZEUS_CLK_MAX;
  235. }
  236. if (clkfreq < ZEUS_CLK_MIN) {
  237. applog(LOG_WARNING, "Clock frequency %d too low, resetting to %d",
  238. clkfreq, ZEUS_CLK_MIN);
  239. clkfreq = ZEUS_CLK_MIN;
  240. }
  241. return (unsigned char)((double)clkfreq * 2. / 3.);
  242. }
  243. static void zeus_get_device_options(const char *devid, int *chips_count, int *chip_clk, const char *options)
  244. {
  245. char *p, *all, *found = NULL;
  246. long lval;
  247. int index = 0;
  248. char *lastslsh = MAX(strrchr(devid, '/'), strrchr(devid, '\\'));
  249. if (lastslsh != NULL)
  250. ++lastslsh;
  251. // set global default options
  252. *chips_count = (opt_zeus_chips_count) ? opt_zeus_chips_count : ZEUS_MIN_CHIPS;
  253. *chip_clk = (opt_zeus_chip_clk) ? opt_zeus_chip_clk : ZEUS_CLK_MIN;
  254. if (options == NULL)
  255. return;
  256. all = strdup(options);
  257. for (p = strtok(all, ";"); p != NULL; p = strtok(NULL, ";")) {
  258. if (strncmp(p, devid, strlen(devid)) == 0) {
  259. found = p;
  260. break;
  261. }
  262. if (lastslsh != NULL && strncmp(p, lastslsh, strlen(lastslsh)) == 0) {
  263. found = p;
  264. break;
  265. }
  266. }
  267. if (found == NULL) {
  268. free(all);
  269. return;
  270. }
  271. for (p = strtok(found, ","); p != NULL; p = strtok(NULL, ",")) {
  272. lval = strtol(p, NULL, 10);
  273. switch (index++) {
  274. case 1: // chip count
  275. if (lval < ZEUS_MIN_CHIPS || lval > ZEUS_MAX_CHIPS) {
  276. applog(LOG_ERR, "Invalid chip count %ld for Zeus device %s",
  277. lval, devid);
  278. break;
  279. }
  280. *chips_count = (int)lval;
  281. break;
  282. case 2: // clock
  283. if (lval < ZEUS_CLK_MIN || lval > ZEUS_CLK_MAX) {
  284. applog(LOG_ERR, "Invalid clock speed %ld for Zeus device %s",
  285. lval, devid);
  286. break;
  287. }
  288. *chip_clk = (int)lval;
  289. break;
  290. default:
  291. break;
  292. }
  293. }
  294. free(all);
  295. return;
  296. }
  297. static char *zeus_device_name(int chips_count)
  298. {
  299. struct name_chip_map *p;
  300. for (p = zeus_models; p->model_name != NULL; ++p) {
  301. if (p->chips_count == chips_count)
  302. return p->model_name;
  303. }
  304. return NULL;
  305. }
  306. static int zeus_usb_control_transfer_data(struct cgpu_info *zeus, uint8_t request_type, uint8_t bRequest,
  307. uint16_t wValue, uint16_t wIndex, uint32_t *data, int siz, enum usb_cmds cmd)
  308. {
  309. int err = usb_transfer_data(zeus, request_type, bRequest, wValue, wIndex, data, siz, cmd);
  310. if (err)
  311. applog(LOG_DEBUG, "%s%d: error %d on USB control transfer %s",
  312. zeus->drv->name, zeus->cgminer_id, err, usb_cmdname(cmd));
  313. return err;
  314. }
  315. static inline int zeus_usb_control_transfer(struct cgpu_info *zeus, uint8_t request_type, uint8_t bRequest,
  316. uint16_t wValue, uint16_t wIndex, enum usb_cmds cmd)
  317. {
  318. return zeus_usb_control_transfer_data(zeus, request_type, bRequest, wValue, wIndex, NULL, 0, cmd);
  319. }
  320. static bool zeus_initialize_cp2102(struct cgpu_info *zeus)
  321. {
  322. int interface = usb_interface(zeus);
  323. //uint32_t baudrate = CP210X_DATA_BAUD;
  324. // Enable the UART
  325. if (zeus_usb_control_transfer(zeus, CP210X_TYPE_OUT, CP210X_REQUEST_IFC_ENABLE,
  326. CP210X_VALUE_UART_ENABLE, interface, C_ENABLE_UART))
  327. return false;
  328. // Set data control
  329. if (zeus_usb_control_transfer(zeus, CP210X_TYPE_OUT, CP210X_REQUEST_DATA,
  330. CP210X_VALUE_DATA, interface, C_SETDATA))
  331. return false;
  332. // Zeusminers have baud hardcoded to 115200, and reject baud commands, even to same value
  333. // Set the baud
  334. //if (zeus_usb_control_transfer_data(zeus, CP210X_TYPE_OUT, CP210X_REQUEST_BAUD,
  335. // 0, interface, &baudrate, sizeof(baudrate), C_SETBAUD))
  336. // return false;
  337. return true;
  338. }
  339. static bool zeus_initialize_ftdi(struct cgpu_info *zeus)
  340. {
  341. int interface = usb_interface(zeus);
  342. // Reset
  343. if (zeus_usb_control_transfer(zeus, FTDI_TYPE_OUT, FTDI_REQUEST_RESET,
  344. FTDI_VALUE_RESET, interface, C_RESET))
  345. return false;
  346. // Latency
  347. if (zeus_usb_control_transfer(zeus, FTDI_TYPE_OUT, FTDI_REQUEST_LATENCY,
  348. 100, interface, C_LATENCY))
  349. return false;
  350. // Data
  351. if (zeus_usb_control_transfer(zeus, FTDI_TYPE_OUT, FTDI_REQUEST_DATA,
  352. FTDI_VALUE_DATA_ZUS, interface, C_SETDATA))
  353. return false;
  354. // Baudrate
  355. if (zeus_usb_control_transfer(zeus, FTDI_TYPE_OUT, FTDI_REQUEST_BAUD,
  356. FTDI_VALUE_BAUD_ZUS, (FTDI_INDEX_BAUD_ZUS & 0xff00) | interface, C_SETBAUD))
  357. return false;
  358. // Modem control
  359. if (zeus_usb_control_transfer(zeus, FTDI_TYPE_OUT, FTDI_REQUEST_MODEM,
  360. FTDI_VALUE_MODEM, interface, C_SETMODEM))
  361. return false;
  362. // Flow control
  363. if (zeus_usb_control_transfer(zeus, FTDI_TYPE_OUT, FTDI_REQUEST_FLOW,
  364. FTDI_VALUE_FLOW, interface, C_SETFLOW))
  365. return false;
  366. // Clear buffers
  367. if (zeus_usb_control_transfer(zeus, FTDI_TYPE_OUT, FTDI_REQUEST_RESET,
  368. FTDI_VALUE_PURGE_TX, interface, C_PURGETX))
  369. return false;
  370. if (zeus_usb_control_transfer(zeus, FTDI_TYPE_OUT, FTDI_REQUEST_RESET,
  371. FTDI_VALUE_PURGE_RX, interface, C_PURGERX))
  372. return false;
  373. return true;
  374. }
  375. static bool zeus_initialize_usb(struct cgpu_info *zeus)
  376. {
  377. struct ZEUS_INFO *info = zeus->device_data;
  378. enum sub_ident ident;
  379. if (zeus->usbinfo.nodev)
  380. return false;
  381. ident = usb_ident(zeus);
  382. switch (ident) {
  383. case IDENT_ZUS1:
  384. info->read_data_offset = 0;
  385. return zeus_initialize_cp2102(zeus);
  386. case IDENT_ZUS2:
  387. info->read_data_offset = 2; // FTDIRL adds 2 status bytes
  388. return zeus_initialize_ftdi(zeus);
  389. default:
  390. applog(LOG_ERR, "zeus_initialize_usb called on wrong device, ident=%d", ident);
  391. return false;
  392. }
  393. }
  394. static struct cgpu_info *zeus_detect_one_usb(struct libusb_device *dev, struct usb_find_devices *found)
  395. {
  396. struct cgpu_info *zeus;
  397. struct ZEUS_INFO *info;
  398. zeus = usb_alloc_cgpu(&zeus_drv, 1);
  399. if (!usb_init(zeus, dev, found))
  400. goto usbdealloc;
  401. info = calloc(1, sizeof(struct ZEUS_INFO));
  402. if (unlikely(!info))
  403. goto usbdealloc;
  404. zeus->device_data = info;
  405. zeus->deven = DEV_ENABLED;
  406. zeus->threads = 1;
  407. info->device_fd = -1;
  408. info->using_libusb = 1;
  409. if (zeus->usbdev->serial_string && strlen(zeus->usbdev->serial_string) > 4)
  410. zeus->unique_id = zeus->usbdev->serial_string;
  411. else
  412. zeus->unique_id = zeus->device_path;
  413. strncpy(info->device_name, zeus->unique_id, sizeof(info->device_name) - 1);
  414. info->device_name[sizeof(info->device_name) - 1] = '\0';
  415. zeus_get_device_options(zeus->unique_id, &info->chips_count, &info->chip_clk, opt_zeus_options);
  416. zeus->name = zeus_device_name(info->chips_count);
  417. info->freqcode = zeus_clk_to_freqcode(info->chip_clk);
  418. info->baud = ZEUS_IO_SPEED;
  419. info->cores_per_chip = ZEUS_CHIP_CORES;
  420. info->chips_count_max = lowest_pow2(info->chips_count);
  421. info->chips_bit_num = log_2(info->chips_count_max);
  422. info->next_chip_clk = -1;
  423. libusb_reset_device(zeus->usbdev->handle);
  424. update_usb_stats(zeus);
  425. zeus->usbdev->usb_type = USB_TYPE_STD;
  426. if (!zeus_initialize_usb(zeus)) {
  427. applog(LOG_ERR, "Failed to initialize Zeus USB-UART interface");
  428. goto alldealloc;
  429. }
  430. info->golden_speed_per_core = (((info->chip_clk * 2.) / 3.) * 1024.) / 8.;
  431. info->work_timeout.tv_sec = 4294967296LL / (info->golden_speed_per_core * info->cores_per_chip * info->chips_count_max) * 0.9;
  432. info->work_timeout.tv_usec = 0;
  433. info->read_count = (uint32_t)((4294967296LL*10)/(info->cores_per_chip*info->chips_count_max*info->golden_speed_per_core*2));
  434. info->read_count = info->read_count*3/4;
  435. if (!add_cgpu(zeus))
  436. goto alldealloc;
  437. return zeus;
  438. alldealloc:
  439. usb_uninit(zeus);
  440. free(zeus->device_data);
  441. zeus->device_data = NULL;
  442. usbdealloc:
  443. zeus = usb_free_cgpu(zeus);
  444. return NULL;
  445. }
  446. static bool zeus_detect_one_serial(const char *devpath)
  447. {
  448. struct timeval tv_start, tv_finish;
  449. int i, fd, baud, cores_per_chip, chips_count_max, chips_count, chip_clk;
  450. //int this_option_offset = ++option_offset;
  451. unsigned char freqcode_init, freqcode;
  452. uint32_t nonce;
  453. uint64_t golden_speed_per_core;
  454. /* this check here is needed as a failsafe because the serial_detect
  455. * functions do not keep track of devices already opened */
  456. for (i = 0; i < total_devices; ++i) {
  457. if (devices[i]->device_path && !strcasecmp(devices[i]->device_path, devpath))
  458. return false;
  459. }
  460. uint32_t golden_nonce_val = be32toh(0x268d0300); // 0xd26 = 3366
  461. unsigned char ob_bin[ZEUS_COMMAND_PKT_LEN], nonce_bin[ZEUS_EVENT_PKT_LEN];
  462. static const char golden_ob[] =
  463. "55aa0001"
  464. "00038000063b0b1b028f32535e900609c15dc49a42b1d8492a6dd4f8f15295c989a1decf584a6aa93be26066d3185f55ef635b5865a7a79b7fa74121a6bb819da416328a9bd2f8cef72794bf02000000";
  465. static const char golden_ob2[] =
  466. "55aa00ff"
  467. "c00278894532091be6f16a5381ad33619dacb9e6a4a6e79956aac97b51112bfb93dc450b8fc765181a344b6244d42d78625f5c39463bbfdc10405ff711dc1222dd065b015ac9c2c66e28da7202000000";
  468. zeus_get_device_options(devpath, &chips_count, &chip_clk, opt_zeus_options);
  469. baud = ZEUS_IO_SPEED; // baud rate is fixed
  470. cores_per_chip = ZEUS_CHIP_CORES; // cores/chip also fixed
  471. chips_count_max = lowest_pow2(chips_count);
  472. //if (chips_count > opt_zeus_chips_count_max)
  473. // opt_zeus_chips_count_max = lowest_pow2(chips_count);
  474. //chips_count_max = opt_zeus_chips_count_max;
  475. if (initial_startup_phase)
  476. applog(LOG_INFO, "Zeus Detect: Attempting to open %s", devpath);
  477. fd = zeus_serial_open_detect(devpath, baud, true);
  478. if (unlikely(fd == -1)) {
  479. if (initial_startup_phase)
  480. applog(LOG_ERR, "Zeus Detect: Failed to open %s", devpath);
  481. return false;
  482. }
  483. freqcode = zeus_clk_to_freqcode(chip_clk);
  484. // from 150M step to the high or low speed. we need to add delay and resend to init chip
  485. if (chip_clk > 150)
  486. freqcode_init = zeus_clk_to_freqcode(165);
  487. else
  488. freqcode_init = zeus_clk_to_freqcode(139);
  489. flush_uart(fd);
  490. hex2bin(ob_bin, golden_ob2, sizeof(ob_bin));
  491. ob_bin[0] = freqcode_init;
  492. ob_bin[1] = ~freqcode_init;
  493. ob_bin[2] = 0x00;
  494. ob_bin[3] = 0x01;
  495. for (i = 0; i < 2; ++i) {
  496. zeus_serial_write(fd, ob_bin, sizeof(ob_bin));
  497. cgsleep_ms(500); // what is the minimum the miners need/will accept?
  498. flush_uart(fd);
  499. }
  500. hex2bin(ob_bin, golden_ob2, sizeof(ob_bin));
  501. ob_bin[0] = freqcode;
  502. ob_bin[1] = ~freqcode;
  503. ob_bin[2] = 0x00;
  504. ob_bin[3] = 0x01;
  505. for (i = 0; i < 2; ++i) {
  506. zeus_serial_write(fd, ob_bin, sizeof(ob_bin));
  507. cgsleep_ms(500);
  508. flush_uart(fd);
  509. }
  510. if (!opt_zeus_nocheck_golden) {
  511. memset(nonce_bin, 0, sizeof(nonce_bin));
  512. hex2bin(ob_bin, golden_ob, sizeof(ob_bin));
  513. ob_bin[0] = freqcode;
  514. ob_bin[1] = ~freqcode;
  515. ob_bin[2] = 0x00;
  516. ob_bin[3] = 0x01;
  517. for (i = 0; i < 2; ++i) {
  518. zeus_serial_write(fd, ob_bin, sizeof(ob_bin));
  519. cgtime(&tv_start);
  520. if (zeus_serial_read(fd, nonce_bin, sizeof(nonce_bin), 25, &tv_finish) == sizeof(nonce_bin))
  521. break;
  522. }
  523. zeus_serial_close(fd);
  524. memcpy(&nonce, nonce_bin, sizeof(nonce_bin));
  525. nonce = be32toh(nonce);
  526. if (nonce != golden_nonce_val) {
  527. applog(LOG_ERR, "Zeus Detect: "
  528. "Test failed at %s: got %08x, should be: %08x",
  529. devpath, nonce, golden_nonce_val);
  530. return false;
  531. }
  532. golden_speed_per_core = (uint64_t)((double)0xd26 / tdiff(&tv_finish, &tv_start));
  533. if (opt_zeus_debug)
  534. applog(LOG_INFO, "Test succeeded at %s: got %08x",
  535. devpath, nonce);
  536. } else {
  537. zeus_serial_close(fd);
  538. golden_speed_per_core = (((chip_clk * 2.) / 3.) * 1024.) / 8.;
  539. }
  540. /* We have a real Zeus miner! */
  541. struct cgpu_info *zeus;
  542. struct ZEUS_INFO *info;
  543. zeus = calloc(1, sizeof(struct cgpu_info));
  544. if (unlikely(!zeus))
  545. quit(1, "Failed to malloc struct cgpu_info");
  546. info = calloc(1, sizeof(struct ZEUS_INFO));
  547. if (unlikely(!info))
  548. quit(1, "Failed to malloc struct ZEUS_INFO");
  549. zeus->drv = &zeus_drv;
  550. zeus->name = zeus_device_name(chips_count);
  551. zeus->device_path = strdup(devpath);
  552. zeus->device_data = info;
  553. zeus->deven = DEV_ENABLED;
  554. zeus->threads = 1;
  555. applog(LOG_NOTICE, "Found Zeus at %s, mark as %d",
  556. devpath, zeus->device_id);
  557. applog(LOG_INFO, "Zeus: Init: %d baud=%d cores_per_chip=%d chips_count=%d",
  558. zeus->device_id, baud, cores_per_chip, chips_count);
  559. info->device_fd = -1;
  560. info->using_libusb = 0;
  561. zeus->unique_id = MAX( strrchr(zeus->device_path, '/'),
  562. strrchr(zeus->device_path, '\\'));
  563. if (zeus->unique_id == NULL)
  564. zeus->unique_id = zeus->device_path;
  565. else
  566. ++zeus->unique_id;
  567. strncpy(info->device_name, zeus->unique_id, sizeof(info->device_name) - 1);
  568. info->device_name[sizeof(info->device_name) - 1] = '\0';
  569. info->work_timeout.tv_sec = 4294967296LL / (golden_speed_per_core * cores_per_chip * chips_count_max) * 0.9;
  570. info->work_timeout.tv_usec = 0;
  571. info->golden_speed_per_core = golden_speed_per_core;
  572. info->read_count = (uint32_t)((4294967296LL*10)/(cores_per_chip*chips_count_max*golden_speed_per_core*2));
  573. info->read_count = info->read_count*3/4;
  574. info->next_chip_clk = -1;
  575. info->freqcode = freqcode;
  576. info->baud = baud;
  577. info->cores_per_chip = cores_per_chip;
  578. info->chips_count = chips_count;
  579. info->chips_count_max = chips_count_max;
  580. if ((chips_count_max & (chips_count_max - 1)) != 0)
  581. quit(1, "chips_count_max must be a power of 2");
  582. info->chip_clk = chip_clk;
  583. info->chips_bit_num = log_2(chips_count_max);
  584. info->read_data_offset = 0;
  585. if (!add_cgpu(zeus))
  586. quit(1, "Failed to add_cgpu");
  587. return true;
  588. }
  589. /************************************************************
  590. * Host <-> ASIC protocol implementation
  591. ************************************************************/
  592. static void zeus_purge_work(struct cgpu_info *zeus)
  593. {
  594. struct ZEUS_INFO *info = zeus->device_data;
  595. mutex_lock(&info->lock);
  596. if (info->current_work != NULL) {
  597. free_work(info->current_work);
  598. info->current_work = NULL;
  599. }
  600. notify_send_work_thread(zeus);
  601. mutex_unlock(&info->lock);
  602. }
  603. #define nonce_range_start(cperc, cmax, core, chip) \
  604. (((0xffffffff / cperc + 1) * core) + ((0x1fffffff / cmax + 1) * chip))
  605. static bool zeus_read_response(struct cgpu_info *zeus)
  606. {
  607. struct ZEUS_INFO *info = zeus->device_data;
  608. unsigned char evtpkt[ZEUS_READ_BUFFER];
  609. uint32_t nonce, chip, core;
  610. int ret, err;
  611. double duration_s;
  612. bool valid;
  613. if (using_libusb(info)) {
  614. //err = usb_read_timeout(zeus, (char *)evtpkt, sizeof(evtpkt), &ret, 250, C_GETRESULTS);
  615. err = usb_read_once(zeus, (char *)evtpkt, sizeof(evtpkt), &ret, C_GETRESULTS);
  616. #if ZEUS_PROTOCOL_DEBUG
  617. if (opt_zeus_debug) {
  618. char *hexstr;
  619. hexstr = bin2hex(evtpkt, ret);
  620. applog(LOG_DEBUG, "< %s err=%d ret=%d", hexstr, err, ret);
  621. free(hexstr);
  622. }
  623. #endif
  624. if (err != LIBUSB_SUCCESS && err != LIBUSB_ERROR_TIMEOUT) {
  625. applog(LOG_ERR, "%s%d: USB read error: %s",
  626. zeus->drv->name, zeus->device_id, libusb_error_name(err));
  627. return false;
  628. }
  629. if (ret < ZEUS_EVENT_PKT_LEN + info->read_data_offset)
  630. return true;
  631. } else {
  632. ret = zeus_serial_read(info->device_fd, evtpkt, ZEUS_EVENT_PKT_LEN, 1, NULL);
  633. if (ret < 0) { // error
  634. info->serial_reopen = true;
  635. notify_send_work_thread(zeus);
  636. return false;
  637. } else if (ret == 0) { // timeout
  638. return true;
  639. }
  640. flush_uart(info->device_fd);
  641. }
  642. cgtime(&info->workend);
  643. memcpy(&nonce, evtpkt + info->read_data_offset, ZEUS_EVENT_PKT_LEN);
  644. nonce = be32toh(nonce);
  645. mutex_lock(&info->lock);
  646. if (info->current_work == NULL) { // work was flushed before we read response
  647. applog(LOG_DEBUG, "%s%d: Received nonce for flushed work",
  648. zeus->drv->name, zeus->device_id);
  649. mutex_unlock(&info->lock);
  650. return true;
  651. }
  652. valid = submit_nonce(info->thr, info->current_work, nonce);
  653. ++info->workdone;
  654. core = (nonce & 0xe0000000) >> 29; // core indicated by 3 highest bits
  655. chip = (nonce & 0x1ff80000) >> (29 - info->chips_bit_num);
  656. duration_s = tdiff(&info->workend, &info->workstart);
  657. if (chip < ZEUS_MAX_CHIPS && core < ZEUS_CHIP_CORES) {
  658. ++info->nonce_count[chip][core];
  659. if (!valid)
  660. ++info->error_count[chip][core];
  661. if (valid && duration_s > 0) {
  662. info->hashes_per_s = (nonce - nonce_range_start(info->cores_per_chip, info->chips_count_max, core, chip)) / duration_s * info->cores_per_chip * info->chips_count;
  663. info->last_nonce = nonce;
  664. }
  665. } else {
  666. applog(LOG_INFO, "%s%d: Corrupt nonce message received, cannot determine chip and core",
  667. zeus->drv->name, zeus->device_id);
  668. }
  669. mutex_unlock(&info->lock);
  670. return true;
  671. }
  672. static bool zeus_check_need_work(struct cgpu_info *zeus)
  673. {
  674. struct ZEUS_INFO *info = zeus->device_data;
  675. struct thr_info *thr = info->thr;
  676. struct work *work;
  677. bool need_work;
  678. need_work = (info->current_work == NULL);
  679. if (need_work) {
  680. work = get_work(thr, thr->id); // get_work can block, so done outside mutex_lock
  681. mutex_lock(&info->lock);
  682. if (info->current_work == NULL) { // verify still NULL
  683. work->devflag = false;
  684. info->current_work = work;
  685. } else {
  686. need_work = false;
  687. }
  688. mutex_unlock(&info->lock);
  689. if (!need_work)
  690. discard_work(work);
  691. }
  692. return need_work;
  693. }
  694. static bool zeus_send_work(struct cgpu_info *zeus, struct work *work)
  695. {
  696. struct ZEUS_INFO *info = zeus->device_data;
  697. unsigned char cmdpkt[ZEUS_COMMAND_PKT_LEN];
  698. uint32_t diff_code, diff;
  699. int ret;
  700. diff = work->work_difficulty;
  701. if (diff < 1)
  702. diff = 1;
  703. diff_code = 0xffff / diff;
  704. applog(LOG_DEBUG, "zeus_send_work: diff=%d diff_code=%04x", diff, diff_code);
  705. cmdpkt[0] = info->freqcode;
  706. cmdpkt[1] = ~(info->freqcode);
  707. cmdpkt[2] = (diff_code & 0xff00) >> 8;
  708. cmdpkt[3] = (diff_code & 0x00ff);
  709. memcpy(cmdpkt + 4, work->data, 80);
  710. rev(cmdpkt + 4, 80);
  711. if (using_libusb(info)) { // in libusb mode we send via usb ;)
  712. #if ZEUS_PROTOCOL_DEBUG
  713. if (opt_zeus_debug) {
  714. char *hexstr;
  715. hexstr = bin2hex(cmdpkt, sizeof(cmdpkt));
  716. applog(LOG_DEBUG, "> %s", hexstr);
  717. free(hexstr);
  718. }
  719. #endif
  720. if (usb_write(zeus, (char *)cmdpkt, sizeof(cmdpkt), &ret, C_SENDWORK) != LIBUSB_SUCCESS ||
  721. ret != sizeof(cmdpkt))
  722. return false;
  723. } else { // otherwise direct via serial port
  724. ret = zeus_serial_write(info->device_fd, cmdpkt, sizeof(cmdpkt));
  725. if (ret < 0) {
  726. info->serial_reopen = true;
  727. notify_send_work_thread(zeus);
  728. return false;
  729. }
  730. }
  731. return true;
  732. }
  733. static void *zeus_send_work_thread(void *data)
  734. {
  735. struct cgpu_info *zeus = (struct cgpu_info *)data;
  736. struct ZEUS_INFO *info = zeus->device_data;
  737. char threadname[24];
  738. struct timeval tv_now, tv_spent, tv_rem;
  739. int retval;
  740. snprintf(threadname, sizeof(threadname), "Zeus/%d", zeus->device_id);
  741. RenameThread(threadname);
  742. applog(LOG_INFO, "%s%d: serial I/O thread running, %s",
  743. zeus->drv->name, zeus->device_id, threadname);
  744. while (likely(!zeus->shutdown)) {
  745. if (unlikely(info->thr->pause || zeus->deven != DEV_ENABLED)) {
  746. cgsem_wait(&info->wusem);
  747. zeus_purge_work(zeus);
  748. continue;
  749. }
  750. if (unlikely(using_libusb(info) && zeus->usbinfo.nodev))
  751. break;
  752. if (unlikely(info->serial_reopen)) {
  753. if (using_serial(info) && !zeus_reopen(zeus)) {
  754. applog(LOG_ERR, "Failed to reopen %s%d on %s, shutting down",
  755. zeus->drv->name, zeus->device_id, zeus->device_path);
  756. break;
  757. }
  758. info->serial_reopen = false;
  759. zeus_purge_work(zeus);
  760. }
  761. zeus_check_need_work(zeus);
  762. mutex_lock(&info->lock);
  763. if (info->current_work && !info->current_work->devflag) {
  764. /* send task to device */
  765. if (opt_zeus_debug)
  766. applog(LOG_INFO, "Sending work");
  767. if (zeus_send_work(zeus, info->current_work)) {
  768. info->current_work->devflag = true;
  769. cgtime(&info->workstart);
  770. if (info->next_chip_clk != -1) {
  771. info->chip_clk = info->next_chip_clk;
  772. info->next_chip_clk = -1;
  773. }
  774. } else {
  775. applog(LOG_NOTICE, "%s%d: I/O error while sending work, will retry",
  776. zeus->drv->name, zeus->device_id);
  777. mutex_unlock(&info->lock);
  778. continue;
  779. }
  780. }
  781. mutex_unlock(&info->lock);
  782. cgtime(&tv_now);
  783. timersub(&tv_now, &info->workstart, &tv_spent);
  784. timersub(&info->work_timeout, &tv_spent, &tv_rem);
  785. if (opt_zeus_debug) {
  786. applog(LOG_DEBUG, "Workstart: %d.%06d", (int)info->workstart.tv_sec, (int)info->workstart.tv_usec);
  787. applog(LOG_DEBUG, "Spent: %d.%06d", (int)tv_spent.tv_sec, (int)tv_spent.tv_usec);
  788. applog(LOG_DEBUG, "Remaining: %d.%06d", (int)tv_rem.tv_sec, (int)tv_rem.tv_usec);
  789. }
  790. retval = cgsem_mswait(&info->wusem, (tv_rem.tv_sec < 1) ? 5000 : tv_rem.tv_sec * 1000);
  791. if (retval == ETIMEDOUT)
  792. zeus_purge_work(zeus); // abandon current work
  793. }
  794. zeus->shutdown = true;
  795. return NULL;
  796. }
  797. /************************************************************
  798. * CGMiner Interface functions
  799. ************************************************************/
  800. static int zeus_autoscan()
  801. {
  802. int found = 0;
  803. applog(LOG_DEBUG, "zeus_autoscan() called");
  804. found += serial_autodetect_udev(zeus_detect_one_serial, ZEUS_USB_ID_MODEL_STR1);
  805. found += serial_autodetect_udev(zeus_detect_one_serial, ZEUS_USB_ID_MODEL_STR2);
  806. return found;
  807. }
  808. static void zeus_detect(bool __maybe_unused hotplug)
  809. {
  810. static int serial_usb = 0;
  811. if (initial_startup_phase && hotplug)
  812. initial_startup_phase = false;
  813. if (serial_usb == 0)
  814. serial_usb = (list_empty(&scan_devices)) ? -1 : 1;
  815. if (serial_usb < 0)
  816. usb_detect(&zeus_drv, zeus_detect_one_usb);
  817. else
  818. serial_detect_iauto(&zeus_drv, zeus_detect_one_serial, zeus_autoscan);
  819. }
  820. static bool zeus_prepare(struct thr_info *thr)
  821. {
  822. struct cgpu_info *zeus = thr->cgpu;
  823. struct ZEUS_INFO *info = zeus->device_data;
  824. applog(LOG_NOTICE, "%s%d opened on %s",
  825. zeus->drv->name, zeus->device_id, zeus->device_path);
  826. info->serial_reopen = (using_serial(info)) ? true : false;
  827. info->thr = thr;
  828. mutex_init(&info->lock);
  829. cgsem_init(&info->wusem);
  830. // Use qualitative value until first result is returned
  831. info->hashes_per_s = info->golden_speed_per_core * info->cores_per_chip * info->chips_count;
  832. return true;
  833. }
  834. static bool zeus_thread_init(struct thr_info *thr)
  835. {
  836. struct cgpu_info *zeus = thr->cgpu;
  837. struct ZEUS_INFO *info = zeus->device_data;
  838. if (pthread_create(&info->sworkpth, NULL, zeus_send_work_thread, zeus)) {
  839. applog(LOG_ERR, "%s%d: Failed to create I/O thread",
  840. zeus->drv->name, zeus->device_id);
  841. return false;
  842. }
  843. return true;
  844. }
  845. static int64_t zeus_scanwork(struct thr_info *thr)
  846. {
  847. struct cgpu_info *zeus = thr->cgpu;
  848. struct ZEUS_INFO *info = zeus->device_data;
  849. struct timeval old_scanwork_time;
  850. double elapsed_s;
  851. int64_t estimate_hashes;
  852. if (unlikely(using_libusb(info) && zeus->usbinfo.nodev))
  853. return -1;
  854. if (unlikely(using_serial(info) && info->serial_reopen)) {
  855. cgsleep_ms(500);
  856. return 0;
  857. }
  858. if (unlikely(!zeus_read_response(zeus))) // reads either from serial or libusb or times out
  859. return 0;
  860. if (thr->work_restart || thr->work_update) {
  861. zeus_purge_work(zeus);
  862. thr->work_restart = false;
  863. thr->work_update = false;
  864. }
  865. mutex_lock(&info->lock);
  866. old_scanwork_time = info->scanwork_time;
  867. cgtime(&info->scanwork_time);
  868. elapsed_s = tdiff(&info->scanwork_time, &old_scanwork_time);
  869. estimate_hashes = elapsed_s * info->hashes_per_s;
  870. mutex_unlock(&info->lock);
  871. if (unlikely(estimate_hashes > 0xffffffff))
  872. estimate_hashes = 0xffffffff;
  873. return estimate_hashes;
  874. }
  875. #define zeus_update_work zeus_flush_work
  876. static void zeus_flush_work(struct cgpu_info *zeus)
  877. {
  878. zeus_purge_work(zeus);
  879. if (opt_zeus_debug)
  880. applog(LOG_INFO, "zeus_flush_work: Tickling I/O thread");
  881. }
  882. static struct api_data *zeus_api_stats(struct cgpu_info *zeus)
  883. {
  884. struct ZEUS_INFO *info = zeus->device_data;
  885. struct api_data *root = NULL;
  886. static struct timeval tv_now, tv_diff, tv_diff2;
  887. static double khs_core, khs_chip, khs_board;
  888. cgtime(&tv_now);
  889. timersub(&tv_now, &(info->workstart), &tv_diff);
  890. timersub(&(info->workend), &(info->workstart), &tv_diff2);
  891. root = api_add_string(root, "Device Name", zeus->unique_id, false);
  892. khs_core = (double)info->golden_speed_per_core / 1000.;
  893. khs_chip = (double)info->golden_speed_per_core * (double)info->cores_per_chip / 1000.;
  894. khs_board = (double)info->golden_speed_per_core * (double)info->cores_per_chip * (double)info->chips_count / 1000.;
  895. root = api_add_khs(root, "KHS/Core", &khs_core, false);
  896. root = api_add_khs(root, "KHS/Chip", &khs_chip, false);
  897. root = api_add_khs(root, "KHS/Board", &khs_board, false);
  898. root = api_add_int(root, "Frequency", &(info->chip_clk), false);
  899. root = api_add_int(root, "Cores/Chip", &(info->cores_per_chip), false);
  900. root = api_add_int(root, "Chips Count", &(info->chips_count), false);
  901. root = api_add_timeval(root, "Time Spent Current Work", &tv_diff, false);
  902. root = api_add_timeval(root, "Work Timeout", &(info->work_timeout), false);
  903. /* It would be nice to report per chip/core nonce and error counts,
  904. * but with more powerful miners with > 100 chips each with 8 cores
  905. * there is too much information and we'd overflow the api buffer.
  906. * Perhaps another api command to query individual chips? */
  907. /* these values are more for diagnostic and debugging */
  908. if (opt_zeus_debug) {
  909. root = api_add_int(root, "chips_count_max", &(info->chips_count_max), false);
  910. root = api_add_int(root, "chips_bit_num", &(info->chips_bit_num), false);
  911. root = api_add_uint32(root, "read_count", &(info->read_count), false);
  912. root = api_add_double(root, "hashes_per_s", &(info->hashes_per_s), false);
  913. root = api_add_uint32(root, "last_nonce", &(info->last_nonce), false);
  914. root = api_add_timeval(root, "last_nonce_time", &tv_diff2, false);
  915. }
  916. return root;
  917. }
  918. static void zeus_get_statline_before(char *buf, size_t bufsiz, struct cgpu_info *zeus)
  919. {
  920. struct ZEUS_INFO *info = zeus->device_data;
  921. if (zeus->name)
  922. tailsprintf(buf, bufsiz, "%-12s %4d MHz ", zeus->name, info->chip_clk);
  923. else
  924. tailsprintf(buf, bufsiz, "%4d chips %4d MHz ", info->chips_count, info->chip_clk);
  925. }
  926. static char *zeus_set_device(struct cgpu_info *zeus, char *option, char *setting, char *replybuf)
  927. {
  928. struct ZEUS_INFO *info = zeus->device_data;
  929. int val;
  930. if (strcasecmp(option, "help") == 0) {
  931. sprintf(replybuf, "freq: range %d-%d, abortwork: true/false",
  932. ZEUS_CLK_MIN, ZEUS_CLK_MAX);
  933. return replybuf;
  934. }
  935. if (strcasecmp(option, "freq") == 0) {
  936. if (!setting || !*setting) {
  937. sprintf(replybuf, "missing freq setting");
  938. return replybuf;
  939. }
  940. val = atoi(setting);
  941. if (val < ZEUS_CLK_MIN || val > ZEUS_CLK_MAX) {
  942. sprintf(replybuf, "invalid freq: '%s' valid range %d-%d",
  943. setting, ZEUS_CLK_MIN, ZEUS_CLK_MAX);
  944. return replybuf;
  945. }
  946. mutex_lock(&info->lock);
  947. info->next_chip_clk = val;
  948. info->freqcode = zeus_clk_to_freqcode(val);
  949. mutex_unlock(&info->lock);
  950. return NULL;
  951. }
  952. if (strcasecmp(option, "abortwork") == 0) {
  953. if (!setting || !*setting) {
  954. sprintf(replybuf, "missing true/false");
  955. return replybuf;
  956. }
  957. if (strcasecmp(setting, "true") != 0) {
  958. sprintf(replybuf, "not aborting current work");
  959. return replybuf;
  960. }
  961. zeus_purge_work(zeus);
  962. return NULL;
  963. }
  964. sprintf(replybuf, "Unknown option: %s", option);
  965. return replybuf;
  966. }
  967. static void zeus_thread_enable(struct thr_info *thr)
  968. {
  969. struct cgpu_info *zeus = thr->cgpu;
  970. notify_send_work_thread(zeus);
  971. }
  972. static void zeus_shutdown(struct thr_info *thr)
  973. {
  974. struct cgpu_info *zeus = thr->cgpu;
  975. struct ZEUS_INFO *info = zeus->device_data;
  976. applog(LOG_NOTICE, "%s%d: Shutting down", zeus->drv->name, zeus->device_id);
  977. pthread_join(info->sworkpth, NULL);
  978. mutex_destroy(&info->lock);
  979. cgsem_destroy(&info->wusem);
  980. if (info->device_fd != -1) {
  981. zeus_serial_close(info->device_fd);
  982. info->device_fd = -1;
  983. }
  984. }
  985. struct device_drv zeus_drv = {
  986. .drv_id = DRIVER_zeus,
  987. .dname = "Zeus",
  988. .name = "ZUS",
  989. .max_diff = 32768,
  990. .drv_detect = zeus_detect,
  991. .thread_prepare = zeus_prepare,
  992. .thread_init = zeus_thread_init,
  993. .hash_work = hash_driver_work,
  994. .scanwork = zeus_scanwork,
  995. .flush_work = zeus_flush_work,
  996. .update_work = zeus_update_work,
  997. .get_api_stats = zeus_api_stats,
  998. .get_statline_before = zeus_get_statline_before,
  999. .set_device = zeus_set_device,
  1000. .thread_enable = zeus_thread_enable,
  1001. .thread_shutdown = zeus_shutdown,
  1002. };