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: 162361 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:aa0b:0:b0:403:3b70:6f57 with SMTP id k11csp124924vqo; Tue, 7 Nov 2023 01:54:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IGo3TK/1erYpr4CeAWM6TIhDynmUKDV7rlsXv/QTEamnsViwQjM5YeYkws81++qovshgToR X-Received: by 2002:a05:6a20:8e08:b0:17b:62af:e63 with SMTP id y8-20020a056a208e0800b0017b62af0e63mr40122465pzj.31.1699350893764; Tue, 07 Nov 2023 01:54:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699350893; cv=none; d=google.com; s=arc-20160816; b=H9dmgwfPgm/x3ahHOCh4aTel03i6dph+vkNSt3hSGpWKXc4qmh2V6iy8v1o/IYmVVj bzl5uWXCLrplAn27y4LUBe4CjdmQss3hwkLSeOL8NvQQxzi9X9M/SvOJDZYIAefd4Rac X/sK6SvVBQnmD6aC7hf+L8pa24OoLSC2u02MZsn9grWZzeHQqY05L7pOhwBHjKthhcr+ ETxvwQ/QMS6jJukfSGmPDjUAZgYF8mpYWlFhFUeH83oVLyMTeQAEK1o6hUirySlFaAMz G8fPOnL4v82WaIbRS2rFtLSxIGIWpZCJXmXSevU7ABiFmDzxQ0V8DbEVl7aJOLyLYbdT DSqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=Rfck5FY3dF9200YZ4tXULFpESCIi8VAAOTwzFmje8Pw=; fh=G3jVr66/sTBxblB4VkyKBP17P5NL/3UjRtmVOzWFD40=; b=xSwAir7aKi9N8i9ltDgoUlF2LLWWLgJlWeumKYonNsaacOgYAeRVKKaY8sqJ5W95Jw mtEjTKQZKayjBq2tu/UAXsUDQsLDaB0S/d3fuhM0LxIYUA1F8zXYxII1BC/t0NZ7whg+ 2+pCW7R0x8rQElIJ6D7G3Jw65AASfGqlqcm4uyLoPSXvSiSb0UKanj2uXf/DJ5pFd3uU /Sczy55lSkIZ5rqMPnu9rNBeH1VAR0cdWGDmTmhW4ILb5pz+Jq+o9H79RYuhW7M3AxE8 t2F7igpkFo/LgWULufW19jMUNbZgJZPezAGY2Bw15zNAT5AVeRVExX2wAlP4BnSncRjt 15rQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jaqEPfOj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id z32-20020a634c20000000b00578a98c0687si1722131pga.99.2023.11.07.01.54.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Nov 2023 01:54:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jaqEPfOj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id BE72E812AD31; Tue, 7 Nov 2023 01:54:52 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234005AbjKGJyv (ORCPT + 33 others); Tue, 7 Nov 2023 04:54:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233856AbjKGJyl (ORCPT ); Tue, 7 Nov 2023 04:54:41 -0500 Received: from mail-lf1-x131.google.com (mail-lf1-x131.google.com [IPv6:2a00:1450:4864:20::131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E42F6125 for ; Tue, 7 Nov 2023 01:54:38 -0800 (PST) Received: by mail-lf1-x131.google.com with SMTP id 2adb3069b0e04-507f1c29f25so7164466e87.1 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=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=Rfck5FY3dF9200YZ4tXULFpESCIi8VAAOTwzFmje8Pw=; b=jaqEPfOjjS8CV42CwprK1l68GnR4JdiOoJohAiH02+nt0IJs/CYUAwD0g/nF8ewjSR WzVDEbobx9Ftxyzqr4x0ruhqu54YWgU9pRfdAtKgDwoRGOp5krhn4dvWok0LdrQKU4uT +A9G+zGOGi1vq0DXOF8njAJyWvEmvBomINwbmRMXkkIcyBg4ZXQJG+BVnrwryuvMFez0 x7kkohxNP7HZ+hMGwa41bs9+Kz4DoJ8Uw7ZTVZyCeIX5TQWfLQ+DiD3ZaDFIwHj2w5Fc udelUm0nWexT3QhiFg+2rbh1CDkSFyVLw0T4ea11v+GSl+3pQVN27DHS4dCYf40AuWNS d65g== 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=TAqAJkNVPlbSFRo526M1LviwrMVuvANbkmKr3r8t1kY3eSd9bxbG4YqNfGGqGqIRef acxZPwRmrf8y+29ECKwfxroKeVDFrtxeuQzs03Qry6m2hwvwAhKjTchaJsBr8qILsDm6 y+FvobgU/1BAKW1D17LG0EmNHfLGEBOMf210IYDM2RhibIqpBdbsj0jm4T2pZxMd/y1G m1yMFyJCY3fFEW/UjSUsAHpGMznFDAG6LOd3aU/sIpmxCExXmjqFYnijmcS1AcgLxzk/ FP22t7W58gm9epFD7vfwvkZC9+BRbWZcFxtYSYHeaEDzH8V5j0oAecQKlpeSjNgsl9+M 4bpQ== X-Gm-Message-State: AOJu0Yxs5DdMTp6pMldRTlXYX+b/hABu85V3QgOaahnBvk5mARtBTpCr VGbUnWIWyjXi7INVo/gTL9fvrA== 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-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 07 Nov 2023 01:54:52 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781898562809279387 X-GMAIL-MSGID: 1781898562809279387 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; }