@@ -75,21 +75,47 @@ mlx5e_tc_post_act_destroy(struct mlx5e_post_act *post_act)
75
75
kfree (post_act );
76
76
}
77
77
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
+
78
107
struct mlx5e_post_act_handle *
79
108
mlx5e_tc_post_act_add (struct mlx5e_post_act * post_act , struct mlx5_flow_attr * attr )
80
109
{
81
110
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 ;
85
113
int err ;
86
114
87
115
handle = kzalloc (sizeof (* handle ), GFP_KERNEL );
88
- spec = kvzalloc (sizeof (* spec ), GFP_KERNEL );
89
116
post_attr = mlx5_alloc_flow_attr (post_act -> ns_type );
90
- if (!handle || !spec || ! post_attr ) {
117
+ if (!handle || !post_attr ) {
91
118
kfree (post_attr );
92
- kvfree (spec );
93
119
kfree (handle );
94
120
return ERR_PTR (- ENOMEM );
95
121
}
@@ -113,36 +139,35 @@ mlx5e_tc_post_act_add(struct mlx5e_post_act *post_act, struct mlx5_flow_attr *at
113
139
if (err )
114
140
goto err_xarray ;
115
141
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
- }
128
142
handle -> attr = post_attr ;
143
+ err = mlx5e_tc_post_act_offload (post_act , handle );
144
+ if (err )
145
+ goto err_rule ;
146
+
129
147
130
- kvfree (spec );
131
148
return handle ;
132
149
133
150
err_rule :
134
151
xa_erase (& post_act -> ids , handle -> id );
135
152
err_xarray :
136
153
kfree (post_attr );
137
- kvfree (spec );
138
154
kfree (handle );
139
155
return ERR_PTR (err );
140
156
}
141
157
142
158
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 )
144
161
{
145
162
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 );
146
171
xa_erase (& post_act -> ids , handle -> id );
147
172
kfree (handle -> attr );
148
173
kfree (handle );
0 commit comments