Add a mechanism to blacklist a usb device from its cgpu.
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
diff --git a/usbutils.c b/usbutils.c
index c7b1448..892321f 100644
--- a/usbutils.c
+++ b/usbutils.c
@@ -636,6 +636,7 @@ struct usb_in_use_list {
// List of in use devices
static struct usb_in_use_list *in_use_head = NULL;
+static struct usb_in_use_list *blacklist_head = NULL;
struct resource_work {
bool lock;
@@ -1243,6 +1244,15 @@ static bool __is_in_use(uint8_t bus_number, uint8_t device_address)
}
in_use_tmp = in_use_tmp->next;
}
+ in_use_tmp = blacklist_head;
+ while (in_use_tmp) {
+ if (in_use_tmp->in_use.bus_number == (int)bus_number &&
+ in_use_tmp->in_use.device_address == (int)device_address) {
+ ret = true;
+ break;
+ }
+ in_use_tmp = in_use_tmp->next;
+ }
return ret;
}
@@ -1262,16 +1272,20 @@ static bool is_in_use(libusb_device *dev)
return is_in_use_bd(libusb_get_bus_number(dev), libusb_get_device_address(dev));
}
-static void add_in_use(uint8_t bus_number, uint8_t device_address)
+static void add_in_use(uint8_t bus_number, uint8_t device_address, bool blacklist)
{
- struct usb_in_use_list *in_use_tmp;
+ struct usb_in_use_list *in_use_tmp, **head;
bool found = false;
mutex_lock(&cgusb_lock);
- if (unlikely(__is_in_use(bus_number, device_address))) {
+ if (unlikely(!blacklist && __is_in_use(bus_number, device_address))) {
found = true;
goto nofway;
}
+ if (blacklist)
+ head = &blacklist_head;
+ else
+ head = &in_use_head;
in_use_tmp = calloc(1, sizeof(*in_use_tmp));
if (unlikely(!in_use_tmp))
@@ -1279,9 +1293,9 @@ static void add_in_use(uint8_t bus_number, uint8_t device_address)
in_use_tmp->in_use.bus_number = (int)bus_number;
in_use_tmp->in_use.device_address = (int)device_address;
in_use_tmp->next = in_use_head;
- if (in_use_head)
- in_use_head->prev = in_use_tmp;
- in_use_head = in_use_tmp;
+ if (*head)
+ (*head)->prev = in_use_tmp;
+ *head = in_use_tmp;
nofway:
mutex_unlock(&cgusb_lock);
@@ -1478,7 +1492,7 @@ void usb_uninit(struct cgpu_info *cgpu)
/* We have dropped the read devlock before entering this function but we pick
* up the write lock to prevent any attempts to work on dereferenced code once
* the nodev flag has been set. */
-static void release_cgpu(struct cgpu_info *cgpu)
+static bool __release_cgpu(struct cgpu_info *cgpu)
{
struct cg_usb_device *cgusb = cgpu->usbdev;
bool initted = cgpu->usbinfo.initialised;
@@ -1487,7 +1501,7 @@ static void release_cgpu(struct cgpu_info *cgpu)
// It has already been done
if (cgpu->usbinfo.nodev)
- return;
+ return false;
applog(LOG_DEBUG, "USB release %s%i",
cgpu->drv->name, cgpu->device_id);
@@ -1520,7 +1534,20 @@ static void release_cgpu(struct cgpu_info *cgpu)
}
_usb_uninit(cgpu);
- cgminer_usb_unlock_bd(cgpu->drv, cgpu->usbinfo.bus_number, cgpu->usbinfo.device_address);
+ return true;
+}
+
+static void release_cgpu(struct cgpu_info *cgpu)
+{
+ if (__release_cgpu(cgpu))
+ cgminer_usb_unlock_bd(cgpu->drv, cgpu->usbinfo.bus_number, cgpu->usbinfo.device_address);
+}
+
+void blacklist_cgpu(struct cgpu_info *cgpu)
+{
+ if (__release_cgpu(cgpu))
+ cgminer_usb_unlock_bd(cgpu->drv, cgpu->usbinfo.bus_number, cgpu->usbinfo.device_address);
+ add_in_use(cgpu->usbinfo.bus_number, cgpu->usbinfo.device_address, true);
}
/*
@@ -3526,7 +3553,7 @@ static bool resource_lock(const char *dname, uint8_t bus_number, uint8_t device_
goto fail;
}
- add_in_use(bus_number, device_address);
+ add_in_use(bus_number, device_address, false);
in_use_store_ress(bus_number, device_address, (void *)usbMutex, (void *)sec);
return true;
@@ -3622,7 +3649,7 @@ fail:
goto free_out;
}
- add_in_use(bus_number, device_address);
+ add_in_use(bus_number, device_address, false);
in_use_store_ress(bus_number, device_address, (void *)key, (void *)sem);
return true;
diff --git a/usbutils.h b/usbutils.h
index 586a469..e8ebf2b 100644
--- a/usbutils.h
+++ b/usbutils.h
@@ -420,6 +420,7 @@ void cancel_usb_transfers(void);
void usb_all(int level);
const char *usb_cmdname(enum usb_cmds cmd);
void usb_applog(struct cgpu_info *cgpu, enum usb_cmds cmd, char *msg, int amount, int err);
+void blacklist_cgpu(struct cgpu_info *cgpu);
void usb_nodev(struct cgpu_info *cgpu);
struct cgpu_info *usb_copy_cgpu(struct cgpu_info *orig);
struct cgpu_info *usb_alloc_cgpu(struct device_drv *drv, int threads);