5bcf06098a88ee4d22b6bf599770aab3e7d0a3e6
[openwrt/staging/blocktrron.git] /
1 From 7a3bcd39ae1f0e3ab896d9df62339ab4297a0bfd Mon Sep 17 00:00:00 2001
2 From: Heiner Kallweit <hkallweit1@gmail.com>
3 Date: Sat, 9 Nov 2024 23:12:12 +0100
4 Subject: [PATCH] r8169: use helper r8169_mod_reg8_cond to simplify
5 rtl_jumbo_config
6
7 Use recently added helper r8169_mod_reg8_cond() to simplify jumbo
8 mode configuration.
9
10 Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
11 Reviewed-by: Simon Horman <horms@kernel.org>
12 Link: https://patch.msgid.link/3df1d484-a02e-46e7-8f75-db5b428e422e@gmail.com
13 Signed-off-by: Jakub Kicinski <kuba@kernel.org>
14 ---
15 drivers/net/ethernet/realtek/r8169_main.c | 77 ++++-------------------
16 1 file changed, 11 insertions(+), 66 deletions(-)
17
18 --- a/drivers/net/ethernet/realtek/r8169_main.c
19 +++ b/drivers/net/ethernet/realtek/r8169_main.c
20 @@ -2547,86 +2547,31 @@ static void rtl8169_init_ring_indexes(st
21 tp->dirty_tx = tp->cur_tx = tp->cur_rx = 0;
22 }
23
24 -static void r8168c_hw_jumbo_enable(struct rtl8169_private *tp)
25 -{
26 - RTL_W8(tp, Config3, RTL_R8(tp, Config3) | Jumbo_En0);
27 - RTL_W8(tp, Config4, RTL_R8(tp, Config4) | Jumbo_En1);
28 -}
29 -
30 -static void r8168c_hw_jumbo_disable(struct rtl8169_private *tp)
31 -{
32 - RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Jumbo_En0);
33 - RTL_W8(tp, Config4, RTL_R8(tp, Config4) & ~Jumbo_En1);
34 -}
35 -
36 -static void r8168dp_hw_jumbo_enable(struct rtl8169_private *tp)
37 -{
38 - RTL_W8(tp, Config3, RTL_R8(tp, Config3) | Jumbo_En0);
39 -}
40 -
41 -static void r8168dp_hw_jumbo_disable(struct rtl8169_private *tp)
42 -{
43 - RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Jumbo_En0);
44 -}
45 -
46 -static void r8168e_hw_jumbo_enable(struct rtl8169_private *tp)
47 -{
48 - RTL_W8(tp, MaxTxPacketSize, 0x24);
49 - RTL_W8(tp, Config3, RTL_R8(tp, Config3) | Jumbo_En0);
50 - RTL_W8(tp, Config4, RTL_R8(tp, Config4) | 0x01);
51 -}
52 -
53 -static void r8168e_hw_jumbo_disable(struct rtl8169_private *tp)
54 -{
55 - RTL_W8(tp, MaxTxPacketSize, 0x3f);
56 - RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Jumbo_En0);
57 - RTL_W8(tp, Config4, RTL_R8(tp, Config4) & ~0x01);
58 -}
59 -
60 -static void r8168b_1_hw_jumbo_enable(struct rtl8169_private *tp)
61 -{
62 - RTL_W8(tp, Config4, RTL_R8(tp, Config4) | (1 << 0));
63 -}
64 -
65 -static void r8168b_1_hw_jumbo_disable(struct rtl8169_private *tp)
66 -{
67 - RTL_W8(tp, Config4, RTL_R8(tp, Config4) & ~(1 << 0));
68 -}
69 -
70 static void rtl_jumbo_config(struct rtl8169_private *tp)
71 {
72 bool jumbo = tp->dev->mtu > ETH_DATA_LEN;
73 int readrq = 4096;
74
75 + if (jumbo && tp->mac_version >= RTL_GIGA_MAC_VER_17 &&
76 + tp->mac_version <= RTL_GIGA_MAC_VER_26)
77 + readrq = 512;
78 +
79 rtl_unlock_config_regs(tp);
80 switch (tp->mac_version) {
81 case RTL_GIGA_MAC_VER_17:
82 - if (jumbo) {
83 - readrq = 512;
84 - r8168b_1_hw_jumbo_enable(tp);
85 - } else {
86 - r8168b_1_hw_jumbo_disable(tp);
87 - }
88 + r8169_mod_reg8_cond(tp, Config4, BIT(0), jumbo);
89 break;
90 case RTL_GIGA_MAC_VER_18 ... RTL_GIGA_MAC_VER_26:
91 - if (jumbo) {
92 - readrq = 512;
93 - r8168c_hw_jumbo_enable(tp);
94 - } else {
95 - r8168c_hw_jumbo_disable(tp);
96 - }
97 + r8169_mod_reg8_cond(tp, Config3, Jumbo_En0, jumbo);
98 + r8169_mod_reg8_cond(tp, Config4, Jumbo_En1, jumbo);
99 break;
100 case RTL_GIGA_MAC_VER_28:
101 - if (jumbo)
102 - r8168dp_hw_jumbo_enable(tp);
103 - else
104 - r8168dp_hw_jumbo_disable(tp);
105 + r8169_mod_reg8_cond(tp, Config3, Jumbo_En0, jumbo);
106 break;
107 case RTL_GIGA_MAC_VER_31 ... RTL_GIGA_MAC_VER_33:
108 - if (jumbo)
109 - r8168e_hw_jumbo_enable(tp);
110 - else
111 - r8168e_hw_jumbo_disable(tp);
112 + RTL_W8(tp, MaxTxPacketSize, jumbo ? 0x24 : 0x3f);
113 + r8169_mod_reg8_cond(tp, Config3, Jumbo_En0, jumbo);
114 + r8169_mod_reg8_cond(tp, Config4, BIT(0), jumbo);
115 break;
116 default:
117 break;