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.web08.267.1603905615566568587 for ; Wed, 28 Oct 2020 10:20:15 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@nvidia.com header.s=n1 header.b=eQcA2EOM; 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 ; Wed, 28 Oct 2020 10:20:18 -0700 Received: from HQMAIL105.nvidia.com (172.20.187.12) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Wed, 28 Oct 2020 17:20:11 +0000 Received: from jbrasen-ux.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; Wed, 28 Oct 2020 17:20:10 +0000 From: "Jeff Brasen" To: CC: , , , Jon Hunter , Jeff Brasen Subject: [PATCH v3 1/1] MdeModulePkg/XhciDxe: Retry device slot init on failure Date: Wed, 28 Oct 2020 11:20:08 -0600 Message-ID: <5a3b90de7f0c824e1a2c29ce06592b263e4c760e.1603905582.git.jbrasen@nvidia.com> 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=1603905618; bh=LZvwlO0gac7zeykc2q0ZsENAv0lEGYaaxVRwbeh9vAU=; h=From:To:CC:Subject:Date:Message-ID:X-Mailer:MIME-Version: X-NVConfidentiality:Content-Transfer-Encoding:Content-Type; b=eQcA2EOMpAMBJ0L3Hqlen+Ddl75j7gGvxAVvufLhoDhFsicuyOZhda+cqZbNHylf3 Pm2kVeXHHPSe4sENSEc9uy6AE/11HjvBiRO94pvOc4n+EGwj6CR4BCjeTPzP3QHIdQ 8NB3ZcMcpJozKNYjl1a0gbAjw5sKfv5n3SaYzgoXVB4f5ZCkOgqk1um/n/ZO3+Wjkf joZUE0GpDFYtzRQj5IvtzxVSBMHTpXduzuvtf/3pafRNREc5q3AT9TPOwFJDjfrfqO qjIhMaTAXv3gdpwBg33P3BM3tVVku6jTkE6tgDYo/kipFwtc3OYB7MeWiaxTuZaDhL siWMMP2XKPY3A== 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. Change was verified using a superspeed mass storage device that was occasio= nally failing to enumerate in UEFI. With this change this failure to enumerate was resolved. This failure was also only seen in UEFI and not in the OS. 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..dc36945962a0 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-- !=3D 0)); } =20 return Status; --=20 2.25.1