Skip to content

Commit 239ce99

Browse files
committed
Merge branch 'r8169-extend-eee-tx-idle-timer-support'
Heiner Kallweit says: ==================== r8169: extend EEE tx idle timer support This series extends EEE tx idle timer support, and exposes the timer value to userspace. ==================== Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents be51ed1 + 9c50139 commit 239ce99

File tree

1 file changed

+46
-15
lines changed

1 file changed

+46
-15
lines changed

drivers/net/ethernet/realtek/r8169_main.c

Lines changed: 46 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,7 @@ struct rtl8169_private {
619619
struct page *Rx_databuff[NUM_RX_DESC]; /* Rx data buffers */
620620
struct ring_info tx_skb[NUM_TX_DESC]; /* Tx data buffers */
621621
u16 cp_cmd;
622+
u16 tx_lpi_timer;
622623
u32 irq_mask;
623624
int irq;
624625
struct clk *clk;
@@ -2031,14 +2032,55 @@ static int rtl_set_coalesce(struct net_device *dev,
20312032
return 0;
20322033
}
20332034

2035+
static void rtl_set_eee_txidle_timer(struct rtl8169_private *tp)
2036+
{
2037+
unsigned int timer_val = READ_ONCE(tp->dev->mtu) + ETH_HLEN + 0x20;
2038+
2039+
switch (tp->mac_version) {
2040+
case RTL_GIGA_MAC_VER_46:
2041+
case RTL_GIGA_MAC_VER_48:
2042+
tp->tx_lpi_timer = timer_val;
2043+
r8168_mac_ocp_write(tp, 0xe048, timer_val);
2044+
break;
2045+
case RTL_GIGA_MAC_VER_61:
2046+
case RTL_GIGA_MAC_VER_63:
2047+
case RTL_GIGA_MAC_VER_65:
2048+
tp->tx_lpi_timer = timer_val;
2049+
RTL_W16(tp, EEE_TXIDLE_TIMER_8125, timer_val);
2050+
break;
2051+
default:
2052+
break;
2053+
}
2054+
}
2055+
2056+
static unsigned int r8169_get_tx_lpi_timer_us(struct rtl8169_private *tp)
2057+
{
2058+
unsigned int speed = tp->phydev->speed;
2059+
unsigned int timer = tp->tx_lpi_timer;
2060+
2061+
if (!timer || speed == SPEED_UNKNOWN)
2062+
return 0;
2063+
2064+
/* tx_lpi_timer value is in bytes */
2065+
return DIV_ROUND_CLOSEST(timer * BITS_PER_BYTE, speed);
2066+
}
2067+
20342068
static int rtl8169_get_eee(struct net_device *dev, struct ethtool_keee *data)
20352069
{
20362070
struct rtl8169_private *tp = netdev_priv(dev);
2071+
int ret;
20372072

20382073
if (!rtl_supports_eee(tp))
20392074
return -EOPNOTSUPP;
20402075

2041-
return phy_ethtool_get_eee(tp->phydev, data);
2076+
ret = phy_ethtool_get_eee(tp->phydev, data);
2077+
if (ret)
2078+
return ret;
2079+
2080+
data->tx_lpi_timer = r8169_get_tx_lpi_timer_us(tp);
2081+
data->tx_lpi_enabled = data->tx_lpi_timer ? data->eee_enabled : false;
2082+
2083+
return 0;
20422084
}
20432085

20442086
static int rtl8169_set_eee(struct net_device *dev, struct ethtool_keee *data)
@@ -2289,14 +2331,8 @@ static void rtl8125a_config_eee_mac(struct rtl8169_private *tp)
22892331
r8168_mac_ocp_modify(tp, 0xeb62, 0, BIT(2) | BIT(1));
22902332
}
22912333

2292-
static void rtl8125_set_eee_txidle_timer(struct rtl8169_private *tp)
2293-
{
2294-
RTL_W16(tp, EEE_TXIDLE_TIMER_8125, tp->dev->mtu + ETH_HLEN + 0x20);
2295-
}
2296-
22972334
static void rtl8125b_config_eee_mac(struct rtl8169_private *tp)
22982335
{
2299-
rtl8125_set_eee_txidle_timer(tp);
23002336
r8168_mac_ocp_modify(tp, 0xe040, 0, BIT(1) | BIT(0));
23012337
}
23022338

@@ -3829,6 +3865,8 @@ static void rtl_hw_start(struct rtl8169_private *tp)
38293865
rtl_hw_aspm_clkreq_enable(tp, false);
38303866
RTL_W16(tp, CPlusCmd, tp->cp_cmd);
38313867

3868+
rtl_set_eee_txidle_timer(tp);
3869+
38323870
if (tp->mac_version <= RTL_GIGA_MAC_VER_06)
38333871
rtl_hw_start_8169(tp);
38343872
else if (rtl_is_8125(tp))
@@ -3862,14 +3900,7 @@ static int rtl8169_change_mtu(struct net_device *dev, int new_mtu)
38623900
dev->mtu = new_mtu;
38633901
netdev_update_features(dev);
38643902
rtl_jumbo_config(tp);
3865-
3866-
switch (tp->mac_version) {
3867-
case RTL_GIGA_MAC_VER_61 ... RTL_GIGA_MAC_VER_65:
3868-
rtl8125_set_eee_txidle_timer(tp);
3869-
break;
3870-
default:
3871-
break;
3872-
}
3903+
rtl_set_eee_txidle_timer(tp);
38733904

38743905
return 0;
38753906
}

0 commit comments

Comments
 (0)