]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
PCI: vmd: Add quirk to configure PCIe ASPM and LTR
authorDavid E. Box <david.e.box@linux.intel.com>
Wed, 6 Sep 2023 07:54:19 +0000 (15:54 +0800)
committerRoxana Nicolescu <roxana.nicolescu@canonical.com>
Mon, 2 Oct 2023 15:20:28 +0000 (17:20 +0200)
BugLink: https://bugs.launchpad.net/bugs/2034504
PCIe ports reserved for VMD use are not visible to BIOS and therefore not
configured to enable PCIe ASPM or LTR values (which BIOS will configure if
they are not set). Lack of this programming results in high power
consumption on laptops as reported in bugzilla.  For affected products use
pci_enable_link_state to set the allowed link states for devices on the
root ports. Also set the LTR value to the maximum value needed for the SoC.

This is a workaround for products from Rocket Lake through Alder Lake.
Raptor Lake, the latest product at this time, has already implemented LTR
configuring in BIOS. Future products will move ASPM configuration back to
BIOS as well.  As this solution is intended for laptops, support is not
added for hotplug or for devices downstream of a switch on the root port.

Link: https://bugzilla.kernel.org/show_bug.cgi?id=212355
Link: https://bugzilla.kernel.org/show_bug.cgi?id=215063
Link: https://bugzilla.kernel.org/show_bug.cgi?id=213717
Link: https://lore.kernel.org/r/20230120031522.2304439-5-david.e.box@linux.intel.com
Signed-off-by: Michael Bottini <michael.a.bottini@linux.intel.com>
Signed-off-by: David E. Box <david.e.box@linux.intel.com>
Signed-off-by: Lorenzo Pieralisi <lpieralisi@kernel.org>
Reviewed-by: Jon Derrick <jonathan.derrick@linux.dev>
Reviewed-by: Nirmal Patel <nirmal.patel@linux.intel.com>
Reviewed-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
(cherry picked from commit f492edb40b54862cbd65e6aa5eb39fa40f9949bf)
Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
Acked-by: Stefan Bader <stefan.bader@canonical.com>
Acked-by: Tim Gardner <tim.gardner@canonical.com>
Signed-off-by: Roxana Nicolescu <roxana.nicolescu@canonical.com>
drivers/pci/controller/vmd.c

index 747c2a44d9e35a02e95ae9784b0d8dccef279dea..98c60dae608bcc78957dd2341157c7c04be81935 100644 (file)
@@ -66,11 +66,22 @@ enum vmd_features {
         * interrupt handling.
         */
        VMD_FEAT_CAN_BYPASS_MSI_REMAP           = (1 << 4),
+
+       /*
+        * Enable ASPM on the PCIE root ports and set the default LTR of the
+        * storage devices on platforms where these values are not configured by
+        * BIOS. This is needed for laptops, which require these settings for
+        * proper power management of the SoC.
+        */
+       VMD_FEAT_BIOS_PM_QUIRK          = (1 << 5),
 };
 
+#define VMD_BIOS_PM_QUIRK_LTR  0x1003  /* 3145728 ns */
+
 #define VMD_FEATS_CLIENT       (VMD_FEAT_HAS_MEMBAR_SHADOW_VSCAP |     \
                                 VMD_FEAT_HAS_BUS_RESTRICTIONS |        \
-                                VMD_FEAT_OFFSET_FIRST_VECTOR)
+                                VMD_FEAT_OFFSET_FIRST_VECTOR |         \
+                                VMD_FEAT_BIOS_PM_QUIRK)
 
 static DEFINE_IDA(vmd_instance_ida);
 
@@ -713,6 +724,46 @@ static void vmd_copy_host_bridge_flags(struct pci_host_bridge *root_bridge,
        vmd_bridge->native_dpc = root_bridge->native_dpc;
 }
 
+/*
+ * Enable ASPM and LTR settings on devices that aren't configured by BIOS.
+ */
+static int vmd_pm_enable_quirk(struct pci_dev *pdev, void *userdata)
+{
+       unsigned long features = *(unsigned long *)userdata;
+       u16 ltr = VMD_BIOS_PM_QUIRK_LTR;
+       u32 ltr_reg;
+       int pos;
+
+       if (!(features & VMD_FEAT_BIOS_PM_QUIRK))
+               return 0;
+
+       pci_enable_link_state(pdev, PCIE_LINK_STATE_ALL);
+
+       pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_LTR);
+       if (!pos)
+               return 0;
+
+       /*
+        * Skip if the max snoop LTR is non-zero, indicating BIOS has set it
+        * so the LTR quirk is not needed.
+        */
+       pci_read_config_dword(pdev, pos + PCI_LTR_MAX_SNOOP_LAT, &ltr_reg);
+       if (!!(ltr_reg & (PCI_LTR_VALUE_MASK | PCI_LTR_SCALE_MASK)))
+               return 0;
+
+       /*
+        * Set the default values to the maximum required by the platform to
+        * allow the deepest power management savings. Write as a DWORD where
+        * the lower word is the max snoop latency and the upper word is the
+        * max non-snoop latency.
+        */
+       ltr_reg = (ltr << 16) | ltr;
+       pci_write_config_dword(pdev, pos + PCI_LTR_MAX_SNOOP_LAT, ltr_reg);
+       pci_info(pdev, "VMD: Default LTR value set by driver\n");
+
+       return 0;
+}
+
 static int vmd_enable_domain(struct vmd_dev *vmd, unsigned long features)
 {
        struct pci_sysdata *sd = &vmd->sysdata;
@@ -890,6 +941,8 @@ static int vmd_enable_domain(struct vmd_dev *vmd, unsigned long features)
 
        pci_assign_unassigned_bus_resources(vmd->bus);
 
+       pci_walk_bus(vmd->bus, vmd_pm_enable_quirk, &features);
+
        /*
         * VMD root buses are virtual and don't return true on pci_is_pcie()
         * and will fail pcie_bus_configure_settings() early. It can instead be