1 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
2 /* Copyright (c) 2015-2018 Mellanox Technologies. All rights reserved */
4 #include <linux/kernel.h>
5 #include <linux/types.h>
6 #include <linux/netdevice.h>
7 #include <linux/etherdevice.h>
8 #include <linux/slab.h>
9 #include <linux/device.h>
10 #include <linux/skbuff.h>
11 #include <linux/if_vlan.h>
12 #include <linux/if_bridge.h>
13 #include <linux/workqueue.h>
14 #include <linux/jiffies.h>
15 #include <linux/rtnetlink.h>
16 #include <linux/netlink.h>
17 #include <net/switchdev.h>
18 #include <net/vxlan.h>
20 #include "spectrum_span.h"
21 #include "spectrum_switchdev.h"
26 struct mlxsw_sp_bridge_ops;
28 struct mlxsw_sp_bridge {
29 struct mlxsw_sp *mlxsw_sp;
31 struct delayed_work dw;
32 #define MLXSW_SP_DEFAULT_LEARNING_INTERVAL 100
33 unsigned int interval; /* ms */
35 #define MLXSW_SP_MIN_AGEING_TIME 10
36 #define MLXSW_SP_MAX_AGEING_TIME 1000000
37 #define MLXSW_SP_DEFAULT_AGEING_TIME 300
39 bool vlan_enabled_exists;
40 struct list_head bridges_list;
41 DECLARE_BITMAP(mids_bitmap, MLXSW_SP_MID_MAX);
42 const struct mlxsw_sp_bridge_ops *bridge_8021q_ops;
43 const struct mlxsw_sp_bridge_ops *bridge_8021d_ops;
46 struct mlxsw_sp_bridge_device {
47 struct net_device *dev;
48 struct list_head list;
49 struct list_head ports_list;
50 struct list_head mids_list;
54 const struct mlxsw_sp_bridge_ops *ops;
57 struct mlxsw_sp_bridge_port {
58 struct net_device *dev;
59 struct mlxsw_sp_bridge_device *bridge_device;
60 struct list_head list;
61 struct list_head vlans_list;
62 unsigned int ref_count;
73 struct mlxsw_sp_bridge_vlan {
74 struct list_head list;
75 struct list_head port_vlan_list;
79 struct mlxsw_sp_bridge_ops {
80 int (*port_join)(struct mlxsw_sp_bridge_device *bridge_device,
81 struct mlxsw_sp_bridge_port *bridge_port,
82 struct mlxsw_sp_port *mlxsw_sp_port,
83 struct netlink_ext_ack *extack);
84 void (*port_leave)(struct mlxsw_sp_bridge_device *bridge_device,
85 struct mlxsw_sp_bridge_port *bridge_port,
86 struct mlxsw_sp_port *mlxsw_sp_port);
87 int (*vxlan_join)(struct mlxsw_sp_bridge_device *bridge_device,
88 const struct net_device *vxlan_dev, u16 vid,
89 struct netlink_ext_ack *extack);
91 (*fid_get)(struct mlxsw_sp_bridge_device *bridge_device,
92 u16 vid, struct netlink_ext_ack *extack);
94 (*fid_lookup)(struct mlxsw_sp_bridge_device *bridge_device,
96 u16 (*fid_vid)(struct mlxsw_sp_bridge_device *bridge_device,
97 const struct mlxsw_sp_fid *fid);
101 mlxsw_sp_bridge_port_fdb_flush(struct mlxsw_sp *mlxsw_sp,
102 struct mlxsw_sp_bridge_port *bridge_port,
106 mlxsw_sp_bridge_port_mdb_flush(struct mlxsw_sp_port *mlxsw_sp_port,
107 struct mlxsw_sp_bridge_port *bridge_port);
110 mlxsw_sp_bridge_mdb_mc_enable_sync(struct mlxsw_sp_port *mlxsw_sp_port,
111 struct mlxsw_sp_bridge_device
115 mlxsw_sp_port_mrouter_update_mdb(struct mlxsw_sp_port *mlxsw_sp_port,
116 struct mlxsw_sp_bridge_port *bridge_port,
119 static struct mlxsw_sp_bridge_device *
120 mlxsw_sp_bridge_device_find(const struct mlxsw_sp_bridge *bridge,
121 const struct net_device *br_dev)
123 struct mlxsw_sp_bridge_device *bridge_device;
125 list_for_each_entry(bridge_device, &bridge->bridges_list, list)
126 if (bridge_device->dev == br_dev)
127 return bridge_device;
132 bool mlxsw_sp_bridge_device_is_offloaded(const struct mlxsw_sp *mlxsw_sp,
133 const struct net_device *br_dev)
135 return !!mlxsw_sp_bridge_device_find(mlxsw_sp->bridge, br_dev);
138 static int mlxsw_sp_bridge_device_upper_rif_destroy(struct net_device *dev,
141 struct mlxsw_sp *mlxsw_sp = data;
143 mlxsw_sp_rif_destroy_by_dev(mlxsw_sp, dev);
147 static void mlxsw_sp_bridge_device_rifs_destroy(struct mlxsw_sp *mlxsw_sp,
148 struct net_device *dev)
150 mlxsw_sp_rif_destroy_by_dev(mlxsw_sp, dev);
151 netdev_walk_all_upper_dev_rcu(dev,
152 mlxsw_sp_bridge_device_upper_rif_destroy,
156 static int mlxsw_sp_bridge_device_vxlan_init(struct mlxsw_sp_bridge *bridge,
157 struct net_device *br_dev,
158 struct netlink_ext_ack *extack)
160 struct net_device *dev, *stop_dev;
161 struct list_head *iter;
164 netdev_for_each_lower_dev(br_dev, dev, iter) {
165 if (netif_is_vxlan(dev) && netif_running(dev)) {
166 err = mlxsw_sp_bridge_vxlan_join(bridge->mlxsw_sp,
179 netdev_for_each_lower_dev(br_dev, dev, iter) {
180 if (netif_is_vxlan(dev) && netif_running(dev)) {
183 mlxsw_sp_bridge_vxlan_leave(bridge->mlxsw_sp, dev);
189 static void mlxsw_sp_bridge_device_vxlan_fini(struct mlxsw_sp_bridge *bridge,
190 struct net_device *br_dev)
192 struct net_device *dev;
193 struct list_head *iter;
195 netdev_for_each_lower_dev(br_dev, dev, iter) {
196 if (netif_is_vxlan(dev) && netif_running(dev))
197 mlxsw_sp_bridge_vxlan_leave(bridge->mlxsw_sp, dev);
201 static struct mlxsw_sp_bridge_device *
202 mlxsw_sp_bridge_device_create(struct mlxsw_sp_bridge *bridge,
203 struct net_device *br_dev,
204 struct netlink_ext_ack *extack)
206 struct device *dev = bridge->mlxsw_sp->bus_info->dev;
207 struct mlxsw_sp_bridge_device *bridge_device;
208 bool vlan_enabled = br_vlan_enabled(br_dev);
211 if (vlan_enabled && bridge->vlan_enabled_exists) {
212 dev_err(dev, "Only one VLAN-aware bridge is supported\n");
213 NL_SET_ERR_MSG_MOD(extack, "Only one VLAN-aware bridge is supported");
214 return ERR_PTR(-EINVAL);
217 bridge_device = kzalloc(sizeof(*bridge_device), GFP_KERNEL);
219 return ERR_PTR(-ENOMEM);
221 bridge_device->dev = br_dev;
222 bridge_device->vlan_enabled = vlan_enabled;
223 bridge_device->multicast_enabled = br_multicast_enabled(br_dev);
224 bridge_device->mrouter = br_multicast_router(br_dev);
225 INIT_LIST_HEAD(&bridge_device->ports_list);
227 bridge->vlan_enabled_exists = true;
228 bridge_device->ops = bridge->bridge_8021q_ops;
230 bridge_device->ops = bridge->bridge_8021d_ops;
232 INIT_LIST_HEAD(&bridge_device->mids_list);
233 list_add(&bridge_device->list, &bridge->bridges_list);
235 /* It is possible we already have VXLAN devices enslaved to the bridge.
236 * In which case, we need to replay their configuration as if they were
237 * just now enslaved to the bridge.
239 err = mlxsw_sp_bridge_device_vxlan_init(bridge, br_dev, extack);
243 return bridge_device;
246 list_del(&bridge_device->list);
247 if (bridge_device->vlan_enabled)
248 bridge->vlan_enabled_exists = false;
249 kfree(bridge_device);
254 mlxsw_sp_bridge_device_destroy(struct mlxsw_sp_bridge *bridge,
255 struct mlxsw_sp_bridge_device *bridge_device)
257 mlxsw_sp_bridge_device_vxlan_fini(bridge, bridge_device->dev);
258 mlxsw_sp_bridge_device_rifs_destroy(bridge->mlxsw_sp,
260 list_del(&bridge_device->list);
261 if (bridge_device->vlan_enabled)
262 bridge->vlan_enabled_exists = false;
263 WARN_ON(!list_empty(&bridge_device->ports_list));
264 WARN_ON(!list_empty(&bridge_device->mids_list));
265 kfree(bridge_device);
268 static struct mlxsw_sp_bridge_device *
269 mlxsw_sp_bridge_device_get(struct mlxsw_sp_bridge *bridge,
270 struct net_device *br_dev,
271 struct netlink_ext_ack *extack)
273 struct mlxsw_sp_bridge_device *bridge_device;
275 bridge_device = mlxsw_sp_bridge_device_find(bridge, br_dev);
277 return bridge_device;
279 return mlxsw_sp_bridge_device_create(bridge, br_dev, extack);
283 mlxsw_sp_bridge_device_put(struct mlxsw_sp_bridge *bridge,
284 struct mlxsw_sp_bridge_device *bridge_device)
286 if (list_empty(&bridge_device->ports_list))
287 mlxsw_sp_bridge_device_destroy(bridge, bridge_device);
290 static struct mlxsw_sp_bridge_port *
291 __mlxsw_sp_bridge_port_find(const struct mlxsw_sp_bridge_device *bridge_device,
292 const struct net_device *brport_dev)
294 struct mlxsw_sp_bridge_port *bridge_port;
296 list_for_each_entry(bridge_port, &bridge_device->ports_list, list) {
297 if (bridge_port->dev == brport_dev)
304 struct mlxsw_sp_bridge_port *
305 mlxsw_sp_bridge_port_find(struct mlxsw_sp_bridge *bridge,
306 struct net_device *brport_dev)
308 struct net_device *br_dev = netdev_master_upper_dev_get(brport_dev);
309 struct mlxsw_sp_bridge_device *bridge_device;
314 bridge_device = mlxsw_sp_bridge_device_find(bridge, br_dev);
318 return __mlxsw_sp_bridge_port_find(bridge_device, brport_dev);
321 static struct mlxsw_sp_bridge_port *
322 mlxsw_sp_bridge_port_create(struct mlxsw_sp_bridge_device *bridge_device,
323 struct net_device *brport_dev)
325 struct mlxsw_sp_bridge_port *bridge_port;
326 struct mlxsw_sp_port *mlxsw_sp_port;
328 bridge_port = kzalloc(sizeof(*bridge_port), GFP_KERNEL);
332 mlxsw_sp_port = mlxsw_sp_port_dev_lower_find(brport_dev);
333 bridge_port->lagged = mlxsw_sp_port->lagged;
334 if (bridge_port->lagged)
335 bridge_port->lag_id = mlxsw_sp_port->lag_id;
337 bridge_port->system_port = mlxsw_sp_port->local_port;
338 bridge_port->dev = brport_dev;
339 bridge_port->bridge_device = bridge_device;
340 bridge_port->stp_state = BR_STATE_DISABLED;
341 bridge_port->flags = BR_LEARNING | BR_FLOOD | BR_LEARNING_SYNC |
343 INIT_LIST_HEAD(&bridge_port->vlans_list);
344 list_add(&bridge_port->list, &bridge_device->ports_list);
345 bridge_port->ref_count = 1;
351 mlxsw_sp_bridge_port_destroy(struct mlxsw_sp_bridge_port *bridge_port)
353 list_del(&bridge_port->list);
354 WARN_ON(!list_empty(&bridge_port->vlans_list));
358 static struct mlxsw_sp_bridge_port *
359 mlxsw_sp_bridge_port_get(struct mlxsw_sp_bridge *bridge,
360 struct net_device *brport_dev,
361 struct netlink_ext_ack *extack)
363 struct net_device *br_dev = netdev_master_upper_dev_get(brport_dev);
364 struct mlxsw_sp_bridge_device *bridge_device;
365 struct mlxsw_sp_bridge_port *bridge_port;
368 bridge_port = mlxsw_sp_bridge_port_find(bridge, brport_dev);
370 bridge_port->ref_count++;
374 bridge_device = mlxsw_sp_bridge_device_get(bridge, br_dev, extack);
375 if (IS_ERR(bridge_device))
376 return ERR_CAST(bridge_device);
378 bridge_port = mlxsw_sp_bridge_port_create(bridge_device, brport_dev);
381 goto err_bridge_port_create;
386 err_bridge_port_create:
387 mlxsw_sp_bridge_device_put(bridge, bridge_device);
391 static void mlxsw_sp_bridge_port_put(struct mlxsw_sp_bridge *bridge,
392 struct mlxsw_sp_bridge_port *bridge_port)
394 struct mlxsw_sp_bridge_device *bridge_device;
396 if (--bridge_port->ref_count != 0)
398 bridge_device = bridge_port->bridge_device;
399 mlxsw_sp_bridge_port_destroy(bridge_port);
400 mlxsw_sp_bridge_device_put(bridge, bridge_device);
403 static struct mlxsw_sp_port_vlan *
404 mlxsw_sp_port_vlan_find_by_bridge(struct mlxsw_sp_port *mlxsw_sp_port,
405 const struct mlxsw_sp_bridge_device *
409 struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan;
411 list_for_each_entry(mlxsw_sp_port_vlan, &mlxsw_sp_port->vlans_list,
413 if (!mlxsw_sp_port_vlan->bridge_port)
415 if (mlxsw_sp_port_vlan->bridge_port->bridge_device !=
418 if (bridge_device->vlan_enabled &&
419 mlxsw_sp_port_vlan->vid != vid)
421 return mlxsw_sp_port_vlan;
427 static struct mlxsw_sp_port_vlan*
428 mlxsw_sp_port_vlan_find_by_fid(struct mlxsw_sp_port *mlxsw_sp_port,
431 struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan;
433 list_for_each_entry(mlxsw_sp_port_vlan, &mlxsw_sp_port->vlans_list,
435 struct mlxsw_sp_fid *fid = mlxsw_sp_port_vlan->fid;
437 if (fid && mlxsw_sp_fid_index(fid) == fid_index)
438 return mlxsw_sp_port_vlan;
444 static struct mlxsw_sp_bridge_vlan *
445 mlxsw_sp_bridge_vlan_find(const struct mlxsw_sp_bridge_port *bridge_port,
448 struct mlxsw_sp_bridge_vlan *bridge_vlan;
450 list_for_each_entry(bridge_vlan, &bridge_port->vlans_list, list) {
451 if (bridge_vlan->vid == vid)
458 static struct mlxsw_sp_bridge_vlan *
459 mlxsw_sp_bridge_vlan_create(struct mlxsw_sp_bridge_port *bridge_port, u16 vid)
461 struct mlxsw_sp_bridge_vlan *bridge_vlan;
463 bridge_vlan = kzalloc(sizeof(*bridge_vlan), GFP_KERNEL);
467 INIT_LIST_HEAD(&bridge_vlan->port_vlan_list);
468 bridge_vlan->vid = vid;
469 list_add(&bridge_vlan->list, &bridge_port->vlans_list);
475 mlxsw_sp_bridge_vlan_destroy(struct mlxsw_sp_bridge_vlan *bridge_vlan)
477 list_del(&bridge_vlan->list);
478 WARN_ON(!list_empty(&bridge_vlan->port_vlan_list));
482 static struct mlxsw_sp_bridge_vlan *
483 mlxsw_sp_bridge_vlan_get(struct mlxsw_sp_bridge_port *bridge_port, u16 vid)
485 struct mlxsw_sp_bridge_vlan *bridge_vlan;
487 bridge_vlan = mlxsw_sp_bridge_vlan_find(bridge_port, vid);
491 return mlxsw_sp_bridge_vlan_create(bridge_port, vid);
494 static void mlxsw_sp_bridge_vlan_put(struct mlxsw_sp_bridge_vlan *bridge_vlan)
496 if (list_empty(&bridge_vlan->port_vlan_list))
497 mlxsw_sp_bridge_vlan_destroy(bridge_vlan);
501 mlxsw_sp_port_bridge_vlan_stp_set(struct mlxsw_sp_port *mlxsw_sp_port,
502 struct mlxsw_sp_bridge_vlan *bridge_vlan,
505 struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan;
507 list_for_each_entry(mlxsw_sp_port_vlan, &bridge_vlan->port_vlan_list,
509 if (mlxsw_sp_port_vlan->mlxsw_sp_port != mlxsw_sp_port)
511 return mlxsw_sp_port_vid_stp_set(mlxsw_sp_port,
512 bridge_vlan->vid, state);
518 static int mlxsw_sp_port_attr_stp_state_set(struct mlxsw_sp_port *mlxsw_sp_port,
519 struct switchdev_trans *trans,
520 struct net_device *orig_dev,
523 struct mlxsw_sp_bridge_port *bridge_port;
524 struct mlxsw_sp_bridge_vlan *bridge_vlan;
527 if (switchdev_trans_ph_prepare(trans))
530 /* It's possible we failed to enslave the port, yet this
531 * operation is executed due to it being deferred.
533 bridge_port = mlxsw_sp_bridge_port_find(mlxsw_sp_port->mlxsw_sp->bridge,
538 list_for_each_entry(bridge_vlan, &bridge_port->vlans_list, list) {
539 err = mlxsw_sp_port_bridge_vlan_stp_set(mlxsw_sp_port,
542 goto err_port_bridge_vlan_stp_set;
545 bridge_port->stp_state = state;
549 err_port_bridge_vlan_stp_set:
550 list_for_each_entry_continue_reverse(bridge_vlan,
551 &bridge_port->vlans_list, list)
552 mlxsw_sp_port_bridge_vlan_stp_set(mlxsw_sp_port, bridge_vlan,
553 bridge_port->stp_state);
558 mlxsw_sp_port_bridge_vlan_flood_set(struct mlxsw_sp_port *mlxsw_sp_port,
559 struct mlxsw_sp_bridge_vlan *bridge_vlan,
560 enum mlxsw_sp_flood_type packet_type,
563 struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan;
565 list_for_each_entry(mlxsw_sp_port_vlan, &bridge_vlan->port_vlan_list,
567 if (mlxsw_sp_port_vlan->mlxsw_sp_port != mlxsw_sp_port)
569 return mlxsw_sp_fid_flood_set(mlxsw_sp_port_vlan->fid,
571 mlxsw_sp_port->local_port,
579 mlxsw_sp_bridge_port_flood_table_set(struct mlxsw_sp_port *mlxsw_sp_port,
580 struct mlxsw_sp_bridge_port *bridge_port,
581 enum mlxsw_sp_flood_type packet_type,
584 struct mlxsw_sp_bridge_vlan *bridge_vlan;
587 list_for_each_entry(bridge_vlan, &bridge_port->vlans_list, list) {
588 err = mlxsw_sp_port_bridge_vlan_flood_set(mlxsw_sp_port,
593 goto err_port_bridge_vlan_flood_set;
598 err_port_bridge_vlan_flood_set:
599 list_for_each_entry_continue_reverse(bridge_vlan,
600 &bridge_port->vlans_list, list)
601 mlxsw_sp_port_bridge_vlan_flood_set(mlxsw_sp_port, bridge_vlan,
602 packet_type, !member);
607 mlxsw_sp_port_bridge_vlan_learning_set(struct mlxsw_sp_port *mlxsw_sp_port,
608 struct mlxsw_sp_bridge_vlan *bridge_vlan,
611 struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan;
612 u16 vid = bridge_vlan->vid;
614 list_for_each_entry(mlxsw_sp_port_vlan, &bridge_vlan->port_vlan_list,
616 if (mlxsw_sp_port_vlan->mlxsw_sp_port != mlxsw_sp_port)
618 return mlxsw_sp_port_vid_learning_set(mlxsw_sp_port, vid, set);
625 mlxsw_sp_bridge_port_learning_set(struct mlxsw_sp_port *mlxsw_sp_port,
626 struct mlxsw_sp_bridge_port *bridge_port,
629 struct mlxsw_sp_bridge_vlan *bridge_vlan;
632 list_for_each_entry(bridge_vlan, &bridge_port->vlans_list, list) {
633 err = mlxsw_sp_port_bridge_vlan_learning_set(mlxsw_sp_port,
636 goto err_port_bridge_vlan_learning_set;
641 err_port_bridge_vlan_learning_set:
642 list_for_each_entry_continue_reverse(bridge_vlan,
643 &bridge_port->vlans_list, list)
644 mlxsw_sp_port_bridge_vlan_learning_set(mlxsw_sp_port,
649 static int mlxsw_sp_port_attr_br_pre_flags_set(struct mlxsw_sp_port
651 struct switchdev_trans *trans,
652 unsigned long brport_flags)
654 if (brport_flags & ~(BR_LEARNING | BR_FLOOD | BR_MCAST_FLOOD))
660 static int mlxsw_sp_port_attr_br_flags_set(struct mlxsw_sp_port *mlxsw_sp_port,
661 struct switchdev_trans *trans,
662 struct net_device *orig_dev,
663 unsigned long brport_flags)
665 struct mlxsw_sp_bridge_port *bridge_port;
668 if (switchdev_trans_ph_prepare(trans))
671 bridge_port = mlxsw_sp_bridge_port_find(mlxsw_sp_port->mlxsw_sp->bridge,
676 err = mlxsw_sp_bridge_port_flood_table_set(mlxsw_sp_port, bridge_port,
677 MLXSW_SP_FLOOD_TYPE_UC,
678 brport_flags & BR_FLOOD);
682 err = mlxsw_sp_bridge_port_learning_set(mlxsw_sp_port, bridge_port,
683 brport_flags & BR_LEARNING);
687 if (bridge_port->bridge_device->multicast_enabled)
690 err = mlxsw_sp_bridge_port_flood_table_set(mlxsw_sp_port, bridge_port,
691 MLXSW_SP_FLOOD_TYPE_MC,
698 memcpy(&bridge_port->flags, &brport_flags, sizeof(brport_flags));
702 static int mlxsw_sp_ageing_set(struct mlxsw_sp *mlxsw_sp, u32 ageing_time)
704 char sfdat_pl[MLXSW_REG_SFDAT_LEN];
707 mlxsw_reg_sfdat_pack(sfdat_pl, ageing_time);
708 err = mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(sfdat), sfdat_pl);
711 mlxsw_sp->bridge->ageing_time = ageing_time;
715 static int mlxsw_sp_port_attr_br_ageing_set(struct mlxsw_sp_port *mlxsw_sp_port,
716 struct switchdev_trans *trans,
717 unsigned long ageing_clock_t)
719 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
720 unsigned long ageing_jiffies = clock_t_to_jiffies(ageing_clock_t);
721 u32 ageing_time = jiffies_to_msecs(ageing_jiffies) / 1000;
723 if (switchdev_trans_ph_prepare(trans)) {
724 if (ageing_time < MLXSW_SP_MIN_AGEING_TIME ||
725 ageing_time > MLXSW_SP_MAX_AGEING_TIME)
731 return mlxsw_sp_ageing_set(mlxsw_sp, ageing_time);
734 static int mlxsw_sp_port_attr_br_vlan_set(struct mlxsw_sp_port *mlxsw_sp_port,
735 struct switchdev_trans *trans,
736 struct net_device *orig_dev,
739 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
740 struct mlxsw_sp_bridge_device *bridge_device;
742 if (!switchdev_trans_ph_prepare(trans))
745 bridge_device = mlxsw_sp_bridge_device_find(mlxsw_sp->bridge, orig_dev);
746 if (WARN_ON(!bridge_device))
749 if (bridge_device->vlan_enabled == vlan_enabled)
752 netdev_err(bridge_device->dev, "VLAN filtering can't be changed for existing bridge\n");
756 static int mlxsw_sp_port_attr_mrouter_set(struct mlxsw_sp_port *mlxsw_sp_port,
757 struct switchdev_trans *trans,
758 struct net_device *orig_dev,
759 bool is_port_mrouter)
761 struct mlxsw_sp_bridge_port *bridge_port;
764 if (switchdev_trans_ph_prepare(trans))
767 bridge_port = mlxsw_sp_bridge_port_find(mlxsw_sp_port->mlxsw_sp->bridge,
772 if (!bridge_port->bridge_device->multicast_enabled)
775 err = mlxsw_sp_bridge_port_flood_table_set(mlxsw_sp_port, bridge_port,
776 MLXSW_SP_FLOOD_TYPE_MC,
781 mlxsw_sp_port_mrouter_update_mdb(mlxsw_sp_port, bridge_port,
784 bridge_port->mrouter = is_port_mrouter;
788 static bool mlxsw_sp_mc_flood(const struct mlxsw_sp_bridge_port *bridge_port)
790 const struct mlxsw_sp_bridge_device *bridge_device;
792 bridge_device = bridge_port->bridge_device;
793 return bridge_device->multicast_enabled ? bridge_port->mrouter :
794 bridge_port->flags & BR_MCAST_FLOOD;
797 static int mlxsw_sp_port_mc_disabled_set(struct mlxsw_sp_port *mlxsw_sp_port,
798 struct switchdev_trans *trans,
799 struct net_device *orig_dev,
802 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
803 struct mlxsw_sp_bridge_device *bridge_device;
804 struct mlxsw_sp_bridge_port *bridge_port;
807 if (switchdev_trans_ph_prepare(trans))
810 /* It's possible we failed to enslave the port, yet this
811 * operation is executed due to it being deferred.
813 bridge_device = mlxsw_sp_bridge_device_find(mlxsw_sp->bridge, orig_dev);
817 if (bridge_device->multicast_enabled != !mc_disabled) {
818 bridge_device->multicast_enabled = !mc_disabled;
819 mlxsw_sp_bridge_mdb_mc_enable_sync(mlxsw_sp_port,
823 list_for_each_entry(bridge_port, &bridge_device->ports_list, list) {
824 enum mlxsw_sp_flood_type packet_type = MLXSW_SP_FLOOD_TYPE_MC;
825 bool member = mlxsw_sp_mc_flood(bridge_port);
827 err = mlxsw_sp_bridge_port_flood_table_set(mlxsw_sp_port,
829 packet_type, member);
834 bridge_device->multicast_enabled = !mc_disabled;
839 static int mlxsw_sp_smid_router_port_set(struct mlxsw_sp *mlxsw_sp,
840 u16 mid_idx, bool add)
845 smid_pl = kmalloc(MLXSW_REG_SMID_LEN, GFP_KERNEL);
849 mlxsw_reg_smid_pack(smid_pl, mid_idx,
850 mlxsw_sp_router_port(mlxsw_sp), add);
851 err = mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(smid), smid_pl);
857 mlxsw_sp_bridge_mrouter_update_mdb(struct mlxsw_sp *mlxsw_sp,
858 struct mlxsw_sp_bridge_device *bridge_device,
861 struct mlxsw_sp_mid *mid;
863 list_for_each_entry(mid, &bridge_device->mids_list, list)
864 mlxsw_sp_smid_router_port_set(mlxsw_sp, mid->mid, add);
868 mlxsw_sp_port_attr_br_mrouter_set(struct mlxsw_sp_port *mlxsw_sp_port,
869 struct switchdev_trans *trans,
870 struct net_device *orig_dev,
873 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
874 struct mlxsw_sp_bridge_device *bridge_device;
876 if (switchdev_trans_ph_prepare(trans))
879 /* It's possible we failed to enslave the port, yet this
880 * operation is executed due to it being deferred.
882 bridge_device = mlxsw_sp_bridge_device_find(mlxsw_sp->bridge, orig_dev);
886 if (bridge_device->mrouter != is_mrouter)
887 mlxsw_sp_bridge_mrouter_update_mdb(mlxsw_sp, bridge_device,
889 bridge_device->mrouter = is_mrouter;
893 static int mlxsw_sp_port_attr_set(struct net_device *dev,
894 const struct switchdev_attr *attr,
895 struct switchdev_trans *trans)
897 struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev);
901 case SWITCHDEV_ATTR_ID_PORT_STP_STATE:
902 err = mlxsw_sp_port_attr_stp_state_set(mlxsw_sp_port, trans,
906 case SWITCHDEV_ATTR_ID_PORT_PRE_BRIDGE_FLAGS:
907 err = mlxsw_sp_port_attr_br_pre_flags_set(mlxsw_sp_port,
909 attr->u.brport_flags);
911 case SWITCHDEV_ATTR_ID_PORT_BRIDGE_FLAGS:
912 err = mlxsw_sp_port_attr_br_flags_set(mlxsw_sp_port, trans,
914 attr->u.brport_flags);
916 case SWITCHDEV_ATTR_ID_BRIDGE_AGEING_TIME:
917 err = mlxsw_sp_port_attr_br_ageing_set(mlxsw_sp_port, trans,
918 attr->u.ageing_time);
920 case SWITCHDEV_ATTR_ID_BRIDGE_VLAN_FILTERING:
921 err = mlxsw_sp_port_attr_br_vlan_set(mlxsw_sp_port, trans,
923 attr->u.vlan_filtering);
925 case SWITCHDEV_ATTR_ID_PORT_MROUTER:
926 err = mlxsw_sp_port_attr_mrouter_set(mlxsw_sp_port, trans,
930 case SWITCHDEV_ATTR_ID_BRIDGE_MC_DISABLED:
931 err = mlxsw_sp_port_mc_disabled_set(mlxsw_sp_port, trans,
933 attr->u.mc_disabled);
935 case SWITCHDEV_ATTR_ID_BRIDGE_MROUTER:
936 err = mlxsw_sp_port_attr_br_mrouter_set(mlxsw_sp_port, trans,
945 if (switchdev_trans_ph_commit(trans))
946 mlxsw_sp_span_respin(mlxsw_sp_port->mlxsw_sp);
952 mlxsw_sp_port_vlan_fid_join(struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan,
953 struct mlxsw_sp_bridge_port *bridge_port,
954 struct netlink_ext_ack *extack)
956 struct mlxsw_sp_port *mlxsw_sp_port = mlxsw_sp_port_vlan->mlxsw_sp_port;
957 struct mlxsw_sp_bridge_device *bridge_device;
958 u8 local_port = mlxsw_sp_port->local_port;
959 u16 vid = mlxsw_sp_port_vlan->vid;
960 struct mlxsw_sp_fid *fid;
963 bridge_device = bridge_port->bridge_device;
964 fid = bridge_device->ops->fid_get(bridge_device, vid, extack);
968 err = mlxsw_sp_fid_flood_set(fid, MLXSW_SP_FLOOD_TYPE_UC, local_port,
969 bridge_port->flags & BR_FLOOD);
971 goto err_fid_uc_flood_set;
973 err = mlxsw_sp_fid_flood_set(fid, MLXSW_SP_FLOOD_TYPE_MC, local_port,
974 mlxsw_sp_mc_flood(bridge_port));
976 goto err_fid_mc_flood_set;
978 err = mlxsw_sp_fid_flood_set(fid, MLXSW_SP_FLOOD_TYPE_BC, local_port,
981 goto err_fid_bc_flood_set;
983 err = mlxsw_sp_fid_port_vid_map(fid, mlxsw_sp_port, vid);
985 goto err_fid_port_vid_map;
987 mlxsw_sp_port_vlan->fid = fid;
991 err_fid_port_vid_map:
992 mlxsw_sp_fid_flood_set(fid, MLXSW_SP_FLOOD_TYPE_BC, local_port, false);
993 err_fid_bc_flood_set:
994 mlxsw_sp_fid_flood_set(fid, MLXSW_SP_FLOOD_TYPE_MC, local_port, false);
995 err_fid_mc_flood_set:
996 mlxsw_sp_fid_flood_set(fid, MLXSW_SP_FLOOD_TYPE_UC, local_port, false);
997 err_fid_uc_flood_set:
998 mlxsw_sp_fid_put(fid);
1003 mlxsw_sp_port_vlan_fid_leave(struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan)
1005 struct mlxsw_sp_port *mlxsw_sp_port = mlxsw_sp_port_vlan->mlxsw_sp_port;
1006 struct mlxsw_sp_fid *fid = mlxsw_sp_port_vlan->fid;
1007 u8 local_port = mlxsw_sp_port->local_port;
1008 u16 vid = mlxsw_sp_port_vlan->vid;
1010 mlxsw_sp_port_vlan->fid = NULL;
1011 mlxsw_sp_fid_port_vid_unmap(fid, mlxsw_sp_port, vid);
1012 mlxsw_sp_fid_flood_set(fid, MLXSW_SP_FLOOD_TYPE_BC, local_port, false);
1013 mlxsw_sp_fid_flood_set(fid, MLXSW_SP_FLOOD_TYPE_MC, local_port, false);
1014 mlxsw_sp_fid_flood_set(fid, MLXSW_SP_FLOOD_TYPE_UC, local_port, false);
1015 mlxsw_sp_fid_put(fid);
1019 mlxsw_sp_port_pvid_determine(const struct mlxsw_sp_port *mlxsw_sp_port,
1020 u16 vid, bool is_pvid)
1024 else if (mlxsw_sp_port->pvid == vid)
1025 return 0; /* Dis-allow untagged packets */
1027 return mlxsw_sp_port->pvid;
1031 mlxsw_sp_port_vlan_bridge_join(struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan,
1032 struct mlxsw_sp_bridge_port *bridge_port,
1033 struct netlink_ext_ack *extack)
1035 struct mlxsw_sp_port *mlxsw_sp_port = mlxsw_sp_port_vlan->mlxsw_sp_port;
1036 struct mlxsw_sp_bridge_vlan *bridge_vlan;
1037 u16 vid = mlxsw_sp_port_vlan->vid;
1040 /* No need to continue if only VLAN flags were changed */
1041 if (mlxsw_sp_port_vlan->bridge_port)
1044 err = mlxsw_sp_port_vlan_fid_join(mlxsw_sp_port_vlan, bridge_port,
1049 err = mlxsw_sp_port_vid_learning_set(mlxsw_sp_port, vid,
1050 bridge_port->flags & BR_LEARNING);
1052 goto err_port_vid_learning_set;
1054 err = mlxsw_sp_port_vid_stp_set(mlxsw_sp_port, vid,
1055 bridge_port->stp_state);
1057 goto err_port_vid_stp_set;
1059 bridge_vlan = mlxsw_sp_bridge_vlan_get(bridge_port, vid);
1062 goto err_bridge_vlan_get;
1065 list_add(&mlxsw_sp_port_vlan->bridge_vlan_node,
1066 &bridge_vlan->port_vlan_list);
1068 mlxsw_sp_bridge_port_get(mlxsw_sp_port->mlxsw_sp->bridge,
1069 bridge_port->dev, extack);
1070 mlxsw_sp_port_vlan->bridge_port = bridge_port;
1074 err_bridge_vlan_get:
1075 mlxsw_sp_port_vid_stp_set(mlxsw_sp_port, vid, BR_STATE_DISABLED);
1076 err_port_vid_stp_set:
1077 mlxsw_sp_port_vid_learning_set(mlxsw_sp_port, vid, false);
1078 err_port_vid_learning_set:
1079 mlxsw_sp_port_vlan_fid_leave(mlxsw_sp_port_vlan);
1084 mlxsw_sp_port_vlan_bridge_leave(struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan)
1086 struct mlxsw_sp_port *mlxsw_sp_port = mlxsw_sp_port_vlan->mlxsw_sp_port;
1087 struct mlxsw_sp_fid *fid = mlxsw_sp_port_vlan->fid;
1088 struct mlxsw_sp_bridge_vlan *bridge_vlan;
1089 struct mlxsw_sp_bridge_port *bridge_port;
1090 u16 vid = mlxsw_sp_port_vlan->vid;
1091 bool last_port, last_vlan;
1093 if (WARN_ON(mlxsw_sp_fid_type(fid) != MLXSW_SP_FID_TYPE_8021Q &&
1094 mlxsw_sp_fid_type(fid) != MLXSW_SP_FID_TYPE_8021D))
1097 bridge_port = mlxsw_sp_port_vlan->bridge_port;
1098 last_vlan = list_is_singular(&bridge_port->vlans_list);
1099 bridge_vlan = mlxsw_sp_bridge_vlan_find(bridge_port, vid);
1100 last_port = list_is_singular(&bridge_vlan->port_vlan_list);
1102 list_del(&mlxsw_sp_port_vlan->bridge_vlan_node);
1103 mlxsw_sp_bridge_vlan_put(bridge_vlan);
1104 mlxsw_sp_port_vid_stp_set(mlxsw_sp_port, vid, BR_STATE_DISABLED);
1105 mlxsw_sp_port_vid_learning_set(mlxsw_sp_port, vid, false);
1107 mlxsw_sp_bridge_port_fdb_flush(mlxsw_sp_port->mlxsw_sp,
1109 mlxsw_sp_fid_index(fid));
1111 mlxsw_sp_bridge_port_mdb_flush(mlxsw_sp_port, bridge_port);
1113 mlxsw_sp_port_vlan_fid_leave(mlxsw_sp_port_vlan);
1115 mlxsw_sp_bridge_port_put(mlxsw_sp_port->mlxsw_sp->bridge, bridge_port);
1116 mlxsw_sp_port_vlan->bridge_port = NULL;
1120 mlxsw_sp_bridge_port_vlan_add(struct mlxsw_sp_port *mlxsw_sp_port,
1121 struct mlxsw_sp_bridge_port *bridge_port,
1122 u16 vid, bool is_untagged, bool is_pvid,
1123 struct netlink_ext_ack *extack)
1125 u16 pvid = mlxsw_sp_port_pvid_determine(mlxsw_sp_port, vid, is_pvid);
1126 struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan;
1127 u16 old_pvid = mlxsw_sp_port->pvid;
1130 /* The only valid scenario in which a port-vlan already exists, is if
1131 * the VLAN flags were changed and the port-vlan is associated with the
1132 * correct bridge port
1134 mlxsw_sp_port_vlan = mlxsw_sp_port_vlan_find_by_vid(mlxsw_sp_port, vid);
1135 if (mlxsw_sp_port_vlan &&
1136 mlxsw_sp_port_vlan->bridge_port != bridge_port)
1139 if (!mlxsw_sp_port_vlan) {
1140 mlxsw_sp_port_vlan = mlxsw_sp_port_vlan_create(mlxsw_sp_port,
1142 if (IS_ERR(mlxsw_sp_port_vlan))
1143 return PTR_ERR(mlxsw_sp_port_vlan);
1146 err = mlxsw_sp_port_vlan_set(mlxsw_sp_port, vid, vid, true,
1149 goto err_port_vlan_set;
1151 err = mlxsw_sp_port_pvid_set(mlxsw_sp_port, pvid);
1153 goto err_port_pvid_set;
1155 err = mlxsw_sp_port_vlan_bridge_join(mlxsw_sp_port_vlan, bridge_port,
1158 goto err_port_vlan_bridge_join;
1162 err_port_vlan_bridge_join:
1163 mlxsw_sp_port_pvid_set(mlxsw_sp_port, old_pvid);
1165 mlxsw_sp_port_vlan_set(mlxsw_sp_port, vid, vid, false, false);
1167 mlxsw_sp_port_vlan_destroy(mlxsw_sp_port_vlan);
1172 mlxsw_sp_br_ban_rif_pvid_change(struct mlxsw_sp *mlxsw_sp,
1173 const struct net_device *br_dev,
1174 const struct switchdev_obj_port_vlan *vlan)
1179 pvid = mlxsw_sp_rif_vid(mlxsw_sp, br_dev);
1183 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) {
1184 if (vlan->flags & BRIDGE_VLAN_INFO_PVID) {
1186 netdev_err(br_dev, "Can't change PVID, it's used by router interface\n");
1191 netdev_err(br_dev, "Can't remove PVID, it's used by router interface\n");
1200 static int mlxsw_sp_port_vlans_add(struct mlxsw_sp_port *mlxsw_sp_port,
1201 const struct switchdev_obj_port_vlan *vlan,
1202 struct switchdev_trans *trans,
1203 struct netlink_ext_ack *extack)
1205 bool flag_untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
1206 bool flag_pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
1207 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
1208 struct net_device *orig_dev = vlan->obj.orig_dev;
1209 struct mlxsw_sp_bridge_port *bridge_port;
1212 if (netif_is_bridge_master(orig_dev)) {
1215 if ((vlan->flags & BRIDGE_VLAN_INFO_BRENTRY) &&
1216 br_vlan_enabled(orig_dev) &&
1217 switchdev_trans_ph_prepare(trans))
1218 err = mlxsw_sp_br_ban_rif_pvid_change(mlxsw_sp,
1225 if (switchdev_trans_ph_commit(trans))
1228 bridge_port = mlxsw_sp_bridge_port_find(mlxsw_sp->bridge, orig_dev);
1229 if (WARN_ON(!bridge_port))
1232 if (!bridge_port->bridge_device->vlan_enabled)
1235 for (vid = vlan->vid_begin; vid <= vlan->vid_end; vid++) {
1238 err = mlxsw_sp_bridge_port_vlan_add(mlxsw_sp_port, bridge_port,
1248 static enum mlxsw_reg_sfdf_flush_type mlxsw_sp_fdb_flush_type(bool lagged)
1250 return lagged ? MLXSW_REG_SFDF_FLUSH_PER_LAG_AND_FID :
1251 MLXSW_REG_SFDF_FLUSH_PER_PORT_AND_FID;
1255 mlxsw_sp_bridge_port_fdb_flush(struct mlxsw_sp *mlxsw_sp,
1256 struct mlxsw_sp_bridge_port *bridge_port,
1259 bool lagged = bridge_port->lagged;
1260 char sfdf_pl[MLXSW_REG_SFDF_LEN];
1263 system_port = lagged ? bridge_port->lag_id : bridge_port->system_port;
1264 mlxsw_reg_sfdf_pack(sfdf_pl, mlxsw_sp_fdb_flush_type(lagged));
1265 mlxsw_reg_sfdf_fid_set(sfdf_pl, fid_index);
1266 mlxsw_reg_sfdf_port_fid_system_port_set(sfdf_pl, system_port);
1268 return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(sfdf), sfdf_pl);
1271 static enum mlxsw_reg_sfd_rec_policy mlxsw_sp_sfd_rec_policy(bool dynamic)
1273 return dynamic ? MLXSW_REG_SFD_REC_POLICY_DYNAMIC_ENTRY_INGRESS :
1274 MLXSW_REG_SFD_REC_POLICY_DYNAMIC_ENTRY_MLAG;
1277 static enum mlxsw_reg_sfd_op mlxsw_sp_sfd_op(bool adding)
1279 return adding ? MLXSW_REG_SFD_OP_WRITE_EDIT :
1280 MLXSW_REG_SFD_OP_WRITE_REMOVE;
1283 static int mlxsw_sp_port_fdb_tunnel_uc_op(struct mlxsw_sp *mlxsw_sp,
1284 const char *mac, u16 fid,
1285 enum mlxsw_sp_l3proto proto,
1286 const union mlxsw_sp_l3addr *addr,
1287 bool adding, bool dynamic)
1289 enum mlxsw_reg_sfd_uc_tunnel_protocol sfd_proto;
1296 case MLXSW_SP_L3_PROTO_IPV4:
1297 uip = be32_to_cpu(addr->addr4);
1298 sfd_proto = MLXSW_REG_SFD_UC_TUNNEL_PROTOCOL_IPV4;
1300 case MLXSW_SP_L3_PROTO_IPV6:
1306 sfd_pl = kmalloc(MLXSW_REG_SFD_LEN, GFP_KERNEL);
1310 mlxsw_reg_sfd_pack(sfd_pl, mlxsw_sp_sfd_op(adding), 0);
1311 mlxsw_reg_sfd_uc_tunnel_pack(sfd_pl, 0,
1312 mlxsw_sp_sfd_rec_policy(dynamic), mac, fid,
1313 MLXSW_REG_SFD_REC_ACTION_NOP, uip,
1315 num_rec = mlxsw_reg_sfd_num_rec_get(sfd_pl);
1316 err = mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(sfd), sfd_pl);
1320 if (num_rec != mlxsw_reg_sfd_num_rec_get(sfd_pl))
1328 static int __mlxsw_sp_port_fdb_uc_op(struct mlxsw_sp *mlxsw_sp, u8 local_port,
1329 const char *mac, u16 fid, bool adding,
1330 enum mlxsw_reg_sfd_rec_action action,
1331 enum mlxsw_reg_sfd_rec_policy policy)
1337 sfd_pl = kmalloc(MLXSW_REG_SFD_LEN, GFP_KERNEL);
1341 mlxsw_reg_sfd_pack(sfd_pl, mlxsw_sp_sfd_op(adding), 0);
1342 mlxsw_reg_sfd_uc_pack(sfd_pl, 0, policy, mac, fid, action, local_port);
1343 num_rec = mlxsw_reg_sfd_num_rec_get(sfd_pl);
1344 err = mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(sfd), sfd_pl);
1348 if (num_rec != mlxsw_reg_sfd_num_rec_get(sfd_pl))
1356 static int mlxsw_sp_port_fdb_uc_op(struct mlxsw_sp *mlxsw_sp, u8 local_port,
1357 const char *mac, u16 fid, bool adding,
1360 return __mlxsw_sp_port_fdb_uc_op(mlxsw_sp, local_port, mac, fid, adding,
1361 MLXSW_REG_SFD_REC_ACTION_NOP,
1362 mlxsw_sp_sfd_rec_policy(dynamic));
1365 int mlxsw_sp_rif_fdb_op(struct mlxsw_sp *mlxsw_sp, const char *mac, u16 fid,
1368 return __mlxsw_sp_port_fdb_uc_op(mlxsw_sp, 0, mac, fid, adding,
1369 MLXSW_REG_SFD_REC_ACTION_FORWARD_IP_ROUTER,
1370 MLXSW_REG_SFD_REC_POLICY_STATIC_ENTRY);
1373 static int mlxsw_sp_port_fdb_uc_lag_op(struct mlxsw_sp *mlxsw_sp, u16 lag_id,
1374 const char *mac, u16 fid, u16 lag_vid,
1375 bool adding, bool dynamic)
1381 sfd_pl = kmalloc(MLXSW_REG_SFD_LEN, GFP_KERNEL);
1385 mlxsw_reg_sfd_pack(sfd_pl, mlxsw_sp_sfd_op(adding), 0);
1386 mlxsw_reg_sfd_uc_lag_pack(sfd_pl, 0, mlxsw_sp_sfd_rec_policy(dynamic),
1387 mac, fid, MLXSW_REG_SFD_REC_ACTION_NOP,
1389 num_rec = mlxsw_reg_sfd_num_rec_get(sfd_pl);
1390 err = mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(sfd), sfd_pl);
1394 if (num_rec != mlxsw_reg_sfd_num_rec_get(sfd_pl))
1403 mlxsw_sp_port_fdb_set(struct mlxsw_sp_port *mlxsw_sp_port,
1404 struct switchdev_notifier_fdb_info *fdb_info, bool adding)
1406 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
1407 struct net_device *orig_dev = fdb_info->info.dev;
1408 struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan;
1409 struct mlxsw_sp_bridge_device *bridge_device;
1410 struct mlxsw_sp_bridge_port *bridge_port;
1413 bridge_port = mlxsw_sp_bridge_port_find(mlxsw_sp->bridge, orig_dev);
1417 bridge_device = bridge_port->bridge_device;
1418 mlxsw_sp_port_vlan = mlxsw_sp_port_vlan_find_by_bridge(mlxsw_sp_port,
1421 if (!mlxsw_sp_port_vlan)
1424 fid_index = mlxsw_sp_fid_index(mlxsw_sp_port_vlan->fid);
1425 vid = mlxsw_sp_port_vlan->vid;
1427 if (!bridge_port->lagged)
1428 return mlxsw_sp_port_fdb_uc_op(mlxsw_sp,
1429 bridge_port->system_port,
1430 fdb_info->addr, fid_index,
1433 return mlxsw_sp_port_fdb_uc_lag_op(mlxsw_sp,
1434 bridge_port->lag_id,
1435 fdb_info->addr, fid_index,
1436 vid, adding, false);
1439 static int mlxsw_sp_port_mdb_op(struct mlxsw_sp *mlxsw_sp, const char *addr,
1440 u16 fid, u16 mid_idx, bool adding)
1446 sfd_pl = kmalloc(MLXSW_REG_SFD_LEN, GFP_KERNEL);
1450 mlxsw_reg_sfd_pack(sfd_pl, mlxsw_sp_sfd_op(adding), 0);
1451 mlxsw_reg_sfd_mc_pack(sfd_pl, 0, addr, fid,
1452 MLXSW_REG_SFD_REC_ACTION_NOP, mid_idx);
1453 num_rec = mlxsw_reg_sfd_num_rec_get(sfd_pl);
1454 err = mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(sfd), sfd_pl);
1458 if (num_rec != mlxsw_reg_sfd_num_rec_get(sfd_pl))
1466 static int mlxsw_sp_port_smid_full_entry(struct mlxsw_sp *mlxsw_sp, u16 mid_idx,
1468 bool set_router_port)
1473 smid_pl = kmalloc(MLXSW_REG_SMID_LEN, GFP_KERNEL);
1477 mlxsw_reg_smid_pack(smid_pl, mid_idx, 0, false);
1478 for (i = 1; i < mlxsw_core_max_ports(mlxsw_sp->core); i++) {
1479 if (mlxsw_sp->ports[i])
1480 mlxsw_reg_smid_port_mask_set(smid_pl, i, 1);
1483 mlxsw_reg_smid_port_mask_set(smid_pl,
1484 mlxsw_sp_router_port(mlxsw_sp), 1);
1486 for_each_set_bit(i, ports_bitmap, mlxsw_core_max_ports(mlxsw_sp->core))
1487 mlxsw_reg_smid_port_set(smid_pl, i, 1);
1489 mlxsw_reg_smid_port_set(smid_pl, mlxsw_sp_router_port(mlxsw_sp),
1492 err = mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(smid), smid_pl);
1497 static int mlxsw_sp_port_smid_set(struct mlxsw_sp_port *mlxsw_sp_port,
1498 u16 mid_idx, bool add)
1500 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
1504 smid_pl = kmalloc(MLXSW_REG_SMID_LEN, GFP_KERNEL);
1508 mlxsw_reg_smid_pack(smid_pl, mid_idx, mlxsw_sp_port->local_port, add);
1509 err = mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(smid), smid_pl);
1515 mlxsw_sp_mid *__mlxsw_sp_mc_get(struct mlxsw_sp_bridge_device *bridge_device,
1516 const unsigned char *addr,
1519 struct mlxsw_sp_mid *mid;
1521 list_for_each_entry(mid, &bridge_device->mids_list, list) {
1522 if (ether_addr_equal(mid->addr, addr) && mid->fid == fid)
1529 mlxsw_sp_bridge_port_get_ports_bitmap(struct mlxsw_sp *mlxsw_sp,
1530 struct mlxsw_sp_bridge_port *bridge_port,
1531 unsigned long *ports_bitmap)
1533 struct mlxsw_sp_port *mlxsw_sp_port;
1534 u64 max_lag_members, i;
1537 if (!bridge_port->lagged) {
1538 set_bit(bridge_port->system_port, ports_bitmap);
1540 max_lag_members = MLXSW_CORE_RES_GET(mlxsw_sp->core,
1542 lag_id = bridge_port->lag_id;
1543 for (i = 0; i < max_lag_members; i++) {
1544 mlxsw_sp_port = mlxsw_sp_port_lagged_get(mlxsw_sp,
1547 set_bit(mlxsw_sp_port->local_port,
1554 mlxsw_sp_mc_get_mrouters_bitmap(unsigned long *flood_bitmap,
1555 struct mlxsw_sp_bridge_device *bridge_device,
1556 struct mlxsw_sp *mlxsw_sp)
1558 struct mlxsw_sp_bridge_port *bridge_port;
1560 list_for_each_entry(bridge_port, &bridge_device->ports_list, list) {
1561 if (bridge_port->mrouter) {
1562 mlxsw_sp_bridge_port_get_ports_bitmap(mlxsw_sp,
1570 mlxsw_sp_mc_write_mdb_entry(struct mlxsw_sp *mlxsw_sp,
1571 struct mlxsw_sp_mid *mid,
1572 struct mlxsw_sp_bridge_device *bridge_device)
1580 mid_idx = find_first_zero_bit(mlxsw_sp->bridge->mids_bitmap,
1582 if (mid_idx == MLXSW_SP_MID_MAX)
1585 num_of_ports = mlxsw_core_max_ports(mlxsw_sp->core);
1586 alloc_size = sizeof(long) * BITS_TO_LONGS(num_of_ports);
1587 flood_bitmap = kzalloc(alloc_size, GFP_KERNEL);
1591 bitmap_copy(flood_bitmap, mid->ports_in_mid, num_of_ports);
1592 mlxsw_sp_mc_get_mrouters_bitmap(flood_bitmap, bridge_device, mlxsw_sp);
1595 err = mlxsw_sp_port_smid_full_entry(mlxsw_sp, mid_idx, flood_bitmap,
1596 bridge_device->mrouter);
1597 kfree(flood_bitmap);
1601 err = mlxsw_sp_port_mdb_op(mlxsw_sp, mid->addr, mid->fid, mid_idx,
1606 set_bit(mid_idx, mlxsw_sp->bridge->mids_bitmap);
1611 static int mlxsw_sp_mc_remove_mdb_entry(struct mlxsw_sp *mlxsw_sp,
1612 struct mlxsw_sp_mid *mid)
1617 clear_bit(mid->mid, mlxsw_sp->bridge->mids_bitmap);
1619 return mlxsw_sp_port_mdb_op(mlxsw_sp, mid->addr, mid->fid, mid->mid,
1624 mlxsw_sp_mid *__mlxsw_sp_mc_alloc(struct mlxsw_sp *mlxsw_sp,
1625 struct mlxsw_sp_bridge_device *bridge_device,
1626 const unsigned char *addr,
1629 struct mlxsw_sp_mid *mid;
1632 mid = kzalloc(sizeof(*mid), GFP_KERNEL);
1636 alloc_size = sizeof(unsigned long) *
1637 BITS_TO_LONGS(mlxsw_core_max_ports(mlxsw_sp->core));
1639 mid->ports_in_mid = kzalloc(alloc_size, GFP_KERNEL);
1640 if (!mid->ports_in_mid)
1641 goto err_ports_in_mid_alloc;
1643 ether_addr_copy(mid->addr, addr);
1647 if (!bridge_device->multicast_enabled)
1650 if (!mlxsw_sp_mc_write_mdb_entry(mlxsw_sp, mid, bridge_device))
1651 goto err_write_mdb_entry;
1654 list_add_tail(&mid->list, &bridge_device->mids_list);
1657 err_write_mdb_entry:
1658 kfree(mid->ports_in_mid);
1659 err_ports_in_mid_alloc:
1664 static int mlxsw_sp_port_remove_from_mid(struct mlxsw_sp_port *mlxsw_sp_port,
1665 struct mlxsw_sp_mid *mid)
1667 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
1670 clear_bit(mlxsw_sp_port->local_port, mid->ports_in_mid);
1671 if (bitmap_empty(mid->ports_in_mid,
1672 mlxsw_core_max_ports(mlxsw_sp->core))) {
1673 err = mlxsw_sp_mc_remove_mdb_entry(mlxsw_sp, mid);
1674 list_del(&mid->list);
1675 kfree(mid->ports_in_mid);
1681 static int mlxsw_sp_port_mdb_add(struct mlxsw_sp_port *mlxsw_sp_port,
1682 const struct switchdev_obj_port_mdb *mdb,
1683 struct switchdev_trans *trans)
1685 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
1686 struct net_device *orig_dev = mdb->obj.orig_dev;
1687 struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan;
1688 struct net_device *dev = mlxsw_sp_port->dev;
1689 struct mlxsw_sp_bridge_device *bridge_device;
1690 struct mlxsw_sp_bridge_port *bridge_port;
1691 struct mlxsw_sp_mid *mid;
1695 if (switchdev_trans_ph_commit(trans))
1698 bridge_port = mlxsw_sp_bridge_port_find(mlxsw_sp->bridge, orig_dev);
1702 bridge_device = bridge_port->bridge_device;
1703 mlxsw_sp_port_vlan = mlxsw_sp_port_vlan_find_by_bridge(mlxsw_sp_port,
1706 if (!mlxsw_sp_port_vlan)
1709 fid_index = mlxsw_sp_fid_index(mlxsw_sp_port_vlan->fid);
1711 mid = __mlxsw_sp_mc_get(bridge_device, mdb->addr, fid_index);
1713 mid = __mlxsw_sp_mc_alloc(mlxsw_sp, bridge_device, mdb->addr,
1716 netdev_err(dev, "Unable to allocate MC group\n");
1720 set_bit(mlxsw_sp_port->local_port, mid->ports_in_mid);
1722 if (!bridge_device->multicast_enabled)
1725 if (bridge_port->mrouter)
1728 err = mlxsw_sp_port_smid_set(mlxsw_sp_port, mid->mid, true);
1730 netdev_err(dev, "Unable to set SMID\n");
1737 mlxsw_sp_port_remove_from_mid(mlxsw_sp_port, mid);
1742 mlxsw_sp_bridge_mdb_mc_enable_sync(struct mlxsw_sp_port *mlxsw_sp_port,
1743 struct mlxsw_sp_bridge_device
1746 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
1747 struct mlxsw_sp_mid *mid;
1750 mc_enabled = bridge_device->multicast_enabled;
1752 list_for_each_entry(mid, &bridge_device->mids_list, list) {
1754 mlxsw_sp_mc_write_mdb_entry(mlxsw_sp, mid,
1757 mlxsw_sp_mc_remove_mdb_entry(mlxsw_sp, mid);
1762 mlxsw_sp_port_mrouter_update_mdb(struct mlxsw_sp_port *mlxsw_sp_port,
1763 struct mlxsw_sp_bridge_port *bridge_port,
1766 struct mlxsw_sp_bridge_device *bridge_device;
1767 struct mlxsw_sp_mid *mid;
1769 bridge_device = bridge_port->bridge_device;
1771 list_for_each_entry(mid, &bridge_device->mids_list, list) {
1772 if (!test_bit(mlxsw_sp_port->local_port, mid->ports_in_mid))
1773 mlxsw_sp_port_smid_set(mlxsw_sp_port, mid->mid, add);
1777 static int mlxsw_sp_port_obj_add(struct net_device *dev,
1778 const struct switchdev_obj *obj,
1779 struct switchdev_trans *trans,
1780 struct netlink_ext_ack *extack)
1782 struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev);
1783 const struct switchdev_obj_port_vlan *vlan;
1787 case SWITCHDEV_OBJ_ID_PORT_VLAN:
1788 vlan = SWITCHDEV_OBJ_PORT_VLAN(obj);
1789 err = mlxsw_sp_port_vlans_add(mlxsw_sp_port, vlan, trans,
1792 if (switchdev_trans_ph_prepare(trans)) {
1793 /* The event is emitted before the changes are actually
1794 * applied to the bridge. Therefore schedule the respin
1795 * call for later, so that the respin logic sees the
1796 * updated bridge state.
1798 mlxsw_sp_span_respin(mlxsw_sp_port->mlxsw_sp);
1801 case SWITCHDEV_OBJ_ID_PORT_MDB:
1802 err = mlxsw_sp_port_mdb_add(mlxsw_sp_port,
1803 SWITCHDEV_OBJ_PORT_MDB(obj),
1815 mlxsw_sp_bridge_port_vlan_del(struct mlxsw_sp_port *mlxsw_sp_port,
1816 struct mlxsw_sp_bridge_port *bridge_port, u16 vid)
1818 u16 pvid = mlxsw_sp_port->pvid == vid ? 0 : mlxsw_sp_port->pvid;
1819 struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan;
1821 mlxsw_sp_port_vlan = mlxsw_sp_port_vlan_find_by_vid(mlxsw_sp_port, vid);
1822 if (WARN_ON(!mlxsw_sp_port_vlan))
1825 mlxsw_sp_port_vlan_bridge_leave(mlxsw_sp_port_vlan);
1826 mlxsw_sp_port_pvid_set(mlxsw_sp_port, pvid);
1827 mlxsw_sp_port_vlan_set(mlxsw_sp_port, vid, vid, false, false);
1828 mlxsw_sp_port_vlan_destroy(mlxsw_sp_port_vlan);
1831 static int mlxsw_sp_port_vlans_del(struct mlxsw_sp_port *mlxsw_sp_port,
1832 const struct switchdev_obj_port_vlan *vlan)
1834 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
1835 struct net_device *orig_dev = vlan->obj.orig_dev;
1836 struct mlxsw_sp_bridge_port *bridge_port;
1839 if (netif_is_bridge_master(orig_dev))
1842 bridge_port = mlxsw_sp_bridge_port_find(mlxsw_sp->bridge, orig_dev);
1843 if (WARN_ON(!bridge_port))
1846 if (!bridge_port->bridge_device->vlan_enabled)
1849 for (vid = vlan->vid_begin; vid <= vlan->vid_end; vid++)
1850 mlxsw_sp_bridge_port_vlan_del(mlxsw_sp_port, bridge_port, vid);
1856 __mlxsw_sp_port_mdb_del(struct mlxsw_sp_port *mlxsw_sp_port,
1857 struct mlxsw_sp_bridge_port *bridge_port,
1858 struct mlxsw_sp_mid *mid)
1860 struct net_device *dev = mlxsw_sp_port->dev;
1863 if (bridge_port->bridge_device->multicast_enabled &&
1864 !bridge_port->mrouter) {
1865 err = mlxsw_sp_port_smid_set(mlxsw_sp_port, mid->mid, false);
1867 netdev_err(dev, "Unable to remove port from SMID\n");
1870 err = mlxsw_sp_port_remove_from_mid(mlxsw_sp_port, mid);
1872 netdev_err(dev, "Unable to remove MC SFD\n");
1877 static int mlxsw_sp_port_mdb_del(struct mlxsw_sp_port *mlxsw_sp_port,
1878 const struct switchdev_obj_port_mdb *mdb)
1880 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
1881 struct net_device *orig_dev = mdb->obj.orig_dev;
1882 struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan;
1883 struct mlxsw_sp_bridge_device *bridge_device;
1884 struct net_device *dev = mlxsw_sp_port->dev;
1885 struct mlxsw_sp_bridge_port *bridge_port;
1886 struct mlxsw_sp_mid *mid;
1889 bridge_port = mlxsw_sp_bridge_port_find(mlxsw_sp->bridge, orig_dev);
1893 bridge_device = bridge_port->bridge_device;
1894 mlxsw_sp_port_vlan = mlxsw_sp_port_vlan_find_by_bridge(mlxsw_sp_port,
1897 if (!mlxsw_sp_port_vlan)
1900 fid_index = mlxsw_sp_fid_index(mlxsw_sp_port_vlan->fid);
1902 mid = __mlxsw_sp_mc_get(bridge_device, mdb->addr, fid_index);
1904 netdev_err(dev, "Unable to remove port from MC DB\n");
1908 return __mlxsw_sp_port_mdb_del(mlxsw_sp_port, bridge_port, mid);
1912 mlxsw_sp_bridge_port_mdb_flush(struct mlxsw_sp_port *mlxsw_sp_port,
1913 struct mlxsw_sp_bridge_port *bridge_port)
1915 struct mlxsw_sp_bridge_device *bridge_device;
1916 struct mlxsw_sp_mid *mid, *tmp;
1918 bridge_device = bridge_port->bridge_device;
1920 list_for_each_entry_safe(mid, tmp, &bridge_device->mids_list, list) {
1921 if (test_bit(mlxsw_sp_port->local_port, mid->ports_in_mid)) {
1922 __mlxsw_sp_port_mdb_del(mlxsw_sp_port, bridge_port,
1924 } else if (bridge_device->multicast_enabled &&
1925 bridge_port->mrouter) {
1926 mlxsw_sp_port_smid_set(mlxsw_sp_port, mid->mid, false);
1931 static int mlxsw_sp_port_obj_del(struct net_device *dev,
1932 const struct switchdev_obj *obj)
1934 struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev);
1938 case SWITCHDEV_OBJ_ID_PORT_VLAN:
1939 err = mlxsw_sp_port_vlans_del(mlxsw_sp_port,
1940 SWITCHDEV_OBJ_PORT_VLAN(obj));
1942 case SWITCHDEV_OBJ_ID_PORT_MDB:
1943 err = mlxsw_sp_port_mdb_del(mlxsw_sp_port,
1944 SWITCHDEV_OBJ_PORT_MDB(obj));
1951 mlxsw_sp_span_respin(mlxsw_sp_port->mlxsw_sp);
1956 static struct mlxsw_sp_port *mlxsw_sp_lag_rep_port(struct mlxsw_sp *mlxsw_sp,
1959 struct mlxsw_sp_port *mlxsw_sp_port;
1960 u64 max_lag_members;
1963 max_lag_members = MLXSW_CORE_RES_GET(mlxsw_sp->core,
1965 for (i = 0; i < max_lag_members; i++) {
1966 mlxsw_sp_port = mlxsw_sp_port_lagged_get(mlxsw_sp, lag_id, i);
1968 return mlxsw_sp_port;
1974 mlxsw_sp_bridge_8021q_port_join(struct mlxsw_sp_bridge_device *bridge_device,
1975 struct mlxsw_sp_bridge_port *bridge_port,
1976 struct mlxsw_sp_port *mlxsw_sp_port,
1977 struct netlink_ext_ack *extack)
1979 if (is_vlan_dev(bridge_port->dev)) {
1980 NL_SET_ERR_MSG_MOD(extack, "Can not enslave a VLAN device to a VLAN-aware bridge");
1984 /* Port is no longer usable as a router interface */
1985 if (mlxsw_sp_port->default_vlan->fid)
1986 mlxsw_sp_port_vlan_router_leave(mlxsw_sp_port->default_vlan);
1992 mlxsw_sp_bridge_8021q_port_leave(struct mlxsw_sp_bridge_device *bridge_device,
1993 struct mlxsw_sp_bridge_port *bridge_port,
1994 struct mlxsw_sp_port *mlxsw_sp_port)
1996 /* Make sure untagged frames are allowed to ingress */
1997 mlxsw_sp_port_pvid_set(mlxsw_sp_port, MLXSW_SP_DEFAULT_VID);
2001 mlxsw_sp_bridge_8021q_vxlan_join(struct mlxsw_sp_bridge_device *bridge_device,
2002 const struct net_device *vxlan_dev, u16 vid,
2003 struct netlink_ext_ack *extack)
2005 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_lower_get(bridge_device->dev);
2006 struct vxlan_dev *vxlan = netdev_priv(vxlan_dev);
2007 struct mlxsw_sp_nve_params params = {
2008 .type = MLXSW_SP_NVE_TYPE_VXLAN,
2009 .vni = vxlan->cfg.vni,
2012 struct mlxsw_sp_fid *fid;
2015 /* If the VLAN is 0, we need to find the VLAN that is configured as
2016 * PVID and egress untagged on the bridge port of the VxLAN device.
2017 * It is possible no such VLAN exists
2020 err = mlxsw_sp_vxlan_mapped_vid(vxlan_dev, &vid);
2025 fid = mlxsw_sp_fid_8021q_get(mlxsw_sp, vid);
2027 NL_SET_ERR_MSG_MOD(extack, "Failed to create 802.1Q FID");
2028 return PTR_ERR(fid);
2031 if (mlxsw_sp_fid_vni_is_set(fid)) {
2032 NL_SET_ERR_MSG_MOD(extack, "VNI is already set on FID");
2034 goto err_vni_exists;
2037 err = mlxsw_sp_nve_fid_enable(mlxsw_sp, fid, ¶ms, extack);
2039 goto err_nve_fid_enable;
2045 mlxsw_sp_fid_put(fid);
2049 static struct net_device *
2050 mlxsw_sp_bridge_8021q_vxlan_dev_find(struct net_device *br_dev, u16 vid)
2052 struct net_device *dev;
2053 struct list_head *iter;
2055 netdev_for_each_lower_dev(br_dev, dev, iter) {
2059 if (!netif_is_vxlan(dev))
2062 err = mlxsw_sp_vxlan_mapped_vid(dev, &pvid);
2063 if (err || pvid != vid)
2072 static struct mlxsw_sp_fid *
2073 mlxsw_sp_bridge_8021q_fid_get(struct mlxsw_sp_bridge_device *bridge_device,
2074 u16 vid, struct netlink_ext_ack *extack)
2076 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_lower_get(bridge_device->dev);
2078 return mlxsw_sp_fid_8021q_get(mlxsw_sp, vid);
2081 static struct mlxsw_sp_fid *
2082 mlxsw_sp_bridge_8021q_fid_lookup(struct mlxsw_sp_bridge_device *bridge_device,
2085 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_lower_get(bridge_device->dev);
2087 return mlxsw_sp_fid_8021q_lookup(mlxsw_sp, vid);
2091 mlxsw_sp_bridge_8021q_fid_vid(struct mlxsw_sp_bridge_device *bridge_device,
2092 const struct mlxsw_sp_fid *fid)
2094 return mlxsw_sp_fid_8021q_vid(fid);
2097 static const struct mlxsw_sp_bridge_ops mlxsw_sp_bridge_8021q_ops = {
2098 .port_join = mlxsw_sp_bridge_8021q_port_join,
2099 .port_leave = mlxsw_sp_bridge_8021q_port_leave,
2100 .vxlan_join = mlxsw_sp_bridge_8021q_vxlan_join,
2101 .fid_get = mlxsw_sp_bridge_8021q_fid_get,
2102 .fid_lookup = mlxsw_sp_bridge_8021q_fid_lookup,
2103 .fid_vid = mlxsw_sp_bridge_8021q_fid_vid,
2107 mlxsw_sp_port_is_br_member(const struct mlxsw_sp_port *mlxsw_sp_port,
2108 const struct net_device *br_dev)
2110 struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan;
2112 list_for_each_entry(mlxsw_sp_port_vlan, &mlxsw_sp_port->vlans_list,
2114 if (mlxsw_sp_port_vlan->bridge_port &&
2115 mlxsw_sp_port_vlan->bridge_port->bridge_device->dev ==
2124 mlxsw_sp_bridge_8021d_port_join(struct mlxsw_sp_bridge_device *bridge_device,
2125 struct mlxsw_sp_bridge_port *bridge_port,
2126 struct mlxsw_sp_port *mlxsw_sp_port,
2127 struct netlink_ext_ack *extack)
2129 struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan;
2130 struct net_device *dev = bridge_port->dev;
2133 vid = is_vlan_dev(dev) ? vlan_dev_vlan_id(dev) : MLXSW_SP_DEFAULT_VID;
2134 mlxsw_sp_port_vlan = mlxsw_sp_port_vlan_find_by_vid(mlxsw_sp_port, vid);
2135 if (WARN_ON(!mlxsw_sp_port_vlan))
2138 if (mlxsw_sp_port_is_br_member(mlxsw_sp_port, bridge_device->dev)) {
2139 NL_SET_ERR_MSG_MOD(extack, "Can not bridge VLAN uppers of the same port");
2143 /* Port is no longer usable as a router interface */
2144 if (mlxsw_sp_port_vlan->fid)
2145 mlxsw_sp_port_vlan_router_leave(mlxsw_sp_port_vlan);
2147 return mlxsw_sp_port_vlan_bridge_join(mlxsw_sp_port_vlan, bridge_port,
2152 mlxsw_sp_bridge_8021d_port_leave(struct mlxsw_sp_bridge_device *bridge_device,
2153 struct mlxsw_sp_bridge_port *bridge_port,
2154 struct mlxsw_sp_port *mlxsw_sp_port)
2156 struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan;
2157 struct net_device *dev = bridge_port->dev;
2160 vid = is_vlan_dev(dev) ? vlan_dev_vlan_id(dev) : MLXSW_SP_DEFAULT_VID;
2161 mlxsw_sp_port_vlan = mlxsw_sp_port_vlan_find_by_vid(mlxsw_sp_port, vid);
2162 if (!mlxsw_sp_port_vlan || !mlxsw_sp_port_vlan->bridge_port)
2165 mlxsw_sp_port_vlan_bridge_leave(mlxsw_sp_port_vlan);
2169 mlxsw_sp_bridge_8021d_vxlan_join(struct mlxsw_sp_bridge_device *bridge_device,
2170 const struct net_device *vxlan_dev, u16 vid,
2171 struct netlink_ext_ack *extack)
2173 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_lower_get(bridge_device->dev);
2174 struct vxlan_dev *vxlan = netdev_priv(vxlan_dev);
2175 struct mlxsw_sp_nve_params params = {
2176 .type = MLXSW_SP_NVE_TYPE_VXLAN,
2177 .vni = vxlan->cfg.vni,
2180 struct mlxsw_sp_fid *fid;
2183 fid = mlxsw_sp_fid_8021d_get(mlxsw_sp, bridge_device->dev->ifindex);
2185 NL_SET_ERR_MSG_MOD(extack, "Failed to create 802.1D FID");
2189 if (mlxsw_sp_fid_vni_is_set(fid)) {
2190 NL_SET_ERR_MSG_MOD(extack, "VNI is already set on FID");
2192 goto err_vni_exists;
2195 err = mlxsw_sp_nve_fid_enable(mlxsw_sp, fid, ¶ms, extack);
2197 goto err_nve_fid_enable;
2203 mlxsw_sp_fid_put(fid);
2207 static struct mlxsw_sp_fid *
2208 mlxsw_sp_bridge_8021d_fid_get(struct mlxsw_sp_bridge_device *bridge_device,
2209 u16 vid, struct netlink_ext_ack *extack)
2211 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_lower_get(bridge_device->dev);
2213 return mlxsw_sp_fid_8021d_get(mlxsw_sp, bridge_device->dev->ifindex);
2216 static struct mlxsw_sp_fid *
2217 mlxsw_sp_bridge_8021d_fid_lookup(struct mlxsw_sp_bridge_device *bridge_device,
2220 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_lower_get(bridge_device->dev);
2222 /* The only valid VLAN for a VLAN-unaware bridge is 0 */
2226 return mlxsw_sp_fid_8021d_lookup(mlxsw_sp, bridge_device->dev->ifindex);
2230 mlxsw_sp_bridge_8021d_fid_vid(struct mlxsw_sp_bridge_device *bridge_device,
2231 const struct mlxsw_sp_fid *fid)
2236 static const struct mlxsw_sp_bridge_ops mlxsw_sp_bridge_8021d_ops = {
2237 .port_join = mlxsw_sp_bridge_8021d_port_join,
2238 .port_leave = mlxsw_sp_bridge_8021d_port_leave,
2239 .vxlan_join = mlxsw_sp_bridge_8021d_vxlan_join,
2240 .fid_get = mlxsw_sp_bridge_8021d_fid_get,
2241 .fid_lookup = mlxsw_sp_bridge_8021d_fid_lookup,
2242 .fid_vid = mlxsw_sp_bridge_8021d_fid_vid,
2245 int mlxsw_sp_port_bridge_join(struct mlxsw_sp_port *mlxsw_sp_port,
2246 struct net_device *brport_dev,
2247 struct net_device *br_dev,
2248 struct netlink_ext_ack *extack)
2250 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
2251 struct mlxsw_sp_bridge_device *bridge_device;
2252 struct mlxsw_sp_bridge_port *bridge_port;
2255 bridge_port = mlxsw_sp_bridge_port_get(mlxsw_sp->bridge, brport_dev,
2257 if (IS_ERR(bridge_port))
2258 return PTR_ERR(bridge_port);
2259 bridge_device = bridge_port->bridge_device;
2261 err = bridge_device->ops->port_join(bridge_device, bridge_port,
2262 mlxsw_sp_port, extack);
2269 mlxsw_sp_bridge_port_put(mlxsw_sp->bridge, bridge_port);
2273 void mlxsw_sp_port_bridge_leave(struct mlxsw_sp_port *mlxsw_sp_port,
2274 struct net_device *brport_dev,
2275 struct net_device *br_dev)
2277 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
2278 struct mlxsw_sp_bridge_device *bridge_device;
2279 struct mlxsw_sp_bridge_port *bridge_port;
2281 bridge_device = mlxsw_sp_bridge_device_find(mlxsw_sp->bridge, br_dev);
2284 bridge_port = __mlxsw_sp_bridge_port_find(bridge_device, brport_dev);
2288 bridge_device->ops->port_leave(bridge_device, bridge_port,
2290 mlxsw_sp_bridge_port_put(mlxsw_sp->bridge, bridge_port);
2293 int mlxsw_sp_bridge_vxlan_join(struct mlxsw_sp *mlxsw_sp,
2294 const struct net_device *br_dev,
2295 const struct net_device *vxlan_dev, u16 vid,
2296 struct netlink_ext_ack *extack)
2298 struct mlxsw_sp_bridge_device *bridge_device;
2300 bridge_device = mlxsw_sp_bridge_device_find(mlxsw_sp->bridge, br_dev);
2301 if (WARN_ON(!bridge_device))
2304 return bridge_device->ops->vxlan_join(bridge_device, vxlan_dev, vid,
2308 void mlxsw_sp_bridge_vxlan_leave(struct mlxsw_sp *mlxsw_sp,
2309 const struct net_device *vxlan_dev)
2311 struct vxlan_dev *vxlan = netdev_priv(vxlan_dev);
2312 struct mlxsw_sp_fid *fid;
2314 /* If the VxLAN device is down, then the FID does not have a VNI */
2315 fid = mlxsw_sp_fid_lookup_by_vni(mlxsw_sp, vxlan->cfg.vni);
2319 mlxsw_sp_nve_fid_disable(mlxsw_sp, fid);
2320 /* Drop both the reference we just took during lookup and the reference
2321 * the VXLAN device took.
2323 mlxsw_sp_fid_put(fid);
2324 mlxsw_sp_fid_put(fid);
2328 mlxsw_sp_switchdev_vxlan_addr_convert(const union vxlan_addr *vxlan_addr,
2329 enum mlxsw_sp_l3proto *proto,
2330 union mlxsw_sp_l3addr *addr)
2332 if (vxlan_addr->sa.sa_family == AF_INET) {
2333 addr->addr4 = vxlan_addr->sin.sin_addr.s_addr;
2334 *proto = MLXSW_SP_L3_PROTO_IPV4;
2336 addr->addr6 = vxlan_addr->sin6.sin6_addr;
2337 *proto = MLXSW_SP_L3_PROTO_IPV6;
2342 mlxsw_sp_switchdev_addr_vxlan_convert(enum mlxsw_sp_l3proto proto,
2343 const union mlxsw_sp_l3addr *addr,
2344 union vxlan_addr *vxlan_addr)
2347 case MLXSW_SP_L3_PROTO_IPV4:
2348 vxlan_addr->sa.sa_family = AF_INET;
2349 vxlan_addr->sin.sin_addr.s_addr = addr->addr4;
2351 case MLXSW_SP_L3_PROTO_IPV6:
2352 vxlan_addr->sa.sa_family = AF_INET6;
2353 vxlan_addr->sin6.sin6_addr = addr->addr6;
2358 static void mlxsw_sp_fdb_vxlan_call_notifiers(struct net_device *dev,
2360 enum mlxsw_sp_l3proto proto,
2361 union mlxsw_sp_l3addr *addr,
2362 __be32 vni, bool adding)
2364 struct switchdev_notifier_vxlan_fdb_info info;
2365 struct vxlan_dev *vxlan = netdev_priv(dev);
2366 enum switchdev_notifier_type type;
2368 type = adding ? SWITCHDEV_VXLAN_FDB_ADD_TO_BRIDGE :
2369 SWITCHDEV_VXLAN_FDB_DEL_TO_BRIDGE;
2370 mlxsw_sp_switchdev_addr_vxlan_convert(proto, addr, &info.remote_ip);
2371 info.remote_port = vxlan->cfg.dst_port;
2372 info.remote_vni = vni;
2373 info.remote_ifindex = 0;
2374 ether_addr_copy(info.eth_addr, mac);
2376 info.offloaded = adding;
2377 call_switchdev_notifiers(type, dev, &info.info, NULL);
2380 static void mlxsw_sp_fdb_nve_call_notifiers(struct net_device *dev,
2382 enum mlxsw_sp_l3proto proto,
2383 union mlxsw_sp_l3addr *addr,
2387 if (netif_is_vxlan(dev))
2388 mlxsw_sp_fdb_vxlan_call_notifiers(dev, mac, proto, addr, vni,
2393 mlxsw_sp_fdb_call_notifiers(enum switchdev_notifier_type type,
2394 const char *mac, u16 vid,
2395 struct net_device *dev, bool offloaded)
2397 struct switchdev_notifier_fdb_info info;
2401 info.offloaded = offloaded;
2402 call_switchdev_notifiers(type, dev, &info.info, NULL);
2405 static void mlxsw_sp_fdb_notify_mac_process(struct mlxsw_sp *mlxsw_sp,
2406 char *sfn_pl, int rec_index,
2409 struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan;
2410 struct mlxsw_sp_bridge_device *bridge_device;
2411 struct mlxsw_sp_bridge_port *bridge_port;
2412 struct mlxsw_sp_port *mlxsw_sp_port;
2413 enum switchdev_notifier_type type;
2417 bool do_notification = true;
2420 mlxsw_reg_sfn_mac_unpack(sfn_pl, rec_index, mac, &fid, &local_port);
2421 mlxsw_sp_port = mlxsw_sp->ports[local_port];
2422 if (!mlxsw_sp_port) {
2423 dev_err_ratelimited(mlxsw_sp->bus_info->dev, "Incorrect local port in FDB notification\n");
2427 if (mlxsw_sp_fid_is_dummy(mlxsw_sp, fid))
2430 mlxsw_sp_port_vlan = mlxsw_sp_port_vlan_find_by_fid(mlxsw_sp_port, fid);
2431 if (!mlxsw_sp_port_vlan) {
2432 netdev_err(mlxsw_sp_port->dev, "Failed to find a matching {Port, VID} following FDB notification\n");
2436 bridge_port = mlxsw_sp_port_vlan->bridge_port;
2438 netdev_err(mlxsw_sp_port->dev, "{Port, VID} not associated with a bridge\n");
2442 bridge_device = bridge_port->bridge_device;
2443 vid = bridge_device->vlan_enabled ? mlxsw_sp_port_vlan->vid : 0;
2446 err = mlxsw_sp_port_fdb_uc_op(mlxsw_sp, local_port, mac, fid,
2449 dev_err_ratelimited(mlxsw_sp->bus_info->dev, "Failed to set FDB entry\n");
2453 if (!do_notification)
2455 type = adding ? SWITCHDEV_FDB_ADD_TO_BRIDGE : SWITCHDEV_FDB_DEL_TO_BRIDGE;
2456 mlxsw_sp_fdb_call_notifiers(type, mac, vid, bridge_port->dev, adding);
2462 do_notification = false;
2466 static void mlxsw_sp_fdb_notify_mac_lag_process(struct mlxsw_sp *mlxsw_sp,
2467 char *sfn_pl, int rec_index,
2470 struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan;
2471 struct mlxsw_sp_bridge_device *bridge_device;
2472 struct mlxsw_sp_bridge_port *bridge_port;
2473 struct mlxsw_sp_port *mlxsw_sp_port;
2474 enum switchdev_notifier_type type;
2479 bool do_notification = true;
2482 mlxsw_reg_sfn_mac_lag_unpack(sfn_pl, rec_index, mac, &fid, &lag_id);
2483 mlxsw_sp_port = mlxsw_sp_lag_rep_port(mlxsw_sp, lag_id);
2484 if (!mlxsw_sp_port) {
2485 dev_err_ratelimited(mlxsw_sp->bus_info->dev, "Cannot find port representor for LAG\n");
2489 if (mlxsw_sp_fid_is_dummy(mlxsw_sp, fid))
2492 mlxsw_sp_port_vlan = mlxsw_sp_port_vlan_find_by_fid(mlxsw_sp_port, fid);
2493 if (!mlxsw_sp_port_vlan) {
2494 netdev_err(mlxsw_sp_port->dev, "Failed to find a matching {Port, VID} following FDB notification\n");
2498 bridge_port = mlxsw_sp_port_vlan->bridge_port;
2500 netdev_err(mlxsw_sp_port->dev, "{Port, VID} not associated with a bridge\n");
2504 bridge_device = bridge_port->bridge_device;
2505 vid = bridge_device->vlan_enabled ? mlxsw_sp_port_vlan->vid : 0;
2506 lag_vid = mlxsw_sp_fid_lag_vid_valid(mlxsw_sp_port_vlan->fid) ?
2507 mlxsw_sp_port_vlan->vid : 0;
2510 err = mlxsw_sp_port_fdb_uc_lag_op(mlxsw_sp, lag_id, mac, fid, lag_vid,
2513 dev_err_ratelimited(mlxsw_sp->bus_info->dev, "Failed to set FDB entry\n");
2517 if (!do_notification)
2519 type = adding ? SWITCHDEV_FDB_ADD_TO_BRIDGE : SWITCHDEV_FDB_DEL_TO_BRIDGE;
2520 mlxsw_sp_fdb_call_notifiers(type, mac, vid, bridge_port->dev, adding);
2526 do_notification = false;
2531 __mlxsw_sp_fdb_notify_mac_uc_tunnel_process(struct mlxsw_sp *mlxsw_sp,
2532 const struct mlxsw_sp_fid *fid,
2534 struct net_device **nve_dev,
2535 u16 *p_vid, __be32 *p_vni)
2537 struct mlxsw_sp_bridge_device *bridge_device;
2538 struct net_device *br_dev, *dev;
2542 err = mlxsw_sp_fid_nve_ifindex(fid, &nve_ifindex);
2546 err = mlxsw_sp_fid_vni(fid, p_vni);
2550 dev = __dev_get_by_index(mlxsw_sp_net(mlxsw_sp), nve_ifindex);
2555 if (!netif_running(dev))
2558 if (adding && !br_port_flag_is_set(dev, BR_LEARNING))
2561 if (adding && netif_is_vxlan(dev)) {
2562 struct vxlan_dev *vxlan = netdev_priv(dev);
2564 if (!(vxlan->cfg.flags & VXLAN_F_LEARN))
2568 br_dev = netdev_master_upper_dev_get(dev);
2572 bridge_device = mlxsw_sp_bridge_device_find(mlxsw_sp->bridge, br_dev);
2576 *p_vid = bridge_device->ops->fid_vid(bridge_device, fid);
2581 static void mlxsw_sp_fdb_notify_mac_uc_tunnel_process(struct mlxsw_sp *mlxsw_sp,
2586 enum mlxsw_reg_sfn_uc_tunnel_protocol sfn_proto;
2587 enum switchdev_notifier_type type;
2588 struct net_device *nve_dev;
2589 union mlxsw_sp_l3addr addr;
2590 struct mlxsw_sp_fid *fid;
2597 mlxsw_reg_sfn_uc_tunnel_unpack(sfn_pl, rec_index, mac, &fid_index,
2600 fid = mlxsw_sp_fid_lookup_by_index(mlxsw_sp, fid_index);
2602 goto err_fid_lookup;
2604 err = mlxsw_sp_nve_learned_ip_resolve(mlxsw_sp, uip,
2605 (enum mlxsw_sp_l3proto) sfn_proto,
2608 goto err_ip_resolve;
2610 err = __mlxsw_sp_fdb_notify_mac_uc_tunnel_process(mlxsw_sp, fid, adding,
2611 &nve_dev, &vid, &vni);
2613 goto err_fdb_process;
2615 err = mlxsw_sp_port_fdb_tunnel_uc_op(mlxsw_sp, mac, fid_index,
2616 (enum mlxsw_sp_l3proto) sfn_proto,
2617 &addr, adding, true);
2621 mlxsw_sp_fdb_nve_call_notifiers(nve_dev, mac,
2622 (enum mlxsw_sp_l3proto) sfn_proto,
2623 &addr, vni, adding);
2625 type = adding ? SWITCHDEV_FDB_ADD_TO_BRIDGE :
2626 SWITCHDEV_FDB_DEL_TO_BRIDGE;
2627 mlxsw_sp_fdb_call_notifiers(type, mac, vid, nve_dev, adding);
2629 mlxsw_sp_fid_put(fid);
2636 mlxsw_sp_fid_put(fid);
2638 /* Remove an FDB entry in case we cannot process it. Otherwise the
2639 * device will keep sending the same notification over and over again.
2641 mlxsw_sp_port_fdb_tunnel_uc_op(mlxsw_sp, mac, fid_index,
2642 (enum mlxsw_sp_l3proto) sfn_proto, &addr,
2646 static void mlxsw_sp_fdb_notify_rec_process(struct mlxsw_sp *mlxsw_sp,
2647 char *sfn_pl, int rec_index)
2649 switch (mlxsw_reg_sfn_rec_type_get(sfn_pl, rec_index)) {
2650 case MLXSW_REG_SFN_REC_TYPE_LEARNED_MAC:
2651 mlxsw_sp_fdb_notify_mac_process(mlxsw_sp, sfn_pl,
2654 case MLXSW_REG_SFN_REC_TYPE_AGED_OUT_MAC:
2655 mlxsw_sp_fdb_notify_mac_process(mlxsw_sp, sfn_pl,
2658 case MLXSW_REG_SFN_REC_TYPE_LEARNED_MAC_LAG:
2659 mlxsw_sp_fdb_notify_mac_lag_process(mlxsw_sp, sfn_pl,
2662 case MLXSW_REG_SFN_REC_TYPE_AGED_OUT_MAC_LAG:
2663 mlxsw_sp_fdb_notify_mac_lag_process(mlxsw_sp, sfn_pl,
2666 case MLXSW_REG_SFN_REC_TYPE_LEARNED_UNICAST_TUNNEL:
2667 mlxsw_sp_fdb_notify_mac_uc_tunnel_process(mlxsw_sp, sfn_pl,
2670 case MLXSW_REG_SFN_REC_TYPE_AGED_OUT_UNICAST_TUNNEL:
2671 mlxsw_sp_fdb_notify_mac_uc_tunnel_process(mlxsw_sp, sfn_pl,
2677 static void mlxsw_sp_fdb_notify_work_schedule(struct mlxsw_sp *mlxsw_sp,
2680 struct mlxsw_sp_bridge *bridge = mlxsw_sp->bridge;
2681 unsigned int interval = no_delay ? 0 : bridge->fdb_notify.interval;
2683 mlxsw_core_schedule_dw(&bridge->fdb_notify.dw,
2684 msecs_to_jiffies(interval));
2687 #define MLXSW_SP_FDB_SFN_QUERIES_PER_SESSION 10
2689 static void mlxsw_sp_fdb_notify_work(struct work_struct *work)
2691 struct mlxsw_sp_bridge *bridge;
2692 struct mlxsw_sp *mlxsw_sp;
2699 sfn_pl = kmalloc(MLXSW_REG_SFN_LEN, GFP_KERNEL);
2703 bridge = container_of(work, struct mlxsw_sp_bridge, fdb_notify.dw.work);
2704 mlxsw_sp = bridge->mlxsw_sp;
2707 queries = MLXSW_SP_FDB_SFN_QUERIES_PER_SESSION;
2708 while (queries > 0) {
2709 mlxsw_reg_sfn_pack(sfn_pl);
2710 err = mlxsw_reg_query(mlxsw_sp->core, MLXSW_REG(sfn), sfn_pl);
2712 dev_err_ratelimited(mlxsw_sp->bus_info->dev, "Failed to get FDB notifications\n");
2715 num_rec = mlxsw_reg_sfn_num_rec_get(sfn_pl);
2716 for (i = 0; i < num_rec; i++)
2717 mlxsw_sp_fdb_notify_rec_process(mlxsw_sp, sfn_pl, i);
2718 if (num_rec != MLXSW_REG_SFN_REC_MAX_COUNT)
2726 mlxsw_sp_fdb_notify_work_schedule(mlxsw_sp, !queries);
2729 struct mlxsw_sp_switchdev_event_work {
2730 struct work_struct work;
2732 struct switchdev_notifier_fdb_info fdb_info;
2733 struct switchdev_notifier_vxlan_fdb_info vxlan_fdb_info;
2735 struct net_device *dev;
2736 unsigned long event;
2740 mlxsw_sp_switchdev_bridge_vxlan_fdb_event(struct mlxsw_sp *mlxsw_sp,
2741 struct mlxsw_sp_switchdev_event_work *
2743 struct mlxsw_sp_fid *fid, __be32 vni)
2745 struct switchdev_notifier_vxlan_fdb_info vxlan_fdb_info;
2746 struct switchdev_notifier_fdb_info *fdb_info;
2747 struct net_device *dev = switchdev_work->dev;
2748 enum mlxsw_sp_l3proto proto;
2749 union mlxsw_sp_l3addr addr;
2752 fdb_info = &switchdev_work->fdb_info;
2753 err = vxlan_fdb_find_uc(dev, fdb_info->addr, vni, &vxlan_fdb_info);
2757 mlxsw_sp_switchdev_vxlan_addr_convert(&vxlan_fdb_info.remote_ip,
2760 switch (switchdev_work->event) {
2761 case SWITCHDEV_FDB_ADD_TO_DEVICE:
2762 err = mlxsw_sp_port_fdb_tunnel_uc_op(mlxsw_sp,
2763 vxlan_fdb_info.eth_addr,
2764 mlxsw_sp_fid_index(fid),
2765 proto, &addr, true, false);
2768 vxlan_fdb_info.offloaded = true;
2769 call_switchdev_notifiers(SWITCHDEV_VXLAN_FDB_OFFLOADED, dev,
2770 &vxlan_fdb_info.info, NULL);
2771 mlxsw_sp_fdb_call_notifiers(SWITCHDEV_FDB_OFFLOADED,
2772 vxlan_fdb_info.eth_addr,
2773 fdb_info->vid, dev, true);
2775 case SWITCHDEV_FDB_DEL_TO_DEVICE:
2776 err = mlxsw_sp_port_fdb_tunnel_uc_op(mlxsw_sp,
2777 vxlan_fdb_info.eth_addr,
2778 mlxsw_sp_fid_index(fid),
2779 proto, &addr, false,
2781 vxlan_fdb_info.offloaded = false;
2782 call_switchdev_notifiers(SWITCHDEV_VXLAN_FDB_OFFLOADED, dev,
2783 &vxlan_fdb_info.info, NULL);
2789 mlxsw_sp_switchdev_bridge_nve_fdb_event(struct mlxsw_sp_switchdev_event_work *
2792 struct mlxsw_sp_bridge_device *bridge_device;
2793 struct net_device *dev = switchdev_work->dev;
2794 struct net_device *br_dev;
2795 struct mlxsw_sp *mlxsw_sp;
2796 struct mlxsw_sp_fid *fid;
2800 if (switchdev_work->event != SWITCHDEV_FDB_ADD_TO_DEVICE &&
2801 switchdev_work->event != SWITCHDEV_FDB_DEL_TO_DEVICE)
2804 if (switchdev_work->event == SWITCHDEV_FDB_ADD_TO_DEVICE &&
2805 !switchdev_work->fdb_info.added_by_user)
2808 if (!netif_running(dev))
2810 br_dev = netdev_master_upper_dev_get(dev);
2813 if (!netif_is_bridge_master(br_dev))
2815 mlxsw_sp = mlxsw_sp_lower_get(br_dev);
2818 bridge_device = mlxsw_sp_bridge_device_find(mlxsw_sp->bridge, br_dev);
2822 fid = bridge_device->ops->fid_lookup(bridge_device,
2823 switchdev_work->fdb_info.vid);
2827 err = mlxsw_sp_fid_vni(fid, &vni);
2831 mlxsw_sp_switchdev_bridge_vxlan_fdb_event(mlxsw_sp, switchdev_work, fid,
2835 mlxsw_sp_fid_put(fid);
2838 static void mlxsw_sp_switchdev_bridge_fdb_event_work(struct work_struct *work)
2840 struct mlxsw_sp_switchdev_event_work *switchdev_work =
2841 container_of(work, struct mlxsw_sp_switchdev_event_work, work);
2842 struct net_device *dev = switchdev_work->dev;
2843 struct switchdev_notifier_fdb_info *fdb_info;
2844 struct mlxsw_sp_port *mlxsw_sp_port;
2848 if (netif_is_vxlan(dev)) {
2849 mlxsw_sp_switchdev_bridge_nve_fdb_event(switchdev_work);
2853 mlxsw_sp_port = mlxsw_sp_port_dev_lower_find(dev);
2857 switch (switchdev_work->event) {
2858 case SWITCHDEV_FDB_ADD_TO_DEVICE:
2859 fdb_info = &switchdev_work->fdb_info;
2860 if (!fdb_info->added_by_user)
2862 err = mlxsw_sp_port_fdb_set(mlxsw_sp_port, fdb_info, true);
2865 mlxsw_sp_fdb_call_notifiers(SWITCHDEV_FDB_OFFLOADED,
2867 fdb_info->vid, dev, true);
2869 case SWITCHDEV_FDB_DEL_TO_DEVICE:
2870 fdb_info = &switchdev_work->fdb_info;
2871 mlxsw_sp_port_fdb_set(mlxsw_sp_port, fdb_info, false);
2873 case SWITCHDEV_FDB_ADD_TO_BRIDGE:
2874 case SWITCHDEV_FDB_DEL_TO_BRIDGE:
2875 /* These events are only used to potentially update an existing
2881 mlxsw_sp_span_respin(mlxsw_sp_port->mlxsw_sp);
2885 kfree(switchdev_work->fdb_info.addr);
2886 kfree(switchdev_work);
2891 mlxsw_sp_switchdev_vxlan_fdb_add(struct mlxsw_sp *mlxsw_sp,
2892 struct mlxsw_sp_switchdev_event_work *
2895 struct switchdev_notifier_vxlan_fdb_info *vxlan_fdb_info;
2896 struct mlxsw_sp_bridge_device *bridge_device;
2897 struct net_device *dev = switchdev_work->dev;
2898 u8 all_zeros_mac[ETH_ALEN] = { 0 };
2899 enum mlxsw_sp_l3proto proto;
2900 union mlxsw_sp_l3addr addr;
2901 struct net_device *br_dev;
2902 struct mlxsw_sp_fid *fid;
2906 vxlan_fdb_info = &switchdev_work->vxlan_fdb_info;
2907 br_dev = netdev_master_upper_dev_get(dev);
2909 bridge_device = mlxsw_sp_bridge_device_find(mlxsw_sp->bridge, br_dev);
2913 fid = mlxsw_sp_fid_lookup_by_vni(mlxsw_sp, vxlan_fdb_info->vni);
2917 mlxsw_sp_switchdev_vxlan_addr_convert(&vxlan_fdb_info->remote_ip,
2920 if (ether_addr_equal(vxlan_fdb_info->eth_addr, all_zeros_mac)) {
2921 err = mlxsw_sp_nve_flood_ip_add(mlxsw_sp, fid, proto, &addr);
2923 mlxsw_sp_fid_put(fid);
2926 vxlan_fdb_info->offloaded = true;
2927 call_switchdev_notifiers(SWITCHDEV_VXLAN_FDB_OFFLOADED, dev,
2928 &vxlan_fdb_info->info, NULL);
2929 mlxsw_sp_fid_put(fid);
2933 /* The device has a single FDB table, whereas Linux has two - one
2934 * in the bridge driver and another in the VxLAN driver. We only
2935 * program an entry to the device if the MAC points to the VxLAN
2936 * device in the bridge's FDB table
2938 vid = bridge_device->ops->fid_vid(bridge_device, fid);
2939 if (br_fdb_find_port(br_dev, vxlan_fdb_info->eth_addr, vid) != dev)
2940 goto err_br_fdb_find;
2942 err = mlxsw_sp_port_fdb_tunnel_uc_op(mlxsw_sp, vxlan_fdb_info->eth_addr,
2943 mlxsw_sp_fid_index(fid), proto,
2944 &addr, true, false);
2946 goto err_fdb_tunnel_uc_op;
2947 vxlan_fdb_info->offloaded = true;
2948 call_switchdev_notifiers(SWITCHDEV_VXLAN_FDB_OFFLOADED, dev,
2949 &vxlan_fdb_info->info, NULL);
2950 mlxsw_sp_fdb_call_notifiers(SWITCHDEV_FDB_OFFLOADED,
2951 vxlan_fdb_info->eth_addr, vid, dev, true);
2953 mlxsw_sp_fid_put(fid);
2957 err_fdb_tunnel_uc_op:
2959 mlxsw_sp_fid_put(fid);
2963 mlxsw_sp_switchdev_vxlan_fdb_del(struct mlxsw_sp *mlxsw_sp,
2964 struct mlxsw_sp_switchdev_event_work *
2967 struct switchdev_notifier_vxlan_fdb_info *vxlan_fdb_info;
2968 struct mlxsw_sp_bridge_device *bridge_device;
2969 struct net_device *dev = switchdev_work->dev;
2970 struct net_device *br_dev = netdev_master_upper_dev_get(dev);
2971 u8 all_zeros_mac[ETH_ALEN] = { 0 };
2972 enum mlxsw_sp_l3proto proto;
2973 union mlxsw_sp_l3addr addr;
2974 struct mlxsw_sp_fid *fid;
2977 vxlan_fdb_info = &switchdev_work->vxlan_fdb_info;
2979 bridge_device = mlxsw_sp_bridge_device_find(mlxsw_sp->bridge, br_dev);
2983 fid = mlxsw_sp_fid_lookup_by_vni(mlxsw_sp, vxlan_fdb_info->vni);
2987 mlxsw_sp_switchdev_vxlan_addr_convert(&vxlan_fdb_info->remote_ip,
2990 if (ether_addr_equal(vxlan_fdb_info->eth_addr, all_zeros_mac)) {
2991 mlxsw_sp_nve_flood_ip_del(mlxsw_sp, fid, proto, &addr);
2992 mlxsw_sp_fid_put(fid);
2996 mlxsw_sp_port_fdb_tunnel_uc_op(mlxsw_sp, vxlan_fdb_info->eth_addr,
2997 mlxsw_sp_fid_index(fid), proto, &addr,
2999 vid = bridge_device->ops->fid_vid(bridge_device, fid);
3000 mlxsw_sp_fdb_call_notifiers(SWITCHDEV_FDB_OFFLOADED,
3001 vxlan_fdb_info->eth_addr, vid, dev, false);
3003 mlxsw_sp_fid_put(fid);
3006 static void mlxsw_sp_switchdev_vxlan_fdb_event_work(struct work_struct *work)
3008 struct mlxsw_sp_switchdev_event_work *switchdev_work =
3009 container_of(work, struct mlxsw_sp_switchdev_event_work, work);
3010 struct net_device *dev = switchdev_work->dev;
3011 struct mlxsw_sp *mlxsw_sp;
3012 struct net_device *br_dev;
3016 if (!netif_running(dev))
3018 br_dev = netdev_master_upper_dev_get(dev);
3021 if (!netif_is_bridge_master(br_dev))
3023 mlxsw_sp = mlxsw_sp_lower_get(br_dev);
3027 switch (switchdev_work->event) {
3028 case SWITCHDEV_VXLAN_FDB_ADD_TO_DEVICE:
3029 mlxsw_sp_switchdev_vxlan_fdb_add(mlxsw_sp, switchdev_work);
3031 case SWITCHDEV_VXLAN_FDB_DEL_TO_DEVICE:
3032 mlxsw_sp_switchdev_vxlan_fdb_del(mlxsw_sp, switchdev_work);
3038 kfree(switchdev_work);
3043 mlxsw_sp_switchdev_vxlan_work_prepare(struct mlxsw_sp_switchdev_event_work *
3045 struct switchdev_notifier_info *info)
3047 struct vxlan_dev *vxlan = netdev_priv(switchdev_work->dev);
3048 struct switchdev_notifier_vxlan_fdb_info *vxlan_fdb_info;
3049 struct vxlan_config *cfg = &vxlan->cfg;
3050 struct netlink_ext_ack *extack;
3052 extack = switchdev_notifier_info_to_extack(info);
3053 vxlan_fdb_info = container_of(info,
3054 struct switchdev_notifier_vxlan_fdb_info,
3057 if (vxlan_fdb_info->remote_port != cfg->dst_port) {
3058 NL_SET_ERR_MSG_MOD(extack, "VxLAN: FDB: Non-default remote port is not supported");
3061 if (vxlan_fdb_info->remote_vni != cfg->vni ||
3062 vxlan_fdb_info->vni != cfg->vni) {
3063 NL_SET_ERR_MSG_MOD(extack, "VxLAN: FDB: Non-default VNI is not supported");
3066 if (vxlan_fdb_info->remote_ifindex) {
3067 NL_SET_ERR_MSG_MOD(extack, "VxLAN: FDB: Local interface is not supported");
3070 if (is_multicast_ether_addr(vxlan_fdb_info->eth_addr)) {
3071 NL_SET_ERR_MSG_MOD(extack, "VxLAN: FDB: Multicast MAC addresses not supported");
3074 if (vxlan_addr_multicast(&vxlan_fdb_info->remote_ip)) {
3075 NL_SET_ERR_MSG_MOD(extack, "VxLAN: FDB: Multicast destination IP is not supported");
3079 switchdev_work->vxlan_fdb_info = *vxlan_fdb_info;
3084 /* Called under rcu_read_lock() */
3085 static int mlxsw_sp_switchdev_event(struct notifier_block *unused,
3086 unsigned long event, void *ptr)
3088 struct net_device *dev = switchdev_notifier_info_to_dev(ptr);
3089 struct mlxsw_sp_switchdev_event_work *switchdev_work;
3090 struct switchdev_notifier_fdb_info *fdb_info;
3091 struct switchdev_notifier_info *info = ptr;
3092 struct net_device *br_dev;
3095 if (event == SWITCHDEV_PORT_ATTR_SET) {
3096 err = switchdev_handle_port_attr_set(dev, ptr,
3097 mlxsw_sp_port_dev_check,
3098 mlxsw_sp_port_attr_set);
3099 return notifier_from_errno(err);
3102 /* Tunnel devices are not our uppers, so check their master instead */
3103 br_dev = netdev_master_upper_dev_get_rcu(dev);
3106 if (!netif_is_bridge_master(br_dev))
3108 if (!mlxsw_sp_port_dev_lower_find_rcu(br_dev))
3111 switchdev_work = kzalloc(sizeof(*switchdev_work), GFP_ATOMIC);
3112 if (!switchdev_work)
3115 switchdev_work->dev = dev;
3116 switchdev_work->event = event;
3119 case SWITCHDEV_FDB_ADD_TO_DEVICE:
3120 case SWITCHDEV_FDB_DEL_TO_DEVICE:
3121 case SWITCHDEV_FDB_ADD_TO_BRIDGE:
3122 case SWITCHDEV_FDB_DEL_TO_BRIDGE:
3123 fdb_info = container_of(info,
3124 struct switchdev_notifier_fdb_info,
3126 INIT_WORK(&switchdev_work->work,
3127 mlxsw_sp_switchdev_bridge_fdb_event_work);
3128 memcpy(&switchdev_work->fdb_info, ptr,
3129 sizeof(switchdev_work->fdb_info));
3130 switchdev_work->fdb_info.addr = kzalloc(ETH_ALEN, GFP_ATOMIC);
3131 if (!switchdev_work->fdb_info.addr)
3132 goto err_addr_alloc;
3133 ether_addr_copy((u8 *)switchdev_work->fdb_info.addr,
3135 /* Take a reference on the device. This can be either
3136 * upper device containig mlxsw_sp_port or just a
3141 case SWITCHDEV_VXLAN_FDB_ADD_TO_DEVICE:
3142 case SWITCHDEV_VXLAN_FDB_DEL_TO_DEVICE:
3143 INIT_WORK(&switchdev_work->work,
3144 mlxsw_sp_switchdev_vxlan_fdb_event_work);
3145 err = mlxsw_sp_switchdev_vxlan_work_prepare(switchdev_work,
3148 goto err_vxlan_work_prepare;
3152 kfree(switchdev_work);
3156 mlxsw_core_schedule_work(&switchdev_work->work);
3160 err_vxlan_work_prepare:
3162 kfree(switchdev_work);
3166 struct notifier_block mlxsw_sp_switchdev_notifier = {
3167 .notifier_call = mlxsw_sp_switchdev_event,
3171 mlxsw_sp_switchdev_vxlan_vlan_add(struct mlxsw_sp *mlxsw_sp,
3172 struct mlxsw_sp_bridge_device *bridge_device,
3173 const struct net_device *vxlan_dev, u16 vid,
3174 bool flag_untagged, bool flag_pvid,
3175 struct netlink_ext_ack *extack)
3177 struct vxlan_dev *vxlan = netdev_priv(vxlan_dev);
3178 __be32 vni = vxlan->cfg.vni;
3179 struct mlxsw_sp_fid *fid;
3183 /* We cannot have the same VLAN as PVID and egress untagged on multiple
3184 * VxLAN devices. Note that we get this notification before the VLAN is
3185 * actually added to the bridge's database, so it is not possible for
3186 * the lookup function to return 'vxlan_dev'
3188 if (flag_untagged && flag_pvid &&
3189 mlxsw_sp_bridge_8021q_vxlan_dev_find(bridge_device->dev, vid)) {
3190 NL_SET_ERR_MSG_MOD(extack, "VLAN already mapped to a different VNI");
3194 if (!netif_running(vxlan_dev))
3197 /* First case: FID is not associated with this VNI, but the new VLAN
3198 * is both PVID and egress untagged. Need to enable NVE on the FID, if
3201 fid = mlxsw_sp_fid_lookup_by_vni(mlxsw_sp, vni);
3203 if (!flag_untagged || !flag_pvid)
3205 return mlxsw_sp_bridge_8021q_vxlan_join(bridge_device,
3206 vxlan_dev, vid, extack);
3209 /* Second case: FID is associated with the VNI and the VLAN associated
3210 * with the FID is the same as the notified VLAN. This means the flags
3211 * (PVID / egress untagged) were toggled and that NVE should be
3212 * disabled on the FID
3214 old_vid = mlxsw_sp_fid_8021q_vid(fid);
3215 if (vid == old_vid) {
3216 if (WARN_ON(flag_untagged && flag_pvid)) {
3217 mlxsw_sp_fid_put(fid);
3220 mlxsw_sp_bridge_vxlan_leave(mlxsw_sp, vxlan_dev);
3221 mlxsw_sp_fid_put(fid);
3225 /* Third case: A new VLAN was configured on the VxLAN device, but this
3226 * VLAN is not PVID, so there is nothing to do.
3229 mlxsw_sp_fid_put(fid);
3233 /* Fourth case: Thew new VLAN is PVID, which means the VLAN currently
3234 * mapped to the VNI should be unmapped
3236 mlxsw_sp_bridge_vxlan_leave(mlxsw_sp, vxlan_dev);
3237 mlxsw_sp_fid_put(fid);
3239 /* Fifth case: The new VLAN is also egress untagged, which means the
3240 * VLAN needs to be mapped to the VNI
3245 err = mlxsw_sp_bridge_8021q_vxlan_join(bridge_device, vxlan_dev, vid,
3248 goto err_vxlan_join;
3253 mlxsw_sp_bridge_8021q_vxlan_join(bridge_device, vxlan_dev, old_vid,
3259 mlxsw_sp_switchdev_vxlan_vlan_del(struct mlxsw_sp *mlxsw_sp,
3260 struct mlxsw_sp_bridge_device *bridge_device,
3261 const struct net_device *vxlan_dev, u16 vid)
3263 struct vxlan_dev *vxlan = netdev_priv(vxlan_dev);
3264 __be32 vni = vxlan->cfg.vni;
3265 struct mlxsw_sp_fid *fid;
3267 if (!netif_running(vxlan_dev))
3270 fid = mlxsw_sp_fid_lookup_by_vni(mlxsw_sp, vni);
3274 /* A different VLAN than the one mapped to the VNI is deleted */
3275 if (mlxsw_sp_fid_8021q_vid(fid) != vid)
3278 mlxsw_sp_bridge_vxlan_leave(mlxsw_sp, vxlan_dev);
3281 mlxsw_sp_fid_put(fid);
3285 mlxsw_sp_switchdev_vxlan_vlans_add(struct net_device *vxlan_dev,
3286 struct switchdev_notifier_port_obj_info *
3289 struct switchdev_obj_port_vlan *vlan =
3290 SWITCHDEV_OBJ_PORT_VLAN(port_obj_info->obj);
3291 bool flag_untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
3292 bool flag_pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
3293 struct switchdev_trans *trans = port_obj_info->trans;
3294 struct mlxsw_sp_bridge_device *bridge_device;
3295 struct netlink_ext_ack *extack;
3296 struct mlxsw_sp *mlxsw_sp;
3297 struct net_device *br_dev;
3300 extack = switchdev_notifier_info_to_extack(&port_obj_info->info);
3301 br_dev = netdev_master_upper_dev_get(vxlan_dev);
3305 mlxsw_sp = mlxsw_sp_lower_get(br_dev);
3309 port_obj_info->handled = true;
3311 if (switchdev_trans_ph_commit(trans))
3314 bridge_device = mlxsw_sp_bridge_device_find(mlxsw_sp->bridge, br_dev);
3318 if (!bridge_device->vlan_enabled)
3321 for (vid = vlan->vid_begin; vid <= vlan->vid_end; vid++) {
3324 err = mlxsw_sp_switchdev_vxlan_vlan_add(mlxsw_sp, bridge_device,
3336 mlxsw_sp_switchdev_vxlan_vlans_del(struct net_device *vxlan_dev,
3337 struct switchdev_notifier_port_obj_info *
3340 struct switchdev_obj_port_vlan *vlan =
3341 SWITCHDEV_OBJ_PORT_VLAN(port_obj_info->obj);
3342 struct mlxsw_sp_bridge_device *bridge_device;
3343 struct mlxsw_sp *mlxsw_sp;
3344 struct net_device *br_dev;
3347 br_dev = netdev_master_upper_dev_get(vxlan_dev);
3351 mlxsw_sp = mlxsw_sp_lower_get(br_dev);
3355 port_obj_info->handled = true;
3357 bridge_device = mlxsw_sp_bridge_device_find(mlxsw_sp->bridge, br_dev);
3361 if (!bridge_device->vlan_enabled)
3364 for (vid = vlan->vid_begin; vid <= vlan->vid_end; vid++)
3365 mlxsw_sp_switchdev_vxlan_vlan_del(mlxsw_sp, bridge_device,
3370 mlxsw_sp_switchdev_handle_vxlan_obj_add(struct net_device *vxlan_dev,
3371 struct switchdev_notifier_port_obj_info *
3376 switch (port_obj_info->obj->id) {
3377 case SWITCHDEV_OBJ_ID_PORT_VLAN:
3378 err = mlxsw_sp_switchdev_vxlan_vlans_add(vxlan_dev,
3389 mlxsw_sp_switchdev_handle_vxlan_obj_del(struct net_device *vxlan_dev,
3390 struct switchdev_notifier_port_obj_info *
3393 switch (port_obj_info->obj->id) {
3394 case SWITCHDEV_OBJ_ID_PORT_VLAN:
3395 mlxsw_sp_switchdev_vxlan_vlans_del(vxlan_dev, port_obj_info);
3402 static int mlxsw_sp_switchdev_blocking_event(struct notifier_block *unused,
3403 unsigned long event, void *ptr)
3405 struct net_device *dev = switchdev_notifier_info_to_dev(ptr);
3409 case SWITCHDEV_PORT_OBJ_ADD:
3410 if (netif_is_vxlan(dev))
3411 err = mlxsw_sp_switchdev_handle_vxlan_obj_add(dev, ptr);
3413 err = switchdev_handle_port_obj_add(dev, ptr,
3414 mlxsw_sp_port_dev_check,
3415 mlxsw_sp_port_obj_add);
3416 return notifier_from_errno(err);
3417 case SWITCHDEV_PORT_OBJ_DEL:
3418 if (netif_is_vxlan(dev))
3419 mlxsw_sp_switchdev_handle_vxlan_obj_del(dev, ptr);
3421 err = switchdev_handle_port_obj_del(dev, ptr,
3422 mlxsw_sp_port_dev_check,
3423 mlxsw_sp_port_obj_del);
3424 return notifier_from_errno(err);
3425 case SWITCHDEV_PORT_ATTR_SET:
3426 err = switchdev_handle_port_attr_set(dev, ptr,
3427 mlxsw_sp_port_dev_check,
3428 mlxsw_sp_port_attr_set);
3429 return notifier_from_errno(err);
3435 static struct notifier_block mlxsw_sp_switchdev_blocking_notifier = {
3436 .notifier_call = mlxsw_sp_switchdev_blocking_event,
3440 mlxsw_sp_bridge_port_stp_state(struct mlxsw_sp_bridge_port *bridge_port)
3442 return bridge_port->stp_state;
3445 static int mlxsw_sp_fdb_init(struct mlxsw_sp *mlxsw_sp)
3447 struct mlxsw_sp_bridge *bridge = mlxsw_sp->bridge;
3448 struct notifier_block *nb;
3451 err = mlxsw_sp_ageing_set(mlxsw_sp, MLXSW_SP_DEFAULT_AGEING_TIME);
3453 dev_err(mlxsw_sp->bus_info->dev, "Failed to set default ageing time\n");
3457 err = register_switchdev_notifier(&mlxsw_sp_switchdev_notifier);
3459 dev_err(mlxsw_sp->bus_info->dev, "Failed to register switchdev notifier\n");
3463 nb = &mlxsw_sp_switchdev_blocking_notifier;
3464 err = register_switchdev_blocking_notifier(nb);
3466 dev_err(mlxsw_sp->bus_info->dev, "Failed to register switchdev blocking notifier\n");
3467 goto err_register_switchdev_blocking_notifier;
3470 INIT_DELAYED_WORK(&bridge->fdb_notify.dw, mlxsw_sp_fdb_notify_work);
3471 bridge->fdb_notify.interval = MLXSW_SP_DEFAULT_LEARNING_INTERVAL;
3472 mlxsw_sp_fdb_notify_work_schedule(mlxsw_sp, false);
3475 err_register_switchdev_blocking_notifier:
3476 unregister_switchdev_notifier(&mlxsw_sp_switchdev_notifier);
3480 static void mlxsw_sp_fdb_fini(struct mlxsw_sp *mlxsw_sp)
3482 struct notifier_block *nb;
3484 cancel_delayed_work_sync(&mlxsw_sp->bridge->fdb_notify.dw);
3486 nb = &mlxsw_sp_switchdev_blocking_notifier;
3487 unregister_switchdev_blocking_notifier(nb);
3489 unregister_switchdev_notifier(&mlxsw_sp_switchdev_notifier);
3492 int mlxsw_sp_switchdev_init(struct mlxsw_sp *mlxsw_sp)
3494 struct mlxsw_sp_bridge *bridge;
3496 bridge = kzalloc(sizeof(*mlxsw_sp->bridge), GFP_KERNEL);
3499 mlxsw_sp->bridge = bridge;
3500 bridge->mlxsw_sp = mlxsw_sp;
3502 INIT_LIST_HEAD(&mlxsw_sp->bridge->bridges_list);
3504 bridge->bridge_8021q_ops = &mlxsw_sp_bridge_8021q_ops;
3505 bridge->bridge_8021d_ops = &mlxsw_sp_bridge_8021d_ops;
3507 return mlxsw_sp_fdb_init(mlxsw_sp);
3510 void mlxsw_sp_switchdev_fini(struct mlxsw_sp *mlxsw_sp)
3512 mlxsw_sp_fdb_fini(mlxsw_sp);
3513 WARN_ON(!list_empty(&mlxsw_sp->bridge->bridges_list));
3514 kfree(mlxsw_sp->bridge);