From nobody Wed May 8 07:20:55 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+66496+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+66496+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=nvidia.com ARC-Seal: i=1; a=rsa-sha256; t=1603295094; cv=none; d=zohomail.com; s=zohoarc; b=bNyq8We+H9csrR8nMfn5LibPhhcSLV8WYXiBttaTb3HJMWvIwnjJMhdArTJuZfv8HuAyBk2SpqkfIKRa07B0pLTXXL6Am0GEeFKpXQh6EKoyx4H+CexbuHQXYPAJCO3aBFT4HvWwALIEPKta6/VHXflyjUnapepF6UUIZRI8Upc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603295094; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Sender:Subject:To; bh=exqyDTlihOsETg0aF091jT0XipqqFB1E1HqUuCBBRo0=; b=FJdfacXLanTcglAS/gxuS1n1Js5XLXTtDdxeBY10ZICdg+dLWmRyMilLlij8wSuomq9+/F4onN4nZBIPghqNJARGcEos7l9M0KN5oXnor46XCkUUyahiIv8Yt+MuPJgLxoOzEGg+tsFcUT+M3sTOmaPekUzOBixYXZ7EtJ3Dp20= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+66496+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1603295094549929.7068405740031; Wed, 21 Oct 2020 08:44:54 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 4j6xYY1788612xzQxtuhWCAl; Wed, 21 Oct 2020 08:44:54 -0700 X-Received: from hqnvemgate26.nvidia.com (hqnvemgate26.nvidia.com [216.228.121.65]) by mx.groups.io with SMTP id smtpd.web10.13730.1603295093712347220 for ; Wed, 21 Oct 2020 08:44:53 -0700 X-Received: from hqmail.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate26.nvidia.com (using TLS: TLSv1.2, AES256-SHA) id ; Wed, 21 Oct 2020 08:44:41 -0700 X-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; Wed, 21 Oct 2020 15:44:50 +0000 X-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, 21 Oct 2020 15:44:49 +0000 From: "Jeff Brasen" To: CC: , , Jon Hunter , Jeff Brasen Subject: [edk2-devel] [PATCH] MdeModulePkg/XhciDxe: Retry device slot init on failure Date: Wed, 21 Oct 2020 09:44:37 -0600 Message-ID: MIME-Version: 1.0 X-NVConfidentiality: public 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,jbrasen@nvidia.com X-Gm-Message-State: 5hkd1xo5Mt7ymlZCNpMhvo8qx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1603295094; bh=8iEf5EwXvnBc5P3m7DKPddRttbPAGFC0TS1iRjXSFkQ=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=Qas6wWL9LNFwvM01vtOC0l5+V2rWFO+VrIUbXRrVEUEnQFwljP2lxhNimhRHtFANq8U estMAbXlAVRL9lmS4VIa7nTjpWzmxKxctK1pJZKd3cR9IsVFdN8nC+ggb2pxFfFy14W1b GsDhhr7pA3oKgoHDTrSIaXXom8vux4mDTHo= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" 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: Jeff Brasen --- MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c | 71 ++++++++++++++---------- 1 file changed, 42 insertions(+), 29 deletions(-) diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c b/MdeModulePkg/Bus/Pc= i/XhciDxe/XhciSched.c index 9cb115363c..1a16864205 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 1; =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; @@ -1739,40 +1741,51 @@ XhcPollPortStatusChange ( RouteChart.Route.TierNum =3D ParentRouteChart.Route.TierNum + 1; } =20 - SlotId =3D XhcRouteStringToSlotId (Xhc, RouteChart); - if (SlotId !=3D 0) { - if (Xhc->HcCParams.Data.Csz =3D=3D 0) { - Status =3D XhcDisableSlotCmd (Xhc, SlotId); - } else { - Status =3D XhcDisableSlotCmd64 (Xhc, SlotId); - } - } - - if (((PortState->PortStatus & USB_PORT_STAT_ENABLE) !=3D 0) && - ((PortState->PortStatus & USB_PORT_STAT_CONNECTION) !=3D 0)) { - // - // Has a device attached, Identify device speed after port is enabled. - // - Speed =3D EFI_USB_SPEED_FULL; - if ((PortState->PortStatus & USB_PORT_STAT_LOW_SPEED) !=3D 0) { - Speed =3D EFI_USB_SPEED_LOW; - } else if ((PortState->PortStatus & USB_PORT_STAT_HIGH_SPEED) !=3D 0) { - Speed =3D EFI_USB_SPEED_HIGH; - } 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. - // + do { SlotId =3D XhcRouteStringToSlotId (Xhc, RouteChart); - if ((SlotId =3D=3D 0) && ((PortState->PortChangeStatus & USB_PORT_STAT= _C_RESET) !=3D 0)) { + if (SlotId !=3D 0) { if (Xhc->HcCParams.Data.Csz =3D=3D 0) { - Status =3D XhcInitializeDeviceSlot (Xhc, ParentRouteChart, Port, R= outeChart, Speed); + Status =3D XhcDisableSlotCmd (Xhc, SlotId); } else { - Status =3D XhcInitializeDeviceSlot64 (Xhc, ParentRouteChart, Port,= RouteChart, Speed); + Status =3D XhcDisableSlotCmd64 (Xhc, SlotId); } } - } + + if (((PortState->PortStatus & USB_PORT_STAT_ENABLE) !=3D 0) && + ((PortState->PortStatus & USB_PORT_STAT_CONNECTION) !=3D 0)) { + // + // Has a device attached, Identify device speed after port is enable= d. + // + Speed =3D EFI_USB_SPEED_FULL; + if ((PortState->PortStatus & USB_PORT_STAT_LOW_SPEED) !=3D 0) { + Speed =3D EFI_USB_SPEED_LOW; + } else if ((PortState->PortStatus & USB_PORT_STAT_HIGH_SPEED) !=3D 0= ) { + Speed =3D EFI_USB_SPEED_HIGH; + } 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 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 Transac= tion + // Error Completion Code for an Address Device Command may be due to a= Stall + // response from a device. Software should issue a Disable Slot Comman= d for + // the Device Slot then an Enable Slot Command to recover from this er= ror." + // Therefore, retry the device slot initialization if it fails due to a + // device error. + // + } while ((Status =3D=3D EFI_DEVICE_ERROR) && (Retries--)); =20 return Status; } --=20 2.25.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 (#66496): https://edk2.groups.io/g/devel/message/66496 Mute This Topic: https://groups.io/mt/77707715/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-