driver-avalon.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256
  1. /*
  2. * Copyright 2013 Con Kolivas <kernel@kolivas.org>
  3. * Copyright 2012-2013 Xiangfu <xiangfu@openmobilefree.com>
  4. * Copyright 2012 Luke Dashjr
  5. * Copyright 2012 Andrew Smith
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the Free
  9. * Software Foundation; either version 3 of the License, or (at your option)
  10. * any later version. See COPYING for more details.
  11. */
  12. #include "config.h"
  13. #include <limits.h>
  14. #include <pthread.h>
  15. #include <stdio.h>
  16. #include <sys/time.h>
  17. #include <sys/types.h>
  18. #include <dirent.h>
  19. #include <unistd.h>
  20. #ifndef WIN32
  21. #include <sys/select.h>
  22. #include <termios.h>
  23. #include <sys/stat.h>
  24. #include <fcntl.h>
  25. #ifndef O_CLOEXEC
  26. #define O_CLOEXEC 0
  27. #endif
  28. #else
  29. #include "compat.h"
  30. #include <windows.h>
  31. #include <io.h>
  32. #endif
  33. #include "elist.h"
  34. #include "miner.h"
  35. #include "usbutils.h"
  36. #include "driver-avalon.h"
  37. #include "hexdump.c"
  38. #include "util.h"
  39. int opt_avalon_temp = AVALON_TEMP_TARGET;
  40. int opt_avalon_overheat = AVALON_TEMP_OVERHEAT;
  41. bool opt_avalon_auto;
  42. static int option_offset = -1;
  43. struct device_drv avalon_drv;
  44. static int avalon_init_task(struct avalon_task *at,
  45. uint8_t reset, uint8_t ff, uint8_t fan,
  46. uint8_t timeout, uint8_t asic_num,
  47. uint8_t miner_num, uint8_t nonce_elf,
  48. uint8_t gate_miner, int frequency)
  49. {
  50. uint16_t *lefreq16;
  51. uint8_t *buf;
  52. static bool first = true;
  53. if (unlikely(!at))
  54. return -1;
  55. if (unlikely(timeout <= 0 || asic_num <= 0 || miner_num <= 0))
  56. return -1;
  57. memset(at, 0, sizeof(struct avalon_task));
  58. if (unlikely(reset)) {
  59. at->reset = 1;
  60. at->fan_eft = 1;
  61. at->timer_eft = 1;
  62. first = true;
  63. }
  64. at->flush_fifo = (ff ? 1 : 0);
  65. at->fan_eft = (fan ? 1 : 0);
  66. if (unlikely(first && !at->reset)) {
  67. at->fan_eft = 1;
  68. at->timer_eft = 1;
  69. first = false;
  70. }
  71. at->fan_pwm_data = (fan ? fan : AVALON_DEFAULT_FAN_MAX_PWM);
  72. at->timeout_data = timeout;
  73. at->asic_num = asic_num;
  74. at->miner_num = miner_num;
  75. at->nonce_elf = nonce_elf;
  76. at->gate_miner_elf = 1;
  77. at->asic_pll = 1;
  78. if (unlikely(gate_miner)) {
  79. at-> gate_miner = 1;
  80. at->asic_pll = 0;
  81. }
  82. buf = (uint8_t *)at;
  83. buf[5] = 0x00;
  84. buf[8] = 0x74;
  85. buf[9] = 0x01;
  86. buf[10] = 0x00;
  87. buf[11] = 0x00;
  88. lefreq16 = (uint16_t *)&buf[6];
  89. *lefreq16 = htole16(frequency * 8);
  90. return 0;
  91. }
  92. static inline void avalon_create_task(struct avalon_task *at,
  93. struct work *work)
  94. {
  95. memcpy(at->midstate, work->midstate, 32);
  96. memcpy(at->data, work->data + 64, 12);
  97. }
  98. static int avalon_write(struct cgpu_info *avalon, char *buf, ssize_t len, int ep)
  99. {
  100. int err, amount;
  101. err = usb_write(avalon, buf, len, &amount, ep);
  102. applog(LOG_DEBUG, "%s%i: usb_write got err %d", avalon->drv->name,
  103. avalon->device_id, err);
  104. if (unlikely(err != 0)) {
  105. applog(LOG_WARNING, "usb_write error on avalon_write");
  106. return AVA_SEND_ERROR;
  107. }
  108. if (amount != len) {
  109. applog(LOG_WARNING, "usb_write length mismatch on avalon_write");
  110. return AVA_SEND_ERROR;
  111. }
  112. return AVA_SEND_OK;
  113. }
  114. static int avalon_send_task(const struct avalon_task *at, struct cgpu_info *avalon)
  115. {
  116. uint8_t buf[AVALON_WRITE_SIZE + 4 * AVALON_DEFAULT_ASIC_NUM];
  117. int delay, ret, i, ep = C_AVALON_TASK;
  118. struct avalon_info *info;
  119. uint32_t nonce_range;
  120. size_t nr_len;
  121. if (at->nonce_elf)
  122. nr_len = AVALON_WRITE_SIZE + 4 * at->asic_num;
  123. else
  124. nr_len = AVALON_WRITE_SIZE;
  125. memcpy(buf, at, AVALON_WRITE_SIZE);
  126. if (at->nonce_elf) {
  127. nonce_range = (uint32_t)0xffffffff / at->asic_num;
  128. for (i = 0; i < at->asic_num; i++) {
  129. buf[AVALON_WRITE_SIZE + (i * 4) + 3] =
  130. (i * nonce_range & 0xff000000) >> 24;
  131. buf[AVALON_WRITE_SIZE + (i * 4) + 2] =
  132. (i * nonce_range & 0x00ff0000) >> 16;
  133. buf[AVALON_WRITE_SIZE + (i * 4) + 1] =
  134. (i * nonce_range & 0x0000ff00) >> 8;
  135. buf[AVALON_WRITE_SIZE + (i * 4) + 0] =
  136. (i * nonce_range & 0x000000ff) >> 0;
  137. }
  138. }
  139. #if defined(__BIG_ENDIAN__) || defined(MIPSEB)
  140. uint8_t tt = 0;
  141. tt = (buf[0] & 0x0f) << 4;
  142. tt |= ((buf[0] & 0x10) ? (1 << 3) : 0);
  143. tt |= ((buf[0] & 0x20) ? (1 << 2) : 0);
  144. tt |= ((buf[0] & 0x40) ? (1 << 1) : 0);
  145. tt |= ((buf[0] & 0x80) ? (1 << 0) : 0);
  146. buf[0] = tt;
  147. tt = (buf[4] & 0x0f) << 4;
  148. tt |= ((buf[4] & 0x10) ? (1 << 3) : 0);
  149. tt |= ((buf[4] & 0x20) ? (1 << 2) : 0);
  150. tt |= ((buf[4] & 0x40) ? (1 << 1) : 0);
  151. tt |= ((buf[4] & 0x80) ? (1 << 0) : 0);
  152. buf[4] = tt;
  153. #endif
  154. info = avalon->device_data;
  155. delay = nr_len * 10 * 1000000;
  156. delay = delay / info->baud;
  157. if (at->reset) {
  158. ep = C_AVALON_RESET;
  159. nr_len = 1;
  160. }
  161. if (opt_debug) {
  162. applog(LOG_DEBUG, "Avalon: Sent(%u):", (unsigned int)nr_len);
  163. hexdump(buf, nr_len);
  164. }
  165. ret = avalon_write(avalon, (char *)buf, nr_len, ep);
  166. delay += 4000;
  167. nusleep(delay);
  168. applog(LOG_DEBUG, "Avalon: Sent: Buffer delay: %dus", delay);
  169. return ret;
  170. }
  171. static bool avalon_decode_nonce(struct thr_info *thr, struct cgpu_info *avalon,
  172. struct avalon_info *info, struct avalon_result *ar,
  173. struct work *work)
  174. {
  175. uint32_t nonce;
  176. info = avalon->device_data;
  177. info->matching_work[work->subid]++;
  178. nonce = htole32(ar->nonce);
  179. applog(LOG_DEBUG, "Avalon: nonce = %0x08x", nonce);
  180. return submit_nonce(thr, work, nonce);
  181. }
  182. /* Wait until the ftdi chip returns a CTS saying we can send more data. */
  183. static void wait_avalon_ready(struct cgpu_info *avalon)
  184. {
  185. while (avalon_buffer_full(avalon)) {
  186. nmsleep(40);
  187. }
  188. }
  189. #define AVALON_CTS (1 << 4)
  190. static inline bool avalon_cts(char c)
  191. {
  192. return (c & AVALON_CTS);
  193. }
  194. static int avalon_read(struct cgpu_info *avalon, unsigned char *buf,
  195. size_t bufsize, int timeout, int ep)
  196. {
  197. struct avalon_info *info = avalon->device_data;
  198. size_t total = 0, readsize = bufsize + 2;
  199. char readbuf[AVALON_READBUF_SIZE];
  200. int err, amount, ofs = 2, cp;
  201. err = usb_read_once_timeout(avalon, readbuf, readsize, &amount, timeout, ep);
  202. applog(LOG_DEBUG, "%s%i: Get avalon read got err %d",
  203. avalon->drv->name, avalon->device_id, err);
  204. if (amount < 2)
  205. goto out;
  206. /* Use the fact that we're reading the status with the buffer to tell
  207. * the write thread it should send more work without needing to call
  208. * avalon_buffer_full directly. */
  209. if (avalon_cts(buf[0]))
  210. cgsem_post(&info->write_sem);
  211. /* The first 2 of every 64 bytes are status on FTDIRL */
  212. while (amount > 2) {
  213. cp = amount - 2;
  214. if (cp > 62)
  215. cp = 62;
  216. memcpy(&buf[total], &readbuf[ofs], cp);
  217. total += cp;
  218. amount -= cp + 2;
  219. ofs += 64;
  220. }
  221. out:
  222. return total;
  223. }
  224. static int avalon_reset(struct cgpu_info *avalon, bool initial)
  225. {
  226. struct avalon_result ar;
  227. int ret, i, spare;
  228. struct avalon_task at;
  229. uint8_t *buf, *tmp;
  230. struct timespec p;
  231. /* Send reset, then check for result */
  232. avalon_init_task(&at, 1, 0,
  233. AVALON_DEFAULT_FAN_MAX_PWM,
  234. AVALON_DEFAULT_TIMEOUT,
  235. AVALON_DEFAULT_ASIC_NUM,
  236. AVALON_DEFAULT_MINER_NUM,
  237. 0, 0,
  238. AVALON_DEFAULT_FREQUENCY);
  239. wait_avalon_ready(avalon);
  240. ret = avalon_send_task(&at, avalon);
  241. if (unlikely(ret == AVA_SEND_ERROR))
  242. return -1;
  243. if (!initial) {
  244. applog(LOG_ERR, "AVA%d reset sequence sent", avalon->device_id);
  245. return 0;
  246. }
  247. ret = avalon_read(avalon, (unsigned char *)&ar, AVALON_READ_SIZE,
  248. AVALON_RESET_TIMEOUT, C_GET_AVALON_RESET);
  249. /* What do these sleeps do?? */
  250. p.tv_sec = 0;
  251. p.tv_nsec = AVALON_RESET_PITCH;
  252. nanosleep(&p, NULL);
  253. /* Look for the first occurrence of 0xAA, the reset response should be:
  254. * AA 55 AA 55 00 00 00 00 00 00 */
  255. spare = ret - 10;
  256. buf = tmp = (uint8_t *)&ar;
  257. if (opt_debug) {
  258. applog(LOG_DEBUG, "AVA%d reset: get:", avalon->device_id);
  259. hexdump(tmp, AVALON_READ_SIZE);
  260. }
  261. for (i = 0; i <= spare; i++) {
  262. buf = &tmp[i];
  263. if (buf[0] == 0xAA)
  264. break;
  265. }
  266. i = 0;
  267. if (buf[0] == 0xAA && buf[1] == 0x55 &&
  268. buf[2] == 0xAA && buf[3] == 0x55) {
  269. for (i = 4; i < 11; i++)
  270. if (buf[i] != 0)
  271. break;
  272. }
  273. if (i != 11) {
  274. applog(LOG_ERR, "AVA%d: Reset failed! not an Avalon?"
  275. " (%d: %02x %02x %02x %02x)", avalon->device_id,
  276. i, buf[0], buf[1], buf[2], buf[3]);
  277. /* FIXME: return 1; */
  278. } else
  279. applog(LOG_WARNING, "AVA%d: Reset succeeded",
  280. avalon->device_id);
  281. return 0;
  282. }
  283. static bool get_options(int this_option_offset, int *baud, int *miner_count,
  284. int *asic_count, int *timeout, int *frequency)
  285. {
  286. char buf[BUFSIZ+1];
  287. char *ptr, *comma, *colon, *colon2, *colon3, *colon4;
  288. size_t max;
  289. int i, tmp;
  290. if (opt_avalon_options == NULL)
  291. buf[0] = '\0';
  292. else {
  293. ptr = opt_avalon_options;
  294. for (i = 0; i < this_option_offset; i++) {
  295. comma = strchr(ptr, ',');
  296. if (comma == NULL)
  297. break;
  298. ptr = comma + 1;
  299. }
  300. comma = strchr(ptr, ',');
  301. if (comma == NULL)
  302. max = strlen(ptr);
  303. else
  304. max = comma - ptr;
  305. if (max > BUFSIZ)
  306. max = BUFSIZ;
  307. strncpy(buf, ptr, max);
  308. buf[max] = '\0';
  309. }
  310. if (!(*buf))
  311. return false;
  312. colon = strchr(buf, ':');
  313. if (colon)
  314. *(colon++) = '\0';
  315. tmp = atoi(buf);
  316. switch (tmp) {
  317. case 115200:
  318. *baud = 115200;
  319. break;
  320. case 57600:
  321. *baud = 57600;
  322. break;
  323. case 38400:
  324. *baud = 38400;
  325. break;
  326. case 19200:
  327. *baud = 19200;
  328. break;
  329. default:
  330. quit(1, "Invalid avalon-options for baud (%s) "
  331. "must be 115200, 57600, 38400 or 19200", buf);
  332. }
  333. if (colon && *colon) {
  334. colon2 = strchr(colon, ':');
  335. if (colon2)
  336. *(colon2++) = '\0';
  337. if (*colon) {
  338. tmp = atoi(colon);
  339. if (tmp > 0 && tmp <= AVALON_DEFAULT_MINER_NUM) {
  340. *miner_count = tmp;
  341. } else {
  342. quit(1, "Invalid avalon-options for "
  343. "miner_count (%s) must be 1 ~ %d",
  344. colon, AVALON_DEFAULT_MINER_NUM);
  345. }
  346. }
  347. if (colon2 && *colon2) {
  348. colon3 = strchr(colon2, ':');
  349. if (colon3)
  350. *(colon3++) = '\0';
  351. tmp = atoi(colon2);
  352. if (tmp > 0 && tmp <= AVALON_DEFAULT_ASIC_NUM)
  353. *asic_count = tmp;
  354. else {
  355. quit(1, "Invalid avalon-options for "
  356. "asic_count (%s) must be 1 ~ %d",
  357. colon2, AVALON_DEFAULT_ASIC_NUM);
  358. }
  359. if (colon3 && *colon3) {
  360. colon4 = strchr(colon3, ':');
  361. if (colon4)
  362. *(colon4++) = '\0';
  363. tmp = atoi(colon3);
  364. if (tmp > 0 && tmp <= 0xff)
  365. *timeout = tmp;
  366. else {
  367. quit(1, "Invalid avalon-options for "
  368. "timeout (%s) must be 1 ~ %d",
  369. colon3, 0xff);
  370. }
  371. if (colon4 && *colon4) {
  372. tmp = atoi(colon4);
  373. if (tmp < AVALON_MIN_FREQUENCY || tmp > AVALON_MAX_FREQUENCY) {
  374. quit(1, "Invalid avalon-options for frequency, must be %d <= frequency <= %d",
  375. AVALON_MIN_FREQUENCY, AVALON_MAX_FREQUENCY);
  376. }
  377. *frequency = tmp;
  378. }
  379. }
  380. }
  381. }
  382. return true;
  383. }
  384. static void avalon_idle(struct cgpu_info *avalon, struct avalon_info *info)
  385. {
  386. int i;
  387. info->idle = true;
  388. wait_avalon_ready(avalon);
  389. /* Send idle to all miners */
  390. for (i = 0; i < info->miner_count; i++) {
  391. struct avalon_task at;
  392. if (unlikely(avalon_buffer_full(avalon)))
  393. break;
  394. avalon_init_task(&at, 0, 0, info->fan_pwm, info->timeout,
  395. info->asic_count, info->miner_count, 1, 1,
  396. info->frequency);
  397. avalon_send_task(&at, avalon);
  398. }
  399. applog(LOG_WARNING, "AVA%i: Idling %d miners", avalon->device_id, i);
  400. wait_avalon_ready(avalon);
  401. }
  402. static void avalon_initialise(struct cgpu_info *avalon)
  403. {
  404. int err, interface;
  405. if (avalon->usbinfo.nodev)
  406. return;
  407. interface = avalon->usbdev->found->interface;
  408. // Reset
  409. err = usb_transfer(avalon, FTDI_TYPE_OUT, FTDI_REQUEST_RESET,
  410. FTDI_VALUE_RESET, interface, C_RESET);
  411. applog(LOG_DEBUG, "%s%i: reset got err %d",
  412. avalon->drv->name, avalon->device_id, err);
  413. if (avalon->usbinfo.nodev)
  414. return;
  415. // Set latency
  416. err = usb_transfer(avalon, FTDI_TYPE_OUT, FTDI_REQUEST_LATENCY,
  417. AVALON_LATENCY, interface, C_LATENCY);
  418. applog(LOG_DEBUG, "%s%i: latency got err %d",
  419. avalon->drv->name, avalon->device_id, err);
  420. if (avalon->usbinfo.nodev)
  421. return;
  422. // Set data
  423. err = usb_transfer(avalon, FTDI_TYPE_OUT, FTDI_REQUEST_DATA,
  424. FTDI_VALUE_DATA_AVA, interface, C_SETDATA);
  425. applog(LOG_DEBUG, "%s%i: data got err %d",
  426. avalon->drv->name, avalon->device_id, err);
  427. if (avalon->usbinfo.nodev)
  428. return;
  429. // Set the baud
  430. err = usb_transfer(avalon, FTDI_TYPE_OUT, FTDI_REQUEST_BAUD, FTDI_VALUE_BAUD_AVA,
  431. (FTDI_INDEX_BAUD_AVA & 0xff00) | interface,
  432. C_SETBAUD);
  433. applog(LOG_DEBUG, "%s%i: setbaud got err %d",
  434. avalon->drv->name, avalon->device_id, err);
  435. if (avalon->usbinfo.nodev)
  436. return;
  437. // Set Modem Control
  438. err = usb_transfer(avalon, FTDI_TYPE_OUT, FTDI_REQUEST_MODEM,
  439. FTDI_VALUE_MODEM, interface, C_SETMODEM);
  440. applog(LOG_DEBUG, "%s%i: setmodemctrl got err %d",
  441. avalon->drv->name, avalon->device_id, err);
  442. if (avalon->usbinfo.nodev)
  443. return;
  444. // Set Flow Control
  445. err = usb_transfer(avalon, FTDI_TYPE_OUT, FTDI_REQUEST_FLOW,
  446. FTDI_VALUE_FLOW, interface, C_SETFLOW);
  447. applog(LOG_DEBUG, "%s%i: setflowctrl got err %d",
  448. avalon->drv->name, avalon->device_id, err);
  449. if (avalon->usbinfo.nodev)
  450. return;
  451. /* Avalon repeats the following */
  452. // Set Modem Control
  453. err = usb_transfer(avalon, FTDI_TYPE_OUT, FTDI_REQUEST_MODEM,
  454. FTDI_VALUE_MODEM, interface, C_SETMODEM);
  455. applog(LOG_DEBUG, "%s%i: setmodemctrl 2 got err %d",
  456. avalon->drv->name, avalon->device_id, err);
  457. if (avalon->usbinfo.nodev)
  458. return;
  459. // Set Flow Control
  460. err = usb_transfer(avalon, FTDI_TYPE_OUT, FTDI_REQUEST_FLOW,
  461. FTDI_VALUE_FLOW, interface, C_SETFLOW);
  462. applog(LOG_DEBUG, "%s%i: setflowctrl 2 got err %d",
  463. avalon->drv->name, avalon->device_id, err);
  464. }
  465. static bool avalon_detect_one(libusb_device *dev, struct usb_find_devices *found)
  466. {
  467. int baud, miner_count, asic_count, timeout, frequency = 0;
  468. int this_option_offset = ++option_offset;
  469. struct avalon_info *info;
  470. struct cgpu_info *avalon;
  471. bool configured;
  472. int ret;
  473. avalon = usb_alloc_cgpu(&avalon_drv, AVALON_MINER_THREADS);
  474. configured = get_options(this_option_offset, &baud, &miner_count,
  475. &asic_count, &timeout, &frequency);
  476. if (!usb_init(avalon, dev, found))
  477. goto shin;
  478. /* Even though this is an FTDI type chip, we want to do the parsing
  479. * all ourselves so set it to std usb type */
  480. avalon->usbdev->usb_type = USB_TYPE_STD;
  481. avalon->usbdev->PrefPacketSize = AVALON_USB_PACKETSIZE;
  482. /* We have a real Avalon! */
  483. avalon_initialise(avalon);
  484. avalon->device_data = calloc(sizeof(struct avalon_info), 1);
  485. if (unlikely(!(avalon->device_data)))
  486. quit(1, "Failed to calloc avalon_info data");
  487. info = avalon->device_data;
  488. if (configured) {
  489. info->baud = baud;
  490. info->miner_count = miner_count;
  491. info->asic_count = asic_count;
  492. info->timeout = timeout;
  493. info->frequency = frequency;
  494. } else {
  495. info->baud = AVALON_IO_SPEED;
  496. info->miner_count = AVALON_DEFAULT_MINER_NUM;
  497. info->asic_count = AVALON_DEFAULT_ASIC_NUM;
  498. info->timeout = AVALON_DEFAULT_TIMEOUT;
  499. info->frequency = AVALON_DEFAULT_FREQUENCY;
  500. }
  501. info->fan_pwm = AVALON_DEFAULT_FAN_MIN_PWM;
  502. info->temp_max = 0;
  503. /* This is for check the temp/fan every 3~4s */
  504. info->temp_history_count = (4 / (float)((float)info->timeout * ((float)1.67/0x32))) + 1;
  505. if (info->temp_history_count <= 0)
  506. info->temp_history_count = 1;
  507. info->temp_history_index = 0;
  508. info->temp_sum = 0;
  509. info->temp_old = 0;
  510. if (!add_cgpu(avalon))
  511. goto unshin;
  512. ret = avalon_reset(avalon, true);
  513. if (ret && !configured)
  514. goto unshin;
  515. update_usb_stats(avalon);
  516. avalon_idle(avalon, info);
  517. applog(LOG_DEBUG, "Avalon Detected: %s "
  518. "(miner_count=%d asic_count=%d timeout=%d frequency=%d)",
  519. avalon->device_path, info->miner_count, info->asic_count, info->timeout,
  520. info->frequency);
  521. return true;
  522. unshin:
  523. usb_uninit(avalon);
  524. shin:
  525. free(avalon->device_data);
  526. avalon->device_data = NULL;
  527. avalon = usb_free_cgpu(avalon);
  528. return false;
  529. }
  530. static void avalon_detect(void)
  531. {
  532. usb_detect(&avalon_drv, avalon_detect_one);
  533. }
  534. static void avalon_init(struct cgpu_info *avalon)
  535. {
  536. applog(LOG_INFO, "Avalon: Opened on %s", avalon->device_path);
  537. }
  538. static struct work *avalon_valid_result(struct cgpu_info *avalon, struct avalon_result *ar)
  539. {
  540. return find_queued_work_bymidstate(avalon, (char *)ar->midstate, 32,
  541. (char *)ar->data, 64, 12);
  542. }
  543. static void avalon_update_temps(struct cgpu_info *avalon, struct avalon_info *info,
  544. struct avalon_result *ar);
  545. static void avalon_inc_nvw(struct avalon_info *info, struct thr_info *thr)
  546. {
  547. if (unlikely(info->idle))
  548. return;
  549. applog(LOG_INFO, "%s%d: No matching work - HW error",
  550. thr->cgpu->drv->name, thr->cgpu->device_id);
  551. inc_hw_errors(thr);
  552. info->no_matching_work++;
  553. }
  554. static void avalon_parse_results(struct cgpu_info *avalon, struct avalon_info *info,
  555. struct thr_info *thr, char *buf, int *offset)
  556. {
  557. int i, spare = *offset - AVALON_READ_SIZE;
  558. bool found = false;
  559. for (i = 0; i <= spare; i++) {
  560. struct avalon_result *ar;
  561. struct work *work;
  562. ar = (struct avalon_result *)&buf[i];
  563. work = avalon_valid_result(avalon, ar);
  564. if (work) {
  565. bool gettemp = false;
  566. found = true;
  567. if (avalon_decode_nonce(thr, avalon, info, ar, work)) {
  568. mutex_lock(&info->lock);
  569. if (!info->nonces++)
  570. gettemp = true;
  571. info->auto_nonces++;
  572. mutex_unlock(&info->lock);
  573. } else if (opt_avalon_auto) {
  574. mutex_lock(&info->lock);
  575. info->auto_hw++;
  576. mutex_unlock(&info->lock);
  577. }
  578. if (gettemp)
  579. avalon_update_temps(avalon, info, ar);
  580. break;
  581. }
  582. }
  583. if (!found) {
  584. spare = *offset - AVALON_READ_SIZE;
  585. /* We are buffering and haven't accumulated one more corrupt
  586. * work result. */
  587. if (spare < (int)AVALON_READ_SIZE)
  588. return;
  589. avalon_inc_nvw(info, thr);
  590. } else {
  591. spare = AVALON_READ_SIZE + i;
  592. if (i) {
  593. if (i >= (int)AVALON_READ_SIZE)
  594. avalon_inc_nvw(info, thr);
  595. else
  596. applog(LOG_WARNING, "Avalon: Discarding %d bytes from buffer", i);
  597. }
  598. }
  599. *offset -= spare;
  600. memmove(buf, buf + spare, *offset);
  601. }
  602. static void avalon_running_reset(struct cgpu_info *avalon,
  603. struct avalon_info *info)
  604. {
  605. avalon_reset(avalon, false);
  606. avalon_idle(avalon, info);
  607. avalon->results = 0;
  608. info->reset = false;
  609. }
  610. static void *avalon_get_results(void *userdata)
  611. {
  612. struct cgpu_info *avalon = (struct cgpu_info *)userdata;
  613. struct avalon_info *info = avalon->device_data;
  614. int offset = 0, read_delay = 0, ret = 0;
  615. const int rsize = AVALON_FTDI_READSIZE;
  616. char readbuf[AVALON_READBUF_SIZE];
  617. struct thr_info *thr = info->thr;
  618. struct timeval tv_start, tv_end;
  619. char threadname[24];
  620. snprintf(threadname, 24, "ava_recv/%d", avalon->device_id);
  621. RenameThread(threadname);
  622. while (likely(!avalon->shutdown)) {
  623. unsigned char buf[rsize];
  624. struct timeval tv_diff;
  625. int us_diff;
  626. if (offset >= (int)AVALON_READ_SIZE)
  627. avalon_parse_results(avalon, info, thr, readbuf, &offset);
  628. if (unlikely(offset + rsize >= AVALON_READBUF_SIZE)) {
  629. /* This should never happen */
  630. applog(LOG_ERR, "Avalon readbuf overflow, resetting buffer");
  631. offset = 0;
  632. }
  633. if (unlikely(info->reset)) {
  634. avalon_running_reset(avalon, info);
  635. /* Discard anything in the buffer */
  636. offset = 0;
  637. }
  638. /* As the usb read returns after just 1ms, sleep long enough
  639. * to leave the interface idle for writes to occur, but do not
  640. * sleep if we have been receiving data as more may be coming. */
  641. if (ret < 1) {
  642. cgtime(&tv_end);
  643. timersub(&tv_end, &tv_start, &tv_diff);
  644. /* Assume it has not been > 1 second so ignore tv_sec */
  645. us_diff = tv_diff.tv_usec;
  646. read_delay = AVALON_READ_TIMEOUT * 1000 - us_diff;
  647. if (likely(read_delay >= 1000))
  648. nusleep(read_delay);
  649. }
  650. cgtime(&tv_start);
  651. ret = avalon_read(avalon, buf, rsize, AVALON_READ_TIMEOUT,
  652. C_AVALON_READ);
  653. if (ret < 1)
  654. continue;
  655. if (opt_debug) {
  656. applog(LOG_DEBUG, "Avalon: get:");
  657. hexdump((uint8_t *)buf, ret);
  658. }
  659. memcpy(&readbuf[offset], &buf, ret);
  660. offset += ret;
  661. }
  662. return NULL;
  663. }
  664. static void avalon_rotate_array(struct cgpu_info *avalon)
  665. {
  666. avalon->queued = 0;
  667. if (++avalon->work_array >= AVALON_ARRAY_SIZE)
  668. avalon->work_array = 0;
  669. }
  670. static void avalon_set_timeout(struct avalon_info *info)
  671. {
  672. info->timeout = AVALON_TIMEOUT_FACTOR / info->frequency;
  673. }
  674. static void avalon_inc_freq(struct avalon_info *info)
  675. {
  676. info->frequency += 2;
  677. if (info->frequency > AVALON_MAX_FREQUENCY)
  678. info->frequency = AVALON_MAX_FREQUENCY;
  679. avalon_set_timeout(info);
  680. applog(LOG_NOTICE, "Avalon increasing frequency to %d, timeout %d",
  681. info->frequency, info->timeout);
  682. }
  683. static void avalon_dec_freq(struct avalon_info *info)
  684. {
  685. info->frequency -= 1;
  686. if (info->frequency < AVALON_MIN_FREQUENCY)
  687. info->frequency = AVALON_MIN_FREQUENCY;
  688. avalon_set_timeout(info);
  689. applog(LOG_NOTICE, "Avalon decreasing frequency to %d, timeout %d",
  690. info->frequency, info->timeout);
  691. }
  692. static void avalon_reset_auto(struct avalon_info *info)
  693. {
  694. info->auto_queued =
  695. info->auto_nonces =
  696. info->auto_hw = 0;
  697. }
  698. static void *avalon_send_tasks(void *userdata)
  699. {
  700. struct cgpu_info *avalon = (struct cgpu_info *)userdata;
  701. struct avalon_info *info = avalon->device_data;
  702. const int avalon_get_work_count = info->miner_count;
  703. char threadname[24];
  704. snprintf(threadname, 24, "ava_send/%d", avalon->device_id);
  705. RenameThread(threadname);
  706. while (likely(!avalon->shutdown)) {
  707. int start_count, end_count, i, j, ret;
  708. struct avalon_task at;
  709. int idled = 0;
  710. while (avalon_buffer_full(avalon))
  711. cgsem_wait(&info->write_sem);
  712. if (opt_avalon_auto && info->auto_queued >= AVALON_AUTO_CYCLE) {
  713. mutex_lock(&info->lock);
  714. if (info->auto_nonces >= (AVALON_AUTO_CYCLE * 19 / 20) &&
  715. info->auto_nonces <= (AVALON_AUTO_CYCLE * 21 / 20)) {
  716. int total = info->auto_nonces + info->auto_hw;
  717. /* Try to keep hw errors ~1-1.5% */
  718. if (info->auto_hw * 100 < total)
  719. avalon_inc_freq(info);
  720. else if (info->auto_hw * 66 > total)
  721. avalon_dec_freq(info);
  722. }
  723. avalon_reset_auto(info);
  724. mutex_unlock(&info->lock);
  725. }
  726. mutex_lock(&info->qlock);
  727. start_count = avalon->work_array * avalon_get_work_count;
  728. end_count = start_count + avalon_get_work_count;
  729. for (i = start_count, j = 0; i < end_count; i++, j++) {
  730. if (avalon_buffer_full(avalon)) {
  731. applog(LOG_INFO,
  732. "AVA%i: Buffer full after only %d of %d work queued",
  733. avalon->device_id, j, avalon_get_work_count);
  734. break;
  735. }
  736. if (likely(j < avalon->queued && !info->overheat)) {
  737. info->idle = false;
  738. avalon_init_task(&at, 0, 0, info->fan_pwm,
  739. info->timeout, info->asic_count,
  740. info->miner_count, 1, 0, info->frequency);
  741. avalon_create_task(&at, avalon->works[i]);
  742. info->auto_queued++;
  743. } else {
  744. idled++;
  745. avalon_init_task(&at, 0, 0, info->fan_pwm,
  746. info->timeout, info->asic_count,
  747. info->miner_count, 1, 1, info->frequency);
  748. /* Reset the auto_queued count if we end up
  749. * idling any miners. */
  750. avalon_reset_auto(info);
  751. }
  752. ret = avalon_send_task(&at, avalon);
  753. if (unlikely(ret == AVA_SEND_ERROR)) {
  754. applog(LOG_ERR, "AVA%i: Comms error(buffer)",
  755. avalon->device_id);
  756. dev_error(avalon, REASON_DEV_COMMS_ERROR);
  757. info->reset = true;
  758. break;
  759. }
  760. }
  761. avalon_rotate_array(avalon);
  762. pthread_cond_signal(&info->qcond);
  763. mutex_unlock(&info->qlock);
  764. if (unlikely(idled && !info->idle)) {
  765. info->idle = true;
  766. applog(LOG_WARNING, "AVA%i: Idled %d miners",
  767. avalon->device_id, idled);
  768. }
  769. }
  770. return NULL;
  771. }
  772. static bool avalon_prepare(struct thr_info *thr)
  773. {
  774. struct cgpu_info *avalon = thr->cgpu;
  775. struct avalon_info *info = avalon->device_data;
  776. struct timeval now;
  777. free(avalon->works);
  778. avalon->works = calloc(info->miner_count * sizeof(struct work *),
  779. AVALON_ARRAY_SIZE);
  780. if (!avalon->works)
  781. quit(1, "Failed to calloc avalon works in avalon_prepare");
  782. info->thr = thr;
  783. mutex_init(&info->lock);
  784. mutex_init(&info->qlock);
  785. if (unlikely(pthread_cond_init(&info->qcond, NULL)))
  786. quit(1, "Failed to pthread_cond_init avalon qcond");
  787. cgsem_init(&info->write_sem);
  788. if (pthread_create(&info->read_thr, NULL, avalon_get_results, (void *)avalon))
  789. quit(1, "Failed to create avalon read_thr");
  790. if (pthread_create(&info->write_thr, NULL, avalon_send_tasks, (void *)avalon))
  791. quit(1, "Failed to create avalon write_thr");
  792. avalon_init(avalon);
  793. cgtime(&now);
  794. get_datestamp(avalon->init, &now);
  795. return true;
  796. }
  797. static void do_avalon_close(struct thr_info *thr)
  798. {
  799. struct cgpu_info *avalon = thr->cgpu;
  800. struct avalon_info *info = avalon->device_data;
  801. pthread_join(info->read_thr, NULL);
  802. pthread_join(info->write_thr, NULL);
  803. avalon_running_reset(avalon, info);
  804. info->no_matching_work = 0;
  805. cgsem_destroy(&info->write_sem);
  806. }
  807. static inline void record_temp_fan(struct avalon_info *info, struct avalon_result *ar, float *temp_avg)
  808. {
  809. info->fan0 = ar->fan0 * AVALON_FAN_FACTOR;
  810. info->fan1 = ar->fan1 * AVALON_FAN_FACTOR;
  811. info->fan2 = ar->fan2 * AVALON_FAN_FACTOR;
  812. info->temp0 = ar->temp0;
  813. info->temp1 = ar->temp1;
  814. info->temp2 = ar->temp2;
  815. if (ar->temp0 & 0x80) {
  816. ar->temp0 &= 0x7f;
  817. info->temp0 = 0 - ((~ar->temp0 & 0x7f) + 1);
  818. }
  819. if (ar->temp1 & 0x80) {
  820. ar->temp1 &= 0x7f;
  821. info->temp1 = 0 - ((~ar->temp1 & 0x7f) + 1);
  822. }
  823. if (ar->temp2 & 0x80) {
  824. ar->temp2 &= 0x7f;
  825. info->temp2 = 0 - ((~ar->temp2 & 0x7f) + 1);
  826. }
  827. *temp_avg = info->temp2 > info->temp1 ? info->temp2 : info->temp1;
  828. if (info->temp0 > info->temp_max)
  829. info->temp_max = info->temp0;
  830. if (info->temp1 > info->temp_max)
  831. info->temp_max = info->temp1;
  832. if (info->temp2 > info->temp_max)
  833. info->temp_max = info->temp2;
  834. }
  835. static void temp_rise(struct avalon_info *info, int temp)
  836. {
  837. if (temp >= opt_avalon_temp + AVALON_TEMP_HYSTERESIS * 3) {
  838. info->fan_pwm = AVALON_DEFAULT_FAN_MAX_PWM;
  839. return;
  840. }
  841. if (temp >= opt_avalon_temp + AVALON_TEMP_HYSTERESIS * 2)
  842. info->fan_pwm += 10;
  843. else if (temp > opt_avalon_temp)
  844. info->fan_pwm += 5;
  845. else if (temp >= opt_avalon_temp - AVALON_TEMP_HYSTERESIS)
  846. info->fan_pwm += 1;
  847. else
  848. return;
  849. if (info->fan_pwm > AVALON_DEFAULT_FAN_MAX_PWM)
  850. info->fan_pwm = AVALON_DEFAULT_FAN_MAX_PWM;
  851. }
  852. static void temp_drop(struct avalon_info *info, int temp)
  853. {
  854. if (temp <= opt_avalon_temp - AVALON_TEMP_HYSTERESIS * 3) {
  855. info->fan_pwm = AVALON_DEFAULT_FAN_MIN_PWM;
  856. return;
  857. }
  858. if (temp <= opt_avalon_temp - AVALON_TEMP_HYSTERESIS * 2)
  859. info->fan_pwm -= 10;
  860. else if (temp <= opt_avalon_temp - AVALON_TEMP_HYSTERESIS)
  861. info->fan_pwm -= 5;
  862. else if (temp < opt_avalon_temp)
  863. info->fan_pwm -= 1;
  864. if (info->fan_pwm < AVALON_DEFAULT_FAN_MIN_PWM)
  865. info->fan_pwm = AVALON_DEFAULT_FAN_MIN_PWM;
  866. }
  867. static inline void adjust_fan(struct avalon_info *info)
  868. {
  869. int temp_new;
  870. temp_new = info->temp_sum / info->temp_history_count;
  871. if (temp_new > info->temp_old)
  872. temp_rise(info, temp_new);
  873. else if (temp_new < info->temp_old)
  874. temp_drop(info, temp_new);
  875. else {
  876. /* temp_new == info->temp_old */
  877. if (temp_new > opt_avalon_temp)
  878. temp_rise(info, temp_new);
  879. else if (temp_new < opt_avalon_temp - AVALON_TEMP_HYSTERESIS)
  880. temp_drop(info, temp_new);
  881. }
  882. info->temp_old = temp_new;
  883. }
  884. static void avalon_update_temps(struct cgpu_info *avalon, struct avalon_info *info,
  885. struct avalon_result *ar)
  886. {
  887. record_temp_fan(info, ar, &(avalon->temp));
  888. applog(LOG_INFO,
  889. "Avalon: Fan1: %d/m, Fan2: %d/m, Fan3: %d/m\t"
  890. "Temp1: %dC, Temp2: %dC, Temp3: %dC, TempMAX: %dC",
  891. info->fan0, info->fan1, info->fan2,
  892. info->temp0, info->temp1, info->temp2, info->temp_max);
  893. info->temp_history_index++;
  894. info->temp_sum += avalon->temp;
  895. applog(LOG_DEBUG, "Avalon: temp_index: %d, temp_count: %d, temp_old: %d",
  896. info->temp_history_index, info->temp_history_count, info->temp_old);
  897. if (info->temp_history_index == info->temp_history_count) {
  898. adjust_fan(info);
  899. info->temp_history_index = 0;
  900. info->temp_sum = 0;
  901. }
  902. if (unlikely(info->temp_old >= opt_avalon_overheat)) {
  903. applog(LOG_WARNING, "AVA%d overheat! Idling", avalon->device_id);
  904. info->overheat = true;
  905. } else if (info->overheat && info->temp_old <= opt_avalon_temp) {
  906. applog(LOG_WARNING, "AVA%d cooled, restarting", avalon->device_id);
  907. info->overheat = false;
  908. }
  909. }
  910. static void get_avalon_statline_before(char *buf, struct cgpu_info *avalon)
  911. {
  912. struct avalon_info *info = avalon->device_data;
  913. int lowfan = 10000;
  914. /* Find the lowest fan speed of the ASIC cooling fans. */
  915. if (info->fan1 >= 0 && info->fan1 < lowfan)
  916. lowfan = info->fan1;
  917. if (info->fan2 >= 0 && info->fan2 < lowfan)
  918. lowfan = info->fan2;
  919. tailsprintf(buf, "%2d/%3dC %04dR | ", info->temp0, info->temp2, lowfan);
  920. }
  921. /* We use a replacement algorithm to only remove references to work done from
  922. * the buffer when we need the extra space for new work. */
  923. static bool avalon_fill(struct cgpu_info *avalon)
  924. {
  925. struct avalon_info *info = avalon->device_data;
  926. int subid, slot, mc;
  927. struct work *work;
  928. bool ret = true;
  929. mc = info->miner_count;
  930. mutex_lock(&info->qlock);
  931. if (avalon->queued >= mc)
  932. goto out_unlock;
  933. work = get_queued(avalon);
  934. if (unlikely(!work)) {
  935. ret = false;
  936. goto out_unlock;
  937. }
  938. subid = avalon->queued++;
  939. work->subid = subid;
  940. slot = avalon->work_array * mc + subid;
  941. if (likely(avalon->works[slot]))
  942. work_completed(avalon, avalon->works[slot]);
  943. avalon->works[slot] = work;
  944. if (avalon->queued < mc)
  945. ret = false;
  946. out_unlock:
  947. mutex_unlock(&info->qlock);
  948. return ret;
  949. }
  950. static int64_t avalon_scanhash(struct thr_info *thr)
  951. {
  952. struct cgpu_info *avalon = thr->cgpu;
  953. struct avalon_info *info = avalon->device_data;
  954. const int miner_count = info->miner_count;
  955. struct timeval now, then, tdiff;
  956. int64_t hash_count, us_timeout;
  957. struct timespec abstime;
  958. /* Half nonce range */
  959. us_timeout = 0x80000000ll / info->asic_count / info->frequency;
  960. tdiff.tv_sec = us_timeout / 1000000;
  961. tdiff.tv_usec = us_timeout - (tdiff.tv_sec * 1000000);
  962. cgtime(&now);
  963. timeradd(&now, &tdiff, &then);
  964. abstime.tv_sec = then.tv_sec;
  965. abstime.tv_nsec = then.tv_usec * 1000;
  966. /* Wait until avalon_send_tasks signals us that it has completed
  967. * sending its work or a full nonce range timeout has occurred */
  968. mutex_lock(&info->qlock);
  969. pthread_cond_timedwait(&info->qcond, &info->qlock, &abstime);
  970. mutex_unlock(&info->qlock);
  971. mutex_lock(&info->lock);
  972. hash_count = 0xffffffffull * (uint64_t)info->nonces;
  973. avalon->results += info->nonces;
  974. if (avalon->results > miner_count)
  975. avalon->results = miner_count;
  976. if (!info->idle && !info->reset)
  977. avalon->results -= miner_count / 3;
  978. else
  979. avalon->results = miner_count;
  980. info->nonces = 0;
  981. mutex_unlock(&info->lock);
  982. /* Check for nothing but consecutive bad results or consistently less
  983. * results than we should be getting and reset the FPGA if necessary */
  984. if (avalon->results < -miner_count && !info->reset) {
  985. applog(LOG_ERR, "AVA%d: Result return rate low, resetting!",
  986. avalon->device_id);
  987. info->reset = true;
  988. }
  989. if (unlikely(avalon->usbinfo.nodev)) {
  990. applog(LOG_ERR, "AVA%d: Device disappeared, shutting down thread",
  991. avalon->device_id);
  992. avalon->shutdown = true;
  993. }
  994. /* This hashmeter is just a utility counter based on returned shares */
  995. return hash_count;
  996. }
  997. static void avalon_flush_work(struct cgpu_info *avalon)
  998. {
  999. struct avalon_info *info = avalon->device_data;
  1000. mutex_lock(&info->qlock);
  1001. /* Will overwrite any work queued */
  1002. avalon->queued = 0;
  1003. pthread_cond_signal(&info->qcond);
  1004. mutex_unlock(&info->qlock);
  1005. }
  1006. static struct api_data *avalon_api_stats(struct cgpu_info *cgpu)
  1007. {
  1008. struct api_data *root = NULL;
  1009. struct avalon_info *info = cgpu->device_data;
  1010. int i;
  1011. root = api_add_int(root, "baud", &(info->baud), false);
  1012. root = api_add_int(root, "miner_count", &(info->miner_count),false);
  1013. root = api_add_int(root, "asic_count", &(info->asic_count), false);
  1014. root = api_add_int(root, "timeout", &(info->timeout), false);
  1015. root = api_add_int(root, "frequency", &(info->frequency), false);
  1016. root = api_add_int(root, "fan1", &(info->fan0), false);
  1017. root = api_add_int(root, "fan2", &(info->fan1), false);
  1018. root = api_add_int(root, "fan3", &(info->fan2), false);
  1019. root = api_add_int(root, "temp1", &(info->temp0), false);
  1020. root = api_add_int(root, "temp2", &(info->temp1), false);
  1021. root = api_add_int(root, "temp3", &(info->temp2), false);
  1022. root = api_add_int(root, "temp_max", &(info->temp_max), false);
  1023. root = api_add_int(root, "no_matching_work", &(info->no_matching_work), false);
  1024. for (i = 0; i < info->miner_count; i++) {
  1025. char mcw[24];
  1026. sprintf(mcw, "match_work_count%d", i + 1);
  1027. root = api_add_int(root, mcw, &(info->matching_work[i]), false);
  1028. }
  1029. return root;
  1030. }
  1031. static void avalon_shutdown(struct thr_info *thr)
  1032. {
  1033. do_avalon_close(thr);
  1034. }
  1035. struct device_drv avalon_drv = {
  1036. .drv_id = DRIVER_AVALON,
  1037. .dname = "avalon",
  1038. .name = "AVA",
  1039. .drv_detect = avalon_detect,
  1040. .thread_prepare = avalon_prepare,
  1041. .hash_work = hash_queued_work,
  1042. .queue_full = avalon_fill,
  1043. .scanwork = avalon_scanhash,
  1044. .flush_work = avalon_flush_work,
  1045. .get_api_stats = avalon_api_stats,
  1046. .get_statline_before = get_avalon_statline_before,
  1047. .reinit_device = avalon_init,
  1048. .thread_shutdown = avalon_shutdown,
  1049. };