From patchwork Tue Mar 9 12:48:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 395964 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp2554704jai; Tue, 9 Mar 2021 04:49:38 -0800 (PST) X-Google-Smtp-Source: ABdhPJzUF/zcAs9M1GakFXzxmDnJBVYDLT4J52kOTvTvR+PHwwOlKqulFg9BNdJcmx1of2uMos+Q X-Received: by 2002:a17:906:4150:: with SMTP id l16mr20529557ejk.90.1615294177912; Tue, 09 Mar 2021 04:49:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615294177; cv=none; d=google.com; s=arc-20160816; b=xXmBhAn5fL2GPxxfrMyr47FqxXU1roGZpNcqGSHpSUgOQ0AYCbjdtNoWi0d/rOz+89 Elba8XeX7dVi/eeeqmYSbFAUv6beT1p6Crj47BNcC2f4VSCpIu5wJXzPSRRWh7S+xRkm fqTiVYGaVHKr1r5dPGazVQjj/R5hSshjGW90xCip5nH6YQ2dmULq2zsrEi0Tn44kSCSg q9+NhRT/ztgFl85Iee80yHPIdtJQEiq7X9Yf9zxyE18cZOa/AZPetMGvHsPYCyVm7Fw0 Us/vrNrZuVLEz/XSRd21EyewVFGnec60id6DTejMPiEjDVuotAqnhrCVNs0Mx+mQ4GND ykaA== 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=siv8ALjvw5nAWM5oVnlAOXA/08MIyz7olXglWGx22ko=; b=qefR8n1Ka5DlIYAObIdM1eP96KNfgWTeCaZsmBs+RxlImr26mCUYuYtVFsl88070/x NPrG5mFgvqk1RHUfAB8srqKPs3OpqPx52t5oxYz9P+d1qngNJloUnCuZ2R9GV6yY4rJ4 0opY9plIPMwAR7DdZLPkF+LDKEyy5lw3UeWxq/hVhiDOxknRGW7kW2NQ4nzQubpmmST7 nlyWe4GkazVOFHZ6T4NbO2yF+76LByR+uRHC63It042OQpesq0no/WdMtgut6pooZmM/ qzTaZvyexyU/O8rBF36V3CabaBSMb5n95Vy55oXmS+1DMPUQOartxJNI7jjI5876YGhA 9hqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kC8B6lj3; 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 la8si9302850ejc.79.2021.03.09.04.49.37; Tue, 09 Mar 2021 04:49:37 -0800 (PST) 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=kC8B6lj3; 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 S231189AbhCIMs5 (ORCPT + 9 others); Tue, 9 Mar 2021 07:48:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36532 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230328AbhCIMsx (ORCPT ); Tue, 9 Mar 2021 07:48:53 -0500 Received: from mail-il1-x130.google.com (mail-il1-x130.google.com [IPv6:2607:f8b0:4864:20::130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 36FE6C06174A for ; Tue, 9 Mar 2021 04:48:53 -0800 (PST) Received: by mail-il1-x130.google.com with SMTP id e7so12032684ile.7 for ; Tue, 09 Mar 2021 04:48:53 -0800 (PST) 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=siv8ALjvw5nAWM5oVnlAOXA/08MIyz7olXglWGx22ko=; b=kC8B6lj3o08cGovB26B9exuiv8S3XJQVO38EPn3FDus4bdyX3gY/cpxyOvP9AGOnQJ EOqtN4cC89OHDSOhSIngjvJaTAAb7HOHeTRHyHflrsyKx0da1IG10suDL0pm6F7O6P9F 2Q1DEbVLKMyzisqhb1hrgCyapRNo6i6QVFujXO5ZPMFOWX3s/3qFOJ96egzJawHvTrDL 7iJpjDASzw2TAMEbSbE7yOFlC9bwvHB/xU0tc1RhQUqPckHG5lQYVFvhSfJRSs+sOqX+ pgWZH6uVPQNqKxqgwoUZ9MV6q/tAaa0p5+xfgJWnUzR8Y/6ZbEWzYyCY5xYFxY+VYybZ n9Bw== 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=siv8ALjvw5nAWM5oVnlAOXA/08MIyz7olXglWGx22ko=; b=dpuP71a3ebUw/DL0J5IhWp9ofRSK1KULDr7HMzi4fPyVST4ZgHCJ7IgbvQihR0//tv u8YdDFxE+XWW8L8ASBsRQuCMo8kXyE03VbfYkzZnhyR2v6cwXpasR/vR4CwsQqk5Ih1L br8rTI9qqYT+Y1NtbW1ZFEjJVml1ETDF4fbOupqi6zTPqYCGaOPHCZu8GAUV7bMn4Kve lixKMhWoJkCuMGmRDkmNJkkGKA/49uIfQa9/k1gLMHal9lxevKan1Ebu4LoIREr10uBJ GHNjzJ4tarxyTLoGZBg+BrkfdYSZHA6nNOKfp2NDFhaQA9sp+pio25nU+CSVbsbUcF3K 3xfA== X-Gm-Message-State: AOAM5312nVLOCB/UArwcWrZwyEcyd3PP9nEdLxNDGTQLBetAJ0mrXLaS pFqy7Bp1IsiVU48srv00ETZHBw== X-Received: by 2002:a05:6e02:1544:: with SMTP id j4mr23743257ilu.67.1615294132685; Tue, 09 Mar 2021 04:48:52 -0800 (PST) Received: from presto.localdomain (c-73-185-129-58.hsd1.mn.comcast.net. [73.185.129.58]) by smtp.gmail.com with ESMTPSA id o23sm7810009ioo.24.2021.03.09.04.48.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Mar 2021 04:48:52 -0800 (PST) From: Alex Elder To: subashab@codeaurora.org, stranche@codeaurora.org, davem@davemloft.net, kuba@kernel.org Cc: sharathv@codeaurora.org, bjorn.andersson@linaro.org, evgreen@chromium.org, cpratapa@codeaurora.org, David.Laight@ACULAB.COM, elder@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v3 1/6] net: qualcomm: rmnet: mark trailer field endianness Date: Tue, 9 Mar 2021 06:48:43 -0600 Message-Id: <20210309124848.238327-2-elder@linaro.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210309124848.238327-1-elder@linaro.org> References: <20210309124848.238327-1-elder@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org The fields in the checksum trailer structure used for QMAP protocol RX packets are all big-endian format, so define them that way. It turns out these fields are never actually used by the RMNet code. The start offset is always assumed to be zero, and the length is taken from the other packet headers. So making these fields explicitly big endian has no effect on the behavior of the code. Signed-off-by: Alex Elder Reviewed-by: Bjorn Andersson --- include/linux/if_rmnet.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) -- 2.27.0 diff --git a/include/linux/if_rmnet.h b/include/linux/if_rmnet.h index 9661416a9bb47..8c7845baf3837 100644 --- a/include/linux/if_rmnet.h +++ b/include/linux/if_rmnet.h @@ -32,8 +32,8 @@ struct rmnet_map_dl_csum_trailer { #else #error "Please fix " #endif - u16 csum_start_offset; - u16 csum_length; + __be16 csum_start_offset; + __be16 csum_length; __be16 csum_value; } __aligned(1); From patchwork Tue Mar 9 12:48:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 395962 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp2554639jai; Tue, 9 Mar 2021 04:49:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJxDzsE4Ix0ynOHE8kcnUFogyi/Ps5ARGk4X3/5IsjZ32yLge6VNEDZ+cw1Jec5KJW3eNR10 X-Received: by 2002:a17:907:20e4:: with SMTP id rh4mr20603144ejb.369.1615294171348; Tue, 09 Mar 2021 04:49:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615294171; cv=none; d=google.com; s=arc-20160816; b=THM9s3T3ILrlSrSMTqG7hDvGqc4E9Uwj/22+qa/d68N51wujE3d2Dul42tFC0c+Tc5 oj81puK3JxCuG7psORA/zwuMdLr2Mw5wI1vEVUpwdKQvli6Cru3jJbR9WfLXcY5ViV68 Xiasjew3SC3GIQqgfiMsT1vp3ghUG0AlHqVvRq9L3vlCbjWK5QFK8LNsZhDYAF4mT1n8 oBe73PcaOfEE9Hejof1rfW1yWrIyXDVz5XJBUQMxxTKs7+T2o6b2dus113YBs7gJgShh yt+29i1i339I7zgrvvL+isX1/E1KUCTd/kqDj+cruAYUUYWflzSZLRXcMPvOCMYXSuNZ MQDA== 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=cYtxP12FPoFyXStxU+dIm5i6FSzaCM643MO9iKA6Wx4=; b=s+1diVuSpWZfPFKqOCrhYND2PzBT0tWH4FKY47mVjeXKbwU0tUaC34SMOOjkWi9EhO S9f//oDVaI5px2Estt0EWrqKNtjC2ak93n5BGpwmIW5QZJYPBnTpwZWlKkmHaKmymuY4 zphn6bL3eGCoDm/SUzjhC92fzO2NeBHyOaIsY6YP9EiC/cgllAtSxMe8E1VZ6yRpTU6h mEvfjDKkx8801hX5lA6yXiQtNycEICW9unjIISecb+BG+c2uDeLxZi2j8a7Lkb4ri+U2 j+6jqh7H6pBo34+19iOupx+qjaQT9U6JOyWffNLXwqBI1BCNtBRwQIi0zEydcxNxygzc QBUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Zq87I4II; 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 la8si9302850ejc.79.2021.03.09.04.49.31; Tue, 09 Mar 2021 04:49:31 -0800 (PST) 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=Zq87I4II; 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 S231224AbhCIMs5 (ORCPT + 9 others); Tue, 9 Mar 2021 07:48:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36538 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230503AbhCIMsy (ORCPT ); Tue, 9 Mar 2021 07:48:54 -0500 Received: from mail-il1-x130.google.com (mail-il1-x130.google.com [IPv6:2607:f8b0:4864:20::130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 22C91C06175F for ; Tue, 9 Mar 2021 04:48:54 -0800 (PST) Received: by mail-il1-x130.google.com with SMTP id e2so12087526ilu.0 for ; Tue, 09 Mar 2021 04:48:54 -0800 (PST) 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=cYtxP12FPoFyXStxU+dIm5i6FSzaCM643MO9iKA6Wx4=; b=Zq87I4II0E01k+QPxUIYPCaiDnxXPJaS2UlN4RnGSqSK26aJ66HiWv+g8NtnZWYcVm tE7gneLkRAAJou61yaRGLIB9zbWw3yS8Fa/EeheX3VexPuxW8nYijGC9V+r+cKQvdj6g 9dH5Wqu5L/RA6zSmoPS1rk6WngRb+uSsw+Ttdfe0a2P00Kjv3zNO+PffFdjtkFuCsuvq SA2fGqHtJYQIa9fEt96I5RwtHx9gpgYKDDgnhl/vcJZDRL6DVkJZknB3viWMYlkJtuJC 0C76ENVaOUI0+6ROGoAd6eRmxcNBzW9km+a24MBwYqVpBvLjrqtoqZN2SMmdcURs8gdx z2aA== 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=cYtxP12FPoFyXStxU+dIm5i6FSzaCM643MO9iKA6Wx4=; b=qXVh3hbKlrhfn09w7husHdQJkM0C2Bf6Ix6csHLKqYmguJZkbN4zGb5i7svbg/v+CG uqueD657Yyo009amIx8OoDxWAJ+hNMwPm5tQ9dzUzso7SlgOszMH4qVwzzcktopTvQCU o2eJkNb9LGwJzP+11OXIAAVk8qoJDp6AJOkkbLjT/gRg6H1JcvAUgefhN8+D4qMoeWCx /vu+Y6OAUXCYs64Jl3n+gQVmfc4ct6vHLUVSZ/8TXPzDqoVPwbYv7Xy75j0YfhSB3ISl 5HKMHCbhIL98y3HqWGyKmiyhfNmKiuCVuAlz4gZGJM51xX3Q3gwLRMa9fxop7svBakwp NApQ== X-Gm-Message-State: AOAM532At9qGihGBVemTsEJS2G1dz5PpNDMgTiqsy4Bve1gcZt/rzNO8 0ucHhe5k3atZvjSy/gvkJiMo4w== X-Received: by 2002:a92:c26f:: with SMTP id h15mr23293678ild.65.1615294133638; Tue, 09 Mar 2021 04:48:53 -0800 (PST) Received: from presto.localdomain (c-73-185-129-58.hsd1.mn.comcast.net. [73.185.129.58]) by smtp.gmail.com with ESMTPSA id o23sm7810009ioo.24.2021.03.09.04.48.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Mar 2021 04:48:53 -0800 (PST) From: Alex Elder To: subashab@codeaurora.org, stranche@codeaurora.org, davem@davemloft.net, kuba@kernel.org Cc: sharathv@codeaurora.org, bjorn.andersson@linaro.org, evgreen@chromium.org, cpratapa@codeaurora.org, David.Laight@ACULAB.COM, elder@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v3 2/6] net: qualcomm: rmnet: simplify some byte order logic Date: Tue, 9 Mar 2021 06:48:44 -0600 Message-Id: <20210309124848.238327-3-elder@linaro.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210309124848.238327-1-elder@linaro.org> References: <20210309124848.238327-1-elder@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org In rmnet_map_ipv4_ul_csum_header() and rmnet_map_ipv6_ul_csum_header() the offset within a packet at which checksumming should commence is calculated. This calculation involves byte swapping and a forced type conversion that makes it hard to understand. Simplify this by computing the offset in host byte order, then converting the result when assigning it into the header field. Signed-off-by: Alex Elder Reviewed-by: Bjorn Andersson --- .../ethernet/qualcomm/rmnet/rmnet_map_data.c | 22 ++++++++++--------- 1 file changed, 12 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 21d38167f9618..bd1aa11c9ce59 100644 --- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c +++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c @@ -197,12 +197,13 @@ rmnet_map_ipv4_ul_csum_header(void *iphdr, struct rmnet_map_ul_csum_header *ul_header, struct sk_buff *skb) { - struct iphdr *ip4h = (struct iphdr *)iphdr; - __be16 *hdr = (__be16 *)ul_header, offset; + __be16 *hdr = (__be16 *)ul_header; + struct iphdr *ip4h = iphdr; + u16 offset; + + offset = skb_transport_header(skb) - (unsigned char *)iphdr; + ul_header->csum_start_offset = htons(offset); - offset = htons((__force u16)(skb_transport_header(skb) - - (unsigned char *)iphdr)); - ul_header->csum_start_offset = offset; ul_header->csum_insert_offset = skb->csum_offset; ul_header->csum_enabled = 1; if (ip4h->protocol == IPPROTO_UDP) @@ -239,12 +240,13 @@ rmnet_map_ipv6_ul_csum_header(void *ip6hdr, struct rmnet_map_ul_csum_header *ul_header, struct sk_buff *skb) { - struct ipv6hdr *ip6h = (struct ipv6hdr *)ip6hdr; - __be16 *hdr = (__be16 *)ul_header, offset; + __be16 *hdr = (__be16 *)ul_header; + struct ipv6hdr *ip6h = ip6hdr; + u16 offset; + + offset = skb_transport_header(skb) - (unsigned char *)ip6hdr; + ul_header->csum_start_offset = htons(offset); - offset = htons((__force u16)(skb_transport_header(skb) - - (unsigned char *)ip6hdr)); - ul_header->csum_start_offset = offset; ul_header->csum_insert_offset = skb->csum_offset; ul_header->csum_enabled = 1; From patchwork Tue Mar 9 12:48:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 395963 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp2554658jai; Tue, 9 Mar 2021 04:49:32 -0800 (PST) X-Google-Smtp-Source: ABdhPJyp/c/5kJrGBINb3JTCALe2NAfdQS0v9YE5FGpeGurz2zhGOrvusQCZlo/zcbWqylBEhE0T X-Received: by 2002:a17:906:660b:: with SMTP id b11mr21250666ejp.458.1615294172818; Tue, 09 Mar 2021 04:49:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615294172; cv=none; d=google.com; s=arc-20160816; b=mYgj8+tjFteak+aCi49News289veJ/LL60Jt8flLKRGd+VunWH8rQqfI4cenEyaKQh kYq2hH6BxFr6Atx1GS3iotMwBepB0l22EZX4Yniv5IULpESccYWcwxqFS13FP7F/i7XW fYiYw1fqLWiwY7tJM2gNGipWE2JKKlA75bmv6QwrXnDEcaA2ggl57W9Kd/HiUpY4Qddf ukszAlyxHOXh+Qa4EsFwa/NKys3FjZJ72ewbDBSRE9GfGbtZAYM12cZTr7cyjts4zs0X d8dXJJPVNTLyOMoMJnz5Nsv4CTk8gx4aPi707KOWtt8Mhpd3X9gpoSuZjwWw+54AaPvv M0Kg== 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=3pf3F65RZucsIMXc3J9HNUjACeQQX3TS4fzpwXGEtjU=; b=LbTv/uFG072u50hxgPzxZ7H07j+OSR1DLaVCC0tC/wiWh29Vjm4zAQ0ApoduC3fGob GCumk4bwRrMkwD/dZ9i/jScBiGbx3+rz7pRXyQxbLNpMbI2qsLS2gEphMykhFoOCnCtD SYKeS+0CErDhslwAvNpIjkHaWF9GMM6ep6bva4wx3vdwl3pzmdJIej25tNQK7eNGEPAy co9XnNQGFjphP6ERdBbxZNxGNfM6O6EbwhNeYs9tgtYBKGyWeCEpIEvUjrVbAql2bQQV /erNS1RiKvdVwrEe5u6F63lAIEEKsIGOn8KrZ5Z4GtztFAVq0fqtyC756ao+hPTR1mYz ahRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=iS8IOxUx; 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 la8si9302850ejc.79.2021.03.09.04.49.32; Tue, 09 Mar 2021 04:49:32 -0800 (PST) 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=iS8IOxUx; 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 S231249AbhCIMs6 (ORCPT + 9 others); Tue, 9 Mar 2021 07:48:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36548 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230525AbhCIMsz (ORCPT ); Tue, 9 Mar 2021 07:48:55 -0500 Received: from mail-il1-x129.google.com (mail-il1-x129.google.com [IPv6:2607:f8b0:4864:20::129]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B896C06174A for ; Tue, 9 Mar 2021 04:48:55 -0800 (PST) Received: by mail-il1-x129.google.com with SMTP id s1so12018468ilh.12 for ; Tue, 09 Mar 2021 04:48:55 -0800 (PST) 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=3pf3F65RZucsIMXc3J9HNUjACeQQX3TS4fzpwXGEtjU=; b=iS8IOxUxwJJorOWzLGMy6Kxb65nOK6/tJxnAed4CH/QFGdI1j8DLGCNadtUB1tLM2F kWT5JkZnmHqCzSltKDpB2O/tj4Kj3i/XlAjpz34Cu12Ihjza53Sm82mqjq1lVNNjUuAn CzK+xNhZHgkR8Q3AF5iwPlNVBcsPbLxxmx2q6E5uLJiwdrR/il8UdIxBYwYzi+DudC5l +vMei49nRxrMfcSzgrhRQNFIT69jBmKWjs1eeAEHMDP7K0rd28IrZhJbbM+2Zij9Qaf/ ZYVr4iiuB13kQEMiZAZYUuDmpXKPmY9vX2n9QCYoV66U224oTkl76KcWxN6mwif1G8H3 hCSw== 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=3pf3F65RZucsIMXc3J9HNUjACeQQX3TS4fzpwXGEtjU=; b=XQpTScoDEeUUqUzklu2gGp3wQajQaZCCUnveVOqObU1QTqZy/fATpKM7pp+zZ4rn2f 08Qnl/SIy/jU7XmYGTIel62PbgjTI3ATyqgEeL1uq0ihE+qDZyt17TdpdK89J5odUl+l ILjmMHKAmXQx/f8Jpy4DdZxub9LXiWiNumAkuwhrlifrVkxqghHJ/Sk/S89Ah8/IHS/1 vcEs2BmAuPRumv+b+wnTAqz7P4iHXmA299ojaivUmfJtES4dbtGxs4E/Qb5bp7avvGdO sTyfgOVymp3Ml5K1ek241BNXZpyCyqFXpbKGQRKM5nPC4lBoEl6vo5c7hlEEFIoh03f2 aX1g== X-Gm-Message-State: AOAM532USZ/9MxbGEQQyDuwpBp99GoRuRT3074k0FykiWTNB6XlCL7PP xrx4kW6uN5WKUYNuQSAwoZK0Nw== X-Received: by 2002:a05:6e02:214f:: with SMTP id d15mr25415063ilv.180.1615294134578; Tue, 09 Mar 2021 04:48:54 -0800 (PST) Received: from presto.localdomain (c-73-185-129-58.hsd1.mn.comcast.net. [73.185.129.58]) by smtp.gmail.com with ESMTPSA id o23sm7810009ioo.24.2021.03.09.04.48.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Mar 2021 04:48:54 -0800 (PST) From: Alex Elder To: subashab@codeaurora.org, stranche@codeaurora.org, davem@davemloft.net, kuba@kernel.org Cc: sharathv@codeaurora.org, bjorn.andersson@linaro.org, evgreen@chromium.org, cpratapa@codeaurora.org, David.Laight@ACULAB.COM, elder@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v3 3/6] net: qualcomm: rmnet: kill RMNET_MAP_GET_*() accessor macros Date: Tue, 9 Mar 2021 06:48:45 -0600 Message-Id: <20210309124848.238327-4-elder@linaro.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210309124848.238327-1-elder@linaro.org> References: <20210309124848.238327-1-elder@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org The following macros, defined in "rmnet_map.h", assume a socket buffer is provided as an argument without any real indication this is the case. RMNET_MAP_GET_MUX_ID() RMNET_MAP_GET_CD_BIT() RMNET_MAP_GET_PAD() RMNET_MAP_GET_CMD_START() RMNET_MAP_GET_LENGTH() What they hide is pretty trivial accessing of fields in a structure, and it's much clearer to see this if we do these accesses directly. So rather than using these accessor macros, assign a local variable of the map header pointer type to the socket buffer data pointer, and derereference that pointer variable. In "rmnet_map_data.c", use sizeof(object) rather than sizeof(type) in one spot. Also, there's no need to byte swap 0; it's all zeros irrespective of endianness. Signed-off-by: Alex Elder Reviewed-by: Bjorn Andersson --- drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c | 10 ++++++---- drivers/net/ethernet/qualcomm/rmnet/rmnet_map.h | 12 ------------ .../net/ethernet/qualcomm/rmnet/rmnet_map_command.c | 11 ++++++++--- drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c | 4 ++-- 4 files changed, 16 insertions(+), 21 deletions(-) -- 2.27.0 diff --git a/drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c b/drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c index 3d00b32323084..2a6b2a609884c 100644 --- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c +++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c @@ -56,20 +56,22 @@ static void __rmnet_map_ingress_handler(struct sk_buff *skb, struct rmnet_port *port) { + struct rmnet_map_header *map_header = (void *)skb->data; struct rmnet_endpoint *ep; u16 len, pad; u8 mux_id; - if (RMNET_MAP_GET_CD_BIT(skb)) { + if (map_header->cd_bit) { + /* Packet contains a MAP command (not data) */ if (port->data_format & RMNET_FLAGS_INGRESS_MAP_COMMANDS) return rmnet_map_command(skb, port); goto free_skb; } - mux_id = RMNET_MAP_GET_MUX_ID(skb); - pad = RMNET_MAP_GET_PAD(skb); - len = RMNET_MAP_GET_LENGTH(skb) - pad; + mux_id = map_header->mux_id; + pad = map_header->pad_len; + len = ntohs(map_header->pkt_len) - pad; if (mux_id >= RMNET_MAX_LOGICAL_EP) goto free_skb; diff --git a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map.h b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map.h index 576501db2a0bc..2aea153f42473 100644 --- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map.h +++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map.h @@ -32,18 +32,6 @@ enum rmnet_map_commands { RMNET_MAP_COMMAND_ENUM_LENGTH }; -#define RMNET_MAP_GET_MUX_ID(Y) (((struct rmnet_map_header *) \ - (Y)->data)->mux_id) -#define RMNET_MAP_GET_CD_BIT(Y) (((struct rmnet_map_header *) \ - (Y)->data)->cd_bit) -#define RMNET_MAP_GET_PAD(Y) (((struct rmnet_map_header *) \ - (Y)->data)->pad_len) -#define RMNET_MAP_GET_CMD_START(Y) ((struct rmnet_map_control_command *) \ - ((Y)->data + \ - sizeof(struct rmnet_map_header))) -#define RMNET_MAP_GET_LENGTH(Y) (ntohs(((struct rmnet_map_header *) \ - (Y)->data)->pkt_len)) - #define RMNET_MAP_COMMAND_REQUEST 0 #define RMNET_MAP_COMMAND_ACK 1 #define RMNET_MAP_COMMAND_UNSUPPORTED 2 diff --git a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_command.c b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_command.c index beaee49621287..add0f5ade2e61 100644 --- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_command.c +++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_command.c @@ -12,12 +12,13 @@ static u8 rmnet_map_do_flow_control(struct sk_buff *skb, struct rmnet_port *port, int enable) { + struct rmnet_map_header *map_header = (void *)skb->data; struct rmnet_endpoint *ep; struct net_device *vnd; u8 mux_id; int r; - mux_id = RMNET_MAP_GET_MUX_ID(skb); + mux_id = map_header->mux_id; if (mux_id >= RMNET_MAX_LOGICAL_EP) { kfree_skb(skb); @@ -49,6 +50,7 @@ static void rmnet_map_send_ack(struct sk_buff *skb, unsigned char type, struct rmnet_port *port) { + struct rmnet_map_header *map_header = (void *)skb->data; struct rmnet_map_control_command *cmd; struct net_device *dev = skb->dev; @@ -58,7 +60,8 @@ static void rmnet_map_send_ack(struct sk_buff *skb, skb->protocol = htons(ETH_P_MAP); - cmd = RMNET_MAP_GET_CMD_START(skb); + /* Command data immediately follows the MAP header */ + cmd = (struct rmnet_map_control_command *)(map_header + 1); cmd->cmd_type = type & 0x03; netif_tx_lock(dev); @@ -71,11 +74,13 @@ static void rmnet_map_send_ack(struct sk_buff *skb, */ void rmnet_map_command(struct sk_buff *skb, struct rmnet_port *port) { + struct rmnet_map_header *map_header = (void *)skb->data; struct rmnet_map_control_command *cmd; unsigned char command_name; unsigned char rc = 0; - cmd = RMNET_MAP_GET_CMD_START(skb); + /* Command data immediately follows the MAP header */ + cmd = (struct rmnet_map_control_command *)(map_header + 1); command_name = cmd->command_name; switch (command_name) { diff --git a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c index bd1aa11c9ce59..fd55269c2ce3c 100644 --- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c +++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c @@ -321,7 +321,7 @@ struct sk_buff *rmnet_map_deaggregate(struct sk_buff *skb, return NULL; maph = (struct rmnet_map_header *)skb->data; - packet_len = ntohs(maph->pkt_len) + sizeof(struct rmnet_map_header); + packet_len = ntohs(maph->pkt_len) + sizeof(*maph); if (port->data_format & RMNET_FLAGS_INGRESS_MAP_CKSUMV4) packet_len += sizeof(struct rmnet_map_dl_csum_trailer); @@ -330,7 +330,7 @@ struct sk_buff *rmnet_map_deaggregate(struct sk_buff *skb, return NULL; /* Some hardware can send us empty frames. Catch them */ - if (ntohs(maph->pkt_len) == 0) + if (!maph->pkt_len) return NULL; skbn = alloc_skb(packet_len + RMNET_MAP_DEAGGR_SPACING, GFP_ATOMIC); From patchwork Tue Mar 9 12:48:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 395966 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp2554924jai; Tue, 9 Mar 2021 04:50:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJy/P3ehA1wvjvOuxRAr7/chBCRgHjE/J6etAZp0QrD8C6pIS40gN3Ol3eW4Q6bBzon3/Mv5 X-Received: by 2002:a17:906:3395:: with SMTP id v21mr20036193eja.322.1615294202353; Tue, 09 Mar 2021 04:50:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615294202; cv=none; d=google.com; s=arc-20160816; b=n5uY3W7swlH/DaJ7bV0L81hv0djy/Ih3FO0Xxed8EEARGY65mAgRPH/adR6G2+zrJK L2zj8MhYvGS13N2KbYcmAPG8dzbZ/v/oszpDghZHcv7J2bcOIOXIKNP+ZuURFAY7aZlX IX6jV0TUX5d05AFc2kY4y04CA5Hk1EIak9FGKfgryiSKnaRH8i9dnK8+CgQ2y3oCGnbA AYETG/lvBychuo4DM6HE1qyv4D6Goc3HGPY9xsz8t4Y+eiLU1OInRGjJjITrn3qcrlUY oH8tFeond9kh4YtHuNkZ5s78wCwy5xpaDFXQ7MYSW4pDlGym8AbSKcyaY4o+/6pg834P GOYQ== 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=0+wb+u/7a6kg9MtdFGlRH2/NSAh7RkwKkpqOHuLRQ5E=; b=DTdOyDvgDqnNsL0LQaFMIQb8UTRWztVbTmObx2odInTeTLVfMWuijsq9Mgj3fdGtSP gQfWhryCU57oipZSImDb5i8GzK7iSld8my3Gm2J+J3dTkcxumHjEqwJGRvI3LonblAZ6 4L6qGz5T8F6BbmcsvQn28Jkw9VnxqFQLXwDnQsQDM/MyzEDRRDMZjhxwXl4N1OQ25gwK SQ5E7Dwtn0AndSz0DZA6Dkl/1UK3jevDrKgZHbK0xaIX59FzDZggvJOLGU3tdUqIepk4 NRIJdtY45JGY8kXDJVjOHlgCK8LqHTpAb4Se/IJ6L1i78sdA0M4VXi6W5PWTCqgP2wkQ p7nw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=C+vX5n8O; 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 ly3si9012939ejb.615.2021.03.09.04.50.02; Tue, 09 Mar 2021 04:50:02 -0800 (PST) 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=C+vX5n8O; 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 S231279AbhCIMtb (ORCPT + 9 others); Tue, 9 Mar 2021 07:49:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36554 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229799AbhCIMs4 (ORCPT ); Tue, 9 Mar 2021 07:48:56 -0500 Received: from mail-il1-x12c.google.com (mail-il1-x12c.google.com [IPv6:2607:f8b0:4864:20::12c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 38632C06175F for ; Tue, 9 Mar 2021 04:48:56 -0800 (PST) Received: by mail-il1-x12c.google.com with SMTP id z9so12068119iln.1 for ; Tue, 09 Mar 2021 04:48:56 -0800 (PST) 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=0+wb+u/7a6kg9MtdFGlRH2/NSAh7RkwKkpqOHuLRQ5E=; b=C+vX5n8Oot6G96fJwnTkOoS03gD4wvAvfOT9CuF2Es6Qar83XkIyQ1X6Salg6zXNGa /C/IOeNm7xddjzaF/NaYtonxtJ688z77ZpLk207CDXMWOouJ0EbObkktbg6F0KaehWD5 7TXBRrNdPWIYFtaYsuBEmHvAF6QRbEk+k5BcyWdEKjgqIsTFe1d4zxywCv8rg6tbepWv 4T0LQqpRoVtsLkesNa01NXuWqkdc9rsCyjdFQUUPSNmtgB9NlALMCg+pVKQs73librYa suoUJ9HSwJg/AE6CUVwrMsg1jApJ7n5NCFfrNjW8I7BavpF6YL/C2dcSds99tzELJj5t vgHg== 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=0+wb+u/7a6kg9MtdFGlRH2/NSAh7RkwKkpqOHuLRQ5E=; b=DfQtGJkisdJZXc3EvPYCYIiep1vl/Vd6W5Zwew+gW9TpV9uJz+qxH/M1jyWwLycW7/ WAGi6N/AMjfy6IAX0l/jsAHz6854SyzXcIleonZhANLLLd+WGhiZKnMN4SLHV0P3Pf8C CaD434W+W7VzrXS51hBGpyE9+VAdp+BXlfi340tijUyKDpaeIkE8SUXi8m2MMr2ivv+A X/rBk76AdR4lyESGUSdXOEyDQOdHTyeQm7KpP1RxZE/nQRVRubIFrzV6kvUbt2Li733D MfetFHmZrj1bmNNywPuNP6+C9CeRREKP6XPQTfHE11/p0JbjIvLGn67XxuCtLZEUYUE9 mCpw== X-Gm-Message-State: AOAM530iLkMN7Bqn5EgInpi/rgtzhsuRiffUICs+iQ4k68cPVDjh1qOy kufPj2wRCdNQqI4JIi5+o8qPLA== X-Received: by 2002:a92:d5d2:: with SMTP id d18mr6464368ilq.50.1615294135594; Tue, 09 Mar 2021 04:48:55 -0800 (PST) Received: from presto.localdomain (c-73-185-129-58.hsd1.mn.comcast.net. [73.185.129.58]) by smtp.gmail.com with ESMTPSA id o23sm7810009ioo.24.2021.03.09.04.48.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Mar 2021 04:48:55 -0800 (PST) From: Alex Elder To: subashab@codeaurora.org, stranche@codeaurora.org, davem@davemloft.net, kuba@kernel.org Cc: sharathv@codeaurora.org, bjorn.andersson@linaro.org, evgreen@chromium.org, cpratapa@codeaurora.org, David.Laight@ACULAB.COM, elder@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v3 4/6] net: qualcomm: rmnet: use field masks instead of C bit-fields Date: Tue, 9 Mar 2021 06:48:46 -0600 Message-Id: <20210309124848.238327-5-elder@linaro.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210309124848.238327-1-elder@linaro.org> References: <20210309124848.238327-1-elder@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org The actual layout of bits defined in C bit-fields (e.g. int foo : 3) is implementation-defined. Structures defined in address this by specifying all bit-fields twice, to cover two possible layouts. I think this pattern is repetitive and noisy, and I find the whole notion of compiler "bitfield endianness" to be non-intuitive. Stop using C bit-fields for the command/data flag and the pad length fields in the rmnet_map structure, and define a single-byte flags field instead. Define a mask for the single bit "command" flag encoded in the flags field. Define a field mask for the encoded pad length, and access it using functions defined in . Signed-off-by: Alex Elder --- v3: Use BIT(x) and don't use u8_get_bits() for the command flag .../ethernet/qualcomm/rmnet/rmnet_handlers.c | 5 ++-- .../ethernet/qualcomm/rmnet/rmnet_map_data.c | 4 +++- include/linux/if_rmnet.h | 23 ++++++++----------- 3 files changed, 16 insertions(+), 16 deletions(-) -- 2.27.0 diff --git a/drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c b/drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c index 2a6b2a609884c..28d355b094683 100644 --- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c +++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c @@ -4,6 +4,7 @@ * RMNET Data ingress/egress handler */ +#include #include #include #include @@ -61,7 +62,7 @@ __rmnet_map_ingress_handler(struct sk_buff *skb, u16 len, pad; u8 mux_id; - if (map_header->cd_bit) { + if (map_header->flags & MAP_CMD_FLAG) { /* Packet contains a MAP command (not data) */ if (port->data_format & RMNET_FLAGS_INGRESS_MAP_COMMANDS) return rmnet_map_command(skb, port); @@ -70,7 +71,7 @@ __rmnet_map_ingress_handler(struct sk_buff *skb, } mux_id = map_header->mux_id; - pad = map_header->pad_len; + pad = u8_get_bits(map_header->flags, MAP_PAD_LEN_FMASK); len = ntohs(map_header->pkt_len) - pad; if (mux_id >= RMNET_MAX_LOGICAL_EP) diff --git a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c index fd55269c2ce3c..3291f252d81b0 100644 --- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c +++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c @@ -4,6 +4,7 @@ * RMNET Data MAP protocol */ +#include #include #include #include @@ -299,7 +300,8 @@ struct rmnet_map_header *rmnet_map_add_map_header(struct sk_buff *skb, done: map_header->pkt_len = htons(map_datalen + padding); - map_header->pad_len = padding & 0x3F; + /* This is a data packet, so the CMD bit is 0 */ + map_header->flags = u8_encode_bits(padding, MAP_PAD_LEN_FMASK); return map_header; } diff --git a/include/linux/if_rmnet.h b/include/linux/if_rmnet.h index 8c7845baf3837..22ccc89bb5d8e 100644 --- a/include/linux/if_rmnet.h +++ b/include/linux/if_rmnet.h @@ -6,21 +6,18 @@ #define _LINUX_IF_RMNET_H_ struct rmnet_map_header { -#if defined(__LITTLE_ENDIAN_BITFIELD) - u8 pad_len:6; - u8 reserved_bit:1; - u8 cd_bit:1; -#elif defined (__BIG_ENDIAN_BITFIELD) - u8 cd_bit:1; - u8 reserved_bit:1; - u8 pad_len:6; -#else -#error "Please fix " -#endif - u8 mux_id; - __be16 pkt_len; + u8 flags; /* MAP_*_FMASK */ + u8 mux_id; + __be16 pkt_len; /* Length of packet, including pad */ } __aligned(1); +/* rmnet_map_header flags field: + * CMD: 1 = packet contains a MAP command; 0 = packet contains data + * PAD_LEN: number of pad bytes following packet data + */ +#define MAP_CMD_FLAG BIT(7) +#define MAP_PAD_LEN_FMASK GENMASK(5, 0) + struct rmnet_map_dl_csum_trailer { u8 reserved1; #if defined(__LITTLE_ENDIAN_BITFIELD) From patchwork Tue Mar 9 12:48:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 395968 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp2554951jai; Tue, 9 Mar 2021 04:50:04 -0800 (PST) X-Google-Smtp-Source: ABdhPJzna0+a7iBdAuMbIE0xsvuS2xWfXzs0DU9lMWW4q4ioT5LzsIZsEOlbjFLFKOUDhmEDeTnR X-Received: by 2002:a50:9dcd:: with SMTP id l13mr3930881edk.220.1615294204514; Tue, 09 Mar 2021 04:50:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615294204; cv=none; d=google.com; s=arc-20160816; b=vqLqzhsGeGj1ta8nh2u/fVidwa/igrY262J3YhQc+EOek7bpkO11BfZGbasj6o9uP+ x50pbA7HHQbcuI9noF1LKF/7831na/hOeh1JnsgdYtA4F+jVWEyNA1EQizompsVni532 6sQsooNfSVK3CrxmopV7TnWpakobZYirbWhcTW827dZUk2iMWVEq23Ouq12aFsMSqpyc caOaV4vAV36noGsV/8Alwvd+YuRtb9P5J3hx9BkGD79V1X1GF2cmczOLMdb5lwWi3ZbL Lb0oq/nooCrh78bRao6x6dkQqUCok1sgDFx1ByRyrI7IaD9ACWGK+E+BTlp5PyIPEWV9 57gQ== 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=m+KRVYYDfV87KFB6tUI9FoT8TIrlqrfga0gxkkg+SWw=; b=cABhSVEESmTaQQZh3VjV+/zcs1w35fBIhZG4Q+pUZFy5tc+aqktuk2Z8OpgCpcn43H 0GqkQWTqKla+vfqJerlF6lBJlEsYlGG0gA0ybABZy25AoxfHJgrcOaW6CfVNCj0s407c ik8d3ULmGOskNnjTmvvDjUEuHvzp+AiCuRTH9OJQ00kdviIY/Jmt4z7WWDa/YqL+WL1N x3pMZg8XRYjW3VW9WsmrL24HCn1p6/ZlJM9xm7Vw0WUx5YBlI02EusVK+SSx3dRT0BDe ApgAE714UAxgWaRiuD4fGZ/1NpPx1CvNVA3oUiPNj3Z827nhhDm0BHM6mMm3zw3KrwX1 sjSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=I9w2f8aM; 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 ly3si9012939ejb.615.2021.03.09.04.50.04; Tue, 09 Mar 2021 04:50:04 -0800 (PST) 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=I9w2f8aM; 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 S231328AbhCIMtf (ORCPT + 9 others); Tue, 9 Mar 2021 07:49:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36564 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230328AbhCIMs5 (ORCPT ); Tue, 9 Mar 2021 07:48:57 -0500 Received: from mail-il1-x133.google.com (mail-il1-x133.google.com [IPv6:2607:f8b0:4864:20::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3A9FDC06175F for ; Tue, 9 Mar 2021 04:48:57 -0800 (PST) Received: by mail-il1-x133.google.com with SMTP id v14so12031062ilj.11 for ; Tue, 09 Mar 2021 04:48:57 -0800 (PST) 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=m+KRVYYDfV87KFB6tUI9FoT8TIrlqrfga0gxkkg+SWw=; b=I9w2f8aMpEAj0XV6jP3/gp/JWkDbLZKqW4VqQUsbdf4LKeCoBsc92x6L7u4MIsJLJo F9raivv5YQMaRRjyO+dcRRHI44MA/FJ5OgE4x+IE7vVoEpIunt6vcW5f5gdRhb7q885l tvi1Mz4t+h0myScM0WYrzUoKkaXTpdLUsQnN/NLeqaBCKlnK/1NIlsFlmpuOhcZjYfRI La6Eil57+K0XvIC/wRnh+45tOaFmQwKtxbLhGqaHC4mrY4b1fn7uEFPXjTIOcIyBfBaR rt3O8mCfgkbH+p21109IOjWWR4LiDtq1QDJ6O/cPO+kwixAs6luimglrpn7EAFD+Jy9S ObIA== 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=m+KRVYYDfV87KFB6tUI9FoT8TIrlqrfga0gxkkg+SWw=; b=Lu1WtDFB9o/FLZQaPq/TNPplkaPwHZX9OcFi0dDEBj9O/Q/mSNaYkwMidyzNH/Vy3z yVJ7nW0lEgVbt9i8zU07pXqjtnYuiSQk7vmiGZVEerrreaqGCrX5FUnuKt3fFPz8apY5 cVMODVjTijOgzarIgNSE1gzFOxox8DnYB/uCOfPxKEO/9C+vLHnd5ovvMJCgLnVYzUUp fCBK4ZVlNS9Ss2V/8VvB4SPAjRku9UPXScVm15zC2VNXw1/fSX0lFMHqGrYJPyqYulqs ac7T591G9LTV3FNm6y2eT12at4OIoiQNwhCRMH3t5hC70Ntn3mtyvMBYqxNY7yt1lVyM T1uw== X-Gm-Message-State: AOAM5333gcTFKg6Tt50LzYjLnJxCLvvfMvaRqwx//H7CN4Wov1chAQqT PwOU6Avtn3YgtBe3l72zrnASYQ== X-Received: by 2002:a05:6e02:144d:: with SMTP id p13mr23938935ilo.41.1615294136729; Tue, 09 Mar 2021 04:48:56 -0800 (PST) Received: from presto.localdomain (c-73-185-129-58.hsd1.mn.comcast.net. [73.185.129.58]) by smtp.gmail.com with ESMTPSA id o23sm7810009ioo.24.2021.03.09.04.48.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Mar 2021 04:48:56 -0800 (PST) From: Alex Elder To: subashab@codeaurora.org, stranche@codeaurora.org, davem@davemloft.net, kuba@kernel.org Cc: sharathv@codeaurora.org, bjorn.andersson@linaro.org, evgreen@chromium.org, cpratapa@codeaurora.org, David.Laight@ACULAB.COM, elder@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v3 5/6] net: qualcomm: rmnet: don't use C bit-fields in rmnet checksum trailer Date: Tue, 9 Mar 2021 06:48:47 -0600 Message-Id: <20210309124848.238327-6-elder@linaro.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210309124848.238327-1-elder@linaro.org> References: <20210309124848.238327-1-elder@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Replace the use of C bit-fields in the rmnet_map_dl_csum_trailer structure with a single one-byte field, using constant field masks to encode or get at embedded values. Signed-off-by: Alex Elder Reviewed-by: Bjorn Andersson --- v3: Use BIT(x) and don't use u8_get_bits() for the checksum valid flag .../ethernet/qualcomm/rmnet/rmnet_map_data.c | 2 +- include/linux/if_rmnet.h | 17 +++++++---------- 2 files changed, 8 insertions(+), 11 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 3291f252d81b0..72dbbe2c27bd7 100644 --- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c +++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c @@ -365,7 +365,7 @@ int rmnet_map_checksum_downlink_packet(struct sk_buff *skb, u16 len) csum_trailer = (struct rmnet_map_dl_csum_trailer *)(skb->data + len); - if (!csum_trailer->valid) { + if (csum_trailer->flags & MAP_CSUM_DL_VALID_FLAG) { priv->stats.csum_valid_unset++; return -EINVAL; } diff --git a/include/linux/if_rmnet.h b/include/linux/if_rmnet.h index 22ccc89bb5d8e..a848bb2e0dad0 100644 --- a/include/linux/if_rmnet.h +++ b/include/linux/if_rmnet.h @@ -19,21 +19,18 @@ struct rmnet_map_header { #define MAP_PAD_LEN_FMASK GENMASK(5, 0) struct rmnet_map_dl_csum_trailer { - u8 reserved1; -#if defined(__LITTLE_ENDIAN_BITFIELD) - u8 valid:1; - u8 reserved2:7; -#elif defined (__BIG_ENDIAN_BITFIELD) - u8 reserved2:7; - u8 valid:1; -#else -#error "Please fix " -#endif + u8 reserved1; + u8 flags; /* MAP_CSUM_DL_*_FMASK */ __be16 csum_start_offset; __be16 csum_length; __be16 csum_value; } __aligned(1); +/* rmnet_map_dl_csum_trailer flags field: + * VALID: 1 = checksum and length valid; 0 = ignore them + */ +#define MAP_CSUM_DL_VALID_FLAG BIT(0) + struct rmnet_map_ul_csum_header { __be16 csum_start_offset; #if defined(__LITTLE_ENDIAN_BITFIELD) From patchwork Tue Mar 9 12:48:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 395967 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp2554936jai; Tue, 9 Mar 2021 04:50:03 -0800 (PST) X-Google-Smtp-Source: ABdhPJyGCiJa9aIHOsFhoYG4KC3TFVP20SCrhRDovwFXsbrwdrTPELsr5aZJ+qn4Ed82n/WCUyXF X-Received: by 2002:a05:6402:c96:: with SMTP id cm22mr3922555edb.128.1615294203726; Tue, 09 Mar 2021 04:50:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615294203; cv=none; d=google.com; s=arc-20160816; b=0blROsrkpYPg8mo5xNpGH3j3SlFRjA8WUcKF5Dztz45OnzZY+uxGo3rZXwiFKgdjrl +X2QsW6+s8zCujEwmQYw8QJPEWcfJglkFqSeMhhVXydWsP2pQCcEFYzwPBBNTzGui/Ib uTPTuTm6d2OmLylxKEVR0lB+rZ7a1tNBFdWFuh7wtQ8KBIHdBmHaqZhmMMGUJJU/MjT8 sCoZwyOMkq0DMdI4SHuuR2RS3gOa95MqtPs7ncRdL02K7r/2eowzgLBqLCm087wY7siU H0NmEyVnQ8riqHQ1DkENnr0lQOMJaLys0Lr0AaBTe5hWcbKd6p/ePRWWdD43LLDJJwPx qRyw== 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=Q3mPtnM0Ocz/MEgmITiZnxbVwwxPG5ePxZNKL9aLA68=; b=IiqcrXeDkNWrtGkeynP61uGK2BcQIILpe07Od6tKd10d1/86oJ9sowi9fYhajWEJ6O ni0ct9nO5Riyw1C7gMfuSYP8tyemWJV2/jXcv547go3GipqabP/uAVJgo6nxW/4AzTFU SqDljQlkzXL4cD8YLjsB04Y6sONFl30cV3TEwgpWOSxoh5ryHdSU2FYuGZ/JWg/gDekF HLO7u+jNXSDX1cUx5jpzbbcXMhMTA9Ulfc0JCxPg/3SWxtCrZcEvKFOpRdDVsvQN/dw/ B1oPCdNOcpZWPNRg8nHwHikFAMaL22C5tJYATTTaytlH8MOOW6M35jYvwBxikGTrWcDF gQnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="d7LTi/33"; 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 ly3si9012939ejb.615.2021.03.09.04.50.03; Tue, 09 Mar 2021 04:50:03 -0800 (PST) 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="d7LTi/33"; 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 S231303AbhCIMte (ORCPT + 9 others); Tue, 9 Mar 2021 07:49:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36568 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231234AbhCIMs6 (ORCPT ); Tue, 9 Mar 2021 07:48:58 -0500 Received: from mail-il1-x12f.google.com (mail-il1-x12f.google.com [IPv6:2607:f8b0:4864:20::12f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 372BCC06174A for ; Tue, 9 Mar 2021 04:48:58 -0800 (PST) Received: by mail-il1-x12f.google.com with SMTP id i18so12006150ilq.13 for ; Tue, 09 Mar 2021 04:48:58 -0800 (PST) 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=Q3mPtnM0Ocz/MEgmITiZnxbVwwxPG5ePxZNKL9aLA68=; b=d7LTi/33dD8m4z+rN9ePkqIrT23bJ6Q6jSOHVxMY9a+LM9O5+DyTXzkvNBpwxKI9gS fJLe6s3rSu6ftV0QoACv+Fob1XIpmD2MPbF4Y+HWGv2vCqTb36hW4IFCNNwaJ1aHAstT hOOdGUPG9RiuXOIARSGH++/o/51lioHGdZgbgt0OfUA+IpIRMnX+NRSVth1Ymicbuykx C347PQbDekgDc87jdRpthFj6yHKdM0S0H55SGlN6SB4Uv8mOpV7p/z1S+gLm5NPVUqcP p94zAKs8rX4BKhZaPWrh4BIg0AX47g72taQn+LmCDrtZVhxvBdMZ93KEhCks45vOENRS V0pQ== 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=Q3mPtnM0Ocz/MEgmITiZnxbVwwxPG5ePxZNKL9aLA68=; b=h1E/l+pxI/nW2TJ2OhYBVfW5CMxaxDjxvGCH2gyZhfFh/d61r2u0udfGf/wIfAn7qR d/dvYJXT93ijhRIOZMzsoTKw1dG6YUGgRrQb45k0/cf3XNjI024IF5C18FIystAiNc/2 9tTNFbG6a54ItJDy8j7V/+K/J7Om6yUdkU+M06j38Pc9I6AxPFj53jTB1ip87amQdm7b Qs6WifQi42QM6nrXsAztdq2o9l2weTdf2VnuCnbn2CnjbK79zlNo8vZfzDq26y0DQhXr fQeAm0z1uT0gaLSpYrGvW/6JxKZZUw09fMogYFHJtfsbUow4rAQf23KtZR65W1OX6kXX 9RUQ== X-Gm-Message-State: AOAM532BRpajeYwBA3wPz3CCIrWodcFaAnx7CDDQKBm/ihm+rQKt4hRW Spml25fPmwGdNT2cUvULwt+lhg== X-Received: by 2002:a05:6e02:12cc:: with SMTP id i12mr24159277ilm.113.1615294137701; Tue, 09 Mar 2021 04:48:57 -0800 (PST) Received: from presto.localdomain (c-73-185-129-58.hsd1.mn.comcast.net. [73.185.129.58]) by smtp.gmail.com with ESMTPSA id o23sm7810009ioo.24.2021.03.09.04.48.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Mar 2021 04:48:57 -0800 (PST) From: Alex Elder To: subashab@codeaurora.org, stranche@codeaurora.org, davem@davemloft.net, kuba@kernel.org Cc: sharathv@codeaurora.org, bjorn.andersson@linaro.org, evgreen@chromium.org, cpratapa@codeaurora.org, David.Laight@ACULAB.COM, elder@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, kernel test robot Subject: [PATCH net-next v3 6/6] net: qualcomm: rmnet: don't use C bit-fields in rmnet checksum header Date: Tue, 9 Mar 2021 06:48:48 -0600 Message-Id: <20210309124848.238327-7-elder@linaro.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210309124848.238327-1-elder@linaro.org> References: <20210309124848.238327-1-elder@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Replace the use of C bit-fields in the rmnet_map_ul_csum_header structure with a single two-byte (big endian) structure member, and use bit or field masks to encode or get values within it. Previously rmnet_map_ipv4_ul_csum_header() would update C bit-field values in host byte order, then forcibly fix their byte order using a combination of byte swap operations and types. Instead, just compute the value that needs to go into the new structure member and save it with a simple byte-order conversion. Make similar simplifications in rmnet_map_ipv6_ul_csum_header(). Finally, in rmnet_map_checksum_uplink_packet() a set of assignments zeroes every field in the upload checksum header. Replace that with a single memset() operation. Signed-off-by: Alex Elder Reported-by: kernel test robot --- v3: Use BIT(x) and don't use u16_get_bits() for single-bit flags v2: Fixed to use u16_encode_bits() instead of be16_encode_bits(). .../ethernet/qualcomm/rmnet/rmnet_map_data.c | 34 ++++++------------- include/linux/if_rmnet.h | 21 ++++++------ 2 files changed, 21 insertions(+), 34 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 72dbbe2c27bd7..1ddc3440c8b48 100644 --- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c +++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c @@ -198,23 +198,19 @@ rmnet_map_ipv4_ul_csum_header(void *iphdr, struct rmnet_map_ul_csum_header *ul_header, struct sk_buff *skb) { - __be16 *hdr = (__be16 *)ul_header; struct iphdr *ip4h = iphdr; u16 offset; + u16 val; offset = skb_transport_header(skb) - (unsigned char *)iphdr; ul_header->csum_start_offset = htons(offset); - ul_header->csum_insert_offset = skb->csum_offset; - ul_header->csum_enabled = 1; + val = MAP_CSUM_UL_ENABLED_FLAG; if (ip4h->protocol == IPPROTO_UDP) - ul_header->udp_ind = 1; - else - ul_header->udp_ind = 0; + val |= MAP_CSUM_UL_UDP_FLAG; + val |= u16_encode_bits(skb->csum_offset, MAP_CSUM_UL_OFFSET_FMASK); - /* Changing remaining fields to network order */ - hdr++; - *hdr = htons((__force u16)*hdr); + ul_header->csum_info = htons(val); skb->ip_summed = CHECKSUM_NONE; @@ -241,24 +237,19 @@ rmnet_map_ipv6_ul_csum_header(void *ip6hdr, struct rmnet_map_ul_csum_header *ul_header, struct sk_buff *skb) { - __be16 *hdr = (__be16 *)ul_header; struct ipv6hdr *ip6h = ip6hdr; u16 offset; + u16 val; offset = skb_transport_header(skb) - (unsigned char *)ip6hdr; ul_header->csum_start_offset = htons(offset); - ul_header->csum_insert_offset = skb->csum_offset; - ul_header->csum_enabled = 1; - + val = MAP_CSUM_UL_ENABLED_FLAG; if (ip6h->nexthdr == IPPROTO_UDP) - ul_header->udp_ind = 1; - else - ul_header->udp_ind = 0; + val |= MAP_CSUM_UL_UDP_FLAG; + val |= u16_encode_bits(skb->csum_offset, MAP_CSUM_UL_OFFSET_FMASK); - /* Changing remaining fields to network order */ - hdr++; - *hdr = htons((__force u16)*hdr); + ul_header->csum_info = htons(val); skb->ip_summed = CHECKSUM_NONE; @@ -425,10 +416,7 @@ void rmnet_map_checksum_uplink_packet(struct sk_buff *skb, } sw_csum: - ul_header->csum_start_offset = 0; - ul_header->csum_insert_offset = 0; - ul_header->csum_enabled = 0; - ul_header->udp_ind = 0; + memset(ul_header, 0, sizeof(*ul_header)); priv->stats.csum_sw++; } diff --git a/include/linux/if_rmnet.h b/include/linux/if_rmnet.h index a848bb2e0dad0..141754d0078cc 100644 --- a/include/linux/if_rmnet.h +++ b/include/linux/if_rmnet.h @@ -33,17 +33,16 @@ struct rmnet_map_dl_csum_trailer { struct rmnet_map_ul_csum_header { __be16 csum_start_offset; -#if defined(__LITTLE_ENDIAN_BITFIELD) - u16 csum_insert_offset:14; - u16 udp_ind:1; - u16 csum_enabled:1; -#elif defined (__BIG_ENDIAN_BITFIELD) - u16 csum_enabled:1; - u16 udp_ind:1; - u16 csum_insert_offset:14; -#else -#error "Please fix " -#endif + __be16 csum_info; /* MAP_CSUM_UL_*_FMASK */ } __aligned(1); +/* csum_info field: + * OFFSET: where (offset in bytes) to insert computed checksum + * UDP: 1 = UDP checksum (zero checkum means no checksum) + * ENABLED: 1 = checksum computation requested + */ +#define MAP_CSUM_UL_OFFSET_FMASK GENMASK(13, 0) +#define MAP_CSUM_UL_UDP_FLAG BIT(14) +#define MAP_CSUM_UL_ENABLED_FLAG BIT(15) + #endif /* !(_LINUX_IF_RMNET_H_) */