Skip to content

Commit f951a64

Browse files
fancerPaolo Abeni
authored andcommitted
net: stmmac: Move MAC caps init to phylink MAC caps getter
After a set of recent fixes the stmmac_phy_setup() and stmmac_reinit_queues() methods have turned to having some duplicated code. Let's get rid from the duplication by moving the MAC-capabilities initialization to the PHYLINK MAC-capabilities getter. The getter is called during each network device interface open/close cycle. So the MAC-capabilities will be initialized in generic device open procedure and in case of the Tx/Rx queues re-initialization as the original code semantics implies. Signed-off-by: Serge Semin <[email protected]> Reviewed-by: Romain Gantois <[email protected]> Signed-off-by: Paolo Abeni <[email protected]>
1 parent dc144ba commit f951a64

File tree

1 file changed

+17
-19
lines changed

1 file changed

+17
-19
lines changed

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

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -936,6 +936,22 @@ static void stmmac_mac_flow_ctrl(struct stmmac_priv *priv, u32 duplex)
936936
priv->pause, tx_cnt);
937937
}
938938

939+
static unsigned long stmmac_mac_get_caps(struct phylink_config *config,
940+
phy_interface_t interface)
941+
{
942+
struct stmmac_priv *priv = netdev_priv(to_net_dev(config->dev));
943+
944+
/* Refresh the MAC-specific capabilities */
945+
stmmac_mac_update_caps(priv);
946+
947+
config->mac_capabilities = priv->hw->link.caps;
948+
949+
if (priv->plat->max_speed)
950+
phylink_limit_mac_speed(config, priv->plat->max_speed);
951+
952+
return config->mac_capabilities;
953+
}
954+
939955
static struct phylink_pcs *stmmac_mac_select_pcs(struct phylink_config *config,
940956
phy_interface_t interface)
941957
{
@@ -1102,6 +1118,7 @@ static void stmmac_mac_link_up(struct phylink_config *config,
11021118
}
11031119

11041120
static const struct phylink_mac_ops stmmac_phylink_mac_ops = {
1121+
.mac_get_caps = stmmac_mac_get_caps,
11051122
.mac_select_pcs = stmmac_mac_select_pcs,
11061123
.mac_config = stmmac_mac_config,
11071124
.mac_link_down = stmmac_mac_link_down,
@@ -1201,7 +1218,6 @@ static int stmmac_phy_setup(struct stmmac_priv *priv)
12011218
int mode = priv->plat->phy_interface;
12021219
struct fwnode_handle *fwnode;
12031220
struct phylink *phylink;
1204-
int max_speed;
12051221

12061222
priv->phylink_config.dev = &priv->dev->dev;
12071223
priv->phylink_config.type = PHYLINK_NETDEV;
@@ -1225,15 +1241,6 @@ static int stmmac_phy_setup(struct stmmac_priv *priv)
12251241
xpcs_get_interfaces(priv->hw->xpcs,
12261242
priv->phylink_config.supported_interfaces);
12271243

1228-
/* Refresh the MAC-specific capabilities */
1229-
stmmac_mac_update_caps(priv);
1230-
1231-
priv->phylink_config.mac_capabilities = priv->hw->link.caps;
1232-
1233-
max_speed = priv->plat->max_speed;
1234-
if (max_speed)
1235-
phylink_limit_mac_speed(&priv->phylink_config, max_speed);
1236-
12371244
fwnode = priv->plat->port_node;
12381245
if (!fwnode)
12391246
fwnode = dev_fwnode(priv->device);
@@ -7329,7 +7336,6 @@ int stmmac_reinit_queues(struct net_device *dev, u32 rx_cnt, u32 tx_cnt)
73297336
{
73307337
struct stmmac_priv *priv = netdev_priv(dev);
73317338
int ret = 0, i;
7332-
int max_speed;
73337339

73347340
if (netif_running(dev))
73357341
stmmac_release(dev);
@@ -7343,14 +7349,6 @@ int stmmac_reinit_queues(struct net_device *dev, u32 rx_cnt, u32 tx_cnt)
73437349
priv->rss.table[i] = ethtool_rxfh_indir_default(i,
73447350
rx_cnt);
73457351

7346-
stmmac_mac_update_caps(priv);
7347-
7348-
priv->phylink_config.mac_capabilities = priv->hw->link.caps;
7349-
7350-
max_speed = priv->plat->max_speed;
7351-
if (max_speed)
7352-
phylink_limit_mac_speed(&priv->phylink_config, max_speed);
7353-
73547352
stmmac_napi_add(dev);
73557353

73567354
if (netif_running(dev))

0 commit comments

Comments
 (0)