From patchwork Thu Mar 4 22:34:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 393336 Delivered-To: patch@linaro.org Received: by 2002:a17:906:a383:0:0:0:0 with SMTP id k3csp899ejz; Thu, 4 Mar 2021 14:49:25 -0800 (PST) X-Google-Smtp-Source: ABdhPJz+IDFQi9+HGsOyDdfZgpwe2aggURPp+7Qw1i3LLSe4Nij/3zLi7WnnFbX0WGdOCNrtdiVJ X-Received: by 2002:a17:906:5012:: with SMTP id s18mr5625272ejj.100.1614897717418; Thu, 04 Mar 2021 14:41:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614897717; cv=none; d=google.com; s=arc-20160816; b=t2FqJ19TNXrRCgpBYZ5ShiYNFUtVr9RqeWwBFPchQOcjylyiLYtZWeOekVUvVf3p70 FAa5diXT0e2CQm+Wqg1E6c85t80rn4f+5d7A60cuyjLggKf8ir531sWHmwIwK3uUV/46 GF8nn8Wamo2IbdbmY8wZMlloSJtLxGoW9mqUvvdF0n2ECZ3bF2Rgu78YPsS3MdnoT2G6 /GVXCCbPmqPpluGjbRzHUloKPw9Z96axSYk+GZic0KmZTFas4Ain8tSYn5dNd7Uv3MZc 4rndrX4KOkWbMnjDwUeul9Zhkg0isumH5dT1YOHiXA8CnZUbcTIFYFLMtBBQlJPcAkOO 6+tA== 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=MnFEnN5RmyJ3fEdCeq5FgUIloZ1Qg9btOxjTlofMuGs=; b=UNIqbXoJOlZQMfmAZA/5Pom6zvjBCsbDm6XauyLAtgn0dFL3hOzaLXjD7IYLurqRUb fMgALQGaWq0UB6caNeS1+uXV27lXi10vO2p6SWOicp/aAcUb0UOt4Ub3dJ2xTNh3iYOW vKOgh2CeunWTevg2egzqgX5o48eq8oXVWLmxIRLWr0V4X12zQQ6+dDjxpTmVGDAa5Ul3 EkllSnVu4Uwno3X+Y7QE+0bH972pUA4iU28JZaAahq2wQhLL5XbLBpirfx2pQ4f3J9ct PdArT6FIzbfAkbaTuUodQTXqHvdmn4xIkNS+3L1TzHYBKO//eFEaHPGe3DrW345fxCT+ JR5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YOUlvIZ6; 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 k6si527757edj.545.2021.03.04.14.41.57; Thu, 04 Mar 2021 14:41:57 -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=YOUlvIZ6; 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 S232103AbhCDWei (ORCPT + 9 others); Thu, 4 Mar 2021 17:34:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55246 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232041AbhCDWeg (ORCPT ); Thu, 4 Mar 2021 17:34:36 -0500 Received: from mail-il1-x135.google.com (mail-il1-x135.google.com [IPv6:2607:f8b0:4864:20::135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 852E3C061574 for ; Thu, 4 Mar 2021 14:34:36 -0800 (PST) Received: by mail-il1-x135.google.com with SMTP id d5so183390iln.6 for ; Thu, 04 Mar 2021 14:34:36 -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=MnFEnN5RmyJ3fEdCeq5FgUIloZ1Qg9btOxjTlofMuGs=; b=YOUlvIZ6vGjjmdarK/YdgLqCpS/wF4ke284UtZhRlJaa7oxOeefH3BiaEB6+6FWjkR UjX/WvLgwYqOZRe21tdw0lO9I6u9WjQNxcZC0t8MxPOzJw0HEfLdZqi+4gwZddNdCNX7 pL9E8Rs3ksjjvulPw+zx91ua76XfWQzeKzxDpO9TbFLfJ/FjuVsxAEukmmnWLOgYu7mm t0kf+km8gp4MD6jigR2KwjSbGFef7v2waqP9Yyjwq6W15Xo1PGpOQ5Mfsbi91sB3M/T8 YXLohZxd4191MG2jOAZS3CuGCzMfYtfyRQlwn5ZiHBXnCpEsIg/N1gAJICuxcM+Zxb6o yNVw== 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=MnFEnN5RmyJ3fEdCeq5FgUIloZ1Qg9btOxjTlofMuGs=; b=iG3AeyKGtAR5dXqYzd+X2vOyqi8T4PgvILcLFPC3D25S4MwlE2drb/JLB/mh5BzKqe y/PfiqS/JDQsPYIKE/8tppGDCiwJytB2HoxQB9pP0cLOqN6uIsZy2zrAXG9yuAb9Od2Z lvVqZhlKuLIrsXOn1UYDEDIe2p9uwIUdxRg1FY7ExBzDM/Ao75Sa5OmhqQO5JsyKVaQZ 8JvvxN9C5rALuv/jm3GvK2lAobe7nkNel7B+NNikMui4+AKjKDKpHtDypLW+BHLsqfun IBornSMq+iKLUkWB9oHf/z/+uSmTFvr5M+AzUpIaq5yIu1hmHQhs03m5Tey59Uyc9RDq mP/g== X-Gm-Message-State: AOAM531KGiyNg+Pmi7jo5/XjBt7E5fXJNJntzmHrXlFKsOAkrYuay6jB AVWnfGGtLizQ9LFsD59GNInlOQ== X-Received: by 2002:a92:194b:: with SMTP id e11mr5947483ilm.184.1614897275911; Thu, 04 Mar 2021 14:34:35 -0800 (PST) Received: from beast.localdomain (c-73-185-129-58.hsd1.mn.comcast.net. [73.185.129.58]) by smtp.gmail.com with ESMTPSA id s18sm399790ilt.9.2021.03.04.14.34.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Mar 2021 14:34:35 -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, elder@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next 1/6] net: qualcomm: rmnet: mark trailer field endianness Date: Thu, 4 Mar 2021 16:34:26 -0600 Message-Id: <20210304223431.15045-2-elder@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210304223431.15045-1-elder@linaro.org> References: <20210304223431.15045-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 --- include/linux/if_rmnet.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) -- 2.20.1 Reviewed-by: Bjorn Andersson 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 Thu Mar 4 22:34: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: 393334 Delivered-To: patch@linaro.org Received: by 2002:a17:906:a383:0:0:0:0 with SMTP id k3csp743ejz; Thu, 4 Mar 2021 14:49:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJyCMfXVxEc0kjUdlM1h/Wt+wgxbDe01Fv9uBEjy2uvVAa499RzcnUqmK4M5uhdNNKJl6aun X-Received: by 2002:a17:906:1447:: with SMTP id q7mr6812187ejc.27.1614897721020; Thu, 04 Mar 2021 14:42:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614897721; cv=none; d=google.com; s=arc-20160816; b=dVxvRPD0YLn2G5oiA1rxYi7W4sA2nQwAE+EmkmaQfk5Jel590bP/lRiJ1UJGXndFvL BQ3msC1dPokcDKKMGnPECOJrG5cFe2j90apJ8z0F48V3rrpaQdbzaVDYyPNjFkD2Iwjb DI/Iqm1/inKu2g928ANDFf9f6TqN1jTB/GPJ9BtlSdTmFuoPZ5w1GkQriUxHaI3LX6fE +piW4zhYrxbDNsVyr5gbqseaSFW/ytiukkNnhCj29B0njhk98pFLrW3fcQABVUcCajlu 8uVGELm+qFVl6NtJnEFIZh7hn7eSkQMXRM/mtVssdqD5JpFFVEoVu3d2b7ynWx7S0KJ4 cqYA== 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=VDRd/k3SE2dFfwLHBJ3IM2QixWpwECC8r/K+T//z74M=; b=vL+4ZdXXPKlaqpC9XOC9soDxpDlKlVmc+2QFlol2BpdVWvG6kHqRPf2F6tbLrEa3bL 3F1635pFjnrLLy/M9Wi6O3U7s7XKsYEnu3O32HSGwc93IccxJ0HnBJVQGf3axcrU+oZ7 06vMoD8oE4xxZ84lSvt4xUhgKt9vfImm1yj6IuxHeRzBR3SMZW6eabtaeZrm+l8Mvcmd GnuFWMWczNxlEfKBt9UXij17nY/n/RvR1SBAht9f/93m05aptp+11KO8Tn7MXw97Y2B6 WXm9z0elgneFaiJb2SX5IhxahHLrw44u1uDx/X2trNieu4UWgaru2E/IqcNhMFitkZn6 YxIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=tWAVR0ya; 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 k6si527757edj.545.2021.03.04.14.42.00; Thu, 04 Mar 2021 14:42:01 -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=tWAVR0ya; 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 S232357AbhCDWew (ORCPT + 9 others); Thu, 4 Mar 2021 17:34:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55250 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232027AbhCDWeh (ORCPT ); Thu, 4 Mar 2021 17:34:37 -0500 Received: from mail-io1-xd33.google.com (mail-io1-xd33.google.com [IPv6:2607:f8b0:4864:20::d33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5AA16C06175F for ; Thu, 4 Mar 2021 14:34:37 -0800 (PST) Received: by mail-io1-xd33.google.com with SMTP id o11so23652567iob.1 for ; Thu, 04 Mar 2021 14:34:37 -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=VDRd/k3SE2dFfwLHBJ3IM2QixWpwECC8r/K+T//z74M=; b=tWAVR0yakCZ7JbblHhvdUrAUdw/HKQQ+0MJzkilNGz6FKRZXu65N0zJK7UF2UGzRQi rcixBryYc2QViduTnMU8eveNB96pOEul3Fe3MrYHMd3mp2H6P95Rqk7b8jHTRB2UWzxz +/SQM82ClIpQgqi9tQNIESuGP87s7V8k5YautEZOBCMamrRs96VVVX9awMGjYxpaEcRf fXeKkKuBdQsimbfnDf3O5OOJ425DT+W59GAdJeZ1jifWwQ1RVUuMsBtZp2WggZ/8z3wj pnbU6oeJyQGaR3AtKqddwZsv4MT7nyCbRYEi2/XGAw7ixJd867oOWli7kzvAYC+aklZh 750A== 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=VDRd/k3SE2dFfwLHBJ3IM2QixWpwECC8r/K+T//z74M=; b=W8I58pwJLTvBgo8LiQXKT27RjvH5Lwc3Cel0uUV42nmhGkDucgY4XjATDuZ29G7AD6 gTIKd3sXyfwkQKi36WOFTDDllJb1Jh3HnqPNYrvCFGyKZfC/HU/qv87Deo80R1jkqv8+ fnDEwPHZovvcJ+WyNMqHWwpBs0YHJeZYXmI+0e0aWOL2bOLJu5O2IYzCWnj6Zc0g6Tc1 x5rT5DrpK4bMbiBsHx63qDYLEca0pBNPJvzLCqXPqT4VBr3ZN924pmw9ZFHp1Nc4hWXU pkQrvlGAfaWCdJKB6SnksL3WmYVwEKIkiIpcj5oLQLh413jnS0znvq0/ZC9HJG1G2WzM cq5w== X-Gm-Message-State: AOAM530KIIbFJSMRO+1drEnnZQBbC6xi+i9EcPVGQh1Ln0ioZNGh20Xx 16M+IV+NMCmQP6g+8mqkovivNg== X-Received: by 2002:a05:6602:2102:: with SMTP id x2mr5722603iox.83.1614897276818; Thu, 04 Mar 2021 14:34:36 -0800 (PST) Received: from beast.localdomain (c-73-185-129-58.hsd1.mn.comcast.net. [73.185.129.58]) by smtp.gmail.com with ESMTPSA id s18sm399790ilt.9.2021.03.04.14.34.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Mar 2021 14:34:36 -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, elder@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next 2/6] net: qualcomm: rmnet: simplify some byte order logic Date: Thu, 4 Mar 2021 16:34:27 -0600 Message-Id: <20210304223431.15045-3-elder@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210304223431.15045-1-elder@linaro.org> References: <20210304223431.15045-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 --- .../ethernet/qualcomm/rmnet/rmnet_map_data.c | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) -- 2.20.1 Reviewed-by: Bjorn Andersson 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 Thu Mar 4 22:34:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 393335 Delivered-To: patch@linaro.org Received: by 2002:a17:906:a383:0:0:0:0 with SMTP id k3csp750ejz; Thu, 4 Mar 2021 14:49:10 -0800 (PST) X-Google-Smtp-Source: ABdhPJwkCBTxyBbi+nRGerxuZ7DQKpOyS3nFsLBrFC8qy42SDNMJBRHeQhMFCB2EAzNKV5n64tL3 X-Received: by 2002:a17:906:40c7:: with SMTP id a7mr6605080ejk.109.1614897719001; Thu, 04 Mar 2021 14:41:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614897718; cv=none; d=google.com; s=arc-20160816; b=iyHZyudz2s06/lGQepjc3Aymgyv/eS06pSq5Pyk4k8pmCTed/Cwo8g3vsNXwDVighL /pI9hYwfxNwboc3J91ajCzKppHkFpjA27QA7mDDQRf7PJQmlm48YjZBbqjBhRNVxRnkX d6qVMWuGSEXY2fN2hrJ0gk2h9C+NVHXhnuYFTEcOPnJHrQ8GXtc/6Z2QvEikyqr5k8FT KoBY+lMwdbVFWQPYjD1ookHx5OAbXP3XfqZtmpSQWtazX+LftKVk8bi3nhkcxWSv/qQV Ue0tQxDOaEhcy/48Rm0+vqFrSwLEcAh037G2FcXR2CJVVAHuIB/N7S6dwQD1CJ/hmyhI JnNg== 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=82gS3dr1lmNX6eOzYCV4o5GS358gJ/Wk20VCXTc/lZ0=; b=SzDypPFlzOduYgqiDSc6UHpWiEZCB1832NQrieec9aSzJQHMX+m3xV2RasnXDo9Fd5 lJxBzQiioui1bzF0NDllox0LEZZoLSpi8KiIfB84p3EPcwELDf/nkBN2MYY2J0HFAviV bVBOkqzhiF+6FSfAJ+tf8RYYWDJJib0tAjDr/yxGjRxfvw/fxsOS70QghnqL1Y4on8Wb Wxzt5k1LzYc2SWAV76S5C+Sq6Tpy4woR1a1At1E8GCO81hX5IuX2ovmtSToDjrG0PNUp sLH35QSlBFKbKVPv43sjk/sVCGtE31uAMeabMMoWB2haecp5V7DJDrYSryAkj3WuKDU5 fX4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VpU233ld; 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 k6si527757edj.545.2021.03.04.14.41.58; Thu, 04 Mar 2021 14:41:58 -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=VpU233ld; 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 S232256AbhCDWet (ORCPT + 9 others); Thu, 4 Mar 2021 17:34:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232115AbhCDWei (ORCPT ); Thu, 4 Mar 2021 17:34:38 -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 49FAAC061574 for ; Thu, 4 Mar 2021 14:34:38 -0800 (PST) Received: by mail-il1-x133.google.com with SMTP id s1so152644ilh.12 for ; Thu, 04 Mar 2021 14:34:38 -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=82gS3dr1lmNX6eOzYCV4o5GS358gJ/Wk20VCXTc/lZ0=; b=VpU233ldeklOSf6A0Pksib3d6P/G5lhb3NWmW+fYuaFZogTCgv7qXAPIeOV0hd495k TX+G2KlO5ePkSX7v1Ode0Xdl92Ny/+0OUrGRT+/QtmQO+D4E0Obuj+8GPlYHOOdjT70X iMdArQH15aJxO8whB9IaYQwolRQ7kraP0EjoKgbWdnjvtpUvYLeJo6HDot61EI/k+Jbz pVa/JW3DYtiIT402uMTbSix4SUcGVisZYJ20o0vnLoq4A/OpKwWN30jN+0alFCS060Wa t3+n32GeofvARRirMIVJ7C7sQu3VdTQbv82SzRKAOuXlUKQgCzEteSmLB06l9C1UX7yr d1yw== 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=82gS3dr1lmNX6eOzYCV4o5GS358gJ/Wk20VCXTc/lZ0=; b=jPGzI8/WFeHLP0Pa5SFA0UjCoDUDfyIvykxXhIlIEAxCGZYeD9vrZQxsOLX9VUbpLR elsbMTzdOqxkj6zhrUUWy77+K8bfXSMvmIFl6g7OAQyGxsmD0Yq2Vi9axkQz2TKL4Zoq Osv+NnxivdmEbbgaxBXVpDnmmIUOXzaoGZ3pXBUugob7IB9ENpKgJTOzGZWxzCgJY+kI /d89cyNovsUKmSiFojCcgYGjMjcc385LSjGKVtsvulf8ehT5JfPGSKq78B5b1YjyZBcp tZCwzQawnpE3NvADOMZK7yooUnV98w/oxq++pAbaeyx68xA+Yf6+Jl+EN2DiFcaHjjN9 U7nw== X-Gm-Message-State: AOAM531yjCj+puONq1AbA1Ey7+QouaZEiclJosooNde5WtXzBEYBivyK cx1pgJw4d5jt6Z7Rrwl0V2GugQ== X-Received: by 2002:a92:4a0e:: with SMTP id m14mr6084223ilf.117.1614897277720; Thu, 04 Mar 2021 14:34:37 -0800 (PST) Received: from beast.localdomain (c-73-185-129-58.hsd1.mn.comcast.net. [73.185.129.58]) by smtp.gmail.com with ESMTPSA id s18sm399790ilt.9.2021.03.04.14.34.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Mar 2021 14:34:37 -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, elder@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next 3/6] net: qualcomm: rmnet: kill RMNET_MAP_GET_*() accessor macros Date: Thu, 4 Mar 2021 16:34:28 -0600 Message-Id: <20210304223431.15045-4-elder@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210304223431.15045-1-elder@linaro.org> References: <20210304223431.15045-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 --- 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.20.1 Reviewed-by: Bjorn Andersson 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 Thu Mar 4 22:34:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 393019 Delivered-To: patch@linaro.org Received: by 2002:a17:906:a383:0:0:0:0 with SMTP id k3csp6387330ejz; Thu, 4 Mar 2021 14:43:34 -0800 (PST) X-Google-Smtp-Source: ABdhPJwJoU4HdmoWwarQ930lao0iRmk7rQChBwqo6uFKu1g6aox9E+GP1cQK5ntpOvdQs6dZ6osA X-Received: by 2002:a05:6402:215:: with SMTP id t21mr6740019edv.363.1614897717040; Thu, 04 Mar 2021 14:41:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614897717; cv=none; d=google.com; s=arc-20160816; b=k28rIlWlQolFo+RwvMsD2OlteZ8/KVr7AKMaSJ2aGGff0as0tGGxyegb2nnpSWZmGB AZxTp/26Fopj/cxLtnvdpu/D3IFvRnZqH8p6NHwadArhvMDmyQBLAbCWnhiuC8X0dhgl 9SMkjX5L8NGl5mskT1S4CmFJZdTT5N69cjBrU4tZgW5YS7kHF5tAvS/z1ateXXaZG/Pi 7x15mcxomyYLS/eeHmQoi4DupAcf5kiQUAoxt1zpVtFV1StelgkXYIBZYWJkbChcC4n8 w3GlztfRj1aU6JAwgz6fh4fV05PtwpmidxXwRfccV9pGXujyYBtYHrmQ93grDShyjDtk JIqg== 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=u8rJljDcSCEpHYCyMqU7xoqI25apaSt0GBEi+BjNLKI=; b=zMNBbxgCiJeRkFvzMnlzUIsNqIf8vWiE1tk8izTfNT3fPAjw8+v87zmgQ1gcOtjluD O7I8OXeknzUdsW5Ylsh+73xNkh94/r8YK/36rysl1eUyO0B2mvikxo6muezeB7CjuaGO ltksLAajIhWY0+6WdmuBlCV7serdArjlxUvHeYZK/NIKp8LM0oNI0xf9bU/q5lzJkDc2 tndtQjAqvqev/ikvDzzou+CTepEkB17NM7OYc14Jh39fkYbxChchf+vtbitvzmPqB8Pk rKh2w95KgMFMB7phmw2ENe/IRw1tfggg20rm5LotRn72OiRHRAHyjci867EYA/Fda+ul Z9JA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QBTvL34e; 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 k6si527757edj.545.2021.03.04.14.41.56; Thu, 04 Mar 2021 14:41:57 -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=QBTvL34e; 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 S232186AbhCDWem (ORCPT + 9 others); Thu, 4 Mar 2021 17:34:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55260 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232126AbhCDWej (ORCPT ); Thu, 4 Mar 2021 17:34:39 -0500 Received: from mail-io1-xd30.google.com (mail-io1-xd30.google.com [IPv6:2607:f8b0:4864:20::d30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 33E89C061756 for ; Thu, 4 Mar 2021 14:34:39 -0800 (PST) Received: by mail-io1-xd30.google.com with SMTP id z13so31578137iox.8 for ; Thu, 04 Mar 2021 14:34:39 -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=u8rJljDcSCEpHYCyMqU7xoqI25apaSt0GBEi+BjNLKI=; b=QBTvL34eQtIQoFiQiYSsWb8p+CLGzKt6R69kgY6VbPQSAq8I74oHLwra/+1KZT0AHf IhGAP2Gbfc2q9cwPbpX19pdw+H0LIoncjV+1bWgDT2I8XDA7pLqvmoIrAwanGyGFpUwV ZBoQWZs6VyC9fE2oUbw3m1Am9l+tjb2BAUI5JE00y1nutlSGhyII1NM0J3rPblwlfXJR +qcpxjUj6cA+GDvxTIxOVqUBKPPVlein1HjqXa8aM3sIb7EBRyyUwie6JniffuWmKkzr 5MzFUnjLw5A6IxWwd4tUNpYbvR2geeGhJUsWKgOY1x/Mqhz9cKTGJaq1kPFnu/OytKrD 1bIQ== 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=u8rJljDcSCEpHYCyMqU7xoqI25apaSt0GBEi+BjNLKI=; b=JDbpk2qEdbiipZrG7U/arkvNrIISwoR/hTopntqlxThCdN487UJNLexa8d+BfPWAlA B/RNQcQsR7fSSpud6FBAUCCrS80l6pFTjPD1Cd/5WliEMOgun1Ghj86WnhahdMefAoxL Ylo2vGklTUmonc08OuTjCzuSzqX2UpxSL5H4ya+mVb7P0YNdYLbovCfG3VN2PqPUH8YY sBxYBQfqKk6Co14WIH8zTmushiUX5ACSPMjQdxJEBLXNfGDXv3z8Pp03hlcMofzMi6fZ 6SMfhWUnx6kSVI4NIQ4mFqbQPfJSLiptCZ4EXgwvvRPxSflZv30ay3bSUqTZjpIXyFwQ G0VQ== X-Gm-Message-State: AOAM530kKfkDs27y/mcB9F4rNzkfQk7Ys7DsfJMYKpeP2U0EB98uMgvi V04+aK8DIA1BahHy9GTQ4cRQBg== X-Received: by 2002:a05:6602:2d83:: with SMTP id k3mr5513960iow.26.1614897278700; Thu, 04 Mar 2021 14:34:38 -0800 (PST) Received: from beast.localdomain (c-73-185-129-58.hsd1.mn.comcast.net. [73.185.129.58]) by smtp.gmail.com with ESMTPSA id s18sm399790ilt.9.2021.03.04.14.34.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Mar 2021 14:34:38 -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, elder@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next 4/6] net: qualcomm: rmnet: use field masks instead of C bit-fields Date: Thu, 4 Mar 2021 16:34:29 -0600 Message-Id: <20210304223431.15045-5-elder@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210304223431.15045-1-elder@linaro.org> References: <20210304223431.15045-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. Instead, define a single-byte flags field, and use the functions defined in , along with field mask constants to extract or assign values within that field. Signed-off-by: Alex Elder --- .../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.20.1 Reviewed-by: Bjorn Andersson diff --git a/drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c b/drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c index 2a6b2a609884c..30f8e2f02696b 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 (u8_get_bits(map_header->flags, MAP_CMD_FMASK)) { /* 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..4824c6328a82c 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_FMASK GENMASK(7, 7) +#define MAP_PAD_LEN_FMASK GENMASK(5, 0) + struct rmnet_map_dl_csum_trailer { u8 reserved1; #if defined(__LITTLE_ENDIAN_BITFIELD) From patchwork Thu Mar 4 22:34:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 392997 Delivered-To: patch@linaro.org Received: by 2002:a17:906:a383:0:0:0:0 with SMTP id k3csp6386257ejz; Thu, 4 Mar 2021 14:41:59 -0800 (PST) X-Google-Smtp-Source: ABdhPJzSD0xiw3aPcRFr//ZEQ6PFCj0KT06uNFcuCRdSEuFloC6RNWSsaR4D1exn0IS0KxAUa2EX X-Received: by 2002:a17:906:4e57:: with SMTP id g23mr6561915ejw.47.1614897719767; Thu, 04 Mar 2021 14:41:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614897719; cv=none; d=google.com; s=arc-20160816; b=fAGGyiwVFehQb645FVSrpUeeD77mXbQxbZbuBrA8qzQofqIsgIYIxCqzbeygYH6Kwr 8/v0KrjHIsXR68kCTlPjgP4dVQGD7WRS8Ks15SirSd5WB4kpuPthNN93xyDpywmRYVOv jp2PIqo+XatuOdm8VBlJN3447xgBN3CHCEKR7R5lp9v1nGZrMibDZi5khyEMuSsWd15L 4ftV+CbOtLEv5pftBTXnMUH80nKX0LfKOh880nTksE/zLiwVPhD+Yjv58m3bbMi0BzQN sjBEC0DyY/lrMas8vgcPk2gdCyd87i/R+jsMrLYqWA4DRR+Lv0WswXtp0ZaqqeNz/AMs ggdg== 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=dqfVD44TkK3usd1mQweHKY2fltJlJNKQWu+x3+YLrx8=; b=0a9p1bdD91ZKEqqjrZivuIlw0aTjfqFEyhWS/YB6gbx6vv68ax5jcFs0+I/HaaI9cp 8xH1QkKeqvVWlTsMs8ZxXnqSGirwFCLVF0qZEuZnO7PejqQyldt7EyYIxaWvCptnW0qP pKQmhVmLoEIBPABvdfosnLUME41ryrOZi0QHz0tkCW4vhdSXaQOOeqoNKAiA9g4xy1LW +ItxyLzUVXUSnQIv+k/mEVwO0R1IwSG5Iv6qIpihRPLt1vGKYf4Jb/j+Fiaro8IobCyn oQvguRI7STts4ciL4xz87WJ+eTEGtiyce/JnzB6EB9LlYEk1no72zSTYf91S8DBwz2Eb o7pA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=LxZjtMdw; 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 k6si527757edj.545.2021.03.04.14.41.59; Thu, 04 Mar 2021 14:41:59 -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=LxZjtMdw; 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 S232295AbhCDWeu (ORCPT + 9 others); Thu, 4 Mar 2021 17:34:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55274 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232163AbhCDWel (ORCPT ); Thu, 4 Mar 2021 17:34:41 -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 12C08C061756 for ; Thu, 4 Mar 2021 14:34:40 -0800 (PST) Received: by mail-il1-x130.google.com with SMTP id i18so148881ilq.13 for ; Thu, 04 Mar 2021 14:34:40 -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=dqfVD44TkK3usd1mQweHKY2fltJlJNKQWu+x3+YLrx8=; b=LxZjtMdwVi1XkqzUFyHPVfOnN+aQagcCZLKwyxir0fVx75Av3MXALiVChEq1IwHJ3z w2ZX1lX+prMbcBACRU5vxpjcnAuyc6EJ4Tgx8bGuQJ5XrJLbSLrPhAIX4LiIYuBmlWyx WF3dSsJIhmv9t/ioU9c9wtvBD+rcjmtrJo7yKWcjStNOitB94bqZS0Q8xjjTyK+F9M23 Q3C1pNNLo8VFGQKbMslmZp9i7CaTsUYvUfj3SSTlfrMJ4gFbqYP18kkhCx85zmq9PDJm SzE6EpqhiEq/l8l2eu8MIcrNeIuH98si3sIqRaWiC1Vsatq6ZS3oD8V9utj7JhK3u9vr Iu4Q== 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=dqfVD44TkK3usd1mQweHKY2fltJlJNKQWu+x3+YLrx8=; b=pdbVD9f4Y8V/9qsTfdEjZrP14/cpLlvsAh9SDCSXcOozEHAfgZ4oi6vgZyTQOek3ts BmHL4M712QV7Oz8mLNS4eV7vqjFhbeaWcdhsjkR+OVwxiyp9X21ZE9HwX0zoILsXR58w 0WbE9XtcO9H3iMxbcY+b9VtgSmUoG3hffWgtqmUe4ArL5NevccAB3Vo76P7o6ogBZZ4F a+zv1FdpVCsqpWFSziGAER5zToECr8t3Y2OOGk6lG9rJ7Xg3j2P8UgzQPK9S8Z3RvaEH CR8FjkjRq+7hg7Km95mWMe1GnxSX1/5Db7DrKU4fGTpfsoNxZ5f5xMKEYHb8uX+NiDGk dl8g== X-Gm-Message-State: AOAM530iHrAYGau+cI0GzVo1+p0I++oYXvzrLecFg9CGkHi5M2qr1Lrf Xg4bVs6yh4NTpUbtPWEre5oVmQ== X-Received: by 2002:a92:d7ce:: with SMTP id g14mr5615815ilq.255.1614897279593; Thu, 04 Mar 2021 14:34:39 -0800 (PST) Received: from beast.localdomain (c-73-185-129-58.hsd1.mn.comcast.net. [73.185.129.58]) by smtp.gmail.com with ESMTPSA id s18sm399790ilt.9.2021.03.04.14.34.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Mar 2021 14:34:39 -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, elder@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next 5/6] net: qualcomm: rmnet: don't use C bit-fields in rmnet checksum trailer Date: Thu, 4 Mar 2021 16:34:30 -0600 Message-Id: <20210304223431.15045-6-elder@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210304223431.15045-1-elder@linaro.org> References: <20210304223431.15045-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 --- .../ethernet/qualcomm/rmnet/rmnet_map_data.c | 2 +- include/linux/if_rmnet.h | 17 +++++++---------- 2 files changed, 8 insertions(+), 11 deletions(-) -- 2.20.1 Reviewed-by: Bjorn Andersson diff --git a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c index 3291f252d81b0..29d485b868a65 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 (!u8_get_bits(csum_trailer->flags, MAP_CSUM_DL_VALID_FMASK)) { priv->stats.csum_valid_unset++; return -EINVAL; } diff --git a/include/linux/if_rmnet.h b/include/linux/if_rmnet.h index 4824c6328a82c..1fbb7531238b6 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_FMASK GENMASK(0, 0) + struct rmnet_map_ul_csum_header { __be16 csum_start_offset; #if defined(__LITTLE_ENDIAN_BITFIELD) From patchwork Thu Mar 4 22:34:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 392998 Delivered-To: patch@linaro.org Received: by 2002:a17:906:a383:0:0:0:0 with SMTP id k3csp6386280ejz; Thu, 4 Mar 2021 14:42:01 -0800 (PST) X-Google-Smtp-Source: ABdhPJwZRC50YZkSm0WSsMbyL/E447o6UPd5zrCeumwodqDTsUaMIcay1eHuZpoCCseVyQkFbcZI X-Received: by 2002:a17:906:acb:: with SMTP id z11mr6661218ejf.193.1614897721765; Thu, 04 Mar 2021 14:42:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614897721; cv=none; d=google.com; s=arc-20160816; b=bqfSAzJ8X3yaBqbH4Q6i3SkXQ2v0Uxj1UgtgeVWo1crnYayjrE7cYKQAGg1bJo5MfR eeV9joDAv6sVkZdwY7H4e0qbS9fMC891X4+ncQ/vYgs7Abs3KIvLUyTxIboErubwCgrV mtdYPlNcb4VkJMP3BWA4A+/KVxwlWK1cn8j2j1Ay/SWmW0zgQSalJNvWTxCWS28fI47D +D1tSxU7amFWsuLEbyqgv/ZD5KEWQMIt7cZ2kXzlAckVRdiL2yoGlZ3EUECTG0ZM1vHE DMZdA5q4aM64Z/X+WOxC9UCw+XuTI/Q9O9HU/J5O9q/UEJNydg/RZnmlI4xs0OaJg5b3 tdxA== 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=Na3YOPu455NEidL4GYMHGo2WvYfOyb52BffrIYZ622Y=; b=gKUgujszZQee0CzWD+EkVjxbWYkVa/JCgY5XceR45Fff4ETqMtjCtMBz6Vk+MPPeFe 8XgncyxFXVBZVAbR0hZGiQ48GJONQwLWingQuo0s1stgiYXyaio6T0zsB4Mv5dzJd6D3 kyuoKL/yODaq3Omrf+PWWSgczh1ZTvDO8MhldKu66T+UvZADhxv9oZI1G2T2LDxygKMG dm7gsruDv37/veH9vmxgRm6FKkkXHJKFI9M7nPQzg3vFhbWR/ipRG9o5NEVtbwZrw6YY dkmlNpaK01dA7lEgTLe2hyxYTRgEjbOZemGXzws1BKBpi57IlHNQLNoL0rp/5D9m4UMa xexQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZyB5GZTD; 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 k6si527757edj.545.2021.03.04.14.42.01; Thu, 04 Mar 2021 14:42:01 -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=ZyB5GZTD; 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 S232395AbhCDWey (ORCPT + 9 others); Thu, 4 Mar 2021 17:34:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55280 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232167AbhCDWel (ORCPT ); Thu, 4 Mar 2021 17:34:41 -0500 Received: from mail-il1-x135.google.com (mail-il1-x135.google.com [IPv6:2607:f8b0:4864:20::135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 41A3EC061760 for ; Thu, 4 Mar 2021 14:34:41 -0800 (PST) Received: by mail-il1-x135.google.com with SMTP id e7so178283ile.7 for ; Thu, 04 Mar 2021 14:34:41 -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=Na3YOPu455NEidL4GYMHGo2WvYfOyb52BffrIYZ622Y=; b=ZyB5GZTDiG+3RByDMmMK/RwfcwzbDLYwmGyxtFjwC82735NihIqpaFNHK9LL+SzfyH JmdwqrB3O6i2w8EyQPZyroWZyysI9spedyBP56xjlsw71kLc4h9hI//OjsCUstxWyE/n M/r9eOoWzBKVv5BUgeSjNnNzc077bEOX6IeP5jmCjI59avpqbjPwByo7awNti2j2lgQ7 d1GNzlFYAzj8XBTD8L2ObkOyBoCnjn7efquBTh8HIfaEn5AKeHsqQ8Khcky0SLPah7TW r9mx6VBSX9WEV8bNcwXYVvkLZ6pPqm9bwplN7YSkqeaU9uqmTDcCLnc2kmqfGDDJy9GT jxxQ== 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=Na3YOPu455NEidL4GYMHGo2WvYfOyb52BffrIYZ622Y=; b=eL0ycwzwaBe2O7NNYLL9QewcGVqv/dsBNqvQ6WzfVsQOcaANUGAgcGmhkpPYvKo8ZM ovJHr2giQvvmqlzzrBIyd80FBiEMSuF1zeTX2aSashzpnIs5OKoRn1S6deR6x/M/k5fg tuCRGECe8nRgxwchCpMhlgTXazrjdIF0MAHIUJdeZjwfFWLj65qykKYvjsr474XDeNLg hd3Y+4t6rnklXVeKuqssvUMArXJtl7+O5PZ6lu0MTp7bvfHoV6FNbQc8Kvb4tx5Au5Od s9Kk4yvNFPI9+E1+8/cvjUf9UEr/RKVsd8z5bm967tdpumNfKGm3YTTHmdOgu/9rCljZ 9apg== X-Gm-Message-State: AOAM532p6BzCHKQIbq/IhcjXCpHBh0rb8OD5IN5CB1phFVq9A1XLZFaq wCTwIsSApXYjTyz4yYZGmgbxjQ== X-Received: by 2002:a92:6b0f:: with SMTP id g15mr6207225ilc.144.1614897280619; Thu, 04 Mar 2021 14:34:40 -0800 (PST) Received: from beast.localdomain (c-73-185-129-58.hsd1.mn.comcast.net. [73.185.129.58]) by smtp.gmail.com with ESMTPSA id s18sm399790ilt.9.2021.03.04.14.34.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Mar 2021 14:34:40 -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, elder@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next 6/6] net: qualcomm: rmnet: don't use C bit-fields in rmnet checksum header Date: Thu, 4 Mar 2021 16:34:31 -0600 Message-Id: <20210304223431.15045-7-elder@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210304223431.15045-1-elder@linaro.org> References: <20210304223431.15045-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 field masks to encode or get values within it. Previously rmnet_map_ipv4_ul_csum_header() would update values in the host byte-order fields, and then forcibly fix their byte order using a combination of byte order 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 --- .../ethernet/qualcomm/rmnet/rmnet_map_data.c | 34 ++++++------------- include/linux/if_rmnet.h | 21 ++++++------ 2 files changed, 21 insertions(+), 34 deletions(-) -- 2.20.1 Reported-by: kernel test robot diff --git a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c index 29d485b868a65..db76bbf000aa1 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 = be16_encode_bits(1, MAP_CSUM_UL_ENABLED_FMASK); if (ip4h->protocol == IPPROTO_UDP) - ul_header->udp_ind = 1; - else - ul_header->udp_ind = 0; + val |= be16_encode_bits(1, MAP_CSUM_UL_UDP_FMASK); + val |= be16_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 = be16_encode_bits(1, MAP_CSUM_UL_ENABLED_FMASK); if (ip6h->nexthdr == IPPROTO_UDP) - ul_header->udp_ind = 1; - else - ul_header->udp_ind = 0; + val |= be16_encode_bits(1, MAP_CSUM_UL_UDP_FMASK); + val |= be16_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 1fbb7531238b6..149d696feb520 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: + * ENABLED: 1 = checksum computation requested + * UDP: 1 = UDP checksum (zero checkum means no checksum) + * OFFSET: where (offset in bytes) to insert computed checksum + */ +#define MAP_CSUM_UL_OFFSET_FMASK GENMASK(13, 0) +#define MAP_CSUM_UL_UDP_FMASK GENMASK(14, 14) +#define MAP_CSUM_UL_ENABLED_FMASK GENMASK(15, 15) + #endif /* !(_LINUX_IF_RMNET_H_) */