Skip to content

Commit fed9ce2

Browse files
ogerlitzdavem330
authored andcommitted
net/mlx5: E-Switch, Add API to create vport rx rules
Add the API to create vport rx rules of the form packet meta-data :: vport == $VPORT --> $TIR where the TIR is opened by this VF representor. This logic will by used for packets that didn't match any rule in the e-switch datapath and should be received into the host OS through the netdevice that represents the VF they were sent from. Signed-off-by: Or Gerlitz <[email protected]> Signed-off-by: Saeed Mahameed <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent c116c6e commit fed9ce2

File tree

2 files changed

+89
-0
lines changed

2 files changed

+89
-0
lines changed

drivers/net/ethernet/mellanox/mlx5/core/eswitch.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ enum {
157157

158158
struct mlx5_esw_offload {
159159
struct mlx5_flow_table *ft_offloads;
160+
struct mlx5_flow_group *vport_rx_group;
160161
};
161162

162163
struct mlx5_eswitch {
@@ -201,6 +202,9 @@ int mlx5_eswitch_get_vport_stats(struct mlx5_eswitch *esw,
201202
struct mlx5_flow_rule *
202203
mlx5_eswitch_add_send_to_vport_rule(struct mlx5_eswitch *esw, int vport, u32 sqn);
203204

205+
struct mlx5_flow_rule *
206+
mlx5_eswitch_create_vport_rx_rule(struct mlx5_eswitch *esw, int vport, u32 tirn);
207+
204208
#define MLX5_DEBUG_ESWITCH_MASK BIT(3)
205209

206210
#define esw_info(dev, format, ...) \

drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,3 +243,88 @@ static void esw_destroy_offloads_table(struct mlx5_eswitch *esw)
243243

244244
mlx5_destroy_flow_table(offloads->ft_offloads);
245245
}
246+
247+
static int esw_create_vport_rx_group(struct mlx5_eswitch *esw)
248+
{
249+
int inlen = MLX5_ST_SZ_BYTES(create_flow_group_in);
250+
struct mlx5_flow_group *g;
251+
struct mlx5_priv *priv = &esw->dev->priv;
252+
u32 *flow_group_in;
253+
void *match_criteria, *misc;
254+
int err = 0;
255+
int nvports = priv->sriov.num_vfs + 2;
256+
257+
flow_group_in = mlx5_vzalloc(inlen);
258+
if (!flow_group_in)
259+
return -ENOMEM;
260+
261+
/* create vport rx group */
262+
memset(flow_group_in, 0, inlen);
263+
MLX5_SET(create_flow_group_in, flow_group_in, match_criteria_enable,
264+
MLX5_MATCH_MISC_PARAMETERS);
265+
266+
match_criteria = MLX5_ADDR_OF(create_flow_group_in, flow_group_in, match_criteria);
267+
misc = MLX5_ADDR_OF(fte_match_param, match_criteria, misc_parameters);
268+
MLX5_SET_TO_ONES(fte_match_set_misc, misc, source_port);
269+
270+
MLX5_SET(create_flow_group_in, flow_group_in, start_flow_index, 0);
271+
MLX5_SET(create_flow_group_in, flow_group_in, end_flow_index, nvports - 1);
272+
273+
g = mlx5_create_flow_group(esw->offloads.ft_offloads, flow_group_in);
274+
275+
if (IS_ERR(g)) {
276+
err = PTR_ERR(g);
277+
mlx5_core_warn(esw->dev, "Failed to create vport rx group err %d\n", err);
278+
goto out;
279+
}
280+
281+
esw->offloads.vport_rx_group = g;
282+
out:
283+
kfree(flow_group_in);
284+
return err;
285+
}
286+
287+
static void esw_destroy_vport_rx_group(struct mlx5_eswitch *esw)
288+
{
289+
mlx5_destroy_flow_group(esw->offloads.vport_rx_group);
290+
}
291+
292+
struct mlx5_flow_rule *
293+
mlx5_eswitch_create_vport_rx_rule(struct mlx5_eswitch *esw, int vport, u32 tirn)
294+
{
295+
struct mlx5_flow_destination dest;
296+
struct mlx5_flow_rule *flow_rule;
297+
int match_header = MLX5_MATCH_MISC_PARAMETERS;
298+
u32 *match_v, *match_c;
299+
void *misc;
300+
301+
match_v = kzalloc(MLX5_ST_SZ_BYTES(fte_match_param), GFP_KERNEL);
302+
match_c = kzalloc(MLX5_ST_SZ_BYTES(fte_match_param), GFP_KERNEL);
303+
if (!match_v || !match_c) {
304+
esw_warn(esw->dev, "Failed to alloc match parameters\n");
305+
flow_rule = ERR_PTR(-ENOMEM);
306+
goto out;
307+
}
308+
309+
misc = MLX5_ADDR_OF(fte_match_param, match_v, misc_parameters);
310+
MLX5_SET(fte_match_set_misc, misc, source_port, vport);
311+
312+
misc = MLX5_ADDR_OF(fte_match_param, match_c, misc_parameters);
313+
MLX5_SET_TO_ONES(fte_match_set_misc, misc, source_port);
314+
315+
dest.type = MLX5_FLOW_DESTINATION_TYPE_TIR;
316+
dest.tir_num = tirn;
317+
318+
flow_rule = mlx5_add_flow_rule(esw->offloads.ft_offloads, match_header, match_c,
319+
match_v, MLX5_FLOW_CONTEXT_ACTION_FWD_DEST,
320+
0, &dest);
321+
if (IS_ERR(flow_rule)) {
322+
esw_warn(esw->dev, "fs offloads: Failed to add vport rx rule err %ld\n", PTR_ERR(flow_rule));
323+
goto out;
324+
}
325+
326+
out:
327+
kfree(match_v);
328+
kfree(match_c);
329+
return flow_rule;
330+
}

0 commit comments

Comments
 (0)