[PATCH 3/4] mmc: dw_mmc: absorb CMD11 timeout into the central watchdog

From: Shawn Lin

Date: Thu Aug 27 2026 - 13:03:12 EST


The voltage switch (CMD11) keeps its dedicated 500ms deadline, but it
is now just another arm of the central watchdog; cmd11_timer is
deleted. The synthesized payload is identical to what the command leg
watchdog produces (cmd_status = RTO plus EVENT_CMD_COMPLETE), so the
request state machine cannot tell the difference.

Behavior notes for review:

* The extra jiffy in the legacy '500ms + 1' arming was pure jiffies
rollover paranoia and disappears together with the jiffies math.
* Since patch 1 arms the regular command watch on every RESP_EXP
command -- including voltage switches -- the subsequent arm here
replaces it, as documented there. For a genuinely stuck CMD11 the
abort latency therefore becomes exactly 500ms instead of racing
min(cto_ms, 500ms) between two timers as before; the reported
error (-ETIMEDOUT either way) is unchanged.
* dw_mci_cmd_interrupt() already delivers the watched events under
irq_lock on any completion path, so the former out-of-lock
timer_delete() next to the VOLT_SWITCH branch simply goes away.

No functional change intended.

Signed-off-by: Shawn Lin <shawn.lin@xxxxxxxxxxxxxx>
---

drivers/mmc/host/dw_mmc.c | 30 ++++--------------------------
drivers/mmc/host/dw_mmc.h | 3 ---
2 files changed, 4 insertions(+), 29 deletions(-)

diff --git a/drivers/mmc/host/dw_mmc.c b/drivers/mmc/host/dw_mmc.c
index 31cf728..6852c05 100644
--- a/drivers/mmc/host/dw_mmc.c
+++ b/drivers/mmc/host/dw_mmc.c
@@ -1393,17 +1393,16 @@ static void dw_mci_start_request(struct dw_mci *host, struct mmc_command *cmd)
/*
* Databook says to fail after 2ms w/ no response, but evidence
* shows that sometimes the cmd11 interrupt takes over 130ms.
- * We'll set to 500ms, plus an extra jiffy just in case jiffies
- * is just about to roll over.
+ * We'll set to 500ms.
*
* We do this whole thing under spinlock and only if the
* command hasn't already completed (indicating the irq
* already ran so we don't want the timeout).
*/
spin_lock_irqsave(&host->irq_lock, irqflags);
- if (!test_bit(EVENT_CMD_COMPLETE, &host->pending_events))
- mod_timer(&host->cmd11_timer,
- jiffies + msecs_to_jiffies(500) + 1);
+ dw_mci_wd_arm(host, 500, DW_MCI_WD_CMD_EVENTS,
+ DW_MCI_WD_CMD_EVENTS,
+ BIT(STATE_SENDING_CMD11));
spin_unlock_irqrestore(&host->irq_lock, irqflags);
}

@@ -2784,15 +2783,9 @@ static irqreturn_t dw_mci_interrupt(int irq, void *dev_id)
mci_writel(host, RINTSTS, SDMMC_INT_VOLT_SWITCH);
pending &= ~SDMMC_INT_VOLT_SWITCH;

- /*
- * Hold the lock; we know cmd11_timer can't be kicked
- * off after the lock is released, so safe to delete.
- */
spin_lock(&host->irq_lock);
dw_mci_cmd_interrupt(host, pending);
spin_unlock(&host->irq_lock);
-
- timer_delete(&host->cmd11_timer);
}

if (pending & DW_MCI_CMD_ERROR_FLAGS) {
@@ -3112,20 +3105,6 @@ static void dw_mci_init_dma(struct dw_mci *host)
host->use_dma = TRANS_MODE_PIO;
}

-static void dw_mci_cmd11_timer(struct timer_list *t)
-{
- struct dw_mci *host = timer_container_of(host, t, cmd11_timer);
-
- if (host->state != STATE_SENDING_CMD11) {
- dev_warn(host->dev, "Unexpected CMD11 timeout\n");
- return;
- }
-
- host->cmd_status = SDMMC_INT_RTO;
- set_bit(EVENT_CMD_COMPLETE, &host->pending_events);
- queue_work(system_bh_wq, &host->bh_work);
-}
-
static int dw_mci_parse_dt(struct dw_mci *host)
{
struct device *dev = host->dev;
@@ -3275,7 +3254,6 @@ int dw_mci_probe(struct dw_mci *host)

hrtimer_setup(&host->wd_timer, dw_mci_watchdog_fn, CLOCK_MONOTONIC,
HRTIMER_MODE_REL);
- timer_setup(&host->cmd11_timer, dw_mci_cmd11_timer, 0);

spin_lock_init(&host->lock);
spin_lock_init(&host->irq_lock);
diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
index 7af2b45..7b70392 100644
--- a/drivers/mmc/host/dw_mmc.h
+++ b/drivers/mmc/host/dw_mmc.h
@@ -127,7 +127,6 @@ struct dw_mci_dma_slave {
* time so that the state machine can synthesize an error.
* @wd_events: pending_events bits still awaited by the armed watch.
* @wd_states: host->state values for which the armed watch is valid.
- * @cmd11_timer: Timer for SD3.0 voltage switch over scheme.
* @mmc: The mmc_host representing this dw_mci.
* @flags: Random state bits associated with the host.
* @ctype: Card type for this host.
@@ -242,8 +241,6 @@ struct dw_mci {
unsigned long wd_events;
unsigned long wd_states;

- struct timer_list cmd11_timer;
-
#ifdef CONFIG_FAULT_INJECTION
struct fault_attr fail_data_crc;
struct hrtimer fault_timer;
--
2.7.4