Skip to contentSkip to conversation

r8169: enable RTL8125 ASPM L1.2

PATCH In review Chunhao Lin 2 participants 17 messages Jan 24, 2022 – Jan 27, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 r8169: enable RTL8125 ASPM L1.2

This patch will enable RTL8125 ASPM L1.2 on the platforms that have tested RTL8125 with ASPM L1.2 enabled.
Register mac ocp 0xc0b2 will help to identify if RTL8125 has been tested on L1.2 enabled platform. If it is, this register will be set to 0xf. If not, this register will be default value 0.

---
 drivers/net/ethernet/realtek/r8169_main.c | 99 ++++++++++++++++++-----
 1 file changed, 79 insertions(+), 20 deletions(-)
drivers/net/ethernet/realtek/r8169_main.c +79 -20
index 19e2621e0645..b1e013969d4c 100644
@@ -2238,21 +2238,6 @@ static void rtl_wol_enable_rx(struct rtl8169_private *tp)
 			AcceptBroadcast | AcceptMulticast | AcceptMyPhys);
 }
 
-static void rtl_prepare_power_down(struct rtl8169_private *tp)
-{
-	if (tp->dash_type != RTL_DASH_NONE)
-		return;
-
-	if (tp->mac_version == RTL_GIGA_MAC_VER_32 ||
-	    tp->mac_version == RTL_GIGA_MAC_VER_33)
-		rtl_ephy_write(tp, 0x19, 0xff64);
-
-	if (device_may_wakeup(tp_to_dev(tp))) {
-		phy_speed_down(tp->phydev, false);
-		rtl_wol_enable_rx(tp);
-	}
-}
-
 static void rtl_init_rxcfg(struct rtl8169_private *tp)
 {
 	switch (tp->mac_version) {
@@ -2650,6 +2635,34 @@ static void rtl_pcie_state_l2l3_disable(struct rtl8169_private *tp)
 	RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Rdy_to_L23);
 }
 
+static void rtl_disable_exit_l1(struct rtl8169_private *tp)
+{
+	/* Bits control which events trigger ASPM L1 exit:
+	 * Bit 12: rxdv
+	 * Bit 11: ltr_msg
+	 * Bit 10: txdma_poll
+	 * Bit  9: xadm
+	 * Bit  8: pktavi
+	 * Bit  7: txpla
+	 */
+	switch (tp->mac_version) {
+	case RTL_GIGA_MAC_VER_34 ... RTL_GIGA_MAC_VER_36:
+		rtl_eri_clear_bits(tp, 0xd4, 0x1f00);
+		break;
+	case RTL_GIGA_MAC_VER_37 ... RTL_GIGA_MAC_VER_38:
+		rtl_eri_clear_bits(tp, 0xd4, 0x0c00);
+		break;
+	case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_53:
+		rtl_eri_clear_bits(tp, 0xd4, 0x1f80);
+		break;
+	case RTL_GIGA_MAC_VER_60 ... RTL_GIGA_MAC_VER_63:
+		r8168_mac_ocp_modify(tp, 0xc0ac, 0x1f80, 0);
+		break;
+	default:
+		break;
+	}
+}
+
 static void rtl_enable_exit_l1(struct rtl8169_private *tp)
 {
 	/* Bits control which events trigger ASPM L1 exit:
@@ -2692,6 +2705,33 @@ static void rtl_hw_aspm_clkreq_enable(struct rtl8169_private *tp, bool enable)
 	udelay(10);
 }
 
+static void rtl_hw_aspm_l12_enable(struct rtl8169_private *tp, bool enable)
+{
+	/* Don't enable L1.2 in the chip if OS can't control ASPM */
+	if (enable && tp->aspm_manageable) {
+		r8168_mac_ocp_modify(tp, 0xe094, 0xff00, 0);
+		r8168_mac_ocp_modify(tp, 0xe092, 0x00ff, BIT(2));
+	} else {
+		r8168_mac_ocp_modify(tp, 0xe092, 0x00ff, 0);
+	}
+}
+
+static void rtl_prepare_power_down(struct rtl8169_private *tp)
+{
+	if (tp->dash_type != RTL_DASH_NONE)
+		return;
+
+	if (tp->mac_version == RTL_GIGA_MAC_VER_32 ||
+	    tp->mac_version == RTL_GIGA_MAC_VER_33)
+		rtl_ephy_write(tp, 0x19, 0xff64);
+
+	if (device_may_wakeup(tp_to_dev(tp))) {
+		rtl_disable_exit_l1(tp);
+		phy_speed_down(tp->phydev, false);
+		rtl_wol_enable_rx(tp);
+	}
+}
+
 static void rtl_set_fifo_size(struct rtl8169_private *tp, u16 rx_stat,
 			      u16 tx_stat, u16 rx_dyn, u16 tx_dyn)
 {
@@ -3675,6 +3715,7 @@ static void rtl_hw_start_8125b(struct rtl8169_private *tp)
 	rtl_ephy_init(tp, e_info_8125b);
 	rtl_hw_start_8125_common(tp);
 
+	rtl_hw_aspm_l12_enable(tp, true);
 	rtl_hw_aspm_clkreq_enable(tp, true);
 }
 
@@ -5255,6 +5296,20 @@ static void rtl_init_mac_address(struct rtl8169_private *tp)
 	rtl_rar_set(tp, mac_addr);
 }
 
+/* mac ocp 0xc0b2 will help to identify if RTL8125 has been tested
+ * on L1.2 enabled platform. If it is, this register will be set to 0xf.
+ * If not, this register will be default value 0.
+ */
+static bool rtl_platform_l12_enabled(struct rtl8169_private *tp)
+{
+	switch (tp->mac_version) {
+	case RTL_GIGA_MAC_VER_60 ... RTL_GIGA_MAC_VER_63:
+		return (r8168_mac_ocp_read(tp, 0xc0b2) & 0xf) ? true : false;
+	default:
+		return false;
+	}
+}
+
 static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 {
 	struct rtl8169_private *tp;
@@ -5333,11 +5388,15 @@ static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 	 * Chips from RTL8168h partially have issues with L1.2, but seem
 	 * to work fine with L1 and L1.1.
 	 */
-	if (tp->mac_version >= RTL_GIGA_MAC_VER_45)
-		rc = pci_disable_link_state(pdev, PCIE_LINK_STATE_L1_2);
-	else
-		rc = pci_disable_link_state(pdev, PCIE_LINK_STATE_L1);
-	tp->aspm_manageable = !rc;
+	if (!rtl_platform_l12_enabled(tp)) {
+		if (tp->mac_version >= RTL_GIGA_MAC_VER_45)
+			rc = pci_disable_link_state(pdev, PCIE_LINK_STATE_L1_2);
+		else
+			rc = pci_disable_link_state(pdev, PCIE_LINK_STATE_L1);
+		tp->aspm_manageable = !rc;
+	} else {
+		tp->aspm_manageable = pcie_aspm_enabled(pdev);
+	}
 
 	tp->dash_type = rtl_check_dash(tp);
 
Signature · 1 line
2.25.1
maintainer
#1 lore raw

Hi Hau,

Quoted 6 lines · Chunhao Lin

This patch will enable RTL8125 ASPM L1.2 on the platforms that have tested RTL8125 with ASPM L1.2 enabled.
Register mac ocp 0xc0b2 will help to identify if RTL8125 has been tested on L1.2 enabled platform. If it is, this register will be set to 0xf. If not, this register will be default value 0.

Who and what defines which value this register has? The BIOS? ACPI? Mainboard vendors test and can control the flagging? How about add-on cards and systems with other boot loaders, e.g. SBC's with RTL8125 like Odroid H2+?

What is actually the critical component that makes L1.2 work or not with RTL8125 on a particular system? The chipset? Or electrical characteristics?

The difference in power consumption between L1.1 and L1.2 is a few mW ([0]). So I wonder whether it's worth it to add this flagging mechanism. Or does it also impact reaching certain package power saving states?

[0] https://pcisig.com/making-most-pcie%C2%AE-low-power-features

Quoted 32 lines
---
 drivers/net/ethernet/realtek/r8169_main.c | 99 ++++++++++++++++++-----
 1 file changed, 79 insertions(+), 20 deletions(-)
drivers/net/ethernet/realtek/r8169_main.c +0 -15
index 19e2621e0645..b1e013969d4c 100644
@@ -2238,21 +2238,6 @@ static void rtl_wol_enable_rx(struct rtl8169_private *tp)
 			AcceptBroadcast | AcceptMulticast | AcceptMyPhys);
 }
 
-static void rtl_prepare_power_down(struct rtl8169_private *tp)
-{
-	if (tp->dash_type != RTL_DASH_NONE)
-		return;
-
-	if (tp->mac_version == RTL_GIGA_MAC_VER_32 ||
-	    tp->mac_version == RTL_GIGA_MAC_VER_33)
-		rtl_ephy_write(tp, 0x19, 0xff64);
-
-	if (device_may_wakeup(tp_to_dev(tp))) {
-		phy_speed_down(tp->phydev, false);
-		rtl_wol_enable_rx(tp);
-	}
-}
-
 static void rtl_init_rxcfg(struct rtl8169_private *tp)
 {
 	switch (tp->mac_version) {

drivers/net/ethernet/realtek/r8169_main.c static void rtl_pcie_state_l2l3_disable(struct rtl8169_private *tp) · line 2639

Quoted 5 lines
drivers/net/ethernet/realtek/r8169_main.c +2 -0
@@ -2650,6 +2635,34 @@ static void rtl_pcie_state_l2l3_disable(struct rtl8169_private *tp)
 	RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Rdy_to_L23);
 }
 
+static void rtl_disable_exit_l1(struct rtl8169_private *tp)
+{

Why is this function needed? The chip should be quiet anyway.
IOW: What could be the impact of not having this function currently? If it fixes something then it should be a separate patch.

Quoted 30 lines
drivers/net/ethernet/realtek/r8169_main.c +26 -0
+	/* Bits control which events trigger ASPM L1 exit:
+	 * Bit 12: rxdv
+	 * Bit 11: ltr_msg
+	 * Bit 10: txdma_poll
+	 * Bit  9: xadm
+	 * Bit  8: pktavi
+	 * Bit  7: txpla
+	 */
+	switch (tp->mac_version) {
+	case RTL_GIGA_MAC_VER_34 ... RTL_GIGA_MAC_VER_36:
+		rtl_eri_clear_bits(tp, 0xd4, 0x1f00);
+		break;
+	case RTL_GIGA_MAC_VER_37 ... RTL_GIGA_MAC_VER_38:
+		rtl_eri_clear_bits(tp, 0xd4, 0x0c00);
+		break;
+	case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_53:
+		rtl_eri_clear_bits(tp, 0xd4, 0x1f80);
+		break;
+	case RTL_GIGA_MAC_VER_60 ... RTL_GIGA_MAC_VER_63:
+		r8168_mac_ocp_modify(tp, 0xc0ac, 0x1f80, 0);
+		break;
+	default:
+		break;
+	}
+}
+
 static void rtl_enable_exit_l1(struct rtl8169_private *tp)
 {
 	/* Bits control which events trigger ASPM L1 exit:

drivers/net/ethernet/realtek/r8169_main.c static void rtl_hw_aspm_clkreq_enable(struct rtl8169_private *tp, bool enable) · line 2709

Quoted 5 lines
drivers/net/ethernet/realtek/r8169_main.c +2 -0
@@ -2692,6 +2705,33 @@ static void rtl_hw_aspm_clkreq_enable(struct rtl8169_private *tp, bool enable)
 	udelay(10);
 }
 
+static void rtl_hw_aspm_l12_enable(struct rtl8169_private *tp, bool enable)
+{

I assume this code works on RTL8125 only. Then this should be reflected in the function naming, like we do it for other version-specific functions.

Quoted 37 lines
drivers/net/ethernet/realtek/r8169_main.c +26 -0
+	/* Don't enable L1.2 in the chip if OS can't control ASPM */
+	if (enable && tp->aspm_manageable) {
+		r8168_mac_ocp_modify(tp, 0xe094, 0xff00, 0);
+		r8168_mac_ocp_modify(tp, 0xe092, 0x00ff, BIT(2));
+	} else {
+		r8168_mac_ocp_modify(tp, 0xe092, 0x00ff, 0);
+	}
+}
+
+static void rtl_prepare_power_down(struct rtl8169_private *tp)
+{
+	if (tp->dash_type != RTL_DASH_NONE)
+		return;
+
+	if (tp->mac_version == RTL_GIGA_MAC_VER_32 ||
+	    tp->mac_version == RTL_GIGA_MAC_VER_33)
+		rtl_ephy_write(tp, 0x19, 0xff64);
+
+	if (device_may_wakeup(tp_to_dev(tp))) {
+		rtl_disable_exit_l1(tp);
+		phy_speed_down(tp->phydev, false);
+		rtl_wol_enable_rx(tp);
+	}
+}
+
 static void rtl_set_fifo_size(struct rtl8169_private *tp, u16 rx_stat,
 			      u16 tx_stat, u16 rx_dyn, u16 tx_dyn)
 {
@@ -3675,6 +3715,7 @@ static void rtl_hw_start_8125b(struct rtl8169_private *tp)
 	rtl_ephy_init(tp, e_info_8125b);
 	rtl_hw_start_8125_common(tp);
 
+	rtl_hw_aspm_l12_enable(tp, true);
 	rtl_hw_aspm_clkreq_enable(tp, true);
 }
 

drivers/net/ethernet/realtek/r8169_main.c static void rtl_init_mac_address(struct rtl8169_private *tp) · line 5304

Quoted 9 lines
drivers/net/ethernet/realtek/r8169_main.c +6 -0
@@ -5255,6 +5296,20 @@ static void rtl_init_mac_address(struct rtl8169_private *tp)
 	rtl_rar_set(tp, mac_addr);
 }
 
+/* mac ocp 0xc0b2 will help to identify if RTL8125 has been tested
+ * on L1.2 enabled platform. If it is, this register will be set to 0xf.
+ * If not, this register will be default value 0.
+ */
+static bool rtl_platform_l12_enabled(struct rtl8169_private *tp)
+{

The function name is misleading. It could be read as checking whether the platform supports L1.2.

Quoted 20 lines
drivers/net/ethernet/realtek/r8169_main.c +8 -5
+	switch (tp->mac_version) {
+	case RTL_GIGA_MAC_VER_60 ... RTL_GIGA_MAC_VER_63:
+		return (r8168_mac_ocp_read(tp, 0xc0b2) & 0xf) ? true : false;
+	default:
+		return false;
+	}
+}
+
 static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 {
 	struct rtl8169_private *tp;
@@ -5333,11 +5388,15 @@ static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 	 * Chips from RTL8168h partially have issues with L1.2, but seem
 	 * to work fine with L1 and L1.1.
 	 */
-	if (tp->mac_version >= RTL_GIGA_MAC_VER_45)
-		rc = pci_disable_link_state(pdev, PCIE_LINK_STATE_L1_2);
-	else
-		rc = pci_disable_link_state(pdev, PCIE_LINK_STATE_L1);
-	tp->aspm_manageable = !rc;

drivers/net/ethernet/realtek/r8169_main.c static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) · line 5400

Quoted 10 lines
drivers/net/ethernet/realtek/r8169_main.c +9 -0
+	if (!rtl_platform_l12_enabled(tp)) {
+		if (tp->mac_version >= RTL_GIGA_MAC_VER_45)
+			rc = pci_disable_link_state(pdev, PCIE_LINK_STATE_L1_2);
+		else
+			rc = pci_disable_link_state(pdev, PCIE_LINK_STATE_L1);
+		tp->aspm_manageable = !rc;
+	} else {
+		tp->aspm_manageable = pcie_aspm_enabled(pdev);
+	}
 

Better readable may be the following:

if (rtl_platform_l12_enabled(tp)) {
	tp->aspm_manageable = pcie_aspm_enabled(pdev);
} else if (tp->mac_version >= RTL_GIGA_MAC_VER_45) {
	rc = pci_disable_link_state(pdev, PCIE_LINK_STATE_L1_2);
	tp->aspm_manageable = !rc;
} else {
	rc = pci_disable_link_state(pdev, PCIE_LINK_STATE_L1);
	tp->aspm_manageable = !rc;
}
Quoted 2 lines
drivers/net/ethernet/realtek/r8169_main.c +0 -0
 	tp->dash_type = rtl_check_dash(tp);
 
author
#2 lore raw
Quoted 7 lines · Chunhao Lin
Quoted 6 lines

This patch will enable RTL8125 ASPM L1.2 on the platforms that have tested RTL8125 with ASPM L1.2 enabled.
Register mac ocp 0xc0b2 will help to identify if RTL8125 has been tested on L1.2 enabled platform. If it is, this register will be set to 0xf. If not, this register will be default value 0.

Quoted 5 lines

Who and what defines which value this register has? The BIOS? ACPI? Mainboard vendors test and can control the flagging? How about add-on cards and systems with other boot loaders, e.g. SBC's with RTL8125 like Odroid H2+?

Soc vendor can opt-in to enable these bits to enable L1.2 through programming tool/bios/uboot. Right now, there is no plan for set these bits for add-on card.

Quoted 3 lines

What is actually the critical component that makes L1.2 work or not with RTL8125 on a particular system? The chipset? Or electrical characteristics?

RTL8125 can support L1.2, but it disabled by r8169. So we create an option to let soc vendor can opn-in to enabled L1.2 with r8169.

Quoted 5 lines

The difference in power consumption between L1.1 and L1.2 is a few mW ([0]).
So I wonder whether it's worth it to add this flagging mechanism. Or does it also impact reaching certain package power saving states?

Upstream port also can save power when rtl8125 L1.2 is enabled.

Quoted 181 lines

[0] https://pcisig.com/making-most-pcie%C2%AE-low-power-features

drivers/net/ethernet/realtek/r8169_main.c static void rtl_wol_enable_rx(struct

Quoted 12 lines
---
 drivers/net/ethernet/realtek/r8169_main.c | 99
++++++++++++++++++-----
 1 file changed, 79 insertions(+), 20 deletions(-)
drivers/net/ethernet/realtek/r8169_main.c +0 -0
index 19e2621e0645..b1e013969d4c 100644
@@ -2238,21 +2238,6 @@ static void rtl_wol_enable_rx(struct

rtl8169_private *tp)

drivers/net/ethernet/realtek/r8169_main.c static void rtl_wol_enable_rx(struct · line 2238

Quoted 1 line
drivers/net/ethernet/realtek/r8169_main.c +0 -0
 			AcceptBroadcast | AcceptMulticast |

AcceptMyPhys); }

drivers/net/ethernet/realtek/r8169_main.c static void rtl_pcie_state_l2l3_disable(struct

Quoted 18 lines
drivers/net/ethernet/realtek/r8169_main.c +0 -14
-static void rtl_prepare_power_down(struct rtl8169_private *tp) -{
-	if (tp->dash_type != RTL_DASH_NONE)
-		return;
-
-	if (tp->mac_version == RTL_GIGA_MAC_VER_32 ||
-	    tp->mac_version == RTL_GIGA_MAC_VER_33)
-		rtl_ephy_write(tp, 0x19, 0xff64);
-
-	if (device_may_wakeup(tp_to_dev(tp))) {
-		phy_speed_down(tp->phydev, false);
-		rtl_wol_enable_rx(tp);
-	}
-}
-
 static void rtl_init_rxcfg(struct rtl8169_private *tp)  {
 	switch (tp->mac_version) {
@@ -2650,6 +2635,34 @@ static void rtl_pcie_state_l2l3_disable(struct

rtl8169_private *tp)

drivers/net/ethernet/realtek/r8169_main.c static void rtl_pcie_state_l2l3_disable(struct · line 2637

Quoted 3 lines
drivers/net/ethernet/realtek/r8169_main.c +1 -0
 	RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Rdy_to_L23);  }
 
+static void rtl_disable_exit_l1(struct rtl8169_private *tp) {

Why is this function needed? The chip should be quiet anyway.
IOW: What could be the impact of not having this function currently? If it fixes something then it should be a separate patch.

drivers/net/ethernet/realtek/r8169_main.c static void rtl_hw_aspm_clkreq_enable(struct

Quoted 29 lines
drivers/net/ethernet/realtek/r8169_main.c +26 -0
+	/* Bits control which events trigger ASPM L1 exit:
+	 * Bit 12: rxdv
+	 * Bit 11: ltr_msg
+	 * Bit 10: txdma_poll
+	 * Bit  9: xadm
+	 * Bit  8: pktavi
+	 * Bit  7: txpla
+	 */
+	switch (tp->mac_version) {
+	case RTL_GIGA_MAC_VER_34 ... RTL_GIGA_MAC_VER_36:
+		rtl_eri_clear_bits(tp, 0xd4, 0x1f00);
+		break;
+	case RTL_GIGA_MAC_VER_37 ... RTL_GIGA_MAC_VER_38:
+		rtl_eri_clear_bits(tp, 0xd4, 0x0c00);
+		break;
+	case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_53:
+		rtl_eri_clear_bits(tp, 0xd4, 0x1f80);
+		break;
+	case RTL_GIGA_MAC_VER_60 ... RTL_GIGA_MAC_VER_63:
+		r8168_mac_ocp_modify(tp, 0xc0ac, 0x1f80, 0);
+		break;
+	default:
+		break;
+	}
+}
+
 static void rtl_enable_exit_l1(struct rtl8169_private *tp)  {
 	/* Bits control which events trigger ASPM L1 exit:
@@ -2692,6 +2705,33 @@ static void rtl_hw_aspm_clkreq_enable(struct

rtl8169_private *tp, bool enable)

drivers/net/ethernet/realtek/r8169_main.c static void rtl_hw_aspm_clkreq_enable(struct rtl8169_private *tp, bool enable)

Quoted 5 lines
drivers/net/ethernet/realtek/r8169_main.c +2 -0
 	udelay(10);
 }
 
+static void rtl_hw_aspm_l12_enable(struct rtl8169_private *tp, bool
+enable) {

I assume this code works on RTL8125 only. Then this should be reflected in the function naming, like we do it for other version-specific functions.

Quoted 16 lines
drivers/net/ethernet/realtek/r8169_main.c +16 -0
+	/* Don't enable L1.2 in the chip if OS can't control ASPM */
+	if (enable && tp->aspm_manageable) {
+		r8168_mac_ocp_modify(tp, 0xe094, 0xff00, 0);
+		r8168_mac_ocp_modify(tp, 0xe092, 0x00ff, BIT(2));
+	} else {
+		r8168_mac_ocp_modify(tp, 0xe092, 0x00ff, 0);
+	}
+}
+
+static void rtl_prepare_power_down(struct rtl8169_private *tp) {
+	if (tp->dash_type != RTL_DASH_NONE)
+		return;
+
+	if (tp->mac_version == RTL_GIGA_MAC_VER_32 ||
+	    tp->mac_version == RTL_GIGA_MAC_VER_33)
+		rtl_ephy_write(tp, 0x19, 0xff64);

drivers/net/ethernet/realtek/r8169_main.c static void rtl_hw_aspm_clkreq_enable(struct rtl8169_private *tp, bool enable)

Quoted 10 lines
drivers/net/ethernet/realtek/r8169_main.c +8 -0
+
+	if (device_may_wakeup(tp_to_dev(tp))) {
+		rtl_disable_exit_l1(tp);
+		phy_speed_down(tp->phydev, false);
+		rtl_wol_enable_rx(tp);
+	}
+}
+
 static void rtl_set_fifo_size(struct rtl8169_private *tp, u16 rx_stat,
 			      u16 tx_stat, u16 rx_dyn, u16 tx_dyn)  { @@ -

3675,6 +3715,7

drivers/net/ethernet/realtek/r8169_main.c static void rtl_init_mac_address(struct

Quoted 8 lines
drivers/net/ethernet/realtek/r8169_main.c +1 -0
 @@ static void rtl_hw_start_8125b(struct rtl8169_private *tp)
 	rtl_ephy_init(tp, e_info_8125b);
 	rtl_hw_start_8125_common(tp);
 
+	rtl_hw_aspm_l12_enable(tp, true);
 	rtl_hw_aspm_clkreq_enable(tp, true);  }
@@ -5255,6 +5296,20 @@ static void rtl_init_mac_address(struct

rtl8169_private *tp)

drivers/net/ethernet/realtek/r8169_main.c static void rtl_init_mac_address(struct rtl8169_private *tp)

Quoted 8 lines
drivers/net/ethernet/realtek/r8169_main.c +5 -0
 	rtl_rar_set(tp, mac_addr);
 }
 
+/* mac ocp 0xc0b2 will help to identify if RTL8125 has been tested
+ * on L1.2 enabled platform. If it is, this register will be set to 0xf.
+ * If not, this register will be default value 0.
+ */
+static bool rtl_platform_l12_enabled(struct rtl8169_private *tp) {

The function name is misleading. It could be read as checking whether the platform supports L1.2.

drivers/net/ethernet/realtek/r8169_main.c static int rtl_init_one(struct pci_dev *pdev,

Quoted 12 lines
drivers/net/ethernet/realtek/r8169_main.c +8 -0
+	switch (tp->mac_version) {
+	case RTL_GIGA_MAC_VER_60 ... RTL_GIGA_MAC_VER_63:
+		return (r8168_mac_ocp_read(tp, 0xc0b2) & 0xf) ? true : false;
+	default:
+		return false;
+	}
+}
+
 static int rtl_init_one(struct pci_dev *pdev, const struct
 pci_device_id *ent)  {
 	struct rtl8169_private *tp;
@@ -5333,11 +5388,15 @@ static int rtl_init_one(struct pci_dev *pdev,

const struct pci_device_id *ent)

drivers/net/ethernet/realtek/r8169_main.c static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)

Quoted 11 lines
drivers/net/ethernet/realtek/r8169_main.c +3 -5
 	 * Chips from RTL8168h partially have issues with L1.2, but seem
 	 * to work fine with L1 and L1.1.
 	 */
-	if (tp->mac_version >= RTL_GIGA_MAC_VER_45)
-		rc = pci_disable_link_state(pdev, PCIE_LINK_STATE_L1_2);
-	else
-		rc = pci_disable_link_state(pdev, PCIE_LINK_STATE_L1);
-	tp->aspm_manageable = !rc;
+	if (!rtl_platform_l12_enabled(tp)) {
+		if (tp->mac_version >= RTL_GIGA_MAC_VER_45)
+			rc = pci_disable_link_state(pdev,

PCIE_LINK_STATE_L1_2);

drivers/net/ethernet/realtek/r8169_main.c static int rtl_init_one(struct pci_dev *pdev, · line 5395

Quoted 2 lines
drivers/net/ethernet/realtek/r8169_main.c +2 -0
+		else
+			rc = pci_disable_link_state(pdev,

PCIE_LINK_STATE_L1);

drivers/net/ethernet/realtek/r8169_main.c static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) · line 5400

Quoted 5 lines
drivers/net/ethernet/realtek/r8169_main.c +4 -0
+		tp->aspm_manageable = !rc;
+	} else {
+		tp->aspm_manageable = pcie_aspm_enabled(pdev);
+	}
 

Better readable may be the following:

if (rtl_platform_l12_enabled(tp)) {
	tp->aspm_manageable = pcie_aspm_enabled(pdev); } else if (tp-

drivers/net/ethernet/realtek/r8169_main.c static int rtl_init_one(struct pci_dev *pdev, · line 5401

Quoted 1 line
drivers/net/ethernet/realtek/r8169_main.c +0 -0
 mac_version >= RTL_GIGA_MAC_VER_45) {
	rc = pci_disable_link_state(pdev, PCIE_LINK_STATE_L1_2);
	tp->aspm_manageable = !rc;
} else {
	rc = pci_disable_link_state(pdev, PCIE_LINK_STATE_L1);
	tp->aspm_manageable = !rc;
}

drivers/net/ethernet/realtek/r8169_main.c static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) · line 5401

Quoted 2 lines
drivers/net/ethernet/realtek/r8169_main.c +0 -0
 	tp->dash_type = rtl_check_dash(tp);

------Please consider the environment before printing this e-mail.

maintainer
#3 lore raw
Quoted 12 lines · Hau
Quoted 7 lines · Chunhao Lin
Quoted 6 lines

This patch will enable RTL8125 ASPM L1.2 on the platforms that have tested RTL8125 with ASPM L1.2 enabled.
Register mac ocp 0xc0b2 will help to identify if RTL8125 has been tested on L1.2 enabled platform. If it is, this register will be set to 0xf. If not, this register will be default value 0.

Quoted 5 lines

Who and what defines which value this register has? The BIOS? ACPI? Mainboard vendors test and can control the flagging? How about add-on cards and systems with other boot loaders, e.g. SBC's with RTL8125 like Odroid H2+?

Quoted 9 lines

Soc vendor can opt-in to enable these bits to enable L1.2 through programming tool/bios/uboot. Right now, there is no plan for set these bits for add-on card.

Quoted 3 lines

What is actually the critical component that makes L1.2 work or not with RTL8125 on a particular system? The chipset? Or electrical characteristics?

RTL8125 can support L1.2, but it disabled by r8169. So we create an option to let soc vendor can opn-in to enabled L1.2 with r8169.

Thanks, Hau. Still the question is open what's the root cause of L1.2 not working with RTL8125 on *some* systems. I can't imagine that it just by chance works or not. If we know which component conflicts with RTL8125 then maybe a PCI quirk could be used.

Quoted 5 lines
Quoted 5 lines

The difference in power consumption between L1.1 and L1.2 is a few mW ([0]).
So I wonder whether it's worth it to add this flagging mechanism. Or does it also impact reaching certain package power saving states?

Quoted 46 lines

Upstream port also can save power when rtl8125 L1.2 is enabled.

Quoted 44 lines

[0] https://pcisig.com/making-most-pcie%C2%AE-low-power-features

drivers/net/ethernet/realtek/r8169_main.c static void rtl_wol_enable_rx(struct

Quoted 12 lines
---
 drivers/net/ethernet/realtek/r8169_main.c | 99
++++++++++++++++++-----
 1 file changed, 79 insertions(+), 20 deletions(-)
drivers/net/ethernet/realtek/r8169_main.c +0 -0
index 19e2621e0645..b1e013969d4c 100644
@@ -2238,21 +2238,6 @@ static void rtl_wol_enable_rx(struct

rtl8169_private *tp)

drivers/net/ethernet/realtek/r8169_main.c static void rtl_wol_enable_rx(struct · line 2238

Quoted 1 line
drivers/net/ethernet/realtek/r8169_main.c +0 -0
 			AcceptBroadcast | AcceptMulticast |

AcceptMyPhys); }

drivers/net/ethernet/realtek/r8169_main.c static void rtl_pcie_state_l2l3_disable(struct

Quoted 18 lines
drivers/net/ethernet/realtek/r8169_main.c +0 -14
-static void rtl_prepare_power_down(struct rtl8169_private *tp) -{
-	if (tp->dash_type != RTL_DASH_NONE)
-		return;
-
-	if (tp->mac_version == RTL_GIGA_MAC_VER_32 ||
-	    tp->mac_version == RTL_GIGA_MAC_VER_33)
-		rtl_ephy_write(tp, 0x19, 0xff64);
-
-	if (device_may_wakeup(tp_to_dev(tp))) {
-		phy_speed_down(tp->phydev, false);
-		rtl_wol_enable_rx(tp);
-	}
-}
-
 static void rtl_init_rxcfg(struct rtl8169_private *tp)  {
 	switch (tp->mac_version) {
@@ -2650,6 +2635,34 @@ static void rtl_pcie_state_l2l3_disable(struct

rtl8169_private *tp)

drivers/net/ethernet/realtek/r8169_main.c static void rtl_pcie_state_l2l3_disable(struct · line 2637

Quoted 3 lines
drivers/net/ethernet/realtek/r8169_main.c +1 -0
 	RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Rdy_to_L23);  }
 
+static void rtl_disable_exit_l1(struct rtl8169_private *tp) {

Why is this function needed? The chip should be quiet anyway.
IOW: What could be the impact of not having this function currently? If it fixes something then it should be a separate patch.

This question would still be open.

Quoted 137 lines
Quoted 137 lines

drivers/net/ethernet/realtek/r8169_main.c static void rtl_hw_aspm_clkreq_enable(struct

Quoted 29 lines
drivers/net/ethernet/realtek/r8169_main.c +26 -0
+	/* Bits control which events trigger ASPM L1 exit:
+	 * Bit 12: rxdv
+	 * Bit 11: ltr_msg
+	 * Bit 10: txdma_poll
+	 * Bit  9: xadm
+	 * Bit  8: pktavi
+	 * Bit  7: txpla
+	 */
+	switch (tp->mac_version) {
+	case RTL_GIGA_MAC_VER_34 ... RTL_GIGA_MAC_VER_36:
+		rtl_eri_clear_bits(tp, 0xd4, 0x1f00);
+		break;
+	case RTL_GIGA_MAC_VER_37 ... RTL_GIGA_MAC_VER_38:
+		rtl_eri_clear_bits(tp, 0xd4, 0x0c00);
+		break;
+	case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_53:
+		rtl_eri_clear_bits(tp, 0xd4, 0x1f80);
+		break;
+	case RTL_GIGA_MAC_VER_60 ... RTL_GIGA_MAC_VER_63:
+		r8168_mac_ocp_modify(tp, 0xc0ac, 0x1f80, 0);
+		break;
+	default:
+		break;
+	}
+}
+
 static void rtl_enable_exit_l1(struct rtl8169_private *tp)  {
 	/* Bits control which events trigger ASPM L1 exit:
@@ -2692,6 +2705,33 @@ static void rtl_hw_aspm_clkreq_enable(struct

rtl8169_private *tp, bool enable)

drivers/net/ethernet/realtek/r8169_main.c static void rtl_hw_aspm_clkreq_enable(struct rtl8169_private *tp, bool enable)

Quoted 5 lines
drivers/net/ethernet/realtek/r8169_main.c +2 -0
 	udelay(10);
 }
 
+static void rtl_hw_aspm_l12_enable(struct rtl8169_private *tp, bool
+enable) {

I assume this code works on RTL8125 only. Then this should be reflected in the function naming, like we do it for other version-specific functions.

Quoted 16 lines
drivers/net/ethernet/realtek/r8169_main.c +16 -0
+	/* Don't enable L1.2 in the chip if OS can't control ASPM */
+	if (enable && tp->aspm_manageable) {
+		r8168_mac_ocp_modify(tp, 0xe094, 0xff00, 0);
+		r8168_mac_ocp_modify(tp, 0xe092, 0x00ff, BIT(2));
+	} else {
+		r8168_mac_ocp_modify(tp, 0xe092, 0x00ff, 0);
+	}
+}
+
+static void rtl_prepare_power_down(struct rtl8169_private *tp) {
+	if (tp->dash_type != RTL_DASH_NONE)
+		return;
+
+	if (tp->mac_version == RTL_GIGA_MAC_VER_32 ||
+	    tp->mac_version == RTL_GIGA_MAC_VER_33)
+		rtl_ephy_write(tp, 0x19, 0xff64);

drivers/net/ethernet/realtek/r8169_main.c static void rtl_hw_aspm_clkreq_enable(struct rtl8169_private *tp, bool enable)

Quoted 10 lines
drivers/net/ethernet/realtek/r8169_main.c +8 -0
+
+	if (device_may_wakeup(tp_to_dev(tp))) {
+		rtl_disable_exit_l1(tp);
+		phy_speed_down(tp->phydev, false);
+		rtl_wol_enable_rx(tp);
+	}
+}
+
 static void rtl_set_fifo_size(struct rtl8169_private *tp, u16 rx_stat,
 			      u16 tx_stat, u16 rx_dyn, u16 tx_dyn)  { @@ -

3675,6 +3715,7

drivers/net/ethernet/realtek/r8169_main.c static void rtl_init_mac_address(struct

Quoted 8 lines
drivers/net/ethernet/realtek/r8169_main.c +1 -0
 @@ static void rtl_hw_start_8125b(struct rtl8169_private *tp)
 	rtl_ephy_init(tp, e_info_8125b);
 	rtl_hw_start_8125_common(tp);
 
+	rtl_hw_aspm_l12_enable(tp, true);
 	rtl_hw_aspm_clkreq_enable(tp, true);  }
@@ -5255,6 +5296,20 @@ static void rtl_init_mac_address(struct

rtl8169_private *tp)

drivers/net/ethernet/realtek/r8169_main.c static void rtl_init_mac_address(struct rtl8169_private *tp)

Quoted 8 lines
drivers/net/ethernet/realtek/r8169_main.c +5 -0
 	rtl_rar_set(tp, mac_addr);
 }
 
+/* mac ocp 0xc0b2 will help to identify if RTL8125 has been tested
+ * on L1.2 enabled platform. If it is, this register will be set to 0xf.
+ * If not, this register will be default value 0.
+ */
+static bool rtl_platform_l12_enabled(struct rtl8169_private *tp) {

The function name is misleading. It could be read as checking whether the platform supports L1.2.

drivers/net/ethernet/realtek/r8169_main.c static int rtl_init_one(struct pci_dev *pdev,

Quoted 12 lines
drivers/net/ethernet/realtek/r8169_main.c +8 -0
+	switch (tp->mac_version) {
+	case RTL_GIGA_MAC_VER_60 ... RTL_GIGA_MAC_VER_63:
+		return (r8168_mac_ocp_read(tp, 0xc0b2) & 0xf) ? true : false;
+	default:
+		return false;
+	}
+}
+
 static int rtl_init_one(struct pci_dev *pdev, const struct
 pci_device_id *ent)  {
 	struct rtl8169_private *tp;
@@ -5333,11 +5388,15 @@ static int rtl_init_one(struct pci_dev *pdev,

const struct pci_device_id *ent)

drivers/net/ethernet/realtek/r8169_main.c static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)

Quoted 11 lines
drivers/net/ethernet/realtek/r8169_main.c +3 -5
 	 * Chips from RTL8168h partially have issues with L1.2, but seem
 	 * to work fine with L1 and L1.1.
 	 */
-	if (tp->mac_version >= RTL_GIGA_MAC_VER_45)
-		rc = pci_disable_link_state(pdev, PCIE_LINK_STATE_L1_2);
-	else
-		rc = pci_disable_link_state(pdev, PCIE_LINK_STATE_L1);
-	tp->aspm_manageable = !rc;
+	if (!rtl_platform_l12_enabled(tp)) {
+		if (tp->mac_version >= RTL_GIGA_MAC_VER_45)
+			rc = pci_disable_link_state(pdev,

PCIE_LINK_STATE_L1_2);

drivers/net/ethernet/realtek/r8169_main.c static int rtl_init_one(struct pci_dev *pdev, · line 5395

Quoted 2 lines
drivers/net/ethernet/realtek/r8169_main.c +2 -0
+		else
+			rc = pci_disable_link_state(pdev,

PCIE_LINK_STATE_L1);

drivers/net/ethernet/realtek/r8169_main.c static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) · line 5400

Quoted 5 lines
drivers/net/ethernet/realtek/r8169_main.c +4 -0
+		tp->aspm_manageable = !rc;
+	} else {
+		tp->aspm_manageable = pcie_aspm_enabled(pdev);
+	}
 

Better readable may be the following:

if (rtl_platform_l12_enabled(tp)) {
	tp->aspm_manageable = pcie_aspm_enabled(pdev); } else if (tp-

drivers/net/ethernet/realtek/r8169_main.c static int rtl_init_one(struct pci_dev *pdev, · line 5401

Quoted 1 line
drivers/net/ethernet/realtek/r8169_main.c +0 -0
 mac_version >= RTL_GIGA_MAC_VER_45) {
	rc = pci_disable_link_state(pdev, PCIE_LINK_STATE_L1_2);
	tp->aspm_manageable = !rc;
} else {
	rc = pci_disable_link_state(pdev, PCIE_LINK_STATE_L1);
	tp->aspm_manageable = !rc;
}

drivers/net/ethernet/realtek/r8169_main.c static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) · line 5401

Quoted 2 lines
drivers/net/ethernet/realtek/r8169_main.c +0 -0
 	tp->dash_type = rtl_check_dash(tp);

------Please consider the environment before printing this e-mail.

author
#4 lore raw
Quoted 23 lines · Hau
Quoted 7 lines
Quoted 7 lines · Chunhao Lin
Quoted 6 lines

This patch will enable RTL8125 ASPM L1.2 on the platforms that have tested RTL8125 with ASPM L1.2 enabled.
Register mac ocp 0xc0b2 will help to identify if RTL8125 has been tested on L1.2 enabled platform. If it is, this register will be set to 0xf. If not, this register will be default value 0.

Quoted 6 lines
Quoted 5 lines

Who and what defines which value this register has? The BIOS? ACPI? Mainboard vendors test and can control the flagging? How about add-on cards and systems with other boot loaders, e.g. SBC's with RTL8125 like Odroid H2+?

Soc vendor can opt-in to enable these bits to enable L1.2 through

programming tool/bios/uboot.

Quoted 7 lines

Right now, there is no plan for set these bits for add-on card.

Quoted 4 lines

What is actually the critical component that makes L1.2 work or not with
RTL8125 on a particular system? The chipset? Or electrical characteristics?

RTL8125 can support L1.2, but it disabled by r8169. So we create an

option

Quoted 9 lines
Quoted 2 lines

to let soc vendor can opn-in to enabled L1.2 with r8169.

Thanks, Hau. Still the question is open what's the root cause of L1.2 not working with RTL8125 on *some* systems. I can't imagine that it just by chance works or not.
If we know which component conflicts with RTL8125 then maybe a PCI quirk could be used.

Most of them are hardware compatibility issues. It may related to refclk/clkreq/ltr... setting. Without the platform, it is hard to debug this kind of issue.

Quoted 193 lines
Quoted 5 lines
Quoted 5 lines

The difference in power consumption between L1.1 and L1.2 is a few mW ([0]).
So I wonder whether it's worth it to add this flagging mechanism. Or does it also impact reaching certain package power saving states?

Quoted 47 lines

Upstream port also can save power when rtl8125 L1.2 is enabled.

Quoted 45 lines

[0] https://pcisig.com/making-most-pcie%C2%AE-low-power-features

drivers/net/ethernet/realtek/r8169_main.c static void rtl_wol_enable_rx(struct

Quoted 12 lines
---
 drivers/net/ethernet/realtek/r8169_main.c | 99
++++++++++++++++++-----
 1 file changed, 79 insertions(+), 20 deletions(-)
drivers/net/ethernet/realtek/r8169_main.c +0 -0
index 19e2621e0645..b1e013969d4c 100644
@@ -2238,21 +2238,6 @@ static void rtl_wol_enable_rx(struct

rtl8169_private *tp)

drivers/net/ethernet/realtek/r8169_main.c static void rtl_wol_enable_rx(struct · line 2238

Quoted 1 line
drivers/net/ethernet/realtek/r8169_main.c +0 -0
 			AcceptBroadcast | AcceptMulticast |

AcceptMyPhys); }

Quoted 18 lines
drivers/net/ethernet/realtek/r8169_main.c +0 -14
-static void rtl_prepare_power_down(struct rtl8169_private *tp) -{
-	if (tp->dash_type != RTL_DASH_NONE)
-		return;
-
-	if (tp->mac_version == RTL_GIGA_MAC_VER_32 ||
-	    tp->mac_version == RTL_GIGA_MAC_VER_33)
-		rtl_ephy_write(tp, 0x19, 0xff64);
-
-	if (device_may_wakeup(tp_to_dev(tp))) {
-		phy_speed_down(tp->phydev, false);
-		rtl_wol_enable_rx(tp);
-	}
-}
-
 static void rtl_init_rxcfg(struct rtl8169_private *tp)  {
 	switch (tp->mac_version) {
@@ -2650,6 +2635,34 @@ static void
Quoted 1 line

rtl_pcie_state_l2l3_disable(struct

rtl8169_private *tp)

drivers/net/ethernet/realtek/r8169_main.c

Quoted 3 lines
drivers/net/ethernet/realtek/r8169_main.c +1 -0
 	RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Rdy_to_L23);  }
 
+static void rtl_disable_exit_l1(struct rtl8169_private *tp) {

Why is this function needed? The chip should be quiet anyway.
IOW: What could be the impact of not having this function currently? If it fixes something then it should be a separate patch.

This question would still be open.

Quoted 30 lines
Quoted 30 lines

drivers/net/ethernet/realtek/r8169_main.c static void rtl_hw_aspm_clkreq_enable(struct

Quoted 29 lines
drivers/net/ethernet/realtek/r8169_main.c +26 -0
+	/* Bits control which events trigger ASPM L1 exit:
+	 * Bit 12: rxdv
+	 * Bit 11: ltr_msg
+	 * Bit 10: txdma_poll
+	 * Bit  9: xadm
+	 * Bit  8: pktavi
+	 * Bit  7: txpla
+	 */
+	switch (tp->mac_version) {
+	case RTL_GIGA_MAC_VER_34 ... RTL_GIGA_MAC_VER_36:
+		rtl_eri_clear_bits(tp, 0xd4, 0x1f00);
+		break;
+	case RTL_GIGA_MAC_VER_37 ... RTL_GIGA_MAC_VER_38:
+		rtl_eri_clear_bits(tp, 0xd4, 0x0c00);
+		break;
+	case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_53:
+		rtl_eri_clear_bits(tp, 0xd4, 0x1f80);
+		break;
+	case RTL_GIGA_MAC_VER_60 ... RTL_GIGA_MAC_VER_63:
+		r8168_mac_ocp_modify(tp, 0xc0ac, 0x1f80, 0);
+		break;
+	default:
+		break;
+	}
+}
+
 static void rtl_enable_exit_l1(struct rtl8169_private *tp)  {
 	/* Bits control which events trigger ASPM L1 exit:
@@ -2692,6 +2705,33 @@ static void rtl_hw_aspm_clkreq_enable(struct

rtl8169_private *tp, bool enable)

Quoted 8 lines
Quoted 8 lines

drivers/net/ethernet/realtek/r8169_main.c static void rtl_hw_aspm_clkreq_enable(struct rtl8169_private *tp, bool enable)

Quoted 5 lines
drivers/net/ethernet/realtek/r8169_main.c +2 -0
 	udelay(10);
 }
 
+static void rtl_hw_aspm_l12_enable(struct rtl8169_private *tp, bool
+enable) {

I assume this code works on RTL8125 only. Then this should be reflected in the function naming, like we do it for other version-specific

functions.

Quoted 100 lines
Quoted 100 lines
Quoted 17 lines
drivers/net/ethernet/realtek/r8169_main.c +16 -0
+	/* Don't enable L1.2 in the chip if OS can't control ASPM */
+	if (enable && tp->aspm_manageable) {
+		r8168_mac_ocp_modify(tp, 0xe094, 0xff00, 0);
+		r8168_mac_ocp_modify(tp, 0xe092, 0x00ff, BIT(2));
+	} else {
+		r8168_mac_ocp_modify(tp, 0xe092, 0x00ff, 0);
+	}
+}
+
+static void rtl_prepare_power_down(struct rtl8169_private *tp) {
+	if (tp->dash_type != RTL_DASH_NONE)
+		return;
+
+	if (tp->mac_version == RTL_GIGA_MAC_VER_32 ||
+	    tp->mac_version == RTL_GIGA_MAC_VER_33)
+		rtl_ephy_write(tp, 0x19, 0xff64);

drivers/net/ethernet/realtek/r8169_main.c static void rtl_hw_aspm_clkreq_enable(struct rtl8169_private *tp, bool enable)

Quoted 10 lines
drivers/net/ethernet/realtek/r8169_main.c +8 -0
+
+	if (device_may_wakeup(tp_to_dev(tp))) {
+		rtl_disable_exit_l1(tp);
+		phy_speed_down(tp->phydev, false);
+		rtl_wol_enable_rx(tp);
+	}
+}
+
 static void rtl_set_fifo_size(struct rtl8169_private *tp, u16 rx_stat,
 			      u16 tx_stat, u16 rx_dyn, u16 tx_dyn)  { @@ -

3675,6 +3715,7

drivers/net/ethernet/realtek/r8169_main.c static void rtl_init_mac_address(struct

Quoted 8 lines
drivers/net/ethernet/realtek/r8169_main.c +1 -0
 @@ static void rtl_hw_start_8125b(struct rtl8169_private *tp)
 	rtl_ephy_init(tp, e_info_8125b);
 	rtl_hw_start_8125_common(tp);
 
+	rtl_hw_aspm_l12_enable(tp, true);
 	rtl_hw_aspm_clkreq_enable(tp, true);  }
@@ -5255,6 +5296,20 @@ static void rtl_init_mac_address(struct

rtl8169_private *tp)

drivers/net/ethernet/realtek/r8169_main.c static void rtl_init_mac_address(struct rtl8169_private *tp)

Quoted 8 lines
drivers/net/ethernet/realtek/r8169_main.c +5 -0
 	rtl_rar_set(tp, mac_addr);
 }
 
+/* mac ocp 0xc0b2 will help to identify if RTL8125 has been tested
+ * on L1.2 enabled platform. If it is, this register will be set to 0xf.
+ * If not, this register will be default value 0.
+ */
+static bool rtl_platform_l12_enabled(struct rtl8169_private *tp) {

The function name is misleading. It could be read as checking whether the platform supports L1.2.

drivers/net/ethernet/realtek/r8169_main.c static int rtl_init_one(struct pci_dev · line 5388

Quoted 13 lines
drivers/net/ethernet/realtek/r8169_main.c +8 -0
+	switch (tp->mac_version) {
+	case RTL_GIGA_MAC_VER_60 ... RTL_GIGA_MAC_VER_63:
+		return (r8168_mac_ocp_read(tp, 0xc0b2) & 0xf) ? true : false;
+	default:
+		return false;
+	}
+}
+
 static int rtl_init_one(struct pci_dev *pdev, const struct
 pci_device_id *ent)  {
 	struct rtl8169_private *tp;
@@ -5333,11 +5388,15 @@ static int rtl_init_one(struct pci_dev
 *pdev,

const struct pci_device_id *ent)

drivers/net/ethernet/realtek/r8169_main.c static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)

Quoted 11 lines
drivers/net/ethernet/realtek/r8169_main.c +3 -5
 	 * Chips from RTL8168h partially have issues with L1.2, but seem
 	 * to work fine with L1 and L1.1.
 	 */
-	if (tp->mac_version >= RTL_GIGA_MAC_VER_45)
-		rc = pci_disable_link_state(pdev, PCIE_LINK_STATE_L1_2);
-	else
-		rc = pci_disable_link_state(pdev, PCIE_LINK_STATE_L1);
-	tp->aspm_manageable = !rc;
+	if (!rtl_platform_l12_enabled(tp)) {
+		if (tp->mac_version >= RTL_GIGA_MAC_VER_45)
+			rc = pci_disable_link_state(pdev,

PCIE_LINK_STATE_L1_2);

drivers/net/ethernet/realtek/r8169_main.c static int rtl_init_one(struct pci_dev · line 5396

Quoted 2 lines
drivers/net/ethernet/realtek/r8169_main.c +2 -0
+		else
+			rc = pci_disable_link_state(pdev,

PCIE_LINK_STATE_L1);

drivers/net/ethernet/realtek/r8169_main.c static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) · line 5400

Quoted 5 lines
drivers/net/ethernet/realtek/r8169_main.c +4 -0
+		tp->aspm_manageable = !rc;
+	} else {
+		tp->aspm_manageable = pcie_aspm_enabled(pdev);
+	}
 

Better readable may be the following:

if (rtl_platform_l12_enabled(tp)) {
	tp->aspm_manageable = pcie_aspm_enabled(pdev); } else if (tp-

drivers/net/ethernet/realtek/r8169_main.c static int rtl_init_one(struct pci_dev · line 5402

Quoted 1 line
drivers/net/ethernet/realtek/r8169_main.c +0 -0
 mac_version >= RTL_GIGA_MAC_VER_45) {
	rc = pci_disable_link_state(pdev, PCIE_LINK_STATE_L1_2);
	tp->aspm_manageable = !rc;
} else {
	rc = pci_disable_link_state(pdev, PCIE_LINK_STATE_L1);
	tp->aspm_manageable = !rc;
}
Quoted 2 lines

tp->dash_type = rtl_check_dash(tp);

------Please consider the environment before printing this e-mail.

maintainer
#5 lore raw
In reply to Chunhao Lin

Hi Hau,

Quoted 77 lines · Chunhao Lin

This patch will enable RTL8125 ASPM L1.2 on the platforms that have tested RTL8125 with ASPM L1.2 enabled.
Register mac ocp 0xc0b2 will help to identify if RTL8125 has been tested on L1.2 enabled platform. If it is, this register will be set to 0xf. If not, this register will be default value 0.

---
 drivers/net/ethernet/realtek/r8169_main.c | 99 ++++++++++++++++++-----
 1 file changed, 79 insertions(+), 20 deletions(-)
drivers/net/ethernet/realtek/r8169_main.c +29 -15
index 19e2621e0645..b1e013969d4c 100644
@@ -2238,21 +2238,6 @@ static void rtl_wol_enable_rx(struct rtl8169_private *tp)
 			AcceptBroadcast | AcceptMulticast | AcceptMyPhys);
 }
 
-static void rtl_prepare_power_down(struct rtl8169_private *tp)
-{
-	if (tp->dash_type != RTL_DASH_NONE)
-		return;
-
-	if (tp->mac_version == RTL_GIGA_MAC_VER_32 ||
-	    tp->mac_version == RTL_GIGA_MAC_VER_33)
-		rtl_ephy_write(tp, 0x19, 0xff64);
-
-	if (device_may_wakeup(tp_to_dev(tp))) {
-		phy_speed_down(tp->phydev, false);
-		rtl_wol_enable_rx(tp);
-	}
-}
-
 static void rtl_init_rxcfg(struct rtl8169_private *tp)
 {
 	switch (tp->mac_version) {
@@ -2650,6 +2635,34 @@ static void rtl_pcie_state_l2l3_disable(struct rtl8169_private *tp)
 	RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Rdy_to_L23);
 }
 
+static void rtl_disable_exit_l1(struct rtl8169_private *tp)
+{
+	/* Bits control which events trigger ASPM L1 exit:
+	 * Bit 12: rxdv
+	 * Bit 11: ltr_msg
+	 * Bit 10: txdma_poll
+	 * Bit  9: xadm
+	 * Bit  8: pktavi
+	 * Bit  7: txpla
+	 */
+	switch (tp->mac_version) {
+	case RTL_GIGA_MAC_VER_34 ... RTL_GIGA_MAC_VER_36:
+		rtl_eri_clear_bits(tp, 0xd4, 0x1f00);
+		break;
+	case RTL_GIGA_MAC_VER_37 ... RTL_GIGA_MAC_VER_38:
+		rtl_eri_clear_bits(tp, 0xd4, 0x0c00);
+		break;
+	case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_53:
+		rtl_eri_clear_bits(tp, 0xd4, 0x1f80);
+		break;
+	case RTL_GIGA_MAC_VER_60 ... RTL_GIGA_MAC_VER_63:
+		r8168_mac_ocp_modify(tp, 0xc0ac, 0x1f80, 0);
+		break;
+	default:
+		break;
+	}
+}
+
 static void rtl_enable_exit_l1(struct rtl8169_private *tp)
 {
 	/* Bits control which events trigger ASPM L1 exit:
@@ -2692,6 +2705,33 @@ static void rtl_hw_aspm_clkreq_enable(struct rtl8169_private *tp, bool enable)
 	udelay(10);
 }
 
+static void rtl_hw_aspm_l12_enable(struct rtl8169_private *tp, bool enable)

drivers/net/ethernet/realtek/r8169_main.c static void rtl_hw_aspm_clkreq_enable(struct rtl8169_private *tp, bool enable) · line 2718

Quoted 10 lines
drivers/net/ethernet/realtek/r8169_main.c +10 -0
+{
+	/* Don't enable L1.2 in the chip if OS can't control ASPM */
+	if (enable && tp->aspm_manageable) {
+		r8168_mac_ocp_modify(tp, 0xe094, 0xff00, 0);
+		r8168_mac_ocp_modify(tp, 0xe092, 0x00ff, BIT(2));
+	} else {
+		r8168_mac_ocp_modify(tp, 0xe092, 0x00ff, 0);
+	}
+}
+

Register E094 bits 0..15 are cleared when enabling, but not touched on disabling. I this correct?

And for basically the same purpose we have the following function. "don't enable L1.2 in the chip" is not covered by ASPM_en in Config5?

static void rtl_hw_aspm_clkreq_enable(struct rtl8169_private *tp, bool enable)

{
	/* Don't enable ASPM in the chip if OS can't control ASPM */
	if (enable && tp->aspm_manageable) {
		RTL_W8(tp, Config5, RTL_R8(tp, Config5) | ASPM_en);
		RTL_W8(tp, Config2, RTL_R8(tp, Config2) | ClkReqEn);
	} else {
		RTL_W8(tp, Config2, RTL_R8(tp, Config2) & ~ClkReqEn);
		RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~ASPM_en);
	}

	udelay(10);
}
Quoted 69 lines
drivers/net/ethernet/realtek/r8169_main.c +40 -5
+static void rtl_prepare_power_down(struct rtl8169_private *tp)
+{
+	if (tp->dash_type != RTL_DASH_NONE)
+		return;
+
+	if (tp->mac_version == RTL_GIGA_MAC_VER_32 ||
+	    tp->mac_version == RTL_GIGA_MAC_VER_33)
+		rtl_ephy_write(tp, 0x19, 0xff64);
+
+	if (device_may_wakeup(tp_to_dev(tp))) {
+		rtl_disable_exit_l1(tp);
+		phy_speed_down(tp->phydev, false);
+		rtl_wol_enable_rx(tp);
+	}
+}
+
 static void rtl_set_fifo_size(struct rtl8169_private *tp, u16 rx_stat,
 			      u16 tx_stat, u16 rx_dyn, u16 tx_dyn)
 {
@@ -3675,6 +3715,7 @@ static void rtl_hw_start_8125b(struct rtl8169_private *tp)
 	rtl_ephy_init(tp, e_info_8125b);
 	rtl_hw_start_8125_common(tp);
 
+	rtl_hw_aspm_l12_enable(tp, true);
 	rtl_hw_aspm_clkreq_enable(tp, true);
 }
 
@@ -5255,6 +5296,20 @@ static void rtl_init_mac_address(struct rtl8169_private *tp)
 	rtl_rar_set(tp, mac_addr);
 }
 
+/* mac ocp 0xc0b2 will help to identify if RTL8125 has been tested
+ * on L1.2 enabled platform. If it is, this register will be set to 0xf.
+ * If not, this register will be default value 0.
+ */
+static bool rtl_platform_l12_enabled(struct rtl8169_private *tp)
+{
+	switch (tp->mac_version) {
+	case RTL_GIGA_MAC_VER_60 ... RTL_GIGA_MAC_VER_63:
+		return (r8168_mac_ocp_read(tp, 0xc0b2) & 0xf) ? true : false;
+	default:
+		return false;
+	}
+}
+
 static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 {
 	struct rtl8169_private *tp;
@@ -5333,11 +5388,15 @@ static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 	 * Chips from RTL8168h partially have issues with L1.2, but seem
 	 * to work fine with L1 and L1.1.
 	 */
-	if (tp->mac_version >= RTL_GIGA_MAC_VER_45)
-		rc = pci_disable_link_state(pdev, PCIE_LINK_STATE_L1_2);
-	else
-		rc = pci_disable_link_state(pdev, PCIE_LINK_STATE_L1);
-	tp->aspm_manageable = !rc;
+	if (!rtl_platform_l12_enabled(tp)) {
+		if (tp->mac_version >= RTL_GIGA_MAC_VER_45)
+			rc = pci_disable_link_state(pdev, PCIE_LINK_STATE_L1_2);
+		else
+			rc = pci_disable_link_state(pdev, PCIE_LINK_STATE_L1);
+		tp->aspm_manageable = !rc;
+	} else {
+		tp->aspm_manageable = pcie_aspm_enabled(pdev);
+	}
 
 	tp->dash_type = rtl_check_dash(tp);
 
author
#6 lore raw
Quoted 79 lines · Chunhao Lin

drivers/net/ethernet/realtek/r8169_main.c static void rtl_wol_enable_rx(struct

Quoted 18 lines

This patch will enable RTL8125 ASPM L1.2 on the platforms that have tested RTL8125 with ASPM L1.2 enabled.
Register mac ocp 0xc0b2 will help to identify if RTL8125 has been tested on L1.2 enabled platform. If it is, this register will be set to 0xf. If not, this register will be default value 0.

---
 drivers/net/ethernet/realtek/r8169_main.c | 99
++++++++++++++++++-----
 1 file changed, 79 insertions(+), 20 deletions(-)
drivers/net/ethernet/realtek/r8169_main.c +0 -0
index 19e2621e0645..b1e013969d4c 100644
@@ -2238,21 +2238,6 @@ static void rtl_wol_enable_rx(struct

rtl8169_private *tp)

drivers/net/ethernet/realtek/r8169_main.c static void rtl_wol_enable_rx(struct · line 2238

Quoted 1 line
drivers/net/ethernet/realtek/r8169_main.c +0 -0
 			AcceptBroadcast | AcceptMulticast |

AcceptMyPhys); }

drivers/net/ethernet/realtek/r8169_main.c static void rtl_pcie_state_l2l3_disable(struct

Quoted 18 lines
drivers/net/ethernet/realtek/r8169_main.c +0 -14
-static void rtl_prepare_power_down(struct rtl8169_private *tp) -{
-	if (tp->dash_type != RTL_DASH_NONE)
-		return;
-
-	if (tp->mac_version == RTL_GIGA_MAC_VER_32 ||
-	    tp->mac_version == RTL_GIGA_MAC_VER_33)
-		rtl_ephy_write(tp, 0x19, 0xff64);
-
-	if (device_may_wakeup(tp_to_dev(tp))) {
-		phy_speed_down(tp->phydev, false);
-		rtl_wol_enable_rx(tp);
-	}
-}
-
 static void rtl_init_rxcfg(struct rtl8169_private *tp)  {
 	switch (tp->mac_version) {
@@ -2650,6 +2635,34 @@ static void rtl_pcie_state_l2l3_disable(struct

rtl8169_private *tp)

drivers/net/ethernet/realtek/r8169_main.c static void rtl_hw_aspm_clkreq_enable(struct

Quoted 32 lines
drivers/net/ethernet/realtek/r8169_main.c +27 -0
 	RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Rdy_to_L23);  }
 
+static void rtl_disable_exit_l1(struct rtl8169_private *tp) {
+	/* Bits control which events trigger ASPM L1 exit:
+	 * Bit 12: rxdv
+	 * Bit 11: ltr_msg
+	 * Bit 10: txdma_poll
+	 * Bit  9: xadm
+	 * Bit  8: pktavi
+	 * Bit  7: txpla
+	 */
+	switch (tp->mac_version) {
+	case RTL_GIGA_MAC_VER_34 ... RTL_GIGA_MAC_VER_36:
+		rtl_eri_clear_bits(tp, 0xd4, 0x1f00);
+		break;
+	case RTL_GIGA_MAC_VER_37 ... RTL_GIGA_MAC_VER_38:
+		rtl_eri_clear_bits(tp, 0xd4, 0x0c00);
+		break;
+	case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_53:
+		rtl_eri_clear_bits(tp, 0xd4, 0x1f80);
+		break;
+	case RTL_GIGA_MAC_VER_60 ... RTL_GIGA_MAC_VER_63:
+		r8168_mac_ocp_modify(tp, 0xc0ac, 0x1f80, 0);
+		break;
+	default:
+		break;
+	}
+}
+
 static void rtl_enable_exit_l1(struct rtl8169_private *tp)  {
 	/* Bits control which events trigger ASPM L1 exit:
@@ -2692,6 +2705,33 @@ static void rtl_hw_aspm_clkreq_enable(struct

rtl8169_private *tp, bool enable)

Quoted 3 lines
drivers/net/ethernet/realtek/r8169_main.c +0 -0
 	udelay(10);
 }
 
Quoted 14 lines

drivers/net/ethernet/realtek/r8169_main.c static void rtl_hw_aspm_clkreq_enable(struct rtl8169_private *tp, bool enable) · line 2718

Quoted 11 lines
drivers/net/ethernet/realtek/r8169_main.c +11 -0
+static void rtl_hw_aspm_l12_enable(struct rtl8169_private *tp, bool
+enable) {
+	/* Don't enable L1.2 in the chip if OS can't control ASPM */
+	if (enable && tp->aspm_manageable) {
+		r8168_mac_ocp_modify(tp, 0xe094, 0xff00, 0);
+		r8168_mac_ocp_modify(tp, 0xe092, 0x00ff, BIT(2));
+	} else {
+		r8168_mac_ocp_modify(tp, 0xe092, 0x00ff, 0);
+	}
+}
+

Register E094 bits 0..15 are cleared when enabling, but not touched on disabling. I this correct?

Register E094 bits 8...15 is a timer counter that is used to control when to disable ephy tx/rx. Set it to 0 means disable ephy tx/rx immediately when certain condition meet.
It has no meaning when register E092 bit 2 is set to 0.

Quoted 2 lines

And for basically the same purpose we have the following function. "don't enable L1.2 in the chip" is not covered by ASPM_en in Config5?

Register E092 is like ASPM_en in Config5. But it controls L1 substate (L1.1/L1.2) enable status.

Quoted 88 lines

static void rtl_hw_aspm_clkreq_enable(struct rtl8169_private *tp, bool

enable) {
	/* Don't enable ASPM in the chip if OS can't control ASPM */
	if (enable && tp->aspm_manageable) {
		RTL_W8(tp, Config5, RTL_R8(tp, Config5) | ASPM_en);
		RTL_W8(tp, Config2, RTL_R8(tp, Config2) | ClkReqEn);
	} else {
		RTL_W8(tp, Config2, RTL_R8(tp, Config2) & ~ClkReqEn);
		RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~ASPM_en);
	}

	udelay(10);
}
Quoted 7 lines
drivers/net/ethernet/realtek/r8169_main.c +7 -0
+static void rtl_prepare_power_down(struct rtl8169_private *tp) {
+	if (tp->dash_type != RTL_DASH_NONE)
+		return;
+
+	if (tp->mac_version == RTL_GIGA_MAC_VER_32 ||
+	    tp->mac_version == RTL_GIGA_MAC_VER_33)
+		rtl_ephy_write(tp, 0x19, 0xff64);

drivers/net/ethernet/realtek/r8169_main.c static void rtl_hw_aspm_clkreq_enable(struct rtl8169_private *tp, bool enable)

Quoted 10 lines
drivers/net/ethernet/realtek/r8169_main.c +8 -0
+
+	if (device_may_wakeup(tp_to_dev(tp))) {
+		rtl_disable_exit_l1(tp);
+		phy_speed_down(tp->phydev, false);
+		rtl_wol_enable_rx(tp);
+	}
+}
+
 static void rtl_set_fifo_size(struct rtl8169_private *tp, u16 rx_stat,
 			      u16 tx_stat, u16 rx_dyn, u16 tx_dyn)  { @@ -

3675,6 +3715,7

drivers/net/ethernet/realtek/r8169_main.c static void rtl_init_mac_address(struct

Quoted 8 lines
drivers/net/ethernet/realtek/r8169_main.c +1 -0
 @@ static void rtl_hw_start_8125b(struct rtl8169_private *tp)
 	rtl_ephy_init(tp, e_info_8125b);
 	rtl_hw_start_8125_common(tp);
 
+	rtl_hw_aspm_l12_enable(tp, true);
 	rtl_hw_aspm_clkreq_enable(tp, true);  }
@@ -5255,6 +5296,20 @@ static void rtl_init_mac_address(struct

rtl8169_private *tp)

drivers/net/ethernet/realtek/r8169_main.c static int rtl_init_one(struct pci_dev *pdev,

Quoted 20 lines
drivers/net/ethernet/realtek/r8169_main.c +13 -0
 	rtl_rar_set(tp, mac_addr);
 }
 
+/* mac ocp 0xc0b2 will help to identify if RTL8125 has been tested
+ * on L1.2 enabled platform. If it is, this register will be set to 0xf.
+ * If not, this register will be default value 0.
+ */
+static bool rtl_platform_l12_enabled(struct rtl8169_private *tp) {
+	switch (tp->mac_version) {
+	case RTL_GIGA_MAC_VER_60 ... RTL_GIGA_MAC_VER_63:
+		return (r8168_mac_ocp_read(tp, 0xc0b2) & 0xf) ? true : false;
+	default:
+		return false;
+	}
+}
+
 static int rtl_init_one(struct pci_dev *pdev, const struct
 pci_device_id *ent)  {
 	struct rtl8169_private *tp;
@@ -5333,11 +5388,15 @@ static int rtl_init_one(struct pci_dev *pdev,

const struct pci_device_id *ent)

drivers/net/ethernet/realtek/r8169_main.c static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)

Quoted 11 lines
drivers/net/ethernet/realtek/r8169_main.c +3 -5
 	 * Chips from RTL8168h partially have issues with L1.2, but seem
 	 * to work fine with L1 and L1.1.
 	 */
-	if (tp->mac_version >= RTL_GIGA_MAC_VER_45)
-		rc = pci_disable_link_state(pdev, PCIE_LINK_STATE_L1_2);
-	else
-		rc = pci_disable_link_state(pdev, PCIE_LINK_STATE_L1);
-	tp->aspm_manageable = !rc;
+	if (!rtl_platform_l12_enabled(tp)) {
+		if (tp->mac_version >= RTL_GIGA_MAC_VER_45)
+			rc = pci_disable_link_state(pdev,

PCIE_LINK_STATE_L1_2);

drivers/net/ethernet/realtek/r8169_main.c static int rtl_init_one(struct pci_dev *pdev, · line 5395

Quoted 2 lines
drivers/net/ethernet/realtek/r8169_main.c +2 -0
+		else
+			rc = pci_disable_link_state(pdev,

PCIE_LINK_STATE_L1);

drivers/net/ethernet/realtek/r8169_main.c static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) · line 5402

Quoted 7 lines
drivers/net/ethernet/realtek/r8169_main.c +4 -0
+		tp->aspm_manageable = !rc;
+	} else {
+		tp->aspm_manageable = pcie_aspm_enabled(pdev);
+	}
 
 	tp->dash_type = rtl_check_dash(tp);
 

------Please consider the environment before printing this e-mail.

maintainer
#7 lore raw
Quoted 93 lines · Hau
Quoted 79 lines · Chunhao Lin

drivers/net/ethernet/realtek/r8169_main.c static void rtl_wol_enable_rx(struct

Quoted 18 lines

This patch will enable RTL8125 ASPM L1.2 on the platforms that have tested RTL8125 with ASPM L1.2 enabled.
Register mac ocp 0xc0b2 will help to identify if RTL8125 has been tested on L1.2 enabled platform. If it is, this register will be set to 0xf. If not, this register will be default value 0.

---
 drivers/net/ethernet/realtek/r8169_main.c | 99
++++++++++++++++++-----
 1 file changed, 79 insertions(+), 20 deletions(-)
drivers/net/ethernet/realtek/r8169_main.c +0 -0
index 19e2621e0645..b1e013969d4c 100644
@@ -2238,21 +2238,6 @@ static void rtl_wol_enable_rx(struct

rtl8169_private *tp)

drivers/net/ethernet/realtek/r8169_main.c static void rtl_wol_enable_rx(struct · line 2238

Quoted 1 line
drivers/net/ethernet/realtek/r8169_main.c +0 -0
 			AcceptBroadcast | AcceptMulticast |

AcceptMyPhys); }

drivers/net/ethernet/realtek/r8169_main.c static void rtl_pcie_state_l2l3_disable(struct

Quoted 18 lines
drivers/net/ethernet/realtek/r8169_main.c +0 -14
-static void rtl_prepare_power_down(struct rtl8169_private *tp) -{
-	if (tp->dash_type != RTL_DASH_NONE)
-		return;
-
-	if (tp->mac_version == RTL_GIGA_MAC_VER_32 ||
-	    tp->mac_version == RTL_GIGA_MAC_VER_33)
-		rtl_ephy_write(tp, 0x19, 0xff64);
-
-	if (device_may_wakeup(tp_to_dev(tp))) {
-		phy_speed_down(tp->phydev, false);
-		rtl_wol_enable_rx(tp);
-	}
-}
-
 static void rtl_init_rxcfg(struct rtl8169_private *tp)  {
 	switch (tp->mac_version) {
@@ -2650,6 +2635,34 @@ static void rtl_pcie_state_l2l3_disable(struct

rtl8169_private *tp)

drivers/net/ethernet/realtek/r8169_main.c static void rtl_hw_aspm_clkreq_enable(struct

Quoted 32 lines
drivers/net/ethernet/realtek/r8169_main.c +27 -0
 	RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Rdy_to_L23);  }
 
+static void rtl_disable_exit_l1(struct rtl8169_private *tp) {
+	/* Bits control which events trigger ASPM L1 exit:
+	 * Bit 12: rxdv
+	 * Bit 11: ltr_msg
+	 * Bit 10: txdma_poll
+	 * Bit  9: xadm
+	 * Bit  8: pktavi
+	 * Bit  7: txpla
+	 */
+	switch (tp->mac_version) {
+	case RTL_GIGA_MAC_VER_34 ... RTL_GIGA_MAC_VER_36:
+		rtl_eri_clear_bits(tp, 0xd4, 0x1f00);
+		break;
+	case RTL_GIGA_MAC_VER_37 ... RTL_GIGA_MAC_VER_38:
+		rtl_eri_clear_bits(tp, 0xd4, 0x0c00);
+		break;
+	case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_53:
+		rtl_eri_clear_bits(tp, 0xd4, 0x1f80);
+		break;
+	case RTL_GIGA_MAC_VER_60 ... RTL_GIGA_MAC_VER_63:
+		r8168_mac_ocp_modify(tp, 0xc0ac, 0x1f80, 0);
+		break;
+	default:
+		break;
+	}
+}
+
 static void rtl_enable_exit_l1(struct rtl8169_private *tp)  {
 	/* Bits control which events trigger ASPM L1 exit:
@@ -2692,6 +2705,33 @@ static void rtl_hw_aspm_clkreq_enable(struct

rtl8169_private *tp, bool enable)

Quoted 3 lines
drivers/net/ethernet/realtek/r8169_main.c +0 -0
 	udelay(10);
 }
 
Quoted 14 lines

drivers/net/ethernet/realtek/r8169_main.c static void rtl_hw_aspm_clkreq_enable(struct rtl8169_private *tp, bool enable) · line 2718

Quoted 11 lines
drivers/net/ethernet/realtek/r8169_main.c +11 -0
+static void rtl_hw_aspm_l12_enable(struct rtl8169_private *tp, bool
+enable) {
+	/* Don't enable L1.2 in the chip if OS can't control ASPM */
+	if (enable && tp->aspm_manageable) {
+		r8168_mac_ocp_modify(tp, 0xe094, 0xff00, 0);
+		r8168_mac_ocp_modify(tp, 0xe092, 0x00ff, BIT(2));
+	} else {
+		r8168_mac_ocp_modify(tp, 0xe092, 0x00ff, 0);
+	}
+}
+

Register E094 bits 0..15 are cleared when enabling, but not touched on disabling. I this correct?

Quoted 4 lines

Register E094 bits 8...15 is a timer counter that is used to control when to disable ephy tx/rx. Set it to 0 means disable ephy tx/rx immediately when certain condition meet.
It has no meaning when register E092 bit 2 is set to 0.

Thanks for the explanation.

Quoted 4 lines
Quoted 2 lines

And for basically the same purpose we have the following function. "don't enable L1.2 in the chip" is not covered by ASPM_en in Config5?

Register E092 is like ASPM_en in Config5. But it controls L1 substate (L1.1/L1.2) enable status.

How is this handled for the RTL8168 chip versions supporting L1 sub-states (RTL8168h)? Is there a similar register or does Config5 ASPM_en control also the L1 substates on these chip versions?

Quoted 16 lines
Quoted 16 lines

static void rtl_hw_aspm_clkreq_enable(struct rtl8169_private *tp, bool

enable) {
	/* Don't enable ASPM in the chip if OS can't control ASPM */
	if (enable && tp->aspm_manageable) {
		RTL_W8(tp, Config5, RTL_R8(tp, Config5) | ASPM_en);
		RTL_W8(tp, Config2, RTL_R8(tp, Config2) | ClkReqEn);
	} else {
		RTL_W8(tp, Config2, RTL_R8(tp, Config2) & ~ClkReqEn);
		RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~ASPM_en);
	}

	udelay(10);
}

...

author
#8 lore raw
Quoted 105 lines · Hau
Quoted 94 lines
Quoted 80 lines · Chunhao Lin

drivers/net/ethernet/realtek/r8169_main.c static void rtl_wol_enable_rx(struct

Quoted 18 lines

This patch will enable RTL8125 ASPM L1.2 on the platforms that have tested RTL8125 with ASPM L1.2 enabled.
Register mac ocp 0xc0b2 will help to identify if RTL8125 has been tested on L1.2 enabled platform. If it is, this register will be set to 0xf. If not, this register will be default value 0.

---
 drivers/net/ethernet/realtek/r8169_main.c | 99
++++++++++++++++++-----
 1 file changed, 79 insertions(+), 20 deletions(-)
drivers/net/ethernet/realtek/r8169_main.c +0 -0
index 19e2621e0645..b1e013969d4c 100644
@@ -2238,21 +2238,6 @@ static void rtl_wol_enable_rx(struct

rtl8169_private *tp)

drivers/net/ethernet/realtek/r8169_main.c static void rtl_wol_enable_rx(struct · line 2238

Quoted 1 line
drivers/net/ethernet/realtek/r8169_main.c +0 -0
 			AcceptBroadcast | AcceptMulticast |

AcceptMyPhys); }

Quoted 18 lines
drivers/net/ethernet/realtek/r8169_main.c +0 -14
-static void rtl_prepare_power_down(struct rtl8169_private *tp) -{
-	if (tp->dash_type != RTL_DASH_NONE)
-		return;
-
-	if (tp->mac_version == RTL_GIGA_MAC_VER_32 ||
-	    tp->mac_version == RTL_GIGA_MAC_VER_33)
-		rtl_ephy_write(tp, 0x19, 0xff64);
-
-	if (device_may_wakeup(tp_to_dev(tp))) {
-		phy_speed_down(tp->phydev, false);
-		rtl_wol_enable_rx(tp);
-	}
-}
-
 static void rtl_init_rxcfg(struct rtl8169_private *tp)  {
 	switch (tp->mac_version) {
@@ -2650,6 +2635,34 @@ static void
Quoted 1 line

rtl_pcie_state_l2l3_disable(struct

rtl8169_private *tp)

drivers/net/ethernet/realtek/r8169_main.c static void rtl_hw_aspm_clkreq_enable(struct

Quoted 32 lines
drivers/net/ethernet/realtek/r8169_main.c +27 -0
 	RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Rdy_to_L23);  }
 
+static void rtl_disable_exit_l1(struct rtl8169_private *tp) {
+	/* Bits control which events trigger ASPM L1 exit:
+	 * Bit 12: rxdv
+	 * Bit 11: ltr_msg
+	 * Bit 10: txdma_poll
+	 * Bit  9: xadm
+	 * Bit  8: pktavi
+	 * Bit  7: txpla
+	 */
+	switch (tp->mac_version) {
+	case RTL_GIGA_MAC_VER_34 ... RTL_GIGA_MAC_VER_36:
+		rtl_eri_clear_bits(tp, 0xd4, 0x1f00);
+		break;
+	case RTL_GIGA_MAC_VER_37 ... RTL_GIGA_MAC_VER_38:
+		rtl_eri_clear_bits(tp, 0xd4, 0x0c00);
+		break;
+	case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_53:
+		rtl_eri_clear_bits(tp, 0xd4, 0x1f80);
+		break;
+	case RTL_GIGA_MAC_VER_60 ... RTL_GIGA_MAC_VER_63:
+		r8168_mac_ocp_modify(tp, 0xc0ac, 0x1f80, 0);
+		break;
+	default:
+		break;
+	}
+}
+
 static void rtl_enable_exit_l1(struct rtl8169_private *tp)  {
 	/* Bits control which events trigger ASPM L1 exit:
@@ -2692,6 +2705,33 @@ static void rtl_hw_aspm_clkreq_enable(struct

rtl8169_private *tp, bool enable)

Quoted 3 lines
drivers/net/ethernet/realtek/r8169_main.c +0 -0
 	udelay(10);
 }
 
Quoted 14 lines

drivers/net/ethernet/realtek/r8169_main.c static void rtl_hw_aspm_clkreq_enable(struct rtl8169_private *tp, bool enable) · line 2718

Quoted 11 lines
drivers/net/ethernet/realtek/r8169_main.c +11 -0
+static void rtl_hw_aspm_l12_enable(struct rtl8169_private *tp, bool
+enable) {
+	/* Don't enable L1.2 in the chip if OS can't control ASPM */
+	if (enable && tp->aspm_manageable) {
+		r8168_mac_ocp_modify(tp, 0xe094, 0xff00, 0);
+		r8168_mac_ocp_modify(tp, 0xe092, 0x00ff, BIT(2));
+	} else {
+		r8168_mac_ocp_modify(tp, 0xe092, 0x00ff, 0);
+	}
+}
+

Register E094 bits 0..15 are cleared when enabling, but not touched on disabling. I this correct?

Quoted 1 line

Register E094 bits 8...15 is a timer counter that is used to control when to

disable ephy tx/rx.

Quoted 1 line

Set it to 0 means disable ephy tx/rx immediately when certain condition

meet.

Quoted 2 lines

It has no meaning when register E092 bit 2 is set to 0.

Thanks for the explanation.

Quoted 2 lines
Quoted 2 lines

And for basically the same purpose we have the following function. "don't enable L1.2 in the chip" is not covered by ASPM_en in Config5?

Quoted 8 lines
Quoted 1 line

Register E092 is like ASPM_en in Config5. But it controls L1 substate

(L1.1/L1.2) enable status.

Quoted 1 line

How is this handled for the RTL8168 chip versions supporting L1 sub-states (RTL8168h)?
Is there a similar register or does Config5 ASPM_en control also the L1 substates on these chip versions?

You could apply the same setting on RTL8168H.

Quoted 19 lines
Quoted 13 lines
Quoted 13 lines

static void rtl_hw_aspm_clkreq_enable(struct rtl8169_private *tp, bool

enable) {
	/* Don't enable ASPM in the chip if OS can't control ASPM */
	if (enable && tp->aspm_manageable) {
		RTL_W8(tp, Config5, RTL_R8(tp, Config5) | ASPM_en);
		RTL_W8(tp, Config2, RTL_R8(tp, Config2) | ClkReqEn);
	} else {
		RTL_W8(tp, Config2, RTL_R8(tp, Config2) & ~ClkReqEn);
		RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~ASPM_en);
	}
Quoted 4 lines
Quoted 4 lines
	udelay(10);
}

...
------Please consider the environment before printing this e-mail.

maintainer
#9 lore raw
In reply to Chunhao Lin
Quoted 146 lines · Chunhao Lin

This patch will enable RTL8125 ASPM L1.2 on the platforms that have tested RTL8125 with ASPM L1.2 enabled.
Register mac ocp 0xc0b2 will help to identify if RTL8125 has been tested on L1.2 enabled platform. If it is, this register will be set to 0xf. If not, this register will be default value 0.

---
 drivers/net/ethernet/realtek/r8169_main.c | 99 ++++++++++++++++++-----
 1 file changed, 79 insertions(+), 20 deletions(-)
drivers/net/ethernet/realtek/r8169_main.c +72 -20
index 19e2621e0645..b1e013969d4c 100644
@@ -2238,21 +2238,6 @@ static void rtl_wol_enable_rx(struct rtl8169_private *tp)
 			AcceptBroadcast | AcceptMulticast | AcceptMyPhys);
 }
 
-static void rtl_prepare_power_down(struct rtl8169_private *tp)
-{
-	if (tp->dash_type != RTL_DASH_NONE)
-		return;
-
-	if (tp->mac_version == RTL_GIGA_MAC_VER_32 ||
-	    tp->mac_version == RTL_GIGA_MAC_VER_33)
-		rtl_ephy_write(tp, 0x19, 0xff64);
-
-	if (device_may_wakeup(tp_to_dev(tp))) {
-		phy_speed_down(tp->phydev, false);
-		rtl_wol_enable_rx(tp);
-	}
-}
-
 static void rtl_init_rxcfg(struct rtl8169_private *tp)
 {
 	switch (tp->mac_version) {
@@ -2650,6 +2635,34 @@ static void rtl_pcie_state_l2l3_disable(struct rtl8169_private *tp)
 	RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Rdy_to_L23);
 }
 
+static void rtl_disable_exit_l1(struct rtl8169_private *tp)
+{
+	/* Bits control which events trigger ASPM L1 exit:
+	 * Bit 12: rxdv
+	 * Bit 11: ltr_msg
+	 * Bit 10: txdma_poll
+	 * Bit  9: xadm
+	 * Bit  8: pktavi
+	 * Bit  7: txpla
+	 */
+	switch (tp->mac_version) {
+	case RTL_GIGA_MAC_VER_34 ... RTL_GIGA_MAC_VER_36:
+		rtl_eri_clear_bits(tp, 0xd4, 0x1f00);
+		break;
+	case RTL_GIGA_MAC_VER_37 ... RTL_GIGA_MAC_VER_38:
+		rtl_eri_clear_bits(tp, 0xd4, 0x0c00);
+		break;
+	case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_53:
+		rtl_eri_clear_bits(tp, 0xd4, 0x1f80);
+		break;
+	case RTL_GIGA_MAC_VER_60 ... RTL_GIGA_MAC_VER_63:
+		r8168_mac_ocp_modify(tp, 0xc0ac, 0x1f80, 0);
+		break;
+	default:
+		break;
+	}
+}
+
 static void rtl_enable_exit_l1(struct rtl8169_private *tp)
 {
 	/* Bits control which events trigger ASPM L1 exit:
@@ -2692,6 +2705,33 @@ static void rtl_hw_aspm_clkreq_enable(struct rtl8169_private *tp, bool enable)
 	udelay(10);
 }
 
+static void rtl_hw_aspm_l12_enable(struct rtl8169_private *tp, bool enable)
+{
+	/* Don't enable L1.2 in the chip if OS can't control ASPM */
+	if (enable && tp->aspm_manageable) {
+		r8168_mac_ocp_modify(tp, 0xe094, 0xff00, 0);
+		r8168_mac_ocp_modify(tp, 0xe092, 0x00ff, BIT(2));
+	} else {
+		r8168_mac_ocp_modify(tp, 0xe092, 0x00ff, 0);
+	}
+}
+
+static void rtl_prepare_power_down(struct rtl8169_private *tp)
+{
+	if (tp->dash_type != RTL_DASH_NONE)
+		return;
+
+	if (tp->mac_version == RTL_GIGA_MAC_VER_32 ||
+	    tp->mac_version == RTL_GIGA_MAC_VER_33)
+		rtl_ephy_write(tp, 0x19, 0xff64);
+
+	if (device_may_wakeup(tp_to_dev(tp))) {
+		rtl_disable_exit_l1(tp);
+		phy_speed_down(tp->phydev, false);
+		rtl_wol_enable_rx(tp);
+	}
+}
+
 static void rtl_set_fifo_size(struct rtl8169_private *tp, u16 rx_stat,
 			      u16 tx_stat, u16 rx_dyn, u16 tx_dyn)
 {
@@ -3675,6 +3715,7 @@ static void rtl_hw_start_8125b(struct rtl8169_private *tp)
 	rtl_ephy_init(tp, e_info_8125b);
 	rtl_hw_start_8125_common(tp);
 
+	rtl_hw_aspm_l12_enable(tp, true);
 	rtl_hw_aspm_clkreq_enable(tp, true);
 }
 
@@ -5255,6 +5296,20 @@ static void rtl_init_mac_address(struct rtl8169_private *tp)
 	rtl_rar_set(tp, mac_addr);
 }
 
+/* mac ocp 0xc0b2 will help to identify if RTL8125 has been tested
+ * on L1.2 enabled platform. If it is, this register will be set to 0xf.
+ * If not, this register will be default value 0.
+ */
+static bool rtl_platform_l12_enabled(struct rtl8169_private *tp)
+{
+	switch (tp->mac_version) {
+	case RTL_GIGA_MAC_VER_60 ... RTL_GIGA_MAC_VER_63:
+		return (r8168_mac_ocp_read(tp, 0xc0b2) & 0xf) ? true : false;
+	default:
+		return false;
+	}
+}
+
 static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 {
 	struct rtl8169_private *tp;
@@ -5333,11 +5388,15 @@ static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 	 * Chips from RTL8168h partially have issues with L1.2, but seem
 	 * to work fine with L1 and L1.1.
 	 */
-	if (tp->mac_version >= RTL_GIGA_MAC_VER_45)
-		rc = pci_disable_link_state(pdev, PCIE_LINK_STATE_L1_2);
-	else
-		rc = pci_disable_link_state(pdev, PCIE_LINK_STATE_L1);
-	tp->aspm_manageable = !rc;
+	if (!rtl_platform_l12_enabled(tp)) {
+		if (tp->mac_version >= RTL_GIGA_MAC_VER_45)

drivers/net/ethernet/realtek/r8169_main.c static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) · line 5402

Quoted 10 lines
drivers/net/ethernet/realtek/r8169_main.c +7 -0
+			rc = pci_disable_link_state(pdev, PCIE_LINK_STATE_L1_2);
+		else
+			rc = pci_disable_link_state(pdev, PCIE_LINK_STATE_L1);
+		tp->aspm_manageable = !rc;
+	} else {
+		tp->aspm_manageable = pcie_aspm_enabled(pdev);
+	}
 
 	tp->dash_type = rtl_check_dash(tp);
 

Hi Hau,

the following is a stripped-down version of the patch. Could you please check/test? If function rtl_disable_exit_l1() is actually needed, I'd prefer to add it in a separate patch (to facilitate bisecting).

 drivers/net/ethernet/realtek/r8169_main.c | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)
drivers/net/ethernet/realtek/r8169_main.c +21 -1
index ca95e9266..890a64245 100644
@@ -2684,7 +2684,15 @@ static void rtl_hw_aspm_clkreq_enable(struct rtl8169_private *tp, bool enable)
 	if (enable && tp->aspm_manageable) {
 		RTL_W8(tp, Config5, RTL_R8(tp, Config5) | ASPM_en);
 		RTL_W8(tp, Config2, RTL_R8(tp, Config2) | ClkReqEn);
+
+		if (tp->mac_version == RTL_GIGA_MAC_VER_63) {
+			r8168_mac_ocp_modify(tp, 0xe094, 0xff00, 0);
+			r8168_mac_ocp_modify(tp, 0xe092, 0x00ff, BIT(2));
+		}
 	} else {
+		if (tp->mac_version == RTL_GIGA_MAC_VER_63)
+			r8168_mac_ocp_modify(tp, 0xe092, 0x00ff, 0);
+
 		RTL_W8(tp, Config2, RTL_R8(tp, Config2) & ~ClkReqEn);
 		RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~ASPM_en);
 	}
@@ -5251,6 +5259,16 @@ static void rtl_init_mac_address(struct rtl8169_private *tp)
 	rtl_rar_set(tp, mac_addr);
 }
 
+/* register is set if system vendor successfully tested ASPM 1.2 */
+static bool rtl_aspm_is_safe(struct rtl8169_private *tp)
+{
+	if (tp->mac_version >= RTL_GIGA_MAC_VER_60 &&
+	    r8168_mac_ocp_read(tp, 0xc0b2) & 0xf)
+		return true;
+
+	return false;
+}
+
 static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 {
 	struct rtl8169_private *tp;
@@ -5329,7 +5347,9 @@ static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 	 * Chips from RTL8168h partially have issues with L1.2, but seem
 	 * to work fine with L1 and L1.1.
 	 */
-	if (tp->mac_version >= RTL_GIGA_MAC_VER_45)
+	if (rtl_aspm_is_safe(tp))
+		rc = 0;
+	else if (tp->mac_version >= RTL_GIGA_MAC_VER_45)
 		rc = pci_disable_link_state(pdev, PCIE_LINK_STATE_L1_2);
 	else
 		rc = pci_disable_link_state(pdev, PCIE_LINK_STATE_L1);
Signature · 1 line
2.35.0
author
#10 lore raw
Quoted 156 lines · Chunhao Lin

drivers/net/ethernet/realtek/r8169_main.c static void rtl_wol_enable_rx(struct

Quoted 18 lines

This patch will enable RTL8125 ASPM L1.2 on the platforms that have tested RTL8125 with ASPM L1.2 enabled.
Register mac ocp 0xc0b2 will help to identify if RTL8125 has been tested on L1.2 enabled platform. If it is, this register will be set to 0xf. If not, this register will be default value 0.

---
 drivers/net/ethernet/realtek/r8169_main.c | 99
++++++++++++++++++-----
 1 file changed, 79 insertions(+), 20 deletions(-)
drivers/net/ethernet/realtek/r8169_main.c +0 -0
index 19e2621e0645..b1e013969d4c 100644
@@ -2238,21 +2238,6 @@ static void rtl_wol_enable_rx(struct

rtl8169_private *tp)

drivers/net/ethernet/realtek/r8169_main.c static void rtl_wol_enable_rx(struct · line 2238

Quoted 1 line
drivers/net/ethernet/realtek/r8169_main.c +0 -0
 			AcceptBroadcast | AcceptMulticast |

AcceptMyPhys); }

drivers/net/ethernet/realtek/r8169_main.c static void rtl_pcie_state_l2l3_disable(struct

Quoted 18 lines
drivers/net/ethernet/realtek/r8169_main.c +0 -14
-static void rtl_prepare_power_down(struct rtl8169_private *tp) -{
-	if (tp->dash_type != RTL_DASH_NONE)
-		return;
-
-	if (tp->mac_version == RTL_GIGA_MAC_VER_32 ||
-	    tp->mac_version == RTL_GIGA_MAC_VER_33)
-		rtl_ephy_write(tp, 0x19, 0xff64);
-
-	if (device_may_wakeup(tp_to_dev(tp))) {
-		phy_speed_down(tp->phydev, false);
-		rtl_wol_enable_rx(tp);
-	}
-}
-
 static void rtl_init_rxcfg(struct rtl8169_private *tp)  {
 	switch (tp->mac_version) {
@@ -2650,6 +2635,34 @@ static void rtl_pcie_state_l2l3_disable(struct

rtl8169_private *tp)

drivers/net/ethernet/realtek/r8169_main.c static void rtl_hw_aspm_clkreq_enable(struct

Quoted 32 lines
drivers/net/ethernet/realtek/r8169_main.c +27 -0
 	RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Rdy_to_L23);  }
 
+static void rtl_disable_exit_l1(struct rtl8169_private *tp) {
+	/* Bits control which events trigger ASPM L1 exit:
+	 * Bit 12: rxdv
+	 * Bit 11: ltr_msg
+	 * Bit 10: txdma_poll
+	 * Bit  9: xadm
+	 * Bit  8: pktavi
+	 * Bit  7: txpla
+	 */
+	switch (tp->mac_version) {
+	case RTL_GIGA_MAC_VER_34 ... RTL_GIGA_MAC_VER_36:
+		rtl_eri_clear_bits(tp, 0xd4, 0x1f00);
+		break;
+	case RTL_GIGA_MAC_VER_37 ... RTL_GIGA_MAC_VER_38:
+		rtl_eri_clear_bits(tp, 0xd4, 0x0c00);
+		break;
+	case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_53:
+		rtl_eri_clear_bits(tp, 0xd4, 0x1f80);
+		break;
+	case RTL_GIGA_MAC_VER_60 ... RTL_GIGA_MAC_VER_63:
+		r8168_mac_ocp_modify(tp, 0xc0ac, 0x1f80, 0);
+		break;
+	default:
+		break;
+	}
+}
+
 static void rtl_enable_exit_l1(struct rtl8169_private *tp)  {
 	/* Bits control which events trigger ASPM L1 exit:
@@ -2692,6 +2705,33 @@ static void rtl_hw_aspm_clkreq_enable(struct

rtl8169_private *tp, bool enable)

Quoted 21 lines
drivers/net/ethernet/realtek/r8169_main.c +18 -0
 	udelay(10);
 }
 
+static void rtl_hw_aspm_l12_enable(struct rtl8169_private *tp, bool
+enable) {
+	/* Don't enable L1.2 in the chip if OS can't control ASPM */
+	if (enable && tp->aspm_manageable) {
+		r8168_mac_ocp_modify(tp, 0xe094, 0xff00, 0);
+		r8168_mac_ocp_modify(tp, 0xe092, 0x00ff, BIT(2));
+	} else {
+		r8168_mac_ocp_modify(tp, 0xe092, 0x00ff, 0);
+	}
+}
+
+static void rtl_prepare_power_down(struct rtl8169_private *tp) {
+	if (tp->dash_type != RTL_DASH_NONE)
+		return;
+
+	if (tp->mac_version == RTL_GIGA_MAC_VER_32 ||
+	    tp->mac_version == RTL_GIGA_MAC_VER_33)
+		rtl_ephy_write(tp, 0x19, 0xff64);

drivers/net/ethernet/realtek/r8169_main.c static void rtl_hw_aspm_clkreq_enable(struct · line 2735

Quoted 10 lines
drivers/net/ethernet/realtek/r8169_main.c +8 -0
+
+	if (device_may_wakeup(tp_to_dev(tp))) {
+		rtl_disable_exit_l1(tp);
+		phy_speed_down(tp->phydev, false);
+		rtl_wol_enable_rx(tp);
+	}
+}
+
 static void rtl_set_fifo_size(struct rtl8169_private *tp, u16 rx_stat,
 			      u16 tx_stat, u16 rx_dyn, u16 tx_dyn)  { @@ -

3675,6 +3715,7

drivers/net/ethernet/realtek/r8169_main.c static void rtl_init_mac_address(struct

Quoted 8 lines
drivers/net/ethernet/realtek/r8169_main.c +1 -0
 @@ static void rtl_hw_start_8125b(struct rtl8169_private *tp)
 	rtl_ephy_init(tp, e_info_8125b);
 	rtl_hw_start_8125_common(tp);
 
+	rtl_hw_aspm_l12_enable(tp, true);
 	rtl_hw_aspm_clkreq_enable(tp, true);  }
@@ -5255,6 +5296,20 @@ static void rtl_init_mac_address(struct

rtl8169_private *tp)

drivers/net/ethernet/realtek/r8169_main.c static int rtl_init_one(struct pci_dev *pdev,

Quoted 20 lines
drivers/net/ethernet/realtek/r8169_main.c +13 -0
 	rtl_rar_set(tp, mac_addr);
 }
 
+/* mac ocp 0xc0b2 will help to identify if RTL8125 has been tested
+ * on L1.2 enabled platform. If it is, this register will be set to 0xf.
+ * If not, this register will be default value 0.
+ */
+static bool rtl_platform_l12_enabled(struct rtl8169_private *tp) {
+	switch (tp->mac_version) {
+	case RTL_GIGA_MAC_VER_60 ... RTL_GIGA_MAC_VER_63:
+		return (r8168_mac_ocp_read(tp, 0xc0b2) & 0xf) ? true : false;
+	default:
+		return false;
+	}
+}
+
 static int rtl_init_one(struct pci_dev *pdev, const struct
 pci_device_id *ent)  {
 	struct rtl8169_private *tp;
@@ -5333,11 +5388,15 @@ static int rtl_init_one(struct pci_dev *pdev,

const struct pci_device_id *ent)

drivers/net/ethernet/realtek/r8169_main.c static int rtl_init_one(struct pci_dev *pdev, · line 5393

Quoted 11 lines
drivers/net/ethernet/realtek/r8169_main.c +3 -5
 	 * Chips from RTL8168h partially have issues with L1.2, but seem
 	 * to work fine with L1 and L1.1.
 	 */
-	if (tp->mac_version >= RTL_GIGA_MAC_VER_45)
-		rc = pci_disable_link_state(pdev, PCIE_LINK_STATE_L1_2);
-	else
-		rc = pci_disable_link_state(pdev, PCIE_LINK_STATE_L1);
-	tp->aspm_manageable = !rc;
+	if (!rtl_platform_l12_enabled(tp)) {
+		if (tp->mac_version >= RTL_GIGA_MAC_VER_45)
+			rc = pci_disable_link_state(pdev,

PCIE_LINK_STATE_L1_2);

drivers/net/ethernet/realtek/r8169_main.c static int rtl_init_one(struct pci_dev *pdev, · line 5395

Quoted 2 lines
drivers/net/ethernet/realtek/r8169_main.c +2 -0
+		else
+			rc = pci_disable_link_state(pdev,

PCIE_LINK_STATE_L1);

Quoted 5 lines
drivers/net/ethernet/realtek/r8169_main.c +4 -0
+		tp->aspm_manageable = !rc;
+	} else {
+		tp->aspm_manageable = pcie_aspm_enabled(pdev);
+	}
 
Quoted 7 lines

drivers/net/ethernet/realtek/r8169_main.c static int rtl_init_one(struct pci_dev *pdev, · line 5402

Quoted 2 lines
drivers/net/ethernet/realtek/r8169_main.c +0 -0
 	tp->dash_type = rtl_check_dash(tp);
 

Hi Hau,

the following is a stripped-down version of the patch. Could you please check/test?

This patch is ok.
L1 substate lock can apply for both rtl8125a.rtl8125b.

if (enable && tp->aspm_manageable) {
	RTL_W8(tp, Config5, RTL_R8(tp, Config5) | ASPM_en);
	RTL_W8(tp, Config2, RTL_R8(tp, Config2) | ClkReqEn);

	if (tp->mac_version >= RTL_GIGA_MAC_VER_60) {
		r8168_mac_ocp_modify(tp, 0xe094, 0xff00, 0);
		r8168_mac_ocp_modify(tp, 0xe092, 0x00ff, BIT(2));
	}
} else {
	if (tp->mac_version >= RTL_GIGA_MAC_VER_60)
		r8168_mac_ocp_modify(tp, 0xe092, 0x00ff, 0);

	RTL_W8(tp, Config2, RTL_R8(tp, Config2) & ~ClkReqEn);
	RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~ASPM_en);
}
Quoted 3 lines

If function rtl_disable_exit_l1() is actually needed, I'd prefer to add it in a separate patch (to facilitate bisecting).

If exit l1 mask is enabled, hardware will prone to exit l1. That will prevent hardware from entering l1 substate. So It needs to disable l1 exist mask when device go to d3 state for entering l1 substate..

Quoted 58 lines
 drivers/net/ethernet/realtek/r8169_main.c | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)
drivers/net/ethernet/realtek/r8169_main.c +8 -0
index ca95e9266..890a64245 100644
@@ -2684,7 +2684,15 @@ static void rtl_hw_aspm_clkreq_enable(struct
 rtl8169_private *tp, bool enable)
 	if (enable && tp->aspm_manageable) {
 		RTL_W8(tp, Config5, RTL_R8(tp, Config5) | ASPM_en);
 		RTL_W8(tp, Config2, RTL_R8(tp, Config2) | ClkReqEn);
+
+		if (tp->mac_version == RTL_GIGA_MAC_VER_63) {
+			r8168_mac_ocp_modify(tp, 0xe094, 0xff00, 0);
+			r8168_mac_ocp_modify(tp, 0xe092, 0x00ff, BIT(2));
+		}
 	} else {
+		if (tp->mac_version == RTL_GIGA_MAC_VER_63)
+			r8168_mac_ocp_modify(tp, 0xe092, 0x00ff, 0);
+
 		RTL_W8(tp, Config2, RTL_R8(tp, Config2) & ~ClkReqEn);
 		RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~ASPM_en);
drivers/net/ethernet/realtek/r8169_main.c +12 -1
 	}
@@ -5251,6 +5259,16 @@ static void rtl_init_mac_address(struct
 rtl8169_private *tp)
 	rtl_rar_set(tp, mac_addr);
 }
 
+/* register is set if system vendor successfully tested ASPM 1.2 */
+static bool rtl_aspm_is_safe(struct rtl8169_private *tp) {
+	if (tp->mac_version >= RTL_GIGA_MAC_VER_60 &&
+	    r8168_mac_ocp_read(tp, 0xc0b2) & 0xf)
+		return true;
+
+	return false;
+}
+
 static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)  {
 	struct rtl8169_private *tp;
@@ -5329,7 +5347,9 @@ static int rtl_init_one(struct pci_dev *pdev, const
 struct pci_device_id *ent)
 	 * Chips from RTL8168h partially have issues with L1.2, but seem
 	 * to work fine with L1 and L1.1.
 	 */
-	if (tp->mac_version >= RTL_GIGA_MAC_VER_45)
+	if (rtl_aspm_is_safe(tp))
+		rc = 0;
+	else if (tp->mac_version >= RTL_GIGA_MAC_VER_45)
 		rc = pci_disable_link_state(pdev, PCIE_LINK_STATE_L1_2);
 	else

rc = pci_disable_link_state(pdev, PCIE_LINK_STATE_L1);
--
2.35.0

------Please consider the environment before printing this e-mail.

maintainer
#11 lore raw
Quoted 181 lines · Hau
Quoted 156 lines · Chunhao Lin

drivers/net/ethernet/realtek/r8169_main.c static void rtl_wol_enable_rx(struct

Quoted 18 lines

This patch will enable RTL8125 ASPM L1.2 on the platforms that have tested RTL8125 with ASPM L1.2 enabled.
Register mac ocp 0xc0b2 will help to identify if RTL8125 has been tested on L1.2 enabled platform. If it is, this register will be set to 0xf. If not, this register will be default value 0.

---
 drivers/net/ethernet/realtek/r8169_main.c | 99
++++++++++++++++++-----
 1 file changed, 79 insertions(+), 20 deletions(-)
drivers/net/ethernet/realtek/r8169_main.c +0 -0
index 19e2621e0645..b1e013969d4c 100644
@@ -2238,21 +2238,6 @@ static void rtl_wol_enable_rx(struct

rtl8169_private *tp)

drivers/net/ethernet/realtek/r8169_main.c static void rtl_wol_enable_rx(struct · line 2238

Quoted 1 line
drivers/net/ethernet/realtek/r8169_main.c +0 -0
 			AcceptBroadcast | AcceptMulticast |

AcceptMyPhys); }

drivers/net/ethernet/realtek/r8169_main.c static void rtl_pcie_state_l2l3_disable(struct

Quoted 18 lines
drivers/net/ethernet/realtek/r8169_main.c +0 -14
-static void rtl_prepare_power_down(struct rtl8169_private *tp) -{
-	if (tp->dash_type != RTL_DASH_NONE)
-		return;
-
-	if (tp->mac_version == RTL_GIGA_MAC_VER_32 ||
-	    tp->mac_version == RTL_GIGA_MAC_VER_33)
-		rtl_ephy_write(tp, 0x19, 0xff64);
-
-	if (device_may_wakeup(tp_to_dev(tp))) {
-		phy_speed_down(tp->phydev, false);
-		rtl_wol_enable_rx(tp);
-	}
-}
-
 static void rtl_init_rxcfg(struct rtl8169_private *tp)  {
 	switch (tp->mac_version) {
@@ -2650,6 +2635,34 @@ static void rtl_pcie_state_l2l3_disable(struct

rtl8169_private *tp)

drivers/net/ethernet/realtek/r8169_main.c static void rtl_hw_aspm_clkreq_enable(struct

Quoted 32 lines
drivers/net/ethernet/realtek/r8169_main.c +27 -0
 	RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Rdy_to_L23);  }
 
+static void rtl_disable_exit_l1(struct rtl8169_private *tp) {
+	/* Bits control which events trigger ASPM L1 exit:
+	 * Bit 12: rxdv
+	 * Bit 11: ltr_msg
+	 * Bit 10: txdma_poll
+	 * Bit  9: xadm
+	 * Bit  8: pktavi
+	 * Bit  7: txpla
+	 */
+	switch (tp->mac_version) {
+	case RTL_GIGA_MAC_VER_34 ... RTL_GIGA_MAC_VER_36:
+		rtl_eri_clear_bits(tp, 0xd4, 0x1f00);
+		break;
+	case RTL_GIGA_MAC_VER_37 ... RTL_GIGA_MAC_VER_38:
+		rtl_eri_clear_bits(tp, 0xd4, 0x0c00);
+		break;
+	case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_53:
+		rtl_eri_clear_bits(tp, 0xd4, 0x1f80);
+		break;
+	case RTL_GIGA_MAC_VER_60 ... RTL_GIGA_MAC_VER_63:
+		r8168_mac_ocp_modify(tp, 0xc0ac, 0x1f80, 0);
+		break;
+	default:
+		break;
+	}
+}
+
 static void rtl_enable_exit_l1(struct rtl8169_private *tp)  {
 	/* Bits control which events trigger ASPM L1 exit:
@@ -2692,6 +2705,33 @@ static void rtl_hw_aspm_clkreq_enable(struct

rtl8169_private *tp, bool enable)

Quoted 21 lines
drivers/net/ethernet/realtek/r8169_main.c +18 -0
 	udelay(10);
 }
 
+static void rtl_hw_aspm_l12_enable(struct rtl8169_private *tp, bool
+enable) {
+	/* Don't enable L1.2 in the chip if OS can't control ASPM */
+	if (enable && tp->aspm_manageable) {
+		r8168_mac_ocp_modify(tp, 0xe094, 0xff00, 0);
+		r8168_mac_ocp_modify(tp, 0xe092, 0x00ff, BIT(2));
+	} else {
+		r8168_mac_ocp_modify(tp, 0xe092, 0x00ff, 0);
+	}
+}
+
+static void rtl_prepare_power_down(struct rtl8169_private *tp) {
+	if (tp->dash_type != RTL_DASH_NONE)
+		return;
+
+	if (tp->mac_version == RTL_GIGA_MAC_VER_32 ||
+	    tp->mac_version == RTL_GIGA_MAC_VER_33)
+		rtl_ephy_write(tp, 0x19, 0xff64);

drivers/net/ethernet/realtek/r8169_main.c static void rtl_hw_aspm_clkreq_enable(struct · line 2735

Quoted 10 lines
drivers/net/ethernet/realtek/r8169_main.c +8 -0
+
+	if (device_may_wakeup(tp_to_dev(tp))) {
+		rtl_disable_exit_l1(tp);
+		phy_speed_down(tp->phydev, false);
+		rtl_wol_enable_rx(tp);
+	}
+}
+
 static void rtl_set_fifo_size(struct rtl8169_private *tp, u16 rx_stat,
 			      u16 tx_stat, u16 rx_dyn, u16 tx_dyn)  { @@ -

3675,6 +3715,7

drivers/net/ethernet/realtek/r8169_main.c static void rtl_init_mac_address(struct

Quoted 8 lines
drivers/net/ethernet/realtek/r8169_main.c +1 -0
 @@ static void rtl_hw_start_8125b(struct rtl8169_private *tp)
 	rtl_ephy_init(tp, e_info_8125b);
 	rtl_hw_start_8125_common(tp);
 
+	rtl_hw_aspm_l12_enable(tp, true);
 	rtl_hw_aspm_clkreq_enable(tp, true);  }
@@ -5255,6 +5296,20 @@ static void rtl_init_mac_address(struct

rtl8169_private *tp)

drivers/net/ethernet/realtek/r8169_main.c static int rtl_init_one(struct pci_dev *pdev,

Quoted 20 lines
drivers/net/ethernet/realtek/r8169_main.c +13 -0
 	rtl_rar_set(tp, mac_addr);
 }
 
+/* mac ocp 0xc0b2 will help to identify if RTL8125 has been tested
+ * on L1.2 enabled platform. If it is, this register will be set to 0xf.
+ * If not, this register will be default value 0.
+ */
+static bool rtl_platform_l12_enabled(struct rtl8169_private *tp) {
+	switch (tp->mac_version) {
+	case RTL_GIGA_MAC_VER_60 ... RTL_GIGA_MAC_VER_63:
+		return (r8168_mac_ocp_read(tp, 0xc0b2) & 0xf) ? true : false;
+	default:
+		return false;
+	}
+}
+
 static int rtl_init_one(struct pci_dev *pdev, const struct
 pci_device_id *ent)  {
 	struct rtl8169_private *tp;
@@ -5333,11 +5388,15 @@ static int rtl_init_one(struct pci_dev *pdev,

const struct pci_device_id *ent)

drivers/net/ethernet/realtek/r8169_main.c static int rtl_init_one(struct pci_dev *pdev, · line 5393

Quoted 11 lines
drivers/net/ethernet/realtek/r8169_main.c +3 -5
 	 * Chips from RTL8168h partially have issues with L1.2, but seem
 	 * to work fine with L1 and L1.1.
 	 */
-	if (tp->mac_version >= RTL_GIGA_MAC_VER_45)
-		rc = pci_disable_link_state(pdev, PCIE_LINK_STATE_L1_2);
-	else
-		rc = pci_disable_link_state(pdev, PCIE_LINK_STATE_L1);
-	tp->aspm_manageable = !rc;
+	if (!rtl_platform_l12_enabled(tp)) {
+		if (tp->mac_version >= RTL_GIGA_MAC_VER_45)
+			rc = pci_disable_link_state(pdev,

PCIE_LINK_STATE_L1_2);

drivers/net/ethernet/realtek/r8169_main.c static int rtl_init_one(struct pci_dev *pdev, · line 5395

Quoted 2 lines
drivers/net/ethernet/realtek/r8169_main.c +2 -0
+		else
+			rc = pci_disable_link_state(pdev,

PCIE_LINK_STATE_L1);

Quoted 5 lines
drivers/net/ethernet/realtek/r8169_main.c +4 -0
+		tp->aspm_manageable = !rc;
+	} else {
+		tp->aspm_manageable = pcie_aspm_enabled(pdev);
+	}
 
Quoted 7 lines

drivers/net/ethernet/realtek/r8169_main.c static int rtl_init_one(struct pci_dev *pdev, · line 5402

Quoted 2 lines
drivers/net/ethernet/realtek/r8169_main.c +0 -0
 	tp->dash_type = rtl_check_dash(tp);
 

Hi Hau,

the following is a stripped-down version of the patch. Could you please check/test?

This patch is ok.
L1 substate lock can apply for both rtl8125a.rtl8125b.

if (enable && tp->aspm_manageable) {
	RTL_W8(tp, Config5, RTL_R8(tp, Config5) | ASPM_en);
	RTL_W8(tp, Config2, RTL_R8(tp, Config2) | ClkReqEn);

	if (tp->mac_version >= RTL_GIGA_MAC_VER_60) {
		r8168_mac_ocp_modify(tp, 0xe094, 0xff00, 0);
		r8168_mac_ocp_modify(tp, 0xe092, 0x00ff, BIT(2));
	}
} else {
	if (tp->mac_version >= RTL_GIGA_MAC_VER_60)
		r8168_mac_ocp_modify(tp, 0xe092, 0x00ff, 0);

	RTL_W8(tp, Config2, RTL_R8(tp, Config2) & ~ClkReqEn);
	RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~ASPM_en);
}
Quoted 7 lines
Quoted 3 lines

If function rtl_disable_exit_l1() is actually needed, I'd prefer to add it in a separate patch (to facilitate bisecting).

If exit l1 mask is enabled, hardware will prone to exit l1. That will prevent hardware from entering l1 substate. So It needs to disable l1 exist mask when device go to d3 state for entering l1 substate..

My understanding of PCI power management may be incomplete, but:
If a device goes to D3, then doesn't the bus go to L2/L3? L1 exit criteria would be irrelevant then.

author
#12 lore raw
Quoted 195 lines

-----Original Message-----
From: Heiner Kallweit [mailto:[email protected]]
Sent: Wednesday, January 26, 2022 9:47 PM
To: Hau <[email protected]>; [email protected]
Cc: nic_swsd <[email protected]>; [email protected]
Subject: Re: [PATCH net-next 1/1] r8169: enable RTL8125 ASPM L1.2

Quoted 185 lines · Hau
Quoted 158 lines · Chunhao Lin

drivers/net/ethernet/realtek/r8169_main.c static void rtl_wol_enable_rx(struct

Quoted 18 lines

This patch will enable RTL8125 ASPM L1.2 on the platforms that have tested RTL8125 with ASPM L1.2 enabled.
Register mac ocp 0xc0b2 will help to identify if RTL8125 has been tested on L1.2 enabled platform. If it is, this register will be set to 0xf. If not, this register will be default value 0.

---
 drivers/net/ethernet/realtek/r8169_main.c | 99
++++++++++++++++++-----
 1 file changed, 79 insertions(+), 20 deletions(-)
drivers/net/ethernet/realtek/r8169_main.c +0 -0
index 19e2621e0645..b1e013969d4c 100644
@@ -2238,21 +2238,6 @@ static void rtl_wol_enable_rx(struct

rtl8169_private *tp)

drivers/net/ethernet/realtek/r8169_main.c static void rtl_wol_enable_rx(struct · line 2238

Quoted 1 line
drivers/net/ethernet/realtek/r8169_main.c +0 -0
 			AcceptBroadcast | AcceptMulticast |

AcceptMyPhys); }

Quoted 18 lines
drivers/net/ethernet/realtek/r8169_main.c +0 -14
-static void rtl_prepare_power_down(struct rtl8169_private *tp) -{
-	if (tp->dash_type != RTL_DASH_NONE)
-		return;
-
-	if (tp->mac_version == RTL_GIGA_MAC_VER_32 ||
-	    tp->mac_version == RTL_GIGA_MAC_VER_33)
-		rtl_ephy_write(tp, 0x19, 0xff64);
-
-	if (device_may_wakeup(tp_to_dev(tp))) {
-		phy_speed_down(tp->phydev, false);
-		rtl_wol_enable_rx(tp);
-	}
-}
-
 static void rtl_init_rxcfg(struct rtl8169_private *tp)  {
 	switch (tp->mac_version) {
@@ -2650,6 +2635,34 @@ static void
Quoted 1 line

rtl_pcie_state_l2l3_disable(struct

rtl8169_private *tp)

drivers/net/ethernet/realtek/r8169_main.c static void rtl_hw_aspm_clkreq_enable(struct

Quoted 32 lines
drivers/net/ethernet/realtek/r8169_main.c +27 -0
 	RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Rdy_to_L23);  }
 
+static void rtl_disable_exit_l1(struct rtl8169_private *tp) {
+	/* Bits control which events trigger ASPM L1 exit:
+	 * Bit 12: rxdv
+	 * Bit 11: ltr_msg
+	 * Bit 10: txdma_poll
+	 * Bit  9: xadm
+	 * Bit  8: pktavi
+	 * Bit  7: txpla
+	 */
+	switch (tp->mac_version) {
+	case RTL_GIGA_MAC_VER_34 ... RTL_GIGA_MAC_VER_36:
+		rtl_eri_clear_bits(tp, 0xd4, 0x1f00);
+		break;
+	case RTL_GIGA_MAC_VER_37 ... RTL_GIGA_MAC_VER_38:
+		rtl_eri_clear_bits(tp, 0xd4, 0x0c00);
+		break;
+	case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_53:
+		rtl_eri_clear_bits(tp, 0xd4, 0x1f80);
+		break;
+	case RTL_GIGA_MAC_VER_60 ... RTL_GIGA_MAC_VER_63:
+		r8168_mac_ocp_modify(tp, 0xc0ac, 0x1f80, 0);
+		break;
+	default:
+		break;
+	}
+}
+
 static void rtl_enable_exit_l1(struct rtl8169_private *tp)  {
 	/* Bits control which events trigger ASPM L1 exit:
@@ -2692,6 +2705,33 @@ static void rtl_hw_aspm_clkreq_enable(struct

rtl8169_private *tp, bool enable)

Quoted 21 lines
drivers/net/ethernet/realtek/r8169_main.c +18 -0
 	udelay(10);
 }
 
+static void rtl_hw_aspm_l12_enable(struct rtl8169_private *tp, bool
+enable) {
+	/* Don't enable L1.2 in the chip if OS can't control ASPM */
+	if (enable && tp->aspm_manageable) {
+		r8168_mac_ocp_modify(tp, 0xe094, 0xff00, 0);
+		r8168_mac_ocp_modify(tp, 0xe092, 0x00ff, BIT(2));
+	} else {
+		r8168_mac_ocp_modify(tp, 0xe092, 0x00ff, 0);
+	}
+}
+
+static void rtl_prepare_power_down(struct rtl8169_private *tp) {
+	if (tp->dash_type != RTL_DASH_NONE)
+		return;
+
+	if (tp->mac_version == RTL_GIGA_MAC_VER_32 ||
+	    tp->mac_version == RTL_GIGA_MAC_VER_33)
+		rtl_ephy_write(tp, 0x19, 0xff64);

drivers/net/ethernet/realtek/r8169_main.c static void rtl_hw_aspm_clkreq_enable(struct · line 2735

Quoted 10 lines
drivers/net/ethernet/realtek/r8169_main.c +8 -0
+
+	if (device_may_wakeup(tp_to_dev(tp))) {
+		rtl_disable_exit_l1(tp);
+		phy_speed_down(tp->phydev, false);
+		rtl_wol_enable_rx(tp);
+	}
+}
+
 static void rtl_set_fifo_size(struct rtl8169_private *tp, u16 rx_stat,
 			      u16 tx_stat, u16 rx_dyn, u16 tx_dyn)  { @@ -

3675,6 +3715,7

drivers/net/ethernet/realtek/r8169_main.c static void rtl_init_mac_address(struct

Quoted 8 lines
drivers/net/ethernet/realtek/r8169_main.c +1 -0
 @@ static void rtl_hw_start_8125b(struct rtl8169_private *tp)
 	rtl_ephy_init(tp, e_info_8125b);
 	rtl_hw_start_8125_common(tp);
 
+	rtl_hw_aspm_l12_enable(tp, true);
 	rtl_hw_aspm_clkreq_enable(tp, true);  }
@@ -5255,6 +5296,20 @@ static void rtl_init_mac_address(struct

rtl8169_private *tp)

Quoted 20 lines
drivers/net/ethernet/realtek/r8169_main.c +13 -0
 	rtl_rar_set(tp, mac_addr);
 }
 
+/* mac ocp 0xc0b2 will help to identify if RTL8125 has been tested
+ * on L1.2 enabled platform. If it is, this register will be set to 0xf.
+ * If not, this register will be default value 0.
+ */
+static bool rtl_platform_l12_enabled(struct rtl8169_private *tp) {
+	switch (tp->mac_version) {
+	case RTL_GIGA_MAC_VER_60 ... RTL_GIGA_MAC_VER_63:
+		return (r8168_mac_ocp_read(tp, 0xc0b2) & 0xf) ? true : false;
+	default:
+		return false;
+	}
+}
+
 static int rtl_init_one(struct pci_dev *pdev, const struct
 pci_device_id *ent)  {
 	struct rtl8169_private *tp;

drivers/net/ethernet/realtek/r8169_main.c static int rtl_init_one(struct pci_dev · line 5388

Quoted 1 line
drivers/net/ethernet/realtek/r8169_main.c +0 -0
@@ -5333,11 +5388,15 @@ static int rtl_init_one(struct pci_dev
 *pdev,

const struct pci_device_id *ent)

drivers/net/ethernet/realtek/r8169_main.c static int rtl_init_one(struct pci_dev · line 5394

Quoted 11 lines
drivers/net/ethernet/realtek/r8169_main.c +3 -5
 	 * Chips from RTL8168h partially have issues with L1.2, but seem
 	 * to work fine with L1 and L1.1.
 	 */
-	if (tp->mac_version >= RTL_GIGA_MAC_VER_45)
-		rc = pci_disable_link_state(pdev, PCIE_LINK_STATE_L1_2);
-	else
-		rc = pci_disable_link_state(pdev, PCIE_LINK_STATE_L1);
-	tp->aspm_manageable = !rc;
+	if (!rtl_platform_l12_enabled(tp)) {
+		if (tp->mac_version >= RTL_GIGA_MAC_VER_45)
+			rc = pci_disable_link_state(pdev,

PCIE_LINK_STATE_L1_2);

drivers/net/ethernet/realtek/r8169_main.c static int rtl_init_one(struct pci_dev · line 5396

Quoted 2 lines
drivers/net/ethernet/realtek/r8169_main.c +2 -0
+		else
+			rc = pci_disable_link_state(pdev,

PCIE_LINK_STATE_L1);

Quoted 5 lines
drivers/net/ethernet/realtek/r8169_main.c +4 -0
+		tp->aspm_manageable = !rc;
+	} else {
+		tp->aspm_manageable = pcie_aspm_enabled(pdev);
+	}
 
Quoted 7 lines

drivers/net/ethernet/realtek/r8169_main.c static int rtl_init_one(struct pci_dev · line 5402

Quoted 2 lines
drivers/net/ethernet/realtek/r8169_main.c +0 -0
 	tp->dash_type = rtl_check_dash(tp);

Hi Hau,

the following is a stripped-down version of the patch. Could you please check/test?

This patch is ok.
L1 substate lock can apply for both rtl8125a.rtl8125b.

if (enable && tp->aspm_manageable) {
	RTL_W8(tp, Config5, RTL_R8(tp, Config5) | ASPM_en);
	RTL_W8(tp, Config2, RTL_R8(tp, Config2) | ClkReqEn);

	if (tp->mac_version >= RTL_GIGA_MAC_VER_60) {
		r8168_mac_ocp_modify(tp, 0xe094, 0xff00, 0);
		r8168_mac_ocp_modify(tp, 0xe092, 0x00ff, BIT(2));
	}
} else {
	if (tp->mac_version >= RTL_GIGA_MAC_VER_60)
		r8168_mac_ocp_modify(tp, 0xe092, 0x00ff, 0);

	RTL_W8(tp, Config2, RTL_R8(tp, Config2) & ~ClkReqEn);
	RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~ASPM_en); }
Quoted 3 lines

If function rtl_disable_exit_l1() is actually needed, I'd prefer to add it in a separate patch (to facilitate bisecting).

Quoted 7 lines
Quoted 4 lines

If exit l1 mask is enabled, hardware will prone to exit l1. That will prevent hardware from entering l1 substate. So It needs to disable l1 exist mask when device go to d3 state for entering l1 substate..

My understanding of PCI power management may be incomplete, but:
If a device goes to D3, then doesn't the bus go to L2/L3? L1 exit criteria would be irrelevant then.

Your understanding is correct.
D3 is divided to two substate, D3hot and D3cold. D3cold will enter L2/L3. D3hot may enter L1 or L2/L3 ready. In D3hot case, enable exit l1 mask will prevent hardware from entering PM L1. That is our hardware issue. So we disable exit l1 mask before hardware enter D3.

Quoted 1 line

------Please consider the environment before printing this e-mail.

maintainer
#13 lore raw
Quoted 199 lines · Hau
Quoted 199 lines

-----Original Message-----
From: Heiner Kallweit [mailto:[email protected]]
Sent: Wednesday, January 26, 2022 9:47 PM
To: Hau <[email protected]>; [email protected]
Cc: nic_swsd <[email protected]>; [email protected]
Subject: Re: [PATCH net-next 1/1] r8169: enable RTL8125 ASPM L1.2

Quoted 189 lines · Hau
Quoted 158 lines · Chunhao Lin

drivers/net/ethernet/realtek/r8169_main.c static void rtl_wol_enable_rx(struct

Quoted 18 lines

This patch will enable RTL8125 ASPM L1.2 on the platforms that have tested RTL8125 with ASPM L1.2 enabled.
Register mac ocp 0xc0b2 will help to identify if RTL8125 has been tested on L1.2 enabled platform. If it is, this register will be set to 0xf. If not, this register will be default value 0.

---
 drivers/net/ethernet/realtek/r8169_main.c | 99
++++++++++++++++++-----
 1 file changed, 79 insertions(+), 20 deletions(-)
drivers/net/ethernet/realtek/r8169_main.c +0 -0
index 19e2621e0645..b1e013969d4c 100644
@@ -2238,21 +2238,6 @@ static void rtl_wol_enable_rx(struct

rtl8169_private *tp)

drivers/net/ethernet/realtek/r8169_main.c static void rtl_wol_enable_rx(struct · line 2238

Quoted 1 line
drivers/net/ethernet/realtek/r8169_main.c +0 -0
 			AcceptBroadcast | AcceptMulticast |

AcceptMyPhys); }

Quoted 18 lines
drivers/net/ethernet/realtek/r8169_main.c +0 -14
-static void rtl_prepare_power_down(struct rtl8169_private *tp) -{
-	if (tp->dash_type != RTL_DASH_NONE)
-		return;
-
-	if (tp->mac_version == RTL_GIGA_MAC_VER_32 ||
-	    tp->mac_version == RTL_GIGA_MAC_VER_33)
-		rtl_ephy_write(tp, 0x19, 0xff64);
-
-	if (device_may_wakeup(tp_to_dev(tp))) {
-		phy_speed_down(tp->phydev, false);
-		rtl_wol_enable_rx(tp);
-	}
-}
-
 static void rtl_init_rxcfg(struct rtl8169_private *tp)  {
 	switch (tp->mac_version) {
@@ -2650,6 +2635,34 @@ static void
Quoted 1 line

rtl_pcie_state_l2l3_disable(struct

rtl8169_private *tp)

drivers/net/ethernet/realtek/r8169_main.c static void rtl_hw_aspm_clkreq_enable(struct

Quoted 32 lines
drivers/net/ethernet/realtek/r8169_main.c +27 -0
 	RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Rdy_to_L23);  }
 
+static void rtl_disable_exit_l1(struct rtl8169_private *tp) {
+	/* Bits control which events trigger ASPM L1 exit:
+	 * Bit 12: rxdv
+	 * Bit 11: ltr_msg
+	 * Bit 10: txdma_poll
+	 * Bit  9: xadm
+	 * Bit  8: pktavi
+	 * Bit  7: txpla
+	 */
+	switch (tp->mac_version) {
+	case RTL_GIGA_MAC_VER_34 ... RTL_GIGA_MAC_VER_36:
+		rtl_eri_clear_bits(tp, 0xd4, 0x1f00);
+		break;
+	case RTL_GIGA_MAC_VER_37 ... RTL_GIGA_MAC_VER_38:
+		rtl_eri_clear_bits(tp, 0xd4, 0x0c00);
+		break;
+	case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_53:
+		rtl_eri_clear_bits(tp, 0xd4, 0x1f80);
+		break;
+	case RTL_GIGA_MAC_VER_60 ... RTL_GIGA_MAC_VER_63:
+		r8168_mac_ocp_modify(tp, 0xc0ac, 0x1f80, 0);
+		break;
+	default:
+		break;
+	}
+}
+
 static void rtl_enable_exit_l1(struct rtl8169_private *tp)  {
 	/* Bits control which events trigger ASPM L1 exit:
@@ -2692,6 +2705,33 @@ static void rtl_hw_aspm_clkreq_enable(struct

rtl8169_private *tp, bool enable)

Quoted 21 lines
drivers/net/ethernet/realtek/r8169_main.c +18 -0
 	udelay(10);
 }
 
+static void rtl_hw_aspm_l12_enable(struct rtl8169_private *tp, bool
+enable) {
+	/* Don't enable L1.2 in the chip if OS can't control ASPM */
+	if (enable && tp->aspm_manageable) {
+		r8168_mac_ocp_modify(tp, 0xe094, 0xff00, 0);
+		r8168_mac_ocp_modify(tp, 0xe092, 0x00ff, BIT(2));
+	} else {
+		r8168_mac_ocp_modify(tp, 0xe092, 0x00ff, 0);
+	}
+}
+
+static void rtl_prepare_power_down(struct rtl8169_private *tp) {
+	if (tp->dash_type != RTL_DASH_NONE)
+		return;
+
+	if (tp->mac_version == RTL_GIGA_MAC_VER_32 ||
+	    tp->mac_version == RTL_GIGA_MAC_VER_33)
+		rtl_ephy_write(tp, 0x19, 0xff64);

drivers/net/ethernet/realtek/r8169_main.c static void rtl_hw_aspm_clkreq_enable(struct · line 2735

Quoted 10 lines
drivers/net/ethernet/realtek/r8169_main.c +8 -0
+
+	if (device_may_wakeup(tp_to_dev(tp))) {
+		rtl_disable_exit_l1(tp);
+		phy_speed_down(tp->phydev, false);
+		rtl_wol_enable_rx(tp);
+	}
+}
+
 static void rtl_set_fifo_size(struct rtl8169_private *tp, u16 rx_stat,
 			      u16 tx_stat, u16 rx_dyn, u16 tx_dyn)  { @@ -

3675,6 +3715,7

drivers/net/ethernet/realtek/r8169_main.c static void rtl_init_mac_address(struct

Quoted 8 lines
drivers/net/ethernet/realtek/r8169_main.c +1 -0
 @@ static void rtl_hw_start_8125b(struct rtl8169_private *tp)
 	rtl_ephy_init(tp, e_info_8125b);
 	rtl_hw_start_8125_common(tp);
 
+	rtl_hw_aspm_l12_enable(tp, true);
 	rtl_hw_aspm_clkreq_enable(tp, true);  }
@@ -5255,6 +5296,20 @@ static void rtl_init_mac_address(struct

rtl8169_private *tp)

Quoted 20 lines
drivers/net/ethernet/realtek/r8169_main.c +13 -0
 	rtl_rar_set(tp, mac_addr);
 }
 
+/* mac ocp 0xc0b2 will help to identify if RTL8125 has been tested
+ * on L1.2 enabled platform. If it is, this register will be set to 0xf.
+ * If not, this register will be default value 0.
+ */
+static bool rtl_platform_l12_enabled(struct rtl8169_private *tp) {
+	switch (tp->mac_version) {
+	case RTL_GIGA_MAC_VER_60 ... RTL_GIGA_MAC_VER_63:
+		return (r8168_mac_ocp_read(tp, 0xc0b2) & 0xf) ? true : false;
+	default:
+		return false;
+	}
+}
+
 static int rtl_init_one(struct pci_dev *pdev, const struct
 pci_device_id *ent)  {
 	struct rtl8169_private *tp;

drivers/net/ethernet/realtek/r8169_main.c static int rtl_init_one(struct pci_dev · line 5388

Quoted 1 line
drivers/net/ethernet/realtek/r8169_main.c +0 -0
@@ -5333,11 +5388,15 @@ static int rtl_init_one(struct pci_dev
 *pdev,

const struct pci_device_id *ent)

drivers/net/ethernet/realtek/r8169_main.c static int rtl_init_one(struct pci_dev · line 5394

Quoted 11 lines
drivers/net/ethernet/realtek/r8169_main.c +3 -5
 	 * Chips from RTL8168h partially have issues with L1.2, but seem
 	 * to work fine with L1 and L1.1.
 	 */
-	if (tp->mac_version >= RTL_GIGA_MAC_VER_45)
-		rc = pci_disable_link_state(pdev, PCIE_LINK_STATE_L1_2);
-	else
-		rc = pci_disable_link_state(pdev, PCIE_LINK_STATE_L1);
-	tp->aspm_manageable = !rc;
+	if (!rtl_platform_l12_enabled(tp)) {
+		if (tp->mac_version >= RTL_GIGA_MAC_VER_45)
+			rc = pci_disable_link_state(pdev,

PCIE_LINK_STATE_L1_2);

drivers/net/ethernet/realtek/r8169_main.c static int rtl_init_one(struct pci_dev · line 5396

Quoted 2 lines
drivers/net/ethernet/realtek/r8169_main.c +2 -0
+		else
+			rc = pci_disable_link_state(pdev,

PCIE_LINK_STATE_L1);

Quoted 5 lines
drivers/net/ethernet/realtek/r8169_main.c +4 -0
+		tp->aspm_manageable = !rc;
+	} else {
+		tp->aspm_manageable = pcie_aspm_enabled(pdev);
+	}
 
Quoted 7 lines

drivers/net/ethernet/realtek/r8169_main.c static int rtl_init_one(struct pci_dev · line 5402

Quoted 2 lines
drivers/net/ethernet/realtek/r8169_main.c +0 -0
 	tp->dash_type = rtl_check_dash(tp);

Hi Hau,

the following is a stripped-down version of the patch. Could you please check/test?

This patch is ok.
L1 substate lock can apply for both rtl8125a.rtl8125b.

if (enable && tp->aspm_manageable) {
	RTL_W8(tp, Config5, RTL_R8(tp, Config5) | ASPM_en);
	RTL_W8(tp, Config2, RTL_R8(tp, Config2) | ClkReqEn);

	if (tp->mac_version >= RTL_GIGA_MAC_VER_60) {
		r8168_mac_ocp_modify(tp, 0xe094, 0xff00, 0);
		r8168_mac_ocp_modify(tp, 0xe092, 0x00ff, BIT(2));
	}
} else {
	if (tp->mac_version >= RTL_GIGA_MAC_VER_60)
		r8168_mac_ocp_modify(tp, 0xe092, 0x00ff, 0);

	RTL_W8(tp, Config2, RTL_R8(tp, Config2) & ~ClkReqEn);
	RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~ASPM_en); }
Quoted 3 lines

If function rtl_disable_exit_l1() is actually needed, I'd prefer to add it in a separate patch (to facilitate bisecting).

If exit l1 mask is enabled, hardware will prone to exit l1. That will prevent hardware from entering l1 substate. So It needs to disable l1 exist mask when device go to d3 state for entering l1 substate..

Quoted 9 lines
Quoted 3 lines

My understanding of PCI power management may be incomplete, but:
If a device goes to D3, then doesn't the bus go to L2/L3? L1 exit criteria would be irrelevant then.

Your understanding is correct.
D3 is divided to two substate, D3hot and D3cold. D3cold will enter L2/L3. D3hot may enter L1 or L2/L3 ready. In D3hot case, enable exit l1 mask will prevent hardware from entering PM L1. That is our hardware issue. So we disable exit l1 mask before hardware enter D3.

Thanks! One, hopefully last, question:
Are you aware of any boards/systems setting this "L1.2 was tested and is safe" flag? Then this could be mentioned in the commit description.

author
#14 lore raw
Quoted 215 lines · Hau
Quoted 131 lines
Quoted 131 lines

-----Original Message-----
From: Heiner Kallweit [mailto:[email protected]]
Sent: Wednesday, January 26, 2022 9:47 PM
To: Hau <[email protected]>; [email protected]
Cc: nic_swsd <[email protected]>; [email protected]
Subject: Re: [PATCH net-next 1/1] r8169: enable RTL8125 ASPM L1.2

Quoted 121 lines · Hau
Quoted 121 lines · Chunhao Lin

drivers/net/ethernet/realtek/r8169_main.c static void rtl_wol_enable_rx(struct

Quoted 18 lines

This patch will enable RTL8125 ASPM L1.2 on the platforms that have tested RTL8125 with ASPM L1.2 enabled.
Register mac ocp 0xc0b2 will help to identify if RTL8125 has been tested on L1.2 enabled platform. If it is, this register will be set to 0xf. If not, this register will be default value 0.

---
 drivers/net/ethernet/realtek/r8169_main.c | 99
++++++++++++++++++-----
 1 file changed, 79 insertions(+), 20 deletions(-)
drivers/net/ethernet/realtek/r8169_main.c +0 -0
index 19e2621e0645..b1e013969d4c 100644
@@ -2238,21 +2238,6 @@ static void rtl_wol_enable_rx(struct

rtl8169_private *tp)

drivers/net/ethernet/realtek/r8169_main.c static void rtl_wol_enable_rx(struct · line 2238

Quoted 1 line
drivers/net/ethernet/realtek/r8169_main.c +0 -0
 			AcceptBroadcast | AcceptMulticast |

AcceptMyPhys); }

Quoted 18 lines
drivers/net/ethernet/realtek/r8169_main.c +0 -14
-static void rtl_prepare_power_down(struct rtl8169_private *tp) -{
-	if (tp->dash_type != RTL_DASH_NONE)
-		return;
-
-	if (tp->mac_version == RTL_GIGA_MAC_VER_32 ||
-	    tp->mac_version == RTL_GIGA_MAC_VER_33)
-		rtl_ephy_write(tp, 0x19, 0xff64);
-
-	if (device_may_wakeup(tp_to_dev(tp))) {
-		phy_speed_down(tp->phydev, false);
-		rtl_wol_enable_rx(tp);
-	}
-}
-
 static void rtl_init_rxcfg(struct rtl8169_private *tp)  {
 	switch (tp->mac_version) {
@@ -2650,6 +2635,34 @@ static void
Quoted 1 line

rtl_pcie_state_l2l3_disable(struct

rtl8169_private *tp)

Quoted 32 lines
drivers/net/ethernet/realtek/r8169_main.c +27 -0
 	RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Rdy_to_L23);  }
 
+static void rtl_disable_exit_l1(struct rtl8169_private *tp) {
+	/* Bits control which events trigger ASPM L1 exit:
+	 * Bit 12: rxdv
+	 * Bit 11: ltr_msg
+	 * Bit 10: txdma_poll
+	 * Bit  9: xadm
+	 * Bit  8: pktavi
+	 * Bit  7: txpla
+	 */
+	switch (tp->mac_version) {
+	case RTL_GIGA_MAC_VER_34 ... RTL_GIGA_MAC_VER_36:
+		rtl_eri_clear_bits(tp, 0xd4, 0x1f00);
+		break;
+	case RTL_GIGA_MAC_VER_37 ... RTL_GIGA_MAC_VER_38:
+		rtl_eri_clear_bits(tp, 0xd4, 0x0c00);
+		break;
+	case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_53:
+		rtl_eri_clear_bits(tp, 0xd4, 0x1f80);
+		break;
+	case RTL_GIGA_MAC_VER_60 ... RTL_GIGA_MAC_VER_63:
+		r8168_mac_ocp_modify(tp, 0xc0ac, 0x1f80, 0);
+		break;
+	default:
+		break;
+	}
+}
+
 static void rtl_enable_exit_l1(struct rtl8169_private *tp)  {
 	/* Bits control which events trigger ASPM L1 exit:
@@ -2692,6 +2705,33 @@ static void
Quoted 1 line

rtl_hw_aspm_clkreq_enable(struct

rtl8169_private *tp, bool enable)

Quoted 22 lines
drivers/net/ethernet/realtek/r8169_main.c +19 -0
 	udelay(10);
 }
 
+static void rtl_hw_aspm_l12_enable(struct rtl8169_private *tp,
+bool
+enable) {
+	/* Don't enable L1.2 in the chip if OS can't control ASPM */
+	if (enable && tp->aspm_manageable) {
+		r8168_mac_ocp_modify(tp, 0xe094, 0xff00, 0);
+		r8168_mac_ocp_modify(tp, 0xe092, 0x00ff, BIT(2));
+	} else {
+		r8168_mac_ocp_modify(tp, 0xe092, 0x00ff, 0);
+	}
+}
+
+static void rtl_prepare_power_down(struct rtl8169_private *tp) {
+	if (tp->dash_type != RTL_DASH_NONE)
+		return;
+
+	if (tp->mac_version == RTL_GIGA_MAC_VER_32 ||
+	    tp->mac_version == RTL_GIGA_MAC_VER_33)
+		rtl_ephy_write(tp, 0x19, 0xff64);

drivers/net/ethernet/realtek/r8169_main.c

Quoted 10 lines
drivers/net/ethernet/realtek/r8169_main.c +8 -0
+
+	if (device_may_wakeup(tp_to_dev(tp))) {
+		rtl_disable_exit_l1(tp);
+		phy_speed_down(tp->phydev, false);
+		rtl_wol_enable_rx(tp);
+	}
+}
+
 static void rtl_set_fifo_size(struct rtl8169_private *tp, u16 rx_stat,
 			      u16 tx_stat, u16 rx_dyn, u16 tx_dyn)  { @@ -

3675,6 +3715,7

drivers/net/ethernet/realtek/r8169_main.c static void rtl_init_mac_address(struct

Quoted 8 lines

@@ static void rtl_hw_start_8125b(struct rtl8169_private *tp)

drivers/net/ethernet/realtek/r8169_main.c +1 -0
 	rtl_ephy_init(tp, e_info_8125b);
 	rtl_hw_start_8125_common(tp);
 
+	rtl_hw_aspm_l12_enable(tp, true);
 	rtl_hw_aspm_clkreq_enable(tp, true);  }
@@ -5255,6 +5296,20 @@ static void rtl_init_mac_address(struct

rtl8169_private *tp)

Quoted 3 lines
drivers/net/ethernet/realtek/r8169_main.c +0 -0
 	rtl_rar_set(tp, mac_addr);
 }
 
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

drivers/net/ethernet/realtek/r8169_main.c static void rtl_init_mac_address(struct · line 5307

Quoted 9 lines
drivers/net/ethernet/realtek/r8169_main.c +9 -0
+/* mac ocp 0xc0b2 will help to identify if RTL8125 has been
+tested
+ * on L1.2 enabled platform. If it is, this register will be set to 0xf.
+ * If not, this register will be default value 0.
+ */
+static bool rtl_platform_l12_enabled(struct rtl8169_private *tp) {
+	switch (tp->mac_version) {
+	case RTL_GIGA_MAC_VER_60 ... RTL_GIGA_MAC_VER_63:
+		return (r8168_mac_ocp_read(tp, 0xc0b2) & 0xf) ?

true : false;

Quoted 62 lines
Quoted 62 lines
Quoted 62 lines
Quoted 31 lines

drivers/net/ethernet/realtek/r8169_main.c static int rtl_init_one(struct pci_dev · line 5388

Quoted 10 lines
drivers/net/ethernet/realtek/r8169_main.c +5 -0
+	default:
+		return false;
+	}
+}
+
 static int rtl_init_one(struct pci_dev *pdev, const struct
 pci_device_id *ent)  {
 	struct rtl8169_private *tp;
@@ -5333,11 +5388,15 @@ static int rtl_init_one(struct pci_dev
 *pdev,

const struct pci_device_id *ent)

drivers/net/ethernet/realtek/r8169_main.c static int rtl_init_one(struct pci_dev · line 5394

Quoted 11 lines
drivers/net/ethernet/realtek/r8169_main.c +3 -5
 	 * Chips from RTL8168h partially have issues with L1.2, but seem
 	 * to work fine with L1 and L1.1.
 	 */
-	if (tp->mac_version >= RTL_GIGA_MAC_VER_45)
-		rc = pci_disable_link_state(pdev, PCIE_LINK_STATE_L1_2);
-	else
-		rc = pci_disable_link_state(pdev, PCIE_LINK_STATE_L1);
-	tp->aspm_manageable = !rc;
+	if (!rtl_platform_l12_enabled(tp)) {
+		if (tp->mac_version >= RTL_GIGA_MAC_VER_45)
+			rc = pci_disable_link_state(pdev,

PCIE_LINK_STATE_L1_2);

drivers/net/ethernet/realtek/r8169_main.c static int rtl_init_one(struct pci_dev · line 5396

Quoted 2 lines
drivers/net/ethernet/realtek/r8169_main.c +2 -0
+		else
+			rc = pci_disable_link_state(pdev,

PCIE_LINK_STATE_L1);

Quoted 5 lines
drivers/net/ethernet/realtek/r8169_main.c +4 -0
+		tp->aspm_manageable = !rc;
+	} else {
+		tp->aspm_manageable = pcie_aspm_enabled(pdev);
+	}
 
Quoted 7 lines

drivers/net/ethernet/realtek/r8169_main.c static int rtl_init_one(struct pci_dev · line 5402

Quoted 2 lines
drivers/net/ethernet/realtek/r8169_main.c +0 -0
 	tp->dash_type = rtl_check_dash(tp);

Hi Hau,

the following is a stripped-down version of the patch. Could you please check/test?

This patch is ok.
L1 substate lock can apply for both rtl8125a.rtl8125b.

if (enable && tp->aspm_manageable) {
	RTL_W8(tp, Config5, RTL_R8(tp, Config5) | ASPM_en);
	RTL_W8(tp, Config2, RTL_R8(tp, Config2) | ClkReqEn);

	if (tp->mac_version >= RTL_GIGA_MAC_VER_60) {
		r8168_mac_ocp_modify(tp, 0xe094, 0xff00, 0);
		r8168_mac_ocp_modify(tp, 0xe092, 0x00ff, BIT(2));
	}
} else {
	if (tp->mac_version >= RTL_GIGA_MAC_VER_60)
		r8168_mac_ocp_modify(tp, 0xe092, 0x00ff, 0);

	RTL_W8(tp, Config2, RTL_R8(tp, Config2) & ~ClkReqEn);
	RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~ASPM_en); }
Quoted 3 lines

If function rtl_disable_exit_l1() is actually needed, I'd prefer to add it in a separate patch (to facilitate bisecting).

If exit l1 mask is enabled, hardware will prone to exit l1. That will prevent hardware from entering l1 substate. So It needs to disable l1 exist mask when device go to d3 state for entering l1 substate..

Quoted 9 lines
Quoted 3 lines

My understanding of PCI power management may be incomplete, but:
If a device goes to D3, then doesn't the bus go to L2/L3? L1 exit criteria would be irrelevant then.

Your understanding is correct.
D3 is divided to two substate, D3hot and D3cold. D3cold will enter L2/L3. D3hot may enter L1 or L2/L3 ready. In D3hot case, enable exit l1 mask will prevent hardware from entering PM L1. That is our hardware issue. So we disable exit l1 mask before hardware enter D3.

Quoted 4 lines

Thanks! One, hopefully last, question:
Are you aware of any boards/systems setting this "L1.2 was tested and is safe" flag?
Then this could be mentioned in the commit description.

Google chromebox will be the first one to use this flag.

Quoted 1 line

------Please consider the environment before printing this e-mail.

maintainer
#15 lore raw
In reply to Hau
Quoted 199 lines · Hau
Quoted 199 lines

-----Original Message-----
From: Heiner Kallweit [mailto:[email protected]]
Sent: Wednesday, January 26, 2022 9:47 PM
To: Hau <[email protected]>; [email protected]
Cc: nic_swsd <[email protected]>; [email protected]
Subject: Re: [PATCH net-next 1/1] r8169: enable RTL8125 ASPM L1.2

Quoted 189 lines · Hau
Quoted 158 lines · Chunhao Lin

drivers/net/ethernet/realtek/r8169_main.c static void rtl_wol_enable_rx(struct

Quoted 18 lines

This patch will enable RTL8125 ASPM L1.2 on the platforms that have tested RTL8125 with ASPM L1.2 enabled.
Register mac ocp 0xc0b2 will help to identify if RTL8125 has been tested on L1.2 enabled platform. If it is, this register will be set to 0xf. If not, this register will be default value 0.

---
 drivers/net/ethernet/realtek/r8169_main.c | 99
++++++++++++++++++-----
 1 file changed, 79 insertions(+), 20 deletions(-)
drivers/net/ethernet/realtek/r8169_main.c +0 -0
index 19e2621e0645..b1e013969d4c 100644
@@ -2238,21 +2238,6 @@ static void rtl_wol_enable_rx(struct

rtl8169_private *tp)

drivers/net/ethernet/realtek/r8169_main.c static void rtl_wol_enable_rx(struct · line 2238

Quoted 1 line
drivers/net/ethernet/realtek/r8169_main.c +0 -0
 			AcceptBroadcast | AcceptMulticast |

AcceptMyPhys); }

Quoted 18 lines
drivers/net/ethernet/realtek/r8169_main.c +0 -14
-static void rtl_prepare_power_down(struct rtl8169_private *tp) -{
-	if (tp->dash_type != RTL_DASH_NONE)
-		return;
-
-	if (tp->mac_version == RTL_GIGA_MAC_VER_32 ||
-	    tp->mac_version == RTL_GIGA_MAC_VER_33)
-		rtl_ephy_write(tp, 0x19, 0xff64);
-
-	if (device_may_wakeup(tp_to_dev(tp))) {
-		phy_speed_down(tp->phydev, false);
-		rtl_wol_enable_rx(tp);
-	}
-}
-
 static void rtl_init_rxcfg(struct rtl8169_private *tp)  {
 	switch (tp->mac_version) {
@@ -2650,6 +2635,34 @@ static void
Quoted 1 line

rtl_pcie_state_l2l3_disable(struct

rtl8169_private *tp)

drivers/net/ethernet/realtek/r8169_main.c static void rtl_hw_aspm_clkreq_enable(struct

Quoted 32 lines
drivers/net/ethernet/realtek/r8169_main.c +27 -0
 	RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Rdy_to_L23);  }
 
+static void rtl_disable_exit_l1(struct rtl8169_private *tp) {
+	/* Bits control which events trigger ASPM L1 exit:
+	 * Bit 12: rxdv
+	 * Bit 11: ltr_msg
+	 * Bit 10: txdma_poll
+	 * Bit  9: xadm
+	 * Bit  8: pktavi
+	 * Bit  7: txpla
+	 */
+	switch (tp->mac_version) {
+	case RTL_GIGA_MAC_VER_34 ... RTL_GIGA_MAC_VER_36:
+		rtl_eri_clear_bits(tp, 0xd4, 0x1f00);
+		break;
+	case RTL_GIGA_MAC_VER_37 ... RTL_GIGA_MAC_VER_38:
+		rtl_eri_clear_bits(tp, 0xd4, 0x0c00);
+		break;
+	case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_53:
+		rtl_eri_clear_bits(tp, 0xd4, 0x1f80);
+		break;
+	case RTL_GIGA_MAC_VER_60 ... RTL_GIGA_MAC_VER_63:
+		r8168_mac_ocp_modify(tp, 0xc0ac, 0x1f80, 0);
+		break;
+	default:
+		break;
+	}
+}
+
 static void rtl_enable_exit_l1(struct rtl8169_private *tp)  {
 	/* Bits control which events trigger ASPM L1 exit:
@@ -2692,6 +2705,33 @@ static void rtl_hw_aspm_clkreq_enable(struct

rtl8169_private *tp, bool enable)

Quoted 21 lines
drivers/net/ethernet/realtek/r8169_main.c +18 -0
 	udelay(10);
 }
 
+static void rtl_hw_aspm_l12_enable(struct rtl8169_private *tp, bool
+enable) {
+	/* Don't enable L1.2 in the chip if OS can't control ASPM */
+	if (enable && tp->aspm_manageable) {
+		r8168_mac_ocp_modify(tp, 0xe094, 0xff00, 0);
+		r8168_mac_ocp_modify(tp, 0xe092, 0x00ff, BIT(2));
+	} else {
+		r8168_mac_ocp_modify(tp, 0xe092, 0x00ff, 0);
+	}
+}
+
+static void rtl_prepare_power_down(struct rtl8169_private *tp) {
+	if (tp->dash_type != RTL_DASH_NONE)
+		return;
+
+	if (tp->mac_version == RTL_GIGA_MAC_VER_32 ||
+	    tp->mac_version == RTL_GIGA_MAC_VER_33)
+		rtl_ephy_write(tp, 0x19, 0xff64);

drivers/net/ethernet/realtek/r8169_main.c static void rtl_hw_aspm_clkreq_enable(struct · line 2735

Quoted 10 lines
drivers/net/ethernet/realtek/r8169_main.c +8 -0
+
+	if (device_may_wakeup(tp_to_dev(tp))) {
+		rtl_disable_exit_l1(tp);
+		phy_speed_down(tp->phydev, false);
+		rtl_wol_enable_rx(tp);
+	}
+}
+
 static void rtl_set_fifo_size(struct rtl8169_private *tp, u16 rx_stat,
 			      u16 tx_stat, u16 rx_dyn, u16 tx_dyn)  { @@ -

3675,6 +3715,7

drivers/net/ethernet/realtek/r8169_main.c static void rtl_init_mac_address(struct

Quoted 8 lines
drivers/net/ethernet/realtek/r8169_main.c +1 -0
 @@ static void rtl_hw_start_8125b(struct rtl8169_private *tp)
 	rtl_ephy_init(tp, e_info_8125b);
 	rtl_hw_start_8125_common(tp);
 
+	rtl_hw_aspm_l12_enable(tp, true);
 	rtl_hw_aspm_clkreq_enable(tp, true);  }
@@ -5255,6 +5296,20 @@ static void rtl_init_mac_address(struct

rtl8169_private *tp)

Quoted 20 lines
drivers/net/ethernet/realtek/r8169_main.c +13 -0
 	rtl_rar_set(tp, mac_addr);
 }
 
+/* mac ocp 0xc0b2 will help to identify if RTL8125 has been tested
+ * on L1.2 enabled platform. If it is, this register will be set to 0xf.
+ * If not, this register will be default value 0.
+ */
+static bool rtl_platform_l12_enabled(struct rtl8169_private *tp) {
+	switch (tp->mac_version) {
+	case RTL_GIGA_MAC_VER_60 ... RTL_GIGA_MAC_VER_63:
+		return (r8168_mac_ocp_read(tp, 0xc0b2) & 0xf) ? true : false;
+	default:
+		return false;
+	}
+}
+
 static int rtl_init_one(struct pci_dev *pdev, const struct
 pci_device_id *ent)  {
 	struct rtl8169_private *tp;

drivers/net/ethernet/realtek/r8169_main.c static int rtl_init_one(struct pci_dev · line 5388

Quoted 1 line
drivers/net/ethernet/realtek/r8169_main.c +0 -0
@@ -5333,11 +5388,15 @@ static int rtl_init_one(struct pci_dev
 *pdev,

const struct pci_device_id *ent)

drivers/net/ethernet/realtek/r8169_main.c static int rtl_init_one(struct pci_dev · line 5394

Quoted 11 lines
drivers/net/ethernet/realtek/r8169_main.c +3 -5
 	 * Chips from RTL8168h partially have issues with L1.2, but seem
 	 * to work fine with L1 and L1.1.
 	 */
-	if (tp->mac_version >= RTL_GIGA_MAC_VER_45)
-		rc = pci_disable_link_state(pdev, PCIE_LINK_STATE_L1_2);
-	else
-		rc = pci_disable_link_state(pdev, PCIE_LINK_STATE_L1);
-	tp->aspm_manageable = !rc;
+	if (!rtl_platform_l12_enabled(tp)) {
+		if (tp->mac_version >= RTL_GIGA_MAC_VER_45)
+			rc = pci_disable_link_state(pdev,

PCIE_LINK_STATE_L1_2);

drivers/net/ethernet/realtek/r8169_main.c static int rtl_init_one(struct pci_dev · line 5396

Quoted 2 lines
drivers/net/ethernet/realtek/r8169_main.c +2 -0
+		else
+			rc = pci_disable_link_state(pdev,

PCIE_LINK_STATE_L1);

Quoted 5 lines
drivers/net/ethernet/realtek/r8169_main.c +4 -0
+		tp->aspm_manageable = !rc;
+	} else {
+		tp->aspm_manageable = pcie_aspm_enabled(pdev);
+	}
 
Quoted 7 lines

drivers/net/ethernet/realtek/r8169_main.c static int rtl_init_one(struct pci_dev · line 5402

Quoted 2 lines
drivers/net/ethernet/realtek/r8169_main.c +0 -0
 	tp->dash_type = rtl_check_dash(tp);

Hi Hau,

the following is a stripped-down version of the patch. Could you please check/test?

This patch is ok.
L1 substate lock can apply for both rtl8125a.rtl8125b.

if (enable && tp->aspm_manageable) {
	RTL_W8(tp, Config5, RTL_R8(tp, Config5) | ASPM_en);
	RTL_W8(tp, Config2, RTL_R8(tp, Config2) | ClkReqEn);

	if (tp->mac_version >= RTL_GIGA_MAC_VER_60) {
		r8168_mac_ocp_modify(tp, 0xe094, 0xff00, 0);
		r8168_mac_ocp_modify(tp, 0xe092, 0x00ff, BIT(2));
	}
} else {
	if (tp->mac_version >= RTL_GIGA_MAC_VER_60)
		r8168_mac_ocp_modify(tp, 0xe092, 0x00ff, 0);

	RTL_W8(tp, Config2, RTL_R8(tp, Config2) & ~ClkReqEn);
	RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~ASPM_en); }
Quoted 3 lines

If function rtl_disable_exit_l1() is actually needed, I'd prefer to add it in a separate patch (to facilitate bisecting).

If exit l1 mask is enabled, hardware will prone to exit l1. That will prevent hardware from entering l1 substate. So It needs to disable l1 exist mask when device go to d3 state for entering l1 substate..

Quoted 10 lines
Quoted 3 lines

My understanding of PCI power management may be incomplete, but:
If a device goes to D3, then doesn't the bus go to L2/L3? L1 exit criteria would be irrelevant then.

Your understanding is correct.
D3 is divided to two substate, D3hot and D3cold. D3cold will enter L2/L3. D3hot may enter L1 or L2/L3 ready. In D3hot case, enable exit l1 mask will prevent hardware from entering PM L1. That is our hardware issue. So we disable exit l1 mask before hardware enter D3.

I submitted the patch to enable L1.2 if tested with your Suggested-by. One last question before submitting the disable_exit_l1 patch.

Depending on the chip version only certain L1 exit bits are set.

+ switch (tp->mac_version) {
+ case RTL_GIGA_MAC_VER_34 ... RTL_GIGA_MAC_VER_36:
+ rtl_eri_clear_bits(tp, 0xd4, 0x1f00);
+ break;
+ case RTL_GIGA_MAC_VER_37 ... RTL_GIGA_MAC_VER_38:
+ rtl_eri_clear_bits(tp, 0xd4, 0x0c00);
+ break;
+ case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_53:
+ rtl_eri_clear_bits(tp, 0xd4, 0x1f80);
+ break;
+ case RTL_GIGA_MAC_VER_60 ... RTL_GIGA_MAC_VER_63:
+ r8168_mac_ocp_modify(tp, 0xc0ac, 0x1f80, 0);
+ break;

Would it be safe to shorten this to the following? Or is some bit in this range used for another purpose on certain chip versions?

+ switch (tp->mac_version) {
+ case RTL_GIGA_MAC_VER_34 ... RTL_GIGA_MAC_VER_38:
+ case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_53:
+ rtl_eri_clear_bits(tp, 0xd4, 0x1f80);
+ break;
+ case RTL_GIGA_MAC_VER_60 ... RTL_GIGA_MAC_VER_63:
+ r8168_mac_ocp_modify(tp, 0xc0ac, 0x1f80, 0);
+ break;

author
#16 lore raw
Quoted 242 lines

-----Original Message-----
From: Heiner Kallweit [mailto:[email protected]]
Sent: Thursday, January 27, 2022 3:58 AM
To: Hau <[email protected]>; [email protected]
Cc: nic_swsd <[email protected]>; [email protected]
Subject: Re: [PATCH net-next 1/1] r8169: enable RTL8125 ASPM L1.2

Quoted 131 lines · Hau
Quoted 131 lines

-----Original Message-----
From: Heiner Kallweit [mailto:[email protected]]
Sent: Wednesday, January 26, 2022 9:47 PM
To: Hau <[email protected]>; [email protected]
Cc: nic_swsd <[email protected]>; [email protected]
Subject: Re: [PATCH net-next 1/1] r8169: enable RTL8125 ASPM L1.2

Quoted 121 lines · Hau
Quoted 121 lines · Chunhao Lin

drivers/net/ethernet/realtek/r8169_main.c static void rtl_wol_enable_rx(struct

Quoted 18 lines

This patch will enable RTL8125 ASPM L1.2 on the platforms that have tested RTL8125 with ASPM L1.2 enabled.
Register mac ocp 0xc0b2 will help to identify if RTL8125 has been tested on L1.2 enabled platform. If it is, this register will be set to 0xf. If not, this register will be default value 0.

---
 drivers/net/ethernet/realtek/r8169_main.c | 99
++++++++++++++++++-----
 1 file changed, 79 insertions(+), 20 deletions(-)
drivers/net/ethernet/realtek/r8169_main.c +0 -0
index 19e2621e0645..b1e013969d4c 100644
@@ -2238,21 +2238,6 @@ static void rtl_wol_enable_rx(struct

rtl8169_private *tp)

drivers/net/ethernet/realtek/r8169_main.c static void rtl_wol_enable_rx(struct · line 2238

Quoted 1 line
drivers/net/ethernet/realtek/r8169_main.c +0 -0
 			AcceptBroadcast | AcceptMulticast |

AcceptMyPhys); }

Quoted 18 lines
drivers/net/ethernet/realtek/r8169_main.c +0 -14
-static void rtl_prepare_power_down(struct rtl8169_private *tp) -{
-	if (tp->dash_type != RTL_DASH_NONE)
-		return;
-
-	if (tp->mac_version == RTL_GIGA_MAC_VER_32 ||
-	    tp->mac_version == RTL_GIGA_MAC_VER_33)
-		rtl_ephy_write(tp, 0x19, 0xff64);
-
-	if (device_may_wakeup(tp_to_dev(tp))) {
-		phy_speed_down(tp->phydev, false);
-		rtl_wol_enable_rx(tp);
-	}
-}
-
 static void rtl_init_rxcfg(struct rtl8169_private *tp)  {
 	switch (tp->mac_version) {
@@ -2650,6 +2635,34 @@ static void
Quoted 1 line

rtl_pcie_state_l2l3_disable(struct

rtl8169_private *tp)

Quoted 32 lines
drivers/net/ethernet/realtek/r8169_main.c +27 -0
 	RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Rdy_to_L23);  }
 
+static void rtl_disable_exit_l1(struct rtl8169_private *tp) {
+	/* Bits control which events trigger ASPM L1 exit:
+	 * Bit 12: rxdv
+	 * Bit 11: ltr_msg
+	 * Bit 10: txdma_poll
+	 * Bit  9: xadm
+	 * Bit  8: pktavi
+	 * Bit  7: txpla
+	 */
+	switch (tp->mac_version) {
+	case RTL_GIGA_MAC_VER_34 ... RTL_GIGA_MAC_VER_36:
+		rtl_eri_clear_bits(tp, 0xd4, 0x1f00);
+		break;
+	case RTL_GIGA_MAC_VER_37 ... RTL_GIGA_MAC_VER_38:
+		rtl_eri_clear_bits(tp, 0xd4, 0x0c00);
+		break;
+	case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_53:
+		rtl_eri_clear_bits(tp, 0xd4, 0x1f80);
+		break;
+	case RTL_GIGA_MAC_VER_60 ... RTL_GIGA_MAC_VER_63:
+		r8168_mac_ocp_modify(tp, 0xc0ac, 0x1f80, 0);
+		break;
+	default:
+		break;
+	}
+}
+
 static void rtl_enable_exit_l1(struct rtl8169_private *tp)  {
 	/* Bits control which events trigger ASPM L1 exit:
@@ -2692,6 +2705,33 @@ static void
Quoted 1 line

rtl_hw_aspm_clkreq_enable(struct

rtl8169_private *tp, bool enable)

Quoted 22 lines
drivers/net/ethernet/realtek/r8169_main.c +19 -0
 	udelay(10);
 }
 
+static void rtl_hw_aspm_l12_enable(struct rtl8169_private *tp,
+bool
+enable) {
+	/* Don't enable L1.2 in the chip if OS can't control ASPM */
+	if (enable && tp->aspm_manageable) {
+		r8168_mac_ocp_modify(tp, 0xe094, 0xff00, 0);
+		r8168_mac_ocp_modify(tp, 0xe092, 0x00ff, BIT(2));
+	} else {
+		r8168_mac_ocp_modify(tp, 0xe092, 0x00ff, 0);
+	}
+}
+
+static void rtl_prepare_power_down(struct rtl8169_private *tp) {
+	if (tp->dash_type != RTL_DASH_NONE)
+		return;
+
+	if (tp->mac_version == RTL_GIGA_MAC_VER_32 ||
+	    tp->mac_version == RTL_GIGA_MAC_VER_33)
+		rtl_ephy_write(tp, 0x19, 0xff64);

drivers/net/ethernet/realtek/r8169_main.c

Quoted 10 lines
drivers/net/ethernet/realtek/r8169_main.c +8 -0
+
+	if (device_may_wakeup(tp_to_dev(tp))) {
+		rtl_disable_exit_l1(tp);
+		phy_speed_down(tp->phydev, false);
+		rtl_wol_enable_rx(tp);
+	}
+}
+
 static void rtl_set_fifo_size(struct rtl8169_private *tp, u16 rx_stat,
 			      u16 tx_stat, u16 rx_dyn, u16 tx_dyn)  { @@ -

3675,6 +3715,7

drivers/net/ethernet/realtek/r8169_main.c static void rtl_init_mac_address(struct

Quoted 8 lines

@@ static void rtl_hw_start_8125b(struct rtl8169_private *tp)

drivers/net/ethernet/realtek/r8169_main.c +1 -0
 	rtl_ephy_init(tp, e_info_8125b);
 	rtl_hw_start_8125_common(tp);
 
+	rtl_hw_aspm_l12_enable(tp, true);
 	rtl_hw_aspm_clkreq_enable(tp, true);  }
@@ -5255,6 +5296,20 @@ static void rtl_init_mac_address(struct

rtl8169_private *tp)

Quoted 3 lines
drivers/net/ethernet/realtek/r8169_main.c +0 -0
 	rtl_rar_set(tp, mac_addr);
 }
 
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

drivers/net/ethernet/realtek/r8169_main.c static void rtl_init_mac_address(struct · line 5307

Quoted 9 lines
drivers/net/ethernet/realtek/r8169_main.c +9 -0
+/* mac ocp 0xc0b2 will help to identify if RTL8125 has been
+tested
+ * on L1.2 enabled platform. If it is, this register will be set to 0xf.
+ * If not, this register will be default value 0.
+ */
+static bool rtl_platform_l12_enabled(struct rtl8169_private *tp) {
+	switch (tp->mac_version) {
+	case RTL_GIGA_MAC_VER_60 ... RTL_GIGA_MAC_VER_63:
+		return (r8168_mac_ocp_read(tp, 0xc0b2) & 0xf) ?

true : false;

Quoted 62 lines
Quoted 62 lines
Quoted 62 lines
Quoted 31 lines

drivers/net/ethernet/realtek/r8169_main.c static int rtl_init_one(struct pci_dev · line 5388

Quoted 10 lines
drivers/net/ethernet/realtek/r8169_main.c +5 -0
+	default:
+		return false;
+	}
+}
+
 static int rtl_init_one(struct pci_dev *pdev, const struct
 pci_device_id *ent)  {
 	struct rtl8169_private *tp;
@@ -5333,11 +5388,15 @@ static int rtl_init_one(struct pci_dev
 *pdev,

const struct pci_device_id *ent)

drivers/net/ethernet/realtek/r8169_main.c static int rtl_init_one(struct pci_dev · line 5394

Quoted 11 lines
drivers/net/ethernet/realtek/r8169_main.c +3 -5
 	 * Chips from RTL8168h partially have issues with L1.2, but seem
 	 * to work fine with L1 and L1.1.
 	 */
-	if (tp->mac_version >= RTL_GIGA_MAC_VER_45)
-		rc = pci_disable_link_state(pdev, PCIE_LINK_STATE_L1_2);
-	else
-		rc = pci_disable_link_state(pdev, PCIE_LINK_STATE_L1);
-	tp->aspm_manageable = !rc;
+	if (!rtl_platform_l12_enabled(tp)) {
+		if (tp->mac_version >= RTL_GIGA_MAC_VER_45)
+			rc = pci_disable_link_state(pdev,

PCIE_LINK_STATE_L1_2);

drivers/net/ethernet/realtek/r8169_main.c static int rtl_init_one(struct pci_dev · line 5396

Quoted 2 lines
drivers/net/ethernet/realtek/r8169_main.c +2 -0
+		else
+			rc = pci_disable_link_state(pdev,

PCIE_LINK_STATE_L1);

Quoted 5 lines
drivers/net/ethernet/realtek/r8169_main.c +4 -0
+		tp->aspm_manageable = !rc;
+	} else {
+		tp->aspm_manageable = pcie_aspm_enabled(pdev);
+	}
 
Quoted 7 lines

drivers/net/ethernet/realtek/r8169_main.c static int rtl_init_one(struct pci_dev · line 5402

Quoted 2 lines
drivers/net/ethernet/realtek/r8169_main.c +0 -0
 	tp->dash_type = rtl_check_dash(tp);

Hi Hau,

the following is a stripped-down version of the patch. Could you please check/test?

This patch is ok.
L1 substate lock can apply for both rtl8125a.rtl8125b.

if (enable && tp->aspm_manageable) {
	RTL_W8(tp, Config5, RTL_R8(tp, Config5) | ASPM_en);
	RTL_W8(tp, Config2, RTL_R8(tp, Config2) | ClkReqEn);

	if (tp->mac_version >= RTL_GIGA_MAC_VER_60) {
		r8168_mac_ocp_modify(tp, 0xe094, 0xff00, 0);
		r8168_mac_ocp_modify(tp, 0xe092, 0x00ff, BIT(2));
	}
} else {
	if (tp->mac_version >= RTL_GIGA_MAC_VER_60)
		r8168_mac_ocp_modify(tp, 0xe092, 0x00ff, 0);

	RTL_W8(tp, Config2, RTL_R8(tp, Config2) & ~ClkReqEn);
	RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~ASPM_en); }
Quoted 3 lines

If function rtl_disable_exit_l1() is actually needed, I'd prefer to add it in a separate patch (to facilitate bisecting).

If exit l1 mask is enabled, hardware will prone to exit l1. That will prevent hardware from entering l1 substate. So It needs to disable l1 exist mask when device go to d3 state for entering l1 substate..

Quoted 10 lines
Quoted 3 lines

My understanding of PCI power management may be incomplete, but:
If a device goes to D3, then doesn't the bus go to L2/L3? L1 exit criteria would be irrelevant then.

Your understanding is correct.
D3 is divided to two substate, D3hot and D3cold. D3cold will enter L2/L3. D3hot may enter L1 or L2/L3 ready. In D3hot case, enable exit l1 mask will prevent hardware from entering PM L1. That is our hardware issue. So we disable exit l1 mask before hardware enter D3.

I submitted the patch to enable L1.2 if tested with your Suggested-by. One last question before submitting the disable_exit_l1 patch.

Depending on the chip version only certain L1 exit bits are set.

(quoted diff) +13 -0
+	switch (tp->mac_version) {
+	case RTL_GIGA_MAC_VER_34 ... RTL_GIGA_MAC_VER_36:
+		rtl_eri_clear_bits(tp, 0xd4, 0x1f00);
+		break;
+	case RTL_GIGA_MAC_VER_37 ... RTL_GIGA_MAC_VER_38:
+		rtl_eri_clear_bits(tp, 0xd4, 0x0c00);
+		break;
+	case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_53:
+		rtl_eri_clear_bits(tp, 0xd4, 0x1f80);
+		break;
+	case RTL_GIGA_MAC_VER_60 ... RTL_GIGA_MAC_VER_63:
+		r8168_mac_ocp_modify(tp, 0xc0ac, 0x1f80, 0);
+		break;
Quoted 2 lines

Would it be safe to shorten this to the following? Or is some bit in this range used for another purpose on certain chip versions?

Bit7 has different purpose for chip ver 34 to chip ver 38. But for chip after rtl8168g, eri 0xd4 is mapped to mac ocp 0xc0ac. The code can be shorten as following.
switch (tp->mac_version) {
case RTL_GIGA_MAC_VER_34 ... RTL_GIGA_MAC_VER_38:

			 rtl_eri_clear_bits(tp, 0xd4, 0x1f00);
			 break;
case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_53:
case RTL_GIGA_MAC_VER_60 ... RTL_GIGA_MAC_VER_63:
			 r8168_mac_ocp_modify(tp, 0xc0ac, 0x1f80, 0);
			 break;
Quoted 9 lines
(quoted diff) +8 -1
+	switch (tp->mac_version) {
+	case RTL_GIGA_MAC_VER_34 ... RTL_GIGA_MAC_VER_38:
+	case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_53:
+		rtl_eri_clear_bits(tp, 0xd4, 0x1f80);
+		break;
+	case RTL_GIGA_MAC_VER_60 ... RTL_GIGA_MAC_VER_63:
+		r8168_mac_ocp_modify(tp, 0xc0ac, 0x1f80, 0);
+		break;
------Please consider the environment before printing this e-mail.