From patchwork Tue Nov 7 09:54:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13448243 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5A9FCC4167D for ; Tue, 7 Nov 2023 09:55:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ArqUBPKh5arH27fi3VggO3iQsU68/UHM5F1hJvffjhk=; b=XDJtFnLQfSoiVC 5f81vzqNqdG6yiMAzejlSXmF48nF2OuHIxahl8w3OhqAWT2BEZCDhgJCG/QKim+Hbaz4xMBUJkd7l XedElTybY3EuEiS0EP3CuVESfOinSRXnsqMlmC20sa9SWayJ5UDG8CPaHhrCXR4spqDD3/E+odWOR gcygHL8JdyGU2QxjU3QWhIG0S5mrfQ+RyUlXRk/ThOOUZ7gM/R3z3s9YuKe2HWW+j7o4Y4PbnWGBy xe0sdNgYzyG1NB0XUqeb2tOCnQ4x3YX0bYvt1ULYtHGMTicyMQm07FVGkgooB4Zo7bajuAW7D8Ctr KpUllRlje/iG0r4ir1Ag==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r0InB-000yAs-3A; Tue, 07 Nov 2023 09:54:41 +0000 Received: from mail-lf1-x130.google.com ([2a00:1450:4864:20::130]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1r0In8-000y8U-2V for linux-arm-kernel@lists.infradead.org; Tue, 07 Nov 2023 09:54:40 +0000 Received: by mail-lf1-x130.google.com with SMTP id 2adb3069b0e04-50797cf5b69so7151209e87.2 for ; Tue, 07 Nov 2023 01:54:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699350877; x=1699955677; darn=lists.infradead.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=Rfck5FY3dF9200YZ4tXULFpESCIi8VAAOTwzFmje8Pw=; b=MGhHfp4wUNgbUfxDQ7n4YUAyst7G6mn5yHr1XJmexDZAVpldG7wq1UXjeNKlPktjQJ F1JEwE1Lu+IlOUc65bpJVSyu5vfZd6cBc6MMtuFskn5lmwt2MogSztIR6AazwHMSWu4m TykhJHsDNhVVvhadVynQy3rLLGQ4h49YivksVO4Klf0pOjDHg8198tcUhYm22u2t01Tm AwhzoedG61258w+HK9fgw/R1CFm0rZi42bU7l38Dtxyt7DqRd0j6L/ZuxA/LzngyotUy 3k9MtlydY3kOLgtu1V2sdnFp3Yr5QW5J3AKutmSiRsb6dH9YEJS2673F9CVesYfp1zBT meYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699350877; x=1699955677; 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=Rfck5FY3dF9200YZ4tXULFpESCIi8VAAOTwzFmje8Pw=; b=IsIqsyKReVQMOLvW1BW1O5pBR7gg3NnM9A0h01nF/VckVKmCnWe2//Wr0G+h7YZn+m G4EPK+yE3mIIYAhLGPieC8CAexHeavXhFnqdxFLdzZ8qsYjwso1eHTYGibOX5TXPlu7E UFMISnW+i0h+RDbN/sLqb+DJnd6DIXGIZvcfcBZfKYxmt1PZIJbw/kPRdPhQf4d9cZRf UM4MXzG6vmQy+wDpYi/z1S4D2nOrxL7BemHsT4mFx7dHXehpT0SCaAbaqk1/LL+oTd4e AAC2YaGajv5PL6uQTLp3foVOnMisnUK74JBszpmmmWO26zPxqhTDDZJTYRwDzGpT6PH7 pnJw== X-Gm-Message-State: AOJu0YxZLxg2sblMQ1vBbczUrpxBObj2PguFhLMdseWIpe/yPbu8QbDw BH0OO6VJZsbQ0FxAmbo1swtbitUp1NaprFq2XSQ= X-Google-Smtp-Source: AGHT+IEBVvk5s+3+jjuHHDZToklheab9cKewXJF+TOy2czkLFGo94g0k21Br2Tt8rSSzF8K3JABtuQ== X-Received: by 2002:a05:6512:ad5:b0:501:bd43:3b9c with SMTP id n21-20020a0565120ad500b00501bd433b9cmr29893465lfu.23.1699350877142; Tue, 07 Nov 2023 01:54:37 -0800 (PST) Received: from [127.0.1.1] ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id m25-20020ac24ad9000000b005091314185asm296356lfp.285.2023.11.07.01.54.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Nov 2023 01:54:36 -0800 (PST) From: Linus Walleij Date: Tue, 07 Nov 2023 10:54:29 +0100 Subject: [PATCH net v3 4/4] net: ethernet: cortina: Checksum only TCP and UDP MIME-Version: 1.0 Message-Id: <20231107-gemini-largeframe-fix-v3-4-e3803c080b75@linaro.org> References: <20231107-gemini-largeframe-fix-v3-0-e3803c080b75@linaro.org> In-Reply-To: <20231107-gemini-largeframe-fix-v3-0-e3803c080b75@linaro.org> To: Hans Ulli Kroll , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= , Vladimir Oltean , Andrew Lunn Cc: linux-arm-kernel@lists.infradead.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Linus Walleij X-Mailer: b4 0.12.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231107_015438_818281_B58134CF X-CRM114-Status: GOOD ( 18.63 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org It is a bit odd that frames that are neither TCP or UDP (such as ICMP or ARP) are still sent to the checksumming engine, where they are clearly just ignored. Rewrite the logic slightly so that we first check if the frame is TCP or UDP, in that case bypass the checksum engine. Reported-by: Vladimir Oltean Signed-off-by: Linus Walleij --- drivers/net/ethernet/cortina/gemini.c | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c index 78287cfcbf63..1bf07505653b 100644 --- a/drivers/net/ethernet/cortina/gemini.c +++ b/drivers/net/ethernet/cortina/gemini.c @@ -1144,6 +1144,7 @@ static int gmac_map_tx_bufs(struct net_device *netdev, struct sk_buff *skb, skb_frag_t *skb_frag; dma_addr_t mapping; unsigned short mtu; + bool tcp, udp; void *buffer; int ret; @@ -1160,7 +1161,18 @@ static int gmac_map_tx_bufs(struct net_device *netdev, struct sk_buff *skb, word3 |= mtu; } - if (skb->len >= ETH_FRAME_LEN) { + /* Check if the protocol is TCP or UDP */ + tcp = false; + udp = false; + if (skb->protocol == htons(ETH_P_IP)) { + tcp = ip_hdr(skb)->protocol == IPPROTO_TCP; + udp = ip_hdr(skb)->protocol == IPPROTO_UDP; + } else { /* IPv6 */ + tcp = ipv6_hdr(skb)->nexthdr == IPPROTO_TCP; + udp = ipv6_hdr(skb)->nexthdr == IPPROTO_UDP; + } + + if (skb->len >= ETH_FRAME_LEN || (!tcp && !udp)) { /* 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 @@ -1168,6 +1180,9 @@ static int gmac_map_tx_bufs(struct net_device *netdev, struct sk_buff *skb, * overwritten by the FCS. * * Just use software checksumming and bypass on bigger frames. + * + * Bypass the checksumming engine for any protocols that are + * not TCP or UDP. */ if (skb->ip_summed == CHECKSUM_PARTIAL) { ret = skb_checksum_help(skb); @@ -1176,22 +1191,14 @@ static int gmac_map_tx_bufs(struct net_device *netdev, struct sk_buff *skb, } 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 we get here we are dealing with a TCP or UDP frame + * which is small enough to be processed by the checkumming + * engine. */ - if (skb->protocol == htons(ETH_P_IP)) { + if (skb->protocol == htons(ETH_P_IP)) word1 |= TSS_IP_CHKSUM_BIT; - tcp = ip_hdr(skb)->protocol == IPPROTO_TCP; - } else { /* IPv6 */ + else word1 |= TSS_IPV6_ENABLE_BIT; - tcp = ipv6_hdr(skb)->nexthdr == IPPROTO_TCP; - } - word1 |= tcp ? TSS_TCP_CHKSUM_BIT : TSS_UDP_CHKSUM_BIT; }