PCI/ASPM: Save/restore L1 PM Substates for suspend/resume
v7 cover PCI/ASPM: Save/restore L1 PM Substates for suspend/resume
From: Bjorn Helgaas <[email protected]>
This is some rework of David's series to preserve ASPM L1 substate configuration across suspend/resume.
We've had several attempts to make this work:
(unlabeled): https://lore.kernel.org/r/[email protected]
v5: https://lore.kernel.org/r/[email protected]
v4: https://lore.kernel.org/all/[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]/
The most recent posting is the unlabeled one mentioned above, and I'm calling it v6 and this rework v7.
Changes since the unlabeled v6:
- Rename pci_save_aspm_state() to pci_save_aspm_l1ss_state() (this is the reason for opening this again, because Vidya's patch [1] had to do some incidental renaming).
- Rename pcie_restore_aspm_l1ss() to pci_restore_aspm_l1ss_state() to match.
- Move the PCI_EXP_LNKCTL_ASPMC from pci_restore_aspm_state() to pci_restore_pcie_state() so both writes are in the same place.
- Rename pci_aspm_get_l1ss() to pci_configure_aspm_l1ss() and add the save_buffer there as well.
- Split [1/5] into two patches: move pci_configure_ltr() and pci_bridge_reconfigure_ltr() to aspm.c, and build aspm.c unconditionally.
- Squash [2/5] and [3/5] since [2/5] didn't add any functionality itself so they seem like a single logical change.
[1] https://lore.kernel.org/r/[email protected]
David E. Box (5):
PCI/ASPM: Move pci_configure_ltr() to aspm.c PCI/ASPM: Always build aspm.c
PCI/ASPM: Move pci_save_ltr_state() to aspm.c PCI/ASPM: Save L1 PM Substates Capability for suspend/resume PCI/ASPM: Call pci_save_ltr_state() from pci_save_pcie_state()
drivers/pci/pci.c | 89 ++++------------ drivers/pci/pci.h | 13 ++- drivers/pci/pcie/Makefile | 2 +- drivers/pci/pcie/aspm.c | 215 ++++++++++++++++++++++++++++++++++++++ drivers/pci/probe.c | 62 +---------- include/linux/pci.h | 2 +- 6 files changed, 252 insertions(+), 131 deletions(-)
Signature · 1 line
2.34.1
PATCH v7 1/5 PCI/ASPM: Move pci_configure_ltr() to aspm.c
From: "David E. Box" <[email protected]>
The Latency Tolerance Reporting (LTR) mechanism supports the ASPM L1.2 state and is only configured when CONFIG_PCIEASPM is set.
Move pci_configure_ltr() and pci_bridge_reconfigure_ltr() into aspm.c since they only build when CONFIG_PCIEASPM is set. No functional change intended.
--- drivers/pci/pci.c | 18 ---------- drivers/pci/pci.h | 5 ++- drivers/pci/pcie/aspm.c | 75 +++++++++++++++++++++++++++++++++++++++++ drivers/pci/probe.c | 61 --------------------------------- 4 files changed, 79 insertions(+), 80 deletions(-)
drivers/pci/pci.c +0 -18
@@ -1626,24 +1626,6 @@ static int pci_save_pcie_state(struct pci_dev *dev)return 0 ; } -void pci_bridge_reconfigure_ltr (struct pci_dev *dev) -{ -#ifdef CONFIG_PCIEASPM -struct pci_dev *bridge; -u32 ctl; - - bridge =pci_upstream_bridge (dev); -if (bridge && bridge->ltr_path) { -pcie_capability_read_dword (bridge,PCI_EXP_DEVCTL2 , &ctl); -if (!(ctl &PCI_EXP_DEVCTL2_LTR_EN )) { -pci_dbg (bridge,"re-enabling LTR\n" ); -pcie_capability_set_word (bridge,PCI_EXP_DEVCTL2 , -PCI_EXP_DEVCTL2_LTR_EN ); - } - } -#endif -} -static void pci_restore_pcie_state (struct pci_dev *dev) {int i =0 ;
drivers/pci/pci.h +4 -1
@@ -97,7 +97,6 @@ void pci_msi_init(struct pci_dev *dev);void pci_msix_init (struct pci_dev *dev);bool pci_bridge_d3_possible (struct pci_dev *dev);void pci_bridge_d3_update (struct pci_dev *dev); -void pci_bridge_reconfigure_ltr (struct pci_dev *dev);int pci_bridge_wait_for_secondary_bus (struct pci_dev *dev,char *reset_type);static inline void pci_wakeup_event (struct pci_dev *dev)
@@ -573,11 +572,15 @@ void pcie_aspm_init_link_state(struct pci_dev *pdev);void pcie_aspm_exit_link_state (struct pci_dev *pdev);void pcie_aspm_pm_state_change (struct pci_dev *pdev);void pcie_aspm_powersave_config_link (struct pci_dev *pdev); +void pci_configure_ltr (struct pci_dev *pdev); +void pci_bridge_reconfigure_ltr (struct pci_dev *pdev);#else static inline void pcie_aspm_init_link_state (struct pci_dev *pdev) { }static inline void pcie_aspm_exit_link_state (struct pci_dev *pdev) { }static inline void pcie_aspm_pm_state_change (struct pci_dev *pdev) { }static inline void pcie_aspm_powersave_config_link (struct pci_dev *pdev) { } +static inline void pci_configure_ltr (struct pci_dev *pdev) { } +static inline void pci_bridge_reconfigure_ltr (struct pci_dev *pdev) { }#endif #ifdef CONFIG_PCIE_ECRC
drivers/pci/pcie/aspm.c +75 -0
81 lines not on this page · raw message
drivers/pci/probe.c +0 -61
67 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v7 2/5 PCI/ASPM: Always build aspm.c
In reply to Bjorn HelgaasFrom: "David E. Box" <[email protected]>
Some ASPM-related tasks, such as save and restore of LTR and L1SS capabilities, still need to be performed when CONFIG_PCIEASPM is not enabled. To prepare for these changes, wrap the current code in aspm.c with an #ifdef and always build the file.
--- drivers/pci/pcie/Makefile | 2 +- drivers/pci/pcie/aspm.c | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-)
drivers/pci/pcie/Makefile +1 -1
@@ -6,7 +6,7 @@ pcieportdrv-y := portdrv.o rcec.o obj-$(CONFIG_PCIEPORTBUS) += pcieportdrv.o -obj-$(CONFIG_PCIEASPM) += aspm.o +obj-y += aspm.o obj-$(CONFIG_PCIEAER) += aer.o err.o obj-$(CONFIG_PCIEAER_INJECT) += aer_inject.o obj-$(CONFIG_PCIE_PME) += pme.o
drivers/pci/pcie/aspm.c +4 -0
@@ -24,6 +24,8 @@#include "../pci.h" +#ifdef CONFIG_PCIEASPM +#ifdef MODULE_PARAM_PREFIX #undef MODULE_PARAM_PREFIX#endif
@@ -1517,3 +1519,5 @@ bool pcie_aspm_support_enabled(void) {return aspm_support_enabled; } + +#endif /* CONFIG_PCIEASPM */
Signature · 1 line
2.34.1
Re: [PATCH v7 2/5] PCI/ASPM: Always build aspm.c
Quoted 6 lines · Bjorn Helgaas
From: "David E. Box" <[email protected]>
Some ASPM-related tasks, such as save and restore of LTR and L1SS capabilities, still need to be performed when
CONFIG_PCIEASPMis not enabled. To prepare for these changes, wrap the current code inaspm.cwith an #ifdef and always build the file.
Since save/restore needs to be called even if CONFIG_PCIEASPM is not set, why not just leave it in pci.c?
Quoted 42 lines
Signed-off-by David E. Box <[email protected]>[bhelgaas: split build change from function moves]Signed-off-by Bjorn Helgaas <[email protected]>--- drivers/pci/pcie/Makefile | 2 +- drivers/pci/pcie/aspm.c | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-)drivers/pci/pcie/Makefile +1
-1@@ -6,7 +6,7 @@ pcieportdrv-y := portdrv.o rcec.o obj-$(CONFIG_PCIEPORTBUS) += pcieportdrv.o -obj-$(CONFIG_PCIEASPM) += aspm.o +obj-y += aspm.o obj-$(CONFIG_PCIEAER) += aer.o err.o obj-$(CONFIG_PCIEAER_INJECT) += aer_inject.o obj-$(CONFIG_PCIE_PME) += pme.odrivers/pci/pcie/aspm.c +4
-0@@ -24,6 +24,8 @@#include "../pci.h" +#ifdef CONFIG_PCIEASPM +#ifdef MODULE_PARAM_PREFIX #undef MODULE_PARAM_PREFIX#endif @@ -1517,3 +1519,5 @@ bool pcie_aspm_support_enabled(void) {return aspm_support_enabled; } + +#endif /* CONFIG_PCIEASPM */
Signature · 2 lines
Sathyanarayanan Kuppuswamy Linux Kernel Developer
Re: [PATCH v7 2/5] PCI/ASPM: Always build aspm.c
Quoted 10 lines · Kuppuswamy Sathyanarayanan
Quoted 6 lines · Bjorn Helgaas
From: "David E. Box" <[email protected]>
Some ASPM-related tasks, such as save and restore of LTR and L1SS capabilities, still need to be performed when
CONFIG_PCIEASPMis not enabled. To prepare for these changes, wrap the current code inaspm.cwith an #ifdef and always build the file.Since save/restore needs to be called even if
CONFIG_PCIEASPMis not set, why not just leave it inpci.c?
We could do that, but we're accumulating various bits of ASPM-related suspend/resume functionality (LTR, L1SS, etc) that seem like they fit better in aspm.c.
Bjorn
PATCH v7 3/5 PCI/ASPM: Move pci_save_ltr_state() to aspm.c
In reply to Bjorn HelgaasFrom: "David E. Box" <[email protected]>
Even when CONFIG_PCIEASPM is not set, we save and restore the LTR Capability so that if ASPM L1.2 and LTR were configured by the platform, ASPM L1.2 will still work after suspend/resume, when that platform configuration may be lost. See dbbfadf23190 ("PCI/ASPM: Save LTR Capability for suspend/resume").
Since ASPM L1.2 depends on the LTR Capability, move the save/restore code to the part of aspm.c that is always compiled regardless of CONFIG_PCIEASPM. No functional change intended.
--- drivers/pci/pci.c | 40 ---------------------------------------- drivers/pci/pci.h | 5 +++++ drivers/pci/pcie/aspm.c | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 40 deletions(-)
drivers/pci/pci.c +0 -40
@@ -1689,46 +1689,6 @@ static void pci_restore_pcix_state(struct pci_dev *dev)pci_write_config_word (dev, pos +PCI_X_CMD , cap[i++]); } -static void pci_save_ltr_state (struct pci_dev *dev) -{ -int ltr; -struct pci_cap_saved_state *save_state; -u32 *cap; - -if (!pci_is_pcie (dev)) -return ; - - ltr =pci_find_ext_capability (dev,PCI_EXT_CAP_ID_LTR ); -if (!ltr) -return ; - - save_state =pci_find_saved_ext_cap (dev,PCI_EXT_CAP_ID_LTR ); -if (!save_state) { -pci_err (dev,"no suspend buffer for LTR; ASPM issues possible after resume\n" ); -return ; - } - -/* Some broken devices only support dword access to LTR */ - cap = &save_state->cap.data[0 ]; -pci_read_config_dword (dev, ltr +PCI_LTR_MAX_SNOOP_LAT , cap); -} - -static void pci_restore_ltr_state (struct pci_dev *dev) -{ -struct pci_cap_saved_state *save_state; -int ltr; -u32 *cap; - - save_state =pci_find_saved_ext_cap (dev,PCI_EXT_CAP_ID_LTR ); - ltr =pci_find_ext_capability (dev,PCI_EXT_CAP_ID_LTR ); -if (!save_state || !ltr) -return ; - -/* Some broken devices only support dword access to LTR */ - cap = &save_state->cap.data[0 ]; -pci_write_config_dword (dev, ltr +PCI_LTR_MAX_SNOOP_LAT , *cap); -} -/** * pci_save_state - save the PCI configuration space of a device before * suspending
drivers/pci/pci.h +5 -0
@@ -567,6 +567,11 @@ pci_ers_result_t pcie_do_recovery(struct pci_dev *dev,bool pcie_wait_for_link (struct pci_dev *pdev,bool active);int pcie_retrain_link (struct pci_dev *pdev,bool use_lt); + +/* ASPM-related functionality we need even without CONFIG_PCIEASPM */ +void pci_save_ltr_state (struct pci_dev *dev); +void pci_restore_ltr_state (struct pci_dev *dev); +#ifdef CONFIG_PCIEASPM void pcie_aspm_init_link_state (struct pci_dev *pdev);void pcie_aspm_exit_link_state (struct pci_dev *pdev);
drivers/pci/pcie/aspm.c +40 -0
@@ -24,6 +24,46 @@#include "../pci.h" +void pci_save_ltr_state (struct pci_dev *dev) +{ +int ltr; +struct pci_cap_saved_state *save_state; +u32 *cap; + +if (!pci_is_pcie (dev)) +return ; + + ltr =pci_find_ext_capability (dev,PCI_EXT_CAP_ID_LTR ); +if (!ltr) +return ; + + save_state =pci_find_saved_ext_cap (dev,PCI_EXT_CAP_ID_LTR ); +if (!save_state) { +pci_err (dev,"no suspend buffer for LTR; ASPM issues possible after resume\n" ); +return ; + } + +/* Some broken devices only support dword access to LTR */ + cap = &save_state->cap.data[0 ]; +pci_read_config_dword (dev, ltr +PCI_LTR_MAX_SNOOP_LAT , cap); +} + +void pci_restore_ltr_state (struct pci_dev *dev) +{ +struct pci_cap_saved_state *save_state; +int ltr; +u32 *cap; + + save_state =pci_find_saved_ext_cap (dev,PCI_EXT_CAP_ID_LTR ); + ltr =pci_find_ext_capability (dev,PCI_EXT_CAP_ID_LTR ); +if (!save_state || !ltr) +return ; + +/* Some broken devices only support dword access to LTR */ + cap = &save_state->cap.data[0 ]; +pci_write_config_dword (dev, ltr +PCI_LTR_MAX_SNOOP_LAT , *cap); +} +#ifdef CONFIG_PCIEASPM #ifdef MODULE_PARAM_PREFIX
Signature · 1 line
2.34.1
PATCH v7 4/5 PCI/ASPM: Save L1 PM Substates Capability for suspend/resume
In reply to Bjorn HelgaasFrom: "David E. Box" <[email protected]>
4ff116d0d5fd ("PCI/ASPM: Save L1 PM Substates Capability for suspend/resume") restored the L1 PM Substates Capability after resume, which reduced power consumption by making the ASPM L1.x states work after resume.
a7152be79b62 ("Revert "PCI/ASPM: Save L1 PM Substates Capability for suspend/resume"") reverted 4ff116d0d5fd because resume failed on some systems, so power consumption after resume increased again.
a7152be79b62 mentioned that we restore L1 PM substate configuration even though ASPM L1 may already be enabled. This is due the fact that the pci_restore_aspm_l1ss_state() was called before pci_restore_pcie_state().
Save and restore the L1 PM Substates Capability, following PCIe r6.1, sec 5.5.4 more closely by:
1) Do not restore ASPM configuration in pci_restore_pcie_state() but do that after PCIe capability is restored in pci_restore_aspm_state() following PCIe r6.1, sec 5.5.4.
2) If BIOS reenables L1SS, particularly L1.2, we need to clear the enables in the right order, downstream before upstream. Defer restoring the L1SS config until we are at the downstream component. Then update the config for both ends of the link in the prescribed order.
3) Program ASPM L1 PM substate configuration before L1 enables.
4) Program ASPM L1 PM substate enables last, after rest of the fields in the capability are programmed.
[bhelgaas: commit log, squash L1SS-related patches, do both LNKCTL restores in pci_restore_pcie_state()]
--- drivers/pci/pci.c | 17 ++++++- drivers/pci/pci.h | 3 ++ drivers/pci/pcie/aspm.c | 102 ++++++++++++++++++++++++++++++++++++++-- drivers/pci/probe.c | 1 + include/linux/pci.h | 2 +- 5 files changed, 119 insertions(+), 6 deletions(-)
drivers/pci/pci.c +15 -2
@@ -1623,6 +1623,8 @@ static int pci_save_pcie_state(struct pci_dev *dev)pcie_capability_read_word (dev,PCI_EXP_LNKCTL2 , &cap[i++]);pcie_capability_read_word (dev,PCI_EXP_SLTCTL2 , &cap[i++]); +pci_save_aspm_l1ss_state (dev); +return 0 ; }
@@ -1630,7 +1632,7 @@ static void pci_restore_pcie_state(struct pci_dev *dev) {int i =0 ;struct pci_cap_saved_state *save_state; -u16 *cap; +u16 *cap, lnkctl; save_state =pci_find_saved_cap (dev,PCI_CAP_ID_EXP );if (!save_state)
@@ -1645,12 +1647,23 @@ static void pci_restore_pcie_state(struct pci_dev *dev) cap = (u16 *)&save_state->cap.data[0 ];pcie_capability_write_word (dev,PCI_EXP_DEVCTL , cap[i++]); -pcie_capability_write_word (dev,PCI_EXP_LNKCTL , cap[i++]); + +/* Restore LNKCTL register with ASPM control field clear */ + lnkctl = cap[i++]; +pcie_capability_write_word (dev,PCI_EXP_LNKCTL , + lnkctl & ~PCI_EXP_LNKCTL_ASPMC ); +pcie_capability_write_word (dev,PCI_EXP_SLTCTL , cap[i++]);pcie_capability_write_word (dev,PCI_EXP_RTCTL , cap[i++]);pcie_capability_write_word (dev,PCI_EXP_DEVCTL2 , cap[i++]);pcie_capability_write_word (dev,PCI_EXP_LNKCTL2 , cap[i++]);pcie_capability_write_word (dev,PCI_EXP_SLTCTL2 , cap[i++]); + +pci_restore_aspm_l1ss_state (dev); + +/* Restore ASPM control after restoring L1SS state */ +pcie_capability_set_word (dev,PCI_EXP_LNKCTL , + lnkctl &PCI_EXP_LNKCTL_ASPMC ); }static int pci_save_pcix_state (struct pci_dev *dev)
drivers/pci/pci.h +3 -0
@@ -571,6 +571,9 @@ int pcie_retrain_link(struct pci_dev *pdev, bool use_lt);/* ASPM-related functionality we need even without CONFIG_PCIEASPM */ void pci_save_ltr_state (struct pci_dev *dev);void pci_restore_ltr_state (struct pci_dev *dev); +void pci_configure_aspm_l1ss (struct pci_dev *dev); +void pci_save_aspm_l1ss_state (struct pci_dev *dev); +void pci_restore_aspm_l1ss_state (struct pci_dev *dev);#ifdef CONFIG_PCIEASPM void pcie_aspm_init_link_state (struct pci_dev *pdev);
drivers/pci/pcie/aspm.c +99 -3
114 lines not on this page · raw message
drivers/pci/probe.c +1 -0
@@ -2259,6 +2259,7 @@ static void pci_configure_device(struct pci_dev *dev)pci_configure_extended_tags (dev,NULL );pci_configure_relaxed_ordering (dev);pci_configure_ltr (dev); +pci_configure_aspm_l1ss (dev);pci_configure_eetlp_prefix (dev);pci_configure_serr (dev);
include/linux/pci.h +1 -1
@@ -390,9 +390,9 @@ struct pci_dev {unsigned int d3hot_delay;/* D3hot->D0 transition time in ms */ unsigned int d3cold_delay;/* D3cold->D0 transition time in ms */ +u16 l1ss;/* L1SS Capability pointer */ #ifdef CONFIG_PCIEASPM struct pcie_link_state *link_state;/* ASPM link state */ -u16 l1ss;/* L1SS Capability pointer */ unsigned int ltr_path:1; /* Latency Tolerance Reportingsupported from root to here */ #endif
Signature · 1 line
2.34.1
Re: [PATCH v7 4/5] PCI/ASPM: Save L1 PM Substates Capability for suspend/resume
Quoted 46 lines · Bjorn Helgaas
From: "David E. Box" <[email protected]>
4ff116d0d5fd("PCI/ASPM: Save L1 PM Substates Capability for suspend/resume") restored the L1 PM Substates Capability after resume, which reduced power consumption by making the ASPM L1.x states work after resume.
a7152be79b62("Revert "PCI/ASPM: Save L1 PM Substates Capability for suspend/resume"") reverted4ff116d0d5fdbecause resume failed on some systems, so power consumption after resume increased again.
a7152be79b62mentioned that we restore L1 PM substate configuration even though ASPM L1 may already be enabled. This is due the fact that thepci_restore_aspm_l1ss_state()was called beforepci_restore_pcie_state().Save and restore the L1 PM Substates Capability, following PCIe r6.1, sec 5.5.4 more closely by:
1) Do not restore ASPM configuration in
pci_restore_pcie_state()but do that after PCIe capability is restored inpci_restore_aspm_state()following PCIe r6.1, sec 5.5.4.2) If BIOS reenables L1SS, particularly L1.2, we need to clear the enables in the right order, downstream before upstream. Defer restoring the L1SS config until we are at the downstream component. Then update the config for both ends of the link in the prescribed order.
3) Program ASPM L1 PM substate configuration before L1 enables.
4) Program ASPM L1 PM substate enables last, after rest of the fields in the capability are programmed.
(quoted diff) +6
-1@@ -1645,12 +1647,23 @@ static void pci_restore_pcie_state(struct pci_dev *dev) cap = (u16 *)&save_state->cap.data[0]; pcie_capability_write_word(dev, PCI_EXP_DEVCTL, cap[i++]); - pcie_capability_write_word(dev, PCI_EXP_LNKCTL, cap[i++]); + + /* Restore LNKCTL register with ASPM control field clear */ + lnkctl = cap[i++]; + pcie_capability_write_word(dev, PCI_EXP_LNKCTL, + lnkctl & ~PCI_EXP_LNKCTL_ASPMC); + pcie_capability_write_word(dev, PCI_EXP_SLTCTL, cap[i++]); pcie_capability_write_word(dev, PCI_EXP_RTCTL, cap[i++]);
Review static void pci_restore_pcie_state(struct pci_dev *dev) · line 1667
Quoted 10 lines
(quoted diff) +6
-0pcie_capability_write_word(dev, PCI_EXP_DEVCTL2, cap[i++]); pcie_capability_write_word(dev, PCI_EXP_LNKCTL2, cap[i++]); pcie_capability_write_word(dev, PCI_EXP_SLTCTL2, cap[i++]); + + pci_restore_aspm_l1ss_state(dev); + + /* Restore ASPM control after restoring L1SS state */ + pcie_capability_set_word(dev, PCI_EXP_LNKCTL, + lnkctl & PCI_EXP_LNKCTL_ASPMC); }
This part makes me wonder if the PCI_EXP_LNKCTL restore could be simplified by moving the L0s/L1 disable into pci_restore_aspm_l1ss_state() as in the patch below.
It would be nice if the knowledge about L0s/L1 being disabled while restoring L1SS state were encapsulated in pci_restore_aspm_l1ss_state() instead of doing this dance in pci_restore_pcie_state().
I didn't include this in the v7 posting because it changes the sequence and I don't have a way to test it, and this whole thing is awfully tricky to get right.
Bjorn
drivers/pci/pci.c +3 -13
@@ -1633,13 +1633,14 @@ static void pci_restore_pcie_state(struct pci_dev *dev) {int i =0 ;struct pci_cap_saved_state *save_state; -u16 *cap, lnkctl; +u16 *cap;/* * Restore max latencies (in the LTR capability) before enabling * LTR itself in PCI_EXP_DEVCTL2. */ pci_restore_ltr_state (dev); +pci_restore_aspm_l1ss_state (dev); save_state =pci_find_saved_cap (dev,PCI_CAP_ID_EXP );if (!save_state)
@@ -1654,23 +1655,12 @@ static void pci_restore_pcie_state(struct pci_dev *dev) cap = (u16 *)&save_state->cap.data[0 ];pcie_capability_write_word (dev,PCI_EXP_DEVCTL , cap[i++]); - -/* Restore LNKCTL register with ASPM control field clear */ - lnkctl = cap[i++]; -pcie_capability_write_word (dev,PCI_EXP_LNKCTL , - lnkctl & ~PCI_EXP_LNKCTL_ASPMC ); - +pcie_capability_write_word (dev,PCI_EXP_LNKCTL , cap[i++]);pcie_capability_write_word (dev,PCI_EXP_SLTCTL , cap[i++]);pcie_capability_write_word (dev,PCI_EXP_RTCTL , cap[i++]);pcie_capability_write_word (dev,PCI_EXP_DEVCTL2 , cap[i++]);pcie_capability_write_word (dev,PCI_EXP_LNKCTL2 , cap[i++]);pcie_capability_write_word (dev,PCI_EXP_SLTCTL2 , cap[i++]); - -pci_restore_aspm_l1ss_state (dev); - -/* Restore ASPM control after restoring L1SS state */ -pcie_capability_set_word (dev,PCI_EXP_LNKCTL , - lnkctl &PCI_EXP_LNKCTL_ASPMC ); }static int pci_save_pcix_state (struct pci_dev *dev)
drivers/pci/pcie/aspm.c +19 -0
@@ -105,6 +105,7 @@ void pci_restore_aspm_l1ss_state(struct pci_dev *pdev)struct pci_dev *parent = pdev->bus->self;u32 *cap, pl_ctl1, pl_ctl2, pl_l1_2_enable;u32 cl_ctl1, cl_ctl2, cl_l1_2_enable; +u16 clnkctl, plnkctl;/* * In case BIOS enabled L1.2 when resuming, we need to disable it first
@@ -129,6 +130,17 @@ void pci_restore_aspm_l1ss_state(struct pci_dev *pdev) pl_ctl2 = *cap++; pl_ctl1 = *cap; +/* Make sure L0s/L1 are disabled before updating L1SS config */ +pcie_capability_read_word (pdev,PCI_EXP_LNKCTL , &clnkctl); +pcie_capability_read_word (parent,PCI_EXP_LNKCTL , &plnkctl); +if (FIELD_GET (PCI_EXP_LNKCTL_ASPMC , clnkctl) || +FIELD_GET (PCI_EXP_LNKCTL_ASPMC , plnkctl)) { +pcie_capability_write_word (pdev,PCI_EXP_LNKCTL , + clnkctl & ~PCI_EXP_LNKCTL_ASPMC ); +pcie_capability_write_word (parent,PCI_EXP_LNKCTL , + plnkctl & ~PCI_EXP_LNKCTL_ASPMC ); + } +/* * Disable L1.2 on this downstream endpoint device first, followed * by the upstream
@@ -161,6 +173,13 @@ void pci_restore_aspm_l1ss_state(struct pci_dev *pdev)pci_write_config_dword (pdev, pdev->l1ss +PCI_L1SS_CTL1 , cl_ctl1 | cl_l1_2_enable); } + +/* Restore L0s/L1 if they were enabled */ +if (FIELD_GET (PCI_EXP_LNKCTL_ASPMC , clnkctl) || +FIELD_GET (PCI_EXP_LNKCTL_ASPMC , plnkctl)) { +pcie_capability_write_word (parent,PCI_EXP_LNKCTL , clnkctl); +pcie_capability_write_word (pdev,PCI_EXP_LNKCTL , plnkctl); + } }#ifdef CONFIG_PCIEASPM
PATCH v7 5/5 PCI/ASPM: Call pci_save_ltr_state() from pci_save_pcie_state()
In reply to Bjorn HelgaasFrom: "David E. Box" <[email protected]>
ASPM state is saved and restored from pci_save/restore_pcie_state(). Since the LTR Capability is linked with ASPM, move the LTR save and restore calls there as well. No functional change intended.
--- drivers/pci/pci.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/pci/pci.c +7 -7
@@ -1624,6 +1624,7 @@ static int pci_save_pcie_state(struct pci_dev *dev)pcie_capability_read_word (dev,PCI_EXP_SLTCTL2 , &cap[i++]);pci_save_aspm_l1ss_state (dev); +pci_save_ltr_state (dev);return 0 ; }
@@ -1634,6 +1635,12 @@ static void pci_restore_pcie_state(struct pci_dev *dev)struct pci_cap_saved_state *save_state;u16 *cap, lnkctl; +/* +* Restore max latencies (in the LTR capability) before enabling +* LTR itself in PCI_EXP_DEVCTL2. +*/ +pci_restore_ltr_state (dev); + save_state =pci_find_saved_cap (dev,PCI_CAP_ID_EXP );if (!save_state)return ;
@@ -1726,7 +1733,6 @@ int pci_save_state(struct pci_dev *dev)if (i !=0 )return i; -pci_save_ltr_state (dev);pci_save_dpc_state (dev);pci_save_aer_state (dev);pci_save_ptm_state (dev);
@@ -1827,12 +1833,6 @@ void pci_restore_state(struct pci_dev *dev)if (!dev->state_saved)return ; -/* -* Restore max latencies (in the LTR capability) before enabling -* LTR itself (in the PCIe capability). -*/ -pci_restore_ltr_state (dev); -pci_restore_pcie_state (dev);pci_restore_pasid_state (dev);pci_restore_pri_state (dev);
Signature · 1 line
2.34.1
Quoted 48 lines · Bjorn Helgaas
From: Bjorn Helgaas <[email protected]>
This is some rework of David's series to preserve ASPM L1 substate configuration across suspend/resume.
We've had several attempts to make this work:
(unlabeled): https://lore.kernel.org/r/[email protected]
v5: https://lore.kernel.org/r/[email protected]
v4: https://lore.kernel.org/all/[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]/The most recent posting is the unlabeled one mentioned above, and I'm calling it v6 and this rework v7.
Changes since the unlabeled v6:
- Rename
pci_save_aspm_state()topci_save_aspm_l1ss_state()(this is the reason for opening this again, because Vidya's patch [1] had to do some incidental renaming).- Rename
pcie_restore_aspm_l1ss()topci_restore_aspm_l1ss_state()to match.- Move the
PCI_EXP_LNKCTL_ASPMCfrompci_restore_aspm_state()topci_restore_pcie_state()so both writes are in the same place.- Rename
pci_aspm_get_l1ss()topci_configure_aspm_l1ss()and add thesave_bufferthere as well.- Split [1/5] into two patches: move
pci_configure_ltr()andpci_bridge_reconfigure_ltr()toaspm.c, and buildaspm.cunconditionally.- Squash [2/5] and [3/5] since [2/5] didn't add any functionality itself so they seem like a single logical change.
[1] https://lore.kernel.org/r/[email protected]
David E. Box (5):
PCI/ASPM: Movepci_configure_ltr()toaspm.cPCI/ASPM: Always buildaspm.c
PCI/ASPM: Movepci_save_ltr_state()toaspm.cPCI/ASPM: Save L1 PM Substates Capability for suspend/resume PCI/ASPM: Callpci_save_ltr_state()frompci_save_pcie_state()
Quoted 7 lines
drivers/pci/pci.c | 89 ++++------------ drivers/pci/pci.h | 13 ++- drivers/pci/pcie/Makefile | 2 +- drivers/pci/pcie/aspm.c | 215 ++++++++++++++++++++++++++++++++++++++ drivers/pci/probe.c | 62 +---------- include/linux/pci.h | 2 +- 6 files changed, 252 insertions(+), 131 deletions(-)
I applied these as pci/aspm for v6.9, replacing the original unlabeled v6 that has been in -next.
I also added the patch I suggested at
https://lore.kernel.org/r/20240223213733.GA115410@bhelgaas to disable L1 inside pci_restore_aspm_l1ss_state() where we actually depend on it being disabled.
Bjorn
[+cc Koba Ko]
Quoted 22 lines · Bjorn Helgaas
Quoted 13 lines · Bjorn Helgaas
From: Bjorn Helgaas <[email protected]>
This is some rework of David's series to preserve ASPM L1 substate configuration across suspend/resume.
...David E. Box (5):
PCI/ASPM: Movepci_configure_ltr()toaspm.cPCI/ASPM: Always buildaspm.c
PCI/ASPM: Movepci_save_ltr_state()toaspm.cPCI/ASPM: Save L1 PM Substates Capability for suspend/resume PCI/ASPM: Callpci_save_ltr_state()frompci_save_pcie_state()Quoted 7 lines
drivers/pci/pci.c | 89 ++++------------ drivers/pci/pci.h | 13 ++- drivers/pci/pcie/Makefile | 2 +- drivers/pci/pcie/aspm.c | 215 ++++++++++++++++++++++++++++++++++++++ drivers/pci/probe.c | 62 +---------- include/linux/pci.h | 2 +- 6 files changed, 252 insertions(+), 131 deletions(-)
Quoted 2 lines
I applied these as pci/aspm for v6.9, replacing the original unlabeled v6 that has been in -next.
Would anybody be able to test this, particularly to make sure it works for the bugs we're claiming to fix with this series?
https://bugzilla.kernel.org/show_bug.cgi?id=217321
https://bugzilla.kernel.org/show_bug.cgi?id=216782
https://bugzilla.kernel.org/show_bug.cgi?id=216877
This series is headed for v6.9, and I hope we can finally claim victory over these issues.
This is in -next as of the Mar 7 tree. Or if you want just the ASPM changes, based on v6.8-rc1, you can use the branch at
https://git.kernel.org/pub/scm/linux/kernel/git/pci/pci.git/log/?h=aspm
Bjorn
Le 7/03/24 à 23:25, Bjorn Helgaas a écrit :
Quoted 32 lines
[+cc Koba Ko]
Quoted 20 lines · Bjorn Helgaas
Quoted 12 lines · Bjorn Helgaas
From: Bjorn Helgaas <[email protected]>
This is some rework of David's series to preserve ASPM L1 substate configuration across suspend/resume.
...
David E. Box (5):
PCI/ASPM: Movepci_configure_ltr()toaspm.cPCI/ASPM: Always buildaspm.c
PCI/ASPM: Movepci_save_ltr_state()toaspm.cPCI/ASPM: Save L1 PM Substates Capability for suspend/resume PCI/ASPM: Callpci_save_ltr_state()frompci_save_pcie_state()Quoted 7 lines
drivers/pci/pci.c | 89 ++++------------ drivers/pci/pci.h | 13 ++- drivers/pci/pcie/Makefile | 2 +- drivers/pci/pcie/aspm.c | 215 ++++++++++++++++++++++++++++++++++++++ drivers/pci/probe.c | 62 +---------- include/linux/pci.h | 2 +- 6 files changed, 252 insertions(+), 131 deletions(-)Quoted 2 lines
I applied these as pci/aspm for v6.9, replacing the original unlabeled v6 that has been in -next.
Would anybody be able to test this, particularly to make sure it works for the bugs we're claiming to fix with this series?
https://bugzilla.kernel.org/show_bug.cgi?id=217321 https://bugzilla.kernel.org/show_bug.cgi?id=216782 https://bugzilla.kernel.org/show_bug.cgi?id=216877
Quoted 8 lines
This series is headed for v6.9, and I hope we can finally claim victory over these issues.
This is in -next as of the Mar 7 tree. Or if you want just the ASPM changes, based on v6.8-rc1, you can use the branch at
https://git.kernel.org/pub/scm/linux/kernel/git/pci/pci.git/log/?h=aspmBjorn
I just tested the patch v7 from Bjorn, it works on my Asus UX305FA. Tested on kernel v6.8-rc1.
Tasev
Bjorn Helgaas
Tested-by Tasev NikolaQuoted 36 lines · tasev.stefanoska
Le 7/03/24 à 23:25, Bjorn Helgaas a écrit :
Quoted 35 lines · Bjorn Helgaas
Quoted 21 lines · Bjorn Helgaas
Quoted 12 lines
From: Bjorn Helgaas <[email protected]>
This is some rework of David's series to preserve ASPM L1 substate configuration across suspend/resume.
...
David E. Box (5):
PCI/ASPM: Movepci_configure_ltr()toaspm.cPCI/ASPM: Always buildaspm.c
PCI/ASPM: Movepci_save_ltr_state()toaspm.cPCI/ASPM: Save L1 PM Substates Capability for suspend/resume PCI/ASPM: Callpci_save_ltr_state()frompci_save_pcie_state()Quoted 7 lines
drivers/pci/pci.c | 89 ++++------------ drivers/pci/pci.h | 13 ++- drivers/pci/pcie/Makefile | 2 +- drivers/pci/pcie/aspm.c | 215 ++++++++++++++++++++++++++++++++++++++ drivers/pci/probe.c | 62 +---------- include/linux/pci.h | 2 +- 6 files changed, 252 insertions(+), 131 deletions(-)Quoted 2 lines
I applied these as pci/aspm for v6.9, replacing the original unlabeled v6 that has been in -next.
Would anybody be able to test this, particularly to make sure it works for the bugs we're claiming to fix with this series?
https://bugzilla.kernel.org/show_bug.cgi?id=217321 https://bugzilla.kernel.org/show_bug.cgi?id=216782 https://bugzilla.kernel.org/show_bug.cgi?id=216877This series is headed for v6.9, and I hope we can finally claim victory over these issues.
Quoted 6 lines
Quoted 3 lines
This is in -next as of the Mar 7 tree. Or if you want just the ASPM changes, based on v6.8-rc1, you can use the branch at
https://git.kernel.org/pub/scm/linux/kernel/git/pci/pci.git/log/?h=aspmI just tested the patch v7 from Bjorn, it works on my Asus UX305FA. Tested on kernel v6.8-rc1.
Thank you very much! I added the following to the "PCI/ASPM: Save L1 PM Substates Capability for suspend/resume" patch: