driver-avalon.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  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 ~ 32",
  311. colon);
  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 ~ 10 ",
  323. colon2);
  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", devpath);
  338. fd = avalon_open2(devpath, baud, true);
  339. if (unlikely(fd == -1)) {
  340. applog(LOG_ERR, "Avalon Detect: Failed to open %s", devpath);
  341. return false;
  342. }
  343. ret = avalon_reset(fd);
  344. avalon_close(fd);
  345. if (ret)
  346. return false;
  347. /* We have a real Avalon! */
  348. struct cgpu_info *avalon;
  349. avalon = calloc(1, sizeof(struct cgpu_info));
  350. avalon->api = &avalon_api;
  351. avalon->device_path = strdup(devpath);
  352. avalon->device_fd = -1;
  353. avalon->threads = AVALON_MINER_THREADS;
  354. add_cgpu(avalon);
  355. avalon_info = realloc(avalon_info,
  356. sizeof(struct avalon_info *) *
  357. (total_devices + 1));
  358. applog(LOG_INFO, "Avalon Detect: Found at %s, mark as %d",
  359. devpath, avalon->device_id);
  360. applog(LOG_DEBUG,
  361. "Avalon: Init: %d baud=%d miner_count=%d asic_count=%d",
  362. avalon->device_id, baud, miner_count, asic_count);
  363. avalon_info[avalon->device_id] = (struct avalon_info *)
  364. malloc(sizeof(struct avalon_info));
  365. if (unlikely(!(avalon_info[avalon->device_id])))
  366. quit(1, "Failed to malloc avalon_info");
  367. info = avalon_info[avalon->device_id];
  368. memset(info, 0, sizeof(struct avalon_info));
  369. info->baud = baud;
  370. info->miner_count = miner_count;
  371. info->asic_count = asic_count;
  372. set_timing_mode(avalon);
  373. return true;
  374. }
  375. static inline void avalon_detect()
  376. {
  377. serial_detect(&avalon_api, avalon_detect_one);
  378. }
  379. static bool avalon_prepare(struct thr_info *thr)
  380. {
  381. struct cgpu_info *avalon = thr->cgpu;
  382. struct timeval now;
  383. int fd, ret;
  384. avalon->device_fd = -1;
  385. fd = avalon_open(avalon->device_path,
  386. avalon_info[avalon->device_id]->baud);
  387. if (unlikely(fd == -1)) {
  388. applog(LOG_ERR, "Avalon: Failed to open on %s",
  389. avalon->device_path);
  390. return false;
  391. }
  392. ret = avalon_reset(fd);
  393. if (ret)
  394. return false;
  395. avalon->device_fd = fd;
  396. applog(LOG_INFO, "Avalon: Opened on %s", avalon->device_path);
  397. gettimeofday(&now, NULL);
  398. get_datestamp(avalon->init, &now);
  399. return true;
  400. }
  401. static void avalon_free_work(struct work **work)
  402. {
  403. int i;
  404. if (!work)
  405. return;
  406. for (i = 0; i < AVALON_GET_WORK_COUNT; i++)
  407. if (work[i]) {
  408. free_work(work[i]);
  409. work[i] = NULL;
  410. }
  411. }
  412. static int64_t avalon_scanhash(struct thr_info *thr, struct work **bulk_work,
  413. __maybe_unused int64_t max_nonce)
  414. {
  415. struct cgpu_info *avalon;
  416. int fd;
  417. int ret;
  418. int full;
  419. struct avalon_info *info;
  420. struct avalon_task at;
  421. struct avalon_result ar;
  422. static struct work *bulk0[3] = {NULL, NULL, NULL};
  423. static struct work *bulk1[3] = {NULL, NULL, NULL};
  424. static struct work *bulk2[3] = {NULL, NULL, NULL};
  425. struct work **work = NULL;
  426. int i, work_i0, work_i1, work_i2;
  427. uint32_t nonce;
  428. int64_t hash_count;
  429. struct timeval tv_start, tv_finish, elapsed;
  430. int curr_hw_errors;
  431. bool was_hw_error;
  432. int64_t estimate_hashes;
  433. avalon = thr->cgpu;
  434. info = avalon_info[avalon->device_id];
  435. if (avalon->device_fd == -1)
  436. if (!avalon_prepare(thr)) {
  437. applog(LOG_ERR, "AVA%i: Comms error",
  438. avalon->device_id);
  439. dev_error(avalon, REASON_DEV_COMMS_ERROR);
  440. /* fail the device if the reopen attempt fails */
  441. return -1;
  442. }
  443. fd = avalon->device_fd;
  444. #ifndef WIN32
  445. tcflush(fd, TCOFLUSH);
  446. #endif
  447. work = bulk_work;
  448. for (i = 0; i < AVALON_GET_WORK_COUNT; i++) {
  449. bulk0[i] = bulk1[i];
  450. bulk1[i] = bulk2[i];
  451. bulk2[i] = work[i];
  452. applog(LOG_DEBUG, "Avalon: bulk0/1/2 buffer [%d]: %p, %p, %p",
  453. i, bulk0[i], bulk1[i], bulk2[i]);
  454. }
  455. i = 0;
  456. while (true) {
  457. avalon_init_default_task(&at);
  458. avalon_create_task(&at, work[i]);
  459. ret = avalon_send_task(fd, &at);
  460. if (ret == AVA_SEND_ERROR) {
  461. avalon_free_work(bulk0);
  462. avalon_free_work(bulk1);
  463. avalon_free_work(bulk2);
  464. do_avalon_close(thr);
  465. applog(LOG_ERR, "AVA%i: Comms error",
  466. avalon->device_id);
  467. dev_error(avalon, REASON_DEV_COMMS_ERROR);
  468. sleep(1);
  469. return 0; /* This should never happen */
  470. }
  471. work[i]->blk.nonce = 0xffffffff;
  472. if (ret == AVA_SEND_BUFFER_FULL)
  473. break;
  474. i++;
  475. if (i == AVALON_GET_WORK_COUNT &&
  476. ret != AVA_SEND_BUFFER_FULL) {
  477. return 0xffffffff;
  478. }
  479. }
  480. elapsed.tv_sec = elapsed.tv_usec = 0;
  481. gettimeofday(&tv_start, NULL);
  482. while(true) {
  483. full = avalon_buffer_full(fd);
  484. applog(LOG_DEBUG, "Avalon: Buffer full: %s",
  485. ((full == AVA_BUFFER_FULL) ? "Yes" : "No"));
  486. if (full == AVA_BUFFER_EMPTY)
  487. break;
  488. work_i0 = work_i1 = work_i2 = -1;
  489. ret = avalon_get_result(fd, &ar, thr, &tv_finish);
  490. if (ret == AVA_GETS_ERROR) {
  491. avalon_free_work(bulk0);
  492. avalon_free_work(bulk1);
  493. avalon_free_work(bulk2);
  494. do_avalon_close(thr);
  495. applog(LOG_ERR,
  496. "AVA%i: Comms error", avalon->device_id);
  497. dev_error(avalon, REASON_DEV_COMMS_ERROR);
  498. return 0;
  499. }
  500. /* aborted before becoming idle, get new work */
  501. if (ret == AVA_GETS_TIMEOUT) {
  502. timersub(&tv_finish, &tv_start, &elapsed);
  503. estimate_hashes = ((double)(elapsed.tv_sec) +
  504. ((double)(elapsed.tv_usec)) /
  505. ((double)1000000)) / info->Hs;
  506. /* If Serial-USB delay allowed the full nonce range to
  507. * complete it can't have done more than a full nonce
  508. */
  509. if (unlikely(estimate_hashes > 0xffffffff))
  510. estimate_hashes = 0xffffffff;
  511. applog(LOG_DEBUG,
  512. "Avalon: no nonce = 0x%08llx hashes "
  513. "(%ld.%06lds)",
  514. estimate_hashes, elapsed.tv_sec,
  515. elapsed.tv_usec);
  516. continue;
  517. }
  518. if (ret == AVA_GETS_RESTART) {
  519. avalon_free_work(bulk0);
  520. avalon_free_work(bulk1);
  521. avalon_free_work(bulk2);
  522. continue;
  523. }
  524. work_i0 = avalon_decode_nonce(bulk0, &ar, &nonce);
  525. work_i1 = avalon_decode_nonce(bulk1, &ar, &nonce);
  526. work_i2 = avalon_decode_nonce(bulk2, &ar, &nonce);
  527. curr_hw_errors = avalon->hw_errors;
  528. if (work_i0 >= 0)
  529. submit_nonce(thr, bulk0[work_i0], nonce);
  530. if (work_i1 >= 0)
  531. submit_nonce(thr, bulk1[work_i1], nonce);
  532. if (work_i2 >= 0)
  533. submit_nonce(thr, bulk2[work_i2], nonce);
  534. was_hw_error = (curr_hw_errors > avalon->hw_errors);
  535. /* Force a USB close/reopen on any hw error */
  536. if (was_hw_error)
  537. do_avalon_close(thr);
  538. hash_count = nonce;
  539. hash_count++;
  540. hash_count *= info->asic_count;
  541. }
  542. avalon_free_work(bulk0);
  543. if (opt_debug) {
  544. timersub(&tv_finish, &tv_start, &elapsed);
  545. applog(LOG_DEBUG,
  546. "Avalon: nonce = 0x%08x = 0x%08llx hashes "
  547. "(%ld.%06lds)",
  548. nonce, hash_count, elapsed.tv_sec, elapsed.tv_usec);
  549. }
  550. return hash_count;
  551. }
  552. static struct api_data *avalon_api_stats(struct cgpu_info *cgpu)
  553. {
  554. struct api_data *root = NULL;
  555. struct avalon_info *info = avalon_info[cgpu->device_id];
  556. /* Warning, access to these is not locked - but we don't really
  557. * care since hashing performance is way more important than
  558. * locking access to displaying API debug 'stats'
  559. * If locking becomes an issue for any of them, use copy_data=true also */
  560. root = api_add_int(root, "read_count", &(info->read_count), false);
  561. root = api_add_double(root, "fullnonce", &(info->fullnonce), false);
  562. root = api_add_int(root, "baud", &(info->baud), false);
  563. root = api_add_int(root, "miner_count", &(info->miner_count),
  564. false);
  565. root = api_add_int(root, "asic_count", &(info->asic_count), false);
  566. return root;
  567. }
  568. static void avalon_shutdown(struct thr_info *thr)
  569. {
  570. do_avalon_close(thr);
  571. }
  572. struct device_api avalon_api = {
  573. .dname = "avalon",
  574. .name = "AVA",
  575. .api_detect = avalon_detect,
  576. .thread_prepare = avalon_prepare,
  577. .scanhash_queue = avalon_scanhash,
  578. .get_api_stats = avalon_api_stats,
  579. .thread_shutdown = avalon_shutdown,
  580. };