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>
17 static unsigned int dsa_switch_fastest_ageing_time(struct dsa_switch *ds,
18 unsigned int ageing_time)
22 dsa_switch_for_each_port(dp, ds)
23 if (dp->ageing_time && dp->ageing_time < ageing_time)
24 ageing_time = dp->ageing_time;
29 static int dsa_switch_ageing_time(struct dsa_switch *ds,
30 struct dsa_notifier_ageing_time_info *info)
32 unsigned int ageing_time = info->ageing_time;
34 if (ds->ageing_time_min && ageing_time < ds->ageing_time_min)
37 if (ds->ageing_time_max && ageing_time > ds->ageing_time_max)
40 /* Program the fastest ageing time in case of multiple bridges */
41 ageing_time = dsa_switch_fastest_ageing_time(ds, ageing_time);
43 if (ds->ops->set_ageing_time)
44 return ds->ops->set_ageing_time(ds, ageing_time);
49 static bool dsa_port_mtu_match(struct dsa_port *dp,
50 struct dsa_notifier_mtu_info *info)
52 if (dp->ds->index == info->sw_index && dp->index == info->port)
55 /* Do not propagate to other switches in the tree if the notifier was
56 * targeted for a single switch.
58 if (info->targeted_match)
61 if (dsa_port_is_dsa(dp) || dsa_port_is_cpu(dp))
67 static int dsa_switch_mtu(struct dsa_switch *ds,
68 struct dsa_notifier_mtu_info *info)
73 if (!ds->ops->port_change_mtu)
76 dsa_switch_for_each_port(dp, ds) {
77 if (dsa_port_mtu_match(dp, info)) {
78 ret = ds->ops->port_change_mtu(ds, dp->index,
88 static int dsa_switch_bridge_join(struct dsa_switch *ds,
89 struct dsa_notifier_bridge_info *info)
91 struct dsa_switch_tree *dst = ds->dst;
94 if (dst->index == info->tree_index && ds->index == info->sw_index) {
95 if (!ds->ops->port_bridge_join)
98 err = ds->ops->port_bridge_join(ds, info->port, info->bridge,
99 &info->tx_fwd_offload);
104 if ((dst->index != info->tree_index || ds->index != info->sw_index) &&
105 ds->ops->crosschip_bridge_join) {
106 err = ds->ops->crosschip_bridge_join(ds, info->tree_index,
108 info->port, info->bridge);
116 static int dsa_switch_sync_vlan_filtering(struct dsa_switch *ds,
117 struct dsa_notifier_bridge_info *info)
119 struct netlink_ext_ack extack = {0};
120 bool change_vlan_filtering = false;
125 if (ds->needs_standalone_vlan_filtering &&
126 !br_vlan_enabled(info->bridge.dev)) {
127 change_vlan_filtering = true;
128 vlan_filtering = true;
129 } else if (!ds->needs_standalone_vlan_filtering &&
130 br_vlan_enabled(info->bridge.dev)) {
131 change_vlan_filtering = true;
132 vlan_filtering = false;
135 /* If the bridge was vlan_filtering, the bridge core doesn't trigger an
136 * event for changing vlan_filtering setting upon slave ports leaving
137 * it. That is a good thing, because that lets us handle it and also
138 * handle the case where the switch's vlan_filtering setting is global
139 * (not per port). When that happens, the correct moment to trigger the
140 * vlan_filtering callback is only when the last port leaves the last
143 if (change_vlan_filtering && ds->vlan_filtering_is_global) {
144 dsa_switch_for_each_port(dp, ds) {
145 struct net_device *br = dsa_port_bridge_dev_get(dp);
147 if (br && br_vlan_enabled(br)) {
148 change_vlan_filtering = false;
154 if (change_vlan_filtering) {
155 err = dsa_port_vlan_filtering(dsa_to_port(ds, info->port),
156 vlan_filtering, &extack);
158 dev_err(ds->dev, "port %d: %s\n", info->port,
160 if (err && err != -EOPNOTSUPP)
167 static int dsa_switch_bridge_leave(struct dsa_switch *ds,
168 struct dsa_notifier_bridge_info *info)
170 struct dsa_switch_tree *dst = ds->dst;
173 if (dst->index == info->tree_index && ds->index == info->sw_index &&
174 ds->ops->port_bridge_leave)
175 ds->ops->port_bridge_leave(ds, info->port, info->bridge);
177 if ((dst->index != info->tree_index || ds->index != info->sw_index) &&
178 ds->ops->crosschip_bridge_leave)
179 ds->ops->crosschip_bridge_leave(ds, info->tree_index,
180 info->sw_index, info->port,
183 if (ds->dst->index == info->tree_index && ds->index == info->sw_index) {
184 err = dsa_switch_sync_vlan_filtering(ds, info);
192 /* Matches for all upstream-facing ports (the CPU port and all upstream-facing
193 * DSA links) that sit between the targeted port on which the notifier was
194 * emitted and its dedicated CPU port.
196 static bool dsa_port_host_address_match(struct dsa_port *dp,
197 int info_sw_index, int info_port)
199 struct dsa_port *targeted_dp, *cpu_dp;
200 struct dsa_switch *targeted_ds;
202 targeted_ds = dsa_switch_find(dp->ds->dst->index, info_sw_index);
203 targeted_dp = dsa_to_port(targeted_ds, info_port);
204 cpu_dp = targeted_dp->cpu_dp;
206 if (dsa_switch_is_upstream_of(dp->ds, targeted_ds))
207 return dp->index == dsa_towards_port(dp->ds, cpu_dp->ds->index,
213 static struct dsa_mac_addr *dsa_mac_addr_find(struct list_head *addr_list,
214 const unsigned char *addr,
217 struct dsa_mac_addr *a;
219 list_for_each_entry(a, addr_list, list)
220 if (ether_addr_equal(a->addr, addr) && a->vid == vid)
226 static int dsa_port_do_mdb_add(struct dsa_port *dp,
227 const struct switchdev_obj_port_mdb *mdb)
229 struct dsa_switch *ds = dp->ds;
230 struct dsa_mac_addr *a;
231 int port = dp->index;
234 /* No need to bother with refcounting for user ports */
235 if (!(dsa_port_is_cpu(dp) || dsa_port_is_dsa(dp)))
236 return ds->ops->port_mdb_add(ds, port, mdb);
238 mutex_lock(&dp->addr_lists_lock);
240 a = dsa_mac_addr_find(&dp->mdbs, mdb->addr, mdb->vid);
242 refcount_inc(&a->refcount);
246 a = kzalloc(sizeof(*a), GFP_KERNEL);
252 err = ds->ops->port_mdb_add(ds, port, mdb);
258 ether_addr_copy(a->addr, mdb->addr);
260 refcount_set(&a->refcount, 1);
261 list_add_tail(&a->list, &dp->mdbs);
264 mutex_unlock(&dp->addr_lists_lock);
269 static int dsa_port_do_mdb_del(struct dsa_port *dp,
270 const struct switchdev_obj_port_mdb *mdb)
272 struct dsa_switch *ds = dp->ds;
273 struct dsa_mac_addr *a;
274 int port = dp->index;
277 /* No need to bother with refcounting for user ports */
278 if (!(dsa_port_is_cpu(dp) || dsa_port_is_dsa(dp)))
279 return ds->ops->port_mdb_del(ds, port, mdb);
281 mutex_lock(&dp->addr_lists_lock);
283 a = dsa_mac_addr_find(&dp->mdbs, mdb->addr, mdb->vid);
289 if (!refcount_dec_and_test(&a->refcount))
292 err = ds->ops->port_mdb_del(ds, port, mdb);
294 refcount_set(&a->refcount, 1);
302 mutex_unlock(&dp->addr_lists_lock);
307 static int dsa_port_do_fdb_add(struct dsa_port *dp, const unsigned char *addr,
310 struct dsa_switch *ds = dp->ds;
311 struct dsa_mac_addr *a;
312 int port = dp->index;
315 /* No need to bother with refcounting for user ports */
316 if (!(dsa_port_is_cpu(dp) || dsa_port_is_dsa(dp)))
317 return ds->ops->port_fdb_add(ds, port, addr, vid);
319 mutex_lock(&dp->addr_lists_lock);
321 a = dsa_mac_addr_find(&dp->fdbs, addr, vid);
323 refcount_inc(&a->refcount);
327 a = kzalloc(sizeof(*a), GFP_KERNEL);
333 err = ds->ops->port_fdb_add(ds, port, addr, vid);
339 ether_addr_copy(a->addr, addr);
341 refcount_set(&a->refcount, 1);
342 list_add_tail(&a->list, &dp->fdbs);
345 mutex_unlock(&dp->addr_lists_lock);
350 static int dsa_port_do_fdb_del(struct dsa_port *dp, const unsigned char *addr,
353 struct dsa_switch *ds = dp->ds;
354 struct dsa_mac_addr *a;
355 int port = dp->index;
358 /* No need to bother with refcounting for user ports */
359 if (!(dsa_port_is_cpu(dp) || dsa_port_is_dsa(dp)))
360 return ds->ops->port_fdb_del(ds, port, addr, vid);
362 mutex_lock(&dp->addr_lists_lock);
364 a = dsa_mac_addr_find(&dp->fdbs, addr, vid);
370 if (!refcount_dec_and_test(&a->refcount))
373 err = ds->ops->port_fdb_del(ds, port, addr, vid);
375 refcount_set(&a->refcount, 1);
383 mutex_unlock(&dp->addr_lists_lock);
388 static int dsa_switch_do_lag_fdb_add(struct dsa_switch *ds, struct dsa_lag *lag,
389 const unsigned char *addr, u16 vid)
391 struct dsa_mac_addr *a;
394 mutex_lock(&lag->fdb_lock);
396 a = dsa_mac_addr_find(&lag->fdbs, addr, vid);
398 refcount_inc(&a->refcount);
402 a = kzalloc(sizeof(*a), GFP_KERNEL);
408 err = ds->ops->lag_fdb_add(ds, *lag, addr, vid);
414 ether_addr_copy(a->addr, addr);
416 refcount_set(&a->refcount, 1);
417 list_add_tail(&a->list, &lag->fdbs);
420 mutex_unlock(&lag->fdb_lock);
425 static int dsa_switch_do_lag_fdb_del(struct dsa_switch *ds, struct dsa_lag *lag,
426 const unsigned char *addr, u16 vid)
428 struct dsa_mac_addr *a;
431 mutex_lock(&lag->fdb_lock);
433 a = dsa_mac_addr_find(&lag->fdbs, addr, vid);
439 if (!refcount_dec_and_test(&a->refcount))
442 err = ds->ops->lag_fdb_del(ds, *lag, addr, vid);
444 refcount_set(&a->refcount, 1);
452 mutex_unlock(&lag->fdb_lock);
457 static int dsa_switch_host_fdb_add(struct dsa_switch *ds,
458 struct dsa_notifier_fdb_info *info)
463 if (!ds->ops->port_fdb_add)
466 dsa_switch_for_each_port(dp, ds) {
467 if (dsa_port_host_address_match(dp, info->sw_index,
469 err = dsa_port_do_fdb_add(dp, info->addr, info->vid);
478 static int dsa_switch_host_fdb_del(struct dsa_switch *ds,
479 struct dsa_notifier_fdb_info *info)
484 if (!ds->ops->port_fdb_del)
487 dsa_switch_for_each_port(dp, ds) {
488 if (dsa_port_host_address_match(dp, info->sw_index,
490 err = dsa_port_do_fdb_del(dp, info->addr, info->vid);
499 static int dsa_switch_fdb_add(struct dsa_switch *ds,
500 struct dsa_notifier_fdb_info *info)
502 int port = dsa_towards_port(ds, info->sw_index, info->port);
503 struct dsa_port *dp = dsa_to_port(ds, port);
505 if (!ds->ops->port_fdb_add)
508 return dsa_port_do_fdb_add(dp, info->addr, info->vid);
511 static int dsa_switch_fdb_del(struct dsa_switch *ds,
512 struct dsa_notifier_fdb_info *info)
514 int port = dsa_towards_port(ds, info->sw_index, info->port);
515 struct dsa_port *dp = dsa_to_port(ds, port);
517 if (!ds->ops->port_fdb_del)
520 return dsa_port_do_fdb_del(dp, info->addr, info->vid);
523 static int dsa_switch_lag_fdb_add(struct dsa_switch *ds,
524 struct dsa_notifier_lag_fdb_info *info)
528 if (!ds->ops->lag_fdb_add)
531 /* Notify switch only if it has a port in this LAG */
532 dsa_switch_for_each_port(dp, ds)
533 if (dsa_port_offloads_lag(dp, info->lag))
534 return dsa_switch_do_lag_fdb_add(ds, info->lag,
535 info->addr, info->vid);
540 static int dsa_switch_lag_fdb_del(struct dsa_switch *ds,
541 struct dsa_notifier_lag_fdb_info *info)
545 if (!ds->ops->lag_fdb_del)
548 /* Notify switch only if it has a port in this LAG */
549 dsa_switch_for_each_port(dp, ds)
550 if (dsa_port_offloads_lag(dp, info->lag))
551 return dsa_switch_do_lag_fdb_del(ds, info->lag,
552 info->addr, info->vid);
557 static int dsa_switch_lag_change(struct dsa_switch *ds,
558 struct dsa_notifier_lag_info *info)
560 if (ds->index == info->sw_index && ds->ops->port_lag_change)
561 return ds->ops->port_lag_change(ds, info->port);
563 if (ds->index != info->sw_index && ds->ops->crosschip_lag_change)
564 return ds->ops->crosschip_lag_change(ds, info->sw_index,
570 static int dsa_switch_lag_join(struct dsa_switch *ds,
571 struct dsa_notifier_lag_info *info)
573 if (ds->index == info->sw_index && ds->ops->port_lag_join)
574 return ds->ops->port_lag_join(ds, info->port, info->lag,
577 if (ds->index != info->sw_index && ds->ops->crosschip_lag_join)
578 return ds->ops->crosschip_lag_join(ds, info->sw_index,
579 info->port, info->lag,
585 static int dsa_switch_lag_leave(struct dsa_switch *ds,
586 struct dsa_notifier_lag_info *info)
588 if (ds->index == info->sw_index && ds->ops->port_lag_leave)
589 return ds->ops->port_lag_leave(ds, info->port, info->lag);
591 if (ds->index != info->sw_index && ds->ops->crosschip_lag_leave)
592 return ds->ops->crosschip_lag_leave(ds, info->sw_index,
593 info->port, info->lag);
598 static int dsa_switch_mdb_add(struct dsa_switch *ds,
599 struct dsa_notifier_mdb_info *info)
601 int port = dsa_towards_port(ds, info->sw_index, info->port);
602 struct dsa_port *dp = dsa_to_port(ds, port);
604 if (!ds->ops->port_mdb_add)
607 return dsa_port_do_mdb_add(dp, info->mdb);
610 static int dsa_switch_mdb_del(struct dsa_switch *ds,
611 struct dsa_notifier_mdb_info *info)
613 int port = dsa_towards_port(ds, info->sw_index, info->port);
614 struct dsa_port *dp = dsa_to_port(ds, port);
616 if (!ds->ops->port_mdb_del)
619 return dsa_port_do_mdb_del(dp, info->mdb);
622 static int dsa_switch_host_mdb_add(struct dsa_switch *ds,
623 struct dsa_notifier_mdb_info *info)
628 if (!ds->ops->port_mdb_add)
631 dsa_switch_for_each_port(dp, ds) {
632 if (dsa_port_host_address_match(dp, info->sw_index,
634 err = dsa_port_do_mdb_add(dp, info->mdb);
643 static int dsa_switch_host_mdb_del(struct dsa_switch *ds,
644 struct dsa_notifier_mdb_info *info)
649 if (!ds->ops->port_mdb_del)
652 dsa_switch_for_each_port(dp, ds) {
653 if (dsa_port_host_address_match(dp, info->sw_index,
655 err = dsa_port_do_mdb_del(dp, info->mdb);
664 /* Port VLANs match on the targeted port and on all DSA ports */
665 static bool dsa_port_vlan_match(struct dsa_port *dp,
666 struct dsa_notifier_vlan_info *info)
668 if (dp->ds->index == info->sw_index && dp->index == info->port)
671 if (dsa_port_is_dsa(dp))
677 /* Host VLANs match on the targeted port's CPU port, and on all DSA ports
678 * (upstream and downstream) of that switch and its upstream switches.
680 static bool dsa_port_host_vlan_match(struct dsa_port *dp,
681 struct dsa_notifier_vlan_info *info)
683 struct dsa_port *targeted_dp, *cpu_dp;
684 struct dsa_switch *targeted_ds;
686 targeted_ds = dsa_switch_find(dp->ds->dst->index, info->sw_index);
687 targeted_dp = dsa_to_port(targeted_ds, info->port);
688 cpu_dp = targeted_dp->cpu_dp;
690 if (dsa_switch_is_upstream_of(dp->ds, targeted_ds))
691 return dsa_port_is_dsa(dp) || dp == cpu_dp;
696 static struct dsa_vlan *dsa_vlan_find(struct list_head *vlan_list,
697 const struct switchdev_obj_port_vlan *vlan)
701 list_for_each_entry(v, vlan_list, list)
702 if (v->vid == vlan->vid)
708 static int dsa_port_do_vlan_add(struct dsa_port *dp,
709 const struct switchdev_obj_port_vlan *vlan,
710 struct netlink_ext_ack *extack)
712 struct dsa_switch *ds = dp->ds;
713 int port = dp->index;
717 /* No need to bother with refcounting for user ports. */
718 if (!(dsa_port_is_cpu(dp) || dsa_port_is_dsa(dp)))
719 return ds->ops->port_vlan_add(ds, port, vlan, extack);
721 /* No need to propagate on shared ports the existing VLANs that were
722 * re-notified after just the flags have changed. This would cause a
723 * refcount bump which we need to avoid, since it unbalances the
724 * additions with the deletions.
729 mutex_lock(&dp->vlans_lock);
731 v = dsa_vlan_find(&dp->vlans, vlan);
733 refcount_inc(&v->refcount);
737 v = kzalloc(sizeof(*v), GFP_KERNEL);
743 err = ds->ops->port_vlan_add(ds, port, vlan, extack);
750 refcount_set(&v->refcount, 1);
751 list_add_tail(&v->list, &dp->vlans);
754 mutex_unlock(&dp->vlans_lock);
759 static int dsa_port_do_vlan_del(struct dsa_port *dp,
760 const struct switchdev_obj_port_vlan *vlan)
762 struct dsa_switch *ds = dp->ds;
763 int port = dp->index;
767 /* No need to bother with refcounting for user ports */
768 if (!(dsa_port_is_cpu(dp) || dsa_port_is_dsa(dp)))
769 return ds->ops->port_vlan_del(ds, port, vlan);
771 mutex_lock(&dp->vlans_lock);
773 v = dsa_vlan_find(&dp->vlans, vlan);
779 if (!refcount_dec_and_test(&v->refcount))
782 err = ds->ops->port_vlan_del(ds, port, vlan);
784 refcount_set(&v->refcount, 1);
792 mutex_unlock(&dp->vlans_lock);
797 static int dsa_switch_vlan_add(struct dsa_switch *ds,
798 struct dsa_notifier_vlan_info *info)
803 if (!ds->ops->port_vlan_add)
806 dsa_switch_for_each_port(dp, ds) {
807 if (dsa_port_vlan_match(dp, info)) {
808 err = dsa_port_do_vlan_add(dp, info->vlan,
818 static int dsa_switch_vlan_del(struct dsa_switch *ds,
819 struct dsa_notifier_vlan_info *info)
824 if (!ds->ops->port_vlan_del)
827 dsa_switch_for_each_port(dp, ds) {
828 if (dsa_port_vlan_match(dp, info)) {
829 err = dsa_port_do_vlan_del(dp, info->vlan);
838 static int dsa_switch_host_vlan_add(struct dsa_switch *ds,
839 struct dsa_notifier_vlan_info *info)
844 if (!ds->ops->port_vlan_add)
847 dsa_switch_for_each_port(dp, ds) {
848 if (dsa_port_host_vlan_match(dp, info)) {
849 err = dsa_port_do_vlan_add(dp, info->vlan,
859 static int dsa_switch_host_vlan_del(struct dsa_switch *ds,
860 struct dsa_notifier_vlan_info *info)
865 if (!ds->ops->port_vlan_del)
868 dsa_switch_for_each_port(dp, ds) {
869 if (dsa_port_host_vlan_match(dp, info)) {
870 err = dsa_port_do_vlan_del(dp, info->vlan);
879 static int dsa_switch_change_tag_proto(struct dsa_switch *ds,
880 struct dsa_notifier_tag_proto_info *info)
882 const struct dsa_device_ops *tag_ops = info->tag_ops;
883 struct dsa_port *dp, *cpu_dp;
886 if (!ds->ops->change_tag_protocol)
891 dsa_switch_for_each_cpu_port(cpu_dp, ds) {
892 err = ds->ops->change_tag_protocol(ds, cpu_dp->index,
897 dsa_port_set_tag_protocol(cpu_dp, tag_ops);
900 /* Now that changing the tag protocol can no longer fail, let's update
901 * the remaining bits which are "duplicated for faster access", and the
902 * bits that depend on the tagger, such as the MTU.
904 dsa_switch_for_each_user_port(dp, ds) {
905 struct net_device *slave = dp->slave;
907 dsa_slave_setup_tagger(slave);
909 /* rtnl_mutex is held in dsa_tree_change_tag_proto */
910 dsa_slave_change_mtu(slave, slave->mtu);
916 /* We use the same cross-chip notifiers to inform both the tagger side, as well
917 * as the switch side, of connection and disconnection events.
918 * Since ds->tagger_data is owned by the tagger, it isn't a hard error if the
919 * switch side doesn't support connecting to this tagger, and therefore, the
920 * fact that we don't disconnect the tagger side doesn't constitute a memory
921 * leak: the tagger will still operate with persistent per-switch memory, just
922 * with the switch side unconnected to it. What does constitute a hard error is
923 * when the switch side supports connecting but fails.
926 dsa_switch_connect_tag_proto(struct dsa_switch *ds,
927 struct dsa_notifier_tag_proto_info *info)
929 const struct dsa_device_ops *tag_ops = info->tag_ops;
932 /* Notify the new tagger about the connection to this switch */
933 if (tag_ops->connect) {
934 err = tag_ops->connect(ds);
939 if (!ds->ops->connect_tag_protocol)
942 /* Notify the switch about the connection to the new tagger */
943 err = ds->ops->connect_tag_protocol(ds, tag_ops->proto);
945 /* Revert the new tagger's connection to this tree */
946 if (tag_ops->disconnect)
947 tag_ops->disconnect(ds);
955 dsa_switch_disconnect_tag_proto(struct dsa_switch *ds,
956 struct dsa_notifier_tag_proto_info *info)
958 const struct dsa_device_ops *tag_ops = info->tag_ops;
960 /* Notify the tagger about the disconnection from this switch */
961 if (tag_ops->disconnect && ds->tagger_data)
962 tag_ops->disconnect(ds);
964 /* No need to notify the switch, since it shouldn't have any
965 * resources to tear down
971 dsa_switch_master_state_change(struct dsa_switch *ds,
972 struct dsa_notifier_master_state_info *info)
974 if (!ds->ops->master_state_change)
977 ds->ops->master_state_change(ds, info->master, info->operational);
982 static int dsa_switch_event(struct notifier_block *nb,
983 unsigned long event, void *info)
985 struct dsa_switch *ds = container_of(nb, struct dsa_switch, nb);
989 case DSA_NOTIFIER_AGEING_TIME:
990 err = dsa_switch_ageing_time(ds, info);
992 case DSA_NOTIFIER_BRIDGE_JOIN:
993 err = dsa_switch_bridge_join(ds, info);
995 case DSA_NOTIFIER_BRIDGE_LEAVE:
996 err = dsa_switch_bridge_leave(ds, info);
998 case DSA_NOTIFIER_FDB_ADD:
999 err = dsa_switch_fdb_add(ds, info);
1001 case DSA_NOTIFIER_FDB_DEL:
1002 err = dsa_switch_fdb_del(ds, info);
1004 case DSA_NOTIFIER_HOST_FDB_ADD:
1005 err = dsa_switch_host_fdb_add(ds, info);
1007 case DSA_NOTIFIER_HOST_FDB_DEL:
1008 err = dsa_switch_host_fdb_del(ds, info);
1010 case DSA_NOTIFIER_LAG_FDB_ADD:
1011 err = dsa_switch_lag_fdb_add(ds, info);
1013 case DSA_NOTIFIER_LAG_FDB_DEL:
1014 err = dsa_switch_lag_fdb_del(ds, info);
1016 case DSA_NOTIFIER_LAG_CHANGE:
1017 err = dsa_switch_lag_change(ds, info);
1019 case DSA_NOTIFIER_LAG_JOIN:
1020 err = dsa_switch_lag_join(ds, info);
1022 case DSA_NOTIFIER_LAG_LEAVE:
1023 err = dsa_switch_lag_leave(ds, info);
1025 case DSA_NOTIFIER_MDB_ADD:
1026 err = dsa_switch_mdb_add(ds, info);
1028 case DSA_NOTIFIER_MDB_DEL:
1029 err = dsa_switch_mdb_del(ds, info);
1031 case DSA_NOTIFIER_HOST_MDB_ADD:
1032 err = dsa_switch_host_mdb_add(ds, info);
1034 case DSA_NOTIFIER_HOST_MDB_DEL:
1035 err = dsa_switch_host_mdb_del(ds, info);
1037 case DSA_NOTIFIER_VLAN_ADD:
1038 err = dsa_switch_vlan_add(ds, info);
1040 case DSA_NOTIFIER_VLAN_DEL:
1041 err = dsa_switch_vlan_del(ds, info);
1043 case DSA_NOTIFIER_HOST_VLAN_ADD:
1044 err = dsa_switch_host_vlan_add(ds, info);
1046 case DSA_NOTIFIER_HOST_VLAN_DEL:
1047 err = dsa_switch_host_vlan_del(ds, info);
1049 case DSA_NOTIFIER_MTU:
1050 err = dsa_switch_mtu(ds, info);
1052 case DSA_NOTIFIER_TAG_PROTO:
1053 err = dsa_switch_change_tag_proto(ds, info);
1055 case DSA_NOTIFIER_TAG_PROTO_CONNECT:
1056 err = dsa_switch_connect_tag_proto(ds, info);
1058 case DSA_NOTIFIER_TAG_PROTO_DISCONNECT:
1059 err = dsa_switch_disconnect_tag_proto(ds, info);
1061 case DSA_NOTIFIER_TAG_8021Q_VLAN_ADD:
1062 err = dsa_switch_tag_8021q_vlan_add(ds, info);
1064 case DSA_NOTIFIER_TAG_8021Q_VLAN_DEL:
1065 err = dsa_switch_tag_8021q_vlan_del(ds, info);
1067 case DSA_NOTIFIER_MASTER_STATE_CHANGE:
1068 err = dsa_switch_master_state_change(ds, info);
1076 dev_dbg(ds->dev, "breaking chain for DSA event %lu (%d)\n",
1079 return notifier_from_errno(err);
1082 int dsa_switch_register_notifier(struct dsa_switch *ds)
1084 ds->nb.notifier_call = dsa_switch_event;
1086 return raw_notifier_chain_register(&ds->dst->nh, &ds->nb);
1089 void dsa_switch_unregister_notifier(struct dsa_switch *ds)
1093 err = raw_notifier_chain_unregister(&ds->dst->nh, &ds->nb);
1095 dev_err(ds->dev, "failed to unregister notifier (%d)\n", err);