Skip to content

Commit d4d0c5b

Browse files
Linus Walleijkuba-moo
authored andcommitted
net: ethernet: cortina: Handle large frames
The Gemini ethernet controller provides hardware checksumming for frames up to 1514 bytes including ethernet headers but not FCS. If we start sending bigger frames (after first bumping up the MTU on both interfaces sending and receiving the frames), truncated packets start to appear on the target such as in this tcpdump resulting from ping -s 1474: 23:34:17.241983 14:d6:4d:a8:3c:4f (oui Unknown) > bc:ae:c5:6b:a8:3d (oui Unknown), ethertype IPv4 (0x0800), length 1514: truncated-ip - 2 bytes missing! (tos 0x0, ttl 64, id 32653, offset 0, flags [DF], proto ICMP (1), length 1502) OpenWrt.lan > Fecusia: ICMP echo request, id 1672, seq 50, length 1482 If we bypass the hardware checksumming and provide a software fallback, everything starts working fine up to the max TX MTU of 2047 bytes, for example ping -s2000 192.168.1.2: 00:44:29.587598 bc:ae:c5:6b:a8:3d (oui Unknown) > 14:d6:4d:a8:3c:4f (oui Unknown), ethertype IPv4 (0x0800), length 2042: (tos 0x0, ttl 64, id 51828, offset 0, flags [none], proto ICMP (1), length 2028) Fecusia > OpenWrt.lan: ICMP echo reply, id 1683, seq 4, length 2008 The bit enabling to bypass hardware checksum (or any of the "TSS" bits) are undocumented in the hardware reference manual. The entire hardware checksum unit appears undocumented. The conclusion that we need to use the "bypass" bit was found by trial-and-error. Since no hardware checksum will happen, we slot in a software checksum fallback. Check for the condition where we need to compute checksum on the skb with either hardware or software using == CHECKSUM_PARTIAL instead of != CHECKSUM_NONE which is an incomplete check according to <linux/skbuff.h>. On the D-Link DIR-685 router this fixes a bug on the conduit interface to the RTL8366RB DSA switch: as the switch needs to add space for its tag it increases the MTU on the conduit interface to 1504 and that means that when the router sends packages of 1500 bytes these get an extra 4 bytes of DSA tag and the transfer fails because of the erroneous hardware checksumming, affecting such basic functionality as the LuCI web interface. Fixes: 4d5ae32 ("net: ethernet: Add a driver for Gemini gigabit ethernet") Signed-off-by: Linus Walleij <linus.walleij@linaro.org> Reviewed-by: Vladimir Oltean <olteanv@gmail.com> Link: https://lore.kernel.org/r/20231109-gemini-largeframe-fix-v4-2-6e611528db08@linaro.org Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 510e35f commit d4d0c5b

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

drivers/net/ethernet/cortina/gemini.c

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1145,6 +1145,7 @@ static int gmac_map_tx_bufs(struct net_device *netdev, struct sk_buff *skb,
11451145
dma_addr_t mapping;
11461146
unsigned short mtu;
11471147
void *buffer;
1148+
int ret;
11481149

11491150
mtu = ETH_HLEN;
11501151
mtu += netdev->mtu;
@@ -1159,9 +1160,30 @@ static int gmac_map_tx_bufs(struct net_device *netdev, struct sk_buff *skb,
11591160
word3 |= mtu;
11601161
}
11611162

1162-
if (skb->ip_summed != CHECKSUM_NONE) {
1163+
if (skb->len >= ETH_FRAME_LEN) {
1164+
/* Hardware offloaded checksumming isn't working on frames
1165+
* bigger than 1514 bytes. A hypothesis about this is that the
1166+
* checksum buffer is only 1518 bytes, so when the frames get
1167+
* bigger they get truncated, or the last few bytes get
1168+
* overwritten by the FCS.
1169+
*
1170+
* Just use software checksumming and bypass on bigger frames.
1171+
*/
1172+
if (skb->ip_summed == CHECKSUM_PARTIAL) {
1173+
ret = skb_checksum_help(skb);
1174+
if (ret)
1175+
return ret;
1176+
}
1177+
word1 |= TSS_BYPASS_BIT;
1178+
} else if (skb->ip_summed == CHECKSUM_PARTIAL) {
11631179
int tcp = 0;
11641180

1181+
/* We do not switch off the checksumming on non TCP/UDP
1182+
* frames: as is shown from tests, the checksumming engine
1183+
* is smart enough to see that a frame is not actually TCP
1184+
* or UDP and then just pass it through without any changes
1185+
* to the frame.
1186+
*/
11651187
if (skb->protocol == htons(ETH_P_IP)) {
11661188
word1 |= TSS_IP_CHKSUM_BIT;
11671189
tcp = ip_hdr(skb)->protocol == IPPROTO_TCP;

0 commit comments

Comments
 (0)