Commit b90afd00ecd55b165f1f0cc1e4f2a0d84bfb03a9

Vitalii Demianets 2013-12-16T16:18:57

Merge tag 'v3.8.5' of https://github.com/ckolivas/cgminer

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
diff --git a/Makefile.am b/Makefile.am
index b791eba..6316cde 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,12 +1,12 @@
 
 ACLOCAL_AMFLAGS = -I m4
 
-JANSSON_INCLUDES= -I$(top_builddir)/compat/jansson-2.5/src -I$(top_srcdir)/compat/jansson-2.5/src
+JANSSON_CPPFLAGS= -I$(top_builddir)/compat/jansson-2.5/src -I$(top_srcdir)/compat/jansson-2.5/src
 
 if WANT_USBUTILS
-USBUTILS_INCLUDES = -I$(top_builddir)/compat/libusb-1.0/libusb -I$(top_srcdir)/compat/libusb-1.0/libusb
+USBUTILS_CPPFLAGS = -I$(top_builddir)/compat/libusb-1.0/libusb -I$(top_srcdir)/compat/libusb-1.0/libusb
 else
-USBUTILS_INCLUDES =
+USBUTILS_CPPFLAGS =
 endif
 
 EXTRA_DIST	= example.conf linux-usb-cgminer \
@@ -18,7 +18,7 @@ EXTRA_DIST	= example.conf linux-usb-cgminer \
 
 SUBDIRS		= lib compat ccan
 
-INCLUDES	= $(PTHREAD_FLAGS) -fno-strict-aliasing $(JANSSON_INCLUDES) $(USBUTILS_INCLUDES)
+cgminer_CPPFLAGS = $(PTHREAD_FLAGS) -fno-strict-aliasing $(JANSSON_CPPFLAGS) $(USBUTILS_CPPFLAGS)
 
 bin_PROGRAMS	= cgminer
 
@@ -28,10 +28,10 @@ cgminer_LDADD	= $(DLOPEN_FLAGS) @LIBCURL_LIBS@ @JANSSON_LIBS@ @PTHREAD_LIBS@ \
 		  @LIBUSB_LIBS@ @MM_LIBS@ @RT_LIBS@ \
 		  @MATH_LIBS@ lib/libgnu.a ccan/libccan.a
 
-if HAVE_WINDOWS
-cgminer_CPPFLAGS = -I$(top_builddir)/lib -I$(top_srcdir)/lib
-else
-cgminer_CPPFLAGS = -I$(top_builddir)/lib -I$(top_srcdir)/lib @LIBCURL_CFLAGS@
+cgminer_CPPFLAGS += -I$(top_builddir)/lib -I$(top_srcdir)/lib
+
+if !HAVE_WINDOWS
+cgminer_CPPFLAGS += @LIBCURL_CFLAGS@
 endif
 
 # common sources
diff --git a/NEWS b/NEWS
index f851e42..10f2b23 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,79 @@
+Version 3.8.5 - 10th December 2013
+
+- Increase the BFLSC overtemp to 75 for fanspeed to maximum.
+- Set bflsc cutoff temperature to 85 degrees and throttle 3 degrees below the
+cutoff temperature.
+- Only set LIBUSB_TRANSFER_ADD_ZERO_PACKET for libusb versions we know include
+support for.
+- Provide a helper function that can reset cgsems to zero.
+- Add to cgminer_CPPFLAGS instead of redefining them.
+- Attempt a libusb reset device on usb devices that have stopped responding.
+- Replace deprecated use of INCLUDES with _CPPFLAGS.
+- Remove more unused GPU code.
+- Attempt USB device resets on usb read/write errors that will normally cause
+the device to drop out.
+- Quieten down jansson component of build.
+- Cache the bool value for usb1.1 in _usb_write
+- Initialise usb locks within usbutils.c instead of exporting them.
+- Imitate a transaction translator for all usb1.1 device writes to compensate
+for variable quality hubs and operating system support.
+- Rationalise variables passed to usb_bulk_transfer.
+- Unlink files opened as semaphores on releasing them.
+- Remove user configuration flag from pll bypass enabling in hashfast driver.
+- Provide an hfa-dfu-boot option for resetting hashfast devices for
+reprogramming.
+- Fixed one byte stack overflow in mcast recvfrom.
+- Having changed C_MAX means we don't calloc enough for usb stats, off by one.
+- Don't free the info struct on hashfast shutdown since it's still accessed
+after a device is removed.
+
+
+Version 3.8.4 - 1st December 2013
+
+- Deprecate the usb usecps function and just split up transfers equal to the
+maxpacketsize on usb1.1 devices.
+- Retry sending after successfully clearing a pipe error.
+- Drop logging of timeout overrun message to verbose level.
+- Use a much longer callback timeout for USB writes on windows only as a last
+resort since cancellations work so poorly.
+- Use vcc2 in bflsc voltage displayed.
+- Increment per core errors on false nonces in bflsc and add per core statistics
+to api stats, removing debugging.
+- Store a per-core nonce and hw error count for bflsc.
+- Fix json parsing in api.c
+- Add debugging to hfa driver for how many jobs are being sent.
+- Shut down the hfa read thread if the device disappears.
+- Add debug output saying what frame command is being sent in hfa driver.
+- Revert "Disable USB stats which were not meant to be enabled by default and
+add extra memory for a memory error when stats are enabled."
+- Reset work restart flag in hfa driver since we may check for it again in
+restart_wait.
+- Add more op usb init errors for hfa driver.
+- Perform basic displaying of hfa notices received.
+- Add hfa op usb notice macros.
+- Update hf protocol header.
+- Use sync usb transfers in lowmem mode.
+- Go back to allowing timeout errors on USB writes to be passed back to the
+driver without removing the device in case the driver wishes to manage them.
+- Initialise more values for the hfa data structures.
+- A USB control error must be < 0
+- Simplify USB NODEV error checking to success only for writes and control
+transfers, and success and timeout for reads.
+- libusb error IO should be fatal as well if it gets through usb read and write.
+- Allow IO errors in usb reads/writes to be ignored up to retry max times.
+- Use correct padding for bxf temperature display.
+- Initialise devices before attempting to connect to pools to allow their thread
+prepare function to be called before having to connect to pools.
+- Add hidden hfa options to set hash clock, group ntime roll and pll bypass,
+fixing frame sent on reset to include extra data.
+- Relax the timeouts for the slower usb devices on linux.
+- Add big endian hf protocol header to Makefile
+- Check for correct big endian macro in hf_protocol
+- Use an absolute timeout in hfa_get_header to cope with buffered usb reads
+returning instantly confusing the 200ms counter.
+- Update hfa_detect_one to use the new detect function API.
+
+
 Version 3.8.3 - 23rd November 2013
 
 - Set the bitfury device start times from when we first get valid work.
diff --git a/api.c b/api.c
index bbc8e17..108bda1 100644
--- a/api.c
+++ b/api.c
@@ -4278,7 +4278,7 @@ static void mcast()
 
 		count++;
 		came_from_siz = sizeof(came_from);
-		if (SOCKETFAIL(rep = recvfrom(mcast_sock, buf, sizeof(buf),
+		if (SOCKETFAIL(rep = recvfrom(mcast_sock, buf, sizeof(buf) - 1,
 						0, (struct sockaddr *)(&came_from), &came_from_siz))) {
 			applog(LOG_DEBUG, "API mcast failed count=%d (%s) (%d)",
 					count, SOCKERRMSG, (int)mcast_sock);
@@ -4387,7 +4387,7 @@ void api(int api_thr_id)
 	bool addrok;
 	char group;
 	json_error_t json_err;
-	json_t *json_config;
+	json_t *json_config = NULL;
 	json_t *json_val;
 	bool isjson;
 	bool did;
@@ -4562,21 +4562,18 @@ void api(int api_thr_id)
 						message(io_data, MSG_INVJSON, 0, NULL, isjson);
 						send_result(io_data, c, isjson);
 						did = true;
-					}
-					else {
+					} else {
 						json_val = json_object_get(json_config, JSON_COMMAND);
 						if (json_val == NULL) {
 							message(io_data, MSG_MISCMD, 0, NULL, isjson);
 							send_result(io_data, c, isjson);
 							did = true;
-						}
-						else {
+						} else {
 							if (!json_is_string(json_val)) {
 								message(io_data, MSG_INVCMD, 0, NULL, isjson);
 								send_result(io_data, c, isjson);
 								did = true;
-							}
-							else {
+							} else {
 								cmd = (char *)json_string_value(json_val);
 								json_val = json_object_get(json_config, JSON_PARAMETER);
 								if (json_is_string(json_val))
@@ -4590,11 +4587,10 @@ void api(int api_thr_id)
 								}
 							}
 						}
-						json_decref(json_config);
 					}
 				}
 
-				if (!did)
+				if (!did) {
 					for (i = 0; cmds[i].name != NULL; i++) {
 						if (strcmp(cmd, cmds[i].name) == 0) {
 							sprintf(cmdbuf, "|%s|", cmd);
@@ -4610,11 +4606,14 @@ void api(int api_thr_id)
 							break;
 						}
 					}
+				}
 
 				if (!did) {
 					message(io_data, MSG_INVCMD, 0, NULL, isjson);
 					send_result(io_data, c, isjson);
 				}
+				if (json_is_object(json_config))
+					json_decref(json_config);
 			}
 		}
 		CLOSESOCKET(c);
diff --git a/cgminer.c b/cgminer.c
index 65ca941..089f585 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -74,6 +74,10 @@ char *curly = ":D";
 
 #ifdef USE_HASHFAST
 #include "driver-hashfast.h"
+int opt_hfa_ntime_roll;
+int opt_hfa_hash_clock;
+bool opt_hfa_pll_bypass;
+bool opt_hfa_dfu_boot;
 #endif
 
 #if defined(USE_BITFORCE) || defined(USE_ICARUS) || defined(USE_AVALON) || defined(USE_MODMINER)
@@ -135,7 +139,7 @@ static bool opt_submit_stale = true;
 static int opt_shares;
 bool opt_fail_only;
 static bool opt_fix_protocol;
-static bool opt_lowmem;
+bool opt_lowmem;
 bool opt_autofan;
 bool opt_autoengine;
 bool opt_noadl;
@@ -204,12 +208,6 @@ int hotplug_time = 5;
 pthread_mutex_t lockstat_lock;
 #endif
 
-#ifdef USE_USBUTILS
-pthread_mutex_t cgusb_lock;
-pthread_mutex_t cgusbres_lock;
-cglock_t cgusb_fd_lock;
-#endif
-
 pthread_mutex_t hash_lock;
 static pthread_mutex_t *stgd_lock;
 pthread_mutex_t console_lock;
@@ -1098,14 +1096,6 @@ static struct opt_table opt_config_table[] = {
 	OPT_WITH_ARG("--api-port",
 		     set_int_1_to_65535, opt_show_intval, &opt_api_port,
 		     "Port number of miner API"),
-#ifdef HAVE_ADL
-	OPT_WITHOUT_ARG("--auto-fan",
-			opt_set_bool, &opt_autofan,
-			"Automatically adjust all GPU fan speeds to maintain a target temperature"),
-	OPT_WITHOUT_ARG("--auto-gpu",
-			opt_set_bool, &opt_autoengine,
-			"Automatically adjust all GPU engine clock speeds to maintain a target temperature"),
-#endif
 	OPT_WITHOUT_ARG("--balance",
 		     set_balance, &pool_strategy,
 		     "Change multipool strategy from failover to even share balance"),
@@ -1195,6 +1185,20 @@ static struct opt_table opt_config_table[] = {
 		     set_bitburner_fury_options, NULL, NULL,
 		     "Override avalon-options for BitBurner Fury boards baud:miners:asic:timeout:freq"),
 #endif
+#ifdef USE_HASHFAST
+	OPT_WITHOUT_ARG("--hfa-dfu-boot",
+			opt_set_bool, &opt_hfa_dfu_boot,
+			opt_hidden),
+	OPT_WITH_ARG("--hfa-hash-clock",
+		     opt_set_intval, NULL, &opt_hfa_hash_clock,
+		     opt_hidden),
+	OPT_WITH_ARG("--hfa-ntime-roll",
+		     opt_set_intval, NULL, &opt_hfa_ntime_roll,
+		     opt_hidden),
+	OPT_WITHOUT_ARG("--hfa-pll-bypass",
+			opt_set_bool, &opt_hfa_pll_bypass,
+			opt_hidden),
+#endif
 #ifdef USE_KLONDIKE
 	OPT_WITH_ARG("--klondike-options",
 		     set_klondike_options, NULL, NULL,
@@ -1217,14 +1221,6 @@ static struct opt_table opt_config_table[] = {
 	OPT_WITHOUT_ARG("--net-delay",
 			opt_set_bool, &opt_delaynet,
 			"Impose small delays in networking to not overload slow routers"),
-	OPT_WITHOUT_ARG("--no-adl",
-			opt_set_bool, &opt_noadl,
-#ifdef HAVE_ADL
-			"Disable the ATI display library used for monitoring and setting GPU parameters"
-#else
-			opt_hidden
-#endif
-			),
 	OPT_WITHOUT_ARG("--no-pool-disable",
 			opt_set_invbool, &opt_disable_pool,
 			opt_hidden),
@@ -1295,22 +1291,11 @@ static struct opt_table opt_config_table[] = {
 			opt_set_bool, &use_syslog,
 			"Use system log for output messages (default: standard error)"),
 #endif
-#if defined(HAVE_ADL) || defined(USE_BITFORCE) || defined(USE_MODMINER) || defined(USE_BFLSC)
+#if defined(USE_BITFORCE) || defined(USE_MODMINER) || defined(USE_BFLSC)
 	OPT_WITH_ARG("--temp-cutoff",
 		     set_temp_cutoff, opt_show_intval, &opt_cutofftemp,
 		     "Temperature where a device will be automatically disabled, one value or comma separated list"),
 #endif
-#ifdef HAVE_ADL
-	OPT_WITH_ARG("--temp-hysteresis",
-		     set_int_1_to_10, opt_show_intval, &opt_hysteresis,
-		     "Set how much the temperature can fluctuate outside limits when automanaging speeds"),
-	OPT_WITH_ARG("--temp-overheat",
-		     set_temp_overheat, opt_show_intval, &opt_overheattemp,
-		     "Overheat temperature when automatically managing fan and GPU speeds, one value or comma separated list"),
-	OPT_WITH_ARG("--temp-target",
-		     set_temp_target, opt_show_intval, &opt_targettemp,
-		     "Target temperature when automatically managing fan and GPU speeds, one value or comma separated list"),
-#endif
 	OPT_WITHOUT_ARG("--text-only|-T",
 			opt_set_invbool, &use_curses,
 #ifdef HAVE_CURSES
@@ -1319,11 +1304,6 @@ static struct opt_table opt_config_table[] = {
 			opt_hidden
 #endif
 	),
-#ifdef USE_SCRYPT
-	OPT_WITH_ARG("--thread-concurrency",
-		     set_thread_concurrency, NULL, NULL,
-		     "Set GPU thread concurrency for scrypt mining, comma separated"),
-#endif
 	OPT_WITH_ARG("--url|-o",
 		     set_url, NULL, NULL,
 		     "URL for bitcoin JSON-RPC server"),
@@ -6817,6 +6797,11 @@ static void *longpoll_thread(void __maybe_unused *userdata)
 
 void reinit_device(struct cgpu_info *cgpu)
 {
+#ifdef USE_USBUTILS
+	/* Attempt a usb device reset if the device has gone sick */
+	if (cgpu->usbdev && cgpu->usbdev->handle)
+		libusb_reset_device(cgpu->usbdev->handle);
+#endif
 	cgpu->drv->reinit_device(cgpu);
 }
 
@@ -7041,19 +7026,6 @@ static void *watchdog_thread(void __maybe_unused *userdata)
 			denable = &cgpu->deven;
 			snprintf(dev_str, sizeof(dev_str), "%s%d", cgpu->drv->name, gpu);
 
-#ifdef HAVE_ADL
-			if (adl_active && cgpu->has_adl)
-				gpu_autotune(gpu, denable);
-			if (opt_debug && cgpu->has_adl) {
-				int engineclock = 0, memclock = 0, activity = 0, fanspeed = 0, fanpercent = 0, powertune = 0;
-				float temp = 0, vddc = 0;
-
-				if (gpu_stats(gpu, &temp, &engineclock, &memclock, &vddc, &activity, &fanspeed, &fanpercent, &powertune))
-					applog(LOG_DEBUG, "%.1f C  F: %d%%(%dRPM)  E: %dMHz  M: %dMhz  V: %.3fV  A: %d%%  P: %d%%",
-					temp, fanpercent, fanspeed, engineclock, memclock, vddc, activity, powertune);
-			}
-#endif
-			
 			/* Thread is waiting on getwork or disabled */
 			if (thr->getwork || *denable == DEV_DISABLED)
 				continue;
@@ -7070,12 +7042,6 @@ static void *watchdog_thread(void __maybe_unused *userdata)
 				cgtime(&thr->sick);
 
 				dev_error(cgpu, REASON_DEV_SICK_IDLE_60);
-#ifdef HAVE_ADL
-				if (adl_active && cgpu->has_adl && gpu_activity(gpu) > 50) {
-					applog(LOG_ERR, "GPU still showing activity suggesting a hard hang.");
-					applog(LOG_ERR, "Will not attempt to auto-restart it.");
-				} else
-#endif
 				if (opt_restart) {
 					applog(LOG_ERR, "%s: Attempting to restart", dev_str);
 					reinit_device(cgpu);
@@ -7090,11 +7056,6 @@ static void *watchdog_thread(void __maybe_unused *userdata)
 				   (cgpu->status == LIFE_SICK || cgpu->status == LIFE_DEAD)) {
 				/* Attempt to restart a GPU that's sick or dead once every minute */
 				cgtime(&thr->sick);
-#ifdef HAVE_ADL
-				if (adl_active && cgpu->has_adl && gpu_activity(gpu) > 50) {
-					/* Again do not attempt to restart a device that may have hard hung */
-				} else
-#endif
 				if (opt_restart)
 					reinit_device(cgpu);
 			}
@@ -7800,14 +7761,13 @@ static void *libusb_poll_thread(void __maybe_unused *arg)
 
 static void initialise_usb(void) {
 	int err = libusb_init(NULL);
+
 	if (err) {
 		fprintf(stderr, "libusb_init() failed err %d", err);
 		fflush(stderr);
 		quit(1, "libusb_init() failed");
 	}
-	mutex_init(&cgusb_lock);
-	mutex_init(&cgusbres_lock);
-	cglock_init(&cgusb_fd_lock);
+	initialise_usblocks();
 	usb_polling = true;
 	pthread_create(&usb_poll_thread, NULL, libusb_poll_thread, NULL);
 }
@@ -8096,6 +8056,37 @@ int main(int argc, char *argv[])
 			quit(1, "Failed to calloc mining_thr[%d]", i);
 	}
 
+	// Start threads
+	k = 0;
+	for (i = 0; i < total_devices; ++i) {
+		struct cgpu_info *cgpu = devices[i];
+		cgpu->thr = malloc(sizeof(*cgpu->thr) * (cgpu->threads+1));
+		cgpu->thr[cgpu->threads] = NULL;
+		cgpu->status = LIFE_INIT;
+
+		for (j = 0; j < cgpu->threads; ++j, ++k) {
+			thr = get_thread(k);
+			thr->id = k;
+			thr->cgpu = cgpu;
+			thr->device_thread = j;
+
+			if (!cgpu->drv->thread_prepare(thr))
+				continue;
+
+			if (unlikely(thr_info_create(thr, NULL, miner_thread, thr)))
+				quit(1, "thread %d create failed", thr->id);
+
+			cgpu->thr[j] = thr;
+
+			/* Enable threads for devices set not to mine but disable
+			 * their queue in case we wish to enable them later */
+			if (cgpu->deven != DEV_DISABLED) {
+				applog(LOG_DEBUG, "Pushing sem post to thread %d", thr->id);
+				cgsem_post(&thr->sem);
+			}
+		}
+	}
+
 	if (opt_benchmark)
 		goto begin_bench;
 
@@ -8153,40 +8144,6 @@ begin_bench:
 	cgtime(&total_tv_end);
 	get_datestamp(datestamp, sizeof(datestamp), &total_tv_start);
 
-	// Start threads
-	k = 0;
-	for (i = 0; i < total_devices; ++i) {
-		struct cgpu_info *cgpu = devices[i];
-		cgpu->thr = malloc(sizeof(*cgpu->thr) * (cgpu->threads+1));
-		cgpu->thr[cgpu->threads] = NULL;
-		cgpu->status = LIFE_INIT;
-
-		for (j = 0; j < cgpu->threads; ++j, ++k) {
-			thr = get_thread(k);
-			thr->id = k;
-			thr->cgpu = cgpu;
-			thr->device_thread = j;
-
-			if (!cgpu->drv->thread_prepare(thr))
-				continue;
-
-			if (unlikely(thr_info_create(thr, NULL, miner_thread, thr)))
-				quit(1, "thread %d create failed", thr->id);
-
-			cgpu->thr[j] = thr;
-
-			/* Enable threads for devices set not to mine but disable
-			 * their queue in case we wish to enable them later */
-			if (cgpu->deven != DEV_DISABLED) {
-				applog(LOG_DEBUG, "Pushing sem post to thread %d", thr->id);
-				cgsem_post(&thr->sem);
-			}
-		}
-	}
-
-	cgtime(&total_tv_start);
-	cgtime(&total_tv_end);
-
 	watchpool_thr_id = 2;
 	thr = &control_thr[watchpool_thr_id];
 	/* start watchpool thread */
diff --git a/compat/jansson-2.5/configure.ac b/compat/jansson-2.5/configure.ac
index d089fdb..a16327e 100644
--- a/compat/jansson-2.5/configure.ac
+++ b/compat/jansson-2.5/configure.ac
@@ -4,6 +4,7 @@ AC_INIT([jansson], [2.5], [petri@digip.org])
 AC_CONFIG_MACRO_DIR([m4])
 
 AM_INIT_AUTOMAKE([1.10 foreign])
+m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
 
 AC_CONFIG_SRCDIR([src/value.c])
 AC_CONFIG_HEADERS([config.h])
diff --git a/configure.ac b/configure.ac
index 10b0eea..3d5f1c1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2,7 +2,7 @@
 ##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##
 m4_define([v_maj], [3])
 m4_define([v_min], [8])
-m4_define([v_mic], [3])
+m4_define([v_mic], [5])
 ##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##
 m4_define([v_ver], [v_maj.v_min.v_mic])
 m4_define([lt_rev], m4_eval(v_maj + v_min))
@@ -392,13 +392,6 @@ fi
 
 AC_DEFINE_UNQUOTED([CGMINER_PREFIX], ["$prefix/bin"], [Path to cgminer install])
 
-AC_DEFINE_UNQUOTED([PHATK_KERNNAME], ["phatk121016"], [Filename for phatk kernel])
-AC_DEFINE_UNQUOTED([POCLBM_KERNNAME], ["poclbm130302"], [Filename for poclbm kernel])
-AC_DEFINE_UNQUOTED([DIAKGCN_KERNNAME], ["diakgcn121016"], [Filename for diakgcn kernel])
-AC_DEFINE_UNQUOTED([DIABLO_KERNNAME], ["diablo130302"], [Filename for diablo kernel])
-AC_DEFINE_UNQUOTED([SCRYPT_KERNNAME], ["scrypt130511"], [Filename for scrypt kernel])
-
-
 AC_SUBST(JANSSON_LIBS)
 AC_SUBST(PTHREAD_FLAGS)
 AC_SUBST(DLOPEN_FLAGS)
@@ -409,7 +402,6 @@ AC_SUBST(WS2_LIBS)
 AC_SUBST(MM_LIBS)
 AC_SUBST(MATH_LIBS)
 AC_SUBST(RT_LIBS)
-AC_SUBST(ADL_CPPFLAGS)
 
 AC_CONFIG_FILES([
 	Makefile
diff --git a/driver-bflsc.c b/driver-bflsc.c
index 5dafa9c..c47afc3 100644
--- a/driver-bflsc.c
+++ b/driver-bflsc.c
@@ -918,7 +918,7 @@ static void get_bflsc_statline_before(char *buf, size_t bufsiz, struct cgpu_info
 {
 	struct bflsc_info *sc_info = (struct bflsc_info *)(bflsc->device_data);
 	float temp = 0;
-	float vcc1 = 0;
+	float vcc2 = 0;
 	int i;
 
 	rd_lock(&(sc_info->stat_lock));
@@ -927,12 +927,12 @@ static void get_bflsc_statline_before(char *buf, size_t bufsiz, struct cgpu_info
 			temp = sc_info->sc_devs[i].temp1;
 		if (sc_info->sc_devs[i].temp2 > temp)
 			temp = sc_info->sc_devs[i].temp2;
-		if (sc_info->sc_devs[i].vcc1 > vcc1)
-			vcc1 = sc_info->sc_devs[i].vcc1;
+		if (sc_info->sc_devs[i].vcc2 > vcc2)
+			vcc2 = sc_info->sc_devs[i].vcc2;
 	}
 	rd_unlock(&(sc_info->stat_lock));
 
-	tailsprintf(buf, bufsiz, " max%3.0fC %4.2fV | ", temp, vcc1);
+	tailsprintf(buf, bufsiz, " max%3.0fC %4.2fV | ", temp, vcc2);
 }
 
 static void flush_one_dev(struct cgpu_info *bflsc, int dev)
@@ -1007,6 +1007,36 @@ static void bflsc_flash_led(struct cgpu_info *bflsc, int dev)
 	return;
 }
 
+/* Flush and stop all work if the device reaches the thermal cutoff temp, or
+ * temporarily stop queueing work if it's in the throttling range. */
+static void bflsc_manage_temp(struct cgpu_info *bflsc, struct bflsc_dev *sc_dev,
+			      int dev, float temp)
+{
+	bflsc->temp = temp;
+	if (bflsc->cutofftemp > 0) {
+		int cutoff = bflsc->cutofftemp;
+		int throttle = cutoff - BFLSC_TEMP_THROTTLE;
+		int recover = cutoff - BFLSC_TEMP_RECOVER;
+
+		if (sc_dev->overheat) {
+			if (temp < recover)
+				sc_dev->overheat = false;
+		} else if (temp > throttle) {
+			sc_dev->overheat = true;
+			if (temp > cutoff) {
+				applog(LOG_WARNING, "%s%i: temp (%.1f) hit thermal cutoff limit %d, stopping work!",
+				       bflsc->drv->name, bflsc->device_id, temp, cutoff);
+				dev_error(bflsc, REASON_DEV_THERMAL_CUTOFF);
+				flush_one_dev(bflsc, dev);
+
+			} else {
+				applog(LOG_NOTICE, "%s%i: temp (%.1f) hit thermal throttle limit %d, throttling",
+				       bflsc->drv->name, bflsc->device_id, temp, throttle);
+			}
+		}
+	}
+}
+
 static bool bflsc_get_temp(struct cgpu_info *bflsc, int dev)
 {
 	struct bflsc_info *sc_info = (struct bflsc_info *)(bflsc->device_data);
@@ -1200,34 +1230,41 @@ static bool bflsc_get_temp(struct cgpu_info *bflsc, int dev)
 		if (temp < temp2)
 			temp = temp2;
 
-		bflsc->temp = temp;
-
-		if (bflsc->cutofftemp > 0 && temp >= bflsc->cutofftemp) {
-			applog(LOG_WARNING, "%s%i:%s temp (%.1f) hit thermal cutoff limit %d, stopping work!",
-						bflsc->drv->name, bflsc->device_id, xlink,
-						temp, bflsc->cutofftemp);
-			dev_error(bflsc, REASON_DEV_THERMAL_CUTOFF);
-			sc_dev->overheat = true;
-			flush_one_dev(bflsc, dev);
-			return false;
-		}
-
-		if (bflsc->cutofftemp > 0 && temp < (bflsc->cutofftemp - BFLSC_TEMP_RECOVER))
-			sc_dev->overheat = false;
+		bflsc_manage_temp(bflsc, sc_dev, dev, temp);
 	}
 
 	return true;
 }
 
+static void inc_core_errors(struct bflsc_info *info, int8_t core)
+{
+	if (core >= 0 && core < 16)
+		info->core_hw[core]++;
+}
+
+static void inc_bflsc_errors(struct thr_info *thr, struct bflsc_info *info, int8_t core)
+{
+	inc_hw_errors(thr);
+	inc_core_errors(info, core);
+}
+
+static void inc_bflsc_nonces(struct bflsc_info *info, int8_t core)
+{
+	if (core >= 0 && core < 16)
+		info->core_nonces[core]++;
+}
+
 static void process_nonces(struct cgpu_info *bflsc, int dev, char *xlink, char *data, int count, char **fields, int *nonces)
 {
 	struct bflsc_info *sc_info = (struct bflsc_info *)(bflsc->device_data);
 	char midstate[MIDSTATE_BYTES], blockdata[MERKLE_BYTES];
+	struct thr_info *thr = bflsc->thr[0];
 	struct work *work;
+	int8_t core = -1;
 	uint32_t nonce;
 	int i, num, x;
-	bool res;
 	char *tmp;
+	bool res;
 
 	if (count < sc_info->que_fld_min) {
 		tmp = str_text(data);
@@ -1235,15 +1272,22 @@ static void process_nonces(struct cgpu_info *bflsc, int dev, char *xlink, char *
 				"%s%i:%s work returned too small (%d,%s)",
 				bflsc->drv->name, bflsc->device_id, xlink, count, tmp);
 		free(tmp);
-		inc_hw_errors(bflsc->thr[0]);
+		inc_bflsc_errors(thr, sc_info, core);
 		return;
 	}
 
+	if (sc_info->que_noncecount != QUE_NONCECOUNT_V1) {
+		unsigned int ucore;
+
+		if (sscanf(fields[QUE_CHIP_V2], "%x", &ucore) == 1)
+			core = ucore;
+	}
+
 	if (count > sc_info->que_fld_max) {
 		applog(LOG_INFO, "%s%i:%s work returned too large (%d) processing %d anyway",
 		       bflsc->drv->name, bflsc->device_id, xlink, count, sc_info->que_fld_max);
 		count = sc_info->que_fld_max;
-		inc_hw_errors(bflsc->thr[0]);
+		inc_bflsc_errors(thr, sc_info, core);
 	}
 
 	num = atoi(fields[sc_info->que_noncecount]);
@@ -1254,7 +1298,7 @@ static void process_nonces(struct cgpu_info *bflsc, int dev, char *xlink, char *
 				bflsc->drv->name, bflsc->device_id, xlink, num,
 				count - sc_info->que_fld_max, tmp);
 		free(tmp);
-		inc_hw_errors(bflsc->thr[0]);
+		inc_bflsc_errors(thr, sc_info, core);
 	}
 
 	memset(midstate, 0, MIDSTATE_BYTES);
@@ -1263,7 +1307,7 @@ static void process_nonces(struct cgpu_info *bflsc, int dev, char *xlink, char *
 	    !hex2bin((unsigned char *)blockdata, fields[QUE_BLOCKDATA], MERKLE_BYTES)) {
 		applog(LOG_INFO, "%s%i:%s Failed to convert binary data to hex result - ignored",
 		       bflsc->drv->name, bflsc->device_id, xlink);
-		inc_hw_errors(bflsc->thr[0]);
+		inc_bflsc_errors(thr, sc_info, core);
 		return;
 	}
 
@@ -1273,7 +1317,7 @@ static void process_nonces(struct cgpu_info *bflsc, int dev, char *xlink, char *
 		if (sc_info->not_first_work) {
 			applog(LOG_INFO, "%s%i:%s failed to find nonce work - can't be processed - ignored",
 			       bflsc->drv->name, bflsc->device_id, xlink);
-			inc_hw_errors(bflsc->thr[0]);
+			inc_bflsc_errors(thr, sc_info, core);
 		}
 		return;
 	}
@@ -1291,7 +1335,7 @@ static void process_nonces(struct cgpu_info *bflsc, int dev, char *xlink, char *
 
 		hex2bin((void*)&nonce, fields[i], 4);
 		nonce = htobe32(nonce);
-		res = submit_nonce(bflsc->thr[0], work, nonce);
+		res = submit_nonce(thr, work, nonce);
 		if (res) {
 			wr_lock(&(sc_info->stat_lock));
 			sc_info->sc_devs[dev].nonces_found++;
@@ -1299,7 +1343,9 @@ static void process_nonces(struct cgpu_info *bflsc, int dev, char *xlink, char *
 
 			(*nonces)++;
 			x++;
-		}
+			inc_bflsc_nonces(sc_info, core);
+		} else
+			inc_core_errors(sc_info, core);
 	}
 
 	wr_lock(&(sc_info->stat_lock));
@@ -1785,7 +1831,7 @@ static int64_t bflsc_scanwork(struct thr_info *thr)
 	return ret;
 }
 
-#define BFLSC_OVER_TEMP 60
+#define BFLSC_OVER_TEMP 75
 
 /* Set the fanspeed to auto for any valid value <= BFLSC_OVER_TEMP,
  * or max for any value > BFLSC_OVER_TEMP or if we don't know the temperature. */
@@ -1924,6 +1970,16 @@ else a whole lot of something like these ... etc
 	root = api_add_volts(root, "X-%d-Vcc2", &(sc_info->vcc2), false);
 	root = api_add_volts(root, "X-%d-Vmain", &(sc_info->vmain), false);
 */
+	if (sc_info->que_noncecount != QUE_NONCECOUNT_V1) {
+		for (i = 0; i < 16; i++) {
+			sprintf(buf, "Core%d Nonces", i);
+			root = api_add_int(root, buf, &sc_info->core_nonces[i], false);
+		}
+		for (i = 0; i < 16; i++) {
+			sprintf(buf, "Core%d HW Errors", i);
+			root = api_add_int(root, buf, &sc_info->core_hw[i], false);
+		}
+	}
 
 	return root;
 }
diff --git a/driver-bflsc.h b/driver-bflsc.h
index b547ded..f3b5ea1 100644
--- a/driver-bflsc.h
+++ b/driver-bflsc.h
@@ -139,6 +139,8 @@ struct bflsc_info {
 	int que_noncecount;
 	int que_fld_min;
 	int que_fld_max;
+	int core_nonces[17];
+	int core_hw[17];
 	int flush_size;
 	// count of given size, [+2] is for any > QUE_MAX_RESULTS
 	uint64_t result_size[QUE_MAX_RESULTS+2];
@@ -346,8 +348,10 @@ struct SaveString {
 #define BFLSC_QUE_WATERMARK_V2 32
 #define BFLSC_QUE_LOW_V2 16
 
-#define BFLSC_TEMP_OVERHEAT 90
-// Must drop this far below cutoff before resuming work
+#define BFLSC_TEMP_OVERHEAT 85
+// Will start throttling this much below overheat
+#define BFLSC_TEMP_THROTTLE 3
+// Must drop this far below overheat before resuming work
 #define BFLSC_TEMP_RECOVER 5
 
 // If initialisation fails the first time,
diff --git a/driver-bitfury.c b/driver-bitfury.c
index 7181488..8de63ce 100644
--- a/driver-bitfury.c
+++ b/driver-bitfury.c
@@ -814,7 +814,7 @@ static void bitfury_get_statline_before(char *buf, size_t bufsiz, struct cgpu_in
 
 	switch(info->ident) {
 		case IDENT_BXF:
-			tailsprintf(buf, bufsiz, "%03.1fC         | ", info->temperature);
+			tailsprintf(buf, bufsiz, "%5.1fC         | ", info->temperature);
 			break;
 		case IDENT_BF1:
 		default:
diff --git a/driver-hashfast.c b/driver-hashfast.c
index 4f4a661..fefe57d 100644
--- a/driver-hashfast.c
+++ b/driver-hashfast.c
@@ -84,13 +84,14 @@ static const struct hfa_cmd hfa_cmds[] = {
 	{OP_GET_TRACE, "OP_GET_TRACE", C_NULL},
 	{OP_LOOPBACK_USB, "OP_LOOPBACK_USB", C_NULL},
 	{OP_LOOPBACK_UART, "OP_LOOPBACK_UART", C_NULL},
-	{OP_DFU, "OP_DFU", C_NULL},
+	{OP_DFU, "OP_DFU", C_HF_DFU},
 	{OP_USB_SHUTDOWN, "OP_USB_SHUTDOWN", C_NULL},
 	{OP_DIE_STATUS, "OP_DIE_STATUS", C_HF_DIE_STATUS},	// 24
 	{OP_GWQ_STATUS, "OP_GWQ_STATUS", C_HF_GWQ_STATUS},
 	{OP_WORK_RESTART, "OP_WORK_RESTART", C_HF_WORK_RESTART},
 	{OP_USB_STATS1, "OP_USB_STATS1", C_NULL},
-	{OP_USB_GWQSTATS, "OP_USB_GWQSTATS", C_HF_GWQSTATS}
+	{OP_USB_GWQSTATS, "OP_USB_GWQSTATS", C_HF_GWQSTATS},
+	{OP_USB_NOTICE, "OP_USB_NOTICE", C_HF_NOTICE}
 };
 
 #define HF_USB_CMD_OFFSET (128 - 18)
@@ -118,6 +119,7 @@ static bool hfa_send_frame(struct cgpu_info *hashfast, uint8_t opcode, uint16_t 
 		memcpy(&packet[sizeof(struct hf_header)], data, len);
 	tx_length = sizeof(struct hf_header) + len;
 
+	applog(LOG_DEBUG, "HFA %d: Sending %s frame", hashfast->device_id, hfa_cmds[opcode].cmd_name);
 	ret = usb_write(hashfast, (char *)packet, tx_length, &amount,
 			hfa_cmds[opcode].usb_cmd);
 	if (unlikely(ret < 0 || amount != tx_length)) {
@@ -204,12 +206,21 @@ static const char *hf_usb_init_errors[] = {
 	"Configuration operation timeout",
 	"Excessive core failures",
 	"All cores failed diagnostics",
-	"Too many groups configured - increase ntime roll amount"
+	"Too many groups configured - increase ntime roll amount",
+	"Chaining connections detected but secondary board(s) did not respond",
+	"Secondary board communication error",
+	"Main board 12V power is bad",
+	"Secondary board(s) 12V power is bad",
+	"Main board FPGA programming error",
+	"Main board FPGA SPI read timeout",
+	"Main board FPGA Bad magic number",
+	"Main board FPGA SPI write timeout",
+	"Main board FPGA register read/write test failed"
 };
 
 static bool hfa_reset(struct cgpu_info *hashfast, struct hashfast_info *info)
 {
-	struct hf_usb_init_header usb_init, *hu = &usb_init;
+	struct hf_usb_init_header usb_init[2], *hu = usb_init;
 	struct hf_usb_init_base *db;
         struct hf_usb_init_options *ho;
 	int retries = 0, i;
@@ -218,9 +229,9 @@ static bool hfa_reset(struct cgpu_info *hashfast, struct hashfast_info *info)
 	uint8_t hcrc;
 	bool ret;
 
-        // XXX Following items need to be defaults with command-line overrides
-	info->hash_clock_rate = 550;	// Hash clock rate in Mhz
-	info->group_ntime_roll = 1;
+	/* Hash clock rate in Mhz */
+	info->hash_clock_rate = opt_hfa_hash_clock ? opt_hfa_hash_clock : 550;
+	info->group_ntime_roll = opt_hfa_ntime_roll ? opt_hfa_ntime_roll : 1;
 	info->core_ntime_roll = 1;
 
 	// Assemble the USB_INIT request
@@ -228,6 +239,8 @@ static bool hfa_reset(struct cgpu_info *hashfast, struct hashfast_info *info)
 	hu->preamble = HF_PREAMBLE;
 	hu->operation_code = OP_USB_INIT;
 	hu->protocol = PROTOCOL_GLOBAL_WORK_QUEUE;	// Protocol to use
+	// Force PLL bypass
+	hu->pll_bypass = opt_hfa_pll_bypass;
 	hu->hash_clock = info->hash_clock_rate;		// Hash clock rate in Mhz
 	if (info->group_ntime_roll > 1 && info->core_ntime_roll) {
 		ho = (struct hf_usb_init_options *)(hu + 1);
@@ -417,6 +430,15 @@ static bool hfa_initialise(struct cgpu_info *hashfast)
 	return (err == 7);
 }
 
+static void hfa_dfu_boot(struct cgpu_info *hashfast)
+{
+	bool ret;
+
+	ret = hfa_send_frame(hashfast, HF_USB_CMD(OP_DFU), 0, NULL, 0);
+	applog(LOG_WARNING, "HFA %d %03d:%03d DFU Boot %s", hashfast->device_id, hashfast->usbinfo.bus_number,
+	       hashfast->usbinfo.device_address, ret ? "Succeeded" : "Failed");
+}
+
 static struct cgpu_info *hfa_detect_one(libusb_device *dev, struct usb_find_devices *found)
 {
 	struct cgpu_info *hashfast;
@@ -436,7 +458,11 @@ static struct cgpu_info *hfa_detect_one(libusb_device *dev, struct usb_find_devi
 		hashfast = usb_free_cgpu(hashfast);
 		return NULL;
 	}
-
+	if (opt_hfa_dfu_boot) {
+		hfa_dfu_boot(hashfast);
+		hashfast = usb_free_cgpu(hashfast);
+		return NULL;
+	}
 	if (!hfa_detect_common(hashfast)) {
 		usb_uninit(hashfast);
 		hashfast = usb_free_cgpu(hashfast);
@@ -680,8 +706,21 @@ static void hfa_update_stats1(struct cgpu_info *hashfast, struct hashfast_info *
 #endif
 	applog(LOG_DEBUG, "      max_tx_buffers:               %6d", sd->max_tx_buffers);
 	applog(LOG_DEBUG, "      max_rx_buffers:               %6d", sd->max_rx_buffers);
+}
 
-    }
+static void hfa_parse_notice(struct cgpu_info *hashfast, struct hf_header *h)
+{
+	struct hf_usb_notice_data *d;
+
+	if (h->data_length == 0) {
+		applog(LOG_DEBUG, "HFA %d: Received OP_USB_NOTICE with zero data length",
+		       hashfast->device_id);
+		return;
+	}
+	d = (struct hf_usb_notice_data *)(h + 1);
+	/* FIXME Do something with the notification code d->extra_data here */
+	applog(LOG_NOTICE, "HFA %d NOTICE: %s", hashfast->device_id, d->message);
+}
 
 static void *hfa_read(void *arg)
 {
@@ -698,6 +737,9 @@ static void *hfa_read(void *arg)
 		struct hf_header *h = (struct hf_header *)buf;
 		bool ret = hfa_get_packet(hashfast, h);
 
+		if (unlikely(hashfast->usbinfo.nodev))
+			break;
+
 		if (unlikely(!ret))
 			continue;
 
@@ -717,12 +759,16 @@ static void *hfa_read(void *arg)
 			case OP_USB_STATS1:
 				hfa_update_stats1(hashfast, info, h);
 				break;
+			case OP_USB_NOTICE:
+				hfa_parse_notice(hashfast, h);
+				break;
 			default:
 				applog(LOG_WARNING, "HFA %d: Unhandled operation code %d",
 				       hashfast->device_id, h->operation_code);
 				break;
 		}
 	}
+	applog(LOG_DEBUG, "HFA %d: Shutting down read thread", hashfast->device_id);
 
 	return NULL;
 }
@@ -774,6 +820,7 @@ static int64_t hfa_scanwork(struct thr_info *thr)
 
 	if (unlikely(thr->work_restart)) {
 restart:
+		thr->work_restart = false;
 		ret = hfa_send_frame(hashfast, HF_USB_CMD(OP_WORK_RESTART), 0, (uint8_t *)NULL, 0);
 		if (unlikely(!ret)) {
 			ret = hfa_reset(hashfast, info);
@@ -794,6 +841,11 @@ restart:
 		jobs = hfa_jobs(info);
 	}
 
+	if (jobs) {
+		applog(LOG_DEBUG, "HFA %d: Sending %d new jobs", hashfast->device_id,
+		       jobs);
+	}
+
 	while (jobs-- > 0) {
 		struct hf_hash_usb op_hash_data;
 		struct work *work;
@@ -810,13 +862,16 @@ restart:
 		p = (uint32_t *)(work->data + 64 + 4);
 		op_hash_data.timestamp = *p++;
 		op_hash_data.bits = *p++;
+		op_hash_data.starting_nonce = 0;
 		op_hash_data.nonce_loops = 0;
+		op_hash_data.ntime_loops = 0;
 
 		/* Set the number of leading zeroes to look for based on diff.
 		 * Diff 1 = 32, Diff 2 = 33, Diff 4 = 34 etc. */
 		intdiff = (uint64_t)work->device_diff;
 		for (i = 31; intdiff; i++, intdiff >>= 1);
 		op_hash_data.search_difficulty = i;
+		op_hash_data.group = 0;
 		if ((sequence = info->hash_sequence_head + 1) >= info->num_sequence)
 			sequence = 0;
 		ret = hfa_send_frame(hashfast, OP_HASH, sequence, (uint8_t *)&op_hash_data, sizeof(op_hash_data));
@@ -971,7 +1026,8 @@ static void hfa_shutdown(struct thr_info *thr)
 	free(info->works);
 	free(info->die_statistics);
 	free(info->die_status);
-	free(info);
+	/* Don't free info here since it will be accessed by statline before
+	 * if a device is removed. */
 }
 
 struct device_drv hashfast_drv = {
diff --git a/driver-hashfast.h b/driver-hashfast.h
index cf6b7ad..c6cc46e 100644
--- a/driver-hashfast.h
+++ b/driver-hashfast.h
@@ -16,6 +16,11 @@
 #include "elist.h"
 #include "hf_protocol.h"
 
+int opt_hfa_ntime_roll;
+int opt_hfa_hash_clock;
+bool opt_hfa_pll_bypass;
+bool opt_hfa_dfu_boot;
+
 #define HASHFAST_MINER_THREADS 1
 
 // Matching fields for hf_statistics, but large #s for local accumulation, per-die
diff --git a/driver-icarus.c b/driver-icarus.c
index af35124..209314a 100644
--- a/driver-icarus.c
+++ b/driver-icarus.c
@@ -314,9 +314,6 @@ static void icarus_initialise(struct cgpu_info *icarus, int baud)
 	if (icarus->usbinfo.nodev)
 		return;
 
-	usb_set_cps(icarus, baud / 10);
-	usb_enable_cps(icarus);
-
 	interface = _usb_interface(icarus, info->intinfo);
 	ident = usb_ident(icarus);
 
diff --git a/driver-modminer.c b/driver-modminer.c
index 642d13d..a3804b7 100644
--- a/driver-modminer.c
+++ b/driver-modminer.c
@@ -126,9 +126,6 @@ static struct cgpu_info *modminer_detect_one(struct libusb_device *dev, struct u
 	if (!usb_init(modminer, dev, found))
 		goto shin;
 
-	usb_set_cps(modminer, 11520);
-	usb_enable_cps(modminer);
-
 	do_ping(modminer);
 
 	if ((err = usb_write(modminer, MODMINER_GET_VERSION, 1, &amount, C_REQUESTVERSION)) < 0 || amount != 1) {
diff --git a/hf_protocol.h b/hf_protocol.h
index 28cc13b..d193fdc 100644
--- a/hf_protocol.h
+++ b/hf_protocol.h
@@ -8,7 +8,7 @@
 //
 // Useful data structures and values for interfacing with HashFast products
 //
-// Version 1.0
+// Version 1.1
 //
 
 #ifndef _HF_PROTOCOL_H_
@@ -45,6 +45,9 @@
 #define GN_CORE_VOLTAGE(a)              ((float)(a)/256*1.2)
 #define GN_DIE_TEMPERATURE(a)           ((((float)(a)*240)/4096.0)-61.5)
 
+// What to use in an OP_CONFIG hdata field to set thermal overload point to a given temp in degrees C
+#define GN_THERMAL_CUTOFF(temp)         ((uint16_t)(((temp)+61.5)*4096/240))
+
 // The sequence distance between a sent and received sequence number.
 #define HF_SEQUENCE_DISTANCE(tx,rx)        ((tx)>=(rx)?((tx)-(rx)):(info->num_sequence+(tx)-(rx)))
 
@@ -92,6 +95,17 @@
 #define E_CLOCKGATE_TIMEOUT             3
 #define E_CONFIG_TIMEOUT                4
 #define E_EXCESS_CORE_FAILURES          5
+#define E_TOTAL_CORE_FAILURES           6
+#define E_TOO_MANY_GROUPS               7
+#define E_NO_SLAVES                     8
+#define E_SLAVE_COMM                    9
+#define E_MAIN_POWER_BAD                10
+#define E_SECONDARY_POWER_BAD           11
+#define E_BOARD_1                       12
+#define E_BOARD_2                       13
+#define E_BOARD_3                       14
+#define E_BOARD_4                       15
+#define E_BOARD_5                       16
 
 #define U32SIZE(x)                      (sizeof(x)/sizeof(uint32_t))
 
diff --git a/miner.h b/miner.h
index 685a4fb..b8aed7d 100644
--- a/miner.h
+++ b/miner.h
@@ -115,10 +115,6 @@ static inline int fsync (int fd)
 #endif
 
 
-#ifdef HAVE_ADL
- #include "ADL_SDK/adl_sdk.h"
-#endif
-
 #ifdef USE_USBUTILS
   #include <libusb.h>
 #endif
@@ -285,44 +281,6 @@ struct strategies {
 
 struct cgpu_info;
 
-#ifdef HAVE_ADL
-struct gpu_adl {
-	ADLTemperature lpTemperature;
-	int iAdapterIndex;
-	int lpAdapterID;
-	int iBusNumber;
-	char strAdapterName[256];
-
-	ADLPMActivity lpActivity;
-	ADLODParameters lpOdParameters;
-	ADLODPerformanceLevels *DefPerfLev;
-	ADLFanSpeedInfo lpFanSpeedInfo;
-	ADLFanSpeedValue lpFanSpeedValue;
-	ADLFanSpeedValue DefFanSpeedValue;
-
-	int iEngineClock;
-	int iMemoryClock;
-	int iVddc;
-	int iPercentage;
-
-	bool autofan;
-	bool autoengine;
-	bool managed; /* Were the values ever changed on this card */
-
-	int lastengine;
-	int lasttemp;
-	int targetfan;
-	int targettemp;
-	int overtemp;
-	int minspeed;
-	int maxspeed;
-
-	int gpu;
-	bool has_fanspeed;
-	struct gpu_adl *twin;
-};
-#endif
-
 extern void blank_get_statline_before(char *buf, size_t bufsiz, struct cgpu_info __maybe_unused *cgpu);
 
 struct api_data;
@@ -390,15 +348,6 @@ enum dev_enable {
 	DEV_RECOVER,
 };
 
-enum cl_kernels {
-	KL_NONE,
-	KL_POCLBM,
-	KL_PHATK,
-	KL_DIAKGCN,
-	KL_DIABLO,
-	KL_SCRYPT,
-};
-
 enum dev_reason {
 	REASON_THREAD_FAIL_INIT,
 	REASON_THREAD_ZERO_HASH,
@@ -978,6 +927,7 @@ extern char *opt_kernel_path;
 extern char *opt_socks_proxy;
 extern char *cgminer_path;
 extern bool opt_fail_only;
+extern bool opt_lowmem;
 extern bool opt_autofan;
 extern bool opt_autoengine;
 extern bool use_curses;
@@ -994,7 +944,6 @@ 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;
@@ -1048,12 +997,6 @@ extern int opt_queue;
 extern int opt_scantime;
 extern int opt_expiry;
 
-#ifdef USE_USBUTILS
-extern pthread_mutex_t cgusb_lock;
-extern pthread_mutex_t cgusbres_lock;
-extern cglock_t cgusb_fd_lock;
-#endif
-
 extern cglock_t control_lock;
 extern pthread_mutex_t hash_lock;
 extern pthread_mutex_t console_lock;
@@ -1072,14 +1015,6 @@ extern void kill_work(void);
 
 extern void reinit_device(struct cgpu_info *cgpu);
 
-#ifdef HAVE_ADL
-extern bool gpu_stats(int gpu, float *temp, int *engineclock, int *memclock, float *vddc, int *activity, int *fanspeed, int *fanpercent, int *powertune);
-extern int set_fanspeed(int gpu, int iFanSpeed);
-extern int set_vddc(int gpu, float fVddc);
-extern int set_engineclock(int gpu, int iEngineClock);
-extern int set_memoryclock(int gpu, int iMemoryClock);
-#endif
-
 extern void api(int thr_id);
 
 extern struct pool *current_pool(void);
@@ -1091,31 +1026,8 @@ extern void adjust_quota_gcd(void);
 extern struct pool *add_pool(void);
 extern bool add_pool_details(struct pool *pool, bool live, char *url, char *user, char *pass);
 
-#define MAX_GPUDEVICES 16
 #define MAX_DEVICES 4096
 
-#define MIN_SHA_INTENSITY -10
-#define MIN_SHA_INTENSITY_STR "-10"
-#define MAX_SHA_INTENSITY 14
-#define MAX_SHA_INTENSITY_STR "14"
-#define MIN_SCRYPT_INTENSITY 8
-#define MIN_SCRYPT_INTENSITY_STR "8"
-#define MAX_SCRYPT_INTENSITY 20
-#define MAX_SCRYPT_INTENSITY_STR "20"
-#ifdef USE_SCRYPT
-#define MIN_INTENSITY (opt_scrypt ? MIN_SCRYPT_INTENSITY : MIN_SHA_INTENSITY)
-#define MIN_INTENSITY_STR (opt_scrypt ? MIN_SCRYPT_INTENSITY_STR : MIN_SHA_INTENSITY_STR)
-#define MAX_INTENSITY (opt_scrypt ? MAX_SCRYPT_INTENSITY : MAX_SHA_INTENSITY)
-#define MAX_INTENSITY_STR (opt_scrypt ? MAX_SCRYPT_INTENSITY_STR : MAX_SHA_INTENSITY_STR)
-#define MAX_GPU_INTENSITY MAX_SCRYPT_INTENSITY
-#else
-#define MIN_INTENSITY MIN_SHA_INTENSITY
-#define MIN_INTENSITY_STR MIN_SHA_INTENSITY_STR
-#define MAX_INTENSITY MAX_SHA_INTENSITY
-#define MAX_INTENSITY_STR MAX_SHA_INTENSITY_STR
-#define MAX_GPU_INTENSITY MAX_SHA_INTENSITY
-#endif
-
 extern bool hotplug_mode;
 extern int hotplug_time;
 extern struct list_head scan_devices;
@@ -1126,13 +1038,6 @@ extern bool use_syslog;
 extern bool opt_quiet;
 extern struct thr_info *control_thr;
 extern struct thr_info **mining_thr;
-extern struct cgpu_info gpus[MAX_GPUDEVICES];
-extern int gpu_threads;
-#ifdef USE_SCRYPT
-extern bool opt_scrypt;
-#else
-#define opt_scrypt (0)
-#endif
 extern double total_secs;
 extern int mining_threads;
 extern int total_devices;
@@ -1330,9 +1235,7 @@ struct work {
 	unsigned char	target[32];
 	unsigned char	hash[32];
 
-#ifdef USE_SCRYPT
 	unsigned char	device_target[32];
-#endif
 	double		device_diff;
 	uint64_t	share_diff;
 
diff --git a/usbutils.c b/usbutils.c
index b3459d2..83468d2 100644
--- a/usbutils.c
+++ b/usbutils.c
@@ -18,15 +18,14 @@
 #include "miner.h"
 #include "usbutils.h"
 
-#define NODEV(err) ((err) == LIBUSB_ERROR_NO_DEVICE || \
-			(err) == LIBUSB_ERROR_PIPE || \
-			(err) == LIBUSB_ERROR_OTHER)
+static pthread_mutex_t cgusb_lock;
+static pthread_mutex_t cgusbres_lock;
+static cglock_t cgusb_fd_lock;
+static cgtimer_t usb11_cgt;
 
-/* Timeout errors on writes are basically unrecoverable */
-#define WRITENODEV(err) ((err) == LIBUSB_ERROR_TIMEOUT || NODEV(err))
+#define NODEV(err) ((err) != LIBUSB_SUCCESS && (err) != LIBUSB_ERROR_TIMEOUT)
 
-#define NOCONTROLDEV(err) ((err) == LIBUSB_ERROR_NO_DEVICE || \
-			(err) == LIBUSB_ERROR_OTHER)
+#define NOCONTROLDEV(err) ((err) < 0 && NODEV(err))
 
 /*
  * WARNING - these assume DEVLOCK(cgpu, pstate) is called first and
@@ -57,27 +56,27 @@
 
 #define USB_CONFIG 1
 
+#define BITFURY_TIMEOUT_MS 999
+#define ICARUS_TIMEOUT_MS 999
+
 #ifdef WIN32
 #define BFLSC_TIMEOUT_MS 999
 #define BITFORCE_TIMEOUT_MS 999
-#define BITFURY_TIMEOUT_MS 999
 #define MODMINER_TIMEOUT_MS 999
 #define AVALON_TIMEOUT_MS 999
 #define KLONDIKE_TIMEOUT_MS 999
-#define ICARUS_TIMEOUT_MS 999
 #define HASHFAST_TIMEOUT_MS 999
 
 /* The safety timeout we use, cancelling async transfers on windows that fail
  * to timeout on their own. */
 #define WIN_CALLBACK_EXTRA 40
+#define WIN_WRITE_CBEXTRA 5000
 #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 KLONDIKE_TIMEOUT_MS 200
-#define ICARUS_TIMEOUT_MS 200
 #define HASHFAST_TIMEOUT_MS 200
 #endif
 
@@ -509,22 +508,14 @@ static const char *BLANK = "";
 static const char *space = " ";
 static const char *nodatareturned = "no data returned ";
 
+/* Fake success on IO errors allowing code to retry up to USB_RETRY_MAX */
 #define IOERR_CHECK(cgpu, err) \
 		if (err == LIBUSB_ERROR_IO) { \
 			cgpu->usbinfo.ioerr_count++; \
-			cgpu->usbinfo.continuous_ioerr_count++; \
-		} else { \
-			cgpu->usbinfo.continuous_ioerr_count = 0; \
-		}
-
-/* Timeout errors on writes are unusual and should be treated as IO errors. */
-#define WRITEIOERR_CHECK(cgpu, err) \
-		if (err == LIBUSB_ERROR_IO || err == LIBUSB_ERROR_TIMEOUT) { \
-			cgpu->usbinfo.ioerr_count++; \
-			cgpu->usbinfo.continuous_ioerr_count++; \
-		} else { \
-			cgpu->usbinfo.continuous_ioerr_count = 0; \
-		}
+			if (++cgpu->usbinfo.continuous_ioerr_count < USB_RETRY_MAX) \
+				err = LIBUSB_SUCCESS; \
+		} else \
+			cgpu->usbinfo.continuous_ioerr_count = 0;
 
 #if 0 // enable USBDEBUG - only during development testing
  static const char *debug_true_str = "true";
@@ -599,7 +590,7 @@ struct resource_reply *res_reply_head = NULL;
 #define MODE_BULK_WRITE (1 << 3)
 
 // Set this to 0 to remove stats processing
-#define DO_USB_STATS 0
+#define DO_USB_STATS 1
 
 static bool stats_initialised = false;
 
@@ -2186,7 +2177,7 @@ static void newstats(struct cgpu_info *cgpu)
 
 	usb_stats[next_stat].name = cgpu->drv->name;
 	usb_stats[next_stat].device_id = -1;
-	usb_stats[next_stat].details = calloc(1, sizeof(struct cg_usb_stats_details) * C_MAX * 2 + 8);
+	usb_stats[next_stat].details = calloc(2, sizeof(struct cg_usb_stats_details) * (C_MAX + 1));
 	if (unlikely(!usb_stats[next_stat].details))
 		quit(1, "USB failed to calloc details for %d", next_stat+1);
 
@@ -2229,7 +2220,7 @@ static void stats(struct cgpu_info *cgpu, struct timeval *tv_start, struct timev
 		int offset = 0;
 
 		if (extrams >= USB_TMO_2) {
-			applog(LOG_ERR, "%s%i: TIMEOUT %s took %dms but was %dms",
+			applog(LOG_INFO, "%s%i: TIMEOUT %s took %dms but was %dms",
 					cgpu->drv->name, cgpu->device_id,
 					usb_cmdname(cmd), totms, timeout) ;
 			offset = 2;
@@ -2421,30 +2412,35 @@ static int callback_wait(struct usb_transfer *ut, int *transferred, unsigned int
 }
 
 static int usb_submit_transfer(struct usb_transfer *ut, struct libusb_transfer *transfer,
-			       bool cancellable)
+			       bool cancellable, bool tt)
 {
 	int err;
 
 	INIT_LIST_HEAD(&ut->list);
 
 	cg_wlock(&cgusb_fd_lock);
+	/* Imitate a transaction translator for writes to usb1.1 devices */
+	if (tt)
+		cgsleep_ms_r(&usb11_cgt, 1);
 	err = libusb_submit_transfer(transfer);
 	if (likely(!err))
 		ut->cancellable = cancellable;
 	list_add(&ut->list, &ut_list);
+	if (tt)
+		cgtimer_time(&usb11_cgt);
 	cg_wunlock(&cgusb_fd_lock);
 
 	return err;
 }
 
 static int
-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, bool cancellable)
+usb_bulk_transfer(struct cgpu_info *cgpu, struct cg_usb_device *usbdev, int intinfo,
+		  int epinfo, unsigned char *data, int length, int *transferred,
+		  unsigned int timeout, __maybe_unused int mode, enum usb_cmds cmd,
+		  __maybe_unused int seq, bool cancellable, bool tt)
 {
-	int bulk_timeout, callback_timeout = timeout;
+	int bulk_timeout, callback_timeout = timeout, pipe_retries = 0;
+	struct libusb_device_handle *dev_handle = usbdev->handle;
 	struct usb_epinfo *usb_epinfo;
 	struct usb_transfer ut;
 	unsigned char endpoint;
@@ -2463,19 +2459,30 @@ usb_bulk_transfer(struct libusb_device_handle *dev_handle, int intinfo,
 	bulk_timeout = 0;
 #endif
 
-	usb_epinfo = &(cgpu->usbdev->found->intinfos[intinfo].epinfos[epinfo]);
+	usb_epinfo = &(usbdev->found->intinfos[intinfo].epinfos[epinfo]);
 	endpoint = usb_epinfo->ep;
 
 	/* Avoid any async transfers during shutdown to allow the polling
 	 * thread to be shut down after all existing transfers are complete */
-	if (unlikely(cgpu->shutdown))
+	if (opt_lowmem || cgpu->shutdown)
 		return libusb_bulk_transfer(dev_handle, endpoint, data, length, transferred, timeout);
-
+pipe_retry:
 	init_usb_transfer(&ut);
 
 	if ((endpoint & LIBUSB_ENDPOINT_DIR_MASK) == LIBUSB_ENDPOINT_OUT) {
 		memcpy(buf, data, length);
+#ifndef HAVE_LIBUSB
+		/* Older versions may not have this feature so only enable it
+		 * when we know we're compiling with included static libusb */
 		ut.transfer->flags |= LIBUSB_TRANSFER_ADD_ZERO_PACKET;
+#endif
+#ifdef WIN32
+		/* Writes on windows really don't like to be cancelled, but
+		 * are prone to timeouts under heavy USB traffic, so make this
+		 * a last resort cancellation delayed long after the write
+		 * would have timed out on its own. */
+		callback_timeout += WIN_WRITE_CBEXTRA;
+#endif
 	}
 
 	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);
@@ -2483,7 +2490,7 @@ usb_bulk_transfer(struct libusb_device_handle *dev_handle, int intinfo,
 	libusb_fill_bulk_transfer(ut.transfer, dev_handle, endpoint, buf, length,
 				  transfer_callback, &ut, bulk_timeout);
 	STATS_TIMEVAL(&tv_start);
-	err = usb_submit_transfer(&ut, ut.transfer, cancellable);
+	err = usb_submit_transfer(&ut, ut.transfer, cancellable, tt);
 	errn = errno;
 	if (!err)
 		err = callback_wait(&ut, transferred, callback_timeout);
@@ -2515,6 +2522,8 @@ usb_bulk_transfer(struct libusb_device_handle *dev_handle, int intinfo,
 			if (err)
 				cgpu->usbinfo.clear_fail_count++;
 		} while (err && ++retries < USB_RETRY_MAX);
+		if (!err && ++pipe_retries < USB_RETRY_MAX)
+			goto pipe_retry;
 	}
 	if ((endpoint & LIBUSB_ENDPOINT_DIR_MASK) == LIBUSB_ENDPOINT_IN)
 		memcpy(data, buf, *transferred);
@@ -2577,10 +2586,9 @@ int _usb_read(struct cgpu_info *cgpu, int intinfo, int epinfo, char *buf, size_t
 	initial_timeout = timeout;
 	cgtime(&read_start);
 	while (bufleft > 0 && !eom) {
-		err = usb_bulk_transfer(usbdev->handle, intinfo, epinfo,
-					ptr, usbbufread, &got, timeout,
-					cgpu, MODE_BULK_READ, cmd, first ? SEQ0 : SEQ1,
-					cancellable);
+		err = usb_bulk_transfer(cgpu, usbdev, intinfo, epinfo, ptr, usbbufread,
+					&got, timeout, MODE_BULK_READ, cmd,
+					first ? SEQ0 : SEQ1, cancellable, false);
 		cgtime(&tv_finish);
 		ptr[got] = '\0';
 
@@ -2603,6 +2611,18 @@ int _usb_read(struct cgpu_info *cgpu, int intinfo, int epinfo, char *buf, size_t
 		if (end != NULL)
 			eom = strstr((const char *)usbbuf, end);
 
+		/* Attempt a usb reset for an error that will otherwise cause
+		 * this device to drop out provided we know the device still
+		 * might exist. */
+		if (err && err != LIBUSB_ERROR_TIMEOUT) {
+			applog(LOG_WARNING, "%s %i %s usb read err:(%d) %s", cgpu->drv->name,
+			       cgpu->device_id, usb_cmdname(cmd), err, libusb_error_name(err));
+			if (err != LIBUSB_ERROR_NO_DEVICE) {
+				err = libusb_reset_device(usbdev->handle);
+				applog(LOG_WARNING, "%s %i attempted reset got err:(%d) %s",
+				       cgpu->drv->name, cgpu->device_id, err, libusb_error_name(err));
+			}
+		}
 		if (err || readonce)
 			break;
 
@@ -2642,12 +2662,6 @@ int _usb_read(struct cgpu_info *cgpu, int intinfo, int epinfo, char *buf, size_t
 	*processed = tot;
 	memcpy((char *)buf, (const char *)usbbuf, (tot < (int)bufsiz) ? tot + 1 : (int)bufsiz);
 
-	if (err && err != LIBUSB_ERROR_TIMEOUT) {
-		applog(LOG_WARNING, "%s %i %s usb read err:(%d) %s", cgpu->drv->name, cgpu->device_id, usb_cmdname(cmd),
-		       err, libusb_error_name(err));
-		if (cgpu->usbinfo.continuous_ioerr_count > USB_RETRY_MAX)
-			err = LIBUSB_ERROR_OTHER;
-	}
 out_noerrmsg:
 	if (NODEV(err)) {
 		cg_ruwlock(&cgpu->usbinfo.devlock);
@@ -2661,10 +2675,10 @@ out_noerrmsg:
 
 int _usb_write(struct cgpu_info *cgpu, int intinfo, int epinfo, char *buf, size_t bufsiz, int *processed, int timeout, enum usb_cmds cmd)
 {
-	struct cg_usb_device *usbdev;
 	struct timeval write_start, tv_finish;
+	bool first = true, usb11 = false;
+	struct cg_usb_device *usbdev;
 	unsigned int initial_timeout;
-	__maybe_unused bool first = true;
 	int err, sent, tot, pstate;
 	double done;
 
@@ -2682,6 +2696,8 @@ int _usb_write(struct cgpu_info *cgpu, int intinfo, int epinfo, char *buf, size_
 	}
 
 	usbdev = cgpu->usbdev;
+	if (usbdev->descriptor->bcdUSB < 0x0200)
+		usb11 = true;
 	if (timeout == DEVTIMEOUT)
 		timeout = usbdev->found->timeout;
 
@@ -2692,23 +2708,40 @@ int _usb_write(struct cgpu_info *cgpu, int intinfo, int epinfo, char *buf, size_
 	while (bufsiz > 0) {
 		int tosend = bufsiz;
 
-		if (usbdev->usecps) {
-			int cpms = usbdev->cps / 1000 ? : 1;
-			if (tosend > cpms)
-				tosend = cpms;
+		/* USB 1.1 devices don't handle zero packets well so split them
+		 * up to not have the final transfer equal to the wMaxPacketSize
+		 * or they will stall waiting for more data. */
+		if (usb11) {
+			struct usb_epinfo *ue = &usbdev->found->intinfos[intinfo].epinfos[epinfo];
+
+			if (tosend == ue->wMaxPacketSize) {
+				tosend >>= 1;
+				if (unlikely(!tosend))
+					tosend = 1;
+			}
 		}
-		err = usb_bulk_transfer(usbdev->handle, intinfo, epinfo,
-					(unsigned char *)buf, tosend, &sent, timeout,
-					cgpu, MODE_BULK_WRITE, cmd, first ? SEQ0 : SEQ1,
-					false);
+		err = usb_bulk_transfer(cgpu, usbdev, intinfo, epinfo, (unsigned char *)buf,
+					tosend, &sent, timeout, MODE_BULK_WRITE,
+					cmd, first ? SEQ0 : SEQ1, false, usb11);
 		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);
 
-		WRITEIOERR_CHECK(cgpu, err);
+		IOERR_CHECK(cgpu, err);
 
 		tot += sent;
 
+		/* Unlike reads, even a timeout error is unrecoverable on
+		 * writes. */
+		if (err) {
+			applog(LOG_WARNING, "%s %i %s usb write err:(%d) %s", cgpu->drv->name,
+			       cgpu->device_id, usb_cmdname(cmd), err, libusb_error_name(err));
+			if (err != LIBUSB_ERROR_NO_DEVICE) {
+				err = libusb_reset_device(usbdev->handle);
+				applog(LOG_WARNING, "%s %i attempted reset got err:(%d) %s",
+				       cgpu->drv->name, cgpu->device_id, err, libusb_error_name(err));
+			}
+		}
 		if (err)
 			break;
 
@@ -2726,14 +2759,8 @@ int _usb_write(struct cgpu_info *cgpu, int intinfo, int epinfo, char *buf, size_
 
 	*processed = tot;
 
-	if (err) {
-		applog(LOG_WARNING, "%s %i %s usb write err:(%d) %s", cgpu->drv->name, cgpu->device_id, usb_cmdname(cmd),
-		       err, libusb_error_name(err));
-		if (cgpu->usbinfo.continuous_ioerr_count > USB_RETRY_MAX)
-			err = LIBUSB_ERROR_OTHER;
-	}
 out_noerrmsg:
-	if (WRITENODEV(err)) {
+	if (NODEV(err)) {
 		cg_ruwlock(&cgpu->usbinfo.devlock);
 		release_cgpu(cgpu);
 		DEVWUNLOCK(cgpu, pstate);
@@ -2753,6 +2780,7 @@ static int usb_control_transfer(struct cgpu_info *cgpu, libusb_device_handle *de
 	struct usb_transfer ut;
 	unsigned char buf[70];
 	int err, transferred;
+	bool tt = false;
 
 	if (unlikely(cgpu->shutdown))
 		return libusb_control_transfer(dev_handle, bmRequestType, bRequest, wValue, wIndex, buffer, wLength, timeout);
@@ -2760,11 +2788,14 @@ static int usb_control_transfer(struct cgpu_info *cgpu, libusb_device_handle *de
 	init_usb_transfer(&ut);
 	libusb_fill_control_setup(buf, bmRequestType, bRequest, wValue,
 				  wIndex, wLength);
-	if ((bmRequestType & LIBUSB_ENDPOINT_DIR_MASK) == LIBUSB_ENDPOINT_OUT)
+	if ((bmRequestType & LIBUSB_ENDPOINT_DIR_MASK) == LIBUSB_ENDPOINT_OUT) {
 		memcpy(buf + LIBUSB_CONTROL_SETUP_SIZE, buffer, wLength);
+		if (cgpu->usbdev->descriptor->bcdUSB < 0x0200)
+			tt = true;
+	}
 	libusb_fill_control_transfer(ut.transfer, dev_handle, buf, transfer_callback,
 				     &ut, 0);
-	err = usb_submit_transfer(&ut, ut.transfer, false);
+	err = usb_submit_transfer(&ut, ut.transfer, false, tt);
 	if (!err)
 		err = callback_wait(&ut, &transferred, timeout);
 	if (err == LIBUSB_SUCCESS && transferred) {
@@ -2822,7 +2853,7 @@ int __usb_transfer(struct cgpu_info *cgpu, uint8_t request_type, uint8_t bReques
 
 	USBDEBUG("USB debug: @_usb_transfer(%s (nodev=%s)) err=%d%s", cgpu->drv->name, bool_str(cgpu->usbinfo.nodev), err, isnodev(err));
 
-	WRITEIOERR_CHECK(cgpu, err);
+	IOERR_CHECK(cgpu, err);
 
 	if (err < 0 && err != LIBUSB_ERROR_TIMEOUT) {
 		applog(LOG_WARNING, "%s %i usb transfer err:(%d) %s", cgpu->drv->name, cgpu->device_id,
@@ -2991,42 +3022,6 @@ uint32_t usb_buffer_size(struct cgpu_info *cgpu)
 	return ret;
 }
 
-void usb_set_cps(struct cgpu_info *cgpu, int cps)
-{
-	int pstate;
-
-	DEVWLOCK(cgpu, pstate);
-
-	if (cgpu->usbdev)
-		cgpu->usbdev->cps = cps;
-
-	DEVWUNLOCK(cgpu, pstate);
-}
-
-void usb_enable_cps(struct cgpu_info *cgpu)
-{
-	int pstate;
-
-	DEVWLOCK(cgpu, pstate);
-
-	if (cgpu->usbdev)
-		cgpu->usbdev->usecps = true;
-
-	DEVWUNLOCK(cgpu, pstate);
-}
-
-void usb_disable_cps(struct cgpu_info *cgpu)
-{
-	int pstate;
-
-	DEVWLOCK(cgpu, pstate);
-
-	if (cgpu->usbdev)
-		cgpu->usbdev->usecps = false;
-
-	DEVWUNLOCK(cgpu, pstate);
-}
-
 /*
  * The value returned (0) when usbdev is NULL
  * doesn't matter since it also means the next call to
@@ -3594,6 +3589,7 @@ fila:
 	free(sem);
 	free(key);
 	remove_in_use(bus_number, device_address);
+	unlink(name);
 	return;
 #endif
 }
@@ -3662,3 +3658,10 @@ void *usb_resource_thread(void __maybe_unused *userdata)
 
 	return NULL;
 }
+
+void initialise_usblocks(void)
+{
+	mutex_init(&cgusb_lock);
+	mutex_init(&cgusbres_lock);
+	cglock_init(&cgusb_fd_lock);
+}
diff --git a/usbutils.h b/usbutils.h
index 035f83e..0b883bd 100644
--- a/usbutils.h
+++ b/usbutils.h
@@ -198,8 +198,6 @@ struct cg_usb_device {
 	enum usb_types usb_type;
 	enum sub_ident ident;
 	uint16_t usbver;
-	int cps;
-	bool usecps;
 	char *prod_string;
 	char *manuf_string;
 	char *serial_string;
@@ -361,10 +359,12 @@ struct cg_usb_info {
 	USB_ADD_COMMAND(C_HF_STATISTICS, "HFStatistics") \
 	USB_ADD_COMMAND(C_HF_CLOCKGATE, "HFClockGate") \
 	USB_ADD_COMMAND(C_HF_USB_INIT, "HFUSBInit") \
+	USB_ADD_COMMAND(C_HF_DFU, "HFDFU") \
 	USB_ADD_COMMAND(C_HF_DIE_STATUS, "HFDieStatus") \
 	USB_ADD_COMMAND(C_HF_GWQ_STATUS, "HFGWQStatus") \
 	USB_ADD_COMMAND(C_HF_WORK_RESTART, "HFWorkRestart") \
 	USB_ADD_COMMAND(C_HF_GWQSTATS, "HFGWQStats") \
+	USB_ADD_COMMAND(C_HF_NOTICE, "HFNotice") \
 	USB_ADD_COMMAND(C_HF_GETHEADER, "HFGetHeader") \
 	USB_ADD_COMMAND(C_HF_GETDATA, "HFGetData") \
 	USB_ADD_COMMAND(C_HF_CLEAR_READ, "HFClearRead")
@@ -401,9 +401,6 @@ 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_clear(struct cgpu_info *cgpu);
 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 intinfo);
 #define usb_interface(_cgpu) _usb_interface(_cgpu, DEFAULT_INTINFO)
 enum sub_ident usb_ident(struct cgpu_info *cgpu);
@@ -411,6 +408,7 @@ void usb_set_dev_start(struct cgpu_info *cgpu);
 void usb_cleanup();
 void usb_initialise();
 void *usb_resource_thread(void *userdata);
+void initialise_usblocks(void);
 
 #define usb_read(cgpu, buf, bufsiz, read, cmd) \
 	_usb_read(cgpu, DEFAULT_INTINFO, DEFAULT_EP_IN, buf, bufsiz, read, DEVTIMEOUT, NULL, cmd, false, false)
diff --git a/util.c b/util.c
index 0e9670c..4e292d4 100644
--- a/util.c
+++ b/util.c
@@ -2601,6 +2601,25 @@ int _cgsem_mswait(cgsem_t *cgsem, int ms, const char *file, const char *func, co
 	/* We don't reach here */
 	return 0;
 }
+
+/* Reset semaphore count back to zero */
+void cgsem_reset(cgsem_t *cgsem)
+{
+	int ret, fd;
+	fd_set rd;
+	char buf;
+
+	fd = cgsem->pipefd[0];
+	FD_ZERO(&rd);
+	FD_SET(fd, &rd);
+	do {
+		struct timeval timeout = {0, 0};
+
+		ret = select(fd + 1, &rd, NULL, NULL, &timeout);
+		if (ret > 0)
+			ret = read(fd, &buf, 1);
+	} while (ret > 0);
+}
 #else
 void _cgsem_init(cgsem_t *cgsem, const char *file, const char *func, const int line)
 {
@@ -2641,6 +2660,15 @@ int _cgsem_mswait(cgsem_t *cgsem, int ms, const char *file, const char *func, co
 	return 0;
 }
 
+void cgsem_reset(cgsem_t *cgsem)
+{
+	int ret;
+
+	do {
+		ret = sem_trywait(cgsem);
+	} while (!ret);
+}
+
 void cgsem_destroy(cgsem_t *cgsem)
 {
 	sem_destroy(cgsem);
diff --git a/util.h b/util.h
index d359656..90b1ca9 100644
--- a/util.h
+++ b/util.h
@@ -138,6 +138,7 @@ void _cgsem_init(cgsem_t *cgsem, const char *file, const char *func, const int l
 void _cgsem_post(cgsem_t *cgsem, const char *file, const char *func, const int line);
 void _cgsem_wait(cgsem_t *cgsem, const char *file, const char *func, const int line);
 int _cgsem_mswait(cgsem_t *cgsem, int ms, const char *file, const char *func, const int line);
+void cgsem_reset(cgsem_t *cgsem);
 void cgsem_destroy(cgsem_t *cgsem);
 bool cg_completion_timeout(void *fn, void *fnarg, int timeout);