net: dsa: Encapsulate legacy switch drivers into dsa_switch_driver
authorFlorian Fainelli <f.fainelli@gmail.com>
Sun, 8 Jan 2017 22:52:07 +0000 (14:52 -0800)
committerDavid S. Miller <davem@davemloft.net>
Mon, 9 Jan 2017 20:44:50 +0000 (15:44 -0500)
In preparation for making struct dsa_switch_ops const, encapsulate it
within a dsa_switch_driver which has a list pointer and a pointer to
dsa_switch_ops. This allows us to take the list_head pointer out of
dsa_switch_ops, which is written to by {un,}register_switch_driver.

Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/dsa/mv88e6060.c
drivers/net/dsa/mv88e6xxx/chip.c
include/net/dsa.h
net/dsa/dsa.c

index 7ce36db..bcbd6dc 100644 (file)
@@ -261,16 +261,20 @@ static struct dsa_switch_ops mv88e6060_switch_ops = {
        .phy_write      = mv88e6060_phy_write,
 };
 
+static struct dsa_switch_driver mv88e6060_switch_drv = {
+       .ops            = &mv88e6060_switch_ops,
+};
+
 static int __init mv88e6060_init(void)
 {
-       register_switch_driver(&mv88e6060_switch_ops);
+       register_switch_driver(&mv88e6060_switch_drv);
        return 0;
 }
 module_init(mv88e6060_init);
 
 static void __exit mv88e6060_cleanup(void)
 {
-       unregister_switch_driver(&mv88e6060_switch_ops);
+       unregister_switch_driver(&mv88e6060_switch_drv);
 }
 module_exit(mv88e6060_cleanup);
 
index 676b0e2..d43d12c 100644 (file)
@@ -4403,6 +4403,10 @@ static struct dsa_switch_ops mv88e6xxx_switch_ops = {
        .port_mdb_dump          = mv88e6xxx_port_mdb_dump,
 };
 
+static struct dsa_switch_driver mv88e6xxx_switch_drv = {
+       .ops                    = &mv88e6xxx_switch_ops,
+};
+
 static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip,
                                     struct device_node *np)
 {
@@ -4565,7 +4569,7 @@ static struct mdio_driver mv88e6xxx_driver = {
 
 static int __init mv88e6xxx_init(void)
 {
-       register_switch_driver(&mv88e6xxx_switch_ops);
+       register_switch_driver(&mv88e6xxx_switch_drv);
        return mdio_driver_register(&mv88e6xxx_driver);
 }
 module_init(mv88e6xxx_init);
@@ -4573,7 +4577,7 @@ module_init(mv88e6xxx_init);
 static void __exit mv88e6xxx_cleanup(void)
 {
        mdio_driver_unregister(&mv88e6xxx_driver);
-       unregister_switch_driver(&mv88e6xxx_switch_ops);
+       unregister_switch_driver(&mv88e6xxx_switch_drv);
 }
 module_exit(mv88e6xxx_cleanup);
 
index b122196..edfa9b1 100644 (file)
@@ -240,8 +240,6 @@ struct switchdev_obj_port_mdb;
 struct switchdev_obj_port_vlan;
 
 struct dsa_switch_ops {
-       struct list_head        list;
-
        /*
         * Probing and setup.
         */
@@ -390,8 +388,13 @@ struct dsa_switch_ops {
                                 int (*cb)(struct switchdev_obj *obj));
 };
 
-void register_switch_driver(struct dsa_switch_ops *type);
-void unregister_switch_driver(struct dsa_switch_ops *type);
+struct dsa_switch_driver {
+       struct list_head        list;
+       struct dsa_switch_ops   *ops;
+};
+
+void register_switch_driver(struct dsa_switch_driver *type);
+void unregister_switch_driver(struct dsa_switch_driver *type);
 struct mii_bus *dsa_host_dev_to_mii_bus(struct device *dev);
 
 static inline bool dsa_uses_tagged_protocol(struct dsa_switch_tree *dst)
index cda787e..4e7bc57 100644 (file)
@@ -60,18 +60,18 @@ const struct dsa_device_ops *dsa_device_ops[DSA_TAG_LAST] = {
 static DEFINE_MUTEX(dsa_switch_drivers_mutex);
 static LIST_HEAD(dsa_switch_drivers);
 
-void register_switch_driver(struct dsa_switch_ops *ops)
+void register_switch_driver(struct dsa_switch_driver *drv)
 {
        mutex_lock(&dsa_switch_drivers_mutex);
-       list_add_tail(&ops->list, &dsa_switch_drivers);
+       list_add_tail(&drv->list, &dsa_switch_drivers);
        mutex_unlock(&dsa_switch_drivers_mutex);
 }
 EXPORT_SYMBOL_GPL(register_switch_driver);
 
-void unregister_switch_driver(struct dsa_switch_ops *ops)
+void unregister_switch_driver(struct dsa_switch_driver *drv)
 {
        mutex_lock(&dsa_switch_drivers_mutex);
-       list_del_init(&ops->list);
+       list_del_init(&drv->list);
        mutex_unlock(&dsa_switch_drivers_mutex);
 }
 EXPORT_SYMBOL_GPL(unregister_switch_driver);
@@ -90,8 +90,10 @@ dsa_switch_probe(struct device *parent, struct device *host_dev, int sw_addr,
        mutex_lock(&dsa_switch_drivers_mutex);
        list_for_each(list, &dsa_switch_drivers) {
                struct dsa_switch_ops *ops;
+               struct dsa_switch_driver *drv;
 
-               ops = list_entry(list, struct dsa_switch_ops, list);
+               drv = list_entry(list, struct dsa_switch_driver, list);
+               ops = drv->ops;
 
                name = ops->probe(parent, host_dev, sw_addr, priv);
                if (name != NULL) {