From 124aeeff837d20374ec00e292c31444b67b7a971 Mon Sep 17 00:00:00 2001 From: Yanir Levin Date: Thu, 22 Jan 2026 10:32:06 +0800 Subject: [PATCH] mmc: Fix retry logic in sd_get_capabilities 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. Signed-off-by: Yanir Levin Reviewed-by: Eran Moshe Signed-off-by: Peng Fan --- drivers/mmc/mmc.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c index 71664173016..7dadff27abe 100644 --- a/drivers/mmc/mmc.c +++ b/drivers/mmc/mmc.c @@ -1382,6 +1382,7 @@ static int sd_get_capabilities(struct mmc *mmc) ALLOC_CACHE_ALIGN_BUFFER(__be32, switch_status, 16); struct mmc_data data; int timeout; + uint retries = 3; mmc->card_caps = MMC_MODE_1BIT | MMC_CAP(MMC_LEGACY); @@ -1389,25 +1390,26 @@ 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; + 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); + err = mmc_send_cmd(mmc, &cmd, NULL); + if (err) + continue; - if (err) - return err; + cmd.cmdidx = SD_CMD_APP_SEND_SCR; + cmd.resp_type = MMC_RSP_R1; + cmd.cmdarg = 0; - 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; - data.dest = (char *)scr; - data.blocksize = 8; - data.blocks = 1; - data.flags = MMC_DATA_READ; - - err = mmc_send_cmd_retry(mmc, &cmd, &data, 3); + err = mmc_send_cmd(mmc, &cmd, &data); + } while (err && retries--); if (err) return err;