mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/2] mmc: cqe: Improve CQHCI error logging and recovery reset handling
@ 2026-12-01 17:20 Athira Palliprath via B4 Relay
  2026-12-01 17:20 ` [PATCH 1/2] mmc: cqhci: Log error IRQ details and card R1 status on recovery Athira Palliprath via B4 Relay
  2026-12-01 17:20 ` [PATCH 2/2] mmc: cqe: Reset card on finish halt/clear failure and before final retry Athira Palliprath via B4 Relay
  0 siblings, 2 replies; 5+ messages in thread
From: Athira Palliprath via B4 Relay @ 2026-12-01 17:20 UTC (permalink / raw)
  To: Adrian Hunter, Asutosh Das, Ritesh Harjani, Ulf Hansson
  Cc: linux-mmc, linux-kernel, Athira Palliprath

This 2-patch series addresses two diagnostics and recovery gaps in the
eMMC CQE / CQHCI error handling path observed in field crash logs:

1. cqhci_error_irq() currently logs status/cmd_error/data_error/TERRI
   only at pr_debug() level and never reads CQHCI_CRI or CQHCI_CRA on
   Response Error Detected (RED), making bus CRC errors, host timeouts,
   and card NAND ECC errors indistinguishable in production logs.
2. cqhci_recovery_finish() discards failures from its final cqhci_halt()
   and cqhci_clear_all_tasks() calls, and unlike non-CQE recovery, CQE
   never performs mmc_blk_reset() before a failing request's final
   retry as long as CMD48 (which ignores CRC) succeeds.

Patch 1 logs the error IRQ details (plus CRI/CRA when CQHCI_IS_RED is
set) via pr_err_ratelimited() once per recovery trigger.

Patch 2 changes struct mmc_cqe_ops::cqe_recovery_finish() to return int
so final halt/task-clear failures propagate -EIO to mmc_cqe_recovery(),
and triggers mmc_blk_reset() before dispatching a failing request's
final CQE retry.

Signed-off-by: Athira Palliprath <palliprath@chromium.org>
---
Athira Palliprath (2):
      mmc: cqhci: Log error IRQ details and card R1 status on recovery
      mmc: cqe: Reset card on finish halt/clear failure and before final retry

 drivers/mmc/core/block.c      |  6 +++++-
 drivers/mmc/core/core.c       |  9 ++++++---
 drivers/mmc/core/queue.h      |  1 +
 drivers/mmc/host/cqhci-core.c | 25 +++++++++++++++++++++----
 drivers/mmc/host/mmc_hsq.c    |  4 +++-
 include/linux/mmc/host.h      |  2 +-
 6 files changed, 37 insertions(+), 10 deletions(-)
---
base-commit: d2616724e01132376c78872b8324f38659af9f28
change-id: 20261201-cqe-recovery-fix-bbd460447801

Best regards,
-- 
Athira Palliprath <palliprath@chromium.org>



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/2] mmc: cqhci: Log error IRQ details and card R1 status on recovery
  2026-12-01 17:20 [PATCH 0/2] mmc: cqe: Improve CQHCI error logging and recovery reset handling Athira Palliprath via B4 Relay
@ 2026-12-01 17:20 ` Athira Palliprath via B4 Relay
  2026-12-04 10:53   ` Adrian Hunter
  2026-12-01 17:20 ` [PATCH 2/2] mmc: cqe: Reset card on finish halt/clear failure and before final retry Athira Palliprath via B4 Relay
  1 sibling, 1 reply; 5+ messages in thread
From: Athira Palliprath via B4 Relay @ 2026-12-01 17:20 UTC (permalink / raw)
  To: Adrian Hunter, Asutosh Das, Ritesh Harjani, Ulf Hansson
  Cc: linux-mmc, linux-kernel, Athira Palliprath

From: Athira Palliprath <palliprath@chromium.org>

Currently cqhci_error_irq() only logs the error IRQ status, cmd_error,
data_error, and TERRI at pr_debug() level and never reads CQHCI_CRI or
CQHCI_CRA (the eMMC R1 card response status on Response Error Detected).
As a result, production kernel logs on CQE-enabled devices only record
"running CQE recovery" without indicating whether recovery was triggered
by an uncorrectable NAND ECC error (R1_CARD_ECC_FAILED), a bus CRC error
(-EILSEQ), or a host timeout (-ETIMEDOUT).

Log these error details via pr_err_ratelimited() once per recovery
trigger (after the recovery_halt guard and idle check so normal I/O and
in-progress recoveries emit zero extra messages), including CRI and CRA
when CQHCI_IS_RED is set.

Signed-off-by: Athira Palliprath <palliprath@chromium.org>
---
 drivers/mmc/host/cqhci-core.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/drivers/mmc/host/cqhci-core.c b/drivers/mmc/host/cqhci-core.c
index a466cd88b..69b125c1e 100644
--- a/drivers/mmc/host/cqhci-core.c
+++ b/drivers/mmc/host/cqhci-core.c
@@ -724,6 +724,19 @@ static void cqhci_error_irq(struct mmc_host *mmc, u32 status, int cmd_error,
 		goto out_unlock;
 	}
 
+	if (status & CQHCI_IS_RED) {
+		u32 cri = cqhci_readl(cq_host, CQHCI_CRI);
+		u32 cra = cqhci_readl(cq_host, CQHCI_CRA);
+
+		pr_err_ratelimited("%s: cqhci: error IRQ status: 0x%08x cmd error %d data error %d TERRI: 0x%08x CRI: 0x%08x CRA: 0x%08x\n",
+				   mmc_hostname(mmc), status, cmd_error,
+				   data_error, terri, cri, cra);
+	} else {
+		pr_err_ratelimited("%s: cqhci: error IRQ status: 0x%08x cmd error %d data error %d TERRI: 0x%08x\n",
+				   mmc_hostname(mmc), status, cmd_error,
+				   data_error, terri);
+	}
+
 	if (CQHCI_TERRI_C_VALID(terri)) {
 		tag = CQHCI_TERRI_C_TASK(terri);
 		slot = &cq_host->slot[tag];

-- 
2.56.1.839.g22a8290db9-goog



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 2/2] mmc: cqe: Reset card on finish halt/clear failure and before final retry
  2026-12-01 17:20 [PATCH 0/2] mmc: cqe: Improve CQHCI error logging and recovery reset handling Athira Palliprath via B4 Relay
  2026-12-01 17:20 ` [PATCH 1/2] mmc: cqhci: Log error IRQ details and card R1 status on recovery Athira Palliprath via B4 Relay
@ 2026-12-01 17:20 ` Athira Palliprath via B4 Relay
  2026-12-04 12:02   ` Adrian Hunter
  1 sibling, 1 reply; 5+ messages in thread
From: Athira Palliprath via B4 Relay @ 2026-12-01 17:20 UTC (permalink / raw)
  To: Adrian Hunter, Asutosh Das, Ritesh Harjani, Ulf Hansson
  Cc: linux-mmc, linux-kernel, Athira Palliprath

From: Athira Palliprath <palliprath@chromium.org>

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@chromium.org>
---
 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



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] mmc: cqhci: Log error IRQ details and card R1 status on recovery
  2026-12-01 17:20 ` [PATCH 1/2] mmc: cqhci: Log error IRQ details and card R1 status on recovery Athira Palliprath via B4 Relay
@ 2026-12-04 10:53   ` Adrian Hunter
  0 siblings, 0 replies; 5+ messages in thread
From: Adrian Hunter @ 2026-12-04 10:53 UTC (permalink / raw)
  To: palliprath, Asutosh Das, Ritesh Harjani, Ulf Hansson
  Cc: linux-mmc, linux-kernel

On 01/12/2026 19:20, Athira Palliprath via B4 Relay wrote:
> From: Athira Palliprath <palliprath@chromium.org>
> 
> Currently cqhci_error_irq() only logs the error IRQ status, cmd_error,
> data_error, and TERRI at pr_debug() level and never reads CQHCI_CRI or
> CQHCI_CRA (the eMMC R1 card response status on Response Error Detected).
> As a result, production kernel logs on CQE-enabled devices only record
> "running CQE recovery" without indicating whether recovery was triggered
> by an uncorrectable NAND ECC error (R1_CARD_ECC_FAILED), a bus CRC error
> (-EILSEQ), or a host timeout (-ETIMEDOUT).

What about making more use of mmc_debugfs_err_stats_inc() instead?

> 
> Log these error details via pr_err_ratelimited() once per recovery
> trigger (after the recovery_halt guard and idle check so normal I/O and
> in-progress recoveries emit zero extra messages), including CRI and CRA
> when CQHCI_IS_RED is set.
> 
> Signed-off-by: Athira Palliprath <palliprath@chromium.org>
> ---
>  drivers/mmc/host/cqhci-core.c | 13 +++++++++++++
>  1 file changed, 13 insertions(+)
> 
> diff --git a/drivers/mmc/host/cqhci-core.c b/drivers/mmc/host/cqhci-core.c
> index a466cd88b..69b125c1e 100644
> --- a/drivers/mmc/host/cqhci-core.c
> +++ b/drivers/mmc/host/cqhci-core.c
> @@ -724,6 +724,19 @@ static void cqhci_error_irq(struct mmc_host *mmc, u32 status, int cmd_error,
>  		goto out_unlock;
>  	}
>  
> +	if (status & CQHCI_IS_RED) {
> +		u32 cri = cqhci_readl(cq_host, CQHCI_CRI);
> +		u32 cra = cqhci_readl(cq_host, CQHCI_CRA);
> +
> +		pr_err_ratelimited("%s: cqhci: error IRQ status: 0x%08x cmd error %d data error %d TERRI: 0x%08x CRI: 0x%08x CRA: 0x%08x\n",
> +				   mmc_hostname(mmc), status, cmd_error,
> +				   data_error, terri, cri, cra);

Might just as well put cqhci_readl(cq_host, CQHCI_CRI) and
cqhci_readl(cq_host, CQHCI_CRA) into the arguments list.

Also, we probably don't need to optimize the error path,
so could have only this version of the print, and drop
the 'if'

And it feels a bit redundant to keep the pr_debug() as well.

> +	} else {
> +		pr_err_ratelimited("%s: cqhci: error IRQ status: 0x%08x cmd error %d data error %d TERRI: 0x%08x\n",
> +				   mmc_hostname(mmc), status, cmd_error,
> +				   data_error, terri);
> +	}
> +
>  	if (CQHCI_TERRI_C_VALID(terri)) {
>  		tag = CQHCI_TERRI_C_TASK(terri);
>  		slot = &cq_host->slot[tag];
> 


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/2] mmc: cqe: Reset card on finish halt/clear failure and before final retry
  2026-12-01 17:20 ` [PATCH 2/2] mmc: cqe: Reset card on finish halt/clear failure and before final retry Athira Palliprath via B4 Relay
@ 2026-12-04 12:02   ` Adrian Hunter
  0 siblings, 0 replies; 5+ messages in thread
From: Adrian Hunter @ 2026-12-04 12:02 UTC (permalink / raw)
  To: palliprath, Asutosh Das, Ritesh Harjani, Ulf Hansson
  Cc: linux-mmc, linux-kernel

On 01/12/2026 19:20, Athira Palliprath via B4 Relay wrote:
> From: Athira Palliprath <palliprath@chromium.org>
> 
> 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.

Should be 2 patches

> 
> 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@chromium.org>
> ---
>  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;

Is that necessary?

>  	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;

Rename 'ret' to 'finish_err'

>  
>  	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;

Skip this and return err ?: finish_err;

> +
>  	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;

The name is not very clear, how about
"cqe_recovery_reset_needed" or "cqe_reset_needed"

>  	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;

Prefer local declarations in descending order of line length
e.g.
	struct cqhci_host *cq_host = mmc->cqe_private;
	unsigned long flags;
+	int ret = 0;
	u32 cqcfg;
	bool ok;

>  
>  	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);
>  };
>  
>  /**
> 


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-12-04 12:29 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-01 17:20 [PATCH 0/2] mmc: cqe: Improve CQHCI error logging and recovery reset handling Athira Palliprath via B4 Relay
2026-12-01 17:20 ` [PATCH 1/2] mmc: cqhci: Log error IRQ details and card R1 status on recovery Athira Palliprath via B4 Relay
2026-12-04 10:53   ` Adrian Hunter
2026-12-01 17:20 ` [PATCH 2/2] mmc: cqe: Reset card on finish halt/clear failure and before final retry Athira Palliprath via B4 Relay
2026-12-04 12:02   ` Adrian Hunter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®