Skip to content

Commit d7e75a3

Browse files
ogerlitzSaeed Mahameed
authored andcommitted
net/mlx5e: Add offloading of E-Switch TC pedit (header re-write) actions
This includes calling the parsing code that translates from pedit speak to the HW API, allocation (deallocation) of a modify header context and setting the modify header id associated with this context to the FTE of that flow. Signed-off-by: Or Gerlitz <[email protected]> Reviewed-by: Hadar Hen Zion <[email protected]> Signed-off-by: Saeed Mahameed <[email protected]>
1 parent 2f4fe4c commit d7e75a3

File tree

3 files changed

+39
-4
lines changed

3 files changed

+39
-4
lines changed

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

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ mlx5e_tc_add_nic_flow(struct mlx5e_priv *priv,
9898
.action = attr->action,
9999
.flow_tag = attr->flow_tag,
100100
.encap_id = 0,
101-
.modify_id = attr->mod_hdr_id,
102101
};
103102
struct mlx5_fc *counter = NULL;
104103
struct mlx5_flow_handle *rule;
@@ -122,6 +121,7 @@ mlx5e_tc_add_nic_flow(struct mlx5e_priv *priv,
122121
parse_attr->num_mod_hdr_actions,
123122
parse_attr->mod_hdr_actions,
124123
&attr->mod_hdr_id);
124+
flow_act.modify_id = attr->mod_hdr_id;
125125
kfree(parse_attr->mod_hdr_actions);
126126
if (err) {
127127
rule = ERR_PTR(err);
@@ -208,32 +208,52 @@ mlx5e_tc_add_fdb_flow(struct mlx5e_priv *priv,
208208
goto err_add_vlan;
209209
}
210210

211+
if (attr->action & MLX5_FLOW_CONTEXT_ACTION_MOD_HDR) {
212+
err = mlx5_modify_header_alloc(priv->mdev, MLX5_FLOW_NAMESPACE_FDB,
213+
parse_attr->num_mod_hdr_actions,
214+
parse_attr->mod_hdr_actions,
215+
&attr->mod_hdr_id);
216+
kfree(parse_attr->mod_hdr_actions);
217+
if (err) {
218+
rule = ERR_PTR(err);
219+
goto err_mod_hdr;
220+
}
221+
}
222+
211223
rule = mlx5_eswitch_add_offloaded_rule(esw, &parse_attr->spec, attr);
212224
if (IS_ERR(rule))
213225
goto err_add_rule;
214226

215227
return rule;
216228

217229
err_add_rule:
230+
if (flow->esw_attr->action & MLX5_FLOW_CONTEXT_ACTION_MOD_HDR)
231+
mlx5_modify_header_dealloc(priv->mdev,
232+
attr->mod_hdr_id);
233+
err_mod_hdr:
218234
mlx5_eswitch_del_vlan_action(esw, attr);
219235
err_add_vlan:
220236
if (attr->action & MLX5_FLOW_CONTEXT_ACTION_ENCAP)
221237
mlx5e_detach_encap(priv, flow);
222-
223238
return rule;
224239
}
225240

226241
static void mlx5e_tc_del_fdb_flow(struct mlx5e_priv *priv,
227242
struct mlx5e_tc_flow *flow)
228243
{
229244
struct mlx5_eswitch *esw = priv->mdev->priv.eswitch;
245+
struct mlx5_esw_flow_attr *attr = flow->esw_attr;
230246

231247
mlx5_eswitch_del_offloaded_rule(esw, flow->rule, flow->esw_attr);
232248

233249
mlx5_eswitch_del_vlan_action(esw, flow->esw_attr);
234250

235251
if (flow->esw_attr->action & MLX5_FLOW_CONTEXT_ACTION_ENCAP)
236252
mlx5e_detach_encap(priv, flow);
253+
254+
if (flow->esw_attr->action & MLX5_FLOW_CONTEXT_ACTION_MOD_HDR)
255+
mlx5_modify_header_dealloc(priv->mdev,
256+
attr->mod_hdr_id);
237257
}
238258

239259
static void mlx5e_detach_encap(struct mlx5e_priv *priv,
@@ -1406,6 +1426,7 @@ static int mlx5e_attach_encap(struct mlx5e_priv *priv,
14061426
}
14071427

14081428
static int parse_tc_fdb_actions(struct mlx5e_priv *priv, struct tcf_exts *exts,
1429+
struct mlx5e_tc_flow_parse_attr *parse_attr,
14091430
struct mlx5e_tc_flow *flow)
14101431
{
14111432
struct mlx5_esw_flow_attr *attr = flow->esw_attr;
@@ -1429,6 +1450,16 @@ static int parse_tc_fdb_actions(struct mlx5e_priv *priv, struct tcf_exts *exts,
14291450
continue;
14301451
}
14311452

1453+
if (is_tcf_pedit(a)) {
1454+
err = parse_tc_pedit_action(priv, a, MLX5_FLOW_NAMESPACE_FDB,
1455+
parse_attr);
1456+
if (err)
1457+
return err;
1458+
1459+
attr->action |= MLX5_FLOW_CONTEXT_ACTION_MOD_HDR;
1460+
continue;
1461+
}
1462+
14321463
if (is_tcf_mirred_egress_redirect(a)) {
14331464
int ifindex = tcf_mirred_ifindex(a);
14341465
struct net_device *out_dev;
@@ -1528,7 +1559,7 @@ int mlx5e_configure_flower(struct mlx5e_priv *priv, __be16 protocol,
15281559
goto err_free;
15291560

15301561
if (flow->flags & MLX5E_TC_FLOW_ESWITCH) {
1531-
err = parse_tc_fdb_actions(priv, f->exts, flow);
1562+
err = parse_tc_fdb_actions(priv, f->exts, parse_attr, flow);
15321563
if (err < 0)
15331564
goto err_free;
15341565
flow->rule = mlx5e_tc_add_fdb_flow(priv, parse_attr, flow);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ struct mlx5_esw_flow_attr {
308308
u16 vlan;
309309
bool vlan_handled;
310310
struct mlx5_encap_entry *encap;
311+
u32 mod_hdr_id;
311312
};
312313

313314
int mlx5_eswitch_sqs2vport_start(struct mlx5_eswitch *esw,

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,10 @@ mlx5_eswitch_add_offloaded_rule(struct mlx5_eswitch *esw,
8888
if (flow_act.action & MLX5_FLOW_CONTEXT_ACTION_DECAP)
8989
spec->match_criteria_enable |= MLX5_MATCH_INNER_HEADERS;
9090

91-
if (attr->encap)
91+
if (attr->action & MLX5_FLOW_CONTEXT_ACTION_MOD_HDR)
92+
flow_act.modify_id = attr->mod_hdr_id;
93+
94+
if (attr->action & MLX5_FLOW_CONTEXT_ACTION_ENCAP)
9295
flow_act.encap_id = attr->encap->encap_id;
9396

9497
rule = mlx5_add_flow_rules((struct mlx5_flow_table *)esw->fdb_table.fdb,

0 commit comments

Comments
 (0)