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: 12117057 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 13B8BC433E6 for ; Thu, 4 Mar 2021 22:34:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D546F64FF9 for ; Thu, 4 Mar 2021 22:34:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232103AbhCDWei (ORCPT ); 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-Google-Smtp-Source: ABdhPJyOuAllyWI83JlkOXfAOW+sismtvbKPbE64ScfusGgJtXSVH+IaVKCW/C19UJj5cMAbXCzIWw== 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 X-Patchwork-Delegate: kuba@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(-) 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: 12117065 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 988E8C433E6 for ; Thu, 4 Mar 2021 22:34:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5FEEF64FEA for ; Thu, 4 Mar 2021 22:34:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232357AbhCDWew (ORCPT ); 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-Google-Smtp-Source: ABdhPJzut91zOjLiXLXYscqglNiYbdwfO2+JCmzKwSIjNlkV5uZSdVWatK4i7w1EtS7S1EmfAfyREQ== 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 X-Patchwork-Delegate: kuba@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(-) 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: 12117061 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5B527C433E9 for ; Thu, 4 Mar 2021 22:34:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3668E65009 for ; Thu, 4 Mar 2021 22:34:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232256AbhCDWet (ORCPT ); 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-Google-Smtp-Source: ABdhPJwVggiyKsWbHMhtG9tNDmnYSbc7bwp2bYbvurm1Pays5Ynbvq5Emyj9vHDLE3SgBhHuhMXVRg== 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 X-Patchwork-Delegate: kuba@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(-) 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: 12117055 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6364CC433E0 for ; Thu, 4 Mar 2021 22:34:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3AD2A64FF9 for ; Thu, 4 Mar 2021 22:34:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232186AbhCDWem (ORCPT ); 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-Google-Smtp-Source: ABdhPJwagmJDSZpFApsu1HguKbDhqjP37QhqzMEeLfCvLX5Xl8wx8YuECoQYd/P0iLbmzCPcb2feVw== 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 X-Patchwork-Delegate: kuba@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 Reviewed-by: Bjorn Andersson --- .../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(-) 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: 12117063 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 979C5C433DB for ; Thu, 4 Mar 2021 22:34:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6621E64FF9 for ; Thu, 4 Mar 2021 22:34:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232295AbhCDWeu (ORCPT ); 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-Google-Smtp-Source: ABdhPJzILta4g3Xcf50Xt0zb78KJ5CcS3Xk8xZRItLD0SD1MaNv6iUHEC+CHXGhRahrq3j1EZLNWAA== 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 X-Patchwork-Delegate: kuba@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 --- .../ethernet/qualcomm/rmnet/rmnet_map_data.c | 2 +- include/linux/if_rmnet.h | 17 +++++++---------- 2 files changed, 8 insertions(+), 11 deletions(-) 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: 12117067 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D55F2C433E0 for ; Thu, 4 Mar 2021 22:34:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B1D0B64FEA for ; Thu, 4 Mar 2021 22:34:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232395AbhCDWey (ORCPT ); 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-Google-Smtp-Source: ABdhPJwnz2KTlbD2EqNS64HpAwknmXvxVVgKmRePmFKEcloLjS2OD2ZetDqhnsebxbBPtuV/dh55Sw== 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 X-Patchwork-Delegate: kuba@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 Reported-by: kernel test robot --- .../ethernet/qualcomm/rmnet/rmnet_map_data.c | 34 ++++++------------- include/linux/if_rmnet.h | 21 ++++++------ 2 files changed, 21 insertions(+), 34 deletions(-) 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_) */