From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from hqnvemgate24.nvidia.com (hqnvemgate24.nvidia.com [216.228.121.143]) by mx.groups.io with SMTP id smtpd.web12.6659.1603447144084294397 for ; Fri, 23 Oct 2020 02:59:04 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@nvidia.com header.s=n1 header.b=ZEbMP6nj; spf=permerror, err=parse error for token &{10 18 %{i}._ip.%{h}._ehlo.%{d}._spf.vali.email}: invalid domain name (domain: nvidia.com, ip: 216.228.121.143, mailfrom: jonathanh@nvidia.com) Received: from hqmail.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate24.nvidia.com (using TLS: TLSv1.2, AES256-SHA) id ; Fri, 23 Oct 2020 02:57:29 -0700 Received: from HQMAIL105.nvidia.com (172.20.187.12) by HQMAIL109.nvidia.com (172.20.187.15) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Fri, 23 Oct 2020 09:58:58 +0000 Received: from thunderball.nvidia.com (10.124.1.5) by mail.nvidia.com (172.20.187.12) with Microsoft SMTP Server id 15.0.1473.3 via Frontend Transport; Fri, 23 Oct 2020 09:58:57 +0000 From: Jon Hunter To: , , , CC: , Jon Hunter Subject: [RESEND PATCH V2] MdeModulePkg/XhciDxe: Retry device slot init on failure Date: Fri, 23 Oct 2020 10:58:55 +0100 Message-ID: <20201023095855.31735-1-jonathanh@nvidia.com> X-Mailer: git-send-email 2.17.1 X-NVConfidentiality: public Return-Path: jonathanh@nvidia.com MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1603447049; bh=k1P8L2ttbGKemtBfjjr0mGFvzBArICSQv09ETGtwyVA=; h=From:To:CC:Subject:Date:Message-ID:X-Mailer:X-NVConfidentiality: MIME-Version:Content-Type; b=ZEbMP6nje5ByMJRJLcvoAxpbyKuTx8EhdeBxlbBBht8qdSFiKGQ9llPX5fRb7j7CI TqO0gEImPe9V540PVBt/0R7gztu1kFLPbrXX7R0Zf9AnJF9qwxi455bPUtuPA5vhgG uYfiWhBIJ1HMkFVzalZuLwbUwRokM1fIhesRKxApr1vtsRBIVVWlgqNoeVXs9/V/N2 gji8VPVrtwQ16pKEIoDIJhpe3kPztkWwf0gzJj+plBlkgVZ/wx5YYlIxkeQwbXuJx5 7Liohd4qq23XZZDenKdls/aKZXN7/T8e7ZMnpMWFq7WfLeeg0gpPz3KiLeR01ItTED DvrDA7QIYBd4w== Content-Type: text/plain With some super-speed USB mass storage devices it has been observed that a USB transaction error may occur when attempting the set the device address during enumeration. According the the xHCI specification (section 4.6.5) ... "A USB Transaction ErrorCompletion Code for an Address Device Command may be due to a Stall response from a device. Software should issue a Disable Slot Commandfor the Device Slot then an Enable Slot Command to recover from this error." To fix this, retry the device slot initialization if it fails due to a device error. Signed-off-by: Jon Hunter --- MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c | 34 +++++++++++++++++------- MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.h | 1 + 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c b/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c index 2e0867af7997..45423869be81 100644 --- a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c +++ b/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c @@ -1684,9 +1684,11 @@ XhcPollPortStatusChange ( EFI_STATUS Status; UINT8 Speed; UINT8 SlotId; + UINT8 Retries; USB_DEV_ROUTE RouteChart; Status = EFI_SUCCESS; + Retries = XHC_INIT_DEVICE_SLOT_RETRIES; if ((PortState->PortChangeStatus & (USB_PORT_STAT_C_CONNECTION | USB_PORT_STAT_C_ENABLE | USB_PORT_STAT_C_OVERCURRENT | USB_PORT_STAT_C_RESET)) == 0) { return EFI_SUCCESS; @@ -1728,17 +1730,29 @@ XhcPollPortStatusChange ( } else if ((PortState->PortStatus & USB_PORT_STAT_SUPER_SPEED) != 0) { Speed = EFI_USB_SPEED_SUPER; } - // - // Execute Enable_Slot cmd for attached device, initialize device context and assign device address. - // - SlotId = XhcRouteStringToSlotId (Xhc, RouteChart); - if ((SlotId == 0) && ((PortState->PortChangeStatus & USB_PORT_STAT_C_RESET) != 0)) { - if (Xhc->HcCParams.Data.Csz == 0) { - Status = XhcInitializeDeviceSlot (Xhc, ParentRouteChart, Port, RouteChart, Speed); - } else { - Status = XhcInitializeDeviceSlot64 (Xhc, ParentRouteChart, Port, RouteChart, Speed); + + do { + // + // Execute Enable_Slot cmd for attached device, initialize device context and assign device address. + // + SlotId = XhcRouteStringToSlotId (Xhc, RouteChart); + if ((SlotId == 0) && ((PortState->PortChangeStatus & USB_PORT_STAT_C_RESET) != 0)) { + if (Xhc->HcCParams.Data.Csz == 0) { + Status = XhcInitializeDeviceSlot (Xhc, ParentRouteChart, Port, RouteChart, Speed); + } else { + Status = XhcInitializeDeviceSlot64 (Xhc, ParentRouteChart, Port, RouteChart, Speed); + } } - } + + // + // According to the xHCI specification (section 4.6.5), "a USB Transaction + // Error Completion Code for an Address Device Command may be due to a Stall + // response from a device. Software should issue a Disable Slot Command for + // the Device Slot then an Enable Slot Command to recover from this error." + // Therefore, retry the device slot initialization if it fails due to a + // device error. + // + } while ((Status == EFI_DEVICE_ERROR) && (Retries--)); } return Status; diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.h b/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.h index 2f1899502151..3f9cdb1c3609 100644 --- a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.h +++ b/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.h @@ -11,6 +11,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #define _EFI_XHCI_SCHED_H_ #define XHC_URB_SIG SIGNATURE_32 ('U', 'S', 'B', 'R') +#define XHC_INIT_DEVICE_SLOT_RETRIES 1 // // Transfer types, used in URB to identify the transfer type -- 2.17.1