diff options
author | Florian Fainelli <f.fainelli@gmail.com> | 2017-01-08 17:52:07 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2017-01-09 15:44:50 -0500 |
commit | ab3d408d3f40f939d46a32b1c24aa2833a13b846 (patch) | |
tree | d63140993898647a7db28c2b635606dc1e7d8bfd | |
parent | 73095cb1881e6da77e2ed711deaf954bdfdde71e (diff) |
net: dsa: Encapsulate legacy switch drivers into dsa_switch_driver
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>
-rw-r--r-- | drivers/net/dsa/mv88e6060.c | 8 | ||||
-rw-r--r-- | drivers/net/dsa/mv88e6xxx/chip.c | 8 | ||||
-rw-r--r-- | include/net/dsa.h | 11 | ||||
-rw-r--r-- | net/dsa/dsa.c | 12 |
4 files changed, 26 insertions, 13 deletions
diff --git a/drivers/net/dsa/mv88e6060.c b/drivers/net/dsa/mv88e6060.c index 7ce36dbd9b62..bcbd6dcbd8e8 100644 --- a/drivers/net/dsa/mv88e6060.c +++ b/drivers/net/dsa/mv88e6060.c | |||
@@ -261,16 +261,20 @@ static struct dsa_switch_ops mv88e6060_switch_ops = { | |||
261 | .phy_write = mv88e6060_phy_write, | 261 | .phy_write = mv88e6060_phy_write, |
262 | }; | 262 | }; |
263 | 263 | ||
264 | static struct dsa_switch_driver mv88e6060_switch_drv = { | ||
265 | .ops = &mv88e6060_switch_ops, | ||
266 | }; | ||
267 | |||
264 | static int __init mv88e6060_init(void) | 268 | static int __init mv88e6060_init(void) |
265 | { | 269 | { |
266 | register_switch_driver(&mv88e6060_switch_ops); | 270 | register_switch_driver(&mv88e6060_switch_drv); |
267 | return 0; | 271 | return 0; |
268 | } | 272 | } |
269 | module_init(mv88e6060_init); | 273 | module_init(mv88e6060_init); |
270 | 274 | ||
271 | static void __exit mv88e6060_cleanup(void) | 275 | static void __exit mv88e6060_cleanup(void) |
272 | { | 276 | { |
273 | unregister_switch_driver(&mv88e6060_switch_ops); | 277 | unregister_switch_driver(&mv88e6060_switch_drv); |
274 | } | 278 | } |
275 | module_exit(mv88e6060_cleanup); | 279 | module_exit(mv88e6060_cleanup); |
276 | 280 | ||
diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/chip.c index 676b0e2ad221..d43d12c281b3 100644 --- a/drivers/net/dsa/mv88e6xxx/chip.c +++ b/drivers/net/dsa/mv88e6xxx/chip.c | |||
@@ -4403,6 +4403,10 @@ static struct dsa_switch_ops mv88e6xxx_switch_ops = { | |||
4403 | .port_mdb_dump = mv88e6xxx_port_mdb_dump, | 4403 | .port_mdb_dump = mv88e6xxx_port_mdb_dump, |
4404 | }; | 4404 | }; |
4405 | 4405 | ||
4406 | static struct dsa_switch_driver mv88e6xxx_switch_drv = { | ||
4407 | .ops = &mv88e6xxx_switch_ops, | ||
4408 | }; | ||
4409 | |||
4406 | static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip, | 4410 | static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip, |
4407 | struct device_node *np) | 4411 | struct device_node *np) |
4408 | { | 4412 | { |
@@ -4565,7 +4569,7 @@ static struct mdio_driver mv88e6xxx_driver = { | |||
4565 | 4569 | ||
4566 | static int __init mv88e6xxx_init(void) | 4570 | static int __init mv88e6xxx_init(void) |
4567 | { | 4571 | { |
4568 | register_switch_driver(&mv88e6xxx_switch_ops); | 4572 | register_switch_driver(&mv88e6xxx_switch_drv); |
4569 | return mdio_driver_register(&mv88e6xxx_driver); | 4573 | return mdio_driver_register(&mv88e6xxx_driver); |
4570 | } | 4574 | } |
4571 | module_init(mv88e6xxx_init); | 4575 | module_init(mv88e6xxx_init); |
@@ -4573,7 +4577,7 @@ module_init(mv88e6xxx_init); | |||
4573 | static void __exit mv88e6xxx_cleanup(void) | 4577 | static void __exit mv88e6xxx_cleanup(void) |
4574 | { | 4578 | { |
4575 | mdio_driver_unregister(&mv88e6xxx_driver); | 4579 | mdio_driver_unregister(&mv88e6xxx_driver); |
4576 | unregister_switch_driver(&mv88e6xxx_switch_ops); | 4580 | unregister_switch_driver(&mv88e6xxx_switch_drv); |
4577 | } | 4581 | } |
4578 | module_exit(mv88e6xxx_cleanup); | 4582 | module_exit(mv88e6xxx_cleanup); |
4579 | 4583 | ||
diff --git a/include/net/dsa.h b/include/net/dsa.h index b122196d5a1f..edfa9b130953 100644 --- a/include/net/dsa.h +++ b/include/net/dsa.h | |||
@@ -240,8 +240,6 @@ struct switchdev_obj_port_mdb; | |||
240 | struct switchdev_obj_port_vlan; | 240 | struct switchdev_obj_port_vlan; |
241 | 241 | ||
242 | struct dsa_switch_ops { | 242 | struct dsa_switch_ops { |
243 | struct list_head list; | ||
244 | |||
245 | /* | 243 | /* |
246 | * Probing and setup. | 244 | * Probing and setup. |
247 | */ | 245 | */ |
@@ -390,8 +388,13 @@ struct dsa_switch_ops { | |||
390 | int (*cb)(struct switchdev_obj *obj)); | 388 | int (*cb)(struct switchdev_obj *obj)); |
391 | }; | 389 | }; |
392 | 390 | ||
393 | void register_switch_driver(struct dsa_switch_ops *type); | 391 | struct dsa_switch_driver { |
394 | void unregister_switch_driver(struct dsa_switch_ops *type); | 392 | struct list_head list; |
393 | struct dsa_switch_ops *ops; | ||
394 | }; | ||
395 | |||
396 | void register_switch_driver(struct dsa_switch_driver *type); | ||
397 | void unregister_switch_driver(struct dsa_switch_driver *type); | ||
395 | struct mii_bus *dsa_host_dev_to_mii_bus(struct device *dev); | 398 | struct mii_bus *dsa_host_dev_to_mii_bus(struct device *dev); |
396 | 399 | ||
397 | static inline bool dsa_uses_tagged_protocol(struct dsa_switch_tree *dst) | 400 | static inline bool dsa_uses_tagged_protocol(struct dsa_switch_tree *dst) |
diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c index cda787ebad15..4e7bc57cdae5 100644 --- a/net/dsa/dsa.c +++ b/net/dsa/dsa.c | |||
@@ -60,18 +60,18 @@ const struct dsa_device_ops *dsa_device_ops[DSA_TAG_LAST] = { | |||
60 | static DEFINE_MUTEX(dsa_switch_drivers_mutex); | 60 | static DEFINE_MUTEX(dsa_switch_drivers_mutex); |
61 | static LIST_HEAD(dsa_switch_drivers); | 61 | static LIST_HEAD(dsa_switch_drivers); |
62 | 62 | ||
63 | void register_switch_driver(struct dsa_switch_ops *ops) | 63 | void register_switch_driver(struct dsa_switch_driver *drv) |
64 | { | 64 | { |
65 | mutex_lock(&dsa_switch_drivers_mutex); | 65 | mutex_lock(&dsa_switch_drivers_mutex); |
66 | list_add_tail(&ops->list, &dsa_switch_drivers); | 66 | list_add_tail(&drv->list, &dsa_switch_drivers); |
67 | mutex_unlock(&dsa_switch_drivers_mutex); | 67 | mutex_unlock(&dsa_switch_drivers_mutex); |
68 | } | 68 | } |
69 | EXPORT_SYMBOL_GPL(register_switch_driver); | 69 | EXPORT_SYMBOL_GPL(register_switch_driver); |
70 | 70 | ||
71 | void unregister_switch_driver(struct dsa_switch_ops *ops) | 71 | void unregister_switch_driver(struct dsa_switch_driver *drv) |
72 | { | 72 | { |
73 | mutex_lock(&dsa_switch_drivers_mutex); | 73 | mutex_lock(&dsa_switch_drivers_mutex); |
74 | list_del_init(&ops->list); | 74 | list_del_init(&drv->list); |
75 | mutex_unlock(&dsa_switch_drivers_mutex); | 75 | mutex_unlock(&dsa_switch_drivers_mutex); |
76 | } | 76 | } |
77 | EXPORT_SYMBOL_GPL(unregister_switch_driver); | 77 | EXPORT_SYMBOL_GPL(unregister_switch_driver); |
@@ -90,8 +90,10 @@ dsa_switch_probe(struct device *parent, struct device *host_dev, int sw_addr, | |||
90 | mutex_lock(&dsa_switch_drivers_mutex); | 90 | mutex_lock(&dsa_switch_drivers_mutex); |
91 | list_for_each(list, &dsa_switch_drivers) { | 91 | list_for_each(list, &dsa_switch_drivers) { |
92 | struct dsa_switch_ops *ops; | 92 | struct dsa_switch_ops *ops; |
93 | struct dsa_switch_driver *drv; | ||
93 | 94 | ||
94 | ops = list_entry(list, struct dsa_switch_ops, list); | 95 | drv = list_entry(list, struct dsa_switch_driver, list); |
96 | ops = drv->ops; | ||
95 | 97 | ||
96 | name = ops->probe(parent, host_dev, sw_addr, priv); | 98 | name = ops->probe(parent, host_dev, sw_addr, priv); |
97 | if (name != NULL) { | 99 | if (name != NULL) { |