PCI/ASPM: Add sysfs attributes for controlling ASPM
v6 cover PCI/ASPM: Add sysfs attributes for controlling ASPM
Background of this extension is a problem with the r8169 network driver. Several combinations of board chipsets and network chip versions have problems if ASPM is enabled, therefore we have to disable ASPM per default. However especially on notebooks ASPM can provide significant power-saving, therefore we want to give users the option to enable ASPM. With the new sysfs attributes users can control which ASPM link-states are disabled.
Note: Series depends on series "PCI: Make pcie_downstream_port() available outside of access.c" from Mika Westerberg that is still sitting in the PCI inbox.
Alternatively I could prepare a version w/o this dependency, but then Mika's series would need to be changed.
v2:
- use a dedicated sysfs attribute per link state
- allow separate control of ASPM and PCI PM L1 sub-states
v3:
- patch 3: statically allocate the attribute group
- patch 3: replace snprintf with printf
- add patch 4
v4:
- patch 3: add call to sysfs_update_group because is_visible callback returns false always at file creation time
- patch 3: simplify code a little
v5:
- rebased to latest pci/next
v6:
- patch 3: consider several review comments from Bjorn
- patch 4: add discussion link to commit message
Heiner Kallweit (4):
PCI/ASPM: Add L1 PM Substate support to pci_disable_link_state PCI/ASPM: Allow to re-enable Clock PM
PCI/ASPM: Add sysfs attributes for controlling ASPM link states PCI/ASPM: Remove Kconfig option PCIEASPM_DEBUG and related code
Documentation/ABI/testing/sysfs-bus-pci | 14 ++ drivers/pci/pci-sysfs.c | 10 +- drivers/pci/pci.h | 12 +- drivers/pci/pcie/Kconfig | 7 - drivers/pci/pcie/aspm.c | 246 +++++++++++++++++------- include/linux/pci.h | 10 +- 6 files changed, 206 insertions(+), 93 deletions(-)
Signature · 1 line
2.23.0
PATCH v6 1/4 PCI/ASPM: Add L1 PM Substate support to pci_disable_link_state
Add support for disabling states L1.1 and L1.2 to pci_disable_link_state(). Allow separate control of ASPM and PCI PM L1 sub-states.
---
v2:
- allow separate control of ASPM and PCI PM L1 sub-states
--- drivers/pci/pcie/aspm.c | 11 ++++++++++- include/linux/pci.h | 10 +++++++--- 2 files changed, 17 insertions(+), 4 deletions(-)
drivers/pci/pcie/aspm.c +10 -1
@@ -1094,7 +1094,16 @@ static int __pci_disable_link_state(struct pci_dev *pdev, int state, bool sem)if (state &PCIE_LINK_STATE_L0S ) link->aspm_disable |=ASPM_STATE_L0S ;if (state &PCIE_LINK_STATE_L1 ) - link->aspm_disable |=ASPM_STATE_L1 ; +/* sub-states require L1 */ + link->aspm_disable |=ASPM_STATE_L1 |ASPM_STATE_L1SS ; +if (state &PCIE_LINK_STATE_L1_1 ) + link->aspm_disable |=ASPM_STATE_L1_1 ; +if (state &PCIE_LINK_STATE_L1_2 ) + link->aspm_disable |=ASPM_STATE_L1_2 ; +if (state &PCIE_LINK_STATE_L1_1_PCIPM ) + link->aspm_disable |=ASPM_STATE_L1_1_PCIPM ; +if (state &PCIE_LINK_STATE_L1_2_PCIPM ) + link->aspm_disable |=ASPM_STATE_L1_2_PCIPM ;pcie_config_aspm_link (link,policy_to_aspm_state (link));if (state &PCIE_LINK_STATE_CLKPM ) {
include/linux/pci.h +7 -3
@@ -1544,9 +1544,13 @@ extern bool pcie_ports_native;#define pcie_ports_native false#endif -#define PCIE_LINK_STATE_L0S 1 -#define PCIE_LINK_STATE_L1 2 -#define PCIE_LINK_STATE_CLKPM 4 +#define PCIE_LINK_STATE_L0S BIT(0) +#define PCIE_LINK_STATE_L1 BIT(1) +#define PCIE_LINK_STATE_CLKPM BIT(2) +#define PCIE_LINK_STATE_L1_1 BIT(3) +#define PCIE_LINK_STATE_L1_2 BIT(4) +#define PCIE_LINK_STATE_L1_1_PCIPM BIT(5) +#define PCIE_LINK_STATE_L1_2_PCIPM BIT(6)#ifdef CONFIG_PCIEASPM int pci_disable_link_state (struct pci_dev *pdev,int state);
Signature · 1 line
2.23.0
PATCH v6 2/4 PCI/ASPM: Allow to re-enable Clock PM
In reply to Heiner KallweitSo far Clock PM can't be re-enabled once it has been disabled with a call to pci_disable_link_state(). Reason is that clkpm_capable is reset. Change this by adding a clkpm_disable field similar to aspm_disable.
--- drivers/pci/pcie/aspm.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-)
drivers/pci/pcie/aspm.c +11 -7
@@ -64,6 +64,7 @@ struct pcie_link_state { u32 clkpm_capable:1; /* Clock PM capable? */ u32 clkpm_enabled:1; /* Current Clock PM state */ u32 clkpm_default:1; /* Default Clock PM state by BIOS */ + u32 clkpm_disable:1; /* Clock PM disabled *//* Exit latencies */ struct aspm_latency latency_up;/* Upstream direction exit latency */
@@ -161,8 +162,11 @@ static void pcie_set_clkpm_nocheck(struct pcie_link_state *link, int enable)static void pcie_set_clkpm (struct pcie_link_state *link,int enable) { -/* Don't enable Clock PM if the link is not Clock PM capable */ -if (!link->clkpm_capable) +/* +* Don't enable Clock PM if the link is not Clock PM capable +* or Clock PM is disabled +*/ +if (!link->clkpm_capable || link->clkpm_disable) enable =0 ;/* Need nothing if the specified equals to current state */ if (link->clkpm_enabled == enable)
@@ -192,7 +196,8 @@ static void pcie_clkpm_cap_init(struct pcie_link_state *link, int blacklist) } link->clkpm_enabled = enabled; link->clkpm_default = enabled; - link->clkpm_capable = (blacklist) ?0 : capable; + link->clkpm_capable = capable; + link->clkpm_disable = blacklist ?1 :0 ; }static bool pcie_retrain_link (struct pcie_link_state *link)
@@ -1106,10 +1111,9 @@ static int __pci_disable_link_state(struct pci_dev *pdev, int state, bool sem) link->aspm_disable |=ASPM_STATE_L1_2_PCIPM ;pcie_config_aspm_link (link,policy_to_aspm_state (link)); -if (state &PCIE_LINK_STATE_CLKPM ) { - link->clkpm_capable =0 ; -pcie_set_clkpm (link,0 ); - } +if (state &PCIE_LINK_STATE_CLKPM ) + link->clkpm_disable =1 ; +pcie_set_clkpm (link,policy_to_clkpm_state (link));mutex_unlock (&aspm_lock);if (sem)up_read (&pci_bus_sem);
Signature · 1 line
2.23.0
PATCH v6 4/4 PCI/ASPM: Remove Kconfig option PCIEASPM_DEBUG and related code
In reply to Heiner KallweitNow that we have sysfs attributes for enabling/disabling the individual ASPM link states, this debug code isn't needed any longer. Removing this debug code has been discussed for quite some time, see e.g. [0].
[0] https://lore.kernel.org/lkml/[email protected]/
---
v6:
- add discussion link to commit message
--- drivers/pci/pci-sysfs.c | 3 -- drivers/pci/pci.h | 8 --- drivers/pci/pcie/Kconfig | 7 --- drivers/pci/pcie/aspm.c | 105 --------------------------------------- 4 files changed, 123 deletions(-)
drivers/pci/pci-sysfs.c +0 -3
@@ -1330,7 +1330,6 @@ static int pci_create_capabilities_sysfs(struct pci_dev *dev)int retval;pcie_vpd_create_sysfs_dev_files (dev); -pcie_aspm_create_sysfs_dev_files (dev);#ifdef CONFIG_PCIEASPM /* update visibility of attributes in this group */ sysfs_update_group (&dev->dev.kobj, &aspm_ctrl_attr_group);
@@ -1344,7 +1343,6 @@ static int pci_create_capabilities_sysfs(struct pci_dev *dev)return 0 ; error: -pcie_aspm_remove_sysfs_dev_files (dev);pcie_vpd_remove_sysfs_dev_files (dev);return retval; }
@@ -1420,7 +1418,6 @@ int __must_check pci_create_sysfs_dev_files(struct pci_dev *pdev)static void pci_remove_capabilities_sysfs (struct pci_dev *dev) {pcie_vpd_remove_sysfs_dev_files (dev); -pcie_aspm_remove_sysfs_dev_files (dev);if (dev->reset_fn) {device_remove_file (&dev->dev, &dev_attr_reset); dev->reset_fn =0 ;
drivers/pci/pci.h +0 -8
@@ -541,14 +541,6 @@ static inline void pcie_aspm_pm_state_change(struct pci_dev *pdev) { }static inline void pcie_aspm_powersave_config_link (struct pci_dev *pdev) { }#endif -#ifdef CONFIG_PCIEASPM_DEBUG -void pcie_aspm_create_sysfs_dev_files (struct pci_dev *pdev); -void pcie_aspm_remove_sysfs_dev_files (struct pci_dev *pdev); -#else -static inline void pcie_aspm_create_sysfs_dev_files (struct pci_dev *pdev) { } -static inline void pcie_aspm_remove_sysfs_dev_files (struct pci_dev *pdev) { } -#endif -#ifdef CONFIG_PCIE_ECRC void pcie_set_ecrc_checking (struct pci_dev *dev);void pcie_ecrc_get_policy (char *str);
drivers/pci/pcie/Kconfig +0 -7
@@ -79,13 +79,6 @@ config PCIEASPM When in doubt, say Y. -config PCIEASPM_DEBUG - bool "Debug PCI Express ASPM" - depends on PCIEASPM - help - This enables PCI Express ASPM debug support. It will add per-device - interface to control ASPM. - choice prompt "Default ASPM policy" default PCIEASPM_DEFAULT
drivers/pci/pcie/aspm.c +0 -105
111 lines not on this page · raw message
Signature · 1 line
2.23.0
PATCH v6 3/4 PCI/ASPM: Add sysfs attributes for controlling ASPM link states
In reply to Heiner KallweitBackground of this extension is a problem with the r8169 network driver. Several combinations of board chipsets and network chip versions have problems if ASPM is enabled, therefore we have to disable ASPM per default. However especially on notebooks ASPM can provide significant power-saving, therefore we want to give users the option to enable ASPM. With the new sysfs attributes users can control which ASPM link-states are enabled/disabled.
---
v2:
- use a dedicated sysfs attribute per link state
- allow separate control of ASPM and PCI PM L1 sub-states
v3:
- statically allocate the attribute group
- replace snprintf with printf
- base on top of "PCI: Make pcie_downstream_port() available outside of access.c" v4:
- add call to sysfs_update_group because is_visible callback returns false always at file creation time
- simplify code a little
v5:
- rebased to latest pci/next
v6:
- fix style of added documentation and extend it
- don't use term "parent" and rename function to pcie_aspm_get_link
- rename pcie_check_valid_aspm_endpoint to pcie_is_aspm_dev
- enable the sysfs files also selected other port types
- avoid usage of !!
--- Documentation/ABI/testing/sysfs-bus-pci | 14 ++ drivers/pci/pci-sysfs.c | 7 + drivers/pci/pci.h | 4 + drivers/pci/pcie/aspm.c | 194 ++++++++++++++++++++++++ 4 files changed, 219 insertions(+)
Documentation/ABI/testing/sysfs-bus-pci +14 -0
@@ -347,3 +347,17 @@ Description: If the device has any Peer-to-Peer memory registered, this file contains a '1' if the memory has been published for use outside the driver that owns the device. + +What: /sys/bus/pci/devices/.../aspm/aspm_l0s + /sys/bus/pci/devices/.../aspm/aspm_l1 + /sys/bus/pci/devices/.../aspm/aspm_l1_1 + /sys/bus/pci/devices/.../aspm/aspm_l1_2 + /sys/bus/pci/devices/.../aspm/aspm_l1_1_pcipm + /sys/bus/pci/devices/.../aspm/aspm_l1_2_pcipm + /sys/bus/pci/devices/.../aspm/aspm_clkpm +Date: September 2019 +Contact: Heiner Kallweit <[email protected]> +Description: If ASPM is supported for an endpoint, then these files + can be used to disable or enable the individual + power management states. Write y/1/on to enable, + n/0/off to disable.
drivers/pci/pci-sysfs.c +7 -0
@@ -1331,6 +1331,10 @@ static int pci_create_capabilities_sysfs(struct pci_dev *dev)pcie_vpd_create_sysfs_dev_files (dev);pcie_aspm_create_sysfs_dev_files (dev); +#ifdef CONFIG_PCIEASPM +/* update visibility of attributes in this group */ +sysfs_update_group (&dev->dev.kobj, &aspm_ctrl_attr_group); +#endif if (dev->reset_fn) { retval =device_create_file (&dev->dev, &dev_attr_reset);
@@ -1587,6 +1591,9 @@ static const struct attribute_group *pci_dev_attr_groups[] = { &pcie_dev_attr_group,#ifdef CONFIG_PCIEAER &aer_stats_attr_group, +#endif +#ifdef CONFIG_PCIEASPM + &aspm_ctrl_attr_group, #endif NULL, };
drivers/pci/pci.h +4 -0
@@ -667,4 +667,8 @@ static inline int pci_acpi_program_hp_params(struct pci_dev *dev) }#endif +#ifdef CONFIG_PCIEASPM +extern const struct attribute_group aspm_ctrl_attr_group; +#endif +#endif /* DRIVERS_PCI_H */
drivers/pci/pcie/aspm.c +194 -0
206 lines not on this page · raw message
Signature · 1 line
2.23.0