Skip to content

Commit 314e110

Browse files
roidayanSaeed Mahameed
authored andcommitted
net/mlx5e: Add post act offload/unoffload API
Introduce mlx5e_tc_post_act_offload() and mlx5e_tc_post_act_unoffload() to be able to unoffload and reoffload existing post action rules handles. For example in neigh update events, the driver removes and readds rules in hardware. Signed-off-by: Roi Dayan <[email protected]> Signed-off-by: Saeed Mahameed <[email protected]>
1 parent 0610f8d commit 314e110

File tree

2 files changed

+54
-21
lines changed

2 files changed

+54
-21
lines changed

drivers/net/ethernet/mellanox/mlx5/core/en/tc/post_act.c

Lines changed: 46 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -75,21 +75,47 @@ mlx5e_tc_post_act_destroy(struct mlx5e_post_act *post_act)
7575
kfree(post_act);
7676
}
7777

78+
int
79+
mlx5e_tc_post_act_offload(struct mlx5e_post_act *post_act,
80+
struct mlx5e_post_act_handle *handle)
81+
{
82+
struct mlx5_flow_spec *spec;
83+
int err;
84+
85+
spec = kvzalloc(sizeof(*spec), GFP_KERNEL);
86+
if (!spec)
87+
return -ENOMEM;
88+
89+
/* Post action rule matches on fte_id and executes original rule's tc rule action */
90+
mlx5e_tc_match_to_reg_match(spec, FTEID_TO_REG, handle->id, MLX5_POST_ACTION_MASK);
91+
92+
handle->rule = mlx5_tc_rule_insert(post_act->priv, spec, handle->attr);
93+
if (IS_ERR(handle->rule)) {
94+
err = PTR_ERR(handle->rule);
95+
netdev_warn(post_act->priv->netdev, "Failed to add post action rule");
96+
goto err_rule;
97+
}
98+
99+
kvfree(spec);
100+
return 0;
101+
102+
err_rule:
103+
kvfree(spec);
104+
return err;
105+
}
106+
78107
struct mlx5e_post_act_handle *
79108
mlx5e_tc_post_act_add(struct mlx5e_post_act *post_act, struct mlx5_flow_attr *attr)
80109
{
81110
u32 attr_sz = ns_to_attr_sz(post_act->ns_type);
82-
struct mlx5e_post_act_handle *handle = NULL;
83-
struct mlx5_flow_attr *post_attr = NULL;
84-
struct mlx5_flow_spec *spec = NULL;
111+
struct mlx5e_post_act_handle *handle;
112+
struct mlx5_flow_attr *post_attr;
85113
int err;
86114

87115
handle = kzalloc(sizeof(*handle), GFP_KERNEL);
88-
spec = kvzalloc(sizeof(*spec), GFP_KERNEL);
89116
post_attr = mlx5_alloc_flow_attr(post_act->ns_type);
90-
if (!handle || !spec || !post_attr) {
117+
if (!handle || !post_attr) {
91118
kfree(post_attr);
92-
kvfree(spec);
93119
kfree(handle);
94120
return ERR_PTR(-ENOMEM);
95121
}
@@ -113,36 +139,35 @@ mlx5e_tc_post_act_add(struct mlx5e_post_act *post_act, struct mlx5_flow_attr *at
113139
if (err)
114140
goto err_xarray;
115141

116-
/* Post action rule matches on fte_id and executes original rule's
117-
* tc rule action
118-
*/
119-
mlx5e_tc_match_to_reg_match(spec, FTEID_TO_REG,
120-
handle->id, MLX5_POST_ACTION_MASK);
121-
122-
handle->rule = mlx5_tc_rule_insert(post_act->priv, spec, post_attr);
123-
if (IS_ERR(handle->rule)) {
124-
err = PTR_ERR(handle->rule);
125-
netdev_warn(post_act->priv->netdev, "Failed to add post action rule");
126-
goto err_rule;
127-
}
128142
handle->attr = post_attr;
143+
err = mlx5e_tc_post_act_offload(post_act, handle);
144+
if (err)
145+
goto err_rule;
146+
129147

130-
kvfree(spec);
131148
return handle;
132149

133150
err_rule:
134151
xa_erase(&post_act->ids, handle->id);
135152
err_xarray:
136153
kfree(post_attr);
137-
kvfree(spec);
138154
kfree(handle);
139155
return ERR_PTR(err);
140156
}
141157

142158
void
143-
mlx5e_tc_post_act_del(struct mlx5e_post_act *post_act, struct mlx5e_post_act_handle *handle)
159+
mlx5e_tc_post_act_unoffload(struct mlx5e_post_act *post_act,
160+
struct mlx5e_post_act_handle *handle)
144161
{
145162
mlx5_tc_rule_delete(post_act->priv, handle->rule, handle->attr);
163+
handle->rule = NULL;
164+
}
165+
166+
void
167+
mlx5e_tc_post_act_del(struct mlx5e_post_act *post_act, struct mlx5e_post_act_handle *handle)
168+
{
169+
if (!IS_ERR_OR_NULL(handle->rule))
170+
mlx5e_tc_post_act_unoffload(post_act, handle);
146171
xa_erase(&post_act->ids, handle->id);
147172
kfree(handle->attr);
148173
kfree(handle);

drivers/net/ethernet/mellanox/mlx5/core/en/tc/post_act.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ mlx5e_tc_post_act_add(struct mlx5e_post_act *post_act, struct mlx5_flow_attr *at
2424
void
2525
mlx5e_tc_post_act_del(struct mlx5e_post_act *post_act, struct mlx5e_post_act_handle *handle);
2626

27+
int
28+
mlx5e_tc_post_act_offload(struct mlx5e_post_act *post_act,
29+
struct mlx5e_post_act_handle *handle);
30+
31+
void
32+
mlx5e_tc_post_act_unoffload(struct mlx5e_post_act *post_act,
33+
struct mlx5e_post_act_handle *handle);
34+
2735
struct mlx5_flow_table *
2836
mlx5e_tc_post_act_get_ft(struct mlx5e_post_act *post_act);
2937

0 commit comments

Comments
 (0)