mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Adrian Hunter <adrian.hunter@intel.com>
To: <palliprath@chromium.org>,
	Asutosh Das <quic_asutoshd@quicinc.com>,
	"Ritesh Harjani" <ritesh.list@gmail.com>,
	Ulf Hansson <ulfh@kernel.org>
Cc: <linux-mmc@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 2/2] mmc: cqe: Reset card on finish halt/clear failure and before final retry
Date: Fri, 4 Dec 2026 14:02:01 +0200	[thread overview]
Message-ID: <eae1e3b9-ae05-42d0-b42a-030a6d9242d9@intel.com> (raw)
In-Reply-To: <20261201-cqe-recovery-fix-v1-2-404b8d26fdcc@chromium.org>

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


      reply	other threads:[~2026-12-04 12:29 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=eae1e3b9-ae05-42d0-b42a-030a6d9242d9@intel.com \
    --to=adrian.hunter@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mmc@vger.kernel.org \
    --cc=palliprath@chromium.org \
    --cc=quic_asutoshd@quicinc.com \
    --cc=ritesh.list@gmail.com \
    --cc=ulfh@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®