public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Adrian Hunter <adrian.hunter@intel.com>
To: "Ulf Hansson" <ulf.hansson@linaro.org>,
	"Kornel Dulęba" <korneld@chromium.org>,
	"Radoslaw Biernacki" <biernacki@google.com>,
	"Gwendal Grignou" <gwendal@chromium.org>,
	"Asutosh Das" <quic_asutoshd@quicinc.com>
Cc: Chaotian Jing <chaotian.jing@mediatek.com>,
	Bhavya Kapoor <b-kapoor@ti.com>,
	Kamal Dasu <kamal.dasu@broadcom.com>,
	Al Cooper <alcooperx@gmail.com>, Haibo Chen <haibo.chen@nxp.com>,
	Shaik Sajida Bhanu <quic_c_sbhanu@quicinc.com>,
	Sai Krishna Potthuri <sai.krishna.potthuri@amd.com>,
	Victor Shih <victor.shih@genesyslogic.com.tw>,
	Ben Chuang <ben.chuang@genesyslogic.com.tw>,
	Thierry Reding <thierry.reding@gmail.com>,
	Aniruddha Tvs Rao <anrao@nvidia.com>,
	Chun-Hung Wu <chun-hung.wu@mediatek.com>,
	linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH V2 6/6] mmc: cqhci: Fix task clearing in CQE error recovery
Date: Fri,  3 Nov 2023 10:47:20 +0200	[thread overview]
Message-ID: <20231103084720.6886-7-adrian.hunter@intel.com> (raw)
In-Reply-To: <20231103084720.6886-1-adrian.hunter@intel.com>

If a task completion notification (TCN) is received when there is no
outstanding task, the cqhci driver issues a "spurious TCN" warning. This
was observed to happen right after CQE error recovery.

When an error interrupt is received the driver runs recovery logic.
It halts the controller, clears all pending tasks, and then re-enables
it. On some platforms, like Intel Jasper Lake, a stale task completion
event was observed, regardless of the CQHCI_CLEAR_ALL_TASKS bit being set.

This results in either:
a) Spurious TC completion event for an empty slot.
b) Corrupted data being passed up the stack, as a result of premature
   completion for a newly added task.

Rather than add a quirk for affected controllers, ensure tasks are cleared
by toggling CQHCI_ENABLE, which would happen anyway if
cqhci_clear_all_tasks() timed out. This is simpler and should be safe and
effective for all controllers.

Fixes: a4080225f51d ("mmc: cqhci: support for command queue enabled host")
Cc: stable@vger.kernel.org
Reported-by: Kornel Dulęba <korneld@chromium.org>
Tested-by: Kornel Dulęba <korneld@chromium.org>
Co-developed-by: Kornel Dulęba <korneld@chromium.org>
Signed-off-by: Kornel Dulęba <korneld@chromium.org>
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
 drivers/mmc/host/cqhci-core.c | 32 ++++++++++++++++----------------
 1 file changed, 16 insertions(+), 16 deletions(-)

diff --git a/drivers/mmc/host/cqhci-core.c b/drivers/mmc/host/cqhci-core.c
index 948799a0980c..41e94cd14109 100644
--- a/drivers/mmc/host/cqhci-core.c
+++ b/drivers/mmc/host/cqhci-core.c
@@ -1075,28 +1075,28 @@ static void cqhci_recovery_finish(struct mmc_host *mmc)
 
 	ok = cqhci_halt(mmc, CQHCI_FINISH_HALT_TIMEOUT);
 
-	if (!cqhci_clear_all_tasks(mmc, CQHCI_CLEAR_TIMEOUT))
-		ok = false;
-
 	/*
 	 * The specification contradicts itself, by saying that tasks cannot be
 	 * cleared if CQHCI does not halt, but if CQHCI does not halt, it should
 	 * be disabled/re-enabled, but not to disable before clearing tasks.
 	 * Have a go anyway.
 	 */
-	if (!ok) {
-		pr_debug("%s: cqhci: disable / re-enable\n", mmc_hostname(mmc));
-		cqcfg = cqhci_readl(cq_host, CQHCI_CFG);
-		cqcfg &= ~CQHCI_ENABLE;
-		cqhci_writel(cq_host, cqcfg, CQHCI_CFG);
-		cqcfg |= CQHCI_ENABLE;
-		cqhci_writel(cq_host, cqcfg, CQHCI_CFG);
-		/* Be sure that there are no tasks */
-		ok = cqhci_halt(mmc, CQHCI_FINISH_HALT_TIMEOUT);
-		if (!cqhci_clear_all_tasks(mmc, CQHCI_CLEAR_TIMEOUT))
-			ok = false;
-		WARN_ON(!ok);
-	}
+	if (!cqhci_clear_all_tasks(mmc, CQHCI_CLEAR_TIMEOUT))
+		ok = false;
+
+	/* Disable to make sure tasks really are cleared */
+	cqcfg = cqhci_readl(cq_host, CQHCI_CFG);
+	cqcfg &= ~CQHCI_ENABLE;
+	cqhci_writel(cq_host, cqcfg, CQHCI_CFG);
+
+	cqcfg = cqhci_readl(cq_host, CQHCI_CFG);
+	cqcfg |= CQHCI_ENABLE;
+	cqhci_writel(cq_host, cqcfg, CQHCI_CFG);
+
+	cqhci_halt(mmc, CQHCI_FINISH_HALT_TIMEOUT);
+
+	if (!ok)
+		cqhci_clear_all_tasks(mmc, CQHCI_CLEAR_TIMEOUT);
 
 	cqhci_recover_mrqs(cq_host);
 
-- 
2.34.1


  parent reply	other threads:[~2023-11-03  8:48 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-03  8:47 [PATCH V2 0/6] mmc: block: Fixes for CQE error recovery recovery Adrian Hunter
2023-11-03  8:47 ` [PATCH V2 1/6] mmc: block: Do not lose cache flush during CQE error recovery Adrian Hunter
2023-11-03 10:18   ` Avri Altman
2023-11-03  8:47 ` [PATCH V2 2/6] mmc: cqhci: Increase recovery halt timeout Adrian Hunter
2023-11-03 10:37   ` Avri Altman
2023-11-06  6:57     ` Adrian Hunter
2023-11-03  8:47 ` [PATCH V2 3/6] mmc: block: Be sure to wait while busy in CQE error recovery Adrian Hunter
2023-11-03 10:48   ` Avri Altman
2023-11-06  6:35     ` Adrian Hunter
2023-11-06  7:35   ` Avri Altman
2023-11-09  9:47   ` Christian Loehle
2023-11-03  8:47 ` [PATCH V2 4/6] mmc: block: Retry commands " Adrian Hunter
2023-11-06  7:37   ` Avri Altman
2023-11-03  8:47 ` [PATCH V2 5/6] mmc: cqhci: Warn of halt or task clear failure Adrian Hunter
2023-11-03 11:58   ` Avri Altman
2023-11-06  7:38   ` Avri Altman
2023-11-03  8:47 ` Adrian Hunter [this message]
2023-11-09  9:23   ` [PATCH V2 6/6] mmc: cqhci: Fix task clearing in CQE error recovery Avri Altman
2023-11-03 10:10 ` [PATCH V2 0/6] mmc: block: Fixes for CQE error recovery recovery Avri Altman
2023-11-06  6:38   ` Adrian Hunter
2023-11-15 15:51 ` Ulf Hansson

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=20231103084720.6886-7-adrian.hunter@intel.com \
    --to=adrian.hunter@intel.com \
    --cc=alcooperx@gmail.com \
    --cc=anrao@nvidia.com \
    --cc=b-kapoor@ti.com \
    --cc=ben.chuang@genesyslogic.com.tw \
    --cc=biernacki@google.com \
    --cc=chaotian.jing@mediatek.com \
    --cc=chun-hung.wu@mediatek.com \
    --cc=gwendal@chromium.org \
    --cc=haibo.chen@nxp.com \
    --cc=kamal.dasu@broadcom.com \
    --cc=korneld@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mmc@vger.kernel.org \
    --cc=quic_asutoshd@quicinc.com \
    --cc=quic_c_sbhanu@quicinc.com \
    --cc=sai.krishna.potthuri@amd.com \
    --cc=thierry.reding@gmail.com \
    --cc=ulf.hansson@linaro.org \
    --cc=victor.shih@genesyslogic.com.tw \
    /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