1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Handling of a single switch chip, part of a switch fabric
5 * Copyright (c) 2017 Savoir-faire Linux Inc.
9 #include <linux/if_bridge.h>
10 #include <linux/netdevice.h>
11 #include <linux/notifier.h>
12 #include <linux/if_vlan.h>
13 #include <net/switchdev.h>
20 #include "tag_8021q.h"
22 static unsigned int dsa_switch_fastest_ageing_time(struct dsa_switch *ds,
23 unsigned int ageing_time)
27 dsa_switch_for_each_port(dp, ds)
28 if (dp->ageing_time && dp->ageing_time < ageing_time)
29 ageing_time = dp->ageing_time;
34 static int dsa_switch_ageing_time(struct dsa_switch *ds,
35 struct dsa_notifier_ageing_time_info *info)
37 unsigned int ageing_time = info->ageing_time;
39 if (ds->ageing_time_min && ageing_time < ds->ageing_time_min)
42 if (ds->ageing_time_max && ageing_time > ds->ageing_time_max)
45 /* Program the fastest ageing time in case of multiple bridges */
46 ageing_time = dsa_switch_fastest_ageing_time(ds, ageing_time);
48 if (ds->ops->set_ageing_time)
49 return ds->ops->set_ageing_time(ds, ageing_time);
54 static bool dsa_port_mtu_match(struct dsa_port *dp,
55 struct dsa_notifier_mtu_info *info)
57 return dp == info->dp || dsa_port_is_dsa(dp) || dsa_port_is_cpu(dp);
60 static int dsa_switch_mtu(struct dsa_switch *ds,
61 struct dsa_notifier_mtu_info *info)
66 if (!ds->ops->port_change_mtu)
69 dsa_switch_for_each_port(dp, ds) {
70 if (dsa_port_mtu_match(dp, info)) {
71 ret = ds->ops->port_change_mtu(ds, dp->index,
81 static int dsa_switch_bridge_join(struct dsa_switch *ds,
82 struct dsa_notifier_bridge_info *info)
86 if (info->dp->ds == ds) {
87 if (!ds->ops->port_bridge_join)
90 err = ds->ops->port_bridge_join(ds, info->dp->index,
92 &info->tx_fwd_offload,
98 if (info->dp->ds != ds && ds->ops->crosschip_bridge_join) {
99 err = ds->ops->crosschip_bridge_join(ds,
100 info->dp->ds->dst->index,
112 static int dsa_switch_bridge_leave(struct dsa_switch *ds,
113 struct dsa_notifier_bridge_info *info)
115 if (info->dp->ds == ds && ds->ops->port_bridge_leave)
116 ds->ops->port_bridge_leave(ds, info->dp->index, info->bridge);
118 if (info->dp->ds != ds && ds->ops->crosschip_bridge_leave)
119 ds->ops->crosschip_bridge_leave(ds, info->dp->ds->dst->index,
127 /* Matches for all upstream-facing ports (the CPU port and all upstream-facing
128 * DSA links) that sit between the targeted port on which the notifier was
129 * emitted and its dedicated CPU port.
131 static bool dsa_port_host_address_match(struct dsa_port *dp,
132 const struct dsa_port *targeted_dp)
134 struct dsa_port *cpu_dp = targeted_dp->cpu_dp;
136 if (dsa_switch_is_upstream_of(dp->ds, targeted_dp->ds))
137 return dp->index == dsa_towards_port(dp->ds, cpu_dp->ds->index,
143 static struct dsa_mac_addr *dsa_mac_addr_find(struct list_head *addr_list,
144 const unsigned char *addr, u16 vid,
147 struct dsa_mac_addr *a;
149 list_for_each_entry(a, addr_list, list)
150 if (ether_addr_equal(a->addr, addr) && a->vid == vid &&
151 dsa_db_equal(&a->db, &db))
157 static int dsa_port_do_mdb_add(struct dsa_port *dp,
158 const struct switchdev_obj_port_mdb *mdb,
161 struct dsa_switch *ds = dp->ds;
162 struct dsa_mac_addr *a;
163 int port = dp->index;
166 /* No need to bother with refcounting for user ports */
167 if (!(dsa_port_is_cpu(dp) || dsa_port_is_dsa(dp)))
168 return ds->ops->port_mdb_add(ds, port, mdb, db);
170 mutex_lock(&dp->addr_lists_lock);
172 a = dsa_mac_addr_find(&dp->mdbs, mdb->addr, mdb->vid, db);
174 refcount_inc(&a->refcount);
178 a = kzalloc(sizeof(*a), GFP_KERNEL);
184 err = ds->ops->port_mdb_add(ds, port, mdb, db);
190 ether_addr_copy(a->addr, mdb->addr);
193 refcount_set(&a->refcount, 1);
194 list_add_tail(&a->list, &dp->mdbs);
197 mutex_unlock(&dp->addr_lists_lock);
202 static int dsa_port_do_mdb_del(struct dsa_port *dp,
203 const struct switchdev_obj_port_mdb *mdb,
206 struct dsa_switch *ds = dp->ds;
207 struct dsa_mac_addr *a;
208 int port = dp->index;
211 /* No need to bother with refcounting for user ports */
212 if (!(dsa_port_is_cpu(dp) || dsa_port_is_dsa(dp)))
213 return ds->ops->port_mdb_del(ds, port, mdb, db);
215 mutex_lock(&dp->addr_lists_lock);
217 a = dsa_mac_addr_find(&dp->mdbs, mdb->addr, mdb->vid, db);
223 if (!refcount_dec_and_test(&a->refcount))
226 err = ds->ops->port_mdb_del(ds, port, mdb, db);
228 refcount_set(&a->refcount, 1);
236 mutex_unlock(&dp->addr_lists_lock);
241 static int dsa_port_do_fdb_add(struct dsa_port *dp, const unsigned char *addr,
242 u16 vid, struct dsa_db db)
244 struct dsa_switch *ds = dp->ds;
245 struct dsa_mac_addr *a;
246 int port = dp->index;
249 /* No need to bother with refcounting for user ports */
250 if (!(dsa_port_is_cpu(dp) || dsa_port_is_dsa(dp)))
251 return ds->ops->port_fdb_add(ds, port, addr, vid, db);
253 mutex_lock(&dp->addr_lists_lock);
255 a = dsa_mac_addr_find(&dp->fdbs, addr, vid, db);
257 refcount_inc(&a->refcount);
261 a = kzalloc(sizeof(*a), GFP_KERNEL);
267 err = ds->ops->port_fdb_add(ds, port, addr, vid, db);
273 ether_addr_copy(a->addr, addr);
276 refcount_set(&a->refcount, 1);
277 list_add_tail(&a->list, &dp->fdbs);
280 mutex_unlock(&dp->addr_lists_lock);
285 static int dsa_port_do_fdb_del(struct dsa_port *dp, const unsigned char *addr,
286 u16 vid, struct dsa_db db)
288 struct dsa_switch *ds = dp->ds;
289 struct dsa_mac_addr *a;
290 int port = dp->index;
293 /* No need to bother with refcounting for user ports */
294 if (!(dsa_port_is_cpu(dp) || dsa_port_is_dsa(dp)))
295 return ds->ops->port_fdb_del(ds, port, addr, vid, db);
297 mutex_lock(&dp->addr_lists_lock);
299 a = dsa_mac_addr_find(&dp->fdbs, addr, vid, db);
305 if (!refcount_dec_and_test(&a->refcount))
308 err = ds->ops->port_fdb_del(ds, port, addr, vid, db);
310 refcount_set(&a->refcount, 1);
318 mutex_unlock(&dp->addr_lists_lock);
323 static int dsa_switch_do_lag_fdb_add(struct dsa_switch *ds, struct dsa_lag *lag,
324 const unsigned char *addr, u16 vid,
327 struct dsa_mac_addr *a;
330 mutex_lock(&lag->fdb_lock);
332 a = dsa_mac_addr_find(&lag->fdbs, addr, vid, db);
334 refcount_inc(&a->refcount);
338 a = kzalloc(sizeof(*a), GFP_KERNEL);
344 err = ds->ops->lag_fdb_add(ds, *lag, addr, vid, db);
350 ether_addr_copy(a->addr, addr);
353 refcount_set(&a->refcount, 1);
354 list_add_tail(&a->list, &lag->fdbs);
357 mutex_unlock(&lag->fdb_lock);
362 static int dsa_switch_do_lag_fdb_del(struct dsa_switch *ds, struct dsa_lag *lag,
363 const unsigned char *addr, u16 vid,
366 struct dsa_mac_addr *a;
369 mutex_lock(&lag->fdb_lock);
371 a = dsa_mac_addr_find(&lag->fdbs, addr, vid, db);
377 if (!refcount_dec_and_test(&a->refcount))
380 err = ds->ops->lag_fdb_del(ds, *lag, addr, vid, db);
382 refcount_set(&a->refcount, 1);
390 mutex_unlock(&lag->fdb_lock);
395 static int dsa_switch_host_fdb_add(struct dsa_switch *ds,
396 struct dsa_notifier_fdb_info *info)
401 if (!ds->ops->port_fdb_add)
404 dsa_switch_for_each_port(dp, ds) {
405 if (dsa_port_host_address_match(dp, info->dp)) {
406 if (dsa_port_is_cpu(dp) && info->dp->cpu_port_in_lag) {
407 err = dsa_switch_do_lag_fdb_add(ds, dp->lag,
412 err = dsa_port_do_fdb_add(dp, info->addr,
413 info->vid, info->db);
423 static int dsa_switch_host_fdb_del(struct dsa_switch *ds,
424 struct dsa_notifier_fdb_info *info)
429 if (!ds->ops->port_fdb_del)
432 dsa_switch_for_each_port(dp, ds) {
433 if (dsa_port_host_address_match(dp, info->dp)) {
434 if (dsa_port_is_cpu(dp) && info->dp->cpu_port_in_lag) {
435 err = dsa_switch_do_lag_fdb_del(ds, dp->lag,
440 err = dsa_port_do_fdb_del(dp, info->addr,
441 info->vid, info->db);
451 static int dsa_switch_fdb_add(struct dsa_switch *ds,
452 struct dsa_notifier_fdb_info *info)
454 int port = dsa_towards_port(ds, info->dp->ds->index, info->dp->index);
455 struct dsa_port *dp = dsa_to_port(ds, port);
457 if (!ds->ops->port_fdb_add)
460 return dsa_port_do_fdb_add(dp, info->addr, info->vid, info->db);
463 static int dsa_switch_fdb_del(struct dsa_switch *ds,
464 struct dsa_notifier_fdb_info *info)
466 int port = dsa_towards_port(ds, info->dp->ds->index, info->dp->index);
467 struct dsa_port *dp = dsa_to_port(ds, port);
469 if (!ds->ops->port_fdb_del)
472 return dsa_port_do_fdb_del(dp, info->addr, info->vid, info->db);
475 static int dsa_switch_lag_fdb_add(struct dsa_switch *ds,
476 struct dsa_notifier_lag_fdb_info *info)
480 if (!ds->ops->lag_fdb_add)
483 /* Notify switch only if it has a port in this LAG */
484 dsa_switch_for_each_port(dp, ds)
485 if (dsa_port_offloads_lag(dp, info->lag))
486 return dsa_switch_do_lag_fdb_add(ds, info->lag,
487 info->addr, info->vid,
493 static int dsa_switch_lag_fdb_del(struct dsa_switch *ds,
494 struct dsa_notifier_lag_fdb_info *info)
498 if (!ds->ops->lag_fdb_del)
501 /* Notify switch only if it has a port in this LAG */
502 dsa_switch_for_each_port(dp, ds)
503 if (dsa_port_offloads_lag(dp, info->lag))
504 return dsa_switch_do_lag_fdb_del(ds, info->lag,
505 info->addr, info->vid,
511 static int dsa_switch_lag_change(struct dsa_switch *ds,
512 struct dsa_notifier_lag_info *info)
514 if (info->dp->ds == ds && ds->ops->port_lag_change)
515 return ds->ops->port_lag_change(ds, info->dp->index);
517 if (info->dp->ds != ds && ds->ops->crosschip_lag_change)
518 return ds->ops->crosschip_lag_change(ds, info->dp->ds->index,
524 static int dsa_switch_lag_join(struct dsa_switch *ds,
525 struct dsa_notifier_lag_info *info)
527 if (info->dp->ds == ds && ds->ops->port_lag_join)
528 return ds->ops->port_lag_join(ds, info->dp->index, info->lag,
529 info->info, info->extack);
531 if (info->dp->ds != ds && ds->ops->crosschip_lag_join)
532 return ds->ops->crosschip_lag_join(ds, info->dp->ds->index,
533 info->dp->index, info->lag,
534 info->info, info->extack);
539 static int dsa_switch_lag_leave(struct dsa_switch *ds,
540 struct dsa_notifier_lag_info *info)
542 if (info->dp->ds == ds && ds->ops->port_lag_leave)
543 return ds->ops->port_lag_leave(ds, info->dp->index, info->lag);
545 if (info->dp->ds != ds && ds->ops->crosschip_lag_leave)
546 return ds->ops->crosschip_lag_leave(ds, info->dp->ds->index,
547 info->dp->index, info->lag);
552 static int dsa_switch_mdb_add(struct dsa_switch *ds,
553 struct dsa_notifier_mdb_info *info)
555 int port = dsa_towards_port(ds, info->dp->ds->index, info->dp->index);
556 struct dsa_port *dp = dsa_to_port(ds, port);
558 if (!ds->ops->port_mdb_add)
561 return dsa_port_do_mdb_add(dp, info->mdb, info->db);
564 static int dsa_switch_mdb_del(struct dsa_switch *ds,
565 struct dsa_notifier_mdb_info *info)
567 int port = dsa_towards_port(ds, info->dp->ds->index, info->dp->index);
568 struct dsa_port *dp = dsa_to_port(ds, port);
570 if (!ds->ops->port_mdb_del)
573 return dsa_port_do_mdb_del(dp, info->mdb, info->db);
576 static int dsa_switch_host_mdb_add(struct dsa_switch *ds,
577 struct dsa_notifier_mdb_info *info)
582 if (!ds->ops->port_mdb_add)
585 dsa_switch_for_each_port(dp, ds) {
586 if (dsa_port_host_address_match(dp, info->dp)) {
587 err = dsa_port_do_mdb_add(dp, info->mdb, info->db);
596 static int dsa_switch_host_mdb_del(struct dsa_switch *ds,
597 struct dsa_notifier_mdb_info *info)
602 if (!ds->ops->port_mdb_del)
605 dsa_switch_for_each_port(dp, ds) {
606 if (dsa_port_host_address_match(dp, info->dp)) {
607 err = dsa_port_do_mdb_del(dp, info->mdb, info->db);
616 /* Port VLANs match on the targeted port and on all DSA ports */
617 static bool dsa_port_vlan_match(struct dsa_port *dp,
618 struct dsa_notifier_vlan_info *info)
620 return dsa_port_is_dsa(dp) || dp == info->dp;
623 /* Host VLANs match on the targeted port's CPU port, and on all DSA ports
624 * (upstream and downstream) of that switch and its upstream switches.
626 static bool dsa_port_host_vlan_match(struct dsa_port *dp,
627 const struct dsa_port *targeted_dp)
629 struct dsa_port *cpu_dp = targeted_dp->cpu_dp;
631 if (dsa_switch_is_upstream_of(dp->ds, targeted_dp->ds))
632 return dsa_port_is_dsa(dp) || dp == cpu_dp;
637 static struct dsa_vlan *dsa_vlan_find(struct list_head *vlan_list,
638 const struct switchdev_obj_port_vlan *vlan)
642 list_for_each_entry(v, vlan_list, list)
643 if (v->vid == vlan->vid)
649 static int dsa_port_do_vlan_add(struct dsa_port *dp,
650 const struct switchdev_obj_port_vlan *vlan,
651 struct netlink_ext_ack *extack)
653 struct dsa_switch *ds = dp->ds;
654 int port = dp->index;
658 /* No need to bother with refcounting for user ports. */
659 if (!(dsa_port_is_cpu(dp) || dsa_port_is_dsa(dp)))
660 return ds->ops->port_vlan_add(ds, port, vlan, extack);
662 /* No need to propagate on shared ports the existing VLANs that were
663 * re-notified after just the flags have changed. This would cause a
664 * refcount bump which we need to avoid, since it unbalances the
665 * additions with the deletions.
670 mutex_lock(&dp->vlans_lock);
672 v = dsa_vlan_find(&dp->vlans, vlan);
674 refcount_inc(&v->refcount);
678 v = kzalloc(sizeof(*v), GFP_KERNEL);
684 err = ds->ops->port_vlan_add(ds, port, vlan, extack);
691 refcount_set(&v->refcount, 1);
692 list_add_tail(&v->list, &dp->vlans);
695 mutex_unlock(&dp->vlans_lock);
700 static int dsa_port_do_vlan_del(struct dsa_port *dp,
701 const struct switchdev_obj_port_vlan *vlan)
703 struct dsa_switch *ds = dp->ds;
704 int port = dp->index;
708 /* No need to bother with refcounting for user ports */
709 if (!(dsa_port_is_cpu(dp) || dsa_port_is_dsa(dp)))
710 return ds->ops->port_vlan_del(ds, port, vlan);
712 mutex_lock(&dp->vlans_lock);
714 v = dsa_vlan_find(&dp->vlans, vlan);
720 if (!refcount_dec_and_test(&v->refcount))
723 err = ds->ops->port_vlan_del(ds, port, vlan);
725 refcount_set(&v->refcount, 1);
733 mutex_unlock(&dp->vlans_lock);
738 static int dsa_switch_vlan_add(struct dsa_switch *ds,
739 struct dsa_notifier_vlan_info *info)
744 if (!ds->ops->port_vlan_add)
747 dsa_switch_for_each_port(dp, ds) {
748 if (dsa_port_vlan_match(dp, info)) {
749 err = dsa_port_do_vlan_add(dp, info->vlan,
759 static int dsa_switch_vlan_del(struct dsa_switch *ds,
760 struct dsa_notifier_vlan_info *info)
765 if (!ds->ops->port_vlan_del)
768 dsa_switch_for_each_port(dp, ds) {
769 if (dsa_port_vlan_match(dp, info)) {
770 err = dsa_port_do_vlan_del(dp, info->vlan);
779 static int dsa_switch_host_vlan_add(struct dsa_switch *ds,
780 struct dsa_notifier_vlan_info *info)
785 if (!ds->ops->port_vlan_add)
788 dsa_switch_for_each_port(dp, ds) {
789 if (dsa_port_host_vlan_match(dp, info->dp)) {
790 err = dsa_port_do_vlan_add(dp, info->vlan,
800 static int dsa_switch_host_vlan_del(struct dsa_switch *ds,
801 struct dsa_notifier_vlan_info *info)
806 if (!ds->ops->port_vlan_del)
809 dsa_switch_for_each_port(dp, ds) {
810 if (dsa_port_host_vlan_match(dp, info->dp)) {
811 err = dsa_port_do_vlan_del(dp, info->vlan);
820 static int dsa_switch_change_tag_proto(struct dsa_switch *ds,
821 struct dsa_notifier_tag_proto_info *info)
823 const struct dsa_device_ops *tag_ops = info->tag_ops;
824 struct dsa_port *dp, *cpu_dp;
827 if (!ds->ops->change_tag_protocol)
832 err = ds->ops->change_tag_protocol(ds, tag_ops->proto);
836 dsa_switch_for_each_cpu_port(cpu_dp, ds)
837 dsa_port_set_tag_protocol(cpu_dp, tag_ops);
839 /* Now that changing the tag protocol can no longer fail, let's update
840 * the remaining bits which are "duplicated for faster access", and the
841 * bits that depend on the tagger, such as the MTU.
843 dsa_switch_for_each_user_port(dp, ds) {
844 struct net_device *slave = dp->slave;
846 dsa_slave_setup_tagger(slave);
848 /* rtnl_mutex is held in dsa_tree_change_tag_proto */
849 dsa_slave_change_mtu(slave, slave->mtu);
855 /* We use the same cross-chip notifiers to inform both the tagger side, as well
856 * as the switch side, of connection and disconnection events.
857 * Since ds->tagger_data is owned by the tagger, it isn't a hard error if the
858 * switch side doesn't support connecting to this tagger, and therefore, the
859 * fact that we don't disconnect the tagger side doesn't constitute a memory
860 * leak: the tagger will still operate with persistent per-switch memory, just
861 * with the switch side unconnected to it. What does constitute a hard error is
862 * when the switch side supports connecting but fails.
865 dsa_switch_connect_tag_proto(struct dsa_switch *ds,
866 struct dsa_notifier_tag_proto_info *info)
868 const struct dsa_device_ops *tag_ops = info->tag_ops;
871 /* Notify the new tagger about the connection to this switch */
872 if (tag_ops->connect) {
873 err = tag_ops->connect(ds);
878 if (!ds->ops->connect_tag_protocol)
881 /* Notify the switch about the connection to the new tagger */
882 err = ds->ops->connect_tag_protocol(ds, tag_ops->proto);
884 /* Revert the new tagger's connection to this tree */
885 if (tag_ops->disconnect)
886 tag_ops->disconnect(ds);
894 dsa_switch_disconnect_tag_proto(struct dsa_switch *ds,
895 struct dsa_notifier_tag_proto_info *info)
897 const struct dsa_device_ops *tag_ops = info->tag_ops;
899 /* Notify the tagger about the disconnection from this switch */
900 if (tag_ops->disconnect && ds->tagger_data)
901 tag_ops->disconnect(ds);
903 /* No need to notify the switch, since it shouldn't have any
904 * resources to tear down
910 dsa_switch_master_state_change(struct dsa_switch *ds,
911 struct dsa_notifier_master_state_info *info)
913 if (!ds->ops->master_state_change)
916 ds->ops->master_state_change(ds, info->master, info->operational);
921 static int dsa_switch_event(struct notifier_block *nb,
922 unsigned long event, void *info)
924 struct dsa_switch *ds = container_of(nb, struct dsa_switch, nb);
928 case DSA_NOTIFIER_AGEING_TIME:
929 err = dsa_switch_ageing_time(ds, info);
931 case DSA_NOTIFIER_BRIDGE_JOIN:
932 err = dsa_switch_bridge_join(ds, info);
934 case DSA_NOTIFIER_BRIDGE_LEAVE:
935 err = dsa_switch_bridge_leave(ds, info);
937 case DSA_NOTIFIER_FDB_ADD:
938 err = dsa_switch_fdb_add(ds, info);
940 case DSA_NOTIFIER_FDB_DEL:
941 err = dsa_switch_fdb_del(ds, info);
943 case DSA_NOTIFIER_HOST_FDB_ADD:
944 err = dsa_switch_host_fdb_add(ds, info);
946 case DSA_NOTIFIER_HOST_FDB_DEL:
947 err = dsa_switch_host_fdb_del(ds, info);
949 case DSA_NOTIFIER_LAG_FDB_ADD:
950 err = dsa_switch_lag_fdb_add(ds, info);
952 case DSA_NOTIFIER_LAG_FDB_DEL:
953 err = dsa_switch_lag_fdb_del(ds, info);
955 case DSA_NOTIFIER_LAG_CHANGE:
956 err = dsa_switch_lag_change(ds, info);
958 case DSA_NOTIFIER_LAG_JOIN:
959 err = dsa_switch_lag_join(ds, info);
961 case DSA_NOTIFIER_LAG_LEAVE:
962 err = dsa_switch_lag_leave(ds, info);
964 case DSA_NOTIFIER_MDB_ADD:
965 err = dsa_switch_mdb_add(ds, info);
967 case DSA_NOTIFIER_MDB_DEL:
968 err = dsa_switch_mdb_del(ds, info);
970 case DSA_NOTIFIER_HOST_MDB_ADD:
971 err = dsa_switch_host_mdb_add(ds, info);
973 case DSA_NOTIFIER_HOST_MDB_DEL:
974 err = dsa_switch_host_mdb_del(ds, info);
976 case DSA_NOTIFIER_VLAN_ADD:
977 err = dsa_switch_vlan_add(ds, info);
979 case DSA_NOTIFIER_VLAN_DEL:
980 err = dsa_switch_vlan_del(ds, info);
982 case DSA_NOTIFIER_HOST_VLAN_ADD:
983 err = dsa_switch_host_vlan_add(ds, info);
985 case DSA_NOTIFIER_HOST_VLAN_DEL:
986 err = dsa_switch_host_vlan_del(ds, info);
988 case DSA_NOTIFIER_MTU:
989 err = dsa_switch_mtu(ds, info);
991 case DSA_NOTIFIER_TAG_PROTO:
992 err = dsa_switch_change_tag_proto(ds, info);
994 case DSA_NOTIFIER_TAG_PROTO_CONNECT:
995 err = dsa_switch_connect_tag_proto(ds, info);
997 case DSA_NOTIFIER_TAG_PROTO_DISCONNECT:
998 err = dsa_switch_disconnect_tag_proto(ds, info);
1000 case DSA_NOTIFIER_TAG_8021Q_VLAN_ADD:
1001 err = dsa_switch_tag_8021q_vlan_add(ds, info);
1003 case DSA_NOTIFIER_TAG_8021Q_VLAN_DEL:
1004 err = dsa_switch_tag_8021q_vlan_del(ds, info);
1006 case DSA_NOTIFIER_MASTER_STATE_CHANGE:
1007 err = dsa_switch_master_state_change(ds, info);
1015 dev_dbg(ds->dev, "breaking chain for DSA event %lu (%d)\n",
1018 return notifier_from_errno(err);
1022 * dsa_tree_notify - Execute code for all switches in a DSA switch tree.
1023 * @dst: collection of struct dsa_switch devices to notify.
1024 * @e: event, must be of type DSA_NOTIFIER_*
1025 * @v: event-specific value.
1027 * Given a struct dsa_switch_tree, this can be used to run a function once for
1028 * each member DSA switch. The other alternative of traversing the tree is only
1029 * through its ports list, which does not uniquely list the switches.
1031 int dsa_tree_notify(struct dsa_switch_tree *dst, unsigned long e, void *v)
1033 struct raw_notifier_head *nh = &dst->nh;
1036 err = raw_notifier_call_chain(nh, e, v);
1038 return notifier_to_errno(err);
1042 * dsa_broadcast - Notify all DSA trees in the system.
1043 * @e: event, must be of type DSA_NOTIFIER_*
1044 * @v: event-specific value.
1046 * Can be used to notify the switching fabric of events such as cross-chip
1047 * bridging between disjoint trees (such as islands of tagger-compatible
1048 * switches bridged by an incompatible middle switch).
1050 * WARNING: this function is not reliable during probe time, because probing
1051 * between trees is asynchronous and not all DSA trees might have probed.
1053 int dsa_broadcast(unsigned long e, void *v)
1055 struct dsa_switch_tree *dst;
1058 list_for_each_entry(dst, &dsa_tree_list, list) {
1059 err = dsa_tree_notify(dst, e, v);
1067 int dsa_switch_register_notifier(struct dsa_switch *ds)
1069 ds->nb.notifier_call = dsa_switch_event;
1071 return raw_notifier_chain_register(&ds->dst->nh, &ds->nb);
1074 void dsa_switch_unregister_notifier(struct dsa_switch *ds)
1078 err = raw_notifier_chain_unregister(&ds->dst->nh, &ds->nb);
1080 dev_err(ds->dev, "failed to unregister notifier (%d)\n", err);