[PATCH] PCI: Avoid D3 in rumtime PM for AMD gfx v12 PCIe switch upstream port

From: Yifan Zhang

Date: Wed Dec 02 2026 - 21:16:02 EST


Do not put the upstream link on gfx v12 cards to D3 at runtime due to hardware
limitation. It can still runtime suspend, but then stays in D0. System
suspend is not affected and still uses D3.

Signed-off-by: Yifan Zhang <yifan1.zhang@xxxxxxx>
---
drivers/pci/quirks.c | 50 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 50 insertions(+)

diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c
index b09f27f7846f..5f87606bf7a2 100644
--- a/drivers/pci/quirks.c
+++ b/drivers/pci/quirks.c
@@ -2085,6 +2085,56 @@ DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, 0x15e0, quirk_ryzen_xhci_d3hot);
DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, 0x15e1, quirk_ryzen_xhci_d3hot);
DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, 0x1639, quirk_ryzen_xhci_d3hot);

+/*
+ * Do not put the upstream link on gfx v12 cards to D3 at runtime due to hardware
+ * limitation. It can still runtime suspend, but then stays in D0. System
+ * suspend is not affected and still uses D3.
+ *
+ * The switch has the same device ID on all Navi cards, so the affected ones
+ * are identified by the major and minor revision of the port, which are the
+ * upper and lower nibble of the PCI Revision ID.
+ */
+#define AMD_NAVI_SWUS_REV_MAJOR GENMASK(7, 4)
+#define AMD_NAVI_SWUS_REV_MINOR GENMASK(3, 0)
+
+static bool amd_gfx12_swus_no_runtime_d3(struct pci_dev *pdev)
+{
+ u8 major = FIELD_GET(AMD_NAVI_SWUS_REV_MAJOR, pdev->revision);
+ u8 minor = FIELD_GET(AMD_NAVI_SWUS_REV_MINOR, pdev->revision);
+
+ /* gfx v12 sw.us revision id 2.4 - 2.5 */
+ return major == 2 && minor >= 4 && minor <= 5;
+}
+
+/* Only log that the quirk applies, the suspend fixup below handles the flag */
+static void quirk_amd_gfx12_swus_no_d3(struct pci_dev *pdev)
+{
+ if (!amd_gfx12_swus_no_runtime_d3(pdev))
+ return;
+
+ pci_info(pdev, "PCIe switch upstream port (rev %lu.%lu), disabling D3 for runtime PM\n",
+ FIELD_GET(AMD_NAVI_SWUS_REV_MAJOR, pdev->revision),
+ FIELD_GET(AMD_NAVI_SWUS_REV_MINOR, pdev->revision));
+}
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_ATI, 0x1478, quirk_amd_gfx12_swus_no_d3);
+
+/*
+ * pci_fixup_suspend runs before the PCI core selects the power state, for
+ * runtime suspend as well as for system suspend. Keep the port out of D3
+ * only for the former.
+ */
+static void quirk_amd_gfx12_swus_suspend(struct pci_dev *pdev)
+{
+ if (!amd_gfx12_swus_no_runtime_d3(pdev))
+ return;
+
+ if (pm_suspend_in_progress())
+ pdev->dev_flags &= ~PCI_DEV_FLAGS_NO_D3;
+ else
+ pdev->dev_flags |= PCI_DEV_FLAGS_NO_D3;
+}
+DECLARE_PCI_FIXUP_SUSPEND(PCI_VENDOR_ID_ATI, 0x1478, quirk_amd_gfx12_swus_suspend);
+
#ifdef CONFIG_X86_IO_APIC
static int dmi_disable_ioapicreroute(const struct dmi_system_id *d)
{
--
2.53.0