Skip to content

Commit 3470079

Browse files
Ansuelkuba-moo
authored andcommitted
net: ethernet: stmicro: stmmac: permit MTU change with interface up
Remove the limitation where the interface needs to be down to change MTU by releasing and opening the stmmac driver to set the new MTU. Also call the set_filter function to correctly init the port. This permits to remove the EBUSY error while the ethernet port is running permitting a correct MTU change if for example a DSA request a MTU change for a switch CPU port. Signed-off-by: Christian Marangi <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]>
1 parent ba39b34 commit 3470079

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

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

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5551,18 +5551,15 @@ static int stmmac_change_mtu(struct net_device *dev, int new_mtu)
55515551
{
55525552
struct stmmac_priv *priv = netdev_priv(dev);
55535553
int txfifosz = priv->plat->tx_fifo_size;
5554+
struct stmmac_dma_conf *dma_conf;
55545555
const int mtu = new_mtu;
5556+
int ret;
55555557

55565558
if (txfifosz == 0)
55575559
txfifosz = priv->dma_cap.tx_fifo_size;
55585560

55595561
txfifosz /= priv->plat->tx_queues_to_use;
55605562

5561-
if (netif_running(dev)) {
5562-
netdev_err(priv->dev, "must be stopped to change its MTU\n");
5563-
return -EBUSY;
5564-
}
5565-
55665563
if (stmmac_xdp_is_enabled(priv) && new_mtu > ETH_DATA_LEN) {
55675564
netdev_dbg(priv->dev, "Jumbo frames not supported for XDP\n");
55685565
return -EINVAL;
@@ -5574,8 +5571,29 @@ static int stmmac_change_mtu(struct net_device *dev, int new_mtu)
55745571
if ((txfifosz < new_mtu) || (new_mtu > BUF_SIZE_16KiB))
55755572
return -EINVAL;
55765573

5577-
dev->mtu = mtu;
5574+
if (netif_running(dev)) {
5575+
netdev_dbg(priv->dev, "restarting interface to change its MTU\n");
5576+
/* Try to allocate the new DMA conf with the new mtu */
5577+
dma_conf = stmmac_setup_dma_desc(priv, mtu);
5578+
if (IS_ERR(dma_conf)) {
5579+
netdev_err(priv->dev, "failed allocating new dma conf for new MTU %d\n",
5580+
mtu);
5581+
return PTR_ERR(dma_conf);
5582+
}
55785583

5584+
stmmac_release(dev);
5585+
5586+
ret = __stmmac_open(dev, dma_conf);
5587+
kfree(dma_conf);
5588+
if (ret) {
5589+
netdev_err(priv->dev, "failed reopening the interface after MTU change\n");
5590+
return ret;
5591+
}
5592+
5593+
stmmac_set_rx_mode(dev);
5594+
}
5595+
5596+
dev->mtu = mtu;
55795597
netdev_update_features(dev);
55805598

55815599
return 0;

0 commit comments

Comments
 (0)