From a98375924d64cba336ab31b426756c946667fdaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Lebrun?= Date: Tue, 13 Oct 2026 15:16:47 +0200 Subject: [PATCH] net: macb: use context swapping in .ndo_change_mtu() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use newly introduced context buffer management to implement .ndo_change_mtu() as a context swap: allocate new context -> reconfigure HW -> free old context. This resists memory pressure well by failing without closing the interface and it is much faster by avoiding PHY reinit. AT91 EMAC is handled differently as their buffer management is separate and they don't do NAPI. They cannot land in macb_change_mtu as they use a different ndo struct. We still defensively protect against it in code. Reviewed-by: Nicolai Buchwitz Signed-off-by: Théo Lebrun Link: https://patch.msgid.link/20261013-macb-context-v11-9-b27785167566@bootlin.com Tested-by: Nicolai Buchwitz # RPi CM5 with RP1 GEM Signed-off-by: Paolo Abeni --- drivers/net/ethernet/cadence/macb_main.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c index 6bacf3e3caab..f087f278f9e5 100644 --- a/drivers/net/ethernet/cadence/macb_main.c +++ b/drivers/net/ethernet/cadence/macb_main.c @@ -3658,11 +3658,29 @@ static int macb_close(struct net_device *netdev) static int macb_change_mtu(struct net_device *netdev, int new_mtu) { - if (netif_running(netdev)) - return -EBUSY; + struct macb *bp = netdev_priv(netdev); + bool running = netif_running(netdev); + struct macb_context *new_ctx; + + if (running) { + /* Context swapping is not supported for AT91. */ + if (bp->caps & MACB_CAPS_MACB_IS_EMAC) + return -EBUSY; + + new_ctx = macb_context_alloc(bp, new_mtu, + bp->configured_rx_ring_size, + bp->configured_tx_ring_size); + if (IS_ERR(new_ctx)) + return PTR_ERR(new_ctx); + + macb_context_swap_start(bp); + } WRITE_ONCE(netdev->mtu, new_mtu); + if (running) + macb_context_swap_end(bp, new_ctx); + return 0; }