Skip to content

Commit 1991819

Browse files
Russell King (Oracle)kuba-moo
authored andcommitted
net: stmmac: move tx_lpi_timer tracking to phylib
When stmmac_ethtool_op_get_eee() is called, stmmac sets the tx_lpi_timer and tx_lpi_enabled members, and then calls into phylink and thus phylib. phylib overwrites these members. phylib will also cause a link down/link up transition when settings that impact the MAC have been changed. Convert stmmac to use the tx_lpi_timer setting in struct phy_device, updating priv->tx_lpi_timer each time when the link comes up, rather than trying to maintain this user setting itself. We initialise the phylib tx_lpi_timer setting by doing a get_ee-modify-set_eee sequence with the last known priv->tx_lpi_timer value. In order for this to work correctly, we also need this member to be initialised earlier. As stmmac_eee_init() is no longer called outside of stmmac_main.c, make it static. Reviewed-by: Andrew Lunn <[email protected]> Tested-by: Choong Yong Liang <[email protected]> Signed-off-by: Russell King (Oracle) <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent cf33710 commit 1991819

File tree

3 files changed

+17
-19
lines changed

3 files changed

+17
-19
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,6 @@ int stmmac_dvr_probe(struct device *device,
406406
struct plat_stmmacenet_data *plat_dat,
407407
struct stmmac_resources *res);
408408
void stmmac_disable_eee_mode(struct stmmac_priv *priv);
409-
bool stmmac_eee_init(struct stmmac_priv *priv);
410409
int stmmac_reinit_queues(struct net_device *dev, u32 rx_cnt, u32 tx_cnt);
411410
int stmmac_reinit_ringparam(struct net_device *dev, u32 rx_size, u32 tx_size);
412411
int stmmac_bus_clks_config(struct stmmac_priv *priv, bool enabled);

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

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -898,7 +898,6 @@ static int stmmac_ethtool_op_get_eee(struct net_device *dev,
898898
if (!priv->dma_cap.eee)
899899
return -EOPNOTSUPP;
900900

901-
edata->tx_lpi_timer = priv->tx_lpi_timer;
902901
edata->tx_lpi_enabled = priv->tx_lpi_enabled;
903902

904903
return phylink_ethtool_get_eee(priv->phylink, edata);
@@ -908,7 +907,6 @@ static int stmmac_ethtool_op_set_eee(struct net_device *dev,
908907
struct ethtool_keee *edata)
909908
{
910909
struct stmmac_priv *priv = netdev_priv(dev);
911-
int ret;
912910

913911
if (!priv->dma_cap.eee)
914912
return -EOPNOTSUPP;
@@ -920,17 +918,7 @@ static int stmmac_ethtool_op_set_eee(struct net_device *dev,
920918
if (!edata->eee_enabled)
921919
stmmac_disable_eee_mode(priv);
922920

923-
ret = phylink_ethtool_set_eee(priv->phylink, edata);
924-
if (ret)
925-
return ret;
926-
927-
if (edata->eee_enabled &&
928-
priv->tx_lpi_timer != edata->tx_lpi_timer) {
929-
priv->tx_lpi_timer = edata->tx_lpi_timer;
930-
stmmac_eee_init(priv);
931-
}
932-
933-
return 0;
921+
return phylink_ethtool_set_eee(priv->phylink, edata);
934922
}
935923

936924
static u32 stmmac_usec2riwt(u32 usec, struct stmmac_priv *priv)

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

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ static void stmmac_eee_ctrl_timer(struct timer_list *t)
469469
* can also manage EEE, this function enable the LPI state and start related
470470
* timer.
471471
*/
472-
bool stmmac_eee_init(struct stmmac_priv *priv)
472+
static bool stmmac_eee_init(struct stmmac_priv *priv)
473473
{
474474
int eee_tw_timer = priv->eee_tw_timer;
475475

@@ -1088,6 +1088,7 @@ static void stmmac_mac_link_up(struct phylink_config *config,
10881088
priv->eee_active =
10891089
phy_init_eee(phy, !(priv->plat->flags &
10901090
STMMAC_FLAG_RX_CLK_RUNS_IN_LPI)) >= 0;
1091+
priv->tx_lpi_timer = phy->eee_cfg.tx_lpi_timer;
10911092
priv->eee_enabled = stmmac_eee_init(priv);
10921093
priv->tx_lpi_enabled = priv->eee_enabled;
10931094
stmmac_set_eee_pls(priv, priv->hw, true);
@@ -1187,6 +1188,16 @@ static int stmmac_init_phy(struct net_device *dev)
11871188
ret = phylink_fwnode_phy_connect(priv->phylink, fwnode, 0);
11881189
}
11891190

1191+
if (ret == 0) {
1192+
struct ethtool_keee eee;
1193+
1194+
/* Configure phylib's copy of the LPI timer */
1195+
if (!phylink_ethtool_get_eee(priv->phylink, &eee)) {
1196+
eee.tx_lpi_timer = priv->tx_lpi_timer;
1197+
phylink_ethtool_set_eee(priv->phylink, &eee);
1198+
}
1199+
}
1200+
11901201
if (!priv->plat->pmt) {
11911202
struct ethtool_wolinfo wol = { .cmd = ETHTOOL_GWOL };
11921203

@@ -3454,10 +3465,6 @@ static int stmmac_hw_setup(struct net_device *dev, bool ptp_register)
34543465

34553466
priv->eee_tw_timer = STMMAC_DEFAULT_TWT_LS;
34563467

3457-
/* Convert the timer from msec to usec */
3458-
if (!priv->tx_lpi_timer)
3459-
priv->tx_lpi_timer = eee_timer * 1000;
3460-
34613468
if (priv->use_riwt) {
34623469
u32 queue;
34633470

@@ -3924,6 +3931,10 @@ static int __stmmac_open(struct net_device *dev,
39243931
u32 chan;
39253932
int ret;
39263933

3934+
/* Initialise the tx lpi timer, converting from msec to usec */
3935+
if (!priv->tx_lpi_timer)
3936+
priv->tx_lpi_timer = eee_timer * 1000;
3937+
39273938
ret = pm_runtime_resume_and_get(priv->device);
39283939
if (ret < 0)
39293940
return ret;

0 commit comments

Comments
 (0)