From: Alex Elder <elder@linaro.org>
To: arnd@arndb.de, subashab@codeaurora.org, david.brown@linaro.org,
agross@kernel.org, davem@davemloft.net
Cc: syadagir@codeaurora.org, ejcaruso@google.com,
netdev@vger.kernel.org, ilias.apalodimas@linaro.org,
linux-kernel@vger.kernel.org, evgreen@chromium.org,
bjorn.andersson@linaro.org, linux-arm-kernel@lists.infradead.org,
linux-arm-msm@vger.kernel.org, cpratapa@codeaurora.org,
benchan@google.com
Subject: [PATCH 3/8] net: qualcomm: rmnet: use field masks instead of C bit-fields
Date: Mon, 20 May 2019 08:53:49 -0500 [thread overview]
Message-ID: <20190520135354.18628-4-elder@linaro.org> (raw)
In-Reply-To: <20190520135354.18628-1-elder@linaro.org>
Using C bitfields (e.g. int foo : 3) is not portable. So stop
using them for the command/data flag and the pad length fields in
the rmnet_map structure. Instead, use the functions defined in
<linux/bitfield.h> along with field mask constants to extract or
assign values within an integral structure member of a known size.
Signed-off-by: Alex Elder <elder@linaro.org>
---
drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c | 5 +++--
drivers/net/ethernet/qualcomm/rmnet/rmnet_map.h | 8 +++++---
drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c | 5 ++++-
3 files changed, 12 insertions(+), 6 deletions(-)
diff --git a/drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c b/drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c
index 4c1b62b72504..5fff6c78ecd5 100644
--- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c
+++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c
@@ -13,6 +13,7 @@
*
*/
+#include <linux/bitfield.h>
#include <linux/netdevice.h>
#include <linux/netdev_features.h>
#include <linux/if_arp.h>
@@ -70,7 +71,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->cmd_pad_len, RMNET_MAP_CMD_FMASK)) {
if (port->data_format & RMNET_FLAGS_INGRESS_MAP_COMMANDS)
return rmnet_map_command(skb, port);
@@ -78,7 +79,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->cmd_pad_len, RMNET_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.h b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map.h
index a30a7b405a11..a56209645c81 100644
--- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map.h
+++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map.h
@@ -40,13 +40,15 @@ enum rmnet_map_commands {
};
struct rmnet_map_header {
- u8 cd_bit:1;
- u8 reserved_bit:1;
- u8 pad_len:6;
+ u8 cmd_pad_len; /* RMNET_MAP_* */
u8 mux_id;
__be16 pkt_len;
} __aligned(1);
+#define RMNET_MAP_CMD_FMASK GENMASK(0, 0) /* 0: data; 1: cmd */
+#define RMNET_MAP_RESERVED_FMASK GENMASK(1, 1)
+#define RMNET_MAP_PAD_LEN_FMASK GENMASK(7, 2)
+
struct rmnet_map_dl_csum_trailer {
u8 reserved1;
u8 valid:1;
diff --git a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c
index 498f20ba1826..10d2d582a9ce 100644
--- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c
+++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c
@@ -13,6 +13,7 @@
*
*/
+#include <linux/bitfield.h>
#include <linux/netdevice.h>
#include <linux/ip.h>
#include <linux/ipv6.h>
@@ -301,7 +302,9 @@ 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 cmd field is 0 */
+ map_header->cmd_pad_len =
+ u8_encode_bits(padding, RMNET_MAP_PAD_LEN_FMASK);
return map_header;
}
--
2.20.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2019-05-20 13:54 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-20 13:53 [PATCH 0/8] net: introduce "include/linux/if_rmnet.h" Alex Elder
2019-05-20 13:53 ` [PATCH 1/8] net: qualcomm: rmnet: fix struct rmnet_map_header Alex Elder
2019-05-20 15:38 ` Bjorn Andersson
2019-05-20 20:11 ` Subash Abhinov Kasiviswanathan
2019-05-20 21:23 ` Alex Elder
2019-05-21 1:32 ` Subash Abhinov Kasiviswanathan
2019-05-21 2:30 ` Alex Elder
2019-05-21 3:07 ` Bjorn Andersson
2019-05-21 11:03 ` Alex Elder
2019-05-20 13:53 ` [PATCH 2/8] net: qualcomm: rmnet: kill RMNET_MAP_GET_*() accessor macros Alex Elder
2019-05-20 15:41 ` Bjorn Andersson
2019-05-20 13:53 ` Alex Elder [this message]
2019-05-20 15:43 ` [PATCH 3/8] net: qualcomm: rmnet: use field masks instead of C bit-fields Bjorn Andersson
2019-05-20 13:53 ` [PATCH 4/8] net: qualcomm: rmnet: don't use C bit-fields in rmnet checksum header Alex Elder
2019-05-20 15:49 ` Bjorn Andersson
2019-05-20 13:53 ` [PATCH 5/8] net: qualcomm: rmnet: don't use C bit-fields in rmnet checksum trailer Alex Elder
2019-05-20 17:17 ` Bjorn Andersson
2019-05-20 13:53 ` [PATCH 6/8] net: qualcomm: rmnet: get rid of a variable in rmnet_map_ipv4_ul_csum_header() Alex Elder
2019-05-20 17:17 ` Bjorn Andersson
2019-05-20 13:53 ` [PATCH 7/8] net: qualcomm: rmnet: mark endianness of struct rmnet_map_dl_csum_trailer fields Alex Elder
2019-05-20 17:17 ` Bjorn Andersson
2019-05-20 13:53 ` [PATCH 8/8] net: introduce "include/linux/if_rmnet.h" Alex Elder
2019-05-20 17:18 ` Bjorn Andersson
2019-05-20 18:00 ` [PATCH 0/8] " Alex Elder
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190520135354.18628-4-elder@linaro.org \
--to=elder@linaro.org \
--cc=agross@kernel.org \
--cc=arnd@arndb.de \
--cc=benchan@google.com \
--cc=bjorn.andersson@linaro.org \
--cc=cpratapa@codeaurora.org \
--cc=davem@davemloft.net \
--cc=david.brown@linaro.org \
--cc=ejcaruso@google.com \
--cc=evgreen@chromium.org \
--cc=ilias.apalodimas@linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=subashab@codeaurora.org \
--cc=syadagir@codeaurora.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).