[edk2-devel] [PATCH] MdeModulePkg/UsbBusDxe: some USB PenDisk fails enumeration.

Feng Libo posted 1 patch 3 years, 9 months ago
Failed in applying to current master (apply log)
MdeModulePkg/Bus/Usb/UsbBusDxe/UsbEnumer.c | 47 +++++++++++++++++++++---------
1 file changed, 34 insertions(+), 13 deletions(-)
[edk2-devel] [PATCH] MdeModulePkg/UsbBusDxe: some USB PenDisk fails enumeration.
Posted by Feng Libo 3 years, 9 months ago
Some USB Pen disk can't be identified during USB enumeration during UEFI
post. We have three USB Pen disks from different manufactors, all with Innostor USB
controller chip (VID=0x1F75, PID=0x917, USB3.1), they all failed in the
second device-descritor requeset. When the first device descriptor
request for the bMaxPacketSize0, only the first 8 byte within the device
descritor is fetched, which could confuse some USB Pen disks in the next
complete device descriptor, then the request of Device descriptor is
failed and USB Pen disk can't be identified. So, we adjust the
enumeration sequences, as below:
1. Port Stabilization Debounce
2. First Port Reset
3. First Device Descriptor Request for bMaxPacketSize0.
4. Second Port Reset. add extra reset
5. Set USB address
6. Second Device Descriptor Request.

whith this adjustment, now Innostor USB Pen disk can work fine in UEFI
posting.

Signed-off-by: Feng Libo <lbfeng@zd-tech.com.cn>
---
 MdeModulePkg/Bus/Usb/UsbBusDxe/UsbEnumer.c | 47 +++++++++++++++++++++---------
 1 file changed, 34 insertions(+), 13 deletions(-)

diff --git a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbEnumer.c b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbEnumer.c
index d3e0cfa626..eb055771d2 100644
--- a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbEnumer.c
+++ b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbEnumer.c
@@ -756,6 +756,40 @@ UsbEnumerateNewDev (
            Child->Translator.TranslatorPortNumber));
 
   //
+  // Host sends a Get_Descriptor request to learn the max packet
+  // size of default pipe (only part of the device's descriptor).
+  // Only the first 8 byte of Device Descriptor is requested,
+  // which could make some USB pen disks confused.
+  // therefore, a second port reset follows. 
+  //
+  Status = UsbGetMaxPacketSize0 (Child);
+
+  if (EFI_ERROR (Status)) {
+    DEBUG ((EFI_D_ERROR, "UsbEnumerateNewDev: failed to get max packet for EP 0 - %r\n", Status));
+    goto ON_ERROR;
+  }
+
+  DEBUG (( EFI_D_INFO, "UsbEnumerateNewDev: max packet size for EP 0 is %d\n", Child->MaxPacket0));
+
+  // 
+  // Some USB Pen disks would become confused by a second request for the Device Descriptor
+  // if they did not return the complete Device Descriptor for the first request.
+  // To allow these devices to enumerate successfully it was necessary to reset the port
+  // between the first and second requests for the device descriptor.
+  //
+  if (ResetIsNeeded) {
+    Status = HubApi->ResetPort (HubIf, Port);
+    if (EFI_ERROR (Status)) {
+      DEBUG ((EFI_D_ERROR, "UsbEnumerateNewDev: failed to reset port %d - %r\n", Port, Status));
+
+      return Status;
+    }
+    DEBUG (( EFI_D_INFO, "UsbEnumerateNewDev: hub port %d is reset\n", Port));
+  } else {
+    DEBUG (( EFI_D_INFO, "UsbEnumerateNewDev: hub port %d reset is skipped\n", Port));
+  }
+
+  //
   // After port is reset, hub establishes a signal path between
   // the device and host (DEFAULT state). Device's registers are
   // reset, use default address 0 (host enumerates one device at
@@ -795,19 +829,6 @@ UsbEnumerateNewDev (
   DEBUG ((EFI_D_INFO, "UsbEnumerateNewDev: device is now ADDRESSED at %d\n", Address));
 
   //
-  // Host sends a Get_Descriptor request to learn the max packet
-  // size of default pipe (only part of the device's descriptor).
-  //
-  Status = UsbGetMaxPacketSize0 (Child);
-
-  if (EFI_ERROR (Status)) {
-    DEBUG ((EFI_D_ERROR, "UsbEnumerateNewDev: failed to get max packet for EP 0 - %r\n", Status));
-    goto ON_ERROR;
-  }
-
-  DEBUG (( EFI_D_INFO, "UsbEnumerateNewDev: max packet size for EP 0 is %d\n", Child->MaxPacket0));
-
-  //
   // Host learns about the device's abilities by requesting device's
   // entire descriptions.
   //
-- 
2.13.2.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#62746): https://edk2.groups.io/g/devel/message/62746
Mute This Topic: https://groups.io/mt/75608816/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-

Re: [edk2-devel] [PATCH] MdeModulePkg/UsbBusDxe: some USB PenDisk fails enumeration.
Posted by Feng Libo 3 years, 8 months ago
Hello,

could anyone review this PATCH?

We encountered the USB enumeration problem and the patch is based on the Microsoft post as below.

https://techcommunity.microsoft.com/t5/microsoft-usb-blog/how-does-usb-stack-enumerate-a-device/ba-p/270685#:~:text=%20How%20does%20USB%20stack%20enumerate%20a%20device%3F,a%20request%20for%20the%20USB%20Device...%20More%20

Thanks

Best Regards

Feng Libo

-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#63763): https://edk2.groups.io/g/devel/message/63763
Mute This Topic: https://groups.io/mt/75608816/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-

Re: [edk2-devel] [PATCH] MdeModulePkg/UsbBusDxe: some USB PenDisk fails enumeration.
Posted by Guomin Jiang 3 years, 8 months ago
I will review it by next weekend(8/14).

Thanks.
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Feng Libo
Sent: Thursday, August 6, 2020 9:25 AM
To: Feng Libo <lbfeng@zd-tech.com.cn>; devel@edk2.groups.io
Subject: Re: [edk2-devel] [PATCH] MdeModulePkg/UsbBusDxe: some USB PenDisk fails enumeration.

Hello,

could anyone review this PATCH?

We encountered the USB enumeration problem and the patch is based on the Microsoft post as below.

https://techcommunity.microsoft.com/t5/microsoft-usb-blog/how-does-usb-stack-enumerate-a-device/ba-p/270685#:~:text=%20How%20does%20USB%20stack%20enumerate%20a%20device%3F,a%20request%20for%20the%20USB%20Device...%20More%20

Thanks

Best Regards

Feng Libo


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#63770): https://edk2.groups.io/g/devel/message/63770
Mute This Topic: https://groups.io/mt/75608816/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-