2 * drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c
3 * Copyright (c) 2015 Mellanox Technologies. All rights reserved.
4 * Copyright (c) 2015 Jiri Pirko <jiri@mellanox.com>
5 * Copyright (c) 2015 Ido Schimmel <idosch@mellanox.com>
6 * Copyright (c) 2015 Elad Raz <eladr@mellanox.com>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the names of the copyright holders nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
20 * Alternatively, this software may be distributed under the terms of the
21 * GNU General Public License ("GPL") version 2 as published by the Free
22 * Software Foundation.
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
28 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 * POSSIBILITY OF SUCH DAMAGE.
37 #include <linux/kernel.h>
38 #include <linux/types.h>
39 #include <linux/netdevice.h>
40 #include <linux/etherdevice.h>
41 #include <linux/slab.h>
42 #include <linux/device.h>
43 #include <linux/skbuff.h>
44 #include <linux/if_vlan.h>
45 #include <linux/if_bridge.h>
46 #include <linux/workqueue.h>
47 #include <linux/jiffies.h>
48 #include <linux/rtnetlink.h>
49 #include <net/switchdev.h>
55 struct mlxsw_sp_bridge_ops;
57 struct mlxsw_sp_bridge {
58 struct mlxsw_sp *mlxsw_sp;
60 struct delayed_work dw;
61 #define MLXSW_SP_DEFAULT_LEARNING_INTERVAL 100
62 unsigned int interval; /* ms */
64 #define MLXSW_SP_MIN_AGEING_TIME 10
65 #define MLXSW_SP_MAX_AGEING_TIME 1000000
66 #define MLXSW_SP_DEFAULT_AGEING_TIME 300
68 bool vlan_enabled_exists;
69 struct list_head bridges_list;
70 struct list_head mids_list;
71 DECLARE_BITMAP(mids_bitmap, MLXSW_SP_MID_MAX);
72 const struct mlxsw_sp_bridge_ops *bridge_8021q_ops;
73 const struct mlxsw_sp_bridge_ops *bridge_8021d_ops;
76 struct mlxsw_sp_bridge_device {
77 struct net_device *dev;
78 struct list_head list;
79 struct list_head ports_list;
82 const struct mlxsw_sp_bridge_ops *ops;
85 struct mlxsw_sp_bridge_port {
86 struct net_device *dev;
87 struct mlxsw_sp_bridge_device *bridge_device;
88 struct list_head list;
89 struct list_head vlans_list;
90 unsigned int ref_count;
101 struct mlxsw_sp_bridge_vlan {
102 struct list_head list;
103 struct list_head port_vlan_list;
107 struct mlxsw_sp_bridge_ops {
108 int (*port_join)(struct mlxsw_sp_bridge_device *bridge_device,
109 struct mlxsw_sp_bridge_port *bridge_port,
110 struct mlxsw_sp_port *mlxsw_sp_port);
111 void (*port_leave)(struct mlxsw_sp_bridge_device *bridge_device,
112 struct mlxsw_sp_bridge_port *bridge_port,
113 struct mlxsw_sp_port *mlxsw_sp_port);
114 struct mlxsw_sp_fid *
115 (*fid_get)(struct mlxsw_sp_bridge_device *bridge_device,
120 mlxsw_sp_bridge_port_fdb_flush(struct mlxsw_sp *mlxsw_sp,
121 struct mlxsw_sp_bridge_port *bridge_port,
124 static struct mlxsw_sp_bridge_device *
125 mlxsw_sp_bridge_device_find(const struct mlxsw_sp_bridge *bridge,
126 const struct net_device *br_dev)
128 struct mlxsw_sp_bridge_device *bridge_device;
130 list_for_each_entry(bridge_device, &bridge->bridges_list, list)
131 if (bridge_device->dev == br_dev)
132 return bridge_device;
137 bool mlxsw_sp_bridge_device_is_offloaded(const struct mlxsw_sp *mlxsw_sp,
138 const struct net_device *br_dev)
140 return !!mlxsw_sp_bridge_device_find(mlxsw_sp->bridge, br_dev);
143 static int mlxsw_sp_bridge_device_upper_rif_destroy(struct net_device *dev,
146 struct mlxsw_sp *mlxsw_sp = data;
148 mlxsw_sp_rif_destroy_by_dev(mlxsw_sp, dev);
152 static void mlxsw_sp_bridge_device_rifs_destroy(struct mlxsw_sp *mlxsw_sp,
153 struct net_device *dev)
155 mlxsw_sp_rif_destroy_by_dev(mlxsw_sp, dev);
156 netdev_walk_all_upper_dev_rcu(dev,
157 mlxsw_sp_bridge_device_upper_rif_destroy,
161 static struct mlxsw_sp_bridge_device *
162 mlxsw_sp_bridge_device_create(struct mlxsw_sp_bridge *bridge,
163 struct net_device *br_dev)
165 struct device *dev = bridge->mlxsw_sp->bus_info->dev;
166 struct mlxsw_sp_bridge_device *bridge_device;
167 bool vlan_enabled = br_vlan_enabled(br_dev);
169 if (vlan_enabled && bridge->vlan_enabled_exists) {
170 dev_err(dev, "Only one VLAN-aware bridge is supported\n");
171 return ERR_PTR(-EINVAL);
174 bridge_device = kzalloc(sizeof(*bridge_device), GFP_KERNEL);
176 return ERR_PTR(-ENOMEM);
178 bridge_device->dev = br_dev;
179 bridge_device->vlan_enabled = vlan_enabled;
180 bridge_device->multicast_enabled = br_multicast_enabled(br_dev);
181 INIT_LIST_HEAD(&bridge_device->ports_list);
183 bridge->vlan_enabled_exists = true;
184 bridge_device->ops = bridge->bridge_8021q_ops;
186 bridge_device->ops = bridge->bridge_8021d_ops;
188 list_add(&bridge_device->list, &bridge->bridges_list);
190 return bridge_device;
194 mlxsw_sp_bridge_device_destroy(struct mlxsw_sp_bridge *bridge,
195 struct mlxsw_sp_bridge_device *bridge_device)
197 mlxsw_sp_bridge_device_rifs_destroy(bridge->mlxsw_sp,
199 list_del(&bridge_device->list);
200 if (bridge_device->vlan_enabled)
201 bridge->vlan_enabled_exists = false;
202 WARN_ON(!list_empty(&bridge_device->ports_list));
203 kfree(bridge_device);
206 static struct mlxsw_sp_bridge_device *
207 mlxsw_sp_bridge_device_get(struct mlxsw_sp_bridge *bridge,
208 struct net_device *br_dev)
210 struct mlxsw_sp_bridge_device *bridge_device;
212 bridge_device = mlxsw_sp_bridge_device_find(bridge, br_dev);
214 return bridge_device;
216 return mlxsw_sp_bridge_device_create(bridge, br_dev);
220 mlxsw_sp_bridge_device_put(struct mlxsw_sp_bridge *bridge,
221 struct mlxsw_sp_bridge_device *bridge_device)
223 if (list_empty(&bridge_device->ports_list))
224 mlxsw_sp_bridge_device_destroy(bridge, bridge_device);
227 static struct mlxsw_sp_bridge_port *
228 __mlxsw_sp_bridge_port_find(const struct mlxsw_sp_bridge_device *bridge_device,
229 const struct net_device *brport_dev)
231 struct mlxsw_sp_bridge_port *bridge_port;
233 list_for_each_entry(bridge_port, &bridge_device->ports_list, list) {
234 if (bridge_port->dev == brport_dev)
241 static struct mlxsw_sp_bridge_port *
242 mlxsw_sp_bridge_port_find(struct mlxsw_sp_bridge *bridge,
243 struct net_device *brport_dev)
245 struct net_device *br_dev = netdev_master_upper_dev_get(brport_dev);
246 struct mlxsw_sp_bridge_device *bridge_device;
251 bridge_device = mlxsw_sp_bridge_device_find(bridge, br_dev);
255 return __mlxsw_sp_bridge_port_find(bridge_device, brport_dev);
258 static struct mlxsw_sp_bridge_port *
259 mlxsw_sp_bridge_port_create(struct mlxsw_sp_bridge_device *bridge_device,
260 struct net_device *brport_dev)
262 struct mlxsw_sp_bridge_port *bridge_port;
263 struct mlxsw_sp_port *mlxsw_sp_port;
265 bridge_port = kzalloc(sizeof(*bridge_port), GFP_KERNEL);
269 mlxsw_sp_port = mlxsw_sp_port_dev_lower_find(brport_dev);
270 bridge_port->lagged = mlxsw_sp_port->lagged;
271 if (bridge_port->lagged)
272 bridge_port->lag_id = mlxsw_sp_port->lag_id;
274 bridge_port->system_port = mlxsw_sp_port->local_port;
275 bridge_port->dev = brport_dev;
276 bridge_port->bridge_device = bridge_device;
277 bridge_port->stp_state = BR_STATE_DISABLED;
278 bridge_port->flags = BR_LEARNING | BR_FLOOD | BR_LEARNING_SYNC;
279 INIT_LIST_HEAD(&bridge_port->vlans_list);
280 list_add(&bridge_port->list, &bridge_device->ports_list);
281 bridge_port->ref_count = 1;
287 mlxsw_sp_bridge_port_destroy(struct mlxsw_sp_bridge_port *bridge_port)
289 list_del(&bridge_port->list);
290 WARN_ON(!list_empty(&bridge_port->vlans_list));
294 static struct mlxsw_sp_bridge_port *
295 mlxsw_sp_bridge_port_get(struct mlxsw_sp_bridge *bridge,
296 struct net_device *brport_dev)
298 struct net_device *br_dev = netdev_master_upper_dev_get(brport_dev);
299 struct mlxsw_sp_bridge_device *bridge_device;
300 struct mlxsw_sp_bridge_port *bridge_port;
303 bridge_port = mlxsw_sp_bridge_port_find(bridge, brport_dev);
305 bridge_port->ref_count++;
309 bridge_device = mlxsw_sp_bridge_device_get(bridge, br_dev);
310 if (IS_ERR(bridge_device))
311 return ERR_CAST(bridge_device);
313 bridge_port = mlxsw_sp_bridge_port_create(bridge_device, brport_dev);
316 goto err_bridge_port_create;
321 err_bridge_port_create:
322 mlxsw_sp_bridge_device_put(bridge, bridge_device);
326 static void mlxsw_sp_bridge_port_put(struct mlxsw_sp_bridge *bridge,
327 struct mlxsw_sp_bridge_port *bridge_port)
329 struct mlxsw_sp_bridge_device *bridge_device;
331 if (--bridge_port->ref_count != 0)
333 bridge_device = bridge_port->bridge_device;
334 mlxsw_sp_bridge_port_destroy(bridge_port);
335 mlxsw_sp_bridge_device_put(bridge, bridge_device);
338 static struct mlxsw_sp_port_vlan *
339 mlxsw_sp_port_vlan_find_by_bridge(struct mlxsw_sp_port *mlxsw_sp_port,
340 const struct mlxsw_sp_bridge_device *
344 struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan;
346 list_for_each_entry(mlxsw_sp_port_vlan, &mlxsw_sp_port->vlans_list,
348 if (!mlxsw_sp_port_vlan->bridge_port)
350 if (mlxsw_sp_port_vlan->bridge_port->bridge_device !=
353 if (bridge_device->vlan_enabled &&
354 mlxsw_sp_port_vlan->vid != vid)
356 return mlxsw_sp_port_vlan;
362 static struct mlxsw_sp_port_vlan*
363 mlxsw_sp_port_vlan_find_by_fid(struct mlxsw_sp_port *mlxsw_sp_port,
366 struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan;
368 list_for_each_entry(mlxsw_sp_port_vlan, &mlxsw_sp_port->vlans_list,
370 struct mlxsw_sp_fid *fid = mlxsw_sp_port_vlan->fid;
372 if (fid && mlxsw_sp_fid_index(fid) == fid_index)
373 return mlxsw_sp_port_vlan;
379 static struct mlxsw_sp_bridge_vlan *
380 mlxsw_sp_bridge_vlan_find(const struct mlxsw_sp_bridge_port *bridge_port,
383 struct mlxsw_sp_bridge_vlan *bridge_vlan;
385 list_for_each_entry(bridge_vlan, &bridge_port->vlans_list, list) {
386 if (bridge_vlan->vid == vid)
393 static struct mlxsw_sp_bridge_vlan *
394 mlxsw_sp_bridge_vlan_create(struct mlxsw_sp_bridge_port *bridge_port, u16 vid)
396 struct mlxsw_sp_bridge_vlan *bridge_vlan;
398 bridge_vlan = kzalloc(sizeof(*bridge_vlan), GFP_KERNEL);
402 INIT_LIST_HEAD(&bridge_vlan->port_vlan_list);
403 bridge_vlan->vid = vid;
404 list_add(&bridge_vlan->list, &bridge_port->vlans_list);
410 mlxsw_sp_bridge_vlan_destroy(struct mlxsw_sp_bridge_vlan *bridge_vlan)
412 list_del(&bridge_vlan->list);
413 WARN_ON(!list_empty(&bridge_vlan->port_vlan_list));
417 static struct mlxsw_sp_bridge_vlan *
418 mlxsw_sp_bridge_vlan_get(struct mlxsw_sp_bridge_port *bridge_port, u16 vid)
420 struct mlxsw_sp_bridge_vlan *bridge_vlan;
422 bridge_vlan = mlxsw_sp_bridge_vlan_find(bridge_port, vid);
426 return mlxsw_sp_bridge_vlan_create(bridge_port, vid);
429 static void mlxsw_sp_bridge_vlan_put(struct mlxsw_sp_bridge_vlan *bridge_vlan)
431 if (list_empty(&bridge_vlan->port_vlan_list))
432 mlxsw_sp_bridge_vlan_destroy(bridge_vlan);
435 static void mlxsw_sp_port_bridge_flags_get(struct mlxsw_sp_bridge *bridge,
436 struct net_device *dev,
437 unsigned long *brport_flags)
439 struct mlxsw_sp_bridge_port *bridge_port;
441 bridge_port = mlxsw_sp_bridge_port_find(bridge, dev);
442 if (WARN_ON(!bridge_port))
445 memcpy(brport_flags, &bridge_port->flags, sizeof(*brport_flags));
448 static int mlxsw_sp_port_attr_get(struct net_device *dev,
449 struct switchdev_attr *attr)
451 struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev);
452 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
455 case SWITCHDEV_ATTR_ID_PORT_PARENT_ID:
456 attr->u.ppid.id_len = sizeof(mlxsw_sp->base_mac);
457 memcpy(&attr->u.ppid.id, &mlxsw_sp->base_mac,
458 attr->u.ppid.id_len);
460 case SWITCHDEV_ATTR_ID_PORT_BRIDGE_FLAGS:
461 mlxsw_sp_port_bridge_flags_get(mlxsw_sp->bridge, attr->orig_dev,
462 &attr->u.brport_flags);
464 case SWITCHDEV_ATTR_ID_PORT_BRIDGE_FLAGS_SUPPORT:
465 attr->u.brport_flags_support = BR_LEARNING | BR_FLOOD;
475 mlxsw_sp_port_bridge_vlan_stp_set(struct mlxsw_sp_port *mlxsw_sp_port,
476 struct mlxsw_sp_bridge_vlan *bridge_vlan,
479 struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan;
481 list_for_each_entry(mlxsw_sp_port_vlan, &bridge_vlan->port_vlan_list,
483 if (mlxsw_sp_port_vlan->mlxsw_sp_port != mlxsw_sp_port)
485 return mlxsw_sp_port_vid_stp_set(mlxsw_sp_port,
486 bridge_vlan->vid, state);
492 static int mlxsw_sp_port_attr_stp_state_set(struct mlxsw_sp_port *mlxsw_sp_port,
493 struct switchdev_trans *trans,
494 struct net_device *orig_dev,
497 struct mlxsw_sp_bridge_port *bridge_port;
498 struct mlxsw_sp_bridge_vlan *bridge_vlan;
501 if (switchdev_trans_ph_prepare(trans))
504 /* It's possible we failed to enslave the port, yet this
505 * operation is executed due to it being deferred.
507 bridge_port = mlxsw_sp_bridge_port_find(mlxsw_sp_port->mlxsw_sp->bridge,
512 list_for_each_entry(bridge_vlan, &bridge_port->vlans_list, list) {
513 err = mlxsw_sp_port_bridge_vlan_stp_set(mlxsw_sp_port,
516 goto err_port_bridge_vlan_stp_set;
519 bridge_port->stp_state = state;
523 err_port_bridge_vlan_stp_set:
524 list_for_each_entry_continue_reverse(bridge_vlan,
525 &bridge_port->vlans_list, list)
526 mlxsw_sp_port_bridge_vlan_stp_set(mlxsw_sp_port, bridge_vlan,
527 bridge_port->stp_state);
532 mlxsw_sp_port_bridge_vlan_flood_set(struct mlxsw_sp_port *mlxsw_sp_port,
533 struct mlxsw_sp_bridge_vlan *bridge_vlan,
534 enum mlxsw_sp_flood_type packet_type,
537 struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan;
539 list_for_each_entry(mlxsw_sp_port_vlan, &bridge_vlan->port_vlan_list,
541 if (mlxsw_sp_port_vlan->mlxsw_sp_port != mlxsw_sp_port)
543 return mlxsw_sp_fid_flood_set(mlxsw_sp_port_vlan->fid,
545 mlxsw_sp_port->local_port,
553 mlxsw_sp_bridge_port_flood_table_set(struct mlxsw_sp_port *mlxsw_sp_port,
554 struct mlxsw_sp_bridge_port *bridge_port,
555 enum mlxsw_sp_flood_type packet_type,
558 struct mlxsw_sp_bridge_vlan *bridge_vlan;
561 list_for_each_entry(bridge_vlan, &bridge_port->vlans_list, list) {
562 err = mlxsw_sp_port_bridge_vlan_flood_set(mlxsw_sp_port,
567 goto err_port_bridge_vlan_flood_set;
572 err_port_bridge_vlan_flood_set:
573 list_for_each_entry_continue_reverse(bridge_vlan,
574 &bridge_port->vlans_list, list)
575 mlxsw_sp_port_bridge_vlan_flood_set(mlxsw_sp_port, bridge_vlan,
576 packet_type, !member);
581 mlxsw_sp_port_bridge_vlan_learning_set(struct mlxsw_sp_port *mlxsw_sp_port,
582 struct mlxsw_sp_bridge_vlan *bridge_vlan,
585 struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan;
586 u16 vid = bridge_vlan->vid;
588 list_for_each_entry(mlxsw_sp_port_vlan, &bridge_vlan->port_vlan_list,
590 if (mlxsw_sp_port_vlan->mlxsw_sp_port != mlxsw_sp_port)
592 return mlxsw_sp_port_vid_learning_set(mlxsw_sp_port, vid, set);
599 mlxsw_sp_bridge_port_learning_set(struct mlxsw_sp_port *mlxsw_sp_port,
600 struct mlxsw_sp_bridge_port *bridge_port,
603 struct mlxsw_sp_bridge_vlan *bridge_vlan;
606 list_for_each_entry(bridge_vlan, &bridge_port->vlans_list, list) {
607 err = mlxsw_sp_port_bridge_vlan_learning_set(mlxsw_sp_port,
610 goto err_port_bridge_vlan_learning_set;
615 err_port_bridge_vlan_learning_set:
616 list_for_each_entry_continue_reverse(bridge_vlan,
617 &bridge_port->vlans_list, list)
618 mlxsw_sp_port_bridge_vlan_learning_set(mlxsw_sp_port,
623 static int mlxsw_sp_port_attr_br_flags_set(struct mlxsw_sp_port *mlxsw_sp_port,
624 struct switchdev_trans *trans,
625 struct net_device *orig_dev,
626 unsigned long brport_flags)
628 struct mlxsw_sp_bridge_port *bridge_port;
631 if (switchdev_trans_ph_prepare(trans))
634 bridge_port = mlxsw_sp_bridge_port_find(mlxsw_sp_port->mlxsw_sp->bridge,
639 err = mlxsw_sp_bridge_port_flood_table_set(mlxsw_sp_port, bridge_port,
640 MLXSW_SP_FLOOD_TYPE_UC,
641 brport_flags & BR_FLOOD);
645 err = mlxsw_sp_bridge_port_learning_set(mlxsw_sp_port, bridge_port,
646 brport_flags & BR_LEARNING);
650 memcpy(&bridge_port->flags, &brport_flags, sizeof(brport_flags));
655 static int mlxsw_sp_ageing_set(struct mlxsw_sp *mlxsw_sp, u32 ageing_time)
657 char sfdat_pl[MLXSW_REG_SFDAT_LEN];
660 mlxsw_reg_sfdat_pack(sfdat_pl, ageing_time);
661 err = mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(sfdat), sfdat_pl);
664 mlxsw_sp->bridge->ageing_time = ageing_time;
668 static int mlxsw_sp_port_attr_br_ageing_set(struct mlxsw_sp_port *mlxsw_sp_port,
669 struct switchdev_trans *trans,
670 unsigned long ageing_clock_t)
672 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
673 unsigned long ageing_jiffies = clock_t_to_jiffies(ageing_clock_t);
674 u32 ageing_time = jiffies_to_msecs(ageing_jiffies) / 1000;
676 if (switchdev_trans_ph_prepare(trans)) {
677 if (ageing_time < MLXSW_SP_MIN_AGEING_TIME ||
678 ageing_time > MLXSW_SP_MAX_AGEING_TIME)
684 return mlxsw_sp_ageing_set(mlxsw_sp, ageing_time);
687 static int mlxsw_sp_port_attr_br_vlan_set(struct mlxsw_sp_port *mlxsw_sp_port,
688 struct switchdev_trans *trans,
689 struct net_device *orig_dev,
692 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
693 struct mlxsw_sp_bridge_device *bridge_device;
695 if (!switchdev_trans_ph_prepare(trans))
698 bridge_device = mlxsw_sp_bridge_device_find(mlxsw_sp->bridge, orig_dev);
699 if (WARN_ON(!bridge_device))
702 if (bridge_device->vlan_enabled == vlan_enabled)
705 netdev_err(bridge_device->dev, "VLAN filtering can't be changed for existing bridge\n");
709 static int mlxsw_sp_port_attr_mc_router_set(struct mlxsw_sp_port *mlxsw_sp_port,
710 struct switchdev_trans *trans,
711 struct net_device *orig_dev,
712 bool is_port_mc_router)
714 struct mlxsw_sp_bridge_port *bridge_port;
717 if (switchdev_trans_ph_prepare(trans))
720 bridge_port = mlxsw_sp_bridge_port_find(mlxsw_sp_port->mlxsw_sp->bridge,
725 if (!bridge_port->bridge_device->multicast_enabled)
728 err = mlxsw_sp_bridge_port_flood_table_set(mlxsw_sp_port, bridge_port,
729 MLXSW_SP_FLOOD_TYPE_MC,
735 bridge_port->mrouter = is_port_mc_router;
739 static int mlxsw_sp_port_mc_disabled_set(struct mlxsw_sp_port *mlxsw_sp_port,
740 struct switchdev_trans *trans,
741 struct net_device *orig_dev,
744 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
745 struct mlxsw_sp_bridge_device *bridge_device;
746 struct mlxsw_sp_bridge_port *bridge_port;
749 if (switchdev_trans_ph_prepare(trans))
752 /* It's possible we failed to enslave the port, yet this
753 * operation is executed due to it being deferred.
755 bridge_device = mlxsw_sp_bridge_device_find(mlxsw_sp->bridge, orig_dev);
759 list_for_each_entry(bridge_port, &bridge_device->ports_list, list) {
760 enum mlxsw_sp_flood_type packet_type = MLXSW_SP_FLOOD_TYPE_MC;
761 bool member = mc_disabled ? true : bridge_port->mrouter;
763 err = mlxsw_sp_bridge_port_flood_table_set(mlxsw_sp_port,
765 packet_type, member);
770 bridge_device->multicast_enabled = !mc_disabled;
775 static int mlxsw_sp_port_attr_set(struct net_device *dev,
776 const struct switchdev_attr *attr,
777 struct switchdev_trans *trans)
779 struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev);
783 case SWITCHDEV_ATTR_ID_PORT_STP_STATE:
784 err = mlxsw_sp_port_attr_stp_state_set(mlxsw_sp_port, trans,
788 case SWITCHDEV_ATTR_ID_PORT_BRIDGE_FLAGS:
789 err = mlxsw_sp_port_attr_br_flags_set(mlxsw_sp_port, trans,
791 attr->u.brport_flags);
793 case SWITCHDEV_ATTR_ID_BRIDGE_AGEING_TIME:
794 err = mlxsw_sp_port_attr_br_ageing_set(mlxsw_sp_port, trans,
795 attr->u.ageing_time);
797 case SWITCHDEV_ATTR_ID_BRIDGE_VLAN_FILTERING:
798 err = mlxsw_sp_port_attr_br_vlan_set(mlxsw_sp_port, trans,
800 attr->u.vlan_filtering);
802 case SWITCHDEV_ATTR_ID_PORT_MROUTER:
803 err = mlxsw_sp_port_attr_mc_router_set(mlxsw_sp_port, trans,
807 case SWITCHDEV_ATTR_ID_BRIDGE_MC_DISABLED:
808 err = mlxsw_sp_port_mc_disabled_set(mlxsw_sp_port, trans,
810 attr->u.mc_disabled);
820 static bool mlxsw_sp_mc_flood(const struct mlxsw_sp_bridge_port *bridge_port)
822 const struct mlxsw_sp_bridge_device *bridge_device;
824 bridge_device = bridge_port->bridge_device;
825 return !bridge_device->multicast_enabled ? true : bridge_port->mrouter;
829 mlxsw_sp_port_vlan_fid_join(struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan,
830 struct mlxsw_sp_bridge_port *bridge_port)
832 struct mlxsw_sp_port *mlxsw_sp_port = mlxsw_sp_port_vlan->mlxsw_sp_port;
833 struct mlxsw_sp_bridge_device *bridge_device;
834 u8 local_port = mlxsw_sp_port->local_port;
835 u16 vid = mlxsw_sp_port_vlan->vid;
836 struct mlxsw_sp_fid *fid;
839 bridge_device = bridge_port->bridge_device;
840 fid = bridge_device->ops->fid_get(bridge_device, vid);
844 err = mlxsw_sp_fid_flood_set(fid, MLXSW_SP_FLOOD_TYPE_UC, local_port,
845 bridge_port->flags & BR_FLOOD);
847 goto err_fid_uc_flood_set;
849 err = mlxsw_sp_fid_flood_set(fid, MLXSW_SP_FLOOD_TYPE_MC, local_port,
850 mlxsw_sp_mc_flood(bridge_port));
852 goto err_fid_mc_flood_set;
854 err = mlxsw_sp_fid_flood_set(fid, MLXSW_SP_FLOOD_TYPE_BC, local_port,
857 goto err_fid_bc_flood_set;
859 err = mlxsw_sp_fid_port_vid_map(fid, mlxsw_sp_port, vid);
861 goto err_fid_port_vid_map;
863 mlxsw_sp_port_vlan->fid = fid;
867 err_fid_port_vid_map:
868 mlxsw_sp_fid_flood_set(fid, MLXSW_SP_FLOOD_TYPE_BC, local_port, false);
869 err_fid_bc_flood_set:
870 mlxsw_sp_fid_flood_set(fid, MLXSW_SP_FLOOD_TYPE_MC, local_port, false);
871 err_fid_mc_flood_set:
872 mlxsw_sp_fid_flood_set(fid, MLXSW_SP_FLOOD_TYPE_UC, local_port, false);
873 err_fid_uc_flood_set:
874 mlxsw_sp_fid_put(fid);
879 mlxsw_sp_port_vlan_fid_leave(struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan)
881 struct mlxsw_sp_port *mlxsw_sp_port = mlxsw_sp_port_vlan->mlxsw_sp_port;
882 struct mlxsw_sp_fid *fid = mlxsw_sp_port_vlan->fid;
883 u8 local_port = mlxsw_sp_port->local_port;
884 u16 vid = mlxsw_sp_port_vlan->vid;
886 mlxsw_sp_port_vlan->fid = NULL;
887 mlxsw_sp_fid_port_vid_unmap(fid, mlxsw_sp_port, vid);
888 mlxsw_sp_fid_flood_set(fid, MLXSW_SP_FLOOD_TYPE_BC, local_port, false);
889 mlxsw_sp_fid_flood_set(fid, MLXSW_SP_FLOOD_TYPE_MC, local_port, false);
890 mlxsw_sp_fid_flood_set(fid, MLXSW_SP_FLOOD_TYPE_UC, local_port, false);
891 mlxsw_sp_fid_put(fid);
895 mlxsw_sp_port_pvid_determine(const struct mlxsw_sp_port *mlxsw_sp_port,
896 u16 vid, bool is_pvid)
900 else if (mlxsw_sp_port->pvid == vid)
901 return 0; /* Dis-allow untagged packets */
903 return mlxsw_sp_port->pvid;
907 mlxsw_sp_port_vlan_bridge_join(struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan,
908 struct mlxsw_sp_bridge_port *bridge_port)
910 struct mlxsw_sp_port *mlxsw_sp_port = mlxsw_sp_port_vlan->mlxsw_sp_port;
911 struct mlxsw_sp_bridge_vlan *bridge_vlan;
912 u16 vid = mlxsw_sp_port_vlan->vid;
915 /* No need to continue if only VLAN flags were changed */
916 if (mlxsw_sp_port_vlan->bridge_port) {
917 mlxsw_sp_port_vlan_put(mlxsw_sp_port_vlan);
921 err = mlxsw_sp_port_vlan_fid_join(mlxsw_sp_port_vlan, bridge_port);
925 err = mlxsw_sp_port_vid_learning_set(mlxsw_sp_port, vid,
926 bridge_port->flags & BR_LEARNING);
928 goto err_port_vid_learning_set;
930 err = mlxsw_sp_port_vid_stp_set(mlxsw_sp_port, vid,
931 bridge_port->stp_state);
933 goto err_port_vid_stp_set;
935 bridge_vlan = mlxsw_sp_bridge_vlan_get(bridge_port, vid);
938 goto err_bridge_vlan_get;
941 list_add(&mlxsw_sp_port_vlan->bridge_vlan_node,
942 &bridge_vlan->port_vlan_list);
944 mlxsw_sp_bridge_port_get(mlxsw_sp_port->mlxsw_sp->bridge,
946 mlxsw_sp_port_vlan->bridge_port = bridge_port;
951 mlxsw_sp_port_vid_stp_set(mlxsw_sp_port, vid, BR_STATE_DISABLED);
952 err_port_vid_stp_set:
953 mlxsw_sp_port_vid_learning_set(mlxsw_sp_port, vid, false);
954 err_port_vid_learning_set:
955 mlxsw_sp_port_vlan_fid_leave(mlxsw_sp_port_vlan);
960 mlxsw_sp_port_vlan_bridge_leave(struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan)
962 struct mlxsw_sp_port *mlxsw_sp_port = mlxsw_sp_port_vlan->mlxsw_sp_port;
963 struct mlxsw_sp_fid *fid = mlxsw_sp_port_vlan->fid;
964 struct mlxsw_sp_bridge_vlan *bridge_vlan;
965 struct mlxsw_sp_bridge_port *bridge_port;
966 u16 vid = mlxsw_sp_port_vlan->vid;
969 if (WARN_ON(mlxsw_sp_fid_type(fid) != MLXSW_SP_FID_TYPE_8021Q &&
970 mlxsw_sp_fid_type(fid) != MLXSW_SP_FID_TYPE_8021D))
973 bridge_port = mlxsw_sp_port_vlan->bridge_port;
974 bridge_vlan = mlxsw_sp_bridge_vlan_find(bridge_port, vid);
975 last = list_is_singular(&bridge_vlan->port_vlan_list);
977 list_del(&mlxsw_sp_port_vlan->bridge_vlan_node);
978 mlxsw_sp_bridge_vlan_put(bridge_vlan);
979 mlxsw_sp_port_vid_stp_set(mlxsw_sp_port, vid, BR_STATE_DISABLED);
980 mlxsw_sp_port_vid_learning_set(mlxsw_sp_port, vid, false);
982 mlxsw_sp_bridge_port_fdb_flush(mlxsw_sp_port->mlxsw_sp,
984 mlxsw_sp_fid_index(fid));
985 mlxsw_sp_port_vlan_fid_leave(mlxsw_sp_port_vlan);
987 mlxsw_sp_bridge_port_put(mlxsw_sp_port->mlxsw_sp->bridge, bridge_port);
988 mlxsw_sp_port_vlan->bridge_port = NULL;
992 mlxsw_sp_bridge_port_vlan_add(struct mlxsw_sp_port *mlxsw_sp_port,
993 struct mlxsw_sp_bridge_port *bridge_port,
994 u16 vid, bool is_untagged, bool is_pvid)
996 u16 pvid = mlxsw_sp_port_pvid_determine(mlxsw_sp_port, vid, is_pvid);
997 struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan;
998 u16 old_pvid = mlxsw_sp_port->pvid;
1001 mlxsw_sp_port_vlan = mlxsw_sp_port_vlan_get(mlxsw_sp_port, vid);
1002 if (IS_ERR(mlxsw_sp_port_vlan))
1003 return PTR_ERR(mlxsw_sp_port_vlan);
1005 err = mlxsw_sp_port_vlan_set(mlxsw_sp_port, vid, vid, true,
1008 goto err_port_vlan_set;
1010 err = mlxsw_sp_port_pvid_set(mlxsw_sp_port, pvid);
1012 goto err_port_pvid_set;
1014 err = mlxsw_sp_port_vlan_bridge_join(mlxsw_sp_port_vlan, bridge_port);
1016 goto err_port_vlan_bridge_join;
1020 err_port_vlan_bridge_join:
1021 mlxsw_sp_port_pvid_set(mlxsw_sp_port, old_pvid);
1023 mlxsw_sp_port_vlan_set(mlxsw_sp_port, vid, vid, false, false);
1025 mlxsw_sp_port_vlan_put(mlxsw_sp_port_vlan);
1029 static int mlxsw_sp_port_vlans_add(struct mlxsw_sp_port *mlxsw_sp_port,
1030 const struct switchdev_obj_port_vlan *vlan,
1031 struct switchdev_trans *trans)
1033 bool flag_untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
1034 bool flag_pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
1035 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
1036 struct net_device *orig_dev = vlan->obj.orig_dev;
1037 struct mlxsw_sp_bridge_port *bridge_port;
1040 if (switchdev_trans_ph_prepare(trans))
1043 bridge_port = mlxsw_sp_bridge_port_find(mlxsw_sp->bridge, orig_dev);
1044 if (WARN_ON(!bridge_port))
1047 if (!bridge_port->bridge_device->vlan_enabled)
1050 for (vid = vlan->vid_begin; vid <= vlan->vid_end; vid++) {
1053 err = mlxsw_sp_bridge_port_vlan_add(mlxsw_sp_port, bridge_port,
1063 static enum mlxsw_reg_sfdf_flush_type mlxsw_sp_fdb_flush_type(bool lagged)
1065 return lagged ? MLXSW_REG_SFDF_FLUSH_PER_LAG_AND_FID :
1066 MLXSW_REG_SFDF_FLUSH_PER_PORT_AND_FID;
1070 mlxsw_sp_bridge_port_fdb_flush(struct mlxsw_sp *mlxsw_sp,
1071 struct mlxsw_sp_bridge_port *bridge_port,
1074 bool lagged = bridge_port->lagged;
1075 char sfdf_pl[MLXSW_REG_SFDF_LEN];
1078 system_port = lagged ? bridge_port->lag_id : bridge_port->system_port;
1079 mlxsw_reg_sfdf_pack(sfdf_pl, mlxsw_sp_fdb_flush_type(lagged));
1080 mlxsw_reg_sfdf_fid_set(sfdf_pl, fid_index);
1081 mlxsw_reg_sfdf_port_fid_system_port_set(sfdf_pl, system_port);
1083 return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(sfdf), sfdf_pl);
1086 static enum mlxsw_reg_sfd_rec_policy mlxsw_sp_sfd_rec_policy(bool dynamic)
1088 return dynamic ? MLXSW_REG_SFD_REC_POLICY_DYNAMIC_ENTRY_INGRESS :
1089 MLXSW_REG_SFD_REC_POLICY_DYNAMIC_ENTRY_MLAG;
1092 static enum mlxsw_reg_sfd_op mlxsw_sp_sfd_op(bool adding)
1094 return adding ? MLXSW_REG_SFD_OP_WRITE_EDIT :
1095 MLXSW_REG_SFD_OP_WRITE_REMOVE;
1098 static int __mlxsw_sp_port_fdb_uc_op(struct mlxsw_sp *mlxsw_sp, u8 local_port,
1099 const char *mac, u16 fid, bool adding,
1100 enum mlxsw_reg_sfd_rec_action action,
1101 enum mlxsw_reg_sfd_rec_policy policy)
1107 sfd_pl = kmalloc(MLXSW_REG_SFD_LEN, GFP_KERNEL);
1111 mlxsw_reg_sfd_pack(sfd_pl, mlxsw_sp_sfd_op(adding), 0);
1112 mlxsw_reg_sfd_uc_pack(sfd_pl, 0, policy, mac, fid, action, local_port);
1113 num_rec = mlxsw_reg_sfd_num_rec_get(sfd_pl);
1114 err = mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(sfd), sfd_pl);
1118 if (num_rec != mlxsw_reg_sfd_num_rec_get(sfd_pl))
1126 static int mlxsw_sp_port_fdb_uc_op(struct mlxsw_sp *mlxsw_sp, u8 local_port,
1127 const char *mac, u16 fid, bool adding,
1130 return __mlxsw_sp_port_fdb_uc_op(mlxsw_sp, local_port, mac, fid, adding,
1131 MLXSW_REG_SFD_REC_ACTION_NOP,
1132 mlxsw_sp_sfd_rec_policy(dynamic));
1135 int mlxsw_sp_rif_fdb_op(struct mlxsw_sp *mlxsw_sp, const char *mac, u16 fid,
1138 return __mlxsw_sp_port_fdb_uc_op(mlxsw_sp, 0, mac, fid, adding,
1139 MLXSW_REG_SFD_REC_ACTION_FORWARD_IP_ROUTER,
1140 MLXSW_REG_SFD_REC_POLICY_STATIC_ENTRY);
1143 static int mlxsw_sp_port_fdb_uc_lag_op(struct mlxsw_sp *mlxsw_sp, u16 lag_id,
1144 const char *mac, u16 fid, u16 lag_vid,
1145 bool adding, bool dynamic)
1151 sfd_pl = kmalloc(MLXSW_REG_SFD_LEN, GFP_KERNEL);
1155 mlxsw_reg_sfd_pack(sfd_pl, mlxsw_sp_sfd_op(adding), 0);
1156 mlxsw_reg_sfd_uc_lag_pack(sfd_pl, 0, mlxsw_sp_sfd_rec_policy(dynamic),
1157 mac, fid, MLXSW_REG_SFD_REC_ACTION_NOP,
1159 num_rec = mlxsw_reg_sfd_num_rec_get(sfd_pl);
1160 err = mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(sfd), sfd_pl);
1164 if (num_rec != mlxsw_reg_sfd_num_rec_get(sfd_pl))
1173 mlxsw_sp_port_fdb_set(struct mlxsw_sp_port *mlxsw_sp_port,
1174 struct switchdev_notifier_fdb_info *fdb_info, bool adding)
1176 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
1177 struct net_device *orig_dev = fdb_info->info.dev;
1178 struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan;
1179 struct mlxsw_sp_bridge_device *bridge_device;
1180 struct mlxsw_sp_bridge_port *bridge_port;
1183 bridge_port = mlxsw_sp_bridge_port_find(mlxsw_sp->bridge, orig_dev);
1187 bridge_device = bridge_port->bridge_device;
1188 mlxsw_sp_port_vlan = mlxsw_sp_port_vlan_find_by_bridge(mlxsw_sp_port,
1191 if (!mlxsw_sp_port_vlan)
1194 fid_index = mlxsw_sp_fid_index(mlxsw_sp_port_vlan->fid);
1195 vid = mlxsw_sp_port_vlan->vid;
1197 if (!bridge_port->lagged)
1198 return mlxsw_sp_port_fdb_uc_op(mlxsw_sp,
1199 bridge_port->system_port,
1200 fdb_info->addr, fid_index,
1203 return mlxsw_sp_port_fdb_uc_lag_op(mlxsw_sp,
1204 bridge_port->lag_id,
1205 fdb_info->addr, fid_index,
1206 vid, adding, false);
1209 static int mlxsw_sp_port_mdb_op(struct mlxsw_sp *mlxsw_sp, const char *addr,
1210 u16 fid, u16 mid, bool adding)
1216 sfd_pl = kmalloc(MLXSW_REG_SFD_LEN, GFP_KERNEL);
1220 mlxsw_reg_sfd_pack(sfd_pl, mlxsw_sp_sfd_op(adding), 0);
1221 mlxsw_reg_sfd_mc_pack(sfd_pl, 0, addr, fid,
1222 MLXSW_REG_SFD_REC_ACTION_NOP, mid);
1223 num_rec = mlxsw_reg_sfd_num_rec_get(sfd_pl);
1224 err = mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(sfd), sfd_pl);
1228 if (num_rec != mlxsw_reg_sfd_num_rec_get(sfd_pl))
1236 static int mlxsw_sp_port_smid_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 mid,
1237 bool add, bool clear_all_ports)
1239 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
1243 smid_pl = kmalloc(MLXSW_REG_SMID_LEN, GFP_KERNEL);
1247 mlxsw_reg_smid_pack(smid_pl, mid, mlxsw_sp_port->local_port, add);
1248 if (clear_all_ports) {
1249 for (i = 1; i < mlxsw_core_max_ports(mlxsw_sp->core); i++)
1250 if (mlxsw_sp->ports[i])
1251 mlxsw_reg_smid_port_mask_set(smid_pl, i, 1);
1253 err = mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(smid), smid_pl);
1258 static struct mlxsw_sp_mid *__mlxsw_sp_mc_get(struct mlxsw_sp *mlxsw_sp,
1259 const unsigned char *addr,
1262 struct mlxsw_sp_mid *mid;
1264 list_for_each_entry(mid, &mlxsw_sp->bridge->mids_list, list) {
1265 if (ether_addr_equal(mid->addr, addr) && mid->fid == fid)
1271 static struct mlxsw_sp_mid *__mlxsw_sp_mc_alloc(struct mlxsw_sp *mlxsw_sp,
1272 const unsigned char *addr,
1275 struct mlxsw_sp_mid *mid;
1278 mid_idx = find_first_zero_bit(mlxsw_sp->bridge->mids_bitmap,
1280 if (mid_idx == MLXSW_SP_MID_MAX)
1283 mid = kzalloc(sizeof(*mid), GFP_KERNEL);
1287 set_bit(mid_idx, mlxsw_sp->bridge->mids_bitmap);
1288 ether_addr_copy(mid->addr, addr);
1292 list_add_tail(&mid->list, &mlxsw_sp->bridge->mids_list);
1297 static int __mlxsw_sp_mc_dec_ref(struct mlxsw_sp *mlxsw_sp,
1298 struct mlxsw_sp_mid *mid)
1300 if (--mid->ref_count == 0) {
1301 list_del(&mid->list);
1302 clear_bit(mid->mid, mlxsw_sp->bridge->mids_bitmap);
1309 static int mlxsw_sp_port_mdb_add(struct mlxsw_sp_port *mlxsw_sp_port,
1310 const struct switchdev_obj_port_mdb *mdb,
1311 struct switchdev_trans *trans)
1313 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
1314 struct net_device *orig_dev = mdb->obj.orig_dev;
1315 struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan;
1316 struct net_device *dev = mlxsw_sp_port->dev;
1317 struct mlxsw_sp_bridge_device *bridge_device;
1318 struct mlxsw_sp_bridge_port *bridge_port;
1319 struct mlxsw_sp_mid *mid;
1323 if (switchdev_trans_ph_commit(trans))
1326 bridge_port = mlxsw_sp_bridge_port_find(mlxsw_sp->bridge, orig_dev);
1330 bridge_device = bridge_port->bridge_device;
1331 mlxsw_sp_port_vlan = mlxsw_sp_port_vlan_find_by_bridge(mlxsw_sp_port,
1334 if (!mlxsw_sp_port_vlan)
1337 fid_index = mlxsw_sp_fid_index(mlxsw_sp_port_vlan->fid);
1339 mid = __mlxsw_sp_mc_get(mlxsw_sp, mdb->addr, fid_index);
1341 mid = __mlxsw_sp_mc_alloc(mlxsw_sp, mdb->addr, fid_index);
1343 netdev_err(dev, "Unable to allocate MC group\n");
1349 err = mlxsw_sp_port_smid_set(mlxsw_sp_port, mid->mid, true,
1350 mid->ref_count == 1);
1352 netdev_err(dev, "Unable to set SMID\n");
1356 if (mid->ref_count == 1) {
1357 err = mlxsw_sp_port_mdb_op(mlxsw_sp, mdb->addr, fid_index,
1360 netdev_err(dev, "Unable to set MC SFD\n");
1368 __mlxsw_sp_mc_dec_ref(mlxsw_sp, mid);
1372 static int mlxsw_sp_port_obj_add(struct net_device *dev,
1373 const struct switchdev_obj *obj,
1374 struct switchdev_trans *trans)
1376 struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev);
1380 case SWITCHDEV_OBJ_ID_PORT_VLAN:
1381 err = mlxsw_sp_port_vlans_add(mlxsw_sp_port,
1382 SWITCHDEV_OBJ_PORT_VLAN(obj),
1385 case SWITCHDEV_OBJ_ID_PORT_MDB:
1386 err = mlxsw_sp_port_mdb_add(mlxsw_sp_port,
1387 SWITCHDEV_OBJ_PORT_MDB(obj),
1399 mlxsw_sp_bridge_port_vlan_del(struct mlxsw_sp_port *mlxsw_sp_port,
1400 struct mlxsw_sp_bridge_port *bridge_port, u16 vid)
1402 u16 pvid = mlxsw_sp_port->pvid == vid ? 0 : mlxsw_sp_port->pvid;
1403 struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan;
1405 mlxsw_sp_port_vlan = mlxsw_sp_port_vlan_find_by_vid(mlxsw_sp_port, vid);
1406 if (WARN_ON(!mlxsw_sp_port_vlan))
1409 mlxsw_sp_port_vlan_bridge_leave(mlxsw_sp_port_vlan);
1410 mlxsw_sp_port_pvid_set(mlxsw_sp_port, pvid);
1411 mlxsw_sp_port_vlan_set(mlxsw_sp_port, vid, vid, false, false);
1412 mlxsw_sp_port_vlan_put(mlxsw_sp_port_vlan);
1415 static int mlxsw_sp_port_vlans_del(struct mlxsw_sp_port *mlxsw_sp_port,
1416 const struct switchdev_obj_port_vlan *vlan)
1418 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
1419 struct net_device *orig_dev = vlan->obj.orig_dev;
1420 struct mlxsw_sp_bridge_port *bridge_port;
1423 bridge_port = mlxsw_sp_bridge_port_find(mlxsw_sp->bridge, orig_dev);
1424 if (WARN_ON(!bridge_port))
1427 if (!bridge_port->bridge_device->vlan_enabled)
1430 for (vid = vlan->vid_begin; vid <= vlan->vid_end; vid++)
1431 mlxsw_sp_bridge_port_vlan_del(mlxsw_sp_port, bridge_port, vid);
1436 static int mlxsw_sp_port_mdb_del(struct mlxsw_sp_port *mlxsw_sp_port,
1437 const struct switchdev_obj_port_mdb *mdb)
1439 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
1440 struct net_device *orig_dev = mdb->obj.orig_dev;
1441 struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan;
1442 struct mlxsw_sp_bridge_device *bridge_device;
1443 struct net_device *dev = mlxsw_sp_port->dev;
1444 struct mlxsw_sp_bridge_port *bridge_port;
1445 struct mlxsw_sp_mid *mid;
1450 bridge_port = mlxsw_sp_bridge_port_find(mlxsw_sp->bridge, orig_dev);
1454 bridge_device = bridge_port->bridge_device;
1455 mlxsw_sp_port_vlan = mlxsw_sp_port_vlan_find_by_bridge(mlxsw_sp_port,
1458 if (!mlxsw_sp_port_vlan)
1461 fid_index = mlxsw_sp_fid_index(mlxsw_sp_port_vlan->fid);
1463 mid = __mlxsw_sp_mc_get(mlxsw_sp, mdb->addr, fid_index);
1465 netdev_err(dev, "Unable to remove port from MC DB\n");
1469 err = mlxsw_sp_port_smid_set(mlxsw_sp_port, mid->mid, false, false);
1471 netdev_err(dev, "Unable to remove port from SMID\n");
1474 if (__mlxsw_sp_mc_dec_ref(mlxsw_sp, mid)) {
1475 err = mlxsw_sp_port_mdb_op(mlxsw_sp, mdb->addr, fid_index,
1478 netdev_err(dev, "Unable to remove MC SFD\n");
1484 static int mlxsw_sp_port_obj_del(struct net_device *dev,
1485 const struct switchdev_obj *obj)
1487 struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev);
1491 case SWITCHDEV_OBJ_ID_PORT_VLAN:
1492 err = mlxsw_sp_port_vlans_del(mlxsw_sp_port,
1493 SWITCHDEV_OBJ_PORT_VLAN(obj));
1495 case SWITCHDEV_OBJ_ID_PORT_MDB:
1496 err = mlxsw_sp_port_mdb_del(mlxsw_sp_port,
1497 SWITCHDEV_OBJ_PORT_MDB(obj));
1507 static struct mlxsw_sp_port *mlxsw_sp_lag_rep_port(struct mlxsw_sp *mlxsw_sp,
1510 struct mlxsw_sp_port *mlxsw_sp_port;
1511 u64 max_lag_members;
1514 max_lag_members = MLXSW_CORE_RES_GET(mlxsw_sp->core,
1516 for (i = 0; i < max_lag_members; i++) {
1517 mlxsw_sp_port = mlxsw_sp_port_lagged_get(mlxsw_sp, lag_id, i);
1519 return mlxsw_sp_port;
1524 static const struct switchdev_ops mlxsw_sp_port_switchdev_ops = {
1525 .switchdev_port_attr_get = mlxsw_sp_port_attr_get,
1526 .switchdev_port_attr_set = mlxsw_sp_port_attr_set,
1527 .switchdev_port_obj_add = mlxsw_sp_port_obj_add,
1528 .switchdev_port_obj_del = mlxsw_sp_port_obj_del,
1532 mlxsw_sp_bridge_8021q_port_join(struct mlxsw_sp_bridge_device *bridge_device,
1533 struct mlxsw_sp_bridge_port *bridge_port,
1534 struct mlxsw_sp_port *mlxsw_sp_port)
1536 struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan;
1538 if (is_vlan_dev(bridge_port->dev))
1541 mlxsw_sp_port_vlan = mlxsw_sp_port_vlan_find_by_vid(mlxsw_sp_port, 1);
1542 if (WARN_ON(!mlxsw_sp_port_vlan))
1545 /* Let VLAN-aware bridge take care of its own VLANs */
1546 mlxsw_sp_port_vlan_put(mlxsw_sp_port_vlan);
1552 mlxsw_sp_bridge_8021q_port_leave(struct mlxsw_sp_bridge_device *bridge_device,
1553 struct mlxsw_sp_bridge_port *bridge_port,
1554 struct mlxsw_sp_port *mlxsw_sp_port)
1556 mlxsw_sp_port_vlan_get(mlxsw_sp_port, 1);
1557 /* Make sure untagged frames are allowed to ingress */
1558 mlxsw_sp_port_pvid_set(mlxsw_sp_port, 1);
1561 static struct mlxsw_sp_fid *
1562 mlxsw_sp_bridge_8021q_fid_get(struct mlxsw_sp_bridge_device *bridge_device,
1565 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_lower_get(bridge_device->dev);
1567 return mlxsw_sp_fid_8021q_get(mlxsw_sp, vid);
1570 static const struct mlxsw_sp_bridge_ops mlxsw_sp_bridge_8021q_ops = {
1571 .port_join = mlxsw_sp_bridge_8021q_port_join,
1572 .port_leave = mlxsw_sp_bridge_8021q_port_leave,
1573 .fid_get = mlxsw_sp_bridge_8021q_fid_get,
1577 mlxsw_sp_port_is_br_member(const struct mlxsw_sp_port *mlxsw_sp_port,
1578 const struct net_device *br_dev)
1580 struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan;
1582 list_for_each_entry(mlxsw_sp_port_vlan, &mlxsw_sp_port->vlans_list,
1584 if (mlxsw_sp_port_vlan->bridge_port &&
1585 mlxsw_sp_port_vlan->bridge_port->bridge_device->dev ==
1594 mlxsw_sp_bridge_8021d_port_join(struct mlxsw_sp_bridge_device *bridge_device,
1595 struct mlxsw_sp_bridge_port *bridge_port,
1596 struct mlxsw_sp_port *mlxsw_sp_port)
1598 struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan;
1601 if (!is_vlan_dev(bridge_port->dev))
1603 vid = vlan_dev_vlan_id(bridge_port->dev);
1605 mlxsw_sp_port_vlan = mlxsw_sp_port_vlan_find_by_vid(mlxsw_sp_port, vid);
1606 if (WARN_ON(!mlxsw_sp_port_vlan))
1609 if (mlxsw_sp_port_is_br_member(mlxsw_sp_port, bridge_device->dev)) {
1610 netdev_err(mlxsw_sp_port->dev, "Can't bridge VLAN uppers of the same port\n");
1614 /* Port is no longer usable as a router interface */
1615 if (mlxsw_sp_port_vlan->fid)
1616 mlxsw_sp_port_vlan_router_leave(mlxsw_sp_port_vlan);
1618 return mlxsw_sp_port_vlan_bridge_join(mlxsw_sp_port_vlan, bridge_port);
1622 mlxsw_sp_bridge_8021d_port_leave(struct mlxsw_sp_bridge_device *bridge_device,
1623 struct mlxsw_sp_bridge_port *bridge_port,
1624 struct mlxsw_sp_port *mlxsw_sp_port)
1626 struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan;
1627 u16 vid = vlan_dev_vlan_id(bridge_port->dev);
1629 mlxsw_sp_port_vlan = mlxsw_sp_port_vlan_find_by_vid(mlxsw_sp_port, vid);
1630 if (!mlxsw_sp_port_vlan)
1633 mlxsw_sp_port_vlan_bridge_leave(mlxsw_sp_port_vlan);
1636 static struct mlxsw_sp_fid *
1637 mlxsw_sp_bridge_8021d_fid_get(struct mlxsw_sp_bridge_device *bridge_device,
1640 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_lower_get(bridge_device->dev);
1642 return mlxsw_sp_fid_8021d_get(mlxsw_sp, bridge_device->dev->ifindex);
1645 static const struct mlxsw_sp_bridge_ops mlxsw_sp_bridge_8021d_ops = {
1646 .port_join = mlxsw_sp_bridge_8021d_port_join,
1647 .port_leave = mlxsw_sp_bridge_8021d_port_leave,
1648 .fid_get = mlxsw_sp_bridge_8021d_fid_get,
1651 int mlxsw_sp_port_bridge_join(struct mlxsw_sp_port *mlxsw_sp_port,
1652 struct net_device *brport_dev,
1653 struct net_device *br_dev)
1655 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
1656 struct mlxsw_sp_bridge_device *bridge_device;
1657 struct mlxsw_sp_bridge_port *bridge_port;
1660 bridge_port = mlxsw_sp_bridge_port_get(mlxsw_sp->bridge, brport_dev);
1661 if (IS_ERR(bridge_port))
1662 return PTR_ERR(bridge_port);
1663 bridge_device = bridge_port->bridge_device;
1665 err = bridge_device->ops->port_join(bridge_device, bridge_port,
1673 mlxsw_sp_bridge_port_put(mlxsw_sp->bridge, bridge_port);
1677 void mlxsw_sp_port_bridge_leave(struct mlxsw_sp_port *mlxsw_sp_port,
1678 struct net_device *brport_dev,
1679 struct net_device *br_dev)
1681 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
1682 struct mlxsw_sp_bridge_device *bridge_device;
1683 struct mlxsw_sp_bridge_port *bridge_port;
1685 bridge_device = mlxsw_sp_bridge_device_find(mlxsw_sp->bridge, br_dev);
1688 bridge_port = __mlxsw_sp_bridge_port_find(bridge_device, brport_dev);
1692 bridge_device->ops->port_leave(bridge_device, bridge_port,
1694 mlxsw_sp_bridge_port_put(mlxsw_sp->bridge, bridge_port);
1698 mlxsw_sp_fdb_call_notifiers(enum switchdev_notifier_type type,
1699 const char *mac, u16 vid,
1700 struct net_device *dev)
1702 struct switchdev_notifier_fdb_info info;
1706 call_switchdev_notifiers(type, dev, &info.info);
1709 static void mlxsw_sp_fdb_notify_mac_process(struct mlxsw_sp *mlxsw_sp,
1710 char *sfn_pl, int rec_index,
1713 struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan;
1714 struct mlxsw_sp_bridge_device *bridge_device;
1715 struct mlxsw_sp_bridge_port *bridge_port;
1716 struct mlxsw_sp_port *mlxsw_sp_port;
1717 enum switchdev_notifier_type type;
1721 bool do_notification = true;
1724 mlxsw_reg_sfn_mac_unpack(sfn_pl, rec_index, mac, &fid, &local_port);
1725 mlxsw_sp_port = mlxsw_sp->ports[local_port];
1726 if (!mlxsw_sp_port) {
1727 dev_err_ratelimited(mlxsw_sp->bus_info->dev, "Incorrect local port in FDB notification\n");
1731 mlxsw_sp_port_vlan = mlxsw_sp_port_vlan_find_by_fid(mlxsw_sp_port, fid);
1732 if (!mlxsw_sp_port_vlan) {
1733 netdev_err(mlxsw_sp_port->dev, "Failed to find a matching {Port, VID} following FDB notification\n");
1737 bridge_port = mlxsw_sp_port_vlan->bridge_port;
1739 netdev_err(mlxsw_sp_port->dev, "{Port, VID} not associated with a bridge\n");
1743 bridge_device = bridge_port->bridge_device;
1744 vid = bridge_device->vlan_enabled ? mlxsw_sp_port_vlan->vid : 0;
1747 err = mlxsw_sp_port_fdb_uc_op(mlxsw_sp, local_port, mac, fid,
1750 dev_err_ratelimited(mlxsw_sp->bus_info->dev, "Failed to set FDB entry\n");
1754 if (!do_notification)
1756 type = adding ? SWITCHDEV_FDB_ADD_TO_BRIDGE : SWITCHDEV_FDB_DEL_TO_BRIDGE;
1757 mlxsw_sp_fdb_call_notifiers(type, mac, vid, bridge_port->dev);
1763 do_notification = false;
1767 static void mlxsw_sp_fdb_notify_mac_lag_process(struct mlxsw_sp *mlxsw_sp,
1768 char *sfn_pl, int rec_index,
1771 struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan;
1772 struct mlxsw_sp_bridge_device *bridge_device;
1773 struct mlxsw_sp_bridge_port *bridge_port;
1774 struct mlxsw_sp_port *mlxsw_sp_port;
1775 enum switchdev_notifier_type type;
1780 bool do_notification = true;
1783 mlxsw_reg_sfn_mac_lag_unpack(sfn_pl, rec_index, mac, &fid, &lag_id);
1784 mlxsw_sp_port = mlxsw_sp_lag_rep_port(mlxsw_sp, lag_id);
1785 if (!mlxsw_sp_port) {
1786 dev_err_ratelimited(mlxsw_sp->bus_info->dev, "Cannot find port representor for LAG\n");
1790 mlxsw_sp_port_vlan = mlxsw_sp_port_vlan_find_by_fid(mlxsw_sp_port, fid);
1791 if (!mlxsw_sp_port_vlan) {
1792 netdev_err(mlxsw_sp_port->dev, "Failed to find a matching {Port, VID} following FDB notification\n");
1796 bridge_port = mlxsw_sp_port_vlan->bridge_port;
1798 netdev_err(mlxsw_sp_port->dev, "{Port, VID} not associated with a bridge\n");
1802 bridge_device = bridge_port->bridge_device;
1803 vid = bridge_device->vlan_enabled ? mlxsw_sp_port_vlan->vid : 0;
1804 lag_vid = mlxsw_sp_port_vlan->vid;
1807 err = mlxsw_sp_port_fdb_uc_lag_op(mlxsw_sp, lag_id, mac, fid, lag_vid,
1810 dev_err_ratelimited(mlxsw_sp->bus_info->dev, "Failed to set FDB entry\n");
1814 if (!do_notification)
1816 type = adding ? SWITCHDEV_FDB_ADD_TO_BRIDGE : SWITCHDEV_FDB_DEL_TO_BRIDGE;
1817 mlxsw_sp_fdb_call_notifiers(type, mac, vid, bridge_port->dev);
1823 do_notification = false;
1827 static void mlxsw_sp_fdb_notify_rec_process(struct mlxsw_sp *mlxsw_sp,
1828 char *sfn_pl, int rec_index)
1830 switch (mlxsw_reg_sfn_rec_type_get(sfn_pl, rec_index)) {
1831 case MLXSW_REG_SFN_REC_TYPE_LEARNED_MAC:
1832 mlxsw_sp_fdb_notify_mac_process(mlxsw_sp, sfn_pl,
1835 case MLXSW_REG_SFN_REC_TYPE_AGED_OUT_MAC:
1836 mlxsw_sp_fdb_notify_mac_process(mlxsw_sp, sfn_pl,
1839 case MLXSW_REG_SFN_REC_TYPE_LEARNED_MAC_LAG:
1840 mlxsw_sp_fdb_notify_mac_lag_process(mlxsw_sp, sfn_pl,
1843 case MLXSW_REG_SFN_REC_TYPE_AGED_OUT_MAC_LAG:
1844 mlxsw_sp_fdb_notify_mac_lag_process(mlxsw_sp, sfn_pl,
1850 static void mlxsw_sp_fdb_notify_work_schedule(struct mlxsw_sp *mlxsw_sp)
1852 struct mlxsw_sp_bridge *bridge = mlxsw_sp->bridge;
1854 mlxsw_core_schedule_dw(&bridge->fdb_notify.dw,
1855 msecs_to_jiffies(bridge->fdb_notify.interval));
1858 static void mlxsw_sp_fdb_notify_work(struct work_struct *work)
1860 struct mlxsw_sp_bridge *bridge;
1861 struct mlxsw_sp *mlxsw_sp;
1867 sfn_pl = kmalloc(MLXSW_REG_SFN_LEN, GFP_KERNEL);
1871 bridge = container_of(work, struct mlxsw_sp_bridge, fdb_notify.dw.work);
1872 mlxsw_sp = bridge->mlxsw_sp;
1875 mlxsw_reg_sfn_pack(sfn_pl);
1876 err = mlxsw_reg_query(mlxsw_sp->core, MLXSW_REG(sfn), sfn_pl);
1878 dev_err_ratelimited(mlxsw_sp->bus_info->dev, "Failed to get FDB notifications\n");
1881 num_rec = mlxsw_reg_sfn_num_rec_get(sfn_pl);
1882 for (i = 0; i < num_rec; i++)
1883 mlxsw_sp_fdb_notify_rec_process(mlxsw_sp, sfn_pl, i);
1888 mlxsw_sp_fdb_notify_work_schedule(mlxsw_sp);
1891 struct mlxsw_sp_switchdev_event_work {
1892 struct work_struct work;
1893 struct switchdev_notifier_fdb_info fdb_info;
1894 struct net_device *dev;
1895 unsigned long event;
1898 static void mlxsw_sp_switchdev_event_work(struct work_struct *work)
1900 struct mlxsw_sp_switchdev_event_work *switchdev_work =
1901 container_of(work, struct mlxsw_sp_switchdev_event_work, work);
1902 struct net_device *dev = switchdev_work->dev;
1903 struct switchdev_notifier_fdb_info *fdb_info;
1904 struct mlxsw_sp_port *mlxsw_sp_port;
1908 mlxsw_sp_port = mlxsw_sp_port_dev_lower_find(dev);
1912 switch (switchdev_work->event) {
1913 case SWITCHDEV_FDB_ADD_TO_DEVICE:
1914 fdb_info = &switchdev_work->fdb_info;
1915 err = mlxsw_sp_port_fdb_set(mlxsw_sp_port, fdb_info, true);
1918 mlxsw_sp_fdb_call_notifiers(SWITCHDEV_FDB_OFFLOADED,
1920 fdb_info->vid, dev);
1922 case SWITCHDEV_FDB_DEL_TO_DEVICE:
1923 fdb_info = &switchdev_work->fdb_info;
1924 mlxsw_sp_port_fdb_set(mlxsw_sp_port, fdb_info, false);
1930 kfree(switchdev_work->fdb_info.addr);
1931 kfree(switchdev_work);
1935 /* Called under rcu_read_lock() */
1936 static int mlxsw_sp_switchdev_event(struct notifier_block *unused,
1937 unsigned long event, void *ptr)
1939 struct net_device *dev = switchdev_notifier_info_to_dev(ptr);
1940 struct mlxsw_sp_switchdev_event_work *switchdev_work;
1941 struct switchdev_notifier_fdb_info *fdb_info = ptr;
1942 struct net_device *br_dev;
1944 /* Tunnel devices are not our uppers, so check their master instead */
1945 br_dev = netdev_master_upper_dev_get_rcu(dev);
1948 if (!netif_is_bridge_master(br_dev))
1950 if (!mlxsw_sp_port_dev_lower_find_rcu(br_dev))
1953 switchdev_work = kzalloc(sizeof(*switchdev_work), GFP_ATOMIC);
1954 if (!switchdev_work)
1957 INIT_WORK(&switchdev_work->work, mlxsw_sp_switchdev_event_work);
1958 switchdev_work->dev = dev;
1959 switchdev_work->event = event;
1962 case SWITCHDEV_FDB_ADD_TO_DEVICE: /* fall through */
1963 case SWITCHDEV_FDB_DEL_TO_DEVICE:
1964 memcpy(&switchdev_work->fdb_info, ptr,
1965 sizeof(switchdev_work->fdb_info));
1966 switchdev_work->fdb_info.addr = kzalloc(ETH_ALEN, GFP_ATOMIC);
1967 if (!switchdev_work->fdb_info.addr)
1968 goto err_addr_alloc;
1969 ether_addr_copy((u8 *)switchdev_work->fdb_info.addr,
1971 /* Take a reference on the device. This can be either
1972 * upper device containig mlxsw_sp_port or just a
1978 kfree(switchdev_work);
1982 mlxsw_core_schedule_work(&switchdev_work->work);
1987 kfree(switchdev_work);
1991 static struct notifier_block mlxsw_sp_switchdev_notifier = {
1992 .notifier_call = mlxsw_sp_switchdev_event,
1995 static int mlxsw_sp_fdb_init(struct mlxsw_sp *mlxsw_sp)
1997 struct mlxsw_sp_bridge *bridge = mlxsw_sp->bridge;
2000 err = mlxsw_sp_ageing_set(mlxsw_sp, MLXSW_SP_DEFAULT_AGEING_TIME);
2002 dev_err(mlxsw_sp->bus_info->dev, "Failed to set default ageing time\n");
2006 err = register_switchdev_notifier(&mlxsw_sp_switchdev_notifier);
2008 dev_err(mlxsw_sp->bus_info->dev, "Failed to register switchdev notifier\n");
2012 INIT_DELAYED_WORK(&bridge->fdb_notify.dw, mlxsw_sp_fdb_notify_work);
2013 bridge->fdb_notify.interval = MLXSW_SP_DEFAULT_LEARNING_INTERVAL;
2014 mlxsw_sp_fdb_notify_work_schedule(mlxsw_sp);
2018 static void mlxsw_sp_fdb_fini(struct mlxsw_sp *mlxsw_sp)
2020 cancel_delayed_work_sync(&mlxsw_sp->bridge->fdb_notify.dw);
2021 unregister_switchdev_notifier(&mlxsw_sp_switchdev_notifier);
2025 static void mlxsw_sp_mids_fini(struct mlxsw_sp *mlxsw_sp)
2027 struct mlxsw_sp_mid *mid, *tmp;
2029 list_for_each_entry_safe(mid, tmp, &mlxsw_sp->bridge->mids_list, list) {
2030 list_del(&mid->list);
2031 clear_bit(mid->mid, mlxsw_sp->bridge->mids_bitmap);
2036 int mlxsw_sp_switchdev_init(struct mlxsw_sp *mlxsw_sp)
2038 struct mlxsw_sp_bridge *bridge;
2040 bridge = kzalloc(sizeof(*mlxsw_sp->bridge), GFP_KERNEL);
2043 mlxsw_sp->bridge = bridge;
2044 bridge->mlxsw_sp = mlxsw_sp;
2046 INIT_LIST_HEAD(&mlxsw_sp->bridge->bridges_list);
2047 INIT_LIST_HEAD(&mlxsw_sp->bridge->mids_list);
2049 bridge->bridge_8021q_ops = &mlxsw_sp_bridge_8021q_ops;
2050 bridge->bridge_8021d_ops = &mlxsw_sp_bridge_8021d_ops;
2052 return mlxsw_sp_fdb_init(mlxsw_sp);
2055 void mlxsw_sp_switchdev_fini(struct mlxsw_sp *mlxsw_sp)
2057 mlxsw_sp_fdb_fini(mlxsw_sp);
2058 mlxsw_sp_mids_fini(mlxsw_sp);
2059 WARN_ON(!list_empty(&mlxsw_sp->bridge->bridges_list));
2060 kfree(mlxsw_sp->bridge);
2063 void mlxsw_sp_port_switchdev_init(struct mlxsw_sp_port *mlxsw_sp_port)
2065 mlxsw_sp_port->dev->switchdev_ops = &mlxsw_sp_port_switchdev_ops;
2068 void mlxsw_sp_port_switchdev_fini(struct mlxsw_sp_port *mlxsw_sp_port)