mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2] mmc: sdhci-pci-gli: GL9763E: Fix LPM ordering and restore hw settings on resume
@ 2026-12-01  7:33 Athira Palliprath via B4 Relay
  2026-12-03  1:52 ` BenChuang[莊智量]
  0 siblings, 1 reply; 3+ messages in thread
From: Athira Palliprath via B4 Relay @ 2026-12-01  7:33 UTC (permalink / raw)
  To: Adrian Hunter, Ulf Hansson
  Cc: linux-mmc, Victor Shih, Ben Chuang, Sven van Ashbrook,
	Tomasz Figa, linux-kernel, stable, Athira Palliprath

From: Athira Palliprath <palliprath@chromium.org>

In gl9763e_runtime_suspend() and gl9763e_suspend(), LPM negotiation is
currently enabled before SDHCI/CQHCI MMIO register accesses finish, and
in gl9763e_runtime_resume() and gl9763e_resume(), SDHCI/CQHCI MMIO
registers are accessed before LPM negotiation is disabled. Because the
GL9763E has known hardware ASPM/L1 exit and replay-timer issues when
accessed while L1 negotiation is enabled, this ordering allows the
controller to enter L1 mid-transition and become inaccessible (0xffffffff
MMIO reads).

In addition, gl9763e_hw_setting() (which programs AXI_REQ, L1DLY,
HS400_RXDLY, and masks the AER replay timer timeout) is only executed
during probe and is not restored after D3cold or a controller reset.

Fix the ordering so LPM negotiation is disabled (and gl9763e_hw_setting()
is re-applied) before touching SDHCI/CQHCI MMIO on resume, and LPM
negotiation is re-enabled only after MMIO accesses complete on suspend.

Fixes: f9e5b33934ce ("mmc: host: Improve I/O read/write performance for GL9763E")
Fixes: 1202d617e3d0 ("mmc: sdhci-pci-gli: fix LPM negotiation so x86/S0ix SoCs can suspend")
Fixes: 340be332e420 ("mmc: sdhci-pci-gli: GL9763e: Mask the replay timer timeout of AER")
Cc: stable@vger.kernel.org
Signed-off-by: Athira Palliprath <palliprath@chromium.org>
---
Changes in v2:
- Disable LPM negotiation before calling gl9763e_hw_setting() in both
  gl9763e_runtime_resume() and gl9763e_resume() so vendor config registers
  (such as L1DLY) are not modified while LPM negotiation is enabled.
- Read back SDHCI_CLOCK_CONTROL in gl9763e_runtime_suspend() to flush the
  posted MMIO write before enabling LPM negotiation.
- Link to v1: https://lore.kernel.org/r/20261126-gl9763e-lpm-ordering-v1-1-71ce1b4edb89@chromium.org
---
 drivers/mmc/host/sdhci-pci-gli.c | 58 +++++++++++++++++++++-------------------
 1 file changed, 30 insertions(+), 28 deletions(-)

diff --git a/drivers/mmc/host/sdhci-pci-gli.c b/drivers/mmc/host/sdhci-pci-gli.c
index 66452ed8c..5e62d3762 100644
--- a/drivers/mmc/host/sdhci-pci-gli.c
+++ b/drivers/mmc/host/sdhci-pci-gli.c
@@ -1880,12 +1880,14 @@ static int gl9763e_runtime_suspend(struct sdhci_pci_chip *chip)
 	struct sdhci_host *host = slot->host;
 	u16 clock;
 
-	/* Enable LPM negotiation to allow entering L1 state */
-	gl9763e_set_low_power_negotiation(slot, true);
-
 	clock = sdhci_readw(host, SDHCI_CLOCK_CONTROL);
 	clock &= ~(SDHCI_CLOCK_PLL_EN | SDHCI_CLOCK_CARD_EN);
 	sdhci_writew(host, clock, SDHCI_CLOCK_CONTROL);
+	/* Flush the posted MMIO write before enabling LPM negotiation. */
+	sdhci_readw(host, SDHCI_CLOCK_CONTROL);
+
+	/* Enable LPM negotiation only after SDHCI MMIO accesses complete. */
+	gl9763e_set_low_power_negotiation(slot, true);
 
 	return 0;
 }
@@ -1896,6 +1898,13 @@ static int gl9763e_runtime_resume(struct sdhci_pci_chip *chip)
 	struct sdhci_host *host = slot->host;
 	u16 clock;
 
+	/*
+	 * Disable LPM negotiation and restore vendor PCI settings (lost across
+	 * D3cold/reset) before touching SDHCI MMIO registers.
+	 */
+	gl9763e_set_low_power_negotiation(slot, false);
+	gl9763e_hw_setting(slot);
+
 	if (host->mmc->ios.power_mode != MMC_POWER_ON)
 		return 0;
 
@@ -1916,9 +1925,6 @@ static int gl9763e_runtime_resume(struct sdhci_pci_chip *chip)
 	clock |= SDHCI_CLOCK_CARD_EN;
 	sdhci_writew(host, clock, SDHCI_CLOCK_CONTROL);
 
-	/* Disable LPM negotiation to avoid entering L1 state. */
-	gl9763e_set_low_power_negotiation(slot, false);
-
 	return 0;
 }
 #endif
@@ -1939,21 +1945,19 @@ static int gl9763e_resume(struct sdhci_pci_chip *chip)
 	struct sdhci_pci_slot *slot = chip->slots[0];
 	int ret;
 
-	ret = sdhci_pci_gli_resume(chip);
-	if (ret)
-		return ret;
-
-	ret = cqhci_resume(slot->host->mmc);
-	if (ret)
-		return ret;
-
 	/*
-	 * Disable LPM negotiation to bring device back in sync
-	 * with its runtime_pm state.
+	 * Disable LPM negotiation and restore vendor PCI config settings
+	 * (AXI_REQ, L1DLY, HS400_RXDLY, AER replay-timer-timeout mask) lost
+	 * across D3cold/reset before touching SDHCI/CQHCI MMIO registers.
 	 */
 	gl9763e_set_low_power_negotiation(slot, false);
+	gl9763e_hw_setting(slot);
 
-	return 0;
+	ret = sdhci_pci_gli_resume(chip);
+	if (ret)
+		return ret;
+
+	return cqhci_resume(slot->host->mmc);
 }
 
 static int gl9763e_suspend(struct sdhci_pci_chip *chip)
@@ -1961,28 +1965,26 @@ static int gl9763e_suspend(struct sdhci_pci_chip *chip)
 	struct sdhci_pci_slot *slot = chip->slots[0];
 	int ret;
 
-	/*
-	 * Certain SoCs can suspend only with the bus in low-
-	 * power state, notably x86 SoCs when using S0ix.
-	 * Re-enable LPM negotiation to allow entering L1 state
-	 * and entering system suspend.
-	 */
-	gl9763e_set_low_power_negotiation(slot, true);
-
 	ret = cqhci_suspend(slot->host->mmc);
 	if (ret)
-		goto err_suspend;
+		return ret;
 
 	ret = sdhci_suspend_host(slot->host);
 	if (ret)
 		goto err_suspend_host;
 
+	/*
+	 * Certain SoCs can suspend only with the bus in low-
+	 * power state, notably x86 SoCs when using S0ix.
+	 * Re-enable LPM negotiation to allow entering L1 state
+	 * only after CQHCI/SDHCI MMIO suspend accesses finish.
+	 */
+	gl9763e_set_low_power_negotiation(slot, true);
+
 	return 0;
 
 err_suspend_host:
 	cqhci_resume(slot->host->mmc);
-err_suspend:
-	gl9763e_set_low_power_negotiation(slot, false);
 	return ret;
 }
 #endif

---
base-commit: d2616724e01132376c78872b8324f38659af9f28
change-id: 20261126-gl9763e-lpm-ordering-cd55919f8cc2

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



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

* RE: [PATCH v2] mmc: sdhci-pci-gli: GL9763E: Fix LPM ordering and restore hw settings on resume
  2026-12-01  7:33 [PATCH v2] mmc: sdhci-pci-gli: GL9763E: Fix LPM ordering and restore hw settings on resume Athira Palliprath via B4 Relay
@ 2026-12-03  1:52 ` BenChuang[莊智量]
  2026-12-04  6:29   ` Athira Palliprath
  0 siblings, 1 reply; 3+ messages in thread
From: BenChuang[莊智量] @ 2026-12-03  1:52 UTC (permalink / raw)
  To: palliprath, Adrian Hunter
  Cc: SeanHYChen[陳宣仰],
	linux-mmc, Sven van Ashbrook, Tomasz Figa, linux-kernel, stable,
	Seth Coulter, Ulf Hansson


> -----Original Message-----
> From: Athira Palliprath via B4 Relay <devnull+palliprath.chromium.org@kernel.org>
> Sent: Tuesday, December 1, 2026 3:34 PM
> To: Adrian Hunter <adrian.hunter@intel.com>; Ulf Hansson <ulfh@kernel.org>
> Cc: linux-mmc@vger.kernel.org; Victor Shih <victor.shih@genesyslogic.com.tw>; BenChuang[莊智量]
> <Ben.Chuang@genesyslogic.com.tw>; Sven van Ashbrook <svenva@chromium.org>; Tomasz Figa <tfiga@chromium.org>;
> linux-kernel@vger.kernel.org; stable@vger.kernel.org; Athira Palliprath <palliprath@chromium.org>
> Subject: [PATCH v2] mmc: sdhci-pci-gli: GL9763E: Fix LPM ordering and restore hw settings on resume
>
> [You don't often get email from devnull+palliprath.chromium.org@kernel.org. Learn why this is important at
> https://aka.ms/LearnAboutSenderIdentification ]
>
> From: Athira Palliprath <palliprath@chromium.org>
>

Hi,

> In gl9763e_runtime_suspend() and gl9763e_suspend(), LPM negotiation is
> currently enabled before SDHCI/CQHCI MMIO register accesses finish, and
> in gl9763e_runtime_resume() and gl9763e_resume(), SDHCI/CQHCI MMIO
> registers are accessed before LPM negotiation is disabled. Because the
> GL9763E has known hardware ASPM/L1 exit and replay-timer issues when
> accessed while L1 negotiation is enabled, this ordering allows the
> controller to enter L1 mid-transition and become inaccessible (0xffffffff
> MMIO reads).
>
> In addition, gl9763e_hw_setting() (which programs AXI_REQ, L1DLY,
> HS400_RXDLY, and masks the AER replay timer timeout) is only executed
> during probe and is not restored after D3cold or a controller reset.
>

Here's some context based on the Chromebook projects and test platforms I have
worked on. In those platforms, the GL9763E was paired with eMMC as the boot
device, using runtime D3hot and being tested for S0ix/s2idle suspend.

My experience with GL9763E is mainly from those runtime-D3hot and
S0ix/s2idle scenarios, which were the configurations exercised on the
platforms I worked with.

I do not have experience with GL9763E platforms exercising D3cold /
controller-reset recovery paths, so my comments here are mainly based on the
suspend/resume ordering and behavior observed in the runtime-D3hot path.

>
> Fix the ordering so LPM negotiation is disabled (and gl9763e_hw_setting()
> is re-applied) before touching SDHCI/CQHCI MMIO on resume, and LPM
> negotiation is re-enabled only after MMIO accesses complete on suspend.
>
> Fixes: f9e5b33934ce ("mmc: host: Improve I/O read/write performance for GL9763E")
> Fixes: 1202d617e3d0 ("mmc: sdhci-pci-gli: fix LPM negotiation so x86/S0ix SoCs can suspend")
> Fixes: 340be332e420 ("mmc: sdhci-pci-gli: GL9763e: Mask the replay timer timeout of AER")
> Cc: stable@vger.kernel.org
> Signed-off-by: Athira Palliprath <palliprath@chromium.org>
> ---
> Changes in v2:
> - Disable LPM negotiation before calling gl9763e_hw_setting() in both
>   gl9763e_runtime_resume() and gl9763e_resume() so vendor config registers
>   (such as L1DLY) are not modified while LPM negotiation is enabled.
> - Read back SDHCI_CLOCK_CONTROL in gl9763e_runtime_suspend() to flush the
>   posted MMIO write before enabling LPM negotiation.
> - Link to v1:
> https://lore.kernel.org/r/20261126-gl9763e-lpm-ordering
> -v1-1-71ce1b4edb89%40chromium.org&data=05%7C02%7Cben.chuang%40genesyslogic.com.tw%7C61655970c37f4b63783b0
> 8df4f7d7c1e%7C4e753840bf6b40a19645185818deeb52%7C0%7C0%7C639317072507008382%7CUnknown%7CTWFpbGZsb3d
> 8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%
> 7C&sdata=x8q%2FZOHhc%2FEaR9MEn9uLtMiAy15QeTpVJ8ii3AnDwp0%3D&reserved=0
> ---
>  drivers/mmc/host/sdhci-pci-gli.c | 58 +++++++++++++++++++++-------------------
>  1 file changed, 30 insertions(+), 28 deletions(-)
>
> diff --git a/drivers/mmc/host/sdhci-pci-gli.c b/drivers/mmc/host/sdhci-pci-gli.c
> index 66452ed8c..5e62d3762 100644
> --- a/drivers/mmc/host/sdhci-pci-gli.c
> +++ b/drivers/mmc/host/sdhci-pci-gli.c
> @@ -1880,12 +1880,14 @@ static int gl9763e_runtime_suspend(struct sdhci_pci_chip *chip)
>         struct sdhci_host *host = slot->host;
>         u16 clock;
>
> -       /* Enable LPM negotiation to allow entering L1 state */
> -       gl9763e_set_low_power_negotiation(slot, true);
> -
>         clock = sdhci_readw(host, SDHCI_CLOCK_CONTROL);
>         clock &= ~(SDHCI_CLOCK_PLL_EN | SDHCI_CLOCK_CARD_EN);
>         sdhci_writew(host, clock, SDHCI_CLOCK_CONTROL);
> +       /* Flush the posted MMIO write before enabling LPM negotiation. */
> +       sdhci_readw(host, SDHCI_CLOCK_CONTROL);
> +
> +       /* Enable LPM negotiation only after SDHCI MMIO accesses complete. */
> +       gl9763e_set_low_power_negotiation(slot, true);
>
>         return 0;
>  }
> @@ -1896,6 +1898,13 @@ static int gl9763e_runtime_resume(struct sdhci_pci_chip *chip)
>         struct sdhci_host *host = slot->host;
>         u16 clock;
>
> +       /*
> +        * Disable LPM negotiation and restore vendor PCI settings (lost across
> +        * D3cold/reset) before touching SDHCI MMIO registers.
> +        */
> +       gl9763e_set_low_power_negotiation(slot, false);
> +       gl9763e_hw_setting(slot);
> +

In gl9763e_runtime_suspend()/resume(), this appears consistent with the
intended LPM ordering.

The only difference I see is that runtime resume now restores the HW settings
as well. This may slightly increase the D3hot resume time.

>         if (host->mmc->ios.power_mode != MMC_POWER_ON)
>                 return 0;
>
> @@ -1916,9 +1925,6 @@ static int gl9763e_runtime_resume(struct sdhci_pci_chip *chip)
>         clock |= SDHCI_CLOCK_CARD_EN;
>         sdhci_writew(host, clock, SDHCI_CLOCK_CONTROL);
>
> -       /* Disable LPM negotiation to avoid entering L1 state. */
> -       gl9763e_set_low_power_negotiation(slot, false);
> -
>         return 0;
>  }
>  #endif
> @@ -1939,21 +1945,19 @@ static int gl9763e_resume(struct sdhci_pci_chip *chip)
>         struct sdhci_pci_slot *slot = chip->slots[0];
>         int ret;
>
> -       ret = sdhci_pci_gli_resume(chip);
> -       if (ret)
> -               return ret;
> -
> -       ret = cqhci_resume(slot->host->mmc);
> -       if (ret)
> -               return ret;
> -
>         /*
> -        * Disable LPM negotiation to bring device back in sync
> -        * with its runtime_pm state.
> +        * Disable LPM negotiation and restore vendor PCI config settings
> +        * (AXI_REQ, L1DLY, HS400_RXDLY, AER replay-timer-timeout mask) lost
> +        * across D3cold/reset before touching SDHCI/CQHCI MMIO registers.
>          */
>         gl9763e_set_low_power_negotiation(slot, false);
> +       gl9763e_hw_setting(slot);
>
> -       return 0;
> +       ret = sdhci_pci_gli_resume(chip);
> +       if (ret)
> +               return ret;
> +
> +       return cqhci_resume(slot->host->mmc);
>  }
>
>  static int gl9763e_suspend(struct sdhci_pci_chip *chip)
> @@ -1961,28 +1965,26 @@ static int gl9763e_suspend(struct sdhci_pci_chip *chip)
>         struct sdhci_pci_slot *slot = chip->slots[0];
>         int ret;
>
> -       /*
> -        * Certain SoCs can suspend only with the bus in low-
> -        * power state, notably x86 SoCs when using S0ix.
> -        * Re-enable LPM negotiation to allow entering L1 state
> -        * and entering system suspend.
> -        */
> -       gl9763e_set_low_power_negotiation(slot, true);
> -

Previous discussion can be found at
v2: https://lore.kernel.org/all/20230823174134.v2.1.I7ed1ca09797be2dd76ca914c57d88b32d24dac88@changeid/
v3: https://lore.kernel.org/all/20230831160055.v3.1.I7ed1ca09797be2dd76ca914c57d88b32d24dac88@changeid/

>         ret = cqhci_suspend(slot->host->mmc);
>         if (ret)
> -               goto err_suspend;
> +               return ret;
>
>         ret = sdhci_suspend_host(slot->host);
>         if (ret)
>                 goto err_suspend_host;
>
> +       /*
> +        * Certain SoCs can suspend only with the bus in low-
> +        * power state, notably x86 SoCs when using S0ix.
> +        * Re-enable LPM negotiation to allow entering L1 state
> +        * only after CQHCI/SDHCI MMIO suspend accesses finish.
> +        */
> +       gl9763e_set_low_power_negotiation(slot, true);
> +
>         return 0;
>
>  err_suspend_host:
>         cqhci_resume(slot->host->mmc);
> -err_suspend:
> -       gl9763e_set_low_power_negotiation(slot, false);
>         return ret;
>  }
>  #endif
>

In gl9763e_suspend()/resume(), this appears consistent with the intended
LPM ordering.

> ---
> base-commit: d2616724e01132376c78872b8324f38659af9f28
> change-id: 20261126-gl9763e-lpm-ordering-cd55919f8cc2
>
> Best regards,
> --
> Athira Palliprath <palliprath@chromium.org>
>
>

Best regards,
Ben Chuang

________________________________

Genesys Logic Email Confidentiality Notice:
This mail and any attachments may contain information that is confidential, proprietary, privileged or otherwise protected by law. The mail is intended solely for the named addressee (or a person responsible for delivering it to the addressee). If you are not the intended recipient of this mail, you are not authorized to read, print, copy or disseminate this mail.

If you have received this email in error, please notify us immediately by reply email and immediately delete this message and any attachments from your system. Please be noted that any unauthorized use, dissemination, distribution or copying of this email is strictly prohibited.
________________________________

Genesys Logic will participate in CES 2027 (January 6-9, 2027). Visit our booth at 36123 in the South Hall 2, Las Vegas.
________________________________

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

* Re: [PATCH v2] mmc: sdhci-pci-gli: GL9763E: Fix LPM ordering and restore hw settings on resume
  2026-12-03  1:52 ` BenChuang[莊智量]
@ 2026-12-04  6:29   ` Athira Palliprath
  0 siblings, 0 replies; 3+ messages in thread
From: Athira Palliprath @ 2026-12-04  6:29 UTC (permalink / raw)
  To: BenChuang[莊智量]
  Cc: Adrian Hunter, SeanHYChen[陳宣仰],
	linux-mmc, Sven van Ashbrook, Tomasz Figa, linux-kernel, stable,
	Seth Coulter, Ulf Hansson

(Resending in plain text for the mailing lists.)

Hi Ben,

Thank you for reviewing v2 and confirming the LPM ordering on both the
runtime and system suspend/resume paths, as well as sharing the earlier
thread context.

On Thu, Dec 3, 2026 at 7:22 AM BenChuang[莊智量]
<Ben.Chuang@genesyslogic.com.tw> wrote:
> In gl9763e_runtime_suspend()/resume(), this appears consistent with the
> intended LPM ordering.
>
> The only difference I see is that runtime resume now restores the HW settings
> as well. This may slightly increase the D3hot resume time.

The reason for calling gl9763e_hw_setting() in gl9763e_runtime_resume()
as well is that PCI runtime PM can also transition the device into D3cold
(not only D3hot) on platforms where runtime D3cold is enabled. When
waking from runtime D3cold, pci_restore_state() restores standard PCI
config space but not the GL9763E vendor registers (AXI_REQ, L1DLY,
HS400_RXDLY) or the AER replay-timer-timeout mask, and gl9763e_resume()
is not called on the runtime-PM path.

Since gl9763e_hw_setting() only performs a small number of PCI config
accesses with no delays or sleeps, the added overhead on D3hot runtime
resume should be minimal (microseconds compared to D3hot -> D0 and SDHCI
clock/PLL stabilization).

If you or Adrian would prefer avoiding those config writes on D3hot
resumes (for example, checking whether the settings are already intact
before reprogramming), I'm happy to adjust that; otherwise keeping it
unconditional is simpler and ensures runtime D3cold is always covered.

Best regards,
Athira

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

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

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-01  7:33 [PATCH v2] mmc: sdhci-pci-gli: GL9763E: Fix LPM ordering and restore hw settings on resume Athira Palliprath via B4 Relay
2026-12-03  1:52 ` BenChuang[莊智量]
2026-12-04  6:29   ` Athira Palliprath

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®