Linux Power Management development
 help / color / mirror / Atom feed
From: Jason Kim <dialogbox@gmail.com>
To: Mathias Nyman <mathias.nyman@intel.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: "Jason Kim" <dialogbox@gmail.com>,
	linux-usb@vger.kernel.org, linux-pm@vger.kernel.org,
	platform-driver-x86@vger.kernel.org, regressions@lists.linux.dev,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	"Xi Pardee" <xi.pardee@linux.intel.com>,
	"Hans de Goede" <hansg@kernel.org>,
	"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
	"Rajneesh Bhardwaj" <irenic.rajneesh@gmail.com>
Subject: [RFC PATCH] usb: xhci-pci: resume Lunar Lake xHC before system suspend
Date: Thu, 26 Nov 2026 09:20:06 +0900	[thread overview]
Message-ID: <20261126002006.25823-1-dialogbox@gmail.com> (raw)
In-Reply-To: <CANb8v8EGmQf90hRvr8cE3vTKOOY8b6LTxki1uORW_TJ9HadrZw@mail.gmail.com>

On a ThinkPad T14s Gen 6 (Lunar Lake), suspend-to-idle often fails to
reach S0ix when the PCH xHC (8086:a87d) is runtime-suspended when the
system suspend starts. The Intel PMT counters show the PCH blocking
package C6 (PREVENT_PKGC6_CHIPSET_1/2) for the whole sleep period, and
the package stays in PC2. No LPS0 constraint is reported as unmet.

A runtime-suspended PCI host controller is runtime-resumed by
pci_pm_suspend() and then suspended again, so it goes through a
D3hot -> D0 -> D3hot cycle in the middle of the system suspend
transition. If the controller is kept active until the transition
starts (power/control set to "on"), S0ix is reached reliably.

Add an HCD flag that makes hcd_pci_prepare() runtime-resume the
controller before any device is suspended, and set it for the Lunar
Lake xHC through a new quirk. The PM core holds a runtime PM reference
from ->prepare() to ->complete(), so the controller stays active until
the system suspend proper and goes from D0 to D3hot once.

Results on v7.4-rc4, battery, 8 s rtcwake cycles, counted as S0ix
entered when last_hw_sleep > 0:

  runtime-suspended xHC (unpatched)       0/30, 4/30
  power/control=on right before suspend  97/100
  with this patch                        28/30

The analysis, the patch and this changelog were prepared with the help
of an AI coding assistant (Claude Code). I reviewed the change and ran
the tests above on my machine.

Link: https://bugzilla.kernel.org/show_bug.cgi?id=222281
Link: https://lore.kernel.org/linux-usb/CANb8v8EGmQf90hRvr8cE3vTKOOY8b6LTxki1uORW_TJ9HadrZw@mail.gmail.com/
Signed-off-by: Jason Kim <dialogbox@gmail.com>
---
This follows up on my report in the thread this mail replies to.

Sent as RFC because I have seen this on only one machine, a ThinkPad
T14s Gen 6 (BIOS N4IET31W 1.17), and I cannot tell whether it is a
Lunar Lake issue or specific to this platform and its firmware. The
ACPI power resource of the xHC here is \_SB.PC00.LPCB.EC.PUBS, which
is defined under the EC device, so firmware may well be involved.
Could someone at Intel check whether other Lunar Lake systems show
the same behaviour? Depending on the answer, the quirk could stay on
the PCI ID as in this patch, be limited by DMI, or be dropped in
favour of a firmware fix. I would appreciate advice on which way to
go.

Notes:

- Tested only on v7.4-rc4, on this one machine. The Thunderbolt xHC at
  00:0d.0 (8086:a831) is not touched by this change.

- No Fixes: tag. On Ubuntu 7.0 the same failure happens about 14% of
  the time and on 7.4-rc4 most of the time, but I have not found the
  commit that made it worse, so this works around the trigger rather
  than reverting a specific change.

- Resuming 00:14.0 alone in ->prepare() is enough. A debug variant that
  resumed both xHCs in ->prepare() gave the same result (29/30), and so
  did taking a runtime PM reference from a PM_SUSPEND_PREPARE notifier
  (29/30).

- Separate issue, mentioned only because I left it out of the numbers
  above: in two boots (one of them with this patch applied) S0ix failed
  in every cycle no matter what the xHC did, including with
  power/control=on (0/30). In those boots the display DMC
  "DC5 -> DC6 allowed count" never increased during sleep, while it
  goes up by 15-20 per cycle in every other boot. It does not seem
  related to USB, and I will report it separately once I can
  reproduce it.

- If a more generic fix is preferred, for example avoiding the runtime
  resume in the system suspend path for this device in USB or PCI core,
  I am happy to test it.

 drivers/usb/core/hcd-pci.c  | 21 +++++++++++++++++++++
 drivers/usb/host/xhci-pci.c | 14 ++++++++++++++
 drivers/usb/host/xhci.h     |  1 +
 include/linux/usb/hcd.h     |  2 ++
 4 files changed, 38 insertions(+)

diff --git a/drivers/usb/core/hcd-pci.c b/drivers/usb/core/hcd-pci.c
index cd223475917e..85df50237e4c 100644
--- a/drivers/usb/core/hcd-pci.c
+++ b/drivers/usb/core/hcd-pci.c
@@ -8,6 +8,7 @@
 #include <linux/pci.h>
 #include <linux/usb.h>
 #include <linux/usb/hcd.h>
+#include <linux/pm_runtime.h>
 
 #include <asm/io.h>
 #include <asm/irq.h>
@@ -521,6 +522,24 @@ static int resume_common(struct device *dev, pm_message_t msg)
 
 #ifdef	CONFIG_PM_SLEEP
 
+static int hcd_pci_prepare(struct device *dev)
+{
+	struct usb_hcd		*hcd = dev_get_drvdata(dev);
+
+	/*
+	 * Some host controllers misbehave if they are runtime-resumed and
+	 * suspended again in the middle of a system suspend transition, which
+	 * is what happens to a runtime-suspended controller in
+	 * pci_pm_suspend().  Resume them here instead, before any device is
+	 * suspended.  The PM core holds a runtime PM reference from now until
+	 * ->complete(), so they stay active until the system suspend proper.
+	 */
+	if (hcd && hcd->resume_before_system_suspend)
+		pm_runtime_resume(dev);
+
+	return 0;
+}
+
 static int hcd_pci_suspend(struct device *dev)
 {
 	return suspend_common(dev, PMSG_SUSPEND);
@@ -599,6 +618,7 @@ static int hcd_pci_restore(struct device *dev)
 
 #else
 
+#define hcd_pci_prepare		NULL
 #define hcd_pci_suspend		NULL
 #define hcd_pci_freeze			NULL
 #define hcd_pci_suspend_noirq	NULL
@@ -631,6 +651,7 @@ static int hcd_pci_runtime_resume(struct device *dev)
 }
 
 const struct dev_pm_ops usb_hcd_pci_pm_ops = {
+	.prepare	= hcd_pci_prepare,
 	.suspend	= hcd_pci_suspend,
 	.suspend_noirq	= hcd_pci_suspend_noirq,
 	.resume_noirq	= hcd_pci_resume_noirq,
diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c
index e278db940a58..261c77ba794c 100644
--- a/drivers/usb/host/xhci-pci.c
+++ b/drivers/usb/host/xhci-pci.c
@@ -60,6 +60,7 @@
 #define PCI_DEVICE_ID_INTEL_COMET_LAKE_XHCI		0xa3af
 #define PCI_DEVICE_ID_INTEL_ALDER_LAKE_PCH_XHCI		0x51ed
 #define PCI_DEVICE_ID_INTEL_ALDER_LAKE_N_PCH_XHCI	0x54ed
+#define PCI_DEVICE_ID_INTEL_LUNAR_LAKE_XHCI		0xa87d
 
 #define PCI_VENDOR_ID_PHYTIUM		0x1db7
 #define PCI_DEVICE_ID_PHYTIUM_XHCI			0xdc27
@@ -419,6 +420,16 @@ static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci)
 	     pdev->device == PCI_DEVICE_ID_INTEL_MAPLE_RIDGE_XHCI))
 		xhci->quirks |= XHCI_DEFAULT_PM_RUNTIME_ALLOW;
 
+	/*
+	 * If the Lunar Lake xHC goes through a D3hot -> D0 -> D3hot cycle
+	 * during system suspend (it is runtime-suspended when the transition
+	 * starts), the platform often fails to reach S0ix: the PCH keeps
+	 * blocking package C6 for the whole suspend-to-idle period.
+	 */
+	if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
+	    pdev->device == PCI_DEVICE_ID_INTEL_LUNAR_LAKE_XHCI)
+		xhci->quirks |= XHCI_RESUME_BEFORE_SYSTEM_SUSPEND;
+
 	if (pdev->vendor == PCI_VENDOR_ID_ETRON &&
 	    (pdev->device == PCI_DEVICE_ID_ETRON_EJ168 ||
 	     pdev->device == PCI_DEVICE_ID_ETRON_EJ188)) {
@@ -679,6 +690,9 @@ int xhci_pci_common_probe(struct pci_dev *dev, const struct pci_device_id *id)
 	else if (xhci->quirks & XHCI_DEFAULT_PM_RUNTIME_ALLOW)
 		pm_runtime_allow(&dev->dev);
 
+	if (xhci->quirks & XHCI_RESUME_BEFORE_SYSTEM_SUSPEND)
+		hcd->resume_before_system_suspend = 1;
+
 	dma_set_max_seg_size(&dev->dev, UINT_MAX);
 
 	if (device_property_read_bool(&dev->dev, "ti,pwron-active-high"))
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index ec4bfeb4887c..d3f202cde46b 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -1652,6 +1652,7 @@ struct xhci_hcd {
 #define XHCI_CDNS_SCTX_QUIRK	BIT_ULL(48)
 #define XHCI_ETRON_HOST	BIT_ULL(49)
 #define XHCI_LIMIT_ENDPOINT_INTERVAL_9 BIT_ULL(50)
+#define XHCI_RESUME_BEFORE_SYSTEM_SUSPEND	BIT_ULL(51)
 
 	unsigned int		num_active_eps;
 	unsigned int		limit_active_eps;
diff --git a/include/linux/usb/hcd.h b/include/linux/usb/hcd.h
index 181db044c4d2..616d334436a1 100644
--- a/include/linux/usb/hcd.h
+++ b/include/linux/usb/hcd.h
@@ -160,6 +160,8 @@ struct usb_hcd {
 	unsigned		tpl_support:1; /* OTG & EH TPL support */
 	unsigned		cant_recv_wakeups:1;
 			/* wakeup requests from downstream aren't received */
+	unsigned		resume_before_system_suspend:1;
+			/* leave runtime suspend in ->prepare of system suspend */
 
 	unsigned int		irq;		/* irq allocated */
 	void __iomem		*regs;		/* device memory/io */
-- 
2.53.0


      reply	other threads:[~2026-11-26  0:20 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25  9:24 [REGRESSION] Lunar Lake: s2idle randomly misses S0ix when PCH xHCI (8086:a87d) is runtime-suspended; much worse since 7.3 Jun Cheol Gim
2026-11-26  0:20 ` Jason Kim [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=20261126002006.25823-1-dialogbox@gmail.com \
    --to=dialogbox@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hansg@kernel.org \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=irenic.rajneesh@gmail.com \
    --cc=linux-pm@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=mathias.nyman@intel.com \
    --cc=platform-driver-x86@vger.kernel.org \
    --cc=rafael@kernel.org \
    --cc=regressions@lists.linux.dev \
    --cc=xi.pardee@linux.intel.com \
    /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