Browse Source

Merge pull request #463 from kanoi/master

usbutils config & device_drv noops
kanoi 12 years ago
parent
commit
f3814b3edc
2 changed files with 41 additions and 15 deletions
  1. 2 2
      cgminer.c
  2. 39 13
      usbutils.c

+ 2 - 2
cgminer.c

@@ -7152,8 +7152,6 @@ void enable_device(struct cgpu_info *cgpu)
 		gpu_threads += cgpu->threads;
 		gpu_threads += cgpu->threads;
 	}
 	}
 #endif
 #endif
-	fill_device_drv(cgpu);
-
 	rwlock_init(&cgpu->qlock);
 	rwlock_init(&cgpu->qlock);
 	cgpu->queued_work = NULL;
 	cgpu->queued_work = NULL;
 }
 }
@@ -7196,6 +7194,8 @@ bool add_cgpu(struct cgpu_info *cgpu)
 	cgpu->last_device_valid_work = time(NULL);
 	cgpu->last_device_valid_work = time(NULL);
 	mutex_unlock(&stats_lock);
 	mutex_unlock(&stats_lock);
 
 
+	fill_device_drv(cgpu);
+
 	if (hotplug_mode)
 	if (hotplug_mode)
 		devices[total_devices + new_devices++] = cgpu;
 		devices[total_devices + new_devices++] = cgpu;
 	else
 	else

+ 39 - 13
usbutils.c

@@ -1485,6 +1485,7 @@ static int _usb_init(struct cgpu_info *cgpu, struct libusb_device *dev, struct u
 	char devstr[STRBUFLEN+1];
 	char devstr[STRBUFLEN+1];
 	int err, i, j, k, pstate;
 	int err, i, j, k, pstate;
 	int bad = USB_INIT_FAIL;
 	int bad = USB_INIT_FAIL;
+	int cfg;
 
 
 	DEVLOCK(cgpu, pstate);
 	DEVLOCK(cgpu, pstate);
 
 
@@ -1606,20 +1607,28 @@ static int _usb_init(struct cgpu_info *cgpu, struct libusb_device *dev, struct u
 		}
 		}
 	}
 	}
 
 
-	err = libusb_set_configuration(cgusb->handle, found->config);
-	if (err) {
-		switch(err) {
-			case LIBUSB_ERROR_BUSY:
-				applog(LOG_WARNING,
-					"USB init, set config %d in use %s",
-					found->config, devstr);
-				break;
-			default:
-				applog(LOG_DEBUG,
-					"USB init, failed to set config to %d, err %d %s",
-					found->config, err, devstr);
+	cfg = -1;
+	err = libusb_get_configuration(cgusb->handle, &cfg);
+	if (err)
+		cfg = -1;
+
+	// Try to set it if we can't read it or it's different
+	if (cfg != found->config) {
+		err = libusb_set_configuration(cgusb->handle, found->config);
+		if (err) {
+			switch(err) {
+				case LIBUSB_ERROR_BUSY:
+					applog(LOG_WARNING,
+						"USB init, set config %d in use %s",
+						found->config, devstr);
+					break;
+				default:
+					applog(LOG_DEBUG,
+						"USB init, failed to set config to %d, err %d %s",
+						found->config, err, devstr);
+			}
+			goto cldame;
 		}
 		}
-		goto cldame;
 	}
 	}
 
 
 	err = libusb_get_active_config_descriptor(dev, &config);
 	err = libusb_get_active_config_descriptor(dev, &config);
@@ -1681,6 +1690,17 @@ static int _usb_init(struct cgpu_info *cgpu, struct libusb_device *dev, struct u
 		goto cldame;
 		goto cldame;
 	}
 	}
 
 
+	cfg = -1;
+	err = libusb_get_configuration(cgusb->handle, &cfg);
+	if (err)
+		cfg = -1;
+	if (cfg != found->config) {
+		applog(LOG_WARNING,
+			"USB init, incorrect config (%d!=%d) after claim of %s",
+			cfg, found->config, devstr);
+		goto reldame;
+	}
+
 	cgusb->usbver = cgusb->descriptor->bcdUSB;
 	cgusb->usbver = cgusb->descriptor->bcdUSB;
 
 
 // TODO: allow this with the right version of the libusb include and running library
 // TODO: allow this with the right version of the libusb include and running library
@@ -1732,6 +1752,10 @@ static int _usb_init(struct cgpu_info *cgpu, struct libusb_device *dev, struct u
 	bad = USB_INIT_OK;
 	bad = USB_INIT_OK;
 	goto out_unlock;
 	goto out_unlock;
 
 
+reldame:
+
+	libusb_release_interface(cgusb->handle, found->interface);
+
 cldame:
 cldame:
 
 
 	cg_wlock(&cgusb_fd_lock);
 	cg_wlock(&cgusb_fd_lock);
@@ -1897,6 +1921,8 @@ void usb_detect(struct device_drv *drv, bool (*device_detect)(struct libusb_devi
 
 
 	if (count == 0)
 	if (count == 0)
 		applog(LOG_DEBUG, "USB scan devices: found no devices");
 		applog(LOG_DEBUG, "USB scan devices: found no devices");
+	else
+		nmsleep(166);
 
 
 	for (i = 0; i < count; i++) {
 	for (i = 0; i < count; i++) {
 		if (total_count >= total_limit) {
 		if (total_count >= total_limit) {