stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4 1/7] mmc: cqhci: Provide helper for resetting both SDHCI and CQHCI
       [not found] <20221026194209.3758834-1-briannorris@chromium.org>
@ 2022-10-26 19:42 ` Brian Norris
  2022-10-26 19:44   ` Florian Fainelli
  2022-10-26 19:42 ` [PATCH v4 2/7] mmc: sdhci-of-arasan: Fix SDHCI_RESET_ALL for CQHCI Brian Norris
  1 sibling, 1 reply; 3+ messages in thread
From: Brian Norris @ 2022-10-26 19:42 UTC (permalink / raw)
  To: Ulf Hansson
  Cc: Shawn Guo, linux-mmc, Adrian Hunter, Shawn Lin, Michal Simek,
	Sascha Hauer, Bjorn Andersson, Thierry Reding, linux-arm-msm,
	linux-arm-kernel, Broadcom internal kernel review list,
	Jonathan Hunter, Andy Gross, Pengutronix Kernel Team,
	linux-kernel, Konrad Dybcio, Al Cooper, Fabio Estevam,
	Florian Fainelli, NXP Linux Team, Haibo Chen,
	Sowjanya Komatineni, Brian Norris, stable

Several SDHCI drivers need to deactivate command queueing in their reset
hook (see sdhci_cqhci_reset() / sdhci-pci-core.c, for example), and
several more are coming.

Those reset implementations have some small subtleties (e.g., ordering
of initialization of SDHCI vs. CQHCI might leave us resetting with a
NULL ->cqe_private), and are often identical across different host
drivers.

We also don't want to force a dependency between SDHCI and CQHCI, or
vice versa; non-SDHCI drivers use CQHCI, and SDHCI drivers might support
command queueing through some other means.

So, implement a small helper, to avoid repeating the same mistakes in
different drivers. Simply stick it in a header, because it's so small it
doesn't deserve its own module right now, and inlining to each driver is
pretty reasonable.

This is marked for -stable, as it is an important prerequisite patch for
several SDHCI controller bugfixes that follow.

Cc: <stable@vger.kernel.org>
Signed-off-by: Brian Norris <briannorris@chromium.org>
Acked-by: Adrian Hunter <adrian.hunter@intel.com>
---

Changes in v4:
 - Whitespace fixup
 - Add Adrian's Ack

Changes in v3:
 - New in v3 (replacing a simple 'cqe_private == NULL' patch in v2)

 drivers/mmc/host/sdhci-cqhci.h | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
 create mode 100644 drivers/mmc/host/sdhci-cqhci.h

diff --git a/drivers/mmc/host/sdhci-cqhci.h b/drivers/mmc/host/sdhci-cqhci.h
new file mode 100644
index 000000000000..cf8e7ba71bbd
--- /dev/null
+++ b/drivers/mmc/host/sdhci-cqhci.h
@@ -0,0 +1,24 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright 2022 The Chromium OS Authors
+ *
+ * Support that applies to the combination of SDHCI and CQHCI, while not
+ * expressing a dependency between the two modules.
+ */
+
+#ifndef __MMC_HOST_SDHCI_CQHCI_H__
+#define __MMC_HOST_SDHCI_CQHCI_H__
+
+#include "cqhci.h"
+#include "sdhci.h"
+
+static inline void sdhci_and_cqhci_reset(struct sdhci_host *host, u8 mask)
+{
+	if ((host->mmc->caps2 & MMC_CAP2_CQE) && (mask & SDHCI_RESET_ALL) &&
+	    host->mmc->cqe_private)
+		cqhci_deactivate(host->mmc);
+
+	sdhci_reset(host, mask);
+}
+
+#endif /* __MMC_HOST_SDHCI_CQHCI_H__ */
-- 
2.38.0.135.g90850a2211-goog


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

* [PATCH v4 2/7] mmc: sdhci-of-arasan: Fix SDHCI_RESET_ALL for CQHCI
       [not found] <20221026194209.3758834-1-briannorris@chromium.org>
  2022-10-26 19:42 ` [PATCH v4 1/7] mmc: cqhci: Provide helper for resetting both SDHCI and CQHCI Brian Norris
@ 2022-10-26 19:42 ` Brian Norris
  1 sibling, 0 replies; 3+ messages in thread
From: Brian Norris @ 2022-10-26 19:42 UTC (permalink / raw)
  To: Ulf Hansson
  Cc: Shawn Guo, linux-mmc, Adrian Hunter, Shawn Lin, Michal Simek,
	Sascha Hauer, Bjorn Andersson, Thierry Reding, linux-arm-msm,
	linux-arm-kernel, Broadcom internal kernel review list,
	Jonathan Hunter, Andy Gross, Pengutronix Kernel Team,
	linux-kernel, Konrad Dybcio, Al Cooper, Fabio Estevam,
	Florian Fainelli, NXP Linux Team, Haibo Chen,
	Sowjanya Komatineni, Brian Norris, stable, Guenter Roeck

SDHCI_RESET_ALL resets will reset the hardware CQE state, but we aren't
tracking that properly in software. When out of sync, we may trigger
various timeouts.

It's not typical to perform resets while CQE is enabled, but one
particular case I hit commonly enough: mmc_suspend() -> mmc_power_off().
Typically we will eventually deactivate CQE (cqhci_suspend() ->
cqhci_deactivate()), but that's not guaranteed -- in particular, if
we perform a partial (e.g., interrupted) system suspend.

The same bug was already found and fixed for two other drivers, in v5.7
and v5.9:

  5cf583f1fb9c ("mmc: sdhci-msm: Deactivate CQE during SDHC reset")
  df57d73276b8 ("mmc: sdhci-pci: Fix SDHCI_RESET_ALL for CQHCI for Intel
                 GLK-based controllers")

The latter is especially prescient, saying "other drivers using CQHCI
might benefit from a similar change, if they also have CQHCI reset by
SDHCI_RESET_ALL."

So like these other patches, deactivate CQHCI when resetting the
controller. Do this via the new sdhci_and_cqhci_reset() helper.

This patch depends on (and should not compile without) the patch
entitled "mmc: cqhci: Provide helper for resetting both SDHCI and
CQHCI".

Fixes: 84362d79f436 ("mmc: sdhci-of-arasan: Add CQHCI support for arasan,sdhci-5.1")
Cc: <stable@vger.kernel.org>
Signed-off-by: Brian Norris <briannorris@chromium.org>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Acked-by: Adrian Hunter <adrian.hunter@intel.com>
---

Changes in v4:
 - Improve for-stable cherry-picking notes
 - Add Adrian's Ack

Changes in v3:
 - Refactor to a "SDHCI and CQHCI" helper -- sdhci_and_cqhci_reset()

Changes in v2:
 - Rely on cqhci_deactivate() to safely handle (ignore)
   not-yet-initialized CQE support

 drivers/mmc/host/sdhci-of-arasan.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/mmc/host/sdhci-of-arasan.c b/drivers/mmc/host/sdhci-of-arasan.c
index 3997cad1f793..cfb891430174 100644
--- a/drivers/mmc/host/sdhci-of-arasan.c
+++ b/drivers/mmc/host/sdhci-of-arasan.c
@@ -25,6 +25,7 @@
 #include <linux/firmware/xlnx-zynqmp.h>
 
 #include "cqhci.h"
+#include "sdhci-cqhci.h"
 #include "sdhci-pltfm.h"
 
 #define SDHCI_ARASAN_VENDOR_REGISTER	0x78
@@ -366,7 +367,7 @@ static void sdhci_arasan_reset(struct sdhci_host *host, u8 mask)
 	struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
 	struct sdhci_arasan_data *sdhci_arasan = sdhci_pltfm_priv(pltfm_host);
 
-	sdhci_reset(host, mask);
+	sdhci_and_cqhci_reset(host, mask);
 
 	if (sdhci_arasan->quirks & SDHCI_ARASAN_QUIRK_FORCE_CDTEST) {
 		ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL);
-- 
2.38.0.135.g90850a2211-goog


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

* Re: [PATCH v4 1/7] mmc: cqhci: Provide helper for resetting both SDHCI and CQHCI
  2022-10-26 19:42 ` [PATCH v4 1/7] mmc: cqhci: Provide helper for resetting both SDHCI and CQHCI Brian Norris
@ 2022-10-26 19:44   ` Florian Fainelli
  0 siblings, 0 replies; 3+ messages in thread
From: Florian Fainelli @ 2022-10-26 19:44 UTC (permalink / raw)
  To: Brian Norris, Ulf Hansson
  Cc: Shawn Guo, linux-mmc, Adrian Hunter, Shawn Lin, Michal Simek,
	Sascha Hauer, Bjorn Andersson, Thierry Reding, linux-arm-msm,
	linux-arm-kernel, Broadcom internal kernel review list,
	Jonathan Hunter, Andy Gross, Pengutronix Kernel Team,
	linux-kernel, Konrad Dybcio, Al Cooper, Fabio Estevam,
	NXP Linux Team, Haibo Chen, Sowjanya Komatineni, stable

On 10/26/22 12:42, Brian Norris wrote:
> Several SDHCI drivers need to deactivate command queueing in their reset
> hook (see sdhci_cqhci_reset() / sdhci-pci-core.c, for example), and
> several more are coming.
> 
> Those reset implementations have some small subtleties (e.g., ordering
> of initialization of SDHCI vs. CQHCI might leave us resetting with a
> NULL ->cqe_private), and are often identical across different host
> drivers.
> 
> We also don't want to force a dependency between SDHCI and CQHCI, or
> vice versa; non-SDHCI drivers use CQHCI, and SDHCI drivers might support
> command queueing through some other means.
> 
> So, implement a small helper, to avoid repeating the same mistakes in
> different drivers. Simply stick it in a header, because it's so small it
> doesn't deserve its own module right now, and inlining to each driver is
> pretty reasonable.
> 
> This is marked for -stable, as it is an important prerequisite patch for
> several SDHCI controller bugfixes that follow.
> 
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Brian Norris <briannorris@chromium.org>
> Acked-by: Adrian Hunter <adrian.hunter@intel.com>

Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
-- 
Florian


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

end of thread, other threads:[~2022-10-26 19:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20221026194209.3758834-1-briannorris@chromium.org>
2022-10-26 19:42 ` [PATCH v4 1/7] mmc: cqhci: Provide helper for resetting both SDHCI and CQHCI Brian Norris
2022-10-26 19:44   ` Florian Fainelli
2022-10-26 19:42 ` [PATCH v4 2/7] mmc: sdhci-of-arasan: Fix SDHCI_RESET_ALL for CQHCI Brian Norris

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).