From nobody Mon Apr 29 02:01:01 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+66565+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+66565+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=nvidia.com ARC-Seal: i=1; a=rsa-sha256; t=1603448708; cv=none; d=zohomail.com; s=zohoarc; b=ifSYUN0shNfXue4LQGY0q8JvaFCtiPJzujXZGcqKW/t77NzN+WTasicASvnvaHhCQ7lZD8/PUZuzbFU+Z0i8FjdvUX36FjRihnG9IQWlPVdhDwow96pKU/VoZ+CqHmaYa7qJRGn4fHC70OrozkWTRK/qIiiSWR3vxyekr4j+Wz8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603448708; h=Content-Type:Cc:Date:From:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Sender:Subject:To; bh=5gpUG0K9eeR6cJjFhFuMTUxC71dsEGDUhbxdmnwSfmY=; b=OmcA7VRdAoBm2ME5ilG6MQkaijRCtn7z93gbEblrTUk/vWjjIwKvxW1XuYIEKE64+gYF7lnnxlEQs3kclZOUU7DpZz4hFIzfujktUTkm0V7E9Jr88YG990ccIPjSofHqBqiWz4WGJJyRyNYWeXtoTvTb4habdywf90QokhI1fC8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+66565+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1603448708056719.4860715099575; Fri, 23 Oct 2020 03:25:08 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id y7YgYY1788612x9GZiAbteHj; Fri, 23 Oct 2020 03:25:07 -0700 X-Received: from hqnvemgate25.nvidia.com (hqnvemgate25.nvidia.com [216.228.121.64]) by mx.groups.io with SMTP id smtpd.web09.6514.1603447115916054976 for ; Fri, 23 Oct 2020 02:58:36 -0700 X-Received: from hqmail.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate25.nvidia.com (using TLS: TLSv1.2, AES256-SHA) id ; Fri, 23 Oct 2020 02:57:47 -0700 X-Received: from HQMAIL109.nvidia.com (172.20.187.15) by HQMAIL111.nvidia.com (172.20.187.18) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Fri, 23 Oct 2020 09:58:31 +0000 X-Received: from thunderball.nvidia.com (172.20.13.39) by mail.nvidia.com (172.20.187.15) with Microsoft SMTP Server id 15.0.1473.3 via Frontend Transport; Fri, 23 Oct 2020 09:58:29 +0000 From: Jon Hunter To: , , , CC: , Jon Hunter Subject: [edk2-devel] [PATCH V2] MdeModulePkg/XhciDxe: Retry device slot init on failure Date: Fri, 23 Oct 2020 10:58:20 +0100 Message-ID: <20201023095820.31673-1-jonathanh@nvidia.com> X-NVConfidentiality: public MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,jonathanh@nvidia.com X-Gm-Message-State: 7APFTLDCrSlvoJHdvodqrIq5x1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1603448707; bh=QzHqobv8DE24Exsc3/nsCsEhL15h/M7iLeMARnTLxWE=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=LxYklPCrLpEJUcKVXcs6xU309S4mK+LOnlxFRu6lyYiM8MQwoP9Dvdnj5yCQpX+r9Ay x3nTB2Tf7lXa/CyihcvYo0v2nHgf/qUfxqOFzRxGngGBJXjv2r9YhiyvDTHQPDkuzhMnZ YBqgdQMf3vXR+8/3DkTqpBRfHvjJuyfXrnw= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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-Id: Id1e06057bee518768c7246c4f0b82b6fe06aef35 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/Pc= i/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; =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; @@ -1728,17 +1730,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; 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 --=20 2.17.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#66565): https://edk2.groups.io/g/devel/message/66565 Mute This Topic: https://groups.io/mt/77749181/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-