-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathmain.c
More file actions
11648 lines (9833 loc) · 330 KB
/
main.c
File metadata and controls
11648 lines (9833 loc) · 330 KB
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
/*
* Copyright 2016-2017 Fazio Bai <yang.bai@bitmain.com>
* Copyright 2016-2017 Clement Duan <kai.duan@bitmain.com>
*
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/time.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/inotify.h>
#include <fcntl.h>
#include <pthread.h>
#include <sys/mman.h>
#include <time.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <errno.h>
#include <arpa/inet.h>
#include <net/if.h>
#include <sys/ioctl.h>
#include <signal.h>
#include <sys/sysinfo.h>
#include <openssl/hmac.h>
#include <openssl/aes.h>
#include <openssl/sha.h>
#include <openssl/evp.h>
#include <openssl/bn.h>
#include <openssl/ecdsa.h>
#include <openssl/obj_mac.h>
#include <openssl/rand.h>
#include <openssl/bn.h>
#include <curl/curl.h>
#include "driver-bitmain.h"
#define RUNNING true
#define STOPED false
pthread_mutex_t stats_lock;
#define START_KEY_DEV "/sys/class/gpio/gpio235/value"
#define RED_LED_DEV "/sys/class/leds/hps_led2/brightness"
#define GREEN_LED_DEV "/sys/class/leds/hps_led0/brightness"
#define CHECK_CHAIN
#define Sliding_rheostat_50k
#ifdef Sliding_rheostat_50k
unsigned int pic_voltage1 = 27; // 10V
unsigned int pic_voltage2 = 21; // 10.25V
unsigned int pic_voltage3 = 16; // 10.50V
#endif
#ifdef Sliding_rheostat_100k
unsigned int pic_voltage1 = 13; // 10V
unsigned int pic_voltage2 = 11; // 10.25V
unsigned int pic_voltage3 = 8; // 10.50V
#endif
#ifdef R4
int R4_MAX_VOLTAGE;
int START_VOLTAGE;
int RETRY_VOLTAGE;
int HIGHEST_FREQ_INDEX;
#endif
int fpga_version; // very important for T9+
int temp_chip_index[BITMAIN_MAX_CHAIN_NUM]={0};
int searchStatus;
bool isChipNumOK_Once=false;
bool isFailedOnTestPatten=false;
bool IsSomeBoardHasNoFreq=false;
char search_failed_info[64];
void saveSearchFailedFlagInfo();
unsigned char chain_pic_buf[BITMAIN_MAX_CHAIN_NUM][128];
bool StartSendFlag[BITMAIN_MAX_CHAIN_NUM];
int chain_DataCount[BITMAIN_MAX_CHAIN_NUM];
int chain_ValidNonce[BITMAIN_MAX_CHAIN_NUM];
int chain_PassCount[BITMAIN_MAX_CHAIN_NUM];
int chain_vol_value[BITMAIN_MAX_CHAIN_NUM]; // the searching vol
int chain_vol_added[BITMAIN_MAX_CHAIN_NUM]; // how many vol added , recorded in PIC
int last_opencore_result[BITMAIN_MAX_CHAIN_NUM][256];
int last_result[BITMAIN_MAX_CHAIN_NUM][256];
int last_freq[BITMAIN_MAX_CHAIN_NUM][256];
int last_success_freq[BITMAIN_MAX_CHAIN_NUM][256]; // success freq recores and will not clear them
bool isNoBoardError=false;
bool search_over[BITMAIN_MAX_CHAIN_NUM];
bool testDone[BITMAIN_MAX_CHAIN_NUM];
unsigned char vol_oldvalue[BITMAIN_MAX_CHAIN_NUM];
signed char board_temp[BITMAIN_MAX_CHAIN_NUM]={0};
int TEST_MODE_OK_NUM=0;
char voltage_char[30] = {0};
char lcd_buffer[16] = {' ','P','i','c',' ','V','o','l',':',' ',' ',' ',' ',' ',' ',' '};
unsigned char time_data[6]= {'H','H','H','H','H','H'};
bool first_freq = true;
int result = 0;
bool search_freq_result[BITMAIN_MAX_CHAIN_NUM]; // set true as default
int search_freq_chances[BITMAIN_MAX_CHAIN_NUM]; // give each board SEARCH_FREQ_CHANCE_NUM chances to search freq.
struct cgpu_info cgpu;
volatile bool gBegin_get_nonce = false;
extern pthread_mutex_t reg_mutex;
pthread_mutex_t iic_mutex = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t log_mutex = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t fpga_mutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_mutex_t temp_work_mutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_mutex_t read_temp_mutex = PTHREAD_MUTEX_INITIALIZER;
extern unsigned int *nonce2_jobid_address; // the value should be filled in NONCE2_AND_JOBID_STORE_ADDRESS
unsigned int send_work_num[BITMAIN_MAX_CHAIN_NUM];
#ifndef T9_18
unsigned char pic_badcore_num[BITMAIN_MAX_CHAIN_NUM][64];
#endif
int temp_asic_core_enabled_flag[BITMAIN_MAX_CHAIN_NUM][256][256]; // only used to try fix enabled flag, temp value
int asic_core_enabled_flag[BITMAIN_MAX_CHAIN_NUM][256][256]; // [chainindex][chipindex][coreindex]=0 disabled, 1:enabled
int last_asic_core_enabled_flag[BITMAIN_MAX_CHAIN_NUM][256][256]; // last asic core flags
int chain_badcore_num[BITMAIN_MAX_CHAIN_NUM][256]; // only used in test mode , not in search mode, because after reboot, we only can get bad core num, but can not know which core is bad!!!
int asic_nonce_num[BITMAIN_MAX_CHAIN_NUM][256];
int asic_core_nonce_num[BITMAIN_MAX_CHAIN_NUM][256][256]; // 1st: which asic, 2nd: which core
int last_nonce_num[BITMAIN_MAX_CHAIN_NUM];
int repeated_nonce_num[BITMAIN_MAX_CHAIN_NUM];
uint32_t repeated_nonce_id[BITMAIN_MAX_CHAIN_NUM][256];
int valid_nonce_num[BITMAIN_MAX_CHAIN_NUM]; // all the received nonce in one test
int err_nonce_num[BITMAIN_MAX_CHAIN_NUM];
int total_valid_nonce_num=0;
volatile bool start_receive = false;
bool start_pic_heart=false;
#define NO_CHIP_DOWN_FREQ_MAX_COUNTER 2 // if there is no chip down freq , but test mode failed for 3 times, we need force to down freq on all chips!
int testModeChainHasNoChipDownFreqCounter[BITMAIN_MAX_CHAIN_NUM];
bool testModeHasTriedAcceptBadCore[BITMAIN_MAX_CHAIN_NUM][256];
int testModeOKCounter[BITMAIN_MAX_CHAIN_NUM];
struct configuration Conf; //store information that read from Config.ini
struct _CONFIG conf; //store the information that handled from Config.ini
extern unsigned int *axi_fpga_addr;
struct reg_buf *reg_value_buf = NULL;
unsigned int gtest = 0;
extern unsigned char hash_board_id[12];
extern unsigned int hash_board_id_recorder;
extern unsigned int CHIP_ADDRESS;
extern unsigned int GOLDEN_NONCE_COUNTER;
extern unsigned int PLL_PARAMETER;
extern unsigned int START_NONCE_OFFSET;
extern unsigned int HASH_COUNTING_NUMBER;
extern unsigned int TICKET_MASK;
extern unsigned int MISC_CONTROL;
extern unsigned int HASH_RATE;
extern unsigned int GENERAL_I2C_COMMAND;
extern unsigned int SECURITY_I2C_COMMAND;
extern unsigned int SIGNATURE_INPUT;
extern unsigned int SIGNATURE_NONCE;
extern unsigned int SIGNATURE_ID;
extern unsigned int SECURITY_CONTROL_AND_STATUS;
extern unsigned int JOB_INFORMATION;
bool gIsReadTemp = false;
bool gReadingTemp = false;
bool gStartTest = false;
bool ExitFlag=false;
bool showExit;
bool receiveExit;
bool picheartExit;
bool sendExit[BITMAIN_MAX_CHAIN_NUM];
signed char chip_temp_offset[BITMAIN_MAX_CHAIN_NUM]={0};
typedef enum{
SEARCH_BASE_FREQ_V89_200=0,
SEARCH_BASE_FREQ_V89_300,
SEARCH_BASE_FREQ_V89_400,
SEARCH_BASE_FREQ_V89_400_2, // speical for 8.9V 400M, only used in search mode 2, this state will not switch voltage, just up freq 100M step
SEARCH_BASE_FREQ_V89_500,
SEARCH_BASE_FREQ_V89_600,
SEARCH_BASE_FREQ_V89_650,
SEARCH_BASE_FREQ_V86_400,
SEARCH_BASE_FREQ_V86_500,
SEARCH_BASE_FREQ_V86_600,
SEARCH_BASE_FREQ_V86_650,
SEARCH_BASE_FREQ, // search one freq as start, if found , changed to ALLCHIP_FREQ_UP, if failed, down all chips freq one step and test
ALLCHIP_FREQ_UP, // All chips up one step freq, if pass then continue up, if failed then go to FAILED_CHIP_DOWN
FAILED_CHIP_DOWN, // failed chip down one step, successful chip keep no change. test OK, then
DOWN_CHIP_ONEBYONE, // need down chip in DC area one by one, to test OK
SUCCESS_CHIP_UP, // successful chip with Fmax+1 freq, keep go up one step
DOWN_VOLTAGE_TEST,
SEARCH_OVER,
}SEARCH_WORK_STATE;
int Fmax[BITMAIN_MAX_CHAIN_NUM];
int base_freq_index[BITMAIN_MAX_CHAIN_NUM]; // the start freq index of hashboard
int searchFreqMode[BITMAIN_MAX_CHAIN_NUM];
extern void set_PWM(unsigned char pwm_percent);
extern void writeLogFile(char *logstr);
extern void ClearForceFreq();
int GetTotalRate();
int ConvirtTotalRate(int totalRate);
int GetBoardRate(int chainIndex);
static int get_mac(char * device, unsigned char *mac);
int getVoltageLimitedFromHashrate(int hashrate_GHz)
{
int vol_value;
#ifdef R4
vol_value=R4_MAX_VOLTAGE;
#endif
#ifdef S9_PLUS
if(hashrate_GHz>=12500)
vol_value=840;
else if(hashrate_GHz>=12000)
vol_value=850;
else if(hashrate_GHz>=11500)
vol_value=870;
else if(hashrate_GHz>=11000)
vol_value=890;
else if(hashrate_GHz>=10500)
vol_value=910;
else if(hashrate_GHz>=10000)
vol_value=930;
else if(hashrate_GHz>=9500)
vol_value=960;
else if(hashrate_GHz>=9000)
vol_value=970;
else
vol_value=970;
#endif
#ifdef S9_63
if(hashrate_GHz>=14500)
vol_value=870;
else if(hashrate_GHz>=14000)
vol_value=880;
else if(hashrate_GHz>=13500)
vol_value=900;
else if(hashrate_GHz>=13000)
vol_value=910;
else if(hashrate_GHz>=12500)
vol_value=930;
else
vol_value=940;
#endif
#ifdef T9_18
if(hashrate_GHz>=12000)
vol_value=810;
else if(hashrate_GHz>=11500)
vol_value=830;
else if(hashrate_GHz>=11000)
vol_value=850;
else if(hashrate_GHz>=10500)
vol_value=870;
else if(hashrate_GHz>=10000)
vol_value=890;
else if(hashrate_GHz>=9500)
vol_value=920;
else if(hashrate_GHz>=9000)
vol_value=930;
else
vol_value=930;
#endif
return vol_value;
}
int getLimitedHashrateByVoltage(int vol_value) // hashrate must be less than this return value, can not equal!!!
{
#ifdef R4
return 14500;
#endif
#ifdef S9_PLUS
switch(vol_value)
{
case 970:
return 9500;
case 960:
case 950:
case 940:
return 10000;
case 930:
case 920:
return 10500;
case 910:
case 900:
return 11000;
case 890:
case 880:
return 11500;
case 870:
case 860:
return 12000;
case 850:
return 12500;
default:
return 13000;
}
#endif
#ifdef S9_63
switch(vol_value)
{
case 940:
return 12500;
case 930:
case 920:
return 13000;
case 910:
return 13500;
case 900:
case 890:
return 14000;
case 880:
return 14500;
case 870:
return 15000;
default:
return 15500;
}
#endif
#ifdef T9_18
switch(vol_value)
{
case 930:
return 9500;
case 920:
case 910:
case 900:
return 10000;
case 890:
case 880:
return 10500;
case 870:
case 860:
return 11000;
case 850:
case 840:
return 11500;
case 830:
case 820:
return 12000;
default:
return 12500;
}
#endif
}
int getNextSearchBaseFreq(int cur_freq)
{
if(cur_freq<0)
cur_freq=66; //600M
else if(cur_freq>=66)
cur_freq=58; //550M
else if(cur_freq>=58)
cur_freq=44; //500M
else if(cur_freq>=44)
cur_freq=28; //450M
else if(cur_freq>=28)
cur_freq=12; //400M
else cur_freq--;
return cur_freq;
}
#ifdef T9_18
void getPICChainIndexOffset(int chainIndex, int *pChain, int *pOffset)
{
int new_T9_PLUS_chainIndex,new_T9_PLUS_chainOffset;
switch(chainIndex)
{
case 1:
new_T9_PLUS_chainIndex=1;
new_T9_PLUS_chainOffset=0;
break;
case 8:
new_T9_PLUS_chainIndex=1;
new_T9_PLUS_chainOffset=1;
break;
case 9:
new_T9_PLUS_chainIndex=1;
new_T9_PLUS_chainOffset=2;
break;
case 2:
new_T9_PLUS_chainIndex=2;
new_T9_PLUS_chainOffset=0;
break;
case 10:
new_T9_PLUS_chainIndex=2;
new_T9_PLUS_chainOffset=1;
break;
case 11:
new_T9_PLUS_chainIndex=2;
new_T9_PLUS_chainOffset=2;
break;
case 3:
new_T9_PLUS_chainIndex=3;
new_T9_PLUS_chainOffset=0;
break;
case 12:
new_T9_PLUS_chainIndex=3;
new_T9_PLUS_chainOffset=1;
break;
case 13:
new_T9_PLUS_chainIndex=3;
new_T9_PLUS_chainOffset=2;
break;
default:
new_T9_PLUS_chainIndex=0;
new_T9_PLUS_chainOffset=0;
break;
}
*pChain=new_T9_PLUS_chainIndex;
*pOffset=new_T9_PLUS_chainOffset;
}
int getChainPICMagicNumber(int chainIndex)
{
if(fpga_version>=0xE)
{
int new_T9_PLUS_chainIndex,new_T9_PLUS_chainOffset;
getPICChainIndexOffset(chainIndex,&new_T9_PLUS_chainIndex,&new_T9_PLUS_chainOffset);
return chain_pic_buf[new_T9_PLUS_chainIndex][0];
}
else
{
return chain_pic_buf[((chainIndex/3)*3)][0];
}
}
int getOneChipFreqIndex(int chainIndex, int chipIndex)
{
if(fpga_version>=0xE)
{
int new_T9_PLUS_chainIndex,new_T9_PLUS_chainOffset;
getPICChainIndexOffset(chainIndex,&new_T9_PLUS_chainIndex,&new_T9_PLUS_chainOffset);
return chain_pic_buf[new_T9_PLUS_chainIndex][7+new_T9_PLUS_chainOffset*31+4+chipIndex];
}
else
{
return chain_pic_buf[((chainIndex/3)*3)][7+(chainIndex%3)*31+4+chipIndex];
}
}
void jump_to_app_CheckAndRestorePIC(int chainIndex)
{
unsigned char pic_version;
char logstr[256];
int try_count=0;
if(fpga_version>=0xE)
{
if(chainIndex<1 || chainIndex>3)
return;
sprintf(logstr,"chain[%d] PIC jump to app\n",chainIndex);
writeLogFile(logstr);
dsPIC33EP16GS202_jump_to_app_from_loader(chainIndex);
get_pic_software_version(chainIndex,&pic_version);
sprintf(logstr,"Check chain[%d] PIC fw version=0x%02x\n",chainIndex,pic_version);
writeLogFile(logstr);
#ifdef ENABLE_RESTORE_PIC_APP
#ifndef DEBUG_PIC_UPGRADE
while(pic_version!=PIC_VERSION && try_count<2)
#endif
{
try_count++;
sprintf(logstr,"chain[%d] PIC need restore ...\n",chainIndex);
writeLogFile(logstr);
dsPIC33EP16GS202_update_pic_app_program(chainIndex);
dsPIC33EP16GS202_jump_to_app_from_loader(chainIndex);
get_pic_software_version(chainIndex,&pic_version);
sprintf(logstr,"After restore: chain[%d] PIC fw version=0x%02x\n",chainIndex,pic_version);
writeLogFile(logstr);
}
#endif
}
else
{
if(chainIndex%3 != 0)
return;
sprintf(logstr,"chain[%d] PIC jump to app\n",chainIndex);
writeLogFile(logstr);
dsPIC33EP16GS202_jump_to_app_from_loader(chainIndex/3);
get_pic_software_version(chainIndex,&pic_version);
sprintf(logstr,"Check chain[%d] PIC fw version=0x%02x\n",chainIndex,pic_version);
writeLogFile(logstr);
#ifdef ENABLE_RESTORE_PIC_APP
#ifndef DEBUG_PIC_UPGRADE
while(pic_version!=PIC_VERSION && try_count<2)
#endif
{
try_count++;
sprintf(logstr,"chain[%d] PIC need restore ...\n",chainIndex);
writeLogFile(logstr);
dsPIC33EP16GS202_update_pic_app_program(chainIndex/3);
dsPIC33EP16GS202_jump_to_app_from_loader(chainIndex/3);
get_pic_software_version(chainIndex,&pic_version);
sprintf(logstr,"After restore: chain[%d] PIC fw version=0x%02x\n",chainIndex,pic_version);
writeLogFile(logstr);
}
#endif
}
}
#else
// this check and restore PIC function must be called after reset_iic_pic process, that means only can be called when in bootloader mode!
void jump_to_app_CheckAndRestorePIC(int chainIndex) // check PIC app is OK or not, if not right, write flash to restore app and jump to app mode again!
{
unsigned char pic_version;
char logstr[256];
int try_count=0;
jump_to_app_from_loader(chainIndex);
get_pic_software_version(chainIndex,&pic_version);
sprintf(logstr,"Check chain[%d] PIC fw version=0x%02x\n",chainIndex,pic_version);
writeLogFile(logstr);
#ifdef ENABLE_RESTORE_PIC_APP
#ifndef DEBUG_PIC_UPGRADE
while(pic_version!=PIC_VERSION && try_count<2)
#endif
{
try_count++;
sprintf(logstr,"chain[%d] PIC need restore ...\n",chainIndex);
writeLogFile(logstr);
update_pic_program(chainIndex);
jump_to_app_from_loader(chainIndex);
get_pic_software_version(chainIndex,&pic_version);
sprintf(logstr,"After restore: chain[%d] PIC fw version=0x%02x\n",chainIndex,pic_version);
writeLogFile(logstr);
}
#endif
}
#endif
void InitAsicCoreEnabledFlag()
{
int i,j,k;
for(i = 0; i < BITMAIN_MAX_CHAIN_NUM; i++)
{
for(j = 0; j < 256; j++)
{
for(k=0; k<256; k++)
{
asic_core_enabled_flag[i][j][k]=1; // set enabled as default value
last_asic_core_enabled_flag[i][j][k]=1; // set enabled as default value
}
chain_badcore_num[i][j]=0; // set init bad core num is 0
}
}
}
void ResetAsicCoreEnabledFlag(int chainIndex)
{
int j,k;
for(j = 0; j < 256; j++)
{
for(k=0; k<256; k++)
{
asic_core_enabled_flag[chainIndex][j][k]=1; // set enabled as default value
last_asic_core_enabled_flag[chainIndex][j][k]=1; // set enabled as default value
}
chain_badcore_num[chainIndex][j]=0; // set init bad core num is 0
}
}
void PrintAsicCoreEnabledFlag(int chainIndex)
{
int i,m;
char logstr[256];
sprintf(logstr,"Chain[%d] Bad Core info:\n",chainIndex);
writeLogFile(logstr);
for(i = 0; i < ASIC_NUM; i++)
{
for(m=0; m<ASIC_CORE_NUM; m++)
{
if(asic_core_enabled_flag[chainIndex][i][m] <= 0)
{
sprintf(logstr,"ASIC[%d] Core[%d] is bad!\n",i,m);
writeLogFile(logstr);
}
}
}
sprintf(logstr,"\n");
writeLogFile(logstr);
}
void UpdateAsicCoreEnabledFlagByResult(int chainIndex)
{
int i,m,j,k;
int n = chain_PassCount[chainIndex]/ASIC_CORE_NUM;
for(j = 0; j < 256; j++)
{
for(k=0; k<256; k++)
{
asic_core_enabled_flag[chainIndex][j][k]=1; // set enabled as default value
}
}
for(i = 0; i < ASIC_NUM; i++)
{
if(asic_nonce_num[chainIndex][i] < chain_PassCount[chainIndex])
{
for(m=0; m<ASIC_CORE_NUM; m++)
{
if(asic_core_nonce_num[chainIndex][i][m] < n)
{
asic_core_enabled_flag[chainIndex][i][m]=0;
}
}
}
}
}
void UpdateSingleAsicCoreEnabledFlagByResult(int chainIndex, int chipIndex)
{
int m,k;
int n = chain_PassCount[chainIndex]/ASIC_CORE_NUM;
for(k=0; k<256; k++)
{
asic_core_enabled_flag[chainIndex][chipIndex][k]=1; // set enabled as default value
}
if(asic_nonce_num[chainIndex][chipIndex] < chain_PassCount[chainIndex])
{
for(m=0; m<ASIC_CORE_NUM; m++)
{
if(asic_core_nonce_num[chainIndex][chipIndex][m] < n)
{
asic_core_enabled_flag[chainIndex][chipIndex][m]=0;
}
}
}
}
void copyAsicCoreEnabledFlagFromTemp(int chainIndex)
{
int i,m;
for(i = 0; i < ASIC_NUM; i++)
{
for(m=0; m<ASIC_CORE_NUM; m++)
{
asic_core_enabled_flag[chainIndex][i][m]=temp_asic_core_enabled_flag[chainIndex][i][m];
}
}
}
void copyAsicCoreEnabledFlagFromLast(int chainIndex)
{
int i,m;
for(i = 0; i < ASIC_NUM; i++)
{
for(m=0; m<ASIC_CORE_NUM; m++)
{
asic_core_enabled_flag[chainIndex][i][m]=last_asic_core_enabled_flag[chainIndex][i][m];
}
}
}
void SaveAsicCoreEnabledFlagByResultToLastRecord(int chainIndex)
{
int i,m,j,k;
int n = chain_PassCount[chainIndex]/ASIC_CORE_NUM;
for(j = 0; j < 256; j++)
{
for(k=0; k<256; k++)
{
last_asic_core_enabled_flag[chainIndex][j][k]=1; // set enabled as default value
}
}
for(i = 0; i < ASIC_NUM; i++)
{
if(asic_nonce_num[chainIndex][i] < chain_PassCount[chainIndex])
{
for(m=0; m<ASIC_CORE_NUM; m++)
{
if(asic_core_nonce_num[chainIndex][i][m] < n)
{
last_asic_core_enabled_flag[chainIndex][i][m]=0;
}
}
}
}
}
void SaveAsicCoreEnabledFlagByResultToTempRecord(int chainIndex)
{
int i,j,k,m;
int n = chain_PassCount[chainIndex]/ASIC_CORE_NUM;
for(j = 0; j < 256; j++)
{
for(k=0; k<256; k++)
{
temp_asic_core_enabled_flag[chainIndex][j][k]=1; // set enabled as default value
}
}
for(i = 0; i < ASIC_NUM; i++)
{
if(asic_nonce_num[chainIndex][i] < chain_PassCount[chainIndex])
{
for(m=0; m<ASIC_CORE_NUM; m++)
{
if(asic_core_nonce_num[chainIndex][i][m] < n)
temp_asic_core_enabled_flag[chainIndex][i][m]=0;
}
}
}
}
bool isSameLastAsicCoreEnabledFlagWithTemp(int chainIndex)
{
int i,m;
for(i = 0; i < ASIC_NUM; i++)
{
for(m=0; m<ASIC_CORE_NUM; m++)
{
if(temp_asic_core_enabled_flag[chainIndex][i][m] != last_asic_core_enabled_flag[chainIndex][i][m])
return false;
}
}
return true;
}
int getChainAsicLastBadCoreNum(int chainIndex, int asicIndex)
{
int m;
int badcore=0;
if(asicIndex>=ASIC_NUM)
return 0;
for(m=0; m<ASIC_CORE_NUM; m++)
{
if(last_asic_core_enabled_flag[chainIndex][asicIndex][m]<=0)
{
badcore++;
}
}
return badcore;
}
int getChainAsicTempBadCoreNum(int chainIndex, int asicIndex)
{
int m;
int badcore=0;
if(asicIndex>=ASIC_NUM)
return 0;
for(m=0; m<ASIC_CORE_NUM; m++)
{
if(temp_asic_core_enabled_flag[chainIndex][asicIndex][m]<=0)
{
badcore++;
}
}
return badcore;
}
bool isLastAsicGoodCoreNumLessThanTempAsicGoodCoreNum(int chainIndex)
{
int i,m;
int tempGoodCoreNum=0;
int lastGoodCoreNum=0;
if(Fmax[chainIndex]>ACCEPT_BADCORE_FREQ_INDEX && chain_vol_value[chainIndex]<RETRY_VOLTAGE)
return false;
for(i = 0; i < ASIC_NUM; i++)
{
for(m=0; m<ASIC_CORE_NUM; m++)
{
if(temp_asic_core_enabled_flag[chainIndex][i][m] > 0)
tempGoodCoreNum++;
}
}
for(i = 0; i < ASIC_NUM; i++)
{
for(m=0; m<ASIC_CORE_NUM; m++)
{
if(last_asic_core_enabled_flag[chainIndex][i][m] > 0)
lastGoodCoreNum++;
}
}
if(lastGoodCoreNum<=tempGoodCoreNum)
{
SaveAsicCoreEnabledFlagByResultToLastRecord(chainIndex);
return true;
}
else return false;
}
int getChainAsicBadCoreNum(int chainIndex, int asicIndex)
{
int m;
int badcore=0;
if(asicIndex>=ASIC_NUM)
return 0;
for(m=0; m<ASIC_CORE_NUM; m++)
{
if(asic_core_enabled_flag[chainIndex][asicIndex][m]<=0)
{
badcore++;
}
}
return badcore;
}
int getChainAsicGoodCoreNum(int chainIndex, int asicIndex)
{
int m;
int okcore=0;
if(asicIndex>=ASIC_NUM)
return 0;
for(m=0; m<ASIC_CORE_NUM; m++)
{
if(asic_core_enabled_flag[chainIndex][asicIndex][m]>0)
{
okcore++;
}
}
// decrease bad core num, when search freq mode, chain_badcore_num is all 0, but in test mode, has value!!!
okcore-=chain_badcore_num[chainIndex][asicIndex];
return okcore;
}
int getChainBadCoreNumUserMode(int chainIndex)
{
int m;
int badcore=0;
int asicIndex;
for(asicIndex=0;asicIndex<ASIC_NUM;asicIndex++)
{
// decrease bad core num, when search freq mode, chain_badcore_num is all 0, but in test mode, has value!!!
badcore+=chain_badcore_num[chainIndex][asicIndex];
}
return badcore;
}
int getChainLastBadCoreNum(int chainIndex)
{
int i,m;
int badcore=0;
for(i=0; i<ASIC_NUM; i++)
for(m=0; m<ASIC_CORE_NUM; m++)
{
if(last_asic_core_enabled_flag[chainIndex][i][m]<=0)
{
badcore++;
}
}
return badcore;
}
int getChainTempBadCoreNum(int chainIndex)
{
int i,m;
int badcore=0;
for(i=0; i<ASIC_NUM; i++)
for(m=0; m<ASIC_CORE_NUM; m++)
{
if(temp_asic_core_enabled_flag[chainIndex][i][m]<=0)
{
badcore++;
}
}
return badcore;
}
int getChainBadCoreNum(int chainIndex)
{
int i,m;
int badcore=0;
for(i=0; i<ASIC_NUM; i++)
for(m=0; m<ASIC_CORE_NUM; m++)
{
if(asic_core_enabled_flag[chainIndex][i][m]<=0)
{
badcore++;
}
}
return badcore;
}
bool isChainAsicLastBadCoreCanAccepted(int chainIndex)
{
int i;
char logstr[256];
bool ret=true;
int badcoreNum;
if(Fmax[chainIndex]>ACCEPT_BADCORE_FREQ_INDEX && chain_vol_value[chainIndex]<RETRY_VOLTAGE)
return false;
for(i = 0; i < ASIC_NUM; i++)
{
badcoreNum=getChainAsicLastBadCoreNum(chainIndex,i);
if(badcoreNum>0)
{
sprintf(logstr,"Chain[%d] Chip[%d] has %d bad cores.\n",chainIndex,i,badcoreNum);
writeLogFile(logstr);
}
if(badcoreNum>MAX_BAD_CORE_NUM)
ret=false; //set failed flag
}
return ret;
}
bool isChainAsicTempBadCoreCanAccepted(int chainIndex)
{
int i;
char logstr[256];
bool ret=true;
int badcoreNum;
if(Fmax[chainIndex]>ACCEPT_BADCORE_FREQ_INDEX && chain_vol_value[chainIndex]<RETRY_VOLTAGE)
return false;
for(i = 0; i < ASIC_NUM; i++)
{
badcoreNum=getChainAsicTempBadCoreNum(chainIndex,i);
if(badcoreNum>0)