Commit f8571b60c5ca9228051b41f499ca89060a8aa255

Con Kolivas 2014-02-20T11:15:32

Send a work restart with every shutdown message to hfa devices to clear any work that might be stale on the next restart.

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;