Merge branch 'bflsc' of github.com:ckolivas/cgminer into bflsc
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
diff --git a/driver-bflsc.c b/driver-bflsc.c
index ce0a59c..cc49db2 100644
--- a/driver-bflsc.c
+++ b/driver-bflsc.c
@@ -807,13 +807,8 @@ static bool bflsc_detect_one(struct libusb_device *dev, struct usb_find_devices
// TODO: fix ... everywhere ...
bflsc->device_file = (FILE *)sc_info;
- if (!usb_init(bflsc, dev, found)) {
- applog(LOG_ERR, "%s detect (%d:%d) failed to initialise (incorrect device?)",
- bflsc->drv->dname,
- (int)(bflsc->usbinfo.bus_number),
- (int)(bflsc->usbinfo.device_address));
+ if (!usb_init(bflsc, dev, found))
goto shin;
- }
sprintf(devpath, "%d:%d",
(int)(bflsc->usbinfo.bus_number),
diff --git a/driver-bitforce.c b/driver-bitforce.c
index cc4e412..e1963f8 100644
--- a/driver-bitforce.c
+++ b/driver-bitforce.c
@@ -179,19 +179,13 @@ static bool bitforce_detect_one(struct libusb_device *dev, struct usb_find_devic
bitforce->deven = DEV_ENABLED;
bitforce->threads = 1;
- if (!usb_init(bitforce, dev, found)) {
- applog(LOG_ERR, "%s detect (%d:%d) failed to initialise (incorrect device?)",
- bitforce->drv->dname,
- (int)(bitforce->usbinfo.bus_number),
- (int)(bitforce->usbinfo.device_address));
+ if (!usb_init(bitforce, dev, found))
goto shin;
- }
sprintf(devpath, "%d:%d",
(int)(bitforce->usbinfo.bus_number),
(int)(bitforce->usbinfo.device_address));
-
// Allow 2 complete attempts if the 1st time returns an unrecognised reply
ident_first = true;
retry:
diff --git a/driver-modminer.c b/driver-modminer.c
index 6358273..f20e555 100644
--- a/driver-modminer.c
+++ b/driver-modminer.c
@@ -126,13 +126,8 @@ static bool modminer_detect_one(struct libusb_device *dev, struct usb_find_devic
mutex_init(modminer->modminer_mutex);
modminer->fpgaid = (char)0;
- if (!usb_init(modminer, dev, found)) {
- applog(LOG_ERR, "%s detect (%d:%d) failed to initialise (incorrect device?)",
- modminer->drv->dname,
- (int)(modminer->usbinfo.bus_number),
- (int)(modminer->usbinfo.device_address));
+ if (!usb_init(modminer, dev, found))
goto shin;
- }
sprintf(devpath, "%d:%d",
(int)(modminer->usbinfo.bus_number),
diff --git a/usbutils.c b/usbutils.c
index f133831..3703862 100644
--- a/usbutils.c
+++ b/usbutils.c
@@ -1217,7 +1217,11 @@ static void release_cgpu(struct cgpu_info *cgpu)
cgminer_usb_unlock_bd(cgpu->drv, cgpu->usbinfo.bus_number, cgpu->usbinfo.device_address);
}
-bool usb_init(struct cgpu_info *cgpu, struct libusb_device *dev, struct usb_find_devices *found)
+#define USB_INIT_FAIL 0
+#define USB_INIT_OK 1
+#define USB_INIT_IGNORE 2
+
+static int _usb_init(struct cgpu_info *cgpu, struct libusb_device *dev, struct usb_find_devices *found)
{
struct cg_usb_device *cgusb = NULL;
struct libusb_config_descriptor *config = NULL;
@@ -1226,6 +1230,7 @@ bool usb_init(struct cgpu_info *cgpu, struct libusb_device *dev, struct usb_find
unsigned char strbuf[STRBUFLEN+1];
char devstr[STRBUFLEN+1];
int err, i, j, k;
+ int bad = USB_INIT_FAIL;
cgpu->usbinfo.bus_number = libusb_get_bus_number(dev);
cgpu->usbinfo.device_address = libusb_get_device_address(dev);
@@ -1301,8 +1306,10 @@ bool usb_init(struct cgpu_info *cgpu, struct libusb_device *dev, struct usb_find
err, devstr);
goto cldame;
}
- if (strcmp((char *)man, found->iManufacturer))
+ if (strcmp((char *)man, found->iManufacturer)) {
+ bad = USB_INIT_IGNORE;
goto cldame;
+ }
}
if (found->iProduct) {
@@ -1317,8 +1324,10 @@ bool usb_init(struct cgpu_info *cgpu, struct libusb_device *dev, struct usb_find
err, devstr);
goto cldame;
}
- if (strcmp((char *)prod, found->iProduct))
+ if (strcmp((char *)prod, found->iProduct)) {
+ bad = USB_INIT_IGNORE;
goto cldame;
+ }
}
err = libusb_set_configuration(cgusb->handle, found->config);
@@ -1435,7 +1444,7 @@ bool usb_init(struct cgpu_info *cgpu, struct libusb_device *dev, struct usb_find
cgpu->drv->name = (char *)(found->name);
}
- return true;
+ return USB_INIT_OK;
cldame:
@@ -1448,7 +1457,22 @@ dame:
cgusb = free_cgusb(cgusb);
- return false;
+ return bad;
+}
+
+bool usb_init(struct cgpu_info *cgpu, struct libusb_device *dev, struct usb_find_devices *found)
+{
+ int ret;
+
+ ret = _usb_init(cgpu, dev, found);
+
+ if (ret == USB_INIT_FAIL)
+ applog(LOG_ERR, "%s detect (%d:%d) failed to initialise (incorrect device?)",
+ cgpu->drv->dname,
+ (int)(cgpu->usbinfo.bus_number),
+ (int)(cgpu->usbinfo.device_address));
+
+ return (ret == USB_INIT_OK);
}
static bool usb_check_device(struct device_drv *drv, struct libusb_device *dev, struct usb_find_devices *look)