Skip to content

Commit 2f4fe4c

Browse files
ogerlitzSaeed Mahameed
authored andcommitted
net/mlx5e: Add offloading of NIC 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 d79b6df commit 2f4fe4c

File tree

1 file changed

+35
-0
lines changed
  • drivers/net/ethernet/mellanox/mlx5/core

1 file changed

+35
-0
lines changed

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
struct mlx5_nic_flow_attr {
5353
u32 action;
5454
u32 flow_tag;
55+
u32 mod_hdr_id;
5556
};
5657

5758
enum {
@@ -97,10 +98,12 @@ mlx5e_tc_add_nic_flow(struct mlx5e_priv *priv,
9798
.action = attr->action,
9899
.flow_tag = attr->flow_tag,
99100
.encap_id = 0,
101+
.modify_id = attr->mod_hdr_id,
100102
};
101103
struct mlx5_fc *counter = NULL;
102104
struct mlx5_flow_handle *rule;
103105
bool table_created = false;
106+
int err;
104107

105108
if (attr->action & MLX5_FLOW_CONTEXT_ACTION_FWD_DEST) {
106109
dest.type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE;
@@ -114,6 +117,18 @@ mlx5e_tc_add_nic_flow(struct mlx5e_priv *priv,
114117
dest.counter = counter;
115118
}
116119

120+
if (attr->action & MLX5_FLOW_CONTEXT_ACTION_MOD_HDR) {
121+
err = mlx5_modify_header_alloc(dev, MLX5_FLOW_NAMESPACE_KERNEL,
122+
parse_attr->num_mod_hdr_actions,
123+
parse_attr->mod_hdr_actions,
124+
&attr->mod_hdr_id);
125+
kfree(parse_attr->mod_hdr_actions);
126+
if (err) {
127+
rule = ERR_PTR(err);
128+
goto err_create_mod_hdr_id;
129+
}
130+
}
131+
117132
if (IS_ERR_OR_NULL(priv->fs.tc.t)) {
118133
priv->fs.tc.t =
119134
mlx5_create_auto_grouped_flow_table(priv->fs.ns,
@@ -146,6 +161,10 @@ mlx5e_tc_add_nic_flow(struct mlx5e_priv *priv,
146161
priv->fs.tc.t = NULL;
147162
}
148163
err_create_ft:
164+
if (attr->action & MLX5_FLOW_CONTEXT_ACTION_MOD_HDR)
165+
mlx5_modify_header_dealloc(priv->mdev,
166+
attr->mod_hdr_id);
167+
err_create_mod_hdr_id:
149168
mlx5_fc_destroy(dev, counter);
150169

151170
return rule;
@@ -164,6 +183,10 @@ static void mlx5e_tc_del_nic_flow(struct mlx5e_priv *priv,
164183
mlx5_destroy_flow_table(priv->fs.tc.t);
165184
priv->fs.tc.t = NULL;
166185
}
186+
187+
if (flow->nic_attr->action & MLX5_FLOW_CONTEXT_ACTION_MOD_HDR)
188+
mlx5_modify_header_dealloc(priv->mdev,
189+
flow->nic_attr->mod_hdr_id);
167190
}
168191

169192
static void mlx5e_detach_encap(struct mlx5e_priv *priv,
@@ -955,6 +978,7 @@ static int parse_tc_nic_actions(struct mlx5e_priv *priv, struct tcf_exts *exts,
955978
struct mlx5_nic_flow_attr *attr = flow->nic_attr;
956979
const struct tc_action *a;
957980
LIST_HEAD(actions);
981+
int err;
958982

959983
if (tc_no_actions(exts))
960984
return -EINVAL;
@@ -976,6 +1000,17 @@ static int parse_tc_nic_actions(struct mlx5e_priv *priv, struct tcf_exts *exts,
9761000
continue;
9771001
}
9781002

1003+
if (is_tcf_pedit(a)) {
1004+
err = parse_tc_pedit_action(priv, a, MLX5_FLOW_NAMESPACE_KERNEL,
1005+
parse_attr);
1006+
if (err)
1007+
return err;
1008+
1009+
attr->action |= MLX5_FLOW_CONTEXT_ACTION_MOD_HDR |
1010+
MLX5_FLOW_CONTEXT_ACTION_FWD_DEST;
1011+
continue;
1012+
}
1013+
9791014
if (is_tcf_skbedit_mark(a)) {
9801015
u32 mark = tcf_skbedit_mark(a);
9811016

0 commit comments

Comments
 (0)