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 static u16 mlxsw_sp_port_vid_to_fid_get(struct mlxsw_sp_port *mlxsw_sp_port,
60 if (mlxsw_sp_port_is_vport(mlxsw_sp_port)) {
61 u16 vfid = mlxsw_sp_vport_vfid_get(mlxsw_sp_port);
63 fid = mlxsw_sp_vfid_to_fid(vfid);
67 fid = mlxsw_sp_port->pvid;
72 static struct mlxsw_sp_port *
73 mlxsw_sp_port_orig_get(struct net_device *dev,
74 struct mlxsw_sp_port *mlxsw_sp_port)
76 struct mlxsw_sp_port *mlxsw_sp_vport;
79 if (!is_vlan_dev(dev))
82 vid = vlan_dev_vlan_id(dev);
83 mlxsw_sp_vport = mlxsw_sp_port_vport_find(mlxsw_sp_port, vid);
84 WARN_ON(!mlxsw_sp_vport);
86 return mlxsw_sp_vport;
89 static int mlxsw_sp_port_attr_get(struct net_device *dev,
90 struct switchdev_attr *attr)
92 struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev);
93 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
95 mlxsw_sp_port = mlxsw_sp_port_orig_get(attr->orig_dev, mlxsw_sp_port);
100 case SWITCHDEV_ATTR_ID_PORT_PARENT_ID:
101 attr->u.ppid.id_len = sizeof(mlxsw_sp->base_mac);
102 memcpy(&attr->u.ppid.id, &mlxsw_sp->base_mac,
103 attr->u.ppid.id_len);
105 case SWITCHDEV_ATTR_ID_PORT_BRIDGE_FLAGS:
106 attr->u.brport_flags =
107 (mlxsw_sp_port->learning ? BR_LEARNING : 0) |
108 (mlxsw_sp_port->learning_sync ? BR_LEARNING_SYNC : 0) |
109 (mlxsw_sp_port->uc_flood ? BR_FLOOD : 0);
118 static int mlxsw_sp_port_stp_state_set(struct mlxsw_sp_port *mlxsw_sp_port,
121 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
122 enum mlxsw_reg_spms_state spms_state;
128 case BR_STATE_FORWARDING:
129 spms_state = MLXSW_REG_SPMS_STATE_FORWARDING;
131 case BR_STATE_LEARNING:
132 spms_state = MLXSW_REG_SPMS_STATE_LEARNING;
134 case BR_STATE_LISTENING: /* fall-through */
135 case BR_STATE_DISABLED: /* fall-through */
136 case BR_STATE_BLOCKING:
137 spms_state = MLXSW_REG_SPMS_STATE_DISCARDING;
143 spms_pl = kmalloc(MLXSW_REG_SPMS_LEN, GFP_KERNEL);
146 mlxsw_reg_spms_pack(spms_pl, mlxsw_sp_port->local_port);
148 if (mlxsw_sp_port_is_vport(mlxsw_sp_port)) {
149 vid = mlxsw_sp_vport_vid_get(mlxsw_sp_port);
150 mlxsw_reg_spms_vid_pack(spms_pl, vid, spms_state);
152 for_each_set_bit(vid, mlxsw_sp_port->active_vlans, VLAN_N_VID)
153 mlxsw_reg_spms_vid_pack(spms_pl, vid, spms_state);
156 err = mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(spms), spms_pl);
161 static int mlxsw_sp_port_attr_stp_state_set(struct mlxsw_sp_port *mlxsw_sp_port,
162 struct switchdev_trans *trans,
165 if (switchdev_trans_ph_prepare(trans))
168 mlxsw_sp_port->stp_state = state;
169 return mlxsw_sp_port_stp_state_set(mlxsw_sp_port, state);
172 static bool mlxsw_sp_vfid_is_vport_br(u16 vfid)
174 return vfid >= MLXSW_SP_VFID_PORT_MAX;
177 static int __mlxsw_sp_port_flood_set(struct mlxsw_sp_port *mlxsw_sp_port,
178 u16 idx_begin, u16 idx_end, bool set,
181 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
182 u16 local_port = mlxsw_sp_port->local_port;
183 enum mlxsw_flood_table_type table_type;
184 u16 range = idx_end - idx_begin + 1;
188 if (mlxsw_sp_port_is_vport(mlxsw_sp_port)) {
189 table_type = MLXSW_REG_SFGC_TABLE_TYPE_FID;
190 if (mlxsw_sp_vfid_is_vport_br(idx_begin))
191 local_port = mlxsw_sp_port->local_port;
193 local_port = MLXSW_PORT_CPU_PORT;
195 table_type = MLXSW_REG_SFGC_TABLE_TYPE_FID_OFFEST;
198 sftr_pl = kmalloc(MLXSW_REG_SFTR_LEN, GFP_KERNEL);
202 mlxsw_reg_sftr_pack(sftr_pl, MLXSW_SP_FLOOD_TABLE_UC, idx_begin,
203 table_type, range, local_port, set);
204 err = mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(sftr), sftr_pl);
208 /* Flooding control allows one to decide whether a given port will
209 * flood unicast traffic for which there is no FDB entry.
214 mlxsw_reg_sftr_pack(sftr_pl, MLXSW_SP_FLOOD_TABLE_BM, idx_begin,
215 table_type, range, local_port, set);
216 err = mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(sftr), sftr_pl);
223 static int mlxsw_sp_port_uc_flood_set(struct mlxsw_sp_port *mlxsw_sp_port,
226 struct net_device *dev = mlxsw_sp_port->dev;
227 u16 vid, last_visited_vid;
230 if (mlxsw_sp_port_is_vport(mlxsw_sp_port)) {
231 u16 vfid = mlxsw_sp_vport_vfid_get(mlxsw_sp_port);
233 return __mlxsw_sp_port_flood_set(mlxsw_sp_port, vfid, vfid,
237 for_each_set_bit(vid, mlxsw_sp_port->active_vlans, VLAN_N_VID) {
238 err = __mlxsw_sp_port_flood_set(mlxsw_sp_port, vid, vid, set,
241 last_visited_vid = vid;
242 goto err_port_flood_set;
249 for_each_set_bit(vid, mlxsw_sp_port->active_vlans, last_visited_vid)
250 __mlxsw_sp_port_flood_set(mlxsw_sp_port, vid, vid, !set, true);
251 netdev_err(dev, "Failed to configure unicast flooding\n");
255 int mlxsw_sp_vport_flood_set(struct mlxsw_sp_port *mlxsw_sp_vport, u16 vfid,
256 bool set, bool only_uc)
258 /* In case of vFIDs, index into the flooding table is relative to
259 * the start of the vFIDs range.
261 return __mlxsw_sp_port_flood_set(mlxsw_sp_vport, vfid, vfid, set,
265 static int mlxsw_sp_port_attr_br_flags_set(struct mlxsw_sp_port *mlxsw_sp_port,
266 struct switchdev_trans *trans,
267 unsigned long brport_flags)
269 unsigned long uc_flood = mlxsw_sp_port->uc_flood ? BR_FLOOD : 0;
273 if (!mlxsw_sp_port->bridged)
276 if (switchdev_trans_ph_prepare(trans))
279 if ((uc_flood ^ brport_flags) & BR_FLOOD) {
280 set = mlxsw_sp_port->uc_flood ? false : true;
281 err = mlxsw_sp_port_uc_flood_set(mlxsw_sp_port, set);
286 mlxsw_sp_port->uc_flood = brport_flags & BR_FLOOD ? 1 : 0;
287 mlxsw_sp_port->learning = brport_flags & BR_LEARNING ? 1 : 0;
288 mlxsw_sp_port->learning_sync = brport_flags & BR_LEARNING_SYNC ? 1 : 0;
293 static int mlxsw_sp_ageing_set(struct mlxsw_sp *mlxsw_sp, u32 ageing_time)
295 char sfdat_pl[MLXSW_REG_SFDAT_LEN];
298 mlxsw_reg_sfdat_pack(sfdat_pl, ageing_time);
299 err = mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(sfdat), sfdat_pl);
302 mlxsw_sp->ageing_time = ageing_time;
306 static int mlxsw_sp_port_attr_br_ageing_set(struct mlxsw_sp_port *mlxsw_sp_port,
307 struct switchdev_trans *trans,
308 unsigned long ageing_clock_t)
310 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
311 unsigned long ageing_jiffies = clock_t_to_jiffies(ageing_clock_t);
312 u32 ageing_time = jiffies_to_msecs(ageing_jiffies) / 1000;
314 if (switchdev_trans_ph_prepare(trans))
317 return mlxsw_sp_ageing_set(mlxsw_sp, ageing_time);
320 static int mlxsw_sp_port_attr_br_vlan_set(struct mlxsw_sp_port *mlxsw_sp_port,
321 struct switchdev_trans *trans,
322 struct net_device *orig_dev,
325 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
327 /* SWITCHDEV_TRANS_PREPARE phase */
328 if ((!vlan_enabled) && (mlxsw_sp->master_bridge.dev == orig_dev)) {
329 netdev_err(mlxsw_sp_port->dev, "Bridge must be vlan-aware\n");
336 static int mlxsw_sp_port_attr_set(struct net_device *dev,
337 const struct switchdev_attr *attr,
338 struct switchdev_trans *trans)
340 struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev);
343 mlxsw_sp_port = mlxsw_sp_port_orig_get(attr->orig_dev, mlxsw_sp_port);
348 case SWITCHDEV_ATTR_ID_PORT_STP_STATE:
349 err = mlxsw_sp_port_attr_stp_state_set(mlxsw_sp_port, trans,
352 case SWITCHDEV_ATTR_ID_PORT_BRIDGE_FLAGS:
353 err = mlxsw_sp_port_attr_br_flags_set(mlxsw_sp_port, trans,
354 attr->u.brport_flags);
356 case SWITCHDEV_ATTR_ID_BRIDGE_AGEING_TIME:
357 err = mlxsw_sp_port_attr_br_ageing_set(mlxsw_sp_port, trans,
358 attr->u.ageing_time);
360 case SWITCHDEV_ATTR_ID_BRIDGE_VLAN_FILTERING:
361 err = mlxsw_sp_port_attr_br_vlan_set(mlxsw_sp_port, trans,
363 attr->u.vlan_filtering);
373 static int mlxsw_sp_port_pvid_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid)
375 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
376 char spvid_pl[MLXSW_REG_SPVID_LEN];
378 mlxsw_reg_spvid_pack(spvid_pl, mlxsw_sp_port->local_port, vid);
379 return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(spvid), spvid_pl);
382 static int mlxsw_sp_fid_create(struct mlxsw_sp *mlxsw_sp, u16 fid)
384 char sfmr_pl[MLXSW_REG_SFMR_LEN];
387 mlxsw_reg_sfmr_pack(sfmr_pl, MLXSW_REG_SFMR_OP_CREATE_FID, fid, fid);
388 err = mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(sfmr), sfmr_pl);
393 set_bit(fid, mlxsw_sp->active_fids);
397 static void mlxsw_sp_fid_destroy(struct mlxsw_sp *mlxsw_sp, u16 fid)
399 char sfmr_pl[MLXSW_REG_SFMR_LEN];
401 clear_bit(fid, mlxsw_sp->active_fids);
403 mlxsw_reg_sfmr_pack(sfmr_pl, MLXSW_REG_SFMR_OP_DESTROY_FID,
405 mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(sfmr), sfmr_pl);
408 static int mlxsw_sp_port_fid_map(struct mlxsw_sp_port *mlxsw_sp_port, u16 fid)
410 enum mlxsw_reg_svfa_mt mt;
412 if (!list_empty(&mlxsw_sp_port->vports_list))
413 mt = MLXSW_REG_SVFA_MT_PORT_VID_TO_FID;
415 mt = MLXSW_REG_SVFA_MT_VID_TO_FID;
417 return mlxsw_sp_port_vid_to_fid_set(mlxsw_sp_port, mt, true, fid, fid);
420 static int mlxsw_sp_port_fid_unmap(struct mlxsw_sp_port *mlxsw_sp_port, u16 fid)
422 enum mlxsw_reg_svfa_mt mt;
424 if (list_empty(&mlxsw_sp_port->vports_list))
427 mt = MLXSW_REG_SVFA_MT_PORT_VID_TO_FID;
428 return mlxsw_sp_port_vid_to_fid_set(mlxsw_sp_port, mt, false, fid, fid);
431 static int mlxsw_sp_port_add_vids(struct net_device *dev, u16 vid_begin,
437 for (vid = vid_begin; vid <= vid_end; vid++) {
438 err = mlxsw_sp_port_add_vid(dev, 0, vid);
440 goto err_port_add_vid;
445 for (vid--; vid >= vid_begin; vid--)
446 mlxsw_sp_port_kill_vid(dev, 0, vid);
450 static int __mlxsw_sp_port_vlans_set(struct mlxsw_sp_port *mlxsw_sp_port,
451 u16 vid_begin, u16 vid_end, bool is_member,
457 for (vid = vid_begin; vid <= vid_end;
458 vid += MLXSW_REG_SPVM_REC_MAX_COUNT) {
459 vid_e = min((u16) (vid + MLXSW_REG_SPVM_REC_MAX_COUNT - 1),
462 err = mlxsw_sp_port_vlan_set(mlxsw_sp_port, vid, vid_e,
463 is_member, untagged);
471 static int __mlxsw_sp_port_vlans_add(struct mlxsw_sp_port *mlxsw_sp_port,
472 u16 vid_begin, u16 vid_end,
473 bool flag_untagged, bool flag_pvid)
475 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
476 struct net_device *dev = mlxsw_sp_port->dev;
477 u16 vid, last_visited_vid, old_pvid;
478 enum mlxsw_reg_svfa_mt mt;
481 /* In case this is invoked with BRIDGE_FLAGS_SELF and port is
482 * not bridged, then packets ingressing through the port with
483 * the specified VIDs will be directed to CPU.
485 if (!mlxsw_sp_port->bridged)
486 return mlxsw_sp_port_add_vids(dev, vid_begin, vid_end);
488 for (vid = vid_begin; vid <= vid_end; vid++) {
489 if (!test_bit(vid, mlxsw_sp->active_fids)) {
490 err = mlxsw_sp_fid_create(mlxsw_sp, vid);
492 netdev_err(dev, "Failed to create FID=%d\n",
497 /* When creating a FID, we set a VID to FID mapping
498 * regardless of the port's mode.
500 mt = MLXSW_REG_SVFA_MT_VID_TO_FID;
501 err = mlxsw_sp_port_vid_to_fid_set(mlxsw_sp_port, mt,
504 netdev_err(dev, "Failed to create FID=VID=%d mapping\n",
506 goto err_port_vid_to_fid_set;
511 /* Set FID mapping according to port's mode */
512 for (vid = vid_begin; vid <= vid_end; vid++) {
513 err = mlxsw_sp_port_fid_map(mlxsw_sp_port, vid);
515 netdev_err(dev, "Failed to map FID=%d", vid);
516 last_visited_vid = --vid;
517 goto err_port_fid_map;
521 err = __mlxsw_sp_port_flood_set(mlxsw_sp_port, vid_begin, vid_end,
524 netdev_err(dev, "Failed to configure flooding\n");
525 goto err_port_flood_set;
528 err = __mlxsw_sp_port_vlans_set(mlxsw_sp_port, vid_begin, vid_end,
529 true, flag_untagged);
531 netdev_err(dev, "Unable to add VIDs %d-%d\n", vid_begin,
533 goto err_port_vlans_set;
536 old_pvid = mlxsw_sp_port->pvid;
537 if (flag_pvid && old_pvid != vid_begin) {
538 err = mlxsw_sp_port_pvid_set(mlxsw_sp_port, vid_begin);
540 netdev_err(dev, "Unable to add PVID %d\n", vid_begin);
541 goto err_port_pvid_set;
543 mlxsw_sp_port->pvid = vid_begin;
546 /* Changing activity bits only if HW operation succeded */
547 for (vid = vid_begin; vid <= vid_end; vid++) {
548 set_bit(vid, mlxsw_sp_port->active_vlans);
550 set_bit(vid, mlxsw_sp_port->untagged_vlans);
552 clear_bit(vid, mlxsw_sp_port->untagged_vlans);
555 /* STP state change must be done after we set active VLANs */
556 err = mlxsw_sp_port_stp_state_set(mlxsw_sp_port,
557 mlxsw_sp_port->stp_state);
559 netdev_err(dev, "Failed to set STP state\n");
560 goto err_port_stp_state_set;
565 err_port_vid_to_fid_set:
566 mlxsw_sp_fid_destroy(mlxsw_sp, vid);
569 err_port_stp_state_set:
570 for (vid = vid_begin; vid <= vid_end; vid++)
571 clear_bit(vid, mlxsw_sp_port->active_vlans);
572 if (old_pvid != mlxsw_sp_port->pvid)
573 mlxsw_sp_port_pvid_set(mlxsw_sp_port, old_pvid);
575 __mlxsw_sp_port_vlans_set(mlxsw_sp_port, vid_begin, vid_end, false,
578 __mlxsw_sp_port_flood_set(mlxsw_sp_port, vid_begin, vid_end, false,
581 last_visited_vid = vid_end;
583 for (vid = last_visited_vid; vid >= vid_begin; vid--)
584 mlxsw_sp_port_fid_unmap(mlxsw_sp_port, vid);
588 static int mlxsw_sp_port_vlans_add(struct mlxsw_sp_port *mlxsw_sp_port,
589 const struct switchdev_obj_port_vlan *vlan,
590 struct switchdev_trans *trans)
592 bool flag_untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
593 bool flag_pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
595 if (switchdev_trans_ph_prepare(trans))
598 return __mlxsw_sp_port_vlans_add(mlxsw_sp_port,
599 vlan->vid_begin, vlan->vid_end,
600 flag_untagged, flag_pvid);
603 static enum mlxsw_reg_sfd_rec_policy mlxsw_sp_sfd_rec_policy(bool dynamic)
605 return dynamic ? MLXSW_REG_SFD_REC_POLICY_DYNAMIC_ENTRY_INGRESS :
606 MLXSW_REG_SFD_REC_POLICY_STATIC_ENTRY;
609 static enum mlxsw_reg_sfd_op mlxsw_sp_sfd_op(bool adding)
611 return adding ? MLXSW_REG_SFD_OP_WRITE_EDIT :
612 MLXSW_REG_SFD_OP_WRITE_REMOVE;
615 static int mlxsw_sp_port_fdb_uc_op(struct mlxsw_sp *mlxsw_sp, u8 local_port,
616 const char *mac, u16 fid, bool adding,
622 sfd_pl = kmalloc(MLXSW_REG_SFD_LEN, GFP_KERNEL);
626 mlxsw_reg_sfd_pack(sfd_pl, mlxsw_sp_sfd_op(adding), 0);
627 mlxsw_reg_sfd_uc_pack(sfd_pl, 0, mlxsw_sp_sfd_rec_policy(dynamic),
628 mac, fid, MLXSW_REG_SFD_REC_ACTION_NOP,
630 err = mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(sfd), sfd_pl);
636 static int mlxsw_sp_port_fdb_uc_lag_op(struct mlxsw_sp *mlxsw_sp, u16 lag_id,
637 const char *mac, u16 fid, u16 lag_vid,
638 bool adding, bool dynamic)
643 sfd_pl = kmalloc(MLXSW_REG_SFD_LEN, GFP_KERNEL);
647 mlxsw_reg_sfd_pack(sfd_pl, mlxsw_sp_sfd_op(adding), 0);
648 mlxsw_reg_sfd_uc_lag_pack(sfd_pl, 0, mlxsw_sp_sfd_rec_policy(dynamic),
649 mac, fid, MLXSW_REG_SFD_REC_ACTION_NOP,
651 err = mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(sfd), sfd_pl);
658 mlxsw_sp_port_fdb_static_add(struct mlxsw_sp_port *mlxsw_sp_port,
659 const struct switchdev_obj_port_fdb *fdb,
660 struct switchdev_trans *trans)
662 u16 fid = mlxsw_sp_port_vid_to_fid_get(mlxsw_sp_port, fdb->vid);
665 if (switchdev_trans_ph_prepare(trans))
668 if (mlxsw_sp_port_is_vport(mlxsw_sp_port)) {
669 lag_vid = mlxsw_sp_vport_vid_get(mlxsw_sp_port);
672 if (!mlxsw_sp_port->lagged)
673 return mlxsw_sp_port_fdb_uc_op(mlxsw_sp_port->mlxsw_sp,
674 mlxsw_sp_port->local_port,
675 fdb->addr, fid, true, false);
677 return mlxsw_sp_port_fdb_uc_lag_op(mlxsw_sp_port->mlxsw_sp,
678 mlxsw_sp_port->lag_id,
679 fdb->addr, fid, lag_vid,
683 static int mlxsw_sp_port_mdb_op(struct mlxsw_sp *mlxsw_sp, const char *addr,
684 u16 fid, u16 mid, bool adding)
689 sfd_pl = kmalloc(MLXSW_REG_SFD_LEN, GFP_KERNEL);
693 mlxsw_reg_sfd_pack(sfd_pl, mlxsw_sp_sfd_op(adding), 0);
694 mlxsw_reg_sfd_mc_pack(sfd_pl, 0, addr, fid,
695 MLXSW_REG_SFD_REC_ACTION_NOP, mid);
696 err = mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(sfd), sfd_pl);
701 static int mlxsw_sp_port_smid_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 mid,
702 bool add, bool clear_all_ports)
704 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
708 smid_pl = kmalloc(MLXSW_REG_SMID_LEN, GFP_KERNEL);
712 mlxsw_reg_smid_pack(smid_pl, mid, mlxsw_sp_port->local_port, add);
713 if (clear_all_ports) {
714 for (i = 1; i < MLXSW_PORT_MAX_PORTS; i++)
715 if (mlxsw_sp->ports[i])
716 mlxsw_reg_smid_port_mask_set(smid_pl, i, 1);
718 err = mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(smid), smid_pl);
723 static struct mlxsw_sp_mid *__mlxsw_sp_mc_get(struct mlxsw_sp *mlxsw_sp,
724 const unsigned char *addr,
727 struct mlxsw_sp_mid *mid;
729 list_for_each_entry(mid, &mlxsw_sp->br_mids.list, list) {
730 if (ether_addr_equal(mid->addr, addr) && mid->vid == vid)
736 static struct mlxsw_sp_mid *__mlxsw_sp_mc_alloc(struct mlxsw_sp *mlxsw_sp,
737 const unsigned char *addr,
740 struct mlxsw_sp_mid *mid;
743 mid_idx = find_first_zero_bit(mlxsw_sp->br_mids.mapped,
745 if (mid_idx == MLXSW_SP_MID_MAX)
748 mid = kzalloc(sizeof(*mid), GFP_KERNEL);
752 set_bit(mid_idx, mlxsw_sp->br_mids.mapped);
753 ether_addr_copy(mid->addr, addr);
757 list_add_tail(&mid->list, &mlxsw_sp->br_mids.list);
762 static int __mlxsw_sp_mc_dec_ref(struct mlxsw_sp *mlxsw_sp,
763 struct mlxsw_sp_mid *mid)
765 if (--mid->ref_count == 0) {
766 list_del(&mid->list);
767 clear_bit(mid->mid, mlxsw_sp->br_mids.mapped);
774 static int mlxsw_sp_port_mdb_add(struct mlxsw_sp_port *mlxsw_sp_port,
775 const struct switchdev_obj_port_mdb *mdb,
776 struct switchdev_trans *trans)
778 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
779 struct net_device *dev = mlxsw_sp_port->dev;
780 struct mlxsw_sp_mid *mid;
781 u16 fid = mlxsw_sp_port_vid_to_fid_get(mlxsw_sp_port, mdb->vid);
784 if (switchdev_trans_ph_prepare(trans))
787 mid = __mlxsw_sp_mc_get(mlxsw_sp, mdb->addr, mdb->vid);
789 mid = __mlxsw_sp_mc_alloc(mlxsw_sp, mdb->addr, mdb->vid);
791 netdev_err(dev, "Unable to allocate MC group\n");
797 err = mlxsw_sp_port_smid_set(mlxsw_sp_port, mid->mid, true,
798 mid->ref_count == 1);
800 netdev_err(dev, "Unable to set SMID\n");
804 if (mid->ref_count == 1) {
805 err = mlxsw_sp_port_mdb_op(mlxsw_sp, mdb->addr, fid, mid->mid,
808 netdev_err(dev, "Unable to set MC SFD\n");
816 __mlxsw_sp_mc_dec_ref(mlxsw_sp, mid);
820 static int mlxsw_sp_port_obj_add(struct net_device *dev,
821 const struct switchdev_obj *obj,
822 struct switchdev_trans *trans)
824 struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev);
827 mlxsw_sp_port = mlxsw_sp_port_orig_get(obj->orig_dev, mlxsw_sp_port);
832 case SWITCHDEV_OBJ_ID_PORT_VLAN:
833 if (mlxsw_sp_port_is_vport(mlxsw_sp_port))
836 err = mlxsw_sp_port_vlans_add(mlxsw_sp_port,
837 SWITCHDEV_OBJ_PORT_VLAN(obj),
840 case SWITCHDEV_OBJ_ID_PORT_FDB:
841 err = mlxsw_sp_port_fdb_static_add(mlxsw_sp_port,
842 SWITCHDEV_OBJ_PORT_FDB(obj),
845 case SWITCHDEV_OBJ_ID_PORT_MDB:
846 err = mlxsw_sp_port_mdb_add(mlxsw_sp_port,
847 SWITCHDEV_OBJ_PORT_MDB(obj),
858 static int mlxsw_sp_port_kill_vids(struct net_device *dev, u16 vid_begin,
864 for (vid = vid_begin; vid <= vid_end; vid++) {
865 err = mlxsw_sp_port_kill_vid(dev, 0, vid);
873 static int __mlxsw_sp_port_vlans_del(struct mlxsw_sp_port *mlxsw_sp_port,
874 u16 vid_begin, u16 vid_end, bool init)
876 struct net_device *dev = mlxsw_sp_port->dev;
880 /* In case this is invoked with BRIDGE_FLAGS_SELF and port is
881 * not bridged, then prevent packets ingressing through the
882 * port with the specified VIDs from being trapped to CPU.
884 if (!init && !mlxsw_sp_port->bridged)
885 return mlxsw_sp_port_kill_vids(dev, vid_begin, vid_end);
887 err = __mlxsw_sp_port_vlans_set(mlxsw_sp_port, vid_begin, vid_end,
890 netdev_err(dev, "Unable to del VIDs %d-%d\n", vid_begin,
895 pvid = mlxsw_sp_port->pvid;
896 if (pvid >= vid_begin && pvid <= vid_end && pvid != 1) {
897 /* Default VLAN is always 1 */
898 err = mlxsw_sp_port_pvid_set(mlxsw_sp_port, 1);
900 netdev_err(dev, "Unable to del PVID %d\n", pvid);
903 mlxsw_sp_port->pvid = 1;
909 err = __mlxsw_sp_port_flood_set(mlxsw_sp_port, vid_begin, vid_end,
912 netdev_err(dev, "Failed to clear flooding\n");
916 for (vid = vid_begin; vid <= vid_end; vid++) {
917 /* Remove FID mapping in case of Virtual mode */
918 err = mlxsw_sp_port_fid_unmap(mlxsw_sp_port, vid);
920 netdev_err(dev, "Failed to unmap FID=%d", vid);
926 /* Changing activity bits only if HW operation succeded */
927 for (vid = vid_begin; vid <= vid_end; vid++)
928 clear_bit(vid, mlxsw_sp_port->active_vlans);
933 static int mlxsw_sp_port_vlans_del(struct mlxsw_sp_port *mlxsw_sp_port,
934 const struct switchdev_obj_port_vlan *vlan)
936 return __mlxsw_sp_port_vlans_del(mlxsw_sp_port,
937 vlan->vid_begin, vlan->vid_end, false);
940 void mlxsw_sp_port_active_vlans_del(struct mlxsw_sp_port *mlxsw_sp_port)
944 for_each_set_bit(vid, mlxsw_sp_port->active_vlans, VLAN_N_VID)
945 __mlxsw_sp_port_vlans_del(mlxsw_sp_port, vid, vid, false);
949 mlxsw_sp_port_fdb_static_del(struct mlxsw_sp_port *mlxsw_sp_port,
950 const struct switchdev_obj_port_fdb *fdb)
952 u16 fid = mlxsw_sp_port_vid_to_fid_get(mlxsw_sp_port, fdb->vid);
955 if (mlxsw_sp_port_is_vport(mlxsw_sp_port)) {
956 lag_vid = mlxsw_sp_vport_vid_get(mlxsw_sp_port);
959 if (!mlxsw_sp_port->lagged)
960 return mlxsw_sp_port_fdb_uc_op(mlxsw_sp_port->mlxsw_sp,
961 mlxsw_sp_port->local_port,
965 return mlxsw_sp_port_fdb_uc_lag_op(mlxsw_sp_port->mlxsw_sp,
966 mlxsw_sp_port->lag_id,
967 fdb->addr, fid, lag_vid,
971 static int mlxsw_sp_port_mdb_del(struct mlxsw_sp_port *mlxsw_sp_port,
972 const struct switchdev_obj_port_mdb *mdb)
974 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
975 struct net_device *dev = mlxsw_sp_port->dev;
976 struct mlxsw_sp_mid *mid;
977 u16 fid = mlxsw_sp_port_vid_to_fid_get(mlxsw_sp_port, mdb->vid);
981 mid = __mlxsw_sp_mc_get(mlxsw_sp, mdb->addr, mdb->vid);
983 netdev_err(dev, "Unable to remove port from MC DB\n");
987 err = mlxsw_sp_port_smid_set(mlxsw_sp_port, mid->mid, false, false);
989 netdev_err(dev, "Unable to remove port from SMID\n");
992 if (__mlxsw_sp_mc_dec_ref(mlxsw_sp, mid)) {
993 err = mlxsw_sp_port_mdb_op(mlxsw_sp, mdb->addr, fid, mid_idx,
996 netdev_err(dev, "Unable to remove MC SFD\n");
1002 static int mlxsw_sp_port_obj_del(struct net_device *dev,
1003 const struct switchdev_obj *obj)
1005 struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev);
1008 mlxsw_sp_port = mlxsw_sp_port_orig_get(obj->orig_dev, mlxsw_sp_port);
1013 case SWITCHDEV_OBJ_ID_PORT_VLAN:
1014 if (mlxsw_sp_port_is_vport(mlxsw_sp_port))
1017 err = mlxsw_sp_port_vlans_del(mlxsw_sp_port,
1018 SWITCHDEV_OBJ_PORT_VLAN(obj));
1020 case SWITCHDEV_OBJ_ID_PORT_FDB:
1021 err = mlxsw_sp_port_fdb_static_del(mlxsw_sp_port,
1022 SWITCHDEV_OBJ_PORT_FDB(obj));
1024 case SWITCHDEV_OBJ_ID_PORT_MDB:
1025 err = mlxsw_sp_port_mdb_del(mlxsw_sp_port,
1026 SWITCHDEV_OBJ_PORT_MDB(obj));
1036 static struct mlxsw_sp_port *mlxsw_sp_lag_rep_port(struct mlxsw_sp *mlxsw_sp,
1039 struct mlxsw_sp_port *mlxsw_sp_port;
1042 for (i = 0; i < MLXSW_SP_PORT_PER_LAG_MAX; i++) {
1043 mlxsw_sp_port = mlxsw_sp_port_lagged_get(mlxsw_sp, lag_id, i);
1045 return mlxsw_sp_port;
1050 static int mlxsw_sp_port_fdb_dump(struct mlxsw_sp_port *mlxsw_sp_port,
1051 struct switchdev_obj_port_fdb *fdb,
1052 switchdev_obj_dump_cb_t *cb,
1053 struct net_device *orig_dev)
1055 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
1056 struct mlxsw_sp_port *tmp;
1068 sfd_pl = kmalloc(MLXSW_REG_SFD_LEN, GFP_KERNEL);
1072 if (mlxsw_sp_port_is_vport(mlxsw_sp_port)) {
1075 tmp = mlxsw_sp_vport_vfid_get(mlxsw_sp_port);
1076 vport_fid = mlxsw_sp_vfid_to_fid(tmp);
1079 mlxsw_reg_sfd_pack(sfd_pl, MLXSW_REG_SFD_OP_QUERY_DUMP, 0);
1081 mlxsw_reg_sfd_num_rec_set(sfd_pl, MLXSW_REG_SFD_REC_MAX_COUNT);
1082 err = mlxsw_reg_query(mlxsw_sp->core, MLXSW_REG(sfd), sfd_pl);
1086 num_rec = mlxsw_reg_sfd_num_rec_get(sfd_pl);
1088 /* Even in case of error, we have to run the dump to the end
1089 * so the session in firmware is finished.
1094 for (i = 0; i < num_rec; i++) {
1095 switch (mlxsw_reg_sfd_rec_type_get(sfd_pl, i)) {
1096 case MLXSW_REG_SFD_REC_TYPE_UNICAST:
1097 mlxsw_reg_sfd_uc_unpack(sfd_pl, i, mac, &fid,
1099 if (local_port == mlxsw_sp_port->local_port) {
1100 if (vport_fid && vport_fid == fid)
1102 else if (!vport_fid &&
1103 !mlxsw_sp_fid_is_vfid(fid))
1107 ether_addr_copy(fdb->addr, mac);
1108 fdb->ndm_state = NUD_REACHABLE;
1109 err = cb(&fdb->obj);
1114 case MLXSW_REG_SFD_REC_TYPE_UNICAST_LAG:
1115 mlxsw_reg_sfd_uc_lag_unpack(sfd_pl, i,
1116 mac, &fid, &lag_id);
1117 tmp = mlxsw_sp_lag_rep_port(mlxsw_sp, lag_id);
1118 if (tmp && tmp->local_port ==
1119 mlxsw_sp_port->local_port) {
1120 /* LAG records can only point to LAG
1121 * devices or VLAN devices on top.
1123 if (!netif_is_lag_master(orig_dev) &&
1124 !is_vlan_dev(orig_dev))
1126 if (vport_fid && vport_fid == fid)
1128 else if (!vport_fid &&
1129 !mlxsw_sp_fid_is_vfid(fid))
1133 ether_addr_copy(fdb->addr, mac);
1134 fdb->ndm_state = NUD_REACHABLE;
1135 err = cb(&fdb->obj);
1142 } while (num_rec == MLXSW_REG_SFD_REC_MAX_COUNT);
1146 return stored_err ? stored_err : err;
1149 static int mlxsw_sp_port_vlan_dump(struct mlxsw_sp_port *mlxsw_sp_port,
1150 struct switchdev_obj_port_vlan *vlan,
1151 switchdev_obj_dump_cb_t *cb)
1156 if (mlxsw_sp_port_is_vport(mlxsw_sp_port)) {
1158 vlan->vid_begin = mlxsw_sp_vport_vid_get(mlxsw_sp_port);
1159 vlan->vid_end = mlxsw_sp_vport_vid_get(mlxsw_sp_port);
1160 return cb(&vlan->obj);
1163 for_each_set_bit(vid, mlxsw_sp_port->active_vlans, VLAN_N_VID) {
1165 if (vid == mlxsw_sp_port->pvid)
1166 vlan->flags |= BRIDGE_VLAN_INFO_PVID;
1167 if (test_bit(vid, mlxsw_sp_port->untagged_vlans))
1168 vlan->flags |= BRIDGE_VLAN_INFO_UNTAGGED;
1169 vlan->vid_begin = vid;
1170 vlan->vid_end = vid;
1171 err = cb(&vlan->obj);
1178 static int mlxsw_sp_port_obj_dump(struct net_device *dev,
1179 struct switchdev_obj *obj,
1180 switchdev_obj_dump_cb_t *cb)
1182 struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev);
1185 mlxsw_sp_port = mlxsw_sp_port_orig_get(obj->orig_dev, mlxsw_sp_port);
1190 case SWITCHDEV_OBJ_ID_PORT_VLAN:
1191 err = mlxsw_sp_port_vlan_dump(mlxsw_sp_port,
1192 SWITCHDEV_OBJ_PORT_VLAN(obj), cb);
1194 case SWITCHDEV_OBJ_ID_PORT_FDB:
1195 err = mlxsw_sp_port_fdb_dump(mlxsw_sp_port,
1196 SWITCHDEV_OBJ_PORT_FDB(obj), cb,
1207 static const struct switchdev_ops mlxsw_sp_port_switchdev_ops = {
1208 .switchdev_port_attr_get = mlxsw_sp_port_attr_get,
1209 .switchdev_port_attr_set = mlxsw_sp_port_attr_set,
1210 .switchdev_port_obj_add = mlxsw_sp_port_obj_add,
1211 .switchdev_port_obj_del = mlxsw_sp_port_obj_del,
1212 .switchdev_port_obj_dump = mlxsw_sp_port_obj_dump,
1215 static void mlxsw_sp_fdb_call_notifiers(bool learning_sync, bool adding,
1217 struct net_device *dev)
1219 struct switchdev_notifier_fdb_info info;
1220 unsigned long notifier_type;
1222 if (learning_sync) {
1225 notifier_type = adding ? SWITCHDEV_FDB_ADD : SWITCHDEV_FDB_DEL;
1226 call_switchdev_notifiers(notifier_type, dev, &info.info);
1230 static void mlxsw_sp_fdb_notify_mac_process(struct mlxsw_sp *mlxsw_sp,
1231 char *sfn_pl, int rec_index,
1234 struct mlxsw_sp_port *mlxsw_sp_port;
1238 bool do_notification = true;
1241 mlxsw_reg_sfn_mac_unpack(sfn_pl, rec_index, mac, &fid, &local_port);
1242 mlxsw_sp_port = mlxsw_sp->ports[local_port];
1243 if (!mlxsw_sp_port) {
1244 dev_err_ratelimited(mlxsw_sp->bus_info->dev, "Incorrect local port in FDB notification\n");
1248 if (mlxsw_sp_fid_is_vfid(fid)) {
1249 u16 vfid = mlxsw_sp_fid_to_vfid(fid);
1250 struct mlxsw_sp_port *mlxsw_sp_vport;
1252 mlxsw_sp_vport = mlxsw_sp_port_vport_find_by_vfid(mlxsw_sp_port,
1254 if (!mlxsw_sp_vport) {
1255 netdev_err(mlxsw_sp_port->dev, "Failed to find a matching vPort following FDB notification\n");
1259 /* Override the physical port with the vPort. */
1260 mlxsw_sp_port = mlxsw_sp_vport;
1265 adding = adding && mlxsw_sp_port->learning;
1268 err = mlxsw_sp_port_fdb_uc_op(mlxsw_sp, local_port, mac, fid,
1271 if (net_ratelimit())
1272 netdev_err(mlxsw_sp_port->dev, "Failed to set FDB entry\n");
1276 if (!do_notification)
1278 mlxsw_sp_fdb_call_notifiers(mlxsw_sp_port->learning_sync,
1279 adding, mac, vid, mlxsw_sp_port->dev);
1284 do_notification = false;
1288 static void mlxsw_sp_fdb_notify_mac_lag_process(struct mlxsw_sp *mlxsw_sp,
1289 char *sfn_pl, int rec_index,
1292 struct mlxsw_sp_port *mlxsw_sp_port;
1293 struct net_device *dev;
1298 bool do_notification = true;
1301 mlxsw_reg_sfn_mac_lag_unpack(sfn_pl, rec_index, mac, &fid, &lag_id);
1302 mlxsw_sp_port = mlxsw_sp_lag_rep_port(mlxsw_sp, lag_id);
1303 if (!mlxsw_sp_port) {
1304 dev_err_ratelimited(mlxsw_sp->bus_info->dev, "Cannot find port representor for LAG\n");
1308 if (mlxsw_sp_fid_is_vfid(fid)) {
1309 u16 vfid = mlxsw_sp_fid_to_vfid(fid);
1310 struct mlxsw_sp_port *mlxsw_sp_vport;
1312 mlxsw_sp_vport = mlxsw_sp_port_vport_find_by_vfid(mlxsw_sp_port,
1314 if (!mlxsw_sp_vport) {
1315 netdev_err(mlxsw_sp_port->dev, "Failed to find a matching vPort following FDB notification\n");
1319 lag_vid = mlxsw_sp_vport_vid_get(mlxsw_sp_vport);
1320 dev = mlxsw_sp_vport->dev;
1322 /* Override the physical port with the vPort. */
1323 mlxsw_sp_port = mlxsw_sp_vport;
1325 dev = mlxsw_sp_lag_get(mlxsw_sp, lag_id)->dev;
1329 adding = adding && mlxsw_sp_port->learning;
1332 err = mlxsw_sp_port_fdb_uc_lag_op(mlxsw_sp, lag_id, mac, fid, lag_vid,
1335 if (net_ratelimit())
1336 netdev_err(mlxsw_sp_port->dev, "Failed to set FDB entry\n");
1340 if (!do_notification)
1342 mlxsw_sp_fdb_call_notifiers(mlxsw_sp_port->learning_sync, adding, mac,
1348 do_notification = false;
1352 static void mlxsw_sp_fdb_notify_rec_process(struct mlxsw_sp *mlxsw_sp,
1353 char *sfn_pl, int rec_index)
1355 switch (mlxsw_reg_sfn_rec_type_get(sfn_pl, rec_index)) {
1356 case MLXSW_REG_SFN_REC_TYPE_LEARNED_MAC:
1357 mlxsw_sp_fdb_notify_mac_process(mlxsw_sp, sfn_pl,
1360 case MLXSW_REG_SFN_REC_TYPE_AGED_OUT_MAC:
1361 mlxsw_sp_fdb_notify_mac_process(mlxsw_sp, sfn_pl,
1364 case MLXSW_REG_SFN_REC_TYPE_LEARNED_MAC_LAG:
1365 mlxsw_sp_fdb_notify_mac_lag_process(mlxsw_sp, sfn_pl,
1368 case MLXSW_REG_SFN_REC_TYPE_AGED_OUT_MAC_LAG:
1369 mlxsw_sp_fdb_notify_mac_lag_process(mlxsw_sp, sfn_pl,
1375 static void mlxsw_sp_fdb_notify_work_schedule(struct mlxsw_sp *mlxsw_sp)
1377 schedule_delayed_work(&mlxsw_sp->fdb_notify.dw,
1378 msecs_to_jiffies(mlxsw_sp->fdb_notify.interval));
1381 static void mlxsw_sp_fdb_notify_work(struct work_struct *work)
1383 struct mlxsw_sp *mlxsw_sp;
1389 sfn_pl = kmalloc(MLXSW_REG_SFN_LEN, GFP_KERNEL);
1393 mlxsw_sp = container_of(work, struct mlxsw_sp, fdb_notify.dw.work);
1397 mlxsw_reg_sfn_pack(sfn_pl);
1398 err = mlxsw_reg_query(mlxsw_sp->core, MLXSW_REG(sfn), sfn_pl);
1400 dev_err_ratelimited(mlxsw_sp->bus_info->dev, "Failed to get FDB notifications\n");
1403 num_rec = mlxsw_reg_sfn_num_rec_get(sfn_pl);
1404 for (i = 0; i < num_rec; i++)
1405 mlxsw_sp_fdb_notify_rec_process(mlxsw_sp, sfn_pl, i);
1411 mlxsw_sp_fdb_notify_work_schedule(mlxsw_sp);
1414 static int mlxsw_sp_fdb_init(struct mlxsw_sp *mlxsw_sp)
1418 err = mlxsw_sp_ageing_set(mlxsw_sp, MLXSW_SP_DEFAULT_AGEING_TIME);
1420 dev_err(mlxsw_sp->bus_info->dev, "Failed to set default ageing time\n");
1423 INIT_DELAYED_WORK(&mlxsw_sp->fdb_notify.dw, mlxsw_sp_fdb_notify_work);
1424 mlxsw_sp->fdb_notify.interval = MLXSW_SP_DEFAULT_LEARNING_INTERVAL;
1425 mlxsw_sp_fdb_notify_work_schedule(mlxsw_sp);
1429 static void mlxsw_sp_fdb_fini(struct mlxsw_sp *mlxsw_sp)
1431 cancel_delayed_work_sync(&mlxsw_sp->fdb_notify.dw);
1434 static void mlxsw_sp_fids_fini(struct mlxsw_sp *mlxsw_sp)
1438 for_each_set_bit(fid, mlxsw_sp->active_fids, VLAN_N_VID)
1439 mlxsw_sp_fid_destroy(mlxsw_sp, fid);
1442 int mlxsw_sp_switchdev_init(struct mlxsw_sp *mlxsw_sp)
1444 return mlxsw_sp_fdb_init(mlxsw_sp);
1447 void mlxsw_sp_switchdev_fini(struct mlxsw_sp *mlxsw_sp)
1449 mlxsw_sp_fdb_fini(mlxsw_sp);
1450 mlxsw_sp_fids_fini(mlxsw_sp);
1453 int mlxsw_sp_port_vlan_init(struct mlxsw_sp_port *mlxsw_sp_port)
1455 struct net_device *dev = mlxsw_sp_port->dev;
1458 /* Allow only untagged packets to ingress and tag them internally
1461 mlxsw_sp_port->pvid = 1;
1462 err = __mlxsw_sp_port_vlans_del(mlxsw_sp_port, 0, VLAN_N_VID - 1,
1465 netdev_err(dev, "Unable to init VLANs\n");
1469 /* Add implicit VLAN interface in the device, so that untagged
1470 * packets will be classified to the default vFID.
1472 err = mlxsw_sp_port_add_vid(dev, 0, 1);
1474 netdev_err(dev, "Failed to configure default vFID\n");
1479 void mlxsw_sp_port_switchdev_init(struct mlxsw_sp_port *mlxsw_sp_port)
1481 mlxsw_sp_port->dev->switchdev_ops = &mlxsw_sp_port_switchdev_ops;
1484 void mlxsw_sp_port_switchdev_fini(struct mlxsw_sp_port *mlxsw_sp_port)