driver-avalon.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687
  1. /*
  2. * Copyright 2012 2013 Xiangfu <xiangfu@openmobilefree.com>
  3. * Copyright 2012 Andrew Smith
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License as published by the Free
  7. * Software Foundation; either version 3 of the License, or (at your option)
  8. * any later version. See COPYING for more details.
  9. */
  10. #include "config.h"
  11. #include <limits.h>
  12. #include <pthread.h>
  13. #include <stdio.h>
  14. #include <sys/time.h>
  15. #include <sys/types.h>
  16. #include <dirent.h>
  17. #include <unistd.h>
  18. #ifndef WIN32
  19. #include <termios.h>
  20. #include <sys/stat.h>
  21. #include <fcntl.h>
  22. #ifndef O_CLOEXEC
  23. #define O_CLOEXEC 0
  24. #endif
  25. #else
  26. #include <windows.h>
  27. #include <io.h>
  28. #endif
  29. #include "elist.h"
  30. #include "miner.h"
  31. #include "fpgautils.h"
  32. #include "driver-avalon.h"
  33. #include "hexdump.c"
  34. static int option_offset = -1;
  35. static struct avalon_info **avalon_info;
  36. struct device_api avalon_api;
  37. static int avalon_init_task(struct avalon_task *at, uint8_t reset, uint8_t ff,
  38. uint8_t fan, uint8_t timeout, uint8_t chip_num,
  39. uint8_t miner_num)
  40. {
  41. static bool first = true;
  42. if (!at)
  43. return -1;
  44. memset(at, 0, sizeof(struct avalon_task));
  45. if (reset) {
  46. at->reset = 1;
  47. first = true;
  48. }
  49. at->flush_fifo = (ff ? 1 : 0);
  50. at->fan_eft = (fan ? 1 : 0);
  51. if (timeout || chip_num || miner_num) {
  52. at->timer_eft = 1;
  53. }
  54. if (first && !at->reset) {
  55. at->fan_eft = 1;
  56. at->timer_eft = 1;
  57. first = false;
  58. }
  59. at->fan_pwm_data = (fan ? fan : AVALON_DEFAULT_FAN_PWM);
  60. at->timeout_data = (timeout ? timeout : AVALON_DEFAULT_TIMEOUT);
  61. at->chip_num = (chip_num ? chip_num : AVALON_DEFAULT_CHIP_NUM);
  62. at->miner_num = (miner_num ? miner_num : AVALON_DEFAULT_MINER_NUM);
  63. at->nonce_elf = 1;
  64. return 0;
  65. }
  66. static inline void avalon_create_task(struct avalon_task *at,
  67. struct work *work)
  68. {
  69. memcpy(at->midstate, work->midstate, 32);
  70. memcpy(at->data, work->data + 64, 12);
  71. }
  72. static int avalon_send_task(int fd, const struct avalon_task *at)
  73. {
  74. size_t ret;
  75. int full;
  76. struct timespec p;
  77. uint8_t *buf;
  78. size_t nr_len;
  79. nr_len = AVALON_WRITE_SIZE + 4 * at->chip_num;
  80. buf = calloc(1, AVALON_WRITE_SIZE + nr_len);
  81. if (!buf)
  82. return AVA_SEND_ERROR;
  83. memcpy(buf, at, AVALON_WRITE_SIZE);
  84. #if defined(__BIG_ENDIAN__) || defined(MIPSEB)
  85. uint8_t tt = 0;
  86. tt = (buf[0] & 0x0f) << 4;
  87. tt |= ((buf[0] & 0x10) ? (1 << 3) : 0);
  88. tt |= ((buf[0] & 0x20) ? (1 << 2) : 0);
  89. tt |= ((buf[0] & 0x40) ? (1 << 1) : 0);
  90. tt |= ((buf[0] & 0x80) ? (1 << 0) : 0);
  91. buf[0] = tt;
  92. buf[4] = rev8(buf[4]);
  93. #endif
  94. if (opt_debug) {
  95. applog(LOG_DEBUG, "Avalon: Sent(%d):", nr_len);
  96. hexdump((uint8_t *)buf, nr_len);
  97. }
  98. ret = write(fd, buf, nr_len);
  99. free(buf);
  100. if (unlikely(ret != nr_len))
  101. return AVA_SEND_ERROR;
  102. p.tv_sec = 0;
  103. p.tv_nsec = AVALON_SEND_WORK_PITCH;
  104. nanosleep(&p, NULL);
  105. full = avalon_buffer_full(fd);
  106. applog(LOG_DEBUG, "Avalon: Sent: Buffer full: %s",
  107. ((full == AVA_BUFFER_FULL) ? "Yes" : "No"));
  108. if (full == AVA_BUFFER_EMPTY)
  109. return AVA_SEND_BUFFER_EMPTY;
  110. return AVA_SEND_BUFFER_FULL;
  111. }
  112. static int avalon_gets(int fd, uint8_t *buf, int read_count,
  113. struct thr_info *thr, struct timeval *tv_finish)
  114. {
  115. ssize_t ret = 0;
  116. int rc = 0;
  117. int read_amount = AVALON_READ_SIZE;
  118. bool first = true;
  119. /* Read reply 1 byte at a time to get earliest tv_finish */
  120. while (true) {
  121. ret = read(fd, buf, 1);
  122. if (ret < 0)
  123. return AVA_GETS_ERROR;
  124. if (first && tv_finish != NULL)
  125. gettimeofday(tv_finish, NULL);
  126. if (ret >= read_amount)
  127. return AVA_GETS_OK;
  128. if (ret > 0) {
  129. buf += ret;
  130. read_amount -= ret;
  131. first = false;
  132. continue;
  133. }
  134. rc++;
  135. if (rc >= read_count) {
  136. if (opt_debug) {
  137. applog(LOG_ERR,
  138. "Avalon: No data in %.2f seconds",
  139. (float)rc/(float)TIME_FACTOR);
  140. }
  141. return AVA_GETS_TIMEOUT;
  142. }
  143. if (thr && thr->work_restart) {
  144. if (opt_debug) {
  145. applog(LOG_ERR,
  146. "Avalon: Work restart at %.2f seconds",
  147. (float)(rc)/(float)TIME_FACTOR);
  148. }
  149. return AVA_GETS_RESTART;
  150. }
  151. }
  152. }
  153. static int avalon_get_result(int fd, struct avalon_result *ar,
  154. struct thr_info *thr, struct timeval *tv_finish)
  155. {
  156. struct cgpu_info *avalon;
  157. struct avalon_info *info;
  158. uint8_t result[AVALON_READ_SIZE];
  159. int ret, read_count = 16;
  160. if (thr) {
  161. avalon = thr->cgpu;
  162. info = avalon_info[avalon->device_id];
  163. read_count = info->read_count;
  164. }
  165. memset(result, 0, AVALON_READ_SIZE);
  166. ret = avalon_gets(fd, result, read_count, thr, tv_finish);
  167. if (ret == AVA_GETS_OK) {
  168. if (opt_debug) {
  169. applog(LOG_DEBUG, "Avalon: get:");
  170. hexdump((uint8_t *)result, AVALON_READ_SIZE);
  171. }
  172. memcpy((uint8_t *)ar, result, AVALON_READ_SIZE);
  173. }
  174. return ret;
  175. }
  176. static int avalon_decode_nonce(struct work **work, struct avalon_result *ar,
  177. uint32_t *nonce)
  178. {
  179. int i;
  180. if (!work)
  181. return -1;
  182. for (i = 0; i < AVALON_GET_WORK_COUNT; i++) {
  183. if (work[i] &&
  184. !memcmp(ar->data, work[i]->data + 64, 12) &&
  185. !memcmp(ar->midstate, work[i]->midstate, 32))
  186. break;
  187. }
  188. if (i == AVALON_GET_WORK_COUNT)
  189. return -1;
  190. *nonce = ar->nonce;
  191. #if defined (__BIG_ENDIAN__) || defined(MIPSEB)
  192. *nonce = swab32(*nonce);
  193. #endif
  194. applog(LOG_DEBUG, "Avalon: match to work[%d]: %p", i, work[i]);
  195. return i;
  196. }
  197. static int avalon_reset(int fd)
  198. {
  199. struct avalon_task at;
  200. struct avalon_result ar;
  201. uint8_t *buf;
  202. int ret, i;
  203. struct timespec p;
  204. avalon_init_task(&at,
  205. 1,
  206. 0,
  207. AVALON_DEFAULT_FAN_PWM,
  208. AVALON_DEFAULT_TIMEOUT,
  209. AVALON_DEFAULT_CHIP_NUM,
  210. AVALON_DEFAULT_MINER_NUM);
  211. ret = avalon_send_task(fd, &at);
  212. if (ret == AVA_SEND_ERROR)
  213. return 1;
  214. avalon_get_result(fd, &ar, NULL, NULL);
  215. buf = (uint8_t *)&ar;
  216. for (i = 0; i < 11; i++)
  217. if (buf[i] != 0)
  218. break;
  219. /* FIXME: add more avalon info base on return */
  220. if (i != 11) {
  221. applog(LOG_ERR, "Avalon: Reset failed! not a Avalon?");
  222. return 1;
  223. }
  224. p.tv_sec = 1;
  225. p.tv_nsec = AVALON_RESET_PITCH;
  226. nanosleep(&p, NULL);
  227. applog(LOG_ERR, "Avalon: Reset succeeded");
  228. return 0;
  229. }
  230. static void do_avalon_close(struct thr_info *thr)
  231. {
  232. struct cgpu_info *avalon = thr->cgpu;
  233. avalon_close(avalon->device_fd);
  234. avalon->device_fd = -1;
  235. }
  236. static void set_timing_mode(struct cgpu_info *avalon)
  237. {
  238. struct avalon_info *info = avalon_info[avalon->device_id];
  239. /* Anything else in buf just uses DEFAULT mode */
  240. info->Hs = AVALON_HASH_TIME;
  241. info->fullnonce = info->Hs * (((double)0xffffffff) + 1);
  242. info->read_count =
  243. (int)(info->fullnonce * TIME_FACTOR) - 1;
  244. }
  245. static void get_options(int this_option_offset, int *baud, int *miner_count,
  246. int *asic_count)
  247. {
  248. char err_buf[BUFSIZ+1];
  249. char buf[BUFSIZ+1];
  250. char *ptr, *comma, *colon, *colon2;
  251. size_t max;
  252. int i, tmp;
  253. if (opt_avalon_options == NULL)
  254. buf[0] = '\0';
  255. else {
  256. ptr = opt_avalon_options;
  257. for (i = 0; i < this_option_offset; i++) {
  258. comma = strchr(ptr, ',');
  259. if (comma == NULL)
  260. break;
  261. ptr = comma + 1;
  262. }
  263. comma = strchr(ptr, ',');
  264. if (comma == NULL)
  265. max = strlen(ptr);
  266. else
  267. max = comma - ptr;
  268. if (max > BUFSIZ)
  269. max = BUFSIZ;
  270. strncpy(buf, ptr, max);
  271. buf[max] = '\0';
  272. }
  273. *baud = AVALON_IO_SPEED;
  274. *miner_count = AVALON_DEFAULT_MINER_NUM;
  275. *asic_count = AVALON_DEFAULT_CHIP_NUM;
  276. if (*buf) {
  277. colon = strchr(buf, ':');
  278. if (colon)
  279. *(colon++) = '\0';
  280. if (*buf) {
  281. tmp = atoi(buf);
  282. switch (tmp) {
  283. case 115200:
  284. *baud = 115200;
  285. break;
  286. case 57600:
  287. *baud = 57600;
  288. break;
  289. case 19200:
  290. *baud = 19200;
  291. break;
  292. default:
  293. sprintf(err_buf,
  294. "Invalid avalon-options for baud (%s) "
  295. "must be 115200, 57600 or 19200", buf);
  296. quit(1, err_buf);
  297. }
  298. }
  299. if (colon && *colon) {
  300. colon2 = strchr(colon, ':');
  301. if (colon2)
  302. *(colon2++) = '\0';
  303. if (*colon) {
  304. tmp = atoi(colon);
  305. if (tmp > 0 && tmp <= AVALON_DEFAULT_MINER_NUM) {
  306. *miner_count = tmp;
  307. } else {
  308. sprintf(err_buf,
  309. "Invalid avalon-options for "
  310. "miner_count (%s) must be 1 ~ %d",
  311. colon, AVALON_DEFAULT_MINER_NUM);
  312. quit(1, err_buf);
  313. }
  314. }
  315. if (colon2 && *colon2) {
  316. tmp = atoi(colon2);
  317. if (tmp > 0 && tmp <= AVALON_DEFAULT_CHIP_NUM)
  318. *asic_count = tmp;
  319. else {
  320. sprintf(err_buf,
  321. "Invalid avalon-options for "
  322. "asic_count (%s) must be 1 ~ %d",
  323. colon2, AVALON_DEFAULT_CHIP_NUM);
  324. quit(1, err_buf);
  325. }
  326. }
  327. }
  328. }
  329. }
  330. static bool avalon_detect_one(const char *devpath)
  331. {
  332. struct avalon_info *info;
  333. int fd, ret;
  334. int baud, miner_count, asic_count;
  335. int this_option_offset = ++option_offset;
  336. get_options(this_option_offset, &baud, &miner_count, &asic_count);
  337. applog(LOG_DEBUG, "Avalon Detect: Attempting to open %s "
  338. "(baud=%d miner_count=%d asic_count=%d)",
  339. devpath, baud, miner_count, asic_count);
  340. fd = avalon_open2(devpath, baud, true);
  341. if (unlikely(fd == -1)) {
  342. applog(LOG_ERR, "Avalon Detect: Failed to open %s", devpath);
  343. return false;
  344. }
  345. ret = avalon_reset(fd);
  346. avalon_close(fd);
  347. if (ret)
  348. return false;
  349. /* We have a real Avalon! */
  350. struct cgpu_info *avalon;
  351. avalon = calloc(1, sizeof(struct cgpu_info));
  352. avalon->api = &avalon_api;
  353. avalon->device_path = strdup(devpath);
  354. avalon->device_fd = -1;
  355. avalon->threads = AVALON_MINER_THREADS;
  356. add_cgpu(avalon);
  357. avalon_info = realloc(avalon_info,
  358. sizeof(struct avalon_info *) *
  359. (total_devices + 1));
  360. applog(LOG_INFO, "Avalon Detect: Found at %s, mark as %d",
  361. devpath, avalon->device_id);
  362. avalon_info[avalon->device_id] = (struct avalon_info *)
  363. malloc(sizeof(struct avalon_info));
  364. if (unlikely(!(avalon_info[avalon->device_id])))
  365. quit(1, "Failed to malloc avalon_info");
  366. info = avalon_info[avalon->device_id];
  367. memset(info, 0, sizeof(struct avalon_info));
  368. info->baud = baud;
  369. info->miner_count = miner_count;
  370. info->asic_count = asic_count;
  371. set_timing_mode(avalon);
  372. return true;
  373. }
  374. static inline void avalon_detect()
  375. {
  376. serial_detect(&avalon_api, avalon_detect_one);
  377. }
  378. static bool avalon_prepare(struct thr_info *thr)
  379. {
  380. struct cgpu_info *avalon = thr->cgpu;
  381. struct timeval now;
  382. int fd, ret;
  383. avalon->device_fd = -1;
  384. fd = avalon_open(avalon->device_path,
  385. avalon_info[avalon->device_id]->baud);
  386. if (unlikely(fd == -1)) {
  387. applog(LOG_ERR, "Avalon: Failed to open on %s",
  388. avalon->device_path);
  389. return false;
  390. }
  391. ret = avalon_reset(fd);
  392. if (ret)
  393. return false;
  394. avalon->device_fd = fd;
  395. applog(LOG_INFO, "Avalon: Opened on %s", avalon->device_path);
  396. gettimeofday(&now, NULL);
  397. get_datestamp(avalon->init, &now);
  398. return true;
  399. }
  400. static void avalon_free_work(struct work **work)
  401. {
  402. int i;
  403. if (!work)
  404. return;
  405. for (i = 0; i < AVALON_GET_WORK_COUNT; i++)
  406. if (work[i]) {
  407. free_work(work[i]);
  408. work[i] = NULL;
  409. }
  410. }
  411. static int64_t avalon_scanhash(struct thr_info *thr, struct work **bulk_work,
  412. __maybe_unused int64_t max_nonce)
  413. {
  414. struct cgpu_info *avalon;
  415. int fd;
  416. int ret;
  417. int full;
  418. struct avalon_info *info;
  419. struct avalon_task at;
  420. struct avalon_result ar;
  421. static struct work *bulk0[3] = {NULL, NULL, NULL};
  422. static struct work *bulk1[3] = {NULL, NULL, NULL};
  423. static struct work *bulk2[3] = {NULL, NULL, NULL};
  424. struct work **work = NULL;
  425. int i, work_i0, work_i1, work_i2;
  426. uint32_t nonce;
  427. int64_t hash_count;
  428. struct timeval tv_start, tv_finish, elapsed;
  429. int curr_hw_errors;
  430. bool was_hw_error;
  431. int64_t estimate_hashes;
  432. avalon = thr->cgpu;
  433. info = avalon_info[avalon->device_id];
  434. if (avalon->device_fd == -1)
  435. if (!avalon_prepare(thr)) {
  436. applog(LOG_ERR, "AVA%i: Comms error",
  437. avalon->device_id);
  438. dev_error(avalon, REASON_DEV_COMMS_ERROR);
  439. /* fail the device if the reopen attempt fails */
  440. return -1;
  441. }
  442. fd = avalon->device_fd;
  443. #ifndef WIN32
  444. tcflush(fd, TCOFLUSH);
  445. #endif
  446. work = bulk_work;
  447. for (i = 0; i < AVALON_GET_WORK_COUNT; i++) {
  448. bulk0[i] = bulk1[i];
  449. bulk1[i] = bulk2[i];
  450. bulk2[i] = work[i];
  451. applog(LOG_DEBUG, "Avalon: bulk0/1/2 buffer [%d]: %p, %p, %p",
  452. i, bulk0[i], bulk1[i], bulk2[i]);
  453. }
  454. i = 0;
  455. while (true) {
  456. avalon_init_default_task(&at);
  457. avalon_create_task(&at, work[i]);
  458. ret = avalon_send_task(fd, &at);
  459. if (ret == AVA_SEND_ERROR) {
  460. avalon_free_work(bulk0);
  461. avalon_free_work(bulk1);
  462. avalon_free_work(bulk2);
  463. do_avalon_close(thr);
  464. applog(LOG_ERR, "AVA%i: Comms error",
  465. avalon->device_id);
  466. dev_error(avalon, REASON_DEV_COMMS_ERROR);
  467. sleep(1);
  468. return 0; /* This should never happen */
  469. }
  470. work[i]->blk.nonce = 0xffffffff;
  471. if (ret == AVA_SEND_BUFFER_FULL)
  472. break;
  473. i++;
  474. if (i == AVALON_GET_WORK_COUNT &&
  475. ret != AVA_SEND_BUFFER_FULL) {
  476. return 0xffffffff;
  477. }
  478. }
  479. elapsed.tv_sec = elapsed.tv_usec = 0;
  480. gettimeofday(&tv_start, NULL);
  481. while(true) {
  482. full = avalon_buffer_full(fd);
  483. applog(LOG_DEBUG, "Avalon: Buffer full: %s",
  484. ((full == AVA_BUFFER_FULL) ? "Yes" : "No"));
  485. if (full == AVA_BUFFER_EMPTY)
  486. break;
  487. work_i0 = work_i1 = work_i2 = -1;
  488. ret = avalon_get_result(fd, &ar, thr, &tv_finish);
  489. if (ret == AVA_GETS_ERROR) {
  490. avalon_free_work(bulk0);
  491. avalon_free_work(bulk1);
  492. avalon_free_work(bulk2);
  493. do_avalon_close(thr);
  494. applog(LOG_ERR,
  495. "AVA%i: Comms error", avalon->device_id);
  496. dev_error(avalon, REASON_DEV_COMMS_ERROR);
  497. return 0;
  498. }
  499. /* aborted before becoming idle, get new work */
  500. if (ret == AVA_GETS_TIMEOUT) {
  501. timersub(&tv_finish, &tv_start, &elapsed);
  502. estimate_hashes = ((double)(elapsed.tv_sec) +
  503. ((double)(elapsed.tv_usec)) /
  504. ((double)1000000)) / info->Hs;
  505. /* If Serial-USB delay allowed the full nonce range to
  506. * complete it can't have done more than a full nonce
  507. */
  508. if (unlikely(estimate_hashes > 0xffffffff))
  509. estimate_hashes = 0xffffffff;
  510. applog(LOG_DEBUG,
  511. "Avalon: no nonce = 0x%08llx hashes "
  512. "(%ld.%06lds)",
  513. estimate_hashes, elapsed.tv_sec,
  514. elapsed.tv_usec);
  515. continue;
  516. }
  517. if (ret == AVA_GETS_RESTART) {
  518. avalon_free_work(bulk0);
  519. avalon_free_work(bulk1);
  520. avalon_free_work(bulk2);
  521. continue;
  522. }
  523. work_i0 = avalon_decode_nonce(bulk0, &ar, &nonce);
  524. work_i1 = avalon_decode_nonce(bulk1, &ar, &nonce);
  525. work_i2 = avalon_decode_nonce(bulk2, &ar, &nonce);
  526. curr_hw_errors = avalon->hw_errors;
  527. if (work_i0 >= 0)
  528. submit_nonce(thr, bulk0[work_i0], nonce);
  529. if (work_i1 >= 0)
  530. submit_nonce(thr, bulk1[work_i1], nonce);
  531. if (work_i2 >= 0)
  532. submit_nonce(thr, bulk2[work_i2], nonce);
  533. was_hw_error = (curr_hw_errors > avalon->hw_errors);
  534. /* Force a USB close/reopen on any hw error */
  535. if (was_hw_error)
  536. do_avalon_close(thr);
  537. hash_count = nonce;
  538. hash_count++;
  539. hash_count *= info->asic_count;
  540. }
  541. avalon_free_work(bulk0);
  542. if (opt_debug) {
  543. timersub(&tv_finish, &tv_start, &elapsed);
  544. applog(LOG_DEBUG,
  545. "Avalon: nonce = 0x%08x = 0x%08llx hashes "
  546. "(%ld.%06lds)",
  547. nonce, hash_count, elapsed.tv_sec, elapsed.tv_usec);
  548. }
  549. return hash_count;
  550. }
  551. static struct api_data *avalon_api_stats(struct cgpu_info *cgpu)
  552. {
  553. struct api_data *root = NULL;
  554. struct avalon_info *info = avalon_info[cgpu->device_id];
  555. /* Warning, access to these is not locked - but we don't really
  556. * care since hashing performance is way more important than
  557. * locking access to displaying API debug 'stats'
  558. * If locking becomes an issue for any of them, use copy_data=true also */
  559. root = api_add_int(root, "read_count", &(info->read_count), false);
  560. root = api_add_double(root, "fullnonce", &(info->fullnonce), false);
  561. root = api_add_int(root, "baud", &(info->baud), false);
  562. root = api_add_int(root, "miner_count", &(info->miner_count),
  563. false);
  564. root = api_add_int(root, "asic_count", &(info->asic_count), false);
  565. return root;
  566. }
  567. static void avalon_shutdown(struct thr_info *thr)
  568. {
  569. do_avalon_close(thr);
  570. }
  571. struct device_api avalon_api = {
  572. .dname = "avalon",
  573. .name = "AVA",
  574. .api_detect = avalon_detect,
  575. .thread_prepare = avalon_prepare,
  576. .scanhash_queue = avalon_scanhash,
  577. .get_api_stats = avalon_api_stats,
  578. .thread_shutdown = avalon_shutdown,
  579. };