From 082143189f28fe0343fb8f2d96b704c61fcfd00b Mon Sep 17 00:00:00 2001 From: NishanthSanjeevi Date: Wed, 19 Nov 2025 13:21:39 +0530 Subject: [PATCH 1/2] Fix retry in UFS device detection APIs --- MdeModulePkg/Bus/Ufs/UfsBlockIoPei/UfsHci.c | 6 ++++-- MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThruHci.c | 9 ++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/MdeModulePkg/Bus/Ufs/UfsBlockIoPei/UfsHci.c b/MdeModulePkg/Bus/Ufs/UfsBlockIoPei/UfsHci.c index f1f69d09f48..8a45abf0203 100644 --- a/MdeModulePkg/Bus/Ufs/UfsBlockIoPei/UfsHci.c +++ b/MdeModulePkg/Bus/Ufs/UfsBlockIoPei/UfsHci.c @@ -1555,7 +1555,8 @@ UfsDeviceDetection ( for (Retry = 0; Retry < 3; Retry++) { Status = UfsExecUicCommands (Private, UfsUicDmeLinkStartup, 0, 0, 0); if (EFI_ERROR (Status)) { - return EFI_DEVICE_ERROR; + DEBUG ((DEBUG_ERROR, "[%a] UfsExecUicCommands failed with Status=%r\n", __func__, Status)); + continue; } // @@ -1567,7 +1568,8 @@ UfsDeviceDetection ( Address = Private->UfsHcBase + UFS_HC_IS_OFFSET; Status = UfsWaitMemSet (Address, UFS_HC_IS_ULSS, UFS_HC_IS_ULSS, UFS_TIMEOUT); if (EFI_ERROR (Status)) { - return EFI_DEVICE_ERROR; + DEBUG ((DEBUG_ERROR, "[%a] UfsWaitMemSet failed with Status=%r\n", __func__, Status)); + continue; } } else { DEBUG ((DEBUG_INFO, "UfsblockioPei: found a attached UFS device\n")); diff --git a/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThruHci.c b/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThruHci.c index 820b089cb57..f0804b53d87 100644 --- a/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThruHci.c +++ b/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThruHci.c @@ -1957,18 +1957,21 @@ UfsDeviceDetection ( LinkStartupCommand.Arg3 = 0; Status = UfsExecUicCommands (Private, &LinkStartupCommand); if (EFI_ERROR (Status)) { - return EFI_DEVICE_ERROR; + DEBUG ((DEBUG_ERROR, "[%a] UfsExecUicCommands failed with Status=%r\n", __func__, Status)); + continue; } Status = UfsMmioRead32 (Private, UFS_HC_STATUS_OFFSET, &Data); if (EFI_ERROR (Status)) { - return EFI_DEVICE_ERROR; + DEBUG ((DEBUG_ERROR, "[%a] UfsMmioRead32 failed with Status=%r\n", __func__, Status)); + continue; } 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)) { - return EFI_DEVICE_ERROR; + DEBUG ((DEBUG_ERROR, "[%a] UfsWaitMemSet failed with Status=%r\n", __func__, Status)); + continue; } } else { return EFI_SUCCESS; From 7fb444ad1417e61f08dc7f604fa3d59e8be73db2 Mon Sep 17 00:00:00 2001 From: NishanthSanjeevi Date: Wed, 19 Nov 2025 23:59:24 +0530 Subject: [PATCH 2/2] Add MU_CHANGE tags --- MdeModulePkg/Bus/Ufs/UfsBlockIoPei/UfsHci.c | 2 ++ MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThruHci.c | 2 ++ 2 files changed, 4 insertions(+) diff --git a/MdeModulePkg/Bus/Ufs/UfsBlockIoPei/UfsHci.c b/MdeModulePkg/Bus/Ufs/UfsBlockIoPei/UfsHci.c index 8a45abf0203..dce26fa7ded 100644 --- a/MdeModulePkg/Bus/Ufs/UfsBlockIoPei/UfsHci.c +++ b/MdeModulePkg/Bus/Ufs/UfsBlockIoPei/UfsHci.c @@ -1552,6 +1552,7 @@ UfsDeviceDetection ( // Start UFS device detection. // Try up to 3 times for establishing data link with device. // + // MU_CHANGE [BEGIN] - Fix UFS device detection retry logic for (Retry = 0; Retry < 3; Retry++) { Status = UfsExecUicCommands (Private, UfsUicDmeLinkStartup, 0, 0, 0); if (EFI_ERROR (Status)) { @@ -1576,6 +1577,7 @@ UfsDeviceDetection ( return EFI_SUCCESS; } } + // MU_CHANGE [END] - Fix UFS device detection retry logic return EFI_NOT_FOUND; } diff --git a/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThruHci.c b/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThruHci.c index f0804b53d87..6fe16a413cc 100644 --- a/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThruHci.c +++ b/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThruHci.c @@ -1950,6 +1950,7 @@ UfsDeviceDetection ( // Start UFS device detection. // Try up to 3 times for establishing data link with device. // + // MU_CHANGE [BEGIN] - Fix UFS device detection retry logic for (Retry = 0; Retry < 3; Retry++) { LinkStartupCommand.Opcode = UfsUicDmeLinkStartup; LinkStartupCommand.Arg1 = 0; @@ -1977,6 +1978,7 @@ UfsDeviceDetection ( return EFI_SUCCESS; } } + // MU_CHANGE [END] - Fix UFS device detection retry logic return EFI_NOT_FOUND; }