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.38428.1614013384259809165 for ; Mon, 22 Feb 2021 09:03:04 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 192.55.52.43, mailfrom: purna.chandra.rao.bandaru@intel.com) IronPort-SDR: nN9qZsA0FDAIVxpHUOHKKOYDl6Zn5NpWphcyXDp1EW0pypB1VOUO6duMLiSS/H1kHqnjfqXye1 E58f7wiInwkA== X-IronPort-AV: E=McAfee;i="6000,8403,9903"; a="269452440" X-IronPort-AV: E=Sophos;i="5.81,197,1610438400"; d="scan'208";a="269452440" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Feb 2021 09:02:55 -0800 IronPort-SDR: 2mNeIEeNpPcr8In64osgK53QOgh6GPg6S5uLl5Tv+AazLgBESufh6x3oYH8RRCHn5Exvoc9Gr4 0uB+Z3pqGHaw== X-IronPort-AV: E=Sophos;i="5.81,197,1610438400"; d="scan'208";a="432152767" Received: from pbandaru-mobl1.gar.corp.intel.com ([10.213.95.147]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Feb 2021 09:02:53 -0800 From: Purna Chandra Rao Bandaru To: devel@edk2.groups.io Cc: Purna Chandra Rao Bandaru , Mateusz Albecki , Ray Ni , Hao A Wu Subject: [PATCH 2/3] MdeModulePkg/UfsPassThruDxe: Improve Error handling of Ufs Pass Thru driver Date: Mon, 22 Feb 2021 22:32:35 +0530 Message-Id: <20210222170236.6312-2-purna.chandra.rao.bandaru@intel.com> X-Mailer: git-send-email 2.16.2.windows.1 In-Reply-To: <20210222170236.6312-1-purna.chandra.rao.bandaru@intel.com> References: <20210222170236.6312-1-purna.chandra.rao.bandaru@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit https://bugzilla.tianocore.org/show_bug.cgi?id=3217 Add UFS host conctroller reset in the last retry of the Link start up to allow scope for recovery of the Link. Signed-off-by: Bandaru Cc: Mateusz Albecki Cc: Ray Ni Cc: Hao A Wu Change-Id: Iecc87be51c557ec07890e2d700d6912ddf16adbd --- MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThruHci.c | 45 +++++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThruHci.c b/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThruHci.c index 0b1030ab47..e1416696d4 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 - 2021, Intel Corporation. All rights reserved.
Copyright (c) Microsoft Corporation.
SPDX-License-Identifier: BSD-2-Clause-Patent @@ -1929,37 +1929,42 @@ UfsDeviceDetection ( // // Start UFS device detection. - // Try up to 3 times for establishing data link with device. + // Try up to 4 times for establishing data link with device. // - for (Retry = 0; Retry < 3; Retry++) { + for (Retry = 0; Retry < 4; Retry++) { LinkStartupCommand.Opcode = UfsUicDmeLinkStartup; LinkStartupCommand.Arg1 = 0; LinkStartupCommand.Arg2 = 0; LinkStartupCommand.Arg3 = 0; Status = UfsExecUicCommands (Private, &LinkStartupCommand); - if (EFI_ERROR (Status)) { - return EFI_DEVICE_ERROR; - } - - Status = UfsMmioRead32 (Private, UFS_HC_STATUS_OFFSET, &Data); - if (EFI_ERROR (Status)) { - return EFI_DEVICE_ERROR; - } - - if ((Data & UFS_HC_HCS_DP) == 0) { - Status = UfsWaitMemSet (Private, UFS_HC_IS_OFFSET, UFS_HC_IS_ULSS, UFS_HC_IS_ULSS, UFS_TIMEOUT); + if (!EFI_ERROR (Status)) { + Status = UfsMmioRead32 (Private, UFS_HC_STATUS_OFFSET, &Data); if (EFI_ERROR (Status)) { return EFI_DEVICE_ERROR; } - } else { - if (mUfsHcPlatform != NULL && mUfsHcPlatform->Callback != NULL) { - Status = mUfsHcPlatform->Callback (Private->Handle, EdkiiUfsHcPostLinkStartup, &Private->UfsHcDriverInterface); + + if ((Data & UFS_HC_HCS_DP) == 0) { + Status = UfsWaitMemSet (Private, UFS_HC_IS_OFFSET, UFS_HC_IS_ULSS, UFS_HC_IS_ULSS, UFS_TIMEOUT); if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "Failure from platform driver during EdkiiUfsHcPostLinkStartup, Status = %r\n", Status)); - return Status; + 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; + } + } + if (Retry == 2) { + Status = UfsEnableHostController (Private); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "UfsDeviceDetection: Enable Host Controller Fails, Status = %r\n", Status)); + return Status; } - return EFI_SUCCESS; } } -- 2.16.2.windows.1