From patchwork Fri Jun 11 19:05:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 458516 Delivered-To: patch@linaro.org Received: by 2002:a02:735a:0:0:0:0:0 with SMTP id a26csp1211017jae; Fri, 11 Jun 2021 12:07:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz3BL+uQJFEjcxEd/NEtVou5mlFW9BHNYurDSb1XlZ3XaUyWLAtUT2o8yjY6XjEB7l4EYSy X-Received: by 2002:a17:907:10cc:: with SMTP id rv12mr4929615ejb.533.1623438454744; Fri, 11 Jun 2021 12:07:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623438454; cv=none; d=google.com; s=arc-20160816; b=QJZ1KXwG1KsZLxOf49JPRrE/p2rzqnaCj3Evkklmt36GyMndUP5TkTe8oOtO1sH6Ia THi9k48mAEzhNc7Di1tV0nwMK9o+PYFQpX5PrsPbh8mi6ZE6FrZpoEELbNTWREbHpzi+ +lBubTxip2YCcS+S1Jg2OaitLrN6/ELeyruTUkIQtM4HE2LEOmfugfRGPTwfsDYip/Pu sNPaTcphr83pdVXzomkRsScFR3Y1QdagTwdYFPlbwX3DMxPtr5grpeHVGo9Imdf7J88F kBBR9R/BFmdhfdlv06BBHWSXrza8Q8+zm6DXqFo34+8hwAez5HpSwkaswJC1KwxZLKE4 KX6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=1jEKoQqd09IhMCBMusRvi4j4SzZxwB5xBIw8eYKxXpA=; b=dzrJ62vqqfsjvQhMSdXvvdYT0dLm14hHZXxr2Sxjq+BPuo2ExNy+E3KrXf5sjE9/fb 2UlQLWDhx85J82fo0Q/hjOaFgM+7RaGTY4dx0PTWhf94156NiIg9yZOsjh3LxK9yMB8v QevLDixEz1feSI+F2b54A/EV7pKhFG+ysIOX9o63KG2AJyhup14iHtPeqhRFBW5tfKcM K4DgmOHuNbn+9pT3sEE8FUsVnpWbrfnOaqDDz1Qfz9fzn9GTxtJ26LGP2nRLVx4q2ORO ZbdjNLrM0kHl3+qDHZJ2W3PnHzJjz6spbWfQlsVlAkrVzal8J2oTDkUpfLsnsjz1snLZ llcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Oqo3RETa; spf=pass (google.com: domain of netdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=netdev-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b3si5248389edh.532.2021.06.11.12.07.34; Fri, 11 Jun 2021 12:07:34 -0700 (PDT) Received-SPF: pass (google.com: domain of netdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Oqo3RETa; spf=pass (google.com: domain of netdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=netdev-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231672AbhFKTI5 (ORCPT + 8 others); Fri, 11 Jun 2021 15:08:57 -0400 Received: from mail-io1-f43.google.com ([209.85.166.43]:45788 "EHLO mail-io1-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231682AbhFKTIx (ORCPT ); Fri, 11 Jun 2021 15:08:53 -0400 Received: by mail-io1-f43.google.com with SMTP id k5so22469728iow.12 for ; Fri, 11 Jun 2021 12:06:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1jEKoQqd09IhMCBMusRvi4j4SzZxwB5xBIw8eYKxXpA=; b=Oqo3RETafwkfkNGoPxdzW/0nahkdiMknjYHn/ccLC3m3zAyZD7FMZkg7jjr4oC0IA/ H/LtVw0T8+vkE+/DBPhIj3tB7HoNJBVjIMA9vNThbPHix151B9A7erob4v5WbDc/KX3U 3mcFtl/qwDh6KeE9akBvU8Z1DZVFvT/lCSpfohmOru9NOsBnAlagPtQPHxMMQEmlwvIo /mx0X1hAJPbze/yDfGLthjjC2MeSqBFw3zBaw++w4+Z73Q5TvoydnvKuBbogFwvqpQQE nkmFdRiI1iP3jjG69JwvNMD8fx0cqMr99h6SL4A3PngPvEjr+gA4c/wy8RgflweQ37qq Awrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1jEKoQqd09IhMCBMusRvi4j4SzZxwB5xBIw8eYKxXpA=; b=E49qR/I4T+RezUEKCB4HDqz/7vyf9/9i/ptH+/rWMA9zPViSBsymKEp+DY7/qvaQ8j iTvt2vdAkIlgA9nU/cJend2AHxVXuhhGmCO6xnnOHuyj3mjGW18LXUnABQOHUFN0KelE czeVcHx5x5v5HHlHji2IxlRkqrl62WgH8OOo/3ECjOWakOm9DbG6gY3Xx/ktT6xGJ8PL qpg9UQ81HmSKakwXmUkhIJkE4M1/z5K0wTwEyeDdAkg1cHd6PPY6dne5lEwtILaDhSfh tkapAr+4tp+CUGUcHlnv9B5EEd9jCqcThkeDa39BiXqtX1YqmoZCRjQ7dmJ0m1Vcthoa n0dw== X-Gm-Message-State: AOAM531gm5mJAeqAFV2oMPCK/iH+3UrqG8ap2WPPaj9K+ihvwjVWD9YJ fV/QeufyqoBPKaZgq76YlvTVvEf7MexHTIqq X-Received: by 2002:a05:6602:2048:: with SMTP id z8mr4292134iod.91.1623438340111; Fri, 11 Jun 2021 12:05:40 -0700 (PDT) Received: from presto.localdomain (c-73-185-129-58.hsd1.mn.comcast.net. [73.185.129.58]) by smtp.gmail.com with ESMTPSA id p9sm3936566ilc.63.2021.06.11.12.05.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 12:05:39 -0700 (PDT) From: Alex Elder To: subashab@codeaurora.org, stranche@codeaurora.org, davem@davemloft.net, kuba@kernel.org Cc: bjorn.andersson@linaro.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next 6/8] net: qualcomm: rmnet: clarify a bit of code Date: Fri, 11 Jun 2021 14:05:27 -0500 Message-Id: <20210611190529.3085813-7-elder@linaro.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210611190529.3085813-1-elder@linaro.org> References: <20210611190529.3085813-1-elder@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org In rmnet_map_ipv6_dl_csum_trailer() there is an especially involved line of code that determines the ones' complement sum of the IPv6 packet header (in host byte order). Simplify that by storing the result of computing just the header checksum in a local variable, then using that in the original assignment. Use the size of the IPv6 header structure as the number of bytes to checksum, rather than computing the offset to the transport header. And use ip_fast_csum() rather than ipa_compute_csum(), knowing that the size of an IPv6 header (40 bytes) is a multiple of 4 bytes greater than 16. Add some comments to match rmnet_map_ipv4_dl_csum_trailer(). Signed-off-by: Alex Elder --- .../ethernet/qualcomm/rmnet/rmnet_map_data.c | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) -- 2.27.0 diff --git a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c index 40d7e0c615f9c..4f93355e9a93a 100644 --- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c +++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c @@ -120,27 +120,33 @@ rmnet_map_ipv6_dl_csum_trailer(struct sk_buff *skb, struct rmnet_map_dl_csum_trailer *csum_trailer, struct rmnet_priv *priv) { - __sum16 *csum_field, ip6_payload_csum, pseudo_csum, csum_temp; + struct ipv6hdr *ip6h = (struct ipv6hdr *)skb->data; + void *txporthdr = skb->data + sizeof(*ip6h); + __sum16 *csum_field, pseudo_csum, csum_temp; u16 csum_value, csum_value_final; __be16 ip6_hdr_csum, addend; - struct ipv6hdr *ip6h; - void *txporthdr; + __sum16 ip6_payload_csum; + __be16 ip_header_csum; u32 length; - ip6h = (struct ipv6hdr *)(skb->data); - - txporthdr = skb->data + sizeof(struct ipv6hdr); + /* Checksum offload is only supported for UDP and TCP protocols; + * the packet cannot include any IPv6 extension headers + */ csum_field = rmnet_map_get_csum_field(ip6h->nexthdr, txporthdr); - if (!csum_field) { priv->stats.csum_err_invalid_transport++; return -EPROTONOSUPPORT; } + /* The checksum value in the trailer is computed over the entire + * IP packet, including the IP header and payload. To derive the + * transport checksum from this, we first subract the contribution + * of the IP header from the trailer checksum. We then add the + * checksum computed over the pseudo header. + */ csum_value = ~ntohs(csum_trailer->csum_value); - ip6_hdr_csum = (__force __be16) - ~ntohs((__force __be16)ip_compute_csum(ip6h, - (int)(txporthdr - (void *)(skb->data)))); + ip_header_csum = (__force __be16)ip_fast_csum(ip6h, sizeof(*ip6h) / 4); + ip6_hdr_csum = (__force __be16)~ntohs(ip_header_csum); ip6_payload_csum = csum16_sub((__force __sum16)csum_value, ip6_hdr_csum);