Skip to contentSkip to conversation

PCI/sg2042: Avoid L0s and L1 on Sophgo 2042 PCIe Root Ports

PATCH Applied Yao Zi 3 participants 8 messages Apr 5 – Apr 9

Subsystems (3)
lore
Share & tools
lore

Yao Zi

author
#0 lore raw

v3 cover PCI/sg2042: Avoid L0s and L1 on Sophgo 2042 PCIe Root Ports

After talking to Inochi privately, I'll take the patch instead.

This series defines quirk flags for Cadence PCIe host driver to allow disabling advertisement of ASPM L0s/L1 states by overriding LNKCAP register, and set them in SG2042 PCIe driver since SG2042's implementation is broken.

I've considered to re-write LNKCAP after cdns_pcie_host_setup() in SG2042 platform glue, like what has been done in the v1 of patch. However, cdns_pcie_host_setup() performs pci_host_probe(), which finally invokes set_pcie_port_type() on the root port. It reads ASPM-related LNKCAP, which might lead to dangling pci_dev.aspm_{l0s,l1}_support values. Early PCI device fixup won't work for similar reasons, since the fixup is performed in pci_setup_device() after calling set_pcie_port_type().

It's hard to fix up the LNKCAP earlier than invokation of cdns_pcie_host_setup() in SG2042's platform glue, either, since the function also performs resource allocation/mapping, and we have no access to the RC registers before it returns.

The safest solution which also depends on no PCI subsystem implementation detail is to have the LNKCAP fixed up right before informing the PCI subsystem of the device through pci_host_probe(), so here come the quirk flags and the ASPM advertisement disabling logic in the core Cadence PCIe driver.

This series is based on next-20260403, thanks for your time and review.

Changed from v2:
- Use flags to allow platform glues to inform the core driver that ASPM implementation is broken and should be disabled, instead of introducing platform-specific hooks to do so.
- Fix Co-developed-by tag in patch 2
- Link to v2: https://lore.kernel.org/linux-pci/[email protected]/

Changed from v1:
- Disable L0s/L1 capabilities through LNKCAP instead of LNKCTL
- Introduce platform-specific init/deinit hooks (new PATCH 1) to realiably overwrite PCIe RC properties
- Link to v1: https://lore.kernel.org/all/[email protected]/

Changed from the original patch:
- Use driver to mask the ASPM advertisement
- Separate from the following patch
https://lore.kernel.org/all/[email protected]

Yao Zi (2):
PCI: cadence: Add flags for disabling ASPM support advertisement
PCI: sg2042: Avoid L0s and L1 on Sophgo 2042 PCIe Root Ports

 .../controller/cadence/pcie-cadence-host.c    |  7 +++++++
 drivers/pci/controller/cadence/pcie-cadence.h | 19 +++++++++++++++++++
 drivers/pci/controller/cadence/pcie-sg2042.c  |  2 ++
 3 files changed, 28 insertions(+)
Signature · 1 line
2.53.0
author
#1 lore raw

PATCH v3 1/2 PCI: cadence: Add flags for disabling ASPM support advertisement

Add flags for disabling advertisement of ASPM L0s/L1 states by clearing corresponding bits in Link Capabilities Register through the local management bus, allowing ASPM to be disabled on platforms which don't support it.

---
 .../controller/cadence/pcie-cadence-host.c    |  7 +++++++
 drivers/pci/controller/cadence/pcie-cadence.h | 19 +++++++++++++++++++
 2 files changed, 26 insertions(+)
drivers/pci/controller/cadence/pcie-cadence-host.c +7 -0
index db3154c1eccb..0bc9e6e90e0e 100644
@@ -147,6 +147,13 @@ static int cdns_pcie_host_init_root_port(struct cdns_pcie_rc *rc)
 	cdns_pcie_rp_writeb(pcie, PCI_CLASS_PROG, 0);
 	cdns_pcie_rp_writew(pcie, PCI_CLASS_DEVICE, PCI_CLASS_BRIDGE_PCI);
 
+	value = cdns_pcie_rp_readl(pcie, CDNS_PCIE_RP_CAP_OFFSET + PCI_EXP_LNKCAP);
+	if (rc->quirk_broken_aspm_l0s)
+		value &= ~PCI_EXP_LNKCAP_ASPM_L0S;
+	if (rc->quirk_broken_aspm_l1)
+		value &= ~PCI_EXP_LNKCAP_ASPM_L1;
+	cdns_pcie_rp_writel(pcie, CDNS_PCIE_RP_CAP_OFFSET + PCI_EXP_LNKCAP, value);
+
 	return 0;
 }
 
drivers/pci/controller/cadence/pcie-cadence.h +19 -0
index 443033c607d7..32a5666204f5 100644
@@ -115,6 +115,8 @@ struct cdns_pcie {
  * @quirk_detect_quiet_flag: LTSSM Detect Quiet min delay set as quirk
  * @ecam_supported: Whether the ECAM is supported
  * @no_inbound_map: Whether inbound mapping is supported
+ * @quirk_broken_aspm_l0s: Disable ASPM L0s support as quirk.
+ * @quirk_broken_aspm_l1: Disable ASPM L1 support as quirk.
  */
 struct cdns_pcie_rc {
 	struct cdns_pcie	pcie;
@@ -127,6 +129,8 @@ struct cdns_pcie_rc {
 	unsigned int		quirk_detect_quiet_flag:1;
 	unsigned int            ecam_supported:1;
 	unsigned int            no_inbound_map:1;
+	unsigned int            quirk_broken_aspm_l0s:1;
+	unsigned int            quirk_broken_aspm_l1:1;
 };
 
 /**
@@ -344,6 +348,21 @@ static inline u16 cdns_pcie_rp_readw(struct cdns_pcie *pcie, u32 reg)
 	return cdns_pcie_read_sz(addr, 0x2);
 }
 
+static inline void cdns_pcie_rp_writel(struct cdns_pcie *pcie,
+				       u32 reg, u32 value)
+{
+	void __iomem *addr = pcie->reg_base + CDNS_PCIE_RP_BASE + reg;
+
+	cdns_pcie_write_sz(addr, 0x4, value);
+}
+
+static inline u32 cdns_pcie_rp_readl(struct cdns_pcie *pcie, u32 reg)
+{
+	void __iomem *addr = pcie->reg_base + CDNS_PCIE_RP_BASE + reg;
+
+	return cdns_pcie_read_sz(addr, 0x4);
+}
+
 static inline void cdns_pcie_hpa_rp_writeb(struct cdns_pcie *pcie,
 					   u32 reg, u8 value)
 {
Signature · 1 line
2.53.0
Reviewed-by Tested-by on v3 1/2
#2 lore raw

Re: [PATCH v3 1/2] PCI: cadence: Add flags for disabling ASPM support advertisement

Quoted 64 lines · Yao Zi

Add flags for disabling advertisement of ASPM L0s/L1 states by clearing corresponding bits in Link Capabilities Register through the local management bus, allowing ASPM to be disabled on platforms which don't support it.

---
  .../controller/cadence/pcie-cadence-host.c    |  7 +++++++
  drivers/pci/controller/cadence/pcie-cadence.h | 19 +++++++++++++++++++
  2 files changed, 26 insertions(+)
drivers/pci/controller/cadence/pcie-cadence-host.c +7 -0
index db3154c1eccb..0bc9e6e90e0e 100644
@@ -147,6 +147,13 @@ static int cdns_pcie_host_init_root_port(struct cdns_pcie_rc *rc)
  	cdns_pcie_rp_writeb(pcie, PCI_CLASS_PROG, 0);
  	cdns_pcie_rp_writew(pcie, PCI_CLASS_DEVICE, PCI_CLASS_BRIDGE_PCI);
 
+	value = cdns_pcie_rp_readl(pcie, CDNS_PCIE_RP_CAP_OFFSET + PCI_EXP_LNKCAP);
+	if (rc->quirk_broken_aspm_l0s)
+		value &= ~PCI_EXP_LNKCAP_ASPM_L0S;
+	if (rc->quirk_broken_aspm_l1)
+		value &= ~PCI_EXP_LNKCAP_ASPM_L1;
+	cdns_pcie_rp_writel(pcie, CDNS_PCIE_RP_CAP_OFFSET + PCI_EXP_LNKCAP, value);
+
  	return 0;
  }
 
drivers/pci/controller/cadence/pcie-cadence.h +12 -0
index 443033c607d7..32a5666204f5 100644
@@ -115,6 +115,8 @@ struct cdns_pcie {
   * @quirk_detect_quiet_flag: LTSSM Detect Quiet min delay set as quirk
   * @ecam_supported: Whether the ECAM is supported
   * @no_inbound_map: Whether inbound mapping is supported
+ * @quirk_broken_aspm_l0s: Disable ASPM L0s support as quirk.
+ * @quirk_broken_aspm_l1: Disable ASPM L1 support as quirk.
   */
  struct cdns_pcie_rc {
  	struct cdns_pcie	pcie;
@@ -127,6 +129,8 @@ struct cdns_pcie_rc {
  	unsigned int		quirk_detect_quiet_flag:1;
  	unsigned int            ecam_supported:1;
  	unsigned int            no_inbound_map:1;
+	unsigned int            quirk_broken_aspm_l0s:1;
+	unsigned int            quirk_broken_aspm_l1:1;
  };
 
  /**
@@ -344,6 +348,21 @@ static inline u16 cdns_pcie_rp_readw(struct cdns_pcie *pcie, u32 reg)
  	return cdns_pcie_read_sz(addr, 0x2);
  }
 
+static inline void cdns_pcie_rp_writel(struct cdns_pcie *pcie,
+				       u32 reg, u32 value)
+{
+	void __iomem *addr = pcie->reg_base + CDNS_PCIE_RP_BASE + reg;
+
+	cdns_pcie_write_sz(addr, 0x4, value);
+}
+

drivers/pci/controller/cadence/pcie-cadence.h static inline u16 cdns_pcie_rp_readw(struct cdns_pcie *pcie, u32 reg) · line 368

Quoted 10 lines
drivers/pci/controller/cadence/pcie-cadence.h +7 -0
+static inline u32 cdns_pcie_rp_readl(struct cdns_pcie *pcie, u32 reg)
+{
+	void __iomem *addr = pcie->reg_base + CDNS_PCIE_RP_BASE + reg;
+
+	return cdns_pcie_read_sz(addr, 0x4);
+}
+
  static inline void cdns_pcie_hpa_rp_writeb(struct cdns_pcie *pcie,
  					   u32 reg, u8 value)
  {

LGTM.

Thanks,

Chen

author
#3 lore raw

PATCH v3 2/2 PCI: sg2042: Avoid L0s and L1 on Sophgo 2042 PCIe Root Ports

In reply to Yao Zi

Since commit f3ac2ff14834 ("PCI/ASPM: Enable all ClockPM and ASPM states for devicetree platforms") force enable ASPM on all device tree platform, the SG2042 root port breaks as it advertises L0s and L1 capabilities without supporting it.

Set ASPM quirks to disable advertisement of L0s and L1 support, so it doesn't try to enable those states.

Fixes 4e27aca4881a ("riscv: sophgo: dts: add PCIe controllers for SG2042")
---
 drivers/pci/controller/cadence/pcie-sg2042.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/pci/controller/cadence/pcie-sg2042.c +2 -0
index 0c50c74d03ee..4a2af4d0713e 100644
@@ -48,6 +48,8 @@ static int sg2042_pcie_probe(struct platform_device *pdev)
 	bridge->child_ops = &sg2042_pcie_child_ops;
 
 	rc = pci_host_bridge_priv(bridge);
+	rc->quirk_broken_aspm_l0s = 1;
+	rc->quirk_broken_aspm_l1 = 1;
 	pcie = &rc->pcie;
 	pcie->dev = dev;
 
Signature · 1 line
2.53.0
Reviewed-by Tested-by on v3 2/2
#4 lore raw

Re: [PATCH v3 2/2] PCI: sg2042: Avoid L0s and L1 on Sophgo 2042 PCIe Root Ports

Quoted 22 lines · Yao Zi

Since commit f3ac2ff14834 ("PCI/ASPM: Enable all ClockPM and ASPM states for devicetree platforms") force enable ASPM on all device tree platform, the SG2042 root port breaks as it advertises L0s and L1 capabilities without supporting it.

Set ASPM quirks to disable advertisement of L0s and L1 support, so it doesn't try to enable those states.

Fixes 4e27aca4881a ("riscv: sophgo: dts: add PCIe controllers for SG2042")
---
  drivers/pci/controller/cadence/pcie-sg2042.c | 2 ++
  1 file changed, 2 insertions(+)
drivers/pci/controller/cadence/pcie-sg2042.c +0 -0
index 0c50c74d03ee..4a2af4d0713e 100644

drivers/pci/controller/cadence/pcie-sg2042.c static int sg2042_pcie_probe(struct platform_device *pdev) · line 55

Quoted 8 lines
drivers/pci/controller/cadence/pcie-sg2042.c +2 -0
@@ -48,6 +48,8 @@ static int sg2042_pcie_probe(struct platform_device *pdev)
  	bridge->child_ops = &sg2042_pcie_child_ops;
 
  	rc = pci_host_bridge_priv(bridge);
+	rc->quirk_broken_aspm_l0s = 1;
+	rc->quirk_broken_aspm_l1 = 1;
  	pcie = &rc->pcie;
  	pcie->dev = dev;
 

LGTM.

Thanks,

Chen

#5 lore raw
In reply to Yao Zi
Quoted 47 lines · Yao Zi

After talking to Inochi privately, I'll take the patch instead.

This series defines quirk flags for Cadence PCIe host driver to allow disabling advertisement of ASPM L0s/L1 states by overriding LNKCAP register, and set them in SG2042 PCIe driver since SG2042's implementation is broken.

I've considered to re-write LNKCAP after cdns_pcie_host_setup() in SG2042 platform glue, like what has been done in the v1 of patch. However, cdns_pcie_host_setup() performs pci_host_probe(), which finally invokes set_pcie_port_type() on the root port. It reads ASPM-related LNKCAP, which might lead to dangling pci_dev.aspm_{l0s,l1}_support values. Early PCI device fixup won't work for similar reasons, since the fixup is performed in pci_setup_device() after calling set_pcie_port_type().

It's hard to fix up the LNKCAP earlier than invokation of cdns_pcie_host_setup() in SG2042's platform glue, either, since the function also performs resource allocation/mapping, and we have no access to the RC registers before it returns.

The safest solution which also depends on no PCI subsystem implementation detail is to have the LNKCAP fixed up right before informing the PCI subsystem of the device through pci_host_probe(), so here come the quirk flags and the ASPM advertisement disabling logic in the core Cadence PCIe driver.

This series is based on next-20260403, thanks for your time and review.

Changed from v2:
- Use flags to allow platform glues to inform the core driver that ASPM implementation is broken and should be disabled, instead of introducing platform-specific hooks to do so.
- Fix Co-developed-by tag in patch 2
- Link to v2: https://lore.kernel.org/linux-pci/[email protected]/

Changed from v1:
- Disable L0s/L1 capabilities through LNKCAP instead of LNKCTL
- Introduce platform-specific init/deinit hooks (new PATCH 1) to realiably overwrite PCIe RC properties
- Link to v1: https://lore.kernel.org/all/[email protected]/

Changed from the original patch:
- Use driver to mask the ASPM advertisement
- Separate from the following patch
https://lore.kernel.org/all/[email protected]

Quoted 8 lines

Yao Zi (2):
PCI: cadence: Add flags for disabling ASPM support advertisement
PCI: sg2042: Avoid L0s and L1 on Sophgo 2042 PCIe Root Ports

  .../controller/cadence/pcie-cadence-host.c    |  7 +++++++
  drivers/pci/controller/cadence/pcie-cadence.h | 19 +++++++++++++++++++
  drivers/pci/controller/cadence/pcie-sg2042.c  |  2 ++
  3 files changed, 28 insertions(+)

BTW, I guess you might forget to post this patchset to [email protected]. Please remember this later.

Thanks,

Chen

author
#6 lore raw
Quoted 53 lines · Chen Wang
Quoted 51 lines · Yao Zi

After talking to Inochi privately, I'll take the patch instead.

This series defines quirk flags for Cadence PCIe host driver to allow disabling advertisement of ASPM L0s/L1 states by overriding LNKCAP register, and set them in SG2042 PCIe driver since SG2042's implementation is broken.

I've considered to re-write LNKCAP after cdns_pcie_host_setup() in SG2042 platform glue, like what has been done in the v1 of patch. However, cdns_pcie_host_setup() performs pci_host_probe(), which finally invokes set_pcie_port_type() on the root port. It reads ASPM-related LNKCAP, which might lead to dangling pci_dev.aspm_{l0s,l1}_support values. Early PCI device fixup won't work for similar reasons, since the fixup is performed in pci_setup_device() after calling set_pcie_port_type().

It's hard to fix up the LNKCAP earlier than invokation of cdns_pcie_host_setup() in SG2042's platform glue, either, since the function also performs resource allocation/mapping, and we have no access to the RC registers before it returns.

The safest solution which also depends on no PCI subsystem implementation detail is to have the LNKCAP fixed up right before informing the PCI subsystem of the device through pci_host_probe(), so here come the quirk flags and the ASPM advertisement disabling logic in the core Cadence PCIe driver.

This series is based on next-20260403, thanks for your time and review.

Changed from v2:
- Use flags to allow platform glues to inform the core driver that ASPM implementation is broken and should be disabled, instead of introducing platform-specific hooks to do so.
- Fix Co-developed-by tag in patch 2
- Link to v2: https://lore.kernel.org/linux-pci/[email protected]/

Changed from v1:
- Disable L0s/L1 capabilities through LNKCAP instead of LNKCTL
- Introduce platform-specific init/deinit hooks (new PATCH 1) to realiably overwrite PCIe RC properties
- Link to v1: https://lore.kernel.org/all/[email protected]/

Changed from the original patch:
- Use driver to mask the ASPM advertisement
- Separate from the following patch
https://lore.kernel.org/all/[email protected]

Yao Zi (2):
PCI: cadence: Add flags for disabling ASPM support advertisement
PCI: sg2042: Avoid L0s and L1 on Sophgo 2042 PCIe Root Ports

Quoted 7 lines
Quoted 4 lines
  .../controller/cadence/pcie-cadence-host.c    |  7 +++++++
  drivers/pci/controller/cadence/pcie-cadence.h | 19 +++++++++++++++++++
  drivers/pci/controller/cadence/pcie-sg2042.c  |  2 ++
  3 files changed, 28 insertions(+)

BTW, I guess you might forget to post this patchset to [email protected]. Please remember this later.

Oops, yes. I blindly followed the output of get_maintainers.pl, which doesn't mention Sophgo's mailing list when run against pcie-sg2042.c.

Maybe we should add pcie-sg2042.c to the "SOPHGO DEVICETREES and DRIVERS" entry in MAINTAINERS file, or add a keyword for the entry?

Quoted 4 lines

Thanks,

Chen

Regards,
Yao Zi

#7 lore raw
In reply to Yao Zi
Quoted 8 lines · Yao Zi

After talking to Inochi privately, I'll take the patch instead.

This series defines quirk flags for Cadence PCIe host driver to allow disabling advertisement of ASPM L0s/L1 states by overriding LNKCAP register, and set them in SG2042 PCIe driver since SG2042's implementation is broken.

[...]

Applied, thanks!

[1/2] PCI: cadence: Add flags for disabling ASPM support advertisement

      commit: 7336e9edaf19d6710b93cc1232270361a20891be
[2/2] PCI: sg2042: Avoid L0s and L1 on Sophgo 2042 PCIe Root Ports
      commit: a4c1e32555ba488e163b88765de739c872da340f

Best regards,

Signature · 1 line
Manivannan Sadhasivam <[email protected]>