Lines Matching +full:dp +full:- +full:bridge

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * net/dsa/dsa2.c - Hardware switch handling, binding version 2
4 * Copyright (c) 2008-2009 Marvell Semiconductor
30 * dsa_tree_notify - Execute code for all switches in a DSA switch tree.
33 * @v: event-specific value.
41 struct raw_notifier_head *nh = &dst->nh; in dsa_tree_notify()
50 * dsa_broadcast - Notify all DSA trees in the system.
52 * @v: event-specific value.
54 * Can be used to notify the switching fabric of events such as cross-chip
55 * bridging between disjoint trees (such as islands of tagger-compatible
76 * dsa_lag_map() - Map LAG structure to a linear LAG array
82 * driver by setting ds->num_lag_ids. It is perfectly legal to leave
84 * no-ops.
90 for (id = 1; id <= dst->lags_len; id++) { in dsa_lag_map()
92 dst->lags[id - 1] = lag; in dsa_lag_map()
93 lag->id = id; in dsa_lag_map()
101 * driver can then return -EOPNOTSUPP back to DSA, which will in dsa_lag_map()
107 * dsa_lag_unmap() - Remove a LAG ID mapping
120 dst->lags[id - 1] = NULL; in dsa_lag_unmap()
121 lag->id = 0; in dsa_lag_unmap()
130 struct dsa_port *dp; in dsa_tree_lag_find() local
132 list_for_each_entry(dp, &dst->ports, list) in dsa_tree_lag_find()
133 if (dsa_port_lag_dev_get(dp) == lag_dev) in dsa_tree_lag_find()
134 return dp->lag; in dsa_tree_lag_find()
142 struct dsa_port *dp; in dsa_tree_bridge_find() local
144 list_for_each_entry(dp, &dst->ports, list) in dsa_tree_bridge_find()
145 if (dsa_port_bridge_dev_get(dp) == br) in dsa_tree_bridge_find()
146 return dp->bridge; in dsa_tree_bridge_find()
156 struct dsa_bridge *bridge; in dsa_bridge_num_find() local
158 bridge = dsa_tree_bridge_find(dst, bridge_dev); in dsa_bridge_num_find()
159 if (bridge) in dsa_bridge_num_find()
160 return bridge->num; in dsa_bridge_num_find()
171 * bridge numbering in dsa_bridge_num_get()
178 * offload for this bridge in dsa_bridge_num_get()
205 struct dsa_port *dp; in dsa_switch_find() local
208 if (dst->index != tree_index) in dsa_switch_find()
211 list_for_each_entry(dp, &dst->ports, list) { in dsa_switch_find()
212 if (dp->ds->index != sw_index) in dsa_switch_find()
215 return dp->ds; in dsa_switch_find()
228 if (dst->index == index) in dsa_tree_find()
242 dst->index = index; in dsa_tree_alloc()
244 INIT_LIST_HEAD(&dst->rtable); in dsa_tree_alloc()
246 INIT_LIST_HEAD(&dst->ports); in dsa_tree_alloc()
248 INIT_LIST_HEAD(&dst->list); in dsa_tree_alloc()
249 list_add_tail(&dst->list, &dsa_tree_list); in dsa_tree_alloc()
251 kref_init(&dst->refcount); in dsa_tree_alloc()
258 if (dst->tag_ops) in dsa_tree_free()
259 dsa_tag_driver_put(dst->tag_ops); in dsa_tree_free()
260 list_del(&dst->list); in dsa_tree_free()
267 kref_get(&dst->refcount); in dsa_tree_get()
295 kref_put(&dst->refcount, dsa_tree_release); in dsa_tree_put()
301 struct dsa_port *dp; in dsa_tree_find_port_by_node() local
303 list_for_each_entry(dp, &dst->ports, list) in dsa_tree_find_port_by_node()
304 if (dp->dn == dn) in dsa_tree_find_port_by_node()
305 return dp; in dsa_tree_find_port_by_node()
310 static struct dsa_link *dsa_link_touch(struct dsa_port *dp, in dsa_link_touch() argument
313 struct dsa_switch *ds = dp->ds; in dsa_link_touch()
317 dst = ds->dst; in dsa_link_touch()
319 list_for_each_entry(dl, &dst->rtable, list) in dsa_link_touch()
320 if (dl->dp == dp && dl->link_dp == link_dp) in dsa_link_touch()
327 dl->dp = dp; in dsa_link_touch()
328 dl->link_dp = link_dp; in dsa_link_touch()
330 INIT_LIST_HEAD(&dl->list); in dsa_link_touch()
331 list_add_tail(&dl->list, &dst->rtable); in dsa_link_touch()
336 static bool dsa_port_setup_routing_table(struct dsa_port *dp) in dsa_port_setup_routing_table() argument
338 struct dsa_switch *ds = dp->ds; in dsa_port_setup_routing_table()
339 struct dsa_switch_tree *dst = ds->dst; in dsa_port_setup_routing_table()
340 struct device_node *dn = dp->dn; in dsa_port_setup_routing_table()
353 dl = dsa_link_touch(dp, link_dp); in dsa_port_setup_routing_table()
366 struct dsa_port *dp; in dsa_tree_setup_routing_table() local
368 list_for_each_entry(dp, &dst->ports, list) { in dsa_tree_setup_routing_table()
369 if (dsa_port_is_dsa(dp)) { in dsa_tree_setup_routing_table()
370 complete = dsa_port_setup_routing_table(dp); in dsa_tree_setup_routing_table()
381 struct dsa_port *dp; in dsa_tree_find_first_cpu() local
383 list_for_each_entry(dp, &dst->ports, list) in dsa_tree_find_first_cpu()
384 if (dsa_port_is_cpu(dp)) in dsa_tree_find_first_cpu()
385 return dp; in dsa_tree_find_first_cpu()
397 ethernet = of_parse_phandle(cpu_dp->dn, "ethernet", 0); in dsa_tree_find_first_master()
409 struct dsa_port *cpu_dp, *dp; in dsa_tree_setup_default_cpu() local
413 pr_err("DSA: tree %d has no CPU port\n", dst->index); in dsa_tree_setup_default_cpu()
414 return -EINVAL; in dsa_tree_setup_default_cpu()
417 list_for_each_entry(dp, &dst->ports, list) { in dsa_tree_setup_default_cpu()
418 if (dp->cpu_dp) in dsa_tree_setup_default_cpu()
421 if (dsa_port_is_user(dp) || dsa_port_is_dsa(dp)) in dsa_tree_setup_default_cpu()
422 dp->cpu_dp = cpu_dp; in dsa_tree_setup_default_cpu()
435 struct dsa_port *cpu_dp, *dp; in dsa_tree_setup_cpu_ports() local
437 list_for_each_entry(cpu_dp, &dst->ports, list) { in dsa_tree_setup_cpu_ports()
442 dsa_switch_for_each_port(dp, cpu_dp->ds) { in dsa_tree_setup_cpu_ports()
444 if (dp->cpu_dp) in dsa_tree_setup_cpu_ports()
447 if (dsa_port_is_user(dp) || dsa_port_is_dsa(dp)) in dsa_tree_setup_cpu_ports()
448 dp->cpu_dp = cpu_dp; in dsa_tree_setup_cpu_ports()
457 struct dsa_port *dp; in dsa_tree_teardown_cpu_ports() local
459 list_for_each_entry(dp, &dst->ports, list) in dsa_tree_teardown_cpu_ports()
460 if (dsa_port_is_user(dp) || dsa_port_is_dsa(dp)) in dsa_tree_teardown_cpu_ports()
461 dp->cpu_dp = NULL; in dsa_tree_teardown_cpu_ports()
464 static int dsa_port_devlink_setup(struct dsa_port *dp) in dsa_port_devlink_setup() argument
466 struct devlink_port *dlp = &dp->devlink_port; in dsa_port_devlink_setup()
467 struct dsa_switch_tree *dst = dp->ds->dst; in dsa_port_devlink_setup()
469 struct devlink *dl = dp->ds->devlink; in dsa_port_devlink_setup()
470 struct dsa_switch *ds = dp->ds; in dsa_port_devlink_setup()
478 if (ds->ops->port_setup) { in dsa_port_devlink_setup()
479 err = ds->ops->port_setup(ds, dp->index); in dsa_port_devlink_setup()
484 id = (const unsigned char *)&dst->index; in dsa_port_devlink_setup()
485 len = sizeof(dst->index); in dsa_port_devlink_setup()
487 attrs.phys.port_number = dp->index; in dsa_port_devlink_setup()
491 switch (dp->type) { in dsa_port_devlink_setup()
507 err = devlink_port_register(dl, dlp, dp->index); in dsa_port_devlink_setup()
509 if (ds->ops->port_teardown) in dsa_port_devlink_setup()
510 ds->ops->port_teardown(ds, dp->index); in dsa_port_devlink_setup()
517 static void dsa_port_devlink_teardown(struct dsa_port *dp) in dsa_port_devlink_teardown() argument
519 struct devlink_port *dlp = &dp->devlink_port; in dsa_port_devlink_teardown()
520 struct dsa_switch *ds = dp->ds; in dsa_port_devlink_teardown()
524 if (ds->ops->port_teardown) in dsa_port_devlink_teardown()
525 ds->ops->port_teardown(ds, dp->index); in dsa_port_devlink_teardown()
530 static int dsa_port_setup(struct dsa_port *dp) in dsa_port_setup() argument
532 struct devlink_port *dlp = &dp->devlink_port; in dsa_port_setup()
534 struct dsa_switch *ds = dp->ds; in dsa_port_setup()
538 if (dp->setup) in dsa_port_setup()
541 err = dsa_port_devlink_setup(dp); in dsa_port_setup()
545 switch (dp->type) { in dsa_port_setup()
547 dsa_port_disable(dp); in dsa_port_setup()
550 if (dp->dn) { in dsa_port_setup()
551 err = dsa_shared_port_link_register_of(dp); in dsa_port_setup()
556 dev_warn(ds->dev, in dsa_port_setup()
558 dp->index); in dsa_port_setup()
561 err = dsa_port_enable(dp, NULL); in dsa_port_setup()
568 if (dp->dn) { in dsa_port_setup()
569 err = dsa_shared_port_link_register_of(dp); in dsa_port_setup()
574 dev_warn(ds->dev, in dsa_port_setup()
576 dp->index); in dsa_port_setup()
579 err = dsa_port_enable(dp, NULL); in dsa_port_setup()
586 of_get_mac_address(dp->dn, dp->mac); in dsa_port_setup()
587 err = dsa_slave_create(dp); in dsa_port_setup()
591 devlink_port_type_eth_set(dlp, dp->slave); in dsa_port_setup()
596 dsa_port_disable(dp); in dsa_port_setup()
598 dsa_shared_port_link_unregister_of(dp); in dsa_port_setup()
600 dsa_port_devlink_teardown(dp); in dsa_port_setup()
604 dp->setup = true; in dsa_port_setup()
609 static void dsa_port_teardown(struct dsa_port *dp) in dsa_port_teardown() argument
611 struct devlink_port *dlp = &dp->devlink_port; in dsa_port_teardown()
613 if (!dp->setup) in dsa_port_teardown()
618 switch (dp->type) { in dsa_port_teardown()
622 dsa_port_disable(dp); in dsa_port_teardown()
623 if (dp->dn) in dsa_port_teardown()
624 dsa_shared_port_link_unregister_of(dp); in dsa_port_teardown()
627 dsa_port_disable(dp); in dsa_port_teardown()
628 if (dp->dn) in dsa_port_teardown()
629 dsa_shared_port_link_unregister_of(dp); in dsa_port_teardown()
632 if (dp->slave) { in dsa_port_teardown()
633 dsa_slave_destroy(dp->slave); in dsa_port_teardown()
634 dp->slave = NULL; in dsa_port_teardown()
639 dsa_port_devlink_teardown(dp); in dsa_port_teardown()
641 dp->setup = false; in dsa_port_teardown()
644 static int dsa_port_setup_as_unused(struct dsa_port *dp) in dsa_port_setup_as_unused() argument
646 dp->type = DSA_PORT_TYPE_UNUSED; in dsa_port_setup_as_unused()
647 return dsa_port_setup(dp); in dsa_port_setup_as_unused()
656 if (ds->ops->devlink_info_get) in dsa_devlink_info_get()
657 return ds->ops->devlink_info_get(ds, req, extack); in dsa_devlink_info_get()
659 return -EOPNOTSUPP; in dsa_devlink_info_get()
668 if (!ds->ops->devlink_sb_pool_get) in dsa_devlink_sb_pool_get()
669 return -EOPNOTSUPP; in dsa_devlink_sb_pool_get()
671 return ds->ops->devlink_sb_pool_get(ds, sb_index, pool_index, in dsa_devlink_sb_pool_get()
682 if (!ds->ops->devlink_sb_pool_set) in dsa_devlink_sb_pool_set()
683 return -EOPNOTSUPP; in dsa_devlink_sb_pool_set()
685 return ds->ops->devlink_sb_pool_set(ds, sb_index, pool_index, size, in dsa_devlink_sb_pool_set()
696 if (!ds->ops->devlink_sb_port_pool_get) in dsa_devlink_sb_port_pool_get()
697 return -EOPNOTSUPP; in dsa_devlink_sb_port_pool_get()
699 return ds->ops->devlink_sb_port_pool_get(ds, port, sb_index, in dsa_devlink_sb_port_pool_get()
711 if (!ds->ops->devlink_sb_port_pool_set) in dsa_devlink_sb_port_pool_set()
712 return -EOPNOTSUPP; in dsa_devlink_sb_port_pool_set()
714 return ds->ops->devlink_sb_port_pool_set(ds, port, sb_index, in dsa_devlink_sb_port_pool_set()
727 if (!ds->ops->devlink_sb_tc_pool_bind_get) in dsa_devlink_sb_tc_pool_bind_get()
728 return -EOPNOTSUPP; in dsa_devlink_sb_tc_pool_bind_get()
730 return ds->ops->devlink_sb_tc_pool_bind_get(ds, port, sb_index, in dsa_devlink_sb_tc_pool_bind_get()
745 if (!ds->ops->devlink_sb_tc_pool_bind_set) in dsa_devlink_sb_tc_pool_bind_set()
746 return -EOPNOTSUPP; in dsa_devlink_sb_tc_pool_bind_set()
748 return ds->ops->devlink_sb_tc_pool_bind_set(ds, port, sb_index, in dsa_devlink_sb_tc_pool_bind_set()
759 if (!ds->ops->devlink_sb_occ_snapshot) in dsa_devlink_sb_occ_snapshot()
760 return -EOPNOTSUPP; in dsa_devlink_sb_occ_snapshot()
762 return ds->ops->devlink_sb_occ_snapshot(ds, sb_index); in dsa_devlink_sb_occ_snapshot()
770 if (!ds->ops->devlink_sb_occ_max_clear) in dsa_devlink_sb_occ_max_clear()
771 return -EOPNOTSUPP; in dsa_devlink_sb_occ_max_clear()
773 return ds->ops->devlink_sb_occ_max_clear(ds, sb_index); in dsa_devlink_sb_occ_max_clear()
784 if (!ds->ops->devlink_sb_occ_port_pool_get) in dsa_devlink_sb_occ_port_pool_get()
785 return -EOPNOTSUPP; in dsa_devlink_sb_occ_port_pool_get()
787 return ds->ops->devlink_sb_occ_port_pool_get(ds, port, sb_index, in dsa_devlink_sb_occ_port_pool_get()
800 if (!ds->ops->devlink_sb_occ_tc_port_bind_get) in dsa_devlink_sb_occ_tc_port_bind_get()
801 return -EOPNOTSUPP; in dsa_devlink_sb_occ_tc_port_bind_get()
803 return ds->ops->devlink_sb_occ_tc_port_bind_get(ds, port, in dsa_devlink_sb_occ_tc_port_bind_get()
825 const struct dsa_device_ops *tag_ops = ds->dst->tag_ops; in dsa_switch_setup_tag_protocol()
826 struct dsa_switch_tree *dst = ds->dst; in dsa_switch_setup_tag_protocol()
829 if (tag_ops->proto == dst->default_proto) in dsa_switch_setup_tag_protocol()
833 err = ds->ops->change_tag_protocol(ds, tag_ops->proto); in dsa_switch_setup_tag_protocol()
836 dev_err(ds->dev, "Unable to use tag protocol \"%s\": %pe\n", in dsa_switch_setup_tag_protocol()
837 tag_ops->name, ERR_PTR(err)); in dsa_switch_setup_tag_protocol()
842 if (tag_ops->connect) { in dsa_switch_setup_tag_protocol()
843 err = tag_ops->connect(ds); in dsa_switch_setup_tag_protocol()
848 if (ds->ops->connect_tag_protocol) { in dsa_switch_setup_tag_protocol()
849 err = ds->ops->connect_tag_protocol(ds, tag_ops->proto); in dsa_switch_setup_tag_protocol()
851 dev_err(ds->dev, in dsa_switch_setup_tag_protocol()
853 tag_ops->name, ERR_PTR(err)); in dsa_switch_setup_tag_protocol()
861 if (tag_ops->disconnect) in dsa_switch_setup_tag_protocol()
862 tag_ops->disconnect(ds); in dsa_switch_setup_tag_protocol()
869 const struct dsa_device_ops *tag_ops = ds->dst->tag_ops; in dsa_switch_teardown_tag_protocol()
871 if (tag_ops->disconnect) in dsa_switch_teardown_tag_protocol()
872 tag_ops->disconnect(ds); in dsa_switch_teardown_tag_protocol()
881 if (ds->setup) in dsa_switch_setup()
884 /* Initialize ds->phys_mii_mask before registering the slave MDIO bus in dsa_switch_setup()
885 * driver and before ops->setup() has run, since the switch drivers and in dsa_switch_setup()
889 ds->phys_mii_mask |= dsa_user_ports(ds); in dsa_switch_setup()
894 ds->devlink = in dsa_switch_setup()
895 devlink_alloc(&dsa_devlink_ops, sizeof(*dl_priv), ds->dev); in dsa_switch_setup()
896 if (!ds->devlink) in dsa_switch_setup()
897 return -ENOMEM; in dsa_switch_setup()
898 dl_priv = devlink_priv(ds->devlink); in dsa_switch_setup()
899 dl_priv->ds = ds; in dsa_switch_setup()
905 ds->configure_vlan_while_not_filtering = true; in dsa_switch_setup()
907 err = ds->ops->setup(ds); in dsa_switch_setup()
915 if (!ds->slave_mii_bus && ds->ops->phy_read) { in dsa_switch_setup()
916 ds->slave_mii_bus = mdiobus_alloc(); in dsa_switch_setup()
917 if (!ds->slave_mii_bus) { in dsa_switch_setup()
918 err = -ENOMEM; in dsa_switch_setup()
924 dn = of_get_child_by_name(ds->dev->of_node, "mdio"); in dsa_switch_setup()
926 err = of_mdiobus_register(ds->slave_mii_bus, dn); in dsa_switch_setup()
932 ds->setup = true; in dsa_switch_setup()
933 devlink_register(ds->devlink); in dsa_switch_setup()
937 if (ds->slave_mii_bus && ds->ops->phy_read) in dsa_switch_setup()
938 mdiobus_free(ds->slave_mii_bus); in dsa_switch_setup()
940 if (ds->ops->teardown) in dsa_switch_setup()
941 ds->ops->teardown(ds); in dsa_switch_setup()
945 devlink_free(ds->devlink); in dsa_switch_setup()
946 ds->devlink = NULL; in dsa_switch_setup()
952 if (!ds->setup) in dsa_switch_teardown()
955 if (ds->devlink) in dsa_switch_teardown()
956 devlink_unregister(ds->devlink); in dsa_switch_teardown()
958 if (ds->slave_mii_bus && ds->ops->phy_read) { in dsa_switch_teardown()
959 mdiobus_unregister(ds->slave_mii_bus); in dsa_switch_teardown()
960 mdiobus_free(ds->slave_mii_bus); in dsa_switch_teardown()
961 ds->slave_mii_bus = NULL; in dsa_switch_teardown()
966 if (ds->ops->teardown) in dsa_switch_teardown()
967 ds->ops->teardown(ds); in dsa_switch_teardown()
971 if (ds->devlink) { in dsa_switch_teardown()
972 devlink_free(ds->devlink); in dsa_switch_teardown()
973 ds->devlink = NULL; in dsa_switch_teardown()
976 ds->setup = false; in dsa_switch_teardown()
979 /* First tear down the non-shared, then the shared ports. This ensures that
985 struct dsa_port *dp; in dsa_tree_teardown_ports() local
987 list_for_each_entry(dp, &dst->ports, list) in dsa_tree_teardown_ports()
988 if (dsa_port_is_user(dp) || dsa_port_is_unused(dp)) in dsa_tree_teardown_ports()
989 dsa_port_teardown(dp); in dsa_tree_teardown_ports()
993 list_for_each_entry(dp, &dst->ports, list) in dsa_tree_teardown_ports()
994 if (dsa_port_is_dsa(dp) || dsa_port_is_cpu(dp)) in dsa_tree_teardown_ports()
995 dsa_port_teardown(dp); in dsa_tree_teardown_ports()
1000 struct dsa_port *dp; in dsa_tree_teardown_switches() local
1002 list_for_each_entry(dp, &dst->ports, list) in dsa_tree_teardown_switches()
1003 dsa_switch_teardown(dp->ds); in dsa_tree_teardown_switches()
1006 /* Bring shared ports up first, then non-shared ports */
1009 struct dsa_port *dp; in dsa_tree_setup_ports() local
1012 list_for_each_entry(dp, &dst->ports, list) { in dsa_tree_setup_ports()
1013 if (dsa_port_is_dsa(dp) || dsa_port_is_cpu(dp)) { in dsa_tree_setup_ports()
1014 err = dsa_port_setup(dp); in dsa_tree_setup_ports()
1020 list_for_each_entry(dp, &dst->ports, list) { in dsa_tree_setup_ports()
1021 if (dsa_port_is_user(dp) || dsa_port_is_unused(dp)) { in dsa_tree_setup_ports()
1022 err = dsa_port_setup(dp); in dsa_tree_setup_ports()
1024 err = dsa_port_setup_as_unused(dp); in dsa_tree_setup_ports()
1041 struct dsa_port *dp; in dsa_tree_setup_switches() local
1044 list_for_each_entry(dp, &dst->ports, list) { in dsa_tree_setup_switches()
1045 err = dsa_switch_setup(dp->ds); in dsa_tree_setup_switches()
1063 struct net_device *master = cpu_dp->master; in dsa_tree_setup_master()
1064 bool admin_up = (master->flags & IFF_UP) && in dsa_tree_setup_master()
1089 struct net_device *master = cpu_dp->master; in dsa_tree_teardown_master()
1106 struct dsa_port *dp; in dsa_tree_setup_lags() local
1108 list_for_each_entry(dp, &dst->ports, list) { in dsa_tree_setup_lags()
1109 if (dp->ds->num_lag_ids > len) in dsa_tree_setup_lags()
1110 len = dp->ds->num_lag_ids; in dsa_tree_setup_lags()
1116 dst->lags = kcalloc(len, sizeof(*dst->lags), GFP_KERNEL); in dsa_tree_setup_lags()
1117 if (!dst->lags) in dsa_tree_setup_lags()
1118 return -ENOMEM; in dsa_tree_setup_lags()
1120 dst->lags_len = len; in dsa_tree_setup_lags()
1126 kfree(dst->lags); in dsa_tree_teardown_lags()
1134 if (dst->setup) { in dsa_tree_setup()
1136 dst->index); in dsa_tree_setup()
1137 return -EEXIST; in dsa_tree_setup()
1164 dst->setup = true; in dsa_tree_setup()
1166 pr_info("DSA: tree %d setup\n", dst->index); in dsa_tree_setup()
1186 if (!dst->setup) in dsa_tree_teardown()
1199 list_for_each_entry_safe(dl, next, &dst->rtable, list) { in dsa_tree_teardown()
1200 list_del(&dl->list); in dsa_tree_teardown()
1204 pr_info("DSA: tree %d torn down\n", dst->index); in dsa_tree_teardown()
1206 dst->setup = false; in dsa_tree_teardown()
1212 const struct dsa_device_ops *old_tag_ops = dst->tag_ops; in dsa_tree_bind_tag_proto()
1216 dst->tag_ops = tag_ops; in dsa_tree_bind_tag_proto()
1223 if (err && err != -EOPNOTSUPP) in dsa_tree_bind_tag_proto()
1235 dst->tag_ops = old_tag_ops; in dsa_tree_bind_tag_proto()
1249 struct dsa_port *dp; in dsa_tree_change_tag_proto() local
1250 int err = -EBUSY; in dsa_tree_change_tag_proto()
1260 dsa_tree_for_each_user_port(dp, dst) { in dsa_tree_change_tag_proto()
1261 if (dsa_port_to_master(dp)->flags & IFF_UP) in dsa_tree_change_tag_proto()
1264 if (dp->slave->flags & IFF_UP) in dsa_tree_change_tag_proto()
1294 struct dsa_port *cpu_dp = master->dsa_ptr; in dsa_tree_master_state_change()
1306 struct dsa_port *cpu_dp = master->dsa_ptr; in dsa_tree_master_admin_state_change()
1316 (up && cpu_dp->master_oper_up)) in dsa_tree_master_admin_state_change()
1319 cpu_dp->master_admin_up = up; in dsa_tree_master_admin_state_change()
1329 struct dsa_port *cpu_dp = master->dsa_ptr; in dsa_tree_master_oper_state_change()
1339 (cpu_dp->master_admin_up && up)) in dsa_tree_master_oper_state_change()
1342 cpu_dp->master_oper_up = up; in dsa_tree_master_oper_state_change()
1350 struct dsa_switch_tree *dst = ds->dst; in dsa_port_touch()
1351 struct dsa_port *dp; in dsa_port_touch() local
1353 dsa_switch_for_each_port(dp, ds) in dsa_port_touch()
1354 if (dp->index == index) in dsa_port_touch()
1355 return dp; in dsa_port_touch()
1357 dp = kzalloc(sizeof(*dp), GFP_KERNEL); in dsa_port_touch()
1358 if (!dp) in dsa_port_touch()
1361 dp->ds = ds; in dsa_port_touch()
1362 dp->index = index; in dsa_port_touch()
1364 mutex_init(&dp->addr_lists_lock); in dsa_port_touch()
1365 mutex_init(&dp->vlans_lock); in dsa_port_touch()
1366 INIT_LIST_HEAD(&dp->fdbs); in dsa_port_touch()
1367 INIT_LIST_HEAD(&dp->mdbs); in dsa_port_touch()
1368 INIT_LIST_HEAD(&dp->vlans); in dsa_port_touch()
1369 INIT_LIST_HEAD(&dp->list); in dsa_port_touch()
1370 list_add_tail(&dp->list, &dst->ports); in dsa_port_touch()
1372 return dp; in dsa_port_touch()
1375 static int dsa_port_parse_user(struct dsa_port *dp, const char *name) in dsa_port_parse_user() argument
1380 dp->type = DSA_PORT_TYPE_USER; in dsa_port_parse_user()
1381 dp->name = name; in dsa_port_parse_user()
1386 static int dsa_port_parse_dsa(struct dsa_port *dp) in dsa_port_parse_dsa() argument
1388 dp->type = DSA_PORT_TYPE_DSA; in dsa_port_parse_dsa()
1393 static enum dsa_tag_protocol dsa_get_tag_protocol(struct dsa_port *dp, in dsa_get_tag_protocol() argument
1397 struct dsa_switch *mds, *ds = dp->ds; in dsa_get_tag_protocol()
1407 mds = mdp->ds; in dsa_get_tag_protocol()
1408 mdp_upstream = dsa_upstream_port(mds, mdp->index); in dsa_get_tag_protocol()
1409 tag_protocol = mds->ops->get_tag_protocol(mds, mdp_upstream, in dsa_get_tag_protocol()
1416 return ds->ops->get_tag_protocol(ds, dp->index, tag_protocol); in dsa_get_tag_protocol()
1419 static int dsa_port_parse_cpu(struct dsa_port *dp, struct net_device *master, in dsa_port_parse_cpu() argument
1423 struct dsa_switch *ds = dp->ds; in dsa_port_parse_cpu()
1424 struct dsa_switch_tree *dst = ds->dst; in dsa_port_parse_cpu()
1428 default_proto = dsa_get_tag_protocol(dp, master); in dsa_port_parse_cpu()
1429 if (dst->default_proto) { in dsa_port_parse_cpu()
1430 if (dst->default_proto != default_proto) { in dsa_port_parse_cpu()
1431 dev_err(ds->dev, in dsa_port_parse_cpu()
1433 return -EINVAL; in dsa_port_parse_cpu()
1436 dst->default_proto = default_proto; in dsa_port_parse_cpu()
1441 if (!ds->ops->change_tag_protocol) { in dsa_port_parse_cpu()
1442 dev_err(ds->dev, "Tag protocol cannot be modified\n"); in dsa_port_parse_cpu()
1443 return -EINVAL; in dsa_port_parse_cpu()
1448 dev_warn(ds->dev, in dsa_port_parse_cpu()
1459 if (PTR_ERR(tag_ops) == -ENOPROTOOPT) in dsa_port_parse_cpu()
1460 return -EPROBE_DEFER; in dsa_port_parse_cpu()
1462 dev_warn(ds->dev, "No tagger for this switch\n"); in dsa_port_parse_cpu()
1466 if (dst->tag_ops) { in dsa_port_parse_cpu()
1467 if (dst->tag_ops != tag_ops) { in dsa_port_parse_cpu()
1468 dev_err(ds->dev, in dsa_port_parse_cpu()
1472 return -EINVAL; in dsa_port_parse_cpu()
1476 * protocol is still reference-counted only per switch tree. in dsa_port_parse_cpu()
1480 dst->tag_ops = tag_ops; in dsa_port_parse_cpu()
1483 dp->master = master; in dsa_port_parse_cpu()
1484 dp->type = DSA_PORT_TYPE_CPU; in dsa_port_parse_cpu()
1485 dsa_port_set_tag_protocol(dp, dst->tag_ops); in dsa_port_parse_cpu()
1486 dp->dst = dst; in dsa_port_parse_cpu()
1504 static int dsa_port_parse_of(struct dsa_port *dp, struct device_node *dn) in dsa_port_parse_of() argument
1510 dp->dn = dn; in dsa_port_parse_of()
1519 return -EPROBE_DEFER; in dsa_port_parse_of()
1521 user_protocol = of_get_property(dn, "dsa-tag-protocol", NULL); in dsa_port_parse_of()
1522 return dsa_port_parse_cpu(dp, master, user_protocol); in dsa_port_parse_of()
1526 return dsa_port_parse_dsa(dp); in dsa_port_parse_of()
1528 return dsa_port_parse_user(dp, name); in dsa_port_parse_of()
1535 struct dsa_port *dp; in dsa_switch_parse_ports_of() local
1541 /* The second possibility is "ethernet-ports" */ in dsa_switch_parse_ports_of()
1542 ports = of_get_child_by_name(dn, "ethernet-ports"); in dsa_switch_parse_ports_of()
1544 dev_err(ds->dev, "no ports child node found\n"); in dsa_switch_parse_ports_of()
1545 return -EINVAL; in dsa_switch_parse_ports_of()
1556 if (reg >= ds->num_ports) { in dsa_switch_parse_ports_of()
1557 dev_err(ds->dev, "port %pOF index %u exceeds num_ports (%u)\n", in dsa_switch_parse_ports_of()
1558 port, reg, ds->num_ports); in dsa_switch_parse_ports_of()
1560 err = -EINVAL; in dsa_switch_parse_ports_of()
1564 dp = dsa_to_port(ds, reg); in dsa_switch_parse_ports_of()
1566 err = dsa_port_parse_of(dp, port); in dsa_switch_parse_ports_of()
1586 if (sz < 0 && sz != -EINVAL) in dsa_switch_parse_member_of()
1589 ds->index = m[1]; in dsa_switch_parse_member_of()
1591 ds->dst = dsa_tree_touch(m[0]); in dsa_switch_parse_member_of()
1592 if (!ds->dst) in dsa_switch_parse_member_of()
1593 return -ENOMEM; in dsa_switch_parse_member_of()
1595 if (dsa_switch_find(ds->dst->index, ds->index)) { in dsa_switch_parse_member_of()
1596 dev_err(ds->dev, in dsa_switch_parse_member_of()
1598 ds->index, ds->dst->index); in dsa_switch_parse_member_of()
1599 return -EEXIST; in dsa_switch_parse_member_of()
1602 if (ds->dst->last_switch < ds->index) in dsa_switch_parse_member_of()
1603 ds->dst->last_switch = ds->index; in dsa_switch_parse_member_of()
1610 struct dsa_port *dp; in dsa_switch_touch_ports() local
1613 for (port = 0; port < ds->num_ports; port++) { in dsa_switch_touch_ports()
1614 dp = dsa_port_touch(ds, port); in dsa_switch_touch_ports()
1615 if (!dp) in dsa_switch_touch_ports()
1616 return -ENOMEM; in dsa_switch_touch_ports()
1637 static int dsa_port_parse(struct dsa_port *dp, const char *name, in dsa_port_parse() argument
1645 return -EPROBE_DEFER; in dsa_port_parse()
1649 return dsa_port_parse_cpu(dp, master, NULL); in dsa_port_parse()
1653 return dsa_port_parse_dsa(dp); in dsa_port_parse()
1655 return dsa_port_parse_user(dp, name); in dsa_port_parse()
1662 struct dsa_port *dp; in dsa_switch_parse_ports() local
1669 name = cd->port_names[i]; in dsa_switch_parse_ports()
1670 dev = cd->netdev[i]; in dsa_switch_parse_ports()
1671 dp = dsa_to_port(ds, i); in dsa_switch_parse_ports()
1676 err = dsa_port_parse(dp, name, dev); in dsa_switch_parse_ports()
1684 return -EINVAL; in dsa_switch_parse_ports()
1693 ds->cd = cd; in dsa_switch_parse()
1698 ds->index = 0; in dsa_switch_parse()
1699 ds->dst = dsa_tree_touch(0); in dsa_switch_parse()
1700 if (!ds->dst) in dsa_switch_parse()
1701 return -ENOMEM; in dsa_switch_parse()
1712 struct dsa_port *dp, *next; in dsa_switch_release_ports() local
1714 dsa_switch_for_each_port_safe(dp, next, ds) { in dsa_switch_release_ports()
1715 WARN_ON(!list_empty(&dp->fdbs)); in dsa_switch_release_ports()
1716 WARN_ON(!list_empty(&dp->mdbs)); in dsa_switch_release_ports()
1717 WARN_ON(!list_empty(&dp->vlans)); in dsa_switch_release_ports()
1718 list_del(&dp->list); in dsa_switch_release_ports()
1719 kfree(dp); in dsa_switch_release_ports()
1730 if (!ds->dev) in dsa_switch_probe()
1731 return -ENODEV; in dsa_switch_probe()
1733 pdata = ds->dev->platform_data; in dsa_switch_probe()
1734 np = ds->dev->of_node; in dsa_switch_probe()
1736 if (!ds->num_ports) in dsa_switch_probe()
1737 return -EINVAL; in dsa_switch_probe()
1748 err = -ENODEV; in dsa_switch_probe()
1754 dst = ds->dst; in dsa_switch_probe()
1771 dsa_tree_put(ds->dst); in dsa_register_switch()
1780 struct dsa_switch_tree *dst = ds->dst; in dsa_switch_remove()
1803 struct dsa_port *dp; in dsa_switch_shutdown() local
1807 if (!ds->setup) in dsa_switch_shutdown()
1812 dsa_switch_for_each_user_port(dp, ds) { in dsa_switch_shutdown()
1813 master = dsa_port_to_master(dp); in dsa_switch_shutdown()
1814 slave_dev = dp->slave; in dsa_switch_shutdown()
1822 dsa_switch_for_each_cpu_port(dp, ds) in dsa_switch_shutdown()
1823 dp->master->dsa_ptr = NULL; in dsa_switch_shutdown()