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.
6 * Vivien Didelot <vivien.didelot@savoirfairelinux.com>
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"
23 static unsigned int dsa_switch_fastest_ageing_time(struct dsa_switch *ds,
24 unsigned int ageing_time)
28 dsa_switch_for_each_port(dp, ds)
29 if (dp->ageing_time && dp->ageing_time < ageing_time)
30 ageing_time = dp->ageing_time;
35 static int dsa_switch_ageing_time(struct dsa_switch *ds,
36 struct dsa_notifier_ageing_time_info *info)
38 unsigned int ageing_time = info->ageing_time;
40 if (ds->ageing_time_min && ageing_time < ds->ageing_time_min)
43 if (ds->ageing_time_max && ageing_time > ds->ageing_time_max)
46 /* Program the fastest ageing time in case of multiple bridges */
47 ageing_time = dsa_switch_fastest_ageing_time(ds, ageing_time);
49 if (ds->ops->set_ageing_time)
50 return ds->ops->set_ageing_time(ds, ageing_time);
55 static bool dsa_port_mtu_match(struct dsa_port *dp,
56 struct dsa_notifier_mtu_info *info)
58 return dp == info->dp || dsa_port_is_dsa(dp) || dsa_port_is_cpu(dp);
61 static int dsa_switch_mtu(struct dsa_switch *ds,
62 struct dsa_notifier_mtu_info *info)
67 if (!ds->ops->port_change_mtu)
70 dsa_switch_for_each_port(dp, ds) {
71 if (dsa_port_mtu_match(dp, info)) {
72 ret = ds->ops->port_change_mtu(ds, dp->index,
82 static int dsa_switch_bridge_join(struct dsa_switch *ds,
83 struct dsa_notifier_bridge_info *info)
87 if (info->dp->ds == ds) {
88 if (!ds->ops->port_bridge_join)
91 err = ds->ops->port_bridge_join(ds, info->dp->index,
93 &info->tx_fwd_offload,
99 if (info->dp->ds != ds && ds->ops->crosschip_bridge_join) {
100 err = ds->ops->crosschip_bridge_join(ds,
101 info->dp->ds->dst->index,
113 static int dsa_switch_bridge_leave(struct dsa_switch *ds,
114 struct dsa_notifier_bridge_info *info)
116 if (info->dp->ds == ds && ds->ops->port_bridge_leave)
117 ds->ops->port_bridge_leave(ds, info->dp->index, info->bridge);
119 if (info->dp->ds != ds && ds->ops->crosschip_bridge_leave)
120 ds->ops->crosschip_bridge_leave(ds, info->dp->ds->dst->index,
128 /* Matches for all upstream-facing ports (the CPU port and all upstream-facing
129 * DSA links) that sit between the targeted port on which the notifier was
130 * emitted and its dedicated CPU port.
132 static bool dsa_port_host_address_match(struct dsa_port *dp,
133 const struct dsa_port *targeted_dp)
135 struct dsa_port *cpu_dp = targeted_dp->cpu_dp;
137 if (dsa_switch_is_upstream_of(dp->ds, targeted_dp->ds))
138 return dp->index == dsa_towards_port(dp->ds, cpu_dp->ds->index,
144 static struct dsa_mac_addr *dsa_mac_addr_find(struct list_head *addr_list,
145 const unsigned char *addr, u16 vid,
148 struct dsa_mac_addr *a;
150 list_for_each_entry(a, addr_list, list)
151 if (ether_addr_equal(a->addr, addr) && a->vid == vid &&
152 dsa_db_equal(&a->db, &db))
158 static int dsa_port_do_mdb_add(struct dsa_port *dp,
159 const struct switchdev_obj_port_mdb *mdb,
162 struct dsa_switch *ds = dp->ds;
163 struct dsa_mac_addr *a;
164 int port = dp->index;
167 /* No need to bother with refcounting for user ports */
168 if (!(dsa_port_is_cpu(dp) || dsa_port_is_dsa(dp))) {
169 err = ds->ops->port_mdb_add(ds, port, mdb, db);
170 trace_dsa_mdb_add_hw(dp, mdb->addr, mdb->vid, &db, err);
175 mutex_lock(&dp->addr_lists_lock);
177 a = dsa_mac_addr_find(&dp->mdbs, mdb->addr, mdb->vid, db);
179 refcount_inc(&a->refcount);
180 trace_dsa_mdb_add_bump(dp, mdb->addr, mdb->vid, &db,
185 a = kzalloc(sizeof(*a), GFP_KERNEL);
191 err = ds->ops->port_mdb_add(ds, port, mdb, db);
192 trace_dsa_mdb_add_hw(dp, mdb->addr, mdb->vid, &db, err);
198 ether_addr_copy(a->addr, mdb->addr);
201 refcount_set(&a->refcount, 1);
202 list_add_tail(&a->list, &dp->mdbs);
205 mutex_unlock(&dp->addr_lists_lock);
210 static int dsa_port_do_mdb_del(struct dsa_port *dp,
211 const struct switchdev_obj_port_mdb *mdb,
214 struct dsa_switch *ds = dp->ds;
215 struct dsa_mac_addr *a;
216 int port = dp->index;
219 /* No need to bother with refcounting for user ports */
220 if (!(dsa_port_is_cpu(dp) || dsa_port_is_dsa(dp))) {
221 err = ds->ops->port_mdb_del(ds, port, mdb, db);
222 trace_dsa_mdb_del_hw(dp, mdb->addr, mdb->vid, &db, err);
227 mutex_lock(&dp->addr_lists_lock);
229 a = dsa_mac_addr_find(&dp->mdbs, mdb->addr, mdb->vid, db);
231 trace_dsa_mdb_del_not_found(dp, mdb->addr, mdb->vid, &db);
236 if (!refcount_dec_and_test(&a->refcount)) {
237 trace_dsa_mdb_del_drop(dp, mdb->addr, mdb->vid, &db,
242 err = ds->ops->port_mdb_del(ds, port, mdb, db);
243 trace_dsa_mdb_del_hw(dp, mdb->addr, mdb->vid, &db, err);
245 refcount_set(&a->refcount, 1);
253 mutex_unlock(&dp->addr_lists_lock);
258 static int dsa_port_do_fdb_add(struct dsa_port *dp, const unsigned char *addr,
259 u16 vid, struct dsa_db db)
261 struct dsa_switch *ds = dp->ds;
262 struct dsa_mac_addr *a;
263 int port = dp->index;
266 /* No need to bother with refcounting for user ports */
267 if (!(dsa_port_is_cpu(dp) || dsa_port_is_dsa(dp))) {
268 err = ds->ops->port_fdb_add(ds, port, addr, vid, db);
269 trace_dsa_fdb_add_hw(dp, addr, vid, &db, err);
274 mutex_lock(&dp->addr_lists_lock);
276 a = dsa_mac_addr_find(&dp->fdbs, addr, vid, db);
278 refcount_inc(&a->refcount);
279 trace_dsa_fdb_add_bump(dp, addr, vid, &db, &a->refcount);
283 a = kzalloc(sizeof(*a), GFP_KERNEL);
289 err = ds->ops->port_fdb_add(ds, port, addr, vid, db);
290 trace_dsa_fdb_add_hw(dp, addr, vid, &db, err);
296 ether_addr_copy(a->addr, addr);
299 refcount_set(&a->refcount, 1);
300 list_add_tail(&a->list, &dp->fdbs);
303 mutex_unlock(&dp->addr_lists_lock);
308 static int dsa_port_do_fdb_del(struct dsa_port *dp, const unsigned char *addr,
309 u16 vid, struct dsa_db db)
311 struct dsa_switch *ds = dp->ds;
312 struct dsa_mac_addr *a;
313 int port = dp->index;
316 /* No need to bother with refcounting for user ports */
317 if (!(dsa_port_is_cpu(dp) || dsa_port_is_dsa(dp))) {
318 err = ds->ops->port_fdb_del(ds, port, addr, vid, db);
319 trace_dsa_fdb_del_hw(dp, addr, vid, &db, err);
324 mutex_lock(&dp->addr_lists_lock);
326 a = dsa_mac_addr_find(&dp->fdbs, addr, vid, db);
328 trace_dsa_fdb_del_not_found(dp, addr, vid, &db);
333 if (!refcount_dec_and_test(&a->refcount)) {
334 trace_dsa_fdb_del_drop(dp, addr, vid, &db, &a->refcount);
338 err = ds->ops->port_fdb_del(ds, port, addr, vid, db);
339 trace_dsa_fdb_del_hw(dp, addr, vid, &db, err);
341 refcount_set(&a->refcount, 1);
349 mutex_unlock(&dp->addr_lists_lock);
354 static int dsa_switch_do_lag_fdb_add(struct dsa_switch *ds, struct dsa_lag *lag,
355 const unsigned char *addr, u16 vid,
358 struct dsa_mac_addr *a;
361 mutex_lock(&lag->fdb_lock);
363 a = dsa_mac_addr_find(&lag->fdbs, addr, vid, db);
365 refcount_inc(&a->refcount);
366 trace_dsa_lag_fdb_add_bump(lag->dev, addr, vid, &db,
371 a = kzalloc(sizeof(*a), GFP_KERNEL);
377 err = ds->ops->lag_fdb_add(ds, *lag, addr, vid, db);
378 trace_dsa_lag_fdb_add_hw(lag->dev, addr, vid, &db, err);
384 ether_addr_copy(a->addr, addr);
387 refcount_set(&a->refcount, 1);
388 list_add_tail(&a->list, &lag->fdbs);
391 mutex_unlock(&lag->fdb_lock);
396 static int dsa_switch_do_lag_fdb_del(struct dsa_switch *ds, struct dsa_lag *lag,
397 const unsigned char *addr, u16 vid,
400 struct dsa_mac_addr *a;
403 mutex_lock(&lag->fdb_lock);
405 a = dsa_mac_addr_find(&lag->fdbs, addr, vid, db);
407 trace_dsa_lag_fdb_del_not_found(lag->dev, addr, vid, &db);
412 if (!refcount_dec_and_test(&a->refcount)) {
413 trace_dsa_lag_fdb_del_drop(lag->dev, addr, vid, &db,
418 err = ds->ops->lag_fdb_del(ds, *lag, addr, vid, db);
419 trace_dsa_lag_fdb_del_hw(lag->dev, addr, vid, &db, err);
421 refcount_set(&a->refcount, 1);
429 mutex_unlock(&lag->fdb_lock);
434 static int dsa_switch_host_fdb_add(struct dsa_switch *ds,
435 struct dsa_notifier_fdb_info *info)
440 if (!ds->ops->port_fdb_add)
443 dsa_switch_for_each_port(dp, ds) {
444 if (dsa_port_host_address_match(dp, info->dp)) {
445 if (dsa_port_is_cpu(dp) && info->dp->cpu_port_in_lag) {
446 err = dsa_switch_do_lag_fdb_add(ds, dp->lag,
451 err = dsa_port_do_fdb_add(dp, info->addr,
452 info->vid, info->db);
462 static int dsa_switch_host_fdb_del(struct dsa_switch *ds,
463 struct dsa_notifier_fdb_info *info)
468 if (!ds->ops->port_fdb_del)
471 dsa_switch_for_each_port(dp, ds) {
472 if (dsa_port_host_address_match(dp, info->dp)) {
473 if (dsa_port_is_cpu(dp) && info->dp->cpu_port_in_lag) {
474 err = dsa_switch_do_lag_fdb_del(ds, dp->lag,
479 err = dsa_port_do_fdb_del(dp, info->addr,
480 info->vid, info->db);
490 static int dsa_switch_fdb_add(struct dsa_switch *ds,
491 struct dsa_notifier_fdb_info *info)
493 int port = dsa_towards_port(ds, info->dp->ds->index, info->dp->index);
494 struct dsa_port *dp = dsa_to_port(ds, port);
496 if (!ds->ops->port_fdb_add)
499 return dsa_port_do_fdb_add(dp, info->addr, info->vid, info->db);
502 static int dsa_switch_fdb_del(struct dsa_switch *ds,
503 struct dsa_notifier_fdb_info *info)
505 int port = dsa_towards_port(ds, info->dp->ds->index, info->dp->index);
506 struct dsa_port *dp = dsa_to_port(ds, port);
508 if (!ds->ops->port_fdb_del)
511 return dsa_port_do_fdb_del(dp, info->addr, info->vid, info->db);
514 static int dsa_switch_lag_fdb_add(struct dsa_switch *ds,
515 struct dsa_notifier_lag_fdb_info *info)
519 if (!ds->ops->lag_fdb_add)
522 /* Notify switch only if it has a port in this LAG */
523 dsa_switch_for_each_port(dp, ds)
524 if (dsa_port_offloads_lag(dp, info->lag))
525 return dsa_switch_do_lag_fdb_add(ds, info->lag,
526 info->addr, info->vid,
532 static int dsa_switch_lag_fdb_del(struct dsa_switch *ds,
533 struct dsa_notifier_lag_fdb_info *info)
537 if (!ds->ops->lag_fdb_del)
540 /* Notify switch only if it has a port in this LAG */
541 dsa_switch_for_each_port(dp, ds)
542 if (dsa_port_offloads_lag(dp, info->lag))
543 return dsa_switch_do_lag_fdb_del(ds, info->lag,
544 info->addr, info->vid,
550 static int dsa_switch_lag_change(struct dsa_switch *ds,
551 struct dsa_notifier_lag_info *info)
553 if (info->dp->ds == ds && ds->ops->port_lag_change)
554 return ds->ops->port_lag_change(ds, info->dp->index);
556 if (info->dp->ds != ds && ds->ops->crosschip_lag_change)
557 return ds->ops->crosschip_lag_change(ds, info->dp->ds->index,
563 static int dsa_switch_lag_join(struct dsa_switch *ds,
564 struct dsa_notifier_lag_info *info)
566 if (info->dp->ds == ds && ds->ops->port_lag_join)
567 return ds->ops->port_lag_join(ds, info->dp->index, info->lag,
568 info->info, info->extack);
570 if (info->dp->ds != ds && ds->ops->crosschip_lag_join)
571 return ds->ops->crosschip_lag_join(ds, info->dp->ds->index,
572 info->dp->index, info->lag,
573 info->info, info->extack);
578 static int dsa_switch_lag_leave(struct dsa_switch *ds,
579 struct dsa_notifier_lag_info *info)
581 if (info->dp->ds == ds && ds->ops->port_lag_leave)
582 return ds->ops->port_lag_leave(ds, info->dp->index, info->lag);
584 if (info->dp->ds != ds && ds->ops->crosschip_lag_leave)
585 return ds->ops->crosschip_lag_leave(ds, info->dp->ds->index,
586 info->dp->index, info->lag);
591 static int dsa_switch_mdb_add(struct dsa_switch *ds,
592 struct dsa_notifier_mdb_info *info)
594 int port = dsa_towards_port(ds, info->dp->ds->index, info->dp->index);
595 struct dsa_port *dp = dsa_to_port(ds, port);
597 if (!ds->ops->port_mdb_add)
600 return dsa_port_do_mdb_add(dp, info->mdb, info->db);
603 static int dsa_switch_mdb_del(struct dsa_switch *ds,
604 struct dsa_notifier_mdb_info *info)
606 int port = dsa_towards_port(ds, info->dp->ds->index, info->dp->index);
607 struct dsa_port *dp = dsa_to_port(ds, port);
609 if (!ds->ops->port_mdb_del)
612 return dsa_port_do_mdb_del(dp, info->mdb, info->db);
615 static int dsa_switch_host_mdb_add(struct dsa_switch *ds,
616 struct dsa_notifier_mdb_info *info)
621 if (!ds->ops->port_mdb_add)
624 dsa_switch_for_each_port(dp, ds) {
625 if (dsa_port_host_address_match(dp, info->dp)) {
626 err = dsa_port_do_mdb_add(dp, info->mdb, info->db);
635 static int dsa_switch_host_mdb_del(struct dsa_switch *ds,
636 struct dsa_notifier_mdb_info *info)
641 if (!ds->ops->port_mdb_del)
644 dsa_switch_for_each_port(dp, ds) {
645 if (dsa_port_host_address_match(dp, info->dp)) {
646 err = dsa_port_do_mdb_del(dp, info->mdb, info->db);
655 /* Port VLANs match on the targeted port and on all DSA ports */
656 static bool dsa_port_vlan_match(struct dsa_port *dp,
657 struct dsa_notifier_vlan_info *info)
659 return dsa_port_is_dsa(dp) || dp == info->dp;
662 /* Host VLANs match on the targeted port's CPU port, and on all DSA ports
663 * (upstream and downstream) of that switch and its upstream switches.
665 static bool dsa_port_host_vlan_match(struct dsa_port *dp,
666 const struct dsa_port *targeted_dp)
668 struct dsa_port *cpu_dp = targeted_dp->cpu_dp;
670 if (dsa_switch_is_upstream_of(dp->ds, targeted_dp->ds))
671 return dsa_port_is_dsa(dp) || dp == cpu_dp;
676 static struct dsa_vlan *dsa_vlan_find(struct list_head *vlan_list,
677 const struct switchdev_obj_port_vlan *vlan)
681 list_for_each_entry(v, vlan_list, list)
682 if (v->vid == vlan->vid)
688 static int dsa_port_do_vlan_add(struct dsa_port *dp,
689 const struct switchdev_obj_port_vlan *vlan,
690 struct netlink_ext_ack *extack)
692 struct dsa_switch *ds = dp->ds;
693 int port = dp->index;
697 /* No need to bother with refcounting for user ports. */
698 if (!(dsa_port_is_cpu(dp) || dsa_port_is_dsa(dp))) {
699 err = ds->ops->port_vlan_add(ds, port, vlan, extack);
700 trace_dsa_vlan_add_hw(dp, vlan, err);
705 /* No need to propagate on shared ports the existing VLANs that were
706 * re-notified after just the flags have changed. This would cause a
707 * refcount bump which we need to avoid, since it unbalances the
708 * additions with the deletions.
713 mutex_lock(&dp->vlans_lock);
715 v = dsa_vlan_find(&dp->vlans, vlan);
717 refcount_inc(&v->refcount);
718 trace_dsa_vlan_add_bump(dp, vlan, &v->refcount);
722 v = kzalloc(sizeof(*v), GFP_KERNEL);
728 err = ds->ops->port_vlan_add(ds, port, vlan, extack);
729 trace_dsa_vlan_add_hw(dp, vlan, err);
736 refcount_set(&v->refcount, 1);
737 list_add_tail(&v->list, &dp->vlans);
740 mutex_unlock(&dp->vlans_lock);
745 static int dsa_port_do_vlan_del(struct dsa_port *dp,
746 const struct switchdev_obj_port_vlan *vlan)
748 struct dsa_switch *ds = dp->ds;
749 int port = dp->index;
753 /* No need to bother with refcounting for user ports */
754 if (!(dsa_port_is_cpu(dp) || dsa_port_is_dsa(dp))) {
755 err = ds->ops->port_vlan_del(ds, port, vlan);
756 trace_dsa_vlan_del_hw(dp, vlan, err);
761 mutex_lock(&dp->vlans_lock);
763 v = dsa_vlan_find(&dp->vlans, vlan);
765 trace_dsa_vlan_del_not_found(dp, vlan);
770 if (!refcount_dec_and_test(&v->refcount)) {
771 trace_dsa_vlan_del_drop(dp, vlan, &v->refcount);
775 err = ds->ops->port_vlan_del(ds, port, vlan);
776 trace_dsa_vlan_del_hw(dp, vlan, err);
778 refcount_set(&v->refcount, 1);
786 mutex_unlock(&dp->vlans_lock);
791 static int dsa_switch_vlan_add(struct dsa_switch *ds,
792 struct dsa_notifier_vlan_info *info)
797 if (!ds->ops->port_vlan_add)
800 dsa_switch_for_each_port(dp, ds) {
801 if (dsa_port_vlan_match(dp, info)) {
802 err = dsa_port_do_vlan_add(dp, info->vlan,
812 static int dsa_switch_vlan_del(struct dsa_switch *ds,
813 struct dsa_notifier_vlan_info *info)
818 if (!ds->ops->port_vlan_del)
821 dsa_switch_for_each_port(dp, ds) {
822 if (dsa_port_vlan_match(dp, info)) {
823 err = dsa_port_do_vlan_del(dp, info->vlan);
832 static int dsa_switch_host_vlan_add(struct dsa_switch *ds,
833 struct dsa_notifier_vlan_info *info)
838 if (!ds->ops->port_vlan_add)
841 dsa_switch_for_each_port(dp, ds) {
842 if (dsa_port_host_vlan_match(dp, info->dp)) {
843 err = dsa_port_do_vlan_add(dp, info->vlan,
853 static int dsa_switch_host_vlan_del(struct dsa_switch *ds,
854 struct dsa_notifier_vlan_info *info)
859 if (!ds->ops->port_vlan_del)
862 dsa_switch_for_each_port(dp, ds) {
863 if (dsa_port_host_vlan_match(dp, info->dp)) {
864 err = dsa_port_do_vlan_del(dp, info->vlan);
873 static int dsa_switch_change_tag_proto(struct dsa_switch *ds,
874 struct dsa_notifier_tag_proto_info *info)
876 const struct dsa_device_ops *tag_ops = info->tag_ops;
877 struct dsa_port *dp, *cpu_dp;
880 if (!ds->ops->change_tag_protocol)
885 err = ds->ops->change_tag_protocol(ds, tag_ops->proto);
889 dsa_switch_for_each_cpu_port(cpu_dp, ds)
890 dsa_port_set_tag_protocol(cpu_dp, tag_ops);
892 /* Now that changing the tag protocol can no longer fail, let's update
893 * the remaining bits which are "duplicated for faster access", and the
894 * bits that depend on the tagger, such as the MTU.
896 dsa_switch_for_each_user_port(dp, ds) {
897 struct net_device *slave = dp->slave;
899 dsa_slave_setup_tagger(slave);
901 /* rtnl_mutex is held in dsa_tree_change_tag_proto */
902 dsa_slave_change_mtu(slave, slave->mtu);
908 /* We use the same cross-chip notifiers to inform both the tagger side, as well
909 * as the switch side, of connection and disconnection events.
910 * Since ds->tagger_data is owned by the tagger, it isn't a hard error if the
911 * switch side doesn't support connecting to this tagger, and therefore, the
912 * fact that we don't disconnect the tagger side doesn't constitute a memory
913 * leak: the tagger will still operate with persistent per-switch memory, just
914 * with the switch side unconnected to it. What does constitute a hard error is
915 * when the switch side supports connecting but fails.
918 dsa_switch_connect_tag_proto(struct dsa_switch *ds,
919 struct dsa_notifier_tag_proto_info *info)
921 const struct dsa_device_ops *tag_ops = info->tag_ops;
924 /* Notify the new tagger about the connection to this switch */
925 if (tag_ops->connect) {
926 err = tag_ops->connect(ds);
931 if (!ds->ops->connect_tag_protocol)
934 /* Notify the switch about the connection to the new tagger */
935 err = ds->ops->connect_tag_protocol(ds, tag_ops->proto);
937 /* Revert the new tagger's connection to this tree */
938 if (tag_ops->disconnect)
939 tag_ops->disconnect(ds);
947 dsa_switch_disconnect_tag_proto(struct dsa_switch *ds,
948 struct dsa_notifier_tag_proto_info *info)
950 const struct dsa_device_ops *tag_ops = info->tag_ops;
952 /* Notify the tagger about the disconnection from this switch */
953 if (tag_ops->disconnect && ds->tagger_data)
954 tag_ops->disconnect(ds);
956 /* No need to notify the switch, since it shouldn't have any
957 * resources to tear down
963 dsa_switch_master_state_change(struct dsa_switch *ds,
964 struct dsa_notifier_master_state_info *info)
966 if (!ds->ops->master_state_change)
969 ds->ops->master_state_change(ds, info->master, info->operational);
974 static int dsa_switch_event(struct notifier_block *nb,
975 unsigned long event, void *info)
977 struct dsa_switch *ds = container_of(nb, struct dsa_switch, nb);
981 case DSA_NOTIFIER_AGEING_TIME:
982 err = dsa_switch_ageing_time(ds, info);
984 case DSA_NOTIFIER_BRIDGE_JOIN:
985 err = dsa_switch_bridge_join(ds, info);
987 case DSA_NOTIFIER_BRIDGE_LEAVE:
988 err = dsa_switch_bridge_leave(ds, info);
990 case DSA_NOTIFIER_FDB_ADD:
991 err = dsa_switch_fdb_add(ds, info);
993 case DSA_NOTIFIER_FDB_DEL:
994 err = dsa_switch_fdb_del(ds, info);
996 case DSA_NOTIFIER_HOST_FDB_ADD:
997 err = dsa_switch_host_fdb_add(ds, info);
999 case DSA_NOTIFIER_HOST_FDB_DEL:
1000 err = dsa_switch_host_fdb_del(ds, info);
1002 case DSA_NOTIFIER_LAG_FDB_ADD:
1003 err = dsa_switch_lag_fdb_add(ds, info);
1005 case DSA_NOTIFIER_LAG_FDB_DEL:
1006 err = dsa_switch_lag_fdb_del(ds, info);
1008 case DSA_NOTIFIER_LAG_CHANGE:
1009 err = dsa_switch_lag_change(ds, info);
1011 case DSA_NOTIFIER_LAG_JOIN:
1012 err = dsa_switch_lag_join(ds, info);
1014 case DSA_NOTIFIER_LAG_LEAVE:
1015 err = dsa_switch_lag_leave(ds, info);
1017 case DSA_NOTIFIER_MDB_ADD:
1018 err = dsa_switch_mdb_add(ds, info);
1020 case DSA_NOTIFIER_MDB_DEL:
1021 err = dsa_switch_mdb_del(ds, info);
1023 case DSA_NOTIFIER_HOST_MDB_ADD:
1024 err = dsa_switch_host_mdb_add(ds, info);
1026 case DSA_NOTIFIER_HOST_MDB_DEL:
1027 err = dsa_switch_host_mdb_del(ds, info);
1029 case DSA_NOTIFIER_VLAN_ADD:
1030 err = dsa_switch_vlan_add(ds, info);
1032 case DSA_NOTIFIER_VLAN_DEL:
1033 err = dsa_switch_vlan_del(ds, info);
1035 case DSA_NOTIFIER_HOST_VLAN_ADD:
1036 err = dsa_switch_host_vlan_add(ds, info);
1038 case DSA_NOTIFIER_HOST_VLAN_DEL:
1039 err = dsa_switch_host_vlan_del(ds, info);
1041 case DSA_NOTIFIER_MTU:
1042 err = dsa_switch_mtu(ds, info);
1044 case DSA_NOTIFIER_TAG_PROTO:
1045 err = dsa_switch_change_tag_proto(ds, info);
1047 case DSA_NOTIFIER_TAG_PROTO_CONNECT:
1048 err = dsa_switch_connect_tag_proto(ds, info);
1050 case DSA_NOTIFIER_TAG_PROTO_DISCONNECT:
1051 err = dsa_switch_disconnect_tag_proto(ds, info);
1053 case DSA_NOTIFIER_TAG_8021Q_VLAN_ADD:
1054 err = dsa_switch_tag_8021q_vlan_add(ds, info);
1056 case DSA_NOTIFIER_TAG_8021Q_VLAN_DEL:
1057 err = dsa_switch_tag_8021q_vlan_del(ds, info);
1059 case DSA_NOTIFIER_MASTER_STATE_CHANGE:
1060 err = dsa_switch_master_state_change(ds, info);
1068 dev_dbg(ds->dev, "breaking chain for DSA event %lu (%d)\n",
1071 return notifier_from_errno(err);
1075 * dsa_tree_notify - Execute code for all switches in a DSA switch tree.
1076 * @dst: collection of struct dsa_switch devices to notify.
1077 * @e: event, must be of type DSA_NOTIFIER_*
1078 * @v: event-specific value.
1080 * Given a struct dsa_switch_tree, this can be used to run a function once for
1081 * each member DSA switch. The other alternative of traversing the tree is only
1082 * through its ports list, which does not uniquely list the switches.
1084 int dsa_tree_notify(struct dsa_switch_tree *dst, unsigned long e, void *v)
1086 struct raw_notifier_head *nh = &dst->nh;
1089 err = raw_notifier_call_chain(nh, e, v);
1091 return notifier_to_errno(err);
1095 * dsa_broadcast - Notify all DSA trees in the system.
1096 * @e: event, must be of type DSA_NOTIFIER_*
1097 * @v: event-specific value.
1099 * Can be used to notify the switching fabric of events such as cross-chip
1100 * bridging between disjoint trees (such as islands of tagger-compatible
1101 * switches bridged by an incompatible middle switch).
1103 * WARNING: this function is not reliable during probe time, because probing
1104 * between trees is asynchronous and not all DSA trees might have probed.
1106 int dsa_broadcast(unsigned long e, void *v)
1108 struct dsa_switch_tree *dst;
1111 list_for_each_entry(dst, &dsa_tree_list, list) {
1112 err = dsa_tree_notify(dst, e, v);
1120 int dsa_switch_register_notifier(struct dsa_switch *ds)
1122 ds->nb.notifier_call = dsa_switch_event;
1124 return raw_notifier_chain_register(&ds->dst->nh, &ds->nb);
1127 void dsa_switch_unregister_notifier(struct dsa_switch *ds)
1131 err = raw_notifier_chain_unregister(&ds->dst->nh, &ds->nb);
1133 dev_err(ds->dev, "failed to unregister notifier (%d)\n", err);