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