linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCHv2] usb-core: Add LINEAR_FRAME_INTR_BINTERVAL USB quirk
@ 2017-03-12 21:48 Samuel Thibault
  2017-03-13  1:28 ` Alan Stern
  0 siblings, 1 reply; 2+ messages in thread
From: Samuel Thibault @ 2017-03-12 21:48 UTC (permalink / raw)
  To: gregkh, Alan Stern
  Cc: linux-usb, linux-kernel, dave, kevin.derome, clause.andreabush,
	mengualjeanphi

Some USB 2.0 devices erroneously report millisecond values in
bInterval. The generic config code manages to catch most of them,
but in some cases it's not completely enough.

The case at stake here is a USB 2.0 braille device, which wants to
announce 10ms and thus sets bInterval to 10, but with the USB 2.0
computation that yields to 64ms.  It happens that one can type fast
enough to reach this interval and get the device buffers overflown,
leading to problematic latencies.  The generic config code does not
catch this case because the 64ms is considered a sane enough value.

This change thus adds a USB_QUIRK_LINEAR_FRAME_INTR_BINTERVAL quirk
to mark devices which actually report milliseconds in bInterval,
and marks Vario Ultra devices as needing it.

Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

--- a/include/linux/usb/quirks.h
+++ b/include/linux/usb/quirks.h
@@ -50,4 +50,10 @@
 /* device can't handle Link Power Management */
 #define USB_QUIRK_NO_LPM			BIT(10)
 
+/*
+ * Device reports its bInterval as linear frames instead of the
+ * USB 2.0 calculation.
+ */
+#define USB_QUIRK_LINEAR_FRAME_INTR_BINTERVAL	BIT(11)
+
 #endif /* __LINUX_USB_QUIRKS_H */
--- a/drivers/usb/core/config.c
+++ b/drivers/usb/core/config.c
@@ -280,6 +280,16 @@ static int usb_parse_endpoint(struct dev
 
 			/*
 			 * Adjust bInterval for quirked devices.
+			 */
+			/*
+			 * This quirk fixes bIntervals reported in ms.
+			 */
+			if (to_usb_device(ddev)->quirks &
+				USB_QUIRK_LINEAR_FRAME_INTR_BINTERVAL) {
+				n = clamp(fls(d->bInterval) + 3, i, j);
+				i = j = n;
+			}
+			/*
 			 * This quirk fixes bIntervals reported in
 			 * linear microframes.
 			 */
--- a/drivers/usb/core/quirks.c
+++ b/drivers/usb/core/quirks.c
@@ -170,6 +170,14 @@ static const struct usb_device_id usb_qu
 	/* M-Systems Flash Disk Pioneers */
 	{ USB_DEVICE(0x08ec, 0x1000), .driver_info = USB_QUIRK_RESET_RESUME },
 
+	/* Baum Vario Ultra */
+	{ USB_DEVICE(0x0904, 0x6101), .driver_info =
+			USB_QUIRK_LINEAR_FRAME_INTR_BINTERVAL },
+	{ USB_DEVICE(0x0904, 0x6102), .driver_info =
+			USB_QUIRK_LINEAR_FRAME_INTR_BINTERVAL },
+	{ USB_DEVICE(0x0904, 0x6103), .driver_info =
+			USB_QUIRK_LINEAR_FRAME_INTR_BINTERVAL },
+
 	/* Keytouch QWERTY Panel keyboard */
 	{ USB_DEVICE(0x0926, 0x3333), .driver_info =
 			USB_QUIRK_CONFIG_INTF_STRINGS },

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCHv2] usb-core: Add LINEAR_FRAME_INTR_BINTERVAL USB quirk
  2017-03-12 21:48 [PATCHv2] usb-core: Add LINEAR_FRAME_INTR_BINTERVAL USB quirk Samuel Thibault
@ 2017-03-13  1:28 ` Alan Stern
  0 siblings, 0 replies; 2+ messages in thread
From: Alan Stern @ 2017-03-13  1:28 UTC (permalink / raw)
  To: Samuel Thibault
  Cc: gregkh, linux-usb, linux-kernel, dave, kevin.derome,
	clause.andreabush, mengualjeanphi

On Sun, 12 Mar 2017, Samuel Thibault wrote:

> Some USB 2.0 devices erroneously report millisecond values in
> bInterval. The generic config code manages to catch most of them,
> but in some cases it's not completely enough.
> 
> The case at stake here is a USB 2.0 braille device, which wants to
> announce 10ms and thus sets bInterval to 10, but with the USB 2.0
> computation that yields to 64ms.  It happens that one can type fast
> enough to reach this interval and get the device buffers overflown,
> leading to problematic latencies.  The generic config code does not
> catch this case because the 64ms is considered a sane enough value.
> 
> This change thus adds a USB_QUIRK_LINEAR_FRAME_INTR_BINTERVAL quirk
> to mark devices which actually report milliseconds in bInterval,
> and marks Vario Ultra devices as needing it.
> 
> Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
> 
> --- a/include/linux/usb/quirks.h
> +++ b/include/linux/usb/quirks.h
> @@ -50,4 +50,10 @@
>  /* device can't handle Link Power Management */
>  #define USB_QUIRK_NO_LPM			BIT(10)
>  
> +/*
> + * Device reports its bInterval as linear frames instead of the
> + * USB 2.0 calculation.
> + */
> +#define USB_QUIRK_LINEAR_FRAME_INTR_BINTERVAL	BIT(11)
> +
>  #endif /* __LINUX_USB_QUIRKS_H */
> --- a/drivers/usb/core/config.c
> +++ b/drivers/usb/core/config.c
> @@ -280,6 +280,16 @@ static int usb_parse_endpoint(struct dev
>  
>  			/*
>  			 * Adjust bInterval for quirked devices.
> +			 */
> +			/*
> +			 * This quirk fixes bIntervals reported in ms.
> +			 */
> +			if (to_usb_device(ddev)->quirks &
> +				USB_QUIRK_LINEAR_FRAME_INTR_BINTERVAL) {
> +				n = clamp(fls(d->bInterval) + 3, i, j);
> +				i = j = n;
> +			}
> +			/*
>  			 * This quirk fixes bIntervals reported in
>  			 * linear microframes.
>  			 */
> --- a/drivers/usb/core/quirks.c
> +++ b/drivers/usb/core/quirks.c
> @@ -170,6 +170,14 @@ static const struct usb_device_id usb_qu
>  	/* M-Systems Flash Disk Pioneers */
>  	{ USB_DEVICE(0x08ec, 0x1000), .driver_info = USB_QUIRK_RESET_RESUME },
>  
> +	/* Baum Vario Ultra */
> +	{ USB_DEVICE(0x0904, 0x6101), .driver_info =
> +			USB_QUIRK_LINEAR_FRAME_INTR_BINTERVAL },
> +	{ USB_DEVICE(0x0904, 0x6102), .driver_info =
> +			USB_QUIRK_LINEAR_FRAME_INTR_BINTERVAL },
> +	{ USB_DEVICE(0x0904, 0x6103), .driver_info =
> +			USB_QUIRK_LINEAR_FRAME_INTR_BINTERVAL },
> +
>  	/* Keytouch QWERTY Panel keyboard */
>  	{ USB_DEVICE(0x0926, 0x3333), .driver_info =
>  			USB_QUIRK_CONFIG_INTF_STRINGS },

Acked-by: Alan Stern <stern@rowland.harvard.edu>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-03-13  1:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-12 21:48 [PATCHv2] usb-core: Add LINEAR_FRAME_INTR_BINTERVAL USB quirk Samuel Thibault
2017-03-13  1:28 ` Alan Stern

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).