Send a work restart with every shutdown message to hfa devices to clear any work that might be stale on the next restart.
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
diff --git a/driver-hashfast.c b/driver-hashfast.c
index b805036..d9834ac 100644
--- a/driver-hashfast.c
+++ b/driver-hashfast.c
@@ -458,12 +458,29 @@ tryagain:
return true;
}
+static void hfa_clear_readbuf(struct cgpu_info *hashfast)
+{
+ int amount, ret;
+ char buf[512];
+
+ do {
+ if (hashfast->usbinfo.nodev)
+ break;
+ ret = usb_read(hashfast, buf, 512, &amount, C_HF_CLEAR_READ);
+ } while (!ret || amount);
+}
+
static bool hfa_send_shutdown(struct cgpu_info *hashfast)
{
bool ret = false;
if (hashfast->usbinfo.nodev)
return ret;
+ /* Send a restart before the shutdown frame to tell the device to
+ * discard any work it thinks is in flight for a cleaner restart. */
+ if (!hfa_send_frame(hashfast, HF_USB_CMD(OP_WORK_RESTART), 0, (uint8_t *)NULL, 0))
+ return ret;
+ hfa_clear_readbuf(hashfast);
if (hfa_send_frame(hashfast, HF_USB_CMD(OP_USB_SHUTDOWN), 0, NULL, 0)) {
/* Wait to allow device to properly shut down. */
cgsleep_ms(1000);
@@ -472,18 +489,6 @@ static bool hfa_send_shutdown(struct cgpu_info *hashfast)
return ret;
}
-static void hfa_clear_readbuf(struct cgpu_info *hashfast)
-{
- int amount, ret;
- char buf[512];
-
- do {
- if (hashfast->usbinfo.nodev)
- break;
- ret = usb_read(hashfast, buf, 512, &amount, C_HF_CLEAR_READ);
- } while (!ret || amount);
-}
-
static bool hfa_detect_common(struct cgpu_info *hashfast)
{
struct hashfast_info *info;