From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from hqnvemgate25.nvidia.com (hqnvemgate25.nvidia.com [216.228.121.64]) by mx.groups.io with SMTP id smtpd.web11.922.1603814407289362734 for ; Tue, 27 Oct 2020 09:00:07 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@nvidia.com header.s=n1 header.b=nW6DueDO; 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.64, mailfrom: jbrasen@nvidia.com) Received: from hqmail.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate25.nvidia.com (using TLS: TLSv1.2, AES256-SHA) id ; Tue, 27 Oct 2020 09:00:11 -0700 Received: from HQMAIL111.nvidia.com (172.20.187.18) by HQMAIL111.nvidia.com (172.20.187.18) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Tue, 27 Oct 2020 16:00:06 +0000 Received: from jbrasen-ux.nvidia.com (10.124.1.5) by mail.nvidia.com (172.20.187.18) with Microsoft SMTP Server id 15.0.1473.3 via Frontend Transport; Tue, 27 Oct 2020 16:00:05 +0000 From: "Jeff Brasen" To: CC: , , , Jon Hunter , Jeff Brasen Subject: [PATCH v2 ] MdeModulePkg/XhciDxe: Retry device slot init on failure Date: Tue, 27 Oct 2020 10:00:04 -0600 Message-ID: X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-NVConfidentiality: public Return-Path: jbrasen@nvidia.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1603814411; bh=Ji3a7evNU2jOGvZ2jUObIWQuxL5v/6AZVd3oZ9PcXys=; h=From:To:CC:Subject:Date:Message-ID:X-Mailer:MIME-Version: X-NVConfidentiality:Content-Transfer-Encoding:Content-Type; b=nW6DueDORPdx7YChhz6iqZ3LKwxYc6WUjBgKFq+Mr3GANZQBgzdgKal2caqFuG4Tl 6GA3nnoC1XIpZUfrBiKlipSGQMa8r3umvRxAmE05kkBVHrKCK5h7Mt+8Y+ul1e0x9t 2kSCEHCdRrb04TfagIPvwr64fZ0rowZ60lc3pjNz7h47f7ahKCDCgbJLMLjRc0SbSL DTnaE5xkYKMLa9/+nrlwvONyjD+yeGc/nGa22tVyzlcN6kfjS5QfT5bw95J/qC/uoV GsRPIEtRvNBc3eAvPQa9NKYGKO2I0op2B3lSj03Jyi79MwWQC451j2UJH6IqMY/dIo HHflYjSNzyEfQ== Content-Transfer-Encoding: quoted-printable Content-Type: text/plain From: Jon Hunter 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 Signed-off-by: Jeff Brasen --- MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.h | 1 + MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c | 34 +++++++++++++++++------- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.h b/MdeModulePkg/Bus/Pc= i/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_ =20 #define XHC_URB_SIG SIGNATURE_32 ('U', 'S', 'B', 'R') +#define XHC_INIT_DEVICE_SLOT_RETRIES 1 =20 // // Transfer types, used in URB to identify the transfer type diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c b/MdeModulePkg/Bus/Pc= i/XhciDxe/XhciSched.c index 00e9cc63d63e..77664940a791 100644 --- a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c +++ b/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c @@ -1717,9 +1717,11 @@ XhcPollPortStatusChange ( EFI_STATUS Status; UINT8 Speed; UINT8 SlotId; + UINT8 Retries; USB_DEV_ROUTE RouteChart; =20 Status =3D EFI_SUCCESS; + Retries =3D XHC_INIT_DEVICE_SLOT_RETRIES; =20 if ((PortState->PortChangeStatus & (USB_PORT_STAT_C_CONNECTION | USB_POR= T_STAT_C_ENABLE | USB_PORT_STAT_C_OVERCURRENT | USB_PORT_STAT_C_RESET)) =3D= =3D 0) { return EFI_SUCCESS; @@ -1761,17 +1763,29 @@ XhcPollPortStatusChange ( } else if ((PortState->PortStatus & USB_PORT_STAT_SUPER_SPEED) !=3D 0)= { Speed =3D EFI_USB_SPEED_SUPER; } - // - // Execute Enable_Slot cmd for attached device, initialize device cont= ext and assign device address. - // - SlotId =3D XhcRouteStringToSlotId (Xhc, RouteChart); - if ((SlotId =3D=3D 0) && ((PortState->PortChangeStatus & USB_PORT_STAT= _C_RESET) !=3D 0)) { - if (Xhc->HcCParams.Data.Csz =3D=3D 0) { - Status =3D XhcInitializeDeviceSlot (Xhc, ParentRouteChart, Port, R= outeChart, Speed); - } else { - Status =3D XhcInitializeDeviceSlot64 (Xhc, ParentRouteChart, Port,= RouteChart, Speed); + + do { + // + // Execute Enable_Slot cmd for attached device, initialize device co= ntext and assign device address. + // + SlotId =3D XhcRouteStringToSlotId (Xhc, RouteChart); + if ((SlotId =3D=3D 0) && ((PortState->PortChangeStatus & USB_PORT_ST= AT_C_RESET) !=3D 0)) { + if (Xhc->HcCParams.Data.Csz =3D=3D 0) { + Status =3D XhcInitializeDeviceSlot (Xhc, ParentRouteChart, Port,= RouteChart, Speed); + } else { + Status =3D XhcInitializeDeviceSlot64 (Xhc, ParentRouteChart, Por= t, RouteChart, Speed); + } } - } + + // + // According to the xHCI specification (section 4.6.5), "a USB Trans= action + // Error Completion Code for an Address Device Command may be due to= a Stall + // response from a device. Software should issue a Disable Slot Comm= and for + // the Device Slot then an Enable Slot Command to recover from this = error." + // Therefore, retry the device slot initialization if it fails due t= o a + // device error. + // + } while ((Status =3D=3D EFI_DEVICE_ERROR) && (Retries--)); } =20 return Status; --=20 2.25.1