e1d46f03a94be7cfedc532b4f7a8b85998270080
[openwrt/staging/thess.git] /
1 From 3470079687448abac42deb62774253be1d6bdef3 Mon Sep 17 00:00:00 2001
2 From: Christian Marangi <ansuelsmth@gmail.com>
3 Date: Sat, 23 Jul 2022 16:29:33 +0200
4 Subject: [PATCH 5/5] net: ethernet: stmicro: stmmac: permit MTU change with
5 interface up
6
7 Remove the limitation where the interface needs to be down to change
8 MTU by releasing and opening the stmmac driver to set the new MTU.
9 Also call the set_filter function to correctly init the port.
10 This permits to remove the EBUSY error while the ethernet port is
11 running permitting a correct MTU change if for example a DSA request
12 a MTU change for a switch CPU port.
13
14 Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
15 Signed-off-by: Jakub Kicinski <kuba@kernel.org>
16 ---
17 .../net/ethernet/stmicro/stmmac/stmmac_main.c | 30 +++++++++++++++----
18 1 file changed, 24 insertions(+), 6 deletions(-)
19
20 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
21 +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
22 @@ -5627,18 +5627,15 @@ static int stmmac_change_mtu(struct net_
23 {
24 struct stmmac_priv *priv = netdev_priv(dev);
25 int txfifosz = priv->plat->tx_fifo_size;
26 + struct stmmac_dma_conf *dma_conf;
27 const int mtu = new_mtu;
28 + int ret;
29
30 if (txfifosz == 0)
31 txfifosz = priv->dma_cap.tx_fifo_size;
32
33 txfifosz /= priv->plat->tx_queues_to_use;
34
35 - if (netif_running(dev)) {
36 - netdev_err(priv->dev, "must be stopped to change its MTU\n");
37 - return -EBUSY;
38 - }
39 -
40 if (stmmac_xdp_is_enabled(priv) && new_mtu > ETH_DATA_LEN) {
41 netdev_dbg(priv->dev, "Jumbo frames not supported for XDP\n");
42 return -EINVAL;
43 @@ -5650,8 +5647,29 @@ static int stmmac_change_mtu(struct net_
44 if ((txfifosz < new_mtu) || (new_mtu > BUF_SIZE_16KiB))
45 return -EINVAL;
46
47 - dev->mtu = mtu;
48 + if (netif_running(dev)) {
49 + netdev_dbg(priv->dev, "restarting interface to change its MTU\n");
50 + /* Try to allocate the new DMA conf with the new mtu */
51 + dma_conf = stmmac_setup_dma_desc(priv, mtu);
52 + if (IS_ERR(dma_conf)) {
53 + netdev_err(priv->dev, "failed allocating new dma conf for new MTU %d\n",
54 + mtu);
55 + return PTR_ERR(dma_conf);
56 + }
57 +
58 + stmmac_release(dev);
59 +
60 + ret = __stmmac_open(dev, dma_conf);
61 + kfree(dma_conf);
62 + if (ret) {
63 + netdev_err(priv->dev, "failed reopening the interface after MTU change\n");
64 + return ret;
65 + }
66 +
67 + stmmac_set_rx_mode(dev);
68 + }
69
70 + dev->mtu = mtu;
71 netdev_update_features(dev);
72
73 return 0;