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.web08.7192.1646742000568672308 for ; Tue, 08 Mar 2022 04:20:00 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=mi1dVd9w; spf=pass (domain: intel.com, ip: 192.55.52.93, mailfrom: purna.chandra.rao.bandaru@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1646742000; x=1678278000; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=aTbKatLMHnoQvYeKkHEuxjWKbXE9zoCvVw+Z8N1P8DY=; b=mi1dVd9wbf8jxWURGsdsFZ1C00ZOdKlr18kXlHu8ZcjU8a7F8yG23CZD TN0O2Pnl7Kk1RazO0K2Z6ZutzO8/oITJzIfxG8N7rfLadg5Oqntm3Ruu9 yEsczDWUf6Q/Xh4r+v4abPzfgDSROKp3DwlVW0bPnG0iTGKCVLRk02AeK ROIdPFL5r6/bKI94CCs0FW8gKP0JHZssE4EVmRxdf1PGYggLD+eH9IScq pNMt2fjCrkBKo/6CwA4sBkmXPw6ze3YclCE0ao4evtVIzSdE1jnsg9AWV 6Q767pvMj/dEX9r21D90K//M9+3DWOLoYh0hC8M5Ibh0Uc5+/7njC7uqj A==; X-IronPort-AV: E=McAfee;i="6200,9189,10279"; a="252241332" X-IronPort-AV: E=Sophos;i="5.90,164,1643702400"; d="scan'208";a="252241332" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Mar 2022 04:19:46 -0800 X-IronPort-AV: E=Sophos;i="5.90,164,1643702400"; d="scan'208";a="537548399" Received: from pbandaru-mobl1.gar.corp.intel.com ([10.213.110.234]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Mar 2022 04:19:44 -0800 From: "Bandaru, Purna Chandra Rao" To: devel@edk2.groups.io Cc: Purna Chandra Rao Bandaru , Wu Hao A , Albecki Mateusz , Liming Gao , Zhiguang Liu Subject: [PATCH] [PATCH v3] MdeModulePkg: Add bRefClkFreq card attribute programming support Date: Tue, 8 Mar 2022 17:49:35 +0530 Message-Id: <4014f68bb8428892e14f15efe152805f95d9b829.1646741878.git.purna.chandra.rao.bandaru@intel.com> X-Mailer: git-send-email 2.31.1.windows.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3851 When the UFS card comes out of Manufacturer, bRefClkFreq attribute is set to 1h on the UFS card as per the Manufacturer Default Value specified by the spec JESD220*. However, depends on the UFS host system environment, it need to be set to the correct value. Reference Clock Frequency value 0h:19.2 MHz 1h: 26 MHz 2h: 38.4 MHz 3h: Obsolete Others: Reserved Cc: Wu Hao A Cc: Albecki Mateusz Cc: Liming Gao Cc: Zhiguang Liu Signed-off-by: Purna Chandra Rao Bandaru --- .../Bus/Ufs/UfsPassThruDxe/UfsPassThru.c | 70 ++++++++++++++++--- .../Bus/Ufs/UfsPassThruDxe/UfsPassThruHci.c | 10 +-- .../Protocol/UfsHostControllerPlatform.h | 15 +++- 3 files changed, 74 insertions(+), 21 deletions(-) diff --git a/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThru.c b/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThru.c index 4c2d6ae27f..dc78e09678 100644 --- a/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThru.c +++ b/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThru.c @@ -1,6 +1,6 @@ /** @file - Copyright (c) 2014 - 2021, Intel Corporation. All rights reserved.
+ Copyright (c) 2014 - 2022, Intel Corporation. All rights reserved.
Copyright (c) Microsoft Corporation.
SPDX-License-Identifier: BSD-2-Clause-Patent @@ -834,15 +834,17 @@ UfsPassThruDriverBindingStart ( IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath ) { - EFI_STATUS Status; - EDKII_UFS_HOST_CONTROLLER_PROTOCOL *UfsHc; - UFS_PASS_THRU_PRIVATE_DATA *Private; - UINTN UfsHcBase; - UINT32 Index; - UFS_UNIT_DESC UnitDescriptor; - UFS_DEV_DESC DeviceDescriptor; - UINT32 UnitDescriptorSize; - UINT32 DeviceDescriptorSize; + EFI_STATUS Status; + EDKII_UFS_HOST_CONTROLLER_PROTOCOL *UfsHc; + UFS_PASS_THRU_PRIVATE_DATA *Private; + UINTN UfsHcBase; + UINT32 Index; + UFS_UNIT_DESC UnitDescriptor; + UFS_DEV_DESC DeviceDescriptor; + UINT32 UnitDescriptorSize; + UINT32 DeviceDescriptorSize; + EDKII_UFS_CARD_REF_CLK_FREQ_ATTRIBUTE Attributes; + UINT8 RefClkAttr; Status = EFI_SUCCESS; UfsHc = NULL; @@ -917,6 +919,54 @@ UfsPassThruDriverBindingStart ( goto Error; } + if ((mUfsHcPlatform != NULL) && + ((mUfsHcPlatform->RefClkFreq == EdkiiUfsCardRefClkFreq19p2Mhz) || + (mUfsHcPlatform->RefClkFreq == EdkiiUfsCardRefClkFreq26Mhz) || + (mUfsHcPlatform->RefClkFreq == EdkiiUfsCardRefClkFreq38p4Mhz))) + { + RefClkAttr = UfsAttrRefClkFreq; + Attributes = EdkiiUfsCardRefClkFreqObsolete; + Status = UfsRwAttributes (Private, TRUE, RefClkAttr, 0, 0, (UINT32 *)&Attributes); + if (!EFI_ERROR (Status)) { + if (Attributes != mUfsHcPlatform->RefClkFreq) { + Attributes = mUfsHcPlatform->RefClkFreq; + DEBUG ( + (DEBUG_INFO, + "Setting bRefClkFreq attribute(%x) to %x\n 0 -> 19.2 Mhz\n 1 -> 26 Mhz\n 2 -> 38.4 Mhz\n 3 -> Obsolete\n", + RefClkAttr, + Attributes) + ); + Status = UfsRwAttributes (Private, FALSE, RefClkAttr, 0, 0, (UINT32 *)&Attributes); + if (EFI_ERROR (Status)) { + DEBUG ( + (DEBUG_ERROR, + "Failed to Change Reference Clock Attribute to %d, Status = %r \n", + mUfsHcPlatform->RefClkFreq, + Status) + ); + } + } + } else { + DEBUG ( + (DEBUG_ERROR, + "Failed to Read Reference Clock Attribute, Status = %r \n", + Status) + ); + } + } + + if ((mUfsHcPlatform != NULL) && (mUfsHcPlatform->Callback != NULL)) { + Status = mUfsHcPlatform->Callback (Private->Handle, EdkiiUfsHcPostLinkStartup, &Private->UfsHcDriverInterface); + if (EFI_ERROR (Status)) { + DEBUG ( + (DEBUG_ERROR, + "Failure from platform driver during EdkiiUfsHcPostLinkStartup, Status = %r\n", + Status) + ); + return Status; + } + } + // // UFS 2.0 spec Section 13.1.3.3: // At the end of the UFS Interconnect Layer initialization on both host and device side, diff --git a/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThruHci.c b/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThruHci.c index eba35cc669..4a9fa01e7d 100644 --- a/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThruHci.c +++ b/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThruHci.c @@ -2,7 +2,7 @@ UfsPassThruDxe driver is used to produce EFI_EXT_SCSI_PASS_THRU protocol interface for upper layer application to execute UFS-supported SCSI cmds. - Copyright (c) 2014 - 2019, Intel Corporation. All rights reserved.
+ Copyright (c) 2014 - 2022, Intel Corporation. All rights reserved.
Copyright (c) Microsoft Corporation.
SPDX-License-Identifier: BSD-2-Clause-Patent @@ -1970,14 +1970,6 @@ UfsDeviceDetection ( return EFI_DEVICE_ERROR; } } else { - if ((mUfsHcPlatform != NULL) && (mUfsHcPlatform->Callback != NULL)) { - Status = mUfsHcPlatform->Callback (Private->Handle, EdkiiUfsHcPostLinkStartup, &Private->UfsHcDriverInterface); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "Failure from platform driver during EdkiiUfsHcPostLinkStartup, Status = %r\n", Status)); - return Status; - } - } - return EFI_SUCCESS; } } diff --git a/MdeModulePkg/Include/Protocol/UfsHostControllerPlatform.h b/MdeModulePkg/Include/Protocol/UfsHostControllerPlatform.h index faa82d0c4e..32e9f6488c 100644 --- a/MdeModulePkg/Include/Protocol/UfsHostControllerPlatform.h +++ b/MdeModulePkg/Include/Protocol/UfsHostControllerPlatform.h @@ -1,7 +1,7 @@ /** @file EDKII_UFS_HC_PLATFORM_PROTOCOL definition. -Copyright (c) 2019, Intel Corporation. All rights reserved.
+Copyright (c) 2019 - 2022, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent **/ @@ -11,7 +11,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include -#define EDKII_UFS_HC_PLATFORM_PROTOCOL_VERSION 1 +#define EDKII_UFS_HC_PLATFORM_PROTOCOL_VERSION 2 extern EFI_GUID gEdkiiUfsHcPlatformProtocolGuid; @@ -83,6 +83,13 @@ typedef enum { EdkiiUfsHcPostLinkStartup } EDKII_UFS_HC_PLATFORM_CALLBACK_PHASE; +typedef enum { + EdkiiUfsCardRefClkFreq19p2Mhz, + EdkiiUfsCardRefClkFreq26Mhz, + EdkiiUfsCardRefClkFreq38p4Mhz, + EdkiiUfsCardRefClkFreqObsolete +} EDKII_UFS_CARD_REF_CLK_FREQ_ATTRIBUTE; + /** Callback function for platform driver. @@ -118,6 +125,10 @@ struct _EDKII_UFS_HC_PLATFORM_PROTOCOL { /// for host controller. /// EDKII_UFS_HC_PLATFORM_CALLBACK Callback; + /// + /// Reference Clock Frequency Ufs Card Attribute that need to be set in this Ufs Host Environment. + /// + EDKII_UFS_CARD_REF_CLK_FREQ_ATTRIBUTE RefClkFreq; }; #endif -- 2.31.1.windows.1