From nobody Fri May 17 07:47:04 2024 Delivered-To: importer@patchew.org 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+109042+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1695655780692373.56984696730774; Mon, 25 Sep 2023 08:29:40 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=MjKCwDXg+gcOZmpUsjM+AraLBQ/I2OtybArhU0I5dwk=; c=relaxed/simple; d=groups.io; h=ARC-Seal:ARC-Message-Signature:ARC-Authentication-Results:Received-SPF:From:To:CC:Subject:Date:Message-ID:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Type; s=20140610; t=1695655780; v=1; b=AdJYbCZZ07r2ynj5lrZyFR3nGcmobvwi1Rs/ujFzTlrJWxYtbsvv9Wh0SuW0bkzLaC1MfBfl tKz5I5eGdNu7lRnUptdr4aE43ziFqNxanvDNWopGFtwNkBo4YDelVF9T3mbZtNXs4+6Q+JGfW2c aSH+Z/d3APs1OPC5ft/m6KX4= X-Received: by 127.0.0.2 with SMTP id pwuOYY1788612xhePPsAhn5w; Mon, 25 Sep 2023 08:29:40 -0700 X-Received: from NAM04-DM6-obe.outbound.protection.outlook.com (NAM04-DM6-obe.outbound.protection.outlook.com [40.107.102.86]) by mx.groups.io with SMTP id smtpd.web10.52595.1695606895795183260 for ; Sun, 24 Sep 2023 18:54:56 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WegcpM3A91VlRUgQIeTAD6pSCdi518ZcXTyVLInXmh7k7A/mKGQ+9Wukmnf+EmlqT5qRRhsGUiL9p0A43ZpIcbpX/uFNPTv9zot8lmlqKZQs/kvV3hmfIz91ABGLufxrhMV6LNmLtIkyW9MX6v4b50THiSRX83Xv87cNtSdWgO/gFMEWa+r82Qc5p9khUhzK/dyuL+xDwz07gC0eV6ennUopiND6j+mVt1T8lXOwmMPLYi9tXon1cZFTLfRD2tSzdJaei1LwFp9C4Am55+RfXPmkU4BK6p/fh7QNwqDrksr/841htczNQmCnCALC5CGhfgotuJd7WNqBd5oKtSAMSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=3ryzaZBQY3L3Sxhb8jIiPzzlur6nV/FPp0awIhinWZU=; b=HBhzXSfIjcFvE2BOqdDBLViYCuzh8cpjCFbsj0LMPwPswognJ/9N5IWTUCU3iszKz9jaBLAY6O554812L9Vy+hdXA2qHjRh5SRG20wGJL46mC2gqZYbg3BxYAdgHZyMvILAMoShu++9ZS15EQinjESduSzpQtPT37VisvfX/VEn6KUGjAq6qWjImWzaBvy1CgKLVJy+kxw0b6B1czJCwnV316i1PTv+djHnz3HqmZ2JijTUVujhOGy8S0d3B7NIJemQNJeSsZdt1llalqTyvZvuQ2VbYptvSwAVEqDvRn420qrw65xDBsUYA2uSPIiLWyV1PjYD8+BmqFWpfoFHhCA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.233) smtp.rcpttodomain=edk2.groups.io smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none X-Received: from DM6PR10CA0033.namprd10.prod.outlook.com (2603:10b6:5:60::46) by MN2PR12MB4533.namprd12.prod.outlook.com (2603:10b6:208:266::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6813.28; Mon, 25 Sep 2023 01:54:53 +0000 X-Received: from DS3PEPF000099DC.namprd04.prod.outlook.com (2603:10b6:5:60:cafe::b1) by DM6PR10CA0033.outlook.office365.com (2603:10b6:5:60::46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.35 via Frontend Transport; Mon, 25 Sep 2023 01:54:52 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.233) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; 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+109042+1787277+3901457@groups.io; helo=mail02.groups.io; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.118.233 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.233; helo=mail.nvidia.com; pr=C X-Received: from mail.nvidia.com (216.228.118.233) by DS3PEPF000099DC.mail.protection.outlook.com (10.167.17.198) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6838.14 via Frontend Transport; Mon, 25 Sep 2023 01:54:52 +0000 X-Received: from drhqmail202.nvidia.com (10.126.190.181) by mail.nvidia.com (10.127.129.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Sun, 24 Sep 2023 18:54:50 -0700 X-Received: from drhqmail203.nvidia.com (10.126.190.182) by drhqmail202.nvidia.com (10.126.190.181) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Sun, 24 Sep 2023 18:54:50 -0700 X-Received: from build-rtseng-20230329T225905692.nvidia.com (10.127.8.11) by mail.nvidia.com (10.126.190.182) with Microsoft SMTP Server id 15.2.986.41 via Frontend Transport; Sun, 24 Sep 2023 18:54:50 -0700 From: "Rick Tseng via groups.io" To: CC: , , , , , , Rick Tseng Subject: [edk2-devel] [PATCH] MdeModulePkg/UsbBus: Get device/config descriptor after port reset Date: Mon, 25 Sep 2023 01:54:33 +0000 Message-ID: <363ba9c963a54eab7ba740c3a22fd12f3f2edfc0.1695606406.git.rtseng@nvidia.com> MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF000099DC:EE_|MN2PR12MB4533:EE_ X-MS-Office365-Filtering-Correlation-Id: 848b4468-defc-418c-4843-08dbbd6a6909 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: ZVVZR0vNT6rWBaVLdW0Niqg3J5lFCfx2DPwEKtptnaid+ygu4R+pCaTGdLIiB640UMa2syxqBl1RZZfwRuZySQQLyj+mBGaIpEja2Dhi8YO8t4Bgy2D4ilaLIcc2aJn0S0ZiWobTsvmidL7i/p61jFUzcMPl1xiS6ZoW7OWPgTqG6uel7lNk5K5SEPH1fGkyYjjtScK8dzkYr6jtkKnuEylfgyG9ics4OXIA+ZiB/IMJIT6iFB2Vw+s0rft0D3Bo0tXMGD8fIWcsSxPXIcVcT5LyXf88uG/3tdTRsvhLhU9RuxtvLg6PftFjRtmIgn4bk+cqRGinVNRgA9t+CNG3Zy7D2eCzLsM1mHwdqX4QzpWiRa9Cf69kWQtECe5AJXoNujXgWuqS/TMQzRH3Hnt1IolyGGdGBjxy7wNodJmkZBZqcUu2L/fwrjl3NI/kLOWaVL9uKaJHoxDm9cQ3NAsWRYDjUbzSzbyN0UdcvtSeCExBsfnwUvKPD2EH6qmYHvyjOKj23vx+v1Fnfp0s33Yro1RWPqtfDvpHlfcRIUEV6Eo7NZgLMguwmPUvC7+Uy55m6ODFs8zXDrK2Fv3sYsaTUR+zVsOdhCE5Ht3WAbkEqJ0Cx7kdvLc+SzG+IOkkCr1p7UttDm02iYbKv3wLLqZ3OPtiw6v6NNOLp0cNM7MTLJq27gVIm6h7h861zpq2jT2IiA6kX0O5kPC0AxmO3oC+cajxl26cHIK7z8CnZUU1I6A= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Sep 2023 01:54:52.7893 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 848b4468-defc-418c-4843-08dbbd6a6909 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.118.233];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DS3PEPF000099DC.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4533 Precedence: Bulk List-Subscribe: List-Help: 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,rtseng@nvidia.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: j5QeWMv2SXYgohjyhxL8Te8Qx1787277AA= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1695655782457100003 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" To fix the assert due to ASSERT(TrsRing !=3DNULL) in XhcSyncTrsRing. There is a recovery in usb mass stroage driver to do port reset after fail in transfer. And port reset operation makes that all memory resources(descriptors, endpoint memory) belonging to this device are reclaimed in underlying Xhci driver. Because USB descriptors are reclaimed in underlying Xhci driver, the next "set config" would not trigger the "Configuration Endpoint" command in Xhci driver as there is no existing configuation descriptor. It would prevent from allocating memory from xhci for endpoints. Thus there is no memmory allocated for transfering on non-default endpoint, it makes the assert happens when usb mass stroage tries to transfer after reset. This change is to refetch the device and config descriptor after port reset, it would rebuild device and configuration descriptor in Xhci driver. So the "set config" command would trigger the "Configuration Endpoint" in xhci and allocate memory for endpoints. Signed-off-by: Rick Tseng --- MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c | 77 ++++++++++++++++++++++-- MdeModulePkg/Bus/Usb/UsbBusDxe/UsbDesc.h | 25 ++++++++ 2 files changed, 96 insertions(+), 6 deletions(-) diff --git a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c b/MdeModulePkg/Bus/Usb= /UsbBusDxe/UsbBus.c index c25f3cc2f2..f6e1f88b3d 100644 --- a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c +++ b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c @@ -815,12 +815,16 @@ UsbIoPortReset ( IN EFI_USB_IO_PROTOCOL *This ) { - USB_INTERFACE *UsbIf; - USB_INTERFACE *HubIf; - USB_DEVICE *Dev; - EFI_TPL OldTpl; - EFI_STATUS Status; - UINT8 DevAddress; + USB_INTERFACE *UsbIf; + USB_INTERFACE *HubIf; + USB_DEVICE *Dev; + EFI_TPL OldTpl; + EFI_STATUS Status; + UINT8 DevAddress; + USB_DEVICE_DESC DevDesc; + UINT8 NumConfig; + VOID *Buf; + UINT8 Index; =20 OldTpl =3D gBS->RaiseTPL (USB_BUS_TPL); =20 @@ -882,6 +886,67 @@ UsbIoPortReset ( // is in CONFIGURED state. // if (Dev->ActiveConfig !=3D NULL) { + // + // We just do a port reset, so we need to do as a new device enumerati= on. + // Need to get the device descriptor, configuration descriptor before = set config + // + Status =3D UsbCtrlGetDesc (Dev, USB_DESC_TYPE_DEVICE, 0, 0, &DevDesc, = sizeof (DevDesc)); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "UsbIoPortReset: failed to get device desc for device %d - %r\n", + Dev->Address, + Status + )); + goto ON_EXIT; + } + + NumConfig =3D Dev->DevDesc->Desc.NumConfigurations; + if (NumConfig =3D=3D 0) { + DEBUG (( + DEBUG_ERROR, + "UsbIoPortReset: no configuration descriptor for device %d - %r\n", + Dev->Address, + Status + )); + goto ON_EXIT; + } + + for (Index =3D 0; Index < NumConfig; Index++) { + if (Dev->DevDesc->Configs[Index] =3D=3D NULL) { + DEBUG (( + DEBUG_ERROR, + "UsbIoPortReset: no configuration descriptor for index %d - %r\n= ", + Index, + Status + )); + goto ON_EXIT; + } + + Buf =3D AllocateZeroPool (Dev->DevDesc->Configs[Index]->Desc.TotalLe= ngth); + if (Buf =3D=3D NULL) { + DEBUG (( + DEBUG_ERROR, + "UsbIoPortReset: allocation memory fail for configuration desc -= %r\n", + Status + )); + goto ON_EXIT; + } + + Status =3D UsbCtrlGetDesc (Dev, USB_DESC_TYPE_CONFIG, Index, 0, Buf,= Dev->DevDesc->Configs[Index]->Desc.TotalLength); + FreePool (Buf); + + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "UsbIoPortReset: failed to get config desc for device %d - %r\n", + Dev->Address, + Status + )); + goto ON_EXIT; + } + } + Status =3D UsbSetConfig (Dev, Dev->ActiveConfig->Desc.ConfigurationVal= ue); =20 if (EFI_ERROR (Status)) { diff --git a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbDesc.h b/MdeModulePkg/Bus/Us= b/UsbBusDxe/UsbDesc.h index ce205e706d..5ae5c4056b 100644 --- a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbDesc.h +++ b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbDesc.h @@ -224,4 +224,29 @@ UsbIoClearFeature ( IN UINT16 Index ); =20 +/** + Get the standard descriptors. + + @param UsbDev The USB device to read descriptor from. + @param DescType The type of descriptor to read. + @param DescIndex The index of descriptor to read. + @param LangId Language ID, only used to get string, othe= rwise set + it to 0. + @param Buf The buffer to hold the descriptor read. + @param Length The length of the buffer. + + @retval EFI_SUCCESS The descriptor is read OK. + @retval Others Failed to retrieve the descriptor. + +**/ +EFI_STATUS +UsbCtrlGetDesc ( + IN USB_DEVICE *UsbDev, + IN UINTN DescType, + IN UINTN DescIndex, + IN UINT16 LangId, + OUT VOID *Buf, + IN UINTN Length + ); + #endif --=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 (#109042): https://edk2.groups.io/g/devel/message/109042 Mute This Topic: https://groups.io/mt/101576341/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-