775-v6.0-05-net-ethernet-stmicro-stmmac-permit-MTU-change-with-i.patch 2.3 KB

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