Merge pull request #559 from kanoi/master antminer updates
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 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388
diff --git a/driver-bitmain.c b/driver-bitmain.c
index 3a5d3ae..9dc88b7 100644
--- a/driver-bitmain.c
+++ b/driver-bitmain.c
@@ -18,23 +18,6 @@ static void ants1_detect(__maybe_unused bool hotplug)
}
#else
-/*
-#include <limits.h>
-#include <pthread.h>
-#include <stdio.h>
-#include <sys/time.h>
-#include <sys/types.h>
-#include <dirent.h>
-#include <unistd.h>
-#include <sys/select.h>
-#include <termios.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#ifndef O_CLOEXEC
-#define O_CLOEXEC 0
-#endif
-*/
-
#include "elist.h"
#include "usbutils.h"
#include "driver-bitmain.h"
@@ -315,14 +298,15 @@ static int bitmain_set_txconfig(struct bitmain_txconfig_token *bm,
int datalen = 0;
uint8_t *sendbuf = (uint8_t *)bm;
if (unlikely(!bm)) {
- applog(LOG_WARNING, "bitmain_set_txconfig bitmain_txconfig_token is null");
+ applog(LOG_WARNING, "%s: %s() bm is null", ants1_drv.dname, __func__);
return -1;
}
if (unlikely(timeout_data <= 0 || asic_num <= 0 || chain_num <= 0)) {
- applog(LOG_WARNING, "bitmain_set_txconfig parameter invalid"
+ applog(LOG_WARNING, "%s: %s() parameter invalid"
" timeout_data(%d) asic_num(%d) chain_num(%d)",
- timeout_data, asic_num, chain_num);
+ ants1_drv.dname, __func__,
+ (int)timeout_data, (int)asic_num, (int)chain_num);
return -1;
}
@@ -358,42 +342,38 @@ static int bitmain_set_txconfig(struct bitmain_txconfig_token *bm,
crc = CRC16((uint8_t *)bm, datalen-2);
bm->crc = htole16(crc);
- applog(LOG_ERR, "BTM TxConfigToken:reset(%d) faneft(%d) touteft(%d) freqeft(%d)"
+ applog(LOG_DEBUG, "%s: %s() reset(%d) faneft(%d) touteft(%d) freqeft(%d)"
" volteft(%d) chainceft(%d) chipceft(%d) hweft(%d) mnum(%d)"
" anum(%d) fanpwmdata(%d) toutdata(%d) freq(%d) volt(%d)"
" chainctime(%d) regdata(%02x%02x%02x%02x) chipaddr(%02x)"
" regaddr(%02x) crc(%04x)",
- reset, fan_eft, timeout_eft, frequency_eft, voltage_eft,
- chain_check_time_eft, chip_config_eft, hw_error_eft,
- chain_num, asic_num, fan_pwm_data, timeout_data, frequency,
- voltage, chain_check_time, reg_data[0], reg_data[1],
- reg_data[2], reg_data[3], chip_address, reg_address, crc);
+ ants1_drv.dname, __func__,
+ (int)reset, (int)fan_eft, (int)timeout_eft, (int)frequency_eft,
+ (int)voltage_eft, (int)chain_check_time_eft, (int)chip_config_eft,
+ (int)hw_error_eft, (int)chain_num, (int)asic_num, (int)fan_pwm_data,
+ (int)timeout_data, (int)frequency, (int)voltage, (int)chain_check_time,
+ (int)reg_data[0], (int)reg_data[1], (int)reg_data[2], (int)reg_data[3],
+ (int)chip_address, (int)reg_address, (int)crc);
return datalen;
}
-static int bitmain_set_txtask(uint8_t *sendbuf, unsigned int *last_work_block,
- struct work **works, int work_array_size, int work_array,
- int sendworkcount, int *sendcount)
+static int bitmain_set_txtask(struct bitmain_info *info, uint8_t *sendbuf,
+ unsigned int *last_work_block, int *sentcount)
{
uint16_t crc = 0;
uint32_t work_id = 0;
int datalen = 0;
- int i = 0;
- int index = work_array;
uint8_t new_block = 0;
//char *ob_hex = NULL;
struct bitmain_txtask_token *bm = (struct bitmain_txtask_token *)sendbuf;
- int cursendcount = 0;
+ int cursentcount = 0;
+ K_ITEM *witem;
- *sendcount = 0;
+ *sentcount = 0;
if (unlikely(!bm)) {
- applog(LOG_WARNING, "bitmain_set_txtask bitmain_txtask_token is null");
- return -1;
- }
- if (unlikely(!works)) {
- applog(LOG_WARNING, "bitmain_set_txtask work is null");
+ applog(LOG_WARNING, "%s: %s() bm is null", ants1_drv.dname, __func__);
return -1;
}
memset(bm, 0, sizeof(struct bitmain_txtask_token));
@@ -401,45 +381,49 @@ static int bitmain_set_txtask(uint8_t *sendbuf, unsigned int *last_work_block,
bm->token_type = BITMAIN_TOKEN_TYPE_TXTASK;
datalen = 10;
- applog(LOG_DEBUG, "BTM send work count %d -----", sendworkcount);
- for (i = 0; i < sendworkcount; i++) {
- if (index > work_array_size)
- index = 0;
-
- if (works[index]) {
- if (works[index]->work_block > *last_work_block) {
- applog(LOG_ERR, "BTM send task new block %d old(%d)",
- works[index]->work_block, *last_work_block);
- new_block = 1;
- *last_work_block = works[index]->work_block;
- }
+ applog(LOG_DEBUG, "%s: send work count %d", ants1_drv.dname, info->work_ready->count);
+ while (info->work_ready->count) {
+ witem = k_unlink_head(info->work_ready);
+ if (DATAW(witem)->work->work_block > *last_work_block) {
+ applog(LOG_ERR, "%s: send task new block %d old(%d)",
+ ants1_drv.dname,
+ DATAW(witem)->work->work_block, *last_work_block);
+ new_block = 1;
+ *last_work_block = DATAW(witem)->work->work_block;
+ }
#ifdef BITMAIN_TEST
- if (!hex2bin(works[index]->data, btm_work_test_data, 128))
- applog(LOG_DEBUG, "BTM send task set test data error");
+ if (!hex2bin(DATAW(witem)->work->data, btm_work_test_data, 128)) {
+ applog(LOG_DEBUG, "%s: send task set test data error",
+ ants1_drv.dname);
+ }
- if (!hex2bin(works[index]->midstate, btm_work_test_midstate, 32))
- applog(LOG_DEBUG, "BTM send task set test midstate error");
-#endif
- work_id = works[index]->id;
- bm->works[cursendcount].work_id = htole32(work_id);
- applog(LOG_DEBUG, "BTM send task work id:%"PRIu32" %"PRIu32,
- bm->works[cursendcount].work_id, work_id);
- memcpy(bm->works[cursendcount].midstate, works[index]->midstate, 32);
- memcpy(bm->works[cursendcount].data2, works[index]->data + 64, 12);
-
- /*ob_hex = bin2hex(works[index]->data, 76);
- applog(LOG_ERR, "work %d data: %s", works[index]->id, ob_hex);
- free(ob_hex);*/
-
- cursendcount++;
+ if (!hex2bin(DATAW(witem)->work->midstate, btm_work_test_midstate, 32)) {
+ applog(LOG_DEBUG, "%s: send task set test midstate error",
+ ants1_drv.dname);
}
- index++;
+#endif
+ work_id = DATAW(witem)->work->id;
+ bm->works[cursentcount].work_id = htole32(work_id);
+ applog(LOG_DEBUG, "%s: send task work id:%"PRIu32" %"PRIu32,
+ ants1_drv.dname,
+ bm->works[cursentcount].work_id, work_id);
+ memcpy(bm->works[cursentcount].midstate, DATAW(witem)->work->midstate, 32);
+ memcpy(bm->works[cursentcount].data2, DATAW(witem)->work->data + 64, 12);
+
+ /*ob_hex = bin2hex(DATAW(witem)->work->data, 76);
+ applog(LOG_ERR, "%s: work %d data: %s",
+ ants1_drv.dname,
+ DATAW(witem)->work->id, ob_hex);
+ free(ob_hex);*/
+
+ cursentcount++;
+ k_add_head(info->work_list, witem);
}
- if (cursendcount <= 0) {
- applog(LOG_ERR, "BTM send work count %d", cursendcount);
+ if (cursentcount <= 0) {
+ applog(LOG_ERR, "%s: send work count %d", ants1_drv.dname, cursentcount);
return 0;
}
- datalen += 48*cursendcount;
+ datalen += 48*cursentcount;
bm->length = datalen-4;
bm->length = htole16(bm->length);
@@ -450,20 +434,23 @@ static int bitmain_set_txtask(uint8_t *sendbuf, unsigned int *last_work_block,
sendbuf[4] = bitswap(sendbuf[4]);
- applog(LOG_DEBUG, "BitMain TxTask Token: %d %d %02x%02x%02x%02x%02x%02x",
+ applog(LOG_DEBUG, "%s: TxTask Token: %d %d %02x%02x%02x%02x%02x%02x",
+ ants1_drv.dname,
datalen, bm->length,
sendbuf[0], sendbuf[1], sendbuf[2],
sendbuf[3], sendbuf[4], sendbuf[5]);
- *sendcount = cursendcount;
+ *sentcount = cursentcount;
crc = CRC16(sendbuf, datalen-2);
crc = htole16(crc);
memcpy(sendbuf+datalen-2, &crc, 2);
- applog(LOG_DEBUG, "BitMain TxTask Token: new_block(%d) work_num(%d) crc(%04x)",
- new_block, cursendcount, crc);
- applog(LOG_DEBUG, "BitMain TxTask Token: %d %d %02x%02x%02x%02x%02x%02x",
+ applog(LOG_DEBUG, "%s: TxTask Token: new_block(%d) work_num(%d) crc(%04x)",
+ ants1_drv.dname,
+ new_block, cursentcount, crc);
+ applog(LOG_DEBUG, "%s: TxTask Token: %d %d %02x%02x%02x%02x%02x%02x",
+ ants1_drv.dname,
datalen, bm->length,
sendbuf[0], sendbuf[1], sendbuf[2],
sendbuf[3], sendbuf[4], sendbuf[5]);
@@ -479,7 +466,7 @@ static int bitmain_set_rxstatus(struct bitmain_rxstatus_token *bm,
uint8_t *sendbuf = (uint8_t *)bm;
if (unlikely(!bm)) {
- applog(LOG_WARNING, "bitmain_set_rxstatus bitmain_rxstatus_token is null");
+ applog(LOG_WARNING, "%s: %s() bm is null", ants1_drv.dname, __func__);
return -1;
}
@@ -500,8 +487,9 @@ static int bitmain_set_rxstatus(struct bitmain_rxstatus_token *bm,
crc = CRC16((uint8_t *)bm, datalen-2);
bm->crc = htole16(crc);
- applog(LOG_DEBUG, "BitMain RxStatus Token: chip_status_eft(%d) detect_get(%d)"
+ applog(LOG_DEBUG, "%s: RxStatus Token: chip_status_eft(%d) detect_get(%d)"
" chip_address(%02x) reg_address(%02x) crc(%04x)",
+ ants1_drv.dname,
chip_status_eft, detect_get, chip_address, reg_address, crc);
return datalen;
@@ -512,43 +500,51 @@ static int bitmain_parse_rxstatus(const uint8_t * data, int datalen, struct bitm
uint16_t crc = 0;
int i = 0;
if (unlikely(!bm)) {
- applog(LOG_WARNING, "bitmain_parse_rxstatus bitmain_rxstatus_data is null");
+ applog(LOG_ERR, "%s: %s() bm is null", ants1_drv.dname, __func__);
return -1;
}
if (unlikely(!data || datalen <= 0)) {
- applog(LOG_WARNING, "bitmain_parse_rxstatus parameter invalid data is null"
- " or datalen(%d) error",
- datalen);
+ applog(LOG_ERR, "%s: %s() parameter invalid data is null"
+ " or datalen(%d) error",
+ ants1_drv.dname, __func__, datalen);
return -1;
}
memcpy(bm, data, sizeof(struct bitmain_rxstatus_data));
if (bm->data_type != BITMAIN_DATA_TYPE_RXSTATUS) {
- applog(LOG_ERR, "bitmain_parse_rxstatus datatype(%02x) error", bm->data_type);
+ applog(LOG_ERR, "%s: %s() datatype(%02x) error",
+ ants1_drv.dname, __func__,
+ bm->data_type);
return -1;
}
if (bm->length+2 != datalen) {
- applog(LOG_ERR, "bitmain_parse_rxstatus length(%d) error", bm->length);
+ applog(LOG_ERR, "%s: %s() length(%d) error",
+ ants1_drv.dname, __func__,
+ bm->length);
return -1;
}
crc = CRC16(data, datalen-2);
memcpy(&(bm->crc), data+datalen-2, 2);
bm->crc = htole16(bm->crc);
if (crc != bm->crc) {
- applog(LOG_ERR, "bitmain_parse_rxstatus check crc(%d)"
+ applog(LOG_ERR, "%s: %s() check crc(%d)"
" != bm crc(%d) datalen(%d)",
+ ants1_drv.dname, __func__,
crc, bm->crc, datalen);
return -1;
}
bm->fifo_space = htole32(bm->fifo_space);
bm->nonce_error = htole32(bm->nonce_error);
if (bm->chain_num*5 + bm->temp_num + bm->fan_num + 22 != datalen) {
- applog(LOG_ERR, "bitmain_parse_rxstatus chain_num(%d) temp_num(%d)"
+ applog(LOG_ERR, "%s: %s() chain_num(%d) temp_num(%d)"
" fan_num(%d) not match datalen(%d)",
+ ants1_drv.dname, __func__,
bm->chain_num, bm->temp_num, bm->fan_num, datalen);
return -1;
}
if (bm->chain_num > BITMAIN_MAX_CHAIN_NUM) {
- applog(LOG_ERR, "bitmain_parse_rxstatus chain_num=%d error", bm->chain_num);
+ applog(LOG_ERR, "%s: %s() chain_num=%d error",
+ ants1_drv.dname, __func__,
+ bm->chain_num);
return -1;
}
if (bm->chain_num > 0) {
@@ -565,22 +561,28 @@ static int bitmain_parse_rxstatus(const uint8_t * data, int datalen, struct bitm
if (bm->fan_num > 0) {
memcpy(bm->fan, data+20+bm->chain_num*5+bm->temp_num, bm->fan_num);
}
- applog(LOG_DEBUG, "BitMain RxStatusData: chipvalueeft(%d) version(%d) fifospace(%d)"
+ applog(LOG_DEBUG, "%s: RxStatus Data chipvalueeft(%d) version(%d) fifospace(%d)"
" regvalue(%d) chainnum(%d) tempnum(%d) fannum(%d) crc(%04x)",
+ ants1_drv.dname,
bm->chip_value_eft, bm->version, bm->fifo_space, bm->reg_value,
bm->chain_num, bm->temp_num, bm->fan_num, bm->crc);
- applog(LOG_DEBUG, "BitMain RxStatus Data chain info:");
+ applog(LOG_DEBUG, "%s: RxStatus Data chain info:", ants1_drv.dname);
for (i = 0; i < bm->chain_num; i++) {
- applog(LOG_DEBUG, "BitMain RxStatus Data chain(%d) asic num=%d asic_status=%08x",
+ applog(LOG_DEBUG, "%s: RxStatus Data chain(%d) asic num=%d asic_status=%08x",
+ ants1_drv.dname,
i+1, bm->chain_asic_num[i], bm->chain_asic_status[i]);
}
- applog(LOG_DEBUG, "BitMain RxStatus Data temp info:");
+ applog(LOG_DEBUG, "%s: RxStatus Data temp info:", ants1_drv.dname);
for (i = 0; i < bm->temp_num; i++) {
- applog(LOG_DEBUG, "BitMain RxStatus Data temp(%d) temp=%d", i+1, bm->temp[i]);
+ applog(LOG_DEBUG, "%s: RxStatus Data temp(%d) temp=%d",
+ ants1_drv.dname,
+ i+1, bm->temp[i]);
}
- applog(LOG_DEBUG, "BitMain RxStatus Data fan info:");
+ applog(LOG_DEBUG, "%s: RxStatus Data fan info:", ants1_drv.dname);
for (i = 0; i < bm->fan_num; i++) {
- applog(LOG_DEBUG, "BitMain RxStatus Data fan(%d) fan=%d", i+1, bm->fan[i]);
+ applog(LOG_DEBUG, "%s: RxStatus Data fan(%d) fan=%d",
+ ants1_drv.dname,
+ i+1, bm->fan[i]);
}
return 0;
}
@@ -591,40 +593,49 @@ static int bitmain_parse_rxnonce(const uint8_t * data, int datalen, struct bitma
uint16_t crc = 0;
int curnoncenum = 0;
if (unlikely(!bm)) {
- applog(LOG_ERR, "bitmain_parse_rxnonce bitmain_rxstatus_data null");
+ applog(LOG_ERR, "%s: %s() bm is null", ants1_drv.dname, __func__);
return -1;
}
if (unlikely(!data || datalen <= 0)) {
- applog(LOG_ERR, "bitmain_parse_rxnonce data null or datalen(%d) error", datalen);
+ applog(LOG_ERR, "%s: %s() parameter invalid data is null"
+ " or datalen(%d) error",
+ ants1_drv.dname, __func__, datalen);
return -1;
}
memcpy(bm, data, sizeof(struct bitmain_rxnonce_data));
if (bm->data_type != BITMAIN_DATA_TYPE_RXNONCE) {
- applog(LOG_ERR, "bitmain_parse_rxnonce datatype(%02x) error", bm->data_type);
+ applog(LOG_ERR, "%s: %s() datatype(%02x) error",
+ ants1_drv.dname, __func__,
+ bm->data_type);
return -1;
}
if (bm->length+2 != datalen) {
- applog(LOG_ERR, "bitmain_parse_rxnonce length(%d) error", bm->length);
+ applog(LOG_ERR, "%s: %s() length(%d) error",
+ ants1_drv.dname, __func__,
+ bm->length);
return -1;
}
crc = CRC16(data, datalen-2);
memcpy(&(bm->crc), data+datalen-2, 2);
bm->crc = htole16(bm->crc);
if (crc != bm->crc) {
- applog(LOG_ERR, "bitmain_parse_rxnonce check crc(%d)"
+ applog(LOG_ERR, "%s: %s() check crc(%d)"
" != bm crc(%d) datalen(%d)",
+ ants1_drv.dname, __func__,
crc, bm->crc, datalen);
return -1;
}
curnoncenum = (datalen-4)/8;
- applog(LOG_DEBUG, "BitMain RxNonce Data: nonce_num(%d-%d) fifo_space(%d)",
+ applog(LOG_DEBUG, "%s: RxNonce Data: nonce_num(%d-%d) fifo_space(%d)",
+ ants1_drv.dname,
curnoncenum, bm->nonce_num, bm->fifo_space);
for (i = 0; i < curnoncenum; i++) {
bm->nonces[i].work_id = htole32(bm->nonces[i].work_id);
bm->nonces[i].nonce = htole32(bm->nonces[i].nonce);
- applog(LOG_DEBUG, "BitMain RxNonce Data %d: work_id(%"PRIu32") nonce(%08x)(%d)",
+ applog(LOG_DEBUG, "%s: RxNonce Data %d: work_id(%"PRIu32") nonce(%08x)(%d)",
+ ants1_drv.dname,
i, bm->nonces[i].work_id,
bm->nonces[i].nonce, bm->nonces[i].nonce);
}
@@ -638,14 +649,16 @@ static int bitmain_read(struct cgpu_info *bitmain, unsigned char *buf,
int readlen = 0, err = 0;
if (bitmain == NULL || buf == NULL || bufsize <= 0) {
- applog(LOG_WARNING, "bitmain_read parameter error bufsize(%d)",
- (int)bufsize);
+ applog(LOG_WARNING, "%s%d: %s() parameter error bufsize(%d)",
+ bitmain->drv->name, bitmain->device_id,
+ __func__, (int)bufsize);
return -1;
}
err = usb_read_once_timeout(bitmain, (char *)buf, bufsize, &readlen, timeout, ep);
- applog(LOG_DEBUG, "%s%i: Get bitmain read got readlen %d err %d",
- bitmain->drv->name, bitmain->device_id, readlen, err);
+ applog(LOG_DEBUG, "%s%i: Get %s() got readlen %d err %d",
+ bitmain->drv->name, bitmain->device_id,
+ __func__, readlen, err);
return readlen;
}
@@ -655,16 +668,18 @@ static int bitmain_write(struct cgpu_info *bitmain, char *buf, ssize_t len, int
int err, amount;
err = usb_write(bitmain, buf, len, &amount, ep);
- applog(LOG_DEBUG, "%s%i: usb_write got err %d",
+ applog(LOG_DEBUG, "%s%d: usb_write got err %d",
bitmain->drv->name, bitmain->device_id, err);
if (unlikely(err != 0)) {
- applog(LOG_ERR, "usb_write error on bitmain_write err=%d", err);
+ applog(LOG_ERR, "%s%d: usb_write error on %s() err=%d",
+ bitmain->drv->name, bitmain->device_id, __func__, err);
return BTM_SEND_ERROR;
}
if (amount != len) {
- applog(LOG_ERR, "usb_write length mismatch on bitmain_write "
+ applog(LOG_ERR, "%s%d: usb_write length mismatch on %s() "
"amount=%d len=%d",
+ bitmain->drv->name, bitmain->device_id, __func__,
amount, (int)len);
return BTM_SEND_ERROR;
}
@@ -697,14 +712,15 @@ static int bitmain_send_data(const uint8_t *data, int datalen, __maybe_unused st
//delay += 4000;
if (opt_debug) {
- applog(LOG_DEBUG, "BitMain: Sent(%d):", datalen);
+ applog(LOG_DEBUG, "%s: Sent(%d):", ants1_drv.dname, datalen);
hexdump(data, datalen);
}
//cgsleep_prepare_r(&ts_start);
- applog(LOG_DEBUG, "----bitmain_send_data start");
+ applog(LOG_DEBUG, "%s: %s() start", ants1_drv.dname, __func__);
ret = bitmain_write(bitmain, (char *)data, datalen, ep);
- applog(LOG_DEBUG, "----bitmain_send_data stop ret=%d datalen=%d", ret, datalen);
+ applog(LOG_DEBUG, "%s: %s() stop ret=%d datalen=%d",
+ ants1_drv.dname, __func__, ret, datalen);
//cgsleep_us_r(&ts_start, delay);
//applog(LOG_DEBUG, "BitMain: Sent: Buffer delay: %dus", delay);
@@ -715,7 +731,7 @@ static int bitmain_send_data(const uint8_t *data, int datalen, __maybe_unused st
static void bitmain_inc_nvw(struct bitmain_info *info, struct thr_info *thr)
{
applog(LOG_INFO, "%s%d: No matching work - HW error",
- thr->cgpu->drv->name, thr->cgpu->device_id);
+ thr->cgpu->drv->name, thr->cgpu->device_id);
inc_hw_errors(thr);
info->no_matching_work++;
@@ -760,7 +776,7 @@ static void bitmain_update_temps(struct cgpu_info *bitmain, struct bitmain_info
int i = 0;
record_temp_fan(info, bm, &(bitmain->temp));
- strcpy(msg, "BitMain: ");
+ sprintf(msg, "%s%d: ", bitmain->drv->name, bitmain->device_id);
for (i = 0; i < bm->fan_num; i++) {
if (i != 0) {
strcat(msg, ", ");
@@ -768,7 +784,7 @@ static void bitmain_update_temps(struct cgpu_info *bitmain, struct bitmain_info
sprintf(tmp, "Fan%d: %d/m", i+1, info->fan[i]);
strcat(msg, tmp);
}
- strcat(msg, "\t");
+ strcat(msg, " ");
for (i = 0; i < bm->temp_num; i++) {
if (i != 0) {
strcat(msg, ", ");
@@ -781,17 +797,20 @@ static void bitmain_update_temps(struct cgpu_info *bitmain, struct bitmain_info
applog(LOG_INFO, msg);
info->temp_history_index++;
info->temp_sum += bitmain->temp;
- applog(LOG_DEBUG, "BitMain: temp_index: %d, temp_count: %d, temp_old: %d",
- info->temp_history_index, info->temp_history_count, info->temp_old);
+ applog(LOG_DEBUG, "%s%d: temp_index: %d, temp_count: %d, temp_max: %d",
+ bitmain->drv->name, bitmain->device_id,
+ info->temp_history_index, info->temp_history_count, info->temp_max);
if (info->temp_history_index == info->temp_history_count) {
info->temp_history_index = 0;
info->temp_sum = 0;
}
- if (unlikely(info->temp_old >= opt_bitmain_overheat)) {
- applog(LOG_WARNING, "BTM%d overheat! Idling", bitmain->device_id);
+ if (unlikely(info->temp_max >= opt_bitmain_overheat)) {
+ applog(LOG_WARNING, "%s%d: overheat! Idling",
+ bitmain->drv->name, bitmain->device_id);
info->overheat = true;
- } else if (info->overheat && info->temp_old <= opt_bitmain_temp) {
- applog(LOG_WARNING, "BTM%d cooled, restarting", bitmain->device_id);
+ } else if (info->overheat && info->temp_max <= opt_bitmain_temp) {
+ applog(LOG_WARNING, "%s%d: cooled, restarting",
+ bitmain->drv->name, bitmain->device_id);
info->overheat = false;
}
}
@@ -804,36 +823,41 @@ static void bitmain_parse_results(struct cgpu_info *bitmain, struct bitmain_info
bool found = false;
struct work *work = NULL;
//char *ob_hex = NULL;
+ uint64_t searches;
+ K_ITEM *witem;
for (i = 0; i <= spare; i++) {
if (buf[i] == 0xa1) {
struct bitmain_rxstatus_data rxstatusdata;
- applog(LOG_DEBUG, "bitmain_parse_results RxStatus Data");
+ applog(LOG_DEBUG, "%s%d: %s() RxStatus Data",
+ bitmain->drv->name, bitmain->device_id,
+ __func__);
if (*offset < 2) {
return;
}
if (buf[i+1] > 124) {
- applog(LOG_ERR, "bitmain_parse_results bitmain_parse_rxstatus"
- " datalen=%d error",
- buf[i+1]+2);
+ applog(LOG_ERR, "%s%d: %s() RxStatus Data datalen=%d error",
+ bitmain->drv->name, bitmain->device_id,
+ __func__, buf[i+1]+2);
continue;
}
if (*offset < buf[i+1] + 2) {
return;
}
if (bitmain_parse_rxstatus(buf+i, buf[i+1]+2, &rxstatusdata) != 0) {
- applog(LOG_ERR, "bitmain_parse_results bitmain_parse_rxstatus"
- " error len=%d",
- buf[i+1]+2);
+ applog(LOG_ERR, "%s%d: %s() RxStatus Data error len=%d",
+ bitmain->drv->name, bitmain->device_id,
+ __func__, buf[i+1]+2);
} else {
mutex_lock(&info->qlock);
info->chain_num = rxstatusdata.chain_num;
info->fifo_space = rxstatusdata.fifo_space;
info->nonce_error = rxstatusdata.nonce_error;
errordiff = info->nonce_error-info->last_nonce_error;
- applog(LOG_ERR, "bitmain_parse_results bitmain_parse_rxstatus"
+ applog(LOG_DEBUG, "%s%d: %s() RxStatus Data"
" version=%d chainnum=%d fifospace=%d"
" nonceerror=%d-%d freq=%d chain info:",
+ bitmain->drv->name, bitmain->device_id, __func__,
rxstatusdata.version, info->chain_num,
info->fifo_space, info->last_nonce_error,
info->nonce_error, info->frequency);
@@ -855,8 +879,10 @@ static void bitmain_parse_results(struct cgpu_info *bitmain, struct bitmain_info
j++;
}
- applog(LOG_ERR, "bitmain_parse_rxstatus chain(%d)"
+ applog(LOG_DEBUG, "%s%d: %s() RxStatus Data chain(%d)"
" asic_num=%d asic_status=%08x-%s",
+ bitmain->drv->name, bitmain->device_id,
+ __func__,
n, info->chain_asic_num[n],
info->chain_asic_status[n],
info->chain_asic_status_t[n]);
@@ -877,87 +903,141 @@ static void bitmain_parse_results(struct cgpu_info *bitmain, struct bitmain_info
found = true;
spare = buf[i+1] + 2 + i;
if (spare > *offset) {
- applog(LOG_ERR, "bitmain_parse_rxresults space(%d) > offset(%d)",
- spare, *offset);
+ applog(LOG_ERR, "%s%d: %s() spare(%d) > offset(%d)",
+ bitmain->drv->name, bitmain->device_id,
+ __func__, spare, *offset);
spare = *offset;
}
break;
} else if (buf[i] == 0xa2) {
struct bitmain_rxnonce_data rxnoncedata;
int nonce_num = 0;
- applog(LOG_DEBUG, "bitmain_parse_results RxNonce Data");
+ applog(LOG_DEBUG, "%s%d: %s() RxNonce Data",
+ bitmain->drv->name, bitmain->device_id,
+ __func__);
if (*offset < 2) {
return;
}
if (buf[i+1] > 70) {
- applog(LOG_ERR, "bitmain_parse_results bitmain_parse_rxnonce "
- "datalen=%d error",
- buf[i+1]+2);
+ applog(LOG_ERR, "%s%d: %s() RxNonce Data datalen=%d error",
+ bitmain->drv->name, bitmain->device_id,
+ __func__, buf[i+1]+2);
continue;
}
if (*offset < buf[i+1] + 2) {
return;
}
if (bitmain_parse_rxnonce(buf+i, buf[i+1]+2, &rxnoncedata, &nonce_num) != 0) {
- applog(LOG_ERR, "bitmain_parse_results bitmain_parse_rxnonce "
- "error len=%d",
- buf[i+1]+2);
+ applog(LOG_ERR, "%s%d: %s() RxNonce Data error len=%d",
+ bitmain->drv->name, bitmain->device_id,
+ __func__, buf[i+1]+2);
} else {
for (j = 0; j < nonce_num; j++) {
- work = find_queued_work_byid(bitmain, rxnoncedata.nonces[j].work_id);
- if (work) {
- applog(LOG_DEBUG, "bitmain_parse_results nonce find "
+ searches = 0;
+ mutex_lock(&info->qlock);
+ witem = info->work_list->head;
+ while (witem) {
+ searches++;
+ if (DATAW(witem)->work->id == rxnoncedata.nonces[j].work_id)
+ break;
+ witem = witem->next;
+ }
+ mutex_unlock(&info->qlock);
+ if (witem) {
+ if (info->work_search == 0) {
+ info->min_search = searches;
+ info->max_search = searches;
+ } else {
+ if (info->min_search > searches)
+ info->min_search = searches;
+ if (info->max_search < searches)
+ info->max_search = searches;
+ }
+ info->work_search++;
+ info->tot_search += searches;
+
+ work = DATAW(witem)->work;
+ applog(LOG_DEBUG, "%s%d: %s() RxNonce Data find "
"work(%"PRIu32"-%"PRIu32")(%08x)",
- work->id,
+ bitmain->drv->name, bitmain->device_id,
+ __func__, work->id,
rxnoncedata.nonces[j].work_id,
rxnoncedata.nonces[j].nonce);
/*ob_hex = bin2hex(work->midstate, 32);
- applog(LOG_ERR, "work %d midstate: %s", work->id, ob_hex);
+ applog(LOG_ERR, "%s%d: work %d midstate: %s",
+ bitmain->drv->name, bitmain->device_id,
+ work->id, ob_hex);
free(ob_hex);
ob_hex = bin2hex(work->data+64, 12);
- applog(LOG_ERR, "work %d data2: %s", work->id, ob_hex);
+ applog(LOG_ERR, "%s%d: work %d data2: %s",i
+ bitmain->drv->name, bitmain->device_id,
+ work->id, ob_hex);
free(ob_hex);*/
//info->matching_work[work->subid]++;
- applog(LOG_DEBUG, "BitMain: nonce = %08x",
- rxnoncedata.nonces[j].nonce);
+ applog(LOG_DEBUG, "%s%d: %s() nonce = %08x",
+ bitmain->drv->name, bitmain->device_id,
+ __func__, rxnoncedata.nonces[j].nonce);
if (submit_nonce(thr, work, rxnoncedata.nonces[j].nonce)) {
- applog(LOG_DEBUG, "bitmain_decode_nonce ok");
+ applog(LOG_DEBUG, "%s%d: %s() RxNonce Data ok",
+ bitmain->drv->name,
+ bitmain->device_id,
+ __func__);
mutex_lock(&info->qlock);
info->nonces++;
info->auto_nonces++;
mutex_unlock(&info->qlock);
} else {
//bitmain_inc_nvw(info, thr);
- applog(LOG_ERR, "BitMain: bitmain_decode_nonce "
+ applog(LOG_ERR, "%s%d: %s() RxNonce Data "
"error work(%"PRIu32")",
+ bitmain->drv->name,
+ bitmain->device_id,
+ __func__,
rxnoncedata.nonces[j].work_id);
}
} else {
+ if (info->failed_search == 0) {
+ info->min_failed = searches;
+ info->max_failed = searches;
+ } else {
+ if (info->min_failed > searches)
+ info->min_failed = searches;
+ if (info->max_failed < searches)
+ info->max_failed = searches;
+ }
+ info->failed_search++;
+ info->tot_failed += searches;
+
//bitmain_inc_nvw(info, thr);
- applog(LOG_ERR, "BitMain: Work not found for id (%"PRIu32")",
- rxnoncedata.nonces[j].work_id);
+ applog(LOG_ERR, "%s%d: %s() Work not found for id (%"PRIu32")",
+ bitmain->drv->name, bitmain->device_id,
+ __func__, rxnoncedata.nonces[j].work_id);
}
}
mutex_lock(&info->qlock);
info->fifo_space = rxnoncedata.fifo_space;
- applog(LOG_DEBUG, "bitmain_parse_rxnonce fifo space=%d",
- info->fifo_space);
+ applog(LOG_DEBUG, "%s%d: %s() RxNonce Data fifo space=%d",
+ bitmain->drv->name, bitmain->device_id,
+ __func__, info->fifo_space);
mutex_unlock(&info->qlock);
}
found = true;
spare = buf[i+1] + 2 + i;
if (spare > *offset) {
- applog(LOG_ERR, "bitmain_parse_rxnonce space(%d) > offset(%d)",
+ applog(LOG_ERR, "%s%d: %s() RxNonce Data space(%d) > offset(%d)",
+ bitmain->drv->name, bitmain->device_id, __func__,
spare, *offset);
spare = *offset;
}
break;
} else {
- applog(LOG_ERR, "bitmain_parse_results data type error=%02x", buf[i]);
+ applog(LOG_ERR, "%s%d: %s() data type error=%02x",
+ bitmain->drv->name, bitmain->device_id,
+ __func__, buf[i]);
}
}
if (!found) {
@@ -973,9 +1053,9 @@ static void bitmain_parse_results(struct cgpu_info *bitmain, struct bitmain_info
memmove(buf, buf + spare, *offset);
}
-static void bitmain_running_reset(struct cgpu_info *bitmain, struct bitmain_info *info)
+static void bitmain_running_reset(struct bitmain_info *info)
{
- bitmain->results = 0;
+ info->results = 0;
info->reset = false;
}
@@ -996,22 +1076,26 @@ static void *bitmain_get_results(void *userdata)
while (likely(!bitmain->shutdown)) {
unsigned char buf[rsize];
- applog(LOG_DEBUG, "+++++++bitmain_get_results offset=%d", offset);
+ applog(LOG_DEBUG, "%s%d: %s() offset=%d",
+ bitmain->drv->name, bitmain->device_id, __func__, offset);
if (offset >= (int)BITMAIN_READ_SIZE) {
- applog(LOG_DEBUG, "======start bitmain_get_results ");
+ applog(LOG_DEBUG, "%s%d: %s() start",
+ bitmain->drv->name, bitmain->device_id, __func__);
bitmain_parse_results(bitmain, info, thr, (uint8_t *)readbuf, &offset);
- applog(LOG_DEBUG, "======stop bitmain_get_results ");
+ applog(LOG_DEBUG, "%s%d: %s() stop",
+ bitmain->drv->name, bitmain->device_id, __func__);
}
if (unlikely(offset + rsize >= BITMAIN_READBUF_SIZE)) {
/* This should never happen */
- applog(LOG_DEBUG, "BitMain readbuf overflow, resetting buffer");
+ applog(LOG_DEBUG, "%s%d: readbuf overflow, resetting buffer",
+ bitmain->drv->name, bitmain->device_id);
offset = 0;
}
if (unlikely(info->reset)) {
- bitmain_running_reset(bitmain, info);
+ bitmain_running_reset(info);
/* Discard anything in the buffer */
offset = 0;
}
@@ -1019,19 +1103,21 @@ static void *bitmain_get_results(void *userdata)
/* As the usb read returns after just 1ms, sleep long enough
* to leave the interface idle for writes to occur, but do not
* sleep if we have been receiving data as more may be coming. */
- //if (offset == 0) {
+ //if (offset == 0)
// cgsleep_ms_r(&ts_start, BITMAIN_READ_TIMEOUT);
- //}
//cgsleep_prepare_r(&ts_start);
- applog(LOG_DEBUG, "======start bitmain_get_results bitmain_read");
+ applog(LOG_DEBUG, "%s%d: %s() read",
+ bitmain->drv->name, bitmain->device_id, __func__);
ret = bitmain_read(bitmain, buf, rsize, BITMAIN_READ_TIMEOUT, C_BITMAIN_READ);
- applog(LOG_DEBUG, "======stop bitmain_get_results bitmain_read=%d", ret);
+ applog(LOG_DEBUG, "%s%d: %s() read=%d",
+ bitmain->drv->name, bitmain->device_id, __func__, ret);
if (ret < 1) {
errorcount++;
if (errorcount > 100) {
- applog(LOG_ERR, "bitmain_read errorcount ret=%d", ret);
+ applog(LOG_ERR, "%s%d: read errorcount>100 ret=%d",
+ bitmain->drv->name, bitmain->device_id, ret);
cgsleep_ms(20);
errorcount = 0;
}
@@ -1039,7 +1125,8 @@ static void *bitmain_get_results(void *userdata)
}
if (opt_debug) {
- applog(LOG_DEBUG, "BitMain: get:");
+ applog(LOG_DEBUG, "%s%d: get:",
+ bitmain->drv->name, bitmain->device_id);
hexdump((uint8_t *)buf, ret);
}
@@ -1058,7 +1145,9 @@ static void bitmain_set_timeout(struct bitmain_info *info)
static void bitmain_init(struct cgpu_info *bitmain)
{
- applog(LOG_INFO, "BitMain: Opened on %s", bitmain->device_path);
+ applog(LOG_INFO, "%s%d: opened on %s",
+ bitmain->drv->name, bitmain->device_id,
+ bitmain->device_path);
}
static bool bitmain_prepare(struct thr_info *thr)
@@ -1066,12 +1155,6 @@ static bool bitmain_prepare(struct thr_info *thr)
struct cgpu_info *bitmain = thr->cgpu;
struct bitmain_info *info = bitmain->device_data;
- free(bitmain->works);
- bitmain->works = calloc(BITMAIN_MAX_WORK_NUM * sizeof(struct work *),
- BITMAIN_ARRAY_SIZE);
- if (!bitmain->works)
- quit(1, "Failed to calloc bitmain works in bitmain_prepare");
-
info->thr = thr;
mutex_init(&info->lock);
mutex_init(&info->qlock);
@@ -1104,7 +1187,8 @@ static int bitmain_initialize(struct cgpu_info *bitmain)
/* Send reset, then check for result */
if (!bitmain) {
- applog(LOG_WARNING, "bitmain_initialize cgpu_info is null");
+ applog(LOG_WARNING, "%s%d: %s() cgpu_info is null",
+ bitmain->drv->name, bitmain->device_id, __func__);
return -1;
}
info = bitmain->device_data;
@@ -1114,20 +1198,23 @@ static int bitmain_initialize(struct cgpu_info *bitmain)
BITMAIN_RESET_TIMEOUT, C_BITMAIN_READ);
if (ret > 0) {
if (opt_debug) {
- applog(LOG_DEBUG, "BTM%d Clear Read(%d):", bitmain->device_id, ret);
+ applog(LOG_DEBUG, "%s%d: clear read(%d):",
+ bitmain->drv->name, bitmain->device_id, ret);
hexdump(data, ret);
}
}
sendlen = bitmain_set_rxstatus((struct bitmain_rxstatus_token *)sendbuf, 0, 1, 0, 0);
if (sendlen <= 0) {
- applog(LOG_ERR, "bitmain_initialize bitmain_set_rxstatus error(%d)", sendlen);
+ applog(LOG_ERR, "%s%d: %s() set_rx error(%d)",
+ bitmain->drv->name, bitmain->device_id, __func__, sendlen);
return -1;
}
ret = bitmain_send_data(sendbuf, sendlen, bitmain);
if (unlikely(ret == BTM_SEND_ERROR)) {
- applog(LOG_ERR, "bitmain_initialize bitmain_send_data error");
+ applog(LOG_ERR, "%s%d: %s() send_data error",
+ bitmain->drv->name, bitmain->device_id, __func__);
return -1;
}
while (trycount >= 0) {
@@ -1139,35 +1226,38 @@ static int bitmain_initialize(struct cgpu_info *bitmain)
for (i = 0; i < readlen; i++) {
if (data[i] == 0xa1) {
if (opt_debug) {
- applog(LOG_DEBUG, "%s%d initset: get:",
+ applog(LOG_DEBUG, "%s%d: initset get:",
bitmain->drv->name,
bitmain->device_id);
hexdump(data, readlen);
}
if (data[i+1] > 124) {
- applog(LOG_ERR, "bitmain_initialize rxstatus "
- "datalen=%d error",
- data[i+1]+2);
+ applog(LOG_ERR, "%s%d: %s() rxstatus datalen=%d error",
+ bitmain->drv->name, bitmain->device_id,
+ __func__, data[i+1]+2);
continue;
}
if (readlen-i < data[i+1]+2) {
- applog(LOG_ERR, "bitmain_initialize rxstatus "
- "datalen=%d low",
- data[i+1]+2);
+ applog(LOG_ERR, "%s%d: %s() rxstatus datalen=%d low",
+ bitmain->drv->name, bitmain->device_id,
+ __func__, data[i+1]+2);
continue;
}
if (bitmain_parse_rxstatus(data+i, data[i+1]+2, &rxstatusdata) != 0) {
- applog(LOG_ERR, "bitmain_initialize "
- "bitmain_parse_rxstatus error");
+ applog(LOG_ERR, "%s%d: %s() parse_rxstatus error",
+ bitmain->drv->name, bitmain->device_id,
+ __func__);
continue;
}
info->chain_num = rxstatusdata.chain_num;
info->fifo_space = rxstatusdata.fifo_space;
info->nonce_error = 0;
info->last_nonce_error = 0;
- applog(LOG_ERR, "bitmain_initialize bitmain_parse_rxstatus "
+ applog(LOG_ERR, "%s%d: %s() parse_rxstatus "
"version(%d) chain_num(%d) fifo_space(%d) "
"nonce_error(%d) freq=%d",
+ bitmain->drv->name, bitmain->device_id,
+ __func__,
rxstatusdata.version,
info->chain_num,
info->fifo_space,
@@ -1191,10 +1281,10 @@ static int bitmain_initialize(struct cgpu_info *bitmain)
j++;
}
- applog(LOG_ERR, "bitmain_initialize "
- "bitmain_parse_rxstatus chain(%d) "
+ applog(LOG_ERR, "%s%d: %s() parse_rxstatus chain(%d) "
"asic_num=%d asic_status=%08x-%s",
- i, info->chain_asic_num[i],
+ bitmain->drv->name, bitmain->device_id,
+ __func__, i, info->chain_asic_num[i],
info->chain_asic_status[i],
info->chain_asic_status_t[i]);
}
@@ -1220,7 +1310,8 @@ static int bitmain_initialize(struct cgpu_info *bitmain)
cgtime(&info->last_status_time);
if (statusok) {
- applog(LOG_ERR, "bitmain_initialize start send txconfig");
+ applog(LOG_ERR, "%s%d: %s() set_txconfig",
+ bitmain->drv->name, bitmain->device_id, __func__);
if (opt_bitmain_hwerror)
eft = 1;
else
@@ -1233,18 +1324,22 @@ static int bitmain_initialize(struct cgpu_info *bitmain)
info->frequency, BITMAIN_DEFAULT_VOLTAGE,
0, 0, 0x04, info->reg_data);
if (sendlen <= 0) {
- applog(LOG_ERR, "bitmain_initialize bitmain_set_txconfig error(%d)", sendlen);
+ applog(LOG_ERR, "%s%d: %s() set_txconfig error(%d)",
+ bitmain->drv->name, bitmain->device_id, __func__, sendlen);
return -1;
}
ret = bitmain_send_data(sendbuf, sendlen, bitmain);
if (unlikely(ret == BTM_SEND_ERROR)) {
- applog(LOG_ERR, "bitmain_initialize bitmain_send_data error");
+ applog(LOG_ERR, "%s%d: %s() send_data error",
+ bitmain->drv->name, bitmain->device_id, __func__);
return -1;
}
- applog(LOG_WARNING, "BMM%d: InitSet succeeded", bitmain->device_id);
+ applog(LOG_WARNING, "%s%d: %s() succeeded",
+ bitmain->drv->name, bitmain->device_id, __func__);
} else {
- applog(LOG_WARNING, "BMS%d: InitSet error", bitmain->device_id);
+ applog(LOG_WARNING, "%s%d: %s() failed",
+ bitmain->drv->name, bitmain->device_id, __func__);
return -1;
}
return 0;
@@ -1312,12 +1407,12 @@ static struct cgpu_info *bitmain_detect_one(libusb_device *dev, struct usb_find_
info->temp_history_index = 0;
info->temp_sum = 0;
- info->temp_old = 0;
if (!add_cgpu(bitmain))
goto unshin;
- applog(LOG_ERR, "------bitmain usb detect one------");
+ applog(LOG_ERR, "%s: detected %s%d",
+ ants1_drv.dname, bitmain->drv->name, bitmain->device_id);
ret = bitmain_initialize(bitmain);
if (ret && !configured)
goto unshin;
@@ -1326,10 +1421,14 @@ static struct cgpu_info *bitmain_detect_one(libusb_device *dev, struct usb_find_
info->errorcount = 0;
- applog(LOG_DEBUG, "BitMain Detected: %s "
- "(chain_num=%d asic_num=%d timeout=%d frequency=%d)",
- bitmain->device_path, info->chain_num, info->asic_num, info->timeout,
- info->frequency);
+ info->work_list = k_new_list("Work", sizeof(WITEM), ALLOC_WITEMS, LIMIT_WITEMS, true);
+ info->work_ready = k_new_store(info->work_list);
+
+ applog(LOG_DEBUG, "%s%d: detected %s "
+ "chain_num=%d asic_num=%d timeout=%d frequency=%d",
+ bitmain->drv->name, bitmain->device_id, bitmain->device_path,
+ info->chain_num, info->asic_num, info->timeout,
+ info->frequency);
return bitmain;
@@ -1358,7 +1457,7 @@ static void do_bitmain_close(struct thr_info *thr)
struct bitmain_info *info = bitmain->device_data;
pthread_join(info->read_thr, NULL);
- bitmain_running_reset(bitmain, info);
+ bitmain_running_reset(info);
info->no_matching_work = 0;
@@ -1385,90 +1484,107 @@ static void get_bitmain_statline_before(char *buf, size_t bufsiz, struct cgpu_in
static bool bitmain_fill(struct cgpu_info *bitmain)
{
struct bitmain_info *info = bitmain->device_data;
- int subid, slot;
- struct work *work;
+ int subid;
+ struct work *work, *usework;
bool ret = true;
- int sendret = 0, sendcount = 0, neednum = 0, queuednum = 0, sendnum = 0, sendlen = 0;
+ int sendret = 0, sentcount = 0, neednum = 0, queuednum = 0, sendnum = 0, sendlen = 0;
+ int roll, roll_limit;
uint8_t sendbuf[BITMAIN_SENDBUF_SIZE];
cgtimer_t ts_start;
int senderror = 0;
struct timeval now;
int timediff = 0;
+ K_ITEM *witem;
- applog(LOG_DEBUG, "BTM bitmain_fill start--------");
+ applog(LOG_DEBUG, "%s%d: %s() start",
+ bitmain->drv->name, bitmain->device_id,
+ __func__);
mutex_lock(&info->qlock);
if (info->fifo_space <= 0) {
- applog(LOG_DEBUG, "BTM bitmain_fill fifo space empty--------");
+ applog(LOG_DEBUG, "%s%d: %s() fifo space empty",
+ bitmain->drv->name, bitmain->device_id,
+ __func__);
ret = true;
goto out_unlock;
}
- if (bitmain->queued >= BITMAIN_MAX_WORK_QUEUE_NUM) {
+
+ if (info->queued >= BITMAIN_MAX_WORK_QUEUE_NUM)
ret = true;
- } else {
+ else
ret = false;
- }
+
while (info->fifo_space > 0) {
neednum = info->fifo_space<8?info->fifo_space:8;
- queuednum = bitmain->queued;
- applog(LOG_DEBUG, "BTM: Work task queued(%d) fifo space(%d) needsend(%d)",
+ queuednum = info->queued;
+ applog(LOG_DEBUG, "%s%d: Work task queued(%d) fifo space(%d) needsend(%d)",
+ bitmain->drv->name, bitmain->device_id,
queuednum, info->fifo_space, neednum);
- if (queuednum < neednum) {
- while (true) {
- work = get_queued(bitmain);
- if (unlikely(!work)) {
- break;
- } else {
- applog(LOG_DEBUG, "BTM get work queued number:%d neednum:%d",
+ while (queuednum < neednum) {
+ work = get_queued(bitmain);
+ if (!work)
+ break;
+ else {
+ roll_limit = work->drv_rolllimit;
+ roll = 0;
+ while (queuednum < neednum && roll <= roll_limit) {
+ applog(LOG_DEBUG, "%s%d: get work queued number:%d"
+ " neednum:%d",
+ bitmain->drv->name,
+ bitmain->device_id,
queuednum, neednum);
- subid = bitmain->queued++;
- work->subid = subid;
- slot = bitmain->work_array + subid;
- if (slot > BITMAIN_ARRAY_SIZE) {
- applog(LOG_DEBUG, "bitmain_fill array cyc %d",
- BITMAIN_ARRAY_SIZE);
- slot = 0;
+
+ // Using devflag to say if it was rolled
+ if (roll == 0) {
+ usework = work;
+ usework->devflag = false;
+ } else {
+ usework = copy_work_noffset(work, roll);
+ usework->devflag = true;
}
- if (likely(bitmain->works[slot])) {
- applog(LOG_DEBUG, "bitmain_fill work_completed %d",
- slot);
- work_completed(bitmain, bitmain->works[slot]);
+
+ subid = info->queued++;
+ usework->subid = subid;
+ witem = k_unlink_tail(info->work_list);
+ if (DATAW(witem)->work) {
+ // Was it rolled?
+ if (DATAW(witem)->work->devflag)
+ free_work(DATAW(witem)->work);
+ else
+ work_completed(bitmain, DATAW(witem)->work);
}
- bitmain->works[slot] = work;
+ DATAW(witem)->work = usework;
+ k_add_tail(info->work_ready, witem);
queuednum++;
- if (queuednum >= neednum) {
- break;
- }
+ roll++;
}
}
}
if (queuednum < BITMAIN_MAX_DEAL_QUEUE_NUM) {
if (queuednum < neednum) {
- applog(LOG_DEBUG, "BTM: No enough work to send, queue num=%d",
+ applog(LOG_DEBUG, "%s%d: Not enough work to send, queue num=%d",
+ bitmain->drv->name, bitmain->device_id,
queuednum);
break;
}
}
sendnum = queuednum < neednum ? queuednum : neednum;
- sendlen = bitmain_set_txtask(sendbuf, &(info->last_work_block), bitmain->works,
- BITMAIN_ARRAY_SIZE, bitmain->work_array, sendnum,
- &sendcount);
- bitmain->queued -= sendnum;
+ sendlen = bitmain_set_txtask(info, sendbuf, &(info->last_work_block), &sentcount);
+ info->queued -= sendnum;
info->send_full_space += sendnum;
- if (bitmain->queued < 0)
- bitmain->queued = 0;
- if (bitmain->work_array + sendnum > BITMAIN_ARRAY_SIZE) {
- bitmain->work_array = bitmain->work_array + sendnum-BITMAIN_ARRAY_SIZE;
- } else {
- bitmain->work_array += sendnum;
- }
- applog(LOG_DEBUG, "BTM: Send work array %d", bitmain->work_array);
+ if (info->queued < 0)
+ info->queued = 0;
+
+ applog(LOG_DEBUG, "%s%d: Send work %d",
+ bitmain->drv->name, bitmain->device_id,
+ sentcount);
if (sendlen > 0) {
- info->fifo_space -= sendcount;
+ info->fifo_space -= sentcount;
if (info->fifo_space < 0)
info->fifo_space = 0;
sendret = bitmain_send_data(sendbuf, sendlen, bitmain);
if (unlikely(sendret == BTM_SEND_ERROR)) {
- applog(LOG_ERR, "BTM%i: Comms error(buffer)", bitmain->device_id);
+ applog(LOG_ERR, "%s%d: send work comms error",
+ bitmain->drv->name, bitmain->device_id);
//dev_error(bitmain, REASON_DEV_COMMS_ERROR);
info->reset = true;
info->errorcount++;
@@ -1482,11 +1598,15 @@ static bool bitmain_fill(struct cgpu_info *bitmain)
}
break;
} else {
- applog(LOG_DEBUG, "bitmain_send_data send ret=%d", sendret);
+ applog(LOG_DEBUG, "%s%d: send_data ret=%d",
+ bitmain->drv->name, bitmain->device_id,
+ sendret);
info->errorcount = 0;
}
} else {
- applog(LOG_DEBUG, "BTM: Send work bitmain_set_txtask error: %d", sendlen);
+ applog(LOG_DEBUG, "%s%d: Send work set_txtask error: %d",
+ bitmain->drv->name, bitmain->device_id,
+ sendlen);
break;
}
}
@@ -1497,15 +1617,17 @@ out_unlock:
if (timediff < 0) timediff = -timediff;
if (now.tv_sec - info->last_status_time.tv_sec > BITMAIN_SEND_STATUS_TIME) {
- applog(LOG_DEBUG, "BTM: Send RX Status Token fifo_space(%d) timediff(%d)",
- info->fifo_space, timediff);
+ applog(LOG_DEBUG, "%s%d: Send RX Status Token fifo_space(%d) timediff(%d)",
+ bitmain->drv->name, bitmain->device_id,
+ info->fifo_space, timediff);
copy_time(&(info->last_status_time), &now);
sendlen = bitmain_set_rxstatus((struct bitmain_rxstatus_token *) sendbuf, 0, 0, 0, 0);
if (sendlen > 0) {
sendret = bitmain_send_data(sendbuf, sendlen, bitmain);
if (unlikely(sendret == BTM_SEND_ERROR)) {
- applog(LOG_ERR, "BTM%i: Comms error(buffer)", bitmain->device_id);
+ applog(LOG_ERR, "%s%d: send status comms error",
+ bitmain->drv->name, bitmain->device_id);
//dev_error(bitmain, REASON_DEV_COMMS_ERROR);
info->reset = true;
info->errorcount++;
@@ -1555,25 +1677,25 @@ static int64_t bitmain_scanhash(struct thr_info *thr)
mutex_lock(&info->qlock);
hash_count = 0xffffffffull * (uint64_t)info->nonces;
- bitmain->results += info->nonces + info->idle;
- if (bitmain->results > chain_num)
- bitmain->results = chain_num;
+ info->results += info->nonces + info->idle;
+ if (info->results > chain_num)
+ info->results = chain_num;
if (!info->reset)
- bitmain->results--;
+ info->results--;
info->nonces = info->idle = 0;
mutex_unlock(&info->qlock);
/* Check for nothing but consecutive bad results or consistently less
* results than we should be getting and reset the FPGA if necessary */
- //if (bitmain->results < -chain_num && !info->reset) {
- // applog(LOG_ERR, "BTM%d: Result return rate low, resetting!",
- // bitmain->device_id);
+ //if (info->results < -chain_num && !info->reset) {
+ // applog(LOG_ERR, "%s%d: Result return rate low, resetting!",
+ // bitmain->drv->name, bitmain->device_id);
// info->reset = true;
//}
if (unlikely(bitmain->usbinfo.nodev)) {
- applog(LOG_ERR, "BTM%d: Device disappeared, shutting down thread",
- bitmain->device_id);
+ applog(LOG_ERR, "%s%d: Device disappeared, shutting down thread",
+ bitmain->drv->name, bitmain->device_id);
bitmain->shutdown = true;
}
@@ -1587,20 +1709,11 @@ static void bitmain_flush_work(struct cgpu_info *bitmain)
//int i = 0;
mutex_lock(&info->qlock);
+ applog(LOG_ERR, "%s%d: %s() queued=%d",
+ bitmain->drv->name, bitmain->device_id,
+ __func__, info->queued);
/* Will overwrite any work queued */
- applog(LOG_ERR, "bitmain_flush_work queued=%d array=%d", bitmain->queued, bitmain->work_array);
- if (bitmain->queued > 0) {
- if (bitmain->work_array + bitmain->queued > BITMAIN_ARRAY_SIZE) {
- bitmain->work_array = bitmain->work_array + bitmain->queued-BITMAIN_ARRAY_SIZE;
- } else {
- bitmain->work_array += bitmain->queued;
- }
- }
- bitmain->queued = 0;
- //bitmain->work_array = 0;
- //for (i = 0; i < BITMAIN_ARRAY_SIZE; i++) {
- // bitmain->works[i] = NULL;
- //}
+ info->queued = 0;
//pthread_cond_signal(&info->qcond);
mutex_unlock(&info->qlock);
}
@@ -1648,7 +1761,6 @@ static struct api_data *bitmain_api_stats(struct cgpu_info *cgpu)
root = api_add_int(root, "chain_acn3", &(info->chain_asic_num[2]), false);
root = api_add_int(root, "chain_acn4", &(info->chain_asic_num[3]), false);
- //applog(LOG_ERR, "chain asic status:%s", info->chain_asic_status_t[0]);
root = api_add_string(root, "chain_acs1", info->chain_asic_status_t[0], false);
root = api_add_string(root, "chain_acs2", info->chain_asic_status_t[1], false);
root = api_add_string(root, "chain_acs3", info->chain_asic_status_t[2], false);
@@ -1659,6 +1771,22 @@ static struct api_data *bitmain_api_stats(struct cgpu_info *cgpu)
//root = api_add_int(root, "chain_acs3", &(info->chain_asic_status[2]), false);
//root = api_add_int(root, "chain_acs4", &(info->chain_asic_status[3]), false);
+ root = api_add_int(root, "work_list_total", &(info->work_list->total), true);
+ root = api_add_int(root, "work_list_count", &(info->work_list->count), true);
+ root = api_add_int(root, "work_ready_count", &(info->work_ready->count), true);
+ root = api_add_uint64(root, "work_search", &(info->work_search), true);
+ root = api_add_uint64(root, "min_search", &(info->min_search), true);
+ root = api_add_uint64(root, "max_search", &(info->max_search), true);
+ float avg = info->work_search ? (float)(info->tot_search) /
+ (float)(info->work_search) : 0;
+ root = api_add_avg(root, "avg_search", &avg, true);
+ root = api_add_uint64(root, "failed_search", &(info->failed_search), true);
+ root = api_add_uint64(root, "min_failed", &(info->min_failed), true);
+ root = api_add_uint64(root, "max_failed", &(info->max_failed), true);
+ avg = info->failed_search ? (float)(info->tot_failed) /
+ (float)(info->failed_search) : 0;
+ root = api_add_avg(root, "avg_failed", &avg, true);
+
return root;
}
diff --git a/driver-bitmain.h b/driver-bitmain.h
index febbf4b..605fdd9 100644
--- a/driver-bitmain.h
+++ b/driver-bitmain.h
@@ -15,6 +15,7 @@
#ifdef USE_ANT_S1
#include "util.h"
+#include "klist.h"
#define BITMAIN_RESET_FAULT_DECISECONDS 1
#define BITMAIN_MINER_THREADS 1
@@ -165,6 +166,9 @@ struct bitmain_rxnonce_data {
} __attribute__((packed, aligned(4)));
struct bitmain_info {
+ int queued;
+ int results;
+
int baud;
int chain_num;
int asic_num;
@@ -187,7 +191,6 @@ struct bitmain_info {
int temp_history_count;
int temp_history_index;
int temp_sum;
- int temp_old;
int fan_pwm;
int frequency;
@@ -216,10 +219,38 @@ struct bitmain_info {
bool reset;
bool overheat;
bool optimal;
+
+ // Work
+ K_LIST *work_list;
+ K_STORE *work_ready;
+
+ uint64_t work_search;
+ uint64_t tot_search;
+ uint64_t min_search;
+ uint64_t max_search;
+
+ uint64_t failed_search;
+ uint64_t tot_failed;
+ uint64_t min_failed;
+ uint64_t max_failed;
};
+// Work
+typedef struct witem {
+ struct work *work;
+ bool clone;
+} WITEM;
+
+#define ALLOC_WITEMS 1024
+/*
+ * The limit doesn't matter since we simply take the tail item
+ * every time, optionally free it, and then put it on the head
+ */
+#define LIMIT_WITEMS 1024
+
+#define DATAW(_item) ((WITEM *)(_item->data))
+
#define BITMAIN_READ_SIZE 12
-#define BITMAIN_ARRAY_SIZE 2048
#define BTM_GETS_ERROR -1
#define BTM_GETS_OK 0
diff --git a/miner.h b/miner.h
index 5507564..f557b0d 100644
--- a/miner.h
+++ b/miner.h
@@ -431,7 +431,7 @@ struct cgpu_info {
struct cg_usb_info usbinfo;
bool blacklisted;
#endif
-#if defined(USE_AVALON) || defined(USE_AVALON2) || defined(USE_ANT_S1)
+#if defined(USE_AVALON) || defined(USE_AVALON2)
struct work **works;
int work_array;
int queued;