Skip to content

Commit ca1bb3f

Browse files
clemensgPaolo Abeni
authored andcommitted
net: fec: account for VLAN header in frame length calculations
The MAX_FL (maximum frame length) and related calculations used ETH_HLEN, which does not account for the 4-byte VLAN tag in tagged frames. This caused the hardware to reject valid VLAN frames as oversized, resulting in RX errors and dropped packets. Use VLAN_ETH_HLEN instead of ETH_HLEN in the MAX_FL register setup, cut-through mode threshold, buffer allocation, and max_mtu calculation. Cc: stable@kernel.org # v6.18+ Fixes: 62b5bb7 ("net: fec: update MAX_FL based on the current MTU") Fixes: d466c16 ("net: fec: enable the Jumbo frame support for i.MX8QM") Fixes: 59e9bf0 ("net: fec: add change_mtu to support dynamic buffer allocation") Fixes: ec2a168 ("net: fec: use a member variable for maximum buffer size") Signed-off-by: Clemens Gruber <mail@clemensgruber.at> Reviewed-by: Wei Fang <wei.fang@nxp.com> Link: https://patch.msgid.link/20260121083751.66997-1-mail@clemensgruber.at Signed-off-by: Paolo Abeni <pabeni@redhat.com>
1 parent cc4816b commit ca1bb3f

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

drivers/net/ethernet/freescale/fec_main.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,7 +1150,7 @@ fec_restart(struct net_device *ndev)
11501150
u32 rcntl = FEC_RCR_MII;
11511151

11521152
if (OPT_ARCH_HAS_MAX_FL)
1153-
rcntl |= (fep->netdev->mtu + ETH_HLEN + ETH_FCS_LEN) << 16;
1153+
rcntl |= (fep->netdev->mtu + VLAN_ETH_HLEN + ETH_FCS_LEN) << 16;
11541154

11551155
if (fep->bufdesc_ex)
11561156
fec_ptp_save_state(fep);
@@ -1285,12 +1285,13 @@ fec_restart(struct net_device *ndev)
12851285

12861286
/* When Jumbo Frame is enabled, the FIFO may not be large enough
12871287
* to hold an entire frame. In such cases, if the MTU exceeds
1288-
* (PKT_MAXBUF_SIZE - ETH_HLEN - ETH_FCS_LEN), configure the interface
1289-
* to operate in cut-through mode, triggered by the FIFO threshold.
1288+
* (PKT_MAXBUF_SIZE - VLAN_ETH_HLEN - ETH_FCS_LEN), configure
1289+
* the interface to operate in cut-through mode, triggered by
1290+
* the FIFO threshold.
12901291
* Otherwise, enable the ENET store-and-forward mode.
12911292
*/
12921293
if ((fep->quirks & FEC_QUIRK_JUMBO_FRAME) &&
1293-
(ndev->mtu > (PKT_MAXBUF_SIZE - ETH_HLEN - ETH_FCS_LEN)))
1294+
(ndev->mtu > (PKT_MAXBUF_SIZE - VLAN_ETH_HLEN - ETH_FCS_LEN)))
12941295
writel(0xF, fep->hwp + FEC_X_WMRK);
12951296
else
12961297
writel(FEC_TXWMRK_STRFWD, fep->hwp + FEC_X_WMRK);
@@ -4037,7 +4038,7 @@ static int fec_change_mtu(struct net_device *ndev, int new_mtu)
40374038
if (netif_running(ndev))
40384039
return -EBUSY;
40394040

4040-
order = get_order(new_mtu + ETH_HLEN + ETH_FCS_LEN
4041+
order = get_order(new_mtu + VLAN_ETH_HLEN + ETH_FCS_LEN
40414042
+ FEC_DRV_RESERVE_SPACE);
40424043
fep->rx_frame_size = (PAGE_SIZE << order) - FEC_DRV_RESERVE_SPACE;
40434044
fep->pagepool_order = order;
@@ -4588,7 +4589,7 @@ fec_probe(struct platform_device *pdev)
45884589
else
45894590
fep->max_buf_size = PKT_MAXBUF_SIZE;
45904591

4591-
ndev->max_mtu = fep->max_buf_size - ETH_HLEN - ETH_FCS_LEN;
4592+
ndev->max_mtu = fep->max_buf_size - VLAN_ETH_HLEN - ETH_FCS_LEN;
45924593

45934594
ret = register_netdev(ndev);
45944595
if (ret)

0 commit comments

Comments
 (0)