Message ID | 20231104-gemini-largeframe-fix-v1-1-9c5513f22f33@linaro.org (mailing list archive) |
---|---|
State | Superseded |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | Fix large frames in the Gemini ethernet driver | expand |
> + if (mtu > MTU_SIZE_BIT_MASK) { > + netdev_err(netdev, "%s: MTU too big, max size 2047 bytes, capped\n", __func__); > + mtu = MTU_SIZE_BIT_MASK; > + } So this should not actually happen. If it does, some protocol above is ignoring the MTU. And if that happens, you are going to spam the log at line rate. Packets which are truncated are also pretty useless. They are likely to be dropped by the receiver when the CRC fails. So i would suggest drop them here, and increment a counter. > #define SOF_EOF_BIT_MASK 0x3fffffff > -#define SOF_BIT 0x80000000 > -#define EOF_BIT 0x40000000 > -#define EOFIE_BIT BIT(29) > -#define MTU_SIZE_BIT_MASK 0x1fff > +#define SOF_BIT BIT(31) /* Start of Frame */ > +#define EOF_BIT BIT(30) /* End of Frame */ > +#define EOFIE_BIT BIT(29) /* End of Frame Interrupt Enable */ > +#define MTU_SIZE_BIT_MASK 0x7ff /* Max MTU 2047 bytes */ Apart from the MTU_SIZE_BIT_MASK, this looks mostly unrelated. Andrew --- pw-bot: cr
diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c index 5423fe26b4ef..e12d14359133 100644 --- a/drivers/net/ethernet/cortina/gemini.c +++ b/drivers/net/ethernet/cortina/gemini.c @@ -1151,6 +1151,11 @@ static int gmac_map_tx_bufs(struct net_device *netdev, struct sk_buff *skb, if (skb->protocol == htons(ETH_P_8021Q)) mtu += VLAN_HLEN; + if (mtu > MTU_SIZE_BIT_MASK) { + netdev_err(netdev, "%s: MTU too big, max size 2047 bytes, capped\n", __func__); + mtu = MTU_SIZE_BIT_MASK; + } + word1 = skb->len; word3 = SOF_BIT; @@ -2464,11 +2469,12 @@ static int gemini_ethernet_port_probe(struct platform_device *pdev) netdev->hw_features = GMAC_OFFLOAD_FEATURES; netdev->features |= GMAC_OFFLOAD_FEATURES | NETIF_F_GRO; - /* We can handle jumbo frames up to 10236 bytes so, let's accept - * payloads of 10236 bytes minus VLAN and ethernet header + /* We can receive jumbo frames up to 10236 bytes but only + * transmit 2047 bytes so, let's accept payloads of 2047 + * bytes minus VLAN and ethernet header */ netdev->min_mtu = ETH_MIN_MTU; - netdev->max_mtu = 10236 - VLAN_ETH_HLEN; + netdev->max_mtu = MTU_SIZE_BIT_MASK - VLAN_ETH_HLEN; port->freeq_refill = 0; netif_napi_add(netdev, &port->napi, gmac_napi_poll); diff --git a/drivers/net/ethernet/cortina/gemini.h b/drivers/net/ethernet/cortina/gemini.h index 9fdf77d5eb37..d7101bfcb4a0 100644 --- a/drivers/net/ethernet/cortina/gemini.h +++ b/drivers/net/ethernet/cortina/gemini.h @@ -499,10 +499,10 @@ union gmac_txdesc_3 { }; #define SOF_EOF_BIT_MASK 0x3fffffff -#define SOF_BIT 0x80000000 -#define EOF_BIT 0x40000000 -#define EOFIE_BIT BIT(29) -#define MTU_SIZE_BIT_MASK 0x1fff +#define SOF_BIT BIT(31) /* Start of Frame */ +#define EOF_BIT BIT(30) /* End of Frame */ +#define EOFIE_BIT BIT(29) /* End of Frame Interrupt Enable */ +#define MTU_SIZE_BIT_MASK 0x7ff /* Max MTU 2047 bytes */ /* GMAC Tx Descriptor */ struct gmac_txdesc {
The RX max frame size is over 10000 for the Gemini ethernet, but the TX max frame size is actually just 2047 (0x7ff after checking the datasheet). Reflect this in what we offer to Linux, cap the MTU at the TX max frame minus ethernet headers. Use the BIT() macro for related bit flags so these TX settings are consistent. Fixes: 4d5ae32f5e1e ("net: ethernet: Add a driver for Gemini gigabit ethernet") Signed-off-by: Linus Walleij <linus.walleij@linaro.org> --- drivers/net/ethernet/cortina/gemini.c | 12 +++++++++--- drivers/net/ethernet/cortina/gemini.h | 8 ++++---- 2 files changed, 13 insertions(+), 7 deletions(-)