Commit 3bc36eb0268fa586cc7f574e05e860b4cf7f882d

Con Kolivas 2013-12-01T15:18:16

Deprecate the usb usecps function and just split up transfers equal to the maxpacketsize on usb1.1 devices.

diff --git a/driver-icarus.c b/driver-icarus.c
index af35124..209314a 100644
--- a/driver-icarus.c
+++ b/driver-icarus.c
@@ -314,9 +314,6 @@ static void icarus_initialise(struct cgpu_info *icarus, int baud)
 	if (icarus->usbinfo.nodev)
 		return;
 
-	usb_set_cps(icarus, baud / 10);
-	usb_enable_cps(icarus);
-
 	interface = _usb_interface(icarus, info->intinfo);
 	ident = usb_ident(icarus);
 
diff --git a/driver-modminer.c b/driver-modminer.c
index 642d13d..a3804b7 100644
--- a/driver-modminer.c
+++ b/driver-modminer.c
@@ -126,9 +126,6 @@ static struct cgpu_info *modminer_detect_one(struct libusb_device *dev, struct u
 	if (!usb_init(modminer, dev, found))
 		goto shin;
 
-	usb_set_cps(modminer, 11520);
-	usb_enable_cps(modminer);
-
 	do_ping(modminer);
 
 	if ((err = usb_write(modminer, MODMINER_GET_VERSION, 1, &amount, C_REQUESTVERSION)) < 0 || amount != 1) {
diff --git a/usbutils.c b/usbutils.c
index 4f55b98..544b855 100644
--- a/usbutils.c
+++ b/usbutils.c
@@ -2687,10 +2687,17 @@ int _usb_write(struct cgpu_info *cgpu, int intinfo, int epinfo, char *buf, size_
 	while (bufsiz > 0) {
 		int tosend = bufsiz;
 
-		if (usbdev->usecps) {
-			int cpms = usbdev->cps / 1000 ? : 1;
-			if (tosend > cpms)
-				tosend = cpms;
+		/* USB 1.1 devices don't handle zero packets well so split them
+		 * up to not have the final transfer equal to the wMaxPacketSize
+		 * or they will stall waiting for more data. */
+		if (usbdev->descriptor->bcdUSB < 0x0200) {
+			struct usb_epinfo *ue = &usbdev->found->intinfos[intinfo].epinfos[epinfo];
+
+			if (tosend == ue->wMaxPacketSize) {
+				tosend >>= 1;
+				if (unlikely(!tosend))
+					tosend = 1;
+			}
 		}
 		err = usb_bulk_transfer(usbdev->handle, intinfo, epinfo,
 					(unsigned char *)buf, tosend, &sent, timeout,
@@ -2986,42 +2993,6 @@ uint32_t usb_buffer_size(struct cgpu_info *cgpu)
 	return ret;
 }
 
-void usb_set_cps(struct cgpu_info *cgpu, int cps)
-{
-	int pstate;
-
-	DEVWLOCK(cgpu, pstate);
-
-	if (cgpu->usbdev)
-		cgpu->usbdev->cps = cps;
-
-	DEVWUNLOCK(cgpu, pstate);
-}
-
-void usb_enable_cps(struct cgpu_info *cgpu)
-{
-	int pstate;
-
-	DEVWLOCK(cgpu, pstate);
-
-	if (cgpu->usbdev)
-		cgpu->usbdev->usecps = true;
-
-	DEVWUNLOCK(cgpu, pstate);
-}
-
-void usb_disable_cps(struct cgpu_info *cgpu)
-{
-	int pstate;
-
-	DEVWLOCK(cgpu, pstate);
-
-	if (cgpu->usbdev)
-		cgpu->usbdev->usecps = false;
-
-	DEVWUNLOCK(cgpu, pstate);
-}
-
 /*
  * The value returned (0) when usbdev is NULL
  * doesn't matter since it also means the next call to
diff --git a/usbutils.h b/usbutils.h
index eda3c08..5b996fc 100644
--- a/usbutils.h
+++ b/usbutils.h
@@ -198,8 +198,6 @@ struct cg_usb_device {
 	enum usb_types usb_type;
 	enum sub_ident ident;
 	uint16_t usbver;
-	int cps;
-	bool usecps;
 	char *prod_string;
 	char *manuf_string;
 	char *serial_string;
@@ -402,9 +400,6 @@ int _usb_ftdi_set_latency(struct cgpu_info *cgpu, int intinfo);
 #define usb_ftdi_set_latency(_cgpu) _usb_ftdi_set_latency(_cgpu, DEFAULT_INTINFO)
 void usb_buffer_clear(struct cgpu_info *cgpu);
 uint32_t usb_buffer_size(struct cgpu_info *cgpu);
-void usb_set_cps(struct cgpu_info *cgpu, int cps);
-void usb_enable_cps(struct cgpu_info *cgpu);
-void usb_disable_cps(struct cgpu_info *cgpu);
 int _usb_interface(struct cgpu_info *cgpu, int intinfo);
 #define usb_interface(_cgpu) _usb_interface(_cgpu, DEFAULT_INTINFO)
 enum sub_ident usb_ident(struct cgpu_info *cgpu);