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 16683940D1D for ; Mon, 16 Oct 2023 01:54:34 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=DvepE78jlGyDk8l+rSgV4Zt8qqZgRQyB3ip34djgoxs=; c=relaxed/simple; d=groups.io; h=ARC-Seal:ARC-Message-Signature:ARC-Authentication-Results:From:To:CC:Subject:Thread-Topic:Thread-Index:Date:Message-ID:References:In-Reply-To:Accept-Language:msip_labels:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Language:Content-Type; s=20140610; t=1697421273; v=1; b=KpNHeT32JSHYNL2gx9fCdSIwujLMYzcSIwPcmtid8taD4bL9fdYPek+ASgOTV7Ypivqpttqq zeOqK9WIKinB4jDY4wuodgSPpM/WE8QUMKd5PCCtSy6y7X9UdAFWy2B829iTtTSQfdoDB7tmEtO yGui8mmHBZ9C6KurrwsyqBdk= X-Received: by 127.0.0.2 with SMTP id JGQzYY7687511xMqRLxjncEy; Sun, 15 Oct 2023 18:54:33 -0700 X-Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.65]) by mx.groups.io with SMTP id smtpd.web10.109127.1697421272588089419 for ; Sun, 15 Oct 2023 18:54:32 -0700 X-IronPort-AV: E=McAfee;i="6600,9927,10863"; a="389289407" X-IronPort-AV: E=Sophos;i="6.03,228,1694761200"; d="scan'208,217";a="389289407" X-Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Oct 2023 18:54:31 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10863"; a="1002747005" X-IronPort-AV: E=Sophos;i="6.03,228,1694761200"; d="scan'208,217";a="1002747005" X-Received: from orsmsx602.amr.corp.intel.com ([10.22.229.15]) by fmsmga006.fm.intel.com with ESMTP/TLS/AES256-GCM-SHA384; 15 Oct 2023 18:54:29 -0700 X-Received: from orsmsx611.amr.corp.intel.com (10.22.229.24) by ORSMSX602.amr.corp.intel.com (10.22.229.15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.32; Sun, 15 Oct 2023 18:54:28 -0700 X-Received: from orsmsx610.amr.corp.intel.com (10.22.229.23) by ORSMSX611.amr.corp.intel.com (10.22.229.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.32; Sun, 15 Oct 2023 18:54:27 -0700 X-Received: from ORSEDG601.ED.cps.intel.com (10.7.248.6) by orsmsx610.amr.corp.intel.com (10.22.229.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.32 via Frontend Transport; Sun, 15 Oct 2023 18:54:27 -0700 X-Received: from NAM11-CO1-obe.outbound.protection.outlook.com (104.47.56.168) by edgegateway.intel.com (134.134.137.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.32; Sun, 15 Oct 2023 18:54:26 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=g7FawqhrONvAiH9c14kV8Rz9qONzgAI1umWlJh9ATV6eg0dSdopyWQf9B1bWm9YnYjgEAnhQiEaSq0MAuNyVRQSC4U/A3xmQstMJ4bJAUsMAML0m+j91V8GnoYs5dxFnxqHaZUA55aNUWnsDT82I87h6gLWhJznx8O5XXkfk8An7jTDFV/FYs7MysMVYKXmyvlcGO02vx/U6iB3imL5r5izRUikA8IAuX2rDKf915Afa4DJYu7V8Rolw3Mdj9CcVqv+0x5KBEYqae2/JqMrvSj+Sg9+2wfrYpi3LneGfQNA00KCRql+AIaNXXjwYA5bSzarARvhF3QabMcb70sJSUw== 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=BA6c8Uo5yWyUwWNoCuQywGf20V3bEIXFzScBiCqrpo4=; b=iCXWPml4jQ5nBqYMqbpL/ZiUL+z9IgrrCQqYXjtpKHHvB+t7EKLPwgpjXb0b3mQNp/9UMWcS7x3BWZxCPSBlV7p1hfxBHUs004SJojTchJLBDnJ2+YvikoVux6+Ai7hIPGYwjPQPgnEoTjc7Ei14YfzkVE1H6D3omwdeIky6yKa3z2bt49hfKUTDGcKDUGjJgJ/mHhmBc/k72GvHQu7Sg6t5uav+Qhr8E7qp7ZfOde2reOb7e2VflOQboAdzgUj7ve84F8aOSLv6EV57eQ+d6W5qRHv+74V1+mJX+qYtAD3cvdxHl6kqbwaDjF9wfVZn+X+sNHEIkFo06ilQfRD15w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none X-Received: from DM6PR11MB4025.namprd11.prod.outlook.com (2603:10b6:5:197::31) by SJ0PR11MB8269.namprd11.prod.outlook.com (2603:10b6:a03:478::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6863.45; Mon, 16 Oct 2023 01:54:24 +0000 X-Received: from DM6PR11MB4025.namprd11.prod.outlook.com ([fe80::a194:b0f9:f9af:b3f2]) by DM6PR11MB4025.namprd11.prod.outlook.com ([fe80::a194:b0f9:f9af:b3f2%6]) with mapi id 15.20.6886.034; Mon, 16 Oct 2023 01:54:24 +0000 From: "Wu, Hao A" To: Ashish Singhal , Rick Tseng , "devel@edk2.groups.io" , "Ni, Ray" , "Wang, Jian J" , "Gao, Liming" CC: Jeff Brasen Subject: Re: [edk2-devel] [PATCH] MdeModulePkg/UsbBus: Get device/config descriptor after port reset Thread-Topic: [PATCH] MdeModulePkg/UsbBus: Get device/config descriptor after port reset Thread-Index: AQHZ71NO0HvOM94wcEiJ7eAzDGhwf7BHFwUAgASxQ1A= Date: Mon, 16 Oct 2023 01:54:23 +0000 Message-ID: References: <363ba9c963a54eab7ba740c3a22fd12f3f2edfc0.1695606406.git.rtseng@nvidia.com> In-Reply-To: Accept-Language: en-US, zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: msip_labels: x-ms-publictraffictype: Email x-ms-traffictypediagnostic: DM6PR11MB4025:EE_|SJ0PR11MB8269:EE_ x-ms-office365-filtering-correlation-id: 5261a30f-f67f-4aa9-6491-08dbcdead26b x-ld-processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam-message-info: cYeWpvgSYZCjOdnhmlmTGIPrZdd4VDGAdybeC098BpbGt5ezep+xXZFuY9pFIkmpL4rzzc0l2kYma2U0qIGG7leT3zo7H7mim3LKBR78czH3rXmkLykgp11VGo5GVJGEzRUCdmkFC/++MtT+hsgVjMxwx2ffB00tKKWhFgDGjK3gTFQ94KW45dTeEX9bXHmWlUSonxLSs9eNpKva27MOMbbbMJ+pOLwnjXyMjYNWIJH/uzTAsdSe6b6hEaXHIj6itjIOUej/IjFKt4g4iJHBMsqIEUefyXh8KO0rI/WLeUuCuTfXN+pgUAXufDicq+Kk0tPBtIl7MJCf+/w3r+31rV/6G/8dNyakYUyqUn53SwXt+u1Er6DHHsQCngnV2qJJLp5K+4XQy8mzfltmoXZz5gwVGOoXc2WlcMHM+tzX3Ln7ZLtZaKurZoJx0wZOjzoIrID+xjqyawZkUSrwd7NWSKuaFviKdrUKIgcIru9g0APVhj9YSZvIZNEMnluxW5WRQyP4Ege4ea2D25KhARzqn1pjHyqeMxaRgTaajodQg432o5GlmIA81SmlQDclO//it+uZ48EZi49OJl13EX8So0Z0i/U4JhMusLpQc4e7zgyr+QGRpS4JJPvqKBXU5Y/t x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?uFZ1HFJVjAvHzOY4EMX/FdCA6RqrS2NO6oJsyKVtHiPucqo6mwc9NeE6NewU?= =?us-ascii?Q?EruricSI50xDl0ALhH0VsSRij2ml/kRNHMTSWU1NSsQeYNlC+lPyIsMkoW3/?= =?us-ascii?Q?FT0jJryUsvCO2yJqs+YARik7QfAMoVc8canbnQ2tbjMJeOx8DbztoXdeE+2j?= =?us-ascii?Q?M7o7+pB2YygrOzQTlMAcVH+/8LyvYXN/qA9XBrjPqv4xuXXNzM1ddieTTeDP?= =?us-ascii?Q?fAU9wPggznzeh9zf+DxcBslkb9WEfqHYG0AVRYchymwzHWWCYLRyz5/2XJs3?= =?us-ascii?Q?8LNLLIqLRD6D9biWPSt/HPt/u2F2ph4MBu90KhZeLCo2gQqk/nML6FNN6p3s?= =?us-ascii?Q?76Z870dU0CgKDZNLjT05I3FzVeDsdPA1w3xWQNZVSfKBSKfgFuKZ60X70u+1?= =?us-ascii?Q?qQZZxBufGKqzpSNancbFqyrwl0iUeinDXLn3KqZtGpI5P8AtaXpBh4opRgW3?= =?us-ascii?Q?fIkNT5nTtM2XPWV/FsTf03xUSio3msjNwJV4SVGEBzRCTJ7XIMDg0gMpHH7l?= =?us-ascii?Q?t0A6MJ3LNAi6lxFg42rrZMLjpcI0EgmZG72VKZi22NsQdOHhMslVB+VGZpu+?= =?us-ascii?Q?aWkdoISs4L+HP4wMJ6ItCXcnInRroFKt6onNg4PH1gFNtjHaiL2coJrXwBCQ?= =?us-ascii?Q?99MwGSc3NDMxfE7MMkXP0wCLF9QfPDGCsWl/llnkXX+XTUO3WJdT+QOKQzIy?= =?us-ascii?Q?qubW/iij61ybw9DKA1pq217trlharU80rp90tIVA52J7AVvEUXd4j3nU1GpF?= =?us-ascii?Q?nnF2I41RjrJMQLqCQzU26cjG4CRc9EypyU8KWbYE7X/pGO4Kd9zoYQzUkN1x?= =?us-ascii?Q?eqLNQrN40BN5v5o5/WZG3OYYkLXeukIyEvoTJ+QCK/6xt0aPBbL7Xg5ZUmjJ?= =?us-ascii?Q?Q1JuJN2BceJ4shCucXteZ7Rg1+eODG+vfekl9CN2BRw3hLZHq2NpXQO9DMX/?= =?us-ascii?Q?rhjcqwmJlWpaZIHsK/9dMxXhnfTDclMi8aA06wLF9WJsopri0AHe3WqcyYdo?= =?us-ascii?Q?eaLTDWpDfOkyPm5jFqOM9uxuZBSkQ0T2ycf0guYPjLm5BYtfK8owcmcQgR+r?= =?us-ascii?Q?nkDsXyod7WE4H+MZFCag/g3i4j8C+keFdRX2GhJS/IuZnY8PQRJZq31gQVKJ?= =?us-ascii?Q?VhD0L6S4wdT3H8d05gUu7YAJduuSJ2DAAh8Q+B8h0pmeq8Sy3HQhcMwlMFhj?= =?us-ascii?Q?vCGwllhN5j6FIt8jfxbeK6Oci24e51QY+RrLqCgnGpZHcy5IabeH8jJvOlCY?= =?us-ascii?Q?vw9QazK1ZcsnZmjY4I292RkuYolkegBNtgQQqxUNFNqA46kZE+znz5JgDWhQ?= =?us-ascii?Q?uVhgJwfJvI2sGCElFbWww/QqcDSod/3t25kcO5+yiwH8xK46rBXpIzpr/K5/?= =?us-ascii?Q?yp4TwfR5elDqvuP4QlxWGqsWQl5w+L0qeJHfzu+sEFebPgi1uHvNJX05MRMX?= =?us-ascii?Q?CBh5snrT3SNWRmnhRXKYSCu19EVpsH13mIsu5ZQcWzFJW/HwSTQJ1hk48z/+?= =?us-ascii?Q?lJM6wR+KOGgDeqxvs2Iy10Fil4C4HUvh0nCl1x7glb8bNh72xkiHw/kWvWUe?= =?us-ascii?Q?nsazZuV3RigXUBh9CmY=3D?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: DM6PR11MB4025.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5261a30f-f67f-4aa9-6491-08dbcdead26b X-MS-Exchange-CrossTenant-originalarrivaltime: 16 Oct 2023 01:54:23.8830 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: eBLq6FMRizrwYP4IcRKFjjWLGuCUtZYjXNZ0ZBdpPZA80ppcM/Vp04pQKtqp6jtD1lyN6R2QhScbDkTmjWu/Xw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR11MB8269 X-OriginatorOrg: intel.com 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,hao.a.wu@intel.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: 7EnidHuVAgxEjnlNjvfNla2Vx7686176AA= Content-Language: en-US Content-Type: multipart/alternative; boundary="_000_DM6PR11MB40257410F2346D2FF692F4D0CAD7ADM6PR11MB4025namp_" X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=KpNHeT32; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=intel.com (policy=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 --_000_DM6PR11MB40257410F2346D2FF692F4D0CAD7ADM6PR11MB4025namp_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Please grant me some time to review this patch. Really sorry that I am not able to provide an estimated time for the review= . Best Regards, Hao Wu From: Ashish Singhal Sent: Friday, October 13, 2023 10:13 AM To: Rick Tseng ; devel@edk2.groups.io; Wu, Hao A ; Ni, Ray ; Wang, Jian J ; Gao, Liming Cc: Jeff Brasen Subject: Re: [PATCH] MdeModulePkg/UsbBus: Get device/config descriptor afte= r port reset Hello Hao/Ray/Jian/Gao, Any feedback on this patch? Thanks Ashish ________________________________ From: Rick Tseng > Sent: Sunday, September 24, 2023 7:54 PM To: devel@edk2.groups.io > Cc: hao.a.wu@intel.com >; ray.ni@intel.com >; jian.j.wang@intel.com >; gaolimi= ng@byosoft.com.cn >; Ashish Singhal >; Jeff Brasen >; Rick Tseng > Subject: [PATCH] MdeModulePkg/UsbBus: Get device/config descriptor after po= rt reset 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; OldTpl =3D gBS->RaiseTPL (USB_BUS_TPL); @@ -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); 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 ); +/** + 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 -- 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 (#109619): https://edk2.groups.io/g/devel/message/109619 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] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- --_000_DM6PR11MB40257410F2346D2FF692F4D0CAD7ADM6PR11MB4025namp_ Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable

Please grant me some time to review this patch.=

Really sorry that I am not able to provide an estima= ted time for the review.

 

Best Regards,

Hao Wu

 

From: Ashish Singhal <ashishsingha@nvidia.= com>
Sent: Friday, October 13, 2023 10:13 AM
To: Rick Tseng <rtseng@nvidia.com>; devel@edk2.groups.io; Wu, = Hao A <hao.a.wu@intel.com>; Ni, Ray <ray.ni@intel.com>; Wang, J= ian J <jian.j.wang@intel.com>; Gao, Liming <gaoliming@byosoft.com.= cn>
Cc: Jeff Brasen <jbrasen@nvidia.com>
Subject: Re: [PATCH] MdeModulePkg/UsbBus: Get device/config descript= or after port reset

 

Hello Hao/Ray/Jian/Gao,

 

Any feedback on this patch?

 

Thanks

Ashish


From: Rick Tseng <rtseng@nvidia.com>
Sent: Sunday, September 24, 2023 7:54 PM
To: devel@edk2.groups.io= <devel@edk2.groups.io> Cc: hao.a.wu@intel.com <= ;hao.a.wu@intel.com>; ray.ni@intel.com <ray.ni@intel.com>; jian.j.wang@intel.com <jian.j.wang@intel.com>; gaoliming@byosoft.com.cn &l= t;gaoliming@byosoft.com.cn&= gt;; Ashish Singhal <ashishsi= ngha@nvidia.com>; Jeff Brasen <jbrasen@nvidia.com>; Rick Tseng <rtseng@nvidia.com&= gt;
Subject: [PATCH] MdeModulePkg/UsbBus: Get device/config descriptor a= fter port reset

 

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 Endpo= int"
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 endpoint= s.

Signed-off-by: Rick Tseng <rtseng@n= vidia.com>
---
 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          DevAddr= ess;
+  USB_INTERFACE    *UsbIf;
+  USB_INTERFACE    *HubIf;
+  USB_DEVICE       *Dev;
+  EFI_TPL          OldTp= l;
+  EFI_STATUS       Status;
+  UINT8          &n= bsp; DevAddress;
+  USB_DEVICE_DESC  DevDesc;
+  UINT8          &n= bsp; NumConfig;
+  VOID          &nb= sp;  *Buf;
+  UINT8          &n= bsp; Index;
 
   OldTpl =3D gBS->RaiseTPL (USB_BUS_TPL);
 
@@ -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 d= evice enumeration.
+    // Need to get the device descriptor, configuration des= criptor 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.NumConfiguration= s;
+    if (NumConfig =3D=3D 0) {
+      DEBUG ((
+        DEBUG_ERROR,
+        "UsbIoPortReset: no config= uration 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,
+          "UsbIoPortRese= t: no configuration descriptor for index %d - %r\n",
+          Index,
+          Status
+          ));
+        goto ON_EXIT;
+      }
+
+      Buf =3D AllocateZeroPool (Dev->DevDesc-&= gt;Configs[Index]->Desc.TotalLength);
+      if (Buf =3D=3D NULL) {
+        DEBUG ((
+          DEBUG_ERROR,
+          "UsbIoPortRese= t: allocation memory fail for configuration desc - %r\n",
+          Status
+          ));
+        goto ON_EXIT;
+      }
+
+      Status =3D UsbCtrlGetDesc (Dev, USB_DESC_TY= PE_CONFIG, Index, 0, Buf, Dev->DevDesc->Configs[Index]->Desc.Total= Length);
+      FreePool (Buf);
+
+      if (EFI_ERROR (Status)) {
+        DEBUG ((
+          DEBUG_ERROR,
+          "UsbIoPortRese= t: failed to get config desc for device %d - %r\n",
+          Dev->Address, +          Status
+          ));
+        goto ON_EXIT;
+      }
+    }
+
     Status =3D UsbSetConfig (Dev, Dev->ActiveConfig= ->Desc.ConfigurationValue);
 
     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
   );
 
+/**
+  Get the standard descriptors.
+
+  @param  UsbDev        =         The USB device to read descripto= r from.
+  @param  DescType       &nbs= p;      The type of descriptor to read.
+  @param  DescIndex       &nb= sp;     The index of descriptor to read.
+  @param  LangId        =         Language ID, only used to get st= ring, otherwise set
+            &n= bsp;            = ;       it to 0.
+  @param  Buf        &nb= sp;          The buffer to hol= d 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:

=20 You receive all messages sent to this group. =20 =20

View/Reply Online (#109619) | =20 | Mute= This Topic | New Topic
Your Subscriptio= n | Contact Group Owner | Unsubscribe [rebecca@openfw.io]

_._,_._,_
--_000_DM6PR11MB40257410F2346D2FF692F4D0CAD7ADM6PR11MB4025namp_--