Skip to content

Commit 6e095fd

Browse files
idoschdavem330
authored andcommitted
mlxsw: spectrum: Edit RIF properties based on netdev events
We are just about to introduce router interfaces (RIFs), but before that we need to be able update the device with the correct RIF attributes whenever they change for the netdev the RIF is backing. Two such attributes are MTU and MAC. The MAC is used both to set the source MAC of packets egressing from the RIF and also to program an FDB rule that will direct packets to the router block. Use the existing netdevice notification block and respond to CHANGEADDR and CHANGEMTU accordingly. Store both attributes in the RIF struct in case we need to revert to old attributes following a failed update. Signed-off-by: Ido Schimmel <[email protected]> Signed-off-by: Jiri Pirko <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 7ce856a commit 6e095fd

File tree

3 files changed

+86
-6
lines changed

3 files changed

+86
-6
lines changed

drivers/net/ethernet/mellanox/mlxsw/spectrum.c

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2627,6 +2627,63 @@ void mlxsw_sp_port_dev_put(struct mlxsw_sp_port *mlxsw_sp_port)
26272627
dev_put(mlxsw_sp_port->dev);
26282628
}
26292629

2630+
static int mlxsw_sp_rif_edit(struct mlxsw_sp *mlxsw_sp, u16 rif,
2631+
const char *mac, int mtu)
2632+
{
2633+
char ritr_pl[MLXSW_REG_RITR_LEN];
2634+
int err;
2635+
2636+
mlxsw_reg_ritr_rif_pack(ritr_pl, rif);
2637+
err = mlxsw_reg_query(mlxsw_sp->core, MLXSW_REG(ritr), ritr_pl);
2638+
if (err)
2639+
return err;
2640+
2641+
mlxsw_reg_ritr_mtu_set(ritr_pl, mtu);
2642+
mlxsw_reg_ritr_if_mac_memcpy_to(ritr_pl, mac);
2643+
mlxsw_reg_ritr_op_set(ritr_pl, MLXSW_REG_RITR_RIF_CREATE);
2644+
return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(ritr), ritr_pl);
2645+
}
2646+
2647+
static int mlxsw_sp_netdevice_router_port_event(struct net_device *dev)
2648+
{
2649+
struct mlxsw_sp *mlxsw_sp;
2650+
struct mlxsw_sp_rif *r;
2651+
int err;
2652+
2653+
mlxsw_sp = mlxsw_sp_lower_get(dev);
2654+
if (!mlxsw_sp)
2655+
return 0;
2656+
2657+
r = mlxsw_sp_rif_find_by_dev(mlxsw_sp, dev);
2658+
if (!r)
2659+
return 0;
2660+
2661+
err = mlxsw_sp_rif_fdb_op(mlxsw_sp, r->addr, r->f->fid, false);
2662+
if (err)
2663+
return err;
2664+
2665+
err = mlxsw_sp_rif_edit(mlxsw_sp, r->rif, dev->dev_addr, dev->mtu);
2666+
if (err)
2667+
goto err_rif_edit;
2668+
2669+
err = mlxsw_sp_rif_fdb_op(mlxsw_sp, dev->dev_addr, r->f->fid, true);
2670+
if (err)
2671+
goto err_rif_fdb_op;
2672+
2673+
ether_addr_copy(r->addr, dev->dev_addr);
2674+
r->mtu = dev->mtu;
2675+
2676+
netdev_dbg(dev, "Updated RIF=%d\n", r->rif);
2677+
2678+
return 0;
2679+
2680+
err_rif_fdb_op:
2681+
mlxsw_sp_rif_edit(mlxsw_sp, r->rif, r->addr, r->mtu);
2682+
err_rif_edit:
2683+
mlxsw_sp_rif_fdb_op(mlxsw_sp, r->addr, r->f->fid, true);
2684+
return err;
2685+
}
2686+
26302687
static bool mlxsw_sp_lag_port_fid_member(struct mlxsw_sp_port *lag_port,
26312688
u16 fid)
26322689
{
@@ -3487,7 +3544,9 @@ static int mlxsw_sp_netdevice_event(struct notifier_block *unused,
34873544
struct net_device *dev = netdev_notifier_info_to_dev(ptr);
34883545
int err = 0;
34893546

3490-
if (mlxsw_sp_port_dev_check(dev))
3547+
if (event == NETDEV_CHANGEADDR || event == NETDEV_CHANGEMTU)
3548+
err = mlxsw_sp_netdevice_router_port_event(dev);
3549+
else if (mlxsw_sp_port_dev_check(dev))
34913550
err = mlxsw_sp_netdevice_port_event(dev, event, ptr);
34923551
else if (netif_is_lag_master(dev))
34933552
err = mlxsw_sp_netdevice_lag_event(dev, event, ptr);

drivers/net/ethernet/mellanox/mlxsw/spectrum.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ struct mlxsw_sp_fid {
107107

108108
struct mlxsw_sp_rif {
109109
struct net_device *dev;
110+
struct mlxsw_sp_fid *f;
111+
unsigned char addr[ETH_ALEN];
112+
int mtu;
110113
u16 rif;
111114
};
112115

@@ -448,6 +451,8 @@ int mlxsw_sp_vport_flood_set(struct mlxsw_sp_port *mlxsw_sp_vport, u16 fid,
448451
void mlxsw_sp_port_active_vlans_del(struct mlxsw_sp_port *mlxsw_sp_port);
449452
int mlxsw_sp_port_pvid_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid);
450453
int mlxsw_sp_port_fdb_flush(struct mlxsw_sp_port *mlxsw_sp_port, u16 fid);
454+
int mlxsw_sp_rif_fdb_op(struct mlxsw_sp *mlxsw_sp, const char *mac, u16 fid,
455+
bool adding);
451456
int mlxsw_sp_port_ets_set(struct mlxsw_sp_port *mlxsw_sp_port,
452457
enum mlxsw_reg_qeec_hr hr, u8 index, u8 next_index,
453458
bool dwrr, u8 dwrr_weight);

drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -753,9 +753,10 @@ static enum mlxsw_reg_sfd_op mlxsw_sp_sfd_op(bool adding)
753753
MLXSW_REG_SFD_OP_WRITE_REMOVE;
754754
}
755755

756-
static int mlxsw_sp_port_fdb_uc_op(struct mlxsw_sp *mlxsw_sp, u8 local_port,
757-
const char *mac, u16 fid, bool adding,
758-
bool dynamic)
756+
static int __mlxsw_sp_port_fdb_uc_op(struct mlxsw_sp *mlxsw_sp, u8 local_port,
757+
const char *mac, u16 fid, bool adding,
758+
enum mlxsw_reg_sfd_rec_action action,
759+
bool dynamic)
759760
{
760761
char *sfd_pl;
761762
int err;
@@ -766,14 +767,29 @@ static int mlxsw_sp_port_fdb_uc_op(struct mlxsw_sp *mlxsw_sp, u8 local_port,
766767

767768
mlxsw_reg_sfd_pack(sfd_pl, mlxsw_sp_sfd_op(adding), 0);
768769
mlxsw_reg_sfd_uc_pack(sfd_pl, 0, mlxsw_sp_sfd_rec_policy(dynamic),
769-
mac, fid, MLXSW_REG_SFD_REC_ACTION_NOP,
770-
local_port);
770+
mac, fid, action, local_port);
771771
err = mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(sfd), sfd_pl);
772772
kfree(sfd_pl);
773773

774774
return err;
775775
}
776776

777+
static int mlxsw_sp_port_fdb_uc_op(struct mlxsw_sp *mlxsw_sp, u8 local_port,
778+
const char *mac, u16 fid, bool adding,
779+
bool dynamic)
780+
{
781+
return __mlxsw_sp_port_fdb_uc_op(mlxsw_sp, local_port, mac, fid, adding,
782+
MLXSW_REG_SFD_REC_ACTION_NOP, dynamic);
783+
}
784+
785+
int mlxsw_sp_rif_fdb_op(struct mlxsw_sp *mlxsw_sp, const char *mac, u16 fid,
786+
bool adding)
787+
{
788+
return __mlxsw_sp_port_fdb_uc_op(mlxsw_sp, 0, mac, fid, adding,
789+
MLXSW_REG_SFD_REC_ACTION_FORWARD_IP_ROUTER,
790+
false);
791+
}
792+
777793
static int mlxsw_sp_port_fdb_uc_lag_op(struct mlxsw_sp *mlxsw_sp, u16 lag_id,
778794
const char *mac, u16 fid, u16 lag_vid,
779795
bool adding, bool dynamic)

0 commit comments

Comments
 (0)