1a27bd190fb6340ff027a4ca01e1a58f77c01c00
[openwrt/staging/wigyori.git] /
1 From 9c50139727265c088f936e496777bf588850e9f1 Mon Sep 17 00:00:00 2001
2 From: Heiner Kallweit <hkallweit1@gmail.com>
3 Date: Mon, 12 Feb 2024 19:59:26 +0100
4 Subject: [PATCH] r8169: add support for returning tx_lpi_timer in
5 ethtool get_eee
6
7 Add support for returning the tx_lpi_timer value to userspace.
8 This is supported by few chip versions only: RTL8168h/RTL8125/RTL8126
9
10 Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
11 Reviewed-by: Andrew Lunn <andrew@lunn.ch>
12 Link: https://lore.kernel.org/r/4eee9c34-c5d6-4c96-9b05-455896dea59a@gmail.com
13 Signed-off-by: Jakub Kicinski <kuba@kernel.org>
14 ---
15 drivers/net/ethernet/realtek/r8169_main.c | 22 +++++++++++++++++++++-
16 1 file changed, 21 insertions(+), 1 deletion(-)
17
18 --- a/drivers/net/ethernet/realtek/r8169_main.c
19 +++ b/drivers/net/ethernet/realtek/r8169_main.c
20 @@ -2103,14 +2103,34 @@ static void rtl_set_eee_txidle_timer(str
21 }
22 }
23
24 +static unsigned int r8169_get_tx_lpi_timer_us(struct rtl8169_private *tp)
25 +{
26 + unsigned int speed = tp->phydev->speed;
27 + unsigned int timer = tp->tx_lpi_timer;
28 +
29 + if (!timer || speed == SPEED_UNKNOWN)
30 + return 0;
31 +
32 + /* tx_lpi_timer value is in bytes */
33 + return DIV_ROUND_CLOSEST(timer * BITS_PER_BYTE, speed);
34 +}
35 +
36 static int rtl8169_get_eee(struct net_device *dev, struct ethtool_eee *data)
37 {
38 struct rtl8169_private *tp = netdev_priv(dev);
39 + int ret;
40
41 if (!rtl_supports_eee(tp))
42 return -EOPNOTSUPP;
43
44 - return phy_ethtool_get_eee(tp->phydev, data);
45 + ret = phy_ethtool_get_eee(tp->phydev, data);
46 + if (ret)
47 + return ret;
48 +
49 + data->tx_lpi_timer = r8169_get_tx_lpi_timer_us(tp);
50 + data->tx_lpi_enabled = data->tx_lpi_timer ? data->eee_enabled : false;
51 +
52 + return 0;
53 }
54
55 static int rtl8169_set_eee(struct net_device *dev, struct ethtool_eee *data)