From patchwork Fri Dec 22 17:36:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13503579 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-lf1-f53.google.com (mail-lf1-f53.google.com [209.85.167.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CECFF28DDF for ; Fri, 22 Dec 2023 17:36:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="LXcYShDf" Received: by mail-lf1-f53.google.com with SMTP id 2adb3069b0e04-50e44c1b35fso2516984e87.3 for ; Fri, 22 Dec 2023 09:36:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1703266597; x=1703871397; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=1M9nYN3vG6J30yAr/55QkQJHhhME7G4QwBy/DGljMWQ=; b=LXcYShDfCEtiCvDbtZeKYQw7ta0lmI3rZV920r0TxC3ZJNrKczW9wuejRJBXz/6MuH I3z4CzGckxwr9YcpbYAhIUsAlVh8Xw3tHE5tvqyKB8QHbnWbZM9xFwyv5nm8lOX6Y2Tv w224kIJcq/nDZ1+R5TUsELiIDlAcQerbIkkWXPmF4R5eVmxAD1mie+m9NeFDmM1QqpQR aW/TLlhINBlgG/MdxaFpzSnUh0TKB9V8pZvs5+dGbYHWQFQON8yQ0G1wcLtHJsuPYhZE OCMEuhwoM3zznX3jfMtxMrs86d1EW+/MOBfX49XiDTIbBE9ACNI2NTJRQ/poS0HQJ5Fi qLUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703266597; x=1703871397; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1M9nYN3vG6J30yAr/55QkQJHhhME7G4QwBy/DGljMWQ=; b=c4tx0svD5RvoxfeHF2hXaIfFSZxzWDc42nfHMR16S+voqoaZrvdKthgrkfNN0SumeZ 4jsJhJfSloRSG+bao1ExhzLpCrQyudoyYK3HcK91YJUvEDHlcAVLXuxAdDezDVtwagl6 ydaMaVrbLyhvWkZrwL0G8XxFQkmfLXSRjzOQkvZDvTK+3npCSB+iE0rfCWUogrKgZIh5 +00gvnuAE8vDhJKPjxhXeLF8ATPTujbKjKgU7de6igj5oV3vxY2SPtn4t65fWRAY65MZ J9aVObo2IrW3dTSS6NBR4C7DmvufnPDT8f3sR+jq2hIgDuQ7Aq6hU/tahzIuclw+8PMm o20Q== X-Gm-Message-State: AOJu0YzXJ3HbmE99f98SyqyjYJpmKNGBphSxVrYjwVPkRdLT5HUCf/Qw WMoXZtzOUqQZnqMOCJYnspPO7kZSXQ0HjQ== X-Google-Smtp-Source: AGHT+IGgMI6M/QgASNrvCSKO+u0Iq0nP4gu1FT8Vj+b5HFoD2eaUHdyJON09YHe9tjDkmSjnE1kaow== X-Received: by 2002:ac2:5325:0:b0:50e:4316:4a1e with SMTP id f5-20020ac25325000000b0050e43164a1emr854795lfh.15.1703266597648; Fri, 22 Dec 2023 09:36:37 -0800 (PST) Received: from [127.0.1.1] ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id h14-20020a056512220e00b0050e709c8deasm43036lfu.226.2023.12.22.09.36.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Dec 2023 09:36:37 -0800 (PST) From: Linus Walleij Date: Fri, 22 Dec 2023 18:36:35 +0100 Subject: [PATCH net v4 1/3] net: ethernet: cortina: Drop software checksum and TSO Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20231222-new-gemini-ethernet-regression-v4-1-a36e71b0f32b@linaro.org> References: <20231222-new-gemini-ethernet-regression-v4-0-a36e71b0f32b@linaro.org> In-Reply-To: <20231222-new-gemini-ethernet-regression-v4-0-a36e71b0f32b@linaro.org> To: Hans Ulli Kroll , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Vladimir Oltean , Household Cang Cc: netdev@vger.kernel.org, Linus Walleij X-Mailer: b4 0.12.4 X-Patchwork-Delegate: kuba@kernel.org The recent change to allow large frames without hardware checksumming slotted in software checksumming in the driver if hardware could not do it. This will however upset TSO (TCP Segment Offloading). Typical error dumps includes this: skb len=2961 headroom=222 headlen=66 tailroom=0 (...) WARNING: CPU: 0 PID: 956 at net/core/dev.c:3259 skb_warn_bad_offload+0x7c/0x108 gemini-ethernet-port: caps=(0x0000010000154813, 0x00002007ffdd7889) And the packets do not go through. After investigating I drilled it down to the introduction of the software checksumming in the driver. Since the segmenting of packets will be done by the hardware this makes a bit of sense since in that case the hardware also needs to be keeping track of the checksumming. That begs the question why large TCP or UDP packets also have to bypass the checksumming (like e.g. ICMP does). If the hardware is splitting it into smaller packets per-MTU setting, and checksumming them, why is this happening then? I don't know. I know it is needed, from tests: the OpenWrt webserver uhttpd starts sending big skb:s (up to 2047 bytes, the max MTU) and above 1514 bytes it starts to fail and hang unless the bypass bit is set: the frames are not getting through. Drop the size check and the offloading features for now: this needs to be fixed up properly. Suggested-by: Eric Dumazet Fixes: d4d0c5b4d279 ("net: ethernet: cortina: Handle large frames") Signed-off-by: Linus Walleij --- drivers/net/ethernet/cortina/gemini.c | 35 ++++------------------------------- 1 file changed, 4 insertions(+), 31 deletions(-) diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c index 78287cfcbf63..5e399c6e095b 100644 --- a/drivers/net/ethernet/cortina/gemini.c +++ b/drivers/net/ethernet/cortina/gemini.c @@ -79,8 +79,7 @@ MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)"); #define GMAC0_IRQ4_8 (GMAC0_MIB_INT_BIT | GMAC0_RX_OVERRUN_INT_BIT) #define GMAC_OFFLOAD_FEATURES (NETIF_F_SG | NETIF_F_IP_CSUM | \ - NETIF_F_IPV6_CSUM | NETIF_F_RXCSUM | \ - NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6) + NETIF_F_IPV6_CSUM | NETIF_F_RXCSUM) /** * struct gmac_queue_page - page buffer per-page info @@ -1143,39 +1142,13 @@ static int gmac_map_tx_bufs(struct net_device *netdev, struct sk_buff *skb, struct gmac_txdesc *txd; skb_frag_t *skb_frag; dma_addr_t mapping; - unsigned short mtu; void *buffer; - int ret; - - mtu = ETH_HLEN; - mtu += netdev->mtu; - if (skb->protocol == htons(ETH_P_8021Q)) - mtu += VLAN_HLEN; + /* TODO: implement proper TSO using MTU in word3 */ word1 = skb->len; - word3 = SOF_BIT; - - if (word1 > mtu) { - word1 |= TSS_MTU_ENABLE_BIT; - word3 |= mtu; - } + word3 = SOF_BIT | skb->len; - if (skb->len >= ETH_FRAME_LEN) { - /* Hardware offloaded checksumming isn't working on frames - * bigger than 1514 bytes. A hypothesis about this is that the - * checksum buffer is only 1518 bytes, so when the frames get - * bigger they get truncated, or the last few bytes get - * overwritten by the FCS. - * - * Just use software checksumming and bypass on bigger frames. - */ - if (skb->ip_summed == CHECKSUM_PARTIAL) { - ret = skb_checksum_help(skb); - if (ret) - return ret; - } - word1 |= TSS_BYPASS_BIT; - } else if (skb->ip_summed == CHECKSUM_PARTIAL) { + if (skb->ip_summed == CHECKSUM_PARTIAL) { int tcp = 0; /* We do not switch off the checksumming on non TCP/UDP From patchwork Fri Dec 22 17:36:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13503580 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8C77028E16 for ; Fri, 22 Dec 2023 17:36:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="HbkWnUlI" Received: by mail-lf1-f48.google.com with SMTP id 2adb3069b0e04-50e34a72660so2527907e87.1 for ; Fri, 22 Dec 2023 09:36:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1703266598; x=1703871398; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=Fcqx42xGNqv9hptaZ/9+//L/6y4mdXg4n74iEw309cI=; b=HbkWnUlIhEUceDCvh3vC7mZuZEEjLW8+IxsTDlYw494NSofm+RnyXH/Ud9C7qyMGCK Sc2OTtu03s2TDaBHnhJ5xVKnp4mN+JR7QJDqfaNTDafy8fkLRaSzV+YrjhcHWZEesLr3 X+eqkXEqiY2wVnoITEOvGQaG7h5gFXgxLc/DG4uj8JH/DhdTPoXQbqXVUUV6Lw1EtzH4 rtQs2gkxKvDU/tNmNvrNQQQiia3juWNoPB6IPxo1agq8qaqGv1irz30qHxN15bN5Ypvm YdwQqlcw9XsNRjk2xus4CjvE8l5im8vSL+pcqQj/rwE1NtOERNgN9z8S+piK/2fx4wVF SVdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703266598; x=1703871398; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Fcqx42xGNqv9hptaZ/9+//L/6y4mdXg4n74iEw309cI=; b=pyl6456BGpsFjsVG9HajZCPAr9TWaIWB9edCMwFUUQ3S1reEUI8KjD8epkQAY2CYft HsNJxF2UJiB0TyAXjYwa0t0xunIl5Zo4DrsIdgbF0OOSZUpxfP+XMO7wZKwQ+L47Gcxy jQGnRojUmgky4PBK0XywghoO2+O7GSU8BXLOHO2XjvkRzWLoKw2s0cfQ7ESGMCrZHKlO 6+Vn3plhYKnOSVJofKWByIm0RJB+OZH2DP6PGRVyhiwry/I2pgpx7MiUdRCsNtpwqETV Nz2D+2IF0BbeUYoWf7buSUV3/02D2LrSWbJ9JbGwtychcR7bW+nOu3FX6CXuWa6MbqnU aHxA== X-Gm-Message-State: AOJu0Yz0EBO0OfV7f/Qg1pv+k3dSXyy5Y0HKrZLMYAcb1HU2+/yKNCc7 ALjGPoUBQHVAklXzvsnXOr2mEZC4mokJHA== X-Google-Smtp-Source: AGHT+IHOJ0oz9prBCkxKJ2d4uIw4EmXeFnXmXsYkLRDFUqs6SwdYHsY8VEAaa1np20RqNUtrfxTq/Q== X-Received: by 2002:a19:700e:0:b0:50d:179b:b38d with SMTP id h14-20020a19700e000000b0050d179bb38dmr792887lfc.45.1703266598625; Fri, 22 Dec 2023 09:36:38 -0800 (PST) Received: from [127.0.1.1] ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id h14-20020a056512220e00b0050e709c8deasm43036lfu.226.2023.12.22.09.36.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Dec 2023 09:36:38 -0800 (PST) From: Linus Walleij Date: Fri, 22 Dec 2023 18:36:36 +0100 Subject: [PATCH net v4 2/3] if_ether: Add an accessor to read the raw ethertype Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20231222-new-gemini-ethernet-regression-v4-2-a36e71b0f32b@linaro.org> References: <20231222-new-gemini-ethernet-regression-v4-0-a36e71b0f32b@linaro.org> In-Reply-To: <20231222-new-gemini-ethernet-regression-v4-0-a36e71b0f32b@linaro.org> To: Hans Ulli Kroll , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Vladimir Oltean , Household Cang Cc: netdev@vger.kernel.org, Linus Walleij , Maxime Chevallier X-Mailer: b4 0.12.4 X-Patchwork-Delegate: kuba@kernel.org There are circumstances where the skb->protocol can not be trusted, such as when using DSA switches that add a custom ethertype to the ethernet packet, which is later on supposed to be stripped by the switch hardware connected to the conduit ethernet interface. Since ethernet drivers transmitting such frames with alien ethertypes can have hardware that will get confused by custom ethertypes they need a way to retrieve and act on any such type. The new eth_skb_raw_ethertype() helper will extract the ethertype directly from the skb->data using the ethernet and (if necessary) VLAN helper functions, and return the ethertype actually found inside the raw buffer. Suggested-by: Maxime Chevallier Suggested-by: Eric Dumazet Signed-off-by: Linus Walleij --- include/linux/if_ether.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/include/linux/if_ether.h b/include/linux/if_ether.h index 8a9792a6427a..264457f291eb 100644 --- a/include/linux/if_ether.h +++ b/include/linux/if_ether.h @@ -37,6 +37,22 @@ static inline struct ethhdr *inner_eth_hdr(const struct sk_buff *skb) return (struct ethhdr *)skb_inner_mac_header(skb); } +/* This determines the ethertype incoded into the skb data without + * relying on skb->protocol which is not always identical. + */ +static inline __be16 skb_eth_raw_ethertype(struct sk_buff *skb) +{ + struct ethhdr *hdr; + + /* If we can't extract a header, return invalid type */ + if (!pskb_may_pull(skb, ETH_HLEN)) + return 0x0000U; + + hdr = skb_eth_hdr(skb); + + return hdr->h_proto; +} + int eth_header_parse(const struct sk_buff *skb, unsigned char *haddr); extern ssize_t sysfs_format_mac(char *buf, const unsigned char *addr, int len); From patchwork Fri Dec 22 17:36:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13503581 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-lf1-f41.google.com (mail-lf1-f41.google.com [209.85.167.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7E47728E3B for ; Fri, 22 Dec 2023 17:36:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="S4sQesgO" Received: by mail-lf1-f41.google.com with SMTP id 2adb3069b0e04-50e44c1b35fso2517011e87.3 for ; Fri, 22 Dec 2023 09:36:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1703266599; x=1703871399; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=FbEsIRMQk4NPPKjRL9zFJNtECaKyqE/EOexWnszdu60=; b=S4sQesgOYUw/AB/iTZZJYXFQpOpttIt+P7pNjemDsbrE5eKy0EwSHddbwkz0xeXmXL R/zvPaEYA51Fkp4RD6+322y4O2Bc66XL9FSmdnhW2fvHdj3gzWichOHApLCn2AGgu/fb pW1UeCceJwqeZeVw2c7vzM2pXfcQidU79S2acvOYYCuE+xk6U9fG+RL3685Bx7ufeEqY 4xiC8LY2dUB239JC8Zr4tMtOqOvrT1U5JCiIXN1BKAVPybQMUgWRlMwGoad2N1p9gLHz xz2zSB/KYbIhMwYVmlZkIgE5XV1i8BZZiEeiSRUcftfrlCgYpYz4cyAPxOqpjlvf0+Yy UEmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703266599; x=1703871399; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FbEsIRMQk4NPPKjRL9zFJNtECaKyqE/EOexWnszdu60=; b=Easj5Rws8Mr2qdU4jin1fIZGFB0rpJXo9zENFa90P+clCrGJaXJIISvC5mh2j4jjAJ ju1lbaWjVdcDq7idsFfFIBAJOVx2vxULnKJAS/6IRYvARe5p/dSDtWwD1ZTzOT5zTCRx e/6poi25sssu0mstHuXFKz5A6bX7VzanrITaQaHkZbJa5L7rA6pzDHRMqs1dOULP7tCf zawT3dWNeKkIc+/jAVJ5EqEjZtzEbLYwymeM0n0LGYD1E84lwFCfdOqVscw9CXpOkGLQ 3d+Iv186kQmV0ZhltcHJrnmbkEKdP3aALL1XCl2chwH0glClCTab7xqgQLGYZdCPfcLn 3C9g== X-Gm-Message-State: AOJu0YwkPTNLCB3rNcH2TUBgWo7D0tV1iXpQCURyvbwyeQFVVzLJlqfm rWUfDZKde4db8TF7HfT7WoCf912TY3YcoocUWOwqvT4CViE= X-Google-Smtp-Source: AGHT+IEe8HXFB31Kj3ZC/ZARJ16nD3ADWWlNASCZ3odHPGFVGdQWL3/JhVRwApg43qVZEg3gSpwmig== X-Received: by 2002:ac2:547c:0:b0:50e:54aa:750d with SMTP id e28-20020ac2547c000000b0050e54aa750dmr844404lfn.85.1703266599561; Fri, 22 Dec 2023 09:36:39 -0800 (PST) Received: from [127.0.1.1] ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id h14-20020a056512220e00b0050e709c8deasm43036lfu.226.2023.12.22.09.36.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Dec 2023 09:36:39 -0800 (PST) From: Linus Walleij Date: Fri, 22 Dec 2023 18:36:37 +0100 Subject: [PATCH net v4 3/3] net: ethernet: cortina: Bypass checksumming engine of alien ethertypes Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20231222-new-gemini-ethernet-regression-v4-3-a36e71b0f32b@linaro.org> References: <20231222-new-gemini-ethernet-regression-v4-0-a36e71b0f32b@linaro.org> In-Reply-To: <20231222-new-gemini-ethernet-regression-v4-0-a36e71b0f32b@linaro.org> To: Hans Ulli Kroll , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Vladimir Oltean , Household Cang Cc: netdev@vger.kernel.org, Linus Walleij X-Mailer: b4 0.12.4 X-Patchwork-Delegate: kuba@kernel.org We had workarounds were the ethernet checksumming engine would be bypassed for larger frames, this fixed devices using DSA, but regressed devices where the ethernet was connected directly to a PHY. The devices with a PHY connected directly can't handle large frames either way, with or without bypass. Looking at the size of the frame is probably just wrong. Rework the workaround such that we don't activate the checksumming engine if the ethertype inside the actual frame is something else than 0x0800 (IPv4) or 0x86dd (IPv6). These are the only frames the checksumming engine can actually handle. VLAN framing (0x8100) also works fine. We can't inspect skb->protocol because DSA frames will sometimes have a custom ethertype despite skb->protocol is e.g. 0x0800. If the frame is ALSO over the size of an ordinary ethernet frame, we will actively bypass the checksumming engine. (Always doing this makes the hardware unstable.) After this both devices with direct ethernet attached such as D-Link DNS-313 and devices with a DSA switch with a custom ethertype such as D-Link DIR-685 work fine. Fixes: d4d0c5b4d279 ("net: ethernet: cortina: Handle large frames") Signed-off-by: Linus Walleij --- drivers/net/ethernet/cortina/gemini.c | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c index 5e399c6e095b..db828e4f258f 100644 --- a/drivers/net/ethernet/cortina/gemini.c +++ b/drivers/net/ethernet/cortina/gemini.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -1142,22 +1143,38 @@ static int gmac_map_tx_bufs(struct net_device *netdev, struct sk_buff *skb, struct gmac_txdesc *txd; skb_frag_t *skb_frag; dma_addr_t mapping; + u16 ethertype; void *buffer; /* TODO: implement proper TSO using MTU in word3 */ word1 = skb->len; word3 = SOF_BIT | skb->len; - if (skb->ip_summed == CHECKSUM_PARTIAL) { + /* Dig out the the ethertype actually in the buffer and not what the + * protocol claims to be. This is the raw data that the checksumming + * offload engine will have to deal with. + */ + ethertype = ntohs(skb_eth_raw_ethertype(skb)); + /* This is the only VLAN type supported by this hardware so check for + * that: the checksumming engine can handle IP and IPv6 inside 802.1Q. + */ + if (ethertype == ETH_P_8021Q) + ethertype = ntohs(__vlan_get_protocol(skb, htons(ethertype), NULL)); + + if (ethertype != ETH_P_IP && ethertype != ETH_P_IPV6) { + /* Hardware offloaded checksumming isn't working on non-IP frames. + * This happens for example on some DSA switches using a custom + * ethertype. When a frame gets bigger than a standard ethernet + * frame, it also needs to actively bypass the checksumming engine. + * There is no clear explanation to why it is like this, the + * reference manual has left the TSS completely undocumented. + */ + if (skb->len > ETH_FRAME_LEN) + word1 |= TSS_BYPASS_BIT; + } else if (skb->ip_summed == CHECKSUM_PARTIAL) { int tcp = 0; - /* We do not switch off the checksumming on non TCP/UDP - * frames: as is shown from tests, the checksumming engine - * is smart enough to see that a frame is not actually TCP - * or UDP and then just pass it through without any changes - * to the frame. - */ - if (skb->protocol == htons(ETH_P_IP)) { + if (ethertype == ETH_P_IP) { word1 |= TSS_IP_CHKSUM_BIT; tcp = ip_hdr(skb)->protocol == IPPROTO_TCP; } else { /* IPv6 */