Add quirk for PCIe root port on AMD systems
Subsystems (2)
v19 cover Add quirk for PCIe root port on AMD systems
Iain reports that USB devices can't be used to wake a Lenovo Z13 from suspend. This is because the PCIe root port has been put into D3hot and AMD's platform can't handle USB devices waking the platform from a hardware sleep state in this case.
The firmware doesn't express this limitation in a way that Linux recognizes so this series introduces a quirk for this problem.
Previous submissions:
* v18
https://lore.kernel.org/linux-usb/[email protected]/T/#m92a2654129d5f6be5439d8a94fb36734804763c1
* v17
https://lore.kernel.org/platform-driver-x86/[email protected]/
This version implemented constraints for the amd-pmc driver and introduced a veto/optin system for the PCI core as suggested by Hans. Rafael suggested not to use the veto/optin system and instead use a quirk.
* v16
https://lore.kernel.org/platform-driver-x86/[email protected]/
This version implemented constraints for the amd-pmc driver.
* v15
https://lore.kernel.org/platform-driver-x86/[email protected]/#t
This version hardcoded the quirk into amd-pmc driver as part of suspend callback.
* v14
https://lore.kernel.org/linux-pci/[email protected]/
https://lore.kernel.org/linux-pci/[email protected]/
https://lore.kernel.org/linux-pci/[email protected]/
This version implemented constraints exporting and limited the policy for
Quoted 1 line
= 2015 to Intel only. It also added support for constraints optin.
V13 was split into multiple parts to make it easier to land. 14.b was merged.
* v13
https://lore.kernel.org/linux-pci/[email protected]/
* v12
https://lore.kernel.org/linux-pci/[email protected]/
* v11
https://lore.kernel.org/linux-pci/[email protected]/
* v10
https://lore.kernel.org/linux-pci/[email protected]/
* v9
https://lore.kernel.org/linux-pci/[email protected]/
* v8
https://lore.kernel.org/linux-pci/[email protected]/
* v7
https://lore.kernel.org/linux-pci/[email protected]/
* v6
https://lore.kernel.org/linux-pci/[email protected]/
* v5
https://lore.kernel.org/linux-pci/[email protected]/
* v4
https://lore.kernel.org/linux-pci/[email protected]/
* v3
https://lore.kernel.org/linux-pci/[email protected]/
* v2
https://lore.kernel.org/linux-pci/[email protected]/
* v1
https://lore.kernel.org/linux-pci/[email protected]/
Mario Limonciello (2):
PCI: Move the PCI_CLASS_SERIAL_USB_USB4 definition to common header
PCI: Add a quirk for AMD PCIe root ports w/ USB4 controllers
drivers/pci/quirks.c | 61 +++++++++++++++++++++++++++++++++++++++ drivers/thunderbolt/nhi.h | 2 -- include/linux/pci_ids.h | 1 + 3 files changed, 62 insertions(+), 2 deletions(-)
base-commit: 0bb80ecc33a8fb5a682236443c1e740d5c917d1d
Signature · 1 line
2.34.1
PATCH v19 1/2 PCI: Move the `PCI_CLASS_SERIAL_USB_USB4` definition to common header
PCI_CLASS_SERIAL_USB_USB4 may be used by code outside of thunderbolt. Move the declaration into the common pci_ids.h header.
--- drivers/thunderbolt/nhi.h | 2 -- include/linux/pci_ids.h | 1 + 2 files changed, 1 insertion(+), 2 deletions(-)
drivers/thunderbolt/nhi.h +0 -2
@@ -91,6 +91,4 @@ extern const struct tb_nhi_ops icl_nhi_ops;#define PCI_DEVICE_ID_INTEL_RPL_NHI0 0xa73e#define PCI_DEVICE_ID_INTEL_RPL_NHI1 0xa76d -#define PCI_CLASS_SERIAL_USB_USB4 0x0c0340 -#endif
include/linux/pci_ids.h +1 -0
@@ -121,6 +121,7 @@#define PCI_CLASS_SERIAL_USB_OHCI 0x0c0310#define PCI_CLASS_SERIAL_USB_EHCI 0x0c0320#define PCI_CLASS_SERIAL_USB_XHCI 0x0c0330 +#define PCI_CLASS_SERIAL_USB_USB4 0x0c0340#define PCI_CLASS_SERIAL_USB_DEVICE 0x0c03fe#define PCI_CLASS_SERIAL_FIBER 0x0c04#define PCI_CLASS_SERIAL_SMBUS 0x0c05
Signature · 1 line
2.34.1
PATCH v19 2/2 PCI: Add a quirk for AMD PCIe root ports w/ USB4 controllers
In reply to Mario LimoncielloIain reports that USB devices can't be used to wake a Lenovo Z13 from suspend. This problem occurs because the PCIe root port has been put into D3hot and AMD's platform can't handle USB devices waking the platform from a hardware sleep state in this case. The platform is put into a hardware sleep state by the actions of the amd-pmc driver.
Although the issue is initially reported on a single model it actually affects all Yellow Carp (Rembrandt) and Pink Sardine (Phoenix) SoCs. This problem only occurs on Linux specifically when attempting to wake the platform from a hardware sleep state.
Comparing the behavior on Windows and Linux, Windows doesn't put the root ports into D3 at this time.
Linux decides the target state to put the device into at suspend by this policy:
1. If platform_pci_power_manageable():
Use platform_pci_choose_state()
2. If the device is armed for wakeup:
Select the deepest D-state that supports a PME.
3. Else:
Use D3hot.
Devices are considered power manageable by the platform when they have one or more objects described in the table in section 7.3 of the ACPI 6.5 specification [1]. In this case the root ports are not power manageable.
If devices are not considered power manageable; specs are ambiguous as to what should happen. In this situation Windows 11 puts PCIe ports in D0 ostensibly due the policy from the "uPEP driver" which is a complimentary driver the Linux "amd-pmc" driver.
Linux chooses to allow D3 for these root ports due to the policy introduced by commit 9d26d3a8f1b0 ("PCI: Put PCIe ports into D3 during suspend").
The Windows uPEP driver expresses the desired state that should be selected for suspend but Linux doesn't, so introduce a quirk for the problematic root ports.
The quirk removes PME support for D3hot and D3cold at suspend time if the system will be using s2idle. When the port is configured for wakeup this will prevent these states from being selected in pci_target_state().
After the system is resumes the PME support is re-read from the PM capabilities register to allow opportunistic power savings at runtime by letting the root port go into D3hot or D3cold.
--- drivers/pci/quirks.c | 61 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+)
drivers/pci/quirks.c +61 -0
@@ -6188,3 +6188,64 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x9a31, dpc_log_size);DECLARE_PCI_FIXUP_FINAL (PCI_VENDOR_ID_XILINX ,0x5020 , of_pci_make_dev_node);DECLARE_PCI_FIXUP_FINAL (PCI_VENDOR_ID_XILINX ,0x5021 , of_pci_make_dev_node);DECLARE_PCI_FIXUP_FINAL (PCI_VENDOR_ID_REDHAT ,0x0005 , of_pci_make_dev_node); + +/* +* When AMD PCIe root ports with AMD USB4 controllers attached to them are put +* into D3hot or D3cold downstream USB devices may fail to wakeup the system. +* This manifests as a missing wakeup interrupt. +* +* Prevent the associated root port from using PME to wake from D3hot or +* D3cold power states during s2idle. +* This will effectively put the root port into D0 power state over s2idle. +*/ +static bool child_has_amd_usb4 (struct pci_dev *pdev) +{ +struct pci_dev *child =NULL ; + +while ((child =pci_get_class (PCI_CLASS_SERIAL_USB_USB4 , child))) { +if (child->vendor !=PCI_VENDOR_ID_AMD ) +continue ; +if (pcie_find_root_port (child) != pdev) +continue ; +return true; + } + +return false; +} + +static void quirk_reenable_pme (struct pci_dev *dev) +{ +u16 pmc; + +if (!dev->pm_cap) +return ; + +if (!child_has_amd_usb4 (dev)) +return ; + +pci_read_config_word (dev, dev->pm_cap +PCI_PM_PMC , &pmc); + pmc &=PCI_PM_CAP_PME_MASK ; + dev->pme_support = pmc >>PCI_PM_CAP_PME_SHIFT ; +} + +static void quirk_disable_pme_suspend (struct pci_dev *dev) +{ +int mask; + +if (pm_suspend_via_firmware ()) +return ; + +if (!child_has_amd_usb4 (dev)) +return ; + + mask = (PCI_PM_CAP_PME_D3hot|PCI_PM_CAP_PME_D3cold) >>PCI_PM_CAP_PME_SHIFT ; +if (!(dev->pme_support & mask)) +return ; + dev->pme_support &= ~mask; +dev_info_once (&dev->dev,"quirk: disabling PME from D3hot and D3cold at suspend\n" ); +} + +DECLARE_PCI_FIXUP_SUSPEND (PCI_VENDOR_ID_AMD ,0x14b9 , quirk_disable_pme_suspend); +DECLARE_PCI_FIXUP_RESUME (PCI_VENDOR_ID_AMD ,0x14b9 , quirk_reenable_pme); +DECLARE_PCI_FIXUP_SUSPEND (PCI_VENDOR_ID_AMD ,0x14eb , quirk_disable_pme_suspend); +DECLARE_PCI_FIXUP_RESUME (PCI_VENDOR_ID_AMD ,0x14eb , quirk_reenable_pme);
Signature · 1 line
2.34.1
Re: [PATCH v19 2/2] PCI: Add a quirk for AMD PCIe root ports w/ USB4 controllers
Quoted 4 lines · Mario Limonciello
drivers/pci/quirks.c +4
-0+static bool child_has_amd_usb4 (struct pci_dev *pdev) +{ +struct pci_dev *child =NULL ; +
drivers/pci/quirks.c DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x9a31, dpc_log_size); · line 6214
Quoted 10 lines
drivers/pci/quirks.c +10
-0+while ((child =pci_get_class (PCI_CLASS_SERIAL_USB_USB4 , child))) { +if (child->vendor !=PCI_VENDOR_ID_AMD ) +continue ; +if (pcie_find_root_port (child) != pdev) +continue ; +return true; + } + +return false; +}
What's the purpose of the pcie_find_root_port() check? PCI is a hierarchy, not a graph, so a device cannot have any other Root Port but the one below which you're searching.
If the purpose is to check that the port is a Root Port (if the PCI IDs you're using in the DECLARE_PCI_FIXUP_* clauses match non-Root Ports), check for pci_pcie_type(pdev) == PCI_EXP_TYPE_ROOT_PORT. (No need to check for that in every loop iteration obviously, just check once in the fixup.)
Thanks,
Lukas
Re: [PATCH v19 2/2] PCI: Add a quirk for AMD PCIe root ports w/ USB4 controllers
Quoted 26 lines · Lukas Wunner
Quoted 4 lines · Mario Limonciello
drivers/pci/quirks.c +4
-0+static bool child_has_amd_usb4 (struct pci_dev *pdev) +{ +struct pci_dev *child =NULL ; +drivers/pci/quirks.c DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x9a31, dpc_log_size); · line 6214
Quoted 10 lines
drivers/pci/quirks.c +10
-0+while ((child =pci_get_class (PCI_CLASS_SERIAL_USB_USB4 , child))) { +if (child->vendor !=PCI_VENDOR_ID_AMD ) +continue ; +if (pcie_find_root_port (child) != pdev) +continue ; +return true; + } + +return false; +}What's the purpose of the
pcie_find_root_port()check? PCI is a hierarchy, not a graph, so a device cannot have any other Root Port but the one below which you're searching.If the purpose is to check that the port is a Root Port (if the PCI IDs you're using in the DECLARE_PCI_FIXUP_* clauses match non-Root Ports), check for
pci_pcie_type(pdev)==PCI_EXP_TYPE_ROOT_PORT. (No need to check for that in every loop iteration obviously, just check once in the fixup.)
Quoted 3 lines
Thanks,
Lukas
The reason to look for it the way that I did was that there are multiple root ports with the exact same PCI ID.
The problem only occurs on the root port that happens to have an AMD USB4 controller connected.
Re: [PATCH v19 2/2] PCI: Add a quirk for AMD PCIe root ports w/ USB4 controllers
Quoted 29 lines · Mario Limonciello
Quoted 28 lines · Lukas Wunner
Quoted 4 lines · Mario Limonciello
drivers/pci/quirks.c +4
-0+static bool child_has_amd_usb4 (struct pci_dev *pdev) +{ +struct pci_dev *child =NULL ; +drivers/pci/quirks.c DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x9a31, dpc_log_size); · line 6214
Quoted 10 lines
drivers/pci/quirks.c +10
-0+while ((child =pci_get_class (PCI_CLASS_SERIAL_USB_USB4 , child))) { +if (child->vendor !=PCI_VENDOR_ID_AMD ) +continue ; +if (pcie_find_root_port (child) != pdev) +continue ; +return true; + } + +return false; +}What's the purpose of the
pcie_find_root_port()check? PCI is a hierarchy, not a graph, so a device cannot have any other Root Port but the one below which you're searching.If the purpose is to check that the port is a Root Port (if the PCI IDs you're using in the DECLARE_PCI_FIXUP_* clauses match non-Root Ports), check for
pci_pcie_type(pdev)==PCI_EXP_TYPE_ROOT_PORT. (No need to check for that in every loop iteration obviously, just check once in the fixup.)Thanks,
Quoted 7 lines
Quoted 1 line
Lukas
The reason to look for it the way that I did was that there are multiple root ports with the exact same PCI ID.
The problem only occurs on the root port that happens to have an AMD USB4 controller connected.
Yes but what's the purpose of the pcie_find_root_port(child) check quoted above?
Thanks,
Lukas
Re: [PATCH v19 2/2] PCI: Add a quirk for AMD PCIe root ports w/ USB4 controllers
Quoted 38 lines · Lukas Wunner
Quoted 29 lines · Mario Limonciello
Quoted 28 lines · Lukas Wunner
Quoted 4 lines · Mario Limonciello
drivers/pci/quirks.c +4
-0+static bool child_has_amd_usb4 (struct pci_dev *pdev) +{ +struct pci_dev *child =NULL ; +drivers/pci/quirks.c DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x9a31, dpc_log_size); · line 6214
Quoted 10 lines
drivers/pci/quirks.c +10
-0+while ((child =pci_get_class (PCI_CLASS_SERIAL_USB_USB4 , child))) { +if (child->vendor !=PCI_VENDOR_ID_AMD ) +continue ; +if (pcie_find_root_port (child) != pdev) +continue ; +return true; + } + +return false; +}What's the purpose of the
pcie_find_root_port()check? PCI is a hierarchy, not a graph, so a device cannot have any other Root Port but the one below which you're searching.If the purpose is to check that the port is a Root Port (if the PCI IDs you're using in the DECLARE_PCI_FIXUP_* clauses match non-Root Ports), check for
pci_pcie_type(pdev)==PCI_EXP_TYPE_ROOT_PORT. (No need to check for that in every loop iteration obviously, just check once in the fixup.)Thanks,
Quoted 7 lines
Quoted 1 line
Lukas
The reason to look for it the way that I did was that there are multiple root ports with the exact same PCI ID.
The problem only occurs on the root port that happens to have an AMD USB4 controller connected.
Quoted 6 lines
Yes but what's the purpose of the
pcie_find_root_port(child)check quoted above?Thanks,
Lukas
You're right that if you look at this system alone that the check isn't strictly necessary. It's to future proof the quirk. If a discrete USB4 controller was connected to the system it would be connected to a different root port (the one that is used for PCI tunneling).
AMD doesn't have any of these devices, but if some day one was created it could trip this codepath.
If you feel it's better to remove the check unless such a device is created sure I can drop it.
Re: [PATCH v19 2/2] PCI: Add a quirk for AMD PCIe root ports w/ USB4 controllers
Quoted 47 lines · Mario Limonciello
Quoted 32 lines · Lukas Wunner
Quoted 31 lines · Mario Limonciello
Quoted 29 lines · Lukas Wunner
Quoted 4 lines · Mario Limonciello
drivers/pci/quirks.c +4
-0+static bool child_has_amd_usb4 (struct pci_dev *pdev) +{ +struct pci_dev *child =NULL ; +drivers/pci/quirks.c DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x9a31, dpc_log_size); · line 6214
Quoted 10 lines
drivers/pci/quirks.c +10
-0+while ((child =pci_get_class (PCI_CLASS_SERIAL_USB_USB4 , child))) { +if (child->vendor !=PCI_VENDOR_ID_AMD ) +continue ; +if (pcie_find_root_port (child) != pdev) +continue ; +return true; + } + +return false; +}What's the purpose of the
pcie_find_root_port()check? PCI is a hierarchy, not a graph, so a device cannot have any other Root Port but the one below which you're searching.If the purpose is to check that the port is a Root Port (if the PCI IDs you're using in the DECLARE_PCI_FIXUP_* clauses match non-Root Ports), check for
pci_pcie_type(pdev)==PCI_EXP_TYPE_ROOT_PORT. (No need to check for that in every loop iteration obviously, just check once in the fixup.)Thanks,
Lukas
Quoted 8 lines
Quoted 5 lines
The reason to look for it the way that I did was that there are multiple root ports with the exact same PCI ID.
The problem only occurs on the root port that happens to have an AMD USB4 controller connected.
Yes but what's the purpose of the
pcie_find_root_port(child)check quoted above?You're right that if you look at this system alone that the check isn't strictly necessary. It's to future proof the quirk. If a discrete USB4 controller was connected to the system it would be connected to a different root port (the one that is used for PCI tunneling).
Quoted 5 lines
AMD doesn't have any of these devices, but if some day one was created it could trip this codepath.
If you feel it's better to remove the check unless such a device is created sure I can drop it.
PCIe ports used for Thunderbolt tunneling are Downstream Ports or Upstream Ports (depending on which of the two ends of the tunnel you're looking at).
The "pcie_find_root_port(child) != pdev" check is always false:
You're searching for a USB controller below a Root Port and check whether the Root Port in the USB controller's ancestry is the Root Port below which you're searching. That's a tautology.
I'm guessing what you really mean is:
if (pci_upstream_bridge(child)) != pdev) continue;
Thanks,
Lukas
Re: [PATCH v19 2/2] PCI: Add a quirk for AMD PCIe root ports w/ USB4 controllers
Quoted 51 lines · Lukas Wunner
Quoted 50 lines · Mario Limonciello
Quoted 32 lines · Lukas Wunner
Quoted 31 lines · Mario Limonciello
Quoted 29 lines · Lukas Wunner
Quoted 4 lines · Mario Limonciello
drivers/pci/quirks.c +4
-0+static bool child_has_amd_usb4 (struct pci_dev *pdev) +{ +struct pci_dev *child =NULL ; +drivers/pci/quirks.c DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x9a31, dpc_log_size); · line 6214
Quoted 10 lines
drivers/pci/quirks.c +10
-0+while ((child =pci_get_class (PCI_CLASS_SERIAL_USB_USB4 , child))) { +if (child->vendor !=PCI_VENDOR_ID_AMD ) +continue ; +if (pcie_find_root_port (child) != pdev) +continue ; +return true; + } + +return false; +}What's the purpose of the
pcie_find_root_port()check? PCI is a hierarchy, not a graph, so a device cannot have any other Root Port but the one below which you're searching.If the purpose is to check that the port is a Root Port (if the PCI IDs you're using in the DECLARE_PCI_FIXUP_* clauses match non-Root Ports), check for
pci_pcie_type(pdev)==PCI_EXP_TYPE_ROOT_PORT. (No need to check for that in every loop iteration obviously, just check once in the fixup.)Thanks,
Lukas
Quoted 8 lines
Quoted 5 lines
The reason to look for it the way that I did was that there are multiple root ports with the exact same PCI ID.
The problem only occurs on the root port that happens to have an AMD USB4 controller connected.
Yes but what's the purpose of the
pcie_find_root_port(child)check quoted above?You're right that if you look at this system alone that the check isn't strictly necessary. It's to future proof the quirk. If a discrete USB4 controller was connected to the system it would be connected to a different root port (the one that is used for PCI tunneling).
AMD doesn't have any of these devices, but if some day one was created it could trip this codepath.
Quoted 6 lines
Quoted 2 lines
If you feel it's better to remove the check unless such a device is created sure I can drop it.
PCIe ports used for Thunderbolt tunneling are Downstream Ports or Upstream Ports (depending on which of the two ends of the tunnel you're looking at).
Let me explain the topology from an actual system with PCIe tunneling active and a dock connected downstream.
-[0000:00]-+-00.0
+-04.1-[33-62]----00.0-[34-36]--+-02.0-[35]----00.0
| \-04.0-[36]--
+-08.3-[64]--+-00.0
| +-00.3
| +-00.4
| +-00.5
| \-00.6This is the root port that tunneled devices will connect to:
$ sudo lspci -s 0000:00:04.1 -v | grep "Capabilities: \[58\]"
Capabilities: [58] Express Root Port (Slot+), MSI 00This is the root port that the USB4 controllers are connected to that is problematic:
$ sudo lspci -s 0000:00:08.3 -v | grep "Capabilities: \[58\]"
Capabilities: [58] Express Root Port (Slot-), MSI 00Here's a downstream connected dock from tunneling:
33:00.0 PCI bridge [0604]: Intel Corporation JHL7540 Thunderbolt 3 Bridge [Titan Ridge DD 2018] [8086:15ef] (rev 06) 34:02.0 PCI bridge [0604]: Intel Corporation JHL7540 Thunderbolt 3 Bridge [Titan Ridge DD 2018] [8086:15ef] (rev 06) 34:04.0 PCI bridge [0604]: Intel Corporation JHL7540 Thunderbolt 3 Bridge [Titan Ridge DD 2018] [8086:15ef] (rev 06)
Here's the USB4 controllers connected to 08.3:
64:00.0 USB controller [0c03]: Advanced Micro Devices, Inc. [AMD] Device [1022:161f] 64:00.3 USB controller [0c03]: Advanced Micro Devices, Inc. [AMD] Device [1022:15d6] 64:00.4 USB controller [0c03]: Advanced Micro Devices, Inc. [AMD] Device [1022:15d7] 64:00.5 USB controller [0c03]: Advanced Micro Devices, Inc. [AMD] Device [1022:162e] 64:00.6 USB controller [0c03]: Advanced Micro Devices, Inc. [AMD] Device [1022:162f]
If an AMD USB4 controller happened to be connected, it would have shown up connected to 04.1 as it's root port.
Quoted 7 lines
The "
pcie_find_root_port(child)!= pdev" check is always false:You're searching for a USB controller below a Root Port and check whether the Root Port in the USB controller's ancestry is the Root Port below which you're searching. That's a tautology.
The search doesn't start at pdev, it starts at NULL.
struct pci_dev *child = NULL;
Quoted 6 lines
I'm guessing what you really mean is:
if (pci_upstream_bridge(child)) != pdev) continue;
That's exactly what I had before and Rafael suggested [1] to change it to pcie_find_root_port().
[1] https://lore.kernel.org/linux-usb/[email protected]/T/#m66acb79a13d314b5e868993b1611266a968cf064
Quoted 3 lines
Thanks,
Lukas
Re: [PATCH v19 2/2] PCI: Add a quirk for AMD PCIe root ports w/ USB4 controllers
In reply to Lukas WunnerQuoted 21 lines · Lukas Wunner
Quoted 18 lines · Mario Limonciello
Quoted 17 lines · Lukas Wunner
Quoted 16 lines · Mario Limonciello
Quoted 15 lines · Lukas Wunner
Quoted 14 lines · Mario Limonciello
drivers/pci/quirks.c +14
-0+static bool child_has_amd_usb4 (struct pci_dev *pdev) +{ +struct pci_dev *child =NULL ; + +while ((child =pci_get_class (PCI_CLASS_SERIAL_USB_USB4 , child))) { +if (child->vendor !=PCI_VENDOR_ID_AMD ) +continue ; +if (pcie_find_root_port (child) != pdev) +continue ; +return true; + } + +return false; +}...
Quoted 1 line
The "
pcie_find_root_port(child)!= pdev" check is always false:
If we were using pci_walk_bus() and only looking at devices below pdev, I would agree, but since we're using pci_get_class(), which searches all PCI devices in the system, I'm confused about why it would always be false.
I don't really see the point of checking for USB4, because the commit log doesn't say anything about why this would be specific to USB4.
I know Mario has mentioned something about how "internal interrupt routing works with the USB4 controller connected to this root port," but I don't understand what that means.
Is the USB4 controller integrated into the Root Port? Or is this interrupt routed via some non-PCIe mechanism? If the USB4 controller is connected via standard PCIe, I don't see why the issue sould be specific to USB4.
I could believe that BIOS configures the Root Port differently based on whether the downstream device is USB4, but I haven't heard anything about that.
Bjorn
Re: [PATCH v19 2/2] PCI: Add a quirk for AMD PCIe root ports w/ USB4 controllers
Quoted 10 lines · Bjorn Helgaas
Quoted 1 line
The "
pcie_find_root_port(child)!= pdev" check is always false:If we were using
pci_walk_bus()and only looking at devices below pdev, I would agree, but since we're usingpci_get_class(), which searches all PCI devices in the system, I'm confused about why it would always be false.I don't really see the point of checking for USB4, because the commit log doesn't say anything about why this would be specific to USB4.
Quoted 8 lines
I know Mario has mentioned something about how "internal interrupt routing works with the USB4 controller connected to this root port," but I don't understand what that means.
Is the USB4 controller integrated into the Root Port? Or is this interrupt routed via some non-PCIe mechanism? If the USB4 controller is connected via standard PCIe, I don't see why the issue sould be specific to USB4.
It's the latter. When the PMC has the SoC in hardware sleep the interrupt routing works differently.
That's where this bug stems from.
Quoted 6 lines
I could believe that BIOS configures the Root Port differently based on whether the downstream device is USB4, but I haven't heard anything about that.
Bjorn
Nothing along these lines.
Re: [PATCH v19 2/2] PCI: Add a quirk for AMD PCIe root ports w/ USB4 controllers
In reply to Bjorn HelgaasQuoted 7 lines · Bjorn Helgaas
Quoted 1 line · Lukas Wunner
The "
pcie_find_root_port(child)!= pdev" check is always false:If we were using
pci_walk_bus()and only looking at devices below pdev, I would agree, but since we're usingpci_get_class(), which searches all PCI devices in the system, I'm confused about why it would always be false.
Right, I had misread the patch, I indeed thought it was using pci_walk_bus(). My apologies for the noise.
(I guess I assumed that because a global search (as done here) is more expensive than just searching below the Root Port.)
Thanks,
Lukas
Re: [PATCH v19 2/2] PCI: Add a quirk for AMD PCIe root ports w/ USB4 controllers
In reply to Mario LimoncielloQuoted 39 lines · Mario Limonciello
Iain reports that USB devices can't be used to wake a Lenovo Z13 from suspend. This problem occurs because the PCIe root port has been put into D3hot and AMD's platform can't handle USB devices waking the platform from a hardware sleep state in this case. The platform is put into a hardware sleep state by the actions of the amd-pmc driver.
Although the issue is initially reported on a single model it actually affects all Yellow Carp (Rembrandt) and Pink Sardine (Phoenix) SoCs. This problem only occurs on Linux specifically when attempting to wake the platform from a hardware sleep state.
Comparing the behavior on Windows and Linux, Windows doesn't put the root ports into D3 at this time.Linux decides the target state to put the device into at suspend by this policy:
1. Ifplatform_pci_power_manageable():
Useplatform_pci_choose_state()
2. If the device is armed for wakeup:
Select the deepest D-state that supports a PME.
3. Else:
Use D3hot.Devices are considered power manageable by the platform when they have one or more objects described in the table in section 7.3 of the ACPI 6.5 specification [1]. In this case the root ports are not power manageable.
If devices are not considered power manageable; specs are ambiguous as to what should happen. In this situation Windows 11 puts PCIe ports in D0 ostensibly due the policy from the "uPEP driver" which is a complimentary driver the Linux "amd-pmc" driver.
Linux chooses to allow D3 for these root ports due to the policy introduced by commit
9d26d3a8f1b0("PCI: Put PCIe ports into D3 during suspend").The Windows uPEP driver expresses the desired state that should be selected for suspend but Linux doesn't, so introduce a quirk for the problematic root ports.
Quoted 7 lines
The quirk removes PME support for D3hot and D3cold at suspend time if the system will be using s2idle. When the port is configured for wakeup this will prevent these states from being selected in
pci_target_state().After the system is resumes the PME support is re-read from the PM capabilities register to allow opportunistic power savings at runtime by letting the root port go into D3hot or D3cold.
There's a lot of text here, but I think the essential thing is:
These Root Ports advertise D3hot and D3cold in the PME_Support register, but PMEs do not work in those states when the amd-pmc driver has put the platform in a sleep state.
Quoted 54 lines
Fixes 9d26d3a8f1b0 ("PCI: Put PCIe ports into D3 during suspend")Reported-by Iain Lane <[email protected]>Signed-off-by Mario Limonciello <[email protected]>--- drivers/pci/quirks.c | 61 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+)drivers/pci/quirks.c +36
-0@@ -6188,3 +6188,64 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x9a31, dpc_log_size);DECLARE_PCI_FIXUP_FINAL (PCI_VENDOR_ID_XILINX ,0x5020 , of_pci_make_dev_node);DECLARE_PCI_FIXUP_FINAL (PCI_VENDOR_ID_XILINX ,0x5021 , of_pci_make_dev_node);DECLARE_PCI_FIXUP_FINAL (PCI_VENDOR_ID_REDHAT ,0x0005 , of_pci_make_dev_node); + +/* +* When AMD PCIe root ports with AMD USB4 controllers attached to them are put +* into D3hot or D3cold downstream USB devices may fail to wakeup the system. +* This manifests as a missing wakeup interrupt. +* +* Prevent the associated root port from using PME to wake from D3hot or +* D3cold power states during s2idle. +* This will effectively put the root port into D0 power state over s2idle. +*/ +static bool child_has_amd_usb4 (struct pci_dev *pdev) +{ +struct pci_dev *child =NULL ; + +while ((child =pci_get_class (PCI_CLASS_SERIAL_USB_USB4 , child))) { +if (child->vendor !=PCI_VENDOR_ID_AMD ) +continue ; +if (pcie_find_root_port (child) != pdev) +continue ; +return true; + } + +return false; +} + +static void quirk_reenable_pme (struct pci_dev *dev) +{ +u16 pmc; + +if (!dev->pm_cap) +return ; + +if (!child_has_amd_usb4 (dev)) +return ; + +pci_read_config_word (dev, dev->pm_cap +PCI_PM_PMC , &pmc);
drivers/pci/quirks.c DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x9a31, dpc_log_size); · line 6236
Quoted 10 lines
drivers/pci/quirks.c +10
-0+ pmc &=PCI_PM_CAP_PME_MASK ; + dev->pme_support = pmc >>PCI_PM_CAP_PME_SHIFT ; +} + +static void quirk_disable_pme_suspend (struct pci_dev *dev) +{ +int mask; + +if (pm_suspend_via_firmware ()) +return ;
There's always something more to confuse me. Why does pm_suspend_via_firmware() matter? I can sort of see that Linux platform power management, which uses the PMC, is not the same as platform firmware being invoked at the end of a system-wide power management transition to a sleep state.
I guess this must have something to do with acpi_suspend_begin() and acpi_hibernation_begin() (the callers of pm_set_suspend_via_firmware())?
Quoted 17 lines
drivers/pci/quirks.c +14
-0+if (!child_has_amd_usb4 (dev)) +return ; + + mask = (PCI_PM_CAP_PME_D3hot|PCI_PM_CAP_PME_D3cold) >>PCI_PM_CAP_PME_SHIFT ; +if (!(dev->pme_support & mask)) +return ; + dev->pme_support &= ~mask; +dev_info_once (&dev->dev,"quirk: disabling PME from D3hot and D3cold at suspend\n" ); +} + +DECLARE_PCI_FIXUP_SUSPEND (PCI_VENDOR_ID_AMD ,0x14b9 , quirk_disable_pme_suspend); +DECLARE_PCI_FIXUP_RESUME (PCI_VENDOR_ID_AMD ,0x14b9 , quirk_reenable_pme); +DECLARE_PCI_FIXUP_SUSPEND (PCI_VENDOR_ID_AMD ,0x14eb , quirk_disable_pme_suspend); +DECLARE_PCI_FIXUP_RESUME (PCI_VENDOR_ID_AMD ,0x14eb , quirk_reenable_pme);Signature · 1 line
2.34.1
Re: [PATCH v19 2/2] PCI: Add a quirk for AMD PCIe root ports w/ USB4 controllers
Quoted 48 lines · Bjorn Helgaas
Quoted 39 lines · Mario Limonciello
Iain reports that USB devices can't be used to wake a Lenovo Z13 from suspend. This problem occurs because the PCIe root port has been put into D3hot and AMD's platform can't handle USB devices waking the platform from a hardware sleep state in this case. The platform is put into a hardware sleep state by the actions of the amd-pmc driver.
Although the issue is initially reported on a single model it actually affects all Yellow Carp (Rembrandt) and Pink Sardine (Phoenix) SoCs. This problem only occurs on Linux specifically when attempting to wake the platform from a hardware sleep state.
Comparing the behavior on Windows and Linux, Windows doesn't put the root ports into D3 at this time.Linux decides the target state to put the device into at suspend by this policy:
1. Ifplatform_pci_power_manageable():
Useplatform_pci_choose_state()
2. If the device is armed for wakeup:
Select the deepest D-state that supports a PME.
3. Else:
Use D3hot.Devices are considered power manageable by the platform when they have one or more objects described in the table in section 7.3 of the ACPI 6.5 specification [1]. In this case the root ports are not power manageable.
If devices are not considered power manageable; specs are ambiguous as to what should happen. In this situation Windows 11 puts PCIe ports in D0 ostensibly due the policy from the "uPEP driver" which is a complimentary driver the Linux "amd-pmc" driver.
Linux chooses to allow D3 for these root ports due to the policy introduced by commit
9d26d3a8f1b0("PCI: Put PCIe ports into D3 during suspend").The Windows uPEP driver expresses the desired state that should be selected for suspend but Linux doesn't, so introduce a quirk for the problematic root ports.
Quoted 7 lines
The quirk removes PME support for D3hot and D3cold at suspend time if the system will be using s2idle. When the port is configured for wakeup this will prevent these states from being selected in
pci_target_state().After the system is resumes the PME support is re-read from the PM capabilities register to allow opportunistic power savings at runtime by letting the root port go into D3hot or D3cold.
Quoted 6 lines
There's a lot of text here, but I think the essential thing is:
These Root Ports advertise D3hot and D3cold in the
PME_Supportregister, but PMEs do not work in those states when the amd-pmc driver has put the platform in a sleep state.
It's specific to the PMEs for root ports with USB4 controller connected, but yes otherwise correct.
I've confirmed that XHCI controllers connected to other root ports work fine.
Quoted 71 lines
Quoted 54 lines
Fixes 9d26d3a8f1b0 ("PCI: Put PCIe ports into D3 during suspend")Reported-by Iain Lane <[email protected]>Signed-off-by Mario Limonciello <[email protected]>--- drivers/pci/quirks.c | 61 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+)drivers/pci/quirks.c +36
-0@@ -6188,3 +6188,64 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x9a31, dpc_log_size);DECLARE_PCI_FIXUP_FINAL (PCI_VENDOR_ID_XILINX ,0x5020 , of_pci_make_dev_node);DECLARE_PCI_FIXUP_FINAL (PCI_VENDOR_ID_XILINX ,0x5021 , of_pci_make_dev_node);DECLARE_PCI_FIXUP_FINAL (PCI_VENDOR_ID_REDHAT ,0x0005 , of_pci_make_dev_node); + +/* +* When AMD PCIe root ports with AMD USB4 controllers attached to them are put +* into D3hot or D3cold downstream USB devices may fail to wakeup the system. +* This manifests as a missing wakeup interrupt. +* +* Prevent the associated root port from using PME to wake from D3hot or +* D3cold power states during s2idle. +* This will effectively put the root port into D0 power state over s2idle. +*/ +static bool child_has_amd_usb4 (struct pci_dev *pdev) +{ +struct pci_dev *child =NULL ; + +while ((child =pci_get_class (PCI_CLASS_SERIAL_USB_USB4 , child))) { +if (child->vendor !=PCI_VENDOR_ID_AMD ) +continue ; +if (pcie_find_root_port (child) != pdev) +continue ; +return true; + } + +return false; +} + +static void quirk_reenable_pme (struct pci_dev *dev) +{ +u16 pmc; + +if (!dev->pm_cap) +return ; + +if (!child_has_amd_usb4 (dev)) +return ; + +pci_read_config_word (dev, dev->pm_cap +PCI_PM_PMC , &pmc);drivers/pci/quirks.c DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x9a31, dpc_log_size); · line 6236
Quoted 10 lines
drivers/pci/quirks.c +10
-0+ pmc &=PCI_PM_CAP_PME_MASK ; + dev->pme_support = pmc >>PCI_PM_CAP_PME_SHIFT ; +} + +static void quirk_disable_pme_suspend (struct pci_dev *dev) +{ +int mask; + +if (pm_suspend_via_firmware ()) +return ;There's always something more to confuse me. Why does
pm_suspend_via_firmware()matter? I can sort of see that Linux platform power management, which uses the PMC, is not the same as platform firmware being invoked at the end of a system-wide power management transition to a sleep state.
Quoted 4 lines
I guess this must have something to do with
acpi_suspend_begin()andacpi_hibernation_begin()(the callers ofpm_set_suspend_via_firmware())?
The "why" has to do with the implementation details of how the platform enters and exits hardware sleep and what happens. It's much different than how ACPI S3 works.
Most OEM platforms don't support S3, so if it distracts from the issue and quirk I'm fine to drop this check.
Quoted 17 lines
Quoted 17 lines
drivers/pci/quirks.c +14
-0+if (!child_has_amd_usb4 (dev)) +return ; + + mask = (PCI_PM_CAP_PME_D3hot|PCI_PM_CAP_PME_D3cold) >>PCI_PM_CAP_PME_SHIFT ; +if (!(dev->pme_support & mask)) +return ; + dev->pme_support &= ~mask; +dev_info_once (&dev->dev,"quirk: disabling PME from D3hot and D3cold at suspend\n" ); +} + +DECLARE_PCI_FIXUP_SUSPEND (PCI_VENDOR_ID_AMD ,0x14b9 , quirk_disable_pme_suspend); +DECLARE_PCI_FIXUP_RESUME (PCI_VENDOR_ID_AMD ,0x14b9 , quirk_reenable_pme); +DECLARE_PCI_FIXUP_SUSPEND (PCI_VENDOR_ID_AMD ,0x14eb , quirk_disable_pme_suspend); +DECLARE_PCI_FIXUP_RESUME (PCI_VENDOR_ID_AMD ,0x14eb , quirk_reenable_pme);Signature · 1 line
2.34.1
Re: [PATCH v19 2/2] PCI: Add a quirk for AMD PCIe root ports w/ USB4 controllers
In reply to Mario LimoncielloQuoted 93 lines · Mario Limonciello
Iain reports that USB devices can't be used to wake a Lenovo Z13 from suspend. This problem occurs because the PCIe root port has been put into D3hot and AMD's platform can't handle USB devices waking the platform from a hardware sleep state in this case. The platform is put into a hardware sleep state by the actions of the amd-pmc driver.
Although the issue is initially reported on a single model it actually affects all Yellow Carp (Rembrandt) and Pink Sardine (Phoenix) SoCs. This problem only occurs on Linux specifically when attempting to wake the platform from a hardware sleep state.
Comparing the behavior on Windows and Linux, Windows doesn't put the root ports into D3 at this time.Linux decides the target state to put the device into at suspend by this policy:
1. Ifplatform_pci_power_manageable():
Useplatform_pci_choose_state()
2. If the device is armed for wakeup:
Select the deepest D-state that supports a PME.
3. Else:
Use D3hot.Devices are considered power manageable by the platform when they have one or more objects described in the table in section 7.3 of the ACPI 6.5 specification [1]. In this case the root ports are not power manageable.
If devices are not considered power manageable; specs are ambiguous as to what should happen. In this situation Windows 11 puts PCIe ports in D0 ostensibly due the policy from the "uPEP driver" which is a complimentary driver the Linux "amd-pmc" driver.
Linux chooses to allow D3 for these root ports due to the policy introduced by commit
9d26d3a8f1b0("PCI: Put PCIe ports into D3 during suspend").The Windows uPEP driver expresses the desired state that should be selected for suspend but Linux doesn't, so introduce a quirk for the problematic root ports.
The quirk removes PME support for D3hot and D3cold at suspend time if the system will be using s2idle. When the port is configured for wakeup this will prevent these states from being selected in
pci_target_state().After the system is resumes the PME support is re-read from the PM capabilities register to allow opportunistic power savings at runtime by letting the root port go into D3hot or D3cold.
Fixes 9d26d3a8f1b0 ("PCI: Put PCIe ports into D3 during suspend")Reported-by Iain Lane <[email protected]>Signed-off-by Mario Limonciello <[email protected]>--- drivers/pci/quirks.c | 61 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+)drivers/pci/quirks.c +28
-0@@ -6188,3 +6188,64 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x9a31, dpc_log_size);DECLARE_PCI_FIXUP_FINAL (PCI_VENDOR_ID_XILINX ,0x5020 , of_pci_make_dev_node);DECLARE_PCI_FIXUP_FINAL (PCI_VENDOR_ID_XILINX ,0x5021 , of_pci_make_dev_node);DECLARE_PCI_FIXUP_FINAL (PCI_VENDOR_ID_REDHAT ,0x0005 , of_pci_make_dev_node); + +/* +* When AMD PCIe root ports with AMD USB4 controllers attached to them are put +* into D3hot or D3cold downstream USB devices may fail to wakeup the system. +* This manifests as a missing wakeup interrupt. +* +* Prevent the associated root port from using PME to wake from D3hot or +* D3cold power states during s2idle. +* This will effectively put the root port into D0 power state over s2idle. +*/ +static bool child_has_amd_usb4 (struct pci_dev *pdev) +{ +struct pci_dev *child =NULL ; + +while ((child =pci_get_class (PCI_CLASS_SERIAL_USB_USB4 , child))) { +if (child->vendor !=PCI_VENDOR_ID_AMD ) +continue ; +if (pcie_find_root_port (child) != pdev) +continue ; +return true; + } + +return false; +} + +static void quirk_reenable_pme (struct pci_dev *dev) +{ +u16 pmc;
drivers/pci/quirks.c DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x9a31, dpc_log_size); · line 6228
Quoted 10 lines
drivers/pci/quirks.c +10
-0+ +if (!dev->pm_cap) +return ; + +if (!child_has_amd_usb4 (dev)) +return ; + +pci_read_config_word (dev, dev->pm_cap +PCI_PM_PMC , &pmc); + pmc &=PCI_PM_CAP_PME_MASK ; + dev->pme_support = pmc >>PCI_PM_CAP_PME_SHIFT ;
FIELD_GET(PCI_PM_CAP_PME_MASK, pmc);
Signature · 1 line
i.
Quoted 24 lines
drivers/pci/quirks.c +23
-0+} + +static void quirk_disable_pme_suspend (struct pci_dev *dev) +{ +int mask; + +if (pm_suspend_via_firmware ()) +return ; + +if (!child_has_amd_usb4 (dev)) +return ; + + mask = (PCI_PM_CAP_PME_D3hot|PCI_PM_CAP_PME_D3cold) >>PCI_PM_CAP_PME_SHIFT ; +if (!(dev->pme_support & mask)) +return ; + dev->pme_support &= ~mask; +dev_info_once (&dev->dev,"quirk: disabling PME from D3hot and D3cold at suspend\n" ); +} + +DECLARE_PCI_FIXUP_SUSPEND (PCI_VENDOR_ID_AMD ,0x14b9 , quirk_disable_pme_suspend); +DECLARE_PCI_FIXUP_RESUME (PCI_VENDOR_ID_AMD ,0x14b9 , quirk_reenable_pme); +DECLARE_PCI_FIXUP_SUSPEND (PCI_VENDOR_ID_AMD ,0x14eb , quirk_disable_pme_suspend); +DECLARE_PCI_FIXUP_RESUME (PCI_VENDOR_ID_AMD ,0x14eb , quirk_reenable_pme);