Skip to contentSkip to conversation

PCI: dw-rockchip: Enable L0S capability

PATCH Superseded Shawn Lin 2 participants 3 messages Apr 11, 2025

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Shawn Lin

author
#0 lore raw

PATCH v2 1/1 PCI: dw-rockchip: Enable L0S capability

L0S capability isn't enabled on all SoCs by default, so enabling it in order to make ASPM L0S work on Rockchip platforms. We have been testing it for quite a long time and found the default FTS number provided by DWC core doesn't work stable and make LTSSM switch between L0S and Recovery, leading to long exit latency, even fail to link sometimes. So override it to the max 255 which seems work fine under test for both PHYs used by Rockchip platforms.

---

Changes in v2:
- Move n_fts to probe function
- rewrite the commit message

 drivers/pci/controller/dwc/pcie-dw-rockchip.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
drivers/pci/controller/dwc/pcie-dw-rockchip.c +14 -0
index 21dc99c..c397f3a 100644
@@ -185,6 +185,17 @@ static int rockchip_pcie_link_up(struct dw_pcie *pci)
 static int rockchip_pcie_start_link(struct dw_pcie *pci)
 {
 	struct rockchip_pcie *rockchip = to_rockchip_pcie(pci);
+	u32 cap, lnkcap;
+
+	/* Enable L0S capability for all SoCs */
+	cap = dw_pcie_find_capability(pci, PCI_CAP_ID_EXP);
+	if (cap) {
+		lnkcap = dw_pcie_readl_dbi(pci, cap + PCI_EXP_LNKCAP);
+		lnkcap |= PCI_EXP_LNKCAP_ASPM_L0S;
+		dw_pcie_dbi_ro_wr_en(pci);
+		dw_pcie_writel_dbi(pci, cap + PCI_EXP_LNKCAP, lnkcap);
+		dw_pcie_dbi_ro_wr_dis(pci);
+	}
 
 	/* Reset device */
 	gpiod_set_value_cansleep(rockchip->rst_gpio, 0);
@@ -598,6 +609,9 @@ static int rockchip_pcie_probe(struct platform_device *pdev)
 	rockchip->pci.dev = dev;
 	rockchip->pci.ops = &dw_pcie_ops;
 	rockchip->data = data;
+	/* Default fts number(210) is broken, override it to 255 */
+	rockchip->pci.n_fts[0] = 255; /* Gen1 */
+	rockchip->pci.n_fts[1] = 255; /* Gen2+ */
 
 	ret = rockchip_pcie_resource_get(pdev, rockchip);
 	if (ret)
Signature · 7 lines
2.7.4


_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip
#1 lore raw

Hello Shawn,

Quoted 27 lines · Shawn Lin

L0S capability isn't enabled on all SoCs by default, so enabling it in order to make ASPM L0S work on Rockchip platforms. We have been testing it for quite a long time and found the default FTS number provided by DWC core doesn't work stable and make LTSSM switch between L0S and Recovery, leading to long exit latency, even fail to link sometimes. So override it to the max 255 which seems work fine under test for both PHYs used by Rockchip platforms.

---

Changes in v2:
- Move n_fts to probe function
- rewrite the commit message

 drivers/pci/controller/dwc/pcie-dw-rockchip.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
drivers/pci/controller/dwc/pcie-dw-rockchip.c +1 -0
index 21dc99c..c397f3a 100644
@@ -185,6 +185,17 @@ static int rockchip_pcie_link_up(struct dw_pcie *pci)
 static int rockchip_pcie_start_link(struct dw_pcie *pci)
 {
 	struct rockchip_pcie *rockchip = to_rockchip_pcie(pci);
+	u32 cap, lnkcap;

drivers/pci/controller/dwc/pcie-dw-rockchip.c static int rockchip_pcie_link_up(struct dw_pcie *pci) · line 198

Quoted 10 lines
drivers/pci/controller/dwc/pcie-dw-rockchip.c +10 -0
+
+	/* Enable L0S capability for all SoCs */
+	cap = dw_pcie_find_capability(pci, PCI_CAP_ID_EXP);
+	if (cap) {
+		lnkcap = dw_pcie_readl_dbi(pci, cap + PCI_EXP_LNKCAP);
+		lnkcap |= PCI_EXP_LNKCAP_ASPM_L0S;
+		dw_pcie_dbi_ro_wr_en(pci);
+		dw_pcie_writel_dbi(pci, cap + PCI_EXP_LNKCAP, lnkcap);
+		dw_pcie_dbi_ro_wr_dis(pci);
+	}

I think it looks wrong to have this in _start_link().
Why not put this code in a new "_enable_l0s() function, and call it from:
rockchip_pcie_ep_init() and rockchip_pcie_host_init().

When looking at this, we probably should also move the rockchip_pcie_ep_hide_broken_ats_cap_rk3588() call from _pre_init() to _init(), because if there is a core reset, _init() is called again, but _pre_init() is not.

drivers/pci/controller/dwc/pcie-dw-rockchip.c static int rockchip_pcie_probe(struct platform_device *pdev) · line 611

Quoted 7 lines
drivers/pci/controller/dwc/pcie-dw-rockchip.c +0 -0
 	/* Reset device */
 	gpiod_set_value_cansleep(rockchip->rst_gpio, 0);
@@ -598,6 +609,9 @@ static int rockchip_pcie_probe(struct platform_device *pdev)
 	rockchip->pci.dev = dev;
 	rockchip->pci.ops = &dw_pcie_ops;
 	rockchip->data = data;

Perhaps add a newline here.

drivers/pci/controller/dwc/pcie-dw-rockchip.c static int rockchip_pcie_probe(struct platform_device *pdev) · line 612

Quoted 1 line
drivers/pci/controller/dwc/pcie-dw-rockchip.c +1 -0
+	/* Default fts number(210) is broken, override it to 255 */

Perhaps add a space between "number" and "(".
Perhaps write it as N_FTS instead of fts.
Perhaps use "value" instead of "number".

ie.

/* Default N_FTS value (210) is broken, ... */

Kind regards,
Niklas

author
#2 lore raw
Quoted 36 lines · Niklas Cassel

Hello Shawn,

Quoted 33 lines · Shawn Lin

L0S capability isn't enabled on all SoCs by default, so enabling it in order to make ASPM L0S work on Rockchip platforms. We have been testing it for quite a long time and found the default FTS number provided by DWC core doesn't work stable and make LTSSM switch between L0S and Recovery, leading to long exit latency, even fail to link sometimes. So override it to the max 255 which seems work fine under test for both PHYs used by Rockchip platforms.

---

Changes in v2:
- Move n_fts to probe function
- rewrite the commit message

  drivers/pci/controller/dwc/pcie-dw-rockchip.c | 14 ++++++++++++++
  1 file changed, 14 insertions(+)
drivers/pci/controller/dwc/pcie-dw-rockchip.c +7 -0
index 21dc99c..c397f3a 100644
@@ -185,6 +185,17 @@ static int rockchip_pcie_link_up(struct dw_pcie *pci)
  static int rockchip_pcie_start_link(struct dw_pcie *pci)
  {
  	struct rockchip_pcie *rockchip = to_rockchip_pcie(pci);
+	u32 cap, lnkcap;
+
+	/* Enable L0S capability for all SoCs */
+	cap = dw_pcie_find_capability(pci, PCI_CAP_ID_EXP);
+	if (cap) {
+		lnkcap = dw_pcie_readl_dbi(pci, cap + PCI_EXP_LNKCAP);
+		lnkcap |= PCI_EXP_LNKCAP_ASPM_L0S;
Quoted 9 lines

drivers/pci/controller/dwc/pcie-dw-rockchip.c static int rockchip_pcie_link_up(struct dw_pcie *pci) · line 198

Quoted 4 lines
drivers/pci/controller/dwc/pcie-dw-rockchip.c +4 -0
+		dw_pcie_dbi_ro_wr_en(pci);
+		dw_pcie_writel_dbi(pci, cap + PCI_EXP_LNKCAP, lnkcap);
+		dw_pcie_dbi_ro_wr_dis(pci);
+	}

I think it looks wrong to have this in _start_link().
Why not put this code in a new "_enable_l0s() function, and call it from:
rockchip_pcie_ep_init() and rockchip_pcie_host_init().

Will do.

Quoted 4 lines

When looking at this, we probably should also move the rockchip_pcie_ep_hide_broken_ats_cap_rk3588() call from _pre_init() to _init(), because if there is a core reset, _init() is called again, but _pre_init() is not.

That's a good point.

Quoted 18 lines

drivers/pci/controller/dwc/pcie-dw-rockchip.c static int rockchip_pcie_probe(struct platform_device *pdev) · line 611

Quoted 9 lines
drivers/pci/controller/dwc/pcie-dw-rockchip.c +0 -0
  	/* Reset device */
  	gpiod_set_value_cansleep(rockchip->rst_gpio, 0);
@@ -598,6 +609,9 @@ static int rockchip_pcie_probe(struct platform_device *pdev)
  	rockchip->pci.dev = dev;
  	rockchip->pci.ops = &dw_pcie_ops;
  	rockchip->data = data;

Perhaps add a newline here.

drivers/pci/controller/dwc/pcie-dw-rockchip.c static int rockchip_pcie_probe(struct platform_device *pdev) · line 612

Quoted 1 line
drivers/pci/controller/dwc/pcie-dw-rockchip.c +1 -0
+	/* Default fts number(210) is broken, override it to 255 */

Perhaps add a space between "number" and "(".
Perhaps write it as N_FTS instead of fts.
Perhaps use "value" instead of "number".

Quoted 4 lines

ie.

/* Default N_FTS value (210) is broken, ... */

Sure.

Quoted 10 lines

Kind regards,
Niklas

_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip

_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip