From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0b-002e3701.pphosted.com (mx0b-002e3701.pphosted.com [148.163.143.35]) by mx.groups.io with SMTP id smtpd.web10.4321.1600889795660781776 for ; Wed, 23 Sep 2020 12:36:35 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@hpe.com header.s=pps0720 header.b=Kbbf9mDX; spf=pass (domain: hpe.com, ip: 148.163.143.35, mailfrom: prvs=0535649adb=patrick.henz@hpe.com) Received: from pps.filterd (m0134424.ppops.net [127.0.0.1]) by mx0b-002e3701.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 08NJaZ8f020874; Wed, 23 Sep 2020 19:36:35 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hpe.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : content-transfer-encoding : mime-version; s=pps0720; bh=lkKjqQtbrJxmfMI48QX3D7x8M16PlM628i7l66c2+Tg=; b=Kbbf9mDXjLY8OMnQCz4o5N4NegObsLSEcSesNH9IF2A8/Uv6k4E4luszP/tmjShKdddj y0kWPYgMNPP7XS0R2zebOAWYSUvRGEICns73VveZOskFppKhT2brJIGeiBNVBajawsi8 gxm8F01nMGprkvOcH/q6f6sKMcuWMj+Eu80dKMftMKByNAl+do3YqbjiKuz1eIU73CaS I0FiIeRZJkjOgVtje97Zf+h4kK+fANlbYibgl3Y3tLiN/ZzYqnHniM1611n9WOHD2CuF ItJ+CkCzr5P5eln9tbapSPdRvvS3J2vJH0x1DqS/eLfU5XACDpCyYTNJ2FLtvSQOEvx2 DA== Received: from g4t3426.houston.hpe.com (g4t3426.houston.hpe.com [15.241.140.75]) by mx0b-002e3701.pphosted.com with ESMTP id 33r56mn28t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 23 Sep 2020 19:36:34 +0000 Received: from G9W8455.americas.hpqcorp.net (g9w8455.houston.hp.com [16.216.161.94]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by g4t3426.houston.hpe.com (Postfix) with ESMTPS id 092AE67; Wed, 23 Sep 2020 19:36:25 +0000 (UTC) Received: from G2W6309.americas.hpqcorp.net (2002:10c5:4033::10c5:4033) by G9W8455.americas.hpqcorp.net (2002:10d8:a15e::10d8:a15e) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 23 Sep 2020 19:36:25 +0000 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (15.241.52.12) by G2W6309.americas.hpqcorp.net (16.197.64.51) with Microsoft SMTP Server (TLS) id 15.0.1497.2 via Frontend Transport; Wed, 23 Sep 2020 19:36:24 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PqgCANSnJHfi/mTS2J5G8YUOgfl4qFMYZYFLLKZJYuTYIe+Ar3HFDlJZozKQCrX2UgU7gStpNnnW9BcfzKHF0b0moHmoyF0aBh1vItmEL5/seturOMl3fEI5Y7ndQ3CPwIr8Or3f+RG4FNX0Dw5GM0GbhypTwZwr6zJsU3ov31iz6UsZr/tiKa7VrD5JtUgj6IdGoxIf+GtjJOg4ilKq7pinlRI1RbW3kubbxn+YHH5o+jus9o/yZllJ+imVXLMbKtKESLzcQnOhquhRFaKHCXmE3lxa/q+++P4FNQXvJDcYM+1RTG4eBV/dkiOH5AUxCFznKqMgwtbUXzSP0E/jQg== 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=lkKjqQtbrJxmfMI48QX3D7x8M16PlM628i7l66c2+Tg=; b=QbDR3X7MqFb3SFl2uoM2xNWykxbYKBk2b+zHyZ4jsCN4IQU6oR67+DUejEab92ZZmd9yW34jGDToXmqNaKhPFi/UCyZQsd5j5dtccWJAJ3eHWnf98PwV87l4v4R0ICh0zc/tDK5oIEayL2TE+GLxe+TbYE3fCGULAx/0oxv3Z90fTe3B9AlXAbYVLMMKh/aaQvpPJV+aErjol0LaYj7LbyyrWAYGWU5H/fCD1flKisF47Ma18gEF/dEYnojRCZA3YhAqSLqL0OaIMmw4M4PIUfdIS7np33M07PmRY1P2Qgz6qdOw0pPem7vJzJYd+r4n9qpaRtG211AQA8wCWIzB3g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=hpe.com; dmarc=pass action=none header.from=hpe.com; dkim=pass header.d=hpe.com; arc=none Authentication-Results: edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=none action=none header.from=hpe.com; Received: from TU4PR8401MB0478.NAMPRD84.PROD.OUTLOOK.COM (2a01:111:e400:7709::19) by TU4PR8401MB0399.NAMPRD84.PROD.OUTLOOK.COM (2a01:111:e400:770c::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3391.14; Wed, 23 Sep 2020 19:36:23 +0000 Received: from TU4PR8401MB0478.NAMPRD84.PROD.OUTLOOK.COM ([fe80::4968:3a88:e4a6:5cea]) by TU4PR8401MB0478.NAMPRD84.PROD.OUTLOOK.COM ([fe80::4968:3a88:e4a6:5cea%8]) with mapi id 15.20.3412.020; Wed, 23 Sep 2020 19:36:23 +0000 From: "Henz, Patrick" To: CC: Patrick Henz , Jian J Wang , Hao A Wu , Ray Ni Subject: [PATCH v3 1/1] MdeModulePkg/XhciDxe: Fix Broken Timeouts Date: Wed, 23 Sep 2020 14:36:03 -0500 Message-ID: <82fc5045fc091b111edeb45c58b64e6e13599b47.1600889280.git.patrick.henz@hpe.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: References: X-Originating-IP: [76.17.188.158] X-ClientProxiedBy: SN4PR0501CA0110.namprd05.prod.outlook.com (2603:10b6:803:42::27) To TU4PR8401MB0478.NAMPRD84.PROD.OUTLOOK.COM (2a01:111:e400:7709::19) X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (76.17.188.158) by SN4PR0501CA0110.namprd05.prod.outlook.com (2603:10b6:803:42::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3412.16 via Frontend Transport; Wed, 23 Sep 2020 19:36:22 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: b201b69e-c224-403d-662a-08d85ff7f429 X-MS-TrafficTypeDiagnostic: TU4PR8401MB0399: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: UpKG3gQ/TJWr6+qmLcsr3A2iowmtim6NwYZYTFfjAixdNDPqx6U4TbTOgX7GO4jcpSBSby7wL0x3ND5NjOLvkoxtdudZ2cjEpbVr7cSHtG2ipBRSoeaPkwNMyAbK6s5l6MaYzzvV9GlnSNxAvunDlQFM71SUAYYXu1mw3pgSyqP9LgqCCZ+ekPHZTuzcdVUSySDlSYiI1lpiDJTdUUoU7XwVrEAPOVMN9ebDARalapGMEBl9BvrwCOmquDXtl/4KgQ+ZntBOuUcBrXX1sEvfEKEkOsjhsV9VzsMBLtJgp6YpYLW+qR36dqSYEFoVhXDsrh872SpYj3DaKOe8Q3i+h/HYV4m9tkCcXtfdi9G9To0jBc19h0rQh+aP/JlYyqb72TuJtqdMOSW4aca0kvM+Cg2BeGYXwoENtr1Zbge5ZcgeWpkepXKCLJvHrjUpZ2P8xO+/G8eevC+icUvNRPRxsw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:TU4PR8401MB0478.NAMPRD84.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(376002)(346002)(39860400002)(396003)(366004)(136003)(8936002)(6666004)(9686003)(66946007)(66556008)(16526019)(66476007)(26005)(54906003)(6512007)(4326008)(186003)(36756003)(69590400008)(6506007)(316002)(86362001)(956004)(2616005)(478600001)(83380400001)(8676002)(52116002)(5660300002)(2906002)(6486002)(6916009);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData: 6cFkZFQUD5oy/nBXm0y0XpnEv7kfpF2wmQcoYLOMtXqP/MNPINwxd0XRxVWvVYwXfXGEAspDeHAWQkAM4ImWS6sGkQREOUGxPoCe6M95Fcy5KxCBvLKFhHW6YiME8nTf2akR74o+GXUKr/BCdiR7cr8Q2GjhTUolCPBudoMoDacEpUC4ScQwZo78sJQkkY4/Y9u7yR5tlyvJPeNa0jFugP9mRTGxp1vcr/HKRwPt/hBpOzcB0VYWc1fe8ncR47UrxUjpLrDSetaX1XR7/IhC4BUGjomHk6g7z6lLwU3i/NhQ724SfoiNg1rtky6IVb1pIoI/x1pMnl59+t7RIzaBOt+lliTuZSw8LufRPYHc6RbYgytoYIV6jXaGTXqcWmDlQJMhYSspeOEs7PaSlo5V/o/d2jTmCvCEygZcMiHzOskea3aTAEZ95sdQ5OX+G7YTqgcRDJO2l0E0kH1uZQ7YBLn1k0K1OGaoJxWFc+6mmwbIlPqtY2Cni30MKw/iG9OiJfrZis5w8AyS2H1enzSG/qq5UNYAjkdZGEPmNOYDOMsbpRYysgTZ0h5SrKAhuP1TNjMu5KdNDMfLT0BIaSEZSmhSAi7e3XTzDtic8MxlhqqahQ4zD/XnAD0ON8pW+c+/EWCWH2otagdyi4ZGAJEntg== X-MS-Exchange-CrossTenant-Network-Message-Id: b201b69e-c224-403d-662a-08d85ff7f429 X-MS-Exchange-CrossTenant-AuthSource: TU4PR8401MB0478.NAMPRD84.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Sep 2020 19:36:23.2968 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 105b2061-b669-4b31-92ac-24d304d195dc X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: vCdOBAYgEu/8f+WgaI+oV+NiBAsLCAUbuNJlnGDAerZQfesoi8jQ/yom/QR9CQWKY9PUEwrv6SJ1Xpbkvp+GgQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: TU4PR8401MB0399 X-OriginatorOrg: hpe.com X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-HPE-SCL: -1 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.235,18.0.687 definitions=2020-09-23_16:2020-09-23,2020-09-23 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 mlxlogscore=999 adultscore=0 impostorscore=0 mlxscore=0 phishscore=0 malwarescore=0 bulkscore=0 clxscore=1015 spamscore=0 priorityscore=1501 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2009230145 Content-Type: text/plain Content-Transfer-Encoding: 8bit From: Patrick Henz REF:https://bugzilla.tianocore.org/show_bug.cgi?id=2948 Timeouts in the XhciDxe driver are taking longer than expected due to the timeout loops not accounting for code execution time. As en example, 5 second timeouts have been observed to take around 36 seconds to complete. Use SetTimer and Create/CheckEvent from Boot Services to determine when timeout occurred. Cc: Jian J Wang Cc: Hao A Wu Cc: Ray Ni Signed-off-by: Patrick Henz --- MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.c | 59 +++++++++++++++++----- MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c | 63 ++++++++++++++++++------ 2 files changed, 94 insertions(+), 28 deletions(-) diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.c b/MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.c index 42b773ab31be..2bab09415b28 100644 --- a/MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.c +++ b/MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.c @@ -423,14 +423,15 @@ XhcClearOpRegBit ( Wait the operation register's bit as specified by Bit to become set (or clear). - @param Xhc The XHCI Instance. - @param Offset The offset of the operation register. - @param Bit The bit of the register to wait for. - @param WaitToSet Wait the bit to set or clear. - @param Timeout The time to wait before abort (in millisecond, ms). + @param Xhc The XHCI Instance. + @param Offset The offset of the operation register. + @param Bit The bit of the register to wait for. + @param WaitToSet Wait the bit to set or clear. + @param Timeout The time to wait before abort (in millisecond, ms). - @retval EFI_SUCCESS The bit successfully changed by host controller. - @retval EFI_TIMEOUT The time out occurred. + @retval EFI_SUCCESS The bit successfully changed by host controller. + @retval EFI_TIMEOUT The time out occurred. + @retval EFI_OUT_OF_RESOURCES Memory for the timer event could not be allocated. **/ EFI_STATUS @@ -442,20 +443,52 @@ XhcWaitOpRegBit ( IN UINT32 Timeout ) { - UINT32 Index; - UINT64 Loop; + EFI_STATUS Status; + EFI_EVENT TimeoutEvent; - Loop = Timeout * XHC_1_MILLISECOND; + TimeoutEvent = NULL; - for (Index = 0; Index < Loop; Index++) { + if (Timeout == 0) { + return EFI_TIMEOUT; + } + + Status = gBS->CreateEvent ( + EVT_TIMER, + TPL_CALLBACK, + NULL, + NULL, + &TimeoutEvent + ); + + if (EFI_ERROR(Status)) { + goto DONE; + } + + Status = gBS->SetTimer (TimeoutEvent, + TimerRelative, + EFI_TIMER_PERIOD_MILLISECONDS(Timeout)); + + if (EFI_ERROR(Status)) { + goto DONE; + } + + do { if (XHC_REG_BIT_IS_SET (Xhc, Offset, Bit) == WaitToSet) { - return EFI_SUCCESS; + Status = EFI_SUCCESS; + goto DONE; } gBS->Stall (XHC_1_MICROSECOND); + } while (EFI_ERROR(gBS->CheckEvent (TimeoutEvent))); + + Status = EFI_TIMEOUT; + +DONE: + if (TimeoutEvent != NULL) { + gBS->CloseEvent (TimeoutEvent); } - return EFI_TIMEOUT; + return Status; } /** diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c b/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c index ab8957c546ee..9cb115363c8b 100644 --- a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c +++ b/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c @@ -1254,14 +1254,15 @@ XhcCheckUrbResult ( /** Execute the transfer by polling the URB. This is a synchronous operation. - @param Xhc The XHCI Instance. - @param CmdTransfer The executed URB is for cmd transfer or not. - @param Urb The URB to execute. - @param Timeout The time to wait before abort, in millisecond. + @param Xhc The XHCI Instance. + @param CmdTransfer The executed URB is for cmd transfer or not. + @param Urb The URB to execute. + @param Timeout The time to wait before abort, in millisecond. - @return EFI_DEVICE_ERROR The transfer failed due to transfer error. - @return EFI_TIMEOUT The transfer failed due to time out. - @return EFI_SUCCESS The transfer finished OK. + @return EFI_DEVICE_ERROR The transfer failed due to transfer error. + @return EFI_TIMEOUT The transfer failed due to time out. + @return EFI_SUCCESS The transfer finished OK. + @retval EFI_OUT_OF_RESOURCES Memory for the timer event could not be allocated. **/ EFI_STATUS @@ -1273,11 +1274,16 @@ XhcExecTransfer ( ) { EFI_STATUS Status; - UINTN Index; - UINT64 Loop; UINT8 SlotId; UINT8 Dci; BOOLEAN Finished; + EFI_EVENT TimeoutEvent; + BOOLEAN IndefiniteTimeout; + + Status = EFI_SUCCESS; + Finished = FALSE; + TimeoutEvent = NULL; + IndefiniteTimeout = FALSE; if (CmdTransfer) { SlotId = 0; @@ -1291,29 +1297,56 @@ XhcExecTransfer ( ASSERT (Dci < 32); } - Status = EFI_SUCCESS; - Loop = Timeout * XHC_1_MILLISECOND; if (Timeout == 0) { - Loop = 0xFFFFFFFF; + IndefiniteTimeout = TRUE; + goto RINGDOORBELL; } + Status = gBS->CreateEvent ( + EVT_TIMER, + TPL_CALLBACK, + NULL, + NULL, + &TimeoutEvent + ); + + if (EFI_ERROR (Status)) { + goto DONE; + } + + Status = gBS->SetTimer (TimeoutEvent, + TimerRelative, + EFI_TIMER_PERIOD_MILLISECONDS(Timeout)); + + if (EFI_ERROR (Status)) { + goto DONE; + } + +RINGDOORBELL: XhcRingDoorBell (Xhc, SlotId, Dci); - for (Index = 0; Index < Loop; Index++) { + do { Finished = XhcCheckUrbResult (Xhc, Urb); if (Finished) { break; } gBS->Stall (XHC_1_MICROSECOND); - } + } while (IndefiniteTimeout || EFI_ERROR(gBS->CheckEvent (TimeoutEvent))); - if (Index == Loop) { +DONE: + if (EFI_ERROR(Status)) { + Urb->Result = EFI_USB_ERR_NOTEXECUTE; + } else if (!Finished) { Urb->Result = EFI_USB_ERR_TIMEOUT; Status = EFI_TIMEOUT; } else if (Urb->Result != EFI_USB_NOERROR) { Status = EFI_DEVICE_ERROR; } + if (TimeoutEvent != NULL) { + gBS->CloseEvent (TimeoutEvent); + } + return Status; } -- 2.28.0