forked from kanoi/cgminer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
driver-bitfury16.c
4677 lines (3824 loc) · 157 KB
/
driver-bitfury16.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "config.h"
#include "math.h"
#include "miner.h"
#include "bf16-communication.h"
#include "bf16-ctrldevice.h"
#include "bf16-mspcontrol.h"
#include "bf16-spidevice.h"
#include "bf16-uartdevice.h"
#include "driver-bitfury16.h"
#ifdef FILELOG
#define LOGFILE "/var/log/cgminer.log"
#endif
#define DISABLE_SEND_CMD_ERROR
#define POWER_WAIT_INTERVAL 100000
#define RENONCE_SEND 5
#define RENONCE_STAGE2_LIMIT 80
#define RENONCE_STAGE3_LIMIT 60
#define RENONCE_QUEUE_LEN 100
#define RENONCE_COUNT 29
/* chip nonce queue len */
#define NONCE_CHIP_QUEUE_LEN 7
#define RENONCE_CHIP_QUEUE_LEN 40
#define WORK_TIMEOUT 2.0
/* statistics intervals */
#define AVG_TIME_DELTA 5.0
#define AVG_TIME_INTERVAL 5.0
/* power chain alarm interval */
#define ICHAIN_ALARM_INTERVAL 60
#define U_LOSS 0.2
/* power chain reenable timeout */
#define CHAIN_REENABLE_INTERVAL 10
#define CHAIN_WORK_INTERVAL 1200
/* disable chip if no good nonces received during CHIP_FAILING_INTERVAL */
#define RENONCE_CHIP_FAILING_INTERVAL 15.0
#define CHIP_FAILING_INTERVAL 30.0
#define CHIP_RECOVERY_INTERVAL 5.0
/* chip is considered to be failed after CHIP_ERROR_FAIL_LIMIT recovery attempts */
#define CHIP_ERROR_FAIL_LIMIT 10
/* this value should be less than CHIP_ERROR_FAIL_LIMIT */
#define RENONCE_CHIP_ERROR_FAIL_LIMIT 8
#define CHIP_ERROR_LIMIT 5
#define CHIP_TASK_STATUS_INTERVAL 7000
#define CHIP_TASK_SWITCH_INTERVAL 5000000
#define CHIP_RESTART_LIMIT 120
/* alarm intervals */
#define LED_GREEN_INTERVAL 1000000
#define LED_RED_INTERVAL 1000000
#define LED_RED_NET_INTERVAL 500000
#define BUZZER_INTERVAL 1000000
/* threads delay */
#define CHIPWORKER_DELAY 1000000
#define NONCEWORKER_DELAY 30000
#define RENONCEWORKER_DELAY 30000
#define HWMONITOR_DELAY 1000000
#define STATISTICS_DELAY 400000
#define ALARM_DELAY 500000
/* hold 3 works for each chip */
#define WORK_QUEUE_LEN 3 * CHIPS_NUM
/* set clock to all chips and exit */
bool opt_bf16_set_clock = false;
/* enable board mining statistics output */
bool opt_bf16_stats_enabled = false;
/* disable automatic power management */
bool opt_bf16_power_management_disabled = false;
/* renonce configuration */
int opt_bf16_renonce = RENONCE_ONE_CHIP;
/* chip clock value */
char* opt_bf16_clock = NULL;
uint8_t bf16_chip_clock = 0x32;
/* renonce chip clock value */
char* opt_bf16_renonce_clock = NULL;
uint8_t bf16_renonce_chip_clock = 0x2d;
/* fan speed */
int opt_bf16_fan_speed = -1;
/* target temp */
int opt_bf16_target_temp = -1;
/* alarm temp */
int opt_bf16_alarm_temp = -1;
/* test chip communication */
char* opt_bf16_test_chip = NULL;
/* number of bits to fixate */
static uint32_t mask_bits = 10;
/* default chip mask */
static uint32_t mask = 0x00000000;
/* initial pid state */
static bf_pid_t pid = {
.i_state = 0,
.i_max = 300,
.i_min = -10,
};
#ifdef MINER_X5
bool opt_bf16_manual_pid_enabled = false;
bool manual_pid_enabled = false;
static bf_bcm250_map_t bcm250_map[CHIPBOARD_NUM][BCM250_NUM] = {
{
{
.channel_path = { BF250_LOCAL, BF250_NONE },
.first_good_chip = 0,
.last_good_chip = BF16_NUM,
.chips_num = BF16_NUM
},
{
.channel_path = { BF250_CHAN1, BF250_LOCAL },
.first_good_chip = 7,
.last_good_chip = BF16_NUM,
.chips_num = 4
},
{
.channel_path = { BF250_CHAN2, BF250_LOCAL },
.first_good_chip = 0,
.last_good_chip = BF16_NUM,
.chips_num = BF16_NUM
}
},
{
{
.channel_path = { BF250_LOCAL, BF250_NONE },
.first_good_chip = 0,
.last_good_chip = BF16_NUM,
.chips_num = BF16_NUM
},
{
.channel_path = { BF250_CHAN1, BF250_LOCAL },
.first_good_chip = 7,
.last_good_chip = BF16_NUM,
.chips_num = 4
},
{
.channel_path = { BF250_CHAN2, BF250_LOCAL },
.first_good_chip = 0,
.last_good_chip = BF16_NUM,
.chips_num = BF16_NUM
}
}
};
#endif
#ifdef MINER_X6
bool opt_bf16_manual_pid_disabled = false;
bool manual_pid_enabled = false;
static bf_bcm250_map_t bcm250_map[CHIPBOARD_NUM][BCM250_NUM] = {
{
{
.channel_path = { BF250_LOCAL, BF250_NONE, BF250_NONE, BF250_NONE },
.first_good_chip = 0,
.last_good_chip = BF16_NUM,
.chips_num = BF16_NUM
},
{
.channel_path = { BF250_CHAN1, BF250_LOCAL, BF250_NONE, BF250_NONE },
.first_good_chip = 0,
.last_good_chip = BF16_NUM,
.chips_num = BF16_NUM
},
{
.channel_path = { BF250_CHAN2, BF250_LOCAL, BF250_NONE, BF250_NONE },
.first_good_chip = 0,
.last_good_chip = 4,
.chips_num = 4
},
{
.channel_path = { BF250_CHAN2, BF250_CHAN2, BF250_LOCAL, BF250_NONE },
.first_good_chip = 0,
.last_good_chip = BF16_NUM,
.chips_num = BF16_NUM
},
{
.channel_path = { BF250_CHAN2, BF250_CHAN2, BF250_CHAN1, BF250_LOCAL },
.first_good_chip = 0,
.last_good_chip = BF16_NUM,
.chips_num = BF16_NUM
},
{
.channel_path = { BF250_CHAN2, BF250_CHAN2, BF250_CHAN2, BF250_LOCAL },
.first_good_chip = 0,
.last_good_chip = 4,
.chips_num = 4
}
},
{
{
.channel_path = { BF250_LOCAL, BF250_NONE, BF250_NONE, BF250_NONE },
.first_good_chip = 0,
.last_good_chip = BF16_NUM,
.chips_num = BF16_NUM
},
{
.channel_path = { BF250_CHAN1, BF250_LOCAL, BF250_NONE, BF250_NONE },
.first_good_chip = 0,
.last_good_chip = BF16_NUM,
.chips_num = BF16_NUM
},
{
.channel_path = { BF250_CHAN2, BF250_LOCAL, BF250_NONE, BF250_NONE },
.first_good_chip = 0,
.last_good_chip = 4,
.chips_num = 4
},
{
.channel_path = { BF250_CHAN2, BF250_CHAN2, BF250_LOCAL, BF250_NONE },
.first_good_chip = 0,
.last_good_chip = BF16_NUM,
.chips_num = BF16_NUM
},
{
.channel_path = { BF250_CHAN2, BF250_CHAN2, BF250_CHAN1, BF250_LOCAL },
.first_good_chip = 0,
.last_good_chip = BF16_NUM,
.chips_num = BF16_NUM
},
{
.channel_path = { BF250_CHAN2, BF250_CHAN2, BF250_CHAN2, BF250_LOCAL },
.first_good_chip = 0,
.last_good_chip = 4,
.chips_num = 4
}
}
};
#endif
/* each array element contains chip address assosiated to corresponting chipboard *
* e.g. first array element - renonce chip address for the first chipboard and so *
* on */
static bf_chip_address_t renonce_chip_address[CHIPBOARD_NUM] = {
{
.board_id = 0,
.bcm250_id = 0,
.chip_id = 0
},
{
.board_id = 1,
.bcm250_id = 0,
.chip_id = 0
}
};
#ifdef FILELOG
static int filelog(struct bitfury16_info *info, const char* format, ...)
{
char fmt[1024];
char datetime[64];
struct timeval tv = {0, 0};
struct tm *tm;
if (info->logfile == NULL)
return -1;
gettimeofday(&tv, NULL);
const time_t tmp_time = tv.tv_sec;
int ms = (int)(tv.tv_usec / 1000);
tm = localtime(&tmp_time);
snprintf(datetime, sizeof(datetime), " [%d-%02d-%02d %02d:%02d:%02d.%03d] ",
tm->tm_year + 1900,
tm->tm_mon + 1,
tm->tm_mday,
tm->tm_hour,
tm->tm_min,
tm->tm_sec, ms);
memset(fmt, 0, sizeof(fmt));
sprintf(fmt, "%s%s\n", datetime, format);
va_list args;
va_start(args, format);
mutex_lock(&info->logfile_mutex);
vfprintf(info->logfile, fmt, args);
fflush(info->logfile);
mutex_unlock(&info->logfile_mutex);
va_end(args);
return 0;
}
#endif
static double timediff(struct timeval time1, struct timeval time2)
{
double time1_val = 1000000 * time1.tv_sec + time1.tv_usec;
double time2_val = 1000000 * time2.tv_sec + time2.tv_usec;
return (double)(time2_val - time1_val) / 1000000.0;
}
static uint32_t timediff_us(struct timeval time1, struct timeval time2)
{
uint32_t time1_val = 1000000 * time1.tv_sec + time1.tv_usec;
uint32_t time2_val = 1000000 * time2.tv_sec + time2.tv_usec;
return (time2_val - time1_val);
}
static void get_average(float* average, float delta, float time_diff, float interval)
{
float ftotal, fprop;
fprop = 1.0 - 1 / (exp((float)time_diff/(float)interval));
ftotal = 1.0 + fprop;
*average += (delta / time_diff * fprop);
*average /= ftotal;
}
static uint8_t renonce_chip(bf_chip_address_t chip_address)
{
uint8_t board_id = chip_address.board_id;
if ((renonce_chip_address[board_id].bcm250_id == chip_address.bcm250_id) &&
(renonce_chip_address[board_id].chip_id == chip_address.chip_id))
return 1;
return 0;
}
static void get_next_chip_address(struct bitfury16_info *info, bf_chip_address_t* chip_address)
{
uint8_t board_id = chip_address->board_id;
uint8_t bcm250_id = chip_address->bcm250_id;
uint8_t chip_id = chip_address->chip_id;
uint8_t last_good_chip = info->chipboard[board_id].bcm250[bcm250_id].last_good_chip - 1;
if (last_good_chip == chip_id) {
#ifdef MINER_X5
bcm250_id = (bcm250_id + 1) % BCM250_NUM;
chip_id = info->chipboard[board_id].bcm250[bcm250_id].first_good_chip;
#endif
#ifdef MINER_X6
if (opt_bf16_power_management_disabled == false) {
bcm250_id = (bcm250_id + 1) % BCM250_NUM;
/* do not set bcm250_id to disabled chain */
/* second power chain disabled */
if ((info->chipboard[board_id].p_chain2_enabled == 0) &&
(info->chipboard[board_id].power2_disabled == true) &&
(bcm250_id >= BCM250_NUM / 2) && (bcm250_id < BCM250_NUM)) {
bcm250_id = 0;
}
chip_id = info->chipboard[board_id].bcm250[bcm250_id].first_good_chip;
} else {
chip_id = info->chipboard[board_id].bcm250[bcm250_id].first_good_chip;
}
#endif
} else
chip_id++;
chip_address->bcm250_id = bcm250_id;
chip_address->chip_id = chip_id;
}
static int8_t change_renonce_chip_address(struct cgpu_info *bitfury, bf_chip_address_t chip_address)
{
struct bitfury16_info *info = (struct bitfury16_info *)(bitfury->device_data);
uint8_t board_id = chip_address.board_id;
uint8_t bcm250_id = chip_address.bcm250_id;
uint8_t chip_id = chip_address.chip_id;
bf_chip_address_t new_chip_address = { board_id, bcm250_id, chip_id };
bool found = false;
uint8_t chip_count = 0;
while (true) {
get_next_chip_address(info, &new_chip_address);
chip_count++;
uint8_t new_board_id = new_chip_address.board_id;
uint8_t new_bcm250_id = new_chip_address.bcm250_id;
uint8_t new_chip_id = new_chip_address.chip_id;
/* enabled chip found */
if (info->chipboard[new_board_id].bcm250[new_bcm250_id].chips[new_chip_id].status != DISABLED) {
found = true;
break;
}
/* we have run full loop chipboard */
#ifdef MINER_X5
if (chip_count == info->chipboard[board_id].chips_num)
break;
#endif
#ifdef MINER_X6
if (opt_bf16_power_management_disabled == false) {
if ((info->chipboard[board_id].p_chain2_enabled == 0) &&
(info->chipboard[board_id].power2_disabled == true)) {
if (chip_count == info->chipboard[board_id].chips_num / 2)
break;
} else {
if (chip_count == info->chipboard[board_id].chips_num)
break;
}
} else {
if (chip_count == info->chipboard[board_id].chips_num)
break;
}
#endif
}
if ((found == true) &&
(memcmp(&new_chip_address, &renonce_chip_address[board_id], sizeof(bf_chip_address_t)) != 0)) {
board_id = new_chip_address.board_id;
bcm250_id = new_chip_address.bcm250_id;
chip_id = new_chip_address.chip_id;
renonce_chip_address[board_id].bcm250_id = bcm250_id;
renonce_chip_address[board_id].chip_id = chip_id;
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status = UNINITIALIZED;
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].last_nonce_time = time(NULL);
gettimeofday(&info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status_time, NULL);
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].recovery_count = 0;
applog(LOG_NOTICE, "%s: changed renonce chip address to: [%d:%d:%2d]",
bitfury->drv->name,
board_id, bcm250_id, chip_id);
#ifdef FILELOG
filelog(info, "%s: changed renonce chip address to: [%d:%d:%2d]",
bitfury->drv->name,
board_id, bcm250_id, chip_id);
#endif
return 0;
} else {
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status = DISABLED;
applog(LOG_NOTICE, "%s: failed to find working renonce chip. disabling...",
bitfury->drv->name);
#ifdef FILELOG
filelog(info, "%s: failed to find working renonce chip. disabling...",
bitfury->drv->name);
#endif
return -1;
}
}
static void increase_good_nonces(struct bitfury16_info *info, bf_chip_address_t chip_address)
{
uint8_t board_id = chip_address.board_id;
uint8_t bcm250_id = chip_address.bcm250_id;
uint8_t chip_id = chip_address.chip_id;
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].nonces_good_dx++;
info->chipboard[board_id].bcm250[bcm250_id].nonces_good_dx++;
info->chipboard[board_id].nonces_good_dx++;
info->nonces_good_dx++;
}
static void increase_bad_nonces(struct bitfury16_info *info, bf_chip_address_t chip_address)
{
uint8_t board_id = chip_address.board_id;
uint8_t bcm250_id = chip_address.bcm250_id;
uint8_t chip_id = chip_address.chip_id;
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].nonces_bad_dx++;
info->chipboard[board_id].bcm250[bcm250_id].nonces_bad_dx++;
info->chipboard[board_id].nonces_bad_dx++;
info->nonces_bad_dx++;
}
static void increase_re_nonces(struct bitfury16_info *info, bf_chip_address_t chip_address)
{
uint8_t board_id = chip_address.board_id;
uint8_t bcm250_id = chip_address.bcm250_id;
uint8_t chip_id = chip_address.chip_id;
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].nonces_re_dx++;
info->chipboard[board_id].bcm250[bcm250_id].nonces_re_dx++;
info->chipboard[board_id].nonces_re_dx++;
info->nonces_re_dx++;
}
static void increase_re_good_nonces(struct bitfury16_info *info, bf_chip_address_t chip_address)
{
uint8_t board_id = chip_address.board_id;
uint8_t bcm250_id = chip_address.bcm250_id;
uint8_t chip_id = chip_address.chip_id;
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].nonces_re_good_dx++;
if (renonce_chip(chip_address) == 0) {
info->chipboard[board_id].bcm250[bcm250_id].nonces_re_good_dx++;
info->chipboard[board_id].nonces_re_good_dx++;
info->nonces_re_good_dx++;
}
}
static void increase_re_bad_nonces(struct bitfury16_info *info, bf_chip_address_t chip_address)
{
uint8_t board_id = chip_address.board_id;
uint8_t bcm250_id = chip_address.bcm250_id;
uint8_t chip_id = chip_address.chip_id;
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].nonces_re_bad_dx++;
if (renonce_chip(chip_address) == 0) {
info->chipboard[board_id].bcm250[bcm250_id].nonces_re_bad_dx++;
info->chipboard[board_id].nonces_re_bad_dx++;
info->nonces_re_bad_dx++;
}
}
static void increase_total_nonces(struct bitfury16_info *info, bf_chip_address_t chip_address)
{
uint8_t board_id = chip_address.board_id;
uint8_t bcm250_id = chip_address.bcm250_id;
uint8_t chip_id = chip_address.chip_id;
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].nonces_dx++;
if ((renonce_chip(chip_address) == 0) ||
(opt_bf16_renonce == RENONCE_DISABLED)) {
info->chipboard[board_id].bcm250[bcm250_id].nonces_dx++;
info->chipboard[board_id].nonces_dx++;
info->nonces_dx++;
}
}
static void increase_task_switch(struct bitfury16_info *info, bf_chip_address_t chip_address)
{
uint8_t board_id = chip_address.board_id;
uint8_t bcm250_id = chip_address.bcm250_id;
uint8_t chip_id = chip_address.chip_id;
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].task_switch_dx++;
info->chipboard[board_id].bcm250[bcm250_id].task_switch_dx++;
info->chipboard[board_id].task_switch_dx++;
info->task_switch_dx++;
}
static void increase_errors(struct bitfury16_info *info, bf_chip_address_t chip_address)
{
uint8_t board_id = chip_address.board_id;
uint8_t bcm250_id = chip_address.bcm250_id;
uint8_t chip_id = chip_address.chip_id;
/* update timing interval */
time_t curr_time = time(NULL);
if (curr_time - info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].last_error_time <= 1)
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].error_rate++;
else
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].error_rate = 0;
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].last_error_time = curr_time;
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].errors++;
if ((renonce_chip(chip_address) == 0) ||
(opt_bf16_renonce == RENONCE_DISABLED))
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status = UNINITIALIZED;
/* mark chip as FAILING if error rate too high*/
if (info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].error_rate >= CHIP_ERROR_LIMIT) {
#ifdef FILELOG
filelog(info, "BF16: chip [%d:%d:%2d] error rate too high: [%d], "
"marked as failing, recovery_count: [%d]",
board_id, bcm250_id, chip_id,
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].error_rate,
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].recovery_count);
#endif
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status = FAILING;
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].error_rate = 0;
}
}
static uint8_t* init_channel_path(uint8_t board_id, uint8_t btc250_num, uint8_t* channel_depth, uint8_t channel_length)
{
uint8_t i, j;
uint8_t* channel_path = cgcalloc(channel_length, sizeof(uint8_t));
for (i = 0, j = 0; i < CHANNEL_DEPTH; i++) {
if (bcm250_map[board_id][btc250_num].channel_path[i] != BF250_NONE)
(*channel_depth)++;
int8_t shift = 8*(j + 1) - 3*(i + 1);
if (shift < 0) {
channel_path[j] |= bcm250_map[board_id][btc250_num].channel_path[i] >> abs(shift);
channel_path[j + 1] |= bcm250_map[board_id][btc250_num].channel_path[i] << (8 - abs(shift));
j++;
} else
channel_path[j] |= bcm250_map[board_id][btc250_num].channel_path[i] << shift;
}
return channel_path;
}
static int8_t parse_chip_address(struct cgpu_info *bitfury, char* address, bf_chip_address_t* chip_address)
{
struct bitfury16_info *info = (struct bitfury16_info *)(bitfury->device_data);
int8_t board_id = 0;
int8_t bcm250_id = 0;
int8_t chip_id = 0;
char buff[16];
if (address == NULL)
return -1;
/* board_id */
char* start = strchr(address, '[');
char* end = strchr(address, ':');
if ((start == NULL) || (end == NULL))
return -1;
uint8_t len = end - start;
memset(buff, 0, sizeof(buff));
cg_memcpy(buff, start + 1, len);
board_id = atoi(buff);
/* bcm250_id */
start = end;
end = strchr(start + 1, ':');
if (end == NULL)
return -1;
len = end - start;
memset(buff, 0, sizeof(buff));
cg_memcpy(buff, start + 1, len);
bcm250_id = atoi(buff);
/* chip_id */
start = end;
end = strchr(start + 1, ']');
if (end == NULL)
return -1;
len = end - start;
memset(buff, 0, sizeof(buff));
cg_memcpy(buff, start + 1, len);
chip_id = atoi(buff);
if ((board_id < 0) || (board_id >= CHIPBOARD_NUM)) {
applog(LOG_ERR, "%s: invalid board_id %d: [0 - %d] specified",
bitfury->drv->name,
board_id, CHIPBOARD_NUM);
return -1;
}
if ((bcm250_id < 0) || (bcm250_id >= BCM250_NUM)) {
applog(LOG_ERR, "%s: invalid bcm250_id %d: [0 - %d] specified",
bitfury->drv->name,
bcm250_id, BCM250_NUM);
return -1;
}
uint8_t first_good_chip = info->chipboard[board_id].bcm250[bcm250_id].first_good_chip;
uint8_t last_good_chip = info->chipboard[board_id].bcm250[bcm250_id].last_good_chip;
if ((chip_id >= first_good_chip) && (chip_id < last_good_chip)) {
chip_address->board_id = board_id;
chip_address->bcm250_id = bcm250_id;
chip_address->chip_id = chip_id;
} else {
applog(LOG_ERR, "%s: invalid chip_id %d: [%d - %d] specified",
bitfury->drv->name,
chip_id, first_good_chip, last_good_chip);
return -1;
}
applog(LOG_NOTICE, "%s: parsed chip address: [%d:%d:%2d]",
bitfury->drv->name,
chip_address->board_id,
chip_address->bcm250_id,
chip_address->chip_id);
return 0;
}
static void update_bcm250_map(struct cgpu_info *bitfury, uint8_t board_id)
{
struct bitfury16_info *info = (struct bitfury16_info *)(bitfury->device_data);
#ifdef MINER_X5
info->chipboard[board_id].board_type = CHIPBOARD_X5;
switch (info->chipboard[board_id].board_ver) {
/* 23 chip board version */
case 5:
info->chipboard[board_id].board_rev = CHIPBOARD_REV2;
bcm250_map[board_id][0].last_good_chip = BF16_NUM - 2;
bcm250_map[board_id][0].chips_num = BF16_NUM - 2;
bcm250_map[board_id][1].first_good_chip = 6;
bcm250_map[board_id][1].chips_num = 5;
bcm250_map[board_id][2].last_good_chip = BF16_NUM - 2;
bcm250_map[board_id][2].chips_num = BF16_NUM - 2;
break;
/* 24 chip board version */
case 7:
info->chipboard[board_id].board_rev = CHIPBOARD_REV2;
bcm250_map[board_id][0].last_good_chip = BF16_NUM - 2;
bcm250_map[board_id][0].chips_num = BF16_NUM - 2;
bcm250_map[board_id][1].first_good_chip = 6;
bcm250_map[board_id][1].chips_num = 5;
bcm250_map[board_id][2].last_good_chip = BF16_NUM - 1;
bcm250_map[board_id][2].chips_num = BF16_NUM - 1;
break;
/* 25 chip board version */
case 9:
info->chipboard[board_id].board_rev = CHIPBOARD_REV2;
bcm250_map[board_id][0].last_good_chip = BF16_NUM - 1;
bcm250_map[board_id][0].chips_num = BF16_NUM - 1;
bcm250_map[board_id][1].first_good_chip = 6;
bcm250_map[board_id][1].chips_num = 5;
bcm250_map[board_id][2].last_good_chip = BF16_NUM - 1;
bcm250_map[board_id][2].chips_num = BF16_NUM - 1;
break;
/* 26 chip board version */
case 11:
info->chipboard[board_id].board_rev = CHIPBOARD_REV2;
bcm250_map[board_id][0].last_good_chip = BF16_NUM - 1;
bcm250_map[board_id][0].chips_num = BF16_NUM - 1;
bcm250_map[board_id][1].first_good_chip = 6;
bcm250_map[board_id][1].chips_num = 5;
break;
/* 27 chip board version */
case 13:
info->chipboard[board_id].board_rev = CHIPBOARD_REV2;
bcm250_map[board_id][1].first_good_chip = 6;
bcm250_map[board_id][1].chips_num = 5;
break;
/* 26 chip board version - default */
case 1:
case 2:
info->chipboard[board_id].board_rev = CHIPBOARD_REV1;
default:
break;
}
#endif
#ifdef MINER_X6
info->chipboard[board_id].board_type = CHIPBOARD_X6;
switch (info->chipboard[board_id].board_ver) {
/* 46 chip board version */
case 4:
info->chipboard[board_id].board_rev = CHIPBOARD_REV2;
bcm250_map[board_id][0].last_good_chip = BF16_NUM - 2;
bcm250_map[board_id][0].chips_num = BF16_NUM - 2;
bcm250_map[board_id][1].first_good_chip = 1;
bcm250_map[board_id][1].last_good_chip = BF16_NUM - 1;
bcm250_map[board_id][1].chips_num = BF16_NUM - 2;
bcm250_map[board_id][2].last_good_chip = 5;
bcm250_map[board_id][2].chips_num = 5;
bcm250_map[board_id][3].last_good_chip = BF16_NUM - 2;
bcm250_map[board_id][3].chips_num = BF16_NUM - 2;
bcm250_map[board_id][4].first_good_chip = 1;
bcm250_map[board_id][4].last_good_chip = BF16_NUM - 1;
bcm250_map[board_id][4].chips_num = BF16_NUM - 1;
bcm250_map[board_id][5].last_good_chip = 5;
bcm250_map[board_id][5].chips_num = 5;
break;
/* 48 chip board version */
case 6:
info->chipboard[board_id].board_rev = CHIPBOARD_REV2;
bcm250_map[board_id][0].last_good_chip = BF16_NUM - 1;
bcm250_map[board_id][0].chips_num = BF16_NUM - 1;
bcm250_map[board_id][1].first_good_chip = 1;
bcm250_map[board_id][1].last_good_chip = BF16_NUM - 1;
bcm250_map[board_id][1].chips_num = BF16_NUM - 2;
bcm250_map[board_id][2].last_good_chip = 5;
bcm250_map[board_id][2].chips_num = 5;
bcm250_map[board_id][3].last_good_chip = BF16_NUM - 1;
bcm250_map[board_id][3].chips_num = BF16_NUM - 1;
bcm250_map[board_id][4].first_good_chip = 1;
bcm250_map[board_id][4].last_good_chip = BF16_NUM - 1;
bcm250_map[board_id][4].chips_num = BF16_NUM - 1;
bcm250_map[board_id][5].last_good_chip = 5;
bcm250_map[board_id][5].chips_num = 5;
break;
/* 50 chip board version */
case 8:
info->chipboard[board_id].board_rev = CHIPBOARD_REV2;
bcm250_map[board_id][0].last_good_chip = BF16_NUM - 1;
bcm250_map[board_id][0].chips_num = BF16_NUM - 1;
bcm250_map[board_id][1].last_good_chip = BF16_NUM - 1;
bcm250_map[board_id][1].chips_num = BF16_NUM - 1;
bcm250_map[board_id][2].last_good_chip = 5;
bcm250_map[board_id][2].chips_num = 5;
bcm250_map[board_id][3].last_good_chip = BF16_NUM - 1;
bcm250_map[board_id][3].chips_num = BF16_NUM - 1;
bcm250_map[board_id][4].last_good_chip = BF16_NUM - 1;
bcm250_map[board_id][4].chips_num = BF16_NUM - 1;
bcm250_map[board_id][5].last_good_chip = 5;
bcm250_map[board_id][5].chips_num = 5;
break;
/* 52 chip board version */
case 10:
info->chipboard[board_id].board_rev = CHIPBOARD_REV2;
bcm250_map[board_id][1].last_good_chip = BF16_NUM - 1;
bcm250_map[board_id][1].chips_num = BF16_NUM - 1;
bcm250_map[board_id][2].last_good_chip = 5;
bcm250_map[board_id][2].chips_num = 5;
bcm250_map[board_id][4].last_good_chip = BF16_NUM - 1;
bcm250_map[board_id][4].chips_num = BF16_NUM - 1;
bcm250_map[board_id][5].last_good_chip = 5;
bcm250_map[board_id][5].chips_num = 5;
break;
/* 54 chip board version */
case 12:
info->chipboard[board_id].board_rev = CHIPBOARD_REV2;
bcm250_map[board_id][2].last_good_chip = 5;
bcm250_map[board_id][2].chips_num = 5;
bcm250_map[board_id][5].last_good_chip = 5;
bcm250_map[board_id][5].chips_num = 5;
break;
/* 46 chip board version */
case 14:;
info->chipboard[board_id].board_rev = CHIPBOARD_REV3;
uint8_t bcm250_channel_path[3][CHANNEL_DEPTH] = {
{ BF250_CHAN1, BF250_CHAN1, BF250_LOCAL, BF250_NONE },
{ BF250_CHAN1, BF250_CHAN1, BF250_CHAN1, BF250_LOCAL },
{ BF250_CHAN1, BF250_CHAN1, BF250_CHAN2, BF250_LOCAL },
};
bcm250_map[board_id][0].first_good_chip = 0;
bcm250_map[board_id][0].last_good_chip = 1;
bcm250_map[board_id][0].chips_num = 1;
bcm250_map[board_id][2].first_good_chip = 0;
bcm250_map[board_id][2].last_good_chip = BF16_NUM;
bcm250_map[board_id][2].chips_num = BF16_NUM;
bcm250_map[board_id][3].first_good_chip = 0;
bcm250_map[board_id][3].last_good_chip = 1;
bcm250_map[board_id][3].chips_num = 1;
cg_memcpy(bcm250_map[board_id][3].channel_path, bcm250_channel_path[0], sizeof(bcm250_map[board_id][3].channel_path));
cg_memcpy(bcm250_map[board_id][4].channel_path, bcm250_channel_path[1], sizeof(bcm250_map[board_id][4].channel_path));
bcm250_map[board_id][5].first_good_chip = 0;
bcm250_map[board_id][5].last_good_chip = BF16_NUM;
bcm250_map[board_id][5].chips_num = BF16_NUM;
cg_memcpy(bcm250_map[board_id][5].channel_path, bcm250_channel_path[2], sizeof(bcm250_map[board_id][5].channel_path));
break;
/* 52 chip board version - default */
case 3:
info->chipboard[board_id].board_rev = CHIPBOARD_REV1;
default:
break;
}
#endif
}
static void reinit_x5(struct bitfury16_info *info, bool chip_reinit)
{
uint8_t board_id, bcm250_id, chip_id;
/* reinit board chips */
for (board_id = 0; board_id < CHIPBOARD_NUM; board_id++) {
for (bcm250_id = 0; bcm250_id < BCM250_NUM; bcm250_id++) {
uint8_t first_good_chip = info->chipboard[board_id].bcm250[bcm250_id].first_good_chip;
uint8_t last_good_chip = info->chipboard[board_id].bcm250[bcm250_id].last_good_chip;
for (chip_id = first_good_chip; chip_id < last_good_chip; chip_id++) {
if (chip_reinit == true) {
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].recovery_count = 0;
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].error_rate = 0;
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status = UNINITIALIZED;
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].last_nonce_time = time(NULL);
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].last_error_time = time(NULL);
gettimeofday(&info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status_time, NULL);
gettimeofday(&info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].switch_time, NULL);
} else {
if (info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].recovery_count < CHIP_ERROR_FAIL_LIMIT)
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status = UNINITIALIZED;
}
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].last_nonce_time = time(NULL);
gettimeofday(&info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status_time, NULL);
gettimeofday(&info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].switch_time, NULL);
}
}
}
/* send reset to all boards */
spi_emit_reset(SPI_CHANNEL1);
spi_emit_reset(SPI_CHANNEL2);
}
static void init_x5(struct cgpu_info *bitfury)
{
uint8_t board_id, bcm250_id, chip_id;
struct bitfury16_info *info = (struct bitfury16_info *)(bitfury->device_data);
info->chipboard = cgcalloc(CHIPBOARD_NUM, sizeof(bf_chipboard_t));
/* channel size in bytes */
info->channel_length = (CHANNEL_DEPTH * 3) / 8 + 1;
info->ialarm_count = 1;
info->work_list = workd_list_init();
info->stale_work_list = workd_list_init();
info->noncework_list = noncework_list_init();
if (opt_bf16_renonce != RENONCE_DISABLED) {
info->renoncework_list = renoncework_list_init();
info->renonce_id = 1;
info->renonce_list = renonce_list_init();
}
for (board_id = 0; board_id < CHIPBOARD_NUM; board_id++) {
/* detect board */
char buff[256];
memset(buff, 0, sizeof(buff));
device_ctrl_txrx(board_id + 1, 0, F_BDET, buff);
parse_board_detect(bitfury, board_id, buff);