Branch
Hash :
6f01253b
Author :
Date :
2017-01-26T13:30:45
merge with cgminer rev 87e3da18638275d2b5adbd0ccd0a17225793bf8f code refactoring: - Con Colivas notes - whitespace nitts - unused parameters removed - compiler warnings removed
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 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677
#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);
if (info->chipboard[board_id].detected == true) {
applog(LOG_NOTICE, "%s: BOARD%d detected", bitfury->drv->name, board_id + 1);
info->chipboard[board_id].bcm250 = cgcalloc(BCM250_NUM, sizeof(bf_bcm250_t));
cmd_buffer_init(&info->chipboard[board_id].cmd_buffer);
get_board_info(bitfury, board_id);
update_bcm250_map(bitfury, board_id);
info->chipboard_num++;
info->chipboard[board_id].bcm250_num = BCM250_NUM;
cg_memcpy(&info->chipboard[board_id].pid, &pid, sizeof(bf_pid_t));
uint8_t chips_num = 0;
for (bcm250_id = 0; bcm250_id < BCM250_NUM; bcm250_id++) {
info->chipboard[board_id].bcm250[bcm250_id].channel_path = init_channel_path(board_id, bcm250_id,
&info->chipboard[board_id].bcm250[bcm250_id].channel_depth, info->channel_length);
info->chipboard[board_id].bcm250[bcm250_id].first_good_chip = bcm250_map[board_id][bcm250_id].first_good_chip;
info->chipboard[board_id].bcm250[bcm250_id].last_good_chip = bcm250_map[board_id][bcm250_id].last_good_chip;
info->chipboard[board_id].bcm250[bcm250_id].chips_num = bcm250_map[board_id][bcm250_id].chips_num;
chips_num += bcm250_map[board_id][bcm250_id].chips_num;
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++) {
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].nonce_list = nonce_list_init();
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);
}
}
info->chipboard[board_id].chips_num = chips_num;
info->chips_num += info->chipboard[board_id].chips_num;
} else
applog(LOG_NOTICE, "%s: BOARD%d not found", bitfury->drv->name, board_id + 1);
applog(LOG_INFO, "%s: initialized board X5.%d", bitfury->drv->name, board_id);
}
applog(LOG_INFO, "%s: initialized X5", bitfury->drv->name);
}
static void deinit_x5(struct cgpu_info *bitfury)
{
uint8_t board_id, bcm250_id, chip_id;
struct bitfury16_info *info = (struct bitfury16_info *)(bitfury->device_data);
workd_list_deinit(info->work_list, bitfury);
workd_list_deinit(info->stale_work_list, bitfury);
noncework_list_deinit(info->noncework_list);
if (opt_bf16_renonce != RENONCE_DISABLED) {
renoncework_list_deinit(info->renoncework_list);
info->renonce_id = 1;
renonce_list_deinit(info->renonce_list);
}
for (board_id = 0; board_id < CHIPBOARD_NUM; board_id++) {
for (bcm250_id = 0; bcm250_id < BCM250_NUM; bcm250_id++) {
free(info->chipboard[board_id].bcm250[bcm250_id].channel_path);
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++)
nonce_list_deinit(info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].nonce_list);
}
free(info->chipboard[board_id].bcm250);
cmd_buffer_deinit(&info->chipboard[board_id].cmd_buffer);
}
free(info->chipboard);
}
static void bitfury16_set_clock(struct cgpu_info *bitfury)
{
uint8_t board_id, bcm250_id, chip_id;
struct bitfury16_info *info = (struct bitfury16_info *)bitfury->device_data;
/* send reset to all boards */
spi_emit_reset(SPI_CHANNEL1);
spi_emit_reset(SPI_CHANNEL2);
/* board loop */
for (board_id = 0; board_id < CHIPBOARD_NUM; board_id++) {
applog(LOG_NOTICE, "%s: CHIPBOARD [%d]:", bitfury->drv->name, board_id);
/* concentrator loop */
for (bcm250_id = 0; bcm250_id < BCM250_NUM; bcm250_id++) {
applog(LOG_NOTICE, "%s: BCM250 [%d]:", bitfury->drv->name, bcm250_id);
spi_emit_reset(board_id + 1);
/* build channel */
create_channel(board_id + 1, info->chipboard[board_id].bcm250[bcm250_id].channel_path, info->channel_length);
uint8_t channel_depth = info->chipboard[board_id].bcm250[bcm250_id].channel_depth;
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;
uint8_t result;
bool fail;
/* chips loop */
for (chip_id = first_good_chip; chip_id < last_good_chip; chip_id++) {
fail = false;
bf_chip_address_t chip_address = { board_id, bcm250_id, chip_id };
result = send_toggle(board_id + 1, channel_depth, chip_address);
if (result != 0)
fail = true;
result = set_clock(board_id + 1, channel_depth, chip_address, bf16_chip_clock);
if ((result != 0) && (fail != true))
fail = true;
if (fail == false)
applog(LOG_NOTICE, "%s: CHIP [%2d]: OK", bitfury->drv->name, chip_id);
else
applog(LOG_NOTICE, "%s: CHIP [%2d]: FAIL", bitfury->drv->name, chip_id);
}
/* destroy channel */
destroy_channel(board_id + 1, info->chipboard[board_id].bcm250[bcm250_id].channel_depth);
}
}
deinit_x5(bitfury);
}
static void bitfury16_test_chip(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;
/* send reset to board */
spi_emit_reset(board_id + 1);
/* build channel */
create_channel(board_id + 1, info->chipboard[board_id].bcm250[bcm250_id].channel_path, info->channel_length);
uint8_t channel_depth = info->chipboard[board_id].bcm250[bcm250_id].channel_depth;
uint8_t result;
bool fail = false;
result = send_toggle(board_id + 1, channel_depth, chip_address);
if (result != 0)
fail = true;
result = set_clock(board_id + 1, channel_depth, chip_address, bf16_chip_clock);
if ((result != 0) && (fail != true))
fail = true;
if (fail == false)
applog(LOG_NOTICE, "%s: CHIP [%2d]: OK", bitfury->drv->name, chip_id);
else
applog(LOG_NOTICE, "%s: CHIP [%2d]: FAIL", bitfury->drv->name, chip_id);
/* destroy channel */
destroy_channel(board_id + 1, info->chipboard[board_id].bcm250[bcm250_id].channel_depth);
deinit_x5(bitfury);
}
static void bitfury16_identify(__maybe_unused struct cgpu_info *bitfury)
{
}
static void set_fan_speed(struct cgpu_info *bitfury)
{
struct bitfury16_info *info = (struct bitfury16_info *)bitfury->device_data;
uint8_t board_id;
for (board_id = 0; board_id < CHIPBOARD_NUM; board_id++) {
if (info->chipboard[board_id].detected == true) {
if (opt_bf16_fan_speed == -1) {
if (device_uart_transfer(board_id + 1, "F") < 0)
quit(1, "%s: %s() failed to set BOARD%d fan speed",
bitfury->drv->name, __func__, board_id + 1);
applog(LOG_INFO, "%s: set BOARD%d fan speed to auto mode",
bitfury->drv->name, board_id + 1);
} else {
char uart_cmd[8];
sprintf(uart_cmd, "F:%d", opt_bf16_fan_speed);
if (device_uart_transfer(board_id + 1, uart_cmd) < 0)
quit(1, "%s: %s() failed to set BOARD%d fan speed",
bitfury->drv->name, __func__, board_id + 1);
applog(LOG_INFO, "%s: set BOARD%d fan speed to [%d]",
bitfury->drv->name, board_id + 1, opt_bf16_fan_speed);
}
}
}
}
static void bitfury16_detect(bool hotplug)
{
struct cgpu_info *bitfury = NULL;
struct bitfury16_info *info = NULL;
uint8_t board_id, bcm250_id, chip_id;
if (hotplug)
return;
bitfury = cgmalloc(sizeof(struct cgpu_info));
if (unlikely(!bitfury))
quit(1, "%s: %s() failed to malloc bitfury",
bitfury->drv->name, __func__);
bitfury->drv = &bitfury16_drv;
bitfury->deven = DEV_ENABLED;
bitfury->threads = 1;
info = cgmalloc(sizeof(struct bitfury16_info));
if (unlikely(!info))
quit(1, "%s: %s() failed to malloc info",
bitfury->drv->name, __func__);
bitfury->device_data = info;
/* manual PID option */
#ifdef MINER_X5
manual_pid_enabled = opt_bf16_manual_pid_enabled;
#endif
#ifdef MINER_X6
manual_pid_enabled = !opt_bf16_manual_pid_disabled;
#endif
/* renonce chip address and renonce chip clock */
if (opt_bf16_renonce != RENONCE_DISABLED) {
if (opt_bf16_renonce_clock != NULL)
bf16_renonce_chip_clock = strtol(opt_bf16_renonce_clock, NULL, 16);
} else
/* default chip clock if renonce is disabled */
bf16_chip_clock = 0x2d;
/* general chip clock */
if (opt_bf16_clock != NULL)
bf16_chip_clock = strtol(opt_bf16_clock, NULL, 16);
else if ((opt_bf16_set_clock == true) || (opt_bf16_test_chip != NULL))
/* default chip clock if set_clock option is set */
bf16_chip_clock = 0x20;
/* open devices */
if (open_spi_device(SPI_CHANNEL1) < 0)
quit(1, "%s: %s() failed to open [%s] device",
bitfury->drv->name, __func__, spi0_device_name);
applog(LOG_INFO, "%s: opened [%s] device", bitfury->drv->name, spi0_device_name);
if (open_spi_device(SPI_CHANNEL2) < 0)
quit(1, "%s: %s() failed to open [%s] device",
bitfury->drv->name, __func__, spi1_device_name);
applog(LOG_INFO, "%s: opened [%s] device", bitfury->drv->name, spi1_device_name);
if (open_ctrl_device() < 0)
quit(1, "%s: %s() failed to open [%s] device",
bitfury->drv->name, __func__, ctrl_device_name);
applog(LOG_INFO, "%s: opened [%s] device", bitfury->drv->name, ctrl_device_name);
if (open_uart_device(UART_CHANNEL1) < 0)
quit(1, "%s: %s() failed to open [%s] device",
bitfury->drv->name, __func__, uart1_device_name);
applog(LOG_INFO, "%s: opened [%s] device", bitfury->drv->name, uart1_device_name);
if (open_uart_device(UART_CHANNEL2) < 0)
quit(1, "%s: %s() failed to open [%s] device",
bitfury->drv->name, __func__, uart2_device_name);
applog(LOG_INFO, "%s: opened [%s] device", bitfury->drv->name, uart2_device_name);
init_x5(bitfury);
/* send reset to boards */
for (board_id = 0; board_id < CHIPBOARD_NUM; board_id++) {
if (info->chipboard[board_id].detected == true) {
device_ctrl_transfer(board_id + 1, 1, F_BRST);
cgsleep_us(POWER_WAIT_INTERVAL);
device_ctrl_transfer(board_id + 1, 0, F_BRST);
cgsleep_us(POWER_WAIT_INTERVAL);
applog(LOG_INFO, "%s: sent reset to BOARD%d",
bitfury->drv->name, board_id + 1);
}
}
/* check if board power is present */
for (board_id = 0; board_id < CHIPBOARD_NUM; board_id++) {
/* read hw sensor data */
char buff[256];
if (info->chipboard[board_id].detected == true) {
memset(buff, 0, sizeof(buff));
if (device_uart_txrx(board_id + 1, "S", buff) < 0)
quit(1, "%s: %s() failed to get BOARD%d status",
bitfury->drv->name, __func__, board_id + 1);
if (parse_hwstats(info, board_id, buff) < 0)
applog(LOG_ERR, "%s: failed to parse hw stats",
bitfury->drv->name);
/* disable board if power voltage is incorrect */
if ((info->chipboard[board_id].u_board < 10.0) ||
(info->chipboard[board_id].u_board > 15.0)) {
/* concentrator loop */
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;
/* chips loop */
for (chip_id = first_good_chip; chip_id < last_good_chip; chip_id++)
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status = DISABLED;
}
applog(LOG_ERR, "%s: incorrect U board detected [%.1f] on BOARD%d, "
"disabling board...",
bitfury->drv->name,
info->chipboard[board_id].u_board,
board_id + 1);
} else {
info->chipboard[board_id].active = true;
info->active_chipboard_num++;
}
}
}
/* enable power chain */
for (board_id = 0; board_id < CHIPBOARD_NUM; board_id++) {
if (enable_power_chain(bitfury, board_id, 0) < 0)
info->chipboard[board_id].detected = false;
else {
#ifdef MINER_X5
info->chipboard[board_id].power_enable_time = time(NULL);
info->chipboard[board_id].power_disable_count = 1;
#endif
#ifdef MINER_X6
info->chipboard[board_id].power1_enable_time = time(NULL);
info->chipboard[board_id].power2_enable_time = time(NULL);
info->chipboard[board_id].power1_disable_count = 1;
info->chipboard[board_id].power2_disable_count = 1;
#endif
}
}
/* wait for power chain to enable */
cgsleep_us(POWER_WAIT_INTERVAL);
if (opt_bf16_set_clock == true) {
applog(LOG_INFO, "%s: setting clock [%02x] to all chips",
bitfury->drv->name, bf16_chip_clock);
bitfury16_set_clock(bitfury);
quit(0, "Done.");
}
if (opt_bf16_test_chip != NULL) {
bf_chip_address_t chip_address = { 0, 0, 0 };
if (parse_chip_address(bitfury, opt_bf16_test_chip, &chip_address) < 0) {
quit(1, "%s: %s() error parsing chip address...",
bitfury->drv->name, __func__);
}
applog(LOG_INFO, "%s: testing communicaton with chip [%d:%d:%2d]",
bitfury->drv->name,
chip_address.board_id,
chip_address.bcm250_id,
chip_address.chip_id);
bitfury16_test_chip(bitfury, chip_address);
quit(0, "Done.");
}
/* fan speed */
if ((opt_bf16_fan_speed != -1) &&
(manual_pid_enabled == true)) {
manual_pid_enabled = false;
}
set_fan_speed(bitfury);
for (board_id = 0; board_id < CHIPBOARD_NUM; board_id++) {
if (info->chipboard[board_id].detected == true) {
/* target temp */
if (opt_bf16_target_temp == -1) {
if (device_uart_transfer(board_id + 1, "T") < 0)
quit(1, "%s: %s() failed to set BOARD%d target temp",
bitfury->drv->name, __func__, board_id + 1);
applog(LOG_INFO, "%s: set BOARD%d target temp to default value",
bitfury->drv->name, board_id + 1);
} else {
char uart_cmd[8];
sprintf(uart_cmd, "T:%d", opt_bf16_target_temp);
if (device_uart_transfer(board_id + 1, uart_cmd) < 0)
quit(1, "%s: %s() failed to set BOARD%d target temp",
bitfury->drv->name, __func__, board_id + 1);
applog(LOG_INFO, "%s: set BOARD%d target temp to [%d]",
bitfury->drv->name, board_id + 1, opt_bf16_target_temp);
}
/* alarm temp */
if (opt_bf16_alarm_temp == -1) {
if (device_uart_transfer(board_id + 1, "C") < 0)
quit(1, "%s: %s() failed to set BOARD%d alarm temp",
bitfury->drv->name, __func__, board_id + 1);
applog(LOG_INFO, "%s: set BOARD%d alarm temp to default value",
bitfury->drv->name, board_id + 1);
} else {
char uart_cmd[8];
sprintf(uart_cmd, "C:%d", opt_bf16_alarm_temp);
if (device_uart_transfer(board_id + 1, uart_cmd) < 0)
quit(1, "%s: %s() failed to set BOARD%d alarm temp",
bitfury->drv->name, __func__, board_id + 1);
applog(LOG_INFO, "%s: set BOARD%d alarm temp to [%d]",
bitfury->drv->name, board_id + 1, opt_bf16_alarm_temp);
}
}
}
/* count number of renonce chips */
if (opt_bf16_renonce != RENONCE_DISABLED) {
info->renonce_chips = opt_bf16_renonce;
uint8_t renonce_chips = 0;
for (board_id = 0; board_id < CHIPBOARD_NUM; board_id++) {
if ((info->chipboard[board_id].detected == true) &&
(info->chipboard[board_id].active == true)) {
if (opt_bf16_renonce == RENONCE_ONE_CHIP) {
if (renonce_chips != info->renonce_chips)
renonce_chips++;
else {
renonce_chip_address[board_id].board_id = -1;
renonce_chip_address[board_id].bcm250_id = -1;
renonce_chip_address[board_id].chip_id = -1;
}
} else
renonce_chips++;
} else {
renonce_chip_address[board_id].board_id = -1;
renonce_chip_address[board_id].bcm250_id = -1;
renonce_chip_address[board_id].chip_id = -1;
}
}
if (renonce_chips != info->renonce_chips) {
applog(LOG_ERR, "%s: expected to find [%d] renonce chips, but found only [%d]",
bitfury->drv->name, opt_bf16_renonce, renonce_chips);
info->renonce_chips = renonce_chips;
}
} else {
for (board_id = 0; board_id < CHIPBOARD_NUM; board_id++) {
renonce_chip_address[board_id].board_id = -1;
renonce_chip_address[board_id].bcm250_id = -1;
renonce_chip_address[board_id].chip_id = -1;
}
}
/* correct renonce chip address */
if (opt_bf16_renonce != RENONCE_DISABLED) {
for (board_id = 0; board_id < CHIPBOARD_NUM; board_id++) {
if ((info->chipboard[board_id].detected == true) &&
(info->chipboard[board_id].active == true) &&
(renonce_chip_address[board_id].board_id != -1)) {
bcm250_id = renonce_chip_address[board_id].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;
if (renonce_chip_address[board_id].chip_id >= last_good_chip)
renonce_chip_address[board_id].chip_id = last_good_chip - 1;
else if (renonce_chip_address[board_id].chip_id < first_good_chip)
renonce_chip_address[board_id].chip_id = first_good_chip;
}
}
}
#ifdef FILELOG
info->logfile = fopen(LOGFILE, "a");
if (info->logfile == NULL)
applog(LOG_ERR, "%s: failed to open logfile [%s]: %s",
bitfury->drv->name, LOGFILE, strerror(errno));
else
mutex_init(&info->logfile_mutex);
#endif
/* exit if no boards present */
if ((info->chipboard_num == 0) ||
(info->active_chipboard_num == 0)) {
deinit_x5(bitfury);
/* close devices */
close_spi_device(SPI_CHANNEL1);
close_spi_device(SPI_CHANNEL2);
close_ctrl_device();
close_uart_device(UART_CHANNEL1);
close_uart_device(UART_CHANNEL2);
#ifdef FILELOG
fclose(info->logfile);
#endif
applog(LOG_ERR, "%s: no boards present. exiting...",
bitfury->drv->name);
free(info);
free(bitfury);
return;
}
mutex_init(&info->nonces_good_lock);
if (!add_cgpu(bitfury))
quit(1, "%s: %s() failed to add_cgpu",
bitfury->drv->name, __func__);
info->initialised = true;
applog(LOG_INFO, "%s: chip driver initialized", bitfury->drv->name);
#ifdef FILELOG
filelog(info, "%s: cgminer started", bitfury->drv->name);
#endif
}
static uint8_t chip_task_update(struct cgpu_info *bitfury, bf_chip_address_t chip_address)
{
uint8_t i;
int8_t ret = 0;
bf_works_t work;
time_t curr_time_t;
struct timeval curr_time;
uint8_t board_id = chip_address.board_id;
uint8_t bcm250_id = chip_address.bcm250_id;
uint8_t chip_id = chip_address.chip_id;
struct bitfury16_info *info = (struct bitfury16_info *)(bitfury->device_data);
bf_cmd_buffer_t* cmd_buffer = &info->chipboard[board_id].cmd_buffer;
if (cmd_buffer->status != EMPTY)
return -1;
switch (info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status) {
/* fill chip buffer with toggle task */
case UNINITIALIZED:
applog(LOG_DEBUG, "%s: chipworker_thr: chip [%d:%d:%2d], prepare toggle_cmd",
bitfury->drv->name,
board_id, bcm250_id, chip_id);
uint8_t toggle[4] = { 0xa5, 0x00, 0x00, 0x02 };
ret = cmd_buffer_push(cmd_buffer,
info->chipboard[board_id].bcm250[bcm250_id].channel_depth, chip_address, chip_address,
work, 0, CHIP_CMD_TOGGLE, 3, toggle);
if (ret < 0)
applog(LOG_ERR, "%s: chipworker_thr: chip [%d:%d:%2d], error prepare toggle_cmd",
bitfury->drv->name,
board_id, bcm250_id, chip_id);
break;
/* fill chip buffer with set clock task */
case TOGGLE_SET:
applog(LOG_DEBUG, "%s: chipworker_thr: chip [%d:%d:%2d], prepare set_clock_cmd",
bitfury->drv->name,
board_id, bcm250_id, chip_id);
uint8_t clock_buf[4];
memset(clock_buf, 0, sizeof(clock_buf));
/* init renonce chip with lower clock */
if ((renonce_chip(chip_address) == 1) &&
(opt_bf16_renonce != RENONCE_DISABLED)) {
gen_clock_data(bf16_renonce_chip_clock, 1, clock_buf);
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].clock = bf16_renonce_chip_clock;
} else {
gen_clock_data(bf16_chip_clock, 1, clock_buf);
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].clock = bf16_chip_clock;
}
ret = cmd_buffer_push(cmd_buffer,
info->chipboard[board_id].bcm250[bcm250_id].channel_depth, chip_address, chip_address,
work, 0, CHIP_CMD_SET_CLOCK, 3, clock_buf);
if (ret < 0)
applog(LOG_ERR, "%s: chipworker_thr: chip [%d:%d:%2d], error prepare set_clock_cmd",
bitfury->drv->name,
board_id, bcm250_id, chip_id);
break;
/* fill chip buffer with chip mask */
case CLOCK_SET:
applog(LOG_DEBUG, "%s: chipworker_thr: chip [%d:%d:%2d], prepare set_mask_cmd",
bitfury->drv->name,
board_id, bcm250_id, chip_id);
uint8_t noncemask[4];
memset(noncemask, 0, sizeof(noncemask));
for (i = 0; i < 4; i++)
noncemask[i] = (mask >> (8*(4 - i - 1))) & 0xff;
ret = cmd_buffer_push(cmd_buffer,
info->chipboard[board_id].bcm250[bcm250_id].channel_depth, chip_address, chip_address,
work, 0, CHIP_CMD_SET_MASK, 3, noncemask);
if (ret < 0)
applog(LOG_ERR, "%s: chipworker_thr: chip [%d:%d:%2d], error prepare set_mask_cmd",
bitfury->drv->name,
board_id, bcm250_id, chip_id);
break;
/* fill chip buffer with new task */
case MASK_SET:
if ((renonce_chip(chip_address) == 0) ||
(opt_bf16_renonce == RENONCE_DISABLED)) {
applog(LOG_DEBUG, "%s: chipworker_thr: chip [%d:%d:%2d], prepare send_task_cmd",
bitfury->drv->name,
board_id, bcm250_id, chip_id);
L_LOCK(info->work_list);
L_LOCK(info->stale_work_list);
if (info->work_list->count > 0) {
memset(info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].cwork.task, 0,
sizeof(info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].cwork.task));
bf_data_t* wdata = info->work_list->head;
workd_list_push(info->stale_work_list, WORKD(wdata));
workd_list_remove(info->work_list, &info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].cwork);
gen_task_data(info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].cwork.payload.midstate,
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].cwork.payload.m7,
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].cwork.payload.ntime,
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].cwork.payload.nbits, mask,
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].cwork.task);
ret = cmd_buffer_push(cmd_buffer,
info->chipboard[board_id].bcm250[bcm250_id].channel_depth, chip_address, chip_address,
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].cwork, 0,
CHIP_CMD_TASK_WRITE, 79,
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].cwork.task);
if (ret < 0)
applog(LOG_ERR, "%s: chipworker_thr: chip [%d:%d:%2d], error prepare send_task_cmd",
bitfury->drv->name,
board_id, bcm250_id, chip_id);
}
#if 0
else
applog(LOG_ERR, "%s: chipworker_thr: chip [%d:%d:%2d], error prepare send_task_cmd: no works available",
bitfury->drv->name,
board_id, bcm250_id, chip_id);
#endif
L_UNLOCK(info->stale_work_list);
L_UNLOCK(info->work_list);
}
break;
/* fill chip buffer with check status task */
case TASK_SENT:
gettimeofday(&curr_time, NULL);
if (((renonce_chip(chip_address) == 0) ||
(opt_bf16_renonce == RENONCE_DISABLED)) &&
(timediff_us(info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status_time, curr_time) > CHIP_TASK_STATUS_INTERVAL)) {
applog(LOG_DEBUG, "%s: chipworker_thr: chip [%d:%d:%2d], prepare task_status_cmd",
bitfury->drv->name,
board_id, bcm250_id, chip_id);
ret = cmd_buffer_push(cmd_buffer,
info->chipboard[board_id].bcm250[bcm250_id].channel_depth, chip_address, chip_address,
work, 0, CHIP_CMD_TASK_STATUS, 0, NULL);
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status_time.tv_sec = curr_time.tv_sec;
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status_time.tv_usec = curr_time.tv_usec;
if (ret < 0)
applog(LOG_ERR, "%s: chipworker_thr: chip [%d:%d:%2d], error prepare task_status_cmd",
bitfury->drv->name,
board_id, bcm250_id, chip_id);
}
break;
/* fill chip buffer with read nonces task */
case TASK_SWITCHED:
if ((renonce_chip(chip_address) == 0) ||
(opt_bf16_renonce == RENONCE_DISABLED)) {
applog(LOG_DEBUG, "%s: chipworker_thr: chip [%d:%d:%2d], prepare read_nonce_cmd",
bitfury->drv->name,
board_id, bcm250_id, chip_id);
ret = cmd_buffer_push(cmd_buffer,
info->chipboard[board_id].bcm250[bcm250_id].channel_depth, chip_address, chip_address,
work, 0, CHIP_CMD_READ_NONCE, 0, NULL);
if (ret < 0)
applog(LOG_ERR, "%s: chipworker_thr: chip [%d:%d:%2d], error prepare read_nonce_cmd",
bitfury->drv->name,
board_id, bcm250_id, chip_id);
}
break;
/* mark chip as UNINITIALIZED and start all over again */
case FAILING:
curr_time_t = time(NULL);
time_t time_diff = curr_time_t - info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].last_error_time;
if (info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].recovery_count < CHIP_ERROR_FAIL_LIMIT) {
if (time_diff >= info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].recovery_count * CHIP_RECOVERY_INTERVAL) {
/* change renonce chip address if RENONCE_CHIP_ERROR_FAIL_LIMIT reached */
if ((renonce_chip(chip_address) == 1) &&
(opt_bf16_renonce != RENONCE_DISABLED)) {
if (info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].recovery_count == RENONCE_CHIP_ERROR_FAIL_LIMIT) {
applog(LOG_ERR, "%s: chipworker_thr: renonce chip [%d:%d:%2d] failed. trying to switch to another one...",
bitfury->drv->name,
chip_address.board_id,
chip_address.bcm250_id,
chip_address.chip_id);
if (change_renonce_chip_address(bitfury, chip_address) == 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 = curr_time_t;
gettimeofday(&info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status_time, NULL);
}
} else {
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 = curr_time_t;
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++;
}
} else {
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 = curr_time_t;
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);
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].recovery_count++;
#ifdef FILELOG
filelog(info, "BF16: chip [%d:%d:%2d] recovered time_diff: [%d], "
"recovery_count: [%d], error_rate: [%d]",
board_id, bcm250_id, chip_id,
time_diff,
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].recovery_count,
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].error_rate);
#endif
}
}
}
/* mark chip as DISABLED and never communicate to it again */
else if (info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status != DISABLED) {
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status = DISABLED;
#ifdef FILELOG
filelog(info, "BF16: disabling chip [%d:%d:%2d] recovery_count: [%d], error_rate: [%d]",
board_id, bcm250_id, chip_id,
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].recovery_count,
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].error_rate);
#endif
}
break;
case DISABLED:
default:
break;
}
return ret;
}
static uint8_t renonce_task_update_loop(struct cgpu_info *bitfury, uint8_t board_id,
bf_renonce_stage_t stage, uint8_t renonce_count)
{
struct bitfury16_info *info = (struct bitfury16_info *)(bitfury->device_data);
bf_cmd_buffer_t* cmd_buffer = &info->chipboard[board_id].cmd_buffer;
uint8_t bcm250_id = renonce_chip_address[board_id].bcm250_id;
uint8_t chip_id = renonce_chip_address[board_id].chip_id;
uint8_t nonces = 0;
if (info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status < FAILING) {
L_LOCK(info->renonce_list);
bf_data_t* rdata = info->renonce_list->head;
while ((rdata != NULL) && (nonces < renonce_count)) {
uint8_t ret = 1;
if ((RENONCE(rdata)->sent == false) &&
(RENONCE(rdata)->stage == stage)) {
/* generate work mask */
uint32_t nonce_mask = gen_mask(RENONCE(rdata)->nonce, mask_bits);
nonce_mask = ntohl(nonce_mask);
switch (RENONCE(rdata)->stage) {
case RENONCE_STAGE0:
case RENONCE_STAGE2:
/* generate chip work with new mask */
cg_memcpy(RENONCE(rdata)->owork.task + 19*4,
&nonce_mask, sizeof(nonce_mask));
/* send task and read nonces at the same time */
ret = cmd_buffer_push(cmd_buffer,
info->chipboard[board_id].bcm250[bcm250_id].channel_depth,
renonce_chip_address[board_id], RENONCE(rdata)->src_address,
RENONCE(rdata)->owork, RENONCE(rdata)->id,
(CHIP_CMD_TASK_WRITE | CHIP_CMD_TASK_SWITCH | CHIP_CMD_READ_NONCE), 79,
RENONCE(rdata)->owork.task);
break;
case RENONCE_STAGE1:
case RENONCE_STAGE3:
/* generate chip work with new mask */
cg_memcpy(RENONCE(rdata)->cwork.task + 19*4,
&nonce_mask, sizeof(nonce_mask));
/* send task and read nonces at the same time */
ret = cmd_buffer_push(cmd_buffer,
info->chipboard[board_id].bcm250[bcm250_id].channel_depth,
renonce_chip_address[board_id], RENONCE(rdata)->src_address,
RENONCE(rdata)->cwork, RENONCE(rdata)->id,
(CHIP_CMD_TASK_WRITE | CHIP_CMD_TASK_SWITCH | CHIP_CMD_READ_NONCE), 79,
RENONCE(rdata)->cwork.task);
break;
case RENONCE_STAGE_FINISHED:
default:
break;
}
}
if (ret == 0) {
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status = TASK_SWITCHED;
RENONCE(rdata)->sent = true;
RENONCE(rdata)->received = false;
nonces++;
}
rdata = rdata->next;
}
L_UNLOCK(info->renonce_list);
}
return nonces;
}
static void renonce_task_update(struct cgpu_info *bitfury, uint8_t board_id, uint8_t renonce_count)
{
struct bitfury16_info *info = (struct bitfury16_info *)(bitfury->device_data);
bf_cmd_buffer_t* cmd_buffer = &info->chipboard[board_id].cmd_buffer;
bf_works_t work;
uint8_t i;
uint8_t bcm250_id = renonce_chip_address[board_id].bcm250_id;
uint8_t chip_id = renonce_chip_address[board_id].chip_id;
cmd_buffer_push_create_channel(cmd_buffer,
info->chipboard[board_id].bcm250[bcm250_id].channel_path,
info->channel_length);
if (info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status < FAILING) {
uint8_t toggle[4] = { 0xa5, 0x00, 0x00, 0x02 };
cmd_buffer_push(cmd_buffer,
info->chipboard[board_id].bcm250[bcm250_id].channel_depth,
renonce_chip_address[board_id], renonce_chip_address[board_id],
work, 0, CHIP_CMD_TOGGLE, 3, toggle);
uint8_t clock_buf[4];
memset(clock_buf, 0, sizeof(clock_buf));
gen_clock_data(bf16_renonce_chip_clock, 1, clock_buf);
cmd_buffer_push(cmd_buffer,
info->chipboard[board_id].bcm250[bcm250_id].channel_depth,
renonce_chip_address[board_id], renonce_chip_address[board_id],
work, 0, CHIP_CMD_SET_CLOCK, 3, clock_buf);
uint8_t noncemask[4];
memset(noncemask, 0, sizeof(noncemask));
for (i = 0; i < 4; i++)
noncemask[i] = (mask >> (8*(4 - i - 1))) & 0xff;
cmd_buffer_push(cmd_buffer,
info->chipboard[board_id].bcm250[bcm250_id].channel_depth,
renonce_chip_address[board_id], renonce_chip_address[board_id],
work, 0, CHIP_CMD_SET_MASK, 3, noncemask);
bf_renonce_stage_t stage = RENONCE_STAGE0;
while ((renonce_count > 0) && (stage != RENONCE_STAGE_FINISHED)) {
renonce_count -= renonce_task_update_loop(bitfury, board_id, stage++, renonce_count);
}
}
cmd_buffer_push_destroy_channel(cmd_buffer,
info->chipboard[board_id].
bcm250[renonce_chip_address[board_id].bcm250_id].channel_depth);
}
static void fill_cmd_buffer_loop(struct cgpu_info *bitfury, uint8_t board_id, bool do_renonce, uint16_t renonce_count)
{
uint8_t bcm250_id, chip_id;
struct bitfury16_info *info = (struct bitfury16_info *)(bitfury->device_data);
bf_cmd_buffer_t* cmd_buffer = &info->chipboard[board_id].cmd_buffer;
/* concentrator loop */
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;
cmd_buffer_push_create_channel(cmd_buffer,
info->chipboard[board_id].bcm250[bcm250_id].channel_path,
info->channel_length);
/* chips loop */
for (chip_id = first_good_chip; chip_id < last_good_chip; chip_id++) {
bf_chip_address_t chip_address = { board_id, bcm250_id, chip_id };
chip_task_update(bitfury, chip_address);
}
cmd_buffer_push_destroy_channel(cmd_buffer,
info->chipboard[board_id].bcm250[bcm250_id].channel_depth);
}
if (do_renonce == true) {
uint8_t count = (cmd_buffer->free_bytes - (2 + 11 + 11 + 11 + 8)) / 136;
if (count < renonce_count) {
if (count > 0)
renonce_task_update(bitfury, board_id, count);
} else if (renonce_count > 0)
renonce_task_update(bitfury, board_id, renonce_count);
}
cmd_buffer->status = TX_READY;
}
static void fill_cmd_buffer(struct cgpu_info *bitfury, uint8_t board_id)
{
static uint8_t do_renonce[CHIPBOARD_NUM];
uint16_t renonce_count = 0;
struct bitfury16_info *info = (struct bitfury16_info *)(bitfury->device_data);
bf_cmd_buffer_t* cmd_buffer = &info->chipboard[board_id].cmd_buffer;
if (cmd_buffer->status == EMPTY) {
if ((opt_bf16_renonce == RENONCE_DISABLED) ||
(renonce_chip_address[board_id].board_id == -1)) {
fill_cmd_buffer_loop(bitfury, board_id, false, 0);
} else {
L_LOCK(info->renonce_list);
bf_data_t* rdata = info->renonce_list->head;
while (rdata != NULL) {
if (RENONCE(rdata)->sent == false)
renonce_count++;
rdata = rdata->next;
}
L_UNLOCK(info->renonce_list);
if (do_renonce[board_id] < RENONCE_SEND) {
fill_cmd_buffer_loop(bitfury, board_id, true, renonce_count);
do_renonce[board_id]++;
} else {
if (renonce_count >= RENONCE_COUNT) {
renonce_task_update(bitfury, board_id, RENONCE_COUNT);
do_renonce[board_id] = 0;
cmd_buffer->status = TX_READY;
} else {
fill_cmd_buffer_loop(bitfury, board_id, true, renonce_count);
do_renonce[board_id]++;
}
}
}
}
}
static uint8_t update_chip_status(struct cgpu_info *bitfury, bf_cmd_status_t cmd_status)
{
struct bitfury16_info *info = (struct bitfury16_info *)(bitfury->device_data);
uint8_t board_id = cmd_status.chip_address.board_id;
uint8_t bcm250_id = cmd_status.chip_address.bcm250_id;
uint8_t chip_id = cmd_status.chip_address.chip_id;
switch (info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status) {
case UNINITIALIZED:
case TOGGLE_SET:
case CLOCK_SET:
case MASK_SET:
applog(LOG_DEBUG, "%s: chipworker_thr: chip [%d:%d:%2d], send_cmd [%s]",
bitfury->drv->name,
board_id, bcm250_id, chip_id,
get_cmd_description(cmd_status.cmd_code));
/* update chip status */
if (cmd_status.checksum_error == false)
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status++;
else {
#ifndef DISABLE_SEND_CMD_ERROR
applog(LOG_ERR, "%s: chipworker_thr: chip [%d:%d:%2d]: error send_cmd [%s]. "
"checksum: expected: [%02x]; received: [%02x]",
bitfury->drv->name,
board_id, bcm250_id, chip_id,
get_cmd_description(cmd_status.cmd_code),
cmd_status.checksum_expected,
cmd_status.checksum_received);
#endif
/* increase error counters */
increase_errors(info, cmd_status.chip_address);
}
break;
case TASK_SENT:
applog(LOG_DEBUG, "%s: chipworker_thr: chip [%d:%d:%2d], send_cmd [%s]",
bitfury->drv->name,
board_id, bcm250_id, chip_id,
get_cmd_description(cmd_status.cmd_code));
/* read task status from chip*/
if (cmd_status.checksum_error == false) {
uint8_t new_buff = ((cmd_status.status & 0x0f) == 0x0f) ? 1 : 0;
/* status cmd counter */
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status_cmd_dx++;
info->chipboard[board_id].bcm250[bcm250_id].status_cmd_dx++;
info->chipboard[board_id].status_cmd_dx++;
info->status_cmd_dx++;
/* check if chip task has switched */
if (new_buff != info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].curr_buff) {
gettimeofday(&info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].switch_time, NULL);
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].curr_buff = new_buff;
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status++;
/* task switch counter */
increase_task_switch(info, cmd_status.chip_address);
} else {
/* task not switched */
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status_cmd_none_dx++;
info->chipboard[board_id].bcm250[bcm250_id].status_cmd_none_dx++;
info->chipboard[board_id].status_cmd_none_dx++;
info->status_cmd_none_dx++;
/* check if chip hang */
struct timeval curr_time;
gettimeofday(&curr_time, NULL);
if ((timediff_us(info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].switch_time, curr_time) > CHIP_TASK_SWITCH_INTERVAL) &&
(info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status < FAILING)) {
increase_errors(info, cmd_status.chip_address);
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status = FAILING;
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].last_error_time = time(NULL);
applog(LOG_ERR, "%s: nonceworker_thr: chip [%d:%d:%2d], "
"failed: no task switch during last [%.3f] seconds",
bitfury->drv->name,
board_id, bcm250_id, chip_id, CHIP_TASK_SWITCH_INTERVAL / 1000000.0);
#ifdef FILELOG
filelog(info, "BF16: no task switch for chip [%d:%d:%2d], "
"error count: [%d], recovery_count: [%d], error_rate: [%d]",
board_id, bcm250_id, chip_id,
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].errors,
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].recovery_count,
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].error_rate);
#endif
}
}
} else {
#ifndef DISABLE_SEND_CMD_ERROR
applog(LOG_ERR, "%s: chipworker_thr: chip [%d:%d:%2d]: error send_cmd [%s]. "
"checksum: expected: [%02x]; received: [%02x]",
bitfury->drv->name,
board_id, bcm250_id, chip_id,
get_cmd_description(cmd_status.cmd_code),
cmd_status.checksum_expected,
cmd_status.checksum_received);
#endif
/* increase error counters */
increase_errors(info, cmd_status.chip_address);
}
break;
case TASK_SWITCHED:
applog(LOG_DEBUG, "%s: chipworker_thr: chip [%d:%d:%2d], send_cmd [%s]",
bitfury->drv->name,
board_id, bcm250_id, chip_id,
get_cmd_description(cmd_status.cmd_code));
if (cmd_status.checksum_error == false) {
if ((renonce_chip(cmd_status.chip_address) == 1) &&
(opt_bf16_renonce != RENONCE_DISABLED)) {
/* task switch counter */
if (cmd_status.cmd_code & CHIP_CMD_READ_NONCE)
increase_task_switch(info, cmd_status.chip_address);
} else if (info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status < FAILING) {
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].task_processed++;
if (info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].task_processed >= CHIP_RESTART_LIMIT) {
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status = UNINITIALIZED;
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].task_processed = 0;
} else
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status = MASK_SET;
}
return 1;
} else {
#ifndef DISABLE_SEND_CMD_ERROR
applog(LOG_ERR, "%s: chipworker_thr: chip [%d:%d:%2d]: error send_cmd [%s]. "
"checksum: expected: [%02x]; received: [%02x]",
bitfury->drv->name,
board_id, bcm250_id, chip_id,
get_cmd_description(cmd_status.cmd_code),
cmd_status.checksum_expected,
cmd_status.checksum_received);
#endif
/* increase error counters */
increase_errors(info, cmd_status.chip_address);
}
break;
case FAILING:
case DISABLED:
default:
break;
}
return 0;
}
static uint8_t process_nonces(struct cgpu_info *bitfury, bf_cmd_status_t cmd_status, uint32_t* nonces)
{
struct bitfury16_info *info = (struct bitfury16_info *)(bitfury->device_data);
uint8_t i;
uint32_t found_nonces[12];
uint8_t board_id = cmd_status.chip_address.board_id;
uint8_t bcm250_id = cmd_status.chip_address.bcm250_id;
uint8_t chip_id = cmd_status.chip_address.chip_id;
if ((cmd_status.checksum_error == false) &&
(cmd_status.nonce_checksum_error == false)) {
cg_memcpy(info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].rx, nonces, sizeof(found_nonces));
uint8_t found = find_nonces(info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].rx,
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].rx_prev,
found_nonces);
/* check if chip is still mining */
if (found == 0) {
time_t curr_time = time(NULL);
time_t time_diff = curr_time - info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].last_nonce_time;
if ((renonce_chip(cmd_status.chip_address) == 1) &&
(opt_bf16_renonce != RENONCE_DISABLED)) {
if ((time_diff >= RENONCE_CHIP_FAILING_INTERVAL) &&
(info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status < FAILING)) {
increase_errors(info, cmd_status.chip_address);
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status = FAILING;
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].last_error_time = curr_time;
applog(LOG_ERR, "%s: nonceworker_thr: renonce chip [%d:%d:%2d] "
"failed: no good nonces during last [%.1f] seconds",
bitfury->drv->name,
board_id, bcm250_id, chip_id, RENONCE_CHIP_FAILING_INTERVAL);
#ifdef FILELOG
filelog(info, "BF16: no good nonces from renonce chip [%d:%d:%2d], "
"error count: [%d] recovery_count: [%d], error_rate: [%d]",
board_id, bcm250_id, chip_id,
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].errors,
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].recovery_count,
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].error_rate);
#endif
}
} else {
if ((time_diff >= CHIP_FAILING_INTERVAL) &&
(info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status < FAILING)) {
increase_errors(info, cmd_status.chip_address);
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status = FAILING;
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].last_error_time = curr_time;
applog(LOG_ERR, "%s: nonceworker_thr: chip [%d:%d:%2d], "
"failed: no good nonces during last [%.1f] seconds",
bitfury->drv->name,
board_id, bcm250_id, chip_id, CHIP_FAILING_INTERVAL);
#ifdef FILELOG
filelog(info, "BF16: no good nonces from chip [%d:%d:%2d], "
"error count: [%d], recovery_count: [%d], error_rate: [%d]",
board_id, bcm250_id, chip_id,
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].errors,
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].recovery_count,
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].error_rate);
#endif
}
}
}
/* increase stage if no nonces received */
if ((renonce_chip(cmd_status.chip_address) == 1) &&
(opt_bf16_renonce != RENONCE_DISABLED)) {
L_LOCK(info->renonce_list);
bf_data_t* rdata = info->renonce_list->head;
while (rdata != NULL) {
if (RENONCE(rdata)->id == cmd_status.id) {
if (found == 0) {
RENONCE(rdata)->stage++;
RENONCE(rdata)->sent = false;
/* clear renonces list if we are running too slow */
if ((RENONCE(rdata)->stage >= RENONCE_STAGE2) &&
(info->renonce_list->count > RENONCE_STAGE2_LIMIT)) {
info->unmatched++;
increase_re_bad_nonces(info, RENONCE(rdata)->src_address);
bf_data_t* rndata = rdata->next;
renonce_list_remove(info->renonce_list, rdata);
rdata = rndata;
continue;
}
if ((RENONCE(rdata)->stage >= RENONCE_STAGE3) &&
(info->renonce_list->count > RENONCE_STAGE3_LIMIT)) {
info->unmatched++;
increase_re_bad_nonces(info, RENONCE(rdata)->src_address);
bf_data_t* rndata = rdata->next;
renonce_list_remove(info->renonce_list, rdata);
rdata = rndata;
continue;
}
/* remove expired renonce */
if (RENONCE(rdata)->stage == RENONCE_STAGE_FINISHED) {
info->unmatched++;
increase_re_bad_nonces(info, RENONCE(rdata)->src_address);
bf_data_t* rndata = rdata->next;
renonce_list_remove(info->renonce_list, rdata);
rdata = rndata;
continue;
}
}
RENONCE(rdata)->received = true;
break;
}
rdata = rdata->next;
}
L_UNLOCK(info->renonce_list);
}
bf_list_t* nonce_list = info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].nonce_list;
for (i = 0; i < found; i++) {
L_LOCK(nonce_list);
int8_t res = nonce_list_push(nonce_list, found_nonces[i]);
L_UNLOCK(nonce_list);
if (res < 0)
continue;
increase_total_nonces(info, cmd_status.chip_address);
/* check if nonce has errors and add it to renonce list */
if ((opt_bf16_renonce != RENONCE_DISABLED) &&
(renonce_chip(cmd_status.chip_address) == 0) &&
(found_nonces[i] & 0xfff00000) == 0xaaa00000) {
increase_re_nonces(info, cmd_status.src_address);
L_LOCK(info->renonce_list);
if (info->renonce_list->count < RENONCE_QUEUE_LEN) {
renonce_list_push(info->renonce_list,
info->renonce_id++,
found_nonces[i],
cmd_status.chip_address,
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].cwork,
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].owork);
} else
increase_re_bad_nonces(info, cmd_status.chip_address);
L_UNLOCK(info->renonce_list);
applog(LOG_DEBUG, "%s: chipworker_thr: pushing renonce task: nonce: [%08x]",
bitfury->drv->name,
found_nonces[i]);
continue;
}
/* add nonces to noncework list */
if ((renonce_chip(cmd_status.chip_address) == 1) &&
(opt_bf16_renonce != RENONCE_DISABLED)) {
L_LOCK(info->renoncework_list);
renoncework_list_push(info->renoncework_list, cmd_status.chip_address, found_nonces[i]);
L_UNLOCK(info->renoncework_list);
} else {
L_LOCK(info->noncework_list);
noncework_list_push(info->noncework_list,
cmd_status.chip_address, cmd_status.src_address,
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].cwork,
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].owork,
found_nonces[i]);
L_UNLOCK(info->noncework_list);
}
applog(LOG_DEBUG, "%s: chipworker_thr: pushing nonce task: nonce: [%08x]",
bitfury->drv->name,
found_nonces[i]);
}
/* rotate works and buffers */
cg_memcpy(info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].rx_prev,
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].rx, sizeof(found_nonces));
cg_memcpy(&info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].owork,
&info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].cwork, sizeof(bf_works_t));
/* remove old nonces from nonce list */
L_LOCK(nonce_list);
if ((renonce_chip(cmd_status.chip_address) == 1) &&
(opt_bf16_renonce != RENONCE_DISABLED)) {
while (nonce_list->count > RENONCE_CHIP_QUEUE_LEN)
nonce_list_pop(nonce_list);
} else {
while (nonce_list->count > NONCE_CHIP_QUEUE_LEN)
nonce_list_pop(nonce_list);
}
L_UNLOCK(nonce_list);
} else {
if (cmd_status.checksum_error != 0) {
#ifndef DISABLE_SEND_CMD_ERROR
applog(LOG_ERR, "%s: chipworker_thr: chip [%d:%d:%2d]: error send_cmd [%s]. "
"checksum: expected: [%02x]; received: [%02x]",
bitfury->drv->name,
board_id, bcm250_id, chip_id,
get_cmd_description(cmd_status.cmd_code),
cmd_status.checksum_expected,
cmd_status.checksum_received);
#endif
/* increase error counters */
increase_errors(info, cmd_status.chip_address);
}
if (cmd_status.nonce_checksum_error != 0) {
if ((renonce_chip(cmd_status.chip_address) == 0) ||
(opt_bf16_renonce == RENONCE_DISABLED)) {
applog(LOG_ERR, "%s: chipworker_thr: chip [%d:%d:%2d]: error receiving data. "
"nonce checksum: expected: [%02x]; received: [%02x]",
bitfury->drv->name,
board_id, bcm250_id, chip_id,
cmd_status.checksum_expected,
cmd_status.checksum_received);
/* increase error counters */
increase_errors(info, cmd_status.chip_address);
}
}
}
return 0;
}
/* routine sending-receiving data to chipboard */
static void process_cmd_buffer(struct cgpu_info *bitfury, uint8_t board_id)
{
struct bitfury16_info *info = (struct bitfury16_info *)(bitfury->device_data);
uint8_t i;
bf_cmd_status_t cmd_status;
bf_cmd_buffer_t* cmd_buffer = &info->chipboard[board_id].cmd_buffer;
if (cmd_buffer->status == EXECUTED) {
/* process extracted data */
uint16_t cmd_number = cmd_buffer->cmd_list->count;
for (i = 0; i < cmd_number; i++) {
uint32_t nonces[12];
cmd_buffer_pop(cmd_buffer, &cmd_status, nonces);
if ((cmd_status.cmd_code == CHIP_CMD_CREATE_CHANNEL) ||
(cmd_status.cmd_code == CHIP_CMD_TASK_SWITCH))
continue;
uint8_t task_switch = update_chip_status(bitfury, cmd_status);
/* analyze nonces */
if ((cmd_status.cmd_code & CHIP_CMD_READ_NONCE) &&
(task_switch == 1)) {
process_nonces(bitfury, cmd_status, nonces);
}
}
cmd_buffer_clear(cmd_buffer);
}
}
static void *bitfury_chipworker(void *userdata)
{
struct cgpu_info *bitfury = (struct cgpu_info *)userdata;
struct bitfury16_info *info = (struct bitfury16_info *)(bitfury->device_data);
uint8_t board_id;
applog(LOG_INFO, "%s: started chipworker thread", bitfury->drv->name);
while (bitfury->shutdown == false) {
if (info->initialised) {
break;
}
cgsleep_us(30);
}
/* send reset sequence to boards */
spi_emit_reset(SPI_CHANNEL1);
spi_emit_reset(SPI_CHANNEL2);
while (bitfury->shutdown == false) {
if ((info->a_temp == false) &&
(info->a_ichain == false)) {
for (board_id = 0; board_id < CHIPBOARD_NUM; board_id++) {
if (info->chipboard[board_id].detected == true) {
/* prepare send buffer */
struct timeval start_time, stop_time;
gettimeofday(&start_time, NULL);
if (info->chipboard[board_id].cmd_buffer.status == EMPTY)
fill_cmd_buffer(bitfury, board_id);
gettimeofday(&stop_time, NULL);
#if 0
applog(LOG_ERR, "%s: chipworker_thr: board %d buffer prepare: time elapsed: [%.6f]",
bitfury->drv->name, board_id, timediff(start_time, stop_time));
#endif
gettimeofday(&start_time, NULL);
/* send buffer to chipboard */
if (info->chipboard[board_id].cmd_buffer.status == TX_READY) {
spi_emit_reset(board_id + 1);
cmd_buffer_exec(board_id + 1, &info->chipboard[board_id].cmd_buffer);
info->chipboard[board_id].bytes_transmitted_dx += info->chipboard[board_id].cmd_buffer.tx_offset;
info->chipboard[board_id].bytes_transmitted += info->chipboard[board_id].cmd_buffer.tx_offset;
}
gettimeofday(&stop_time, NULL);
#if 0
applog(LOG_ERR, "%s: chipworker_thr: board %d TX/RX time: [%.6f]",
bitfury->drv->name, board_id, timediff(start_time, stop_time));
#endif
gettimeofday(&start_time, NULL);
/* analyze received data */
if (info->chipboard[board_id].cmd_buffer.status == EXECUTED) {
process_cmd_buffer(bitfury, board_id);
}
gettimeofday(&stop_time, NULL);
#if 0
applog(LOG_ERR, "%s: chipworker_thr: board %d buffer processing: time elapsed: [%.6f]",
bitfury->drv->name, board_id, timediff(start_time, stop_time));
#endif
}
}
} else
cgsleep_us(CHIPWORKER_DELAY);
}
applog(LOG_INFO, "%s: chipworker_thr: exiting...", bitfury->drv->name);
return NULL;
}
static int16_t cleanup_older(struct cgpu_info *bitfury)
{
struct bitfury16_info *info = (struct bitfury16_info *)(bitfury->device_data);
time_t curr_time = time(NULL);
uint16_t released = 0;
/* clear stale work list */
L_LOCK(info->stale_work_list);
bf_data_t* wdata = info->stale_work_list->head;
while (wdata != NULL) {
if (curr_time - WORKD(wdata)->generated >= WORK_TIMEOUT) {
workd_list_pop(info->stale_work_list, bitfury);
released++;
} else
break;
wdata = info->stale_work_list->head;
}
L_UNLOCK(info->stale_work_list);
applog(LOG_INFO, "%s: released %d works", bitfury->drv->name, released);
return released;
}
static void *bitfury_nonceworker(void *userdata)
{
struct cgpu_info *bitfury = (struct cgpu_info *)userdata;
struct bitfury16_info *info = (struct bitfury16_info *)(bitfury->device_data);
applog(LOG_INFO, "%s: started nonceworker thread", bitfury->drv->name);
while (bitfury->shutdown == false) {
if (info->initialised) {
break;
}
cgsleep_us(30);
}
applog(LOG_INFO, "%s: nonceworker loop started", bitfury->drv->name);
while (bitfury->shutdown == false) {
struct timeval start_time, stop_time;
gettimeofday(&start_time, NULL);
uint32_t nonce_cnt = 0;
/* general nonces processing */
L_LOCK(info->noncework_list);
bf_data_t* nwdata = info->noncework_list->head;
while (nwdata != NULL) {
uint8_t board_id = NONCEWORK(nwdata)->chip_address.board_id;
uint8_t bcm250_id = NONCEWORK(nwdata)->chip_address.bcm250_id;
uint8_t chip_id = NONCEWORK(nwdata)->chip_address.chip_id;
nonce_cnt++;
/* general chip results processing */
if (test_nonce(&NONCEWORK(nwdata)->owork.work, NONCEWORK(nwdata)->nonce)) {
applog(LOG_DEBUG, "%s: nonceworker_thr: chip [%d:%d:%2d], valid nonce [%08x]",
bitfury->drv->name,
board_id, bcm250_id, chip_id, NONCEWORK(nwdata)->nonce);
submit_tested_work(info->thr, &NONCEWORK(nwdata)->owork.work);
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].last_nonce_time = time(NULL);
if (info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].recovery_count > 0) {
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].recovery_count = 0;
#ifdef FILELOG
filelog(info, "BF16: good nonce for chip [%d:%d:%2d] "
"setting recovery_count to [0], error_rate: [%d]",
board_id, bcm250_id, chip_id,
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].error_rate);
#endif
}
increase_good_nonces(info, NONCEWORK(nwdata)->chip_address);
mutex_lock(&info->nonces_good_lock);
info->nonces_good_cg++;
mutex_unlock(&info->nonces_good_lock);
} else if (test_nonce(&NONCEWORK(nwdata)->cwork.work, NONCEWORK(nwdata)->nonce)) {
applog(LOG_DEBUG, "%s: nonceworker_thr: chip [%d:%d:%2d], valid nonce [%08x]",
bitfury->drv->name,
board_id, bcm250_id, chip_id, NONCEWORK(nwdata)->nonce);
submit_tested_work(info->thr, &NONCEWORK(nwdata)->cwork.work);
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].last_nonce_time = time(NULL);
if (info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].recovery_count > 0) {
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].recovery_count = 0;
#ifdef FILELOG
filelog(info, "BF16: good nonce for chip [%d:%d:%2d] "
"setting recovery_count to 0, error_rate: [%d]",
board_id, bcm250_id, chip_id,
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].error_rate);
#endif
}
increase_good_nonces(info, NONCEWORK(nwdata)->chip_address);
mutex_lock(&info->nonces_good_lock);
info->nonces_good_cg++;
mutex_unlock(&info->nonces_good_lock);
} else {
time_t curr_time = time(NULL);
time_t time_diff = curr_time - info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].last_nonce_time;
if ((time_diff >= CHIP_FAILING_INTERVAL) &&
(info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status < FAILING)) {
increase_errors(info, NONCEWORK(nwdata)->chip_address);
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status = FAILING;
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].last_error_time = curr_time;
applog(LOG_ERR, "%s: nonceworker_thr: chip [%d:%d:%2d], "
"failed: no good nonces during last [%.1f] seconds",
bitfury->drv->name,
board_id, bcm250_id, chip_id, CHIP_FAILING_INTERVAL);
#ifdef FILELOG
filelog(info, "BF16: no good nonces from chip [%d:%d:%2d], "
"error count: [%d], recovery_count: [%d], error_rate: [%d]",
board_id, bcm250_id, chip_id,
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].errors,
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].recovery_count,
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].error_rate);
#endif
}
if (opt_bf16_renonce != RENONCE_DISABLED) {
/* add failed nonce to renonce list */
increase_bad_nonces(info, NONCEWORK(nwdata)->chip_address);
L_LOCK(info->renonce_list);
if (info->renonce_list->count < RENONCE_QUEUE_LEN) {
renonce_list_push(info->renonce_list,
info->renonce_id++,
NONCEWORK(nwdata)->nonce,
NONCEWORK(nwdata)->chip_address,
NONCEWORK(nwdata)->cwork,
NONCEWORK(nwdata)->owork);
} else
increase_re_bad_nonces(info, NONCEWORK(nwdata)->chip_address);
L_UNLOCK(info->renonce_list);
applog(LOG_DEBUG, "%s: nonceworker_thr: pushing renonce task: nonce: [%08x]",
bitfury->drv->name,
NONCEWORK(nwdata)->nonce);
} else
increase_bad_nonces(info, NONCEWORK(nwdata)->chip_address);
}
/* remove nonce from list */
noncework_list_pop(info->noncework_list);
nwdata = info->noncework_list->head;
}
L_UNLOCK(info->noncework_list);
/* cleanup older works */
cleanup_older(bitfury);
gettimeofday(&stop_time, NULL);
#if 0
applog(LOG_DEBUG, "%s: nonceworker_thr: nonces processed [%d]: time elapsed: [%.6f]",
bitfury->drv->name,
nonce_cnt, timediff(start_time, stop_time));
#endif
cgsleep_us(NONCEWORKER_DELAY);
}
applog(LOG_INFO, "%s: nonceworker_thr: exiting...", bitfury->drv->name);
return NULL;
}
static bool test_renonce(struct cgpu_info *bitfury, bf_data_t* rdata, bf_data_t* rnwdata, bool owork)
{
struct bitfury16_info *info = (struct bitfury16_info *)(bitfury->device_data);
uint8_t board_id = RENONCEWORK(rnwdata)->src_address.board_id;
uint8_t bcm250_id = renonce_chip_address[board_id].bcm250_id;
uint8_t chip_id = renonce_chip_address[board_id].chip_id;
if (owork == true) {
if (test_nonce(&RENONCE(rdata)->owork.work, RENONCEWORK(rnwdata)->nonce)) {
applog(LOG_DEBUG, "%s: renonceworker_thr: restored renonce: nonce: [%08x]",
bitfury->drv->name,
RENONCEWORK(rnwdata)->nonce);
submit_tested_work(info->thr, &RENONCE(rdata)->owork.work);
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].last_nonce_time = time(NULL);
if (info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].recovery_count > 0) {
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].recovery_count = 0;
#ifdef FILELOG
filelog(info, "BF16: good nonce for renonce chip [%d:%d:%2d] "
"setting recovery_count to 0, error_rate: [%d]",
board_id, bcm250_id, chip_id,
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].error_rate);
#endif
}
increase_re_good_nonces(info, RENONCE(rdata)->src_address);
increase_re_good_nonces(info, renonce_chip_address[board_id]);
mutex_lock(&info->nonces_good_lock);
info->nonces_good_cg++;
mutex_unlock(&info->nonces_good_lock);
RENONCE(rdata)->match = true;
} else {
time_t curr_time = time(NULL);
time_t time_diff = curr_time - info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].last_nonce_time;
if ((time_diff >= RENONCE_CHIP_FAILING_INTERVAL) &&
(info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status < FAILING)) {
increase_errors(info, renonce_chip_address[board_id]);
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status = FAILING;
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].last_error_time = curr_time;
applog(LOG_ERR, "%s: nonceworker_thr: renonce chip [%d:%d:%2d] "
"failed: no good nonces during last [%.1f] seconds",
bitfury->drv->name,
board_id, bcm250_id, chip_id, RENONCE_CHIP_FAILING_INTERVAL);
#ifdef FILELOG
filelog(info, "BF16: no good nonces from renonce chip [%d:%d:%2d], "
"error count: [%d] recovery_count: [%d], error_rate: [%d]",
board_id, bcm250_id, chip_id,
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].errors,
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].recovery_count,
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].error_rate);
#endif
}
}
} else {
if (test_nonce(&RENONCE(rdata)->cwork.work, RENONCEWORK(rnwdata)->nonce)) {
applog(LOG_DEBUG, "%s: renonceworker_thr: restored renonce: nonce: [%08x]",
bitfury->drv->name,
RENONCEWORK(rnwdata)->nonce);
submit_tested_work(info->thr, &RENONCE(rdata)->cwork.work);
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].last_nonce_time = time(NULL);
if (info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].recovery_count > 0) {
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].recovery_count = 0;
#ifdef FILELOG
filelog(info, "BF16: good nonce for renonce chip [%d:%d:%2d] "
"setting recovery_count to 0, error_rate: [%d]",
board_id, bcm250_id, chip_id,
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].error_rate);
#endif
}
increase_re_good_nonces(info, RENONCE(rdata)->src_address);
increase_re_good_nonces(info, renonce_chip_address[board_id]);
mutex_lock(&info->nonces_good_lock);
info->nonces_good_cg++;
mutex_unlock(&info->nonces_good_lock);
RENONCE(rdata)->match = true;
} else {
time_t curr_time = time(NULL);
time_t time_diff = curr_time - info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].last_nonce_time;
if ((time_diff >= RENONCE_CHIP_FAILING_INTERVAL) &&
(info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status < FAILING)) {
increase_errors(info, renonce_chip_address[board_id]);
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status = FAILING;
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].last_error_time = curr_time;
applog(LOG_ERR, "%s: nonceworker_thr: renonce chip [%d:%d:%2d] "
"failed: no good nonces during last [%.1f] seconds",
bitfury->drv->name,
board_id, bcm250_id, chip_id, RENONCE_CHIP_FAILING_INTERVAL);
#ifdef FILELOG
filelog(info, "BF16: no good nonces from renonce chip [%d:%d:%2d], "
"error count: [%d] recovery_count: [%d], error_rate: [%d]",
board_id, bcm250_id, chip_id,
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].errors,
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].recovery_count,
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].error_rate);
#endif
}
}
}
return RENONCE(rdata)->match;
}
static void *bitfury_renonceworker(void *userdata)
{
struct cgpu_info *bitfury = (struct cgpu_info *)userdata;
struct bitfury16_info *info = (struct bitfury16_info *)(bitfury->device_data);
bf_list_t* id_list = nonce_list_init();
applog(LOG_INFO, "%s: started renonceworker thread", bitfury->drv->name);
while (bitfury->shutdown == false) {
if (info->initialised) {
break;
}
cgsleep_us(30);
}
applog(LOG_INFO, "%s: renonceworker loop started", bitfury->drv->name);
while (bitfury->shutdown == false) {
struct timeval start_time, stop_time;
gettimeofday(&start_time, NULL);
uint32_t nonce_cnt = 0;
/* renonce chip results processing */
L_LOCK(info->renoncework_list);
bf_data_t* rnwdata = info->renoncework_list->head;
while (rnwdata != NULL) {
nonce_cnt++;
/* find nonce by id */
L_LOCK(info->renonce_list);
bf_data_t* rdata = info->renonce_list->head;
while (rdata != NULL) {
if (match_nonce(RENONCEWORK(rnwdata)->nonce, RENONCE(rdata)->nonce, mask_bits)) {
if (RENONCE(rdata)->match == false) {
switch (RENONCE(rdata)->stage) {
case RENONCE_STAGE0:
if (test_renonce(bitfury, rdata, rnwdata, true) == true)
info->stage0_match++;
else
info->stage0_mismatch++;
break;
case RENONCE_STAGE1:
case RENONCE_STAGE2:
case RENONCE_STAGE3:
/* test old work first */
if (test_renonce(bitfury, rdata, rnwdata, true) == true) {
if (RENONCE(rdata)->stage == RENONCE_STAGE1)
info->stage1_mismatch++;
if (RENONCE(rdata)->stage == RENONCE_STAGE2)
info->stage2_match++;
if (RENONCE(rdata)->stage == RENONCE_STAGE3)
info->stage3_mismatch++;
} else {
if (test_renonce(bitfury, rdata, rnwdata, false) == true) {
if (RENONCE(rdata)->stage == RENONCE_STAGE1)
info->stage1_match++;
if (RENONCE(rdata)->stage == RENONCE_STAGE2)
info->stage2_mismatch++;
if (RENONCE(rdata)->stage == RENONCE_STAGE3)
info->stage3_match++;
}
}
break;
default:
applog(LOG_ERR, "%s: renonceworker_thr: invalid renonce stage arrived: [%d]",
bitfury->drv->name,
RENONCE(rdata)->stage);
}
}
nonce_list_push(id_list, RENONCE(rdata)->id);
if (RENONCE(rdata)->match == true)
break;
}
rdata = rdata->next;
}
L_UNLOCK(info->renonce_list);
/* remove nonce from list */
renoncework_list_pop(info->renoncework_list);
rnwdata = info->renoncework_list->head;
}
L_UNLOCK(info->renoncework_list);
L_LOCK(info->renonce_list);
bf_data_t* rdata = info->renonce_list->head;
while (rdata != NULL) {
if (RENONCE(rdata)->match == true) {
bf_data_t* rndata = rdata->next;
renonce_list_remove(info->renonce_list, rdata);
rdata = rndata;
continue;
}
/* update stage */
bf_data_t* ndata = id_list->head;
while (ndata != NULL) {
if (NONCE(ndata)->nonce == RENONCE(rdata)->id) {
RENONCE(rdata)->stage++;
RENONCE(rdata)->sent = false;
RENONCE(rdata)->received = false;
break;
}
ndata = ndata->next;
}
/* update tasks with wrong or dup nonces recieved */
if ((RENONCE(rdata)->stage != RENONCE_STAGE_FINISHED) &&
(RENONCE(rdata)->received == true)) {
RENONCE(rdata)->stage++;
RENONCE(rdata)->sent = false;
RENONCE(rdata)->received = false;
}
/* clear renonces list if we are running too slow */
if ((RENONCE(rdata)->stage >= RENONCE_STAGE2) &&
(info->renonce_list->count > RENONCE_STAGE2_LIMIT)) {
info->unmatched++;
increase_re_bad_nonces(info, RENONCE(rdata)->src_address);
bf_data_t* rndata = rdata->next;
renonce_list_remove(info->renonce_list, rdata);
rdata = rndata;
continue;
}
if ((RENONCE(rdata)->stage >= RENONCE_STAGE3) &&
(info->renonce_list->count > RENONCE_STAGE3_LIMIT)) {
info->unmatched++;
increase_re_bad_nonces(info, RENONCE(rdata)->src_address);
bf_data_t* rndata = rdata->next;
renonce_list_remove(info->renonce_list, rdata);
rdata = rndata;
continue;
}
if ((RENONCE(rdata)->stage == RENONCE_STAGE_FINISHED) &&
(RENONCE(rdata)->sent == false)) {
info->unmatched++;
increase_re_bad_nonces(info, RENONCE(rdata)->src_address);
bf_data_t* rndata = rdata->next;
renonce_list_remove(info->renonce_list, rdata);
rdata = rndata;
continue;
}
rdata = rdata->next;
}
L_UNLOCK(info->renonce_list);
/* clear id list */
bf_data_t* ndata = id_list->head;
while (ndata != NULL) {
nonce_list_pop(id_list);
ndata = id_list->head;
}
gettimeofday(&stop_time, NULL);
#if 0
applog(LOG_DEBUG, "%s: renonceworker_thr: nonces processed [%d]: time elapsed: [%.6f]",
bitfury->drv->name,
nonce_cnt, timediff(start_time, stop_time));
#endif
cgsleep_us(RENONCEWORKER_DELAY);
}
applog(LOG_INFO, "%s: renonceworker_thr: exiting...", bitfury->drv->name);
return NULL;
}
int16_t update_pid(bf_pid_t *pid, int16_t error)
{
int16_t pTerm, iTerm;
pTerm = 2 * error;
pid->i_state += error;
if(pid->i_state > pid->i_max)
pid->i_state = pid->i_max;
else if(pid->i_state < pid->i_min)
pid->i_state = pid->i_min;
iTerm = pid->i_state;
return (pTerm + iTerm);
}
static void *bitfury_hwmonitor(void *userdata)
{
struct cgpu_info *bitfury = (struct cgpu_info *)userdata;
struct bitfury16_info *info = (struct bitfury16_info *)(bitfury->device_data);
uint8_t board_id, bcm250_id, chip_id;
time_t curr_time;
applog(LOG_INFO, "%s: started hwmonitor thread", bitfury->drv->name);
while (bitfury->shutdown == false) {
if (info->initialised) {
break;
}
cgsleep_us(30);
}
applog(LOG_INFO, "%s: hwmonitor loop started", bitfury->drv->name);
while (bitfury->shutdown == false) {
float max_temp = 0.0;
float t_alarm = 100.0;
bool a_temp = false;
bool a_ichain = false;
for (board_id = 0; board_id < CHIPBOARD_NUM; board_id++) {
/* read hw sensor data */
char buff[256];
if (info->chipboard[board_id].detected == true) {
memset(buff, 0, sizeof(buff));
if (device_uart_txrx(board_id + 1, "S", buff) < 0)
quit(1, "%s: %s() failed to get BOARD%d status",
bitfury->drv->name, __func__, board_id + 1);
if (parse_hwstats(info, board_id, buff) < 0)
applog(LOG_ERR, "%s: failed to parse hw stats",
bitfury->drv->name);
info->chipboard[board_id].p_chain1 = info->chipboard[board_id].u_chain1 * info->chipboard[board_id].i_chain1;
info->chipboard[board_id].p_chain2 = info->chipboard[board_id].u_chain2 * info->chipboard[board_id].i_chain2;
/* fan power calculation */
if (info->chipboard[board_id].rpm != 0) {
if (info->chipboard[board_id].fan_speed > 40)
info->chipboard[board_id].p_fan = (0.1 + 0.0236 * (info->chipboard[board_id].fan_speed - 40)) *
(info->chipboard[board_id].u_board + U_LOSS);
else
info->chipboard[board_id].p_fan = 1.23;
} else {
info->chipboard[board_id].p_fan = 0.0;
}
/* board power calculation */
#ifdef MINER_X5
float i_board = info->chipboard[board_id].i_chain1;
#endif
#ifdef MINER_X6
float i_board = info->chipboard[board_id].i_chain1 + info->chipboard[board_id].i_chain2;
#endif
info->chipboard[board_id].p_board = ((info->chipboard[board_id].u_board + U_LOSS) * i_board + 2.0 +
info->chipboard[board_id].p_fan);
if (info->chipboard[board_id].a_temp == 1)
a_temp = true;
if ((info->chipboard[board_id].a_ichain1 == 1) ||
(info->chipboard[board_id].a_ichain2 == 1))
a_ichain = true;
if (max_temp < info->chipboard[board_id].temp)
max_temp = info->chipboard[board_id].temp;
if (t_alarm > info->chipboard[board_id].t_alarm)
t_alarm = info->chipboard[board_id].t_alarm;
}
}
/* enable temp alarm */
if ((a_temp == true) && (info->a_temp == false)) {
applog(LOG_ERR, "%s: temperature alarm enabled: [%5.1f]!!!",
bitfury->drv->name, max_temp);
/* enable fans to full speed*/
for (board_id = 0; board_id < CHIPBOARD_NUM; board_id++) {
if (info->chipboard[board_id].detected == true) {
if (device_uart_transfer(board_id + 1, "F:100") < 0)
quit(1, "%s: %s() failed to set BOARD%d fan speed",
bitfury->drv->name, __func__, board_id + 1);
applog(LOG_INFO, "%s: set BOARD%d fan speed to max speed",
bitfury->drv->name, board_id + 1);
}
}
}
/* temp alarm recovery */
if ((a_temp == false) && (info->a_temp == true)) {
applog(LOG_ERR, "%s: temperature alarm recovery: [%5.1f]",
bitfury->drv->name, max_temp);
/* restore fans speed */
set_fan_speed(bitfury);
reinit_x5(info, false);
}
/* enable power chain alarm */
if ((a_ichain == true) && (info->a_ichain == false)) {
applog(LOG_ERR, "%s: power chain alarm enabled!!!",
bitfury->drv->name);
info->ialarm_start = time(NULL);
}
/* power chain alarm recovery */
if ((a_ichain == false) && (info->a_ichain == true)) {
if (info->ialarm_count > 1) {
applog(LOG_ERR, "%s: power chain alarm recovery",
bitfury->drv->name);
info->ialarm_count = 1;
info->ialarm_buzzer = false;
info->ialarm_start = time(NULL);
reinit_x5(info, false);
}
}
info->a_temp = a_temp;
info->a_ichain = a_ichain;
if (info->a_temp == true)
applog(LOG_ERR, "%s: ALARM: board temp: [%5.1f] alarm temp: [%5.1f]",
bitfury->drv->name, max_temp, t_alarm);
if (info->a_ichain == true) {
curr_time = time(NULL);
if (curr_time - info->ialarm_start >= info->ialarm_count * ICHAIN_ALARM_INTERVAL) {
info->ialarm_count *= 2;
info->ialarm_start = curr_time;
/* enable power chain */
for (board_id = 0; board_id < CHIPBOARD_NUM; board_id++) {
enable_power_chain(bitfury, board_id, 0);
#ifdef MINER_X5
info->chipboard[board_id].power_enable_time = curr_time;
#endif
#ifdef MINER_X6
info->chipboard[board_id].power1_enable_time = curr_time;
info->chipboard[board_id].power2_enable_time = curr_time;
#endif
}
}
} else if (opt_bf16_power_management_disabled == false) {
if (info->a_net == true) {
/* disable power chain if no internet available */
for (board_id = 0; board_id < CHIPBOARD_NUM; board_id++) {
if (info->chipboard[board_id].detected == true) {
#ifdef MINER_X5
if (info->chipboard[board_id].p_chain1_enabled == 1) {
#endif
#ifdef MINER_X6
if ((info->chipboard[board_id].p_chain1_enabled == 1) ||
(info->chipboard[board_id].p_chain2_enabled == 1)) {
#endif
disable_power_chain(bitfury, board_id, 0);
}
}
}
} else {
/* enable power chain - internet recovery */
bool recovery = false;
for (board_id = 0; board_id < CHIPBOARD_NUM; board_id++) {
if (info->chipboard[board_id].detected == true) {
#ifdef MINER_X5
if ((info->chipboard[board_id].p_chain1_enabled == 0) &&
(info->chipboard[board_id].power_disabled == false)) {
enable_power_chain(bitfury, board_id, 0);
info->chipboard[board_id].power_enable_time = time(NULL);
/* wait for power chain to enable */
cgsleep_us(POWER_WAIT_INTERVAL);
reinit_x5(info, false);
}
#endif
#ifdef MINER_X6
if ((info->chipboard[board_id].p_chain1_enabled == 0) &&
(info->chipboard[board_id].power1_disabled == false)){
enable_power_chain(bitfury, board_id, 1);
info->chipboard[board_id].power1_enable_time = time(NULL);
recovery = true;
}
if ((info->chipboard[board_id].p_chain2_enabled == 0) &&
(info->chipboard[board_id].power2_disabled == false)) {
enable_power_chain(bitfury, board_id, 2);
info->chipboard[board_id].power2_enable_time = time(NULL);
recovery = true;
}
#endif
}
}
/* reinit chips on alarm recovery */
if (recovery == true) {
/* wait for power chain to enable */
cgsleep_us(POWER_WAIT_INTERVAL);
reinit_x5(info, false);
}
}
}
/* board temperature regulation */
char uart_cmd[8];
if (manual_pid_enabled == false) {
sprintf(uart_cmd, "N:%d", (int)max_temp);
for (board_id = 0; board_id < CHIPBOARD_NUM; board_id++) {
if (info->chipboard[board_id].detected == true) {
if (device_uart_transfer(board_id + 1, uart_cmd) < 0)
quit(1, "%s: %s() failed to set BOARD%d next temp",
bitfury->drv->name, __func__, board_id + 1);
applog(LOG_INFO, "%s: set BOARD%d next temp to [%5.1f]",
bitfury->drv->name, board_id + 1, max_temp);
}
}
} else {
uint8_t max_fan_speed = 0;
for (board_id = 0; board_id < CHIPBOARD_NUM; board_id++) {
if (info->chipboard[board_id].detected == true) {
uint16_t pid_temp = 10 * info->chipboard[board_id].temp;
if (10 * max_temp > pid_temp)
pid_temp = 10 * max_temp;
int16_t fan_speed = update_pid(&info->chipboard[board_id].pid,
(pid_temp - 10 * info->chipboard[board_id].target_temp) / 10);
if (fan_speed > 100)
fan_speed = 100;
else if (fan_speed < 0)
fan_speed = 0;
if (max_fan_speed < fan_speed)
max_fan_speed = fan_speed;
}
}
sprintf(uart_cmd, "F:%d", max_fan_speed);
for (board_id = 0; board_id < CHIPBOARD_NUM; board_id++) {
if (info->chipboard[board_id].detected == true) {
if (device_uart_transfer(board_id + 1, uart_cmd) < 0)
quit(1, "%s: %s() failed to set BOARD%d fan speed",
bitfury->drv->name, __func__, board_id + 1);
applog(LOG_INFO, "%s: set BOARD%d fan speed to [%d]",
bitfury->drv->name, board_id + 1, max_fan_speed);
}
}
}
/* board power management */
if (opt_bf16_power_management_disabled == false) {
curr_time = time(NULL);
for (board_id = 0; board_id < CHIPBOARD_NUM; board_id++) {
if (info->chipboard[board_id].detected == true) {
#ifdef MINER_X5
uint8_t disabled_chips = 0;
uint8_t total_chips = 0;
#endif
#ifdef MINER_X6
uint8_t disabled_chips_chain1 = 0;
uint8_t total_chips_chain1 = 0;
uint8_t disabled_chips_chain2 = 0;
uint8_t total_chips_chain2 = 0;
#endif
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;
/* chips loop */
for (chip_id = first_good_chip; chip_id < last_good_chip; chip_id++) {
#ifdef MINER_X5
total_chips++;
if (info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status == DISABLED)
disabled_chips++;
#endif
#ifdef MINER_X6
if (bcm250_id < BCM250_NUM / 2) {
total_chips_chain1++;
if (info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status == DISABLED)
disabled_chips_chain1++;
}
if ((bcm250_id >= BCM250_NUM / 2) && (bcm250_id < BCM250_NUM)) {
total_chips_chain2++;
if (info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status == DISABLED)
disabled_chips_chain2++;
}
#endif
}
}
#ifdef MINER_X5
/* disable chain power if all chips failed */
if ((total_chips == disabled_chips) &&
(info->chipboard[board_id].p_chain1_enabled == 1)) {
disable_power_chain(bitfury, board_id, 0);
/* increase disable counter until we reach long enough work time */
time_t work_interval = curr_time - info->chipboard[board_id].power_enable_time;
if (work_interval < CHAIN_WORK_INTERVAL)
info->chipboard[board_id].power_disable_count *= 2;
info->chipboard[board_id].power_disabled = true;
info->chipboard[board_id].power_disable_time = curr_time;
info->chipboard[board_id].chips_disabled = info->chipboard[board_id].chips_num;
}
/* enable disabled chain */
if ((info->chipboard[board_id].p_chain1_enabled == 0) &&
(info->chipboard[board_id].power_disabled == true) &&
(curr_time - info->chipboard[board_id].power_disable_time >= info->chipboard[board_id].power_disable_count * CHAIN_REENABLE_INTERVAL)) {
time_t disable_interval = curr_time - info->chipboard[board_id].power_disable_time;
info->chipboard[board_id].power_disable_time = curr_time;
info->chipboard[board_id].chips_disabled = 0;
enable_power_chain(bitfury, board_id, 0);
info->chipboard[board_id].power_enable_time = curr_time;
info->chipboard[board_id].power_disabled = false;
/* wait for power chain to enable */
cgsleep_us(POWER_WAIT_INTERVAL);
reinit_x5(info, true);
applog(LOG_NOTICE, "%s: reenabled power on BOARD%d: time interval [%d]",
bitfury->drv->name,
board_id + 1, (int)disable_interval);
#ifdef FILELOG
filelog(info, "%s: reenabled power on BOARD%d: time interval [%d]",
bitfury->drv->name,
board_id + 1, (int)disable_interval);
#endif
}
#endif
#ifdef MINER_X6
/* disable power on chain 1 only if chips on both chains failed
* as chain 2 data channel depends on chain 1 */
if ((total_chips_chain1 == disabled_chips_chain1) &&
(info->chipboard[board_id].p_chain1_enabled == 1) &&
(info->chipboard[board_id].power2_disabled == true)) {
disable_power_chain(bitfury, board_id, 0);
/* increase disable counter until we reach long enough work time */
time_t work_interval = curr_time - info->chipboard[board_id].power1_enable_time;
if (work_interval < CHAIN_WORK_INTERVAL)
info->chipboard[board_id].power1_disable_count *= 2;
info->chipboard[board_id].power1_disabled = true;
info->chipboard[board_id].power2_disabled = true;
info->chipboard[board_id].power1_disable_time = curr_time;
info->chipboard[board_id].power2_disable_time = curr_time;
info->chipboard[board_id].chips_disabled = info->chipboard[board_id].chips_num;
} else
if ((total_chips_chain2 == disabled_chips_chain2) &&
(info->chipboard[board_id].p_chain2_enabled == 1)) {
disable_power_chain(bitfury, board_id, 2);
/* increase disable counter until we reach long enough work time */
time_t work_interval = curr_time - info->chipboard[board_id].power2_enable_time;
if (work_interval < CHAIN_WORK_INTERVAL)
info->chipboard[board_id].power2_disable_count *= 2;
info->chipboard[board_id].power2_disabled = true;
info->chipboard[board_id].power2_disable_time = curr_time;
info->chipboard[board_id].chips_disabled = info->chipboard[board_id].chips_num / 2;
}
/* HW FIX: try to reenable disabled chain */
if ((info->chipboard[board_id].p_chain1_enabled == 0) &&
(info->chipboard[board_id].power1_disabled == true) &&
(curr_time - info->chipboard[board_id].power1_disable_time >= info->chipboard[board_id].power1_disable_count * CHAIN_REENABLE_INTERVAL)) {
time_t disable_interval = curr_time - info->chipboard[board_id].power1_disable_time;
info->chipboard[board_id].power1_disable_time = curr_time;
info->chipboard[board_id].power2_disable_time = curr_time;
info->chipboard[board_id].chips_disabled = 0;
enable_power_chain(bitfury, board_id, 0);
info->chipboard[board_id].power1_enable_time = curr_time;
info->chipboard[board_id].power2_enable_time = curr_time;
info->chipboard[board_id].power1_disabled = false;
info->chipboard[board_id].power2_disabled = false;
/* wait for power chain to enable */
cgsleep_us(POWER_WAIT_INTERVAL);
reinit_x5(info, true);
applog(LOG_NOTICE, "%s: reenabled power on BOARD%d: time interval [%d]",
bitfury->drv->name,
board_id + 1, (int)disable_interval);
#ifdef FILELOG
filelog(info, "%s: reenabled power on BOARD%d: time interval [%d]",
bitfury->drv->name,
board_id + 1, (int)disable_interval);
#endif
} else
if ((info->chipboard[board_id].p_chain2_enabled == 0) &&
(info->chipboard[board_id].power2_disabled == true) &&
(curr_time - info->chipboard[board_id].power2_disable_time >= info->chipboard[board_id].power2_disable_count * CHAIN_REENABLE_INTERVAL)) {
time_t disable_interval = curr_time - info->chipboard[board_id].power2_disable_time;
info->chipboard[board_id].power2_disable_time = curr_time;
info->chipboard[board_id].chips_disabled = 0;
enable_power_chain(bitfury, board_id, 2);
info->chipboard[board_id].power2_enable_time = curr_time;
info->chipboard[board_id].power2_disabled = false;
/* wait for power chain to enable */
cgsleep_us(POWER_WAIT_INTERVAL);
reinit_x5(info, true);
applog(LOG_NOTICE, "%s: reenabled chainboard 2 on BOARD%d: time interval [%d]",
bitfury->drv->name,
board_id + 1, (int)disable_interval);
#ifdef FILELOG
filelog(info, "%s: reenabled chainboard 2 on BOARD%d: time interval [%d]",
bitfury->drv->name,
board_id + 1, (int)disable_interval);
#endif
}
#endif
/* switch renonce chip to next board */
if ((info->renonce_chips == 1) &&
(renonce_chip_address[board_id].board_id == board_id) &&
#ifdef MINER_X5
(info->chipboard[board_id].power_disabled == true)) {
#endif
#ifdef MINER_X6
(info->chipboard[board_id].power1_disabled == true) &&
(info->chipboard[board_id].power2_disabled == true)) {
#endif
uint8_t next_board_id = (board_id + 1) % CHIPBOARD_NUM;
uint8_t next_bcm250_id = renonce_chip_address[board_id].bcm250_id;
uint8_t next_chip_id = renonce_chip_address[board_id].chip_id;
/* board id should be set last */
renonce_chip_address[next_board_id].bcm250_id = next_bcm250_id;
renonce_chip_address[next_board_id].chip_id = next_chip_id;
renonce_chip_address[next_board_id].board_id = next_board_id;
info->chipboard[next_board_id].bcm250[next_bcm250_id].chips[next_chip_id].status = UNINITIALIZED;
applog(LOG_NOTICE, "%s: changed renonce chip address to: [%d:%d:%2d]",
bitfury->drv->name,
next_board_id, next_bcm250_id, next_chip_id);
renonce_chip_address[board_id].board_id = -1;
renonce_chip_address[board_id].bcm250_id = -1;
renonce_chip_address[board_id].chip_id = -1;
}
}
}
}
cgsleep_us(HWMONITOR_DELAY);
}
applog(LOG_INFO, "%s: hwmonitor_thr: exiting...", bitfury->drv->name);
return NULL;
}
static void *bitfury_alarm(void *userdata)
{
struct cgpu_info *bitfury = (struct cgpu_info *)userdata;
struct bitfury16_info *info = (struct bitfury16_info *)(bitfury->device_data);
struct pool *pool;
int i;
time_t curr_time_t;
struct timeval curr_time;
applog(LOG_INFO, "%s: started alarm thread", bitfury->drv->name);
/* blink lamps once */
led_red_enable(info);
led_green_enable(info);
cgsleep_ms(1000);
led_red_disable(info);
led_green_disable(info);
buzzer_disable(info);
applog(LOG_INFO, "%s: alarm loop started", bitfury->drv->name);
while (bitfury->shutdown == false) {
curr_time_t = time(NULL);
gettimeofday(&curr_time, NULL);
/* check if there are enabled pools present */
bool idle = true;
for (i = 0; i < total_pools; i++) {
pool = pools[i];
if (pool->idle == false)
idle = false;
}
if (idle == true)
info->a_net = true;
else
info->a_net = false;
/* temperature alarm processing */
if ((info->a_temp == true) && (info->a_ichain == false)) {
if (timediff_us(info->led_red_switch, curr_time) >= LED_RED_INTERVAL) {
if (info->led_red_enabled == true)
led_red_disable(info);
else
led_red_enable(info);
}
/* enable buzzer */
if (timediff_us(info->buzzer_switch, curr_time) >= BUZZER_INTERVAL) {
if (info->buzzer_enabled == true)
buzzer_disable(info);
else
buzzer_enable(info);
}
} else if ((info->a_ichain == false) && (info->a_net == false)) {
if (info->led_red_enabled == true)
led_red_disable(info);
if (info->buzzer_enabled == true)
buzzer_disable(info);
}
/* power chain alarm processing */
if ((info->a_ichain == true) && (info->a_temp == false)) {
if (timediff_us(info->led_red_switch, curr_time) >= LED_RED_INTERVAL) {
if (info->led_red_enabled == true)
led_red_disable(info);
else
led_red_enable(info);
}
if (info->ialarm_buzzer == false) {
buzzer_enable(info);
cgsleep_ms(1000);
buzzer_disable(info);
info->ialarm_buzzer = true;
}
/* enable buzzer */
if (curr_time_t - info->ialarm_start >= info->ialarm_count * ICHAIN_ALARM_INTERVAL) {
buzzer_enable(info);
cgsleep_ms(1000);
buzzer_disable(info);
}
} else if ((info->a_temp == false) && (info->a_net == false)) {
if (info->led_red_enabled == true)
led_red_disable(info);
if (info->buzzer_enabled == true)
buzzer_disable(info);
}
/* blink green lamp if there are enabled pools present and no alarms active */
if ((info->a_net == false) && (info->a_temp == false) && (info->a_ichain == false)) {
if (info->led_red_enabled == true)
led_red_disable(info);
if (timediff_us(info->led_green_switch, curr_time) >= LED_GREEN_INTERVAL) {
if (info->led_green_enabled == true)
led_green_disable(info);
else
led_green_enable(info);
}
} else {
if (info->led_green_enabled == true)
led_green_disable(info);
if ((info->a_temp == false) && (info->a_ichain == false)) {
if (timediff_us(info->led_red_switch, curr_time) >= LED_RED_NET_INTERVAL) {
if (info->led_red_enabled == true)
led_red_disable(info);
else
led_red_enable(info);
}
}
}
cgsleep_us(ALARM_DELAY);
}
led_red_disable(info);
led_green_disable(info);
buzzer_disable(info);
applog(LOG_INFO, "%s: alarm_thr: exiting...", bitfury->drv->name);
return NULL;
}
static void *bitfury_statistics(void *userdata)
{
struct cgpu_info *bitfury = (struct cgpu_info *)userdata;
struct bitfury16_info *info = (struct bitfury16_info *)(bitfury->device_data);
struct timeval start_time, stop_time;
uint8_t board_id, bcm250_id, chip_id;
float u_board;
float i_total;
float p_total;
float u_chip;
float p_chip;
time_t time0 = time(NULL);
time_t time1 = time(NULL);
time_t time2;
/* statistics calculation loop */
while (bitfury->shutdown == false) {
time2 = time(NULL);
if (time2 - time1 >= AVG_TIME_DELTA) {
gettimeofday(&start_time, NULL);
u_board = 0.0;
i_total = 0.0;
p_total = 0.0;
u_chip = 0.0;
p_chip = 0.0;
info->chips_failed = 0;
info->chips_disabled = 0;
for (board_id = 0; board_id < CHIPBOARD_NUM; board_id++) {
if (info->chipboard[board_id].detected == true) {
info->chipboard[board_id].chips_failed = 0;
info->chips_disabled += info->chipboard[board_id].chips_disabled;
/* concentrator loop */
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;
info->chipboard[board_id].bcm250[bcm250_id].chips_failed = 0;
/* chips loop */
for (chip_id = first_good_chip; chip_id < last_good_chip; chip_id++) {
if (info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status >= FAILING) {
info->chipboard[board_id].bcm250[bcm250_id].chips_failed++;
info->chipboard[board_id].chips_failed++;
info->chips_failed++;
}
if (opt_bf16_stats_enabled) {
get_average(&info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].task_switch,
(float)info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].task_switch_dx,
(float)(time2 - time1), AVG_TIME_INTERVAL);
get_average(&info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status_cmd,
(float)info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status_cmd_dx,
(float)(time2 - time1), AVG_TIME_INTERVAL);
get_average(&info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status_cmd_none,
(float)info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status_cmd_none_dx,
(float)(time2 - time1), AVG_TIME_INTERVAL);
get_average(&info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].nonces,
(float)info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].nonces_dx,
(float)(time2 - time1), AVG_TIME_INTERVAL);
get_average(&info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].hashrate,
(float)info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].nonces_dx,
(float)(time2 - time1), AVG_TIME_INTERVAL);
get_average(&info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].hashrate_good,
(float)info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].nonces_good_dx,
(float)(time2 - time1), AVG_TIME_INTERVAL);
get_average(&info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].hashrate_diff,
(float)info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].nonces_diff_dx,
(float)(time2 - time1), AVG_TIME_INTERVAL);
get_average(&info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].hashrate_bad,
(float)info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].nonces_bad_dx,
(float)(time2 - time1), AVG_TIME_INTERVAL);
if (opt_bf16_renonce != RENONCE_DISABLED) {
get_average(&info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].hashrate_re,
(float)info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].nonces_re_dx,
(float)(time2 - time1), AVG_TIME_INTERVAL);
get_average(&info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].hashrate_re_good,
(float)info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].nonces_re_good_dx,
(float)(time2 - time1), AVG_TIME_INTERVAL);
get_average(&info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].hashrate_re_bad,
(float)info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].nonces_re_bad_dx,
(float)(time2 - time1), AVG_TIME_INTERVAL);
}
}
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].task_switch_dx = 0;
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status_cmd_dx = 0;
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status_cmd_none_dx = 0;
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].nonces_dx = 0;
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].nonces_good_dx = 0;
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].nonces_diff_dx = 0;
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].nonces_bad_dx = 0;
if (opt_bf16_renonce != RENONCE_DISABLED) {
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].nonces_re_dx = 0;
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].nonces_re_good_dx = 0;
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].nonces_re_bad_dx = 0;
}
if (opt_bf16_stats_enabled) {
if (opt_bf16_renonce != RENONCE_DISABLED)
applog(LOG_NOTICE, "STATS: chp [%d:%d:%2d], tsk/s [%4.0f], "
"ncs/s [%4.0f], sts/s [%3.0f], none/s [%3.0f], hr/s [%8.3f] hr+/s [%8.3f] rhr/s [%8.3f]",
board_id, bcm250_id, chip_id,
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].task_switch,
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].nonces,
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status_cmd,
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status_cmd_none,
CHIP_COEFF * info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].hashrate,
CHIP_COEFF * info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].hashrate_good,
CHIP_COEFF * (info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].hashrate_good +
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].hashrate_re_good));
else
applog(LOG_NOTICE, "STATS: chp [%d:%d:%2d], tsk/s [%4.0f], "
"ncs/s [%3.0f], sts/s [%3.0f], none/s [%3.0f], hr/s [%8.3f] hr+/s [%8.3f]",
board_id, bcm250_id, chip_id,
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].task_switch,
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].nonces,
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status_cmd,
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status_cmd_none,
CHIP_COEFF * info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].hashrate,
CHIP_COEFF * info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].hashrate_good);
}
}
if (opt_bf16_stats_enabled) {
get_average(&info->chipboard[board_id].bcm250[bcm250_id].task_switch,
(float)info->chipboard[board_id].bcm250[bcm250_id].task_switch_dx,
(float)(time2 - time1), AVG_TIME_INTERVAL);
get_average(&info->chipboard[board_id].bcm250[bcm250_id].status_cmd,
(float)info->chipboard[board_id].bcm250[bcm250_id].status_cmd_dx,
(float)(time2 - time1), AVG_TIME_INTERVAL);
get_average(&info->chipboard[board_id].bcm250[bcm250_id].status_cmd_none,
(float)info->chipboard[board_id].bcm250[bcm250_id].status_cmd_none_dx,
(float)(time2 - time1), AVG_TIME_INTERVAL);
get_average(&info->chipboard[board_id].bcm250[bcm250_id].nonces,
(float)info->chipboard[board_id].bcm250[bcm250_id].nonces_dx,
(float)(time2 - time1), AVG_TIME_INTERVAL);
get_average(&info->chipboard[board_id].bcm250[bcm250_id].hashrate,
(float)info->chipboard[board_id].bcm250[bcm250_id].nonces_dx,
(float)(time2 - time1), AVG_TIME_INTERVAL);
get_average(&info->chipboard[board_id].bcm250[bcm250_id].hashrate_good,
(float)info->chipboard[board_id].bcm250[bcm250_id].nonces_good_dx,
(float)(time2 - time1), AVG_TIME_INTERVAL);
get_average(&info->chipboard[board_id].bcm250[bcm250_id].hashrate_diff,
(float)info->chipboard[board_id].bcm250[bcm250_id].nonces_diff_dx,
(float)(time2 - time1), AVG_TIME_INTERVAL);
get_average(&info->chipboard[board_id].bcm250[bcm250_id].hashrate_bad,
(float)info->chipboard[board_id].bcm250[bcm250_id].nonces_bad_dx,
(float)(time2 - time1), AVG_TIME_INTERVAL);
if (opt_bf16_renonce != RENONCE_DISABLED) {
get_average(&info->chipboard[board_id].bcm250[bcm250_id].hashrate_re,
(float)info->chipboard[board_id].bcm250[bcm250_id].nonces_re_dx,
(float)(time2 - time1), AVG_TIME_INTERVAL);
get_average(&info->chipboard[board_id].bcm250[bcm250_id].hashrate_re_good,
(float)info->chipboard[board_id].bcm250[bcm250_id].nonces_re_good_dx,
(float)(time2 - time1), AVG_TIME_INTERVAL);
get_average(&info->chipboard[board_id].bcm250[bcm250_id].hashrate_re_bad,
(float)info->chipboard[board_id].bcm250[bcm250_id].nonces_re_bad_dx,
(float)(time2 - time1), AVG_TIME_INTERVAL);
}
}
info->chipboard[board_id].bcm250[bcm250_id].task_switch_dx = 0;
info->chipboard[board_id].bcm250[bcm250_id].status_cmd_dx = 0;
info->chipboard[board_id].bcm250[bcm250_id].status_cmd_none_dx = 0;
info->chipboard[board_id].bcm250[bcm250_id].nonces_dx = 0;
info->chipboard[board_id].bcm250[bcm250_id].nonces_good_dx = 0;
info->chipboard[board_id].bcm250[bcm250_id].nonces_diff_dx = 0;
info->chipboard[board_id].bcm250[bcm250_id].nonces_bad_dx = 0;
if (opt_bf16_renonce != RENONCE_DISABLED) {
info->chipboard[board_id].bcm250[bcm250_id].nonces_re_dx = 0;
info->chipboard[board_id].bcm250[bcm250_id].nonces_re_good_dx = 0;
info->chipboard[board_id].bcm250[bcm250_id].nonces_re_bad_dx = 0;
}
}
if (opt_bf16_stats_enabled) {
get_average(&info->chipboard[board_id].task_switch,
(float)info->chipboard[board_id].task_switch_dx,
(float)(time2 - time1), AVG_TIME_INTERVAL);
get_average(&info->chipboard[board_id].status_cmd,
(float)info->chipboard[board_id].status_cmd_dx,
(float)(time2 - time1), AVG_TIME_INTERVAL);
get_average(&info->chipboard[board_id].status_cmd_none,
(float)info->chipboard[board_id].status_cmd_none_dx,
(float)(time2 - time1), AVG_TIME_INTERVAL);
get_average(&info->chipboard[board_id].nonces,
(float)info->chipboard[board_id].nonces_dx,
(float)(time2 - time1), AVG_TIME_INTERVAL);
}
get_average(&info->chipboard[board_id].hashrate,
(float)info->chipboard[board_id].nonces_dx,
(float)(time2 - time1), AVG_TIME_INTERVAL);
get_average(&info->chipboard[board_id].hashrate_good,
(float)info->chipboard[board_id].nonces_good_dx,
(float)(time2 - time1), AVG_TIME_INTERVAL);
get_average(&info->chipboard[board_id].hashrate_diff,
(float)info->chipboard[board_id].nonces_diff_dx,
(float)(time2 - time1), AVG_TIME_INTERVAL);
get_average(&info->chipboard[board_id].hashrate_bad,
(float)info->chipboard[board_id].nonces_bad_dx,
(float)(time2 - time1), AVG_TIME_INTERVAL);
info->chipboard[board_id].task_switch_dx = 0;
info->chipboard[board_id].status_cmd_dx = 0;
info->chipboard[board_id].status_cmd_none_dx = 0;
info->chipboard[board_id].nonces_dx = 0;
info->chipboard[board_id].nonces_good_dx = 0;
info->chipboard[board_id].nonces_diff_dx = 0;
info->chipboard[board_id].nonces_bad_dx = 0;
u_board += (info->chipboard[board_id].u_board + U_LOSS);
#ifdef MINER_X5
i_total += (info->chipboard[board_id].i_chain1);
u_chip += (info->chipboard[board_id].u_chain1);
p_chip += (info->chipboard[board_id].p_chain1);
#endif
#ifdef MINER_X6
i_total += (info->chipboard[board_id].i_chain1 + info->chipboard[board_id].i_chain2);
u_chip += (info->chipboard[board_id].u_chain1 + info->chipboard[board_id].u_chain2);
p_chip += (info->chipboard[board_id].p_chain1 + info->chipboard[board_id].p_chain2);
#endif
p_total += info->chipboard[board_id].p_board;
if (opt_bf16_renonce != RENONCE_DISABLED) {
get_average(&info->chipboard[board_id].hashrate_re,
(float)info->chipboard[board_id].nonces_re_dx,
(float)(time2 - time1), AVG_TIME_INTERVAL);
get_average(&info->chipboard[board_id].hashrate_re_good,
(float)info->chipboard[board_id].nonces_re_good_dx,
(float)(time2 - time1), AVG_TIME_INTERVAL);
get_average(&info->chipboard[board_id].hashrate_re_bad,
(float)info->chipboard[board_id].nonces_re_bad_dx,
(float)(time2 - time1), AVG_TIME_INTERVAL);
info->chipboard[board_id].nonces_re_dx = 0;
info->chipboard[board_id].nonces_re_good_dx = 0;
info->chipboard[board_id].nonces_re_bad_dx = 0;
}
get_average(&info->chipboard[board_id].txrx_speed,
(float)info->chipboard[board_id].bytes_transmitted_dx,
(float)(time2 - time1), AVG_TIME_INTERVAL);
info->chipboard[board_id].bytes_transmitted_dx = 0;
if (opt_bf16_stats_enabled) {
if (opt_bf16_renonce != RENONCE_DISABLED) {
applog(LOG_NOTICE, "STATS: board [%d] hrate: good: [%8.3f] re_good: [%8.3f] => "
"[%8.3f] toren: [%8.3f] bad: [%8.3f] total: [%8.3f]",
board_id,
CHIP_COEFF * (info->chipboard[board_id].hashrate_good),
CHIP_COEFF * (info->chipboard[board_id].hashrate_re_good),
CHIP_COEFF * (info->chipboard[board_id].hashrate_good + info->chipboard[board_id].hashrate_re_good),
CHIP_COEFF * (info->chipboard[board_id].hashrate - info->chipboard[board_id].hashrate_good),
CHIP_COEFF * (info->chipboard[board_id].hashrate_bad),
CHIP_COEFF * (info->chipboard[board_id].hashrate));
} else {
applog(LOG_NOTICE, "STATS: board [%d] hrate: good: [%8.3f] "
"bad: [%8.3f] total: [%8.3f]",
board_id,
CHIP_COEFF * (info->chipboard[board_id].hashrate_good),
CHIP_COEFF * (info->chipboard[board_id].hashrate_bad),
CHIP_COEFF * (info->chipboard[board_id].hashrate));
}
#ifdef MINER_X5
applog(LOG_NOTICE, "STATS: TX/RX: [%5.3f] Mbit/s UB: [%3.1f] "
"U1: [%3.1f] I1: [%3.1f] T: [%3.1f] RPM: [%4d] FAN: [%3d]",
8.0 * info->chipboard[board_id].txrx_speed / 1000000,
info->chipboard[board_id].u_board + U_LOSS,
info->chipboard[board_id].u_chain1,
info->chipboard[board_id].i_chain1,
info->chipboard[board_id].temp,
info->chipboard[board_id].rpm,
info->chipboard[board_id].fan_speed);
#endif
#ifdef MINER_X6
applog(LOG_NOTICE, "STATS: TX/RX: [%5.3f] Mbit/s UB: [%3.1f] "
"U1: [%3.1f] U2: [%3.1f] I1: [%3.1f] I2: [%3.1f] T: [%3.1f] RPM: [%4d] FAN: [%3d]",
8.0 * info->chipboard[board_id].txrx_speed / 1000000,
info->chipboard[board_id].u_board + U_LOSS,
info->chipboard[board_id].u_chain1,
info->chipboard[board_id].u_chain2,
info->chipboard[board_id].i_chain1,
info->chipboard[board_id].i_chain2,
info->chipboard[board_id].temp,
info->chipboard[board_id].rpm,
info->chipboard[board_id].fan_speed);
#endif
applog(LOG_NOTICE, "STATS: ver: [%d] fw: [%d] hwid: [%s]",
info->chipboard[board_id].board_ver,
info->chipboard[board_id].board_fwver,
info->chipboard[board_id].board_hwid);
}
}
}
if (opt_bf16_stats_enabled) {
get_average(&info->task_switch,
(float)info->task_switch_dx,
(float)(time2 - time1), AVG_TIME_INTERVAL);
get_average(&info->status_cmd,
(float)info->status_cmd_dx,
(float)(time2 - time1), AVG_TIME_INTERVAL);
get_average(&info->status_cmd_none,
(float)info->status_cmd_none_dx,
(float)(time2 - time1), AVG_TIME_INTERVAL);
get_average(&info->chipboard[board_id].nonces,
(float)info->chipboard[board_id].nonces_dx,
(float)(time2 - time1), AVG_TIME_INTERVAL);
}
get_average(&info->hashrate,
(float)info->nonces_dx,
(float)(time2 - time1), AVG_TIME_INTERVAL);
get_average(&info->hashrate_good,
(float)info->nonces_good_dx,
(float)(time2 - time1), AVG_TIME_INTERVAL);
get_average(&info->hashrate_diff,
(float)info->nonces_diff_dx,
(float)(time2 - time1), AVG_TIME_INTERVAL);
get_average(&info->hashrate_bad,
(float)info->nonces_bad_dx,
(float)(time2 - time1), AVG_TIME_INTERVAL);
info->task_switch_dx = 0;
info->status_cmd_dx = 0;
info->status_cmd_none_dx = 0;
info->nonces_dx = 0;
info->nonces_good_dx = 0;
info->nonces_diff_dx = 0;
info->nonces_bad_dx = 0;
if (opt_bf16_renonce != RENONCE_DISABLED) {
get_average(&info->hashrate_re,
(float)info->nonces_re_dx,
(float)(time2 - time1), AVG_TIME_INTERVAL);
get_average(&info->hashrate_re_good,
(float)info->nonces_re_good_dx,
(float)(time2 - time1), AVG_TIME_INTERVAL);
get_average(&info->hashrate_re_bad,
(float)info->nonces_re_bad_dx,
(float)(time2 - time1), AVG_TIME_INTERVAL);
info->nonces_re_dx = 0;
info->nonces_re_good_dx = 0;
info->nonces_re_bad_dx = 0;
}
time1 = time2;
gettimeofday(&stop_time, NULL);
uint32_t uptime = time2 - time0;
uint32_t hours = uptime / 3600;
uint8_t minutes = (uptime - hours * 3600) / 60;
uint8_t seconds = uptime - hours * 3600 - minutes * 60;
info->u_avg = u_board / info->active_chipboard_num;
info->i_total = i_total;
info->p_total = p_total;
info->u_chip = u_chip;
info->p_chip = p_chip;
if (opt_bf16_stats_enabled) {
if (opt_bf16_renonce != RENONCE_DISABLED) {
applog(LOG_NOTICE, "STATS: rencs: [%d] stale: [%d] nws: [%d] rnws: [%d] failed: [%d]",
info->renonce_list->count,
info->stale_work_list->count,
info->noncework_list->count,
info->renoncework_list->count,
info->chips_failed);
applog(LOG_NOTICE, "STATS: %4.0fGH/s osc: 0x%02x re_osc: 0x%02x "
"%3.1fV %3.1fA %4.1fW %.3fW/GH",
CHIP_COEFF * (info->hashrate_good + info->hashrate_re_good),
bf16_chip_clock,
bf16_renonce_chip_clock,
info->u_avg,
info->i_total,
info->p_total,
(info->a_net == true) ?
0.0 :
info->p_total / (CHIP_COEFF * (info->hashrate_good + info->hashrate_re_good)));
applog(LOG_NOTICE, "STATS: TOTAL: %5.1fGH/s %5.3fV %3.1fA %5.2fW "
"CHIP: %5.1fGH/s GOOD: %4.1fGH/s RENONCE: %4.1fGH/s BAD: %4.1fGH/s",
CHIP_COEFF * info->hashrate / (info->chips_num - info->renonce_chips - info->chips_failed),
info->u_chip / (info->chips_num - info->chips_disabled),
(info->a_net == true) ? 0.0 : info->p_chip / info->u_chip,
info->p_chip / (info->chips_num - info->chips_disabled),
CHIP_COEFF * (info->hashrate_good + info->hashrate_re_good) / (info->chips_num - info->renonce_chips - info->chips_failed),
CHIP_COEFF * info->hashrate_good / (info->chips_num - info->renonce_chips - info->chips_failed),
CHIP_COEFF * info->hashrate_re_good / (info->chips_num - info->renonce_chips - info->chips_failed),
CHIP_COEFF * info->hashrate_re_bad / (info->chips_num - info->renonce_chips - info->chips_failed));
#if 1
applog(LOG_NOTICE, "STATS: m0: [%lu] mm0: [%lu] m1: [%lu] mm1: [%lu] m2: [%lu] mm2: [%lu] "
"m3: [%lu] mm3: [%lu] um: [%lu]",
info->stage0_match / (time2 - time0),
info->stage0_mismatch / (time2 - time0),
info->stage1_match / (time2 - time0),
info->stage1_mismatch / (time2 - time0),
info->stage2_match / (time2 - time0),
info->stage2_mismatch / (time2 - time0),
info->stage3_match / (time2 - time0),
info->stage3_mismatch / (time2 - time0),
info->unmatched / (time2 - time0));
#endif
} else {
applog(LOG_NOTICE, "STATS: stale: [%d] nws: [%d]",
info->stale_work_list->count, info->noncework_list->count);
applog(LOG_NOTICE, "STATS: %4.0fGH/s osc: 0x%02x"
"%3.1fV %3.1fA %4.1fW %.3fW/GH",
CHIP_COEFF * info->hashrate_good,
bf16_chip_clock,
info->u_avg,
info->i_total,
info->p_total,
(info->a_net == true) ?
0.0 :
info->p_total / (CHIP_COEFF * info->hashrate_good));
applog(LOG_NOTICE, "STATS: TOTAL: %5.1fGH/s %5.3fV %3.1fA %5.2fW "
"CHIP: %5.1fGH/s GOOD: %4.1fGH/s BAD: %4.1fGH/s",
CHIP_COEFF * info->hashrate / (info->chips_num - info->chips_failed),
info->u_chip / (info->chips_num - info->chips_disabled),
(info->a_net == true) ? 0.0 : info->p_chip / info->u_chip,
info->p_chip / (info->chips_num - info->chips_disabled),
CHIP_COEFF * info->hashrate_good / (info->chips_num - info->chips_failed),
CHIP_COEFF * info->hashrate_good / (info->chips_num - info->chips_failed),
CHIP_COEFF * info->hashrate_bad / (info->chips_num - info->chips_failed));
}
applog(LOG_NOTICE, "STATS: uptime: [%4d:%02d:%02d] time elapsed: [%.6f] ",
hours, minutes, seconds, timediff(start_time, stop_time));
}
}
cgsleep_us(STATISTICS_DELAY);
}
applog(LOG_INFO, "%s: statistics_thr: exiting...", bitfury->drv->name);
return NULL;
}
static bool bitfury16_thread_prepare(struct thr_info *thr)
{
struct cgpu_info *bitfury = thr->cgpu;
struct bitfury16_info *info = (struct bitfury16_info *)(bitfury->device_data);
info->thr = thr;
if (thr_info_create(&(info->chipworker_thr), NULL, bitfury_chipworker, (void *)bitfury)) {
applog(LOG_ERR, "%s: %s() chipworker thread create failed",
bitfury->drv->name, __func__);
return false;
}
pthread_detach(info->chipworker_thr.pth);
applog(LOG_INFO, "%s: thread prepare: starting chipworker thread", bitfury->drv->name);
if (thr_info_create(&(info->nonceworker_thr), NULL, bitfury_nonceworker, (void *)bitfury)) {
applog(LOG_ERR, "%s: %s() nonceworker thread create failed",
bitfury->drv->name, __func__);
return false;
}
pthread_detach(info->nonceworker_thr.pth);
applog(LOG_INFO, "%s: thread prepare: starting nonceworker thread", bitfury->drv->name);
if (opt_bf16_renonce != RENONCE_DISABLED) {
if (thr_info_create(&(info->renonceworker_thr), NULL, bitfury_renonceworker, (void *)bitfury)) {
applog(LOG_ERR, "%s: %s() renonceworker thread create failed",
bitfury->drv->name, __func__);
return false;
}
pthread_detach(info->renonceworker_thr.pth);
applog(LOG_INFO, "%s: thread prepare: starting renonceworker thread", bitfury->drv->name);
}
if (thr_info_create(&(info->hwmonitor_thr), NULL, bitfury_hwmonitor, (void *)bitfury)) {
applog(LOG_ERR, "%s: %s() hwmonitor thread create failed",
bitfury->drv->name, __func__);
return false;
}
pthread_detach(info->hwmonitor_thr.pth);
applog(LOG_INFO, "%s: thread prepare: starting hwmonitor thread", bitfury->drv->name);
if (thr_info_create(&(info->alarm_thr), NULL, bitfury_alarm, (void *)bitfury)) {
applog(LOG_ERR, "%s: %s() alarm thread create failed",
bitfury->drv->name, __func__);
return false;
}
pthread_detach(info->alarm_thr.pth);
applog(LOG_INFO, "%s: thread prepare: starting alarm thread", bitfury->drv->name);
if (thr_info_create(&(info->statistics_thr), NULL, bitfury_statistics, (void *)bitfury)) {
applog(LOG_ERR, "%s: %s() statistics thread create failed",
bitfury->drv->name, __func__);
return false;
}
pthread_detach(info->statistics_thr.pth);
applog(LOG_INFO, "%s: thread prepare: starting statistics thread", bitfury->drv->name);
return true;
}
static int64_t bitfury16_scanwork(struct thr_info *thr)
{
struct cgpu_info *bitfury = thr->cgpu;
struct bitfury16_info *info = bitfury->device_data;
int64_t hashcount = 0;
applog(LOG_INFO, "%s: scan work", bitfury->drv->name);
mutex_lock(&info->nonces_good_lock);
if (info->nonces_good_cg) {
hashcount += 0xffffffffull * info->nonces_good_cg;
info->nonces_good_cg = 0;
}
mutex_unlock(&info->nonces_good_lock);
return hashcount;
}
static void prepare_work(struct cgpu_info *bitfury, struct work *work, bool rolled)
{
struct bitfury16_info *info = (struct bitfury16_info *)bitfury->device_data;
bf_workd_t* wdata = cgmalloc(sizeof(bf_workd_t));
wdata->work = work;
wdata->rolled = rolled;
wdata->generated = time(NULL);
/* generate task payload */
cg_memcpy(wdata->payload.midstate, work->midstate, 32);
wdata->payload.m7 = *(uint32_t *)(work->data + 64);
wdata->payload.ntime = *(uint32_t *)(work->data + 68);
wdata->payload.nbits = *(uint32_t *)(work->data + 72);
workd_list_push(info->work_list, wdata);
}
static bool bitfury16_queue_full(struct cgpu_info *bitfury)
{
struct bitfury16_info *info = (struct bitfury16_info *)bitfury->device_data;
struct work *work, *usework;
uint16_t need = 0;
uint16_t generated = 0;
uint16_t roll, roll_limit;
bool rolled;
if (info->initialised == false) {
cgsleep_us(30);
return true;
}
L_LOCK(info->work_list);
uint16_t work_count = info->work_list->count;
L_UNLOCK(info->work_list);
if (work_count < WORK_QUEUE_LEN)
need = WORK_QUEUE_LEN - work_count;
else
return true;
/* Ensure we do enough rolling to reduce CPU
but dont roll too much to have them end up stale */
work = get_queued(bitfury);
if (work) {
roll_limit = work->drv_rolllimit;
roll = 0;
L_LOCK(info->work_list);
do {
if (roll == 0) {
usework = work;
rolled = false;
} else {
usework = copy_work_noffset(work, roll);
rolled = true;
}
prepare_work(bitfury, usework, rolled);
generated++;
} while ((--need > 0) && (++roll <= roll_limit));
L_UNLOCK(info->work_list);
applog(LOG_INFO, "%s: queue full: generated %d works", bitfury->drv->name, generated);
} else
cgsleep_us(30);
if (need > 0)
return false;
else
return true;
}
static void bitfury16_flush_work(struct cgpu_info *bitfury)
{
struct bitfury16_info *info = (struct bitfury16_info *)bitfury->device_data;
uint16_t flushed = 0;
if (info->initialised == false)
return;
bf_works_t works;
/* flush work list */
L_LOCK(info->work_list);
L_LOCK(info->stale_work_list);
bf_data_t* wdata = info->work_list->head;
while (wdata != NULL) {
workd_list_push(info->stale_work_list, WORKD(wdata));
workd_list_remove(info->work_list, &works);
wdata = info->work_list->head;
flushed++;
}
L_UNLOCK(info->stale_work_list);
L_UNLOCK(info->work_list);
/* flush nonces list */
L_LOCK(info->noncework_list);
bf_data_t* nwdata = info->noncework_list->head;
while (nwdata != NULL) {
noncework_list_pop(info->noncework_list);
nwdata = info->noncework_list->head;
}
L_UNLOCK(info->noncework_list);
if (opt_bf16_renonce != RENONCE_DISABLED) {
/* flush renonces list */
L_LOCK(info->renonce_list);
bf_data_t* rdata = info->renonce_list->head;
while (rdata != NULL) {
renonce_list_pop(info->renonce_list);
rdata = info->renonce_list->head;
}
L_UNLOCK(info->renonce_list);
/* flush renoncework list */
L_LOCK(info->renoncework_list);
bf_data_t* rnwdata = info->renoncework_list->head;
while (rnwdata != NULL) {
renoncework_list_pop(info->renoncework_list);
rnwdata = info->renoncework_list->head;
}
L_UNLOCK(info->renoncework_list);
}
applog(LOG_INFO, "%s: flushed %d works", bitfury->drv->name, flushed);
}
static struct api_data *bitfury16_api_stats(struct cgpu_info *bitfury)
{
uint8_t board_id, bcm250_id, chip_id;
struct bitfury16_info *info = bitfury->device_data;
char data[128];
char value[128];
struct api_data *root = NULL;
applog(LOG_INFO, "%s: API stats", bitfury->drv->name);
if (info->initialised == false)
return NULL;
#ifdef MINER_X5
root = api_add_string(root, "Device name", "Bitfury X5", true);
#endif
#ifdef MINER_X6
root = api_add_string(root, "Device name", "Bitfury X6", true);
#endif
root = api_add_uint8(root, "Boards number", &info->chipboard_num, false);
root = api_add_uint8(root, "Boards detected", &info->chipboard_num, false);
root = api_add_uint8(root, "Chips number", &info->chips_num, false);
/* software revision chages according to comments in CHANGELOG */
root = api_add_string(root, "hwv1", "1", true);
root = api_add_string(root, "hwv2", "2", true);
root = api_add_string(root, "hwv3", "11", true);
root = api_add_string(root, "hwv4", "0", true);
root = api_add_string(root, "hwv5", "0", true);
/* U avg */
sprintf(value, "%.1f", info->u_avg);
root = api_add_string(root, "U avg", value, true);
/* I total */
sprintf(value, "%.1f", info->i_total);
root = api_add_string(root, "I total", value, true);
/* P total */
sprintf(value, "%.1f", info->p_total);
root = api_add_string(root, "P total", value, true);
if (opt_bf16_renonce != RENONCE_DISABLED) {
/* Efficiency */
sprintf(value, "%.3f",
(info->a_net == true) ?
0.0 :
info->p_total / (CHIP_COEFF * (info->hashrate_good + info->hashrate_re_good)));
root = api_add_string(root, "Efficiency", value, true);
/* Chip GHS total avg */
sprintf(value, "%.1f", CHIP_COEFF * info->hashrate / (info->chips_num - info->renonce_chips - info->chips_failed));
root = api_add_string(root, "Chip GHS total avg", value, true);
/* Chip GHS avg */
sprintf(value, "%.1f", CHIP_COEFF * (info->hashrate_good + info->hashrate_re_good) / (info->chips_num - info->renonce_chips - info->chips_failed));
root = api_add_string(root, "Chip GHS avg", value, true);
/* Chip GHS good avg */
sprintf(value, "%.1f", CHIP_COEFF * info->hashrate_good / (info->chips_num - info->renonce_chips - info->chips_failed));
root = api_add_string(root, "Chip GHS good avg", value, true);
/* Chip GHS re avg */
sprintf(value, "%.1f", CHIP_COEFF * info->hashrate_re_good / (info->chips_num - info->renonce_chips - info->chips_failed));
root = api_add_string(root, "Chip GHS re avg", value, true);
/* Chip GHS bad avg */
sprintf(value, "%.1f", CHIP_COEFF * info->hashrate_re_bad / (info->chips_num - info->renonce_chips - info->chips_failed));
root = api_add_string(root, "Chip GHS bad avg", value, true);
} else {
/* Efficiency */
sprintf(value, "%.3f",
(info->a_net == true) ?
0.0 :
info->p_total / (CHIP_COEFF * info->hashrate_good));
root = api_add_string(root, "Efficiency", value, true);
/* Chip GHS total avg */
sprintf(value, "%.1f", CHIP_COEFF * info->hashrate / (info->chips_num - info->chips_failed));
root = api_add_string(root, "Chip GHS total avg", value, true);
/* Chip GHS avg */
sprintf(value, "%.1f", CHIP_COEFF * info->hashrate_good / (info->chips_num - info->chips_failed));
root = api_add_string(root, "Chip GHS avg", value, true);
/* Chip GHS good avg */
sprintf(value, "%.1f", CHIP_COEFF * info->hashrate_good / (info->chips_num - info->chips_failed));
root = api_add_string(root, "Chip GHS good avg", value, true);
/* Chip GHS re avg */
sprintf(value, "%.1f", 0.0);
root = api_add_string(root, "Chip GHS re avg", value, true);
/* Chip GHS bad avg */
sprintf(value, "%.1f", CHIP_COEFF * info->hashrate_bad / (info->chips_num - info->chips_failed));
root = api_add_string(root, "Chip GHS bad avg", value, true);
}
/* U Chip avg */
sprintf(value, "%.3f", info->u_chip / (info->chips_num - info->chips_disabled));
root = api_add_string(root, "U Chip avg", value, true);
/* I Chip avg */
sprintf(value, "%.1f", (info->a_net == true) ? 0.0 : info->p_chip / info->u_chip);
root = api_add_string(root, "I Chip avg", value, true);
/* P Chip avg */
sprintf(value, "%.2f", info->p_chip / (info->chips_num - info->chips_disabled));
root = api_add_string(root, "P Chip avg", value, true);
for (board_id = 0; board_id < CHIPBOARD_NUM; board_id++) {
/* board status */
sprintf(data, "Board%d detected", board_id);
if (info->chipboard[board_id].detected == true)
root = api_add_string(root, data, "1", true);
else
root = api_add_string(root, data, "0", true);
/* number of concentratord on board */
sprintf(data, "Board%d BTC250", board_id);
root = api_add_uint8(root, data, &info->chipboard[board_id].bcm250_num, false);
/* number of chips on board */
sprintf(data, "Board%d BTC16", board_id);
root = api_add_uint8(root, data, &info->chipboard[board_id].chips_num, false);
/* number of good chips on board */
sprintf(data, "Board%d BTC16 good", board_id);
uint8_t chips_good = info->chipboard[board_id].chips_num - info->chipboard[board_id].chips_failed;
root = api_add_uint8(root, data, &chips_good, true);
sprintf(data, "Board%d Clock", board_id);
if (info->chipboard[board_id].detected == true)
sprintf(value, "%d (0x%02x)", bf16_chip_clock, bf16_chip_clock);
else
sprintf(value, "%d (0x%02x)", 0, 0);
root = api_add_string(root, data, value, true);
sprintf(data, "Board%d GHS av", board_id);
if (opt_bf16_renonce != RENONCE_DISABLED) {
sprintf(value, "%.2f",
CHIP_COEFF * (info->chipboard[board_id].hashrate_good + info->chipboard[board_id].hashrate_re_good));
} else {
sprintf(value, "%.2f", CHIP_COEFF * (info->chipboard[board_id].hashrate_good));
}
root = api_add_string(root, data, value, true);
/* number of chips per concentrator */
uint8_t i = 0;
memset(value, 0, sizeof(value));
for (bcm250_id = 0; bcm250_id < BCM250_NUM; bcm250_id++) {
sprintf(data, "Board%d BTC250_%d BTC16", board_id, bcm250_id);
root = api_add_uint8(root, data, &info->chipboard[board_id].bcm250[bcm250_id].chips_num, false);
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;
/* chips loop */
for (chip_id = first_good_chip; chip_id < last_good_chip; chip_id++, i++) {
bf_chip_address_t chip_address;
chip_address.board_id = board_id;
chip_address.bcm250_id = bcm250_id;
chip_address.chip_id = chip_id;
if (info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status < FAILING) {
if ((opt_bf16_renonce != RENONCE_DISABLED) &&
(renonce_chip(chip_address) == 1))
value[i] = 'O';
else
value[i] = 'o';
} else {
if ((opt_bf16_renonce != RENONCE_DISABLED) &&
(renonce_chip(chip_address) == 1))
value[i] = 'X';
else
value[i] = 'x';
}
}
if (bcm250_id != BCM250_NUM - 1)
value[i++] = ' ';
}
sprintf(data, "Board%d BF16 Status", board_id);
root = api_add_string(root, data, value, true);
/* MSP version data */
/* board version */
sprintf(data, "Board%d Ver", board_id);
root = api_add_uint32(root, data, &info->chipboard[board_id].board_ver, false);
/* board firmware version */
sprintf(data, "Board%d FW", board_id);
root = api_add_uint32(root, data, &info->chipboard[board_id].board_fwver, false);
/* board hardware id */
sprintf(data, "Board%d HWID", board_id);
root = api_add_string(root, data, info->chipboard[board_id].board_hwid, true);
/* MSP hw data */
/* T */
sprintf(data, "Board%d T", board_id);
sprintf(value, "%.1f", info->chipboard[board_id].temp);
root = api_add_string(root, data, value, true);
/* UB */
sprintf(data, "Board%d UB", board_id);
sprintf(value, "%.1f", info->chipboard[board_id].u_board);
root = api_add_string(root, data, value, true);
/* P1 */
sprintf(data, "Board%d P1", board_id);
root = api_add_uint8(root, data, &info->chipboard[board_id].p_chain1_enabled, false);
/* P2 */
sprintf(data, "Board%d P2", board_id);
root = api_add_uint8(root, data, &info->chipboard[board_id].p_chain2_enabled, false);
/* U1 */
sprintf(data, "Board%d U1", board_id);
sprintf(value, "%.1f", info->chipboard[board_id].u_chain1);
root = api_add_string(root, data, value, true);
/* U2 */
sprintf(data, "Board%d U2", board_id);
sprintf(value, "%.1f", info->chipboard[board_id].u_chain2);
root = api_add_string(root, data, value, true);
/* I1 */
sprintf(data, "Board%d I1", board_id);
sprintf(value, "%.1f", info->chipboard[board_id].i_chain1);
root = api_add_string(root, data, value, true);
/* I2 */
sprintf(data, "Board%d I2", board_id);
sprintf(value, "%.1f", info->chipboard[board_id].i_chain2);
root = api_add_string(root, data, value, true);
/* RPM */
sprintf(data, "Board%d PRM", board_id);
root = api_add_uint32(root, data, &info->chipboard[board_id].rpm, true);
/* A */
sprintf(data, "Board%d T_Alarm", board_id);
root = api_add_uint8(root, data, &info->chipboard[board_id].a_temp, true);
sprintf(data, "Board%d I1_Alarm", board_id);
root = api_add_uint8(root, data, &info->chipboard[board_id].a_ichain1, true);
sprintf(data, "Board%d I2_Alarm", board_id);
root = api_add_uint8(root, data, &info->chipboard[board_id].a_ichain2, true);
/* F */
sprintf(data, "Board%d F", board_id);
root = api_add_uint8(root, data, &info->chipboard[board_id].fan_speed, false);
/* AI */
sprintf(data, "Board%d AI", board_id);
sprintf(value, "%.1f", info->chipboard[board_id].i_alarm);
root = api_add_string(root, data, value, true);
/* AT */
sprintf(data, "Board%d AT", board_id);
sprintf(value, "%.0f", info->chipboard[board_id].t_alarm);
root = api_add_string(root, data, value, true);
/* AG */
sprintf(data, "Board%d AG", board_id);
sprintf(value, "%.0f", info->chipboard[board_id].t_gisteresis);
root = api_add_string(root, data, value, true);
/* FM */
sprintf(data, "Board%d FM", board_id);
#ifdef MINER_X5
sprintf(value, "%c", info->chipboard[board_id].fan_mode);
#endif
#ifdef MINER_X6
if (manual_pid_enabled == true)
sprintf(value, "A");
else
sprintf(value, "%c", info->chipboard[board_id].fan_mode);
#endif
root = api_add_string(root, data, value, true);
/* TT */
sprintf(data, "Board%d TT", board_id);
sprintf(value, "%.0f", info->chipboard[board_id].target_temp);
root = api_add_string(root, data, value, true);
}
return root;
}
static void bitfury16_shutdown(struct thr_info *thr)
{
struct cgpu_info *bitfury = thr->cgpu;
struct bitfury16_info *info = (struct bitfury16_info *)bitfury->device_data;
uint8_t board_id;
bitfury->shutdown = true;
cgsleep_ms(300);
/* flush next board temp to default value */
if (manual_pid_enabled == false) {
for (board_id = 0; board_id < CHIPBOARD_NUM; board_id++) {
if (info->chipboard[board_id].detected == true) {
if (device_uart_transfer(board_id + 1, "N") < 0)
quit(1, "%s: %s() failed to set BOARD%d next temp",
bitfury->drv->name, __func__, board_id + 1);
applog(LOG_INFO, "%s: set BOARD%d next temp to default value",
bitfury->drv->name, board_id + 1);
}
}
} else {
for (board_id = 0; board_id < CHIPBOARD_NUM; board_id++) {
if (info->chipboard[board_id].detected == true) {
if (device_uart_transfer(board_id + 1, "F") < 0)
quit(1, "%s: %s() failed to set BOARD%d fan speed to auto mode",
bitfury->drv->name, __func__, board_id + 1);
applog(LOG_INFO, "%s: set BOARD%d fan speed to auto mode",
bitfury->drv->name, board_id + 1);
}
}
}
/* disable power chain */
for (board_id = 0; board_id < CHIPBOARD_NUM; board_id++) {
disable_power_chain(bitfury, board_id, 0);
}
mutex_destroy(&info->nonces_good_lock);
/* close devices */
close_spi_device(SPI_CHANNEL1);
close_spi_device(SPI_CHANNEL2);
close_ctrl_device();
close_uart_device(UART_CHANNEL1);
close_uart_device(UART_CHANNEL2);
#ifdef FILELOG
filelog(info, "%s: cgminer stopped", bitfury->drv->name);
fclose(info->logfile);
mutex_destroy(&info->logfile_mutex);
#endif
applog(LOG_INFO, "%s: driver shutdown", bitfury->drv->name);
}
/* Currently hardcoded to BF1 devices */
struct device_drv bitfury16_drv = {
.drv_id = DRIVER_bitfury16,
.dname = "bitfury16",
.name = "BF16",
.drv_detect = bitfury16_detect,
.get_api_stats = bitfury16_api_stats,
.identify_device = bitfury16_identify,
.thread_prepare = bitfury16_thread_prepare,
.hash_work = hash_queued_work,
.scanwork = bitfury16_scanwork,
.queue_full = bitfury16_queue_full,
.flush_work = bitfury16_flush_work,
.thread_shutdown = bitfury16_shutdown
};