* [PATCH net-next v10 1/8] net: bcmgenet: let the caller decide whether to start the PHY
2026-11-27 11:25 [PATCH net-next v10 0/8] net: bcmgenet: support larger MTUs Nicolai Buchwitz
@ 2026-11-27 11:25 ` Nicolai Buchwitz
2026-11-27 11:25 ` [PATCH net-next v10 2/8] net: bcmgenet: allow a continuation descriptor without the alignment pad Nicolai Buchwitz
` (6 subsequent siblings)
7 siblings, 0 replies; 18+ messages in thread
From: Nicolai Buchwitz @ 2026-11-27 11:25 UTC (permalink / raw)
To: Doug Berger, Florian Fainelli, Nicolai Buchwitz,
Broadcom internal kernel review list, Andrew Lunn,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: Florian Fainelli, netdev, linux-kernel
bcmgenet_netif_stop() already takes stop_phy, bcmgenet_netif_start() does
not. The MTU change in a later patch leaves the PHY running while the
datapath goes down and comes back, and phy_start() expects a stopped PHY.
Add the same parameter to the start side.
No functional change.
Signed-off-by: Nicolai Buchwitz <nb@tipi-net.de>
Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com>
---
drivers/net/ethernet/broadcom/genet/bcmgenet.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/drivers/net/ethernet/broadcom/genet/bcmgenet.c b/drivers/net/ethernet/broadcom/genet/bcmgenet.c
index 1f2d85b37b0f..7e78db243442 100644
--- a/drivers/net/ethernet/broadcom/genet/bcmgenet.c
+++ b/drivers/net/ethernet/broadcom/genet/bcmgenet.c
@@ -3392,7 +3392,7 @@ static void bcmgenet_get_hw_addr(struct bcmgenet_priv *priv,
put_unaligned_be16(addr_tmp, &addr[4]);
}
-static void bcmgenet_netif_start(struct net_device *dev)
+static void bcmgenet_netif_start(struct net_device *dev, bool start_phy)
{
struct bcmgenet_priv *priv = netdev_priv(dev);
@@ -3409,7 +3409,8 @@ static void bcmgenet_netif_start(struct net_device *dev)
/* Monitor link interrupts now */
bcmgenet_link_intr_enable(priv);
- phy_start(dev->phydev);
+ if (start_phy)
+ phy_start(dev->phydev);
}
static int bcmgenet_open(struct net_device *dev)
@@ -3472,7 +3473,7 @@ static int bcmgenet_open(struct net_device *dev)
bcmgenet_phy_pause_set(dev, priv->rx_pause, priv->tx_pause);
- bcmgenet_netif_start(dev);
+ bcmgenet_netif_start(dev, true);
netif_tx_start_all_queues(dev);
@@ -4371,7 +4372,7 @@ static int bcmgenet_resume(struct device *d)
if (!device_may_wakeup(d))
phy_resume(dev->phydev);
- bcmgenet_netif_start(dev);
+ bcmgenet_netif_start(dev, true);
netif_device_attach(dev);
--
2.53.0
^ permalink raw reply related [flat|nested] 18+ messages in thread* [PATCH net-next v10 2/8] net: bcmgenet: allow a continuation descriptor without the alignment pad
2026-11-27 11:25 [PATCH net-next v10 0/8] net: bcmgenet: support larger MTUs Nicolai Buchwitz
2026-11-27 11:25 ` [PATCH net-next v10 1/8] net: bcmgenet: let the caller decide whether to start the PHY Nicolai Buchwitz
@ 2026-11-27 11:25 ` Nicolai Buchwitz
2026-11-28 11:26 ` netdev-bot+sashiko
2026-11-27 11:25 ` [PATCH net-next v10 3/8] net: bcmgenet: rename ENET_MAX_MTU_SIZE to ENET_MAX_FRAME_LEN Nicolai Buchwitz
` (5 subsequent siblings)
7 siblings, 1 reply; 18+ messages in thread
From: Nicolai Buchwitz @ 2026-11-27 11:25 UTC (permalink / raw)
To: Doug Berger, Florian Fainelli, Nicolai Buchwitz,
Broadcom internal kernel review list, Andrew Lunn,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: Florian Fainelli, netdev, linux-kernel, Pierre-Marin Leclercq
A frame longer than the packet ready threshold arrives in several
descriptors, each with its own status block. Only the first one also
carries the two alignment bytes. The length check assumes the pad is always
there, so a continuation holding a single byte looks a byte too short and
the whole frame is dropped.
Account for the pad on the first descriptor only.
The MTU cannot produce a frame past the threshold yet, so nothing hits this
today. It is preparation for the larger MTU.
Tested-by: Pierre-Marin Leclercq <pierremarinleclercq88@gmail.com>
Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com>
Signed-off-by: Nicolai Buchwitz <nb@tipi-net.de>
---
drivers/net/ethernet/broadcom/genet/bcmgenet.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/broadcom/genet/bcmgenet.c b/drivers/net/ethernet/broadcom/genet/bcmgenet.c
index 7e78db243442..67296eb22a5c 100644
--- a/drivers/net/ethernet/broadcom/genet/bcmgenet.c
+++ b/drivers/net/ethernet/broadcom/genet/bcmgenet.c
@@ -53,7 +53,8 @@
/* Page pool RX buffer layout:
* RSB(64) + pad(2) | frame data | skb_shared_info
- * The HW writes the 64B RSB + 2B alignment padding before the frame.
+ * The HW writes the 64B RSB before every descriptor of a frame. Only the
+ * first one also gets the 2B alignment padding.
*/
#define GENET_RSB_PAD (sizeof(struct status_64) + 2)
@@ -2358,6 +2359,7 @@ static unsigned int bcmgenet_desc_rx(struct bcmgenet_rx_ring *ring,
unsigned int rx_offset, rx_size;
struct status_64 *status;
struct page *rx_page;
+ unsigned int min_len;
void *hard_start;
__be16 rx_csum;
@@ -2394,8 +2396,12 @@ static unsigned int bcmgenet_desc_rx(struct bcmgenet_rx_ring *ring,
__func__, p_index, ring->c_index,
ring->read_ptr, dma_length_status);
+ /* Only the first descriptor carries the alignment pad */
+ min_len = dma_flag & DMA_SOP ? GENET_RSB_PAD
+ : sizeof(struct status_64);
+
/* Reject lengths that would underflow the SKB build path. */
- if (unlikely(len > RX_BUF_LENGTH || len < GENET_RSB_PAD)) {
+ if (unlikely(len > RX_BUF_LENGTH || len < min_len)) {
netif_err(priv, rx_status, dev,
"invalid packet length %d\n", len);
BCMGENET_STATS64_INC(stats, length_errors);
--
2.53.0
^ permalink raw reply related [flat|nested] 18+ messages in thread* Re: [PATCH net-next v10 2/8] net: bcmgenet: allow a continuation descriptor without the alignment pad
2026-11-27 11:25 ` [PATCH net-next v10 2/8] net: bcmgenet: allow a continuation descriptor without the alignment pad Nicolai Buchwitz
@ 2026-11-28 11:26 ` netdev-bot+sashiko
0 siblings, 0 replies; 18+ messages in thread
From: netdev-bot+sashiko @ 2026-11-28 11:26 UTC (permalink / raw)
To: nb
Cc: opendmb, florian.fainelli, bcm-kernel-feedback-list,
andrew+netdev, davem, edumazet, kuba, pabeni, f.fainelli, netdev,
linux-kernel, pierremarinleclercq88, dave.stevenson, justin.chen
Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] Concern: after this patch, the length check in bcmgenet_desc_rx()
(drivers/net/ethernet/broadcom/genet/bcmgenet.c), commented "Reject…
--
net: bcmgenet: allow a continuation descriptor without the alignment pad
This patch changes the RX length check in bcmgenet_desc_rx(). Only
descriptors with DMA_SOP now need room for the 64 byte status block plus
the 2 byte alignment pad. Continuation descriptors only need room for the
64 byte status block. The patch prepares for a larger MTU.
> diff --git a/drivers/net/ethernet/broadcom/genet/bcmgenet.c b/drivers/net/ethernet/broadcom/genet/bcmgenet.c
> index 7e78db243442c..67296eb22a5c3 100644
> --- a/drivers/net/ethernet/broadcom/genet/bcmgenet.c
> +++ b/drivers/net/ethernet/broadcom/genet/bcmgenet.c
[ ... ]
> @@ -2394,8 +2396,12 @@ static unsigned int bcmgenet_desc_rx(struct bcmgenet_rx_ring *ring,
> __func__, p_index, ring->c_index,
> ring->read_ptr, dma_length_status);
>
> + /* Only the first descriptor carries the alignment pad */
> + min_len = dma_flag & DMA_SOP ? GENET_RSB_PAD
> + : sizeof(struct status_64);
> +
> /* Reject lengths that would underflow the SKB build path. */
> - if (unlikely(len > RX_BUF_LENGTH || len < GENET_RSB_PAD)) {
> + if (unlikely(len > RX_BUF_LENGTH || len < min_len)) {
[Severity: Low]
The comment above this check still says it rejects lengths that would
underflow the SKB build path. For a non-SOP descriptor, though, it now
accepts len values of 64 and 65.
Further down in bcmgenet_desc_rx(), the build path always subtracts the
full 66 byte GENET_RSB_PAD:
skb_reserve(skb, GENET_RSB_PAD);
__skb_put(skb, len - GENET_RSB_PAD);
At this commit, only the fragmented drop that comes next keeps such a
descriptor away from that subtraction:
if (unlikely(!(dma_flag & DMA_EOP) || !(dma_flag & DMA_SOP))) {
So nothing can be hit at runtime here. Still, is it intended that the
guard and the build path disagree at this point in the series?
Later in the series, "net: bcmgenet: reassemble jumbo frames from status
block fragments" sends non-SOP descriptors to bcmgenet_add_frag(), which
subtracts sizeof(struct status_64). That commit also raises the non-SOP
minimum to sizeof(struct status_64) + 1, which brings the guard and both
build paths back in line.
The commit message describes a continuation "holding a single byte", which
is a len of 65. A len of 64, with no data bytes, also passes this check.
Would it make sense to use sizeof(struct status_64) + 1 here already, or
to adjust the comment in this patch?
> netif_err(priv, rx_status, dev,
> "invalid packet length %d\n", len);
> BCMGENET_STATS64_INC(stats, length_errors);
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261127-nb-genet-mtu-nn-v2-v10-0-749c7cc45d97%40tipi-net.de
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH net-next v10 3/8] net: bcmgenet: rename ENET_MAX_MTU_SIZE to ENET_MAX_FRAME_LEN
2026-11-27 11:25 [PATCH net-next v10 0/8] net: bcmgenet: support larger MTUs Nicolai Buchwitz
2026-11-27 11:25 ` [PATCH net-next v10 1/8] net: bcmgenet: let the caller decide whether to start the PHY Nicolai Buchwitz
2026-11-27 11:25 ` [PATCH net-next v10 2/8] net: bcmgenet: allow a continuation descriptor without the alignment pad Nicolai Buchwitz
@ 2026-11-27 11:25 ` Nicolai Buchwitz
2026-11-28 11:26 ` netdev-bot+sashiko
2026-11-27 11:25 ` [PATCH net-next v10 4/8] net: bcmgenet: derive the receive buffer length from the MTU Nicolai Buchwitz
` (4 subsequent siblings)
7 siblings, 1 reply; 18+ messages in thread
From: Nicolai Buchwitz @ 2026-11-27 11:25 UTC (permalink / raw)
To: Doug Berger, Florian Fainelli, Nicolai Buchwitz,
Broadcom internal kernel review list, Andrew Lunn,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: Florian Fainelli, netdev, linux-kernel
ENET_MAX_MTU_SIZE holds a frame length, not an MTU. Both users program it
into hardware that expects a frame length. The name is wrong once the MTU
is no longer fixed at ETH_DATA_LEN.
No functional change.
Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com>
Signed-off-by: Nicolai Buchwitz <nb@tipi-net.de>
---
drivers/net/ethernet/broadcom/genet/bcmgenet.c | 4 ++--
drivers/net/ethernet/broadcom/genet/bcmgenet.h | 7 +++----
2 files changed, 5 insertions(+), 6 deletions(-)
diff --git a/drivers/net/ethernet/broadcom/genet/bcmgenet.c b/drivers/net/ethernet/broadcom/genet/bcmgenet.c
index 67296eb22a5c..5c050331da69 100644
--- a/drivers/net/ethernet/broadcom/genet/bcmgenet.c
+++ b/drivers/net/ethernet/broadcom/genet/bcmgenet.c
@@ -2669,7 +2669,7 @@ static void init_umac(struct bcmgenet_priv *priv)
UMAC_MIB_CTRL);
bcmgenet_umac_writel(priv, 0, UMAC_MIB_CTRL);
- bcmgenet_umac_writel(priv, ENET_MAX_MTU_SIZE, UMAC_MAX_FRAME_LEN);
+ bcmgenet_umac_writel(priv, ENET_MAX_FRAME_LEN, UMAC_MAX_FRAME_LEN);
/* init tx registers, enable TSB */
reg = bcmgenet_tbuf_ctrl_get(priv);
@@ -2780,7 +2780,7 @@ static void bcmgenet_init_tx_ring(struct bcmgenet_priv *priv,
/* Set flow period for ring != 0 */
if (index)
- flow_period_val = ENET_MAX_MTU_SIZE << 16;
+ flow_period_val = ENET_MAX_FRAME_LEN << 16;
bcmgenet_tdma_ring_writel(priv, index, 0, TDMA_PROD_INDEX);
bcmgenet_tdma_ring_writel(priv, index, 0, TDMA_CONS_INDEX);
diff --git a/drivers/net/ethernet/broadcom/genet/bcmgenet.h b/drivers/net/ethernet/broadcom/genet/bcmgenet.h
index 6ab3f7347555..afaccb769933 100644
--- a/drivers/net/ethernet/broadcom/genet/bcmgenet.h
+++ b/drivers/net/ethernet/broadcom/genet/bcmgenet.h
@@ -28,12 +28,11 @@
/* which ring is descriptor based */
#define DESC_INDEX 16
-/* Body(1500) + EH_SIZE(14) + VLANTAG(4) + BRCMTAG(6) + FCS(4) = 1528.
- * 1536 is multiple of 256 bytes
- */
#define ENET_BRCM_TAG_LEN 6
#define ENET_PAD 8
-#define ENET_MAX_MTU_SIZE (ETH_DATA_LEN + ETH_HLEN + VLAN_HLEN + \
+
+/* Longest frame the MAC must accept for the default MTU */
+#define ENET_MAX_FRAME_LEN (ETH_DATA_LEN + ETH_HLEN + VLAN_HLEN + \
ENET_BRCM_TAG_LEN + ETH_FCS_LEN + ENET_PAD)
#define DMA_MAX_BURST_LENGTH 0x10
--
2.53.0
^ permalink raw reply related [flat|nested] 18+ messages in thread* Re: [PATCH net-next v10 3/8] net: bcmgenet: rename ENET_MAX_MTU_SIZE to ENET_MAX_FRAME_LEN
2026-11-27 11:25 ` [PATCH net-next v10 3/8] net: bcmgenet: rename ENET_MAX_MTU_SIZE to ENET_MAX_FRAME_LEN Nicolai Buchwitz
@ 2026-11-28 11:26 ` netdev-bot+sashiko
0 siblings, 0 replies; 18+ messages in thread
From: netdev-bot+sashiko @ 2026-11-28 11:26 UTC (permalink / raw)
To: nb
Cc: opendmb, florian.fainelli, bcm-kernel-feedback-list,
andrew+netdev, davem, edumazet, kuba, pabeni, f.fainelli, netdev,
linux-kernel, pierremarinleclercq88, dave.stevenson, justin.chen
Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] In drivers/net/ethernet/broadcom/genet/bcmgenet.h, the commit
"net: bcmgenet: rename ENET_MAX_FRAME_LEN" deletes the old comment…
--
net: bcmgenet: rename ENET_MAX_MTU_SIZE to ENET_MAX_FRAME_LEN
This patch renames ENET_MAX_MTU_SIZE to ENET_MAX_FRAME_LEN because the
value is a frame length, not an MTU. It updates the two users, init_umac()
and bcmgenet_init_tx_ring(), and replaces the comment above the macro. No
functional change is intended.
> diff --git a/drivers/net/ethernet/broadcom/genet/bcmgenet.h b/drivers/net/ethernet/broadcom/genet/bcmgenet.h
> index 6ab3f73475550..afaccb7699336 100644
> --- a/drivers/net/ethernet/broadcom/genet/bcmgenet.h
> +++ b/drivers/net/ethernet/broadcom/genet/bcmgenet.h
> @@ -28,12 +28,11 @@
> /* which ring is descriptor based */
> #define DESC_INDEX 16
>
> -/* Body(1500) + EH_SIZE(14) + VLANTAG(4) + BRCMTAG(6) + FCS(4) = 1528.
> - * 1536 is multiple of 256 bytes
> - */
> #define ENET_BRCM_TAG_LEN 6
> #define ENET_PAD 8
> -#define ENET_MAX_MTU_SIZE (ETH_DATA_LEN + ETH_HLEN + VLAN_HLEN + \
> +
> +/* Longest frame the MAC must accept for the default MTU */
> +#define ENET_MAX_FRAME_LEN (ETH_DATA_LEN + ETH_HLEN + VLAN_HLEN + \
> ENET_BRCM_TAG_LEN + ETH_FCS_LEN + ENET_PAD)
[Severity: Low]
This isn't a bug, but is the new comment accurate? The expression adds
up to 1536:
1500 + 14 + 4 + 6 + 4 + 8 (ENET_PAD) = 1536
The longest frame the MAC actually has to accept for the default MTU is
1528. The extra 8 bytes come from ENET_PAD, which is not part of any frame.
The deleted comment was the only place that explained ENET_PAD, as
rounding up to a 256-byte multiple. After this patch nothing explains it.
The padded value is still written to UMAC_MAX_FRAME_LEN in init_umac(). It
is also shifted into the TDMA flow period in bcmgenet_init_tx_ring(), which
the new comment doesn't mention.
The next patch in the series, "net: bcmgenet: derive the receive buffer
length from the MTU", rewrites this comment to explain that ENET_PAD rounds
1528 up to 1536, so the end of the series is fine. Could this patch keep
the ENET_PAD explanation, so the comment is also correct at this commit?
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261127-nb-genet-mtu-nn-v2-v10-0-749c7cc45d97%40tipi-net.de
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH net-next v10 4/8] net: bcmgenet: derive the receive buffer length from the MTU
2026-11-27 11:25 [PATCH net-next v10 0/8] net: bcmgenet: support larger MTUs Nicolai Buchwitz
` (2 preceding siblings ...)
2026-11-27 11:25 ` [PATCH net-next v10 3/8] net: bcmgenet: rename ENET_MAX_MTU_SIZE to ENET_MAX_FRAME_LEN Nicolai Buchwitz
@ 2026-11-27 11:25 ` Nicolai Buchwitz
2026-11-28 11:26 ` netdev-bot+sashiko
2026-11-27 11:25 ` [PATCH net-next v10 5/8] net: bcmgenet: split frames that end just past the transmit threshold Nicolai Buchwitz
` (3 subsequent siblings)
7 siblings, 1 reply; 18+ messages in thread
From: Nicolai Buchwitz @ 2026-11-27 11:25 UTC (permalink / raw)
To: Doug Berger, Florian Fainelli, Nicolai Buchwitz,
Broadcom internal kernel review list, Andrew Lunn,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: Florian Fainelli, netdev, linux-kernel, Dave Stevenson
The receive buffer length is a fixed 2048 bytes. The packet ready
thresholds keep whatever value the reset left. Neither follows the MTU.
Compute the receive threshold from the MTU and program it into RBUF. The
buffer length follows from it, with the status block on top. The MTU is
still fixed at ETH_DATA_LEN, so the threshold comes out at 0x80, the value
a v5 holds out of reset, and the buffer only grows by the status block the
hardware already wrote. Derive UMAC_MAX_FRAME_LEN and the flow period from
the MTU too, with a floor at ETH_DATA_LEN so a lower MTU does not stop the
MAC accepting a standard frame.
Suggested-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
Signed-off-by: Nicolai Buchwitz <nb@tipi-net.de>
---
drivers/net/ethernet/broadcom/genet/bcmgenet.c | 91 +++++++++++++++++++++-----
drivers/net/ethernet/broadcom/genet/bcmgenet.h | 18 ++++-
2 files changed, 91 insertions(+), 18 deletions(-)
diff --git a/drivers/net/ethernet/broadcom/genet/bcmgenet.c b/drivers/net/ethernet/broadcom/genet/bcmgenet.c
index 5c050331da69..15b7c8a52520 100644
--- a/drivers/net/ethernet/broadcom/genet/bcmgenet.c
+++ b/drivers/net/ethernet/broadcom/genet/bcmgenet.c
@@ -48,18 +48,42 @@
#define GENET_Q0_TX_BD_CNT \
(TOTAL_DESC - priv->hw_params->tx_queues * priv->hw_params->tx_bds_per_q)
-#define RX_BUF_LENGTH 2048
#define SKB_ALIGNMENT 32
+/* The transmit descriptors carry their own lengths, so this is unused and
+ * keeps the reset value.
+ */
+#define TX_RING_BUF_SIZE 2048
+
+/* Once the threshold is reached RBUF hands a frame to the receive DMA and
+ * TBUF hands one to the MAC. Both registers are 8 bit in units of 16 bytes
+ * and want a multiple of the 256 byte burst size, so 0xf0 is the largest
+ * usable value.
+ */
+#define ENET_THLD_UNIT 16
+#define ENET_THLD_BURST 256
+#define ENET_THLD_DEFAULT 0x80
+#define ENET_THLD_MAX 0xf0
+
/* Page pool RX buffer layout:
* RSB(64) + pad(2) | frame data | skb_shared_info
* The HW writes the 64B RSB before every descriptor of a frame. Only the
* first one also gets the 2B alignment padding.
*/
-#define GENET_RSB_PAD (sizeof(struct status_64) + 2)
+#define GENET_RBUF_ALIGN 2
+#define GENET_RSB_PAD (sizeof(struct status_64) + GENET_RBUF_ALIGN)
-/* RX buffer plus the skb_shared_info napi_build_skb() places behind it */
-#define GENET_RX_BUF_SIZE SKB_HEAD_ALIGN(RX_BUF_LENGTH)
+/* A descriptor never spans more than one page, which also holds
+ * skb_shared_info behind the frame, so on 4K pages the page bounds the
+ * threshold before the register does. Larger pages fit several descriptors.
+ */
+#define ENET_SHINFO_LEN SKB_DATA_ALIGN(sizeof(struct skb_shared_info))
+#define ENET_THLD_PAGE_LEN round_down(PAGE_SIZE - ENET_SHINFO_LEN - \
+ sizeof(struct status_64), \
+ ENET_THLD_BURST)
+#define ENET_THLD_MAX_LEN min_t(unsigned int, \
+ ENET_THLD_MAX * ENET_THLD_UNIT, \
+ ENET_THLD_PAGE_LEN)
/* Tx/Rx DMA register offset, skip 256 descriptors */
#define WORDS_PER_BD(p) (p->hw_params->words_per_bd)
@@ -2282,7 +2306,7 @@ static int bcmgenet_rx_refill(struct bcmgenet_rx_ring *ring,
struct enet_cb *cb)
{
struct bcmgenet_priv *priv = ring->priv;
- unsigned int size = GENET_RX_BUF_SIZE;
+ unsigned int size = SKB_HEAD_ALIGN(priv->rx_buf_len);
unsigned int offset;
dma_addr_t mapping;
struct page *page;
@@ -2297,7 +2321,7 @@ static int bcmgenet_rx_refill(struct bcmgenet_rx_ring *ring,
/* page_pool handles DMA mapping via PP_FLAG_DMA_MAP */
mapping = page_pool_get_dma_addr(page) + offset;
- dma_sync_single_for_device(&priv->pdev->dev, mapping, RX_BUF_LENGTH,
+ dma_sync_single_for_device(&priv->pdev->dev, mapping, priv->rx_buf_len,
DMA_FROM_DEVICE);
cb->rx_page = page;
@@ -2376,10 +2400,10 @@ static unsigned int bcmgenet_desc_rx(struct bcmgenet_rx_ring *ring,
}
/* Sync the full buffer; the HW may have written anywhere
- * up to RX_BUF_LENGTH.
+ * up to priv->rx_buf_len.
*/
page_pool_dma_sync_for_cpu(ring->page_pool, rx_page, rx_offset,
- RX_BUF_LENGTH);
+ priv->rx_buf_len);
hard_start = page_address(rx_page) + rx_offset;
status = (struct status_64 *)hard_start;
@@ -2401,7 +2425,7 @@ static unsigned int bcmgenet_desc_rx(struct bcmgenet_rx_ring *ring,
: sizeof(struct status_64);
/* Reject lengths that would underflow the SKB build path. */
- if (unlikely(len > RX_BUF_LENGTH || len < min_len)) {
+ if (unlikely(len > priv->rx_buf_len || len < min_len)) {
netif_err(priv, rx_status, dev,
"invalid packet length %d\n", len);
BCMGENET_STATS64_INC(stats, length_errors);
@@ -2653,6 +2677,41 @@ static void bcmgenet_link_intr_enable(struct bcmgenet_priv *priv)
bcmgenet_intrl2_0_writel(priv, int0_enable, INTRL2_CPU_MASK_CLEAR);
}
+/* Receive threshold in register units. Covers the alignment bytes and the
+ * frame, but not the status block, which the hardware adds on top.
+ */
+static unsigned int bcmgenet_pkt_rdy_thld(unsigned int mtu)
+{
+ unsigned int len = GENET_RBUF_ALIGN + mtu + ETH_HLEN + VLAN_HLEN;
+
+ len = round_up(len, ENET_THLD_BURST) / ENET_THLD_UNIT;
+
+ /* Keep the reset default for the common MTUs */
+ return clamp_t(unsigned int, len, ENET_THLD_DEFAULT,
+ ENET_THLD_MAX_LEN / ENET_THLD_UNIT);
+}
+
+/* A buffer has to hold everything the threshold lets the hardware deliver */
+static unsigned int bcmgenet_rx_buf_len(unsigned int mtu)
+{
+ return sizeof(struct status_64) +
+ bcmgenet_pkt_rdy_thld(mtu) * ENET_THLD_UNIT;
+}
+
+/* Call with the MAC disabled */
+static void bcmgenet_set_mtu_regs(struct bcmgenet_priv *priv, unsigned int mtu)
+{
+ u32 thld = bcmgenet_pkt_rdy_thld(mtu);
+
+ bcmgenet_umac_writel(priv, ENET_MAC_FRAME_LEN(mtu), UMAC_MAX_FRAME_LEN);
+
+ /* GENET v1 maps other registers at these offsets */
+ if (GENET_IS_V1(priv))
+ return;
+
+ bcmgenet_rbuf_writel(priv, thld, RBUF_PKT_RDY_THLD);
+}
+
static void init_umac(struct bcmgenet_priv *priv)
{
struct device *kdev = &priv->pdev->dev;
@@ -2669,7 +2728,7 @@ static void init_umac(struct bcmgenet_priv *priv)
UMAC_MIB_CTRL);
bcmgenet_umac_writel(priv, 0, UMAC_MIB_CTRL);
- bcmgenet_umac_writel(priv, ENET_MAX_FRAME_LEN, UMAC_MAX_FRAME_LEN);
+ bcmgenet_set_mtu_regs(priv, priv->dev->mtu);
/* init tx registers, enable TSB */
reg = bcmgenet_tbuf_ctrl_get(priv);
@@ -2780,7 +2839,7 @@ static void bcmgenet_init_tx_ring(struct bcmgenet_priv *priv,
/* Set flow period for ring != 0 */
if (index)
- flow_period_val = ENET_MAX_FRAME_LEN << 16;
+ flow_period_val = ENET_MAC_FRAME_LEN(priv->dev->mtu) << 16;
bcmgenet_tdma_ring_writel(priv, index, 0, TDMA_PROD_INDEX);
bcmgenet_tdma_ring_writel(priv, index, 0, TDMA_CONS_INDEX);
@@ -2791,7 +2850,7 @@ static void bcmgenet_init_tx_ring(struct bcmgenet_priv *priv,
TDMA_FLOW_PERIOD);
bcmgenet_tdma_ring_writel(priv, index,
((size << DMA_RING_SIZE_SHIFT) |
- RX_BUF_LENGTH), DMA_RING_BUF_SIZE);
+ TX_RING_BUF_SIZE), DMA_RING_BUF_SIZE);
/* Set start and end address, read and write pointers */
bcmgenet_tdma_ring_writel(priv, index, start_ptr * words_per_bd,
@@ -2810,8 +2869,9 @@ static void bcmgenet_init_tx_ring(struct bcmgenet_priv *priv,
static int bcmgenet_rx_ring_create_pool(struct bcmgenet_priv *priv,
struct bcmgenet_rx_ring *ring)
{
- /* Buffers share a page. bcmgenet_rx_refill() syncs each one for the
- * device, PP_FLAG_DMA_SYNC_DEV would sync the whole page.
+ /* Buffers may share a page, depending on PAGE_SIZE and the MTU.
+ * bcmgenet_rx_refill() syncs each one for the device,
+ * PP_FLAG_DMA_SYNC_DEV would sync the whole page.
*/
struct page_pool_params pp_params = {
.order = 0,
@@ -2876,7 +2936,7 @@ static int bcmgenet_init_rx_ring(struct bcmgenet_priv *priv,
bcmgenet_rdma_ring_writel(priv, index, 0, RDMA_CONS_INDEX);
bcmgenet_rdma_ring_writel(priv, index,
((size << DMA_RING_SIZE_SHIFT) |
- RX_BUF_LENGTH), DMA_RING_BUF_SIZE);
+ priv->rx_buf_len), DMA_RING_BUF_SIZE);
bcmgenet_rdma_ring_writel(priv, index,
(DMA_FC_THRESH_LO <<
DMA_XOFF_THRESHOLD_SHIFT) |
@@ -4156,6 +4216,7 @@ 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);
INIT_WORK(&priv->bcmgenet_irq_work, bcmgenet_irq_task);
priv->clk_wol = devm_clk_get_optional(&priv->pdev->dev, "enet-wol");
diff --git a/drivers/net/ethernet/broadcom/genet/bcmgenet.h b/drivers/net/ethernet/broadcom/genet/bcmgenet.h
index afaccb769933..b40e56872132 100644
--- a/drivers/net/ethernet/broadcom/genet/bcmgenet.h
+++ b/drivers/net/ethernet/broadcom/genet/bcmgenet.h
@@ -31,9 +31,17 @@
#define ENET_BRCM_TAG_LEN 6
#define ENET_PAD 8
-/* Longest frame the MAC must accept for the default MTU */
-#define ENET_MAX_FRAME_LEN (ETH_DATA_LEN + ETH_HLEN + VLAN_HLEN + \
- ENET_BRCM_TAG_LEN + ETH_FCS_LEN + ENET_PAD)
+/* Longest frame the MAC must accept for a given MTU. ENET_PAD is slack the
+ * driver has always carried, it rounded the default up to 1536 from 1528.
+ */
+#define ENET_FRAME_OVERHEAD (ETH_HLEN + VLAN_HLEN + ENET_BRCM_TAG_LEN + \
+ ETH_FCS_LEN + ENET_PAD)
+#define ENET_MAX_FRAME_LEN(mtu) ((mtu) + ENET_FRAME_OVERHEAD)
+
+/* The MAC keeps accepting a standard frame below the default MTU */
+#define ENET_MAC_FRAME_LEN(mtu) ENET_MAX_FRAME_LEN(max_t(unsigned int, (mtu), \
+ ETH_DATA_LEN))
+
#define DMA_MAX_BURST_LENGTH 0x10
/* misc. configuration */
@@ -218,6 +226,8 @@ struct bcmgenet_rx_stats64 {
#define RBUF_ALIGN_2B (1 << 1)
#define RBUF_BAD_DIS (1 << 2)
+#define RBUF_PKT_RDY_THLD 0x08
+
#define RBUF_STATUS 0x0C
#define RBUF_STATUS_WOL (1 << 0)
#define RBUF_STATUS_MPD_INTR_ACTIVE (1 << 1)
@@ -248,6 +258,7 @@ struct bcmgenet_rx_stats64 {
#define TBUF_CTRL 0x00
#define TBUF_64B_EN (1 << 0)
#define TBUF_BP_MC 0x0C
+#define TBUF_PKT_RDY_THLD 0x10
#define TBUF_ENERGY_CTRL 0x14
#define TBUF_EEE_EN (1 << 0)
#define TBUF_PM_EN (1 << 1)
@@ -614,6 +625,7 @@ struct bcmgenet_priv {
void __iomem *rx_bds;
struct enet_cb *rx_cbs;
unsigned int num_rx_bds;
+ unsigned int rx_buf_len;
struct bcmgenet_rxnfc_rule rxnfc_rules[MAX_NUM_OF_FS_RULES];
struct list_head rxnfc_list;
--
2.53.0
^ permalink raw reply related [flat|nested] 18+ messages in thread* Re: [PATCH net-next v10 4/8] net: bcmgenet: derive the receive buffer length from the MTU
2026-11-27 11:25 ` [PATCH net-next v10 4/8] net: bcmgenet: derive the receive buffer length from the MTU Nicolai Buchwitz
@ 2026-11-28 11:26 ` netdev-bot+sashiko
0 siblings, 0 replies; 18+ messages in thread
From: netdev-bot+sashiko @ 2026-11-28 11:26 UTC (permalink / raw)
To: nb
Cc: opendmb, florian.fainelli, bcm-kernel-feedback-list,
andrew+netdev, davem, edumazet, kuba, pabeni, f.fainelli, netdev,
linux-kernel, pierremarinleclercq88, dave.stevenson, justin.chen
Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] In drivers/net/ethernet/broadcom/genet/bcmgenet.c,
bcmgenet_set_mtu_regs() now writes RBUF_PKT_RDY_THLD (RBUF + 0x08)…
--
net: bcmgenet: derive the receive buffer length from the MTU
This patch drops the fixed 2048 byte receive buffer length. The length is
now derived from an MTU-based packet ready threshold, which the patch also
programs into RBUF_PKT_RDY_THLD. UMAC_MAX_FRAME_LEN and the TDMA flow
period are also derived from the MTU, with a floor at ETH_DATA_LEN.
> diff --git a/drivers/net/ethernet/broadcom/genet/bcmgenet.c b/drivers/net/ethernet/broadcom/genet/bcmgenet.c
> index 5c050331da690..15b7c8a525201 100644
> --- a/drivers/net/ethernet/broadcom/genet/bcmgenet.c
> +++ b/drivers/net/ethernet/broadcom/genet/bcmgenet.c
[ ... ]
> @@ -2653,6 +2677,41 @@ static void bcmgenet_link_intr_enable(struct bcmgenet_priv *priv)
> bcmgenet_intrl2_0_writel(priv, int0_enable, INTRL2_CPU_MASK_CLEAR);
> }
>
> +/* Receive threshold in register units. Covers the alignment bytes and the
> + * frame, but not the status block, which the hardware adds on top.
> + */
> +static unsigned int bcmgenet_pkt_rdy_thld(unsigned int mtu)
> +{
> + unsigned int len = GENET_RBUF_ALIGN + mtu + ETH_HLEN + VLAN_HLEN;
> +
> + len = round_up(len, ENET_THLD_BURST) / ENET_THLD_UNIT;
> +
> + /* Keep the reset default for the common MTUs */
> + return clamp_t(unsigned int, len, ENET_THLD_DEFAULT,
> + ENET_THLD_MAX_LEN / ENET_THLD_UNIT);
> +}
[ ... ]
> +/* Call with the MAC disabled */
> +static void bcmgenet_set_mtu_regs(struct bcmgenet_priv *priv, unsigned int mtu)
> +{
> + u32 thld = bcmgenet_pkt_rdy_thld(mtu);
> +
> + bcmgenet_umac_writel(priv, ENET_MAC_FRAME_LEN(mtu), UMAC_MAX_FRAME_LEN);
> +
> + /* GENET v1 maps other registers at these offsets */
> + if (GENET_IS_V1(priv))
> + return;
> +
> + bcmgenet_rbuf_writel(priv, thld, RBUF_PKT_RDY_THLD);
[Severity: Low]
The commit message treats this write as a no-op:
"so the threshold comes out at 0x80, the value a v5 holds out of reset"
Before this patch the driver never wrote RBUF_PKT_RDY_THLD. Now every
open and resume on v2, v3, v4 and v5 writes it, via
init_umac()->bcmgenet_set_mtu_regs().
Is it known that v2-v4 match v5 here? That covers the reset value, the
RBUF + 0x08 offset, the 8 bit field in 16 byte units and the 256 byte
burst rule.
The driver's own register map already shows that the RBUF block differs
between revisions:
#define RBUF_OVFL_CNT_V2 0x80
#define RBUF_OVFL_CNT_V3PLUS 0x94
...
#define RBUF_ERR_CNT_V2 0x84
#define RBUF_ERR_CNT_V3PLUS 0x98
Also, init_umac() writes RBUF_TBUF_SIZE_CTRL only on v3 and later.
If something else lives at RBUF + 0x08 on v2, or the units differ, could
RX frames end up split across descriptors? At this commit,
bcmgenet_desc_rx() drops those:
if (unlikely(!(dma_flag & DMA_EOP) || !(dma_flag & DMA_SOP))) {
netif_err(priv, rx_status, dev,
"dropping fragmented packet!\n");
v1 skips the write, but bcmgenet_probe() still sizes rx_buf_len from the
threshold formula on every revision:
priv->rx_buf_len = bcmgenet_rx_buf_len(dev->mtu);
So on v1, the rule "A buffer has to hold everything the threshold lets
the hardware deliver" depends on a threshold that is never programmed.
The later patch "net: bcmgenet: split frames that end just past the
transmit threshold" adds an unconditional TBUF_PKT_RDY_THLD write on the
same revisions, with the same v5-only reasoning.
Could the commit message state that the v2-v4 reset values and register
semantics match v5? Alternatively, the write could be limited to
revisions where it is known to change nothing.
> +}
> +
> static void init_umac(struct bcmgenet_priv *priv)
[ ... ]
> @@ -4156,6 +4216,7 @@ 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);
> INIT_WORK(&priv->bcmgenet_irq_work, bcmgenet_irq_task);
[ ... ]
> diff --git a/drivers/net/ethernet/broadcom/genet/bcmgenet.h b/drivers/net/ethernet/broadcom/genet/bcmgenet.h
> index afaccb7699336..b40e56872132c 100644
> --- a/drivers/net/ethernet/broadcom/genet/bcmgenet.h
> +++ b/drivers/net/ethernet/broadcom/genet/bcmgenet.h
[ ... ]
> @@ -218,6 +226,8 @@ struct bcmgenet_rx_stats64 {
> #define RBUF_ALIGN_2B (1 << 1)
> #define RBUF_BAD_DIS (1 << 2)
>
> +#define RBUF_PKT_RDY_THLD 0x08
> +
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261127-nb-genet-mtu-nn-v2-v10-0-749c7cc45d97%40tipi-net.de
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH net-next v10 5/8] net: bcmgenet: split frames that end just past the transmit threshold
2026-11-27 11:25 [PATCH net-next v10 0/8] net: bcmgenet: support larger MTUs Nicolai Buchwitz
` (3 preceding siblings ...)
2026-11-27 11:25 ` [PATCH net-next v10 4/8] net: bcmgenet: derive the receive buffer length from the MTU Nicolai Buchwitz
@ 2026-11-27 11:25 ` Nicolai Buchwitz
2026-11-28 11:26 ` netdev-bot+sashiko
2026-11-27 11:25 ` [PATCH net-next v10 6/8] net: bcmgenet: build the DMA rings before giving up the running ones Nicolai Buchwitz
` (2 subsequent siblings)
7 siblings, 1 reply; 18+ messages in thread
From: Nicolai Buchwitz @ 2026-11-27 11:25 UTC (permalink / raw)
To: Doug Berger, Florian Fainelli, Nicolai Buchwitz,
Broadcom internal kernel review list, Andrew Lunn,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: Florian Fainelli, netdev, linux-kernel
A frame that ends a few bytes past the transmit packet ready threshold
stops the transmitter as soon as a shorter frame follows. Tx DMA then
refuses to halt, so every later bcmgenet_init_dma() fails and the
interface cannot be opened again. IP fragmentation generates that pattern
on every datagram, full frames and a short tail. At the default MTU no
frame is long enough to reach the threshold, so the stall needs the
larger MTU that comes later in this series.
The window starts one byte past the threshold and never reaches 64 bytes.
On a v5 it ends 28, 32 and 46 bytes past thresholds of 2560, 3584 and
3840, and link speed makes no difference. That is one DMA transfer wide,
which wtschueller measured and proposed to split around. The bcm2711
programs a burst of 0x08 and sends nothing at all at 0x10, so the window
follows the burst length to cover the parts that program the larger value.
Splitting such a frame over two descriptors keeps its end out of that
transfer. Both share the one mapping, so the wire bytes do not change. The
split costs one descriptor, so the queue stops and wakes one earlier, and
a frame is flattened one fragment sooner.
The driver never wrote the threshold before. On a v5 it holds 0x80, which
is what an MTU up to ETH_DATA_LEN programs, so the common MTUs stay as
they were.
The MAC inserts a checksum only into a frame it holds in full, so a longer
one has to fall back to software.
Link: https://github.com/raspberrypi/linux/pull/7617#issuecomment-6201096155
Signed-off-by: Nicolai Buchwitz <nb@tipi-net.de>
---
drivers/net/ethernet/broadcom/genet/bcmgenet.c | 174 +++++++++++++++++++------
drivers/net/ethernet/broadcom/genet/bcmgenet.h | 4 +
2 files changed, 141 insertions(+), 37 deletions(-)
diff --git a/drivers/net/ethernet/broadcom/genet/bcmgenet.c b/drivers/net/ethernet/broadcom/genet/bcmgenet.c
index 15b7c8a52520..5ad38b4eccd1 100644
--- a/drivers/net/ethernet/broadcom/genet/bcmgenet.c
+++ b/drivers/net/ethernet/broadcom/genet/bcmgenet.c
@@ -65,6 +65,13 @@
#define ENET_THLD_DEFAULT 0x80
#define ENET_THLD_MAX 0xf0
+/* A frame that ends within one DMA transfer past the transmit threshold
+ * stops the transmitter once a shorter frame follows. The burst register
+ * has no documented unit, 8 bytes per count matches the 46 bytes measured
+ * on a bcm2711, which programs 0x08.
+ */
+#define ENET_BURST_UNIT 8
+
/* Page pool RX buffer layout:
* RSB(64) + pad(2) | frame data | skb_shared_info
* The HW writes the 64B RSB before every descriptor of a frame. Only the
@@ -1916,15 +1923,20 @@ static struct sk_buff *bcmgenet_free_tx_cb(struct device *dev,
if (skb) {
cb->skb = NULL;
- if (cb == GENET_CB(skb)->first_cb)
- dma_unmap_single(dev, dma_unmap_addr(cb, dma_addr),
- dma_unmap_len(cb, dma_len),
- DMA_TO_DEVICE);
- else
- dma_unmap_page(dev, dma_unmap_addr(cb, dma_addr),
- dma_unmap_len(cb, dma_len),
- DMA_TO_DEVICE);
- dma_unmap_addr_set(cb, dma_addr, 0);
+ /* A cut descriptor left its mapping to the one after it */
+ if (cb != GENET_CB(skb)->split_cb) {
+ if (cb == GENET_CB(skb)->head_cb)
+ dma_unmap_single(dev,
+ dma_unmap_addr(cb, dma_addr),
+ dma_unmap_len(cb, dma_len),
+ DMA_TO_DEVICE);
+ else
+ dma_unmap_page(dev,
+ dma_unmap_addr(cb, dma_addr),
+ dma_unmap_len(cb, dma_len),
+ DMA_TO_DEVICE);
+ dma_unmap_addr_set(cb, dma_addr, 0);
+ }
if (cb == GENET_CB(skb)->last_cb)
return skb;
@@ -2151,7 +2163,10 @@ static netdev_tx_t bcmgenet_xmit(struct sk_buff *skb, struct net_device *dev)
{
struct bcmgenet_priv *priv = netdev_priv(dev);
struct device *kdev = &priv->pdev->dev;
+ unsigned int split_i = 0, split_at = 0;
struct bcmgenet_tx_ring *ring = NULL;
+ dma_addr_t split_mapping = 0;
+ unsigned int split_size = 0;
struct enet_cb *tx_cb_ptr;
struct netdev_queue *txq;
int nr_frags, index;
@@ -2159,6 +2174,7 @@ static netdev_tx_t bcmgenet_xmit(struct sk_buff *skb, struct net_device *dev)
unsigned int size;
skb_frag_t *frag;
u32 len_stat;
+ bool split;
int ret;
int i;
@@ -2168,8 +2184,14 @@ static netdev_tx_t bcmgenet_xmit(struct sk_buff *skb, struct net_device *dev)
nr_frags = skb_shinfo(skb)->nr_frags;
+ /* Cut a frame ending in that window in two at the threshold, its end
+ * then lands in a separate transfer.
+ */
+ split = unlikely(skb->len > priv->tx_thld_len &&
+ skb->len < priv->tx_thld_len + priv->tx_thld_window);
+
/* The check below would always refuse this frame */
- if (unlikely(nr_frags + 1 >= ring->size)) {
+ if (unlikely(nr_frags + 1 + split >= ring->size)) {
skb = skb_share_check(skb, GFP_ATOMIC);
if (skb && skb_linearize(skb)) {
dev_kfree_skb_any(skb);
@@ -2185,7 +2207,7 @@ static netdev_tx_t bcmgenet_xmit(struct sk_buff *skb, struct net_device *dev)
}
spin_lock(&ring->lock);
- if (ring->free_bds <= (nr_frags + 1)) {
+ if (ring->free_bds <= (nr_frags + 1 + split)) {
if (!netif_tx_queue_stopped(txq))
netif_tx_stop_queue(txq);
ret = NETDEV_TX_BUSY;
@@ -2202,6 +2224,20 @@ static netdev_tx_t bcmgenet_xmit(struct sk_buff *skb, struct net_device *dev)
goto out;
}
+ /* The MAC inserts a checksum only into a frame it holds in full and
+ * silently drops a longer one, so fall back to software.
+ */
+ if (unlikely(skb->len > priv->tx_thld_len) &&
+ skb->ip_summed == CHECKSUM_PARTIAL) {
+ if (skb_checksum_help(skb)) {
+ BCMGENET_STATS64_INC((&ring->stats64), dropped);
+ dev_kfree_skb_any(skb);
+ ret = NETDEV_TX_OK;
+ goto out;
+ }
+ nr_frags = skb_shinfo(skb)->nr_frags;
+ }
+
/* Retain how many bytes will be sent on the wire, without TSB inserted
* by transmit checksum offload
*/
@@ -2214,34 +2250,79 @@ static netdev_tx_t bcmgenet_xmit(struct sk_buff *skb, struct net_device *dev)
goto out;
}
- for (i = 0; i <= nr_frags; i++) {
+ /* A threshold that already ends a buffer needs no cut */
+ if (split) {
+ unsigned int buf = skb_headlen(skb);
+ unsigned int covered = buf - sizeof(struct status_64);
+
+ while (covered < priv->tx_thld_len) {
+ frag = &skb_shinfo(skb)->frags[split_i++];
+ buf = skb_frag_size(frag);
+ covered += buf;
+ }
+
+ split_at = buf - (covered - priv->tx_thld_len);
+ split = split_at && split_at < buf;
+ }
+
+ for (i = 0; i <= nr_frags + split; i++) {
+ unsigned int f = i - (split && i > split_i);
+ bool cont = split && i == split_i + 1;
+
tx_cb_ptr = bcmgenet_get_txcb(priv, ring);
BUG_ON(!tx_cb_ptr);
- if (!i) {
- /* Transmit single SKB or head of fragment list */
- GENET_CB(skb)->first_cb = tx_cb_ptr;
- size = skb_headlen(skb);
- mapping = dma_map_single(kdev, skb->data, size,
- DMA_TO_DEVICE);
+ if (cont) {
+ /* Rest of the buffer cut above. It unmaps for both,
+ * the hardware is done with it only now.
+ */
+ mapping = split_mapping + split_at;
+ size = split_size - split_at;
+ dma_unmap_addr_set(tx_cb_ptr, dma_addr, split_mapping);
+ dma_unmap_len_set(tx_cb_ptr, dma_len, split_size);
+
+ /* A cut head buffer leaves its mapping here too */
+ if (!split_i)
+ GENET_CB(skb)->head_cb = tx_cb_ptr;
} else {
- /* xmit fragment */
- frag = &skb_shinfo(skb)->frags[i - 1];
- size = skb_frag_size(frag);
- mapping = skb_frag_dma_map(kdev, frag, 0, size,
- DMA_TO_DEVICE);
- }
+ if (!f) {
+ /* Transmit single SKB or head of frag list */
+ GENET_CB(skb)->first_cb = tx_cb_ptr;
+ GENET_CB(skb)->head_cb = tx_cb_ptr;
+ GENET_CB(skb)->split_cb = NULL;
+ size = skb_headlen(skb);
+ mapping = dma_map_single(kdev, skb->data,
+ size, DMA_TO_DEVICE);
+ } else {
+ /* xmit fragment */
+ frag = &skb_shinfo(skb)->frags[f - 1];
+ size = skb_frag_size(frag);
+ mapping = skb_frag_dma_map(kdev, frag, 0, size,
+ DMA_TO_DEVICE);
+ }
- ret = dma_mapping_error(kdev, mapping);
- if (ret) {
- priv->mib.tx_dma_failed++;
- netif_err(priv, tx_err, dev, "Tx DMA map failed\n");
- ret = NETDEV_TX_OK;
- goto out_unmap_frags;
+ ret = dma_mapping_error(kdev, mapping);
+ if (ret) {
+ priv->mib.tx_dma_failed++;
+ netif_err(priv, tx_err, dev,
+ "Tx DMA map failed\n");
+ ret = NETDEV_TX_OK;
+ goto out_unmap_frags;
+ }
+ dma_unmap_addr_set(tx_cb_ptr, dma_addr, mapping);
+ dma_unmap_len_set(tx_cb_ptr, dma_len, size);
+
+ /* The cut hands buffer and mapping to the next one */
+ if (split && i == split_i) {
+ GENET_CB(skb)->split_cb = tx_cb_ptr;
+ split_mapping = mapping;
+ split_size = size;
+ size = split_at;
+ dma_unmap_addr_set(tx_cb_ptr, dma_addr, 0);
+ dma_unmap_len_set(tx_cb_ptr, dma_len, 0);
+ }
}
- dma_unmap_addr_set(tx_cb_ptr, dma_addr, mapping);
- dma_unmap_len_set(tx_cb_ptr, dma_len, size);
tx_cb_ptr->skb = skb;
@@ -2258,7 +2339,7 @@ static netdev_tx_t bcmgenet_xmit(struct sk_buff *skb, struct net_device *dev)
if (skb->ip_summed == CHECKSUM_PARTIAL)
len_stat |= DMA_TX_DO_CSUM;
}
- if (i == nr_frags)
+ if (i == nr_frags + split)
len_stat |= DMA_EOP;
dmadesc_set(priv, tx_cb_ptr->bd_addr, mapping, len_stat);
@@ -2270,8 +2351,8 @@ static netdev_tx_t bcmgenet_xmit(struct sk_buff *skb, struct net_device *dev)
skb_tx_timestamp(skb);
/* Decrement total BD count and advance our write pointer */
- ring->free_bds -= nr_frags + 1;
- ring->prod_index += nr_frags + 1;
+ ring->free_bds -= nr_frags + 1 + split;
+ ring->prod_index += nr_frags + 1 + split;
ring->prod_index &= DMA_P_INDEX_MASK;
netdev_tx_sent_queue(txq, GENET_CB(skb)->bytes_sent);
@@ -2691,6 +2772,17 @@ static unsigned int bcmgenet_pkt_rdy_thld(unsigned int mtu)
ENET_THLD_MAX_LEN / ENET_THLD_UNIT);
}
+/* The transmit threshold in register units. Keep the reset value while the
+ * MTU has no use for more, the hardware never reaches it below ETH_DATA_LEN.
+ */
+static unsigned int bcmgenet_tx_pkt_rdy_thld(unsigned int mtu)
+{
+ if (mtu <= ETH_DATA_LEN)
+ return ENET_THLD_DEFAULT;
+
+ return ENET_THLD_MAX;
+}
+
/* A buffer has to hold everything the threshold lets the hardware deliver */
static unsigned int bcmgenet_rx_buf_len(unsigned int mtu)
{
@@ -2701,8 +2793,10 @@ static unsigned int bcmgenet_rx_buf_len(unsigned int mtu)
/* Call with the MAC disabled */
static void bcmgenet_set_mtu_regs(struct bcmgenet_priv *priv, unsigned int mtu)
{
+ u32 tx_thld = bcmgenet_tx_pkt_rdy_thld(mtu);
u32 thld = bcmgenet_pkt_rdy_thld(mtu);
+ priv->tx_thld_len = tx_thld * ENET_THLD_UNIT;
bcmgenet_umac_writel(priv, ENET_MAC_FRAME_LEN(mtu), UMAC_MAX_FRAME_LEN);
/* GENET v1 maps other registers at these offsets */
@@ -2710,6 +2804,8 @@ static void bcmgenet_set_mtu_regs(struct bcmgenet_priv *priv, unsigned int mtu)
return;
bcmgenet_rbuf_writel(priv, thld, RBUF_PKT_RDY_THLD);
+ bcmgenet_writel(tx_thld, priv->base + priv->hw_params->tbuf_offset +
+ TBUF_PKT_RDY_THLD);
}
static void init_umac(struct bcmgenet_priv *priv)
@@ -2827,8 +2923,10 @@ static void bcmgenet_init_tx_ring(struct bcmgenet_priv *priv,
ring->index = index;
ring->cbs = priv->tx_cbs + start_ptr;
ring->size = size;
- /* An empty ring must be able to wake the queue */
- ring->stop_thld = min_t(unsigned int, MAX_SKB_FRAGS + 1, size - 1);
+ /* An empty ring must be able to wake the queue, a split frame takes
+ * one descriptor more.
+ */
+ ring->stop_thld = min_t(unsigned int, MAX_SKB_FRAGS + 2, size - 1);
ring->clean_ptr = start_ptr;
ring->c_index = 0;
ring->free_bds = size;
@@ -4217,6 +4315,8 @@ static int bcmgenet_probe(struct platform_device *pdev)
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;
+ priv->tx_thld_window = priv->dma_max_burst_length * ENET_BURST_UNIT;
INIT_WORK(&priv->bcmgenet_irq_work, bcmgenet_irq_task);
priv->clk_wol = devm_clk_get_optional(&priv->pdev->dev, "enet-wol");
diff --git a/drivers/net/ethernet/broadcom/genet/bcmgenet.h b/drivers/net/ethernet/broadcom/genet/bcmgenet.h
index b40e56872132..906639c1f012 100644
--- a/drivers/net/ethernet/broadcom/genet/bcmgenet.h
+++ b/drivers/net/ethernet/broadcom/genet/bcmgenet.h
@@ -543,7 +543,9 @@ struct bcmgenet_hw_params {
struct bcmgenet_skb_cb {
struct enet_cb *first_cb; /* First control block of SKB */
+ struct enet_cb *head_cb; /* Owns the head mapping */
struct enet_cb *last_cb; /* Last control block of SKB */
+ struct enet_cb *split_cb; /* Cut, the next one unmaps for both */
unsigned int bytes_sent; /* bytes on the wire (no TSB) */
};
@@ -618,6 +620,8 @@ struct bcmgenet_priv {
void __iomem *tx_bds;
struct enet_cb *tx_cbs;
unsigned int num_tx_bds;
+ unsigned int tx_thld_len;
+ unsigned int tx_thld_window;
struct bcmgenet_tx_ring tx_rings[GENET_MAX_MQ_CNT + 1];
--
2.53.0
^ permalink raw reply related [flat|nested] 18+ messages in thread* Re: [PATCH net-next v10 5/8] net: bcmgenet: split frames that end just past the transmit threshold
2026-11-27 11:25 ` [PATCH net-next v10 5/8] net: bcmgenet: split frames that end just past the transmit threshold Nicolai Buchwitz
@ 2026-11-28 11:26 ` netdev-bot+sashiko
2026-11-28 13:04 ` Nicolai Buchwitz
0 siblings, 1 reply; 18+ messages in thread
From: netdev-bot+sashiko @ 2026-11-28 11:26 UTC (permalink / raw)
To: nb
Cc: opendmb, florian.fainelli, bcm-kernel-feedback-list,
andrew+netdev, davem, edumazet, kuba, pabeni, f.fainelli, netdev,
linux-kernel, pierremarinleclercq88, dave.stevenson, justin.chen
Thank you for your contribution! Sashiko AI review found 4 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 3
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Medium] The transmit stall window is extrapolated, not measured, on
every GENET that programs a DMA burst of 0x10.
- [Low] bcmgenet_xmit() now calls skb_checksum_help() for any
CHECKSUM_PARTIAL frame with skb->len > priv->tx_thld_len, and it does…
- [Low] (Baseline decision: not a functional bug; kept because
requires_validation=true.) bcmgenet_set_mtu_regs() now writes…
- [Low] (Baseline decision: not a bug; kept because
requires_validation=true.) bcmgenet_set_mtu_regs() sets…
--
net: bcmgenet: split frames that end just past the transmit threshold
Transmit frames that end just past the TBUF packet ready threshold are now
split over two descriptors that share one DMA mapping. This avoids a
transmitter stall after which Tx DMA refuses to halt. The patch also
programs TBUF_PKT_RDY_THLD based on the MTU, and frames longer than the
threshold fall back to a software checksum.
Link: https://github.com/raspberrypi/linux/pull/7617#issuecomment-6201096155
> diff --git a/drivers/net/ethernet/broadcom/genet/bcmgenet.c b/drivers/net/ethernet/broadcom/genet/bcmgenet.c
> index 15b7c8a525201..5ad38b4eccd1e 100644
> --- a/drivers/net/ethernet/broadcom/genet/bcmgenet.c
> +++ b/drivers/net/ethernet/broadcom/genet/bcmgenet.c
> @@ -65,6 +65,13 @@
> #define ENET_THLD_DEFAULT 0x80
> #define ENET_THLD_MAX 0xf0
>
> +/* A frame that ends within one DMA transfer past the transmit threshold
> + * stops the transmitter once a shorter frame follows. The burst register
> + * has no documented unit, 8 bytes per count matches the 46 bytes measured
> + * on a bcm2711, which programs 0x08.
> + */
> +#define ENET_BURST_UNIT 8
[Severity: Medium]
bcmgenet_probe() computes the window for every part as:
priv->tx_thld_window = priv->dma_max_burst_length * ENET_BURST_UNIT;
The 8 bytes per count comes from a single bcm2711 measurement at burst
0x08. The commit message says the bcm2711 sends nothing at 0x10, so the
0x10 case (16 * 8 = 128 bytes) was never measured.
The 46 byte result shows the unit is at least about 5.75 bytes per count.
Does it show that the unit is exactly 8, or that the window grows linearly
with the burst count?
v5_plat_data and bcm7712_plat_data both use DMA_MAX_BURST_LENGTH (0x10).
Their real window could be wider than 128 bytes, for example because of a
wider bus. In that case bcmgenet_xmit() would send a frame with
tx_thld_len + tx_thld_window <= skb->len < real window end
without splitting it. If a shorter frame follows, wouldn't that bring back
the Tx DMA stall where every later bcmgenet_init_dma() fails?
Later in the series, "net: bcmgenet: allow the MTU to be changed" raises
max_mtu for every GENET_IS_V5() part, so this becomes reachable on those
0x10 parts. Has the window been verified on any part that programs 0x10?
[ ... ]
> @@ -2185,7 +2207,7 @@ static netdev_tx_t bcmgenet_xmit(struct sk_buff *skb, struct net_device *dev)
> }
>
> spin_lock(&ring->lock);
> - if (ring->free_bds <= (nr_frags + 1)) {
> + if (ring->free_bds <= (nr_frags + 1 + split)) {
> if (!netif_tx_queue_stopped(txq))
> netif_tx_stop_queue(txq);
> ret = NETDEV_TX_BUSY;
[ ... ]
> @@ -2202,6 +2224,20 @@ static netdev_tx_t bcmgenet_xmit(struct sk_buff *skb, struct net_device *dev)
> goto out;
> }
>
> + /* The MAC inserts a checksum only into a frame it holds in full and
> + * silently drops a longer one, so fall back to software.
> + */
> + if (unlikely(skb->len > priv->tx_thld_len) &&
> + skb->ip_summed == CHECKSUM_PARTIAL) {
> + if (skb_checksum_help(skb)) {
[Severity: Low]
This calls skb_checksum_help() with ring->lock held. For a jumbo frame it
checksums the whole payload, and it may also linearize the skb or expand
its head. Meanwhile bcmgenet_tx_poll() and bcmgenet_tx_reclaim() spin on
the same ring->lock.
The checksum depends only on the skb, which xmit already owns. Could it run
outside the critical section? One option is to clear NETIF_F_CSUM_MASK in
an ndo_features_check callback when skb->len > tx_thld_len, so that
validate_xmit_skb() does the fallback before the driver is entered.
At this commit the path is dormant because the MTU is capped at
ETH_DATA_LEN. Once the larger MTU is allowed, it applies to every
CHECKSUM_PARTIAL frame above the threshold.
[ ... ]
> @@ -2691,6 +2772,17 @@ static unsigned int bcmgenet_pkt_rdy_thld(unsigned int mtu)
> ENET_THLD_MAX_LEN / ENET_THLD_UNIT);
> }
>
> +/* The transmit threshold in register units. Keep the reset value while the
> + * MTU has no use for more, the hardware never reaches it below ETH_DATA_LEN.
> + */
> +static unsigned int bcmgenet_tx_pkt_rdy_thld(unsigned int mtu)
> +{
> + if (mtu <= ETH_DATA_LEN)
> + return ENET_THLD_DEFAULT;
> +
> + return ENET_THLD_MAX;
> +}
[Severity: Low]
This isn't a functional bug, but the comment says the reset value is kept.
The function actually returns a fixed ENET_THLD_DEFAULT (0x80), and the
commit message only confirms 0x80 as the reset value on v5.
bcmgenet_set_mtu_regs() now writes this value on v2-v4 too, and their
reset value isn't documented in the tree. At MTU <= ETH_DATA_LEN no frame
reaches 2048 bytes, so behaviour on those parts shouldn't change.
Could the comment say that a fixed value is written?
> @@ -2701,8 +2793,10 @@ static unsigned int bcmgenet_rx_buf_len(unsigned int mtu)
> /* Call with the MAC disabled */
> static void bcmgenet_set_mtu_regs(struct bcmgenet_priv *priv, unsigned int mtu)
> {
> + u32 tx_thld = bcmgenet_tx_pkt_rdy_thld(mtu);
> u32 thld = bcmgenet_pkt_rdy_thld(mtu);
>
> + priv->tx_thld_len = tx_thld * ENET_THLD_UNIT;
> bcmgenet_umac_writel(priv, ENET_MAC_FRAME_LEN(mtu), UMAC_MAX_FRAME_LEN);
>
> /* GENET v1 maps other registers at these offsets */
> @@ -2710,6 +2804,8 @@ static void bcmgenet_set_mtu_regs(struct bcmgenet_priv *priv, unsigned int mtu)
> return;
>
> bcmgenet_rbuf_writel(priv, thld, RBUF_PKT_RDY_THLD);
> + bcmgenet_writel(tx_thld, priv->base + priv->hw_params->tbuf_offset +
> + TBUF_PKT_RDY_THLD);
> }
[Severity: Low]
This isn't a bug, but priv->tx_thld_len is set before the GENET_IS_V1()
early return. On v1 the cached value is never written to
TBUF_PKT_RDY_THLD, yet bcmgenet_xmit() still uses it for the split and
software checksum decisions.
v1 never gets an MTU above ETH_DATA_LEN in this series, so tx_thld_len
stays at 2048 and neither path can run.
Would a short comment noting that the value has no effect on v1 help
future readers?
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261127-nb-genet-mtu-nn-v2-v10-0-749c7cc45d97%40tipi-net.de
^ permalink raw reply [flat|nested] 18+ messages in thread* Re: [PATCH net-next v10 5/8] net: bcmgenet: split frames that end just past the transmit threshold
2026-11-28 11:26 ` netdev-bot+sashiko
@ 2026-11-28 13:04 ` Nicolai Buchwitz
0 siblings, 0 replies; 18+ messages in thread
From: Nicolai Buchwitz @ 2026-11-28 13:04 UTC (permalink / raw)
To: netdev-bot+sashiko, florian.fainelli
Cc: opendmb, bcm-kernel-feedback-list, andrew+netdev, davem, edumazet,
kuba, pabeni, f.fainelli, netdev, linux-kernel,
pierremarinleclercq88, dave.stevenson, justin.chen
On 28.11.2026 12:26, netdev-bot+sashiko@kernel.org wrote:
> [...]
> [Severity: Medium]
> bcmgenet_probe() computes the window for every part as:
>
> priv->tx_thld_window = priv->dma_max_burst_length *
> ENET_BURST_UNIT;
>
> The 8 bytes per count comes from a single bcm2711 measurement at burst
> 0x08. The commit message says the bcm2711 sends nothing at 0x10, so the
> 0x10 case (16 * 8 = 128 bytes) was never measured.
>
> The 46 byte result shows the unit is at least about 5.75 bytes per
> count.
> Does it show that the unit is exactly 8, or that the window grows
> linearly
> with the burst count?
>
> v5_plat_data and bcm7712_plat_data both use DMA_MAX_BURST_LENGTH
> (0x10).
> Their real window could be wider than 128 bytes, for example because of
> a
> wider bus. In that case bcmgenet_xmit() would send a frame with
>
> tx_thld_len + tx_thld_window <= skb->len < real window end
>
> without splitting it. If a shorter frame follows, wouldn't that bring
> back
> the Tx DMA stall where every later bcmgenet_init_dma() fails?
>
> Later in the series, "net: bcmgenet: allow the MTU to be changed"
> raises
> max_mtu for every GENET_IS_V5() part, so this becomes reachable on
> those
> 0x10 parts. Has the window been verified on any part that programs
> 0x10?
No. 46 bytes is what I measured on a bcm2711, which programs 0x08. The
8 bytes per count is a fit based on that point, rounded up to 64 for
margin.
Florian: Do you know (or can check the RTL) if the window is related to
DMA_SCB_BURST_SIZE at all?
> [...]
Nicolai
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH net-next v10 6/8] net: bcmgenet: build the DMA rings before giving up the running ones
2026-11-27 11:25 [PATCH net-next v10 0/8] net: bcmgenet: support larger MTUs Nicolai Buchwitz
` (4 preceding siblings ...)
2026-11-27 11:25 ` [PATCH net-next v10 5/8] net: bcmgenet: split frames that end just past the transmit threshold Nicolai Buchwitz
@ 2026-11-27 11:25 ` Nicolai Buchwitz
2026-11-27 11:25 ` [PATCH net-next v10 7/8] net: bcmgenet: allow the MTU to be changed Nicolai Buchwitz
2026-11-27 11:25 ` [PATCH net-next v10 8/8] net: bcmgenet: reassemble jumbo frames from status block fragments Nicolai Buchwitz
7 siblings, 0 replies; 18+ messages in thread
From: Nicolai Buchwitz @ 2026-11-27 11:25 UTC (permalink / raw)
To: Doug Berger, Florian Fainelli, Nicolai Buchwitz,
Broadcom internal kernel review list, Andrew Lunn,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: Florian Fainelli, netdev, linux-kernel
bcmgenet_init_dma() allocates the new rings only after its callers have
torn the running ones down, so a failure under memory pressure leaves the
interface with no datapath at all. The MTU change in the next patch runs
the same path on a live interface, where that takes a working link down.
Allocate into a set of its own first and install it only once it is
complete, so a failed allocation costs the running datapath nothing.
The receive buffers can only reach the hardware at install time, the
descriptors of a running ring must not be rewritten.
Signed-off-by: Nicolai Buchwitz <nb@tipi-net.de>
---
drivers/net/ethernet/broadcom/genet/bcmgenet.c | 248 +++++++++++++++----------
drivers/net/ethernet/broadcom/genet/bcmgenet.h | 9 +
2 files changed, 158 insertions(+), 99 deletions(-)
diff --git a/drivers/net/ethernet/broadcom/genet/bcmgenet.c b/drivers/net/ethernet/broadcom/genet/bcmgenet.c
index 5ad38b4eccd1..fc8b8400fcbb 100644
--- a/drivers/net/ethernet/broadcom/genet/bcmgenet.c
+++ b/drivers/net/ethernet/broadcom/genet/bcmgenet.c
@@ -2383,16 +2383,15 @@ static netdev_tx_t bcmgenet_xmit(struct sk_buff *skb, struct net_device *dev)
goto out;
}
-static int bcmgenet_rx_refill(struct bcmgenet_rx_ring *ring,
- struct enet_cb *cb)
+static int bcmgenet_rx_alloc_cb(struct bcmgenet_priv *priv,
+ struct page_pool *pool, unsigned int buf_len,
+ struct enet_cb *cb)
{
- struct bcmgenet_priv *priv = ring->priv;
- unsigned int size = SKB_HEAD_ALIGN(priv->rx_buf_len);
+ unsigned int size = SKB_HEAD_ALIGN(buf_len);
unsigned int offset;
- dma_addr_t mapping;
struct page *page;
- page = page_pool_dev_alloc(ring->page_pool, &offset, &size);
+ page = page_pool_dev_alloc(pool, &offset, &size);
if (!page) {
priv->mib.alloc_rx_buff_failed++;
netif_err(priv, rx_err, priv->dev,
@@ -2400,15 +2399,36 @@ static int bcmgenet_rx_refill(struct bcmgenet_rx_ring *ring,
return -ENOMEM;
}
+ cb->rx_page = page;
+ cb->rx_offset = offset;
+ cb->rx_size = size;
+
+ return 0;
+}
+
+static void bcmgenet_rx_arm_cb(struct bcmgenet_priv *priv, struct enet_cb *cb)
+{
+ dma_addr_t mapping;
+
/* page_pool handles DMA mapping via PP_FLAG_DMA_MAP */
- mapping = page_pool_get_dma_addr(page) + offset;
+ mapping = page_pool_get_dma_addr(cb->rx_page) + cb->rx_offset;
dma_sync_single_for_device(&priv->pdev->dev, mapping, priv->rx_buf_len,
DMA_FROM_DEVICE);
- cb->rx_page = page;
- cb->rx_offset = offset;
- cb->rx_size = size;
dmadesc_set_addr(priv, cb->bd_addr, mapping);
+}
+
+static int bcmgenet_rx_refill(struct bcmgenet_rx_ring *ring,
+ struct enet_cb *cb)
+{
+ struct bcmgenet_priv *priv = ring->priv;
+ int ret;
+
+ ret = bcmgenet_rx_alloc_cb(priv, ring->page_pool, priv->rx_buf_len, cb);
+ if (ret)
+ return ret;
+
+ bcmgenet_rx_arm_cb(priv, cb);
return 0;
}
@@ -2657,22 +2677,15 @@ static void bcmgenet_dim_work(struct work_struct *work)
}
/* Assign page_pool pages to RX DMA descriptors. */
-static int bcmgenet_alloc_rx_buffers(struct bcmgenet_priv *priv,
- struct bcmgenet_rx_ring *ring)
+static void bcmgenet_arm_rx_buffers(struct bcmgenet_priv *priv,
+ struct bcmgenet_rx_ring *ring)
{
- struct enet_cb *cb;
int i;
netif_dbg(priv, hw, priv->dev, "%s\n", __func__);
- /* loop here for each buffer needing assign */
- for (i = 0; i < ring->size; i++) {
- cb = ring->cbs + i;
- if (bcmgenet_rx_refill(ring, cb))
- return -ENOMEM;
- }
-
- return 0;
+ for (i = 0; i < ring->size; i++)
+ bcmgenet_rx_arm_cb(priv, ring->cbs + i);
}
static void bcmgenet_free_rx_buffers(struct bcmgenet_priv *priv)
@@ -2964,41 +2977,33 @@ static void bcmgenet_init_tx_ring(struct bcmgenet_priv *priv,
netif_napi_add_tx(priv->dev, &ring->napi, bcmgenet_tx_poll);
}
-static int bcmgenet_rx_ring_create_pool(struct bcmgenet_priv *priv,
- struct bcmgenet_rx_ring *ring)
+static struct page_pool *bcmgenet_create_rx_pool(struct bcmgenet_priv *priv,
+ unsigned int size)
{
/* Buffers may share a page, depending on PAGE_SIZE and the MTU.
- * bcmgenet_rx_refill() syncs each one for the device,
+ * bcmgenet_rx_arm_cb() syncs each one for the device,
* PP_FLAG_DMA_SYNC_DEV would sync the whole page.
*/
struct page_pool_params pp_params = {
.order = 0,
.flags = PP_FLAG_DMA_MAP,
- .pool_size = ring->size,
+ .pool_size = size,
.nid = NUMA_NO_NODE,
.dev = &priv->pdev->dev,
.dma_dir = DMA_FROM_DEVICE,
};
- int err;
-
- ring->page_pool = page_pool_create(&pp_params);
- if (IS_ERR(ring->page_pool)) {
- err = PTR_ERR(ring->page_pool);
- ring->page_pool = NULL;
- return err;
- }
- return 0;
+ return page_pool_create(&pp_params);
}
/* Initialize a RDMA ring */
-static int bcmgenet_init_rx_ring(struct bcmgenet_priv *priv,
- unsigned int index, unsigned int size,
- unsigned int start_ptr, unsigned int end_ptr)
+static void bcmgenet_init_rx_ring(struct bcmgenet_priv *priv,
+ unsigned int index, unsigned int size,
+ unsigned int start_ptr, unsigned int end_ptr,
+ struct page_pool *pool)
{
struct bcmgenet_rx_ring *ring = &priv->rx_rings[index];
u32 words_per_bd = WORDS_PER_BD(priv);
- int ret, i;
ring->priv = priv;
ring->index = index;
@@ -3008,21 +3013,11 @@ static int bcmgenet_init_rx_ring(struct bcmgenet_priv *priv,
ring->read_ptr = start_ptr;
ring->cb_ptr = start_ptr;
ring->end_ptr = end_ptr - 1;
+ ring->page_pool = pool;
/* Zeroing RDMA_PROD_INDEX below also clears the discard counter */
ring->old_discards = 0;
- ret = bcmgenet_rx_ring_create_pool(priv, ring);
- if (ret)
- return ret;
-
- ret = bcmgenet_alloc_rx_buffers(priv, ring);
- if (ret) {
- for (i = 0; i < ring->size; i++)
- bcmgenet_free_rx_cb(ring->cbs + i, ring->page_pool);
- page_pool_destroy(ring->page_pool);
- ring->page_pool = NULL;
- return ret;
- }
+ bcmgenet_arm_rx_buffers(priv, ring);
bcmgenet_init_dim(ring, bcmgenet_dim_work);
bcmgenet_init_rx_coalesce(ring);
@@ -3049,8 +3044,6 @@ static int bcmgenet_init_rx_ring(struct bcmgenet_priv *priv,
RDMA_WRITE_PTR);
bcmgenet_rdma_ring_writel(priv, index, end_ptr * words_per_bd - 1,
DMA_END_ADDR);
-
- return ret;
}
static void bcmgenet_enable_tx_napi(struct bcmgenet_priv *priv)
@@ -3239,18 +3232,17 @@ static void bcmgenet_destroy_rx_page_pools(struct bcmgenet_priv *priv)
*
* Queue 0 is also the default Rx queue with GENET_Q0_RX_BD_CNT descriptors.
*/
-static int bcmgenet_init_rx_queues(struct net_device *dev)
+static void bcmgenet_init_rx_queues(struct net_device *dev,
+ struct bcmgenet_dma_set *set)
{
struct bcmgenet_priv *priv = netdev_priv(dev);
unsigned int start = 0, end = GENET_Q0_RX_BD_CNT;
u32 i, ring_mask;
- int ret;
/* Initialize Rx priority queues */
for (i = 0; i <= priv->hw_params->rx_queues; i++) {
- ret = bcmgenet_init_rx_ring(priv, i, end - start, start, end);
- if (ret)
- return ret;
+ bcmgenet_init_rx_ring(priv, i, end - start, start, end,
+ set->page_pool[i]);
start = end;
end += priv->hw_params->rx_bds_per_q;
@@ -3263,8 +3255,6 @@ static int bcmgenet_init_rx_queues(struct net_device *dev)
/* Enable Rx rings */
ring_mask <<= DMA_RING_BUF_EN_SHIFT;
bcmgenet_rdma_writel(priv, ring_mask, DMA_CTRL);
-
- return 0;
}
static int bcmgenet_dma_teardown(struct bcmgenet_priv *priv)
@@ -3310,11 +3300,86 @@ static void bcmgenet_fini_dma(struct bcmgenet_priv *priv)
priv->tx_cbs = NULL;
}
-/* init_edma: Initialize DMA control register */
-static int bcmgenet_init_dma(struct bcmgenet_priv *priv, bool flush_rx)
+/* Hand back a set that was never installed */
+static void bcmgenet_free_dma_set(struct bcmgenet_priv *priv,
+ struct bcmgenet_dma_set *set)
+{
+ unsigned int start = 0, end = GENET_Q0_RX_BD_CNT;
+ unsigned int i, q;
+
+ for (q = 0; q <= priv->hw_params->rx_queues; q++) {
+ if (set->page_pool[q]) {
+ for (i = start; i < end; i++)
+ bcmgenet_free_rx_cb(set->rx_cbs + i,
+ set->page_pool[q]);
+ page_pool_destroy(set->page_pool[q]);
+ }
+
+ start = end;
+ end += priv->hw_params->rx_bds_per_q;
+ }
+
+ kfree(set->rx_cbs);
+ kfree(set->tx_cbs);
+ memset(set, 0, sizeof(*set));
+}
+
+/* Build everything a datapath of this buffer length needs. The running one
+ * keeps its own until the caller installs this set, so a failure here costs
+ * nothing.
+ */
+static int bcmgenet_alloc_dma(struct bcmgenet_priv *priv, unsigned int buf_len,
+ struct bcmgenet_dma_set *set)
+{
+ unsigned int start = 0, end = GENET_Q0_RX_BD_CNT;
+ unsigned int i, q;
+
+ memset(set, 0, sizeof(*set));
+
+ set->rx_cbs = kzalloc_objs(struct enet_cb, TOTAL_DESC);
+ set->tx_cbs = kzalloc_objs(struct enet_cb, TOTAL_DESC);
+ if (!set->rx_cbs || !set->tx_cbs)
+ goto err;
+
+ for (i = 0; i < TOTAL_DESC; i++) {
+ set->rx_cbs[i].bd_addr = priv->base +
+ priv->hw_params->rdma_offset +
+ i * DMA_DESC_SIZE;
+ set->tx_cbs[i].bd_addr = priv->base +
+ priv->hw_params->tdma_offset +
+ i * DMA_DESC_SIZE;
+ }
+
+ for (q = 0; q <= priv->hw_params->rx_queues; q++) {
+ set->page_pool[q] = bcmgenet_create_rx_pool(priv, end - start);
+ if (IS_ERR(set->page_pool[q])) {
+ set->page_pool[q] = NULL;
+ goto err;
+ }
+
+ for (i = start; i < end; i++)
+ if (bcmgenet_rx_alloc_cb(priv, set->page_pool[q],
+ buf_len, set->rx_cbs + i))
+ goto err;
+
+ start = end;
+ end += priv->hw_params->rx_bds_per_q;
+ }
+
+ return 0;
+
+err:
+ bcmgenet_free_dma_set(priv, set);
+
+ return -ENOMEM;
+}
+
+/* Install a set built by bcmgenet_alloc_dma() and start the engines. The set
+ * is consumed either way, a failure frees it and leaves no datapath behind.
+ */
+static int bcmgenet_init_dma(struct bcmgenet_priv *priv, bool flush_rx,
+ struct bcmgenet_dma_set *set)
{
- struct enet_cb *cb;
- unsigned int i;
int ret;
u32 reg;
@@ -3324,14 +3389,14 @@ static int bcmgenet_init_dma(struct bcmgenet_priv *priv, bool flush_rx)
ret = bcmgenet_tdma_disable(priv);
if (ret) {
netdev_err(priv->dev, "failed to halt Tx DMA\n");
- return ret;
+ goto err;
}
/* Disable RX DMA */
ret = bcmgenet_rdma_disable(priv);
if (ret) {
netdev_err(priv->dev, "failed to halt Rx DMA\n");
- return ret;
+ goto err;
}
/* Flush TX queues */
@@ -3347,49 +3412,21 @@ static int bcmgenet_init_dma(struct bcmgenet_priv *priv, bool flush_rx)
udelay(10);
}
- /* Initialize common Rx ring structures */
+ /* The set belongs to the datapath from here on */
priv->rx_bds = priv->base + priv->hw_params->rdma_offset;
priv->num_rx_bds = TOTAL_DESC;
- priv->rx_cbs = kzalloc_objs(struct enet_cb, priv->num_rx_bds);
- if (!priv->rx_cbs)
- return -ENOMEM;
+ priv->rx_cbs = set->rx_cbs;
- for (i = 0; i < priv->num_rx_bds; i++) {
- cb = priv->rx_cbs + i;
- cb->bd_addr = priv->rx_bds + i * DMA_DESC_SIZE;
- }
-
- /* Initialize common TX ring structures */
priv->tx_bds = priv->base + priv->hw_params->tdma_offset;
priv->num_tx_bds = TOTAL_DESC;
- priv->tx_cbs = kzalloc_objs(struct enet_cb, priv->num_tx_bds);
- if (!priv->tx_cbs) {
- kfree(priv->rx_cbs);
- priv->rx_cbs = NULL;
- return -ENOMEM;
- }
-
- for (i = 0; i < priv->num_tx_bds; i++) {
- cb = priv->tx_cbs + i;
- cb->bd_addr = priv->tx_bds + i * DMA_DESC_SIZE;
- }
+ priv->tx_cbs = set->tx_cbs;
/* Init rDma */
bcmgenet_rdma_writel(priv, priv->dma_max_burst_length,
DMA_SCB_BURST_SIZE);
/* Initialize Rx queues */
- ret = bcmgenet_init_rx_queues(priv->dev);
- if (ret) {
- netdev_err(priv->dev, "failed to initialize Rx queues\n");
- bcmgenet_free_rx_buffers(priv);
- bcmgenet_destroy_rx_page_pools(priv);
- kfree(priv->rx_cbs);
- priv->rx_cbs = NULL;
- kfree(priv->tx_cbs);
- priv->tx_cbs = NULL;
- return ret;
- }
+ bcmgenet_init_rx_queues(priv->dev, set);
/* Init tDma */
bcmgenet_tdma_writel(priv, priv->dma_max_burst_length,
@@ -3408,6 +3445,11 @@ static int bcmgenet_init_dma(struct bcmgenet_priv *priv, bool flush_rx)
bcmgenet_tdma_writel(priv, reg, DMA_CTRL);
return 0;
+
+err:
+ bcmgenet_free_dma_set(priv, set);
+
+ return ret;
}
/* Interrupt bottom half */
@@ -3580,6 +3622,7 @@ static void bcmgenet_netif_start(struct net_device *dev, bool start_phy)
static int bcmgenet_open(struct net_device *dev)
{
struct bcmgenet_priv *priv = netdev_priv(dev);
+ struct bcmgenet_dma_set set;
int ret;
netif_dbg(priv, ifup, dev, "bcmgenet_open\n");
@@ -3609,7 +3652,11 @@ static int bcmgenet_open(struct net_device *dev)
bcmgenet_hfb_restore(priv);
/* Reinitialize TDMA and RDMA and SW housekeeping */
- ret = bcmgenet_init_dma(priv, true);
+ ret = bcmgenet_alloc_dma(priv, priv->rx_buf_len, &set);
+ if (ret)
+ goto err_clk_disable;
+
+ ret = bcmgenet_init_dma(priv, true, &set);
if (ret) {
netdev_err(dev, "failed to initialize DMA\n");
goto err_clk_disable;
@@ -4464,6 +4511,7 @@ static int bcmgenet_resume(struct device *d)
struct net_device *dev = dev_get_drvdata(d);
struct bcmgenet_priv *priv = netdev_priv(dev);
struct bcmgenet_rxnfc_rule *rule;
+ struct bcmgenet_dma_set set;
int ret;
u32 reg;
@@ -4529,7 +4577,9 @@ static int bcmgenet_resume(struct device *d)
bcmgenet_hfb_restore(priv);
/* Reinitialize TDMA and RDMA and SW housekeeping */
- ret = bcmgenet_init_dma(priv, false);
+ ret = bcmgenet_alloc_dma(priv, priv->rx_buf_len, &set);
+ if (!ret)
+ ret = bcmgenet_init_dma(priv, false, &set);
if (ret) {
/* Leave the block clocked, close and suspend tear it down */
netdev_err(dev, "failed to initialize DMA\n");
diff --git a/drivers/net/ethernet/broadcom/genet/bcmgenet.h b/drivers/net/ethernet/broadcom/genet/bcmgenet.h
index 906639c1f012..1f48a67c5c01 100644
--- a/drivers/net/ethernet/broadcom/genet/bcmgenet.h
+++ b/drivers/net/ethernet/broadcom/genet/bcmgenet.h
@@ -541,6 +541,15 @@ struct bcmgenet_hw_params {
u32 words_per_bd;
};
+/* Everything an open datapath needs that can fail to be allocated. Built
+ * before the running one is given up, so a failure changes nothing.
+ */
+struct bcmgenet_dma_set {
+ struct enet_cb *rx_cbs;
+ struct enet_cb *tx_cbs;
+ struct page_pool *page_pool[GENET_MAX_MQ_CNT + 1];
+};
+
struct bcmgenet_skb_cb {
struct enet_cb *first_cb; /* First control block of SKB */
struct enet_cb *head_cb; /* Owns the head mapping */
--
2.53.0
^ permalink raw reply related [flat|nested] 18+ messages in thread* [PATCH net-next v10 7/8] net: bcmgenet: allow the MTU to be changed
2026-11-27 11:25 [PATCH net-next v10 0/8] net: bcmgenet: support larger MTUs Nicolai Buchwitz
` (5 preceding siblings ...)
2026-11-27 11:25 ` [PATCH net-next v10 6/8] net: bcmgenet: build the DMA rings before giving up the running ones Nicolai Buchwitz
@ 2026-11-27 11:25 ` Nicolai Buchwitz
2026-11-28 11:26 ` netdev-bot+sashiko
2026-11-27 11:25 ` [PATCH net-next v10 8/8] net: bcmgenet: reassemble jumbo frames from status block fragments Nicolai Buchwitz
7 siblings, 1 reply; 18+ messages in thread
From: Nicolai Buchwitz @ 2026-11-27 11:25 UTC (permalink / raw)
To: Doug Berger, Florian Fainelli, Nicolai Buchwitz,
Broadcom internal kernel review list, Andrew Lunn,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: Florian Fainelli, netdev, linux-kernel, Dave Stevenson
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.
Above that the threshold is quantised, so a band of MTUs shares one buffer
length, on 4K pages every MTU from 3309 up. A change within a band keeps
the running rings rather than building a second set, so it cannot fail on
memory either.
Only v5 is known to size the TBUF for a long frame and to carry the full
length in a transmit descriptor, so the older parts keep the default MTU
until someone confirms them.
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 | 149 +++++++++++++++++++++++--
1 file changed, 138 insertions(+), 11 deletions(-)
diff --git a/drivers/net/ethernet/broadcom/genet/bcmgenet.c b/drivers/net/ethernet/broadcom/genet/bcmgenet.c
index fc8b8400fcbb..1307faf135bd 100644
--- a/drivers/net/ethernet/broadcom/genet/bcmgenet.c
+++ b/drivers/net/ethernet/broadcom/genet/bcmgenet.c
@@ -92,6 +92,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))
@@ -3279,8 +3285,14 @@ static int bcmgenet_dma_teardown(struct bcmgenet_priv *priv)
return ret;
}
-static void bcmgenet_fini_dma(struct bcmgenet_priv *priv)
+/* A non NULL keep takes the rings instead of freeing them, so a restart that
+ * does not resize the buffers can hand them straight back to
+ * bcmgenet_init_dma().
+ */
+static void bcmgenet_fini_dma(struct bcmgenet_priv *priv,
+ struct bcmgenet_dma_set *keep)
{
+ struct bcmgenet_rx_ring *ring;
struct netdev_queue *txq;
int i;
@@ -3292,11 +3304,24 @@ static void bcmgenet_fini_dma(struct bcmgenet_priv *priv)
netdev_tx_reset_queue(txq);
}
- bcmgenet_free_rx_buffers(priv);
- bcmgenet_destroy_rx_page_pools(priv);
- kfree(priv->rx_cbs);
+ if (keep) {
+ memset(keep, 0, sizeof(*keep));
+ keep->rx_cbs = priv->rx_cbs;
+ keep->tx_cbs = priv->tx_cbs;
+
+ for (i = 0; i <= priv->hw_params->rx_queues; i++) {
+ ring = &priv->rx_rings[i];
+ keep->page_pool[i] = ring->page_pool;
+ ring->page_pool = NULL;
+ }
+ } else {
+ bcmgenet_free_rx_buffers(priv);
+ bcmgenet_destroy_rx_page_pools(priv);
+ kfree(priv->rx_cbs);
+ kfree(priv->tx_cbs);
+ }
+
priv->rx_cbs = NULL;
- kfree(priv->tx_cbs);
priv->tx_cbs = NULL;
}
@@ -3696,7 +3721,7 @@ static int bcmgenet_open(struct net_device *dev)
free_irq(priv->irq0, priv);
err_fini_dma:
bcmgenet_dma_teardown(priv);
- bcmgenet_fini_dma(priv);
+ bcmgenet_fini_dma(priv, NULL);
err_clk_disable:
if (priv->internal_phy)
bcmgenet_power_down(priv, GENET_POWER_PASSIVE);
@@ -3704,7 +3729,8 @@ static int bcmgenet_open(struct net_device *dev)
return ret;
}
-static void bcmgenet_netif_stop(struct net_device *dev, bool stop_phy)
+static void bcmgenet_netif_stop(struct net_device *dev, bool stop_phy,
+ struct bcmgenet_dma_set *keep)
{
struct bcmgenet_priv *priv = netdev_priv(dev);
@@ -3734,7 +3760,7 @@ static void bcmgenet_netif_stop(struct net_device *dev, bool stop_phy)
/* tx reclaim */
bcmgenet_tx_reclaim_all(dev);
- bcmgenet_fini_dma(priv);
+ bcmgenet_fini_dma(priv, keep);
}
static int bcmgenet_close(struct net_device *dev)
@@ -3746,7 +3772,7 @@ static int bcmgenet_close(struct net_device *dev)
/* A failed resume has torn the datapath down already */
if (priv->tx_cbs)
- bcmgenet_netif_stop(dev, false);
+ bcmgenet_netif_stop(dev, false, NULL);
/* Really kill the PHY state machine and disconnect from it */
phy_disconnect(dev->phydev);
@@ -3997,6 +4023,97 @@ 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)
+{
+ unsigned int buf_len = bcmgenet_rx_buf_len(new_mtu);
+ struct bcmgenet_priv *priv = netdev_priv(dev);
+ unsigned int old_mtu = dev->mtu;
+ struct bcmgenet_dma_set set;
+ bool reuse;
+ int ret;
+
+ /* Nothing to reprogram while down, the next open does it */
+ if (!netif_running(dev)) {
+ WRITE_ONCE(dev->mtu, new_mtu);
+ priv->rx_buf_len = buf_len;
+ return 0;
+ }
+
+ /* Below ETH_DATA_LEN everything is floored, so there is nothing to
+ * reprogram and rx_buf_len stays as the receive path reads it.
+ */
+ if (max_t(unsigned int, old_mtu, ETH_DATA_LEN) ==
+ max_t(unsigned int, new_mtu, ETH_DATA_LEN)) {
+ WRITE_ONCE(dev->mtu, new_mtu);
+ return 0;
+ }
+
+ /* The threshold is quantised, so a band of MTUs shares one buffer
+ * length and the running rings can serve the new MTU as they are.
+ */
+ reuse = buf_len == priv->rx_buf_len;
+ if (!reuse) {
+ ret = bcmgenet_alloc_dma(priv, buf_len, &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, reuse ? &set : NULL);
+
+ WRITE_ONCE(dev->mtu, new_mtu);
+ priv->rx_buf_len = buf_len;
+ 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);
+
+ /* 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);
+
+ mutex_unlock(&dev->phydev->lock);
+
+ /* Interrupts were off, so a latched link event is lost. Internal PHYs
+ * on v1-v4 are not polled either.
+ */
+ phy_mac_interrupt(dev->phydev);
+
+ /* An energy detect event cancelled with the work is still latched */
+ if (READ_ONCE(priv->irq0_stat))
+ schedule_work(&priv->bcmgenet_irq_work);
+
+ 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,
@@ -4008,6 +4125,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 */
@@ -4361,9 +4479,18 @@ 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;
priv->tx_thld_window = priv->dma_max_burst_length * ENET_BURST_UNIT;
+
+ /* Only v5 is known to size the TBUF for a long frame and to carry the
+ * full length in a transmit descriptor, the older parts stay at the
+ * default MTU
+ */
+ if (GENET_IS_V5(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");
@@ -4553,7 +4680,7 @@ static int bcmgenet_resume(struct device *d)
umac_enable_set(priv, CMD_RX_EN | CMD_TX_EN, false);
bcmgenet_rdma_disable(priv);
bcmgenet_intr_disable(priv);
- bcmgenet_fini_dma(priv);
+ bcmgenet_fini_dma(priv, NULL);
if (phy_is_started(dev->phydev) ||
dev->phydev->state == PHY_ERROR)
phy_stop(dev->phydev);
@@ -4665,7 +4792,7 @@ static int bcmgenet_suspend(struct device *d)
bcmgenet_fini_tx_napi(priv);
} else {
/* Teardown the interface */
- bcmgenet_netif_stop(dev, true);
+ bcmgenet_netif_stop(dev, true, NULL);
}
return 0;
--
2.53.0
^ permalink raw reply related [flat|nested] 18+ messages in thread* Re: [PATCH net-next v10 7/8] net: bcmgenet: allow the MTU to be changed
2026-11-27 11:25 ` [PATCH net-next v10 7/8] net: bcmgenet: allow the MTU to be changed Nicolai Buchwitz
@ 2026-11-28 11:26 ` netdev-bot+sashiko
2026-11-28 13:07 ` Nicolai Buchwitz
0 siblings, 1 reply; 18+ messages in thread
From: netdev-bot+sashiko @ 2026-11-28 11:26 UTC (permalink / raw)
To: nb
Cc: opendmb, florian.fainelli, bcm-kernel-feedback-list,
andrew+netdev, davem, edumazet, kuba, pabeni, f.fainelli, netdev,
linux-kernel, pierremarinleclercq88, dave.stevenson, justin.chen
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 0
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Medium] In bcmgenet_change_mtu(), if the DMA engine will not halt, the
driver frees RX buffers and page pools that the hardware descriptors…
--
net: bcmgenet: allow the MTU to be changed
This commit sets dev->max_mtu on GENET v5 from the packet ready threshold
and adds bcmgenet_change_mtu(). On a running interface it stops the
datapath, reprograms the MTU registers and restarts DMA while the PHY
keeps running. When the new MTU maps to the same rx_buf_len, the existing
rings are reused.
Link: https://github.com/raspberrypi/linux/issues/5561
> diff --git a/drivers/net/ethernet/broadcom/genet/bcmgenet.c b/drivers/net/ethernet/broadcom/genet/bcmgenet.c
> index fc8b8400fcbb5..1307faf135bd4 100644
> --- a/drivers/net/ethernet/broadcom/genet/bcmgenet.c
> +++ b/drivers/net/ethernet/broadcom/genet/bcmgenet.c
[ ... ]
> @@ -3997,6 +4023,97 @@ 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)
> +{
[ ... ]
> + /* The threshold is quantised, so a band of MTUs shares one buffer
> + * length and the running rings can serve the new MTU as they are.
> + */
> + reuse = buf_len == priv->rx_buf_len;
> + if (!reuse) {
> + ret = bcmgenet_alloc_dma(priv, buf_len, &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, reuse ? &set : NULL);
> +
> + WRITE_ONCE(dev->mtu, new_mtu);
> + priv->rx_buf_len = buf_len;
> + bcmgenet_set_mtu_regs(priv, new_mtu);
> +
> + ret = bcmgenet_init_dma(priv, true, &set);
> + if (ret) {
[Severity: Medium]
What happens to the RX buffers here if the DMA engine does not halt?
bcmgenet_netif_stop() ignores the return value of bcmgenet_dma_teardown():
bcmgenet_netif_stop() {
...
bcmgenet_dma_teardown(priv);
...
bcmgenet_tx_reclaim_all(dev);
bcmgenet_fini_dma(priv, keep);
}
On the reuse path, bcmgenet_fini_dma() moves the live rx_cbs, tx_cbs and
page pools into set. The RDMA descriptors still hold the DMA addresses of
those pages.
bcmgenet_init_dma() then checks the halt again with
bcmgenet_tdma_disable() and bcmgenet_rdma_disable(). On a timeout it
jumps to err before it rewrites any descriptor:
err:
bcmgenet_free_dma_set(priv, set);
bcmgenet_free_dma_set() is documented as:
/* Hand back a set that was never installed */
Here the set is the one the hardware is armed with. The helper returns
every page to its pool and calls page_pool_destroy(), which unmaps the
pages and hands them back to the page allocator.
After that, netif_close() runs bcmgenet_close(). Because tx_cbs is NULL,
bcmgenet_close() skips bcmgenet_netif_stop(), and nothing resets RDMA,
UMAC or RBUF. Can an RX engine that never reported halted then write into
pages that have been freed and reused?
The non-reuse path looks similar. bcmgenet_fini_dma(priv, NULL) frees the
old, still-armed rings regardless of what bcmgenet_dma_teardown()
returned. bcmgenet_close() and the resume path already have the same
"teardown failed, free anyway" pattern, but this patch makes it reachable
at runtime through an MTU change on a running v5 interface.
The commit message only says:
Only a DMA that refuses to halt still takes the interface down, because
nothing is left to run on.
It does not cover the hardware still referencing the freed buffers.
On a halt failure, would it be safer to WARN and leak the set rather than
free it? Another option is to reset the block before releasing the
buffers.
As far as I can tell, the later patch "net: bcmgenet: reassemble jumbo
frames from status block fragments" does not change this error path in
bcmgenet_init_dma() or bcmgenet_change_mtu(), so the issue remains at the
end of the series.
> + /* 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;
> + }
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261127-nb-genet-mtu-nn-v2-v10-0-749c7cc45d97%40tipi-net.de
^ permalink raw reply [flat|nested] 18+ messages in thread* Re: [PATCH net-next v10 7/8] net: bcmgenet: allow the MTU to be changed
2026-11-28 11:26 ` netdev-bot+sashiko
@ 2026-11-28 13:07 ` Nicolai Buchwitz
0 siblings, 0 replies; 18+ messages in thread
From: Nicolai Buchwitz @ 2026-11-28 13:07 UTC (permalink / raw)
To: netdev-bot+sashiko
Cc: opendmb, florian.fainelli, bcm-kernel-feedback-list,
andrew+netdev, davem, edumazet, kuba, pabeni, f.fainelli, netdev,
linux-kernel, pierremarinleclercq88, dave.stevenson, justin.chen
On 28.11.2026 12:26, netdev-bot+sashiko@kernel.org wrote:
> [...]
> [Severity: Medium]
> What happens to the RX buffers here if the DMA engine does not halt?
They get freed while the hardware may still write into them. But this is
not new, close, suspend and resume all ignore the teardown result too.
I'm not aware of any bug reports in the field regarding this.
I can fix this in a fllow up series.
> [...]
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH net-next v10 8/8] net: bcmgenet: reassemble jumbo frames from status block fragments
2026-11-27 11:25 [PATCH net-next v10 0/8] net: bcmgenet: support larger MTUs Nicolai Buchwitz
` (6 preceding siblings ...)
2026-11-27 11:25 ` [PATCH net-next v10 7/8] net: bcmgenet: allow the MTU to be changed Nicolai Buchwitz
@ 2026-11-27 11:25 ` Nicolai Buchwitz
2026-11-28 11:26 ` netdev-bot+sashiko
7 siblings, 1 reply; 18+ messages in thread
From: Nicolai Buchwitz @ 2026-11-27 11:25 UTC (permalink / raw)
To: Doug Berger, Florian Fainelli, Nicolai Buchwitz,
Broadcom internal kernel review list, Andrew Lunn,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: Florian Fainelli, netdev, linux-kernel, Justin Chen
The hardware does not truncate a frame longer than the packet ready
threshold. It splits the frame across descriptors and writes a status block
at the start of each one. The first fragment then arrives with SOP and no
EOP and is dropped as fragmented. This caps the MTU.
Strip the status blocks and reassemble the fragments. Only the last block
holds the checksum of the whole frame. Broadcom confirmed from the RTL that
every GENET revision splits long frames this way, not just the v5 this was
tested on.
On transmit the MAC only checksums a frame it holds in full, so anything
longer than the threshold falls back to software. At jumbo sizes the larger
frame saves more per packet overhead than the checksum costs.
UMAC_MAX_FRAME_LEN is 14 bit and counts the FCS. That puts the maximum MTU
at 16347.
The TX descriptor length field is wider than DMA_BUFLENGTH_MASK suggests,
that mask only extracts the length from the RX status word. A frame of
16361 bytes, the largest untagged frame that MTU allows, came back byte
exact 200 times over UMAC loopback.
Suggested-by: Justin Chen <justin.chen@broadcom.com>
Signed-off-by: Nicolai Buchwitz <nb@tipi-net.de>
---
drivers/net/ethernet/broadcom/genet/bcmgenet.c | 135 +++++++++++++++++++++----
drivers/net/ethernet/broadcom/genet/bcmgenet.h | 4 +-
2 files changed, 116 insertions(+), 23 deletions(-)
diff --git a/drivers/net/ethernet/broadcom/genet/bcmgenet.c b/drivers/net/ethernet/broadcom/genet/bcmgenet.c
index 1307faf135bd..ec196a71a734 100644
--- a/drivers/net/ethernet/broadcom/genet/bcmgenet.c
+++ b/drivers/net/ethernet/broadcom/genet/bcmgenet.c
@@ -92,11 +92,8 @@
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)
+/* UMAC_MAX_FRAME_LEN is 14 bits wide and counts the FCS */
+#define ENET_MAX_MTU (GENMASK(13, 0) - ENET_FRAME_OVERHEAD)
/* Tx/Rx DMA register offset, skip 256 descriptors */
#define WORDS_PER_BD(p) (p->hw_params->words_per_bd)
@@ -2439,6 +2436,52 @@ static int bcmgenet_rx_refill(struct bcmgenet_rx_ring *ring,
return 0;
}
+/* The rest of the frame carries no SOP. Drop it and do not count it again
+ * until the next SOP, unless this descriptor already ended the frame.
+ */
+static void bcmgenet_discard_frags(struct bcmgenet_rx_ring *ring, bool eop)
+{
+ ring->frag_drop = !eop;
+
+ if (!ring->frag_head)
+ return;
+
+ dev_kfree_skb_any(ring->frag_head);
+ ring->frag_head = NULL;
+}
+
+/* A frame longer than the threshold arrives in several descriptors, each with
+ * its own status block. Returns the frame once EOP is in. NULL means either
+ * more descriptors are coming or the frame is gone.
+ */
+static struct sk_buff *bcmgenet_add_frag(struct bcmgenet_rx_ring *ring,
+ struct page *page,
+ unsigned int offset,
+ unsigned int size,
+ unsigned int dma_flag,
+ unsigned int len)
+{
+ struct sk_buff *head = ring->frag_head;
+
+ if (unlikely(skb_shinfo(head)->nr_frags >= MAX_SKB_FRAGS)) {
+ BCMGENET_STATS64_INC((&ring->stats64), fragmented_errors);
+ bcmgenet_discard_frags(ring, dma_flag & DMA_EOP);
+ page_pool_put_full_page(ring->page_pool, page, true);
+ return NULL;
+ }
+
+ skb_add_rx_frag(head, skb_shinfo(head)->nr_frags, page,
+ offset + sizeof(struct status_64),
+ len - sizeof(struct status_64), size);
+
+ if (!(dma_flag & DMA_EOP))
+ return NULL;
+
+ ring->frag_head = NULL;
+
+ return head;
+}
+
/* bcmgenet_desc_rx - descriptor based rx process.
* this could be called from bottom half, or from NAPI polling method.
*/
@@ -2456,6 +2499,7 @@ static unsigned int bcmgenet_desc_rx(struct bcmgenet_rx_ring *ring,
unsigned int rxpktprocessed = 0, rxpkttoprocess;
unsigned int bytes_processed = 0;
unsigned int p_index, mask;
+ unsigned int rxframes = 0;
unsigned int discards;
/* Clear status before servicing to reduce spurious interrupts */
@@ -2503,6 +2547,7 @@ static unsigned int bcmgenet_desc_rx(struct bcmgenet_rx_ring *ring,
if (bcmgenet_rx_refill(ring, cb)) {
BCMGENET_STATS64_INC(stats, dropped);
+ bcmgenet_discard_frags(ring, false);
goto next;
}
@@ -2527,24 +2572,43 @@ static unsigned int bcmgenet_desc_rx(struct bcmgenet_rx_ring *ring,
__func__, p_index, ring->c_index,
ring->read_ptr, dma_length_status);
- /* Only the first descriptor carries the alignment pad */
- min_len = dma_flag & DMA_SOP ? GENET_RSB_PAD
- : sizeof(struct status_64);
+ /* Only the first descriptor carries the alignment pad. A head
+ * with more to come needs the Ethernet header in it, a
+ * continuation needs at least one payload byte.
+ */
+ if (dma_flag & DMA_SOP) {
+ min_len = GENET_RSB_PAD;
+ if (!(dma_flag & DMA_EOP))
+ min_len += ETH_HLEN;
+ } else {
+ min_len = sizeof(struct status_64) + 1;
+ }
/* Reject lengths that would underflow the SKB build path. */
if (unlikely(len > priv->rx_buf_len || len < min_len)) {
netif_err(priv, rx_status, dev,
"invalid packet length %d\n", len);
BCMGENET_STATS64_INC(stats, length_errors);
+ if ((dma_flag & DMA_SOP) && ring->frag_head)
+ BCMGENET_STATS64_INC(stats, fragmented_errors);
+ bcmgenet_discard_frags(ring, dma_flag & DMA_EOP);
page_pool_put_full_page(ring->page_pool, rx_page,
true);
goto next;
}
- if (unlikely(!(dma_flag & DMA_EOP) || !(dma_flag & DMA_SOP))) {
- netif_err(priv, rx_status, dev,
- "dropping fragmented packet!\n");
- BCMGENET_STATS64_INC(stats, fragmented_errors);
+ /* A new SOP picks up again after an incomplete frame */
+ if (dma_flag & DMA_SOP) {
+ if (ring->frag_head) {
+ BCMGENET_STATS64_INC(stats, fragmented_errors);
+ bcmgenet_discard_frags(ring, false);
+ }
+ ring->frag_drop = false;
+ } else if (unlikely(!ring->frag_head)) {
+ /* Rest of a dropped frame, or no SOP seen yet */
+ if (!ring->frag_drop)
+ BCMGENET_STATS64_INC(stats, fragmented_errors);
+ ring->frag_drop = !(dma_flag & DMA_EOP);
page_pool_put_full_page(ring->page_pool, rx_page,
true);
goto next;
@@ -2574,17 +2638,27 @@ static unsigned int bcmgenet_desc_rx(struct bcmgenet_rx_ring *ring,
DMA_RX_RXER)) == DMA_RX_RXER)
u64_stats_inc(&stats->errors);
u64_stats_update_end(&stats->syncp);
+ bcmgenet_discard_frags(ring, dma_flag & DMA_EOP);
page_pool_put_full_page(ring->page_pool, rx_page,
true);
goto next;
} /* error packet */
+ if (!(dma_flag & DMA_SOP)) {
+ skb = bcmgenet_add_frag(ring, rx_page, rx_offset,
+ rx_size, dma_flag, len);
+ if (!skb)
+ goto next;
+ goto deliver;
+ }
+
/* Build SKB from the page - data starts at hard_start,
* frame begins after RSB(64) + pad(2) = 66 bytes.
*/
skb = napi_build_skb(hard_start, rx_size);
if (unlikely(!skb)) {
BCMGENET_STATS64_INC(stats, dropped);
+ bcmgenet_discard_frags(ring, dma_flag & DMA_EOP);
page_pool_put_full_page(ring->page_pool, rx_page,
true);
goto next;
@@ -2596,17 +2670,26 @@ static unsigned int bcmgenet_desc_rx(struct bcmgenet_rx_ring *ring,
skb_reserve(skb, GENET_RSB_PAD);
__skb_put(skb, len - GENET_RSB_PAD);
- if (priv->crc_fwd_en) {
- skb_trim(skb, skb->len - ETH_FCS_LEN);
+ if (unlikely(!(dma_flag & DMA_EOP))) {
+ ring->frag_head = skb;
+ goto next;
+ }
+
+deliver:
+ /* The FCS trim may free the page with the last status block */
+ rx_csum = (__force __be16)(status->rx_csum & 0xffff);
+
+ if (priv->crc_fwd_en &&
+ unlikely(pskb_trim(skb, skb->len - ETH_FCS_LEN))) {
+ BCMGENET_STATS64_INC(stats, dropped);
+ dev_kfree_skb_any(skb);
+ goto next;
}
/* Set up checksum offload */
- if (dev->features & NETIF_F_RXCSUM) {
- rx_csum = (__force __be16)(status->rx_csum & 0xffff);
- if (rx_csum) {
- skb->csum = (__force __wsum)ntohs(rx_csum);
- skb->ip_summed = CHECKSUM_COMPLETE;
- }
+ if ((dev->features & NETIF_F_RXCSUM) && rx_csum) {
+ skb->csum = (__force __wsum)ntohs(rx_csum);
+ skb->ip_summed = CHECKSUM_COMPLETE;
}
len = skb->len;
@@ -2614,6 +2697,7 @@ static unsigned int bcmgenet_desc_rx(struct bcmgenet_rx_ring *ring,
/*Finish setting up the received SKB and send it to the kernel*/
skb->protocol = eth_type_trans(skb, priv->dev);
+ rxframes++;
u64_stats_update_begin(&stats->syncp);
u64_stats_inc(&stats->packets);
@@ -2640,7 +2724,8 @@ static unsigned int bcmgenet_desc_rx(struct bcmgenet_rx_ring *ring,
}
ring->dim.bytes += bytes_processed;
- ring->dim.packets += rxpktprocessed;
+ /* A long frame spans several descriptors but is one packet */
+ ring->dim.packets += rxframes;
return rxpktprocessed;
}
@@ -2708,6 +2793,8 @@ static void bcmgenet_free_rx_buffers(struct bcmgenet_priv *priv)
cb = ring->cbs + i;
bcmgenet_free_rx_cb(cb, ring->page_pool);
}
+ /* A partial frame still holds pages of this pool */
+ bcmgenet_discard_frags(ring, true);
}
}
@@ -2778,7 +2865,9 @@ static void bcmgenet_link_intr_enable(struct bcmgenet_priv *priv)
}
/* Receive threshold in register units. Covers the alignment bytes and the
- * frame, but not the status block, which the hardware adds on top.
+ * frame, but not the status block, which the hardware adds on top. The
+ * usable maximum is whichever of register and page is smaller. A longer
+ * frame arrives in several descriptors.
*/
static unsigned int bcmgenet_pkt_rdy_thld(unsigned int mtu)
{
@@ -3311,6 +3400,8 @@ static void bcmgenet_fini_dma(struct bcmgenet_priv *priv,
for (i = 0; i <= priv->hw_params->rx_queues; i++) {
ring = &priv->rx_rings[i];
+ /* A partial frame holds pages the ring keeps */
+ bcmgenet_discard_frags(ring, true);
keep->page_pool[i] = ring->page_pool;
ring->page_pool = NULL;
}
diff --git a/drivers/net/ethernet/broadcom/genet/bcmgenet.h b/drivers/net/ethernet/broadcom/genet/bcmgenet.h
index 1f48a67c5c01..8f432a830a5a 100644
--- a/drivers/net/ethernet/broadcom/genet/bcmgenet.h
+++ b/drivers/net/ethernet/broadcom/genet/bcmgenet.h
@@ -446,7 +446,7 @@ struct bcmgenet_rx_stats64 {
#define DMA_RATE_ADJ_MASK 0xFF
/* Tx/Rx Dma Descriptor common bits*/
-#define DMA_BUFLENGTH_MASK 0x0fff
+#define DMA_BUFLENGTH_MASK 0x0fff /* RX status word only */
#define DMA_BUFLENGTH_SHIFT 16
#define DMA_OWN 0x8000
#define DMA_EOP 0x4000
@@ -598,6 +598,8 @@ struct bcmgenet_rx_ring {
unsigned int cb_ptr; /* Rx ring initial CB ptr */
unsigned int end_ptr; /* Rx ring end CB ptr */
unsigned int old_discards;
+ struct sk_buff *frag_head; /* frame being reassembled */
+ bool frag_drop; /* discarding until the next SOP */
struct bcmgenet_net_dim dim;
u32 rx_max_coalesced_frames;
u32 rx_coalesce_usecs;
--
2.53.0
^ permalink raw reply related [flat|nested] 18+ messages in thread* Re: [PATCH net-next v10 8/8] net: bcmgenet: reassemble jumbo frames from status block fragments
2026-11-27 11:25 ` [PATCH net-next v10 8/8] net: bcmgenet: reassemble jumbo frames from status block fragments Nicolai Buchwitz
@ 2026-11-28 11:26 ` netdev-bot+sashiko
2026-11-28 13:12 ` Nicolai Buchwitz
0 siblings, 1 reply; 18+ messages in thread
From: netdev-bot+sashiko @ 2026-11-28 11:26 UTC (permalink / raw)
To: nb
Cc: opendmb, florian.fainelli, bcm-kernel-feedback-list,
andrew+netdev, davem, edumazet, kuba, pabeni, f.fainelli, netdev,
linux-kernel, pierremarinleclercq88, dave.stevenson, justin.chen
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 2 · Low: 0
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Medium] In bcmgenet_desc_rx()
(drivers/net/ethernet/broadcom/genet/bcmgenet.c), the patch raises the…
- [Medium] For a frame reassembled from several descriptors,
bcmgenet_desc_rx() jumps from the bcmgenet_add_frag() path to…
--
net: bcmgenet: reassemble jumbo frames from status block fragments
GENET splits frames longer than the RX packet ready threshold across
several descriptors, each with its own status block. This patch removes
those status blocks and reassembles the fragments into one skb, which
lifts the MTU cap. The maximum MTU is now 16347, based on the 14-bit
UMAC_MAX_FRAME_LEN.
> diff --git a/drivers/net/ethernet/broadcom/genet/bcmgenet.c b/drivers/net/ethernet/broadcom/genet/bcmgenet.c
> index 1307faf135bd4..ec196a71a7347 100644
> --- a/drivers/net/ethernet/broadcom/genet/bcmgenet.c
> +++ b/drivers/net/ethernet/broadcom/genet/bcmgenet.c
[ ... ]
> @@ -2527,24 +2572,43 @@ static unsigned int bcmgenet_desc_rx(struct bcmgenet_rx_ring *ring,
> __func__, p_index, ring->c_index,
> ring->read_ptr, dma_length_status);
>
> - /* Only the first descriptor carries the alignment pad */
> - min_len = dma_flag & DMA_SOP ? GENET_RSB_PAD
> - : sizeof(struct status_64);
> + /* Only the first descriptor carries the alignment pad. A head
> + * with more to come needs the Ethernet header in it, a
> + * continuation needs at least one payload byte.
> + */
> + if (dma_flag & DMA_SOP) {
> + min_len = GENET_RSB_PAD;
> + if (!(dma_flag & DMA_EOP))
> + min_len += ETH_HLEN;
> + } else {
> + min_len = sizeof(struct status_64) + 1;
> + }
>
> /* Reject lengths that would underflow the SKB build path. */
> if (unlikely(len > priv->rx_buf_len || len < min_len)) {
> netif_err(priv, rx_status, dev,
> "invalid packet length %d\n", len);
> BCMGENET_STATS64_INC(stats, length_errors);
> + if ((dma_flag & DMA_SOP) && ring->frag_head)
> + BCMGENET_STATS64_INC(stats, fragmented_errors);
> + bcmgenet_discard_frags(ring, dma_flag & DMA_EOP);
[Severity: Medium]
Can a split frame end with a descriptor that holds only its status
block plus DMA_EOP, with no payload?
The previous patch in this series ("net: bcmgenet: allow a continuation
descriptor without the alignment pad") set the non-SOP minimum to
sizeof(struct status_64). This patch raises it to
sizeof(struct status_64) + 1.
Suppose the hardware posts an EOP descriptor with
len == sizeof(struct status_64). It would then land in this branch.
The branch logs "invalid packet length" and bumps length_errors. Then
bcmgenet_discard_frags() frees ring->frag_head, which at that point
holds every payload byte of a complete, valid frame.
That can only happen when the alignment pad plus the frame length is an
exact multiple of the RX threshold. On 4K pages the threshold is 3584
bytes, so frames of 7166, 10750 and 14334 bytes would hit it (FCS
included when crc_fwd_en is set). MTU 9000 and MTU 16347 can both reach
these sizes.
The 16361 byte loopback test in the commit message doesn't fall on one
of these boundaries.
Would it make sense to accept len == sizeof(struct status_64) with
DMA_EOP as an empty terminator? bcmgenet_add_frag() would add no frag
and deliver frag_head with that descriptor's checksum. Or can Broadcom
confirm that the hardware never emits such a descriptor?
> page_pool_put_full_page(ring->page_pool, rx_page,
> true);
> goto next;
> }
[ ... ]
> @@ -2574,17 +2638,27 @@ static unsigned int bcmgenet_desc_rx(struct bcmgenet_rx_ring *ring,
> DMA_RX_RXER)) == DMA_RX_RXER)
> u64_stats_inc(&stats->errors);
> u64_stats_update_end(&stats->syncp);
> + bcmgenet_discard_frags(ring, dma_flag & DMA_EOP);
> page_pool_put_full_page(ring->page_pool, rx_page,
> true);
> goto next;
> } /* error packet */
>
> + if (!(dma_flag & DMA_SOP)) {
> + skb = bcmgenet_add_frag(ring, rx_page, rx_offset,
> + rx_size, dma_flag, len);
> + if (!skb)
> + goto next;
> + goto deliver;
> + }
[Severity: Medium]
For a reassembled frame, dma_flag at the deliver label holds the status
word of the final EOP descriptor. The stats code in bcmgenet_desc_rx()
then does:
if (dma_flag & DMA_RX_MULT)
u64_stats_inc(&stats->multicast);
else if (dma_flag & DMA_RX_BRDCAST)
u64_stats_inc(&stats->broadcast);
The commit message says the status blocks of a split frame differ
("Only the last block holds the checksum of the whole frame"). It
doesn't say which block carries the DMA_RX_MULT and DMA_RX_BRDCAST
classification. The MAC already has that from the destination address
when it writes the SOP block.
If these flags are set only in the SOP status block, would jumbo
multicast and broadcast frames go uncounted in stats->multicast and
stats->broadcast?
Could the SOP descriptor's flags be saved when frag_head is set up and
used here instead?
>
> /* Build SKB from the page - data starts at hard_start,
> * frame begins after RSB(64) + pad(2) = 66 bytes.
> */
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261127-nb-genet-mtu-nn-v2-v10-0-749c7cc45d97%40tipi-net.de
^ permalink raw reply [flat|nested] 18+ messages in thread* Re: [PATCH net-next v10 8/8] net: bcmgenet: reassemble jumbo frames from status block fragments
2026-11-28 11:26 ` netdev-bot+sashiko
@ 2026-11-28 13:12 ` Nicolai Buchwitz
0 siblings, 0 replies; 18+ messages in thread
From: Nicolai Buchwitz @ 2026-11-28 13:12 UTC (permalink / raw)
To: netdev-bot+sashiko
Cc: opendmb, florian.fainelli, bcm-kernel-feedback-list,
andrew+netdev, davem, edumazet, kuba, pabeni, f.fainelli, netdev,
linux-kernel, pierremarinleclercq88, dave.stevenson, justin.chen
On 28.11.2026 12:26, netdev-bot+sashiko@kernel.org wrote:
> [...]
> [Severity: Medium]
> Can a split frame end with a descriptor that holds only its status
> block plus DMA_EOP, with no payload?
Not on a bcm2711. I tested both boundaries reachable with MTU 9000, 3582
and 7166, 200 frames each. All bytes were delivered and I observed no
errors.
EOP landed on the last descriptor that had data.
> [...]
> [Severity: Medium]
> For a reassembled frame, dma_flag at the deliver label holds the status
> word of the final EOP descriptor. The stats code in bcmgenet_desc_rx()
> then does:
>
> if (dma_flag & DMA_RX_MULT)
> u64_stats_inc(&stats->multicast);
> else if (dma_flag & DMA_RX_BRDCAST)
> u64_stats_inc(&stats->broadcast);
>
> The commit message says the status blocks of a split frame differ
> ("Only the last block holds the checksum of the whole frame"). It
> doesn't say which block carries the DMA_RX_MULT and DMA_RX_BRDCAST
> classification. The MAC already has that from the destination address
> when it writes the SOP block.
>
> If these flags are set only in the SOP status block, would jumbo
> multicast and broadcast frames go uncounted in stats->multicast and
> stats->broadcast?
They do, but the SOP block has no flags either.
The MAC just stops setting DMA_RX_BRDCAST and DMA_RX_MULT above 1518
bytes,
same boundary at MTU 1500 as at 9000. So a full size VLAN tagged
broadcast
frame is already miscounted today.
I'd make this a separate fix for net, using skb->pkt_type instead.
> Could the SOP descriptor's flags be saved when frag_head is set up and
> used here instead?
>
>>
>> /* Build SKB from the page - data starts at hard_start,
>> * frame begins after RSB(64) + pad(2) = 66 bytes.
>> */
>
> [ ... ]
^ permalink raw reply [flat|nested] 18+ messages in thread