From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-m24147.qiye.163.com (mail-m24147.qiye.163.com [220.194.24.147]) by mx.groups.io with SMTP id smtpd.web11.3843.1594954172564662585 for ; Thu, 16 Jul 2020 19:49:33 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: zd-tech.com.cn, ip: 220.194.24.147, mailfrom: lbfeng@zd-tech.com.cn) Received: from localhost.localdomain (unknown [223.104.3.146]) by smtp4 (Coremail) with SMTP id JedpCgB3itC3ERFfKkOICA--.323S2; Fri, 17 Jul 2020 10:49:28 +0800 (CST) From: "Feng Libo" To: devel@edk2.groups.io, czhang@zd-tech.com.cn Cc: Feng Libo Subject: [PATCH] MdeModulePkg/UsbBusDxe: some USB PenDisk fails enumeration. Date: Fri, 17 Jul 2020 10:49:13 +0800 Message-Id: <2a831532171eec3c9f5a0630621fc23c7f894935.1594953823.git.lbfeng@zd-tech.com.cn> X-Mailer: git-send-email 2.13.2.windows.1 X-CM-TRANSID: JedpCgB3itC3ERFfKkOICA--.323S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxGF1rAFy8KFyDuw17JrWDArb_yoWrJrW3pF 45Jay5trZxJF90kw4fXw18Kw1rCF4rGa93XFZ3tw12kr1avrZY9F1a93WUuayUJF1kZFyk urn8ZFWrWr429FJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0JbfdgAUUUUU= X-Originating-IP: [223.104.3.146] X-CM-SenderInfo: poeiv0vj62vghwhfxhxfrphubq/1tbiWhhkmFf4ppHJZwAAsI 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 --- 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