PCI: Move VMD ASPM/LTR fix to PCI quirk
Subsystems (3)
PATCH v2 1/1 PCI: Move VMD ASPM/LTR fix to PCI quirk
In commit f492edb40b54 ("PCI: vmd: Add quirk to configure PCIe ASPM and LTR") the VMD driver calls pci_enabled_link_state as a callback from pci_bus_walk. Both will acquire the pci_bus_sem lock leading to a lockdep warning. Instead of doing the pci_bus_walk, move the fix to quirks.c using DECLARE_PCI_FIXUP_FINAL.
---
V2 - Instead of adding a lock flag argument to pci_enabled_link_state, move
the fix to quirks.c
drivers/pci/controller/vmd.c | 55 +-------------------------- drivers/pci/quirks.c | 72 ++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 54 deletions(-)
drivers/pci/controller/vmd.c +1 -54
@@ -66,22 +66,11 @@ 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_BIOS_PM_QUIRK) + VMD_FEAT_OFFSET_FIRST_VECTOR)static DEFINE_IDA (vmd_instance_ida);
@@ -724,46 +713,6 @@ 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 , <r_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;
@@ -936,8 +885,6 @@ 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
drivers/pci/quirks.c +72 -0
75 lines not on this page · raw message
Signature · 1 line
2.34.1
Patchwork
CI[Intel-gfx] ✗ Fi.CI.BUILD: failure for PCI: Move VMD ASPM/LTR fix to PCI quirk
== Series Details ==
== Series Details ==
Series: PCI: Move VMD ASPM/LTR fix to PCI quirk
URL : https://patchwork.freedesktop.org/series/116343/
State : failure
== Summary ==
Error: patch https://patchwork.freedesktop.org/api/1.0/series/116343/revisions/1/mbox/ not applied
Applying: PCI: Move VMD ASPM/LTR fix to PCI quirk
Using index info to reconstruct a base tree...
M drivers/pci/controller/vmd.c
Falling back to patching base and 3-way merge...
Auto-merging drivers/pci/controller/vmd.c
CONFLICT (content): Merge conflict in drivers/pci/controller/vmd.c
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0001 PCI: Move VMD ASPM/LTR fix to PCI quirk
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
Build failed, no error log produced
Quoted 5 lines · David E. Box
In commit
f492edb40b54("PCI: vmd: Add quirk to configure PCIe ASPM and LTR") the VMD driver callspci_enabled_link_stateas a callback frompci_bus_walk. Both will acquire thepci_bus_semlock leading to a lockdep warning. Instead of doing thepci_bus_walk, move the fix toquirks.cusingDECLARE_PCI_FIXUP_FINAL.
s/pci_enabled_link_state/pci_enable_link_state/
Add "()" after pci_enable_link_state() and pci_bus_walk() to make it obvious they're functions.
drivers/pci/quirks.c DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x9a2d, dpc_log_size); · line 6032
Quoted 13 lines
...
+++b/drivers/pci/quirks.cdrivers/pci/quirks.c +7
-0@@ -6023,3 +6023,75 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x9a2d, dpc_log_size);DECLARE_PCI_FIXUP_HEADER (PCI_VENDOR_ID_INTEL ,0x9a2f , dpc_log_size);DECLARE_PCI_FIXUP_HEADER (PCI_VENDOR_ID_INTEL ,0x9a31 , dpc_log_size);#endif + +#ifdef CONFIG_VMD +/* +* Enable ASPM on the PCIE root ports under VMD 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.
s/PCIE/PCIe/ to match spec usage.
drivers/pci/quirks.c DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x9a2d, dpc_log_size); · line 6034
Quoted 2 lines
drivers/pci/quirks.c +2
-0+*/ +#define VMD_DEVICE_LTR 0x1003/* 3145728 ns */
It would be nice to know how this value was derived. But I know we had this hard-coded value before, so it's not new with this patch.
drivers/pci/quirks.c DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x9a2d, dpc_log_size); · line 6035
Quoted 1 line
drivers/pci/quirks.c +1
-0+static void quirk_intel_vmd (struct pci_dev *pdev)
I think this quirk could possibly stay in drivers/pci/controller/vmd.c, couldn't it? It has a lot of VMD-specific knowledge that it would nice to contain in vmd.c.
drivers/pci/quirks.c DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x9a2d, dpc_log_size); · line 6038
Quoted 3 lines
drivers/pci/quirks.c +3
-0+{ +struct pci_dev *parent; +u16 ltr =VMD_DEVICE_LTR ;
I don't think "ltr" is an improvement over using "VMD_DEVICE_LTR" below.
drivers/pci/quirks.c DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x9a2d, dpc_log_size); · line 6044
Quoted 6 lines
drivers/pci/quirks.c +6
-0+u32 ltr_reg; +int pos; + +/* Check in VMD domain */ +if (pci_domain_nr (pdev->bus) <0x10000 ) +return ;
If in vmd.c, maybe could identify devices under a VMD by checking pdev->bus->ops as vmd_acpi_find_companion() does?
Quoted 18 lines
drivers/pci/quirks.c +18
-0+/* Get Root Port */ + parent =pci_upstream_bridge (pdev); +if (!parent || parent->vendor !=PCI_VENDOR_ID_INTEL ) +return ; + +/* Get VMD Host Bridge */ + parent =to_pci_dev (parent->dev.parent); +if (!parent) +return ; + +/* Get RAID controller */ + parent =to_pci_dev (parent->dev.parent); +if (!parent) +return ; + +switch (parent->device) { +case 0x467f : +case 0x4c3d :
drivers/pci/quirks.c DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x9a2d, dpc_log_size); · line 6073
Quoted 10 lines
drivers/pci/quirks.c +10
-0+case 0xa77f : +case 0x7d0b : +case 0xad0b : +case 0x9a0b : +break ; +default : +return ; + } + +pci_enable_link_state (pdev,PCIE_LINK_STATE_ALL );
Seems like you would want to set LTR *before* enabling the link states?
Quoted 4 lines
drivers/pci/quirks.c +4
-0+ pos =pci_find_ext_capability (pdev,PCI_EXT_CAP_ID_LTR ); +if (!pos) +return ; +
drivers/pci/quirks.c DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x9a2d, dpc_log_size); · line 6088
Quoted 10 lines
drivers/pci/quirks.c +10
-0+/* Skip if the max snoop LTR is non-zero, indicating BIOS has set it */ +pci_read_config_dword (pdev, pos +PCI_LTR_MAX_SNOOP_LAT , <r_reg); +if (!!(ltr_reg & (PCI_LTR_VALUE_MASK |PCI_LTR_SCALE_MASK ))) +return ; + +/* +* Set the LTR 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.
This comment suggests that the LTR value is platform-dependent, which is what I would expect, but the code and the hard-coded VMD_DEVICE_LTR value don't have any platform dependencies. Again, nothing new in *this* patch; that's true in the current tree, too.
drivers/pci/quirks.c DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x9a2d, dpc_log_size); · line 6092
Quoted 3 lines
drivers/pci/quirks.c +3
-0+ ltr_reg = (ltr <<16 ) | ltr; +pci_write_config_dword (pdev, pos +PCI_LTR_MAX_SNOOP_LAT , ltr_reg); +pci_info (pdev,"LTR set by VMD PCI quick\n" );
s/quick/quirk/
Quoted 8 lines
drivers/pci/quirks.c +5
-0+ +} +DECLARE_PCI_FIXUP_CLASS_FINAL (PCI_ANY_ID ,PCI_ANY_ID , +PCI_CLASS_STORAGE_EXPRESS ,0 , quirk_intel_vmd); +#endif Signature · 1 line
2.34.1
Hi Bjorn,
Quoted 32 lines · Bjorn Helgaas
Quoted 5 lines · David E. Box
In commit
f492edb40b54("PCI: vmd: Add quirk to configure PCIe ASPM and LTR") the VMD driver callspci_enabled_link_stateas a callback frompci_bus_walk. Both will acquire thepci_bus_semlock leading to a lockdep warning. Instead of doing thepci_bus_walk, move the fix toquirks.cusingDECLARE_PCI_FIXUP_FINAL.s/pci_enabled_link_state/pci_enable_link_state/
Add "()" after
pci_enable_link_state()andpci_bus_walk()to make it obvious they're functions.Quoted 11 lines
...
+++b/drivers/pci/quirks.cdrivers/pci/quirks.c +0
-0@@ -6023,3 +6023,75 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x9a2d, dpc_log_size); DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x9a2f, dpc_log_size); DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x9a31, dpc_log_size);#endif
drivers/pci/quirks.c +4
-0+ +#ifdef CONFIG_VMD +/* +* Enable ASPM on the PCIE root ports under VMD and set the default LTR of Quoted 6 lines
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.s/PCIE/PCIe/ to match spec usage.
Quoted 5 lines
Quoted 2 lines
+ */
+#define VMD_DEVICE_LTR 0x1003 /* 3145728 ns */It would be nice to know how this value was derived. But I know we had this hard-coded value before, so it's not new with this patch.
Do you mean to show the multiplier that determines that value or to say why this particular number was chosen? For the latter, it the largest that could be set (given the multipier options) that will allow the SoC to get to it's lowest power state. And it's the same so far on all the SoCs covered by the VMD driver.
Quoted 6 lines
Quoted 2 lines
+static void
quirk_intel_vmd(struct pci_dev *pdev)I think this quirk could possibly stay in
drivers/pci/controller/vmd.c, couldn't it? It has a lot of VMD-specific knowledge that it would nice to contain invmd.c.
I may have misunderstood your comment on V1 then. But you suggested that this would be typically done as PCI_FIXUP so that the PCI core could call it and we could avoid the locking issue that was seen while walking the bus in vmd.c.
https://lore.kernel.org/lkml/[email protected]/T/#m09dc05ef56b8d9f104f91594f582251b6088d24d
Quoted 41 lines
Quoted 4 lines
+{
+ structpci_dev*parent;
+ u16 ltr =VMD_DEVICE_LTR;I don't think "ltr" is an improvement over using "
VMD_DEVICE_LTR" below.Quoted 6 lines
+ u32
ltr_reg;
+ int pos;
+
+ /* Check in VMD domain */
+ if (pci_domain_nr(pdev->bus)<0x10000)
+ return;If in
vmd.c, maybe could identify devices under a VMD by checkingpdev->bus->opsasvmd_acpi_find_companion()does?Quoted 23 lines
+ /* Get Root Port */
+ parent =pci_upstream_bridge(pdev);
+ if (!parent ||parent->vendor!=PCI_VENDOR_ID_INTEL) + return;drivers/pci/quirks.c +19
-0+ + /* Get VMD Host Bridge */ + parent = to_pci_dev(parent->dev.parent); + if (!parent) + return; + + /* Get RAID controller */ + parent = to_pci_dev(parent->dev.parent); + if (!parent) + return; + + switch (parent->device) { + case 0x467f: + case 0x4c3d: + case 0xa77f: + case 0x7d0b: + case 0xad0b: + case 0x9a0b: + break;
Quoted 8 lines
Quoted 5 lines
+ default:
+ return;
+ }
+
+ pci_enable_link_state(pdev,PCIE_LINK_STATE_ALL);Seems like you would want to set LTR *before* enabling the link states?
Yes that would be better. We'll still want to check if the LTR is set first though because if it is then we don't need to do either.
David
Quoted 38 lines
Quoted 17 lines
+ pos =
pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_LTR); + if (!pos)
+ return;
+
+ /* Skip if the max snoop LTR is non-zero, indicating BIOS has set it */
+ pci_read_config_dword(pdev, pos +PCI_LTR_MAX_SNOOP_LAT,<r_reg); + if (!!(ltr_reg & (PCI_LTR_VALUE_MASK|PCI_LTR_SCALE_MASK))) + return;
+
+ /*
+ * Set the LTR 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.This comment suggests that the LTR value is platform-dependent, which is what I would expect, but the code and the hard-coded
VMD_DEVICE_LTRvalue don't have any platform dependencies. Again, nothing new in *this* patch; that's true in the current tree, too.Quoted 3 lines
+ ltr_reg = (ltr << 16) | ltr;
+ pci_write_config_dword(pdev, pos +PCI_LTR_MAX_SNOOP_LAT,ltr_reg); + pci_info(pdev, "LTR set by VMD PCI quick\n");s/quick/quirk/
Quoted 9 lines
drivers/pci/quirks.c +4
-0+ +} +DECLARE_PCI_FIXUP_CLASS_FINAL(PCI_ANY_ID, PCI_ANY_ID, + PCI_CLASS_STORAGE_EXPRESS, 0,
quirk_intel_vmd);
+#endifSignature · 1 line
2.34.1
Quoted 12 lines · David E. Box
Hi Bjorn,
Quoted 9 lines · Bjorn Helgaas
Quoted 7 lines · David E. Box
In commit
f492edb40b54("PCI: vmd: Add quirk to configure PCIe ASPM and LTR") the VMD driver callspci_enabled_link_stateas a callback frompci_bus_walk. Both will acquire thepci_bus_semlock leading to a lockdep warning. Instead of doing thepci_bus_walk, move the fix toquirks.cusingDECLARE_PCI_FIXUP_FINAL.+#define VMD_DEVICE_LTR 0x1003 /* 3145728 ns */
Quoted 8 lines
Quoted 2 lines
It would be nice to know how this value was derived. But I know we had this hard-coded value before, so it's not new with this patch.
Do you mean to show the multiplier that determines that value or to say why this particular number was chosen? For the latter, it the largest that could be set (given the multipier options) that will allow the SoC to get to it's lowest power state. And it's the same so far on all the SoCs covered by the VMD driver.
Oh, sorry, I meant "why this number was chosen". PCIe r6.0, sec 7.8.2, says this capability allows software to provide "platform latency information," so I assume this is somehow dependent on platform, but I really don't understand the details of how LTR works, and we didn't have an explanation before, so this was just a "if you happen to know, it might be useful here" comment.
Quoted 10 lines
Quoted 5 lines
Quoted 1 line
+static void
quirk_intel_vmd(struct pci_dev *pdev)I think this quirk could possibly stay in
drivers/pci/controller/vmd.c, couldn't it? It has a lot of VMD-specific knowledge that it would nice to contain invmd.c.I may have misunderstood your comment on V1 then. But you suggested that this would be typically done as
PCI_FIXUPso that the PCI core could call it and we could avoid the locking issue that was seen while walking the bus invmd.c.
Right, I think it makes sense to be a DECLARE_PCI_FIXUP_CLASS_FINAL(), but I was thinking that it could be implemented in vmd.c and still be called by the PCI core.
But now I'm uncertain since vmd.c can be compiled as a module, and I'm not sure how that could work, since pci_fixup_device() calls things in the __start_pci_fixups_final[] table, and I don't see how loading a module would insert the fixup entry into that table.
So maybe it needs to be in quirks.c after all.
I think my only remaining questions here are about how to identify devices below VMD and the order of enabling ASPM states vs setting LTR.
Bjorn
Quoted 24 lines · Bjorn Helgaas
Quoted 14 lines · David E. Box
Hi Bjorn,
Quoted 11 lines · Bjorn Helgaas
Quoted 9 lines · David E. Box
In commit
f492edb40b54("PCI: vmd: Add quirk to configure PCIe ASPM and LTR") the VMD driver callspci_enabled_link_stateas a callback frompci_bus_walk. Both will acquire thepci_bus_semlock leading to a lockdep
warning. Instead of doing thepci_bus_walk, move the fix toquirks.cusingDECLARE_PCI_FIXUP_FINAL.+#define VMD_DEVICE_LTR 0x1003 /* 3145728 ns */
Quoted 8 lines
Quoted 2 lines
It would be nice to know how this value was derived. But I know we had this hard-coded value before, so it's not new with this patch.
Do you mean to show the multiplier that determines that value or to say why this particular number was chosen? For the latter, it the largest that could be set (given the multipier options) that will allow the SoC to get to it's lowest power state. And it's the same so far on all the SoCs covered by the VMD driver.
Quoted 6 lines
Oh, sorry, I meant "why this number was chosen". PCIe r6.0, sec 7.8.2, says this capability allows software to provide "platform latency information," so I assume this is somehow dependent on platform, but I really don't understand the details of how LTR works, and we didn't have an explanation before, so this was just a "if you happen to know, it might be useful here" comment.
Sure.
Quoted 16 lines
Quoted 11 lines
Quoted 6 lines
Quoted 2 lines
+static void
quirk_intel_vmd(struct pci_dev *pdev)I think this quirk could possibly stay in
drivers/pci/controller/vmd.c, couldn't it? It has a lot of VMD-specific knowledge that it would nice to contain invmd.c.I may have misunderstood your comment on V1 then. But you suggested that this would be typically done as
PCI_FIXUPso that the PCI core could call it and we could avoid the locking issue that was seen while walking the bus invmd.c.Right, I think it makes sense to be a
DECLARE_PCI_FIXUP_CLASS_FINAL(), but I was thinking that it could be implemented invmd.cand still be called by the PCI core.
Quoted 6 lines
But now I'm uncertain since
vmd.ccan be compiled as a module, and I'm not sure how that could work, sincepci_fixup_device()calls things in the __start_pci_fixups_final[] table, and I don't see how loading a module would insert the fixup entry into that table.So maybe it needs to be in
quirks.cafter all.
Okay.
Quoted 4 lines
I think my only remaining questions here are about how to identify devices below VMD and the order of enabling ASPM states vs setting LTR.
Agree on setting the LTR first. I'll also look at other ways to identify devices below VMD.
David
Quoted 5 lines · David E. Box
In commit
f492edb40b54("PCI: vmd: Add quirk to configure PCIe ASPM and LTR") the VMD driver callspci_enabled_link_stateas a callback frompci_bus_walk. Both will acquire thepci_bus_semlock leading to a lockdep warning. Instead of doing thepci_bus_walk, move the fix toquirks.cusingDECLARE_PCI_FIXUP_FINAL.
What happened to this patch? We're still carrying a local fix for this in drm-tip...
Quoted 179 lines
Fixes f492edb40b54 ("PCI: vmd: Add quirk to configure PCIe ASPM and LTR")Suggested-by Bjorn Helgaas <[email protected]>Signed-off-by David E. Box <[email protected]>---
V2 - Instead of adding a lock flag argument to
pci_enabled_link_state, move
the fix toquirks.cdrivers/pci/controller/vmd.c | 55 +-------------------------- drivers/pci/quirks.c | 72 ++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 54 deletions(-)drivers/pci/controller/vmd.c +1
-54@@ -66,22 +66,11 @@ 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_BIOS_PM_QUIRK) + VMD_FEAT_OFFSET_FIRST_VECTOR)static DEFINE_IDA (vmd_instance_ida);@@ -724,46 +713,6 @@ 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 , <r_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;@@ -936,8 +885,6 @@ 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 drivers/pci/quirks.c +72
-0@@ -6023,3 +6023,75 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x9a2d, dpc_log_size);DECLARE_PCI_FIXUP_HEADER (PCI_VENDOR_ID_INTEL ,0x9a2f , dpc_log_size);DECLARE_PCI_FIXUP_HEADER (PCI_VENDOR_ID_INTEL ,0x9a31 , dpc_log_size);#endif + +#ifdef CONFIG_VMD +/* +* Enable ASPM on the PCIE root ports under VMD 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. +*/ +#define VMD_DEVICE_LTR 0x1003/* 3145728 ns */ +static void quirk_intel_vmd (struct pci_dev *pdev) +{ +struct pci_dev *parent; +u16 ltr =VMD_DEVICE_LTR ; +u32 ltr_reg; +int pos; + +/* Check in VMD domain */ +if (pci_domain_nr (pdev->bus) <0x10000 ) +return ; + +/* Get Root Port */ + parent =pci_upstream_bridge (pdev); +if (!parent || parent->vendor !=PCI_VENDOR_ID_INTEL ) +return ; + +/* Get VMD Host Bridge */ + parent =to_pci_dev (parent->dev.parent); +if (!parent) +return ; + +/* Get RAID controller */ + parent =to_pci_dev (parent->dev.parent); +if (!parent) +return ; + +switch (parent->device) { +case 0x467f : +case 0x4c3d : +case 0xa77f : +case 0x7d0b : +case 0xad0b : +case 0x9a0b : +break ; +default : +return ; + } + +pci_enable_link_state (pdev,PCIE_LINK_STATE_ALL ); + + pos =pci_find_ext_capability (pdev,PCI_EXT_CAP_ID_LTR ); +if (!pos) +return ; + +/* Skip if the max snoop LTR is non-zero, indicating BIOS has set it */ +pci_read_config_dword (pdev, pos +PCI_LTR_MAX_SNOOP_LAT , <r_reg); +if (!!(ltr_reg & (PCI_LTR_VALUE_MASK |PCI_LTR_SCALE_MASK ))) +return ; + +/* +* Set the LTR 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,"LTR set by VMD PCI quick\n" ); + +} +DECLARE_PCI_FIXUP_CLASS_FINAL (PCI_ANY_ID ,PCI_ANY_ID , +PCI_CLASS_STORAGE_EXPRESS ,0 , quirk_intel_vmd); +#endif Signature · 1 line
2.34.1
Signature · 2 lines
Ville Syrjälä Intel
Quoted 116 lines · Ville Syrjälä
Quoted 5 lines · David E. Box
In commit
f492edb40b54("PCI: vmd: Add quirk to configure PCIe ASPM and LTR") the VMD driver callspci_enabled_link_stateas a callback frompci_bus_walk. Both will acquire thepci_bus_semlock leading to a lockdep warning. Instead of doing thepci_bus_walk, move the fix toquirks.cusingDECLARE_PCI_FIXUP_FINAL.What happened to this patch? We're still carrying a local fix for this in drm-tip...
Quoted 106 lines
Fixes f492edb40b54 ("PCI: vmd: Add quirk to configure PCIe ASPM and LTR")Suggested-by Bjorn Helgaas <[email protected]>Signed-off-by David E. Box <[email protected]>---
V2 - Instead of adding a lock flag argument to
pci_enabled_link_state, move
the fix toquirks.cdrivers/pci/controller/vmd.c | 55 +-------------------------- drivers/pci/quirks.c | 72 ++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 54 deletions(-)drivers/pci/controller/vmd.c +1
-54@@ -66,22 +66,11 @@ 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_BIOS_PM_QUIRK) + VMD_FEAT_OFFSET_FIRST_VECTOR)static DEFINE_IDA (vmd_instance_ida);@@ -724,46 +713,6 @@ 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 , <r_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;@@ -936,8 +885,6 @@ 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 drivers/pci/quirks.c +1
-0@@ -6023,3 +6023,75 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x9a2d, dpc_log_size);DECLARE_PCI_FIXUP_HEADER (PCI_VENDOR_ID_INTEL ,0x9a2f , dpc_log_size);DECLARE_PCI_FIXUP_HEADER (PCI_VENDOR_ID_INTEL ,0x9a31 , dpc_log_size);#endif +
Quoted 8 lines
drivers/pci/quirks.c DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x9a2d, dpc_log_size); · line 6034
Quoted 8 lines
drivers/pci/quirks.c +8
-0+#ifdef CONFIG_VMD +/* +* Enable ASPM on the PCIE root ports under VMD 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. +*/ +#define VMD_DEVICE_LTR 0x1003/* 3145728 ns */
This should be defined using FIELD_PREP()s. It is better to construct both snoop and nosnoop registers here and not do the shift below at all.
There are new defines for the nosnoop reg in pci/field-get branch for the nosnoop reg fields.
Signature · 1 line
i.
Quoted 67 lines
Quoted 65 lines
drivers/pci/quirks.c +63
-0+static void quirk_intel_vmd (struct pci_dev *pdev) +{ +struct pci_dev *parent; +u16 ltr =VMD_DEVICE_LTR ; +u32 ltr_reg; +int pos; + +/* Check in VMD domain */ +if (pci_domain_nr (pdev->bus) <0x10000 ) +return ; + +/* Get Root Port */ + parent =pci_upstream_bridge (pdev); +if (!parent || parent->vendor !=PCI_VENDOR_ID_INTEL ) +return ; + +/* Get VMD Host Bridge */ + parent =to_pci_dev (parent->dev.parent); +if (!parent) +return ; + +/* Get RAID controller */ + parent =to_pci_dev (parent->dev.parent); +if (!parent) +return ; + +switch (parent->device) { +case 0x467f : +case 0x4c3d : +case 0xa77f : +case 0x7d0b : +case 0xad0b : +case 0x9a0b : +break ; +default : +return ; + } + +pci_enable_link_state (pdev,PCIE_LINK_STATE_ALL ); + + pos =pci_find_ext_capability (pdev,PCI_EXT_CAP_ID_LTR ); +if (!pos) +return ; + +/* Skip if the max snoop LTR is non-zero, indicating BIOS has set it */ +pci_read_config_dword (pdev, pos +PCI_LTR_MAX_SNOOP_LAT , <r_reg); +if (!!(ltr_reg & (PCI_LTR_VALUE_MASK |PCI_LTR_SCALE_MASK ))) +return ; + +/* +* Set the LTR 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,"LTR set by VMD PCI quick\n" ); + +} +DECLARE_PCI_FIXUP_CLASS_FINAL (PCI_ANY_ID ,PCI_ANY_ID , +PCI_CLASS_STORAGE_EXPRESS ,0 , quirk_intel_vmd); +#endif Signature · 1 line
2.34.1