Skip to content

Commit 4218647

Browse files
Russell King (Oracle)kuba-moo
authored andcommitted
net: stmmac: convert to phylink managed EEE support
Convert stmmac to use phylink managed EEE support rather than delving into phylib: 1. Move the stmmac_eee_init() calls out of mac_link_down() and mac_link_up() methods into the new mac_{enable,disable}_lpi() methods. We leave the calls to stmmac_set_eee_pls() in place as these change bits which tell the EEE hardware when the link came up or down, and is used for a separate hardware timer. However, symmetrically conditionalise this with priv->dma_cap.eee. 2. Update the current LPI timer each time LPI is enabled - which we need for software-timed LPI. 3. With phylink managed EEE, phylink manages the receive clock stop configuration via phylink_config.eee_rx_clk_stop_enable. Set this appropriately which makes the call to phy_eee_rx_clock_stop() redundant. 4. From what I can work out, all supported interfaces support LPI signalling on stmmac (there's no restriction implemented.) It also appears to support LPI at all full duplex speeds at or over 100M. Set these capabilities. 5. The default timer appears to be derived from a module parameter. Set this the same, although we keep code that reconfigures the timer in stmmac_init_phy(). 6. Remove the direct call to phy_support_eee(), which phylink will do on the drivers behalf if phylink_config.eee_enabled_default is set. Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk> Reviewed-by: Jacob Keller <jacob.e.keller@intel.com> Link: https://patch.msgid.link/E1tYAEG-0014QH-9O@rmk-PC.armlinux.org.uk Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent bd691d5 commit 4218647

File tree

1 file changed

+45
-12
lines changed

1 file changed

+45
-12
lines changed

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

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -988,8 +988,8 @@ static void stmmac_mac_link_down(struct phylink_config *config,
988988
struct stmmac_priv *priv = netdev_priv(to_net_dev(config->dev));
989989

990990
stmmac_mac_set(priv, priv->ioaddr, false);
991-
stmmac_eee_init(priv, false);
992-
stmmac_set_eee_pls(priv, priv->hw, false);
991+
if (priv->dma_cap.eee)
992+
stmmac_set_eee_pls(priv, priv->hw, false);
993993

994994
if (stmmac_fpe_supported(priv))
995995
stmmac_fpe_link_state_handle(priv, false);
@@ -1096,13 +1096,8 @@ static void stmmac_mac_link_up(struct phylink_config *config,
10961096
writel(ctrl, priv->ioaddr + MAC_CTRL_REG);
10971097

10981098
stmmac_mac_set(priv, priv->ioaddr, true);
1099-
if (phy && priv->dma_cap.eee) {
1100-
phy_eee_rx_clock_stop(phy, !(priv->plat->flags &
1101-
STMMAC_FLAG_RX_CLK_RUNS_IN_LPI));
1102-
priv->tx_lpi_timer = phy->eee_cfg.tx_lpi_timer;
1103-
stmmac_eee_init(priv, phy->enable_tx_lpi);
1099+
if (priv->dma_cap.eee)
11041100
stmmac_set_eee_pls(priv, priv->hw, true);
1105-
}
11061101

11071102
if (stmmac_fpe_supported(priv))
11081103
stmmac_fpe_link_state_handle(priv, true);
@@ -1111,12 +1106,32 @@ static void stmmac_mac_link_up(struct phylink_config *config,
11111106
stmmac_hwtstamp_correct_latency(priv, priv);
11121107
}
11131108

1109+
static void stmmac_mac_disable_tx_lpi(struct phylink_config *config)
1110+
{
1111+
struct stmmac_priv *priv = netdev_priv(to_net_dev(config->dev));
1112+
1113+
stmmac_eee_init(priv, false);
1114+
}
1115+
1116+
static int stmmac_mac_enable_tx_lpi(struct phylink_config *config, u32 timer,
1117+
bool tx_clk_stop)
1118+
{
1119+
struct stmmac_priv *priv = netdev_priv(to_net_dev(config->dev));
1120+
1121+
priv->tx_lpi_timer = timer;
1122+
stmmac_eee_init(priv, true);
1123+
1124+
return 0;
1125+
}
1126+
11141127
static const struct phylink_mac_ops stmmac_phylink_mac_ops = {
11151128
.mac_get_caps = stmmac_mac_get_caps,
11161129
.mac_select_pcs = stmmac_mac_select_pcs,
11171130
.mac_config = stmmac_mac_config,
11181131
.mac_link_down = stmmac_mac_link_down,
11191132
.mac_link_up = stmmac_mac_link_up,
1133+
.mac_disable_tx_lpi = stmmac_mac_disable_tx_lpi,
1134+
.mac_enable_tx_lpi = stmmac_mac_enable_tx_lpi,
11201135
};
11211136

11221137
/**
@@ -1189,9 +1204,6 @@ static int stmmac_init_phy(struct net_device *dev)
11891204
return -ENODEV;
11901205
}
11911206

1192-
if (priv->dma_cap.eee)
1193-
phy_support_eee(phydev);
1194-
11951207
ret = phylink_connect_phy(priv->phylink, phydev);
11961208
} else {
11971209
fwnode_handle_put(phy_fwnode);
@@ -1201,7 +1213,12 @@ static int stmmac_init_phy(struct net_device *dev)
12011213
if (ret == 0) {
12021214
struct ethtool_keee eee;
12031215

1204-
/* Configure phylib's copy of the LPI timer */
1216+
/* Configure phylib's copy of the LPI timer. Normally,
1217+
* phylink_config.lpi_timer_default would do this, but there is
1218+
* a chance that userspace could change the eee_timer setting
1219+
* via sysfs before the first open. Thus, preserve existing
1220+
* behaviour.
1221+
*/
12051222
if (!phylink_ethtool_get_eee(priv->phylink, &eee)) {
12061223
eee.tx_lpi_timer = priv->tx_lpi_timer;
12071224
phylink_ethtool_set_eee(priv->phylink, &eee);
@@ -1234,6 +1251,9 @@ static int stmmac_phy_setup(struct stmmac_priv *priv)
12341251
/* Stmmac always requires an RX clock for hardware initialization */
12351252
priv->phylink_config.mac_requires_rxc = true;
12361253

1254+
if (!(priv->plat->flags & STMMAC_FLAG_RX_CLK_RUNS_IN_LPI))
1255+
priv->phylink_config.eee_rx_clk_stop_enable = true;
1256+
12371257
mdio_bus_data = priv->plat->mdio_bus_data;
12381258
if (mdio_bus_data)
12391259
priv->phylink_config.default_an_inband =
@@ -1255,6 +1275,19 @@ static int stmmac_phy_setup(struct stmmac_priv *priv)
12551275
priv->phylink_config.supported_interfaces,
12561276
pcs->supported_interfaces);
12571277

1278+
if (priv->dma_cap.eee) {
1279+
/* Assume all supported interfaces also support LPI */
1280+
memcpy(priv->phylink_config.lpi_interfaces,
1281+
priv->phylink_config.supported_interfaces,
1282+
sizeof(priv->phylink_config.lpi_interfaces));
1283+
1284+
/* All full duplex speeds above 100Mbps are supported */
1285+
priv->phylink_config.lpi_capabilities = ~(MAC_1000FD - 1) |
1286+
MAC_100FD;
1287+
priv->phylink_config.lpi_timer_default = eee_timer * 1000;
1288+
priv->phylink_config.eee_enabled_default = true;
1289+
}
1290+
12581291
fwnode = priv->plat->port_node;
12591292
if (!fwnode)
12601293
fwnode = dev_fwnode(priv->device);

0 commit comments

Comments
 (0)