From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id 082BA941738 for ; Mon, 25 Sep 2023 15:29:41 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=NtHV/0/iVxnEbLuCkmG+sJr1q9QSBYn8Kwbn6vf8EWs=; 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=H+yZEg1zWSmokHvyTF6yZN2bR0DznuSPJ7aZQWhRboSX/WD/e1r+uXzeJRxdSEu+zUh9tV3k OZoKviL59aRqAg5QVovO4yd1vQZLBKBOxpRZ2YO7p3ewfGfATPyVsE3UZtonsWsD+01GcVy/YWI numghTWaW4uW/EidfFjJ8MQw= X-Received: by 127.0.0.2 with SMTP id HHRZYY7687511xb0iWv1PEXm; 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 (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: wnFgOc0lBxkAa09ul9eVzcgdx7686176AA= Content-Type: text/plain X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=H+yZEg1z; dmarc=none; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io To fix the assert due to ASSERT(TrsRing !=NULL) 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; OldTpl = gBS->RaiseTPL (USB_BUS_TPL); @@ -882,6 +886,67 @@ UsbIoPortReset ( // is in CONFIGURED state. // if (Dev->ActiveConfig != NULL) { + // + // We just do a port reset, so we need to do as a new device enumeration. + // Need to get the device descriptor, configuration descriptor before set config + // + Status = 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 = Dev->DevDesc->Desc.NumConfigurations; + if (NumConfig == 0) { + DEBUG (( + DEBUG_ERROR, + "UsbIoPortReset: no configuration descriptor for device %d - %r\n", + Dev->Address, + Status + )); + goto ON_EXIT; + } + + for (Index = 0; Index < NumConfig; Index++) { + if (Dev->DevDesc->Configs[Index] == NULL) { + DEBUG (( + DEBUG_ERROR, + "UsbIoPortReset: no configuration descriptor for index %d - %r\n", + Index, + Status + )); + goto ON_EXIT; + } + + Buf = AllocateZeroPool (Dev->DevDesc->Configs[Index]->Desc.TotalLength); + if (Buf == NULL) { + DEBUG (( + DEBUG_ERROR, + "UsbIoPortReset: allocation memory fail for configuration desc - %r\n", + Status + )); + goto ON_EXIT; + } + + Status = 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 = UsbSetConfig (Dev, Dev->ActiveConfig->Desc.ConfigurationValue); if (EFI_ERROR (Status)) { diff --git a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbDesc.h b/MdeModulePkg/Bus/Usb/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 ); +/** + 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, otherwise 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 -- 2.17.1 -=-=-=-=-=-=-=-=-=-=-=- 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/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-