USB and clear endpoint stall

From: Fredrik Lindberg <fli+freebsd-current_at_shapeshifter.se>
Date: Sun, 19 Feb 2006 14:23:33 +0100
After a quite recent -current update, UPEKs touchchip driver began
to run dead slow and by turning on debugging for libusb (which the
driver utilize) I noticed several 5 seconds long read timeouts.

These timeouts were not present with the same driver on an earlier
current and I think I've tracked it down to the commits on Jan 8
which dropped usbd_clear_endpoint_stall() from usbd_setup_pipe().
Apparently this device needs this, because after re-adding this
functionallity the timeout disappears.

I've attached a patch that works for me, it's basicly the same
as before Jan 8, but with the quirk reversed.
My USB-foo isn't that good so people with better understanding
of the USB stack might have a better fix for this.

Fredrik Lindberg

Index: sys/dev/usb/usb_quirks.c
===================================================================
RCS file: /home/ncvs/src/sys/dev/usb/usb_quirks.c,v
retrieving revision 1.47
diff -u -r1.47 usb_quirks.c
--- sys/dev/usb/usb_quirks.c	8 Jan 2006 03:34:29 -0000	1.47
+++ sys/dev/usb/usb_quirks.c	19 Feb 2006 09:59:34 -0000
_at__at_ -79,6 +79,8 _at__at_
  { USB_VENDOR_TELEX, USB_PRODUCT_TELEX_MIC1,	    0x009, { UQ_AU_NO_FRAC }},
  { USB_VENDOR_SILICONPORTALS, USB_PRODUCT_SILICONPORTALS_YAPPHONE,
    						    0x100, { UQ_AU_INP_ASYNC }},
+ { USB_VENDOR_STMICRO, USB_PRODUCT_STMICRO_BIOCPU,
+  						    ANY, { UQ_OPEN_CLEARSTALL }},
  /* XXX These should have a revision number, but I don't know what they are. */
  { USB_VENDOR_HP, USB_PRODUCT_HP_895C,		    ANY,   { UQ_BROKEN_BIDIR }},
  { USB_VENDOR_HP, USB_PRODUCT_HP_880C,		    ANY,   { UQ_BROKEN_BIDIR }},
Index: sys/dev/usb/usb_quirks.h
===================================================================
RCS file: /home/ncvs/src/sys/dev/usb/usb_quirks.h,v
retrieving revision 1.21
diff -u -r1.21 usb_quirks.h
--- sys/dev/usb/usb_quirks.h	8 Jan 2006 03:34:29 -0000	1.21
+++ sys/dev/usb/usb_quirks.h	19 Feb 2006 09:59:34 -0000
_at__at_ -54,6 +54,7 _at__at_
 #define UQ_AU_INP_ASYNC	0x0800	/* input is async despite claim of adaptive */
 #define UQ_ASSUME_CM_OVER_DATA 0x1000 /* modem device breaks on cm over data */
 #define UQ_BROKEN_BIDIR	0x2000	/* printer has broken bidir mode */
+#define UQ_OPEN_CLEARSTALL	0x4000	/* device needs clear endpoint stall */
 #define UQ_HID_IGNORE	0x8000	/* device should be ignored by hid class */
 					
 };
Index: sys/dev/usb/usb_subr.c
===================================================================
RCS file: /home/ncvs/src/sys/dev/usb/usb_subr.c,v
retrieving revision 1.80
diff -u -r1.80 usb_subr.c
--- sys/dev/usb/usb_subr.c	11 Feb 2006 03:41:20 -0000	1.80
+++ sys/dev/usb/usb_subr.c	19 Feb 2006 09:59:34 -0000
_at__at_ -780,6 +780,18 _at__at_
 		return (err);
 	}
 
+	if (dev->quirks->uq_flags & UQ_OPEN_CLEARSTALL) {
+		/* Clear any stall and make sure DATA0 toggle will be used next. */
+		if (UE_GET_ADDR(ep->edesc->bEndpointAddress) != USB_CONTROL_ENDPOINT) {
+			err = usbd_clear_endpoint_stall(p);
+			if (err && err != USBD_STALLED && err != USBD_TIMEOUT) {
+				printf("usbd_setup_pipe: failed to start "
+				    "endpoint, %s\n", usbd_errstr(err));
+				return (err);
+			}
+		}
+	}
+
 	*pipe = p;
 	return (USBD_NORMAL_COMPLETION);
 }
Index: sys/dev/usb/usbdevs
===================================================================
RCS file: /home/ncvs/src/sys/dev/usb/usbdevs,v
retrieving revision 1.253
diff -u -r1.253 usbdevs
--- sys/dev/usb/usbdevs	11 Feb 2006 03:27:57 -0000	1.253
+++ sys/dev/usb/usbdevs	19 Feb 2006 09:59:34 -0000
_at__at_ -1529,6 +1529,7 _at__at_
 product SOURCENEXT KEIKAI8_CHG	0x012e	KeikaiDenwa 8 with charger
 
 /* STMicroelectronics products */
+product STMICRO BIOCPU		0x2016	Biometric Coprocessor
 product STMICRO COMMUNICATOR	0x7554	USB Communicator
 
 /* STSN products */
Received on Sun Feb 19 2006 - 12:23:48 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:38:52 UTC