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 <[email protected]>
Reviewed-by: Eran Moshe <[email protected]>
---
 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

Reply via email to