rename device_api -> device_drv and all related api -> drv and add a device_drv->drv enum for identifying which driver each is
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
diff --git a/api.c b/api.c
index 3561c7a..2e013ff 100644
--- a/api.c
+++ b/api.c
@@ -599,22 +599,6 @@ struct APIGROUPS {
static struct IP4ACCESS *ipaccess = NULL;
static int ips = 0;
-#ifdef USE_BITFORCE
-extern struct device_api bitforce_api;
-#endif
-
-#ifdef USE_ICARUS
-extern struct device_api icarus_api;
-#endif
-
-#ifdef USE_ZTEX
-extern struct device_api ztex_api;
-#endif
-
-#ifdef USE_MODMINER
-extern struct device_api modminer_api;
-#endif
-
struct io_data {
size_t siz;
char *ptr;
@@ -1153,19 +1137,19 @@ static int numpgas()
for (i = 0; i < total_devices; i++) {
#ifdef USE_BITFORCE
- if (devices[i]->api == &bitforce_api)
+ if (devices[i]->drv->drv == DRIVER_BITFORCE)
count++;
#endif
#ifdef USE_ICARUS
- if (devices[i]->api == &icarus_api)
+ if (devices[i]->drv->drv == DRIVER_ICARUS)
count++;
#endif
#ifdef USE_ZTEX
- if (devices[i]->api == &ztex_api)
+ if (devices[i]->drv->drv == DRIVER_ZTEX)
count++;
#endif
#ifdef USE_MODMINER
- if (devices[i]->api == &modminer_api)
+ if (devices[i]->drv->drv == DRIVER_MODMINER)
count++;
#endif
}
@@ -1179,19 +1163,19 @@ static int pgadevice(int pgaid)
for (i = 0; i < total_devices; i++) {
#ifdef USE_BITFORCE
- if (devices[i]->api == &bitforce_api)
+ if (devices[i]->drv->drv == DRIVER_BITFORCE)
count++;
#endif
#ifdef USE_ICARUS
- if (devices[i]->api == &icarus_api)
+ if (devices[i]->drv->drv == DRIVER_ICARUS)
count++;
#endif
#ifdef USE_ZTEX
- if (devices[i]->api == &ztex_api)
+ if (devices[i]->drv->drv == DRIVER_ZTEX)
count++;
#endif
#ifdef USE_MODMINER
- if (devices[i]->api == &modminer_api)
+ if (devices[i]->drv->drv == DRIVER_MODMINER)
count++;
#endif
if (count == (pgaid + 1))
@@ -1535,11 +1519,11 @@ static void pgastatus(struct io_data *io_data, int pga, bool isjson, bool precom
float temp = cgpu->temp;
#ifdef USE_ZTEX
- if (cgpu->api == &ztex_api && cgpu->device_ztex)
+ if (cgpu->drv->drv == DRIVER_ZTEX && cgpu->device_ztex)
frequency = cgpu->device_ztex->freqM1 * (cgpu->device_ztex->freqM + 1);
#endif
#ifdef USE_MODMINER
- if (cgpu->api == &modminer_api)
+ if (cgpu->drv->drv == DRIVER_MODMINER)
frequency = cgpu->clock;
#endif
@@ -1553,7 +1537,7 @@ static void pgastatus(struct io_data *io_data, int pga, bool isjson, bool precom
status = (char *)status2str(cgpu->status);
root = api_add_int(root, "PGA", &pga, false);
- root = api_add_string(root, "Name", cgpu->api->name, false);
+ root = api_add_string(root, "Name", cgpu->drv->name, false);
root = api_add_int(root, "ID", &(cgpu->device_id), false);
root = api_add_string(root, "Enabled", enabled, false);
root = api_add_string(root, "Status", status, false);
@@ -1868,12 +1852,12 @@ static void pgaidentify(struct io_data *io_data, __maybe_unused SOCKETTYPE c, ch
}
struct cgpu_info *cgpu = devices[dev];
- struct device_api *api = cgpu->api;
+ struct device_drv *drv = cgpu->drv;
- if (!api->identify_device)
+ if (!drv->identify_device)
message(io_data, MSG_PGANOID, id, NULL, isjson);
else {
- api->identify_device(cgpu);
+ drv->identify_device(cgpu);
message(io_data, MSG_PGAIDENT, id, NULL, isjson);
}
}
@@ -2753,7 +2737,7 @@ void notifystatus(struct io_data *io_data, int device, struct cgpu_info *cgpu, b
// ALL counters (and only counters) must start the name with a '*'
// Simplifies future external support for identifying new counters
root = api_add_int(root, "NOTIFY", &device, false);
- root = api_add_string(root, "Name", cgpu->api->name, false);
+ root = api_add_string(root, "Name", cgpu->drv->name, false);
root = api_add_int(root, "ID", &(cgpu->device_id), false);
root = api_add_time(root, "Last Well", &(cgpu->device_last_well), false);
root = api_add_time(root, "Last Not Well", &(cgpu->device_last_not_well), false);
@@ -2817,9 +2801,9 @@ static void devdetails(struct io_data *io_data, __maybe_unused SOCKETTYPE c, __m
cgpu = devices[i];
root = api_add_int(root, "DEVDETAILS", &i, false);
- root = api_add_string(root, "Name", cgpu->api->name, false);
+ root = api_add_string(root, "Name", cgpu->drv->name, false);
root = api_add_int(root, "ID", &(cgpu->device_id), false);
- root = api_add_string(root, "Driver", cgpu->api->dname, false);
+ root = api_add_string(root, "Driver", cgpu->drv->dname, false);
root = api_add_const(root, "Kernel", cgpu->kname ? : BLANK, false);
root = api_add_const(root, "Model", cgpu->name ? : BLANK, false);
root = api_add_const(root, "Device Path", cgpu->device_path ? : BLANK, false);
@@ -2923,13 +2907,13 @@ static void minerstats(struct io_data *io_data, __maybe_unused SOCKETTYPE c, __m
for (j = 0; j < total_devices; j++) {
struct cgpu_info *cgpu = devices[j];
- if (cgpu && cgpu->api) {
- if (cgpu->api->get_api_stats)
- extra = cgpu->api->get_api_stats(cgpu);
+ if (cgpu && cgpu->drv) {
+ if (cgpu->drv->get_api_stats)
+ extra = cgpu->drv->get_api_stats(cgpu);
else
extra = NULL;
- sprintf(id, "%s%d", cgpu->api->name, cgpu->device_id);
+ sprintf(id, "%s%d", cgpu->drv->name, cgpu->device_id);
i = itemstats(io_data, i, id, &(cgpu->cgminer_stats), NULL, extra, isjson);
}
}
@@ -3195,16 +3179,16 @@ static void pgaset(struct io_data *io_data, __maybe_unused SOCKETTYPE c, __maybe
}
struct cgpu_info *cgpu = devices[dev];
- struct device_api *api = cgpu->api;
+ struct device_drv *drv = cgpu->drv;
char *set = strchr(opt, ',');
if (set)
*(set++) = '\0';
- if (!api->set_device)
+ if (!drv->set_device)
message(io_data, MSG_PGANOSET, id, NULL, isjson);
else {
- char *ret = api->set_device(cgpu, opt, set, buf);
+ char *ret = drv->set_device(cgpu, opt, set, buf);
if (ret) {
if (strcasecmp(opt, "help") == 0)
message(io_data, MSG_PGAHELP, id, ret, isjson);
diff --git a/cgminer.c b/cgminer.c
index 19ffcb9..adf7db4 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -385,7 +385,7 @@ static void sharelog(const char*disposition, const struct work*work)
data = bin2hex(work->data, sizeof(work->data));
// timestamp,disposition,target,pool,dev,thr,sharehash,sharedata
- rv = snprintf(s, sizeof(s), "%lu,%s,%s,%s,%s%u,%u,%s,%s\n", t, disposition, target, pool->rpc_url, cgpu->api->name, cgpu->device_id, thr_id, hash, data);
+ rv = snprintf(s, sizeof(s), "%lu,%s,%s,%s,%s%u,%u,%s,%s\n", t, disposition, target, pool->rpc_url, cgpu->drv->name, cgpu->device_id, thr_id, hash, data);
free(target);
free(hash);
free(data);
@@ -1875,9 +1875,9 @@ static void get_statline(char *buf, struct cgpu_info *cgpu)
suffix_string(dh64, displayed_hashes, 4);
suffix_string(dr64, displayed_rolling, 4);
- sprintf(buf, "%s%d ", cgpu->api->name, cgpu->device_id);
- if (cgpu->api->get_statline_before)
- cgpu->api->get_statline_before(buf, cgpu);
+ sprintf(buf, "%s%d ", cgpu->drv->name, cgpu->device_id);
+ if (cgpu->drv->get_statline_before)
+ cgpu->drv->get_statline_before(buf, cgpu);
else
tailsprintf(buf, " | ");
tailsprintf(buf, "(%ds):%s (avg):%sh/s | A:%d R:%d HW:%d U:%.1f/m",
@@ -1888,8 +1888,8 @@ static void get_statline(char *buf, struct cgpu_info *cgpu)
cgpu->rejected,
cgpu->hw_errors,
cgpu->utility);
- if (cgpu->api->get_statline)
- cgpu->api->get_statline(buf, cgpu);
+ if (cgpu->drv->get_statline)
+ cgpu->drv->get_statline(buf, cgpu);
}
static void text_print_status(int thr_id)
@@ -1971,10 +1971,10 @@ static void curses_print_devstatus(int thr_id)
cgpu->utility = cgpu->accepted / total_secs * 60;
wmove(statuswin,devcursor + cgpu->cgminer_id, 0);
- wprintw(statuswin, " %s %*d: ", cgpu->api->name, dev_width, cgpu->device_id);
- if (cgpu->api->get_statline_before) {
+ wprintw(statuswin, " %s %*d: ", cgpu->drv->name, dev_width, cgpu->device_id);
+ if (cgpu->drv->get_statline_before) {
logline[0] = '\0';
- cgpu->api->get_statline_before(logline, cgpu);
+ cgpu->drv->get_statline_before(logline, cgpu);
wprintw(statuswin, "%s", logline);
}
else
@@ -2007,9 +2007,9 @@ static void curses_print_devstatus(int thr_id)
hwwidth, cgpu->hw_errors,
uwidth + 3, cgpu->utility);
- if (cgpu->api->get_statline) {
+ if (cgpu->drv->get_statline) {
logline[0] = '\0';
- cgpu->api->get_statline(logline, cgpu);
+ cgpu->drv->get_statline(logline, cgpu);
wprintw(statuswin, "%s", logline);
}
@@ -2234,10 +2234,10 @@ share_result(json_t *val, json_t *res, json_t *err, const struct work *work,
if (!QUIET) {
if (total_pools > 1)
applog(LOG_NOTICE, "Accepted %s %s %d pool %d %s%s",
- hashshow, cgpu->api->name, cgpu->device_id, work->pool->pool_no, resubmit ? "(resubmit)" : "", worktime);
+ hashshow, cgpu->drv->name, cgpu->device_id, work->pool->pool_no, resubmit ? "(resubmit)" : "", worktime);
else
applog(LOG_NOTICE, "Accepted %s %s %d %s%s",
- hashshow, cgpu->api->name, cgpu->device_id, resubmit ? "(resubmit)" : "", worktime);
+ hashshow, cgpu->drv->name, cgpu->device_id, resubmit ? "(resubmit)" : "", worktime);
}
sharelog("accept", work);
if (opt_shares && total_accepted >= opt_shares) {
@@ -2302,7 +2302,7 @@ share_result(json_t *val, json_t *res, json_t *err, const struct work *work,
}
applog(LOG_NOTICE, "Rejected %s %s %d %s%s %s%s",
- hashshow, cgpu->api->name, cgpu->device_id, where, reason, resubmit ? "(resubmit)" : "", worktime);
+ hashshow, cgpu->drv->name, cgpu->device_id, where, reason, resubmit ? "(resubmit)" : "", worktime);
sharelog(disposition, work);
}
@@ -5238,15 +5238,15 @@ static bool hashtest(struct thr_info *thr, struct work *work)
if (hash2_32[7] != 0) {
applog(LOG_WARNING, "%s%d: invalid nonce - HW error",
- thr->cgpu->api->name, thr->cgpu->device_id);
+ thr->cgpu->drv->name, thr->cgpu->device_id);
mutex_lock(&stats_lock);
hw_errors++;
thr->cgpu->hw_errors++;
mutex_unlock(&stats_lock);
- if (thr->cgpu->api->hw_error)
- thr->cgpu->api->hw_error(thr);
+ if (thr->cgpu->drv->hw_error)
+ thr->cgpu->drv->hw_error(thr);
goto out;
}
@@ -5294,7 +5294,7 @@ static inline bool abandon_work(struct work *work, struct timeval *wdiff, uint64
}
static void mt_disable(struct thr_info *mythr, const int thr_id,
- struct device_api *api)
+ struct device_drv *drv)
{
applog(LOG_WARNING, "Thread %d being disabled", thr_id);
mythr->rolling = mythr->cgpu->rolling = 0;
@@ -5305,8 +5305,8 @@ static void mt_disable(struct thr_info *mythr, const int thr_id,
} while (mythr->pause);
thread_reportin(mythr);
applog(LOG_WARNING, "Thread %d being re-enabled", thr_id);
- if (api->thread_enable)
- api->thread_enable(mythr);
+ if (drv->thread_enable)
+ drv->thread_enable(mythr);
}
void *miner_thread(void *userdata)
@@ -5314,7 +5314,7 @@ void *miner_thread(void *userdata)
struct thr_info *mythr = userdata;
const int thr_id = mythr->id;
struct cgpu_info *cgpu = mythr->cgpu;
- struct device_api *api = cgpu->api;
+ struct device_drv *drv = cgpu->drv;
struct cgminer_stats *dev_stats = &(cgpu->cgminer_stats);
struct cgminer_stats *pool_stats;
struct timeval getwork_start;
@@ -5323,7 +5323,7 @@ void *miner_thread(void *userdata)
const long cycle = opt_log_interval / 5 ? : 1;
struct timeval tv_start, tv_end, tv_workstart, tv_lastupdate;
struct timeval diff, sdiff, wdiff = {0, 0};
- uint32_t max_nonce = api->can_limit_work ? api->can_limit_work(mythr) : 0xffffffff;
+ uint32_t max_nonce = drv->can_limit_work ? drv->can_limit_work(mythr) : 0xffffffff;
int64_t hashes_done = 0;
int64_t hashes;
struct work *work;
@@ -5337,7 +5337,7 @@ void *miner_thread(void *userdata)
gettimeofday(&getwork_start, NULL);
- if (api->thread_init && !api->thread_init(mythr)) {
+ if (drv->thread_init && !drv->thread_init(mythr)) {
dev_error(cgpu, REASON_THREAD_FAIL_INIT);
goto out;
}
@@ -5357,7 +5357,7 @@ void *miner_thread(void *userdata)
gettimeofday(&tv_workstart, NULL);
work->blk.nonce = 0;
cgpu->max_hashes = 0;
- if (api->prepare_work && !api->prepare_work(mythr, work)) {
+ if (drv->prepare_work && !drv->prepare_work(mythr, work)) {
applog(LOG_ERR, "work prepare failed, exiting "
"mining thread %d", thr_id);
break;
@@ -5399,16 +5399,16 @@ void *miner_thread(void *userdata)
gettimeofday(&(work->tv_work_start), NULL);
thread_reportin(mythr);
- hashes = api->scanhash(mythr, work, work->blk.nonce + max_nonce);
+ hashes = drv->scanhash(mythr, work, work->blk.nonce + max_nonce);
thread_reportin(mythr);
gettimeofday(&getwork_start, NULL);
if (unlikely(hashes == -1)) {
- applog(LOG_ERR, "%s %d failure, disabling!", api->name, cgpu->device_id);
+ applog(LOG_ERR, "%s %d failure, disabling!", drv->name, cgpu->device_id);
cgpu->deven = DEV_DISABLED;
dev_error(cgpu, REASON_THREAD_ZERO_HASH);
- mt_disable(mythr, thr_id, api);
+ mt_disable(mythr, thr_id, drv);
}
hashes_done += hashes;
@@ -5429,7 +5429,7 @@ void *miner_thread(void *userdata)
if (unlikely((long)sdiff.tv_sec < cycle)) {
int mult;
- if (likely(!api->can_limit_work || max_nonce == 0xffffffff))
+ if (likely(!drv->can_limit_work || max_nonce == 0xffffffff))
continue;
mult = 1000000 / ((sdiff.tv_usec + 0x400) / 0x400) + 0x10;
@@ -5438,9 +5438,9 @@ void *miner_thread(void *userdata)
max_nonce = 0xffffffff;
else
max_nonce = (max_nonce * mult) / 0x400;
- } else if (unlikely(sdiff.tv_sec > cycle) && api->can_limit_work)
+ } else if (unlikely(sdiff.tv_sec > cycle) && drv->can_limit_work)
max_nonce = max_nonce * cycle / sdiff.tv_sec;
- else if (unlikely(sdiff.tv_usec > 100000) && api->can_limit_work)
+ else if (unlikely(sdiff.tv_usec > 100000) && drv->can_limit_work)
max_nonce = max_nonce * 0x400 / (((cycle * 1000000) + sdiff.tv_usec) / (cycle * 1000000 / 0x400));
timersub(&tv_end, &tv_lastupdate, &diff);
@@ -5466,7 +5466,7 @@ void *miner_thread(void *userdata)
}
if (unlikely(mythr->pause || cgpu->deven != DEV_ENABLED))
- mt_disable(mythr, thr_id, api);
+ mt_disable(mythr, thr_id, drv);
sdiff.tv_sec = sdiff.tv_usec = 0;
} while (!abandon_work(work, &wdiff, cgpu->max_hashes));
@@ -5474,8 +5474,8 @@ void *miner_thread(void *userdata)
}
out:
- if (api->thread_shutdown)
- api->thread_shutdown(mythr);
+ if (drv->thread_shutdown)
+ drv->thread_shutdown(mythr);
thread_reportin(mythr);
applog(LOG_ERR, "Thread %d failure, exiting", thr_id);
@@ -5703,8 +5703,8 @@ out:
void reinit_device(struct cgpu_info *cgpu)
{
- if (cgpu->api->reinit_device)
- cgpu->api->reinit_device(cgpu);
+ if (cgpu->drv->reinit_device)
+ cgpu->drv->reinit_device(cgpu);
}
static struct timeval rotate_tv;
@@ -5879,12 +5879,12 @@ static void *watchdog_thread(void __maybe_unused *userdata)
char dev_str[8];
int gpu;
- if (cgpu->api->get_stats)
- cgpu->api->get_stats(cgpu);
+ if (cgpu->drv->get_stats)
+ cgpu->drv->get_stats(cgpu);
gpu = cgpu->device_id;
denable = &cgpu->deven;
- sprintf(dev_str, "%s%d", cgpu->api->name, gpu);
+ sprintf(dev_str, "%s%d", cgpu->drv->name, gpu);
#ifdef HAVE_ADL
if (adl_active && cgpu->has_adl)
@@ -5904,7 +5904,7 @@ static void *watchdog_thread(void __maybe_unused *userdata)
continue;
#ifdef WANT_CPUMINE
- if (!strcmp(cgpu->api->dname, "cpu"))
+ if (cgpu->drv->drv != DRIVER_CPU)
continue;
#endif
if (cgpu->status != LIFE_WELL && (now.tv_sec - thr->last.tv_sec < WATCHDOG_SICK_TIME)) {
@@ -6294,26 +6294,27 @@ void enable_curses(void) {
/* TODO: fix need a dummy CPU device_api even if no support for CPU mining */
#ifndef WANT_CPUMINE
-struct device_api cpu_api;
-struct device_api cpu_api = {
+struct device_drv cpu_drv;
+struct device_drv cpu_drv = {
+ .drv = DRIVER_CPU,
.name = "CPU",
};
#endif
#ifdef USE_BITFORCE
-extern struct device_api bitforce_api;
+extern struct device_drv bitforce_drv;
#endif
#ifdef USE_ICARUS
-extern struct device_api icarus_api;
+extern struct device_drv icarus_drv;
#endif
#ifdef USE_MODMINER
-extern struct device_api modminer_api;
+extern struct device_drv modminer_drv;
#endif
#ifdef USE_ZTEX
-extern struct device_api ztex_api;
+extern struct device_drv ztex_drv;
#endif
@@ -6328,7 +6329,7 @@ void enable_device(struct cgpu_info *cgpu)
adj_width(mining_threads, &dev_width);
#endif
#ifdef HAVE_OPENCL
- if (cgpu->api == &opencl_api) {
+ if (cgpu->drv->drv == DRIVER_OPENCL) {
gpu_threads += cgpu->threads;
}
#endif
@@ -6345,12 +6346,12 @@ bool add_cgpu(struct cgpu_info*cgpu)
static struct _cgpu_devid_counter *devids = NULL;
struct _cgpu_devid_counter *d;
- HASH_FIND_STR(devids, cgpu->api->name, d);
+ HASH_FIND_STR(devids, cgpu->drv->name, d);
if (d)
cgpu->device_id = ++d->lastid;
else {
d = malloc(sizeof(*d));
- memcpy(d->name, cgpu->api->name, sizeof(d->name));
+ memcpy(d->name, cgpu->drv->name, sizeof(d->name));
cgpu->device_id = d->lastid = 0;
HASH_ADD_STR(devids, name, d);
}
@@ -6568,32 +6569,32 @@ int main(int argc, char *argv[])
#ifdef HAVE_OPENCL
if (!opt_nogpu)
- opencl_api.api_detect();
+ opencl_drv.drv_detect();
gpu_threads = 0;
#endif
#ifdef USE_ICARUS
if (!opt_scrypt)
- icarus_api.api_detect();
+ icarus_drv.drv_detect();
#endif
#ifdef USE_BITFORCE
if (!opt_scrypt)
- bitforce_api.api_detect();
+ bitforce_drv.drv_detect();
#endif
#ifdef USE_MODMINER
if (!opt_scrypt)
- modminer_api.api_detect();
+ modminer_drv.drv_detect();
#endif
#ifdef USE_ZTEX
if (!opt_scrypt)
- ztex_api.api_detect();
+ ztex_drv.drv_detect();
#endif
#ifdef WANT_CPUMINE
- cpu_api.api_detect();
+ cpu_drv.drv_detect();
#endif
if (devices_enabled == -1) {
@@ -6601,9 +6602,9 @@ int main(int argc, char *argv[])
for (i = 0; i < total_devices; ++i) {
struct cgpu_info *cgpu = devices[i];
if (cgpu->name)
- applog(LOG_ERR, " %2d. %s %d: %s (driver: %s)", i, cgpu->api->name, cgpu->device_id, cgpu->name, cgpu->api->dname);
+ applog(LOG_ERR, " %2d. %s %d: %s (driver: %s)", i, cgpu->drv->name, cgpu->device_id, cgpu->name, cgpu->drv->dname);
else
- applog(LOG_ERR, " %2d. %s %d (driver: %s)", i, cgpu->api->name, cgpu->device_id, cgpu->api->dname);
+ applog(LOG_ERR, " %2d. %s %d (driver: %s)", i, cgpu->drv->name, cgpu->device_id, cgpu->drv->dname);
}
quit(0, "%d devices listed", total_devices);
}
@@ -6617,7 +6618,7 @@ int main(int argc, char *argv[])
enable_device(devices[i]);
} else if (i < total_devices) {
if (opt_removedisabled) {
- if (devices[i]->api == &cpu_api)
+ if (devices[i]->drv->drv == DRIVER_CPU)
--opt_n_threads;
} else {
enable_device(devices[i]);
@@ -6789,7 +6790,7 @@ begin_bench:
thr->q = tq_new();
if (!thr->q)
- quit(1, "tq_new failed in starting %s%d mining thread (#%d)", cgpu->api->name, cgpu->device_id, i);
+ quit(1, "tq_new failed in starting %s%d mining thread (#%d)", cgpu->drv->name, cgpu->device_id, i);
/* Enable threads for devices set not to mine but disable
* their queue in case we wish to enable them later */
@@ -6799,7 +6800,7 @@ begin_bench:
tq_push(thr->q, &ping);
}
- if (cgpu->api->thread_prepare && !cgpu->api->thread_prepare(thr))
+ if (cgpu->drv->thread_prepare && !cgpu->drv->thread_prepare(thr))
continue;
thread_reportout(thr);
diff --git a/driver-bitforce.c b/driver-bitforce.c
index 4a06b59..f119632 100644
--- a/driver-bitforce.c
+++ b/driver-bitforce.c
@@ -64,7 +64,7 @@
static const char *blank = "";
-struct device_api bitforce_api;
+struct device_drv bitforce_drv;
static void bitforce_initialise(struct cgpu_info *bitforce, bool lock)
{
@@ -78,14 +78,14 @@ static void bitforce_initialise(struct cgpu_info *bitforce, bool lock)
FTDI_VALUE_RESET, bitforce->usbdev->found->interface, C_RESET);
if (opt_debug)
applog(LOG_DEBUG, "%s%i: reset got err %d",
- bitforce->api->name, bitforce->device_id, err);
+ bitforce->drv->name, bitforce->device_id, err);
// Set data control
err = usb_transfer(bitforce, FTDI_TYPE_OUT, FTDI_REQUEST_DATA,
FTDI_VALUE_DATA, bitforce->usbdev->found->interface, C_SETDATA);
if (opt_debug)
applog(LOG_DEBUG, "%s%i: setdata got err %d",
- bitforce->api->name, bitforce->device_id, err);
+ bitforce->drv->name, bitforce->device_id, err);
// Set the baud
err = usb_transfer(bitforce, FTDI_TYPE_OUT, FTDI_REQUEST_BAUD, FTDI_VALUE_BAUD,
@@ -93,35 +93,35 @@ static void bitforce_initialise(struct cgpu_info *bitforce, bool lock)
C_SETBAUD);
if (opt_debug)
applog(LOG_DEBUG, "%s%i: setbaud got err %d",
- bitforce->api->name, bitforce->device_id, err);
+ bitforce->drv->name, bitforce->device_id, err);
// Set Flow Control
err = usb_transfer(bitforce, FTDI_TYPE_OUT, FTDI_REQUEST_FLOW,
FTDI_VALUE_FLOW, bitforce->usbdev->found->interface, C_SETFLOW);
if (opt_debug)
applog(LOG_DEBUG, "%s%i: setflowctrl got err %d",
- bitforce->api->name, bitforce->device_id, err);
+ bitforce->drv->name, bitforce->device_id, err);
// Set Modem Control
err = usb_transfer(bitforce, FTDI_TYPE_OUT, FTDI_REQUEST_MODEM,
FTDI_VALUE_MODEM, bitforce->usbdev->found->interface, C_SETMODEM);
if (opt_debug)
applog(LOG_DEBUG, "%s%i: setmodemctrl got err %d",
- bitforce->api->name, bitforce->device_id, err);
+ bitforce->drv->name, bitforce->device_id, err);
// Clear any sent data
err = usb_transfer(bitforce, FTDI_TYPE_OUT, FTDI_REQUEST_RESET,
FTDI_VALUE_PURGE_TX, bitforce->usbdev->found->interface, C_PURGETX);
if (opt_debug)
applog(LOG_DEBUG, "%s%i: purgetx got err %d",
- bitforce->api->name, bitforce->device_id, err);
+ bitforce->drv->name, bitforce->device_id, err);
// Clear any received data
err = usb_transfer(bitforce, FTDI_TYPE_OUT, FTDI_REQUEST_RESET,
FTDI_VALUE_PURGE_RX, bitforce->usbdev->found->interface, C_PURGERX);
if (opt_debug)
applog(LOG_DEBUG, "%s%i: purgerx got err %d",
- bitforce->api->name, bitforce->device_id, err);
+ bitforce->drv->name, bitforce->device_id, err);
if (lock)
mutex_unlock(&bitforce->device_mutex);
@@ -136,13 +136,13 @@ static bool bitforce_detect_one(struct libusb_device *dev, struct usb_find_devic
struct cgpu_info *bitforce = NULL;
bitforce = calloc(1, sizeof(*bitforce));
- bitforce->api = &bitforce_api;
+ bitforce->drv = &bitforce_drv;
bitforce->deven = DEV_ENABLED;
bitforce->threads = 1;
if (!usb_init(bitforce, dev, found)) {
applog(LOG_ERR, "%s detect (%d:%d) failed to initialise (incorrect device?)",
- bitforce->api->dname,
+ bitforce->drv->dname,
(int)libusb_get_bus_number(dev),
(int)libusb_get_device_address(dev));
goto shin;
@@ -159,7 +159,7 @@ reinit:
if ((err = usb_write(bitforce, BITFORCE_IDENTIFY, BITFORCE_IDENTIFY_LEN, &amount, C_REQUESTIDENTIFY)) < 0 || amount != BITFORCE_IDENTIFY_LEN) {
applog(LOG_ERR, "%s detect (%s) send identify request failed (%d:%d)",
- bitforce->api->dname, devpath, amount, err);
+ bitforce->drv->dname, devpath, amount, err);
goto unshin;
}
@@ -168,7 +168,7 @@ reinit:
if (++init_count <= REINIT_COUNT) {
if (init_count < 2) {
applog(LOG_WARNING, "%s detect (%s) 1st init failed - retrying (%d:%d)",
- bitforce->api->dname, devpath, amount, err);
+ bitforce->drv->dname, devpath, amount, err);
}
nmsleep(REINIT_TIME_MS);
goto reinit;
@@ -176,14 +176,14 @@ reinit:
if (init_count > 0)
applog(LOG_WARNING, "%s detect (%s) init failed %d times",
- bitforce->api->dname, devpath, init_count);
+ bitforce->drv->dname, devpath, init_count);
if (err < 0) {
applog(LOG_ERR, "%s detect (%s) error identify reply (%d:%d)",
- bitforce->api->dname, devpath, amount, err);
+ bitforce->drv->dname, devpath, amount, err);
} else {
applog(LOG_ERR, "%s detect (%s) empty identify reply (%d)",
- bitforce->api->dname, devpath, amount);
+ bitforce->drv->dname, devpath, amount);
}
goto unshin;
@@ -192,7 +192,7 @@ reinit:
if (unlikely(!strstr(buf, "SHA256"))) {
applog(LOG_ERR, "%s detect (%s) didn't recognise '%s'",
- bitforce->api->dname, devpath, buf);
+ bitforce->drv->dname, devpath, buf);
goto unshin;
}
@@ -205,7 +205,7 @@ reinit:
// We have a real BitForce!
applog(LOG_DEBUG, "%s (%s) identified as: '%s'",
- bitforce->api->dname, devpath, bitforce->name);
+ bitforce->drv->dname, devpath, bitforce->name);
/* Initially enable support for nonce range and disable it later if it
* fails */
@@ -247,7 +247,7 @@ shin:
static void bitforce_detect(void)
{
- usb_detect(&bitforce_api, bitforce_detect_one);
+ usb_detect(&bitforce_drv, bitforce_detect_one);
}
static void get_bitforce_statline_before(char *buf, struct cgpu_info *bitforce)
@@ -288,7 +288,7 @@ static void bitforce_flash_led(struct cgpu_info *bitforce)
if ((err = usb_write(bitforce, BITFORCE_FLASH, BITFORCE_FLASH_LEN, &amount, C_REQUESTFLASH)) < 0 || amount != BITFORCE_FLASH_LEN) {
applog(LOG_ERR, "%s%i: flash request failed (%d:%d)",
- bitforce->api->name, bitforce->device_id, amount, err);
+ bitforce->drv->name, bitforce->device_id, amount, err);
} else {
/* However, this stops anything else getting a reply
* So best to delay any other access to the BFL */
@@ -328,7 +328,7 @@ static bool bitforce_get_temp(struct cgpu_info *bitforce)
if ((err = usb_write(bitforce, BITFORCE_TEMPERATURE, BITFORCE_TEMPERATURE_LEN, &amount, C_REQUESTTEMPERATURE)) < 0 || amount != BITFORCE_TEMPERATURE_LEN) {
mutex_unlock(&bitforce->device_mutex);
applog(LOG_ERR, "%s%i: Error: Request temp invalid/timed out (%d:%d)",
- bitforce->api->name, bitforce->device_id, amount, err);
+ bitforce->drv->name, bitforce->device_id, amount, err);
bitforce->hw_errors++;
return false;
}
@@ -337,10 +337,10 @@ static bool bitforce_get_temp(struct cgpu_info *bitforce)
mutex_unlock(&bitforce->device_mutex);
if (err < 0) {
applog(LOG_ERR, "%s%i: Error: Get temp return invalid/timed out (%d:%d)",
- bitforce->api->name, bitforce->device_id, amount, err);
+ bitforce->drv->name, bitforce->device_id, amount, err);
} else {
applog(LOG_ERR, "%s%i: Error: Get temp returned nothing (%d:%d)",
- bitforce->api->name, bitforce->device_id, amount, err);
+ bitforce->drv->name, bitforce->device_id, amount, err);
}
bitforce->hw_errors++;
return false;
@@ -360,7 +360,7 @@ static bool bitforce_get_temp(struct cgpu_info *bitforce)
bitforce->temp = temp;
if (unlikely(bitforce->cutofftemp > 0 && temp > bitforce->cutofftemp)) {
applog(LOG_WARNING, "%s%i: Hit thermal cutoff limit, disabling!",
- bitforce->api->name, bitforce->device_id);
+ bitforce->drv->name, bitforce->device_id);
bitforce->deven = DEV_RECOVER;
dev_error(bitforce, REASON_DEV_THERMAL_CUTOFF);
}
@@ -370,7 +370,7 @@ static bool bitforce_get_temp(struct cgpu_info *bitforce)
* our responses are out of sync and flush the buffer to
* hopefully recover */
applog(LOG_WARNING, "%s%i: Garbled response probably throttling, clearing buffer",
- bitforce->api->name, bitforce->device_id);
+ bitforce->drv->name, bitforce->device_id);
dev_error(bitforce, REASON_DEV_THROTTLE);
/* Count throttling episodes as hardware errors */
bitforce->hw_errors++;
@@ -404,14 +404,14 @@ re_send:
if ((err = usb_write(bitforce, cmd, len, &amount, C_REQUESTSENDWORK)) < 0 || amount != len) {
mutex_unlock(&bitforce->device_mutex);
applog(LOG_ERR, "%s%i: request send work failed (%d:%d)",
- bitforce->api->name, bitforce->device_id, amount, err);
+ bitforce->drv->name, bitforce->device_id, amount, err);
return false;
}
if ((err = usb_ftdi_read_nl(bitforce, buf, sizeof(buf)-1, &amount, C_REQUESTSENDWORKSTATUS)) < 0) {
mutex_unlock(&bitforce->device_mutex);
applog(LOG_ERR, "%s%d: read request send work status failed (%d:%d)",
- bitforce->api->name, bitforce->device_id, amount, err);
+ bitforce->drv->name, bitforce->device_id, amount, err);
return false;
}
@@ -423,14 +423,14 @@ re_send:
mutex_unlock(&bitforce->device_mutex);
if (bitforce->nonce_range) {
applog(LOG_WARNING, "%s%i: Does not support nonce range, disabling",
- bitforce->api->name, bitforce->device_id);
+ bitforce->drv->name, bitforce->device_id);
bitforce->nonce_range = false;
bitforce->sleep_ms *= 5;
bitforce->kname = KNAME_WORK;
goto re_send;
}
applog(LOG_ERR, "%s%i: Error: Send work reports: %s",
- bitforce->api->name, bitforce->device_id, buf);
+ bitforce->drv->name, bitforce->device_id, buf);
return false;
}
@@ -458,14 +458,14 @@ re_send:
if ((err = usb_write(bitforce, (char *)ob, len, &amount, C_SENDWORK)) < 0 || amount != len) {
mutex_unlock(&bitforce->device_mutex);
applog(LOG_ERR, "%s%i: send work failed (%d:%d)",
- bitforce->api->name, bitforce->device_id, amount, err);
+ bitforce->drv->name, bitforce->device_id, amount, err);
return false;
}
if ((err = usb_ftdi_read_nl(bitforce, buf, sizeof(buf)-1, &amount, C_SENDWORKSTATUS)) < 0) {
mutex_unlock(&bitforce->device_mutex);
applog(LOG_ERR, "%s%d: read send work status failed (%d:%d)",
- bitforce->api->name, bitforce->device_id, amount, err);
+ bitforce->drv->name, bitforce->device_id, amount, err);
return false;
}
@@ -474,19 +474,19 @@ re_send:
if (opt_debug) {
s = bin2hex(ob + 8, 44);
applog(LOG_DEBUG, "%s%i: block data: %s",
- bitforce->api->name, bitforce->device_id, s);
+ bitforce->drv->name, bitforce->device_id, s);
free(s);
}
if (amount == 0 || !buf[0]) {
applog(LOG_ERR, "%s%i: Error: Send block data returned empty string/timed out",
- bitforce->api->name, bitforce->device_id);
+ bitforce->drv->name, bitforce->device_id);
return false;
}
if (unlikely(strncasecmp(buf, "OK", 2))) {
applog(LOG_ERR, "%s%i: Error: Send block data reports: %s",
- bitforce->api->name, bitforce->device_id, buf);
+ bitforce->drv->name, bitforce->device_id, buf);
return false;
}
@@ -519,7 +519,7 @@ static int64_t bitforce_get_result(struct thr_info *thr, struct work *work)
if (elapsed.tv_sec >= BITFORCE_LONG_TIMEOUT_S) {
applog(LOG_ERR, "%s%i: took %dms - longer than %dms",
- bitforce->api->name, bitforce->device_id,
+ bitforce->drv->name, bitforce->device_id,
tv_to_ms(elapsed), BITFORCE_LONG_TIMEOUT_MS);
return 0;
}
@@ -535,7 +535,7 @@ static int64_t bitforce_get_result(struct thr_info *thr, struct work *work)
if (elapsed.tv_sec > BITFORCE_TIMEOUT_S) {
applog(LOG_ERR, "%s%i: took %dms - longer than %dms",
- bitforce->api->name, bitforce->device_id,
+ bitforce->drv->name, bitforce->device_id,
tv_to_ms(elapsed), BITFORCE_TIMEOUT_MS);
dev_error(bitforce, REASON_DEV_OVER_HEAT);
@@ -560,7 +560,7 @@ static int64_t bitforce_get_result(struct thr_info *thr, struct work *work)
if (delay_time_ms != bitforce->sleep_ms)
applog(LOG_DEBUG, "%s%i: Wait time changed to: %d, waited %u",
- bitforce->api->name, bitforce->device_id,
+ bitforce->drv->name, bitforce->device_id,
bitforce->sleep_ms, bitforce->wait_ms);
/* Work out the average time taken. Float for calculation, uint for display */
@@ -569,7 +569,7 @@ static int64_t bitforce_get_result(struct thr_info *thr, struct work *work)
}
applog(LOG_DEBUG, "%s%i: waited %dms until %s",
- bitforce->api->name, bitforce->device_id,
+ bitforce->drv->name, bitforce->device_id,
bitforce->wait_ms, buf);
if (!strncasecmp(&buf[2], "-", 1))
return bitforce->nonces; /* No valid nonce found */
@@ -578,7 +578,7 @@ static int64_t bitforce_get_result(struct thr_info *thr, struct work *work)
else if (strncasecmp(buf, "NONCE-FOUND", 11)) {
bitforce->hw_errors++;
applog(LOG_WARNING, "%s%i: Error: Get result reports: %s",
- bitforce->api->name, bitforce->device_id, buf);
+ bitforce->drv->name, bitforce->device_id, buf);
bitforce_initialise(bitforce, true);
return 0;
}
@@ -593,7 +593,7 @@ static int64_t bitforce_get_result(struct thr_info *thr, struct work *work)
if (unlikely(bitforce->nonce_range && (nonce >= work->blk.nonce ||
(work->blk.nonce > 0 && nonce < work->blk.nonce - bitforce->nonces - 1)))) {
applog(LOG_WARNING, "%s%i: Disabling broken nonce range support",
- bitforce->api->name, bitforce->device_id);
+ bitforce->drv->name, bitforce->device_id);
bitforce->nonce_range = false;
work->blk.nonce = 0xffffffff;
bitforce->sleep_ms *= 5;
@@ -643,7 +643,7 @@ static int64_t bitforce_scanhash(struct thr_info *thr, struct work *work, int64_
if (ret == -1) {
ret = 0;
- applog(LOG_ERR, "%s%i: Comms error", bitforce->api->name, bitforce->device_id);
+ applog(LOG_ERR, "%s%i: Comms error", bitforce->drv->name, bitforce->device_id);
dev_error(bitforce, REASON_DEV_COMMS_ERROR);
bitforce->hw_errors++;
/* empty read buffer */
@@ -671,7 +671,7 @@ static bool bitforce_thread_init(struct thr_info *thr)
* so the devices aren't making calls all at the same time. */
wait = thr->id * MAX_START_DELAY_MS;
applog(LOG_DEBUG, "%s%d: Delaying start by %dms",
- bitforce->api->name, bitforce->device_id, wait / 1000);
+ bitforce->drv->name, bitforce->device_id, wait / 1000);
nmsleep(wait);
return true;
@@ -691,10 +691,11 @@ static struct api_data *bitforce_api_stats(struct cgpu_info *cgpu)
return root;
}
-struct device_api bitforce_api = {
+struct device_drv bitforce_drv = {
+ .drv = DRIVER_BITFORCE,
.dname = "bitforce",
.name = "BFL",
- .api_detect = bitforce_detect,
+ .drv_detect = bitforce_detect,
.get_api_stats = bitforce_api_stats,
.get_statline_before = get_bitforce_statline_before,
.get_stats = bitforce_get_stats,
diff --git a/driver-cpu.c b/driver-cpu.c
index 75d9a5a..99c5a3f 100644
--- a/driver-cpu.c
+++ b/driver-cpu.c
@@ -758,7 +758,7 @@ static void cpu_detect()
struct cgpu_info *cgpu;
cgpu = &cpus[i];
- cgpu->api = &cpu_api;
+ cgpu->drv = &cpu_drv;
cgpu->deven = DEV_ENABLED;
cgpu->threads = 1;
cgpu->kname = algo_names[opt_algo];
@@ -843,10 +843,10 @@ CPUSearch:
return last_nonce - first_nonce + 1;
}
-struct device_api cpu_api = {
+struct device_drv cpu_drv = {
.dname = "cpu",
.name = "CPU",
- .api_detect = cpu_detect,
+ .drv_detect = cpu_detect,
.reinit_device = reinit_cpu_device,
.thread_prepare = cpu_thread_prepare,
.can_limit_work = cpu_can_limit_work,
diff --git a/driver-cpu.h b/driver-cpu.h
index e4b4452..361ae5d 100644
--- a/driver-cpu.h
+++ b/driver-cpu.h
@@ -53,7 +53,7 @@ enum sha256_algos {
extern const char *algo_names[];
extern bool opt_usecpu;
-extern struct device_api cpu_api;
+extern struct device_drv cpu_drv;
extern char *set_algo(const char *arg, enum sha256_algos *algo);
extern void show_algo(char buf[OPT_SHOW_LEN], const enum sha256_algos *algo);
diff --git a/driver-icarus.c b/driver-icarus.c
index c979a68..f42e721 100644
--- a/driver-icarus.c
+++ b/driver-icarus.c
@@ -208,7 +208,7 @@ static struct ICARUS_INFO **icarus_info;
//
static int option_offset = -1;
-struct device_api icarus_api;
+struct device_drv icarus_drv;
static void rev(unsigned char *s, size_t l)
{
@@ -571,7 +571,7 @@ static bool icarus_detect_one(const char *devpath)
/* We have a real Icarus! */
struct cgpu_info *icarus;
icarus = calloc(1, sizeof(struct cgpu_info));
- icarus->api = &icarus_api;
+ icarus->drv = &icarus_drv;
icarus->device_path = strdup(devpath);
icarus->device_fd = -1;
icarus->threads = 1;
@@ -609,7 +609,7 @@ static bool icarus_detect_one(const char *devpath)
static void icarus_detect()
{
- serial_detect(&icarus_api, icarus_detect_one);
+ serial_detect(&icarus_drv, icarus_detect_one);
}
static bool icarus_prepare(struct thr_info *thr)
@@ -900,10 +900,11 @@ static void icarus_shutdown(struct thr_info *thr)
do_icarus_close(thr);
}
-struct device_api icarus_api = {
+struct device_drv icarus_drv = {
+ .drv = DRIVER_ICARUS,
.dname = "icarus",
.name = "ICA",
- .api_detect = icarus_detect,
+ .drv_detect = icarus_detect,
.get_api_stats = icarus_api_stats,
.thread_prepare = icarus_prepare,
.scanhash = icarus_scanhash,
diff --git a/driver-modminer.c b/driver-modminer.c
index c48a51b..0868e85 100644
--- a/driver-modminer.c
+++ b/driver-modminer.c
@@ -87,7 +87,7 @@
// Limit when reducing shares_to_good
#define MODMINER_MIN_BACK 12
-struct device_api modminer_api;
+struct device_drv modminer_drv;
// 45 noops sent when detecting, in case the device was left in "start job" reading
static const char NOOP[] = MODMINER_PING "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff";
@@ -100,15 +100,15 @@ static void do_ping(struct cgpu_info *modminer)
// Don't care if it fails
err = usb_write(modminer, (char *)NOOP, sizeof(NOOP)-1, &amount, C_PING);
applog(LOG_DEBUG, "%s%u: flush noop got %d err %d",
- modminer->api->name, modminer->fpgaid, amount, err);
+ modminer->drv->name, modminer->fpgaid, amount, err);
// Clear any outstanding data
while ((err = usb_read(modminer, buf, sizeof(buf)-1, &amount, C_CLEAR)) == 0 && amount > 0)
applog(LOG_DEBUG, "%s%u: clear got %d",
- modminer->api->name, modminer->fpgaid, amount);
+ modminer->drv->name, modminer->fpgaid, amount);
applog(LOG_DEBUG, "%s%u: final clear got %d err %d",
- modminer->api->name, modminer->fpgaid, amount, err);
+ modminer->drv->name, modminer->fpgaid, amount, err);
}
static bool modminer_detect_one(struct libusb_device *dev, struct usb_find_devices *found)
@@ -121,7 +121,7 @@ static bool modminer_detect_one(struct libusb_device *dev, struct usb_find_devic
struct cgpu_info *modminer = NULL;
modminer = calloc(1, sizeof(*modminer));
- modminer->api = &modminer_api;
+ modminer->drv = &modminer_drv;
modminer->modminer_mutex = calloc(1, sizeof(*(modminer->modminer_mutex)));
mutex_init(modminer->modminer_mutex);
modminer->fpgaid = (char)0;
@@ -182,7 +182,7 @@ static bool modminer_detect_one(struct libusb_device *dev, struct usb_find_devic
for (i = 0; i < buf[0]; i++) {
struct cgpu_info *tmp = calloc(1, sizeof(*tmp));
- tmp->api = modminer->api;
+ tmp->drv = modminer->drv;
tmp->name = devname;
sprintf(devpath, "%d:%d:%d",
@@ -233,7 +233,7 @@ shin:
static void modminer_detect()
{
- usb_detect(&modminer_api, modminer_detect_one);
+ usb_detect(&modminer_drv, modminer_detect_one);
}
static bool get_expect(struct cgpu_info *modminer, FILE *f, char c)
@@ -242,13 +242,13 @@ static bool get_expect(struct cgpu_info *modminer, FILE *f, char c)
if (fread(&buf, 1, 1, f) != 1) {
applog(LOG_ERR, "%s%u: Error (%d) reading bitstream (%c)",
- modminer->api->name, modminer->device_id, errno, c);
+ modminer->drv->name, modminer->device_id, errno, c);
return false;
}
if (buf != c) {
applog(LOG_ERR, "%s%u: firmware code mismatch (%c)",
- modminer->api->name, modminer->device_id, c);
+ modminer->drv->name, modminer->device_id, c);
return false;
}
@@ -262,7 +262,7 @@ static bool get_info(struct cgpu_info *modminer, FILE *f, char *buf, int bufsiz,
if (fread(siz, 2, 1, f) != 1) {
applog(LOG_ERR, "%s%u: Error (%d) reading bitstream '%s' len",
- modminer->api->name, modminer->device_id, errno, name);
+ modminer->drv->name, modminer->device_id, errno, name);
return false;
}
@@ -270,13 +270,13 @@ static bool get_info(struct cgpu_info *modminer, FILE *f, char *buf, int bufsiz,
if (len >= bufsiz) {
applog(LOG_ERR, "%s%u: Bitstream '%s' len too large (%d)",
- modminer->api->name, modminer->device_id, name, len);
+ modminer->drv->name, modminer->device_id, name, len);
return false;
}
if (fread(buf, len, 1, f) != 1) {
applog(LOG_ERR, "%s%u: Error (%d) reading bitstream '%s'", errno,
- modminer->api->name, modminer->device_id, errno, name);
+ modminer->drv->name, modminer->device_id, errno, name);
return false;
}
@@ -302,7 +302,7 @@ static bool get_status_timeout(struct cgpu_info *modminer, char *msg, unsigned i
mutex_unlock(modminer->modminer_mutex);
applog(LOG_ERR, "%s%u: Error (%d:%d) getting %s reply",
- modminer->api->name, modminer->device_id, amount, err, msg);
+ modminer->drv->name, modminer->device_id, amount, err, msg);
return false;
}
@@ -311,7 +311,7 @@ static bool get_status_timeout(struct cgpu_info *modminer, char *msg, unsigned i
mutex_unlock(modminer->modminer_mutex);
applog(LOG_ERR, "%s%u: Error, invalid %s reply (was %d should be 1)",
- modminer->api->name, modminer->device_id, msg, buf[0]);
+ modminer->drv->name, modminer->device_id, msg, buf[0]);
return false;
}
@@ -343,7 +343,7 @@ static bool modminer_fpga_upload_bitstream(struct cgpu_info *modminer)
mutex_unlock(modminer->modminer_mutex);
applog(LOG_ERR, "%s%u: Error (%d) opening bitstream file %s",
- modminer->api->name, modminer->device_id, errno, bsfile);
+ modminer->drv->name, modminer->device_id, errno, bsfile);
return false;
}
@@ -352,7 +352,7 @@ static bool modminer_fpga_upload_bitstream(struct cgpu_info *modminer)
mutex_unlock(modminer->modminer_mutex);
applog(LOG_ERR, "%s%u: Error (%d) reading bitstream magic",
- modminer->api->name, modminer->device_id, errno);
+ modminer->drv->name, modminer->device_id, errno);
goto dame;
}
@@ -361,7 +361,7 @@ static bool modminer_fpga_upload_bitstream(struct cgpu_info *modminer)
mutex_unlock(modminer->modminer_mutex);
applog(LOG_ERR, "%s%u: bitstream has incorrect magic (%u,%u) instead of (%u,%u)",
- modminer->api->name, modminer->device_id,
+ modminer->drv->name, modminer->device_id,
buf[0], buf[1],
BITSTREAM_MAGIC_0, BITSTREAM_MAGIC_1);
@@ -372,7 +372,7 @@ static bool modminer_fpga_upload_bitstream(struct cgpu_info *modminer)
mutex_unlock(modminer->modminer_mutex);
applog(LOG_ERR, "%s%u: Error (%d) bitstream seek failed",
- modminer->api->name, modminer->device_id, errno);
+ modminer->drv->name, modminer->device_id, errno);
goto dame;
}
@@ -384,7 +384,7 @@ static bool modminer_fpga_upload_bitstream(struct cgpu_info *modminer)
goto undame;
applog(LOG_DEBUG, "%s%u: bitstream file '%s' info:",
- modminer->api->name, modminer->device_id, bsfile);
+ modminer->drv->name, modminer->device_id, bsfile);
applog(LOG_DEBUG, " Design name: '%s'", buf);
@@ -399,7 +399,7 @@ static bool modminer_fpga_upload_bitstream(struct cgpu_info *modminer)
mutex_unlock(modminer->modminer_mutex);
applog(LOG_ERR, "%s%u: Bad usercode in bitstream file",
- modminer->api->name, modminer->device_id);
+ modminer->drv->name, modminer->device_id);
goto dame;
}
@@ -408,7 +408,7 @@ static bool modminer_fpga_upload_bitstream(struct cgpu_info *modminer)
mutex_unlock(modminer->modminer_mutex);
applog(LOG_ERR, "%s%u: bitstream doesn't support user code",
- modminer->api->name, modminer->device_id);
+ modminer->drv->name, modminer->device_id);
goto dame;
}
@@ -446,7 +446,7 @@ static bool modminer_fpga_upload_bitstream(struct cgpu_info *modminer)
mutex_unlock(modminer->modminer_mutex);
applog(LOG_ERR, "%s%u: Error (%d) reading bitstream data len",
- modminer->api->name, modminer->device_id, errno);
+ modminer->drv->name, modminer->device_id, errno);
goto dame;
}
@@ -460,7 +460,7 @@ static bool modminer_fpga_upload_bitstream(struct cgpu_info *modminer)
*ptr = '\0';
applog(LOG_WARNING, "%s%u: Programming all FPGA on %s ... Mining will not start until complete",
- modminer->api->name, modminer->device_id, devmsg);
+ modminer->drv->name, modminer->device_id, devmsg);
buf[0] = MODMINER_PROGRAM;
buf[1] = fpgaid;
@@ -473,7 +473,7 @@ static bool modminer_fpga_upload_bitstream(struct cgpu_info *modminer)
mutex_unlock(modminer->modminer_mutex);
applog(LOG_ERR, "%s%u: Program init failed (%d:%d)",
- modminer->api->name, modminer->device_id, amount, err);
+ modminer->drv->name, modminer->device_id, amount, err);
goto dame;
}
@@ -492,7 +492,7 @@ static bool modminer_fpga_upload_bitstream(struct cgpu_info *modminer)
mutex_unlock(modminer->modminer_mutex);
applog(LOG_ERR, "%s%u: bitstream file read error %d (%d bytes left)",
- modminer->api->name, modminer->device_id, errno, len);
+ modminer->drv->name, modminer->device_id, errno, len);
goto dame;
}
@@ -507,7 +507,7 @@ static bool modminer_fpga_upload_bitstream(struct cgpu_info *modminer)
if (opt_debug)
applog(LOG_DEBUG, "%s%u: Program timeout (%d:%d) sent %d tries %d",
- modminer->api->name, modminer->device_id,
+ modminer->drv->name, modminer->device_id,
amount, err, remaining, tries);
if (!get_status(modminer, "write status", C_PROGRAMSTATUS2))
@@ -517,7 +517,7 @@ static bool modminer_fpga_upload_bitstream(struct cgpu_info *modminer)
mutex_unlock(modminer->modminer_mutex);
applog(LOG_ERR, "%s%u: Program failed (%d:%d) sent %d",
- modminer->api->name, modminer->device_id, amount, err, remaining);
+ modminer->drv->name, modminer->device_id, amount, err, remaining);
goto dame;
}
@@ -532,7 +532,7 @@ static bool modminer_fpga_upload_bitstream(struct cgpu_info *modminer)
if (upto >= nextmsg) {
applog(LOG_WARNING,
"%s%u: Programming %.1f%% (%d out of %d)",
- modminer->api->name, modminer->device_id, upto*100, (totlen - len), totlen);
+ modminer->drv->name, modminer->device_id, upto*100, (totlen - len), totlen);
nextmsg += 0.1;
}
@@ -542,7 +542,7 @@ static bool modminer_fpga_upload_bitstream(struct cgpu_info *modminer)
goto undame;
applog(LOG_WARNING, "%s%u: Programming completed for all FPGA on %s",
- modminer->api->name, modminer->device_id, devmsg);
+ modminer->drv->name, modminer->device_id, devmsg);
// Give it a 2/3s delay after programming
nmsleep(666);
@@ -653,7 +653,7 @@ static const char *modminer_delta_clock(struct thr_info *thr, int delta, bool te
mutex_unlock(modminer->modminer_mutex);
applog(LOG_ERR, "%s%u: Error writing set clock speed (%d:%d)",
- modminer->api->name, modminer->device_id, amount, err);
+ modminer->drv->name, modminer->device_id, amount, err);
return clocksetfail;
}
@@ -662,7 +662,7 @@ static const char *modminer_delta_clock(struct thr_info *thr, int delta, bool te
mutex_unlock(modminer->modminer_mutex);
applog(LOG_ERR, "%s%u: Error reading set clock speed (%d:%d)",
- modminer->api->name, modminer->device_id, amount, err);
+ modminer->drv->name, modminer->device_id, amount, err);
return clockreplyfail;
}
@@ -670,7 +670,7 @@ static const char *modminer_delta_clock(struct thr_info *thr, int delta, bool te
mutex_unlock(modminer->modminer_mutex);
applog(LOG_WARNING, "%s%u: Set clock speed %sto %u",
- modminer->api->name, modminer->device_id,
+ modminer->drv->name, modminer->device_id,
(delta < 0) ? "down " : (delta > 0 ? "up " : ""),
modminer->clock);
@@ -691,7 +691,7 @@ static bool modminer_fpga_init(struct thr_info *thr)
mutex_unlock(modminer->modminer_mutex);
applog(LOG_ERR, "%s%u: Error requesting USER code (%d:%d)",
- modminer->api->name, modminer->device_id, amount, err);
+ modminer->drv->name, modminer->device_id, amount, err);
return false;
}
@@ -700,14 +700,14 @@ static bool modminer_fpga_init(struct thr_info *thr)
mutex_unlock(modminer->modminer_mutex);
applog(LOG_ERR, "%s%u: Error reading USER code (%d:%d)",
- modminer->api->name, modminer->device_id, amount, err);
+ modminer->drv->name, modminer->device_id, amount, err);
return false;
}
if (memcmp(buf, BISTREAM_USER_ID, 4)) {
applog(LOG_ERR, "%s%u: FPGA not programmed",
- modminer->api->name, modminer->device_id);
+ modminer->drv->name, modminer->device_id);
if (!modminer_fpga_upload_bitstream(modminer))
return false;
@@ -717,7 +717,7 @@ static bool modminer_fpga_init(struct thr_info *thr)
mutex_unlock(modminer->modminer_mutex);
applog(LOG_DEBUG, "%s%u: FPGA is already programmed :)",
- modminer->api->name, modminer->device_id);
+ modminer->drv->name, modminer->device_id);
}
modminer->clock = MODMINER_DEF_CLOCK;
@@ -773,7 +773,7 @@ static bool modminer_start_work(struct thr_info *thr)
mutex_unlock(modminer->modminer_mutex);
applog(LOG_ERR, "%s%u: Start work failed (%d:%d)",
- modminer->api->name, modminer->device_id, amount, err);
+ modminer->drv->name, modminer->device_id, amount, err);
return false;
}
@@ -827,14 +827,14 @@ static void check_temperature(struct thr_info *thr)
if (modminer->temp < MODMINER_RECOVER_TEMP) {
state->overheated = false;
applog(LOG_WARNING, "%s%u: Recovered, temp less than (%.1f) now %.3f",
- modminer->api->name, modminer->device_id,
+ modminer->drv->name, modminer->device_id,
MODMINER_RECOVER_TEMP, modminer->temp);
}
}
else if (modminer->temp >= MODMINER_OVERHEAT_TEMP) {
if (modminer->temp >= MODMINER_CUTOFF_TEMP) {
applog(LOG_WARNING, "%s%u: Hit thermal cutoff limit! (%.1f) at %.3f",
- modminer->api->name, modminer->device_id,
+ modminer->drv->name, modminer->device_id,
MODMINER_CUTOFF_TEMP, modminer->temp);
modminer_delta_clock(thr, MODMINER_CLOCK_CUTOFF, true, false);
@@ -842,7 +842,7 @@ static void check_temperature(struct thr_info *thr)
dev_error(modminer, REASON_DEV_THERMAL_CUTOFF);
} else {
applog(LOG_WARNING, "%s%u: Overheat limit (%.1f) reached %.3f",
- modminer->api->name, modminer->device_id,
+ modminer->drv->name, modminer->device_id,
MODMINER_OVERHEAT_TEMP, modminer->temp);
// If it's defined to be 0 then don't call modminer_delta_clock()
@@ -909,7 +909,7 @@ static uint64_t modminer_process_results(struct thr_info *thr)
}
applog(LOG_ERR, "%s%u: Error sending (get nonce) (%d:%d)",
- modminer->api->name, modminer->device_id, amount, err);
+ modminer->drv->name, modminer->device_id, amount, err);
return -1;
}
@@ -936,7 +936,7 @@ static uint64_t modminer_process_results(struct thr_info *thr)
}
applog(LOG_ERR, "%s%u: Error reading (get nonce) (%d:%d)",
- modminer->api->name, modminer->device_id, amount+amount2, err);
+ modminer->drv->name, modminer->device_id, amount+amount2, err);
}
if (memcmp(&nonce, "\xff\xff\xff\xff", 4)) {
@@ -975,7 +975,7 @@ static uint64_t modminer_process_results(struct thr_info *thr)
if (state->death_stage_one) {
modminer_delta_clock(thr, MODMINER_CLOCK_DEAD, false, true);
applog(LOG_ERR, "%s%u: DEATH clock down",
- modminer->api->name, modminer->device_id);
+ modminer->drv->name, modminer->device_id);
// reset the death info and DISABLE it
state->last_nonce.tv_sec = 0;
@@ -985,7 +985,7 @@ static uint64_t modminer_process_results(struct thr_info *thr)
} else {
modminer_delta_clock(thr, MODMINER_CLOCK_DEAD, false, true);
applog(LOG_ERR, "%s%u: death clock down",
- modminer->api->name, modminer->device_id);
+ modminer->drv->name, modminer->device_id);
state->death_stage_one = true;
}
@@ -1141,10 +1141,11 @@ static char *modminer_set_device(struct cgpu_info *modminer, char *option, char
return replybuf;
}
-struct device_api modminer_api = {
+struct device_drv modminer_drv = {
+ .drv = DRIVER_MODMINER,
.dname = "modminer",
.name = "MMQ",
- .api_detect = modminer_detect,
+ .drv_detect = modminer_detect,
.get_statline_before = get_modminer_statline_before,
.set_device = modminer_set_device,
.thread_prepare = modminer_fpga_prepare,
diff --git a/driver-opencl.c b/driver-opencl.c
index 01e7019..966d8cd 100644
--- a/driver-opencl.c
+++ b/driver-opencl.c
@@ -50,24 +50,24 @@ extern int gpur_thr_id;
extern bool opt_noadl;
extern bool have_opencl;
-
-
extern void *miner_thread(void *userdata);
extern int dev_from_id(int thr_id);
extern void tailsprintf(char *f, const char *fmt, ...);
extern void wlog(const char *f, ...);
extern void decay_time(double *f, double fadd);
-
/**********************************************/
+#ifdef HAVE_OPENCL
+struct device_drv opencl_drv;
+#endif
+
#ifdef HAVE_ADL
extern float gpu_temp(int gpu);
extern int gpu_fanspeed(int gpu);
extern int gpu_fanpercent(int gpu);
#endif
-
#ifdef HAVE_OPENCL
char *set_vector(char *arg)
{
@@ -591,28 +591,20 @@ char *set_intensity(char *arg)
return NULL;
}
-#endif
-
-
-#ifdef HAVE_OPENCL
-struct device_api opencl_api;
char *print_ndevs_and_exit(int *ndevs)
{
opt_log_output = true;
- opencl_api.api_detect();
+ opencl_drv.drv_detect();
clear_adl(*ndevs);
applog(LOG_INFO, "%i GPU devices max detected", *ndevs);
exit(*ndevs);
}
#endif
-
struct cgpu_info gpus[MAX_GPUDEVICES]; /* Maximum number apparently possible */
struct cgpu_info *cpus;
-
-
#ifdef HAVE_OPENCL
/* In dynamic mode, only the first thread of each device will be in use.
@@ -637,9 +629,6 @@ void pause_dynamic_threads(int gpu)
}
}
-
-struct device_api opencl_api;
-
#endif /* HAVE_OPENCL */
#if defined(HAVE_OPENCL) && defined(HAVE_CURSES)
@@ -773,7 +762,7 @@ retry:
for (i = 0; i < mining_threads; ++i) {
thr = &thr_info[i];
cgpu = thr->cgpu;
- if (cgpu->api != &opencl_api)
+ if (cgpu->drv->drv != DRIVER_OPENCL)
continue;
if (dev_from_id(i) != selected)
continue;
@@ -1160,7 +1149,7 @@ select_cgpu:
for (thr_id = 0; thr_id < mining_threads; ++thr_id) {
thr = &thr_info[thr_id];
cgpu = thr->cgpu;
- if (cgpu->api != &opencl_api)
+ if (cgpu->drv->drv != DRIVER_OPENCL)
continue;
if (dev_from_id(thr_id) != gpu)
continue;
@@ -1185,7 +1174,7 @@ select_cgpu:
thr = &thr_info[thr_id];
cgpu = thr->cgpu;
- if (cgpu->api != &opencl_api)
+ if (cgpu->drv->drv != DRIVER_OPENCL)
continue;
if (dev_from_id(thr_id) != gpu)
continue;
@@ -1222,7 +1211,7 @@ select_cgpu:
for (thr_id = 0; thr_id < mining_threads; ++thr_id) {
thr = &thr_info[thr_id];
cgpu = thr->cgpu;
- if (cgpu->api != &opencl_api)
+ if (cgpu->drv->drv != DRIVER_OPENCL)
continue;
if (dev_from_id(thr_id) != gpu)
continue;
@@ -1243,8 +1232,6 @@ void *reinit_gpu(__maybe_unused void *userdata)
#ifdef HAVE_OPENCL
-struct device_api opencl_api;
-
static void opencl_detect()
{
int i;
@@ -1263,7 +1250,7 @@ static void opencl_detect()
cgpu = &gpus[i];
cgpu->deven = DEV_ENABLED;
- cgpu->api = &opencl_api;
+ cgpu->drv = &opencl_drv;
cgpu->device_id = i;
cgpu->threads = opt_g_threads;
cgpu->virtual_gpu = i;
@@ -1570,10 +1557,11 @@ static void opencl_thread_shutdown(struct thr_info *thr)
clReleaseContext(clState->context);
}
-struct device_api opencl_api = {
+struct device_drv opencl_drv = {
+ .drv = DRIVER_OPENCL,
.dname = "opencl",
.name = "GPU",
- .api_detect = opencl_detect,
+ .drv_detect = opencl_detect,
.reinit_device = reinit_opencl_device,
#ifdef HAVE_ADL
.get_statline_before = get_opencl_statline_before,
diff --git a/driver-opencl.h b/driver-opencl.h
index c1d6182..22bd9ec 100644
--- a/driver-opencl.h
+++ b/driver-opencl.h
@@ -30,6 +30,6 @@ extern void pause_dynamic_threads(int gpu);
extern bool have_opencl;
extern int opt_platform_id;
-extern struct device_api opencl_api;
+extern struct device_drv opencl_drv;
#endif /* __DEVICE_GPU_H__ */
diff --git a/driver-ztex.c b/driver-ztex.c
index 23aa97e..4a61a5c 100644
--- a/driver-ztex.c
+++ b/driver-ztex.c
@@ -30,7 +30,7 @@
#define GOLDEN_BACKLOG 5
-struct device_api ztex_api;
+struct device_drv ztex_drv;
// Forward declarations
static void ztex_disable(struct thr_info* thr);
@@ -68,7 +68,7 @@ static void ztex_detect(void)
for (i = 0; i < cnt; i++) {
ztex = calloc(1, sizeof(struct cgpu_info));
- ztex->api = &ztex_api;
+ ztex->drv = &ztex_drv;
ztex->device_ztex = ztex_devices[i]->dev;
ztex->threads = 1;
ztex->device_ztex->fpgaNum = 0;
@@ -82,7 +82,7 @@ static void ztex_detect(void)
for (j = 1; j < fpgacount; j++) {
ztex = calloc(1, sizeof(struct cgpu_info));
- ztex->api = &ztex_api;
+ ztex->drv = &ztex_drv;
ztex_slave = calloc(1, sizeof(struct libztex_device));
memcpy(ztex_slave, ztex_devices[i]->dev, sizeof(struct libztex_device));
ztex->device_ztex = ztex_slave;
@@ -394,10 +394,10 @@ static void ztex_disable(struct thr_info *thr)
ztex_shutdown(thr);
}
-struct device_api ztex_api = {
+struct device_drv ztex_drv = {
.dname = "ztex",
.name = "ZTX",
- .api_detect = ztex_detect,
+ .drv_detect = ztex_detect,
.get_statline_before = ztex_statline_before,
.thread_prepare = ztex_prepare,
.scanhash = ztex_scanhash,
diff --git a/findnonce.c b/findnonce.c
index bf39a12..fcf75f2 100644
--- a/findnonce.c
+++ b/findnonce.c
@@ -204,7 +204,7 @@ static void *postcalc_hash(void *userdata)
* end of the res[] array */
if (unlikely(pcd->res[FOUND] & ~FOUND)) {
applog(LOG_WARNING, "%s%d: invalid nonce count - HW error",
- thr->cgpu->api->name, thr->cgpu->device_id);
+ thr->cgpu->drv->name, thr->cgpu->device_id);
hw_errors++;
thr->cgpu->hw_errors++;
pcd->res[FOUND] &= FOUND;
diff --git a/fpgautils.c b/fpgautils.c
index 487395c..307bec4 100644
--- a/fpgautils.c
+++ b/fpgautils.c
@@ -104,14 +104,14 @@ int serial_autodetect_devserial(__maybe_unused detectone_func_t detectone, __may
#endif
}
-int _serial_detect(struct device_api *api, detectone_func_t detectone, autoscan_func_t autoscan, bool forceauto)
+int _serial_detect(struct device_drv *drv, detectone_func_t detectone, autoscan_func_t autoscan, bool forceauto)
{
struct string_elist *iter, *tmp;
const char *dev, *colon;
bool inhibitauto = false;
char found = 0;
- size_t namel = strlen(api->name);
- size_t dnamel = strlen(api->dname);
+ size_t namel = strlen(drv->name);
+ size_t dnamel = strlen(drv->dname);
list_for_each_entry_safe(iter, tmp, &scan_devices, list) {
dev = iter->string;
@@ -119,8 +119,8 @@ int _serial_detect(struct device_api *api, detectone_func_t detectone, autoscan_
size_t idlen = colon - dev;
// allow either name:device or dname:device
- if ((idlen != namel || strncasecmp(dev, api->name, idlen))
- && (idlen != dnamel || strncasecmp(dev, api->dname, idlen)))
+ if ((idlen != namel || strncasecmp(dev, drv->name, idlen))
+ && (idlen != dnamel || strncasecmp(dev, drv->dname, idlen)))
continue;
dev = colon + 1;
diff --git a/fpgautils.h b/fpgautils.h
index 1802548..b979b6c 100644
--- a/fpgautils.h
+++ b/fpgautils.h
@@ -16,13 +16,13 @@
typedef bool(*detectone_func_t)(const char*);
typedef int(*autoscan_func_t)();
-extern int _serial_detect(struct device_api *api, detectone_func_t, autoscan_func_t, bool force_autoscan);
-#define serial_detect_fauto(api, detectone, autoscan) \
- _serial_detect(api, detectone, autoscan, true)
-#define serial_detect_auto(api, detectone, autoscan) \
- _serial_detect(api, detectone, autoscan, false)
-#define serial_detect(api, detectone) \
- _serial_detect(api, detectone, NULL, false)
+extern int _serial_detect(struct device_drv *drv, detectone_func_t, autoscan_func_t, bool force_autoscan);
+#define serial_detect_fauto(drv, detectone, autoscan) \
+ _serial_detect(drv, detectone, autoscan, true)
+#define serial_detect_auto(drv, detectone, autoscan) \
+ _serial_detect(drv, detectone, autoscan, false)
+#define serial_detect(drv, detectone) \
+ _serial_detect(drv, detectone, NULL, false)
extern int serial_autodetect_devserial(detectone_func_t, const char *prodname);
extern int serial_autodetect_udev(detectone_func_t, const char *prodname);
diff --git a/miner.h b/miner.h
index d892ed0..4e888f3 100644
--- a/miner.h
+++ b/miner.h
@@ -196,6 +196,15 @@ static inline int fsync (int fd)
#endif
#endif
+enum drv_driver {
+ DRIVER_OPENCL,
+ DRIVER_ICARUS,
+ DRIVER_BITFORCE,
+ DRIVER_MODMINER,
+ DRIVER_ZTEX,
+ DRIVER_CPU,
+};
+
enum alive {
LIFE_WELL,
LIFE_SICK,
@@ -263,12 +272,14 @@ struct api_data;
struct thr_info;
struct work;
-struct device_api {
+struct device_drv {
+ enum drv_driver drv;
+
char *dname;
char *name;
- // API-global functions
- void (*api_detect)();
+ // DRV-global functions
+ void (*drv_detect)();
// Device-specific functions
void (*reinit_device)(struct cgpu_info *);
@@ -365,7 +376,7 @@ struct cgminer_pool_stats {
struct cgpu_info {
int cgminer_id;
- struct device_api *api;
+ struct device_drv *drv;
int device_id;
char *name;
char *device_path;
diff --git a/usbutils.c b/usbutils.c
index 0d9e79a..bebd722 100644
--- a/usbutils.c
+++ b/usbutils.c
@@ -99,15 +99,15 @@ static struct usb_find_devices find_dev[] = {
};
#ifdef USE_BITFORCE
-extern struct device_api bitforce_api;
+extern struct device_drv bitforce_drv;
#endif
#ifdef USE_ICARUS
-extern struct device_api icarus_api;
+extern struct device_drv icarus_drv;
#endif
#ifdef USE_MODMINER
-extern struct device_api modminer_api;
+extern struct device_drv modminer_drv;
#endif
/*
@@ -907,7 +907,7 @@ dame:
return false;
}
-static bool usb_check_device(struct device_api *api, struct libusb_device *dev, struct usb_find_devices *look)
+static bool usb_check_device(struct device_drv *drv, struct libusb_device *dev, struct usb_find_devices *look)
{
struct libusb_device_descriptor desc;
int err;
@@ -920,25 +920,25 @@ static bool usb_check_device(struct device_api *api, struct libusb_device *dev,
if (desc.idVendor != look->idVendor || desc.idProduct != look->idProduct) {
applog(LOG_DEBUG, "%s looking for %04x:%04x but found %04x:%04x instead",
- api->name, look->idVendor, look->idProduct, desc.idVendor, desc.idProduct);
+ drv->name, look->idVendor, look->idProduct, desc.idVendor, desc.idProduct);
return false;
}
applog(LOG_DEBUG, "%s looking for and found %04x:%04x",
- api->name, look->idVendor, look->idProduct);
+ drv->name, look->idVendor, look->idProduct);
return true;
}
-static struct usb_find_devices *usb_check_each(int drv, struct device_api *api, struct libusb_device *dev)
+static struct usb_find_devices *usb_check_each(int drvnum, struct device_drv *drv, struct libusb_device *dev)
{
struct usb_find_devices *found;
int i;
for (i = 0; find_dev[i].drv != DRV_LAST; i++)
- if (find_dev[i].drv == drv) {
- if (usb_check_device(api, dev, &(find_dev[i]))) {
+ if (find_dev[i].drv == drvnum) {
+ if (usb_check_device(drv, dev, &(find_dev[i]))) {
found = malloc(sizeof(*found));
memcpy(found, &(find_dev[i]), sizeof(*found));
return found;
@@ -948,27 +948,27 @@ static struct usb_find_devices *usb_check_each(int drv, struct device_api *api,
return NULL;
}
-static struct usb_find_devices *usb_check(__maybe_unused struct device_api *api, __maybe_unused struct libusb_device *dev)
+static struct usb_find_devices *usb_check(__maybe_unused struct device_drv *drv, __maybe_unused struct libusb_device *dev)
{
#ifdef USE_BITFORCE
- if (api == &bitforce_api)
- return usb_check_each(DRV_BITFORCE, api, dev);
+ if (drv->drv == DRIVER_BITFORCE)
+ return usb_check_each(DRV_BITFORCE, drv, dev);
#endif
#ifdef USE_ICARUS
- if (api == &icarus_api)
- return usb_check_each(DRV_ICARUS, api, dev);
+ if (drv->drv == DRIVER_ICARUS)
+ return usb_check_each(DRV_ICARUS, drv, dev);
#endif
#ifdef USE_MODMINER
- if (api == &modminer_api)
- return usb_check_each(DRV_MODMINER, api, dev);
+ if (drv->drv == DRIVER_MODMINER)
+ return usb_check_each(DRV_MODMINER, drv, dev);
#endif
return NULL;
}
-void usb_detect(struct device_api *api, bool (*device_detect)(struct libusb_device *, struct usb_find_devices *))
+void usb_detect(struct device_drv *drv, bool (*device_detect)(struct libusb_device *, struct usb_find_devices *))
{
libusb_device **list;
ssize_t count, i;
@@ -995,7 +995,7 @@ void usb_detect(struct device_api *api, bool (*device_detect)(struct libusb_devi
mutex_unlock(list_lock);
- found = usb_check(api, list[i]);
+ found = usb_check(drv, list[i]);
if (!found)
release_dev(list[i], true);
else
@@ -1106,7 +1106,7 @@ static void newstats(struct cgpu_info *cgpu)
cgpu->usbstat = ++next_stat;
usb_stats = realloc(usb_stats, sizeof(*usb_stats) * next_stat);
- usb_stats[next_stat-1].name = cgpu->api->name;
+ usb_stats[next_stat-1].name = cgpu->drv->name;
usb_stats[next_stat-1].device_id = -1;
usb_stats[next_stat-1].details = calloc(1, sizeof(struct cg_usb_stats_details) * C_MAX * 2);
for (i = 1; i < C_MAX * 2; i += 2)
diff --git a/usbutils.h b/usbutils.h
index 156e2a2..2ee8615 100644
--- a/usbutils.h
+++ b/usbutils.h
@@ -116,12 +116,12 @@ enum usb_cmds {
C_MAX
};
-struct device_api;
+struct device_drv;
struct cgpu_info;
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_api *api, bool (*device_detect)(struct libusb_device *, struct usb_find_devices *));
+void usb_detect(struct device_drv *drv, bool (*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 ep, char *buf, size_t bufsiz, int *processed, unsigned int timeout, int eol, enum usb_cmds, bool ftdi);