From patchwork Mon Mar 15 13:34: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: 400432 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp3424712jai; Mon, 15 Mar 2021 06:35:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzvLIeKoblql1NnO+CdBKf9PJSNFtw/oRs8TxFUCTfkrpuXK8JxvmqIwQykNhr2GNYIkBzM X-Received: by 2002:a05:6402:5211:: with SMTP id s17mr30566684edd.327.1615815347628; Mon, 15 Mar 2021 06:35:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615815347; cv=none; d=google.com; s=arc-20160816; b=hq6e+IMTRePUSVAPY8cGjgTpyX/vjTNI7+zBUlaQMVuCq28RZY9xgyxLica3/lYcjs JWPFz7Abmv856RdRwnWju1IuToxbvoWa//KdpM4TrXVp+avWWicSNZU1OAig9uPffuBn NDBnLe7VzfoNjtgR9yLSjgDJ8NscHR19oc+R0czah2b3t9jFT2FAjWg9EmGvr3c9W038 k9SBBJc+9iM5wx2F7GHNQcIdzN78wUHGWwBezsgBLRObfvaTI7JcpCgf6HJeyxsiuZO3 mmaal9pv0oY6oOouKtlhr6SEtOSPEXjGy4G5TAfZtBr2VjyIIAn1cKlRUcRGxTZWhLw4 yoZw== 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=wXxaWVvz2P6TfWLtMsPRxORpG9HVQf2J/U+dMnMyWbzH1snSlPieiJBcA/3ZvYr4te tslJMMbjOJzY2TGr4YVsk6VhD4ymLwZHVJNaKxWff0wTm8usO5CVJQIea1CN3GdkCCec yejRcoZ8npyBICfy2kFevJLCe2yjbFm9gFK+ajT89i/WiuizBEI0HADPL9HplrmmBuuK ec3By6izRh1v/Fh7zkZF0Z7ktnro+JZGb6fvxcg6MSiwHFEs1L+Sa6RtkGBTBAe3lXQR HYkGIqye2irSoVQGGO8AyYmMyUxQOp1Rl2sK+hUKxyJqLLi4+gNyXRjoynBZyxQoT5xK DbzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=l7lFexo0; 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 s18si11097004edr.249.2021.03.15.06.35.47; Mon, 15 Mar 2021 06:35:47 -0700 (PDT) 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=l7lFexo0; 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 S229602AbhCONfP (ORCPT + 8 others); Mon, 15 Mar 2021 09:35:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39278 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229605AbhCONfA (ORCPT ); Mon, 15 Mar 2021 09:35:00 -0400 Received: from mail-io1-xd36.google.com (mail-io1-xd36.google.com [IPv6:2607:f8b0:4864:20::d36]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B9D0FC06175F for ; Mon, 15 Mar 2021 06:35:00 -0700 (PDT) Received: by mail-io1-xd36.google.com with SMTP id u20so33315505iot.9 for ; Mon, 15 Mar 2021 06:35:00 -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=siv8ALjvw5nAWM5oVnlAOXA/08MIyz7olXglWGx22ko=; b=l7lFexo0b5S+LJMcrD4VEZOBoMyKEJdpy4GLKvP0UuCvCnZ/Ib2cwt2IirxXVgzThr WGXcio2aZZAf5pUeJq9HINoY4eXbx0M/YwqVz9/LnGNtPGjJJ4FyZE+SxwGde1+7hqGM lenXuPW6+0QRD7PesJZr0tWyGrSNUd+TK8QIMBjiayLv4ah3H8DmPOHt6R/JwjOVUvhg jf5QF+/aXCEwR4OMZ0bp51EpnMrHrsVPBqa6jIF98l3XbyYsuIRvJgREeW0Z73Mt+PDb GcMrMIImU1ldqtyQnk6NcFd4sJju0L8BD8IVIyNfsH+FIiEBTJDmiQMPVhrV/U65PNsl 1F0w== 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=D4wlCQGJlezwMvDY/Q8+NPv3ve+3PMPpPSlBwsSUMA9dIPCl92cCjZ9xME1TfkBFiE UGP/qHTWJazQ7KzvplYX2vBy+UxgWZ1bkJlU2jRyCDawVapOiEp5EOl7EeZBjyRuU+R6 FyND1hblV7wbiAYK7s44z0abSLtNcRwek2b3hoFYG8n3j08x9sAROJDy1/B52nI2AlvB tZtvZgKXrxB/iwN+h9IhkOf4lBsaET7wfXAiCqTY8YimkrZb3O/Zr41SoU3vZapUPBzw jRCougkQ9FQLmhYqwS4YThiJ5AuVFdVHcfR6/kJ2WgSE+sf0GAezXlGu3P1Cdxo7mybu vVEw== X-Gm-Message-State: AOAM53282ZNd3He9ERHYZhuE8PEwRa7tUbJeXKis3D3YTfpiGPPXvERa zaXEdg1tQWax679amyZwnbiiqQ== X-Received: by 2002:a02:a90f:: with SMTP id n15mr9697057jam.110.1615815300258; Mon, 15 Mar 2021 06:35:00 -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 o23sm7127672ioo.24.2021.03.15.06.34.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Mar 2021 06:34:59 -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, elder@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v4 1/6] net: qualcomm: rmnet: mark trailer field endianness Date: Mon, 15 Mar 2021 08:34:50 -0500 Message-Id: <20210315133455.1576188-2-elder@linaro.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210315133455.1576188-1-elder@linaro.org> References: <20210315133455.1576188-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 Mon Mar 15 13:34:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 400438 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp3424843jai; Mon, 15 Mar 2021 06:35:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzkK1nrjFFQbyHQE52xYWky62NpYIZiILaK1tzroxeGdZkxzEDUIZxH4rRAbrFWCGx1o2ZW X-Received: by 2002:a17:907:aa2:: with SMTP id bz2mr23979910ejc.239.1615815354204; Mon, 15 Mar 2021 06:35:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615815354; cv=none; d=google.com; s=arc-20160816; b=TSMvLJQvYfdu2DMw9tJwW7HcanHruFiwKo80eh75++mPVq6fgZRQnBX0tTnrVRvLBn oRYz7/BPYA5+ucWSQX+ptcVKHgHk4mxW0+S48LXdDqibSEf2zJ+birbS7eHn2/OKsqJM FtQg2NBfOU22kb0EZKMngwcdKIK4TyrE3xGw2/GEnQkseBxe+NR9VEu8m/aGxBKkkjMi CMKCS9KLM5hKJR5s9tZiXSrjA7VjY+meFWL/RWYZQoOO4buKgT6cpjnp9QDEdoc46bmR 9JBrAbmwkzuEDt5IXsE8OrhngUjta+iqdH9E0IXnt5cmXAAv3NKsACeMhZEdx+rTXC3w mShQ== 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=xh6FKV9BuwA621P6qdB6V0hYuCqq/iR0uQbpWolby7yj620ir2sZN7uuDnzwGIA9n0 camCcDgw7pb/wCEutIhoHeuyj1zyV3+dsqwzUo/ckpjfuBhWvvv9SV5MJF2nPEoxs4if 2c1freAId4W1XHKPIgKRKGl12sqbmSWSxjRSOsI+qkc4TczyoeSdONilDdX7FPM1RWTC 4AB/65AA8QY0cdC/vwHiiarTZj7fIQ0CKnBF+iReDa/YwwGaSBX2ndnzjAL97JYy9m1W xvy+wImBWN55hzOAlMmqdvW3prFGz5OGO0vxD7sU2iDi+gh9sJrpT1HTeYSQeVttU3fB vQNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=T8zJlH3c; 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 s18si11097004edr.249.2021.03.15.06.35.53; Mon, 15 Mar 2021 06:35:54 -0700 (PDT) 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=T8zJlH3c; 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 S229648AbhCONfO (ORCPT + 8 others); Mon, 15 Mar 2021 09:35:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39280 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229613AbhCONfB (ORCPT ); Mon, 15 Mar 2021 09:35:01 -0400 Received: from mail-io1-xd33.google.com (mail-io1-xd33.google.com [IPv6:2607:f8b0:4864:20::d33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE9F2C06174A for ; Mon, 15 Mar 2021 06:35:01 -0700 (PDT) Received: by mail-io1-xd33.google.com with SMTP id y20so15012708iot.4 for ; Mon, 15 Mar 2021 06:35:01 -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=cYtxP12FPoFyXStxU+dIm5i6FSzaCM643MO9iKA6Wx4=; b=T8zJlH3c6GJ1K6qfFZW0U97MtWrn/qHAzbfHZ/iCc/n2mu/eSy2SQE8pcVzT4POyNt m6sxGdWtlxGKqvHVz2Sl60+dhjGEE7qQBkCAtjZOkoLCdZ4Dh/HM9/y6042PWF3CjibI yR0lBUob5tYA8EkbkFfiNfRVuiiUjmOw+l0VX2Te4FJVvPeDpAr1djgtKOQ3orLpWxOf UZkUjTYYLAfjsLv7Rr/Gy3D44oad+rD19Cd86zXLVuAmlaO+WdYAvfDV94WQA/drIB0R QdzZqs8+u6BTTVv3uNCibqWdnW1rA2qPg2JeyeTSoXnXsn3ZT874/Mx88eMt6Q/s+PGt RwlA== 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=aqXE63H0HJihu3VwYXyK4DRuwzmou4R+akna8OAIPY5v40VthWCTYhmF0FpwMn3uyu yxOsfwgnPhc8yeW/Z9nA/tK4Is8nirEjGzpBuEB3PEarYv//Jb91zAya3mOsKxqtHaNy ChfGFlFpW5nuSObmattbS8P930L/VjBqnJHxMYGufRdOHsP8eeu90sMswsCnJkr3UdpD cfSkZ4U1h/Zg9k54diKMi0+GOcq1ePTm5qxhqiOssJ90u/zXXakgkshg7CEKWxDJXCJi ou+9uUPHvwzsMPgDILmGD55/c8rCYY4X5oUTDH/9F1OyYeEpzXQgWpjMi9TnJ0G060ZU VnUw== X-Gm-Message-State: AOAM530nT8gwE/Y9x/uyDTExLCsoIeaT9D6vvuPcTvi5tVdSBCLlFt4j cvIx8oMOwQgZ4xWn66aL3c3Hlg== X-Received: by 2002:a02:cbb2:: with SMTP id v18mr9526215jap.4.1615815301232; Mon, 15 Mar 2021 06:35:01 -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 o23sm7127672ioo.24.2021.03.15.06.35.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Mar 2021 06:35:00 -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, elder@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v4 2/6] net: qualcomm: rmnet: simplify some byte order logic Date: Mon, 15 Mar 2021 08:34:51 -0500 Message-Id: <20210315133455.1576188-3-elder@linaro.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210315133455.1576188-1-elder@linaro.org> References: <20210315133455.1576188-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 Mon Mar 15 13:34:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 400433 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp3424724jai; Mon, 15 Mar 2021 06:35:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwsqmmT+jFgVPnY/l93EZcjQoWlfI+VURNeL0FxfhC4Imd2LhaCr4C8qv4FPJ+seHT4/69f X-Received: by 2002:a05:6402:22b5:: with SMTP id cx21mr30138249edb.27.1615815348384; Mon, 15 Mar 2021 06:35:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615815348; cv=none; d=google.com; s=arc-20160816; b=vkqaPAdt4As8Ar96seUCP/ZPGrx/I0VLNTQRZ4ahk5F3QZWXppY3HSn9Cdt2PrcgyJ wavxBLZ5HaqSY/U6V64T75+jZ1fL2Wtu9Hg/v0a1+U581whi+mRFCby5SyjKhi4JoA8H uteuH9x107QUcHmN/f/KfMQozHavq3WzUKzJOD0DOvvnDaQSP+mAhZR2uMEPuGJgzM6F BTvhuj2v0JEcSyxonNYprH3FMZcKbb1leFLfQyx203pTqLDbhTe2D3t/fb650VFyNQQC mDpDgcWaE6RwS7hOA2FmZ8Igsury6FVgw3lRdJLuapVE/XvO6obhimf5vYmF8sObqyTN nsAQ== 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=WrDx/obq51/WOlMclEaqnN6AgLm6dzFik0zsjiXMckAENL02ePFLEPH/IxzVtIuXIz 65z7AI/G2cr7yMaj2Clt5+m8f0xYKyR5R3QlRF2csrcvI29csrLANfei3llBxuTVX4F5 7QCdqfmeIOsQ4OIV+o7Rej8V1pUTgDG51vqDuevaqYaSfuxHubEHJmYWdSMh8vaqbHLd jEMdQrJxjrW97lTjvq0nTvx/nTeIJxNcZ3bPjs5nhHpxOe1G9iZVO+KdxNsAozaeqN4C ewGz25BV7m08ZQdiEftZ9PGuKZuJibz3o5p+0FvemnwZtKqg4g7ytBr9Q//AGrCpYxGI e9KA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=yd2ISsg+; 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 s18si11097004edr.249.2021.03.15.06.35.48; Mon, 15 Mar 2021 06:35:48 -0700 (PDT) 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=yd2ISsg+; 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 S229731AbhCONfQ (ORCPT + 8 others); Mon, 15 Mar 2021 09:35:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39290 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229623AbhCONfC (ORCPT ); Mon, 15 Mar 2021 09:35:02 -0400 Received: from mail-io1-xd2c.google.com (mail-io1-xd2c.google.com [IPv6:2607:f8b0:4864:20::d2c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B602FC06174A for ; Mon, 15 Mar 2021 06:35:02 -0700 (PDT) Received: by mail-io1-xd2c.google.com with SMTP id o11so33410055iob.1 for ; Mon, 15 Mar 2021 06:35:02 -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=3pf3F65RZucsIMXc3J9HNUjACeQQX3TS4fzpwXGEtjU=; b=yd2ISsg+IwbCyrOjfk5XLhW/EAi2HWd64fKaH10eoZaXbuv9wG+RUtGfBj4lvoV4sV dWQ5pGYOqlVMQ6OS+bn9pstrhXMiGWZlVFFVfb2PuCSTHUUtusVUfBygW3V1YJ7islt/ JTtZHKym0NxmkLfJ7Ruh1XB8759kcEVrvSuW2ZdXZpJsH6s1V22VrP9LlKNR/5sUQC85 oCsZz/Nfoq5EOnHkzkfZPWD7hfqy0e0FVaOjHgylTb7yb6JGWwac9AjrypQfFwsljKkK wttn23vo+iVYxyuotjXXHEjzR5B4s7TyhuR+kJGOS2i1imX1+wTqGRKKgD7CqDbERBfy p3ow== 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=LNiI7UcROCfuoMnPZhsLMUAnx+lG1f5Mjpswr+zWZNRqdY51joCEtvcx5OP8duRUso hkTQTVYRq8EU+Xh5h04sLuMuytss3c7UFSFZLDQEVzUoD3ShCehV/kU4aVVFojbvDitH 7+0k4j8eX/SR7KUONbjDyWQ5hFws2dfzwtE1MDWigCahrA2cFLY1x+a74ynsc21msbK3 Fp/hRXf7bMxK9XCucDRgcmPwu/53knMLiIm8SYn9nTpdjfu37PYWC8alS5z+MkWPqkS5 NXS8h3h32my9mfXDEnGWClGrga+xVBT2+VRDeEy85gw9U0ZFpYiIx3GkgWKaoiHI7M6+ myRw== X-Gm-Message-State: AOAM532LlBzXmD2qtpN+xMKls0cQuvfqzzLaQSwuytStjNfUdpFSOYGR kUPoW7g7gRRJ99A7zNnRVBIZ4w== X-Received: by 2002:a05:6638:1390:: with SMTP id w16mr9543353jad.83.1615815302226; Mon, 15 Mar 2021 06:35:02 -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 o23sm7127672ioo.24.2021.03.15.06.35.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Mar 2021 06:35:01 -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, elder@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v4 3/6] net: qualcomm: rmnet: kill RMNET_MAP_GET_*() accessor macros Date: Mon, 15 Mar 2021 08:34:52 -0500 Message-Id: <20210315133455.1576188-4-elder@linaro.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210315133455.1576188-1-elder@linaro.org> References: <20210315133455.1576188-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 Mon Mar 15 13:34:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 400436 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp3424798jai; Mon, 15 Mar 2021 06:35:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzIFGNal7g5rKuvHHffqRmtX66Z1ny7IA7ii3EIZ41zxcPYOBLQNwfXyg3HVEiVUSuu9/kM X-Received: by 2002:a17:906:e48:: with SMTP id q8mr12172291eji.84.1615815351794; Mon, 15 Mar 2021 06:35:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615815351; cv=none; d=google.com; s=arc-20160816; b=MCPj2dAV3vB5SrYmLyk5Laf3YfoeTuvzytkl4KKavp9lv5oirORdjWZZOcIMnwQRs8 2xEvKUnIIDpEZSsXYKOcSvR9fsTr8Efm9w6EgsC0rRl6VeqV52GjSLzrvga6Zyrkp0TC QzvlipgKsXRlb5Lr9GoCtbeD9GCQ4C+dAQOYCaK7b1TmxJqLYowB5Oo3LNLqQqhGm5dV e+65OegAuygY1zhcYDTzLWOeJpYpqWQwoSmU6kkp1IbRh+YIEttns4zpEjk6sCYvc6qf CrabkCAwetQQWdr61bNgb7U/0Z13mKbCufdr3m1vxww8HmEDn1a4V/aDeXDVOEJqUl1b ruQg== 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=a5fPLpnmRYKCCGzy3IvCXfKkaVbI3lZUkXb2iTfRIc4=; b=kbI10s5U25qjq3wZN6VREoN1R/HBzFgSmTRmNeFBF+6biAyfuKk4cmkb1BMpsaTbfo b2zJ+TsZ11hmUYXiH+Sj9T86U0FpWI55Sb9qNB6RlIsDy54aJwegp/rtR3EGnBThMvja /NP1TOR/7hWB3EEbROGHMShk7J2ZVMf17zQpHuaA9I58UlXCQk1NdcJN6/KRvivOhqmX z1muPxGNakcHl1BuzZmcFHK1+0Dd+uwpvmhxaBF2drzRdjmtqMReSl1+C3FL3hcGaPZg ZIOUCtBLAQT98HivUkSssllxEogYYKEfInBlTDs/di2z4C1rln+6CcLRZ3GNAIyCFTyd aWfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Qf4bX1ko; 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 s18si11097004edr.249.2021.03.15.06.35.51; Mon, 15 Mar 2021 06:35:51 -0700 (PDT) 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=Qf4bX1ko; 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 S229780AbhCONfS (ORCPT + 8 others); Mon, 15 Mar 2021 09:35:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39296 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229636AbhCONfE (ORCPT ); Mon, 15 Mar 2021 09:35:04 -0400 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 D05A6C06174A for ; Mon, 15 Mar 2021 06:35:03 -0700 (PDT) Received: by mail-io1-xd2b.google.com with SMTP id w11so7578617iol.13 for ; Mon, 15 Mar 2021 06:35:03 -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=a5fPLpnmRYKCCGzy3IvCXfKkaVbI3lZUkXb2iTfRIc4=; b=Qf4bX1koH8aDNSOhdjjfxdweABS28diydyKTn8jEP2JSfXgSZBpQPIRvTg81GOyRmc jECxRjOUZkO3RuW8K6RBvT6VHaI4YSzWWcvGe/l/85MxKxH1/1m5q0JI4/05LA6rZ7xW j/vGFQ8DF2ydgK1RxD6Q0vgPpqCJGN0dmywLbJ7R/MpIG5AoS49HVABA3f4UN/+y8aSX +Jqa42HRI67eEYes3Wco9wmys6P3Y9MYOc5BX+vY0IX1Dj0s3d4CF/UjoZSdkiKpYh0C wzOYhsad1tStUZpafRi5Nyv7nuVsooguOJSIwk2ozQW35Dsq2OsKBgBMrwKegmfkcxoY tzLQ== 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=a5fPLpnmRYKCCGzy3IvCXfKkaVbI3lZUkXb2iTfRIc4=; b=E9dCAqttUml0aR0AaCBCD5oZbtw2z4UIw7NcRcg7XgntIvIYInBQt4Ib467OLzBY8u xuRwi1yi8SOprmMqWGmoacSVsXHHHj2MViCwvXxSZk1nQvH7vG5mDOG1x+pdLWcn0FXR S0yH97Azw/IzD1o9u5P1ToCknGpNsqlujjZfaIFhknnuCnNbQQ1DakUDdElbs2cXWl+Z SxeWYaAxcT9PX+J3oDHcYvzaNje8OuAiI3btTBmUk9m2zhn14a41p2fXb/6wumzG7ipW VPIfQLbONr40GMjhLgpkWvgsaszbuuecG4Lnv3gEctnKucBNx+9uDIhIhJEKtyuMhqvz rx/w== X-Gm-Message-State: AOAM532251h7ppo5eEx8bA4Wnq0+S2pNwCHOtIOrc0uC+XwXFEIt7IwN ie3rtf+leC6qRmhIx48v3ZdNJg== X-Received: by 2002:a05:6638:2a3:: with SMTP id d3mr9849917jaq.42.1615815303313; Mon, 15 Mar 2021 06:35:03 -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 o23sm7127672ioo.24.2021.03.15.06.35.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Mar 2021 06:35:03 -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, elder@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v4 4/6] net: qualcomm: rmnet: use masks instead of C bit-fields Date: Mon, 15 Mar 2021 08:34:53 -0500 Message-Id: <20210315133455.1576188-5-elder@linaro.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210315133455.1576188-1-elder@linaro.org> References: <20210315133455.1576188-1-elder@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org The actual layout of bits defined in C bit-fields (e.g. int foo : 3) is implementation-defined. Structures defined in address this by specifying all bit-fields twice, to cover two possible layouts. I think this pattern is repetitive and noisy, and I find the whole notion of compiler "bitfield endianness" to be non-intuitive. Stop using C bit-fields for the command/data flag and the pad length fields in the rmnet_map structure, and define a single-byte flags field instead. Define a mask for the single bit "command" flag, 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 --- 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(-) -- 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..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 fd55269c2ce3c..3c3307949db00 100644 --- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c +++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c @@ -286,6 +286,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) @@ -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 = 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 13:34:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 400434 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp3424778jai; Mon, 15 Mar 2021 06:35:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw0dKFZcxnW7BOV5hLeCPQ71uGIiKv4qOtNiu7LQWjmXKKKguLByIulBdZ87CQuo1G3cSyt X-Received: by 2002:a17:907:7699:: with SMTP id jv25mr22241111ejc.363.1615815350632; Mon, 15 Mar 2021 06:35:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615815350; cv=none; d=google.com; s=arc-20160816; b=DkqXDbQnNIAnV3lZjcHSz9VfgHMS32nVlQ82sFUdtea86hl4Udu/2UXFcWT0LtzRXK 4p/G18xHnoycJhOBi56I/N6xya0oHLO4gvY+m9YGFVsysZ7aSNKCpGax4X49EgzF5gWJ QOkyQ3zXolZ577prrSDLp56iIKUexj28Lz9pBMg44LPl/uhDWKn6P/ox71JfN2J7BK9j 4jD+VeTyG6k9PerGWebBVL9m3pkS2kYnMI3yL+Bpt2a89VFzVhBhWF/7WYCI2phGvQw6 aItJLB7wEF4UvICy3C2UHnuN6z+fLJ2eBJjYYKmVNd2XYYF5VQhSmb5cvQRM+YatQ2rY 88VA== 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=e5ukPamWfSMWajj2pGN9CHr8brD2zi1Azop7dU5O7zI=; b=b1NirWl7eYanoaEmxHfYbRX4O77VZ5NlSXmExMzUWUtbsPe533re0ifZ8NhMLBRi+P VwUFEbNP6TZz7OMkkdIoKV/vqBrKvnN7f2wJ+NqBC28xYpsxdYJ4x3ITfZaYC7Fodf9H 8O225EW89h4xlqNvVuGrMs5aatgfLT00mZMAEhzMBokWYXtN7PL9tnvInQ5nacKH4MGG XcQrGNRMGhJBdZXQ9Esb7s1/ycaQ93mRMJsv/TSyqC4PmuDG+eHFOBZdVVnH5QSYu/fx P3qNd7X12EmAara3/xhIU7QPb9j9CN+moS1hCe14eXS60+dZK/uu/NxCEOer/RWQ/zIg m6MQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cTyJVvPK; 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 s18si11097004edr.249.2021.03.15.06.35.50; Mon, 15 Mar 2021 06:35:50 -0700 (PDT) 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=cTyJVvPK; 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 S229754AbhCONfR (ORCPT + 8 others); Mon, 15 Mar 2021 09:35:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39306 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229637AbhCONfE (ORCPT ); Mon, 15 Mar 2021 09:35:04 -0400 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 CD673C06174A for ; Mon, 15 Mar 2021 06:35:04 -0700 (PDT) Received: by mail-io1-xd2b.google.com with SMTP id y20so15012917iot.4 for ; Mon, 15 Mar 2021 06:35:04 -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=e5ukPamWfSMWajj2pGN9CHr8brD2zi1Azop7dU5O7zI=; b=cTyJVvPKlSorpCZKc4vJ0k+XaRwOm0r5EzNKlRugLWtCGEDT8UFduPyDw2SyfKWji+ rxJctXOfR3KNPC09pdvyBSkQZciR1Y3xUjEO1tSaqoeT1tR5Wl7MXU5pycpNbLDmkKpZ JHooao4mD3pO69VOzVJ8Pvxe4cvBTYgOc1WNVs2PGCWSqyb/PoJwb0H6pBv1NYEb3I4I goLGJbBToaChIIWNNJScEjBMC8/ymJS4WyOVDVv1dGMwx95mo/LLDYa+Ndw0mhkgwhyy agkYCxHAfOt1+fzep4rtj7YqB9tHSet6EgRaeWiB+N5uSPukS5RQTDYKrrPM4yV2Bj5d q5zw== 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=e5ukPamWfSMWajj2pGN9CHr8brD2zi1Azop7dU5O7zI=; b=K1bSxTf9F91ugOiR1VrwETOHZwBfaTxKn3fgxFrCzsIDTotz3JpzZYEanvTvJejpcN 1d8urlNCyzx7ozqZZASTd+J9zrf8/sJ7oUY918ya9QolFDsdOcw6E3ErHsZ/GnE16o23 9Ay9Qenmnw+I15G0yj6KnOJ9W9nDfLT/c7QNcw70caA7NasjystBBBAgMKOuitQjBy7M Fo6AreFsPY2IekuuIjO4EZZw308/2sA62b6zaHWE8KbsYFAxiOLstV1HskileF0GyXNp sgM4wtIZGmnZupMzdKnRu9ij9WbQ9wXQxrnvabAB5tyc0DtlDJEAFm2Ddg22IKexuRYc 97rw== X-Gm-Message-State: AOAM533HH2he8BlimcDRuGuQkdJeeH/RVYHrWs6yeENMGkbkpAd6SsUv WT0B7k2wJuFSGWnICwUrlRSbuw== X-Received: by 2002:a02:3c01:: with SMTP id m1mr9259223jaa.87.1615815304301; Mon, 15 Mar 2021 06:35:04 -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 o23sm7127672ioo.24.2021.03.15.06.35.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Mar 2021 06:35:04 -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, elder@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v4 5/6] net: qualcomm: rmnet: don't use C bit-fields in rmnet checksum trailer Date: Mon, 15 Mar 2021 08:34:54 -0500 Message-Id: <20210315133455.1576188-6-elder@linaro.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210315133455.1576188-1-elder@linaro.org> References: <20210315133455.1576188-1-elder@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Replace the use of C bit-fields in the rmnet_map_dl_csum_trailer structure with a single one-byte field, using constant field masks to encode or get at embedded values. Signed-off-by: Alex Elder Reviewed-by: Bjorn Andersson --- v3: - Use BIT(x) and don't use u8_get_bits() for the checksum valid flag .../ethernet/qualcomm/rmnet/rmnet_map_data.c | 2 +- include/linux/if_rmnet.h | 17 +++++++---------- 2 files changed, 8 insertions(+), 11 deletions(-) -- 2.27.0 diff --git a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c index 3c3307949db00..3df23365497c4 100644 --- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c +++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c @@ -365,7 +365,7 @@ int rmnet_map_checksum_downlink_packet(struct sk_buff *skb, u16 len) csum_trailer = (struct rmnet_map_dl_csum_trailer *)(skb->data + len); - if (!csum_trailer->valid) { + if (!(csum_trailer->flags & MAP_CSUM_DL_VALID_FLAG)) { priv->stats.csum_valid_unset++; return -EINVAL; } diff --git a/include/linux/if_rmnet.h b/include/linux/if_rmnet.h index 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 13:34:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 400435 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp3424787jai; Mon, 15 Mar 2021 06:35:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzmYpkCWjt94fN6qOOifDQkXBhjLh4BUGkao77cwIDF7w6xGe6zPSh4PFGDUh27/z2ZPOof X-Received: by 2002:a17:906:4d96:: with SMTP id s22mr23627316eju.189.1615815351400; Mon, 15 Mar 2021 06:35:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615815351; cv=none; d=google.com; s=arc-20160816; b=eKENwuBtFzZ7W+YN+oBXPpfmVYrPxkSYHF4cWLL1xXLVSX5zIW2oPhL0EZ5gO2cFKk 2eX1MCnD8KjD73UCgqpWNVpRjz6pANOg42SvEOQB8+CfeiabICAtW5QfnUxtZ1thTCqC ujWoqBFULvjA+dL/N7+JpFYBpjXMhyE3XBZOaki8fYe0E+dUo/naa+4NhNoQJjY8QEqz Je0tx89EyTFHloCZq7M2xLs+Cmv97JSdWKdGYjtsg9Wt7LBIky0svIdPklWAm2Gikct8 Ljz5YrMe7hRCHaPEm3KRElC+mO4Y8593Vf5yBPiS1Ceq+irBM3zGTDBXewNqI/6DOx7W eKEw== 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=9wMFcNuOVXwXfZ6AijxvuqRZ/xlVmx3dzuXhVIw9piE=; b=KqBEL+GiOMydWQdS58vbLIDTf7AXXpnllDl1s09eKUrYF4OKW/uNw2gmmyFMyXoKq5 8dB+HDYXru0SJ1TmHoqjgVCoRn9DXEGs+x0nS0lGuuDNh8GNqEVakso/O/Ket/guvaOx O7uiNkX8FlSAPigqgm+oXvdMgAXRVOETI5ffv5G4UlXDoJsa+KI9DzAwYujr3use4K9v wCsj6XS/fToFeZimG6MoHfJyQ4VMv/mplgAQSks/HkBGJ6X2KKKFSHfiJZrm0/pF8D/s zuYQeWtWdUDQzdzZoXDRefbewPOa7I0Ni1KkxZN5bhZpn4/PzMOXNDzLYt+GWLkZ4zf3 6LUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VFz1SVaL; 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 s18si11097004edr.249.2021.03.15.06.35.51; Mon, 15 Mar 2021 06:35:51 -0700 (PDT) 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=VFz1SVaL; 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 S229806AbhCONfT (ORCPT + 8 others); Mon, 15 Mar 2021 09:35:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39312 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229646AbhCONfF (ORCPT ); Mon, 15 Mar 2021 09:35:05 -0400 Received: from mail-io1-xd33.google.com (mail-io1-xd33.google.com [IPv6:2607:f8b0:4864:20::d33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CAE2FC06175F for ; Mon, 15 Mar 2021 06:35:05 -0700 (PDT) Received: by mail-io1-xd33.google.com with SMTP id n14so33368000iog.3 for ; Mon, 15 Mar 2021 06:35:05 -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=9wMFcNuOVXwXfZ6AijxvuqRZ/xlVmx3dzuXhVIw9piE=; b=VFz1SVaLgdPj7f1Blere5/zlo9Q2YANYLg/vbJnJntFNyuwjMP/xLfvubtjZB8V/Sm AWYVcK9wHMxEyQKxhVbWC4Csp2U8QUyrGzeCUfsOSa3jqn+ZKnWfRnvja/9vj7hJzxXK Y+wvB5WEtZHOUlvJzgo3Vg/KFMmcaHNBNWe6HlCm4QWQah72mv0s5o8CWnbBZTW2NYAX CDtHvYz9hf1ZjA3koZAwhW4Hul+LfGZPSGV1QOUnCLkswPKBtjPOvIFKIDNG+TRwje4d lWSEbKgpXo0q2zJ1aICH+Gsdc74CZSLbEp7ioUzhW2UhHkn7XZo13GkAG+fzRzjpeR2D IShw== 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=9wMFcNuOVXwXfZ6AijxvuqRZ/xlVmx3dzuXhVIw9piE=; b=Rd7VRJy5haCiN4YcgEMhMfFNI796QpzoqTYSUnL0FwKdRgmGlk4UmysJCetAUI0+6O 80/lZiUF8U6PcYwev5TZiPfPBvnj3ygUbNpPWp0GEoa7ytSH1l6+cGSk2EmvZSj2e/wb KMrY9557K0hHAfEt7XNXfKtW4DfmA+BzOZ6weYwmbLlSOPcUGURtLtFvECahw4oWyGS4 YXKzi3ptKBMcPOXf9Hk6qCUSsYM+SG1B6gQ4eUPZvfbSE/82pqFNGQJ6E0zGaFqj+FI5 jUlh9FMdkfeaTFkvfhHP34/GgGlsiiSrV5gqA/ey3FagUsGFApRV5OlaEjME3vl/ZVh2 UMYg== X-Gm-Message-State: AOAM530fKYTfePxKI1uFr5PuSPD8/I1oa6a+mpBA/ldw3IQpOLtdPKVw QTsiSySrEXTBsAeT8NeaKdd2YA== X-Received: by 2002:a5d:93c2:: with SMTP id j2mr7444285ioo.166.1615815305317; Mon, 15 Mar 2021 06:35:05 -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 o23sm7127672ioo.24.2021.03.15.06.35.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Mar 2021 06:35:05 -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, elder@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v4 6/6] net: qualcomm: rmnet: don't use C bit-fields in rmnet checksum header Date: Mon, 15 Mar 2021 08:34:55 -0500 Message-Id: <20210315133455.1576188-7-elder@linaro.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210315133455.1576188-1-elder@linaro.org> References: <20210315133455.1576188-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 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 --- 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 | 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 3df23365497c4..bdb6ab6dad83d 100644 --- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c +++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c @@ -197,23 +197,19 @@ rmnet_map_ipv4_ul_csum_header(void *iphdr, struct rmnet_map_ul_csum_header *ul_header, struct sk_buff *skb) { - __be16 *hdr = (__be16 *)ul_header; struct iphdr *ip4h = iphdr; u16 offset; + u16 val; offset = skb_transport_header(skb) - (unsigned char *)iphdr; ul_header->csum_start_offset = htons(offset); - ul_header->csum_insert_offset = skb->csum_offset; - ul_header->csum_enabled = 1; + val = MAP_CSUM_UL_ENABLED_FLAG; if (ip4h->protocol == IPPROTO_UDP) - ul_header->udp_ind = 1; - else - ul_header->udp_ind = 0; + val |= MAP_CSUM_UL_UDP_FLAG; + val |= skb->csum_offset & MAP_CSUM_UL_OFFSET_MASK; - /* Changing remaining fields to network order */ - hdr++; - *hdr = htons((__force u16)*hdr); + ul_header->csum_info = htons(val); skb->ip_summed = CHECKSUM_NONE; @@ -240,24 +236,19 @@ rmnet_map_ipv6_ul_csum_header(void *ip6hdr, struct rmnet_map_ul_csum_header *ul_header, struct sk_buff *skb) { - __be16 *hdr = (__be16 *)ul_header; struct ipv6hdr *ip6h = ip6hdr; u16 offset; + u16 val; offset = skb_transport_header(skb) - (unsigned char *)ip6hdr; ul_header->csum_start_offset = htons(offset); - ul_header->csum_insert_offset = skb->csum_offset; - ul_header->csum_enabled = 1; - + val = MAP_CSUM_UL_ENABLED_FLAG; if (ip6h->nexthdr == IPPROTO_UDP) - ul_header->udp_ind = 1; - else - ul_header->udp_ind = 0; + val |= MAP_CSUM_UL_UDP_FLAG; + val |= skb->csum_offset & MAP_CSUM_UL_OFFSET_MASK; - /* 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 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_) */