Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: stmmac: Modify configuration method of EEE timers

Ethtool manual stated that the tx-timer is the "the amount of time the
device should stay in idle mode prior to asserting its Tx LPI". The
previous implementation for "ethtool --set-eee tx-timer" sets the LPI TW
timer duration which is not correct. Hence, this patch fixes the
"ethtool --set-eee tx-timer" to configure the EEE LPI timer.

The LPI TW Timer will be using the defined default value instead of
"ethtool --set-eee tx-timer" which follows the EEE LS timer implementation.

Changelog V2
*Not removing/modifying the eee_timer.
*EEE LPI timer can be configured through ethtool and also the eee_timer
module param.
*EEE TW Timer will be configured with default value only, not able to be
configured through ethtool or module param. This follows the implementation
of the EEE LS Timer.

Fixes: d765955d2ae0 ("stmmac: add the Energy Efficient Ethernet support")
Signed-off-by: Vineetha G. Jaya Kumaran <vineetha.g.jaya.kumaran@intel.com>
Signed-off-by: Voon Weifeng <weifeng.voon@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Vineetha G. Jaya Kumaran and committed by
David S. Miller
388e201d ab0faf5f

+28 -9
+2
drivers/net/ethernet/stmicro/stmmac/stmmac.h
··· 203 203 int eee_enabled; 204 204 int eee_active; 205 205 int tx_lpi_timer; 206 + int tx_lpi_enabled; 207 + int eee_tw_timer; 206 208 unsigned int mode; 207 209 unsigned int chain_mode; 208 210 int extend_desc;
+11 -1
drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c
··· 665 665 edata->eee_enabled = priv->eee_enabled; 666 666 edata->eee_active = priv->eee_active; 667 667 edata->tx_lpi_timer = priv->tx_lpi_timer; 668 + edata->tx_lpi_enabled = priv->tx_lpi_enabled; 668 669 669 670 return phylink_ethtool_get_eee(priv->phylink, edata); 670 671 } ··· 679 678 if (!priv->dma_cap.eee) 680 679 return -EOPNOTSUPP; 681 680 681 + if (priv->tx_lpi_enabled != edata->tx_lpi_enabled) 682 + netdev_warn(priv->dev, 683 + "Setting EEE tx-lpi is not supported\n"); 684 + 682 685 if (!edata->eee_enabled) 683 686 stmmac_disable_eee_mode(priv); 684 687 ··· 690 685 if (ret) 691 686 return ret; 692 687 693 - priv->tx_lpi_timer = edata->tx_lpi_timer; 688 + if (edata->eee_enabled && 689 + priv->tx_lpi_timer != edata->tx_lpi_timer) { 690 + priv->tx_lpi_timer = edata->tx_lpi_timer; 691 + stmmac_eee_init(priv); 692 + } 693 + 694 694 return 0; 695 695 } 696 696
+15 -8
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
··· 94 94 static int eee_timer = STMMAC_DEFAULT_LPI_TIMER; 95 95 module_param(eee_timer, int, 0644); 96 96 MODULE_PARM_DESC(eee_timer, "LPI tx expiration time in msec"); 97 - #define STMMAC_LPI_T(x) (jiffies + msecs_to_jiffies(x)) 97 + #define STMMAC_LPI_T(x) (jiffies + usecs_to_jiffies(x)) 98 98 99 99 /* By default the driver will use the ring mode to manage tx and rx descriptors, 100 100 * but allow user to force to use the chain instead of the ring ··· 370 370 struct stmmac_priv *priv = from_timer(priv, t, eee_ctrl_timer); 371 371 372 372 stmmac_enable_eee_mode(priv); 373 - mod_timer(&priv->eee_ctrl_timer, STMMAC_LPI_T(eee_timer)); 373 + mod_timer(&priv->eee_ctrl_timer, STMMAC_LPI_T(priv->tx_lpi_timer)); 374 374 } 375 375 376 376 /** ··· 383 383 */ 384 384 bool stmmac_eee_init(struct stmmac_priv *priv) 385 385 { 386 - int tx_lpi_timer = priv->tx_lpi_timer; 386 + int eee_tw_timer = priv->eee_tw_timer; 387 387 388 388 /* Using PCS we cannot dial with the phy registers at this stage 389 389 * so we do not support extra feature like EEE. ··· 403 403 if (priv->eee_enabled) { 404 404 netdev_dbg(priv->dev, "disable EEE\n"); 405 405 del_timer_sync(&priv->eee_ctrl_timer); 406 - stmmac_set_eee_timer(priv, priv->hw, 0, tx_lpi_timer); 406 + stmmac_set_eee_timer(priv, priv->hw, 0, eee_tw_timer); 407 407 } 408 408 mutex_unlock(&priv->lock); 409 409 return false; ··· 411 411 412 412 if (priv->eee_active && !priv->eee_enabled) { 413 413 timer_setup(&priv->eee_ctrl_timer, stmmac_eee_ctrl_timer, 0); 414 - mod_timer(&priv->eee_ctrl_timer, STMMAC_LPI_T(eee_timer)); 415 414 stmmac_set_eee_timer(priv, priv->hw, STMMAC_DEFAULT_LIT_LS, 416 - tx_lpi_timer); 415 + eee_tw_timer); 417 416 } 417 + 418 + mod_timer(&priv->eee_ctrl_timer, STMMAC_LPI_T(priv->tx_lpi_timer)); 418 419 419 420 mutex_unlock(&priv->lock); 420 421 netdev_dbg(priv->dev, "Energy-Efficient Ethernet initialized\n"); ··· 931 930 932 931 stmmac_mac_set(priv, priv->ioaddr, false); 933 932 priv->eee_active = false; 933 + priv->tx_lpi_enabled = false; 934 934 stmmac_eee_init(priv); 935 935 stmmac_set_eee_pls(priv, priv->hw, false); 936 936 } ··· 1029 1027 if (phy && priv->dma_cap.eee) { 1030 1028 priv->eee_active = phy_init_eee(phy, 1) >= 0; 1031 1029 priv->eee_enabled = stmmac_eee_init(priv); 1030 + priv->tx_lpi_enabled = priv->eee_enabled; 1032 1031 stmmac_set_eee_pls(priv, priv->hw, true); 1033 1032 } 1034 1033 } ··· 2064 2061 2065 2062 if ((priv->eee_enabled) && (!priv->tx_path_in_lpi_mode)) { 2066 2063 stmmac_enable_eee_mode(priv); 2067 - mod_timer(&priv->eee_ctrl_timer, STMMAC_LPI_T(eee_timer)); 2064 + mod_timer(&priv->eee_ctrl_timer, STMMAC_LPI_T(priv->tx_lpi_timer)); 2068 2065 } 2069 2066 2070 2067 /* We still have pending packets, let's call for a new scheduling */ ··· 2697 2694 netdev_warn(priv->dev, "PTP init failed\n"); 2698 2695 } 2699 2696 2700 - priv->tx_lpi_timer = STMMAC_DEFAULT_TWT_LS; 2697 + priv->eee_tw_timer = STMMAC_DEFAULT_TWT_LS; 2698 + 2699 + /* Convert the timer from msec to usec */ 2700 + if (!priv->tx_lpi_timer) 2701 + priv->tx_lpi_timer = eee_timer * 1000; 2701 2702 2702 2703 if (priv->use_riwt) { 2703 2704 if (!priv->rx_riwt)