Linux 5.7.7
[linux/fpc-iii.git] / net / dsa / dsa2.c
blobd90665b465b8ab6ceb2f85750af9eef9dc87cac5
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * net/dsa/dsa2.c - Hardware switch handling, binding version 2
4 * Copyright (c) 2008-2009 Marvell Semiconductor
5 * Copyright (c) 2013 Florian Fainelli <florian@openwrt.org>
6 * Copyright (c) 2016 Andrew Lunn <andrew@lunn.ch>
7 */
9 #include <linux/device.h>
10 #include <linux/err.h>
11 #include <linux/list.h>
12 #include <linux/netdevice.h>
13 #include <linux/slab.h>
14 #include <linux/rtnetlink.h>
15 #include <linux/of.h>
16 #include <linux/of_net.h>
17 #include <net/devlink.h>
19 #include "dsa_priv.h"
21 static DEFINE_MUTEX(dsa2_mutex);
22 LIST_HEAD(dsa_tree_list);
24 static const struct devlink_ops dsa_devlink_ops = {
27 static struct dsa_switch_tree *dsa_tree_find(int index)
29 struct dsa_switch_tree *dst;
31 list_for_each_entry(dst, &dsa_tree_list, list)
32 if (dst->index == index)
33 return dst;
35 return NULL;
38 static struct dsa_switch_tree *dsa_tree_alloc(int index)
40 struct dsa_switch_tree *dst;
42 dst = kzalloc(sizeof(*dst), GFP_KERNEL);
43 if (!dst)
44 return NULL;
46 dst->index = index;
48 INIT_LIST_HEAD(&dst->rtable);
50 INIT_LIST_HEAD(&dst->ports);
52 INIT_LIST_HEAD(&dst->list);
53 list_add_tail(&dst->list, &dsa_tree_list);
55 kref_init(&dst->refcount);
57 return dst;
60 static void dsa_tree_free(struct dsa_switch_tree *dst)
62 list_del(&dst->list);
63 kfree(dst);
66 static struct dsa_switch_tree *dsa_tree_get(struct dsa_switch_tree *dst)
68 if (dst)
69 kref_get(&dst->refcount);
71 return dst;
74 static struct dsa_switch_tree *dsa_tree_touch(int index)
76 struct dsa_switch_tree *dst;
78 dst = dsa_tree_find(index);
79 if (dst)
80 return dsa_tree_get(dst);
81 else
82 return dsa_tree_alloc(index);
85 static void dsa_tree_release(struct kref *ref)
87 struct dsa_switch_tree *dst;
89 dst = container_of(ref, struct dsa_switch_tree, refcount);
91 dsa_tree_free(dst);
94 static void dsa_tree_put(struct dsa_switch_tree *dst)
96 if (dst)
97 kref_put(&dst->refcount, dsa_tree_release);
100 static bool dsa_port_is_dsa(struct dsa_port *port)
102 return port->type == DSA_PORT_TYPE_DSA;
105 static bool dsa_port_is_cpu(struct dsa_port *port)
107 return port->type == DSA_PORT_TYPE_CPU;
110 static bool dsa_port_is_user(struct dsa_port *dp)
112 return dp->type == DSA_PORT_TYPE_USER;
115 static struct dsa_port *dsa_tree_find_port_by_node(struct dsa_switch_tree *dst,
116 struct device_node *dn)
118 struct dsa_port *dp;
120 list_for_each_entry(dp, &dst->ports, list)
121 if (dp->dn == dn)
122 return dp;
124 return NULL;
127 static struct dsa_link *dsa_link_touch(struct dsa_port *dp,
128 struct dsa_port *link_dp)
130 struct dsa_switch *ds = dp->ds;
131 struct dsa_switch_tree *dst;
132 struct dsa_link *dl;
134 dst = ds->dst;
136 list_for_each_entry(dl, &dst->rtable, list)
137 if (dl->dp == dp && dl->link_dp == link_dp)
138 return dl;
140 dl = kzalloc(sizeof(*dl), GFP_KERNEL);
141 if (!dl)
142 return NULL;
144 dl->dp = dp;
145 dl->link_dp = link_dp;
147 INIT_LIST_HEAD(&dl->list);
148 list_add_tail(&dl->list, &dst->rtable);
150 return dl;
153 static bool dsa_port_setup_routing_table(struct dsa_port *dp)
155 struct dsa_switch *ds = dp->ds;
156 struct dsa_switch_tree *dst = ds->dst;
157 struct device_node *dn = dp->dn;
158 struct of_phandle_iterator it;
159 struct dsa_port *link_dp;
160 struct dsa_link *dl;
161 int err;
163 of_for_each_phandle(&it, err, dn, "link", NULL, 0) {
164 link_dp = dsa_tree_find_port_by_node(dst, it.node);
165 if (!link_dp) {
166 of_node_put(it.node);
167 return false;
170 dl = dsa_link_touch(dp, link_dp);
171 if (!dl) {
172 of_node_put(it.node);
173 return false;
177 return true;
180 static bool dsa_tree_setup_routing_table(struct dsa_switch_tree *dst)
182 bool complete = true;
183 struct dsa_port *dp;
185 list_for_each_entry(dp, &dst->ports, list) {
186 if (dsa_port_is_dsa(dp)) {
187 complete = dsa_port_setup_routing_table(dp);
188 if (!complete)
189 break;
193 return complete;
196 static struct dsa_port *dsa_tree_find_first_cpu(struct dsa_switch_tree *dst)
198 struct dsa_port *dp;
200 list_for_each_entry(dp, &dst->ports, list)
201 if (dsa_port_is_cpu(dp))
202 return dp;
204 return NULL;
207 static int dsa_tree_setup_default_cpu(struct dsa_switch_tree *dst)
209 struct dsa_port *cpu_dp, *dp;
211 cpu_dp = dsa_tree_find_first_cpu(dst);
212 if (!cpu_dp) {
213 pr_err("DSA: tree %d has no CPU port\n", dst->index);
214 return -EINVAL;
217 /* Assign the default CPU port to all ports of the fabric */
218 list_for_each_entry(dp, &dst->ports, list)
219 if (dsa_port_is_user(dp) || dsa_port_is_dsa(dp))
220 dp->cpu_dp = cpu_dp;
222 return 0;
225 static void dsa_tree_teardown_default_cpu(struct dsa_switch_tree *dst)
227 struct dsa_port *dp;
229 list_for_each_entry(dp, &dst->ports, list)
230 if (dsa_port_is_user(dp) || dsa_port_is_dsa(dp))
231 dp->cpu_dp = NULL;
234 static int dsa_port_setup(struct dsa_port *dp)
236 struct dsa_switch *ds = dp->ds;
237 struct dsa_switch_tree *dst = ds->dst;
238 const unsigned char *id = (const unsigned char *)&dst->index;
239 const unsigned char len = sizeof(dst->index);
240 struct devlink_port *dlp = &dp->devlink_port;
241 bool dsa_port_link_registered = false;
242 bool devlink_port_registered = false;
243 struct devlink *dl = ds->devlink;
244 bool dsa_port_enabled = false;
245 int err = 0;
247 if (dp->setup)
248 return 0;
250 switch (dp->type) {
251 case DSA_PORT_TYPE_UNUSED:
252 dsa_port_disable(dp);
253 break;
254 case DSA_PORT_TYPE_CPU:
255 memset(dlp, 0, sizeof(*dlp));
256 devlink_port_attrs_set(dlp, DEVLINK_PORT_FLAVOUR_CPU,
257 dp->index, false, 0, id, len);
258 err = devlink_port_register(dl, dlp, dp->index);
259 if (err)
260 break;
261 devlink_port_registered = true;
263 err = dsa_port_link_register_of(dp);
264 if (err)
265 break;
266 dsa_port_link_registered = true;
268 err = dsa_port_enable(dp, NULL);
269 if (err)
270 break;
271 dsa_port_enabled = true;
273 break;
274 case DSA_PORT_TYPE_DSA:
275 memset(dlp, 0, sizeof(*dlp));
276 devlink_port_attrs_set(dlp, DEVLINK_PORT_FLAVOUR_DSA,
277 dp->index, false, 0, id, len);
278 err = devlink_port_register(dl, dlp, dp->index);
279 if (err)
280 break;
281 devlink_port_registered = true;
283 err = dsa_port_link_register_of(dp);
284 if (err)
285 break;
286 dsa_port_link_registered = true;
288 err = dsa_port_enable(dp, NULL);
289 if (err)
290 break;
291 dsa_port_enabled = true;
293 break;
294 case DSA_PORT_TYPE_USER:
295 memset(dlp, 0, sizeof(*dlp));
296 devlink_port_attrs_set(dlp, DEVLINK_PORT_FLAVOUR_PHYSICAL,
297 dp->index, false, 0, id, len);
298 err = devlink_port_register(dl, dlp, dp->index);
299 if (err)
300 break;
301 devlink_port_registered = true;
303 dp->mac = of_get_mac_address(dp->dn);
304 err = dsa_slave_create(dp);
305 if (err)
306 break;
308 devlink_port_type_eth_set(dlp, dp->slave);
309 break;
312 if (err && dsa_port_enabled)
313 dsa_port_disable(dp);
314 if (err && dsa_port_link_registered)
315 dsa_port_link_unregister_of(dp);
316 if (err && devlink_port_registered)
317 devlink_port_unregister(dlp);
318 if (err)
319 return err;
321 dp->setup = true;
323 return 0;
326 static void dsa_port_teardown(struct dsa_port *dp)
328 struct devlink_port *dlp = &dp->devlink_port;
330 if (!dp->setup)
331 return;
333 switch (dp->type) {
334 case DSA_PORT_TYPE_UNUSED:
335 break;
336 case DSA_PORT_TYPE_CPU:
337 dsa_port_disable(dp);
338 dsa_tag_driver_put(dp->tag_ops);
339 devlink_port_unregister(dlp);
340 dsa_port_link_unregister_of(dp);
341 break;
342 case DSA_PORT_TYPE_DSA:
343 dsa_port_disable(dp);
344 devlink_port_unregister(dlp);
345 dsa_port_link_unregister_of(dp);
346 break;
347 case DSA_PORT_TYPE_USER:
348 devlink_port_unregister(dlp);
349 if (dp->slave) {
350 dsa_slave_destroy(dp->slave);
351 dp->slave = NULL;
353 break;
356 dp->setup = false;
359 static int dsa_switch_setup(struct dsa_switch *ds)
361 struct dsa_devlink_priv *dl_priv;
362 int err;
364 if (ds->setup)
365 return 0;
367 /* Initialize ds->phys_mii_mask before registering the slave MDIO bus
368 * driver and before ops->setup() has run, since the switch drivers and
369 * the slave MDIO bus driver rely on these values for probing PHY
370 * devices or not
372 ds->phys_mii_mask |= dsa_user_ports(ds);
374 /* Add the switch to devlink before calling setup, so that setup can
375 * add dpipe tables
377 ds->devlink = devlink_alloc(&dsa_devlink_ops, sizeof(*dl_priv));
378 if (!ds->devlink)
379 return -ENOMEM;
380 dl_priv = devlink_priv(ds->devlink);
381 dl_priv->ds = ds;
383 err = devlink_register(ds->devlink, ds->dev);
384 if (err)
385 goto free_devlink;
387 err = dsa_switch_register_notifier(ds);
388 if (err)
389 goto unregister_devlink;
391 err = ds->ops->setup(ds);
392 if (err < 0)
393 goto unregister_notifier;
395 devlink_params_publish(ds->devlink);
397 if (!ds->slave_mii_bus && ds->ops->phy_read) {
398 ds->slave_mii_bus = devm_mdiobus_alloc(ds->dev);
399 if (!ds->slave_mii_bus) {
400 err = -ENOMEM;
401 goto unregister_notifier;
404 dsa_slave_mii_bus_init(ds);
406 err = mdiobus_register(ds->slave_mii_bus);
407 if (err < 0)
408 goto unregister_notifier;
411 ds->setup = true;
413 return 0;
415 unregister_notifier:
416 dsa_switch_unregister_notifier(ds);
417 unregister_devlink:
418 devlink_unregister(ds->devlink);
419 free_devlink:
420 devlink_free(ds->devlink);
421 ds->devlink = NULL;
423 return err;
426 static void dsa_switch_teardown(struct dsa_switch *ds)
428 if (!ds->setup)
429 return;
431 if (ds->slave_mii_bus && ds->ops->phy_read)
432 mdiobus_unregister(ds->slave_mii_bus);
434 dsa_switch_unregister_notifier(ds);
436 if (ds->ops->teardown)
437 ds->ops->teardown(ds);
439 if (ds->devlink) {
440 devlink_unregister(ds->devlink);
441 devlink_free(ds->devlink);
442 ds->devlink = NULL;
445 ds->setup = false;
448 static int dsa_tree_setup_switches(struct dsa_switch_tree *dst)
450 struct dsa_port *dp;
451 int err;
453 list_for_each_entry(dp, &dst->ports, list) {
454 err = dsa_switch_setup(dp->ds);
455 if (err)
456 goto teardown;
459 list_for_each_entry(dp, &dst->ports, list) {
460 err = dsa_port_setup(dp);
461 if (err)
462 continue;
465 return 0;
467 teardown:
468 list_for_each_entry(dp, &dst->ports, list)
469 dsa_port_teardown(dp);
471 list_for_each_entry(dp, &dst->ports, list)
472 dsa_switch_teardown(dp->ds);
474 return err;
477 static void dsa_tree_teardown_switches(struct dsa_switch_tree *dst)
479 struct dsa_port *dp;
481 list_for_each_entry(dp, &dst->ports, list)
482 dsa_port_teardown(dp);
484 list_for_each_entry(dp, &dst->ports, list)
485 dsa_switch_teardown(dp->ds);
488 static int dsa_tree_setup_master(struct dsa_switch_tree *dst)
490 struct dsa_port *dp;
491 int err;
493 list_for_each_entry(dp, &dst->ports, list) {
494 if (dsa_port_is_cpu(dp)) {
495 err = dsa_master_setup(dp->master, dp);
496 if (err)
497 return err;
501 return 0;
504 static void dsa_tree_teardown_master(struct dsa_switch_tree *dst)
506 struct dsa_port *dp;
508 list_for_each_entry(dp, &dst->ports, list)
509 if (dsa_port_is_cpu(dp))
510 dsa_master_teardown(dp->master);
513 static int dsa_tree_setup(struct dsa_switch_tree *dst)
515 bool complete;
516 int err;
518 if (dst->setup) {
519 pr_err("DSA: tree %d already setup! Disjoint trees?\n",
520 dst->index);
521 return -EEXIST;
524 complete = dsa_tree_setup_routing_table(dst);
525 if (!complete)
526 return 0;
528 err = dsa_tree_setup_default_cpu(dst);
529 if (err)
530 return err;
532 err = dsa_tree_setup_switches(dst);
533 if (err)
534 goto teardown_default_cpu;
536 err = dsa_tree_setup_master(dst);
537 if (err)
538 goto teardown_switches;
540 dst->setup = true;
542 pr_info("DSA: tree %d setup\n", dst->index);
544 return 0;
546 teardown_switches:
547 dsa_tree_teardown_switches(dst);
548 teardown_default_cpu:
549 dsa_tree_teardown_default_cpu(dst);
551 return err;
554 static void dsa_tree_teardown(struct dsa_switch_tree *dst)
556 struct dsa_link *dl, *next;
558 if (!dst->setup)
559 return;
561 dsa_tree_teardown_master(dst);
563 dsa_tree_teardown_switches(dst);
565 dsa_tree_teardown_default_cpu(dst);
567 list_for_each_entry_safe(dl, next, &dst->rtable, list) {
568 list_del(&dl->list);
569 kfree(dl);
572 pr_info("DSA: tree %d torn down\n", dst->index);
574 dst->setup = false;
577 static struct dsa_port *dsa_port_touch(struct dsa_switch *ds, int index)
579 struct dsa_switch_tree *dst = ds->dst;
580 struct dsa_port *dp;
582 list_for_each_entry(dp, &dst->ports, list)
583 if (dp->ds == ds && dp->index == index)
584 return dp;
586 dp = kzalloc(sizeof(*dp), GFP_KERNEL);
587 if (!dp)
588 return NULL;
590 dp->ds = ds;
591 dp->index = index;
593 INIT_LIST_HEAD(&dp->list);
594 list_add_tail(&dp->list, &dst->ports);
596 return dp;
599 static int dsa_port_parse_user(struct dsa_port *dp, const char *name)
601 if (!name)
602 name = "eth%d";
604 dp->type = DSA_PORT_TYPE_USER;
605 dp->name = name;
607 return 0;
610 static int dsa_port_parse_dsa(struct dsa_port *dp)
612 dp->type = DSA_PORT_TYPE_DSA;
614 return 0;
617 static enum dsa_tag_protocol dsa_get_tag_protocol(struct dsa_port *dp,
618 struct net_device *master)
620 enum dsa_tag_protocol tag_protocol = DSA_TAG_PROTO_NONE;
621 struct dsa_switch *mds, *ds = dp->ds;
622 unsigned int mdp_upstream;
623 struct dsa_port *mdp;
625 /* It is possible to stack DSA switches onto one another when that
626 * happens the switch driver may want to know if its tagging protocol
627 * is going to work in such a configuration.
629 if (dsa_slave_dev_check(master)) {
630 mdp = dsa_slave_to_port(master);
631 mds = mdp->ds;
632 mdp_upstream = dsa_upstream_port(mds, mdp->index);
633 tag_protocol = mds->ops->get_tag_protocol(mds, mdp_upstream,
634 DSA_TAG_PROTO_NONE);
637 /* If the master device is not itself a DSA slave in a disjoint DSA
638 * tree, then return immediately.
640 return ds->ops->get_tag_protocol(ds, dp->index, tag_protocol);
643 static int dsa_port_parse_cpu(struct dsa_port *dp, struct net_device *master)
645 struct dsa_switch *ds = dp->ds;
646 struct dsa_switch_tree *dst = ds->dst;
647 const struct dsa_device_ops *tag_ops;
648 enum dsa_tag_protocol tag_protocol;
650 tag_protocol = dsa_get_tag_protocol(dp, master);
651 tag_ops = dsa_tag_driver_get(tag_protocol);
652 if (IS_ERR(tag_ops)) {
653 if (PTR_ERR(tag_ops) == -ENOPROTOOPT)
654 return -EPROBE_DEFER;
655 dev_warn(ds->dev, "No tagger for this switch\n");
656 dp->master = NULL;
657 return PTR_ERR(tag_ops);
660 dp->master = master;
661 dp->type = DSA_PORT_TYPE_CPU;
662 dp->filter = tag_ops->filter;
663 dp->rcv = tag_ops->rcv;
664 dp->tag_ops = tag_ops;
665 dp->dst = dst;
667 return 0;
670 static int dsa_port_parse_of(struct dsa_port *dp, struct device_node *dn)
672 struct device_node *ethernet = of_parse_phandle(dn, "ethernet", 0);
673 const char *name = of_get_property(dn, "label", NULL);
674 bool link = of_property_read_bool(dn, "link");
676 dp->dn = dn;
678 if (ethernet) {
679 struct net_device *master;
681 master = of_find_net_device_by_node(ethernet);
682 if (!master)
683 return -EPROBE_DEFER;
685 return dsa_port_parse_cpu(dp, master);
688 if (link)
689 return dsa_port_parse_dsa(dp);
691 return dsa_port_parse_user(dp, name);
694 static int dsa_switch_parse_ports_of(struct dsa_switch *ds,
695 struct device_node *dn)
697 struct device_node *ports, *port;
698 struct dsa_port *dp;
699 int err = 0;
700 u32 reg;
702 ports = of_get_child_by_name(dn, "ports");
703 if (!ports) {
704 dev_err(ds->dev, "no ports child node found\n");
705 return -EINVAL;
708 for_each_available_child_of_node(ports, port) {
709 err = of_property_read_u32(port, "reg", &reg);
710 if (err)
711 goto out_put_node;
713 if (reg >= ds->num_ports) {
714 err = -EINVAL;
715 goto out_put_node;
718 dp = dsa_to_port(ds, reg);
720 err = dsa_port_parse_of(dp, port);
721 if (err)
722 goto out_put_node;
725 out_put_node:
726 of_node_put(ports);
727 return err;
730 static int dsa_switch_parse_member_of(struct dsa_switch *ds,
731 struct device_node *dn)
733 u32 m[2] = { 0, 0 };
734 int sz;
736 /* Don't error out if this optional property isn't found */
737 sz = of_property_read_variable_u32_array(dn, "dsa,member", m, 2, 2);
738 if (sz < 0 && sz != -EINVAL)
739 return sz;
741 ds->index = m[1];
743 ds->dst = dsa_tree_touch(m[0]);
744 if (!ds->dst)
745 return -ENOMEM;
747 return 0;
750 static int dsa_switch_touch_ports(struct dsa_switch *ds)
752 struct dsa_port *dp;
753 int port;
755 for (port = 0; port < ds->num_ports; port++) {
756 dp = dsa_port_touch(ds, port);
757 if (!dp)
758 return -ENOMEM;
761 return 0;
764 static int dsa_switch_parse_of(struct dsa_switch *ds, struct device_node *dn)
766 int err;
768 err = dsa_switch_parse_member_of(ds, dn);
769 if (err)
770 return err;
772 err = dsa_switch_touch_ports(ds);
773 if (err)
774 return err;
776 return dsa_switch_parse_ports_of(ds, dn);
779 static int dsa_port_parse(struct dsa_port *dp, const char *name,
780 struct device *dev)
782 if (!strcmp(name, "cpu")) {
783 struct net_device *master;
785 master = dsa_dev_to_net_device(dev);
786 if (!master)
787 return -EPROBE_DEFER;
789 dev_put(master);
791 return dsa_port_parse_cpu(dp, master);
794 if (!strcmp(name, "dsa"))
795 return dsa_port_parse_dsa(dp);
797 return dsa_port_parse_user(dp, name);
800 static int dsa_switch_parse_ports(struct dsa_switch *ds,
801 struct dsa_chip_data *cd)
803 bool valid_name_found = false;
804 struct dsa_port *dp;
805 struct device *dev;
806 const char *name;
807 unsigned int i;
808 int err;
810 for (i = 0; i < DSA_MAX_PORTS; i++) {
811 name = cd->port_names[i];
812 dev = cd->netdev[i];
813 dp = dsa_to_port(ds, i);
815 if (!name)
816 continue;
818 err = dsa_port_parse(dp, name, dev);
819 if (err)
820 return err;
822 valid_name_found = true;
825 if (!valid_name_found && i == DSA_MAX_PORTS)
826 return -EINVAL;
828 return 0;
831 static int dsa_switch_parse(struct dsa_switch *ds, struct dsa_chip_data *cd)
833 int err;
835 ds->cd = cd;
837 /* We don't support interconnected switches nor multiple trees via
838 * platform data, so this is the unique switch of the tree.
840 ds->index = 0;
841 ds->dst = dsa_tree_touch(0);
842 if (!ds->dst)
843 return -ENOMEM;
845 err = dsa_switch_touch_ports(ds);
846 if (err)
847 return err;
849 return dsa_switch_parse_ports(ds, cd);
852 static void dsa_switch_release_ports(struct dsa_switch *ds)
854 struct dsa_switch_tree *dst = ds->dst;
855 struct dsa_port *dp, *next;
857 list_for_each_entry_safe(dp, next, &dst->ports, list) {
858 if (dp->ds != ds)
859 continue;
860 list_del(&dp->list);
861 kfree(dp);
865 static int dsa_switch_probe(struct dsa_switch *ds)
867 struct dsa_switch_tree *dst;
868 struct dsa_chip_data *pdata;
869 struct device_node *np;
870 int err;
872 if (!ds->dev)
873 return -ENODEV;
875 pdata = ds->dev->platform_data;
876 np = ds->dev->of_node;
878 if (!ds->num_ports)
879 return -EINVAL;
881 if (np) {
882 err = dsa_switch_parse_of(ds, np);
883 if (err)
884 dsa_switch_release_ports(ds);
885 } else if (pdata) {
886 err = dsa_switch_parse(ds, pdata);
887 if (err)
888 dsa_switch_release_ports(ds);
889 } else {
890 err = -ENODEV;
893 if (err)
894 return err;
896 dst = ds->dst;
897 dsa_tree_get(dst);
898 err = dsa_tree_setup(dst);
899 if (err) {
900 dsa_switch_release_ports(ds);
901 dsa_tree_put(dst);
904 return err;
907 int dsa_register_switch(struct dsa_switch *ds)
909 int err;
911 mutex_lock(&dsa2_mutex);
912 err = dsa_switch_probe(ds);
913 dsa_tree_put(ds->dst);
914 mutex_unlock(&dsa2_mutex);
916 return err;
918 EXPORT_SYMBOL_GPL(dsa_register_switch);
920 static void dsa_switch_remove(struct dsa_switch *ds)
922 struct dsa_switch_tree *dst = ds->dst;
924 dsa_tree_teardown(dst);
925 dsa_switch_release_ports(ds);
926 dsa_tree_put(dst);
929 void dsa_unregister_switch(struct dsa_switch *ds)
931 mutex_lock(&dsa2_mutex);
932 dsa_switch_remove(ds);
933 mutex_unlock(&dsa2_mutex);
935 EXPORT_SYMBOL_GPL(dsa_unregister_switch);