[PATCH] mmc: Fix retry logic in sd_get_capabilities

Yanir Levin yanir.levin at tandemg.com
Tue Jan 13 09:06:33 CET 2026


Hi Peng,
I did meet an issue with specific HW.
With this specific HW, we had SDHCI for interfacing with MMC.
On initialization, the first SD_CMD_APP_SEND_SCR command failed with a CRC error, indicated by SDHCI, probably related to HW issue or HW initialization issue.
After the first CRC error, no errors occurred anymore and everything worked fine.

The fix in this patch is for the retry mechanism, which is relevant only if an error occurs in the first place, not for the initial CRC error.

The issue with the retry mechanism for SD_CMD_APP_SEND_SCR is that it didn't take into account that both {MMC_CMD_APP_CMD, SD_CMD_APP_SEND_SCR} have to be sent in sequence on retry attempts.
So with the existing implementation the MMC didn't interpret SD_CMD_APP_SEND_SCR as application specific command in the retry attempts.

Thanks,
Yanir Levin
________________________________
From: Peng Fan <peng.fan at oss.nxp.com>
Sent: 13 January 2026 09:54
To: Yanir Levin <yanir.levin at tandemg.com>
Cc: u-boot at lists.denx.de <u-boot at lists.denx.de>; peng.fan at nxp.com <peng.fan at nxp.com>; jh80.chung at samsung.com <jh80.chung at samsung.com>; Eran Moshe <emoshe at gsitechnology.com>
Subject: Re: [PATCH] mmc: Fix retry logic in sd_get_capabilities

Hi Yanir,

On Sun, Jan 11, 2026 at 08:21:13AM +0000, Yanir Levin wrote:
>In sd_get_capabilities an ACMD is sent (SD_CMD_APP_SEND_SCR),
>which requires sending APP_CMD (MMC_CMD_APP_CMD) before.
>
>Currently, the ACMD is retried on error, however APP_CMD isn't.
>In this case, when the ACMD fails and it is tried again,
>the retry attempts will not be handled as ACMD, which is wrong.
>
>The fix performs the retry attempts on the sequence of
>APP_CMD and the ACMD together.

Did you meet any issues, or is this just code inspection?

Thanks,
Peng

>
>Signed-off-by: Yanir Levin <yanir.levin at tandemg.com>
>Reviewed-by: Eran Moshe <emoshe at gsitechnology.com>
>---
> drivers/mmc/mmc.c | 41 ++++++++++++++++++++++-------------------
> 1 file changed, 22 insertions(+), 19 deletions(-)
>
>diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c
>index bf82c515600..c1146ab3648 100644
>--- a/drivers/mmc/mmc.c
>+++ b/drivers/mmc/mmc.c
>@@ -1389,25 +1389,28 @@ static int sd_get_capabilities(struct mmc *mmc)
>                return 0;
>
>        /* Read the SCR to find out if this card supports higher speeds */
>-       cmd.cmdidx = MMC_CMD_APP_CMD;
>-       cmd.resp_type = MMC_RSP_R1;
>-       cmd.cmdarg = mmc->rca << 16;
>-
>-       err = mmc_send_cmd(mmc, &cmd, NULL);
>-
>-       if (err)
>-               return err;
>-
>-       cmd.cmdidx = SD_CMD_APP_SEND_SCR;
>-       cmd.resp_type = MMC_RSP_R1;
>-       cmd.cmdarg = 0;
>-
>-       data.dest = (char *)scr;
>-       data.blocksize = 8;
>-       data.blocks = 1;
>-       data.flags = MMC_DATA_READ;
>-
>-       err = mmc_send_cmd_retry(mmc, &cmd, &data, 3);
>+       uint retries = 3;
>+       do {
>+               cmd.cmdidx = MMC_CMD_APP_CMD;
>+               cmd.resp_type = MMC_RSP_R1;
>+               cmd.cmdarg = mmc->rca << 16;
>+
>+               err = mmc_send_cmd(mmc, &cmd, NULL);
>+
>+               if (err)
>+                       continue;
>+
>+               cmd.cmdidx = SD_CMD_APP_SEND_SCR;
>+               cmd.resp_type = MMC_RSP_R1;
>+               cmd.cmdarg = 0;
>+
>+               data.dest = (char *)scr;
>+               data.blocksize = 8;
>+               data.blocks = 1;
>+               data.flags = MMC_DATA_READ;
>+
>+               err = mmc_send_cmd(mmc, &cmd, &data);
>+       } while (err && retries--);
>
>        if (err)
>                return err;
>--
>2.43.0
>
>


More information about the U-Boot mailing list