1a7eed191f6cf15e3dd8fafcb839331de6fab0a8
[openwrt/staging/linusw.git] /
1 From 2ce30993831041b9dcd31eb12896be6611e8b7e2 Mon Sep 17 00:00:00 2001
2 From: Heiner Kallweit <hkallweit1@gmail.com>
3 Date: Mon, 12 Feb 2024 19:57:46 +0100
4 Subject: [PATCH] r8169: add generic rtl_set_eee_txidle_timer function
5
6 Add a generic setter for the EEE tx idle timer and use it with all
7 RTL8125/RTL8126 chip versions, in line with the vendor driver.
8 This prepares for adding EEE tx idle timer support for additional
9 chip versions.
10
11 Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
12 Reviewed-by: Andrew Lunn <andrew@lunn.ch>
13 Link: https://lore.kernel.org/r/39beed72-0dc4-4c45-8899-b72c43ab62a7@gmail.com
14 Signed-off-by: Jakub Kicinski <kuba@kernel.org>
15 ---
16 drivers/net/ethernet/realtek/r8169_main.c | 34 +++++++++++++----------
17 1 file changed, 20 insertions(+), 14 deletions(-)
18
19 --- a/drivers/net/ethernet/realtek/r8169_main.c
20 +++ b/drivers/net/ethernet/realtek/r8169_main.c
21 @@ -619,6 +619,7 @@ struct rtl8169_private {
22 struct page *Rx_databuff[NUM_RX_DESC]; /* Rx data buffers */
23 struct ring_info tx_skb[NUM_TX_DESC]; /* Tx data buffers */
24 u16 cp_cmd;
25 + u16 tx_lpi_timer;
26 u32 irq_mask;
27 int irq;
28 struct clk *clk;
29 @@ -2054,6 +2055,22 @@ static int rtl_set_coalesce(struct net_d
30 return 0;
31 }
32
33 +static void rtl_set_eee_txidle_timer(struct rtl8169_private *tp)
34 +{
35 + unsigned int timer_val = READ_ONCE(tp->dev->mtu) + ETH_HLEN + 0x20;
36 +
37 + switch (tp->mac_version) {
38 + case RTL_GIGA_MAC_VER_61:
39 + case RTL_GIGA_MAC_VER_63:
40 + case RTL_GIGA_MAC_VER_65:
41 + tp->tx_lpi_timer = timer_val;
42 + RTL_W16(tp, EEE_TXIDLE_TIMER_8125, timer_val);
43 + break;
44 + default:
45 + break;
46 + }
47 +}
48 +
49 static int rtl8169_get_eee(struct net_device *dev, struct ethtool_eee *data)
50 {
51 struct rtl8169_private *tp = netdev_priv(dev);
52 @@ -2312,14 +2329,8 @@ static void rtl8125a_config_eee_mac(stru
53 r8168_mac_ocp_modify(tp, 0xeb62, 0, BIT(2) | BIT(1));
54 }
55
56 -static void rtl8125_set_eee_txidle_timer(struct rtl8169_private *tp)
57 -{
58 - RTL_W16(tp, EEE_TXIDLE_TIMER_8125, tp->dev->mtu + ETH_HLEN + 0x20);
59 -}
60 -
61 static void rtl8125b_config_eee_mac(struct rtl8169_private *tp)
62 {
63 - rtl8125_set_eee_txidle_timer(tp);
64 r8168_mac_ocp_modify(tp, 0xe040, 0, BIT(1) | BIT(0));
65 }
66
67 @@ -3852,6 +3863,8 @@ static void rtl_hw_start(struct rtl8169
68 rtl_hw_aspm_clkreq_enable(tp, false);
69 RTL_W16(tp, CPlusCmd, tp->cp_cmd);
70
71 + rtl_set_eee_txidle_timer(tp);
72 +
73 if (tp->mac_version <= RTL_GIGA_MAC_VER_06)
74 rtl_hw_start_8169(tp);
75 else if (rtl_is_8125(tp))
76 @@ -3885,14 +3898,7 @@ static int rtl8169_change_mtu(struct net
77 dev->mtu = new_mtu;
78 netdev_update_features(dev);
79 rtl_jumbo_config(tp);
80 -
81 - switch (tp->mac_version) {
82 - case RTL_GIGA_MAC_VER_61 ... RTL_GIGA_MAC_VER_65:
83 - rtl8125_set_eee_txidle_timer(tp);
84 - break;
85 - default:
86 - break;
87 - }
88 + rtl_set_eee_txidle_timer(tp);
89
90 return 0;
91 }