dsa: Add boilerplate helper to register DSA tag driver modules
authorAndrew Lunn <andrew@lunn.ch>
Sun, 28 Apr 2019 17:37:15 +0000 (19:37 +0200)
committerDavid S. Miller <davem@davemloft.net>
Sun, 28 Apr 2019 23:41:01 +0000 (19:41 -0400)
A DSA tag driver module will need to register the tag protocols it
implements with the DSA core. Add macros 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>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
v2
Fix indent of #endif
Rewrite to move list pointer into a new structure
v3
Move kdoc next to macro
Fix THIS_MODULE indentation

Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/dsa.h
net/dsa/dsa.c
net/dsa/tag_brcm.c
net/dsa/tag_dsa.c
net/dsa/tag_edsa.c
net/dsa/tag_gswip.c
net/dsa/tag_ksz.c
net/dsa/tag_lan9303.c
net/dsa/tag_mtk.c
net/dsa/tag_qca.c
net/dsa/tag_trailer.c

index 720036f48fb333a3f67c7b1668ec4ab093cbbc58..08ac05c014e3d44d4c38b8dbe628d5ea900b34fc 100644 (file)
@@ -594,4 +594,70 @@ 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);
 
+struct dsa_tag_driver {
+       const struct dsa_device_ops *ops;
+       struct list_head list;
+       struct module *owner;
+};
+
+void dsa_tag_drivers_register(struct dsa_tag_driver *dsa_tag_driver_array[],
+                             unsigned int count,
+                             struct module *owner);
+void dsa_tag_drivers_unregister(struct dsa_tag_driver *dsa_tag_driver_array[],
+                               unsigned int count);
+
+#define dsa_tag_driver_module_drivers(__dsa_tag_drivers_array, __count)        \
+static int __init dsa_tag_driver_module_init(void)                     \
+{                                                                      \
+       dsa_tag_drivers_register(__dsa_tag_drivers_array, __count,      \
+                                THIS_MODULE);                          \
+       return 0;                                                       \
+}                                                                      \
+module_init(dsa_tag_driver_module_init);                               \
+                                                                       \
+static void __exit dsa_tag_driver_module_exit(void)                    \
+{                                                                      \
+       dsa_tag_drivers_unregister(__dsa_tag_drivers_array, __count);   \
+}                                                                      \
+module_exit(dsa_tag_driver_module_exit)
+
+/**
+ * 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 module_dsa_tag_drivers(__ops_array)                            \
+dsa_tag_driver_module_drivers(__ops_array, ARRAY_SIZE(__ops_array))
+
+#define DSA_TAG_DRIVER_NAME(__ops) dsa_tag_driver ## _ ## __ops
+
+/* Create a static structure we can build a linked list of dsa_tag
+ * drivers
+ */
+#define DSA_TAG_DRIVER(__ops)                                          \
+static struct dsa_tag_driver DSA_TAG_DRIVER_NAME(__ops) = {            \
+       .ops = &__ops,                                                  \
+}
+
+/**
+ * module_dsa_tag_driver() - Helper macro for registering a single DSA tag
+ * driver
+ * @__ops: Single tag driver structures
+ *
+ * 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)                                   \
+DSA_TAG_DRIVER(__ops);                                                 \
+                                                                       \
+static struct dsa_tag_driver *dsa_tag_driver_array[] = {               \
+       &DSA_TAG_DRIVER_NAME(__ops)                                     \
+};                                                                     \
+module_dsa_tag_drivers(dsa_tag_driver_array)
 #endif
+
index 2da733dff86bc82369c690f8859d1047eadc8760..34becafbd37b17effaa468daef3734496b4ed903 100644 (file)
@@ -76,6 +76,18 @@ const struct dsa_device_ops *dsa_device_ops[DSA_TAG_LAST] = {
        [DSA_TAG_PROTO_NONE] = &none_ops,
 };
 
+void dsa_tag_drivers_register(struct dsa_tag_driver *dsa_tag_driver_array[],
+                             unsigned int count, struct module *owner)
+{
+}
+EXPORT_SYMBOL_GPL(dsa_tag_drivers_register);
+
+void dsa_tag_drivers_unregister(struct dsa_tag_driver *dsa_tag_driver_array[],
+                               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;
index 39b380485e5a24259effe3e1643d76cd856a95a2..63c8c6645a05e8ace29e35218c708ff995fb3211 100644 (file)
@@ -175,6 +175,7 @@ const struct dsa_device_ops brcm_netdev_ops = {
        .overhead = BRCM_TAG_LEN,
 };
 
+DSA_TAG_DRIVER(brcm_netdev_ops);
 MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_BRCM);
 #endif
 
@@ -203,5 +204,18 @@ const struct dsa_device_ops brcm_prepend_netdev_ops = {
 };
 #endif
 
-MODULE_LICENSE("GPL");
+DSA_TAG_DRIVER(brcm_prepend_netdev_ops);
 MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_BRCM_PREPEND);
+
+static struct dsa_tag_driver *dsa_tag_driver_array[] = {
+#if IS_ENABLED(CONFIG_NET_DSA_TAG_BRCM)
+       &DSA_TAG_DRIVER_NAME(brcm_netdev_ops),
+#endif
+#if IS_ENABLED(CONFIG_NET_DSA_TAG_BRCM_PREPEND)
+       &DSA_TAG_DRIVER_NAME(brcm_prepend_netdev_ops),
+#endif
+};
+
+module_dsa_tag_drivers(dsa_tag_driver_array);
+
+MODULE_LICENSE("GPL");
index ec9b66c11219c1c91bd9f9e09e7d445642d0fea6..96b5147b6f3ea637cb96efa99727b00c2122a1d1 100644 (file)
@@ -161,3 +161,5 @@ const 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);
index 866d4e684511b4b71d7c1d9d870cec53eb006e75..76bf3db4e9d43ea4fb5232c364cd0341d6a9e104 100644 (file)
@@ -180,3 +180,5 @@ const 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);
index 1921563731088b1cfd68929fe1aa70232159d70e..ee5167180e79f6cd64e5a60d330f3bc34462c1cf 100644 (file)
@@ -113,3 +113,5 @@ const 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);
index 5f5c8f9a6141fa54670d013b0a9f3ed7b8f8c192..02689ac6f9da881d5b4366ace13ae1a42c84b898 100644 (file)
@@ -141,6 +141,7 @@ const struct dsa_device_ops ksz9477_netdev_ops = {
        .overhead = KSZ9477_INGRESS_TAG_LEN,
 };
 
+DSA_TAG_DRIVER(ksz9477_netdev_ops);
 MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_KSZ9477);
 
 #define KSZ9893_TAIL_TAG_OVERRIDE      BIT(5)
@@ -178,5 +179,14 @@ const struct dsa_device_ops ksz9893_netdev_ops = {
        .overhead = KSZ_INGRESS_TAG_LEN,
 };
 
-MODULE_LICENSE("GPL");
+DSA_TAG_DRIVER(ksz9893_netdev_ops);
 MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_KSZ9893);
+
+static struct dsa_tag_driver *dsa_tag_driver_array[] = {
+       &DSA_TAG_DRIVER_NAME(ksz9477_netdev_ops),
+       &DSA_TAG_DRIVER_NAME(ksz9893_netdev_ops),
+};
+
+module_dsa_tag_drivers(dsa_tag_driver_array);
+
+MODULE_LICENSE("GPL");
index b6ef1e1a66731b724e10968cc5fdcc82ded1caf8..609a2405abd86f30a13e84923d95b147740fafc7 100644 (file)
@@ -138,3 +138,5 @@ const 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);
index ca02ab3dcd8009e926e3532b0faa98f33fb85e65..a4d2dcdb71025e4918dde56889475bbf1cd7fd66 100644 (file)
@@ -109,3 +109,5 @@ const 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);
index 1ff65c2e0cb4a2846bb26c7772ff8ff026369ce2..552ddfbbf5ec33de8aaa536b21c52e2b3875a98f 100644 (file)
@@ -110,3 +110,5 @@ const 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);
index 628ab1a44ed7d5bbaa77de8a6fbaf636841121d8..807cc2dff052325bb260ba983edcfa8bd841a2b9 100644 (file)
@@ -87,3 +87,5 @@ const 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);