[PATCH 2/2] mmc: cqe: Reset card on finish halt/clear failure and before final retry
From: Athira Palliprath via B4 Relay
Date: Tue Dec 01 2026 - 12:20:26 EST
From: Athira Palliprath <palliprath@xxxxxxxxxxxx>
Two gaps in the eMMC CQE recovery path allow failing requests to exhaust
all retries and fail with BLK_STS_IOERR without ever attempting a card
hardware reset:
1. cqhci_recovery_finish() returns void and discards failures from
cqhci_halt() ("Failed to halt") and cqhci_clear_all_tasks() ("Failed
to clear tasks") after CMD12/CMD48 and the CQHCI enable toggle. If
CMD48 succeeds, mmc_cqe_recovery() returns 0 and
mmc_blk_cqe_recovery() skips mmc_blk_reset(), leaving CQHCI wedged.
2. Unlike non-CQE mmc_blk_mq_rw_recovery(), which explicitly performs
mmc_blk_reset() before the final retry, CQE retries MMC_CQE_RETRIES
times and ends the request with BLK_STS_IOERR without ever calling
mmc_hw_reset() as long as CMD48 (which ignores CRC) succeeds.
Change struct mmc_cqe_ops::cqe_recovery_finish() to return int so
cqhci_recovery_finish() propagates -EIO to mmc_cqe_recovery() when its
final halt or task-clear fails, and mark mq->cqe_recovery_reset in
mmc_blk_cqe_complete_rq() when a failing request is requeued for its
final retry so mmc_blk_cqe_recovery() executes mmc_blk_reset() before
dispatching the last attempt.
Signed-off-by: Athira Palliprath <palliprath@xxxxxxxxxxxx>
---
drivers/mmc/core/block.c | 6 +++++-
drivers/mmc/core/core.c | 9 ++++++---
drivers/mmc/core/queue.h | 1 +
drivers/mmc/host/cqhci-core.c | 12 ++++++++----
drivers/mmc/host/mmc_hsq.c | 4 +++-
include/linux/mmc/host.h | 2 +-
6 files changed, 24 insertions(+), 10 deletions(-)
diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c
index a02bb2fee..417ebff9e 100644
--- a/drivers/mmc/core/block.c
+++ b/drivers/mmc/core/block.c
@@ -1545,6 +1545,8 @@ static void mmc_blk_cqe_complete_rq(struct mmc_queue *mq, struct request *req)
if (err) {
if (mqrq->retries++ < MMC_CQE_RETRIES) {
mqrq->flags |= MQRQ_XFER_SINGLE_BLOCK;
+ if (mq->in_recovery && mqrq->retries == MMC_CQE_RETRIES)
+ mq->cqe_recovery_reset = true;
blk_mq_requeue_request(req, true);
} else {
blk_mq_end_request(req, BLK_STS_IOERR);
@@ -1585,9 +1587,11 @@ void mmc_blk_cqe_recovery(struct mmc_queue *mq)
pr_debug("%s: CQE recovery start\n", mmc_hostname(host));
+ mq->cqe_recovery_reset = false;
err = mmc_cqe_recovery(host);
- if (err)
+ if (err || mq->cqe_recovery_reset)
mmc_blk_reset(mq->blkdata, host, MMC_BLK_CQE_RECOVERY);
+ mq->cqe_recovery_reset = false;
mmc_blk_reset_success(mq->blkdata, MMC_BLK_CQE_RECOVERY);
pr_debug("%s: CQE recovery done\n", mmc_hostname(host));
diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
index 677e445dc..11a1f486b 100644
--- a/drivers/mmc/core/core.c
+++ b/drivers/mmc/core/core.c
@@ -538,12 +538,12 @@ EXPORT_SYMBOL(mmc_cqe_post_req);
* Recovery consists of stopping CQE, stopping eMMC, discarding the queue
* in eMMC, and discarding the queue in CQE. CQE must call
* mmc_cqe_request_done() on all requests. An error is returned if the eMMC
- * fails to discard its queue.
+ * fails to discard its queue or CQE fails to finish recovery.
*/
int mmc_cqe_recovery(struct mmc_host *host)
{
struct mmc_command cmd;
- int err;
+ int err, ret;
mmc_retune_hold_now(host);
@@ -570,11 +570,14 @@ int mmc_cqe_recovery(struct mmc_host *host)
cmd.busy_timeout = MMC_CQE_RECOVERY_TIMEOUT;
err = mmc_wait_for_cmd(host, &cmd, MMC_CMD_RETRIES);
- host->cqe_ops->cqe_recovery_finish(host);
+ ret = host->cqe_ops->cqe_recovery_finish(host);
if (err)
err = mmc_wait_for_cmd(host, &cmd, MMC_CMD_RETRIES);
+ if (!err)
+ err = ret;
+
mmc_retune_release(host);
return err;
diff --git a/drivers/mmc/core/queue.h b/drivers/mmc/core/queue.h
index dd7211e3a..2154ff21f 100644
--- a/drivers/mmc/core/queue.h
+++ b/drivers/mmc/core/queue.h
@@ -87,6 +87,7 @@ struct mmc_queue {
bool busy;
bool recovery_needed;
bool in_recovery;
+ bool cqe_recovery_reset;
bool rw_wait;
bool waiting;
struct work_struct recovery_work;
diff --git a/drivers/mmc/host/cqhci-core.c b/drivers/mmc/host/cqhci-core.c
index 69b125c1e..723cc39fd 100644
--- a/drivers/mmc/host/cqhci-core.c
+++ b/drivers/mmc/host/cqhci-core.c
@@ -1079,12 +1079,13 @@ static void cqhci_recover_mrqs(struct cqhci_host *cq_host)
/* CQHCI could be expected to clear it's internal state pretty quickly */
#define CQHCI_CLEAR_TIMEOUT 20
-static void cqhci_recovery_finish(struct mmc_host *mmc)
+static int cqhci_recovery_finish(struct mmc_host *mmc)
{
struct cqhci_host *cq_host = mmc->cqe_private;
unsigned long flags;
u32 cqcfg;
bool ok;
+ int ret = 0;
pr_debug("%s: cqhci: %s\n", mmc_hostname(mmc), __func__);
@@ -1110,10 +1111,11 @@ static void cqhci_recovery_finish(struct mmc_host *mmc)
cqcfg |= CQHCI_ENABLE;
cqhci_writel(cq_host, cqcfg, CQHCI_CFG);
- cqhci_halt(mmc, CQHCI_FINISH_HALT_TIMEOUT);
+ if (!cqhci_halt(mmc, CQHCI_FINISH_HALT_TIMEOUT))
+ ret = -EIO;
- if (!ok)
- cqhci_clear_all_tasks(mmc, CQHCI_CLEAR_TIMEOUT);
+ if (!ok && !cqhci_clear_all_tasks(mmc, CQHCI_CLEAR_TIMEOUT))
+ ret = -EIO;
cqhci_recover_mrqs(cq_host);
@@ -1133,6 +1135,8 @@ static void cqhci_recovery_finish(struct mmc_host *mmc)
cqhci_set_irqs(cq_host, CQHCI_IS_MASK);
pr_debug("%s: cqhci: recovery done\n", mmc_hostname(mmc));
+
+ return ret;
}
static const struct mmc_cqe_ops cqhci_cqe_ops = {
diff --git a/drivers/mmc/host/mmc_hsq.c b/drivers/mmc/host/mmc_hsq.c
index 57e172bd3..3e99317f7 100644
--- a/drivers/mmc/host/mmc_hsq.c
+++ b/drivers/mmc/host/mmc_hsq.c
@@ -190,7 +190,7 @@ static void mmc_hsq_recovery_start(struct mmc_host *mmc)
spin_unlock_irqrestore(&hsq->lock, flags);
}
-static void mmc_hsq_recovery_finish(struct mmc_host *mmc)
+static int mmc_hsq_recovery_finish(struct mmc_host *mmc)
{
struct mmc_hsq *hsq = mmc->cqe_private;
int remains;
@@ -208,6 +208,8 @@ static void mmc_hsq_recovery_finish(struct mmc_host *mmc)
*/
if (remains > 0)
mmc_hsq_pump_requests(hsq);
+
+ return 0;
}
static int mmc_hsq_request(struct mmc_host *mmc, struct mmc_request *mrq)
diff --git a/include/linux/mmc/host.h b/include/linux/mmc/host.h
index 032c01865..a744aa237 100644
--- a/include/linux/mmc/host.h
+++ b/include/linux/mmc/host.h
@@ -316,7 +316,7 @@ struct mmc_cqe_ops {
* (data->error or cmd->error for DCMD). Requests that did not error
* will have zero data bytes transferred.
*/
- void (*cqe_recovery_finish)(struct mmc_host *host);
+ int (*cqe_recovery_finish)(struct mmc_host *host);
};
/**
--
2.56.1.839.g22a8290db9-goog