From patchwork Mon Mar 15 18:49:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 12140453 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,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 1AC45C433E0 for ; Mon, 15 Mar 2021 18:50:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 47F4064F4D for ; Mon, 15 Mar 2021 18:50:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232306AbhCOSuB (ORCPT ); Mon, 15 Mar 2021 14:50:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231338AbhCOSte (ORCPT ); Mon, 15 Mar 2021 14:49:34 -0400 Received: from mail-il1-x12a.google.com (mail-il1-x12a.google.com [IPv6:2607:f8b0:4864:20::12a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F0FCC06174A for ; Mon, 15 Mar 2021 11:49:34 -0700 (PDT) Received: by mail-il1-x12a.google.com with SMTP id r7so10394711ilb.0 for ; Mon, 15 Mar 2021 11:49:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=tkE3LmGUj01YPH3BPs1/nEBfeLQdWBdBqpXnFwRgcR4=; b=bom4lMmQJrp5VcTVXyEm9MMJ4NeJCRL6bqdHhGXRV8mep6rnDF0QdfZZzpn1mM50H6 qvHHmBXE2mqaHSkdqifKS546EMOYBAnUJ5FhxHltL83Pdxc5JCc4ZUiIFrxjZNQeQ5bV Okf91VbuTCBZJ6I4UYIxfXiwnzNKEfNANWfqyKPqkk1ZaDlOHyfibNOZBNFIcDjjQyTE qtTU/ERepKCjDksL8h+aY++zNqwez/tAA1gpPrf09QeUe08+i+ryBizTgRUUSBnQVqoD nkP3sOy/HYJ4nzBS01d7XTLT+SqI0ubN7ayRTRPjYdv02YaufxlII17g5KoZztlN2IHG M3Sw== 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=tkE3LmGUj01YPH3BPs1/nEBfeLQdWBdBqpXnFwRgcR4=; b=Fy1C1ghBjS0UIpylXNyW8xFavgHieKlTnEYrdzPMhFlWFg8G2DvdofeaiTabouWWcU ZfAvDLFxnrk9019X5oBjXIBUbCEhZVrj4wW6AJOqq54RlkRalPVhszLQyYaPwUOoGvNx DFEi2lsWHefwb9oTIqg/cXCf2m19gQxRm5vEXx+I5BNezUj94VQ4Y++Invq97aVSmesE 2Bm3u0JGrFOo9T9HBUrf0Yuw65E6l1hzTHRD1SGk5Q67Kruy4CtlGbf6YYVkiIF2PTsT NaG5gCAO3yxpiuc6ZQs9Kb6DjX9maY93uZySvBGpLiZoEZsDQq5qcglAH/tqfgvywF3r w1qA== X-Gm-Message-State: AOAM532gQs76qYB8guWslXUOZIkkVORqSj5akJLi2hvXmLQVbFuOuXMi YIIiSx79SXh4gDoAVkqa5fb4/A== X-Google-Smtp-Source: ABdhPJxoEqSlw3wLBbuIXMxokGl4pSHO7F63WKkv8o6e2lAwtEG+kIowll9PL/c1tM70omcDWEfwMQ== X-Received: by 2002:a05:6e02:ee1:: with SMTP id j1mr765610ilk.179.1615834173956; Mon, 15 Mar 2021 11:49:33 -0700 (PDT) Received: from localhost.localdomain (c-73-185-129-58.hsd1.mn.comcast.net. [73.185.129.58]) by smtp.gmail.com with ESMTPSA id a5sm8212162ilk.14.2021.03.15.11.49.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Mar 2021 11:49:33 -0700 (PDT) From: Alex Elder To: subashab@codeaurora.org, stranche@codeaurora.org, davem@davemloft.net, kuba@kernel.org Cc: sharathv@codeaurora.org, bjorn.andersson@linaro.org, evgreen@chromium.org, cpratapa@codeaurora.org, David.Laight@ACULAB.COM, olteanv@gmail.com, alexander.duyck@gmail.com, elder@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Alexander Duyck Subject: [PATCH net-next v5 1/6] net: qualcomm: rmnet: mark trailer field endianness Date: Mon, 15 Mar 2021 13:49:23 -0500 Message-Id: <20210315184928.2913264-2-elder@linaro.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210315184928.2913264-1-elder@linaro.org> References: <20210315184928.2913264-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 Reviewed-by: Alexander Duyck --- 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 Mon Mar 15 18:49:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 12140455 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,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 22B33C43381 for ; Mon, 15 Mar 2021 18:50:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6C67F64F5D for ; Mon, 15 Mar 2021 18:50:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232506AbhCOSuE (ORCPT ); Mon, 15 Mar 2021 14:50:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51642 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231748AbhCOStf (ORCPT ); Mon, 15 Mar 2021 14:49:35 -0400 Received: from mail-il1-x12e.google.com (mail-il1-x12e.google.com [IPv6:2607:f8b0:4864:20::12e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7B5FBC06175F for ; Mon, 15 Mar 2021 11:49:35 -0700 (PDT) Received: by mail-il1-x12e.google.com with SMTP id d5so10362528iln.6 for ; Mon, 15 Mar 2021 11:49:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=dYz46nd8LxGdX7fvsu6maJR2XM9zulyZ7ppS5hOn0SA=; b=GLM4k0nd1Bu2JQTPV+3Is3ZBwQmMUM7EL0g1eCcX6kCEdhQXfspaPcdrW33QxPxq0R JjqeSAczLiFgq/GqqoJ6h5ln4ltkVAcjlUB4MEXzsgcEGTdRcWLacL0GfVwXzWcA8+F6 1MtBnCWBA7T7CcSvNxExnyHGIdDoeAnPM7/fH68BEt/rCkb5Ov4PqqvqXQ7YZop/cIu4 MpO+nADtMdw6KXaBuHrLAPj9e/ElyDiJ7rUKza7A7wrnIDW0zH9bBBcRpMl52uKNu/nL p9eblUJUamUe88VQ7yhdd8edLin4o78kGFPSwYg7ZDki6ekXG6YiofNCC8xES0L5T2Ft gI9Q== 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=dYz46nd8LxGdX7fvsu6maJR2XM9zulyZ7ppS5hOn0SA=; b=hYpoivSxQPcmQt0BzNAp6f6fBEhI5OXB5gM0Z6I1g7Y7m5/Q5DIKSbQHRYJPJ4UAPk 0AwZME3HA9VPB66EFVOVWMuzwmZWTKd0DxiPthA8pN8guopWb+6ICOXXW+hW+u6m2w/G jbgrRXnALfn7ilcHZN23XZwF33Jrt77/DaU9ZkOK/2DkHY4d9Lep2iwUE3oMN9TWD+Yi yFtUMo9QB4t90lXxzX9JjT7DD00LD05CanIqqBq4JexZZS8r5IzBGw26Qq8h8Bucrn9U 9quDBokZgo+L32Ok7KnyAhHVKLAb7gSG3kbQrazJOUo4EFFMLjHEIhx+k1sHWdKnk5dT BXHQ== X-Gm-Message-State: AOAM53252bFwh5jzU7mFZ9ijazlIKkEJnkFcxLpib2kajtdNe4iqH9YK exrNhWRwfGggZfTQcNyZZgJL5w== X-Google-Smtp-Source: ABdhPJx0hxpr5Y6mZtZjZC1KpeigrU/YIn+UsMpYP8286jLLiUZisiW1Nn1i5s8cwkVgvVewqInmpg== X-Received: by 2002:a92:c24a:: with SMTP id k10mr794970ilo.284.1615834174989; Mon, 15 Mar 2021 11:49:34 -0700 (PDT) Received: from localhost.localdomain (c-73-185-129-58.hsd1.mn.comcast.net. [73.185.129.58]) by smtp.gmail.com with ESMTPSA id a5sm8212162ilk.14.2021.03.15.11.49.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Mar 2021 11:49:34 -0700 (PDT) From: Alex Elder To: subashab@codeaurora.org, stranche@codeaurora.org, davem@davemloft.net, kuba@kernel.org Cc: sharathv@codeaurora.org, bjorn.andersson@linaro.org, evgreen@chromium.org, cpratapa@codeaurora.org, David.Laight@ACULAB.COM, olteanv@gmail.com, alexander.duyck@gmail.com, elder@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v5 2/6] net: qualcomm: rmnet: simplify some byte order logic Date: Mon, 15 Mar 2021 13:49:24 -0500 Message-Id: <20210315184928.2913264-3-elder@linaro.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210315184928.2913264-1-elder@linaro.org> References: <20210315184928.2913264-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 --- v5: - Use skb_network_header_len() to decide the checksum offset. .../net/ethernet/qualcomm/rmnet/rmnet_map_data.c | 16 ++++++---------- 1 file changed, 6 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..0bfe69698b278 100644 --- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c +++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c @@ -197,12 +197,10 @@ 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; - offset = htons((__force u16)(skb_transport_header(skb) - - (unsigned char *)iphdr)); - ul_header->csum_start_offset = offset; + ul_header->csum_start_offset = htons(skb_network_header_len(skb)); ul_header->csum_insert_offset = skb->csum_offset; ul_header->csum_enabled = 1; if (ip4h->protocol == IPPROTO_UDP) @@ -239,12 +237,10 @@ 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; - offset = htons((__force u16)(skb_transport_header(skb) - - (unsigned char *)ip6hdr)); - ul_header->csum_start_offset = offset; + ul_header->csum_start_offset = htons(skb_network_header_len(skb)); ul_header->csum_insert_offset = skb->csum_offset; ul_header->csum_enabled = 1; From patchwork Mon Mar 15 18:49:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 12140461 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,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 5E1FDC43332 for ; Mon, 15 Mar 2021 18:50:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AA3D564F5E for ; Mon, 15 Mar 2021 18:50:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232577AbhCOSuG (ORCPT ); Mon, 15 Mar 2021 14:50:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51650 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231891AbhCOSth (ORCPT ); Mon, 15 Mar 2021 14:49:37 -0400 Received: from mail-il1-x12c.google.com (mail-il1-x12c.google.com [IPv6:2607:f8b0:4864:20::12c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 974A1C06174A for ; Mon, 15 Mar 2021 11:49:36 -0700 (PDT) Received: by mail-il1-x12c.google.com with SMTP id i18so10308060ilq.13 for ; Mon, 15 Mar 2021 11:49:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rVEslqQM6fsvVZ7LiAEkE3ccCznmfly+zx9t6yJZNsM=; b=yUDI23OYNIhkInkPACeIRm6oTCYvArJ1DWfEBHdqn9lrVkf1BiRmV7avyO3i2MeQhk 6VbDct0tvBlipbjt1Mb+YJmVvRm/Xdc4RkQ7bYEuzFQB+Ythiwb7jPsYpeBjE64Akgwi NjPrfcZbVhbjaqKLIq1GUxQ/dzqoQZUi6/6sXBN3nPIMUTX1sjEsQ/EQsQTenN//7BEp WFXK+P6iO5qkw5GDh2nTDlXu+BRssJ3kHLLn6Rgl6t2lH5mP0e71cpHq9ElkAHJiPHa4 5pbSsL73kLDgOgZiFBBNsVW3bllt+atlZUV9Glhlfw+8gwcyqojK6/UXRGzPGjZhWPY3 S8UA== 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=rVEslqQM6fsvVZ7LiAEkE3ccCznmfly+zx9t6yJZNsM=; b=PfXHs6NdRsi9jztJ2JFkeWZ3lLJIfw6Ux/jdUHXmztPy576BR1AxpPvUh+QlTaQRRk tRZExXB8kMS6gg7LQGrOvO3sAHjxNRT8XlnjiwgciZdgNtkVm6f8TWnNdS5pnJesZ8Ec cGpmhXi3JhmT2UMZNgBvVU/4UaMH8c2CXRI+bDvsav/II29EaFk/empjHC0OMm4Xm1bW QzQ/dVeZnmrYNH4/+KPn9z0XMs5MvBoA3ev7cU9CMpdT4bq+futekb+h/Se6ByliApFH gY1rE3PJ6u/JXe0/W4IWsN2LJ29lGbfxOGnQKrvDbVGjV0JfzSXXUgrtucJsZxK2KLxH +dJQ== X-Gm-Message-State: AOAM532M1KN4SsGKvsR/GHAL24U0BGhSrgmfwVoTnWFqOH9ZGDJXWWZA 5+Ffokp6zZ5LFL0r81J8x2w9Sg== X-Google-Smtp-Source: ABdhPJyCUOJv2Ejai6mGChKuXaCD5Bjl1V/vyrtQ7q9TVPlXgUa+asn3dRI6VmUuFZcgdIMnUJ6FYQ== X-Received: by 2002:a92:d909:: with SMTP id s9mr858869iln.120.1615834176027; Mon, 15 Mar 2021 11:49:36 -0700 (PDT) Received: from localhost.localdomain (c-73-185-129-58.hsd1.mn.comcast.net. [73.185.129.58]) by smtp.gmail.com with ESMTPSA id a5sm8212162ilk.14.2021.03.15.11.49.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Mar 2021 11:49:35 -0700 (PDT) From: Alex Elder To: subashab@codeaurora.org, stranche@codeaurora.org, davem@davemloft.net, kuba@kernel.org Cc: sharathv@codeaurora.org, bjorn.andersson@linaro.org, evgreen@chromium.org, cpratapa@codeaurora.org, David.Laight@ACULAB.COM, olteanv@gmail.com, alexander.duyck@gmail.com, elder@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Alexander Duyck Subject: [PATCH net-next v5 3/6] net: qualcomm: rmnet: kill RMNET_MAP_GET_*() accessor macros Date: Mon, 15 Mar 2021 13:49:25 -0500 Message-Id: <20210315184928.2913264-4-elder@linaro.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210315184928.2913264-1-elder@linaro.org> References: <20210315184928.2913264-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 Reviewed-by: Alexander Duyck --- 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 0bfe69698b278..3af68368fc315 100644 --- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c +++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c @@ -315,7 +315,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); @@ -324,7 +324,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 Mon Mar 15 18:49: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: 12140463 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,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 5CB39C4332D for ; Mon, 15 Mar 2021 18:50:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9617464F50 for ; Mon, 15 Mar 2021 18:50:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232137AbhCOSuF (ORCPT ); Mon, 15 Mar 2021 14:50:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51654 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231964AbhCOSth (ORCPT ); Mon, 15 Mar 2021 14:49:37 -0400 Received: from mail-io1-xd29.google.com (mail-io1-xd29.google.com [IPv6:2607:f8b0:4864:20::d29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9BF8FC06174A for ; Mon, 15 Mar 2021 11:49:37 -0700 (PDT) Received: by mail-io1-xd29.google.com with SMTP id f20so34480638ioo.10 for ; Mon, 15 Mar 2021 11:49:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Gzfg71vsx3VY2377GfG2oAcRHO8kBLm5otxChzsZJP0=; b=siTp/EcDCURtedClVwE0kYOM6IqyOaIr3aFJkBce7eWylsrNmhEKOD3/4orkrGH+KA gouAetKh8XjyZMjjGsi3NJd//K7wllrCij7gdrwhVFw/RdkUcmRPoJhQGevQ2Tyqnjb8 Uqxs+YSfV30PLd79wJuG+1LGhamiOG8GbwaRpUYZ2soEx3mPg9YgAveJ8sW9SCy9iyaX r284yDsdz1/3XTn6Mdq2B3vW6WYy/Fkj+ZFApRNcOdHXKqPprY16AqxKF8hoH2BDVb2g /ru7FuQjI63zbgzbe8ylg0qD46nIoNWcgRr07mnGLRe8Eq/uNeDykuo+czdPX/IwJ9Jn PHGQ== 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=Gzfg71vsx3VY2377GfG2oAcRHO8kBLm5otxChzsZJP0=; b=Yn9Zhmb5aOkQ05iZDNFhV1yOBga/a+G5Ju6obAgBzKC1Or43tuZuN7IDlyHqdVPvSy wT4HIGB/Lnfl5TdH4tsuCmQzaolbh6I4qCkH0fC9U7Cyc511c0b7H0KMl9I/CAE7tCtA +YnbMW/ebuPhyeiKukpF/cI7MHz52CBj82kxGigrK+H1hzvlA8awiKBT/xin+pdn/6yR k5T8eiWLRgmXsHXzhvRL3kMlUiDVOEb6uIiURKfekb3zfqGkujlq8NhvJ2ShUWcX8iNx bvTP0yQSghlR3WTNETk+do4skDPvE+kHbfmJORaIXiQeOi5g/GR5CbhkShCqS0TwSr2H +0uw== X-Gm-Message-State: AOAM530py+CkbSSUAOkV91ENM1k4YHrBuopebym2JKsf5t7ZELoNU8Ly XMmzMMXvOqF/Z4yJFlCxrwRc0g== X-Google-Smtp-Source: ABdhPJxONwwqPMDVaCTJ93gvqndXgfXB6DE1FDfsQEyu+0q7fsmp7DXwUvlTKXVop/rVk8st+LJrNg== X-Received: by 2002:a02:94a9:: with SMTP id x38mr10824603jah.50.1615834177131; Mon, 15 Mar 2021 11:49:37 -0700 (PDT) Received: from localhost.localdomain (c-73-185-129-58.hsd1.mn.comcast.net. [73.185.129.58]) by smtp.gmail.com with ESMTPSA id a5sm8212162ilk.14.2021.03.15.11.49.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Mar 2021 11:49:36 -0700 (PDT) From: Alex Elder To: subashab@codeaurora.org, stranche@codeaurora.org, davem@davemloft.net, kuba@kernel.org Cc: sharathv@codeaurora.org, bjorn.andersson@linaro.org, evgreen@chromium.org, cpratapa@codeaurora.org, David.Laight@ACULAB.COM, olteanv@gmail.com, alexander.duyck@gmail.com, elder@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Alexander Duyck Subject: [PATCH net-next v5 4/6] net: qualcomm: rmnet: use masks instead of C bit-fields Date: Mon, 15 Mar 2021 13:49:26 -0500 Message-Id: <20210315184928.2913264-5-elder@linaro.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210315184928.2913264-1-elder@linaro.org> References: <20210315184928.2913264-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, and define a single-byte flags field instead. Define a mask for the single-bit "command" flag, and another mask for the encoded pad length. The content of both fields can be accessed using a simple bitwise AND operation. Signed-off-by: Alex Elder Reviewed-by: Bjorn Andersson Reviewed-by: Alexander Duyck --- v4: - Don't use u8_get_bits() to access the pad length - Added BUILD_BUG_ON() to ensure field width is adequate v3: - Use BIT(x) and don't use u8_get_bits() for the command flag .../ethernet/qualcomm/rmnet/rmnet_handlers.c | 4 ++-- .../ethernet/qualcomm/rmnet/rmnet_map_data.c | 4 +++- include/linux/if_rmnet.h | 23 ++++++++----------- 3 files changed, 15 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..0be5ac7ab2617 100644 --- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c +++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c @@ -61,7 +61,7 @@ __rmnet_map_ingress_handler(struct sk_buff *skb, u16 len, pad; u8 mux_id; - if (map_header->cd_bit) { + if (map_header->flags & MAP_CMD_FLAG) { /* Packet contains a MAP command (not data) */ if (port->data_format & RMNET_FLAGS_INGRESS_MAP_COMMANDS) return rmnet_map_command(skb, port); @@ -70,7 +70,7 @@ __rmnet_map_ingress_handler(struct sk_buff *skb, } mux_id = map_header->mux_id; - pad = map_header->pad_len; + pad = map_header->flags & MAP_PAD_LEN_MASK; 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 3af68368fc315..e7d0394cb2979 100644 --- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c +++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c @@ -280,6 +280,7 @@ struct rmnet_map_header *rmnet_map_add_map_header(struct sk_buff *skb, return map_header; } + BUILD_BUG_ON(MAP_PAD_LEN_MASK < 3); padding = ALIGN(map_datalen, 4) - map_datalen; if (padding == 0) @@ -293,7 +294,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 = padding & MAP_PAD_LEN_MASK; return map_header; } diff --git a/include/linux/if_rmnet.h b/include/linux/if_rmnet.h index 8c7845baf3837..a02f0a3df1d9a 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_CMD_FLAG, MAP_PAD_LEN_MASK */ + u8 mux_id; + __be16 pkt_len; /* Length of packet, including pad */ } __aligned(1); +/* rmnet_map_header flags field: + * PAD_LEN: number of pad bytes following packet data + * CMD: 1 = packet contains a MAP command; 0 = packet contains data + */ +#define MAP_PAD_LEN_MASK GENMASK(5, 0) +#define MAP_CMD_FLAG BIT(7) + struct rmnet_map_dl_csum_trailer { u8 reserved1; #if defined(__LITTLE_ENDIAN_BITFIELD) From patchwork Mon Mar 15 18:49: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: 12140459 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,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 58BC5C4332E for ; Mon, 15 Mar 2021 18:50:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 367AA64F92 for ; Mon, 15 Mar 2021 18:50:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232621AbhCOSuH (ORCPT ); Mon, 15 Mar 2021 14:50:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51666 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231328AbhCOStj (ORCPT ); Mon, 15 Mar 2021 14:49:39 -0400 Received: from mail-io1-xd29.google.com (mail-io1-xd29.google.com [IPv6:2607:f8b0:4864:20::d29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AFC76C06174A for ; Mon, 15 Mar 2021 11:49:38 -0700 (PDT) Received: by mail-io1-xd29.google.com with SMTP id o11so34591962iob.1 for ; Mon, 15 Mar 2021 11:49:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jKWpv2lC6idRAW4U2uy3fxWpPmNFe54usond8BqeY/A=; b=GshvCtSdibj2Ffh/vsYup4grJLYSBDrLhGFzj8q7C2rsrUWkzrGgiNA/JGfpzuREt/ +z30ti8N7gKvy/Ar8+Czba+I3X+RoeQtsJYT7GJQIKeb1MydifhTy5ZTtsAuNc7r+UoT ZkDrpwaBP0iVnYaB8JN6rZRZp+5hCBEYLbELrGnAMTcSIhvgYxU7qkqOQ1v4e0T5cY3E MatXOqMHnSaW+uDQjC8vERY5EuhIwT7ofjB1lOc2wqydqRXkViOBkc+PWS+ONVV/Mujh oHxWj0CyOhdFojKrY2dH6VbuHJFna0BSyUxyB7ul92IbWm513OMqrkoqJ2HpMrOgxA9G nTlA== 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=jKWpv2lC6idRAW4U2uy3fxWpPmNFe54usond8BqeY/A=; b=ZpkUh8mvw+1LIoq1ZwOF3nlVJP4r9sZtCOFimeM9RI8ZtXFNslnSAAigbMdr2B7WJd na+MahBQmoz26jfMlip9bHVd5LvNp15XnETKrxb1NSGAlBSBaGcZRgTU8EjUByPthyzw 4J4ge693RfITp66J4iiboy79PLlJFGKlqIOKYZ2xbxq53njQZuMOrSLfvpeWKjwWMEAo V8YZsZh3OsfPrwzuV8yfvh/zqHVfcSynvKfSXNOHyZbooaHGD8gkwJIr23Or+yt27Vhx xMjU/znXew6m+EeZIUYfxEXxuTP90GwAfVwx4dWlZUA5HheFDdxiLoRIl96UCT1jKLut xPbw== X-Gm-Message-State: AOAM531MU2E2O+ZYD+nF8DcRhxPRnugZXS6aSBRvG3XdkgCYYlEE5wRk hRtmdhmWNxttNPCu+iMZBj5FKg== X-Google-Smtp-Source: ABdhPJx75Z0hNEPSA2mIGdL/bS4OvWvLxRiLo4nVeh0ZU4azGr2SFrGanXb1A3JmMIbhjh8iC6edrA== X-Received: by 2002:a5e:cb4c:: with SMTP id h12mr668803iok.183.1615834178223; Mon, 15 Mar 2021 11:49:38 -0700 (PDT) Received: from localhost.localdomain (c-73-185-129-58.hsd1.mn.comcast.net. [73.185.129.58]) by smtp.gmail.com with ESMTPSA id a5sm8212162ilk.14.2021.03.15.11.49.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Mar 2021 11:49:37 -0700 (PDT) From: Alex Elder To: subashab@codeaurora.org, stranche@codeaurora.org, davem@davemloft.net, kuba@kernel.org Cc: sharathv@codeaurora.org, bjorn.andersson@linaro.org, evgreen@chromium.org, cpratapa@codeaurora.org, David.Laight@ACULAB.COM, olteanv@gmail.com, alexander.duyck@gmail.com, elder@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Alexander Duyck Subject: [PATCH net-next v5 5/6] net: qualcomm: rmnet: don't use C bit-fields in rmnet checksum trailer Date: Mon, 15 Mar 2021 13:49:27 -0500 Message-Id: <20210315184928.2913264-6-elder@linaro.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210315184928.2913264-1-elder@linaro.org> References: <20210315184928.2913264-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 Reviewed-by: Alexander Duyck --- v3: - Use BIT(x) and don't use u8_get_bits() for the checksum valid flag .../ethernet/qualcomm/rmnet/rmnet_map_data.c | 2 +- include/linux/if_rmnet.h | 17 +++++++---------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c index e7d0394cb2979..c336c17e01fe4 100644 --- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c +++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c @@ -359,7 +359,7 @@ int rmnet_map_checksum_downlink_packet(struct sk_buff *skb, u16 len) csum_trailer = (struct rmnet_map_dl_csum_trailer *)(skb->data + len); - if (!csum_trailer->valid) { + if (!(csum_trailer->flags & MAP_CSUM_DL_VALID_FLAG)) { priv->stats.csum_valid_unset++; return -EINVAL; } diff --git a/include/linux/if_rmnet.h b/include/linux/if_rmnet.h index a02f0a3df1d9a..941997df9e088 100644 --- a/include/linux/if_rmnet.h +++ b/include/linux/if_rmnet.h @@ -19,21 +19,18 @@ struct rmnet_map_header { #define MAP_CMD_FLAG BIT(7) 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_VALID_FLAG */ __be16 csum_start_offset; __be16 csum_length; __be16 csum_value; } __aligned(1); +/* rmnet_map_dl_csum_trailer flags field: + * VALID: 1 = checksum and length valid; 0 = ignore them + */ +#define MAP_CSUM_DL_VALID_FLAG BIT(0) + struct rmnet_map_ul_csum_header { __be16 csum_start_offset; #if defined(__LITTLE_ENDIAN_BITFIELD) From patchwork Mon Mar 15 18:49: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: 12140465 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,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 624E9C43333 for ; Mon, 15 Mar 2021 18:50:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0B7C464F64 for ; Mon, 15 Mar 2021 18:50:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232707AbhCOSuI (ORCPT ); Mon, 15 Mar 2021 14:50:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51676 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232160AbhCOStk (ORCPT ); Mon, 15 Mar 2021 14:49:40 -0400 Received: from mail-io1-xd31.google.com (mail-io1-xd31.google.com [IPv6:2607:f8b0:4864:20::d31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CBB4BC061763 for ; Mon, 15 Mar 2021 11:49:39 -0700 (PDT) Received: by mail-io1-xd31.google.com with SMTP id 81so34501050iou.11 for ; Mon, 15 Mar 2021 11:49:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PXbxDLQ5qzFahsfuQdQd2/oh6y0N5sQbqIGCA/JCZcI=; b=gcxva2A+i8wAZZUM0MJqS4HJtjOcnfep/osbYXHElsJUPfyLqq0LlOqZ7yxTsu/U3O X3qDUjpfYAtFVvZqW7hNgCnTx1XtIxQ2F9oqTNQQWvbRcuE92jdH9P7l1KbMMW9Mcobk 2s6+byeIDyItyjgCkC58xd0YiK8pamcDf+UI19fkAtf09oJmr14pittbE6f3rK4pqRWZ 3WkBcebWEJyAaztFyLqphCYnRzp7ww9Rt9C7KtwNbsU+gujsQkLQ84odRpnFum6cLmBD nECtX0a17koHvS55m3nsYoqDQjibk+kUMFmdjEgGXY7eDaeGq5NFdHHDvnPayOQvR7Zg dI3A== 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=PXbxDLQ5qzFahsfuQdQd2/oh6y0N5sQbqIGCA/JCZcI=; b=UEVpTEnJGv+YpAX7bthSq7u5P0qOmaVnXQCaB9dddLofnI2Lcs8cUeE/Kx7eNaE1RF CSC/48+NBevUhySJ+yS+/lYvfA1W9VY/qBNpaZyG+dRSZcI7DCYDTSg4QCX8+7+SgHxO QmUqKWiVtHmlNs7FwvfX5MOTRFihgwS/7aetIS9D78Tll+1EzfZc9Gq/e5k3NmnyRfWE Tz24BiDWHuACgiibWFLYxsLpdA7fIhbNJ/kPaqUDvvtZ1gx6+yq9DyypV2tjl5Ye6dI8 XM3b2UXKltLS1bik9Oem4KvcQDopUOinink6ZltmiXpurj8LXeQjSG0p4EeEvL3GQKpi VjWA== X-Gm-Message-State: AOAM533Dw+Tr34JKXaLpAbDEJoOwEYjPC25fQZ1I/AICj8ipWhVLkrFi jbWxq9H367nXPqPcXGq6yNtI2Q== X-Google-Smtp-Source: ABdhPJzG2lwjHlnTmgu1x/TXnXdNoT1TErE7Cvq+6JDSdEhCn+dELPNR/j8apYR0iz7HPsxaL6KizQ== X-Received: by 2002:a5d:9bc8:: with SMTP id d8mr680632ion.115.1615834179259; Mon, 15 Mar 2021 11:49:39 -0700 (PDT) Received: from localhost.localdomain (c-73-185-129-58.hsd1.mn.comcast.net. [73.185.129.58]) by smtp.gmail.com with ESMTPSA id a5sm8212162ilk.14.2021.03.15.11.49.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Mar 2021 11:49:38 -0700 (PDT) From: Alex Elder To: subashab@codeaurora.org, stranche@codeaurora.org, davem@davemloft.net, kuba@kernel.org Cc: sharathv@codeaurora.org, bjorn.andersson@linaro.org, evgreen@chromium.org, cpratapa@codeaurora.org, David.Laight@ACULAB.COM, olteanv@gmail.com, alexander.duyck@gmail.com, elder@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Alexander Duyck Subject: [PATCH net-next v5 6/6] net: qualcomm: rmnet: don't use C bit-fields in rmnet checksum header Date: Mon, 15 Mar 2021 13:49:28 -0500 Message-Id: <20210315184928.2913264-7-elder@linaro.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210315184928.2913264-1-elder@linaro.org> References: <20210315184928.2913264-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 masks to encode or get values within it. The content of these fields can be accessed using simple bitwise AND and OR operations on the (host byte order) value of the new structure member. Previously rmnet_map_ipv4_ul_csum_header() would update C bit-field values in host byte order, then forcibly fix their byte order using a combination of byte swap operations and types. Instead, just compute the value that needs to go into the new structure member and save it with a simple byte-order conversion. Make similar simplifications in rmnet_map_ipv6_ul_csum_header(). Finally, in rmnet_map_checksum_uplink_packet() a set of assignments zeroes every field in the upload checksum header. Replace that with a single memset() operation. Signed-off-by: Alex Elder Reviewed-by: Alexander Duyck --- v5: - Assign checksum start offset a little later (with csum_info) v4: - Don't use u16_get_bits() to access the checksum field offset v3: - Use BIT(x) and don't use u16_get_bits() for single-bit flags v2: - Fixed to use u16_encode_bits() instead of be16_encode_bits() .../ethernet/qualcomm/rmnet/rmnet_map_data.c | 38 +++++++------------ include/linux/if_rmnet.h | 21 +++++----- 2 files changed, 23 insertions(+), 36 deletions(-) iff --git a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c ndex c336c17e01fe4..0ac2ff828320c 100644 -- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c ++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c @ -197,20 +197,16 @@ 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 val; ul_header->csum_start_offset = htons(skb_network_header_len(skb)); ul_header->csum_insert_offset = skb->csum_offset; ul_header->csum_enabled = 1; val = MAP_CSUM_UL_ENABLED_FLAG; if (ip4h->protocol == IPPROTO_UDP) ul_header->udp_ind = 1; else ul_header->udp_ind = 0; val |= MAP_CSUM_UL_UDP_FLAG; val |= skb->csum_offset & MAP_CSUM_UL_OFFSET_MASK; - /* Changing remaining fields to network order */ - hdr++; - *hdr = htons((__force u16)*hdr); + ul_header->csum_start_offset = htons(skb_network_header_len(skb)); + ul_header->csum_info = htons(val); skb->ip_summed = CHECKSUM_NONE; @@ -237,21 +233,16 @@ 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 val; - ul_header->csum_start_offset = htons(skb_network_header_len(skb)); - ul_header->csum_insert_offset = skb->csum_offset; - ul_header->csum_enabled = 1; - + val = MAP_CSUM_UL_ENABLED_FLAG; if (ip6h->nexthdr == IPPROTO_UDP) - ul_header->udp_ind = 1; - else - ul_header->udp_ind = 0; + val |= MAP_CSUM_UL_UDP_FLAG; + val |= skb->csum_offset & MAP_CSUM_UL_OFFSET_MASK; - /* Changing remaining fields to network order */ - hdr++; - *hdr = htons((__force u16)*hdr); + ul_header->csum_start_offset = htons(skb_network_header_len(skb)); + ul_header->csum_info = htons(val); skb->ip_summed = CHECKSUM_NONE; @@ -419,10 +410,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 941997df9e088..4efb537f57f31 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_* */ } __aligned(1); +/* csum_info field: + * OFFSET: where (offset in bytes) to insert computed checksum + * UDP: 1 = UDP checksum (zero checkum means no checksum) + * ENABLED: 1 = checksum computation requested + */ +#define MAP_CSUM_UL_OFFSET_MASK GENMASK(13, 0) +#define MAP_CSUM_UL_UDP_FLAG BIT(14) +#define MAP_CSUM_UL_ENABLED_FLAG BIT(15) + #endif /* !(_LINUX_IF_RMNET_H_) */