Add PCIe Bandwidth Controller
Subsystems (9)
Ilpo Järvinen
maintainerv3 cover Add PCIe Bandwidth Controller
Hi all,
This series adds PCIe bandwidth controller (bwctrl) and associated PCIe cooling driver to the thermal core side for limiting PCIe Link Speed due to thermal reasons. PCIe bandwidth controller is a PCI express bus port service driver. A cooling device is created for each port the service driver finds if they support changing speeds.
This series only adds support for controlling PCIe Link Speed. Controlling PCIe Link Width might also be useful but AFAIK, there is no mechanism for that until PCIe 6.0 (L0p). Based on feedback for v1, the thermal/cooling device side prefers Link Speed and Link Width to be separate cooling devices [1] which is taken into account in naming the cooling device for Link Speed but the Link Width one is not added yet as it would not be able to control anything at the moment.
bwctrl is built on top of BW notifications revert. I'm just not sure what is the best practice when re-adding some old functionality in a modified form so please let me know if I need to somehow alter that patch.
[1] https://lore.kernel.org/linux-pci/[email protected]/
v3:
- Correct hfi1 shortlog prefix
- Improve error prints in hfi1
- Add L: linux-pci to the MAINTAINERS entry
v2:
- Adds LNKCTL2 to RMW safe list in Documentation/PCI/pciebus-howto.rst
- Renamed cooling devices from PCIe_Port_* to PCIe_Port_Link_Speed_* in order to plan for possibility of adding Link Width cooling devices later on
- Moved struct thermal_cooling_device declaration to the correct patch
- Small tweaks to Kconfig texts
- Series rebased to resolve conflict (in the selftest list)
Ilpo Järvinen (10):
PCI: Protect Link Control 2 Register with RMW locking drm/radeon: Use RMW accessors for changing LNKCTL2 drm/amdgpu: Use RMW accessors for changing LNKCTL2 RDMA/hfi1: Use RMW accessors for changing LNKCTL2
PCI: Store all PCIe Supported Link Speeds
PCI: Cache PCIe device's Supported Speed Vector PCI/LINK: Re-add BW notification portdrv as PCIe BW controller PCI/bwctrl: Add "controller" part into PCIe bwctrl
thermal: Add PCIe cooling driver selftests/pcie_bwctrl: Create selftests
Documentation/PCI/pciebus-howto.rst | 8 +- MAINTAINERS | 9 + drivers/gpu/drm/amd/amdgpu/cik.c | 41 +-- drivers/gpu/drm/amd/amdgpu/si.c | 41 +-- drivers/gpu/drm/radeon/cik.c | 40 +-- drivers/gpu/drm/radeon/si.c | 40 +-- drivers/infiniband/hw/hfi1/pcie.c | 30 +- drivers/pci/pcie/Kconfig | 9 + drivers/pci/pcie/Makefile | 1 + drivers/pci/pcie/bwctrl.c | 309 ++++++++++++++++++ drivers/pci/pcie/portdrv.c | 9 +- drivers/pci/pcie/portdrv.h | 10 +- drivers/pci/probe.c | 38 ++- drivers/pci/remove.c | 2 + drivers/thermal/Kconfig | 10 + drivers/thermal/Makefile | 2 + drivers/thermal/pcie_cooling.c | 107 ++++++ include/linux/pci-bwctrl.h | 33 ++ include/linux/pci.h | 3 + include/uapi/linux/pci_regs.h | 1 + tools/testing/selftests/Makefile | 1 + tools/testing/selftests/pcie_bwctrl/Makefile | 2 + .../pcie_bwctrl/set_pcie_cooling_state.sh | 122 +++++++ .../selftests/pcie_bwctrl/set_pcie_speed.sh | 67 ++++ 24 files changed, 800 insertions(+), 135 deletions(-) create mode 100644 drivers/pci/pcie/bwctrl.c create mode 100644 drivers/thermal/pcie_cooling.c create mode 100644 include/linux/pci-bwctrl.h create mode 100644 tools/testing/selftests/pcie_bwctrl/Makefile create mode 100755 tools/testing/selftests/pcie_bwctrl/set_pcie_cooling_state.sh create mode 100755 tools/testing/selftests/pcie_bwctrl/set_pcie_speed.sh
Signature · 1 line
2.30.2
Ilpo Järvinen
maintainerPATCH v3 1/10 PCI: Protect Link Control 2 Register with RMW locking
PCIe Bandwidth Controller performs RMW accesses the Link Control 2 Register which can occur concurrently to other sources of Link Control 2 Register writes. Therefore, add Link Control 2 Register among the PCI Express Capability Registers that need RMW locking.
--- Documentation/PCI/pciebus-howto.rst | 8 ++++---- include/linux/pci.h | 1 + 2 files changed, 5 insertions(+), 4 deletions(-)
Documentation/PCI/pciebus-howto.rst +4 -4
@@ -218,7 +218,7 @@ that is shared between many drivers including the service drivers. RMW Capability accessors (pcie_capability_clear_and_set_word(), pcie_capability_set_word(), and pcie_capability_clear_word()) protect a selected set of PCI Express Capability Registers (Link Control -Register and Root Control Register). Any change to those registers -should be performed using RMW accessors to avoid problems due to -concurrent updates. For the up-to-date list of protected registers, -see pcie_capability_clear_and_set_word(). +Register, Root Control Register, and Link Control 2 Register). Any +change to those registers should be performed using RMW accessors to +avoid problems due to concurrent updates. For the up-to-date list of +protected registers, see pcie_capability_clear_and_set_word().
include/linux/pci.h +1 -0
@@ -1243,6 +1243,7 @@ static inline int pcie_capability_clear_and_set_word(struct pci_dev *dev, {switch (pos) {case PCI_EXP_LNKCTL : +case PCI_EXP_LNKCTL2 :case PCI_EXP_RTCTL :return pcie_capability_clear_and_set_word_locked (dev, pos, clear, set);
Signature · 1 line
2.30.2
Re: [PATCH v3 01/10] PCI: Protect Link Control 2 Register with RMW locking
Quoted 1 line · Ilpo Järvinen
PCIe Bandwidth Controller performs RMW accesses the Link Control 2
^ to
Quoted 3 lines
Register which can occur concurrently to other sources of Link Control 2 Register writes. Therefore, add Link Control 2 Register among the PCI Express Capability Registers that need RMW locking.
[...]
Quoted 4 lines
Documentation/PCI/pciebus-howto.rst +0
-0@@ -218,7 +218,7 @@ that is shared between many drivers including the service drivers. RMW Capability accessors (pcie_capability_clear_and_set_word(),
Documentation/PCI/pciebus-howto.rst that is shared between many drivers including the service drivers. · line 224
Quoted 10 lines
Documentation/PCI/pciebus-howto.rst +4
-4pcie_capability_set_word(), and pcie_capability_clear_word()) protect a selected set of PCI Express Capability Registers (Link Control -Register and Root Control Register). Any change to those registers -should be performed using RMW accessors to avoid problems due to -concurrent updates. For the up-to-date list of protected registers, -see pcie_capability_clear_and_set_word(). +Register, Root Control Register, and Link Control 2 Register). Any +change to those registers should be performed using RMW accessors to +avoid problems due to concurrent updates. For the up-to-date list of +protected registers, see pcie_capability_clear_and_set_word().
Maybe use a list of bullet points of the affected registers so that this can be extended more easily in the future.
Otherwise,
Ilpo Järvinen
maintainerPATCH v3 2/10 drm/radeon: Use RMW accessors for changing LNKCTL2
In reply to Ilpo JärvinenDon't assume that only the driver would be accessing LNKCTL2. In the case of upstream (parent), the driver does not even own the device it's changing the registers for.
Use RMW capability accessors which do proper locking to avoid losing concurrent updates to the register value. This change is also useful as a cleanup.
--- drivers/gpu/drm/radeon/cik.c | 40 ++++++++++++++---------------------- drivers/gpu/drm/radeon/si.c | 40 ++++++++++++++---------------------- 2 files changed, 30 insertions(+), 50 deletions(-)
drivers/gpu/drm/radeon/cik.c +15 -25
@@ -9592,28 +9592,18 @@ static void cik_pcie_gen3_enable(struct radeon_device *rdev) PCI_EXP_LNKCTL_HAWD);/* linkctl2 */ -pcie_capability_read_word (root,PCI_EXP_LNKCTL2 , - &tmp16); - tmp16 &= ~(PCI_EXP_LNKCTL2_ENTER_COMP | -PCI_EXP_LNKCTL2_TX_MARGIN ); - tmp16 |= (bridge_cfg2 & - (PCI_EXP_LNKCTL2_ENTER_COMP | -PCI_EXP_LNKCTL2_TX_MARGIN )); -pcie_capability_write_word (root, -PCI_EXP_LNKCTL2 , - tmp16); - -pcie_capability_read_word (rdev->pdev, -PCI_EXP_LNKCTL2 , - &tmp16); - tmp16 &= ~(PCI_EXP_LNKCTL2_ENTER_COMP | -PCI_EXP_LNKCTL2_TX_MARGIN ); - tmp16 |= (gpu_cfg2 & - (PCI_EXP_LNKCTL2_ENTER_COMP | -PCI_EXP_LNKCTL2_TX_MARGIN )); -pcie_capability_write_word (rdev->pdev, -PCI_EXP_LNKCTL2 , - tmp16); +pcie_capability_clear_and_set_word (root,PCI_EXP_LNKCTL2 , +PCI_EXP_LNKCTL2_ENTER_COMP | +PCI_EXP_LNKCTL2_TX_MARGIN , + bridge_cfg2 | + (PCI_EXP_LNKCTL2_ENTER_COMP | +PCI_EXP_LNKCTL2_TX_MARGIN )); +pcie_capability_clear_and_set_word (rdev->pdev,PCI_EXP_LNKCTL2 , +PCI_EXP_LNKCTL2_ENTER_COMP | +PCI_EXP_LNKCTL2_TX_MARGIN , + gpu_cfg2 | + (PCI_EXP_LNKCTL2_ENTER_COMP | +PCI_EXP_LNKCTL2_TX_MARGIN )); tmp =RREG32_PCIE_PORT (PCIE_LC_CNTL4 ); tmp &= ~LC_SET_QUIESCE ;
@@ -9627,15 +9617,15 @@ static void cik_pcie_gen3_enable(struct radeon_device *rdev) speed_cntl &= ~LC_FORCE_DIS_SW_SPEED_CHANGE ;WREG32_PCIE_PORT (PCIE_LC_SPEED_CNTL , speed_cntl); -pcie_capability_read_word (rdev->pdev,PCI_EXP_LNKCTL2 , &tmp16); - tmp16 &= ~PCI_EXP_LNKCTL2_TLS ; + tmp16 =0 ;if (speed_cap ==PCIE_SPEED_8_0GT ) tmp16 |=PCI_EXP_LNKCTL2_TLS_8_0GT ;/* gen3 */ else if (speed_cap ==PCIE_SPEED_5_0GT ) tmp16 |=PCI_EXP_LNKCTL2_TLS_5_0GT ;/* gen2 */ else tmp16 |=PCI_EXP_LNKCTL2_TLS_2_5GT ;/* gen1 */ -pcie_capability_write_word (rdev->pdev,PCI_EXP_LNKCTL2 , tmp16); +pcie_capability_clear_and_set_word (rdev->pdev,PCI_EXP_LNKCTL2 , +PCI_EXP_LNKCTL2_TLS , tmp16); speed_cntl =RREG32_PCIE_PORT (PCIE_LC_SPEED_CNTL ); speed_cntl |=LC_INITIATE_LINK_SPEED_CHANGE ;
drivers/gpu/drm/radeon/si.c +15 -25
@@ -7189,28 +7189,18 @@ static void si_pcie_gen3_enable(struct radeon_device *rdev) PCI_EXP_LNKCTL_HAWD);/* linkctl2 */ -pcie_capability_read_word (root,PCI_EXP_LNKCTL2 , - &tmp16); - tmp16 &= ~(PCI_EXP_LNKCTL2_ENTER_COMP | -PCI_EXP_LNKCTL2_TX_MARGIN ); - tmp16 |= (bridge_cfg2 & - (PCI_EXP_LNKCTL2_ENTER_COMP | -PCI_EXP_LNKCTL2_TX_MARGIN )); -pcie_capability_write_word (root, -PCI_EXP_LNKCTL2 , - tmp16); - -pcie_capability_read_word (rdev->pdev, -PCI_EXP_LNKCTL2 , - &tmp16); - tmp16 &= ~(PCI_EXP_LNKCTL2_ENTER_COMP | -PCI_EXP_LNKCTL2_TX_MARGIN ); - tmp16 |= (gpu_cfg2 & - (PCI_EXP_LNKCTL2_ENTER_COMP | -PCI_EXP_LNKCTL2_TX_MARGIN )); -pcie_capability_write_word (rdev->pdev, -PCI_EXP_LNKCTL2 , - tmp16); +pcie_capability_clear_and_set_word (root,PCI_EXP_LNKCTL2 , +PCI_EXP_LNKCTL2_ENTER_COMP | +PCI_EXP_LNKCTL2_TX_MARGIN , + bridge_cfg2 & + (PCI_EXP_LNKCTL2_ENTER_COMP | +PCI_EXP_LNKCTL2_TX_MARGIN )); +pcie_capability_clear_and_set_word (rdev->pdev,PCI_EXP_LNKCTL2 , +PCI_EXP_LNKCTL2_ENTER_COMP | +PCI_EXP_LNKCTL2_TX_MARGIN , + gpu_cfg2 & + (PCI_EXP_LNKCTL2_ENTER_COMP | +PCI_EXP_LNKCTL2_TX_MARGIN )); tmp =RREG32_PCIE_PORT (PCIE_LC_CNTL4 ); tmp &= ~LC_SET_QUIESCE ;
@@ -7224,15 +7214,15 @@ static void si_pcie_gen3_enable(struct radeon_device *rdev) speed_cntl &= ~LC_FORCE_DIS_SW_SPEED_CHANGE ;WREG32_PCIE_PORT (PCIE_LC_SPEED_CNTL , speed_cntl); -pcie_capability_read_word (rdev->pdev,PCI_EXP_LNKCTL2 , &tmp16); - tmp16 &= ~PCI_EXP_LNKCTL2_TLS ; + tmp16 =0 ;if (speed_cap ==PCIE_SPEED_8_0GT ) tmp16 |=PCI_EXP_LNKCTL2_TLS_8_0GT ;/* gen3 */ else if (speed_cap ==PCIE_SPEED_5_0GT ) tmp16 |=PCI_EXP_LNKCTL2_TLS_5_0GT ;/* gen2 */ else tmp16 |=PCI_EXP_LNKCTL2_TLS_2_5GT ;/* gen1 */ -pcie_capability_write_word (rdev->pdev,PCI_EXP_LNKCTL2 , tmp16); +pcie_capability_clear_and_set_word (rdev->pdev,PCI_EXP_LNKCTL2 , +PCI_EXP_LNKCTL2_TLS , tmp16); speed_cntl =RREG32_PCIE_PORT (PCIE_LC_SPEED_CNTL ); speed_cntl |=LC_INITIATE_LINK_SPEED_CHANGE ;
Signature · 1 line
2.30.2
Ilpo Järvinen
maintainerPATCH v3 3/10 drm/amdgpu: Use RMW accessors for changing LNKCTL2
In reply to Ilpo JärvinenDon't assume that only the driver would be accessing LNKCTL2. In the case of upstream (parent), the driver does not even own the device it's changing the registers for.
Use RMW capability accessors which do proper locking to avoid losing concurrent updates to the register value. This change is also useful as a cleanup.
--- drivers/gpu/drm/amd/amdgpu/cik.c | 41 ++++++++++++-------------------- drivers/gpu/drm/amd/amdgpu/si.c | 41 ++++++++++++-------------------- 2 files changed, 30 insertions(+), 52 deletions(-)
drivers/gpu/drm/amd/amdgpu/cik.c +15 -26
@@ -1638,28 +1638,18 @@ static void cik_pcie_gen3_enable(struct amdgpu_device *adev) PCI_EXP_LNKCTL_HAWD);/* linkctl2 */ -pcie_capability_read_word (root,PCI_EXP_LNKCTL2 , - &tmp16); - tmp16 &= ~(PCI_EXP_LNKCTL2_ENTER_COMP | -PCI_EXP_LNKCTL2_TX_MARGIN ); - tmp16 |= (bridge_cfg2 & - (PCI_EXP_LNKCTL2_ENTER_COMP | -PCI_EXP_LNKCTL2_TX_MARGIN )); -pcie_capability_write_word (root, -PCI_EXP_LNKCTL2 , - tmp16); - -pcie_capability_read_word (adev->pdev, -PCI_EXP_LNKCTL2 , - &tmp16); - tmp16 &= ~(PCI_EXP_LNKCTL2_ENTER_COMP | -PCI_EXP_LNKCTL2_TX_MARGIN ); - tmp16 |= (gpu_cfg2 & - (PCI_EXP_LNKCTL2_ENTER_COMP | -PCI_EXP_LNKCTL2_TX_MARGIN )); -pcie_capability_write_word (adev->pdev, -PCI_EXP_LNKCTL2 , - tmp16); +pcie_capability_clear_and_set_word (root,PCI_EXP_LNKCTL2 , +PCI_EXP_LNKCTL2_ENTER_COMP | +PCI_EXP_LNKCTL2_TX_MARGIN , + bridge_cfg2 & + (PCI_EXP_LNKCTL2_ENTER_COMP | +PCI_EXP_LNKCTL2_TX_MARGIN )); +pcie_capability_clear_and_set_word (adev->pdev,PCI_EXP_LNKCTL2 , +PCI_EXP_LNKCTL2_ENTER_COMP | +PCI_EXP_LNKCTL2_TX_MARGIN , + gpu_cfg2 & + (PCI_EXP_LNKCTL2_ENTER_COMP | +PCI_EXP_LNKCTL2_TX_MARGIN )); tmp =RREG32_PCIE (ixPCIE_LC_CNTL4); tmp &= ~PCIE_LC_CNTL4__LC_SET_QUIESCE_MASK ;
@@ -1674,16 +1664,15 @@ static void cik_pcie_gen3_enable(struct amdgpu_device *adev) speed_cntl &= ~PCIE_LC_SPEED_CNTL__LC_FORCE_DIS_SW_SPEED_CHANGE_MASK ;WREG32_PCIE (ixPCIE_LC_SPEED_CNTL, speed_cntl); -pcie_capability_read_word (adev->pdev,PCI_EXP_LNKCTL2 , &tmp16); - tmp16 &= ~PCI_EXP_LNKCTL2_TLS ; - + tmp16 =0 ;if (adev->pm.pcie_gen_mask &CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3 ) tmp16 |=PCI_EXP_LNKCTL2_TLS_8_0GT ;/* gen3 */ else if (adev->pm.pcie_gen_mask &CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2 ) tmp16 |=PCI_EXP_LNKCTL2_TLS_5_0GT ;/* gen2 */ else tmp16 |=PCI_EXP_LNKCTL2_TLS_2_5GT ;/* gen1 */ -pcie_capability_write_word (adev->pdev,PCI_EXP_LNKCTL2 , tmp16); +pcie_capability_clear_and_set_word (adev->pdev,PCI_EXP_LNKCTL2 , +PCI_EXP_LNKCTL2_TLS , tmp16); speed_cntl =RREG32_PCIE (ixPCIE_LC_SPEED_CNTL); speed_cntl |=PCIE_LC_SPEED_CNTL__LC_INITIATE_LINK_SPEED_CHANGE_MASK ;
drivers/gpu/drm/amd/amdgpu/si.c +15 -26
59 lines not on this page · raw message
Signature · 1 line
2.30.2
Ilpo Järvinen
maintainerPATCH v3 4/10 RDMA/hfi1: Use RMW accessors for changing LNKCTL2
In reply to Ilpo JärvinenDon't assume that only the driver would be accessing LNKCTL2. In the case of upstream (parent), the driver does not even own the device it's changing the registers for.
Use RMW capability accessors which do proper locking to avoid losing concurrent updates to the register value. This change is also useful as a cleanup.
--- drivers/infiniband/hw/hfi1/pcie.c | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-)
drivers/infiniband/hw/hfi1/pcie.c +8 -22
@@ -1212,14 +1212,11 @@ int do_pcie_gen3_transition(struct hfi1_devdata *dd) (u32)lnkctl2);/* only write to parent if target is not as high as ours */ if ((lnkctl2 &PCI_EXP_LNKCTL2_TLS ) < target_vector) { - lnkctl2 &= ~PCI_EXP_LNKCTL2_TLS ; - lnkctl2 |= target_vector; -dd_dev_info (dd,"%s: ..new link control2: 0x%x\n" , __func__, - (u32 )lnkctl2); - ret =pcie_capability_write_word (parent, -PCI_EXP_LNKCTL2 , lnkctl2); + ret =pcie_capability_clear_and_set_word (parent,PCI_EXP_LNKCTL2 , +PCI_EXP_LNKCTL2_TLS , + target_vector);if (ret) { -dd_dev_err (dd,"Unable to write to PCI config\n" ); +dd_dev_err (dd,"Unable to change parent PCI target speed\n" ); return_error =1 ; goto done; }
@@ -1228,22 +1225,11 @@ int do_pcie_gen3_transition(struct hfi1_devdata *dd) }dd_dev_info (dd,"%s: setting target link speed\n" , __func__); - ret =pcie_capability_read_word (dd->pcidev,PCI_EXP_LNKCTL2 , &lnkctl2); + ret =pcie_capability_clear_and_set_word (dd->pcidev,PCI_EXP_LNKCTL2 , +PCI_EXP_LNKCTL2_TLS , + target_vector);if (ret) { -dd_dev_err (dd,"Unable to read from PCI config\n" ); - return_error =1 ; - goto done; - } - -dd_dev_info (dd,"%s: ..old link control2: 0x%x\n" , __func__, - (u32 )lnkctl2); - lnkctl2 &= ~PCI_EXP_LNKCTL2_TLS ; - lnkctl2 |= target_vector; -dd_dev_info (dd,"%s: ..new link control2: 0x%x\n" , __func__, - (u32 )lnkctl2); - ret =pcie_capability_write_word (dd->pcidev,PCI_EXP_LNKCTL2 , lnkctl2); -if (ret) { -dd_dev_err (dd,"Unable to write to PCI config\n" ); +dd_dev_err (dd,"Unable to change device PCI target speed\n" ); return_error =1 ; goto done; }
Signature · 1 line
2.30.2
Re: [PATCH v3 04/10] RDMA/hfi1: Use RMW accessors for changing LNKCTL2
Quoted 54 lines · Ilpo Järvinen
Don't assume that only the driver would be accessing LNKCTL2. In the case of upstream (parent), the driver does not even own the device it's changing the registers for.
Use RMW capability accessors which do proper locking to avoid losing concurrent updates to the register value. This change is also useful as a cleanup.
Suggested-by Lukas Wunner <[email protected]>Signed-off-by Ilpo Järvinen <[email protected]>--- drivers/infiniband/hw/hfi1/pcie.c | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-)drivers/infiniband/hw/hfi1/pcie.c +7
-16@@ -1212,14 +1212,11 @@ int do_pcie_gen3_transition(struct hfi1_devdata *dd) (u32)lnkctl2);/* only write to parent if target is not as high as ours */ if ((lnkctl2 &PCI_EXP_LNKCTL2_TLS ) < target_vector) { - lnkctl2 &= ~PCI_EXP_LNKCTL2_TLS ; - lnkctl2 |= target_vector; -dd_dev_info (dd,"%s: ..new link control2: 0x%x\n" , __func__, - (u32 )lnkctl2); - ret =pcie_capability_write_word (parent, -PCI_EXP_LNKCTL2 , lnkctl2); + ret =pcie_capability_clear_and_set_word (parent,PCI_EXP_LNKCTL2 , +PCI_EXP_LNKCTL2_TLS , + target_vector);if (ret) { -dd_dev_err (dd,"Unable to write to PCI config\n" ); +dd_dev_err (dd,"Unable to change parent PCI target speed\n" ); return_error =1 ; goto done; }@@ -1228,22 +1225,11 @@ int do_pcie_gen3_transition(struct hfi1_devdata *dd) }dd_dev_info (dd,"%s: setting target link speed\n" , __func__); - ret =pcie_capability_read_word (dd->pcidev,PCI_EXP_LNKCTL2 , &lnkctl2); + ret =pcie_capability_clear_and_set_word (dd->pcidev,PCI_EXP_LNKCTL2 , +PCI_EXP_LNKCTL2_TLS , + target_vector);if (ret) { -dd_dev_err (dd,"Unable to read from PCI config\n" ); - return_error =1 ; - goto done; - } - -dd_dev_info (dd,"%s: ..old link control2: 0x%x\n" , __func__, - (u32 )lnkctl2); - lnkctl2 &= ~PCI_EXP_LNKCTL2_TLS ;
drivers/infiniband/hw/hfi1/pcie.c int do_pcie_gen3_transition(struct hfi1_devdata *dd) · line 1235
Quoted 10 lines
drivers/infiniband/hw/hfi1/pcie.c +1
-6- lnkctl2 |= target_vector; -dd_dev_info (dd,"%s: ..new link control2: 0x%x\n" , __func__, - (u32 )lnkctl2); - ret =pcie_capability_write_word (dd->pcidev,PCI_EXP_LNKCTL2 , lnkctl2); -if (ret) { -dd_dev_err (dd,"Unable to write to PCI config\n" ); +dd_dev_err (dd,"Unable to change device PCI target speed\n" ); return_error =1 ; goto done; }
Looks good. Thank you for my suggested changes.
-Dean
External recipient
Ilpo Järvinen
maintainerPATCH v3 5/10 PCI: Store all PCIe Supported Link Speeds
In reply to Ilpo Järvinenstruct pci_bus stores max_bus_speed. Implementation Note in PCIe r6.0.1 sec 7.5.3.18, however, recommends determining supported Link Speeds using the Supported Link Speeds Vector in the Link Capabilities 2 Register (when available).
Add pcie_bus_speeds into struct pci_bus which caches the Supported Link Speeds. The value is taken directly from the Supported Link Speeds Vector or synthetized from the Max Link Speed in the Link Capabilities Register when the Link Capabilities 2 Register is not available.
pcie_bus_speeds field keeps the extra reserved zero at the least significant bit to match the Link Capabilities 2 Register layouting.
--- drivers/pci/probe.c | 28 +++++++++++++++++++++++++++- include/linux/pci.h | 1 + include/uapi/linux/pci_regs.h | 1 + 3 files changed, 29 insertions(+), 1 deletion(-)
drivers/pci/probe.c +27 -1
@@ -767,6 +767,29 @@ static enum pci_bus_speed agp_speed(int agp3, int agpstat)return agp_speeds[index]; } +/* +* Implementation Note in PCIe r6.0.1 sec 7.5.3.18 recommends determining +* supported link speeds using the Supported Link Speeds Vector in the Link +* Capabilities 2 Register (when available). +*/ +static u8 pcie_get_supported_speeds (u32 linkcap,u32 linkcap2) +{ +u8 speeds; + + speeds = linkcap2 &PCI_EXP_LNKCAP2_SLS ; +if (speeds) +return speeds; + +/* +* Synthetize supported link speeds from the Max Link Speed in the +* Link Capabilities Register. +*/ + speeds =PCI_EXP_LNKCAP2_SLS_2_5GB ; +if ((linkcap &PCI_EXP_LNKCAP_SLS ) ==PCI_EXP_LNKCAP_SLS_5_0GB ) + speeds |=PCI_EXP_LNKCAP2_SLS_5_0GB ; +return speeds; +} +static void pci_set_bus_speed (struct pci_bus *bus) {struct pci_dev *bridge = bus->self;
@@ -814,12 +837,15 @@ static void pci_set_bus_speed(struct pci_bus *bus) }if (pci_is_pcie (bridge)) { -u32 linkcap; +u32 linkcap, linkcap2;u16 linksta;pcie_capability_read_dword (bridge,PCI_EXP_LNKCAP , &linkcap); bus->max_bus_speed = pcie_link_speed[linkcap &PCI_EXP_LNKCAP_SLS ]; +pcie_capability_read_dword (bridge,PCI_EXP_LNKCAP2 , &linkcap2); + bus->pcie_bus_speeds =pcie_get_supported_speeds (linkcap, linkcap2); +pcie_capability_read_word (bridge,PCI_EXP_LNKSTA , &linksta);pcie_update_link_speed (bus, linksta); }
include/linux/pci.h +1 -0
@@ -664,6 +664,7 @@ struct pci_bus {unsigned char primary;/* Number of primary bridge */ unsigned char max_bus_speed;/* enum pci_bus_speed */ unsigned char cur_bus_speed;/* enum pci_bus_speed */ +u8 pcie_bus_speeds;/* Supported Link Speeds Vector (+ reserved 0 at LSB) */ #ifdef CONFIG_PCI_DOMAINS_GENERIC int domain_nr;#endif
include/uapi/linux/pci_regs.h +1 -0
@@ -674,6 +674,7 @@#define PCI_EXP_DEVSTA2 0x2a/* Device Status 2 */ #define PCI_CAP_EXP_RC_ENDPOINT_SIZEOF_V2 0x2c/* end of v2 EPs w/o link */ #define PCI_EXP_LNKCAP2 0x2c/* Link Capabilities 2 */ +#define PCI_EXP_LNKCAP2_SLS 0x000000fe/* Supported Link Speeds Vector */ #define PCI_EXP_LNKCAP2_SLS_2_5GB 0x00000002/* Supported Speed 2.5GT/s */ #define PCI_EXP_LNKCAP2_SLS_5_0GB 0x00000004/* Supported Speed 5GT/s */ #define PCI_EXP_LNKCAP2_SLS_8_0GB 0x00000008/* Supported Speed 8GT/s */
Signature · 1 line
2.30.2
Re: [PATCH v3 05/10] PCI: Store all PCIe Supported Link Speeds
Quoted 9 lines · Ilpo Järvinen
struct
pci_busstoresmax_bus_speed. Implementation Note in PCIe r6.0.1 sec 7.5.3.18, however, recommends determining supported Link Speeds using the Supported Link Speeds Vector in the Link Capabilities 2 Register (when available).Add
pcie_bus_speedsinto structpci_buswhich caches the Supported Link Speeds. The value is taken directly from the Supported Link Speeds Vector or synthetized from the Max Link Speed in the Link Capabilities Register when the Link Capabilities 2 Register is not available.
Remind me, what's the reason again to cache this and why is max_bus_speed not sufficient? Is the point that there may be "gaps" in the supported link speeds, i.e. not every bit below the maximum supported speed may be set? And you need to skip over those gaps when throttling to a lower speed?
Maybe this becomes apparent in a later patch but from a reviewer's perspective starting at patch 1 and working one's way forward through the series, it's a bit puzzling, so an explanation in the commit message would be beneficial.
Quoted 2 lines
drivers/pci/probe.c +0
-0
[...]
Quoted 7 lines
drivers/pci/probe.c +7
-0+static u8 pcie_get_supported_speeds (u32 linkcap,u32 linkcap2) +{ +u8 speeds; + + speeds = linkcap2 &PCI_EXP_LNKCAP2_SLS ; +if (speeds) +return speeds;
drivers/pci/probe.c static enum pci_bus_speed agp_speed(int agp3, int agpstat) · line 791
Quoted 10 lines
drivers/pci/probe.c +10
-0+ +/* +* Synthetize supported link speeds from the Max Link Speed in the +* Link Capabilities Register. +*/ + speeds =PCI_EXP_LNKCAP2_SLS_2_5GB ; +if ((linkcap &PCI_EXP_LNKCAP_SLS ) ==PCI_EXP_LNKCAP_SLS_5_0GB ) + speeds |=PCI_EXP_LNKCAP2_SLS_5_0GB ; +return speeds; +}
This seems to duplicate portions of pcie_get_speed_cap().
Can you refactor that function to take advantage of the cached value, i.e. basically return PCIE_LNKCAP2_SLS2SPEED(dev->bus->pcie_bus_speeds)?
Also, I note that pci_set_bus_speed() doesn't use LNKCAP2. Presumably that's a historic artefact but maybe it can be converted to use LNKCAP2 as well. Granted, it's not directly related to this series, but always nice to clean up and rationalize the code.
Thanks,
Lukas
Re: [PATCH v3 05/10] PCI: Store all PCIe Supported Link Speeds
Quoted 11 lines · Lukas Wunner
Quoted 9 lines · Ilpo Järvinen
struct
pci_busstoresmax_bus_speed. Implementation Note in PCIe r6.0.1 sec 7.5.3.18, however, recommends determining supported Link Speeds using the Supported Link Speeds Vector in the Link Capabilities 2 Register (when available).Add
pcie_bus_speedsinto structpci_buswhich caches the Supported Link Speeds. The value is taken directly from the Supported Link Speeds Vector or synthetized from the Max Link Speed in the Link Capabilities Register when the Link Capabilities 2 Register is not available.
Quoted 5 lines
Remind me, what's the reason again to cache this and why is
max_bus_speednot sufficient? Is the point that there may be "gaps" in the supported link speeds, i.e. not every bit below the maximum supported speed may be set? And you need to skip over those gaps when throttling to a lower speed?
FWIW I went and re-read the internal review I provided on May 18. Turns out I already mentioned back then that gaps aren't permitted:
"Per PCIe r6.0.1 sec 8.2.1, the bitfield in the Link Capabilities 2
register is not permitted to contain gaps between maximum supported speed and lowest possible speed (2.5 GT/s Gen1)."
Quoted 1 line
Also, I note that
pci_set_bus_speed()doesn't use LNKCAP2.
About that, I wrote in May:
"Actually, scratch that. pci_set_bus_speed() is fine. Since it's only
interested in the *maximum* link speed, reading just LnkCap is correct. LnkCap2 only needs to be read to determine if a certain speed is *supported*. E.g., even though 32 GT/s are supported, perhaps 16 GT/s are not.
It's rather pcie_get_speed_cap() which should be changed. There's no need for it to read LnkCap2. The commit which introduced this, 6cf57be0f78e, was misguided and had to be fixed up with f1f90e254e46. It could be simplified to just read LnkCap and return pcie_link_speed[linkcap & PCI_EXP_LNKCAP_SLS]. If the device is a Root Port or Downstream Port, it doesn't even have to do that but could return the cached value in subordinate->max_bus_speed. If you add another attribute to struct pci_bus for the downstream device's maximum speed, the maximum speed for Endpoints and Upstream Ports could be returned directly as well from that attribute."
Thanks,
Lukas
Ilpo Järvinen
maintainerRe: [PATCH v3 05/10] PCI: Store all PCIe Supported Link Speeds
Quoted 36 lines · Lukas Wunner
Quoted 11 lines · Lukas Wunner
Quoted 9 lines · Ilpo Järvinen
struct
pci_busstoresmax_bus_speed. Implementation Note in PCIe r6.0.1 sec 7.5.3.18, however, recommends determining supported Link Speeds using the Supported Link Speeds Vector in the Link Capabilities 2 Register (when available).Add
pcie_bus_speedsinto structpci_buswhich caches the Supported Link Speeds. The value is taken directly from the Supported Link Speeds Vector or synthetized from the Max Link Speed in the Link Capabilities Register when the Link Capabilities 2 Register is not available.Quoted 5 lines
Remind me, what's the reason again to cache this and why is
max_bus_speednot sufficient? Is the point that there may be "gaps" in the supported link speeds, i.e. not every bit below the maximum supported speed may be set? And you need to skip over those gaps when throttling to a lower speed?FWIW I went and re-read the internal review I provided on May 18. Turns out I already mentioned back then that gaps aren't permitted:
"Per PCIe r6.0.1 sec 8.2.1, the bitfield in the Link Capabilities 2
register is not permitted to contain gaps between maximum supported speed and lowest possible speed (2.5 GT/s Gen1)."Quoted 1 line
Also, I note that
pci_set_bus_speed()doesn't use LNKCAP2.About that, I wrote in May:
"Actually, scratch that.
pci_set_bus_speed()is fine. Since it's only
interested in the *maximum* link speed, reading just LnkCap is correct. LnkCap2 only needs to be read to determine if a certain speed is *supported*. E.g., even though 32 GT/s are supported, perhaps 16 GT/s are not.
Quoted 10 lines
It's rather
pcie_get_speed_cap()which should be changed. There's no need for it to read LnkCap2. The commit which introduced this,6cf57be0f78e, was misguided and had to be fixed up withf1f90e254e46. It could be simplified to just read LnkCap and return pcie_link_speed[linkcap &PCI_EXP_LNKCAP_SLS]. If the device is a Root Port or Downstream Port, it doesn't even have to do that but could return the cached value insubordinate->max_bus_speed. If you add another attribute to structpci_busfor the downstream device's maximum speed, the maximum speed for Endpoints and Upstream Ports could be returned directly as well from that attribute."
I know it's quite far back so it's understandable to forget :-), but already by May 23rd your position had changed and you wrote this:
'Per the Implementation Note at the end of PCIe r6.0.1 sec 7.5.3.18,
"It is strongly encouraged that software primarily utilize the
Supported Link Speeds Vector instead of the Max Link Speed field, so that software can determine the exact set of supported speeds on current and future hardware. This can avoid software being confused if a future specification defines Links that do not require support for all slower speeds."
This means that it's not sufficient if you just check that the desired speed is lower than the maximum. Instead, you should check if the bit corresponding to the desired speed is set in the LnkCap2 register's Supported Link Speeds Vector.
PCIe r6.0.1 sec 8.2.1 stipulates that the bitfield is not permitted to contain gaps between maximum supported speed and lowest possible speed (2.5 GT/s Gen1). However the Implementation Note suggests that rule may no longer apply in future revisions of the PCIe Base Spec.'
So I'd assume I should still follow the way spec recommends, not the "old method" that may not function correctly after some future version of the spec, or have you really changed position once again on this?
Signature · 1 line
i.
Re: [PATCH v3 05/10] PCI: Store all PCIe Supported Link Speeds
Quoted 66 lines · Ilpo Järvinen
Quoted 36 lines · Lukas Wunner
Quoted 11 lines · Lukas Wunner
Quoted 9 lines · Ilpo Järvinen
struct
pci_busstoresmax_bus_speed. Implementation Note in PCIe r6.0.1 sec 7.5.3.18, however, recommends determining supported Link Speeds using the Supported Link Speeds Vector in the Link Capabilities 2 Register (when available).Add
pcie_bus_speedsinto structpci_buswhich caches the Supported Link Speeds. The value is taken directly from the Supported Link Speeds Vector or synthetized from the Max Link Speed in the Link Capabilities Register when the Link Capabilities 2 Register is not available.Quoted 5 lines
Remind me, what's the reason again to cache this and why is
max_bus_speednot sufficient? Is the point that there may be "gaps" in the supported link speeds, i.e. not every bit below the maximum supported speed may be set? And you need to skip over those gaps when throttling to a lower speed?FWIW I went and re-read the internal review I provided on May 18. Turns out I already mentioned back then that gaps aren't permitted:
"Per PCIe r6.0.1 sec 8.2.1, the bitfield in the Link Capabilities 2
register is not permitted to contain gaps between maximum supported speed and lowest possible speed (2.5 GT/s Gen1)."Quoted 1 line
Also, I note that
pci_set_bus_speed()doesn't use LNKCAP2.About that, I wrote in May:
"Actually, scratch that.
pci_set_bus_speed()is fine. Since it's only
interested in the *maximum* link speed, reading just LnkCap is correct. LnkCap2 only needs to be read to determine if a certain speed is *supported*. E.g., even though 32 GT/s are supported, perhaps 16 GT/s are not.Quoted 10 lines
It's rather
pcie_get_speed_cap()which should be changed. There's no need for it to read LnkCap2. The commit which introduced this,6cf57be0f78e, was misguided and had to be fixed up withf1f90e254e46. It could be simplified to just read LnkCap and return pcie_link_speed[linkcap &PCI_EXP_LNKCAP_SLS]. If the device is a Root Port or Downstream Port, it doesn't even have to do that but could return the cached value insubordinate->max_bus_speed. If you add another attribute to structpci_busfor the downstream device's maximum speed, the maximum speed for Endpoints and Upstream Ports could be returned directly as well from that attribute."I know it's quite far back so it's understandable to forget :-), but already by May 23rd your position had changed and you wrote this:
'Per the Implementation Note at the end of PCIe r6.0.1 sec 7.5.3.18,
"It is strongly encouraged that software primarily utilize the
Supported Link Speeds Vector instead of the Max Link Speed field, so that software can determine the exact set of supported speeds on current and future hardware. This can avoid software being confused if a future specification defines Links that do not require support for all slower speeds."This means that it's not sufficient if you just check that the desired speed is lower than the maximum. Instead, you should check if the bit corresponding to the desired speed is set in the LnkCap2 register's Supported Link Speeds Vector.
Quoted 8 lines
PCIe r6.0.1 sec 8.2.1 stipulates that the bitfield is not permitted to contain gaps between maximum supported speed and lowest possible speed (2.5 GT/s Gen1). However the Implementation Note suggests that rule may no longer apply in future revisions of the PCIe Base Spec.'
So I'd assume I should still follow the way spec recommends, not the "old method" that may not function correctly after some future version of the spec, or have you really changed position once again on this?
I haven't, you're right, I forgot about all those details. Thanks for that blast from the past. ;)
But it would be good to extend the commit message because without all that context, it's difficult to understand why the max_bus_speed isn't sufficient.
Lukas
Ilpo Järvinen
maintainerRe: [PATCH v3 05/10] PCI: Store all PCIe Supported Link Speeds
Quoted 76 lines · Lukas Wunner
Quoted 66 lines · Ilpo Järvinen
Quoted 36 lines · Lukas Wunner
Quoted 11 lines · Lukas Wunner
Quoted 9 lines · Ilpo Järvinen
struct
pci_busstoresmax_bus_speed. Implementation Note in PCIe r6.0.1 sec 7.5.3.18, however, recommends determining supported Link Speeds using the Supported Link Speeds Vector in the Link Capabilities 2 Register (when available).Add
pcie_bus_speedsinto structpci_buswhich caches the Supported Link Speeds. The value is taken directly from the Supported Link Speeds Vector or synthetized from the Max Link Speed in the Link Capabilities Register when the Link Capabilities 2 Register is not available.Quoted 5 lines
Remind me, what's the reason again to cache this and why is
max_bus_speednot sufficient? Is the point that there may be "gaps" in the supported link speeds, i.e. not every bit below the maximum supported speed may be set? And you need to skip over those gaps when throttling to a lower speed?FWIW I went and re-read the internal review I provided on May 18. Turns out I already mentioned back then that gaps aren't permitted:
"Per PCIe r6.0.1 sec 8.2.1, the bitfield in the Link Capabilities 2
register is not permitted to contain gaps between maximum supported speed and lowest possible speed (2.5 GT/s Gen1)."Quoted 1 line
Also, I note that
pci_set_bus_speed()doesn't use LNKCAP2.About that, I wrote in May:
"Actually, scratch that.
pci_set_bus_speed()is fine. Since it's only
interested in the *maximum* link speed, reading just LnkCap is correct. LnkCap2 only needs to be read to determine if a certain speed is *supported*. E.g., even though 32 GT/s are supported, perhaps 16 GT/s are not.Quoted 10 lines
It's rather
pcie_get_speed_cap()which should be changed. There's no need for it to read LnkCap2. The commit which introduced this,6cf57be0f78e, was misguided and had to be fixed up withf1f90e254e46. It could be simplified to just read LnkCap and return pcie_link_speed[linkcap &PCI_EXP_LNKCAP_SLS]. If the device is a Root Port or Downstream Port, it doesn't even have to do that but could return the cached value insubordinate->max_bus_speed. If you add another attribute to structpci_busfor the downstream device's maximum speed, the maximum speed for Endpoints and Upstream Ports could be returned directly as well from that attribute."I know it's quite far back so it's understandable to forget :-), but already by May 23rd your position had changed and you wrote this:
'Per the Implementation Note at the end of PCIe r6.0.1 sec 7.5.3.18,
"It is strongly encouraged that software primarily utilize the
Supported Link Speeds Vector instead of the Max Link Speed field, so that software can determine the exact set of supported speeds on current and future hardware. This can avoid software being confused if a future specification defines Links that do not require support for all slower speeds."This means that it's not sufficient if you just check that the desired speed is lower than the maximum. Instead, you should check if the bit corresponding to the desired speed is set in the LnkCap2 register's Supported Link Speeds Vector.
Quoted 8 lines
PCIe r6.0.1 sec 8.2.1 stipulates that the bitfield is not permitted to contain gaps between maximum supported speed and lowest possible speed (2.5 GT/s Gen1). However the Implementation Note suggests that rule may no longer apply in future revisions of the PCIe Base Spec.'
So I'd assume I should still follow the way spec recommends, not the "old method" that may not function correctly after some future version of the spec, or have you really changed position once again on this?
Quoted 6 lines
I haven't, you're right, I forgot about all those details. Thanks for that blast from the past. ;)
But it would be good to extend the commit message because without all that context, it's difficult to understand why the
max_bus_speedisn't sufficient.
Thanks. I'll extend the commit message.
Signature · 1 line
i.
Ilpo Järvinen
maintainerPATCH v3 6/10 PCI: Cache PCIe device's Supported Speed Vector
In reply to Ilpo JärvinenThe Supported Link Speeds Vector in the Link Capabilities Register 2 corresponds to the bus below on Root Ports and Downstream Ports, whereas it corresponds to the bus above on Upstream Ports and Endpoints. Only the former is currently cached in pcie_bus_speeds in the struct pci_bus. The link speeds that are supported is the intersection of these two.
Store the device's Supported Link Speeds Vector into the struct pci_bus when the Function 0 is enumerated (the Multi-Function Devices must have same speeds the same for all Functions) to be easily able to calculate the intersection of Supported Link Speeds.
--- drivers/pci/probe.c | 10 ++++++++++ drivers/pci/remove.c | 2 ++ include/linux/pci.h | 1 + 3 files changed, 13 insertions(+)
drivers/pci/probe.c +10 -0
@@ -2564,6 +2564,7 @@ static void pci_set_msi_domain(struct pci_dev *dev)void pci_device_add (struct pci_dev *dev,struct pci_bus *bus) { +u8 dev_speeds =0 ;int ret;pci_configure_device (dev);
@@ -2590,11 +2591,20 @@ void pci_device_add(struct pci_dev *dev, struct pci_bus *bus)pci_init_capabilities (dev); +if (pci_is_pcie (dev) &&PCI_FUNC (dev->devfn) ==0 ) { +u32 linkcap, linkcap2; + +pcie_capability_read_dword (dev,PCI_EXP_LNKCAP , &linkcap); +pcie_capability_read_dword (dev,PCI_EXP_LNKCAP2 , &linkcap2); + dev_speeds =pcie_get_supported_speeds (linkcap, linkcap2); + }/* * Add the device to our list of discovered devices * and the bus list for fixup functions, etc. */ down_write (&pci_bus_sem); +if (dev_speeds) + bus->pcie_dev_speeds = dev_speeds;list_add_tail (&dev->bus_list, &bus->devices);up_write (&pci_bus_sem);
drivers/pci/remove.c +2 -0
@@ -36,6 +36,8 @@ static void pci_destroy_dev(struct pci_dev *dev)device_del (&dev->dev);down_write (&pci_bus_sem); +if (pci_is_pcie (dev) &&PCI_FUNC (dev->devfn) ==0 ) + dev->bus->pcie_dev_speeds =0 ;list_del (&dev->bus_list);up_write (&pci_bus_sem);
include/linux/pci.h +1 -0
@@ -665,6 +665,7 @@ struct pci_bus {unsigned char max_bus_speed;/* enum pci_bus_speed */ unsigned char cur_bus_speed;/* enum pci_bus_speed */ u8 pcie_bus_speeds;/* Supported Link Speeds Vector (+ reserved 0 at LSB) */ +u8 pcie_dev_speeds;/* Device's Supported Link Speeds Vector (+ 0 at LSB) */ #ifdef CONFIG_PCI_DOMAINS_GENERIC int domain_nr;#endif
Signature · 1 line
2.30.2
Re: [PATCH v3 06/10] PCI: Cache PCIe device's Supported Speed Vector
Quoted 4 lines · Ilpo Järvinen
The Supported Link Speeds Vector in the Link Capabilities Register 2 corresponds to the bus below on Root Ports and Downstream Ports, whereas it corresponds to the bus above on Upstream Ports and Endpoints.
It would be good to add a pointer to the spec here. I think the relevant section is PCIe r6.1 sec 7.5.3.18 which says:
"Supported Link Speeds Vector - This field indicates the supported
Link speed(s) of the associated Port."
^^^^^^^^^^^^^^^
Obviously the associated port is upstream on a Switch Upstream Port or Endpoint, whereas it is downstream on a Switch Downstream Port or Root Port.
Come to think of it, what about edge cases such as RCiEPs?
Quoted 3 lines
Only the former is currently cached in
pcie_bus_speedsin the structpci_bus. The link speeds that are supported is the intersection of these two.
I'm wondering if caching both is actually necessary. Why not cache just the intersection? Do we need either of the two somewhere?
Quoted 4 lines
Store the device's Supported Link Speeds Vector into the struct
pci_buswhen the Function 0 is enumerated (the Multi-Function Devices must have same speeds the same for all Functions) to be easily able to calculate the intersection of Supported Link Speeds.
Might want to add an explanation what you're going to need this for, I assume it's accessed frequently by the bandwidth throttling driver in a subsequent patch?
Thanks,
Lukas
Ilpo Järvinen
maintainerRe: [PATCH v3 06/10] PCI: Cache PCIe device's Supported Speed Vector
Quoted 11 lines · Lukas Wunner
Quoted 4 lines · Ilpo Järvinen
The Supported Link Speeds Vector in the Link Capabilities Register 2 corresponds to the bus below on Root Ports and Downstream Ports, whereas it corresponds to the bus above on Upstream Ports and Endpoints.
It would be good to add a pointer to the spec here. I think the relevant section is PCIe r6.1 sec 7.5.3.18 which says:
"Supported Link Speeds Vector - This field indicates the supported
Link speed(s) of the associated Port."
Quoted 7 lines
^^^^^^^^^^^^^^^Obviously the associated port is upstream on a Switch Upstream Port or Endpoint, whereas it is downstream on a Switch Downstream Port or Root Port.
Come to think of it, what about edge cases such as RCiEPs?
On real HW I've seen, RCiEPs don't seem to have these speeds at all (PCIe r6.1, sec 7.5.3):
"The Link Capabilities, Link Status, and Link Control registers are required for all Root Ports, Switch Ports, Bridges, and Endpoints that are not RCiEPs. For Functions that do not implement the Link Capabilities, Link Status, and Link Contro registers, these spaces must be hardwired to
0. Link Capabilities 2, Link Status 2, and Link Control 2 registers are required for all Root Ports, Switch Ports, Bridges, and Endpoints (except for RCiEPs) that implement capabilities requiring those registers. For Functions that do not implement the Link Capabilities 2, Link Status 2, and Link Control 2 registers, these spaces must be hardwired to 0b."
Quoted 6 lines
Quoted 3 lines
Only the former is currently cached in
pcie_bus_speedsin the structpci_bus. The link speeds that are supported is the intersection of these two.I'm wondering if caching both is actually necessary. Why not cache just the intersection? Do we need either of the two somewhere?
Intersection is enough at least for bwctrl. The only downside that is barely worth mentioning is that the bus SLSV has to be re-read when function 0 sets the intersection.
I can think of somebody wanting to expose the list of both supported speed to userspace though sysfs (not done by this patch series), but they could be read from the registers in that case so that use case doesn't really matter much, IMO.
Quoted 8 lines
Quoted 4 lines
Store the device's Supported Link Speeds Vector into the struct
pci_buswhen the Function 0 is enumerated (the Multi-Function Devices must have same speeds the same for all Functions) to be easily able to calculate the intersection of Supported Link Speeds.Might want to add an explanation what you're going to need this for, I assume it's accessed frequently by the bandwidth throttling driver in a subsequent patch?
Yes. I tend to try to avoid forward references because some maintainers complain about them (leading to minimal changes where true motivations have to be hidden because "future" cannot be used to motivate a change even if that's often the truest motivation within a patch series). But I'll add a fwd ref here to make it more obvious. :-)
Signature · 1 line
i.
Re: [PATCH v3 06/10] PCI: Cache PCIe device's Supported Speed Vector
Quoted 9 lines · Ilpo Järvinen
Quoted 7 lines · Lukas Wunner
Quoted 3 lines · Ilpo Järvinen
Only the former is currently cached in
pcie_bus_speedsin the structpci_bus. The link speeds that are supported is the intersection of these two.I'm wondering if caching both is actually necessary. Why not cache just the intersection? Do we need either of the two somewhere?
Quoted 8 lines
Intersection is enough at least for bwctrl. The only downside that is barely worth mentioning is that the bus SLSV has to be re-read when function 0 sets the intersection.
I can think of somebody wanting to expose the list of both supported speed to userspace though sysfs (not done by this patch series), but they could be read from the registers in that case so that use case doesn't really matter much, IMO.
Yes, that would be a reasonable argument to keep both values instead of storing just the intersection.
Quoted 9 lines
Quoted 8 lines
Quoted 4 lines
Store the device's Supported Link Speeds Vector into the struct
pci_buswhen the Function 0 is enumerated (the Multi-Function Devices must have same speeds the same for all Functions) to be easily able to calculate the intersection of Supported Link Speeds.Might want to add an explanation what you're going to need this for, I assume it's accessed frequently by the bandwidth throttling driver in a subsequent patch?
Quoted 5 lines
Yes. I tend to try to avoid forward references because some maintainers complain about them (leading to minimal changes where true motivations have to be hidden because "future" cannot be used to motivate a change even if that's often the truest motivation within a patch series). But I'll add a fwd ref here to make it more obvious. :-)
Bjorn has used phrases such as "We're about to ..." a couple of times in commit messages to convey that a particular change in the present patch will be taken advantage of by a subsequent patch.
I've used the same phrase but got criticized (in other subsystems) for using "we".
So I use phrases such as:
"An upcoming commit will create DOE mailboxes upon device enumeration by
the PCI core. Their lifetime shall not be limited by a driver. Therefore rework..." (see 022b66f38195)
Can also reference the past:
"The PCI core has just been amended to create a pci_doe_mb struct for
every DOE instance on device enumeration. [...] That leaves [...] without any callers, so drop them." (see 74e491e5d1bc)
If someone finds your commit e.g. through git blame, it may help them enormously if you provide context in the commit message. If maintainers in other subsystem tell you otherwise, they're wrong. ;)
Thanks,
Lukas
Ilpo Järvinen
maintainerPATCH v3 7/10 PCI/LINK: Re-add BW notification portdrv as PCIe BW controller
In reply to Ilpo JärvinenThis mostly reverts b4c7d2076b4e ("PCI/LINK: Remove bandwidth notification"), however, there are small tweaks:
1) Call it PCIe bwctrl (bandwidth controller) instead of just bandwidth notifications.
2) Don't print the notifications into kernel log, just keep the current link speed updated.
3) Use concurrency safe LNKCTL RMW operations.
4) Read link speed after enabling the notification to ensure the current link speed is correct from the start.
5) Add local variable in probe for srv->port.
6) Handle link speed read and LBMS write race in pcie_bw_notification_irq().
The reason for 1) is to indicate the increased scope of the driver. A subsequent commit extends the driver to allow controlling PCIe bandwidths from user space upon crossing thermal thresholds.
While 2) is somewhat unfortunate, the log spam was the source of complaints that eventually lead to the removal of the bandwidth notifications driver (see the links below for further information). After re-adding this driver back the userspace can, if it wishes to, observe the link speed changes using the current bus speed files under sysfs.
--- drivers/pci/pcie/Kconfig | 8 +++ drivers/pci/pcie/Makefile | 1 + drivers/pci/pcie/bwctrl.c | 131 +++++++++++++++++++++++++++++++++++++ drivers/pci/pcie/portdrv.c | 9 +-- drivers/pci/pcie/portdrv.h | 10 ++- 5 files changed, 153 insertions(+), 6 deletions(-) create mode 100644 drivers/pci/pcie/bwctrl.c
drivers/pci/pcie/Kconfig +8 -0
@@ -137,6 +137,14 @@ config PCIE_PTM This is only useful if you have devices that support PTM, but it is safe to enable even if you don't. +config PCIE_BW + bool "PCI Express Bandwidth Change Notification" + depends on PCIEPORTBUS + help + This enables PCI Express Bandwidth Change Notification. If + you know link width or rate changes occur to correct unreliable + links, you may answer Y. + config PCIE_EDR bool "PCI Express Error Disconnect Recover support" depends on PCIE_DPC && ACPI
drivers/pci/pcie/Makefile +1 -0
@@ -12,4 +12,5 @@ obj-$(CONFIG_PCIEAER_INJECT) += aer_inject.o obj-$(CONFIG_PCIE_PME) += pme.o obj-$(CONFIG_PCIE_DPC) += dpc.o obj-$(CONFIG_PCIE_PTM) += ptm.o +obj-$(CONFIG_PCIE_BW) += bwctrl.o obj-$(CONFIG_PCIE_EDR) += edr.o
drivers/pci/pcie/bwctrl.c new file +131 -0
131 lines not on this page · raw message
drivers/pci/pcie/portdrv.c +5 -4
@@ -67,7 +67,7 @@ static int pcie_message_numbers(struct pci_dev *dev, int mask,*/ if (mask & (PCIE_PORT_SERVICE_PME |PCIE_PORT_SERVICE_HP | -PCIE_PORT_SERVICE_BWNOTIF )) { +PCIE_PORT_SERVICE_BWCTRL )) {pcie_capability_read_word (dev,PCI_EXP_FLAGS , ®16); *pme = (reg16 &PCI_EXP_FLAGS_IRQ ) >>9 ; nvec = *pme +1 ;
@@ -149,11 +149,11 @@ static int pcie_port_enable_irq_vec(struct pci_dev *dev, int *irqs, int mask)/* PME, hotplug and bandwidth notification share an MSI/MSI-X vector */ if (mask & (PCIE_PORT_SERVICE_PME |PCIE_PORT_SERVICE_HP | -PCIE_PORT_SERVICE_BWNOTIF )) { +PCIE_PORT_SERVICE_BWCTRL )) { pcie_irq =pci_irq_vector (dev, pme); irqs[PCIE_PORT_SERVICE_PME_SHIFT ] = pcie_irq; irqs[PCIE_PORT_SERVICE_HP_SHIFT ] = pcie_irq; - irqs[PCIE_PORT_SERVICE_BWNOTIF_SHIFT ] = pcie_irq; + irqs[PCIE_PORT_SERVICE_BWCTRL_SHIFT ] = pcie_irq; }if (mask &PCIE_PORT_SERVICE_AER )
@@ -270,7 +270,7 @@ static int get_port_device_capability(struct pci_dev *dev)pcie_capability_read_dword (dev,PCI_EXP_LNKCAP , &linkcap);if (linkcap &PCI_EXP_LNKCAP_LBNC ) - services |=PCIE_PORT_SERVICE_BWNOTIF ; + services |=PCIE_PORT_SERVICE_BWCTRL ; }return services;
@@ -828,6 +828,7 @@ static void __init pcie_init_services(void)pcie_pme_init ();pcie_dpc_init ();pcie_hp_init (); +pcie_bwctrl_init (); }static int __init pcie_portdrv_init (void )
drivers/pci/pcie/portdrv.h +8 -2
@@ -20,8 +20,8 @@#define PCIE_PORT_SERVICE_HP (1 << PCIE_PORT_SERVICE_HP_SHIFT)#define PCIE_PORT_SERVICE_DPC_SHIFT 3/* Downstream Port Containment */ #define PCIE_PORT_SERVICE_DPC (1 << PCIE_PORT_SERVICE_DPC_SHIFT) -#define PCIE_PORT_SERVICE_BWNOTIF_SHIFT 4/* Bandwidth notification */ -#define PCIE_PORT_SERVICE_BWNOTIF (1 << PCIE_PORT_SERVICE_BWNOTIF_SHIFT) +#define PCIE_PORT_SERVICE_BWCTRL_SHIFT 4/* Bandwidth Controller (notifications) */ +#define PCIE_PORT_SERVICE_BWCTRL (1 << PCIE_PORT_SERVICE_BWCTRL_SHIFT)#define PCIE_PORT_DEVICE_MAXSERVICES 5
@@ -53,6 +53,12 @@ int pcie_dpc_init(void);static inline int pcie_dpc_init (void ) {return 0 ; }#endif +#ifdef CONFIG_PCIE_BW +int pcie_bwctrl_init (void ); +#else +static inline int pcie_bwctrl_init (void ) {return 0 ; } +#endif +/* Port Type */ #define PCIE_ANY_PORT (~0)
Signature · 1 line
2.30.2
Re: [PATCH v3 07/10] PCI/LINK: Re-add BW notification portdrv as PCIe BW controller
Quoted 18 lines · Ilpo Järvinen
This mostly reverts
b4c7d2076b4e("PCI/LINK: Remove bandwidth notification"), however, there are small tweaks:1) Call it PCIe bwctrl (bandwidth controller) instead of just bandwidth notifications.
2) Don't print the notifications into kernel log, just keep the current link speed updated.
3) Use concurrency safe LNKCTL RMW operations.
4) Read link speed after enabling the notification to ensure the current link speed is correct from the start.
5) Add local variable in probe forsrv->port.
6) Handle link speed read and LBMS write race inpcie_bw_notification_irq().The reason for 1) is to indicate the increased scope of the driver. A subsequent commit extends the driver to allow controlling PCIe bandwidths from user space upon crossing thermal thresholds.
Quoted 6 lines
While 2) is somewhat unfortunate, the log spam was the source of complaints that eventually lead to the removal of the bandwidth notifications driver (see the links below for further information). After re-adding this driver back the userspace can, if it wishes to, observe the link speed changes using the current bus speed files under sysfs.
Good commit message.
Quoted 4 lines
drivers/pci/pcie/Kconfig +0
-0@@ -137,6 +137,14 @@ config PCIE_PTM This is only useful if you have devices that support PTM, but it
drivers/pci/pcie/Kconfig config PCIE_PTM · line 147
Quoted 10 lines
drivers/pci/pcie/Kconfig +8
-0is safe to enable even if you don't. +config PCIE_BW + bool "PCI Express Bandwidth Change Notification" + depends on PCIEPORTBUS + help + This enables PCI Express Bandwidth Change Notification. If + you know link width or rate changes occur to correct unreliable + links, you may answer Y. +
For an end user browsing Kconfig entries, this isn't as helpful as it could be. Maybe mention that autonomous link changes are automatically picked up and observable through sysfs (name the relevant attributes).
Quoted 4 lines
drivers/pci/pcie/bwctrl.c new file +1
-0@@ -0,0 +1,131 @@ +// SPDX-License-Identifier: GPL-2.0+
drivers/pci/pcie/bwctrl.c line 11
Quoted 10 lines
drivers/pci/pcie/bwctrl.c new file +10
-0+/* +* PCI Express Link Bandwidth Notification services driver +* Author: Alexandru Gagniuc <[email protected]> +* +* Copyright (C) 2019, Dell Inc +* +* The PCIe Link Bandwidth Notification provides a way to notify the +* operating system when the link width or data rate changes. This +* capability is required for all root ports and downstream ports +* supporting links wider than x1 and/or multiple link speeds.
Capitalize Root Ports and Downstream Ports.
Reference the spec section prescribing this.
drivers/pci/pcie/bwctrl.c line 26
Quoted 4 lines
drivers/pci/pcie/bwctrl.c new file +4
-0+static bool pcie_link_bandwidth_notification_supported (struct pci_dev *dev) +{ +int ret; +u32 lnk_cap;
Inverse Christmas tree?
drivers/pci/pcie/bwctrl.c line 38
Quoted 7 lines
drivers/pci/pcie/bwctrl.c new file +7
-0+static void pcie_enable_link_bandwidth_notification (struct pci_dev *dev) +{ +u16 link_status; +int ret; + +pcie_capability_write_word (dev,PCI_EXP_LNKSTA ,PCI_EXP_LNKSTA_LBMS ); +pcie_capability_set_word (dev,PCI_EXP_LNKCTL ,PCI_EXP_LNKCTL_LBMIE );
I'm wondering why we're not enabling LABIE as well? (And clear LABS.)
Can't it happen that we miss bandwidth changes unless we enable that as well?
drivers/pci/pcie/bwctrl.c line 87
Quoted 8 lines
drivers/pci/pcie/bwctrl.c new file +8
-0+static int pcie_bandwidth_notification_probe (struct pcie_device *srv) +{ +struct pci_dev *port = srv->port; +int ret; + +/* Single-width or single-speed ports do not have to support this. */ +if (!pcie_link_bandwidth_notification_supported (port)) +return -ENODEV ;
I'm wondering if this should be checked in get_port_device_capability() instead?
drivers/pci/pcie/bwctrl.c line 90
Quoted 2 lines
drivers/pci/pcie/bwctrl.c new file +2
-0+ ret =request_irq (srv->irq, pcie_bw_notification_irq, +IRQF_SHARED ,"PCIe BW ctrl" , srv);
Is there a reason to run the IRQ handler in hardirq context or would it work to run it in an IRQ thread? Usually on systems than enable PREEMPT_RT, a threaded IRQ handler is preferred, so unless hardirq context is necessary, I'd recommend using an IRQ thread.
Thanks,
Lukas
Ilpo Järvinen
maintainerRe: [PATCH v3 07/10] PCI/LINK: Re-add BW notification portdrv as PCIe BW controller
Quoted 43 lines · Lukas Wunner
Quoted 18 lines · Ilpo Järvinen
This mostly reverts
b4c7d2076b4e("PCI/LINK: Remove bandwidth notification"), however, there are small tweaks:1) Call it PCIe bwctrl (bandwidth controller) instead of just bandwidth notifications.
2) Don't print the notifications into kernel log, just keep the current link speed updated.
3) Use concurrency safe LNKCTL RMW operations.
4) Read link speed after enabling the notification to ensure the current link speed is correct from the start.
5) Add local variable in probe forsrv->port.
6) Handle link speed read and LBMS write race inpcie_bw_notification_irq().The reason for 1) is to indicate the increased scope of the driver. A subsequent commit extends the driver to allow controlling PCIe bandwidths from user space upon crossing thermal thresholds.
Quoted 6 lines
While 2) is somewhat unfortunate, the log spam was the source of complaints that eventually lead to the removal of the bandwidth notifications driver (see the links below for further information). After re-adding this driver back the userspace can, if it wishes to, observe the link speed changes using the current bus speed files under sysfs.
Good commit message.
drivers/pci/pcie/bwctrl.c line 38
Quoted 10 lines
drivers/pci/pcie/bwctrl.c new file +7
-0+static void pcie_enable_link_bandwidth_notification (struct pci_dev *dev) +{ +u16 link_status; +int ret; + +pcie_capability_write_word (dev,PCI_EXP_LNKSTA ,PCI_EXP_LNKSTA_LBMS ); +pcie_capability_set_word (dev,PCI_EXP_LNKCTL ,PCI_EXP_LNKCTL_LBMIE );I'm wondering why we're not enabling LABIE as well? (And clear LABS.)
Quoted 2 lines
Can't it happen that we miss bandwidth changes unless we enable that as well?
Thanks. Reading the spec, it sounds like both are necessary to not miss changes.
Quoted 11 lines
drivers/pci/pcie/bwctrl.c line 87
Quoted 8 lines
drivers/pci/pcie/bwctrl.c new file +8
-0+static int pcie_bandwidth_notification_probe (struct pcie_device *srv) +{ +struct pci_dev *port = srv->port; +int ret; + +/* Single-width or single-speed ports do not have to support this. */ +if (!pcie_link_bandwidth_notification_supported (port)) +return -ENODEV ;I'm wondering if this should be checked in
get_port_device_capability()instead?
I can move the check there.
Quoted 8 lines
drivers/pci/pcie/bwctrl.c line 90
Quoted 2 lines
drivers/pci/pcie/bwctrl.c new file +2
-0+ ret =request_irq (srv->irq, pcie_bw_notification_irq, +IRQF_SHARED ,"PCIe BW ctrl" , srv);Is there a reason to run the IRQ handler in hardirq context or would it work to run it in an IRQ thread? Usually on systems than enable
PREEMPT_RT, a threaded IRQ handler is preferred, so unless hardirq context is necessary, I'd recommend using an IRQ thread.
Can I somehow postpone the decision between IRQ_NONE / IRQ_HANDLED straight into the thread_fn? One LNKSTA read is necessary to decide that.
I suppose the other write + reread of LNKSTA could be moved into thread_fn even if the first read would not be movable.
Signature · 1 line
i.
Re: [PATCH v3 07/10] PCI/LINK: Re-add BW notification portdrv as PCIe BW controller
Quoted 8 lines · Ilpo Järvinen
Quoted 7 lines · Lukas Wunner
drivers/pci/pcie/bwctrl.c line 38
Quoted 2 lines · Ilpo Järvinen
drivers/pci/pcie/bwctrl.c new file +2
-0+pcie_capability_write_word (dev,PCI_EXP_LNKSTA ,PCI_EXP_LNKSTA_LBMS ); +pcie_capability_set_word (dev,PCI_EXP_LNKCTL ,PCI_EXP_LNKCTL_LBMIE );I'm wondering why we're not enabling LABIE as well? (And clear LABS.)
Quoted 5 lines
Quoted 2 lines
Can't it happen that we miss bandwidth changes unless we enable that as well?
Thanks. Reading the spec, it sounds like both are necessary to not miss changes.
I guess this is an artefact of Alex' original patch. I don't know why he enabled one but not the other.
Quoted 9 lines
Quoted 8 lines
drivers/pci/pcie/bwctrl.c line 90
Quoted 2 lines
drivers/pci/pcie/bwctrl.c new file +2
-0+ ret =request_irq (srv->irq, pcie_bw_notification_irq, +IRQF_SHARED ,"PCIe BW ctrl" , srv);Is there a reason to run the IRQ handler in hardirq context or would it work to run it in an IRQ thread? Usually on systems than enable
PREEMPT_RT, a threaded IRQ handler is preferred, so unless hardirq context is necessary, I'd recommend using an IRQ thread.
Quoted 6 lines
Can I somehow postpone the decision between
IRQ_NONE/IRQ_HANDLEDstraight into thethread_fn? One LNKSTA read is necessary to decide that.I suppose the other write + reread of LNKSTA could be moved into
thread_fneven if the first read would not be movable.
You can just use request_threaded_irq(), pass NULL for the "handler" argument and pcie_bw_notification_irq for the "thread_fn" argument.
Because of the NULL argument for "handler", the hardirq handler will then become irq_default_primary_handler(). Which does nothing else but return IRQ_WAKE_THREAD. And the decision between IRQ_NONE and IRQ_HANDLED is then indeed postponed to the IRQ thread.
Alternatively you can split the IRQ handler, move the check whether PCI_EXP_LNKSTA_LBMS is set to the hardirq handler and keep the rest in the IRQ thread. Means you won't have unnecessary wakeups of the IRQ thread if the interrupt is caused by something else (I understand it's always shared with PME and hotplug). But you'll spend more time in hardirq context. In practice bandwidth notifications may be more frequent than PME and hotplug interrupts, so unnecessary wakeups of the IRQ thread will be rare. Hence not splitting the IRQ handler may be better. Dunno. Ask Thomas Gleixner or Sebastian Siewior. :)
Thanks,
Lukas
Ilpo Järvinen
maintainerPATCH v3 8/10 PCI/bwctrl: Add "controller" part into PCIe bwctrl
In reply to Ilpo JärvinenAdd "controller" parts into PCIe bwctrl for limiting PCIe Link Speed (due to thermal reasons).
PCIe bandwidth controller introduces an in-kernel API to set PCIe Link Speed. This new API is intended to be used in an upcoming commit that adds a thermal cooling device to throttle PCIe bandwidth when thermal thresholds are reached. No users are introduced in this commit yet.
The PCIe bandwidth control procedure is as follows. The requested speed is validated against Link Speeds supported by the port and downstream device. Then bandwidth controller sets the Target Link Speed in the Link Control 2 Register and retrains the PCIe Link.
Bandwidth notifications enable the cur_bus_speed in the struct pci_bus to keep track PCIe Link Speed changes. This keeps the link speed seen through sysfs correct (both for PCI device and thermal cooling device). While bandwidth notifications should also be generated when bandwidth controller alters the PCIe Link Speed, a few platforms do not deliver LMBS interrupt after Link Training as expected. Thus, after changing the Link Speed, bandwidth controller makes additional read for the Link Status Register to ensure cur_bus_speed is consistent with the new PCIe Link Speed.
--- MAINTAINERS | 7 ++ drivers/pci/pcie/Kconfig | 9 +- drivers/pci/pcie/bwctrl.c | 177 +++++++++++++++++++++++++++++++++++-- include/linux/pci-bwctrl.h | 17 ++++ 4 files changed, 201 insertions(+), 9 deletions(-) create mode 100644 include/linux/pci-bwctrl.h
MAINTAINERS +7 -0
@@ -16569,6 +16569,13 @@ F: include/linux/pci* F: include/uapi/linux/pci* F: lib/pci* +PCIE BANDWIDTH CONTROLLER +M: Ilpo Järvinen <[email protected]> +L: [email protected] +S: Supported +F: drivers/pci/pcie/bwctrl.c +F: include/linux/pci-bwctrl.h + PCIE DRIVER FOR AMAZON ANNAPURNA LABS M: Jonathan Chocron <[email protected]> L: [email protected]
drivers/pci/pcie/Kconfig +5 -4
@@ -138,12 +138,13 @@ config PCIE_PTM is safe to enable even if you don't. config PCIE_BW - bool "PCI Express Bandwidth Change Notification" + bool "PCI Express Bandwidth Controller" depends on PCIEPORTBUS help - This enables PCI Express Bandwidth Change Notification. If - you know link width or rate changes occur to correct unreliable - links, you may answer Y. + This enables PCI Express Bandwidth Controller. The Bandwidth + Controller allows controlling PCIe link speed and listens for link + peed Change Notifications. If you know link width or rate changes + occur to correct unreliable links, you may answer Y. config PCIE_EDR bool "PCI Express Error Disconnect Recover support"
drivers/pci/pcie/bwctrl.c +172 -5
219 lines not on this page · raw message
include/linux/pci-bwctrl.h new file +17 -0
@@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* PCIe bandwidth controller +* +* Copyright (C) 2023 Intel Corporation. +*/ + +#ifndef LINUX_PCI_BWCTRL_H +#define LINUX_PCI_BWCTRL_H + +#include <linux/pci.h> + +struct pcie_device ; + +int bwctrl_set_current_speed (struct pcie_device *srv,enum pci_bus_speed speed); + +#endif
Signature · 1 line
2.30.2
Re: [PATCH v3 08/10] PCI/bwctrl: Add "controller" part into PCIe bwctrl
MAINTAINERS F: include/linux/pci* · line 16578
Quoted 13 lines · Ilpo Järvinen
MAINTAINERS +7
-0@@ -16569,6 +16569,13 @@ F: include/linux/pci* F: include/uapi/linux/pci* F: lib/pci* +PCIE BANDWIDTH CONTROLLER +M: Ilpo Järvinen <[email protected]> +L: [email protected] +S: Supported +F: drivers/pci/pcie/bwctrl.c +F: include/linux/pci-bwctrl.h +
Maybe add this already in the preceding patch.
drivers/pci/pcie/Kconfig config PCIE_PTM · line 141
Quoted 8 lines
drivers/pci/pcie/Kconfig +1
-1@@ -138,12 +138,13 @@ config PCIE_PTM is safe to enable even if you don't. config PCIE_BW - bool "PCI Express Bandwidth Change Notification" + bool "PCI Express Bandwidth Controller"
I'd fold this change into the preceding patch. Deleting a line introduced by the preceding patch isn't great.
Never mind that the patch isn't a clean revert that way. Your approach of making changes to the original version of the bandwith monitoring driver and calling out those changes in the commit message seems fine to me.
drivers/pci/pcie/Kconfig config PCIE_PTM · line 147
Quoted 9 lines
drivers/pci/pcie/Kconfig +4
-3depends on PCIEPORTBUS help - This enables PCI Express Bandwidth Change Notification. If - you know link width or rate changes occur to correct unreliable - links, you may answer Y. + This enables PCI Express Bandwidth Controller. The Bandwidth + Controller allows controlling PCIe link speed and listens for link + peed Change Notifications. If you know link width or rate changes + occur to correct unreliable links, you may answer Y.
It would be neater if you could avoid deleting lines introduced by the preceding patch. Ideally you'd add a new paragraph, thus only add new lines but not delete any existing ones.
drivers/pci/pcie/bwctrl.c line 4
Quoted 8 lines
drivers/pci/pcie/bwctrl.c +2
-1@@ -1,14 +1,16 @@// SPDX-License-Identifier: GPL-2.0+ /* -* PCI Express Link Bandwidth Notification services driver +* PCIe bandwidth controller +*
Again, fold this change into the preceding patch please.
drivers/pci/pcie/bwctrl.c line 8
Quoted 4 lines
drivers/pci/pcie/bwctrl.c +1
-0* Author: Alexandru Gagniuc <[email protected]> * * Copyright (C) 2019, Dell Inc +* Copyright (C) 2023 Intel Corporation.
For extra neatness, drop the comma in the preceding patch and the period in this patch.
drivers/pci/pcie/bwctrl.c line 13
Quoted 8 lines
drivers/pci/pcie/bwctrl.c +4
-4-* The PCIe Link Bandwidth Notification provides a way to notify the -* operating system when the link width or data rate changes. This -* capability is required for all root ports and downstream ports -* supporting links wider than x1 and/or multiple link speeds. +* The PCIe Bandwidth Controller provides a way to alter PCIe link speeds +* and notify the operating system when the link width or data rate changes. +* The notification capability is required for all Root Ports and Downstream +* Ports supporting links wider than x1 and/or multiple link speeds.
Again, adding a new paragraph and not deleting lines introduced by the preceding patch would be much nicer.
drivers/pci/pcie/bwctrl.c line 30
Quoted 9 lines
drivers/pci/pcie/bwctrl.c +9
-0+#include <linux/bitops.h> +#include <linux/errno.h> +#include <linux/mutex.h> +#include <linux/pci.h> +#include <linux/pci-bwctrl.h> +#include <linux/types.h> + +#include <asm/rwonce.h> +
Which of these are necessary for functionality introduced by this patch and which are necessary anyway and should be moved to the preceding patch?
Quoted 2 lines
+/**
+ * structbwctrl_service_data- PCIe Port Bandwidth Controller
Code comment at the top of this file says "PCIe bandwidth controller", use here as well for neatness.
drivers/pci/pcie/bwctrl.c line 56
Quoted 10 lines
drivers/pci/pcie/bwctrl.c +10
-0+static u16 speed2lnkctl2 (enum pci_bus_speed speed) +{ +static const u16 speed_conv[] = { + [PCIE_SPEED_2_5GT ] =PCI_EXP_LNKCTL2_TLS_2_5GT , + [PCIE_SPEED_5_0GT ] =PCI_EXP_LNKCTL2_TLS_5_0GT , + [PCIE_SPEED_8_0GT ] =PCI_EXP_LNKCTL2_TLS_8_0GT , + [PCIE_SPEED_16_0GT ] =PCI_EXP_LNKCTL2_TLS_16_0GT , + [PCIE_SPEED_32_0GT ] =PCI_EXP_LNKCTL2_TLS_32_0GT , + [PCIE_SPEED_64_0GT ] =PCI_EXP_LNKCTL2_TLS_64_0GT , + };
Looks like this could be a u8 array to save a little bit of memory.
Also, this seems to duplicate pcie_link_speed[] defined in probe.c.
drivers/pci/pcie/bwctrl.c static irqreturn_t pcie_bw_notification_irq(int irq, void *context) · line 143
Quoted 10 lines
drivers/pci/pcie/bwctrl.c +10
-0+static int bwctrl_select_speed (struct pcie_device *srv,enum pci_bus_speed *speed) +{ +struct pci_bus *bus = srv->port->subordinate; +u8 speeds, dev_speeds; +int i; + +if (*speed >PCIE_LNKCAP2_SLS2SPEED (bus->pcie_bus_speeds)) +return -EINVAL ; + + dev_speeds =READ_ONCE (bus->pcie_dev_speeds);
Hm, why is the compiler barrier needed?
drivers/pci/pcie/bwctrl.c static irqreturn_t pcie_bw_notification_irq(int irq, void *context) · line 146
Quoted 3 lines
drivers/pci/pcie/bwctrl.c +3
-0+/* Only the lowest speed can be set when there are no devices */ +if (!dev_speeds) + dev_speeds =PCI_EXP_LNKCAP2_SLS_2_5GB ;
Maybe move this to patch [06/10], i.e. set dev->bus->pcie_dev_speeds to PCI_EXP_LNKCAP2_SLS_2_5GB on removal (instead of 0).
Quoted 4 lines
drivers/pci/pcie/bwctrl.c +4
-0+ speeds = bus->pcie_bus_speeds & dev_speeds; + i =BIT (fls (speeds)); +while (i >=PCI_EXP_LNKCAP2_SLS_2_5GB ) { +enum pci_bus_speed candidate;
drivers/pci/pcie/bwctrl.c static irqreturn_t pcie_bw_notification_irq(int irq, void *context) · line 169
Quoted 10 lines
drivers/pci/pcie/bwctrl.c +10
-0+ +if (speeds & i) { + candidate =PCIE_LNKCAP2_SLS2SPEED (i); +if (candidate <= *speed) { + *speed = candidate; +return 0 ; + } + } + i >>=1 ; + }
Can't we just do something like
supported_speeds = bus->pcie_bus_speeds & dev_speeds; desired_speeds = GEN_MASK(pcie_link_speed[*speed], 1); *speed = BIT(fls(supported_speeds & desired_speeds));
and thus avoid the loop altogether?
Quoted 8 lines
+/**
+ *bwctrl_set_current_speed- Set downstream link speed for PCIe port
+ * @srv: PCIe port
+ * @speed: PCIe bus speed to set
+ *
+ * Attempts to set PCIe port link speed to @speed. As long as @speed is less
+ * than the maximum of what is supported by @srv, the speed is adjusted
+ * downwards to the best speed supported by both the port and device
Quoted 8 lines
+ * underneath it.
+ *
+ * Return:
+ * * 0 - on success
+ * *-EINVAL- @speed is higher than the maximum @srv supports
+ * *-ETIMEDOUT- changing link speed took too long
+ * *-EAGAIN- link speed was changed but @speed was not achieved
+ */
So passing a higher speed than what's supported by the Endpoint is fine but passing a higher speed than what's supported by the Downstream Port is not? Why the distinction? Maybe it would be more logical to just pick the maximum of what either supports and use that in lieu of a too-high speed?
drivers/pci/pcie/bwctrl.c static irqreturn_t pcie_bw_notification_irq(int irq, void *context) · line 202
Quoted 13 lines
drivers/pci/pcie/bwctrl.c +13
-0+int bwctrl_set_current_speed (struct pcie_device *srv,enum pci_bus_speed speed) +{ +struct bwctrl_service_data *data =get_service_data (srv); +struct pci_dev *port = srv->port; +u16 link_status; +int ret; + +if (WARN_ON_ONCE (!bwctrl_valid_pcie_speed (speed))) +return -EINVAL ; + + ret =bwctrl_select_speed (srv, &speed); +if (ret <0 ) +return ret;
How about checking here if the selected speed is equivalent to what's being used right now and bailing out if so? No need to retrain if we're already at the desired speed.
drivers/pci/pcie/bwctrl.c static int pcie_bandwidth_notification_probe(struct pcie_device *srv) · line 252
Quoted 12 lines
drivers/pci/pcie/bwctrl.c +8
-0@@ -91,16 +242,32 @@ static int pcie_bandwidth_notification_probe(struct pcie_device *srv)if (ret)return ret; + data =kzalloc (sizeof (*data),GFP_KERNEL ); +if (!data) { + ret = -ENOMEM ; + goto free_irq; + } +mutex_init (&data->set_speed_mutex); +set_service_data (srv, data); +
I think you should move that further up so that you allocate and populate the data struct before requesting the IRQ. Otherwise if BIOS has already enabled link bandwith notification for some reason, the IRQ handler might be invoked without the data struct being allocated.
include/linux/pci-bwctrl.h line 5
Quoted 8 lines
include/linux/pci-bwctrl.h new file +5
-0@@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* PCIe bandwidth controller +* +* Copyright (C) 2023 Intel Corporation.
Another trailing period I'd remove.
Thanks,
Lukas
Ilpo Järvinen
maintainerRe: [PATCH v3 08/10] PCI/bwctrl: Add "controller" part into PCIe bwctrl
Quoted 18 lines · Lukas Wunner
drivers/pci/pcie/bwctrl.c line 56
Quoted 12 lines · Ilpo Järvinen
---
a/drivers/pci/pcie/bwctrl.cdrivers/pci/pcie/bwctrl.c +10
-0+static u16 speed2lnkctl2 (enum pci_bus_speed speed) +{ +static const u16 speed_conv[] = { + [PCIE_SPEED_2_5GT ] =PCI_EXP_LNKCTL2_TLS_2_5GT , + [PCIE_SPEED_5_0GT ] =PCI_EXP_LNKCTL2_TLS_5_0GT , + [PCIE_SPEED_8_0GT ] =PCI_EXP_LNKCTL2_TLS_8_0GT , + [PCIE_SPEED_16_0GT ] =PCI_EXP_LNKCTL2_TLS_16_0GT , + [PCIE_SPEED_32_0GT ] =PCI_EXP_LNKCTL2_TLS_32_0GT , + [PCIE_SPEED_64_0GT ] =PCI_EXP_LNKCTL2_TLS_64_0GT , + };Looks like this could be a u8 array to save a little bit of memory.
Quoted 1 line
Also, this seems to duplicate pcie_link_speed[] defined in
probe.c.
It's not the same. pcie_link_speed[] is indexed by a different thing unless you also suggest I should do index minus a number? There are plenty of arithmetics possible when converting between the types but the existing converions functions don't seem to take advantage of those properties so I've been a bit hesitant to add such assumptions myself.
I suppose I used u16 because the reg is u16 but you're of course correct that the values don't take up more than u8.
Quoted 4 lines
Quoted 4 lines
drivers/pci/pcie/bwctrl.c +4
-0+static int bwctrl_select_speed (struct pcie_device *srv,enum pci_bus_speed *speed) +{ +struct pci_bus *bus = srv->port->subordinate; +u8 speeds, dev_speeds;
Quoted 8 lines
drivers/pci/pcie/bwctrl.c static irqreturn_t pcie_bw_notification_irq(int irq, void *context) · line 143
Quoted 6 lines
drivers/pci/pcie/bwctrl.c +6
-0+int i; + +if (*speed >PCIE_LNKCAP2_SLS2SPEED (bus->pcie_bus_speeds)) +return -EINVAL ; + + dev_speeds =READ_ONCE (bus->pcie_dev_speeds);Hm, why is the compiler barrier needed?
It's probably an overkill but there could be a checker which finds this read is not protected by anything while the value could get updated concurrectly (there's probably already such checker as I've seen patches to data races found with some tool). I suppose the alternative would be to mark the data race being harmless (because if endpoint removal clears pcie_dev_speeds, bwctrl will be pretty moot). I just chose to use READ_ONCE() that prevents rereading the same value later in this function making the function behave consistently regardless of what occurs parallel to it with the endpoints.
If the value selected cannot be set because of endpoint no longer being there, the other parts of the code will detect that.
So if I just add a comment to this line why there's the data race and keep it as is?
Quoted 6 lines
drivers/pci/pcie/bwctrl.c static irqreturn_t pcie_bw_notification_irq(int irq, void *context) · line 146
Quoted 3 lines
drivers/pci/pcie/bwctrl.c +3
-0+/* Only the lowest speed can be set when there are no devices */ +if (!dev_speeds) + dev_speeds =PCI_EXP_LNKCAP2_SLS_2_5GB ;Maybe move this to patch [06/10], i.e. set
dev->bus->pcie_dev_speedstoPCI_EXP_LNKCAP2_SLS_2_5GBon removal (instead of 0).
Okay, I'll set it to 2_5GB on init and removal.
Quoted 17 lines
Quoted 4 lines
drivers/pci/pcie/bwctrl.c +4
-0+ speeds = bus->pcie_bus_speeds & dev_speeds; + i =BIT (fls (speeds)); +while (i >=PCI_EXP_LNKCAP2_SLS_2_5GB ) { +enum pci_bus_speed candidate;drivers/pci/pcie/bwctrl.c static irqreturn_t pcie_bw_notification_irq(int irq, void *context) · line 169
Quoted 10 lines
drivers/pci/pcie/bwctrl.c +10
-0+ +if (speeds & i) { + candidate =PCIE_LNKCAP2_SLS2SPEED (i); +if (candidate <= *speed) { + *speed = candidate; +return 0 ; + } + } + i >>=1 ; + }Can't we just do something like
Quoted 5 lines
supported_speeds = bus->pcie_bus_speeds & dev_speeds; desired_speeds = GEN_MASK(pcie_link_speed[*speed], 1); *speed = BIT(fls(supported_speeds & desired_speeds));and thus avoid the loop altogether?
Yes, I can change to loopless version.
I'll try to create functions for the speed format conversions though rather than open coding them into the logic.
Quoted 4 lines
Quoted 4 lines
drivers/pci/pcie/bwctrl.c +0
-0@@ -91,16 +242,32 @@ static int pcie_bandwidth_notification_probe(struct pcie_device *srv)if (ret)return ret;
Quoted 13 lines
drivers/pci/pcie/bwctrl.c static int pcie_bandwidth_notification_probe(struct pcie_device *srv) · line 252
Quoted 8 lines
drivers/pci/pcie/bwctrl.c +8
-0+ data =kzalloc (sizeof (*data),GFP_KERNEL ); +if (!data) { + ret = -ENOMEM ; + goto free_irq; + } +mutex_init (&data->set_speed_mutex); +set_service_data (srv, data); +I think you should move that further up so that you allocate and populate the data struct before requesting the IRQ. Otherwise if BIOS has already enabled link bandwith notification for some reason, the IRQ handler might be invoked without the data struct being allocated.
Sure, I don't know why I missed that possibility.
Signature · 1 line
i.
Re: [PATCH v3 08/10] PCI/bwctrl: Add "controller" part into PCIe bwctrl
Quoted 16 lines · Ilpo Järvinen
Quoted 15 lines · Lukas Wunner
drivers/pci/pcie/bwctrl.c line 56
Quoted 11 lines · Ilpo Järvinen
---
a/drivers/pci/pcie/bwctrl.cdrivers/pci/pcie/bwctrl.c +10
-0+static u16 speed2lnkctl2 (enum pci_bus_speed speed) +{ +static const u16 speed_conv[] = { + [PCIE_SPEED_2_5GT ] =PCI_EXP_LNKCTL2_TLS_2_5GT , + [PCIE_SPEED_5_0GT ] =PCI_EXP_LNKCTL2_TLS_5_0GT , + [PCIE_SPEED_8_0GT ] =PCI_EXP_LNKCTL2_TLS_8_0GT , + [PCIE_SPEED_16_0GT ] =PCI_EXP_LNKCTL2_TLS_16_0GT , + [PCIE_SPEED_32_0GT ] =PCI_EXP_LNKCTL2_TLS_32_0GT , + [PCIE_SPEED_64_0GT ] =PCI_EXP_LNKCTL2_TLS_64_0GT , + };Looks like this could be a u8 array to save a little bit of memory.
Quoted 3 lines
Quoted 1 line
Also, this seems to duplicate pcie_link_speed[] defined in
probe.c.It's not the same. pcie_link_speed[] is indexed by a different thing
Ah, missed that. Those various conversion functions are confusing.
Quoted 7 lines
Quoted 3 lines
drivers/pci/pcie/bwctrl.c static irqreturn_t pcie_bw_notification_irq(int irq, void *context) · line 143
Quoted 1 line
drivers/pci/pcie/bwctrl.c +1
-0+ dev_speeds =READ_ONCE (bus->pcie_dev_speeds);Hm, why is the compiler barrier needed?
It's probably an overkill but there could be a checker which finds this read is not protected by anything while the value could get updated concurrectly
Why should it be updated? It's a static value cached on enumeration and never changed AFAICS.
Quoted 2 lines
If the value selected cannot be set because of endpoint no longer being there, the other parts of the code will detect that.
If the endpoint is hot-unplugged, the link is down, so retraining the link will fail.
If the device is replaced concurrently to retraining then you may try to retrain to a speed which is too fast or too slow for the new device. Maybe it's necessary to cope with that? Basically find the pci_dev on the bus with the device/function id and check if the pci_dev pointer still points to the same location. Another idea would be to hook up bwctrl with pciehp so that pciehp tells bwctrl the device is gone and any speed changes should be aborted. We've hooked up DPC with pciehp in a similar way.
Quoted 2 lines
So if I just add a comment to this line why there's the data race and keep it as is?
I'd just drop the READ_ONCE() here if there's not a good reason for it.
Thanks,
Lukas
Ilpo Järvinen
maintainerPATCH v3 9/10 thermal: Add PCIe cooling driver
In reply to Ilpo JärvinenAdd a thermal cooling driver to provide path to access PCIe bandwidth controller using the usual thermal interfaces.
A cooling device is instantiated for controllable PCIe ports from the bwctrl service driver.
The thermal side state 0 means no throttling, i.e., maximum supported PCIe speed.
--- MAINTAINERS | 1 + drivers/pci/pcie/bwctrl.c | 11 ++++ drivers/thermal/Kconfig | 10 +++ drivers/thermal/Makefile | 2 + drivers/thermal/pcie_cooling.c | 107 +++++++++++++++++++++++++++++++++ include/linux/pci-bwctrl.h | 16 +++++ 6 files changed, 147 insertions(+) create mode 100644 drivers/thermal/pcie_cooling.c
MAINTAINERS +1 -0
@@ -16574,6 +16574,7 @@ M: Ilpo Järvinen <[email protected]> L: [email protected] S: Supported F: drivers/pci/pcie/bwctrl.c +F: drivers/thermal/pcie_cooling.c F: include/linux/pci-bwctrl.h PCIE DRIVER FOR AMAZON ANNAPURNA LABS
drivers/pci/pcie/bwctrl.c +11 -0
@@ -34,9 +34,11 @@/** * struct bwctrl_service_data - PCIe Port Bandwidth Controller * @set_speed_mutex: serializes link speed changes +* @cdev: thermal cooling device associated with the port */ struct bwctrl_service_data {struct mutex set_speed_mutex; +struct thermal_cooling_device *cdev; };static bool bwctrl_valid_pcie_speed (enum pci_bus_speed speed)
@@ -253,8 +255,16 @@ static int pcie_bandwidth_notification_probe(struct pcie_device *srv)pcie_enable_link_bandwidth_notification (port);pci_info (port,"enabled with IRQ %d\n" , srv->irq); + data->cdev =pcie_cooling_device_register (port, srv); +if (IS_ERR (data->cdev)) { + ret =PTR_ERR (data->cdev); + goto disable_notifications; + }return 0 ; +disable_notifications: +pcie_disable_link_bandwidth_notification (srv->port); +kfree (data); free_irq:free_irq (srv->irq, srv);return ret;
@@ -264,6 +274,7 @@ static void pcie_bandwidth_notification_remove(struct pcie_device *srv) {struct bwctrl_service_data *data =get_service_data (srv); +pcie_cooling_device_unregister (data->cdev);pcie_disable_link_bandwidth_notification (srv->port);free_irq (srv->irq, srv);mutex_destroy (&data->set_speed_mutex);
drivers/thermal/Kconfig +10 -0
@@ -219,6 +219,16 @@ config DEVFREQ_THERMAL If you want this support, you should say Y here. +config PCIE_THERMAL + bool "PCIe cooling support" + depends on PCIEPORTBUS + select PCIE_BW + help + This implements PCIe cooling mechanism through bandwidth reduction + for PCIe devices. + + If you want this support, you should say Y here. + config THERMAL_EMULATION bool "Thermal emulation mode support" help
drivers/thermal/Makefile +2 -0
@@ -30,6 +30,8 @@ thermal_sys-$(CONFIG_CPU_IDLE_THERMAL) += cpuidle_cooling.o # devfreq cooling thermal_sys-$(CONFIG_DEVFREQ_THERMAL) += devfreq_cooling.o +thermal_sys-$(CONFIG_PCIE_THERMAL) += pcie_cooling.o + obj-$(CONFIG_K3_THERMAL) += k3_bandgap.o k3_j72xx_bandgap.o # platform thermal drivers obj-y += broadcom/
drivers/thermal/pcie_cooling.c new file +107 -0
107 lines not on this page · raw message
include/linux/pci-bwctrl.h +16 -0
@@ -11,7 +11,23 @@#include <linux/pci.h> struct pcie_device ; +struct thermal_cooling_device ;int bwctrl_set_current_speed (struct pcie_device *srv,enum pci_bus_speed speed); +#ifdef CONFIG_PCIE_THERMAL +struct thermal_cooling_device *pcie_cooling_device_register (struct pci_dev *port, +struct pcie_device *pdev); +void pcie_cooling_device_unregister (struct thermal_cooling_device *cdev); +#else +static inline struct thermal_cooling_device *pcie_cooling_device_register (struct pci_dev *port, +struct pcie_device *pdev) +{ +return NULL ; +} +static inline void pcie_cooling_device_unregister (struct thermal_cooling_device *cdev) +{ +} +#endif +#endif
Signature · 1 line
2.30.2
Re: [PATCH v3 09/10] thermal: Add PCIe cooling driver
drivers/pci/pcie/bwctrl.c static int pcie_bandwidth_notification_probe(struct pcie_device *srv) · line 263
Quoted 10 lines · Ilpo Järvinen
drivers/pci/pcie/bwctrl.c +5
-0@@ -253,8 +255,16 @@ static int pcie_bandwidth_notification_probe(struct pcie_device *srv)pcie_enable_link_bandwidth_notification (port);pci_info (port,"enabled with IRQ %d\n" , srv->irq); + data->cdev =pcie_cooling_device_register (port, srv); +if (IS_ERR (data->cdev)) { + ret =PTR_ERR (data->cdev); + goto disable_notifications; + }return 0 ;
Now wait a minute, if you can't register the cooling device, you still want to provide accurate link speeds to the user in sysfs, right? At least that's what you promise in Kconfig.
drivers/thermal/pcie_cooling.c line 5
Quoted 8 lines
drivers/thermal/pcie_cooling.c new file +5
-0@@ -0,0 +1,107 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* PCIe cooling device +* +* Copyright (C) 2023 Intel Corporation.
Another trailing period I'd remove.
I take it this patch (only) allows manual bandwidth throttling through sysfs, right? And emergency throttling is introduced separately on top of this?
Thanks,
Lukas
Ilpo Järvinen
maintainerRe: [PATCH v3 09/10] thermal: Add PCIe cooling driver
Quoted 5 lines · Lukas Wunner
Quoted 4 lines · Ilpo Järvinen
drivers/pci/pcie/bwctrl.c +0
-0@@ -253,8 +255,16 @@ static int pcie_bandwidth_notification_probe(struct pcie_device *srv)pcie_enable_link_bandwidth_notification (port);pci_info (port,"enabled with IRQ %d\n" , srv->irq);
Quoted 10 lines
drivers/pci/pcie/bwctrl.c static int pcie_bandwidth_notification_probe(struct pcie_device *srv) · line 263
Quoted 6 lines
drivers/pci/pcie/bwctrl.c +5
-0+ data->cdev =pcie_cooling_device_register (port, srv); +if (IS_ERR (data->cdev)) { + ret =PTR_ERR (data->cdev); + goto disable_notifications; + }return 0 ;Now wait a minute, if you can't register the cooling device, you still want to provide accurate link speeds to the user in sysfs, right? At least that's what you promise in
Kconfig.
When thermal side is not even configured, it returns NULL which is not ERR.
I guess I can change the behavior for the real ERR cases (I was bit on borderline what to do with those failures).
Quoted 11 lines
drivers/thermal/pcie_cooling.c line 5
Quoted 8 lines
drivers/thermal/pcie_cooling.c new file +5
-0@@ -0,0 +1,107 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* PCIe cooling device +* +* Copyright (C) 2023 Intel Corporation. Another trailing period I'd remove.
Quoted 3 lines
I take it this patch (only) allows manual bandwidth throttling through sysfs, right? And emergency throttling is introduced separately on top of this?
Only sysfs throttling is introduced by this series, there's no emergency throttling in the series. Also, many things have been simplified in this series because more complex things would be only justified with the emergency throttling and would just raise questions 'why is this and that being done' (e.g., the critical section was enlarged as per your request where if there would be emergency throttlink doesn't make sense to wait until the end of the link training before "emergency throttling" can attempt to lower the link speed).
Signature · 1 line
i.
Ilpo Järvinen
maintainerPATCH v3 10/10 selftests/pcie_bwctrl: Create selftests
In reply to Ilpo JärvinenCreate selftests for PCIe BW control through the PCIe cooling device sysfs interface.
First, the BW control selftest finds the PCIe port to test with. By default, the PCIe port with the highest bus speed is selected but another PCIe port can be provided with -d parameter.
The actual test steps the cur_state of the cooling device one-by-one from max_state to what the cur_state was initially. The speed change is confirmed by observing the current_link_speed for the corresponding PCIe port.
--- MAINTAINERS | 1 + tools/testing/selftests/Makefile | 1 + tools/testing/selftests/pcie_bwctrl/Makefile | 2 + .../pcie_bwctrl/set_pcie_cooling_state.sh | 122 ++++++++++++++++++ .../selftests/pcie_bwctrl/set_pcie_speed.sh | 67 ++++++++++ 5 files changed, 193 insertions(+) create mode 100644 tools/testing/selftests/pcie_bwctrl/Makefile create mode 100755 tools/testing/selftests/pcie_bwctrl/set_pcie_cooling_state.sh create mode 100755 tools/testing/selftests/pcie_bwctrl/set_pcie_speed.sh
MAINTAINERS +1 -0
@@ -16576,6 +16576,7 @@ S: Supported F: drivers/pci/pcie/bwctrl.c F: drivers/thermal/pcie_cooling.c F: include/linux/pci-bwctrl.h +F: tools/testing/selftests/pcie_bwctrl/ PCIE DRIVER FOR AMAZON ANNAPURNA LABS M: Jonathan Chocron <[email protected]>
tools/testing/selftests/Makefile +1 -0
@@ -59,6 +59,7 @@ TARGETS += net/mptcp TARGETS += net/openvswitch TARGETS += netfilter TARGETS += nsfs +TARGETS += pcie_bwctrl TARGETS += perf_events TARGETS += pidfd TARGETS += pid_namespace
tools/testing/selftests/pcie_bwctrl/Makefile new file +2 -0
@@ -0,0 +1,2 @@ +TEST_PROGS = set_pcie_cooling_state.sh +include ../lib.mk
tools/testing/selftests/pcie_bwctrl/set_pcie_cooling_state.sh new file +122 -0
122 lines not on this page · raw message
tools/testing/selftests/pcie_bwctrl/set_pcie_speed.sh new file +67 -0
67 lines not on this page · raw message
Signature · 1 line
2.30.2