From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by mx.groups.io with SMTP id smtpd.web11.29537.1640238141450171514 for ; Wed, 22 Dec 2021 21:42:22 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=XDCjSCoZ; spf=pass (domain: intel.com, ip: 192.55.52.93, mailfrom: hao.a.wu@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1640238141; x=1671774141; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=gYGGUgpg6WI7EvthJ5mztpf/m2t0nM0rMZYvcUfbHIA=; b=XDCjSCoZTxB9KnVLtKcnc1tFDZj4RBCVMGKuIuNIXdW07YvEW18Nv7ZS Frm+fmIW+rx7qS/X4fDNrGZh7N6iWFqotd3l/fox4eDzzxrDbkHm7nvam gFTiOZvGD9KAOdtd1ZjBzRONUX+bGGbt9lwsHAd7vkRG20nSr4g/2/tQC cUGm1+HJv/nh+MkOFX2ptOZ2pxzo+V4zqnhWtsA/FHaCg6SXFaUGwEadD LKiBgFJHGiDPlA/1wgeY7tpWmP2VYpD1Vov8eieu0IwuGxHbUr9jN6xxj smCB1oZXJ9R/kwM+h+yDGXneWSWZPms1obUHpvFRnae8xRs+/d4w1MCvK A==; X-IronPort-AV: E=McAfee;i="6200,9189,10206"; a="238297540" X-IronPort-AV: E=Sophos;i="5.88,228,1635231600"; d="scan'208";a="238297540" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Dec 2021 21:42:20 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,228,1635231600"; d="scan'208";a="607649115" Received: from fmsmsx604.amr.corp.intel.com ([10.18.126.84]) by FMSMGA003.fm.intel.com with ESMTP; 22 Dec 2021 21:42:20 -0800 Received: from fmsmsx610.amr.corp.intel.com (10.18.126.90) by fmsmsx604.amr.corp.intel.com (10.18.126.84) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Wed, 22 Dec 2021 21:42:20 -0800 Received: from fmsedg602.ED.cps.intel.com (10.1.192.136) by fmsmsx610.amr.corp.intel.com (10.18.126.90) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20 via Frontend Transport; Wed, 22 Dec 2021 21:42:20 -0800 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (104.47.55.109) by edgegateway.intel.com (192.55.55.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2308.20; Wed, 22 Dec 2021 21:42:20 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iXak1aZRcTKDnrmeHns3Jlj/dYSrI1afOrBVNIfaOF4c3zfiWUebZRO0auZnSCQqbMsPb47BX5BCnA++zyn9wA/qeVgjqFojJyAonQgfuxXd9TUqXmk3NefgSVtsqDaORDOCfT05FZB/eOxTMgNPEDrhEjVd2zcTRE67XD1PiLxf4MjAxvIdSktjslCXwjfxrnqw8YgAkk1oD4Q/WXCNb0+XGzhQIyFAJvud+4t62IHf+hgRTquA6N+2dMuoB4DpcUA9NYtfNshteF1G2A3d47qT4pCJ0yo2orYHKmWFN+OZpit7eWS8cPPYObyJyrwfsF5/kRA14sPicoJRakN4cA== 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=uenNSS67BQnDXlhwYRMV59abqPgtMnwuIcrDw84uB88=; b=ayF8xcHBDwFQ0GOJIrYSnPo9Ckrfi0LcMDPquni4OAvouoOWzebcKwSrxnO8dXW14zZ1clyiXjlRVXDggEh/5rSQXGNVitfguh3+IBnQCEC4U7/A+DetduHi2iHDvvoGMsbkGbaUIYmZFVPxQ+cCJz8Lb80A7TwMRQ/V+5OHT+cj4Xu6bP5HTZQdkcc8UQ2aeX1ecfqVfRz2eEJssWzVlzIuMaab9RUdNXNxV4zRoCFwn9KPeNvAdNpellWvKFpYhpfrJ8FHALN9uoHordvpgj1ec4vVpHHxU2sBdtn3rESCoOI4gEIsDT6n6v9CkVgImHmDT2i1qoF3QxB/JuMlsw== 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 Received: from DM6PR11MB4025.namprd11.prod.outlook.com (2603:10b6:5:197::31) by DM6PR11MB3980.namprd11.prod.outlook.com (2603:10b6:5:192::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4801.14; Thu, 23 Dec 2021 05:42:18 +0000 Received: from DM6PR11MB4025.namprd11.prod.outlook.com ([fe80::b8f1:aa83:cbbf:6964]) by DM6PR11MB4025.namprd11.prod.outlook.com ([fe80::b8f1:aa83:cbbf:6964%6]) with mapi id 15.20.4823.019; Thu, 23 Dec 2021 05:42:18 +0000 From: "Wu, Hao A" To: "Ke, VincentX" , "devel@edk2.groups.io" CC: "Ni, Ray" , "Chiu, Ian" , "Chu, Maggie" Subject: Re: [PATCH v6 2/3] MdeModulePkg: Refactoring UFS DME request and fix timing problem Thread-Topic: [PATCH v6 2/3] MdeModulePkg: Refactoring UFS DME request and fix timing problem Thread-Index: AQHX97RpLnu1uZbfkkyuEThp9Bhhq6w/izIw Date: Thu, 23 Dec 2021 05:42:18 +0000 Message-ID: References: <20211223041919.1307-1-vincentx.ke@intel.com> <20211223041919.1307-3-vincentx.ke@intel.com> In-Reply-To: <20211223041919.1307-3-vincentx.ke@intel.com> Accept-Language: en-US, zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-reaction: no-action dlp-version: 11.5.1.3 authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: e95ccb52-2802-42e4-4116-08d9c5d6fb95 x-ms-traffictypediagnostic: DM6PR11MB3980:EE_ x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:9508; x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: Di+fCUuchzpLIYt7Sbv35ORRQBM/cCvwy7gxnoUKrEsExnXkp1xTXLHiHF1g6A/Rxr3dKlFWtAXPfdn4NHO1jK6J+1Ml3WAvV/oPDC8TqY5XLyXsX/T0tRa1RuQsFxpaTCzMmyqf5rgZrWhNTzOQ/tFPUgZwfQry+DAuXk2PCAQWuldUgec7QzmY0bOfPxVnf8U4cDcIpOOWBh3BFIGRDvfHTID/c/WOjzartTqeyzDiYebL6slCROC8X252nbo+fYJyCIj/J8uk0DIYrmFXn/y98ogIZkOpg29WUVm02DhgnkYleGa8Y3I3ofNqQdEZ3HTLq8Ept0iOovBLne3mK4Ag1Ed8kzw2mU3aWvmnoX8r6/OScHlhHLZKA/owc4VkYqIjkBJqC3ytfMkOWaGhVBOtF34LGoZisGcwtpHufkzcimAXiBDUuJPEEKjIjB7gxeG7clgeFEiNYjX6VZZpLzeWaz+dngtll6511d8VG16LzCiLAVqWkH1iy5KlhPaNnWEuKV+lll3pMnQ99KHQGcAMLoFUnWRGYa/9BdQbtluUD8lRbMOgLuTVcIs+7xRcMnAk3E9LAxTKmiyq3SDO2TlF2FxttooctazgTzcfS3716IZ/1y404xIzj3jmywN5nd1hIsrQmAhah8nG2exifEtgPpOr87dxiNWqaqAYUtGYbg0trax5mi2FiI5jr0YYK8sdx8qswvMSC9l72aj1Te839mVYgBogBwAXIoGqW2QCmujDBsX2Uqg1i8zr5N6FvQyQWwQ/QJjqVzRAv/TsE9sl6BiKLJZ6TxYZgT07ufI9GSRjLQr2NKgCOK/wE2IA x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR11MB4025.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(366004)(82960400001)(71200400001)(2906002)(64756008)(38070700005)(122000001)(508600001)(54906003)(4326008)(110136005)(38100700002)(8936002)(5660300002)(107886003)(83380400001)(26005)(316002)(33656002)(7696005)(66446008)(186003)(9686003)(66556008)(55016003)(52536014)(86362001)(76116006)(8676002)(66946007)(30864003)(53546011)(966005)(66476007)(6506007)(290074003);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?g17Z9k840ifZwY7odMGbjNzZH/siZT+ZvyA/zI0JzNo+PfDf9BPBNQ5sKOq2?= =?us-ascii?Q?HgW2i6Gsertq6rizywPbd/g8B68fNMen2AGcvRwAwv2Wwuo0tnVAJwbu6swM?= =?us-ascii?Q?4VUC2SSBYmMCCuuj7iMV6+3jIuMgaJHpIsvLaLO/RCEFk4xmG7I+EnEpwWi9?= =?us-ascii?Q?NLck3XD1nB1q0NVbNhj8RE6lHB9gkYzHJ7kM4/Fs8RHkQ4etmgoJmOjlMw/Q?= =?us-ascii?Q?R6H56K45eNnHfEeY0t7O2UXlU+Dp9URd6jsP/RqP8fSV7nT44mdnTY6ENyFy?= =?us-ascii?Q?ssyqxFAcLTTFdi9/ooKmIOLoBh/J2DmDYbZQp9dXEug+XWVwTr+0767GOuGZ?= =?us-ascii?Q?q1rubkKzAzg4FzxTwrkQbYX/cCcG8NOCFoJ19RK1IIZb2a55mpoNlQiHeIaX?= =?us-ascii?Q?lZECk6RkSAaqsjQi9e4VYUo7f13J2CoGxgCIAfrH4Qg+kbjlJpq1SFzC8RNg?= =?us-ascii?Q?kStMK3LEym5jh3ihXSXNLsRIjtphpBEXKIOHDrl6iLXKbmScUhNjtvlVSeUX?= =?us-ascii?Q?LJRaGzP4z3Oe7rlONt1chN5FTl5HPx7oE5c1y+vJpZW09JLAMFwdUhyfBPo5?= =?us-ascii?Q?vVd2zTTNj9E/JwemD8cTByif32a1krr33K5dzrKZ6LIIBif92f5n/sGcjZh9?= =?us-ascii?Q?DZl51oanJOExoC1K/FsSXMBZ0BsrVcEez9wOZphJVxwGLzovdtx7opl0+aI+?= =?us-ascii?Q?+xw1F2xsKClxlFrnu2BV2KrjYgC4JHGOaIoLyUXPL3rIteLz9Sem8bbRwSSR?= =?us-ascii?Q?6BE+IfAEv4M38qxUA+OamAv3Lxu/j4r+Ur3leCzyWmq1riZKnXRmxuPkRg0j?= =?us-ascii?Q?qizF0EgA5KZgbkfG5znDQXoeANS4tZqsgTZuBNKgKKSrhk6xMKj29vZ1sm4g?= =?us-ascii?Q?oPxPKBt+o6jaMQSbTPXZq8BloYBRXPJ/9TxXly7Xnm8TyMgORteGehxa1qgY?= =?us-ascii?Q?DSbYi5PBEPfrDm2++UhWxx24n/aJcCWTzMD3Mrz6Tm/Gvi59TZ2Bfc9Td+mS?= =?us-ascii?Q?ZXcXe+8YYkPy7Ydz1G8bqZoHM2XIvjb1+poAParJUtJ6gagQkGAQsg3FEWWO?= =?us-ascii?Q?gCfnk24Y910LRcHDPnuAp2VEqTP7Bhbk65jLywP8sTLjYwRFe5tOnldJbM4g?= =?us-ascii?Q?FSAcf8+nT+awNOClxhni2lQiSAb2RH+clmyoypc+9krKZvA4/Iq2sxMR4Zm2?= =?us-ascii?Q?C8Yo4a1zSgRQdO3SIgCnPysAR/9Ov7kjX4DjegUGVJgda7gj/8YkGdloKujj?= =?us-ascii?Q?RCk5xpfPY/426L+/XkqUMNYbIJkPlcN9BciNSWkYiwzgkkOj8GCpVAPzlZic?= =?us-ascii?Q?yO/+hkkSlnoZtMmaEuKrPe3sL2UuDsn9g33dz3Q1KLCyeWWWWEBtLE2UvDsq?= =?us-ascii?Q?YA2kwKqDI/mmy08UXtDwD4Mc43v1+opZ0AXpNU98gCNRE5qR/uy4ww/61HF2?= =?us-ascii?Q?MIPw2TMBBteTKkXp6Z/D2x3huWRm9W3JrFD7r6p+jAN91jyFLlnaj6NOqq5W?= =?us-ascii?Q?kNc4W5zc+D/ciDvgh9d/nFP87xXg7TtV5LtipXP5GMP4FqcsQdzF/+35rH3T?= =?us-ascii?Q?TcXUpY6AEZdRNgN59bp0yd6wiYGla9bsFmwVfDZs3jVsL0dQ53A1ZOd4QZ+T?= =?us-ascii?Q?OxluwqQ+KLBx3vxGYr8fXuA=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: e95ccb52-2802-42e4-4116-08d9c5d6fb95 X-MS-Exchange-CrossTenant-originalarrivaltime: 23 Dec 2021 05:42:18.2609 (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: L00cDuXvObve46KjsYWN+rkAUaoL2claR8OWVxPVFrCh+lXUglZqYaxBs8vxgGoxhztlGR+7OAN2w3UpB2uiww== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR11MB3980 Return-Path: hao.a.wu@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Inline comment below: > -----Original Message----- > From: Ke, VincentX > Sent: Thursday, December 23, 2021 12:19 PM > To: devel@edk2.groups.io > Cc: Ke, VincentX ; Wu, Hao A > ; Ni, Ray ; Chiu, Ian > ; Chu, Maggie > Subject: [PATCH v6 2/3] MdeModulePkg: Refactoring UFS DME request and > fix timing problem >=20 > BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3775 >=20 > Refactoring UFS DME request function and retry up to 5 times. >=20 > Cc: Hao A Wu > Cc: Ray Ni > Cc: Ian Chiu > Cc: Maggie Chu > Signed-off-by: VincentX Ke > --- > MdeModulePkg/Bus/Ufs/UfsBlockIoPei/UfsHci.c | 312 +++++++++++-------- > - > 1 file changed, 179 insertions(+), 133 deletions(-) >=20 > diff --git a/MdeModulePkg/Bus/Ufs/UfsBlockIoPei/UfsHci.c > b/MdeModulePkg/Bus/Ufs/UfsBlockIoPei/UfsHci.c > index 2baa57593e..cffe8e02a7 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 > **/ > @@ -557,7 +557,7 @@ UfsCreateDMCommandDesc ( > return EFI_INVALID_PARAMETER; > } >=20 > - if ( ((Opcode =3D=3D UtpQueryFuncOpcodeSetFlag) || (Opcode =3D=3D > UtpQueryFuncOpcodeClrFlag) || (Opcode =3D=3D UtpQueryFuncOpcodeTogFlag)) > + if ( ((Opcode =3D=3D UtpQueryFuncOpcodeClrFlag) || (Opcode =3D=3D > UtpQueryFuncOpcodeTogFlag)) Please help to just remove the above check. > && ((DataSize !=3D 0) || (Data !=3D NULL))) > { > return EFI_INVALID_PARAMETER; > @@ -747,60 +747,91 @@ 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_DATA data structure. > - @param[in] Read The boolean variable to show r/w directi= on. > - @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 re= ad or > written. > - @param[in] DescSize The size of device descriptor buffer. > + @param[in, out] Packet Pointer to the > UFS_DEVICE_MANAGEMENT_REQUEST_PACKET. > + @param[in] QueryResp Pointer to the query response. >=20 > - @retval EFI_SUCCESS The device descriptor was read/written > successfully. > - @retval EFI_DEVICE_ERROR A device error occurred while attempting= to > r/w the device descriptor. > - @retval EFI_TIMEOUT A timeout occurred while waiting for the > completion 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 > (UINT16)); > + // > + // Make sure the hardware device does not return more data than > expected. > + // > + 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 > (UINT16)); > + Packet->OutTransferLength =3D ReturnDataSize; > + break; > + case UtpQueryFuncOpcodeRdFlag: > + case UtpQueryFuncOpcodeSetFlag: > + case UtpQueryFuncOpcodeClrFlag: > + case UtpQueryFuncOpcodeTogFlag: > + // > + // The 'FLAG VALUE' field is at byte offset 3 of QueryResp->Tsf.Va= lue > + // > + *((UINT8 *)(Packet->OutDataBuffer)) =3D *((UINT8 *)&(QueryResp- > >Tsf.Value) + 3); Use "OutDataBuffer" only for UtpQueryFuncOpcodeSetFlag, UtpQueryFuncOpcodeC= lrFlag and UtpQueryFuncOpcodeTogFlag. Use "InDataBuffer" for UtpQueryFuncOpcodeRdFlag. > + break; > + default: > + return EFI_INVALID_PARAMETER; > + } > + > + return EFI_SUCCESS; > +} > + > +/** > + Creates Transfer Request descriptor and sends Query Request to the > device. > + > + @param[in] Private Pointer to the UFS_PEIM_HC_PRIVATE_DATA. > + @param[in, out] Packet Pointer to the > UFS_DEVICE_MANAGEMENT_REQUEST_PACKET. > + > + @retval EFI_SUCCESS The device descriptor was read/written > successfully. > + @retval EFI_INVALID_PARAMETER The DescId, Index and Selector fields in > Packet are invalid > + combination to point to a type of UFS de= vice descriptor. > + @retval EFI_DEVICE_ERROR A device error occurred while attempting= to > r/w the device descriptor. > + @retval EFI_TIMEOUT A timeout occurred while waiting for the > completion 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 0)) { Please use: if ((Trd->Ocs !=3D 0) || (QueryResp->QueryResp !=3D UfsUtpQueryResponseSu= ccess)) { > + DEBUG ((DEBUG_ERROR, "Failed to send query request, OCS =3D %X, > QueryResp =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 > expected. > - // > - 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 > correctly 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_REQUEST_PACKET. > + > + @retval EFI_SUCCESS The device responded correctly to the Qu= ery > request. > + @retval EFI_INVALID_PARAMETER The DescId, Index and Selector fields in > Packet are invalid > + combination to point to a type of UFS de= vice descriptor. > + @retval EFI_DEVICE_ERROR A device error occurred while waiting fo= r > the response from the device. > + @retval EFI_TIMEOUT A timeout occurred while waiting for the > completion 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 > retries\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_DATA data structure. > + @param[in] Read The boolean variable to show r/w directi= on. > + @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 re= ad or > written. > + @param[in] DescSize The size of device descriptor buffer. > + > + @retval EFI_SUCCESS The device descriptor was read/written > successfully. > + @retval EFI_DEVICE_ERROR A device error occurred while attempting= to > r/w the device descriptor. > + @retval EFI_TIMEOUT A timeout occurred while waiting for the > completion 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; > @@ -926,67 +1025,14 @@ UfsRwFlags ( > } > } >=20 > - Packet.DescId =3D FlagId; > - Packet.Index =3D 0; > - Packet.Selector =3D 0; > - Packet.Timeout =3D UFS_TIMEOUT; > + Packet.OutDataBuffer =3D (VOID *)Value; Please use "Packet.OutDataBuffer" only for the write case, use "Packet.InDa= taBuffer" for read case. Also, I suggest to set OutTransferLength and InTransferLength to 0 respecti= vely. > + Packet.DescId =3D FlagId; > + Packet.Index =3D 0; > + 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) | > LShiftU64 ((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.Valu= e > - // > - *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); > + *Value =3D *((UINT8 *)(Packet.OutDataBuffer)); Similar comment as above, please use "Packet.InDataBuffer" for read case. Best Regards, Hao Wu >=20 > return Status; > } > -- > 2.31.1.windows.1