Skip to content

Commit

Permalink
net/mlx5: Lag, add support to create/destroy/modify port selection
Browse files Browse the repository at this point in the history
Add create function, build the steering tables, TTC and definers
according to the LAG hash type.

The destroy function, destroys all the steering components.

The modify functions is used when the bond mapping changes and it
iterates over all the rules in the definers and modifies them to steer
the packet to the relevant active ports.

Signed-off-by: Maor Gottlieb <[email protected]>
Reviewed-by: Mark Bloch <[email protected]>
Signed-off-by: Saeed Mahameed <[email protected]>
  • Loading branch information
maorgottlieb authored and Saeed Mahameed committed Oct 19, 2021
1 parent 8e25a2b commit b726786
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 1 deletion.
2 changes: 1 addition & 1 deletion drivers/net/ethernet/mellanox/mlx5/core/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ mlx5_core-$(CONFIG_MLX5_EN_ARFS) += en_arfs.o
mlx5_core-$(CONFIG_MLX5_EN_RXNFC) += en_fs_ethtool.o
mlx5_core-$(CONFIG_MLX5_CORE_EN_DCB) += en_dcbnl.o en/port_buffer.o
mlx5_core-$(CONFIG_PCI_HYPERV_INTERFACE) += en/hv_vhca_stats.o
mlx5_core-$(CONFIG_MLX5_ESWITCH) += lag/mp.o lib/geneve.o lib/port_tun.o \
mlx5_core-$(CONFIG_MLX5_ESWITCH) += lag/mp.o lag/port_sel.o lib/geneve.o lib/port_tun.o \
en_rep.o en/rep/bond.o en/mod_hdr.o \
en/mapping.o
mlx5_core-$(CONFIG_MLX5_CLS_ACT) += en_tc.o en/rep/tc.o en/rep/neigh.o \
Expand Down
98 changes: 98 additions & 0 deletions drivers/net/ethernet/mellanox/mlx5/core/lag/port_sel.c
Original file line number Diff line number Diff line change
Expand Up @@ -511,3 +511,101 @@ static int mlx5_lag_create_inner_ttc_table(struct mlx5_lag *ldev)

return 0;
}

int mlx5_lag_port_sel_create(struct mlx5_lag *ldev,
enum netdev_lag_hash hash_type, u8 port1, u8 port2)
{
struct mlx5_lag_port_sel *port_sel = &ldev->port_sel;
int err;

set_tt_map(port_sel, hash_type);
err = mlx5_lag_create_definers(ldev, hash_type, port1, port2);
if (err)
return err;

if (port_sel->tunnel) {
err = mlx5_lag_create_inner_ttc_table(ldev);
if (err)
goto destroy_definers;
}

err = mlx5_lag_create_ttc_table(ldev);
if (err)
goto destroy_inner;

return 0;

destroy_inner:
if (port_sel->tunnel)
mlx5_destroy_ttc_table(port_sel->inner.ttc);
destroy_definers:
mlx5_lag_destroy_definers(ldev);
return err;
}

static int
mlx5_lag_modify_definers_destinations(struct mlx5_lag *ldev,
struct mlx5_lag_definer **definers,
u8 port1, u8 port2)
{
struct mlx5_lag_port_sel *port_sel = &ldev->port_sel;
struct mlx5_flow_destination dest = {};
int err;
int tt;

dest.type = MLX5_FLOW_DESTINATION_TYPE_UPLINK;
dest.vport.flags |= MLX5_FLOW_DEST_VPORT_VHCA_ID;

for_each_set_bit(tt, port_sel->tt_map, MLX5_NUM_TT) {
struct mlx5_flow_handle **rules = definers[tt]->rules;

if (ldev->v2p_map[MLX5_LAG_P1] != port1) {
dest.vport.vhca_id =
MLX5_CAP_GEN(ldev->pf[port1 - 1].dev, vhca_id);
err = mlx5_modify_rule_destination(rules[MLX5_LAG_P1],
&dest, NULL);
if (err)
return err;
}

if (ldev->v2p_map[MLX5_LAG_P2] != port2) {
dest.vport.vhca_id =
MLX5_CAP_GEN(ldev->pf[port2 - 1].dev, vhca_id);
err = mlx5_modify_rule_destination(rules[MLX5_LAG_P2],
&dest, NULL);
if (err)
return err;
}
}

return 0;
}

int mlx5_lag_port_sel_modify(struct mlx5_lag *ldev, u8 port1, u8 port2)
{
struct mlx5_lag_port_sel *port_sel = &ldev->port_sel;
int err;

err = mlx5_lag_modify_definers_destinations(ldev,
port_sel->outer.definers,
port1, port2);
if (err)
return err;

if (!port_sel->tunnel)
return 0;

return mlx5_lag_modify_definers_destinations(ldev,
port_sel->inner.definers,
port1, port2);
}

void mlx5_lag_port_sel_destroy(struct mlx5_lag *ldev)
{
struct mlx5_lag_port_sel *port_sel = &ldev->port_sel;

mlx5_destroy_ttc_table(port_sel->outer.ttc);
if (port_sel->tunnel)
mlx5_destroy_ttc_table(port_sel->inner.ttc);
mlx5_lag_destroy_definers(ldev);
}
24 changes: 24 additions & 0 deletions drivers/net/ethernet/mellanox/mlx5/core/lag/port_sel.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,28 @@ struct mlx5_lag_port_sel {
struct mlx5_lag_ttc inner;
};

#ifdef CONFIG_MLX5_ESWITCH

int mlx5_lag_port_sel_modify(struct mlx5_lag *ldev, u8 port1, u8 port2);
void mlx5_lag_port_sel_destroy(struct mlx5_lag *ldev);
int mlx5_lag_port_sel_create(struct mlx5_lag *ldev,
enum netdev_lag_hash hash_type, u8 port1,
u8 port2);

#else /* CONFIG_MLX5_ESWITCH */
static inline int mlx5_lag_port_sel_create(struct mlx5_lag *ldev,
enum netdev_lag_hash hash_type,
u8 port1, u8 port2)
{
return 0;
}

static inline int mlx5_lag_port_sel_modify(struct mlx5_lag *ldev, u8 port1,
u8 port2)
{
return 0;
}

static inline void mlx5_lag_port_sel_destroy(struct mlx5_lag *ldev) {}
#endif /* CONFIG_MLX5_ESWITCH */
#endif /* __MLX5_LAG_FS_H__ */

0 comments on commit b726786

Please sign in to comment.