Commit f49a3c76574dc90a004ebf63720044109bf67e0d

Con Kolivas 2013-09-30T08:43:29

Merge branch 'master' into hashfast Conflicts: Makefile.am api.c cgminer.c configure.ac miner.h usbutils.c usbutils.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
diff --git a/01-cgminer.rules b/01-cgminer.rules
index f3a488a..24211b4 100644
--- a/01-cgminer.rules
+++ b/01-cgminer.rules
@@ -18,3 +18,6 @@ ATTRS{idVendor}=="067b", ATTRS{idProduct}=="0230", SUBSYSTEMS=="usb", ACTION=="a
 
 # Ztex
 ATTRS{idVendor}=="221a", ATTRS{idProduct}=="0100", SUBSYSTEMS=="usb", ACTION=="add", MODE="0666", GROUP="plugdev"
+
+# BF1
+ATTRS{idVendor}=="03eb", ATTRS{idProduct}=="204b", SUBSYSTEMS=="usb", ACTION=="add", MODE="0666", GROUP="plugdev"
diff --git a/ASIC-README b/ASIC-README
index e485032..4da05ab 100644
--- a/ASIC-README
+++ b/ASIC-README
@@ -1,10 +1,10 @@
 SUPPORTED DEVICES
 
 Currently supported devices include the Avalon (including BitBurner), the
-Butterfly Labs SC range of devices and the ASICMINER block erupters. 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 be
-disconnected when cgminer is running.
+Butterfly Labs SC range of devices, the ASICMINER block erupters and the BPMC
+BF1 (bitfury) USB devices. No COM ports on windows or TTY devices will be used
+by cgminer as it communicates directly with them via USB so it is normal for
+them to not exist or be disconnected when cgminer is running.
 
 
 The BFL devices should come up as one of the following:
@@ -24,7 +24,18 @@ ASICMINER block erupters will come up as AMU.
 
 ASICMINER devices need the --enable-icarus option when compiling cgminer.
 Also note that the AMU is managed by the Icarus driver which is detailed
-in the FPGA-README
+in the FPGA-README. Configuring them uses the same mechanism as outlined
+below for getting started with butterfly labs ASICs.
+
+
+BITFURY devices
+
+Bitfury devices need the --enable-bitfury option when compiling cgminer.
+
+Currently only the BPMC BF1 devices AKA redfury/bluefury are supported and
+come up as BF1. There are no options available for them. Bitfury device are
+also set up as per the butterfly labs ASICs below.
+
 
 
 GETTING STARTED WITH BUTTERFLY LABS ASICS
diff --git a/Makefile.am b/Makefile.am
index 6097f14..01ba36f 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -86,6 +86,14 @@ if HAS_HASHFAST
 cgminer_SOURCES += driver-hashfast.c driver-hashfast.h
 endif
 
+if HAS_BITFURY
+cgminer_SOURCES += driver-bitfury.c driver-bitfury.h
+endif
+
+if HAS_ICARUS
+cgminer_SOURCES += driver-icarus.c
+endif
+
 if HAS_ICARUS
 cgminer_SOURCES += driver-icarus.c
 endif
diff --git a/NEWS b/NEWS
index 5c7d697..ad19011 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,140 @@
+Version 3.5.0 - 29th September 2013
+
+- Add magic init sequence required on BF1 devices to get them mining on windows.
+- usbinfo.devlock is only ever write locked so convert it to a mutex
+- Icarus remove unneeded opt_debug tests due to applog being a macro
+- Icarus - CMR shouldn't wait the full timeout due to handle sharing
+- We should only yield once in cg_wunlock
+- Provide a function to downgrade a cglock from a write lock to an intermediate
+variant.
+- Deuglify use of _PARSE_COMMANDS macro expansions.
+- Deuglify use of usb parse commands macro in usbutils.
+- Use the driver add commands macros in api.c to avoid individually listing
+them.
+- Separate out asic fpga and opencl drivers in the driver parse commands macro
+for use individually as needed.
+- Use macro expansion in usb_find_devices to avoid explicitly listing them all.
+- Use macro expansion to iterate over all the drivers without explicitly writing
+them out in usbutils.c
+- Iterate over the bitfury offsets in order of decreasing likelihood.
+- Reattach the kernel driver on linux on usb_uninit.
+- Attach the kernel driver on failure to usb init on linux.
+- libusb kernel driver operations are only available on linux.
+- There is no need to get the external prototypes for drivers in cgminer.c any
+more.
+- Remove unnecessary gpu_threads initialisation.
+- Put avalon last in the sequence of adding drivers to prevent it trying to
+claim similar chip devices on startup.
+- Use macro expansion to iterate over all device drivers without needing to
+explicitly code in support in all places. Pass a hotplug bool to the detect()
+function to prevent opencl trying to hogplug GPUs.
+- Forward declare all device drivers in miner.h avoiding the need to export them
+everywhere else.
+- Add a noop function for driver detect when it's missing.
+- Reuse the DRIVER_ macros to avoid having yet another definition for DRV_
+- Use macro expansion to generate extern device_drv prototypes.
+- Create a macro list of drivers to enable easier addition of further drivers.
+- There is no point setting the BF1 preferred packet size to the maximum since
+it will do so automatically.
+- icarus ensure all cmr interfaces are initialised properly
+- usbutils - fix USBDEBUG warnings
+- Remove unnecessary steps in communicating with BF1 and just use USB interface
+1.
+- usbutils - usb_bulk_transfer fix the buf/data fix
+- usb_bulk_transfer - use the allocated buffer
+- Set preferred packet sizes per interface on BF1.
+- usbutils allow PrefPacketSize per endpoint
+- Remove magic control sequences on open/close on BF1 and just flush the read
+buffers.
+- Check return codes in getinfo and reset and fail as needed in BF1.
+- Check return code for bitfury_open and release resources properly on failed
+initialisation.
+- Abstract out flushing of interrupt reads in BF1 devices.
+- Perform interrupt read after close message on BF1 as per serial close.
+- Perform interrupt read flush as per serial open on BF1 devices.
+- Add information for 2nd USB interface on BF1 devices and choose interface 1
+for bulk transfers.
+- usbutils - bulk transfer copy test fix
+- usbutils - add USBDEBUG for usb_bulk_transfer
+- Add more read_ii variants to usbutils.
+- Name remainder of BFU usb commands used.
+- Use submit_tested_work in bitfury driver to avoid unnecessarily re-testing the
+work for validity.
+- Abstract out work submission once it's been tested, to be used by drivers that
+do their own internal validity testing.
+- Store the hash2 array in struct work for further reuse.
+- usbutils - which_intinfo not requried
+- Use the test_nonce function within submit_nonce and store the uint32
+corresponding to hash2 37 for further use.
+- usbutils - interfaces must all be on one handle - ep implies the interface
+- avalon stats use exact type
+- Only set share diff if we've confirmed it's a share first.
+- Update ASIC-README for bitfury devices.
+- Use an array of offsets when checking nonces in bitfury_checkresults
+- Limit the duration we wait for reads in BF1 based on time already elapsed to
+account for other delays such as work restart messages or out of work.
+- Minimise size of serial string we copy in BF1 stats to avoid overflow.
+- Implement basic API stats for BF1 and increase array of results to check for
+the rare straggling result.
+- Space debug output for bf1 to separate from numerals.
+- Abstract out the bitfury open close and reset functions and use them on
+reinit.
+- Rename BF1 devices BF1
+- Check for work restart, breaking out early after usb reads in BF1.
+- Do not lose the first sets of results from BF1.
+- There is no point checking for results from the next round of work on BF1.
+- Last result returned by BF1 is an end of results marker so ignore it.
+- restart_wait should return 0 if thr_restart is true.
+- Remove unused code by bitfury driver since current driver uses serialised
+scanhash.
+- Meter out return of estimated hashes in BF1 to smooth out visible hashrate.
+- Optimise inner scanhash loop for bf1.
+- Add yet another backup work for triple buffering of work in bf1 to account for
+extra late results returned and don't check nonce offsets which appear to never
+return.
+- Name the work request and result usb commands for BF1
+- Define a mandatory upper limit to waiting for reset and data on BF1 based on
+full nonce duration.
+- Decrease usb buffering to verbose logging.
+- Add in first draft for a serialised work model sending/receiving data for BF1
+devices.
+- Add complete close sequence to bf1 as it happens on serial.
+- Provide a bitfury identify function for bf1.
+- Reliably extract BF1 information at startup and reset the device.
+- Add commands for getting BF1 bitfury info
+- Add magic BF1 bitfury open and close control sequences.
+- Add BF1 detection code to bitfury driver.
+- Create basic placeholders for bitfury driver code.
+- Add bf1 device information to usbutils to enable device detection.
+- Add basic defines for building for bitfury devices.
+- Add redfury device to udev rules.
+- avalon: display the FPGA controller version on API
+- pool_active uninitialised_var rolltime
+- Use macro expansion to only need to define usb enums and commands in one
+place.
+- usbutils saving incorrect overflow buffer
+- ignore libusb.la and *.lo on linux
+- icarus support CMR with no extensions
+- usbtils - interfaces dont work yet in libusb windows so disable for that only
+- Provide a --disable-libcurl config option to build support for stratum mining
+only.
+- Fix the api-example.c compile under Linux
+- usbutils - only release the device once - for the first intinfo
+- usbutils set_interface is no longer valid
+- ubsutils interfaces much each have their own handle
+- usbutils kernel_detach should use the interface number
+- usbutils - allow the driver to change which_intinfo
+- Reset quotas on load balance for all pools at the same time to avoid running
+out during selection and unintentionally dropping to fallback.
+- Break out of select pool from a common point for appropriate debug messages
+and to avoid further tests.
+- usbutils correct/reverse CMR product numbers
+- usbutils specifically track handles and interfaces
+- change drivers to use usb_interface() - required for multi interface change
+- usbutils - allow a device to use multiple interfaces (and better var names)
+- Cast -1 to (char) to cope with different default char types on ARM.
+
+
 Version 3.4.3 - 13th September 2013
 
 - Put corefoundation and iokit separate in ldflags for darwin.
diff --git a/api.c b/api.c
index 006e8f9..f5bfd5b 100644
--- a/api.c
+++ b/api.c
@@ -29,7 +29,7 @@
 #include "miner.h"
 #include "util.h"
 
-#if defined(USE_BFLSC) || defined(USE_AVALON) || defined(USE_HASHFAST)
+#if defined(USE_BFLSC) || defined(USE_AVALON) || defined(USE_HASHFAST) || defined(USE_BITFURY)
 #define HAVE_AN_ASIC 1
 #endif
 
@@ -167,8 +167,8 @@ static const char *SCRYPTSTR = "scrypt";
 static const char *SHA256STR = "sha256";
 
 static const char *DEVICECODE = ""
-#ifdef HAVE_OPENCL
-			"GPU "
+#ifdef USE_AVALON
+			"AVA "
 #endif
 #ifdef USE_BFLSC
 			"BAS "
@@ -176,21 +176,24 @@ static const char *DEVICECODE = ""
 #ifdef USE_BITFORCE
 			"BFL "
 #endif
+#ifdef USE_BITFURY
+			"BFU "
+#endif
+#ifdef HAVE_OPENCL
+			"GPU "
+#endif
 #ifdef USE_HASHFAST
 			"HFA "
 #endif
 #ifdef USE_ICARUS
 			"ICA "
 #endif
-#ifdef USE_AVALON
-			"AVA "
+#ifdef USE_MODMINER
+			"MMQ "
 #endif
 #ifdef USE_ZTEX
 			"ZTX "
 #endif
-#ifdef USE_MODMINER
-			"MMQ "
-#endif
 			"";
 
 static const char *OSINFO =
@@ -1211,26 +1214,18 @@ static struct api_data *print_data(struct api_data *root, char *buf, bool isjson
 	return root;
 }
 
+#define DRIVER_COUNT_DRV(X) if (devices[i]->drv->drv_id == DRIVER_##X) \
+	count++;
+
 #ifdef HAVE_AN_ASIC
-static int numascs()
+static int numascs(void)
 {
 	int count = 0;
 	int i;
 
 	rd_lock(&devices_lock);
 	for (i = 0; i < total_devices; i++) {
-#ifdef USE_AVALON
-		if (devices[i]->drv->drv_id == DRIVER_AVALON)
-			count++;
-#endif
-#ifdef USE_BFLSC
-		if (devices[i]->drv->drv_id == DRIVER_BFLSC)
-			count++;
-#endif
-#ifdef USE_HASHFAST
-		if (devices[i]->drv->drv_id == DRIVER_HASHFAST)
-			count++;
-#endif
+		ASIC_PARSE_COMMANDS(DRIVER_COUNT_DRV)
 	}
 	rd_unlock(&devices_lock);
 	return count;
@@ -1243,18 +1238,7 @@ static int ascdevice(int ascid)
 
 	rd_lock(&devices_lock);
 	for (i = 0; i < total_devices; i++) {
-#ifdef USE_AVALON
-		if (devices[i]->drv->drv_id == DRIVER_AVALON)
-			count++;
-#endif
-#ifdef USE_BFLSC
-		if (devices[i]->drv->drv_id == DRIVER_BFLSC)
-			count++;
-#endif
-#ifdef USE_HASHFAST
-		if (devices[i]->drv->drv_id == DRIVER_HASHFAST)
-			count++;
-#endif
+		ASIC_PARSE_COMMANDS(DRIVER_COUNT_DRV)
 		if (count == (ascid + 1))
 			goto foundit;
 	}
@@ -1270,29 +1254,14 @@ foundit:
 #endif
 
 #ifdef HAVE_AN_FPGA
-static int numpgas()
+static int numpgas(void)
 {
 	int count = 0;
 	int i;
 
 	rd_lock(&devices_lock);
 	for (i = 0; i < total_devices; i++) {
-#ifdef USE_BITFORCE
-		if (devices[i]->drv->drv_id == DRIVER_BITFORCE)
-			count++;
-#endif
-#ifdef USE_ICARUS
-		if (devices[i]->drv->drv_id == DRIVER_ICARUS)
-			count++;
-#endif
-#ifdef USE_ZTEX
-		if (devices[i]->drv->drv_id == DRIVER_ZTEX)
-			count++;
-#endif
-#ifdef USE_MODMINER
-		if (devices[i]->drv->drv_id == DRIVER_MODMINER)
-			count++;
-#endif
+		FPGA_PARSE_COMMANDS(DRIVER_COUNT_DRV)
 	}
 	rd_unlock(&devices_lock);
 	return count;
@@ -1305,22 +1274,7 @@ static int pgadevice(int pgaid)
 
 	rd_lock(&devices_lock);
 	for (i = 0; i < total_devices; i++) {
-#ifdef USE_BITFORCE
-		if (devices[i]->drv->drv_id == DRIVER_BITFORCE)
-			count++;
-#endif
-#ifdef USE_ICARUS
-		if (devices[i]->drv->drv_id == DRIVER_ICARUS)
-			count++;
-#endif
-#ifdef USE_ZTEX
-		if (devices[i]->drv->drv_id == DRIVER_ZTEX)
-			count++;
-#endif
-#ifdef USE_MODMINER
-		if (devices[i]->drv->drv_id == DRIVER_MODMINER)
-			count++;
-#endif
+		FPGA_PARSE_COMMANDS(DRIVER_COUNT_DRV)
 		if (count == (pgaid + 1))
 			goto foundit;
 	}
@@ -1770,11 +1724,11 @@ static void pgastatus(struct io_data *io_data, int pga, bool isjson, bool precom
 			dev_runtime = 1.0;
 
 #ifdef USE_ZTEX
-		if (cgpu->drv->drv_id == DRIVER_ZTEX && cgpu->device_ztex)
+		if (cgpu->drv->drv_id == DRIVER_ztex && cgpu->device_ztex)
 			frequency = cgpu->device_ztex->freqM1 * (cgpu->device_ztex->freqM + 1);
 #endif
 #ifdef USE_MODMINER
-		if (cgpu->drv->drv_id == DRIVER_MODMINER)
+		if (cgpu->drv->drv_id == DRIVER_modminer)
 			frequency = cgpu->clock;
 #endif
 
diff --git a/cgminer.c b/cgminer.c
index ac7b07a..5f2afa6 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -123,7 +123,7 @@ bool opt_scrypt;
 #endif
 #endif
 bool opt_restart = true;
-static bool opt_nogpu;
+bool opt_nogpu;
 
 struct list_head scan_devices;
 static bool devices_enabled[MAX_DEVICES];
@@ -1567,6 +1567,9 @@ static char *opt_verusage_and_exit(const char *extra)
 #ifdef USE_BITFORCE
 		"bitforce "
 #endif
+#ifdef USE_BITFURY
+		"bitfury "
+#endif
 #ifdef HAVE_OPENCL
 		"GPU "
 #endif
@@ -3662,15 +3665,6 @@ static void rebuild_hash(struct work *work)
 		scrypt_regenhash(work);
 	else
 		regen_hash(work);
-
-	work->share_diff = share_diff(work);
-	if (unlikely(work->share_diff >= current_diff)) {
-		work->block = true;
-		work->pool->solved++;
-		found_blocks++;
-		work->mandatory = true;
-		applog(LOG_NOTICE, "Found block for pool %d!", work->pool->pool_no);
-	}
 }
 
 static bool cnx_needed(struct pool *pool);
@@ -3848,7 +3842,7 @@ int restart_wait(struct thr_info *thr, unsigned int mstime)
 
 	mutex_lock(&restart_lock);
 	if (thr->work_restart)
-		rc = ETIMEDOUT;
+		rc = 0;
 	else
 		rc = pthread_cond_timedwait(&restart_cond, &restart_lock, &abstime);
 	mutex_unlock(&restart_lock);
@@ -5578,7 +5572,7 @@ static bool pool_active(struct pool *pool, bool pinging)
 	bool ret = false;
 	json_t *val;
 	CURL *curl;
-	int rolltime;
+	int uninitialised_var(rolltime);
 
 	if (pool->has_gbt)
 		applog(LOG_DEBUG, "Retrieving block template from pool %s", pool->rpc_url);
@@ -6020,17 +6014,12 @@ void inc_hw_errors(struct thr_info *thr)
 	thr->cgpu->drv->hw_error(thr);
 }
 
-/* Returns true if nonce for work was a valid share */
-bool submit_nonce(struct thr_info *thr, struct work *work, uint32_t nonce)
+bool test_nonce(struct work *work, uint32_t nonce)
 {
 	uint32_t *work_nonce = (uint32_t *)(work->data + 64 + 12);
-	struct timeval tv_work_found;
-	unsigned char hash2[32];
-	uint32_t *hash2_32 = (uint32_t *)hash2;
+	uint32_t *hash2_32 = (uint32_t *)work->hash2;
 	uint32_t diff1targ;
-	bool ret = true;
 
-	cgtime(&tv_work_found);
 	*work_nonce = htole32(nonce);
 
 	/* Do one last check before attempting to submit the work */
@@ -6038,14 +6027,16 @@ bool submit_nonce(struct thr_info *thr, struct work *work, uint32_t nonce)
 	flip32(hash2_32, work->hash);
 
 	diff1targ = opt_scrypt ? 0x0000ffffUL : 0;
-	if (be32toh(hash2_32[7]) > diff1targ) {
-		applog(LOG_INFO, "%s%d: invalid nonce - HW error",
-		       thr->cgpu->drv->name, thr->cgpu->device_id);
+	return (be32toh(hash2_32[7]) <= diff1targ);
+}
 
-		inc_hw_errors(thr);
-		ret = false;
-		goto out;
-	}
+/* To be used once the work has been tested to be meet diff1 and has had its
+ * nonce adjusted. */
+void submit_tested_work(struct thr_info *thr, struct work *work)
+{
+	struct timeval tv_work_found;
+
+	work->share_diff = share_diff(work);
 
 	mutex_lock(&stats_lock);
 	total_diff1 += work->device_diff;
@@ -6054,13 +6045,30 @@ bool submit_nonce(struct thr_info *thr, struct work *work, uint32_t nonce)
 	thr->cgpu->last_device_valid_work = time(NULL);
 	mutex_unlock(&stats_lock);
 
-	if (!fulltest(hash2, work->target)) {
+	if (!fulltest(work->hash2, work->target)) {
 		applog(LOG_INFO, "Share below target");
-		goto out;
+		return;
 	}
 
+	cgtime(&tv_work_found);
 	submit_work_async(work, &tv_work_found);
-out:
+}
+
+/* Returns true if nonce for work was a valid share */
+bool submit_nonce(struct thr_info *thr, struct work *work, uint32_t nonce)
+{
+	bool ret = true;
+
+	if (test_nonce(work, nonce))
+		submit_tested_work(thr, work);
+	else {
+		applog(LOG_INFO, "%s%d: invalid nonce - HW error",
+		       thr->cgpu->drv->name, thr->cgpu->device_id);
+
+		inc_hw_errors(thr);
+		ret = false;
+	}
+
 	return ret;
 }
 
@@ -7351,34 +7359,6 @@ void enable_curses(void) {
 }
 #endif
 
-#ifdef USE_BFLSC
-extern struct device_drv bflsc_drv;
-#endif
-
-#ifdef USE_BITFORCE
-extern struct device_drv bitforce_drv;
-#endif
-
-#ifdef USE_HASHFAST
-extern struct device_drv hashfast_drv;
-#endif
-
-#ifdef USE_ICARUS
-extern struct device_drv icarus_drv;
-#endif
-
-#ifdef USE_AVALON
-extern struct device_drv avalon_drv;
-#endif
-
-#ifdef USE_MODMINER
-extern struct device_drv modminer_drv;
-#endif
-
-#ifdef USE_ZTEX
-extern struct device_drv ztex_drv;
-#endif
-
 static int cgminer_id_count = 0;
 
 /* Various noop functions for drivers that don't support or need their
@@ -7433,14 +7413,17 @@ static void noop_thread_enable(struct thr_info __maybe_unused *thr)
 {
 }
 
+static void noop_detect(bool __maybe_unused hotplug)
+{
+}
 #define noop_flush_work noop_reinit_device
 #define noop_queue_full noop_get_stats
 
 /* Fill missing driver drv functions with noops */
-void fill_device_drv(struct cgpu_info *cgpu)
+void fill_device_drv(struct device_drv *drv)
 {
-	struct device_drv *drv = cgpu->drv;
-
+	if (!drv->drv_detect)
+		drv->drv_detect = &noop_detect;
 	if (!drv->reinit_device)
 		drv->reinit_device = &noop_reinit_device;
 	if (!drv->get_statline_before)
@@ -7495,7 +7478,7 @@ void enable_device(struct cgpu_info *cgpu)
 #endif
 	}
 #ifdef HAVE_OPENCL
-	if (cgpu->drv->drv_id == DRIVER_OPENCL) {
+	if (cgpu->drv->drv_id == DRIVER_opencl) {
 		gpu_threads += cgpu->threads;
 	}
 #endif
@@ -7538,8 +7521,6 @@ bool add_cgpu(struct cgpu_info *cgpu)
 	cgpu->last_device_valid_work = time(NULL);
 	mutex_unlock(&stats_lock);
 
-	fill_device_drv(cgpu);
-
 	if (hotplug_mode)
 		devices[total_devices + new_devices++] = cgpu;
 	else
@@ -7630,6 +7611,8 @@ static void hotplug_process()
 	switch_logsize(true);
 }
 
+#define DRIVER_DRV_DETECT_HOTPLUG(X) X##_drv.drv_detect(true);
+
 static void *hotplug_thread(void __maybe_unused *userdata)
 {
 	pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
@@ -7649,29 +7632,9 @@ static void *hotplug_thread(void __maybe_unused *userdata)
 			new_devices = 0;
 			new_threads = 0;
 
-#ifdef USE_ICARUS
-			icarus_drv.drv_detect();
-#endif
-
-#ifdef USE_BFLSC
-			bflsc_drv.drv_detect();
-#endif
-
-#ifdef USE_BITFORCE
-			bitforce_drv.drv_detect();
-#endif
-
-#ifdef USE_HASHFAST
-			hashfast_drv.drv_detect();
-#endif
-
-#ifdef USE_MODMINER
-			modminer_drv.drv_detect();
-#endif
-
-#ifdef USE_AVALON
-			avalon_drv.drv_detect();
-#endif
+			/* Use the DRIVER_PARSE_COMMANDS macro to detect all
+			 * devices */
+			DRIVER_PARSE_COMMANDS(DRIVER_DRV_DETECT_HOTPLUG)
 
 			if (new_devices)
 				hotplug_process();
@@ -7697,6 +7660,9 @@ static void probe_pools(void)
 	}
 }
 
+#define DRIVER_FILL_DEVICE_DRV(X) fill_device_drv(&X##_drv);
+#define DRIVER_DRV_DETECT_ALL(X) X##_drv.drv_detect(false);
+
 int main(int argc, char *argv[])
 {
 	struct sigaction handler;
@@ -7877,44 +7843,14 @@ int main(int argc, char *argv[])
 	}
 #endif
 
-#ifdef HAVE_OPENCL
-	if (!opt_nogpu)
-		opencl_drv.drv_detect();
-	gpu_threads = 0;
-#endif
-
-	if (!opt_scrypt) {
-#ifdef USE_ICARUS
-	icarus_drv.drv_detect();
-#endif
-
-#ifdef USE_BFLSC
-	bflsc_drv.drv_detect();
-#endif
-
-#ifdef USE_BITFORCE
-	bitforce_drv.drv_detect();
-#endif
+	/* Use the DRIVER_PARSE_COMMANDS macro to fill all the device_drvs */
+	DRIVER_PARSE_COMMANDS(DRIVER_FILL_DEVICE_DRV)
 
-#ifdef USE_HASHFAST
-	hf_init_crc8();
-	hf_init_crc32();
-	hashfast_drv.drv_detect();
-#endif
-
-#ifdef USE_MODMINER
-	modminer_drv.drv_detect();
-#endif
-
-#ifdef USE_ZTEX
-		ztex_drv.drv_detect();
-#endif
-
-	/* Detect avalon last since it will try to claim the device regardless
-	 * as detection is unreliable. */
-#ifdef USE_AVALON
-	avalon_drv.drv_detect();
-#endif
+	if (opt_scrypt)
+		opencl_drv.drv_detect(false);
+	else {
+	/* Use the DRIVER_PARSE_COMMANDS macro to detect all devices */
+		DRIVER_PARSE_COMMANDS(DRIVER_DRV_DETECT_ALL)
 	}
 
 	if (opt_display_devs) {
diff --git a/configure.ac b/configure.ac
index 0392ab3..ab0c06d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,8 +1,8 @@
 ##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##
 ##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##
 m4_define([v_maj], [3])
-m4_define([v_min], [4])
-m4_define([v_mic], [3])
+m4_define([v_min], [5])
+m4_define([v_mic], [0])
 ##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##
 m4_define([v_ver], [v_maj.v_min.v_mic])
 m4_define([lt_rev], m4_eval(v_maj + v_min))
@@ -253,6 +253,17 @@ if test "x$bitforce" = xyes; then
 fi
 AM_CONDITIONAL([HAS_BITFORCE], [test x$bitforce = xyes])
 
+bitfury="no"
+
+AC_ARG_ENABLE([bitfury],
+	[AC_HELP_STRING([--enable-bitfury],[Compile support for BitFury ASICs (default disabled)])],
+	[bitfury=$enableval]
+	)
+if test "x$bitfury" = xyes; then
+	AC_DEFINE([USE_BITFURY], [1], [Defined to 1 if BitForce support is wanted])
+fi
+AM_CONDITIONAL([HAS_BITFURY], [test x$bitfury = xyes])
+
 hashfast="no"
 
 AC_ARG_ENABLE([hashfast],
@@ -321,7 +332,7 @@ else
 	])
 fi
 
-if test x$avalon$bitforce$modminer$bflsc$icarus$hashfast != xnononononono; then
+if test x$avalon$bitforce$bitfury$modminer$bflsc$icarus$hashfast != xnonononononono; then
 	want_usbutils=true
 else
 	want_usbutils=false
@@ -493,14 +504,14 @@ if test "x$opencl" != xno; then
 
 	else
 		echo "  OpenCL...............: NOT FOUND. GPU mining support DISABLED"
-		if test "x$bitforce$avalon$icarus$ztex$modminer$bflsc$hashfast" = xnonononononono; then
+		if test "x$avalon$bitforce$bitfury$icarus$ztex$modminer$bflsc$hashfast" = xnononononononono; then
 			AC_MSG_ERROR([No mining configured in])
 		fi
 		echo "  scrypt...............: Disabled (needs OpenCL)"
 	fi
 else
 	echo "  OpenCL...............: Detection overrided. GPU mining support DISABLED"
-	if test "x$bitforce$icarus$avalon$ztex$modminer$bflsc$hashfast" = xnonononononono; then
+	if test "x$avalon$bitforce$bitfury$icarus$ztex$modminer$bflsc$hashfast" = xnononononononono; then
 		AC_MSG_ERROR([No mining configured in])
 	fi
 	echo "  scrypt...............: Disabled (needs OpenCL)"
@@ -535,6 +546,12 @@ else
 	echo "  BitForce.FPGAs.......: Disabled"
 fi
 
+if test "x$bitfury" = xyes; then
+	echo "  BitFury.ASICs........: Enabled"
+else
+	echo "  BitFury.ASICs........: Disabled"
+fi
+
 if test "x$hashfast" = xyes; then
 	echo "  Hashfast.ASICs.......: Enabled"
 else
diff --git a/driver-avalon.c b/driver-avalon.c
index 348a2ae..6abdaeb 100644
--- a/driver-avalon.c
+++ b/driver-avalon.c
@@ -52,7 +52,6 @@ int opt_bitburner_core_voltage = BITBURNER_DEFAULT_CORE_VOLTAGE;
 bool opt_avalon_auto;
 
 static int option_offset = -1;
-struct device_drv avalon_drv;
 
 static int avalon_init_task(struct avalon_task *at,
 			    uint8_t reset, uint8_t ff, uint8_t fan,
@@ -273,6 +272,7 @@ static int avalon_reset(struct cgpu_info *avalon, bool initial)
 	struct avalon_task at;
 	uint8_t *buf, *tmp;
 	struct timespec p;
+	struct avalon_info *info = avalon->device_data;
 
 	/* Send reset, then check for result */
 	avalon_init_task(&at, 1, 0,
@@ -329,9 +329,17 @@ static int avalon_reset(struct cgpu_info *avalon, bool initial)
 		       " (%d: %02x %02x %02x %02x)", avalon->drv->name, avalon->device_id,
 		       i, buf[0], buf[1], buf[2], buf[3]);
 		/* FIXME: return 1; */
-	} else
-		applog(LOG_WARNING, "%s%d: Reset succeeded",
-		       avalon->drv->name, avalon->device_id);
+	} else {
+		/* buf[44]: minor
+		 * buf[45]: day
+		 * buf[46]: year,month, d6: 201306
+		 */
+		info->ctlr_ver = ((buf[46] >> 4) + 2000) * 1000000 +
+			(buf[46] & 0x0f) * 10000 +
+			buf[45] * 100 +	buf[44];
+		applog(LOG_WARNING, "%s%d: Reset succeeded (Controller version: %d)",
+		       avalon->drv->name, avalon->device_id, info->ctlr_ver);
+	}
 
 	return 0;
 }
@@ -711,7 +719,7 @@ static bool avalon_detect_one(libusb_device *dev, struct usb_find_devices *found
 	/* Even though this is an FTDI type chip, we want to do the parsing
 	 * all ourselves so set it to std usb type */
 	avalon->usbdev->usb_type = USB_TYPE_STD;
-	avalon->usbdev->PrefPacketSize = AVALON_USB_PACKETSIZE;
+	usb_set_pps(avalon, AVALON_USB_PACKETSIZE);
 
 	/* We have a real Avalon! */
 	avalon_initialise(avalon);
@@ -791,7 +799,7 @@ shin:
 	return false;
 }
 
-static void avalon_detect(void)
+static void avalon_detect(bool __maybe_unused hotplug)
 {
 	usb_detect(&avalon_drv, avalon_detect_one);
 }
@@ -1522,6 +1530,7 @@ static struct api_data *avalon_api_stats(struct cgpu_info *cgpu)
 				info->version1, info->version2, info->version3);
 		root = api_add_string(root, "version", buf, true);
 	}
+	root = api_add_uint32(root, "Controller Version", &(info->ctlr_ver), false);
 
 	return root;
 }
@@ -1590,7 +1599,7 @@ static char *avalon_set_device(struct cgpu_info *avalon, char *option, char *set
 }
 
 struct device_drv avalon_drv = {
-	.drv_id = DRIVER_AVALON,
+	.drv_id = DRIVER_avalon,
 	.dname = "avalon",
 	.name = "AVA",
 	.drv_detect = avalon_detect,
diff --git a/driver-avalon.h b/driver-avalon.h
index 3f7c696..54dc5e2 100644
--- a/driver-avalon.h
+++ b/driver-avalon.h
@@ -125,6 +125,7 @@ struct avalon_info {
 	int matching_work[AVALON_DEFAULT_MINER_NUM];
 
 	int frequency;
+	uint32_t ctlr_ver;
 
 	struct thr_info *thr;
 	pthread_t read_thr;
diff --git a/driver-bflsc.c b/driver-bflsc.c
index 48cadf2..bebed38 100644
--- a/driver-bflsc.c
+++ b/driver-bflsc.c
@@ -33,8 +33,6 @@ int opt_bflsc_overheat = BFLSC_TEMP_OVERHEAT;
 
 static const char *blank = "";
 
-struct device_drv bflsc_drv;
-
 static enum driver_version drv_ver(struct cgpu_info *bflsc, const char *ver)
 {
 	char *tmp;
@@ -895,7 +893,7 @@ shin:
 	return false;
 }
 
-static void bflsc_detect(void)
+static void bflsc_detect(bool __maybe_unused hotplug)
 {
 	usb_detect(&bflsc_drv, bflsc_detect_one);
 }
@@ -1915,7 +1913,7 @@ else a whole lot of something like these ... etc
 }
 
 struct device_drv bflsc_drv = {
-	.drv_id = DRIVER_BFLSC,
+	.drv_id = DRIVER_bflsc,
 	.dname = "BitForceSC",
 	.name = BFLSC_SINGLE,
 	.drv_detect = bflsc_detect,
diff --git a/driver-bitforce.c b/driver-bitforce.c
index 30a6b2d..6cd0d52 100644
--- a/driver-bitforce.c
+++ b/driver-bitforce.c
@@ -77,8 +77,6 @@
 
 static const char *blank = "";
 
-struct device_drv bitforce_drv;
-
 static void bitforce_initialise(struct cgpu_info *bitforce, bool lock)
 {
 	int err, interface;
@@ -290,7 +288,7 @@ shin:
 	return false;
 }
 
-static void bitforce_detect(void)
+static void bitforce_detect(bool __maybe_unused hotplug)
 {
 	usb_detect(&bitforce_drv, bitforce_detect_one);
 }
@@ -742,7 +740,7 @@ static struct api_data *bitforce_api_stats(struct cgpu_info *cgpu)
 }
 
 struct device_drv bitforce_drv = {
-	.drv_id = DRIVER_BITFORCE,
+	.drv_id = DRIVER_bitforce,
 	.dname = "BitForce",
 	.name = "BFL",
 	.drv_detect = bitforce_detect,
diff --git a/driver-bitfury.c b/driver-bitfury.c
new file mode 100644
index 0000000..8069a1d
--- /dev/null
+++ b/driver-bitfury.c
@@ -0,0 +1,330 @@
+/*
+ * Copyright 2013 Con Kolivas
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 3 of the License, or (at your option)
+ * any later version.  See COPYING for more details.
+ */
+
+#include "config.h"
+
+#include "miner.h"
+#include "driver-bitfury.h"
+#include "sha2.h"
+
+/* Wait longer 1/3 longer than it would take for a full nonce range */
+#define BF1WAIT 1600
+
+static void bitfury_empty_buffer(struct cgpu_info *bitfury)
+{
+	char buf[512];
+	int amount;
+
+	do {
+		usb_read_once(bitfury, buf, 512, &amount, C_BF1_FLUSH);
+	} while (amount);
+}
+
+static void bitfury_open(struct cgpu_info *bitfury)
+{
+	uint32_t buf[2];
+
+	bitfury_empty_buffer(bitfury);
+	/* Magic sequence to reset device only really needed for windows but
+	 * harmless on linux. */
+	buf[0] = 0x80250000;
+	buf[1] = 0x00000800;
+	usb_transfer(bitfury, 0, 9, 1, 0, C_BF1_RESET);
+	usb_transfer(bitfury, 0x21, 0x22, 0, 0, C_BF1_OPEN);
+	usb_transfer_data(bitfury, 0x21, 0x20, 0x0000, 0, buf, 7, C_BF1_INIT);
+}
+
+static void bitfury_close(struct cgpu_info *bitfury)
+{
+	bitfury_empty_buffer(bitfury);
+}
+
+static void bitfury_identify(struct cgpu_info *bitfury)
+{
+	int amount;
+
+	usb_write(bitfury, "L", 1, &amount, C_BF1_IDENTIFY);
+}
+
+static bool bitfury_getinfo(struct cgpu_info *bitfury, struct bitfury_info *info)
+{
+	int amount, err;
+	char buf[16];
+
+	err = usb_write(bitfury, "I", 1, &amount, C_BF1_REQINFO);
+	if (err) {
+		applog(LOG_INFO, "%s %d: Failed to write REQINFO",
+		       bitfury->drv->name, bitfury->device_id);
+		return false;
+	}
+	err = usb_read(bitfury, buf, 14, &amount, C_BF1_GETINFO);
+	if (err) {
+		applog(LOG_INFO, "%s %d: Failed to read GETINFO",
+		       bitfury->drv->name, bitfury->device_id);
+		return false;
+	}
+	if (amount != 14) {
+		applog(LOG_INFO, "%s %d: Getinfo received %d bytes instead of 14",
+		       bitfury->drv->name, bitfury->device_id, amount);
+		return false;
+	}
+	info->version = buf[1];
+	memcpy(&info->product, buf + 2, 8);
+	memcpy(&info->serial, buf + 10, 4);
+
+	applog(LOG_INFO, "%s %d: Getinfo returned version %d, product %s serial %08x", bitfury->drv->name,
+	       bitfury->device_id, info->version, info->product, info->serial);
+	bitfury_empty_buffer(bitfury);
+	return true;
+}
+
+static bool bitfury_reset(struct cgpu_info *bitfury)
+{
+	int amount, err;
+	char buf[16];
+
+	err = usb_write(bitfury, "R", 1, &amount, C_BF1_REQRESET);
+	if (err) {
+		applog(LOG_INFO, "%s %d: Failed to write REQRESET",
+		       bitfury->drv->name, bitfury->device_id);
+		return false;
+	}
+	err = usb_read_timeout(bitfury, buf, 7, &amount, BF1WAIT, C_BF1_GETRESET);
+	if (err) {
+		applog(LOG_INFO, "%s %d: Failed to read GETRESET",
+		       bitfury->drv->name, bitfury->device_id);
+		return false;
+	}
+	if (amount != 7) {
+		applog(LOG_INFO, "%s %d: Getreset received %d bytes instead of 7",
+		       bitfury->drv->name, bitfury->device_id, amount);
+		return false;
+	}
+	applog(LOG_DEBUG, "%s %d: Getreset returned %s", bitfury->drv->name,
+	       bitfury->device_id, buf);
+	bitfury_empty_buffer(bitfury);
+	return true;
+}
+
+static bool bitfury_detect_one(struct libusb_device *dev, struct usb_find_devices *found)
+{
+	struct cgpu_info *bitfury;
+	struct bitfury_info *info;
+
+	bitfury = usb_alloc_cgpu(&bitfury_drv, 1);
+
+	if (!usb_init(bitfury, dev, found))
+		goto out;
+	applog(LOG_INFO, "%s %d: Found at %s", bitfury->drv->name,
+	       bitfury->device_id, bitfury->device_path);
+
+	info = calloc(sizeof(struct bitfury_info), 1);
+	if (!info)
+		quit(1, "Failed to calloc info in bitfury_detect_one");
+	bitfury->device_data = info;
+
+	usb_buffer_enable(bitfury);
+
+	bitfury_open(bitfury);
+
+	/* Send getinfo request */
+	if (!bitfury_getinfo(bitfury, info))
+		goto out_close;
+
+	/* Send reset request */
+	if (!bitfury_reset(bitfury))
+		goto out_close;
+
+	bitfury_identify(bitfury);
+	bitfury_empty_buffer(bitfury);
+
+	if (!add_cgpu(bitfury))
+		goto out_close;
+
+	update_usb_stats(bitfury);
+	applog(LOG_INFO, "%s %d: Found at %s",
+	       bitfury->drv->name, bitfury->device_id, bitfury->device_path);
+	return true;
+out_close:
+	bitfury_close(bitfury);
+	usb_uninit(bitfury);
+out:
+	bitfury = usb_free_cgpu(bitfury);
+	return false;
+}
+
+static void bitfury_detect(bool __maybe_unused hotplug)
+{
+	usb_detect(&bitfury_drv, bitfury_detect_one);
+}
+
+static uint32_t decnonce(uint32_t in)
+{
+	uint32_t out;
+
+	/* First part load */
+	out = (in & 0xFF) << 24; in >>= 8;
+
+	/* Byte reversal */
+	in = (((in & 0xaaaaaaaa) >> 1) | ((in & 0x55555555) << 1));
+	in = (((in & 0xcccccccc) >> 2) | ((in & 0x33333333) << 2));
+	in = (((in & 0xf0f0f0f0) >> 4) | ((in & 0x0f0f0f0f) << 4));
+
+	out |= (in >> 2)&0x3FFFFF;
+
+	/* Extraction */
+	if (in & 1) out |= (1 << 23);
+	if (in & 2) out |= (1 << 22);
+
+	out -= 0x800004;
+	return out;
+}
+
+#define BT_OFFSETS 3
+const uint32_t bf_offsets[] = {-0x800000, 0, -0x400000};
+
+static bool bitfury_checkresults(struct thr_info *thr, struct work *work, uint32_t nonce)
+{
+	int i;
+
+	for (i = 0; i < BT_OFFSETS; i++) {
+		if (test_nonce(work, nonce + bf_offsets[i])) {
+			submit_tested_work(thr, work);
+			return true;
+		}
+	}
+	return false;
+}
+
+static int64_t bitfury_scanhash(struct thr_info *thr, struct work *work,
+				int64_t __maybe_unused max_nonce)
+{
+	struct cgpu_info *bitfury = thr->cgpu;
+	struct bitfury_info *info = bitfury->device_data;
+	struct timeval tv_now;
+	int amount, i;
+	char buf[45];
+	int ms_diff;
+
+	buf[0] = 'W';
+	memcpy(buf + 1, work->midstate, 32);
+	memcpy(buf + 33, work->data + 64, 12);
+
+	/* New results may spill out from the latest work, making us drop out
+	 * too early so read whatever we get for the first half nonce and then
+	 * look for the results to prev work. */
+	cgtime(&tv_now);
+	ms_diff = 600 - ms_tdiff(&tv_now, &info->tv_start);
+	if (ms_diff > 0) {
+		usb_read_timeout(bitfury, info->buf, 512, &amount, ms_diff, C_BF1_GETRES);
+		info->tot += amount;
+	}
+
+	if (unlikely(thr->work_restart))
+		goto cascade;
+
+	/* Now look for the bulk of the previous work results, they will come
+	 * in a batch following the first data. */
+	cgtime(&tv_now);
+	ms_diff = BF1WAIT - ms_tdiff(&tv_now, &info->tv_start);
+	if (unlikely(ms_diff < 10))
+		ms_diff = 10;
+	usb_read_once_timeout(bitfury, info->buf + info->tot, 7, &amount, ms_diff, C_BF1_GETRES);
+	info->tot += amount;
+	while (amount) {
+		usb_read_once_timeout(bitfury, info->buf + info->tot, 512, &amount, 10, C_BF1_GETRES);
+		info->tot += amount;
+	};
+
+	if (unlikely(thr->work_restart))
+		goto cascade;
+
+	/* Send work */
+	usb_write(bitfury, buf, 45, &amount, C_BF1_REQWORK);
+	cgtime(&info->tv_start);
+	/* Get response acknowledging work */
+	usb_read(bitfury, buf, 7, &amount, C_BF1_GETWORK);
+
+	/* Only happens on startup */
+	if (unlikely(!info->prevwork[BF1ARRAY_SIZE]))
+		goto cascade;
+
+	/* Search for what work the nonce matches in order of likelihood. Last
+	 * entry is end of result marker. */
+	for (i = 0; i < info->tot - 7; i += 7) {
+		uint32_t nonce;
+		int j;
+
+		/* Ignore state & switched data in results for now. */
+		memcpy(&nonce, info->buf + i + 3, 4);
+		nonce = decnonce(nonce);
+		for (j = 0; j < BF1ARRAY_SIZE; j++) {
+			if (bitfury_checkresults(thr, info->prevwork[j], nonce)) {
+				info->nonces++;
+				break;
+			}
+		}
+	}
+
+	info->tot = 0;
+	free_work(info->prevwork[BF1ARRAY_SIZE]);
+cascade:
+	for (i = BF1ARRAY_SIZE; i > 0; i--)
+		info->prevwork[i] = info->prevwork[i - 1];
+	info->prevwork[0] = copy_work(work);
+	work->blk.nonce = 0xffffffff;
+	if (info->nonces) {
+		info->nonces--;
+		return (int64_t)0xffffffff;
+	}
+	return 0;
+}
+
+static struct api_data *bitfury_api_stats(struct cgpu_info *cgpu)
+{
+	struct bitfury_info *info = cgpu->device_data;
+	struct api_data *root = NULL;
+	char serial[16];
+	int version;
+
+	version = info->version;
+	root = api_add_int(root, "Version", &version, true);
+	root = api_add_string(root, "Product", info->product, false);
+	sprintf(serial, "%08x", info->serial);
+	root = api_add_string(root, "Serial", serial, true);
+
+	return root;
+}
+
+static void bitfury_init(struct cgpu_info  *bitfury)
+{
+	bitfury_close(bitfury);
+	bitfury_open(bitfury);
+	bitfury_reset(bitfury);
+}
+
+static void bitfury_shutdown(struct thr_info *thr)
+{
+	struct cgpu_info *bitfury = thr->cgpu;
+
+	bitfury_close(bitfury);
+}
+
+/* Currently hardcoded to BF1 devices */
+struct device_drv bitfury_drv = {
+	.drv_id = DRIVER_bitfury,
+	.dname = "bitfury",
+	.name = "BF1",
+	.drv_detect = bitfury_detect,
+	.scanhash = bitfury_scanhash,
+	.get_api_stats = bitfury_api_stats,
+	.reinit_device = bitfury_init,
+	.thread_shutdown = bitfury_shutdown,
+	.identify_device = bitfury_identify
+};
diff --git a/driver-bitfury.h b/driver-bitfury.h
new file mode 100644
index 0000000..9cbe420
--- /dev/null
+++ b/driver-bitfury.h
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2013 Con Kolivas
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 3 of the License, or (at your option)
+ * any later version.  See COPYING for more details.
+ */
+
+#ifndef BITFURY_H
+#define BITFURY_H
+
+#include "miner.h"
+#include "usbutils.h"
+
+#define BF1ARRAY_SIZE 2
+
+struct bitfury_info {
+	struct cgpu_info *base_cgpu;
+	uint8_t version;
+	char product[8];
+	uint32_t serial;
+	struct work *prevwork[BF1ARRAY_SIZE + 1];
+	char buf[512];
+	int tot;
+	int nonces;
+	struct timeval tv_start;
+};
+
+#endif /* BITFURY_H */
diff --git a/driver-hashfast.c b/driver-hashfast.c
index 49d4a98..aabccc5 100644
--- a/driver-hashfast.c
+++ b/driver-hashfast.c
@@ -285,7 +285,7 @@ static bool hashfast_detect_one_usb(libusb_device *dev, struct usb_find_devices 
 	}
 
 	hashfast->usbdev->usb_type = USB_TYPE_STD;
-	hashfast->usbdev->PrefPacketSize = HASHFAST_USB_PACKETSIZE;
+	usb_set_pps(hashfast, HASHFAST_USB_PACKETSIZE);
 
 	hashfast_usb_initialise(hashfast);
 
@@ -293,8 +293,13 @@ static bool hashfast_detect_one_usb(libusb_device *dev, struct usb_find_devices 
 	return hashfast_detect_common(hashfast, baud);
 }
 
-static void hashfast_detect(void)
+static void hashfast_detect(bool hotplug)
 {
+	/* Set up the CRC tables only once. */
+	if (!hotplug) {
+		hf_init_crc8();
+		hf_init_crc32();
+	}
 	usb_detect(&hashfast_drv, hashfast_detect_one_usb);
 }
 
@@ -328,7 +333,7 @@ static void hashfast_shutdown(struct thr_info __maybe_unused *thr)
 }
 
 struct device_drv hashfast_drv = {
-	.drv_id = DRIVER_HASHFAST,
+	.drv_id = DRIVER_hashfast,
 	.dname = "Hashfast",
 	.name = "HFA",
 	.drv_detect = hashfast_detect,
diff --git a/driver-icarus.c b/driver-icarus.c
index 42814a1..6ac1a0b 100644
--- a/driver-icarus.c
+++ b/driver-icarus.c
@@ -74,6 +74,7 @@ ASSERT1(sizeof(uint32_t) == 4);
 
 // USB ms timeout to wait - user specified timeouts are multiples of this
 #define ICARUS_WAIT_TIMEOUT 100
+#define ICARUS_CMR2_TIMEOUT 1
 
 // Defined in multiples of ICARUS_WAIT_TIMEOUT
 // Must of course be greater than ICARUS_READ_COUNT_TIMING/ICARUS_WAIT_TIMEOUT
@@ -177,6 +178,8 @@ static const char *MODE_VALUE_STR = "value";
 static const char *MODE_UNKNOWN_STR = "unknown";
 
 struct ICARUS_INFO {
+	int intinfo;
+
 	// time to calculate the golden_ob
 	uint64_t golden_hashes;
 	struct timeval golden_tv;
@@ -184,6 +187,8 @@ struct ICARUS_INFO {
 	struct ICARUS_HISTORY history[INFO_HISTORY+1];
 	uint32_t min_data_count;
 
+	int timeout;
+
 	// seconds per Hash
 	double Hs;
 	// ms til we abort
@@ -233,8 +238,6 @@ struct ICARUS_INFO {
 //
 static int option_offset = -1;
 
-struct device_drv icarus_drv;
-
 /*
 #define ICA_BUFSIZ (0x200)
 
@@ -277,7 +280,7 @@ static void icarus_initialise(struct cgpu_info *icarus, int baud)
 	usb_set_cps(icarus, baud / 10);
 	usb_enable_cps(icarus);
 
-	interface = usb_interface(icarus);
+	interface = _usb_interface(icarus, info->intinfo);
 	ident = usb_ident(icarus);
 
 	switch (ident) {
@@ -287,9 +290,6 @@ static void icarus_initialise(struct cgpu_info *icarus, int baud)
 		case IDENT_CMR2:
 			usb_set_pps(icarus, BLT_PREF_PACKET);
 
-			if (ident == IDENT_CMR2) // Chip hack
-				interface++;
-
 			// Reset
 			transfer(icarus, FTDI_TYPE_OUT, FTDI_REQUEST_RESET, FTDI_VALUE_RESET,
 				 interface, C_RESET);
@@ -298,7 +298,7 @@ static void icarus_initialise(struct cgpu_info *icarus, int baud)
 				return;
 
 			// Latency
-			usb_ftdi_set_latency(icarus);
+			_usb_ftdi_set_latency(icarus, info->intinfo);
 
 			if (icarus->usbinfo.nodev)
 				return;
@@ -434,9 +434,10 @@ static void rev(unsigned char *s, size_t l)
 
 static int icarus_get_nonce(struct cgpu_info *icarus, unsigned char *buf, struct timeval *tv_start, struct timeval *tv_finish, struct thr_info *thr, int read_time)
 {
+	struct ICARUS_INFO *info = (struct ICARUS_INFO *)(icarus->device_data);
 	struct timeval read_start, read_finish;
 	int err, amt;
-	int rc = 0;
+	int rc = 0, delay;
 	int read_amount = ICARUS_READ_SIZE;
 	bool first = true;
 
@@ -446,7 +447,9 @@ static int icarus_get_nonce(struct cgpu_info *icarus, unsigned char *buf, struct
 			return ICA_NONCE_ERROR;
 
 		cgtime(&read_start);
-		err = usb_read_timeout(icarus, (char *)buf, read_amount, &amt, ICARUS_WAIT_TIMEOUT, C_GETRESULTS);
+		err = usb_read_ii_timeout(icarus, info->intinfo,
+					  (char *)buf, read_amount, &amt,
+					  info->timeout, C_GETRESULTS);
 		cgtime(&read_finish);
 		if (err < 0 && err != LIBUSB_ERROR_TIMEOUT) {
 			applog(LOG_ERR, "%s%i: Comms error (rerr=%d amt=%d)",
@@ -471,10 +474,7 @@ static int icarus_get_nonce(struct cgpu_info *icarus, unsigned char *buf, struct
 		}
 
 		if (thr && thr->work_restart) {
-			if (opt_debug) {
-				applog(LOG_DEBUG,
-					"Icarus Read: Work restart at %d ms", rc);
-			}
+			applog(LOG_DEBUG, "Icarus Read: Work restart at %d ms", rc);
 			return ICA_NONCE_RESTART;
 		}
 
@@ -483,6 +483,18 @@ static int icarus_get_nonce(struct cgpu_info *icarus, unsigned char *buf, struct
 			read_amount -= amt;
 			first = false;
 		}
+
+		if (info->timeout < ICARUS_WAIT_TIMEOUT) {
+			delay = ICARUS_WAIT_TIMEOUT - rc;
+			if (delay > 0) {
+				cgsleep_ms(delay);
+
+				if (thr && thr->work_restart) {
+					applog(LOG_DEBUG, "Icarus Read: Work restart at %d ms", rc);
+					return ICA_NONCE_RESTART;
+				}
+			}
+		}
 	}
 }
 
@@ -796,6 +808,7 @@ static bool icarus_detect_one(struct libusb_device *dev, struct usb_find_devices
 	int baud, uninitialised_var(work_division), uninitialised_var(fpga_count);
 	struct cgpu_info *icarus;
 	int ret, err, amount, tries;
+	enum sub_ident ident;
 	bool ok;
 
 	icarus = usb_alloc_cgpu(&icarus_drv, 1);
@@ -814,6 +827,23 @@ static bool icarus_detect_one(struct libusb_device *dev, struct usb_find_devices
 		quit(1, "Failed to malloc ICARUS_INFO");
 	icarus->device_data = (void *)info;
 
+	ident = usb_ident(icarus);
+	switch (ident) {
+		case IDENT_ICA:
+		case IDENT_BLT:
+		case IDENT_LLT:
+		case IDENT_AMU:
+		case IDENT_CMR1:
+			info->timeout = ICARUS_WAIT_TIMEOUT;
+			break;
+		case IDENT_CMR2:
+			info->timeout = ICARUS_CMR2_TIMEOUT;
+			break;
+		default:
+			quit(1, "%s icarus_detect_one() invalid %s ident=%d",
+				icarus->drv->dname, icarus->drv->dname, ident);
+	}
+
 	tries = 2;
 	ok = false;
 	while (!ok && tries-- > 0) {
@@ -879,7 +909,7 @@ static bool icarus_detect_one(struct libusb_device *dev, struct usb_find_devices
 			struct cgpu_info *cgtmp;
 			struct ICARUS_INFO *intmp;
 
-			cgtmp = usb_init_intinfo(icarus, i);
+			cgtmp = usb_copy_cgpu(icarus);
 			if (!cgtmp) {
 				applog(LOG_ERR, "%s%d: Init failed initinfo %d",
 						icarus->drv->name, icarus->device_id, i);
@@ -888,13 +918,6 @@ static bool icarus_detect_one(struct libusb_device *dev, struct usb_find_devices
 
 			cgtmp->usbinfo.usbstat = USB_NOSTAT;
 
-			if (!add_cgpu(cgtmp)) {
-				usb_uninit(cgtmp);
-				continue;
-			}
-
-			update_usb_stats(cgtmp);
-
 			intmp = (struct ICARUS_INFO *)malloc(sizeof(struct ICARUS_INFO));
 			if (unlikely(!intmp))
 				quit(1, "Failed2 to malloc ICARUS_INFO");
@@ -903,6 +926,18 @@ static bool icarus_detect_one(struct libusb_device *dev, struct usb_find_devices
 
 			// Initialise everything to match
 			memcpy(intmp, info, sizeof(struct ICARUS_INFO));
+
+			intmp->intinfo = i;
+
+			icarus_initialise(cgtmp, baud);
+
+			if (!add_cgpu(cgtmp)) {
+				usb_uninit(cgtmp);
+				free(intmp);
+				continue;
+			}
+
+			update_usb_stats(cgtmp);
 		}
 	}
 
@@ -921,7 +956,7 @@ shin:
 	return false;
 }
 
-static void icarus_detect()
+static void icarus_detect(bool __maybe_unused hotplug)
 {
 	usb_detect(&icarus_drv, icarus_detect_one);
 }
@@ -976,7 +1011,7 @@ static int64_t icarus_scanhash(struct thr_info *thr, struct work *work,
 	// We only want results for the work we are about to send
 	usb_buffer_clear(icarus);
 
-	err = usb_write(icarus, (char *)ob_bin, sizeof(ob_bin), &amount, C_SENDWORK);
+	err = usb_write_ii(icarus, info->intinfo, (char *)ob_bin, sizeof(ob_bin), &amount, C_SENDWORK);
 	if (err < 0 || amount != sizeof(ob_bin)) {
 		applog(LOG_ERR, "%s%i: Comms error (werr=%d amt=%d)",
 				icarus->drv->name, icarus->device_id, err, amount);
@@ -1014,12 +1049,10 @@ static int64_t icarus_scanhash(struct thr_info *thr, struct work *work,
 		if (unlikely(estimate_hashes > 0xffffffff))
 			estimate_hashes = 0xffffffff;
 
-		if (opt_debug) {
-			applog(LOG_DEBUG, "%s%d: no nonce = 0x%08lX hashes (%ld.%06lds)",
-					icarus->drv->name, icarus->device_id,
-					(long unsigned int)estimate_hashes,
-					elapsed.tv_sec, elapsed.tv_usec);
-		}
+		applog(LOG_DEBUG, "%s%d: no nonce = 0x%08lX hashes (%ld.%06lds)",
+				icarus->drv->name, icarus->device_id,
+				(long unsigned int)estimate_hashes,
+				elapsed.tv_sec, elapsed.tv_usec);
 
 		return estimate_hashes;
 	}
@@ -1051,12 +1084,10 @@ static int64_t icarus_scanhash(struct thr_info *thr, struct work *work,
 	if (opt_debug || info->do_icarus_timing)
 		timersub(&tv_finish, &tv_start, &elapsed);
 
-	if (opt_debug) {
-		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,
-				elapsed.tv_sec, elapsed.tv_usec);
-	}
+	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,
+			elapsed.tv_sec, elapsed.tv_usec);
 
 	// Ignore possible end condition values ... and hw errors
 	// TODO: set limitations on calculated values depending on the device
@@ -1203,7 +1234,7 @@ static void icarus_shutdown(__maybe_unused struct thr_info *thr)
 }
 
 struct device_drv icarus_drv = {
-	.drv_id = DRIVER_ICARUS,
+	.drv_id = DRIVER_icarus,
 	.dname = "Icarus",
 	.name = "ICA",
 	.drv_detect = icarus_detect,
diff --git a/driver-modminer.c b/driver-modminer.c
index 8f85855..0672c99 100644
--- a/driver-modminer.c
+++ b/driver-modminer.c
@@ -87,8 +87,6 @@
 // Limit when reducing shares_to_good
 #define MODMINER_MIN_BACK 12
 
-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";
 
@@ -239,7 +237,7 @@ shin:
 		return false;
 }
 
-static void modminer_detect()
+static void modminer_detect(bool __maybe_unused hotplug)
 {
 	usb_detect(&modminer_drv, modminer_detect_one);
 }
@@ -1132,7 +1130,7 @@ static char *modminer_set_device(struct cgpu_info *modminer, char *option, char 
 }
 
 struct device_drv modminer_drv = {
-	.drv_id = DRIVER_MODMINER,
+	.drv_id = DRIVER_modminer,
 	.dname = "ModMiner",
 	.name = "MMQ",
 	.drv_detect = modminer_detect,
diff --git a/driver-opencl.c b/driver-opencl.c
index 57df2dc..d7b663a 100644
--- a/driver-opencl.c
+++ b/driver-opencl.c
@@ -56,10 +56,6 @@ 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);
@@ -585,7 +581,7 @@ char *set_intensity(char *arg)
 void print_ndevs(int *ndevs)
 {
 	opt_log_output = true;
-	opencl_drv.drv_detect();
+	opencl_drv.drv_detect(false);
 	clear_adl(*ndevs);
 	applog(LOG_INFO, "%i GPU devices max detected", *ndevs);
 }
@@ -753,7 +749,7 @@ retry:
 		for (i = 0; i < mining_threads; ++i) {
 			thr = get_thread(i);
 			cgpu = thr->cgpu;
-			if (cgpu->drv->drv_id != DRIVER_OPENCL)
+			if (cgpu->drv->drv_id != DRIVER_opencl)
 				continue;
 			if (dev_from_id(i) != selected)
 				continue;
@@ -1148,7 +1144,7 @@ select_cgpu:
 	for (thr_id = 0; thr_id < mining_threads; ++thr_id) {
 		thr = get_thread(thr_id);
 		cgpu = thr->cgpu;
-		if (cgpu->drv->drv_id != DRIVER_OPENCL)
+		if (cgpu->drv->drv_id != DRIVER_opencl)
 			continue;
 		if (dev_from_id(thr_id) != gpu)
 			continue;
@@ -1173,7 +1169,7 @@ select_cgpu:
 
 		thr = get_thread(thr_id);
 		cgpu = thr->cgpu;
-		if (cgpu->drv->drv_id != DRIVER_OPENCL)
+		if (cgpu->drv->drv_id != DRIVER_opencl)
 			continue;
 		if (dev_from_id(thr_id) != gpu)
 			continue;
@@ -1210,7 +1206,7 @@ select_cgpu:
 	for (thr_id = 0; thr_id < mining_threads; ++thr_id) {
 		thr = get_thread(thr_id);
 		cgpu = thr->cgpu;
-		if (cgpu->drv->drv_id != DRIVER_OPENCL)
+		if (cgpu->drv->drv_id != DRIVER_opencl)
 			continue;
 		if (dev_from_id(thr_id) != gpu)
 			continue;
@@ -1231,10 +1227,12 @@ void *reinit_gpu(__maybe_unused void *userdata)
 
 
 #ifdef HAVE_OPENCL
-static void opencl_detect()
+static void opencl_detect(bool hotplug)
 {
 	int i;
 
+	if (opt_nogpu || hotplug)
+		return;
 	nDevs = clDevicesNum();
 	if (nDevs < 0) {
 		applog(LOG_ERR, "clDevicesNum returned error, no GPUs usable");
@@ -1575,7 +1573,7 @@ static void opencl_thread_shutdown(struct thr_info *thr)
 }
 
 struct device_drv opencl_drv = {
-	.drv_id = DRIVER_OPENCL,
+	.drv_id = DRIVER_opencl,
 	.dname = "opencl",
 	.name = "GPU",
 	.drv_detect = opencl_detect,
diff --git a/driver-ztex.c b/driver-ztex.c
index 2525471..ee0c0a9 100644
--- a/driver-ztex.c
+++ b/driver-ztex.c
@@ -31,8 +31,6 @@
 
 #define GOLDEN_BACKLOG 5
 
-struct device_drv ztex_drv;
-
 // Forward declarations
 static void ztex_disable(struct thr_info* thr);
 static bool ztex_prepare(struct thr_info *thr);
@@ -54,7 +52,7 @@ static void ztex_releaseFpga(struct libztex_device* ztex)
 	}
 }
 
-static void ztex_detect(void)
+static void ztex_detect(bool __maybe_unused hotplug)
 {
 	int cnt;
 	int i,j;
@@ -413,7 +411,7 @@ static void ztex_disable(struct thr_info *thr)
 }
 
 struct device_drv ztex_drv = {
-	.drv_id = DRIVER_ZTEX,
+	.drv_id = DRIVER_ztex,
 	.dname = "ztex",
 	.name = "ZTX",
 	.drv_detect = ztex_detect,
diff --git a/miner.h b/miner.h
index be33daa..4bda1bd 100644
--- a/miner.h
+++ b/miner.h
@@ -230,18 +230,39 @@ static inline int fsync (int fd)
 #define MIN(x, y)	((x) > (y) ? (y) : (x))
 #define MAX(x, y)	((x) > (y) ? (x) : (y))
 
+/* Put avalon last to make it the last device it tries to detect to prevent it
+ * trying to claim same chip but different devices. Adding a device here will
+ * update all macros in the code that use the *_PARSE_COMMANDS macros for each
+ * listed driver. */
+#define FPGA_PARSE_COMMANDS(DRIVER_ADD_COMMAND) \
+	DRIVER_ADD_COMMAND(bitforce) \
+	DRIVER_ADD_COMMAND(icarus) \
+	DRIVER_ADD_COMMAND(modminer) \
+	DRIVER_ADD_COMMAND(ztex)
+
+#define ASIC_PARSE_COMMANDS(DRIVER_ADD_COMMAND) \
+	DRIVER_ADD_COMMAND(bflsc) \
+	DRIVER_ADD_COMMAND(bitfury) \
+	DRIVER_ADD_COMMAND(hashfast) \
+	DRIVER_ADD_COMMAND(avalon)
+
+#define DRIVER_PARSE_COMMANDS(DRIVER_ADD_COMMAND) \
+	DRIVER_ADD_COMMAND(opencl) \
+	FPGA_PARSE_COMMANDS(DRIVER_ADD_COMMAND) \
+	ASIC_PARSE_COMMANDS(DRIVER_ADD_COMMAND)
+
+#define DRIVER_ENUM(X) DRIVER_##X,
+#define DRIVER_PROTOTYPE(X) struct device_drv X##_drv;
+
+/* Create drv_driver enum from DRIVER_PARSE_COMMANDS macro */
 enum drv_driver {
-	DRIVER_OPENCL = 0,
-	DRIVER_ICARUS,
-	DRIVER_BITFORCE,
-	DRIVER_MODMINER,
-	DRIVER_ZTEX,
-	DRIVER_BFLSC,
-	DRIVER_AVALON,
-	DRIVER_HASHFAST,
+	DRIVER_PARSE_COMMANDS(DRIVER_ENUM)
 	DRIVER_MAX
 };
 
+/* Use DRIVER_PARSE_COMMANDS to generate extern device_drv prototypes */
+DRIVER_PARSE_COMMANDS(DRIVER_PROTOTYPE)
+
 enum alive {
 	LIFE_WELL,
 	LIFE_SICK,
@@ -318,7 +339,7 @@ struct device_drv {
 	char *name;
 
 	// DRV-global functions
-	void (*drv_detect)();
+	void (*drv_detect)(bool);
 
 	// Device-specific functions
 	void (*reinit_device)(struct cgpu_info *);
@@ -823,7 +844,7 @@ static inline void cglock_init(cglock_t *lock)
 	rwlock_init(&lock->rwlock);
 }
 
-/* Read lock variant of cglock */
+/* Read lock variant of cglock. Cannot be promoted. */
 static inline void cg_rlock(cglock_t *lock)
 {
 	mutex_lock(&lock->mutex);
@@ -831,7 +852,8 @@ static inline void cg_rlock(cglock_t *lock)
 	mutex_unlock_noyield(&lock->mutex);
 }
 
-/* Intermediate variant of cglock */
+/* Intermediate variant of cglock - behaves as a read lock but can be promoted
+ * to a write lock or demoted to read lock. */
 static inline void cg_ilock(cglock_t *lock)
 {
 	mutex_lock(&lock->mutex);
@@ -858,6 +880,12 @@ static inline void cg_dwlock(cglock_t *lock)
 	mutex_unlock_noyield(&lock->mutex);
 }
 
+/* Demote a write variant to an intermediate variant */
+static inline void cg_dwilock(cglock_t *lock)
+{
+	wr_unlock(&lock->rwlock);
+}
+
 /* Downgrade intermediate variant to a read lock */
 static inline void cg_dlock(cglock_t *lock)
 {
@@ -872,7 +900,7 @@ static inline void cg_runlock(cglock_t *lock)
 
 static inline void cg_wunlock(cglock_t *lock)
 {
-	wr_unlock(&lock->rwlock);
+	wr_unlock_noyield(&lock->rwlock);
 	mutex_unlock(&lock->mutex);
 }
 
@@ -903,6 +931,7 @@ extern bool opt_api_listen;
 extern bool opt_api_network;
 extern bool opt_delaynet;
 extern bool opt_restart;
+extern bool opt_nogpu;
 extern char *opt_icarus_options;
 extern char *opt_icarus_timing;
 extern bool opt_worktime;
@@ -1263,6 +1292,7 @@ struct work {
 #endif
 	double		device_diff;
 	uint64_t	share_diff;
+	unsigned char	hash2[32];
 
 	int		rolls;
 
@@ -1356,6 +1386,8 @@ struct modminer_fpga_state {
 
 extern void get_datestamp(char *, size_t, struct timeval *);
 extern void inc_hw_errors(struct thr_info *thr);
+extern bool test_nonce(struct work *work, uint32_t nonce);
+extern void submit_tested_work(struct thr_info *thr, struct work *work);
 extern bool submit_nonce(struct thr_info *thr, struct work *work, uint32_t nonce);
 extern struct work *get_queued(struct cgpu_info *cgpu);
 extern struct work *__find_work_bymidstate(struct work *que, char *midstate, size_t midstatelen, char *data, int offset, size_t datalen);
diff --git a/usbutils.c b/usbutils.c
index 867389a..9fa8ef5 100644
--- a/usbutils.c
+++ b/usbutils.c
@@ -34,55 +34,27 @@
  */
 #define DEVLOCK(cgpu, _pth_state) do { \
 			pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &_pth_state); \
-			wr_lock(cgpu->usbinfo.devlock); \
+			mutex_lock(cgpu->usbinfo.devlock); \
 			} while (0)
 
 #define DEVUNLOCK(cgpu, _pth_state) do { \
-			wr_unlock(cgpu->usbinfo.devlock); \
+			mutex_unlock(cgpu->usbinfo.devlock); \
 			pthread_setcancelstate(_pth_state, NULL); \
 			} while (0)
 
-#ifdef USE_BFLSC
-#define DRV_BFLSC 1
-#endif
-
-#ifdef USE_BITFORCE
-#define DRV_BITFORCE 2
-#endif
-
-#ifdef USE_MODMINER
-#define DRV_MODMINER 3
-#endif
-
-#ifdef USE_ZTEX
-#define DRV_ZTEX 4
-#endif
-
-#ifdef USE_ICARUS
-#define DRV_ICARUS 5
-#endif
-
-#ifdef USE_AVALON
-#define DRV_AVALON 6
-#endif
-
-#ifdef USE_HASHFAST
-#define DRV_HASHFAST 7
-#endif
-
-#define DRV_LAST -1
-
 #define USB_CONFIG 1
 
 #ifdef WIN32
 #define BFLSC_TIMEOUT_MS 999
 #define BITFORCE_TIMEOUT_MS 999
+#define BITFURY_TIMEOUT_MS 999
 #define MODMINER_TIMEOUT_MS 999
 #define AVALON_TIMEOUT_MS 999
 #define ICARUS_TIMEOUT_MS 999
 #else
 #define BFLSC_TIMEOUT_MS 300
 #define BITFORCE_TIMEOUT_MS 200
+#define BITFURY_TIMEOUT_MS 100
 #define MODMINER_TIMEOUT_MS 100
 #define AVALON_TIMEOUT_MS 200
 #define ICARUS_TIMEOUT_MS 200
@@ -92,15 +64,23 @@
 
 #define USB_EPS(_intx, _epinfosx) { \
 		.interface = _intx, \
+		.ctrl_transfer = _intx, \
 		.epinfo_count = ARRAY_SIZE(_epinfosx), \
 		.epinfos = _epinfosx \
 	}
 
+#define USB_EPS_CTRL(_inty, _ctrlinty, _epinfosy) { \
+		.interface = _inty, \
+		.ctrl_transfer = _ctrlinty, \
+		.epinfo_count = ARRAY_SIZE(_epinfosy), \
+		.epinfos = _epinfosy \
+	}
+
 #ifdef USE_BFLSC
 // N.B. transfer size is 512 with USB2.0, but only 64 with USB1.1
 static struct usb_epinfo bas_epinfos[] = {
-	{ LIBUSB_TRANSFER_TYPE_BULK,	64,	EPI(1), 0 },
-	{ LIBUSB_TRANSFER_TYPE_BULK,	64,	EPO(2), 0 }
+	{ LIBUSB_TRANSFER_TYPE_BULK,	64,	EPI(1), 0, 0, 0 },
+	{ LIBUSB_TRANSFER_TYPE_BULK,	64,	EPO(2), 0, 0, 0 }
 };
 
 static struct usb_intinfo bas_ints[] = {
@@ -111,8 +91,8 @@ static struct usb_intinfo bas_ints[] = {
 #ifdef USE_BITFORCE
 // N.B. transfer size is 512 with USB2.0, but only 64 with USB1.1
 static struct usb_epinfo bfl_epinfos[] = {
-	{ LIBUSB_TRANSFER_TYPE_BULK,	64,	EPI(1), 0 },
-	{ LIBUSB_TRANSFER_TYPE_BULK,	64,	EPO(2), 0 }
+	{ LIBUSB_TRANSFER_TYPE_BULK,	64,	EPI(1), 0, 0, 0 },
+	{ LIBUSB_TRANSFER_TYPE_BULK,	64,	EPO(2), 0, 0, 0 }
 };
 
 static struct usb_intinfo bfl_ints[] = {
@@ -120,10 +100,27 @@ static struct usb_intinfo bfl_ints[] = {
 };
 #endif
 
+#ifdef USE_BITFURY
+static struct usb_epinfo bfu0_epinfos[] = {
+	{ LIBUSB_TRANSFER_TYPE_INTERRUPT,	8,	EPI(2), 0, 0, 0 }
+};
+
+static struct usb_epinfo bfu1_epinfos[] = {
+	{ LIBUSB_TRANSFER_TYPE_BULK,	16,	EPI(3), 0, 0, 0 },
+	{ LIBUSB_TRANSFER_TYPE_BULK,	16,	EPO(4), 0, 0, 0 }
+};
+
+/* Default to interface 1 */
+static struct usb_intinfo bfu_ints[] = {
+	USB_EPS(1,  bfu1_epinfos),
+	USB_EPS(0,  bfu0_epinfos)
+};
+#endif
+
 #ifdef USE_MODMINER
 static struct usb_epinfo mmq_epinfos[] = {
-	{ LIBUSB_TRANSFER_TYPE_BULK,	64,	EPI(3), 0 },
-	{ LIBUSB_TRANSFER_TYPE_BULK,	64,	EPO(3), 0 }
+	{ LIBUSB_TRANSFER_TYPE_BULK,	64,	EPI(3), 0, 0, 0 },
+	{ LIBUSB_TRANSFER_TYPE_BULK,	64,	EPO(3), 0, 0, 0 }
 };
 
 static struct usb_intinfo mmq_ints[] = {
@@ -133,8 +130,8 @@ static struct usb_intinfo mmq_ints[] = {
 
 #ifdef USE_AVALON
 static struct usb_epinfo ava_epinfos[] = {
-	{ LIBUSB_TRANSFER_TYPE_BULK,	64,	EPI(1), 0 },
-	{ LIBUSB_TRANSFER_TYPE_BULK,	64,	EPO(2), 0 }
+	{ LIBUSB_TRANSFER_TYPE_BULK,	64,	EPI(1), 0, 0, 0 },
+	{ LIBUSB_TRANSFER_TYPE_BULK,	64,	EPO(2), 0, 0, 0 }
 };
 
 static struct usb_intinfo ava_ints[] = {
@@ -144,8 +141,8 @@ static struct usb_intinfo ava_ints[] = {
 
 #ifdef USE_ICARUS
 static struct usb_epinfo ica_epinfos[] = {
-	{ LIBUSB_TRANSFER_TYPE_BULK,	64,	EPI(3), 0 },
-	{ LIBUSB_TRANSFER_TYPE_BULK,	64,	EPO(2), 0 }
+	{ LIBUSB_TRANSFER_TYPE_BULK,	64,	EPI(3), 0, 0, 0 },
+	{ LIBUSB_TRANSFER_TYPE_BULK,	64,	EPO(2), 0, 0, 0 }
 };
 
 static struct usb_intinfo ica_ints[] = {
@@ -153,8 +150,8 @@ static struct usb_intinfo ica_ints[] = {
 };
 
 static struct usb_epinfo amu_epinfos[] = {
-	{ LIBUSB_TRANSFER_TYPE_BULK,	64,	EPI(1), 0 },
-	{ LIBUSB_TRANSFER_TYPE_BULK,	64,	EPO(1), 0 }
+	{ LIBUSB_TRANSFER_TYPE_BULK,	64,	EPI(1), 0, 0, 0 },
+	{ LIBUSB_TRANSFER_TYPE_BULK,	64,	EPO(1), 0, 0, 0 }
 };
 
 static struct usb_intinfo amu_ints[] = {
@@ -162,8 +159,8 @@ static struct usb_intinfo amu_ints[] = {
 };
 
 static struct usb_epinfo llt_epinfos[] = {
-	{ LIBUSB_TRANSFER_TYPE_BULK,	64,	EPI(1), 0 },
-	{ LIBUSB_TRANSFER_TYPE_BULK,	64,	EPO(2), 0 }
+	{ LIBUSB_TRANSFER_TYPE_BULK,	64,	EPI(1), 0, 0, 0 },
+	{ LIBUSB_TRANSFER_TYPE_BULK,	64,	EPO(2), 0, 0, 0 }
 };
 
 static struct usb_intinfo llt_ints[] = {
@@ -171,8 +168,8 @@ static struct usb_intinfo llt_ints[] = {
 };
 
 static struct usb_epinfo cmr1_epinfos[] = {
-	{ LIBUSB_TRANSFER_TYPE_BULK,	64,	EPI(1), 0 },
-	{ LIBUSB_TRANSFER_TYPE_BULK,	64,	EPO(2), 0 }
+	{ LIBUSB_TRANSFER_TYPE_BULK,	64,	EPI(1), 0, 0, 0 },
+	{ LIBUSB_TRANSFER_TYPE_BULK,	64,	EPO(2), 0, 0, 0 }
 };
 
 static struct usb_intinfo cmr1_ints[] = {
@@ -180,51 +177,45 @@ static struct usb_intinfo cmr1_ints[] = {
 };
 
 static struct usb_epinfo cmr2_epinfos0[] = {
-	{ LIBUSB_TRANSFER_TYPE_BULK,	64,	EPI(1), 0 },
-	{ LIBUSB_TRANSFER_TYPE_BULK,	64,	EPO(2), 0 }
+	{ LIBUSB_TRANSFER_TYPE_BULK,	64,	EPI(1), 0, 0, 0 },
+	{ LIBUSB_TRANSFER_TYPE_BULK,	64,	EPO(2), 0, 0, 0 }
 };
-#ifndef WIN32
 static struct usb_epinfo cmr2_epinfos1[] = {
-	{ LIBUSB_TRANSFER_TYPE_BULK,	64,	EPI(3), 0 },
-	{ LIBUSB_TRANSFER_TYPE_BULK,	64,	EPO(4), 0 },
+	{ LIBUSB_TRANSFER_TYPE_BULK,	64,	EPI(3), 0, 0, 0 },
+	{ LIBUSB_TRANSFER_TYPE_BULK,	64,	EPO(4), 0, 0, 0 },
 };
 static struct usb_epinfo cmr2_epinfos2[] = {
-	{ LIBUSB_TRANSFER_TYPE_BULK,	64,	EPI(5), 0 },
-	{ LIBUSB_TRANSFER_TYPE_BULK,	64,	EPO(6), 0 },
+	{ LIBUSB_TRANSFER_TYPE_BULK,	64,	EPI(5), 0, 0, 0 },
+	{ LIBUSB_TRANSFER_TYPE_BULK,	64,	EPO(6), 0, 0, 0 },
 };
 static struct usb_epinfo cmr2_epinfos3[] = {
-	{ LIBUSB_TRANSFER_TYPE_BULK,	64,	EPI(7), 0 },
-	{ LIBUSB_TRANSFER_TYPE_BULK,	64,	EPO(8), 0 }
+	{ LIBUSB_TRANSFER_TYPE_BULK,	64,	EPI(7), 0, 0, 0 },
+	{ LIBUSB_TRANSFER_TYPE_BULK,	64,	EPO(8), 0, 0, 0 }
 };
-#endif
 
 static struct usb_intinfo cmr2_ints[] = {
-	USB_EPS(0, cmr2_epinfos0)
-#ifndef WIN32
-	,
-	USB_EPS(1, cmr2_epinfos1),
-	USB_EPS(2, cmr2_epinfos2),
-	USB_EPS(3, cmr2_epinfos3)
-#endif
+	USB_EPS_CTRL(0, 1, cmr2_epinfos0),
+	USB_EPS_CTRL(1, 2, cmr2_epinfos1),
+	USB_EPS_CTRL(2, 3, cmr2_epinfos2),
+	USB_EPS_CTRL(3, 4, cmr2_epinfos3)
 };
 #endif
 
 #define IDVENDOR_FTDI 0x0403
 
 #define INTINFO(_ints) \
-		.which_intinfo = 0, \
 		.intinfo_count = ARRAY_SIZE(_ints), \
 		.intinfos = _ints
 
-#define USBEP(_usbdev, _epinfo) (_usbdev->found->intinfos[_usbdev->found->which_intinfo].epinfos[_epinfo].ep)
-#define FOUNDIF(_found) (_found->intinfos[_found->which_intinfo].interface)
-#define USBIF(_usbdev) FOUNDIF(_usbdev->found)
+#define USBEP(_usbdev, _intinfo, _epinfo) (_usbdev->found->intinfos[_intinfo].epinfos[_epinfo].ep)
+#define THISIF(_found, _this) (_found->intinfos[_this].interface)
+#define USBIF(_usbdev, _this) THISIF(_usbdev->found, _this)
 
 // TODO: Add support for (at least) Isochronous endpoints
 static struct usb_find_devices find_dev[] = {
 #ifdef USE_BFLSC
 	{
-		.drv = DRV_BFLSC,
+		.drv = DRIVER_bflsc,
 		.name = "BAS",
 		.ident = IDENT_BAS,
 		.idVendor = IDVENDOR_FTDI,
@@ -238,7 +229,7 @@ static struct usb_find_devices find_dev[] = {
 #endif
 #ifdef USE_BITFORCE
 	{
-		.drv = DRV_BITFORCE,
+		.drv = DRIVER_bitforce,
 		.name = "BFL",
 		.ident = IDENT_BFL,
 		.idVendor = IDVENDOR_FTDI,
@@ -250,9 +241,24 @@ static struct usb_find_devices find_dev[] = {
 		.latency = LATENCY_STD,
 		INTINFO(bfl_ints) },
 #endif
+#ifdef USE_BITFURY
+	{
+		.drv = DRIVER_bitfury,
+		.name = "BF1",
+		.ident = IDENT_BFU,
+		.idVendor = 0x03eb,
+		.idProduct = 0x204b,
+		.config = 1,
+		.timeout = BITFURY_TIMEOUT_MS,
+		.latency = LATENCY_UNUSED,
+		.iManufacturer = "BPMC",
+		.iProduct = "Bitfury BF1",
+		INTINFO(bfu_ints)
+	},
+#endif
 #ifdef USE_MODMINER
 	{
-		.drv = DRV_MODMINER,
+		.drv = DRIVER_modminer,
 		.name = "MMQ",
 		.ident = IDENT_MMQ,
 		.idVendor = 0x1fc9,
@@ -264,7 +270,7 @@ static struct usb_find_devices find_dev[] = {
 #endif
 #ifdef USE_AVALON
 	{
-		.drv = DRV_AVALON,
+		.drv = DRIVER_avalon,
 		.name = "BTB",
 		.ident = IDENT_BTB,
 		.idVendor = IDVENDOR_FTDI,
@@ -276,7 +282,7 @@ static struct usb_find_devices find_dev[] = {
 		.latency = 10,
 		INTINFO(ava_ints) },
 	{
-		.drv = DRV_AVALON,
+		.drv = DRIVER_avalon,
 		.name = "AVA",
 		.ident = IDENT_AVA,
 		.idVendor = IDVENDOR_FTDI,
@@ -288,14 +294,14 @@ static struct usb_find_devices find_dev[] = {
 #endif
 #ifdef USE_HASHFAST
 	{
-		.drv = DRV_HASHFAST,
+		.drv = DRIVER_hashfast,
 		.name = "HFA",
 		.ident = IDENT_HFA,
 	},
 #endif
 #ifdef USE_ICARUS
 	{
-		.drv = DRV_ICARUS,
+		.drv = DRIVER_icarus,
 		.name = "ICA",
 		.ident = IDENT_ICA,
 		.idVendor = 0x067b,
@@ -305,7 +311,7 @@ static struct usb_find_devices find_dev[] = {
 		.latency = LATENCY_UNUSED,
 		INTINFO(ica_ints) },
 	{
-		.drv = DRV_ICARUS,
+		.drv = DRIVER_icarus,
 		.name = "AMU",
 		.ident = IDENT_AMU,
 		.idVendor = 0x10c4,
@@ -315,7 +321,7 @@ static struct usb_find_devices find_dev[] = {
 		.latency = LATENCY_UNUSED,
 		INTINFO(amu_ints) },
 	{
-		.drv = DRV_ICARUS,
+		.drv = DRIVER_icarus,
 		.name = "BLT",
 		.ident = IDENT_BLT,
 		.idVendor = IDVENDOR_FTDI,
@@ -327,7 +333,7 @@ static struct usb_find_devices find_dev[] = {
 		INTINFO(llt_ints) },
 	// For any that don't match the above "BLT"
 	{
-		.drv = DRV_ICARUS,
+		.drv = DRIVER_icarus,
 		.name = "LLT",
 		.ident = IDENT_LLT,
 		.idVendor = IDVENDOR_FTDI,
@@ -337,7 +343,7 @@ static struct usb_find_devices find_dev[] = {
 		.latency = LATENCY_STD,
 		INTINFO(llt_ints) },
 	{
-		.drv = DRV_ICARUS,
+		.drv = DRIVER_icarus,
 		.name = "CMR",
 		.ident = IDENT_CMR1,
 		.idVendor = IDVENDOR_FTDI,
@@ -348,7 +354,7 @@ static struct usb_find_devices find_dev[] = {
 		.latency = LATENCY_STD,
 		INTINFO(cmr1_ints) },
 	{
-		.drv = DRV_ICARUS,
+		.drv = DRIVER_icarus,
 		.name = "CMR",
 		.ident = IDENT_CMR2,
 		.idVendor = IDVENDOR_FTDI,
@@ -363,7 +369,7 @@ static struct usb_find_devices find_dev[] = {
 // This is here so cgminer -n shows them
 // the ztex driver (as at 201303) doesn't use usbutils
 	{
-		.drv = DRV_ZTEX,
+		.drv = DRIVER_ztex,
 		.name = "ZTX",
 		.ident = IDENT_ZTX,
 		.idVendor = 0x221a,
@@ -371,33 +377,12 @@ static struct usb_find_devices find_dev[] = {
 		.config = 1,
 		.timeout = 100,
 		.latency = LATENCY_UNUSED,
-		.which_intinfo = 0,
 		.intinfo_count = 0,
 		.intinfos = NULL },
 #endif
-	{ DRV_LAST, NULL, 0, 0, 0, NULL, NULL, 0, 0, 0, 0, 0, 0, NULL }
+	{ DRIVER_MAX, NULL, 0, 0, 0, NULL, NULL, 0, 0, 0, 0, NULL }
 };
 
-#ifdef USE_BFLSC
-extern struct device_drv bflsc_drv;
-#endif
-
-#ifdef USE_BITFORCE
-extern struct device_drv bitforce_drv;
-#endif
-
-#ifdef USE_MODMINER
-extern struct device_drv modminer_drv;
-#endif
-
-#ifdef USE_ICARUS
-extern struct device_drv icarus_drv;
-#endif
-
-#ifdef USE_AVALON
-extern struct device_drv avalon_drv;
-#endif
-
 #define STRBUFLEN 256
 static const char *BLANK = "";
 static const char *space = " ";
@@ -543,12 +528,10 @@ static int next_stat = USB_NOSTAT;
 #endif // DO_USB_STATS
 
 /* Create usb_commands array from USB_PARSE_COMMANDS macro in usbutils.h */
-#define USB_ADD_COMMAND(X, Y) Y,
 char *usb_commands[] = {
-	USB_PARSE_COMMANDS
+	USB_PARSE_COMMANDS(JUMPTABLE)
 	"Null"
 };
-#undef USB_ADD_COMMAND
 
 #ifdef EOL
 #undef EOL
@@ -779,7 +762,7 @@ static void usb_full(ssize_t *count, libusb_device *dev, char **buf, size_t *off
 	if (!opt_usb_list_all) {
 		bool known = false;
 
-		for (i = 0; find_dev[i].drv != DRV_LAST; i++)
+		for (i = 0; find_dev[i].drv != DRIVER_MAX; i++)
 			if ((find_dev[i].idVendor == desc.idVendor) &&
 			    (find_dev[i].idProduct == desc.idProduct)) {
 				known = true;
@@ -1280,6 +1263,8 @@ static struct cg_usb_device *free_cgusb(struct cg_usb_device *cgusb)
 
 static void _usb_uninit(struct cgpu_info *cgpu)
 {
+	int ifinfo;
+
 	applog(LOG_DEBUG, "USB uninit %s%i",
 			cgpu->drv->name, cgpu->device_id);
 
@@ -1289,7 +1274,13 @@ static void _usb_uninit(struct cgpu_info *cgpu)
 		return;
 
 	if (cgpu->usbdev->handle) {
-		libusb_release_interface(cgpu->usbdev->handle, USBIF(cgpu->usbdev));
+		for (ifinfo = cgpu->usbdev->found->intinfo_count - 1; ifinfo >= 0; ifinfo--) {
+			libusb_release_interface(cgpu->usbdev->handle,
+						 THISIF(cgpu->usbdev->found, ifinfo));
+		}
+#ifdef LINUX
+		libusb_attach_kernel_driver(cgpu->usbdev->handle, THISIF(cgpu->usbdev->found, ifinfo));
+#endif
 		cg_wlock(&cgusb_fd_lock);
 		libusb_close(cgpu->usbdev->handle);
 		cgpu->usbdev->handle = NULL;
@@ -1317,7 +1308,7 @@ static void release_cgpu(struct cgpu_info *cgpu)
 {
 	struct cg_usb_device *cgusb = cgpu->usbdev;
 	struct cgpu_info *lookcgpu;
-	int which_intinfo, i;
+	int i;
 
 	applog(LOG_DEBUG, "USB release %s%i",
 			cgpu->drv->name, cgpu->device_id);
@@ -1335,7 +1326,6 @@ static void release_cgpu(struct cgpu_info *cgpu)
 	cgtime(&cgpu->usbinfo.last_nodev);
 
 	// Any devices sharing the same USB device should be marked also
-	// Currently only MMQ shares a USB device
 	for (i = 0; i < total_devices; i++) {
 		lookcgpu = get_devices(i);
 		if (lookcgpu != cgpu && lookcgpu->usbdev == cgusb) {
@@ -1350,15 +1340,12 @@ static void release_cgpu(struct cgpu_info *cgpu)
 		}
 	}
 
-	which_intinfo = cgpu->usbdev->found->which_intinfo;
 	_usb_uninit(cgpu);
-	if (which_intinfo == 0)
-		cgminer_usb_unlock_bd(cgpu->drv, cgpu->usbinfo.bus_number, cgpu->usbinfo.device_address);
+	cgminer_usb_unlock_bd(cgpu->drv, cgpu->usbinfo.bus_number, cgpu->usbinfo.device_address);
 }
 
 /*
- * Used by MMQ - use the same usbdev thus locking is across all 4 related devices
- * since they must use the same USB handle since they use the same interface
+ * Use the same usbdev thus locking is across all related devices
  */
 struct cgpu_info *usb_copy_cgpu(struct cgpu_info *orig)
 {
@@ -1382,80 +1369,11 @@ struct cgpu_info *usb_copy_cgpu(struct cgpu_info *orig)
 
 	copy->usbinfo.nodev = (copy->usbdev == NULL);
 
-	copy->usbinfo.devlock = orig->usbinfo.devlock;
-
 	DEVUNLOCK(orig, pstate);
 
 	return copy;
 }
 
-/*
- * Used by CMR - use a different usbdev - since they must use a different
- * USB handle due to using different interfaces (libusb requirement)
- * N.B. multiple interfaces don't as yet work in windows libusb
- * so the CMR defines above that use them are defined out in windows
- * Nothing else uses multiple interfaces as at 20130922
- */
-static struct cgpu_info *usb_dup_cgpu(struct cgpu_info *orig, int intinfo)
-{
-	struct cgpu_info *copy;
-
-	copy = calloc(1, sizeof(*copy));
-	if (unlikely(!copy))
-		quit(1, "Failed to calloc cgpu for %s in usb_dup_cgpu", orig->drv->dname);
-
-	copy->name = orig->name;
-	copy->drv = copy_drv(orig->drv);
-	copy->deven = orig->deven;
-	copy->threads = orig->threads;
-
-	if (orig->usbdev) {
-		copy->usbdev = calloc(1, sizeof(*(copy->usbdev)));
-		if (unlikely(!copy->usbdev))
-			quit(1, "Failed to calloc usbdev for %s in usb_dup_cgpu", orig->drv->dname);
-
-		copy->usbdev->found = malloc(sizeof(*(copy->usbdev->found)));
-		if (unlikely(!copy->usbdev->found))
-			quit(1, "Failed to malloc found for %s in usb_dup_cgpu", orig->drv->dname);
-		memcpy(copy->usbdev->found, orig->usbdev->found, sizeof(*(copy->usbdev->found)));
-
-		copy->usbdev->found->which_intinfo = intinfo;
-
-		copy->usbdev->descriptor = NULL; // don't need it
-		copy->usbdev->usb_type = orig->usbdev->usb_type;
-		copy->usbdev->ident = orig->usbdev->ident;
-		copy->usbdev->usbver = orig->usbdev->usbver;
-		copy->usbdev->cps = orig->usbdev->cps;
-		copy->usbdev->usecps = orig->usbdev->usecps;
-		if (orig->usbdev->prod_string == BLANK)
-			copy->usbdev->prod_string = (char *)BLANK;
-		else
-			copy->usbdev->prod_string = strdup(orig->usbdev->prod_string);
-		if (orig->usbdev->manuf_string == BLANK)
-			copy->usbdev->manuf_string = (char *)BLANK;
-		else
-			copy->usbdev->manuf_string = strdup(orig->usbdev->manuf_string);
-		if (orig->usbdev->serial_string == BLANK)
-			copy->usbdev->serial_string = (char *)BLANK;
-		else
-			copy->usbdev->serial_string = strdup(orig->usbdev->serial_string);
-		copy->usbdev->fwVersion = orig->usbdev->fwVersion;
-		copy->usbdev->interfaceVersion = orig->usbdev->interfaceVersion;
-	}
-
-	memcpy(&(copy->usbinfo), &(orig->usbinfo), sizeof(copy->usbinfo));
-
-	copy->usbinfo.nodev = (copy->usbdev == NULL);
-
-	copy->usbinfo.devlock = calloc(1, sizeof(*(copy->usbinfo.devlock)));
-	if (unlikely(!copy->usbinfo.devlock))
-		quit(1, "Failed to calloc devlock for %s in usb_dup_cgpu", orig->drv->dname);
-
-	rwlock_init(copy->usbinfo.devlock);
-
-	return copy;
-}
-
 struct cgpu_info *usb_alloc_cgpu(struct device_drv *drv, int threads)
 {
 	struct cgpu_info *cgpu = calloc(1, sizeof(*cgpu));
@@ -1473,7 +1391,7 @@ struct cgpu_info *usb_alloc_cgpu(struct device_drv *drv, int threads)
 	if (unlikely(!cgpu->usbinfo.devlock))
 		quit(1, "Failed to calloc devlock for %s in usb_alloc_cgpu", drv->dname);
 
-	rwlock_init(cgpu->usbinfo.devlock);
+	mutex_init(cgpu->usbinfo.devlock);
 
 	return cgpu;
 }
@@ -1508,7 +1426,7 @@ static int _usb_init(struct cgpu_info *cgpu, struct libusb_device *dev, struct u
 	char devstr[STRBUFLEN+1];
 	int err, ifinfo, epinfo, alt, epnum, pstate;
 	int bad = USB_INIT_FAIL;
-	int cfg;
+	int cfg, claimed = 0;
 
 	DEVLOCK(cgpu, pstate);
 
@@ -1519,7 +1437,7 @@ static int _usb_init(struct cgpu_info *cgpu, struct libusb_device *dev, struct u
 		snprintf(devpath, sizeof(devpath), "%d:%d-i%d",
 			(int)(cgpu->usbinfo.bus_number),
 			(int)(cgpu->usbinfo.device_address),
-			FOUNDIF(found));
+			THISIF(found, 0));
 	} else {
 		snprintf(devpath, sizeof(devpath), "%d:%d",
 			(int)(cgpu->usbinfo.bus_number),
@@ -1580,19 +1498,23 @@ static int _usb_init(struct cgpu_info *cgpu, struct libusb_device *dev, struct u
 		goto dame;
 	}
 
-#ifndef WIN32
-	if (libusb_kernel_driver_active(cgusb->handle, FOUNDIF(found)) == 1) {
-		applog(LOG_DEBUG, "USB init, kernel attached ... %s", devstr);
-		err = libusb_detach_kernel_driver(cgusb->handle, FOUNDIF(found));
-		if (err == 0) {
-			applog(LOG_DEBUG,
-				"USB init, kernel detached interface %d successfully %s",
-				FOUNDIF(found), devstr);
-		} else {
-			applog(LOG_WARNING,
-				"USB init, kernel detach interface %d failed, err %d in use? %s",
-				FOUNDIF(found), err, devstr);
-			goto cldame;
+#ifdef LINUX
+	for (ifinfo = 0; ifinfo < found->intinfo_count; ifinfo++) {
+		if (libusb_kernel_driver_active(cgusb->handle, THISIF(found, ifinfo)) == 1) {
+			applog(LOG_DEBUG, "USB init, kernel attached ... %s", devstr);
+			err = libusb_detach_kernel_driver(cgusb->handle, THISIF(found, ifinfo));
+			if (err == 0) {
+				applog(LOG_DEBUG,
+					"USB init, kernel detached ifinfo %d interface %d"
+					" successfully %s",
+					ifinfo, THISIF(found, ifinfo), devstr);
+			} else {
+				applog(LOG_WARNING,
+					"USB init, kernel detach ifinfo %d interface %d failed,"
+					" err %d in use? %s",
+					ifinfo, THISIF(found, ifinfo), err, devstr);
+				goto nokernel;
+			}
 		}
 	}
 #endif
@@ -1697,8 +1619,7 @@ static int _usb_init(struct cgpu_info *cgpu, struct libusb_device *dev, struct u
 						&&  epdesc->wMaxPacketSize >= epinfos[epinfo].size
 						&&  epdesc->bEndpointAddress == epinfos[epinfo].ep) {
 							epinfos[epinfo].found = true;
-							// TODO: it's an ep (not device) attribute
-							found->wMaxPacketSize = epdesc->wMaxPacketSize;
+							epinfos[epinfo].wMaxPacketSize = epdesc->wMaxPacketSize;
 							break;
 						}
 					}
@@ -1715,20 +1636,26 @@ static int _usb_init(struct cgpu_info *cgpu, struct libusb_device *dev, struct u
 				goto cldame;
 			}
 
-	err = libusb_claim_interface(cgusb->handle, FOUNDIF(found));
-	if (err) {
-		switch(err) {
-			case LIBUSB_ERROR_BUSY:
-				applog(LOG_WARNING,
-					"USB init, claim interface %d in use %s",
-					FOUNDIF(found), devstr);
-				break;
-			default:
-				applog(LOG_DEBUG,
-					"USB init, claim interface %d failed, err %d %s",
-					FOUNDIF(found), err, devstr);
+	claimed = 0;
+	for (ifinfo = 0; ifinfo < found->intinfo_count; ifinfo++) {
+		err = libusb_claim_interface(cgusb->handle, THISIF(found, ifinfo));
+		if (err == 0)
+			claimed++;
+		else {
+			switch(err) {
+				case LIBUSB_ERROR_BUSY:
+					applog(LOG_WARNING,
+						"USB init, claim ifinfo %d interface %d in use %s",
+						ifinfo, THISIF(found, ifinfo), devstr);
+					break;
+				default:
+					applog(LOG_DEBUG,
+						"USB init, claim ifinfo %d interface %d failed,"
+						" err %d %s",
+						ifinfo, THISIF(found, ifinfo), err, devstr);
+			}
+			goto reldame;
 		}
-		goto reldame;
 	}
 
 	cfg = -1;
@@ -1795,10 +1722,16 @@ static int _usb_init(struct cgpu_info *cgpu, struct libusb_device *dev, struct u
 
 reldame:
 
-	libusb_release_interface(cgusb->handle, FOUNDIF(found));
+	ifinfo = claimed;
+	while (ifinfo-- > 0)
+		libusb_release_interface(cgusb->handle, THISIF(found, ifinfo));
 
 cldame:
+#ifdef LINUX
+	libusb_attach_kernel_driver(cgusb->handle, THISIF(found, ifinfo));
 
+nokernel:
+#endif
 	cg_wlock(&cgusb_fd_lock);
 	libusb_close(cgusb->handle);
 	cgusb->handle = NULL;
@@ -1817,151 +1750,13 @@ out_unlock:
 	return bad;
 }
 
-// To get the extra interfaces on a multi interface device
-struct cgpu_info *usb_init_intinfo(struct cgpu_info *orig, int intinfo)
-{
-	struct usb_find_devices *found;
-	struct libusb_device *dev;
-	struct cgpu_info *copy = NULL;
-	char msgstr[STRBUFLEN+1];
-	char devstr[STRBUFLEN+1];
-	char devpath[32];
-	int err, pstate;
-
-	DEVLOCK(orig, pstate);
-
-	snprintf(msgstr, sizeof(msgstr), "USB %s init_intinfo (%d:%d-i%d)",
-			orig->drv->dname,
-			(int)(orig->usbinfo.bus_number),
-			(int)(orig->usbinfo.device_address),
-			orig->usbdev->found->which_intinfo);
-
-	if (orig->usbinfo.nodev) {
-		applog(LOG_ERR, "%s cgpu has nodev", msgstr);
-		goto Hitagi;
-	}
-
-	if (orig->usbdev->found->which_intinfo != 0) {
-		applog(LOG_ERR, "%s incorrect cgpu (must be i0)", msgstr);
-		goto Hitagi;
-	}
-
-	if (orig->usbdev->found->intinfo_count < 2) {
-		applog(LOG_ERR, "%s cgpu only has 1 interface", msgstr);
-		goto Hitagi;
-	}
-
-	if (intinfo < 1 || intinfo >= orig->usbdev->found->intinfo_count) {
-		applog(LOG_ERR, "%s invalid intinfo (%d) must be > 0 && < %d",
-				msgstr, intinfo, orig->usbdev->found->intinfo_count);
-		goto Hitagi;
-	}
-
-	dev = libusb_get_device(orig->usbdev->handle);
-
-	copy = usb_dup_cgpu(orig, intinfo);
-	if (!copy)
-		goto Hitagi;
-
-	found = copy->usbdev->found;
-
-	snprintf(devpath, sizeof(devpath), "%d:%d-i%d",
-		(int)(copy->usbinfo.bus_number),
-		(int)(copy->usbinfo.device_address),
-		FOUNDIF(found));
-
-	copy->device_path = strdup(devpath);
-
-	snprintf(devstr, sizeof(devstr), "- %s device %s", found->name, devpath);
-
-	cg_wlock(&cgusb_fd_lock);
-	err = libusb_open(dev, &(copy->usbdev->handle));
-	cg_wunlock(&cgusb_fd_lock);
-	if (err) {
-		switch (err) {
-			case LIBUSB_ERROR_ACCESS:
-				applog(LOG_ERR,
-					"USB init_intinfo, open device failed, err %d, "
-					"you don't have privilege to access %s",
-					err, devstr);
-				break;
-#ifdef WIN32
-			// Windows specific message
-			case LIBUSB_ERROR_NOT_SUPPORTED:
-				applog(LOG_ERR,
-					"USB init_intinfo, open device failed, err %d, "
-					"you need to install a WinUSB driver for %s",
-					err, devstr);
-				break;
-#endif
-			default:
-				applog(LOG_DEBUG,
-					"USB init_intinfo, open failed, err %d %s",
-					err, devstr);
-		}
-		goto Hitagi;
-	}
-
-#ifndef WIN32
-	if (libusb_kernel_driver_active(copy->usbdev->handle, FOUNDIF(found)) == 1) {
-		applog(LOG_DEBUG, "USB init_intinfo, kernel attached ... %s", devstr);
-		err = libusb_detach_kernel_driver(copy->usbdev->handle, FOUNDIF(found));
-		if (err == 0) {
-			applog(LOG_DEBUG,
-				"USB init_intinfo, kernel detached interface %d successfully %s",
-				FOUNDIF(found), devstr);
-		} else {
-			applog(LOG_WARNING,
-				"USB init_intinfo, kernel detach interface %d failed, err %d in use? %s",
-				FOUNDIF(found), err, devstr);
-			goto HitagiClose;
-		}
-	}
-#endif
-
-	err = libusb_claim_interface(copy->usbdev->handle, FOUNDIF(found));
-	if (err) {
-		switch(err) {
-			case LIBUSB_ERROR_BUSY:
-				applog(LOG_WARNING,
-					"USB init_intinfo, claim interface %d in use %s",
-					FOUNDIF(found), devstr);
-				break;
-			default:
-				applog(LOG_DEBUG,
-					"USB init_intinfo, claim interface %d failed, err %d %s",
-					FOUNDIF(found), err, devstr);
-		}
-		goto HitagiClose;
-	}
-
-	goto Hitagi;
-
-HitagiClose:
-
-	cg_wlock(&cgusb_fd_lock);
-	libusb_close(copy->usbdev->handle);
-	copy->usbdev->handle = NULL;
-	cg_wunlock(&cgusb_fd_lock);
-
-	copy->usbdev = free_cgusb(copy->usbdev);
-
-	copy = usb_free_cgpu(copy);
-
-Hitagi:
-
-	DEVUNLOCK(orig, pstate);
-
-	return copy;
-}
-
 bool usb_init(struct cgpu_info *cgpu, struct libusb_device *dev, struct usb_find_devices *found_match)
 {
 	struct usb_find_devices *found_use = NULL;
 	int uninitialised_var(ret);
 	int i;
 
-	for (i = 0; find_dev[i].drv != DRV_LAST; i++) {
+	for (i = 0; find_dev[i].drv != DRIVER_MAX; i++) {
 		if (find_dev[i].drv == found_match->drv &&
 		    find_dev[i].idVendor == found_match->idVendor &&
 		    find_dev[i].idProduct == found_match->idProduct) {
@@ -2038,7 +1833,7 @@ static struct usb_find_devices *usb_check_each(int drvnum, struct device_drv *dr
 	struct usb_find_devices *found;
 	int i;
 
-	for (i = 0; find_dev[i].drv != DRV_LAST; i++)
+	for (i = 0; find_dev[i].drv != DRIVER_MAX; i++)
 		if (find_dev[i].drv == drvnum) {
 			if (usb_check_device(drv, dev, &(find_dev[i]))) {
 				found = malloc(sizeof(*found));
@@ -2052,6 +1847,9 @@ static struct usb_find_devices *usb_check_each(int drvnum, struct device_drv *dr
 	return NULL;
 }
 
+#define DRIVER_USB_CHECK_EACH(X) 	if (drv->drv_id == DRIVER_##X) \
+		return usb_check_each(DRIVER_##X, drv, dev);
+
 static struct usb_find_devices *usb_check(__maybe_unused struct device_drv *drv, __maybe_unused struct libusb_device *dev)
 {
 	if (drv_count[drv->drv_id].count >= drv_count[drv->drv_id].limit) {
@@ -2061,30 +1859,7 @@ static struct usb_find_devices *usb_check(__maybe_unused struct device_drv *drv,
 		return NULL;
 	}
 
-#ifdef USE_BFLSC
-	if (drv->drv_id == DRIVER_BFLSC)
-		return usb_check_each(DRV_BFLSC, drv, dev);
-#endif
-
-#ifdef USE_BITFORCE
-	if (drv->drv_id == DRIVER_BITFORCE)
-		return usb_check_each(DRV_BITFORCE, drv, dev);
-#endif
-
-#ifdef USE_MODMINER
-	if (drv->drv_id == DRIVER_MODMINER)
-		return usb_check_each(DRV_MODMINER, drv, dev);
-#endif
-
-#ifdef USE_ICARUS
-	if (drv->drv_id == DRIVER_ICARUS)
-		return usb_check_each(DRV_ICARUS, drv, dev);
-#endif
-
-#ifdef USE_AVALON
-	if (drv->drv_id == DRIVER_AVALON)
-		return usb_check_each(DRV_AVALON, drv, dev);
-#endif
+	DRIVER_PARSE_COMMANDS(DRIVER_USB_CHECK_EACH)
 
 	return NULL;
 }
@@ -2432,12 +2207,14 @@ static char *find_end(unsigned char *buf, unsigned char *ptr, int ptrlen, int to
 #define USB_RETRY_MAX 5
 
 static int
-usb_bulk_transfer(struct libusb_device_handle *dev_handle,
-		  unsigned char endpoint, unsigned char *data, int length,
+usb_bulk_transfer(struct libusb_device_handle *dev_handle, int intinfo,
+		  int epinfo, unsigned char *data, int length,
 		  int *transferred, unsigned int timeout,
 		  struct cgpu_info *cgpu, __maybe_unused int mode,
 		  enum usb_cmds cmd, __maybe_unused int seq)
 {
+	struct usb_epinfo *usb_epinfo;
+	unsigned char endpoint;
 	uint16_t MaxPacketSize;
 	int err, errn, tries = 0;
 #if DO_USB_STATS
@@ -2445,21 +2222,26 @@ usb_bulk_transfer(struct libusb_device_handle *dev_handle,
 #endif
 	unsigned char *buf;
 
+	usb_epinfo = &(cgpu->usbdev->found->intinfos[intinfo].epinfos[epinfo]);
+	endpoint = usb_epinfo->ep;
+
 	/* Limit length of transfer to the largest this descriptor supports
 	 * and leave the higher level functions to transfer more if needed. */
-	if (cgpu->usbdev->PrefPacketSize)
-		MaxPacketSize = cgpu->usbdev->PrefPacketSize;
+	if (usb_epinfo->PrefPacketSize)
+		MaxPacketSize = usb_epinfo->PrefPacketSize;
 	else
-		MaxPacketSize = cgpu->usbdev->found->wMaxPacketSize;
+		MaxPacketSize = usb_epinfo->wMaxPacketSize;
 	if (length > MaxPacketSize)
 		length = MaxPacketSize;
 	buf = alloca(MaxPacketSize);
-	if (endpoint == LIBUSB_ENDPOINT_OUT)
+	if ((endpoint & LIBUSB_ENDPOINT_DIR_MASK) == LIBUSB_ENDPOINT_OUT)
 		memcpy(buf, data, length);
 
+	USBDEBUG("USB debug: @usb_bulk_transfer(%s (nodev=%s),intinfo=%d,epinfo=%d,data=%p,length=%d,timeout=%u,mode=%d,cmd=%s,seq=%d) endpoint=%d", cgpu->drv->name, bool_str(cgpu->usbinfo.nodev), intinfo, epinfo, data, length, timeout, mode, usb_cmdname(cmd), seq, (int)endpoint);
+
 	STATS_TIMEVAL(&tv_start);
 	cg_rlock(&cgusb_fd_lock);
-	err = libusb_bulk_transfer(dev_handle, endpoint, data, length,
+	err = libusb_bulk_transfer(dev_handle, endpoint, buf, length,
 				   transferred, timeout);
 	errn = errno;
 	cg_runlock(&cgusb_fd_lock);
@@ -2486,7 +2268,7 @@ usb_bulk_transfer(struct libusb_device_handle *dev_handle,
 
 			STATS_TIMEVAL(&tv_start);
 			cg_rlock(&cgusb_fd_lock);
-			err = libusb_bulk_transfer(dev_handle, endpoint, data,
+			err = libusb_bulk_transfer(dev_handle, endpoint, buf,
 						   length, transferred, timeout);
 			errn = errno;
 			cg_runlock(&cgusb_fd_lock);
@@ -2507,13 +2289,13 @@ usb_bulk_transfer(struct libusb_device_handle *dev_handle,
 		if (err)
 			cgpu->usbinfo.clear_fail_count++;
 	}
-	if (endpoint == LIBUSB_ENDPOINT_OUT)
+	if ((endpoint & LIBUSB_ENDPOINT_DIR_MASK) == LIBUSB_ENDPOINT_IN)
 		memcpy(data, buf, length);
 
 	return err;
 }
 
-int _usb_read(struct cgpu_info *cgpu, int epinfo, char *buf, size_t bufsiz, int *processed, unsigned int timeout, const char *end, enum usb_cmds cmd, bool readonce)
+int _usb_read(struct cgpu_info *cgpu, int intinfo, int epinfo, char *buf, size_t bufsiz, int *processed, unsigned int timeout, const char *end, enum usb_cmds cmd, bool readonce)
 {
 	struct cg_usb_device *usbdev;
 	bool ftdi;
@@ -2541,7 +2323,7 @@ int _usb_read(struct cgpu_info *cgpu, int epinfo, char *buf, size_t bufsiz, int 
 	usbdev = cgpu->usbdev;
 	ftdi = (usbdev->usb_type == USB_TYPE_FTDI);
 
-	USBDEBUG("USB debug: _usb_read(%s (nodev=%s),epinfo=%d,buf=%p,bufsiz=%zu,proc=%p,timeout=%u,end=%s,cmd=%s,ftdi=%s,readonce=%s)", cgpu->drv->name, bool_str(cgpu->usbinfo.nodev), epinfo, buf, bufsiz, processed, timeout, end ? (char *)str_text((char *)end) : "NULL", usb_cmdname(cmd), bool_str(ftdi), bool_str(readonce));
+	USBDEBUG("USB debug: _usb_read(%s (nodev=%s),intinfo=%d,epinfo=%d,buf=%p,bufsiz=%d,proc=%p,timeout=%u,end=%s,cmd=%s,ftdi=%s,readonce=%s)", cgpu->drv->name, bool_str(cgpu->usbinfo.nodev), intinfo, epinfo, buf, (int)bufsiz, processed, timeout, end ? (char *)str_text((char *)end) : "NULL", usb_cmdname(cmd), bool_str(ftdi), bool_str(readonce));
 
 	if (bufsiz > USB_MAX_READ)
 		quit(1, "%s USB read request %d too large (max=%d)", cgpu->drv->name, (int)bufsiz, USB_MAX_READ);
@@ -2594,14 +2376,13 @@ int _usb_read(struct cgpu_info *cgpu, int epinfo, char *buf, size_t bufsiz, int 
 					cgpu->usbinfo.total_read_delay += sleep_estimate;
 				}
 			}
-			err = usb_bulk_transfer(usbdev->handle,
-						USBEP(usbdev, epinfo),
+			err = usb_bulk_transfer(usbdev->handle, intinfo, epinfo,
 						ptr, usbbufread, &got, timeout,
 						cgpu, MODE_BULK_READ, cmd, first ? SEQ0 : SEQ1);
 			cgtime(&tv_finish);
 			ptr[got] = '\0';
 
-			USBDEBUG("USB debug: @_usb_read(%s (nodev=%s)) first=%s err=%d%s got=%d ptr='%s' usbbufread=%zu", cgpu->drv->name, bool_str(cgpu->usbinfo.nodev), bool_str(first), err, isnodev(err), got, (char *)str_text((char *)ptr), usbbufread);
+			USBDEBUG("USB debug: @_usb_read(%s (nodev=%s)) first=%s err=%d%s got=%d ptr='%s' usbbufread=%d", cgpu->drv->name, bool_str(cgpu->usbinfo.nodev), bool_str(first), err, isnodev(err), got, (char *)str_text((char *)ptr), (int)usbbufread);
 
 			IOERR_CHECK(cgpu, err);
 
@@ -2641,7 +2422,7 @@ int _usb_read(struct cgpu_info *cgpu, int epinfo, char *buf, size_t bufsiz, int 
 			memcpy(usbdev->buffer, usbbuf + bufsiz, usbdev->bufamt);
 			tot -= usbdev->bufamt;
 			usbbuf[tot] = '\0';
-			applog(LOG_ERR, "USB: %s%i read1 buffering %d extra bytes",
+			applog(LOG_INFO, "USB: %s%i read1 buffering %d extra bytes",
 					cgpu->drv->name, cgpu->device_id, usbdev->bufamt);
 		}
 
@@ -2698,14 +2479,13 @@ int _usb_read(struct cgpu_info *cgpu, int epinfo, char *buf, size_t bufsiz, int 
 				cgpu->usbinfo.total_read_delay += sleep_estimate;
 			}
 		}
-		err = usb_bulk_transfer(usbdev->handle,
-					USBEP(usbdev, epinfo), ptr,
-					usbbufread, &got, timeout,
+		err = usb_bulk_transfer(usbdev->handle, intinfo, epinfo,
+					ptr, usbbufread, &got, timeout,
 					cgpu, MODE_BULK_READ, cmd, first ? SEQ0 : SEQ1);
 		cgtime(&tv_finish);
 		ptr[got] = '\0';
 
-		USBDEBUG("USB debug: @_usb_read(%s (nodev=%s)) first=%s err=%d%s got=%d ptr='%s' usbbufread=%zu", cgpu->drv->name, bool_str(cgpu->usbinfo.nodev), bool_str(first), err, isnodev(err), got, (char *)str_text((char *)ptr), usbbufread);
+		USBDEBUG("USB debug: @_usb_read(%s (nodev=%s)) first=%s err=%d%s got=%d ptr='%s' usbbufread=%d", cgpu->drv->name, bool_str(cgpu->usbinfo.nodev), bool_str(first), err, isnodev(err), got, (char *)str_text((char *)ptr), (int)usbbufread);
 
 		IOERR_CHECK(cgpu, err);
 
@@ -2786,7 +2566,7 @@ out_unlock:
 	return err;
 }
 
-int _usb_write(struct cgpu_info *cgpu, int epinfo, char *buf, size_t bufsiz, int *processed, unsigned int timeout, enum usb_cmds cmd)
+int _usb_write(struct cgpu_info *cgpu, int intinfo, int epinfo, char *buf, size_t bufsiz, int *processed, unsigned int timeout, enum usb_cmds cmd)
 {
 	struct cg_usb_device *usbdev;
 	struct timeval read_start, tv_finish;
@@ -2797,7 +2577,7 @@ int _usb_write(struct cgpu_info *cgpu, int epinfo, char *buf, size_t bufsiz, int
 
 	DEVLOCK(cgpu, pstate);
 
-	USBDEBUG("USB debug: _usb_write(%s (nodev=%s),epinfo=%d,buf='%s',bufsiz=%zu,proc=%p,timeout=%u,cmd=%s)", cgpu->drv->name, bool_str(cgpu->usbinfo.nodev), epinfo, (char *)str_text(buf), bufsiz, processed, timeout, usb_cmdname(cmd));
+	USBDEBUG("USB debug: _usb_write(%s (nodev=%s),intinfo=%d,epinfo=%d,buf='%s',bufsiz=%d,proc=%p,timeout=%u,cmd=%s)", cgpu->drv->name, bool_str(cgpu->usbinfo.nodev), intinfo, epinfo, (char *)str_text(buf), (int)bufsiz, processed, timeout, usb_cmdname(cmd));
 
 	*processed = 0;
 
@@ -2839,10 +2619,9 @@ int _usb_write(struct cgpu_info *cgpu, int epinfo, char *buf, size_t bufsiz, int
 			cgsleep_prepare_r(&usbdev->cgt_last_write);
 			usbdev->last_write_siz = bufsiz;
 		}
-		err = usb_bulk_transfer(usbdev->handle,
-					USBEP(usbdev, epinfo),
-					(unsigned char *)buf, bufsiz, &sent,
-					timeout, cgpu, MODE_BULK_WRITE, cmd, first ? SEQ0 : SEQ1);
+		err = usb_bulk_transfer(usbdev->handle, intinfo, epinfo,
+					(unsigned char *)buf, bufsiz, &sent, timeout,
+					cgpu, MODE_BULK_WRITE, cmd, first ? SEQ0 : SEQ1);
 		cgtime(&tv_finish);
 
 		USBDEBUG("USB debug: @_usb_write(%s (nodev=%s)) err=%d%s sent=%d", cgpu->drv->name, bool_str(cgpu->usbinfo.nodev), err, isnodev(err), sent);
@@ -3057,7 +2836,7 @@ int usb_ftdi_cts(struct cgpu_info *cgpu)
 	return (ret & FTDI_RS0_CTS);
 }
 
-int usb_ftdi_set_latency(struct cgpu_info *cgpu)
+int _usb_ftdi_set_latency(struct cgpu_info *cgpu, int intinfo)
 {
 	int err = 0;
 	int pstate;
@@ -3078,7 +2857,7 @@ int usb_ftdi_set_latency(struct cgpu_info *cgpu)
 		if (!err)
 			err = __usb_transfer(cgpu, FTDI_TYPE_OUT, FTDI_REQUEST_LATENCY,
 						cgpu->usbdev->found->latency,
-						USBIF(cgpu->usbdev),
+						USBIF(cgpu->usbdev, intinfo),
 						NULL, 0, DEVTIMEOUT, C_LATENCY);
 	}
 
@@ -3196,8 +2975,10 @@ void usb_disable_cps(struct cgpu_info *cgpu)
  * The value returned (0) when usbdev is NULL
  * doesn't matter since it also means the next call to
  * any usbutils function will fail with a nodev
+ * N.B. this is to get the interface number to use in a control_transfer
+ * which for some devices isn't actually the interface number
  */
-int usb_interface(struct cgpu_info *cgpu)
+int _usb_interface(struct cgpu_info *cgpu, int intinfo)
 {
 	int interface = 0;
 	int pstate;
@@ -3205,7 +2986,7 @@ int usb_interface(struct cgpu_info *cgpu)
 	DEVLOCK(cgpu, pstate);
 
 	if (cgpu->usbdev)
-		interface = USBIF(cgpu->usbdev);
+		interface = cgpu->usbdev->found->intinfos[intinfo].ctrl_transfer;
 
 	DEVUNLOCK(cgpu, pstate);
 
@@ -3227,14 +3008,36 @@ enum sub_ident usb_ident(struct cgpu_info *cgpu)
 	return ident;
 }
 
-void usb_set_pps(struct cgpu_info *cgpu, uint16_t PrefPacketSize)
+/*
+ * If you pass both intinfo and epinfo as <0 then it will set all
+ * endpoints to PrefPacketSize
+ * If intinfo >=0 but epinfo <0 then it will set all endpoints
+ * for the given one intinfo to PrefPacketSize
+ * If both are >=0 then it will set only the specified single
+ * endpoint (intinfo,epinfo) to PrefPacketSize
+ */
+void _usb_set_pps(struct cgpu_info *cgpu, int intinfo, int epinfo, uint16_t PrefPacketSize)
 {
+	struct usb_find_devices *found;
 	int pstate;
 
 	DEVLOCK(cgpu, pstate);
 
-	if (cgpu->usbdev)
-		cgpu->usbdev->PrefPacketSize = PrefPacketSize;
+	if (cgpu->usbdev) {
+		found = cgpu->usbdev->found;
+		if (intinfo >= 0 && epinfo >= 0)
+			found->intinfos[intinfo].epinfos[epinfo].PrefPacketSize = PrefPacketSize;
+		else {
+			if (intinfo >= 0) {
+				for (epinfo = 0; epinfo < found->intinfos[intinfo].epinfo_count; epinfo++)
+					found->intinfos[intinfo].epinfos[epinfo].PrefPacketSize = PrefPacketSize;
+			} else {
+				for (intinfo = 0; intinfo < found->intinfo_count ; intinfo++)
+					for (epinfo = 0; epinfo < found->intinfos[intinfo].epinfo_count; epinfo++)
+						found->intinfos[intinfo].epinfos[epinfo].PrefPacketSize = PrefPacketSize;
+			}
+		}
+	}
 
 	DEVUNLOCK(cgpu, pstate);
 }
@@ -3281,14 +3084,15 @@ void usb_cleanup()
 	for (i = 0; i < total_devices; i++) {
 		cgpu = devices[i];
 		switch (cgpu->drv->drv_id) {
-			case DRIVER_BFLSC:
-			case DRIVER_BITFORCE:
-			case DRIVER_MODMINER:
-			case DRIVER_ICARUS:
-			case DRIVER_AVALON:
-				wr_lock(cgpu->usbinfo.devlock);
+			case DRIVER_bflsc:
+			case DRIVER_bitforce:
+			case DRIVER_bitfury:
+			case DRIVER_modminer:
+			case DRIVER_icarus:
+			case DRIVER_avalon:
+				mutex_lock(cgpu->usbinfo.devlock);
 				release_cgpu(cgpu);
-				wr_unlock(cgpu->usbinfo.devlock);
+				mutex_unlock(cgpu->usbinfo.devlock);
 				count++;
 				break;
 			default:
@@ -3327,6 +3131,10 @@ void usb_cleanup()
 	cgsem_destroy(&usb_resource_sem);
 }
 
+#define DRIVER_COUNT_FOUND(X) if (strcasecmp(ptr, X##_drv.name) == 0) { \
+	drv_count[X##_drv.drv_id].limit = lim; \
+	found = true; \
+	}
 void usb_initialise()
 {
 	char *fre, *ptr, *comma, *colon;
@@ -3410,36 +3218,9 @@ void usb_initialise()
 					quit(1, "Invalid --usb DRV:limit - limit must be >= 0");
 
 				found = false;
-#ifdef USE_BFLSC
-				if (strcasecmp(ptr, bflsc_drv.name) == 0) {
-					drv_count[bflsc_drv.drv_id].limit = lim;
-					found = true;
-				}
-#endif
-#ifdef USE_BITFORCE
-				if (!found && strcasecmp(ptr, bitforce_drv.name) == 0) {
-					drv_count[bitforce_drv.drv_id].limit = lim;
-					found = true;
-				}
-#endif
-#ifdef USE_MODMINER
-				if (!found && strcasecmp(ptr, modminer_drv.name) == 0) {
-					drv_count[modminer_drv.drv_id].limit = lim;
-					found = true;
-				}
-#endif
-#ifdef USE_ICARUS
-				if (!found && strcasecmp(ptr, icarus_drv.name) == 0) {
-					drv_count[icarus_drv.drv_id].limit = lim;
-					found = true;
-				}
-#endif
-#ifdef USE_AVALON
-				if (!found && strcasecmp(ptr, avalon_drv.name) == 0) {
-					drv_count[avalon_drv.drv_id].limit = lim;
-					found = true;
-				}
-#endif
+				/* Use the DRIVER_PARSE_COMMANDS macro to iterate
+				 * over all the drivers. */
+				DRIVER_PARSE_COMMANDS(DRIVER_COUNT_FOUND)
 				if (!found)
 					quit(1, "Invalid --usb DRV:limit - unknown DRV='%s'", ptr);
 
diff --git a/usbutils.h b/usbutils.h
index e0aea5a..bd823c7 100644
--- a/usbutils.h
+++ b/usbutils.h
@@ -109,6 +109,9 @@
 // Use the device defined timeout
 #define DEVTIMEOUT 0
 
+// The default intinfo structure used is the first one
+#define DEFAULT_INTINFO 0
+
 // For endpoints defined in usb_find_devices.intinfos.epinfos,
 // the first two must be the default IN and OUT and both must always exist
 #define DEFAULT_EP_IN 0
@@ -118,11 +121,14 @@ struct usb_epinfo {
 	uint8_t att;
 	uint16_t size;
 	unsigned char ep;
+	uint16_t wMaxPacketSize;
+	uint16_t PrefPacketSize;
 	bool found;
 };
 
 struct usb_intinfo {
 	int interface;
+	int ctrl_transfer;
 	int epinfo_count;
 	struct usb_epinfo *epinfos;
 };
@@ -134,6 +140,7 @@ enum sub_ident {
 	IDENT_BAS,
 	IDENT_BAM,
 	IDENT_BFL,
+	IDENT_BFU,
 	IDENT_MMQ,
 	IDENT_AVA,
 	IDENT_BTB,
@@ -157,9 +164,7 @@ struct usb_find_devices {
 	char *iProduct;
 	int config;
 	unsigned int timeout;
-	uint16_t wMaxPacketSize;
 	uint16_t latency;
-	int which_intinfo;
 	int intinfo_count;
 	struct usb_intinfo *intinfos;
 };
@@ -193,7 +198,6 @@ struct cg_usb_device {
 	char *buffer;
 	uint32_t bufsiz;
 	uint32_t bufamt;
-	uint16_t PrefPacketSize;
 	cgtimer_t cgt_last_write;
 	size_t last_write_siz;
 };
@@ -234,7 +238,7 @@ struct cg_usb_info {
 	 * that uses the lock - however, all usbutils code MUST use it
 	 * to avoid devices disappearing while in use by multiple threads
 	 */
-	pthread_rwlock_t *devlock;
+	pthread_mutex_t *devlock;
 
 	time_t last_pipe;
 	uint64_t pipe_count;
@@ -258,7 +262,10 @@ struct cg_usb_info {
 	struct cg_usb_tmo usb_tmo[USB_TMOS];
 };
 
-#define USB_PARSE_COMMANDS \
+#define ENUMERATION(a,b) a,
+#define JUMPTABLE(a,b) b,
+
+#define USB_PARSE_COMMANDS(USB_ADD_COMMAND) \
 	USB_ADD_COMMAND(C_REJECTED, "RejectedNoDevice") \
 	USB_ADD_COMMAND(C_PING, "Ping") \
 	USB_ADD_COMMAND(C_CLEAR, "Clear") \
@@ -322,6 +329,20 @@ struct cg_usb_info {
 	USB_ADD_COMMAND(C_ENABLE_UART, "EnableUART") \
 	USB_ADD_COMMAND(C_BB_SET_VOLTAGE, "SetCoreVoltage") \
 	USB_ADD_COMMAND(C_BB_GET_VOLTAGE, "GetCoreVoltage") \
+	USB_ADD_COMMAND(C_BF1_RESET, "BF1Reset") \
+	USB_ADD_COMMAND(C_BF1_OPEN, "BF1Open") \
+	USB_ADD_COMMAND(C_BF1_INIT, "BF1Init") \
+	USB_ADD_COMMAND(C_BF1_CLOSE, "BF1Close") \
+	USB_ADD_COMMAND(C_BF1_REQINFO, "BF1RequestInfo") \
+	USB_ADD_COMMAND(C_BF1_GETINFO, "BF1GetInfo") \
+	USB_ADD_COMMAND(C_BF1_REQRESET, "BF1RequestReset") \
+	USB_ADD_COMMAND(C_BF1_GETRESET, "BF1GetReset") \
+	USB_ADD_COMMAND(C_BF1_REQWORK, "BF1RequestWork") \
+	USB_ADD_COMMAND(C_BF1_GETWORK, "BF1GetWork") \
+	USB_ADD_COMMAND(C_BF1_GETRES, "BF1GetResults") \
+	USB_ADD_COMMAND(C_BF1_FLUSH, "BF1Flush") \
+	USB_ADD_COMMAND(C_BF1_IFLUSH, "BF1InterruptFlush") \
+	USB_ADD_COMMAND(C_BF1_IDENTIFY, "BF1Identify") \
 	USB_ADD_COMMAND(C_HF_RESET, "HFReset") \
 	USB_ADD_COMMAND(C_HF_PLL_CONFIG, "HFPLLConfig") \
 	USB_ADD_COMMAND(C_HF_ADDRESS, "HFAddress") \
@@ -335,12 +356,10 @@ struct cg_usb_info {
 	USB_ADD_COMMAND(C_HF_CLOCKGATE, "HFClockGate")
 
 /* Create usb_cmds enum from USB_PARSE_COMMANDS macro */
-#define USB_ADD_COMMAND(X, Y) X,
 enum usb_cmds {
-	USB_PARSE_COMMANDS
+	USB_PARSE_COMMANDS(ENUMERATION)
 	C_MAX
 };
-#undef USB_ADD_COMMAND
 
 struct device_drv;
 struct cgpu_info;
@@ -353,17 +372,17 @@ struct cgpu_info *usb_alloc_cgpu(struct device_drv *drv, int threads);
 struct cgpu_info *usb_free_cgpu_devlock(struct cgpu_info *cgpu, bool free_devlock);
 #define usb_free_cgpu(cgpu) usb_free_cgpu_devlock(cgpu, true)
 void usb_uninit(struct cgpu_info *cgpu);
-struct cgpu_info *usb_init_intinfo(struct cgpu_info *orig,  int intinfo);
 bool usb_init(struct cgpu_info *cgpu, struct libusb_device *dev, struct usb_find_devices *found);
 void usb_detect(struct device_drv *drv, bool (*device_detect)(struct libusb_device *, struct usb_find_devices *));
 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, const char *end, enum usb_cmds cmd, bool readonce);
-int _usb_write(struct cgpu_info *cgpu, int ep, char *buf, size_t bufsiz, int *processed, unsigned int timeout, enum usb_cmds);
+int _usb_read(struct cgpu_info *cgpu, int intinfo, int epinfo, char *buf, size_t bufsiz, int *processed, unsigned int timeout, const char *end, enum usb_cmds cmd, bool readonce);
+int _usb_write(struct cgpu_info *cgpu, int intinfo, int epinfo, char *buf, size_t bufsiz, int *processed, unsigned int timeout, enum usb_cmds);
 int _usb_transfer(struct cgpu_info *cgpu, uint8_t request_type, uint8_t bRequest, uint16_t wValue, uint16_t wIndex, uint32_t *data, int siz, unsigned int timeout, enum usb_cmds cmd);
 int _usb_transfer_read(struct cgpu_info *cgpu, uint8_t request_type, uint8_t bRequest, uint16_t wValue, uint16_t wIndex, char *buf, int bufsiz, int *amount, unsigned int timeout, enum usb_cmds cmd);
 int usb_ftdi_cts(struct cgpu_info *cgpu);
-int usb_ftdi_set_latency(struct cgpu_info *cgpu);
+int _usb_ftdi_set_latency(struct cgpu_info *cgpu, int intinfo);
+#define usb_ftdi_set_latency(_cgpu) _usb_ftdi_set_latency(_cgpu, DEFAULT_INTINFO)
 void usb_buffer_enable(struct cgpu_info *cgpu);
 void usb_buffer_disable(struct cgpu_info *cgpu);
 void usb_buffer_clear(struct cgpu_info *cgpu);
@@ -371,55 +390,72 @@ uint32_t usb_buffer_size(struct cgpu_info *cgpu);
 void usb_set_cps(struct cgpu_info *cgpu, int cps);
 void usb_enable_cps(struct cgpu_info *cgpu);
 void usb_disable_cps(struct cgpu_info *cgpu);
-int usb_interface(struct cgpu_info *cgpu);
+int _usb_interface(struct cgpu_info *cgpu, int intinfo);
+#define usb_interface(_cgpu) _usb_interface(_cgpu, DEFAULT_INTINFO)
 enum sub_ident usb_ident(struct cgpu_info *cgpu);
-void usb_set_pps(struct cgpu_info *cgpu, uint16_t PrefPacketSize);
+void _usb_set_pps(struct cgpu_info *cgpu, int intinfo, int epinfo, uint16_t PrefPacketSize);
+#define usb_set_pps(_cgpu, _pps) _usb_set_pps(_cgpu, -1, -1, _pps)
 void usb_set_dev_start(struct cgpu_info *cgpu);
 void usb_cleanup();
 void usb_initialise();
 void *usb_resource_thread(void *userdata);
 
 #define usb_read(cgpu, buf, bufsiz, read, cmd) \
-	_usb_read(cgpu, DEFAULT_EP_IN, buf, bufsiz, read, DEVTIMEOUT, NULL, cmd, false)
+	_usb_read(cgpu, DEFAULT_INTINFO, DEFAULT_EP_IN, buf, bufsiz, read, DEVTIMEOUT, NULL, cmd, false)
+
+#define usb_read_ii(cgpu, intinfo, buf, bufsiz, read, cmd) \
+	_usb_read(cgpu, intinfo, DEFAULT_EP_IN, buf, bufsiz, read, DEVTIMEOUT, NULL, cmd, false)
 
 #define usb_read_once(cgpu, buf, bufsiz, read, cmd) \
-	_usb_read(cgpu, DEFAULT_EP_IN, buf, bufsiz, read, DEVTIMEOUT, NULL, cmd, true)
+	_usb_read(cgpu, DEFAULT_INTINFO, DEFAULT_EP_IN, buf, bufsiz, read, DEVTIMEOUT, NULL, cmd, true)
+
+#define usb_read_ii_once(cgpu, intinfo, buf, bufsiz, read, cmd) \
+	_usb_read(cgpu, intinfo, DEFAULT_EP_IN, buf, bufsiz, read, DEVTIMEOUT, NULL, cmd, true)
 
 #define usb_read_once_timeout(cgpu, buf, bufsiz, read, timeout, cmd) \
-	_usb_read(cgpu, DEFAULT_EP_IN, buf, bufsiz, read, timeout, NULL, cmd, true)
+	_usb_read(cgpu, DEFAULT_INTINFO, DEFAULT_EP_IN, buf, bufsiz, read, timeout, NULL, cmd, true)
+
+#define usb_read_ii_once_timeout(cgpu, intinfo, buf, bufsiz, read, timeout, cmd) \
+	_usb_read(cgpu, intinfo, DEFAULT_EP_IN, buf, bufsiz, read, timeout, NULL, cmd, true)
 
 #define usb_read_nl(cgpu, buf, bufsiz, read, cmd) \
-	_usb_read(cgpu, DEFAULT_EP_IN, buf, bufsiz, read, DEVTIMEOUT, "\n", cmd, false)
+	_usb_read(cgpu, DEFAULT_INTINFO, DEFAULT_EP_IN, buf, bufsiz, read, DEVTIMEOUT, "\n", cmd, false)
 
 #define usb_read_nl_timeout(cgpu, buf, bufsiz, read, timeout, cmd) \
-	_usb_read(cgpu, DEFAULT_EP_IN, buf, bufsiz, read, timeout, "\n", cmd, false)
+	_usb_read(cgpu, DEFAULT_INTINFO, DEFAULT_EP_IN, buf, bufsiz, read, timeout, "\n", cmd, false)
 
 #define usb_read_ok(cgpu, buf, bufsiz, read, cmd) \
-	_usb_read(cgpu, DEFAULT_EP_IN, buf, bufsiz, read, DEVTIMEOUT, "OK\n", cmd, false)
+	_usb_read(cgpu, DEFAULT_INTINFO, DEFAULT_EP_IN, buf, bufsiz, read, DEVTIMEOUT, "OK\n", cmd, false)
 
 #define usb_read_ok_timeout(cgpu, buf, bufsiz, read, timeout, cmd) \
-	_usb_read(cgpu, DEFAULT_EP_IN, buf, bufsiz, read, timeout, "OK\n", cmd, false)
+	_usb_read(cgpu, DEFAULT_INTINFO, DEFAULT_EP_IN, buf, bufsiz, read, timeout, "OK\n", cmd, false)
 
 #define usb_read_ep(cgpu, ep, buf, bufsiz, read, cmd) \
-	_usb_read(cgpu, ep, buf, bufsiz, read, DEVTIMEOUT, NULL, cmd, false)
+	_usb_read(cgpu, DEFAULT_INTINFO, ep, buf, bufsiz, read, DEVTIMEOUT, NULL, cmd, false)
 
 #define usb_read_timeout(cgpu, buf, bufsiz, read, timeout, cmd) \
-	_usb_read(cgpu, DEFAULT_EP_IN, buf, bufsiz, read, timeout, NULL, cmd, false)
+	_usb_read(cgpu, DEFAULT_INTINFO, DEFAULT_EP_IN, buf, bufsiz, read, timeout, NULL, cmd, false)
+
+#define usb_read_ii_timeout(cgpu, intinfo, buf, bufsiz, read, timeout, cmd) \
+	_usb_read(cgpu, intinfo, DEFAULT_EP_IN, buf, bufsiz, read, timeout, NULL, cmd, false)
 
 #define usb_read_ep_timeout(cgpu, ep, buf, bufsiz, read, timeout, cmd) \
-	_usb_read(cgpu, ep, buf, bufsiz, read, timeout, NULL, cmd, false)
+	_usb_read(cgpu, DEFAULT_INTINFO, ep, buf, bufsiz, read, timeout, NULL, cmd, false)
 
 #define usb_write(cgpu, buf, bufsiz, wrote, cmd) \
-	_usb_write(cgpu, DEFAULT_EP_OUT, buf, bufsiz, wrote, DEVTIMEOUT, cmd)
+	_usb_write(cgpu, DEFAULT_INTINFO, DEFAULT_EP_OUT, buf, bufsiz, wrote, DEVTIMEOUT, cmd)
+
+#define usb_write_ii(cgpu, intinfo, buf, bufsiz, wrote, cmd) \
+	_usb_write(cgpu, intinfo, DEFAULT_EP_OUT, buf, bufsiz, wrote, DEVTIMEOUT, cmd)
 
 #define usb_write_ep(cgpu, ep, buf, bufsiz, wrote, cmd) \
-	_usb_write(cgpu, ep, buf, bufsiz, wrote, DEVTIMEOUT, cmd)
+	_usb_write(cgpu, DEFAULT_INTINFO, ep, buf, bufsiz, wrote, DEVTIMEOUT, cmd)
 
 #define usb_write_timeout(cgpu, buf, bufsiz, wrote, timeout, cmd) \
-	_usb_write(cgpu, DEFAULT_EP_OUT, buf, bufsiz, wrote, timeout, cmd)
+	_usb_write(cgpu, DEFAULT_INTINFO, DEFAULT_EP_OUT, buf, bufsiz, wrote, timeout, cmd)
 
 #define usb_write_ep_timeout(cgpu, ep, buf, bufsiz, wrote, timeout, cmd) \
-	_usb_write(cgpu, ep, buf, bufsiz, wrote, timeout, cmd)
+	_usb_write(cgpu, DEFAULT_INTINFO, ep, buf, bufsiz, wrote, timeout, cmd)
 
 #define usb_transfer(cgpu, typ, req, val, idx, cmd) \
 	_usb_transfer(cgpu, typ, req, val, idx, NULL, 0, DEVTIMEOUT, cmd)
diff --git a/util.c b/util.c
index c0feaaf..ecece48 100644
--- a/util.c
+++ b/util.c
@@ -1074,6 +1074,12 @@ double us_tdiff(struct timeval *end, struct timeval *start)
 	return end->tv_sec * 1000000 + end->tv_usec - start->tv_sec * 1000000 - start->tv_usec;
 }
 
+/* Returns the milliseconds difference between end and start times */
+int ms_tdiff(struct timeval *end, struct timeval *start)
+{
+	return end->tv_sec * 1000 + end->tv_usec / 1000 - start->tv_sec * 1000 - start->tv_usec / 1000;
+}
+
 /* Returns the seconds difference between end and start times as a double */
 double tdiff(struct timeval *end, struct timeval *start)
 {
diff --git a/util.h b/util.h
index 04343b7..2370e87 100644
--- a/util.h
+++ b/util.h
@@ -99,6 +99,7 @@ void cgsleep_us_r(cgtimer_t *ts_start, int64_t us);
 int cgtimer_to_ms(cgtimer_t *cgt);
 void cgtimer_sub(cgtimer_t *a, cgtimer_t *b, cgtimer_t *res);
 double us_tdiff(struct timeval *end, struct timeval *start);
+int ms_tdiff(struct timeval *end, struct timeval *start);
 double tdiff(struct timeval *end, struct timeval *start);
 bool stratum_send(struct pool *pool, char *s, ssize_t len);
 bool sock_full(struct pool *pool);