From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by mx.groups.io with SMTP id smtpd.web09.11338.1603163703475864997 for ; Mon, 19 Oct 2020 20:15:03 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@intel.onmicrosoft.com header.s=selector2-intel-onmicrosoft-com header.b=R26MOXi8; spf=pass (domain: intel.com, ip: 192.55.52.43, mailfrom: heng.luo@intel.com) IronPort-SDR: yTwHudAxKShA3i6MvvSfukdHIkPOycoUzgEnJ3scMoFXI7zZX6ARvbbrS1SBHeyrfwzlPhYngx jpFhsKns4AiQ== X-IronPort-AV: E=McAfee;i="6000,8403,9779"; a="251839185" X-IronPort-AV: E=Sophos;i="5.77,396,1596524400"; d="scan'208";a="251839185" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Oct 2020 20:15:02 -0700 IronPort-SDR: Xw7kQQ9R9WE4XYFQOIJwp8vvkFwikX3g16062hkr1Hijro6y0+Xl7EF3hWS3mvMvaCxsa7HSob eWu+v3RfYLNg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,396,1596524400"; d="scan'208";a="465766464" Received: from orsmsx604.amr.corp.intel.com ([10.22.229.17]) by orsmga004.jf.intel.com with ESMTP; 19 Oct 2020 20:15:02 -0700 Received: from orsmsx609.amr.corp.intel.com (10.22.229.22) by ORSMSX604.amr.corp.intel.com (10.22.229.17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Mon, 19 Oct 2020 20:15:01 -0700 Received: from orsmsx610.amr.corp.intel.com (10.22.229.23) by ORSMSX609.amr.corp.intel.com (10.22.229.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Mon, 19 Oct 2020 20:15:01 -0700 Received: from ORSEDG602.ED.cps.intel.com (10.7.248.7) 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.1713.5 via Frontend Transport; Mon, 19 Oct 2020 20:15:01 -0700 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (104.47.66.47) by edgegateway.intel.com (134.134.137.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.1713.5; Mon, 19 Oct 2020 20:15:01 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Cr3vd8UT1flzexCaBXuJV0UenQM8wLdpnKu/1dMUee1upPnsYGXygwy/LX19AxZ0lH019hMwIOKFc9KMdRl6De26EjDaXGlu7V2iDWWu0/dBNCcTWaf1RwgPaYJ1a46WELfa7okXpPkP5gjOePfvop2wydy2ugS8IiLHnd7qNuEla0swzUeIU4+K48i2koQ95WFHa8oogEYIOIY9POgfU1ygWwYx46f81hppjbNk1HZgFFfh77gIWoIiSCzl5VnApS9H9pfSlfkrRW6DQScD2AwwuwI8GcGY8W1txue+mj6U62HT3PUjA8D72oRfaxTQeLNtZDefbK30eNUnysifNg== 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-SenderADCheck; bh=sLBzvaMfsBUG+I2SUKJxoehM+D/rO+vWll1+Ga4GJhs=; b=lZ4lbcyjYY5UCYyI+eH9+7eqH/xUhkuCqj3Sposd9wBZXNwWZm7gK4mPrIXF8eXwyvptYEs1Gz0fgwEdG6TspBSZaYmRST145iGi6KsMUymihz3NqkBy+qnXJ+1rXxQuzIU4Am2nD5kRFkouGsxS8shJfN3wvOlUlqYioJvX0LMquW8+umMxJX8FklcFtTaBbYY/quZZhRmbauYD7lGz1kmgtb18X6/w9EoyllEAWEsknZDBrsPcAQAFHTo+nTJpHxcGK7T85PZXE98ihT34A+ivl8D514PKCRNgLwtdUmOYxgWn1oBIhz23bqxi2TDgVgrcVvqgfFfsC3UxonwHSA== 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.onmicrosoft.com; s=selector2-intel-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=sLBzvaMfsBUG+I2SUKJxoehM+D/rO+vWll1+Ga4GJhs=; b=R26MOXi8ZukPZEqEmIS/Tk4/SjusH8TQHeF2OONlL/QCsySbMO8CzANg0lYOws/MIy3Ra4W38gbvRJddciUcybdh86yBAas/rnfWIxSyimDy0RtmYe2B+fiVC+m7IbZF/rz2h49vLRzmPrDqoYMxobmxKEazPrhYaip7fmpvb7E= Received: from MWHPR11MB1805.namprd11.prod.outlook.com (2603:10b6:300:114::14) by MWHPR11MB0063.namprd11.prod.outlook.com (2603:10b6:301:6c::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3477.20; Tue, 20 Oct 2020 03:15:00 +0000 Received: from MWHPR11MB1805.namprd11.prod.outlook.com ([fe80::bd78:5a79:d875:65e4]) by MWHPR11MB1805.namprd11.prod.outlook.com ([fe80::bd78:5a79:d875:65e4%12]) with mapi id 15.20.3477.028; Tue, 20 Oct 2020 03:15:00 +0000 From: "Heng Luo" To: "Wu, Hao A" , "devel@edk2.groups.io" CC: "Ni, Ray" Subject: Re: [PATCH] XhciDxe: Clean up UsbDevContext if USB slot initialization is failed Thread-Topic: [PATCH] XhciDxe: Clean up UsbDevContext if USB slot initialization is failed Thread-Index: AQHWopWHnBe20E7vzEm142fMV0AReKmZzOzQgARtGyCAAGov0IABNGYw Date: Tue, 20 Oct 2020 03:15:00 +0000 Message-ID: References: <20201015014901.1154-1-heng.luo@intel.com> In-Reply-To: Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-reaction: no-action dlp-version: 11.5.1.3 authentication-results: intel.com; dkim=none (message not signed) header.d=none;intel.com; dmarc=none action=none header.from=intel.com; x-originating-ip: [192.198.147.198] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 1a753027-2040-4086-22f7-08d874a65489 x-ms-traffictypediagnostic: MWHPR11MB0063: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:10000; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: U82HRwk5zeFF8f433nb4vo2pyP+gn3uNjJMVWIN0RHPER+bhMhE1egfPx56FCDGHO/G1eIoFdYVgNG9pHbew2FtCHoEbpmDTvNmXatF0IZmC87/q4hPTYIbE4tiyLO7PudtG6uxoc6wtHi2FSH/XUQFqULPwhVpJx77qM6So6tKNpxt7igncBD399c4xYMQPEGSl8cvXw0U+gTSfMysHLY1oa0Sp5stHXii5Ll45LZvgs5gfedLZadQQa9H7EgQ8MK0EGuo4emd+LPRuEpF3vJmq8+YftI+NUPUx0dD11M/bsOxe7YfCOTGGxWIFT55DSVM3g7rg7AiIX4IYwN+NzTCnrbfLTyN8rElphfjKTTcNkfsRCIGRLCqXIZUG8ANG9pVm+pKpwqnAQlS76ZZ85g== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MWHPR11MB1805.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(376002)(346002)(136003)(396003)(366004)(39860400002)(2906002)(8936002)(66476007)(110136005)(83380400001)(86362001)(66556008)(66446008)(186003)(64756008)(76116006)(966005)(66946007)(5660300002)(19627235002)(9686003)(4326008)(107886003)(8676002)(71200400001)(55016002)(52536014)(33656002)(6506007)(26005)(45080400002)(478600001)(53546011)(316002)(7696005);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata: VbbM9vP5Q7oQp/c51KC556GufKaHmvJilo41VxY23g+bteMx8LOflCgc0/YD0BU1O98xtyjrMdExhFbSvrRJSzkIvHCWvrtLnDR9QYLSmPfx6YGHvkiVyK/MkVskIkVwCoARTNyUemNbP02O4nQRtaMtJJ8Q1rb4gmqSvnq5gCj78if/V8zA8l0XtBwXcH8Ovdu5hmSF4MpCubQzf8iCHvfKA0D0IAwGh/iVHCpkG8DnpHGVJ/JQOy0Y7u9DaoSjT8JKygSIXtvUWEGj/gaBxEY8Yac2W2cY5RICGs49MRRptwHQcnSNEIzDtuM/+kWr91wflkue9NfS4VWGIWBDjD8zdngoz0Lh8iLj3zgNCCNyXHq0uON3NWyxHjrTBf8L+JoEQSCD7Dsc//pP9YgfjjsE4ipgWq6Jevg4uetr790QsDd2zXliPFIJ/uFaqXEVl/GVZ2Udp1aUAN6lIEJyGfoiII3JVJ14cRBjunauabAbD8JGOWjduKJz31lCA8stbE6Hc8m2cZkJcHfJKF3o4TweyoBpdJZYt7uMw4a7Umjpm3ouENr/Uwr9JYuFy2cNkFnIVOSgbcpQY4SSVl1sFswx05wRi6T8c1suy8IXHKEwgluZdfTvbnp5wDquvq+wtnu7JWTs2LxdaLFk6/ekEQ== MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MWHPR11MB1805.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1a753027-2040-4086-22f7-08d874a65489 X-MS-Exchange-CrossTenant-originalarrivaltime: 20 Oct 2020 03:15:00.3592 (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: kH5rom/oxmgrXOXybDwH9I5BR1GMrQCPOAo9QFiyZBxuVb5PKuP6IbwRf9/KTrHzbwREvw3YQWlT0+uuW95Jog== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR11MB0063 Return-Path: heng.luo@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Thanks Hao, Sorry I don't know how to test USB on PEI phase. I will send patch V2 following your comments. Thanks, Heng > -----Original Message----- > From: Wu, Hao A > Sent: Tuesday, October 20, 2020 10:22 AM > To: Luo, Heng ; devel@edk2.groups.io > Cc: Ni, Ray > Subject: RE: [PATCH] XhciDxe: Clean up UsbDevContext if USB slot > initialization is failed >=20 > Thanks Heng, >=20 > Inline comments below: >=20 > > -----Original Message----- > > From: Luo, Heng > > Sent: Monday, October 19, 2020 11:04 AM > > To: Wu, Hao A ; devel@edk2.groups.io > > Cc: Ni, Ray > > Subject: RE: [PATCH] XhciDxe: Clean up UsbDevContext if USB slot > > initialization is failed > > > > Hi Hao, > > Thank you for your review. > > I think the slot Id is allocated by HW because the pointer EvtTrb > > point to > > EvtRing->EventRingDequeue, EventRingDequeue is filled by XHCI > > controller(correct me if I am wrong): > > > > XhcDequeue =3D (UINT64)(LShiftU64((UINT64)High, 32) | Low); > > > > PhyAddr =3D UsbHcGetPciAddrForHostAddr (Xhc->MemPool, Xhc- > > >EventRing.EventRingDequeue, sizeof (TRB_TEMPLATE)); > > > > if ((XhcDequeue & (~0x0F)) !=3D (PhyAddr & (~0x0F))) { > > // > > // Some 3rd party XHCI external cards don't support single > > 64-bytes width register access, > > // So divide it to two 32-bytes width register access. > > // > > XhcWriteRuntimeReg (Xhc, XHC_ERDP_OFFSET, XHC_LOW_32BIT > (PhyAddr) > > | BIT3); > > XhcWriteRuntimeReg (Xhc, XHC_ERDP_OFFSET + 4, XHC_HIGH_32BIT > > (PhyAddr)); > > } > > > > So it should be better to use XhcDisableSlotCmd to disable slot but > > not directly clean up UsbDevContext, I will submit new patch if you agr= ee. >=20 >=20 > I agree with the above proposal, please help to send a V2 patch. > For the V2 patch, could you help to rename the title to: > MdeModulePkg/XhciDxe: Error handle for USB slot initialization failure Th= e > package name is needed for title for easy reference. >=20 > If you are able to test the PEI Xhci stack, could you help to check if a = similar > issue exists under: MdeModulePkg\Bus\Pci\XhciPei? > If not, then only changing the XhciDxe will be fine. >=20 > Also, could you help to provide the information on what tests have been > done for the patch? >=20 > Thanks in advance. >=20 >=20 > > + } else { > > + DEBUG ((DEBUG_INFO, " Address %d assigned unsuccessfully\n")); > > + Status =3D XhcDisableSlotCmd (Xhc, SlotId); > > } > > > > Notice that even if a slot have been disable, but it is not reused. I h= ave a > try: > > 1. the USB keyboard is port 0, slot 1: > > UsbEnumeratePort: new device connected at port 0 ... > > Enable Slot Successfully, The Slot ID =3D 0x1 2. remove USB keyboard, > > slot 1 is > > disabled: > > Disable device slot 1! > > ... > > UsbEnumeratePort: device disconnected event on port 0 3. plug in USB > > keyboard in port 0 again, but slot ID is 4 now. > > UsbEnumeratePort: new device connected at port 0 Enable Slot > > Successfully, The Slot ID =3D 0x4 > > > > So I think we can reuse slot ID unless previous slot ID is 255. >=20 >=20 > I think it is the controller's behavior to return which slot ID when a 'E= nable > Slot' command is received. The current proposal of using 'Disable Slot' > to inform the xHCI that a Device Slot is no longer needed looks good to m= e. >=20 > Best Regards, > Hao Wu >=20 >=20 > > > > Thanks, > > Heng > > > > > -----Original Message----- > > > From: Wu, Hao A > > > Sent: Friday, October 16, 2020 3:05 PM > > > To: Luo, Heng ; devel@edk2.groups.io > > > Cc: Ni, Ray > > > Subject: RE: [PATCH] XhciDxe: Clean up UsbDevContext if USB slot > > > initialization is failed > > > > > > > -----Original Message----- > > > > From: Luo, Heng > > > > Sent: Thursday, October 15, 2020 9:49 AM > > > > To: devel@edk2.groups.io > > > > Cc: Ni, Ray ; Wu, Hao A > > > > Subject: [PATCH] XhciDxe: Clean up UsbDevContext if USB slot > > > > initialization is failed > > > > > > > > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3007 > > > > > > > > > Thanks for the patch Heng. > > > > > > After looking into the analysis at > > > https://bugzilla.tianocore.org/show_bug.cgi?id=3D3007#c1: > > > |> Enable Slot Successfully, The Slot ID =3D 0x3 > > > |> Address 3 assigned successfully > > > |> UsbEnumerateNewDev: hub port 15 is reset > > > |> UsbEnumerateNewDev: device is of 3 speed > > > |> UsbEnumerateNewDev: device uses translator (0, 0) > > > |> XhcControlTransfer: SlotId =3D=3D 2 DeviceAddress=3D0 > > > > > > The wrong 'SlotId' is used for the control transfer command, where > > > SlotId 2 is for the device failed to be initialized. > > > Heng, could you help to check whether it is possible for the next > > > device to use SlotId 2 again? Thanks in advance. > > > > > > Best Regards, > > > Hao Wu > > > > > > > > > > > > > > Currently UsbDevContext is not cleaned up if USB slot > > > > initialization is failed, the wrong context data will affect next > > > > USB devices and the USB devices can not be enumerated. > > > > Need to clean up UsbDevContext if USB slot initialization is failed= . > > > > > > > > Cc: Ray Ni > > > > Cc: Hao A Wu > > > > Signed-off-by: Heng Luo > > > > --- > > > > MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c | 9 ++++++++- > > > > 1 file changed, 8 insertions(+), 1 deletion(-) > > > > > > > > diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c > > > > b/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c > > > > index 9cb115363c..1e8430ac34 100644 > > > > --- a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c > > > > +++ b/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c > > > > @@ -2,7 +2,7 @@ > > > > XHCI transfer scheduling routines. -Copyright (c) 2011 - 2018, > > > > Intel Corporation. All rights reserved.
+Copyright (c) 2011 - > > > > 2020, Intel Corporation. All rights reserved.
Copyright (c) > > > > Microsoft Corporation.
SPDX-License-Identifier: > > > > BSD-2-Clause-Patent @@ > > > > -2279,6 > > > > +2279,9 @@ XhcInitializeDeviceSlot ( > > > > DeviceAddress =3D (UINT8) ((DEVICE_CONTEXT *) OutputContext)- > > > > >Slot.DeviceAddress; DEBUG ((EFI_D_INFO, " Address %d assign= ed > > > > successfully\n", DeviceAddress)); Xhc- > > > > >UsbDevContext[SlotId].XhciDevAddr =3D DeviceAddress;+ } else {+ > > DEBUG > > > > ((DEBUG_INFO, " Address %d assigned unsuccessfully, clean up > context > > > > data.\n"));+ ZeroMem (&Xhc->UsbDevContext[SlotId], sizeof > > > > (USB_DEV_CONTEXT)); } return Status;@@ -2489,7 +2492,11 @@ > > > > XhcInitializeDeviceSlot64 ( > > > > DeviceAddress =3D (UINT8) ((DEVICE_CONTEXT_64 *) > > > > OutputContext)- > > > > >Slot.DeviceAddress; DEBUG ((EFI_D_INFO, " Address %d assign= ed > > > > successfully\n", DeviceAddress)); Xhc- > > > > >UsbDevContext[SlotId].XhciDevAddr =3D DeviceAddress;+ } else {+ > > DEBUG > > > > ((DEBUG_INFO, " Address %d assigned unsuccessfully, clean up > context > > > > data.\n"));+ ZeroMem (&Xhc->UsbDevContext[SlotId], sizeof > > > > (USB_DEV_CONTEXT)); }+ return Status; } -- > > > > 2.24.0.windows.2