Article View: linux.kernel.netdev
Article #15063[PATCH net-next v7 8/9] net: bcmgenet: allow the MTU to be changed
From: Nicolai Buchwitz
Date: Thu, 12 Nov 2026 10:45
Date: Thu, 12 Nov 2026 10:45
150 lines
13774 bytes
13774 bytes
The driver never sets dev->max_mtu, so the MTU is stuck at ETH_DATA_LEN.
One descriptor reaches as far as the packet ready threshold, so derive the
maximum from it. The threshold registers are 8 bit in units of 16 bytes and
want a multiple of the 256 byte burst size. A descriptor is one page and
also holds skb_shared_info behind the frame. On 4K pages the page is the
tighter limit and leaves 3564 bytes. That includes room for a VLAN tag so a
VLAN interface can run at the parent MTU. The MAC accepts a little more
than one descriptor holds, so a double tagged frame at that maximum is
dropped as fragmented until a later patch reassembles those.
The PHY keeps running across the change so the link stays up, with its
lock held so that a link event cannot enable the MAC while the registers
change. Two MTUs at or below ETH_DATA_LEN derive the same values, so a
change between them needs no restart at all.
Only a DMA that refuses to halt still takes the interface down, because
nothing is left to run on.
Suggested-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
Link: https://github.com/raspberrypi/linux/issues/5561
Signed-off-by: Nicolai Buchwitz <nb@tipi-net.de>
---
drivers/net/ethernet/broadcom/genet/bcmgenet.c | 86 ++++++++++++++++++++++++++
1 file changed, 86 insertions(+)
diff --git a/drivers/net/ethernet/broadcom/genet/bcmgenet.c b/drivers/net/ethernet/broadcom/genet/bcmgenet.c
index 3cbffbc333dea..30ba77931c4f0 100644
--- a/drivers/net/ethernet/broadcom/genet/bcmgenet.c
+++ b/drivers/net/ethernet/broadcom/genet/bcmgenet.c
@@ -84,6 +84,12 @@
ENET_THLD_MAX * ENET_THLD_UNIT, \
ENET_THLD_PAGE_LEN)
+/* Largest MTU that fits one descriptor, with room for a VLAN tag so a VLAN
+ * interface can use the parent MTU.
+ */
+#define ENET_MAX_MTU (ENET_THLD_MAX_LEN - GENET_RBUF_ALIGN - \
+ ETH_HLEN - VLAN_HLEN)
+
/* Tx/Rx DMA register offset, skip 256 descriptors */
#define WORDS_PER_BD(p) (p->hw_params->words_per_bd)
#define DMA_DESC_SIZE (WORDS_PER_BD(priv) * sizeof(u32))
@@ -3981,6 +3987,79 @@ static int bcmgenet_change_carrier(struct net_device *dev, bool new_carrier)
return 0;
}
+static int bcmgenet_change_mtu(struct net_device *dev, int new_mtu)
+{
+ struct bcmgenet_priv *priv = netdev_priv(dev);
+ unsigned int old_mtu = dev->mtu;
+ struct bcmgenet_dma_set set;
+ int ret;
+
+ /* Below ETH_DATA_LEN everything is floored, so there is nothing to
+ * reprogram. Same when a failed resume left the datapath down.
+ */
+ if (!netif_running(dev) || !priv->tx_cbs ||
+ max_t(unsigned int, old_mtu, ETH_DATA_LEN) ==
+ max_t(unsigned int, new_mtu, ETH_DATA_LEN)) {
+ WRITE_ONCE(dev->mtu, new_mtu);
+ priv->rx_buf_len = bcmgenet_rx_buf_len(new_mtu);
+ return 0;
+ }
+
+ ret = bcmgenet_alloc_dma(priv, bcmgenet_rx_buf_len(new_mtu), &set);
+ if (ret)
+ return ret;
+
+ /* The watchdog trips on an idle queue once the rings are gone */
+ netif_device_detach(dev);
+
+ /* The PHY stays up, hold its lock. A link event would otherwise take
+ * the MAC out of reset and enable it mid rewrite.
+ */
+ mutex_lock(&dev->phydev->lock);
+ bcmgenet_netif_stop(dev, false);
+
+ WRITE_ONCE(dev->mtu, new_mtu);
+ priv->rx_buf_len = bcmgenet_rx_buf_len(new_mtu);
+ bcmgenet_set_mtu_regs(priv, new_mtu);
+
+ ret = bcmgenet_init_dma(priv, true, &set);
+ if (ret) {
+ /* The datapath is gone, do not leave the interface up */
+ netdev_err(dev, "failed to initialize DMA, closing\n");
+ WRITE_ONCE(dev->mtu, old_mtu);
+ priv->rx_buf_len = bcmgenet_rx_buf_len(old_mtu);
+ mutex_unlock(&dev->phydev->lock);
+ /* bcmgenet_close() attaches the device again */
+ netif_close(dev);
+ return ret;
+ }
+
+ bcmgenet_hfb_restore(priv);
+ bcmgenet_netif_start(dev, false);
+ mutex_unlock(&dev->phydev->lock);
+
+ /* bcmgenet_netif_start() only restores the link interrupt */
+ if (bcmgenet_has_mdio_intr(priv))
+ bcmgenet_intrl2_0_writel(priv, UMAC_IRQ_MDIO_EVENT,
+ INTRL2_CPU_MASK_CLEAR);
+
+ /* Interrupts were off, so a latched link event is lost. Internal PHYs
+ * on v1-v4 are not polled either.
+ */
+ phy_mac_interrupt(dev->phydev);
+
+ netif_device_attach(dev);
+
+ /* Filter updates that came in while the device was detached got
+ * dropped. An IPv6 join does not hold RTNL.
+ */
+ netif_addr_lock_bh(dev);
+ bcmgenet_set_rx_mode(dev);
+ netif_addr_unlock_bh(dev);
+
+ return 0;
+}
+
static const struct net_device_ops bcmgenet_netdev_ops = {
.ndo_open = bcmgenet_open,
.ndo_stop = bcmgenet_close,
@@ -3992,6 +4071,7 @@ static const struct net_device_ops bcmgenet_netdev_ops = {
.ndo_set_features = bcmgenet_set_features,
.ndo_get_stats64 = bcmgenet_get_stats64,
.ndo_change_carrier = bcmgenet_change_carrier,
+ .ndo_change_mtu = bcmgenet_change_mtu,
};
/* GENET hardware parameters/characteristics */
@@ -4345,8 +4425,14 @@ static int bcmgenet_probe(struct platform_device *pdev)
/* Mii wait queue */
init_waitqueue_head(&priv->wq);
bcmgenet_hfb_init(priv);
+
priv->rx_buf_len = bcmgenet_rx_buf_len(dev->mtu);
priv->tx_thld_len = bcmgenet_tx_pkt_rdy_thld(dev->mtu) * ENET_THLD_UNIT;
+
+ /* v1 cannot program the thresholds, so it stays at the default MTU */
+ if (!GENET_IS_V1(priv))
+ dev->max_mtu = ENET_MAX_MTU;
+
INIT_WORK(&priv->bcmgenet_irq_work, bcmgenet_irq_task);
priv->clk_wol = devm_clk_get_optional(&priv->pdev->dev, "enet-wol");
--
2.53.0
Technical Details
Message-ID:
<20261112-nb-genet-mtu-nn-v2-v7-8-43a5d90b3256@tipi-net.de>Path:
mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!nntp.comgw.net!eternal-september.org!feeder.eternal-september.org!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-361730-linux-kernel-netdev=dewy.ruReferences:
<20261112-nb-genet-mtu-nn-v2-v7-0-43a5d90b3256@tipi-net.de>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!nntp.comgw.net!eternal-september.org!feeder.eternal-september.org!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-361730-linux-kernel-netdev=dewy.ru From: nb@tipi-net.de (Nicolai Buchwitz) Newsgroups: linux.kernel.netdev Subject: [PATCH net-next v7 8/9] net: bcmgenet: allow the MTU to be changed Date: Thu, 12 Nov 2026 11:45:22 +0100 Organization: Usenet Network Message-ID: <20261112-nb-genet-mtu-nn-v2-v7-8-43a5d90b3256@tipi-net.de> References: <20261112-nb-genet-mtu-nn-v2-v7-0-43a5d90b3256@tipi-net.de> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Injection-Info: usenet.network; logging-data="1065710"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:S+4k+Sd9qjzUv2r0qlnvymOm4gc= sha256:PoTwI95nh1LTYV1cG5ThV2L7amqtPaUP6AxnJk4UPwU= sha1:F+N0FtoAieLJIIVRpGMwJbwdDzo= sha256:RYeK8D2ILbcst0uToLRnMlvE4g92z97Y1vj3fkJOuO4= List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id 63A361141CA; Thu, 12 Nov 2026 13:53:35 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.151 X-Spam-Status: No, score=-3.151 tagged_above=-9999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=tipi-net.de X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id aAdQBmc4TCeX; Thu, 12 Nov 2026 13:53:25 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-361730-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=none (p=none dis=none) header.from=tipi-net.de X-Received: from sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74]) by mail.dewy.ru (Postfix) with ESMTPS id 66F371141CD; Thu, 12 Nov 2026 13:53:16 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sto.lore.kernel.org (Postfix) with ESMTP id 35F53624C2F; Thu, 12 Nov 2026 10:46:17 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1794480333; b=cX1hdZlnND/iPtsUHQd7Y9RKFRHTj/tooyrborV8SMPPekzSqXVYEpUvxLgjalQAdwuj n2ZARjJZILsraFaXP6IXlOQNXgzSfXe9HieMGIvhUnfhMwP5vguKf9rcPSrkEoqn0m98a DUT/7GqMmrrXCklbIy9ankuvpeBoSdKd+AZwKzxtNBnHZEtB1hftnm/Dy/nrRaa7K7oHa IOfvm2NHGB588aqzGJkSS4FC+PaEa3hARFxP/XfNzIv56CeS6/R1qZAnGCVic+V7F6rcY jyOW9YVZCd4kOIa5S20+UoxxUWmVACrPhUiMoyE1Gf/oSMVoSUwkx3gK6bYfANeE5Zg== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794480333; h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:From: Date:Subject:X-Mailing-List:List-Id:List-Post:List-Help: List-Subscribe:List-Unsubscribe:List-Owner:Precedence:MIME-Version: Content-Type:Content-Transfer-Encoding:Message-Id:References: In-Reply-To:To:Cc:X-Mailer:X-Last-TLS-Session-Version; bh=xM6X2HpPl0oh2NnJvMA/KQEL/haePWW5jhVYUURKVtY=; b=rvKhqvaglRl5TVX68Bj9kjcb7Ata/TVJdu3F2vBa+BlfqqE9c79dWhIQSJJx1Oo34SZR 3EcuGhPyrDQZ11Ze0XWOwVDZBLasU881CPU0q+trDWdlHd+YXAcmGOTMWz6ceX9/2E+3t 1APRc+SDBjUcewivgVIyaMgd+zAo/vAfBjs+qrPcs5j2KMuB2UfqLD8Ve2DFm/2wRxeRa mrDYrU6RT+q7ChpUYNw0NRoM01Jx9/QtkKI0WVxkT/zd4d3fVv/qluxfzKFY0v7SafJPD k1eo3QGtAk3o8ooiMlNp7a+FMcrg3XLoTnOGEkCf0GqdEKbf+82hH3MhJDivwDD+QpA== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=tipi-net.de header.i=@tipi-net.de header.a=rsa-sha256 header.s=dkim header.b=kwsyu+FV; dmarc=none header.from=tipi-net.de; spf=pass smtp.mailfrom=tipi-net.de; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2E97060A2629; Thu, 12 Nov 2026 10:45:33 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tipi-net.de header.i=@tipi-net.de header.a=rsa-sha256 header.s=dkim header.b=kwsyu+FV X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=194.13.80.246 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794480332; b=KNEt8PBg3MnvgOZFXeAqENCv11bjZ5JgNjHxvIChqc7xxZXSHjSASDw+3xtc64OUPbS6 8QjO61LqY4I80JDSdULf9+mJtxhriWqLP1J98h4LgHK9CI3y/ipnI8fKLnWszfqSBLhdG yHCiecpJhShYYrNFC2fZs4c/hbB7tyfWf8fa8h/cijKMAhEZLb8/GiE1gIFb84pgoxX8M DTjxJrFwFO+nQxplR8+wIJ3jfgNSjS2f5bvMjE+TODtJbs+dEBFfFDhPjv1PeWG1SsCax eflR6rHkPmyhlKidJqqTeW+DPEp5P5F+MRL3AgHSiIdlxJoCgNfKsxQ23hhpOjvfweA== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794480332; h=DMARC-Filter:Received:DKIM-Signature:From:Date:Subject:MIME-Version: Content-Type:Content-Transfer-Encoding:Message-Id:References: In-Reply-To:To:Cc:X-Mailer:X-Last-TLS-Session-Version; bh=xM6X2HpPl0oh2NnJvMA/KQEL/haePWW5jhVYUURKVtY=; b=wPfeDGFxC6/VIZwwIzJccuuzzLt0G9+infokbnp/2aHbmPcIoQgxULRGRDITfcsAT3OJ K/tdb8Q3rM5mwV8/hDxmBJJaDqlCFtTwQQjyGjYteChji47871xV3XhQGuAKef5i157ye W6Gd925EGerrdCY55tpwjf+hgPUnIN/MnXt10rDODXbwNWanHHI+ulEIH6YNYHWCdmwKA mLKbvIwsN5Um1HZY4xJXe3PIz0ObseY1nmTarDvRYMmpfafetNz5lU3ZrEd/K9rrA92BJ xDrnAw0hQqFT2BRguDCyRUpIkNTj1/AY7Mt1UGumVYREELkGQp9xTwhGfMxWx0qu1vg== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=tipi-net.de; spf=pass smtp.mailfrom=tipi-net.de; dkim=pass header.d=tipi-net.de header.i=@tipi-net.de header.a=rsa-sha256 header.s=dkim header.b=kwsyu+FV; arc=none smtp.remote-ip=194.13.80.246 X-Received: from mail.tipi-net.de (mail.tipi-net.de [194.13.80.246]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AA24D60A2628; Thu, 12 Nov 2026 10:45:31 +0000 (UTC) X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org AA24D60A2628 X-Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tipi-net.de X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tipi-net.de X-Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id B50FAA1D1C; Thu, 12 Nov 2026 11:45:29 +0100 (CET) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tipi-net.de; s=dkim; t=1794480330; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=xM6X2HpPl0oh2NnJvMA/KQEL/haePWW5jhVYUURKVtY=; b=kwsyu+FVkZ9wEtg80kxFrgHvWqDv4DiWUvToesNSDXOobKG6xOrMS0cFAmpL4+f8rdFhVO 5vbx9T2BVVjv+82UpVUnUABpnM1j6sjUQw5E1F6vcZ4c6+7OLRP3qtO5ZTd09z24uvX8Xi JIBqXDG/LCVGAReZAXQURAr/cCwOYYqlpBLdylIJ7JalAuAs8GY7NOQagvbCuhhNlpnyR2 I0mJsrzGJ5DWtW1wpWlkTyFDs+aN/uo8oF+LL1v4ZLTr/hFlB9Jo5PZOIVd6PI4ipqKkPr lR4GyOtgcyPWoWQHBus2rSTrFEMyWgX5Z4nBXhzprCkH09pllmHuMRKhQV1cSQ== X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list X-In-Reply-To: <20261112-nb-genet-mtu-nn-v2-v7-0-43a5d90b3256@tipi-net.de> X-Cc: Florian Fainelli <f.fainelli@gmail.com>, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Dave Stevenson <dave.stevenson@raspberrypi.com> X-Mailer: b4 0.16.0 X-Last-TLS-Session-Version: TLSv1.3