lkml.org 
[lkml]   [2019]   [Dec]   [30]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH RFC net-next 04/19] net: dsa: tag_ar9331: split out common tag accessors
Date
They will be reused in upcoming GRO callbacks.
(Almost) no functional changes except less informative error string.

Signed-off-by: Alexander Lobakin <alobakin@dlink.ru>
---
net/dsa/tag_ar9331.c | 46 +++++++++++++++++++++++++++-----------------
1 file changed, 28 insertions(+), 18 deletions(-)

diff --git a/net/dsa/tag_ar9331.c b/net/dsa/tag_ar9331.c
index 399ca21ec03b..c22c1b515e02 100644
--- a/net/dsa/tag_ar9331.c
+++ b/net/dsa/tag_ar9331.c
@@ -24,6 +24,25 @@
#define AR9331_HDR_RESERVED_MASK GENMASK(5, 4)
#define AR9331_HDR_PORT_NUM_MASK GENMASK(3, 0)

+static inline bool ar9331_tag_sanity_check(const u8 *data)
+{
+ u16 hdr = le16_to_cpup((__le16 *)(data - ETH_HLEN));
+
+ return FIELD_GET(AR9331_HDR_VERSION_MASK, hdr) == AR9331_HDR_VERSION &&
+ !(hdr & AR9331_HDR_FROM_CPU);
+}
+
+static inline int ar9331_tag_source_port(const u8 *data)
+{
+ /* hdr comes in LE byte order, so srcport field is in the first byte */
+ return FIELD_GET(AR9331_HDR_PORT_NUM_MASK, *(data - ETH_HLEN));
+}
+
+static inline __be16 ar9331_tag_encap_proto(const u8 *data)
+{
+ return *(__be16 *)data;
+}
+
static struct sk_buff *ar9331_tag_xmit(struct sk_buff *skb,
struct net_device *dev)
{
@@ -50,36 +69,27 @@ static struct sk_buff *ar9331_tag_rcv(struct sk_buff *skb,
struct net_device *ndev,
struct packet_type *pt)
{
- u8 ver, port;
- u16 hdr;
+ int port;

if (unlikely(!pskb_may_pull(skb, AR9331_HDR_LEN)))
return NULL;

- hdr = le16_to_cpu(*(__le16 *)skb_mac_header(skb));
-
- ver = FIELD_GET(AR9331_HDR_VERSION_MASK, hdr);
- if (unlikely(ver != AR9331_HDR_VERSION)) {
- netdev_warn_once(ndev, "%s:%i wrong header version 0x%2x\n",
- __func__, __LINE__, hdr);
- return NULL;
- }
-
- if (unlikely(hdr & AR9331_HDR_FROM_CPU)) {
- netdev_warn_once(ndev, "%s:%i packet should not be from cpu 0x%2x\n",
- __func__, __LINE__, hdr);
+ if (unlikely(!ar9331_tag_sanity_check(skb->data))) {
+ netdev_warn_once(ndev,
+ "%s:%i wrong header version or source port\n",
+ __func__, __LINE__);
return NULL;
}

- skb_pull_rcsum(skb, AR9331_HDR_LEN);
-
/* Get source port information */
- port = FIELD_GET(AR9331_HDR_PORT_NUM_MASK, hdr);
+ port = ar9331_tag_source_port(skb->data);

skb->dev = dsa_master_find_slave(ndev, 0, port);
if (!skb->dev)
return NULL;

+ skb_pull_rcsum(skb, AR9331_HDR_LEN);
+
return skb;
}

@@ -87,7 +97,7 @@ static void ar9331_tag_flow_dissect(const struct sk_buff *skb, __be16 *proto,
int *offset)
{
*offset = AR9331_HDR_LEN;
- *proto = *(__be16 *)skb->data;
+ *proto = ar9331_tag_encap_proto(skb->data);
}

static const struct dsa_device_ops ar9331_netdev_ops = {
--
2.24.1
\
 
 \ /
  Last update: 2019-12-30 15:32    [W:0.126 / U:1.580 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site