From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga02.intel.com (mga02.intel.com []) by mx.groups.io with SMTP id smtpd.web12.10586.1579003565254711279 for ; Tue, 14 Jan 2020 04:06:06 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=fail (domain: intel.com, ip: , mailfrom: mateusz.albecki@intel.com) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 14 Jan 2020 04:06:06 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,432,1571727600"; d="scan'208";a="248028979" Received: from gklab-27-32.ger.corp.intel.com ([10.102.28.45]) by fmsmga004.fm.intel.com with ESMTP; 14 Jan 2020 04:06:04 -0800 From: "Albecki, Mateusz" To: devel@edk2.groups.io Cc: Mateusz Albecki , Hao A Wu , Marcin Wojtas , Zhichao Gao , Liming Gao Subject: [PATCHv2 3/4] MdeModulePkg/SdMmcPciHcDxe: Add retries for sync commands Date: Tue, 14 Jan 2020 13:05:29 +0100 Message-Id: <20200114120530.1660-4-mateusz.albecki@intel.com> X-Mailer: git-send-email 2.14.1.windows.1 In-Reply-To: <20200114120530.1660-1-mateusz.albecki@intel.com> References: <20200114120530.1660-1-mateusz.albecki@intel.com> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1140 To increase the resiliency driver will now attempt to retry the commands that failed due to the CRC error up to 5 times. This should address the problems with the commands that fail due to random condition on links. This should also help the boards on which CMD13 is particularly unstable after switching the link frequency. Cc: Hao A Wu Cc: Marcin Wojtas Cc: Zhichao Gao Cc: Liming Gao Signed-off-by: Mateusz Albecki --- MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.c | 83 ++++++++++++++-------- MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.h | 5 +- MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c | 1 + 3 files changed, 59 insertions(+), 30 deletions(-) diff --git a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.c b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.c index 373f1bed45..193b0f24e2 100644 --- a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.c +++ b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.c @@ -7,7 +7,7 @@ It would expose EFI_SD_MMC_PASS_THRU_PROTOCOL for upper layer use. Copyright (c) 2018-2019, NVIDIA CORPORATION. All rights reserved. - Copyright (c) 2015 - 2019, Intel Corporation. All rights reserved.
+ Copyright (c) 2015 - 2020, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent **/ @@ -974,6 +974,58 @@ SdMmcPciHcDriverBindingStop ( return Status; } +/** + Execute TRB synchronously. + + @param[in] Private Pointer to driver private data. + @param[in] Trb Pointer to TRB to execute. + + @retval EFI_SUCCESS TRB executed successfully. + @retval Other TRB failed. +**/ +EFI_STATUS +SdMmcPassThruExecSyncTrb ( + IN SD_MMC_HC_PRIVATE_DATA *Private, + IN SD_MMC_HC_TRB *Trb + ) +{ + EFI_STATUS Status; + EFI_TPL OldTpl; + + // + // Wait async I/O list is empty before execute sync I/O operation. + // + while (TRUE) { + OldTpl = gBS->RaiseTPL (TPL_NOTIFY); + if (IsListEmpty (&Private->Queue)) { + gBS->RestoreTPL (OldTpl); + break; + } + gBS->RestoreTPL (OldTpl); + } + + while (Trb->Retries) { + Status = SdMmcWaitTrbEnv (Private, Trb); + if (EFI_ERROR (Status)) { + return Status; + } + + Status = SdMmcExecTrb (Private, Trb); + if (EFI_ERROR (Status)) { + return Status; + } + + Status = SdMmcWaitTrbResult (Private, Trb); + if (Status == EFI_CRC_ERROR) { + Trb->Retries--; + } else { + return Status; + } + } + + return Status; +} + /** Sends SD command to an SD card that is attached to the SD controller. @@ -1023,7 +1075,6 @@ SdMmcPassThruPassThru ( EFI_STATUS Status; SD_MMC_HC_PRIVATE_DATA *Private; SD_MMC_HC_TRB *Trb; - EFI_TPL OldTpl; if ((This == NULL) || (Packet == NULL)) { return EFI_INVALID_PARAMETER; @@ -1066,34 +1117,8 @@ SdMmcPassThruPassThru ( return EFI_SUCCESS; } - // - // Wait async I/O list is empty before execute sync I/O operation. - // - while (TRUE) { - OldTpl = gBS->RaiseTPL (TPL_NOTIFY); - if (IsListEmpty (&Private->Queue)) { - gBS->RestoreTPL (OldTpl); - break; - } - gBS->RestoreTPL (OldTpl); - } - - Status = SdMmcWaitTrbEnv (Private, Trb); - if (EFI_ERROR (Status)) { - goto Done; - } - - Status = SdMmcExecTrb (Private, Trb); - if (EFI_ERROR (Status)) { - goto Done; - } + Status = SdMmcPassThruExecSyncTrb (Private, Trb); - Status = SdMmcWaitTrbResult (Private, Trb); - if (EFI_ERROR (Status)) { - goto Done; - } - -Done: SdMmcFreeTrb (Trb); return Status; diff --git a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.h b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.h index 0304960132..5bc3577ba2 100644 --- a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.h +++ b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.h @@ -3,7 +3,7 @@ Provides some data structure definitions used by the SD/MMC host controller driver. Copyright (c) 2018-2019, NVIDIA CORPORATION. All rights reserved. -Copyright (c) 2015, Intel Corporation. All rights reserved.
+Copyright (c) 2015 - 2020, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent **/ @@ -130,6 +130,8 @@ typedef struct { #define SD_MMC_HC_TRB_SIG SIGNATURE_32 ('T', 'R', 'B', 'T') +#define SD_MMC_TRB_RETRIES 5 + // // TRB (Transfer Request Block) contains information for the cmd request. // @@ -152,6 +154,7 @@ typedef struct { EFI_EVENT Event; BOOLEAN Started; UINT64 Timeout; + UINT32 Retries; SD_MMC_HC_ADMA_32_DESC_LINE *Adma32Desc; SD_MMC_HC_ADMA_64_V3_DESC_LINE *Adma64V3Desc; diff --git a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c index 637455b400..b0384a507a 100644 --- a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c +++ b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c @@ -1683,6 +1683,7 @@ SdMmcCreateTrb ( Trb->Event = Event; Trb->Started = FALSE; Trb->Timeout = Packet->Timeout; + Trb->Retries = SD_MMC_TRB_RETRIES; Trb->Private = Private; if ((Packet->InTransferLength != 0) && (Packet->InDataBuffer != NULL)) { -- 2.14.1.windows.1 -------------------------------------------------------------------- Intel Technology Poland sp. z o.o. ul. Slowackiego 173 | 80-298 Gdansk | Sad Rejonowy Gdansk Polnoc | VII Wydzial Gospodarczy Krajowego Rejestru Sadowego - KRS 101882 | NIP 957-07-52-316 | Kapital zakladowy 200.000 PLN. Ta wiadomosc wraz z zalacznikami jest przeznaczona dla okreslonego adresata i moze zawierac informacje poufne. W razie przypadkowego otrzymania tej wiadomosci, prosimy o powiadomienie nadawcy oraz trwale jej usuniecie; jakiekolwiek przegladanie lub rozpowszechnianie jest zabronione. This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). If you are not the intended recipient, please contact the sender and delete all copies; any review or distribution by others is strictly prohibited.