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

Signed-off-by: Andrew Lunn <and...@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

Reply via email to