The RX buffers for GEM can have a maximum size of 16320 bytes
(0xff in the RXBS field of the DMACFG register means 255*64 =
16320 bytes).
The GEM IP has configurable maximum jumbo frame length that can go up to
16383. The actual value for this limit can be found in the
"jumbo_max_length" field (bits 0..13) of the DCFG2 register.
Currently, the macb driver doesn't use the DCFG2 register when
determining the max MTU, instead an hardcoded value (jumbo_max_len in
struct macb_config) is used for each platform. Right now the maximum
value for jumbo_max_len is 10240 (0x2800).
GEM uses one buffer per packet which means that one buffer must allow
room for the max MTU plus L2 encapsulation and alignment. This is a
limitation of the driver.
This commit adds a limit to max_mtu and rx_buffer_size so that the RXBS
field can never overflow when a large MTU is used.
With this commit, it is now possible to add new platforms with a
jumbo_max_len of 16383 so that the hardware properties of each IP can be
properly captured in struct macb_config.
Signed-off-by: Charles Perry <charles.perry@microchip.com>
Reviewed-by: Simon Horman <horms@kernel.org>
---
drivers/net/ethernet/cadence/macb_main.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c
index 32f9463edff0..c653ea6cadef 100644
--- a/drivers/net/ethernet/cadence/macb_main.c
+++ b/drivers/net/ethernet/cadence/macb_main.c
@@ -52,6 +52,7 @@ struct sifive_fu540_macb_mgmt {
#define MACB_RX_BUFFER_SIZE 128
#define RX_BUFFER_MULTIPLE 64 /* bytes */
+#define RX_BUFFER_MAX (0xFF * RX_BUFFER_MULTIPLE) /* 16320 bytes */
#define DEFAULT_RX_RING_SIZE 512 /* must be power of 2 */
#define MIN_RX_RING_SIZE 64
@@ -2603,7 +2604,7 @@ static void macb_init_rx_buffer_size(struct macb *bp, size_t size)
if (!macb_is_gem(bp)) {
bp->rx_buffer_size = MACB_RX_BUFFER_SIZE;
} else {
- bp->rx_buffer_size = size;
+ bp->rx_buffer_size = MIN(size, RX_BUFFER_MAX);
if (bp->rx_buffer_size % RX_BUFFER_MULTIPLE) {
netdev_dbg(bp->dev,
@@ -5794,7 +5795,8 @@ static int macb_probe(struct platform_device *pdev)
/* MTU range: 68 - 1518 or 10240 */
dev->min_mtu = GEM_MTU_MIN_SIZE;
if ((bp->caps & MACB_CAPS_JUMBO) && bp->jumbo_max_len)
- dev->max_mtu = bp->jumbo_max_len - ETH_HLEN - ETH_FCS_LEN;
+ dev->max_mtu = MIN(bp->jumbo_max_len, RX_BUFFER_MAX) -
+ ETH_HLEN - ETH_FCS_LEN;
else
dev->max_mtu = 1536 - ETH_HLEN - ETH_FCS_LEN;
--
2.47.3
Hello Charles, On Fri Mar 13, 2026 at 3:06 PM CET, Charles Perry wrote: > The RX buffers for GEM can have a maximum size of 16320 bytes > (0xff in the RXBS field of the DMACFG register means 255*64 = > 16320 bytes). > > The GEM IP has configurable maximum jumbo frame length that can go up to > 16383. The actual value for this limit can be found in the > "jumbo_max_length" field (bits 0..13) of the DCFG2 register. > Currently, the macb driver doesn't use the DCFG2 register when > determining the max MTU, instead an hardcoded value (jumbo_max_len in > struct macb_config) is used for each platform. Right now the maximum > value for jumbo_max_len is 10240 (0x2800). If DCFG2 contains the value then we can runtime detect it. With that, we could make the macb_config->jumbo_max_len attribute optional. Then start dropping it from platforms where we know we can trust the DCFG2 value. An alternative would be to validate macb_config->jumbo_max_len against the DCFG2 value, but that is less useful. Thanks, -- Théo Lebrun, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
On Mon, Mar 16, 2026 at 06:21:38PM +0100, Théo Lebrun wrote: > Hello Charles, > > On Fri Mar 13, 2026 at 3:06 PM CET, Charles Perry wrote: > > The RX buffers for GEM can have a maximum size of 16320 bytes > > (0xff in the RXBS field of the DMACFG register means 255*64 = > > 16320 bytes). > > > > The GEM IP has configurable maximum jumbo frame length that can go up to > > 16383. The actual value for this limit can be found in the > > "jumbo_max_length" field (bits 0..13) of the DCFG2 register. > > Currently, the macb driver doesn't use the DCFG2 register when > > determining the max MTU, instead an hardcoded value (jumbo_max_len in > > struct macb_config) is used for each platform. Right now the maximum > > value for jumbo_max_len is 10240 (0x2800). > > If DCFG2 contains the value then we can runtime detect it. With that, we > could make the macb_config->jumbo_max_len attribute optional. Then > start dropping it from platforms where we know we can trust the DCFG2 > value. > Hello Théo, That would be a good idea. We could use "jumbo_max_len == 0" as a way to signal that the DCFG2 register should be used for determining the max MTU. However, that's a new feature and it doesn't belong in this patch. All I want to do in this patchset is put the real value of jumbo_max_length in the PIC64-HPSC macb_config and make sure the driver doesn't overflow when that's used. Thanks, Charles > An alternative would be to validate macb_config->jumbo_max_len against > the DCFG2 value, but that is less useful. > > Thanks, > > -- > Théo Lebrun, Bootlin > Embedded Linux and Kernel engineering > https://bootlin.com >
On 3/16/26 7:26 PM, Charles Perry wrote: > On Mon, Mar 16, 2026 at 06:21:38PM +0100, Théo Lebrun wrote: >> Hello Charles, >> >> On Fri Mar 13, 2026 at 3:06 PM CET, Charles Perry wrote: >>> The RX buffers for GEM can have a maximum size of 16320 bytes >>> (0xff in the RXBS field of the DMACFG register means 255*64 = >>> 16320 bytes). >>> >>> The GEM IP has configurable maximum jumbo frame length that can go up to >>> 16383. The actual value for this limit can be found in the >>> "jumbo_max_length" field (bits 0..13) of the DCFG2 register. >>> Currently, the macb driver doesn't use the DCFG2 register when >>> determining the max MTU, instead an hardcoded value (jumbo_max_len in >>> struct macb_config) is used for each platform. Right now the maximum >>> value for jumbo_max_len is 10240 (0x2800). >> >> If DCFG2 contains the value then we can runtime detect it. With that, we >> could make the macb_config->jumbo_max_len attribute optional. Then >> start dropping it from platforms where we know we can trust the DCFG2 >> value. >> > > Hello Théo, > > That would be a good idea. We could use "jumbo_max_len == 0" as a way to > signal that the DCFG2 register should be used for determining the max MTU. > > However, that's a new feature and it doesn't belong in this patch. All I > want to do in this patchset is put the real value of jumbo_max_length in > the PIC64-HPSC macb_config and make sure the driver doesn't overflow when > that's used. FWIW, I agree that is better suited for a follow-up than for the initial bring-up. /P
On Tue Mar 17, 2026 at 1:29 PM CET, Paolo Abeni wrote: > On 3/16/26 7:26 PM, Charles Perry wrote: >> On Mon, Mar 16, 2026 at 06:21:38PM +0100, Théo Lebrun wrote: >>> Hello Charles, >>> >>> On Fri Mar 13, 2026 at 3:06 PM CET, Charles Perry wrote: >>>> The RX buffers for GEM can have a maximum size of 16320 bytes >>>> (0xff in the RXBS field of the DMACFG register means 255*64 = >>>> 16320 bytes). >>>> >>>> The GEM IP has configurable maximum jumbo frame length that can go up to >>>> 16383. The actual value for this limit can be found in the >>>> "jumbo_max_length" field (bits 0..13) of the DCFG2 register. >>>> Currently, the macb driver doesn't use the DCFG2 register when >>>> determining the max MTU, instead an hardcoded value (jumbo_max_len in >>>> struct macb_config) is used for each platform. Right now the maximum >>>> value for jumbo_max_len is 10240 (0x2800). >>> >>> If DCFG2 contains the value then we can runtime detect it. With that, we >>> could make the macb_config->jumbo_max_len attribute optional. Then >>> start dropping it from platforms where we know we can trust the DCFG2 >>> value. >>> >> >> Hello Théo, >> >> That would be a good idea. We could use "jumbo_max_len == 0" as a way to >> signal that the DCFG2 register should be used for determining the max MTU. >> >> However, that's a new feature and it doesn't belong in this patch. All I >> want to do in this patchset is put the real value of jumbo_max_length in >> the PIC64-HPSC macb_config and make sure the driver doesn't overflow when >> that's used. > > FWIW, I agree that is better suited for a follow-up than for the initial > bring-up. then: Reviewed-by: Théo Lebrun <theo.lebrun@bootlin.com> Thanks, -- Théo Lebrun, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
© 2016 - 2026 Red Hat, Inc.