All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Lunn <andrew@lunn.ch>
To: David Miller <davem@davemloft.net>
Cc: netdev <netdev@vger.kernel.org>,
	Florian Fainelli <f.fainelli@gmail.com>,
	Vivien Didelot <vivien.didelot@gmail.com>,
	Andrew Lunn <andrew@lunn.ch>
Subject: [PATCH net-next 02/15] dsa: Move tagger name into its ops structure
Date: Thu, 18 Apr 2019 04:31:07 +0200	[thread overview]
Message-ID: <20190418023120.17067-3-andrew@lunn.ch> (raw)
In-Reply-To: <20190418023120.17067-1-andrew@lunn.ch>

Rather than keep a list to map a tagger ops to a name, place the name
into the ops structure. This removes the hard coded list, a stop
towards making the taggers more dynamic.

Signed-off-by: Andrew Lunn <andrew@lunn.ch>
---
 include/net/dsa.h     |  1 +
 net/dsa/dsa.c         | 45 ++-----------------------------------------
 net/dsa/tag_brcm.c    |  2 ++
 net/dsa/tag_dsa.c     |  1 +
 net/dsa/tag_edsa.c    |  1 +
 net/dsa/tag_gswip.c   |  1 +
 net/dsa/tag_ksz.c     |  2 ++
 net/dsa/tag_lan9303.c |  1 +
 net/dsa/tag_mtk.c     |  1 +
 net/dsa/tag_qca.c     |  1 +
 net/dsa/tag_trailer.c |  1 +
 11 files changed, 14 insertions(+), 43 deletions(-)

diff --git a/include/net/dsa.h b/include/net/dsa.h
index 0cfc2f828b87..9bcbbde0f61d 100644
--- a/include/net/dsa.h
+++ b/include/net/dsa.h
@@ -50,6 +50,7 @@ struct packet_type;
 struct dsa_switch;
 
 struct dsa_device_ops {
+	const char *name;
 	struct sk_buff *(*xmit)(struct sk_buff *skb, struct net_device *dev);
 	struct sk_buff *(*rcv)(struct sk_buff *skb, struct net_device *dev,
 			       struct packet_type *pt);
diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c
index 36de4f2a3366..92b3cd129eb7 100644
--- a/net/dsa/dsa.c
+++ b/net/dsa/dsa.c
@@ -35,6 +35,7 @@ static struct sk_buff *dsa_slave_notag_xmit(struct sk_buff *skb,
 }
 
 static const struct dsa_device_ops none_ops = {
+	.name	= "none",
 	.xmit	= dsa_slave_notag_xmit,
 	.rcv	= NULL,
 };
@@ -76,49 +77,7 @@ const struct dsa_device_ops *dsa_device_ops[DSA_TAG_LAST] = {
 
 const char *dsa_tag_protocol_to_str(const struct dsa_device_ops *ops)
 {
-	const char *protocol_name[DSA_TAG_LAST] = {
-#ifdef CONFIG_NET_DSA_TAG_BRCM
-		[DSA_TAG_PROTO_BRCM] = "brcm",
-#endif
-#ifdef CONFIG_NET_DSA_TAG_BRCM_PREPEND
-		[DSA_TAG_PROTO_BRCM_PREPEND] = "brcm-prepend",
-#endif
-#ifdef CONFIG_NET_DSA_TAG_DSA
-		[DSA_TAG_PROTO_DSA] = "dsa",
-#endif
-#ifdef CONFIG_NET_DSA_TAG_EDSA
-		[DSA_TAG_PROTO_EDSA] = "edsa",
-#endif
-#ifdef CONFIG_NET_DSA_TAG_GSWIP
-		[DSA_TAG_PROTO_GSWIP] = "gswip",
-#endif
-#ifdef CONFIG_NET_DSA_TAG_KSZ9477
-		[DSA_TAG_PROTO_KSZ9477] = "ksz9477",
-		[DSA_TAG_PROTO_KSZ9893] = "ksz9893",
-#endif
-#ifdef CONFIG_NET_DSA_TAG_LAN9303
-		[DSA_TAG_PROTO_LAN9303] = "lan9303",
-#endif
-#ifdef CONFIG_NET_DSA_TAG_MTK
-		[DSA_TAG_PROTO_MTK] = "mtk",
-#endif
-#ifdef CONFIG_NET_DSA_TAG_QCA
-		[DSA_TAG_PROTO_QCA] = "qca",
-#endif
-#ifdef CONFIG_NET_DSA_TAG_TRAILER
-		[DSA_TAG_PROTO_TRAILER] = "trailer",
-#endif
-		[DSA_TAG_PROTO_NONE] = "none",
-	};
-	unsigned int i;
-
-	BUILD_BUG_ON(ARRAY_SIZE(protocol_name) != DSA_TAG_LAST);
-
-	for (i = 0; i < ARRAY_SIZE(dsa_device_ops); i++)
-		if (ops == dsa_device_ops[i])
-			return protocol_name[i];
-
-	return protocol_name[DSA_TAG_PROTO_NONE];
+	return ops->name;
 };
 
 const struct dsa_device_ops *dsa_resolve_tag_protocol(int tag_protocol)
diff --git a/net/dsa/tag_brcm.c b/net/dsa/tag_brcm.c
index b3063e7adb73..1b7dfbe6b3ae 100644
--- a/net/dsa/tag_brcm.c
+++ b/net/dsa/tag_brcm.c
@@ -168,6 +168,7 @@ static struct sk_buff *brcm_tag_rcv(struct sk_buff *skb, struct net_device *dev,
 }
 
 const struct dsa_device_ops brcm_netdev_ops = {
+	.name	= "brcm",
 	.xmit	= brcm_tag_xmit,
 	.rcv	= brcm_tag_rcv,
 	.overhead = BRCM_TAG_LEN,
@@ -191,6 +192,7 @@ static struct sk_buff *brcm_tag_rcv_prepend(struct sk_buff *skb,
 }
 
 const struct dsa_device_ops brcm_prepend_netdev_ops = {
+	.name	= "brcm-prepend",
 	.xmit	= brcm_tag_xmit_prepend,
 	.rcv	= brcm_tag_rcv_prepend,
 	.overhead = BRCM_TAG_LEN,
diff --git a/net/dsa/tag_dsa.c b/net/dsa/tag_dsa.c
index fdaf850831e2..e1c90709de6c 100644
--- a/net/dsa/tag_dsa.c
+++ b/net/dsa/tag_dsa.c
@@ -151,6 +151,7 @@ static int dsa_tag_flow_dissect(const struct sk_buff *skb, __be16 *proto,
 }
 
 const struct dsa_device_ops dsa_netdev_ops = {
+	.name	= "dsa",
 	.xmit	= dsa_xmit,
 	.rcv	= dsa_rcv,
 	.flow_dissect   = dsa_tag_flow_dissect,
diff --git a/net/dsa/tag_edsa.c b/net/dsa/tag_edsa.c
index df879445f658..b936b4660b71 100644
--- a/net/dsa/tag_edsa.c
+++ b/net/dsa/tag_edsa.c
@@ -170,6 +170,7 @@ static int edsa_tag_flow_dissect(const struct sk_buff *skb, __be16 *proto,
 }
 
 const struct dsa_device_ops edsa_netdev_ops = {
+	.name	= "edsa",
 	.xmit	= edsa_xmit,
 	.rcv	= edsa_rcv,
 	.flow_dissect   = edsa_tag_flow_dissect,
diff --git a/net/dsa/tag_gswip.c b/net/dsa/tag_gswip.c
index cb6f82ffe5eb..d1c1e7db87b6 100644
--- a/net/dsa/tag_gswip.c
+++ b/net/dsa/tag_gswip.c
@@ -104,6 +104,7 @@ static struct sk_buff *gswip_tag_rcv(struct sk_buff *skb,
 }
 
 const struct dsa_device_ops gswip_netdev_ops = {
+	.name = "gwsip",
 	.xmit = gswip_tag_xmit,
 	.rcv = gswip_tag_rcv,
 	.overhead = GSWIP_RX_HEADER_LEN,
diff --git a/net/dsa/tag_ksz.c b/net/dsa/tag_ksz.c
index 12b2f58786ee..631094599514 100644
--- a/net/dsa/tag_ksz.c
+++ b/net/dsa/tag_ksz.c
@@ -134,6 +134,7 @@ static struct sk_buff *ksz9477_rcv(struct sk_buff *skb, struct net_device *dev,
 }
 
 const struct dsa_device_ops ksz9477_netdev_ops = {
+	.name	= "ksz9477",
 	.xmit	= ksz9477_xmit,
 	.rcv	= ksz9477_rcv,
 	.overhead = KSZ9477_INGRESS_TAG_LEN,
@@ -167,6 +168,7 @@ static struct sk_buff *ksz9893_xmit(struct sk_buff *skb,
 }
 
 const struct dsa_device_ops ksz9893_netdev_ops = {
+	.name	= "ksz9893",
 	.xmit	= ksz9893_xmit,
 	.rcv	= ksz9477_rcv,
 	.overhead = KSZ_INGRESS_TAG_LEN,
diff --git a/net/dsa/tag_lan9303.c b/net/dsa/tag_lan9303.c
index 7bfd3165e46e..67d70339536d 100644
--- a/net/dsa/tag_lan9303.c
+++ b/net/dsa/tag_lan9303.c
@@ -129,6 +129,7 @@ static struct sk_buff *lan9303_rcv(struct sk_buff *skb, struct net_device *dev,
 }
 
 const struct dsa_device_ops lan9303_netdev_ops = {
+	.name = "lan9303",
 	.xmit = lan9303_xmit,
 	.rcv = lan9303_rcv,
 	.overhead = LAN9303_TAG_LEN,
diff --git a/net/dsa/tag_mtk.c b/net/dsa/tag_mtk.c
index 6e06fa621bbc..dc537d9a18c0 100644
--- a/net/dsa/tag_mtk.c
+++ b/net/dsa/tag_mtk.c
@@ -99,6 +99,7 @@ static int mtk_tag_flow_dissect(const struct sk_buff *skb, __be16 *proto,
 }
 
 const struct dsa_device_ops mtk_netdev_ops = {
+	.name		= "mtk",
 	.xmit		= mtk_tag_xmit,
 	.rcv		= mtk_tag_rcv,
 	.flow_dissect	= mtk_tag_flow_dissect,
diff --git a/net/dsa/tag_qca.c b/net/dsa/tag_qca.c
index de3eb1022e21..f62296ffc5b7 100644
--- a/net/dsa/tag_qca.c
+++ b/net/dsa/tag_qca.c
@@ -100,6 +100,7 @@ static int qca_tag_flow_dissect(const struct sk_buff *skb, __be16 *proto,
 }
 
 const struct dsa_device_ops qca_netdev_ops = {
+	.name	= "qca",
 	.xmit	= qca_tag_xmit,
 	.rcv	= qca_tag_rcv,
 	.flow_dissect = qca_tag_flow_dissect,
diff --git a/net/dsa/tag_trailer.c b/net/dsa/tag_trailer.c
index 492a30046281..20ee7f84fe4d 100644
--- a/net/dsa/tag_trailer.c
+++ b/net/dsa/tag_trailer.c
@@ -78,6 +78,7 @@ static struct sk_buff *trailer_rcv(struct sk_buff *skb, struct net_device *dev,
 }
 
 const struct dsa_device_ops trailer_netdev_ops = {
+	.name	= "trailer",
 	.xmit	= trailer_xmit,
 	.rcv	= trailer_rcv,
 	.overhead = 4,
-- 
2.20.1


  parent reply	other threads:[~2019-04-18  2:36 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-18  2:31 [PATCH net-next 00/15] Make DSA tag drivers kernel modules Andrew Lunn
2019-04-18  2:31 ` [PATCH net-next 01/15] dsa: Add SPDX header to tag drivers Andrew Lunn
2019-04-18 17:35   ` Florian Fainelli
2019-04-18  2:31 ` Andrew Lunn [this message]
2019-04-18 17:37   ` [PATCH net-next 02/15] dsa: Move tagger name into its ops structure Florian Fainelli
2019-04-18  2:31 ` [PATCH net-next 03/15] dsa: Add MODULE_ALIAS to taggers in preperation to become modules Andrew Lunn
2019-04-19 15:25   ` Florian Fainelli
2019-04-18  2:31 ` [PATCH net-next 04/15] dsa: Add MODULE_LICENSE to tag drivers Andrew Lunn
2019-04-18 17:51   ` Florian Fainelli
2019-04-18  2:31 ` [PATCH net-next 05/15] dsa: Add TAG protocol to tag ops Andrew Lunn
2019-04-19 15:27   ` Florian Fainelli
2019-04-18  2:31 ` [PATCH net-next 06/15] dsa: Remove const from tag driver ops structure Andrew Lunn
2019-04-18 17:58   ` Florian Fainelli
2019-04-18 21:47     ` Andrew Lunn
2019-04-19 15:26       ` Florian Fainelli
2019-04-18  2:31 ` [PATCH net-next 07/15] dsa: Add boilerplate helper to register DSA tag driver modules Andrew Lunn
2019-04-19 15:29   ` Florian Fainelli
2019-04-18  2:31 ` [PATCH net-next 08/15] dsa: Keep link list of tag drivers Andrew Lunn
2019-04-18  7:25   ` David Miller
2019-04-18  9:35   ` Sergei Shtylyov
2019-04-18 13:19     ` Andrew Lunn
2019-04-18 14:40       ` Sergei Shtylyov
2019-04-19 15:30   ` Florian Fainelli
2019-04-18  2:31 ` [PATCH net-next 09/15] dsa: Register the none tagger ops Andrew Lunn
2019-04-19 15:31   ` Florian Fainelli
2019-04-18  2:31 ` [PATCH net-next 10/15] dsa: Rename dsa_resolve_tag_protocol() to _get ready for locking Andrew Lunn
2019-04-19 15:31   ` Florian Fainelli
2019-04-18  2:31 ` [PATCH net-next 11/15] dsa: Add stub tag driver put method Andrew Lunn
2019-04-19 15:32   ` Florian Fainelli
2019-04-18  2:31 ` [PATCH net-next 12/15] dsa: Make use of the list of tag drivers Andrew Lunn
2019-04-19 15:33   ` Florian Fainelli
2019-04-18  2:31 ` [PATCH net-next 13/15] dsa: Cleanup unneeded table and make tag structures static Andrew Lunn
2019-04-19 15:34   ` Florian Fainelli
2019-04-18  2:31 ` [PATCH net-next 14/15] dsa: Allow tag drivers to be built as modules Andrew Lunn
2019-04-19 15:38   ` Florian Fainelli
2019-04-18  2:31 ` [PATCH net-next 15/15] dsa: tag_brcm: Avoid unused symbols Andrew Lunn
2019-04-19 15:39   ` Florian Fainelli

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=20190418023120.17067-3-andrew@lunn.ch \
    --to=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=f.fainelli@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=vivien.didelot@gmail.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.