Skip to contentSkip to conversation

usb: Add 1ms delay after first Get Descriptor request

PATCH In review Marek Vasut 3 participants 5 messages Oct 30, 2022 – Nov 3, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usb: Add 1ms delay after first Get Descriptor request

Logitech Unifying Receiver 046d:c52b bcdDevice 12.10 seems sensitive about the first Get Descriptor request. If there are any other requests in the same microframe, the device reports bogus data, first of the descriptor parts is not sent to the host. Wait over one microframe duration before issuing subsequent requests to avoid probe failure with this device, since it can be used to connect USB keyboards.

---
Cc: Janne Grunau <[email protected]>
Cc: Mark Kettenis <[email protected]>

---
 common/usb.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
common/usb.c +11 -0
index 6fcf1e8428e..ae9253dfc0e 100644
@@ -999,6 +999,17 @@ static int usb_setup_descriptor(struct usb_device *dev, bool do_read)
 		err = get_descriptor_len(dev, 64, 8);
 		if (err)
 			return err;
+
+		/*
+		 * Logitech Unifying Receiver 046d:c52b bcdDevice 12.10 seems
+		 * sensitive about the first Get Descriptor request. If there
+		 * are any other requests in the same microframe, the device
+		 * reports bogus data, first of the descriptor parts is not
+		 * sent to the host. Wait over one microframe duration here
+		 * (1mS for USB 1.x , 125uS for USB 2.0) to avoid triggering
+		 * the issue.
+		 */
+		mdelay(1);
 	}
 
 	dev->epmaxpacketin[0] = dev->descriptor.bMaxPacketSize0;
Signature · 1 line
2.35.1
#1 lore raw

Hi Marek,

Quoted 9 lines · Marek Vasut

Logitech Unifying Receiver 046d:c52b bcdDevice 12.10 seems sensitive about the first Get Descriptor request. If there are any other requests in the same microframe, the device reports bogus data, first of the descriptor parts is not sent to the host. Wait over one microframe duration before issuing subsequent requests to avoid probe failure with this device, since it can be used to connect USB keyboards.

Quoted 7 lines

---
Cc: Janne Grunau <[email protected]>
Cc: Mark Kettenis <[email protected]>

---
 common/usb.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

Is this device complying with the spec or is it broken?

In any case we need a way to enable/disable this as it will slow down unaffected platforms.

I've also been wondering if (not with this patch) USB can move to using the cyclic stuff to do its work, so we don't have to wait.

Quoted 24 lines
common/usb.c +11 -1
index 6fcf1e8428e..ae9253dfc0e 100644
@@ -999,6 +999,17 @@ static int usb_setup_descriptor(struct usb_device *dev, bool do_read)
                err = get_descriptor_len(dev, 64, 8);
                if (err)
                        return err;
+
+               /*
+                * Logitech Unifying Receiver 046d:c52b bcdDevice 12.10 seems
+                * sensitive about the first Get Descriptor request. If there
+                * are any other requests in the same microframe, the device
+                * reports bogus data, first of the descriptor parts is not
+                * sent to the host. Wait over one microframe duration here
+                * (1mS for USB 1.x , 125uS for USB 2.0) to avoid triggering
+                * the issue.
+                */
+               mdelay(1);
        }
 
        dev->epmaxpacketin[0] = dev->descriptor.bMaxPacketSize0;
--
Quoted 2 lines

2.35.1

Regards,
Simon

#2 lore raw
Quoted 1 line · Simon Glass

Hi Marek,

Hi,

Quoted 18 lines · Marek Vasut
Quoted 9 lines

Logitech Unifying Receiver 046d:c52b bcdDevice 12.10 seems sensitive about the first Get Descriptor request. If there are any other requests in the same microframe, the device reports bogus data, first of the descriptor parts is not sent to the host. Wait over one microframe duration before issuing subsequent requests to avoid probe failure with this device, since it can be used to connect USB keyboards.

Quoted 7 lines

---
Cc: Janne Grunau <[email protected]>
Cc: Mark Kettenis <[email protected]>

---
  common/usb.c | 11 +++++++++++
  1 file changed, 11 insertions(+)
Quoted 4 lines

Is this device complying with the spec or is it broken?

In any case we need a way to enable/disable this as it will slow down unaffected platforms.

This makes little difference, since anyone can plug such device into a port and suddenly the platform is affected. We cannot really predict what users have on their desks.

Specifically for this case, the logitech receiver seems to be a rather common device.

Quoted 2 lines

I've also been wondering if (not with this patch) USB can move to using the cyclic stuff to do its work, so we don't have to wait.

EHCI HCD already partly does, at least for storage, so yes, patches welcome.

Tested-by
#3 lore raw
Quoted 24 lines · Marek Vasut
Quoted 1 line · Simon Glass

Hi Marek,

Hi,

Quoted 19 lines · Marek Vasut
Quoted 9 lines

Logitech Unifying Receiver 046d:c52b bcdDevice 12.10 seems sensitive about the first Get Descriptor request. If there are any other requests in the same microframe, the device reports bogus data, first of the descriptor parts is not sent to the host. Wait over one microframe duration before issuing subsequent requests to avoid probe failure with this device, since it can be used to connect USB keyboards.

Quoted 7 lines

---
Cc: Janne Grunau <[email protected]>
Cc: Mark Kettenis <[email protected]>

---
  common/usb.c | 11 +++++++++++
  1 file changed, 11 insertions(+)

Is this device complying with the spec or is it broken?

This is not just this device. We have seen this reported with a few keyboards on apple silicon devices. Keychron devices are one group I can remember.

Quoted 7 lines
Quoted 3 lines

In any case we need a way to enable/disable this as it will slow down unaffected platforms.

This makes little difference, since anyone can plug such device into a port and suddenly the platform is affected. We cannot really predict what users have on their desks.

Would it make sense to limit it to dwc3 host controllers or do you fear the same problem could happen with other controllers on fast boards?

In any case patch fixes the problem here as well.

Thanks,

Janne

#4 lore raw

On 11/3/22 22:31, Janne Grunau wrote:

Hi,

[...]

Quoted 9 lines
Quoted 6 lines
Quoted 2 lines

In any case we need a way to enable/disable this as it will slow down unaffected platforms.

This makes little difference, since anyone can plug such device into a port and suddenly the platform is affected. We cannot really predict what users have on their desks.

Would it make sense to limit it to dwc3 host controllers or do you fear the same problem could happen with other controllers on fast boards?

I believe the DWC3 triggers it on "fast" devices now, but this is a generic issue. The U-Boot USB stack is just way too efficient (well, more efficient than any OS anyway, because it is basically just a tight loop), no OS triggers this because the OSes take their time.

Quoted 3 lines

In any case patch fixes the problem here as well.

Thanks!

(and sorry for the delay)