Article View: linux.kernel.netdev
Article #10203[PATCH net-next v6 8/9] net: bcmgenet: allow the MTU to be changed
From: Nicolai Buchwitz
Date: Tue, 03 Nov 2026 10:05
Date: Tue, 03 Nov 2026 10:05
152 lines
13814 bytes
13814 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, nothing is
left to run on then.
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 | 88 ++++++++++++++++++++++++++
1 file changed, 88 insertions(+)
diff --git a/drivers/net/ethernet/broadcom/genet/bcmgenet.c b/drivers/net/ethernet/broadcom/genet/bcmgenet.c
index f6ed15bb1a91c..e42de63fac14d 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))
@@ -3965,6 +3971,81 @@ 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) {
+ /* Take it down here, or close and suspend tear it down twice */
+ 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);
+ netif_close(dev);
+
+ /* __dev_open() refuses a detached device */
+ netif_device_attach(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,
@@ -3976,6 +4057,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 */
@@ -4329,8 +4411,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:
<20261103-nb-genet-mtu-nn-v2-v6-8-61d5631676e5@tipi-net.de>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-355373-linux-kernel-netdev=dewy.ruReferences:
<20261103-nb-genet-mtu-nn-v2-v6-0-61d5631676e5@tipi-net.de>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-355373-linux-kernel-netdev=dewy.ru From: nb@tipi-net.de (Nicolai Buchwitz) Newsgroups: linux.kernel.netdev Subject: [PATCH net-next v6 8/9] net: bcmgenet: allow the MTU to be changed Date: Tue, 03 Nov 2026 11:05:02 +0100 Organization: Usenet Network Message-ID: <20261103-nb-genet-mtu-nn-v2-v6-8-61d5631676e5@tipi-net.de> References: <20261103-nb-genet-mtu-nn-v2-v6-0-61d5631676e5@tipi-net.de> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Injection-Info: usenet.network; logging-data="3142594"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:QOjb0bnytxQkt3S2+A8pl7zOdN0= sha256:ZMBDDjsc1DjDoD2V9ajjRNycoagkl8pv89+RTE/RZXA= sha1:og8ZgXwPip3flMz8hLg5Aj966iQ= sha256:0hr9y7dwbmjmDKkSk6cra0X8sj6Np99yJ9SWljBGajw= 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 7244C1127E7; Tue, 3 Nov 2026 13:31:06 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.051 X-Spam-Status: No, score=-3.051 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, 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 bCCwTrUVWeXN; Tue, 3 Nov 2026 13:31:03 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-355373-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 tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mail.dewy.ru (Postfix) with ESMTPS id 38ACF1127DD; Tue, 3 Nov 2026 13:30:55 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by tor.lore.kernel.org (Postfix) with ESMTP id 9B4CB60C72; Tue, 3 Nov 2026 10:08:13 +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=1793700337; b=uNS9MhLOTow5PH0G5Vu7T9iMKue8D+Rxl3/BPe4128numuOspBC7DSFyRN8qiYDSq6ay aleCTlcowW87Z+pdo/HxuA5vlFYxQKT1t96WBBR0pORfZYciyUzI3Ok49SNISKMxYy0ru zdyR6pc9Rof91fwRRf2o3DLBBzj9M16HCuNCfKdTbc/SLwMDvSadJZf69/A2QvwHg+fk+ jv0LVlpFC4JDrEOXZ9KpLe2rm16VXojgNI6/elK7kvZDVyGXhVvKATEzQTwuwF8LAusnE xzEfaAnb6n99FWuiool3dcLO7Vafqb4RX6WgnoOQ6dV1n9ZbeORi6XPN//O5hjO7MrQ== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793700337; 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=crorAxXvnKsE7T5XLx1xJ9nM/l4kKcvMxg6tXRH0Qrk=; b=dYvZqaEcIsoqDPmes0a8ERajuDTLlkZdff+acGVjxhBw9lsfAqBQkeDm6YTYvF23joVy 1/qnUuw/pigQVCogBgJvNQ0kF2ryVDHowl3zYBqgeljsx5acHLaqnDJPqvzX60OEVwu/7 /SyTkjBX/1lMAJrCsA8egZUQUGl2GzAb9tAtBsIf+T5D1di4G8Ak/XJ9KMbjcgSZZzg3l dJKPk4+Z9hgfENYxAAL2wLPTtiNoJ9o+u7nF7bTdOzwVL6GLpNjxZfIgNdQdShCt0LMf2 fhDXWoKghbP1BA3NFBAF9hIZiU1LYleN4Bakon0uiyUFd3LF/GILkBhq55pvRJH/uVA== 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=497tw1HG; 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 3189260A2606; Tue, 3 Nov 2026 10:05:37 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=tipi-net.de header.i=@tipi-net.de header.a=rsa-sha256 header.s=dkim header.b=497tw1HG 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=1793700332; b=ZQiaE6W1qbdWATwX3SzAjW81XzAKrlF/MguDlV9rpQOWQwrnRD86qZPaAhvGsX5Uj4ow zuItu2grmZlnIKRp6s+JOeM/fmg2i70XA1RLFeKCXbGlPkwgpiYdWRekdM1EJ+JAG7fYv P8OHJXPPT/30G8CCZCl5WlR5QtSCIXWi1gOMmH4sakl9Yr2yjVVUCXXDbqC7S3zftnBbl laMatZpO58Sg8w9Pol/oXxGyBB8jO+lIJOYr1Ney4EjQJx81B8p0UCor6JV6kgFK5wRjw NGAOOBuVxk2OIc9I7ra0VFr4bXfwgVN1q5zUG1Bv/bBIkmA28ubNsDmkOg+h0SqAWlQ== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793700332; 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=crorAxXvnKsE7T5XLx1xJ9nM/l4kKcvMxg6tXRH0Qrk=; b=nv7oyp8KeO9vh1ipbftcmZbOw64h9ctOjorE5Kkd3/absZFSmR+HnC1YZUc4vkY5tNYf w8+FIphTUUsTtdXRp6oFW8K5v/lDgDa9iAJyKu1k6iEXePsXa+COkxkbzGduFt/J6tYL4 7AP1RUoV9QD0rvfuxKiMTUrmyUtKdA5TujujCyoK02a09PSefvALQcAbbvCaFHiP+PK0D 7VcDeXpC88zx3+0ZeQ4dMQWfsEsHSEbfynb71It45Uw4RP/s1qX3bnkRAb/lcY6U5Bn3u uUh+oDXiNtpiUQ3tgUUbc7XvrGEUxBFsWOXxn8Mo/7OK7tomWC326fhoLYTkqVFDxFA== 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=497tw1HG; 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 33F55606A827; Tue, 3 Nov 2026 10:05:32 +0000 (UTC) X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 33F55606A827 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 08C1FA1651; Tue, 03 Nov 2026 11:05:30 +0100 (CET) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tipi-net.de; s=dkim; t=1793700330; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=crorAxXvnKsE7T5XLx1xJ9nM/l4kKcvMxg6tXRH0Qrk=; b=497tw1HG5tTvPHnKBcyLAHMQUIaLSVTHFgVkIHqnaFIwgR8ebbEXDhdlkHxi9jPN9+84an MBs6izTJyvlsQE7oAqluFd6srtrXEWr4Hcv+k2HiZkutjMEYEZLWombC3ZvWGujIpCjald x4vXIYF396TC1SxAQU4EBuylC3oErp1wJXfRnchjOwei0V/WQBE03v+VLFSSuhLAq3vESz 3w6hmPaeTNAfakkI8AyzxR57uoqJQlr6byagRjp3qPEC94AiQvL1bNf3wmHGwMGyIKG4vH 8Wwl/xstxV2OAAiPzPvcf0HCIsXFK2kn4QN53VTt1prcIsA+vLp9Hw/iZMVssw== 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: <20261103-nb-genet-mtu-nn-v2-v6-0-61d5631676e5@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