Skip to contentSkip to conversation

r8169: sync few functionalities with vendor driver

PATCH Applied Heiner Kallweit 2 participants 6 messages May 8, 2020 – May 9, 2020

Subsystems (3)
lore
Share & tools
lore

Heiner Kallweit

author maintainer
#0 lore raw

cover r8169: sync few functionalities with vendor driver

Add few helpers (with names copied from vendor drivers) to make clearer what the respective code is doing. In addition improve reset preparation for chips from RTL8168g.

Heiner Kallweit (4):
r8169: add helper r8168g_wait_ll_share_fifo_ready
r8169: add helper rtl_enable_rxdvgate
r8169: add helper rtl_wait_txrx_fifo_empty
r8169: improve reset handling for chips from RTL8168g

 drivers/net/ethernet/realtek/r8169_main.c | 63 ++++++++++++++---------
 1 file changed, 39 insertions(+), 24 deletions(-)
Signature · 1 line
2.26.2
author maintainer
#1 lore raw

PATCH 1/4 r8169: add helper r8168g_wait_ll_share_fifo_ready

Create a helper for this waiting function, name of the helper is borrowed from the vendor driver. In addition don't return in the two hw_init functions if the first wait runs into a timeout, there's no benefit in doing so.

---
 drivers/net/ethernet/realtek/r8169_main.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)
drivers/net/ethernet/realtek/r8169_main.c +9 -10
index 8c41f6848..1c96fc219 100644
@@ -5057,6 +5057,11 @@ DECLARE_RTL_COND(rtl_link_list_ready_cond)
 	return RTL_R8(tp, MCU) & LINK_LIST_RDY;
 }
 
+static void r8168g_wait_ll_share_fifo_ready(struct rtl8169_private *tp)
+{
+	rtl_loop_wait_high(tp, &rtl_link_list_ready_cond, 100, 42);
+}
+
 DECLARE_RTL_COND(rtl_rxtx_empty_cond)
 {
 	return (RTL_R8(tp, MCU) & RXTX_EMPTY) == RXTX_EMPTY;
@@ -5141,13 +5146,10 @@ static void rtl_hw_init_8168g(struct rtl8169_private *tp)
 	RTL_W8(tp, MCU, RTL_R8(tp, MCU) & ~NOW_IS_OOB);
 
 	r8168_mac_ocp_modify(tp, 0xe8de, BIT(14), 0);
-
-	if (!rtl_loop_wait_high(tp, &rtl_link_list_ready_cond, 100, 42))
-		return;
+	r8168g_wait_ll_share_fifo_ready(tp);
 
 	r8168_mac_ocp_modify(tp, 0xe8de, 0, BIT(15));
-
-	rtl_loop_wait_high(tp, &rtl_link_list_ready_cond, 100, 42);
+	r8168g_wait_ll_share_fifo_ready(tp);
 }
 
 static void rtl_hw_init_8125(struct rtl8169_private *tp)
@@ -5162,15 +5164,12 @@ static void rtl_hw_init_8125(struct rtl8169_private *tp)
 	RTL_W8(tp, MCU, RTL_R8(tp, MCU) & ~NOW_IS_OOB);
 
 	r8168_mac_ocp_modify(tp, 0xe8de, BIT(14), 0);
-
-	if (!rtl_loop_wait_high(tp, &rtl_link_list_ready_cond, 100, 42))
-		return;
+	r8168g_wait_ll_share_fifo_ready(tp);
 
 	r8168_mac_ocp_write(tp, 0xc0aa, 0x07d0);
 	r8168_mac_ocp_write(tp, 0xc0a6, 0x0150);
 	r8168_mac_ocp_write(tp, 0xc01e, 0x5555);
-
-	rtl_loop_wait_high(tp, &rtl_link_list_ready_cond, 100, 42);
+	r8168g_wait_ll_share_fifo_ready(tp);
 }
 
 static void rtl_hw_initialize(struct rtl8169_private *tp)
Signature · 1 line
2.26.2
author maintainer
#2 lore raw

PATCH 2/4 r8169: add helper rtl_enable_rxdvgate

In reply to Heiner Kallweit

Add a helper for setting RXDV_GATED_EN, the 2ms delay is copied from the vendor driver.

---
 drivers/net/ethernet/realtek/r8169_main.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/net/ethernet/realtek/r8169_main.c +8 -2
index 1c96fc219..eb26c3477 100644
@@ -2496,6 +2496,12 @@ DECLARE_RTL_COND(rtl_txcfg_empty_cond)
 	return RTL_R32(tp, TxConfig) & TXCFG_EMPTY;
 }
 
+static void rtl_enable_rxdvgate(struct rtl8169_private *tp)
+{
+	RTL_W32(tp, MISC, RTL_R32(tp, MISC) | RXDV_GATED_EN);
+	fsleep(2000);
+}
+
 static void rtl8169_hw_reset(struct rtl8169_private *tp)
 {
 	/* Disable interrupts */
@@ -5133,7 +5139,7 @@ static int r8169_mdio_register(struct rtl8169_private *tp)
 
 static void rtl_hw_init_8168g(struct rtl8169_private *tp)
 {
-	RTL_W32(tp, MISC, RTL_R32(tp, MISC) | RXDV_GATED_EN);
+	rtl_enable_rxdvgate(tp);
 
 	if (!rtl_loop_wait_high(tp, &rtl_txcfg_empty_cond, 100, 42))
 		return;
@@ -5154,7 +5160,7 @@ static void rtl_hw_init_8168g(struct rtl8169_private *tp)
 
 static void rtl_hw_init_8125(struct rtl8169_private *tp)
 {
-	RTL_W32(tp, MISC, RTL_R32(tp, MISC) | RXDV_GATED_EN);
+	rtl_enable_rxdvgate(tp);
 
 	if (!rtl_loop_wait_high(tp, &rtl_rxtx_empty_cond, 100, 42))
 		return;
Signature · 1 line
2.26.2
author maintainer
#3 lore raw

PATCH 3/4 r8169: add helper rtl_wait_txrx_fifo_empty

In reply to Heiner Kallweit

Add a helper for waiting for FIFO's to be empty, again the name is borrowed from the vendor driver.

---
 drivers/net/ethernet/realtek/r8169_main.c | 35 ++++++++++++++---------
 1 file changed, 21 insertions(+), 14 deletions(-)
drivers/net/ethernet/realtek/r8169_main.c +21 -14
index eb26c3477..7ea58bd9b 100644
@@ -2496,10 +2496,31 @@ DECLARE_RTL_COND(rtl_txcfg_empty_cond)
 	return RTL_R32(tp, TxConfig) & TXCFG_EMPTY;
 }
 
+DECLARE_RTL_COND(rtl_rxtx_empty_cond)
+{
+	return (RTL_R8(tp, MCU) & RXTX_EMPTY) == RXTX_EMPTY;
+}
+
+static void rtl_wait_txrx_fifo_empty(struct rtl8169_private *tp)
+{
+	switch (tp->mac_version) {
+	case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_52:
+		rtl_loop_wait_high(tp, &rtl_txcfg_empty_cond, 100, 42);
+		rtl_loop_wait_high(tp, &rtl_rxtx_empty_cond, 100, 42);
+		break;
+	case RTL_GIGA_MAC_VER_60 ... RTL_GIGA_MAC_VER_61:
+		rtl_loop_wait_high(tp, &rtl_rxtx_empty_cond, 100, 42);
+		break;
+	default:
+		break;
+	}
+}
+
 static void rtl_enable_rxdvgate(struct rtl8169_private *tp)
 {
 	RTL_W32(tp, MISC, RTL_R32(tp, MISC) | RXDV_GATED_EN);
 	fsleep(2000);
+	rtl_wait_txrx_fifo_empty(tp);
 }
 
 static void rtl8169_hw_reset(struct rtl8169_private *tp)
@@ -5068,11 +5089,6 @@ static void r8168g_wait_ll_share_fifo_ready(struct rtl8169_private *tp)
 	rtl_loop_wait_high(tp, &rtl_link_list_ready_cond, 100, 42);
 }
 
-DECLARE_RTL_COND(rtl_rxtx_empty_cond)
-{
-	return (RTL_R8(tp, MCU) & RXTX_EMPTY) == RXTX_EMPTY;
-}
-
 static int r8169_mdio_read_reg(struct mii_bus *mii_bus, int phyaddr, int phyreg)
 {
 	struct rtl8169_private *tp = mii_bus->priv;
@@ -5141,12 +5157,6 @@ static void rtl_hw_init_8168g(struct rtl8169_private *tp)
 {
 	rtl_enable_rxdvgate(tp);
 
-	if (!rtl_loop_wait_high(tp, &rtl_txcfg_empty_cond, 100, 42))
-		return;
-
-	if (!rtl_loop_wait_high(tp, &rtl_rxtx_empty_cond, 100, 42))
-		return;
-
 	RTL_W8(tp, ChipCmd, RTL_R8(tp, ChipCmd) & ~(CmdTxEnb | CmdRxEnb));
 	msleep(1);
 	RTL_W8(tp, MCU, RTL_R8(tp, MCU) & ~NOW_IS_OOB);
@@ -5162,9 +5172,6 @@ static void rtl_hw_init_8125(struct rtl8169_private *tp)
 {
 	rtl_enable_rxdvgate(tp);
 
-	if (!rtl_loop_wait_high(tp, &rtl_rxtx_empty_cond, 100, 42))
-		return;
-
 	RTL_W8(tp, ChipCmd, RTL_R8(tp, ChipCmd) & ~(CmdTxEnb | CmdRxEnb));
 	msleep(1);
 	RTL_W8(tp, MCU, RTL_R8(tp, MCU) & ~NOW_IS_OOB);
Signature · 1 line
2.26.2
author maintainer
#4 lore raw

PATCH 4/4 r8169: improve reset handling for chips from RTL8168g

In reply to Heiner Kallweit

Sync the reset preparation for chips from RTL8168g with the r8168 and r8125 vendor drivers.

---
 drivers/net/ethernet/realtek/r8169_main.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/ethernet/realtek/r8169_main.c +4 -1
index 7ea58bd9b..0e96d0de2 100644
@@ -2537,10 +2537,13 @@ static void rtl8169_hw_reset(struct rtl8169_private *tp)
 		rtl_loop_wait_low(tp, &rtl_npq_cond, 20, 2000);
 		break;
 	case RTL_GIGA_MAC_VER_34 ... RTL_GIGA_MAC_VER_38:
-	case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_52:
 		RTL_W8(tp, ChipCmd, RTL_R8(tp, ChipCmd) | StopReq);
 		rtl_loop_wait_high(tp, &rtl_txcfg_empty_cond, 100, 666);
 		break;
+	case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_61:
+		rtl_enable_rxdvgate(tp);
+		fsleep(2000);
+		break;
 	default:
 		RTL_W8(tp, ChipCmd, RTL_R8(tp, ChipCmd) | StopReq);
 		udelay(100);
Signature · 1 line
2.26.2
maintainer Applied
#5 lore raw
In reply to Heiner Kallweit
Quoted 3 lines · On Fri, 8 May 2020 23:28:51 +0200 Heiner Kallweit wrote:

Add few helpers (with names copied from vendor drivers) to make clearer what the respective code is doing. In addition improve reset preparation for chips from RTL8168g.

Applied, thank you!