Implement and use usb_cleanup() on shutdown or 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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
diff --git a/cgminer.c b/cgminer.c
index 3c70257..910bce5 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -2842,6 +2842,16 @@ static void __kill_work(void)
applog(LOG_DEBUG, "Killing off API thread");
thr = &control_thr[api_thr_id];
thr_info_cancel(thr);
+
+#if defined(USE_MODMINER) || defined(USE_BITFORCE)
+ /* Release USB resources in case it's a restart
+ * and not a QUIT */
+ if (!opt_scrypt) {
+ applog(LOG_DEBUG, "Releasing all USB devices");
+ usb_cleanup();
+ }
+#endif
+
}
/* This should be the common exit path */
diff --git a/usbutils.c b/usbutils.c
index f0dd7c7..27c67ce 100644
--- a/usbutils.c
+++ b/usbutils.c
@@ -184,6 +184,7 @@ static const char *C_SETFLOW_S = "SetFlowCtrl";
static const char *C_SETMODEM_S = "SetModemCtrl";
static const char *C_PURGERX_S = "PurgeRx";
static const char *C_PURGETX_S = "PurgeTx";
+static const char *C_FLASHREPLY_S = "FlashReply";
#ifdef EOL
#undef EOL
@@ -572,6 +573,7 @@ static void cgusb_check_init()
usb_commands[C_SETMODEM] = C_SETMODEM_S;
usb_commands[C_PURGERX] = C_PURGERX_S;
usb_commands[C_PURGETX] = C_PURGETX_S;
+ usb_commands[C_FLASHREPLY] = C_FLASHREPLY_S;
stats_initialised = true;
}
@@ -1522,5 +1524,17 @@ int _usb_transfer(struct cgpu_info *cgpu, uint8_t request_type, uint8_t bRequest
void usb_cleanup()
{
- // TODO:
+ int i;
+
+ mutex_lock(&devices_lock);
+ for (i = 0; i < total_devices; i++) {
+ switch (devices[i]->drv->drv_id) {
+ case DRIVER_BITFORCE:
+ case DRIVER_MODMINER:
+ release_cgpu(devices[i]);
+ default:
+ break;
+ }
+ }
+ mutex_unlock(&devices_lock);
}
diff --git a/usbutils.h b/usbutils.h
index 1ec1936..fc6340f 100644
--- a/usbutils.h
+++ b/usbutils.h
@@ -122,6 +122,7 @@ enum usb_cmds {
C_SETMODEM,
C_PURGERX,
C_PURGETX,
+ C_FLASHREPLY,
C_MAX
};