[PATCH v3] mmc: core: poll busy at HS clock if CMD6 errors in mmc_select_hs400
From: Athira Palliprath via B4 Relay
Date: Tue Dec 01 2026 - 03:19:31 EST
From: Athira Palliprath <palliprath@xxxxxxxxxxxx>
When switching from HS200 to HS in mmc_select_hs400(), some eMMC cards
immediately switch to 52 MHz HS timing upon receiving CMD6, causing the
host at 200 MHz to fail sampling the R1b response (-EILSEQ / -ETIMEDOUT)
and leaving the host stuck at 200 MHz HS200 while the card is in 52 MHz
HS mode.
To keep JEDEC JESD84-B51 ordering (send CMD6 first, then lower clock to
<= 52 MHz), pass retries = 0 to __mmc_switch() and, if it fails with
-EILSEQ or -ETIMEDOUT, switch the host to HS timing and 52 MHz first
before polling for busy completion at 52 MHz. Other error codes still
fail immediately. On this fallback path, read back EXT_CSD_HS_TIMING
via mmc_get_ext_csd() to confirm the card actually entered HS mode
before proceeding to EXT_CSD_DDR_BUS_WIDTH_8, avoiding an illegal mode
transition if a transient bus error dropped CMD6 at 200 MHz on a
compliant card.
Also temporarily set host->retune_crc_disable across the HS200->HS
__mmc_switch() and fallback mmc_poll_for_busy(). Since
mmc_select_hs400() runs right after HS200 tuning enables
host->can_retune, an expected -EILSEQ on CMD6 (or on a retried CMD13
while polling) would otherwise flag host->need_retune in
mmc_request_done(), triggering invalid tuning at 52 MHz HS timing on
resume/reset or leaving re-tuning pending after returning to HS400.
The retries parameter in __mmc_switch() was added in
commit 5e52a168be37 ("mmc: core: Add a retries parameter to __mmc_switch
function") specifically so callers where retrying CMD6 is harmful (such
as eMMC sanitize in commit 5b96247c68d8 ("mmc: core: Let eMMC sanitize
not retry in case of timeout/failure")) can pass 0 instead of
MMC_CMD_RETRIES. Passing 0 here trades off automatic retries if a
transient bus error corrupts the CMD6 request itself at 200 MHz, in
order to avoid retrying CMD6 at 200 MHz after the card has already
switched to 52 MHz.
Fixes: 649c6059d237 ("mmc: mmc: Fix HS switch failure in mmc_select_hs400()")
Signed-off-by: Athira Palliprath <palliprath@xxxxxxxxxxxx>
---
Changes in v3:
- On the fallback path (when HS200->HS CMD6 returns -EILSEQ or
-ETIMEDOUT), read back EXT_CSD_HS_TIMING via mmc_get_ext_csd() after
mmc_switch_status() to verify the card actually entered HS mode before
proceeding to EXT_CSD_DDR_BUS_WIDTH_8 (prevents an illegal switch if a
transient bus error dropped CMD6 at 200 MHz on a compliant card).
- Link to v2: https://lore.kernel.org/r/20261123-fix-hs400-clock-v2-1-ad3b935bd9f9@xxxxxxxxxxxx
Changes in v2:
- Temporarily set host->retune_crc_disable across the HS200->HS
__mmc_switch() and fallback mmc_poll_for_busy() so expected -EILSEQ
errors do not set host->need_retune (reported by Sashiko AI review).
- Link to v1: https://lore.kernel.org/r/20261120-fix-hs400-clock-v1-1-96522138aa3e@xxxxxxxxxxxx
---
drivers/mmc/core/mmc.c | 52 +++++++++++++++++++++++++++++++++++++++++---------
1 file changed, 43 insertions(+), 9 deletions(-)
diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c
index a02b04938..49d96425d 100644
--- a/drivers/mmc/core/mmc.c
+++ b/drivers/mmc/core/mmc.c
@@ -1181,8 +1181,9 @@ static int mmc_select_hs_ddr(struct mmc_card *card)
static int mmc_select_hs400(struct mmc_card *card)
{
struct mmc_host *host = card->host;
+ bool retune_crc_disable;
unsigned int max_dtr;
- int err = 0;
+ int err = 0, switch_err;
u8 val;
/*
@@ -1192,16 +1193,25 @@ static int mmc_select_hs400(struct mmc_card *card)
host->ios.bus_width == MMC_BUS_WIDTH_8))
return 0;
- /* Switch card to HS mode */
+ /*
+ * Switch card to HS mode.
+ * Temporarily suppress CRC-triggered re-tuning because non-compliant
+ * cards may switch to 52 MHz HS immediately on CMD6, causing an
+ * expected -EILSEQ at 200 MHz (or on a retried CMD13 while polling)
+ * that would otherwise set host->need_retune.
+ */
val = EXT_CSD_TIMING_HS;
- err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
- EXT_CSD_HS_TIMING, val,
- card->ext_csd.generic_cmd6_time, 0,
- false, true, MMC_CMD_RETRIES);
- if (err) {
+ retune_crc_disable = host->retune_crc_disable;
+ host->retune_crc_disable = true;
+ switch_err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
+ EXT_CSD_HS_TIMING, val,
+ card->ext_csd.generic_cmd6_time, 0,
+ false, true, 0);
+ if (switch_err && switch_err != -EILSEQ && switch_err != -ETIMEDOUT) {
+ host->retune_crc_disable = retune_crc_disable;
pr_err("%s: switch to high-speed from hs200 failed, err:%d\n",
- mmc_hostname(host), err);
- return err;
+ mmc_hostname(host), switch_err);
+ return switch_err;
}
/* Prepare host to downgrade to HS timing */
@@ -1215,10 +1225,34 @@ static int mmc_select_hs400(struct mmc_card *card)
max_dtr = card->ext_csd.hs_max_dtr;
mmc_set_clock(host, max_dtr);
+ if (switch_err)
+ err = mmc_poll_for_busy(card, card->ext_csd.generic_cmd6_time,
+ true, MMC_BUSY_CMD6);
+ host->retune_crc_disable = retune_crc_disable;
+ if (err) {
+ pr_err("%s: switch to high-speed from hs200 failed, err:%d\n",
+ mmc_hostname(host), err);
+ return err;
+ }
+
err = mmc_switch_status(card, true);
if (err)
goto out_err;
+ if (switch_err) {
+ u8 *ext_csd;
+
+ err = mmc_get_ext_csd(card, &ext_csd);
+ if (err)
+ goto out_err;
+
+ if ((ext_csd[EXT_CSD_HS_TIMING] & 0x0f) != EXT_CSD_TIMING_HS)
+ err = switch_err;
+ kfree(ext_csd);
+ if (err)
+ goto out_err;
+ }
+
if (host->ops->hs400_prepare_ddr)
host->ops->hs400_prepare_ddr(host);
---
base-commit: d2616724e01132376c78872b8324f38659af9f28
change-id: 20261120-fix-hs400-clock-99400fb042c0
Best regards,
--
Athira Palliprath <palliprath@xxxxxxxxxxxx>