netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next 00/15] Make DSA tag drivers kernel modules
@ 2019-04-18  2:31 Andrew Lunn
  2019-04-18  2:31 ` [PATCH net-next 01/15] dsa: Add SPDX header to tag drivers Andrew Lunn
                   ` (14 more replies)
  0 siblings, 15 replies; 37+ messages in thread
From: Andrew Lunn @ 2019-04-18  2:31 UTC (permalink / raw)
  To: David Miller; +Cc: netdev, Florian Fainelli, Vivien Didelot, Andrew Lunn

Historically, DSA tag drivers have been compiled into the kernel as
part of the DSA core. With the growing number of tag drivers, it makes
sense to allow this driver code to be compiled as a module, and loaded
on demand.

Andrew Lunn (15):
  dsa: Add SPDX header to tag drivers.
  dsa: Move tagger name into its ops structure
  dsa: Add MODULE_ALIAS to taggers in preperation to become modules
  dsa: Add MODULE_LICENSE to tag drivers
  dsa: Add TAG protocol to tag ops
  dsa: Remove const from tag driver ops structure
  dsa: Add boilerplate helper to register DSA tag driver modules
  dsa: Keep link list of tag drivers
  dsa: Register the none tagger ops
  dsa: Rename dsa_resolve_tag_protocol() to _get ready for locking
  dsa: Add stub tag driver put method
  dsa: Make use of the list of tag drivers
  dsa: Cleanup unneeded table and make tag structures static
  dsa: Allow tag drivers to be built as modules
  dsa: tag_brcm: Avoid unused symbols

 include/net/dsa.h     |  94 ++++++++++++++++++++----
 net/dsa/Kconfig       |  86 +++++++++++++++++-----
 net/dsa/Makefile      |  19 +++--
 net/dsa/dsa.c         | 163 +++++++++++++++++++++---------------------
 net/dsa/dsa2.c        |   4 +-
 net/dsa/dsa_priv.h    |  33 +--------
 net/dsa/legacy.c      |   4 +-
 net/dsa/tag_brcm.c    |  34 +++++++--
 net/dsa/tag_dsa.c     |  15 ++--
 net/dsa/tag_edsa.c    |  15 ++--
 net/dsa/tag_gswip.c   |   9 ++-
 net/dsa/tag_ksz.c     |  26 +++++--
 net/dsa/tag_lan9303.c |  20 +++---
 net/dsa/tag_mtk.c     |  18 ++---
 net/dsa/tag_qca.c     |  19 +++--
 net/dsa/tag_trailer.c |  15 ++--
 16 files changed, 354 insertions(+), 220 deletions(-)

-- 
2.20.1


^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH net-next 01/15] dsa: Add SPDX header to tag drivers.
  2019-04-18  2:31 [PATCH net-next 00/15] Make DSA tag drivers kernel modules Andrew Lunn
@ 2019-04-18  2:31 ` Andrew Lunn
  2019-04-18 17:35   ` Florian Fainelli
  2019-04-18  2:31 ` [PATCH net-next 02/15] dsa: Move tagger name into its ops structure Andrew Lunn
                   ` (13 subsequent siblings)
  14 siblings, 1 reply; 37+ messages in thread
From: Andrew Lunn @ 2019-04-18  2:31 UTC (permalink / raw)
  To: David Miller; +Cc: netdev, Florian Fainelli, Vivien Didelot, Andrew Lunn

Add an SPDX header, and remove the license boilerplate text.

Signed-off-by: Andrew Lunn <andrew@lunn.ch>
---
 net/dsa/tag_brcm.c    |  6 +-----
 net/dsa/tag_dsa.c     |  6 +-----
 net/dsa/tag_edsa.c    |  6 +-----
 net/dsa/tag_ksz.c     |  6 +-----
 net/dsa/tag_lan9303.c | 11 +----------
 net/dsa/tag_mtk.c     |  9 +--------
 net/dsa/tag_qca.c     | 10 +---------
 net/dsa/tag_trailer.c |  6 +-----
 8 files changed, 8 insertions(+), 52 deletions(-)

diff --git a/net/dsa/tag_brcm.c b/net/dsa/tag_brcm.c
index 4aa1d368a5ae..b3063e7adb73 100644
--- a/net/dsa/tag_brcm.c
+++ b/net/dsa/tag_brcm.c
@@ -1,12 +1,8 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * Broadcom tag support
  *
  * Copyright (C) 2014 Broadcom Corporation
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
  */
 
 #include <linux/etherdevice.h>
diff --git a/net/dsa/tag_dsa.c b/net/dsa/tag_dsa.c
index 67ff3fae18d8..fdaf850831e2 100644
--- a/net/dsa/tag_dsa.c
+++ b/net/dsa/tag_dsa.c
@@ -1,11 +1,7 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * net/dsa/tag_dsa.c - (Non-ethertype) DSA tagging
  * Copyright (c) 2008-2009 Marvell Semiconductor
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
  */
 
 #include <linux/etherdevice.h>
diff --git a/net/dsa/tag_edsa.c b/net/dsa/tag_edsa.c
index 234585ec116e..df879445f658 100644
--- a/net/dsa/tag_edsa.c
+++ b/net/dsa/tag_edsa.c
@@ -1,11 +1,7 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * net/dsa/tag_edsa.c - Ethertype DSA tagging
  * Copyright (c) 2008-2009 Marvell Semiconductor
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
  */
 
 #include <linux/etherdevice.h>
diff --git a/net/dsa/tag_ksz.c b/net/dsa/tag_ksz.c
index de246c93d3bb..12b2f58786ee 100644
--- a/net/dsa/tag_ksz.c
+++ b/net/dsa/tag_ksz.c
@@ -1,11 +1,7 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * net/dsa/tag_ksz.c - Microchip KSZ Switch tag format handling
  * Copyright (c) 2017 Microchip Technology
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
  */
 
 #include <linux/etherdevice.h>
diff --git a/net/dsa/tag_lan9303.c b/net/dsa/tag_lan9303.c
index f48889e46ff7..7bfd3165e46e 100644
--- a/net/dsa/tag_lan9303.c
+++ b/net/dsa/tag_lan9303.c
@@ -1,15 +1,6 @@
+// SPDX-License-Identifier: GPL-2.0
 /*
  * Copyright (C) 2017 Pengutronix, Juergen Borleis <jbe@pengutronix.de>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * version 2, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
  */
 #include <linux/dsa/lan9303.h>
 #include <linux/etherdevice.h>
diff --git a/net/dsa/tag_mtk.c b/net/dsa/tag_mtk.c
index f39f4dfeda34..6e06fa621bbc 100644
--- a/net/dsa/tag_mtk.c
+++ b/net/dsa/tag_mtk.c
@@ -1,15 +1,8 @@
+// SPDX-License-Identifier: GPL-2.0
 /*
  * Mediatek DSA Tag support
  * Copyright (C) 2017 Landen Chao <landen.chao@mediatek.com>
  *		      Sean Wang <sean.wang@mediatek.com>
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 and
- * only version 2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
  */
 
 #include <linux/etherdevice.h>
diff --git a/net/dsa/tag_qca.c b/net/dsa/tag_qca.c
index 85c22ada4744..de3eb1022e21 100644
--- a/net/dsa/tag_qca.c
+++ b/net/dsa/tag_qca.c
@@ -1,14 +1,6 @@
+// SPDX-License-Identifier: GPL-2.0
 /*
  * Copyright (c) 2015, The Linux Foundation. All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 and
- * only version 2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
  */
 
 #include <linux/etherdevice.h>
diff --git a/net/dsa/tag_trailer.c b/net/dsa/tag_trailer.c
index b40756ed6e57..492a30046281 100644
--- a/net/dsa/tag_trailer.c
+++ b/net/dsa/tag_trailer.c
@@ -1,11 +1,7 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * net/dsa/tag_trailer.c - Trailer tag format handling
  * Copyright (c) 2008-2009 Marvell Semiconductor
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
  */
 
 #include <linux/etherdevice.h>
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [PATCH net-next 02/15] dsa: Move tagger name into its ops structure
  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  2:31 ` Andrew Lunn
  2019-04-18 17:37   ` 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
                   ` (12 subsequent siblings)
  14 siblings, 1 reply; 37+ messages in thread
From: Andrew Lunn @ 2019-04-18  2:31 UTC (permalink / raw)
  To: David Miller; +Cc: netdev, Florian Fainelli, Vivien Didelot, Andrew Lunn

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


^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [PATCH net-next 03/15] dsa: Add MODULE_ALIAS to taggers in preperation to become modules
  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  2:31 ` [PATCH net-next 02/15] dsa: Move tagger name into its ops structure Andrew Lunn
@ 2019-04-18  2:31 ` 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
                   ` (11 subsequent siblings)
  14 siblings, 1 reply; 37+ messages in thread
From: Andrew Lunn @ 2019-04-18  2:31 UTC (permalink / raw)
  To: David Miller; +Cc: netdev, Florian Fainelli, Vivien Didelot, Andrew Lunn

When the tag drivers become modules, we will need to dynamically load
them based on what the switch drivers need. Add aliases to map between
the TAG protocol and the driver.

In order to do this, we need the tag protocol number as something
which the C pre-processor can stringinfy. Only the compiler knows the
value of an enum, CPP cannot use them. So add #defines.

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

diff --git a/include/net/dsa.h b/include/net/dsa.h
index 9bcbbde0f61d..838b09011b9f 100644
--- a/include/net/dsa.h
+++ b/include/net/dsa.h
@@ -30,20 +30,33 @@ struct phy_device;
 struct fixed_phy_status;
 struct phylink_link_state;
 
+#define DSA_TAG_PROTO_NONE_VALUE		0
+#define DSA_TAG_PROTO_BRCM_VALUE		1
+#define DSA_TAG_PROTO_BRCM_PREPEND_VALUE	2
+#define DSA_TAG_PROTO_DSA_VALUE			3
+#define DSA_TAG_PROTO_EDSA_VALUE		4
+#define DSA_TAG_PROTO_GSWIP_VALUE		5
+#define DSA_TAG_PROTO_KSZ9477_VALUE		6
+#define DSA_TAG_PROTO_KSZ9893_VALUE		7
+#define DSA_TAG_PROTO_LAN9303_VALUE		8
+#define DSA_TAG_PROTO_MTK_VALUE			9
+#define DSA_TAG_PROTO_QCA_VALUE			10
+#define DSA_TAG_PROTO_TRAILER_VALUE		11
+
 enum dsa_tag_protocol {
-	DSA_TAG_PROTO_NONE = 0,
-	DSA_TAG_PROTO_BRCM,
-	DSA_TAG_PROTO_BRCM_PREPEND,
-	DSA_TAG_PROTO_DSA,
-	DSA_TAG_PROTO_EDSA,
-	DSA_TAG_PROTO_GSWIP,
-	DSA_TAG_PROTO_KSZ9477,
-	DSA_TAG_PROTO_KSZ9893,
-	DSA_TAG_PROTO_LAN9303,
-	DSA_TAG_PROTO_MTK,
-	DSA_TAG_PROTO_QCA,
-	DSA_TAG_PROTO_TRAILER,
-	DSA_TAG_LAST,		/* MUST BE LAST */
+	DSA_TAG_PROTO_NONE		= DSA_TAG_PROTO_NONE_VALUE,
+	DSA_TAG_PROTO_BRCM		= DSA_TAG_PROTO_BRCM_VALUE,
+	DSA_TAG_PROTO_BRCM_PREPEND	= DSA_TAG_PROTO_BRCM_PREPEND_VALUE,
+	DSA_TAG_PROTO_DSA		= DSA_TAG_PROTO_DSA_VALUE,
+	DSA_TAG_PROTO_EDSA		= DSA_TAG_PROTO_EDSA_VALUE,
+	DSA_TAG_PROTO_GSWIP		= DSA_TAG_PROTO_GSWIP_VALUE,
+	DSA_TAG_PROTO_KSZ9477		= DSA_TAG_PROTO_KSZ9477_VALUE,
+	DSA_TAG_PROTO_KSZ9893		= DSA_TAG_PROTO_KSZ9893_VALUE,
+	DSA_TAG_PROTO_LAN9303		= DSA_TAG_PROTO_LAN9303_VALUE,
+	DSA_TAG_PROTO_MTK		= DSA_TAG_PROTO_MTK_VALUE,
+	DSA_TAG_PROTO_QCA		= DSA_TAG_PROTO_QCA_VALUE,
+	DSA_TAG_PROTO_TRAILER		= DSA_TAG_PROTO_TRAILER_VALUE,
+	DSA_TAG_LAST,			/* MUST BE LAST */
 };
 
 struct packet_type;
@@ -59,6 +72,10 @@ struct dsa_device_ops {
 	unsigned int overhead;
 };
 
+#define DSA_TAG_DRIVER_ALIAS "dsa_tag-"
+#define MODULE_ALIAS_DSA_TAG_DRIVER(__proto)				\
+	MODULE_ALIAS(DSA_TAG_DRIVER_ALIAS __stringify(__proto##_VALUE))
+
 struct dsa_switch_tree {
 	struct list_head	list;
 
diff --git a/net/dsa/tag_brcm.c b/net/dsa/tag_brcm.c
index 1b7dfbe6b3ae..24d8f45a7e6f 100644
--- a/net/dsa/tag_brcm.c
+++ b/net/dsa/tag_brcm.c
@@ -173,6 +173,8 @@ const struct dsa_device_ops brcm_netdev_ops = {
 	.rcv	= brcm_tag_rcv,
 	.overhead = BRCM_TAG_LEN,
 };
+
+MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_BRCM);
 #endif
 
 #ifdef CONFIG_NET_DSA_TAG_BRCM_PREPEND
@@ -198,3 +200,5 @@ const struct dsa_device_ops brcm_prepend_netdev_ops = {
 	.overhead = BRCM_TAG_LEN,
 };
 #endif
+
+MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_BRCM_PREPEND);
diff --git a/net/dsa/tag_dsa.c b/net/dsa/tag_dsa.c
index e1c90709de6c..8aefaf96c1ca 100644
--- a/net/dsa/tag_dsa.c
+++ b/net/dsa/tag_dsa.c
@@ -157,3 +157,5 @@ const struct dsa_device_ops dsa_netdev_ops = {
 	.flow_dissect   = dsa_tag_flow_dissect,
 	.overhead = DSA_HLEN,
 };
+
+MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_DSA);
diff --git a/net/dsa/tag_edsa.c b/net/dsa/tag_edsa.c
index b936b4660b71..bad12e760f3d 100644
--- a/net/dsa/tag_edsa.c
+++ b/net/dsa/tag_edsa.c
@@ -176,3 +176,5 @@ const struct dsa_device_ops edsa_netdev_ops = {
 	.flow_dissect   = edsa_tag_flow_dissect,
 	.overhead = EDSA_HLEN,
 };
+
+MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_EDSA);
diff --git a/net/dsa/tag_gswip.c b/net/dsa/tag_gswip.c
index d1c1e7db87b6..30bf7036620f 100644
--- a/net/dsa/tag_gswip.c
+++ b/net/dsa/tag_gswip.c
@@ -109,3 +109,5 @@ const struct dsa_device_ops gswip_netdev_ops = {
 	.rcv = gswip_tag_rcv,
 	.overhead = GSWIP_RX_HEADER_LEN,
 };
+
+MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_GSWIP);
diff --git a/net/dsa/tag_ksz.c b/net/dsa/tag_ksz.c
index 631094599514..9be0f5f12afb 100644
--- a/net/dsa/tag_ksz.c
+++ b/net/dsa/tag_ksz.c
@@ -140,6 +140,8 @@ const struct dsa_device_ops ksz9477_netdev_ops = {
 	.overhead = KSZ9477_INGRESS_TAG_LEN,
 };
 
+MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_KSZ9477);
+
 #define KSZ9893_TAIL_TAG_OVERRIDE	BIT(5)
 #define KSZ9893_TAIL_TAG_LOOKUP		BIT(6)
 
@@ -173,3 +175,5 @@ const struct dsa_device_ops ksz9893_netdev_ops = {
 	.rcv	= ksz9477_rcv,
 	.overhead = KSZ_INGRESS_TAG_LEN,
 };
+
+MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_KSZ9893);
diff --git a/net/dsa/tag_lan9303.c b/net/dsa/tag_lan9303.c
index 67d70339536d..48bca20024d4 100644
--- a/net/dsa/tag_lan9303.c
+++ b/net/dsa/tag_lan9303.c
@@ -134,3 +134,5 @@ const struct dsa_device_ops lan9303_netdev_ops = {
 	.rcv = lan9303_rcv,
 	.overhead = LAN9303_TAG_LEN,
 };
+
+MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_LAN9303);
diff --git a/net/dsa/tag_mtk.c b/net/dsa/tag_mtk.c
index dc537d9a18c0..23210a65cbed 100644
--- a/net/dsa/tag_mtk.c
+++ b/net/dsa/tag_mtk.c
@@ -105,3 +105,5 @@ const struct dsa_device_ops mtk_netdev_ops = {
 	.flow_dissect	= mtk_tag_flow_dissect,
 	.overhead	= MTK_HDR_LEN,
 };
+
+MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_MTK);
diff --git a/net/dsa/tag_qca.c b/net/dsa/tag_qca.c
index f62296ffc5b7..7d9cb178da3d 100644
--- a/net/dsa/tag_qca.c
+++ b/net/dsa/tag_qca.c
@@ -106,3 +106,5 @@ const struct dsa_device_ops qca_netdev_ops = {
 	.flow_dissect = qca_tag_flow_dissect,
 	.overhead = QCA_HDR_LEN,
 };
+
+MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_QCA);
diff --git a/net/dsa/tag_trailer.c b/net/dsa/tag_trailer.c
index 20ee7f84fe4d..00d521cf9c48 100644
--- a/net/dsa/tag_trailer.c
+++ b/net/dsa/tag_trailer.c
@@ -83,3 +83,5 @@ const struct dsa_device_ops trailer_netdev_ops = {
 	.rcv	= trailer_rcv,
 	.overhead = 4,
 };
+
+MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_TRAILER);
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [PATCH net-next 04/15] dsa: Add MODULE_LICENSE to tag drivers
  2019-04-18  2:31 [PATCH net-next 00/15] Make DSA tag drivers kernel modules Andrew Lunn
                   ` (2 preceding siblings ...)
  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-18  2:31 ` 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
                   ` (10 subsequent siblings)
  14 siblings, 1 reply; 37+ messages in thread
From: Andrew Lunn @ 2019-04-18  2:31 UTC (permalink / raw)
  To: David Miller; +Cc: netdev, Florian Fainelli, Vivien Didelot, Andrew Lunn

All the tag drivers are some variant of GPL. Add a MODULE_LICENSE()
indicating this, so the drivers can later be compiled as modules.

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

diff --git a/net/dsa/tag_brcm.c b/net/dsa/tag_brcm.c
index 24d8f45a7e6f..59421f9e96de 100644
--- a/net/dsa/tag_brcm.c
+++ b/net/dsa/tag_brcm.c
@@ -201,4 +201,5 @@ const struct dsa_device_ops brcm_prepend_netdev_ops = {
 };
 #endif
 
+MODULE_LICENSE("GPL");
 MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_BRCM_PREPEND);
diff --git a/net/dsa/tag_dsa.c b/net/dsa/tag_dsa.c
index 8aefaf96c1ca..b8f3236db877 100644
--- a/net/dsa/tag_dsa.c
+++ b/net/dsa/tag_dsa.c
@@ -158,4 +158,5 @@ const struct dsa_device_ops dsa_netdev_ops = {
 	.overhead = DSA_HLEN,
 };
 
+MODULE_LICENSE("GPL");
 MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_DSA);
diff --git a/net/dsa/tag_edsa.c b/net/dsa/tag_edsa.c
index bad12e760f3d..c4fddf7292cf 100644
--- a/net/dsa/tag_edsa.c
+++ b/net/dsa/tag_edsa.c
@@ -177,4 +177,5 @@ const struct dsa_device_ops edsa_netdev_ops = {
 	.overhead = EDSA_HLEN,
 };
 
+MODULE_LICENSE("GPL");
 MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_EDSA);
diff --git a/net/dsa/tag_gswip.c b/net/dsa/tag_gswip.c
index 30bf7036620f..6a7ff063b6e0 100644
--- a/net/dsa/tag_gswip.c
+++ b/net/dsa/tag_gswip.c
@@ -110,4 +110,5 @@ const struct dsa_device_ops gswip_netdev_ops = {
 	.overhead = GSWIP_RX_HEADER_LEN,
 };
 
+MODULE_LICENSE("GPL");
 MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_GSWIP);
diff --git a/net/dsa/tag_ksz.c b/net/dsa/tag_ksz.c
index 9be0f5f12afb..6d78d88270fc 100644
--- a/net/dsa/tag_ksz.c
+++ b/net/dsa/tag_ksz.c
@@ -176,4 +176,5 @@ const struct dsa_device_ops ksz9893_netdev_ops = {
 	.overhead = KSZ_INGRESS_TAG_LEN,
 };
 
+MODULE_LICENSE("GPL");
 MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_KSZ9893);
diff --git a/net/dsa/tag_lan9303.c b/net/dsa/tag_lan9303.c
index 48bca20024d4..1f5819e4e687 100644
--- a/net/dsa/tag_lan9303.c
+++ b/net/dsa/tag_lan9303.c
@@ -135,4 +135,5 @@ const struct dsa_device_ops lan9303_netdev_ops = {
 	.overhead = LAN9303_TAG_LEN,
 };
 
+MODULE_LICENSE("GPL");
 MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_LAN9303);
diff --git a/net/dsa/tag_mtk.c b/net/dsa/tag_mtk.c
index 23210a65cbed..7ecafb569f74 100644
--- a/net/dsa/tag_mtk.c
+++ b/net/dsa/tag_mtk.c
@@ -106,4 +106,5 @@ const struct dsa_device_ops mtk_netdev_ops = {
 	.overhead	= MTK_HDR_LEN,
 };
 
+MODULE_LICENSE("GPL");
 MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_MTK);
diff --git a/net/dsa/tag_qca.c b/net/dsa/tag_qca.c
index 7d9cb178da3d..f3fdeafef1fe 100644
--- a/net/dsa/tag_qca.c
+++ b/net/dsa/tag_qca.c
@@ -107,4 +107,5 @@ const struct dsa_device_ops qca_netdev_ops = {
 	.overhead = QCA_HDR_LEN,
 };
 
+MODULE_LICENSE("GPL");
 MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_QCA);
diff --git a/net/dsa/tag_trailer.c b/net/dsa/tag_trailer.c
index 00d521cf9c48..9ec6aa7938cc 100644
--- a/net/dsa/tag_trailer.c
+++ b/net/dsa/tag_trailer.c
@@ -84,4 +84,5 @@ const struct dsa_device_ops trailer_netdev_ops = {
 	.overhead = 4,
 };
 
+MODULE_LICENSE("GPL");
 MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_TRAILER);
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [PATCH net-next 05/15] dsa: Add TAG protocol to tag ops
  2019-04-18  2:31 [PATCH net-next 00/15] Make DSA tag drivers kernel modules Andrew Lunn
                   ` (3 preceding siblings ...)
  2019-04-18  2:31 ` [PATCH net-next 04/15] dsa: Add MODULE_LICENSE to tag drivers Andrew Lunn
@ 2019-04-18  2:31 ` 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
                   ` (9 subsequent siblings)
  14 siblings, 1 reply; 37+ messages in thread
From: Andrew Lunn @ 2019-04-18  2:31 UTC (permalink / raw)
  To: David Miller; +Cc: netdev, Florian Fainelli, Vivien Didelot, Andrew Lunn

In order that we can match the tagging protocol a switch driver
request to the tagger, we need to know what protocol the tagger
supports. Add this information to the ops structure.

Signed-off-by: Andrew Lunn <andrew@lunn.ch>
---
 include/net/dsa.h     | 1 +
 net/dsa/dsa.c         | 1 +
 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, 13 insertions(+)

diff --git a/include/net/dsa.h b/include/net/dsa.h
index 838b09011b9f..303c71c5288a 100644
--- a/include/net/dsa.h
+++ b/include/net/dsa.h
@@ -64,6 +64,7 @@ struct dsa_switch;
 
 struct dsa_device_ops {
 	const char *name;
+	enum dsa_tag_protocol proto;
 	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 92b3cd129eb7..2da733dff86b 100644
--- a/net/dsa/dsa.c
+++ b/net/dsa/dsa.c
@@ -36,6 +36,7 @@ static struct sk_buff *dsa_slave_notag_xmit(struct sk_buff *skb,
 
 static const struct dsa_device_ops none_ops = {
 	.name	= "none",
+	.proto	= DSA_TAG_PROTO_NONE,
 	.xmit	= dsa_slave_notag_xmit,
 	.rcv	= NULL,
 };
diff --git a/net/dsa/tag_brcm.c b/net/dsa/tag_brcm.c
index 59421f9e96de..39b380485e5a 100644
--- a/net/dsa/tag_brcm.c
+++ b/net/dsa/tag_brcm.c
@@ -169,6 +169,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",
+	.proto	= DSA_TAG_PROTO_BRCM,
 	.xmit	= brcm_tag_xmit,
 	.rcv	= brcm_tag_rcv,
 	.overhead = BRCM_TAG_LEN,
@@ -195,6 +196,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",
+	.proto	= DSA_TAG_PROTO_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 b8f3236db877..ec9b66c11219 100644
--- a/net/dsa/tag_dsa.c
+++ b/net/dsa/tag_dsa.c
@@ -152,6 +152,7 @@ static int dsa_tag_flow_dissect(const struct sk_buff *skb, __be16 *proto,
 
 const struct dsa_device_ops dsa_netdev_ops = {
 	.name	= "dsa",
+	.proto	= DSA_TAG_PROTO_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 c4fddf7292cf..866d4e684511 100644
--- a/net/dsa/tag_edsa.c
+++ b/net/dsa/tag_edsa.c
@@ -171,6 +171,7 @@ static int edsa_tag_flow_dissect(const struct sk_buff *skb, __be16 *proto,
 
 const struct dsa_device_ops edsa_netdev_ops = {
 	.name	= "edsa",
+	.proto	= DSA_TAG_PROTO_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 6a7ff063b6e0..192156373108 100644
--- a/net/dsa/tag_gswip.c
+++ b/net/dsa/tag_gswip.c
@@ -105,6 +105,7 @@ static struct sk_buff *gswip_tag_rcv(struct sk_buff *skb,
 
 const struct dsa_device_ops gswip_netdev_ops = {
 	.name = "gwsip",
+	.proto	= DSA_TAG_PROTO_GSWIP,
 	.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 6d78d88270fc..5f5c8f9a6141 100644
--- a/net/dsa/tag_ksz.c
+++ b/net/dsa/tag_ksz.c
@@ -135,6 +135,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",
+	.proto	= DSA_TAG_PROTO_KSZ9477,
 	.xmit	= ksz9477_xmit,
 	.rcv	= ksz9477_rcv,
 	.overhead = KSZ9477_INGRESS_TAG_LEN,
@@ -171,6 +172,7 @@ static struct sk_buff *ksz9893_xmit(struct sk_buff *skb,
 
 const struct dsa_device_ops ksz9893_netdev_ops = {
 	.name	= "ksz9893",
+	.proto	= DSA_TAG_PROTO_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 1f5819e4e687..b6ef1e1a6673 100644
--- a/net/dsa/tag_lan9303.c
+++ b/net/dsa/tag_lan9303.c
@@ -130,6 +130,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",
+	.proto	= DSA_TAG_PROTO_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 7ecafb569f74..ca02ab3dcd80 100644
--- a/net/dsa/tag_mtk.c
+++ b/net/dsa/tag_mtk.c
@@ -100,6 +100,7 @@ static int mtk_tag_flow_dissect(const struct sk_buff *skb, __be16 *proto,
 
 const struct dsa_device_ops mtk_netdev_ops = {
 	.name		= "mtk",
+	.proto		= DSA_TAG_PROTO_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 f3fdeafef1fe..1ff65c2e0cb4 100644
--- a/net/dsa/tag_qca.c
+++ b/net/dsa/tag_qca.c
@@ -101,6 +101,7 @@ static int qca_tag_flow_dissect(const struct sk_buff *skb, __be16 *proto,
 
 const struct dsa_device_ops qca_netdev_ops = {
 	.name	= "qca",
+	.proto	= DSA_TAG_PROTO_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 9ec6aa7938cc..628ab1a44ed7 100644
--- a/net/dsa/tag_trailer.c
+++ b/net/dsa/tag_trailer.c
@@ -79,6 +79,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",
+	.proto	= DSA_TAG_PROTO_TRAILER,
 	.xmit	= trailer_xmit,
 	.rcv	= trailer_rcv,
 	.overhead = 4,
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [PATCH net-next 06/15] dsa: Remove const from tag driver ops structure
  2019-04-18  2:31 [PATCH net-next 00/15] Make DSA tag drivers kernel modules Andrew Lunn
                   ` (4 preceding siblings ...)
  2019-04-18  2:31 ` [PATCH net-next 05/15] dsa: Add TAG protocol to tag ops Andrew Lunn
@ 2019-04-18  2:31 ` Andrew Lunn
  2019-04-18 17:58   ` Florian Fainelli
  2019-04-18  2:31 ` [PATCH net-next 07/15] dsa: Add boilerplate helper to register DSA tag driver modules Andrew Lunn
                   ` (8 subsequent siblings)
  14 siblings, 1 reply; 37+ messages in thread
From: Andrew Lunn @ 2019-04-18  2:31 UTC (permalink / raw)
  To: David Miller; +Cc: netdev, Florian Fainelli, Vivien Didelot, Andrew Lunn

A later patch will create a linked list of tag driver ops structures,
using a list_head in the structure. So the structure cannot be const.

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

diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c
index 2da733dff86b..5c37508747a0 100644
--- a/net/dsa/dsa.c
+++ b/net/dsa/dsa.c
@@ -34,7 +34,7 @@ static struct sk_buff *dsa_slave_notag_xmit(struct sk_buff *skb,
 	return skb;
 }
 
-static const struct dsa_device_ops none_ops = {
+static struct dsa_device_ops none_ops = {
 	.name	= "none",
 	.proto	= DSA_TAG_PROTO_NONE,
 	.xmit	= dsa_slave_notag_xmit,
diff --git a/net/dsa/dsa_priv.h b/net/dsa/dsa_priv.h
index 093b7d145eb1..32a063cefe46 100644
--- a/net/dsa/dsa_priv.h
+++ b/net/dsa/dsa_priv.h
@@ -202,32 +202,32 @@ int dsa_switch_register_notifier(struct dsa_switch *ds);
 void dsa_switch_unregister_notifier(struct dsa_switch *ds);
 
 /* tag_brcm.c */
-extern const struct dsa_device_ops brcm_netdev_ops;
-extern const struct dsa_device_ops brcm_prepend_netdev_ops;
+extern struct dsa_device_ops brcm_netdev_ops;
+extern struct dsa_device_ops brcm_prepend_netdev_ops;
 
 /* tag_dsa.c */
-extern const struct dsa_device_ops dsa_netdev_ops;
+extern struct dsa_device_ops dsa_netdev_ops;
 
 /* tag_edsa.c */
-extern const struct dsa_device_ops edsa_netdev_ops;
+extern struct dsa_device_ops edsa_netdev_ops;
 
 /* tag_gswip.c */
-extern const struct dsa_device_ops gswip_netdev_ops;
+extern struct dsa_device_ops gswip_netdev_ops;
 
 /* tag_ksz.c */
-extern const struct dsa_device_ops ksz9477_netdev_ops;
-extern const struct dsa_device_ops ksz9893_netdev_ops;
+extern struct dsa_device_ops ksz9477_netdev_ops;
+extern struct dsa_device_ops ksz9893_netdev_ops;
 
 /* tag_lan9303.c */
-extern const struct dsa_device_ops lan9303_netdev_ops;
+extern struct dsa_device_ops lan9303_netdev_ops;
 
 /* tag_mtk.c */
-extern const struct dsa_device_ops mtk_netdev_ops;
+extern struct dsa_device_ops mtk_netdev_ops;
 
 /* tag_qca.c */
-extern const struct dsa_device_ops qca_netdev_ops;
+extern struct dsa_device_ops qca_netdev_ops;
 
 /* tag_trailer.c */
-extern const struct dsa_device_ops trailer_netdev_ops;
+extern struct dsa_device_ops trailer_netdev_ops;
 
 #endif
diff --git a/net/dsa/tag_brcm.c b/net/dsa/tag_brcm.c
index 39b380485e5a..756bade54fee 100644
--- a/net/dsa/tag_brcm.c
+++ b/net/dsa/tag_brcm.c
@@ -167,7 +167,7 @@ static struct sk_buff *brcm_tag_rcv(struct sk_buff *skb, struct net_device *dev,
 	return nskb;
 }
 
-const struct dsa_device_ops brcm_netdev_ops = {
+struct dsa_device_ops brcm_netdev_ops = {
 	.name	= "brcm",
 	.proto	= DSA_TAG_PROTO_BRCM,
 	.xmit	= brcm_tag_xmit,
@@ -194,7 +194,7 @@ static struct sk_buff *brcm_tag_rcv_prepend(struct sk_buff *skb,
 	return brcm_tag_rcv_ll(skb, dev, pt, ETH_HLEN);
 }
 
-const struct dsa_device_ops brcm_prepend_netdev_ops = {
+struct dsa_device_ops brcm_prepend_netdev_ops = {
 	.name	= "brcm-prepend",
 	.proto	= DSA_TAG_PROTO_BRCM_PREPEND,
 	.xmit	= brcm_tag_xmit_prepend,
diff --git a/net/dsa/tag_dsa.c b/net/dsa/tag_dsa.c
index ec9b66c11219..5db7dd21c73a 100644
--- a/net/dsa/tag_dsa.c
+++ b/net/dsa/tag_dsa.c
@@ -150,7 +150,7 @@ static int dsa_tag_flow_dissect(const struct sk_buff *skb, __be16 *proto,
 	return 0;
 }
 
-const struct dsa_device_ops dsa_netdev_ops = {
+struct dsa_device_ops dsa_netdev_ops = {
 	.name	= "dsa",
 	.proto	= DSA_TAG_PROTO_DSA,
 	.xmit	= dsa_xmit,
diff --git a/net/dsa/tag_edsa.c b/net/dsa/tag_edsa.c
index 866d4e684511..94c6eed1905f 100644
--- a/net/dsa/tag_edsa.c
+++ b/net/dsa/tag_edsa.c
@@ -169,7 +169,7 @@ static int edsa_tag_flow_dissect(const struct sk_buff *skb, __be16 *proto,
 	return 0;
 }
 
-const struct dsa_device_ops edsa_netdev_ops = {
+struct dsa_device_ops edsa_netdev_ops = {
 	.name	= "edsa",
 	.proto	= DSA_TAG_PROTO_EDSA,
 	.xmit	= edsa_xmit,
diff --git a/net/dsa/tag_gswip.c b/net/dsa/tag_gswip.c
index 192156373108..f2cb183e4a8a 100644
--- a/net/dsa/tag_gswip.c
+++ b/net/dsa/tag_gswip.c
@@ -103,7 +103,7 @@ static struct sk_buff *gswip_tag_rcv(struct sk_buff *skb,
 	return skb;
 }
 
-const struct dsa_device_ops gswip_netdev_ops = {
+struct dsa_device_ops gswip_netdev_ops = {
 	.name = "gwsip",
 	.proto	= DSA_TAG_PROTO_GSWIP,
 	.xmit = gswip_tag_xmit,
diff --git a/net/dsa/tag_ksz.c b/net/dsa/tag_ksz.c
index 5f5c8f9a6141..9c5f7db632a7 100644
--- a/net/dsa/tag_ksz.c
+++ b/net/dsa/tag_ksz.c
@@ -133,7 +133,7 @@ static struct sk_buff *ksz9477_rcv(struct sk_buff *skb, struct net_device *dev,
 	return ksz_common_rcv(skb, dev, port, len);
 }
 
-const struct dsa_device_ops ksz9477_netdev_ops = {
+struct dsa_device_ops ksz9477_netdev_ops = {
 	.name	= "ksz9477",
 	.proto	= DSA_TAG_PROTO_KSZ9477,
 	.xmit	= ksz9477_xmit,
@@ -170,7 +170,7 @@ static struct sk_buff *ksz9893_xmit(struct sk_buff *skb,
 	return nskb;
 }
 
-const struct dsa_device_ops ksz9893_netdev_ops = {
+struct dsa_device_ops ksz9893_netdev_ops = {
 	.name	= "ksz9893",
 	.proto	= DSA_TAG_PROTO_KSZ9893,
 	.xmit	= ksz9893_xmit,
diff --git a/net/dsa/tag_lan9303.c b/net/dsa/tag_lan9303.c
index b6ef1e1a6673..edfa15583607 100644
--- a/net/dsa/tag_lan9303.c
+++ b/net/dsa/tag_lan9303.c
@@ -128,7 +128,7 @@ static struct sk_buff *lan9303_rcv(struct sk_buff *skb, struct net_device *dev,
 	return skb;
 }
 
-const struct dsa_device_ops lan9303_netdev_ops = {
+struct dsa_device_ops lan9303_netdev_ops = {
 	.name = "lan9303",
 	.proto	= DSA_TAG_PROTO_LAN9303,
 	.xmit = lan9303_xmit,
diff --git a/net/dsa/tag_mtk.c b/net/dsa/tag_mtk.c
index ca02ab3dcd80..dc51d7d05370 100644
--- a/net/dsa/tag_mtk.c
+++ b/net/dsa/tag_mtk.c
@@ -98,7 +98,7 @@ static int mtk_tag_flow_dissect(const struct sk_buff *skb, __be16 *proto,
 	return 0;
 }
 
-const struct dsa_device_ops mtk_netdev_ops = {
+struct dsa_device_ops mtk_netdev_ops = {
 	.name		= "mtk",
 	.proto		= DSA_TAG_PROTO_MTK,
 	.xmit		= mtk_tag_xmit,
diff --git a/net/dsa/tag_qca.c b/net/dsa/tag_qca.c
index 1ff65c2e0cb4..e34c507e9e7e 100644
--- a/net/dsa/tag_qca.c
+++ b/net/dsa/tag_qca.c
@@ -99,7 +99,7 @@ static int qca_tag_flow_dissect(const struct sk_buff *skb, __be16 *proto,
 	return 0;
 }
 
-const struct dsa_device_ops qca_netdev_ops = {
+struct dsa_device_ops qca_netdev_ops = {
 	.name	= "qca",
 	.proto	= DSA_TAG_PROTO_QCA,
 	.xmit	= qca_tag_xmit,
diff --git a/net/dsa/tag_trailer.c b/net/dsa/tag_trailer.c
index 628ab1a44ed7..81a45c523ab7 100644
--- a/net/dsa/tag_trailer.c
+++ b/net/dsa/tag_trailer.c
@@ -77,7 +77,7 @@ static struct sk_buff *trailer_rcv(struct sk_buff *skb, struct net_device *dev,
 	return skb;
 }
 
-const struct dsa_device_ops trailer_netdev_ops = {
+struct dsa_device_ops trailer_netdev_ops = {
 	.name	= "trailer",
 	.proto	= DSA_TAG_PROTO_TRAILER,
 	.xmit	= trailer_xmit,
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [PATCH net-next 07/15] dsa: Add boilerplate helper to register DSA tag driver modules
  2019-04-18  2:31 [PATCH net-next 00/15] Make DSA tag drivers kernel modules Andrew Lunn
                   ` (5 preceding siblings ...)
  2019-04-18  2:31 ` [PATCH net-next 06/15] dsa: Remove const from tag driver ops structure Andrew Lunn
@ 2019-04-18  2:31 ` 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
                   ` (7 subsequent siblings)
  14 siblings, 1 reply; 37+ messages in thread
From: Andrew Lunn @ 2019-04-18  2:31 UTC (permalink / raw)
  To: David Miller; +Cc: netdev, Florian Fainelli, Vivien Didelot, Andrew Lunn

A DSA tag driver module will need to register the tag protocols it
implements with the DSA core. Add a macro containing this boiler plate.

The registration/unregistration code is currently just a stub. A Later
patch will add the real implementation.

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

diff --git a/include/net/dsa.h b/include/net/dsa.h
index 303c71c5288a..551c6c0d7870 100644
--- a/include/net/dsa.h
+++ b/include/net/dsa.h
@@ -594,4 +594,52 @@ int dsa_port_get_ethtool_phy_stats(struct dsa_port *dp, uint64_t *data);
 int dsa_port_get_phy_sset_count(struct dsa_port *dp);
 void dsa_port_phylink_mac_change(struct dsa_switch *ds, int port, bool up);
 
+int dsa_tag_drivers_register(struct dsa_device_ops *ops_array[],
+			     unsigned int count,
+			     struct module *owner);
+void dsa_tag_drivers_unregister(struct dsa_device_ops *ops_array[],
+				unsigned int count);
+
+/**
+ * module_dsa_tag_drivers() - Helper macro for registering DSA tag
+ * drivers
+ * @__ops_array: Array of tag driver strucutres
+ *
+ * Helper macro for DSA tag drivers which do not do anything special
+ * in module init/exit. Each module may only use this macro once, and
+ * calling it replaces module_init() and module_exit().
+ */
+#define dsa_tag_driver_module_drivers(__ops_array, __count)		\
+static int __init dsa_tag_driver_module_init(void)			\
+{									\
+	return dsa_tag_drivers_register(__ops_array, __count,		\
+				       THIS_MODULE);			\
+}									\
+module_init(dsa_tag_driver_module_init);				\
+									\
+static void __exit dsa_tag_driver_module_exit(void)			\
+{									\
+	dsa_tag_drivers_unregister(__ops_array, __count);		\
+}									\
+module_exit(dsa_tag_driver_module_exit)
+
+#define module_dsa_tag_drivers(__ops_array)				\
+dsa_tag_driver_module_drivers(__ops_array, ARRAY_SIZE(__ops_array))
+
+/**
+ * module_dsa_tag_driver() - Helper macro for registering a single DSA tag
+ * driver
+ * @__ops: Single tag driver strucutres
+ *
+ * Helper macro for DSA tag drivers which do not do anything special
+ * in module init/exit. Each module may only use this macro once, and
+ * calling it replaces module_init() and module_exit().
+ */
+#define module_dsa_tag_driver(__ops)					\
+	static struct dsa_device_ops *ops_array[] =			\
+	{ __ops };							\
+									\
+	module_dsa_tag_drivers(ops_array);				\
+
 #endif
+
diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c
index 5c37508747a0..a49e230b6247 100644
--- a/net/dsa/dsa.c
+++ b/net/dsa/dsa.c
@@ -76,6 +76,19 @@ const struct dsa_device_ops *dsa_device_ops[DSA_TAG_LAST] = {
 	[DSA_TAG_PROTO_NONE] = &none_ops,
 };
 
+int dsa_tag_drivers_register(struct dsa_device_ops *ops[],
+			     unsigned int count, struct module *owner)
+{
+	return 0;
+}
+EXPORT_SYMBOL_GPL(dsa_tag_drivers_register);
+
+void dsa_tag_drivers_unregister(struct dsa_device_ops *ops[],
+				unsigned int count)
+{
+}
+EXPORT_SYMBOL_GPL(dsa_tag_drivers_unregister);
+
 const char *dsa_tag_protocol_to_str(const struct dsa_device_ops *ops)
 {
 	return ops->name;
diff --git a/net/dsa/tag_brcm.c b/net/dsa/tag_brcm.c
index 756bade54fee..bff9b03a7752 100644
--- a/net/dsa/tag_brcm.c
+++ b/net/dsa/tag_brcm.c
@@ -205,3 +205,14 @@ struct dsa_device_ops brcm_prepend_netdev_ops = {
 
 MODULE_LICENSE("GPL");
 MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_BRCM_PREPEND);
+
+static struct dsa_device_ops *ops_array[] = {
+#ifdef CONFIG_NET_DSA_TAG_BRCM
+	&brcm_netdev_ops,
+	#endif
+#ifdef CONFIG_NET_DSA_TAG_BRCM_PREPEND
+	&brcm_prepend_netdev_ops,
+	#endif
+};
+
+module_dsa_tag_drivers(ops_array);
diff --git a/net/dsa/tag_dsa.c b/net/dsa/tag_dsa.c
index 5db7dd21c73a..44e023e3da84 100644
--- a/net/dsa/tag_dsa.c
+++ b/net/dsa/tag_dsa.c
@@ -161,3 +161,5 @@ struct dsa_device_ops dsa_netdev_ops = {
 
 MODULE_LICENSE("GPL");
 MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_DSA);
+
+module_dsa_tag_driver(&dsa_netdev_ops);
diff --git a/net/dsa/tag_edsa.c b/net/dsa/tag_edsa.c
index 94c6eed1905f..e51e5db45d43 100644
--- a/net/dsa/tag_edsa.c
+++ b/net/dsa/tag_edsa.c
@@ -180,3 +180,5 @@ struct dsa_device_ops edsa_netdev_ops = {
 
 MODULE_LICENSE("GPL");
 MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_EDSA);
+
+module_dsa_tag_driver(&edsa_netdev_ops);
diff --git a/net/dsa/tag_gswip.c b/net/dsa/tag_gswip.c
index f2cb183e4a8a..38d7617d8a03 100644
--- a/net/dsa/tag_gswip.c
+++ b/net/dsa/tag_gswip.c
@@ -113,3 +113,5 @@ struct dsa_device_ops gswip_netdev_ops = {
 
 MODULE_LICENSE("GPL");
 MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_GSWIP);
+
+module_dsa_tag_driver(&gswip_netdev_ops);
diff --git a/net/dsa/tag_ksz.c b/net/dsa/tag_ksz.c
index 9c5f7db632a7..3e4ea4ac10d6 100644
--- a/net/dsa/tag_ksz.c
+++ b/net/dsa/tag_ksz.c
@@ -180,3 +180,10 @@ struct dsa_device_ops ksz9893_netdev_ops = {
 
 MODULE_LICENSE("GPL");
 MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_KSZ9893);
+
+static struct dsa_device_ops *ops_array[] = {
+	&ksz9477_netdev_ops,
+	&ksz9893_netdev_ops,
+};
+
+module_dsa_tag_drivers(ops_array);
diff --git a/net/dsa/tag_lan9303.c b/net/dsa/tag_lan9303.c
index edfa15583607..4135080559cf 100644
--- a/net/dsa/tag_lan9303.c
+++ b/net/dsa/tag_lan9303.c
@@ -138,3 +138,5 @@ struct dsa_device_ops lan9303_netdev_ops = {
 
 MODULE_LICENSE("GPL");
 MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_LAN9303);
+
+module_dsa_tag_driver(&lan9303_netdev_ops);
diff --git a/net/dsa/tag_mtk.c b/net/dsa/tag_mtk.c
index dc51d7d05370..bcca5e1a3732 100644
--- a/net/dsa/tag_mtk.c
+++ b/net/dsa/tag_mtk.c
@@ -109,3 +109,5 @@ struct dsa_device_ops mtk_netdev_ops = {
 
 MODULE_LICENSE("GPL");
 MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_MTK);
+
+module_dsa_tag_driver(&mtk_netdev_ops);
diff --git a/net/dsa/tag_qca.c b/net/dsa/tag_qca.c
index e34c507e9e7e..fce437c51fcd 100644
--- a/net/dsa/tag_qca.c
+++ b/net/dsa/tag_qca.c
@@ -110,3 +110,5 @@ struct dsa_device_ops qca_netdev_ops = {
 
 MODULE_LICENSE("GPL");
 MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_QCA);
+
+module_dsa_tag_driver(&qca_netdev_ops);
diff --git a/net/dsa/tag_trailer.c b/net/dsa/tag_trailer.c
index 81a45c523ab7..d8955ec1a38f 100644
--- a/net/dsa/tag_trailer.c
+++ b/net/dsa/tag_trailer.c
@@ -87,3 +87,5 @@ struct dsa_device_ops trailer_netdev_ops = {
 
 MODULE_LICENSE("GPL");
 MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_TRAILER);
+
+module_dsa_tag_driver(&trailer_netdev_ops);
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [PATCH net-next 08/15] dsa: Keep link list of tag drivers
  2019-04-18  2:31 [PATCH net-next 00/15] Make DSA tag drivers kernel modules Andrew Lunn
                   ` (6 preceding siblings ...)
  2019-04-18  2:31 ` [PATCH net-next 07/15] dsa: Add boilerplate helper to register DSA tag driver modules Andrew Lunn
@ 2019-04-18  2:31 ` Andrew Lunn
  2019-04-18  7:25   ` David Miller
                     ` (2 more replies)
  2019-04-18  2:31 ` [PATCH net-next 09/15] dsa: Register the none tagger ops Andrew Lunn
                   ` (6 subsequent siblings)
  14 siblings, 3 replies; 37+ messages in thread
From: Andrew Lunn @ 2019-04-18  2:31 UTC (permalink / raw)
  To: David Miller; +Cc: netdev, Florian Fainelli, Vivien Didelot, Andrew Lunn

Let the tag drivers register themselves with the DSA core, keeping
them in a linked list.

Signed-off-by: Andrew Lunn <andrew@lunn.ch>
---
 include/net/dsa.h |  2 ++
 net/dsa/dsa.c     | 35 ++++++++++++++++++++++++++++++++++-
 2 files changed, 36 insertions(+), 1 deletion(-)

diff --git a/include/net/dsa.h b/include/net/dsa.h
index 551c6c0d7870..46774e812f1b 100644
--- a/include/net/dsa.h
+++ b/include/net/dsa.h
@@ -65,6 +65,8 @@ struct dsa_switch;
 struct dsa_device_ops {
 	const char *name;
 	enum dsa_tag_protocol proto;
+	struct list_head list;
+	struct module *owner;
 	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 a49e230b6247..861fe1441a7d 100644
--- a/net/dsa/dsa.c
+++ b/net/dsa/dsa.c
@@ -27,6 +27,9 @@
 
 #include "dsa_priv.h"
 
+static LIST_HEAD(dsa_tag_drivers_list);
+static DEFINE_MUTEX(dsa_tag_drivers_lock);
+
 static struct sk_buff *dsa_slave_notag_xmit(struct sk_buff *skb,
 					    struct net_device *dev)
 {
@@ -76,16 +79,46 @@ const struct dsa_device_ops *dsa_device_ops[DSA_TAG_LAST] = {
 	[DSA_TAG_PROTO_NONE] = &none_ops,
 };
 
+static int dsa_tag_driver_register(struct dsa_device_ops *ops,
+				   struct module *owner)
+{
+	ops->owner = owner;
+
+	mutex_lock(&dsa_tag_drivers_lock);
+	list_add_tail(&ops->list, &dsa_tag_drivers_list);
+	mutex_unlock(&dsa_tag_drivers_lock);
+	return 0;
+}
+
 int dsa_tag_drivers_register(struct dsa_device_ops *ops[],
 			     unsigned int count, struct module *owner)
 {
-	return 0;
+	int err, i;
+
+	for (i = 0; i < count; i++) {
+		err = dsa_tag_driver_register(ops[i], owner);
+		if (err)
+			break;
+	}
+
+	return err;
+}
+
+static void dsa_tag_driver_unregister(struct dsa_device_ops *ops)
+{
+	mutex_lock(&dsa_tag_drivers_lock);
+	list_del(&ops->list);
+	mutex_unlock(&dsa_tag_drivers_lock);
 }
 EXPORT_SYMBOL_GPL(dsa_tag_drivers_register);
 
 void dsa_tag_drivers_unregister(struct dsa_device_ops *ops[],
 				unsigned int count)
 {
+	int i;
+
+	for (i = 0; i < count; i++)
+		dsa_tag_driver_unregister(ops[i]);
 }
 EXPORT_SYMBOL_GPL(dsa_tag_drivers_unregister);
 
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [PATCH net-next 09/15] dsa: Register the none tagger ops
  2019-04-18  2:31 [PATCH net-next 00/15] Make DSA tag drivers kernel modules Andrew Lunn
                   ` (7 preceding siblings ...)
  2019-04-18  2:31 ` [PATCH net-next 08/15] dsa: Keep link list of tag drivers Andrew Lunn
@ 2019-04-18  2:31 ` 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
                   ` (5 subsequent siblings)
  14 siblings, 1 reply; 37+ messages in thread
From: Andrew Lunn @ 2019-04-18  2:31 UTC (permalink / raw)
  To: David Miller; +Cc: netdev, Florian Fainelli, Vivien Didelot, Andrew Lunn

The none tagger is special in that it does not live in a tag_*.c file,
but is within the core. Register/unregister when DSA is
loaded/unloaded.

Signed-off-by: Andrew Lunn <andrew@lunn.ch>
---
 net/dsa/dsa.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c
index 861fe1441a7d..a91c5ac86d86 100644
--- a/net/dsa/dsa.c
+++ b/net/dsa/dsa.c
@@ -358,12 +358,16 @@ static int __init dsa_init_module(void)
 
 	dev_add_pack(&dsa_pack_type);
 
+	dsa_tag_driver_register(&none_ops, THIS_MODULE);
+
 	return 0;
 }
 module_init(dsa_init_module);
 
 static void __exit dsa_cleanup_module(void)
 {
+	dsa_tag_driver_unregister(&none_ops);
+
 	dsa_slave_unregister_notifier();
 	dev_remove_pack(&dsa_pack_type);
 	dsa_legacy_unregister();
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [PATCH net-next 10/15] dsa: Rename dsa_resolve_tag_protocol() to _get ready for locking
  2019-04-18  2:31 [PATCH net-next 00/15] Make DSA tag drivers kernel modules Andrew Lunn
                   ` (8 preceding siblings ...)
  2019-04-18  2:31 ` [PATCH net-next 09/15] dsa: Register the none tagger ops Andrew Lunn
@ 2019-04-18  2:31 ` 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
                   ` (4 subsequent siblings)
  14 siblings, 1 reply; 37+ messages in thread
From: Andrew Lunn @ 2019-04-18  2:31 UTC (permalink / raw)
  To: David Miller; +Cc: netdev, Florian Fainelli, Vivien Didelot, Andrew Lunn

dsa_resolve_tag_protocol() is used to find the tagging driver needed
by a switch driver. When the tagging drivers become modules, it will
be necassary to take a reference on the module to prevent it being
unloaded. So rename this function to _get() to indicate it has some
locking properties.

Signed-off-by: Andrew Lunn <andrew@lunn.ch>
---
 net/dsa/dsa.c      | 2 +-
 net/dsa/dsa2.c     | 2 +-
 net/dsa/dsa_priv.h | 3 ++-
 net/dsa/legacy.c   | 2 +-
 4 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c
index a91c5ac86d86..5e99f291723f 100644
--- a/net/dsa/dsa.c
+++ b/net/dsa/dsa.c
@@ -127,7 +127,7 @@ const char *dsa_tag_protocol_to_str(const struct dsa_device_ops *ops)
 	return ops->name;
 };
 
-const struct dsa_device_ops *dsa_resolve_tag_protocol(int tag_protocol)
+const struct dsa_device_ops *dsa_tag_driver_get(int tag_protocol)
 {
 	const struct dsa_device_ops *ops;
 
diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c
index d122f1bcdab2..ba91bda8bdd3 100644
--- a/net/dsa/dsa2.c
+++ b/net/dsa/dsa2.c
@@ -577,7 +577,7 @@ static int dsa_port_parse_cpu(struct dsa_port *dp, struct net_device *master)
 	enum dsa_tag_protocol tag_protocol;
 
 	tag_protocol = ds->ops->get_tag_protocol(ds, dp->index);
-	tag_ops = dsa_resolve_tag_protocol(tag_protocol);
+	tag_ops = dsa_tag_driver_get(tag_protocol);
 	if (IS_ERR(tag_ops)) {
 		dev_warn(ds->dev, "No tagger for this switch\n");
 		return PTR_ERR(tag_ops);
diff --git a/net/dsa/dsa_priv.h b/net/dsa/dsa_priv.h
index 32a063cefe46..d7dbdf06e437 100644
--- a/net/dsa/dsa_priv.h
+++ b/net/dsa/dsa_priv.h
@@ -84,7 +84,8 @@ struct dsa_slave_priv {
 };
 
 /* dsa.c */
-const struct dsa_device_ops *dsa_resolve_tag_protocol(int tag_protocol);
+const struct dsa_device_ops *dsa_tag_driver_get(int tag_protocol);
+
 bool dsa_schedule_work(struct work_struct *work);
 const char *dsa_tag_protocol_to_str(const struct dsa_device_ops *ops);
 
diff --git a/net/dsa/legacy.c b/net/dsa/legacy.c
index cb42939db776..a8c076250237 100644
--- a/net/dsa/legacy.c
+++ b/net/dsa/legacy.c
@@ -152,7 +152,7 @@ static int dsa_switch_setup_one(struct dsa_switch *ds,
 		enum dsa_tag_protocol tag_protocol;
 
 		tag_protocol = ops->get_tag_protocol(ds, dst->cpu_dp->index);
-		tag_ops = dsa_resolve_tag_protocol(tag_protocol);
+		tag_ops = dsa_tag_driver_get(tag_protocol);
 		if (IS_ERR(tag_ops))
 			return PTR_ERR(tag_ops);
 
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [PATCH net-next 11/15] dsa: Add stub tag driver put method
  2019-04-18  2:31 [PATCH net-next 00/15] Make DSA tag drivers kernel modules Andrew Lunn
                   ` (9 preceding siblings ...)
  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-18  2:31 ` 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
                   ` (3 subsequent siblings)
  14 siblings, 1 reply; 37+ messages in thread
From: Andrew Lunn @ 2019-04-18  2:31 UTC (permalink / raw)
  To: David Miller; +Cc: netdev, Florian Fainelli, Vivien Didelot, Andrew Lunn

When a DSA switch driver is unloaded, the lock on the tag driver
should be released so the module can be unloaded. Add the needed calls,
but leave the actual relase code as a stub.

Signed-off-by: Andrew Lunn <andrew@lunn.ch>
---
 net/dsa/dsa.c      | 4 ++++
 net/dsa/dsa2.c     | 2 ++
 net/dsa/dsa_priv.h | 1 +
 net/dsa/legacy.c   | 2 ++
 4 files changed, 9 insertions(+)

diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c
index 5e99f291723f..a3210b2f88a2 100644
--- a/net/dsa/dsa.c
+++ b/net/dsa/dsa.c
@@ -141,6 +141,10 @@ const struct dsa_device_ops *dsa_tag_driver_get(int tag_protocol)
 	return ops;
 }
 
+void dsa_tag_driver_put(const struct dsa_device_ops *ops)
+{
+}
+
 static int dev_is_class(struct device *dev, void *class)
 {
 	if (dev->class != NULL && !strcmp(dev->class->name, class))
diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c
index ba91bda8bdd3..efc51a9dc9c8 100644
--- a/net/dsa/dsa2.c
+++ b/net/dsa/dsa2.c
@@ -335,6 +335,8 @@ static void dsa_port_teardown(struct dsa_port *dp)
 	case DSA_PORT_TYPE_UNUSED:
 		break;
 	case DSA_PORT_TYPE_CPU:
+		dsa_tag_driver_put(dp->tag_ops);
+		/* fall thought */
 	case DSA_PORT_TYPE_DSA:
 		dsa_port_link_unregister_of(dp);
 		break;
diff --git a/net/dsa/dsa_priv.h b/net/dsa/dsa_priv.h
index d7dbdf06e437..ec002a7c8a58 100644
--- a/net/dsa/dsa_priv.h
+++ b/net/dsa/dsa_priv.h
@@ -85,6 +85,7 @@ struct dsa_slave_priv {
 
 /* dsa.c */
 const struct dsa_device_ops *dsa_tag_driver_get(int tag_protocol);
+void dsa_tag_driver_put(const struct dsa_device_ops *ops);
 
 bool dsa_schedule_work(struct work_struct *work);
 const char *dsa_tag_protocol_to_str(const struct dsa_device_ops *ops);
diff --git a/net/dsa/legacy.c b/net/dsa/legacy.c
index a8c076250237..219f4fa7ff4b 100644
--- a/net/dsa/legacy.c
+++ b/net/dsa/legacy.c
@@ -163,6 +163,8 @@ static int dsa_switch_setup_one(struct dsa_switch *ds,
 		dst->cpu_dp->dst = dst;
 	}
 
+	dsa_tag_driver_put(dst->cpu_dp->tag_ops);
+
 	memcpy(ds->rtable, cd->rtable, sizeof(ds->rtable));
 
 	/*
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [PATCH net-next 12/15] dsa: Make use of the list of tag drivers
  2019-04-18  2:31 [PATCH net-next 00/15] Make DSA tag drivers kernel modules Andrew Lunn
                   ` (10 preceding siblings ...)
  2019-04-18  2:31 ` [PATCH net-next 11/15] dsa: Add stub tag driver put method Andrew Lunn
@ 2019-04-18  2:31 ` 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
                   ` (2 subsequent siblings)
  14 siblings, 1 reply; 37+ messages in thread
From: Andrew Lunn @ 2019-04-18  2:31 UTC (permalink / raw)
  To: David Miller; +Cc: netdev, Florian Fainelli, Vivien Didelot, Andrew Lunn

Implement the _get and _put functions to make use of the list of tag
drivers. Also, trigger the loading of the module, based on the alias
information. The _get function takes a reference on the tag driver, so
it cannot be unloaded, and the _put function releases the reference.

Signed-off-by: Andrew Lunn <andrew@lunn.ch>
---
 net/dsa/dsa.c | 30 ++++++++++++++++++++++++------
 1 file changed, 24 insertions(+), 6 deletions(-)

diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c
index a3210b2f88a2..17d26cc7a128 100644
--- a/net/dsa/dsa.c
+++ b/net/dsa/dsa.c
@@ -129,20 +129,38 @@ const char *dsa_tag_protocol_to_str(const struct dsa_device_ops *ops)
 
 const struct dsa_device_ops *dsa_tag_driver_get(int tag_protocol)
 {
-	const struct dsa_device_ops *ops;
+	struct dsa_device_ops *ops;
+	char module_name[128];
+	bool found = false;
 
-	if (tag_protocol >= DSA_TAG_LAST)
-		return ERR_PTR(-EINVAL);
-	ops = dsa_device_ops[tag_protocol];
+	snprintf(module_name, 127, "%s%d", DSA_TAG_DRIVER_ALIAS,
+		 tag_protocol);
 
-	if (!ops)
-		return ERR_PTR(-ENOPROTOOPT);
+	request_module(module_name);
+
+	mutex_lock(&dsa_tag_drivers_lock);
+	list_for_each_entry(ops, &dsa_tag_drivers_list, list) {
+		if (ops->proto == tag_protocol) {
+			found = true;
+			break;
+		}
+	}
+
+	if (found) {
+		if (!try_module_get(ops->owner))
+			ops = ERR_PTR(-ENOPROTOOPT);
+	} else {
+		ops = ERR_PTR(-ENOPROTOOPT);
+	}
+
+	mutex_unlock(&dsa_tag_drivers_lock);
 
 	return ops;
 }
 
 void dsa_tag_driver_put(const struct dsa_device_ops *ops)
 {
+	module_put(ops->owner);
 }
 
 static int dev_is_class(struct device *dev, void *class)
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [PATCH net-next 13/15] dsa: Cleanup unneeded table and make tag structures static
  2019-04-18  2:31 [PATCH net-next 00/15] Make DSA tag drivers kernel modules Andrew Lunn
                   ` (11 preceding siblings ...)
  2019-04-18  2:31 ` [PATCH net-next 12/15] dsa: Make use of the list of tag drivers Andrew Lunn
@ 2019-04-18  2:31 ` 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-18  2:31 ` [PATCH net-next 15/15] dsa: tag_brcm: Avoid unused symbols Andrew Lunn
  14 siblings, 1 reply; 37+ messages in thread
From: Andrew Lunn @ 2019-04-18  2:31 UTC (permalink / raw)
  To: David Miller; +Cc: netdev, Florian Fainelli, Vivien Didelot, Andrew Lunn

Now that tag drivers dynamically register, we don't need the static
table. Remove it. This also means the tag driver structures can be
made static.

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

diff --git a/include/net/dsa.h b/include/net/dsa.h
index 46774e812f1b..547507db2d02 100644
--- a/include/net/dsa.h
+++ b/include/net/dsa.h
@@ -56,7 +56,6 @@ enum dsa_tag_protocol {
 	DSA_TAG_PROTO_MTK		= DSA_TAG_PROTO_MTK_VALUE,
 	DSA_TAG_PROTO_QCA		= DSA_TAG_PROTO_QCA_VALUE,
 	DSA_TAG_PROTO_TRAILER		= DSA_TAG_PROTO_TRAILER_VALUE,
-	DSA_TAG_LAST,			/* MUST BE LAST */
 };
 
 struct packet_type;
diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c
index 17d26cc7a128..b3f0b32a4cd6 100644
--- a/net/dsa/dsa.c
+++ b/net/dsa/dsa.c
@@ -44,41 +44,6 @@ static struct dsa_device_ops none_ops = {
 	.rcv	= NULL,
 };
 
-const struct dsa_device_ops *dsa_device_ops[DSA_TAG_LAST] = {
-#ifdef CONFIG_NET_DSA_TAG_BRCM
-	[DSA_TAG_PROTO_BRCM] = &brcm_netdev_ops,
-#endif
-#ifdef CONFIG_NET_DSA_TAG_BRCM_PREPEND
-	[DSA_TAG_PROTO_BRCM_PREPEND] = &brcm_prepend_netdev_ops,
-#endif
-#ifdef CONFIG_NET_DSA_TAG_DSA
-	[DSA_TAG_PROTO_DSA] = &dsa_netdev_ops,
-#endif
-#ifdef CONFIG_NET_DSA_TAG_EDSA
-	[DSA_TAG_PROTO_EDSA] = &edsa_netdev_ops,
-#endif
-#ifdef CONFIG_NET_DSA_TAG_GSWIP
-	[DSA_TAG_PROTO_GSWIP] = &gswip_netdev_ops,
-#endif
-#ifdef CONFIG_NET_DSA_TAG_KSZ9477
-	[DSA_TAG_PROTO_KSZ9477] = &ksz9477_netdev_ops,
-	[DSA_TAG_PROTO_KSZ9893] = &ksz9893_netdev_ops,
-#endif
-#ifdef CONFIG_NET_DSA_TAG_LAN9303
-	[DSA_TAG_PROTO_LAN9303] = &lan9303_netdev_ops,
-#endif
-#ifdef CONFIG_NET_DSA_TAG_MTK
-	[DSA_TAG_PROTO_MTK] = &mtk_netdev_ops,
-#endif
-#ifdef CONFIG_NET_DSA_TAG_QCA
-	[DSA_TAG_PROTO_QCA] = &qca_netdev_ops,
-#endif
-#ifdef CONFIG_NET_DSA_TAG_TRAILER
-	[DSA_TAG_PROTO_TRAILER] = &trailer_netdev_ops,
-#endif
-	[DSA_TAG_PROTO_NONE] = &none_ops,
-};
-
 static int dsa_tag_driver_register(struct dsa_device_ops *ops,
 				   struct module *owner)
 {
diff --git a/net/dsa/dsa_priv.h b/net/dsa/dsa_priv.h
index ec002a7c8a58..7467d062f0c7 100644
--- a/net/dsa/dsa_priv.h
+++ b/net/dsa/dsa_priv.h
@@ -203,33 +203,4 @@ dsa_slave_to_master(const struct net_device *dev)
 int dsa_switch_register_notifier(struct dsa_switch *ds);
 void dsa_switch_unregister_notifier(struct dsa_switch *ds);
 
-/* tag_brcm.c */
-extern struct dsa_device_ops brcm_netdev_ops;
-extern struct dsa_device_ops brcm_prepend_netdev_ops;
-
-/* tag_dsa.c */
-extern struct dsa_device_ops dsa_netdev_ops;
-
-/* tag_edsa.c */
-extern struct dsa_device_ops edsa_netdev_ops;
-
-/* tag_gswip.c */
-extern struct dsa_device_ops gswip_netdev_ops;
-
-/* tag_ksz.c */
-extern struct dsa_device_ops ksz9477_netdev_ops;
-extern struct dsa_device_ops ksz9893_netdev_ops;
-
-/* tag_lan9303.c */
-extern struct dsa_device_ops lan9303_netdev_ops;
-
-/* tag_mtk.c */
-extern struct dsa_device_ops mtk_netdev_ops;
-
-/* tag_qca.c */
-extern struct dsa_device_ops qca_netdev_ops;
-
-/* tag_trailer.c */
-extern struct dsa_device_ops trailer_netdev_ops;
-
 #endif
diff --git a/net/dsa/tag_brcm.c b/net/dsa/tag_brcm.c
index bff9b03a7752..684730d52b4c 100644
--- a/net/dsa/tag_brcm.c
+++ b/net/dsa/tag_brcm.c
@@ -167,7 +167,7 @@ static struct sk_buff *brcm_tag_rcv(struct sk_buff *skb, struct net_device *dev,
 	return nskb;
 }
 
-struct dsa_device_ops brcm_netdev_ops = {
+static struct dsa_device_ops brcm_netdev_ops = {
 	.name	= "brcm",
 	.proto	= DSA_TAG_PROTO_BRCM,
 	.xmit	= brcm_tag_xmit,
@@ -194,7 +194,7 @@ static struct sk_buff *brcm_tag_rcv_prepend(struct sk_buff *skb,
 	return brcm_tag_rcv_ll(skb, dev, pt, ETH_HLEN);
 }
 
-struct dsa_device_ops brcm_prepend_netdev_ops = {
+static struct dsa_device_ops brcm_prepend_netdev_ops = {
 	.name	= "brcm-prepend",
 	.proto	= DSA_TAG_PROTO_BRCM_PREPEND,
 	.xmit	= brcm_tag_xmit_prepend,
diff --git a/net/dsa/tag_dsa.c b/net/dsa/tag_dsa.c
index 44e023e3da84..1dcc4bb7d295 100644
--- a/net/dsa/tag_dsa.c
+++ b/net/dsa/tag_dsa.c
@@ -150,7 +150,7 @@ static int dsa_tag_flow_dissect(const struct sk_buff *skb, __be16 *proto,
 	return 0;
 }
 
-struct dsa_device_ops dsa_netdev_ops = {
+static struct dsa_device_ops dsa_netdev_ops = {
 	.name	= "dsa",
 	.proto	= DSA_TAG_PROTO_DSA,
 	.xmit	= dsa_xmit,
diff --git a/net/dsa/tag_edsa.c b/net/dsa/tag_edsa.c
index e51e5db45d43..59f0a7a57743 100644
--- a/net/dsa/tag_edsa.c
+++ b/net/dsa/tag_edsa.c
@@ -169,7 +169,7 @@ static int edsa_tag_flow_dissect(const struct sk_buff *skb, __be16 *proto,
 	return 0;
 }
 
-struct dsa_device_ops edsa_netdev_ops = {
+static struct dsa_device_ops edsa_netdev_ops = {
 	.name	= "edsa",
 	.proto	= DSA_TAG_PROTO_EDSA,
 	.xmit	= edsa_xmit,
diff --git a/net/dsa/tag_gswip.c b/net/dsa/tag_gswip.c
index 38d7617d8a03..a681d0878c0e 100644
--- a/net/dsa/tag_gswip.c
+++ b/net/dsa/tag_gswip.c
@@ -103,7 +103,7 @@ static struct sk_buff *gswip_tag_rcv(struct sk_buff *skb,
 	return skb;
 }
 
-struct dsa_device_ops gswip_netdev_ops = {
+static struct dsa_device_ops gswip_netdev_ops = {
 	.name = "gwsip",
 	.proto	= DSA_TAG_PROTO_GSWIP,
 	.xmit = gswip_tag_xmit,
diff --git a/net/dsa/tag_ksz.c b/net/dsa/tag_ksz.c
index 3e4ea4ac10d6..059a015bcaae 100644
--- a/net/dsa/tag_ksz.c
+++ b/net/dsa/tag_ksz.c
@@ -133,7 +133,7 @@ static struct sk_buff *ksz9477_rcv(struct sk_buff *skb, struct net_device *dev,
 	return ksz_common_rcv(skb, dev, port, len);
 }
 
-struct dsa_device_ops ksz9477_netdev_ops = {
+static struct dsa_device_ops ksz9477_netdev_ops = {
 	.name	= "ksz9477",
 	.proto	= DSA_TAG_PROTO_KSZ9477,
 	.xmit	= ksz9477_xmit,
@@ -170,7 +170,7 @@ static struct sk_buff *ksz9893_xmit(struct sk_buff *skb,
 	return nskb;
 }
 
-struct dsa_device_ops ksz9893_netdev_ops = {
+static struct dsa_device_ops ksz9893_netdev_ops = {
 	.name	= "ksz9893",
 	.proto	= DSA_TAG_PROTO_KSZ9893,
 	.xmit	= ksz9893_xmit,
diff --git a/net/dsa/tag_lan9303.c b/net/dsa/tag_lan9303.c
index 4135080559cf..ee39e73fe9f9 100644
--- a/net/dsa/tag_lan9303.c
+++ b/net/dsa/tag_lan9303.c
@@ -128,7 +128,7 @@ static struct sk_buff *lan9303_rcv(struct sk_buff *skb, struct net_device *dev,
 	return skb;
 }
 
-struct dsa_device_ops lan9303_netdev_ops = {
+static struct dsa_device_ops lan9303_netdev_ops = {
 	.name = "lan9303",
 	.proto	= DSA_TAG_PROTO_LAN9303,
 	.xmit = lan9303_xmit,
diff --git a/net/dsa/tag_mtk.c b/net/dsa/tag_mtk.c
index bcca5e1a3732..4dfbb79435cc 100644
--- a/net/dsa/tag_mtk.c
+++ b/net/dsa/tag_mtk.c
@@ -98,7 +98,7 @@ static int mtk_tag_flow_dissect(const struct sk_buff *skb, __be16 *proto,
 	return 0;
 }
 
-struct dsa_device_ops mtk_netdev_ops = {
+static struct dsa_device_ops mtk_netdev_ops = {
 	.name		= "mtk",
 	.proto		= DSA_TAG_PROTO_MTK,
 	.xmit		= mtk_tag_xmit,
diff --git a/net/dsa/tag_qca.c b/net/dsa/tag_qca.c
index fce437c51fcd..f8ab977a42a8 100644
--- a/net/dsa/tag_qca.c
+++ b/net/dsa/tag_qca.c
@@ -99,7 +99,7 @@ static int qca_tag_flow_dissect(const struct sk_buff *skb, __be16 *proto,
 	return 0;
 }
 
-struct dsa_device_ops qca_netdev_ops = {
+static struct dsa_device_ops qca_netdev_ops = {
 	.name	= "qca",
 	.proto	= DSA_TAG_PROTO_QCA,
 	.xmit	= qca_tag_xmit,
diff --git a/net/dsa/tag_trailer.c b/net/dsa/tag_trailer.c
index d8955ec1a38f..8d6446d4ee41 100644
--- a/net/dsa/tag_trailer.c
+++ b/net/dsa/tag_trailer.c
@@ -77,7 +77,7 @@ static struct sk_buff *trailer_rcv(struct sk_buff *skb, struct net_device *dev,
 	return skb;
 }
 
-struct dsa_device_ops trailer_netdev_ops = {
+static struct dsa_device_ops trailer_netdev_ops = {
 	.name	= "trailer",
 	.proto	= DSA_TAG_PROTO_TRAILER,
 	.xmit	= trailer_xmit,
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [PATCH net-next 14/15] dsa: Allow tag drivers to be built as modules
  2019-04-18  2:31 [PATCH net-next 00/15] Make DSA tag drivers kernel modules Andrew Lunn
                   ` (12 preceding siblings ...)
  2019-04-18  2:31 ` [PATCH net-next 13/15] dsa: Cleanup unneeded table and make tag structures static Andrew Lunn
@ 2019-04-18  2:31 ` 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
  14 siblings, 1 reply; 37+ messages in thread
From: Andrew Lunn @ 2019-04-18  2:31 UTC (permalink / raw)
  To: David Miller; +Cc: netdev, Florian Fainelli, Vivien Didelot, Andrew Lunn

Make the CONFIG symbols tristate and add help text.

The broadcom and Microchip KSZ tag drivers support two different
tagging protocols in one driver. Add a configuration option for the
drivers, and then options to select the protocol.

Create a submenu for the tagging drivers.

Signed-off-by: Andrew Lunn <andrew@lunn.ch>
---
 net/dsa/Kconfig  | 86 +++++++++++++++++++++++++++++++++++++-----------
 net/dsa/Makefile | 19 +++++------
 2 files changed, 76 insertions(+), 29 deletions(-)

diff --git a/net/dsa/Kconfig b/net/dsa/Kconfig
index b695170795c2..01bb770338eb 100644
--- a/net/dsa/Kconfig
+++ b/net/dsa/Kconfig
@@ -4,7 +4,7 @@ config HAVE_NET_DSA
 
 # Drivers must select NET_DSA and the appropriate tagging format
 
-config NET_DSA
+menuconfig NET_DSA
 	tristate "Distributed Switch Architecture"
 	depends on HAVE_NET_DSA
 	depends on BRIDGE || BRIDGE=n
@@ -26,39 +26,87 @@ config NET_DSA_LEGACY
 
 	  This feature is scheduled for removal in 4.17.
 
-# tagging formats
+config NET_DSA_TAG_BRCM_COMMON
+       tristate "Tag driver for Broadcom switch"
+	help
+          Say Y or M if you want to enable support for tagging frames
+	  for the Broadcom switches.
+
 config NET_DSA_TAG_BRCM
-	bool
+	bool "Tag driver for Broadcom switch using in frame headers"
+	depends on NET_DSA_TAG_BRCM_COMMON
+	help
+	  Say Y if you want to enable support for tagging frames for the
+	  Broadcom switches which place the tag after the MAC addresses.
+
 
 config NET_DSA_TAG_BRCM_PREPEND
-	bool
+	bool "Tag driver for Broadcom switches using prepended headers"
+	depends on NET_DSA_TAG_BRCM_COMMON
+	help
+	  Say Y if you want to enable support for tagging frames for the
+	  Broadcom switches which preprended headers.
+
+config NET_DSA_TAG_GSWIP
+	tristate "Tag driver for Lantiq / Intel GSWIP switches"
+	help
+	  Say Y or M if you want to enable support for tagging frames for the
+	  Lantiq / Intel GSWIP switches
 
 config NET_DSA_TAG_DSA
-	bool
+	tristate "Tag driver for Marvell switches using DSA headers"
+	help
+	  Say Y or M if you want to enable support for tagging frames for the
+	  Marvell switches which use DSA headers
 
 config NET_DSA_TAG_EDSA
-	bool
+	tristate "Tag driver for Marvell switches using EtherType DSA headers"
+	help
+	  Say Y or M if you want to enable support for tagging frames for the
+	  Marvell switches which use EtherType DSA headers
 
-config NET_DSA_TAG_GSWIP
-	bool
+config NET_DSA_TAG_MTK
+	tristate "Tag driver for Mediatek switches"
+	help
+	  Say Y or M if you want to enable support for tagging frames for
+	  Mediatek switches
+
+config NET_DSA_TAG_KSZ_COMMON
+	tristate "Tag driver for Microchip KSZ families of switches"
+	help
+	  Say Y or M if you want to enable support for tagging frames for the
+	  Microchip KZS families of switches
 
 config NET_DSA_TAG_KSZ
-	bool
+	bool "Tag driver for Microchip 9893 family of switches"
+	depends on NET_DSA_TAG_KSZ_COMMON
+	help
+	  Say Y if you want to enable support for tagging frames for the
+	  Microchip 9893 family of switches
 
 config NET_DSA_TAG_KSZ9477
-	bool
-	select NET_DSA_TAG_KSZ
+	bool "Tag driver for Microchip 9477 family of switches"
+	depends on NET_DSA_TAG_KSZ_COMMON
+	help
+	  Say Y if you want to enable support for tagging frames for the
+	  Microchip 9477 family of switches
 
-config NET_DSA_TAG_LAN9303
-	bool
+config NET_DSA_TAG_QCA
+       tristate "Tag driver for Qualcomm Atheros QCA8K switches"
+	help
+	  Say Y or M if you want to enable support for tagging frames for
+	  the Qualcomm Atheros QCA8K switches
 
-config NET_DSA_TAG_MTK
-	bool
+config NET_DSA_TAG_LAN9303
+	tristate "Tag driver for SMSC/Microchip LAN9303 family of switches"
+	help
+	  Say Y or M if you want to enable support for tagging frames for the
+	  SMSC/Microchip LAN9303 family of switches
 
 config NET_DSA_TAG_TRAILER
-	bool
-
-config NET_DSA_TAG_QCA
-	bool
+       tristate "Tag driver for switches using a trailler tag"
+	help
+	  Say Y or M if you want to enable support for tagging frames at
+	  with a trailed. e.g. Marvell 88E6060
 
 endif
diff --git a/net/dsa/Makefile b/net/dsa/Makefile
index 6e721f7a2947..717ac1618100 100644
--- a/net/dsa/Makefile
+++ b/net/dsa/Makefile
@@ -5,13 +5,12 @@ dsa_core-y += dsa.o dsa2.o master.o port.o slave.o switch.o
 dsa_core-$(CONFIG_NET_DSA_LEGACY) += legacy.o
 
 # tagging formats
-dsa_core-$(CONFIG_NET_DSA_TAG_BRCM) += tag_brcm.o
-dsa_core-$(CONFIG_NET_DSA_TAG_BRCM_PREPEND) += tag_brcm.o
-dsa_core-$(CONFIG_NET_DSA_TAG_DSA) += tag_dsa.o
-dsa_core-$(CONFIG_NET_DSA_TAG_EDSA) += tag_edsa.o
-dsa_core-$(CONFIG_NET_DSA_TAG_GSWIP) += tag_gswip.o
-dsa_core-$(CONFIG_NET_DSA_TAG_KSZ) += tag_ksz.o
-dsa_core-$(CONFIG_NET_DSA_TAG_LAN9303) += tag_lan9303.o
-dsa_core-$(CONFIG_NET_DSA_TAG_MTK) += tag_mtk.o
-dsa_core-$(CONFIG_NET_DSA_TAG_QCA) += tag_qca.o
-dsa_core-$(CONFIG_NET_DSA_TAG_TRAILER) += tag_trailer.o
+obj-$(CONFIG_NET_DSA_TAG_BRCM_COMMON) += tag_brcm.o
+obj-$(CONFIG_NET_DSA_TAG_DSA) += tag_dsa.o
+obj-$(CONFIG_NET_DSA_TAG_EDSA) += tag_edsa.o
+obj-$(CONFIG_NET_DSA_TAG_GSWIP) += tag_gswip.o
+obj-$(CONFIG_NET_DSA_TAG_KSZ_COMMON) += tag_ksz.o
+obj-$(CONFIG_NET_DSA_TAG_LAN9303) += tag_lan9303.o
+obj-$(CONFIG_NET_DSA_TAG_MTK) += tag_mtk.o
+obj-$(CONFIG_NET_DSA_TAG_QCA) += tag_qca.o
+obj-$(CONFIG_NET_DSA_TAG_TRAILER) += tag_trailer.o
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [PATCH net-next 15/15] dsa: tag_brcm: Avoid unused symbols
  2019-04-18  2:31 [PATCH net-next 00/15] Make DSA tag drivers kernel modules Andrew Lunn
                   ` (13 preceding siblings ...)
  2019-04-18  2:31 ` [PATCH net-next 14/15] dsa: Allow tag drivers to be built as modules Andrew Lunn
@ 2019-04-18  2:31 ` Andrew Lunn
  2019-04-19 15:39   ` Florian Fainelli
  14 siblings, 1 reply; 37+ messages in thread
From: Andrew Lunn @ 2019-04-18  2:31 UTC (permalink / raw)
  To: David Miller; +Cc: netdev, Florian Fainelli, Vivien Didelot, Andrew Lunn

It is possible that the driver is compiled with both
CONFIG_NET_DSA_TAG_BRCM and CONFIG_NET_DSA_TAG_BRCM_PREPEND disabled.
This results in warnings about unused symbols. Add some conditional
compilation to avoid this.

Signed-off-by: Andrew Lunn <andrew@lunn.ch>
---
 net/dsa/tag_brcm.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/net/dsa/tag_brcm.c b/net/dsa/tag_brcm.c
index 684730d52b4c..ad81521a7782 100644
--- a/net/dsa/tag_brcm.c
+++ b/net/dsa/tag_brcm.c
@@ -55,6 +55,9 @@
 #define BRCM_EG_TC_MASK		0x7
 #define BRCM_EG_PID_MASK	0x1f
 
+#if IS_ENABLED(CONFIG_NET_DSA_TAG_BRCM) || \
+	IS_ENABLED(CONFIG_NET_DSA_TAG_BRCM_PREPEND)
+
 static struct sk_buff *brcm_tag_xmit_ll(struct sk_buff *skb,
 					struct net_device *dev,
 					unsigned int offset)
@@ -139,6 +142,7 @@ static struct sk_buff *brcm_tag_rcv_ll(struct sk_buff *skb,
 
 	return skb;
 }
+#endif
 
 #ifdef CONFIG_NET_DSA_TAG_BRCM
 static struct sk_buff *brcm_tag_xmit(struct sk_buff *skb,
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 37+ messages in thread

* Re: [PATCH net-next 08/15] dsa: Keep link list of tag drivers
  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-19 15:30   ` Florian Fainelli
  2 siblings, 0 replies; 37+ messages in thread
From: David Miller @ 2019-04-18  7:25 UTC (permalink / raw)
  To: andrew; +Cc: netdev, f.fainelli, vivien.didelot

From: Andrew Lunn <andrew@lunn.ch>
Date: Thu, 18 Apr 2019 04:31:13 +0200

> +static int dsa_tag_driver_register(struct dsa_device_ops *ops,
> +				   struct module *owner)
> +{
> +	ops->owner = owner;
> +
> +	mutex_lock(&dsa_tag_drivers_lock);
> +	list_add_tail(&ops->list, &dsa_tag_drivers_list);
> +	mutex_unlock(&dsa_tag_drivers_lock);
> +	return 0;
> +}
> +
>  int dsa_tag_drivers_register(struct dsa_device_ops *ops[],
>  			     unsigned int count, struct module *owner)
>  {
> -	return 0;
> +	int err, i;
> +
> +	for (i = 0; i < count; i++) {
> +		err = dsa_tag_driver_register(ops[i], owner);
> +		if (err)
> +			break;
> +	}
> +
> +	return err;
> +}

dsa_tag_driver_register() never returns non-zero, and anyways it's probably
not nice to return an error leaving a partial registry of the given ops
vector.  We'd have to unwind, because the calling module could unload itself
on such a failure.

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [PATCH net-next 08/15] dsa: Keep link list of tag drivers
  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-19 15:30   ` Florian Fainelli
  2 siblings, 1 reply; 37+ messages in thread
From: Sergei Shtylyov @ 2019-04-18  9:35 UTC (permalink / raw)
  To: Andrew Lunn, David Miller; +Cc: netdev, Florian Fainelli, Vivien Didelot

On 18.04.2019 5:31, Andrew Lunn wrote:

> Let the tag drivers register themselves with the DSA core, keeping
> them in a linked list.
> 
> Signed-off-by: Andrew Lunn <andrew@lunn.ch>
> ---
>   include/net/dsa.h |  2 ++
>   net/dsa/dsa.c     | 35 ++++++++++++++++++++++++++++++++++-
>   2 files changed, 36 insertions(+), 1 deletion(-)
> 
[...]
> diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c
> index a49e230b6247..861fe1441a7d 100644
> --- a/net/dsa/dsa.c
> +++ b/net/dsa/dsa.c
> @@ -27,6 +27,9 @@
[...]
>   int dsa_tag_drivers_register(struct dsa_device_ops *ops[],
>   			     unsigned int count, struct module *owner)
>   {
> -	return 0;
> +	int err, i;
> +
> +	for (i = 0; i < count; i++) {
> +		err = dsa_tag_driver_register(ops[i], owner);
> +		if (err)
> +			break;
> +	}
> +
> +	return err;

    What if count == 0? Can't happen?

[...]

MBR, Sergei

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [PATCH net-next 08/15] dsa: Keep link list of tag drivers
  2019-04-18  9:35   ` Sergei Shtylyov
@ 2019-04-18 13:19     ` Andrew Lunn
  2019-04-18 14:40       ` Sergei Shtylyov
  0 siblings, 1 reply; 37+ messages in thread
From: Andrew Lunn @ 2019-04-18 13:19 UTC (permalink / raw)
  To: Sergei Shtylyov; +Cc: David Miller, netdev, Florian Fainelli, Vivien Didelot

On Thu, Apr 18, 2019 at 12:35:44PM +0300, Sergei Shtylyov wrote:
> On 18.04.2019 5:31, Andrew Lunn wrote:
> 
> >Let the tag drivers register themselves with the DSA core, keeping
> >them in a linked list.
> >
> >Signed-off-by: Andrew Lunn <andrew@lunn.ch>
> >---
> >  include/net/dsa.h |  2 ++
> >  net/dsa/dsa.c     | 35 ++++++++++++++++++++++++++++++++++-
> >  2 files changed, 36 insertions(+), 1 deletion(-)
> >
> [...]
> >diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c
> >index a49e230b6247..861fe1441a7d 100644
> >--- a/net/dsa/dsa.c
> >+++ b/net/dsa/dsa.c
> >@@ -27,6 +27,9 @@
> [...]
> >  int dsa_tag_drivers_register(struct dsa_device_ops *ops[],
> >  			     unsigned int count, struct module *owner)
> >  {
> >-	return 0;
> >+	int err, i;
> >+
> >+	for (i = 0; i < count; i++) {
> >+		err = dsa_tag_driver_register(ops[i], owner);
> >+		if (err)
> >+			break;
> >+	}
> >+
> >+	return err;
> 
>    What if count == 0? Can't happen?

Hi Sergei

The current drivers would prevent that. But to be robust, i will add a
check.

Thanks
	Andrew

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [PATCH net-next 08/15] dsa: Keep link list of tag drivers
  2019-04-18 13:19     ` Andrew Lunn
@ 2019-04-18 14:40       ` Sergei Shtylyov
  0 siblings, 0 replies; 37+ messages in thread
From: Sergei Shtylyov @ 2019-04-18 14:40 UTC (permalink / raw)
  To: Andrew Lunn; +Cc: David Miller, netdev, Florian Fainelli, Vivien Didelot

On 04/18/2019 04:19 PM, Andrew Lunn wrote:

>>> Let the tag drivers register themselves with the DSA core, keeping
>>> them in a linked list.
>>>
>>> Signed-off-by: Andrew Lunn <andrew@lunn.ch>
>>> ---
>>>  include/net/dsa.h |  2 ++
>>>  net/dsa/dsa.c     | 35 ++++++++++++++++++++++++++++++++++-
>>>  2 files changed, 36 insertions(+), 1 deletion(-)
>>>
>> [...]
>>> diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c
>>> index a49e230b6247..861fe1441a7d 100644
>>> --- a/net/dsa/dsa.c
>>> +++ b/net/dsa/dsa.c
>>> @@ -27,6 +27,9 @@
>> [...]
>>>  int dsa_tag_drivers_register(struct dsa_device_ops *ops[],
>>>  			     unsigned int count, struct module *owner)
>>>  {
>>> -	return 0;
>>> +	int err, i;
>>> +
>>> +	for (i = 0; i < count; i++) {
>>> +		err = dsa_tag_driver_register(ops[i], owner);
>>> +		if (err)
>>> +			break;
>>> +	}
>>> +
>>> +	return err;
>>
>>    What if count == 0? Can't happen?
> 
> Hi Sergei
> 
> The current drivers would prevent that. But to be robust, i will add a
> check.

   You'd just need to init the variavble. :-)

> Thanks
> 	Andrew

MBR, Sergei

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [PATCH net-next 01/15] dsa: Add SPDX header to tag drivers.
  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
  0 siblings, 0 replies; 37+ messages in thread
From: Florian Fainelli @ 2019-04-18 17:35 UTC (permalink / raw)
  To: Andrew Lunn, David Miller; +Cc: netdev, Vivien Didelot



On 4/17/2019 7:31 PM, Andrew Lunn wrote:
> Add an SPDX header, and remove the license boilerplate text.
> 
> Signed-off-by: Andrew Lunn <andrew@lunn.ch>

Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
-- 
Florian

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [PATCH net-next 02/15] dsa: Move tagger name into its ops structure
  2019-04-18  2:31 ` [PATCH net-next 02/15] dsa: Move tagger name into its ops structure Andrew Lunn
@ 2019-04-18 17:37   ` Florian Fainelli
  0 siblings, 0 replies; 37+ messages in thread
From: Florian Fainelli @ 2019-04-18 17:37 UTC (permalink / raw)
  To: Andrew Lunn, David Miller; +Cc: netdev, Vivien Didelot



On 4/17/2019 7:31 PM, Andrew Lunn wrote:
> 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>
> ---

[snip]

> 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;

Nit: I would place this after the xmit and rcv function pointers since
we do not control how big the name is and it could theoretically push us
one cache line down... With that:

Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
-- 
Florian

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [PATCH net-next 04/15] dsa: Add MODULE_LICENSE to tag drivers
  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
  0 siblings, 0 replies; 37+ messages in thread
From: Florian Fainelli @ 2019-04-18 17:51 UTC (permalink / raw)
  To: Andrew Lunn, David Miller; +Cc: netdev, Vivien Didelot



On 4/17/2019 7:31 PM, Andrew Lunn wrote:
> All the tag drivers are some variant of GPL. Add a MODULE_LICENSE()
> indicating this, so the drivers can later be compiled as modules.
> 
> Signed-off-by: Andrew Lunn <andrew@lunn.ch>

Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
-- 
Florian

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [PATCH net-next 06/15] dsa: Remove const from tag driver ops structure
  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
  0 siblings, 1 reply; 37+ messages in thread
From: Florian Fainelli @ 2019-04-18 17:58 UTC (permalink / raw)
  To: Andrew Lunn, David Miller; +Cc: netdev, Vivien Didelot



On 4/17/2019 7:31 PM, Andrew Lunn wrote:
> A later patch will create a linked list of tag driver ops structures,
> using a list_head in the structure. So the structure cannot be const.

Can't we encapsulate the existing dsa_device_ops, while leaving them
const into another structure which is not const? Similar to how we did
with the dsa_switch_driver structure?
-- 
Florian

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [PATCH net-next 06/15] dsa: Remove const from tag driver ops structure
  2019-04-18 17:58   ` Florian Fainelli
@ 2019-04-18 21:47     ` Andrew Lunn
  2019-04-19 15:26       ` Florian Fainelli
  0 siblings, 1 reply; 37+ messages in thread
From: Andrew Lunn @ 2019-04-18 21:47 UTC (permalink / raw)
  To: Florian Fainelli; +Cc: David Miller, netdev, Vivien Didelot

On Thu, Apr 18, 2019 at 10:58:46AM -0700, Florian Fainelli wrote:
> 
> 
> On 4/17/2019 7:31 PM, Andrew Lunn wrote:
> > A later patch will create a linked list of tag driver ops structures,
> > using a list_head in the structure. So the structure cannot be const.
> 
> Can't we encapsulate the existing dsa_device_ops, while leaving them
> const into another structure which is not const? Similar to how we did
> with the dsa_switch_driver structure?

Hi Florian

I was trying to keep it KISS, no dynamic memory allocation.

But i can make it more complex. For a tag driver with a single set of
ops, i can probably hide it all in the boiler plate, and make it all
static memory. For tag_brcm.c and tag_ksz.c, which have two ops
structures, i'm not sure i can hide it all.

I will think about it.

	Andrew


^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [PATCH net-next 03/15] dsa: Add MODULE_ALIAS to taggers in preperation to become modules
  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
  0 siblings, 0 replies; 37+ messages in thread
From: Florian Fainelli @ 2019-04-19 15:25 UTC (permalink / raw)
  To: Andrew Lunn, David Miller; +Cc: netdev, Vivien Didelot



On 4/17/2019 7:31 PM, Andrew Lunn wrote:
> When the tag drivers become modules, we will need to dynamically load
> them based on what the switch drivers need. Add aliases to map between
> the TAG protocol and the driver.
> 
> In order to do this, we need the tag protocol number as something
> which the C pre-processor can stringinfy. Only the compiler knows the
> value of an enum, CPP cannot use them. So add #defines.
> 
> Signed-off-by: Andrew Lunn <andrew@lunn.ch>

Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>

Just in case you need to resubmit, typo in the subject
s/preperation/preparation/

Thanks!
-- 
Florian

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [PATCH net-next 06/15] dsa: Remove const from tag driver ops structure
  2019-04-18 21:47     ` Andrew Lunn
@ 2019-04-19 15:26       ` Florian Fainelli
  0 siblings, 0 replies; 37+ messages in thread
From: Florian Fainelli @ 2019-04-19 15:26 UTC (permalink / raw)
  To: Andrew Lunn; +Cc: David Miller, netdev, Vivien Didelot



On 4/18/2019 2:47 PM, Andrew Lunn wrote:
> On Thu, Apr 18, 2019 at 10:58:46AM -0700, Florian Fainelli wrote:
>>
>>
>> On 4/17/2019 7:31 PM, Andrew Lunn wrote:
>>> A later patch will create a linked list of tag driver ops structures,
>>> using a list_head in the structure. So the structure cannot be const.
>>
>> Can't we encapsulate the existing dsa_device_ops, while leaving them
>> const into another structure which is not const? Similar to how we did
>> with the dsa_switch_driver structure?
> 
> Hi Florian
> 
> I was trying to keep it KISS, no dynamic memory allocation.
> 
> But i can make it more complex. For a tag driver with a single set of
> ops, i can probably hide it all in the boiler plate, and make it all
> static memory. For tag_brcm.c and tag_ksz.c, which have two ops
> structures, i'm not sure i can hide it all.

I don't think you need dynamic allocation, since you already have a
dsa_device_ops structure within each of the tagger source file, you can
just encapsulate that within the context of the file:

struct dsa_tag_driver {
	const char *name;
	const struct dsa_device_ops *ops;
}

Or something along those lines?
-- 
Florian

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [PATCH net-next 05/15] dsa: Add TAG protocol to tag ops
  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
  0 siblings, 0 replies; 37+ messages in thread
From: Florian Fainelli @ 2019-04-19 15:27 UTC (permalink / raw)
  To: Andrew Lunn, David Miller; +Cc: netdev, Vivien Didelot



On 4/17/2019 7:31 PM, Andrew Lunn wrote:
> In order that we can match the tagging protocol a switch driver
> request to the tagger, we need to know what protocol the tagger
> supports. Add this information to the ops structure.
> 
> Signed-off-by: Andrew Lunn <andrew@lunn.ch>

Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
-- 
Florian

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [PATCH net-next 07/15] dsa: Add boilerplate helper to register DSA tag driver modules
  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
  0 siblings, 0 replies; 37+ messages in thread
From: Florian Fainelli @ 2019-04-19 15:29 UTC (permalink / raw)
  To: Andrew Lunn, David Miller; +Cc: netdev, Vivien Didelot



On 4/17/2019 7:31 PM, Andrew Lunn wrote:
> A DSA tag driver module will need to register the tag protocols it
> implements with the DSA core. Add a macro containing this boiler plate.
> 
> The registration/unregistration code is currently just a stub. A Later
> patch will add the real implementation.
> 
> Signed-off-by: Andrew Lunn <andrew@lunn.ch>
> ---
[snip]

> diff --git a/net/dsa/tag_brcm.c b/net/dsa/tag_brcm.c
> index 756bade54fee..bff9b03a7752 100644
> --- a/net/dsa/tag_brcm.c
> +++ b/net/dsa/tag_brcm.c
> @@ -205,3 +205,14 @@ struct dsa_device_ops brcm_prepend_netdev_ops = {
>  
>  MODULE_LICENSE("GPL");
>  MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_BRCM_PREPEND);
> +
> +static struct dsa_device_ops *ops_array[] = {
> +#ifdef CONFIG_NET_DSA_TAG_BRCM
> +	&brcm_netdev_ops,
> +	#endif
> +#ifdef CONFIG_NET_DSA_TAG_BRCM_PREPEND
> +	&brcm_prepend_netdev_ops,
> +	#endif
> +};

The indentation for the two #endif is off by one tab here. Other than that:

Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
-- 
Florian

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [PATCH net-next 08/15] dsa: Keep link list of tag drivers
  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-19 15:30   ` Florian Fainelli
  2 siblings, 0 replies; 37+ messages in thread
From: Florian Fainelli @ 2019-04-19 15:30 UTC (permalink / raw)
  To: Andrew Lunn, David Miller; +Cc: netdev, Vivien Didelot



On 4/17/2019 7:31 PM, Andrew Lunn wrote:
> Let the tag drivers register themselves with the DSA core, keeping
> them in a linked list.
> 
> Signed-off-by: Andrew Lunn <andrew@lunn.ch>
> ---

[snip]

>  int dsa_tag_drivers_register(struct dsa_device_ops *ops[],
>  			     unsigned int count, struct module *owner)
>  {
> -	return 0;
> +	int err, i;
> +
> +	for (i = 0; i < count; i++) {

count is unsigned, so i should also be unsigned.

> +		err = dsa_tag_driver_register(ops[i], owner);
> +		if (err)
> +			break;
> +	}
> +
> +	return err;
> +}
> +
> +static void dsa_tag_driver_unregister(struct dsa_device_ops *ops)
> +{
> +	mutex_lock(&dsa_tag_drivers_lock);
> +	list_del(&ops->list);
> +	mutex_unlock(&dsa_tag_drivers_lock);
>  }
>  EXPORT_SYMBOL_GPL(dsa_tag_drivers_register);
>  
>  void dsa_tag_drivers_unregister(struct dsa_device_ops *ops[],
>  				unsigned int count)
>  {
> +	int i;
> +
> +	for (i = 0; i < count; i++)
> +		dsa_tag_driver_unregister(ops[i]);

Likewise.
-- 
Florian

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [PATCH net-next 09/15] dsa: Register the none tagger ops
  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
  0 siblings, 0 replies; 37+ messages in thread
From: Florian Fainelli @ 2019-04-19 15:31 UTC (permalink / raw)
  To: Andrew Lunn, David Miller; +Cc: netdev, Vivien Didelot



On 4/17/2019 7:31 PM, Andrew Lunn wrote:
> The none tagger is special in that it does not live in a tag_*.c file,
> but is within the core. Register/unregister when DSA is
> loaded/unloaded.
> 
> Signed-off-by: Andrew Lunn <andrew@lunn.ch>

Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
-- 
Florian

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [PATCH net-next 10/15] dsa: Rename dsa_resolve_tag_protocol() to _get ready for locking
  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
  0 siblings, 0 replies; 37+ messages in thread
From: Florian Fainelli @ 2019-04-19 15:31 UTC (permalink / raw)
  To: Andrew Lunn, David Miller; +Cc: netdev, Vivien Didelot



On 4/17/2019 7:31 PM, Andrew Lunn wrote:
> dsa_resolve_tag_protocol() is used to find the tagging driver needed
> by a switch driver. When the tagging drivers become modules, it will
> be necassary to take a reference on the module to prevent it being
> unloaded. So rename this function to _get() to indicate it has some
> locking properties.
> 
> Signed-off-by: Andrew Lunn <andrew@lunn.ch>

Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
-- 
Florian

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [PATCH net-next 11/15] dsa: Add stub tag driver put method
  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
  0 siblings, 0 replies; 37+ messages in thread
From: Florian Fainelli @ 2019-04-19 15:32 UTC (permalink / raw)
  To: Andrew Lunn, David Miller; +Cc: netdev, Vivien Didelot



On 4/17/2019 7:31 PM, Andrew Lunn wrote:
> When a DSA switch driver is unloaded, the lock on the tag driver
> should be released so the module can be unloaded. Add the needed calls,
> but leave the actual relase code as a stub.
> 
> Signed-off-by: Andrew Lunn <andrew@lunn.ch>
> ---

[snip]

> diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c
> index ba91bda8bdd3..efc51a9dc9c8 100644
> --- a/net/dsa/dsa2.c
> +++ b/net/dsa/dsa2.c
> @@ -335,6 +335,8 @@ static void dsa_port_teardown(struct dsa_port *dp)
>  	case DSA_PORT_TYPE_UNUSED:
>  		break;
>  	case DSA_PORT_TYPE_CPU:
> +		dsa_tag_driver_put(dp->tag_ops);
> +		/* fall thought */

Typo: s/fall thought/fall through/

Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
-- 
Florian

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [PATCH net-next 12/15] dsa: Make use of the list of tag drivers
  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
  0 siblings, 0 replies; 37+ messages in thread
From: Florian Fainelli @ 2019-04-19 15:33 UTC (permalink / raw)
  To: Andrew Lunn, David Miller; +Cc: netdev, Vivien Didelot



On 4/17/2019 7:31 PM, Andrew Lunn wrote:
> Implement the _get and _put functions to make use of the list of tag
> drivers. Also, trigger the loading of the module, based on the alias
> information. The _get function takes a reference on the tag driver, so
> it cannot be unloaded, and the _put function releases the reference.
> 
> Signed-off-by: Andrew Lunn <andrew@lunn.ch>

Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
-- 
Florian

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [PATCH net-next 13/15] dsa: Cleanup unneeded table and make tag structures static
  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
  0 siblings, 0 replies; 37+ messages in thread
From: Florian Fainelli @ 2019-04-19 15:34 UTC (permalink / raw)
  To: Andrew Lunn, David Miller; +Cc: netdev, Vivien Didelot



On 4/17/2019 7:31 PM, Andrew Lunn wrote:
> Now that tag drivers dynamically register, we don't need the static
> table. Remove it. This also means the tag driver structures can be
> made static.
> 
> Signed-off-by: Andrew Lunn <andrew@lunn.ch>

Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
-- 
Florian

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [PATCH net-next 14/15] dsa: Allow tag drivers to be built as modules
  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
  0 siblings, 0 replies; 37+ messages in thread
From: Florian Fainelli @ 2019-04-19 15:38 UTC (permalink / raw)
  To: Andrew Lunn, David Miller; +Cc: netdev, Vivien Didelot



On 4/17/2019 7:31 PM, Andrew Lunn wrote:
> Make the CONFIG symbols tristate and add help text.
> 
> The broadcom and Microchip KSZ tag drivers support two different
> tagging protocols in one driver. Add a configuration option for the
> drivers, and then options to select the protocol.
> 
> Create a submenu for the tagging drivers.
> 
> Signed-off-by: Andrew Lunn <andrew@lunn.ch>
> ---

[snip]

>  
> -# tagging formats
> +config NET_DSA_TAG_BRCM_COMMON
> +       tristate "Tag driver for Broadcom switch"
> +	help
> +          Say Y or M if you want to enable support for tagging frames
> +	  for the Broadcom switches.

The indentation between the tristate and help lines seems to be off a
little bit with spaces vs. tabs. This particular Kconfig symbol should
probably be hidden and selected by NET_DSA_TAG_BRCM and
NET_DSA_TAG_BRCM_PREPEND.

> +
>  config NET_DSA_TAG_BRCM
> -	bool
> +	bool "Tag driver for Broadcom switch using in frame headers"

Plural: switches

> +	depends on NET_DSA_TAG_BRCM_COMMON
> +	help
> +	  Say Y if you want to enable support for tagging frames for the
> +	  Broadcom switches which place the tag after the MAC addresses.

After the MAC source address.

> +
>  
>  config NET_DSA_TAG_BRCM_PREPEND
> -	bool
> +	bool "Tag driver for Broadcom switches using prepended headers"
> +	depends on NET_DSA_TAG_BRCM_COMMON
> +	help
> +	  Say Y if you want to enable support for tagging frames for the
> +	  Broadcom switches which preprended headers.

Which places the tag before the Ethernet header (prepended).
-- 
Florian

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [PATCH net-next 15/15] dsa: tag_brcm: Avoid unused symbols
  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
  0 siblings, 0 replies; 37+ messages in thread
From: Florian Fainelli @ 2019-04-19 15:39 UTC (permalink / raw)
  To: Andrew Lunn, David Miller; +Cc: netdev, Vivien Didelot



On 4/17/2019 7:31 PM, Andrew Lunn wrote:
> It is possible that the driver is compiled with both
> CONFIG_NET_DSA_TAG_BRCM and CONFIG_NET_DSA_TAG_BRCM_PREPEND disabled.
> This results in warnings about unused symbols. Add some conditional
> compilation to avoid this.
> 
> Signed-off-by: Andrew Lunn <andrew@lunn.ch>

Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>

Would not you want to re-order this patch such that it comes before
patch 14 and there is not possibility of generating unused symbols warnings?
-- 
Florian

^ permalink raw reply	[flat|nested] 37+ messages in thread

end of thread, other threads:[~2019-04-19 19:23 UTC | newest]

Thread overview: 37+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH net-next 02/15] dsa: Move tagger name into its ops structure Andrew Lunn
2019-04-18 17:37   ` 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

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).