driver-klondike.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. /*
  2. * Copyright 2013 Andrew Smith
  3. * Copyright 2013 Con Kolivas
  4. * Copyright 2013 Chris Savery
  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 <float.h>
  12. #include <limits.h>
  13. #include <pthread.h>
  14. #include <stdint.h>
  15. #include <stdio.h>
  16. #include <strings.h>
  17. #include <sys/time.h>
  18. #include <unistd.h>
  19. #include "config.h"
  20. #ifdef WIN32
  21. #include <windows.h>
  22. #endif
  23. #include "compat.h"
  24. #include "miner.h"
  25. #include "usbutils.h"
  26. #define K1 "K1"
  27. #define K16 "K16"
  28. #define K64 "K64"
  29. #define REPLY_BUFSIZE 64
  30. struct device_drv klondike_drv;
  31. struct klondike_info {
  32. bool shutdown;
  33. };
  34. struct klondike_id {
  35. uint8_t version;
  36. uint32_t serial;
  37. char product[8];
  38. };
  39. struct klondike_status {
  40. uint8_t state;
  41. uint8_t chipcount;
  42. uint8_t slavecount;
  43. uint8_t workqc;
  44. uint8_t workid;
  45. uint8_t temp;
  46. uint8_t fanspeed;
  47. uint16_t hashcount;
  48. uint16_t errorcount;
  49. };
  50. struct kondike_cfg {
  51. uint16_t hashclock;
  52. uint8_t temptarget;
  53. uint8_t tempcritical;
  54. uint8_t fantarget;
  55. };
  56. static bool klondike_detect_one(struct libusb_device *dev, struct usb_find_devices *found)
  57. {
  58. struct cgpu_info *klninfo = calloc(1, sizeof(*klninfo));
  59. char replybuf[REPLY_BUFSIZE];
  60. char devpath[20];
  61. int attempts = 0;
  62. int sent, recd, err;
  63. if (unlikely(!klninfo))
  64. quit(1, "Failed to calloc klninfo in klondike_detect_one");
  65. klninfo->drv = &klondike_drv;
  66. klninfo->deven = DEV_ENABLED;
  67. klninfo->threads = 1;
  68. if (usb_init(klninfo, dev, found)) {
  69. sprintf(devpath, "%d:%d", (int)(klninfo->usbinfo.bus_number), (int)(klninfo->usbinfo.device_address));
  70. while(attempts++ < 2) {
  71. err = usb_write(klninfo, "I", 2, &sent, C_REQUESTIDENTIFY);
  72. if (err < 0 || sent != 2) {
  73. applog(LOG_ERR, "%s detect (%s) send identify request failed (%d:%d)", klninfo->drv->dname, devpath, sent, err);
  74. break;
  75. }
  76. err = usb_read(klninfo, replybuf, sizeof(replybuf), &recd, C_GETIDENTIFY);
  77. if (err < 0) {
  78. applog(LOG_ERR, "%s detect (%s) error identify reply (%d:%d)", klninfo->drv->dname, devpath, recd, err);
  79. } else if (recd < 1) {
  80. applog(LOG_ERR, "%s detect (%s) empty identify reply (%d)", klninfo->drv->dname, devpath, recd);
  81. } else if (replybuf[0] == 'I' && replybuf[1] == 0) {
  82. applog(LOG_DEBUG, "%s (%s) identified as: '%s'", klninfo->drv->dname, devpath, klninfo->drv->name);
  83. // do something with id info
  84. update_usb_stats(klninfo);
  85. return true;
  86. }
  87. }
  88. usb_uninit(klninfo);
  89. }
  90. free(klninfo);
  91. return false;
  92. }
  93. static void klondike_detect(void)
  94. {
  95. usb_detect(&klondike_drv, klondike_detect_one);
  96. }
  97. static void klondike_identify(struct cgpu_info *klninfo)
  98. {
  99. struct klondike_info *k_info = (struct klondike_info *)(klninfo->device_file);
  100. }
  101. static bool klondike_thread_prepare(struct thr_info *thr)
  102. {
  103. struct cgpu_info *klninfo = thr->cgpu;
  104. struct klondike_info *k_info = (struct klondike_info *)(klninfo->device_file);
  105. return true;
  106. }
  107. static bool klondike_thread_init(struct thr_info *thr)
  108. {
  109. struct cgpu_info *klninfo = thr->cgpu;
  110. if (klninfo->usbinfo.nodev)
  111. return false;
  112. //klondike_initialise(klninfo);
  113. return true;
  114. }
  115. static void klondike_flush_work(struct cgpu_info *klninfo)
  116. {
  117. struct klondike_info *k_info = (struct klondike_info *)(klninfo->device_file);
  118. }
  119. static void klondike_shutdown(struct thr_info *thr)
  120. {
  121. struct cgpu_info *klninfo = thr->cgpu;
  122. struct klondike_info *k_info = (struct klondike_info *)(klninfo->device_file);
  123. klondike_flush_work(klninfo);
  124. k_info->shutdown = true;
  125. }
  126. static void klondike_thread_enable(struct thr_info *thr)
  127. {
  128. struct cgpu_info *klninfo = thr->cgpu;
  129. if (klninfo->usbinfo.nodev)
  130. return;
  131. //klondike_initialise(bflsc);
  132. }
  133. static bool klondike_send_work(struct cgpu_info *klninfo, int dev, struct work *work)
  134. {
  135. struct klondike_info *k_info = (struct klondike_info *)(klninfo->device_file);
  136. // Device is gone
  137. if (klninfo->usbinfo.nodev)
  138. return false;
  139. }
  140. static bool klondike_queue_full(struct cgpu_info *klninfo)
  141. {
  142. struct klondike_info *sc_info = (struct klondike_info *)(klninfo->device_file);
  143. }
  144. static int64_t klondike_scanwork(struct thr_info *thr)
  145. {
  146. struct cgpu_info *klninfo = thr->cgpu;
  147. struct klondike_info *sc_info = (struct klondike_info *)(klninfo->device_file);
  148. // Device is gone
  149. if (klninfo->usbinfo.nodev)
  150. return -1;
  151. }
  152. static bool klondike_get_stats(struct cgpu_info *klninfo)
  153. {
  154. struct klondike_info *k_info = (struct klondike_info *)(klninfo->device_file);
  155. bool allok = true;
  156. int i;
  157. // Device is gone
  158. if (klninfo->usbinfo.nodev)
  159. return false;
  160. return allok;
  161. }
  162. static void get_klondike_statline_before(char *buf, struct cgpu_info *klninfo)
  163. {
  164. }
  165. static struct api_data *klondike_api_stats(struct cgpu_info *klninfo)
  166. {
  167. }
  168. struct device_drv klondike_drv = {
  169. .drv_id = DRIVER_KLONDIKE,
  170. .dname = "Klondike",
  171. .name = K16,
  172. .drv_detect = klondike_detect,
  173. .get_api_stats = klondike_api_stats,
  174. .get_statline_before = get_klondike_statline_before,
  175. .get_stats = klondike_get_stats,
  176. .identify_device = klondike_identify,
  177. .thread_prepare = klondike_thread_prepare,
  178. .thread_init = klondike_thread_init,
  179. .hash_work = hash_queued_work,
  180. .scanwork = klondike_scanwork,
  181. .queue_full = klondike_queue_full,
  182. .flush_work = klondike_flush_work,
  183. .thread_shutdown = klondike_shutdown,
  184. .thread_enable = klondike_thread_enable
  185. };