From nobody Fri Apr 26 00:08:02 2024 Delivered-To: importer@patchew.org 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+85194+1787277+3901457@groups.io; helo=mail02.groups.io; 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+85194+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1640243304; cv=none; d=zohomail.com; s=zohoarc; b=MjqsWR1mPsdWTWqF72nH9LrN28GZiyIFkX8limaEErn0nwCV/zRuM/V/y/Q6vkaoPMDlrVID6xvQLLnYqehrkLYkOmEbeQKZuGKjUS7Bj9HMEm9oAtKfz6ycwC748XbmFC8KwTO5EZ6FyEJcH8Y81bGpPJmQ99vDSbv47vSy1E0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1640243304; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=rZpP92oKQyDCQ7udeF94QkIgEfTIbg3XqTuypBAacBA=; b=CWMbK2KmDa1FVxicuxtdnn/9m7YrtxVA+5o9fJgbf/1N5ssD5Mce2pSI4AxcK2va7EVykW43U2vFXz3Btdu3FgluEMuKeqO/Cw53KQps3BLwlv9RKPQPuF4h/n4IkQQg1vKPn4fuNx7h+f6O9hf6Xm8F680wQnJUX/f5RSqSSJY= ARC-Authentication-Results: i=1; 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+85194+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1640243304478490.14154599041126; Wed, 22 Dec 2021 23:08:24 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id Y4zCYY1788612xMNiXAZUpiU; Wed, 22 Dec 2021 23:08:24 -0800 X-Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by mx.groups.io with SMTP id smtpd.web08.29919.1640243303065241192 for ; Wed, 22 Dec 2021 23:08:23 -0800 X-IronPort-AV: E=McAfee;i="6200,9189,10206"; a="227616826" X-IronPort-AV: E=Sophos;i="5.88,228,1635231600"; d="scan'208";a="227616826" X-Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Dec 2021 23:08:21 -0800 X-IronPort-AV: E=Sophos;i="5.88,228,1635231600"; d="scan'208";a="521984447" X-Received: from kxinfux-mobl2.gar.corp.intel.com ([10.214.170.104]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Dec 2021 23:08:19 -0800 From: "VincentX Ke" To: devel@edk2.groups.io Cc: VincentX Ke , Hao A Wu , Ray Ni , Ian Chiu , Maggie Chu Subject: [edk2-devel] [PATCH v7 1/3] MdeModulePkg: Replace with UFS_UNIT_DESC to fix timeout problem Date: Thu, 23 Dec 2021 15:07:52 +0800 Message-Id: <20211223070754.2190-2-vincentx.ke@intel.com> In-Reply-To: <20211223070754.2190-1-vincentx.ke@intel.com> References: <20211223070754.2190-1-vincentx.ke@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,vincentx.ke@intel.com X-Gm-Message-State: MKkL7sxuE0bEMddtlsN79pZcx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1640243304; bh=0jEL/x5bFuipAFO7nY7i+Ce8DVZO0uBu/6SB+wSsrMI=; h=Cc:Date:From:Reply-To:Subject:To; b=llyFJxJ4O/Oz27TVTVgKEd4FlDNDnrrckKvwvJ+6UzbQe4q/m7G7FnNRPdQwDGaeal1 wXj+lJzhIH6B1U4NiA6tEM72iV502UJcy2v025peIyi/3F1mMK/EEtA5hqlm61K64SRlu FRGivfHCczH9vDxEux/3R93MH/pT01ectdg= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1640243306859100002 Content-Type: text/plain; charset="utf-8" BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3714 Replace with UFS_UNIT_DESC to fix response timeout problem. Cc: Hao A Wu Cc: Ray Ni Cc: Ian Chiu Cc: Maggie Chu Signed-off-by: VincentX Ke Reviewed-by: Hao A Wu --- .../Bus/Ufs/UfsBlockIoPei/UfsBlockIoPei.c | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/MdeModulePkg/Bus/Ufs/UfsBlockIoPei/UfsBlockIoPei.c b/MdeModule= Pkg/Bus/Ufs/UfsBlockIoPei/UfsBlockIoPei.c index b331c0f3e3..b8651ff998 100644 --- a/MdeModulePkg/Bus/Ufs/UfsBlockIoPei/UfsBlockIoPei.c +++ b/MdeModulePkg/Bus/Ufs/UfsBlockIoPei/UfsBlockIoPei.c @@ -1,6 +1,6 @@ /** @file =20 - Copyright (c) 2014 - 2019, Intel Corporation. All rights reserved.
+ Copyright (c) 2014 - 2021, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent =20 **/ @@ -1037,9 +1037,9 @@ InitializeUfsBlockIoPeim ( UFS_PEIM_HC_PRIVATE_DATA *Private; EDKII_UFS_HOST_CONTROLLER_PPI *UfsHcPpi; UINT32 Index; - UFS_CONFIG_DESC Config; UINTN MmioBase; UINT8 Controller; + UFS_UNIT_DESC UnitDescriptor; =20 // // Shadow this PEIM to run from memory @@ -1126,19 +1126,18 @@ InitializeUfsBlockIoPeim ( } =20 // - // Get Ufs Device's Lun Info by reading Configuration Descriptor. + // Check if 8 common luns are active and set corresponding bit mask. // - Status =3D UfsRwDeviceDesc (Private, TRUE, UfsConfigDesc, 0, 0, &Confi= g, sizeof (UFS_CONFIG_DESC)); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "Ufs Get Configuration Descriptor Error, Status= =3D %r\n", Status)); - Controller++; - continue; - } - for (Index =3D 0; Index < UFS_PEIM_MAX_LUNS; Index++) { - if (Config.UnitDescConfParams[Index].LunEn !=3D 0) { - Private->Luns.BitMask |=3D (BIT0 << Index); + Status =3D UfsRwDeviceDesc (Private, TRUE, UfsUnitDesc, (UINT8)Index= , 0, &UnitDescriptor, sizeof (UFS_UNIT_DESC)); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Fail to read UFS Unit Descriptor, Index =3D = %X, Status =3D %r\n", Index, Status)); + continue; + } + + if (UnitDescriptor.LunEn =3D=3D 0x1) { DEBUG ((DEBUG_INFO, "Ufs %d Lun %d is enabled\n", Controller, Inde= x)); + Private->Luns.BitMask |=3D (BIT0 << Index); } } =20 --=20 2.31.1.windows.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 (#85194): https://edk2.groups.io/g/devel/message/85194 Mute This Topic: https://groups.io/mt/87914346/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- From nobody Fri Apr 26 00:08:02 2024 Delivered-To: importer@patchew.org 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+85195+1787277+3901457@groups.io; helo=mail02.groups.io; 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+85195+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1640243331; cv=none; d=zohomail.com; s=zohoarc; b=ThrDF4Mef3Pc4WQtMtU7QmMurJESfOZN20AN+GB3yotwm8sOXfg0T3dZ8mm2yQRRKVFIcPT6eVsEUTorR7wqJHM61k++RDMOyM4R4V1VGXbiDDXu4odZwpgPn1ZOKGhRd0KAv6htJv/2k+VGz/EzITw4GMZqoZLsI3SSc+UDUtk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1640243331; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=L6hkFdeiXkxIxi4rq6tyxu5mZiZU9N8qJfERAD2V4Ec=; b=mE1xSPlvrscqC+qIpcgSRC91hQ4kp5peJMvFFXvvhskSpEOKJA7P8rFz+ZpXXqygH9xYqPPQPFEop5trohD90pGo9qyvBg8CH+/SmtU26vHYMkBHpyG5EgSFC5kJqkMvlsegIi0R4iid+v3+8QPevJRQAlaWV8xtFXpU8BM7IrM= ARC-Authentication-Results: i=1; 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+85195+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1640243331148815.6943386336907; Wed, 22 Dec 2021 23:08:51 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id DQJHYY1788612xgYaokiavEw; Wed, 22 Dec 2021 23:08:50 -0800 X-Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by mx.groups.io with SMTP id smtpd.web10.30187.1640243330110009510 for ; Wed, 22 Dec 2021 23:08:50 -0800 X-IronPort-AV: E=McAfee;i="6200,9189,10206"; a="228070456" X-IronPort-AV: E=Sophos;i="5.88,228,1635231600"; d="scan'208";a="228070456" X-Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Dec 2021 23:08:30 -0800 X-IronPort-AV: E=Sophos;i="5.88,228,1635231600"; d="scan'208";a="521984466" X-Received: from kxinfux-mobl2.gar.corp.intel.com ([10.214.170.104]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Dec 2021 23:08:27 -0800 From: "VincentX Ke" To: devel@edk2.groups.io Cc: VincentX Ke , Hao A Wu , Ray Ni , Ian Chiu , Maggie Chu Subject: [edk2-devel] [PATCH v7 2/3] MdeModulePkg: Refactoring UFS DME request and fix timing problem Date: Thu, 23 Dec 2021 15:07:53 +0800 Message-Id: <20211223070754.2190-3-vincentx.ke@intel.com> In-Reply-To: <20211223070754.2190-1-vincentx.ke@intel.com> References: <20211223070754.2190-1-vincentx.ke@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,vincentx.ke@intel.com X-Gm-Message-State: pZsBpAOXOAskNOwTi4vnp0J2x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1640243330; bh=4PGSo69JwZYY0bGWLm2+Nn0/FQYdOpw6h7z5x4CKsYs=; h=Cc:Date:From:Reply-To:Subject:To; b=XpSV3AI5mJWCgTQL/1H3WZrExF/eBwyT5CFZNHPG9xhzsPHqwjkK4hb3hS5xiltkQSm bcC3vZitvc+D8U45oK0z9uPqlEZ52qHdpTY5ailk3PnlmEYf9LM0/Lk1Aouva2VIs90QY NDZ89pwq4l9zMwUvh3yG2Mglvh26/K/IooI= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1640243332232100002 Content-Type: text/plain; charset="utf-8" BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3775 Refactoring UFS DME request function and retry up to 5 times. Cc: Hao A Wu Cc: Ray Ni Cc: Ian Chiu Cc: Maggie Chu Signed-off-by: VincentX Ke Reviewed-by: Hao A Wu --- MdeModulePkg/Bus/Ufs/UfsBlockIoPei/UfsHci.c | 326 +++++++++++--------- 1 file changed, 187 insertions(+), 139 deletions(-) diff --git a/MdeModulePkg/Bus/Ufs/UfsBlockIoPei/UfsHci.c b/MdeModulePkg/Bus= /Ufs/UfsBlockIoPei/UfsHci.c index 2baa57593e..409ea283f5 100644 --- a/MdeModulePkg/Bus/Ufs/UfsBlockIoPei/UfsHci.c +++ b/MdeModulePkg/Bus/Ufs/UfsBlockIoPei/UfsHci.c @@ -1,6 +1,6 @@ /** @file =20 - Copyright (c) 2014 - 2018, Intel Corporation. All rights reserved.
+ Copyright (c) 2014 - 2021, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent =20 **/ @@ -551,14 +551,9 @@ UfsCreateDMCommandDesc ( Data =3D NULL; } =20 - if ( ((Opcode !=3D UtpQueryFuncOpcodeSetFlag) && (Opcode !=3D UtpQueryF= uncOpcodeClrFlag) && (Opcode !=3D UtpQueryFuncOpcodeTogFlag)) - && ((DataSize =3D=3D 0) || (Data =3D=3D NULL))) - { - return EFI_INVALID_PARAMETER; - } - - if ( ((Opcode =3D=3D UtpQueryFuncOpcodeSetFlag) || (Opcode =3D=3D UtpQu= eryFuncOpcodeClrFlag) || (Opcode =3D=3D UtpQueryFuncOpcodeTogFlag)) - && ((DataSize !=3D 0) || (Data !=3D NULL))) + if (((Opcode !=3D UtpQueryFuncOpcodeRdFlag) && (Opcode !=3D UtpQueryFunc= OpcodeSetFlag) && + (Opcode !=3D UtpQueryFuncOpcodeClrFlag) && (Opcode !=3D UtpQueryFun= cOpcodeTogFlag)) && + ((DataSize =3D=3D 0) || (Data =3D=3D NULL))) { return EFI_INVALID_PARAMETER; } @@ -747,60 +742,96 @@ UfsStopExecCmd ( } =20 /** - Read or write specified device descriptor of a UFS device. + Extracts return data from query response upiu. =20 - @param[in] Private The pointer to the UFS_PEIM_HC_PRIVATE_DAT= A data structure. - @param[in] Read The boolean variable to show r/w direction. - @param[in] DescId The ID of device descriptor. - @param[in] Index The Index of device descriptor. - @param[in] Selector The Selector of device descriptor. - @param[in, out] Descriptor The buffer of device descriptor to be read= or written. - @param[in] DescSize The size of device descriptor buffer. + @param[in, out] Packet Pointer to the UFS_DEVICE_MANAGEMENT_REQUE= ST_PACKET. + @param[in] QueryResp Pointer to the query response. =20 - @retval EFI_SUCCESS The device descriptor was read/written suc= cessfully. - @retval EFI_DEVICE_ERROR A device error occurred while attempting t= o r/w the device descriptor. - @retval EFI_TIMEOUT A timeout occurred while waiting for the c= ompletion of r/w the device descriptor. + @retval EFI_INVALID_PARAMETER Packet or QueryResp are empty or opcode is= invalid. + @retval EFI_DEVICE_ERROR Data returned from device is invalid. + @retval EFI_SUCCESS Data extracted. =20 **/ EFI_STATUS -UfsRwDeviceDesc ( - IN UFS_PEIM_HC_PRIVATE_DATA *Private, - IN BOOLEAN Read, - IN UINT8 DescId, - IN UINT8 Index, - IN UINT8 Selector, - IN OUT VOID *Descriptor, - IN UINT32 DescSize +UfsGetReturnDataFromQueryResponse ( + IN OUT UFS_DEVICE_MANAGEMENT_REQUEST_PACKET *Packet, + IN UTP_QUERY_RESP_UPIU *QueryResp ) { - EFI_STATUS Status; - UFS_DEVICE_MANAGEMENT_REQUEST_PACKET Packet; - UINT8 Slot; - UTP_TRD *Trd; - UINTN Address; - UTP_QUERY_RESP_UPIU *QueryResp; - UINT8 *CmdDescBase; - UINT32 CmdDescSize; - UINT16 ReturnDataSize; + UINT16 ReturnDataSize; =20 - ZeroMem (&Packet, sizeof (UFS_DEVICE_MANAGEMENT_REQUEST_PACKET)); + ReturnDataSize =3D 0; =20 - if (Read) { - Packet.DataDirection =3D UfsDataIn; - Packet.InDataBuffer =3D Descriptor; - Packet.InTransferLength =3D DescSize; - Packet.Opcode =3D UtpQueryFuncOpcodeRdDesc; - } else { - Packet.DataDirection =3D UfsDataOut; - Packet.OutDataBuffer =3D Descriptor; - Packet.OutTransferLength =3D DescSize; - Packet.Opcode =3D UtpQueryFuncOpcodeWrDesc; + if ((Packet =3D=3D NULL) || (QueryResp =3D=3D NULL)) { + return EFI_INVALID_PARAMETER; } =20 - Packet.DescId =3D DescId; - Packet.Index =3D Index; - Packet.Selector =3D Selector; - Packet.Timeout =3D UFS_TIMEOUT; + switch (Packet->Opcode) { + case UtpQueryFuncOpcodeRdDesc: + ReturnDataSize =3D QueryResp->Tsf.Length; + SwapLittleEndianToBigEndian ((UINT8 *)&ReturnDataSize, sizeof (UINT1= 6)); + // + // Make sure the hardware device does not return more data than expe= cted. + // + if (ReturnDataSize > Packet->InTransferLength) { + return EFI_DEVICE_ERROR; + } + + CopyMem (Packet->InDataBuffer, (QueryResp + 1), ReturnDataSize); + Packet->InTransferLength =3D ReturnDataSize; + break; + case UtpQueryFuncOpcodeWrDesc: + ReturnDataSize =3D QueryResp->Tsf.Length; + SwapLittleEndianToBigEndian ((UINT8 *)&ReturnDataSize, sizeof (UINT1= 6)); + Packet->OutTransferLength =3D ReturnDataSize; + break; + case UtpQueryFuncOpcodeRdFlag: + // + // The 'FLAG VALUE' field is at byte offset 3 of QueryResp->Tsf.Value + // + *((UINT8 *)(Packet->InDataBuffer)) =3D *((UINT8 *)&(QueryResp->Tsf.V= alue) + 3); + break; + case UtpQueryFuncOpcodeSetFlag: + case UtpQueryFuncOpcodeClrFlag: + case UtpQueryFuncOpcodeTogFlag: + // + // The 'FLAG VALUE' field is at byte offset 3 of QueryResp->Tsf.Value + // + *((UINT8 *)(Packet->OutDataBuffer)) =3D *((UINT8 *)&(QueryResp->Tsf.= Value) + 3); + break; + default: + return EFI_INVALID_PARAMETER; + } + + return EFI_SUCCESS; +} + +/** + Creates Transfer Request descriptor and sends Query Request to the devic= e. + + @param[in] Private Pointer to the UFS_PEIM_HC_PRIVATE_DATA. + @param[in, out] Packet Pointer to the UFS_DEVICE_MANAGEMENT_REQUE= ST_PACKET. + + @retval EFI_SUCCESS The device descriptor was read/written suc= cessfully. + @retval EFI_INVALID_PARAMETER The DescId, Index and Selector fields in P= acket are invalid + combination to point to a type of UFS devi= ce descriptor. + @retval EFI_DEVICE_ERROR A device error occurred while attempting t= o r/w the device descriptor. + @retval EFI_TIMEOUT A timeout occurred while waiting for the c= ompletion of r/w the device descriptor. + +**/ +EFI_STATUS +UfsSendDmRequestRetry ( + IN UFS_PEIM_HC_PRIVATE_DATA *Private, + IN OUT UFS_DEVICE_MANAGEMENT_REQUEST_PACKET *Packet + ) +{ + UINT8 Slot; + EFI_STATUS Status; + UTP_TRD *Trd; + UINTN Address; + UTP_QUERY_RESP_UPIU *QueryResp; + UINT8 *CmdDescBase; + UINT32 CmdDescSize; =20 // // Find out which slot of transfer request list is available. @@ -814,8 +845,9 @@ UfsRwDeviceDesc ( // // Fill transfer request descriptor to this slot. // - Status =3D UfsCreateDMCommandDesc (Private, &Packet, Trd); + Status =3D UfsCreateDMCommandDesc (Private, Packet, Trd); if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Failed to create DM command descriptor\n")); return Status; } =20 @@ -835,43 +867,116 @@ UfsRwDeviceDesc ( // Wait for the completion of the transfer request. // Address =3D Private->UfsHcBase + UFS_HC_UTRLDBR_OFFSET; - Status =3D UfsWaitMemSet (Address, BIT0 << Slot, 0, Packet.Timeout); + Status =3D UfsWaitMemSet (Address, (BIT0 << Slot), 0, Packet->Timeout); if (EFI_ERROR (Status)) { goto Exit; } =20 - if (QueryResp->QueryResp !=3D 0) { + if ((Trd->Ocs !=3D 0) || (QueryResp->QueryResp !=3D UfsUtpQueryResponseS= uccess)) { + DEBUG ((DEBUG_ERROR, "Failed to send query request, OCS =3D %X, QueryR= esp =3D %X\n", Trd->Ocs, QueryResp->QueryResp)); DumpQueryResponseResult (QueryResp->QueryResp); Status =3D EFI_DEVICE_ERROR; goto Exit; } =20 - if (Trd->Ocs =3D=3D 0) { - ReturnDataSize =3D QueryResp->Tsf.Length; - SwapLittleEndianToBigEndian ((UINT8 *)&ReturnDataSize, sizeof (UINT16)= ); + Status =3D UfsGetReturnDataFromQueryResponse (Packet, QueryResp); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Failed to get return data from query response\n"= )); + goto Exit; + } =20 - if (Read) { - // - // Make sure the hardware device does not return more data than expe= cted. - // - if (ReturnDataSize > Packet.InTransferLength) { - Status =3D EFI_DEVICE_ERROR; - goto Exit; - } +Exit: + UfsStopExecCmd (Private, Slot); + UfsPeimFreeMem (Private->Pool, CmdDescBase, CmdDescSize); =20 - CopyMem (Packet.InDataBuffer, (QueryResp + 1), ReturnDataSize); - Packet.InTransferLength =3D ReturnDataSize; - } else { - Packet.OutTransferLength =3D ReturnDataSize; + return Status; +} + +/** + Sends Query Request to the device. Query is sent until device responds c= orrectly or counter runs out. + + @param[in] Private Pointer to the UFS_PEIM_HC_PRIVATE_DATA. + @param[in, out] Packet Pointer to the UFS_DEVICE_MANAGEMENT_REQUE= ST_PACKET. + + @retval EFI_SUCCESS The device responded correctly to the Quer= y request. + @retval EFI_INVALID_PARAMETER The DescId, Index and Selector fields in P= acket are invalid + combination to point to a type of UFS devi= ce descriptor. + @retval EFI_DEVICE_ERROR A device error occurred while waiting for = the response from the device. + @retval EFI_TIMEOUT A timeout occurred while waiting for the c= ompletion of the operation. + +**/ +EFI_STATUS +UfsSendDmRequest ( + IN UFS_PEIM_HC_PRIVATE_DATA *Private, + IN OUT UFS_DEVICE_MANAGEMENT_REQUEST_PACKET *Packet + ) +{ + EFI_STATUS Status; + UINT8 Retry; + + Status =3D EFI_SUCCESS; + + for (Retry =3D 0; Retry < 5; Retry++) { + Status =3D UfsSendDmRequestRetry (Private, Packet); + if (!EFI_ERROR (Status)) { + return EFI_SUCCESS; } + } + + DEBUG ((DEBUG_ERROR, "Failed to get response from the device after %d re= tries\n", Retry)); + return Status; +} + +/** + Read or write specified device descriptor of a UFS device. + + @param[in] Private The pointer to the UFS_PEIM_HC_PRIVATE_DAT= A data structure. + @param[in] Read The boolean variable to show r/w direction. + @param[in] DescId The ID of device descriptor. + @param[in] Index The Index of device descriptor. + @param[in] Selector The Selector of device descriptor. + @param[in, out] Descriptor The buffer of device descriptor to be read= or written. + @param[in] DescSize The size of device descriptor buffer. + + @retval EFI_SUCCESS The device descriptor was read/written suc= cessfully. + @retval EFI_DEVICE_ERROR A device error occurred while attempting t= o r/w the device descriptor. + @retval EFI_TIMEOUT A timeout occurred while waiting for the c= ompletion of r/w the device descriptor. + +**/ +EFI_STATUS +UfsRwDeviceDesc ( + IN UFS_PEIM_HC_PRIVATE_DATA *Private, + IN BOOLEAN Read, + IN UINT8 DescId, + IN UINT8 Index, + IN UINT8 Selector, + IN OUT VOID *Descriptor, + IN UINT32 DescSize + ) +{ + EFI_STATUS Status; + UFS_DEVICE_MANAGEMENT_REQUEST_PACKET Packet; + + ZeroMem (&Packet, sizeof (UFS_DEVICE_MANAGEMENT_REQUEST_PACKET)); + + if (Read) { + Packet.DataDirection =3D UfsDataIn; + Packet.InDataBuffer =3D Descriptor; + Packet.InTransferLength =3D DescSize; + Packet.Opcode =3D UtpQueryFuncOpcodeRdDesc; } else { - Status =3D EFI_DEVICE_ERROR; + Packet.DataDirection =3D UfsDataOut; + Packet.OutDataBuffer =3D Descriptor; + Packet.OutTransferLength =3D DescSize; + Packet.Opcode =3D UtpQueryFuncOpcodeWrDesc; } =20 -Exit: - UfsStopExecCmd (Private, Slot); - UfsPeimFreeMem (Private->Pool, CmdDescBase, CmdDescSize); + Packet.DescId =3D DescId; + Packet.Index =3D Index; + Packet.Selector =3D Selector; + Packet.Timeout =3D UFS_TIMEOUT; =20 + Status =3D UfsSendDmRequest (Private, &Packet); return Status; } =20 @@ -898,12 +1003,6 @@ UfsRwFlags ( { EFI_STATUS Status; UFS_DEVICE_MANAGEMENT_REQUEST_PACKET Packet; - UINT8 Slot; - UTP_TRD *Trd; - UINTN Address; - UTP_QUERY_RESP_UPIU *QueryResp; - UINT8 *CmdDescBase; - UINT32 CmdDescSize; =20 if (Value =3D=3D NULL) { return EFI_INVALID_PARAMETER; @@ -913,10 +1012,14 @@ UfsRwFlags ( =20 if (Read) { ASSERT (Value !=3D NULL); - Packet.DataDirection =3D UfsDataIn; - Packet.Opcode =3D UtpQueryFuncOpcodeRdFlag; + Packet.DataDirection =3D UfsDataIn; + Packet.InDataBuffer =3D (VOID *)Value; + Packet.InTransferLength =3D 0; + Packet.Opcode =3D UtpQueryFuncOpcodeRdFlag; } else { - Packet.DataDirection =3D UfsDataOut; + Packet.DataDirection =3D UfsDataOut; + Packet.OutDataBuffer =3D (VOID *)Value; + Packet.OutTransferLength =3D 0; if (*Value =3D=3D 1) { Packet.Opcode =3D UtpQueryFuncOpcodeSetFlag; } else if (*Value =3D=3D 0) { @@ -931,62 +1034,7 @@ UfsRwFlags ( Packet.Selector =3D 0; Packet.Timeout =3D UFS_TIMEOUT; =20 - // - // Find out which slot of transfer request list is available. - // - Status =3D UfsFindAvailableSlotInTrl (Private, &Slot); - if (EFI_ERROR (Status)) { - return Status; - } - - // - // Fill transfer request descriptor to this slot. - // - Trd =3D ((UTP_TRD *)Private->UtpTrlBase) + Slot; - Status =3D UfsCreateDMCommandDesc (Private, &Packet, Trd); - if (EFI_ERROR (Status)) { - return Status; - } - - // - // Check the transfer request result. - // - CmdDescBase =3D (UINT8 *)(UINTN)(LShiftU64 ((UINT64)Trd->UcdBaU, 32) | L= ShiftU64 ((UINT64)Trd->UcdBa, 7)); - QueryResp =3D (UTP_QUERY_RESP_UPIU *)(CmdDescBase + Trd->RuO * sizeof = (UINT32)); - CmdDescSize =3D Trd->RuO * sizeof (UINT32) + Trd->RuL * sizeof (UINT32); - - // - // Start to execute the transfer request. - // - UfsStartExecCmd (Private, Slot); - - // - // Wait for the completion of the transfer request. - // - Address =3D Private->UfsHcBase + UFS_HC_UTRLDBR_OFFSET; - Status =3D UfsWaitMemSet (Address, BIT0 << Slot, 0, Packet.Timeout); - if (EFI_ERROR (Status)) { - goto Exit; - } - - if (QueryResp->QueryResp !=3D 0) { - DumpQueryResponseResult (QueryResp->QueryResp); - Status =3D EFI_DEVICE_ERROR; - goto Exit; - } - - if (Trd->Ocs =3D=3D 0) { - // - // The 'FLAG VALUE' field is at byte offset 3 of QueryResp->Tsf.Value - // - *Value =3D *((UINT8 *)&(QueryResp->Tsf.Value) + 3); - } else { - Status =3D EFI_DEVICE_ERROR; - } - -Exit: - UfsStopExecCmd (Private, Slot); - UfsPeimFreeMem (Private->Pool, CmdDescBase, CmdDescSize); + Status =3D UfsSendDmRequest (Private, &Packet); =20 return Status; } --=20 2.31.1.windows.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 (#85195): https://edk2.groups.io/g/devel/message/85195 Mute This Topic: https://groups.io/mt/87914349/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- From nobody Fri Apr 26 00:08:02 2024 Delivered-To: importer@patchew.org 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+85196+1787277+3901457@groups.io; helo=mail02.groups.io; 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+85196+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1640243331; cv=none; d=zohomail.com; s=zohoarc; b=DArd0ruRzkuhz7Qgi9thrCWuu032JXkpYg0041iOxuiGI0mT29es7XfelgLpL3lGLU01zWOtiauU937U7Ft8bIAYR/w/v1LWLCkk+F/3K/Yp9aEC4dLWD5ZpXZxggPEMjBCElbOtdpI1n+A5J6A0ZJqS1IEI4dWomcKfoL1haD8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1640243331; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=E1u0nvjAX2e15933qtQpcMTNMhhY/QrKSeHt67q/5ec=; b=mTlbcx9YU4KFQz53rsEJr0vYfX63TINbKwSFByfAeqcOatwt/UAXVs8989/VHKieQHWgD1GO12C4h42Dh+fz/cx/AFd7xxj2o1cgHKrUBDsHZI8mu/r+TK/Gy/+yWSOvzufIKyH7pOkKtbG1Ncr0fIMEuc00z/ZloUcW5Ge4z9Y= ARC-Authentication-Results: i=1; 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+85196+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1640243331609502.63489208876206; Wed, 22 Dec 2021 23:08:51 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id ZSMiYY1788612xJ70A7DaHdr; Wed, 22 Dec 2021 23:08:51 -0800 X-Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by mx.groups.io with SMTP id smtpd.web10.30187.1640243330110009510 for ; Wed, 22 Dec 2021 23:08:50 -0800 X-IronPort-AV: E=McAfee;i="6200,9189,10206"; a="228070467" X-IronPort-AV: E=Sophos;i="5.88,228,1635231600"; d="scan'208";a="228070467" X-Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Dec 2021 23:08:34 -0800 X-IronPort-AV: E=Sophos;i="5.88,228,1635231600"; d="scan'208";a="521984479" X-Received: from kxinfux-mobl2.gar.corp.intel.com ([10.214.170.104]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Dec 2021 23:08:31 -0800 From: "VincentX Ke" To: devel@edk2.groups.io Cc: VincentX Ke , Hao A Wu , Ray Ni , Ian Chiu , Maggie Chu Subject: [edk2-devel] [PATCH v7 3/3] MdeModulePkg: Put off UFS HCS.DP checking to fix timing problem Date: Thu, 23 Dec 2021 15:07:54 +0800 Message-Id: <20211223070754.2190-4-vincentx.ke@intel.com> In-Reply-To: <20211223070754.2190-1-vincentx.ke@intel.com> References: <20211223070754.2190-1-vincentx.ke@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,vincentx.ke@intel.com X-Gm-Message-State: inkXM7Ay0u7ZIhWhg6GGJuKRx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1640243331; bh=aVs4oYIAEUj90gCYL4rqsjWridZhsaT/tbmKeWY9yn8=; h=Cc:Date:From:Reply-To:Subject:To; b=LMohRu+7+jC1T1rsrmtpW4AWxPyeO3NWJ30Naoys+Qeenm1y8PcwqqyYaFRJy6r2UuL teIfWE4Jo7ft6hzueki0LzCiOPDctkt/4T+q78WaKO+Xj4eXVN+34VN/EGH/TqUcJ7hsP bqyYXj1YntMER/mF+KLSstvO3vB5F/91SgI= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1640243332283100004 Content-Type: text/plain; charset="utf-8" BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3776 Put off UFS HCS.DP (Device Attached) checking until UfsDeviceDetection() to fix timing problem. Cc: Hao A Wu Cc: Ray Ni Cc: Ian Chiu Cc: Maggie Chu Signed-off-by: VincentX Ke Reviewed-by: Hao A Wu --- MdeModulePkg/Bus/Ufs/UfsBlockIoPei/UfsHci.c | 47 +++++++++------------ 1 file changed, 19 insertions(+), 28 deletions(-) diff --git a/MdeModulePkg/Bus/Ufs/UfsBlockIoPei/UfsHci.c b/MdeModulePkg/Bus= /Ufs/UfsBlockIoPei/UfsHci.c index 409ea283f5..d19a7fed6e 100644 --- a/MdeModulePkg/Bus/Ufs/UfsBlockIoPei/UfsHci.c +++ b/MdeModulePkg/Bus/Ufs/UfsBlockIoPei/UfsHci.c @@ -1355,23 +1355,6 @@ UfsExecUicCommands ( } } =20 - // - // Check value of HCS.DP and make sure that there is a device attached t= o the Link. - // - Address =3D UfsHcBase + UFS_HC_STATUS_OFFSET; - Data =3D MmioRead32 (Address); - if ((Data & UFS_HC_HCS_DP) =3D=3D 0) { - Address =3D UfsHcBase + UFS_HC_IS_OFFSET; - Status =3D UfsWaitMemSet (Address, UFS_HC_IS_ULSS, UFS_HC_IS_ULSS, UF= S_TIMEOUT); - if (EFI_ERROR (Status)) { - return EFI_DEVICE_ERROR; - } - - return EFI_NOT_FOUND; - } - - DEBUG ((DEBUG_INFO, "UfsblockioPei: found a attached UFS device\n")); - return EFI_SUCCESS; } =20 @@ -1445,6 +1428,8 @@ UfsDeviceDetection ( ) { UINTN Retry; + UINTN Address; + UINT32 Data; EFI_STATUS Status; =20 // @@ -1453,22 +1438,28 @@ UfsDeviceDetection ( // for (Retry =3D 0; Retry < 3; Retry++) { Status =3D UfsExecUicCommands (Private, UfsUicDmeLinkStartup, 0, 0, 0); - if (!EFI_ERROR (Status)) { - break; + if (EFI_ERROR (Status)) { + return EFI_DEVICE_ERROR; } =20 - if (Status =3D=3D EFI_NOT_FOUND) { - continue; + // + // Check value of HCS.DP and make sure that there is a device attached= to the Link + // + Address =3D Private->UfsHcBase + UFS_HC_STATUS_OFFSET; + Data =3D MmioRead32 (Address); + if ((Data & UFS_HC_HCS_DP) =3D=3D 0) { + Address =3D Private->UfsHcBase + UFS_HC_IS_OFFSET; + Status =3D UfsWaitMemSet (Address, UFS_HC_IS_ULSS, UFS_HC_IS_ULSS, = UFS_TIMEOUT); + if (EFI_ERROR (Status)) { + return EFI_DEVICE_ERROR; + } + } else { + DEBUG ((DEBUG_INFO, "UfsblockioPei: found a attached UFS device\n")); + return EFI_SUCCESS; } - - return EFI_DEVICE_ERROR; } =20 - if (Retry =3D=3D 3) { - return EFI_NOT_FOUND; - } - - return EFI_SUCCESS; + return EFI_NOT_FOUND; } =20 /** --=20 2.31.1.windows.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 (#85196): https://edk2.groups.io/g/devel/message/85196 Mute This Topic: https://groups.io/mt/87914350/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-