driver-bitfury16.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. #ifndef BITFURY16_H
  2. #define BITFURY16_H
  3. #include "miner.h"
  4. #include "bf16-bitfury16.h"
  5. /* file contains device build revision: one of following */
  6. /* #define MINER_X5 */
  7. /* #define MINER_X6 */
  8. /* #include "bf16-devicerev.h" */
  9. #define MINER_X6
  10. #if defined(MINER_X5) && defined(MINER_X6)
  11. #error "MINER_X5 and MINER_X6 can not be defined both"
  12. #endif
  13. #if !defined(MINER_X5) && !defined(MINER_X6)
  14. #error "At least one of MINER_X5 and MINER_X6 should be defined"
  15. #endif
  16. #define CHIPBOARD_NUM 2 /* chipboard number */
  17. #define BF16_NUM 11 /* chips number per BTC250 concentrator */
  18. #ifdef MINER_X5
  19. #define BCM250_NUM 3 /* BCM250 chips per chipboard */
  20. #define CHANNEL_DEPTH 2 /* maximum channel length */
  21. #define CHIPS_NUM 26 /* BF16 chips per chipboard */
  22. #endif
  23. #ifdef MINER_X6
  24. #define BCM250_NUM 6 /* BCM250 chips per chipboard */
  25. #define CHANNEL_DEPTH 4 /* maximum channel length */
  26. #define CHIPS_NUM 52 /* BF16 chips per chipboard */
  27. #endif
  28. #define FILELOG
  29. enum bf_opt_renonce {
  30. RENONCE_DISABLED,
  31. RENONCE_ONE_CHIP,
  32. RENONCE_CHIP_PER_BOARD
  33. };
  34. /* chip structure */
  35. typedef struct {
  36. uint8_t clock;
  37. bf_chip_status_t status;
  38. uint8_t curr_buff;
  39. uint8_t task_processed;
  40. /* nonces list to extract dups */
  41. bf_list_t* nonce_list;
  42. /* chip statistics */
  43. float nonces;
  44. float task_switch;
  45. float status_cmd;
  46. float status_cmd_none;
  47. uint32_t nonces_dx;
  48. uint32_t nonces_good_dx;
  49. uint32_t nonces_diff_dx;
  50. uint32_t nonces_bad_dx;
  51. uint32_t nonces_re_dx;
  52. uint32_t nonces_re_good_dx;
  53. uint32_t nonces_re_bad_dx;
  54. uint32_t task_switch_dx;
  55. uint32_t status_cmd_dx;
  56. uint32_t status_cmd_none_dx;
  57. float hashrate;
  58. float hashrate_good;
  59. float hashrate_diff;
  60. float hashrate_bad;
  61. float hashrate_re;
  62. float hashrate_re_good;
  63. float hashrate_re_bad;
  64. uint32_t errors; /* error counter */
  65. uint32_t error_rate; /* error rate */
  66. time_t last_error_time;/* time since last error */
  67. uint16_t recovery_count;
  68. time_t last_nonce_time;/* time since last good nonce */
  69. struct timeval status_time; /* time since last status cmd */
  70. struct timeval switch_time; /* time since last task switch */
  71. /* command stuff */
  72. bf_works_t owork; /* old work */
  73. bf_works_t cwork; /* current work */
  74. uint32_t rx[12];
  75. uint32_t rx_prev[12];
  76. } bf_chip_t;
  77. /* chip concentrator init map structure */
  78. typedef struct {
  79. uint8_t channel_path[CHANNEL_DEPTH];
  80. uint8_t first_good_chip;
  81. uint8_t last_good_chip;
  82. uint8_t chips_num;
  83. } bf_bcm250_map_t;
  84. /* chip concentrator structure */
  85. typedef struct {
  86. uint8_t* channel_path; /* channel path to chip concentrator */
  87. uint8_t channel_depth;
  88. uint8_t first_good_chip;
  89. uint8_t last_good_chip;
  90. uint8_t chips_num;
  91. uint8_t chips_failed;
  92. bf_chip_t chips[BF16_NUM];
  93. /* chip statistics */
  94. float nonces;
  95. float task_switch;
  96. float status_cmd;
  97. float status_cmd_none;
  98. uint32_t nonces_dx;
  99. uint32_t nonces_good_dx;
  100. uint32_t nonces_diff_dx;
  101. uint32_t nonces_bad_dx;
  102. uint32_t nonces_re_dx;
  103. uint32_t nonces_re_good_dx;
  104. uint32_t nonces_re_bad_dx;
  105. uint32_t task_switch_dx;
  106. uint32_t status_cmd_dx;
  107. uint32_t status_cmd_none_dx;
  108. float hashrate;
  109. float hashrate_good;
  110. float hashrate_diff;
  111. float hashrate_bad;
  112. float hashrate_re;
  113. float hashrate_re_good;
  114. float hashrate_re_bad;
  115. } bf_bcm250_t;
  116. /* pid structure */
  117. typedef struct {
  118. int16_t i_state; /* integrator state */
  119. int16_t i_max; /* maximum allowable integrator state */
  120. int16_t i_min; /* minimum allowable integrator state */
  121. } bf_pid_t;
  122. typedef enum {
  123. CHIPBOARD_X5,
  124. CHIPBOARD_X6
  125. } bf_chipboard_type_t;
  126. typedef enum {
  127. CHIPBOARD_REV1,
  128. CHIPBOARD_REV2,
  129. CHIPBOARD_REV3
  130. } bf_chipboard_rev_t;
  131. /* chipboard structure */
  132. typedef struct {
  133. bool detected;
  134. bool active;
  135. bf_pid_t pid;
  136. bf_chipboard_type_t board_type;
  137. bf_chipboard_rev_t board_rev;
  138. /* MSP version data */
  139. uint32_t board_ver;
  140. uint32_t board_fwver;
  141. char board_hwid[32];
  142. /* MSP hw data */
  143. float temp;
  144. float u_board;
  145. float p_board;
  146. uint8_t p_chain1_enabled;
  147. uint8_t p_chain2_enabled;
  148. float u_chain1;
  149. float u_chain2;
  150. float i_chain1;
  151. float i_chain2;
  152. float p_chain1;
  153. float p_chain2;
  154. float p_fan;
  155. uint32_t rpm;
  156. uint8_t fan_speed;
  157. float i_alarm;
  158. float t_alarm;
  159. float t_gisteresis;
  160. char fan_mode;
  161. float target_temp;
  162. uint8_t a_temp;
  163. uint8_t a_ichain1;
  164. uint8_t a_ichain2;
  165. uint8_t bcm250_num;
  166. uint8_t chips_num;
  167. uint8_t chips_failed;
  168. uint8_t chips_disabled;
  169. bf_bcm250_t* bcm250;
  170. #ifdef MINER_X5
  171. bool power_disabled;
  172. uint32_t power_disable_count;
  173. time_t power_disable_time;
  174. time_t power_enable_time;
  175. #endif
  176. #ifdef MINER_X6
  177. bool power1_disabled;
  178. bool power2_disabled;
  179. uint32_t power1_disable_count;
  180. uint32_t power2_disable_count;
  181. time_t power1_disable_time;
  182. time_t power2_disable_time;
  183. time_t power1_enable_time;
  184. time_t power2_enable_time;
  185. #endif
  186. bf_cmd_buffer_t cmd_buffer;
  187. /* chip statistics */
  188. float nonces;
  189. float task_switch;
  190. float status_cmd;
  191. float status_cmd_none;
  192. uint32_t nonces_dx;
  193. uint32_t nonces_good_dx;
  194. uint32_t nonces_diff_dx;
  195. uint32_t nonces_bad_dx;
  196. uint32_t nonces_re_dx;
  197. uint32_t nonces_re_good_dx;
  198. uint32_t nonces_re_bad_dx;
  199. uint32_t task_switch_dx;
  200. uint32_t status_cmd_dx;
  201. uint32_t status_cmd_none_dx;
  202. float hashrate;
  203. float hashrate_good;
  204. float hashrate_diff;
  205. float hashrate_bad;
  206. float hashrate_re;
  207. float hashrate_re_good;
  208. float hashrate_re_bad;
  209. float txrx_speed;
  210. uint32_t bytes_transmitted_dx;
  211. uint64_t bytes_transmitted;
  212. } bf_chipboard_t;
  213. struct bitfury16_info {
  214. struct thr_info *thr;
  215. struct thr_info chipworker_thr;
  216. struct thr_info nonceworker_thr;
  217. struct thr_info renonceworker_thr;
  218. struct thr_info hwmonitor_thr;
  219. struct thr_info alarm_thr;
  220. struct thr_info statistics_thr;
  221. #ifdef FILELOG
  222. FILE* logfile;
  223. pthread_mutex_t logfile_mutex;
  224. #endif
  225. uint8_t chipboard_num;
  226. /* boards with all sensors in propriate state */
  227. uint8_t active_chipboard_num;
  228. uint8_t chips_num;
  229. uint8_t chips_failed;
  230. uint8_t chips_disabled;
  231. uint8_t renonce_chips;
  232. bf_chipboard_t* chipboard;
  233. /* work list */
  234. bf_list_t* work_list;
  235. /* work list */
  236. bf_list_t* stale_work_list;
  237. /* nonces for calculation */
  238. bf_list_t* noncework_list;
  239. /* renonces for calculation */
  240. bf_list_t* renoncework_list;
  241. /* nonces for recalculation */
  242. uint32_t renonce_id;
  243. bf_list_t* renonce_list;
  244. uint32_t stage0_match;
  245. uint32_t stage0_mismatch;
  246. uint32_t stage1_match;
  247. uint32_t stage1_mismatch;
  248. uint32_t stage2_match;
  249. uint32_t stage2_mismatch;
  250. uint32_t stage3_match;
  251. uint32_t stage3_mismatch;
  252. uint32_t unmatched;
  253. uint8_t channel_length;
  254. /* driver statistics */
  255. float nonces;
  256. float task_switch;
  257. float status_cmd;
  258. float status_cmd_none;
  259. uint32_t nonces_dx;
  260. uint32_t nonces_good_dx;
  261. uint32_t nonces_diff_dx;
  262. uint32_t nonces_bad_dx;
  263. uint32_t nonces_re_dx;
  264. uint32_t nonces_re_good_dx;
  265. uint32_t nonces_re_bad_dx;
  266. uint32_t task_switch_dx;
  267. uint32_t status_cmd_dx;
  268. uint32_t status_cmd_none_dx;
  269. float hashrate;
  270. float hashrate_good;
  271. float hashrate_diff;
  272. float hashrate_bad;
  273. float hashrate_re;
  274. float hashrate_re_good;
  275. float hashrate_re_bad;
  276. pthread_mutex_t nonces_good_lock;
  277. uint32_t nonces_good_cg;
  278. float u_avg;
  279. float i_total;
  280. float p_total;
  281. float u_chip;
  282. float p_chip;
  283. bool a_temp;
  284. bool a_ichain;
  285. bool a_net;
  286. time_t ialarm_start;
  287. uint16_t ialarm_count;
  288. bool ialarm_buzzer;
  289. bool led_red_enabled;
  290. struct timeval led_red_switch;
  291. bool led_green_enabled;
  292. struct timeval led_green_switch;
  293. bool buzzer_enabled;
  294. struct timeval buzzer_switch;
  295. bool initialised;
  296. };
  297. /* set clock to all chips and exit */
  298. extern bool opt_bf16_set_clock;
  299. /* enable board mining statistics output */
  300. extern bool opt_bf16_stats_enabled;
  301. /* chip clock value */
  302. extern char* opt_bf16_clock;
  303. extern uint8_t bf16_chip_clock;
  304. /* renonce chip clock value */
  305. extern char* opt_bf16_renonce_clock;
  306. extern uint8_t bf16_renonce_chip_clock;
  307. /* renonce configuration */
  308. extern int opt_bf16_renonce;
  309. /* manual PID enabled */
  310. #ifdef MINER_X5
  311. extern bool opt_bf16_manual_pid_enabled;
  312. #endif
  313. #ifdef MINER_X6
  314. extern bool opt_bf16_manual_pid_disabled;
  315. #endif
  316. /* disable automatic power management */
  317. extern bool opt_bf16_power_management_disabled;
  318. /* fan speed */
  319. extern int opt_bf16_fan_speed;
  320. /* target temp */
  321. extern int opt_bf16_target_temp;
  322. /* alarm temp */
  323. extern int opt_bf16_alarm_temp;
  324. /* test chip communication */
  325. extern char* opt_bf16_test_chip;
  326. #endif /* BITFURY16_H */