From patchwork Sat Mar 6 03:15:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 394535 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp965458jai; Fri, 5 Mar 2021 19:17:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJxwCabqHSp3ZUu4Jm4Q0BKWQRcnS71tgYRurmft7NNGXaCHe1xApBa1hRewAMiiFknmV6n6 X-Received: by 2002:aa7:cf90:: with SMTP id z16mr12152307edx.273.1615000628551; Fri, 05 Mar 2021 19:17:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615000628; cv=none; d=google.com; s=arc-20160816; b=WFVO2wPVPrQ/HRYPVg1QpYJdJGfeU4zRvWUVCcaaBSMh9Gz6u8pcNkJc4NsBFqWT4S 3Cni8jHjCa5J7fKsh3tki+tJJEmm8f7IDx4UkN2rLYifRQgxT8JzPAY35f3nBs+VmyQm VLbMNbPS8Dh3+MsiYV9zqE0UVek8CyilyWC0dKwI3dvY4zihc6SYGiIc1WsWtCWokRkU +aNbyqQu3l0diYljNYFGUE71m/hG8ZdPbGybI688IYKxmE6ZDbHP5porvTPgZriMbIp5 5YWzububZ00rWaiqXGiTiYOiYUpTS4sIBKvbJ6L82nSZwTsPpHMpl8U9+9q39O+bWgzP 7f1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=siv8ALjvw5nAWM5oVnlAOXA/08MIyz7olXglWGx22ko=; b=r/4sbO58nfoVDX0XRum60AsTqb1GQAwR19ZJEXZqP+7eeOlb/7sLt/Jip1203pBh2L nH/RSZqhSoieP39WBiSnXUi8zeU/RMBZ6LX7wLh5/n3Nv5kaSAI+NnWW8Ah5Y05kpX6n uHm2lZGwgSDSn2HHSEjQOvtvk5EdduOjw8gQltEi9FA+B9qZiqXsJk3lLXG6HJSgydqZ igENifBLlYHuEMHk35uPSleLzQ/R1jyqc42PFCfa6Bw1yaapyiTaEIdOH0SsoqTPEtZK S58nzWWZwpggFyq0UTOifcF+a+ArTiJNVXT1P8SuInXIV05VWnIcV9tOk90musGBrblg JGRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VaG23pAj; 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 j7si2719448edh.201.2021.03.05.19.17.08; Fri, 05 Mar 2021 19:17:08 -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=VaG23pAj; 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 S230087AbhCFDQf (ORCPT + 9 others); Fri, 5 Mar 2021 22:16:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57688 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229749AbhCFDP7 (ORCPT ); Fri, 5 Mar 2021 22:15:59 -0500 Received: from mail-il1-x129.google.com (mail-il1-x129.google.com [IPv6:2607:f8b0:4864:20::129]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3CB4CC061762 for ; Fri, 5 Mar 2021 19:15:56 -0800 (PST) Received: by mail-il1-x129.google.com with SMTP id d5so3856239iln.6 for ; Fri, 05 Mar 2021 19:15:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=siv8ALjvw5nAWM5oVnlAOXA/08MIyz7olXglWGx22ko=; b=VaG23pAj8JOs+CT9cgwwHYOa0+JEos2V4LSaNc5NiboFIMDa6NIW9Njr6Tic3vZQj+ ud1QGV7C0CUFhgk02O9V5sxvLl/z0WlZTFmlf3XSZSWP1al4lrQ19CtsK+hSNUQt9TwH wbLpSKexzyuafiBtRYNJ56LIR0XrwTjVoi0hL4h0rJBV47Tl/T5j9J4FLq6uRy/+tfv1 krPb9Tq36Ab2hg+kvq8h0gYWZlr2NibtRnil57rpD3fGeeZxDlqJNAYQ54NWFPiVKfe/ frZjcpfTVaga8Inw+np2mr/ngDYqMS4I+lT2MUxb3r/xtu8TA0M+s7rOXOFDzk/1AjJ0 bcQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=siv8ALjvw5nAWM5oVnlAOXA/08MIyz7olXglWGx22ko=; b=i5tbz+QtJOlzt/+r6AvClyCBFPOEwfo/yS6mTzhTgkTncygMTlBRUdZMhNOjLxXEW+ zwPHvd2dScdT2/InPVatlCpKw4v/XYCCUpYKEzoE9eEtoK961B0r51VQyLJPmXUWt8iO xyyFAeFkXY3NAhImCi5z5ndpGE2mgpchi9MHVw0CdYQ8Mpefig4SMO1eVQNiCtPX7QJY rf+BREW1zzdjVV0F0QhJIgTZ/3jqHOaF/NOhU0HzhuCp/bqvReqn+U8eBIQBW+68612Z xW9Adi7A2kmGSHrRXSn/TcrZK9vq2s+nkVygBnwmQ3YnqTRqK118vRkGrAjvVZyMnGx3 yQNQ== X-Gm-Message-State: AOAM5324o6dE1I50KnsOFlvRs4iXwPm7OuUBndfnPQJl2WQPEIVEJP0j I8bW/+UCqWMBdBr77BFjxXdZvQ== X-Received: by 2002:a92:c7c2:: with SMTP id g2mr11802891ilk.209.1615000555738; Fri, 05 Mar 2021 19:15:55 -0800 (PST) Received: from presto.localdomain (c-73-185-129-58.hsd1.mn.comcast.net. [73.185.129.58]) by smtp.gmail.com with ESMTPSA id i67sm2278693ioa.3.2021.03.05.19.15.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 19:15:55 -0800 (PST) From: Alex Elder To: subashab@codeaurora.org, stranche@codeaurora.org, davem@davemloft.net, kuba@kernel.org Cc: sharathv@codeaurora.org, bjorn.andersson@linaro.org, evgreen@chromium.org, cpratapa@codeaurora.org, elder@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v2 1/6] net: qualcomm: rmnet: mark trailer field endianness Date: Fri, 5 Mar 2021 21:15:45 -0600 Message-Id: <20210306031550.26530-2-elder@linaro.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210306031550.26530-1-elder@linaro.org> References: <20210306031550.26530-1-elder@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org The fields in the checksum trailer structure used for QMAP protocol RX packets are all big-endian format, so define them that way. It turns out these fields are never actually used by the RMNet code. The start offset is always assumed to be zero, and the length is taken from the other packet headers. So making these fields explicitly big endian has no effect on the behavior of the code. Signed-off-by: Alex Elder Reviewed-by: Bjorn Andersson --- include/linux/if_rmnet.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) -- 2.27.0 diff --git a/include/linux/if_rmnet.h b/include/linux/if_rmnet.h index 9661416a9bb47..8c7845baf3837 100644 --- a/include/linux/if_rmnet.h +++ b/include/linux/if_rmnet.h @@ -32,8 +32,8 @@ struct rmnet_map_dl_csum_trailer { #else #error "Please fix " #endif - u16 csum_start_offset; - u16 csum_length; + __be16 csum_start_offset; + __be16 csum_length; __be16 csum_value; } __aligned(1); From patchwork Sat Mar 6 03:15:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 394534 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp965445jai; Fri, 5 Mar 2021 19:17:07 -0800 (PST) X-Google-Smtp-Source: ABdhPJyK1LQljHkmiNmOyUYeu5nYq99J6rX3/IZxukxNHL4jgnS9Mt8fcIJmkl6R1gv1HRCYKOaD X-Received: by 2002:a17:906:39a:: with SMTP id b26mr5351510eja.158.1615000627362; Fri, 05 Mar 2021 19:17:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615000627; cv=none; d=google.com; s=arc-20160816; b=dOd2hW21tr1Ahpmfaik4kk6rKNPU5lBqp9a53swGREh8+p2kJ7pYbRezrWA7e2xuB0 GnGDheSInyJjOVB0kkJu2xsFjxqyb4yKDZcTbfzwTaI8CrNDW6MYt5POvTOR8vCI982x YhWBEZFv6zk6LOPNlsJTS4jgtp66rrZm5UrWyJckjGEbfQMNFbbxK6aXyIRY4AIcLxor s+X4fsfKpydyuptfjgYU9haPOZhcYtDupIXzhaXOaFNQutdrsKZgwddxhOJYAjZ5r+LC o6qPEb661HB+I8XCyXOXqNnBHvj+JudvvFPu9b0yMD7ti2A6c6TUoWmlicqC+4hYzLkH UEJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=cYtxP12FPoFyXStxU+dIm5i6FSzaCM643MO9iKA6Wx4=; b=UBjyDNxmBDX7jQ51r6Wkac3THrBl3hWS9Uu2wpu2bPwCwtQBTAosDcNOg6/BdO3l39 omiZgzaBkZCBDg34LfBJQIW+dByjtKD5neSj0EvOvi0dWlim+umxpzters94++hUBmIg J+VlseJgXEqDsfz0JXMwlXGJJ9kxPb2ADeOEVw9+ADBnattuLx/Z5akhN2pgehj3WQDa /oAEzlir8Z9omBzKmvXhR/TQvyczpGU7rh5Fh8wcB5/9tX9X+EYRZ3sGaJJVwCw1+hgT pnUljd4DsIkvpSVABP3KQ7V8wziE5FK+K3LZbcqB5PgCnledZERkQuWLkLJzlEopxAqi 4BxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=g6WXRn34; 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 j7si2719448edh.201.2021.03.05.19.17.07; Fri, 05 Mar 2021 19:17:07 -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=g6WXRn34; 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 S229704AbhCFDQe (ORCPT + 9 others); Fri, 5 Mar 2021 22:16:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57700 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229775AbhCFDP7 (ORCPT ); Fri, 5 Mar 2021 22:15:59 -0500 Received: from mail-io1-xd35.google.com (mail-io1-xd35.google.com [IPv6:2607:f8b0:4864:20::d35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4134CC061764 for ; Fri, 5 Mar 2021 19:15:57 -0800 (PST) Received: by mail-io1-xd35.google.com with SMTP id o9so4151708iow.6 for ; Fri, 05 Mar 2021 19:15:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=cYtxP12FPoFyXStxU+dIm5i6FSzaCM643MO9iKA6Wx4=; b=g6WXRn347j7pmgYD2zoZKiQgCwOofJv+sDMycNiZfHjV+4kUFyOaqWKZdkkhUNvuCL /LW3sRYmJ+vhfn4A4JjQt6sODuznGgWlOPRvihgZorv5LKW0/CrU+BrBcZ0sDTea7En5 HeW6hMGRwApLSX87LhzywnKtvCU/bUl39Dtj1OwgiC7b3rTDirJ8T6Z2U1t5oDdtKjfZ QsS9G3IQFKVcxb2c+tKbWL6B6u6f780oewXnHJFtnQ3+ybEpSITiSvV1Niw6FGf7dpti UzmTGSWFyDzdpa3w29sfg0+xqOXRaGb+V31kjrtiflO6NZb63K76zNZWXHD4ONgkWMaF iQDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=cYtxP12FPoFyXStxU+dIm5i6FSzaCM643MO9iKA6Wx4=; b=DcqZmXpSrMGUVUMXyd8jyOwZfume9IuIOsA+UrQoeJ37YV+1QzN5gdy7mYFS6VeV+P 3LS/lfzpFFR9aYsQyFkLruAA1JbufWx+fFpKIhQnB0AusiGYInyQSvaOJMTkLvyQeEUQ SQiERYArT8Jv3G4mtXn5RuFL/6Kuyrbby2mj9fszH25bpXAplNhXOyUg4IfxMyDIZkgY 408YBhhI3pabOlR6lS92itWJy8ZJUGoDnhgOkluBckGijZMlHXxckSrsdwMFwqRAcBi+ 8sbwtWTF05U3sw8AHO+odorRi1cEaA3qyauWE5wBAz1NCB9pB7DbLFAu+OU3EqwL7d4h eVUg== X-Gm-Message-State: AOAM53037hYsFL9UUcF2OVC3XzVMcIDk2iaa10sPglG5BkZNZzd3Efv1 DCsYCMKTjvEQ7CVN5plaZZiGKA== X-Received: by 2002:a02:9003:: with SMTP id w3mr12920361jaf.31.1615000556740; Fri, 05 Mar 2021 19:15:56 -0800 (PST) Received: from presto.localdomain (c-73-185-129-58.hsd1.mn.comcast.net. [73.185.129.58]) by smtp.gmail.com with ESMTPSA id i67sm2278693ioa.3.2021.03.05.19.15.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 19:15:56 -0800 (PST) From: Alex Elder To: subashab@codeaurora.org, stranche@codeaurora.org, davem@davemloft.net, kuba@kernel.org Cc: sharathv@codeaurora.org, bjorn.andersson@linaro.org, evgreen@chromium.org, cpratapa@codeaurora.org, elder@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v2 2/6] net: qualcomm: rmnet: simplify some byte order logic Date: Fri, 5 Mar 2021 21:15:46 -0600 Message-Id: <20210306031550.26530-3-elder@linaro.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210306031550.26530-1-elder@linaro.org> References: <20210306031550.26530-1-elder@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org In rmnet_map_ipv4_ul_csum_header() and rmnet_map_ipv6_ul_csum_header() the offset within a packet at which checksumming should commence is calculated. This calculation involves byte swapping and a forced type conversion that makes it hard to understand. Simplify this by computing the offset in host byte order, then converting the result when assigning it into the header field. Signed-off-by: Alex Elder Reviewed-by: Bjorn Andersson --- .../ethernet/qualcomm/rmnet/rmnet_map_data.c | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) -- 2.27.0 diff --git a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c index 21d38167f9618..bd1aa11c9ce59 100644 --- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c +++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c @@ -197,12 +197,13 @@ rmnet_map_ipv4_ul_csum_header(void *iphdr, struct rmnet_map_ul_csum_header *ul_header, struct sk_buff *skb) { - struct iphdr *ip4h = (struct iphdr *)iphdr; - __be16 *hdr = (__be16 *)ul_header, offset; + __be16 *hdr = (__be16 *)ul_header; + struct iphdr *ip4h = iphdr; + u16 offset; + + offset = skb_transport_header(skb) - (unsigned char *)iphdr; + ul_header->csum_start_offset = htons(offset); - offset = htons((__force u16)(skb_transport_header(skb) - - (unsigned char *)iphdr)); - ul_header->csum_start_offset = offset; ul_header->csum_insert_offset = skb->csum_offset; ul_header->csum_enabled = 1; if (ip4h->protocol == IPPROTO_UDP) @@ -239,12 +240,13 @@ rmnet_map_ipv6_ul_csum_header(void *ip6hdr, struct rmnet_map_ul_csum_header *ul_header, struct sk_buff *skb) { - struct ipv6hdr *ip6h = (struct ipv6hdr *)ip6hdr; - __be16 *hdr = (__be16 *)ul_header, offset; + __be16 *hdr = (__be16 *)ul_header; + struct ipv6hdr *ip6h = ip6hdr; + u16 offset; + + offset = skb_transport_header(skb) - (unsigned char *)ip6hdr; + ul_header->csum_start_offset = htons(offset); - offset = htons((__force u16)(skb_transport_header(skb) - - (unsigned char *)ip6hdr)); - ul_header->csum_start_offset = offset; ul_header->csum_insert_offset = skb->csum_offset; ul_header->csum_enabled = 1; From patchwork Sat Mar 6 03:15:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 394533 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp965440jai; Fri, 5 Mar 2021 19:17:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJz1ZewzQGnTzzEMat74SBVv4uirxkMjdACtCx+juqjEAwlcTWOkkHNRNYuWvkcTY9C6y+Bd X-Received: by 2002:a17:906:85b:: with SMTP id f27mr5353553ejd.414.1615000626569; Fri, 05 Mar 2021 19:17:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615000626; cv=none; d=google.com; s=arc-20160816; b=jbZ9z0uDbyJrykY3VWbHj1wGdLzXZ6pEkCW+BVQStUwUm0pkQDMgT/aUegwDTK1bj3 2G0SsQkMXbXzpHCZLUCgKgTuucvphBJEsouCqfGduVNvAlIVPZ6Td0jfDixsey4Zst/5 v2toFC8/n6E3unTYiRaFHrffd7MJNq5c7GnYuuBbdxpJHiM6jYChHaXUCDRUsG0Ttvu3 NHA0mv5Lgrb6WVSsBp/gWnxpsHaTb5pfgK7W1MI4JedTW+7Hr/Mxku95yP5r0p26upvt DujLuIDzXFecRtMW2VQQXLbypTNNQBkrK5dX21ZuPpSGOk2pLQxFObnp8E4HpGtqH4nv lC7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=3pf3F65RZucsIMXc3J9HNUjACeQQX3TS4fzpwXGEtjU=; b=cbUrUop5Q+F+ylOrvvMZasr1lRro1AeB3vE6Abc3SdbMs0e1OX1Cea9J1yISJ/oVDJ oH1fL+WJEdlQUVVlEE0OVftQ6otEExC77L1Xnif1s5sCZUZWa5e7eWpPRxiAFqTqa2Q6 kr48LNPozdqIIjVEEL3qiMoEzHCMFd789qm0DwWr3Vq4ajjywwJE1NBEIMvSKQ64vWQE qBaSutUEiFIl+0FG2JXwE6FMS4G5esUzfd3thnHJGfDMt/3OYzTaGB8hqJRjZxM7X1UY 1B//uN7FKDhsQpeM9SCP8gMQuDu0QdvyUC6esp8nQVxDKvDyX3MncW1K9c9zyEo0Lr/f gykw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=uJ9LqBW6; 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 j7si2719448edh.201.2021.03.05.19.17.06; Fri, 05 Mar 2021 19:17:06 -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=uJ9LqBW6; 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 S230034AbhCFDQd (ORCPT + 9 others); Fri, 5 Mar 2021 22:16:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229758AbhCFDP7 (ORCPT ); Fri, 5 Mar 2021 22:15:59 -0500 Received: from mail-io1-xd2b.google.com (mail-io1-xd2b.google.com [IPv6:2607:f8b0:4864:20::d2b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 46FFAC0613D7 for ; Fri, 5 Mar 2021 19:15:58 -0800 (PST) Received: by mail-io1-xd2b.google.com with SMTP id a7so4109779iok.12 for ; Fri, 05 Mar 2021 19:15:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3pf3F65RZucsIMXc3J9HNUjACeQQX3TS4fzpwXGEtjU=; b=uJ9LqBW64xawg2GQYw0Lomzejf0+ejneX7u8Q34Pgygl8ZzbDHpX4gHHV+mQjdt8Ua VMhs68YznM7G6lcLvwNw+krd+8Rkjph+RQmOfB1bqWbNjwyHxwLZZ0VVmcAIOCW7oZQl SUT0po0KzaS9fU3Ds33YqwELQfIOJ0RqL8VrdBeMn7VxVuKP2ORZWEe/tGolsx1t4CLT n281ZO8pjoTnuWKW9xiUl+HNB2ICxptZ9CrKJtzu2WJpWe6nEn44TtKW0OoLIJ9Tg29N ZAu97+NP9bKHuZJV7RWei9oL2Rbgb1YYmcUfFC5sfhSOyGbfXXRcH2XzWXuO1w0yMXpM onJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=3pf3F65RZucsIMXc3J9HNUjACeQQX3TS4fzpwXGEtjU=; b=fdK+OqHwkekupTyWfz3bX2rUsnteIoppCp95JDq8Q1TPQgI4oC0DTF5JHiduAPhkN+ d14BhMSZHSVMfINcK+lDcP/eU3U8dsiZFdo7KBQKNIC3m23rfwJJK+BH2M+QEcUopM1J +/3SaNy6HFqmKV8WSMSPrbyxihAKFKCawuFJLZCAm9V/90qTvJtDCfwmJgVF6kow4VHE f8mpYTF12rFbi5e3/Imff8Z6QidxMUDRNsiVHtowtut3hvF+39XBAXWpFI6AyGkTiYUq SnosED8ET67TZE+syP4gthDRUIlDZNAX7HW28tPDl8wMelNfXibo4VChy9zHmYixev/3 Oaog== X-Gm-Message-State: AOAM532UQ1VKVdPvv4yben8dUWrquP6yE2Fbq/SSRdLpgQoVHKDTAiHr RgGe8U33TT699VtXBzv9rsqSGg== X-Received: by 2002:a5e:9908:: with SMTP id t8mr11147172ioj.101.1615000557713; Fri, 05 Mar 2021 19:15:57 -0800 (PST) Received: from presto.localdomain (c-73-185-129-58.hsd1.mn.comcast.net. [73.185.129.58]) by smtp.gmail.com with ESMTPSA id i67sm2278693ioa.3.2021.03.05.19.15.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 19:15:57 -0800 (PST) From: Alex Elder To: subashab@codeaurora.org, stranche@codeaurora.org, davem@davemloft.net, kuba@kernel.org Cc: sharathv@codeaurora.org, bjorn.andersson@linaro.org, evgreen@chromium.org, cpratapa@codeaurora.org, elder@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v2 3/6] net: qualcomm: rmnet: kill RMNET_MAP_GET_*() accessor macros Date: Fri, 5 Mar 2021 21:15:47 -0600 Message-Id: <20210306031550.26530-4-elder@linaro.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210306031550.26530-1-elder@linaro.org> References: <20210306031550.26530-1-elder@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org The following macros, defined in "rmnet_map.h", assume a socket buffer is provided as an argument without any real indication this is the case. RMNET_MAP_GET_MUX_ID() RMNET_MAP_GET_CD_BIT() RMNET_MAP_GET_PAD() RMNET_MAP_GET_CMD_START() RMNET_MAP_GET_LENGTH() What they hide is pretty trivial accessing of fields in a structure, and it's much clearer to see this if we do these accesses directly. So rather than using these accessor macros, assign a local variable of the map header pointer type to the socket buffer data pointer, and derereference that pointer variable. In "rmnet_map_data.c", use sizeof(object) rather than sizeof(type) in one spot. Also, there's no need to byte swap 0; it's all zeros irrespective of endianness. Signed-off-by: Alex Elder Reviewed-by: Bjorn Andersson --- drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c | 10 ++++++---- drivers/net/ethernet/qualcomm/rmnet/rmnet_map.h | 12 ------------ .../net/ethernet/qualcomm/rmnet/rmnet_map_command.c | 11 ++++++++--- drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c | 4 ++-- 4 files changed, 16 insertions(+), 21 deletions(-) -- 2.27.0 diff --git a/drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c b/drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c index 3d00b32323084..2a6b2a609884c 100644 --- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c +++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c @@ -56,20 +56,22 @@ static void __rmnet_map_ingress_handler(struct sk_buff *skb, struct rmnet_port *port) { + struct rmnet_map_header *map_header = (void *)skb->data; struct rmnet_endpoint *ep; u16 len, pad; u8 mux_id; - if (RMNET_MAP_GET_CD_BIT(skb)) { + if (map_header->cd_bit) { + /* Packet contains a MAP command (not data) */ if (port->data_format & RMNET_FLAGS_INGRESS_MAP_COMMANDS) return rmnet_map_command(skb, port); goto free_skb; } - mux_id = RMNET_MAP_GET_MUX_ID(skb); - pad = RMNET_MAP_GET_PAD(skb); - len = RMNET_MAP_GET_LENGTH(skb) - pad; + mux_id = map_header->mux_id; + pad = map_header->pad_len; + len = ntohs(map_header->pkt_len) - pad; if (mux_id >= RMNET_MAX_LOGICAL_EP) goto free_skb; diff --git a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map.h b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map.h index 576501db2a0bc..2aea153f42473 100644 --- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map.h +++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map.h @@ -32,18 +32,6 @@ enum rmnet_map_commands { RMNET_MAP_COMMAND_ENUM_LENGTH }; -#define RMNET_MAP_GET_MUX_ID(Y) (((struct rmnet_map_header *) \ - (Y)->data)->mux_id) -#define RMNET_MAP_GET_CD_BIT(Y) (((struct rmnet_map_header *) \ - (Y)->data)->cd_bit) -#define RMNET_MAP_GET_PAD(Y) (((struct rmnet_map_header *) \ - (Y)->data)->pad_len) -#define RMNET_MAP_GET_CMD_START(Y) ((struct rmnet_map_control_command *) \ - ((Y)->data + \ - sizeof(struct rmnet_map_header))) -#define RMNET_MAP_GET_LENGTH(Y) (ntohs(((struct rmnet_map_header *) \ - (Y)->data)->pkt_len)) - #define RMNET_MAP_COMMAND_REQUEST 0 #define RMNET_MAP_COMMAND_ACK 1 #define RMNET_MAP_COMMAND_UNSUPPORTED 2 diff --git a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_command.c b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_command.c index beaee49621287..add0f5ade2e61 100644 --- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_command.c +++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_command.c @@ -12,12 +12,13 @@ static u8 rmnet_map_do_flow_control(struct sk_buff *skb, struct rmnet_port *port, int enable) { + struct rmnet_map_header *map_header = (void *)skb->data; struct rmnet_endpoint *ep; struct net_device *vnd; u8 mux_id; int r; - mux_id = RMNET_MAP_GET_MUX_ID(skb); + mux_id = map_header->mux_id; if (mux_id >= RMNET_MAX_LOGICAL_EP) { kfree_skb(skb); @@ -49,6 +50,7 @@ static void rmnet_map_send_ack(struct sk_buff *skb, unsigned char type, struct rmnet_port *port) { + struct rmnet_map_header *map_header = (void *)skb->data; struct rmnet_map_control_command *cmd; struct net_device *dev = skb->dev; @@ -58,7 +60,8 @@ static void rmnet_map_send_ack(struct sk_buff *skb, skb->protocol = htons(ETH_P_MAP); - cmd = RMNET_MAP_GET_CMD_START(skb); + /* Command data immediately follows the MAP header */ + cmd = (struct rmnet_map_control_command *)(map_header + 1); cmd->cmd_type = type & 0x03; netif_tx_lock(dev); @@ -71,11 +74,13 @@ static void rmnet_map_send_ack(struct sk_buff *skb, */ void rmnet_map_command(struct sk_buff *skb, struct rmnet_port *port) { + struct rmnet_map_header *map_header = (void *)skb->data; struct rmnet_map_control_command *cmd; unsigned char command_name; unsigned char rc = 0; - cmd = RMNET_MAP_GET_CMD_START(skb); + /* Command data immediately follows the MAP header */ + cmd = (struct rmnet_map_control_command *)(map_header + 1); command_name = cmd->command_name; switch (command_name) { diff --git a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c index bd1aa11c9ce59..fd55269c2ce3c 100644 --- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c +++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c @@ -321,7 +321,7 @@ struct sk_buff *rmnet_map_deaggregate(struct sk_buff *skb, return NULL; maph = (struct rmnet_map_header *)skb->data; - packet_len = ntohs(maph->pkt_len) + sizeof(struct rmnet_map_header); + packet_len = ntohs(maph->pkt_len) + sizeof(*maph); if (port->data_format & RMNET_FLAGS_INGRESS_MAP_CKSUMV4) packet_len += sizeof(struct rmnet_map_dl_csum_trailer); @@ -330,7 +330,7 @@ struct sk_buff *rmnet_map_deaggregate(struct sk_buff *skb, return NULL; /* Some hardware can send us empty frames. Catch them */ - if (ntohs(maph->pkt_len) == 0) + if (!maph->pkt_len) return NULL; skbn = alloc_skb(packet_len + RMNET_MAP_DEAGGR_SPACING, GFP_ATOMIC); From patchwork Sat Mar 6 03:15:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 394532 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp965424jai; Fri, 5 Mar 2021 19:17:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJzylLQ4+jfQU7vuCHi5bTR9ty79GPSy9YkAImlajKkH3yzLhmd7BKZXs7IvVpcnt4qkhzrE X-Received: by 2002:a17:906:32d1:: with SMTP id k17mr4716432ejk.94.1615000625351; Fri, 05 Mar 2021 19:17:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615000625; cv=none; d=google.com; s=arc-20160816; b=yRoQCqbWU+MKSHdMYS/3VS8c4Lq3j6IDST4YH6CONDdXMgHMq5UMJXgz8NQg5GgG77 lIf2Fjr3A13iqzuL/rqz95Cyb36DjDAlaSi5RcAhw0PC0qFzFPwMvecMu64j+2iwYhpK kgGSc4S15FtUMoN3jc56nOxuWqX/LTvUk0mS0+IplbajlcQXrDO1fIDlsV7ptVccGwX5 Rz1ZDRRSAkspktfcLp8CVmMiuY0XinC0Wbm2hLQ0aZRxb3JQyFrSIRgYe1/K5aIXQ6LB 1sZtnZkc/UnIlqSj6eFjvt14p5RvqUB47Pq3tGIlkZ/56R6PCmzf73J8VaQIzjbcM/yj 0azw== 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=Cz9pvy9/DMfTSTzewlxOLsfS473feLrBEN4uWmNYcUQ=; b=HCDLFMda5Ge9f+FRrAWXtAZFdDp7fpR3myhZrWBEme6ZpO+Cr8LjcYXQBE2imLlxlm fPbV20nJ1eBqwEbQLczLW7p2mg28w4Mfwnb24QZhkOgN2qVUt7tsFeFfW2jZQy6GpPQA phYuvpf2dUpkayq272FgijIxp+W5hrCKIGKMYnn+IiIX6X0/auxQobMb9rVaa24J4y/S 5xN4AbELMatN6zC/pkHJyihAyCkrsjTOUGUqnXTAmAsqs53QxAZohyoja9tIWxugo1dj /JUJj7DMDr4cKYAc1EmtJg6NxoThwMfoDy06+0ydK9a5NSJqF6EwDfSNckDCC1mGZN7z RjPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="mGtVXYn/"; 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 j7si2719448edh.201.2021.03.05.19.17.05; Fri, 05 Mar 2021 19:17:05 -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="mGtVXYn/"; 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 S229978AbhCFDQc (ORCPT + 9 others); Fri, 5 Mar 2021 22:16:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229788AbhCFDP7 (ORCPT ); Fri, 5 Mar 2021 22:15:59 -0500 Received: from mail-il1-x129.google.com (mail-il1-x129.google.com [IPv6:2607:f8b0:4864:20::129]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D9FDC0613D8 for ; Fri, 5 Mar 2021 19:15:59 -0800 (PST) Received: by mail-il1-x129.google.com with SMTP id v14so3835471ilj.11 for ; Fri, 05 Mar 2021 19:15:59 -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=Cz9pvy9/DMfTSTzewlxOLsfS473feLrBEN4uWmNYcUQ=; b=mGtVXYn/bwhRQsYvtNd7ZGXWKsevaqd53fLNz1Q3QEtpsF5uML8Js98pB8bnacaMXQ k20khoRHAscRm7jho+f0O3zgfzuomc0jjJz9MFhbMmIa7+1HsGXR+DwgVPldRUw/gPkT a5n+FXp5+blFq4dWiFVXf+e00GkNZZ9ygi9GTYk6/SGxzLGDjrvJI9aMME4v/v0fe73P 7pyH/IXordCMPDiLWa5hY16XKva+suxJyAic1K9xkeMxr22Y07baCLYlh9LCn0ltjyaM cKl5p2TfOxszF24qnSoXvt3Maf8/ooGFRpT2amEBrsk2IKG9rGQmp+rtVGw0jjHgiUAg SF9g== 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=Cz9pvy9/DMfTSTzewlxOLsfS473feLrBEN4uWmNYcUQ=; b=oKjKMMRZFu8MjSFc1HXF4DtfiQLhq3TGVrwIgaRCLNblCLbAbN2C/613brBATlmYF/ bgssidaDDlI+0Cuce5YwCdbIiib0kbxAP6HQvOEHQj3mnVrCg3KNx6XvlIrkwEBZt931 fD0OHQE9zFuNcZJCULUnImr8+Ov0axn+tJecfiqmA50N1xUr5HLvIKSFbP7i6yA4xjRQ kusufXM5QRmCIqqTnPYdpFyeutn6GKMfEftXd9DGAuyud6quv3JT/+o1kBf00NRM7Oqn TmbSDMWhHaB0F4XOCfiLKYwtNdSjZ/K0gunGt9lTQZBgs/Fjz7qzo4ciHCfaaa3k+25+ rfuw== X-Gm-Message-State: AOAM533jXME6nrzHPqWzzJ34IMOemSCJqvd+h37G7cJO+ZGBn2foGO3j bATX1bj+IfX0CIrtzYOKBHpN0Q== X-Received: by 2002:a92:cda2:: with SMTP id g2mr11834168ild.297.1615000558717; Fri, 05 Mar 2021 19:15:58 -0800 (PST) Received: from presto.localdomain (c-73-185-129-58.hsd1.mn.comcast.net. [73.185.129.58]) by smtp.gmail.com with ESMTPSA id i67sm2278693ioa.3.2021.03.05.19.15.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 19:15:58 -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 v2 4/6] net: qualcomm: rmnet: use field masks instead of C bit-fields Date: Fri, 5 Mar 2021 21:15:48 -0600 Message-Id: <20210306031550.26530-5-elder@linaro.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210306031550.26530-1-elder@linaro.org> References: <20210306031550.26530-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 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(-) -- 2.27.0 diff --git a/drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c b/drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c index 2a6b2a609884c..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 Sat Mar 6 03:15:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 394531 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp965419jai; Fri, 5 Mar 2021 19:17:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJz42SeGz4XZ9VP7gJulqkaZy9FOHBfxiG8toyDE80X/wlSkjibYuN1bYM8GyjTKEdvcCFpQ X-Received: by 2002:a17:906:b4c:: with SMTP id v12mr5330421ejg.330.1615000624958; Fri, 05 Mar 2021 19:17:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615000624; cv=none; d=google.com; s=arc-20160816; b=Zgz84L9tAcWATzojCpqQTZtWY3t6MBtJ2B75btyjlKtbSI0vVnjLddc6H79gBVKt2t cJfoOZ5jaXy3kgj8AYOKlJFQNDCbLuc2qx6cATGMDZmN61pDw4dkSbfq39xO5GApumzT h93JeDBbSuXonvLS618xbtDgdjQjfSGTiwzzK8WG2+xnw5CzvhZIn5hGQtNPJNKK7a6b TJ37GOpZxgv/LaLqA9MOilYZ70hdouI2xaJ/7DKKP7LM4AR+teFi9SvsiJMxAfbE+hkQ 7aTT0pmbCppnP4lbk52xBt8hES2H3oo+stU3GtOg3KjY+tNDyvVmywccjxyg6CiuQZrD xwHA== 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=v75WqFNEqmNfaFvo+fJoS+EBGR7oORQvhBv4GH6rgs0=; b=ZjeqhIx/vz+GxWay4kVP2P4veuMXJdyH58lR16cYSIl8suvhS3Oa4VDYFDm12n6B3p MN2+Mtaazr7MZn9HY16kCLOaINU6elwTQmyd4MI752xXxo4JYYcKnZ/COprcBp1Bl5// DvioK/dr2W2X7bZZO9PmhxLAVBBEclttsDkN3aXfKnIAscioRAOPqH+g/v7jZl66dTFR 0RJxdROxgZ8z/34c7CuPzLODeQu4os/a9KZbC59DYQtW44tk2ACXZaQghgxHF8+dHVMx dmyVeOnK8PzvXaNSVHLXPKHS14J9HRVD7dK0B3Qzh1nh+gu/3BvJpw3InMKa68/aERHo CTmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=o4HiSXgu; 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 j7si2719448edh.201.2021.03.05.19.17.04; Fri, 05 Mar 2021 19:17:04 -0800 (PST) Received-SPF: pass (google.com: domain of netdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=o4HiSXgu; 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 S229940AbhCFDQb (ORCPT + 9 others); Fri, 5 Mar 2021 22:16:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57700 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229797AbhCFDQA (ORCPT ); Fri, 5 Mar 2021 22:16:00 -0500 Received: from mail-io1-xd35.google.com (mail-io1-xd35.google.com [IPv6:2607:f8b0:4864:20::d35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D3A4C061760 for ; Fri, 5 Mar 2021 19:16:00 -0800 (PST) Received: by mail-io1-xd35.google.com with SMTP id k2so4163265ioh.5 for ; Fri, 05 Mar 2021 19:16:00 -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=v75WqFNEqmNfaFvo+fJoS+EBGR7oORQvhBv4GH6rgs0=; b=o4HiSXgu0idLl/ulWk8usLU0pMTEcPGiNrBY7cmCtob+2QUIgLgh0WGzC4tToMdqcr ZewxhKsdTKHknEEs/ImvzgvmJ93jjxcJiwWXxIFM2tNc4PiBVvQF/5uZkz3R19xRQKNq zi9SmowDHhzAR3r9x6aQo7zD0nF0PW+A2lMOf3iVEhOq1xLkai45OwKSdZnEAcpNPSQM aGic4P6rrBAGS0NqC9JN43LrD3koQJc7UQyG7jJFEe/rJKoertziZ57ucAhZucS48cY5 /KCAZYk3zU2ptJDhGB/9gI1NnrxoUSFIkfCk7SrFS0fDbK0j/zOc8DDFmPp5QKXVgVuU 4Maw== 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=v75WqFNEqmNfaFvo+fJoS+EBGR7oORQvhBv4GH6rgs0=; b=dcIHRFDlKebD53Fq6DzKBARCZ+vqCODMY73AGGz4r3LKJ0MbESWiu7tKqdJ6Nuh0+/ BUHZy/P559n44WqH14Bjkjz7mCLQM3/E5pjrMn6fVn/vBY4+gMulDPVuBLo7nImiz/9r J4YQPpdSMdupuLt5qTjy0lRJwLUxNPnghE2V507QNU15f+WXBr70C4+BgCdUzQIANoF9 n6ziomqGMJKPzIFc7MXsGczYIknyPt4BrwrdJ83FrPihgnidMR645DwNWBurXTju8dJx ZFGKM2KNmcqJbZEvOvt2BW9VuDgerpfAEOeFtQ6uCbR3lHdkbmmcEvYmVQ3R/MSCau+a zYxQ== X-Gm-Message-State: AOAM5322e9eyknGrwB38ml/VfRH//QCYT52nVcR2uxOSyecUsRp/NWyi F/34/e0D5QKTAJzmFVoNrEq0GI4UNB0BDA== X-Received: by 2002:a02:9985:: with SMTP id a5mr13152384jal.122.1615000559695; Fri, 05 Mar 2021 19:15:59 -0800 (PST) Received: from presto.localdomain (c-73-185-129-58.hsd1.mn.comcast.net. [73.185.129.58]) by smtp.gmail.com with ESMTPSA id i67sm2278693ioa.3.2021.03.05.19.15.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 19:15:59 -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 v2 5/6] net: qualcomm: rmnet: don't use C bit-fields in rmnet checksum trailer Date: Fri, 5 Mar 2021 21:15:49 -0600 Message-Id: <20210306031550.26530-6-elder@linaro.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210306031550.26530-1-elder@linaro.org> References: <20210306031550.26530-1-elder@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Replace the use of C bit-fields in the rmnet_map_dl_csum_trailer structure with a single one-byte field, using constant field masks to encode or get at embedded values. Signed-off-by: Alex Elder Reviewed-by: Bjorn Andersson --- .../ethernet/qualcomm/rmnet/rmnet_map_data.c | 2 +- include/linux/if_rmnet.h | 17 +++++++---------- 2 files changed, 8 insertions(+), 11 deletions(-) -- 2.27.0 diff --git a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c index 3291f252d81b0..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 Sat Mar 6 03:15:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 394536 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp965462jai; Fri, 5 Mar 2021 19:17:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJyJjp81fJzTTH87Z/8pTGGf0AbCMwVpdXvnVkVbNQCyTFRFYuxng2VQh1nyoOtvLRsJE/Et X-Received: by 2002:a17:906:5849:: with SMTP id h9mr5308238ejs.551.1615000628937; Fri, 05 Mar 2021 19:17:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615000628; cv=none; d=google.com; s=arc-20160816; b=z8nDC4ZWuyElSTZIdwNuDXb/fTy13bPi0KUl+52MPfe7Ohdh67KLNnsH/yE+7X44Fx x6FcEiUUEgi6KZEZ2ie4DxGkxK0UAU63gZa1OVFG25FNZbiSGwCZMVk2vb0+yhqnZX7D +MpS5xFOZM98nCvZNCvElCUI01vllUdzwLQCs4bvwWZrpQ2ZxyjWb6cMXmH3GvJRA2KO Iss6Y8uKtCIFo00crocNRwkUdr9aiFLxpJGoLovYPDP3m2fRzArhh7U3Ktf3okdxiAC1 QjQlLPgS9bTXNp6rtITyX0yAGdkxG4zImFXmvoV2qxu18bC2Iz3rgSCOYRQDI4oFhCFB qC+Q== 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=AQkKL/OB7ALpeFx7XOfbe4/eCQx3rmR+Ln/joz2blFc=; b=NhoLoImhU5QWL7rhHBVUUGFhMr1O8vAUTsPD10AC9FDpgfiXj638NMDUuBpsgPODH6 HLnB7joBHLqzm7/gmmji8mKDijDJ7Lzxj4HNnzB227AWERZx1+R+MWFd075ldv1FTll2 iKW5/UChyVQorAYef1sxHPwlmCrsAsiRYm53en0CJdHzWsiiVp4yQPNnFtpcjG9N3KJx 4GMJ46gNB2SuxsjbxIFyYw578WyI45k2N+fMlKW/va+i0PXEQVgcUpr+J76s19Qji/Pa odaG7PnZZ/JipBWr+o3CWYwqbNwGb6EvffN+9amAhxFQ+ZcxbSpryX7xZI7bvbhrrqvm W9+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fiVdoyp4; 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 j7si2719448edh.201.2021.03.05.19.17.08; Fri, 05 Mar 2021 19:17:08 -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=fiVdoyp4; 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 S230130AbhCFDQg (ORCPT + 9 others); Fri, 5 Mar 2021 22:16:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229815AbhCFDQM (ORCPT ); Fri, 5 Mar 2021 22:16:12 -0500 Received: from mail-io1-xd2f.google.com (mail-io1-xd2f.google.com [IPv6:2607:f8b0:4864:20::d2f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7AAF3C061760 for ; Fri, 5 Mar 2021 19:16:01 -0800 (PST) Received: by mail-io1-xd2f.google.com with SMTP id o9so4151813iow.6 for ; Fri, 05 Mar 2021 19:16:01 -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=AQkKL/OB7ALpeFx7XOfbe4/eCQx3rmR+Ln/joz2blFc=; b=fiVdoyp41dr0PAzh3H73TXdQmN7xdWdEPXFvKEEXCEtpiqU6kqPtU4+0I+YCAoeTMA pVbwgNkuuXzpfN5J6HrZcMcJyoT6O3gSp8Hixome4W7bd5t1cbVELqfXexhTYArjkF6r vW+uxsKYiVdOntRLYlaNNl5WLg6Ycik7GYaTnaIsH0DygM+4vqqCeVw4N5ixClepaa0u E7Bqd+vDf8YASWQDZqjwiT1CPRtrM4IBZ0XifO9EhkFEg0ZQy38PG1sVHxToNQ9O+K5a J6yvdvzO9H/OCgqKKlbV8YkvhiBS2UTWtEeS2QN61rKJKSB0ruZo33ovqj01KEegN9jP IHIg== 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=AQkKL/OB7ALpeFx7XOfbe4/eCQx3rmR+Ln/joz2blFc=; b=mifrUusW4WXg4B4ACTkMjEj4fk+1KecQQflozUiziN7VUUM6w1bE5OMQMSe3ErUCSc g3Fe9Wt1NDpYbP6zuTLgATm0I4PcCFqk0nvVarkAGLbMMXG3swWszxkfWCVcEvKdzIzj TllRqhIOYlZODsj+oa5AxJVC3hFX1A1mXdEHE0rN3hpAtX5Kn4LdXJq4VuyxbqMH0le0 CMv1hWmPj0qb55Fu69N1iJRMPYLYj4SME93D504D55EfQ0NZ2FFnsh970xgvfaIygDvD PubiD8N3Ml8nnbQ38SpCOuwgTBrSGinFAWPOIQ7flHn1Uu6sGFwME8e3C8fVUE1Sz/Lp uHQQ== X-Gm-Message-State: AOAM531uSivkN5zVqVF/DswlrkbiSTH9xNKZLohM+P/cI/JzvHTUpZMg PsJ8t+IKZmNnOPQOkydvvds9bA== X-Received: by 2002:a6b:8b0e:: with SMTP id n14mr10951457iod.199.1615000560938; Fri, 05 Mar 2021 19:16:00 -0800 (PST) Received: from presto.localdomain (c-73-185-129-58.hsd1.mn.comcast.net. [73.185.129.58]) by smtp.gmail.com with ESMTPSA id i67sm2278693ioa.3.2021.03.05.19.15.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 19:16:00 -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, kernel test robot Subject: [PATCH net-next v2 6/6] net: qualcomm: rmnet: don't use C bit-fields in rmnet checksum header Date: Fri, 5 Mar 2021 21:15:50 -0600 Message-Id: <20210306031550.26530-7-elder@linaro.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210306031550.26530-1-elder@linaro.org> References: <20210306031550.26530-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 Reported-by: kernel test robot --- v2: Fixed to use u16_encode_bits() instead of be16_encode_bits(). .../ethernet/qualcomm/rmnet/rmnet_map_data.c | 34 ++++++------------- include/linux/if_rmnet.h | 21 ++++++------ 2 files changed, 21 insertions(+), 34 deletions(-) -- 2.27.0 diff --git a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c index 29d485b868a65..b76ad48da7325 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 = u16_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 |= u16_encode_bits(1, MAP_CSUM_UL_UDP_FMASK); + val |= u16_encode_bits(skb->csum_offset, MAP_CSUM_UL_OFFSET_FMASK); - /* Changing remaining fields to network order */ - hdr++; - *hdr = htons((__force u16)*hdr); + ul_header->csum_info = htons(val); skb->ip_summed = CHECKSUM_NONE; @@ -241,24 +237,19 @@ rmnet_map_ipv6_ul_csum_header(void *ip6hdr, struct rmnet_map_ul_csum_header *ul_header, struct sk_buff *skb) { - __be16 *hdr = (__be16 *)ul_header; struct ipv6hdr *ip6h = ip6hdr; u16 offset; + u16 val; offset = skb_transport_header(skb) - (unsigned char *)ip6hdr; ul_header->csum_start_offset = htons(offset); - ul_header->csum_insert_offset = skb->csum_offset; - ul_header->csum_enabled = 1; - + val = u16_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 |= u16_encode_bits(1, MAP_CSUM_UL_UDP_FMASK); + val |= u16_encode_bits(skb->csum_offset, MAP_CSUM_UL_OFFSET_FMASK); - /* Changing remaining fields to network order */ - hdr++; - *hdr = htons((__force u16)*hdr); + ul_header->csum_info = htons(val); skb->ip_summed = CHECKSUM_NONE; @@ -425,10 +416,7 @@ void rmnet_map_checksum_uplink_packet(struct sk_buff *skb, } sw_csum: - ul_header->csum_start_offset = 0; - ul_header->csum_insert_offset = 0; - ul_header->csum_enabled = 0; - ul_header->udp_ind = 0; + memset(ul_header, 0, sizeof(*ul_header)); priv->stats.csum_sw++; } diff --git a/include/linux/if_rmnet.h b/include/linux/if_rmnet.h index 1fbb7531238b6..9ff09a2bcf9e1 100644 --- a/include/linux/if_rmnet.h +++ b/include/linux/if_rmnet.h @@ -33,17 +33,16 @@ struct rmnet_map_dl_csum_trailer { struct rmnet_map_ul_csum_header { __be16 csum_start_offset; -#if defined(__LITTLE_ENDIAN_BITFIELD) - u16 csum_insert_offset:14; - u16 udp_ind:1; - u16 csum_enabled:1; -#elif defined (__BIG_ENDIAN_BITFIELD) - u16 csum_enabled:1; - u16 udp_ind:1; - u16 csum_insert_offset:14; -#else -#error "Please fix " -#endif + __be16 csum_info; /* MAP_CSUM_UL_*_FMASK */ } __aligned(1); +/* csum_info field: + * OFFSET: where (offset in bytes) to insert computed checksum + * UDP: 1 = UDP checksum (zero checkum means no checksum) + * ENABLED: 1 = checksum computation requested + */ +#define MAP_CSUM_UL_OFFSET_FMASK GENMASK(13, 0) +#define MAP_CSUM_UL_UDP_FMASK GENMASK(14, 14) +#define MAP_CSUM_UL_ENABLED_FMASK GENMASK(15, 15) + #endif /* !(_LINUX_IF_RMNET_H_) */