Re: [PATCH] XhciDxe: Clean up UsbDevContext if USB slot initialization is failed


Wu, Hao A
 

-----Original Message-----
From: Luo, Heng <heng.luo@...>
Sent: Thursday, October 15, 2020 9:49 AM
To: devel@edk2.groups.io
Cc: Ni, Ray <ray.ni@...>; Wu, Hao A <hao.a.wu@...>
Subject: [PATCH] XhciDxe: Clean up UsbDevContext if USB slot initialization is
failed

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3007

Thanks for the patch Heng.

After looking into the analysis at https://bugzilla.tianocore.org/show_bug.cgi?id=3007#c1:
|> Enable Slot Successfully, The Slot ID = 0x3
|> Address 3 assigned successfully
|> UsbEnumerateNewDev: hub port 15 is reset
|> UsbEnumerateNewDev: device is of 3 speed
|> UsbEnumerateNewDev: device uses translator (0, 0)
|> XhcControlTransfer: SlotId == 2 DeviceAddress=0

The wrong 'SlotId' is used for the control transfer command, where SlotId 2 is for the device failed to be initialized.
Heng, could you help to check whether it is possible for the next device to use SlotId 2 again? Thanks in advance.

Best Regards,
Hao Wu



Currently UsbDevContext is not cleaned up if USB slot initialization is failed,
the wrong context data will affect next USB devices and the USB devices can
not be enumerated.
Need to clean up UsbDevContext if USB slot initialization is failed.

Cc: Ray Ni <ray.ni@...>
Cc: Hao A Wu <hao.a.wu@...>
Signed-off-by: Heng Luo <heng.luo@...>
---
MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c
b/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c
index 9cb115363c..1e8430ac34 100644
--- a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c
+++ b/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c
@@ -2,7 +2,7 @@
XHCI transfer scheduling routines. -Copyright (c) 2011 - 2018, Intel
Corporation. All rights reserved.<BR>+Copyright (c) 2011 - 2020, Intel
Corporation. All rights reserved.<BR> Copyright (c) Microsoft
Corporation.<BR> SPDX-License-Identifier: BSD-2-Clause-Patent @@ -2279,6
+2279,9 @@ XhcInitializeDeviceSlot (
DeviceAddress = (UINT8) ((DEVICE_CONTEXT *) OutputContext)-
Slot.DeviceAddress; DEBUG ((EFI_D_INFO, " Address %d assigned
successfully\n", DeviceAddress)); Xhc-
UsbDevContext[SlotId].XhciDevAddr = DeviceAddress;+ } else {+ DEBUG
((DEBUG_INFO, " Address %d assigned unsuccessfully, clean up context
data.\n"));+ ZeroMem (&Xhc->UsbDevContext[SlotId], sizeof
(USB_DEV_CONTEXT)); } return Status;@@ -2489,7 +2492,11 @@
XhcInitializeDeviceSlot64 (
DeviceAddress = (UINT8) ((DEVICE_CONTEXT_64 *) OutputContext)-
Slot.DeviceAddress; DEBUG ((EFI_D_INFO, " Address %d assigned
successfully\n", DeviceAddress)); Xhc-
UsbDevContext[SlotId].XhciDevAddr = DeviceAddress;+ } else {+ DEBUG
((DEBUG_INFO, " Address %d assigned unsuccessfully, clean up context
data.\n"));+ ZeroMem (&Xhc->UsbDevContext[SlotId], sizeof
(USB_DEV_CONTEXT)); }+ return Status; } --
2.24.0.windows.2

Join devel@edk2.groups.io to automatically receive all group messages.