netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Lunn <andrew@lunn.ch>
To: David Miller <davem@davemloft.net>
Cc: netdev <netdev@vger.kernel.org>,
	Florian Fainelli <f.fainelli@gmail.com>,
	Vivien Didelot <vivien.didelot@gmail.com>,
	Andrew Lunn <andrew@lunn.ch>
Subject: [PATCH net-next 07/15] dsa: Add boilerplate helper to register DSA tag driver modules
Date: Thu, 18 Apr 2019 04:31:12 +0200	[thread overview]
Message-ID: <20190418023120.17067-8-andrew@lunn.ch> (raw)
In-Reply-To: <20190418023120.17067-1-andrew@lunn.ch>

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


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

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-18  2:31 [PATCH net-next 00/15] Make DSA tag drivers kernel modules Andrew Lunn
2019-04-18  2:31 ` [PATCH net-next 01/15] dsa: Add SPDX header to tag drivers Andrew Lunn
2019-04-18 17:35   ` Florian Fainelli
2019-04-18  2:31 ` [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 ` Andrew Lunn [this message]
2019-04-19 15:29   ` [PATCH net-next 07/15] dsa: Add boilerplate helper to register DSA tag driver modules Florian Fainelli
2019-04-18  2:31 ` [PATCH net-next 08/15] dsa: Keep link list of tag drivers Andrew Lunn
2019-04-18  7:25   ` David Miller
2019-04-18  9:35   ` Sergei Shtylyov
2019-04-18 13:19     ` Andrew Lunn
2019-04-18 14:40       ` Sergei Shtylyov
2019-04-19 15:30   ` Florian Fainelli
2019-04-18  2:31 ` [PATCH net-next 09/15] dsa: Register the none tagger ops Andrew Lunn
2019-04-19 15:31   ` Florian Fainelli
2019-04-18  2:31 ` [PATCH net-next 10/15] dsa: Rename dsa_resolve_tag_protocol() to _get ready for locking Andrew Lunn
2019-04-19 15:31   ` Florian Fainelli
2019-04-18  2:31 ` [PATCH net-next 11/15] dsa: Add stub tag driver put method Andrew Lunn
2019-04-19 15:32   ` Florian Fainelli
2019-04-18  2:31 ` [PATCH net-next 12/15] dsa: Make use of the list of tag drivers Andrew Lunn
2019-04-19 15:33   ` Florian Fainelli
2019-04-18  2:31 ` [PATCH net-next 13/15] dsa: Cleanup unneeded table and make tag structures static Andrew Lunn
2019-04-19 15:34   ` Florian Fainelli
2019-04-18  2:31 ` [PATCH net-next 14/15] dsa: Allow tag drivers to be built as modules Andrew Lunn
2019-04-19 15:38   ` Florian Fainelli
2019-04-18  2:31 ` [PATCH net-next 15/15] dsa: tag_brcm: Avoid unused symbols Andrew Lunn
2019-04-19 15:39   ` Florian Fainelli

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190418023120.17067-8-andrew@lunn.ch \
    --to=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=f.fainelli@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=vivien.didelot@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is 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).