Commit | Line | Data |
---|---|---|
e8f887ac AV |
1 | /* |
2 | * Copyright (c) 2016, Mellanox Technologies. All rights reserved. | |
3 | * | |
4 | * This software is available to you under a choice of one of two | |
5 | * licenses. You may choose to be licensed under the terms of the GNU | |
6 | * General Public License (GPL) Version 2, available from the file | |
7 | * COPYING in the main directory of this source tree, or the | |
8 | * OpenIB.org BSD license below: | |
9 | * | |
10 | * Redistribution and use in source and binary forms, with or | |
11 | * without modification, are permitted provided that the following | |
12 | * conditions are met: | |
13 | * | |
14 | * - Redistributions of source code must retain the above | |
15 | * copyright notice, this list of conditions and the following | |
16 | * disclaimer. | |
17 | * | |
18 | * - Redistributions in binary form must reproduce the above | |
19 | * copyright notice, this list of conditions and the following | |
20 | * disclaimer in the documentation and/or other materials | |
21 | * provided with the distribution. | |
22 | * | |
23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
24 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
25 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |
26 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | |
27 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | |
28 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | |
29 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
30 | * SOFTWARE. | |
31 | */ | |
32 | ||
e3a2b7ed | 33 | #include <net/flow_dissector.h> |
e2394a61 | 34 | #include <net/flow_offload.h> |
3f7d0eb4 | 35 | #include <net/sch_generic.h> |
e3a2b7ed | 36 | #include <net/pkt_cls.h> |
e8f887ac AV |
37 | #include <linux/mlx5/fs.h> |
38 | #include <linux/mlx5/device.h> | |
39 | #include <linux/rhashtable.h> | |
5a7e5bcb | 40 | #include <linux/refcount.h> |
db76ca24 | 41 | #include <linux/completion.h> |
d79b6df6 | 42 | #include <net/tc_act/tc_pedit.h> |
26c02749 | 43 | #include <net/tc_act/tc_csum.h> |
41c2fd94 | 44 | #include <net/psample.h> |
f6dfb4c3 | 45 | #include <net/arp.h> |
3616d08b | 46 | #include <net/ipv6_stubs.h> |
f828ca6a | 47 | #include <net/bareudp.h> |
d34eb2fc | 48 | #include <net/bonding.h> |
e8f887ac | 49 | #include "en.h" |
f0da4daa | 50 | #include "en/tc/post_act.h" |
1d447a39 | 51 | #include "en_rep.h" |
768c3667 | 52 | #include "en/rep/tc.h" |
e2394a61 | 53 | #include "en/rep/neigh.h" |
232c0013 | 54 | #include "en_tc.h" |
03a9d11e | 55 | #include "eswitch.h" |
3f6d08d1 | 56 | #include "fs_core.h" |
2c81bfd5 | 57 | #include "en/port.h" |
101f4de9 | 58 | #include "en/tc_tun.h" |
0a7fcb78 | 59 | #include "en/mapping.h" |
4c3844d9 | 60 | #include "en/tc_ct.h" |
b2fdf3d0 | 61 | #include "en/mod_hdr.h" |
0d9f9647 VB |
62 | #include "en/tc_priv.h" |
63 | #include "en/tc_tun_encap.h" | |
0027d70c | 64 | #include "en/tc/sample.h" |
04de7dda | 65 | #include "lib/devcom.h" |
9272e3df | 66 | #include "lib/geneve.h" |
ae430332 | 67 | #include "lib/fs_chains.h" |
7a978759 | 68 | #include "diag/en_tc_tracepoint.h" |
1fe3e316 | 69 | #include <asm/div64.h> |
e8f887ac | 70 | |
6a064674 | 71 | #define nic_chains(priv) ((priv)->fs.tc.chains) |
d65dbedf | 72 | #define MLX5_MH_ACT_SZ MLX5_UN_SZ_BYTES(set_add_copy_action_in_auto) |
17091853 | 73 | |
acff797c | 74 | #define MLX5E_TC_TABLE_NUM_GROUPS 4 |
6a064674 | 75 | #define MLX5E_TC_TABLE_MAX_GROUP_SIZE BIT(18) |
e8f887ac | 76 | |
8f1e0b97 PB |
77 | struct mlx5e_tc_attr_to_reg_mapping mlx5e_tc_attr_to_reg_mappings[] = { |
78 | [CHAIN_TO_REG] = { | |
79 | .mfield = MLX5_ACTION_IN_FIELD_METADATA_REG_C_0, | |
80 | .moffset = 0, | |
ed2fe7ba | 81 | .mlen = 16, |
8f1e0b97 | 82 | }, |
10742efc VB |
83 | [VPORT_TO_REG] = { |
84 | .mfield = MLX5_ACTION_IN_FIELD_METADATA_REG_C_0, | |
ed2fe7ba PB |
85 | .moffset = 16, |
86 | .mlen = 16, | |
10742efc | 87 | }, |
0a7fcb78 PB |
88 | [TUNNEL_TO_REG] = { |
89 | .mfield = MLX5_ACTION_IN_FIELD_METADATA_REG_C_1, | |
ed2fe7ba PB |
90 | .moffset = 8, |
91 | .mlen = ESW_TUN_OPTS_BITS + ESW_TUN_ID_BITS, | |
0a7fcb78 PB |
92 | .soffset = MLX5_BYTE_OFF(fte_match_param, |
93 | misc_parameters_2.metadata_reg_c_1), | |
94 | }, | |
4c3844d9 | 95 | [ZONE_TO_REG] = zone_to_reg_ct, |
a8eb919b | 96 | [ZONE_RESTORE_TO_REG] = zone_restore_to_reg_ct, |
4c3844d9 PB |
97 | [CTSTATE_TO_REG] = ctstate_to_reg_ct, |
98 | [MARK_TO_REG] = mark_to_reg_ct, | |
99 | [LABELS_TO_REG] = labels_to_reg_ct, | |
100 | [FTEID_TO_REG] = fteid_to_reg_ct, | |
39c538d6 | 101 | /* For NIC rules we store the restore metadata directly |
c7569097 AL |
102 | * into reg_b that is passed to SW since we don't |
103 | * jump between steering domains. | |
104 | */ | |
105 | [NIC_CHAIN_TO_REG] = { | |
106 | .mfield = MLX5_ACTION_IN_FIELD_METADATA_REG_B, | |
107 | .moffset = 0, | |
ed2fe7ba | 108 | .mlen = 16, |
c7569097 | 109 | }, |
aedd133d | 110 | [NIC_ZONE_RESTORE_TO_REG] = nic_zone_restore_to_reg_ct, |
8f1e0b97 PB |
111 | }; |
112 | ||
9ba33339 RD |
113 | /* To avoid false lock dependency warning set the tc_ht lock |
114 | * class different than the lock class of the ht being used when deleting | |
115 | * last flow from a group and then deleting a group, we get into del_sw_flow_group() | |
116 | * which call rhashtable_destroy on fg->ftes_hash which will take ht->mutex but | |
117 | * it's different than the ht->mutex here. | |
118 | */ | |
119 | static struct lock_class_key tc_ht_lock_key; | |
120 | ||
0a7fcb78 PB |
121 | static void mlx5e_put_flow_tunnel_id(struct mlx5e_tc_flow *flow); |
122 | ||
123 | void | |
124 | mlx5e_tc_match_to_reg_match(struct mlx5_flow_spec *spec, | |
125 | enum mlx5e_tc_attr_to_reg type, | |
ed2fe7ba | 126 | u32 val, |
0a7fcb78 PB |
127 | u32 mask) |
128 | { | |
ed2fe7ba | 129 | void *headers_c = spec->match_criteria, *headers_v = spec->match_value, *fmask, *fval; |
0a7fcb78 | 130 | int soffset = mlx5e_tc_attr_to_reg_mappings[type].soffset; |
ed2fe7ba | 131 | int moffset = mlx5e_tc_attr_to_reg_mappings[type].moffset; |
0a7fcb78 | 132 | int match_len = mlx5e_tc_attr_to_reg_mappings[type].mlen; |
ed2fe7ba PB |
133 | u32 max_mask = GENMASK(match_len - 1, 0); |
134 | __be32 curr_mask_be, curr_val_be; | |
135 | u32 curr_mask, curr_val; | |
0a7fcb78 PB |
136 | |
137 | fmask = headers_c + soffset; | |
138 | fval = headers_v + soffset; | |
139 | ||
ed2fe7ba PB |
140 | memcpy(&curr_mask_be, fmask, 4); |
141 | memcpy(&curr_val_be, fval, 4); | |
142 | ||
143 | curr_mask = be32_to_cpu(curr_mask_be); | |
144 | curr_val = be32_to_cpu(curr_val_be); | |
145 | ||
146 | //move to correct offset | |
147 | WARN_ON(mask > max_mask); | |
148 | mask <<= moffset; | |
149 | val <<= moffset; | |
150 | max_mask <<= moffset; | |
151 | ||
152 | //zero val and mask | |
153 | curr_mask &= ~max_mask; | |
154 | curr_val &= ~max_mask; | |
0a7fcb78 | 155 | |
ed2fe7ba PB |
156 | //add current to mask |
157 | curr_mask |= mask; | |
158 | curr_val |= val; | |
159 | ||
160 | //back to be32 and write | |
161 | curr_mask_be = cpu_to_be32(curr_mask); | |
162 | curr_val_be = cpu_to_be32(curr_val); | |
163 | ||
164 | memcpy(fmask, &curr_mask_be, 4); | |
165 | memcpy(fval, &curr_val_be, 4); | |
0a7fcb78 PB |
166 | |
167 | spec->match_criteria_enable |= MLX5_MATCH_MISC_PARAMETERS_2; | |
168 | } | |
169 | ||
7e36feeb PB |
170 | void |
171 | mlx5e_tc_match_to_reg_get_match(struct mlx5_flow_spec *spec, | |
172 | enum mlx5e_tc_attr_to_reg type, | |
ed2fe7ba | 173 | u32 *val, |
7e36feeb PB |
174 | u32 *mask) |
175 | { | |
ed2fe7ba | 176 | void *headers_c = spec->match_criteria, *headers_v = spec->match_value, *fmask, *fval; |
7e36feeb | 177 | int soffset = mlx5e_tc_attr_to_reg_mappings[type].soffset; |
ed2fe7ba | 178 | int moffset = mlx5e_tc_attr_to_reg_mappings[type].moffset; |
7e36feeb | 179 | int match_len = mlx5e_tc_attr_to_reg_mappings[type].mlen; |
ed2fe7ba PB |
180 | u32 max_mask = GENMASK(match_len - 1, 0); |
181 | __be32 curr_mask_be, curr_val_be; | |
182 | u32 curr_mask, curr_val; | |
7e36feeb PB |
183 | |
184 | fmask = headers_c + soffset; | |
185 | fval = headers_v + soffset; | |
186 | ||
ed2fe7ba PB |
187 | memcpy(&curr_mask_be, fmask, 4); |
188 | memcpy(&curr_val_be, fval, 4); | |
189 | ||
190 | curr_mask = be32_to_cpu(curr_mask_be); | |
191 | curr_val = be32_to_cpu(curr_val_be); | |
7e36feeb | 192 | |
ed2fe7ba PB |
193 | *mask = (curr_mask >> moffset) & max_mask; |
194 | *val = (curr_val >> moffset) & max_mask; | |
7e36feeb PB |
195 | } |
196 | ||
0a7fcb78 | 197 | int |
c7b9038d VB |
198 | mlx5e_tc_match_to_reg_set_and_get_id(struct mlx5_core_dev *mdev, |
199 | struct mlx5e_tc_mod_hdr_acts *mod_hdr_acts, | |
200 | enum mlx5_flow_namespace_type ns, | |
201 | enum mlx5e_tc_attr_to_reg type, | |
202 | u32 data) | |
0a7fcb78 PB |
203 | { |
204 | int moffset = mlx5e_tc_attr_to_reg_mappings[type].moffset; | |
205 | int mfield = mlx5e_tc_attr_to_reg_mappings[type].mfield; | |
206 | int mlen = mlx5e_tc_attr_to_reg_mappings[type].mlen; | |
207 | char *modact; | |
208 | int err; | |
209 | ||
aedd133d | 210 | err = alloc_mod_hdr_actions(mdev, ns, mod_hdr_acts); |
0a7fcb78 PB |
211 | if (err) |
212 | return err; | |
213 | ||
214 | modact = mod_hdr_acts->actions + | |
215 | (mod_hdr_acts->num_actions * MLX5_MH_ACT_SZ); | |
216 | ||
217 | /* Firmware has 5bit length field and 0 means 32bits */ | |
ed2fe7ba | 218 | if (mlen == 32) |
0a7fcb78 PB |
219 | mlen = 0; |
220 | ||
221 | MLX5_SET(set_action_in, modact, action_type, MLX5_ACTION_TYPE_SET); | |
222 | MLX5_SET(set_action_in, modact, field, mfield); | |
ed2fe7ba PB |
223 | MLX5_SET(set_action_in, modact, offset, moffset); |
224 | MLX5_SET(set_action_in, modact, length, mlen); | |
0a7fcb78 | 225 | MLX5_SET(set_action_in, modact, data, data); |
c7b9038d | 226 | err = mod_hdr_acts->num_actions; |
0a7fcb78 PB |
227 | mod_hdr_acts->num_actions++; |
228 | ||
c7b9038d | 229 | return err; |
0a7fcb78 PB |
230 | } |
231 | ||
aedd133d AL |
232 | static struct mlx5_tc_ct_priv * |
233 | get_ct_priv(struct mlx5e_priv *priv) | |
234 | { | |
235 | struct mlx5_eswitch *esw = priv->mdev->priv.eswitch; | |
236 | struct mlx5_rep_uplink_priv *uplink_priv; | |
237 | struct mlx5e_rep_priv *uplink_rpriv; | |
238 | ||
e8711402 | 239 | if (is_mdev_switchdev_mode(priv->mdev)) { |
aedd133d AL |
240 | uplink_rpriv = mlx5_eswitch_get_uplink_priv(esw, REP_ETH); |
241 | uplink_priv = &uplink_rpriv->uplink_priv; | |
242 | ||
243 | return uplink_priv->ct_priv; | |
244 | } | |
245 | ||
246 | return priv->fs.tc.ct; | |
247 | } | |
248 | ||
f94d6389 | 249 | #if IS_ENABLED(CONFIG_MLX5_TC_SAMPLE) |
0027d70c | 250 | static struct mlx5e_tc_psample * |
f94d6389 CM |
251 | get_sample_priv(struct mlx5e_priv *priv) |
252 | { | |
253 | struct mlx5_eswitch *esw = priv->mdev->priv.eswitch; | |
254 | struct mlx5_rep_uplink_priv *uplink_priv; | |
255 | struct mlx5e_rep_priv *uplink_rpriv; | |
256 | ||
257 | if (is_mdev_switchdev_mode(priv->mdev)) { | |
258 | uplink_rpriv = mlx5_eswitch_get_uplink_priv(esw, REP_ETH); | |
259 | uplink_priv = &uplink_rpriv->uplink_priv; | |
260 | ||
0027d70c | 261 | return uplink_priv->tc_psample; |
f94d6389 CM |
262 | } |
263 | ||
264 | return NULL; | |
265 | } | |
266 | #endif | |
267 | ||
aedd133d AL |
268 | struct mlx5_flow_handle * |
269 | mlx5_tc_rule_insert(struct mlx5e_priv *priv, | |
270 | struct mlx5_flow_spec *spec, | |
271 | struct mlx5_flow_attr *attr) | |
272 | { | |
273 | struct mlx5_eswitch *esw = priv->mdev->priv.eswitch; | |
274 | ||
e8711402 | 275 | if (is_mdev_switchdev_mode(priv->mdev)) |
aedd133d AL |
276 | return mlx5_eswitch_add_offloaded_rule(esw, spec, attr); |
277 | ||
278 | return mlx5e_add_offloaded_nic_rule(priv, spec, attr); | |
279 | } | |
280 | ||
281 | void | |
282 | mlx5_tc_rule_delete(struct mlx5e_priv *priv, | |
283 | struct mlx5_flow_handle *rule, | |
284 | struct mlx5_flow_attr *attr) | |
285 | { | |
286 | struct mlx5_eswitch *esw = priv->mdev->priv.eswitch; | |
287 | ||
e8711402 | 288 | if (is_mdev_switchdev_mode(priv->mdev)) { |
aedd133d AL |
289 | mlx5_eswitch_del_offloaded_rule(esw, rule, attr); |
290 | ||
291 | return; | |
292 | } | |
293 | ||
294 | mlx5e_del_offloaded_nic_rule(priv, rule, attr); | |
295 | } | |
296 | ||
c7b9038d VB |
297 | int |
298 | mlx5e_tc_match_to_reg_set(struct mlx5_core_dev *mdev, | |
299 | struct mlx5e_tc_mod_hdr_acts *mod_hdr_acts, | |
300 | enum mlx5_flow_namespace_type ns, | |
301 | enum mlx5e_tc_attr_to_reg type, | |
302 | u32 data) | |
303 | { | |
304 | int ret = mlx5e_tc_match_to_reg_set_and_get_id(mdev, mod_hdr_acts, ns, type, data); | |
305 | ||
306 | return ret < 0 ? ret : 0; | |
307 | } | |
308 | ||
309 | void mlx5e_tc_match_to_reg_mod_hdr_change(struct mlx5_core_dev *mdev, | |
310 | struct mlx5e_tc_mod_hdr_acts *mod_hdr_acts, | |
311 | enum mlx5e_tc_attr_to_reg type, | |
312 | int act_id, u32 data) | |
313 | { | |
314 | int moffset = mlx5e_tc_attr_to_reg_mappings[type].moffset; | |
315 | int mfield = mlx5e_tc_attr_to_reg_mappings[type].mfield; | |
316 | int mlen = mlx5e_tc_attr_to_reg_mappings[type].mlen; | |
317 | char *modact; | |
318 | ||
319 | modact = mod_hdr_acts->actions + (act_id * MLX5_MH_ACT_SZ); | |
320 | ||
321 | /* Firmware has 5bit length field and 0 means 32bits */ | |
ed2fe7ba | 322 | if (mlen == 32) |
c7b9038d VB |
323 | mlen = 0; |
324 | ||
325 | MLX5_SET(set_action_in, modact, action_type, MLX5_ACTION_TYPE_SET); | |
326 | MLX5_SET(set_action_in, modact, field, mfield); | |
ed2fe7ba PB |
327 | MLX5_SET(set_action_in, modact, offset, moffset); |
328 | MLX5_SET(set_action_in, modact, length, mlen); | |
c7b9038d VB |
329 | MLX5_SET(set_action_in, modact, data, data); |
330 | } | |
331 | ||
77ab67b7 OG |
332 | struct mlx5e_hairpin { |
333 | struct mlx5_hairpin *pair; | |
334 | ||
335 | struct mlx5_core_dev *func_mdev; | |
3f6d08d1 | 336 | struct mlx5e_priv *func_priv; |
77ab67b7 | 337 | u32 tdn; |
a6696735 | 338 | struct mlx5e_tir direct_tir; |
3f6d08d1 OG |
339 | |
340 | int num_channels; | |
341 | struct mlx5e_rqt indir_rqt; | |
a6696735 | 342 | struct mlx5e_tir indir_tir[MLX5E_NUM_INDIR_TIRS]; |
f4b45940 | 343 | struct mlx5_ttc_table *ttc; |
77ab67b7 OG |
344 | }; |
345 | ||
5c65c564 OG |
346 | struct mlx5e_hairpin_entry { |
347 | /* a node of a hash table which keeps all the hairpin entries */ | |
348 | struct hlist_node hairpin_hlist; | |
349 | ||
73edca73 VB |
350 | /* protects flows list */ |
351 | spinlock_t flows_lock; | |
5c65c564 OG |
352 | /* flows sharing the same hairpin */ |
353 | struct list_head flows; | |
db76ca24 VB |
354 | /* hpe's that were not fully initialized when dead peer update event |
355 | * function traversed them. | |
356 | */ | |
357 | struct list_head dead_peer_wait_list; | |
5c65c564 | 358 | |
d8822868 | 359 | u16 peer_vhca_id; |
106be53b | 360 | u8 prio; |
5c65c564 | 361 | struct mlx5e_hairpin *hp; |
e4f9abbd | 362 | refcount_t refcnt; |
db76ca24 | 363 | struct completion res_ready; |
5c65c564 OG |
364 | }; |
365 | ||
5a7e5bcb VB |
366 | static void mlx5e_tc_del_flow(struct mlx5e_priv *priv, |
367 | struct mlx5e_tc_flow *flow); | |
368 | ||
0d9f9647 | 369 | struct mlx5e_tc_flow *mlx5e_flow_get(struct mlx5e_tc_flow *flow) |
5a7e5bcb VB |
370 | { |
371 | if (!flow || !refcount_inc_not_zero(&flow->refcnt)) | |
372 | return ERR_PTR(-EINVAL); | |
373 | return flow; | |
374 | } | |
375 | ||
0d9f9647 | 376 | void mlx5e_flow_put(struct mlx5e_priv *priv, struct mlx5e_tc_flow *flow) |
5a7e5bcb VB |
377 | { |
378 | if (refcount_dec_and_test(&flow->refcnt)) { | |
379 | mlx5e_tc_del_flow(priv, flow); | |
c5d326b2 | 380 | kfree_rcu(flow, rcu_head); |
5a7e5bcb VB |
381 | } |
382 | } | |
383 | ||
aedd133d | 384 | bool mlx5e_is_eswitch_flow(struct mlx5e_tc_flow *flow) |
226f2ca3 VB |
385 | { |
386 | return flow_flag_test(flow, ESWITCH); | |
387 | } | |
388 | ||
84179981 PB |
389 | static bool mlx5e_is_ft_flow(struct mlx5e_tc_flow *flow) |
390 | { | |
391 | return flow_flag_test(flow, FT); | |
392 | } | |
393 | ||
0d9f9647 | 394 | bool mlx5e_is_offloaded_flow(struct mlx5e_tc_flow *flow) |
226f2ca3 VB |
395 | { |
396 | return flow_flag_test(flow, OFFLOADED); | |
397 | } | |
398 | ||
b2fdf3d0 | 399 | static int get_flow_name_space(struct mlx5e_tc_flow *flow) |
11c9c548 | 400 | { |
b2fdf3d0 PB |
401 | return mlx5e_is_eswitch_flow(flow) ? |
402 | MLX5_FLOW_NAMESPACE_FDB : MLX5_FLOW_NAMESPACE_KERNEL; | |
11c9c548 OG |
403 | } |
404 | ||
dd58edc3 | 405 | static struct mod_hdr_tbl * |
b2fdf3d0 | 406 | get_mod_hdr_table(struct mlx5e_priv *priv, struct mlx5e_tc_flow *flow) |
dd58edc3 VB |
407 | { |
408 | struct mlx5_eswitch *esw = priv->mdev->priv.eswitch; | |
409 | ||
b2fdf3d0 PB |
410 | return get_flow_name_space(flow) == MLX5_FLOW_NAMESPACE_FDB ? |
411 | &esw->offloads.mod_hdr : | |
dd58edc3 VB |
412 | &priv->fs.tc.mod_hdr; |
413 | } | |
414 | ||
11c9c548 OG |
415 | static int mlx5e_attach_mod_hdr(struct mlx5e_priv *priv, |
416 | struct mlx5e_tc_flow *flow, | |
417 | struct mlx5e_tc_flow_parse_attr *parse_attr) | |
418 | { | |
b2fdf3d0 PB |
419 | struct mlx5_modify_hdr *modify_hdr; |
420 | struct mlx5e_mod_hdr_handle *mh; | |
11c9c548 | 421 | |
b2fdf3d0 PB |
422 | mh = mlx5e_mod_hdr_attach(priv->mdev, get_mod_hdr_table(priv, flow), |
423 | get_flow_name_space(flow), | |
424 | &parse_attr->mod_hdr_acts); | |
425 | if (IS_ERR(mh)) | |
426 | return PTR_ERR(mh); | |
11c9c548 | 427 | |
b2fdf3d0 | 428 | modify_hdr = mlx5e_mod_hdr_get(mh); |
c620b772 | 429 | flow->attr->modify_hdr = modify_hdr; |
b2fdf3d0 | 430 | flow->mh = mh; |
11c9c548 OG |
431 | |
432 | return 0; | |
11c9c548 OG |
433 | } |
434 | ||
435 | static void mlx5e_detach_mod_hdr(struct mlx5e_priv *priv, | |
436 | struct mlx5e_tc_flow *flow) | |
437 | { | |
5a7e5bcb | 438 | /* flow wasn't fully initialized */ |
dd58edc3 | 439 | if (!flow->mh) |
5a7e5bcb VB |
440 | return; |
441 | ||
b2fdf3d0 PB |
442 | mlx5e_mod_hdr_detach(priv->mdev, get_mod_hdr_table(priv, flow), |
443 | flow->mh); | |
dd58edc3 | 444 | flow->mh = NULL; |
11c9c548 OG |
445 | } |
446 | ||
77ab67b7 OG |
447 | static |
448 | struct mlx5_core_dev *mlx5e_hairpin_get_mdev(struct net *net, int ifindex) | |
449 | { | |
b1c2f631 | 450 | struct mlx5_core_dev *mdev; |
77ab67b7 OG |
451 | struct net_device *netdev; |
452 | struct mlx5e_priv *priv; | |
453 | ||
b1c2f631 DC |
454 | netdev = dev_get_by_index(net, ifindex); |
455 | if (!netdev) | |
456 | return ERR_PTR(-ENODEV); | |
457 | ||
77ab67b7 | 458 | priv = netdev_priv(netdev); |
b1c2f631 DC |
459 | mdev = priv->mdev; |
460 | dev_put(netdev); | |
461 | ||
462 | /* Mirred tc action holds a refcount on the ifindex net_device (see | |
463 | * net/sched/act_mirred.c:tcf_mirred_get_dev). So, it's okay to continue using mdev | |
464 | * after dev_put(netdev), while we're in the context of adding a tc flow. | |
465 | * | |
466 | * The mdev pointer corresponds to the peer/out net_device of a hairpin. It is then | |
467 | * stored in a hairpin object, which exists until all flows, that refer to it, get | |
468 | * removed. | |
469 | * | |
470 | * On the other hand, after a hairpin object has been created, the peer net_device may | |
471 | * be removed/unbound while there are still some hairpin flows that are using it. This | |
472 | * case is handled by mlx5e_tc_hairpin_update_dead_peer, which is hooked to | |
473 | * NETDEV_UNREGISTER event of the peer net_device. | |
474 | */ | |
475 | return mdev; | |
77ab67b7 OG |
476 | } |
477 | ||
478 | static int mlx5e_hairpin_create_transport(struct mlx5e_hairpin *hp) | |
479 | { | |
a6696735 | 480 | struct mlx5e_tir_builder *builder; |
77ab67b7 OG |
481 | int err; |
482 | ||
a6696735 MM |
483 | builder = mlx5e_tir_builder_alloc(false); |
484 | if (!builder) | |
485 | return -ENOMEM; | |
486 | ||
77ab67b7 OG |
487 | err = mlx5_core_alloc_transport_domain(hp->func_mdev, &hp->tdn); |
488 | if (err) | |
a6696735 | 489 | goto out; |
77ab67b7 | 490 | |
a6696735 MM |
491 | mlx5e_tir_builder_build_inline(builder, hp->tdn, hp->pair->rqn[0]); |
492 | err = mlx5e_tir_init(&hp->direct_tir, builder, hp->func_mdev, false); | |
77ab67b7 OG |
493 | if (err) |
494 | goto create_tir_err; | |
495 | ||
a6696735 MM |
496 | out: |
497 | mlx5e_tir_builder_free(builder); | |
498 | return err; | |
77ab67b7 OG |
499 | |
500 | create_tir_err: | |
501 | mlx5_core_dealloc_transport_domain(hp->func_mdev, hp->tdn); | |
a6696735 MM |
502 | |
503 | goto out; | |
77ab67b7 OG |
504 | } |
505 | ||
506 | static void mlx5e_hairpin_destroy_transport(struct mlx5e_hairpin *hp) | |
507 | { | |
a6696735 | 508 | mlx5e_tir_destroy(&hp->direct_tir); |
77ab67b7 OG |
509 | mlx5_core_dealloc_transport_domain(hp->func_mdev, hp->tdn); |
510 | } | |
511 | ||
3f6d08d1 OG |
512 | static int mlx5e_hairpin_create_indirect_rqt(struct mlx5e_hairpin *hp) |
513 | { | |
3f6d08d1 OG |
514 | struct mlx5e_priv *priv = hp->func_priv; |
515 | struct mlx5_core_dev *mdev = priv->mdev; | |
06e9f13a MM |
516 | struct mlx5e_rss_params_indir *indir; |
517 | int err; | |
3f6d08d1 | 518 | |
06e9f13a MM |
519 | indir = kvmalloc(sizeof(*indir), GFP_KERNEL); |
520 | if (!indir) | |
3f6d08d1 OG |
521 | return -ENOMEM; |
522 | ||
43befe99 | 523 | mlx5e_rss_params_indir_init_uniform(indir, hp->num_channels); |
06e9f13a | 524 | err = mlx5e_rqt_init_indir(&hp->indir_rqt, mdev, hp->pair->rqn, hp->num_channels, |
43ec0f41 MM |
525 | mlx5e_rx_res_get_current_hash(priv->rx_res).hfunc, |
526 | indir); | |
3f6d08d1 | 527 | |
06e9f13a | 528 | kvfree(indir); |
3f6d08d1 OG |
529 | return err; |
530 | } | |
531 | ||
532 | static int mlx5e_hairpin_create_indirect_tirs(struct mlx5e_hairpin *hp) | |
533 | { | |
534 | struct mlx5e_priv *priv = hp->func_priv; | |
43ec0f41 | 535 | struct mlx5e_rss_params_hash rss_hash; |
d443c6f6 | 536 | enum mlx5_traffic_types tt, max_tt; |
a6696735 MM |
537 | struct mlx5e_tir_builder *builder; |
538 | int err = 0; | |
539 | ||
540 | builder = mlx5e_tir_builder_alloc(false); | |
541 | if (!builder) | |
542 | return -ENOMEM; | |
543 | ||
43ec0f41 | 544 | rss_hash = mlx5e_rx_res_get_current_hash(priv->rx_res); |
3f6d08d1 OG |
545 | |
546 | for (tt = 0; tt < MLX5E_NUM_INDIR_TIRS; tt++) { | |
65d6b6e5 | 547 | struct mlx5e_rss_params_traffic_type rss_tt; |
d930ac79 | 548 | |
65d6b6e5 | 549 | rss_tt = mlx5e_rss_get_default_tt_config(tt); |
3f6d08d1 | 550 | |
a6696735 MM |
551 | mlx5e_tir_builder_build_rqt(builder, hp->tdn, |
552 | mlx5e_rqt_get_rqtn(&hp->indir_rqt), | |
553 | false); | |
43ec0f41 | 554 | mlx5e_tir_builder_build_rss(builder, &rss_hash, &rss_tt, false); |
bbeb53b8 | 555 | |
a6696735 | 556 | err = mlx5e_tir_init(&hp->indir_tir[tt], builder, hp->func_mdev, false); |
3f6d08d1 OG |
557 | if (err) { |
558 | mlx5_core_warn(hp->func_mdev, "create indirect tirs failed, %d\n", err); | |
559 | goto err_destroy_tirs; | |
560 | } | |
a6696735 MM |
561 | |
562 | mlx5e_tir_builder_clear(builder); | |
3f6d08d1 | 563 | } |
3f6d08d1 | 564 | |
a6696735 MM |
565 | out: |
566 | mlx5e_tir_builder_free(builder); | |
3f6d08d1 | 567 | return err; |
a6696735 MM |
568 | |
569 | err_destroy_tirs: | |
570 | max_tt = tt; | |
571 | for (tt = 0; tt < max_tt; tt++) | |
572 | mlx5e_tir_destroy(&hp->indir_tir[tt]); | |
573 | ||
574 | goto out; | |
3f6d08d1 OG |
575 | } |
576 | ||
577 | static void mlx5e_hairpin_destroy_indirect_tirs(struct mlx5e_hairpin *hp) | |
578 | { | |
579 | int tt; | |
580 | ||
581 | for (tt = 0; tt < MLX5E_NUM_INDIR_TIRS; tt++) | |
a6696735 | 582 | mlx5e_tir_destroy(&hp->indir_tir[tt]); |
3f6d08d1 OG |
583 | } |
584 | ||
585 | static void mlx5e_hairpin_set_ttc_params(struct mlx5e_hairpin *hp, | |
586 | struct ttc_params *ttc_params) | |
587 | { | |
588 | struct mlx5_flow_table_attr *ft_attr = &ttc_params->ft_attr; | |
589 | int tt; | |
590 | ||
591 | memset(ttc_params, 0, sizeof(*ttc_params)); | |
592 | ||
bc29764e MG |
593 | ttc_params->ns = mlx5_get_flow_namespace(hp->func_mdev, |
594 | MLX5_FLOW_NAMESPACE_KERNEL); | |
595 | for (tt = 0; tt < MLX5_NUM_TT; tt++) { | |
596 | ttc_params->dests[tt].type = MLX5_FLOW_DESTINATION_TYPE_TIR; | |
597 | ttc_params->dests[tt].tir_num = | |
598 | tt == MLX5_TT_ANY ? | |
599 | mlx5e_tir_get_tirn(&hp->direct_tir) : | |
600 | mlx5e_tir_get_tirn(&hp->indir_tir[tt]); | |
601 | } | |
3f6d08d1 | 602 | |
3f6d08d1 OG |
603 | ft_attr->level = MLX5E_TC_TTC_FT_LEVEL; |
604 | ft_attr->prio = MLX5E_TC_PRIO; | |
605 | } | |
606 | ||
607 | static int mlx5e_hairpin_rss_init(struct mlx5e_hairpin *hp) | |
608 | { | |
609 | struct mlx5e_priv *priv = hp->func_priv; | |
610 | struct ttc_params ttc_params; | |
611 | int err; | |
612 | ||
613 | err = mlx5e_hairpin_create_indirect_rqt(hp); | |
614 | if (err) | |
615 | return err; | |
616 | ||
617 | err = mlx5e_hairpin_create_indirect_tirs(hp); | |
618 | if (err) | |
619 | goto err_create_indirect_tirs; | |
620 | ||
621 | mlx5e_hairpin_set_ttc_params(hp, &ttc_params); | |
f4b45940 MG |
622 | hp->ttc = mlx5_create_ttc_table(priv->mdev, &ttc_params); |
623 | if (IS_ERR(hp->ttc)) { | |
624 | err = PTR_ERR(hp->ttc); | |
3f6d08d1 | 625 | goto err_create_ttc_table; |
f4b45940 | 626 | } |
3f6d08d1 OG |
627 | |
628 | netdev_dbg(priv->netdev, "add hairpin: using %d channels rss ttc table id %x\n", | |
f4b45940 MG |
629 | hp->num_channels, |
630 | mlx5_get_ttc_flow_table(priv->fs.ttc)->id); | |
3f6d08d1 OG |
631 | |
632 | return 0; | |
633 | ||
634 | err_create_ttc_table: | |
635 | mlx5e_hairpin_destroy_indirect_tirs(hp); | |
636 | err_create_indirect_tirs: | |
06e9f13a | 637 | mlx5e_rqt_destroy(&hp->indir_rqt); |
3f6d08d1 OG |
638 | |
639 | return err; | |
640 | } | |
641 | ||
642 | static void mlx5e_hairpin_rss_cleanup(struct mlx5e_hairpin *hp) | |
643 | { | |
f4b45940 | 644 | mlx5_destroy_ttc_table(hp->ttc); |
3f6d08d1 | 645 | mlx5e_hairpin_destroy_indirect_tirs(hp); |
06e9f13a | 646 | mlx5e_rqt_destroy(&hp->indir_rqt); |
3f6d08d1 OG |
647 | } |
648 | ||
77ab67b7 OG |
649 | static struct mlx5e_hairpin * |
650 | mlx5e_hairpin_create(struct mlx5e_priv *priv, struct mlx5_hairpin_params *params, | |
651 | int peer_ifindex) | |
652 | { | |
653 | struct mlx5_core_dev *func_mdev, *peer_mdev; | |
654 | struct mlx5e_hairpin *hp; | |
655 | struct mlx5_hairpin *pair; | |
656 | int err; | |
657 | ||
658 | hp = kzalloc(sizeof(*hp), GFP_KERNEL); | |
659 | if (!hp) | |
660 | return ERR_PTR(-ENOMEM); | |
661 | ||
662 | func_mdev = priv->mdev; | |
663 | peer_mdev = mlx5e_hairpin_get_mdev(dev_net(priv->netdev), peer_ifindex); | |
b1c2f631 DC |
664 | if (IS_ERR(peer_mdev)) { |
665 | err = PTR_ERR(peer_mdev); | |
666 | goto create_pair_err; | |
667 | } | |
77ab67b7 OG |
668 | |
669 | pair = mlx5_core_hairpin_create(func_mdev, peer_mdev, params); | |
670 | if (IS_ERR(pair)) { | |
671 | err = PTR_ERR(pair); | |
672 | goto create_pair_err; | |
673 | } | |
674 | hp->pair = pair; | |
675 | hp->func_mdev = func_mdev; | |
3f6d08d1 OG |
676 | hp->func_priv = priv; |
677 | hp->num_channels = params->num_channels; | |
77ab67b7 OG |
678 | |
679 | err = mlx5e_hairpin_create_transport(hp); | |
680 | if (err) | |
681 | goto create_transport_err; | |
682 | ||
3f6d08d1 OG |
683 | if (hp->num_channels > 1) { |
684 | err = mlx5e_hairpin_rss_init(hp); | |
685 | if (err) | |
686 | goto rss_init_err; | |
687 | } | |
688 | ||
77ab67b7 OG |
689 | return hp; |
690 | ||
3f6d08d1 OG |
691 | rss_init_err: |
692 | mlx5e_hairpin_destroy_transport(hp); | |
77ab67b7 OG |
693 | create_transport_err: |
694 | mlx5_core_hairpin_destroy(hp->pair); | |
695 | create_pair_err: | |
696 | kfree(hp); | |
697 | return ERR_PTR(err); | |
698 | } | |
699 | ||
700 | static void mlx5e_hairpin_destroy(struct mlx5e_hairpin *hp) | |
701 | { | |
3f6d08d1 OG |
702 | if (hp->num_channels > 1) |
703 | mlx5e_hairpin_rss_cleanup(hp); | |
77ab67b7 OG |
704 | mlx5e_hairpin_destroy_transport(hp); |
705 | mlx5_core_hairpin_destroy(hp->pair); | |
706 | kvfree(hp); | |
707 | } | |
708 | ||
106be53b OG |
709 | static inline u32 hash_hairpin_info(u16 peer_vhca_id, u8 prio) |
710 | { | |
711 | return (peer_vhca_id << 16 | prio); | |
712 | } | |
713 | ||
5c65c564 | 714 | static struct mlx5e_hairpin_entry *mlx5e_hairpin_get(struct mlx5e_priv *priv, |
106be53b | 715 | u16 peer_vhca_id, u8 prio) |
5c65c564 OG |
716 | { |
717 | struct mlx5e_hairpin_entry *hpe; | |
106be53b | 718 | u32 hash_key = hash_hairpin_info(peer_vhca_id, prio); |
5c65c564 OG |
719 | |
720 | hash_for_each_possible(priv->fs.tc.hairpin_tbl, hpe, | |
106be53b | 721 | hairpin_hlist, hash_key) { |
e4f9abbd VB |
722 | if (hpe->peer_vhca_id == peer_vhca_id && hpe->prio == prio) { |
723 | refcount_inc(&hpe->refcnt); | |
5c65c564 | 724 | return hpe; |
e4f9abbd | 725 | } |
5c65c564 OG |
726 | } |
727 | ||
728 | return NULL; | |
729 | } | |
730 | ||
e4f9abbd VB |
731 | static void mlx5e_hairpin_put(struct mlx5e_priv *priv, |
732 | struct mlx5e_hairpin_entry *hpe) | |
733 | { | |
734 | /* no more hairpin flows for us, release the hairpin pair */ | |
b32accda | 735 | if (!refcount_dec_and_mutex_lock(&hpe->refcnt, &priv->fs.tc.hairpin_tbl_lock)) |
e4f9abbd | 736 | return; |
b32accda VB |
737 | hash_del(&hpe->hairpin_hlist); |
738 | mutex_unlock(&priv->fs.tc.hairpin_tbl_lock); | |
e4f9abbd | 739 | |
db76ca24 VB |
740 | if (!IS_ERR_OR_NULL(hpe->hp)) { |
741 | netdev_dbg(priv->netdev, "del hairpin: peer %s\n", | |
742 | dev_name(hpe->hp->pair->peer_mdev->device)); | |
743 | ||
744 | mlx5e_hairpin_destroy(hpe->hp); | |
745 | } | |
e4f9abbd VB |
746 | |
747 | WARN_ON(!list_empty(&hpe->flows)); | |
e4f9abbd VB |
748 | kfree(hpe); |
749 | } | |
750 | ||
106be53b OG |
751 | #define UNKNOWN_MATCH_PRIO 8 |
752 | ||
753 | static int mlx5e_hairpin_get_prio(struct mlx5e_priv *priv, | |
e98bedf5 EB |
754 | struct mlx5_flow_spec *spec, u8 *match_prio, |
755 | struct netlink_ext_ack *extack) | |
106be53b OG |
756 | { |
757 | void *headers_c, *headers_v; | |
758 | u8 prio_val, prio_mask = 0; | |
759 | bool vlan_present; | |
760 | ||
761 | #ifdef CONFIG_MLX5_CORE_EN_DCB | |
762 | if (priv->dcbx_dp.trust_state != MLX5_QPTS_TRUST_PCP) { | |
e98bedf5 EB |
763 | NL_SET_ERR_MSG_MOD(extack, |
764 | "only PCP trust state supported for hairpin"); | |
106be53b OG |
765 | return -EOPNOTSUPP; |
766 | } | |
767 | #endif | |
768 | headers_c = MLX5_ADDR_OF(fte_match_param, spec->match_criteria, outer_headers); | |
769 | headers_v = MLX5_ADDR_OF(fte_match_param, spec->match_value, outer_headers); | |
770 | ||
771 | vlan_present = MLX5_GET(fte_match_set_lyr_2_4, headers_v, cvlan_tag); | |
772 | if (vlan_present) { | |
773 | prio_mask = MLX5_GET(fte_match_set_lyr_2_4, headers_c, first_prio); | |
774 | prio_val = MLX5_GET(fte_match_set_lyr_2_4, headers_v, first_prio); | |
775 | } | |
776 | ||
777 | if (!vlan_present || !prio_mask) { | |
778 | prio_val = UNKNOWN_MATCH_PRIO; | |
779 | } else if (prio_mask != 0x7) { | |
e98bedf5 EB |
780 | NL_SET_ERR_MSG_MOD(extack, |
781 | "masked priority match not supported for hairpin"); | |
106be53b OG |
782 | return -EOPNOTSUPP; |
783 | } | |
784 | ||
785 | *match_prio = prio_val; | |
786 | return 0; | |
787 | } | |
788 | ||
5c65c564 OG |
789 | static int mlx5e_hairpin_flow_add(struct mlx5e_priv *priv, |
790 | struct mlx5e_tc_flow *flow, | |
e98bedf5 EB |
791 | struct mlx5e_tc_flow_parse_attr *parse_attr, |
792 | struct netlink_ext_ack *extack) | |
5c65c564 | 793 | { |
98b66cb1 | 794 | int peer_ifindex = parse_attr->mirred_ifindex[0]; |
5c65c564 | 795 | struct mlx5_hairpin_params params; |
d8822868 | 796 | struct mlx5_core_dev *peer_mdev; |
5c65c564 OG |
797 | struct mlx5e_hairpin_entry *hpe; |
798 | struct mlx5e_hairpin *hp; | |
3f6d08d1 OG |
799 | u64 link_speed64; |
800 | u32 link_speed; | |
106be53b | 801 | u8 match_prio; |
d8822868 | 802 | u16 peer_id; |
5c65c564 OG |
803 | int err; |
804 | ||
d8822868 | 805 | peer_mdev = mlx5e_hairpin_get_mdev(dev_net(priv->netdev), peer_ifindex); |
b1c2f631 DC |
806 | if (IS_ERR(peer_mdev)) { |
807 | NL_SET_ERR_MSG_MOD(extack, "invalid ifindex of mirred device"); | |
808 | return PTR_ERR(peer_mdev); | |
809 | } | |
810 | ||
d8822868 | 811 | if (!MLX5_CAP_GEN(priv->mdev, hairpin) || !MLX5_CAP_GEN(peer_mdev, hairpin)) { |
e98bedf5 | 812 | NL_SET_ERR_MSG_MOD(extack, "hairpin is not supported"); |
5c65c564 OG |
813 | return -EOPNOTSUPP; |
814 | } | |
815 | ||
d8822868 | 816 | peer_id = MLX5_CAP_GEN(peer_mdev, vhca_id); |
e98bedf5 EB |
817 | err = mlx5e_hairpin_get_prio(priv, &parse_attr->spec, &match_prio, |
818 | extack); | |
106be53b OG |
819 | if (err) |
820 | return err; | |
b32accda VB |
821 | |
822 | mutex_lock(&priv->fs.tc.hairpin_tbl_lock); | |
106be53b | 823 | hpe = mlx5e_hairpin_get(priv, peer_id, match_prio); |
db76ca24 VB |
824 | if (hpe) { |
825 | mutex_unlock(&priv->fs.tc.hairpin_tbl_lock); | |
826 | wait_for_completion(&hpe->res_ready); | |
827 | ||
828 | if (IS_ERR(hpe->hp)) { | |
829 | err = -EREMOTEIO; | |
830 | goto out_err; | |
831 | } | |
5c65c564 | 832 | goto attach_flow; |
db76ca24 | 833 | } |
5c65c564 OG |
834 | |
835 | hpe = kzalloc(sizeof(*hpe), GFP_KERNEL); | |
b32accda | 836 | if (!hpe) { |
db76ca24 VB |
837 | mutex_unlock(&priv->fs.tc.hairpin_tbl_lock); |
838 | return -ENOMEM; | |
b32accda | 839 | } |
5c65c564 | 840 | |
73edca73 | 841 | spin_lock_init(&hpe->flows_lock); |
5c65c564 | 842 | INIT_LIST_HEAD(&hpe->flows); |
db76ca24 | 843 | INIT_LIST_HEAD(&hpe->dead_peer_wait_list); |
d8822868 | 844 | hpe->peer_vhca_id = peer_id; |
106be53b | 845 | hpe->prio = match_prio; |
e4f9abbd | 846 | refcount_set(&hpe->refcnt, 1); |
db76ca24 VB |
847 | init_completion(&hpe->res_ready); |
848 | ||
849 | hash_add(priv->fs.tc.hairpin_tbl, &hpe->hairpin_hlist, | |
850 | hash_hairpin_info(peer_id, match_prio)); | |
851 | mutex_unlock(&priv->fs.tc.hairpin_tbl_lock); | |
5c65c564 | 852 | |
6cdc686a | 853 | params.log_data_size = 16; |
5c65c564 OG |
854 | params.log_data_size = min_t(u8, params.log_data_size, |
855 | MLX5_CAP_GEN(priv->mdev, log_max_hairpin_wq_data_sz)); | |
856 | params.log_data_size = max_t(u8, params.log_data_size, | |
857 | MLX5_CAP_GEN(priv->mdev, log_min_hairpin_wq_data_sz)); | |
5c65c564 | 858 | |
eb9180f7 OG |
859 | params.log_num_packets = params.log_data_size - |
860 | MLX5_MPWRQ_MIN_LOG_STRIDE_SZ(priv->mdev); | |
861 | params.log_num_packets = min_t(u8, params.log_num_packets, | |
862 | MLX5_CAP_GEN(priv->mdev, log_max_hairpin_num_packets)); | |
863 | ||
864 | params.q_counter = priv->q_counter; | |
3f6d08d1 | 865 | /* set hairpin pair per each 50Gbs share of the link */ |
2c81bfd5 | 866 | mlx5e_port_max_linkspeed(priv->mdev, &link_speed); |
3f6d08d1 OG |
867 | link_speed = max_t(u32, link_speed, 50000); |
868 | link_speed64 = link_speed; | |
869 | do_div(link_speed64, 50000); | |
870 | params.num_channels = link_speed64; | |
871 | ||
5c65c564 | 872 | hp = mlx5e_hairpin_create(priv, ¶ms, peer_ifindex); |
db76ca24 VB |
873 | hpe->hp = hp; |
874 | complete_all(&hpe->res_ready); | |
5c65c564 OG |
875 | if (IS_ERR(hp)) { |
876 | err = PTR_ERR(hp); | |
db76ca24 | 877 | goto out_err; |
5c65c564 OG |
878 | } |
879 | ||
eb9180f7 | 880 | netdev_dbg(priv->netdev, "add hairpin: tirn %x rqn %x peer %s sqn %x prio %d (log) data %d packets %d\n", |
a6696735 | 881 | mlx5e_tir_get_tirn(&hp->direct_tir), hp->pair->rqn[0], |
27b942fb | 882 | dev_name(hp->pair->peer_mdev->device), |
eb9180f7 | 883 | hp->pair->sqn[0], match_prio, params.log_data_size, params.log_num_packets); |
5c65c564 | 884 | |
5c65c564 | 885 | attach_flow: |
3f6d08d1 | 886 | if (hpe->hp->num_channels > 1) { |
226f2ca3 | 887 | flow_flag_set(flow, HAIRPIN_RSS); |
f4b45940 MG |
888 | flow->attr->nic_attr->hairpin_ft = |
889 | mlx5_get_ttc_flow_table(hpe->hp->ttc); | |
3f6d08d1 | 890 | } else { |
a6696735 | 891 | flow->attr->nic_attr->hairpin_tirn = mlx5e_tir_get_tirn(&hpe->hp->direct_tir); |
3f6d08d1 | 892 | } |
b32accda | 893 | |
e4f9abbd | 894 | flow->hpe = hpe; |
73edca73 | 895 | spin_lock(&hpe->flows_lock); |
5c65c564 | 896 | list_add(&flow->hairpin, &hpe->flows); |
73edca73 | 897 | spin_unlock(&hpe->flows_lock); |
3f6d08d1 | 898 | |
5c65c564 OG |
899 | return 0; |
900 | ||
db76ca24 VB |
901 | out_err: |
902 | mlx5e_hairpin_put(priv, hpe); | |
5c65c564 OG |
903 | return err; |
904 | } | |
905 | ||
906 | static void mlx5e_hairpin_flow_del(struct mlx5e_priv *priv, | |
907 | struct mlx5e_tc_flow *flow) | |
908 | { | |
5a7e5bcb | 909 | /* flow wasn't fully initialized */ |
e4f9abbd | 910 | if (!flow->hpe) |
5a7e5bcb VB |
911 | return; |
912 | ||
73edca73 | 913 | spin_lock(&flow->hpe->flows_lock); |
5c65c564 | 914 | list_del(&flow->hairpin); |
73edca73 VB |
915 | spin_unlock(&flow->hpe->flows_lock); |
916 | ||
e4f9abbd VB |
917 | mlx5e_hairpin_put(priv, flow->hpe); |
918 | flow->hpe = NULL; | |
5c65c564 OG |
919 | } |
920 | ||
08247066 AL |
921 | struct mlx5_flow_handle * |
922 | mlx5e_add_offloaded_nic_rule(struct mlx5e_priv *priv, | |
923 | struct mlx5_flow_spec *spec, | |
c620b772 | 924 | struct mlx5_flow_attr *attr) |
e8f887ac | 925 | { |
08247066 | 926 | struct mlx5_flow_context *flow_context = &spec->flow_context; |
c7569097 | 927 | struct mlx5_fs_chains *nic_chains = nic_chains(priv); |
c620b772 | 928 | struct mlx5_nic_flow_attr *nic_attr = attr->nic_attr; |
6a064674 | 929 | struct mlx5e_tc_table *tc = &priv->fs.tc; |
5c65c564 | 930 | struct mlx5_flow_destination dest[2] = {}; |
66958ed9 | 931 | struct mlx5_flow_act flow_act = { |
3bc4b7bf | 932 | .action = attr->action, |
bb0ee7dc | 933 | .flags = FLOW_ACT_NO_APPEND, |
66958ed9 | 934 | }; |
08247066 | 935 | struct mlx5_flow_handle *rule; |
c7569097 | 936 | struct mlx5_flow_table *ft; |
08247066 | 937 | int dest_ix = 0; |
e8f887ac | 938 | |
bb0ee7dc | 939 | flow_context->flags |= FLOW_CONTEXT_HAS_TAG; |
c620b772 | 940 | flow_context->flow_tag = nic_attr->flow_tag; |
bb0ee7dc | 941 | |
aedd133d AL |
942 | if (attr->dest_ft) { |
943 | dest[dest_ix].type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE; | |
944 | dest[dest_ix].ft = attr->dest_ft; | |
945 | dest_ix++; | |
946 | } else if (nic_attr->hairpin_ft) { | |
08247066 | 947 | dest[dest_ix].type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE; |
c620b772 | 948 | dest[dest_ix].ft = nic_attr->hairpin_ft; |
08247066 | 949 | dest_ix++; |
c620b772 | 950 | } else if (nic_attr->hairpin_tirn) { |
08247066 | 951 | dest[dest_ix].type = MLX5_FLOW_DESTINATION_TYPE_TIR; |
c620b772 | 952 | dest[dest_ix].tir_num = nic_attr->hairpin_tirn; |
5c65c564 | 953 | dest_ix++; |
3f6d08d1 OG |
954 | } else if (attr->action & MLX5_FLOW_CONTEXT_ACTION_FWD_DEST) { |
955 | dest[dest_ix].type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE; | |
c7569097 AL |
956 | if (attr->dest_chain) { |
957 | dest[dest_ix].ft = mlx5_chains_get_table(nic_chains, | |
958 | attr->dest_chain, 1, | |
959 | MLX5E_TC_FT_LEVEL); | |
960 | if (IS_ERR(dest[dest_ix].ft)) | |
961 | return ERR_CAST(dest[dest_ix].ft); | |
962 | } else { | |
6783f0a2 | 963 | dest[dest_ix].ft = mlx5e_vlan_get_flowtable(priv->fs.vlan); |
c7569097 | 964 | } |
3f6d08d1 | 965 | dest_ix++; |
5c65c564 | 966 | } |
aad7e08d | 967 | |
c7569097 AL |
968 | if (dest[0].type == MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE && |
969 | MLX5_CAP_FLOWTABLE_NIC_RX(priv->mdev, ignore_flow_level)) | |
970 | flow_act.flags |= FLOW_ACT_IGNORE_FLOW_LEVEL; | |
971 | ||
08247066 | 972 | if (flow_act.action & MLX5_FLOW_CONTEXT_ACTION_COUNT) { |
5c65c564 | 973 | dest[dest_ix].type = MLX5_FLOW_DESTINATION_TYPE_COUNTER; |
08247066 | 974 | dest[dest_ix].counter_id = mlx5_fc_id(attr->counter); |
5c65c564 | 975 | dest_ix++; |
aad7e08d AV |
976 | } |
977 | ||
08247066 | 978 | if (attr->action & MLX5_FLOW_CONTEXT_ACTION_MOD_HDR) |
2b688ea5 | 979 | flow_act.modify_hdr = attr->modify_hdr; |
2f4fe4ca | 980 | |
6a064674 AL |
981 | mutex_lock(&tc->t_lock); |
982 | if (IS_ERR_OR_NULL(tc->t)) { | |
983 | /* Create the root table here if doesn't exist yet */ | |
984 | tc->t = | |
c7569097 | 985 | mlx5_chains_get_table(nic_chains, 0, 1, MLX5E_TC_FT_LEVEL); |
6a064674 AL |
986 | |
987 | if (IS_ERR(tc->t)) { | |
988 | mutex_unlock(&tc->t_lock); | |
e8f887ac AV |
989 | netdev_err(priv->netdev, |
990 | "Failed to create tc offload table\n"); | |
c7569097 AL |
991 | rule = ERR_CAST(priv->fs.tc.t); |
992 | goto err_ft_get; | |
e8f887ac | 993 | } |
e8f887ac | 994 | } |
08247066 | 995 | mutex_unlock(&tc->t_lock); |
e8f887ac | 996 | |
aedd133d AL |
997 | if (attr->chain || attr->prio) |
998 | ft = mlx5_chains_get_table(nic_chains, | |
999 | attr->chain, attr->prio, | |
1000 | MLX5E_TC_FT_LEVEL); | |
1001 | else | |
1002 | ft = attr->ft; | |
1003 | ||
c7569097 AL |
1004 | if (IS_ERR(ft)) { |
1005 | rule = ERR_CAST(ft); | |
1006 | goto err_ft_get; | |
1007 | } | |
1008 | ||
c620b772 | 1009 | if (attr->outer_match_level != MLX5_MATCH_NONE) |
08247066 | 1010 | spec->match_criteria_enable |= MLX5_MATCH_OUTER_HEADERS; |
38aa51c1 | 1011 | |
c7569097 | 1012 | rule = mlx5_add_flow_rules(ft, spec, |
08247066 AL |
1013 | &flow_act, dest, dest_ix); |
1014 | if (IS_ERR(rule)) | |
c7569097 | 1015 | goto err_rule; |
08247066 AL |
1016 | |
1017 | return rule; | |
c7569097 AL |
1018 | |
1019 | err_rule: | |
aedd133d AL |
1020 | if (attr->chain || attr->prio) |
1021 | mlx5_chains_put_table(nic_chains, | |
1022 | attr->chain, attr->prio, | |
1023 | MLX5E_TC_FT_LEVEL); | |
c7569097 AL |
1024 | err_ft_get: |
1025 | if (attr->dest_chain) | |
1026 | mlx5_chains_put_table(nic_chains, | |
1027 | attr->dest_chain, 1, | |
1028 | MLX5E_TC_FT_LEVEL); | |
1029 | ||
1030 | return ERR_CAST(rule); | |
08247066 AL |
1031 | } |
1032 | ||
1033 | static int | |
1034 | mlx5e_tc_add_nic_flow(struct mlx5e_priv *priv, | |
08247066 AL |
1035 | struct mlx5e_tc_flow *flow, |
1036 | struct netlink_ext_ack *extack) | |
1037 | { | |
c6cfe113 | 1038 | struct mlx5e_tc_flow_parse_attr *parse_attr; |
c620b772 | 1039 | struct mlx5_flow_attr *attr = flow->attr; |
08247066 | 1040 | struct mlx5_core_dev *dev = priv->mdev; |
97a8d29a | 1041 | struct mlx5_fc *counter; |
08247066 AL |
1042 | int err; |
1043 | ||
c6cfe113 RD |
1044 | parse_attr = attr->parse_attr; |
1045 | ||
08247066 AL |
1046 | if (flow_flag_test(flow, HAIRPIN)) { |
1047 | err = mlx5e_hairpin_flow_add(priv, flow, parse_attr, extack); | |
1048 | if (err) | |
1049 | return err; | |
1050 | } | |
1051 | ||
1052 | if (attr->action & MLX5_FLOW_CONTEXT_ACTION_COUNT) { | |
1053 | counter = mlx5_fc_create(dev, true); | |
1054 | if (IS_ERR(counter)) | |
1055 | return PTR_ERR(counter); | |
1056 | ||
1057 | attr->counter = counter; | |
1058 | } | |
1059 | ||
1060 | if (attr->action & MLX5_FLOW_CONTEXT_ACTION_MOD_HDR) { | |
1061 | err = mlx5e_attach_mod_hdr(priv, flow, parse_attr); | |
1062 | dealloc_mod_hdr_actions(&parse_attr->mod_hdr_acts); | |
1063 | if (err) | |
1064 | return err; | |
1065 | } | |
1066 | ||
aedd133d AL |
1067 | if (flow_flag_test(flow, CT)) |
1068 | flow->rule[0] = mlx5_tc_ct_flow_offload(get_ct_priv(priv), flow, &parse_attr->spec, | |
1069 | attr, &parse_attr->mod_hdr_acts); | |
1070 | else | |
1071 | flow->rule[0] = mlx5e_add_offloaded_nic_rule(priv, &parse_attr->spec, | |
1072 | attr); | |
aad7e08d | 1073 | |
a2b7189b | 1074 | return PTR_ERR_OR_ZERO(flow->rule[0]); |
e8f887ac AV |
1075 | } |
1076 | ||
08247066 | 1077 | void mlx5e_del_offloaded_nic_rule(struct mlx5e_priv *priv, |
c7569097 AL |
1078 | struct mlx5_flow_handle *rule, |
1079 | struct mlx5_flow_attr *attr) | |
08247066 | 1080 | { |
c7569097 AL |
1081 | struct mlx5_fs_chains *nic_chains = nic_chains(priv); |
1082 | ||
08247066 | 1083 | mlx5_del_flow_rules(rule); |
c7569097 | 1084 | |
aedd133d AL |
1085 | if (attr->chain || attr->prio) |
1086 | mlx5_chains_put_table(nic_chains, attr->chain, attr->prio, | |
1087 | MLX5E_TC_FT_LEVEL); | |
c7569097 AL |
1088 | |
1089 | if (attr->dest_chain) | |
1090 | mlx5_chains_put_table(nic_chains, attr->dest_chain, 1, | |
1091 | MLX5E_TC_FT_LEVEL); | |
08247066 AL |
1092 | } |
1093 | ||
d85cdccb OG |
1094 | static void mlx5e_tc_del_nic_flow(struct mlx5e_priv *priv, |
1095 | struct mlx5e_tc_flow *flow) | |
1096 | { | |
c620b772 | 1097 | struct mlx5_flow_attr *attr = flow->attr; |
6a064674 | 1098 | struct mlx5e_tc_table *tc = &priv->fs.tc; |
d85cdccb | 1099 | |
c7569097 AL |
1100 | flow_flag_clear(flow, OFFLOADED); |
1101 | ||
aedd133d AL |
1102 | if (flow_flag_test(flow, CT)) |
1103 | mlx5_tc_ct_delete_flow(get_ct_priv(flow->priv), flow, attr); | |
1104 | else if (!IS_ERR_OR_NULL(flow->rule[0])) | |
1105 | mlx5e_del_offloaded_nic_rule(priv, flow->rule[0], attr); | |
1106 | ||
c7569097 AL |
1107 | /* Remove root table if no rules are left to avoid |
1108 | * extra steering hops. | |
1109 | */ | |
b6fac0b4 | 1110 | mutex_lock(&priv->fs.tc.t_lock); |
6a064674 AL |
1111 | if (!mlx5e_tc_num_filters(priv, MLX5_TC_FLAG(NIC_OFFLOAD)) && |
1112 | !IS_ERR_OR_NULL(tc->t)) { | |
1113 | mlx5_chains_put_table(nic_chains(priv), 0, 1, MLX5E_TC_FT_LEVEL); | |
d85cdccb OG |
1114 | priv->fs.tc.t = NULL; |
1115 | } | |
b6fac0b4 | 1116 | mutex_unlock(&priv->fs.tc.t_lock); |
2f4fe4ca | 1117 | |
aedd133d AL |
1118 | kvfree(attr->parse_attr); |
1119 | ||
513f8f7f | 1120 | if (attr->action & MLX5_FLOW_CONTEXT_ACTION_MOD_HDR) |
3099eb5a | 1121 | mlx5e_detach_mod_hdr(priv, flow); |
5c65c564 | 1122 | |
aedd133d AL |
1123 | mlx5_fc_destroy(priv->mdev, attr->counter); |
1124 | ||
226f2ca3 | 1125 | if (flow_flag_test(flow, HAIRPIN)) |
5c65c564 | 1126 | mlx5e_hairpin_flow_del(priv, flow); |
c620b772 AL |
1127 | |
1128 | kfree(flow->attr); | |
d85cdccb OG |
1129 | } |
1130 | ||
0d9f9647 | 1131 | struct mlx5_flow_handle * |
6d2a3ed0 OG |
1132 | mlx5e_tc_offload_fdb_rules(struct mlx5_eswitch *esw, |
1133 | struct mlx5e_tc_flow *flow, | |
1134 | struct mlx5_flow_spec *spec, | |
c620b772 | 1135 | struct mlx5_flow_attr *attr) |
6d2a3ed0 | 1136 | { |
1ef3018f | 1137 | struct mlx5e_tc_mod_hdr_acts *mod_hdr_acts; |
6d2a3ed0 | 1138 | struct mlx5_flow_handle *rule; |
4c3844d9 | 1139 | |
89e39467 PB |
1140 | if (attr->flags & MLX5_ESW_ATTR_FLAG_SLOW_PATH) |
1141 | return mlx5_eswitch_add_offloaded_rule(esw, spec, attr); | |
1142 | ||
1ef3018f PB |
1143 | if (flow_flag_test(flow, CT)) { |
1144 | mod_hdr_acts = &attr->parse_attr->mod_hdr_acts; | |
1145 | ||
69e2916e | 1146 | rule = mlx5_tc_ct_flow_offload(get_ct_priv(flow->priv), |
aedd133d | 1147 | flow, spec, attr, |
1ef3018f | 1148 | mod_hdr_acts); |
f94d6389 CM |
1149 | #if IS_ENABLED(CONFIG_MLX5_TC_SAMPLE) |
1150 | } else if (flow_flag_test(flow, SAMPLE)) { | |
ee950e5d CM |
1151 | rule = mlx5e_tc_sample_offload(get_sample_priv(flow->priv), spec, attr, |
1152 | mlx5e_tc_get_flow_tun_id(flow)); | |
f94d6389 | 1153 | #endif |
69e2916e PB |
1154 | } else { |
1155 | rule = mlx5_eswitch_add_offloaded_rule(esw, spec, attr); | |
1ef3018f | 1156 | } |
6d2a3ed0 | 1157 | |
6d2a3ed0 OG |
1158 | if (IS_ERR(rule)) |
1159 | return rule; | |
1160 | ||
c620b772 | 1161 | if (attr->esw_attr->split_count) { |
6d2a3ed0 OG |
1162 | flow->rule[1] = mlx5_eswitch_add_fwd_rule(esw, spec, attr); |
1163 | if (IS_ERR(flow->rule[1])) { | |
69e2916e PB |
1164 | if (flow_flag_test(flow, CT)) |
1165 | mlx5_tc_ct_delete_flow(get_ct_priv(flow->priv), flow, attr); | |
1166 | else | |
1167 | mlx5_eswitch_del_offloaded_rule(esw, rule, attr); | |
6d2a3ed0 OG |
1168 | return flow->rule[1]; |
1169 | } | |
1170 | } | |
1171 | ||
6d2a3ed0 OG |
1172 | return rule; |
1173 | } | |
1174 | ||
0d9f9647 VB |
1175 | void mlx5e_tc_unoffload_fdb_rules(struct mlx5_eswitch *esw, |
1176 | struct mlx5e_tc_flow *flow, | |
1177 | struct mlx5_flow_attr *attr) | |
6d2a3ed0 | 1178 | { |
226f2ca3 | 1179 | flow_flag_clear(flow, OFFLOADED); |
6d2a3ed0 | 1180 | |
89e39467 PB |
1181 | if (attr->flags & MLX5_ESW_ATTR_FLAG_SLOW_PATH) |
1182 | goto offload_rule_0; | |
1183 | ||
4c3844d9 | 1184 | if (flow_flag_test(flow, CT)) { |
aedd133d | 1185 | mlx5_tc_ct_delete_flow(get_ct_priv(flow->priv), flow, attr); |
4c3844d9 PB |
1186 | return; |
1187 | } | |
1188 | ||
f94d6389 CM |
1189 | #if IS_ENABLED(CONFIG_MLX5_TC_SAMPLE) |
1190 | if (flow_flag_test(flow, SAMPLE)) { | |
0027d70c | 1191 | mlx5e_tc_sample_unoffload(get_sample_priv(flow->priv), flow->rule[0], attr); |
f94d6389 CM |
1192 | return; |
1193 | } | |
1194 | #endif | |
1195 | ||
c620b772 | 1196 | if (attr->esw_attr->split_count) |
6d2a3ed0 OG |
1197 | mlx5_eswitch_del_fwd_rule(esw, flow->rule[1], attr); |
1198 | ||
89e39467 | 1199 | offload_rule_0: |
6d2a3ed0 OG |
1200 | mlx5_eswitch_del_offloaded_rule(esw, flow->rule[0], attr); |
1201 | } | |
1202 | ||
0d9f9647 | 1203 | struct mlx5_flow_handle * |
5dbe906f PB |
1204 | mlx5e_tc_offload_to_slow_path(struct mlx5_eswitch *esw, |
1205 | struct mlx5e_tc_flow *flow, | |
178f69b4 | 1206 | struct mlx5_flow_spec *spec) |
5dbe906f | 1207 | { |
c620b772 | 1208 | struct mlx5_flow_attr *slow_attr; |
5dbe906f PB |
1209 | struct mlx5_flow_handle *rule; |
1210 | ||
c620b772 AL |
1211 | slow_attr = mlx5_alloc_flow_attr(MLX5_FLOW_NAMESPACE_FDB); |
1212 | if (!slow_attr) | |
1213 | return ERR_PTR(-ENOMEM); | |
5dbe906f | 1214 | |
c620b772 AL |
1215 | memcpy(slow_attr, flow->attr, ESW_FLOW_ATTR_SZ); |
1216 | slow_attr->action = MLX5_FLOW_CONTEXT_ACTION_FWD_DEST; | |
1217 | slow_attr->esw_attr->split_count = 0; | |
1218 | slow_attr->flags |= MLX5_ESW_ATTR_FLAG_SLOW_PATH; | |
1219 | ||
1220 | rule = mlx5e_tc_offload_fdb_rules(esw, flow, spec, slow_attr); | |
5dbe906f | 1221 | if (!IS_ERR(rule)) |
226f2ca3 | 1222 | flow_flag_set(flow, SLOW); |
5dbe906f | 1223 | |
c620b772 AL |
1224 | kfree(slow_attr); |
1225 | ||
5dbe906f PB |
1226 | return rule; |
1227 | } | |
1228 | ||
0d9f9647 VB |
1229 | void mlx5e_tc_unoffload_from_slow_path(struct mlx5_eswitch *esw, |
1230 | struct mlx5e_tc_flow *flow) | |
5dbe906f | 1231 | { |
c620b772 | 1232 | struct mlx5_flow_attr *slow_attr; |
178f69b4 | 1233 | |
c620b772 | 1234 | slow_attr = mlx5_alloc_flow_attr(MLX5_FLOW_NAMESPACE_FDB); |
5efbe617 AL |
1235 | if (!slow_attr) { |
1236 | mlx5_core_warn(flow->priv->mdev, "Unable to alloc attr to unoffload slow path rule\n"); | |
1237 | return; | |
1238 | } | |
c620b772 AL |
1239 | |
1240 | memcpy(slow_attr, flow->attr, ESW_FLOW_ATTR_SZ); | |
1241 | slow_attr->action = MLX5_FLOW_CONTEXT_ACTION_FWD_DEST; | |
1242 | slow_attr->esw_attr->split_count = 0; | |
1243 | slow_attr->flags |= MLX5_ESW_ATTR_FLAG_SLOW_PATH; | |
1244 | mlx5e_tc_unoffload_fdb_rules(esw, flow, slow_attr); | |
226f2ca3 | 1245 | flow_flag_clear(flow, SLOW); |
c620b772 | 1246 | kfree(slow_attr); |
5dbe906f PB |
1247 | } |
1248 | ||
ad86755b VB |
1249 | /* Caller must obtain uplink_priv->unready_flows_lock mutex before calling this |
1250 | * function. | |
1251 | */ | |
1252 | static void unready_flow_add(struct mlx5e_tc_flow *flow, | |
1253 | struct list_head *unready_flows) | |
1254 | { | |
1255 | flow_flag_set(flow, NOT_READY); | |
1256 | list_add_tail(&flow->unready, unready_flows); | |
1257 | } | |
1258 | ||
1259 | /* Caller must obtain uplink_priv->unready_flows_lock mutex before calling this | |
1260 | * function. | |
1261 | */ | |
1262 | static void unready_flow_del(struct mlx5e_tc_flow *flow) | |
1263 | { | |
1264 | list_del(&flow->unready); | |
1265 | flow_flag_clear(flow, NOT_READY); | |
1266 | } | |
1267 | ||
b4a23329 RD |
1268 | static void add_unready_flow(struct mlx5e_tc_flow *flow) |
1269 | { | |
1270 | struct mlx5_rep_uplink_priv *uplink_priv; | |
1271 | struct mlx5e_rep_priv *rpriv; | |
1272 | struct mlx5_eswitch *esw; | |
1273 | ||
1274 | esw = flow->priv->mdev->priv.eswitch; | |
1275 | rpriv = mlx5_eswitch_get_uplink_priv(esw, REP_ETH); | |
1276 | uplink_priv = &rpriv->uplink_priv; | |
1277 | ||
ad86755b VB |
1278 | mutex_lock(&uplink_priv->unready_flows_lock); |
1279 | unready_flow_add(flow, &uplink_priv->unready_flows); | |
1280 | mutex_unlock(&uplink_priv->unready_flows_lock); | |
b4a23329 RD |
1281 | } |
1282 | ||
1283 | static void remove_unready_flow(struct mlx5e_tc_flow *flow) | |
1284 | { | |
ad86755b VB |
1285 | struct mlx5_rep_uplink_priv *uplink_priv; |
1286 | struct mlx5e_rep_priv *rpriv; | |
1287 | struct mlx5_eswitch *esw; | |
1288 | ||
1289 | esw = flow->priv->mdev->priv.eswitch; | |
1290 | rpriv = mlx5_eswitch_get_uplink_priv(esw, REP_ETH); | |
1291 | uplink_priv = &rpriv->uplink_priv; | |
1292 | ||
1293 | mutex_lock(&uplink_priv->unready_flows_lock); | |
1294 | unready_flow_del(flow); | |
1295 | mutex_unlock(&uplink_priv->unready_flows_lock); | |
b4a23329 RD |
1296 | } |
1297 | ||
10742efc VB |
1298 | static bool same_hw_devs(struct mlx5e_priv *priv, struct mlx5e_priv *peer_priv); |
1299 | ||
a508728a | 1300 | bool mlx5e_tc_is_vf_tunnel(struct net_device *out_dev, struct net_device *route_dev) |
10742efc VB |
1301 | { |
1302 | struct mlx5_core_dev *out_mdev, *route_mdev; | |
1303 | struct mlx5e_priv *out_priv, *route_priv; | |
1304 | ||
1305 | out_priv = netdev_priv(out_dev); | |
1306 | out_mdev = out_priv->mdev; | |
1307 | route_priv = netdev_priv(route_dev); | |
1308 | route_mdev = route_priv->mdev; | |
1309 | ||
1310 | if (out_mdev->coredev_type != MLX5_COREDEV_PF || | |
1311 | route_mdev->coredev_type != MLX5_COREDEV_VF) | |
1312 | return false; | |
1313 | ||
1314 | return same_hw_devs(out_priv, route_priv); | |
1315 | } | |
1316 | ||
a508728a | 1317 | int mlx5e_tc_query_route_vport(struct net_device *out_dev, struct net_device *route_dev, u16 *vport) |
10742efc VB |
1318 | { |
1319 | struct mlx5e_priv *out_priv, *route_priv; | |
f9d196bd | 1320 | struct mlx5_devcom *devcom = NULL; |
10742efc VB |
1321 | struct mlx5_core_dev *route_mdev; |
1322 | struct mlx5_eswitch *esw; | |
1323 | u16 vhca_id; | |
1324 | int err; | |
1325 | ||
1326 | out_priv = netdev_priv(out_dev); | |
1327 | esw = out_priv->mdev->priv.eswitch; | |
1328 | route_priv = netdev_priv(route_dev); | |
1329 | route_mdev = route_priv->mdev; | |
1330 | ||
1331 | vhca_id = MLX5_CAP_GEN(route_mdev, vhca_id); | |
f9d196bd DL |
1332 | if (mlx5_lag_is_active(out_priv->mdev)) { |
1333 | /* In lag case we may get devices from different eswitch instances. | |
1334 | * If we failed to get vport num, it means, mostly, that we on the wrong | |
1335 | * eswitch. | |
1336 | */ | |
1337 | err = mlx5_eswitch_vhca_id_to_vport(esw, vhca_id, vport); | |
1338 | if (err != -ENOENT) | |
1339 | return err; | |
1340 | ||
1341 | devcom = out_priv->mdev->priv.devcom; | |
1342 | esw = mlx5_devcom_get_peer_data(devcom, MLX5_DEVCOM_ESW_OFFLOADS); | |
1343 | if (!esw) | |
1344 | return -ENODEV; | |
1345 | } | |
1346 | ||
10742efc | 1347 | err = mlx5_eswitch_vhca_id_to_vport(esw, vhca_id, vport); |
f9d196bd DL |
1348 | if (devcom) |
1349 | mlx5_devcom_release_peer_data(devcom, MLX5_DEVCOM_ESW_OFFLOADS); | |
10742efc VB |
1350 | return err; |
1351 | } | |
1352 | ||
c7b9038d VB |
1353 | int mlx5e_tc_add_flow_mod_hdr(struct mlx5e_priv *priv, |
1354 | struct mlx5e_tc_flow_parse_attr *parse_attr, | |
1355 | struct mlx5e_tc_flow *flow) | |
1356 | { | |
1357 | struct mlx5e_tc_mod_hdr_acts *mod_hdr_acts = &parse_attr->mod_hdr_acts; | |
1358 | struct mlx5_modify_hdr *mod_hdr; | |
1359 | ||
1360 | mod_hdr = mlx5_modify_header_alloc(priv->mdev, | |
1361 | get_flow_name_space(flow), | |
1362 | mod_hdr_acts->num_actions, | |
1363 | mod_hdr_acts->actions); | |
1364 | if (IS_ERR(mod_hdr)) | |
1365 | return PTR_ERR(mod_hdr); | |
1366 | ||
1367 | WARN_ON(flow->attr->modify_hdr); | |
1368 | flow->attr->modify_hdr = mod_hdr; | |
1369 | ||
1370 | return 0; | |
1371 | } | |
1372 | ||
c83954ab | 1373 | static int |
74491de9 | 1374 | mlx5e_tc_add_fdb_flow(struct mlx5e_priv *priv, |
e98bedf5 EB |
1375 | struct mlx5e_tc_flow *flow, |
1376 | struct netlink_ext_ack *extack) | |
adb4c123 OG |
1377 | { |
1378 | struct mlx5_eswitch *esw = priv->mdev->priv.eswitch; | |
c620b772 AL |
1379 | struct mlx5e_tc_flow_parse_attr *parse_attr; |
1380 | struct mlx5_flow_attr *attr = flow->attr; | |
8914add2 | 1381 | bool vf_tun = false, encap_valid = true; |
fe7738eb | 1382 | struct net_device *encap_dev = NULL; |
c620b772 | 1383 | struct mlx5_esw_flow_attr *esw_attr; |
3c37745e OG |
1384 | struct mlx5e_rep_priv *rpriv; |
1385 | struct mlx5e_priv *out_priv; | |
97a8d29a | 1386 | struct mlx5_fc *counter; |
39ac237c | 1387 | u32 max_prio, max_chain; |
0ad060ee | 1388 | int err = 0; |
f493f155 | 1389 | int out_index; |
8b32580d | 1390 | |
84179981 PB |
1391 | /* We check chain range only for tc flows. |
1392 | * For ft flows, we checked attr->chain was originally 0 and set it to | |
1393 | * FDB_FT_CHAIN which is outside tc range. | |
1394 | * See mlx5e_rep_setup_ft_cb(). | |
1395 | */ | |
ae430332 | 1396 | max_chain = mlx5_chains_get_chain_range(esw_chains(esw)); |
84179981 | 1397 | if (!mlx5e_is_ft_flow(flow) && attr->chain > max_chain) { |
61644c3d RD |
1398 | NL_SET_ERR_MSG_MOD(extack, |
1399 | "Requested chain is out of supported range"); | |
8914add2 VB |
1400 | err = -EOPNOTSUPP; |
1401 | goto err_out; | |
bf07aa73 PB |
1402 | } |
1403 | ||
ae430332 | 1404 | max_prio = mlx5_chains_get_prio_range(esw_chains(esw)); |
bf07aa73 | 1405 | if (attr->prio > max_prio) { |
61644c3d RD |
1406 | NL_SET_ERR_MSG_MOD(extack, |
1407 | "Requested priority is out of supported range"); | |
8914add2 VB |
1408 | err = -EOPNOTSUPP; |
1409 | goto err_out; | |
bf07aa73 | 1410 | } |
e52c2802 | 1411 | |
777bb800 VB |
1412 | if (flow_flag_test(flow, TUN_RX)) { |
1413 | err = mlx5e_attach_decap_route(priv, flow); | |
1414 | if (err) | |
8914add2 | 1415 | goto err_out; |
777bb800 VB |
1416 | } |
1417 | ||
14e6b038 EC |
1418 | if (flow_flag_test(flow, L3_TO_L2_DECAP)) { |
1419 | err = mlx5e_attach_decap(priv, flow, extack); | |
1420 | if (err) | |
8914add2 | 1421 | goto err_out; |
14e6b038 EC |
1422 | } |
1423 | ||
c620b772 AL |
1424 | parse_attr = attr->parse_attr; |
1425 | esw_attr = attr->esw_attr; | |
1426 | ||
f493f155 | 1427 | for (out_index = 0; out_index < MLX5_MAX_FLOW_FWD_VPORTS; out_index++) { |
fe7738eb | 1428 | struct net_device *out_dev; |
8c4dc42b EB |
1429 | int mirred_ifindex; |
1430 | ||
c620b772 | 1431 | if (!(esw_attr->dests[out_index].flags & MLX5_ESW_DEST_ENCAP)) |
f493f155 EB |
1432 | continue; |
1433 | ||
7040632d | 1434 | mirred_ifindex = parse_attr->mirred_ifindex[out_index]; |
fe7738eb DC |
1435 | out_dev = dev_get_by_index(dev_net(priv->netdev), mirred_ifindex); |
1436 | if (!out_dev) { | |
1437 | NL_SET_ERR_MSG_MOD(extack, "Requested mirred device not found"); | |
1438 | err = -ENODEV; | |
1439 | goto err_out; | |
1440 | } | |
733d4f36 | 1441 | err = mlx5e_attach_encap(priv, flow, out_dev, out_index, |
0ad060ee | 1442 | extack, &encap_dev, &encap_valid); |
fe7738eb | 1443 | dev_put(out_dev); |
0ad060ee | 1444 | if (err) |
8914add2 | 1445 | goto err_out; |
0ad060ee | 1446 | |
8914add2 VB |
1447 | if (esw_attr->dests[out_index].flags & |
1448 | MLX5_ESW_DEST_CHAIN_WITH_SRC_PORT_CHANGE) | |
1449 | vf_tun = true; | |
3c37745e OG |
1450 | out_priv = netdev_priv(encap_dev); |
1451 | rpriv = out_priv->ppriv; | |
c620b772 AL |
1452 | esw_attr->dests[out_index].rep = rpriv->rep; |
1453 | esw_attr->dests[out_index].mdev = out_priv->mdev; | |
3c37745e OG |
1454 | } |
1455 | ||
7d1a3d08 VB |
1456 | if (vf_tun && esw_attr->out_count > 1) { |
1457 | NL_SET_ERR_MSG_MOD(extack, "VF tunnel encap with mirroring is not supported"); | |
1458 | err = -EOPNOTSUPP; | |
1459 | goto err_out; | |
1460 | } | |
1461 | ||
8b32580d | 1462 | err = mlx5_eswitch_add_vlan_action(esw, attr); |
c83954ab | 1463 | if (err) |
8914add2 | 1464 | goto err_out; |
adb4c123 | 1465 | |
d5a3c2b6 RD |
1466 | if (attr->action & MLX5_FLOW_CONTEXT_ACTION_MOD_HDR && |
1467 | !(attr->ct_attr.ct_action & TCA_CT_ACT_CLEAR)) { | |
8914add2 VB |
1468 | if (vf_tun) { |
1469 | err = mlx5e_tc_add_flow_mod_hdr(priv, parse_attr, flow); | |
1470 | if (err) | |
1471 | goto err_out; | |
1472 | } else { | |
1473 | err = mlx5e_attach_mod_hdr(priv, flow, parse_attr); | |
1474 | if (err) | |
1475 | goto err_out; | |
1476 | } | |
d7e75a32 OG |
1477 | } |
1478 | ||
b8aee822 | 1479 | if (attr->action & MLX5_FLOW_CONTEXT_ACTION_COUNT) { |
c620b772 | 1480 | counter = mlx5_fc_create(esw_attr->counter_dev, true); |
8914add2 VB |
1481 | if (IS_ERR(counter)) { |
1482 | err = PTR_ERR(counter); | |
1483 | goto err_out; | |
1484 | } | |
b8aee822 MB |
1485 | |
1486 | attr->counter = counter; | |
1487 | } | |
1488 | ||
0ad060ee RD |
1489 | /* we get here if one of the following takes place: |
1490 | * (1) there's no error | |
1491 | * (2) there's an encap action and we don't have valid neigh | |
3c37745e | 1492 | */ |
bc1d75fa | 1493 | if (!encap_valid) |
178f69b4 | 1494 | flow->rule[0] = mlx5e_tc_offload_to_slow_path(esw, flow, &parse_attr->spec); |
bc1d75fa | 1495 | else |
6d2a3ed0 | 1496 | flow->rule[0] = mlx5e_tc_offload_fdb_rules(esw, flow, &parse_attr->spec, attr); |
c83954ab | 1497 | |
8914add2 VB |
1498 | if (IS_ERR(flow->rule[0])) { |
1499 | err = PTR_ERR(flow->rule[0]); | |
1500 | goto err_out; | |
1501 | } | |
1502 | flow_flag_set(flow, OFFLOADED); | |
5dbe906f PB |
1503 | |
1504 | return 0; | |
8914add2 VB |
1505 | |
1506 | err_out: | |
1507 | flow_flag_set(flow, FAILED); | |
1508 | return err; | |
aa0cbbae | 1509 | } |
d85cdccb | 1510 | |
9272e3df YK |
1511 | static bool mlx5_flow_has_geneve_opt(struct mlx5e_tc_flow *flow) |
1512 | { | |
c620b772 | 1513 | struct mlx5_flow_spec *spec = &flow->attr->parse_attr->spec; |
9272e3df YK |
1514 | void *headers_v = MLX5_ADDR_OF(fte_match_param, |
1515 | spec->match_value, | |
1516 | misc_parameters_3); | |
1517 | u32 geneve_tlv_opt_0_data = MLX5_GET(fte_match_set_misc3, | |
1518 | headers_v, | |
1519 | geneve_tlv_option_0_data); | |
1520 | ||
1521 | return !!geneve_tlv_opt_0_data; | |
1522 | } | |
1523 | ||
d85cdccb OG |
1524 | static void mlx5e_tc_del_fdb_flow(struct mlx5e_priv *priv, |
1525 | struct mlx5e_tc_flow *flow) | |
1526 | { | |
1527 | struct mlx5_eswitch *esw = priv->mdev->priv.eswitch; | |
c620b772 | 1528 | struct mlx5_flow_attr *attr = flow->attr; |
777bb800 | 1529 | struct mlx5_esw_flow_attr *esw_attr; |
8914add2 | 1530 | bool vf_tun = false; |
f493f155 | 1531 | int out_index; |
d85cdccb | 1532 | |
777bb800 | 1533 | esw_attr = attr->esw_attr; |
0a7fcb78 PB |
1534 | mlx5e_put_flow_tunnel_id(flow); |
1535 | ||
12a240a4 | 1536 | if (flow_flag_test(flow, NOT_READY)) |
b4a23329 | 1537 | remove_unready_flow(flow); |
ef06c9ee | 1538 | |
226f2ca3 VB |
1539 | if (mlx5e_is_offloaded_flow(flow)) { |
1540 | if (flow_flag_test(flow, SLOW)) | |
178f69b4 | 1541 | mlx5e_tc_unoffload_from_slow_path(esw, flow); |
5dbe906f PB |
1542 | else |
1543 | mlx5e_tc_unoffload_fdb_rules(esw, flow, attr); | |
1544 | } | |
d85cdccb | 1545 | |
9272e3df YK |
1546 | if (mlx5_flow_has_geneve_opt(flow)) |
1547 | mlx5_geneve_tlv_option_del(priv->mdev->geneve); | |
1548 | ||
513f8f7f | 1549 | mlx5_eswitch_del_vlan_action(esw, attr); |
d85cdccb | 1550 | |
777bb800 VB |
1551 | if (flow->decap_route) |
1552 | mlx5e_detach_decap_route(priv, flow); | |
1553 | ||
1554 | for (out_index = 0; out_index < MLX5_MAX_FLOW_FWD_VPORTS; out_index++) { | |
8914add2 VB |
1555 | if (esw_attr->dests[out_index].flags & |
1556 | MLX5_ESW_DEST_CHAIN_WITH_SRC_PORT_CHANGE) | |
1557 | vf_tun = true; | |
777bb800 | 1558 | if (esw_attr->dests[out_index].flags & MLX5_ESW_DEST_ENCAP) { |
8c4dc42b | 1559 | mlx5e_detach_encap(priv, flow, out_index); |
2a4b6526 VB |
1560 | kfree(attr->parse_attr->tun_info[out_index]); |
1561 | } | |
777bb800 | 1562 | } |
d7e75a32 | 1563 | |
aedd133d | 1564 | mlx5_tc_ct_match_del(get_ct_priv(priv), &flow->attr->ct_attr); |
4c8594ad | 1565 | |
c7b9038d VB |
1566 | if (attr->action & MLX5_FLOW_CONTEXT_ACTION_MOD_HDR) { |
1567 | dealloc_mod_hdr_actions(&attr->parse_attr->mod_hdr_acts); | |
8914add2 VB |
1568 | if (vf_tun && attr->modify_hdr) |
1569 | mlx5_modify_header_dealloc(priv->mdev, attr->modify_hdr); | |
1570 | else | |
1571 | mlx5e_detach_mod_hdr(priv, flow); | |
c7b9038d | 1572 | } |
bcd6740c | 1573 | kfree(attr->sample_attr); |
8914add2 VB |
1574 | kvfree(attr->parse_attr); |
1575 | kvfree(attr->esw_attr->rx_tun_attr); | |
b8aee822 MB |
1576 | |
1577 | if (attr->action & MLX5_FLOW_CONTEXT_ACTION_COUNT) | |
777bb800 | 1578 | mlx5_fc_destroy(esw_attr->counter_dev, attr->counter); |
14e6b038 EC |
1579 | |
1580 | if (flow_flag_test(flow, L3_TO_L2_DECAP)) | |
1581 | mlx5e_detach_decap(priv, flow); | |
c620b772 AL |
1582 | |
1583 | kfree(flow->attr); | |
d85cdccb OG |
1584 | } |
1585 | ||
0d9f9647 | 1586 | struct mlx5_fc *mlx5e_tc_get_counter(struct mlx5e_tc_flow *flow) |
b8aee822 | 1587 | { |
c620b772 | 1588 | return flow->attr->counter; |
b8aee822 MB |
1589 | } |
1590 | ||
6a06c2f7 | 1591 | /* Iterate over tmp_list of flows attached to flow_list head. */ |
021905f8 | 1592 | void mlx5e_put_flow_list(struct mlx5e_priv *priv, struct list_head *flow_list) |
6a06c2f7 VB |
1593 | { |
1594 | struct mlx5e_tc_flow *flow, *tmp; | |
1595 | ||
1596 | list_for_each_entry_safe(flow, tmp, flow_list, tmp_list) | |
1597 | mlx5e_flow_put(priv, flow); | |
1598 | } | |
1599 | ||
04de7dda RD |
1600 | static void __mlx5e_tc_del_fdb_peer_flow(struct mlx5e_tc_flow *flow) |
1601 | { | |
1602 | struct mlx5_eswitch *esw = flow->priv->mdev->priv.eswitch; | |
1603 | ||
226f2ca3 VB |
1604 | if (!flow_flag_test(flow, ESWITCH) || |
1605 | !flow_flag_test(flow, DUP)) | |
04de7dda RD |
1606 | return; |
1607 | ||
1608 | mutex_lock(&esw->offloads.peer_mutex); | |
1609 | list_del(&flow->peer); | |
1610 | mutex_unlock(&esw->offloads.peer_mutex); | |
1611 | ||
226f2ca3 | 1612 | flow_flag_clear(flow, DUP); |
04de7dda | 1613 | |
eb252c3a RD |
1614 | if (refcount_dec_and_test(&flow->peer_flow->refcnt)) { |
1615 | mlx5e_tc_del_fdb_flow(flow->peer_flow->priv, flow->peer_flow); | |
1616 | kfree(flow->peer_flow); | |
1617 | } | |
1618 | ||
04de7dda RD |
1619 | flow->peer_flow = NULL; |
1620 | } | |
1621 | ||
1622 | static void mlx5e_tc_del_fdb_peer_flow(struct mlx5e_tc_flow *flow) | |
1623 | { | |
1624 | struct mlx5_core_dev *dev = flow->priv->mdev; | |
1625 | struct mlx5_devcom *devcom = dev->priv.devcom; | |
1626 | struct mlx5_eswitch *peer_esw; | |
1627 | ||
1628 | peer_esw = mlx5_devcom_get_peer_data(devcom, MLX5_DEVCOM_ESW_OFFLOADS); | |
1629 | if (!peer_esw) | |
1630 | return; | |
1631 | ||
1632 | __mlx5e_tc_del_fdb_peer_flow(flow); | |
1633 | mlx5_devcom_release_peer_data(devcom, MLX5_DEVCOM_ESW_OFFLOADS); | |
1634 | } | |
1635 | ||
e8f887ac | 1636 | static void mlx5e_tc_del_flow(struct mlx5e_priv *priv, |
961e8979 | 1637 | struct mlx5e_tc_flow *flow) |
e8f887ac | 1638 | { |
226f2ca3 | 1639 | if (mlx5e_is_eswitch_flow(flow)) { |
04de7dda | 1640 | mlx5e_tc_del_fdb_peer_flow(flow); |
d85cdccb | 1641 | mlx5e_tc_del_fdb_flow(priv, flow); |
04de7dda | 1642 | } else { |
d85cdccb | 1643 | mlx5e_tc_del_nic_flow(priv, flow); |
04de7dda | 1644 | } |
e8f887ac AV |
1645 | } |
1646 | ||
ee950e5d | 1647 | static bool flow_requires_tunnel_mapping(u32 chain, struct flow_cls_offload *f) |
0a7fcb78 PB |
1648 | { |
1649 | struct flow_rule *rule = flow_cls_offload_flow_rule(f); | |
1650 | struct flow_action *flow_action = &rule->action; | |
1651 | const struct flow_action_entry *act; | |
1652 | int i; | |
1653 | ||
ee950e5d CM |
1654 | if (chain) |
1655 | return false; | |
1656 | ||
0a7fcb78 PB |
1657 | flow_action_for_each(i, act, flow_action) { |
1658 | switch (act->id) { | |
1659 | case FLOW_ACTION_GOTO: | |
1660 | return true; | |
ee950e5d CM |
1661 | case FLOW_ACTION_SAMPLE: |
1662 | return true; | |
0a7fcb78 PB |
1663 | default: |
1664 | continue; | |
1665 | } | |
1666 | } | |
1667 | ||
1668 | return false; | |
1669 | } | |
bbd00f7e | 1670 | |
0a7fcb78 PB |
1671 | static int |
1672 | enc_opts_is_dont_care_or_full_match(struct mlx5e_priv *priv, | |
1673 | struct flow_dissector_key_enc_opts *opts, | |
1674 | struct netlink_ext_ack *extack, | |
1675 | bool *dont_care) | |
1676 | { | |
1677 | struct geneve_opt *opt; | |
1678 | int off = 0; | |
1679 | ||
1680 | *dont_care = true; | |
1681 | ||
1682 | while (opts->len > off) { | |
1683 | opt = (struct geneve_opt *)&opts->data[off]; | |
1684 | ||
1685 | if (!(*dont_care) || opt->opt_class || opt->type || | |
1686 | memchr_inv(opt->opt_data, 0, opt->length * 4)) { | |
1687 | *dont_care = false; | |
1688 | ||
c51323ee | 1689 | if (opt->opt_class != htons(U16_MAX) || |
d7a42ad0 | 1690 | opt->type != U8_MAX) { |
0a7fcb78 PB |
1691 | NL_SET_ERR_MSG(extack, |
1692 | "Partial match of tunnel options in chain > 0 isn't supported"); | |
1693 | netdev_warn(priv->netdev, | |
1694 | "Partial match of tunnel options in chain > 0 isn't supported"); | |
1695 | return -EOPNOTSUPP; | |
1696 | } | |
1697 | } | |
1698 | ||
1699 | off += sizeof(struct geneve_opt) + opt->length * 4; | |
1700 | } | |
1701 | ||
1702 | return 0; | |
1703 | } | |
1704 | ||
1705 | #define COPY_DISSECTOR(rule, diss_key, dst)\ | |
1706 | ({ \ | |
1707 | struct flow_rule *__rule = (rule);\ | |
1708 | typeof(dst) __dst = dst;\ | |
1709 | \ | |
1710 | memcpy(__dst,\ | |
1711 | skb_flow_dissector_target(__rule->match.dissector,\ | |
1712 | diss_key,\ | |
1713 | __rule->match.key),\ | |
1714 | sizeof(*__dst));\ | |
1715 | }) | |
1716 | ||
1717 | static int mlx5e_get_flow_tunnel_id(struct mlx5e_priv *priv, | |
1718 | struct mlx5e_tc_flow *flow, | |
1719 | struct flow_cls_offload *f, | |
1720 | struct net_device *filter_dev) | |
bbd00f7e | 1721 | { |
f9e30088 | 1722 | struct flow_rule *rule = flow_cls_offload_flow_rule(f); |
0a7fcb78 | 1723 | struct netlink_ext_ack *extack = f->common.extack; |
0a7fcb78 PB |
1724 | struct mlx5e_tc_mod_hdr_acts *mod_hdr_acts; |
1725 | struct flow_match_enc_opts enc_opts_match; | |
d7a42ad0 | 1726 | struct tunnel_match_enc_opts tun_enc_opts; |
0a7fcb78 | 1727 | struct mlx5_rep_uplink_priv *uplink_priv; |
c620b772 | 1728 | struct mlx5_flow_attr *attr = flow->attr; |
0a7fcb78 PB |
1729 | struct mlx5e_rep_priv *uplink_rpriv; |
1730 | struct tunnel_match_key tunnel_key; | |
1731 | bool enc_opts_is_dont_care = true; | |
1732 | u32 tun_id, enc_opts_id = 0; | |
1733 | struct mlx5_eswitch *esw; | |
1734 | u32 value, mask; | |
8f256622 | 1735 | int err; |
2e72eb43 | 1736 | |
0a7fcb78 PB |
1737 | esw = priv->mdev->priv.eswitch; |
1738 | uplink_rpriv = mlx5_eswitch_get_uplink_priv(esw, REP_ETH); | |
1739 | uplink_priv = &uplink_rpriv->uplink_priv; | |
1740 | ||
1741 | memset(&tunnel_key, 0, sizeof(tunnel_key)); | |
1742 | COPY_DISSECTOR(rule, FLOW_DISSECTOR_KEY_ENC_CONTROL, | |
1743 | &tunnel_key.enc_control); | |
1744 | if (tunnel_key.enc_control.addr_type == FLOW_DISSECTOR_KEY_IPV4_ADDRS) | |
1745 | COPY_DISSECTOR(rule, FLOW_DISSECTOR_KEY_ENC_IPV4_ADDRS, | |
1746 | &tunnel_key.enc_ipv4); | |
1747 | else | |
1748 | COPY_DISSECTOR(rule, FLOW_DISSECTOR_KEY_ENC_IPV6_ADDRS, | |
1749 | &tunnel_key.enc_ipv6); | |
1750 | COPY_DISSECTOR(rule, FLOW_DISSECTOR_KEY_ENC_IP, &tunnel_key.enc_ip); | |
1751 | COPY_DISSECTOR(rule, FLOW_DISSECTOR_KEY_ENC_PORTS, | |
1752 | &tunnel_key.enc_tp); | |
1753 | COPY_DISSECTOR(rule, FLOW_DISSECTOR_KEY_ENC_KEYID, | |
1754 | &tunnel_key.enc_key_id); | |
1755 | tunnel_key.filter_ifindex = filter_dev->ifindex; | |
1756 | ||
1757 | err = mapping_add(uplink_priv->tunnel_mapping, &tunnel_key, &tun_id); | |
1758 | if (err) | |
101f4de9 | 1759 | return err; |
bbd00f7e | 1760 | |
0a7fcb78 PB |
1761 | flow_rule_match_enc_opts(rule, &enc_opts_match); |
1762 | err = enc_opts_is_dont_care_or_full_match(priv, | |
1763 | enc_opts_match.mask, | |
1764 | extack, | |
1765 | &enc_opts_is_dont_care); | |
1766 | if (err) | |
1767 | goto err_enc_opts; | |
fe1587a7 | 1768 | |
0a7fcb78 | 1769 | if (!enc_opts_is_dont_care) { |
d7a42ad0 RD |
1770 | memset(&tun_enc_opts, 0, sizeof(tun_enc_opts)); |
1771 | memcpy(&tun_enc_opts.key, enc_opts_match.key, | |
1772 | sizeof(*enc_opts_match.key)); | |
1773 | memcpy(&tun_enc_opts.mask, enc_opts_match.mask, | |
1774 | sizeof(*enc_opts_match.mask)); | |
1775 | ||
0a7fcb78 | 1776 | err = mapping_add(uplink_priv->tunnel_enc_opts_mapping, |
d7a42ad0 | 1777 | &tun_enc_opts, &enc_opts_id); |
0a7fcb78 PB |
1778 | if (err) |
1779 | goto err_enc_opts; | |
1780 | } | |
fe1587a7 | 1781 | |
0a7fcb78 PB |
1782 | value = tun_id << ENC_OPTS_BITS | enc_opts_id; |
1783 | mask = enc_opts_id ? TUNNEL_ID_MASK : | |
1784 | (TUNNEL_ID_MASK & ~ENC_OPTS_BITS_MASK); | |
fe1587a7 | 1785 | |
0a7fcb78 PB |
1786 | if (attr->chain) { |
1787 | mlx5e_tc_match_to_reg_match(&attr->parse_attr->spec, | |
1788 | TUNNEL_TO_REG, value, mask); | |
1789 | } else { | |
1790 | mod_hdr_acts = &attr->parse_attr->mod_hdr_acts; | |
1791 | err = mlx5e_tc_match_to_reg_set(priv->mdev, | |
aedd133d | 1792 | mod_hdr_acts, MLX5_FLOW_NAMESPACE_FDB, |
0a7fcb78 PB |
1793 | TUNNEL_TO_REG, value); |
1794 | if (err) | |
1795 | goto err_set; | |
fe1587a7 | 1796 | |
0a7fcb78 | 1797 | attr->action |= MLX5_FLOW_CONTEXT_ACTION_MOD_HDR; |
2e72eb43 | 1798 | } |
bbd00f7e | 1799 | |
0a7fcb78 PB |
1800 | flow->tunnel_id = value; |
1801 | return 0; | |
bcef735c | 1802 | |
0a7fcb78 PB |
1803 | err_set: |
1804 | if (enc_opts_id) | |
1805 | mapping_remove(uplink_priv->tunnel_enc_opts_mapping, | |
1806 | enc_opts_id); | |
1807 | err_enc_opts: | |
1808 | mapping_remove(uplink_priv->tunnel_mapping, tun_id); | |
1809 | return err; | |
1810 | } | |
bcef735c | 1811 | |
0a7fcb78 PB |
1812 | static void mlx5e_put_flow_tunnel_id(struct mlx5e_tc_flow *flow) |
1813 | { | |
1814 | u32 enc_opts_id = flow->tunnel_id & ENC_OPTS_BITS_MASK; | |
1815 | u32 tun_id = flow->tunnel_id >> ENC_OPTS_BITS; | |
1816 | struct mlx5_rep_uplink_priv *uplink_priv; | |
1817 | struct mlx5e_rep_priv *uplink_rpriv; | |
1818 | struct mlx5_eswitch *esw; | |
bcef735c | 1819 | |
0a7fcb78 PB |
1820 | esw = flow->priv->mdev->priv.eswitch; |
1821 | uplink_rpriv = mlx5_eswitch_get_uplink_priv(esw, REP_ETH); | |
1822 | uplink_priv = &uplink_rpriv->uplink_priv; | |
1823 | ||
1824 | if (tun_id) | |
1825 | mapping_remove(uplink_priv->tunnel_mapping, tun_id); | |
1826 | if (enc_opts_id) | |
1827 | mapping_remove(uplink_priv->tunnel_enc_opts_mapping, | |
1828 | enc_opts_id); | |
1829 | } | |
e98bedf5 | 1830 | |
4c3844d9 PB |
1831 | u32 mlx5e_tc_get_flow_tun_id(struct mlx5e_tc_flow *flow) |
1832 | { | |
1833 | return flow->tunnel_id; | |
1834 | } | |
1835 | ||
fca53304 EB |
1836 | void mlx5e_tc_set_ethertype(struct mlx5_core_dev *mdev, |
1837 | struct flow_match_basic *match, bool outer, | |
1838 | void *headers_c, void *headers_v) | |
1839 | { | |
1840 | bool ip_version_cap; | |
1841 | ||
1842 | ip_version_cap = outer ? | |
1843 | MLX5_CAP_FLOWTABLE_NIC_RX(mdev, | |
1844 | ft_field_support.outer_ip_version) : | |
1845 | MLX5_CAP_FLOWTABLE_NIC_RX(mdev, | |
1846 | ft_field_support.inner_ip_version); | |
1847 | ||
1848 | if (ip_version_cap && match->mask->n_proto == htons(0xFFFF) && | |
1849 | (match->key->n_proto == htons(ETH_P_IP) || | |
1850 | match->key->n_proto == htons(ETH_P_IPV6))) { | |
1851 | MLX5_SET_TO_ONES(fte_match_set_lyr_2_4, headers_c, ip_version); | |
1852 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_version, | |
1853 | match->key->n_proto == htons(ETH_P_IP) ? 4 : 6); | |
1854 | } else { | |
1855 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, ethertype, | |
1856 | ntohs(match->mask->n_proto)); | |
1857 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, ethertype, | |
1858 | ntohs(match->key->n_proto)); | |
1859 | } | |
4a5d5d73 EB |
1860 | } |
1861 | ||
0d9f9647 | 1862 | u8 mlx5e_tc_get_ip_version(struct mlx5_flow_spec *spec, bool outer) |
a508728a VB |
1863 | { |
1864 | void *headers_v; | |
1865 | u16 ethertype; | |
1866 | u8 ip_version; | |
1867 | ||
1868 | if (outer) | |
1869 | headers_v = MLX5_ADDR_OF(fte_match_param, spec->match_value, outer_headers); | |
1870 | else | |
1871 | headers_v = MLX5_ADDR_OF(fte_match_param, spec->match_value, inner_headers); | |
1872 | ||
1873 | ip_version = MLX5_GET(fte_match_set_lyr_2_4, headers_v, ip_version); | |
1874 | /* Return ip_version converted from ethertype anyway */ | |
1875 | if (!ip_version) { | |
1876 | ethertype = MLX5_GET(fte_match_set_lyr_2_4, headers_v, ethertype); | |
1877 | if (ethertype == ETH_P_IP || ethertype == ETH_P_ARP) | |
1878 | ip_version = 4; | |
1879 | else if (ethertype == ETH_P_IPV6) | |
1880 | ip_version = 6; | |
1881 | } | |
1882 | return ip_version; | |
1883 | } | |
1884 | ||
bbd00f7e | 1885 | static int parse_tunnel_attr(struct mlx5e_priv *priv, |
0a7fcb78 | 1886 | struct mlx5e_tc_flow *flow, |
bbd00f7e | 1887 | struct mlx5_flow_spec *spec, |
f9e30088 | 1888 | struct flow_cls_offload *f, |
0a7fcb78 PB |
1889 | struct net_device *filter_dev, |
1890 | u8 *match_level, | |
1891 | bool *match_inner) | |
bbd00f7e | 1892 | { |
a508728a | 1893 | struct mlx5e_tc_tunnel *tunnel = mlx5e_get_tc_tun(filter_dev); |
0a7fcb78 | 1894 | struct mlx5_eswitch *esw = priv->mdev->priv.eswitch; |
e98bedf5 | 1895 | struct netlink_ext_ack *extack = f->common.extack; |
0a7fcb78 | 1896 | bool needs_mapping, sets_mapping; |
8f256622 | 1897 | int err; |
2e72eb43 | 1898 | |
0a7fcb78 PB |
1899 | if (!mlx5e_is_eswitch_flow(flow)) |
1900 | return -EOPNOTSUPP; | |
1901 | ||
c620b772 | 1902 | needs_mapping = !!flow->attr->chain; |
ee950e5d | 1903 | sets_mapping = flow_requires_tunnel_mapping(flow->attr->chain, f); |
0a7fcb78 PB |
1904 | *match_inner = !needs_mapping; |
1905 | ||
1906 | if ((needs_mapping || sets_mapping) && | |
636bb968 | 1907 | !mlx5_eswitch_reg_c1_loopback_enabled(esw)) { |
0a7fcb78 | 1908 | NL_SET_ERR_MSG(extack, |
636bb968 | 1909 | "Chains on tunnel devices isn't supported without register loopback support"); |
0a7fcb78 | 1910 | netdev_warn(priv->netdev, |
636bb968 | 1911 | "Chains on tunnel devices isn't supported without register loopback support"); |
0a7fcb78 | 1912 | return -EOPNOTSUPP; |
bbd00f7e HHZ |
1913 | } |
1914 | ||
c620b772 | 1915 | if (!flow->attr->chain) { |
0a7fcb78 PB |
1916 | err = mlx5e_tc_tun_parse(filter_dev, priv, spec, f, |
1917 | match_level); | |
1918 | if (err) { | |
e98bedf5 | 1919 | NL_SET_ERR_MSG_MOD(extack, |
0a7fcb78 PB |
1920 | "Failed to parse tunnel attributes"); |
1921 | netdev_warn(priv->netdev, | |
1922 | "Failed to parse tunnel attributes"); | |
1923 | return err; | |
e98bedf5 EB |
1924 | } |
1925 | ||
14e6b038 EC |
1926 | /* With mpls over udp we decapsulate using packet reformat |
1927 | * object | |
1928 | */ | |
1929 | if (!netif_is_bareudp(filter_dev)) | |
c620b772 | 1930 | flow->attr->action |= MLX5_FLOW_CONTEXT_ACTION_DECAP; |
a508728a VB |
1931 | err = mlx5e_tc_set_attr_rx_tun(flow, spec); |
1932 | if (err) | |
1933 | return err; | |
1934 | } else if (tunnel && tunnel->tunnel_type == MLX5E_TC_TUNNEL_TYPE_VXLAN) { | |
1935 | struct mlx5_flow_spec *tmp_spec; | |
1936 | ||
1937 | tmp_spec = kvzalloc(sizeof(*tmp_spec), GFP_KERNEL); | |
1938 | if (!tmp_spec) { | |
1939 | NL_SET_ERR_MSG_MOD(extack, "Failed to allocate memory for vxlan tmp spec"); | |
1940 | netdev_warn(priv->netdev, "Failed to allocate memory for vxlan tmp spec"); | |
1941 | return -ENOMEM; | |
1942 | } | |
1943 | memcpy(tmp_spec, spec, sizeof(*tmp_spec)); | |
1944 | ||
1945 | err = mlx5e_tc_tun_parse(filter_dev, priv, tmp_spec, f, match_level); | |
1946 | if (err) { | |
1947 | kvfree(tmp_spec); | |
1948 | NL_SET_ERR_MSG_MOD(extack, "Failed to parse tunnel attributes"); | |
1949 | netdev_warn(priv->netdev, "Failed to parse tunnel attributes"); | |
1950 | return err; | |
1951 | } | |
1952 | err = mlx5e_tc_set_attr_rx_tun(flow, tmp_spec); | |
1953 | kvfree(tmp_spec); | |
1954 | if (err) | |
1955 | return err; | |
bcef735c OG |
1956 | } |
1957 | ||
0a7fcb78 PB |
1958 | if (!needs_mapping && !sets_mapping) |
1959 | return 0; | |
bbd00f7e | 1960 | |
0a7fcb78 | 1961 | return mlx5e_get_flow_tunnel_id(priv, flow, f, filter_dev); |
bbd00f7e | 1962 | } |
bbd00f7e | 1963 | |
0a7fcb78 | 1964 | static void *get_match_inner_headers_criteria(struct mlx5_flow_spec *spec) |
8377629e | 1965 | { |
0a7fcb78 PB |
1966 | return MLX5_ADDR_OF(fte_match_param, spec->match_criteria, |
1967 | inner_headers); | |
bbd00f7e HHZ |
1968 | } |
1969 | ||
0a7fcb78 | 1970 | static void *get_match_inner_headers_value(struct mlx5_flow_spec *spec) |
8377629e | 1971 | { |
0a7fcb78 PB |
1972 | return MLX5_ADDR_OF(fte_match_param, spec->match_value, |
1973 | inner_headers); | |
1974 | } | |
1975 | ||
1976 | static void *get_match_outer_headers_criteria(struct mlx5_flow_spec *spec) | |
1977 | { | |
1978 | return MLX5_ADDR_OF(fte_match_param, spec->match_criteria, | |
1979 | outer_headers); | |
1980 | } | |
1981 | ||
1982 | static void *get_match_outer_headers_value(struct mlx5_flow_spec *spec) | |
1983 | { | |
1984 | return MLX5_ADDR_OF(fte_match_param, spec->match_value, | |
1985 | outer_headers); | |
8377629e EB |
1986 | } |
1987 | ||
1988 | static void *get_match_headers_value(u32 flags, | |
1989 | struct mlx5_flow_spec *spec) | |
1990 | { | |
1991 | return (flags & MLX5_FLOW_CONTEXT_ACTION_DECAP) ? | |
0a7fcb78 PB |
1992 | get_match_inner_headers_value(spec) : |
1993 | get_match_outer_headers_value(spec); | |
1994 | } | |
1995 | ||
1996 | static void *get_match_headers_criteria(u32 flags, | |
1997 | struct mlx5_flow_spec *spec) | |
1998 | { | |
1999 | return (flags & MLX5_FLOW_CONTEXT_ACTION_DECAP) ? | |
2000 | get_match_inner_headers_criteria(spec) : | |
2001 | get_match_outer_headers_criteria(spec); | |
8377629e EB |
2002 | } |
2003 | ||
6d65bc64 | 2004 | static int mlx5e_flower_parse_meta(struct net_device *filter_dev, |
2005 | struct flow_cls_offload *f) | |
2006 | { | |
2007 | struct flow_rule *rule = flow_cls_offload_flow_rule(f); | |
2008 | struct netlink_ext_ack *extack = f->common.extack; | |
2009 | struct net_device *ingress_dev; | |
2010 | struct flow_match_meta match; | |
2011 | ||
2012 | if (!flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_META)) | |
2013 | return 0; | |
2014 | ||
2015 | flow_rule_match_meta(rule, &match); | |
e3e0f9b2 | 2016 | if (!match.mask->ingress_ifindex) |
2017 | return 0; | |
2018 | ||
6d65bc64 | 2019 | if (match.mask->ingress_ifindex != 0xFFFFFFFF) { |
2020 | NL_SET_ERR_MSG_MOD(extack, "Unsupported ingress ifindex mask"); | |
a683012a | 2021 | return -EOPNOTSUPP; |
6d65bc64 | 2022 | } |
2023 | ||
2024 | ingress_dev = __dev_get_by_index(dev_net(filter_dev), | |
2025 | match.key->ingress_ifindex); | |
2026 | if (!ingress_dev) { | |
2027 | NL_SET_ERR_MSG_MOD(extack, | |
2028 | "Can't find the ingress port to match on"); | |
a683012a | 2029 | return -ENOENT; |
6d65bc64 | 2030 | } |
2031 | ||
2032 | if (ingress_dev != filter_dev) { | |
2033 | NL_SET_ERR_MSG_MOD(extack, | |
2034 | "Can't match on the ingress filter port"); | |
a683012a | 2035 | return -EOPNOTSUPP; |
6d65bc64 | 2036 | } |
2037 | ||
2038 | return 0; | |
2039 | } | |
2040 | ||
72046a91 EC |
2041 | static bool skip_key_basic(struct net_device *filter_dev, |
2042 | struct flow_cls_offload *f) | |
2043 | { | |
2044 | /* When doing mpls over udp decap, the user needs to provide | |
2045 | * MPLS_UC as the protocol in order to be able to match on mpls | |
2046 | * label fields. However, the actual ethertype is IP so we want to | |
2047 | * avoid matching on this, otherwise we'll fail the match. | |
2048 | */ | |
2049 | if (netif_is_bareudp(filter_dev) && f->common.chain_index == 0) | |
2050 | return true; | |
2051 | ||
2052 | return false; | |
2053 | } | |
2054 | ||
de0af0bf | 2055 | static int __parse_cls_flower(struct mlx5e_priv *priv, |
0a7fcb78 | 2056 | struct mlx5e_tc_flow *flow, |
de0af0bf | 2057 | struct mlx5_flow_spec *spec, |
f9e30088 | 2058 | struct flow_cls_offload *f, |
54c177ca | 2059 | struct net_device *filter_dev, |
93b3586e | 2060 | u8 *inner_match_level, u8 *outer_match_level) |
e3a2b7ed | 2061 | { |
e98bedf5 | 2062 | struct netlink_ext_ack *extack = f->common.extack; |
c5bb1730 MG |
2063 | void *headers_c = MLX5_ADDR_OF(fte_match_param, spec->match_criteria, |
2064 | outer_headers); | |
2065 | void *headers_v = MLX5_ADDR_OF(fte_match_param, spec->match_value, | |
2066 | outer_headers); | |
699e96dd JL |
2067 | void *misc_c = MLX5_ADDR_OF(fte_match_param, spec->match_criteria, |
2068 | misc_parameters); | |
2069 | void *misc_v = MLX5_ADDR_OF(fte_match_param, spec->match_value, | |
2070 | misc_parameters); | |
a3222a2d MD |
2071 | void *misc_c_3 = MLX5_ADDR_OF(fte_match_param, spec->match_criteria, |
2072 | misc_parameters_3); | |
2073 | void *misc_v_3 = MLX5_ADDR_OF(fte_match_param, spec->match_value, | |
2074 | misc_parameters_3); | |
f9e30088 | 2075 | struct flow_rule *rule = flow_cls_offload_flow_rule(f); |
8f256622 | 2076 | struct flow_dissector *dissector = rule->match.dissector; |
afe93f71 | 2077 | enum fs_flow_table_type fs_type; |
e3a2b7ed AV |
2078 | u16 addr_type = 0; |
2079 | u8 ip_proto = 0; | |
93b3586e | 2080 | u8 *match_level; |
6d65bc64 | 2081 | int err; |
e3a2b7ed | 2082 | |
afe93f71 | 2083 | fs_type = mlx5e_is_eswitch_flow(flow) ? FS_FT_FDB : FS_FT_NIC_RX; |
93b3586e | 2084 | match_level = outer_match_level; |
de0af0bf | 2085 | |
8f256622 | 2086 | if (dissector->used_keys & |
3d144578 VB |
2087 | ~(BIT(FLOW_DISSECTOR_KEY_META) | |
2088 | BIT(FLOW_DISSECTOR_KEY_CONTROL) | | |
e3a2b7ed AV |
2089 | BIT(FLOW_DISSECTOR_KEY_BASIC) | |
2090 | BIT(FLOW_DISSECTOR_KEY_ETH_ADDRS) | | |
095b6cfd | 2091 | BIT(FLOW_DISSECTOR_KEY_VLAN) | |
699e96dd | 2092 | BIT(FLOW_DISSECTOR_KEY_CVLAN) | |
e3a2b7ed AV |
2093 | BIT(FLOW_DISSECTOR_KEY_IPV4_ADDRS) | |
2094 | BIT(FLOW_DISSECTOR_KEY_IPV6_ADDRS) | | |
bbd00f7e HHZ |
2095 | BIT(FLOW_DISSECTOR_KEY_PORTS) | |
2096 | BIT(FLOW_DISSECTOR_KEY_ENC_KEYID) | | |
2097 | BIT(FLOW_DISSECTOR_KEY_ENC_IPV4_ADDRS) | | |
2098 | BIT(FLOW_DISSECTOR_KEY_ENC_IPV6_ADDRS) | | |
2099 | BIT(FLOW_DISSECTOR_KEY_ENC_PORTS) | | |
e77834ec | 2100 | BIT(FLOW_DISSECTOR_KEY_ENC_CONTROL) | |
fd7da28b | 2101 | BIT(FLOW_DISSECTOR_KEY_TCP) | |
bcef735c | 2102 | BIT(FLOW_DISSECTOR_KEY_IP) | |
4c3844d9 | 2103 | BIT(FLOW_DISSECTOR_KEY_CT) | |
9272e3df | 2104 | BIT(FLOW_DISSECTOR_KEY_ENC_IP) | |
72046a91 | 2105 | BIT(FLOW_DISSECTOR_KEY_ENC_OPTS) | |
a3222a2d | 2106 | BIT(FLOW_DISSECTOR_KEY_ICMP) | |
72046a91 | 2107 | BIT(FLOW_DISSECTOR_KEY_MPLS))) { |
e98bedf5 | 2108 | NL_SET_ERR_MSG_MOD(extack, "Unsupported key"); |
48470a90 MD |
2109 | netdev_dbg(priv->netdev, "Unsupported key used: 0x%x\n", |
2110 | dissector->used_keys); | |
e3a2b7ed AV |
2111 | return -EOPNOTSUPP; |
2112 | } | |
2113 | ||
075973c7 | 2114 | if (mlx5e_get_tc_tun(filter_dev)) { |
0a7fcb78 | 2115 | bool match_inner = false; |
bbd00f7e | 2116 | |
0a7fcb78 PB |
2117 | err = parse_tunnel_attr(priv, flow, spec, f, filter_dev, |
2118 | outer_match_level, &match_inner); | |
2119 | if (err) | |
2120 | return err; | |
2121 | ||
2122 | if (match_inner) { | |
2123 | /* header pointers should point to the inner headers | |
2124 | * if the packet was decapsulated already. | |
2125 | * outer headers are set by parse_tunnel_attr. | |
2126 | */ | |
2127 | match_level = inner_match_level; | |
2128 | headers_c = get_match_inner_headers_criteria(spec); | |
2129 | headers_v = get_match_inner_headers_value(spec); | |
2130 | } | |
bbd00f7e HHZ |
2131 | } |
2132 | ||
6d65bc64 | 2133 | err = mlx5e_flower_parse_meta(filter_dev, f); |
2134 | if (err) | |
2135 | return err; | |
2136 | ||
72046a91 EC |
2137 | if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_BASIC) && |
2138 | !skip_key_basic(filter_dev, f)) { | |
8f256622 PNA |
2139 | struct flow_match_basic match; |
2140 | ||
2141 | flow_rule_match_basic(rule, &match); | |
fca53304 EB |
2142 | mlx5e_tc_set_ethertype(priv->mdev, &match, |
2143 | match_level == outer_match_level, | |
2144 | headers_c, headers_v); | |
e3a2b7ed | 2145 | |
8f256622 | 2146 | if (match.mask->n_proto) |
d708f902 | 2147 | *match_level = MLX5_MATCH_L2; |
e3a2b7ed | 2148 | } |
35a605db EB |
2149 | if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_VLAN) || |
2150 | is_vlan_dev(filter_dev)) { | |
2151 | struct flow_dissector_key_vlan filter_dev_mask; | |
2152 | struct flow_dissector_key_vlan filter_dev_key; | |
8f256622 PNA |
2153 | struct flow_match_vlan match; |
2154 | ||
35a605db EB |
2155 | if (is_vlan_dev(filter_dev)) { |
2156 | match.key = &filter_dev_key; | |
2157 | match.key->vlan_id = vlan_dev_vlan_id(filter_dev); | |
2158 | match.key->vlan_tpid = vlan_dev_vlan_proto(filter_dev); | |
2159 | match.key->vlan_priority = 0; | |
2160 | match.mask = &filter_dev_mask; | |
2161 | memset(match.mask, 0xff, sizeof(*match.mask)); | |
2162 | match.mask->vlan_priority = 0; | |
2163 | } else { | |
2164 | flow_rule_match_vlan(rule, &match); | |
2165 | } | |
8f256622 PNA |
2166 | if (match.mask->vlan_id || |
2167 | match.mask->vlan_priority || | |
2168 | match.mask->vlan_tpid) { | |
2169 | if (match.key->vlan_tpid == htons(ETH_P_8021AD)) { | |
699e96dd JL |
2170 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, |
2171 | svlan_tag, 1); | |
2172 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, | |
2173 | svlan_tag, 1); | |
2174 | } else { | |
2175 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, | |
2176 | cvlan_tag, 1); | |
2177 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, | |
2178 | cvlan_tag, 1); | |
2179 | } | |
095b6cfd | 2180 | |
8f256622 PNA |
2181 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, first_vid, |
2182 | match.mask->vlan_id); | |
2183 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, first_vid, | |
2184 | match.key->vlan_id); | |
358d79a4 | 2185 | |
8f256622 PNA |
2186 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, first_prio, |
2187 | match.mask->vlan_priority); | |
2188 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, first_prio, | |
2189 | match.key->vlan_priority); | |
54782900 | 2190 | |
d708f902 | 2191 | *match_level = MLX5_MATCH_L2; |
54782900 | 2192 | } |
d3a80bb5 | 2193 | } else if (*match_level != MLX5_MATCH_NONE) { |
fc603294 MB |
2194 | /* cvlan_tag enabled in match criteria and |
2195 | * disabled in match value means both S & C tags | |
2196 | * don't exist (untagged of both) | |
2197 | */ | |
cee26487 | 2198 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, cvlan_tag, 1); |
d3a80bb5 | 2199 | *match_level = MLX5_MATCH_L2; |
54782900 OG |
2200 | } |
2201 | ||
8f256622 PNA |
2202 | if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_CVLAN)) { |
2203 | struct flow_match_vlan match; | |
2204 | ||
12d5cbf8 | 2205 | flow_rule_match_cvlan(rule, &match); |
8f256622 PNA |
2206 | if (match.mask->vlan_id || |
2207 | match.mask->vlan_priority || | |
2208 | match.mask->vlan_tpid) { | |
afe93f71 RD |
2209 | if (!MLX5_CAP_FLOWTABLE_TYPE(priv->mdev, ft_field_support.outer_second_vid, |
2210 | fs_type)) { | |
2211 | NL_SET_ERR_MSG_MOD(extack, | |
2212 | "Matching on CVLAN is not supported"); | |
2213 | return -EOPNOTSUPP; | |
2214 | } | |
2215 | ||
8f256622 | 2216 | if (match.key->vlan_tpid == htons(ETH_P_8021AD)) { |
699e96dd JL |
2217 | MLX5_SET(fte_match_set_misc, misc_c, |
2218 | outer_second_svlan_tag, 1); | |
2219 | MLX5_SET(fte_match_set_misc, misc_v, | |
2220 | outer_second_svlan_tag, 1); | |
2221 | } else { | |
2222 | MLX5_SET(fte_match_set_misc, misc_c, | |
2223 | outer_second_cvlan_tag, 1); | |
2224 | MLX5_SET(fte_match_set_misc, misc_v, | |
2225 | outer_second_cvlan_tag, 1); | |
2226 | } | |
2227 | ||
2228 | MLX5_SET(fte_match_set_misc, misc_c, outer_second_vid, | |
8f256622 | 2229 | match.mask->vlan_id); |
699e96dd | 2230 | MLX5_SET(fte_match_set_misc, misc_v, outer_second_vid, |
8f256622 | 2231 | match.key->vlan_id); |
699e96dd | 2232 | MLX5_SET(fte_match_set_misc, misc_c, outer_second_prio, |
8f256622 | 2233 | match.mask->vlan_priority); |
699e96dd | 2234 | MLX5_SET(fte_match_set_misc, misc_v, outer_second_prio, |
8f256622 | 2235 | match.key->vlan_priority); |
699e96dd JL |
2236 | |
2237 | *match_level = MLX5_MATCH_L2; | |
0faddfe6 | 2238 | spec->match_criteria_enable |= MLX5_MATCH_MISC_PARAMETERS; |
699e96dd JL |
2239 | } |
2240 | } | |
2241 | ||
8f256622 PNA |
2242 | if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_ETH_ADDRS)) { |
2243 | struct flow_match_eth_addrs match; | |
54782900 | 2244 | |
8f256622 | 2245 | flow_rule_match_eth_addrs(rule, &match); |
d3a80bb5 OG |
2246 | ether_addr_copy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_c, |
2247 | dmac_47_16), | |
8f256622 | 2248 | match.mask->dst); |
d3a80bb5 OG |
2249 | ether_addr_copy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v, |
2250 | dmac_47_16), | |
8f256622 | 2251 | match.key->dst); |
d3a80bb5 OG |
2252 | |
2253 | ether_addr_copy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_c, | |
2254 | smac_47_16), | |
8f256622 | 2255 | match.mask->src); |
d3a80bb5 OG |
2256 | ether_addr_copy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v, |
2257 | smac_47_16), | |
8f256622 | 2258 | match.key->src); |
d3a80bb5 | 2259 | |
8f256622 PNA |
2260 | if (!is_zero_ether_addr(match.mask->src) || |
2261 | !is_zero_ether_addr(match.mask->dst)) | |
d708f902 | 2262 | *match_level = MLX5_MATCH_L2; |
54782900 OG |
2263 | } |
2264 | ||
8f256622 PNA |
2265 | if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_CONTROL)) { |
2266 | struct flow_match_control match; | |
54782900 | 2267 | |
8f256622 PNA |
2268 | flow_rule_match_control(rule, &match); |
2269 | addr_type = match.key->addr_type; | |
54782900 OG |
2270 | |
2271 | /* the HW doesn't support frag first/later */ | |
8f256622 | 2272 | if (match.mask->flags & FLOW_DIS_FIRST_FRAG) |
54782900 OG |
2273 | return -EOPNOTSUPP; |
2274 | ||
8f256622 | 2275 | if (match.mask->flags & FLOW_DIS_IS_FRAGMENT) { |
54782900 OG |
2276 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, frag, 1); |
2277 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, frag, | |
8f256622 | 2278 | match.key->flags & FLOW_DIS_IS_FRAGMENT); |
54782900 OG |
2279 | |
2280 | /* the HW doesn't need L3 inline to match on frag=no */ | |
8f256622 | 2281 | if (!(match.key->flags & FLOW_DIS_IS_FRAGMENT)) |
83621b7d | 2282 | *match_level = MLX5_MATCH_L2; |
54782900 OG |
2283 | /* *** L2 attributes parsing up to here *** */ |
2284 | else | |
83621b7d | 2285 | *match_level = MLX5_MATCH_L3; |
095b6cfd OG |
2286 | } |
2287 | } | |
2288 | ||
8f256622 PNA |
2289 | if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_BASIC)) { |
2290 | struct flow_match_basic match; | |
2291 | ||
2292 | flow_rule_match_basic(rule, &match); | |
2293 | ip_proto = match.key->ip_proto; | |
54782900 OG |
2294 | |
2295 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, ip_protocol, | |
8f256622 | 2296 | match.mask->ip_proto); |
54782900 | 2297 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, |
8f256622 | 2298 | match.key->ip_proto); |
54782900 | 2299 | |
8f256622 | 2300 | if (match.mask->ip_proto) |
d708f902 | 2301 | *match_level = MLX5_MATCH_L3; |
54782900 OG |
2302 | } |
2303 | ||
e3a2b7ed | 2304 | if (addr_type == FLOW_DISSECTOR_KEY_IPV4_ADDRS) { |
8f256622 | 2305 | struct flow_match_ipv4_addrs match; |
e3a2b7ed | 2306 | |
8f256622 | 2307 | flow_rule_match_ipv4_addrs(rule, &match); |
e3a2b7ed AV |
2308 | memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_c, |
2309 | src_ipv4_src_ipv6.ipv4_layout.ipv4), | |
8f256622 | 2310 | &match.mask->src, sizeof(match.mask->src)); |
e3a2b7ed AV |
2311 | memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v, |
2312 | src_ipv4_src_ipv6.ipv4_layout.ipv4), | |
8f256622 | 2313 | &match.key->src, sizeof(match.key->src)); |
e3a2b7ed AV |
2314 | memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_c, |
2315 | dst_ipv4_dst_ipv6.ipv4_layout.ipv4), | |
8f256622 | 2316 | &match.mask->dst, sizeof(match.mask->dst)); |
e3a2b7ed AV |
2317 | memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v, |
2318 | dst_ipv4_dst_ipv6.ipv4_layout.ipv4), | |
8f256622 | 2319 | &match.key->dst, sizeof(match.key->dst)); |
de0af0bf | 2320 | |
8f256622 | 2321 | if (match.mask->src || match.mask->dst) |
d708f902 | 2322 | *match_level = MLX5_MATCH_L3; |
e3a2b7ed AV |
2323 | } |
2324 | ||
2325 | if (addr_type == FLOW_DISSECTOR_KEY_IPV6_ADDRS) { | |
8f256622 | 2326 | struct flow_match_ipv6_addrs match; |
e3a2b7ed | 2327 | |
8f256622 | 2328 | flow_rule_match_ipv6_addrs(rule, &match); |
e3a2b7ed AV |
2329 | memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_c, |
2330 | src_ipv4_src_ipv6.ipv6_layout.ipv6), | |
8f256622 | 2331 | &match.mask->src, sizeof(match.mask->src)); |
e3a2b7ed AV |
2332 | memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v, |
2333 | src_ipv4_src_ipv6.ipv6_layout.ipv6), | |
8f256622 | 2334 | &match.key->src, sizeof(match.key->src)); |
e3a2b7ed AV |
2335 | |
2336 | memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_c, | |
2337 | dst_ipv4_dst_ipv6.ipv6_layout.ipv6), | |
8f256622 | 2338 | &match.mask->dst, sizeof(match.mask->dst)); |
e3a2b7ed AV |
2339 | memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v, |
2340 | dst_ipv4_dst_ipv6.ipv6_layout.ipv6), | |
8f256622 | 2341 | &match.key->dst, sizeof(match.key->dst)); |
de0af0bf | 2342 | |
8f256622 PNA |
2343 | if (ipv6_addr_type(&match.mask->src) != IPV6_ADDR_ANY || |
2344 | ipv6_addr_type(&match.mask->dst) != IPV6_ADDR_ANY) | |
d708f902 | 2345 | *match_level = MLX5_MATCH_L3; |
e3a2b7ed AV |
2346 | } |
2347 | ||
8f256622 PNA |
2348 | if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_IP)) { |
2349 | struct flow_match_ip match; | |
1f97a526 | 2350 | |
8f256622 PNA |
2351 | flow_rule_match_ip(rule, &match); |
2352 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, ip_ecn, | |
2353 | match.mask->tos & 0x3); | |
2354 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ecn, | |
2355 | match.key->tos & 0x3); | |
1f97a526 | 2356 | |
8f256622 PNA |
2357 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, ip_dscp, |
2358 | match.mask->tos >> 2); | |
2359 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_dscp, | |
2360 | match.key->tos >> 2); | |
1f97a526 | 2361 | |
8f256622 PNA |
2362 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, ttl_hoplimit, |
2363 | match.mask->ttl); | |
2364 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, ttl_hoplimit, | |
2365 | match.key->ttl); | |
1f97a526 | 2366 | |
8f256622 | 2367 | if (match.mask->ttl && |
a8ade55f | 2368 | !MLX5_CAP_ESW_FLOWTABLE_FDB(priv->mdev, |
e98bedf5 EB |
2369 | ft_field_support.outer_ipv4_ttl)) { |
2370 | NL_SET_ERR_MSG_MOD(extack, | |
2371 | "Matching on TTL is not supported"); | |
1f97a526 | 2372 | return -EOPNOTSUPP; |
e98bedf5 | 2373 | } |
a8ade55f | 2374 | |
8f256622 | 2375 | if (match.mask->tos || match.mask->ttl) |
d708f902 | 2376 | *match_level = MLX5_MATCH_L3; |
1f97a526 OG |
2377 | } |
2378 | ||
54782900 OG |
2379 | /* *** L3 attributes parsing up to here *** */ |
2380 | ||
8f256622 PNA |
2381 | if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_PORTS)) { |
2382 | struct flow_match_ports match; | |
2383 | ||
2384 | flow_rule_match_ports(rule, &match); | |
e3a2b7ed AV |
2385 | switch (ip_proto) { |
2386 | case IPPROTO_TCP: | |
2387 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, | |
8f256622 | 2388 | tcp_sport, ntohs(match.mask->src)); |
e3a2b7ed | 2389 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, |
8f256622 | 2390 | tcp_sport, ntohs(match.key->src)); |
e3a2b7ed AV |
2391 | |
2392 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, | |
8f256622 | 2393 | tcp_dport, ntohs(match.mask->dst)); |
e3a2b7ed | 2394 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, |
8f256622 | 2395 | tcp_dport, ntohs(match.key->dst)); |
e3a2b7ed AV |
2396 | break; |
2397 | ||
2398 | case IPPROTO_UDP: | |
2399 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, | |
8f256622 | 2400 | udp_sport, ntohs(match.mask->src)); |
e3a2b7ed | 2401 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, |
8f256622 | 2402 | udp_sport, ntohs(match.key->src)); |
e3a2b7ed AV |
2403 | |
2404 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, | |
8f256622 | 2405 | udp_dport, ntohs(match.mask->dst)); |
e3a2b7ed | 2406 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, |
8f256622 | 2407 | udp_dport, ntohs(match.key->dst)); |
e3a2b7ed AV |
2408 | break; |
2409 | default: | |
e98bedf5 EB |
2410 | NL_SET_ERR_MSG_MOD(extack, |
2411 | "Only UDP and TCP transports are supported for L4 matching"); | |
e3a2b7ed AV |
2412 | netdev_err(priv->netdev, |
2413 | "Only UDP and TCP transport are supported\n"); | |
2414 | return -EINVAL; | |
2415 | } | |
de0af0bf | 2416 | |
8f256622 | 2417 | if (match.mask->src || match.mask->dst) |
d708f902 | 2418 | *match_level = MLX5_MATCH_L4; |
e3a2b7ed AV |
2419 | } |
2420 | ||
8f256622 PNA |
2421 | if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_TCP)) { |
2422 | struct flow_match_tcp match; | |
e77834ec | 2423 | |
8f256622 | 2424 | flow_rule_match_tcp(rule, &match); |
e77834ec | 2425 | MLX5_SET(fte_match_set_lyr_2_4, headers_c, tcp_flags, |
8f256622 | 2426 | ntohs(match.mask->flags)); |
e77834ec | 2427 | MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_flags, |
8f256622 | 2428 | ntohs(match.key->flags)); |
e77834ec | 2429 | |
8f256622 | 2430 | if (match.mask->flags) |
d708f902 | 2431 | *match_level = MLX5_MATCH_L4; |
e77834ec | 2432 | } |
a3222a2d MD |
2433 | if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_ICMP)) { |
2434 | struct flow_match_icmp match; | |
e77834ec | 2435 | |
a3222a2d MD |
2436 | flow_rule_match_icmp(rule, &match); |
2437 | switch (ip_proto) { | |
2438 | case IPPROTO_ICMP: | |
2439 | if (!(MLX5_CAP_GEN(priv->mdev, flex_parser_protocols) & | |
2440 | MLX5_FLEX_PROTO_ICMP)) | |
2441 | return -EOPNOTSUPP; | |
2442 | MLX5_SET(fte_match_set_misc3, misc_c_3, icmp_type, | |
2443 | match.mask->type); | |
2444 | MLX5_SET(fte_match_set_misc3, misc_v_3, icmp_type, | |
2445 | match.key->type); | |
2446 | MLX5_SET(fte_match_set_misc3, misc_c_3, icmp_code, | |
2447 | match.mask->code); | |
2448 | MLX5_SET(fte_match_set_misc3, misc_v_3, icmp_code, | |
2449 | match.key->code); | |
2450 | break; | |
2451 | case IPPROTO_ICMPV6: | |
2452 | if (!(MLX5_CAP_GEN(priv->mdev, flex_parser_protocols) & | |
2453 | MLX5_FLEX_PROTO_ICMPV6)) | |
2454 | return -EOPNOTSUPP; | |
2455 | MLX5_SET(fte_match_set_misc3, misc_c_3, icmpv6_type, | |
2456 | match.mask->type); | |
2457 | MLX5_SET(fte_match_set_misc3, misc_v_3, icmpv6_type, | |
2458 | match.key->type); | |
2459 | MLX5_SET(fte_match_set_misc3, misc_c_3, icmpv6_code, | |
2460 | match.mask->code); | |
2461 | MLX5_SET(fte_match_set_misc3, misc_v_3, icmpv6_code, | |
2462 | match.key->code); | |
2463 | break; | |
2464 | default: | |
2465 | NL_SET_ERR_MSG_MOD(extack, | |
2466 | "Code and type matching only with ICMP and ICMPv6"); | |
2467 | netdev_err(priv->netdev, | |
2468 | "Code and type matching only with ICMP and ICMPv6\n"); | |
2469 | return -EINVAL; | |
2470 | } | |
2471 | if (match.mask->code || match.mask->type) { | |
2472 | *match_level = MLX5_MATCH_L4; | |
2473 | spec->match_criteria_enable |= MLX5_MATCH_MISC_PARAMETERS_3; | |
2474 | } | |
2475 | } | |
39c538d6 | 2476 | /* Currently supported only for MPLS over UDP */ |
7d6c86e3 AH |
2477 | if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_MPLS) && |
2478 | !netif_is_bareudp(filter_dev)) { | |
2479 | NL_SET_ERR_MSG_MOD(extack, | |
2480 | "Matching on MPLS is supported only for MPLS over UDP"); | |
2481 | netdev_err(priv->netdev, | |
2482 | "Matching on MPLS is supported only for MPLS over UDP\n"); | |
2483 | return -EOPNOTSUPP; | |
2484 | } | |
2485 | ||
e3a2b7ed AV |
2486 | return 0; |
2487 | } | |
2488 | ||
de0af0bf | 2489 | static int parse_cls_flower(struct mlx5e_priv *priv, |
65ba8fb7 | 2490 | struct mlx5e_tc_flow *flow, |
de0af0bf | 2491 | struct mlx5_flow_spec *spec, |
f9e30088 | 2492 | struct flow_cls_offload *f, |
54c177ca | 2493 | struct net_device *filter_dev) |
de0af0bf | 2494 | { |
93b3586e | 2495 | u8 inner_match_level, outer_match_level, non_tunnel_match_level; |
e98bedf5 | 2496 | struct netlink_ext_ack *extack = f->common.extack; |
de0af0bf RD |
2497 | struct mlx5_core_dev *dev = priv->mdev; |
2498 | struct mlx5_eswitch *esw = dev->priv.eswitch; | |
1d447a39 SM |
2499 | struct mlx5e_rep_priv *rpriv = priv->ppriv; |
2500 | struct mlx5_eswitch_rep *rep; | |
226f2ca3 | 2501 | bool is_eswitch_flow; |
de0af0bf RD |
2502 | int err; |
2503 | ||
93b3586e HN |
2504 | inner_match_level = MLX5_MATCH_NONE; |
2505 | outer_match_level = MLX5_MATCH_NONE; | |
2506 | ||
0a7fcb78 PB |
2507 | err = __parse_cls_flower(priv, flow, spec, f, filter_dev, |
2508 | &inner_match_level, &outer_match_level); | |
93b3586e HN |
2509 | non_tunnel_match_level = (inner_match_level == MLX5_MATCH_NONE) ? |
2510 | outer_match_level : inner_match_level; | |
de0af0bf | 2511 | |
226f2ca3 VB |
2512 | is_eswitch_flow = mlx5e_is_eswitch_flow(flow); |
2513 | if (!err && is_eswitch_flow) { | |
1d447a39 | 2514 | rep = rpriv->rep; |
b05af6aa | 2515 | if (rep->vport != MLX5_VPORT_UPLINK && |
1d447a39 | 2516 | (esw->offloads.inline_mode != MLX5_INLINE_MODE_NONE && |
93b3586e | 2517 | esw->offloads.inline_mode < non_tunnel_match_level)) { |
e98bedf5 EB |
2518 | NL_SET_ERR_MSG_MOD(extack, |
2519 | "Flow is not offloaded due to min inline setting"); | |
de0af0bf RD |
2520 | netdev_warn(priv->netdev, |
2521 | "Flow is not offloaded due to min inline setting, required %d actual %d\n", | |
93b3586e | 2522 | non_tunnel_match_level, esw->offloads.inline_mode); |
de0af0bf RD |
2523 | return -EOPNOTSUPP; |
2524 | } | |
2525 | } | |
2526 | ||
c620b772 AL |
2527 | flow->attr->inner_match_level = inner_match_level; |
2528 | flow->attr->outer_match_level = outer_match_level; | |
2529 | ||
38aa51c1 | 2530 | |
de0af0bf RD |
2531 | return err; |
2532 | } | |
2533 | ||
d79b6df6 OG |
2534 | struct pedit_headers { |
2535 | struct ethhdr eth; | |
0eb69bb9 | 2536 | struct vlan_hdr vlan; |
d79b6df6 OG |
2537 | struct iphdr ip4; |
2538 | struct ipv6hdr ip6; | |
2539 | struct tcphdr tcp; | |
2540 | struct udphdr udp; | |
2541 | }; | |
2542 | ||
c500c86b PNA |
2543 | struct pedit_headers_action { |
2544 | struct pedit_headers vals; | |
2545 | struct pedit_headers masks; | |
2546 | u32 pedits; | |
2547 | }; | |
2548 | ||
d79b6df6 | 2549 | static int pedit_header_offsets[] = { |
73867881 PNA |
2550 | [FLOW_ACT_MANGLE_HDR_TYPE_ETH] = offsetof(struct pedit_headers, eth), |
2551 | [FLOW_ACT_MANGLE_HDR_TYPE_IP4] = offsetof(struct pedit_headers, ip4), | |
2552 | [FLOW_ACT_MANGLE_HDR_TYPE_IP6] = offsetof(struct pedit_headers, ip6), | |
2553 | [FLOW_ACT_MANGLE_HDR_TYPE_TCP] = offsetof(struct pedit_headers, tcp), | |
2554 | [FLOW_ACT_MANGLE_HDR_TYPE_UDP] = offsetof(struct pedit_headers, udp), | |
d79b6df6 OG |
2555 | }; |
2556 | ||
2557 | #define pedit_header(_ph, _htype) ((void *)(_ph) + pedit_header_offsets[_htype]) | |
2558 | ||
2559 | static int set_pedit_val(u8 hdr_type, u32 mask, u32 val, u32 offset, | |
c500c86b | 2560 | struct pedit_headers_action *hdrs) |
d79b6df6 OG |
2561 | { |
2562 | u32 *curr_pmask, *curr_pval; | |
2563 | ||
c500c86b PNA |
2564 | curr_pmask = (u32 *)(pedit_header(&hdrs->masks, hdr_type) + offset); |
2565 | curr_pval = (u32 *)(pedit_header(&hdrs->vals, hdr_type) + offset); | |
d79b6df6 OG |
2566 | |
2567 | if (*curr_pmask & mask) /* disallow acting twice on the same location */ | |
2568 | goto out_err; | |
2569 | ||
2570 | *curr_pmask |= mask; | |
2571 | *curr_pval |= (val & mask); | |
2572 | ||
2573 | return 0; | |
2574 | ||
2575 | out_err: | |
2576 | return -EOPNOTSUPP; | |
2577 | } | |
2578 | ||
2579 | struct mlx5_fields { | |
2580 | u8 field; | |
88f30bbc DL |
2581 | u8 field_bsize; |
2582 | u32 field_mask; | |
d79b6df6 | 2583 | u32 offset; |
27c11b6b | 2584 | u32 match_offset; |
d79b6df6 OG |
2585 | }; |
2586 | ||
88f30bbc DL |
2587 | #define OFFLOAD(fw_field, field_bsize, field_mask, field, off, match_field) \ |
2588 | {MLX5_ACTION_IN_FIELD_OUT_ ## fw_field, field_bsize, field_mask, \ | |
27c11b6b EB |
2589 | offsetof(struct pedit_headers, field) + (off), \ |
2590 | MLX5_BYTE_OFF(fte_match_set_lyr_2_4, match_field)} | |
2591 | ||
2ef86872 EB |
2592 | /* masked values are the same and there are no rewrites that do not have a |
2593 | * match. | |
2594 | */ | |
2595 | #define SAME_VAL_MASK(type, valp, maskp, matchvalp, matchmaskp) ({ \ | |
2596 | type matchmaskx = *(type *)(matchmaskp); \ | |
2597 | type matchvalx = *(type *)(matchvalp); \ | |
2598 | type maskx = *(type *)(maskp); \ | |
2599 | type valx = *(type *)(valp); \ | |
2600 | \ | |
2601 | (valx & maskx) == (matchvalx & matchmaskx) && !(maskx & (maskx ^ \ | |
2602 | matchmaskx)); \ | |
2603 | }) | |
2604 | ||
27c11b6b | 2605 | static bool cmp_val_mask(void *valp, void *maskp, void *matchvalp, |
88f30bbc | 2606 | void *matchmaskp, u8 bsize) |
27c11b6b EB |
2607 | { |
2608 | bool same = false; | |
2609 | ||
88f30bbc DL |
2610 | switch (bsize) { |
2611 | case 8: | |
2ef86872 | 2612 | same = SAME_VAL_MASK(u8, valp, maskp, matchvalp, matchmaskp); |
27c11b6b | 2613 | break; |
88f30bbc | 2614 | case 16: |
2ef86872 | 2615 | same = SAME_VAL_MASK(u16, valp, maskp, matchvalp, matchmaskp); |
27c11b6b | 2616 | break; |
88f30bbc | 2617 | case 32: |
2ef86872 | 2618 | same = SAME_VAL_MASK(u32, valp, maskp, matchvalp, matchmaskp); |
27c11b6b EB |
2619 | break; |
2620 | } | |
2621 | ||
2622 | return same; | |
2623 | } | |
a8e4f0c4 | 2624 | |
d79b6df6 | 2625 | static struct mlx5_fields fields[] = { |
88f30bbc DL |
2626 | OFFLOAD(DMAC_47_16, 32, U32_MAX, eth.h_dest[0], 0, dmac_47_16), |
2627 | OFFLOAD(DMAC_15_0, 16, U16_MAX, eth.h_dest[4], 0, dmac_15_0), | |
2628 | OFFLOAD(SMAC_47_16, 32, U32_MAX, eth.h_source[0], 0, smac_47_16), | |
2629 | OFFLOAD(SMAC_15_0, 16, U16_MAX, eth.h_source[4], 0, smac_15_0), | |
2630 | OFFLOAD(ETHERTYPE, 16, U16_MAX, eth.h_proto, 0, ethertype), | |
2631 | OFFLOAD(FIRST_VID, 16, U16_MAX, vlan.h_vlan_TCI, 0, first_vid), | |
2632 | ||
ab9341b5 | 2633 | OFFLOAD(IP_DSCP, 8, 0xfc, ip4.tos, 0, ip_dscp), |
88f30bbc DL |
2634 | OFFLOAD(IP_TTL, 8, U8_MAX, ip4.ttl, 0, ttl_hoplimit), |
2635 | OFFLOAD(SIPV4, 32, U32_MAX, ip4.saddr, 0, src_ipv4_src_ipv6.ipv4_layout.ipv4), | |
2636 | OFFLOAD(DIPV4, 32, U32_MAX, ip4.daddr, 0, dst_ipv4_dst_ipv6.ipv4_layout.ipv4), | |
2637 | ||
2638 | OFFLOAD(SIPV6_127_96, 32, U32_MAX, ip6.saddr.s6_addr32[0], 0, | |
27c11b6b | 2639 | src_ipv4_src_ipv6.ipv6_layout.ipv6[0]), |
88f30bbc | 2640 | OFFLOAD(SIPV6_95_64, 32, U32_MAX, ip6.saddr.s6_addr32[1], 0, |
27c11b6b | 2641 | src_ipv4_src_ipv6.ipv6_layout.ipv6[4]), |
88f30bbc | 2642 | OFFLOAD(SIPV6_63_32, 32, U32_MAX, ip6.saddr.s6_addr32[2], 0, |
27c11b6b | 2643 | src_ipv4_src_ipv6.ipv6_layout.ipv6[8]), |
88f30bbc | 2644 | OFFLOAD(SIPV6_31_0, 32, U32_MAX, ip6.saddr.s6_addr32[3], 0, |
27c11b6b | 2645 | src_ipv4_src_ipv6.ipv6_layout.ipv6[12]), |
88f30bbc | 2646 | OFFLOAD(DIPV6_127_96, 32, U32_MAX, ip6.daddr.s6_addr32[0], 0, |
27c11b6b | 2647 | dst_ipv4_dst_ipv6.ipv6_layout.ipv6[0]), |
88f30bbc | 2648 | OFFLOAD(DIPV6_95_64, 32, U32_MAX, ip6.daddr.s6_addr32[1], 0, |
27c11b6b | 2649 | dst_ipv4_dst_ipv6.ipv6_layout.ipv6[4]), |
88f30bbc | 2650 | OFFLOAD(DIPV6_63_32, 32, U32_MAX, ip6.daddr.s6_addr32[2], 0, |
27c11b6b | 2651 | dst_ipv4_dst_ipv6.ipv6_layout.ipv6[8]), |
88f30bbc | 2652 | OFFLOAD(DIPV6_31_0, 32, U32_MAX, ip6.daddr.s6_addr32[3], 0, |
27c11b6b | 2653 | dst_ipv4_dst_ipv6.ipv6_layout.ipv6[12]), |
88f30bbc | 2654 | OFFLOAD(IPV6_HOPLIMIT, 8, U8_MAX, ip6.hop_limit, 0, ttl_hoplimit), |
748cde9a | 2655 | OFFLOAD(IP_DSCP, 16, 0xc00f, ip6, 0, ip_dscp), |
27c11b6b | 2656 | |
88f30bbc DL |
2657 | OFFLOAD(TCP_SPORT, 16, U16_MAX, tcp.source, 0, tcp_sport), |
2658 | OFFLOAD(TCP_DPORT, 16, U16_MAX, tcp.dest, 0, tcp_dport), | |
2659 | /* in linux iphdr tcp_flags is 8 bits long */ | |
2660 | OFFLOAD(TCP_FLAGS, 8, U8_MAX, tcp.ack_seq, 5, tcp_flags), | |
27c11b6b | 2661 | |
88f30bbc DL |
2662 | OFFLOAD(UDP_SPORT, 16, U16_MAX, udp.source, 0, udp_sport), |
2663 | OFFLOAD(UDP_DPORT, 16, U16_MAX, udp.dest, 0, udp_dport), | |
d79b6df6 OG |
2664 | }; |
2665 | ||
82198d8b MD |
2666 | static unsigned long mask_to_le(unsigned long mask, int size) |
2667 | { | |
2668 | __be32 mask_be32; | |
2669 | __be16 mask_be16; | |
2670 | ||
2671 | if (size == 32) { | |
2672 | mask_be32 = (__force __be32)(mask); | |
2673 | mask = (__force unsigned long)cpu_to_le32(be32_to_cpu(mask_be32)); | |
2674 | } else if (size == 16) { | |
2675 | mask_be32 = (__force __be32)(mask); | |
2676 | mask_be16 = *(__be16 *)&mask_be32; | |
2677 | mask = (__force unsigned long)cpu_to_le16(be16_to_cpu(mask_be16)); | |
2678 | } | |
2679 | ||
2680 | return mask; | |
2681 | } | |
6ae4a6a5 PB |
2682 | static int offload_pedit_fields(struct mlx5e_priv *priv, |
2683 | int namespace, | |
2684 | struct pedit_headers_action *hdrs, | |
e98bedf5 | 2685 | struct mlx5e_tc_flow_parse_attr *parse_attr, |
27c11b6b | 2686 | u32 *action_flags, |
e98bedf5 | 2687 | struct netlink_ext_ack *extack) |
d79b6df6 OG |
2688 | { |
2689 | struct pedit_headers *set_masks, *add_masks, *set_vals, *add_vals; | |
6ae4a6a5 | 2690 | int i, action_size, first, last, next_z; |
88f30bbc DL |
2691 | void *headers_c, *headers_v, *action, *vals_p; |
2692 | u32 *s_masks_p, *a_masks_p, s_mask, a_mask; | |
6ae4a6a5 | 2693 | struct mlx5e_tc_mod_hdr_acts *mod_acts; |
d79b6df6 | 2694 | struct mlx5_fields *f; |
82198d8b | 2695 | unsigned long mask, field_mask; |
6ae4a6a5 | 2696 | int err; |
88f30bbc DL |
2697 | u8 cmd; |
2698 | ||
6ae4a6a5 | 2699 | mod_acts = &parse_attr->mod_hdr_acts; |
88f30bbc DL |
2700 | headers_c = get_match_headers_criteria(*action_flags, &parse_attr->spec); |
2701 | headers_v = get_match_headers_value(*action_flags, &parse_attr->spec); | |
d79b6df6 | 2702 | |
73867881 PNA |
2703 | set_masks = &hdrs[0].masks; |
2704 | add_masks = &hdrs[1].masks; | |
2705 | set_vals = &hdrs[0].vals; | |
2706 | add_vals = &hdrs[1].vals; | |
d79b6df6 | 2707 | |
d65dbedf | 2708 | action_size = MLX5_UN_SZ_BYTES(set_add_copy_action_in_auto); |
d79b6df6 OG |
2709 | |
2710 | for (i = 0; i < ARRAY_SIZE(fields); i++) { | |
27c11b6b EB |
2711 | bool skip; |
2712 | ||
d79b6df6 OG |
2713 | f = &fields[i]; |
2714 | /* avoid seeing bits set from previous iterations */ | |
e3ca4e05 OG |
2715 | s_mask = 0; |
2716 | a_mask = 0; | |
d79b6df6 OG |
2717 | |
2718 | s_masks_p = (void *)set_masks + f->offset; | |
2719 | a_masks_p = (void *)add_masks + f->offset; | |
2720 | ||
88f30bbc DL |
2721 | s_mask = *s_masks_p & f->field_mask; |
2722 | a_mask = *a_masks_p & f->field_mask; | |
d79b6df6 OG |
2723 | |
2724 | if (!s_mask && !a_mask) /* nothing to offload here */ | |
2725 | continue; | |
2726 | ||
2727 | if (s_mask && a_mask) { | |
e98bedf5 EB |
2728 | NL_SET_ERR_MSG_MOD(extack, |
2729 | "can't set and add to the same HW field"); | |
61b6a6c3 CH |
2730 | netdev_warn(priv->netdev, |
2731 | "mlx5: can't set and add to the same HW field (%x)\n", | |
2732 | f->field); | |
d79b6df6 OG |
2733 | return -EOPNOTSUPP; |
2734 | } | |
2735 | ||
27c11b6b | 2736 | skip = false; |
d79b6df6 | 2737 | if (s_mask) { |
27c11b6b EB |
2738 | void *match_mask = headers_c + f->match_offset; |
2739 | void *match_val = headers_v + f->match_offset; | |
2740 | ||
d79b6df6 OG |
2741 | cmd = MLX5_ACTION_TYPE_SET; |
2742 | mask = s_mask; | |
2743 | vals_p = (void *)set_vals + f->offset; | |
27c11b6b EB |
2744 | /* don't rewrite if we have a match on the same value */ |
2745 | if (cmp_val_mask(vals_p, s_masks_p, match_val, | |
88f30bbc | 2746 | match_mask, f->field_bsize)) |
27c11b6b | 2747 | skip = true; |
d79b6df6 | 2748 | /* clear to denote we consumed this field */ |
88f30bbc | 2749 | *s_masks_p &= ~f->field_mask; |
d79b6df6 OG |
2750 | } else { |
2751 | cmd = MLX5_ACTION_TYPE_ADD; | |
2752 | mask = a_mask; | |
2753 | vals_p = (void *)add_vals + f->offset; | |
27c11b6b | 2754 | /* add 0 is no change */ |
88f30bbc | 2755 | if ((*(u32 *)vals_p & f->field_mask) == 0) |
27c11b6b | 2756 | skip = true; |
d79b6df6 | 2757 | /* clear to denote we consumed this field */ |
88f30bbc | 2758 | *a_masks_p &= ~f->field_mask; |
d79b6df6 | 2759 | } |
27c11b6b EB |
2760 | if (skip) |
2761 | continue; | |
d79b6df6 | 2762 | |
82198d8b | 2763 | mask = mask_to_le(mask, f->field_bsize); |
2b64beba | 2764 | |
88f30bbc DL |
2765 | first = find_first_bit(&mask, f->field_bsize); |
2766 | next_z = find_next_zero_bit(&mask, f->field_bsize, first); | |
2767 | last = find_last_bit(&mask, f->field_bsize); | |
2b64beba | 2768 | if (first < next_z && next_z < last) { |
e98bedf5 EB |
2769 | NL_SET_ERR_MSG_MOD(extack, |
2770 | "rewrite of few sub-fields isn't supported"); | |
61b6a6c3 CH |
2771 | netdev_warn(priv->netdev, |
2772 | "mlx5: rewrite of few sub-fields (mask %lx) isn't offloaded\n", | |
2773 | mask); | |
d79b6df6 OG |
2774 | return -EOPNOTSUPP; |
2775 | } | |
2776 | ||
6ae4a6a5 PB |
2777 | err = alloc_mod_hdr_actions(priv->mdev, namespace, mod_acts); |
2778 | if (err) { | |
2779 | NL_SET_ERR_MSG_MOD(extack, | |
2780 | "too many pedit actions, can't offload"); | |
2781 | mlx5_core_warn(priv->mdev, | |
2782 | "mlx5: parsed %d pedit actions, can't do more\n", | |
2783 | mod_acts->num_actions); | |
2784 | return err; | |
2785 | } | |
2786 | ||
2787 | action = mod_acts->actions + | |
2788 | (mod_acts->num_actions * action_size); | |
d79b6df6 OG |
2789 | MLX5_SET(set_action_in, action, action_type, cmd); |
2790 | MLX5_SET(set_action_in, action, field, f->field); | |
2791 | ||
2792 | if (cmd == MLX5_ACTION_TYPE_SET) { | |
88f30bbc DL |
2793 | int start; |
2794 | ||
82198d8b MD |
2795 | field_mask = mask_to_le(f->field_mask, f->field_bsize); |
2796 | ||
88f30bbc | 2797 | /* if field is bit sized it can start not from first bit */ |
82198d8b | 2798 | start = find_first_bit(&field_mask, f->field_bsize); |
88f30bbc DL |
2799 | |
2800 | MLX5_SET(set_action_in, action, offset, first - start); | |
d79b6df6 | 2801 | /* length is num of bits to be written, zero means length of 32 */ |
2b64beba | 2802 | MLX5_SET(set_action_in, action, length, (last - first + 1)); |
d79b6df6 OG |
2803 | } |
2804 | ||
88f30bbc | 2805 | if (f->field_bsize == 32) |
2b64beba | 2806 | MLX5_SET(set_action_in, action, data, ntohl(*(__be32 *)vals_p) >> first); |
88f30bbc | 2807 | else if (f->field_bsize == 16) |
2b64beba | 2808 | MLX5_SET(set_action_in, action, data, ntohs(*(__be16 *)vals_p) >> first); |
88f30bbc | 2809 | else if (f->field_bsize == 8) |
2b64beba | 2810 | MLX5_SET(set_action_in, action, data, *(u8 *)vals_p >> first); |
d79b6df6 | 2811 | |
6ae4a6a5 | 2812 | ++mod_acts->num_actions; |
d79b6df6 OG |
2813 | } |
2814 | ||
d79b6df6 OG |
2815 | return 0; |
2816 | } | |
2817 | ||
2cc1cb1d TZ |
2818 | static int mlx5e_flow_namespace_max_modify_action(struct mlx5_core_dev *mdev, |
2819 | int namespace) | |
2820 | { | |
2821 | if (namespace == MLX5_FLOW_NAMESPACE_FDB) /* FDB offloading */ | |
2822 | return MLX5_CAP_ESW_FLOWTABLE_FDB(mdev, max_modify_header_actions); | |
2823 | else /* namespace is MLX5_FLOW_NAMESPACE_KERNEL - NIC offloading */ | |
2824 | return MLX5_CAP_FLOWTABLE_NIC_RX(mdev, max_modify_header_actions); | |
2825 | } | |
2826 | ||
6ae4a6a5 PB |
2827 | int alloc_mod_hdr_actions(struct mlx5_core_dev *mdev, |
2828 | int namespace, | |
2829 | struct mlx5e_tc_mod_hdr_acts *mod_hdr_acts) | |
d79b6df6 | 2830 | { |
6ae4a6a5 PB |
2831 | int action_size, new_num_actions, max_hw_actions; |
2832 | size_t new_sz, old_sz; | |
2833 | void *ret; | |
d79b6df6 | 2834 | |
6ae4a6a5 PB |
2835 | if (mod_hdr_acts->num_actions < mod_hdr_acts->max_actions) |
2836 | return 0; | |
d79b6df6 | 2837 | |
d65dbedf | 2838 | action_size = MLX5_UN_SZ_BYTES(set_add_copy_action_in_auto); |
d79b6df6 | 2839 | |
6ae4a6a5 PB |
2840 | max_hw_actions = mlx5e_flow_namespace_max_modify_action(mdev, |
2841 | namespace); | |
2842 | new_num_actions = min(max_hw_actions, | |
2843 | mod_hdr_acts->actions ? | |
2844 | mod_hdr_acts->max_actions * 2 : 1); | |
2845 | if (mod_hdr_acts->max_actions == new_num_actions) | |
2846 | return -ENOSPC; | |
2847 | ||
2848 | new_sz = action_size * new_num_actions; | |
2849 | old_sz = mod_hdr_acts->max_actions * action_size; | |
2850 | ret = krealloc(mod_hdr_acts->actions, new_sz, GFP_KERNEL); | |
2851 | if (!ret) | |
d79b6df6 OG |
2852 | return -ENOMEM; |
2853 | ||
6ae4a6a5 PB |
2854 | memset(ret + old_sz, 0, new_sz - old_sz); |
2855 | mod_hdr_acts->actions = ret; | |
2856 | mod_hdr_acts->max_actions = new_num_actions; | |
2857 | ||
d79b6df6 OG |
2858 | return 0; |
2859 | } | |
2860 | ||
6ae4a6a5 PB |
2861 | void dealloc_mod_hdr_actions(struct mlx5e_tc_mod_hdr_acts *mod_hdr_acts) |
2862 | { | |
2863 | kfree(mod_hdr_acts->actions); | |
2864 | mod_hdr_acts->actions = NULL; | |
2865 | mod_hdr_acts->num_actions = 0; | |
2866 | mod_hdr_acts->max_actions = 0; | |
2867 | } | |
2868 | ||
d79b6df6 OG |
2869 | static const struct pedit_headers zero_masks = {}; |
2870 | ||
582234b4 EC |
2871 | static int |
2872 | parse_pedit_to_modify_hdr(struct mlx5e_priv *priv, | |
2873 | const struct flow_action_entry *act, int namespace, | |
2874 | struct mlx5e_tc_flow_parse_attr *parse_attr, | |
2875 | struct pedit_headers_action *hdrs, | |
2876 | struct netlink_ext_ack *extack) | |
d79b6df6 | 2877 | { |
73867881 PNA |
2878 | u8 cmd = (act->id == FLOW_ACTION_MANGLE) ? 0 : 1; |
2879 | int err = -EOPNOTSUPP; | |
d79b6df6 | 2880 | u32 mask, val, offset; |
73867881 | 2881 | u8 htype; |
d79b6df6 | 2882 | |
73867881 PNA |
2883 | htype = act->mangle.htype; |
2884 | err = -EOPNOTSUPP; /* can't be all optimistic */ | |
d79b6df6 | 2885 | |
73867881 PNA |
2886 | if (htype == FLOW_ACT_MANGLE_UNSPEC) { |
2887 | NL_SET_ERR_MSG_MOD(extack, "legacy pedit isn't offloaded"); | |
2888 | goto out_err; | |
2889 | } | |
d79b6df6 | 2890 | |
2cc1cb1d TZ |
2891 | if (!mlx5e_flow_namespace_max_modify_action(priv->mdev, namespace)) { |
2892 | NL_SET_ERR_MSG_MOD(extack, | |
2893 | "The pedit offload action is not supported"); | |
2894 | goto out_err; | |
2895 | } | |
2896 | ||
73867881 PNA |
2897 | mask = act->mangle.mask; |
2898 | val = act->mangle.val; | |
2899 | offset = act->mangle.offset; | |
d79b6df6 | 2900 | |
73867881 PNA |
2901 | err = set_pedit_val(htype, ~mask, val, offset, &hdrs[cmd]); |
2902 | if (err) | |
2903 | goto out_err; | |
c500c86b | 2904 | |
73867881 | 2905 | hdrs[cmd].pedits++; |
d79b6df6 | 2906 | |
c500c86b PNA |
2907 | return 0; |
2908 | out_err: | |
2909 | return err; | |
2910 | } | |
2911 | ||
582234b4 EC |
2912 | static int |
2913 | parse_pedit_to_reformat(struct mlx5e_priv *priv, | |
2914 | const struct flow_action_entry *act, | |
2915 | struct mlx5e_tc_flow_parse_attr *parse_attr, | |
2916 | struct netlink_ext_ack *extack) | |
2917 | { | |
2918 | u32 mask, val, offset; | |
2919 | u32 *p; | |
2920 | ||
2921 | if (act->id != FLOW_ACTION_MANGLE) | |
2922 | return -EOPNOTSUPP; | |
2923 | ||
2924 | if (act->mangle.htype != FLOW_ACT_MANGLE_HDR_TYPE_ETH) { | |
2925 | NL_SET_ERR_MSG_MOD(extack, "Only Ethernet modification is supported"); | |
2926 | return -EOPNOTSUPP; | |
2927 | } | |
2928 | ||
2929 | mask = ~act->mangle.mask; | |
2930 | val = act->mangle.val; | |
2931 | offset = act->mangle.offset; | |
2932 | p = (u32 *)&parse_attr->eth; | |
2933 | *(p + (offset >> 2)) |= (val & mask); | |
2934 | ||
2935 | return 0; | |
2936 | } | |
2937 | ||
2938 | static int parse_tc_pedit_action(struct mlx5e_priv *priv, | |
2939 | const struct flow_action_entry *act, int namespace, | |
2940 | struct mlx5e_tc_flow_parse_attr *parse_attr, | |
2941 | struct pedit_headers_action *hdrs, | |
2942 | struct mlx5e_tc_flow *flow, | |
2943 | struct netlink_ext_ack *extack) | |
2944 | { | |
2945 | if (flow && flow_flag_test(flow, L3_TO_L2_DECAP)) | |
2946 | return parse_pedit_to_reformat(priv, act, parse_attr, extack); | |
2947 | ||
2948 | return parse_pedit_to_modify_hdr(priv, act, namespace, | |
2949 | parse_attr, hdrs, extack); | |
2950 | } | |
2951 | ||
c500c86b PNA |
2952 | static int alloc_tc_pedit_action(struct mlx5e_priv *priv, int namespace, |
2953 | struct mlx5e_tc_flow_parse_attr *parse_attr, | |
2954 | struct pedit_headers_action *hdrs, | |
27c11b6b | 2955 | u32 *action_flags, |
c500c86b PNA |
2956 | struct netlink_ext_ack *extack) |
2957 | { | |
2958 | struct pedit_headers *cmd_masks; | |
2959 | int err; | |
2960 | u8 cmd; | |
2961 | ||
6ae4a6a5 PB |
2962 | err = offload_pedit_fields(priv, namespace, hdrs, parse_attr, |
2963 | action_flags, extack); | |
d79b6df6 OG |
2964 | if (err < 0) |
2965 | goto out_dealloc_parsed_actions; | |
2966 | ||
2967 | for (cmd = 0; cmd < __PEDIT_CMD_MAX; cmd++) { | |
c500c86b | 2968 | cmd_masks = &hdrs[cmd].masks; |
d79b6df6 | 2969 | if (memcmp(cmd_masks, &zero_masks, sizeof(zero_masks))) { |
e98bedf5 EB |
2970 | NL_SET_ERR_MSG_MOD(extack, |
2971 | "attempt to offload an unsupported field"); | |
b3a433de | 2972 | netdev_warn(priv->netdev, "attempt to offload an unsupported field (cmd %d)\n", cmd); |
d79b6df6 OG |
2973 | print_hex_dump(KERN_WARNING, "mask: ", DUMP_PREFIX_ADDRESS, |
2974 | 16, 1, cmd_masks, sizeof(zero_masks), true); | |
2975 | err = -EOPNOTSUPP; | |
2976 | goto out_dealloc_parsed_actions; | |
2977 | } | |
2978 | } | |
2979 | ||
2980 | return 0; | |
2981 | ||
2982 | out_dealloc_parsed_actions: | |
6ae4a6a5 | 2983 | dealloc_mod_hdr_actions(&parse_attr->mod_hdr_acts); |
d79b6df6 OG |
2984 | return err; |
2985 | } | |
2986 | ||
e98bedf5 EB |
2987 | static bool csum_offload_supported(struct mlx5e_priv *priv, |
2988 | u32 action, | |
2989 | u32 update_flags, | |
2990 | struct netlink_ext_ack *extack) | |
26c02749 OG |
2991 | { |
2992 | u32 prot_flags = TCA_CSUM_UPDATE_FLAG_IPV4HDR | TCA_CSUM_UPDATE_FLAG_TCP | | |
2993 | TCA_CSUM_UPDATE_FLAG_UDP; | |
2994 | ||
2995 | /* The HW recalcs checksums only if re-writing headers */ | |
2996 | if (!(action & MLX5_FLOW_CONTEXT_ACTION_MOD_HDR)) { | |
e98bedf5 EB |
2997 | NL_SET_ERR_MSG_MOD(extack, |
2998 | "TC csum action is only offloaded with pedit"); | |
26c02749 OG |
2999 | netdev_warn(priv->netdev, |
3000 | "TC csum action is only offloaded with pedit\n"); | |
3001 | return false; | |
3002 | } | |
3003 | ||
3004 | if (update_flags & ~prot_flags) { | |
e98bedf5 EB |
3005 | NL_SET_ERR_MSG_MOD(extack, |
3006 | "can't offload TC csum action for some header/s"); | |
26c02749 OG |
3007 | netdev_warn(priv->netdev, |
3008 | "can't offload TC csum action for some header/s - flags %#x\n", | |
3009 | update_flags); | |
3010 | return false; | |
3011 | } | |
3012 | ||
3013 | return true; | |
3014 | } | |
3015 | ||
8998576b DL |
3016 | struct ip_ttl_word { |
3017 | __u8 ttl; | |
3018 | __u8 protocol; | |
3019 | __sum16 check; | |
3020 | }; | |
3021 | ||
3022 | struct ipv6_hoplimit_word { | |
3023 | __be16 payload_len; | |
3024 | __u8 nexthdr; | |
3025 | __u8 hop_limit; | |
3026 | }; | |
3027 | ||
1836d780 RD |
3028 | static bool |
3029 | is_action_keys_supported(const struct flow_action_entry *act, bool ct_flow, | |
3030 | bool *modify_ip_header, bool *modify_tuple, | |
3031 | struct netlink_ext_ack *extack) | |
8998576b DL |
3032 | { |
3033 | u32 mask, offset; | |
3034 | u8 htype; | |
3035 | ||
3036 | htype = act->mangle.htype; | |
3037 | offset = act->mangle.offset; | |
3038 | mask = ~act->mangle.mask; | |
3039 | /* For IPv4 & IPv6 header check 4 byte word, | |
3040 | * to determine that modified fields | |
3041 | * are NOT ttl & hop_limit only. | |
3042 | */ | |
3043 | if (htype == FLOW_ACT_MANGLE_HDR_TYPE_IP4) { | |
3044 | struct ip_ttl_word *ttl_word = | |
3045 | (struct ip_ttl_word *)&mask; | |
3046 | ||
3047 | if (offset != offsetof(struct iphdr, ttl) || | |
3048 | ttl_word->protocol || | |
3049 | ttl_word->check) { | |
4c3844d9 PB |
3050 | *modify_ip_header = true; |
3051 | } | |
3052 | ||
7e36feeb PB |
3053 | if (offset >= offsetof(struct iphdr, saddr)) |
3054 | *modify_tuple = true; | |
3055 | ||
3056 | if (ct_flow && *modify_tuple) { | |
4c3844d9 PB |
3057 | NL_SET_ERR_MSG_MOD(extack, |
3058 | "can't offload re-write of ipv4 address with action ct"); | |
1836d780 | 3059 | return false; |
8998576b DL |
3060 | } |
3061 | } else if (htype == FLOW_ACT_MANGLE_HDR_TYPE_IP6) { | |
3062 | struct ipv6_hoplimit_word *hoplimit_word = | |
3063 | (struct ipv6_hoplimit_word *)&mask; | |
3064 | ||
3065 | if (offset != offsetof(struct ipv6hdr, payload_len) || | |
3066 | hoplimit_word->payload_len || | |
3067 | hoplimit_word->nexthdr) { | |
4c3844d9 PB |
3068 | *modify_ip_header = true; |
3069 | } | |
3070 | ||
7e36feeb PB |
3071 | if (ct_flow && offset >= offsetof(struct ipv6hdr, saddr)) |
3072 | *modify_tuple = true; | |
3073 | ||
3074 | if (ct_flow && *modify_tuple) { | |
4c3844d9 PB |
3075 | NL_SET_ERR_MSG_MOD(extack, |
3076 | "can't offload re-write of ipv6 address with action ct"); | |
1836d780 | 3077 | return false; |
8998576b | 3078 | } |
7e36feeb PB |
3079 | } else if (htype == FLOW_ACT_MANGLE_HDR_TYPE_TCP || |
3080 | htype == FLOW_ACT_MANGLE_HDR_TYPE_UDP) { | |
3081 | *modify_tuple = true; | |
3082 | if (ct_flow) { | |
3083 | NL_SET_ERR_MSG_MOD(extack, | |
3084 | "can't offload re-write of transport header ports with action ct"); | |
1836d780 | 3085 | return false; |
7e36feeb | 3086 | } |
8998576b | 3087 | } |
4c3844d9 | 3088 | |
1836d780 | 3089 | return true; |
8998576b DL |
3090 | } |
3091 | ||
96b5b458 DC |
3092 | static bool modify_tuple_supported(bool modify_tuple, bool ct_clear, |
3093 | bool ct_flow, struct netlink_ext_ack *extack, | |
3094 | struct mlx5e_priv *priv, | |
3095 | struct mlx5_flow_spec *spec) | |
3096 | { | |
3097 | if (!modify_tuple || ct_clear) | |
3098 | return true; | |
3099 | ||
3100 | if (ct_flow) { | |
3101 | NL_SET_ERR_MSG_MOD(extack, | |
3102 | "can't offload tuple modification with non-clear ct()"); | |
3103 | netdev_info(priv->netdev, | |
3104 | "can't offload tuple modification with non-clear ct()"); | |
3105 | return false; | |
3106 | } | |
3107 | ||
3108 | /* Add ct_state=-trk match so it will be offloaded for non ct flows | |
3109 | * (or after clear action), as otherwise, since the tuple is changed, | |
3110 | * we can't restore ct state | |
3111 | */ | |
3112 | if (mlx5_tc_ct_add_no_trk_match(spec)) { | |
3113 | NL_SET_ERR_MSG_MOD(extack, | |
3114 | "can't offload tuple modification with ct matches and no ct(clear) action"); | |
3115 | netdev_info(priv->netdev, | |
3116 | "can't offload tuple modification with ct matches and no ct(clear) action"); | |
3117 | return false; | |
3118 | } | |
3119 | ||
3120 | return true; | |
3121 | } | |
3122 | ||
3d486ec4 OS |
3123 | static bool modify_header_match_supported(struct mlx5e_priv *priv, |
3124 | struct mlx5_flow_spec *spec, | |
73867881 | 3125 | struct flow_action *flow_action, |
4c3844d9 | 3126 | u32 actions, bool ct_flow, |
7e36feeb | 3127 | bool ct_clear, |
e98bedf5 | 3128 | struct netlink_ext_ack *extack) |
bdd66ac0 | 3129 | { |
73867881 | 3130 | const struct flow_action_entry *act; |
7e36feeb | 3131 | bool modify_ip_header, modify_tuple; |
fca53304 | 3132 | void *headers_c; |
bdd66ac0 OG |
3133 | void *headers_v; |
3134 | u16 ethertype; | |
8998576b | 3135 | u8 ip_proto; |
1836d780 | 3136 | int i; |
bdd66ac0 | 3137 | |
fca53304 | 3138 | headers_c = get_match_headers_criteria(actions, spec); |
8377629e | 3139 | headers_v = get_match_headers_value(actions, spec); |
bdd66ac0 OG |
3140 | ethertype = MLX5_GET(fte_match_set_lyr_2_4, headers_v, ethertype); |
3141 | ||
3142 | /* for non-IP we only re-write MACs, so we're okay */ | |
fca53304 EB |
3143 | if (MLX5_GET(fte_match_set_lyr_2_4, headers_c, ip_version) == 0 && |
3144 | ethertype != ETH_P_IP && ethertype != ETH_P_IPV6) | |
bdd66ac0 OG |
3145 | goto out_ok; |
3146 | ||
3147 | modify_ip_header = false; | |
7e36feeb | 3148 | modify_tuple = false; |
73867881 PNA |
3149 | flow_action_for_each(i, act, flow_action) { |
3150 | if (act->id != FLOW_ACTION_MANGLE && | |
3151 | act->id != FLOW_ACTION_ADD) | |
bdd66ac0 OG |
3152 | continue; |
3153 | ||
1836d780 RD |
3154 | if (!is_action_keys_supported(act, ct_flow, |
3155 | &modify_ip_header, | |
3156 | &modify_tuple, extack)) | |
3157 | return false; | |
bdd66ac0 OG |
3158 | } |
3159 | ||
96b5b458 DC |
3160 | if (!modify_tuple_supported(modify_tuple, ct_clear, ct_flow, extack, |
3161 | priv, spec)) | |
7e36feeb | 3162 | return false; |
7e36feeb | 3163 | |
bdd66ac0 | 3164 | ip_proto = MLX5_GET(fte_match_set_lyr_2_4, headers_v, ip_protocol); |
1ccef350 JL |
3165 | if (modify_ip_header && ip_proto != IPPROTO_TCP && |
3166 | ip_proto != IPPROTO_UDP && ip_proto != IPPROTO_ICMP) { | |
e98bedf5 EB |
3167 | NL_SET_ERR_MSG_MOD(extack, |
3168 | "can't offload re-write of non TCP/UDP"); | |
3d486ec4 OS |
3169 | netdev_info(priv->netdev, "can't offload re-write of ip proto %d\n", |
3170 | ip_proto); | |
bdd66ac0 OG |
3171 | return false; |
3172 | } | |
3173 | ||
3174 | out_ok: | |
3175 | return true; | |
3176 | } | |
3177 | ||
3178 | static bool actions_match_supported(struct mlx5e_priv *priv, | |
73867881 | 3179 | struct flow_action *flow_action, |
bdd66ac0 | 3180 | struct mlx5e_tc_flow_parse_attr *parse_attr, |
e98bedf5 EB |
3181 | struct mlx5e_tc_flow *flow, |
3182 | struct netlink_ext_ack *extack) | |
bdd66ac0 | 3183 | { |
a7c119bd | 3184 | bool ct_flow = false, ct_clear = false; |
bdd66ac0 OG |
3185 | u32 actions; |
3186 | ||
c620b772 AL |
3187 | ct_clear = flow->attr->ct_attr.ct_action & |
3188 | TCA_CT_ACT_CLEAR; | |
3189 | ct_flow = flow_flag_test(flow, CT) && !ct_clear; | |
3190 | actions = flow->attr->action; | |
3191 | ||
4c3844d9 | 3192 | if (mlx5e_is_eswitch_flow(flow)) { |
69e2916e PB |
3193 | if (flow->attr->esw_attr->split_count && ct_flow && |
3194 | !MLX5_CAP_GEN(flow->attr->esw_attr->in_mdev, reg_c_preserve)) { | |
4c3844d9 PB |
3195 | /* All registers used by ct are cleared when using |
3196 | * split rules. | |
3197 | */ | |
3198 | NL_SET_ERR_MSG_MOD(extack, | |
3199 | "Can't offload mirroring with action ct"); | |
49397b80 | 3200 | return false; |
4c3844d9 | 3201 | } |
4c3844d9 | 3202 | } |
bdd66ac0 OG |
3203 | |
3204 | if (actions & MLX5_FLOW_CONTEXT_ACTION_MOD_HDR) | |
3d486ec4 | 3205 | return modify_header_match_supported(priv, &parse_attr->spec, |
a655fe9f | 3206 | flow_action, actions, |
7e36feeb PB |
3207 | ct_flow, ct_clear, |
3208 | extack); | |
bdd66ac0 OG |
3209 | |
3210 | return true; | |
3211 | } | |
3212 | ||
32134847 MD |
3213 | static bool same_port_devs(struct mlx5e_priv *priv, struct mlx5e_priv *peer_priv) |
3214 | { | |
3215 | return priv->mdev == peer_priv->mdev; | |
3216 | } | |
3217 | ||
5c65c564 OG |
3218 | static bool same_hw_devs(struct mlx5e_priv *priv, struct mlx5e_priv *peer_priv) |
3219 | { | |
3220 | struct mlx5_core_dev *fmdev, *pmdev; | |
816f6706 | 3221 | u64 fsystem_guid, psystem_guid; |
5c65c564 OG |
3222 | |
3223 | fmdev = priv->mdev; | |
3224 | pmdev = peer_priv->mdev; | |
3225 | ||
59c9d35e AH |
3226 | fsystem_guid = mlx5_query_nic_system_image_guid(fmdev); |
3227 | psystem_guid = mlx5_query_nic_system_image_guid(pmdev); | |
5c65c564 | 3228 | |
816f6706 | 3229 | return (fsystem_guid == psystem_guid); |
5c65c564 OG |
3230 | } |
3231 | ||
bb569657 AL |
3232 | static bool same_vf_reps(struct mlx5e_priv *priv, |
3233 | struct net_device *out_dev) | |
3234 | { | |
3235 | return mlx5e_eswitch_vf_rep(priv->netdev) && | |
3236 | priv->netdev == out_dev; | |
3237 | } | |
3238 | ||
bdc837ee EB |
3239 | static int add_vlan_rewrite_action(struct mlx5e_priv *priv, int namespace, |
3240 | const struct flow_action_entry *act, | |
3241 | struct mlx5e_tc_flow_parse_attr *parse_attr, | |
3242 | struct pedit_headers_action *hdrs, | |
3243 | u32 *action, struct netlink_ext_ack *extack) | |
3244 | { | |
3245 | u16 mask16 = VLAN_VID_MASK; | |
3246 | u16 val16 = act->vlan.vid & VLAN_VID_MASK; | |
3247 | const struct flow_action_entry pedit_act = { | |
3248 | .id = FLOW_ACTION_MANGLE, | |
3249 | .mangle.htype = FLOW_ACT_MANGLE_HDR_TYPE_ETH, | |
3250 | .mangle.offset = offsetof(struct vlan_ethhdr, h_vlan_TCI), | |
3251 | .mangle.mask = ~(u32)be16_to_cpu(*(__be16 *)&mask16), | |
3252 | .mangle.val = (u32)be16_to_cpu(*(__be16 *)&val16), | |
3253 | }; | |
6fca9d1e | 3254 | u8 match_prio_mask, match_prio_val; |
bf2f3bca | 3255 | void *headers_c, *headers_v; |
bdc837ee EB |
3256 | int err; |
3257 | ||
bf2f3bca EB |
3258 | headers_c = get_match_headers_criteria(*action, &parse_attr->spec); |
3259 | headers_v = get_match_headers_value(*action, &parse_attr->spec); | |
3260 | ||
3261 | if (!(MLX5_GET(fte_match_set_lyr_2_4, headers_c, cvlan_tag) && | |
3262 | MLX5_GET(fte_match_set_lyr_2_4, headers_v, cvlan_tag))) { | |
3263 | NL_SET_ERR_MSG_MOD(extack, | |
3264 | "VLAN rewrite action must have VLAN protocol match"); | |
3265 | return -EOPNOTSUPP; | |
3266 | } | |
3267 | ||
6fca9d1e EB |
3268 | match_prio_mask = MLX5_GET(fte_match_set_lyr_2_4, headers_c, first_prio); |
3269 | match_prio_val = MLX5_GET(fte_match_set_lyr_2_4, headers_v, first_prio); | |
3270 | if (act->vlan.prio != (match_prio_val & match_prio_mask)) { | |
3271 | NL_SET_ERR_MSG_MOD(extack, | |
3272 | "Changing VLAN prio is not supported"); | |
bdc837ee EB |
3273 | return -EOPNOTSUPP; |
3274 | } | |
3275 | ||
582234b4 | 3276 | err = parse_tc_pedit_action(priv, &pedit_act, namespace, parse_attr, hdrs, NULL, extack); |
bdc837ee EB |
3277 | *action |= MLX5_FLOW_CONTEXT_ACTION_MOD_HDR; |
3278 | ||
3279 | return err; | |
3280 | } | |
3281 | ||
0bac1194 EB |
3282 | static int |
3283 | add_vlan_prio_tag_rewrite_action(struct mlx5e_priv *priv, | |
3284 | struct mlx5e_tc_flow_parse_attr *parse_attr, | |
3285 | struct pedit_headers_action *hdrs, | |
3286 | u32 *action, struct netlink_ext_ack *extack) | |
3287 | { | |
3288 | const struct flow_action_entry prio_tag_act = { | |
3289 | .vlan.vid = 0, | |
3290 | .vlan.prio = | |
3291 | MLX5_GET(fte_match_set_lyr_2_4, | |
3292 | get_match_headers_value(*action, | |
3293 | &parse_attr->spec), | |
3294 | first_prio) & | |
3295 | MLX5_GET(fte_match_set_lyr_2_4, | |
3296 | get_match_headers_criteria(*action, | |
3297 | &parse_attr->spec), | |
3298 | first_prio), | |
3299 | }; | |
3300 | ||
3301 | return add_vlan_rewrite_action(priv, MLX5_FLOW_NAMESPACE_FDB, | |
3302 | &prio_tag_act, parse_attr, hdrs, action, | |
3303 | extack); | |
3304 | } | |
3305 | ||
c7569097 AL |
3306 | static int validate_goto_chain(struct mlx5e_priv *priv, |
3307 | struct mlx5e_tc_flow *flow, | |
3308 | const struct flow_action_entry *act, | |
3309 | u32 actions, | |
3310 | struct netlink_ext_ack *extack) | |
3311 | { | |
3312 | bool is_esw = mlx5e_is_eswitch_flow(flow); | |
3313 | struct mlx5_flow_attr *attr = flow->attr; | |
3314 | bool ft_flow = mlx5e_is_ft_flow(flow); | |
3315 | u32 dest_chain = act->chain_index; | |
3316 | struct mlx5_fs_chains *chains; | |
3317 | struct mlx5_eswitch *esw; | |
3318 | u32 reformat_and_fwd; | |
3319 | u32 max_chain; | |
3320 | ||
3321 | esw = priv->mdev->priv.eswitch; | |
3322 | chains = is_esw ? esw_chains(esw) : nic_chains(priv); | |
3323 | max_chain = mlx5_chains_get_chain_range(chains); | |
3324 | reformat_and_fwd = is_esw ? | |
3325 | MLX5_CAP_ESW_FLOWTABLE_FDB(priv->mdev, reformat_and_fwd_to_table) : | |
3326 | MLX5_CAP_FLOWTABLE_NIC_RX(priv->mdev, reformat_and_fwd_to_table); | |
3327 | ||
3328 | if (ft_flow) { | |
3329 | NL_SET_ERR_MSG_MOD(extack, "Goto action is not supported"); | |
3330 | return -EOPNOTSUPP; | |
3331 | } | |
3332 | ||
3333 | if (!mlx5_chains_backwards_supported(chains) && | |
3334 | dest_chain <= attr->chain) { | |
3335 | NL_SET_ERR_MSG_MOD(extack, | |
3336 | "Goto lower numbered chain isn't supported"); | |
3337 | return -EOPNOTSUPP; | |
3338 | } | |
3339 | ||
3340 | if (dest_chain > max_chain) { | |
3341 | NL_SET_ERR_MSG_MOD(extack, | |
3342 | "Requested destination chain is out of supported range"); | |
3343 | return -EOPNOTSUPP; | |
3344 | } | |
3345 | ||
3346 | if (actions & (MLX5_FLOW_CONTEXT_ACTION_PACKET_REFORMAT | | |
3347 | MLX5_FLOW_CONTEXT_ACTION_DECAP) && | |
3348 | !reformat_and_fwd) { | |
3349 | NL_SET_ERR_MSG_MOD(extack, | |
3350 | "Goto chain is not allowed if action has reformat or decap"); | |
3351 | return -EOPNOTSUPP; | |
3352 | } | |
3353 | ||
3354 | return 0; | |
3355 | } | |
3356 | ||
73867881 PNA |
3357 | static int parse_tc_nic_actions(struct mlx5e_priv *priv, |
3358 | struct flow_action *flow_action, | |
e98bedf5 EB |
3359 | struct mlx5e_tc_flow *flow, |
3360 | struct netlink_ext_ack *extack) | |
e3a2b7ed | 3361 | { |
c6cfe113 | 3362 | struct mlx5e_tc_flow_parse_attr *parse_attr; |
c620b772 | 3363 | struct mlx5_flow_attr *attr = flow->attr; |
73867881 PNA |
3364 | struct pedit_headers_action hdrs[2] = {}; |
3365 | const struct flow_action_entry *act; | |
c620b772 | 3366 | struct mlx5_nic_flow_attr *nic_attr; |
1cab1cd7 | 3367 | u32 action = 0; |
244cd96a | 3368 | int err, i; |
e3a2b7ed | 3369 | |
73867881 | 3370 | if (!flow_action_has_entries(flow_action)) |
e3a2b7ed AV |
3371 | return -EINVAL; |
3372 | ||
53eca1f3 JK |
3373 | if (!flow_action_hw_stats_check(flow_action, extack, |
3374 | FLOW_ACTION_HW_STATS_DELAYED_BIT)) | |
319a1d19 JP |
3375 | return -EOPNOTSUPP; |
3376 | ||
c620b772 | 3377 | nic_attr = attr->nic_attr; |
c620b772 | 3378 | nic_attr->flow_tag = MLX5_FS_DEFAULT_FLOW_TAG; |
c6cfe113 | 3379 | parse_attr = attr->parse_attr; |
e3a2b7ed | 3380 | |
73867881 PNA |
3381 | flow_action_for_each(i, act, flow_action) { |
3382 | switch (act->id) { | |
15fc92ec TZ |
3383 | case FLOW_ACTION_ACCEPT: |
3384 | action |= MLX5_FLOW_CONTEXT_ACTION_FWD_DEST | | |
3385 | MLX5_FLOW_CONTEXT_ACTION_COUNT; | |
3386 | break; | |
73867881 | 3387 | case FLOW_ACTION_DROP: |
950b4df9 RD |
3388 | action |= MLX5_FLOW_CONTEXT_ACTION_DROP | |
3389 | MLX5_FLOW_CONTEXT_ACTION_COUNT; | |
73867881 PNA |
3390 | break; |
3391 | case FLOW_ACTION_MANGLE: | |
3392 | case FLOW_ACTION_ADD: | |
3393 | err = parse_tc_pedit_action(priv, act, MLX5_FLOW_NAMESPACE_KERNEL, | |
582234b4 | 3394 | parse_attr, hdrs, NULL, extack); |
2f4fe4ca OG |
3395 | if (err) |
3396 | return err; | |
3397 | ||
c7569097 | 3398 | action |= MLX5_FLOW_CONTEXT_ACTION_MOD_HDR; |
73867881 | 3399 | break; |
bdc837ee EB |
3400 | case FLOW_ACTION_VLAN_MANGLE: |
3401 | err = add_vlan_rewrite_action(priv, | |
3402 | MLX5_FLOW_NAMESPACE_KERNEL, | |
3403 | act, parse_attr, hdrs, | |
3404 | &action, extack); | |
3405 | if (err) | |
3406 | return err; | |
3407 | ||
3408 | break; | |
73867881 | 3409 | case FLOW_ACTION_CSUM: |
1cab1cd7 | 3410 | if (csum_offload_supported(priv, action, |
73867881 | 3411 | act->csum_flags, |
e98bedf5 | 3412 | extack)) |
73867881 | 3413 | break; |
26c02749 OG |
3414 | |
3415 | return -EOPNOTSUPP; | |
73867881 PNA |
3416 | case FLOW_ACTION_REDIRECT: { |
3417 | struct net_device *peer_dev = act->dev; | |
5c65c564 OG |
3418 | |
3419 | if (priv->netdev->netdev_ops == peer_dev->netdev_ops && | |
3420 | same_hw_devs(priv, netdev_priv(peer_dev))) { | |
98b66cb1 | 3421 | parse_attr->mirred_ifindex[0] = peer_dev->ifindex; |
226f2ca3 | 3422 | flow_flag_set(flow, HAIRPIN); |
1cab1cd7 OG |
3423 | action |= MLX5_FLOW_CONTEXT_ACTION_FWD_DEST | |
3424 | MLX5_FLOW_CONTEXT_ACTION_COUNT; | |
5c65c564 | 3425 | } else { |
e98bedf5 EB |
3426 | NL_SET_ERR_MSG_MOD(extack, |
3427 | "device is not on same HW, can't offload"); | |
5c65c564 OG |
3428 | netdev_warn(priv->netdev, "device %s not on same HW, can't offload\n", |
3429 | peer_dev->name); | |
25f150f4 | 3430 | return -EOPNOTSUPP; |
5c65c564 | 3431 | } |
73867881 PNA |
3432 | } |
3433 | break; | |
3434 | case FLOW_ACTION_MARK: { | |
3435 | u32 mark = act->mark; | |
e3a2b7ed AV |
3436 | |
3437 | if (mark & ~MLX5E_TC_FLOW_ID_MASK) { | |
e98bedf5 EB |
3438 | NL_SET_ERR_MSG_MOD(extack, |
3439 | "Bad flow mark - only 16 bit is supported"); | |
25f150f4 | 3440 | return -EOPNOTSUPP; |
e3a2b7ed AV |
3441 | } |
3442 | ||
c620b772 | 3443 | nic_attr->flow_tag = mark; |
1cab1cd7 | 3444 | action |= MLX5_FLOW_CONTEXT_ACTION_FWD_DEST; |
73867881 PNA |
3445 | } |
3446 | break; | |
c7569097 AL |
3447 | case FLOW_ACTION_GOTO: |
3448 | err = validate_goto_chain(priv, flow, act, action, | |
3449 | extack); | |
3450 | if (err) | |
3451 | return err; | |
3452 | ||
7f8770c7 RD |
3453 | action |= MLX5_FLOW_CONTEXT_ACTION_FWD_DEST | |
3454 | MLX5_FLOW_CONTEXT_ACTION_COUNT; | |
c7569097 AL |
3455 | attr->dest_chain = act->chain_index; |
3456 | break; | |
aedd133d AL |
3457 | case FLOW_ACTION_CT: |
3458 | err = mlx5_tc_ct_parse_action(get_ct_priv(priv), attr, act, extack); | |
3459 | if (err) | |
3460 | return err; | |
3461 | ||
3462 | flow_flag_set(flow, CT); | |
3463 | break; | |
73867881 | 3464 | default: |
2cc1cb1d TZ |
3465 | NL_SET_ERR_MSG_MOD(extack, "The offload action is not supported"); |
3466 | return -EOPNOTSUPP; | |
e3a2b7ed | 3467 | } |
e3a2b7ed AV |
3468 | } |
3469 | ||
c500c86b PNA |
3470 | if (hdrs[TCA_PEDIT_KEY_EX_CMD_SET].pedits || |
3471 | hdrs[TCA_PEDIT_KEY_EX_CMD_ADD].pedits) { | |
3472 | err = alloc_tc_pedit_action(priv, MLX5_FLOW_NAMESPACE_KERNEL, | |
27c11b6b | 3473 | parse_attr, hdrs, &action, extack); |
c500c86b PNA |
3474 | if (err) |
3475 | return err; | |
27c11b6b EB |
3476 | /* in case all pedit actions are skipped, remove the MOD_HDR |
3477 | * flag. | |
3478 | */ | |
6ae4a6a5 | 3479 | if (parse_attr->mod_hdr_acts.num_actions == 0) { |
27c11b6b | 3480 | action &= ~MLX5_FLOW_CONTEXT_ACTION_MOD_HDR; |
6ae4a6a5 | 3481 | dealloc_mod_hdr_actions(&parse_attr->mod_hdr_acts); |
e7739a60 | 3482 | } |
c500c86b PNA |
3483 | } |
3484 | ||
1cab1cd7 | 3485 | attr->action = action; |
c7569097 | 3486 | |
7f8770c7 RD |
3487 | if (attr->dest_chain && parse_attr->mirred_ifindex[0]) { |
3488 | NL_SET_ERR_MSG(extack, "Mirroring goto chain rules isn't supported"); | |
3489 | return -EOPNOTSUPP; | |
c7569097 AL |
3490 | } |
3491 | ||
73867881 | 3492 | if (!actions_match_supported(priv, flow_action, parse_attr, flow, extack)) |
bdd66ac0 OG |
3493 | return -EOPNOTSUPP; |
3494 | ||
e3a2b7ed AV |
3495 | return 0; |
3496 | } | |
3497 | ||
32134847 | 3498 | static bool is_merged_eswitch_vfs(struct mlx5e_priv *priv, |
b1d90e6b RL |
3499 | struct net_device *peer_netdev) |
3500 | { | |
3501 | struct mlx5e_priv *peer_priv; | |
3502 | ||
3503 | peer_priv = netdev_priv(peer_netdev); | |
3504 | ||
3505 | return (MLX5_CAP_ESW(priv->mdev, merged_eswitch) && | |
32134847 MD |
3506 | mlx5e_eswitch_vf_rep(priv->netdev) && |
3507 | mlx5e_eswitch_vf_rep(peer_netdev) && | |
68931c7d | 3508 | same_hw_devs(priv, peer_priv)); |
b1d90e6b RL |
3509 | } |
3510 | ||
1482bd3d | 3511 | static int parse_tc_vlan_action(struct mlx5e_priv *priv, |
73867881 | 3512 | const struct flow_action_entry *act, |
1482bd3d JL |
3513 | struct mlx5_esw_flow_attr *attr, |
3514 | u32 *action) | |
3515 | { | |
cc495188 JL |
3516 | u8 vlan_idx = attr->total_vlan; |
3517 | ||
3518 | if (vlan_idx >= MLX5_FS_VLAN_DEPTH) | |
3519 | return -EOPNOTSUPP; | |
3520 | ||
73867881 PNA |
3521 | switch (act->id) { |
3522 | case FLOW_ACTION_VLAN_POP: | |
cc495188 JL |
3523 | if (vlan_idx) { |
3524 | if (!mlx5_eswitch_vlan_actions_supported(priv->mdev, | |
3525 | MLX5_FS_VLAN_DEPTH)) | |
3526 | return -EOPNOTSUPP; | |
3527 | ||
3528 | *action |= MLX5_FLOW_CONTEXT_ACTION_VLAN_POP_2; | |
3529 | } else { | |
3530 | *action |= MLX5_FLOW_CONTEXT_ACTION_VLAN_POP; | |
3531 | } | |
73867881 PNA |
3532 | break; |
3533 | case FLOW_ACTION_VLAN_PUSH: | |
3534 | attr->vlan_vid[vlan_idx] = act->vlan.vid; | |
3535 | attr->vlan_prio[vlan_idx] = act->vlan.prio; | |
3536 | attr->vlan_proto[vlan_idx] = act->vlan.proto; | |
cc495188 JL |
3537 | if (!attr->vlan_proto[vlan_idx]) |
3538 | attr->vlan_proto[vlan_idx] = htons(ETH_P_8021Q); | |
3539 | ||
3540 | if (vlan_idx) { | |
3541 | if (!mlx5_eswitch_vlan_actions_supported(priv->mdev, | |
3542 | MLX5_FS_VLAN_DEPTH)) | |
3543 | return -EOPNOTSUPP; | |
3544 | ||
3545 | *action |= MLX5_FLOW_CONTEXT_ACTION_VLAN_PUSH_2; | |
3546 | } else { | |
3547 | if (!mlx5_eswitch_vlan_actions_supported(priv->mdev, 1) && | |
73867881 PNA |
3548 | (act->vlan.proto != htons(ETH_P_8021Q) || |
3549 | act->vlan.prio)) | |
cc495188 JL |
3550 | return -EOPNOTSUPP; |
3551 | ||
3552 | *action |= MLX5_FLOW_CONTEXT_ACTION_VLAN_PUSH; | |
1482bd3d | 3553 | } |
73867881 PNA |
3554 | break; |
3555 | default: | |
bdc837ee | 3556 | return -EINVAL; |
1482bd3d JL |
3557 | } |
3558 | ||
cc495188 JL |
3559 | attr->total_vlan = vlan_idx + 1; |
3560 | ||
1482bd3d JL |
3561 | return 0; |
3562 | } | |
3563 | ||
d34eb2fc OG |
3564 | static struct net_device *get_fdb_out_dev(struct net_device *uplink_dev, |
3565 | struct net_device *out_dev) | |
3566 | { | |
3567 | struct net_device *fdb_out_dev = out_dev; | |
3568 | struct net_device *uplink_upper; | |
3569 | ||
3570 | rcu_read_lock(); | |
3571 | uplink_upper = netdev_master_upper_dev_get_rcu(uplink_dev); | |
3572 | if (uplink_upper && netif_is_lag_master(uplink_upper) && | |
3573 | uplink_upper == out_dev) { | |
3574 | fdb_out_dev = uplink_dev; | |
3575 | } else if (netif_is_lag_master(out_dev)) { | |
3576 | fdb_out_dev = bond_option_active_slave_get_rcu(netdev_priv(out_dev)); | |
3577 | if (fdb_out_dev && | |
3578 | (!mlx5e_eswitch_rep(fdb_out_dev) || | |
3579 | !netdev_port_same_parent_id(fdb_out_dev, uplink_dev))) | |
3580 | fdb_out_dev = NULL; | |
3581 | } | |
3582 | rcu_read_unlock(); | |
3583 | return fdb_out_dev; | |
3584 | } | |
3585 | ||
278748a9 | 3586 | static int add_vlan_push_action(struct mlx5e_priv *priv, |
c620b772 | 3587 | struct mlx5_flow_attr *attr, |
278748a9 EB |
3588 | struct net_device **out_dev, |
3589 | u32 *action) | |
3590 | { | |
3591 | struct net_device *vlan_dev = *out_dev; | |
3592 | struct flow_action_entry vlan_act = { | |
3593 | .id = FLOW_ACTION_VLAN_PUSH, | |
3594 | .vlan.vid = vlan_dev_vlan_id(vlan_dev), | |
3595 | .vlan.proto = vlan_dev_vlan_proto(vlan_dev), | |
3596 | .vlan.prio = 0, | |
3597 | }; | |
3598 | int err; | |
3599 | ||
c620b772 | 3600 | err = parse_tc_vlan_action(priv, &vlan_act, attr->esw_attr, action); |
278748a9 EB |
3601 | if (err) |
3602 | return err; | |
3603 | ||
dca59f4a DC |
3604 | rcu_read_lock(); |
3605 | *out_dev = dev_get_by_index_rcu(dev_net(vlan_dev), dev_get_iflink(vlan_dev)); | |
3606 | rcu_read_unlock(); | |
3607 | if (!*out_dev) | |
3608 | return -ENODEV; | |
3609 | ||
278748a9 EB |
3610 | if (is_vlan_dev(*out_dev)) |
3611 | err = add_vlan_push_action(priv, attr, out_dev, action); | |
3612 | ||
3613 | return err; | |
3614 | } | |
3615 | ||
35a605db | 3616 | static int add_vlan_pop_action(struct mlx5e_priv *priv, |
c620b772 | 3617 | struct mlx5_flow_attr *attr, |
35a605db EB |
3618 | u32 *action) |
3619 | { | |
35a605db EB |
3620 | struct flow_action_entry vlan_act = { |
3621 | .id = FLOW_ACTION_VLAN_POP, | |
3622 | }; | |
70f478ca | 3623 | int nest_level, err = 0; |
35a605db | 3624 | |
70f478ca DL |
3625 | nest_level = attr->parse_attr->filter_dev->lower_level - |
3626 | priv->netdev->lower_level; | |
35a605db | 3627 | while (nest_level--) { |
c620b772 | 3628 | err = parse_tc_vlan_action(priv, &vlan_act, attr->esw_attr, action); |
35a605db EB |
3629 | if (err) |
3630 | return err; | |
3631 | } | |
3632 | ||
3633 | return err; | |
3634 | } | |
3635 | ||
32134847 MD |
3636 | static bool same_hw_reps(struct mlx5e_priv *priv, |
3637 | struct net_device *peer_netdev) | |
3638 | { | |
3639 | struct mlx5e_priv *peer_priv; | |
3640 | ||
3641 | peer_priv = netdev_priv(peer_netdev); | |
3642 | ||
3643 | return mlx5e_eswitch_rep(priv->netdev) && | |
3644 | mlx5e_eswitch_rep(peer_netdev) && | |
3645 | same_hw_devs(priv, peer_priv); | |
3646 | } | |
3647 | ||
3648 | static bool is_lag_dev(struct mlx5e_priv *priv, | |
3649 | struct net_device *peer_netdev) | |
3650 | { | |
3651 | return ((mlx5_lag_is_sriov(priv->mdev) || | |
3652 | mlx5_lag_is_multipath(priv->mdev)) && | |
3653 | same_hw_reps(priv, peer_netdev)); | |
3654 | } | |
3655 | ||
f6dc1264 PB |
3656 | bool mlx5e_is_valid_eswitch_fwd_dev(struct mlx5e_priv *priv, |
3657 | struct net_device *out_dev) | |
3658 | { | |
32134847 MD |
3659 | if (is_merged_eswitch_vfs(priv, out_dev)) |
3660 | return true; | |
3661 | ||
3662 | if (is_lag_dev(priv, out_dev)) | |
f6dc1264 PB |
3663 | return true; |
3664 | ||
3665 | return mlx5e_eswitch_rep(out_dev) && | |
32134847 | 3666 | same_port_devs(priv, netdev_priv(out_dev)); |
f6dc1264 PB |
3667 | } |
3668 | ||
554fe75c DL |
3669 | static bool is_duplicated_output_device(struct net_device *dev, |
3670 | struct net_device *out_dev, | |
3671 | int *ifindexes, int if_count, | |
3672 | struct netlink_ext_ack *extack) | |
3673 | { | |
3674 | int i; | |
3675 | ||
3676 | for (i = 0; i < if_count; i++) { | |
3677 | if (ifindexes[i] == out_dev->ifindex) { | |
3678 | NL_SET_ERR_MSG_MOD(extack, | |
3679 | "can't duplicate output to same device"); | |
3680 | netdev_err(dev, "can't duplicate output to same device: %s\n", | |
3681 | out_dev->name); | |
3682 | return true; | |
3683 | } | |
3684 | } | |
3685 | ||
3686 | return false; | |
3687 | } | |
3688 | ||
613f53fe EC |
3689 | static int verify_uplink_forwarding(struct mlx5e_priv *priv, |
3690 | struct mlx5e_tc_flow *flow, | |
3691 | struct net_device *out_dev, | |
3692 | struct netlink_ext_ack *extack) | |
3693 | { | |
c620b772 | 3694 | struct mlx5_esw_flow_attr *attr = flow->attr->esw_attr; |
613f53fe | 3695 | struct mlx5_eswitch *esw = priv->mdev->priv.eswitch; |
613f53fe EC |
3696 | struct mlx5e_rep_priv *rep_priv; |
3697 | ||
3698 | /* Forwarding non encapsulated traffic between | |
3699 | * uplink ports is allowed only if | |
3700 | * termination_table_raw_traffic cap is set. | |
3701 | * | |
c620b772 | 3702 | * Input vport was stored attr->in_rep. |
613f53fe EC |
3703 | * In LAG case, *priv* is the private data of |
3704 | * uplink which may be not the input vport. | |
3705 | */ | |
3706 | rep_priv = mlx5e_rep_to_rep_priv(attr->in_rep); | |
3707 | ||
3708 | if (!(mlx5e_eswitch_uplink_rep(rep_priv->netdev) && | |
3709 | mlx5e_eswitch_uplink_rep(out_dev))) | |
3710 | return 0; | |
3711 | ||
3712 | if (!MLX5_CAP_ESW_FLOWTABLE_FDB(esw->dev, | |
3713 | termination_table_raw_traffic)) { | |
3714 | NL_SET_ERR_MSG_MOD(extack, | |
3715 | "devices are both uplink, can't offload forwarding"); | |
3716 | pr_err("devices %s %s are both uplink, can't offload forwarding\n", | |
3717 | priv->netdev->name, out_dev->name); | |
3718 | return -EOPNOTSUPP; | |
3719 | } else if (out_dev != rep_priv->netdev) { | |
3720 | NL_SET_ERR_MSG_MOD(extack, | |
3721 | "devices are not the same uplink, can't offload forwarding"); | |
3722 | pr_err("devices %s %s are both uplink but not the same, can't offload forwarding\n", | |
3723 | priv->netdev->name, out_dev->name); | |
3724 | return -EOPNOTSUPP; | |
3725 | } | |
3726 | return 0; | |
3727 | } | |
3728 | ||
73867881 PNA |
3729 | static int parse_tc_fdb_actions(struct mlx5e_priv *priv, |
3730 | struct flow_action *flow_action, | |
e98bedf5 | 3731 | struct mlx5e_tc_flow *flow, |
70f8019e | 3732 | struct netlink_ext_ack *extack) |
03a9d11e | 3733 | { |
73867881 | 3734 | struct pedit_headers_action hdrs[2] = {}; |
bf07aa73 | 3735 | struct mlx5_eswitch *esw = priv->mdev->priv.eswitch; |
c620b772 | 3736 | struct mlx5e_tc_flow_parse_attr *parse_attr; |
1d447a39 | 3737 | struct mlx5e_rep_priv *rpriv = priv->ppriv; |
bcd6740c | 3738 | struct mlx5e_sample_attr sample_attr = {}; |
73867881 | 3739 | const struct ip_tunnel_info *info = NULL; |
c620b772 | 3740 | struct mlx5_flow_attr *attr = flow->attr; |
554fe75c | 3741 | int ifindexes[MLX5_MAX_FLOW_FWD_VPORTS]; |
84179981 | 3742 | bool ft_flow = mlx5e_is_ft_flow(flow); |
73867881 | 3743 | const struct flow_action_entry *act; |
c620b772 | 3744 | struct mlx5_esw_flow_attr *esw_attr; |
0a7fcb78 PB |
3745 | bool encap = false, decap = false; |
3746 | u32 action = attr->action; | |
554fe75c | 3747 | int err, i, if_count = 0; |
f828ca6a | 3748 | bool mpls_push = false; |
03a9d11e | 3749 | |
73867881 | 3750 | if (!flow_action_has_entries(flow_action)) |
03a9d11e OG |
3751 | return -EINVAL; |
3752 | ||
53eca1f3 JK |
3753 | if (!flow_action_hw_stats_check(flow_action, extack, |
3754 | FLOW_ACTION_HW_STATS_DELAYED_BIT)) | |
319a1d19 JP |
3755 | return -EOPNOTSUPP; |
3756 | ||
c620b772 AL |
3757 | esw_attr = attr->esw_attr; |
3758 | parse_attr = attr->parse_attr; | |
3759 | ||
73867881 PNA |
3760 | flow_action_for_each(i, act, flow_action) { |
3761 | switch (act->id) { | |
3762 | case FLOW_ACTION_DROP: | |
1cab1cd7 OG |
3763 | action |= MLX5_FLOW_CONTEXT_ACTION_DROP | |
3764 | MLX5_FLOW_CONTEXT_ACTION_COUNT; | |
73867881 | 3765 | break; |
f0288210 EC |
3766 | case FLOW_ACTION_TRAP: |
3767 | if (!flow_offload_has_one_action(flow_action)) { | |
3768 | NL_SET_ERR_MSG_MOD(extack, | |
3769 | "action trap is supported as a sole action only"); | |
3770 | return -EOPNOTSUPP; | |
3771 | } | |
3772 | action |= (MLX5_FLOW_CONTEXT_ACTION_FWD_DEST | | |
3773 | MLX5_FLOW_CONTEXT_ACTION_COUNT); | |
3774 | attr->flags |= MLX5_ESW_ATTR_FLAG_SLOW_PATH; | |
3775 | break; | |
f828ca6a EC |
3776 | case FLOW_ACTION_MPLS_PUSH: |
3777 | if (!MLX5_CAP_ESW_FLOWTABLE_FDB(priv->mdev, | |
3778 | reformat_l2_to_l3_tunnel) || | |
3779 | act->mpls_push.proto != htons(ETH_P_MPLS_UC)) { | |
3780 | NL_SET_ERR_MSG_MOD(extack, | |
3781 | "mpls push is supported only for mpls_uc protocol"); | |
3782 | return -EOPNOTSUPP; | |
3783 | } | |
3784 | mpls_push = true; | |
3785 | break; | |
14e6b038 EC |
3786 | case FLOW_ACTION_MPLS_POP: |
3787 | /* we only support mpls pop if it is the first action | |
3788 | * and the filter net device is bareudp. Subsequent | |
3789 | * actions can be pedit and the last can be mirred | |
3790 | * egress redirect. | |
3791 | */ | |
3792 | if (i) { | |
3793 | NL_SET_ERR_MSG_MOD(extack, | |
3794 | "mpls pop supported only as first action"); | |
3795 | return -EOPNOTSUPP; | |
3796 | } | |
70f8019e | 3797 | if (!netif_is_bareudp(parse_attr->filter_dev)) { |
14e6b038 EC |
3798 | NL_SET_ERR_MSG_MOD(extack, |
3799 | "mpls pop supported only on bareudp devices"); | |
3800 | return -EOPNOTSUPP; | |
3801 | } | |
3802 | ||
3803 | parse_attr->eth.h_proto = act->mpls_pop.proto; | |
3804 | action |= MLX5_FLOW_CONTEXT_ACTION_PACKET_REFORMAT; | |
3805 | flow_flag_set(flow, L3_TO_L2_DECAP); | |
3806 | break; | |
73867881 PNA |
3807 | case FLOW_ACTION_MANGLE: |
3808 | case FLOW_ACTION_ADD: | |
3809 | err = parse_tc_pedit_action(priv, act, MLX5_FLOW_NAMESPACE_FDB, | |
582234b4 | 3810 | parse_attr, hdrs, flow, extack); |
d7e75a32 OG |
3811 | if (err) |
3812 | return err; | |
3813 | ||
582234b4 EC |
3814 | if (!flow_flag_test(flow, L3_TO_L2_DECAP)) { |
3815 | action |= MLX5_FLOW_CONTEXT_ACTION_MOD_HDR; | |
c620b772 | 3816 | esw_attr->split_count = esw_attr->out_count; |
582234b4 | 3817 | } |
73867881 PNA |
3818 | break; |
3819 | case FLOW_ACTION_CSUM: | |
1cab1cd7 | 3820 | if (csum_offload_supported(priv, action, |
73867881 PNA |
3821 | act->csum_flags, extack)) |
3822 | break; | |
26c02749 OG |
3823 | |
3824 | return -EOPNOTSUPP; | |
73867881 PNA |
3825 | case FLOW_ACTION_REDIRECT: |
3826 | case FLOW_ACTION_MIRRED: { | |
03a9d11e | 3827 | struct mlx5e_priv *out_priv; |
592d3651 | 3828 | struct net_device *out_dev; |
03a9d11e | 3829 | |
73867881 | 3830 | out_dev = act->dev; |
ef381359 OS |
3831 | if (!out_dev) { |
3832 | /* out_dev is NULL when filters with | |
3833 | * non-existing mirred device are replayed to | |
3834 | * the driver. | |
3835 | */ | |
3836 | return -EINVAL; | |
3837 | } | |
03a9d11e | 3838 | |
f828ca6a EC |
3839 | if (mpls_push && !netif_is_bareudp(out_dev)) { |
3840 | NL_SET_ERR_MSG_MOD(extack, | |
3841 | "mpls is supported only through a bareudp device"); | |
3842 | return -EOPNOTSUPP; | |
3843 | } | |
3844 | ||
84179981 PB |
3845 | if (ft_flow && out_dev == priv->netdev) { |
3846 | /* Ignore forward to self rules generated | |
3847 | * by adding both mlx5 devs to the flow table | |
3848 | * block on a normal nft offload setup. | |
3849 | */ | |
3850 | return -EOPNOTSUPP; | |
3851 | } | |
3852 | ||
c620b772 | 3853 | if (esw_attr->out_count >= MLX5_MAX_FLOW_FWD_VPORTS) { |
e98bedf5 EB |
3854 | NL_SET_ERR_MSG_MOD(extack, |
3855 | "can't support more output ports, can't offload forwarding"); | |
4ccd83f4 RD |
3856 | netdev_warn(priv->netdev, |
3857 | "can't support more than %d output ports, can't offload forwarding\n", | |
c620b772 | 3858 | esw_attr->out_count); |
592d3651 CM |
3859 | return -EOPNOTSUPP; |
3860 | } | |
3861 | ||
f493f155 EB |
3862 | action |= MLX5_FLOW_CONTEXT_ACTION_FWD_DEST | |
3863 | MLX5_FLOW_CONTEXT_ACTION_COUNT; | |
b6a4ac24 | 3864 | if (encap) { |
c620b772 | 3865 | parse_attr->mirred_ifindex[esw_attr->out_count] = |
b6a4ac24 | 3866 | out_dev->ifindex; |
0d9f9647 VB |
3867 | parse_attr->tun_info[esw_attr->out_count] = |
3868 | mlx5e_dup_tun_info(info); | |
c620b772 | 3869 | if (!parse_attr->tun_info[esw_attr->out_count]) |
b6a4ac24 VB |
3870 | return -ENOMEM; |
3871 | encap = false; | |
c620b772 | 3872 | esw_attr->dests[esw_attr->out_count].flags |= |
b6a4ac24 | 3873 | MLX5_ESW_DEST_ENCAP; |
c620b772 | 3874 | esw_attr->out_count++; |
b6a4ac24 VB |
3875 | /* attr->dests[].rep is resolved when we |
3876 | * handle encap | |
3877 | */ | |
3878 | } else if (netdev_port_same_parent_id(priv->netdev, out_dev)) { | |
7ba58ba7 RL |
3879 | struct mlx5_eswitch *esw = priv->mdev->priv.eswitch; |
3880 | struct net_device *uplink_dev = mlx5_eswitch_uplink_get_proto_dev(esw, REP_ETH); | |
7ba58ba7 | 3881 | |
554fe75c DL |
3882 | if (is_duplicated_output_device(priv->netdev, |
3883 | out_dev, | |
3884 | ifindexes, | |
3885 | if_count, | |
3886 | extack)) | |
3887 | return -EOPNOTSUPP; | |
3888 | ||
3889 | ifindexes[if_count] = out_dev->ifindex; | |
3890 | if_count++; | |
3891 | ||
d34eb2fc OG |
3892 | out_dev = get_fdb_out_dev(uplink_dev, out_dev); |
3893 | if (!out_dev) | |
3894 | return -ENODEV; | |
7ba58ba7 | 3895 | |
278748a9 EB |
3896 | if (is_vlan_dev(out_dev)) { |
3897 | err = add_vlan_push_action(priv, attr, | |
3898 | &out_dev, | |
3899 | &action); | |
3900 | if (err) | |
3901 | return err; | |
3902 | } | |
f6dc1264 | 3903 | |
35a605db EB |
3904 | if (is_vlan_dev(parse_attr->filter_dev)) { |
3905 | err = add_vlan_pop_action(priv, attr, | |
3906 | &action); | |
3907 | if (err) | |
3908 | return err; | |
3909 | } | |
278748a9 | 3910 | |
613f53fe EC |
3911 | err = verify_uplink_forwarding(priv, flow, out_dev, extack); |
3912 | if (err) | |
3913 | return err; | |
ffec9702 | 3914 | |
f6dc1264 PB |
3915 | if (!mlx5e_is_valid_eswitch_fwd_dev(priv, out_dev)) { |
3916 | NL_SET_ERR_MSG_MOD(extack, | |
3917 | "devices are not on same switch HW, can't offload forwarding"); | |
a0646c88 | 3918 | return -EOPNOTSUPP; |
f6dc1264 | 3919 | } |
a0646c88 | 3920 | |
bb569657 AL |
3921 | if (same_vf_reps(priv, out_dev)) { |
3922 | NL_SET_ERR_MSG_MOD(extack, | |
3923 | "can't forward from a VF to itself"); | |
3924 | return -EOPNOTSUPP; | |
3925 | } | |
3926 | ||
a54e20b4 | 3927 | out_priv = netdev_priv(out_dev); |
1d447a39 | 3928 | rpriv = out_priv->ppriv; |
c620b772 AL |
3929 | esw_attr->dests[esw_attr->out_count].rep = rpriv->rep; |
3930 | esw_attr->dests[esw_attr->out_count].mdev = out_priv->mdev; | |
3931 | esw_attr->out_count++; | |
ef381359 OS |
3932 | } else if (parse_attr->filter_dev != priv->netdev) { |
3933 | /* All mlx5 devices are called to configure | |
3934 | * high level device filters. Therefore, the | |
3935 | * *attempt* to install a filter on invalid | |
3936 | * eswitch should not trigger an explicit error | |
3937 | */ | |
3938 | return -EINVAL; | |
a54e20b4 | 3939 | } else { |
e98bedf5 EB |
3940 | NL_SET_ERR_MSG_MOD(extack, |
3941 | "devices are not on same switch HW, can't offload forwarding"); | |
4ccd83f4 RD |
3942 | netdev_warn(priv->netdev, |
3943 | "devices %s %s not on same switch HW, can't offload forwarding\n", | |
3944 | priv->netdev->name, | |
3945 | out_dev->name); | |
25f150f4 | 3946 | return -EOPNOTSUPP; |
03a9d11e | 3947 | } |
73867881 PNA |
3948 | } |
3949 | break; | |
3950 | case FLOW_ACTION_TUNNEL_ENCAP: | |
3951 | info = act->tunnel; | |
a54e20b4 HHZ |
3952 | if (info) |
3953 | encap = true; | |
3954 | else | |
3955 | return -EOPNOTSUPP; | |
1482bd3d | 3956 | |
73867881 PNA |
3957 | break; |
3958 | case FLOW_ACTION_VLAN_PUSH: | |
3959 | case FLOW_ACTION_VLAN_POP: | |
76b496b1 EB |
3960 | if (act->id == FLOW_ACTION_VLAN_PUSH && |
3961 | (action & MLX5_FLOW_CONTEXT_ACTION_VLAN_POP)) { | |
3962 | /* Replace vlan pop+push with vlan modify */ | |
3963 | action &= ~MLX5_FLOW_CONTEXT_ACTION_VLAN_POP; | |
3964 | err = add_vlan_rewrite_action(priv, | |
3965 | MLX5_FLOW_NAMESPACE_FDB, | |
3966 | act, parse_attr, hdrs, | |
3967 | &action, extack); | |
3968 | } else { | |
c620b772 | 3969 | err = parse_tc_vlan_action(priv, act, esw_attr, &action); |
76b496b1 | 3970 | } |
1482bd3d JL |
3971 | if (err) |
3972 | return err; | |
3973 | ||
c620b772 | 3974 | esw_attr->split_count = esw_attr->out_count; |
bdc837ee EB |
3975 | break; |
3976 | case FLOW_ACTION_VLAN_MANGLE: | |
3977 | err = add_vlan_rewrite_action(priv, | |
3978 | MLX5_FLOW_NAMESPACE_FDB, | |
3979 | act, parse_attr, hdrs, | |
3980 | &action, extack); | |
3981 | if (err) | |
3982 | return err; | |
3983 | ||
c620b772 | 3984 | esw_attr->split_count = esw_attr->out_count; |
73867881 PNA |
3985 | break; |
3986 | case FLOW_ACTION_TUNNEL_DECAP: | |
0a7fcb78 | 3987 | decap = true; |
73867881 | 3988 | break; |
2fbbc30d | 3989 | case FLOW_ACTION_GOTO: |
c7569097 AL |
3990 | err = validate_goto_chain(priv, flow, act, action, |
3991 | extack); | |
2fbbc30d EC |
3992 | if (err) |
3993 | return err; | |
bf07aa73 | 3994 | |
7f8770c7 RD |
3995 | action |= MLX5_FLOW_CONTEXT_ACTION_FWD_DEST | |
3996 | MLX5_FLOW_CONTEXT_ACTION_COUNT; | |
2fbbc30d | 3997 | attr->dest_chain = act->chain_index; |
73867881 | 3998 | break; |
4c3844d9 | 3999 | case FLOW_ACTION_CT: |
41c2fd94 CM |
4000 | if (flow_flag_test(flow, SAMPLE)) { |
4001 | NL_SET_ERR_MSG_MOD(extack, "Sample action with connection tracking is not supported"); | |
4002 | return -EOPNOTSUPP; | |
4003 | } | |
aedd133d | 4004 | err = mlx5_tc_ct_parse_action(get_ct_priv(priv), attr, act, extack); |
4c3844d9 PB |
4005 | if (err) |
4006 | return err; | |
4007 | ||
4008 | flow_flag_set(flow, CT); | |
69e2916e | 4009 | esw_attr->split_count = esw_attr->out_count; |
4c3844d9 | 4010 | break; |
41c2fd94 CM |
4011 | case FLOW_ACTION_SAMPLE: |
4012 | if (flow_flag_test(flow, CT)) { | |
4013 | NL_SET_ERR_MSG_MOD(extack, "Sample action with connection tracking is not supported"); | |
4014 | return -EOPNOTSUPP; | |
4015 | } | |
bcd6740c CM |
4016 | sample_attr.rate = act->sample.rate; |
4017 | sample_attr.group_num = act->sample.psample_group->group_num; | |
41c2fd94 | 4018 | if (act->sample.truncate) |
bcd6740c | 4019 | sample_attr.trunc_size = act->sample.trunc_size; |
41c2fd94 CM |
4020 | flow_flag_set(flow, SAMPLE); |
4021 | break; | |
73867881 | 4022 | default: |
2cc1cb1d TZ |
4023 | NL_SET_ERR_MSG_MOD(extack, "The offload action is not supported"); |
4024 | return -EOPNOTSUPP; | |
bf07aa73 | 4025 | } |
03a9d11e | 4026 | } |
bdd66ac0 | 4027 | |
a508728a VB |
4028 | /* always set IP version for indirect table handling */ |
4029 | attr->ip_version = mlx5e_tc_get_ip_version(&parse_attr->spec, true); | |
4030 | ||
0bac1194 EB |
4031 | if (MLX5_CAP_GEN(esw->dev, prio_tag_required) && |
4032 | action & MLX5_FLOW_CONTEXT_ACTION_VLAN_POP) { | |
4033 | /* For prio tag mode, replace vlan pop with rewrite vlan prio | |
4034 | * tag rewrite. | |
4035 | */ | |
4036 | action &= ~MLX5_FLOW_CONTEXT_ACTION_VLAN_POP; | |
4037 | err = add_vlan_prio_tag_rewrite_action(priv, parse_attr, hdrs, | |
4038 | &action, extack); | |
4039 | if (err) | |
4040 | return err; | |
4041 | } | |
4042 | ||
c500c86b PNA |
4043 | if (hdrs[TCA_PEDIT_KEY_EX_CMD_SET].pedits || |
4044 | hdrs[TCA_PEDIT_KEY_EX_CMD_ADD].pedits) { | |
84be899f | 4045 | err = alloc_tc_pedit_action(priv, MLX5_FLOW_NAMESPACE_FDB, |
27c11b6b | 4046 | parse_attr, hdrs, &action, extack); |
c500c86b PNA |
4047 | if (err) |
4048 | return err; | |
27c11b6b EB |
4049 | /* in case all pedit actions are skipped, remove the MOD_HDR |
4050 | * flag. we might have set split_count either by pedit or | |
4051 | * pop/push. if there is no pop/push either, reset it too. | |
4052 | */ | |
6ae4a6a5 | 4053 | if (parse_attr->mod_hdr_acts.num_actions == 0) { |
27c11b6b | 4054 | action &= ~MLX5_FLOW_CONTEXT_ACTION_MOD_HDR; |
6ae4a6a5 | 4055 | dealloc_mod_hdr_actions(&parse_attr->mod_hdr_acts); |
27c11b6b EB |
4056 | if (!((action & MLX5_FLOW_CONTEXT_ACTION_VLAN_POP) || |
4057 | (action & MLX5_FLOW_CONTEXT_ACTION_VLAN_PUSH))) | |
c620b772 | 4058 | esw_attr->split_count = 0; |
27c11b6b | 4059 | } |
c500c86b PNA |
4060 | } |
4061 | ||
1cab1cd7 | 4062 | attr->action = action; |
73867881 | 4063 | if (!actions_match_supported(priv, flow_action, parse_attr, flow, extack)) |
bdd66ac0 OG |
4064 | return -EOPNOTSUPP; |
4065 | ||
7f8770c7 RD |
4066 | if (attr->dest_chain && decap) { |
4067 | /* It can be supported if we'll create a mapping for | |
4068 | * the tunnel device only (without tunnel), and set | |
4069 | * this tunnel id with this decap flow. | |
4070 | * | |
4071 | * On restore (miss), we'll just set this saved tunnel | |
4072 | * device. | |
4073 | */ | |
0a7fcb78 | 4074 | |
7f8770c7 RD |
4075 | NL_SET_ERR_MSG(extack, "Decap with goto isn't supported"); |
4076 | netdev_warn(priv->netdev, "Decap with goto isn't supported"); | |
4077 | return -EOPNOTSUPP; | |
e88afe75 OG |
4078 | } |
4079 | ||
ae2741e2 VB |
4080 | if (!(attr->action & |
4081 | (MLX5_FLOW_CONTEXT_ACTION_FWD_DEST | MLX5_FLOW_CONTEXT_ACTION_DROP))) { | |
61644c3d RD |
4082 | NL_SET_ERR_MSG_MOD(extack, |
4083 | "Rule must have at least one forward/drop action"); | |
ae2741e2 VB |
4084 | return -EOPNOTSUPP; |
4085 | } | |
4086 | ||
c620b772 | 4087 | if (esw_attr->split_count > 0 && !mlx5_esw_has_fwd_fdb(priv->mdev)) { |
e98bedf5 EB |
4088 | NL_SET_ERR_MSG_MOD(extack, |
4089 | "current firmware doesn't support split rule for port mirroring"); | |
592d3651 CM |
4090 | netdev_warn_once(priv->netdev, "current firmware doesn't support split rule for port mirroring\n"); |
4091 | return -EOPNOTSUPP; | |
4092 | } | |
4093 | ||
41c2fd94 CM |
4094 | /* Allocate sample attribute only when there is a sample action and |
4095 | * no errors after parsing. | |
4096 | */ | |
4097 | if (flow_flag_test(flow, SAMPLE)) { | |
bcd6740c CM |
4098 | attr->sample_attr = kzalloc(sizeof(*attr->sample_attr), GFP_KERNEL); |
4099 | if (!attr->sample_attr) | |
41c2fd94 | 4100 | return -ENOMEM; |
bcd6740c | 4101 | *attr->sample_attr = sample_attr; |
41c2fd94 CM |
4102 | } |
4103 | ||
31c8eba5 | 4104 | return 0; |
03a9d11e OG |
4105 | } |
4106 | ||
226f2ca3 | 4107 | static void get_flags(int flags, unsigned long *flow_flags) |
60bd4af8 | 4108 | { |
226f2ca3 | 4109 | unsigned long __flow_flags = 0; |
60bd4af8 | 4110 | |
226f2ca3 VB |
4111 | if (flags & MLX5_TC_FLAG(INGRESS)) |
4112 | __flow_flags |= BIT(MLX5E_TC_FLOW_FLAG_INGRESS); | |
4113 | if (flags & MLX5_TC_FLAG(EGRESS)) | |
4114 | __flow_flags |= BIT(MLX5E_TC_FLOW_FLAG_EGRESS); | |
60bd4af8 | 4115 | |
226f2ca3 VB |
4116 | if (flags & MLX5_TC_FLAG(ESW_OFFLOAD)) |
4117 | __flow_flags |= BIT(MLX5E_TC_FLOW_FLAG_ESWITCH); | |
4118 | if (flags & MLX5_TC_FLAG(NIC_OFFLOAD)) | |
4119 | __flow_flags |= BIT(MLX5E_TC_FLOW_FLAG_NIC); | |
84179981 PB |
4120 | if (flags & MLX5_TC_FLAG(FT_OFFLOAD)) |
4121 | __flow_flags |= BIT(MLX5E_TC_FLOW_FLAG_FT); | |
d9ee0491 | 4122 | |
60bd4af8 OG |
4123 | *flow_flags = __flow_flags; |
4124 | } | |
4125 | ||
05866c82 OG |
4126 | static const struct rhashtable_params tc_ht_params = { |
4127 | .head_offset = offsetof(struct mlx5e_tc_flow, node), | |
4128 | .key_offset = offsetof(struct mlx5e_tc_flow, cookie), | |
4129 | .key_len = sizeof(((struct mlx5e_tc_flow *)0)->cookie), | |
4130 | .automatic_shrinking = true, | |
4131 | }; | |
4132 | ||
226f2ca3 VB |
4133 | static struct rhashtable *get_tc_ht(struct mlx5e_priv *priv, |
4134 | unsigned long flags) | |
05866c82 | 4135 | { |
655dc3d2 OG |
4136 | struct mlx5_eswitch *esw = priv->mdev->priv.eswitch; |
4137 | struct mlx5e_rep_priv *uplink_rpriv; | |
4138 | ||
226f2ca3 | 4139 | if (flags & MLX5_TC_FLAG(ESW_OFFLOAD)) { |
655dc3d2 | 4140 | uplink_rpriv = mlx5_eswitch_get_uplink_priv(esw, REP_ETH); |
ec1366c2 | 4141 | return &uplink_rpriv->uplink_priv.tc_ht; |
d9ee0491 | 4142 | } else /* NIC offload */ |
655dc3d2 | 4143 | return &priv->fs.tc.ht; |
05866c82 OG |
4144 | } |
4145 | ||
04de7dda RD |
4146 | static bool is_peer_flow_needed(struct mlx5e_tc_flow *flow) |
4147 | { | |
c620b772 AL |
4148 | struct mlx5_esw_flow_attr *esw_attr = flow->attr->esw_attr; |
4149 | struct mlx5_flow_attr *attr = flow->attr; | |
4150 | bool is_rep_ingress = esw_attr->in_rep->vport != MLX5_VPORT_UPLINK && | |
226f2ca3 | 4151 | flow_flag_test(flow, INGRESS); |
1418ddd9 AH |
4152 | bool act_is_encap = !!(attr->action & |
4153 | MLX5_FLOW_CONTEXT_ACTION_PACKET_REFORMAT); | |
c620b772 | 4154 | bool esw_paired = mlx5_devcom_is_paired(esw_attr->in_mdev->priv.devcom, |
1418ddd9 AH |
4155 | MLX5_DEVCOM_ESW_OFFLOADS); |
4156 | ||
10fbb1cd RD |
4157 | if (!esw_paired) |
4158 | return false; | |
4159 | ||
c620b772 AL |
4160 | if ((mlx5_lag_is_sriov(esw_attr->in_mdev) || |
4161 | mlx5_lag_is_multipath(esw_attr->in_mdev)) && | |
10fbb1cd RD |
4162 | (is_rep_ingress || act_is_encap)) |
4163 | return true; | |
4164 | ||
4165 | return false; | |
04de7dda RD |
4166 | } |
4167 | ||
c620b772 AL |
4168 | struct mlx5_flow_attr * |
4169 | mlx5_alloc_flow_attr(enum mlx5_flow_namespace_type type) | |
4170 | { | |
4171 | u32 ex_attr_size = (type == MLX5_FLOW_NAMESPACE_FDB) ? | |
4172 | sizeof(struct mlx5_esw_flow_attr) : | |
4173 | sizeof(struct mlx5_nic_flow_attr); | |
4174 | struct mlx5_flow_attr *attr; | |
4175 | ||
4176 | return kzalloc(sizeof(*attr) + ex_attr_size, GFP_KERNEL); | |
4177 | } | |
4178 | ||
a88780a9 RD |
4179 | static int |
4180 | mlx5e_alloc_flow(struct mlx5e_priv *priv, int attr_size, | |
226f2ca3 | 4181 | struct flow_cls_offload *f, unsigned long flow_flags, |
a88780a9 RD |
4182 | struct mlx5e_tc_flow_parse_attr **__parse_attr, |
4183 | struct mlx5e_tc_flow **__flow) | |
e3a2b7ed | 4184 | { |
17091853 | 4185 | struct mlx5e_tc_flow_parse_attr *parse_attr; |
c620b772 | 4186 | struct mlx5_flow_attr *attr; |
3bc4b7bf | 4187 | struct mlx5e_tc_flow *flow; |
ff7ea04a GS |
4188 | int err = -ENOMEM; |
4189 | int out_index; | |
e3a2b7ed | 4190 | |
c620b772 | 4191 | flow = kzalloc(sizeof(*flow), GFP_KERNEL); |
1b9a07ee | 4192 | parse_attr = kvzalloc(sizeof(*parse_attr), GFP_KERNEL); |
ff7ea04a GS |
4193 | if (!parse_attr || !flow) |
4194 | goto err_free; | |
c620b772 AL |
4195 | |
4196 | flow->flags = flow_flags; | |
4197 | flow->cookie = f->cookie; | |
4198 | flow->priv = priv; | |
4199 | ||
4200 | attr = mlx5_alloc_flow_attr(get_flow_name_space(flow)); | |
ff7ea04a | 4201 | if (!attr) |
e3a2b7ed | 4202 | goto err_free; |
ff7ea04a | 4203 | |
c620b772 | 4204 | flow->attr = attr; |
e3a2b7ed | 4205 | |
5a7e5bcb VB |
4206 | for (out_index = 0; out_index < MLX5_MAX_FLOW_FWD_VPORTS; out_index++) |
4207 | INIT_LIST_HEAD(&flow->encaps[out_index].list); | |
5a7e5bcb | 4208 | INIT_LIST_HEAD(&flow->hairpin); |
14e6b038 | 4209 | INIT_LIST_HEAD(&flow->l3_to_l2_reformat); |
5a7e5bcb | 4210 | refcount_set(&flow->refcnt, 1); |
95435ad7 | 4211 | init_completion(&flow->init_done); |
e3a2b7ed | 4212 | |
a88780a9 RD |
4213 | *__flow = flow; |
4214 | *__parse_attr = parse_attr; | |
4215 | ||
4216 | return 0; | |
4217 | ||
4218 | err_free: | |
4219 | kfree(flow); | |
4220 | kvfree(parse_attr); | |
4221 | return err; | |
4222 | } | |
4223 | ||
c7569097 AL |
4224 | static void |
4225 | mlx5e_flow_attr_init(struct mlx5_flow_attr *attr, | |
4226 | struct mlx5e_tc_flow_parse_attr *parse_attr, | |
4227 | struct flow_cls_offload *f) | |
4228 | { | |
4229 | attr->parse_attr = parse_attr; | |
4230 | attr->chain = f->common.chain_index; | |
4231 | attr->prio = f->common.prio; | |
4232 | } | |
4233 | ||
988ab9c7 | 4234 | static void |
c620b772 | 4235 | mlx5e_flow_esw_attr_init(struct mlx5_flow_attr *attr, |
988ab9c7 TZ |
4236 | struct mlx5e_priv *priv, |
4237 | struct mlx5e_tc_flow_parse_attr *parse_attr, | |
f9e30088 | 4238 | struct flow_cls_offload *f, |
988ab9c7 TZ |
4239 | struct mlx5_eswitch_rep *in_rep, |
4240 | struct mlx5_core_dev *in_mdev) | |
4241 | { | |
4242 | struct mlx5_eswitch *esw = priv->mdev->priv.eswitch; | |
c620b772 | 4243 | struct mlx5_esw_flow_attr *esw_attr = attr->esw_attr; |
988ab9c7 | 4244 | |
c7569097 | 4245 | mlx5e_flow_attr_init(attr, parse_attr, f); |
988ab9c7 TZ |
4246 | |
4247 | esw_attr->in_rep = in_rep; | |
4248 | esw_attr->in_mdev = in_mdev; | |
4249 | ||
4250 | if (MLX5_CAP_ESW(esw->dev, counter_eswitch_affinity) == | |
4251 | MLX5_COUNTER_SOURCE_ESWITCH) | |
4252 | esw_attr->counter_dev = in_mdev; | |
4253 | else | |
4254 | esw_attr->counter_dev = priv->mdev; | |
4255 | } | |
4256 | ||
71129676 | 4257 | static struct mlx5e_tc_flow * |
04de7dda | 4258 | __mlx5e_add_fdb_flow(struct mlx5e_priv *priv, |
f9e30088 | 4259 | struct flow_cls_offload *f, |
226f2ca3 | 4260 | unsigned long flow_flags, |
04de7dda RD |
4261 | struct net_device *filter_dev, |
4262 | struct mlx5_eswitch_rep *in_rep, | |
71129676 | 4263 | struct mlx5_core_dev *in_mdev) |
a88780a9 | 4264 | { |
f9e30088 | 4265 | struct flow_rule *rule = flow_cls_offload_flow_rule(f); |
a88780a9 RD |
4266 | struct netlink_ext_ack *extack = f->common.extack; |
4267 | struct mlx5e_tc_flow_parse_attr *parse_attr; | |
4268 | struct mlx5e_tc_flow *flow; | |
4269 | int attr_size, err; | |
e3a2b7ed | 4270 | |
226f2ca3 | 4271 | flow_flags |= BIT(MLX5E_TC_FLOW_FLAG_ESWITCH); |
a88780a9 RD |
4272 | attr_size = sizeof(struct mlx5_esw_flow_attr); |
4273 | err = mlx5e_alloc_flow(priv, attr_size, f, flow_flags, | |
4274 | &parse_attr, &flow); | |
4275 | if (err) | |
4276 | goto out; | |
988ab9c7 | 4277 | |
d11afc26 | 4278 | parse_attr->filter_dev = filter_dev; |
c620b772 | 4279 | mlx5e_flow_esw_attr_init(flow->attr, |
988ab9c7 TZ |
4280 | priv, parse_attr, |
4281 | f, in_rep, in_mdev); | |
4282 | ||
54c177ca OS |
4283 | err = parse_cls_flower(flow->priv, flow, &parse_attr->spec, |
4284 | f, filter_dev); | |
d11afc26 OS |
4285 | if (err) |
4286 | goto err_free; | |
a88780a9 | 4287 | |
7e36feeb | 4288 | /* actions validation depends on parsing the ct matches first */ |
aedd133d | 4289 | err = mlx5_tc_ct_match_add(get_ct_priv(priv), &parse_attr->spec, f, |
c620b772 | 4290 | &flow->attr->ct_attr, extack); |
a88780a9 RD |
4291 | if (err) |
4292 | goto err_free; | |
4293 | ||
70f8019e | 4294 | err = parse_tc_fdb_actions(priv, &rule->action, flow, extack); |
4c3844d9 PB |
4295 | if (err) |
4296 | goto err_free; | |
4297 | ||
7040632d | 4298 | err = mlx5e_tc_add_fdb_flow(priv, flow, extack); |
95435ad7 | 4299 | complete_all(&flow->init_done); |
ef06c9ee RD |
4300 | if (err) { |
4301 | if (!(err == -ENETUNREACH && mlx5_lag_is_multipath(in_mdev))) | |
4302 | goto err_free; | |
4303 | ||
b4a23329 | 4304 | add_unready_flow(flow); |
ef06c9ee | 4305 | } |
e3a2b7ed | 4306 | |
71129676 | 4307 | return flow; |
a88780a9 RD |
4308 | |
4309 | err_free: | |
5a7e5bcb | 4310 | mlx5e_flow_put(priv, flow); |
a88780a9 | 4311 | out: |
71129676 | 4312 | return ERR_PTR(err); |
a88780a9 RD |
4313 | } |
4314 | ||
f9e30088 | 4315 | static int mlx5e_tc_add_fdb_peer_flow(struct flow_cls_offload *f, |
95dc1902 | 4316 | struct mlx5e_tc_flow *flow, |
226f2ca3 | 4317 | unsigned long flow_flags) |
04de7dda RD |
4318 | { |
4319 | struct mlx5e_priv *priv = flow->priv, *peer_priv; | |
4320 | struct mlx5_eswitch *esw = priv->mdev->priv.eswitch, *peer_esw; | |
c620b772 | 4321 | struct mlx5_esw_flow_attr *attr = flow->attr->esw_attr; |
04de7dda RD |
4322 | struct mlx5_devcom *devcom = priv->mdev->priv.devcom; |
4323 | struct mlx5e_tc_flow_parse_attr *parse_attr; | |
4324 | struct mlx5e_rep_priv *peer_urpriv; | |
4325 | struct mlx5e_tc_flow *peer_flow; | |
4326 | struct mlx5_core_dev *in_mdev; | |
4327 | int err = 0; | |
4328 | ||
4329 | peer_esw = mlx5_devcom_get_peer_data(devcom, MLX5_DEVCOM_ESW_OFFLOADS); | |
4330 | if (!peer_esw) | |
4331 | return -ENODEV; | |
4332 | ||
4333 | peer_urpriv = mlx5_eswitch_get_uplink_priv(peer_esw, REP_ETH); | |
4334 | peer_priv = netdev_priv(peer_urpriv->netdev); | |
4335 | ||
4336 | /* in_mdev is assigned of which the packet originated from. | |
4337 | * So packets redirected to uplink use the same mdev of the | |
4338 | * original flow and packets redirected from uplink use the | |
4339 | * peer mdev. | |
4340 | */ | |
c620b772 | 4341 | if (attr->in_rep->vport == MLX5_VPORT_UPLINK) |
04de7dda RD |
4342 | in_mdev = peer_priv->mdev; |
4343 | else | |
4344 | in_mdev = priv->mdev; | |
4345 | ||
c620b772 | 4346 | parse_attr = flow->attr->parse_attr; |
95dc1902 | 4347 | peer_flow = __mlx5e_add_fdb_flow(peer_priv, f, flow_flags, |
71129676 | 4348 | parse_attr->filter_dev, |
c620b772 | 4349 | attr->in_rep, in_mdev); |
71129676 JG |
4350 | if (IS_ERR(peer_flow)) { |
4351 | err = PTR_ERR(peer_flow); | |
04de7dda | 4352 | goto out; |
71129676 | 4353 | } |
04de7dda RD |
4354 | |
4355 | flow->peer_flow = peer_flow; | |
226f2ca3 | 4356 | flow_flag_set(flow, DUP); |
04de7dda RD |
4357 | mutex_lock(&esw->offloads.peer_mutex); |
4358 | list_add_tail(&flow->peer, &esw->offloads.peer_flows); | |
4359 | mutex_unlock(&esw->offloads.peer_mutex); | |
4360 | ||
4361 | out: | |
4362 | mlx5_devcom_release_peer_data(devcom, MLX5_DEVCOM_ESW_OFFLOADS); | |
4363 | return err; | |
4364 | } | |
4365 | ||
4366 | static int | |
4367 | mlx5e_add_fdb_flow(struct mlx5e_priv *priv, | |
f9e30088 | 4368 | struct flow_cls_offload *f, |
226f2ca3 | 4369 | unsigned long flow_flags, |
04de7dda RD |
4370 | struct net_device *filter_dev, |
4371 | struct mlx5e_tc_flow **__flow) | |
4372 | { | |
4373 | struct mlx5e_rep_priv *rpriv = priv->ppriv; | |
4374 | struct mlx5_eswitch_rep *in_rep = rpriv->rep; | |
4375 | struct mlx5_core_dev *in_mdev = priv->mdev; | |
4376 | struct mlx5e_tc_flow *flow; | |
4377 | int err; | |
4378 | ||
71129676 JG |
4379 | flow = __mlx5e_add_fdb_flow(priv, f, flow_flags, filter_dev, in_rep, |
4380 | in_mdev); | |
4381 | if (IS_ERR(flow)) | |
4382 | return PTR_ERR(flow); | |
04de7dda RD |
4383 | |
4384 | if (is_peer_flow_needed(flow)) { | |
95dc1902 | 4385 | err = mlx5e_tc_add_fdb_peer_flow(f, flow, flow_flags); |
04de7dda RD |
4386 | if (err) { |
4387 | mlx5e_tc_del_fdb_flow(priv, flow); | |
4388 | goto out; | |
4389 | } | |
4390 | } | |
4391 | ||
4392 | *__flow = flow; | |
4393 | ||
4394 | return 0; | |
4395 | ||
4396 | out: | |
4397 | return err; | |
4398 | } | |
4399 | ||
a88780a9 RD |
4400 | static int |
4401 | mlx5e_add_nic_flow(struct mlx5e_priv *priv, | |
f9e30088 | 4402 | struct flow_cls_offload *f, |
226f2ca3 | 4403 | unsigned long flow_flags, |
d11afc26 | 4404 | struct net_device *filter_dev, |
a88780a9 RD |
4405 | struct mlx5e_tc_flow **__flow) |
4406 | { | |
f9e30088 | 4407 | struct flow_rule *rule = flow_cls_offload_flow_rule(f); |
a88780a9 RD |
4408 | struct netlink_ext_ack *extack = f->common.extack; |
4409 | struct mlx5e_tc_flow_parse_attr *parse_attr; | |
4410 | struct mlx5e_tc_flow *flow; | |
4411 | int attr_size, err; | |
4412 | ||
c7569097 AL |
4413 | if (!MLX5_CAP_FLOWTABLE_NIC_RX(priv->mdev, ignore_flow_level)) { |
4414 | if (!tc_cls_can_offload_and_chain0(priv->netdev, &f->common)) | |
4415 | return -EOPNOTSUPP; | |
4416 | } else if (!tc_can_offload_extack(priv->netdev, f->common.extack)) { | |
bf07aa73 | 4417 | return -EOPNOTSUPP; |
c7569097 | 4418 | } |
bf07aa73 | 4419 | |
226f2ca3 | 4420 | flow_flags |= BIT(MLX5E_TC_FLOW_FLAG_NIC); |
a88780a9 RD |
4421 | attr_size = sizeof(struct mlx5_nic_flow_attr); |
4422 | err = mlx5e_alloc_flow(priv, attr_size, f, flow_flags, | |
4423 | &parse_attr, &flow); | |
4424 | if (err) | |
4425 | goto out; | |
4426 | ||
d11afc26 | 4427 | parse_attr->filter_dev = filter_dev; |
c7569097 AL |
4428 | mlx5e_flow_attr_init(flow->attr, parse_attr, f); |
4429 | ||
54c177ca OS |
4430 | err = parse_cls_flower(flow->priv, flow, &parse_attr->spec, |
4431 | f, filter_dev); | |
d11afc26 OS |
4432 | if (err) |
4433 | goto err_free; | |
4434 | ||
aedd133d AL |
4435 | err = mlx5_tc_ct_match_add(get_ct_priv(priv), &parse_attr->spec, f, |
4436 | &flow->attr->ct_attr, extack); | |
4437 | if (err) | |
4438 | goto err_free; | |
4439 | ||
c6cfe113 | 4440 | err = parse_tc_nic_actions(priv, &rule->action, flow, extack); |
a88780a9 RD |
4441 | if (err) |
4442 | goto err_free; | |
4443 | ||
c6cfe113 | 4444 | err = mlx5e_tc_add_nic_flow(priv, flow, extack); |
a88780a9 RD |
4445 | if (err) |
4446 | goto err_free; | |
4447 | ||
226f2ca3 | 4448 | flow_flag_set(flow, OFFLOADED); |
a88780a9 RD |
4449 | *__flow = flow; |
4450 | ||
4451 | return 0; | |
e3a2b7ed | 4452 | |
e3a2b7ed | 4453 | err_free: |
8914add2 | 4454 | flow_flag_set(flow, FAILED); |
e68e28b4 | 4455 | dealloc_mod_hdr_actions(&parse_attr->mod_hdr_acts); |
5a7e5bcb | 4456 | mlx5e_flow_put(priv, flow); |
a88780a9 RD |
4457 | out: |
4458 | return err; | |
4459 | } | |
4460 | ||
4461 | static int | |
4462 | mlx5e_tc_add_flow(struct mlx5e_priv *priv, | |
f9e30088 | 4463 | struct flow_cls_offload *f, |
226f2ca3 | 4464 | unsigned long flags, |
d11afc26 | 4465 | struct net_device *filter_dev, |
a88780a9 RD |
4466 | struct mlx5e_tc_flow **flow) |
4467 | { | |
4468 | struct mlx5_eswitch *esw = priv->mdev->priv.eswitch; | |
226f2ca3 | 4469 | unsigned long flow_flags; |
a88780a9 RD |
4470 | int err; |
4471 | ||
4472 | get_flags(flags, &flow_flags); | |
4473 | ||
bf07aa73 PB |
4474 | if (!tc_can_offload_extack(priv->netdev, f->common.extack)) |
4475 | return -EOPNOTSUPP; | |
4476 | ||
f6455de0 | 4477 | if (esw && esw->mode == MLX5_ESWITCH_OFFLOADS) |
d11afc26 OS |
4478 | err = mlx5e_add_fdb_flow(priv, f, flow_flags, |
4479 | filter_dev, flow); | |
a88780a9 | 4480 | else |
d11afc26 OS |
4481 | err = mlx5e_add_nic_flow(priv, f, flow_flags, |
4482 | filter_dev, flow); | |
a88780a9 RD |
4483 | |
4484 | return err; | |
4485 | } | |
4486 | ||
553f9328 VP |
4487 | static bool is_flow_rule_duplicate_allowed(struct net_device *dev, |
4488 | struct mlx5e_rep_priv *rpriv) | |
4489 | { | |
4490 | /* Offloaded flow rule is allowed to duplicate on non-uplink representor | |
2fb15e72 VB |
4491 | * sharing tc block with other slaves of a lag device. Rpriv can be NULL if this |
4492 | * function is called from NIC mode. | |
553f9328 | 4493 | */ |
2fb15e72 | 4494 | return netif_is_lag_port(dev) && rpriv && rpriv->rep->vport != MLX5_VPORT_UPLINK; |
553f9328 VP |
4495 | } |
4496 | ||
71d82d2a | 4497 | int mlx5e_configure_flower(struct net_device *dev, struct mlx5e_priv *priv, |
226f2ca3 | 4498 | struct flow_cls_offload *f, unsigned long flags) |
a88780a9 RD |
4499 | { |
4500 | struct netlink_ext_ack *extack = f->common.extack; | |
d9ee0491 | 4501 | struct rhashtable *tc_ht = get_tc_ht(priv, flags); |
553f9328 | 4502 | struct mlx5e_rep_priv *rpriv = priv->ppriv; |
a88780a9 RD |
4503 | struct mlx5e_tc_flow *flow; |
4504 | int err = 0; | |
4505 | ||
7dc84de9 RD |
4506 | if (!mlx5_esw_hold(priv->mdev)) |
4507 | return -EAGAIN; | |
4508 | ||
4509 | mlx5_esw_get(priv->mdev); | |
4510 | ||
c5d326b2 VB |
4511 | rcu_read_lock(); |
4512 | flow = rhashtable_lookup(tc_ht, &f->cookie, tc_ht_params); | |
a88780a9 | 4513 | if (flow) { |
553f9328 VP |
4514 | /* Same flow rule offloaded to non-uplink representor sharing tc block, |
4515 | * just return 0. | |
4516 | */ | |
4517 | if (is_flow_rule_duplicate_allowed(dev, rpriv) && flow->orig_dev != dev) | |
c1aea9e1 | 4518 | goto rcu_unlock; |
553f9328 | 4519 | |
a88780a9 RD |
4520 | NL_SET_ERR_MSG_MOD(extack, |
4521 | "flow cookie already exists, ignoring"); | |
4522 | netdev_warn_once(priv->netdev, | |
4523 | "flow cookie %lx already exists, ignoring\n", | |
4524 | f->cookie); | |
0e1c1a2f | 4525 | err = -EEXIST; |
c1aea9e1 | 4526 | goto rcu_unlock; |
a88780a9 | 4527 | } |
c1aea9e1 VB |
4528 | rcu_unlock: |
4529 | rcu_read_unlock(); | |
4530 | if (flow) | |
4531 | goto out; | |
a88780a9 | 4532 | |
7a978759 | 4533 | trace_mlx5e_configure_flower(f); |
d11afc26 | 4534 | err = mlx5e_tc_add_flow(priv, f, flags, dev, &flow); |
a88780a9 RD |
4535 | if (err) |
4536 | goto out; | |
4537 | ||
553f9328 VP |
4538 | /* Flow rule offloaded to non-uplink representor sharing tc block, |
4539 | * set the flow's owner dev. | |
4540 | */ | |
4541 | if (is_flow_rule_duplicate_allowed(dev, rpriv)) | |
4542 | flow->orig_dev = dev; | |
4543 | ||
c5d326b2 | 4544 | err = rhashtable_lookup_insert_fast(tc_ht, &flow->node, tc_ht_params); |
a88780a9 RD |
4545 | if (err) |
4546 | goto err_free; | |
4547 | ||
7dc84de9 | 4548 | mlx5_esw_release(priv->mdev); |
a88780a9 RD |
4549 | return 0; |
4550 | ||
4551 | err_free: | |
5a7e5bcb | 4552 | mlx5e_flow_put(priv, flow); |
a88780a9 | 4553 | out: |
7dc84de9 RD |
4554 | mlx5_esw_put(priv->mdev); |
4555 | mlx5_esw_release(priv->mdev); | |
e3a2b7ed AV |
4556 | return err; |
4557 | } | |
4558 | ||
8f8ae895 OG |
4559 | static bool same_flow_direction(struct mlx5e_tc_flow *flow, int flags) |
4560 | { | |
226f2ca3 VB |
4561 | bool dir_ingress = !!(flags & MLX5_TC_FLAG(INGRESS)); |
4562 | bool dir_egress = !!(flags & MLX5_TC_FLAG(EGRESS)); | |
8f8ae895 | 4563 | |
226f2ca3 VB |
4564 | return flow_flag_test(flow, INGRESS) == dir_ingress && |
4565 | flow_flag_test(flow, EGRESS) == dir_egress; | |
8f8ae895 OG |
4566 | } |
4567 | ||
71d82d2a | 4568 | int mlx5e_delete_flower(struct net_device *dev, struct mlx5e_priv *priv, |
226f2ca3 | 4569 | struct flow_cls_offload *f, unsigned long flags) |
e3a2b7ed | 4570 | { |
d9ee0491 | 4571 | struct rhashtable *tc_ht = get_tc_ht(priv, flags); |
e3a2b7ed | 4572 | struct mlx5e_tc_flow *flow; |
c5d326b2 | 4573 | int err; |
e3a2b7ed | 4574 | |
c5d326b2 | 4575 | rcu_read_lock(); |
ab818362 | 4576 | flow = rhashtable_lookup(tc_ht, &f->cookie, tc_ht_params); |
c5d326b2 VB |
4577 | if (!flow || !same_flow_direction(flow, flags)) { |
4578 | err = -EINVAL; | |
4579 | goto errout; | |
4580 | } | |
e3a2b7ed | 4581 | |
c5d326b2 VB |
4582 | /* Only delete the flow if it doesn't have MLX5E_TC_FLOW_DELETED flag |
4583 | * set. | |
4584 | */ | |
4585 | if (flow_flag_test_and_set(flow, DELETED)) { | |
4586 | err = -EINVAL; | |
4587 | goto errout; | |
4588 | } | |
05866c82 | 4589 | rhashtable_remove_fast(tc_ht, &flow->node, tc_ht_params); |
c5d326b2 | 4590 | rcu_read_unlock(); |
e3a2b7ed | 4591 | |
7a978759 | 4592 | trace_mlx5e_delete_flower(f); |
5a7e5bcb | 4593 | mlx5e_flow_put(priv, flow); |
e3a2b7ed | 4594 | |
7dc84de9 | 4595 | mlx5_esw_put(priv->mdev); |
e3a2b7ed | 4596 | return 0; |
c5d326b2 VB |
4597 | |
4598 | errout: | |
4599 | rcu_read_unlock(); | |
4600 | return err; | |
e3a2b7ed AV |
4601 | } |
4602 | ||
71d82d2a | 4603 | int mlx5e_stats_flower(struct net_device *dev, struct mlx5e_priv *priv, |
226f2ca3 | 4604 | struct flow_cls_offload *f, unsigned long flags) |
aad7e08d | 4605 | { |
04de7dda | 4606 | struct mlx5_devcom *devcom = priv->mdev->priv.devcom; |
d9ee0491 | 4607 | struct rhashtable *tc_ht = get_tc_ht(priv, flags); |
04de7dda | 4608 | struct mlx5_eswitch *peer_esw; |
aad7e08d | 4609 | struct mlx5e_tc_flow *flow; |
aad7e08d | 4610 | struct mlx5_fc *counter; |
316d5f72 RD |
4611 | u64 lastuse = 0; |
4612 | u64 packets = 0; | |
4613 | u64 bytes = 0; | |
5a7e5bcb | 4614 | int err = 0; |
aad7e08d | 4615 | |
c5d326b2 VB |
4616 | rcu_read_lock(); |
4617 | flow = mlx5e_flow_get(rhashtable_lookup(tc_ht, &f->cookie, | |
4618 | tc_ht_params)); | |
4619 | rcu_read_unlock(); | |
5a7e5bcb VB |
4620 | if (IS_ERR(flow)) |
4621 | return PTR_ERR(flow); | |
4622 | ||
4623 | if (!same_flow_direction(flow, flags)) { | |
4624 | err = -EINVAL; | |
4625 | goto errout; | |
4626 | } | |
aad7e08d | 4627 | |
4c3844d9 | 4628 | if (mlx5e_is_offloaded_flow(flow) || flow_flag_test(flow, CT)) { |
316d5f72 RD |
4629 | counter = mlx5e_tc_get_counter(flow); |
4630 | if (!counter) | |
5a7e5bcb | 4631 | goto errout; |
aad7e08d | 4632 | |
316d5f72 RD |
4633 | mlx5_fc_query_cached(counter, &bytes, &packets, &lastuse); |
4634 | } | |
aad7e08d | 4635 | |
316d5f72 RD |
4636 | /* Under multipath it's possible for one rule to be currently |
4637 | * un-offloaded while the other rule is offloaded. | |
4638 | */ | |
04de7dda RD |
4639 | peer_esw = mlx5_devcom_get_peer_data(devcom, MLX5_DEVCOM_ESW_OFFLOADS); |
4640 | if (!peer_esw) | |
4641 | goto out; | |
4642 | ||
226f2ca3 VB |
4643 | if (flow_flag_test(flow, DUP) && |
4644 | flow_flag_test(flow->peer_flow, OFFLOADED)) { | |
04de7dda RD |
4645 | u64 bytes2; |
4646 | u64 packets2; | |
4647 | u64 lastuse2; | |
4648 | ||
4649 | counter = mlx5e_tc_get_counter(flow->peer_flow); | |
316d5f72 RD |
4650 | if (!counter) |
4651 | goto no_peer_counter; | |
04de7dda RD |
4652 | mlx5_fc_query_cached(counter, &bytes2, &packets2, &lastuse2); |
4653 | ||
4654 | bytes += bytes2; | |
4655 | packets += packets2; | |
4656 | lastuse = max_t(u64, lastuse, lastuse2); | |
4657 | } | |
4658 | ||
316d5f72 | 4659 | no_peer_counter: |
04de7dda | 4660 | mlx5_devcom_release_peer_data(devcom, MLX5_DEVCOM_ESW_OFFLOADS); |
04de7dda | 4661 | out: |
4b61d3e8 | 4662 | flow_stats_update(&f->stats, bytes, packets, 0, lastuse, |
93a129eb | 4663 | FLOW_ACTION_HW_STATS_DELAYED); |
7a978759 | 4664 | trace_mlx5e_stats_flower(f); |
5a7e5bcb VB |
4665 | errout: |
4666 | mlx5e_flow_put(priv, flow); | |
4667 | return err; | |
aad7e08d AV |
4668 | } |
4669 | ||
1fe3e316 | 4670 | static int apply_police_params(struct mlx5e_priv *priv, u64 rate, |
fcb64c0f EC |
4671 | struct netlink_ext_ack *extack) |
4672 | { | |
4673 | struct mlx5e_rep_priv *rpriv = priv->ppriv; | |
4674 | struct mlx5_eswitch *esw; | |
1fe3e316 | 4675 | u32 rate_mbps = 0; |
fcb64c0f | 4676 | u16 vport_num; |
fcb64c0f EC |
4677 | int err; |
4678 | ||
e401a184 EC |
4679 | vport_num = rpriv->rep->vport; |
4680 | if (vport_num >= MLX5_VPORT_ECPF) { | |
4681 | NL_SET_ERR_MSG_MOD(extack, | |
4682 | "Ingress rate limit is supported only for Eswitch ports connected to VFs"); | |
4683 | return -EOPNOTSUPP; | |
4684 | } | |
4685 | ||
fcb64c0f EC |
4686 | esw = priv->mdev->priv.eswitch; |
4687 | /* rate is given in bytes/sec. | |
4688 | * First convert to bits/sec and then round to the nearest mbit/secs. | |
4689 | * mbit means million bits. | |
4690 | * Moreover, if rate is non zero we choose to configure to a minimum of | |
4691 | * 1 mbit/sec. | |
4692 | */ | |
1fe3e316 PP |
4693 | if (rate) { |
4694 | rate = (rate * BITS_PER_BYTE) + 500000; | |
8b90d897 PP |
4695 | do_div(rate, 1000000); |
4696 | rate_mbps = max_t(u32, rate, 1); | |
1fe3e316 PP |
4697 | } |
4698 | ||
2d116e3e | 4699 | err = mlx5_esw_qos_modify_vport_rate(esw, vport_num, rate_mbps); |
fcb64c0f EC |
4700 | if (err) |
4701 | NL_SET_ERR_MSG_MOD(extack, "failed applying action to hardware"); | |
4702 | ||
4703 | return err; | |
4704 | } | |
4705 | ||
4706 | static int scan_tc_matchall_fdb_actions(struct mlx5e_priv *priv, | |
4707 | struct flow_action *flow_action, | |
4708 | struct netlink_ext_ack *extack) | |
4709 | { | |
4710 | struct mlx5e_rep_priv *rpriv = priv->ppriv; | |
4711 | const struct flow_action_entry *act; | |
4712 | int err; | |
4713 | int i; | |
4714 | ||
4715 | if (!flow_action_has_entries(flow_action)) { | |
4716 | NL_SET_ERR_MSG_MOD(extack, "matchall called with no action"); | |
4717 | return -EINVAL; | |
4718 | } | |
4719 | ||
4720 | if (!flow_offload_has_one_action(flow_action)) { | |
4721 | NL_SET_ERR_MSG_MOD(extack, "matchall policing support only a single action"); | |
4722 | return -EOPNOTSUPP; | |
4723 | } | |
4724 | ||
53eca1f3 | 4725 | if (!flow_action_basic_hw_stats_check(flow_action, extack)) |
319a1d19 JP |
4726 | return -EOPNOTSUPP; |
4727 | ||
fcb64c0f EC |
4728 | flow_action_for_each(i, act, flow_action) { |
4729 | switch (act->id) { | |
4730 | case FLOW_ACTION_POLICE: | |
6a56e199 BZ |
4731 | if (act->police.rate_pkt_ps) { |
4732 | NL_SET_ERR_MSG_MOD(extack, "QoS offload not support packets per second"); | |
4733 | return -EOPNOTSUPP; | |
4734 | } | |
fcb64c0f EC |
4735 | err = apply_police_params(priv, act->police.rate_bytes_ps, extack); |
4736 | if (err) | |
4737 | return err; | |
4738 | ||
4739 | rpriv->prev_vf_vport_stats = priv->stats.vf_vport; | |
4740 | break; | |
4741 | default: | |
4742 | NL_SET_ERR_MSG_MOD(extack, "mlx5 supports only police action for matchall"); | |
4743 | return -EOPNOTSUPP; | |
4744 | } | |
4745 | } | |
4746 | ||
4747 | return 0; | |
4748 | } | |
4749 | ||
4750 | int mlx5e_tc_configure_matchall(struct mlx5e_priv *priv, | |
4751 | struct tc_cls_matchall_offload *ma) | |
4752 | { | |
b5f814cc | 4753 | struct mlx5_eswitch *esw = priv->mdev->priv.eswitch; |
fcb64c0f | 4754 | struct netlink_ext_ack *extack = ma->common.extack; |
fcb64c0f | 4755 | |
b5f814cc EC |
4756 | if (!mlx5_esw_qos_enabled(esw)) { |
4757 | NL_SET_ERR_MSG_MOD(extack, "QoS is not supported on this device"); | |
4758 | return -EOPNOTSUPP; | |
4759 | } | |
4760 | ||
7b83355f | 4761 | if (ma->common.prio != 1) { |
fcb64c0f EC |
4762 | NL_SET_ERR_MSG_MOD(extack, "only priority 1 is supported"); |
4763 | return -EINVAL; | |
4764 | } | |
4765 | ||
4766 | return scan_tc_matchall_fdb_actions(priv, &ma->rule->action, extack); | |
4767 | } | |
4768 | ||
4769 | int mlx5e_tc_delete_matchall(struct mlx5e_priv *priv, | |
4770 | struct tc_cls_matchall_offload *ma) | |
4771 | { | |
4772 | struct netlink_ext_ack *extack = ma->common.extack; | |
4773 | ||
4774 | return apply_police_params(priv, 0, extack); | |
4775 | } | |
4776 | ||
4777 | void mlx5e_tc_stats_matchall(struct mlx5e_priv *priv, | |
4778 | struct tc_cls_matchall_offload *ma) | |
4779 | { | |
4780 | struct mlx5e_rep_priv *rpriv = priv->ppriv; | |
4781 | struct rtnl_link_stats64 cur_stats; | |
4782 | u64 dbytes; | |
4783 | u64 dpkts; | |
4784 | ||
4785 | cur_stats = priv->stats.vf_vport; | |
4786 | dpkts = cur_stats.rx_packets - rpriv->prev_vf_vport_stats.rx_packets; | |
4787 | dbytes = cur_stats.rx_bytes - rpriv->prev_vf_vport_stats.rx_bytes; | |
4788 | rpriv->prev_vf_vport_stats = cur_stats; | |
4b61d3e8 | 4789 | flow_stats_update(&ma->stats, dbytes, dpkts, 0, jiffies, |
93a129eb | 4790 | FLOW_ACTION_HW_STATS_DELAYED); |
fcb64c0f EC |
4791 | } |
4792 | ||
4d8fcf21 AH |
4793 | static void mlx5e_tc_hairpin_update_dead_peer(struct mlx5e_priv *priv, |
4794 | struct mlx5e_priv *peer_priv) | |
4795 | { | |
4796 | struct mlx5_core_dev *peer_mdev = peer_priv->mdev; | |
db76ca24 VB |
4797 | struct mlx5e_hairpin_entry *hpe, *tmp; |
4798 | LIST_HEAD(init_wait_list); | |
4d8fcf21 AH |
4799 | u16 peer_vhca_id; |
4800 | int bkt; | |
4801 | ||
4802 | if (!same_hw_devs(priv, peer_priv)) | |
4803 | return; | |
4804 | ||
4805 | peer_vhca_id = MLX5_CAP_GEN(peer_mdev, vhca_id); | |
4806 | ||
b32accda | 4807 | mutex_lock(&priv->fs.tc.hairpin_tbl_lock); |
db76ca24 VB |
4808 | hash_for_each(priv->fs.tc.hairpin_tbl, bkt, hpe, hairpin_hlist) |
4809 | if (refcount_inc_not_zero(&hpe->refcnt)) | |
4810 | list_add(&hpe->dead_peer_wait_list, &init_wait_list); | |
4811 | mutex_unlock(&priv->fs.tc.hairpin_tbl_lock); | |
4812 | ||
4813 | list_for_each_entry_safe(hpe, tmp, &init_wait_list, dead_peer_wait_list) { | |
4814 | wait_for_completion(&hpe->res_ready); | |
4815 | if (!IS_ERR_OR_NULL(hpe->hp) && hpe->peer_vhca_id == peer_vhca_id) | |
a3e5fd93 | 4816 | mlx5_core_hairpin_clear_dead_peer(hpe->hp->pair); |
db76ca24 VB |
4817 | |
4818 | mlx5e_hairpin_put(priv, hpe); | |
4d8fcf21 AH |
4819 | } |
4820 | } | |
4821 | ||
4822 | static int mlx5e_tc_netdev_event(struct notifier_block *this, | |
4823 | unsigned long event, void *ptr) | |
4824 | { | |
4825 | struct net_device *ndev = netdev_notifier_info_to_dev(ptr); | |
4826 | struct mlx5e_flow_steering *fs; | |
4827 | struct mlx5e_priv *peer_priv; | |
4828 | struct mlx5e_tc_table *tc; | |
4829 | struct mlx5e_priv *priv; | |
4830 | ||
4831 | if (ndev->netdev_ops != &mlx5e_netdev_ops || | |
4832 | event != NETDEV_UNREGISTER || | |
4833 | ndev->reg_state == NETREG_REGISTERED) | |
4834 | return NOTIFY_DONE; | |
4835 | ||
4836 | tc = container_of(this, struct mlx5e_tc_table, netdevice_nb); | |
4837 | fs = container_of(tc, struct mlx5e_flow_steering, tc); | |
4838 | priv = container_of(fs, struct mlx5e_priv, fs); | |
4839 | peer_priv = netdev_priv(ndev); | |
4840 | if (priv == peer_priv || | |
4841 | !(priv->netdev->features & NETIF_F_HW_TC)) | |
4842 | return NOTIFY_DONE; | |
4843 | ||
4844 | mlx5e_tc_hairpin_update_dead_peer(priv, peer_priv); | |
4845 | ||
4846 | return NOTIFY_DONE; | |
4847 | } | |
4848 | ||
6a064674 AL |
4849 | static int mlx5e_tc_nic_get_ft_size(struct mlx5_core_dev *dev) |
4850 | { | |
4851 | int tc_grp_size, tc_tbl_size; | |
4852 | u32 max_flow_counter; | |
4853 | ||
4854 | max_flow_counter = (MLX5_CAP_GEN(dev, max_flow_counter_31_16) << 16) | | |
4855 | MLX5_CAP_GEN(dev, max_flow_counter_15_0); | |
4856 | ||
4857 | tc_grp_size = min_t(int, max_flow_counter, MLX5E_TC_TABLE_MAX_GROUP_SIZE); | |
4858 | ||
4859 | tc_tbl_size = min_t(int, tc_grp_size * MLX5E_TC_TABLE_NUM_GROUPS, | |
4860 | BIT(MLX5_CAP_FLOWTABLE_NIC_RX(dev, log_max_ft_size))); | |
4861 | ||
4862 | return tc_tbl_size; | |
4863 | } | |
4864 | ||
655dc3d2 | 4865 | int mlx5e_tc_nic_init(struct mlx5e_priv *priv) |
e8f887ac | 4866 | { |
acff797c | 4867 | struct mlx5e_tc_table *tc = &priv->fs.tc; |
6a064674 | 4868 | struct mlx5_core_dev *dev = priv->mdev; |
c9355682 | 4869 | struct mapping_ctx *chains_mapping; |
6a064674 | 4870 | struct mlx5_chains_attr attr = {}; |
2198b932 | 4871 | u64 mapping_id; |
4d8fcf21 | 4872 | int err; |
e8f887ac | 4873 | |
b2fdf3d0 | 4874 | mlx5e_mod_hdr_tbl_init(&tc->mod_hdr); |
b6fac0b4 | 4875 | mutex_init(&tc->t_lock); |
b32accda | 4876 | mutex_init(&tc->hairpin_tbl_lock); |
5c65c564 | 4877 | hash_init(tc->hairpin_tbl); |
11c9c548 | 4878 | |
4d8fcf21 AH |
4879 | err = rhashtable_init(&tc->ht, &tc_ht_params); |
4880 | if (err) | |
4881 | return err; | |
4882 | ||
9ba33339 RD |
4883 | lockdep_set_class(&tc->ht.mutex, &tc_ht_lock_key); |
4884 | ||
2198b932 RD |
4885 | mapping_id = mlx5_query_nic_system_image_guid(dev); |
4886 | ||
4887 | chains_mapping = mapping_create_for_id(mapping_id, MAPPING_TYPE_CHAIN, | |
4888 | sizeof(struct mlx5_mapped_obj), | |
4889 | MLX5E_TC_TABLE_CHAIN_TAG_MASK, true); | |
4890 | ||
c9355682 CM |
4891 | if (IS_ERR(chains_mapping)) { |
4892 | err = PTR_ERR(chains_mapping); | |
4893 | goto err_mapping; | |
4894 | } | |
4895 | tc->mapping = chains_mapping; | |
4896 | ||
4897 | if (MLX5_CAP_FLOWTABLE_NIC_RX(priv->mdev, ignore_flow_level)) | |
c7569097 AL |
4898 | attr.flags = MLX5_CHAINS_AND_PRIOS_SUPPORTED | |
4899 | MLX5_CHAINS_IGNORE_FLOW_LEVEL_SUPPORTED; | |
6a064674 AL |
4900 | attr.ns = MLX5_FLOW_NAMESPACE_KERNEL; |
4901 | attr.max_ft_sz = mlx5e_tc_nic_get_ft_size(dev); | |
4902 | attr.max_grp_num = MLX5E_TC_TABLE_NUM_GROUPS; | |
6783f0a2 | 4903 | attr.default_ft = mlx5e_vlan_get_flowtable(priv->fs.vlan); |
c9355682 | 4904 | attr.mapping = chains_mapping; |
6a064674 AL |
4905 | |
4906 | tc->chains = mlx5_chains_create(dev, &attr); | |
4907 | if (IS_ERR(tc->chains)) { | |
4908 | err = PTR_ERR(tc->chains); | |
4909 | goto err_chains; | |
4910 | } | |
4911 | ||
f0da4daa | 4912 | tc->post_act = mlx5e_tc_post_act_init(priv, tc->chains, MLX5_FLOW_NAMESPACE_KERNEL); |
aedd133d | 4913 | tc->ct = mlx5_tc_ct_init(priv, tc->chains, &priv->fs.tc.mod_hdr, |
f0da4daa | 4914 | MLX5_FLOW_NAMESPACE_KERNEL, tc->post_act); |
aedd133d | 4915 | |
4d8fcf21 | 4916 | tc->netdevice_nb.notifier_call = mlx5e_tc_netdev_event; |
d48834f9 JP |
4917 | err = register_netdevice_notifier_dev_net(priv->netdev, |
4918 | &tc->netdevice_nb, | |
4919 | &tc->netdevice_nn); | |
4920 | if (err) { | |
4d8fcf21 AH |
4921 | tc->netdevice_nb.notifier_call = NULL; |
4922 | mlx5_core_warn(priv->mdev, "Failed to register netdev notifier\n"); | |
6a064674 | 4923 | goto err_reg; |
4d8fcf21 AH |
4924 | } |
4925 | ||
6a064674 AL |
4926 | return 0; |
4927 | ||
4928 | err_reg: | |
aedd133d | 4929 | mlx5_tc_ct_clean(tc->ct); |
f0da4daa | 4930 | mlx5e_tc_post_act_destroy(tc->post_act); |
6a064674 AL |
4931 | mlx5_chains_destroy(tc->chains); |
4932 | err_chains: | |
c9355682 CM |
4933 | mapping_destroy(chains_mapping); |
4934 | err_mapping: | |
6a064674 | 4935 | rhashtable_destroy(&tc->ht); |
4d8fcf21 | 4936 | return err; |
e8f887ac AV |
4937 | } |
4938 | ||
4939 | static void _mlx5e_tc_del_flow(void *ptr, void *arg) | |
4940 | { | |
4941 | struct mlx5e_tc_flow *flow = ptr; | |
655dc3d2 | 4942 | struct mlx5e_priv *priv = flow->priv; |
e8f887ac | 4943 | |
961e8979 | 4944 | mlx5e_tc_del_flow(priv, flow); |
e8f887ac AV |
4945 | kfree(flow); |
4946 | } | |
4947 | ||
655dc3d2 | 4948 | void mlx5e_tc_nic_cleanup(struct mlx5e_priv *priv) |
e8f887ac | 4949 | { |
acff797c | 4950 | struct mlx5e_tc_table *tc = &priv->fs.tc; |
e8f887ac | 4951 | |
4d8fcf21 | 4952 | if (tc->netdevice_nb.notifier_call) |
d48834f9 JP |
4953 | unregister_netdevice_notifier_dev_net(priv->netdev, |
4954 | &tc->netdevice_nb, | |
4955 | &tc->netdevice_nn); | |
4d8fcf21 | 4956 | |
b2fdf3d0 | 4957 | mlx5e_mod_hdr_tbl_destroy(&tc->mod_hdr); |
b32accda VB |
4958 | mutex_destroy(&tc->hairpin_tbl_lock); |
4959 | ||
6a064674 | 4960 | rhashtable_free_and_destroy(&tc->ht, _mlx5e_tc_del_flow, NULL); |
e8f887ac | 4961 | |
acff797c | 4962 | if (!IS_ERR_OR_NULL(tc->t)) { |
6a064674 | 4963 | mlx5_chains_put_table(tc->chains, 0, 1, MLX5E_TC_FT_LEVEL); |
acff797c | 4964 | tc->t = NULL; |
e8f887ac | 4965 | } |
b6fac0b4 | 4966 | mutex_destroy(&tc->t_lock); |
6a064674 | 4967 | |
aedd133d | 4968 | mlx5_tc_ct_clean(tc->ct); |
f0da4daa | 4969 | mlx5e_tc_post_act_destroy(tc->post_act); |
c9355682 | 4970 | mapping_destroy(tc->mapping); |
6a064674 | 4971 | mlx5_chains_destroy(tc->chains); |
e8f887ac | 4972 | } |
655dc3d2 OG |
4973 | |
4974 | int mlx5e_tc_esw_init(struct rhashtable *tc_ht) | |
4975 | { | |
d7a42ad0 | 4976 | const size_t sz_enc_opts = sizeof(struct tunnel_match_enc_opts); |
0a7fcb78 | 4977 | struct mlx5_rep_uplink_priv *uplink_priv; |
aedd133d | 4978 | struct mlx5e_rep_priv *rpriv; |
0a7fcb78 | 4979 | struct mapping_ctx *mapping; |
aedd133d AL |
4980 | struct mlx5_eswitch *esw; |
4981 | struct mlx5e_priv *priv; | |
2198b932 | 4982 | u64 mapping_id; |
aedd133d | 4983 | int err = 0; |
0a7fcb78 PB |
4984 | |
4985 | uplink_priv = container_of(tc_ht, struct mlx5_rep_uplink_priv, tc_ht); | |
aedd133d AL |
4986 | rpriv = container_of(uplink_priv, struct mlx5e_rep_priv, uplink_priv); |
4987 | priv = netdev_priv(rpriv->netdev); | |
4988 | esw = priv->mdev->priv.eswitch; | |
0a7fcb78 | 4989 | |
f0da4daa CM |
4990 | uplink_priv->post_act = mlx5e_tc_post_act_init(priv, esw_chains(esw), |
4991 | MLX5_FLOW_NAMESPACE_FDB); | |
aedd133d AL |
4992 | uplink_priv->ct_priv = mlx5_tc_ct_init(netdev_priv(priv->netdev), |
4993 | esw_chains(esw), | |
4994 | &esw->offloads.mod_hdr, | |
f0da4daa CM |
4995 | MLX5_FLOW_NAMESPACE_FDB, |
4996 | uplink_priv->post_act); | |
4c3844d9 | 4997 | |
2a9ab10a | 4998 | #if IS_ENABLED(CONFIG_MLX5_TC_SAMPLE) |
2741f223 | 4999 | uplink_priv->tc_psample = mlx5e_tc_sample_init(esw, uplink_priv->post_act); |
2a9ab10a CM |
5000 | #endif |
5001 | ||
2198b932 RD |
5002 | mapping_id = mlx5_query_nic_system_image_guid(esw->dev); |
5003 | ||
5004 | mapping = mapping_create_for_id(mapping_id, MAPPING_TYPE_TUNNEL, | |
5005 | sizeof(struct tunnel_match_key), | |
5006 | TUNNEL_INFO_BITS_MASK, true); | |
5007 | ||
0a7fcb78 PB |
5008 | if (IS_ERR(mapping)) { |
5009 | err = PTR_ERR(mapping); | |
5010 | goto err_tun_mapping; | |
5011 | } | |
5012 | uplink_priv->tunnel_mapping = mapping; | |
5013 | ||
8e404fef | 5014 | /* 0xFFF is reserved for stack devices slow path table mark */ |
2198b932 RD |
5015 | mapping = mapping_create_for_id(mapping_id, MAPPING_TYPE_TUNNEL_ENC_OPTS, |
5016 | sz_enc_opts, ENC_OPTS_BITS_MASK - 1, true); | |
0a7fcb78 PB |
5017 | if (IS_ERR(mapping)) { |
5018 | err = PTR_ERR(mapping); | |
5019 | goto err_enc_opts_mapping; | |
5020 | } | |
5021 | uplink_priv->tunnel_enc_opts_mapping = mapping; | |
5022 | ||
5023 | err = rhashtable_init(tc_ht, &tc_ht_params); | |
5024 | if (err) | |
5025 | goto err_ht_init; | |
5026 | ||
9ba33339 RD |
5027 | lockdep_set_class(&tc_ht->mutex, &tc_ht_lock_key); |
5028 | ||
8914add2 | 5029 | uplink_priv->encap = mlx5e_tc_tun_init(priv); |
2b6c3c1e WY |
5030 | if (IS_ERR(uplink_priv->encap)) { |
5031 | err = PTR_ERR(uplink_priv->encap); | |
8914add2 | 5032 | goto err_register_fib_notifier; |
2b6c3c1e | 5033 | } |
8914add2 | 5034 | |
2b6c3c1e | 5035 | return 0; |
0a7fcb78 | 5036 | |
8914add2 VB |
5037 | err_register_fib_notifier: |
5038 | rhashtable_destroy(tc_ht); | |
0a7fcb78 PB |
5039 | err_ht_init: |
5040 | mapping_destroy(uplink_priv->tunnel_enc_opts_mapping); | |
5041 | err_enc_opts_mapping: | |
5042 | mapping_destroy(uplink_priv->tunnel_mapping); | |
5043 | err_tun_mapping: | |
2a9ab10a | 5044 | #if IS_ENABLED(CONFIG_MLX5_TC_SAMPLE) |
0027d70c | 5045 | mlx5e_tc_sample_cleanup(uplink_priv->tc_psample); |
2a9ab10a | 5046 | #endif |
aedd133d | 5047 | mlx5_tc_ct_clean(uplink_priv->ct_priv); |
0a7fcb78 PB |
5048 | netdev_warn(priv->netdev, |
5049 | "Failed to initialize tc (eswitch), err: %d", err); | |
f0da4daa | 5050 | mlx5e_tc_post_act_destroy(uplink_priv->post_act); |
0a7fcb78 | 5051 | return err; |
655dc3d2 OG |
5052 | } |
5053 | ||
5054 | void mlx5e_tc_esw_cleanup(struct rhashtable *tc_ht) | |
5055 | { | |
0a7fcb78 PB |
5056 | struct mlx5_rep_uplink_priv *uplink_priv; |
5057 | ||
0a7fcb78 | 5058 | uplink_priv = container_of(tc_ht, struct mlx5_rep_uplink_priv, tc_ht); |
aedd133d | 5059 | |
8914add2 VB |
5060 | rhashtable_free_and_destroy(tc_ht, _mlx5e_tc_del_flow, NULL); |
5061 | mlx5e_tc_tun_cleanup(uplink_priv->encap); | |
5062 | ||
0a7fcb78 PB |
5063 | mapping_destroy(uplink_priv->tunnel_enc_opts_mapping); |
5064 | mapping_destroy(uplink_priv->tunnel_mapping); | |
4c3844d9 | 5065 | |
2a9ab10a | 5066 | #if IS_ENABLED(CONFIG_MLX5_TC_SAMPLE) |
0027d70c | 5067 | mlx5e_tc_sample_cleanup(uplink_priv->tc_psample); |
2a9ab10a | 5068 | #endif |
aedd133d | 5069 | mlx5_tc_ct_clean(uplink_priv->ct_priv); |
f0da4daa | 5070 | mlx5e_tc_post_act_destroy(uplink_priv->post_act); |
655dc3d2 | 5071 | } |
01252a27 | 5072 | |
226f2ca3 | 5073 | int mlx5e_tc_num_filters(struct mlx5e_priv *priv, unsigned long flags) |
01252a27 | 5074 | { |
d9ee0491 | 5075 | struct rhashtable *tc_ht = get_tc_ht(priv, flags); |
01252a27 OG |
5076 | |
5077 | return atomic_read(&tc_ht->nelems); | |
5078 | } | |
04de7dda RD |
5079 | |
5080 | void mlx5e_tc_clean_fdb_peer_flows(struct mlx5_eswitch *esw) | |
5081 | { | |
5082 | struct mlx5e_tc_flow *flow, *tmp; | |
5083 | ||
5084 | list_for_each_entry_safe(flow, tmp, &esw->offloads.peer_flows, peer) | |
5085 | __mlx5e_tc_del_fdb_peer_flow(flow); | |
5086 | } | |
b4a23329 RD |
5087 | |
5088 | void mlx5e_tc_reoffload_flows_work(struct work_struct *work) | |
5089 | { | |
5090 | struct mlx5_rep_uplink_priv *rpriv = | |
5091 | container_of(work, struct mlx5_rep_uplink_priv, | |
5092 | reoffload_flows_work); | |
5093 | struct mlx5e_tc_flow *flow, *tmp; | |
5094 | ||
ad86755b | 5095 | mutex_lock(&rpriv->unready_flows_lock); |
b4a23329 RD |
5096 | list_for_each_entry_safe(flow, tmp, &rpriv->unready_flows, unready) { |
5097 | if (!mlx5e_tc_add_fdb_flow(flow->priv, flow, NULL)) | |
ad86755b | 5098 | unready_flow_del(flow); |
b4a23329 | 5099 | } |
ad86755b | 5100 | mutex_unlock(&rpriv->unready_flows_lock); |
b4a23329 | 5101 | } |
e2394a61 VB |
5102 | |
5103 | static int mlx5e_setup_tc_cls_flower(struct mlx5e_priv *priv, | |
5104 | struct flow_cls_offload *cls_flower, | |
5105 | unsigned long flags) | |
5106 | { | |
5107 | switch (cls_flower->command) { | |
5108 | case FLOW_CLS_REPLACE: | |
5109 | return mlx5e_configure_flower(priv->netdev, priv, cls_flower, | |
5110 | flags); | |
5111 | case FLOW_CLS_DESTROY: | |
5112 | return mlx5e_delete_flower(priv->netdev, priv, cls_flower, | |
5113 | flags); | |
5114 | case FLOW_CLS_STATS: | |
5115 | return mlx5e_stats_flower(priv->netdev, priv, cls_flower, | |
5116 | flags); | |
5117 | default: | |
5118 | return -EOPNOTSUPP; | |
5119 | } | |
5120 | } | |
5121 | ||
5122 | int mlx5e_setup_tc_block_cb(enum tc_setup_type type, void *type_data, | |
5123 | void *cb_priv) | |
5124 | { | |
ec9457a6 | 5125 | unsigned long flags = MLX5_TC_FLAG(INGRESS); |
e2394a61 VB |
5126 | struct mlx5e_priv *priv = cb_priv; |
5127 | ||
2ff349c5 RD |
5128 | if (!priv->netdev || !netif_device_present(priv->netdev)) |
5129 | return -EOPNOTSUPP; | |
5130 | ||
ec9457a6 RD |
5131 | if (mlx5e_is_uplink_rep(priv)) |
5132 | flags |= MLX5_TC_FLAG(ESW_OFFLOAD); | |
5133 | else | |
5134 | flags |= MLX5_TC_FLAG(NIC_OFFLOAD); | |
5135 | ||
e2394a61 VB |
5136 | switch (type) { |
5137 | case TC_SETUP_CLSFLOWER: | |
5138 | return mlx5e_setup_tc_cls_flower(priv, type_data, flags); | |
5139 | default: | |
5140 | return -EOPNOTSUPP; | |
5141 | } | |
5142 | } | |
c7569097 AL |
5143 | |
5144 | bool mlx5e_tc_update_skb(struct mlx5_cqe64 *cqe, | |
5145 | struct sk_buff *skb) | |
5146 | { | |
5147 | #if IS_ENABLED(CONFIG_NET_TC_SKB_EXT) | |
aedd133d | 5148 | u32 chain = 0, chain_tag, reg_b, zone_restore_id; |
c7569097 | 5149 | struct mlx5e_priv *priv = netdev_priv(skb->dev); |
aedd133d | 5150 | struct mlx5e_tc_table *tc = &priv->fs.tc; |
a91d98a0 | 5151 | struct mlx5_mapped_obj mapped_obj; |
c7569097 AL |
5152 | struct tc_skb_ext *tc_skb_ext; |
5153 | int err; | |
5154 | ||
5155 | reg_b = be32_to_cpu(cqe->ft_metadata); | |
5156 | ||
5157 | chain_tag = reg_b & MLX5E_TC_TABLE_CHAIN_TAG_MASK; | |
5158 | ||
c9355682 | 5159 | err = mapping_find(tc->mapping, chain_tag, &mapped_obj); |
c7569097 AL |
5160 | if (err) { |
5161 | netdev_dbg(priv->netdev, | |
5162 | "Couldn't find chain for chain tag: %d, err: %d\n", | |
5163 | chain_tag, err); | |
5164 | return false; | |
5165 | } | |
5166 | ||
a91d98a0 CM |
5167 | if (mapped_obj.type == MLX5_MAPPED_OBJ_CHAIN) { |
5168 | chain = mapped_obj.chain; | |
9453d45e | 5169 | tc_skb_ext = tc_skb_ext_alloc(skb); |
c7569097 AL |
5170 | if (WARN_ON(!tc_skb_ext)) |
5171 | return false; | |
5172 | ||
5173 | tc_skb_ext->chain = chain; | |
aedd133d | 5174 | |
ed2fe7ba | 5175 | zone_restore_id = (reg_b >> REG_MAPPING_MOFFSET(NIC_ZONE_RESTORE_TO_REG)) & |
48d216e5 | 5176 | ESW_ZONE_ID_MASK; |
aedd133d AL |
5177 | |
5178 | if (!mlx5e_tc_ct_restore_flow(tc->ct, skb, | |
5179 | zone_restore_id)) | |
5180 | return false; | |
a91d98a0 CM |
5181 | } else { |
5182 | netdev_dbg(priv->netdev, "Invalid mapped object type: %d\n", mapped_obj.type); | |
5183 | return false; | |
c7569097 AL |
5184 | } |
5185 | #endif /* CONFIG_NET_TC_SKB_EXT */ | |
5186 | ||
5187 | return true; | |
5188 | } |