[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20191230143028.27313-8-alobakin@dlink.ru>
Date: Mon, 30 Dec 2019 17:30:15 +0300
From: Alexander Lobakin <alobakin@...nk.ru>
To: "David S. Miller" <davem@...emloft.net>
Cc: Edward Cree <ecree@...arflare.com>, Andrew Lunn <andrew@...n.ch>,
Vivien Didelot <vivien.didelot@...il.com>,
Florian Fainelli <f.fainelli@...il.com>,
Hauke Mehrtens <hauke@...ke-m.de>,
Sean Wang <sean.wang@...iatek.com>,
Matthias Brugger <matthias.bgg@...il.com>,
Jiri Pirko <jiri@...lanox.com>,
Eric Dumazet <edumazet@...gle.com>,
Paolo Abeni <pabeni@...hat.com>,
Jakub Kicinski <jakub.kicinski@...ronome.com>,
Alexander Lobakin <alobakin@...nk.ru>,
Taehee Yoo <ap420073@...il.com>,
Stephen Hemminger <stephen@...workplumber.org>,
Stanislav Fomichev <sdf@...gle.com>,
Daniel Borkmann <daniel@...earbox.net>,
Song Liu <songliubraving@...com>,
Matteo Croce <mcroce@...hat.com>,
Jakub Sitnicki <jakub@...udflare.com>,
Paul Blakey <paulb@...lanox.com>,
Yoshiki Komachi <komachi.yoshiki@...il.com>,
netdev@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-arm-kernel@...ts.infradead.org,
linux-mediatek@...ts.infradead.org
Subject: [PATCH RFC net-next 07/19] net: dsa: tag_gswip: switch to bitfield helpers
Make code look cleaner and more readable by using bitfield macros instead
of open-coding masks and shifts.
Misc: remove redundant variable in gswip_tag_xmit(), make dsa_port const.
Signed-off-by: Alexander Lobakin <alobakin@...nk.ru>
---
net/dsa/tag_gswip.c | 24 +++++++++---------------
1 file changed, 9 insertions(+), 15 deletions(-)
diff --git a/net/dsa/tag_gswip.c b/net/dsa/tag_gswip.c
index 408d4af390a0..de920f6aac5b 100644
--- a/net/dsa/tag_gswip.c
+++ b/net/dsa/tag_gswip.c
@@ -5,6 +5,7 @@
* Copyright (C) 2017 - 2018 Hauke Mehrtens <hauke@...ke-m.de>
*/
+#include <linux/bitfield.h>
#include <linux/bitops.h>
#include <linux/etherdevice.h>
#include <linux/skbuff.h>
@@ -45,26 +46,22 @@
#define GSWIP_TX_CLASS_MASK GENMASK(3, 0)
/* Byte 3 */
+#define GSWIP_TX_PORT_MAP(port) FIELD_PREP(GENMASK(6, 1), BIT(port))
#define GSWIP_TX_DPID_EN BIT(0)
-#define GSWIP_TX_PORT_MAP_SHIFT 1
-#define GSWIP_TX_PORT_MAP_MASK GENMASK(6, 1)
-#define GSWIP_RX_HEADER_LEN 8
+#define GSWIP_RX_HEADER_LEN 8
/* special tag in RX path header */
/* Byte 7 */
-#define GSWIP_RX_SPPID_SHIFT 4
-#define GSWIP_RX_SPPID_MASK GENMASK(6, 4)
+#define GSWIP_RX_SPPID(byte_7) FIELD_GET(GENMASK(6, 4), byte_7)
static struct sk_buff *gswip_tag_xmit(struct sk_buff *skb,
struct net_device *dev)
{
- struct dsa_port *dp = dsa_slave_to_port(dev);
- int err;
+ const struct dsa_port *dp = dsa_slave_to_port(dev);
u8 *gswip_tag;
- err = skb_cow_head(skb, GSWIP_TX_HEADER_LEN);
- if (err)
+ if (skb_cow_head(skb, GSWIP_TX_HEADER_LEN))
return NULL;
skb_push(skb, GSWIP_TX_HEADER_LEN);
@@ -73,8 +70,7 @@ static struct sk_buff *gswip_tag_xmit(struct sk_buff *skb,
gswip_tag[0] = GSWIP_TX_SLPID_CPU;
gswip_tag[1] = GSWIP_TX_DPID_ELAN;
gswip_tag[2] = GSWIP_TX_PORT_MAP_EN | GSWIP_TX_PORT_MAP_SEL;
- gswip_tag[3] = BIT(dp->index + GSWIP_TX_PORT_MAP_SHIFT) & GSWIP_TX_PORT_MAP_MASK;
- gswip_tag[3] |= GSWIP_TX_DPID_EN;
+ gswip_tag[3] = GSWIP_TX_PORT_MAP(dp->index) | GSWIP_TX_DPID_EN;
return skb;
}
@@ -84,15 +80,13 @@ static struct sk_buff *gswip_tag_rcv(struct sk_buff *skb,
struct packet_type *pt)
{
int port;
- u8 *gswip_tag;
if (unlikely(!pskb_may_pull(skb, GSWIP_RX_HEADER_LEN)))
return NULL;
- gswip_tag = skb->data - ETH_HLEN;
-
/* Get source port information */
- port = (gswip_tag[7] & GSWIP_RX_SPPID_MASK) >> GSWIP_RX_SPPID_SHIFT;
+ port = GSWIP_RX_SPPID(*(skb->data - ETH_HLEN + 7));
+
skb->dev = dsa_master_find_slave(dev, 0, port);
if (!skb->dev)
return NULL;
--
2.24.1
Powered by blists - more mailing lists