Skip to content

Commit 388e201

Browse files
vgjayakudavem330
authored andcommitted
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: d765955 ("stmmac: add the Energy Efficient Ethernet support") Signed-off-by: Vineetha G. Jaya Kumaran <[email protected]> Signed-off-by: Voon Weifeng <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent ab0faf5 commit 388e201

File tree

3 files changed

+28
-9
lines changed

3 files changed

+28
-9
lines changed

drivers/net/ethernet/stmicro/stmmac/stmmac.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,8 @@ struct stmmac_priv {
203203
int eee_enabled;
204204
int eee_active;
205205
int tx_lpi_timer;
206+
int tx_lpi_enabled;
207+
int eee_tw_timer;
206208
unsigned int mode;
207209
unsigned int chain_mode;
208210
int extend_desc;

drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,7 @@ static int stmmac_ethtool_op_get_eee(struct net_device *dev,
665665
edata->eee_enabled = priv->eee_enabled;
666666
edata->eee_active = priv->eee_active;
667667
edata->tx_lpi_timer = priv->tx_lpi_timer;
668+
edata->tx_lpi_enabled = priv->tx_lpi_enabled;
668669

669670
return phylink_ethtool_get_eee(priv->phylink, edata);
670671
}
@@ -678,14 +679,23 @@ static int stmmac_ethtool_op_set_eee(struct net_device *dev,
678679
if (!priv->dma_cap.eee)
679680
return -EOPNOTSUPP;
680681

682+
if (priv->tx_lpi_enabled != edata->tx_lpi_enabled)
683+
netdev_warn(priv->dev,
684+
"Setting EEE tx-lpi is not supported\n");
685+
681686
if (!edata->eee_enabled)
682687
stmmac_disable_eee_mode(priv);
683688

684689
ret = phylink_ethtool_set_eee(priv->phylink, edata);
685690
if (ret)
686691
return ret;
687692

688-
priv->tx_lpi_timer = edata->tx_lpi_timer;
693+
if (edata->eee_enabled &&
694+
priv->tx_lpi_timer != edata->tx_lpi_timer) {
695+
priv->tx_lpi_timer = edata->tx_lpi_timer;
696+
stmmac_eee_init(priv);
697+
}
698+
689699
return 0;
690700
}
691701

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ static const u32 default_msg_level = (NETIF_MSG_DRV | NETIF_MSG_PROBE |
9494
static int eee_timer = STMMAC_DEFAULT_LPI_TIMER;
9595
module_param(eee_timer, int, 0644);
9696
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))
9898

9999
/* By default the driver will use the ring mode to manage tx and rx descriptors,
100100
* but allow user to force to use the chain instead of the ring
@@ -370,7 +370,7 @@ static void stmmac_eee_ctrl_timer(struct timer_list *t)
370370
struct stmmac_priv *priv = from_timer(priv, t, eee_ctrl_timer);
371371

372372
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));
374374
}
375375

376376
/**
@@ -383,7 +383,7 @@ static void stmmac_eee_ctrl_timer(struct timer_list *t)
383383
*/
384384
bool stmmac_eee_init(struct stmmac_priv *priv)
385385
{
386-
int tx_lpi_timer = priv->tx_lpi_timer;
386+
int eee_tw_timer = priv->eee_tw_timer;
387387

388388
/* Using PCS we cannot dial with the phy registers at this stage
389389
* so we do not support extra feature like EEE.
@@ -403,19 +403,20 @@ bool stmmac_eee_init(struct stmmac_priv *priv)
403403
if (priv->eee_enabled) {
404404
netdev_dbg(priv->dev, "disable EEE\n");
405405
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);
407407
}
408408
mutex_unlock(&priv->lock);
409409
return false;
410410
}
411411

412412
if (priv->eee_active && !priv->eee_enabled) {
413413
timer_setup(&priv->eee_ctrl_timer, stmmac_eee_ctrl_timer, 0);
414-
mod_timer(&priv->eee_ctrl_timer, STMMAC_LPI_T(eee_timer));
415414
stmmac_set_eee_timer(priv, priv->hw, STMMAC_DEFAULT_LIT_LS,
416-
tx_lpi_timer);
415+
eee_tw_timer);
417416
}
418417

418+
mod_timer(&priv->eee_ctrl_timer, STMMAC_LPI_T(priv->tx_lpi_timer));
419+
419420
mutex_unlock(&priv->lock);
420421
netdev_dbg(priv->dev, "Energy-Efficient Ethernet initialized\n");
421422
return true;
@@ -930,6 +931,7 @@ static void stmmac_mac_link_down(struct phylink_config *config,
930931

931932
stmmac_mac_set(priv, priv->ioaddr, false);
932933
priv->eee_active = false;
934+
priv->tx_lpi_enabled = false;
933935
stmmac_eee_init(priv);
934936
stmmac_set_eee_pls(priv, priv->hw, false);
935937
}
@@ -1027,6 +1029,7 @@ static void stmmac_mac_link_up(struct phylink_config *config,
10271029
if (phy && priv->dma_cap.eee) {
10281030
priv->eee_active = phy_init_eee(phy, 1) >= 0;
10291031
priv->eee_enabled = stmmac_eee_init(priv);
1032+
priv->tx_lpi_enabled = priv->eee_enabled;
10301033
stmmac_set_eee_pls(priv, priv->hw, true);
10311034
}
10321035
}
@@ -2061,7 +2064,7 @@ static int stmmac_tx_clean(struct stmmac_priv *priv, int budget, u32 queue)
20612064

20622065
if ((priv->eee_enabled) && (!priv->tx_path_in_lpi_mode)) {
20632066
stmmac_enable_eee_mode(priv);
2064-
mod_timer(&priv->eee_ctrl_timer, STMMAC_LPI_T(eee_timer));
2067+
mod_timer(&priv->eee_ctrl_timer, STMMAC_LPI_T(priv->tx_lpi_timer));
20652068
}
20662069

20672070
/* We still have pending packets, let's call for a new scheduling */
@@ -2694,7 +2697,11 @@ static int stmmac_hw_setup(struct net_device *dev, bool init_ptp)
26942697
netdev_warn(priv->dev, "PTP init failed\n");
26952698
}
26962699

2697-
priv->tx_lpi_timer = STMMAC_DEFAULT_TWT_LS;
2700+
priv->eee_tw_timer = STMMAC_DEFAULT_TWT_LS;
2701+
2702+
/* Convert the timer from msec to usec */
2703+
if (!priv->tx_lpi_timer)
2704+
priv->tx_lpi_timer = eee_timer * 1000;
26982705

26992706
if (priv->use_riwt) {
27002707
if (!priv->rx_riwt)

0 commit comments

Comments
 (0)