Merge remote-tracking branch 'upstream' into merge_383 Conflicts: usbutils.c usbutils.h
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
diff --git a/01-cgminer.rules b/01-cgminer.rules
index 972468c..733a774 100644
--- a/01-cgminer.rules
+++ b/01-cgminer.rules
@@ -30,3 +30,6 @@ ATTRS{idVendor}=="04d8", ATTRS{idProduct}=="f60a", SUBSYSTEMS=="usb", ACTION=="a
#HashFast
ATTRS{idVendor}=="297c", ATTRS{idProduct}=="0001", SUBSYSTEMS=="usb", ACTION=="add", MODE="0666", GROUP="plugdev", ENV{ID_MM_DEVICE_IGNORE}="1"
+
+# BXF
+ATTRS{idVendor}=="198c", ATTRS{idProduct}=="b1f1", SUBSYSTEMS=="usb", ACTION=="add", MODE="0666", GROUP="plugdev"
diff --git a/ASIC-README b/ASIC-README
index bf83045..a535c2b 100644
--- a/ASIC-README
+++ b/ASIC-README
@@ -3,8 +3,8 @@ SUPPORTED DEVICES
Currently supported devices include the Avalon (including BitBurner and
Klondike), the Butterfly Labs SC range of devices, the ASICMINER block
erupters, the BF1 (bitfury) USB (red and blue) devices, KnCminer Mercury,
-Saturn and Jupiter devices, BlackArrow Bitfury devices and upcoming
-Hashfast devices.
+Saturn and Jupiter devices, BlackArrow Bitfury devices, Bi*fury USB devices
+and upcoming Hashfast devices.
No COM ports on windows or TTY devices will be used by cgminer as it
communicates directly with them via USB so it is normal for them to not exist or
@@ -32,7 +32,7 @@ ASICMINER block erupters will come up as AMU.
ASICMINER devices need the --enable-icarus option when compiling cgminer.
Also note that the AMU is managed by the Icarus driver which is detailed
in the FPGA-README. Configuring them uses the same mechanism as outlined
-below for getting started with butterfly labs ASICs.
+below for getting started with USB ASICs.
BlackArrow Bitfury devices
@@ -47,13 +47,14 @@ BITFURY devices
Bitfury devices need the --enable-bitfury option when compiling cgminer.
-Currently only the BPMC BF1 devices AKA redfury/bluefury are supported and
-come up as BF1. There are no options available for them. Bitfury device are
-also set up as per the butterfly labs ASICs below.
+Currently the BPMC/BGMC BF1 devices AKA redfury/bluefury are supported and
+come up as BF1, along with the Bi*fury USB devices which come up as BXF.
+There are no options available for them. Bitfury USB devices are also set up
+as per the USB ASICs below.
-
-GETTING STARTED WITH BUTTERFLY LABS ASICS
+---
+GETTING STARTED WITH USB ASICS
Unlike other software, cgminer uses direct USB communication instead of the
ancient serial USB communication to be much faster, more reliable and use a
@@ -64,9 +65,13 @@ devices requires different drivers.
WINDOWS:
On windows, the direct USB support requires the installation of a WinUSB
-driver (NOT the ftdi_sio driver), and attach it to the Butterfly labs device.
-The easiest way to do this is to use the zadig utility which will install the
-drivers for you and then once you plug in your device you can choose the
+driver (NOT the ftdi_sio driver), and attach it to the chosen USB device.
+When configuring your device, plug it in and wait for windows to attempt to
+install a driver on its own. It may think it has succeeded or failed but wait
+for it to finish regardless. This is NOT the driver you want installed. At this
+point you need to associate your device with the WinUSB driver. The easiest
+way to do this is to use the zadig utility which you must right click on and
+run as administrator. Then once you plug in your device you can choose the
"list all devices" from the "option" menu and you should be able to see the
device as something like: "BitFORCE SHA256 SC". Choose the install or replace
driver option and select WinUSB. You can either google for zadig or download
@@ -103,6 +108,18 @@ After this you can either manually restart udev and re-login, or more easily
just reboot.
+OSX:
+
+On OSX, like Linux, no drivers need to be installed. However some devices
+like the bitfury USB sticks automatically load a driver thinking they're a
+modem and the driver needs to be unloaded for cgminer to work:
+
+sudo kextunload -b com.apple.driver.AppleUSBCDC
+sudo kextunload -b com.apple.driver.AppleUSBCDCACMData
+
+
+---
+
ASIC SPECIFIC COMMANDS
--avalon-auto Adjust avalon overclock frequency dynamically for best hashrate
diff --git a/Makefile.am b/Makefile.am
index 91530c5..b2d72f9 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -69,7 +69,7 @@ cgminer_SOURCES += driver-bitforce.c
endif
if HAS_HASHFAST
-cgminer_SOURCES += driver-hashfast.c driver-hashfast.h hf_protocol.h
+cgminer_SOURCES += driver-hashfast.c driver-hashfast.h hf_protocol.h hf_protocol_be.h
endif
if HAS_BITFURY
diff --git a/NEWS b/NEWS
index a1209b7..f851e42 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,129 @@
+Version 3.8.3 - 23rd November 2013
+
+- Set the bitfury device start times from when we first get valid work.
+- Fix stack corruption of zeroing too much in bf1 driver.
+- Make usb_detect return the cgpu associated with it to check if it succeeds to
+decide on whether to increment the device count or not.
+- Set tv work start time for bxf driver.
+- Age the bxf work items over 90 seconds, not the bf1 work items.
+- Zero the read buffer in _usb_read to avoid stale data and only use stack
+memory instead of using the bulkbuf since it is only used in _usb_read.
+- Leave room for temperatures above 100 degrees and pad consistently for bxf
+statline.
+- Drop json stratum auth failed message log level to verbose.
+- Change the processed value not the bufsiz in response to an end of message
+marker.
+- Don't lose data beyond the end of message in a usb read.
+- Silence irrelevant warning.
+- Only check strlen on end if end exists.
+- Simplify the end of message detection in _usb_read and allow it to return
+without doing another read if the message is already in the buffer.
+- Increase work ageing time to 90 seconds for bxf driver to account for firmware
+changes.
+- Use the age_queued_work function in the bitfury driver.
+- Provide a function to discard queued work based on age.
+- The json_val in api.c is a borrowed reference, not a new one so don't decref
+it.
+- Decrement json references in api.c to not leak memory.
+- line 2913 added urlencode
+- With reliable writes to the avalon there is no need for the sleep delays
+between writes.
+- There is no need to limit usb write transfers to maxpacketsize and it's
+harmful for large transfers on slow devices such as wrt routers.
+- Disable USB stats which were not meant to be enabled by default and add extra
+memory for a memory error when stats are enabled.
+- Set limit and count to integers to not overflow during failed hotplug attempts
+and then not trying again.
+- Update api example compilation instructions.
+
+
+Version 3.8.2 - 16th November 2013
+
+- Add more verbose documentation to the readme files for windows users.
+- Add more information on libusb failure to init telling users to check README
+file.
+- Add information on unloading cdc drivers on osx to README
+- Prevent a deadlock with use of restart_threads by spawning a thread to send
+the driver flush work messages.
+- Set priority of various threads if possible.
+- Add bxf data to api output.
+- Do not hold the mining thread lock in restart_threads when calling the driver
+flush work commands.
+- Send extra work regularly to the bxf device and parse the needwork command by
+sending the amount of work it requests.
+- Allow messages to have arbitrary offsets in the bxf parser in case we have
+lingering buffered data.
+- Send the maxroll command to the bxf driver and store the value to see if we
+need to update it.
+- Add sending of flush command to bxf on flush_work
+- Add flush and version commands to bxf start up, flush buffer and try to parse
+version response string.
+- Abstract out bxf recv message.
+- Add extra bxf commands to usbutils
+- Abstract out bxf send message to allow us to easily add extra commands.
+- Don't run device restart code if the device is not enabled.
+- Expand size of bitfury statline
+- Various driver fixes for bitfury devices, including a flag from when first
+valid work appears.
+- Look up work results in bxf driver from correct variable.
+- Correct incorrect error code in bxf driver for usb writes and add debugging.
+- Add bxf details to usbutils.
+- Implement a statline showing temperature for bxf
+- Add api data for bxf device, sharing the hashrate function with bf1.
+- Count no matching work as a hw error on bxf
+- Add BXF to udev rules.
+- Work id should be hexadecimal in bxf messages.
+- Add unrecognised string debugging to bxf driver.
+- Implement the main scanloop for bxf, trying to prevent it from ntime rolling
+work if the work protocol does not allow it.
+- Parse bxf work submits fully, submitting the results.
+- Provide a function for setting the work ntime.
+- Implement a skeleton parse bxf submit function.
+- Use the bxf read thread to set the device target and send its first work item.
+- Implement a bxf send work function and set update and restart functions to
+sending new work since that's the equivalent for that device.
+- Add temperature parsing to bxf driver
+- Create and destroy a basic bxf read thread.
+- Remove the buffer from bitfury info since it is only used on one pass in the
+bf1 device.
+- Add a rudimentary bxf detect one function.
+- Rename all bf1 specific functions in the bitfury driver, using a switch to
+choose correct function.
+- Rename bitfury_getinfo to bf1_getinfo since it's unique to bf1 devices.
+- Separate out the bf1 reset from bitfury reset.
+- Store the bitfury identity in the info struct.
+- BaB - updated tested OS comment
+- Uniquely identify the BF1 and BXF bitfury devices.
+- Remove the default libusb WinUsb pipe policies that don't suit us.
+- Only set the winusb pipe policy if it doesn't match our requirements instead
+of every transfer.
+- klondike - dont try to flush if not initialised
+- api.c trylock() add missing locklock
+- Use our new zero length packet support directly in windows.
+- Enable support for zero length packet on windows and auto clear pipe stalls.
+- util.c: Decreasing reference count on allocated JSON obects to prevent memory
+leak
+- api.c: Release apisock on error in api()
+- api.c: Release io_data->ptr when releasing io_data in io_free()
+- We can't connect to a GBT pool at all with fix protocol enabled.
+- Initialise the stgd lock mutex earlier to prevent dereferences when pool
+testing occurs before it.
+- Klondike support I2C USB layout also - as KLI
+- Return error codes in avalon_read() if they're not timeouts.
+- Break out of the avalon idle loop if we get a send error.
+- Set avalon ftdi latency to just less than the time it would take to fill the
+ftdi buffer at 115200 baud
+- Update example.conf
+- Only limit packetsize on usb out writes.
+- We must chop up every 64 bytes returned on an ftdi chip, not just the first 2
+bytes so revert to parsing the data internally in the avalon instead of using
+usbutils' simple ftdi parser.
+- Only retry 3 times in hfa_reset.
+- Only add_cgpu in hashfast driver once we have a real driver set up.
+- Clean up properly if hfa_detect_common fails in the hashfast driver.
+- --shares should be scaled to diff1 not absolute number of shares
+
+
Version 3.8.1 - 11th November 2013
- Revert "Send a zero length packet at the end of every usb transfer on windows
diff --git a/README b/README
index 3e19f78..cf2420e 100644
--- a/README
+++ b/README
@@ -235,7 +235,8 @@ See FGPA-README for more information regarding this.
Cgminer should automatically find all of your Avalon ASIC, BFL ASIC, BitForce
FPGAs, Icarus bitstream FPGAs, Klondike ASIC, ASICMINER usb block erupters,
-KnC ASICs, BaB ASICs, Hashfast ASICs and ModMiner FPGAs.
+KnC ASICs, BaB ASICs, Hashfast ASICs, ModMiner FPGAs, BPMC/BGMC BF1 USB ASICs
+and Bi*fury USB ASICs.
---
@@ -244,14 +245,24 @@ SETTING UP USB DEVICES
WINDOWS:
On windows, the direct USB support requires the installation of a WinUSB
-driver (NOT the ftdi_sio driver), and attach it to your devices.
-The easiest way to do this is to use the zadig utility which will install the
-drivers for you and then once you plug in your device you can choose the
+driver (NOT the ftdi_sio driver), and attach it to the chosen USB device.
+When configuring your device, plug it in and wait for windows to attempt to
+install a driver on its own. It may think it has succeeded or failed but wait
+for it to finish regardless. This is NOT the driver you want installed. At this
+point you need to associate your device with the WinUSB driver. The easiest
+way to do this is to use the zadig utility which you must right click on and
+run as administrator. Then once you plug in your device you can choose the
"list all devices" from the "option" menu and you should be able to see the
device as something like: "BitFORCE SHA256 SC". Choose the install or replace
driver option and select WinUSB. You can either google for zadig or download
it from the cgminer directory in the DOWNLOADS link above.
+When you first switch a device over to WinUSB with zadig and it shows that
+correctly on the left of the zadig window, but it still gives permission
+errors, you may need to unplug the USB miner and then plug it back in. Some
+users may need to reboot at this point.
+
+
LINUX:
On linux, the direct USB support requires no drivers at all. However due to
@@ -276,6 +287,19 @@ directory with the following command:
After this you can either manually restart udev and re-login, or more easily
just reboot.
+
+OSX:
+
+On OSX, like Linux, no drivers need to be installed. However some devices
+like the bitfury USB sticks automatically load a driver thinking they're a
+modem and the driver needs to be unloaded for cgminer to work:
+
+sudo kextunload -b com.apple.driver.AppleUSBCDC
+sudo kextunload -b com.apple.driver.AppleUSBCDCACMData
+
+
+---
+
Advanced USB options:
The --usb option can restrict how many Avalon, BFL ASIC, BitForce FPGAs,
diff --git a/api-example.c b/api-example.c
index d14b6aa..26d5a0e 100644
--- a/api-example.c
+++ b/api-example.c
@@ -8,7 +8,7 @@
*/
/* Compile:
- * gcc api-example.c -Icompat/jansson -Icompat/libusb-1.0/libusb -o cgminer-api
+ * gcc api-example.c -Icompat/jansson-2.5 -Icompat/libusb-1.0/libusb -o cgminer-api
*/
#include "config.h"
diff --git a/api.c b/api.c
index 302196d..c82b0d2 100644
--- a/api.c
+++ b/api.c
@@ -719,6 +719,7 @@ static void io_free()
do {
io_next = io_list->next;
+ free(io_list->io_data->ptr);
free(io_list->io_data);
free(io_list);
@@ -4381,12 +4382,12 @@ void api(int api_thr_id)
struct sockaddr_in cli;
socklen_t clisiz;
char cmdbuf[100];
- char *cmd;
+ char *cmd = NULL;
char *param;
bool addrok;
char group;
json_error_t json_err;
- json_t *json_config;
+ json_t *json_config = NULL;
json_t *json_val;
bool isjson;
bool did;
@@ -4399,6 +4400,7 @@ void api(int api_thr_id)
if (!opt_api_listen) {
applog(LOG_DEBUG, "API not running%s", UNAVAILABLE);
+ free(apisock);
return;
}
@@ -4416,6 +4418,7 @@ void api(int api_thr_id)
if (ips == 0) {
applog(LOG_WARNING, "API not running (no valid IPs specified)%s", UNAVAILABLE);
+ free(apisock);
return;
}
}
@@ -4427,6 +4430,7 @@ void api(int api_thr_id)
*apisock = socket(AF_INET, SOCK_STREAM, 0);
if (*apisock == INVSOCK) {
applog(LOG_ERR, "API1 initialisation failed (%s)%s", SOCKERRMSG, UNAVAILABLE);
+ free(apisock);
return;
}
@@ -4438,6 +4442,7 @@ void api(int api_thr_id)
serv.sin_addr.s_addr = inet_addr(localaddr);
if (serv.sin_addr.s_addr == (in_addr_t)INVINETADDR) {
applog(LOG_ERR, "API2 initialisation failed (%s)%s", SOCKERRMSG, UNAVAILABLE);
+ free(apisock);
return;
}
}
@@ -4476,12 +4481,14 @@ void api(int api_thr_id)
if (bound == 0) {
applog(LOG_ERR, "API bind to port %d failed (%s)%s", port, binderror, UNAVAILABLE);
+ free(apisock);
return;
}
if (SOCKETFAIL(listen(*apisock, QUEUE))) {
applog(LOG_ERR, "API3 initialisation failed (%s)%s", SOCKERRMSG, UNAVAILABLE);
CLOSESOCKET(*apisock);
+ free(apisock);
return;
}
@@ -4555,21 +4562,18 @@ void api(int api_thr_id)
message(io_data, MSG_INVJSON, 0, NULL, isjson);
send_result(io_data, c, isjson);
did = true;
- }
- else {
+ } else {
json_val = json_object_get(json_config, JSON_COMMAND);
if (json_val == NULL) {
message(io_data, MSG_MISCMD, 0, NULL, isjson);
send_result(io_data, c, isjson);
did = true;
- }
- else {
+ } else {
if (!json_is_string(json_val)) {
message(io_data, MSG_INVCMD, 0, NULL, isjson);
send_result(io_data, c, isjson);
did = true;
- }
- else {
+ } else {
cmd = (char *)json_string_value(json_val);
json_val = json_object_get(json_config, JSON_PARAMETER);
if (json_is_string(json_val))
@@ -4586,7 +4590,7 @@ void api(int api_thr_id)
}
}
- if (!did)
+ if (!did) {
for (i = 0; cmds[i].name != NULL; i++) {
if (strcmp(cmd, cmds[i].name) == 0) {
sprintf(cmdbuf, "|%s|", cmd);
@@ -4602,11 +4606,14 @@ void api(int api_thr_id)
break;
}
}
+ }
if (!did) {
message(io_data, MSG_INVCMD, 0, NULL, isjson);
send_result(io_data, c, isjson);
}
+ if (json_is_object(json_config))
+ json_decref(json_config);
}
}
CLOSESOCKET(c);
@@ -4618,6 +4625,8 @@ die:
;
pthread_cleanup_pop(true);
+ free(apisock);
+
if (opt_debug)
applog(LOG_DEBUG, "API: terminating due to: %s",
do_a_quit ? "QUIT" : (do_a_restart ? "RESTART" : (bye ? "BYE" : "UNKNOWN!")));
diff --git a/cgminer.c b/cgminer.c
index ca5e345..a36a3cb 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -74,6 +74,9 @@ char *curly = ":D";
#ifdef USE_HASHFAST
#include "driver-hashfast.h"
+int opt_hfa_ntime_roll;
+int opt_hfa_hash_clock;
+bool opt_hfa_pll_bypass;
#endif
#if defined(USE_BITFORCE) || defined(USE_ICARUS) || defined(USE_AVALON) || defined(USE_MODMINER)
@@ -135,7 +138,7 @@ static bool opt_submit_stale = true;
static int opt_shares;
bool opt_fail_only;
static bool opt_fix_protocol;
-static bool opt_lowmem;
+bool opt_lowmem;
bool opt_autofan;
bool opt_autoengine;
bool opt_noadl;
@@ -1207,6 +1210,17 @@ static struct opt_table opt_config_table[] = {
set_bitburner_fury_options, NULL, NULL,
"Override avalon-options for BitBurner Fury boards baud:miners:asic:timeout:freq"),
#endif
+#ifdef USE_HASHFAST
+ OPT_WITH_ARG("--hfa-ntime-roll",
+ opt_set_intval, NULL, &opt_hfa_ntime_roll,
+ opt_hidden),
+ OPT_WITH_ARG("--hfa-hash-clock",
+ opt_set_intval, NULL, &opt_hfa_hash_clock,
+ opt_hidden),
+ OPT_WITHOUT_ARG("--hfa-pll-bypass",
+ opt_set_bool, &opt_hfa_pll_bypass,
+ opt_hidden),
+#endif
#ifdef USE_KLONDIKE
OPT_WITH_ARG("--klondike-options",
set_klondike_options, NULL, NULL,
@@ -3549,6 +3563,17 @@ static void _copy_work(struct work *work, const struct work *base_work, int noff
work->coinbase = strdup(base_work->coinbase);
}
+void set_work_ntime(struct work *work, int ntime)
+{
+ uint32_t *work_ntime = (uint32_t *)(work->data + 68);
+
+ *work_ntime = htobe32(ntime);
+ if (work->ntime) {
+ free(work->ntime);
+ work->ntime = bin2hex((unsigned char *)work_ntime, 4);
+ }
+}
+
/* Generates a copy of an existing work struct, creating fresh heap allocations
* for all dynamically allocated arrays within the struct. noffset is used for
* when a driver has internally rolled the ntime, noffset is a relative value.
@@ -3871,11 +3896,13 @@ int restart_wait(struct thr_info *thr, unsigned int mstime)
static void flush_queue(struct cgpu_info *cgpu);
-static void restart_threads(void)
+static void *restart_thread(void __maybe_unused *arg)
{
struct pool *cp = current_pool();
struct cgpu_info *cgpu;
- int i;
+ int i, mt;
+
+ pthread_detach(pthread_self());
/* Artificially set the lagging flag to avoid pool not providing work
* fast enough messages after every long poll */
@@ -3885,15 +3912,19 @@ static void restart_threads(void)
discard_stale();
rd_lock(&mining_thr_lock);
- for (i = 0; i < mining_threads; i++) {
+ mt = mining_threads;
+ rd_unlock(&mining_thr_lock);
+
+ for (i = 0; i < mt; i++) {
cgpu = mining_thr[i]->cgpu;
if (unlikely(!cgpu))
continue;
+ if (cgpu->deven != DEV_ENABLED)
+ continue;
mining_thr[i]->work_restart = true;
flush_queue(cgpu);
cgpu->drv->flush_work(cgpu);
}
- rd_unlock(&mining_thr_lock);
mutex_lock(&restart_lock);
pthread_cond_broadcast(&restart_cond);
@@ -3905,6 +3936,17 @@ static void restart_threads(void)
* early. */
cancel_usb_transfers();
#endif
+ return NULL;
+}
+
+/* In order to prevent a deadlock via the various drv->flush_work
+ * implementations we send the restart messages via a separate thread. */
+static void restart_threads(void)
+{
+ pthread_t rthread;
+
+ if (unlikely(pthread_create(&rthread, NULL, restart_thread, NULL)))
+ quit(1, "Failed to create restart thread");
}
static void signal_work_update(void)
@@ -4460,6 +4502,30 @@ void zero_stats(void)
}
}
+static void set_highprio(void)
+{
+#ifndef WIN32
+ int ret = nice(-10);
+
+ if (!ret)
+ applog(LOG_DEBUG, "Unable to set thread to high priority");
+#else
+ SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST);
+#endif
+}
+
+static void set_lowprio(void)
+{
+#ifndef WIN32
+ int ret = nice(10);
+
+ if (!ret)
+ applog(LOG_INFO, "Unable to set thread to low priority");
+#else
+ SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_LOWEST);
+#endif
+}
+
#ifdef HAVE_CURSES
static void display_pools(void)
{
@@ -4865,6 +4931,7 @@ static void *api_thread(void *userdata)
RenameThread("api");
+ set_lowprio();
api(api_thr_id);
PTH(mythr) = 0L;
@@ -6354,6 +6421,30 @@ void __work_completed(struct cgpu_info *cgpu, struct work *work)
cgpu->queued_count--;
HASH_DEL(cgpu->queued_work, work);
}
+
+/* This iterates over a queued hashlist finding work started more than secs
+ * seconds ago and discards the work as completed. The driver must set the
+ * work->tv_work_start value appropriately. Returns the number of items aged. */
+int age_queued_work(struct cgpu_info *cgpu, double secs)
+{
+ struct work *work, *tmp;
+ struct timeval tv_now;
+ int aged = 0;
+
+ cgtime(&tv_now);
+
+ wr_lock(&cgpu->qlock);
+ HASH_ITER(hh, cgpu->queued_work, work, tmp) {
+ if (tdiff(&tv_now, &work->tv_work_start) > secs) {
+ __work_completed(cgpu, work);
+ aged++;
+ }
+ }
+ wr_unlock(&cgpu->qlock);
+
+ return aged;
+}
+
/* This function should be used by queued device drivers when they're sure
* the work struct is no longer in use. */
void work_completed(struct cgpu_info *cgpu, struct work *work)
@@ -6525,6 +6616,7 @@ void *miner_thread(void *userdata)
applog(LOG_DEBUG, "Waiting on sem in miner thread");
cgsem_wait(&mythr->sem);
+ set_highprio();
drv->hash_work(mythr);
out:
drv->thread_shutdown(mythr);
@@ -6803,6 +6895,8 @@ static void *watchpool_thread(void __maybe_unused *userdata)
RenameThread("watchpool");
+ set_lowprio();
+
while (42) {
struct timeval now;
int i;
@@ -6886,6 +6980,7 @@ static void *watchdog_thread(void __maybe_unused *userdata)
RenameThread("watchdog");
+ set_lowprio();
memset(&zero_tv, 0, sizeof(struct timeval));
cgtime(&rotate_tv);
@@ -7673,6 +7768,8 @@ static void *hotplug_thread(void __maybe_unused *userdata)
RenameThread("hotplug");
+ set_lowprio();
+
hotplug_mode = true;
cgsleep_ms(5000);
@@ -8037,6 +8134,37 @@ int main(int argc, char *argv[])
quit(1, "Failed to calloc mining_thr[%d]", i);
}
+ // Start threads
+ k = 0;
+ for (i = 0; i < total_devices; ++i) {
+ struct cgpu_info *cgpu = devices[i];
+ cgpu->thr = malloc(sizeof(*cgpu->thr) * (cgpu->threads+1));
+ cgpu->thr[cgpu->threads] = NULL;
+ cgpu->status = LIFE_INIT;
+
+ for (j = 0; j < cgpu->threads; ++j, ++k) {
+ thr = get_thread(k);
+ thr->id = k;
+ thr->cgpu = cgpu;
+ thr->device_thread = j;
+
+ if (!cgpu->drv->thread_prepare(thr))
+ continue;
+
+ if (unlikely(thr_info_create(thr, NULL, miner_thread, thr)))
+ quit(1, "thread %d create failed", thr->id);
+
+ cgpu->thr[j] = thr;
+
+ /* Enable threads for devices set not to mine but disable
+ * their queue in case we wish to enable them later */
+ if (cgpu->deven != DEV_DISABLED) {
+ applog(LOG_DEBUG, "Pushing sem post to thread %d", thr->id);
+ cgsem_post(&thr->sem);
+ }
+ }
+ }
+
if (opt_benchmark)
goto begin_bench;
@@ -8094,40 +8222,6 @@ begin_bench:
cgtime(&total_tv_end);
get_datestamp(datestamp, sizeof(datestamp), &total_tv_start);
- // Start threads
- k = 0;
- for (i = 0; i < total_devices; ++i) {
- struct cgpu_info *cgpu = devices[i];
- cgpu->thr = malloc(sizeof(*cgpu->thr) * (cgpu->threads+1));
- cgpu->thr[cgpu->threads] = NULL;
- cgpu->status = LIFE_INIT;
-
- for (j = 0; j < cgpu->threads; ++j, ++k) {
- thr = get_thread(k);
- thr->id = k;
- thr->cgpu = cgpu;
- thr->device_thread = j;
-
- if (!cgpu->drv->thread_prepare(thr))
- continue;
-
- if (unlikely(thr_info_create(thr, NULL, miner_thread, thr)))
- quit(1, "thread %d create failed", thr->id);
-
- cgpu->thr[j] = thr;
-
- /* Enable threads for devices set not to mine but disable
- * their queue in case we wish to enable them later */
- if (cgpu->deven != DEV_DISABLED) {
- applog(LOG_DEBUG, "Pushing sem post to thread %d", thr->id);
- cgsem_post(&thr->sem);
- }
- }
- }
-
- cgtime(&total_tv_start);
- cgtime(&total_tv_end);
-
watchpool_thr_id = 2;
thr = &control_thr[watchpool_thr_id];
/* start watchpool thread */
diff --git a/configure.ac b/configure.ac
index de7d5e7..8eb34ce 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2,7 +2,7 @@
##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##
m4_define([v_maj], [3])
m4_define([v_min], [8])
-m4_define([v_mic], [1])
+m4_define([v_mic], [3])
##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##
m4_define([v_ver], [v_maj.v_min.v_mic])
m4_define([lt_rev], m4_eval(v_maj + v_min))
diff --git a/driver-avalon.c b/driver-avalon.c
index db94436..aaabe55 100644
--- a/driver-avalon.c
+++ b/driver-avalon.c
@@ -142,12 +142,10 @@ static int avalon_write(struct cgpu_info *avalon, char *buf, ssize_t len, int ep
return AVA_SEND_OK;
}
-static int avalon_send_task(const struct avalon_task *at, struct cgpu_info *avalon,
- struct avalon_info *info)
-
+static int avalon_send_task(const struct avalon_task *at, struct cgpu_info *avalon)
{
uint8_t buf[AVALON_WRITE_SIZE + 4 * AVALON_DEFAULT_ASIC_NUM];
- int delay, ret, i, ep = C_AVALON_TASK;
+ int ret, i, ep = C_AVALON_TASK;
uint32_t nonce_range;
size_t nr_len;
@@ -188,10 +186,6 @@ static int avalon_send_task(const struct avalon_task *at, struct cgpu_info *aval
tt |= ((buf[4] & 0x80) ? (1 << 0) : 0);
buf[4] = tt;
#endif
- delay = nr_len * 10 * 1000000;
- delay = delay / info->baud;
- delay += 4000;
-
if (at->reset) {
ep = C_AVALON_RESET;
nr_len = 1;
@@ -200,15 +194,8 @@ static int avalon_send_task(const struct avalon_task *at, struct cgpu_info *aval
applog(LOG_DEBUG, "Avalon: Sent(%u):", (unsigned int)nr_len);
hexdump(buf, nr_len);
}
- /* Sleep from the last time we sent data */
- cgsleep_us_r(&info->cgsent, info->send_delay);
-
- cgsleep_prepare_r(&info->cgsent);
ret = avalon_write(avalon, (char *)buf, nr_len, ep);
- applog(LOG_DEBUG, "Avalon: Sent: Buffer delay: %dus", info->send_delay);
- info->send_delay = delay;
-
return ret;
}
@@ -337,7 +324,7 @@ static int avalon_reset(struct cgpu_info *avalon, bool initial)
AVALON_DEFAULT_FREQUENCY);
wait_avalon_ready(avalon);
- ret = avalon_send_task(&at, avalon, info);
+ ret = avalon_send_task(&at, avalon);
if (unlikely(ret == AVA_SEND_ERROR))
return -1;
@@ -578,7 +565,7 @@ static void avalon_idle(struct cgpu_info *avalon, struct avalon_info *info)
avalon_init_task(&at, 0, 0, info->fan_pwm, info->timeout,
info->asic_count, info->miner_count, 1, 1,
info->frequency);
- if (avalon_send_task(&at, avalon, info) == AVA_SEND_ERROR)
+ if (avalon_send_task(&at, avalon) == AVA_SEND_ERROR)
break;
}
applog(LOG_WARNING, "%s%i: Idling %d miners", avalon->drv->name, avalon->device_id, i);
@@ -754,7 +741,7 @@ static void bitburner_get_version(struct cgpu_info *avalon)
}
}
-static bool avalon_detect_one(libusb_device *dev, struct usb_find_devices *found)
+static struct cgpu_info *avalon_detect_one(libusb_device *dev, struct usb_find_devices *found)
{
int baud, miner_count, asic_count, timeout, frequency;
int this_option_offset;
@@ -864,7 +851,7 @@ static bool avalon_detect_one(libusb_device *dev, struct usb_find_devices *found
bitburner_get_version(avalon);
}
- return true;
+ return avalon;
unshin:
@@ -877,7 +864,7 @@ shin:
avalon = usb_free_cgpu(avalon);
- return false;
+ return NULL;
}
static void avalon_detect(bool __maybe_unused hotplug)
@@ -1172,7 +1159,7 @@ static void *avalon_send_tasks(void *userdata)
}
mutex_unlock(&info->qlock);
- ret = avalon_send_task(&at, avalon, info);
+ ret = avalon_send_task(&at, avalon);
if (unlikely(ret == AVA_SEND_ERROR)) {
/* Send errors are fatal */
diff --git a/driver-avalon.h b/driver-avalon.h
index 9111291..5b6cf83 100644
--- a/driver-avalon.h
+++ b/driver-avalon.h
@@ -145,8 +145,6 @@ struct avalon_info {
pthread_mutex_t lock;
pthread_mutex_t qlock;
cgsem_t qsem;
- cgtimer_t cgsent;
- int send_delay;
int nonces;
int auto_queued;
diff --git a/driver-bflsc.c b/driver-bflsc.c
index f3e45c4..5dafa9c 100644
--- a/driver-bflsc.c
+++ b/driver-bflsc.c
@@ -688,7 +688,7 @@ ne:
return ok;
}
-static bool bflsc_detect_one(struct libusb_device *dev, struct usb_find_devices *found)
+static struct cgpu_info *bflsc_detect_one(struct libusb_device *dev, struct usb_find_devices *found)
{
struct bflsc_info *sc_info = NULL;
char buf[BFLSC_BUFSIZ+1];
@@ -888,7 +888,7 @@ reinit:
mutex_init(&bflsc->device_mutex);
rwlock_init(&sc_info->stat_lock);
- return true;
+ return bflsc;
unshin:
@@ -906,7 +906,7 @@ shin:
bflsc = usb_free_cgpu(bflsc);
- return false;
+ return NULL;
}
static void bflsc_detect(bool __maybe_unused hotplug)
diff --git a/driver-bitforce.c b/driver-bitforce.c
index 901ba08..d4f51c1 100644
--- a/driver-bitforce.c
+++ b/driver-bitforce.c
@@ -162,7 +162,7 @@ failed:
mutex_unlock(&bitforce->device_mutex);
}
-static bool bitforce_detect_one(struct libusb_device *dev, struct usb_find_devices *found)
+static struct cgpu_info *bitforce_detect_one(struct libusb_device *dev, struct usb_find_devices *found)
{
char buf[BITFORCE_BUFSIZ+1];
int err, amount;
@@ -270,7 +270,7 @@ reinit:
mutex_init(&bitforce->device_mutex);
- return true;
+ return bitforce;
unshin:
@@ -285,7 +285,7 @@ shin:
bitforce = usb_free_cgpu(bitforce);
- return false;
+ return NULL;
}
static void bitforce_detect(bool __maybe_unused hotplug)
diff --git a/driver-bitfury.c b/driver-bitfury.c
index 3331d82..8de63ce 100644
--- a/driver-bitfury.c
+++ b/driver-bitfury.c
@@ -18,7 +18,7 @@
#define BF1MSGSIZE 7
#define BF1INFOSIZE 14
-static void bitfury_empty_buffer(struct cgpu_info *bitfury)
+static void bf1_empty_buffer(struct cgpu_info *bitfury)
{
char buf[512];
int amount;
@@ -28,12 +28,12 @@ static void bitfury_empty_buffer(struct cgpu_info *bitfury)
} while (amount);
}
-static int bitfury_open(struct cgpu_info *bitfury)
+static bool bf1_open(struct cgpu_info *bitfury)
{
uint32_t buf[2];
int err;
- bitfury_empty_buffer(bitfury);
+ bf1_empty_buffer(bitfury);
/* Magic sequence to reset device only really needed for windows but
* harmless on linux. */
buf[0] = 0x80250000;
@@ -53,19 +53,33 @@ static int bitfury_open(struct cgpu_info *bitfury)
return (err == BF1MSGSIZE);
}
-static void bitfury_close(struct cgpu_info *bitfury)
+static void bf1_close(struct cgpu_info *bitfury)
{
- bitfury_empty_buffer(bitfury);
+ bf1_empty_buffer(bitfury);
}
-static void bitfury_identify(struct cgpu_info *bitfury)
+static void bf1_identify(struct cgpu_info *bitfury)
{
int amount;
usb_write(bitfury, "L", 1, &amount, C_BF1_IDENTIFY);
}
-static bool bitfury_getinfo(struct cgpu_info *bitfury, struct bitfury_info *info)
+static void bitfury_identify(struct cgpu_info *bitfury)
+{
+ struct bitfury_info *info = bitfury->device_data;
+
+ switch(info->ident) {
+ case IDENT_BF1:
+ bf1_identify(bitfury);
+ break;
+ case IDENT_BXF:
+ default:
+ break;
+ }
+}
+
+static bool bf1_getinfo(struct cgpu_info *bitfury, struct bitfury_info *info)
{
int amount, err;
char buf[16];
@@ -93,11 +107,11 @@ static bool bitfury_getinfo(struct cgpu_info *bitfury, struct bitfury_info *info
applog(LOG_INFO, "%s %d: Getinfo returned version %d, product %s serial %08x", bitfury->drv->name,
bitfury->device_id, info->version, info->product, info->serial);
- bitfury_empty_buffer(bitfury);
+ bf1_empty_buffer(bitfury);
return true;
}
-static bool bitfury_reset(struct cgpu_info *bitfury)
+static bool bf1_reset(struct cgpu_info *bitfury)
{
int amount, err;
char buf[16];
@@ -122,64 +136,352 @@ static bool bitfury_reset(struct cgpu_info *bitfury)
}
applog(LOG_DEBUG, "%s %d: Getreset returned %s", bitfury->drv->name,
bitfury->device_id, buf);
- bitfury_empty_buffer(bitfury);
+ bf1_empty_buffer(bitfury);
return true;
}
-static bool bitfury_detect_one(struct libusb_device *dev, struct usb_find_devices *found)
+static bool bxf_send_msg(struct cgpu_info *bitfury, char *buf, enum usb_cmds cmd)
{
- struct cgpu_info *bitfury;
- struct bitfury_info *info;
+ int err, amount, len;
+
+ len = strlen(buf);
+ applog(LOG_DEBUG, "%s %d: Sending %s", bitfury->drv->name, bitfury->device_id, buf);
+ err = usb_write(bitfury, buf, len, &amount, cmd);
+ if (err || amount != len) {
+ applog(LOG_WARNING, "%s %d: Error %d sending %s sent %d of %d", bitfury->drv->name,
+ bitfury->device_id, err, usb_cmdname(cmd), amount, len);
+ return false;
+ }
+ return true;
+}
- bitfury = usb_alloc_cgpu(&bitfury_drv, 1);
+/* Returns the amount received only if we receive a full message, otherwise
+ * it returns the err value. */
+static int bxf_recv_msg(struct cgpu_info *bitfury, char *buf)
+{
+ int err, amount;
- if (!usb_init(bitfury, dev, found))
- goto out;
- applog(LOG_INFO, "%s %d: Found at %s", bitfury->drv->name,
- bitfury->device_id, bitfury->device_path);
+ err = usb_read_nl(bitfury, buf, 512, &amount, C_BXF_READ);
+ if (amount)
+ applog(LOG_DEBUG, "%s %d: Received %s", bitfury->drv->name, bitfury->device_id, buf);
+ if (!err)
+ return amount;
+ return err;
+}
+
+/* Keep reading till the first timeout or error */
+static void bxf_clear_buffer(struct cgpu_info *bitfury)
+{
+ int err, retries = 0;
+ char buf[512];
+
+ do {
+ err = bxf_recv_msg(bitfury, buf);
+ usb_buffer_clear(bitfury);
+ if (err < 0)
+ break;
+ } while (retries++ < 10);
+}
+
+static bool bxf_send_flush(struct cgpu_info *bitfury)
+{
+ char buf[8];
+
+ sprintf(buf, "flush\n");
+ return bxf_send_msg(bitfury, buf, C_BXF_FLUSH);
+}
+
+static bool bxf_detect_one(struct cgpu_info *bitfury, struct bitfury_info *info)
+{
+ int err, retries = 0;
+ char buf[512];
+
+ if (!bxf_send_flush(bitfury))
+ return false;
+
+ bxf_clear_buffer(bitfury);
+
+ sprintf(buf, "version\n");
+ if (!bxf_send_msg(bitfury, buf, C_BXF_VERSION))
+ return false;
+
+ do {
+ err = bxf_recv_msg(bitfury, buf);
+ if (err < 0 && err != LIBUSB_ERROR_TIMEOUT)
+ return false;
+ if (err > 0 && !strncmp(buf, "version", 7)) {
+ sscanf(&buf[8], "%d.%d rev %d chips %d", &info->ver_major,
+ &info->ver_minor, &info->hw_rev, &info->chips);
+ applog(LOG_INFO, "%s %d: Version %d.%d rev %d chips %d",
+ bitfury->drv->name, bitfury->device_id, info->ver_major,
+ info->ver_minor, info->hw_rev, info->chips);
+ break;
+ }
+ /* Keep parsing if the buffer is full without counting it as
+ * a retry. */
+ if (usb_buffer_size(bitfury))
+ continue;
+ } while (retries++ < 10);
+
+ if (!add_cgpu(bitfury))
+ quit(1, "Failed to add_cgpu in bxf_detect_one");
+
+ update_usb_stats(bitfury);
+ applog(LOG_INFO, "%s %d: Successfully initialised %s",
+ bitfury->drv->name, bitfury->device_id, bitfury->device_path);
- info = calloc(sizeof(struct bitfury_info), 1);
- if (!info)
- quit(1, "Failed to calloc info in bitfury_detect_one");
- bitfury->device_data = info;
- /* This does not artificially raise hashrate, it simply allows the
- * hashrate to adapt quickly on starting. */
info->total_nonces = 1;
+ /* This unsets it to make sure it gets set on the first pass */
+ info->maxroll = -1;
- if (!bitfury_open(bitfury))
+ return true;
+}
+
+static bool bf1_detect_one(struct cgpu_info *bitfury, struct bitfury_info *info)
+{
+ if (!bf1_open(bitfury))
goto out_close;
/* Send getinfo request */
- if (!bitfury_getinfo(bitfury, info))
+ if (!bf1_getinfo(bitfury, info))
goto out_close;
/* Send reset request */
- if (!bitfury_reset(bitfury))
+ if (!bf1_reset(bitfury))
goto out_close;
- bitfury_identify(bitfury);
- bitfury_empty_buffer(bitfury);
+ bf1_identify(bitfury);
+ bf1_empty_buffer(bitfury);
if (!add_cgpu(bitfury))
- quit(1, "Failed to add_cgpu in bitfury_detect_one");
+ quit(1, "Failed to add_cgpu in bf1_detect_one");
update_usb_stats(bitfury);
applog(LOG_INFO, "%s %d: Successfully initialised %s",
bitfury->drv->name, bitfury->device_id, bitfury->device_path);
+
+ /* This does not artificially raise hashrate, it simply allows the
+ * hashrate to adapt quickly on starting. */
+ info->total_nonces = 1;
+
return true;
out_close:
- bitfury_close(bitfury);
- usb_uninit(bitfury);
-out:
- bitfury = usb_free_cgpu(bitfury);
+ bf1_close(bitfury);
return false;
}
+static struct cgpu_info *bitfury_detect_one(struct libusb_device *dev, struct usb_find_devices *found)
+{
+ struct cgpu_info *bitfury;
+ struct bitfury_info *info;
+ enum sub_ident ident;
+ bool ret = false;
+
+ bitfury = usb_alloc_cgpu(&bitfury_drv, 1);
+
+ if (!usb_init(bitfury, dev, found))
+ goto out;
+ applog(LOG_INFO, "%s %d: Found at %s", bitfury->drv->name,
+ bitfury->device_id, bitfury->device_path);
+
+ info = calloc(sizeof(struct bitfury_info), 1);
+ if (!info)
+ quit(1, "Failed to calloc info in bitfury_detect_one");
+ bitfury->device_data = info;
+ info->ident = ident = usb_ident(bitfury);
+ switch (ident) {
+ case IDENT_BF1:
+ ret = bf1_detect_one(bitfury, info);
+ break;
+ case IDENT_BXF:
+ ret = bxf_detect_one(bitfury, info);
+ break;
+ default:
+ applog(LOG_INFO, "%s %d: Unrecognised bitfury device",
+ bitfury->drv->name, bitfury->device_id);
+ break;
+ }
+
+ if (!ret) {
+ free(info);
+ usb_uninit(bitfury);
+out:
+ bitfury = usb_free_cgpu(bitfury);
+ }
+ return bitfury;
+}
+
static void bitfury_detect(bool __maybe_unused hotplug)
{
usb_detect(&bitfury_drv, bitfury_detect_one);
}
+static void parse_bxf_submit(struct cgpu_info *bitfury, struct bitfury_info *info, char *buf)
+{
+ struct work *match_work, *tmp, *work = NULL;
+ struct thr_info *thr = info->thr;
+ uint32_t nonce, timestamp;
+ int workid;
+
+ if (!sscanf(&buf[7], "%x %x %x", &nonce, &workid, ×tamp)) {
+ applog(LOG_WARNING, "%s %d: Failed to parse submit response",
+ bitfury->drv->name, bitfury->device_id);
+ return;
+ }
+
+ applog(LOG_DEBUG, "%s %d: Parsed nonce %u workid %d timestamp %u",
+ bitfury->drv->name, bitfury->device_id, nonce, workid, timestamp);
+
+ rd_lock(&bitfury->qlock);
+ HASH_ITER(hh, bitfury->queued_work, match_work, tmp) {
+ if (match_work->subid == workid) {
+ work = copy_work(match_work);
+ break;
+ }
+ }
+ rd_unlock(&bitfury->qlock);
+
+ if (!work) {
+ /* Discard first results from any previous run */
+ if (unlikely(!info->valid))
+ return;
+
+ applog(LOG_INFO, "%s %d: No matching work", bitfury->drv->name, bitfury->device_id);
+
+ mutex_lock(&info->lock);
+ info->no_matching_work++;
+ mutex_unlock(&info->lock);
+
+ inc_hw_errors(thr);
+ return;
+ }
+ /* Set the device start time from when we first get valid results */
+ if (unlikely(!info->valid)) {
+ info->valid = true;
+ cgtime(&bitfury->dev_start_tv);
+ }
+ set_work_ntime(work, timestamp);
+ if (submit_nonce(thr, work, nonce)) {
+ mutex_lock(&info->lock);
+ info->nonces++;
+ mutex_unlock(&info->lock);
+ }
+ free_work(work);
+}
+
+static void parse_bxf_temp(struct cgpu_info *bitfury, struct bitfury_info *info, char *buf)
+{
+ unsigned int temp;
+
+ if (!sscanf(&buf[5], "%u", &temp)) {
+ applog(LOG_INFO, "%s %d: Failed to parse temperature",
+ bitfury->drv->name, bitfury->device_id);
+ return;
+ }
+ mutex_lock(&info->lock);
+ info->temperature = (double)temp / 10;
+ mutex_unlock(&info->lock);
+}
+
+static void bxf_update_work(struct cgpu_info *bitfury, struct bitfury_info *info);
+
+static void parse_bxf_needwork(struct cgpu_info *bitfury, struct bitfury_info *info,
+ char *buf)
+{
+ int needed;
+
+ if (!sscanf(&buf[9], "%d", &needed)) {
+ applog(LOG_INFO, "%s %d: Failed to parse needwork",
+ bitfury->drv->name, bitfury->device_id);
+ return;
+ }
+ while (needed-- > 0)
+ bxf_update_work(bitfury, info);
+}
+
+static void *bxf_get_results(void *userdata)
+{
+ struct cgpu_info *bitfury = userdata;
+ struct bitfury_info *info = bitfury->device_data;
+ char threadname[24], buf[512];
+
+ snprintf(threadname, 24, "bxf_recv/%d", bitfury->device_id);
+
+ /* We operate the device at lowest diff since it's not a lot of results
+ * to process and gives us a better indicator of the nonce return rate
+ * and hardware errors. */
+ sprintf(buf, "target ffffffff\n");
+ if (!bxf_send_msg(bitfury, buf, C_BXF_TARGET))
+ goto out;
+
+ /* Read thread sends the first work item to get the device started
+ * since it will roll ntime and make work itself from there on. */
+ bxf_update_work(bitfury, info);
+ bxf_update_work(bitfury, info);
+
+ while (likely(!bitfury->shutdown)) {
+ char *msg;
+ int err;
+
+ if (unlikely(bitfury->usbinfo.nodev))
+ break;
+
+ err = bxf_recv_msg(bitfury, buf);
+ if (err < 0) {
+ if (err != LIBUSB_ERROR_TIMEOUT)
+ break;
+ continue;
+ }
+ if (!err)
+ continue;
+
+ msg = strstr(buf, "submit");
+ if (msg) {
+ parse_bxf_submit(bitfury, info, msg);
+ continue;
+ }
+ msg = strstr(buf, "temp");
+ if (msg) {
+ parse_bxf_temp(bitfury, info, msg);
+ continue;
+ }
+ msg = strstr(buf, "needwork");
+ if (msg) {
+ parse_bxf_needwork(bitfury, info, msg);
+ continue;
+ }
+ applog(LOG_DEBUG, "%s %d: Unrecognised string %s",
+ bitfury->drv->name, bitfury->device_id, buf);
+ }
+out:
+ return NULL;
+}
+
+static bool bxf_prepare(struct cgpu_info *bitfury, struct bitfury_info *info)
+{
+ mutex_init(&info->lock);
+ if (pthread_create(&info->read_thr, NULL, bxf_get_results, (void *)bitfury))
+ quit(1, "Failed to create bxf read_thr");
+ return true;
+}
+
+static bool bitfury_prepare(struct thr_info *thr)
+{
+ struct cgpu_info *bitfury = thr->cgpu;
+ struct bitfury_info *info = bitfury->device_data;
+
+ info->thr = thr;
+
+ switch(info->ident) {
+ case IDENT_BXF:
+ return bxf_prepare(bitfury, info);
+ break;
+ case IDENT_BF1:
+ default:
+ return true;
+ }
+}
+
static uint32_t decnonce(uint32_t in)
{
uint32_t out;
@@ -220,16 +522,31 @@ static bool bitfury_checkresults(struct thr_info *thr, struct work *work, uint32
return false;
}
-static int64_t bitfury_scanwork(struct thr_info *thr)
+static int64_t bitfury_rate(struct bitfury_info *info)
{
- struct cgpu_info *bitfury = thr->cgpu;
- struct bitfury_info *info = bitfury->device_data;
- int amount, i, aged = 0, total = 0, ms_diff;
+ double nonce_rate;
+ int64_t ret = 0;
+
+ info->cycles++;
+ info->total_nonces += info->nonces;
+ info->saved_nonces += info->nonces;
+ info->nonces = 0;
+ nonce_rate = (double)info->total_nonces / (double)info->cycles;
+ if (info->saved_nonces >= nonce_rate) {
+ info->saved_nonces -= nonce_rate;
+ ret = (double)0xffffffff * nonce_rate;
+ }
+ return ret;
+}
+
+static int64_t bf1_scan(struct thr_info *thr, struct cgpu_info *bitfury,
+ struct bitfury_info *info)
+{
+ int amount, i, aged, total = 0, ms_diff;
+ char readbuf[512], buf[45];
struct work *work, *tmp;
struct timeval tv_now;
- double nonce_rate;
int64_t ret = 0;
- char buf[45];
work = get_queue_work(thr, bitfury, thr->id);
if (unlikely(thr->work_restart)) {
@@ -247,7 +564,7 @@ static int64_t bitfury_scanwork(struct thr_info *thr)
cgtime(&tv_now);
ms_diff = 600 - ms_tdiff(&tv_now, &info->tv_start);
if (ms_diff > 0) {
- usb_read_timeout_cancellable(bitfury, info->buf, 512, &amount, ms_diff,
+ usb_read_timeout_cancellable(bitfury, readbuf, 512, &amount, ms_diff,
C_BF1_GETRES);
total += amount;
}
@@ -259,11 +576,11 @@ static int64_t bitfury_scanwork(struct thr_info *thr)
/* If a work restart was sent, just empty the buffer. */
if (unlikely(ms_diff < 10 || thr->work_restart))
ms_diff = 10;
- usb_read_once_timeout_cancellable(bitfury, info->buf + total, BF1MSGSIZE,
+ usb_read_once_timeout_cancellable(bitfury, readbuf + total, BF1MSGSIZE,
&amount, ms_diff, C_BF1_GETRES);
total += amount;
while (amount) {
- usb_read_once_timeout(bitfury, info->buf + total, 512, &amount, 10,
+ usb_read_once_timeout(bitfury, readbuf + total, 512 - total, &amount, 10,
C_BF1_GETRES);
total += amount;
};
@@ -288,7 +605,7 @@ out:
uint32_t nonce;
/* Ignore state & switched data in results for now. */
- memcpy(&nonce, info->buf + i + 3, 4);
+ memcpy(&nonce, readbuf + i + 3, 4);
nonce = decnonce(nonce);
rd_lock(&bitfury->qlock);
@@ -301,37 +618,53 @@ out:
}
rd_unlock(&bitfury->qlock);
- if (!found)
- inc_hw_errors(thr);
+ if (!found) {
+ if (likely(info->valid))
+ inc_hw_errors(thr);
+ } else if (unlikely(!info->valid)) {
+ info->valid = true;
+ cgtime(&bitfury->dev_start_tv);
+ }
}
cgtime(&tv_now);
/* This iterates over the hashlist finding work started more than 6
- * seconds ago which equates to leaving 5 past work items in the array
- * to look for results. */
- wr_lock(&bitfury->qlock);
- HASH_ITER(hh, bitfury->queued_work, work, tmp) {
- if (tdiff(&tv_now, &work->tv_work_start) > 6.0) {
- __work_completed(bitfury, work);
- aged++;
- }
- }
- wr_unlock(&bitfury->qlock);
-
+ * seconds ago. */
+ aged = age_queued_work(bitfury, 6.0);
if (aged) {
applog(LOG_DEBUG, "%s %d: Aged %d work items", bitfury->drv->name,
bitfury->device_id, aged);
}
- info->cycles++;
- info->total_nonces += info->nonces;
- info->saved_nonces += info->nonces;
- info->nonces = 0;
- nonce_rate = (double)info->total_nonces / (double)info->cycles;
- if (info->saved_nonces >= nonce_rate) {
- info->saved_nonces -= nonce_rate;
- ret = (double)0xffffffff * nonce_rate;
+ ret = bitfury_rate(info);
+
+ if (unlikely(bitfury->usbinfo.nodev)) {
+ applog(LOG_WARNING, "%s %d: Device disappeared, disabling thread",
+ bitfury->drv->name, bitfury->device_id);
+ ret = -1;
+ }
+ return ret;
+}
+
+static int64_t bxf_scan(struct cgpu_info *bitfury, struct bitfury_info *info)
+{
+ int64_t ret;
+ int aged;
+
+ bxf_update_work(bitfury, info);
+ cgsleep_ms(600);
+
+ mutex_lock(&info->lock);
+ ret = bitfury_rate(info);
+ mutex_unlock(&info->lock);
+
+ /* Keep no more than the last 90 seconds worth of work items in the
+ * hashlist */
+ aged = age_queued_work(bitfury, 90.0);
+ if (aged) {
+ applog(LOG_DEBUG, "%s %d: Aged %d work items", bitfury->drv->name,
+ bitfury->device_id, aged);
}
if (unlikely(bitfury->usbinfo.nodev)) {
@@ -342,9 +675,89 @@ out:
return ret;
}
-static struct api_data *bitfury_api_stats(struct cgpu_info *cgpu)
+static int64_t bitfury_scanwork(struct thr_info *thr)
+{
+ struct cgpu_info *bitfury = thr->cgpu;
+ struct bitfury_info *info = bitfury->device_data;
+
+ switch(info->ident) {
+ case IDENT_BF1:
+ return bf1_scan(thr, bitfury, info);
+ break;
+ case IDENT_BXF:
+ return bxf_scan(bitfury, info);
+ break;
+ default:
+ return 0;
+ }
+}
+
+static void bxf_send_maxroll(struct cgpu_info *bitfury, int maxroll)
+{
+ char buf[20];
+
+ sprintf(buf, "maxroll %d\n", maxroll);
+ bxf_send_msg(bitfury, buf, C_BXF_MAXROLL);
+}
+
+static bool bxf_send_work(struct cgpu_info *bitfury, struct work *work)
+{
+ char buf[512], hexwork[156];
+
+ __bin2hex(hexwork, work->data, 76);
+ sprintf(buf, "work %s %x\n", hexwork, work->subid);
+ return bxf_send_msg(bitfury, buf, C_BXF_WORK);
+}
+
+static void bxf_update_work(struct cgpu_info *bitfury, struct bitfury_info *info)
+{
+ struct thr_info *thr = info->thr;
+ struct work *work;
+
+ work = get_queue_work(thr, bitfury, thr->id);
+ if (work->drv_rolllimit != info->maxroll) {
+ info->maxroll = work->drv_rolllimit;
+ bxf_send_maxroll(bitfury, info->maxroll);
+ }
+
+ mutex_lock(&info->lock);
+ work->subid = ++info->work_id;
+ mutex_unlock(&info->lock);
+
+ cgtime(&work->tv_work_start);
+ bxf_send_work(bitfury, work);
+}
+
+static void bitfury_flush_work(struct cgpu_info *bitfury)
+{
+ struct bitfury_info *info = bitfury->device_data;
+
+ switch(info->ident) {
+ case IDENT_BXF:
+ bxf_send_flush(bitfury);
+ bxf_update_work(bitfury, info);
+ bxf_update_work(bitfury, info);
+ case IDENT_BF1:
+ default:
+ break;
+ }
+}
+
+static void bitfury_update_work(struct cgpu_info *bitfury)
+{
+ struct bitfury_info *info = bitfury->device_data;
+
+ switch(info->ident) {
+ case IDENT_BXF:
+ bxf_update_work(bitfury, info);
+ case IDENT_BF1:
+ default:
+ break;
+ }
+}
+
+static struct api_data *bf1_api_stats(struct bitfury_info *info)
{
- struct bitfury_info *info = cgpu->device_data;
struct api_data *root = NULL;
double nonce_rate;
char serial[16];
@@ -361,18 +774,97 @@ static struct api_data *bitfury_api_stats(struct cgpu_info *cgpu)
return root;
}
-static void bitfury_init(struct cgpu_info *bitfury)
+static struct api_data *bxf_api_stats(struct bitfury_info *info)
{
- bitfury_close(bitfury);
- bitfury_open(bitfury);
- bitfury_reset(bitfury);
+ struct api_data *root = NULL;
+ double nonce_rate;
+ char buf[32];
+
+ sprintf(buf, "%d.%d", info->ver_major, info->ver_minor);
+ root = api_add_string(root, "Version", buf, true);
+ root = api_add_int(root, "Revision", &info->hw_rev, false);
+ root = api_add_int(root, "Chips", &info->chips, false);
+ nonce_rate = (double)info->total_nonces / (double)info->cycles;
+ root = api_add_double(root, "NonceRate", &nonce_rate, true);
+ root = api_add_int(root, "NoMatchingWork", &info->no_matching_work, false);
+
+ return root;
+}
+
+static struct api_data *bitfury_api_stats(struct cgpu_info *cgpu)
+{
+ struct bitfury_info *info = cgpu->device_data;
+
+ switch(info->ident) {
+ case IDENT_BF1:
+ return bf1_api_stats(info);
+ break;
+ case IDENT_BXF:
+ return bxf_api_stats(info);
+ break;
+ default:
+ break;
+ }
+ return NULL;
+}
+
+static void bitfury_get_statline_before(char *buf, size_t bufsiz, struct cgpu_info *cgpu)
+{
+ struct bitfury_info *info = cgpu->device_data;
+
+ switch(info->ident) {
+ case IDENT_BXF:
+ tailsprintf(buf, bufsiz, "%5.1fC | ", info->temperature);
+ break;
+ case IDENT_BF1:
+ default:
+ tailsprintf(buf, bufsiz, " | ");
+ break;
+ }
+}
+
+static void bf1_init(struct cgpu_info *bitfury)
+{
+ bf1_close(bitfury);
+ bf1_open(bitfury);
+ bf1_reset(bitfury);
+}
+
+static void bitfury_init(struct cgpu_info *bitfury)
+{
+ struct bitfury_info *info = bitfury->device_data;
+
+ switch(info->ident) {
+ case IDENT_BF1:
+ bf1_init(bitfury);
+ break;
+ case IDENT_BXF:
+ default:
+ break;
+ }
+}
+
+static void bxf_close(struct bitfury_info *info)
+{
+ pthread_join(info->read_thr, NULL);
+ mutex_destroy(&info->lock);
}
static void bitfury_shutdown(struct thr_info *thr)
{
struct cgpu_info *bitfury = thr->cgpu;
+ struct bitfury_info *info = bitfury->device_data;
- bitfury_close(bitfury);
+ switch(info->ident) {
+ case IDENT_BF1:
+ bf1_close(bitfury);
+ break;
+ case IDENT_BXF:
+ bxf_close(info);
+ break;
+ default:
+ break;
+ }
}
/* Currently hardcoded to BF1 devices */
@@ -381,9 +873,13 @@ struct device_drv bitfury_drv = {
.dname = "bitfury",
.name = "BF1",
.drv_detect = bitfury_detect,
+ .thread_prepare = bitfury_prepare,
.hash_work = &hash_driver_work,
.scanwork = bitfury_scanwork,
+ .flush_work = bitfury_flush_work,
+ .update_work = bitfury_update_work,
.get_api_stats = bitfury_api_stats,
+ .get_statline_before = bitfury_get_statline_before,
.reinit_device = bitfury_init,
.thread_shutdown = bitfury_shutdown,
.identify_device = bitfury_identify
diff --git a/driver-bitfury.h b/driver-bitfury.h
index 79921b8..851d3cc 100644
--- a/driver-bitfury.h
+++ b/driver-bitfury.h
@@ -15,15 +15,31 @@
struct bitfury_info {
struct cgpu_info *base_cgpu;
- uint8_t version;
- char product[8];
- uint32_t serial;
- char buf[512];
+ struct thr_info *thr;
+ enum sub_ident ident;
int nonces;
int total_nonces;
double saved_nonces;
int cycles;
+ bool valid; /* Set on first valid data being found */
+
+ /* BF1 specific data */
+ uint8_t version;
+ char product[8];
+ uint32_t serial;
struct timeval tv_start;
+
+ /* BXF specific data */
+ pthread_mutex_t lock;
+ pthread_t read_thr;
+ double temperature;
+ int work_id; // Current work->subid
+ int no_matching_work;
+ int maxroll; // Last maxroll sent to device
+ int ver_major;
+ int ver_minor;
+ int hw_rev;
+ int chips;
};
#endif /* BITFURY_H */
diff --git a/driver-hashfast.c b/driver-hashfast.c
index 0b230fa..2f0c076 100644
--- a/driver-hashfast.c
+++ b/driver-hashfast.c
@@ -90,7 +90,8 @@ static const struct hfa_cmd hfa_cmds[] = {
{OP_GWQ_STATUS, "OP_GWQ_STATUS", C_HF_GWQ_STATUS},
{OP_WORK_RESTART, "OP_WORK_RESTART", C_HF_WORK_RESTART},
{OP_USB_STATS1, "OP_USB_STATS1", C_NULL},
- {OP_USB_GWQSTATS, "OP_USB_GWQSTATS", C_HF_GWQSTATS}
+ {OP_USB_GWQSTATS, "OP_USB_GWQSTATS", C_HF_GWQSTATS},
+ {OP_USB_NOTICE, "OP_USB_NOTICE", C_HF_NOTICE}
};
#define HF_USB_CMD_OFFSET (128 - 18)
@@ -118,6 +119,7 @@ static bool hfa_send_frame(struct cgpu_info *hashfast, uint8_t opcode, uint16_t
memcpy(&packet[sizeof(struct hf_header)], data, len);
tx_length = sizeof(struct hf_header) + len;
+ applog(LOG_DEBUG, "HFA %d: Sending %s frame", hashfast->device_id, hfa_cmds[opcode].cmd_name);
ret = usb_write(hashfast, (char *)packet, tx_length, &amount,
hfa_cmds[opcode].usb_cmd);
if (unlikely(ret < 0 || amount != tx_length)) {
@@ -147,20 +149,26 @@ static bool hfa_send_packet(struct cgpu_info *hashfast, struct hf_header *h, int
static bool hfa_get_header(struct cgpu_info *hashfast, struct hf_header *h, uint8_t *computed_crc)
{
- int amount, ret, orig_len, len, ofs = 0, reads = 0;
+ int amount, ret, orig_len, len, ofs = 0;
+ cgtimer_t ts_start;
char buf[512];
char *header;
+ orig_len = len = sizeof(*h);
+
/* Read for up to 200ms till we find the first occurrence of HF_PREAMBLE
* though it should be the first byte unless we get woefully out of
* sync. */
- orig_len = len = sizeof(*h);
+ cgtimer_time(&ts_start);
do {
+ cgtimer_t ts_now, ts_diff;
- if (++reads > 20)
+ cgtimer_time(&ts_now);
+ cgtimer_sub(&ts_now, &ts_start, &ts_diff);
+ if (cgtimer_to_ms(&ts_diff) > 200)
return false;
- ret = usb_read_timeout(hashfast, buf + ofs, len, &amount, 10, C_HF_GETHEADER);
+ ret = usb_read(hashfast, buf + ofs, len, &amount, C_HF_GETHEADER);
if (unlikely(ret && ret != LIBUSB_ERROR_TIMEOUT))
return false;
ofs += amount;
@@ -198,12 +206,21 @@ static const char *hf_usb_init_errors[] = {
"Configuration operation timeout",
"Excessive core failures",
"All cores failed diagnostics",
- "Too many groups configured - increase ntime roll amount"
+ "Too many groups configured - increase ntime roll amount",
+ "Chaining connections detected but secondary board(s) did not respond",
+ "Secondary board communication error",
+ "Main board 12V power is bad",
+ "Secondary board(s) 12V power is bad",
+ "Main board FPGA programming error",
+ "Main board FPGA SPI read timeout",
+ "Main board FPGA Bad magic number",
+ "Main board FPGA SPI write timeout",
+ "Main board FPGA register read/write test failed"
};
static bool hfa_reset(struct cgpu_info *hashfast, struct hashfast_info *info)
{
- struct hf_usb_init_header usb_init, *hu = &usb_init;
+ struct hf_usb_init_header usb_init[2], *hu = usb_init;
struct hf_usb_init_base *db;
struct hf_usb_init_options *ho;
int retries = 0, i;
@@ -212,9 +229,9 @@ static bool hfa_reset(struct cgpu_info *hashfast, struct hashfast_info *info)
uint8_t hcrc;
bool ret;
- // XXX Following items need to be defaults with command-line overrides
- info->hash_clock_rate = 550; // Hash clock rate in Mhz
- info->group_ntime_roll = 1;
+ /* Hash clock rate in Mhz */
+ info->hash_clock_rate = opt_hfa_hash_clock ? opt_hfa_hash_clock : 550;
+ info->group_ntime_roll = opt_hfa_ntime_roll ? opt_hfa_ntime_roll : 1;
info->core_ntime_roll = 1;
// Assemble the USB_INIT request
@@ -222,6 +239,11 @@ static bool hfa_reset(struct cgpu_info *hashfast, struct hashfast_info *info)
hu->preamble = HF_PREAMBLE;
hu->operation_code = OP_USB_INIT;
hu->protocol = PROTOCOL_GLOBAL_WORK_QUEUE; // Protocol to use
+ // Force PLL bypass
+ if (opt_hfa_pll_bypass) {
+ hu->user_configuration = 1;
+ hu->pll_bypass = 1;
+ }
hu->hash_clock = info->hash_clock_rate; // Hash clock rate in Mhz
if (info->group_ntime_roll > 1 && info->core_ntime_roll) {
ho = (struct hf_usb_init_options *)(hu + 1);
@@ -411,7 +433,7 @@ static bool hfa_initialise(struct cgpu_info *hashfast)
return (err == 7);
}
-static bool hfa_detect_one_usb(libusb_device *dev, struct usb_find_devices *found)
+static struct cgpu_info *hfa_detect_one(libusb_device *dev, struct usb_find_devices *found)
{
struct cgpu_info *hashfast;
@@ -421,25 +443,25 @@ static bool hfa_detect_one_usb(libusb_device *dev, struct usb_find_devices *foun
if (!usb_init(hashfast, dev, found)) {
hashfast = usb_free_cgpu(hashfast);
- return false;
+ return NULL;
}
hashfast->usbdev->usb_type = USB_TYPE_STD;
if (!hfa_initialise(hashfast)) {
hashfast = usb_free_cgpu(hashfast);
- return false;
+ return NULL;
}
if (!hfa_detect_common(hashfast)) {
usb_uninit(hashfast);
hashfast = usb_free_cgpu(hashfast);
- return false;
+ return NULL;
}
if (!add_cgpu(hashfast))
- return false;
+ return NULL;
- return true;
+ return hashfast;
}
static void hfa_detect(bool hotplug)
@@ -447,7 +469,7 @@ static void hfa_detect(bool hotplug)
/* Set up the CRC tables only once. */
if (!hotplug)
hfa_init_crc8();
- usb_detect(&hashfast_drv, hfa_detect_one_usb);
+ usb_detect(&hashfast_drv, hfa_detect_one);
}
static bool hfa_get_packet(struct cgpu_info *hashfast, struct hf_header *h)
@@ -674,8 +696,21 @@ static void hfa_update_stats1(struct cgpu_info *hashfast, struct hashfast_info *
#endif
applog(LOG_DEBUG, " max_tx_buffers: %6d", sd->max_tx_buffers);
applog(LOG_DEBUG, " max_rx_buffers: %6d", sd->max_rx_buffers);
+}
- }
+static void hfa_parse_notice(struct cgpu_info *hashfast, struct hf_header *h)
+{
+ struct hf_usb_notice_data *d;
+
+ if (h->data_length == 0) {
+ applog(LOG_DEBUG, "HFA %d: Received OP_USB_NOTICE with zero data length",
+ hashfast->device_id);
+ return;
+ }
+ d = (struct hf_usb_notice_data *)(h + 1);
+ /* FIXME Do something with the notification code d->extra_data here */
+ applog(LOG_NOTICE, "HFA %d NOTICE: %s", hashfast->device_id, d->message);
+}
static void *hfa_read(void *arg)
{
@@ -692,6 +727,9 @@ static void *hfa_read(void *arg)
struct hf_header *h = (struct hf_header *)buf;
bool ret = hfa_get_packet(hashfast, h);
+ if (unlikely(hashfast->usbinfo.nodev))
+ break;
+
if (unlikely(!ret))
continue;
@@ -711,12 +749,16 @@ static void *hfa_read(void *arg)
case OP_USB_STATS1:
hfa_update_stats1(hashfast, info, h);
break;
+ case OP_USB_NOTICE:
+ hfa_parse_notice(hashfast, h);
+ break;
default:
applog(LOG_WARNING, "HFA %d: Unhandled operation code %d",
hashfast->device_id, h->operation_code);
break;
}
}
+ applog(LOG_DEBUG, "HFA %d: Shutting down read thread", hashfast->device_id);
return NULL;
}
@@ -768,6 +810,7 @@ static int64_t hfa_scanwork(struct thr_info *thr)
if (unlikely(thr->work_restart)) {
restart:
+ thr->work_restart = false;
ret = hfa_send_frame(hashfast, HF_USB_CMD(OP_WORK_RESTART), 0, (uint8_t *)NULL, 0);
if (unlikely(!ret)) {
ret = hfa_reset(hashfast, info);
@@ -788,6 +831,11 @@ restart:
jobs = hfa_jobs(info);
}
+ if (jobs) {
+ applog(LOG_DEBUG, "HFA %d: Sending %d new jobs", hashfast->device_id,
+ jobs);
+ }
+
while (jobs-- > 0) {
struct hf_hash_usb op_hash_data;
struct work *work;
@@ -804,13 +852,16 @@ restart:
p = (uint32_t *)(work->data + 64 + 4);
op_hash_data.timestamp = *p++;
op_hash_data.bits = *p++;
+ op_hash_data.starting_nonce = 0;
op_hash_data.nonce_loops = 0;
+ op_hash_data.ntime_loops = 0;
/* Set the number of leading zeroes to look for based on diff.
* Diff 1 = 32, Diff 2 = 33, Diff 4 = 34 etc. */
intdiff = (uint64_t)work->device_diff;
for (i = 31; intdiff; i++, intdiff >>= 1);
op_hash_data.search_difficulty = i;
+ op_hash_data.group = 0;
if ((sequence = info->hash_sequence_head + 1) >= info->num_sequence)
sequence = 0;
ret = hfa_send_frame(hashfast, OP_HASH, sequence, (uint8_t *)&op_hash_data, sizeof(op_hash_data));
diff --git a/driver-hashfast.h b/driver-hashfast.h
index cf6b7ad..5ce7234 100644
--- a/driver-hashfast.h
+++ b/driver-hashfast.h
@@ -16,6 +16,9 @@
#include "elist.h"
#include "hf_protocol.h"
+int opt_hfa_ntime_roll;
+int opt_hfa_hash_clock;
+bool opt_hfa_pll_bypass;
#define HASHFAST_MINER_THREADS 1
// Matching fields for hf_statistics, but large #s for local accumulation, per-die
diff --git a/driver-icarus.c b/driver-icarus.c
index 7da4a99..af35124 100644
--- a/driver-icarus.c
+++ b/driver-icarus.c
@@ -786,7 +786,7 @@ static void get_options(int this_option_offset, struct cgpu_info *icarus, int *b
}
}
-static bool icarus_detect_one(struct libusb_device *dev, struct usb_find_devices *found)
+static struct cgpu_info *icarus_detect_one(struct libusb_device *dev, struct usb_find_devices *found)
{
int this_option_offset = ++option_offset;
struct ICARUS_INFO *info;
@@ -1010,7 +1010,7 @@ cmr2_retry:
}
}
- return true;
+ return icarus;
unshin:
@@ -1022,7 +1022,7 @@ shin:
icarus = usb_free_cgpu(icarus);
- return false;
+ return NULL;
}
static void icarus_detect(bool __maybe_unused hotplug)
diff --git a/driver-klondike.c b/driver-klondike.c
index 3a740ec..5da915c 100644
--- a/driver-klondike.c
+++ b/driver-klondike.c
@@ -765,7 +765,7 @@ static void control_init(struct cgpu_info *klncgpu)
klncgpu->drv->name, klncgpu->device_id, err);
}
-static bool klondike_detect_one(struct libusb_device *dev, struct usb_find_devices *found)
+static struct cgpu_info *klondike_detect_one(struct libusb_device *dev, struct usb_find_devices *found)
{
struct cgpu_info *klncgpu = usb_alloc_cgpu(&klondike_drv, 1);
struct klondike_info *klninfo = NULL;
@@ -823,7 +823,7 @@ static bool klondike_detect_one(struct libusb_device *dev, struct usb_find_devic
applog(LOG_DEBUG, "Klondike cgpu added");
rwlock_init(&klninfo->stat_lock);
cglock_init(&klninfo->klist_lock);
- return true;
+ return klncgpu;
}
}
usb_uninit(klncgpu);
@@ -831,7 +831,7 @@ static bool klondike_detect_one(struct libusb_device *dev, struct usb_find_devic
free(klninfo->free);
free(klninfo);
free(klncgpu);
- return false;
+ return NULL;
}
static void klondike_detect(bool __maybe_unused hotplug)
diff --git a/driver-modminer.c b/driver-modminer.c
index e10cbba..642d13d 100644
--- a/driver-modminer.c
+++ b/driver-modminer.c
@@ -109,7 +109,7 @@ static void do_ping(struct cgpu_info *modminer)
modminer->drv->name, modminer->fpgaid, amount, err);
}
-static bool modminer_detect_one(struct libusb_device *dev, struct usb_find_devices *found)
+static struct cgpu_info *modminer_detect_one(struct libusb_device *dev, struct usb_find_devices *found)
{
char buf[0x100+1];
char *devname = NULL;
@@ -217,7 +217,7 @@ static bool modminer_detect_one(struct libusb_device *dev, struct usb_find_devic
modminer = usb_free_cgpu(modminer);
- return true;
+ return modminer;
unshin:
if (!added)
@@ -232,9 +232,9 @@ shin:
modminer = usb_free_cgpu(modminer);
if (added)
- return true;
+ return modminer;
else
- return false;
+ return NULL;
}
static void modminer_detect(bool __maybe_unused hotplug)
diff --git a/hf_protocol.h b/hf_protocol.h
index 387c284..d193fdc 100644
--- a/hf_protocol.h
+++ b/hf_protocol.h
@@ -8,7 +8,7 @@
//
// Useful data structures and values for interfacing with HashFast products
//
-// Version 1.0
+// Version 1.1
//
#ifndef _HF_PROTOCOL_H_
@@ -45,6 +45,9 @@
#define GN_CORE_VOLTAGE(a) ((float)(a)/256*1.2)
#define GN_DIE_TEMPERATURE(a) ((((float)(a)*240)/4096.0)-61.5)
+// What to use in an OP_CONFIG hdata field to set thermal overload point to a given temp in degrees C
+#define GN_THERMAL_CUTOFF(temp) ((uint16_t)(((temp)+61.5)*4096/240))
+
// The sequence distance between a sent and received sequence number.
#define HF_SEQUENCE_DISTANCE(tx,rx) ((tx)>=(rx)?((tx)-(rx)):(info->num_sequence+(tx)-(rx)))
@@ -92,13 +95,24 @@
#define E_CLOCKGATE_TIMEOUT 3
#define E_CONFIG_TIMEOUT 4
#define E_EXCESS_CORE_FAILURES 5
+#define E_TOTAL_CORE_FAILURES 6
+#define E_TOO_MANY_GROUPS 7
+#define E_NO_SLAVES 8
+#define E_SLAVE_COMM 9
+#define E_MAIN_POWER_BAD 10
+#define E_SECONDARY_POWER_BAD 11
+#define E_BOARD_1 12
+#define E_BOARD_2 13
+#define E_BOARD_3 14
+#define E_BOARD_4 15
+#define E_BOARD_5 16
#define U32SIZE(x) (sizeof(x)/sizeof(uint32_t))
// Structure definitions, LE platforms
-#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+#if __BYTE_ORDER == __BIG_ENDIAN
#include "hf_protocol_be.h"
#else
// Generic header
diff --git a/miner.h b/miner.h
index 261527f..94e60d9 100644
--- a/miner.h
+++ b/miner.h
@@ -979,6 +979,7 @@ extern char *opt_kernel_path;
extern char *opt_socks_proxy;
extern char *cgminer_path;
extern bool opt_fail_only;
+extern bool opt_lowmem;
extern bool opt_autofan;
extern bool opt_autoengine;
extern bool use_curses;
@@ -1448,6 +1449,7 @@ extern struct work *__find_work_bymidstate(struct work *que, char *midstate, siz
extern struct work *find_queued_work_bymidstate(struct cgpu_info *cgpu, char *midstate, size_t midstatelen, char *data, int offset, size_t datalen);
extern struct work *clone_queued_work_bymidstate(struct cgpu_info *cgpu, char *midstate, size_t midstatelen, char *data, int offset, size_t datalen);
extern void __work_completed(struct cgpu_info *cgpu, struct work *work);
+extern int age_queued_work(struct cgpu_info *cgpu, double secs);
extern void work_completed(struct cgpu_info *cgpu, struct work *work);
extern struct work *take_queued_work_bymidstate(struct cgpu_info *cgpu, char *midstate, size_t midstatelen, char *data, int offset, size_t datalen);
extern void hash_driver_work(struct thr_info *mythr);
@@ -1479,6 +1481,7 @@ extern void adl(void);
extern void app_restart(void);
extern void clean_work(struct work *work);
extern void free_work(struct work *work);
+extern void set_work_ntime(struct work *work, int ntime);
extern struct work *copy_work_noffset(struct work *base_work, int noffset);
#define copy_work(work_in) copy_work_noffset(work_in, 0)
extern struct thr_info *get_thread(int thr_id);
diff --git a/miner.php b/miner.php
index fd42271..ff2e457 100644
--- a/miner.php
+++ b/miner.php
@@ -2910,7 +2910,7 @@ function display()
if ($allowcustompages === true)
{
- $pg = trim(getparam('pg', true));
+ $pg = urlencode(trim(getparam('pg', true)));
if ($pagesonly === true)
{
if ($pg !== null && $pg !== '')
diff --git a/usbutils.c b/usbutils.c
index 212dfa8..cd717da 100644
--- a/usbutils.c
+++ b/usbutils.c
@@ -18,15 +18,9 @@
#include "miner.h"
#include "usbutils.h"
-#define NODEV(err) ((err) == LIBUSB_ERROR_NO_DEVICE || \
- (err) == LIBUSB_ERROR_PIPE || \
- (err) == LIBUSB_ERROR_OTHER)
+#define NODEV(err) ((err) != LIBUSB_SUCCESS && (err) != LIBUSB_ERROR_TIMEOUT)
-/* Timeout errors on writes are basically unrecoverable */
-#define WRITENODEV(err) ((err) == LIBUSB_ERROR_TIMEOUT || NODEV(err))
-
-#define NOCONTROLDEV(err) ((err) == LIBUSB_ERROR_NO_DEVICE || \
- (err) == LIBUSB_ERROR_OTHER)
+#define NOCONTROLDEV(err) ((err) < 0 && NODEV(err))
/*
* WARNING - these assume DEVLOCK(cgpu, pstate) is called first and
@@ -57,15 +51,16 @@
#define USB_CONFIG 1
+#define BITFURY_TIMEOUT_MS 999
+#define DRILLBIT_TIMEOUT_MS 999
+#define ICARUS_TIMEOUT_MS 999
+
#ifdef WIN32
#define BFLSC_TIMEOUT_MS 999
#define BITFORCE_TIMEOUT_MS 999
-#define BITFURY_TIMEOUT_MS 999
-#define DRILLBIT_TIMEOUT_MS 999
#define MODMINER_TIMEOUT_MS 999
#define AVALON_TIMEOUT_MS 999
#define KLONDIKE_TIMEOUT_MS 999
-#define ICARUS_TIMEOUT_MS 999
#define HASHFAST_TIMEOUT_MS 999
/* The safety timeout we use, cancelling async transfers on windows that fail
@@ -74,12 +69,9 @@
#else
#define BFLSC_TIMEOUT_MS 300
#define BITFORCE_TIMEOUT_MS 200
-#define BITFURY_TIMEOUT_MS 100
-#define DRILLBIT_TIMEOUT_MS 200
#define MODMINER_TIMEOUT_MS 100
#define AVALON_TIMEOUT_MS 200
#define KLONDIKE_TIMEOUT_MS 200
-#define ICARUS_TIMEOUT_MS 200
#define HASHFAST_TIMEOUT_MS 200
#endif
@@ -159,6 +151,20 @@ static struct usb_intinfo drillbit_ints[] = {
USB_EPS(1, drillbit_bulk_epinfos),
USB_EPS(0, drillbit_int_epinfos)
};
+
+static struct usb_epinfo bxf0_epinfos[] = {
+ { LIBUSB_TRANSFER_TYPE_INTERRUPT, 8, EPI(1), 0, 0 }
+};
+
+static struct usb_epinfo bxf1_epinfos[] = {
+ { LIBUSB_TRANSFER_TYPE_BULK, 64, EPI(2), 0, 0 },
+ { LIBUSB_TRANSFER_TYPE_BULK, 64, EPO(2), 0, 0 }
+};
+
+static struct usb_intinfo bxf_ints[] = {
+ USB_EPS(1, bxf1_epinfos),
+ USB_EPS(0, bxf0_epinfos)
+};
#endif
#ifdef USE_HASHFAST
@@ -333,7 +339,7 @@ static struct usb_find_devices find_dev[] = {
{
.drv = DRIVER_bitfury,
.name = "BF1",
- .ident = IDENT_BFU,
+ .ident = IDENT_BF1,
.idVendor = 0x03eb,
.idProduct = 0x204b,
.config = 1,
@@ -358,6 +364,19 @@ static struct usb_find_devices find_dev[] = {
.iProduct = NULL, /* Can be Thumb or Eight, same driver */
INTINFO(drillbit_ints)
},
+ {
+ .drv = DRIVER_bitfury,
+ .name = "BXF",
+ .ident = IDENT_BXF,
+ .idVendor = 0x198c,
+ .idProduct = 0xb1f1,
+ .config = 1,
+ .timeout = BITFURY_TIMEOUT_MS,
+ .latency = LATENCY_UNUSED,
+ .iManufacturer = "c-scape",
+ .iProduct = "bi?fury",
+ INTINFO(bxf_ints)
+ },
#endif
#ifdef USE_MODMINER
{
@@ -517,22 +536,14 @@ static const char *BLANK = "";
static const char *space = " ";
static const char *nodatareturned = "no data returned ";
+/* Fake success on IO errors allowing code to retry up to USB_RETRY_MAX */
#define IOERR_CHECK(cgpu, err) \
if (err == LIBUSB_ERROR_IO) { \
cgpu->usbinfo.ioerr_count++; \
- cgpu->usbinfo.continuous_ioerr_count++; \
- } else { \
- cgpu->usbinfo.continuous_ioerr_count = 0; \
- }
-
-/* Timeout errors on writes are unusual and should be treated as IO errors. */
-#define WRITEIOERR_CHECK(cgpu, err) \
- if (err == LIBUSB_ERROR_IO || err == LIBUSB_ERROR_TIMEOUT) { \
- cgpu->usbinfo.ioerr_count++; \
- cgpu->usbinfo.continuous_ioerr_count++; \
- } else { \
- cgpu->usbinfo.continuous_ioerr_count = 0; \
- }
+ if (++cgpu->usbinfo.continuous_ioerr_count < USB_RETRY_MAX) \
+ err = LIBUSB_SUCCESS; \
+ } else \
+ cgpu->usbinfo.continuous_ioerr_count = 0;
#if 0 // enable USBDEBUG - only during development testing
static const char *debug_true_str = "true";
@@ -547,8 +558,8 @@ static const char *nodatareturned = "no data returned ";
// For device limits by driver
static struct driver_count {
- uint32_t count;
- uint32_t limit;
+ int count;
+ int limit;
} drv_count[DRIVER_MAX];
// For device limits by list of bus/dev
@@ -1418,6 +1429,7 @@ void usb_uninit(struct cgpu_info *cgpu)
static void release_cgpu(struct cgpu_info *cgpu)
{
struct cg_usb_device *cgusb = cgpu->usbdev;
+ bool initted = cgpu->usbinfo.initialised;
struct cgpu_info *lookcgpu;
int i;
@@ -1428,9 +1440,11 @@ static void release_cgpu(struct cgpu_info *cgpu)
applog(LOG_DEBUG, "USB release %s%i",
cgpu->drv->name, cgpu->device_id);
- zombie_devs++;
- total_count--;
- drv_count[cgpu->drv->drv_id].count--;
+ if (initted) {
+ zombie_devs++;
+ total_count--;
+ drv_count[cgpu->drv->drv_id].count--;
+ }
cgpu->usbinfo.nodev = true;
cgpu->usbinfo.nodev_count++;
@@ -1440,8 +1454,10 @@ static void release_cgpu(struct cgpu_info *cgpu)
for (i = 0; i < total_devices; i++) {
lookcgpu = get_devices(i);
if (lookcgpu != cgpu && lookcgpu->usbdev == cgusb) {
- total_count--;
- drv_count[lookcgpu->drv->drv_id].count--;
+ if (initted) {
+ total_count--;
+ drv_count[lookcgpu->drv->drv_id].count--;
+ }
lookcgpu->usbinfo.nodev = true;
lookcgpu->usbinfo.nodev_count++;
@@ -1598,6 +1614,7 @@ static int _usb_init(struct cgpu_info *cgpu, struct libusb_device *dev, struct u
"USB init, open device failed, err %d, "
"you don't have privilege to access %s",
err, devstr);
+ applog(LOG_ERR, "See README file included for help");
break;
#ifdef WIN32
// Windows specific message
@@ -1606,6 +1623,7 @@ static int _usb_init(struct cgpu_info *cgpu, struct libusb_device *dev, struct u
"USB init, open device failed, err %d, "
"you need to install a WinUSB driver for %s",
err, devstr);
+ applog(LOG_ERR, "See README.txt file included for help");
break;
#endif
default:
@@ -1984,11 +2002,12 @@ static struct usb_find_devices *usb_check(__maybe_unused struct device_drv *drv,
return NULL;
}
-void usb_detect(struct device_drv *drv, bool (*device_detect)(struct libusb_device *, struct usb_find_devices *))
+void usb_detect(struct device_drv *drv, struct cgpu_info *(*device_detect)(struct libusb_device *, struct usb_find_devices *))
{
libusb_device **list;
ssize_t count, i;
struct usb_find_devices *found;
+ struct cgpu_info *cgpu;
applog(LOG_DEBUG, "USB scan devices: checking for %s devices", drv->name);
@@ -2033,9 +2052,11 @@ void usb_detect(struct device_drv *drv, bool (*device_detect)(struct libusb_devi
if (is_in_use(list[i]) || cgminer_usb_lock(drv, list[i]) == false)
free(found);
else {
- if (!device_detect(list[i], found))
+ cgpu = device_detect(list[i], found);
+ if (!cgpu)
cgminer_usb_unlock(drv, list[i]);
else {
+ cgpu->usbinfo.initialised = true;
total_count++;
drv_count[drv->drv_id].count++;
}
@@ -2293,37 +2314,6 @@ static void rejected_inc(struct cgpu_info *cgpu, uint32_t mode)
}
#endif
-static char *find_end(unsigned char *buf, unsigned char *ptr, int ptrlen, int tot, char *end, int endlen, bool first)
-{
- unsigned char *search;
-
- if (endlen > tot)
- return NULL;
-
- // If end is only 1 char - do a faster search
- if (endlen == 1) {
- if (first)
- search = buf;
- else
- search = ptr;
-
- return strchr((char *)search, *end);
- } else {
- if (first)
- search = buf;
- else {
- // must allow end to have been chopped in 2
- if ((tot - ptrlen) >= (endlen - 1))
- search = ptr - (endlen - 1);
- else
- search = ptr - (tot - ptrlen);
- }
-
- return strstr((char *)search, end);
- }
-}
-
-#define USB_MAX_READ 8192
#define USB_RETRY_MAX 5
struct usb_transfer {
@@ -2497,15 +2487,13 @@ usb_bulk_transfer(struct libusb_device_handle *dev_handle, int intinfo,
/* Avoid any async transfers during shutdown to allow the polling
* thread to be shut down after all existing transfers are complete */
- if (unlikely(cgpu->shutdown))
+ if (opt_lowmem || cgpu->shutdown)
return libusb_bulk_transfer(dev_handle, endpoint, data, length, transferred, timeout);
init_usb_transfer(&ut);
if ((endpoint & LIBUSB_ENDPOINT_DIR_MASK) == LIBUSB_ENDPOINT_OUT) {
memcpy(buf, data, length);
- if (length > usb_epinfo->wMaxPacketSize)
- length = usb_epinfo->wMaxPacketSize;
ut.transfer->flags |= LIBUSB_TRANSFER_ADD_ZERO_PACKET;
}
@@ -2555,23 +2543,27 @@ usb_bulk_transfer(struct libusb_device_handle *dev_handle, int intinfo,
int _usb_read(struct cgpu_info *cgpu, int intinfo, int epinfo, char *buf, size_t bufsiz, int *processed, int timeout, const char *end, enum usb_cmds cmd, bool readonce, bool cancellable)
{
- struct cg_usb_device *usbdev;
- bool ftdi;
+ unsigned char *ptr, usbbuf[USB_READ_BUFSIZE];
struct timeval read_start, tv_finish;
- unsigned int initial_timeout;
int bufleft, err, got, tot, pstate;
- bool first = true;
- bool dobuffer;
- char *search;
- int endlen;
- unsigned char *ptr, *usbbuf = cgpu->usbinfo.bulkbuf;
const size_t usbbufread = 512; /* Always read full size */
+ struct cg_usb_device *usbdev;
+ unsigned int initial_timeout;
+ bool first = true;
+ int endlen = 0;
+ char *eom = NULL;
double done;
+ bool ftdi;
+
+ memset(usbbuf, 0, USB_READ_BUFSIZE);
+ memset(buf, 0, bufsiz);
+
+ if (end)
+ endlen = strlen(end);
DEVRLOCK(cgpu, pstate);
if (cgpu->usbinfo.nodev) {
- *buf = '\0';
*processed = 0;
USB_REJECT(cgpu, MODE_BULK_READ);
@@ -2590,75 +2582,6 @@ int _usb_read(struct cgpu_info *cgpu, int intinfo, int epinfo, char *buf, size_t
if (timeout == DEVTIMEOUT)
timeout = usbdev->found->timeout;
- if (end == NULL) {
- tot = usbdev->bufamt;
- bufleft = bufsiz - tot;
- if (tot)
- memcpy(usbbuf, usbdev->buffer, tot);
- ptr = usbbuf + tot;
- usbdev->bufamt = 0;
-
- err = LIBUSB_SUCCESS;
- initial_timeout = timeout;
- cgtime(&read_start);
- while (bufleft > 0) {
- got = 0;
-
- err = usb_bulk_transfer(usbdev->handle, intinfo, epinfo,
- ptr, usbbufread, &got, timeout,
- cgpu, MODE_BULK_READ, cmd, first ? SEQ0 : SEQ1,
- cancellable);
- cgtime(&tv_finish);
- ptr[got] = '\0';
-
- USBDEBUG("USB debug: @_usb_read(%s (nodev=%s)) first=%s err=%d%s got=%d ptr='%s' usbbufread=%d", cgpu->drv->name, bool_str(cgpu->usbinfo.nodev), bool_str(first), err, isnodev(err), got, (char *)str_text((char *)ptr), (int)usbbufread);
-
- IOERR_CHECK(cgpu, err);
-
- if (ftdi) {
- // first 2 bytes returned are an FTDI status
- if (got > 2) {
- got -= 2;
- memmove(ptr, ptr+2, got+1);
- } else {
- got = 0;
- *ptr = '\0';
- }
- }
-
- tot += got;
-
- if (err || readonce)
- break;
-
- ptr += got;
- bufleft -= got;
-
- first = false;
-
- done = tdiff(&tv_finish, &read_start);
- // N.B. this is: return last err with whatever size has already been read
- timeout = initial_timeout - (done * 1000);
- if (timeout <= 0)
- break;
- }
-
- // N.B. usbdev->buffer was emptied before the while() loop
- if (tot > (int)bufsiz) {
- usbdev->bufamt = tot - bufsiz;
- memcpy(usbdev->buffer, usbbuf + bufsiz, usbdev->bufamt);
- tot -= usbdev->bufamt;
- usbbuf[tot] = '\0';
- applog(LOG_DEBUG, "USB: %s%i read1 buffering %d extra bytes",
- cgpu->drv->name, cgpu->device_id, usbdev->bufamt);
- }
-
- *processed = tot;
- memcpy((char *)buf, (const char *)usbbuf, (tot < (int)bufsiz) ? tot + 1 : (int)bufsiz);
-
- goto out_unlock;
- }
-
tot = usbdev->bufamt;
bufleft = bufsiz - tot;
if (tot)
@@ -2666,13 +2589,13 @@ int _usb_read(struct cgpu_info *cgpu, int intinfo, int epinfo, char *buf, size_t
ptr = usbbuf + tot;
usbdev->bufamt = 0;
- endlen = strlen(end);
err = LIBUSB_SUCCESS;
+ if (end != NULL)
+ eom = strstr((const char *)usbbuf, end);
+
initial_timeout = timeout;
cgtime(&read_start);
-
- while (bufleft > 0) {
- got = 0;
+ while (bufleft > 0 && !eom) {
err = usb_bulk_transfer(usbdev->handle, intinfo, epinfo,
ptr, usbbufread, &got, timeout,
cgpu, MODE_BULK_READ, cmd, first ? SEQ0 : SEQ1,
@@ -2696,59 +2619,48 @@ int _usb_read(struct cgpu_info *cgpu, int intinfo, int epinfo, char *buf, size_t
}
tot += got;
+ if (end != NULL)
+ eom = strstr((const char *)usbbuf, end);
if (err || readonce)
break;
- if (find_end(usbbuf, ptr, got, tot, (char *)end, endlen, first))
- break;
-
ptr += got;
bufleft -= got;
first = false;
done = tdiff(&tv_finish, &read_start);
- // N.B. this is: return LIBUSB_SUCCESS with whatever size has already been read
+ // N.B. this is: return last err with whatever size has already been read
timeout = initial_timeout - (done * 1000);
if (timeout <= 0)
break;
}
- dobuffer = false;
+ /* If we found the end of message marker, just use that data and
+ * return success. */
+ if (eom) {
+ size_t eomlen = (void *)eom - (void *)usbbuf + endlen;
- if ((search = find_end(usbbuf, usbbuf, tot, tot, (char *)end, endlen, true))) {
- // end finishes after bufsiz
- if ((search + endlen - (char *)usbbuf) > (int)bufsiz) {
- usbdev->bufamt = tot - bufsiz;
- dobuffer = true;
- } else {
- // extra data after end
- if (*(search + endlen)) {
- usbdev->bufamt = tot - (search + endlen - (char *)usbbuf);
- dobuffer = true;
- }
- }
- } else {
- // no end, but still bigger than bufsiz
- if (tot > (int)bufsiz) {
- usbdev->bufamt = tot - bufsiz;
- dobuffer = true;
+ if (eomlen < bufsiz) {
+ bufsiz = eomlen;
+ err = LIBUSB_SUCCESS;
}
}
- if (dobuffer) {
+ // N.B. usbdev->buffer was emptied before the while() loop
+ if (tot > (int)bufsiz) {
+ usbdev->bufamt = tot - bufsiz;
+ memcpy(usbdev->buffer, usbbuf + bufsiz, usbdev->bufamt);
tot -= usbdev->bufamt;
- memcpy(usbdev->buffer, usbbuf + tot, usbdev->bufamt);
usbbuf[tot] = '\0';
- applog(LOG_DEBUG, "USB: %s%i read2 buffering %d extra bytes",
+ applog(LOG_DEBUG, "USB: %s%i read1 buffering %d extra bytes",
cgpu->drv->name, cgpu->device_id, usbdev->bufamt);
}
*processed = tot;
memcpy((char *)buf, (const char *)usbbuf, (tot < (int)bufsiz) ? tot + 1 : (int)bufsiz);
-out_unlock:
if (err && err != LIBUSB_ERROR_TIMEOUT) {
applog(LOG_WARNING, "%s %i %s usb read err:(%d) %s", cgpu->drv->name, cgpu->device_id, usb_cmdname(cmd),
err, libusb_error_name(err));
@@ -2812,7 +2724,7 @@ int _usb_write(struct cgpu_info *cgpu, int intinfo, int epinfo, char *buf, size_
USBDEBUG("USB debug: @_usb_write(%s (nodev=%s)) err=%d%s sent=%d", cgpu->drv->name, bool_str(cgpu->usbinfo.nodev), err, isnodev(err), sent);
- WRITEIOERR_CHECK(cgpu, err);
+ IOERR_CHECK(cgpu, err);
tot += sent;
@@ -2840,7 +2752,7 @@ int _usb_write(struct cgpu_info *cgpu, int intinfo, int epinfo, char *buf, size_
err = LIBUSB_ERROR_OTHER;
}
out_noerrmsg:
- if (WRITENODEV(err)) {
+ if (NODEV(err)) {
cg_ruwlock(&cgpu->usbinfo.devlock);
release_cgpu(cgpu);
DEVWUNLOCK(cgpu, pstate);
@@ -2929,7 +2841,7 @@ int __usb_transfer(struct cgpu_info *cgpu, uint8_t request_type, uint8_t bReques
USBDEBUG("USB debug: @_usb_transfer(%s (nodev=%s)) err=%d%s", cgpu->drv->name, bool_str(cgpu->usbinfo.nodev), err, isnodev(err));
- WRITEIOERR_CHECK(cgpu, err);
+ IOERR_CHECK(cgpu, err);
if (err < 0 && err != LIBUSB_ERROR_TIMEOUT) {
applog(LOG_WARNING, "%s %i usb transfer err:(%d) %s", cgpu->drv->name, cgpu->device_id,
diff --git a/usbutils.h b/usbutils.h
index 214f97a..d7f06b4 100644
--- a/usbutils.h
+++ b/usbutils.h
@@ -134,24 +134,25 @@ struct usb_intinfo {
enum sub_ident {
IDENT_UNK = 0,
+ IDENT_AMU,
+ IDENT_AVA,
IDENT_BAJ,
IDENT_BAL,
- IDENT_BAS,
IDENT_BAM,
+ IDENT_BAS,
+ IDENT_BBF,
+ IDENT_BF1,
IDENT_BFL,
- IDENT_BFU,
- IDENT_MMQ,
- IDENT_AVA,
+ IDENT_BLT,
IDENT_BTB,
+ IDENT_BXF,
+ IDENT_CMR1,
+ IDENT_CMR2,
IDENT_HFA,
- IDENT_BBF,
- IDENT_KLN,
IDENT_ICA,
- IDENT_AMU,
- IDENT_BLT,
+ IDENT_KLN,
IDENT_LLT,
- IDENT_CMR1,
- IDENT_CMR2,
+ IDENT_MMQ,
IDENT_ZTX,
IDENT_DRB
};
@@ -183,6 +184,12 @@ enum usb_types {
};
#define USB_MAX_READ 8192
+/*
+ * We add 4: 1 for null, 2 for FTDI status and 1 to round to 4 bytes
+ * If a single device ever has multiple end points then it will need
+ * multiple of these
+ */
+#define USB_READ_BUFSIZE (USB_MAX_READ + 4)
struct cg_usb_device {
struct usb_find_devices *found;
@@ -224,6 +231,7 @@ struct cg_usb_info {
uint8_t device_address;
int usbstat;
bool nodev;
+ bool initialised;
int nodev_count;
struct timeval last_nodev;
uint32_t ioerr_count;
@@ -251,13 +259,6 @@ struct cg_usb_info {
uint64_t write_delay_count;
double total_write_delay;
- /*
- * We add 4: 1 for null, 2 for FTDI status and 1 to round to 4 bytes
- * If a single device ever has multiple end points then it will need
- * multiple of these
- */
- unsigned char bulkbuf[USB_MAX_READ+4];
-
uint64_t tmo_count;
struct cg_usb_tmo usb_tmo[USB_TMOS];
};
@@ -359,6 +360,12 @@ struct cg_usb_info {
USB_ADD_COMMAND(C_BF1_FLUSH, "BF1Flush") \
USB_ADD_COMMAND(C_BF1_IFLUSH, "BF1InterruptFlush") \
USB_ADD_COMMAND(C_BF1_IDENTIFY, "BF1Identify") \
+ USB_ADD_COMMAND(C_BXF_READ, "BXFRead") \
+ USB_ADD_COMMAND(C_BXF_WORK, "BXFWork") \
+ USB_ADD_COMMAND(C_BXF_TARGET, "BXFTarget") \
+ USB_ADD_COMMAND(C_BXF_VERSION, "BXFVersion") \
+ USB_ADD_COMMAND(C_BXF_MAXROLL, "BXFMaxRoll") \
+ USB_ADD_COMMAND(C_BXF_FLUSH, "BXFFlush") \
USB_ADD_COMMAND(C_HF_RESET, "HFReset") \
USB_ADD_COMMAND(C_HF_PLL_CONFIG, "HFPLLConfig") \
USB_ADD_COMMAND(C_HF_ADDRESS, "HFAddress") \
@@ -375,6 +382,7 @@ struct cg_usb_info {
USB_ADD_COMMAND(C_HF_GWQ_STATUS, "HFGWQStatus") \
USB_ADD_COMMAND(C_HF_WORK_RESTART, "HFWorkRestart") \
USB_ADD_COMMAND(C_HF_GWQSTATS, "HFGWQStats") \
+ USB_ADD_COMMAND(C_HF_NOTICE, "HFNotice") \
USB_ADD_COMMAND(C_HF_GETHEADER, "HFGetHeader") \
USB_ADD_COMMAND(C_HF_GETDATA, "HFGetData") \
USB_ADD_COMMAND(C_HF_CLEAR_READ, "HFClearRead")
@@ -399,7 +407,7 @@ struct cgpu_info *usb_alloc_cgpu(struct device_drv *drv, int threads);
struct cgpu_info *usb_free_cgpu(struct cgpu_info *cgpu);
void usb_uninit(struct cgpu_info *cgpu);
bool usb_init(struct cgpu_info *cgpu, struct libusb_device *dev, struct usb_find_devices *found);
-void usb_detect(struct device_drv *drv, bool (*device_detect)(struct libusb_device *, struct usb_find_devices *));
+void usb_detect(struct device_drv *drv, struct cgpu_info *(*device_detect)(struct libusb_device *, struct usb_find_devices *));
struct api_data *api_usb_stats(int *count);
void update_usb_stats(struct cgpu_info *cgpu);
int _usb_read(struct cgpu_info *cgpu, int intinfo, int epinfo, char *buf, size_t bufsiz, int *processed, int timeout, const char *end, enum usb_cmds cmd, bool readonce, bool cancellable);
diff --git a/util.c b/util.c
index f5472c3..0e9670c 100644
--- a/util.c
+++ b/util.c
@@ -1738,8 +1738,10 @@ bool parse_method(struct pool *pool, char *s)
}
method = json_object_get(val, "method");
- if (!method)
+ if (!method) {
+ json_decref(val);
return ret;
+ }
err_val = json_object_get(val, "error");
params = json_object_get(val, "params");
@@ -1753,42 +1755,51 @@ bool parse_method(struct pool *pool, char *s)
applog(LOG_INFO, "JSON-RPC method decode failed: %s", ss);
+ json_decref(val);
free(ss);
return ret;
}
buf = (char *)json_string_value(method);
- if (!buf)
+ if (!buf) {
+ json_decref(val);
return ret;
+ }
if (!strncasecmp(buf, "mining.notify", 13)) {
if (parse_notify(pool, params))
pool->stratum_notify = ret = true;
else
pool->stratum_notify = ret = false;
+ json_decref(val);
return ret;
}
if (!strncasecmp(buf, "mining.set_difficulty", 21) && parse_diff(pool, params)) {
ret = true;
+ json_decref(val);
return ret;
}
if (!strncasecmp(buf, "client.reconnect", 16) && parse_reconnect(pool, params)) {
ret = true;
+ json_decref(val);
return ret;
}
if (!strncasecmp(buf, "client.get_version", 18) && send_version(pool, val)) {
ret = true;
+ json_decref(val);
return ret;
}
if (!strncasecmp(buf, "client.show_message", 19) && show_message(pool, params)) {
ret = true;
+ json_decref(val);
return ret;
}
+ json_decref(val);
return ret;
}
@@ -1828,16 +1839,19 @@ bool auth_stratum(struct pool *pool)
ss = json_dumps(err_val, JSON_INDENT(3));
else
ss = strdup("(unknown reason)");
- applog(LOG_WARNING, "pool %d JSON stratum auth failed: %s", pool->pool_no, ss);
+ applog(LOG_INFO, "pool %d JSON stratum auth failed: %s", pool->pool_no, ss);
free(ss);
- return ret;
+ goto out;
}
ret = true;
applog(LOG_INFO, "Stratum authorisation success for pool %d", pool->pool_no);
pool->probed = true;
successful_connect = true;
+
+out:
+ json_decref(val);
return ret;
}
@@ -2383,6 +2397,7 @@ out:
applog(LOG_DEBUG, "Failed to resume stratum, trying afresh");
noresume = true;
+ json_decref(val);
goto resend;
}
applog(LOG_DEBUG, "Initiate stratum failed");
@@ -2390,6 +2405,7 @@ out:
suspend_stratum(pool);
}
+ json_decref(val);
return ret;
}