Merge pull request #1 from ckolivas/master Sync with new upstream version
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
diff --git a/ASIC-README b/ASIC-README
index 648142f..6019325 100644
--- a/ASIC-README
+++ b/ASIC-README
@@ -18,6 +18,7 @@ Currently supported devices include:
- Cointerra
- Antminer S1
- BFx2 USB
+- Rockminer R-Box
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
@@ -120,6 +121,11 @@ BITMINE A1 devices
Bitmine A1 devices need the --enable-bitmine_A1 compile option set.
+
+Rockminer R-Box
+
+Rockminer R-Box devices need the --enable-icarus compile option set.
+
---
GETTING STARTED WITH USB ASICS
@@ -240,6 +246,7 @@ ASIC SPECIFIC COMMANDS
--minion-overheat Enable directly halting any chip when the status exceeds 100C
--minion-temp <arg> Set minion chip temperature threshold, single value or comma list, range 120-160 (default: 135C)
--nfu-bits <arg> Set nanofury bits for overclocking, range 32-63 (default: 50)
+--rock-freq <arg> Set RockMiner frequency in MHz, range 125-500 (default: 270)
ANTMINER S1 DEVICES
@@ -630,6 +637,13 @@ Set 0 for fields you want to keep untouched to default, e.g.
--bitmine-a1-options 0:0:400
to only set SPI clock to 400kHz
+
+Rockminer R-Box Devices
+
+--rock-freq <arg> Set RockMiner frequency in MHz, range 125-500 (default: 270)
+
+Note that only a limited range is likely to be accepted (usually 200-290)
+
---
This code is provided entirely free of charge by the programmer in his spare
diff --git a/NEWS b/NEWS
index 4d51b97..27f2cad 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,29 @@
+Version 4.3.5 - 10th June 2014
+
+- Cointerra driver updates.
+- Sleep before retrying in the test pool thread after a pool has died
+- Use valid_ascii testing for job_id since it need not be hex only
+- Only show slow/down message till pool is flagged idle
+- Do some random sanity checking for stratum message parsing
+- Keep looking for when a pool comes to life at startup and touch the logwin so
+the message is not invisible
+- Fix no libcurl build
+- Added Drillbit Thumb to udev rules.
+- Avoid dereference on getting API stats on partially initialised HFA instances
+- A1: add support for updated product variants, small fixes
+- Add one more usbutils fix
+- Convert uses of usbutils memcpy to cg_memcpy
+- Add a sanity checking memcpy function which checks for overflows
+- minion - count force use reread
+- minion - add a disabled ioctl() test
+- minion - add more checking of SPI results for corruption
+- minion - optional (disabled) ioctl() debug
+- Increase S1 overheat to 75 degrees C
+- Add ruby api-example to API-README
+- minion - allow core selection at runtime
+- API - lcd all-in-one brief summary
+
+
Version 4.3.4 - 25th May 2014
- Add support for 2 nonces per block in spond driver
diff --git a/README b/README
index 55f6b2b..bfbafb6 100644
--- a/README
+++ b/README
@@ -234,6 +234,7 @@ Options for both config file and command line:
--quiet|-q Disable logging output, display status and errors
--quota|-U <arg> quota;URL combination for server with load-balance strategy quotas
--real-quiet Disable all output
+--rock-freq <arg> Set RockMiner frequency in MHz, range 125-500 (default: 270)
--rotate <arg> Change multipool strategy from failover to regularly rotate at N minutes (default: 0)
--round-robin Change multipool strategy from failover to round robin on failure
--scan-time|-s <arg> Upper bound on time spent scanning current work, in seconds (default: -1)
@@ -285,6 +286,7 @@ ASIC only options:
--bitburner-fury-options <arg> Override avalon-options for BitBurner Fury boards baud:miners:asic:timeout:freq
--bitburner-fury-voltage <arg> Set BitBurner Fury core voltage, in millivolts
--bitburner-voltage <arg> Set BitBurner (Avalon) core voltage, in millivolts
+--bitmine-a1-options <ref_clk>:<sys_clk>:<spi_clk>:<max_chip>
--bxf-temp-target <arg> Set target temperature for BXF devices (default: 82)
--bxm-bits <arg> Set BXM bits for overclocking (default: 50)
--hfa-hash-clock <arg> Set hashfast clock speed (default: 550)
@@ -295,6 +297,7 @@ ASIC only options:
--hfa-temp-overheat <arg> Set the hashfast overheat throttling temperature (default: 95)
--hfa-temp-target <arg> Set the hashfast target temperature (0 to disable) (default: 88)
--klondike-options <arg> Set klondike options clock:temptarget
+--rock-freq <arg> Set RockMiner frequency in MHz, range 125-500 (default: 270)
See ASIC-README for more information regarding these.
@@ -310,7 +313,8 @@ 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, ModMiner FPGAs, BPMC/BGMC BF1 USB ASICs,
Bi*fury USB ASICs, Onestring miner USB ASICs, Hexfury USB ASICs, Nanofury USB
-ASICs, Antminer U1/U2/U2+ USB ASICs, Cointerra devices and BFx2 USB ASICs.
+ASICs, Antminer U1/U2/U2+ USB ASICs, Cointerra devices, BFx2 USB ASICs and
+Rockminer R-Box USB ASICs.
---
diff --git a/cgminer.c b/cgminer.c
index 04cf81e..b03a44a 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -208,6 +208,7 @@ static bool no_work;
char *opt_icarus_options = NULL;
char *opt_icarus_timing = NULL;
float opt_anu_freq = 200;
+float opt_rock_freq = 270;
#endif
bool opt_worktime;
#ifdef USE_AVALON
@@ -1062,7 +1063,7 @@ static char *set_null(const char __maybe_unused *arg)
static struct opt_table opt_config_table[] = {
#ifdef USE_ICARUS
OPT_WITH_ARG("--anu-freq",
- set_float_125_to_500, &opt_show_intval, &opt_anu_freq,
+ set_float_125_to_500, &opt_show_floatval, &opt_anu_freq,
"Set AntminerU1 frequency in MHz, range 125-500"),
#endif
OPT_WITH_ARG("--api-allow",
@@ -1416,6 +1417,11 @@ static struct opt_table opt_config_table[] = {
OPT_WITH_ARG("--retry-pause",
set_null, NULL, &opt_set_null,
opt_hidden),
+#ifdef USE_ICARUS
+ OPT_WITH_ARG("--rock-freq",
+ set_float_125_to_500, &opt_show_floatval, &opt_rock_freq,
+ "Set RockMiner frequency in MHz, range 125-500"),
+#endif
OPT_WITH_ARG("--rotate",
set_rotate, NULL, &opt_set_null,
"Change multipool strategy from failover to regularly rotate at N minutes"),
@@ -3006,13 +3012,18 @@ share_result(json_t *val, json_t *res, json_t *err, const struct work *work,
reason[reasonLen + 2] = ')'; reason[reasonLen + 3] = '\0';
memcpy(disposition + 7, reasontmp, reasonLen);
disposition[6] = ':'; disposition[reasonLen + 7] = '\0';
- } else if (work->stratum && err && json_is_array(err)) {
- json_t *reason_val = json_array_get(err, 1);
- char *reason_str;
-
- if (reason_val && json_is_string(reason_val)) {
- reason_str = (char *)json_string_value(reason_val);
- snprintf(reason, 31, " (%s)", reason_str);
+ } else if (work->stratum && err) {
+ if (json_is_array(err)) {
+ json_t *reason_val = json_array_get(err, 1);
+ char *reason_str;
+
+ if (reason_val && json_is_string(reason_val)) {
+ reason_str = (char *)json_string_value(reason_val);
+ snprintf(reason, 31, " (%s)", reason_str);
+ }
+ } else if (json_is_string(err)) {
+ const char *s = json_string_value(err);
+ snprintf(reason, 31, " (%s)", s);
}
}
@@ -6656,7 +6667,7 @@ retry_stratum:
}
applog(LOG_DEBUG, "FAILED to retrieve work from pool %u %s",
pool->pool_no, pool->rpc_url);
- if (!pinging)
+ if (!pinging && !pool->idle)
applog(LOG_WARNING, "Pool %u slow/down or URL or credentials invalid", pool->pool_no);
}
out:
@@ -8634,10 +8645,12 @@ retry:
if (unlikely(first_pool))
applog(LOG_NOTICE, "Switching to pool %d %s - first alive pool", pool->pool_no, pool->rpc_url);
+ pool_tclear(pool, &pool->idle);
pool_resus(pool);
switch_pools(NULL);
} else {
pool_died(pool);
+ sleep(5);
goto retry;
}
@@ -9004,6 +9017,20 @@ static void adjust_mostdevs(void)
most_devices = total_devices - zombie_devs;
}
+#ifdef USE_ICARUS
+bool icarus_get_device_id(struct cgpu_info *cgpu)
+{
+ static struct _cgpu_devid_counter *devids = NULL;
+ struct _cgpu_devid_counter *d;
+
+ HASH_FIND_STR(devids, cgpu->drv->name, d);
+ if (d)
+ return (d->lastid + 1);
+ else
+ return 0;
+}
+#endif
+
bool add_cgpu(struct cgpu_info *cgpu)
{
static struct _cgpu_devid_counter *devids = NULL;
diff --git a/configure.ac b/configure.ac
index 020ac7e..d42c1b1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2,7 +2,7 @@
##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##
m4_define([v_maj], [4])
m4_define([v_min], [3])
-m4_define([v_mic], [4])
+m4_define([v_mic], [5])
##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##
m4_define([v_ver], [v_maj.v_min.v_mic])
m4_define([lt_rev], m4_eval(v_maj + v_min))
diff --git a/driver-cointerra.c b/driver-cointerra.c
index a11f390..a84b9cf 100644
--- a/driver-cointerra.c
+++ b/driver-cointerra.c
@@ -11,7 +11,6 @@
#include "miner.h"
#include "driver-cointerra.h"
-#include <math.h>
static const char *cointerra_hdr = "ZZ";
@@ -355,7 +354,7 @@ static void cta_parse_recvmatch(struct thr_info *thr, struct cgpu_info *cointerr
/* Debugging, remove me */
swab256(rhash, work->hash);
__bin2hex(outhash, rhash, 8);
- applog(LOG_DEBUG, "submit work %s 0x%04x 0x%08x %d 0x%08x",
+ applog(LOG_WARNING, "submit work %s 0x%04x 0x%08x %d 0x%08x",
outhash, retwork, mcu_tag, timestamp_offset, nonce);
}
@@ -392,9 +391,16 @@ static void cta_parse_recvmatch(struct thr_info *thr, struct cgpu_info *cointerr
mutex_unlock(&info->lock);
} else {
char sendbuf[CTA_MSG_SIZE];
+ uint8_t asic, core, coreno;
+ asic = u8_from_msg(buf, CTA_MCU_ASIC);
+ core = u8_from_msg(buf, CTA_MCU_CORE);
+ coreno = asic * 4 + core;
+ inc_hw_errors(thr);
- applog(LOG_DEBUG, "%s %d: Notify bad match work",
+ applog(LOG_WARNING, "%s %d: Notify bad match work",
cointerra->drv->name, cointerra->device_id);
+ if (coreno < CTA_CORES)
+ info->fmatch_errors[coreno]++;
if (opt_debug) {
uint64_t sdiff = share_diff(work);
unsigned char midstate[32], wdata[12];
@@ -418,12 +424,12 @@ static void cta_parse_recvmatch(struct thr_info *thr, struct cgpu_info *cointerr
/* Tell the device we got a false match */
cta_gen_message(sendbuf, CTA_SEND_FMATCH);
- memcpy(sendbuf + 3, buf, CTA_MSG_SIZE - 3);
+ memcpy(sendbuf + 3, buf + 3, CTA_MSG_SIZE - 3);
cta_send_msg(cointerra, sendbuf);
}
free_work(work);
} else {
- applog(LOG_INFO, "%s %d: Matching work id 0x%X %d not found", cointerra->drv->name,
+ applog(LOG_WARNING, "%s %d: Matching work id 0x%X %d not found", cointerra->drv->name,
cointerra->device_id, retwork, __LINE__);
inc_hw_errors(thr);
@@ -440,10 +446,12 @@ static void cta_parse_wdone(struct thr_info *thr, struct cgpu_info *cointerra,
struct work *work = take_work_by_id(cointerra, retwork);
uint64_t hashes;
- if (likely(work))
+ if (likely(work)) {
free_work(work);
- else {
- applog(LOG_INFO, "%s %d: Done work not found id 0x%X %d",
+ applog(LOG_DEBUG, "%s %d: Done work found id 0x%X %d",
+ cointerra->drv->name, cointerra->device_id, retwork, __LINE__);
+ } else {
+ applog(LOG_WARNING, "%s %d: Done work not found id 0x%X %d",
cointerra->drv->name, cointerra->device_id, retwork, __LINE__);
inc_hw_errors(thr);
}
@@ -519,6 +527,27 @@ static void cta_parse_statset(struct cointerra_info *info, char *buf)
mutex_unlock(&info->lock);
}
+static void cta_parse_irstat(struct cointerra_info *info, char *buf)
+{
+ uint8_t channel = u8_from_msg(buf,CTA_IRSTAT_CHANNEL);
+
+ if (channel >= CTA_CORES)
+ return;
+
+ mutex_lock(&info->lock);
+ info->irstat_vin[channel] = hu16_from_msg(buf,CTA_IRSTAT_VIN);
+ info->irstat_iin[channel] = hu16_from_msg(buf,CTA_IRSTAT_IIN);
+ info->irstat_vout[channel] = hu16_from_msg(buf,CTA_IRSTAT_VOUT);
+ info->irstat_iout[channel] = hu16_from_msg(buf,CTA_IRSTAT_IOUT);
+ info->irstat_temp1[channel] = hu16_from_msg(buf,CTA_IRSTAT_TEMP1);
+ info->irstat_temp2[channel] = hu16_from_msg(buf,CTA_IRSTAT_TEMP2);
+ info->irstat_pout[channel] = hu16_from_msg(buf,CTA_IRSTAT_POUT);
+ info->irstat_pin[channel] = hu16_from_msg(buf,CTA_IRSTAT_PIN);
+ info->irstat_efficiency[channel] = hu16_from_msg(buf,CTA_IRSTAT_EFF);
+ info->irstat_status[channel] = hu16_from_msg(buf,CTA_IRSTAT_STATUS);
+ mutex_unlock(&info->lock);
+}
+
static void cta_parse_info(struct cgpu_info *cointerra, struct cointerra_info *info,
char *buf)
{
@@ -557,8 +586,6 @@ static void cta_parse_rdone(struct cgpu_info *cointerra, struct cointerra_info *
diffbits = buf[CTA_RESET_DIFF];
wdone = hu64_from_msg(buf, CTA_WDONE_NONCES);
- applog(LOG_INFO, "%s %d: Reset done type %u message %u diffbits %"PRIu64" done received",
- cointerra->drv->name, cointerra->device_id, reset_type, diffbits, wdone);
if (wdone) {
applog(LOG_INFO, "%s %d: Reset done type %u message %u diffbits %"PRIu64" done received",
cointerra->drv->name, cointerra->device_id, reset_type, diffbits, wdone);
@@ -623,9 +650,29 @@ static void cta_parse_debug(struct cointerra_info *info, char *buf)
}
}
+static int verify_checksum(char *buf)
+{
+ unsigned char checksum = 0;
+ unsigned char i;
+
+ for (i = 0; i < 63; i++)
+ checksum += buf[i];
+
+ return (checksum == buf[63]);
+}
+
static void cta_parse_msg(struct thr_info *thr, struct cgpu_info *cointerra,
struct cointerra_info *info, char *buf)
{
+ if ((buf[CTA_MSG_TYPE] != CTA_RECV_MATCH)&&
+ (buf[CTA_MSG_TYPE] != CTA_RECV_WDONE)) {
+ if (unlikely(verify_checksum(buf) == 0)) {
+ inc_hw_errors(thr);
+ applog(LOG_WARNING, "%s %d: checksum bad",cointerra->drv->name,cointerra->device_id);
+ return;
+ }
+ }
+
switch (buf[CTA_MSG_TYPE]) {
default:
case CTA_RECV_UNUSED:
@@ -668,6 +715,9 @@ static void cta_parse_msg(struct thr_info *thr, struct cgpu_info *cointerra,
case CTA_RECV_STATDEBUG:
cta_parse_debug(info, buf);
break;
+ case CTA_RECV_IRSTAT:
+ cta_parse_irstat(info, buf);
+ break;
}
}
@@ -953,10 +1003,14 @@ static void cta_send_corehashes(struct cgpu_info *cointerra, struct cointerra_in
int i, offset;
for (i = 0; i < CTA_CORES; i++) {
- k[i] = (double)info->tot_core_hashes[i] / ((double)32 * (double)0x100000000ull);
+ k[i] = (double)info->tot_core_hashes[i];
+#if 0
+ k[i] /= ((double)32 * (double)0x100000000ull);
k[i] = sqrt(k[i]) + 1;
k[i] *= k[i];
- k[i] = k[i] * 32 * ((double)0x100000000ull / (double)1000000000) / corehash_time;
+ k[i] = k[i] * 32 * ((double)0x100000000ull );
+#endif
+ k[i] /= ((double)1000000000 * corehash_time);
core_ghs[i] = k[i];
}
cta_gen_message(buf, CTA_SEND_COREHASHRATE);
@@ -974,6 +1028,7 @@ static int64_t cta_scanwork(struct thr_info *thr)
struct cointerra_info *info = cointerra->device_data;
double corehash_time;
struct timeval now;
+ uint32_t runtime;
int64_t hashes;
applog(LOG_DEBUG, "%s %d: cta_scanwork %d", cointerra->drv->name, cointerra->device_id,__LINE__);
@@ -1038,6 +1093,9 @@ static int64_t cta_scanwork(struct thr_info *thr)
hashes = info->share_hashes;
info->tot_share_hashes += info->share_hashes;
info->tot_calc_hashes += info->hashes;
+ runtime = cgpu_runtime(thr->cgpu);
+ runtime /= 30;
+ info->old_hashes[runtime % 32] = info->tot_calc_hashes;
info->hashes = info->share_hashes = 0;
mutex_unlock(&info->lock);
@@ -1069,11 +1127,15 @@ static void cta_shutdown(struct thr_info *thr)
static void cta_zero_stats(struct cgpu_info *cointerra)
{
struct cointerra_info *info = cointerra->device_data;
+ int i;
info->tot_calc_hashes = 0;
info->tot_reset_hashes = info->tot_hashes;
info->tot_share_hashes = 0;
cta_zero_corehashes(info);
+
+ for (i = 0; i < 16 * 2; i++)
+ info->old_hashes[i] = 0;
}
static int bits_set(char v)
@@ -1095,6 +1157,7 @@ static struct api_data *cta_api_stats(struct cgpu_info *cgpu)
char bitmaphex[36];
uint64_t ghs, val;
char buf[64];
+ uint32_t runtime = cgpu_runtime(cgpu);
/* Info data */
root = api_add_uint16(root, "HW Revision", &info->hwrev, false);
@@ -1166,6 +1229,14 @@ static struct api_data *cta_api_stats(struct cgpu_info *cgpu)
root = api_add_uint64(root, "Calc hashrate", &ghs, true);
ghs = (info->tot_hashes - info->tot_reset_hashes) / dev_runtime;
root = api_add_uint64(root, "Hashrate", &ghs, true);
+ //root = api_add_uint64(root, "cgminer 15m Hashrate", &cgpu->rolling15, true);
+ // get runtime in 30 second steps
+ runtime = runtime / 30;
+ // store the current hashes
+ info->old_hashes[runtime%32] = info->tot_calc_hashes;
+ // calc the 15 minute average hashrate
+ ghs = (info->old_hashes[(runtime+31)%32] - info->old_hashes[(runtime+1)%32])/(15*60);
+ root = api_add_uint64(root, "15m Hashrate", &ghs, true);
ghs = info->tot_share_hashes / dev_runtime;
root = api_add_uint64(root, "Share hashrate", &ghs, true);
root = api_add_uint64(root, "Total calc hashes", &info->tot_calc_hashes, false);
@@ -1209,13 +1280,63 @@ static struct api_data *cta_api_stats(struct cgpu_info *cgpu)
}
root = api_add_uint8(root, "AV", &info->autovoltage, false);
root = api_add_uint8(root, "Power Supply Percent", &info->current_ps_percent, false);
- root = api_add_uint16(root, "Power Used", &info->power_used, false);
- root = api_add_uint16(root, "IOUT", &info->power_used, false);
- root = api_add_uint16(root, "VOUT", &info->power_voltage, false);
- root = api_add_uint16(root, "IIN", &info->ipower_used, false);
- root = api_add_uint16(root, "VIN", &info->ipower_voltage, false);
- root = api_add_uint16(root, "PSTemp1", &info->power_temps[0], false);
- root = api_add_uint16(root, "PSTemp2", &info->power_temps[1], false);
+ //if (info->power_used != 0) {
+ {
+ double value = info->power_used/100.0;
+
+ value *= (info->power_voltage/100.0);
+ root = api_add_double(root, "Power Used", &value, true);
+ }
+ root = api_add_uint16(root, "IOUT", &info->power_used, false);
+ root = api_add_uint16(root, "VOUT", &info->power_voltage, false);
+ root = api_add_uint16(root, "IIN", &info->ipower_used, false);
+ root = api_add_uint16(root, "VIN", &info->ipower_voltage, false);
+ root = api_add_uint16(root, "PSTemp1", &info->power_temps[0], false);
+ root = api_add_uint16(root, "PSTemp2", &info->power_temps[1], false);
+ //}
+
+ for (core = 0; core < CTA_CORES; core++) {
+ char name[20];
+ char str[20];
+ double value;
+
+ sprintf(name,"IRVIN%d",core+1);
+ value = info->irstat_vin[core]/100.0;
+ root = api_add_double(root,name,&value,true);
+ sprintf(name,"IRIIN%d",core+1);
+ value = info->irstat_iin[core]/100.0;
+ root = api_add_double(root,name,&value,true);
+ sprintf(name,"IRVOUT%d",core+1);
+ value = info->irstat_vout[core]/100.0;
+ root = api_add_double(root,name,&value,true);
+ sprintf(name,"IRIOUT%d",core+1);
+ value = info->irstat_iout[core]/100.0;
+ root = api_add_double(root,name,&value,true);
+ sprintf(name,"IRTEMP1_%d",core+1);
+ value = info->irstat_temp1[core]/100.0;
+ root = api_add_double(root,name,&value,true);
+ sprintf(name,"IRTEMP2_%d",core+1);
+ value = info->irstat_temp2[core]/100.0;
+ root = api_add_double(root,name,&value,true);
+ sprintf(name,"IRPOUT%d",core+1);
+ value = info->irstat_pout[core]/100.0;
+ root = api_add_double(root,name,&value,true);
+ sprintf(name,"IRPIN%d",core+1);
+ value = info->irstat_pin[core]/100.0;
+ root = api_add_double(root,name,&value,true);
+ sprintf(name,"IREFFICIENCY%d",core+1);
+ value = info->irstat_efficiency[core]/100.0;
+ root = api_add_double(root,name,&value,true);
+ sprintf(name,"IRSTATUS%d",core+1);
+ //root = api_add_uint16(root,name,&info->irstat_status[core],false);
+ sprintf(str,"0x%04X",info->irstat_status[core]);
+ root = api_add_string(root, name, str, true);
+ }
+
+ for (i = 0; i < CTA_CORES; i++) {
+ sprintf(buf, "CoreFmatch%d", i);
+ root = api_add_uint16(root, buf, &info->fmatch_errors[i], false);
+ }
return root;
}
@@ -1252,5 +1373,5 @@ struct device_drv cointerra_drv = {
.get_statline_before = cta_statline_before,
.thread_shutdown = cta_shutdown,
.zero_stats = cta_zero_stats,
- .max_diff = 32, // Set it below the actual limit to check nonces
+ .max_diff = 64, // Set it below the actual limit to check nonces
};
diff --git a/driver-cointerra.h b/driver-cointerra.h
index e989cf5..6f0649c 100644
--- a/driver-cointerra.h
+++ b/driver-cointerra.h
@@ -61,6 +61,7 @@
#define CTA_RECV_MSG 7
#define CTA_RECV_RDONE 8
#define CTA_RECV_STATDEBUG 10
+#define CTA_RECV_IRSTAT 11
/* Sent message types */
#define CTA_SEND_UNUSED 0
@@ -129,6 +130,18 @@
#define CTA_STAT_PS_TEMP1 51
#define CTA_STAT_PS_TEMP2 53
+#define CTA_IRSTAT_CHANNEL 3
+#define CTA_IRSTAT_VIN 4
+#define CTA_IRSTAT_IIN 6
+#define CTA_IRSTAT_VOUT 8
+#define CTA_IRSTAT_IOUT 10
+#define CTA_IRSTAT_TEMP1 12
+#define CTA_IRSTAT_TEMP2 14
+#define CTA_IRSTAT_POUT 16
+#define CTA_IRSTAT_PIN 18
+#define CTA_IRSTAT_EFF 20
+#define CTA_IRSTAT_STATUS 22
+
#define CTA_CORES 8
#define CTA_PUMPS 2
@@ -181,6 +194,7 @@ struct cointerra_info {
/* Status debug data */
uint16_t underruns;
uint16_t hw_errors[CTA_CORES];
+ uint16_t fmatch_errors[CTA_CORES];
/* Running total from debug messages */
int tot_underruns;
@@ -219,6 +233,19 @@ struct cointerra_info {
pthread_cond_t wake_cond;
pthread_t read_thr;
cgsem_t reset_sem;
+
+ uint16_t irstat_vin[CTA_CORES];
+ uint16_t irstat_iin[CTA_CORES];
+ uint16_t irstat_vout[CTA_CORES];
+ uint16_t irstat_iout[CTA_CORES];
+ uint16_t irstat_temp1[CTA_CORES];
+ uint16_t irstat_temp2[CTA_CORES];
+ uint16_t irstat_pout[CTA_CORES];
+ uint16_t irstat_pin[CTA_CORES];
+ uint16_t irstat_efficiency[CTA_CORES];
+ uint16_t irstat_status[CTA_CORES];
+
+ uint64_t old_hashes[16 * 2];
};
#endif /* COINTERRA_H */
diff --git a/driver-icarus.c b/driver-icarus.c
index 8bae1ca..635531c 100644
--- a/driver-icarus.c
+++ b/driver-icarus.c
@@ -50,6 +50,8 @@
#include "miner.h"
#include "usbutils.h"
+#define ROCKMINER
+#define ROCKMINER_PRINT_DEBUG 0
// The serial I/O speed - Linux uses a define 'B115200' in bits/termios.h
#define ICARUS_IO_SPEED 115200
@@ -57,6 +59,7 @@
// The size of a successful nonce read
#define ANT_READ_SIZE 5
#define ICARUS_READ_SIZE 4
+#define ROCK_READ_SIZE 8
// Ensure the sizes are correct for the Serial read
#if (ICARUS_READ_SIZE != 4)
@@ -272,6 +275,84 @@ struct ICARUS_WORK {
uint8_t work[ICARUS_WORK_SIZE];
};
+#define MAX_DEVICE_NUM 100
+#define MAX_WORK_BUFFER_SIZE 2
+#define MAX_CHIP_NUM 24
+#define NONCE_CORRECTION_TIMES 3
+#define MAX_TRIES 4
+//#define NONCE_TEST
+#define RM_CMD_MASK 0x0F
+#define RM_STATUS_MASK 0xF0
+#define RM_CHIP_MASK 0x3F
+#define RM_PRODUCT_MASK 0xC0
+#define RM_PRODUCT_RBOX 0x00
+#define RM_PRODUCT_T1 0x10
+
+#ifdef NONCE_TEST
+int device_nonce_conunts[MAX_DEVICE_NUM];
+int chip_nonce_conunts[MAX_CHIP_NUM];
+int chip_work_conunts[MAX_CHIP_NUM];
+int device_nonce_corr_ok_1[MAX_DEVICE_NUM];
+int device_nonce_corr_ok[MAX_DEVICE_NUM];
+int device_nonce_corr_fail[MAX_DEVICE_NUM];
+int device_nonce_corr_fail_2[MAX_DEVICE_NUM];
+#endif
+
+typedef enum {
+ NONCE_DATA1_OFFSET= 0,
+ NONCE_DATA2_OFFSET,
+ NONCE_DATA3_OFFSET,
+ NONCE_DATA4_OFFSET,
+ NONCE_TASK_CMD_OFFSET,
+ NONCE_CHIP_NO_OFFSET,
+ NONCE_TASK_NO_OFFSET,
+ NONCE_COMMAND_OFFSET,
+ NONCE_MAX_OFFSET
+} NONCE_OFFSET;
+
+typedef enum {
+ NONCE_DATA_CMD= 0,
+ NONCE_TASK_COMPLETE_CMD,
+ NONCE_GET_TASK_CMD,
+} NONCE_COMMAND;
+
+typedef struct NONCE_DATA
+{
+int chip_no ;
+unsigned int task_no ;
+unsigned char work_state;
+int cmd_value;
+}NONCE_DATA;
+
+
+
+typedef enum {
+ ROCKMINER_RBOX= 0,
+ ROCKMINER_T1,
+ ROCKMINER_MAX
+} ROCKMINER_PRODUCT_T;
+
+typedef struct ROCKMINER_CHIP_INFO
+{
+unsigned char freq;
+int error_cnt;
+time_t last_received_task_complete_time;
+}ROCKMINER_CHIP_INFO;
+
+typedef struct ROCKMINER_DEVICE_INFO
+{
+unsigned char detect_chip_no;
+unsigned char chip_max;
+unsigned char product_id;
+float min_frq;
+float def_frq;
+float max_frq;
+ROCKMINER_CHIP_INFO chip[MAX_CHIP_NUM];
+time_t dev_detect_time;
+}ROCKMINER_DEVICE_INFO;
+
+ROCKMINER_DEVICE_INFO rmdev[MAX_DEVICE_NUM];
+
#define END_CONDITION 0x0000ffff
// Looking for options in --icarus-timing and --icarus-options:
@@ -955,6 +1036,46 @@ static bool set_anu_freq(struct cgpu_info *icarus, struct ICARUS_INFO *info)
return true;
}
+static void rock_init_last_received_task_complete_time(uint32_t dev_id)
+{
+ int i;
+ if(opt_rock_freq<rmdev[dev_id].min_frq||(opt_rock_freq>rmdev[dev_id].max_frq))
+ opt_rock_freq =rmdev[dev_id].def_frq;
+ for (i = 0; i < MAX_CHIP_NUM; ++i)
+ {
+ rmdev[dev_id].chip[i].last_received_task_complete_time = time(NULL);
+ rmdev[dev_id].chip[i].freq = opt_rock_freq/10 - 1;
+ rmdev[dev_id].chip[i].error_cnt= 0;
+ }
+ rmdev[dev_id].dev_detect_time = time(NULL);
+}
+
+struct work *g_work[MAX_DEVICE_NUM][MAX_CHIP_NUM][MAX_WORK_BUFFER_SIZE];
+
+void clear_chip_busy(int device_id)
+{
+ memset(&(g_work[device_id][0]), 0, (sizeof(g_work)/MAX_DEVICE_NUM));
+}
+
+void rock_print_work_data(struct ICARUS_WORK *p_workdata)
+{
+ char *ob_hex = NULL;
+ opt_debug = ROCKMINER_PRINT_DEBUG;
+ if (opt_debug) {
+ ob_hex = bin2hex((void *)(p_workdata), sizeof(*p_workdata));
+ applog(LOG_WARNING, "sent %s", ob_hex);
+ free(ob_hex);
+
+ rev((void *)(&(p_workdata->midstate)), ICARUS_MIDSTATE_SIZE);
+ rev((void *)(&(p_workdata->work)), ICARUS_WORK_SIZE);
+ ob_hex = bin2hex((void *)(p_workdata), sizeof(*p_workdata));
+ applog(LOG_WARNING, "revert sent %s", ob_hex);
+ free(ob_hex);
+ }
+}
+
+bool icarus_get_device_id(struct cgpu_info *cgpu);
+
static struct cgpu_info *icarus_detect_one(struct libusb_device *dev, struct usb_find_devices *found)
{
int this_option_offset = ++option_offset;
@@ -1056,6 +1177,13 @@ cmr2_retry:
if (ret != ICA_NONCE_OK)
continue;
+ if (info->nonce_size == ICARUS_READ_SIZE && usb_buffer_size(icarus) == 4) {
+ applog(LOG_DEBUG, "%s %i: Detected Rockminer, deferring detection",
+ icarus->drv->name, icarus->device_id);
+ usb_buffer_clear(icarus);
+ break;
+
+ }
if (info->nonce_size == ICARUS_READ_SIZE && usb_buffer_size(icarus) == 1) {
usb_buffer_clear(icarus);
icarus->usbdev->ident = info->ident = IDENT_ANU;
@@ -1218,8 +1346,260 @@ shin:
return NULL;
}
+static int64_t rock_scanwork(struct thr_info *thr);
+
+static bool rock_prepare(struct thr_info *thr)
+{
+ struct cgpu_info *icarus = thr->cgpu;
+
+ icarus->drv->name = "LIN";
+ return true;
+}
+
+static void rock_statline_before(char *buf, size_t bufsiz, struct cgpu_info *cgpu)
+{
+ if (cgpu->temp)
+ tailsprintf(buf, bufsiz, "%3.0fMHz %3.0fC", opt_rock_freq, cgpu->temp);
+ else
+ tailsprintf(buf, bufsiz, "%.0fMHz", opt_rock_freq);
+}
+
+static struct cgpu_info *rock_detect_one(struct libusb_device *dev, struct usb_find_devices *found)
+{
+ struct ICARUS_INFO *info;
+ struct timeval tv_start, tv_finish;
+ int opt_debug = ROCKMINER_PRINT_DEBUG;
+ char *ob_hex = NULL;
+
+ // Block 171874 nonce = (0xa2870100) = 0x000187a2
+ // N.B. golden_ob MUST take less time to calculate
+ // than the timeout set in icarus_open()
+ // This one takes ~0.53ms on Rev3 Icarus
+ const char golden_ob[] =
+ "4679ba4ec99876bf4bfe086082b40025"
+ "4df6c356451471139a3afa71e48f544a"
+ "00000000000000000000000000000000"
+ "aa1ff05587320b1a1426674f2fa722ce";
+
+ const char golden_nonce[] = "000187a2";
+ const uint32_t golden_nonce_val = 0x000187a2;
+ unsigned char nonce_bin[ROCK_READ_SIZE];
+ struct ICARUS_WORK workdata;
+ char *nonce_hex;
+ struct cgpu_info *icarus;
+ int ret, err, amount, tries;
+ bool ok;
+ int correction_times = 0;
+#if (NONCE_CORRECTION_TIMES == 9)
+ int32_t correction_value[] = {0, 1, -1, 2, -2, 3, -3, 4, -4};
+#endif
+#if (NONCE_CORRECTION_TIMES == 3)
+ int32_t correction_value[] = {0, 1, -1};
+#endif
+ NONCE_DATA nonce_data;
+
+ uint32_t nonce;
+ //int cmd_value = 0;
+ int dev_id;
+
+ if ((sizeof(workdata) << 1) != (sizeof(golden_ob) - 1))
+ quithere(1, "Data and golden_ob sizes don't match");
+
+ icarus = usb_alloc_cgpu(&icarus_drv, 1);
+
+ if (!usb_init(icarus, dev, found))
+ goto shin;
+
+#ifdef WIN32
+ dev_id = icarus_get_device_id(icarus);
+#else
+ dev_id = icarus->device_id;
+#endif
+
+ hex2bin((void *)(&workdata), golden_ob, sizeof(workdata));
+ rev((void *)(&(workdata.midstate)), ICARUS_MIDSTATE_SIZE);
+ rev((void *)(&(workdata.work)), ICARUS_WORK_SIZE);
+ opt_debug = ROCKMINER_PRINT_DEBUG;
+ if (opt_debug) {
+ ob_hex = bin2hex((void *)(&workdata), sizeof(workdata));
+ applog(LOG_WARNING, "%s%d: send_gold_nonce %s",
+ icarus->drv->name, icarus->device_id, ob_hex);
+ free(ob_hex);
+ }
+
+ info = (struct ICARUS_INFO *)calloc(1, sizeof(struct ICARUS_INFO));
+ if (unlikely(!info))
+ quit(1, "Failed to malloc ICARUS_INFO");
+ (void)memset(info, 0, sizeof(struct ICARUS_INFO));
+ icarus->device_data = (void *)info;
+ icarus->usbdev->ident = info->ident = IDENT_LIN;
+ info->nonce_size = ROCK_READ_SIZE;
+ info->fail_time = 10;
+ info->nonce_mask = 0xffffffff;
+ update_usb_stats(icarus);
+
+ tries = MAX_TRIES;
+ ok = false;
+ while (!ok && tries-- > 0) {
+#if ROCKMINER_PRINT_DEBUG
+ applog(LOG_WARNING, "tries: %d", tries);
+#endif
+ workdata.unused[ICARUS_UNUSED_SIZE - 3] = opt_rock_freq/10 - 1;
+ workdata.unused[ICARUS_UNUSED_SIZE - 2] = (MAX_TRIES-1-tries);
+ rmdev[dev_id].detect_chip_no ++;
+ if(rmdev[dev_id].detect_chip_no >=MAX_TRIES )
+ rmdev[dev_id].detect_chip_no = 0;
+ //g_detect_chip_no[dev_id] = (g_detect_chip_no[dev_id] + 1) & MAX_CHIP_NUM;
+
+ err = usb_write_ii(icarus, info->intinfo,
+ (char *)(&workdata), sizeof(workdata), &amount, C_SENDWORK);
+ rock_print_work_data(&workdata);
+ if (err != LIBUSB_SUCCESS || amount != sizeof(workdata))
+ continue;
+
+ memset(nonce_bin, 0, sizeof(nonce_bin));
+ ret = icarus_get_nonce(icarus, nonce_bin, &tv_start, &tv_finish, NULL, 100);
+#if ROCKMINER_PRINT_DEBUG
+ applog(LOG_WARNING, "Rockminer nonce_bin: %02X, %02X, %02X, %02X, %02X, %02X, %02X, %02X", nonce_bin[0], nonce_bin[1], nonce_bin[2], nonce_bin[3], nonce_bin[4], nonce_bin[5], nonce_bin[6], nonce_bin[7]);
+#endif
+ if (ret != ICA_NONCE_OK)
+ {
+#if ROCKMINER_PRINT_DEBUG
+ applog(LOG_WARNING, "detect_one get_gold_nonce error, tries = %d.\r\n", tries);
+#endif
+ continue;
+ }
+
+ //device max chip
+ if((nonce_bin[NONCE_CHIP_NO_OFFSET]&RM_PRODUCT_MASK)==RM_PRODUCT_T1)
+ {
+ rmdev[dev_id].product_id = ROCKMINER_T1;
+ rmdev[dev_id].chip_max = 24;
+ rmdev[dev_id].min_frq = 200;
+ rmdev[dev_id].def_frq = 280;
+ rmdev[dev_id].max_frq = 320;
+ }
+ else
+ {
+ rmdev[dev_id].product_id= ROCKMINER_RBOX;
+ rmdev[dev_id].chip_max = 4;
+ rmdev[dev_id].min_frq = 200;
+ rmdev[dev_id].def_frq = 270;
+ rmdev[dev_id].max_frq = 290;
+ }
+ nonce_data.chip_no = nonce_bin[NONCE_CHIP_NO_OFFSET]&RM_CHIP_MASK;
+ if (nonce_data.chip_no >= rmdev[dev_id].chip_max)
+ {
+ nonce_data.chip_no = 0;
+ }
+
+ nonce_data.cmd_value = nonce_bin[NONCE_TASK_CMD_OFFSET]&RM_CMD_MASK;
+ if (nonce_data.cmd_value == NONCE_TASK_COMPLETE_CMD)
+ {
+#if ROCKMINER_PRINT_DEBUG
+ applog(LOG_WARNING, "complete g_detect_chip_no: %d", rmdev[dev_id].detect_chip_no);
+#endif
+ workdata.unused[ICARUS_UNUSED_SIZE - 3] = opt_rock_freq/10 - 1;
+ workdata.unused[ICARUS_UNUSED_SIZE - 2] = rmdev[dev_id].detect_chip_no;
+ rmdev[dev_id].detect_chip_no ++;
+ if(rmdev[dev_id].detect_chip_no>=MAX_TRIES)
+ rmdev[dev_id].detect_chip_no = 0;
+
+ err = usb_write_ii(icarus, info->intinfo,
+ (char *)(&workdata), sizeof(workdata), &amount, C_SENDWORK);
+ rock_print_work_data(&workdata);
+ if (err != LIBUSB_SUCCESS || amount != sizeof(workdata))
+ continue;
+#if ROCKMINER_PRINT_DEBUG
+ applog(LOG_WARNING, "send_gold_nonce usb_write_ii");
+#endif
+ continue;
+ }
+
+ memcpy((char *)&nonce, nonce_bin, ICARUS_READ_SIZE);
+ nonce = htobe32(nonce);
+#if ROCKMINER_PRINT_DEBUG
+ applog(LOG_WARNING, "Rockminer nonce: %08X", nonce);
+#endif
+ correction_times = 0;
+ while(correction_times<NONCE_CORRECTION_TIMES)
+ {
+ nonce_hex = bin2hex(nonce_bin, 4);
+ if (golden_nonce_val == nonce + correction_value[correction_times]) {
+ clear_chip_busy(dev_id);
+ rock_init_last_received_task_complete_time(dev_id);
+
+ ok = true;
+ break;
+ } else {
+#if ROCKMINER_PRINT_DEBUG
+ applog(LOG_WARNING, "detect_one gold_nonce compare error times = %d\r\n", correction_times);
+#endif
+ if (tries < 0 && info->ident != IDENT_CMR2) {
+ applog(LOG_WARNING,
+ "Icarus Detect: "
+ "Test failed at %s: get %s, should: %s",
+ icarus->device_path, nonce_hex, golden_nonce);
+ }
+
+ if(nonce == 0)
+ {
+ break;
+ }
+ }
+ free(nonce_hex);
+ correction_times++;
+ }
+
+#if ROCKMINER_PRINT_DEBUG
+ if(correction_times > 0 )
+ {
+ if (correction_times < NONCE_CORRECTION_TIMES)
+ applog(LOG_WARNING, "Rockminer correction the Golden nonce success %s%d[%d]=%d",icarus->drv->name, icarus->device_id,chip_no,correction_times);
+ else
+ applog(LOG_WARNING, "Rockminer correction the Golden nonce fail %s%d[%d]=%d",icarus->drv->name, icarus->device_id,chip_no,correction_times);
+ }
+#endif
+
+ }
+
+ if (!ok)
+ goto unshin;
+ applog(LOG_DEBUG, "Icarus Detect: Test succeeded at %s: got %s",
+ icarus->device_path, golden_nonce);
+
+ /* We have a real Rockminer! */
+ if (!add_cgpu(icarus))
+ goto unshin;
+
+ icarus->drv->scanwork = rock_scanwork;
+ icarus->drv->dname = "Rockminer";
+ icarus->drv->thread_prepare = &rock_prepare;
+ icarus->drv->get_statline_before = &rock_statline_before;
+
+ applog(LOG_INFO, "%s%d: Found at %s",
+ icarus->drv->name, icarus->device_id, icarus->device_path);
+
+ timersub(&tv_finish, &tv_start, &(info->golden_tv));
+
+ return icarus;
+
+unshin:
+
+ usb_uninit(icarus);
+ free(info);
+ icarus->device_data = NULL;
+
+shin:
+
+ icarus = usb_free_cgpu(icarus);
+
+ return NULL;
+}
+
static void icarus_detect(bool __maybe_unused hotplug)
{
+ usb_detect(&icarus_drv, rock_detect_one);
usb_detect(&icarus_drv, icarus_detect_one);
}
@@ -1269,6 +1649,109 @@ static void cmr2_commands(struct cgpu_info *icarus)
}
}
+void rock_send_task(unsigned char chip_no, unsigned int current_task_id, struct thr_info *thr)
+{
+ struct cgpu_info *icarus = thr->cgpu;
+ struct ICARUS_INFO *info = (struct ICARUS_INFO *)(icarus->device_data);
+ int err, amount;
+ struct ICARUS_WORK workdata;
+ char *ob_hex;
+ struct work *work = NULL;
+ int dev_id = icarus->device_id;
+
+#if ROCKMINER_PRINT_DEBUG
+ applog(LOG_WARNING, "thr_info id:%d, device_thread:%d, icarus cgminer_id: %d, device_id: %d.", thr->id, thr->device_thread, icarus->cgminer_id, icarus->device_id);
+ applog(LOG_WARNING, "::::::::::::::g_work[%d][%d][%d] = 0x%x", dev_id, chip_no, current_task_id, (int)g_work[dev_id][chip_no][current_task_id]);
+#endif
+ if (g_work[dev_id][chip_no][current_task_id] == NULL)
+ {
+ work = get_work(thr, thr->id);
+ if (work == NULL)
+ {
+ return;
+ }
+ g_work[dev_id][chip_no][current_task_id] = work;
+ }
+ else
+ {
+ work = g_work[dev_id][chip_no][current_task_id];
+#if ROCKMINER_PRINT_DEBUG
+ applog(LOG_WARNING, "::resend work");
+#endif
+ }
+
+#if ROCKMINER_PRINT_DEBUG
+ //if(chip_no == 7)
+ applog(LOG_WARNING, "::::::::::::::g_work[%d][%d][%d] = 0x%x", dev_id, chip_no, current_task_id, (int)g_work[dev_id][chip_no][current_task_id]);
+#endif
+
+ memset((void *)(&workdata), 0, sizeof(workdata));
+ memcpy(&(workdata.midstate), work->midstate, ICARUS_MIDSTATE_SIZE);
+ memcpy(&(workdata.work), work->data + ICARUS_WORK_DATA_OFFSET, ICARUS_WORK_SIZE);
+ workdata.unused[ICARUS_UNUSED_SIZE - 4] = 0xaa;
+ if((rmdev[dev_id].chip[chip_no].freq>(rmdev[dev_id].max_frq/10-1))||(rmdev[dev_id].chip[chip_no].freq<(rmdev[dev_id].min_frq/10-1)))
+ {
+ rock_init_last_received_task_complete_time(dev_id);
+ }
+ workdata.unused[ICARUS_UNUSED_SIZE - 3] = rmdev[dev_id].chip[chip_no].freq; //icarus->freq/10 - 1; ;
+ workdata.unused[ICARUS_UNUSED_SIZE - 2] = chip_no ;
+ workdata.unused[ICARUS_UNUSED_SIZE - 1] = 0x55;
+
+ opt_debug = ROCKMINER_PRINT_DEBUG;
+ if (opt_debug) {
+ ob_hex = bin2hex((void *)(work->data), 128);
+ applog(LOG_WARNING, "%s%d: work->data %s",
+ icarus->drv->name, icarus->device_id, ob_hex);
+ free(ob_hex);
+ }
+
+#ifndef ROCKMINER
+ rev((void *)(&(workdata.midstate)), ICARUS_MIDSTATE_SIZE);
+ rev((void *)(&(workdata.work)), ICARUS_WORK_SIZE);
+
+ if (info->speed_next_work || info->flash_next_work)
+ //cmr2_commands(icarus);
+#endif
+
+ // We only want results for the work we are about to send
+ usb_buffer_clear(icarus);
+
+
+ err = usb_write_ii(icarus, info->intinfo, (char *)(&workdata), sizeof(workdata), &amount, C_SENDWORK);
+
+ if (err < 0 || amount != sizeof(workdata)) {
+ applog(LOG_ERR, "%s%i: Comms error (werr=%d amt=%d)",
+ icarus->drv->name, icarus->device_id, err, amount);
+ dev_error(icarus, REASON_DEV_COMMS_ERROR);
+ icarus_initialise(icarus, info->baud);
+
+ if(g_work[dev_id][chip_no][current_task_id])
+ {
+ free_work(g_work[dev_id][chip_no][current_task_id]);
+ g_work[dev_id][chip_no][current_task_id] = NULL;
+ }
+
+ return;
+ }
+
+ opt_debug = ROCKMINER_PRINT_DEBUG;
+ if (opt_debug) {
+ ob_hex = bin2hex((void *)(&workdata), sizeof(workdata));
+ applog(LOG_WARNING, "%s%d: sent %s",
+ icarus->drv->name, icarus->device_id, ob_hex);
+ free(ob_hex);
+
+ rev((void *)(&(workdata.midstate)), ICARUS_MIDSTATE_SIZE);
+ rev((void *)(&(workdata.work)), ICARUS_WORK_SIZE);
+ ob_hex = bin2hex((void *)(&workdata), sizeof(workdata));
+ applog(LOG_WARNING, "%s%d: revert sent %s",
+ icarus->drv->name, icarus->device_id, ob_hex);
+ free(ob_hex);
+ }
+
+ return;
+}
+
static int64_t icarus_scanwork(struct thr_info *thr)
{
struct cgpu_info *icarus = thr->cgpu;
@@ -1523,6 +2006,293 @@ out:
return hash_count;
}
+static int64_t rock_scanwork(struct thr_info *thr)
+{
+ struct cgpu_info *icarus = thr->cgpu;
+ struct ICARUS_INFO *info = (struct ICARUS_INFO *)(icarus->device_data);
+ int ret;
+ unsigned char nonce_bin[ICARUS_BUF_SIZE];
+ uint32_t nonce;
+ int64_t hash_count = 0;
+ struct timeval tv_start, tv_finish, elapsed;
+ struct work *work = NULL;
+
+ int64_t estimate_hashes;
+ int correction_times = 0;
+#if (NONCE_CORRECTION_TIMES == 9)
+ int32_t correction_value[] = {0, 1, -1, 2, -2, 3, -3, 4, -4};
+#endif
+#if (NONCE_CORRECTION_TIMES == 3)
+ int32_t correction_value[] = {0, 1, -1};
+#endif
+ NONCE_DATA nonce_data;
+
+ int chip_no = 0;
+ time_t recv_time = 0;
+ //unsigned int task_no = 0;
+ // int cmd_value = 0;
+ int dev_id = icarus->device_id;
+ //unsigned char work_state;
+
+ if (unlikely(share_work_tdiff(icarus) > info->fail_time)) {
+ if (info->failing) {
+ if (share_work_tdiff(icarus) > info->fail_time + 60) {
+ applog(LOG_ERR, "%s %d: Device failed to respond to restart",
+ icarus->drv->name, icarus->device_id);
+ usb_nodev(icarus);
+ return -1;
+ }
+ } else {
+ applog(LOG_WARNING, "%s %d: No valid hashes for over %d secs, attempting to reset",
+ icarus->drv->name, icarus->device_id, info->fail_time);
+ usb_reset(icarus);
+ info->failing = true;
+ }
+ }
+
+ // Device is gone
+ if (icarus->usbinfo.nodev)
+ return -1;
+
+ elapsed.tv_sec = elapsed.tv_usec = 0;
+
+
+ for (chip_no = 0; chip_no < rmdev[dev_id].chip_max; chip_no++)
+ {
+ recv_time = time(NULL);
+ if (recv_time > rmdev[dev_id].chip[chip_no].last_received_task_complete_time + 1)
+ {
+#if NONCE_TEST
+ applog(LOG_WARNING, ":::chip_no error = %d nonce timeout", chip_no);
+#endif
+ rmdev[dev_id].chip[chip_no].last_received_task_complete_time = recv_time;
+ rock_send_task(chip_no, 0,thr);
+ break;
+ }
+ }
+
+ /* Icarus will return 4 bytes (ICARUS_READ_SIZE) nonces or nothing */
+ memset(nonce_bin, 0, sizeof(nonce_bin));
+ ret = icarus_get_nonce(icarus, nonce_bin, &tv_start, &tv_finish, thr, 3000);//info->read_time);
+#if ROCKMINER_PRINT_DEBUG
+ applog(LOG_WARNING, "Rockminer nonce_bin: ret = %d. %02X, %02X, %02X, %02X, %02X, %02X, %02X, %02X", ret, nonce_bin[0], nonce_bin[1], nonce_bin[2], nonce_bin[3], nonce_bin[4], nonce_bin[5], nonce_bin[6], nonce_bin[7]);
+#endif
+ if((nonce_bin[NONCE_CHIP_NO_OFFSET]&RM_PRODUCT_MASK)==RM_PRODUCT_T1)
+ {
+ rmdev[dev_id].product_id = ROCKMINER_T1;
+ rmdev[dev_id].chip_max = 24;
+ rmdev[dev_id].min_frq = 200;
+ rmdev[dev_id].def_frq = 280;
+ rmdev[dev_id].max_frq = 320;
+ }
+ else
+ {
+ rmdev[dev_id].product_id= ROCKMINER_RBOX;
+ rmdev[dev_id].chip_max = 4;
+ rmdev[dev_id].min_frq = 200;
+ rmdev[dev_id].def_frq = 270;
+ rmdev[dev_id].max_frq = 290;
+ }
+ nonce_data.chip_no = nonce_bin[NONCE_CHIP_NO_OFFSET]&RM_CHIP_MASK;
+ if(nonce_data.chip_no>=rmdev[dev_id].chip_max)
+ nonce_data.chip_no=0;
+ nonce_data.task_no = nonce_bin[NONCE_TASK_NO_OFFSET]>=2?0:nonce_bin[NONCE_TASK_NO_OFFSET];
+ nonce_data.cmd_value = nonce_bin[NONCE_TASK_CMD_OFFSET]&RM_CMD_MASK;
+ nonce_data.work_state = nonce_bin[NONCE_TASK_CMD_OFFSET]&RM_STATUS_MASK;
+#if ROCKMINER_PRINT_DEBUG
+ if(nonce_data.work_state == 2)
+ applog(LOG_WARNING, "Temperature of Device is too hign to work!");
+#endif
+
+ icarus->temp = (double)nonce_bin[NONCE_COMMAND_OFFSET];
+ if (icarus->temp == 128)
+ icarus->temp = 0;
+
+ if (nonce_data.cmd_value == NONCE_TASK_COMPLETE_CMD)
+ {
+ rmdev[dev_id].chip[nonce_data.chip_no].last_received_task_complete_time = time(NULL);
+
+ if (g_work[dev_id][nonce_data.chip_no][nonce_data.task_no])
+ {
+ free_work(g_work[dev_id][nonce_data.chip_no][nonce_data.task_no]);
+ g_work[dev_id][nonce_data.chip_no][nonce_data.task_no] = NULL;
+ }
+#ifdef NONCE_TEST// ROCKMINER_PRINT_DEBUG
+ chip_work_conunts[nonce_data.chip_no] ++;
+#endif
+
+ goto out;
+ }
+
+ if (nonce_data.cmd_value == NONCE_GET_TASK_CMD)
+ {
+ rock_send_task(nonce_data.chip_no, nonce_data.task_no, thr);
+ goto out;
+ }
+
+ if (ret == ICA_NONCE_TIMEOUT)
+ {
+#if ROCKMINER_PRINT_DEBUG
+ applog(LOG_WARNING, "chip_no = %d nonce timeout, ret = %d", nonce_data.chip_no, ret);
+#endif
+ rock_send_task(nonce_data.chip_no, nonce_data.task_no, thr);
+ }
+
+#if ROCKMINER_PRINT_DEBUG
+ applog(LOG_WARNING, "Rockminer chip_no: %d", nonce_data.chip_no);
+#endif
+
+ work = g_work[dev_id][nonce_data.chip_no][nonce_data.task_no];
+ if (work == NULL)
+ {
+ goto out;
+ }
+
+ if (ret == ICA_NONCE_ERROR)
+ goto out;
+
+ // aborted before becoming idle, get new work
+ if (ret == ICA_NONCE_TIMEOUT || ret == ICA_NONCE_RESTART) {
+ timersub(&tv_finish, &tv_start, &elapsed);
+
+ // ONLY up to just when it aborted
+ // We didn't read a reply so we don't subtract ICARUS_READ_TIME
+ estimate_hashes = ((double)(elapsed.tv_sec)
+ + ((double)(elapsed.tv_usec))/((double)1000000)) / info->Hs;
+
+ // If some Serial-USB delay allowed the full nonce range to
+ // complete it can't have done more than a full nonce
+ if (unlikely(estimate_hashes > 0xffffffff))
+ estimate_hashes = 0xffffffff;
+
+ applog(LOG_DEBUG, "%s%d: no nonce = 0x%08lX hashes (%ld.%06lds)",
+ icarus->drv->name, icarus->device_id,
+ (long unsigned int)estimate_hashes,
+ (long)elapsed.tv_sec, (long)elapsed.tv_usec);
+
+ goto out;
+ }
+
+ memcpy((char *)&nonce, nonce_bin, ICARUS_READ_SIZE);
+ nonce = htobe32(nonce);
+#if ROCKMINER_PRINT_DEBUG
+ applog(LOG_WARNING, "Rockminer nonce %s%d[%d/24]-%d: %08X",icarus->drv->name, icarus->device_id,nonce_data.chip_no,nonce_data.task_no, nonce);
+#endif
+
+#ifdef NONCE_TEST// ROCKMINER_PRINT_DEBUG
+ device_nonce_conunts[dev_id] ++;
+ chip_nonce_conunts[nonce_data.chip_no] ++;
+#endif
+
+ recv_time = time(NULL);
+ if((recv_time-rmdev[dev_id].dev_detect_time )>=60)//device_chip_max[device_id]
+ {
+ unsigned char i;
+ rmdev[dev_id].dev_detect_time = recv_time;
+#ifdef NONCE_TEST// ROCKMINER_PRINT_DEBUG
+ applog(LOG_WARNING, "AMU%d Freq: %d0MHz/ %d0MHz/ %d0MHz/ %d0MHz ",dev_id,rmdev[dev_id].chip[0].freq+1,rmdev[dev_id].chip[1].freq+1,rmdev[dev_id].chip[2].freq+1,rmdev[dev_id].chip[3].freq+1);
+#endif
+ for (i = 0; i < rmdev[dev_id].chip_max; i ++)
+ {
+#ifdef NONCE_TEST// ROCKMINER_PRINT_DEBUG
+ applog(LOG_WARNING, "AMU%d Chip[%d] nonce=%d/%d/%d,freq:%d0MHz, ",dev_id,i,rmdev[dev_id].chip[i].error_cnt,chip_nonce_conunts[i],chip_work_conunts[i],rmdev[dev_id].chip[i].freq+1);
+ chip_nonce_conunts[i] = 0;
+ chip_work_conunts[i] = 0;
+#endif
+ if(rmdev[dev_id].chip[i].error_cnt>=12)
+ {
+ if(rmdev[dev_id].chip[i].freq>rmdev[dev_id].min_frq) //200Mhz
+ {
+ rmdev[dev_id].chip[i].freq --;
+#ifdef NONCE_TEST
+ applog(LOG_WARNING, "AMU%d Chip[%d]=%d SUB FREQ TO %d0MHz,DEF(%fMHz) ",dev_id,i,rmdev[dev_id].chip[i].error_cnt,rmdev[dev_id].chip[i].freq+1,opt_rock_freq);
+#endif
+ }
+ }
+ else if(rmdev[dev_id].chip[i].error_cnt<=1)
+ {
+ if(rmdev[dev_id].chip[i].freq<(rmdev[dev_id].def_frq/10-1))
+ {
+ rmdev[dev_id].chip[i].freq ++;
+#ifdef NONCE_TEST
+ applog(LOG_WARNING, "AMU%d Chip[%d]=%d ADD FREQ TO %d0MHz,DEF(%fMHz) ",dev_id,i,rmdev[dev_id].chip[i].error_cnt,rmdev[dev_id].chip[i].freq+1,opt_rock_freq);
+#endif
+ }
+ }
+ rmdev[dev_id].chip[i].error_cnt = 0;
+ }
+#ifdef NONCE_TEST// ROCKMINER_PRINT_DEBUG
+ device_nonce_corr_ok[dev_id] = 0;
+ device_nonce_corr_fail[dev_id] = 0;
+ device_nonce_corr_fail_2[dev_id] = 0;
+ device_nonce_conunts[dev_id] = 0;
+#endif
+
+ }
+
+ correction_times = 0;
+ while(correction_times<NONCE_CORRECTION_TIMES)
+ {
+ if (submit_nonce(thr, work, nonce + correction_value[correction_times]))
+ {
+ hash_count++;
+ info->failing = false;
+#if ROCKMINER_PRINT_DEBUG
+ applog(LOG_WARNING, "Rockminer nonce :::OK:::\r\n");
+#endif
+ break;
+ }
+ else
+ {
+#if ROCKMINER_PRINT_DEBUG
+ applog(LOG_WARNING, "Rockminer nonce error times = %d\r\n", correction_times);
+#endif
+ if(nonce == 0)
+ {
+ break;
+ }
+ }
+ correction_times++;
+ }
+
+ if(correction_times > 0 )
+ {
+
+ /* FIXME: Where is this i supposed to come from? Comment out instead */
+ //rmdev[dev_id].chip[i].error_cnt ++;
+ if (correction_times < NONCE_CORRECTION_TIMES)
+ {
+
+#ifdef NONCE_TEST// ROCKMINER_PRINT_DEBUG
+ device_nonce_corr_ok[dev_id] ++;
+ //applog(LOG_WARNING, "Rockminer correction the nonce success %s%d[%d]=%d",icarus->drv->name, icarus->dev_id,chip_no,correction_times);
+#endif
+ }
+ else
+ {
+#ifdef NONCE_TEST// ROCKMINER_PRINT_DEBUG
+ device_nonce_corr_fail[dev_id] ++;
+#endif
+ //applog(LOG_WARNING, "Rockminer correction the nonce fail ---------%s%d[%d]=%d",icarus->drv->name, icarus->dev_id,chip_no,correction_times);
+ }
+
+ }
+
+ hash_count = (hash_count * info->nonce_mask);
+
+ if (opt_debug || info->do_icarus_timing)
+ timersub(&tv_finish, &tv_start, &elapsed);
+
+ applog(LOG_DEBUG, "%s%d: nonce = 0x%08x = 0x%08lX hashes (%ld.%06lds)",
+ icarus->drv->name, icarus->device_id,
+ nonce, (long unsigned int)hash_count,
+ (long)elapsed.tv_sec, (long)elapsed.tv_usec);
+
+out:
+
+ return hash_count;
+}
+
static struct api_data *icarus_api_stats(struct cgpu_info *cgpu)
{
struct api_data *root = NULL;
diff --git a/driver-minion.c b/driver-minion.c
index 0070a1f..960940a 100644
--- a/driver-minion.c
+++ b/driver-minion.c
@@ -24,6 +24,7 @@ static void minion_detect(__maybe_unused bool hotplug)
#include <linux/spi/spidev.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
+#include <sys/mman.h>
#include <fcntl.h>
#include <poll.h>
@@ -36,14 +37,87 @@ static void minion_detect(__maybe_unused bool hotplug)
// The code is always in - this just decides if it does it
static bool minreread = true;
+/*
+ * Use pins for board selection
+ * If disabled, it will test chips just as 'pin 0'
+ * but never do any gpio - the equivalent of the previous 'no pins' code
+ */
+static bool usepins = true;
+
+#define MINION_PAGE_SIZE 4096
+
+#define BCM2835_BASE 0x20000000
+#define BCM2835_GPIO_BASE (BCM2835_BASE + 0x200000)
+
+#define BCM2835_GPIO_SET0 0x001c // GPIO Pin Output Set 0
+#define BCM2835_GPIO_CLR0 0x0028 // GPIO Pin Output Clear 0
+
+#define BCM2835_GPIO_FSEL0 0x0000
+
+#define BCM2835_GPIO_FSEL_INPUT 0b000
+#define BCM2835_GPIO_FSEL_OUTPUT 0b001
+#define BCM2835_GPIO_FSEL_MASK 0b111
+
+
+#define BCM2835_PIN_HIGH 0x1
+#define BCM2835_PIN_LOW 0x0
+
+static const char *minion_memory = "/dev/mem";
+static int minion_memory_addr = BCM2835_GPIO_BASE;
+
#define MINION_SPI_BUS 0
#define MINION_SPI_CHIP 0
//#define MINION_SPI_SPEED 2000000
-#define MINION_SPI_SPEED 1000000
+#define MINION_SPI_SPEED 8000000
#define MINION_SPI_BUFSIZ 1024
-#define MINION_CHIPS 32
+static struct minion_select_pins {
+ int pin;
+ int wpi;
+ char *name;
+ int bcm; // this is what we use
+} minionPins[] = {
+ { 24, 10, "CE0", 8, },
+ { 26, 11, "CE1", 7, },
+ { 16, 4, "GPIO4", 23, },
+ { 22, 6, "GPIO6", 25, },
+ { 12, 1, "GPIO1", 18, },
+ { 18, 5, "GPIO5", 24, },
+ { 11, 0, "GPIO0", 17, },
+ { 13, 2, "GPIO2", 27, },
+ { 15, 3, "GPIO3", 22, },
+ { 7, 7, "GPIO7", 4, }
+
+/* The rest on the RPi
+ { 3, 8, "SDA", 2, }
+ { 5, 9, "SCL", 3, }
+ { 19, 12, "MOSI", 10, }
+ { 21, 13, "MISO", 9, }
+ { 23, 14, "SCLK", 11, }
+ { 8, 15, "TxD", 14, }
+ { 10, 16, "RxD", 15, }
+*/
+};
+
+/*
+ * uS delays for GPIO pin access
+ */
+#define MINION_PIN_BEFORE cgsleep_us(33)
+#define MINION_PIN_SLEEP cgsleep_us(133)
+#define MINION_PIN_AFTER
+
+#define MINION_PIN_COUNT (sizeof(minionPins)/ \
+ sizeof(struct minion_select_pins))
+
+#define CHIP_PIN(_chip) (minioninfo->chip_pin[_chip])
+
+#define MINION_MIN_CHIP 0
+#define MINION_MAX_CHIP 10
+
+#define MINION_CHIP_PER_PIN (1 + MINION_MAX_CHIP - MINION_MIN_CHIP)
+
+#define MINION_CHIPS (MINION_PIN_COUNT * MINION_CHIP_PER_PIN)
#define MINION_CORES 99
#define FAKE_CORE MINION_CORES
@@ -239,7 +313,7 @@ static const char *min_temp_invalid = "?";
} while (0)
struct minion_header {
- uint8_t chip;
+ uint8_t chipid;
uint8_t reg;
uint8_t siz[2];
uint8_t data[4]; // placeholder
@@ -336,7 +410,7 @@ struct minion_status {
#define FIFO_CMD(_fifo, _off) ((_fifo)[(_off) + 1])
#define RES_GOLD(_res) ((((_res)->status[3]) & 0x80) == 0)
-#define RES_CHIP(_res) (((_res)->status[3]) & 0x1f)
+#define RES_CHIPID(_res) (((_res)->status[3]) & 0x1f)
#define RES_CORE(_res) ((_res)->status[2])
#define RES_TASK(_res) ((int)((_res)->status[1]) * 0x100 + (int)((_res)->status[0]))
#define RES_NONCE(_res) u8tou32((_res)->nonce, 0)
@@ -607,17 +681,22 @@ struct minion_info {
cgsem_t nonce_ready;
cgsem_t scan_work;
+ volatile unsigned *gpio;
+
int spifd;
char gpiointvalue[64];
int gpiointfd;
// TODO: need to track disabled chips - done?
int chips;
- bool chip[MINION_CHIPS];
+ bool has_chip[MINION_CHIPS];
int init_freq[MINION_CHIPS];
int init_temp[MINION_CHIPS];
uint8_t init_cores[MINION_CHIPS][DATA_SIZ*MINION_CORE_REPS];
+ uint8_t chipid[MINION_CHIPS]; // Chip Number
+ int chip_pin[MINION_CHIPS];
+
uint32_t next_task_id;
// Stats
@@ -893,19 +972,19 @@ static void display_ioctl(int reply, uint32_t osiz, uint8_t *obuf, uint32_t rsiz
}
if (reply < 0) {
- applog(IOCTRL_LOG, "%s %s chip %d osiz %d%s%s",
+ applog(IOCTRL_LOG, "%s %s chipid %d osiz %d%s%s",
name, dir, (int)obuf[0], (int)osiz, ex, buf);
applog(IOCTRL_LOG, " reply was error %d", reply);
} else {
if (IS_ADDR_WRITE(obuf[1])) {
- applog(IOCTRL_LOG, "%s %s chip %d osiz %d%s%s",
+ applog(IOCTRL_LOG, "%s %s chipid %d osiz %d%s%s",
name, dir, (int)obuf[0], (int)osiz, ex, buf);
applog(IOCTRL_LOG, " write ret was %d", reply);
} else {
switch (obuf[1]) {
case READ_ADDR(MINION_RES_DATA):
rescount = (int)((float)rsiz / (float)MINION_RES_DATA_SIZ);
- applog(IOCTRL_LOG, "%s %s chip %d osiz %d%s%s",
+ applog(IOCTRL_LOG, "%s %s chipid %d osiz %d%s%s",
name, dir, (int)obuf[0], (int)osiz, ex, buf);
for (i = 0; i < rescount; i++) {
res = (struct minion_result *)(rbuf + osiz - rsiz + (i * MINION_RES_DATA_SIZ));
@@ -914,10 +993,10 @@ static void display_ioctl(int reply, uint32_t osiz, uint8_t *obuf, uint32_t rsiz
} else {
__bin2hex(buf, res->nonce, DATA_SIZ);
applog(IOCTRL_LOG, " %s reply %d of %d %d(%d) was task 0x%04x"
- " chip %d core %d gold %s nonce 0x%s",
+ " chipid %d core %d gold %s nonce 0x%s",
name, i+1, rescount, reply, rsiz,
RES_TASK(res),
- (int)RES_CHIP(res),
+ (int)RES_CHIPID(res),
(int)RES_CORE(res),
(int)RES_GOLD(res) ? "Y" : "N",
buf);
@@ -927,7 +1006,7 @@ static void display_ioctl(int reply, uint32_t osiz, uint8_t *obuf, uint32_t rsiz
case READ_ADDR(MINION_SYS_CHIP_SIG):
case READ_ADDR(MINION_SYS_CHIP_STA):
default:
- applog(IOCTRL_LOG, "%s %s chip %d osiz %d%s%s",
+ applog(IOCTRL_LOG, "%s %s chipid %d osiz %d%s%s",
name, dir, (int)obuf[0], (int)osiz, ex, buf);
__bin2hex(buf, rbuf + osiz - rsiz, rsiz);
applog(IOCTRL_LOG, " %s reply %d(%d) was %s", name, reply, rsiz, buf);
@@ -941,7 +1020,35 @@ static void display_ioctl(int reply, uint32_t osiz, uint8_t *obuf, uint32_t rsiz
#define MINION_UNEXPECTED_TASK -999
#define MINION_OVERSIZE_TASK -998
-static int __do_ioctl(struct minion_info *minioninfo, uint8_t *obuf, uint32_t osiz, uint8_t *rbuf, uint32_t rsiz, MINION_FFL_ARGS)
+static void set_pin(struct minion_info *minioninfo, int pin, bool on)
+{
+ volatile uint32_t *paddr;
+ uint32_t value;
+ int bcm;
+
+ bcm = minionPins[pin].bcm;
+
+ paddr = minioninfo->gpio + ((on ? BCM2835_GPIO_SET0 : BCM2835_GPIO_CLR0) / 4) + (bcm / 10);
+
+ value = 1 << (bcm % 32);
+
+ *paddr = value;
+ *paddr = value;
+}
+
+static void init_pins(struct minion_info *minioninfo)
+{
+ int pin;
+
+ // Initialise all pins high as required
+ MINION_PIN_BEFORE;
+ for (pin = 0; pin < (int)MINION_PIN_COUNT; pin++) {
+ set_pin(minioninfo, pin, true);
+ MINION_PIN_SLEEP;
+ }
+}
+
+static int __do_ioctl(struct minion_info *minioninfo, int pin, uint8_t *obuf, uint32_t osiz, uint8_t *rbuf, uint32_t rsiz, MINION_FFL_ARGS)
{
struct spi_ioc_transfer tran;
int ret;
@@ -970,8 +1077,8 @@ static int __do_ioctl(struct minion_info *minioninfo, uint8_t *obuf, uint32_t os
memcpy(&dataw[DATA_OFF], &obuf[0], osiz);
char *buf = bin2hex((unsigned char *)&(dataw[DATA_OFF]), osiz);
- applog(IOCTRL_LOG, "*** %s() sending %02x %02x %s %02x %02x",
- __func__,
+ applog(IOCTRL_LOG, "*** %s() pin %d cid %d sending %02x %02x %s %02x %02x",
+ __func__, pin, (int)(dataw[DATA_OFF]),
dataw[0], dataw[DATA_OFF-1], buf,
dataw[DATA_OFF+osiz], dataw[DATA_ALL-1]);
free(buf);
@@ -1001,9 +1108,20 @@ static int __do_ioctl(struct minion_info *minioninfo, uint8_t *obuf, uint32_t os
IO_STAT_NOW(&lsta);
mutex_lock(&(minioninfo->spi_lock));
+ if (usepins) {
+ // Pin low for I/O
+ MINION_PIN_BEFORE;
+ set_pin(minioninfo, pin, false);
+ MINION_PIN_SLEEP;
+ }
IO_STAT_NOW(&sta);
ret = ioctl(minioninfo->spifd, SPI_IOC_MESSAGE(1), (void *)&tran);
IO_STAT_NOW(&fin);
+ if (usepins) {
+ MINION_PIN_AFTER;
+ // Pin back high after I/O
+ set_pin(minioninfo, pin, true);
+ }
mutex_unlock(&(minioninfo->spi_lock));
IO_STAT_NOW(&lfin);
IO_STAT_NOW(&tsd);
@@ -1013,8 +1131,8 @@ static int __do_ioctl(struct minion_info *minioninfo, uint8_t *obuf, uint32_t os
#if MINION_SHOW_IO
if (ret > 0) {
buf = bin2hex((unsigned char *)&(datar[DATA_OFF]), ret);
- applog(IOCTRL_LOG, "*** %s() reply %d = %02x %02x %s %02x %02x",
- __func__, ret,
+ applog(IOCTRL_LOG, "*** %s() reply %d = pin %d cid %d %02x %02x %s %02x %02x",
+ __func__, ret, pin, (int)(dataw[DATA_OFF]),
datar[0], datar[DATA_OFF-1], buf,
datar[DATA_OFF+osiz], datar[DATA_ALL-1]);
free(buf);
@@ -1030,11 +1148,11 @@ static int __do_ioctl(struct minion_info *minioninfo, uint8_t *obuf, uint32_t os
}
#if 1
-#define do_ioctl(_obuf, _osiz, _rbuf, _rsiz) __do_ioctl(minioninfo, _obuf, _osiz, _rbuf, _rsiz, MINION_FFL_HERE)
+#define do_ioctl(_pin, _obuf, _osiz, _rbuf, _rsiz) __do_ioctl(minioninfo, _pin, _obuf, _osiz, _rbuf, _rsiz, MINION_FFL_HERE)
#else
-#define do_ioctl(_obuf, _osiz, _rbuf, _rsiz) _do_ioctl(minioninfo, _obuf, _osiz, _rbuf, _rsiz, MINION_FFL_HERE)
+#define do_ioctl(_pin, _obuf, _osiz, _rbuf, _rsiz) _do_ioctl(minioninfo, _pin, _obuf, _osiz, _rbuf, _rsiz, MINION_FFL_HERE)
// This sends an expected to work, SPI command before each SPI command
-static int _do_ioctl(struct minion_info *minioninfo, uint8_t *obuf, uint32_t osiz, uint8_t *rbuf, uint32_t rsiz, MINION_FFL_ARGS)
+static int _do_ioctl(struct minion_info *minioninfo, int pin, uint8_t *obuf, uint32_t osiz, uint8_t *rbuf, uint32_t rsiz, MINION_FFL_ARGS)
{
struct minion_header *head;
uint8_t buf1[MINION_BUFSIZ];
@@ -1042,13 +1160,13 @@ static int _do_ioctl(struct minion_info *minioninfo, uint8_t *obuf, uint32_t osi
uint32_t siz;
head = (struct minion_header *)buf1;
- head->chip = 1; // Needs to be set to a valid chip
+ head->chipid = 1; // Needs to be set to a valid chip
head->reg = READ_ADDR(MINION_SYS_FIFO_STA);
SET_HEAD_SIZ(head, DATA_SIZ);
siz = HSIZE() + DATA_SIZ;
- __do_ioctl(minioninfo, buf1, siz, buf2, MINION_CORE_SIZ, MINION_FFL_PASS);
+ __do_ioctl(minioninfo, pin, buf1, siz, buf2, MINION_CORE_SIZ, MINION_FFL_PASS);
- return __do_ioctl(minioninfo, obuf, osiz, rbuf, rsiz, MINION_FFL_PASS);
+ return __do_ioctl(minioninfo, pin, obuf, osiz, rbuf, rsiz, MINION_FFL_PASS);
}
#endif
@@ -1057,7 +1175,7 @@ static bool _minion_txrx(struct cgpu_info *minioncgpu, struct minion_info *minio
struct minion_header *head;
head = (struct minion_header *)(task->obuf);
- head->chip = task->chip;
+ head->chipid = minioninfo->chipid[task->chip];
if (task->write)
SET_HEAD_WRITE(head, task->address);
else
@@ -1069,7 +1187,7 @@ static bool _minion_txrx(struct cgpu_info *minioncgpu, struct minion_info *minio
memcpy(&(head->data[0]), task->wbuf, task->wsiz);
task->osiz = HSIZE() + task->wsiz + task->rsiz;
- task->reply = do_ioctl(task->obuf, task->osiz, task->rbuf, task->rsiz);
+ task->reply = do_ioctl(CHIP_PIN(task->chip), task->obuf, task->osiz, task->rbuf, task->rsiz);
if (task->reply < 0) {
applog(LOG_ERR, "%s%d: chip=%d ioctl failed reply=%d err=%d" MINION_FFL,
minioncgpu->drv->name, minioncgpu->device_id,
@@ -1092,7 +1210,7 @@ static int build_cmd(struct cgpu_info *minioncgpu, struct minion_info *minioninf
int reply;
head = (struct minion_header *)wbuf;
- head->chip = chip;
+ head->chipid = minioninfo->chipid[chip];
head->reg = reg;
SET_HEAD_SIZ(head, DATA_SIZ);
@@ -1102,7 +1220,7 @@ static int build_cmd(struct cgpu_info *minioncgpu, struct minion_info *minioninf
head->data[3] = data[3];
wsiz = HSIZE() + DATA_SIZ;
- reply = do_ioctl(wbuf, wsiz, rbuf, rsiz);
+ reply = do_ioctl(CHIP_PIN(chip), wbuf, wsiz, rbuf, rsiz);
if (reply != (int)wsiz) {
applog(LOG_ERR, "%s: chip %d %s returned %d (should be %d)",
@@ -1350,71 +1468,90 @@ static void enable_interrupt(struct cgpu_info *minioncgpu, struct minion_info *m
}
#endif
-// Simple detect - just check each chip for the signature
-static void minion_detect_chips(struct cgpu_info *minioncgpu, struct minion_info *minioninfo)
+static void minion_detect_one(struct cgpu_info *minioncgpu, struct minion_info *minioninfo, int pin, int chipid)
{
struct minion_header *head;
uint8_t wbuf[MINION_BUFSIZ];
uint8_t rbuf[MINION_BUFSIZ];
uint32_t wsiz, rsiz;
- int chip, reply, tries;
+ int reply, tries, newchip;
bool ok;
head = (struct minion_header *)wbuf;
+ head->chipid = chipid;
rsiz = MINION_SYS_SIZ;
SET_HEAD_READ(head, MINION_SYS_CHIP_SIG);
SET_HEAD_SIZ(head, rsiz);
wsiz = HSIZE() + rsiz;
- for (chip = 0; chip < MINION_CHIPS; chip++) {
- head->chip = (uint8_t)chip;
- tries = 0;
- ok = false;
- do {
- reply = do_ioctl(wbuf, wsiz, rbuf, rsiz);
-
- if (reply == (int)(wsiz)) {
- uint32_t sig = u8tou32(rbuf, wsiz - rsiz);
-
- if (sig == MINION_CHIP_SIG) {
- minioninfo->chip[chip] = true;
- minioninfo->chips++;
- ok = true;
+
+ tries = 0;
+ ok = false;
+ do {
+ reply = do_ioctl(pin, wbuf, wsiz, rbuf, rsiz);
+
+ if (reply == (int)(wsiz)) {
+ uint32_t sig = u8tou32(rbuf, wsiz - rsiz);
+
+ if (sig == MINION_CHIP_SIG) {
+ newchip = (minioninfo->chips)++;
+ minioninfo->has_chip[newchip] = true;
+ minioninfo->chipid[newchip] = chipid;
+ minioninfo->chip_pin[newchip] = pin;
+ ok = true;
+ } else {
+ if (sig == MINION_CHIP_SIG_SHIFT1 ||
+ sig == MINION_CHIP_SIG_SHIFT2 ||
+ sig == MINION_CHIP_SIG_SHIFT3 ||
+ sig == MINION_CHIP_SIG_SHIFT4) {
+ applog(LOG_WARNING, "%s: pin %d chipid %d detect offset got"
+ " 0x%08x wanted 0x%08x",
+ minioncgpu->drv->dname, pin, chipid,
+ sig, MINION_CHIP_SIG);
} else {
- if (sig == MINION_CHIP_SIG_SHIFT1 ||
- sig == MINION_CHIP_SIG_SHIFT2 ||
- sig == MINION_CHIP_SIG_SHIFT3 ||
- sig == MINION_CHIP_SIG_SHIFT4) {
- applog(LOG_WARNING, "%s: chip %d detect offset got"
- " 0x%08x wanted 0x%08x",
- minioncgpu->drv->dname, chip, sig,
- MINION_CHIP_SIG);
- } else {
- if (sig == MINION_NOCHIP_SIG ||
- sig == MINION_NOCHIP_SIG2) // Assume no chip
- ok = true;
- else {
- applog(LOG_ERR, "%s: chip %d detect failed got"
- " 0x%08x wanted 0x%08x",
- minioncgpu->drv->dname, chip, sig,
- MINION_CHIP_SIG);
- }
+ if (sig == MINION_NOCHIP_SIG ||
+ sig == MINION_NOCHIP_SIG2) // Assume no chip
+ ok = true;
+ else {
+ applog(LOG_ERR, "%s: pin %d chipid %d detect failed"
+ " got 0x%08x wanted 0x%08x",
+ minioncgpu->drv->dname, pin,
+ chipid, sig, MINION_CHIP_SIG);
}
}
- } else {
- applog(LOG_ERR, "%s: chip %d reply %d ignored should be %d",
- minioncgpu->drv->dname, chip, reply, (int)(wsiz));
}
- } while (!ok && ++tries <= MINION_SIG_TRIES);
+ } else {
+ applog(LOG_ERR, "%s: pin %d chipid %d reply %d ignored should be %d",
+ minioncgpu->drv->dname, pin, chipid, reply, (int)(wsiz));
+ }
+ } while (!ok && ++tries <= MINION_SIG_TRIES);
+
+ if (!ok) {
+ applog(LOG_ERR, "%s: pin %d chipid %d - detect failure status",
+ minioncgpu->drv->dname, pin, chipid);
+ }
+}
+
+// Simple detect - just check each chip for the signature
+static void minion_detect_chips(struct cgpu_info *minioncgpu, struct minion_info *minioninfo)
+{
+ int pin, chipid, chip;
+ int pinend;
- if (!ok) {
- applog(LOG_ERR, "%s: chip %d - detect failure status",
- minioncgpu->drv->dname, chip);
+ if (usepins) {
+ init_pins(minioninfo);
+ pinend = (int)MINION_PIN_COUNT;
+ } else
+ pinend = 1;
+
+ for (pin = 0; pin < pinend; pin++) {
+ for (chipid = MINION_MIN_CHIP; chipid <= MINION_MAX_CHIP; chipid++) {
+ minion_detect_one(minioncgpu, minioninfo, pin, chipid);
}
}
if (minioninfo->chips) {
- for (chip = 0; chip < MINION_CHIPS; chip++) {
- if (minioninfo->chip[chip]) {
+ for (chip = 0; chip < (int)MINION_CHIPS; chip++) {
+ if (minioninfo->has_chip[chip]) {
init_chip(minioncgpu, minioninfo, chip);
enable_chip_cores(minioncgpu, minioninfo, chip);
}
@@ -1423,7 +1560,7 @@ static void minion_detect_chips(struct cgpu_info *minioncgpu, struct minion_info
#if ENABLE_INT_NONO
// After everything is ready
for (chip = 0; chip < MINION_CHIPS; chip++)
- if (minioninfo->chip[chip])
+ if (minioninfo->has_chip[chip])
enable_interrupt(minioncgpu, minioninfo, chip);
#endif
}
@@ -1502,6 +1639,62 @@ bad_out:
return false;
}
+static bool minion_setup_chip_select(struct cgpu_info *minioncgpu, struct minion_info *minioninfo)
+{
+ volatile uint32_t *paddr;
+ uint32_t mask, value, mem;
+ int count, memfd, pin, bcm;
+
+ memfd = open(minion_memory, O_RDWR | O_SYNC);
+ if (memfd < 0) {
+ applog(LOG_ERR, "%s: failed open %s (%d)",
+ minioncgpu->drv->dname,
+ minion_memory, errno);
+ return false;
+ }
+
+ minioninfo->gpio = (volatile unsigned *)mmap(NULL, MINION_PAGE_SIZE,
+ PROT_READ | PROT_WRITE,
+ MAP_SHARED, memfd,
+ minion_memory_addr);
+ if (minioninfo->gpio == MAP_FAILED) {
+ close(memfd);
+ applog(LOG_ERR, "%s: failed mmap gpio (%d)",
+ minioncgpu->drv->dname,
+ errno);
+ return false;
+ }
+
+ close(memfd);
+
+ for (pin = 0; pin < (int)MINION_PIN_COUNT; pin++) {
+ bcm = minionPins[pin].bcm;
+
+ paddr = minioninfo->gpio + (BCM2835_GPIO_FSEL0 / 4) + (bcm / 10);
+
+ // Set each pin to be an output pin
+ mask = BCM2835_GPIO_FSEL_MASK << ((bcm % 10) * 3);
+ value = BCM2835_GPIO_FSEL_OUTPUT << ((bcm % 10) * 3);
+
+ // Read settings
+ mem = *paddr;
+ *paddr;
+
+ mem = (mem & ~mask) | (value & mask);
+
+ // Write appended setting
+ *paddr = mem;
+ *paddr = mem;
+
+ count++;
+ }
+
+ if (count == 0)
+ return false;
+ else
+ return true;
+}
+
#if ENABLE_INT_NONO
static bool minion_init_gpio_interrupt(struct cgpu_info *minioncgpu, struct minion_info *minioninfo)
{
@@ -1686,7 +1879,7 @@ static void minion_process_options(struct minion_info *minioninfo)
if (comma)
*(comma++) = '\0';
- for (i = 0; i < MINION_CHIPS; i++) {
+ for (i = 0; i < (int)MINION_CHIPS; i++) {
if (freq && isdigit(*freq)) {
last_freq = (int)(round((double)atoi(freq) / (double)MINION_FREQ_FACTOR)) * MINION_FREQ_FACTOR;
if (last_freq < MINION_FREQ_MIN)
@@ -1713,7 +1906,7 @@ static void minion_process_options(struct minion_info *minioninfo)
if (comma)
*(comma++) = '\0';
- for (i = 0; i < MINION_CHIPS; i++) {
+ for (i = 0; i < (int)MINION_CHIPS; i++) {
if (temp) {
if (isdigit(*temp)) {
last_temp = atoi(temp);
@@ -1748,7 +1941,7 @@ static void minion_process_options(struct minion_info *minioninfo)
if (comma)
*(comma++) = '\0';
- for (i = 0; i < MINION_CHIPS; i++) {
+ for (i = 0; i < (int)MINION_CHIPS; i++) {
// default to previous until we find valid data
cleared = false;
if (core) {
@@ -1841,16 +2034,21 @@ static void minion_detect(bool hotplug)
goto unalloc;
#endif
+
+ if (usepins) {
+ if (!minion_setup_chip_select(minioncgpu, minioninfo))
+ goto unalloc;
+ }
+
mutex_init(&(minioninfo->spi_lock));
mutex_init(&(minioninfo->sta_lock));
- for (i = 0; i < MINION_CHIPS; i++) {
+ for (i = 0; i < (int)MINION_CHIPS; i++) {
minioninfo->init_freq[i] = MINION_FREQ_DEF;
minioninfo->init_temp[i] = MINION_TEMP_CTL_DEF;
default_all_cores(&(minioninfo->init_cores[i][0]));
}
-
minion_process_options(minioninfo);
applog(LOG_WARNING, "%s: checking for chips ...", minioncgpu->drv->dname);
@@ -1858,10 +2056,11 @@ static void minion_detect(bool hotplug)
minion_detect_chips(minioncgpu, minioninfo);
buf[0] = '\0';
- for (i = 0; i < MINION_CHIPS; i++) {
- if (minioninfo->chip[i]) {
+ for (i = 0; i < (int)MINION_CHIPS; i++) {
+ if (minioninfo->has_chip[i]) {
off = strlen(buf);
- snprintf(buf + off, sizeof(buf) - off, " %d", i);
+ snprintf(buf + off, sizeof(buf) - off, " %d:%d/%d",
+ i, minioninfo->chip_pin[i], (int)(minioninfo->chipid[i]));
}
}
@@ -1880,7 +2079,7 @@ static void minion_detect(bool hotplug)
minioninfo->wfree_list = k_new_list("Work", sizeof(WITEM), ALLOC_WITEMS, LIMIT_WITEMS, true);
minioninfo->wwork_list = k_new_store(minioninfo->wfree_list);
// Initialise them all in case we later decide to enable chips
- for (i = 0; i < MINION_CHIPS; i++) {
+ for (i = 0; i < (int)MINION_CHIPS; i++) {
minioninfo->wque_list[i] = k_new_store(minioninfo->wfree_list);
minioninfo->wchip_list[i] = k_new_store(minioninfo->wfree_list);
}
@@ -1894,7 +2093,7 @@ static void minion_detect(bool hotplug)
minioninfo->history_gen = MINION_MAX_RESET_CHECK;
minioninfo->hfree_list = k_new_list("History", sizeof(HITEM), ALLOC_HITEMS, LIMIT_HITEMS, true);
- for (i = 0; i < MINION_CHIPS; i++)
+ for (i = 0; i < (int)MINION_CHIPS; i++)
minioninfo->hchip_list[i] = k_new_store(minioninfo->hfree_list);
cgsem_init(&(minioninfo->task_ready));
@@ -2224,8 +2423,8 @@ static void *minion_spi_reply(void *userdata)
somelow = false;
while (minioncgpu->shutdown == false) {
- for (chip = 0; chip < MINION_CHIPS; chip++) {
- if (minioninfo->chip[chip]) {
+ for (chip = 0; chip < (int)MINION_CHIPS; chip++) {
+ if (minioninfo->has_chip[chip]) {
int tries = 0;
uint8_t res, cmd;
while (++tries < 4) {
@@ -2394,15 +2593,15 @@ repeek:
minioninfo->use_res2[chip]++;
}
- //DATAR(item)->chip = RES_CHIP(use1);
+ //DATAR(item)->chip = RES_CHIPID(use1);
// We can avoid any SPI transmission error of the chip number
DATAR(item)->chip = (uint8_t)chip;
- if ((uint8_t)chip != RES_CHIP(use1)) {
+ if (minioninfo->chipid[chip] != RES_CHIPID(use1)) {
minioninfo->spi_errors++;
minioninfo->res_spi_errors[chip]++;
minioninfo->res_err_count[chip]++;
}
- if (use2 && (uint8_t)chip != RES_CHIP(use2)) {
+ if (use2 && minioninfo->chipid[chip] != RES_CHIPID(use2)) {
minioninfo->spi_errors++;
minioninfo->res_spi_errors[chip]++;
minioninfo->res_err_count[chip]++;
@@ -2419,7 +2618,7 @@ repeek:
DATAR(item)->task_id2 = RES_TASK(use2);
DATAR(item)->nonce2 = RES_NONCE(use2);
}
-//applog(MINTASK_LOG, "%s%i: ZZZ reply task_id 0x%04x - chip %d - gold %d", minioncgpu->drv->name, minioncgpu->device_id, RES_TASK(use1), (int)RES_CHIP(use1), (int)RES_GOLD(use1));
+//applog(MINTASK_LOG, "%s%i: ZZZ reply task_id 0x%04x - chip %d - gold %d", minioncgpu->drv->name, minioncgpu->device_id, RES_TASK(use1), (int)RES_CHIPID(use1), (int)RES_GOLD(use1));
//if (RES_GOLD(use1))
//applog(MINTASK_LOG, "%s%i: found a result chip %d core %d task 0x%04x nonce 0x%08x gold=%d", minioncgpu->drv->name, minioncgpu->device_id, DATAR(item)->chip, DATAR(item)->core, DATAR(item)->task_id, DATAR(item)->nonce, (int)RES_GOLD(use1));
@@ -2480,11 +2679,11 @@ repeek:
// minioncgpu->device_id);
gotres = false;
- for (chip = 0; chip < MINION_CHIPS; chip++) {
- if (minioninfo->chip[chip]) {
+ for (chip = 0; chip < (int)MINION_CHIPS; chip++) {
+ if (minioninfo->has_chip[chip]) {
SET_HEAD_READ(head, MINION_SYS_INT_STA);
- head->chip = chip;
- reply = do_ioctl(wbuf, wsiz, rbuf, rsiz);
+ head->chipid = minioninfo->chipid[chip];
+ reply = do_ioctl(CHIP_PIN(chip), wbuf, wsiz, rbuf, rsiz);
if (reply != (int)wsiz) {
applog(LOG_ERR, "%s: chip %d int status returned %d"
" (should be %d)",
@@ -2629,7 +2828,7 @@ static enum nonce_state oknonce(struct thr_info *thr, struct cgpu_info *minioncg
bool redo;
// if the chip has been disabled - but we don't do that - so not possible (yet)
- if (!(minioninfo->chip[chip])) {
+ if (!(minioninfo->has_chip[chip])) {
minioninfo->spi_errors++;
applog(MINTASK_LOG, "%s%i: nonce error chip %d not present",
minioncgpu->drv->name, minioncgpu->device_id, chip);
@@ -2740,7 +2939,7 @@ retest:
item = k_unlink_head(minioninfo->hfree_list);
memcpy(&(DATAH(item)->when), when, sizeof(*when));
k_add_head(minioninfo->hchip_list[chip], item);
- for (chip_tmp = 0; chip_tmp < MINION_CHIPS; chip_tmp++) {
+ for (chip_tmp = 0; chip_tmp < (int)MINION_CHIPS; chip_tmp++) {
tail = minioninfo->hchip_list[chip_tmp]->tail;
while (tail && tdiff(&(DATAH(tail)->when), &now) > MINION_HISTORY_s) {
tail = k_unlink_tail(minioninfo->hchip_list[chip_tmp]);
@@ -2815,6 +3014,9 @@ static void minion_flush_work(struct cgpu_info *minioncgpu)
K_ITEM *stale_unused_work, *prev_unused, *task, *prev_task, *witem;
int i;
+ if (minioninfo->initialised == false)
+ return;
+
applog(MINION_LOG, "%s%i: flushing work",
minioncgpu->drv->name, minioncgpu->device_id);
@@ -2853,8 +3055,8 @@ static void minion_flush_work(struct cgpu_info *minioncgpu)
}
task = prev_task;
}
- for (i = 0; i < MINION_CHIPS; i++) {
- if (minioninfo->chip[i]) {
+ for (i = 0; i < (int)MINION_CHIPS; i++) {
+ if (minioninfo->has_chip[i]) {
// TODO: consider sending it now rather than adding to the task list?
task = k_unlink_head(minioninfo->tfree_list);
DATAT(task)->tid = ++(minioninfo->next_tid);
@@ -3084,11 +3286,11 @@ static void minion_do_work(struct cgpu_info *minioncgpu)
for (state = 0; state < 3; state++) {
#define CHP 0
//applog(LOG_ERR, "%s%i: chip %d presta %d: quew %d chw %d", minioncgpu->drv->name, minioncgpu->device_id, CHP, state, minioninfo->chip_status[CHP].quework, minioninfo->chip_status[CHP].chipwork);
- for (chip = 0; chip < MINION_CHIPS; chip++)
+ for (chip = 0; chip < (int)MINION_CHIPS; chip++)
minioninfo->chip_status[chip].tohigh = false;
- for (chip = 0; chip < MINION_CHIPS; chip++) {
- if (minioninfo->chip[chip] && !minioninfo->chip_status[chip].overheat) {
+ for (chip = 0; chip < (int)MINION_CHIPS; chip++) {
+ if (minioninfo->has_chip[chip] && !minioninfo->chip_status[chip].overheat) {
K_WLOCK(minioninfo->wchip_list[chip]);
count = minioninfo->chip_status[chip].quework +
minioninfo->chip_status[chip].realwork;
@@ -3171,7 +3373,7 @@ static void minion_do_work(struct cgpu_info *minioncgpu)
break;
}
} else
- if (minioninfo->chip[chip] && minioninfo->chip_status[chip].overheat && state == 2)
+ if (minioninfo->has_chip[chip] && minioninfo->chip_status[chip].overheat && state == 2)
sys_chip_sta(minioncgpu, chip);
}
}
@@ -3249,8 +3451,8 @@ static void minion_shutdown(struct thr_info *thr)
applog(MINION_LOG, "%s%i: shutting down",
minioncgpu->drv->name, minioncgpu->device_id);
- for (i = 0; i < MINION_CHIPS; i++)
- if (minioninfo->chip[i])
+ for (i = 0; i < (int)MINION_CHIPS; i++)
+ if (minioninfo->has_chip[i])
// TODO: minion_shutdown(minioncgpu, minioninfo, i);
i = i;
@@ -3264,6 +3466,11 @@ static bool minion_queue_full(struct cgpu_info *minioncgpu)
int count, need, roll, roll_limit;
bool ret, rolled;
+ if (minioninfo->initialised == false) {
+ cgsleep_us(42);
+ return true;
+ }
+
K_RLOCK(minioninfo->wwork_list);
count = minioninfo->wwork_list->count;
K_RUNLOCK(minioninfo->wwork_list);
@@ -3310,8 +3517,8 @@ static void idle_report(struct cgpu_info *minioncgpu)
int msdiff;
int chip;
- for (chip = 0; chip < MINION_CHIPS; chip++) {
- if (minioninfo->chip[chip]) {
+ for (chip = 0; chip < (int)MINION_CHIPS; chip++) {
+ if (minioninfo->has_chip[chip]) {
idle = minioninfo->chip_status[chip].idle;
if (idle != minioninfo->chip_status[chip].last_rpt_idle) {
cgtime(&now);
@@ -3355,8 +3562,8 @@ static void chip_report(struct cgpu_info *minioncgpu)
res_err_msg[0] = '\0';
res_err_msg[1] = '\0';
K_RLOCK(minioninfo->hfree_list);
- for (chip = 0; chip < MINION_CHIPS; chip++) {
- if (minioninfo->chip[chip]) {
+ for (chip = 0; chip < (int)MINION_CHIPS; chip++) {
+ if (minioninfo->has_chip[chip]) {
len = strlen(buf);
if (minioninfo->hchip_list[chip]->count < 2)
ghs = 0.0;
@@ -3392,8 +3599,8 @@ static void chip_report(struct cgpu_info *minioncgpu)
msdiff = ms_tdiff(&now, &(minioninfo->chip_chk));
if (total_secs >= MINION_HISTORY_s && msdiff >= (minioninfo->history_gen * 1000)) {
K_RLOCK(minioninfo->hfree_list);
- for (chip = 0; chip < MINION_CHIPS; chip++) {
- if (minioninfo->chip[chip]) {
+ for (chip = 0; chip < (int)MINION_CHIPS; chip++) {
+ if (minioninfo->has_chip[chip]) {
if (minioninfo->hchip_list[chip]->count < 2)
ghs = 0.0;
else {
@@ -3411,8 +3618,8 @@ static void chip_report(struct cgpu_info *minioncgpu)
}
K_RUNLOCK(minioninfo->hfree_list);
- for (chip = 0; chip < MINION_CHIPS; chip++) {
- if (minioninfo->chip[chip]) {
+ for (chip = 0; chip < (int)MINION_CHIPS; chip++) {
+ if (minioninfo->has_chip[chip]) {
if (minioninfo->do_reset[chip] > 1.0) {
applog(LOG_WARNING, "%s%d: Chip %d down to threshold %.2fGHs - resetting ...",
minioncgpu->drv->name, minioncgpu->device_id,
@@ -3433,6 +3640,9 @@ static int64_t minion_scanwork(__maybe_unused struct thr_info *thr)
struct minion_info *minioninfo = (struct minion_info *)(minioncgpu->device_data);
int64_t hashcount = 0;
+ if (minioninfo->initialised == false)
+ return hashcount;
+
minion_do_work(minioncgpu);
mutex_lock(&(minioninfo->nonce_lock));
@@ -3484,8 +3694,8 @@ static void minion_get_statline_before(char *buf, size_t bufsiz, struct cgpu_inf
max_temp = 0;
cores = 0;
mutex_lock(&(minioninfo->sta_lock));
- for (chip = 0; chip < MINION_CHIPS; chip++) {
- if (minioninfo->chip[chip]) {
+ for (chip = 0; chip < (int)MINION_CHIPS; chip++) {
+ if (minioninfo->has_chip[chip]) {
if (max_temp < minioninfo->chip_status[chip].temp)
max_temp = minioninfo->chip_status[chip].temp;
for (core = 0; core < MINION_CORES; core++) {
@@ -3521,12 +3731,19 @@ static struct api_data *minion_api_stats(struct cgpu_info *minioncgpu)
root = api_add_uint64(root, "Untested Nonces", &(minioninfo->untested_nonces), true);
root = api_add_int(root, "Chips", &(minioninfo->chips), true);
+ i = MINION_PIN_COUNT;
+ root = api_add_int(root, "GPIO Pins", &i, true);
max_chip = 0;
- for (chip = 0; chip < MINION_CHIPS; chip++)
- if (minioninfo->chip[chip]) {
+ for (chip = 0; chip < (int)MINION_CHIPS; chip++)
+ if (minioninfo->has_chip[chip]) {
max_chip = chip;
+ snprintf(buf, sizeof(buf), "Chip %d Pin", chip);
+ root = api_add_int(root, buf, &(minioninfo->chip_pin[chip]), true);
+ snprintf(buf, sizeof(buf), "Chip %d ChipID", chip);
+ i = (int)(minioninfo->chipid[chip]);
+ root = api_add_int(root, buf, &i, true);
snprintf(buf, sizeof(buf), "Chip %d Temperature", chip);
root = api_add_const(root, buf, temp_str(minioninfo->chip_status[chip].temp), false);
snprintf(buf, sizeof(buf), "Chip %d Cores", chip);
@@ -3608,7 +3825,7 @@ static struct api_data *minion_api_stats(struct cgpu_info *minioncgpu)
snprintf(buf, sizeof(buf),
"%s%d",
j == i ? "" : " ",
- minioninfo->chip[j] ? 1 : 0);
+ minioninfo->has_chip[j] ? 1 : 0);
strcat(data, buf);
}
snprintf(buf, sizeof(buf), "Detected %02d - %02d", i, to);
@@ -3709,7 +3926,7 @@ static struct api_data *minion_api_stats(struct cgpu_info *minioncgpu)
que_work = chip_work = 0;
for (chip = 0; chip <= max_chip; chip++)
- if (minioninfo->chip[chip]) {
+ if (minioninfo->has_chip[chip]) {
que_work += minioninfo->wchip_list[chip]->count;
chip_work += minioninfo->wchip_list[chip]->count;
}
diff --git a/miner.h b/miner.h
index a97b5b8..74993c0 100644
--- a/miner.h
+++ b/miner.h
@@ -208,12 +208,6 @@ static inline int fsync (int fd)
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
#endif
-#ifdef MIPSEB
-#ifndef roundl
-#define roundl(x) (long double)((long long)((x==0)?0.0:((x)+((x)>0)?0.5:-0.5)))
-#endif
-#endif
-
/* No semtimedop on apple so ignore timeout till we implement one */
#ifdef __APPLE__
#define semtimedop(SEM, SOPS, VAL, TIMEOUT) semop(SEM, SOPS, VAL)
@@ -992,6 +986,7 @@ extern bool opt_restart;
extern char *opt_icarus_options;
extern char *opt_icarus_timing;
extern float opt_anu_freq;
+extern float opt_rock_freq;
#endif
extern bool opt_worktime;
#ifdef USE_AVALON
diff --git a/usbutils.c b/usbutils.c
index 4e46b23..595ed05 100644
--- a/usbutils.c
+++ b/usbutils.c
@@ -583,6 +583,16 @@ static struct usb_find_devices find_dev[] = {
INTINFO(amu_ints) },
{
.drv = DRIVER_icarus,
+ .name = "LIN",
+ .ident = IDENT_LIN,
+ .idVendor = 0x10c4,
+ .idProduct = 0xea60,
+ .config = 1,
+ .timeout = ICARUS_TIMEOUT_MS,
+ .latency = LATENCY_UNUSED,
+ INTINFO(amu_ints) },
+ {
+ .drv = DRIVER_icarus,
.name = "ANU",
.ident = IDENT_ANU,
.idVendor = 0x10c4,
diff --git a/usbutils.h b/usbutils.h
index 335cb39..8e9f949 100644
--- a/usbutils.h
+++ b/usbutils.h
@@ -157,6 +157,7 @@ enum sub_ident {
IDENT_HFA,
IDENT_ICA,
IDENT_KLN,
+ IDENT_LIN,
IDENT_LLT,
IDENT_MMQ,
IDENT_NFU,
diff --git a/util.c b/util.c
index 756b77d..683ce09 100644
--- a/util.c
+++ b/util.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2011-2013 Con Kolivas
+ * Copyright 2011-2014 Con Kolivas
* Copyright 2010 Jeff Garzik
*
* This program is free software; you can redistribute it and/or modify it
@@ -720,6 +720,58 @@ bool hex2bin(unsigned char *p, const char *hexstr, size_t len)
return ret;
}
+static bool _valid_hex(char *s, const char *file, const char *func, const int line)
+{
+ bool ret = false;
+ int i, len;
+
+ if (unlikely(!s)) {
+ applog(LOG_ERR, "Null string passed to valid_hex from"IN_FMT_FFL, file, func, line);
+ return ret;
+ }
+ len = strlen(s);
+ for (i = 0; i < len; i++) {
+ unsigned char idx = s[i];
+
+ if (unlikely(hex2bin_tbl[idx] < 0)) {
+ applog(LOG_ERR, "Invalid char 0x%x passed to valid_hex from"IN_FMT_FFL, idx, file, func, line);
+ return ret;
+ }
+ }
+ ret = true;
+ return ret;
+}
+
+#define valid_hex(s) _valid_hex(s, __FILE__, __func__, __LINE__)
+
+static bool _valid_ascii(char *s, const char *file, const char *func, const int line)
+{
+ bool ret = false;
+ int i, len;
+
+ if (unlikely(!s)) {
+ applog(LOG_ERR, "Null string passed to valid_ascii from"IN_FMT_FFL, file, func, line);
+ return ret;
+ }
+ len = strlen(s);
+ if (unlikely(!len)) {
+ applog(LOG_ERR, "Zero length string passed to valid_ascii from"IN_FMT_FFL, file, func, line);
+ return ret;
+ }
+ for (i = 0; i < len; i++) {
+ unsigned char idx = s[i];
+
+ if (unlikely(idx < 32 || idx > 126)) {
+ applog(LOG_ERR, "Invalid char 0x%x passed to valid_ascii from"IN_FMT_FFL, idx, file, func, line);
+ return ret;
+ }
+ }
+ ret = true;
+ return ret;
+}
+
+#define valid_ascii(s) _valid_ascii(s, __FILE__, __func__, __LINE__)
+
static const int b58tobin_tbl[] = {
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
@@ -1375,7 +1427,7 @@ bool extract_sockaddr(char *url, char **sockaddr_url, char **sockaddr_port)
if (url_len < 1)
return false;
- sprintf(url_address, "%.*s", url_len, url_begin);
+ snprintf(url_address, 254, "%.*s", url_len, url_begin);
if (port_len) {
char *slash;
@@ -1685,14 +1737,13 @@ static bool parse_notify(struct pool *pool, json_t *val)
ntime = __json_array_string(val, 7);
clean = json_is_true(json_array_get(val, 8));
- if (!job_id || !prev_hash || !coinbase1 || !coinbase2 || !bbversion || !nbit || !ntime) {
+ if (!valid_ascii(job_id) || !valid_hex(prev_hash) || !valid_hex(coinbase1) ||
+ !valid_hex(coinbase2) || !valid_hex(bbversion) || !valid_hex(nbit) ||
+ !valid_hex(ntime)) {
/* Annoying but we must not leak memory */
- if (job_id)
- free(job_id);
- if (coinbase1)
- free(coinbase1);
- if (coinbase2)
- free(coinbase2);
+ free(job_id);
+ free(coinbase1);
+ free(coinbase2);
goto out;
}
@@ -1880,7 +1931,7 @@ static bool parse_reconnect(struct pool *pool, json_t *val)
if (!port)
port = pool->stratum_port;
- sprintf(address, "%s:%s", url, port);
+ snprintf(address, 254, "%s:%s", url, port);
if (!extract_sockaddr(address, &sockaddr_url, &stratum_port))
return false;
@@ -2551,14 +2602,14 @@ resend:
if (!sessionid)
applog(LOG_DEBUG, "Failed to get sessionid in initiate_stratum");
nonce1 = json_array_string(res_val, 1);
- if (!nonce1) {
- applog(LOG_INFO, "Failed to get nonce1 in initiate_stratum");
+ if (!valid_hex(nonce1)) {
+ applog(LOG_INFO, "Failed to get valid nonce1 in initiate_stratum");
free(sessionid);
goto out;
}
n2size = json_integer_value(json_array_get(res_val, 2));
- if (!n2size) {
- applog(LOG_INFO, "Failed to get n2size in initiate_stratum");
+ if (n2size < 2 || n2size > 16) {
+ applog(LOG_INFO, "Failed to get valid n2size in initiate_stratum");
free(sessionid);
free(nonce1);
goto out;