Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright 2018 Mellanox Technologies, Ltd
3 : : */
4 : :
5 : : #include <sys/queue.h>
6 : : #include <stdalign.h>
7 : : #include <stdint.h>
8 : : #include <string.h>
9 : : #include <unistd.h>
10 : :
11 : : #include <rte_common.h>
12 : : #include <rte_ether.h>
13 : : #include <ethdev_driver.h>
14 : : #include <rte_flow.h>
15 : : #include <rte_flow_driver.h>
16 : : #include <rte_malloc.h>
17 : : #include <rte_cycles.h>
18 : : #include <bus_pci_driver.h>
19 : : #include <rte_ip.h>
20 : : #include <rte_gre.h>
21 : : #include <rte_vxlan.h>
22 : : #include <rte_gtp.h>
23 : : #include <rte_eal_paging.h>
24 : : #include <rte_mpls.h>
25 : : #include <rte_mtr.h>
26 : : #include <rte_mtr_driver.h>
27 : : #include <rte_tailq.h>
28 : :
29 : : #include <mlx5_glue.h>
30 : : #include <mlx5_devx_cmds.h>
31 : : #include <mlx5_prm.h>
32 : : #include <mlx5_malloc.h>
33 : :
34 : : #include "mlx5_defs.h"
35 : : #include "mlx5.h"
36 : : #include "mlx5_common_os.h"
37 : : #include "mlx5_flow.h"
38 : : #include "mlx5_flow_os.h"
39 : : #include "mlx5_rx.h"
40 : : #include "mlx5_tx.h"
41 : : #include "rte_pmd_mlx5.h"
42 : :
43 : : #if defined(HAVE_IBV_FLOW_DV_SUPPORT) || !defined(HAVE_INFINIBAND_VERBS_H)
44 : :
45 : : #ifndef HAVE_IBV_FLOW_DEVX_COUNTERS
46 : : #define MLX5DV_FLOW_ACTION_COUNTERS_DEVX 0
47 : : #endif
48 : :
49 : : #ifndef HAVE_MLX5DV_DR_ESWITCH
50 : : #ifndef MLX5DV_FLOW_TABLE_TYPE_FDB
51 : : #define MLX5DV_FLOW_TABLE_TYPE_FDB 0
52 : : #endif
53 : : #endif
54 : :
55 : : #ifndef HAVE_MLX5DV_DR
56 : : #define MLX5DV_DR_ACTION_FLAGS_ROOT_LEVEL 1
57 : : #endif
58 : :
59 : : /* VLAN header definitions */
60 : : #define MLX5DV_FLOW_VLAN_PCP_SHIFT 13
61 : : #define MLX5DV_FLOW_VLAN_PCP_MASK (0x7 << MLX5DV_FLOW_VLAN_PCP_SHIFT)
62 : : #define MLX5DV_FLOW_VLAN_VID_MASK 0x0fff
63 : : #define MLX5DV_FLOW_VLAN_PCP_MASK_BE RTE_BE16(MLX5DV_FLOW_VLAN_PCP_MASK)
64 : : #define MLX5DV_FLOW_VLAN_VID_MASK_BE RTE_BE16(MLX5DV_FLOW_VLAN_VID_MASK)
65 : :
66 : : #define MLX5_ITEM_VALID(item, key_type) \
67 : : (((MLX5_SET_MATCHER_SW & (key_type)) && !((item)->spec)) || \
68 : : ((MLX5_SET_MATCHER_HS_V == (key_type)) && !((item)->spec)) || \
69 : : ((MLX5_SET_MATCHER_HS_M == (key_type)) && !((item)->mask)))
70 : :
71 : : #define MLX5_ITEM_UPDATE(item, key_type, v, m, gm) \
72 : : do { \
73 : : if ((key_type) == MLX5_SET_MATCHER_SW_V) { \
74 : : v = (item)->spec; \
75 : : m = (item)->mask ? (item)->mask : (gm); \
76 : : } else if ((key_type) == MLX5_SET_MATCHER_HS_V) { \
77 : : v = (item)->spec; \
78 : : m = (v); \
79 : : } else { \
80 : : v = (item)->mask ? (item)->mask : (gm); \
81 : : m = (v); \
82 : : } \
83 : : } while (0)
84 : :
85 : : union flow_dv_attr {
86 : : struct {
87 : : uint32_t valid:1;
88 : : uint32_t ipv4:1;
89 : : uint32_t ipv6:1;
90 : : uint32_t tcp:1;
91 : : uint32_t udp:1;
92 : : uint32_t reserved:27;
93 : : };
94 : : uint32_t attr;
95 : : };
96 : :
97 : : static int
98 : : flow_dv_encap_decap_resource_release(struct rte_eth_dev *dev,
99 : : uint32_t encap_decap_idx);
100 : :
101 : : static int
102 : : flow_dv_port_id_action_resource_release(struct rte_eth_dev *dev,
103 : : uint32_t port_id);
104 : : static void
105 : : flow_dv_shared_rss_action_release(struct rte_eth_dev *dev, uint32_t srss);
106 : :
107 : : static int
108 : : flow_dv_jump_tbl_resource_release(struct rte_eth_dev *dev,
109 : : uint32_t rix_jump);
110 : :
111 : : /**
112 : : * Initialize flow attributes structure according to flow items' types.
113 : : *
114 : : * flow_dv_validate() avoids multiple L3/L4 layers cases other than tunnel
115 : : * mode. For tunnel mode, the items to be modified are the outermost ones.
116 : : *
117 : : * @param[in] item
118 : : * Pointer to item specification.
119 : : * @param[out] attr
120 : : * Pointer to flow attributes structure.
121 : : * @param[in] dev_flow
122 : : * Pointer to the sub flow.
123 : : * @param[in] tunnel_decap
124 : : * Whether action is after tunnel decapsulation.
125 : : */
126 : : static void
127 : 0 : flow_dv_attr_init(const struct rte_flow_item *item, union flow_dv_attr *attr,
128 : : struct mlx5_flow *dev_flow, bool tunnel_decap)
129 : : {
130 : 0 : uint64_t layers = dev_flow->handle->layers;
131 : : bool tunnel_match = false;
132 : :
133 : : /*
134 : : * If layers is already initialized, it means this dev_flow is the
135 : : * suffix flow, the layers flags is set by the prefix flow. Need to
136 : : * use the layer flags from prefix flow as the suffix flow may not
137 : : * have the user defined items as the flow is split.
138 : : */
139 [ # # ]: 0 : if (layers) {
140 [ # # ]: 0 : if (tunnel_decap) {
141 : : /*
142 : : * If decap action before modify, it means the driver
143 : : * should take the inner as outer for the modify actions.
144 : : */
145 : 0 : layers = ((layers >> 6) & MLX5_FLOW_LAYER_OUTER);
146 : : }
147 [ # # ]: 0 : if (layers & MLX5_FLOW_LAYER_OUTER_L3_IPV4)
148 : 0 : attr->ipv4 = 1;
149 [ # # ]: 0 : else if (layers & MLX5_FLOW_LAYER_OUTER_L3_IPV6)
150 : 0 : attr->ipv6 = 1;
151 [ # # ]: 0 : if (layers & MLX5_FLOW_LAYER_OUTER_L4_TCP)
152 : 0 : attr->tcp = 1;
153 [ # # ]: 0 : else if (layers & MLX5_FLOW_LAYER_OUTER_L4_UDP)
154 : 0 : attr->udp = 1;
155 : 0 : attr->valid = 1;
156 : 0 : return;
157 : : }
158 [ # # ]: 0 : for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
159 : : uint8_t next_protocol = 0xff;
160 [ # # # # : 0 : switch (item->type) {
# # ]
161 : 0 : case RTE_FLOW_ITEM_TYPE_GRE:
162 : : case RTE_FLOW_ITEM_TYPE_NVGRE:
163 : : case RTE_FLOW_ITEM_TYPE_VXLAN:
164 : : case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
165 : : case RTE_FLOW_ITEM_TYPE_GENEVE:
166 : : case RTE_FLOW_ITEM_TYPE_MPLS:
167 : : case RTE_FLOW_ITEM_TYPE_GTP:
168 [ # # ]: 0 : if (tunnel_decap) {
169 : 0 : attr->attr = 0;
170 : : tunnel_match = true;
171 : : }
172 : : break;
173 : 0 : case RTE_FLOW_ITEM_TYPE_IPV4:
174 [ # # ]: 0 : if (!attr->ipv6)
175 : 0 : attr->ipv4 = 1;
176 [ # # ]: 0 : if (item->mask != NULL &&
177 : : ((const struct rte_flow_item_ipv4 *)
178 [ # # ]: 0 : item->mask)->hdr.next_proto_id)
179 : 0 : next_protocol =
180 : : ((const struct rte_flow_item_ipv4 *)
181 : 0 : (item->spec))->hdr.next_proto_id &
182 : : ((const struct rte_flow_item_ipv4 *)
183 : : (item->mask))->hdr.next_proto_id;
184 : 0 : if ((next_protocol == IPPROTO_IPIP ||
185 [ # # ]: 0 : next_protocol == IPPROTO_IPV6) && tunnel_decap &&
186 [ # # ]: 0 : !tunnel_match)
187 : 0 : attr->attr = 0;
188 : : break;
189 : 0 : case RTE_FLOW_ITEM_TYPE_IPV6:
190 [ # # ]: 0 : if (!attr->ipv4)
191 : 0 : attr->ipv6 = 1;
192 [ # # ]: 0 : if (item->mask != NULL &&
193 : : ((const struct rte_flow_item_ipv6 *)
194 [ # # ]: 0 : item->mask)->hdr.proto)
195 : 0 : next_protocol =
196 : : ((const struct rte_flow_item_ipv6 *)
197 : 0 : (item->spec))->hdr.proto &
198 : : ((const struct rte_flow_item_ipv6 *)
199 : : (item->mask))->hdr.proto;
200 : 0 : if ((next_protocol == IPPROTO_IPIP ||
201 [ # # ]: 0 : next_protocol == IPPROTO_IPV6) && tunnel_decap &&
202 [ # # ]: 0 : !tunnel_match)
203 : 0 : attr->attr = 0;
204 : : break;
205 : 0 : case RTE_FLOW_ITEM_TYPE_UDP:
206 [ # # ]: 0 : if (!attr->tcp)
207 : 0 : attr->udp = 1;
208 : : break;
209 : 0 : case RTE_FLOW_ITEM_TYPE_TCP:
210 [ # # ]: 0 : if (!attr->udp)
211 : 0 : attr->tcp = 1;
212 : : break;
213 : : default:
214 : : break;
215 : : }
216 : : }
217 : 0 : attr->valid = 1;
218 : : }
219 : :
220 : : struct field_modify_info modify_eth[] = {
221 : : {4, 0, MLX5_MODI_OUT_DMAC_47_16},
222 : : {2, 4, MLX5_MODI_OUT_DMAC_15_0},
223 : : {4, 6, MLX5_MODI_OUT_SMAC_47_16},
224 : : {2, 10, MLX5_MODI_OUT_SMAC_15_0},
225 : : {0, 0, 0},
226 : : };
227 : :
228 : : struct field_modify_info modify_vlan_out_first_vid[] = {
229 : : /* Size in bits !!! */
230 : : {12, 0, MLX5_MODI_OUT_FIRST_VID},
231 : : {0, 0, 0},
232 : : };
233 : :
234 : : struct field_modify_info modify_ipv4[] = {
235 : : {1, 1, MLX5_MODI_OUT_IP_DSCP},
236 : : {1, 8, MLX5_MODI_OUT_IPV4_TTL},
237 : : {4, 12, MLX5_MODI_OUT_SIPV4},
238 : : {4, 16, MLX5_MODI_OUT_DIPV4},
239 : : {0, 0, 0},
240 : : };
241 : :
242 : : struct field_modify_info modify_ipv6[] = {
243 : : {1, 0, MLX5_MODI_OUT_IP_DSCP},
244 : : {1, 7, MLX5_MODI_OUT_IPV6_HOPLIMIT},
245 : : {4, 8, MLX5_MODI_OUT_SIPV6_127_96},
246 : : {4, 12, MLX5_MODI_OUT_SIPV6_95_64},
247 : : {4, 16, MLX5_MODI_OUT_SIPV6_63_32},
248 : : {4, 20, MLX5_MODI_OUT_SIPV6_31_0},
249 : : {4, 24, MLX5_MODI_OUT_DIPV6_127_96},
250 : : {4, 28, MLX5_MODI_OUT_DIPV6_95_64},
251 : : {4, 32, MLX5_MODI_OUT_DIPV6_63_32},
252 : : {4, 36, MLX5_MODI_OUT_DIPV6_31_0},
253 : : {0, 0, 0},
254 : : };
255 : :
256 : : struct field_modify_info modify_udp[] = {
257 : : {2, 0, MLX5_MODI_OUT_UDP_SPORT},
258 : : {2, 2, MLX5_MODI_OUT_UDP_DPORT},
259 : : {0, 0, 0},
260 : : };
261 : :
262 : : struct field_modify_info modify_tcp[] = {
263 : : {2, 0, MLX5_MODI_OUT_TCP_SPORT},
264 : : {2, 2, MLX5_MODI_OUT_TCP_DPORT},
265 : : {4, 4, MLX5_MODI_OUT_TCP_SEQ_NUM},
266 : : {4, 8, MLX5_MODI_OUT_TCP_ACK_NUM},
267 : : {0, 0, 0},
268 : : };
269 : :
270 : : static void
271 : : mlx5_flow_tunnel_ip_check(const struct rte_flow_item *item __rte_unused,
272 : : uint8_t next_protocol, uint64_t *item_flags,
273 : : int *tunnel)
274 : : {
275 : : MLX5_ASSERT(item->type == RTE_FLOW_ITEM_TYPE_IPV4 ||
276 : : item->type == RTE_FLOW_ITEM_TYPE_IPV6);
277 : 0 : if (next_protocol == IPPROTO_IPIP) {
278 : 0 : *item_flags |= MLX5_FLOW_LAYER_IPIP;
279 : : *tunnel = 1;
280 : : }
281 [ # # # # : 0 : if (next_protocol == IPPROTO_IPV6) {
# # # # ]
282 : 0 : *item_flags |= MLX5_FLOW_LAYER_IPV6_ENCAP;
283 : : *tunnel = 1;
284 : : }
285 : : }
286 : :
287 : : static inline struct mlx5_hlist *
288 : 0 : flow_dv_hlist_prepare(struct mlx5_dev_ctx_shared *sh, struct mlx5_hlist **phl,
289 : : const char *name, uint32_t size, bool direct_key,
290 : : bool lcores_share, void *ctx,
291 : : mlx5_list_create_cb cb_create,
292 : : mlx5_list_match_cb cb_match,
293 : : mlx5_list_remove_cb cb_remove,
294 : : mlx5_list_clone_cb cb_clone,
295 : : mlx5_list_clone_free_cb cb_clone_free,
296 : : struct rte_flow_error *error)
297 : : {
298 : : struct mlx5_hlist *hl;
299 : : struct mlx5_hlist *expected = NULL;
300 : : char s[MLX5_NAME_SIZE];
301 : :
302 : 0 : hl = __atomic_load_n(phl, __ATOMIC_SEQ_CST);
303 [ # # ]: 0 : if (likely(hl))
304 : : return hl;
305 : 0 : snprintf(s, sizeof(s), "%s_%s", sh->ibdev_name, name);
306 : 0 : hl = mlx5_hlist_create(s, size, direct_key, lcores_share,
307 : : ctx, cb_create, cb_match, cb_remove, cb_clone,
308 : : cb_clone_free);
309 [ # # ]: 0 : if (!hl) {
310 : 0 : DRV_LOG(ERR, "%s hash creation failed", name);
311 : 0 : rte_flow_error_set(error, ENOMEM,
312 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
313 : : "cannot allocate resource memory");
314 : 0 : return NULL;
315 : : }
316 [ # # ]: 0 : if (!__atomic_compare_exchange_n(phl, &expected, hl, false,
317 : : __ATOMIC_SEQ_CST,
318 : : __ATOMIC_SEQ_CST)) {
319 : 0 : mlx5_hlist_destroy(hl);
320 : 0 : hl = __atomic_load_n(phl, __ATOMIC_SEQ_CST);
321 : : }
322 : : return hl;
323 : : }
324 : :
325 : : /* Update VLAN's VID/PCP based on input rte_flow_action.
326 : : *
327 : : * @param[in] action
328 : : * Pointer to struct rte_flow_action.
329 : : * @param[out] vlan
330 : : * Pointer to struct rte_vlan_hdr.
331 : : */
332 : : static void
333 : 0 : mlx5_update_vlan_vid_pcp(const struct rte_flow_action *action,
334 : : struct rte_vlan_hdr *vlan)
335 : : {
336 : : uint16_t vlan_tci;
337 [ # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP) {
338 : 0 : vlan_tci =
339 : : ((const struct rte_flow_action_of_set_vlan_pcp *)
340 : 0 : action->conf)->vlan_pcp;
341 : 0 : vlan_tci = vlan_tci << MLX5DV_FLOW_VLAN_PCP_SHIFT;
342 : 0 : vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_PCP_MASK;
343 : 0 : vlan->vlan_tci |= vlan_tci;
344 [ # # ]: 0 : } else if (action->type == RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID) {
345 : 0 : vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_VID_MASK;
346 [ # # ]: 0 : vlan->vlan_tci |= rte_be_to_cpu_16
347 : : (((const struct rte_flow_action_of_set_vlan_vid *)
348 : : action->conf)->vlan_vid);
349 : : }
350 : 0 : }
351 : :
352 : : /**
353 : : * Convert modify-header action to DV specification.
354 : : *
355 : : * Data length of each action is determined by provided field description
356 : : * and the item mask. Data bit offset and width of each action is determined
357 : : * by provided item mask.
358 : : *
359 : : * @param[in] item
360 : : * Pointer to item specification.
361 : : * @param[in] field
362 : : * Pointer to field modification information.
363 : : * For MLX5_MODIFICATION_TYPE_SET specifies destination field.
364 : : * For MLX5_MODIFICATION_TYPE_ADD specifies destination field.
365 : : * For MLX5_MODIFICATION_TYPE_COPY specifies source field.
366 : : * @param[in] dcopy
367 : : * Destination field info for MLX5_MODIFICATION_TYPE_COPY in @type.
368 : : * Negative offset value sets the same offset as source offset.
369 : : * size field is ignored, value is taken from source field.
370 : : * @param[in,out] resource
371 : : * Pointer to the modify-header resource.
372 : : * @param[in] type
373 : : * Type of modification.
374 : : * @param[out] error
375 : : * Pointer to the error structure.
376 : : *
377 : : * @return
378 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
379 : : */
380 : : int
381 : 0 : flow_dv_convert_modify_action(struct rte_flow_item *item,
382 : : struct field_modify_info *field,
383 : : struct field_modify_info *dcopy,
384 : : struct mlx5_flow_dv_modify_hdr_resource *resource,
385 : : uint32_t type, struct rte_flow_error *error)
386 : : {
387 : 0 : uint32_t i = resource->actions_num;
388 : 0 : struct mlx5_modification_cmd *actions = resource->actions;
389 : : uint32_t carry_b = 0;
390 : :
391 : : /*
392 : : * The item and mask are provided in big-endian format.
393 : : * The fields should be presented as in big-endian format either.
394 : : * Mask must be always present, it defines the actual field width.
395 : : */
396 : : MLX5_ASSERT(item->mask);
397 : : MLX5_ASSERT(field->size);
398 : : do {
399 : : uint32_t size_b;
400 : : uint32_t off_b;
401 : : uint32_t mask;
402 : : uint32_t data;
403 : : bool next_field = true;
404 : : bool next_dcopy = true;
405 : :
406 [ # # ]: 0 : if (i >= MLX5_MAX_MODIFY_NUM)
407 : 0 : return rte_flow_error_set(error, EINVAL,
408 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
409 : : "too many items to modify");
410 : : /* Fetch variable byte size mask from the array. */
411 : 0 : mask = flow_dv_fetch_field((const uint8_t *)item->mask +
412 : 0 : field->offset, field->size);
413 [ # # ]: 0 : if (!mask) {
414 : 0 : ++field;
415 : : continue;
416 : : }
417 [ # # # # ]: 0 : if (type == MLX5_MODIFICATION_TYPE_COPY && field->is_flex) {
418 : 0 : off_b = 32 - field->shift + carry_b - field->size * CHAR_BIT;
419 : 0 : size_b = field->size * CHAR_BIT - carry_b;
420 : : } else {
421 : : /* Deduce actual data width in bits from mask value. */
422 : 0 : off_b = rte_bsf32(mask) + carry_b;
423 : 0 : size_b = sizeof(uint32_t) * CHAR_BIT -
424 : 0 : off_b - rte_clz32(mask);
425 : : }
426 : : MLX5_ASSERT(size_b);
427 : 0 : actions[i] = (struct mlx5_modification_cmd) {
428 : : .action_type = type,
429 : 0 : .field = field->id,
430 : : .offset = off_b,
431 : : .length = (size_b == sizeof(uint32_t) * CHAR_BIT) ?
432 [ # # ]: 0 : 0 : size_b,
433 : : };
434 [ # # ]: 0 : if (type == MLX5_MODIFICATION_TYPE_COPY) {
435 : : MLX5_ASSERT(dcopy);
436 : 0 : actions[i].dst_field = dcopy->id;
437 : 0 : actions[i].dst_offset =
438 [ # # ]: 0 : (int)dcopy->offset < 0 ? off_b : dcopy->offset;
439 : : /* Convert entire record to big-endian format. */
440 [ # # ]: 0 : actions[i].data1 = rte_cpu_to_be_32(actions[i].data1);
441 : : /*
442 : : * Destination field overflow. Copy leftovers of
443 : : * a source field to the next destination field.
444 : : */
445 [ # # # # ]: 0 : if ((size_b > dcopy->size * CHAR_BIT - dcopy->offset) &&
446 : : dcopy->size != 0) {
447 : 0 : actions[i].length =
448 : 0 : dcopy->size * CHAR_BIT - dcopy->offset;
449 : 0 : carry_b += actions[i].length;
450 : 0 : next_field = false;
451 : : } else {
452 : : carry_b = 0;
453 : : }
454 : : /*
455 : : * Not enough bits in a source filed to fill a
456 : : * destination field. Switch to the next source.
457 : : */
458 [ # # ]: 0 : if ((size_b < dcopy->size * CHAR_BIT - dcopy->offset) &&
459 [ # # ]: 0 : ((size_b == field->size * CHAR_BIT - off_b) ||
460 [ # # ]: 0 : field->is_flex)) {
461 : 0 : actions[i].length = size_b;
462 : 0 : dcopy->offset += actions[i].length;
463 : : next_dcopy = false;
464 : : }
465 : : } else {
466 : : MLX5_ASSERT(item->spec);
467 : 0 : data = flow_dv_fetch_field((const uint8_t *)item->spec +
468 : : field->offset, field->size);
469 : : /* Shift out the trailing masked bits from data. */
470 : 0 : data = (data & mask) >> off_b;
471 [ # # ]: 0 : if (field->is_flex)
472 : 0 : actions[i].offset = 32 - field->shift - field->size * CHAR_BIT;
473 [ # # ]: 0 : actions[i].data1 = rte_cpu_to_be_32(data);
474 : : }
475 : : /* Convert entire record to expected big-endian format. */
476 [ # # ]: 0 : actions[i].data0 = rte_cpu_to_be_32(actions[i].data0);
477 [ # # ]: 0 : if ((type != MLX5_MODIFICATION_TYPE_COPY ||
478 [ # # # # ]: 0 : dcopy->id != (enum mlx5_modification_field)UINT32_MAX) &&
479 : : field->id != (enum mlx5_modification_field)UINT32_MAX)
480 : 0 : ++i;
481 [ # # ]: 0 : if (next_dcopy && type == MLX5_MODIFICATION_TYPE_COPY)
482 : 0 : ++dcopy;
483 [ # # ]: 0 : if (next_field)
484 : 0 : ++field;
485 [ # # ]: 0 : } while (field->size);
486 [ # # ]: 0 : if (resource->actions_num == i)
487 : 0 : return rte_flow_error_set(error, EINVAL,
488 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
489 : : "invalid modification flow item");
490 : 0 : resource->actions_num = i;
491 : 0 : return 0;
492 : : }
493 : :
494 : : /**
495 : : * Convert modify-header set IPv4 address action to DV specification.
496 : : *
497 : : * @param[in,out] resource
498 : : * Pointer to the modify-header resource.
499 : : * @param[in] action
500 : : * Pointer to action specification.
501 : : * @param[out] error
502 : : * Pointer to the error structure.
503 : : *
504 : : * @return
505 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
506 : : */
507 : : static int
508 : 0 : flow_dv_convert_action_modify_ipv4
509 : : (struct mlx5_flow_dv_modify_hdr_resource *resource,
510 : : const struct rte_flow_action *action,
511 : : struct rte_flow_error *error)
512 : : {
513 : 0 : const struct rte_flow_action_set_ipv4 *conf =
514 : : (const struct rte_flow_action_set_ipv4 *)(action->conf);
515 [ # # ]: 0 : struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV4 };
516 : : struct rte_flow_item_ipv4 ipv4;
517 : : struct rte_flow_item_ipv4 ipv4_mask;
518 : :
519 : : memset(&ipv4, 0, sizeof(ipv4));
520 : : memset(&ipv4_mask, 0, sizeof(ipv4_mask));
521 [ # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC) {
522 : 0 : ipv4.hdr.src_addr = conf->ipv4_addr;
523 : 0 : ipv4_mask.hdr.src_addr = rte_flow_item_ipv4_mask.hdr.src_addr;
524 : : } else {
525 : 0 : ipv4.hdr.dst_addr = conf->ipv4_addr;
526 : 0 : ipv4_mask.hdr.dst_addr = rte_flow_item_ipv4_mask.hdr.dst_addr;
527 : : }
528 : 0 : item.spec = &ipv4;
529 : 0 : item.mask = &ipv4_mask;
530 : 0 : return flow_dv_convert_modify_action(&item, modify_ipv4, NULL, resource,
531 : : MLX5_MODIFICATION_TYPE_SET, error);
532 : : }
533 : :
534 : : /**
535 : : * Convert modify-header set IPv6 address action to DV specification.
536 : : *
537 : : * @param[in,out] resource
538 : : * Pointer to the modify-header resource.
539 : : * @param[in] action
540 : : * Pointer to action specification.
541 : : * @param[out] error
542 : : * Pointer to the error structure.
543 : : *
544 : : * @return
545 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
546 : : */
547 : : static int
548 : 0 : flow_dv_convert_action_modify_ipv6
549 : : (struct mlx5_flow_dv_modify_hdr_resource *resource,
550 : : const struct rte_flow_action *action,
551 : : struct rte_flow_error *error)
552 : : {
553 : 0 : const struct rte_flow_action_set_ipv6 *conf =
554 : : (const struct rte_flow_action_set_ipv6 *)(action->conf);
555 [ # # ]: 0 : struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV6 };
556 : : struct rte_flow_item_ipv6 ipv6;
557 : : struct rte_flow_item_ipv6 ipv6_mask;
558 : :
559 : : memset(&ipv6, 0, sizeof(ipv6));
560 : : memset(&ipv6_mask, 0, sizeof(ipv6_mask));
561 [ # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC) {
562 : : memcpy(&ipv6.hdr.src_addr, &conf->ipv6_addr,
563 : : sizeof(ipv6.hdr.src_addr));
564 : : memcpy(&ipv6_mask.hdr.src_addr,
565 : : &rte_flow_item_ipv6_mask.hdr.src_addr,
566 : : sizeof(ipv6.hdr.src_addr));
567 : : } else {
568 : : memcpy(&ipv6.hdr.dst_addr, &conf->ipv6_addr,
569 : : sizeof(ipv6.hdr.dst_addr));
570 : : memcpy(&ipv6_mask.hdr.dst_addr,
571 : : &rte_flow_item_ipv6_mask.hdr.dst_addr,
572 : : sizeof(ipv6.hdr.dst_addr));
573 : : }
574 : 0 : item.spec = &ipv6;
575 : 0 : item.mask = &ipv6_mask;
576 : 0 : return flow_dv_convert_modify_action(&item, modify_ipv6, NULL, resource,
577 : : MLX5_MODIFICATION_TYPE_SET, error);
578 : : }
579 : :
580 : : /**
581 : : * Convert modify-header set MAC address action to DV specification.
582 : : *
583 : : * @param[in,out] resource
584 : : * Pointer to the modify-header resource.
585 : : * @param[in] action
586 : : * Pointer to action specification.
587 : : * @param[out] error
588 : : * Pointer to the error structure.
589 : : *
590 : : * @return
591 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
592 : : */
593 : : static int
594 : 0 : flow_dv_convert_action_modify_mac
595 : : (struct mlx5_flow_dv_modify_hdr_resource *resource,
596 : : const struct rte_flow_action *action,
597 : : struct rte_flow_error *error)
598 : : {
599 : 0 : const struct rte_flow_action_set_mac *conf =
600 : : (const struct rte_flow_action_set_mac *)(action->conf);
601 [ # # ]: 0 : struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_ETH };
602 : : struct rte_flow_item_eth eth;
603 : : struct rte_flow_item_eth eth_mask;
604 : :
605 : : memset(ð, 0, sizeof(eth));
606 : : memset(ð_mask, 0, sizeof(eth_mask));
607 [ # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_SET_MAC_SRC) {
608 : : memcpy(ð.hdr.src_addr.addr_bytes, &conf->mac_addr,
609 : : sizeof(eth.hdr.src_addr.addr_bytes));
610 : : memcpy(ð_mask.hdr.src_addr.addr_bytes,
611 : : &rte_flow_item_eth_mask.hdr.src_addr.addr_bytes,
612 : : sizeof(eth_mask.hdr.src_addr.addr_bytes));
613 : : } else {
614 : : memcpy(ð.hdr.dst_addr.addr_bytes, &conf->mac_addr,
615 : : sizeof(eth.hdr.dst_addr.addr_bytes));
616 : : memcpy(ð_mask.hdr.dst_addr.addr_bytes,
617 : : &rte_flow_item_eth_mask.hdr.dst_addr.addr_bytes,
618 : : sizeof(eth_mask.hdr.dst_addr.addr_bytes));
619 : : }
620 : 0 : item.spec = ð
621 : 0 : item.mask = ð_mask;
622 : 0 : return flow_dv_convert_modify_action(&item, modify_eth, NULL, resource,
623 : : MLX5_MODIFICATION_TYPE_SET, error);
624 : : }
625 : :
626 : : /**
627 : : * Convert modify-header set VLAN VID action to DV specification.
628 : : *
629 : : * @param[in,out] resource
630 : : * Pointer to the modify-header resource.
631 : : * @param[in] action
632 : : * Pointer to action specification.
633 : : * @param[out] error
634 : : * Pointer to the error structure.
635 : : *
636 : : * @return
637 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
638 : : */
639 : : static int
640 : 0 : flow_dv_convert_action_modify_vlan_vid
641 : : (struct mlx5_flow_dv_modify_hdr_resource *resource,
642 : : const struct rte_flow_action *action,
643 : : struct rte_flow_error *error)
644 : : {
645 : 0 : const struct rte_flow_action_of_set_vlan_vid *conf =
646 : : (const struct rte_flow_action_of_set_vlan_vid *)(action->conf);
647 : 0 : int i = resource->actions_num;
648 : 0 : struct mlx5_modification_cmd *actions = resource->actions;
649 : : struct field_modify_info *field = modify_vlan_out_first_vid;
650 : :
651 [ # # ]: 0 : if (i >= MLX5_MAX_MODIFY_NUM)
652 : 0 : return rte_flow_error_set(error, EINVAL,
653 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
654 : : "too many items to modify");
655 : 0 : actions[i] = (struct mlx5_modification_cmd) {
656 : : .action_type = MLX5_MODIFICATION_TYPE_SET,
657 : 0 : .field = field->id,
658 : 0 : .length = field->size,
659 : 0 : .offset = field->offset,
660 : : };
661 [ # # ]: 0 : actions[i].data0 = rte_cpu_to_be_32(actions[i].data0);
662 : 0 : actions[i].data1 = conf->vlan_vid;
663 : 0 : actions[i].data1 = actions[i].data1 << 16;
664 : 0 : resource->actions_num = ++i;
665 : 0 : return 0;
666 : : }
667 : :
668 : : /**
669 : : * Convert modify-header set TP action to DV specification.
670 : : *
671 : : * @param[in,out] resource
672 : : * Pointer to the modify-header resource.
673 : : * @param[in] action
674 : : * Pointer to action specification.
675 : : * @param[in] items
676 : : * Pointer to rte_flow_item objects list.
677 : : * @param[in] attr
678 : : * Pointer to flow attributes structure.
679 : : * @param[in] dev_flow
680 : : * Pointer to the sub flow.
681 : : * @param[in] tunnel_decap
682 : : * Whether action is after tunnel decapsulation.
683 : : * @param[out] error
684 : : * Pointer to the error structure.
685 : : *
686 : : * @return
687 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
688 : : */
689 : : static int
690 : 0 : flow_dv_convert_action_modify_tp
691 : : (struct mlx5_flow_dv_modify_hdr_resource *resource,
692 : : const struct rte_flow_action *action,
693 : : const struct rte_flow_item *items,
694 : : union flow_dv_attr *attr, struct mlx5_flow *dev_flow,
695 : : bool tunnel_decap, struct rte_flow_error *error)
696 : : {
697 : 0 : const struct rte_flow_action_set_tp *conf =
698 : : (const struct rte_flow_action_set_tp *)(action->conf);
699 : : struct rte_flow_item item;
700 : : struct rte_flow_item_udp udp;
701 : : struct rte_flow_item_udp udp_mask;
702 : : struct rte_flow_item_tcp tcp;
703 : : struct rte_flow_item_tcp tcp_mask;
704 : : struct field_modify_info *field;
705 : :
706 [ # # ]: 0 : if (!attr->valid)
707 : 0 : flow_dv_attr_init(items, attr, dev_flow, tunnel_decap);
708 [ # # ]: 0 : if (attr->udp) {
709 : : memset(&udp, 0, sizeof(udp));
710 : : memset(&udp_mask, 0, sizeof(udp_mask));
711 [ # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_SET_TP_SRC) {
712 : 0 : udp.hdr.src_port = conf->port;
713 : 0 : udp_mask.hdr.src_port =
714 : : rte_flow_item_udp_mask.hdr.src_port;
715 : : } else {
716 : 0 : udp.hdr.dst_port = conf->port;
717 : 0 : udp_mask.hdr.dst_port =
718 : : rte_flow_item_udp_mask.hdr.dst_port;
719 : : }
720 : 0 : item.type = RTE_FLOW_ITEM_TYPE_UDP;
721 : 0 : item.spec = &udp;
722 : 0 : item.mask = &udp_mask;
723 : : field = modify_udp;
724 : : } else {
725 : : MLX5_ASSERT(attr->tcp);
726 : : memset(&tcp, 0, sizeof(tcp));
727 : : memset(&tcp_mask, 0, sizeof(tcp_mask));
728 [ # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_SET_TP_SRC) {
729 : 0 : tcp.hdr.src_port = conf->port;
730 : 0 : tcp_mask.hdr.src_port =
731 : : rte_flow_item_tcp_mask.hdr.src_port;
732 : : } else {
733 : 0 : tcp.hdr.dst_port = conf->port;
734 : 0 : tcp_mask.hdr.dst_port =
735 : : rte_flow_item_tcp_mask.hdr.dst_port;
736 : : }
737 : 0 : item.type = RTE_FLOW_ITEM_TYPE_TCP;
738 : 0 : item.spec = &tcp;
739 : 0 : item.mask = &tcp_mask;
740 : : field = modify_tcp;
741 : : }
742 : 0 : return flow_dv_convert_modify_action(&item, field, NULL, resource,
743 : : MLX5_MODIFICATION_TYPE_SET, error);
744 : : }
745 : :
746 : : /**
747 : : * Convert modify-header set TTL action to DV specification.
748 : : *
749 : : * @param[in,out] resource
750 : : * Pointer to the modify-header resource.
751 : : * @param[in] action
752 : : * Pointer to action specification.
753 : : * @param[in] items
754 : : * Pointer to rte_flow_item objects list.
755 : : * @param[in] attr
756 : : * Pointer to flow attributes structure.
757 : : * @param[in] dev_flow
758 : : * Pointer to the sub flow.
759 : : * @param[in] tunnel_decap
760 : : * Whether action is after tunnel decapsulation.
761 : : * @param[out] error
762 : : * Pointer to the error structure.
763 : : *
764 : : * @return
765 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
766 : : */
767 : : static int
768 : 0 : flow_dv_convert_action_modify_ttl
769 : : (struct mlx5_flow_dv_modify_hdr_resource *resource,
770 : : const struct rte_flow_action *action,
771 : : const struct rte_flow_item *items,
772 : : union flow_dv_attr *attr, struct mlx5_flow *dev_flow,
773 : : bool tunnel_decap, struct rte_flow_error *error)
774 : : {
775 : 0 : const struct rte_flow_action_set_ttl *conf =
776 : : (const struct rte_flow_action_set_ttl *)(action->conf);
777 : : struct rte_flow_item item;
778 : : struct rte_flow_item_ipv4 ipv4;
779 : : struct rte_flow_item_ipv4 ipv4_mask;
780 : : struct rte_flow_item_ipv6 ipv6;
781 : : struct rte_flow_item_ipv6 ipv6_mask;
782 : : struct field_modify_info *field;
783 : :
784 [ # # ]: 0 : if (!attr->valid)
785 : 0 : flow_dv_attr_init(items, attr, dev_flow, tunnel_decap);
786 [ # # ]: 0 : if (attr->ipv4) {
787 : : memset(&ipv4, 0, sizeof(ipv4));
788 : : memset(&ipv4_mask, 0, sizeof(ipv4_mask));
789 : 0 : ipv4.hdr.time_to_live = conf->ttl_value;
790 : 0 : ipv4_mask.hdr.time_to_live = 0xFF;
791 : 0 : item.type = RTE_FLOW_ITEM_TYPE_IPV4;
792 : 0 : item.spec = &ipv4;
793 : 0 : item.mask = &ipv4_mask;
794 : : field = modify_ipv4;
795 : : } else {
796 : : MLX5_ASSERT(attr->ipv6);
797 : : memset(&ipv6, 0, sizeof(ipv6));
798 : : memset(&ipv6_mask, 0, sizeof(ipv6_mask));
799 : 0 : ipv6.hdr.hop_limits = conf->ttl_value;
800 : 0 : ipv6_mask.hdr.hop_limits = 0xFF;
801 : 0 : item.type = RTE_FLOW_ITEM_TYPE_IPV6;
802 : 0 : item.spec = &ipv6;
803 : 0 : item.mask = &ipv6_mask;
804 : : field = modify_ipv6;
805 : : }
806 : 0 : return flow_dv_convert_modify_action(&item, field, NULL, resource,
807 : : MLX5_MODIFICATION_TYPE_SET, error);
808 : : }
809 : :
810 : : /**
811 : : * Convert modify-header decrement TTL action to DV specification.
812 : : *
813 : : * @param[in,out] resource
814 : : * Pointer to the modify-header resource.
815 : : * @param[in] action
816 : : * Pointer to action specification.
817 : : * @param[in] items
818 : : * Pointer to rte_flow_item objects list.
819 : : * @param[in] attr
820 : : * Pointer to flow attributes structure.
821 : : * @param[in] dev_flow
822 : : * Pointer to the sub flow.
823 : : * @param[in] tunnel_decap
824 : : * Whether action is after tunnel decapsulation.
825 : : * @param[out] error
826 : : * Pointer to the error structure.
827 : : *
828 : : * @return
829 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
830 : : */
831 : : static int
832 : 0 : flow_dv_convert_action_modify_dec_ttl
833 : : (struct mlx5_flow_dv_modify_hdr_resource *resource,
834 : : const struct rte_flow_item *items,
835 : : union flow_dv_attr *attr, struct mlx5_flow *dev_flow,
836 : : bool tunnel_decap, struct rte_flow_error *error)
837 : : {
838 : : struct rte_flow_item item;
839 : : struct rte_flow_item_ipv4 ipv4;
840 : : struct rte_flow_item_ipv4 ipv4_mask;
841 : : struct rte_flow_item_ipv6 ipv6;
842 : : struct rte_flow_item_ipv6 ipv6_mask;
843 : : struct field_modify_info *field;
844 : :
845 [ # # ]: 0 : if (!attr->valid)
846 : 0 : flow_dv_attr_init(items, attr, dev_flow, tunnel_decap);
847 [ # # ]: 0 : if (attr->ipv4) {
848 : : memset(&ipv4, 0, sizeof(ipv4));
849 : : memset(&ipv4_mask, 0, sizeof(ipv4_mask));
850 : 0 : ipv4.hdr.time_to_live = 0xFF;
851 : 0 : ipv4_mask.hdr.time_to_live = 0xFF;
852 : 0 : item.type = RTE_FLOW_ITEM_TYPE_IPV4;
853 : 0 : item.spec = &ipv4;
854 : 0 : item.mask = &ipv4_mask;
855 : : field = modify_ipv4;
856 : : } else {
857 : : MLX5_ASSERT(attr->ipv6);
858 : : memset(&ipv6, 0, sizeof(ipv6));
859 : : memset(&ipv6_mask, 0, sizeof(ipv6_mask));
860 : 0 : ipv6.hdr.hop_limits = 0xFF;
861 : 0 : ipv6_mask.hdr.hop_limits = 0xFF;
862 : 0 : item.type = RTE_FLOW_ITEM_TYPE_IPV6;
863 : 0 : item.spec = &ipv6;
864 : 0 : item.mask = &ipv6_mask;
865 : : field = modify_ipv6;
866 : : }
867 : 0 : return flow_dv_convert_modify_action(&item, field, NULL, resource,
868 : : MLX5_MODIFICATION_TYPE_ADD, error);
869 : : }
870 : :
871 : : /**
872 : : * Convert modify-header increment/decrement TCP Sequence number
873 : : * to DV specification.
874 : : *
875 : : * @param[in,out] resource
876 : : * Pointer to the modify-header resource.
877 : : * @param[in] action
878 : : * Pointer to action specification.
879 : : * @param[out] error
880 : : * Pointer to the error structure.
881 : : *
882 : : * @return
883 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
884 : : */
885 : : static int
886 : 0 : flow_dv_convert_action_modify_tcp_seq
887 : : (struct mlx5_flow_dv_modify_hdr_resource *resource,
888 : : const struct rte_flow_action *action,
889 : : struct rte_flow_error *error)
890 : : {
891 : 0 : const rte_be32_t *conf = (const rte_be32_t *)(action->conf);
892 [ # # ]: 0 : uint64_t value = rte_be_to_cpu_32(*conf);
893 : : struct rte_flow_item item;
894 : : struct rte_flow_item_tcp tcp;
895 : : struct rte_flow_item_tcp tcp_mask;
896 : :
897 : : memset(&tcp, 0, sizeof(tcp));
898 : : memset(&tcp_mask, 0, sizeof(tcp_mask));
899 [ # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ)
900 : : /*
901 : : * The HW has no decrement operation, only increment operation.
902 : : * To simulate decrement X from Y using increment operation
903 : : * we need to add UINT32_MAX X times to Y.
904 : : * Each adding of UINT32_MAX decrements Y by 1.
905 : : */
906 : 0 : value *= UINT32_MAX;
907 [ # # ]: 0 : tcp.hdr.sent_seq = rte_cpu_to_be_32((uint32_t)value);
908 : 0 : tcp_mask.hdr.sent_seq = RTE_BE32(UINT32_MAX);
909 : 0 : item.type = RTE_FLOW_ITEM_TYPE_TCP;
910 : 0 : item.spec = &tcp;
911 : 0 : item.mask = &tcp_mask;
912 : 0 : return flow_dv_convert_modify_action(&item, modify_tcp, NULL, resource,
913 : : MLX5_MODIFICATION_TYPE_ADD, error);
914 : : }
915 : :
916 : : /**
917 : : * Convert modify-header increment/decrement TCP Acknowledgment number
918 : : * to DV specification.
919 : : *
920 : : * @param[in,out] resource
921 : : * Pointer to the modify-header resource.
922 : : * @param[in] action
923 : : * Pointer to action specification.
924 : : * @param[out] error
925 : : * Pointer to the error structure.
926 : : *
927 : : * @return
928 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
929 : : */
930 : : static int
931 : 0 : flow_dv_convert_action_modify_tcp_ack
932 : : (struct mlx5_flow_dv_modify_hdr_resource *resource,
933 : : const struct rte_flow_action *action,
934 : : struct rte_flow_error *error)
935 : : {
936 : 0 : const rte_be32_t *conf = (const rte_be32_t *)(action->conf);
937 [ # # ]: 0 : uint64_t value = rte_be_to_cpu_32(*conf);
938 : : struct rte_flow_item item;
939 : : struct rte_flow_item_tcp tcp;
940 : : struct rte_flow_item_tcp tcp_mask;
941 : :
942 : : memset(&tcp, 0, sizeof(tcp));
943 : : memset(&tcp_mask, 0, sizeof(tcp_mask));
944 [ # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK)
945 : : /*
946 : : * The HW has no decrement operation, only increment operation.
947 : : * To simulate decrement X from Y using increment operation
948 : : * we need to add UINT32_MAX X times to Y.
949 : : * Each adding of UINT32_MAX decrements Y by 1.
950 : : */
951 : 0 : value *= UINT32_MAX;
952 [ # # ]: 0 : tcp.hdr.recv_ack = rte_cpu_to_be_32((uint32_t)value);
953 : 0 : tcp_mask.hdr.recv_ack = RTE_BE32(UINT32_MAX);
954 : 0 : item.type = RTE_FLOW_ITEM_TYPE_TCP;
955 : 0 : item.spec = &tcp;
956 : 0 : item.mask = &tcp_mask;
957 : 0 : return flow_dv_convert_modify_action(&item, modify_tcp, NULL, resource,
958 : : MLX5_MODIFICATION_TYPE_ADD, error);
959 : : }
960 : :
961 : : static enum mlx5_modification_field reg_to_field[] = {
962 : : [REG_NON] = MLX5_MODI_OUT_NONE,
963 : : [REG_A] = MLX5_MODI_META_DATA_REG_A,
964 : : [REG_B] = MLX5_MODI_META_DATA_REG_B,
965 : : [REG_C_0] = MLX5_MODI_META_REG_C_0,
966 : : [REG_C_1] = MLX5_MODI_META_REG_C_1,
967 : : [REG_C_2] = MLX5_MODI_META_REG_C_2,
968 : : [REG_C_3] = MLX5_MODI_META_REG_C_3,
969 : : [REG_C_4] = MLX5_MODI_META_REG_C_4,
970 : : [REG_C_5] = MLX5_MODI_META_REG_C_5,
971 : : [REG_C_6] = MLX5_MODI_META_REG_C_6,
972 : : [REG_C_7] = MLX5_MODI_META_REG_C_7,
973 : : [REG_C_8] = MLX5_MODI_META_REG_C_8,
974 : : [REG_C_9] = MLX5_MODI_META_REG_C_9,
975 : : [REG_C_10] = MLX5_MODI_META_REG_C_10,
976 : : [REG_C_11] = MLX5_MODI_META_REG_C_11,
977 : : };
978 : :
979 : : /**
980 : : * Convert register set to DV specification.
981 : : *
982 : : * @param[in,out] resource
983 : : * Pointer to the modify-header resource.
984 : : * @param[in] action
985 : : * Pointer to action specification.
986 : : * @param[out] error
987 : : * Pointer to the error structure.
988 : : *
989 : : * @return
990 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
991 : : */
992 : : static int
993 : 0 : flow_dv_convert_action_set_reg
994 : : (struct mlx5_flow_dv_modify_hdr_resource *resource,
995 : : const struct rte_flow_action *action,
996 : : struct rte_flow_error *error)
997 : : {
998 : 0 : const struct mlx5_rte_flow_action_set_tag *conf = action->conf;
999 : 0 : struct mlx5_modification_cmd *actions = resource->actions;
1000 : 0 : uint32_t i = resource->actions_num;
1001 : :
1002 [ # # ]: 0 : if (i >= MLX5_MAX_MODIFY_NUM)
1003 : 0 : return rte_flow_error_set(error, EINVAL,
1004 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1005 : : "too many items to modify");
1006 : : MLX5_ASSERT(conf->id != REG_NON);
1007 : : MLX5_ASSERT(conf->id < (enum modify_reg)RTE_DIM(reg_to_field));
1008 : 0 : actions[i] = (struct mlx5_modification_cmd) {
1009 : : .action_type = MLX5_MODIFICATION_TYPE_SET,
1010 : 0 : .field = reg_to_field[conf->id],
1011 : 0 : .offset = conf->offset,
1012 : 0 : .length = conf->length,
1013 : : };
1014 [ # # ]: 0 : actions[i].data0 = rte_cpu_to_be_32(actions[i].data0);
1015 [ # # ]: 0 : actions[i].data1 = rte_cpu_to_be_32(conf->data);
1016 : : ++i;
1017 : 0 : resource->actions_num = i;
1018 : 0 : return 0;
1019 : : }
1020 : :
1021 : : /**
1022 : : * Convert SET_TAG action to DV specification.
1023 : : *
1024 : : * @param[in] dev
1025 : : * Pointer to the rte_eth_dev structure.
1026 : : * @param[in,out] resource
1027 : : * Pointer to the modify-header resource.
1028 : : * @param[in] conf
1029 : : * Pointer to action specification.
1030 : : * @param[out] error
1031 : : * Pointer to the error structure.
1032 : : *
1033 : : * @return
1034 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1035 : : */
1036 : : static int
1037 : 0 : flow_dv_convert_action_set_tag
1038 : : (struct rte_eth_dev *dev,
1039 : : struct mlx5_flow_dv_modify_hdr_resource *resource,
1040 : : const struct rte_flow_action_set_tag *conf,
1041 : : struct rte_flow_error *error)
1042 : : {
1043 [ # # ]: 0 : rte_be32_t data = rte_cpu_to_be_32(conf->data);
1044 [ # # ]: 0 : rte_be32_t mask = rte_cpu_to_be_32(conf->mask);
1045 : 0 : struct rte_flow_item item = {
1046 : : .spec = &data,
1047 : : .mask = &mask,
1048 : : };
1049 : 0 : struct field_modify_info reg_c_x[] = {
1050 : : [1] = {0, 0, 0},
1051 : : };
1052 : : enum mlx5_modification_field reg_type;
1053 : : int ret;
1054 : :
1055 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, conf->index, error);
1056 [ # # ]: 0 : if (ret < 0)
1057 : : return ret;
1058 : : MLX5_ASSERT(ret != REG_NON);
1059 : : MLX5_ASSERT((unsigned int)ret < RTE_DIM(reg_to_field));
1060 : 0 : reg_type = reg_to_field[ret];
1061 : : MLX5_ASSERT(reg_type > 0);
1062 : 0 : reg_c_x[0] = (struct field_modify_info){4, 0, reg_type};
1063 : 0 : return flow_dv_convert_modify_action(&item, reg_c_x, NULL, resource,
1064 : : MLX5_MODIFICATION_TYPE_SET, error);
1065 : : }
1066 : :
1067 : : /**
1068 : : * Convert internal COPY_REG action to DV specification.
1069 : : *
1070 : : * @param[in] dev
1071 : : * Pointer to the rte_eth_dev structure.
1072 : : * @param[in,out] res
1073 : : * Pointer to the modify-header resource.
1074 : : * @param[in] action
1075 : : * Pointer to action specification.
1076 : : * @param[out] error
1077 : : * Pointer to the error structure.
1078 : : *
1079 : : * @return
1080 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1081 : : */
1082 : : static int
1083 : 0 : flow_dv_convert_action_copy_mreg(struct rte_eth_dev *dev,
1084 : : struct mlx5_flow_dv_modify_hdr_resource *res,
1085 : : const struct rte_flow_action *action,
1086 : : struct rte_flow_error *error)
1087 : : {
1088 : 0 : const struct mlx5_flow_action_copy_mreg *conf = action->conf;
1089 : 0 : rte_be32_t mask = RTE_BE32(UINT32_MAX);
1090 : 0 : struct rte_flow_item item = {
1091 : : .spec = NULL,
1092 : : .mask = &mask,
1093 : : };
1094 : 0 : struct field_modify_info reg_src[] = {
1095 : 0 : {4, 0, reg_to_field[conf->src]},
1096 : : {0, 0, 0},
1097 : : };
1098 : 0 : struct field_modify_info reg_dst = {
1099 : : .offset = 0,
1100 : 0 : .id = reg_to_field[conf->dst],
1101 : : };
1102 : : /* Adjust reg_c[0] usage according to reported mask. */
1103 [ # # # # ]: 0 : if (conf->dst == REG_C_0 || conf->src == REG_C_0) {
1104 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1105 : 0 : uint32_t reg_c0 = priv->sh->dv_regc0_mask;
1106 : :
1107 : : MLX5_ASSERT(reg_c0);
1108 : : MLX5_ASSERT(priv->sh->config.dv_xmeta_en !=
1109 : : MLX5_XMETA_MODE_LEGACY);
1110 [ # # ]: 0 : if (conf->dst == REG_C_0) {
1111 : : /* Copy to reg_c[0], within mask only. */
1112 : 0 : reg_dst.offset = rte_bsf32(reg_c0);
1113 [ # # ]: 0 : mask = rte_cpu_to_be_32(reg_c0 >> reg_dst.offset);
1114 : : } else {
1115 : : reg_dst.offset = 0;
1116 [ # # ]: 0 : mask = rte_cpu_to_be_32(reg_c0);
1117 : : }
1118 : : }
1119 : 0 : return flow_dv_convert_modify_action(&item,
1120 : : reg_src, ®_dst, res,
1121 : : MLX5_MODIFICATION_TYPE_COPY,
1122 : : error);
1123 : : }
1124 : :
1125 : : /**
1126 : : * Convert MARK action to DV specification. This routine is used
1127 : : * in extensive metadata only and requires metadata register to be
1128 : : * handled. In legacy mode hardware tag resource is engaged.
1129 : : *
1130 : : * @param[in] dev
1131 : : * Pointer to the rte_eth_dev structure.
1132 : : * @param[in] conf
1133 : : * Pointer to MARK action specification.
1134 : : * @param[in,out] resource
1135 : : * Pointer to the modify-header resource.
1136 : : * @param[out] error
1137 : : * Pointer to the error structure.
1138 : : *
1139 : : * @return
1140 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1141 : : */
1142 : : static int
1143 : 0 : flow_dv_convert_action_mark(struct rte_eth_dev *dev,
1144 : : const struct rte_flow_action_mark *conf,
1145 : : struct mlx5_flow_dv_modify_hdr_resource *resource,
1146 : : struct rte_flow_error *error)
1147 : : {
1148 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1149 [ # # ]: 0 : rte_be32_t mask = rte_cpu_to_be_32(MLX5_FLOW_MARK_MASK &
1150 : : priv->sh->dv_mark_mask);
1151 [ # # ]: 0 : rte_be32_t data = rte_cpu_to_be_32(conf->id) & mask;
1152 : 0 : struct rte_flow_item item = {
1153 : : .spec = &data,
1154 : : .mask = &mask,
1155 : : };
1156 : 0 : struct field_modify_info reg_c_x[] = {
1157 : : [1] = {0, 0, 0},
1158 : : };
1159 : : int reg;
1160 : :
1161 [ # # ]: 0 : if (!mask)
1162 : 0 : return rte_flow_error_set(error, EINVAL,
1163 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1164 : : NULL, "zero mark action mask");
1165 : 0 : reg = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
1166 [ # # ]: 0 : if (reg < 0)
1167 : : return reg;
1168 : : MLX5_ASSERT(reg > 0);
1169 [ # # ]: 0 : if (reg == REG_C_0) {
1170 [ # # ]: 0 : uint32_t msk_c0 = priv->sh->dv_regc0_mask;
1171 : : uint32_t shl_c0 = rte_bsf32(msk_c0);
1172 : :
1173 [ # # ]: 0 : data = rte_cpu_to_be_32(rte_cpu_to_be_32(data) << shl_c0);
1174 [ # # ]: 0 : mask = rte_cpu_to_be_32(mask) & msk_c0;
1175 [ # # ]: 0 : mask = rte_cpu_to_be_32(mask << shl_c0);
1176 : : }
1177 : 0 : reg_c_x[0] = (struct field_modify_info){4, 0, reg_to_field[reg]};
1178 : 0 : return flow_dv_convert_modify_action(&item, reg_c_x, NULL, resource,
1179 : : MLX5_MODIFICATION_TYPE_SET, error);
1180 : : }
1181 : :
1182 : : /**
1183 : : * Get metadata register index for specified steering domain.
1184 : : *
1185 : : * @param[in] dev
1186 : : * Pointer to the rte_eth_dev structure.
1187 : : * @param[in] attr
1188 : : * Attributes of flow to determine steering domain.
1189 : : * @param[out] error
1190 : : * Pointer to the error structure.
1191 : : *
1192 : : * @return
1193 : : * positive index on success, a negative errno value otherwise
1194 : : * and rte_errno is set.
1195 : : */
1196 : : static enum modify_reg
1197 : 0 : flow_dv_get_metadata_reg(struct rte_eth_dev *dev,
1198 : : const struct rte_flow_attr *attr,
1199 : : struct rte_flow_error *error)
1200 : : {
1201 : : int reg =
1202 [ # # ]: 0 : mlx5_flow_get_reg_id(dev, attr->transfer ?
1203 : 0 : MLX5_METADATA_FDB :
1204 [ # # ]: 0 : attr->egress ?
1205 : : MLX5_METADATA_TX :
1206 : : MLX5_METADATA_RX, 0, error);
1207 [ # # ]: 0 : if (reg < 0)
1208 : 0 : return rte_flow_error_set(error,
1209 : : ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM,
1210 : : NULL, "unavailable "
1211 : : "metadata register");
1212 : 0 : return reg;
1213 : : }
1214 : :
1215 : : /**
1216 : : * Convert SET_META action to DV specification.
1217 : : *
1218 : : * @param[in] dev
1219 : : * Pointer to the rte_eth_dev structure.
1220 : : * @param[in,out] resource
1221 : : * Pointer to the modify-header resource.
1222 : : * @param[in] attr
1223 : : * Attributes of flow that includes this item.
1224 : : * @param[in] conf
1225 : : * Pointer to action specification.
1226 : : * @param[out] error
1227 : : * Pointer to the error structure.
1228 : : *
1229 : : * @return
1230 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1231 : : */
1232 : : static int
1233 : 0 : flow_dv_convert_action_set_meta
1234 : : (struct rte_eth_dev *dev,
1235 : : struct mlx5_flow_dv_modify_hdr_resource *resource,
1236 : : const struct rte_flow_attr *attr,
1237 : : const struct rte_flow_action_set_meta *conf,
1238 : : struct rte_flow_error *error)
1239 : : {
1240 [ # # ]: 0 : uint32_t mask = rte_cpu_to_be_32(conf->mask);
1241 [ # # ]: 0 : uint32_t data = rte_cpu_to_be_32(conf->data) & mask;
1242 : 0 : struct rte_flow_item item = {
1243 : : .spec = &data,
1244 : : .mask = &mask,
1245 : : };
1246 : 0 : struct field_modify_info reg_c_x[] = {
1247 : : [1] = {0, 0, 0},
1248 : : };
1249 : 0 : int reg = flow_dv_get_metadata_reg(dev, attr, error);
1250 : :
1251 [ # # ]: 0 : if (reg < 0)
1252 : : return reg;
1253 : : MLX5_ASSERT(reg != REG_NON);
1254 [ # # ]: 0 : if (reg == REG_C_0) {
1255 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1256 [ # # ]: 0 : uint32_t msk_c0 = priv->sh->dv_regc0_mask;
1257 : : uint32_t shl_c0 = rte_bsf32(msk_c0);
1258 : :
1259 [ # # ]: 0 : data = rte_cpu_to_be_32(rte_cpu_to_be_32(data) << shl_c0);
1260 [ # # ]: 0 : mask = rte_cpu_to_be_32(mask) & msk_c0;
1261 [ # # ]: 0 : mask = rte_cpu_to_be_32(mask << shl_c0);
1262 : : }
1263 : 0 : reg_c_x[0] = (struct field_modify_info){4, 0, reg_to_field[reg]};
1264 : : /* The routine expects parameters in memory as big-endian ones. */
1265 : 0 : return flow_dv_convert_modify_action(&item, reg_c_x, NULL, resource,
1266 : : MLX5_MODIFICATION_TYPE_SET, error);
1267 : : }
1268 : :
1269 : : /**
1270 : : * Convert modify-header set IPv4 DSCP action to DV specification.
1271 : : *
1272 : : * @param[in,out] resource
1273 : : * Pointer to the modify-header resource.
1274 : : * @param[in] action
1275 : : * Pointer to action specification.
1276 : : * @param[out] error
1277 : : * Pointer to the error structure.
1278 : : *
1279 : : * @return
1280 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1281 : : */
1282 : : static int
1283 : 0 : flow_dv_convert_action_modify_ipv4_dscp
1284 : : (struct mlx5_flow_dv_modify_hdr_resource *resource,
1285 : : const struct rte_flow_action *action,
1286 : : struct rte_flow_error *error)
1287 : : {
1288 : 0 : const struct rte_flow_action_set_dscp *conf =
1289 : : (const struct rte_flow_action_set_dscp *)(action->conf);
1290 : 0 : struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV4 };
1291 : : struct rte_flow_item_ipv4 ipv4;
1292 : : struct rte_flow_item_ipv4 ipv4_mask;
1293 : :
1294 : : memset(&ipv4, 0, sizeof(ipv4));
1295 : : memset(&ipv4_mask, 0, sizeof(ipv4_mask));
1296 : 0 : ipv4.hdr.type_of_service = conf->dscp;
1297 : 0 : ipv4_mask.hdr.type_of_service = RTE_IPV4_HDR_DSCP_MASK >> 2;
1298 : 0 : item.spec = &ipv4;
1299 : 0 : item.mask = &ipv4_mask;
1300 : 0 : return flow_dv_convert_modify_action(&item, modify_ipv4, NULL, resource,
1301 : : MLX5_MODIFICATION_TYPE_SET, error);
1302 : : }
1303 : :
1304 : : /**
1305 : : * Convert modify-header set IPv6 DSCP action to DV specification.
1306 : : *
1307 : : * @param[in,out] resource
1308 : : * Pointer to the modify-header resource.
1309 : : * @param[in] action
1310 : : * Pointer to action specification.
1311 : : * @param[out] error
1312 : : * Pointer to the error structure.
1313 : : *
1314 : : * @return
1315 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1316 : : */
1317 : : static int
1318 : 0 : flow_dv_convert_action_modify_ipv6_dscp
1319 : : (struct mlx5_flow_dv_modify_hdr_resource *resource,
1320 : : const struct rte_flow_action *action,
1321 : : struct rte_flow_error *error)
1322 : : {
1323 : 0 : const struct rte_flow_action_set_dscp *conf =
1324 : : (const struct rte_flow_action_set_dscp *)(action->conf);
1325 : 0 : struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV6 };
1326 : : struct rte_flow_item_ipv6 ipv6;
1327 : : struct rte_flow_item_ipv6 ipv6_mask;
1328 : :
1329 : : memset(&ipv6, 0, sizeof(ipv6));
1330 : : memset(&ipv6_mask, 0, sizeof(ipv6_mask));
1331 : : /*
1332 : : * Even though the DSCP bits offset of IPv6 is not byte aligned,
1333 : : * rdma-core only accept the DSCP bits byte aligned start from
1334 : : * bit 0 to 5 as to be compatible with IPv4. No need to shift the
1335 : : * bits in IPv6 case as rdma-core requires byte aligned value.
1336 : : */
1337 : 0 : ipv6.hdr.vtc_flow = conf->dscp;
1338 : 0 : ipv6_mask.hdr.vtc_flow = RTE_IPV6_HDR_DSCP_MASK >> 22;
1339 : 0 : item.spec = &ipv6;
1340 : 0 : item.mask = &ipv6_mask;
1341 : 0 : return flow_dv_convert_modify_action(&item, modify_ipv6, NULL, resource,
1342 : : MLX5_MODIFICATION_TYPE_SET, error);
1343 : : }
1344 : :
1345 : : int
1346 : 0 : mlx5_flow_item_field_width(struct rte_eth_dev *dev,
1347 : : enum rte_flow_field_id field, int inherit,
1348 : : const struct rte_flow_attr *attr,
1349 : : struct rte_flow_error *error)
1350 : : {
1351 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1352 : :
1353 [ # # # # : 0 : switch (field) {
# # # # #
# # # # #
# # # #
# ]
1354 : : case RTE_FLOW_FIELD_START:
1355 : : return 32;
1356 : 0 : case RTE_FLOW_FIELD_MAC_DST:
1357 : : case RTE_FLOW_FIELD_MAC_SRC:
1358 : 0 : return 48;
1359 : 0 : case RTE_FLOW_FIELD_VLAN_TYPE:
1360 : 0 : return 16;
1361 : 0 : case RTE_FLOW_FIELD_VLAN_ID:
1362 : 0 : return 12;
1363 : 0 : case RTE_FLOW_FIELD_MAC_TYPE:
1364 : 0 : return 16;
1365 : 0 : case RTE_FLOW_FIELD_IPV4_DSCP:
1366 : 0 : return 6;
1367 : 0 : case RTE_FLOW_FIELD_IPV4_TTL:
1368 : 0 : return 8;
1369 : : case RTE_FLOW_FIELD_IPV4_SRC:
1370 : : case RTE_FLOW_FIELD_IPV4_DST:
1371 : : return 32;
1372 : 0 : case RTE_FLOW_FIELD_IPV6_DSCP:
1373 : 0 : return 6;
1374 : 0 : case RTE_FLOW_FIELD_IPV6_HOPLIMIT:
1375 : : case RTE_FLOW_FIELD_IPV6_PROTO:
1376 : 0 : return 8;
1377 : 0 : case RTE_FLOW_FIELD_IPV6_SRC:
1378 : : case RTE_FLOW_FIELD_IPV6_DST:
1379 : 0 : return 128;
1380 : 0 : case RTE_FLOW_FIELD_TCP_PORT_SRC:
1381 : : case RTE_FLOW_FIELD_TCP_PORT_DST:
1382 : 0 : return 16;
1383 : : case RTE_FLOW_FIELD_TCP_SEQ_NUM:
1384 : : case RTE_FLOW_FIELD_TCP_ACK_NUM:
1385 : : return 32;
1386 : 0 : case RTE_FLOW_FIELD_TCP_FLAGS:
1387 : 0 : return 9;
1388 : 0 : case RTE_FLOW_FIELD_UDP_PORT_SRC:
1389 : : case RTE_FLOW_FIELD_UDP_PORT_DST:
1390 : 0 : return 16;
1391 : 0 : case RTE_FLOW_FIELD_VXLAN_VNI:
1392 : : case RTE_FLOW_FIELD_GENEVE_VNI:
1393 : 0 : return 24;
1394 : : case RTE_FLOW_FIELD_GTP_TEID:
1395 : : case RTE_FLOW_FIELD_MPLS:
1396 : : case RTE_FLOW_FIELD_TAG:
1397 : : return 32;
1398 : 0 : case RTE_FLOW_FIELD_MARK:
1399 : 0 : return rte_popcount32(priv->sh->dv_mark_mask);
1400 : 0 : case RTE_FLOW_FIELD_META:
1401 : 0 : return (flow_dv_get_metadata_reg(dev, attr, error) == REG_C_0) ?
1402 [ # # ]: 0 : rte_popcount32(priv->sh->dv_meta_mask) : 32;
1403 : 0 : case RTE_FLOW_FIELD_POINTER:
1404 : : case RTE_FLOW_FIELD_VALUE:
1405 : 0 : return inherit < 0 ? 0 : inherit;
1406 : 0 : case RTE_FLOW_FIELD_IPV4_ECN:
1407 : : case RTE_FLOW_FIELD_IPV6_ECN:
1408 : : case RTE_FLOW_FIELD_METER_COLOR:
1409 : 0 : return 2;
1410 : : case RTE_FLOW_FIELD_HASH_RESULT:
1411 : : return 32;
1412 : 0 : default:
1413 : : MLX5_ASSERT(false);
1414 : : }
1415 : 0 : return 0;
1416 : : }
1417 : :
1418 : : static __rte_always_inline uint8_t
1419 : : flow_modify_info_mask_8(uint32_t length, uint32_t off)
1420 : : {
1421 : 0 : return (0xffu >> (8 - length)) << off;
1422 : : }
1423 : :
1424 : : static __rte_always_inline uint16_t
1425 : : flow_modify_info_mask_16(uint32_t length, uint32_t off)
1426 : : {
1427 [ # # # # : 0 : return rte_cpu_to_be_16((0xffffu >> (16 - length)) << off);
# # # # #
# # # # #
# # # # ]
1428 : : }
1429 : :
1430 : : static __rte_always_inline uint32_t
1431 : : flow_modify_info_mask_32(uint32_t length, uint32_t off)
1432 : : {
1433 [ # # # # : 0 : return rte_cpu_to_be_32((0xffffffffu >> (32 - length)) << off);
# # # # #
# # # # #
# # # # #
# # # #
# ]
1434 : : }
1435 : :
1436 : : static __rte_always_inline uint32_t
1437 : : flow_modify_info_mask_32_masked(uint32_t length, uint32_t off, uint32_t post_mask)
1438 : : {
1439 : 0 : uint32_t mask = (0xffffffffu >> (32 - length)) << off;
1440 : 0 : return rte_cpu_to_be_32(mask & post_mask);
1441 : : }
1442 : :
1443 : : static __rte_always_inline enum mlx5_modification_field
1444 : : mlx5_mpls_modi_field_get(const struct rte_flow_action_modify_data *data)
1445 : : {
1446 : 0 : return MLX5_MODI_IN_MPLS_LABEL_0 + data->tag_index;
1447 : : }
1448 : :
1449 : : static void
1450 : 0 : mlx5_modify_flex_item(const struct rte_eth_dev *dev,
1451 : : const struct mlx5_flex_item *flex,
1452 : : const struct rte_flow_action_modify_data *data,
1453 : : struct field_modify_info *info,
1454 : : uint32_t *mask, uint32_t width)
1455 : : {
1456 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1457 : 0 : struct mlx5_hca_flex_attr *attr = &priv->sh->cdev->config.hca_attr.flex;
1458 : : uint32_t i, j;
1459 : : int id = 0;
1460 : 0 : uint32_t pos = 0;
1461 : : const struct mlx5_flex_pattern_field *map;
1462 : 0 : uint32_t offset = data->offset;
1463 : : uint32_t width_left = width;
1464 : : uint32_t def;
1465 : : uint32_t cur_width = 0;
1466 : : uint32_t tmp_ofs;
1467 : : uint32_t idx = 0;
1468 : : struct field_modify_info tmp;
1469 : : int tmp_id;
1470 : :
1471 [ # # ]: 0 : if (!attr->query_match_sample_info) {
1472 : 0 : DRV_LOG(ERR, "FW doesn't support modify field with flex item.");
1473 : 0 : return;
1474 : : }
1475 : : /*
1476 : : * search for the mapping instance until Accumulated width is no
1477 : : * less than data->offset.
1478 : : */
1479 [ # # ]: 0 : for (i = 0; i < flex->mapnum; i++) {
1480 [ # # ]: 0 : if (flex->map[i].width + pos > data->offset)
1481 : : break;
1482 : 0 : pos += flex->map[i].width;
1483 : : }
1484 [ # # ]: 0 : if (i >= flex->mapnum)
1485 : : return;
1486 [ # # ]: 0 : tmp_ofs = pos < data->offset ? data->offset - pos : 0;
1487 [ # # # # ]: 0 : for (j = i; i < flex->mapnum && width_left > 0; ) {
1488 : 0 : map = flex->map + i;
1489 : 0 : id = mlx5_flex_get_sample_id(flex, i, &pos, false, &def);
1490 [ # # ]: 0 : if (id == -1) {
1491 : 0 : i++;
1492 : : /* All left length is dummy */
1493 [ # # ]: 0 : if (pos >= data->offset + width)
1494 : : return;
1495 : 0 : cur_width = map->width;
1496 : : /* One mapping instance covers the whole width. */
1497 [ # # ]: 0 : } else if (pos + map->width >= (data->offset + width)) {
1498 : : cur_width = width_left;
1499 : : } else {
1500 : 0 : cur_width = cur_width + map->width - tmp_ofs;
1501 : 0 : pos += map->width;
1502 : : /*
1503 : : * Continue to search next until:
1504 : : * 1. Another flex parser ID.
1505 : : * 2. Width has been covered.
1506 : : */
1507 [ # # ]: 0 : for (j = i + 1; j < flex->mapnum; j++) {
1508 : 0 : tmp_id = mlx5_flex_get_sample_id(flex, j, &pos, false, &def);
1509 [ # # ]: 0 : if (tmp_id == -1) {
1510 : : i = j;
1511 : 0 : pos -= flex->map[j].width;
1512 : 0 : break;
1513 : : }
1514 [ # # # # ]: 0 : if (id >= (int)flex->devx_fp->num_samples ||
1515 [ # # ]: 0 : id >= MLX5_GRAPH_NODE_SAMPLE_NUM ||
1516 [ # # ]: 0 : tmp_id >= (int)flex->devx_fp->num_samples ||
1517 : : tmp_id >= MLX5_GRAPH_NODE_SAMPLE_NUM)
1518 : : return;
1519 : 0 : if (flex->devx_fp->sample_info[id].modify_field_id !=
1520 [ # # ]: 0 : flex->devx_fp->sample_info[tmp_id].modify_field_id ||
1521 : 0 : flex->map[j].shift != flex->map[j - 1].width +
1522 [ # # ]: 0 : flex->map[j - 1].shift) {
1523 : : i = j;
1524 : : break;
1525 : : }
1526 [ # # ]: 0 : if ((pos + flex->map[j].width) >= (data->offset + width)) {
1527 : : cur_width = width_left;
1528 : : break;
1529 : : }
1530 : 0 : pos += flex->map[j].width;
1531 : 0 : cur_width += flex->map[j].width;
1532 : : }
1533 : : }
1534 [ # # ]: 0 : if (cur_width > width_left)
1535 : : cur_width = width_left;
1536 [ # # # # : 0 : else if (cur_width < width_left && (j == flex->mapnum || i == flex->mapnum))
# # ]
1537 : : return;
1538 : :
1539 : : MLX5_ASSERT(id < (int)flex->devx_fp->num_samples);
1540 [ # # # # ]: 0 : if (id >= (int)flex->devx_fp->num_samples || id >= MLX5_GRAPH_NODE_SAMPLE_NUM)
1541 : : return;
1542 : : /* Use invalid entry as placeholder for DUMMY mapping. */
1543 : 0 : info[idx] = (struct field_modify_info){cur_width / CHAR_BIT, offset / CHAR_BIT,
1544 [ # # ]: 0 : id == -1 ? MLX5_MODI_INVALID :
1545 : : (enum mlx5_modification_field)
1546 : 0 : flex->devx_fp->sample_info[id].modify_field_id,
1547 : 0 : map->shift + tmp_ofs, 1};
1548 : 0 : offset += cur_width;
1549 : 0 : width_left -= cur_width;
1550 [ # # ]: 0 : if (!mask) {
1551 : 0 : info[idx].offset = (32 - cur_width - map->shift - tmp_ofs);
1552 : 0 : info[idx].size = cur_width / CHAR_BIT + info[idx].offset / CHAR_BIT;
1553 : : }
1554 : : cur_width = 0;
1555 : : tmp_ofs = 0;
1556 : 0 : idx++;
1557 : : }
1558 [ # # ]: 0 : if (unlikely(width_left > 0)) {
1559 : : MLX5_ASSERT(false);
1560 : : return;
1561 : : }
1562 [ # # ]: 0 : if (mask)
1563 : 0 : memset(mask, 0xff, data->offset / CHAR_BIT + width / CHAR_BIT);
1564 : : /* Re-order the info to follow IPv6 address. */
1565 [ # # ]: 0 : for (i = 0; i < idx / 2; i++) {
1566 : 0 : tmp = info[i];
1567 : : MLX5_ASSERT(info[i].id);
1568 : : MLX5_ASSERT(info[idx - 1 - i].id);
1569 : 0 : info[i] = info[idx - 1 - i];
1570 : 0 : info[idx - 1 - i] = tmp;
1571 : : }
1572 : : }
1573 : :
1574 : : void
1575 : 0 : mlx5_flow_field_id_to_modify_info
1576 : : (const struct rte_flow_action_modify_data *data,
1577 : : struct field_modify_info *info, uint32_t *mask,
1578 : : uint32_t width, struct rte_eth_dev *dev,
1579 : : const struct rte_flow_attr *attr, struct rte_flow_error *error)
1580 : : {
1581 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1582 : : uint32_t idx = 0;
1583 : : uint32_t off_be = 0;
1584 : : uint32_t length = 0;
1585 [ # # # # : 0 : switch ((int)data->field) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # ]
1586 : : case RTE_FLOW_FIELD_START:
1587 : : /* not supported yet */
1588 : : MLX5_ASSERT(false);
1589 : : break;
1590 : 0 : case RTE_FLOW_FIELD_MAC_DST:
1591 : : MLX5_ASSERT(data->offset + width <= 48);
1592 : 0 : off_be = 48 - (data->offset + width);
1593 [ # # ]: 0 : if (off_be < 16) {
1594 : 0 : info[idx] = (struct field_modify_info){2, 4,
1595 : : MLX5_MODI_OUT_DMAC_15_0};
1596 [ # # ]: 0 : length = off_be + width <= 16 ? width : 16 - off_be;
1597 [ # # ]: 0 : if (mask)
1598 : 0 : mask[1] = flow_modify_info_mask_16(length,
1599 : : off_be);
1600 : : else
1601 : 0 : info[idx].offset = off_be;
1602 : 0 : width -= length;
1603 [ # # ]: 0 : if (!width)
1604 : : break;
1605 : : off_be = 0;
1606 : : idx++;
1607 : : } else {
1608 : 0 : off_be -= 16;
1609 : : }
1610 : 0 : info[idx] = (struct field_modify_info){4, 0,
1611 : : MLX5_MODI_OUT_DMAC_47_16};
1612 [ # # ]: 0 : if (mask)
1613 : 0 : mask[0] = flow_modify_info_mask_32(width, off_be);
1614 : : else
1615 : 0 : info[idx].offset = off_be;
1616 : : break;
1617 : 0 : case RTE_FLOW_FIELD_MAC_SRC:
1618 : : MLX5_ASSERT(data->offset + width <= 48);
1619 : 0 : off_be = 48 - (data->offset + width);
1620 [ # # ]: 0 : if (off_be < 16) {
1621 : 0 : info[idx] = (struct field_modify_info){2, 4,
1622 : : MLX5_MODI_OUT_SMAC_15_0};
1623 [ # # ]: 0 : length = off_be + width <= 16 ? width : 16 - off_be;
1624 [ # # ]: 0 : if (mask)
1625 : 0 : mask[1] = flow_modify_info_mask_16(length,
1626 : : off_be);
1627 : : else
1628 : 0 : info[idx].offset = off_be;
1629 : 0 : width -= length;
1630 [ # # ]: 0 : if (!width)
1631 : : break;
1632 : : off_be = 0;
1633 : : idx++;
1634 : : } else {
1635 : 0 : off_be -= 16;
1636 : : }
1637 : 0 : info[idx] = (struct field_modify_info){4, 0,
1638 : : MLX5_MODI_OUT_SMAC_47_16};
1639 [ # # ]: 0 : if (mask)
1640 : 0 : mask[0] = flow_modify_info_mask_32(width, off_be);
1641 : : else
1642 : 0 : info[idx].offset = off_be;
1643 : : break;
1644 : : case RTE_FLOW_FIELD_VLAN_TYPE:
1645 : : /* not supported yet */
1646 : : break;
1647 : 0 : case RTE_FLOW_FIELD_VLAN_ID:
1648 : : MLX5_ASSERT(data->offset + width <= 12);
1649 : 0 : off_be = 12 - (data->offset + width);
1650 : 0 : info[idx] = (struct field_modify_info){2, 0,
1651 : : MLX5_MODI_OUT_FIRST_VID};
1652 [ # # ]: 0 : if (mask)
1653 : 0 : mask[idx] = flow_modify_info_mask_16(width, off_be);
1654 : : else
1655 : 0 : info[idx].offset = off_be;
1656 : : break;
1657 : 0 : case RTE_FLOW_FIELD_MAC_TYPE:
1658 : : MLX5_ASSERT(data->offset + width <= 16);
1659 : 0 : off_be = 16 - (data->offset + width);
1660 : 0 : info[idx] = (struct field_modify_info){2, 0,
1661 : : MLX5_MODI_OUT_ETHERTYPE};
1662 [ # # ]: 0 : if (mask)
1663 : 0 : mask[idx] = flow_modify_info_mask_16(width, off_be);
1664 : : else
1665 : 0 : info[idx].offset = off_be;
1666 : : break;
1667 : 0 : case RTE_FLOW_FIELD_IPV4_DSCP:
1668 : : MLX5_ASSERT(data->offset + width <= 6);
1669 : 0 : off_be = 6 - (data->offset + width);
1670 : 0 : info[idx] = (struct field_modify_info){1, 0,
1671 : : MLX5_MODI_OUT_IP_DSCP};
1672 [ # # ]: 0 : if (mask)
1673 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
1674 : : else
1675 : 0 : info[idx].offset = off_be;
1676 : : break;
1677 : 0 : case RTE_FLOW_FIELD_IPV4_TTL:
1678 : : MLX5_ASSERT(data->offset + width <= 8);
1679 : 0 : off_be = 8 - (data->offset + width);
1680 : 0 : info[idx] = (struct field_modify_info){1, 0,
1681 : : MLX5_MODI_OUT_IPV4_TTL};
1682 [ # # ]: 0 : if (mask)
1683 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
1684 : : else
1685 : 0 : info[idx].offset = off_be;
1686 : : break;
1687 : 0 : case RTE_FLOW_FIELD_IPV4_SRC:
1688 : : MLX5_ASSERT(data->offset + width <= 32);
1689 : 0 : off_be = 32 - (data->offset + width);
1690 : 0 : info[idx] = (struct field_modify_info){4, 0,
1691 : : MLX5_MODI_OUT_SIPV4};
1692 [ # # ]: 0 : if (mask)
1693 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
1694 : : else
1695 : 0 : info[idx].offset = off_be;
1696 : : break;
1697 : 0 : case RTE_FLOW_FIELD_IPV4_DST:
1698 : : MLX5_ASSERT(data->offset + width <= 32);
1699 : 0 : off_be = 32 - (data->offset + width);
1700 : 0 : info[idx] = (struct field_modify_info){4, 0,
1701 : : MLX5_MODI_OUT_DIPV4};
1702 [ # # ]: 0 : if (mask)
1703 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
1704 : : else
1705 : 0 : info[idx].offset = off_be;
1706 : : break;
1707 : 0 : case RTE_FLOW_FIELD_IPV6_DSCP:
1708 : : MLX5_ASSERT(data->offset + width <= 6);
1709 : 0 : off_be = 6 - (data->offset + width);
1710 : 0 : info[idx] = (struct field_modify_info){1, 0,
1711 : : MLX5_MODI_OUT_IP_DSCP};
1712 [ # # ]: 0 : if (mask)
1713 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
1714 : : else
1715 : 0 : info[idx].offset = off_be;
1716 : : break;
1717 : 0 : case RTE_FLOW_FIELD_IPV6_HOPLIMIT:
1718 : : MLX5_ASSERT(data->offset + width <= 8);
1719 : 0 : off_be = 8 - (data->offset + width);
1720 : 0 : info[idx] = (struct field_modify_info){1, 0,
1721 : : MLX5_MODI_OUT_IPV6_HOPLIMIT};
1722 [ # # ]: 0 : if (mask)
1723 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
1724 : : else
1725 : 0 : info[idx].offset = off_be;
1726 : : break;
1727 : 0 : case RTE_FLOW_FIELD_IPV6_SRC: {
1728 : : /*
1729 : : * Fields corresponding to IPv6 source address bytes
1730 : : * arranged according to network byte ordering.
1731 : : */
1732 : 0 : struct field_modify_info fields[] = {
1733 : : { 4, 0, MLX5_MODI_OUT_SIPV6_127_96 },
1734 : : { 4, 4, MLX5_MODI_OUT_SIPV6_95_64 },
1735 : : { 4, 8, MLX5_MODI_OUT_SIPV6_63_32 },
1736 : : { 4, 12, MLX5_MODI_OUT_SIPV6_31_0 },
1737 : : };
1738 : : /* First mask to be modified is the mask of 4th address byte. */
1739 : : uint32_t midx = 3;
1740 : :
1741 : : MLX5_ASSERT(data->offset + width <= 128);
1742 : 0 : off_be = 128 - (data->offset + width);
1743 [ # # ]: 0 : while (width > 0 && midx > 0) {
1744 [ # # ]: 0 : if (off_be < 32) {
1745 : 0 : info[idx] = fields[midx];
1746 : 0 : length = off_be + width <= 32 ?
1747 [ # # ]: 0 : width : 32 - off_be;
1748 [ # # ]: 0 : if (mask)
1749 [ # # ]: 0 : mask[midx] = flow_modify_info_mask_32
1750 : : (length, off_be);
1751 : : else
1752 : 0 : info[idx].offset = off_be;
1753 : 0 : width -= length;
1754 : : off_be = 0;
1755 : 0 : idx++;
1756 : : } else {
1757 : 0 : off_be -= 32;
1758 : : }
1759 : 0 : midx--;
1760 : : }
1761 [ # # ]: 0 : if (!width)
1762 : : break;
1763 : 0 : info[idx] = fields[midx];
1764 [ # # ]: 0 : if (mask)
1765 [ # # ]: 0 : mask[midx] = flow_modify_info_mask_32(width, off_be);
1766 : : else
1767 : 0 : info[idx].offset = off_be;
1768 : : break;
1769 : : }
1770 : 0 : case RTE_FLOW_FIELD_IPV6_DST: {
1771 : : /*
1772 : : * Fields corresponding to IPv6 destination address bytes
1773 : : * arranged according to network byte ordering.
1774 : : */
1775 : 0 : struct field_modify_info fields[] = {
1776 : : { 4, 0, MLX5_MODI_OUT_DIPV6_127_96 },
1777 : : { 4, 4, MLX5_MODI_OUT_DIPV6_95_64 },
1778 : : { 4, 8, MLX5_MODI_OUT_DIPV6_63_32 },
1779 : : { 4, 12, MLX5_MODI_OUT_DIPV6_31_0 },
1780 : : };
1781 : : /* First mask to be modified is the mask of 4th address byte. */
1782 : : uint32_t midx = 3;
1783 : :
1784 : : MLX5_ASSERT(data->offset + width <= 128);
1785 : 0 : off_be = 128 - (data->offset + width);
1786 [ # # ]: 0 : while (width > 0 && midx > 0) {
1787 [ # # ]: 0 : if (off_be < 32) {
1788 : 0 : info[idx] = fields[midx];
1789 : 0 : length = off_be + width <= 32 ?
1790 [ # # ]: 0 : width : 32 - off_be;
1791 [ # # ]: 0 : if (mask)
1792 [ # # ]: 0 : mask[midx] = flow_modify_info_mask_32
1793 : : (length, off_be);
1794 : : else
1795 : 0 : info[idx].offset = off_be;
1796 : 0 : width -= length;
1797 : : off_be = 0;
1798 : 0 : idx++;
1799 : : } else {
1800 : 0 : off_be -= 32;
1801 : : }
1802 : 0 : midx--;
1803 : : }
1804 [ # # ]: 0 : if (!width)
1805 : : break;
1806 : 0 : info[idx] = fields[midx];
1807 [ # # ]: 0 : if (mask)
1808 [ # # ]: 0 : mask[midx] = flow_modify_info_mask_32(width, off_be);
1809 : : else
1810 : 0 : info[idx].offset = off_be;
1811 : : break;
1812 : : }
1813 : 0 : case RTE_FLOW_FIELD_TCP_PORT_SRC:
1814 : : MLX5_ASSERT(data->offset + width <= 16);
1815 : 0 : off_be = 16 - (data->offset + width);
1816 : 0 : info[idx] = (struct field_modify_info){2, 0,
1817 : : MLX5_MODI_OUT_TCP_SPORT};
1818 [ # # ]: 0 : if (mask)
1819 : 0 : mask[idx] = flow_modify_info_mask_16(width, off_be);
1820 : : else
1821 : 0 : info[idx].offset = off_be;
1822 : : break;
1823 : 0 : case RTE_FLOW_FIELD_TCP_PORT_DST:
1824 : : MLX5_ASSERT(data->offset + width <= 16);
1825 : 0 : off_be = 16 - (data->offset + width);
1826 : 0 : info[idx] = (struct field_modify_info){2, 0,
1827 : : MLX5_MODI_OUT_TCP_DPORT};
1828 [ # # ]: 0 : if (mask)
1829 : 0 : mask[idx] = flow_modify_info_mask_16(width, off_be);
1830 : : else
1831 : 0 : info[idx].offset = off_be;
1832 : : break;
1833 : 0 : case RTE_FLOW_FIELD_TCP_SEQ_NUM:
1834 : : MLX5_ASSERT(data->offset + width <= 32);
1835 : 0 : off_be = 32 - (data->offset + width);
1836 : 0 : info[idx] = (struct field_modify_info){4, 0,
1837 : : MLX5_MODI_OUT_TCP_SEQ_NUM};
1838 [ # # ]: 0 : if (mask)
1839 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
1840 : : else
1841 : 0 : info[idx].offset = off_be;
1842 : : break;
1843 : 0 : case RTE_FLOW_FIELD_TCP_ACK_NUM:
1844 : : MLX5_ASSERT(data->offset + width <= 32);
1845 : 0 : off_be = 32 - (data->offset + width);
1846 : 0 : info[idx] = (struct field_modify_info){4, 0,
1847 : : MLX5_MODI_OUT_TCP_ACK_NUM};
1848 [ # # ]: 0 : if (mask)
1849 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
1850 : : else
1851 : 0 : info[idx].offset = off_be;
1852 : : break;
1853 : 0 : case RTE_FLOW_FIELD_TCP_FLAGS:
1854 : : MLX5_ASSERT(data->offset + width <= 9);
1855 : 0 : off_be = 9 - (data->offset + width);
1856 : 0 : info[idx] = (struct field_modify_info){2, 0,
1857 : : MLX5_MODI_OUT_TCP_FLAGS};
1858 [ # # ]: 0 : if (mask)
1859 : 0 : mask[idx] = flow_modify_info_mask_16(width, off_be);
1860 : : else
1861 : 0 : info[idx].offset = off_be;
1862 : : break;
1863 : 0 : case RTE_FLOW_FIELD_UDP_PORT_SRC:
1864 : : MLX5_ASSERT(data->offset + width <= 16);
1865 : 0 : off_be = 16 - (data->offset + width);
1866 : 0 : info[idx] = (struct field_modify_info){2, 0,
1867 : : MLX5_MODI_OUT_UDP_SPORT};
1868 [ # # ]: 0 : if (mask)
1869 : 0 : mask[idx] = flow_modify_info_mask_16(width, off_be);
1870 : : else
1871 : 0 : info[idx].offset = off_be;
1872 : : break;
1873 : 0 : case RTE_FLOW_FIELD_UDP_PORT_DST:
1874 : : MLX5_ASSERT(data->offset + width <= 16);
1875 : 0 : off_be = 16 - (data->offset + width);
1876 : 0 : info[idx] = (struct field_modify_info){2, 0,
1877 : : MLX5_MODI_OUT_UDP_DPORT};
1878 [ # # ]: 0 : if (mask)
1879 : 0 : mask[idx] = flow_modify_info_mask_16(width, off_be);
1880 : : else
1881 : 0 : info[idx].offset = off_be;
1882 : : break;
1883 : 0 : case RTE_FLOW_FIELD_VXLAN_VNI:
1884 : : MLX5_ASSERT(data->offset + width <= 24);
1885 : : /* VNI is on bits 31-8 of TUNNEL_HDR_DW_1. */
1886 : 0 : off_be = 24 - (data->offset + width) + 8;
1887 : 0 : info[idx] = (struct field_modify_info){4, 0,
1888 : : MLX5_MODI_TUNNEL_HDR_DW_1};
1889 [ # # ]: 0 : if (mask)
1890 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
1891 : : else
1892 : 0 : info[idx].offset = off_be;
1893 : : break;
1894 : : case RTE_FLOW_FIELD_GENEVE_VNI:
1895 : : /* not supported yet*/
1896 : : break;
1897 : 0 : case RTE_FLOW_FIELD_GTP_TEID:
1898 : : MLX5_ASSERT(data->offset + width <= 32);
1899 : 0 : off_be = 32 - (data->offset + width);
1900 : 0 : info[idx] = (struct field_modify_info){4, 0,
1901 : : MLX5_MODI_GTP_TEID};
1902 [ # # ]: 0 : if (mask)
1903 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
1904 : : else
1905 : 0 : info[idx].offset = off_be;
1906 : : break;
1907 : 0 : case RTE_FLOW_FIELD_MPLS:
1908 : : MLX5_ASSERT(data->offset + width <= 32);
1909 : 0 : off_be = 32 - (data->offset + width);
1910 : 0 : info[idx] = (struct field_modify_info){4, 0,
1911 : : mlx5_mpls_modi_field_get(data)};
1912 [ # # ]: 0 : if (mask)
1913 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
1914 : : else
1915 : 0 : info[idx].offset = off_be;
1916 : : break;
1917 : : case RTE_FLOW_FIELD_TAG:
1918 : : {
1919 : : MLX5_ASSERT(data->offset + width <= 32);
1920 : : uint8_t tag_index = flow_tag_index_get(data);
1921 : : int reg;
1922 : :
1923 : : off_be = (tag_index == RTE_PMD_MLX5_LINEAR_HASH_TAG_INDEX) ?
1924 [ # # ]: 0 : 16 - (data->offset + width) + 16 : data->offset;
1925 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2)
1926 : 0 : reg = flow_hw_get_reg_id(dev,
1927 : : RTE_FLOW_ITEM_TYPE_TAG,
1928 [ # # ]: 0 : data->level);
1929 : : else
1930 : 0 : reg = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG,
1931 : : tag_index, error);
1932 [ # # ]: 0 : if (reg < 0)
1933 : : return;
1934 : : MLX5_ASSERT(reg != REG_NON);
1935 : : MLX5_ASSERT((unsigned int)reg < RTE_DIM(reg_to_field));
1936 : 0 : info[idx] = (struct field_modify_info){4, 0,
1937 : 0 : reg_to_field[reg]};
1938 [ # # ]: 0 : if (mask)
1939 : 0 : mask[idx] = flow_modify_info_mask_32
1940 : : (width, off_be);
1941 : : else
1942 : 0 : info[idx].offset = off_be;
1943 : : }
1944 : : break;
1945 : 0 : case RTE_FLOW_FIELD_MARK:
1946 : : {
1947 : 0 : uint32_t mark_mask = priv->sh->dv_mark_mask;
1948 : : uint32_t mark_count = rte_popcount32(mark_mask);
1949 : : RTE_SET_USED(mark_count);
1950 : : MLX5_ASSERT(data->offset + width <= mark_count);
1951 : 0 : int reg = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK,
1952 : : 0, error);
1953 [ # # ]: 0 : if (reg < 0)
1954 : : return;
1955 : : MLX5_ASSERT(reg != REG_NON);
1956 : : MLX5_ASSERT((unsigned int)reg < RTE_DIM(reg_to_field));
1957 : 0 : info[idx] = (struct field_modify_info){4, 0,
1958 : 0 : reg_to_field[reg]};
1959 [ # # ]: 0 : if (mask)
1960 : 0 : mask[idx] = flow_modify_info_mask_32_masked
1961 [ # # ]: 0 : (width, data->offset, mark_mask);
1962 : : else
1963 : 0 : info[idx].offset = data->offset;
1964 : : }
1965 : : break;
1966 : 0 : case RTE_FLOW_FIELD_META:
1967 : : {
1968 : 0 : uint32_t meta_mask = priv->sh->dv_meta_mask;
1969 : : uint32_t meta_count = rte_popcount32(meta_mask);
1970 : : RTE_SET_USED(meta_count);
1971 : : MLX5_ASSERT(data->offset + width <= meta_count);
1972 : 0 : int reg = flow_dv_get_metadata_reg(dev, attr, error);
1973 [ # # ]: 0 : if (reg < 0)
1974 : : return;
1975 : : MLX5_ASSERT(reg != REG_NON);
1976 : : MLX5_ASSERT((unsigned int)reg < RTE_DIM(reg_to_field));
1977 : 0 : info[idx] = (struct field_modify_info){4, 0,
1978 : 0 : reg_to_field[reg]};
1979 [ # # ]: 0 : if (mask)
1980 : 0 : mask[idx] = flow_modify_info_mask_32_masked
1981 [ # # ]: 0 : (width, data->offset, meta_mask);
1982 : : else
1983 : 0 : info[idx].offset = data->offset;
1984 : : }
1985 : : break;
1986 : 0 : case RTE_FLOW_FIELD_IPV4_ECN:
1987 : : case RTE_FLOW_FIELD_IPV6_ECN:
1988 : : MLX5_ASSERT(data->offset + width <= 2);
1989 : 0 : off_be = 2 - (data->offset + width);
1990 : 0 : info[idx] = (struct field_modify_info){1, 0,
1991 : : MLX5_MODI_OUT_IP_ECN};
1992 [ # # ]: 0 : if (mask)
1993 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
1994 : : else
1995 : 0 : info[idx].offset = off_be;
1996 : : break;
1997 : 0 : case RTE_FLOW_FIELD_GTP_PSC_QFI:
1998 : : MLX5_ASSERT(data->offset + width <= 8);
1999 : 0 : off_be = data->offset + 8;
2000 : 0 : info[idx] = (struct field_modify_info){4, 0,
2001 : : MLX5_MODI_GTPU_FIRST_EXT_DW_0};
2002 [ # # ]: 0 : if (mask)
2003 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
2004 : : else
2005 : 0 : info[idx].offset = off_be;
2006 : : break;
2007 : 0 : case MLX5_RTE_FLOW_FIELD_META_REG:
2008 : : {
2009 [ # # ]: 0 : uint32_t meta_mask = priv->sh->dv_meta_mask;
2010 : : uint32_t meta_count = rte_popcount32(meta_mask);
2011 : : uint8_t reg = flow_tag_index_get(data);
2012 : :
2013 : : RTE_SET_USED(meta_count);
2014 : : MLX5_ASSERT(data->offset + width <= meta_count);
2015 : : MLX5_ASSERT(reg != REG_NON);
2016 : : MLX5_ASSERT(reg < RTE_DIM(reg_to_field));
2017 : 0 : info[idx] = (struct field_modify_info){4, 0, reg_to_field[reg]};
2018 [ # # ]: 0 : if (mask)
2019 : 0 : mask[idx] = flow_modify_info_mask_32_masked
2020 [ # # ]: 0 : (width, data->offset, meta_mask);
2021 : : else
2022 : 0 : info[idx].offset = data->offset;
2023 : : }
2024 : : break;
2025 : 0 : case RTE_FLOW_FIELD_METER_COLOR:
2026 : : {
2027 : : const uint32_t color_mask =
2028 : : (UINT32_C(1) << MLX5_MTR_COLOR_BITS) - 1;
2029 : : int reg;
2030 : :
2031 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2)
2032 : : reg = flow_hw_get_reg_id
2033 : : (dev,
2034 : : RTE_FLOW_ITEM_TYPE_METER_COLOR, 0);
2035 : : else
2036 : 0 : reg = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR,
2037 : : 0, error);
2038 [ # # ]: 0 : if (reg < 0)
2039 : : return;
2040 : : MLX5_ASSERT(reg != REG_NON);
2041 : : MLX5_ASSERT((unsigned int)reg < RTE_DIM(reg_to_field));
2042 : 0 : info[idx] = (struct field_modify_info){4, 0,
2043 : 0 : reg_to_field[reg]};
2044 [ # # ]: 0 : if (mask)
2045 : 0 : mask[idx] = flow_modify_info_mask_32_masked
2046 [ # # ]: 0 : (width, data->offset, color_mask);
2047 : : else
2048 : 0 : info[idx].offset = data->offset;
2049 : : }
2050 : : break;
2051 : 0 : case RTE_FLOW_FIELD_IPV6_PROTO:
2052 : : MLX5_ASSERT(data->offset + width <= 8);
2053 : 0 : off_be = 8 - (data->offset + width);
2054 : 0 : info[idx] = (struct field_modify_info){1, 0, MLX5_MODI_OUT_IPV6_NEXT_HDR};
2055 [ # # ]: 0 : if (mask)
2056 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
2057 : : else
2058 : 0 : info[idx].offset = off_be;
2059 : : break;
2060 : 0 : case RTE_FLOW_FIELD_FLEX_ITEM:
2061 : : MLX5_ASSERT(data->flex_handle != NULL && !(data->offset & 0x7));
2062 : 0 : mlx5_modify_flex_item(dev, (const struct mlx5_flex_item *)data->flex_handle,
2063 : : data, info, mask, width);
2064 : 0 : break;
2065 : 0 : case RTE_FLOW_FIELD_HASH_RESULT:
2066 : : MLX5_ASSERT(data->offset + width <= 32);
2067 : 0 : off_be = 32 - (data->offset + width);
2068 : 0 : info[idx] = (struct field_modify_info){4, 0,
2069 : : MLX5_MODI_HASH_RESULT};
2070 [ # # ]: 0 : if (mask)
2071 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
2072 : : else
2073 : 0 : info[idx].offset = off_be;
2074 : : break;
2075 : : case RTE_FLOW_FIELD_POINTER:
2076 : : case RTE_FLOW_FIELD_VALUE:
2077 : : default:
2078 : : MLX5_ASSERT(false);
2079 : : break;
2080 : : }
2081 : : }
2082 : :
2083 : : /**
2084 : : * Convert modify_field action to DV specification.
2085 : : *
2086 : : * @param[in] dev
2087 : : * Pointer to the rte_eth_dev structure.
2088 : : * @param[in,out] resource
2089 : : * Pointer to the modify-header resource.
2090 : : * @param[in] action
2091 : : * Pointer to action specification.
2092 : : * @param[in] attr
2093 : : * Attributes of flow that includes this item.
2094 : : * @param[out] error
2095 : : * Pointer to the error structure.
2096 : : *
2097 : : * @return
2098 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2099 : : */
2100 : : static int
2101 : 0 : flow_dv_convert_action_modify_field
2102 : : (struct rte_eth_dev *dev,
2103 : : struct mlx5_flow_dv_modify_hdr_resource *resource,
2104 : : const struct rte_flow_action *action,
2105 : : const struct rte_flow_attr *attr,
2106 : : struct rte_flow_error *error)
2107 : : {
2108 : 0 : const struct rte_flow_action_modify_field *conf =
2109 : : (const struct rte_flow_action_modify_field *)(action->conf);
2110 : 0 : struct rte_flow_item item = {
2111 : : .spec = NULL,
2112 : : .mask = NULL
2113 : : };
2114 : 0 : struct field_modify_info field[MLX5_ACT_MAX_MOD_FIELDS] = {
2115 : : {0, 0, 0} };
2116 : 0 : struct field_modify_info dcopy[MLX5_ACT_MAX_MOD_FIELDS] = {
2117 : : {0, 0, 0} };
2118 : 0 : uint32_t mask[MLX5_ACT_MAX_MOD_FIELDS] = {0, 0, 0, 0, 0};
2119 : 0 : uint32_t type, meta = 0;
2120 : :
2121 [ # # ]: 0 : if (conf->src.field == RTE_FLOW_FIELD_POINTER ||
2122 : : conf->src.field == RTE_FLOW_FIELD_VALUE) {
2123 : 0 : type = conf->operation == RTE_FLOW_MODIFY_SET ?
2124 [ # # ]: 0 : MLX5_MODIFICATION_TYPE_SET : MLX5_MODIFICATION_TYPE_ADD;
2125 : : /** For SET fill the destination field (field) first. */
2126 : 0 : mlx5_flow_field_id_to_modify_info(&conf->dst, field, mask,
2127 : 0 : conf->width, dev,
2128 : : attr, error);
2129 : 0 : item.spec = conf->src.field == RTE_FLOW_FIELD_POINTER ?
2130 [ # # ]: 0 : (void *)(uintptr_t)conf->src.pvalue :
2131 : : (void *)(uintptr_t)&conf->src.value;
2132 [ # # ]: 0 : if (conf->dst.field == RTE_FLOW_FIELD_META ||
2133 [ # # ]: 0 : conf->dst.field == RTE_FLOW_FIELD_TAG ||
2134 : : conf->dst.field == RTE_FLOW_FIELD_METER_COLOR) {
2135 : 0 : meta = *(const unaligned_uint32_t *)item.spec;
2136 [ # # ]: 0 : meta = rte_cpu_to_be_32(meta);
2137 : 0 : item.spec = &meta;
2138 : : }
2139 : : } else {
2140 : : type = MLX5_MODIFICATION_TYPE_COPY;
2141 : : /** For COPY fill the destination field (dcopy) without mask. */
2142 : 0 : mlx5_flow_field_id_to_modify_info(&conf->dst, dcopy, NULL,
2143 : 0 : conf->width, dev,
2144 : : attr, error);
2145 : : /** Then construct the source field (field) with mask. */
2146 : 0 : mlx5_flow_field_id_to_modify_info(&conf->src, field, mask,
2147 : 0 : conf->width, dev,
2148 : : attr, error);
2149 : : }
2150 : 0 : item.mask = &mask;
2151 : 0 : return flow_dv_convert_modify_action(&item,
2152 : : field, dcopy, resource, type, error);
2153 : : }
2154 : :
2155 : : /**
2156 : : * Validate MARK item.
2157 : : *
2158 : : * @param[in] dev
2159 : : * Pointer to the rte_eth_dev structure.
2160 : : * @param[in] item
2161 : : * Item specification.
2162 : : * @param[in] attr
2163 : : * Attributes of flow that includes this item.
2164 : : * @param[out] error
2165 : : * Pointer to error structure.
2166 : : *
2167 : : * @return
2168 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2169 : : */
2170 : : static int
2171 : 0 : flow_dv_validate_item_mark(struct rte_eth_dev *dev,
2172 : : const struct rte_flow_item *item,
2173 : : const struct rte_flow_attr *attr __rte_unused,
2174 : : struct rte_flow_error *error)
2175 : : {
2176 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2177 : 0 : struct mlx5_sh_config *config = &priv->sh->config;
2178 : 0 : const struct rte_flow_item_mark *spec = item->spec;
2179 : 0 : const struct rte_flow_item_mark *mask = item->mask;
2180 : 0 : const struct rte_flow_item_mark nic_mask = {
2181 : 0 : .id = priv->sh->dv_mark_mask,
2182 : : };
2183 : : int ret;
2184 : :
2185 [ # # ]: 0 : if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY)
2186 : 0 : return rte_flow_error_set(error, ENOTSUP,
2187 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2188 : : "extended metadata feature"
2189 : : " isn't enabled");
2190 [ # # ]: 0 : if (!mlx5_flow_ext_mreg_supported(dev))
2191 : 0 : return rte_flow_error_set(error, ENOTSUP,
2192 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2193 : : "extended metadata register"
2194 : : " isn't supported");
2195 [ # # ]: 0 : if (!nic_mask.id)
2196 : 0 : return rte_flow_error_set(error, ENOTSUP,
2197 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2198 : : "extended metadata register"
2199 : : " isn't available");
2200 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
2201 [ # # ]: 0 : if (ret < 0)
2202 : : return ret;
2203 [ # # ]: 0 : if (!spec)
2204 : 0 : return rte_flow_error_set(error, EINVAL,
2205 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
2206 : 0 : item->spec,
2207 : : "data cannot be empty");
2208 [ # # ]: 0 : if (spec->id >= (MLX5_FLOW_MARK_MAX & nic_mask.id))
2209 : 0 : return rte_flow_error_set(error, EINVAL,
2210 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2211 : 0 : &spec->id,
2212 : : "mark id exceeds the limit");
2213 [ # # ]: 0 : if (!mask)
2214 : : mask = &nic_mask;
2215 [ # # ]: 0 : if (!mask->id)
2216 : 0 : return rte_flow_error_set(error, EINVAL,
2217 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
2218 : : "mask cannot be zero");
2219 : :
2220 : 0 : ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2221 : : (const uint8_t *)&nic_mask,
2222 : : sizeof(struct rte_flow_item_mark),
2223 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2224 : : if (ret < 0)
2225 : : return ret;
2226 : : return 0;
2227 : : }
2228 : :
2229 : : /**
2230 : : * Validate META item.
2231 : : *
2232 : : * @param[in] dev
2233 : : * Pointer to the rte_eth_dev structure.
2234 : : * @param[in] item
2235 : : * Item specification.
2236 : : * @param[in] attr
2237 : : * Attributes of flow that includes this item.
2238 : : * @param[out] error
2239 : : * Pointer to error structure.
2240 : : *
2241 : : * @return
2242 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2243 : : */
2244 : : static int
2245 : 0 : flow_dv_validate_item_meta(struct rte_eth_dev *dev __rte_unused,
2246 : : const struct rte_flow_item *item,
2247 : : const struct rte_flow_attr *attr,
2248 : : struct rte_flow_error *error)
2249 : : {
2250 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2251 : 0 : struct mlx5_sh_config *config = &priv->sh->config;
2252 : 0 : const struct rte_flow_item_meta *spec = item->spec;
2253 : 0 : const struct rte_flow_item_meta *mask = item->mask;
2254 : 0 : struct rte_flow_item_meta nic_mask = {
2255 : : .data = UINT32_MAX
2256 : : };
2257 : : int reg;
2258 : : int ret;
2259 : :
2260 [ # # ]: 0 : if (!spec)
2261 : 0 : return rte_flow_error_set(error, EINVAL,
2262 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
2263 : : item->spec,
2264 : : "data cannot be empty");
2265 [ # # ]: 0 : if (config->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
2266 [ # # ]: 0 : if (!mlx5_flow_ext_mreg_supported(dev))
2267 : 0 : return rte_flow_error_set(error, ENOTSUP,
2268 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2269 : : "extended metadata register"
2270 : : " isn't supported");
2271 : 0 : reg = flow_dv_get_metadata_reg(dev, attr, error);
2272 [ # # ]: 0 : if (reg < 0)
2273 : : return reg;
2274 [ # # ]: 0 : if (reg == REG_NON)
2275 : 0 : return rte_flow_error_set(error, ENOTSUP,
2276 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2277 : : "unavailable extended metadata register");
2278 [ # # ]: 0 : if (reg == REG_B)
2279 : 0 : return rte_flow_error_set(error, ENOTSUP,
2280 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2281 : : "match on reg_b "
2282 : : "isn't supported");
2283 [ # # ]: 0 : if (reg != REG_A)
2284 : 0 : nic_mask.data = priv->sh->dv_meta_mask;
2285 : : } else {
2286 [ # # ]: 0 : if (attr->transfer)
2287 : 0 : return rte_flow_error_set(error, ENOTSUP,
2288 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2289 : : "extended metadata feature "
2290 : : "should be enabled when "
2291 : : "meta item is requested "
2292 : : "with e-switch mode ");
2293 [ # # ]: 0 : if (attr->ingress)
2294 : 0 : return rte_flow_error_set(error, ENOTSUP,
2295 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2296 : : "match on metadata for ingress "
2297 : : "is not supported in legacy "
2298 : : "metadata mode");
2299 : : }
2300 [ # # ]: 0 : if (!mask)
2301 : : mask = &rte_flow_item_meta_mask;
2302 [ # # ]: 0 : if (!mask->data)
2303 : 0 : return rte_flow_error_set(error, EINVAL,
2304 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
2305 : : "mask cannot be zero");
2306 : :
2307 : 0 : ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2308 : : (const uint8_t *)&nic_mask,
2309 : : sizeof(struct rte_flow_item_meta),
2310 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2311 : 0 : return ret;
2312 : : }
2313 : :
2314 : : /**
2315 : : * Validate TAG item.
2316 : : *
2317 : : * @param[in] dev
2318 : : * Pointer to the rte_eth_dev structure.
2319 : : * @param[in] item
2320 : : * Item specification.
2321 : : * @param[in] tag_bitmap
2322 : : * Tag index bitmap.
2323 : : * @param[in] attr
2324 : : * Attributes of flow that includes this item.
2325 : : * @param[out] error
2326 : : * Pointer to error structure.
2327 : : *
2328 : : * @return
2329 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2330 : : */
2331 : : static int
2332 : 0 : flow_dv_validate_item_tag(struct rte_eth_dev *dev,
2333 : : const struct rte_flow_item *item,
2334 : : uint32_t *tag_bitmap,
2335 : : const struct rte_flow_attr *attr __rte_unused,
2336 : : struct rte_flow_error *error)
2337 : : {
2338 : 0 : const struct rte_flow_item_tag *spec = item->spec;
2339 : 0 : const struct rte_flow_item_tag *mask = item->mask;
2340 : 0 : const struct rte_flow_item_tag nic_mask = {
2341 : : .data = RTE_BE32(UINT32_MAX),
2342 : : .index = 0xff,
2343 : : };
2344 : : int ret;
2345 : :
2346 [ # # ]: 0 : if (!mlx5_flow_ext_mreg_supported(dev))
2347 : 0 : return rte_flow_error_set(error, ENOTSUP,
2348 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2349 : : "extensive metadata register"
2350 : : " isn't supported");
2351 [ # # ]: 0 : if (!spec)
2352 : 0 : return rte_flow_error_set(error, EINVAL,
2353 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
2354 : 0 : item->spec,
2355 : : "data cannot be empty");
2356 [ # # ]: 0 : if (!mask)
2357 : : mask = &rte_flow_item_tag_mask;
2358 [ # # ]: 0 : if (!mask->data)
2359 : 0 : return rte_flow_error_set(error, EINVAL,
2360 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
2361 : : "mask cannot be zero");
2362 : :
2363 : 0 : ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2364 : : (const uint8_t *)&nic_mask,
2365 : : sizeof(struct rte_flow_item_tag),
2366 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2367 [ # # ]: 0 : if (ret < 0)
2368 : : return ret;
2369 [ # # ]: 0 : if (mask->index != 0xff)
2370 : 0 : return rte_flow_error_set(error, EINVAL,
2371 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
2372 : : "partial mask for tag index"
2373 : : " is not supported");
2374 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, spec->index, error);
2375 [ # # ]: 0 : if (ret < 0)
2376 : : return ret;
2377 : : MLX5_ASSERT(ret != REG_NON);
2378 [ # # ]: 0 : if (*tag_bitmap & (1 << ret))
2379 : 0 : return rte_flow_error_set(error, EINVAL,
2380 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
2381 : 0 : item->spec,
2382 : : "Duplicated tag index");
2383 : 0 : *tag_bitmap |= 1 << ret;
2384 : 0 : return 0;
2385 : : }
2386 : :
2387 : : /**
2388 : : * Validate vport item.
2389 : : *
2390 : : * @param[in] dev
2391 : : * Pointer to the rte_eth_dev structure.
2392 : : * @param[in] item
2393 : : * Item specification.
2394 : : * @param[in] attr
2395 : : * Attributes of flow that includes this item.
2396 : : * @param[in] item_flags
2397 : : * Bit-fields that holds the items detected until now.
2398 : : * @param[out] error
2399 : : * Pointer to error structure.
2400 : : *
2401 : : * @return
2402 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2403 : : */
2404 : : static int
2405 : 0 : flow_dv_validate_item_port_id(struct rte_eth_dev *dev,
2406 : : const struct rte_flow_item *item,
2407 : : const struct rte_flow_attr *attr,
2408 : : uint64_t item_flags,
2409 : : struct mlx5_priv **act_priv,
2410 : : struct rte_flow_error *error)
2411 : : {
2412 : 0 : const struct rte_flow_item_port_id *spec = item->spec;
2413 : 0 : const struct rte_flow_item_port_id *mask = item->mask;
2414 : 0 : const struct rte_flow_item_port_id switch_mask = {
2415 : : .id = 0xffffffff,
2416 : : };
2417 : : struct mlx5_priv *esw_priv;
2418 : : struct mlx5_priv *dev_priv;
2419 : : int ret;
2420 : :
2421 [ # # ]: 0 : if (!attr->transfer)
2422 : 0 : return rte_flow_error_set(error, EINVAL,
2423 : : RTE_FLOW_ERROR_TYPE_ITEM,
2424 : : NULL,
2425 : : "match on port id is valid only"
2426 : : " when transfer flag is enabled");
2427 [ # # ]: 0 : if (item_flags & MLX5_FLOW_ITEM_PORT_ID)
2428 : 0 : return rte_flow_error_set(error, ENOTSUP,
2429 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2430 : : "multiple source ports are not"
2431 : : " supported");
2432 [ # # ]: 0 : if (!mask)
2433 : : mask = &switch_mask;
2434 [ # # ]: 0 : if (mask->id != 0xffffffff)
2435 : 0 : return rte_flow_error_set(error, ENOTSUP,
2436 : : RTE_FLOW_ERROR_TYPE_ITEM_MASK,
2437 : : mask,
2438 : : "no support for partial mask on"
2439 : : " \"id\" field");
2440 : 0 : ret = mlx5_flow_item_acceptable
2441 : : (item, (const uint8_t *)mask,
2442 : : (const uint8_t *)&rte_flow_item_port_id_mask,
2443 : : sizeof(struct rte_flow_item_port_id),
2444 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2445 [ # # ]: 0 : if (ret)
2446 : : return ret;
2447 [ # # ]: 0 : if (!spec)
2448 : : return 0;
2449 [ # # ]: 0 : if (spec->id == MLX5_PORT_ESW_MGR)
2450 : : return 0;
2451 : 0 : esw_priv = mlx5_port_to_eswitch_info(spec->id, false);
2452 [ # # ]: 0 : if (!esw_priv)
2453 : 0 : return rte_flow_error_set(error, rte_errno,
2454 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, spec,
2455 : : "failed to obtain E-Switch info for"
2456 : : " port");
2457 : 0 : dev_priv = mlx5_dev_to_eswitch_info(dev);
2458 [ # # ]: 0 : if (!dev_priv)
2459 : 0 : return rte_flow_error_set(error, rte_errno,
2460 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2461 : : NULL,
2462 : : "failed to obtain E-Switch info");
2463 [ # # ]: 0 : if (esw_priv->domain_id != dev_priv->domain_id)
2464 : 0 : return rte_flow_error_set(error, EINVAL,
2465 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, spec,
2466 : : "cannot match on a port from a"
2467 : : " different E-Switch");
2468 : 0 : *act_priv = esw_priv;
2469 : 0 : return 0;
2470 : : }
2471 : :
2472 : : /**
2473 : : * Validate represented port item.
2474 : : *
2475 : : * @param[in] dev
2476 : : * Pointer to the rte_eth_dev structure.
2477 : : * @param[in] item
2478 : : * Item specification.
2479 : : * @param[in] attr
2480 : : * Attributes of flow that includes this item.
2481 : : * @param[in] item_flags
2482 : : * Bit-fields that holds the items detected until now.
2483 : : * @param[out] error
2484 : : * Pointer to error structure.
2485 : : *
2486 : : * @return
2487 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2488 : : */
2489 : : static int
2490 : 0 : flow_dv_validate_item_represented_port(struct rte_eth_dev *dev,
2491 : : const struct rte_flow_item *item,
2492 : : const struct rte_flow_attr *attr,
2493 : : uint64_t item_flags,
2494 : : struct mlx5_priv **act_priv,
2495 : : struct rte_flow_error *error)
2496 : : {
2497 : 0 : const struct rte_flow_item_ethdev *spec = item->spec;
2498 : 0 : const struct rte_flow_item_ethdev *mask = item->mask;
2499 : 0 : const struct rte_flow_item_ethdev switch_mask = {
2500 : : .port_id = UINT16_MAX,
2501 : : };
2502 : : struct mlx5_priv *esw_priv;
2503 : : struct mlx5_priv *dev_priv;
2504 : : int ret;
2505 : :
2506 [ # # ]: 0 : if (!attr->transfer)
2507 : 0 : return rte_flow_error_set(error, EINVAL,
2508 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
2509 : : "match on port id is valid only when transfer flag is enabled");
2510 [ # # ]: 0 : if (item_flags & MLX5_FLOW_ITEM_REPRESENTED_PORT)
2511 : 0 : return rte_flow_error_set(error, ENOTSUP,
2512 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2513 : : "multiple source ports are not supported");
2514 [ # # ]: 0 : if (!mask)
2515 : : mask = &switch_mask;
2516 [ # # ]: 0 : if (mask->port_id != UINT16_MAX)
2517 : 0 : return rte_flow_error_set(error, ENOTSUP,
2518 : : RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
2519 : : "no support for partial mask on \"id\" field");
2520 : 0 : ret = mlx5_flow_item_acceptable
2521 : : (item, (const uint8_t *)mask,
2522 : : (const uint8_t *)&rte_flow_item_ethdev_mask,
2523 : : sizeof(struct rte_flow_item_ethdev),
2524 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2525 [ # # ]: 0 : if (ret)
2526 : : return ret;
2527 [ # # # # ]: 0 : if (!spec || spec->port_id == UINT16_MAX)
2528 : : return 0;
2529 : 0 : esw_priv = mlx5_port_to_eswitch_info(spec->port_id, false);
2530 [ # # ]: 0 : if (!esw_priv)
2531 : 0 : return rte_flow_error_set(error, rte_errno,
2532 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, spec,
2533 : : "failed to obtain E-Switch info for port");
2534 : 0 : dev_priv = mlx5_dev_to_eswitch_info(dev);
2535 [ # # ]: 0 : if (!dev_priv)
2536 : 0 : return rte_flow_error_set(error, rte_errno,
2537 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2538 : : NULL,
2539 : : "failed to obtain E-Switch info");
2540 [ # # ]: 0 : if (esw_priv->domain_id != dev_priv->domain_id)
2541 : 0 : return rte_flow_error_set(error, EINVAL,
2542 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, spec,
2543 : : "cannot match on a port from a different E-Switch");
2544 : 0 : *act_priv = esw_priv;
2545 : 0 : return 0;
2546 : : }
2547 : :
2548 : : /**
2549 : : * Validate VLAN item.
2550 : : *
2551 : : * @param[in] item
2552 : : * Item specification.
2553 : : * @param[in] item_flags
2554 : : * Bit-fields that holds the items detected until now.
2555 : : * @param[in] dev
2556 : : * Ethernet device flow is being created on.
2557 : : * @param[out] error
2558 : : * Pointer to error structure.
2559 : : *
2560 : : * @return
2561 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2562 : : */
2563 : : static int
2564 : 0 : flow_dv_validate_item_vlan(const struct rte_flow_item *item,
2565 : : uint64_t item_flags,
2566 : : struct rte_eth_dev *dev,
2567 : : struct rte_flow_error *error)
2568 : : {
2569 : 0 : const struct rte_flow_item_vlan *mask = item->mask;
2570 : 0 : const struct rte_flow_item_vlan nic_mask = {
2571 : : .hdr.vlan_tci = RTE_BE16(UINT16_MAX),
2572 : : .hdr.eth_proto = RTE_BE16(UINT16_MAX),
2573 : : .has_more_vlan = 1,
2574 : : };
2575 : 0 : const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2576 : : int ret;
2577 : : const uint64_t l34m = tunnel ? (MLX5_FLOW_LAYER_INNER_L3 |
2578 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_L4) :
2579 : : (MLX5_FLOW_LAYER_OUTER_L3 |
2580 : : MLX5_FLOW_LAYER_OUTER_L4);
2581 [ # # ]: 0 : const uint64_t vlanm = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
2582 : : MLX5_FLOW_LAYER_OUTER_VLAN;
2583 : :
2584 [ # # ]: 0 : if (item_flags & vlanm)
2585 : 0 : return rte_flow_error_set(error, EINVAL,
2586 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2587 : : "multiple VLAN layers not supported");
2588 [ # # ]: 0 : else if ((item_flags & l34m) != 0)
2589 : 0 : return rte_flow_error_set(error, EINVAL,
2590 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2591 : : "VLAN cannot follow L3/L4 layer");
2592 [ # # ]: 0 : if (!mask)
2593 : : mask = &rte_flow_item_vlan_mask;
2594 : 0 : ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2595 : : (const uint8_t *)&nic_mask,
2596 : : sizeof(struct rte_flow_item_vlan),
2597 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2598 [ # # ]: 0 : if (ret)
2599 : : return ret;
2600 [ # # # # ]: 0 : if (!tunnel && mask->hdr.vlan_tci != RTE_BE16(0x0fff)) {
2601 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2602 : :
2603 [ # # ]: 0 : if (priv->vmwa_context) {
2604 : : /*
2605 : : * Non-NULL context means we have a virtual machine
2606 : : * and SR-IOV enabled, we have to create VLAN interface
2607 : : * to make hypervisor to setup E-Switch vport
2608 : : * context correctly. We avoid creating the multiple
2609 : : * VLAN interfaces, so we cannot support VLAN tag mask.
2610 : : */
2611 : 0 : return rte_flow_error_set(error, EINVAL,
2612 : : RTE_FLOW_ERROR_TYPE_ITEM,
2613 : : item,
2614 : : "VLAN tag mask is not"
2615 : : " supported in virtual"
2616 : : " environment");
2617 : : }
2618 : : }
2619 : : return 0;
2620 : : }
2621 : :
2622 : : /*
2623 : : * GTP flags are contained in 1 byte of the format:
2624 : : * -------------------------------------------
2625 : : * | bit | 0 - 2 | 3 | 4 | 5 | 6 | 7 |
2626 : : * |-----------------------------------------|
2627 : : * | value | Version | PT | Res | E | S | PN |
2628 : : * -------------------------------------------
2629 : : *
2630 : : * Matching is supported only for GTP flags E, S, PN.
2631 : : */
2632 : : #define MLX5_GTP_FLAGS_MASK 0x07
2633 : :
2634 : : /**
2635 : : * Validate GTP item.
2636 : : *
2637 : : * @param[in] dev
2638 : : * Pointer to the rte_eth_dev structure.
2639 : : * @param[in] item
2640 : : * Item specification.
2641 : : * @param[in] item_flags
2642 : : * Bit-fields that holds the items detected until now.
2643 : : * @param[out] error
2644 : : * Pointer to error structure.
2645 : : *
2646 : : * @return
2647 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2648 : : */
2649 : : static int
2650 : 0 : flow_dv_validate_item_gtp(struct rte_eth_dev *dev,
2651 : : const struct rte_flow_item *item,
2652 : : uint64_t item_flags,
2653 : : struct rte_flow_error *error)
2654 : : {
2655 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2656 : 0 : const struct rte_flow_item_gtp *spec = item->spec;
2657 : 0 : const struct rte_flow_item_gtp *mask = item->mask;
2658 : 0 : const struct rte_flow_item_gtp nic_mask = {
2659 : : .hdr.gtp_hdr_info = MLX5_GTP_FLAGS_MASK,
2660 : : .hdr.msg_type = 0xff,
2661 : : .hdr.teid = RTE_BE32(0xffffffff),
2662 : : };
2663 : :
2664 [ # # ]: 0 : if (!priv->sh->cdev->config.hca_attr.tunnel_stateless_gtp)
2665 : 0 : return rte_flow_error_set(error, ENOTSUP,
2666 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2667 : : "GTP support is not enabled");
2668 [ # # ]: 0 : if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2669 : 0 : return rte_flow_error_set(error, ENOTSUP,
2670 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2671 : : "multiple tunnel layers not"
2672 : : " supported");
2673 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2674 : 0 : return rte_flow_error_set(error, EINVAL,
2675 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2676 : : "no outer UDP layer found");
2677 [ # # ]: 0 : if (!mask)
2678 : : mask = &rte_flow_item_gtp_mask;
2679 [ # # # # ]: 0 : if (spec && spec->hdr.gtp_hdr_info & ~MLX5_GTP_FLAGS_MASK)
2680 : 0 : return rte_flow_error_set(error, ENOTSUP,
2681 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2682 : : "Match is supported for GTP"
2683 : : " flags only");
2684 : 0 : return mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2685 : : (const uint8_t *)&nic_mask,
2686 : : sizeof(struct rte_flow_item_gtp),
2687 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2688 : : }
2689 : :
2690 : : /**
2691 : : * Validate GTP PSC item.
2692 : : *
2693 : : * @param[in] item
2694 : : * Item specification.
2695 : : * @param[in] last_item
2696 : : * Previous validated item in the pattern items.
2697 : : * @param[in] gtp_item
2698 : : * Previous GTP item specification.
2699 : : * @param root
2700 : : * Whether action is on root table.
2701 : : * @param[out] error
2702 : : * Pointer to error structure.
2703 : : *
2704 : : * @return
2705 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2706 : : */
2707 : : static int
2708 : 0 : flow_dv_validate_item_gtp_psc(const struct rte_flow_item *item,
2709 : : uint64_t last_item,
2710 : : const struct rte_flow_item *gtp_item,
2711 : : bool root,
2712 : : struct rte_flow_error *error)
2713 : : {
2714 : : const struct rte_flow_item_gtp *gtp_spec;
2715 : : const struct rte_flow_item_gtp *gtp_mask;
2716 : : const struct rte_flow_item_gtp_psc *mask;
2717 : 0 : const struct rte_flow_item_gtp_psc nic_mask = {
2718 : : .hdr.type = 0xF,
2719 : : .hdr.qfi = 0x3F,
2720 : : };
2721 : :
2722 [ # # # # ]: 0 : if (!gtp_item || !(last_item & MLX5_FLOW_LAYER_GTP))
2723 : 0 : return rte_flow_error_set
2724 : : (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2725 : : "GTP PSC item must be preceded with GTP item");
2726 : 0 : gtp_spec = gtp_item->spec;
2727 [ # # ]: 0 : gtp_mask = gtp_item->mask ? gtp_item->mask : &rte_flow_item_gtp_mask;
2728 : : /* GTP spec and E flag is requested to match zero. */
2729 [ # # ]: 0 : if (gtp_spec &&
2730 : 0 : (gtp_mask->hdr.gtp_hdr_info &
2731 [ # # ]: 0 : ~gtp_spec->hdr.gtp_hdr_info & MLX5_GTP_EXT_HEADER_FLAG))
2732 : 0 : return rte_flow_error_set
2733 : : (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2734 : : "GTP E flag must be 1 to match GTP PSC");
2735 : : /* Check the flow is not created in group zero. */
2736 [ # # ]: 0 : if (root)
2737 : 0 : return rte_flow_error_set
2738 : : (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2739 : : "GTP PSC is not supported for group 0");
2740 : : /* GTP spec is here and E flag is requested to match zero. */
2741 [ # # ]: 0 : if (!item->spec)
2742 : : return 0;
2743 [ # # ]: 0 : mask = item->mask ? item->mask : &rte_flow_item_gtp_psc_mask;
2744 : 0 : return mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2745 : : (const uint8_t *)&nic_mask,
2746 : : sizeof(struct rte_flow_item_gtp_psc),
2747 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2748 : : }
2749 : :
2750 : : /**
2751 : : * Validate IPV4 item.
2752 : : * Use existing validation function mlx5_flow_validate_item_ipv4(), and
2753 : : * add specific validation of fragment_offset field,
2754 : : *
2755 : : * @param[in] item
2756 : : * Item specification.
2757 : : * @param[in] item_flags
2758 : : * Bit-fields that holds the items detected until now.
2759 : : * @param[out] error
2760 : : * Pointer to error structure.
2761 : : *
2762 : : * @return
2763 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2764 : : */
2765 : : static int
2766 : 0 : flow_dv_validate_item_ipv4(struct rte_eth_dev *dev,
2767 : : const struct rte_flow_item *item,
2768 : : uint64_t item_flags, uint64_t last_item,
2769 : : uint16_t ether_type, struct rte_flow_error *error)
2770 : : {
2771 : : int ret;
2772 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2773 : 0 : struct mlx5_hca_attr *attr = &priv->sh->cdev->config.hca_attr;
2774 : 0 : const struct rte_flow_item_ipv4 *spec = item->spec;
2775 : 0 : const struct rte_flow_item_ipv4 *last = item->last;
2776 : 0 : const struct rte_flow_item_ipv4 *mask = item->mask;
2777 : : rte_be16_t fragment_offset_spec = 0;
2778 : : rte_be16_t fragment_offset_last = 0;
2779 : 0 : struct rte_flow_item_ipv4 nic_ipv4_mask = {
2780 : : .hdr = {
2781 : : .src_addr = RTE_BE32(0xffffffff),
2782 : : .dst_addr = RTE_BE32(0xffffffff),
2783 : : .type_of_service = 0xff,
2784 : : .fragment_offset = RTE_BE16(0xffff),
2785 : : .next_proto_id = 0xff,
2786 : : .time_to_live = 0xff,
2787 : : },
2788 : : };
2789 : :
2790 [ # # # # ]: 0 : if (mask && (mask->hdr.version_ihl & RTE_IPV4_HDR_IHL_MASK)) {
2791 : 0 : int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2792 : : bool ihl_cap = !tunnel ?
2793 [ # # ]: 0 : attr->outer_ipv4_ihl : attr->inner_ipv4_ihl;
2794 [ # # ]: 0 : if (!ihl_cap)
2795 : 0 : return rte_flow_error_set(error, ENOTSUP,
2796 : : RTE_FLOW_ERROR_TYPE_ITEM,
2797 : : item,
2798 : : "IPV4 ihl offload not supported");
2799 : 0 : nic_ipv4_mask.hdr.version_ihl = mask->hdr.version_ihl;
2800 : : }
2801 : 0 : ret = mlx5_flow_validate_item_ipv4(item, item_flags, last_item,
2802 : : ether_type, &nic_ipv4_mask,
2803 : : MLX5_ITEM_RANGE_ACCEPTED, error);
2804 [ # # ]: 0 : if (ret < 0)
2805 : : return ret;
2806 [ # # ]: 0 : if (spec && mask)
2807 : 0 : fragment_offset_spec = spec->hdr.fragment_offset &
2808 : 0 : mask->hdr.fragment_offset;
2809 [ # # ]: 0 : if (!fragment_offset_spec)
2810 : : return 0;
2811 : : /*
2812 : : * spec and mask are valid, enforce using full mask to make sure the
2813 : : * complete value is used correctly.
2814 : : */
2815 [ # # ]: 0 : if ((mask->hdr.fragment_offset & RTE_BE16(MLX5_IPV4_FRAG_OFFSET_MASK))
2816 : : != RTE_BE16(MLX5_IPV4_FRAG_OFFSET_MASK))
2817 : 0 : return rte_flow_error_set(error, EINVAL,
2818 : : RTE_FLOW_ERROR_TYPE_ITEM_MASK,
2819 : : item, "must use full mask for"
2820 : : " fragment_offset");
2821 : : /*
2822 : : * Match on fragment_offset 0x2000 means MF is 1 and frag-offset is 0,
2823 : : * indicating this is 1st fragment of fragmented packet.
2824 : : * This is not yet supported in MLX5, return appropriate error message.
2825 : : */
2826 [ # # ]: 0 : if (fragment_offset_spec == RTE_BE16(RTE_IPV4_HDR_MF_FLAG))
2827 : 0 : return rte_flow_error_set(error, ENOTSUP,
2828 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2829 : : "match on first fragment not "
2830 : : "supported");
2831 [ # # ]: 0 : if (fragment_offset_spec && !last)
2832 : 0 : return rte_flow_error_set(error, ENOTSUP,
2833 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2834 : : "specified value not supported");
2835 : : /* spec and last are valid, validate the specified range. */
2836 : 0 : fragment_offset_last = last->hdr.fragment_offset &
2837 : : mask->hdr.fragment_offset;
2838 : : /*
2839 : : * Match on fragment_offset spec 0x2001 and last 0x3fff
2840 : : * means MF is 1 and frag-offset is > 0.
2841 : : * This packet is fragment 2nd and onward, excluding last.
2842 : : * This is not yet supported in MLX5, return appropriate
2843 : : * error message.
2844 : : */
2845 : 0 : if (fragment_offset_spec == RTE_BE16(RTE_IPV4_HDR_MF_FLAG + 1) &&
2846 [ # # ]: 0 : fragment_offset_last == RTE_BE16(MLX5_IPV4_FRAG_OFFSET_MASK))
2847 : 0 : return rte_flow_error_set(error, ENOTSUP,
2848 : : RTE_FLOW_ERROR_TYPE_ITEM_LAST,
2849 : : last, "match on following "
2850 : : "fragments not supported");
2851 : : /*
2852 : : * Match on fragment_offset spec 0x0001 and last 0x1fff
2853 : : * means MF is 0 and frag-offset is > 0.
2854 : : * This packet is last fragment of fragmented packet.
2855 : : * This is not yet supported in MLX5, return appropriate
2856 : : * error message.
2857 : : */
2858 : 0 : if (fragment_offset_spec == RTE_BE16(1) &&
2859 [ # # ]: 0 : fragment_offset_last == RTE_BE16(RTE_IPV4_HDR_OFFSET_MASK))
2860 : 0 : return rte_flow_error_set(error, ENOTSUP,
2861 : : RTE_FLOW_ERROR_TYPE_ITEM_LAST,
2862 : : last, "match on last "
2863 : : "fragment not supported");
2864 : : /*
2865 : : * Match on fragment_offset spec 0x0001 and last 0x3fff
2866 : : * means MF and/or frag-offset is not 0.
2867 : : * This is a fragmented packet.
2868 : : * Other range values are invalid and rejected.
2869 : : */
2870 : 0 : if (!(fragment_offset_spec == RTE_BE16(1) &&
2871 [ # # ]: 0 : fragment_offset_last == RTE_BE16(MLX5_IPV4_FRAG_OFFSET_MASK)))
2872 : 0 : return rte_flow_error_set(error, ENOTSUP,
2873 : : RTE_FLOW_ERROR_TYPE_ITEM_LAST, last,
2874 : : "specified range not supported");
2875 : : return 0;
2876 : : }
2877 : :
2878 : : /**
2879 : : * Validate IPV6 fragment extension item.
2880 : : *
2881 : : * @param[in] item
2882 : : * Item specification.
2883 : : * @param[in] item_flags
2884 : : * Bit-fields that holds the items detected until now.
2885 : : * @param[out] error
2886 : : * Pointer to error structure.
2887 : : *
2888 : : * @return
2889 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2890 : : */
2891 : : static int
2892 : 0 : flow_dv_validate_item_ipv6_frag_ext(const struct rte_flow_item *item,
2893 : : uint64_t item_flags,
2894 : : struct rte_flow_error *error)
2895 : : {
2896 : 0 : const struct rte_flow_item_ipv6_frag_ext *spec = item->spec;
2897 : 0 : const struct rte_flow_item_ipv6_frag_ext *last = item->last;
2898 : 0 : const struct rte_flow_item_ipv6_frag_ext *mask = item->mask;
2899 : : rte_be16_t frag_data_spec = 0;
2900 : : rte_be16_t frag_data_last = 0;
2901 : 0 : const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2902 [ # # ]: 0 : const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2903 : : MLX5_FLOW_LAYER_OUTER_L4;
2904 : : int ret = 0;
2905 : 0 : struct rte_flow_item_ipv6_frag_ext nic_mask = {
2906 : : .hdr = {
2907 : : .next_header = 0xff,
2908 : : .frag_data = RTE_BE16(0xffff),
2909 : : },
2910 : : };
2911 : :
2912 [ # # ]: 0 : if (item_flags & l4m)
2913 : 0 : return rte_flow_error_set(error, EINVAL,
2914 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2915 : : "ipv6 fragment extension item cannot "
2916 : : "follow L4 item.");
2917 [ # # # # : 0 : if ((tunnel && !(item_flags & MLX5_FLOW_LAYER_INNER_L3_IPV6)) ||
# # ]
2918 [ # # ]: 0 : (!tunnel && !(item_flags & MLX5_FLOW_LAYER_OUTER_L3_IPV6)))
2919 : 0 : return rte_flow_error_set(error, EINVAL,
2920 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2921 : : "ipv6 fragment extension item must "
2922 : : "follow ipv6 item");
2923 [ # # ]: 0 : if (spec && mask)
2924 : 0 : frag_data_spec = spec->hdr.frag_data & mask->hdr.frag_data;
2925 [ # # ]: 0 : if (!frag_data_spec)
2926 : : return 0;
2927 : : /*
2928 : : * spec and mask are valid, enforce using full mask to make sure the
2929 : : * complete value is used correctly.
2930 : : */
2931 [ # # ]: 0 : if ((mask->hdr.frag_data & RTE_BE16(RTE_IPV6_FRAG_USED_MASK)) !=
2932 : : RTE_BE16(RTE_IPV6_FRAG_USED_MASK))
2933 : 0 : return rte_flow_error_set(error, EINVAL,
2934 : : RTE_FLOW_ERROR_TYPE_ITEM_MASK,
2935 : : item, "must use full mask for"
2936 : : " frag_data");
2937 : : /*
2938 : : * Match on frag_data 0x00001 means M is 1 and frag-offset is 0.
2939 : : * This is 1st fragment of fragmented packet.
2940 : : */
2941 [ # # ]: 0 : if (frag_data_spec == RTE_BE16(RTE_IPV6_EHDR_MF_MASK))
2942 : 0 : return rte_flow_error_set(error, ENOTSUP,
2943 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2944 : : "match on first fragment not "
2945 : : "supported");
2946 [ # # ]: 0 : if (frag_data_spec && !last)
2947 : 0 : return rte_flow_error_set(error, EINVAL,
2948 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2949 : : "specified value not supported");
2950 : 0 : ret = mlx5_flow_item_acceptable
2951 : : (item, (const uint8_t *)mask,
2952 : : (const uint8_t *)&nic_mask,
2953 : : sizeof(struct rte_flow_item_ipv6_frag_ext),
2954 : : MLX5_ITEM_RANGE_ACCEPTED, error);
2955 [ # # ]: 0 : if (ret)
2956 : : return ret;
2957 : : /* spec and last are valid, validate the specified range. */
2958 : 0 : frag_data_last = last->hdr.frag_data & mask->hdr.frag_data;
2959 : : /*
2960 : : * Match on frag_data spec 0x0009 and last 0xfff9
2961 : : * means M is 1 and frag-offset is > 0.
2962 : : * This packet is fragment 2nd and onward, excluding last.
2963 : : * This is not yet supported in MLX5, return appropriate
2964 : : * error message.
2965 : : */
2966 : 0 : if (frag_data_spec == RTE_BE16(RTE_IPV6_EHDR_FO_ALIGN |
2967 : 0 : RTE_IPV6_EHDR_MF_MASK) &&
2968 [ # # ]: 0 : frag_data_last == RTE_BE16(RTE_IPV6_FRAG_USED_MASK))
2969 : 0 : return rte_flow_error_set(error, ENOTSUP,
2970 : : RTE_FLOW_ERROR_TYPE_ITEM_LAST,
2971 : : last, "match on following "
2972 : : "fragments not supported");
2973 : : /*
2974 : : * Match on frag_data spec 0x0008 and last 0xfff8
2975 : : * means M is 0 and frag-offset is > 0.
2976 : : * This packet is last fragment of fragmented packet.
2977 : : * This is not yet supported in MLX5, return appropriate
2978 : : * error message.
2979 : : */
2980 : 0 : if (frag_data_spec == RTE_BE16(RTE_IPV6_EHDR_FO_ALIGN) &&
2981 [ # # ]: 0 : frag_data_last == RTE_BE16(RTE_IPV6_EHDR_FO_MASK))
2982 : 0 : return rte_flow_error_set(error, ENOTSUP,
2983 : : RTE_FLOW_ERROR_TYPE_ITEM_LAST,
2984 : : last, "match on last "
2985 : : "fragment not supported");
2986 : : /* Other range values are invalid and rejected. */
2987 : 0 : return rte_flow_error_set(error, EINVAL,
2988 : : RTE_FLOW_ERROR_TYPE_ITEM_LAST, last,
2989 : : "specified range not supported");
2990 : : }
2991 : :
2992 : : /*
2993 : : * Validate ASO CT item.
2994 : : *
2995 : : * @param[in] dev
2996 : : * Pointer to the rte_eth_dev structure.
2997 : : * @param[in] item
2998 : : * Item specification.
2999 : : * @param[in] item_flags
3000 : : * Pointer to bit-fields that holds the items detected until now.
3001 : : * @param[out] error
3002 : : * Pointer to error structure.
3003 : : *
3004 : : * @return
3005 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3006 : : */
3007 : : static int
3008 : 0 : flow_dv_validate_item_aso_ct(struct rte_eth_dev *dev,
3009 : : const struct rte_flow_item *item,
3010 : : uint64_t *item_flags,
3011 : : struct rte_flow_error *error)
3012 : : {
3013 : 0 : const struct rte_flow_item_conntrack *spec = item->spec;
3014 : 0 : const struct rte_flow_item_conntrack *mask = item->mask;
3015 : : RTE_SET_USED(dev);
3016 : : uint32_t flags;
3017 : :
3018 [ # # ]: 0 : if (*item_flags & MLX5_FLOW_LAYER_ASO_CT)
3019 : 0 : return rte_flow_error_set(error, EINVAL,
3020 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
3021 : : "Only one CT is supported");
3022 [ # # ]: 0 : if (!mask)
3023 : : mask = &rte_flow_item_conntrack_mask;
3024 : 0 : flags = spec->flags & mask->flags;
3025 [ # # ]: 0 : if ((flags & RTE_FLOW_CONNTRACK_PKT_STATE_VALID) &&
3026 : : ((flags & RTE_FLOW_CONNTRACK_PKT_STATE_INVALID) ||
3027 [ # # ]: 0 : (flags & RTE_FLOW_CONNTRACK_PKT_STATE_BAD) ||
3028 : : (flags & RTE_FLOW_CONNTRACK_PKT_STATE_DISABLED)))
3029 : 0 : return rte_flow_error_set(error, EINVAL,
3030 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
3031 : : "Conflict status bits");
3032 : : /* State change also needs to be considered. */
3033 : 0 : *item_flags |= MLX5_FLOW_LAYER_ASO_CT;
3034 : 0 : return 0;
3035 : : }
3036 : :
3037 : : /**
3038 : : * Validate the pop VLAN action.
3039 : : *
3040 : : * @param[in] dev
3041 : : * Pointer to the rte_eth_dev structure.
3042 : : * @param[in] action_flags
3043 : : * Holds the actions detected until now.
3044 : : * @param[in] action
3045 : : * Pointer to the pop vlan action.
3046 : : * @param[in] item_flags
3047 : : * The items found in this flow rule.
3048 : : * @param[in] attr
3049 : : * Pointer to flow attributes.
3050 : : * @param[out] error
3051 : : * Pointer to error structure.
3052 : : *
3053 : : * @return
3054 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3055 : : */
3056 : : static int
3057 : 0 : flow_dv_validate_action_pop_vlan(struct rte_eth_dev *dev,
3058 : : uint64_t action_flags,
3059 : : const struct rte_flow_action *action,
3060 : : uint64_t item_flags,
3061 : : const struct rte_flow_attr *attr,
3062 : : struct rte_flow_error *error)
3063 : : {
3064 : 0 : const struct mlx5_priv *priv = dev->data->dev_private;
3065 : :
3066 [ # # ]: 0 : if (!priv->sh->pop_vlan_action)
3067 : 0 : return rte_flow_error_set(error, ENOTSUP,
3068 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3069 : : NULL,
3070 : : "pop vlan action is not supported");
3071 [ # # ]: 0 : if (action_flags & MLX5_FLOW_VLAN_ACTIONS)
3072 : 0 : return rte_flow_error_set(error, ENOTSUP,
3073 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3074 : : "no support for multiple VLAN "
3075 : : "actions");
3076 : : /* Pop VLAN with preceding Decap requires inner header with VLAN. */
3077 [ # # ]: 0 : if ((action_flags & MLX5_FLOW_ACTION_DECAP) &&
3078 [ # # ]: 0 : !(item_flags & MLX5_FLOW_LAYER_INNER_VLAN))
3079 : 0 : return rte_flow_error_set(error, ENOTSUP,
3080 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3081 : : NULL,
3082 : : "cannot pop vlan after decap without "
3083 : : "match on inner vlan in the flow");
3084 : : /* Pop VLAN without preceding Decap requires outer header with VLAN. */
3085 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_ACTION_DECAP) &&
3086 [ # # ]: 0 : !(item_flags & MLX5_FLOW_LAYER_OUTER_VLAN))
3087 : 0 : return rte_flow_error_set(error, ENOTSUP,
3088 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3089 : : NULL,
3090 : : "cannot pop vlan without a "
3091 : : "match on (outer) vlan in the flow");
3092 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
3093 : 0 : return rte_flow_error_set(error, EINVAL,
3094 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3095 : : "wrong action order, port_id should "
3096 : : "be after pop VLAN action");
3097 [ # # # # ]: 0 : if (!attr->transfer && priv->representor)
3098 : 0 : return rte_flow_error_set(error, ENOTSUP,
3099 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3100 : : "pop vlan action for VF representor "
3101 : : "not supported on NIC table");
3102 : : return 0;
3103 : : }
3104 : :
3105 : : /**
3106 : : * Get VLAN default info from vlan match info.
3107 : : *
3108 : : * @param[in] items
3109 : : * the list of item specifications.
3110 : : * @param[out] vlan
3111 : : * pointer VLAN info to fill to.
3112 : : *
3113 : : * @return
3114 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3115 : : */
3116 : : static void
3117 : 0 : flow_dev_get_vlan_info_from_items(const struct rte_flow_item *items,
3118 : : struct rte_vlan_hdr *vlan)
3119 : : {
3120 : 0 : const struct rte_flow_item_vlan nic_mask = {
3121 : : .hdr.vlan_tci = RTE_BE16(MLX5DV_FLOW_VLAN_PCP_MASK |
3122 : : MLX5DV_FLOW_VLAN_VID_MASK),
3123 : : .hdr.eth_proto = RTE_BE16(0xffff),
3124 : : };
3125 : :
3126 [ # # ]: 0 : if (items == NULL)
3127 : 0 : return;
3128 [ # # ]: 0 : for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
3129 : 0 : int type = items->type;
3130 : :
3131 : 0 : if (type == RTE_FLOW_ITEM_TYPE_VLAN ||
3132 [ # # ]: 0 : type == MLX5_RTE_FLOW_ITEM_TYPE_VLAN)
3133 : : break;
3134 : : }
3135 [ # # ]: 0 : if (items->type != RTE_FLOW_ITEM_TYPE_END) {
3136 : 0 : const struct rte_flow_item_vlan *vlan_m = items->mask;
3137 : 0 : const struct rte_flow_item_vlan *vlan_v = items->spec;
3138 : :
3139 : : /* If VLAN item in pattern doesn't contain data, return here. */
3140 [ # # ]: 0 : if (!vlan_v)
3141 : : return;
3142 [ # # ]: 0 : if (!vlan_m)
3143 : : vlan_m = &nic_mask;
3144 : : /* Only full match values are accepted */
3145 [ # # ]: 0 : if ((vlan_m->hdr.vlan_tci & MLX5DV_FLOW_VLAN_PCP_MASK_BE) ==
3146 : : MLX5DV_FLOW_VLAN_PCP_MASK_BE) {
3147 : 0 : vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_PCP_MASK;
3148 : 0 : vlan->vlan_tci |=
3149 [ # # ]: 0 : rte_be_to_cpu_16(vlan_v->hdr.vlan_tci &
3150 : : MLX5DV_FLOW_VLAN_PCP_MASK_BE);
3151 : : }
3152 [ # # ]: 0 : if ((vlan_m->hdr.vlan_tci & MLX5DV_FLOW_VLAN_VID_MASK_BE) ==
3153 : : MLX5DV_FLOW_VLAN_VID_MASK_BE) {
3154 : 0 : vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_VID_MASK;
3155 : 0 : vlan->vlan_tci |=
3156 [ # # ]: 0 : rte_be_to_cpu_16(vlan_v->hdr.vlan_tci &
3157 : : MLX5DV_FLOW_VLAN_VID_MASK_BE);
3158 : : }
3159 [ # # ]: 0 : if (vlan_m->hdr.eth_proto == nic_mask.hdr.eth_proto)
3160 [ # # ]: 0 : vlan->eth_proto = rte_be_to_cpu_16(vlan_v->hdr.eth_proto &
3161 : : vlan_m->hdr.eth_proto);
3162 : : }
3163 : : }
3164 : :
3165 : : /**
3166 : : * Validate the push VLAN action.
3167 : : *
3168 : : * @param[in] dev
3169 : : * Pointer to the rte_eth_dev structure.
3170 : : * @param[in] action_flags
3171 : : * Holds the actions detected until now.
3172 : : * @param[in] item_flags
3173 : : * The items found in this flow rule.
3174 : : * @param[in] action
3175 : : * Pointer to the action structure.
3176 : : * @param[in] attr
3177 : : * Pointer to flow attributes
3178 : : * @param[out] error
3179 : : * Pointer to error structure.
3180 : : *
3181 : : * @return
3182 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3183 : : */
3184 : : static int
3185 : 0 : flow_dv_validate_action_push_vlan(struct rte_eth_dev *dev,
3186 : : uint64_t action_flags,
3187 : : const struct rte_flow_item_vlan *vlan_m,
3188 : : const struct rte_flow_action *action,
3189 : : const struct rte_flow_attr *attr,
3190 : : struct rte_flow_error *error)
3191 : : {
3192 : 0 : const struct rte_flow_action_of_push_vlan *push_vlan = action->conf;
3193 : 0 : const struct mlx5_priv *priv = dev->data->dev_private;
3194 : :
3195 [ # # ]: 0 : if (push_vlan->ethertype != RTE_BE16(RTE_ETHER_TYPE_VLAN) &&
3196 : : push_vlan->ethertype != RTE_BE16(RTE_ETHER_TYPE_QINQ))
3197 : 0 : return rte_flow_error_set(error, EINVAL,
3198 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3199 : : "invalid vlan ethertype");
3200 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
3201 : 0 : return rte_flow_error_set(error, EINVAL,
3202 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3203 : : "wrong action order, port_id should "
3204 : : "be after push VLAN");
3205 [ # # # # ]: 0 : if (!attr->transfer && priv->representor)
3206 : 0 : return rte_flow_error_set(error, ENOTSUP,
3207 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3208 : : "push vlan action for VF representor "
3209 : : "not supported on NIC table");
3210 [ # # ]: 0 : if (vlan_m &&
3211 [ # # # # ]: 0 : (vlan_m->hdr.vlan_tci & MLX5DV_FLOW_VLAN_PCP_MASK_BE) &&
3212 : : (vlan_m->hdr.vlan_tci & MLX5DV_FLOW_VLAN_PCP_MASK_BE) !=
3213 : 0 : MLX5DV_FLOW_VLAN_PCP_MASK_BE &&
3214 [ # # # # ]: 0 : !(action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_PCP) &&
3215 : 0 : !(mlx5_flow_find_action
3216 : : (action + 1, RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP)))
3217 : 0 : return rte_flow_error_set(error, EINVAL,
3218 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3219 : : "not full match mask on VLAN PCP and "
3220 : : "there is no of_set_vlan_pcp action, "
3221 : : "push VLAN action cannot figure out "
3222 : : "PCP value");
3223 [ # # ]: 0 : if (vlan_m &&
3224 [ # # # # ]: 0 : (vlan_m->hdr.vlan_tci & MLX5DV_FLOW_VLAN_VID_MASK_BE) &&
3225 : : (vlan_m->hdr.vlan_tci & MLX5DV_FLOW_VLAN_VID_MASK_BE) !=
3226 : 0 : MLX5DV_FLOW_VLAN_VID_MASK_BE &&
3227 [ # # # # ]: 0 : !(action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_VID) &&
3228 : 0 : !(mlx5_flow_find_action
3229 : : (action + 1, RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID)))
3230 : 0 : return rte_flow_error_set(error, EINVAL,
3231 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3232 : : "not full match mask on VLAN VID and "
3233 : : "there is no of_set_vlan_vid action, "
3234 : : "push VLAN action cannot figure out "
3235 : : "VID value");
3236 : : (void)attr;
3237 : : return 0;
3238 : : }
3239 : :
3240 : : /**
3241 : : * Validate the set VLAN PCP.
3242 : : *
3243 : : * @param[in] action_flags
3244 : : * Holds the actions detected until now.
3245 : : * @param[in] actions
3246 : : * Pointer to the list of actions remaining in the flow rule.
3247 : : * @param[out] error
3248 : : * Pointer to error structure.
3249 : : *
3250 : : * @return
3251 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3252 : : */
3253 : : static int
3254 : 0 : flow_dv_validate_action_set_vlan_pcp(uint64_t action_flags,
3255 : : const struct rte_flow_action actions[],
3256 : : struct rte_flow_error *error)
3257 : : {
3258 : : const struct rte_flow_action *action = actions;
3259 : 0 : const struct rte_flow_action_of_set_vlan_pcp *conf = action->conf;
3260 : :
3261 [ # # ]: 0 : if (conf->vlan_pcp > 7)
3262 : 0 : return rte_flow_error_set(error, EINVAL,
3263 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3264 : : "VLAN PCP value is too big");
3265 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN))
3266 : 0 : return rte_flow_error_set(error, ENOTSUP,
3267 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3268 : : "set VLAN PCP action must follow "
3269 : : "the push VLAN action");
3270 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_PCP)
3271 : 0 : return rte_flow_error_set(error, ENOTSUP,
3272 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3273 : : "Multiple VLAN PCP modification are "
3274 : : "not supported");
3275 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
3276 : 0 : return rte_flow_error_set(error, EINVAL,
3277 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3278 : : "wrong action order, port_id should "
3279 : : "be after set VLAN PCP");
3280 : : return 0;
3281 : : }
3282 : :
3283 : : /**
3284 : : * Validate the set VLAN VID.
3285 : : *
3286 : : * @param[in] item_flags
3287 : : * Holds the items detected in this rule.
3288 : : * @param[in] action_flags
3289 : : * Holds the actions detected until now.
3290 : : * @param[in] actions
3291 : : * Pointer to the list of actions remaining in the flow rule.
3292 : : * @param[out] error
3293 : : * Pointer to error structure.
3294 : : *
3295 : : * @return
3296 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3297 : : */
3298 : : static int
3299 : 0 : flow_dv_validate_action_set_vlan_vid(uint64_t item_flags,
3300 : : uint64_t action_flags,
3301 : : const struct rte_flow_action actions[],
3302 : : struct rte_flow_error *error)
3303 : : {
3304 : : const struct rte_flow_action *action = actions;
3305 : 0 : const struct rte_flow_action_of_set_vlan_vid *conf = action->conf;
3306 : :
3307 [ # # # # ]: 0 : if (rte_be_to_cpu_16(conf->vlan_vid) > 0xFFE)
3308 : 0 : return rte_flow_error_set(error, EINVAL,
3309 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3310 : : "VLAN VID value is too big");
3311 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN) &&
3312 [ # # ]: 0 : !(item_flags & MLX5_FLOW_LAYER_OUTER_VLAN))
3313 : 0 : return rte_flow_error_set(error, ENOTSUP,
3314 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3315 : : "set VLAN VID action must follow push"
3316 : : " VLAN action or match on VLAN item");
3317 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_VID)
3318 : 0 : return rte_flow_error_set(error, ENOTSUP,
3319 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3320 : : "Multiple VLAN VID modifications are "
3321 : : "not supported");
3322 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
3323 : 0 : return rte_flow_error_set(error, EINVAL,
3324 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3325 : : "wrong action order, port_id should "
3326 : : "be after set VLAN VID");
3327 : : return 0;
3328 : : }
3329 : :
3330 : : /*
3331 : : * Validate the FLAG action.
3332 : : *
3333 : : * @param[in] dev
3334 : : * Pointer to the rte_eth_dev structure.
3335 : : * @param[in] action_flags
3336 : : * Holds the actions detected until now.
3337 : : * @param[in] attr
3338 : : * Pointer to flow attributes
3339 : : * @param[out] error
3340 : : * Pointer to error structure.
3341 : : *
3342 : : * @return
3343 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3344 : : */
3345 : : static int
3346 : 0 : flow_dv_validate_action_flag(struct rte_eth_dev *dev,
3347 : : uint64_t action_flags,
3348 : : const struct rte_flow_attr *attr,
3349 : : struct rte_flow_error *error)
3350 : : {
3351 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3352 : 0 : struct mlx5_sh_config *config = &priv->sh->config;
3353 : : int ret;
3354 : :
3355 : : /* Fall back if no extended metadata register support. */
3356 [ # # ]: 0 : if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY)
3357 : 0 : return mlx5_flow_validate_action_flag(action_flags, attr,
3358 : : error);
3359 : : /* Extensive metadata mode requires registers. */
3360 [ # # ]: 0 : if (!mlx5_flow_ext_mreg_supported(dev))
3361 : 0 : return rte_flow_error_set(error, ENOTSUP,
3362 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3363 : : "no metadata registers "
3364 : : "to support flag action");
3365 [ # # ]: 0 : if (!(priv->sh->dv_mark_mask & MLX5_FLOW_MARK_DEFAULT))
3366 : 0 : return rte_flow_error_set(error, ENOTSUP,
3367 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3368 : : "extended metadata register"
3369 : : " isn't available");
3370 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
3371 [ # # ]: 0 : if (ret < 0)
3372 : : return ret;
3373 : : MLX5_ASSERT(ret > 0);
3374 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_MARK)
3375 : 0 : return rte_flow_error_set(error, EINVAL,
3376 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3377 : : "can't mark and flag in same flow");
3378 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_FLAG)
3379 : 0 : return rte_flow_error_set(error, EINVAL,
3380 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3381 : : "can't have 2 flag"
3382 : : " actions in same flow");
3383 : : return 0;
3384 : : }
3385 : :
3386 : : /**
3387 : : * Validate MARK action.
3388 : : *
3389 : : * @param[in] dev
3390 : : * Pointer to the rte_eth_dev structure.
3391 : : * @param[in] action
3392 : : * Pointer to action.
3393 : : * @param[in] action_flags
3394 : : * Holds the actions detected until now.
3395 : : * @param[in] attr
3396 : : * Pointer to flow attributes
3397 : : * @param[out] error
3398 : : * Pointer to error structure.
3399 : : *
3400 : : * @return
3401 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3402 : : */
3403 : : static int
3404 : 0 : flow_dv_validate_action_mark(struct rte_eth_dev *dev,
3405 : : const struct rte_flow_action *action,
3406 : : uint64_t action_flags,
3407 : : const struct rte_flow_attr *attr,
3408 : : struct rte_flow_error *error)
3409 : : {
3410 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3411 : 0 : struct mlx5_sh_config *config = &priv->sh->config;
3412 [ # # ]: 0 : const struct rte_flow_action_mark *mark = action->conf;
3413 : : int ret;
3414 : :
3415 [ # # ]: 0 : if (is_tunnel_offload_active(dev))
3416 : 0 : return rte_flow_error_set(error, ENOTSUP,
3417 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3418 : : "no mark action "
3419 : : "if tunnel offload active");
3420 : : /* Fall back if no extended metadata register support. */
3421 [ # # ]: 0 : if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY)
3422 : 0 : return mlx5_flow_validate_action_mark(action, action_flags,
3423 : : attr, error);
3424 : : /* Extensive metadata mode requires registers. */
3425 [ # # ]: 0 : if (!mlx5_flow_ext_mreg_supported(dev))
3426 : 0 : return rte_flow_error_set(error, ENOTSUP,
3427 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3428 : : "no metadata registers "
3429 : : "to support mark action");
3430 [ # # ]: 0 : if (!priv->sh->dv_mark_mask)
3431 : 0 : return rte_flow_error_set(error, ENOTSUP,
3432 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3433 : : "extended metadata register"
3434 : : " isn't available");
3435 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
3436 [ # # ]: 0 : if (ret < 0)
3437 : : return ret;
3438 : : MLX5_ASSERT(ret > 0);
3439 [ # # ]: 0 : if (!mark)
3440 : 0 : return rte_flow_error_set(error, EINVAL,
3441 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3442 : : "configuration cannot be null");
3443 [ # # ]: 0 : if (mark->id >= (MLX5_FLOW_MARK_MAX & priv->sh->dv_mark_mask))
3444 : 0 : return rte_flow_error_set(error, EINVAL,
3445 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
3446 : 0 : &mark->id,
3447 : : "mark id exceeds the limit");
3448 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_FLAG)
3449 : 0 : return rte_flow_error_set(error, EINVAL,
3450 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3451 : : "can't flag and mark in same flow");
3452 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_MARK)
3453 : 0 : return rte_flow_error_set(error, EINVAL,
3454 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3455 : : "can't have 2 mark actions in same"
3456 : : " flow");
3457 : : return 0;
3458 : : }
3459 : :
3460 : : /**
3461 : : * Validate SET_META action.
3462 : : *
3463 : : * @param[in] dev
3464 : : * Pointer to the rte_eth_dev structure.
3465 : : * @param[in] action
3466 : : * Pointer to the action structure.
3467 : : * @param[in] action_flags
3468 : : * Holds the actions detected until now.
3469 : : * @param[in] attr
3470 : : * Pointer to flow attributes
3471 : : * @param[out] error
3472 : : * Pointer to error structure.
3473 : : *
3474 : : * @return
3475 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3476 : : */
3477 : : static int
3478 : 0 : flow_dv_validate_action_set_meta(struct rte_eth_dev *dev,
3479 : : const struct rte_flow_action *action,
3480 : : uint64_t action_flags __rte_unused,
3481 : : const struct rte_flow_attr *attr,
3482 : : struct rte_flow_error *error)
3483 : : {
3484 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3485 : 0 : struct mlx5_sh_config *config = &priv->sh->config;
3486 : : const struct rte_flow_action_set_meta *conf;
3487 : : uint32_t nic_mask = UINT32_MAX;
3488 : : int reg;
3489 : :
3490 [ # # # # ]: 0 : if (config->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
3491 : 0 : !mlx5_flow_ext_mreg_supported(dev))
3492 : 0 : return rte_flow_error_set(error, ENOTSUP,
3493 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3494 : : "extended metadata register"
3495 : : " isn't supported");
3496 : 0 : reg = flow_dv_get_metadata_reg(dev, attr, error);
3497 [ # # ]: 0 : if (reg < 0)
3498 : : return reg;
3499 [ # # ]: 0 : if (reg == REG_NON)
3500 : 0 : return rte_flow_error_set(error, ENOTSUP,
3501 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3502 : : "unavailable extended metadata register");
3503 [ # # ]: 0 : if (reg != REG_A && reg != REG_B) {
3504 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3505 : :
3506 : 0 : nic_mask = priv->sh->dv_meta_mask;
3507 : : }
3508 [ # # ]: 0 : if (!(action->conf))
3509 : 0 : return rte_flow_error_set(error, EINVAL,
3510 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3511 : : "configuration cannot be null");
3512 : : conf = (const struct rte_flow_action_set_meta *)action->conf;
3513 [ # # ]: 0 : if (!conf->mask)
3514 : 0 : return rte_flow_error_set(error, EINVAL,
3515 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3516 : : "zero mask doesn't have any effect");
3517 [ # # ]: 0 : if (conf->mask & ~nic_mask)
3518 : 0 : return rte_flow_error_set(error, EINVAL,
3519 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3520 : : "meta data must be within reg C0");
3521 : : return 0;
3522 : : }
3523 : :
3524 : : /**
3525 : : * Validate SET_TAG action.
3526 : : *
3527 : : * @param[in] dev
3528 : : * Pointer to the rte_eth_dev structure.
3529 : : * @param[in] action
3530 : : * Pointer to the action structure.
3531 : : * @param[in] action_flags
3532 : : * Holds the actions detected until now.
3533 : : * @param[in] attr
3534 : : * Pointer to flow attributes
3535 : : * @param[out] error
3536 : : * Pointer to error structure.
3537 : : *
3538 : : * @return
3539 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3540 : : */
3541 : : static int
3542 : 0 : flow_dv_validate_action_set_tag(struct rte_eth_dev *dev,
3543 : : const struct rte_flow_action *action,
3544 : : uint64_t action_flags,
3545 : : const struct rte_flow_attr *attr,
3546 : : struct rte_flow_error *error)
3547 : : {
3548 : : const struct rte_flow_action_set_tag *conf;
3549 : : const uint64_t terminal_action_flags =
3550 : : MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_QUEUE |
3551 : : MLX5_FLOW_ACTION_RSS;
3552 : : int ret;
3553 : :
3554 [ # # ]: 0 : if (!mlx5_flow_ext_mreg_supported(dev))
3555 : 0 : return rte_flow_error_set(error, ENOTSUP,
3556 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3557 : : "extensive metadata register"
3558 : : " isn't supported");
3559 [ # # ]: 0 : if (!(action->conf))
3560 : 0 : return rte_flow_error_set(error, EINVAL,
3561 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3562 : : "configuration cannot be null");
3563 : : conf = (const struct rte_flow_action_set_tag *)action->conf;
3564 [ # # ]: 0 : if (!conf->mask)
3565 : 0 : return rte_flow_error_set(error, EINVAL,
3566 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3567 : : "zero mask doesn't have any effect");
3568 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, conf->index, error);
3569 [ # # ]: 0 : if (ret < 0)
3570 : : return ret;
3571 [ # # # # ]: 0 : if (attr->ingress && (action_flags & terminal_action_flags))
3572 : 0 : return rte_flow_error_set(error, EINVAL,
3573 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3574 : : "set_tag has no effect"
3575 : : " with terminal actions");
3576 : : return 0;
3577 : : }
3578 : :
3579 : : /**
3580 : : * Indicates whether ASO aging is supported.
3581 : : *
3582 : : * @param[in] priv
3583 : : * Pointer to device private context structure.
3584 : : * @param[in] root
3585 : : * Whether action is on root table.
3586 : : *
3587 : : * @return
3588 : : * True when ASO aging is supported, false otherwise.
3589 : : */
3590 : : static inline bool
3591 : : flow_hit_aso_supported(const struct mlx5_priv *priv, bool root)
3592 : : {
3593 : : MLX5_ASSERT(priv);
3594 [ # # # # : 0 : return (priv->sh->flow_hit_aso_en && !root);
# # # # #
# ]
3595 : : }
3596 : :
3597 : : /**
3598 : : * Validate count action.
3599 : : *
3600 : : * @param[in] dev
3601 : : * Pointer to rte_eth_dev structure.
3602 : : * @param[in] shared
3603 : : * Indicator if action is shared.
3604 : : * @param[in] action_flags
3605 : : * Holds the actions detected until now.
3606 : : * @param[in] root
3607 : : * Whether action is on root table.
3608 : : * @param[out] error
3609 : : * Pointer to error structure.
3610 : : *
3611 : : * @return
3612 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3613 : : */
3614 : : static int
3615 : 0 : flow_dv_validate_action_count(struct rte_eth_dev *dev, bool shared,
3616 : : uint64_t action_flags,
3617 : : bool root,
3618 : : struct rte_flow_error *error)
3619 : : {
3620 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3621 : :
3622 [ # # ]: 0 : if (!priv->sh->cdev->config.devx)
3623 : 0 : goto notsup_err;
3624 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_COUNT)
3625 : 0 : return rte_flow_error_set(error, EINVAL,
3626 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3627 : : "duplicate count actions set");
3628 [ # # # # : 0 : if (shared && (action_flags & MLX5_FLOW_ACTION_AGE) &&
# # ]
3629 : : !flow_hit_aso_supported(priv, root))
3630 : 0 : return rte_flow_error_set(error, EINVAL,
3631 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3632 : : "old age and indirect count combination is not supported");
3633 : : #ifdef HAVE_IBV_FLOW_DEVX_COUNTERS
3634 : : return 0;
3635 : : #endif
3636 : : notsup_err:
3637 : 0 : return rte_flow_error_set
3638 : : (error, ENOTSUP,
3639 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3640 : : NULL,
3641 : : "count action not supported");
3642 : : }
3643 : :
3644 : : /**
3645 : : * Validate the L2 encap action.
3646 : : *
3647 : : * @param[in] dev
3648 : : * Pointer to the rte_eth_dev structure.
3649 : : * @param[in] action_flags
3650 : : * Holds the actions detected until now.
3651 : : * @param[in] action
3652 : : * Pointer to the action structure.
3653 : : * @param[in] attr
3654 : : * Pointer to flow attributes.
3655 : : * @param[out] error
3656 : : * Pointer to error structure.
3657 : : *
3658 : : * @return
3659 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3660 : : */
3661 : : static int
3662 : 0 : flow_dv_validate_action_l2_encap(struct rte_eth_dev *dev,
3663 : : uint64_t action_flags,
3664 : : const struct rte_flow_action *action,
3665 : : const struct rte_flow_attr *attr,
3666 : : struct rte_flow_error *error)
3667 : : {
3668 : 0 : const struct mlx5_priv *priv = dev->data->dev_private;
3669 : :
3670 [ # # ]: 0 : if (!(action->conf))
3671 : 0 : return rte_flow_error_set(error, EINVAL,
3672 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3673 : : "configuration cannot be null");
3674 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_ENCAP)
3675 : 0 : return rte_flow_error_set(error, EINVAL,
3676 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3677 : : "can only have a single encap action "
3678 : : "in a flow");
3679 [ # # # # ]: 0 : if (!attr->transfer && priv->representor)
3680 : 0 : return rte_flow_error_set(error, ENOTSUP,
3681 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3682 : : "encap action for VF representor "
3683 : : "not supported on NIC table");
3684 : : return 0;
3685 : : }
3686 : :
3687 : : /**
3688 : : * Validate a decap action.
3689 : : *
3690 : : * @param[in] dev
3691 : : * Pointer to the rte_eth_dev structure.
3692 : : * @param[in] action_flags
3693 : : * Holds the actions detected until now.
3694 : : * @param[in] action
3695 : : * Pointer to the action structure.
3696 : : * @param[in] item_flags
3697 : : * Holds the items detected.
3698 : : * @param[in] attr
3699 : : * Pointer to flow attributes
3700 : : * @param[out] error
3701 : : * Pointer to error structure.
3702 : : *
3703 : : * @return
3704 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3705 : : */
3706 : : static int
3707 : 0 : flow_dv_validate_action_decap(struct rte_eth_dev *dev,
3708 : : uint64_t action_flags,
3709 : : const struct rte_flow_action *action,
3710 : : const uint64_t item_flags,
3711 : : const struct rte_flow_attr *attr,
3712 : : struct rte_flow_error *error)
3713 : : {
3714 : 0 : const struct mlx5_priv *priv = dev->data->dev_private;
3715 : :
3716 [ # # ]: 0 : if (priv->sh->cdev->config.hca_attr.scatter_fcs_w_decap_disable &&
3717 [ # # ]: 0 : !priv->sh->config.decap_en)
3718 : 0 : return rte_flow_error_set(error, ENOTSUP,
3719 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3720 : : "decap is not enabled");
3721 [ # # ]: 0 : if (action_flags & MLX5_FLOW_XCAP_ACTIONS)
3722 : 0 : return rte_flow_error_set(error, ENOTSUP,
3723 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3724 [ # # ]: 0 : action_flags &
3725 : : MLX5_FLOW_ACTION_DECAP ? "can only "
3726 : : "have a single decap action" : "decap "
3727 : : "after encap is not supported");
3728 [ # # ]: 0 : if (action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS)
3729 : 0 : return rte_flow_error_set(error, EINVAL,
3730 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3731 : : "can't have decap action after"
3732 : : " modify action");
3733 [ # # ]: 0 : if (attr->egress)
3734 : 0 : return rte_flow_error_set(error, ENOTSUP,
3735 : : RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
3736 : : NULL,
3737 : : "decap action not supported for "
3738 : : "egress");
3739 [ # # # # ]: 0 : if (!attr->transfer && priv->representor)
3740 : 0 : return rte_flow_error_set(error, ENOTSUP,
3741 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3742 : : "decap action for VF representor "
3743 : : "not supported on NIC table");
3744 [ # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_VXLAN_DECAP &&
3745 [ # # ]: 0 : !(item_flags & MLX5_FLOW_LAYER_VXLAN))
3746 : 0 : return rte_flow_error_set(error, ENOTSUP,
3747 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3748 : : "VXLAN item should be present for VXLAN decap");
3749 : : return 0;
3750 : : }
3751 : :
3752 : : const struct rte_flow_action_raw_decap empty_decap = {.data = NULL, .size = 0,};
3753 : :
3754 : : /**
3755 : : * Validate the raw encap and decap actions.
3756 : : *
3757 : : * @param[in] dev
3758 : : * Pointer to the rte_eth_dev structure.
3759 : : * @param[in] decap
3760 : : * Pointer to the decap action.
3761 : : * @param[in] encap
3762 : : * Pointer to the encap action.
3763 : : * @param[in] attr
3764 : : * Pointer to flow attributes
3765 : : * @param[in/out] action_flags
3766 : : * Holds the actions detected until now.
3767 : : * @param[out] actions_n
3768 : : * pointer to the number of actions counter.
3769 : : * @param[in] action
3770 : : * Pointer to the action structure.
3771 : : * @param[in] item_flags
3772 : : * Holds the items detected.
3773 : : * @param[out] error
3774 : : * Pointer to error structure.
3775 : : *
3776 : : * @return
3777 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3778 : : */
3779 : : static int
3780 : 0 : flow_dv_validate_action_raw_encap_decap
3781 : : (struct rte_eth_dev *dev,
3782 : : const struct rte_flow_action_raw_decap *decap,
3783 : : const struct rte_flow_action_raw_encap *encap,
3784 : : const struct rte_flow_attr *attr, uint64_t *action_flags,
3785 : : int *actions_n, const struct rte_flow_action *action,
3786 : : uint64_t item_flags, struct rte_flow_error *error)
3787 : : {
3788 : 0 : const struct mlx5_priv *priv = dev->data->dev_private;
3789 : : int ret;
3790 : :
3791 [ # # # # : 0 : if (encap && (!encap->size || !encap->data))
# # ]
3792 : 0 : return rte_flow_error_set(error, EINVAL,
3793 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3794 : : "raw encap data cannot be empty");
3795 [ # # ]: 0 : if (decap && encap) {
3796 [ # # ]: 0 : if (decap->size <= MLX5_ENCAPSULATION_DECISION_SIZE &&
3797 [ # # ]: 0 : encap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
3798 : : /* L3 encap. */
3799 : : decap = NULL;
3800 [ # # ]: 0 : else if (encap->size <=
3801 [ # # ]: 0 : MLX5_ENCAPSULATION_DECISION_SIZE &&
3802 : : decap->size >
3803 : : MLX5_ENCAPSULATION_DECISION_SIZE)
3804 : : /* L3 decap. */
3805 : : encap = NULL;
3806 [ # # ]: 0 : else if (encap->size >
3807 [ # # ]: 0 : MLX5_ENCAPSULATION_DECISION_SIZE &&
3808 : : decap->size >
3809 : : MLX5_ENCAPSULATION_DECISION_SIZE)
3810 : : /* 2 L2 actions: encap and decap. */
3811 : : ;
3812 : : else
3813 : 0 : return rte_flow_error_set(error,
3814 : : ENOTSUP,
3815 : : RTE_FLOW_ERROR_TYPE_ACTION,
3816 : : NULL, "unsupported too small "
3817 : : "raw decap and too small raw "
3818 : : "encap combination");
3819 : : }
3820 [ # # ]: 0 : if (decap) {
3821 : 0 : ret = flow_dv_validate_action_decap(dev, *action_flags, action,
3822 : : item_flags, attr, error);
3823 [ # # ]: 0 : if (ret < 0)
3824 : : return ret;
3825 : 0 : *action_flags |= MLX5_FLOW_ACTION_DECAP;
3826 : 0 : ++(*actions_n);
3827 : : }
3828 [ # # ]: 0 : if (encap) {
3829 [ # # ]: 0 : if (encap->size <= MLX5_ENCAPSULATION_DECISION_SIZE)
3830 : 0 : return rte_flow_error_set(error, ENOTSUP,
3831 : : RTE_FLOW_ERROR_TYPE_ACTION,
3832 : : NULL,
3833 : : "small raw encap size");
3834 [ # # ]: 0 : if (*action_flags & MLX5_FLOW_ACTION_ENCAP)
3835 : 0 : return rte_flow_error_set(error, EINVAL,
3836 : : RTE_FLOW_ERROR_TYPE_ACTION,
3837 : : NULL,
3838 : : "more than one encap action");
3839 [ # # # # ]: 0 : if (!attr->transfer && priv->representor)
3840 : 0 : return rte_flow_error_set
3841 : : (error, ENOTSUP,
3842 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3843 : : "encap action for VF representor "
3844 : : "not supported on NIC table");
3845 : 0 : *action_flags |= MLX5_FLOW_ACTION_ENCAP;
3846 : 0 : ++(*actions_n);
3847 : : }
3848 : : return 0;
3849 : : }
3850 : :
3851 : : /*
3852 : : * Validate the ASO CT action.
3853 : : *
3854 : : * @param[in] dev
3855 : : * Pointer to the rte_eth_dev structure.
3856 : : * @param[in] action_flags
3857 : : * Holds the actions detected until now.
3858 : : * @param[in] item_flags
3859 : : * The items found in this flow rule.
3860 : : * @param root
3861 : : * Whether action is on root table.
3862 : : * @param[out] error
3863 : : * Pointer to error structure.
3864 : : *
3865 : : * @return
3866 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3867 : : */
3868 : : static int
3869 : 0 : flow_dv_validate_action_aso_ct(struct rte_eth_dev *dev,
3870 : : uint64_t action_flags,
3871 : : uint64_t item_flags,
3872 : : bool root,
3873 : : struct rte_flow_error *error)
3874 : : {
3875 : : RTE_SET_USED(dev);
3876 : :
3877 [ # # ]: 0 : if (root)
3878 : 0 : return rte_flow_error_set(error, ENOTSUP,
3879 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3880 : : NULL,
3881 : : "Only support non-root table");
3882 [ # # ]: 0 : if (action_flags & MLX5_FLOW_FATE_ACTIONS)
3883 : 0 : return rte_flow_error_set(error, ENOTSUP,
3884 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3885 : : "CT cannot follow a fate action");
3886 [ # # ]: 0 : if ((action_flags & MLX5_FLOW_ACTION_METER) ||
3887 : : (action_flags & MLX5_FLOW_ACTION_AGE))
3888 : 0 : return rte_flow_error_set(error, EINVAL,
3889 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3890 : : "Only one ASO action is supported");
3891 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_ENCAP)
3892 : 0 : return rte_flow_error_set(error, EINVAL,
3893 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3894 : : "Encap cannot exist before CT");
3895 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_TCP))
3896 : 0 : return rte_flow_error_set(error, EINVAL,
3897 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3898 : : "Not a outer TCP packet");
3899 : : return 0;
3900 : : }
3901 : :
3902 : : /**
3903 : : * Validate METER_COLOR item.
3904 : : *
3905 : : * @param[in] dev
3906 : : * Pointer to the rte_eth_dev structure.
3907 : : * @param[in] item
3908 : : * Item specification.
3909 : : * @param[in] attr
3910 : : * Attributes of flow that includes this item.
3911 : : * @param[out] error
3912 : : * Pointer to error structure.
3913 : : *
3914 : : * @return
3915 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3916 : : */
3917 : : static int
3918 : 0 : flow_dv_validate_item_meter_color(struct rte_eth_dev *dev,
3919 : : const struct rte_flow_item *item,
3920 : : const struct rte_flow_attr *attr __rte_unused,
3921 : : struct rte_flow_error *error)
3922 : : {
3923 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3924 : 0 : const struct rte_flow_item_meter_color *spec = item->spec;
3925 : 0 : const struct rte_flow_item_meter_color *mask = item->mask;
3926 : 0 : struct rte_flow_item_meter_color nic_mask = {
3927 : : .color = RTE_COLORS
3928 : : };
3929 : : int ret;
3930 : :
3931 [ # # ]: 0 : if (priv->sh->registers.aso_reg == REG_NON)
3932 : 0 : return rte_flow_error_set(error, ENOTSUP,
3933 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3934 : : "meter color register"
3935 : : " isn't available");
3936 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, error);
3937 [ # # ]: 0 : if (ret < 0)
3938 : : return ret;
3939 [ # # ]: 0 : if (!spec)
3940 : 0 : return rte_flow_error_set(error, EINVAL,
3941 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
3942 : 0 : item->spec,
3943 : : "data cannot be empty");
3944 [ # # ]: 0 : if (spec->color > RTE_COLORS)
3945 : 0 : return rte_flow_error_set(error, EINVAL,
3946 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
3947 : 0 : &spec->color,
3948 : : "meter color is invalid");
3949 [ # # ]: 0 : if (!mask)
3950 : : mask = &rte_flow_item_meter_color_mask;
3951 [ # # ]: 0 : if (!mask->color)
3952 : 0 : return rte_flow_error_set(error, EINVAL,
3953 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
3954 : : "mask cannot be zero");
3955 : :
3956 : 0 : ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
3957 : : (const uint8_t *)&nic_mask,
3958 : : sizeof(struct rte_flow_item_meter_color),
3959 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
3960 : : if (ret < 0)
3961 : : return ret;
3962 : : return 0;
3963 : : }
3964 : :
3965 : : /**
3966 : : * Validate aggregated affinity item.
3967 : : *
3968 : : * @param[in] dev
3969 : : * Pointer to the rte_eth_dev structure.
3970 : : * @param[in] item
3971 : : * Item specification.
3972 : : * @param[in] attr
3973 : : * Attributes of flow that includes this item.
3974 : : * @param[out] error
3975 : : * Pointer to error structure.
3976 : : *
3977 : : * @return
3978 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3979 : : */
3980 : : static int
3981 : 0 : flow_dv_validate_item_aggr_affinity(struct rte_eth_dev *dev,
3982 : : const struct rte_flow_item *item,
3983 : : const struct rte_flow_attr *attr,
3984 : : struct rte_flow_error *error)
3985 : : {
3986 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3987 : 0 : const struct rte_flow_item_aggr_affinity *spec = item->spec;
3988 : 0 : const struct rte_flow_item_aggr_affinity *mask = item->mask;
3989 : 0 : struct rte_flow_item_aggr_affinity nic_mask = {
3990 : : .affinity = UINT8_MAX
3991 : : };
3992 : : int ret;
3993 : :
3994 [ # # ]: 0 : if (!priv->sh->lag_rx_port_affinity_en)
3995 : 0 : return rte_flow_error_set(error, EINVAL,
3996 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
3997 : : "Unsupported aggregated affinity with Older FW");
3998 [ # # # # : 0 : if ((attr->transfer && priv->fdb_def_rule) ||
# # ]
3999 [ # # ]: 0 : attr->egress || attr->group)
4000 : 0 : return rte_flow_error_set(error, ENOTSUP,
4001 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
4002 : : item->spec,
4003 : : "aggregated affinity is not supported with egress or FDB on non root table");
4004 [ # # ]: 0 : if (!spec)
4005 : 0 : return rte_flow_error_set(error, EINVAL,
4006 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
4007 : : item->spec,
4008 : : "data cannot be empty");
4009 [ # # ]: 0 : if (spec->affinity == 0)
4010 : 0 : return rte_flow_error_set(error, ENOTSUP,
4011 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
4012 : : item->spec,
4013 : : "zero affinity number not supported");
4014 [ # # ]: 0 : if (spec->affinity > priv->num_lag_ports)
4015 : 0 : return rte_flow_error_set(error, ENOTSUP,
4016 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
4017 : : item->spec,
4018 : : "exceed max affinity number in lag ports");
4019 [ # # ]: 0 : if (!mask)
4020 : : mask = &rte_flow_item_aggr_affinity_mask;
4021 [ # # ]: 0 : if (!mask->affinity)
4022 : 0 : return rte_flow_error_set(error, EINVAL,
4023 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
4024 : : "mask cannot be zero");
4025 : 0 : ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
4026 : : (const uint8_t *)&nic_mask,
4027 : : sizeof(struct rte_flow_item_aggr_affinity),
4028 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
4029 : : if (ret < 0)
4030 : : return ret;
4031 : : return 0;
4032 : : }
4033 : :
4034 : : int
4035 : 0 : flow_dv_encap_decap_match_cb(void *tool_ctx __rte_unused,
4036 : : struct mlx5_list_entry *entry, void *cb_ctx)
4037 : : {
4038 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4039 : 0 : struct mlx5_flow_dv_encap_decap_resource *ctx_resource = ctx->data;
4040 : : struct mlx5_flow_dv_encap_decap_resource *resource;
4041 : :
4042 : : resource = container_of(entry, struct mlx5_flow_dv_encap_decap_resource,
4043 : : entry);
4044 [ # # ]: 0 : if (resource->reformat_type == ctx_resource->reformat_type &&
4045 : 0 : resource->ft_type == ctx_resource->ft_type &&
4046 [ # # ]: 0 : resource->flags == ctx_resource->flags &&
4047 [ # # ]: 0 : resource->size == ctx_resource->size &&
4048 : 0 : !memcmp((const void *)resource->buf,
4049 [ # # ]: 0 : (const void *)ctx_resource->buf,
4050 : : resource->size))
4051 : 0 : return 0;
4052 : : return -1;
4053 : : }
4054 : :
4055 : : struct mlx5_list_entry *
4056 : 0 : flow_dv_encap_decap_create_cb(void *tool_ctx, void *cb_ctx)
4057 : : {
4058 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
4059 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4060 : : struct mlx5dv_dr_domain *domain;
4061 : 0 : struct mlx5_flow_dv_encap_decap_resource *ctx_resource = ctx->data;
4062 : : struct mlx5_flow_dv_encap_decap_resource *resource;
4063 : : uint32_t idx;
4064 : : int ret;
4065 : :
4066 [ # # ]: 0 : if (ctx_resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
4067 : 0 : domain = sh->fdb_domain;
4068 [ # # ]: 0 : else if (ctx_resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_RX)
4069 : 0 : domain = sh->rx_domain;
4070 : : else
4071 : 0 : domain = sh->tx_domain;
4072 : : /* Register new encap/decap resource. */
4073 : 0 : resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_DECAP_ENCAP], &idx);
4074 [ # # ]: 0 : if (!resource) {
4075 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
4076 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4077 : : "cannot allocate resource memory");
4078 : 0 : return NULL;
4079 : : }
4080 : 0 : *resource = *ctx_resource;
4081 : 0 : resource->idx = idx;
4082 [ # # ]: 0 : ret = mlx5_flow_os_create_flow_action_packet_reformat(sh->cdev->ctx,
4083 : : domain, resource,
4084 : : &resource->action);
4085 : : if (ret) {
4086 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_DECAP_ENCAP], idx);
4087 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
4088 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
4089 : : NULL, "cannot create action");
4090 : 0 : return NULL;
4091 : : }
4092 : :
4093 : 0 : return &resource->entry;
4094 : : }
4095 : :
4096 : : struct mlx5_list_entry *
4097 : 0 : flow_dv_encap_decap_clone_cb(void *tool_ctx, struct mlx5_list_entry *oentry,
4098 : : void *cb_ctx)
4099 : : {
4100 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
4101 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4102 : : struct mlx5_flow_dv_encap_decap_resource *cache_resource;
4103 : : uint32_t idx;
4104 : :
4105 : 0 : cache_resource = mlx5_ipool_malloc(sh->ipool[MLX5_IPOOL_DECAP_ENCAP],
4106 : : &idx);
4107 [ # # ]: 0 : if (!cache_resource) {
4108 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
4109 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4110 : : "cannot allocate resource memory");
4111 : 0 : return NULL;
4112 : : }
4113 : : memcpy(cache_resource, oentry, sizeof(*cache_resource));
4114 : 0 : cache_resource->idx = idx;
4115 : 0 : return &cache_resource->entry;
4116 : : }
4117 : :
4118 : : void
4119 : 0 : flow_dv_encap_decap_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
4120 : : {
4121 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
4122 : : struct mlx5_flow_dv_encap_decap_resource *res =
4123 : : container_of(entry, typeof(*res), entry);
4124 : :
4125 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_DECAP_ENCAP], res->idx);
4126 : 0 : }
4127 : :
4128 : : /**
4129 : : * Find existing encap/decap resource or create and register a new one.
4130 : : *
4131 : : * @param[in, out] dev
4132 : : * Pointer to rte_eth_dev structure.
4133 : : * @param[in, out] resource
4134 : : * Pointer to encap/decap resource.
4135 : : * @parm[in, out] dev_flow
4136 : : * Pointer to the dev_flow.
4137 : : * @param[out] error
4138 : : * pointer to error structure.
4139 : : *
4140 : : * @return
4141 : : * 0 on success otherwise -errno and errno is set.
4142 : : */
4143 : : static int
4144 : 0 : flow_dv_encap_decap_resource_register
4145 : : (struct rte_eth_dev *dev,
4146 : : struct mlx5_flow_dv_encap_decap_resource *resource,
4147 : : struct mlx5_flow *dev_flow,
4148 : : struct rte_flow_error *error)
4149 : : {
4150 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4151 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
4152 : : struct mlx5_list_entry *entry;
4153 : : union {
4154 : : struct {
4155 : : uint32_t ft_type:8;
4156 : : uint32_t refmt_type:8;
4157 : : /*
4158 : : * Header reformat actions can be shared between
4159 : : * non-root tables. One bit to indicate non-root
4160 : : * table or not.
4161 : : */
4162 : : uint32_t is_root:1;
4163 : : uint32_t reserve:15;
4164 : : };
4165 : : uint32_t v32;
4166 : 0 : } encap_decap_key = {
4167 : : {
4168 : 0 : .ft_type = resource->ft_type,
4169 : 0 : .refmt_type = resource->reformat_type,
4170 : 0 : .is_root = !!dev_flow->dv.group,
4171 : : .reserve = 0,
4172 : : }
4173 : : };
4174 : 0 : struct mlx5_flow_cb_ctx ctx = {
4175 : : .error = error,
4176 : : .data = resource,
4177 : : };
4178 : : struct mlx5_hlist *encaps_decaps;
4179 : : uint64_t key64;
4180 : :
4181 : 0 : encaps_decaps = flow_dv_hlist_prepare(sh, &sh->encaps_decaps,
4182 : : "encaps_decaps",
4183 : : MLX5_FLOW_ENCAP_DECAP_HTABLE_SZ,
4184 : : true, true, sh,
4185 : : flow_dv_encap_decap_create_cb,
4186 : : flow_dv_encap_decap_match_cb,
4187 : : flow_dv_encap_decap_remove_cb,
4188 : : flow_dv_encap_decap_clone_cb,
4189 : : flow_dv_encap_decap_clone_free_cb,
4190 : : error);
4191 [ # # ]: 0 : if (unlikely(!encaps_decaps))
4192 : 0 : return -rte_errno;
4193 : 0 : resource->flags = dev_flow->dv.group ? 0 : 1;
4194 : 0 : key64 = __rte_raw_cksum(&encap_decap_key.v32,
4195 : : sizeof(encap_decap_key.v32), 0);
4196 [ # # ]: 0 : if (resource->reformat_type !=
4197 : 0 : MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TUNNEL_TO_L2 &&
4198 [ # # ]: 0 : resource->size)
4199 : 0 : key64 = __rte_raw_cksum(resource->buf, resource->size, key64);
4200 : 0 : entry = mlx5_hlist_register(encaps_decaps, key64, &ctx);
4201 [ # # ]: 0 : if (!entry)
4202 : 0 : return -rte_errno;
4203 : : resource = container_of(entry, typeof(*resource), entry);
4204 : 0 : dev_flow->dv.encap_decap = resource;
4205 : 0 : dev_flow->handle->dvh.rix_encap_decap = resource->idx;
4206 : 0 : return 0;
4207 : : }
4208 : :
4209 : : /**
4210 : : * Find existing table jump resource or create and register a new one.
4211 : : *
4212 : : * @param[in, out] dev
4213 : : * Pointer to rte_eth_dev structure.
4214 : : * @param[in, out] tbl
4215 : : * Pointer to flow table resource.
4216 : : * @parm[in, out] dev_flow
4217 : : * Pointer to the dev_flow.
4218 : : * @param[out] error
4219 : : * pointer to error structure.
4220 : : *
4221 : : * @return
4222 : : * 0 on success otherwise -errno and errno is set.
4223 : : */
4224 : : static int
4225 : : flow_dv_jump_tbl_resource_register
4226 : : (struct rte_eth_dev *dev __rte_unused,
4227 : : struct mlx5_flow_tbl_resource *tbl,
4228 : : struct mlx5_flow *dev_flow,
4229 : : struct rte_flow_error *error __rte_unused)
4230 : : {
4231 : : struct mlx5_flow_tbl_data_entry *tbl_data =
4232 : 0 : container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
4233 : :
4234 : : MLX5_ASSERT(tbl);
4235 : : MLX5_ASSERT(tbl_data->jump.action);
4236 : 0 : dev_flow->handle->rix_jump = tbl_data->idx;
4237 : 0 : dev_flow->dv.jump = &tbl_data->jump;
4238 : : return 0;
4239 : : }
4240 : :
4241 : : int
4242 : 0 : flow_dv_port_id_match_cb(void *tool_ctx __rte_unused,
4243 : : struct mlx5_list_entry *entry, void *cb_ctx)
4244 : : {
4245 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4246 : 0 : struct mlx5_flow_dv_port_id_action_resource *ref = ctx->data;
4247 : : struct mlx5_flow_dv_port_id_action_resource *res =
4248 : : container_of(entry, typeof(*res), entry);
4249 : :
4250 : 0 : return ref->port_id != res->port_id;
4251 : : }
4252 : :
4253 : : struct mlx5_list_entry *
4254 : 0 : flow_dv_port_id_create_cb(void *tool_ctx, void *cb_ctx)
4255 : : {
4256 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
4257 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4258 : 0 : struct mlx5_flow_dv_port_id_action_resource *ref = ctx->data;
4259 : : struct mlx5_flow_dv_port_id_action_resource *resource;
4260 : : uint32_t idx;
4261 : : int ret;
4262 : :
4263 : : /* Register new port id action resource. */
4264 : 0 : resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_PORT_ID], &idx);
4265 [ # # ]: 0 : if (!resource) {
4266 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
4267 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4268 : : "cannot allocate port_id action memory");
4269 : 0 : return NULL;
4270 : : }
4271 : 0 : *resource = *ref;
4272 : 0 : ret = mlx5_flow_os_create_flow_action_dest_port(sh->fdb_domain,
4273 : : ref->port_id,
4274 : : &resource->action);
4275 : : if (ret) {
4276 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PORT_ID], idx);
4277 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
4278 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4279 : : "cannot create action");
4280 : 0 : return NULL;
4281 : : }
4282 : 0 : resource->idx = idx;
4283 : 0 : return &resource->entry;
4284 : : }
4285 : :
4286 : : struct mlx5_list_entry *
4287 : 0 : flow_dv_port_id_clone_cb(void *tool_ctx,
4288 : : struct mlx5_list_entry *entry __rte_unused,
4289 : : void *cb_ctx)
4290 : : {
4291 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
4292 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4293 : : struct mlx5_flow_dv_port_id_action_resource *resource;
4294 : : uint32_t idx;
4295 : :
4296 : 0 : resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_PORT_ID], &idx);
4297 [ # # ]: 0 : if (!resource) {
4298 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
4299 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4300 : : "cannot allocate port_id action memory");
4301 : 0 : return NULL;
4302 : : }
4303 : : memcpy(resource, entry, sizeof(*resource));
4304 : 0 : resource->idx = idx;
4305 : 0 : return &resource->entry;
4306 : : }
4307 : :
4308 : : void
4309 : 0 : flow_dv_port_id_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
4310 : : {
4311 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
4312 : : struct mlx5_flow_dv_port_id_action_resource *resource =
4313 : : container_of(entry, typeof(*resource), entry);
4314 : :
4315 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PORT_ID], resource->idx);
4316 : 0 : }
4317 : :
4318 : : /**
4319 : : * Find existing table port ID resource or create and register a new one.
4320 : : *
4321 : : * @param[in, out] dev
4322 : : * Pointer to rte_eth_dev structure.
4323 : : * @param[in, out] ref
4324 : : * Pointer to port ID action resource reference.
4325 : : * @parm[in, out] dev_flow
4326 : : * Pointer to the dev_flow.
4327 : : * @param[out] error
4328 : : * pointer to error structure.
4329 : : *
4330 : : * @return
4331 : : * 0 on success otherwise -errno and errno is set.
4332 : : */
4333 : : static int
4334 : 0 : flow_dv_port_id_action_resource_register
4335 : : (struct rte_eth_dev *dev,
4336 : : struct mlx5_flow_dv_port_id_action_resource *ref,
4337 : : struct mlx5_flow *dev_flow,
4338 : : struct rte_flow_error *error)
4339 : : {
4340 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4341 : : struct mlx5_list_entry *entry;
4342 : : struct mlx5_flow_dv_port_id_action_resource *resource;
4343 : 0 : struct mlx5_flow_cb_ctx ctx = {
4344 : : .error = error,
4345 : : .data = ref,
4346 : : };
4347 : :
4348 : 0 : entry = mlx5_list_register(priv->sh->port_id_action_list, &ctx);
4349 [ # # ]: 0 : if (!entry)
4350 : 0 : return -rte_errno;
4351 : : resource = container_of(entry, typeof(*resource), entry);
4352 : 0 : dev_flow->dv.port_id_action = resource;
4353 : 0 : dev_flow->handle->rix_port_id_action = resource->idx;
4354 : 0 : return 0;
4355 : : }
4356 : :
4357 : : int
4358 : 0 : flow_dv_push_vlan_match_cb(void *tool_ctx __rte_unused,
4359 : : struct mlx5_list_entry *entry, void *cb_ctx)
4360 : : {
4361 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4362 : 0 : struct mlx5_flow_dv_push_vlan_action_resource *ref = ctx->data;
4363 : : struct mlx5_flow_dv_push_vlan_action_resource *res =
4364 : : container_of(entry, typeof(*res), entry);
4365 : :
4366 : 0 : return ref->vlan_tag != res->vlan_tag || ref->ft_type != res->ft_type;
4367 : : }
4368 : :
4369 : : struct mlx5_list_entry *
4370 : 0 : flow_dv_push_vlan_create_cb(void *tool_ctx, void *cb_ctx)
4371 : : {
4372 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
4373 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4374 : 0 : struct mlx5_flow_dv_push_vlan_action_resource *ref = ctx->data;
4375 : : struct mlx5_flow_dv_push_vlan_action_resource *resource;
4376 : : struct mlx5dv_dr_domain *domain;
4377 : : uint32_t idx;
4378 : : int ret;
4379 : :
4380 : : /* Register new port id action resource. */
4381 : 0 : resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_PUSH_VLAN], &idx);
4382 [ # # ]: 0 : if (!resource) {
4383 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
4384 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4385 : : "cannot allocate push_vlan action memory");
4386 : 0 : return NULL;
4387 : : }
4388 : 0 : *resource = *ref;
4389 [ # # ]: 0 : if (ref->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
4390 : 0 : domain = sh->fdb_domain;
4391 [ # # ]: 0 : else if (ref->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_RX)
4392 : 0 : domain = sh->rx_domain;
4393 : : else
4394 : 0 : domain = sh->tx_domain;
4395 : 0 : ret = mlx5_flow_os_create_flow_action_push_vlan(domain, ref->vlan_tag,
4396 : : &resource->action);
4397 : : if (ret) {
4398 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PUSH_VLAN], idx);
4399 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
4400 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4401 : : "cannot create push vlan action");
4402 : 0 : return NULL;
4403 : : }
4404 : 0 : resource->idx = idx;
4405 : 0 : return &resource->entry;
4406 : : }
4407 : :
4408 : : struct mlx5_list_entry *
4409 : 0 : flow_dv_push_vlan_clone_cb(void *tool_ctx,
4410 : : struct mlx5_list_entry *entry __rte_unused,
4411 : : void *cb_ctx)
4412 : : {
4413 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
4414 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4415 : : struct mlx5_flow_dv_push_vlan_action_resource *resource;
4416 : : uint32_t idx;
4417 : :
4418 : 0 : resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_PUSH_VLAN], &idx);
4419 [ # # ]: 0 : if (!resource) {
4420 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
4421 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4422 : : "cannot allocate push_vlan action memory");
4423 : 0 : return NULL;
4424 : : }
4425 : : memcpy(resource, entry, sizeof(*resource));
4426 : 0 : resource->idx = idx;
4427 : 0 : return &resource->entry;
4428 : : }
4429 : :
4430 : : void
4431 : 0 : flow_dv_push_vlan_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
4432 : : {
4433 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
4434 : : struct mlx5_flow_dv_push_vlan_action_resource *resource =
4435 : : container_of(entry, typeof(*resource), entry);
4436 : :
4437 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PUSH_VLAN], resource->idx);
4438 : 0 : }
4439 : :
4440 : : /**
4441 : : * Find existing push vlan resource or create and register a new one.
4442 : : *
4443 : : * @param [in, out] dev
4444 : : * Pointer to rte_eth_dev structure.
4445 : : * @param[in, out] ref
4446 : : * Pointer to port ID action resource reference.
4447 : : * @parm[in, out] dev_flow
4448 : : * Pointer to the dev_flow.
4449 : : * @param[out] error
4450 : : * pointer to error structure.
4451 : : *
4452 : : * @return
4453 : : * 0 on success otherwise -errno and errno is set.
4454 : : */
4455 : : static int
4456 : 0 : flow_dv_push_vlan_action_resource_register
4457 : : (struct rte_eth_dev *dev,
4458 : : struct mlx5_flow_dv_push_vlan_action_resource *ref,
4459 : : struct mlx5_flow *dev_flow,
4460 : : struct rte_flow_error *error)
4461 : : {
4462 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4463 : : struct mlx5_flow_dv_push_vlan_action_resource *resource;
4464 : : struct mlx5_list_entry *entry;
4465 : 0 : struct mlx5_flow_cb_ctx ctx = {
4466 : : .error = error,
4467 : : .data = ref,
4468 : : };
4469 : :
4470 : 0 : entry = mlx5_list_register(priv->sh->push_vlan_action_list, &ctx);
4471 [ # # ]: 0 : if (!entry)
4472 : 0 : return -rte_errno;
4473 : : resource = container_of(entry, typeof(*resource), entry);
4474 : :
4475 : 0 : dev_flow->handle->dvh.rix_push_vlan = resource->idx;
4476 : 0 : dev_flow->dv.push_vlan_res = resource;
4477 : 0 : return 0;
4478 : : }
4479 : :
4480 : : /**
4481 : : * Get the size of specific rte_flow_item_type hdr size
4482 : : *
4483 : : * @param[in] item_type
4484 : : * Tested rte_flow_item_type.
4485 : : *
4486 : : * @return
4487 : : * sizeof struct item_type, 0 if void or irrelevant.
4488 : : */
4489 : : size_t
4490 [ # # ]: 0 : flow_dv_get_item_hdr_len(const enum rte_flow_item_type item_type)
4491 : : {
4492 : : size_t retval;
4493 : :
4494 : : switch (item_type) {
4495 : : case RTE_FLOW_ITEM_TYPE_ETH:
4496 : : retval = sizeof(struct rte_ether_hdr);
4497 : : break;
4498 : : case RTE_FLOW_ITEM_TYPE_VLAN:
4499 : : retval = sizeof(struct rte_vlan_hdr);
4500 : : break;
4501 : : case RTE_FLOW_ITEM_TYPE_IPV4:
4502 : : retval = sizeof(struct rte_ipv4_hdr);
4503 : : break;
4504 : : case RTE_FLOW_ITEM_TYPE_IPV6:
4505 : : retval = sizeof(struct rte_ipv6_hdr);
4506 : : break;
4507 : : case RTE_FLOW_ITEM_TYPE_UDP:
4508 : : retval = sizeof(struct rte_udp_hdr);
4509 : : break;
4510 : : case RTE_FLOW_ITEM_TYPE_TCP:
4511 : : retval = sizeof(struct rte_tcp_hdr);
4512 : : break;
4513 : : case RTE_FLOW_ITEM_TYPE_VXLAN:
4514 : : case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
4515 : : retval = sizeof(struct rte_vxlan_hdr);
4516 : : break;
4517 : : case RTE_FLOW_ITEM_TYPE_GRE:
4518 : : case RTE_FLOW_ITEM_TYPE_NVGRE:
4519 : : retval = sizeof(struct rte_gre_hdr);
4520 : : break;
4521 : : case RTE_FLOW_ITEM_TYPE_MPLS:
4522 : : retval = sizeof(struct rte_mpls_hdr);
4523 : : break;
4524 : : case RTE_FLOW_ITEM_TYPE_VOID: /* Fall through. */
4525 : : default:
4526 : : retval = 0;
4527 : : break;
4528 : : }
4529 : 0 : return retval;
4530 : : }
4531 : :
4532 : : #define MLX5_ENCAP_IPV4_VERSION 0x40
4533 : : #define MLX5_ENCAP_IPV4_IHL_MIN 0x05
4534 : : #define MLX5_ENCAP_IPV4_TTL_DEF 0x40
4535 : : #define MLX5_ENCAP_IPV6_VTC_FLOW 0x60000000
4536 : : #define MLX5_ENCAP_IPV6_HOP_LIMIT 0xff
4537 : : #define MLX5_ENCAP_VXLAN_FLAGS 0x08000000
4538 : : #define MLX5_ENCAP_VXLAN_GPE_FLAGS 0x04
4539 : :
4540 : : /**
4541 : : * Convert the encap action data from list of rte_flow_item to raw buffer
4542 : : *
4543 : : * @param[in] items
4544 : : * Pointer to rte_flow_item objects list.
4545 : : * @param[out] buf
4546 : : * Pointer to the output buffer.
4547 : : * @param[out] size
4548 : : * Pointer to the output buffer size.
4549 : : * @param[out] error
4550 : : * Pointer to the error structure.
4551 : : *
4552 : : * @return
4553 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
4554 : : */
4555 : : int
4556 : 0 : flow_dv_convert_encap_data(const struct rte_flow_item *items, uint8_t *buf,
4557 : : size_t *size, struct rte_flow_error *error)
4558 : : {
4559 : : struct rte_ether_hdr *eth = NULL;
4560 : : struct rte_vlan_hdr *vlan = NULL;
4561 : : struct rte_ipv4_hdr *ipv4 = NULL;
4562 : : struct rte_ipv6_hdr *ipv6 = NULL;
4563 : : struct rte_udp_hdr *udp = NULL;
4564 : : struct rte_vxlan_hdr *vxlan = NULL;
4565 : : struct rte_vxlan_gpe_hdr *vxlan_gpe = NULL;
4566 : : struct rte_gre_hdr *gre = NULL;
4567 : : size_t len;
4568 : : size_t temp_size = 0;
4569 : :
4570 [ # # ]: 0 : if (!items)
4571 : 0 : return rte_flow_error_set(error, EINVAL,
4572 : : RTE_FLOW_ERROR_TYPE_ACTION,
4573 : : NULL, "invalid empty data");
4574 [ # # ]: 0 : for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
4575 : 0 : len = flow_dv_get_item_hdr_len(items->type);
4576 [ # # ]: 0 : if (len + temp_size > MLX5_ENCAP_MAX_LEN)
4577 : 0 : return rte_flow_error_set(error, EINVAL,
4578 : : RTE_FLOW_ERROR_TYPE_ACTION,
4579 : 0 : (void *)items->type,
4580 : : "items total size is too big"
4581 : : " for encap action");
4582 [ # # ]: 0 : if (items->spec)
4583 [ # # ]: 0 : rte_memcpy(&buf[temp_size], items->spec, len);
4584 [ # # # # : 0 : switch (items->type) {
# # # # #
# ]
4585 : 0 : case RTE_FLOW_ITEM_TYPE_ETH:
4586 : 0 : eth = (struct rte_ether_hdr *)&buf[temp_size];
4587 : 0 : break;
4588 : 0 : case RTE_FLOW_ITEM_TYPE_VLAN:
4589 : 0 : vlan = (struct rte_vlan_hdr *)&buf[temp_size];
4590 [ # # ]: 0 : if (!eth)
4591 : 0 : return rte_flow_error_set(error, EINVAL,
4592 : : RTE_FLOW_ERROR_TYPE_ACTION,
4593 : : (void *)items->type,
4594 : : "eth header not found");
4595 [ # # ]: 0 : if (!eth->ether_type)
4596 : 0 : eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_VLAN);
4597 : : break;
4598 : 0 : case RTE_FLOW_ITEM_TYPE_IPV4:
4599 : 0 : ipv4 = (struct rte_ipv4_hdr *)&buf[temp_size];
4600 [ # # ]: 0 : if (!vlan && !eth)
4601 : 0 : return rte_flow_error_set(error, EINVAL,
4602 : : RTE_FLOW_ERROR_TYPE_ACTION,
4603 : : (void *)items->type,
4604 : : "neither eth nor vlan"
4605 : : " header found");
4606 [ # # # # ]: 0 : if (vlan && !vlan->eth_proto)
4607 : 0 : vlan->eth_proto = RTE_BE16(RTE_ETHER_TYPE_IPV4);
4608 [ # # # # ]: 0 : else if (eth && !eth->ether_type)
4609 : 0 : eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_IPV4);
4610 [ # # ]: 0 : if (!ipv4->version_ihl)
4611 : 0 : ipv4->version_ihl = MLX5_ENCAP_IPV4_VERSION |
4612 : : MLX5_ENCAP_IPV4_IHL_MIN;
4613 [ # # ]: 0 : if (!ipv4->time_to_live)
4614 : 0 : ipv4->time_to_live = MLX5_ENCAP_IPV4_TTL_DEF;
4615 : : break;
4616 : 0 : case RTE_FLOW_ITEM_TYPE_IPV6:
4617 : 0 : ipv6 = (struct rte_ipv6_hdr *)&buf[temp_size];
4618 [ # # ]: 0 : if (!vlan && !eth)
4619 : 0 : return rte_flow_error_set(error, EINVAL,
4620 : : RTE_FLOW_ERROR_TYPE_ACTION,
4621 : : (void *)items->type,
4622 : : "neither eth nor vlan"
4623 : : " header found");
4624 [ # # # # ]: 0 : if (vlan && !vlan->eth_proto)
4625 : 0 : vlan->eth_proto = RTE_BE16(RTE_ETHER_TYPE_IPV6);
4626 [ # # # # ]: 0 : else if (eth && !eth->ether_type)
4627 : 0 : eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_IPV6);
4628 [ # # ]: 0 : if (!ipv6->vtc_flow)
4629 : 0 : ipv6->vtc_flow =
4630 : : RTE_BE32(MLX5_ENCAP_IPV6_VTC_FLOW);
4631 [ # # ]: 0 : if (!ipv6->hop_limits)
4632 : 0 : ipv6->hop_limits = MLX5_ENCAP_IPV6_HOP_LIMIT;
4633 : : break;
4634 : 0 : case RTE_FLOW_ITEM_TYPE_UDP:
4635 : 0 : udp = (struct rte_udp_hdr *)&buf[temp_size];
4636 [ # # ]: 0 : if (!ipv4 && !ipv6)
4637 : 0 : return rte_flow_error_set(error, EINVAL,
4638 : : RTE_FLOW_ERROR_TYPE_ACTION,
4639 : : (void *)items->type,
4640 : : "ip header not found");
4641 [ # # # # ]: 0 : if (ipv4 && !ipv4->next_proto_id)
4642 : 0 : ipv4->next_proto_id = IPPROTO_UDP;
4643 [ # # # # ]: 0 : else if (ipv6 && !ipv6->proto)
4644 : 0 : ipv6->proto = IPPROTO_UDP;
4645 : : break;
4646 : 0 : case RTE_FLOW_ITEM_TYPE_VXLAN:
4647 : 0 : vxlan = (struct rte_vxlan_hdr *)&buf[temp_size];
4648 [ # # ]: 0 : if (!udp)
4649 : 0 : return rte_flow_error_set(error, EINVAL,
4650 : : RTE_FLOW_ERROR_TYPE_ACTION,
4651 : : (void *)items->type,
4652 : : "udp header not found");
4653 [ # # ]: 0 : if (!udp->dst_port)
4654 : 0 : udp->dst_port = RTE_BE16(MLX5_UDP_PORT_VXLAN);
4655 [ # # ]: 0 : if (!vxlan->vx_flags)
4656 : 0 : vxlan->vx_flags =
4657 : : RTE_BE32(MLX5_ENCAP_VXLAN_FLAGS);
4658 : : break;
4659 : 0 : case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
4660 : 0 : vxlan_gpe = (struct rte_vxlan_gpe_hdr *)&buf[temp_size];
4661 [ # # ]: 0 : if (!udp)
4662 : 0 : return rte_flow_error_set(error, EINVAL,
4663 : : RTE_FLOW_ERROR_TYPE_ACTION,
4664 : : (void *)items->type,
4665 : : "udp header not found");
4666 [ # # ]: 0 : if (!vxlan_gpe->proto)
4667 : 0 : return rte_flow_error_set(error, EINVAL,
4668 : : RTE_FLOW_ERROR_TYPE_ACTION,
4669 : : (void *)items->type,
4670 : : "next protocol not found");
4671 [ # # ]: 0 : if (!udp->dst_port)
4672 : 0 : udp->dst_port =
4673 : : RTE_BE16(MLX5_UDP_PORT_VXLAN_GPE);
4674 [ # # ]: 0 : if (!vxlan_gpe->vx_flags)
4675 : 0 : vxlan_gpe->vx_flags =
4676 : : MLX5_ENCAP_VXLAN_GPE_FLAGS;
4677 : : break;
4678 : 0 : case RTE_FLOW_ITEM_TYPE_GRE:
4679 : : case RTE_FLOW_ITEM_TYPE_NVGRE:
4680 : 0 : gre = (struct rte_gre_hdr *)&buf[temp_size];
4681 [ # # ]: 0 : if (!gre->proto)
4682 : 0 : return rte_flow_error_set(error, EINVAL,
4683 : : RTE_FLOW_ERROR_TYPE_ACTION,
4684 : 0 : (void *)items->type,
4685 : : "next protocol not found");
4686 [ # # ]: 0 : if (!ipv4 && !ipv6)
4687 : 0 : return rte_flow_error_set(error, EINVAL,
4688 : : RTE_FLOW_ERROR_TYPE_ACTION,
4689 : 0 : (void *)items->type,
4690 : : "ip header not found");
4691 [ # # # # ]: 0 : if (ipv4 && !ipv4->next_proto_id)
4692 : 0 : ipv4->next_proto_id = IPPROTO_GRE;
4693 [ # # # # ]: 0 : else if (ipv6 && !ipv6->proto)
4694 : 0 : ipv6->proto = IPPROTO_GRE;
4695 : : break;
4696 : : case RTE_FLOW_ITEM_TYPE_VOID:
4697 : : break;
4698 : 0 : default:
4699 : 0 : return rte_flow_error_set(error, EINVAL,
4700 : : RTE_FLOW_ERROR_TYPE_ACTION,
4701 : 0 : (void *)items->type,
4702 : : "unsupported item type");
4703 : : break;
4704 : : }
4705 : : temp_size += len;
4706 : : }
4707 : 0 : *size = temp_size;
4708 : 0 : return 0;
4709 : : }
4710 : :
4711 : : static int
4712 : 0 : flow_dv_zero_encap_udp_csum(void *data, struct rte_flow_error *error)
4713 : : {
4714 : : struct rte_ether_hdr *eth = NULL;
4715 : : struct rte_vlan_hdr *vlan = NULL;
4716 : : struct rte_ipv4_hdr *ipv4 = NULL;
4717 : : struct rte_ipv6_hdr *ipv6 = NULL;
4718 : : struct rte_udp_hdr *udp = NULL;
4719 : : char *next_hdr;
4720 : : uint16_t proto;
4721 : :
4722 : : eth = (struct rte_ether_hdr *)data;
4723 : 0 : next_hdr = (char *)(eth + 1);
4724 : 0 : proto = RTE_BE16(eth->ether_type);
4725 : :
4726 : : /* VLAN skipping */
4727 [ # # ]: 0 : while (proto == RTE_ETHER_TYPE_VLAN || proto == RTE_ETHER_TYPE_QINQ) {
4728 : : vlan = (struct rte_vlan_hdr *)next_hdr;
4729 : 0 : proto = RTE_BE16(vlan->eth_proto);
4730 : 0 : next_hdr += sizeof(struct rte_vlan_hdr);
4731 : : }
4732 : :
4733 : : /* non IPv4/IPv6 header. not supported */
4734 [ # # ]: 0 : if (proto != RTE_ETHER_TYPE_IPV4 && proto != RTE_ETHER_TYPE_IPV6) {
4735 : 0 : return rte_flow_error_set(error, ENOTSUP,
4736 : : RTE_FLOW_ERROR_TYPE_ACTION,
4737 : : NULL, "Cannot offload non IPv4/IPv6");
4738 : : }
4739 : :
4740 [ # # ]: 0 : if (proto == RTE_ETHER_TYPE_IPV4) {
4741 : : ipv4 = (struct rte_ipv4_hdr *)next_hdr;
4742 : : /* ignore non UDP */
4743 [ # # ]: 0 : if (ipv4->next_proto_id != IPPROTO_UDP)
4744 : : return 0;
4745 : 0 : udp = (struct rte_udp_hdr *)(ipv4 + 1);
4746 : : } else {
4747 : : ipv6 = (struct rte_ipv6_hdr *)next_hdr;
4748 : : /* ignore non UDP */
4749 [ # # ]: 0 : if (ipv6->proto != IPPROTO_UDP)
4750 : : return 0;
4751 : 0 : udp = (struct rte_udp_hdr *)(ipv6 + 1);
4752 : : }
4753 : :
4754 : 0 : udp->dgram_cksum = 0;
4755 : :
4756 : 0 : return 0;
4757 : : }
4758 : :
4759 : : /**
4760 : : * Convert L2 encap action to DV specification.
4761 : : *
4762 : : * @param[in] dev
4763 : : * Pointer to rte_eth_dev structure.
4764 : : * @param[in] action
4765 : : * Pointer to action structure.
4766 : : * @param[in, out] dev_flow
4767 : : * Pointer to the mlx5_flow.
4768 : : * @param[in] transfer
4769 : : * Mark if the flow is E-Switch flow.
4770 : : * @param[out] error
4771 : : * Pointer to the error structure.
4772 : : *
4773 : : * @return
4774 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
4775 : : */
4776 : : static int
4777 : 0 : flow_dv_create_action_l2_encap(struct rte_eth_dev *dev,
4778 : : const struct rte_flow_action *action,
4779 : : struct mlx5_flow *dev_flow,
4780 : : uint8_t transfer,
4781 : : struct rte_flow_error *error)
4782 : : {
4783 : : const struct rte_flow_item *encap_data;
4784 : : const struct rte_flow_action_raw_encap *raw_encap_data;
4785 [ # # ]: 0 : struct mlx5_flow_dv_encap_decap_resource res = {
4786 : : .reformat_type =
4787 : : MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TO_L2_TUNNEL,
4788 : : .ft_type = transfer ? MLX5DV_FLOW_TABLE_TYPE_FDB :
4789 : : MLX5DV_FLOW_TABLE_TYPE_NIC_TX,
4790 : : };
4791 : :
4792 [ # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
4793 : 0 : raw_encap_data =
4794 : : (const struct rte_flow_action_raw_encap *)action->conf;
4795 : 0 : res.size = raw_encap_data->size;
4796 : 0 : memcpy(res.buf, raw_encap_data->data, res.size);
4797 : : } else {
4798 [ # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP)
4799 : 0 : encap_data =
4800 : : ((const struct rte_flow_action_vxlan_encap *)
4801 : 0 : action->conf)->definition;
4802 : : else
4803 : 0 : encap_data =
4804 : : ((const struct rte_flow_action_nvgre_encap *)
4805 : 0 : action->conf)->definition;
4806 [ # # ]: 0 : if (flow_dv_convert_encap_data(encap_data, res.buf,
4807 : : &res.size, error))
4808 : 0 : return -rte_errno;
4809 : : }
4810 [ # # ]: 0 : if (flow_dv_zero_encap_udp_csum(res.buf, error))
4811 : 0 : return -rte_errno;
4812 [ # # ]: 0 : if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
4813 : 0 : return rte_flow_error_set(error, EINVAL,
4814 : : RTE_FLOW_ERROR_TYPE_ACTION,
4815 : : NULL, "can't create L2 encap action");
4816 : : return 0;
4817 : : }
4818 : :
4819 : : /**
4820 : : * Convert L2 decap action to DV specification.
4821 : : *
4822 : : * @param[in] dev
4823 : : * Pointer to rte_eth_dev structure.
4824 : : * @param[in, out] dev_flow
4825 : : * Pointer to the mlx5_flow.
4826 : : * @param[in] transfer
4827 : : * Mark if the flow is E-Switch flow.
4828 : : * @param[out] error
4829 : : * Pointer to the error structure.
4830 : : *
4831 : : * @return
4832 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
4833 : : */
4834 : : static int
4835 : 0 : flow_dv_create_action_l2_decap(struct rte_eth_dev *dev,
4836 : : struct mlx5_flow *dev_flow,
4837 : : uint8_t transfer,
4838 : : struct rte_flow_error *error)
4839 : : {
4840 [ # # ]: 0 : struct mlx5_flow_dv_encap_decap_resource res = {
4841 : : .size = 0,
4842 : : .reformat_type =
4843 : : MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TUNNEL_TO_L2,
4844 : : .ft_type = transfer ? MLX5DV_FLOW_TABLE_TYPE_FDB :
4845 : : MLX5DV_FLOW_TABLE_TYPE_NIC_RX,
4846 : : };
4847 : :
4848 [ # # ]: 0 : if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
4849 : 0 : return rte_flow_error_set(error, EINVAL,
4850 : : RTE_FLOW_ERROR_TYPE_ACTION,
4851 : : NULL, "can't create L2 decap action");
4852 : : return 0;
4853 : : }
4854 : :
4855 : : /**
4856 : : * Convert raw decap/encap (L3 tunnel) action to DV specification.
4857 : : *
4858 : : * @param[in] dev
4859 : : * Pointer to rte_eth_dev structure.
4860 : : * @param[in] action
4861 : : * Pointer to action structure.
4862 : : * @param[in, out] dev_flow
4863 : : * Pointer to the mlx5_flow.
4864 : : * @param[in] attr
4865 : : * Pointer to the flow attributes.
4866 : : * @param[out] error
4867 : : * Pointer to the error structure.
4868 : : *
4869 : : * @return
4870 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
4871 : : */
4872 : : static int
4873 [ # # ]: 0 : flow_dv_create_action_raw_encap(struct rte_eth_dev *dev,
4874 : : const struct rte_flow_action *action,
4875 : : struct mlx5_flow *dev_flow,
4876 : : const struct rte_flow_attr *attr,
4877 : : struct rte_flow_error *error)
4878 : : {
4879 : : const struct rte_flow_action_raw_encap *encap_data;
4880 : : struct mlx5_flow_dv_encap_decap_resource res;
4881 : :
4882 : : memset(&res, 0, sizeof(res));
4883 : 0 : encap_data = (const struct rte_flow_action_raw_encap *)action->conf;
4884 : 0 : res.size = encap_data->size;
4885 [ # # ]: 0 : memcpy(res.buf, encap_data->data, res.size);
4886 [ # # ]: 0 : res.reformat_type = res.size < MLX5_ENCAPSULATION_DECISION_SIZE ?
4887 : : MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L3_TUNNEL_TO_L2 :
4888 : : MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TO_L3_TUNNEL;
4889 [ # # ]: 0 : if (attr->transfer)
4890 : 0 : res.ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
4891 : : else
4892 : 0 : res.ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
4893 : : MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
4894 [ # # ]: 0 : if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
4895 : 0 : return rte_flow_error_set(error, EINVAL,
4896 : : RTE_FLOW_ERROR_TYPE_ACTION,
4897 : : NULL, "can't create encap action");
4898 : : return 0;
4899 : : }
4900 : :
4901 : : /**
4902 : : * Create action push VLAN.
4903 : : *
4904 : : * @param[in] dev
4905 : : * Pointer to rte_eth_dev structure.
4906 : : * @param[in] attr
4907 : : * Pointer to the flow attributes.
4908 : : * @param[in] vlan
4909 : : * Pointer to the vlan to push to the Ethernet header.
4910 : : * @param[in, out] dev_flow
4911 : : * Pointer to the mlx5_flow.
4912 : : * @param[out] error
4913 : : * Pointer to the error structure.
4914 : : *
4915 : : * @return
4916 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
4917 : : */
4918 : : static int
4919 [ # # ]: 0 : flow_dv_create_action_push_vlan(struct rte_eth_dev *dev,
4920 : : const struct rte_flow_attr *attr,
4921 : : const struct rte_vlan_hdr *vlan,
4922 : : struct mlx5_flow *dev_flow,
4923 : : struct rte_flow_error *error)
4924 : : {
4925 : : struct mlx5_flow_dv_push_vlan_action_resource res;
4926 : :
4927 : : memset(&res, 0, sizeof(res));
4928 : 0 : res.vlan_tag =
4929 [ # # ]: 0 : rte_cpu_to_be_32(((uint32_t)vlan->eth_proto) << 16 |
4930 : : vlan->vlan_tci);
4931 [ # # ]: 0 : if (attr->transfer)
4932 : 0 : res.ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
4933 : : else
4934 : 0 : res.ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
4935 : : MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
4936 : 0 : return flow_dv_push_vlan_action_resource_register
4937 : : (dev, &res, dev_flow, error);
4938 : : }
4939 : :
4940 : : /**
4941 : : * Validate the modify-header actions.
4942 : : *
4943 : : * @param[in] action_flags
4944 : : * Holds the actions detected until now.
4945 : : * @param[in] action
4946 : : * Pointer to the modify action.
4947 : : * @param[out] error
4948 : : * Pointer to error structure.
4949 : : *
4950 : : * @return
4951 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
4952 : : */
4953 : : static int
4954 : 0 : flow_dv_validate_action_modify_hdr(const uint64_t action_flags,
4955 : : const struct rte_flow_action *action,
4956 : : struct rte_flow_error *error)
4957 : : {
4958 [ # # # # ]: 0 : if (action->type != RTE_FLOW_ACTION_TYPE_DEC_TTL && !action->conf)
4959 : 0 : return rte_flow_error_set(error, EINVAL,
4960 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
4961 : : NULL, "action configuration not set");
4962 : :
4963 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_ENCAP)
4964 : 0 : return rte_flow_error_set(error, EINVAL,
4965 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
4966 : : "can't have encap action before"
4967 : : " modify action");
4968 : : return 0;
4969 : : }
4970 : :
4971 : : /**
4972 : : * Validate the modify-header MAC address actions.
4973 : : *
4974 : : * @param[in] action_flags
4975 : : * Holds the actions detected until now.
4976 : : * @param[in] action
4977 : : * Pointer to the modify action.
4978 : : * @param[in] item_flags
4979 : : * Holds the items detected.
4980 : : * @param[out] error
4981 : : * Pointer to error structure.
4982 : : *
4983 : : * @return
4984 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
4985 : : */
4986 : : static int
4987 : 0 : flow_dv_validate_action_modify_mac(const uint64_t action_flags,
4988 : : const struct rte_flow_action *action,
4989 : : const uint64_t item_flags,
4990 : : struct rte_flow_error *error)
4991 : : {
4992 : : int ret = 0;
4993 : :
4994 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4995 [ # # ]: 0 : if (!ret) {
4996 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_L2))
4997 : 0 : return rte_flow_error_set(error, EINVAL,
4998 : : RTE_FLOW_ERROR_TYPE_ACTION,
4999 : : NULL,
5000 : : "no L2 item in pattern");
5001 : : }
5002 : : return ret;
5003 : : }
5004 : :
5005 : : /**
5006 : : * Validate the modify-header IPv4 address actions.
5007 : : *
5008 : : * @param[in] action_flags
5009 : : * Holds the actions detected until now.
5010 : : * @param[in] action
5011 : : * Pointer to the modify action.
5012 : : * @param[in] item_flags
5013 : : * Holds the items detected.
5014 : : * @param[out] error
5015 : : * Pointer to error structure.
5016 : : *
5017 : : * @return
5018 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5019 : : */
5020 : : static int
5021 : 0 : flow_dv_validate_action_modify_ipv4(const uint64_t action_flags,
5022 : : const struct rte_flow_action *action,
5023 : : const uint64_t item_flags,
5024 : : struct rte_flow_error *error)
5025 : : {
5026 : : int ret = 0;
5027 : : uint64_t layer;
5028 : :
5029 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5030 [ # # ]: 0 : if (!ret) {
5031 : 0 : layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
5032 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_L3_IPV4 :
5033 : : MLX5_FLOW_LAYER_OUTER_L3_IPV4;
5034 [ # # ]: 0 : if (!(item_flags & layer))
5035 : 0 : return rte_flow_error_set(error, EINVAL,
5036 : : RTE_FLOW_ERROR_TYPE_ACTION,
5037 : : NULL,
5038 : : "no ipv4 item in pattern");
5039 : : }
5040 : : return ret;
5041 : : }
5042 : :
5043 : : /**
5044 : : * Validate the modify-header IPv6 address actions.
5045 : : *
5046 : : * @param[in] action_flags
5047 : : * Holds the actions detected until now.
5048 : : * @param[in] action
5049 : : * Pointer to the modify action.
5050 : : * @param[in] item_flags
5051 : : * Holds the items detected.
5052 : : * @param[out] error
5053 : : * Pointer to error structure.
5054 : : *
5055 : : * @return
5056 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5057 : : */
5058 : : static int
5059 : 0 : flow_dv_validate_action_modify_ipv6(const uint64_t action_flags,
5060 : : const struct rte_flow_action *action,
5061 : : const uint64_t item_flags,
5062 : : struct rte_flow_error *error)
5063 : : {
5064 : : int ret = 0;
5065 : : uint64_t layer;
5066 : :
5067 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5068 [ # # ]: 0 : if (!ret) {
5069 : 0 : layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
5070 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_L3_IPV6 :
5071 : : MLX5_FLOW_LAYER_OUTER_L3_IPV6;
5072 [ # # ]: 0 : if (!(item_flags & layer))
5073 : 0 : return rte_flow_error_set(error, EINVAL,
5074 : : RTE_FLOW_ERROR_TYPE_ACTION,
5075 : : NULL,
5076 : : "no ipv6 item in pattern");
5077 : : }
5078 : : return ret;
5079 : : }
5080 : :
5081 : : /**
5082 : : * Validate the modify-header TP actions.
5083 : : *
5084 : : * @param[in] action_flags
5085 : : * Holds the actions detected until now.
5086 : : * @param[in] action
5087 : : * Pointer to the modify action.
5088 : : * @param[in] item_flags
5089 : : * Holds the items detected.
5090 : : * @param[out] error
5091 : : * Pointer to error structure.
5092 : : *
5093 : : * @return
5094 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5095 : : */
5096 : : static int
5097 : 0 : flow_dv_validate_action_modify_tp(const uint64_t action_flags,
5098 : : const struct rte_flow_action *action,
5099 : : const uint64_t item_flags,
5100 : : struct rte_flow_error *error)
5101 : : {
5102 : : int ret = 0;
5103 : : uint64_t layer;
5104 : :
5105 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5106 [ # # ]: 0 : if (!ret) {
5107 : 0 : layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
5108 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_L4 :
5109 : : MLX5_FLOW_LAYER_OUTER_L4;
5110 [ # # ]: 0 : if (!(item_flags & layer))
5111 : 0 : return rte_flow_error_set(error, EINVAL,
5112 : : RTE_FLOW_ERROR_TYPE_ACTION,
5113 : : NULL, "no transport layer "
5114 : : "in pattern");
5115 : : }
5116 : : return ret;
5117 : : }
5118 : :
5119 : : /**
5120 : : * Validate the modify-header actions of increment/decrement
5121 : : * TCP Sequence-number.
5122 : : *
5123 : : * @param[in] action_flags
5124 : : * Holds the actions detected until now.
5125 : : * @param[in] action
5126 : : * Pointer to the modify action.
5127 : : * @param[in] item_flags
5128 : : * Holds the items detected.
5129 : : * @param[out] error
5130 : : * Pointer to error structure.
5131 : : *
5132 : : * @return
5133 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5134 : : */
5135 : : static int
5136 : 0 : flow_dv_validate_action_modify_tcp_seq(const uint64_t action_flags,
5137 : : const struct rte_flow_action *action,
5138 : : const uint64_t item_flags,
5139 : : struct rte_flow_error *error)
5140 : : {
5141 : : int ret = 0;
5142 : : uint64_t layer;
5143 : :
5144 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5145 [ # # ]: 0 : if (!ret) {
5146 : 0 : layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
5147 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_L4_TCP :
5148 : : MLX5_FLOW_LAYER_OUTER_L4_TCP;
5149 [ # # ]: 0 : if (!(item_flags & layer))
5150 : 0 : return rte_flow_error_set(error, EINVAL,
5151 : : RTE_FLOW_ERROR_TYPE_ACTION,
5152 : : NULL, "no TCP item in"
5153 : : " pattern");
5154 [ # # ]: 0 : if ((action->type == RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ &&
5155 [ # # # # ]: 0 : (action_flags & MLX5_FLOW_ACTION_DEC_TCP_SEQ)) ||
5156 : 0 : (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ &&
5157 [ # # ]: 0 : (action_flags & MLX5_FLOW_ACTION_INC_TCP_SEQ)))
5158 : 0 : return rte_flow_error_set(error, EINVAL,
5159 : : RTE_FLOW_ERROR_TYPE_ACTION,
5160 : : NULL,
5161 : : "cannot decrease and increase"
5162 : : " TCP sequence number"
5163 : : " at the same time");
5164 : : }
5165 : : return ret;
5166 : : }
5167 : :
5168 : : /**
5169 : : * Validate the modify-header actions of increment/decrement
5170 : : * TCP Acknowledgment number.
5171 : : *
5172 : : * @param[in] action_flags
5173 : : * Holds the actions detected until now.
5174 : : * @param[in] action
5175 : : * Pointer to the modify action.
5176 : : * @param[in] item_flags
5177 : : * Holds the items detected.
5178 : : * @param[out] error
5179 : : * Pointer to error structure.
5180 : : *
5181 : : * @return
5182 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5183 : : */
5184 : : static int
5185 : 0 : flow_dv_validate_action_modify_tcp_ack(const uint64_t action_flags,
5186 : : const struct rte_flow_action *action,
5187 : : const uint64_t item_flags,
5188 : : struct rte_flow_error *error)
5189 : : {
5190 : : int ret = 0;
5191 : : uint64_t layer;
5192 : :
5193 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5194 [ # # ]: 0 : if (!ret) {
5195 : 0 : layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
5196 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_L4_TCP :
5197 : : MLX5_FLOW_LAYER_OUTER_L4_TCP;
5198 [ # # ]: 0 : if (!(item_flags & layer))
5199 : 0 : return rte_flow_error_set(error, EINVAL,
5200 : : RTE_FLOW_ERROR_TYPE_ACTION,
5201 : : NULL, "no TCP item in"
5202 : : " pattern");
5203 [ # # ]: 0 : if ((action->type == RTE_FLOW_ACTION_TYPE_INC_TCP_ACK &&
5204 [ # # # # ]: 0 : (action_flags & MLX5_FLOW_ACTION_DEC_TCP_ACK)) ||
5205 : 0 : (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK &&
5206 [ # # ]: 0 : (action_flags & MLX5_FLOW_ACTION_INC_TCP_ACK)))
5207 : 0 : return rte_flow_error_set(error, EINVAL,
5208 : : RTE_FLOW_ERROR_TYPE_ACTION,
5209 : : NULL,
5210 : : "cannot decrease and increase"
5211 : : " TCP acknowledgment number"
5212 : : " at the same time");
5213 : : }
5214 : : return ret;
5215 : : }
5216 : :
5217 : : /**
5218 : : * Validate the modify-header TTL actions.
5219 : : *
5220 : : * @param[in] action_flags
5221 : : * Holds the actions detected until now.
5222 : : * @param[in] action
5223 : : * Pointer to the modify action.
5224 : : * @param[in] item_flags
5225 : : * Holds the items detected.
5226 : : * @param[out] error
5227 : : * Pointer to error structure.
5228 : : *
5229 : : * @return
5230 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5231 : : */
5232 : : static int
5233 : 0 : flow_dv_validate_action_modify_ttl(const uint64_t action_flags,
5234 : : const struct rte_flow_action *action,
5235 : : const uint64_t item_flags,
5236 : : struct rte_flow_error *error)
5237 : : {
5238 : : int ret = 0;
5239 : : uint64_t layer;
5240 : :
5241 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5242 [ # # ]: 0 : if (!ret) {
5243 : 0 : layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
5244 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_L3 :
5245 : : MLX5_FLOW_LAYER_OUTER_L3;
5246 [ # # ]: 0 : if (!(item_flags & layer))
5247 : 0 : return rte_flow_error_set(error, EINVAL,
5248 : : RTE_FLOW_ERROR_TYPE_ACTION,
5249 : : NULL,
5250 : : "no IP protocol in pattern");
5251 : : }
5252 : : return ret;
5253 : : }
5254 : :
5255 : : /**
5256 : : * Validate the generic modify field actions.
5257 : : * @param[in] dev
5258 : : * Pointer to the rte_eth_dev structure.
5259 : : * @param[in] action_flags
5260 : : * Holds the actions detected until now.
5261 : : * @param[in] action
5262 : : * Pointer to the modify action.
5263 : : * @param[in] attr
5264 : : * Pointer to the flow attributes.
5265 : : * @param root
5266 : : * Whether action is on root table.
5267 : : * @param[out] error
5268 : : * Pointer to error structure.
5269 : : *
5270 : : * @return
5271 : : * Number of header fields to modify (0 or more) on success,
5272 : : * a negative errno value otherwise and rte_errno is set.
5273 : : */
5274 : : static int
5275 : 0 : flow_dv_validate_action_modify_field(struct rte_eth_dev *dev,
5276 : : const uint64_t action_flags,
5277 : : const struct rte_flow_action *action,
5278 : : const struct rte_flow_attr *attr,
5279 : : bool root,
5280 : : struct rte_flow_error *error)
5281 : : {
5282 : : int ret = 0;
5283 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5284 : 0 : struct mlx5_sh_config *config = &priv->sh->config;
5285 : 0 : struct mlx5_hca_attr *hca_attr = &priv->sh->cdev->config.hca_attr;
5286 : 0 : const struct rte_flow_action_modify_field *conf = action->conf;
5287 : 0 : const struct rte_flow_action_modify_data *src_data = &conf->src;
5288 : 0 : const struct rte_flow_action_modify_data *dst_data = &conf->dst;
5289 : 0 : uint32_t dst_width, src_width, width = conf->width;
5290 : :
5291 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5292 [ # # ]: 0 : if (ret)
5293 : : return ret;
5294 [ # # ]: 0 : if (src_data->field == RTE_FLOW_FIELD_FLEX_ITEM ||
5295 [ # # ]: 0 : dst_data->field == RTE_FLOW_FIELD_FLEX_ITEM)
5296 : 0 : return rte_flow_error_set(error, ENOTSUP,
5297 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5298 : : "flex item fields modification"
5299 : : " is not supported");
5300 : 0 : dst_width = mlx5_flow_item_field_width(dev, dst_data->field,
5301 : : -1, attr, error);
5302 : 0 : src_width = mlx5_flow_item_field_width(dev, src_data->field,
5303 : : dst_width, attr, error);
5304 [ # # ]: 0 : if (width == 0)
5305 : 0 : return rte_flow_error_set(error, EINVAL,
5306 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5307 : : "no bits are requested to be modified");
5308 [ # # ]: 0 : else if (width > dst_width || width > src_width)
5309 : 0 : return rte_flow_error_set(error, EINVAL,
5310 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5311 : : "cannot modify more bits than"
5312 : : " the width of a field");
5313 [ # # ]: 0 : if (dst_data->field != RTE_FLOW_FIELD_VALUE &&
5314 : : dst_data->field != RTE_FLOW_FIELD_POINTER) {
5315 [ # # ]: 0 : if (dst_data->offset + width > dst_width)
5316 : 0 : return rte_flow_error_set(error, EINVAL,
5317 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5318 : : "destination offset is too big");
5319 : 0 : ret = flow_validate_modify_field_level(dst_data, error);
5320 [ # # ]: 0 : if (ret)
5321 : : return ret;
5322 [ # # ]: 0 : if (dst_data->tag_index &&
5323 [ # # ]: 0 : !flow_modify_field_support_tag_array(dst_data->field))
5324 : 0 : return rte_flow_error_set(error, EINVAL,
5325 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5326 : : "destination tag index is not supported");
5327 [ # # ]: 0 : if (dst_data->class_id)
5328 : 0 : return rte_flow_error_set(error, EINVAL,
5329 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5330 : : "destination class ID is not supported");
5331 : : }
5332 [ # # ]: 0 : if (src_data->field != RTE_FLOW_FIELD_VALUE &&
5333 : : src_data->field != RTE_FLOW_FIELD_POINTER) {
5334 [ # # ]: 0 : if (root)
5335 : 0 : return rte_flow_error_set(error, ENOTSUP,
5336 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5337 : : "modify field action is not"
5338 : : " supported for group 0");
5339 [ # # ]: 0 : if (src_data->offset + width > src_width)
5340 : 0 : return rte_flow_error_set(error, EINVAL,
5341 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5342 : : "source offset is too big");
5343 : 0 : ret = flow_validate_modify_field_level(src_data, error);
5344 [ # # ]: 0 : if (ret)
5345 : : return ret;
5346 [ # # ]: 0 : if (src_data->tag_index &&
5347 [ # # ]: 0 : !flow_modify_field_support_tag_array(src_data->field))
5348 : 0 : return rte_flow_error_set(error, EINVAL,
5349 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5350 : : "source tag index is not supported");
5351 [ # # ]: 0 : if (src_data->class_id)
5352 : 0 : return rte_flow_error_set(error, EINVAL,
5353 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5354 : : "source class ID is not supported");
5355 : : }
5356 [ # # ]: 0 : if ((dst_data->field == src_data->field) &&
5357 [ # # ]: 0 : (dst_data->level == src_data->level))
5358 : 0 : return rte_flow_error_set(error, EINVAL,
5359 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5360 : : "source and destination fields"
5361 : : " cannot be the same");
5362 : 0 : if (dst_data->field == RTE_FLOW_FIELD_VALUE ||
5363 [ # # ]: 0 : dst_data->field == RTE_FLOW_FIELD_POINTER ||
5364 : : dst_data->field == RTE_FLOW_FIELD_MARK)
5365 : 0 : return rte_flow_error_set(error, EINVAL,
5366 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5367 : : "mark, immediate value or a pointer to it"
5368 : : " cannot be used as a destination");
5369 [ # # # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_START ||
5370 : : src_data->field == RTE_FLOW_FIELD_START)
5371 : 0 : return rte_flow_error_set(error, ENOTSUP,
5372 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5373 : : "modifications of an arbitrary"
5374 : : " place in a packet is not supported");
5375 [ # # # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_VLAN_TYPE ||
5376 : : src_data->field == RTE_FLOW_FIELD_VLAN_TYPE)
5377 : 0 : return rte_flow_error_set(error, ENOTSUP,
5378 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5379 : : "modifications of the 802.1Q Tag"
5380 : : " Identifier is not supported");
5381 [ # # # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_VXLAN_VNI ||
5382 : : src_data->field == RTE_FLOW_FIELD_VXLAN_VNI)
5383 : 0 : return rte_flow_error_set(error, ENOTSUP,
5384 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5385 : : "modifications of the VXLAN Network"
5386 : : " Identifier is not supported");
5387 [ # # # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_GENEVE_VNI ||
5388 : : src_data->field == RTE_FLOW_FIELD_GENEVE_VNI)
5389 : 0 : return rte_flow_error_set(error, ENOTSUP,
5390 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5391 : : "modifications of the GENEVE Network"
5392 : : " Identifier is not supported");
5393 [ # # # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_MPLS ||
5394 : : src_data->field == RTE_FLOW_FIELD_MPLS)
5395 : 0 : return rte_flow_error_set(error, ENOTSUP,
5396 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5397 : : "modifications of the MPLS header "
5398 : : "is not supported");
5399 [ # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_MARK ||
5400 : : src_data->field == RTE_FLOW_FIELD_MARK)
5401 [ # # # # ]: 0 : if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
5402 : 0 : !mlx5_flow_ext_mreg_supported(dev))
5403 : 0 : return rte_flow_error_set(error, ENOTSUP,
5404 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5405 : : "cannot modify mark in legacy mode"
5406 : : " or without extensive registers");
5407 [ # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_META ||
5408 [ # # ]: 0 : src_data->field == RTE_FLOW_FIELD_META) {
5409 [ # # # # ]: 0 : if (config->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
5410 : 0 : !mlx5_flow_ext_mreg_supported(dev))
5411 : 0 : return rte_flow_error_set(error, ENOTSUP,
5412 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5413 : : "cannot modify meta without"
5414 : : " extensive registers support");
5415 : 0 : ret = flow_dv_get_metadata_reg(dev, attr, error);
5416 [ # # ]: 0 : if (ret < 0 || ret == REG_NON)
5417 : 0 : return rte_flow_error_set(error, ENOTSUP,
5418 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5419 : : "cannot modify meta without"
5420 : : " extensive registers available");
5421 : : }
5422 [ # # ]: 0 : if (conf->operation == RTE_FLOW_MODIFY_SUB)
5423 : 0 : return rte_flow_error_set(error, ENOTSUP,
5424 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5425 : : "sub operations are not supported");
5426 [ # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_IPV4_ECN ||
5427 [ # # # # ]: 0 : src_data->field == RTE_FLOW_FIELD_IPV4_ECN ||
5428 [ # # ]: 0 : dst_data->field == RTE_FLOW_FIELD_IPV6_ECN ||
5429 : : src_data->field == RTE_FLOW_FIELD_IPV6_ECN)
5430 [ # # # # ]: 0 : if (!hca_attr->modify_outer_ip_ecn && root)
5431 : 0 : return rte_flow_error_set(error, ENOTSUP,
5432 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5433 : : "modifications of the ECN for current firmware is not supported");
5434 : 0 : return (width / 32) + !!(width % 32);
5435 : : }
5436 : :
5437 : : /**
5438 : : * Validate jump action.
5439 : : *
5440 : : * @param[in] action
5441 : : * Pointer to the jump action.
5442 : : * @param[in] action_flags
5443 : : * Holds the actions detected until now.
5444 : : * @param[in] attributes
5445 : : * Pointer to flow attributes
5446 : : * @param[in] external
5447 : : * Action belongs to flow rule created by request external to PMD.
5448 : : * @param[out] error
5449 : : * Pointer to error structure.
5450 : : *
5451 : : * @return
5452 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5453 : : */
5454 : : static int
5455 : 0 : flow_dv_validate_action_jump(struct rte_eth_dev *dev,
5456 : : const struct mlx5_flow_tunnel *tunnel,
5457 : : const struct rte_flow_action *action,
5458 : : uint64_t action_flags,
5459 : : const struct rte_flow_attr *attributes,
5460 : : bool external, struct rte_flow_error *error)
5461 : : {
5462 : 0 : uint32_t target_group, table = 0;
5463 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5464 : : int ret = 0;
5465 : 0 : struct flow_grp_info grp_info = {
5466 : : .external = !!external,
5467 : 0 : .transfer = !!attributes->transfer,
5468 : 0 : .fdb_def_rule = !!priv->fdb_def_rule,
5469 : : .std_tbl_fix = 0
5470 : : };
5471 [ # # ]: 0 : if (action_flags & (MLX5_FLOW_FATE_ACTIONS |
5472 : : MLX5_FLOW_FATE_ESWITCH_ACTIONS))
5473 : 0 : return rte_flow_error_set(error, EINVAL,
5474 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5475 : : "can't have 2 fate actions in"
5476 : : " same flow");
5477 [ # # ]: 0 : if (!action->conf)
5478 : 0 : return rte_flow_error_set(error, EINVAL,
5479 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
5480 : : NULL, "action configuration not set");
5481 : 0 : target_group =
5482 : : ((const struct rte_flow_action_jump *)action->conf)->group;
5483 : 0 : ret = mlx5_flow_group_to_table(dev, tunnel, target_group, &table,
5484 : : &grp_info, error);
5485 [ # # ]: 0 : if (ret)
5486 : : return ret;
5487 [ # # ]: 0 : if (attributes->group == target_group &&
5488 [ # # ]: 0 : !(action_flags & (MLX5_FLOW_ACTION_TUNNEL_SET |
5489 : : MLX5_FLOW_ACTION_TUNNEL_MATCH)))
5490 : 0 : return rte_flow_error_set(error, EINVAL,
5491 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5492 : : "target group must be other than"
5493 : : " the current flow group");
5494 [ # # ]: 0 : if (table == 0)
5495 : 0 : return rte_flow_error_set(error, EINVAL,
5496 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
5497 : : NULL, "root table shouldn't be destination");
5498 : : return 0;
5499 : : }
5500 : :
5501 : : /*
5502 : : * Validate action PORT_ID / REPRESENTED_PORT.
5503 : : *
5504 : : * @param[in] dev
5505 : : * Pointer to rte_eth_dev structure.
5506 : : * @param[in] action_flags
5507 : : * Bit-fields that holds the actions detected until now.
5508 : : * @param[in] action
5509 : : * PORT_ID / REPRESENTED_PORT action structure.
5510 : : * @param[in] attr
5511 : : * Attributes of flow that includes this action.
5512 : : * @param[out] error
5513 : : * Pointer to error structure.
5514 : : *
5515 : : * @return
5516 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5517 : : */
5518 : : static int
5519 : 0 : flow_dv_validate_action_port_id(struct rte_eth_dev *dev,
5520 : : uint64_t action_flags,
5521 : : const struct rte_flow_action *action,
5522 : : const struct rte_flow_attr *attr,
5523 : : struct rte_flow_error *error)
5524 : : {
5525 : : const struct rte_flow_action_port_id *port_id;
5526 : : const struct rte_flow_action_ethdev *ethdev;
5527 : : struct mlx5_priv *act_priv;
5528 : : struct mlx5_priv *dev_priv;
5529 : : uint16_t port;
5530 : :
5531 [ # # ]: 0 : if (!attr->transfer)
5532 : 0 : return rte_flow_error_set(error, ENOTSUP,
5533 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5534 : : NULL,
5535 : : "port action is valid in transfer"
5536 : : " mode only");
5537 [ # # # # ]: 0 : if (!action || !action->conf)
5538 : 0 : return rte_flow_error_set(error, ENOTSUP,
5539 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
5540 : : NULL,
5541 : : "port action parameters must be"
5542 : : " specified");
5543 [ # # ]: 0 : if (action_flags & (MLX5_FLOW_FATE_ACTIONS |
5544 : : MLX5_FLOW_FATE_ESWITCH_ACTIONS))
5545 : 0 : return rte_flow_error_set(error, EINVAL,
5546 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5547 : : "can have only one fate actions in"
5548 : : " a flow");
5549 : 0 : dev_priv = mlx5_dev_to_eswitch_info(dev);
5550 [ # # ]: 0 : if (!dev_priv)
5551 : 0 : return rte_flow_error_set(error, rte_errno,
5552 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5553 : : NULL,
5554 : : "failed to obtain E-Switch info");
5555 [ # # # ]: 0 : switch (action->type) {
5556 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_ID:
5557 : 0 : port_id = action->conf;
5558 [ # # ]: 0 : port = port_id->original ? dev->data->port_id : port_id->id;
5559 : : break;
5560 : 0 : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
5561 : 0 : ethdev = action->conf;
5562 : 0 : port = ethdev->port_id;
5563 : 0 : break;
5564 : 0 : default:
5565 : : MLX5_ASSERT(false);
5566 : 0 : return rte_flow_error_set
5567 : : (error, EINVAL,
5568 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5569 : : "unknown E-Switch action");
5570 : : }
5571 : 0 : act_priv = mlx5_port_to_eswitch_info(port, false);
5572 [ # # ]: 0 : if (!act_priv)
5573 : 0 : return rte_flow_error_set
5574 : : (error, rte_errno,
5575 : 0 : RTE_FLOW_ERROR_TYPE_ACTION_CONF, action->conf,
5576 : : "failed to obtain E-Switch port id for port");
5577 [ # # ]: 0 : if (act_priv->domain_id != dev_priv->domain_id)
5578 : 0 : return rte_flow_error_set
5579 : : (error, EINVAL,
5580 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5581 : : "port does not belong to"
5582 : : " E-Switch being configured");
5583 : : return 0;
5584 : : }
5585 : :
5586 : : /**
5587 : : * Get the maximum number of modify header actions.
5588 : : *
5589 : : * @param dev
5590 : : * Pointer to rte_eth_dev structure.
5591 : : * @param root
5592 : : * Whether action is on root table.
5593 : : *
5594 : : * @return
5595 : : * Max number of modify header actions device can support.
5596 : : */
5597 : : static inline unsigned int
5598 : : flow_dv_modify_hdr_action_max(struct rte_eth_dev *dev __rte_unused,
5599 : : bool root)
5600 : : {
5601 : : /*
5602 : : * There's no way to directly query the max capacity from FW.
5603 : : * The maximal value on root table should be assumed to be supported.
5604 : : */
5605 [ # # ]: 0 : if (!root)
5606 : : return MLX5_MAX_MODIFY_NUM;
5607 : : else
5608 : 0 : return MLX5_ROOT_TBL_MODIFY_NUM;
5609 : : }
5610 : :
5611 : : /**
5612 : : * Validate the meter action.
5613 : : *
5614 : : * @param[in] dev
5615 : : * Pointer to rte_eth_dev structure.
5616 : : * @param[in] action_flags
5617 : : * Bit-fields that holds the actions detected until now.
5618 : : * @param[in] item_flags
5619 : : * Holds the items detected.
5620 : : * @param[in] action
5621 : : * Pointer to the meter action.
5622 : : * @param[in] attr
5623 : : * Attributes of flow that includes this action.
5624 : : * @param[in] port_id_item
5625 : : * Pointer to item indicating port id.
5626 : : * @param[out] error
5627 : : * Pointer to error structure.
5628 : : *
5629 : : * @return
5630 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5631 : : */
5632 : : static int
5633 : 0 : mlx5_flow_validate_action_meter(struct rte_eth_dev *dev,
5634 : : uint64_t action_flags, uint64_t item_flags,
5635 : : const struct rte_flow_action *action,
5636 : : const struct rte_flow_attr *attr,
5637 : : const struct rte_flow_item *port_id_item,
5638 : : bool *def_policy,
5639 : : struct rte_flow_error *error)
5640 : : {
5641 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5642 : 0 : const struct rte_flow_action_meter *am = action->conf;
5643 : : struct mlx5_flow_meter_info *fm;
5644 : : struct mlx5_flow_meter_policy *mtr_policy;
5645 : 0 : struct mlx5_flow_mtr_mng *mtrmng = priv->sh->mtrmng;
5646 : 0 : uint16_t flow_src_port = priv->representor_id;
5647 : 0 : bool all_ports = false;
5648 : :
5649 [ # # ]: 0 : if (!am)
5650 : 0 : return rte_flow_error_set(error, EINVAL,
5651 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5652 : : "meter action conf is NULL");
5653 : :
5654 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_METER)
5655 : 0 : return rte_flow_error_set(error, ENOTSUP,
5656 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5657 : : "meter chaining not support");
5658 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_JUMP)
5659 : 0 : return rte_flow_error_set(error, ENOTSUP,
5660 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5661 : : "meter with jump not support");
5662 [ # # ]: 0 : if (!priv->mtr_en)
5663 : 0 : return rte_flow_error_set(error, ENOTSUP,
5664 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5665 : : NULL,
5666 : : "meter action not supported");
5667 : 0 : fm = mlx5_flow_meter_find(priv, am->mtr_id, NULL);
5668 [ # # ]: 0 : if (!fm)
5669 : 0 : return rte_flow_error_set(error, EINVAL,
5670 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5671 : : "Meter not found");
5672 : : /* aso meter can always be shared by different domains */
5673 [ # # # # ]: 0 : if (fm->ref_cnt && !priv->sh->meter_aso_en &&
5674 [ # # ]: 0 : !(fm->transfer == attr->transfer ||
5675 [ # # # # ]: 0 : (!fm->ingress && !attr->ingress && attr->egress) ||
5676 [ # # # # ]: 0 : (!fm->egress && !attr->egress && attr->ingress)))
5677 : 0 : return rte_flow_error_set(error, EINVAL,
5678 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5679 : : "Flow attributes domain are either invalid "
5680 : : "or have a domain conflict with current "
5681 : : "meter attributes");
5682 [ # # ]: 0 : if (fm->def_policy) {
5683 [ # # ]: 0 : if (!((attr->transfer &&
5684 [ # # ]: 0 : mtrmng->def_policy[MLX5_MTR_DOMAIN_TRANSFER]) ||
5685 [ # # ]: 0 : (attr->egress &&
5686 [ # # ]: 0 : mtrmng->def_policy[MLX5_MTR_DOMAIN_EGRESS]) ||
5687 [ # # ]: 0 : (attr->ingress &&
5688 [ # # ]: 0 : mtrmng->def_policy[MLX5_MTR_DOMAIN_INGRESS])))
5689 : 0 : return rte_flow_error_set(error, EINVAL,
5690 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5691 : : "Flow attributes domain "
5692 : : "have a conflict with current "
5693 : : "meter domain attributes");
5694 : 0 : *def_policy = true;
5695 : : } else {
5696 : 0 : mtr_policy = mlx5_flow_meter_policy_find(dev,
5697 : : fm->policy_id, NULL);
5698 [ # # ]: 0 : if (!mtr_policy)
5699 : 0 : return rte_flow_error_set(error, EINVAL,
5700 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5701 : : "Invalid policy id for meter ");
5702 [ # # # # ]: 0 : if (!((attr->transfer && mtr_policy->transfer) ||
5703 [ # # # # ]: 0 : (attr->egress && mtr_policy->egress) ||
5704 [ # # # # ]: 0 : (attr->ingress && mtr_policy->ingress)))
5705 : 0 : return rte_flow_error_set(error, EINVAL,
5706 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5707 : : "Flow attributes domain "
5708 : : "have a conflict with current "
5709 : : "meter domain attributes");
5710 [ # # ]: 0 : if (port_id_item) {
5711 [ # # ]: 0 : if (mlx5_flow_get_item_vport_id(dev, port_id_item, &flow_src_port,
5712 : : &all_ports, error))
5713 : 0 : return -rte_errno;
5714 : : }
5715 [ # # ]: 0 : if (attr->transfer) {
5716 : : /* When flow matching all src ports, meter should not have drop count. */
5717 [ # # # # : 0 : if (all_ports && (fm->drop_cnt || mtr_policy->hierarchy_match_port))
# # ]
5718 : 0 : return rte_flow_error_set(error, EINVAL,
5719 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
5720 : : "Meter drop count or "
5721 : : "modify_field/set_tag in meter hierarchy "
5722 : : "not supported when matching all ports.");
5723 [ # # ]: 0 : } else if (mtr_policy->is_rss) {
5724 : : struct mlx5_flow_meter_policy *fp;
5725 : : struct mlx5_meter_policy_action_container *acg;
5726 : : struct mlx5_meter_policy_action_container *acy;
5727 : : const struct rte_flow_action *rss_act;
5728 : : int ret;
5729 : :
5730 : 0 : fp = mlx5_flow_meter_hierarchy_get_final_policy(dev,
5731 : : mtr_policy);
5732 [ # # ]: 0 : if (fp == NULL)
5733 : 0 : return rte_flow_error_set(error, EINVAL,
5734 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5735 : : "Unable to get the final "
5736 : : "policy in the hierarchy");
5737 : : acg = &fp->act_cnt[RTE_COLOR_GREEN];
5738 : : acy = &fp->act_cnt[RTE_COLOR_YELLOW];
5739 : : MLX5_ASSERT(acg->fate_action ==
5740 : : MLX5_FLOW_FATE_SHARED_RSS ||
5741 : : acy->fate_action ==
5742 : : MLX5_FLOW_FATE_SHARED_RSS);
5743 [ # # ]: 0 : if (acg->fate_action == MLX5_FLOW_FATE_SHARED_RSS)
5744 : 0 : rss_act = acg->rss;
5745 : : else
5746 : 0 : rss_act = acy->rss;
5747 : 0 : ret = mlx5_flow_validate_action_rss(rss_act,
5748 : : action_flags, dev, attr,
5749 : : item_flags, error);
5750 [ # # ]: 0 : if (ret)
5751 : : return ret;
5752 : : }
5753 : 0 : *def_policy = false;
5754 : : }
5755 : : return 0;
5756 : : }
5757 : :
5758 : : /**
5759 : : * Validate the age action.
5760 : : *
5761 : : * @param[in] action_flags
5762 : : * Holds the actions detected until now.
5763 : : * @param[in] action
5764 : : * Pointer to the age action.
5765 : : * @param[in] dev
5766 : : * Pointer to the Ethernet device structure.
5767 : : * @param[out] error
5768 : : * Pointer to error structure.
5769 : : *
5770 : : * @return
5771 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5772 : : */
5773 : : static int
5774 : 0 : flow_dv_validate_action_age(uint64_t action_flags,
5775 : : const struct rte_flow_action *action,
5776 : : struct rte_eth_dev *dev,
5777 : : struct rte_flow_error *error)
5778 : : {
5779 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5780 : 0 : const struct rte_flow_action_age *age = action->conf;
5781 : :
5782 [ # # ]: 0 : if (!priv->sh->cdev->config.devx ||
5783 [ # # # # ]: 0 : (priv->sh->sws_cmng.counter_fallback && !priv->sh->aso_age_mng))
5784 : 0 : return rte_flow_error_set(error, ENOTSUP,
5785 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5786 : : NULL,
5787 : : "age action not supported");
5788 [ # # ]: 0 : if (!(action->conf))
5789 : 0 : return rte_flow_error_set(error, EINVAL,
5790 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5791 : : "configuration cannot be null");
5792 [ # # ]: 0 : if (!(age->timeout))
5793 : 0 : return rte_flow_error_set(error, EINVAL,
5794 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5795 : : "invalid timeout value 0");
5796 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_AGE)
5797 : 0 : return rte_flow_error_set(error, EINVAL,
5798 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5799 : : "duplicate age actions set");
5800 : : return 0;
5801 : : }
5802 : :
5803 : : /**
5804 : : * Validate the modify-header IPv4 DSCP actions.
5805 : : *
5806 : : * @param[in] action_flags
5807 : : * Holds the actions detected until now.
5808 : : * @param[in] action
5809 : : * Pointer to the modify action.
5810 : : * @param[in] item_flags
5811 : : * Holds the items detected.
5812 : : * @param[out] error
5813 : : * Pointer to error structure.
5814 : : *
5815 : : * @return
5816 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5817 : : */
5818 : : static int
5819 : 0 : flow_dv_validate_action_modify_ipv4_dscp(const uint64_t action_flags,
5820 : : const struct rte_flow_action *action,
5821 : : const uint64_t item_flags,
5822 : : struct rte_flow_error *error)
5823 : : {
5824 : : int ret = 0;
5825 : :
5826 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5827 [ # # ]: 0 : if (!ret) {
5828 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_L3_IPV4))
5829 : 0 : return rte_flow_error_set(error, EINVAL,
5830 : : RTE_FLOW_ERROR_TYPE_ACTION,
5831 : : NULL,
5832 : : "no ipv4 item in pattern");
5833 : : }
5834 : : return ret;
5835 : : }
5836 : :
5837 : : /**
5838 : : * Validate the modify-header IPv6 DSCP actions.
5839 : : *
5840 : : * @param[in] action_flags
5841 : : * Holds the actions detected until now.
5842 : : * @param[in] action
5843 : : * Pointer to the modify action.
5844 : : * @param[in] item_flags
5845 : : * Holds the items detected.
5846 : : * @param[out] error
5847 : : * Pointer to error structure.
5848 : : *
5849 : : * @return
5850 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5851 : : */
5852 : : static int
5853 : 0 : flow_dv_validate_action_modify_ipv6_dscp(const uint64_t action_flags,
5854 : : const struct rte_flow_action *action,
5855 : : const uint64_t item_flags,
5856 : : struct rte_flow_error *error)
5857 : : {
5858 : : int ret = 0;
5859 : :
5860 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5861 [ # # ]: 0 : if (!ret) {
5862 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_L3_IPV6))
5863 : 0 : return rte_flow_error_set(error, EINVAL,
5864 : : RTE_FLOW_ERROR_TYPE_ACTION,
5865 : : NULL,
5866 : : "no ipv6 item in pattern");
5867 : : }
5868 : : return ret;
5869 : : }
5870 : :
5871 : : int
5872 : 0 : flow_dv_modify_match_cb(void *tool_ctx __rte_unused,
5873 : : struct mlx5_list_entry *entry, void *cb_ctx)
5874 : : {
5875 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
5876 : 0 : struct mlx5_flow_dv_modify_hdr_resource *ref = ctx->data;
5877 : : struct mlx5_flow_dv_modify_hdr_resource *resource =
5878 : : container_of(entry, typeof(*resource), entry);
5879 : : uint32_t key_len = sizeof(*ref) - offsetof(typeof(*ref), ft_type);
5880 : :
5881 : 0 : key_len += ref->actions_num * sizeof(ref->actions[0]);
5882 [ # # ]: 0 : return ref->actions_num != resource->actions_num ||
5883 [ # # ]: 0 : memcmp(&ref->ft_type, &resource->ft_type, key_len);
5884 : : }
5885 : :
5886 : : static struct mlx5_indexed_pool *
5887 : 0 : flow_dv_modify_ipool_get(struct mlx5_dev_ctx_shared *sh, uint8_t index)
5888 : : {
5889 : 0 : struct mlx5_indexed_pool *ipool = __atomic_load_n
5890 : 0 : (&sh->mdh_ipools[index], __ATOMIC_SEQ_CST);
5891 : :
5892 [ # # ]: 0 : if (!ipool) {
5893 : : struct mlx5_indexed_pool *expected = NULL;
5894 : 0 : struct mlx5_indexed_pool_config cfg =
5895 : : (struct mlx5_indexed_pool_config) {
5896 : 0 : .size = sizeof(struct mlx5_flow_dv_modify_hdr_resource) +
5897 : 0 : (index + 1) *
5898 : : sizeof(struct mlx5_modification_cmd),
5899 : : .trunk_size = 64,
5900 : : .grow_trunk = 3,
5901 : : .grow_shift = 2,
5902 : : .need_lock = 1,
5903 : 0 : .release_mem_en = !!sh->config.reclaim_mode,
5904 : : .per_core_cache =
5905 [ # # ]: 0 : sh->config.reclaim_mode ? 0 : (1 << 16),
5906 : : .malloc = mlx5_malloc,
5907 : : .free = mlx5_free,
5908 : : .type = "mlx5_modify_action_resource",
5909 : : };
5910 : :
5911 : 0 : cfg.size = RTE_ALIGN(cfg.size, sizeof(ipool));
5912 : 0 : ipool = mlx5_ipool_create(&cfg);
5913 [ # # ]: 0 : if (!ipool)
5914 : 0 : return NULL;
5915 [ # # ]: 0 : if (!__atomic_compare_exchange_n(&sh->mdh_ipools[index],
5916 : : &expected, ipool, false,
5917 : : __ATOMIC_SEQ_CST,
5918 : : __ATOMIC_SEQ_CST)) {
5919 : 0 : mlx5_ipool_destroy(ipool);
5920 : 0 : ipool = __atomic_load_n(&sh->mdh_ipools[index],
5921 : : __ATOMIC_SEQ_CST);
5922 : : }
5923 : : }
5924 : : return ipool;
5925 : : }
5926 : :
5927 : : struct mlx5_list_entry *
5928 : 0 : flow_dv_modify_create_cb(void *tool_ctx, void *cb_ctx)
5929 : : {
5930 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
5931 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
5932 : : struct mlx5dv_dr_domain *ns;
5933 : : struct mlx5_flow_dv_modify_hdr_resource *entry;
5934 : 0 : struct mlx5_flow_dv_modify_hdr_resource *ref = ctx->data;
5935 : 0 : struct mlx5_indexed_pool *ipool = flow_dv_modify_ipool_get(sh,
5936 : 0 : ref->actions_num - 1);
5937 : : int ret;
5938 : 0 : uint32_t data_len = ref->actions_num * sizeof(ref->actions[0]);
5939 : : uint32_t key_len = sizeof(*ref) - offsetof(typeof(*ref), ft_type);
5940 : : uint32_t idx;
5941 : :
5942 [ # # ]: 0 : if (unlikely(!ipool)) {
5943 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
5944 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5945 : : NULL, "cannot allocate modify ipool");
5946 : 0 : return NULL;
5947 : : }
5948 : 0 : entry = mlx5_ipool_zmalloc(ipool, &idx);
5949 [ # # ]: 0 : if (!entry) {
5950 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
5951 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
5952 : : "cannot allocate resource memory");
5953 : 0 : return NULL;
5954 : : }
5955 : 0 : rte_memcpy(&entry->ft_type,
5956 : 0 : RTE_PTR_ADD(ref, offsetof(typeof(*ref), ft_type)),
5957 [ # # ]: 0 : key_len + data_len);
5958 [ # # ]: 0 : if (entry->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
5959 : 0 : ns = sh->fdb_domain;
5960 [ # # ]: 0 : else if (entry->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_TX)
5961 : 0 : ns = sh->tx_domain;
5962 : : else
5963 : 0 : ns = sh->rx_domain;
5964 : 0 : ret = mlx5_flow_os_create_flow_action_modify_header
5965 : 0 : (sh->cdev->ctx, ns, entry,
5966 : : data_len, &entry->action);
5967 : : if (ret) {
5968 : 0 : mlx5_ipool_free(sh->mdh_ipools[ref->actions_num - 1], idx);
5969 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
5970 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5971 : : NULL, "cannot create modification action");
5972 : 0 : return NULL;
5973 : : }
5974 : 0 : entry->idx = idx;
5975 : 0 : return &entry->entry;
5976 : : }
5977 : :
5978 : : struct mlx5_list_entry *
5979 : 0 : flow_dv_modify_clone_cb(void *tool_ctx, struct mlx5_list_entry *oentry,
5980 : : void *cb_ctx)
5981 : : {
5982 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
5983 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
5984 : : struct mlx5_flow_dv_modify_hdr_resource *entry;
5985 : 0 : struct mlx5_flow_dv_modify_hdr_resource *ref = ctx->data;
5986 : 0 : uint32_t data_len = ref->actions_num * sizeof(ref->actions[0]);
5987 : : uint32_t idx;
5988 : :
5989 : 0 : entry = mlx5_ipool_malloc(sh->mdh_ipools[ref->actions_num - 1],
5990 : : &idx);
5991 [ # # ]: 0 : if (!entry) {
5992 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
5993 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
5994 : : "cannot allocate resource memory");
5995 : 0 : return NULL;
5996 : : }
5997 : 0 : memcpy(entry, oentry, sizeof(*entry) + data_len);
5998 : 0 : entry->idx = idx;
5999 : 0 : return &entry->entry;
6000 : : }
6001 : :
6002 : : void
6003 : 0 : flow_dv_modify_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
6004 : : {
6005 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
6006 : : struct mlx5_flow_dv_modify_hdr_resource *res =
6007 : : container_of(entry, typeof(*res), entry);
6008 : :
6009 : 0 : mlx5_ipool_free(sh->mdh_ipools[res->actions_num - 1], res->idx);
6010 : 0 : }
6011 : :
6012 : : /**
6013 : : * Validate the sample action.
6014 : : *
6015 : : * @param[in, out] action_flags
6016 : : * Holds the actions detected until now.
6017 : : * @param[in] action
6018 : : * Pointer to the sample action.
6019 : : * @param[in] dev
6020 : : * Pointer to the Ethernet device structure.
6021 : : * @param[in] attr
6022 : : * Attributes of flow that includes this action.
6023 : : * @param[in] item_flags
6024 : : * Holds the items detected.
6025 : : * @param[in] rss
6026 : : * Pointer to the RSS action.
6027 : : * @param[out] sample_rss
6028 : : * Pointer to the RSS action in sample action list.
6029 : : * @param[out] count
6030 : : * Pointer to the COUNT action in sample action list.
6031 : : * @param[out] fdb_mirror
6032 : : * Pointer to the FDB mirror flag.
6033 : : * @param root
6034 : : * Whether action is on root table.
6035 : : * @param[out] error
6036 : : * Pointer to error structure.
6037 : : *
6038 : : * @return
6039 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
6040 : : */
6041 : : static int
6042 : 0 : flow_dv_validate_action_sample(uint64_t *action_flags,
6043 : : uint64_t *sub_action_flags,
6044 : : const struct rte_flow_action *action,
6045 : : struct rte_eth_dev *dev,
6046 : : const struct rte_flow_attr *attr,
6047 : : uint64_t item_flags,
6048 : : const struct rte_flow_action_rss *rss,
6049 : : const struct rte_flow_action_rss **sample_rss,
6050 : : const struct rte_flow_action_count **count,
6051 : : int *fdb_mirror,
6052 : : uint16_t *sample_port_id,
6053 : : bool root,
6054 : : struct rte_flow_error *error)
6055 : : {
6056 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6057 : 0 : struct mlx5_sh_config *dev_conf = &priv->sh->config;
6058 : 0 : const struct rte_flow_action_sample *sample = action->conf;
6059 : : const struct rte_flow_action_port_id *port = NULL;
6060 : : const struct rte_flow_action *act;
6061 : : uint16_t queue_index = 0xFFFF;
6062 : 0 : int actions_n = 0;
6063 : : int ret;
6064 : :
6065 [ # # ]: 0 : if (!sample)
6066 : 0 : return rte_flow_error_set(error, EINVAL,
6067 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6068 : : "configuration cannot be NULL");
6069 [ # # ]: 0 : if (sample->ratio == 0)
6070 : 0 : return rte_flow_error_set(error, EINVAL,
6071 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6072 : : "ratio value starts from 1");
6073 [ # # ]: 0 : if (!priv->sh->cdev->config.devx ||
6074 [ # # ]: 0 : (sample->ratio > 0 && !priv->sampler_en))
6075 : 0 : return rte_flow_error_set(error, ENOTSUP,
6076 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6077 : : NULL,
6078 : : "sample action not supported");
6079 [ # # ]: 0 : if (*action_flags & MLX5_FLOW_ACTION_SAMPLE)
6080 : 0 : return rte_flow_error_set(error, EINVAL,
6081 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
6082 : : "Multiple sample actions not "
6083 : : "supported");
6084 [ # # ]: 0 : if (*action_flags & MLX5_FLOW_ACTION_METER)
6085 : 0 : return rte_flow_error_set(error, EINVAL,
6086 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6087 : : "wrong action order, meter should "
6088 : : "be after sample action");
6089 [ # # ]: 0 : if (*action_flags & MLX5_FLOW_ACTION_JUMP)
6090 : 0 : return rte_flow_error_set(error, EINVAL,
6091 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6092 : : "wrong action order, jump should "
6093 : : "be after sample action");
6094 [ # # ]: 0 : if (*action_flags & MLX5_FLOW_ACTION_CT)
6095 : 0 : return rte_flow_error_set(error, EINVAL,
6096 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6097 : : "Sample after CT not supported");
6098 : 0 : act = sample->actions;
6099 [ # # ]: 0 : for (; act->type != RTE_FLOW_ACTION_TYPE_END; act++) {
6100 [ # # ]: 0 : if (actions_n == MLX5_DV_MAX_NUMBER_OF_ACTIONS)
6101 : 0 : return rte_flow_error_set(error, ENOTSUP,
6102 : : RTE_FLOW_ERROR_TYPE_ACTION,
6103 : : act, "too many actions");
6104 [ # # # # : 0 : switch (act->type) {
# # # # ]
6105 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
6106 : 0 : ret = mlx5_flow_validate_action_queue(act,
6107 : : *sub_action_flags,
6108 : : dev,
6109 : : attr, error);
6110 [ # # ]: 0 : if (ret < 0)
6111 : 0 : return ret;
6112 : 0 : queue_index = ((const struct rte_flow_action_queue *)
6113 : 0 : (act->conf))->index;
6114 : 0 : *sub_action_flags |= MLX5_FLOW_ACTION_QUEUE;
6115 : 0 : ++actions_n;
6116 : 0 : break;
6117 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
6118 : 0 : *sample_rss = act->conf;
6119 : 0 : ret = mlx5_flow_validate_action_rss(act,
6120 : : *sub_action_flags,
6121 : : dev, attr,
6122 : : item_flags,
6123 : : error);
6124 [ # # ]: 0 : if (ret < 0)
6125 : 0 : return ret;
6126 [ # # # # ]: 0 : if (rss && *sample_rss &&
6127 [ # # ]: 0 : ((*sample_rss)->level != rss->level ||
6128 [ # # ]: 0 : (*sample_rss)->types != rss->types))
6129 : 0 : return rte_flow_error_set(error, ENOTSUP,
6130 : : RTE_FLOW_ERROR_TYPE_ACTION,
6131 : : NULL,
6132 : : "Can't use the different RSS types "
6133 : : "or level in the same flow");
6134 [ # # # # ]: 0 : if (*sample_rss != NULL && (*sample_rss)->queue_num)
6135 : 0 : queue_index = (*sample_rss)->queue[0];
6136 : 0 : *sub_action_flags |= MLX5_FLOW_ACTION_RSS;
6137 : 0 : ++actions_n;
6138 : 0 : break;
6139 : 0 : case RTE_FLOW_ACTION_TYPE_MARK:
6140 : 0 : ret = flow_dv_validate_action_mark(dev, act,
6141 : : *sub_action_flags,
6142 : : attr, error);
6143 [ # # ]: 0 : if (ret < 0)
6144 : 0 : return ret;
6145 [ # # ]: 0 : if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY)
6146 : 0 : *sub_action_flags |= MLX5_FLOW_ACTION_MARK |
6147 : : MLX5_FLOW_ACTION_MARK_EXT;
6148 : : else
6149 : 0 : *sub_action_flags |= MLX5_FLOW_ACTION_MARK;
6150 : 0 : ++actions_n;
6151 : 0 : break;
6152 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
6153 : 0 : ret = flow_dv_validate_action_count
6154 : 0 : (dev, false, *action_flags | *sub_action_flags,
6155 : : root, error);
6156 [ # # ]: 0 : if (ret < 0)
6157 : 0 : return ret;
6158 : 0 : *count = act->conf;
6159 : 0 : *sub_action_flags |= MLX5_FLOW_ACTION_COUNT;
6160 : 0 : *action_flags |= MLX5_FLOW_ACTION_COUNT;
6161 : 0 : ++actions_n;
6162 : 0 : break;
6163 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_ID:
6164 : : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
6165 : 0 : ret = flow_dv_validate_action_port_id(dev,
6166 : : *sub_action_flags,
6167 : : act,
6168 : : attr,
6169 : : error);
6170 [ # # ]: 0 : if (ret)
6171 : 0 : return ret;
6172 [ # # ]: 0 : if (act->type == RTE_FLOW_ACTION_TYPE_PORT_ID) {
6173 : 0 : port = (const struct rte_flow_action_port_id *)
6174 : : act->conf;
6175 [ # # ]: 0 : *sample_port_id = port->original ?
6176 : 0 : dev->data->port_id : port->id;
6177 : : } else {
6178 : 0 : *sample_port_id = ((const struct rte_flow_action_ethdev *)
6179 : 0 : act->conf)->port_id;
6180 : : }
6181 : 0 : *sub_action_flags |= MLX5_FLOW_ACTION_PORT_ID;
6182 : 0 : ++actions_n;
6183 : 0 : break;
6184 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
6185 : 0 : ret = flow_dv_validate_action_raw_encap_decap
6186 : 0 : (dev, NULL, act->conf, attr, sub_action_flags,
6187 : : &actions_n, action, item_flags, error);
6188 [ # # ]: 0 : if (ret < 0)
6189 : 0 : return ret;
6190 : 0 : ++actions_n;
6191 : 0 : break;
6192 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
6193 : : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
6194 : 0 : ret = flow_dv_validate_action_l2_encap(dev,
6195 : : *sub_action_flags,
6196 : : act, attr,
6197 : : error);
6198 [ # # ]: 0 : if (ret < 0)
6199 : 0 : return ret;
6200 : 0 : *sub_action_flags |= MLX5_FLOW_ACTION_ENCAP;
6201 : 0 : ++actions_n;
6202 : 0 : break;
6203 : 0 : default:
6204 : 0 : return rte_flow_error_set(error, ENOTSUP,
6205 : : RTE_FLOW_ERROR_TYPE_ACTION,
6206 : : NULL,
6207 : : "Doesn't support optional "
6208 : : "action");
6209 : : }
6210 : : }
6211 [ # # ]: 0 : if (attr->ingress) {
6212 [ # # ]: 0 : if (!(*sub_action_flags & (MLX5_FLOW_ACTION_QUEUE |
6213 : : MLX5_FLOW_ACTION_RSS)))
6214 : 0 : return rte_flow_error_set(error, EINVAL,
6215 : : RTE_FLOW_ERROR_TYPE_ACTION,
6216 : : NULL,
6217 : : "Ingress must has a dest "
6218 : : "QUEUE for Sample");
6219 [ # # ]: 0 : } else if (attr->egress) {
6220 : 0 : return rte_flow_error_set(error, ENOTSUP,
6221 : : RTE_FLOW_ERROR_TYPE_ACTION,
6222 : : NULL,
6223 : : "Sample Only support Ingress "
6224 : : "or E-Switch");
6225 [ # # ]: 0 : } else if (sample->actions->type != RTE_FLOW_ACTION_TYPE_END) {
6226 : : MLX5_ASSERT(attr->transfer);
6227 [ # # ]: 0 : if (sample->ratio > 1)
6228 : 0 : return rte_flow_error_set(error, ENOTSUP,
6229 : : RTE_FLOW_ERROR_TYPE_ACTION,
6230 : : NULL,
6231 : : "E-Switch doesn't support "
6232 : : "any optional action "
6233 : : "for sampling");
6234 [ # # ]: 0 : if (*sub_action_flags & MLX5_FLOW_ACTION_QUEUE)
6235 : 0 : return rte_flow_error_set(error, ENOTSUP,
6236 : : RTE_FLOW_ERROR_TYPE_ACTION,
6237 : : NULL,
6238 : : "unsupported action QUEUE");
6239 [ # # ]: 0 : if (*sub_action_flags & MLX5_FLOW_ACTION_RSS)
6240 : 0 : return rte_flow_error_set(error, ENOTSUP,
6241 : : RTE_FLOW_ERROR_TYPE_ACTION,
6242 : : NULL,
6243 : : "unsupported action QUEUE");
6244 [ # # ]: 0 : if (!(*sub_action_flags & MLX5_FLOW_ACTION_PORT_ID))
6245 : 0 : return rte_flow_error_set(error, EINVAL,
6246 : : RTE_FLOW_ERROR_TYPE_ACTION,
6247 : : NULL,
6248 : : "E-Switch must has a dest "
6249 : : "port for mirroring");
6250 : 0 : *fdb_mirror = 1;
6251 : : }
6252 : : /* Continue validation for Xcap actions.*/
6253 [ # # # # ]: 0 : if ((*sub_action_flags & MLX5_FLOW_XCAP_ACTIONS) &&
6254 [ # # ]: 0 : (queue_index == 0xFFFF || !mlx5_rxq_is_hairpin(dev, queue_index))) {
6255 [ # # ]: 0 : if ((*sub_action_flags & MLX5_FLOW_XCAP_ACTIONS) ==
6256 : : MLX5_FLOW_XCAP_ACTIONS)
6257 : 0 : return rte_flow_error_set(error, ENOTSUP,
6258 : : RTE_FLOW_ERROR_TYPE_ACTION,
6259 : : NULL, "encap and decap "
6260 : : "combination aren't "
6261 : : "supported");
6262 [ # # # # ]: 0 : if (attr->ingress && (*sub_action_flags & MLX5_FLOW_ACTION_ENCAP))
6263 : 0 : return rte_flow_error_set(error, ENOTSUP,
6264 : : RTE_FLOW_ERROR_TYPE_ACTION,
6265 : : NULL, "encap is not supported"
6266 : : " for ingress traffic");
6267 : : }
6268 : : return 0;
6269 : : }
6270 : :
6271 : : /**
6272 : : * Find existing modify-header resource or create and register a new one.
6273 : : *
6274 : : * @param dev[in, out]
6275 : : * Pointer to rte_eth_dev structure.
6276 : : * @param[in, out] resource
6277 : : * Pointer to modify-header resource.
6278 : : * @parm[in, out] dev_flow
6279 : : * Pointer to the dev_flow.
6280 : : * @param[out] error
6281 : : * pointer to error structure.
6282 : : *
6283 : : * @return
6284 : : * 0 on success otherwise -errno and errno is set.
6285 : : */
6286 : : static int
6287 : 0 : flow_dv_modify_hdr_resource_register
6288 : : (struct rte_eth_dev *dev,
6289 : : struct mlx5_flow_dv_modify_hdr_resource *resource,
6290 : : struct mlx5_flow *dev_flow,
6291 : : struct rte_flow_error *error)
6292 : : {
6293 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6294 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
6295 : 0 : uint32_t key_len = sizeof(*resource) -
6296 : : offsetof(typeof(*resource), ft_type) +
6297 : 0 : resource->actions_num * sizeof(resource->actions[0]);
6298 : : struct mlx5_list_entry *entry;
6299 : 0 : struct mlx5_flow_cb_ctx ctx = {
6300 : : .error = error,
6301 : : .data = resource,
6302 : : };
6303 : : struct mlx5_hlist *modify_cmds;
6304 : : uint64_t key64;
6305 : :
6306 : 0 : modify_cmds = flow_dv_hlist_prepare(sh, &sh->modify_cmds,
6307 : : "hdr_modify",
6308 : : MLX5_FLOW_HDR_MODIFY_HTABLE_SZ,
6309 : : true, false, sh,
6310 : : flow_dv_modify_create_cb,
6311 : : flow_dv_modify_match_cb,
6312 : : flow_dv_modify_remove_cb,
6313 : : flow_dv_modify_clone_cb,
6314 : : flow_dv_modify_clone_free_cb,
6315 : : error);
6316 [ # # ]: 0 : if (unlikely(!modify_cmds))
6317 : 0 : return -rte_errno;
6318 : 0 : resource->root = !dev_flow->dv.group;
6319 [ # # # # ]: 0 : if (resource->actions_num > flow_dv_modify_hdr_action_max(dev,
6320 : : resource->root))
6321 : 0 : return rte_flow_error_set(error, EOVERFLOW,
6322 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
6323 : : "too many modify header items");
6324 : 0 : key64 = __rte_raw_cksum(&resource->ft_type, key_len, 0);
6325 : 0 : entry = mlx5_hlist_register(modify_cmds, key64, &ctx);
6326 [ # # ]: 0 : if (!entry)
6327 : 0 : return -rte_errno;
6328 : : resource = container_of(entry, typeof(*resource), entry);
6329 : 0 : dev_flow->handle->dvh.modify_hdr = resource;
6330 : 0 : return 0;
6331 : : }
6332 : :
6333 : : /**
6334 : : * Get DV flow counter by index.
6335 : : *
6336 : : * @param[in] dev
6337 : : * Pointer to the Ethernet device structure.
6338 : : * @param[in] idx
6339 : : * mlx5 flow counter index in the container.
6340 : : * @param[out] ppool
6341 : : * mlx5 flow counter pool in the container.
6342 : : *
6343 : : * @return
6344 : : * Pointer to the counter, NULL otherwise.
6345 : : */
6346 : : static struct mlx5_flow_counter *
6347 : : flow_dv_counter_get_by_idx(struct rte_eth_dev *dev,
6348 : : uint32_t idx,
6349 : : struct mlx5_flow_counter_pool **ppool)
6350 : : {
6351 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6352 : 0 : struct mlx5_flow_counter_mng *cmng = &priv->sh->sws_cmng;
6353 : : struct mlx5_flow_counter_pool *pool;
6354 : :
6355 : : /* Decrease to original index and clear shared bit. */
6356 : 0 : idx = (idx - 1) & (MLX5_CNT_SHARED_OFFSET - 1);
6357 : : MLX5_ASSERT(idx / MLX5_COUNTERS_PER_POOL < MLX5_COUNTER_POOLS_MAX_NUM);
6358 : 0 : pool = cmng->pools[idx / MLX5_COUNTERS_PER_POOL];
6359 : : MLX5_ASSERT(pool);
6360 : : if (ppool)
6361 : : *ppool = pool;
6362 [ # # # # : 0 : return MLX5_POOL_GET_CNT(pool, idx % MLX5_COUNTERS_PER_POOL);
# # # # #
# # # ]
6363 : : }
6364 : :
6365 : : /**
6366 : : * Check the devx counter belongs to the pool.
6367 : : *
6368 : : * @param[in] pool
6369 : : * Pointer to the counter pool.
6370 : : * @param[in] id
6371 : : * The counter devx ID.
6372 : : *
6373 : : * @return
6374 : : * True if counter belongs to the pool, false otherwise.
6375 : : */
6376 : : static bool
6377 : : flow_dv_is_counter_in_pool(struct mlx5_flow_counter_pool *pool, int id)
6378 : : {
6379 : 0 : int base = (pool->min_dcs->id / MLX5_COUNTERS_PER_POOL) *
6380 : : MLX5_COUNTERS_PER_POOL;
6381 : :
6382 [ # # # # ]: 0 : if (id >= base && id < base + MLX5_COUNTERS_PER_POOL)
6383 : : return true;
6384 : : return false;
6385 : : }
6386 : :
6387 : : /**
6388 : : * Get a pool by devx counter ID.
6389 : : *
6390 : : * @param[in] cmng
6391 : : * Pointer to the counter management.
6392 : : * @param[in] id
6393 : : * The counter devx ID.
6394 : : *
6395 : : * @return
6396 : : * The counter pool pointer if exists, NULL otherwise,
6397 : : */
6398 : : static struct mlx5_flow_counter_pool *
6399 : 0 : flow_dv_find_pool_by_id(struct mlx5_flow_counter_mng *cmng, int id)
6400 : : {
6401 : : uint32_t i;
6402 : : struct mlx5_flow_counter_pool *pool = NULL;
6403 : :
6404 : 0 : rte_spinlock_lock(&cmng->pool_update_sl);
6405 : : /* Check last used pool. */
6406 [ # # ]: 0 : if (cmng->last_pool_idx != POOL_IDX_INVALID &&
6407 [ # # ]: 0 : flow_dv_is_counter_in_pool(cmng->pools[cmng->last_pool_idx], id)) {
6408 : : pool = cmng->pools[cmng->last_pool_idx];
6409 : 0 : goto out;
6410 : : }
6411 : : /* ID out of range means no suitable pool in the container. */
6412 [ # # # # ]: 0 : if (id > cmng->max_id || id < cmng->min_id)
6413 : 0 : goto out;
6414 : : /*
6415 : : * Find the pool from the end of the container, since mostly counter
6416 : : * ID is sequence increasing, and the last pool should be the needed
6417 : : * one.
6418 : : */
6419 : 0 : i = cmng->n_valid;
6420 [ # # ]: 0 : while (i--) {
6421 [ # # ]: 0 : struct mlx5_flow_counter_pool *pool_tmp = cmng->pools[i];
6422 : :
6423 : : if (flow_dv_is_counter_in_pool(pool_tmp, id)) {
6424 : : pool = pool_tmp;
6425 : : break;
6426 : : }
6427 : : }
6428 : 0 : out:
6429 : : rte_spinlock_unlock(&cmng->pool_update_sl);
6430 : 0 : return pool;
6431 : : }
6432 : :
6433 : : /**
6434 : : * Query a devx flow counter.
6435 : : *
6436 : : * @param[in] dev
6437 : : * Pointer to the Ethernet device structure.
6438 : : * @param[in] counter
6439 : : * Index to the flow counter.
6440 : : * @param[out] pkts
6441 : : * The statistics value of packets.
6442 : : * @param[out] bytes
6443 : : * The statistics value of bytes.
6444 : : *
6445 : : * @return
6446 : : * 0 on success, otherwise a negative errno value and rte_errno is set.
6447 : : */
6448 : : static inline int
6449 : 0 : _flow_dv_query_count(struct rte_eth_dev *dev, uint32_t counter, uint64_t *pkts,
6450 : : uint64_t *bytes)
6451 : : {
6452 [ # # ]: 0 : struct mlx5_priv *priv = dev->data->dev_private;
6453 : : struct mlx5_flow_counter_pool *pool = NULL;
6454 : : struct mlx5_flow_counter *cnt;
6455 : : int offset;
6456 : :
6457 : : cnt = flow_dv_counter_get_by_idx(dev, counter, &pool);
6458 : : MLX5_ASSERT(pool);
6459 [ # # ]: 0 : if (priv->sh->sws_cmng.counter_fallback)
6460 : 0 : return mlx5_devx_cmd_flow_counter_query(cnt->dcs_when_active, 0,
6461 : : 0, pkts, bytes, 0, NULL, NULL, 0);
6462 : 0 : rte_spinlock_lock(&pool->sl);
6463 [ # # ]: 0 : if (!pool->raw) {
6464 : 0 : *pkts = 0;
6465 : 0 : *bytes = 0;
6466 : : } else {
6467 [ # # ]: 0 : offset = MLX5_CNT_ARRAY_IDX(pool, cnt);
6468 : 0 : *pkts = rte_be_to_cpu_64(pool->raw->data[offset].hits);
6469 : 0 : *bytes = rte_be_to_cpu_64(pool->raw->data[offset].bytes);
6470 : : }
6471 : : rte_spinlock_unlock(&pool->sl);
6472 : 0 : return 0;
6473 : : }
6474 : :
6475 : : /**
6476 : : * Create and initialize a new counter pool.
6477 : : *
6478 : : * @param[in] dev
6479 : : * Pointer to the Ethernet device structure.
6480 : : * @param[out] dcs
6481 : : * The devX counter handle.
6482 : : * @param[in] age
6483 : : * Whether the pool is for counter that was allocated for aging.
6484 : : *
6485 : : * @return
6486 : : * The pool container pointer on success, NULL otherwise and rte_errno is set.
6487 : : */
6488 : : static struct mlx5_flow_counter_pool *
6489 : 0 : flow_dv_pool_create(struct rte_eth_dev *dev, struct mlx5_devx_obj *dcs,
6490 : : uint32_t age)
6491 : : {
6492 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6493 : : struct mlx5_flow_counter_pool *pool;
6494 : 0 : struct mlx5_flow_counter_mng *cmng = &priv->sh->sws_cmng;
6495 : 0 : bool fallback = cmng->counter_fallback;
6496 : : uint32_t size = sizeof(*pool);
6497 : :
6498 [ # # ]: 0 : if (cmng->n_valid == MLX5_COUNTER_POOLS_MAX_NUM) {
6499 : 0 : DRV_LOG(ERR, "All counter is in used, try again later.");
6500 : 0 : rte_errno = EAGAIN;
6501 : 0 : return NULL;
6502 : : }
6503 : : size += MLX5_COUNTERS_PER_POOL * MLX5_CNT_SIZE;
6504 [ # # ]: 0 : size += (!age ? 0 : MLX5_COUNTERS_PER_POOL * MLX5_AGE_SIZE);
6505 : 0 : pool = mlx5_malloc(MLX5_MEM_ZERO, size, 0, SOCKET_ID_ANY);
6506 [ # # ]: 0 : if (!pool) {
6507 : 0 : rte_errno = ENOMEM;
6508 : 0 : return NULL;
6509 : : }
6510 : 0 : pool->raw = NULL;
6511 : 0 : pool->is_aged = !!age;
6512 : 0 : pool->query_gen = 0;
6513 : 0 : pool->min_dcs = dcs;
6514 : : rte_spinlock_init(&pool->sl);
6515 : : rte_spinlock_init(&pool->csl);
6516 : 0 : TAILQ_INIT(&pool->counters[0]);
6517 : 0 : TAILQ_INIT(&pool->counters[1]);
6518 : 0 : pool->time_of_last_age_check = MLX5_CURR_TIME_SEC;
6519 : 0 : rte_spinlock_lock(&cmng->pool_update_sl);
6520 : 0 : pool->index = cmng->n_valid;
6521 : 0 : cmng->pools[pool->index] = pool;
6522 : 0 : cmng->n_valid++;
6523 [ # # ]: 0 : if (unlikely(fallback)) {
6524 : 0 : int base = RTE_ALIGN_FLOOR(dcs->id, MLX5_COUNTERS_PER_POOL);
6525 : :
6526 [ # # ]: 0 : if (base < cmng->min_id)
6527 : 0 : cmng->min_id = base;
6528 [ # # ]: 0 : if (base > cmng->max_id)
6529 : 0 : cmng->max_id = base + MLX5_COUNTERS_PER_POOL - 1;
6530 : 0 : cmng->last_pool_idx = pool->index;
6531 : : }
6532 : : rte_spinlock_unlock(&cmng->pool_update_sl);
6533 : 0 : return pool;
6534 : : }
6535 : :
6536 : : /**
6537 : : * Prepare a new counter and/or a new counter pool.
6538 : : *
6539 : : * @param[in] dev
6540 : : * Pointer to the Ethernet device structure.
6541 : : * @param[out] cnt_free
6542 : : * Where to put the pointer of a new counter.
6543 : : * @param[in] age
6544 : : * Whether the pool is for counter that was allocated for aging.
6545 : : *
6546 : : * @return
6547 : : * The counter pool pointer and @p cnt_free is set on success,
6548 : : * NULL otherwise and rte_errno is set.
6549 : : */
6550 : : static struct mlx5_flow_counter_pool *
6551 : 0 : flow_dv_counter_pool_prepare(struct rte_eth_dev *dev,
6552 : : struct mlx5_flow_counter **cnt_free,
6553 : : uint32_t age)
6554 : : {
6555 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6556 : 0 : struct mlx5_flow_counter_mng *cmng = &priv->sh->sws_cmng;
6557 : : struct mlx5_flow_counter_pool *pool;
6558 : : struct mlx5_counters tmp_tq;
6559 : : struct mlx5_devx_obj *dcs = NULL;
6560 : : struct mlx5_flow_counter *cnt;
6561 : 0 : enum mlx5_counter_type cnt_type =
6562 : 0 : age ? MLX5_COUNTER_TYPE_AGE : MLX5_COUNTER_TYPE_ORIGIN;
6563 : 0 : bool fallback = priv->sh->sws_cmng.counter_fallback;
6564 : : uint32_t i;
6565 : :
6566 [ # # ]: 0 : if (fallback) {
6567 : : /* bulk_bitmap must be 0 for single counter allocation. */
6568 : 0 : dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->cdev->ctx, 0);
6569 [ # # ]: 0 : if (!dcs)
6570 : : return NULL;
6571 : 0 : pool = flow_dv_find_pool_by_id(cmng, dcs->id);
6572 [ # # ]: 0 : if (!pool) {
6573 : 0 : pool = flow_dv_pool_create(dev, dcs, age);
6574 [ # # ]: 0 : if (!pool) {
6575 : 0 : mlx5_devx_cmd_destroy(dcs);
6576 : 0 : return NULL;
6577 : : }
6578 : : }
6579 : 0 : i = dcs->id % MLX5_COUNTERS_PER_POOL;
6580 [ # # ]: 0 : cnt = MLX5_POOL_GET_CNT(pool, i);
6581 : 0 : cnt->pool = pool;
6582 : 0 : cnt->dcs_when_free = dcs;
6583 : 0 : *cnt_free = cnt;
6584 : 0 : return pool;
6585 : : }
6586 : 0 : dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->cdev->ctx, 0x4);
6587 [ # # ]: 0 : if (!dcs) {
6588 : 0 : rte_errno = ENODATA;
6589 : 0 : return NULL;
6590 : : }
6591 : 0 : pool = flow_dv_pool_create(dev, dcs, age);
6592 [ # # ]: 0 : if (!pool) {
6593 : 0 : mlx5_devx_cmd_destroy(dcs);
6594 : 0 : return NULL;
6595 : : }
6596 : 0 : TAILQ_INIT(&tmp_tq);
6597 [ # # ]: 0 : for (i = 1; i < MLX5_COUNTERS_PER_POOL; ++i) {
6598 [ # # ]: 0 : cnt = MLX5_POOL_GET_CNT(pool, i);
6599 : 0 : cnt->pool = pool;
6600 [ # # ]: 0 : TAILQ_INSERT_HEAD(&tmp_tq, cnt, next);
6601 : : }
6602 : 0 : rte_spinlock_lock(&cmng->csl[cnt_type]);
6603 [ # # ]: 0 : TAILQ_CONCAT(&cmng->counters[cnt_type], &tmp_tq, next);
6604 : : rte_spinlock_unlock(&cmng->csl[cnt_type]);
6605 : 0 : *cnt_free = MLX5_POOL_GET_CNT(pool, 0);
6606 : 0 : (*cnt_free)->pool = pool;
6607 : 0 : return pool;
6608 : : }
6609 : :
6610 : : /**
6611 : : * Allocate a flow counter.
6612 : : *
6613 : : * @param[in] dev
6614 : : * Pointer to the Ethernet device structure.
6615 : : * @param[in] age
6616 : : * Whether the counter was allocated for aging.
6617 : : *
6618 : : * @return
6619 : : * Index to flow counter on success, 0 otherwise and rte_errno is set.
6620 : : */
6621 : : static uint32_t
6622 : 0 : flow_dv_counter_alloc(struct rte_eth_dev *dev, uint32_t age)
6623 : : {
6624 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6625 : : struct mlx5_flow_counter_pool *pool = NULL;
6626 : 0 : struct mlx5_flow_counter *cnt_free = NULL;
6627 : 0 : bool fallback = priv->sh->sws_cmng.counter_fallback;
6628 : : struct mlx5_flow_counter_mng *cmng = &priv->sh->sws_cmng;
6629 : 0 : enum mlx5_counter_type cnt_type =
6630 : 0 : age ? MLX5_COUNTER_TYPE_AGE : MLX5_COUNTER_TYPE_ORIGIN;
6631 : : uint32_t cnt_idx;
6632 : :
6633 [ # # ]: 0 : if (!priv->sh->cdev->config.devx) {
6634 : 0 : rte_errno = ENOTSUP;
6635 : 0 : return 0;
6636 : : }
6637 : : /* Get free counters from container. */
6638 : 0 : rte_spinlock_lock(&cmng->csl[cnt_type]);
6639 : 0 : cnt_free = TAILQ_FIRST(&cmng->counters[cnt_type]);
6640 [ # # ]: 0 : if (cnt_free)
6641 [ # # ]: 0 : TAILQ_REMOVE(&cmng->counters[cnt_type], cnt_free, next);
6642 : : rte_spinlock_unlock(&cmng->csl[cnt_type]);
6643 [ # # # # ]: 0 : if (!cnt_free && !flow_dv_counter_pool_prepare(dev, &cnt_free, age))
6644 : 0 : goto err;
6645 : 0 : pool = cnt_free->pool;
6646 [ # # ]: 0 : if (fallback)
6647 : 0 : cnt_free->dcs_when_active = cnt_free->dcs_when_free;
6648 : : /* Create a DV counter action only in the first time usage. */
6649 [ # # ]: 0 : if (!cnt_free->action) {
6650 : : uint16_t offset;
6651 : : struct mlx5_devx_obj *dcs;
6652 : : int ret;
6653 : :
6654 [ # # ]: 0 : if (!fallback) {
6655 [ # # ]: 0 : offset = MLX5_CNT_ARRAY_IDX(pool, cnt_free);
6656 : 0 : dcs = pool->min_dcs;
6657 : : } else {
6658 : : offset = 0;
6659 : 0 : dcs = cnt_free->dcs_when_free;
6660 : : }
6661 : 0 : ret = mlx5_flow_os_create_flow_action_count(dcs->obj, offset,
6662 : : &cnt_free->action);
6663 : : if (ret) {
6664 : 0 : rte_errno = errno;
6665 : 0 : goto err;
6666 : : }
6667 : : }
6668 [ # # ]: 0 : cnt_idx = MLX5_MAKE_CNT_IDX(pool->index,
6669 : : MLX5_CNT_ARRAY_IDX(pool, cnt_free));
6670 : : /* Update the counter reset values. */
6671 [ # # ]: 0 : if (_flow_dv_query_count(dev, cnt_idx, &cnt_free->hits,
6672 : : &cnt_free->bytes))
6673 : 0 : goto err;
6674 [ # # # # ]: 0 : if (!fallback && !priv->sh->sws_cmng.query_thread_on)
6675 : : /* Start the asynchronous batch query by the host thread. */
6676 : 0 : mlx5_set_query_alarm(priv->sh);
6677 : : /*
6678 : : * When the count action isn't shared (by ID), shared_info field is
6679 : : * used for indirect action API's refcnt.
6680 : : * When the counter action is not shared neither by ID nor by indirect
6681 : : * action API, shared info must be 1.
6682 : : */
6683 : 0 : cnt_free->shared_info.refcnt = 1;
6684 : 0 : return cnt_idx;
6685 : 0 : err:
6686 [ # # ]: 0 : if (cnt_free) {
6687 : 0 : cnt_free->pool = pool;
6688 [ # # ]: 0 : if (fallback)
6689 : 0 : cnt_free->dcs_when_free = cnt_free->dcs_when_active;
6690 : : rte_spinlock_lock(&cmng->csl[cnt_type]);
6691 : 0 : TAILQ_INSERT_TAIL(&cmng->counters[cnt_type], cnt_free, next);
6692 : : rte_spinlock_unlock(&cmng->csl[cnt_type]);
6693 : : }
6694 : : return 0;
6695 : : }
6696 : :
6697 : : /**
6698 : : * Get age param from counter index.
6699 : : *
6700 : : * @param[in] dev
6701 : : * Pointer to the Ethernet device structure.
6702 : : * @param[in] counter
6703 : : * Index to the counter handler.
6704 : : *
6705 : : * @return
6706 : : * The aging parameter specified for the counter index.
6707 : : */
6708 : : static struct mlx5_age_param*
6709 : : flow_dv_counter_idx_get_age(struct rte_eth_dev *dev,
6710 : : uint32_t counter)
6711 : : {
6712 : : struct mlx5_flow_counter *cnt;
6713 : : struct mlx5_flow_counter_pool *pool = NULL;
6714 : :
6715 : : flow_dv_counter_get_by_idx(dev, counter, &pool);
6716 : : counter = (counter - 1) % MLX5_COUNTERS_PER_POOL;
6717 : : cnt = MLX5_POOL_GET_CNT(pool, counter);
6718 : 0 : return MLX5_CNT_TO_AGE(cnt);
6719 : : }
6720 : :
6721 : : /**
6722 : : * Remove a flow counter from aged counter list.
6723 : : *
6724 : : * @param[in] dev
6725 : : * Pointer to the Ethernet device structure.
6726 : : * @param[in] counter
6727 : : * Index to the counter handler.
6728 : : * @param[in] cnt
6729 : : * Pointer to the counter handler.
6730 : : */
6731 : : static void
6732 : 0 : flow_dv_counter_remove_from_age(struct rte_eth_dev *dev,
6733 : : uint32_t counter, struct mlx5_flow_counter *cnt)
6734 : : {
6735 : : struct mlx5_age_info *age_info;
6736 : : struct mlx5_age_param *age_param;
6737 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6738 : : uint16_t expected = AGE_CANDIDATE;
6739 : :
6740 [ # # ]: 0 : age_info = GET_PORT_AGE_INFO(priv);
6741 : : age_param = flow_dv_counter_idx_get_age(dev, counter);
6742 [ # # ]: 0 : if (!__atomic_compare_exchange_n(&age_param->state, &expected,
6743 : : AGE_FREE, false, __ATOMIC_RELAXED,
6744 : : __ATOMIC_RELAXED)) {
6745 : : /**
6746 : : * We need the lock even it is age timeout,
6747 : : * since counter may still in process.
6748 : : */
6749 : 0 : rte_spinlock_lock(&age_info->aged_sl);
6750 [ # # ]: 0 : TAILQ_REMOVE(&age_info->aged_counters, cnt, next);
6751 : : rte_spinlock_unlock(&age_info->aged_sl);
6752 : 0 : __atomic_store_n(&age_param->state, AGE_FREE, __ATOMIC_RELAXED);
6753 : : }
6754 : 0 : }
6755 : :
6756 : : /**
6757 : : * Release a flow counter.
6758 : : *
6759 : : * @param[in] dev
6760 : : * Pointer to the Ethernet device structure.
6761 : : * @param[in] counter
6762 : : * Index to the counter handler.
6763 : : */
6764 : : static void
6765 : 0 : flow_dv_counter_free(struct rte_eth_dev *dev, uint32_t counter)
6766 : : {
6767 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6768 : : struct mlx5_flow_counter_pool *pool = NULL;
6769 : : struct mlx5_flow_counter *cnt;
6770 : : enum mlx5_counter_type cnt_type;
6771 : :
6772 [ # # ]: 0 : if (!counter)
6773 : : return;
6774 : : cnt = flow_dv_counter_get_by_idx(dev, counter, &pool);
6775 : : MLX5_ASSERT(pool);
6776 [ # # ]: 0 : if (pool->is_aged) {
6777 : 0 : flow_dv_counter_remove_from_age(dev, counter, cnt);
6778 : : } else {
6779 : : /*
6780 : : * If the counter action is shared by indirect action API,
6781 : : * the atomic function reduces its references counter.
6782 : : * If after the reduction the action is still referenced, the
6783 : : * function returns here and does not release it.
6784 : : * When the counter action is not shared by
6785 : : * indirect action API, shared info is 1 before the reduction,
6786 : : * so this condition is failed and function doesn't return here.
6787 : : */
6788 [ # # ]: 0 : if (__atomic_fetch_sub(&cnt->shared_info.refcnt, 1,
6789 : : __ATOMIC_RELAXED) - 1)
6790 : : return;
6791 : : }
6792 : 0 : cnt->pool = pool;
6793 : : /*
6794 : : * Put the counter back to list to be updated in none fallback mode.
6795 : : * Currently, we are using two list alternately, while one is in query,
6796 : : * add the freed counter to the other list based on the pool query_gen
6797 : : * value. After query finishes, add counter the list to the global
6798 : : * container counter list. The list changes while query starts. In
6799 : : * this case, lock will not be needed as query callback and release
6800 : : * function both operate with the different list.
6801 : : */
6802 [ # # ]: 0 : if (!priv->sh->sws_cmng.counter_fallback) {
6803 : 0 : rte_spinlock_lock(&pool->csl);
6804 : 0 : TAILQ_INSERT_TAIL(&pool->counters[pool->query_gen], cnt, next);
6805 : : rte_spinlock_unlock(&pool->csl);
6806 : : } else {
6807 : 0 : cnt->dcs_when_free = cnt->dcs_when_active;
6808 : 0 : cnt_type = pool->is_aged ? MLX5_COUNTER_TYPE_AGE :
6809 : : MLX5_COUNTER_TYPE_ORIGIN;
6810 : 0 : rte_spinlock_lock(&priv->sh->sws_cmng.csl[cnt_type]);
6811 : 0 : TAILQ_INSERT_TAIL(&priv->sh->sws_cmng.counters[cnt_type],
6812 : : cnt, next);
6813 : 0 : rte_spinlock_unlock(&priv->sh->sws_cmng.csl[cnt_type]);
6814 : : }
6815 : : }
6816 : :
6817 : : /**
6818 : : * Resize a meter id container.
6819 : : *
6820 : : * @param[in] dev
6821 : : * Pointer to the Ethernet device structure.
6822 : : *
6823 : : * @return
6824 : : * 0 on success, otherwise negative errno value and rte_errno is set.
6825 : : */
6826 : : static int
6827 : 0 : flow_dv_mtr_container_resize(struct rte_eth_dev *dev)
6828 : : {
6829 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6830 : : struct mlx5_aso_mtr_pools_mng *pools_mng =
6831 : 0 : &priv->sh->mtrmng->pools_mng;
6832 : 0 : void *old_pools = pools_mng->pools;
6833 : 0 : uint32_t resize = pools_mng->n + MLX5_MTRS_CONTAINER_RESIZE;
6834 : 0 : uint32_t mem_size = sizeof(struct mlx5_aso_mtr_pool *) * resize;
6835 : 0 : void *pools = mlx5_malloc(MLX5_MEM_ZERO, mem_size, 0, SOCKET_ID_ANY);
6836 : :
6837 [ # # ]: 0 : if (!pools) {
6838 : 0 : rte_errno = ENOMEM;
6839 : 0 : return -ENOMEM;
6840 : : }
6841 [ # # ]: 0 : if (!pools_mng->n)
6842 [ # # ]: 0 : if (mlx5_aso_queue_init(priv->sh, ASO_OPC_MOD_POLICER, 1)) {
6843 : 0 : mlx5_free(pools);
6844 : 0 : return -ENOMEM;
6845 : : }
6846 [ # # ]: 0 : if (old_pools)
6847 : 0 : memcpy(pools, old_pools, pools_mng->n *
6848 : : sizeof(struct mlx5_aso_mtr_pool *));
6849 : 0 : pools_mng->n = resize;
6850 : 0 : pools_mng->pools = pools;
6851 [ # # ]: 0 : if (old_pools)
6852 : 0 : mlx5_free(old_pools);
6853 : : return 0;
6854 : : }
6855 : :
6856 : : /**
6857 : : * Prepare a new meter and/or a new meter pool.
6858 : : *
6859 : : * @param[in] dev
6860 : : * Pointer to the Ethernet device structure.
6861 : : * @param[out] mtr_free
6862 : : * Where to put the pointer of a new meter.g.
6863 : : *
6864 : : * @return
6865 : : * The meter pool pointer and @mtr_free is set on success,
6866 : : * NULL otherwise and rte_errno is set.
6867 : : */
6868 : : static struct mlx5_aso_mtr_pool *
6869 : 0 : flow_dv_mtr_pool_create(struct rte_eth_dev *dev, struct mlx5_aso_mtr **mtr_free)
6870 : : {
6871 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6872 : 0 : struct mlx5_aso_mtr_pools_mng *pools_mng = &priv->sh->mtrmng->pools_mng;
6873 : : struct mlx5_aso_mtr_pool *pool = NULL;
6874 : : struct mlx5_devx_obj *dcs = NULL;
6875 : : uint32_t i;
6876 : : uint32_t log_obj_size;
6877 : :
6878 : : log_obj_size = rte_log2_u32(MLX5_ASO_MTRS_PER_POOL >> 1);
6879 : 0 : dcs = mlx5_devx_cmd_create_flow_meter_aso_obj(priv->sh->cdev->ctx,
6880 : 0 : priv->sh->cdev->pdn,
6881 : : log_obj_size);
6882 [ # # ]: 0 : if (!dcs) {
6883 : 0 : rte_errno = ENODATA;
6884 : 0 : return NULL;
6885 : : }
6886 : 0 : pool = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*pool), 0, SOCKET_ID_ANY);
6887 [ # # ]: 0 : if (!pool) {
6888 : 0 : rte_errno = ENOMEM;
6889 : 0 : claim_zero(mlx5_devx_cmd_destroy(dcs));
6890 : 0 : return NULL;
6891 : : }
6892 : 0 : pool->devx_obj = dcs;
6893 : 0 : rte_rwlock_write_lock(&pools_mng->resize_mtrwl);
6894 : 0 : pool->index = pools_mng->n_valid;
6895 [ # # # # ]: 0 : if (pool->index == pools_mng->n && flow_dv_mtr_container_resize(dev)) {
6896 : 0 : mlx5_free(pool);
6897 : 0 : claim_zero(mlx5_devx_cmd_destroy(dcs));
6898 : : rte_rwlock_write_unlock(&pools_mng->resize_mtrwl);
6899 : 0 : return NULL;
6900 : : }
6901 : 0 : pools_mng->pools[pool->index] = pool;
6902 : 0 : pools_mng->n_valid++;
6903 : : rte_rwlock_write_unlock(&pools_mng->resize_mtrwl);
6904 [ # # ]: 0 : for (i = 1; i < MLX5_ASO_MTRS_PER_POOL; ++i) {
6905 : 0 : pool->mtrs[i].offset = i;
6906 [ # # ]: 0 : LIST_INSERT_HEAD(&pools_mng->meters, &pool->mtrs[i], next);
6907 : : }
6908 : 0 : pool->mtrs[0].offset = 0;
6909 : 0 : *mtr_free = &pool->mtrs[0];
6910 : 0 : return pool;
6911 : : }
6912 : :
6913 : : /**
6914 : : * Release a flow meter into pool.
6915 : : *
6916 : : * @param[in] dev
6917 : : * Pointer to the Ethernet device structure.
6918 : : * @param[in] mtr_idx
6919 : : * Index to aso flow meter.
6920 : : */
6921 : : static void
6922 : 0 : flow_dv_aso_mtr_release_to_pool(struct rte_eth_dev *dev, uint32_t mtr_idx)
6923 : : {
6924 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6925 : : struct mlx5_aso_mtr_pools_mng *pools_mng =
6926 : 0 : &priv->sh->mtrmng->pools_mng;
6927 : 0 : struct mlx5_aso_mtr *aso_mtr = mlx5_aso_meter_by_idx(priv, mtr_idx);
6928 : :
6929 : : MLX5_ASSERT(aso_mtr);
6930 : 0 : rte_spinlock_lock(&pools_mng->mtrsl);
6931 [ # # ]: 0 : memset(&aso_mtr->fm, 0, sizeof(struct mlx5_flow_meter_info));
6932 : 0 : aso_mtr->state = ASO_METER_FREE;
6933 [ # # ]: 0 : LIST_INSERT_HEAD(&pools_mng->meters, aso_mtr, next);
6934 : : rte_spinlock_unlock(&pools_mng->mtrsl);
6935 : 0 : }
6936 : :
6937 : : /**
6938 : : * Allocate a aso flow meter.
6939 : : *
6940 : : * @param[in] dev
6941 : : * Pointer to the Ethernet device structure.
6942 : : *
6943 : : * @return
6944 : : * Index to aso flow meter on success, 0 otherwise and rte_errno is set.
6945 : : */
6946 : : static uint32_t
6947 : 0 : flow_dv_mtr_alloc(struct rte_eth_dev *dev)
6948 : : {
6949 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6950 : 0 : struct mlx5_aso_mtr *mtr_free = NULL;
6951 : : struct mlx5_aso_mtr_pools_mng *pools_mng =
6952 : 0 : &priv->sh->mtrmng->pools_mng;
6953 : : struct mlx5_aso_mtr_pool *pool;
6954 : : uint32_t mtr_idx = 0;
6955 : :
6956 [ # # ]: 0 : if (!priv->sh->cdev->config.devx) {
6957 : 0 : rte_errno = ENOTSUP;
6958 : 0 : return 0;
6959 : : }
6960 : : /* Allocate the flow meter memory. */
6961 : : /* Get free meters from management. */
6962 : 0 : rte_spinlock_lock(&pools_mng->mtrsl);
6963 : 0 : mtr_free = LIST_FIRST(&pools_mng->meters);
6964 [ # # ]: 0 : if (mtr_free)
6965 [ # # ]: 0 : LIST_REMOVE(mtr_free, next);
6966 [ # # # # ]: 0 : if (!mtr_free && !flow_dv_mtr_pool_create(dev, &mtr_free)) {
6967 : : rte_spinlock_unlock(&pools_mng->mtrsl);
6968 : 0 : return 0;
6969 : : }
6970 : 0 : mtr_free->state = ASO_METER_WAIT;
6971 : : rte_spinlock_unlock(&pools_mng->mtrsl);
6972 : 0 : pool = container_of(mtr_free,
6973 : : struct mlx5_aso_mtr_pool,
6974 : : mtrs[mtr_free->offset]);
6975 : 0 : mtr_idx = MLX5_MAKE_MTR_IDX(pool->index, mtr_free->offset);
6976 [ # # ]: 0 : if (!mtr_free->fm.meter_action_g) {
6977 : : #ifdef HAVE_MLX5_DR_CREATE_ACTION_ASO
6978 : : struct rte_flow_error error;
6979 : : uint8_t reg_id;
6980 : :
6981 : 0 : reg_id = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, &error);
6982 : 0 : mtr_free->fm.meter_action_g =
6983 : 0 : mlx5_glue->dv_create_flow_action_aso
6984 : 0 : (priv->sh->rx_domain,
6985 : 0 : pool->devx_obj->obj,
6986 : : mtr_free->offset,
6987 : : (1 << MLX5_FLOW_COLOR_GREEN),
6988 : 0 : reg_id - REG_C_0);
6989 : : #endif /* HAVE_MLX5_DR_CREATE_ACTION_ASO */
6990 [ # # ]: 0 : if (!mtr_free->fm.meter_action_g) {
6991 : 0 : flow_dv_aso_mtr_release_to_pool(dev, mtr_idx);
6992 : 0 : return 0;
6993 : : }
6994 : : }
6995 : : return mtr_idx;
6996 : : }
6997 : :
6998 : : /**
6999 : : * Verify the @p attributes will be correctly understood by the NIC and store
7000 : : * them in the @p flow if everything is correct.
7001 : : *
7002 : : * @param[in] dev
7003 : : * Pointer to dev struct.
7004 : : * @param[in] attributes
7005 : : * Pointer to flow attributes
7006 : : * @param[in] external
7007 : : * This flow rule is created by request external to PMD.
7008 : : * @param[out] error
7009 : : * Pointer to error structure.
7010 : : *
7011 : : * @return
7012 : : * - 0 on success and non root table.
7013 : : * - 1 on success and root table.
7014 : : * - a negative errno value otherwise and rte_errno is set.
7015 : : */
7016 : : static int
7017 : 0 : flow_dv_validate_attributes(struct rte_eth_dev *dev,
7018 : : const struct mlx5_flow_tunnel *tunnel,
7019 : : const struct rte_flow_attr *attributes,
7020 : : const struct flow_grp_info *grp_info,
7021 : : struct rte_flow_error *error)
7022 : : {
7023 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7024 : 0 : uint32_t lowest_priority = mlx5_get_lowest_priority(dev, attributes);
7025 : : int ret = 0;
7026 : :
7027 : : #ifndef HAVE_MLX5DV_DR
7028 : : RTE_SET_USED(tunnel);
7029 : : RTE_SET_USED(grp_info);
7030 : : if (attributes->group)
7031 : : return rte_flow_error_set(error, ENOTSUP,
7032 : : RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
7033 : : NULL,
7034 : : "groups are not supported");
7035 : : #else
7036 : 0 : uint32_t table = 0;
7037 : :
7038 : 0 : ret = mlx5_flow_group_to_table(dev, tunnel, attributes->group, &table,
7039 : : grp_info, error);
7040 [ # # ]: 0 : if (ret)
7041 : : return ret;
7042 [ # # ]: 0 : if (!table)
7043 : : ret = MLX5DV_DR_ACTION_FLAGS_ROOT_LEVEL;
7044 : : #endif
7045 [ # # # # ]: 0 : if (attributes->priority != MLX5_FLOW_LOWEST_PRIO_INDICATOR &&
7046 : : attributes->priority > lowest_priority)
7047 : 0 : return rte_flow_error_set(error, ENOTSUP,
7048 : : RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
7049 : : NULL,
7050 : : "priority out of range");
7051 [ # # # # ]: 0 : if (attributes->transfer && !priv->sh->config.dv_esw_en)
7052 : 0 : return rte_flow_error_set(error, ENOTSUP,
7053 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
7054 : : "E-Switch dr is not supported");
7055 [ # # ]: 0 : if (attributes->ingress + attributes->egress + attributes->transfer != 1) {
7056 : 0 : return rte_flow_error_set(error, EINVAL,
7057 : : RTE_FLOW_ERROR_TYPE_ATTR, NULL,
7058 : : "must specify exactly one of "
7059 : : "ingress, egress or transfer");
7060 : : }
7061 : : return ret;
7062 : : }
7063 : :
7064 : : static int
7065 : 0 : validate_integrity_bits(const struct rte_flow_item_integrity *mask,
7066 : : int64_t pattern_flags, uint64_t l3_flags,
7067 : : uint64_t l4_flags, uint64_t ip4_flag,
7068 : : struct rte_flow_error *error)
7069 : : {
7070 [ # # # # ]: 0 : if (mask->l3_ok && !(pattern_flags & l3_flags))
7071 : 0 : return rte_flow_error_set(error, EINVAL,
7072 : : RTE_FLOW_ERROR_TYPE_ITEM,
7073 : : NULL, "missing L3 protocol");
7074 : :
7075 [ # # # # ]: 0 : if (mask->ipv4_csum_ok && !(pattern_flags & ip4_flag))
7076 : 0 : return rte_flow_error_set(error, EINVAL,
7077 : : RTE_FLOW_ERROR_TYPE_ITEM,
7078 : : NULL, "missing IPv4 protocol");
7079 : :
7080 [ # # # # ]: 0 : if ((mask->l4_ok || mask->l4_csum_ok) && !(pattern_flags & l4_flags))
7081 : 0 : return rte_flow_error_set(error, EINVAL,
7082 : : RTE_FLOW_ERROR_TYPE_ITEM,
7083 : : NULL, "missing L4 protocol");
7084 : :
7085 : : return 0;
7086 : : }
7087 : :
7088 : : static int
7089 : 0 : flow_dv_validate_item_integrity_post(const struct
7090 : : rte_flow_item *integrity_items[2],
7091 : : int64_t pattern_flags,
7092 : : struct rte_flow_error *error)
7093 : : {
7094 : : const struct rte_flow_item_integrity *mask;
7095 : : int ret;
7096 : :
7097 [ # # ]: 0 : if (pattern_flags & MLX5_FLOW_ITEM_OUTER_INTEGRITY) {
7098 : 0 : mask = (typeof(mask))integrity_items[0]->mask;
7099 : 0 : ret = validate_integrity_bits(mask, pattern_flags,
7100 : : MLX5_FLOW_LAYER_OUTER_L3,
7101 : : MLX5_FLOW_LAYER_OUTER_L4,
7102 : : MLX5_FLOW_LAYER_OUTER_L3_IPV4,
7103 : : error);
7104 [ # # ]: 0 : if (ret)
7105 : : return ret;
7106 : : }
7107 [ # # ]: 0 : if (pattern_flags & MLX5_FLOW_ITEM_INNER_INTEGRITY) {
7108 : 0 : mask = (typeof(mask))integrity_items[1]->mask;
7109 : 0 : ret = validate_integrity_bits(mask, pattern_flags,
7110 : : MLX5_FLOW_LAYER_INNER_L3,
7111 : : MLX5_FLOW_LAYER_INNER_L4,
7112 : : MLX5_FLOW_LAYER_INNER_L3_IPV4,
7113 : : error);
7114 [ # # ]: 0 : if (ret)
7115 : 0 : return ret;
7116 : : }
7117 : : return 0;
7118 : : }
7119 : :
7120 : : static int
7121 : 0 : flow_dv_validate_item_integrity(struct rte_eth_dev *dev,
7122 : : const struct rte_flow_item *integrity_item,
7123 : : uint64_t pattern_flags, uint64_t *last_item,
7124 : : const struct rte_flow_item *integrity_items[2],
7125 : : struct rte_flow_error *error)
7126 : : {
7127 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7128 : 0 : const struct rte_flow_item_integrity *mask = (typeof(mask))
7129 : : integrity_item->mask;
7130 : 0 : const struct rte_flow_item_integrity *spec = (typeof(spec))
7131 : : integrity_item->spec;
7132 : :
7133 [ # # ]: 0 : if (!priv->sh->cdev->config.hca_attr.pkt_integrity_match)
7134 : 0 : return rte_flow_error_set(error, ENOTSUP,
7135 : : RTE_FLOW_ERROR_TYPE_ITEM,
7136 : : integrity_item,
7137 : : "packet integrity integrity_item not supported");
7138 [ # # ]: 0 : if (!spec)
7139 : 0 : return rte_flow_error_set(error, ENOTSUP,
7140 : : RTE_FLOW_ERROR_TYPE_ITEM,
7141 : : integrity_item,
7142 : : "no spec for integrity item");
7143 [ # # ]: 0 : if (!mask)
7144 : : mask = &rte_flow_item_integrity_mask;
7145 [ # # ]: 0 : if (!mlx5_validate_integrity_item(mask))
7146 : 0 : return rte_flow_error_set(error, ENOTSUP,
7147 : : RTE_FLOW_ERROR_TYPE_ITEM,
7148 : : integrity_item,
7149 : : "unsupported integrity filter");
7150 [ # # # # ]: 0 : if ((mask->l3_ok & !spec->l3_ok) || (mask->l4_ok & !spec->l4_ok) ||
7151 [ # # ]: 0 : (mask->ipv4_csum_ok & !spec->ipv4_csum_ok) ||
7152 [ # # ]: 0 : (mask->l4_csum_ok & !spec->l4_csum_ok))
7153 : 0 : return rte_flow_error_set(error, EINVAL,
7154 : : RTE_FLOW_ERROR_TYPE_ITEM,
7155 : : NULL, "negative integrity flow is not supported");
7156 [ # # ]: 0 : if (spec->level > 1) {
7157 [ # # ]: 0 : if (pattern_flags & MLX5_FLOW_ITEM_INNER_INTEGRITY)
7158 : 0 : return rte_flow_error_set
7159 : : (error, ENOTSUP,
7160 : : RTE_FLOW_ERROR_TYPE_ITEM,
7161 : : NULL, "multiple inner integrity items not supported");
7162 : 0 : integrity_items[1] = integrity_item;
7163 : 0 : *last_item |= MLX5_FLOW_ITEM_INNER_INTEGRITY;
7164 : : } else {
7165 [ # # ]: 0 : if (pattern_flags & MLX5_FLOW_ITEM_OUTER_INTEGRITY)
7166 : 0 : return rte_flow_error_set
7167 : : (error, ENOTSUP,
7168 : : RTE_FLOW_ERROR_TYPE_ITEM,
7169 : : NULL, "multiple outer integrity items not supported");
7170 : 0 : integrity_items[0] = integrity_item;
7171 : 0 : *last_item |= MLX5_FLOW_ITEM_OUTER_INTEGRITY;
7172 : : }
7173 : : return 0;
7174 : : }
7175 : :
7176 : : static int
7177 : 0 : flow_dv_validate_item_flex(struct rte_eth_dev *dev,
7178 : : const struct rte_flow_item *item,
7179 : : uint64_t item_flags,
7180 : : uint64_t *last_item,
7181 : : bool is_inner,
7182 : : struct rte_flow_error *error)
7183 : : {
7184 : 0 : const struct rte_flow_item_flex *flow_spec = item->spec;
7185 : 0 : const struct rte_flow_item_flex *flow_mask = item->mask;
7186 : : struct mlx5_flex_item *flex;
7187 : :
7188 [ # # ]: 0 : if (!flow_spec)
7189 : 0 : return rte_flow_error_set(error, EINVAL,
7190 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
7191 : : "flex flow item spec cannot be NULL");
7192 [ # # ]: 0 : if (!flow_mask)
7193 : 0 : return rte_flow_error_set(error, EINVAL,
7194 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
7195 : : "flex flow item mask cannot be NULL");
7196 [ # # ]: 0 : if (item->last)
7197 : 0 : return rte_flow_error_set(error, ENOTSUP,
7198 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
7199 : : "flex flow item last not supported");
7200 [ # # ]: 0 : if (mlx5_flex_acquire_index(dev, flow_spec->handle, false) < 0)
7201 : 0 : return rte_flow_error_set(error, EINVAL,
7202 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
7203 : : "invalid flex flow item handle");
7204 : 0 : flex = (struct mlx5_flex_item *)flow_spec->handle;
7205 [ # # # # : 0 : switch (flex->tunnel_mode) {
# # ]
7206 : 0 : case FLEX_TUNNEL_MODE_SINGLE:
7207 [ # # ]: 0 : if (item_flags &
7208 : : (MLX5_FLOW_ITEM_OUTER_FLEX | MLX5_FLOW_ITEM_INNER_FLEX))
7209 : 0 : rte_flow_error_set(error, EINVAL,
7210 : : RTE_FLOW_ERROR_TYPE_ITEM,
7211 : : NULL, "multiple flex items not supported");
7212 : : break;
7213 : 0 : case FLEX_TUNNEL_MODE_OUTER:
7214 [ # # ]: 0 : if (is_inner)
7215 : 0 : rte_flow_error_set(error, EINVAL,
7216 : : RTE_FLOW_ERROR_TYPE_ITEM,
7217 : : NULL, "inner flex item was not configured");
7218 [ # # ]: 0 : if (item_flags & MLX5_FLOW_ITEM_OUTER_FLEX)
7219 : 0 : rte_flow_error_set(error, ENOTSUP,
7220 : : RTE_FLOW_ERROR_TYPE_ITEM,
7221 : : NULL, "multiple flex items not supported");
7222 : : break;
7223 : 0 : case FLEX_TUNNEL_MODE_INNER:
7224 [ # # ]: 0 : if (!is_inner)
7225 : 0 : rte_flow_error_set(error, EINVAL,
7226 : : RTE_FLOW_ERROR_TYPE_ITEM,
7227 : : NULL, "outer flex item was not configured");
7228 [ # # ]: 0 : if (item_flags & MLX5_FLOW_ITEM_INNER_FLEX)
7229 : 0 : rte_flow_error_set(error, EINVAL,
7230 : : RTE_FLOW_ERROR_TYPE_ITEM,
7231 : : NULL, "multiple flex items not supported");
7232 : : break;
7233 : 0 : case FLEX_TUNNEL_MODE_MULTI:
7234 [ # # # # : 0 : if ((is_inner && (item_flags & MLX5_FLOW_ITEM_INNER_FLEX)) ||
# # ]
7235 [ # # ]: 0 : (!is_inner && (item_flags & MLX5_FLOW_ITEM_OUTER_FLEX))) {
7236 : 0 : rte_flow_error_set(error, EINVAL,
7237 : : RTE_FLOW_ERROR_TYPE_ITEM,
7238 : : NULL, "multiple flex items not supported");
7239 : : }
7240 : : break;
7241 : 0 : case FLEX_TUNNEL_MODE_TUNNEL:
7242 [ # # # # ]: 0 : if (is_inner || (item_flags & MLX5_FLOW_ITEM_FLEX_TUNNEL))
7243 : 0 : rte_flow_error_set(error, EINVAL,
7244 : : RTE_FLOW_ERROR_TYPE_ITEM,
7245 : : NULL, "multiple flex tunnel items not supported");
7246 : : break;
7247 : 0 : default:
7248 : 0 : rte_flow_error_set(error, EINVAL,
7249 : : RTE_FLOW_ERROR_TYPE_ITEM,
7250 : : NULL, "invalid flex item configuration");
7251 : : }
7252 : 0 : *last_item = flex->tunnel_mode == FLEX_TUNNEL_MODE_TUNNEL ?
7253 [ # # ]: 0 : MLX5_FLOW_ITEM_FLEX_TUNNEL : is_inner ?
7254 [ # # ]: 0 : MLX5_FLOW_ITEM_INNER_FLEX : MLX5_FLOW_ITEM_OUTER_FLEX;
7255 : 0 : return 0;
7256 : : }
7257 : :
7258 : : /**
7259 : : * Validate IB BTH item.
7260 : : *
7261 : : * @param[in] dev
7262 : : * Pointer to the rte_eth_dev structure.
7263 : : * @param[in] udp_dport
7264 : : * UDP destination port
7265 : : * @param[in] item
7266 : : * Item specification.
7267 : : * @param root
7268 : : * Whether action is on root table.
7269 : : * @param[out] error
7270 : : * Pointer to the error structure.
7271 : : *
7272 : : * @return
7273 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
7274 : : */
7275 : : static int
7276 : 0 : mlx5_flow_validate_item_ib_bth(struct rte_eth_dev *dev,
7277 : : uint16_t udp_dport,
7278 : : const struct rte_flow_item *item,
7279 : : bool root,
7280 : : struct rte_flow_error *error)
7281 : : {
7282 : 0 : const struct rte_flow_item_ib_bth *mask = item->mask;
7283 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7284 : : const struct rte_flow_item_ib_bth *valid_mask;
7285 : : int ret;
7286 : :
7287 : : valid_mask = &rte_flow_item_ib_bth_mask;
7288 [ # # ]: 0 : if (udp_dport && udp_dport != MLX5_UDP_PORT_ROCEv2)
7289 : 0 : return rte_flow_error_set(error, EINVAL,
7290 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
7291 : : "protocol filtering not compatible"
7292 : : " with UDP layer");
7293 [ # # # # ]: 0 : if (mask && (mask->hdr.se || mask->hdr.m || mask->hdr.padcnt ||
7294 [ # # # # ]: 0 : mask->hdr.tver || mask->hdr.pkey || mask->hdr.f || mask->hdr.b ||
7295 [ # # ]: 0 : mask->hdr.rsvd0 || mask->hdr.a || mask->hdr.rsvd1 ||
7296 [ # # # # : 0 : mask->hdr.psn[0] || mask->hdr.psn[1] || mask->hdr.psn[2]))
# # ]
7297 : 0 : return rte_flow_error_set(error, EINVAL,
7298 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
7299 : : "only opcode and dst_qp are supported");
7300 [ # # # # ]: 0 : if (root || priv->sh->steering_format_version ==
7301 : : MLX5_STEERING_LOGIC_FORMAT_CONNECTX_5)
7302 : 0 : return rte_flow_error_set(error, EINVAL,
7303 : : RTE_FLOW_ERROR_TYPE_ITEM,
7304 : : item,
7305 : : "IB BTH item is not supported");
7306 [ # # ]: 0 : if (!mask)
7307 : : mask = &rte_flow_item_ib_bth_mask;
7308 : 0 : ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
7309 : : (const uint8_t *)valid_mask,
7310 : : sizeof(struct rte_flow_item_ib_bth),
7311 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
7312 : : if (ret < 0)
7313 : : return ret;
7314 : : return 0;
7315 : : }
7316 : :
7317 : : /**
7318 : : * Internal validation function. For validating both actions and items.
7319 : : *
7320 : : * @param[in] dev
7321 : : * Pointer to the rte_eth_dev structure.
7322 : : * @param[in] attr
7323 : : * Pointer to the flow attributes.
7324 : : * @param[in] items
7325 : : * Pointer to the list of items.
7326 : : * @param[in] actions
7327 : : * Pointer to the list of actions.
7328 : : * @param[in] external
7329 : : * This flow rule is created by request external to PMD.
7330 : : * @param[in] hairpin
7331 : : * Number of hairpin TX actions, 0 means classic flow.
7332 : : * @param[out] error
7333 : : * Pointer to the error structure.
7334 : : *
7335 : : * @return
7336 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
7337 : : */
7338 : : static int
7339 : 0 : flow_dv_validate(struct rte_eth_dev *dev, const struct rte_flow_attr *attr,
7340 : : const struct rte_flow_item items[],
7341 : : const struct rte_flow_action actions[],
7342 : : bool external, int hairpin, struct rte_flow_error *error)
7343 : : {
7344 : : int ret;
7345 : 0 : uint64_t aso_mask, action_flags = 0;
7346 : 0 : uint64_t item_flags = 0;
7347 : 0 : uint64_t last_item = 0;
7348 : : uint8_t next_protocol = 0xff;
7349 : : uint16_t ether_type = 0;
7350 : 0 : int actions_n = 0;
7351 : : uint8_t item_ipv6_proto = 0;
7352 : 0 : int fdb_mirror = 0;
7353 : : int modify_after_mirror = 0;
7354 : : const struct rte_flow_item *geneve_item = NULL;
7355 : : const struct rte_flow_item *gre_item = NULL;
7356 : : const struct rte_flow_item *gtp_item = NULL;
7357 : : const struct rte_flow_action_raw_decap *decap;
7358 : : const struct rte_flow_action_raw_encap *encap;
7359 : : const struct rte_flow_action_rss *rss = NULL;
7360 : 0 : const struct rte_flow_action_rss *sample_rss = NULL;
7361 : 0 : const struct rte_flow_action_count *sample_count = NULL;
7362 : 0 : const struct rte_flow_item_tcp nic_tcp_mask = {
7363 : : .hdr = {
7364 : : .tcp_flags = 0xFF,
7365 : : .src_port = RTE_BE16(UINT16_MAX),
7366 : : .dst_port = RTE_BE16(UINT16_MAX),
7367 : : }
7368 : : };
7369 : 0 : const struct rte_flow_item_ipv6 nic_ipv6_mask = {
7370 : : .hdr = {
7371 : : .src_addr =
7372 : : "\xff\xff\xff\xff\xff\xff\xff\xff"
7373 : : "\xff\xff\xff\xff\xff\xff\xff\xff",
7374 : : .dst_addr =
7375 : : "\xff\xff\xff\xff\xff\xff\xff\xff"
7376 : : "\xff\xff\xff\xff\xff\xff\xff\xff",
7377 : : .vtc_flow = RTE_BE32(0xffffffff),
7378 : : .proto = 0xff,
7379 : : .hop_limits = 0xff,
7380 : : },
7381 : : .has_frag_ext = 1,
7382 : : };
7383 : 0 : const struct rte_flow_item_ecpri nic_ecpri_mask = {
7384 : : .hdr = {
7385 : : .common = {
7386 : : .u32 =
7387 : : RTE_BE32(((const struct rte_ecpri_common_hdr) {
7388 : : .type = 0xFF,
7389 : : }).u32),
7390 : : },
7391 : : .dummy[0] = 0xffffffff,
7392 : : },
7393 : : };
7394 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7395 : 0 : struct mlx5_sh_config *dev_conf = &priv->sh->config;
7396 : : uint16_t queue_index = 0xFFFF;
7397 : : const struct rte_flow_item_vlan *vlan_m = NULL;
7398 : : uint32_t rw_act_num = 0;
7399 : : uint64_t is_root;
7400 : : const struct mlx5_flow_tunnel *tunnel;
7401 : : enum mlx5_tof_rule_type tof_rule_type;
7402 : 0 : struct flow_grp_info grp_info = {
7403 : : .external = !!external,
7404 : 0 : .transfer = !!attr->transfer,
7405 : 0 : .fdb_def_rule = !!priv->fdb_def_rule,
7406 : : .std_tbl_fix = true,
7407 : : };
7408 : : const struct rte_eth_hairpin_conf *conf;
7409 : 0 : const struct rte_flow_item *integrity_items[2] = {NULL, NULL};
7410 : : const struct rte_flow_item *port_id_item = NULL;
7411 : 0 : bool def_policy = false;
7412 : : bool shared_count = false;
7413 : : uint16_t udp_dport = 0;
7414 : 0 : uint32_t tag_id = 0, tag_bitmap = 0;
7415 : : const struct rte_flow_action_age *non_shared_age = NULL;
7416 : : const struct rte_flow_action_count *count = NULL;
7417 : : const struct rte_flow_action_port_id *port = NULL;
7418 : : const struct mlx5_rte_flow_item_tag *mlx5_tag;
7419 : 0 : struct mlx5_priv *act_priv = NULL;
7420 : : int aso_after_sample = 0;
7421 : : struct mlx5_priv *port_priv = NULL;
7422 : 0 : uint64_t sub_action_flags = 0;
7423 : 0 : uint16_t sample_port_id = 0;
7424 : : uint16_t port_id = 0;
7425 : :
7426 [ # # ]: 0 : if (items == NULL)
7427 : : return -1;
7428 : : tunnel = is_tunnel_offload_active(dev) ?
7429 [ # # ]: 0 : mlx5_get_tof(items, actions, &tof_rule_type) : NULL;
7430 [ # # ]: 0 : if (tunnel) {
7431 [ # # ]: 0 : if (!dev_conf->dv_flow_en)
7432 : 0 : return rte_flow_error_set
7433 : : (error, ENOTSUP,
7434 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7435 : : NULL, "tunnel offload requires DV flow interface");
7436 [ # # ]: 0 : if (priv->representor)
7437 : 0 : return rte_flow_error_set
7438 : : (error, ENOTSUP,
7439 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7440 : : NULL, "decap not supported for VF representor");
7441 [ # # ]: 0 : if (tof_rule_type == MLX5_TUNNEL_OFFLOAD_SET_RULE)
7442 : 0 : action_flags |= MLX5_FLOW_ACTION_TUNNEL_SET;
7443 [ # # ]: 0 : else if (tof_rule_type == MLX5_TUNNEL_OFFLOAD_MATCH_RULE)
7444 : 0 : action_flags |= MLX5_FLOW_ACTION_TUNNEL_MATCH |
7445 : : MLX5_FLOW_ACTION_DECAP;
7446 : 0 : grp_info.std_tbl_fix = tunnel_use_standard_attr_group_translate
7447 : : (dev, attr, tunnel, tof_rule_type);
7448 : : }
7449 : 0 : ret = flow_dv_validate_attributes(dev, tunnel, attr, &grp_info, error);
7450 [ # # ]: 0 : if (ret < 0)
7451 : : return ret;
7452 : 0 : is_root = (uint64_t)ret;
7453 [ # # ]: 0 : for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
7454 : 0 : int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
7455 : 0 : int type = items->type;
7456 : :
7457 : : if (!mlx5_flow_os_item_supported(type))
7458 : : return rte_flow_error_set(error, ENOTSUP,
7459 : : RTE_FLOW_ERROR_TYPE_ITEM,
7460 : : NULL, "item not supported");
7461 [ # # # # : 0 : switch (type) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # #
# ]
7462 : : case RTE_FLOW_ITEM_TYPE_VOID:
7463 : : break;
7464 : 0 : case RTE_FLOW_ITEM_TYPE_ESP:
7465 : 0 : ret = mlx5_flow_os_validate_item_esp(items, item_flags,
7466 : : next_protocol,
7467 : : error);
7468 [ # # ]: 0 : if (ret < 0)
7469 : 0 : return ret;
7470 : 0 : last_item = MLX5_FLOW_ITEM_ESP;
7471 : 0 : break;
7472 : 0 : case RTE_FLOW_ITEM_TYPE_PORT_ID:
7473 : 0 : ret = flow_dv_validate_item_port_id
7474 : : (dev, items, attr, item_flags, &act_priv, error);
7475 [ # # ]: 0 : if (ret < 0)
7476 : 0 : return ret;
7477 : 0 : last_item = MLX5_FLOW_ITEM_PORT_ID;
7478 : : port_id_item = items;
7479 : 0 : break;
7480 : 0 : case RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT:
7481 : : case RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR:
7482 : 0 : ret = flow_dv_validate_item_represented_port
7483 : : (dev, items, attr, item_flags, &act_priv, error);
7484 [ # # ]: 0 : if (ret < 0)
7485 : 0 : return ret;
7486 : 0 : last_item = MLX5_FLOW_ITEM_REPRESENTED_PORT;
7487 : : port_id_item = items;
7488 : 0 : break;
7489 : 0 : case RTE_FLOW_ITEM_TYPE_ETH:
7490 : 0 : ret = mlx5_flow_validate_item_eth(items, item_flags,
7491 : : true, error);
7492 [ # # ]: 0 : if (ret < 0)
7493 : 0 : return ret;
7494 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
7495 : : MLX5_FLOW_LAYER_OUTER_L2;
7496 [ # # # # ]: 0 : if (items->mask != NULL && items->spec != NULL) {
7497 : 0 : ether_type =
7498 : : ((const struct rte_flow_item_eth *)
7499 : : items->spec)->hdr.ether_type;
7500 : 0 : ether_type &=
7501 : : ((const struct rte_flow_item_eth *)
7502 : 0 : items->mask)->hdr.ether_type;
7503 [ # # ]: 0 : ether_type = rte_be_to_cpu_16(ether_type);
7504 : : } else {
7505 : : ether_type = 0;
7506 : : }
7507 : : break;
7508 : 0 : case RTE_FLOW_ITEM_TYPE_VLAN:
7509 : 0 : ret = flow_dv_validate_item_vlan(items, item_flags,
7510 : : dev, error);
7511 [ # # ]: 0 : if (ret < 0)
7512 : 0 : return ret;
7513 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
7514 : : MLX5_FLOW_LAYER_OUTER_VLAN;
7515 [ # # # # ]: 0 : if (items->mask != NULL && items->spec != NULL) {
7516 : 0 : ether_type =
7517 : : ((const struct rte_flow_item_vlan *)
7518 : : items->spec)->hdr.eth_proto;
7519 : 0 : ether_type &=
7520 : : ((const struct rte_flow_item_vlan *)
7521 : 0 : items->mask)->hdr.eth_proto;
7522 [ # # ]: 0 : ether_type = rte_be_to_cpu_16(ether_type);
7523 : : } else {
7524 : : ether_type = 0;
7525 : : }
7526 : : /* Store outer VLAN mask for of_push_vlan action. */
7527 [ # # ]: 0 : if (!tunnel)
7528 : : vlan_m = items->mask;
7529 : : break;
7530 [ # # ]: 0 : case RTE_FLOW_ITEM_TYPE_IPV4:
7531 : : mlx5_flow_tunnel_ip_check(items, next_protocol,
7532 : : &item_flags, &tunnel);
7533 : 0 : ret = flow_dv_validate_item_ipv4(dev, items, item_flags,
7534 : : last_item, ether_type,
7535 : : error);
7536 [ # # ]: 0 : if (ret < 0)
7537 : 0 : return ret;
7538 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
7539 : : MLX5_FLOW_LAYER_OUTER_L3_IPV4;
7540 [ # # ]: 0 : if (items->mask != NULL &&
7541 : : ((const struct rte_flow_item_ipv4 *)
7542 [ # # ]: 0 : items->mask)->hdr.next_proto_id) {
7543 : 0 : next_protocol =
7544 : : ((const struct rte_flow_item_ipv4 *)
7545 : 0 : (items->spec))->hdr.next_proto_id;
7546 : 0 : next_protocol &=
7547 : : ((const struct rte_flow_item_ipv4 *)
7548 : : (items->mask))->hdr.next_proto_id;
7549 : : } else {
7550 : : /* Reset for inner layer. */
7551 : : next_protocol = 0xff;
7552 : : }
7553 : : break;
7554 [ # # ]: 0 : case RTE_FLOW_ITEM_TYPE_IPV6:
7555 : : mlx5_flow_tunnel_ip_check(items, next_protocol,
7556 : : &item_flags, &tunnel);
7557 : 0 : ret = mlx5_flow_validate_item_ipv6(items, item_flags,
7558 : : last_item,
7559 : : ether_type,
7560 : : &nic_ipv6_mask,
7561 : : error);
7562 [ # # ]: 0 : if (ret < 0)
7563 : 0 : return ret;
7564 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
7565 : : MLX5_FLOW_LAYER_OUTER_L3_IPV6;
7566 [ # # ]: 0 : if (items->mask != NULL &&
7567 : : ((const struct rte_flow_item_ipv6 *)
7568 [ # # ]: 0 : items->mask)->hdr.proto) {
7569 : 0 : item_ipv6_proto =
7570 : : ((const struct rte_flow_item_ipv6 *)
7571 : 0 : items->spec)->hdr.proto;
7572 : : next_protocol =
7573 : : ((const struct rte_flow_item_ipv6 *)
7574 : : items->spec)->hdr.proto;
7575 : 0 : next_protocol &=
7576 : : ((const struct rte_flow_item_ipv6 *)
7577 : : items->mask)->hdr.proto;
7578 : : } else {
7579 : : /* Reset for inner layer. */
7580 : : next_protocol = 0xff;
7581 : : }
7582 : : break;
7583 : 0 : case RTE_FLOW_ITEM_TYPE_IPV6_FRAG_EXT:
7584 : 0 : ret = flow_dv_validate_item_ipv6_frag_ext(items,
7585 : : item_flags,
7586 : : error);
7587 [ # # ]: 0 : if (ret < 0)
7588 : 0 : return ret;
7589 : 0 : last_item = tunnel ?
7590 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_L3_IPV6_FRAG_EXT :
7591 : : MLX5_FLOW_LAYER_OUTER_L3_IPV6_FRAG_EXT;
7592 [ # # ]: 0 : if (items->mask != NULL &&
7593 : : ((const struct rte_flow_item_ipv6_frag_ext *)
7594 [ # # ]: 0 : items->mask)->hdr.next_header) {
7595 : 0 : next_protocol =
7596 : : ((const struct rte_flow_item_ipv6_frag_ext *)
7597 : 0 : items->spec)->hdr.next_header;
7598 : 0 : next_protocol &=
7599 : : ((const struct rte_flow_item_ipv6_frag_ext *)
7600 : : items->mask)->hdr.next_header;
7601 : : } else {
7602 : : /* Reset for inner layer. */
7603 : : next_protocol = 0xff;
7604 : : }
7605 : : break;
7606 : 0 : case RTE_FLOW_ITEM_TYPE_TCP:
7607 : 0 : ret = mlx5_flow_validate_item_tcp
7608 : : (items, item_flags,
7609 : : next_protocol,
7610 : : &nic_tcp_mask,
7611 : : error);
7612 [ # # ]: 0 : if (ret < 0)
7613 : 0 : return ret;
7614 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_TCP :
7615 : : MLX5_FLOW_LAYER_OUTER_L4_TCP;
7616 : 0 : break;
7617 : 0 : case RTE_FLOW_ITEM_TYPE_UDP:
7618 : 0 : ret = mlx5_flow_validate_item_udp(items, item_flags,
7619 : : next_protocol,
7620 : : error);
7621 : 0 : const struct rte_flow_item_udp *spec = items->spec;
7622 : 0 : const struct rte_flow_item_udp *mask = items->mask;
7623 [ # # ]: 0 : if (!mask)
7624 : : mask = &rte_flow_item_udp_mask;
7625 [ # # ]: 0 : if (spec != NULL)
7626 [ # # ]: 0 : udp_dport = rte_be_to_cpu_16
7627 : : (spec->hdr.dst_port &
7628 : : mask->hdr.dst_port);
7629 [ # # ]: 0 : if (ret < 0)
7630 : 0 : return ret;
7631 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_UDP :
7632 : : MLX5_FLOW_LAYER_OUTER_L4_UDP;
7633 : 0 : break;
7634 : 0 : case RTE_FLOW_ITEM_TYPE_GRE:
7635 : 0 : ret = mlx5_flow_validate_item_gre(items, item_flags,
7636 : : next_protocol, error);
7637 [ # # ]: 0 : if (ret < 0)
7638 : 0 : return ret;
7639 : : gre_item = items;
7640 : 0 : last_item = MLX5_FLOW_LAYER_GRE;
7641 : 0 : break;
7642 : 0 : case RTE_FLOW_ITEM_TYPE_GRE_OPTION:
7643 : 0 : ret = mlx5_flow_validate_item_gre_option(dev, items, item_flags,
7644 : : attr, gre_item, error);
7645 [ # # ]: 0 : if (ret < 0)
7646 : 0 : return ret;
7647 : 0 : last_item = MLX5_FLOW_LAYER_GRE;
7648 : 0 : break;
7649 : 0 : case RTE_FLOW_ITEM_TYPE_NVGRE:
7650 : 0 : ret = mlx5_flow_validate_item_nvgre(items, item_flags,
7651 : : next_protocol,
7652 : : error);
7653 [ # # ]: 0 : if (ret < 0)
7654 : 0 : return ret;
7655 : 0 : last_item = MLX5_FLOW_LAYER_NVGRE;
7656 : 0 : break;
7657 : 0 : case RTE_FLOW_ITEM_TYPE_GRE_KEY:
7658 : 0 : ret = mlx5_flow_validate_item_gre_key
7659 : : (items, item_flags, gre_item, error);
7660 [ # # ]: 0 : if (ret < 0)
7661 : 0 : return ret;
7662 : 0 : last_item = MLX5_FLOW_LAYER_GRE_KEY;
7663 : 0 : break;
7664 : 0 : case RTE_FLOW_ITEM_TYPE_VXLAN:
7665 : 0 : ret = mlx5_flow_validate_item_vxlan(dev, udp_dport,
7666 : : items, item_flags,
7667 : : is_root, error);
7668 [ # # ]: 0 : if (ret < 0)
7669 : 0 : return ret;
7670 : 0 : last_item = MLX5_FLOW_LAYER_VXLAN;
7671 : 0 : break;
7672 : 0 : case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
7673 : 0 : ret = mlx5_flow_validate_item_vxlan_gpe(items,
7674 : : item_flags, dev,
7675 : : error);
7676 [ # # ]: 0 : if (ret < 0)
7677 : 0 : return ret;
7678 : 0 : last_item = MLX5_FLOW_LAYER_VXLAN_GPE;
7679 : 0 : break;
7680 : 0 : case RTE_FLOW_ITEM_TYPE_GENEVE:
7681 : 0 : ret = mlx5_flow_validate_item_geneve(items,
7682 : : item_flags, dev,
7683 : : error);
7684 [ # # ]: 0 : if (ret < 0)
7685 : 0 : return ret;
7686 : : geneve_item = items;
7687 : 0 : last_item = MLX5_FLOW_LAYER_GENEVE;
7688 : 0 : break;
7689 : 0 : case RTE_FLOW_ITEM_TYPE_GENEVE_OPT:
7690 : 0 : ret = mlx5_flow_validate_item_geneve_opt(items,
7691 : : last_item,
7692 : : geneve_item,
7693 : : dev,
7694 : : error);
7695 [ # # ]: 0 : if (ret < 0)
7696 : 0 : return ret;
7697 : 0 : last_item = MLX5_FLOW_LAYER_GENEVE_OPT;
7698 : 0 : break;
7699 : 0 : case RTE_FLOW_ITEM_TYPE_MPLS:
7700 : 0 : ret = mlx5_flow_validate_item_mpls(dev, items,
7701 : : item_flags,
7702 : : last_item, error);
7703 [ # # ]: 0 : if (ret < 0)
7704 : 0 : return ret;
7705 : 0 : last_item = MLX5_FLOW_LAYER_MPLS;
7706 : 0 : break;
7707 : :
7708 : 0 : case RTE_FLOW_ITEM_TYPE_MARK:
7709 : 0 : ret = flow_dv_validate_item_mark(dev, items, attr,
7710 : : error);
7711 [ # # ]: 0 : if (ret < 0)
7712 : 0 : return ret;
7713 : 0 : last_item = MLX5_FLOW_ITEM_MARK;
7714 : 0 : break;
7715 : 0 : case RTE_FLOW_ITEM_TYPE_META:
7716 : 0 : ret = flow_dv_validate_item_meta(dev, items, attr,
7717 : : error);
7718 [ # # ]: 0 : if (ret < 0)
7719 : 0 : return ret;
7720 : 0 : last_item = MLX5_FLOW_ITEM_METADATA;
7721 : 0 : break;
7722 : 0 : case RTE_FLOW_ITEM_TYPE_ICMP:
7723 : 0 : ret = mlx5_flow_validate_item_icmp(items, item_flags,
7724 : : next_protocol,
7725 : : error);
7726 [ # # ]: 0 : if (ret < 0)
7727 : 0 : return ret;
7728 : 0 : last_item = MLX5_FLOW_LAYER_ICMP;
7729 : 0 : break;
7730 : 0 : case RTE_FLOW_ITEM_TYPE_ICMP6:
7731 : 0 : ret = mlx5_flow_validate_item_icmp6(items, item_flags,
7732 : : next_protocol,
7733 : : error);
7734 [ # # ]: 0 : if (ret < 0)
7735 : 0 : return ret;
7736 : : item_ipv6_proto = IPPROTO_ICMPV6;
7737 : 0 : last_item = MLX5_FLOW_LAYER_ICMP6;
7738 : 0 : break;
7739 : 0 : case RTE_FLOW_ITEM_TYPE_ICMP6_ECHO_REQUEST:
7740 : : case RTE_FLOW_ITEM_TYPE_ICMP6_ECHO_REPLY:
7741 : 0 : ret = mlx5_flow_validate_item_icmp6_echo(items,
7742 : : item_flags,
7743 : : next_protocol,
7744 : : error);
7745 [ # # ]: 0 : if (ret < 0)
7746 : 0 : return ret;
7747 : : item_ipv6_proto = IPPROTO_ICMPV6;
7748 : 0 : last_item = MLX5_FLOW_LAYER_ICMP6;
7749 : 0 : break;
7750 : 0 : case RTE_FLOW_ITEM_TYPE_TAG:
7751 : 0 : ret = flow_dv_validate_item_tag(dev, items, &tag_bitmap,
7752 : : attr, error);
7753 [ # # ]: 0 : if (ret < 0)
7754 : 0 : return ret;
7755 : 0 : last_item = MLX5_FLOW_ITEM_TAG;
7756 : 0 : break;
7757 : 0 : case MLX5_RTE_FLOW_ITEM_TYPE_SQ:
7758 : 0 : last_item = MLX5_FLOW_ITEM_SQ;
7759 : 0 : break;
7760 : 0 : case MLX5_RTE_FLOW_ITEM_TYPE_TAG:
7761 : 0 : mlx5_tag = (const struct mlx5_rte_flow_item_tag *)items->spec;
7762 [ # # ]: 0 : if (tag_bitmap & (1 << mlx5_tag->id))
7763 : 0 : return rte_flow_error_set(error, EINVAL,
7764 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
7765 : : items->spec,
7766 : : "Duplicated tag index");
7767 : 0 : tag_bitmap |= 1 << mlx5_tag->id;
7768 : 0 : break;
7769 : 0 : case RTE_FLOW_ITEM_TYPE_GTP:
7770 : 0 : ret = flow_dv_validate_item_gtp(dev, items, item_flags,
7771 : : error);
7772 [ # # ]: 0 : if (ret < 0)
7773 : 0 : return ret;
7774 : : gtp_item = items;
7775 : 0 : last_item = MLX5_FLOW_LAYER_GTP;
7776 : 0 : break;
7777 : 0 : case RTE_FLOW_ITEM_TYPE_GTP_PSC:
7778 : 0 : ret = flow_dv_validate_item_gtp_psc(items, last_item,
7779 : : gtp_item, is_root,
7780 : : error);
7781 [ # # ]: 0 : if (ret < 0)
7782 : 0 : return ret;
7783 : 0 : last_item = MLX5_FLOW_LAYER_GTP_PSC;
7784 : 0 : break;
7785 : 0 : case RTE_FLOW_ITEM_TYPE_ECPRI:
7786 : : /* Capacity will be checked in the translate stage. */
7787 : 0 : ret = mlx5_flow_validate_item_ecpri(items, item_flags,
7788 : : last_item,
7789 : : ether_type,
7790 : : &nic_ecpri_mask,
7791 : : error);
7792 [ # # ]: 0 : if (ret < 0)
7793 : 0 : return ret;
7794 : 0 : last_item = MLX5_FLOW_LAYER_ECPRI;
7795 : 0 : break;
7796 : 0 : case RTE_FLOW_ITEM_TYPE_INTEGRITY:
7797 : 0 : ret = flow_dv_validate_item_integrity(dev, items,
7798 : : item_flags,
7799 : : &last_item,
7800 : : integrity_items,
7801 : : error);
7802 [ # # ]: 0 : if (ret < 0)
7803 : 0 : return ret;
7804 : : break;
7805 : 0 : case RTE_FLOW_ITEM_TYPE_CONNTRACK:
7806 : 0 : ret = flow_dv_validate_item_aso_ct(dev, items,
7807 : : &item_flags, error);
7808 [ # # ]: 0 : if (ret < 0)
7809 : 0 : return ret;
7810 : : break;
7811 : : case MLX5_RTE_FLOW_ITEM_TYPE_TUNNEL:
7812 : : /* tunnel offload item was processed before
7813 : : * list it here as a supported type
7814 : : */
7815 : : break;
7816 : 0 : case RTE_FLOW_ITEM_TYPE_FLEX:
7817 : 0 : ret = flow_dv_validate_item_flex(dev, items, item_flags,
7818 : : &last_item,
7819 : : tunnel != 0, error);
7820 [ # # ]: 0 : if (ret < 0)
7821 : 0 : return ret;
7822 : : break;
7823 : 0 : case RTE_FLOW_ITEM_TYPE_METER_COLOR:
7824 : 0 : ret = flow_dv_validate_item_meter_color(dev, items,
7825 : : attr, error);
7826 [ # # ]: 0 : if (ret < 0)
7827 : 0 : return ret;
7828 : 0 : last_item = MLX5_FLOW_ITEM_METER_COLOR;
7829 : 0 : break;
7830 : 0 : case RTE_FLOW_ITEM_TYPE_AGGR_AFFINITY:
7831 : 0 : ret = flow_dv_validate_item_aggr_affinity(dev, items,
7832 : : attr, error);
7833 [ # # ]: 0 : if (ret < 0)
7834 : 0 : return ret;
7835 : 0 : last_item = MLX5_FLOW_ITEM_AGGR_AFFINITY;
7836 : 0 : break;
7837 : 0 : case RTE_FLOW_ITEM_TYPE_IB_BTH:
7838 : 0 : ret = mlx5_flow_validate_item_ib_bth(dev, udp_dport,
7839 : : items, is_root, error);
7840 [ # # ]: 0 : if (ret < 0)
7841 : 0 : return ret;
7842 : :
7843 : 0 : last_item = MLX5_FLOW_ITEM_IB_BTH;
7844 : 0 : break;
7845 : 0 : case RTE_FLOW_ITEM_TYPE_NSH:
7846 : 0 : ret = mlx5_flow_validate_item_nsh(dev, items, error);
7847 [ # # ]: 0 : if (ret < 0)
7848 : 0 : return ret;
7849 : 0 : last_item = MLX5_FLOW_ITEM_NSH;
7850 : 0 : break;
7851 : 0 : default:
7852 : 0 : return rte_flow_error_set(error, ENOTSUP,
7853 : : RTE_FLOW_ERROR_TYPE_ITEM,
7854 : : NULL, "item not supported");
7855 : : }
7856 : 0 : item_flags |= last_item;
7857 : : }
7858 [ # # ]: 0 : if (item_flags & MLX5_FLOW_ITEM_INTEGRITY) {
7859 : 0 : ret = flow_dv_validate_item_integrity_post(integrity_items,
7860 : : item_flags, error);
7861 [ # # ]: 0 : if (ret)
7862 : : return ret;
7863 : : }
7864 [ # # ]: 0 : for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
7865 : 0 : int type = actions->type;
7866 : :
7867 : : if (!mlx5_flow_os_action_supported(type))
7868 : : return rte_flow_error_set(error, ENOTSUP,
7869 : : RTE_FLOW_ERROR_TYPE_ACTION,
7870 : : actions,
7871 : : "action not supported");
7872 [ # # ]: 0 : if (actions_n == MLX5_DV_MAX_NUMBER_OF_ACTIONS)
7873 : 0 : return rte_flow_error_set(error, ENOTSUP,
7874 : : RTE_FLOW_ERROR_TYPE_ACTION,
7875 : : actions, "too many actions");
7876 [ # # ]: 0 : if (action_flags &
7877 : : MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY)
7878 : 0 : return rte_flow_error_set(error, ENOTSUP,
7879 : : RTE_FLOW_ERROR_TYPE_ACTION,
7880 : : NULL, "meter action with policy "
7881 : : "must be the last action");
7882 [ # # # # : 0 : switch (type) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # ]
7883 : : case RTE_FLOW_ACTION_TYPE_VOID:
7884 : : break;
7885 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_ID:
7886 : : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
7887 : 0 : ret = flow_dv_validate_action_port_id(dev,
7888 : : action_flags,
7889 : : actions,
7890 : : attr,
7891 : : error);
7892 [ # # ]: 0 : if (ret)
7893 : 0 : return ret;
7894 [ # # ]: 0 : if (type == RTE_FLOW_ACTION_TYPE_PORT_ID) {
7895 : 0 : port = (const struct rte_flow_action_port_id *)
7896 : : actions->conf;
7897 [ # # ]: 0 : port_id = port->original ? dev->data->port_id : port->id;
7898 : : } else {
7899 : 0 : port_id = ((const struct rte_flow_action_ethdev *)
7900 : 0 : actions->conf)->port_id;
7901 : : }
7902 : 0 : action_flags |= MLX5_FLOW_ACTION_PORT_ID;
7903 : 0 : ++actions_n;
7904 : 0 : break;
7905 : 0 : case RTE_FLOW_ACTION_TYPE_FLAG:
7906 : 0 : ret = flow_dv_validate_action_flag(dev, action_flags,
7907 : : attr, error);
7908 [ # # ]: 0 : if (ret < 0)
7909 : 0 : return ret;
7910 [ # # ]: 0 : if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
7911 : : /* Count all modify-header actions as one. */
7912 [ # # ]: 0 : if (!(action_flags &
7913 : : MLX5_FLOW_MODIFY_HDR_ACTIONS))
7914 : 0 : ++actions_n;
7915 : 0 : action_flags |= MLX5_FLOW_ACTION_FLAG |
7916 : : MLX5_FLOW_ACTION_MARK_EXT;
7917 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7918 : : modify_after_mirror = 1;
7919 : :
7920 : : } else {
7921 : 0 : action_flags |= MLX5_FLOW_ACTION_FLAG;
7922 : 0 : ++actions_n;
7923 : : }
7924 : 0 : rw_act_num += MLX5_ACT_NUM_SET_MARK;
7925 : 0 : break;
7926 : 0 : case RTE_FLOW_ACTION_TYPE_MARK:
7927 : 0 : ret = flow_dv_validate_action_mark(dev, actions,
7928 : : action_flags,
7929 : : attr, error);
7930 [ # # ]: 0 : if (ret < 0)
7931 : 0 : return ret;
7932 [ # # ]: 0 : if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
7933 : : /* Count all modify-header actions as one. */
7934 [ # # ]: 0 : if (!(action_flags &
7935 : : MLX5_FLOW_MODIFY_HDR_ACTIONS))
7936 : 0 : ++actions_n;
7937 : 0 : action_flags |= MLX5_FLOW_ACTION_MARK |
7938 : : MLX5_FLOW_ACTION_MARK_EXT;
7939 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7940 : : modify_after_mirror = 1;
7941 : : } else {
7942 : 0 : action_flags |= MLX5_FLOW_ACTION_MARK;
7943 : 0 : ++actions_n;
7944 : : }
7945 : 0 : rw_act_num += MLX5_ACT_NUM_SET_MARK;
7946 : 0 : break;
7947 : 0 : case RTE_FLOW_ACTION_TYPE_SET_META:
7948 : 0 : ret = flow_dv_validate_action_set_meta(dev, actions,
7949 : : action_flags,
7950 : : attr, error);
7951 [ # # ]: 0 : if (ret < 0)
7952 : 0 : return ret;
7953 : : /* Count all modify-header actions as one action. */
7954 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7955 : 0 : ++actions_n;
7956 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7957 : : modify_after_mirror = 1;
7958 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_META;
7959 : 0 : rw_act_num += MLX5_ACT_NUM_SET_META;
7960 : 0 : break;
7961 : 0 : case RTE_FLOW_ACTION_TYPE_SET_TAG:
7962 : 0 : ret = flow_dv_validate_action_set_tag(dev, actions,
7963 : : action_flags,
7964 : : attr, error);
7965 [ # # ]: 0 : if (ret < 0)
7966 : 0 : return ret;
7967 : : /* Count all modify-header actions as one action. */
7968 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7969 : 0 : ++actions_n;
7970 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7971 : : modify_after_mirror = 1;
7972 : 0 : tag_id = ((const struct rte_flow_action_set_tag *)
7973 : 0 : actions->conf)->index;
7974 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_TAG;
7975 : 0 : rw_act_num += MLX5_ACT_NUM_SET_TAG;
7976 : 0 : break;
7977 : 0 : case RTE_FLOW_ACTION_TYPE_DROP:
7978 : 0 : ret = mlx5_flow_validate_action_drop(dev, is_root,
7979 : : attr, error);
7980 [ # # ]: 0 : if (ret < 0)
7981 : 0 : return ret;
7982 : 0 : action_flags |= MLX5_FLOW_ACTION_DROP;
7983 : 0 : ++actions_n;
7984 : 0 : break;
7985 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
7986 : 0 : ret = mlx5_flow_validate_action_queue(actions,
7987 : : action_flags, dev,
7988 : : attr, error);
7989 [ # # ]: 0 : if (ret < 0)
7990 : 0 : return ret;
7991 : 0 : queue_index = ((const struct rte_flow_action_queue *)
7992 : 0 : (actions->conf))->index;
7993 : 0 : action_flags |= MLX5_FLOW_ACTION_QUEUE;
7994 : 0 : ++actions_n;
7995 : 0 : break;
7996 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
7997 : 0 : rss = actions->conf;
7998 : 0 : ret = mlx5_flow_validate_action_rss(actions,
7999 : : action_flags, dev,
8000 : : attr, item_flags,
8001 : : error);
8002 [ # # ]: 0 : if (ret < 0)
8003 : 0 : return ret;
8004 [ # # ]: 0 : if (rss && sample_rss &&
8005 [ # # ]: 0 : (sample_rss->level != rss->level ||
8006 [ # # ]: 0 : sample_rss->types != rss->types))
8007 : 0 : return rte_flow_error_set(error, ENOTSUP,
8008 : : RTE_FLOW_ERROR_TYPE_ACTION,
8009 : : NULL,
8010 : : "Can't use the different RSS types "
8011 : : "or level in the same flow");
8012 [ # # # # ]: 0 : if (rss != NULL && rss->queue_num)
8013 : 0 : queue_index = rss->queue[0];
8014 : 0 : action_flags |= MLX5_FLOW_ACTION_RSS;
8015 : 0 : ++actions_n;
8016 : 0 : break;
8017 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS:
8018 : : ret =
8019 : 0 : mlx5_flow_validate_action_default_miss(action_flags,
8020 : : attr, error);
8021 [ # # ]: 0 : if (ret < 0)
8022 : 0 : return ret;
8023 : 0 : action_flags |= MLX5_FLOW_ACTION_DEFAULT_MISS;
8024 : 0 : ++actions_n;
8025 : 0 : break;
8026 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_COUNT:
8027 : : shared_count = true;
8028 : : /* fall-through. */
8029 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
8030 : 0 : ret = flow_dv_validate_action_count(dev, shared_count,
8031 : : action_flags,
8032 : : is_root, error);
8033 [ # # ]: 0 : if (ret < 0)
8034 : 0 : return ret;
8035 : 0 : count = actions->conf;
8036 : 0 : action_flags |= MLX5_FLOW_ACTION_COUNT;
8037 : 0 : ++actions_n;
8038 : 0 : break;
8039 : 0 : case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
8040 [ # # ]: 0 : if (flow_dv_validate_action_pop_vlan(dev,
8041 : : action_flags,
8042 : : actions,
8043 : : item_flags, attr,
8044 : : error))
8045 : 0 : return -rte_errno;
8046 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8047 : : modify_after_mirror = 1;
8048 : 0 : action_flags |= MLX5_FLOW_ACTION_OF_POP_VLAN;
8049 : 0 : ++actions_n;
8050 : 0 : break;
8051 : 0 : case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
8052 : 0 : ret = flow_dv_validate_action_push_vlan(dev,
8053 : : action_flags,
8054 : : vlan_m,
8055 : : actions, attr,
8056 : : error);
8057 [ # # ]: 0 : if (ret < 0)
8058 : 0 : return ret;
8059 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8060 : : modify_after_mirror = 1;
8061 : 0 : action_flags |= MLX5_FLOW_ACTION_OF_PUSH_VLAN;
8062 : 0 : ++actions_n;
8063 : 0 : break;
8064 : 0 : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
8065 : 0 : ret = flow_dv_validate_action_set_vlan_pcp
8066 : : (action_flags, actions, error);
8067 [ # # ]: 0 : if (ret < 0)
8068 : 0 : return ret;
8069 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8070 : : modify_after_mirror = 1;
8071 : : /* Count PCP with push_vlan command. */
8072 : 0 : action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_PCP;
8073 : 0 : break;
8074 : 0 : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
8075 : 0 : ret = flow_dv_validate_action_set_vlan_vid
8076 : : (item_flags, action_flags,
8077 : : actions, error);
8078 [ # # ]: 0 : if (ret < 0)
8079 : 0 : return ret;
8080 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8081 : : modify_after_mirror = 1;
8082 : : /* Count VID with push_vlan command. */
8083 : 0 : action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_VID;
8084 : 0 : rw_act_num += MLX5_ACT_NUM_MDF_VID;
8085 : 0 : break;
8086 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
8087 : : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
8088 : 0 : ret = flow_dv_validate_action_l2_encap(dev,
8089 : : action_flags,
8090 : : actions, attr,
8091 : : error);
8092 [ # # ]: 0 : if (ret < 0)
8093 : 0 : return ret;
8094 : 0 : action_flags |= MLX5_FLOW_ACTION_ENCAP;
8095 : 0 : ++actions_n;
8096 : 0 : break;
8097 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
8098 : : case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
8099 : 0 : ret = flow_dv_validate_action_decap(dev, action_flags,
8100 : : actions, item_flags,
8101 : : attr, error);
8102 [ # # ]: 0 : if (ret < 0)
8103 : 0 : return ret;
8104 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8105 : : modify_after_mirror = 1;
8106 : 0 : action_flags |= MLX5_FLOW_ACTION_DECAP;
8107 : 0 : ++actions_n;
8108 : 0 : break;
8109 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
8110 : 0 : ret = flow_dv_validate_action_raw_encap_decap
8111 : 0 : (dev, NULL, actions->conf, attr, &action_flags,
8112 : : &actions_n, actions, item_flags, error);
8113 [ # # ]: 0 : if (ret < 0)
8114 : 0 : return ret;
8115 : : break;
8116 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
8117 : 0 : decap = actions->conf;
8118 [ # # ]: 0 : while ((++actions)->type == RTE_FLOW_ACTION_TYPE_VOID)
8119 : : ;
8120 [ # # ]: 0 : if (actions->type != RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
8121 : : encap = NULL;
8122 : : actions--;
8123 : : } else {
8124 : 0 : encap = actions->conf;
8125 : : }
8126 [ # # ]: 0 : ret = flow_dv_validate_action_raw_encap_decap
8127 : : (dev,
8128 : : decap ? decap : &empty_decap, encap,
8129 : : attr, &action_flags, &actions_n,
8130 : : actions, item_flags, error);
8131 [ # # ]: 0 : if (ret < 0)
8132 : 0 : return ret;
8133 [ # # ]: 0 : if ((action_flags & MLX5_FLOW_ACTION_SAMPLE) &&
8134 : : (action_flags & MLX5_FLOW_ACTION_DECAP))
8135 : : modify_after_mirror = 1;
8136 : : break;
8137 : 0 : case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
8138 : : case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
8139 : 0 : ret = flow_dv_validate_action_modify_mac(action_flags,
8140 : : actions,
8141 : : item_flags,
8142 : : error);
8143 [ # # ]: 0 : if (ret < 0)
8144 : 0 : return ret;
8145 : : /* Count all modify-header actions as one action. */
8146 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8147 : 0 : ++actions_n;
8148 : 0 : action_flags |= actions->type ==
8149 : : RTE_FLOW_ACTION_TYPE_SET_MAC_SRC ?
8150 [ # # ]: 0 : MLX5_FLOW_ACTION_SET_MAC_SRC :
8151 : : MLX5_FLOW_ACTION_SET_MAC_DST;
8152 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8153 : : modify_after_mirror = 1;
8154 : : /*
8155 : : * Even if the source and destination MAC addresses have
8156 : : * overlap in the header with 4B alignment, the convert
8157 : : * function will handle them separately and 4 SW actions
8158 : : * will be created. And 2 actions will be added each
8159 : : * time no matter how many bytes of address will be set.
8160 : : */
8161 : 0 : rw_act_num += MLX5_ACT_NUM_MDF_MAC;
8162 : 0 : break;
8163 : 0 : case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
8164 : : case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
8165 : 0 : ret = flow_dv_validate_action_modify_ipv4(action_flags,
8166 : : actions,
8167 : : item_flags,
8168 : : error);
8169 [ # # ]: 0 : if (ret < 0)
8170 : 0 : return ret;
8171 : : /* Count all modify-header actions as one action. */
8172 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8173 : 0 : ++actions_n;
8174 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8175 : : modify_after_mirror = 1;
8176 : 0 : action_flags |= actions->type ==
8177 : : RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC ?
8178 [ # # ]: 0 : MLX5_FLOW_ACTION_SET_IPV4_SRC :
8179 : : MLX5_FLOW_ACTION_SET_IPV4_DST;
8180 : 0 : rw_act_num += MLX5_ACT_NUM_MDF_IPV4;
8181 : 0 : break;
8182 : 0 : case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
8183 : : case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
8184 : 0 : ret = flow_dv_validate_action_modify_ipv6(action_flags,
8185 : : actions,
8186 : : item_flags,
8187 : : error);
8188 [ # # ]: 0 : if (ret < 0)
8189 : 0 : return ret;
8190 [ # # ]: 0 : if (item_ipv6_proto == IPPROTO_ICMPV6)
8191 : 0 : return rte_flow_error_set(error, ENOTSUP,
8192 : : RTE_FLOW_ERROR_TYPE_ACTION,
8193 : : actions,
8194 : : "Can't change header "
8195 : : "with ICMPv6 proto");
8196 : : /* Count all modify-header actions as one action. */
8197 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8198 : 0 : ++actions_n;
8199 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8200 : : modify_after_mirror = 1;
8201 : 0 : action_flags |= actions->type ==
8202 : : RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC ?
8203 [ # # ]: 0 : MLX5_FLOW_ACTION_SET_IPV6_SRC :
8204 : : MLX5_FLOW_ACTION_SET_IPV6_DST;
8205 : 0 : rw_act_num += MLX5_ACT_NUM_MDF_IPV6;
8206 : 0 : break;
8207 : 0 : case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
8208 : : case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
8209 : 0 : ret = flow_dv_validate_action_modify_tp(action_flags,
8210 : : actions,
8211 : : item_flags,
8212 : : error);
8213 [ # # ]: 0 : if (ret < 0)
8214 : 0 : return ret;
8215 : : /* Count all modify-header actions as one action. */
8216 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8217 : 0 : ++actions_n;
8218 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8219 : : modify_after_mirror = 1;
8220 : 0 : action_flags |= actions->type ==
8221 : : RTE_FLOW_ACTION_TYPE_SET_TP_SRC ?
8222 [ # # ]: 0 : MLX5_FLOW_ACTION_SET_TP_SRC :
8223 : : MLX5_FLOW_ACTION_SET_TP_DST;
8224 : 0 : rw_act_num += MLX5_ACT_NUM_MDF_PORT;
8225 : 0 : break;
8226 : 0 : case RTE_FLOW_ACTION_TYPE_DEC_TTL:
8227 : : case RTE_FLOW_ACTION_TYPE_SET_TTL:
8228 : 0 : ret = flow_dv_validate_action_modify_ttl(action_flags,
8229 : : actions,
8230 : : item_flags,
8231 : : error);
8232 [ # # ]: 0 : if (ret < 0)
8233 : 0 : return ret;
8234 : : /* Count all modify-header actions as one action. */
8235 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8236 : 0 : ++actions_n;
8237 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8238 : : modify_after_mirror = 1;
8239 : 0 : action_flags |= actions->type ==
8240 : : RTE_FLOW_ACTION_TYPE_SET_TTL ?
8241 [ # # ]: 0 : MLX5_FLOW_ACTION_SET_TTL :
8242 : : MLX5_FLOW_ACTION_DEC_TTL;
8243 : 0 : rw_act_num += MLX5_ACT_NUM_MDF_TTL;
8244 : 0 : break;
8245 : 0 : case RTE_FLOW_ACTION_TYPE_JUMP:
8246 : 0 : ret = flow_dv_validate_action_jump(dev, tunnel, actions,
8247 : : action_flags,
8248 : : attr, external,
8249 : : error);
8250 [ # # ]: 0 : if (ret)
8251 : 0 : return ret;
8252 : 0 : ++actions_n;
8253 : 0 : action_flags |= MLX5_FLOW_ACTION_JUMP;
8254 : 0 : break;
8255 : 0 : case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
8256 : : case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
8257 : 0 : ret = flow_dv_validate_action_modify_tcp_seq
8258 : : (action_flags,
8259 : : actions,
8260 : : item_flags,
8261 : : error);
8262 [ # # ]: 0 : if (ret < 0)
8263 : 0 : return ret;
8264 : : /* Count all modify-header actions as one action. */
8265 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8266 : 0 : ++actions_n;
8267 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8268 : : modify_after_mirror = 1;
8269 : 0 : action_flags |= actions->type ==
8270 : : RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ ?
8271 [ # # ]: 0 : MLX5_FLOW_ACTION_INC_TCP_SEQ :
8272 : : MLX5_FLOW_ACTION_DEC_TCP_SEQ;
8273 : 0 : rw_act_num += MLX5_ACT_NUM_MDF_TCPSEQ;
8274 : 0 : break;
8275 : 0 : case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
8276 : : case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
8277 : 0 : ret = flow_dv_validate_action_modify_tcp_ack
8278 : : (action_flags,
8279 : : actions,
8280 : : item_flags,
8281 : : error);
8282 [ # # ]: 0 : if (ret < 0)
8283 : 0 : return ret;
8284 : : /* Count all modify-header actions as one action. */
8285 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8286 : 0 : ++actions_n;
8287 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8288 : : modify_after_mirror = 1;
8289 : 0 : action_flags |= actions->type ==
8290 : : RTE_FLOW_ACTION_TYPE_INC_TCP_ACK ?
8291 [ # # ]: 0 : MLX5_FLOW_ACTION_INC_TCP_ACK :
8292 : : MLX5_FLOW_ACTION_DEC_TCP_ACK;
8293 : 0 : rw_act_num += MLX5_ACT_NUM_MDF_TCPACK;
8294 : 0 : break;
8295 : : case MLX5_RTE_FLOW_ACTION_TYPE_MARK:
8296 : : break;
8297 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_TAG:
8298 : : case MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG:
8299 : 0 : rw_act_num += MLX5_ACT_NUM_SET_TAG;
8300 : 0 : break;
8301 : 0 : case RTE_FLOW_ACTION_TYPE_METER:
8302 : 0 : ret = mlx5_flow_validate_action_meter(dev,
8303 : : action_flags,
8304 : : item_flags,
8305 : : actions, attr,
8306 : : port_id_item,
8307 : : &def_policy,
8308 : : error);
8309 [ # # ]: 0 : if (ret < 0)
8310 : 0 : return ret;
8311 : 0 : action_flags |= MLX5_FLOW_ACTION_METER;
8312 [ # # ]: 0 : if (!def_policy)
8313 : 0 : action_flags |=
8314 : : MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY;
8315 : 0 : ++actions_n;
8316 : : /* Meter action will add one more TAG action. */
8317 : 0 : rw_act_num += MLX5_ACT_NUM_SET_TAG;
8318 : 0 : break;
8319 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_AGE:
8320 [ # # ]: 0 : if (is_root)
8321 : 0 : return rte_flow_error_set(error, ENOTSUP,
8322 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8323 : : NULL,
8324 : : "Shared ASO age action is not supported for group 0");
8325 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_AGE)
8326 : 0 : return rte_flow_error_set
8327 : : (error, EINVAL,
8328 : : RTE_FLOW_ERROR_TYPE_ACTION,
8329 : : NULL,
8330 : : "duplicate age actions set");
8331 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8332 : : aso_after_sample = 1;
8333 : 0 : action_flags |= MLX5_FLOW_ACTION_AGE;
8334 : 0 : ++actions_n;
8335 : 0 : break;
8336 : 0 : case RTE_FLOW_ACTION_TYPE_AGE:
8337 : 0 : non_shared_age = actions->conf;
8338 : 0 : ret = flow_dv_validate_action_age(action_flags,
8339 : : actions, dev,
8340 : : error);
8341 [ # # ]: 0 : if (ret < 0)
8342 : 0 : return ret;
8343 : : /*
8344 : : * Validate the regular AGE action (using counter)
8345 : : * mutual exclusion with indirect counter actions.
8346 : : */
8347 [ # # ]: 0 : if (!flow_hit_aso_supported(priv, is_root)) {
8348 [ # # ]: 0 : if (shared_count)
8349 : 0 : return rte_flow_error_set
8350 : : (error, EINVAL,
8351 : : RTE_FLOW_ERROR_TYPE_ACTION,
8352 : : NULL,
8353 : : "old age and indirect count combination is not supported");
8354 [ # # ]: 0 : if (sample_count)
8355 : 0 : return rte_flow_error_set
8356 : : (error, EINVAL,
8357 : : RTE_FLOW_ERROR_TYPE_ACTION,
8358 : : NULL,
8359 : : "old age action and count must be in the same sub flow");
8360 : : } else {
8361 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8362 : : aso_after_sample = 1;
8363 : : }
8364 : 0 : action_flags |= MLX5_FLOW_ACTION_AGE;
8365 : 0 : ++actions_n;
8366 : 0 : break;
8367 : 0 : case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
8368 : 0 : ret = flow_dv_validate_action_modify_ipv4_dscp
8369 : : (action_flags,
8370 : : actions,
8371 : : item_flags,
8372 : : error);
8373 [ # # ]: 0 : if (ret < 0)
8374 : 0 : return ret;
8375 : : /* Count all modify-header actions as one action. */
8376 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8377 : 0 : ++actions_n;
8378 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8379 : : modify_after_mirror = 1;
8380 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_IPV4_DSCP;
8381 : 0 : rw_act_num += MLX5_ACT_NUM_SET_DSCP;
8382 : 0 : break;
8383 : 0 : case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
8384 : 0 : ret = flow_dv_validate_action_modify_ipv6_dscp
8385 : : (action_flags,
8386 : : actions,
8387 : : item_flags,
8388 : : error);
8389 [ # # ]: 0 : if (ret < 0)
8390 : 0 : return ret;
8391 : : /* Count all modify-header actions as one action. */
8392 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8393 : 0 : ++actions_n;
8394 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8395 : : modify_after_mirror = 1;
8396 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_IPV6_DSCP;
8397 : 0 : rw_act_num += MLX5_ACT_NUM_SET_DSCP;
8398 : 0 : break;
8399 : 0 : case RTE_FLOW_ACTION_TYPE_SAMPLE:
8400 : 0 : ret = flow_dv_validate_action_sample(&action_flags,
8401 : : &sub_action_flags,
8402 : : actions, dev,
8403 : : attr, item_flags,
8404 : : rss, &sample_rss,
8405 : : &sample_count,
8406 : : &fdb_mirror,
8407 : : &sample_port_id,
8408 : : is_root,
8409 : : error);
8410 [ # # ]: 0 : if (ret < 0)
8411 : 0 : return ret;
8412 [ # # # # ]: 0 : if ((action_flags & MLX5_FLOW_ACTION_SET_TAG) &&
8413 : 0 : tag_id == 0 &&
8414 [ # # ]: 0 : priv->sh->registers.aso_reg == REG_NON)
8415 : 0 : return rte_flow_error_set(error, EINVAL,
8416 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
8417 : : "sample after tag action causes metadata tag index 0 corruption");
8418 : 0 : action_flags |= MLX5_FLOW_ACTION_SAMPLE;
8419 : 0 : ++actions_n;
8420 : 0 : break;
8421 : 0 : case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
8422 : 0 : ret = flow_dv_validate_action_modify_field(dev,
8423 : : action_flags,
8424 : : actions,
8425 : : attr,
8426 : : is_root,
8427 : : error);
8428 [ # # ]: 0 : if (ret < 0)
8429 : 0 : return ret;
8430 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8431 : : modify_after_mirror = 1;
8432 : : /* Count all modify-header actions as one action. */
8433 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8434 : 0 : ++actions_n;
8435 : 0 : action_flags |= MLX5_FLOW_ACTION_MODIFY_FIELD;
8436 : 0 : rw_act_num += ret;
8437 : 0 : break;
8438 : 0 : case RTE_FLOW_ACTION_TYPE_CONNTRACK:
8439 : 0 : ret = flow_dv_validate_action_aso_ct(dev, action_flags,
8440 : : item_flags,
8441 : : is_root, error);
8442 [ # # ]: 0 : if (ret < 0)
8443 : 0 : return ret;
8444 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8445 : : aso_after_sample = 1;
8446 : 0 : action_flags |= MLX5_FLOW_ACTION_CT;
8447 : 0 : break;
8448 : : case MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET:
8449 : : /* tunnel offload action was processed before
8450 : : * list it here as a supported type
8451 : : */
8452 : : break;
8453 : : #ifdef HAVE_MLX5DV_DR_ACTION_CREATE_DEST_ROOT_TABLE
8454 : : case RTE_FLOW_ACTION_TYPE_SEND_TO_KERNEL:
8455 : : action_flags |= MLX5_FLOW_ACTION_SEND_TO_KERNEL;
8456 : : ++actions_n;
8457 : : break;
8458 : : #endif
8459 : 0 : default:
8460 : 0 : return rte_flow_error_set(error, ENOTSUP,
8461 : : RTE_FLOW_ERROR_TYPE_ACTION,
8462 : : actions,
8463 : : "action not supported");
8464 : : }
8465 : : }
8466 : : /*
8467 : : * Validate actions in flow rules
8468 : : * - Explicit decap action is prohibited by the tunnel offload API.
8469 : : * - Drop action in tunnel steer rule is prohibited by the API.
8470 : : * - Application cannot use MARK action because it's value can mask
8471 : : * tunnel default miss notification.
8472 : : * - JUMP in tunnel match rule has no support in current PMD
8473 : : * implementation.
8474 : : * - TAG & META are reserved for future uses.
8475 : : */
8476 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_TUNNEL_SET) {
8477 : : uint64_t bad_actions_mask = MLX5_FLOW_ACTION_DECAP |
8478 : : MLX5_FLOW_ACTION_MARK |
8479 : : MLX5_FLOW_ACTION_SET_TAG |
8480 : : MLX5_FLOW_ACTION_SET_META |
8481 : : MLX5_FLOW_ACTION_DROP;
8482 : :
8483 [ # # ]: 0 : if (action_flags & bad_actions_mask)
8484 : 0 : return rte_flow_error_set
8485 : : (error, EINVAL,
8486 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
8487 : : "Invalid RTE action in tunnel "
8488 : : "set decap rule");
8489 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_ACTION_JUMP))
8490 : 0 : return rte_flow_error_set
8491 : : (error, EINVAL,
8492 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
8493 : : "tunnel set decap rule must terminate "
8494 : : "with JUMP");
8495 [ # # ]: 0 : if (attr->egress)
8496 : 0 : return rte_flow_error_set
8497 : : (error, EINVAL,
8498 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
8499 : : "tunnel flows for ingress and transfer traffic only");
8500 : : }
8501 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_TUNNEL_MATCH) {
8502 : : uint64_t bad_actions_mask = MLX5_FLOW_ACTION_JUMP |
8503 : : MLX5_FLOW_ACTION_MARK |
8504 : : MLX5_FLOW_ACTION_SET_TAG |
8505 : : MLX5_FLOW_ACTION_SET_META;
8506 : :
8507 [ # # ]: 0 : if (action_flags & bad_actions_mask)
8508 : 0 : return rte_flow_error_set
8509 : : (error, EINVAL,
8510 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
8511 : : "Invalid RTE action in tunnel "
8512 : : "set match rule");
8513 : : }
8514 : : /*
8515 : : * Validate the drop action mutual exclusion with other actions.
8516 : : * Drop action is mutually-exclusive with any other action, except for
8517 : : * Count/Sample/Age actions.
8518 : : * Drop action compatibility with tunnel offload was already validated.
8519 : : */
8520 [ # # ]: 0 : if (action_flags & (MLX5_FLOW_ACTION_TUNNEL_MATCH |
8521 : : MLX5_FLOW_ACTION_TUNNEL_MATCH));
8522 [ # # ]: 0 : else if ((action_flags & MLX5_FLOW_ACTION_DROP) &&
8523 [ # # ]: 0 : (action_flags & ~(MLX5_FLOW_ACTION_DROP | MLX5_FLOW_DROP_INCLUSIVE_ACTIONS)))
8524 : 0 : return rte_flow_error_set(error, EINVAL,
8525 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
8526 : : "Drop action is mutually-exclusive "
8527 : : "with any other action, except for "
8528 : : "Count/Sample/Age action");
8529 : : /* Eswitch has few restrictions on using items and actions */
8530 [ # # ]: 0 : if (attr->transfer) {
8531 [ # # ]: 0 : if (!mlx5_flow_ext_mreg_supported(dev) &&
8532 [ # # ]: 0 : action_flags & MLX5_FLOW_ACTION_FLAG)
8533 : 0 : return rte_flow_error_set(error, ENOTSUP,
8534 : : RTE_FLOW_ERROR_TYPE_ACTION,
8535 : : NULL,
8536 : : "unsupported action FLAG");
8537 [ # # ]: 0 : if (!mlx5_flow_ext_mreg_supported(dev) &&
8538 [ # # ]: 0 : action_flags & MLX5_FLOW_ACTION_MARK)
8539 : 0 : return rte_flow_error_set(error, ENOTSUP,
8540 : : RTE_FLOW_ERROR_TYPE_ACTION,
8541 : : NULL,
8542 : : "unsupported action MARK");
8543 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_QUEUE)
8544 : 0 : return rte_flow_error_set(error, ENOTSUP,
8545 : : RTE_FLOW_ERROR_TYPE_ACTION,
8546 : : NULL,
8547 : : "unsupported action QUEUE");
8548 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_RSS)
8549 : 0 : return rte_flow_error_set(error, ENOTSUP,
8550 : : RTE_FLOW_ERROR_TYPE_ACTION,
8551 : : NULL,
8552 : : "unsupported action RSS");
8553 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_FATE_ESWITCH_ACTIONS))
8554 : 0 : return rte_flow_error_set(error, EINVAL,
8555 : : RTE_FLOW_ERROR_TYPE_ACTION,
8556 : : actions,
8557 : : "no fate action is found");
8558 : : } else {
8559 [ # # # # ]: 0 : if (!(action_flags & MLX5_FLOW_FATE_ACTIONS) && attr->ingress)
8560 : 0 : return rte_flow_error_set(error, EINVAL,
8561 : : RTE_FLOW_ERROR_TYPE_ACTION,
8562 : : actions,
8563 : : "no fate action is found");
8564 : : }
8565 : : /*
8566 : : * Continue validation for Xcap and VLAN actions.
8567 : : * If hairpin is working in explicit TX rule mode, there is no actions
8568 : : * splitting and the validation of hairpin ingress flow should be the
8569 : : * same as other standard flows.
8570 : : */
8571 [ # # ]: 0 : if ((action_flags & (MLX5_FLOW_XCAP_ACTIONS |
8572 [ # # ]: 0 : MLX5_FLOW_VLAN_ACTIONS)) &&
8573 [ # # # # ]: 0 : (queue_index == 0xFFFF || !mlx5_rxq_is_hairpin(dev, queue_index) ||
8574 : 0 : ((conf = mlx5_rxq_get_hairpin_conf(dev, queue_index)) != NULL &&
8575 [ # # ]: 0 : conf->tx_explicit != 0))) {
8576 [ # # ]: 0 : if ((action_flags & MLX5_FLOW_XCAP_ACTIONS) ==
8577 : : MLX5_FLOW_XCAP_ACTIONS)
8578 : 0 : return rte_flow_error_set(error, ENOTSUP,
8579 : : RTE_FLOW_ERROR_TYPE_ACTION,
8580 : : NULL, "encap and decap "
8581 : : "combination aren't supported");
8582 : : /* Push VLAN is not supported in ingress except for NICs newer than CX5. */
8583 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN) {
8584 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
8585 : : bool direction_error = false;
8586 : :
8587 [ # # ]: 0 : if (attr->transfer) {
8588 [ # # ]: 0 : bool fdb_tx = flow_source_vport_representor(priv, act_priv);
8589 : 0 : bool is_cx5 = sh->steering_format_version ==
8590 : : MLX5_STEERING_LOGIC_FORMAT_CONNECTX_5;
8591 : :
8592 [ # # ]: 0 : if (!fdb_tx && is_cx5)
8593 : : direction_error = true;
8594 [ # # ]: 0 : } else if (attr->ingress) {
8595 : : direction_error = true;
8596 : : }
8597 : : if (direction_error)
8598 : 0 : return rte_flow_error_set(error, ENOTSUP,
8599 : : RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
8600 : : NULL,
8601 : : "push VLAN action not supported "
8602 : : "for ingress");
8603 : : }
8604 [ # # ]: 0 : if (attr->ingress) {
8605 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_ENCAP)
8606 : 0 : return rte_flow_error_set
8607 : : (error, ENOTSUP,
8608 : : RTE_FLOW_ERROR_TYPE_ACTION,
8609 : : NULL, "encap is not supported"
8610 : : " for ingress traffic");
8611 [ # # ]: 0 : else if ((action_flags & MLX5_FLOW_VLAN_ACTIONS) ==
8612 : : MLX5_FLOW_VLAN_ACTIONS)
8613 : 0 : return rte_flow_error_set
8614 : : (error, ENOTSUP,
8615 : : RTE_FLOW_ERROR_TYPE_ACTION,
8616 : : NULL, "no support for "
8617 : : "multiple VLAN actions");
8618 : : }
8619 : : }
8620 : : /* Pop VLAN is not supported in egress except for NICs newer than CX5. */
8621 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_OF_POP_VLAN) {
8622 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
8623 : : bool direction_error = false;
8624 : :
8625 [ # # ]: 0 : if (attr->transfer) {
8626 [ # # ]: 0 : bool fdb_tx = flow_source_vport_representor(priv, act_priv);
8627 : 0 : bool is_cx5 = sh->steering_format_version ==
8628 : : MLX5_STEERING_LOGIC_FORMAT_CONNECTX_5;
8629 : :
8630 [ # # ]: 0 : if (fdb_tx && is_cx5)
8631 : : direction_error = true;
8632 [ # # ]: 0 : } else if (attr->egress) {
8633 : : direction_error = true;
8634 : : }
8635 : : if (direction_error)
8636 : 0 : return rte_flow_error_set(error, ENOTSUP,
8637 : : RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
8638 : : NULL,
8639 : : "pop vlan action not supported for egress");
8640 : : }
8641 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY) {
8642 [ # # ]: 0 : if ((action_flags & (MLX5_FLOW_FATE_ACTIONS &
8643 [ # # ]: 0 : ~MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY)) &&
8644 : : attr->ingress)
8645 : 0 : return rte_flow_error_set
8646 : : (error, ENOTSUP,
8647 : : RTE_FLOW_ERROR_TYPE_ACTION,
8648 : : NULL, "fate action not supported for "
8649 : : "meter with policy");
8650 [ # # ]: 0 : if (attr->egress) {
8651 [ # # ]: 0 : if (action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS)
8652 : 0 : return rte_flow_error_set
8653 : : (error, ENOTSUP,
8654 : : RTE_FLOW_ERROR_TYPE_ACTION,
8655 : : NULL, "modify header action in egress "
8656 : : "cannot be done before meter action");
8657 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_ENCAP)
8658 : 0 : return rte_flow_error_set
8659 : : (error, ENOTSUP,
8660 : : RTE_FLOW_ERROR_TYPE_ACTION,
8661 : : NULL, "encap action in egress "
8662 : : "cannot be done before meter action");
8663 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN)
8664 : 0 : return rte_flow_error_set
8665 : : (error, ENOTSUP,
8666 : : RTE_FLOW_ERROR_TYPE_ACTION,
8667 : : NULL, "push vlan action in egress "
8668 : : "cannot be done before meter action");
8669 : : }
8670 : : }
8671 : : /*
8672 : : * Only support one ASO action in a single flow rule.
8673 : : * non-shared AGE + counter will fallback to use HW counter, no ASO hit object.
8674 : : * Group 0 uses HW counter for AGE too even if no counter action.
8675 : : */
8676 [ # # # # ]: 0 : aso_mask = (action_flags & MLX5_FLOW_ACTION_METER && priv->sh->meter_aso_en) << 2 |
8677 [ # # # # ]: 0 : (action_flags & MLX5_FLOW_ACTION_CT && priv->sh->ct_aso_en) << 1 |
8678 : 0 : (action_flags & MLX5_FLOW_ACTION_AGE &&
8679 [ # # ]: 0 : !(non_shared_age && count) &&
8680 [ # # # # : 0 : (attr->group || (attr->transfer && priv->fdb_def_rule)) &&
# # # # ]
8681 [ # # ]: 0 : priv->sh->flow_hit_aso_en);
8682 [ # # ]: 0 : if (__builtin_popcountl(aso_mask) > 1)
8683 : 0 : return rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
8684 : : NULL, "unsupported combining AGE, METER, CT ASO actions in a single rule");
8685 : : /*
8686 : : * Hairpin flow will add one more TAG action in TX implicit mode.
8687 : : * In TX explicit mode, there will be no hairpin flow ID.
8688 : : */
8689 [ # # ]: 0 : if (hairpin > 0)
8690 : 0 : rw_act_num += MLX5_ACT_NUM_SET_TAG;
8691 : : /* extra metadata enabled: one more TAG action will be add. */
8692 [ # # ]: 0 : if (dev_conf->dv_flow_en &&
8693 [ # # # # ]: 0 : dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
8694 : 0 : mlx5_flow_ext_mreg_supported(dev))
8695 : 0 : rw_act_num += MLX5_ACT_NUM_SET_TAG;
8696 [ # # ]: 0 : if (rw_act_num >
8697 : : flow_dv_modify_hdr_action_max(dev, is_root)) {
8698 : 0 : return rte_flow_error_set(error, ENOTSUP,
8699 : : RTE_FLOW_ERROR_TYPE_ACTION,
8700 : : NULL, "too many header modify"
8701 : : " actions to support");
8702 : : }
8703 [ # # ]: 0 : if (fdb_mirror) {
8704 [ # # # # ]: 0 : if (!priv->sh->cdev->config.hca_attr.reg_c_preserve &&
8705 [ # # ]: 0 : flow_source_vport_representor(priv, act_priv)) {
8706 : : /* Eswitch egress mirror and modify flow has limitation on CX5 */
8707 [ # # ]: 0 : if (modify_after_mirror)
8708 : 0 : return rte_flow_error_set(error, EINVAL,
8709 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
8710 : : "sample before modify action is not supported");
8711 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_JUMP)
8712 : 0 : return rte_flow_error_set(error, EINVAL,
8713 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
8714 : : "sample and jump action combination is not supported");
8715 : : }
8716 [ # # ]: 0 : if (aso_mask > 0 && aso_after_sample && fdb_mirror)
8717 : 0 : return rte_flow_error_set(error, ENOTSUP,
8718 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
8719 : : "sample before ASO action is not supported");
8720 [ # # ]: 0 : if (sub_action_flags & MLX5_FLOW_ACTION_PORT_ID) {
8721 : 0 : port_priv = mlx5_port_to_eswitch_info(sample_port_id, false);
8722 [ # # ]: 0 : if (flow_source_vport_representor(priv, port_priv)) {
8723 [ # # ]: 0 : if (sub_action_flags & MLX5_FLOW_ACTION_ENCAP)
8724 : 0 : return rte_flow_error_set(error, ENOTSUP,
8725 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
8726 : : "mirror to rep port with encap is not supported");
8727 : : } else {
8728 [ # # ]: 0 : if (!(sub_action_flags & MLX5_FLOW_ACTION_ENCAP) &&
8729 [ # # ]: 0 : (action_flags & MLX5_FLOW_ACTION_JUMP))
8730 : 0 : return rte_flow_error_set(error, ENOTSUP,
8731 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
8732 : : "mirror to wire port without encap is not supported");
8733 : : }
8734 : : }
8735 [ # # ]: 0 : if ((action_flags & MLX5_FLOW_ACTION_PORT_ID) &&
8736 : : (action_flags & MLX5_FLOW_ACTION_ENCAP)) {
8737 : 0 : port_priv = mlx5_port_to_eswitch_info(port_id, false);
8738 [ # # ]: 0 : if (flow_source_vport_representor(priv, port_priv))
8739 : 0 : return rte_flow_error_set(error, ENOTSUP,
8740 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
8741 : : "mirror to rep port with encap is not supported");
8742 : : }
8743 : : }
8744 : : /*
8745 : : * Validation the NIC Egress flow on representor, except implicit
8746 : : * hairpin default egress flow with TX_QUEUE item, other flows not
8747 : : * work due to metadata regC0 mismatch.
8748 : : */
8749 [ # # # # : 0 : if (attr->egress && priv->representor && !(item_flags & MLX5_FLOW_ITEM_SQ))
# # ]
8750 : 0 : return rte_flow_error_set(error, EINVAL,
8751 : : RTE_FLOW_ERROR_TYPE_ITEM,
8752 : : NULL,
8753 : : "NIC egress rules on representors"
8754 : : " is not supported");
8755 : : return 0;
8756 : : }
8757 : :
8758 : : /**
8759 : : * Internal preparation function. Allocates the DV flow size,
8760 : : * this size is constant.
8761 : : *
8762 : : * @param[in] dev
8763 : : * Pointer to the rte_eth_dev structure.
8764 : : * @param[in] attr
8765 : : * Pointer to the flow attributes.
8766 : : * @param[in] items
8767 : : * Pointer to the list of items.
8768 : : * @param[in] actions
8769 : : * Pointer to the list of actions.
8770 : : * @param[out] error
8771 : : * Pointer to the error structure.
8772 : : *
8773 : : * @return
8774 : : * Pointer to mlx5_flow object on success,
8775 : : * otherwise NULL and rte_errno is set.
8776 : : */
8777 : : static struct mlx5_flow *
8778 : 0 : flow_dv_prepare(struct rte_eth_dev *dev,
8779 : : const struct rte_flow_attr *attr __rte_unused,
8780 : : const struct rte_flow_item items[] __rte_unused,
8781 : : const struct rte_flow_action actions[] __rte_unused,
8782 : : struct rte_flow_error *error)
8783 : : {
8784 : 0 : uint32_t handle_idx = 0;
8785 : : struct mlx5_flow *dev_flow;
8786 : : struct mlx5_flow_handle *dev_handle;
8787 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
8788 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
8789 : :
8790 : : MLX5_ASSERT(wks);
8791 : 0 : wks->skip_matcher_reg = 0;
8792 : 0 : wks->policy = NULL;
8793 : 0 : wks->final_policy = NULL;
8794 : 0 : wks->vport_meta_tag = 0;
8795 : : /* In case of corrupting the memory. */
8796 [ # # ]: 0 : if (wks->flow_idx >= MLX5_NUM_MAX_DEV_FLOWS) {
8797 : 0 : rte_flow_error_set(error, ENOSPC,
8798 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
8799 : : "not free temporary device flow");
8800 : 0 : return NULL;
8801 : : }
8802 : 0 : dev_handle = mlx5_ipool_zmalloc(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
8803 : : &handle_idx);
8804 [ # # ]: 0 : if (!dev_handle) {
8805 : 0 : rte_flow_error_set(error, ENOMEM,
8806 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
8807 : : "not enough memory to create flow handle");
8808 : 0 : return NULL;
8809 : : }
8810 : : MLX5_ASSERT(wks->flow_idx < RTE_DIM(wks->flows));
8811 : 0 : dev_flow = &wks->flows[wks->flow_idx++];
8812 : : memset(dev_flow, 0, sizeof(*dev_flow));
8813 : 0 : dev_flow->handle = dev_handle;
8814 : 0 : dev_flow->handle_idx = handle_idx;
8815 : 0 : dev_flow->dv.value.size = MLX5_ST_SZ_BYTES(fte_match_param);
8816 : 0 : dev_flow->ingress = attr->ingress;
8817 : 0 : dev_flow->dv.transfer = attr->transfer;
8818 : 0 : return dev_flow;
8819 : : }
8820 : :
8821 : : #ifdef RTE_LIBRTE_MLX5_DEBUG
8822 : : /**
8823 : : * Sanity check for match mask and value. Similar to check_valid_spec() in
8824 : : * kernel driver. If unmasked bit is present in value, it returns failure.
8825 : : *
8826 : : * @param match_mask
8827 : : * pointer to match mask buffer.
8828 : : * @param match_value
8829 : : * pointer to match value buffer.
8830 : : *
8831 : : * @return
8832 : : * 0 if valid, -EINVAL otherwise.
8833 : : */
8834 : : static int
8835 : : flow_dv_check_valid_spec(void *match_mask, void *match_value)
8836 : : {
8837 : : uint8_t *m = match_mask;
8838 : : uint8_t *v = match_value;
8839 : : unsigned int i;
8840 : :
8841 : : for (i = 0; i < MLX5_ST_SZ_BYTES(fte_match_param); ++i) {
8842 : : if (v[i] & ~m[i]) {
8843 : : DRV_LOG(ERR,
8844 : : "match_value differs from match_criteria"
8845 : : " %p[%u] != %p[%u]",
8846 : : match_value, i, match_mask, i);
8847 : : return -EINVAL;
8848 : : }
8849 : : }
8850 : : return 0;
8851 : : }
8852 : : #endif
8853 : :
8854 : : /**
8855 : : * Add match of ip_version.
8856 : : *
8857 : : * @param[in] group
8858 : : * Flow group.
8859 : : * @param[in] headers_v
8860 : : * Values header pointer.
8861 : : * @param[in] headers_m
8862 : : * Masks header pointer.
8863 : : * @param[in] ip_version
8864 : : * The IP version to set.
8865 : : */
8866 : : static inline void
8867 : 0 : flow_dv_set_match_ip_version(uint32_t group,
8868 : : void *headers_v,
8869 : : uint32_t key_type,
8870 : : uint8_t ip_version)
8871 : : {
8872 [ # # # # ]: 0 : if (group == 0 && (key_type & MLX5_SET_MATCHER_M))
8873 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_version, 0xf);
8874 : : else
8875 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_version,
8876 : : ip_version);
8877 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ethertype, 0);
8878 : 0 : }
8879 : :
8880 : : /**
8881 : : * Add Ethernet item to the value.
8882 : : *
8883 : : * @param[in, out] key
8884 : : * Flow matcher value.
8885 : : * @param[in] item
8886 : : * Flow pattern to translate.
8887 : : * @param[in] inner
8888 : : * Item is inner pattern.
8889 : : * @param[in] grpup
8890 : : * Flow matcher group.
8891 : : * @param[in] key_type
8892 : : * Set flow matcher mask or value.
8893 : : */
8894 : : static void
8895 : 0 : flow_dv_translate_item_eth(void *key, const struct rte_flow_item *item,
8896 : : int inner, uint32_t group, uint32_t key_type)
8897 : : {
8898 : 0 : const struct rte_flow_item_eth *eth_vv = item->spec;
8899 : : const struct rte_flow_item_eth *eth_m;
8900 : : const struct rte_flow_item_eth *eth_v;
8901 : 0 : const struct rte_flow_item_eth nic_mask = {
8902 : : .hdr.dst_addr.addr_bytes = "\xff\xff\xff\xff\xff\xff",
8903 : : .hdr.src_addr.addr_bytes = "\xff\xff\xff\xff\xff\xff",
8904 : : .hdr.ether_type = RTE_BE16(0xffff),
8905 : : .has_vlan = 0,
8906 : : };
8907 : : void *hdrs_v;
8908 : : char *l24_v;
8909 : : unsigned int i;
8910 : :
8911 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
8912 : 0 : return;
8913 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, eth_v, eth_m, &nic_mask);
# # # # ]
8914 [ # # ]: 0 : if (!eth_vv)
8915 : : eth_vv = eth_v;
8916 [ # # ]: 0 : if (inner)
8917 : 0 : hdrs_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8918 : : else
8919 : : hdrs_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8920 : : /* The value must be in the range of the mask. */
8921 : : l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_v, dmac_47_16);
8922 [ # # ]: 0 : for (i = 0; i < sizeof(eth_m->hdr.dst_addr); ++i)
8923 : 0 : l24_v[i] = eth_m->hdr.dst_addr.addr_bytes[i] & eth_v->hdr.dst_addr.addr_bytes[i];
8924 : : l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_v, smac_47_16);
8925 : : /* The value must be in the range of the mask. */
8926 [ # # ]: 0 : for (i = 0; i < sizeof(eth_m->hdr.dst_addr); ++i)
8927 : 0 : l24_v[i] = eth_m->hdr.src_addr.addr_bytes[i] & eth_v->hdr.src_addr.addr_bytes[i];
8928 : : /*
8929 : : * HW supports match on one Ethertype, the Ethertype following the last
8930 : : * VLAN tag of the packet (see PRM).
8931 : : * Set match on ethertype only if ETH header is not followed by VLAN.
8932 : : * HW is optimized for IPv4/IPv6. In such cases, avoid setting
8933 : : * ethertype, and use ip_version field instead.
8934 : : * eCPRI over Ether layer will use type value 0xAEFE.
8935 : : */
8936 [ # # ]: 0 : if (eth_m->hdr.ether_type == 0xFFFF) {
8937 : 0 : rte_be16_t type = eth_v->hdr.ether_type;
8938 : :
8939 : : /*
8940 : : * When set the matcher mask, refer to the original spec
8941 : : * value.
8942 : : */
8943 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_SW_M) {
8944 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 1);
8945 : 0 : type = eth_vv->hdr.ether_type;
8946 : : }
8947 : : /* Set cvlan_tag mask for any single\multi\un-tagged case. */
8948 [ # # # # : 0 : switch (type) {
# ]
8949 : 0 : case RTE_BE16(RTE_ETHER_TYPE_VLAN):
8950 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 1);
8951 : 0 : return;
8952 : 0 : case RTE_BE16(RTE_ETHER_TYPE_QINQ):
8953 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag, 1);
8954 : 0 : return;
8955 : 0 : case RTE_BE16(RTE_ETHER_TYPE_IPV4):
8956 : 0 : flow_dv_set_match_ip_version(group, hdrs_v, key_type,
8957 : : 4);
8958 : 0 : return;
8959 : 0 : case RTE_BE16(RTE_ETHER_TYPE_IPV6):
8960 : 0 : flow_dv_set_match_ip_version(group, hdrs_v, key_type,
8961 : : 6);
8962 : 0 : return;
8963 : : default:
8964 : : break;
8965 : : }
8966 : : }
8967 : : /*
8968 : : * Only SW steering value should refer to the mask value.
8969 : : * Other cases are using the fake masks, just ignore the mask.
8970 : : */
8971 [ # # # # ]: 0 : if (eth_v->has_vlan && eth_m->has_vlan) {
8972 : : /*
8973 : : * Here, when also has_more_vlan field in VLAN item is
8974 : : * not set, only single-tagged packets will be matched.
8975 : : */
8976 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 1);
8977 [ # # # # ]: 0 : if (key_type != MLX5_SET_MATCHER_HS_M && eth_vv->has_vlan)
8978 : : return;
8979 : : }
8980 : : l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_v, ethertype);
8981 : 0 : *(uint16_t *)(l24_v) = eth_m->hdr.ether_type & eth_v->hdr.ether_type;
8982 : : }
8983 : :
8984 : : /**
8985 : : * Add VLAN item to the value.
8986 : : *
8987 : : * @param[in, out] key
8988 : : * Flow matcher value.
8989 : : * @param[in] item
8990 : : * Flow pattern to translate.
8991 : : * @param[in] inner
8992 : : * Item is inner pattern.
8993 : : * @param[in] wks
8994 : : * Item workspace.
8995 : : * @param[in] key_type
8996 : : * Set flow matcher mask or value.
8997 : : */
8998 : : static void
8999 : 0 : flow_dv_translate_item_vlan(void *key, const struct rte_flow_item *item,
9000 : : int inner, struct mlx5_dv_matcher_workspace *wks,
9001 : : uint32_t key_type)
9002 : : {
9003 : : const struct rte_flow_item_vlan *vlan_m;
9004 : : const struct rte_flow_item_vlan *vlan_v;
9005 : 0 : const struct rte_flow_item_vlan *vlan_vv = item->spec;
9006 : : void *hdrs_v;
9007 : : uint16_t tci_v;
9008 : :
9009 [ # # ]: 0 : if (inner) {
9010 : 0 : hdrs_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
9011 : : } else {
9012 : : hdrs_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9013 : : /*
9014 : : * This is workaround, masks are not supported,
9015 : : * and pre-validated.
9016 : : */
9017 [ # # ]: 0 : if (vlan_vv)
9018 [ # # ]: 0 : wks->vlan_tag = rte_be_to_cpu_16(vlan_vv->hdr.vlan_tci) & 0x0fff;
9019 : : }
9020 : : /*
9021 : : * When VLAN item exists in flow, mark packet as tagged,
9022 : : * even if TCI is not specified.
9023 : : */
9024 [ # # # # ]: 0 : if (!MLX5_GET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag))
9025 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 1);
9026 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9027 : : return;
9028 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, vlan_v, vlan_m,
# # # # ]
9029 : : &rte_flow_item_vlan_mask);
9030 [ # # ]: 0 : tci_v = rte_be_to_cpu_16(vlan_m->hdr.vlan_tci & vlan_v->hdr.vlan_tci);
9031 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, first_vid, tci_v);
9032 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, first_cfi, tci_v >> 12);
9033 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, first_prio, tci_v >> 13);
9034 : : /*
9035 : : * HW is optimized for IPv4/IPv6. In such cases, avoid setting
9036 : : * ethertype, and use ip_version field instead.
9037 : : */
9038 [ # # ]: 0 : if (vlan_m->hdr.eth_proto == 0xFFFF) {
9039 : 0 : rte_be16_t inner_type = vlan_v->hdr.eth_proto;
9040 : :
9041 : : /*
9042 : : * When set the matcher mask, refer to the original spec
9043 : : * value.
9044 : : */
9045 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_SW_M)
9046 : 0 : inner_type = vlan_vv->hdr.eth_proto;
9047 [ # # # # ]: 0 : switch (inner_type) {
9048 : 0 : case RTE_BE16(RTE_ETHER_TYPE_VLAN):
9049 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag, 1);
9050 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_V)
9051 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v,
9052 : : cvlan_tag, 0);
9053 : 0 : return;
9054 : 0 : case RTE_BE16(RTE_ETHER_TYPE_IPV4):
9055 : 0 : flow_dv_set_match_ip_version
9056 : : (wks->group, hdrs_v, key_type, 4);
9057 : 0 : return;
9058 : 0 : case RTE_BE16(RTE_ETHER_TYPE_IPV6):
9059 : 0 : flow_dv_set_match_ip_version
9060 : : (wks->group, hdrs_v, key_type, 6);
9061 : 0 : return;
9062 : : default:
9063 : : break;
9064 : : }
9065 : : }
9066 [ # # # # ]: 0 : if (vlan_m->has_more_vlan && vlan_v->has_more_vlan) {
9067 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag, 1);
9068 : : /* Only one vlan_tag bit can be set. */
9069 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_V)
9070 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 0);
9071 : 0 : return;
9072 : : }
9073 [ # # # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, ethertype,
9074 : : rte_be_to_cpu_16(vlan_m->hdr.eth_proto & vlan_v->hdr.eth_proto));
9075 : : }
9076 : :
9077 : : /**
9078 : : * Add IPV4 item to the value.
9079 : : *
9080 : : * @param[in, out] key
9081 : : * Flow matcher value.
9082 : : * @param[in] item
9083 : : * Flow pattern to translate.
9084 : : * @param[in] inner
9085 : : * Item is inner pattern.
9086 : : * @param[in] group
9087 : : * The group to insert the rule.
9088 : : * @param[in] key_type
9089 : : * Set flow matcher mask or value.
9090 : : */
9091 : : static void
9092 : 0 : flow_dv_translate_item_ipv4(void *key, const struct rte_flow_item *item,
9093 : : int inner, uint32_t group, uint32_t key_type)
9094 : : {
9095 : : const struct rte_flow_item_ipv4 *ipv4_m;
9096 : : const struct rte_flow_item_ipv4 *ipv4_v;
9097 : 0 : const struct rte_flow_item_ipv4 nic_mask = {
9098 : : .hdr = {
9099 : : .src_addr = RTE_BE32(0xffffffff),
9100 : : .dst_addr = RTE_BE32(0xffffffff),
9101 : : .type_of_service = 0xff,
9102 : : .next_proto_id = 0xff,
9103 : : .time_to_live = 0xff,
9104 : : },
9105 : : };
9106 : : void *headers_v;
9107 : : char *l24_v;
9108 : : uint8_t tos;
9109 : :
9110 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
9111 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9112 : 0 : flow_dv_set_match_ip_version(group, headers_v, key_type, 4);
9113 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9114 : 0 : return;
9115 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, ipv4_v, ipv4_m, &nic_mask);
# # # # ]
9116 : : l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
9117 : : dst_ipv4_dst_ipv6.ipv4_layout.ipv4);
9118 : 0 : *(uint32_t *)l24_v = ipv4_m->hdr.dst_addr & ipv4_v->hdr.dst_addr;
9119 : : l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
9120 : : src_ipv4_src_ipv6.ipv4_layout.ipv4);
9121 : 0 : *(uint32_t *)l24_v = ipv4_m->hdr.src_addr & ipv4_v->hdr.src_addr;
9122 : 0 : tos = ipv4_m->hdr.type_of_service & ipv4_v->hdr.type_of_service;
9123 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ipv4_ihl,
9124 : : ipv4_v->hdr.ihl & ipv4_m->hdr.ihl);
9125 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_SW_M)
9126 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ecn,
9127 : : ipv4_v->hdr.type_of_service);
9128 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ecn, tos);
9129 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_dscp, tos >> 2);
9130 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
9131 : : ipv4_v->hdr.next_proto_id & ipv4_m->hdr.next_proto_id);
9132 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ttl_hoplimit,
9133 : : ipv4_v->hdr.time_to_live & ipv4_m->hdr.time_to_live);
9134 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, frag,
9135 : : !!(ipv4_v->hdr.fragment_offset & ipv4_m->hdr.fragment_offset));
9136 : : }
9137 : :
9138 : : /**
9139 : : * Add IPV6 item to the value.
9140 : : *
9141 : : * @param[in, out] key
9142 : : * Flow matcher value.
9143 : : * @param[in] item
9144 : : * Flow pattern to translate.
9145 : : * @param[in] inner
9146 : : * Item is inner pattern.
9147 : : * @param[in] group
9148 : : * The group to insert the rule.
9149 : : * @param[in] key_type
9150 : : * Set flow matcher mask or value.
9151 : : */
9152 : : static void
9153 : 0 : flow_dv_translate_item_ipv6(void *key, const struct rte_flow_item *item,
9154 : : int inner, uint32_t group, uint32_t key_type)
9155 : : {
9156 : : const struct rte_flow_item_ipv6 *ipv6_m;
9157 : : const struct rte_flow_item_ipv6 *ipv6_v;
9158 : 0 : const struct rte_flow_item_ipv6 nic_mask = {
9159 : : .hdr = {
9160 : : .src_addr =
9161 : : "\xff\xff\xff\xff\xff\xff\xff\xff"
9162 : : "\xff\xff\xff\xff\xff\xff\xff\xff",
9163 : : .dst_addr =
9164 : : "\xff\xff\xff\xff\xff\xff\xff\xff"
9165 : : "\xff\xff\xff\xff\xff\xff\xff\xff",
9166 : : .vtc_flow = RTE_BE32(0xffffffff),
9167 : : .proto = 0xff,
9168 : : .hop_limits = 0xff,
9169 : : },
9170 : : };
9171 : : void *headers_v;
9172 : : void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
9173 : : char *l24_v;
9174 : : uint32_t vtc_v;
9175 : : int i;
9176 : : int size;
9177 : :
9178 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
9179 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9180 : 0 : flow_dv_set_match_ip_version(group, headers_v, key_type, 6);
9181 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9182 : 0 : return;
9183 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, ipv6_v, ipv6_m, &nic_mask);
# # # # ]
9184 : : size = sizeof(ipv6_m->hdr.dst_addr);
9185 : : l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
9186 : : dst_ipv4_dst_ipv6.ipv6_layout.ipv6);
9187 [ # # ]: 0 : for (i = 0; i < size; ++i)
9188 : 0 : l24_v[i] = ipv6_m->hdr.dst_addr[i] & ipv6_v->hdr.dst_addr[i];
9189 : : l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
9190 : : src_ipv4_src_ipv6.ipv6_layout.ipv6);
9191 [ # # ]: 0 : for (i = 0; i < size; ++i)
9192 : 0 : l24_v[i] = ipv6_m->hdr.src_addr[i] & ipv6_v->hdr.src_addr[i];
9193 : : /* TOS. */
9194 [ # # ]: 0 : vtc_v = rte_be_to_cpu_32(ipv6_m->hdr.vtc_flow & ipv6_v->hdr.vtc_flow);
9195 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ecn, vtc_v >> 20);
9196 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_dscp, vtc_v >> 22);
9197 : : /* Label. */
9198 [ # # ]: 0 : if (inner)
9199 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, inner_ipv6_flow_label,
9200 : : vtc_v);
9201 : : else
9202 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, outer_ipv6_flow_label,
9203 : : vtc_v);
9204 : : /* Protocol. */
9205 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
9206 : : ipv6_v->hdr.proto & ipv6_m->hdr.proto);
9207 : : /* Hop limit. */
9208 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ttl_hoplimit,
9209 : : ipv6_v->hdr.hop_limits & ipv6_m->hdr.hop_limits);
9210 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, frag,
9211 : : !!(ipv6_v->has_frag_ext & ipv6_m->has_frag_ext));
9212 : : }
9213 : :
9214 : : /**
9215 : : * Add IPV6 fragment extension item to the value.
9216 : : *
9217 : : * @param[in, out] key
9218 : : * Flow matcher value.
9219 : : * @param[in] item
9220 : : * Flow pattern to translate.
9221 : : * @param[in] inner
9222 : : * Item is inner pattern.
9223 : : * @param[in] key_type
9224 : : * Set flow matcher mask or value.
9225 : : */
9226 : : static void
9227 : 0 : flow_dv_translate_item_ipv6_frag_ext(void *key,
9228 : : const struct rte_flow_item *item,
9229 : : int inner, uint32_t key_type)
9230 : : {
9231 : : const struct rte_flow_item_ipv6_frag_ext *ipv6_frag_ext_m;
9232 : : const struct rte_flow_item_ipv6_frag_ext *ipv6_frag_ext_v;
9233 : 0 : const struct rte_flow_item_ipv6_frag_ext nic_mask = {
9234 : : .hdr = {
9235 : : .next_header = 0xff,
9236 : : .frag_data = RTE_BE16(0xffff),
9237 : : },
9238 : : };
9239 : : void *headers_v;
9240 : :
9241 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
9242 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9243 : : /* IPv6 fragment extension item exists, so packet is IP fragment. */
9244 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, frag, 1);
9245 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9246 : 0 : return;
9247 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, ipv6_frag_ext_v,
# # # # ]
9248 : : ipv6_frag_ext_m, &nic_mask);
9249 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
9250 : : ipv6_frag_ext_v->hdr.next_header &
9251 : : ipv6_frag_ext_m->hdr.next_header);
9252 : : }
9253 : :
9254 : : /**
9255 : : * Add TCP item to the value.
9256 : : *
9257 : : * @param[in, out] key
9258 : : * Flow matcher value.
9259 : : * @param[in] item
9260 : : * Flow pattern to translate.
9261 : : * @param[in] inner
9262 : : * Item is inner pattern.
9263 : : * @param[in] key_type
9264 : : * Set flow matcher mask or value.
9265 : : */
9266 : : static void
9267 : 0 : flow_dv_translate_item_tcp(void *key, const struct rte_flow_item *item,
9268 : : int inner, uint32_t key_type)
9269 : : {
9270 : : const struct rte_flow_item_tcp *tcp_m;
9271 : : const struct rte_flow_item_tcp *tcp_v;
9272 : : void *headers_v;
9273 : :
9274 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
9275 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9276 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
9277 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
9278 : : ip_protocol, 0xff);
9279 : : else
9280 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
9281 : : ip_protocol, IPPROTO_TCP);
9282 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9283 : : return;
9284 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, tcp_v, tcp_m,
# # # # ]
9285 : : &rte_flow_item_tcp_mask);
9286 [ # # # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_sport,
9287 : : rte_be_to_cpu_16(tcp_v->hdr.src_port & tcp_m->hdr.src_port));
9288 [ # # # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_dport,
9289 : : rte_be_to_cpu_16(tcp_v->hdr.dst_port & tcp_m->hdr.dst_port));
9290 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_flags,
9291 : : tcp_v->hdr.tcp_flags & tcp_m->hdr.tcp_flags);
9292 : : }
9293 : :
9294 : : /**
9295 : : * Add ESP item to the value.
9296 : : *
9297 : : * @param[in, out] key
9298 : : * Flow matcher value.
9299 : : * @param[in] item
9300 : : * Flow pattern to translate.
9301 : : * @param[in] inner
9302 : : * Item is inner pattern.
9303 : : * @param[in] key_type
9304 : : * Set flow matcher mask or value.
9305 : : */
9306 : : static void
9307 : 0 : flow_dv_translate_item_esp(void *key, const struct rte_flow_item *item,
9308 : : int inner, uint32_t key_type)
9309 : : {
9310 : : const struct rte_flow_item_esp *esp_m;
9311 : : const struct rte_flow_item_esp *esp_v;
9312 : : void *headers_v;
9313 : : char *spi_v;
9314 : :
9315 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
9316 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9317 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
9318 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
9319 : : ip_protocol, 0xff);
9320 : : else
9321 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
9322 : : ip_protocol, IPPROTO_ESP);
9323 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9324 : : return;
9325 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, esp_v, esp_m,
# # # # ]
9326 : : &rte_flow_item_esp_mask);
9327 : : headers_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
9328 : : spi_v = inner ? MLX5_ADDR_OF(fte_match_set_misc, headers_v,
9329 [ # # ]: 0 : inner_esp_spi) : MLX5_ADDR_OF(fte_match_set_misc
9330 : : , headers_v, outer_esp_spi);
9331 : 0 : *(uint32_t *)spi_v = esp_m->hdr.spi & esp_v->hdr.spi;
9332 : : }
9333 : :
9334 : : /**
9335 : : * Add UDP item to the value.
9336 : : *
9337 : : * @param[in, out] key
9338 : : * Flow matcher value.
9339 : : * @param[in] item
9340 : : * Flow pattern to translate.
9341 : : * @param[in] inner
9342 : : * Item is inner pattern.
9343 : : * @param[in] key_type
9344 : : * Set flow matcher mask or value.
9345 : : */
9346 : : static void
9347 : 0 : flow_dv_translate_item_udp(void *key, const struct rte_flow_item *item,
9348 : : int inner, struct mlx5_dv_matcher_workspace *wks,
9349 : : uint32_t key_type)
9350 : : {
9351 : : const struct rte_flow_item_udp *udp_m;
9352 : : const struct rte_flow_item_udp *udp_v;
9353 : : void *headers_v;
9354 : :
9355 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
9356 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9357 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
9358 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
9359 : : ip_protocol, 0xff);
9360 : : else
9361 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
9362 : : ip_protocol, IPPROTO_UDP);
9363 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9364 : : return;
9365 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, udp_v, udp_m,
# # # # ]
9366 : : &rte_flow_item_udp_mask);
9367 [ # # # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_sport,
9368 : : rte_be_to_cpu_16(udp_v->hdr.src_port & udp_m->hdr.src_port));
9369 [ # # # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
9370 : : rte_be_to_cpu_16(udp_v->hdr.dst_port & udp_m->hdr.dst_port));
9371 : : /* Force get UDP dport in case to be used in VXLAN translate. */
9372 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_SW) {
9373 : 0 : udp_v = item->spec;
9374 [ # # ]: 0 : wks->udp_dport = rte_be_to_cpu_16(udp_v->hdr.dst_port &
9375 : : udp_m->hdr.dst_port);
9376 : : }
9377 : : }
9378 : :
9379 : : /**
9380 : : * Add GRE optional Key item to the value.
9381 : : *
9382 : : * @param[in, out] key
9383 : : * Flow matcher value.
9384 : : * @param[in] item
9385 : : * Flow pattern to translate.
9386 : : * @param[in] inner
9387 : : * Item is inner pattern.
9388 : : */
9389 : : static void
9390 : 0 : flow_dv_translate_item_gre_key(void *key, const struct rte_flow_item *item,
9391 : : uint32_t key_type)
9392 : : {
9393 : : const rte_be32_t *key_m;
9394 : : const rte_be32_t *key_v;
9395 : : void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
9396 : 0 : rte_be32_t gre_key_default_mask = RTE_BE32(UINT32_MAX);
9397 : :
9398 : : /* GRE K bit must be on and should already be validated */
9399 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, gre_k_present, 1);
9400 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9401 : 0 : return;
9402 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, key_v, key_m,
# # # # ]
9403 : : &gre_key_default_mask);
9404 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, gre_key_h,
9405 : : rte_be_to_cpu_32((*key_v) & (*key_m)) >> 8);
9406 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, gre_key_l,
9407 : : rte_be_to_cpu_32((*key_v) & (*key_m)) & 0xFF);
9408 : : }
9409 : :
9410 : : /**
9411 : : * Add GRE item to the value.
9412 : : *
9413 : : * @param[in, out] key
9414 : : * Flow matcher value.
9415 : : * @param[in] item
9416 : : * Flow pattern to translate.
9417 : : * @param[in] pattern_flags
9418 : : * Accumulated pattern flags.
9419 : : * @param[in] key_type
9420 : : * Set flow matcher mask or value.
9421 : : */
9422 : : static void
9423 : 0 : flow_dv_translate_item_gre(void *key, const struct rte_flow_item *item,
9424 : : uint64_t pattern_flags, uint32_t key_type)
9425 : : {
9426 : : static const struct rte_flow_item_gre empty_gre = {0,};
9427 : 0 : const struct rte_flow_item_gre *gre_m = item->mask;
9428 : 0 : const struct rte_flow_item_gre *gre_v = item->spec;
9429 : : void *headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9430 : : void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
9431 : : struct {
9432 : : union {
9433 : : __extension__
9434 : : struct {
9435 : : uint16_t version:3;
9436 : : uint16_t rsvd0:9;
9437 : : uint16_t s_present:1;
9438 : : uint16_t k_present:1;
9439 : : uint16_t rsvd_bit1:1;
9440 : : uint16_t c_present:1;
9441 : : };
9442 : : uint16_t value;
9443 : : };
9444 : : } gre_crks_rsvd0_ver_m, gre_crks_rsvd0_ver_v;
9445 : : uint16_t protocol_m, protocol_v;
9446 : :
9447 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
9448 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, 0xff);
9449 : : else
9450 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
9451 : : IPPROTO_GRE);
9452 [ # # ]: 0 : if (!gre_v) {
9453 : : gre_v = &empty_gre;
9454 : : gre_m = &empty_gre;
9455 : : } else {
9456 [ # # ]: 0 : if (!gre_m)
9457 : : gre_m = &rte_flow_item_gre_mask;
9458 : : }
9459 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
9460 : : gre_v = gre_m;
9461 [ # # ]: 0 : else if (key_type == MLX5_SET_MATCHER_HS_V)
9462 : : gre_m = gre_v;
9463 [ # # ]: 0 : gre_crks_rsvd0_ver_m.value = rte_be_to_cpu_16(gre_m->c_rsvd0_ver);
9464 [ # # ]: 0 : gre_crks_rsvd0_ver_v.value = rte_be_to_cpu_16(gre_v->c_rsvd0_ver);
9465 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, gre_c_present,
9466 : : gre_crks_rsvd0_ver_v.c_present &
9467 : : gre_crks_rsvd0_ver_m.c_present);
9468 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, gre_k_present,
9469 : : gre_crks_rsvd0_ver_v.k_present &
9470 : : gre_crks_rsvd0_ver_m.k_present);
9471 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, gre_s_present,
9472 : : gre_crks_rsvd0_ver_v.s_present &
9473 : : gre_crks_rsvd0_ver_m.s_present);
9474 [ # # ]: 0 : protocol_m = rte_be_to_cpu_16(gre_m->protocol);
9475 [ # # ]: 0 : protocol_v = rte_be_to_cpu_16(gre_v->protocol);
9476 [ # # ]: 0 : if (!protocol_m) {
9477 : : /* Force next protocol to prevent matchers duplication */
9478 : : protocol_v = mlx5_translate_tunnel_etypes(pattern_flags);
9479 : : if (protocol_v)
9480 : : protocol_m = 0xFFFF;
9481 : : /* Restore the value to mask in mask case. */
9482 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
9483 : : protocol_v = protocol_m;
9484 : : }
9485 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, gre_protocol,
9486 : : protocol_m & protocol_v);
9487 : 0 : }
9488 : :
9489 : : /**
9490 : : * Add GRE optional items to the value.
9491 : : *
9492 : : * @param[in, out] key
9493 : : * Flow matcher value.
9494 : : * @param[in] item
9495 : : * Flow pattern to translate.
9496 : : * @param[in] gre_item
9497 : : * Pointer to gre_item.
9498 : : * @param[in] pattern_flags
9499 : : * Accumulated pattern flags.
9500 : : * @param[in] key_type
9501 : : * Set flow matcher mask or value.
9502 : : */
9503 : : static void
9504 : 0 : flow_dv_translate_item_gre_option(void *key,
9505 : : const struct rte_flow_item *item,
9506 : : const struct rte_flow_item *gre_item,
9507 : : uint64_t pattern_flags, uint32_t key_type)
9508 : : {
9509 : : void *misc5_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_5);
9510 : 0 : const struct rte_flow_item_gre_opt *option_m = item->mask;
9511 : 0 : const struct rte_flow_item_gre_opt *option_v = item->spec;
9512 : 0 : const struct rte_flow_item_gre *gre_m = gre_item->mask;
9513 : 0 : const struct rte_flow_item_gre *gre_v = gre_item->spec;
9514 : : static const struct rte_flow_item_gre empty_gre = {0};
9515 : : struct rte_flow_item gre_key_item;
9516 : : uint16_t c_rsvd0_ver_m, c_rsvd0_ver_v;
9517 : : uint16_t protocol_m, protocol_v;
9518 : :
9519 : : /*
9520 : : * If only match key field, keep using misc for matching.
9521 : : * If need to match checksum or sequence, using misc5 and do
9522 : : * not need using misc.
9523 : : */
9524 [ # # ]: 0 : if (!(option_m->sequence.sequence ||
9525 [ # # ]: 0 : option_m->checksum_rsvd.checksum)) {
9526 : 0 : flow_dv_translate_item_gre(key, gre_item, pattern_flags, key_type);
9527 : 0 : gre_key_item.spec = &option_v->key.key;
9528 : 0 : gre_key_item.mask = &option_m->key.key;
9529 : 0 : flow_dv_translate_item_gre_key(key, &gre_key_item, key_type);
9530 : 0 : return;
9531 : : }
9532 [ # # ]: 0 : if (!gre_v) {
9533 : : gre_v = &empty_gre;
9534 : : gre_m = &empty_gre;
9535 : : } else {
9536 [ # # ]: 0 : if (!gre_m)
9537 : : gre_m = &rte_flow_item_gre_mask;
9538 : : }
9539 : 0 : protocol_v = gre_v->protocol;
9540 : 0 : protocol_m = gre_m->protocol;
9541 [ # # ]: 0 : if (!protocol_m) {
9542 : : /* Force next protocol to prevent matchers duplication */
9543 : : uint16_t ether_type =
9544 : : mlx5_translate_tunnel_etypes(pattern_flags);
9545 : : if (ether_type) {
9546 [ # # ]: 0 : protocol_v = rte_be_to_cpu_16(ether_type);
9547 : : protocol_m = UINT16_MAX;
9548 : : }
9549 : : }
9550 : 0 : c_rsvd0_ver_v = gre_v->c_rsvd0_ver;
9551 : 0 : c_rsvd0_ver_m = gre_m->c_rsvd0_ver;
9552 [ # # ]: 0 : if (option_m->sequence.sequence) {
9553 : 0 : c_rsvd0_ver_v |= RTE_BE16(0x1000);
9554 : 0 : c_rsvd0_ver_m |= RTE_BE16(0x1000);
9555 : : }
9556 [ # # ]: 0 : if (option_m->key.key) {
9557 : 0 : c_rsvd0_ver_v |= RTE_BE16(0x2000);
9558 : 0 : c_rsvd0_ver_m |= RTE_BE16(0x2000);
9559 : : }
9560 [ # # ]: 0 : if (option_m->checksum_rsvd.checksum) {
9561 : 0 : c_rsvd0_ver_v |= RTE_BE16(0x8000);
9562 : 0 : c_rsvd0_ver_m |= RTE_BE16(0x8000);
9563 : : }
9564 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M) {
9565 : : c_rsvd0_ver_v = c_rsvd0_ver_m;
9566 : : protocol_v = protocol_m;
9567 : : option_v = option_m;
9568 : : }
9569 : : /*
9570 : : * Hardware parses GRE optional field into the fixed location,
9571 : : * do not need to adjust the tunnel dword indices.
9572 : : */
9573 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc5, misc5_v, tunnel_header_0,
9574 : : rte_be_to_cpu_32((c_rsvd0_ver_v | protocol_v << 16) &
9575 : : (c_rsvd0_ver_m | protocol_m << 16)));
9576 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc5, misc5_v, tunnel_header_1,
9577 : : rte_be_to_cpu_32(option_v->checksum_rsvd.checksum &
9578 : : option_m->checksum_rsvd.checksum));
9579 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc5, misc5_v, tunnel_header_2,
9580 : : rte_be_to_cpu_32(option_v->key.key & option_m->key.key));
9581 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc5, misc5_v, tunnel_header_3,
9582 : : rte_be_to_cpu_32(option_v->sequence.sequence &
9583 : : option_m->sequence.sequence));
9584 : : }
9585 : :
9586 : : /**
9587 : : * Add NVGRE item to matcher and to the value.
9588 : : *
9589 : : * @param[in, out] key
9590 : : * Flow matcher value.
9591 : : * @param[in] item
9592 : : * Flow pattern to translate.
9593 : : * @param[in] pattern_flags
9594 : : * Accumulated pattern flags.
9595 : : * @param[in] key_type
9596 : : * Set flow matcher mask or value.
9597 : : */
9598 : : static void
9599 : 0 : flow_dv_translate_item_nvgre(void *key, const struct rte_flow_item *item,
9600 : : unsigned long pattern_flags, uint32_t key_type)
9601 : : {
9602 : : const struct rte_flow_item_nvgre *nvgre_m;
9603 : : const struct rte_flow_item_nvgre *nvgre_v;
9604 : : void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
9605 : : const char *tni_flow_id_m;
9606 : : const char *tni_flow_id_v;
9607 : : char *gre_key_v;
9608 : : int size;
9609 : : int i;
9610 : :
9611 : : /* For NVGRE, GRE header fields must be set with defined values. */
9612 : 0 : const struct rte_flow_item_gre gre_spec = {
9613 : : .c_rsvd0_ver = RTE_BE16(0x2000),
9614 : : .protocol = RTE_BE16(RTE_ETHER_TYPE_TEB)
9615 : : };
9616 : 0 : const struct rte_flow_item_gre gre_mask = {
9617 : : .c_rsvd0_ver = RTE_BE16(0xB000),
9618 : : .protocol = RTE_BE16(UINT16_MAX),
9619 : : };
9620 : 0 : const struct rte_flow_item gre_item = {
9621 : : .spec = &gre_spec,
9622 : : .mask = &gre_mask,
9623 : : .last = NULL,
9624 : : };
9625 : 0 : flow_dv_translate_item_gre(key, &gre_item, pattern_flags, key_type);
9626 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9627 : 0 : return;
9628 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, nvgre_v, nvgre_m,
# # # # ]
9629 : : &rte_flow_item_nvgre_mask);
9630 : 0 : tni_flow_id_m = (const char *)nvgre_m->tni;
9631 : 0 : tni_flow_id_v = (const char *)nvgre_v->tni;
9632 : : size = sizeof(nvgre_m->tni) + sizeof(nvgre_m->flow_id);
9633 : 0 : gre_key_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, gre_key_h);
9634 [ # # ]: 0 : for (i = 0; i < size; ++i)
9635 : 0 : gre_key_v[i] = tni_flow_id_m[i] & tni_flow_id_v[i];
9636 : : }
9637 : :
9638 : : /**
9639 : : * Add VXLAN item to the value.
9640 : : *
9641 : : * @param[in] dev
9642 : : * Pointer to the Ethernet device structure.
9643 : : * @param[in] attr
9644 : : * Flow rule attributes.
9645 : : * @param[in, out] key
9646 : : * Flow matcher value.
9647 : : * @param[in] item
9648 : : * Flow pattern to translate.
9649 : : * @param[in] inner
9650 : : * Item is inner pattern.
9651 : : * @param[in] wks
9652 : : * Matcher workspace.
9653 : : * @param[in] key_type
9654 : : * Set flow matcher mask or value.
9655 : : */
9656 : : static void
9657 : 0 : flow_dv_translate_item_vxlan(struct rte_eth_dev *dev,
9658 : : const struct rte_flow_attr *attr,
9659 : : void *key, const struct rte_flow_item *item,
9660 : : int inner, struct mlx5_dv_matcher_workspace *wks,
9661 : : uint32_t key_type)
9662 : : {
9663 : : const struct rte_flow_item_vxlan *vxlan_m;
9664 : : const struct rte_flow_item_vxlan *vxlan_v;
9665 : : void *headers_v;
9666 : : void *misc_v;
9667 : : void *misc5_v;
9668 : : uint32_t tunnel_v;
9669 : : char *vni_v;
9670 : : uint16_t dport;
9671 : : int size;
9672 : : int i;
9673 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
9674 : 0 : const struct rte_flow_item_vxlan nic_mask = {
9675 : : .hdr.vni = "\xff\xff\xff",
9676 : : .hdr.rsvd1 = 0xff,
9677 : : };
9678 : :
9679 : : misc5_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_5);
9680 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
9681 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9682 [ # # ]: 0 : dport = item->type == RTE_FLOW_ITEM_TYPE_VXLAN ?
9683 : : MLX5_UDP_PORT_VXLAN : MLX5_UDP_PORT_VXLAN_GPE;
9684 [ # # # # ]: 0 : if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
9685 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
9686 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
9687 : : udp_dport, 0xFFFF);
9688 : : else
9689 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
9690 : : udp_dport, dport);
9691 : : }
9692 : : /*
9693 : : * Read the UDP dport to check if the value satisfies the VXLAN
9694 : : * matching with MISC5 for CX5.
9695 : : */
9696 [ # # ]: 0 : if (wks->udp_dport)
9697 : : dport = wks->udp_dport;
9698 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9699 : 0 : return;
9700 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, vxlan_v, vxlan_m, &nic_mask);
# # # # ]
9701 : : if ((item->mask == &nic_mask) &&
9702 : : ((!attr->group && !(attr->transfer && priv->fdb_def_rule) &&
9703 : : !priv->sh->tunnel_header_0_1) ||
9704 : : ((attr->group || (attr->transfer && priv->fdb_def_rule)) &&
9705 : : !priv->sh->misc5_cap)))
9706 : : vxlan_m = &rte_flow_item_vxlan_mask;
9707 [ # # ]: 0 : if ((priv->sh->steering_format_version ==
9708 [ # # ]: 0 : MLX5_STEERING_LOGIC_FORMAT_CONNECTX_5 &&
9709 : 0 : dport != MLX5_UDP_PORT_VXLAN) ||
9710 [ # # # # : 0 : (!attr->group && !(attr->transfer && priv->fdb_def_rule)) ||
# # # # ]
9711 [ # # # # ]: 0 : ((attr->group || (attr->transfer && priv->fdb_def_rule)) &&
9712 [ # # ]: 0 : !priv->sh->misc5_cap)) {
9713 : : misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
9714 : : size = sizeof(vxlan_m->hdr.vni);
9715 : 0 : vni_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, vxlan_vni);
9716 [ # # ]: 0 : for (i = 0; i < size; ++i)
9717 : 0 : vni_v[i] = vxlan_m->hdr.vni[i] & vxlan_v->hdr.vni[i];
9718 : : return;
9719 : : }
9720 : 0 : tunnel_v = (vxlan_v->hdr.vni[0] & vxlan_m->hdr.vni[0]) |
9721 : 0 : (vxlan_v->hdr.vni[1] & vxlan_m->hdr.vni[1]) << 8 |
9722 : 0 : (vxlan_v->hdr.vni[2] & vxlan_m->hdr.vni[2]) << 16;
9723 : 0 : tunnel_v |= (vxlan_v->hdr.rsvd1 & vxlan_m->hdr.rsvd1) << 24;
9724 [ # # ]: 0 : MLX5_SET(fte_match_set_misc5, misc5_v, tunnel_header_1, RTE_BE32(tunnel_v));
9725 : : }
9726 : :
9727 : : /**
9728 : : * Add VXLAN-GPE item to the value.
9729 : : *
9730 : : * @param[in, out] key
9731 : : * Flow matcher value.
9732 : : * @param[in] item
9733 : : * Flow pattern to translate.
9734 : : * @param[in] pattern_flags
9735 : : * Item pattern flags.
9736 : : * @param[in] key_type
9737 : : * Set flow matcher mask or value.
9738 : : */
9739 : :
9740 : : static void
9741 : 0 : flow_dv_translate_item_vxlan_gpe(void *key, const struct rte_flow_item *item,
9742 : : const uint64_t pattern_flags,
9743 : : uint32_t key_type)
9744 : : {
9745 : : static const struct rte_flow_item_vxlan_gpe dummy_vxlan_gpe_hdr = {{{0}}};
9746 : 0 : const struct rte_flow_item_vxlan_gpe *vxlan_m = item->mask;
9747 : 0 : const struct rte_flow_item_vxlan_gpe *vxlan_v = item->spec;
9748 : : /* The item was validated to be on the outer side */
9749 : : void *headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9750 : : void *misc_v =
9751 : : MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
9752 : 0 : char *vni_v =
9753 : : MLX5_ADDR_OF(fte_match_set_misc3, misc_v, outer_vxlan_gpe_vni);
9754 : : int i, size = sizeof(vxlan_m->hdr.vni);
9755 : : uint8_t flags_m = 0xff;
9756 : : uint8_t flags_v = 0xc;
9757 : : uint8_t m_protocol, v_protocol;
9758 : :
9759 [ # # # # ]: 0 : if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
9760 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
9761 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
9762 : : 0xFFFF);
9763 : : else
9764 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
9765 : : MLX5_UDP_PORT_VXLAN_GPE);
9766 : : }
9767 [ # # ]: 0 : if (!vxlan_v) {
9768 : : vxlan_v = &dummy_vxlan_gpe_hdr;
9769 : : vxlan_m = &dummy_vxlan_gpe_hdr;
9770 : : } else {
9771 [ # # ]: 0 : if (!vxlan_m)
9772 : : vxlan_m = &rte_flow_item_vxlan_gpe_mask;
9773 : : }
9774 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
9775 : : vxlan_v = vxlan_m;
9776 [ # # ]: 0 : else if (key_type == MLX5_SET_MATCHER_HS_V)
9777 : : vxlan_m = vxlan_v;
9778 [ # # ]: 0 : for (i = 0; i < size; ++i)
9779 : 0 : vni_v[i] = vxlan_m->hdr.vni[i] & vxlan_v->hdr.vni[i];
9780 [ # # ]: 0 : if (vxlan_m->hdr.flags) {
9781 : : flags_m = vxlan_m->hdr.flags;
9782 : 0 : flags_v = vxlan_v->hdr.flags;
9783 : : }
9784 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc_v, outer_vxlan_gpe_flags,
9785 : : flags_m & flags_v);
9786 : 0 : m_protocol = vxlan_m->hdr.protocol;
9787 : 0 : v_protocol = vxlan_v->hdr.protocol;
9788 [ # # ]: 0 : if (!m_protocol) {
9789 : : /* Force next protocol to ensure next headers parsing. */
9790 [ # # ]: 0 : if (pattern_flags & MLX5_FLOW_ITEM_NSH)
9791 : : v_protocol = RTE_VXLAN_GPE_TYPE_NSH;
9792 [ # # ]: 0 : else if (pattern_flags & MLX5_FLOW_LAYER_INNER_L2)
9793 : : v_protocol = RTE_VXLAN_GPE_TYPE_ETH;
9794 [ # # ]: 0 : else if (pattern_flags & MLX5_FLOW_LAYER_INNER_L3_IPV4)
9795 : : v_protocol = RTE_VXLAN_GPE_TYPE_IPV4;
9796 [ # # ]: 0 : else if (pattern_flags & MLX5_FLOW_LAYER_INNER_L3_IPV6)
9797 : : v_protocol = RTE_VXLAN_GPE_TYPE_IPV6;
9798 [ # # ]: 0 : if (v_protocol)
9799 : : m_protocol = 0xFF;
9800 : : /* Restore the value to mask in mask case. */
9801 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
9802 : : v_protocol = m_protocol;
9803 : : }
9804 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc_v,
9805 : : outer_vxlan_gpe_next_protocol, m_protocol & v_protocol);
9806 : 0 : }
9807 : :
9808 : : /**
9809 : : * Add Geneve item to the value.
9810 : : *
9811 : : * @param[in, out] key
9812 : : * Flow matcher value.
9813 : : * @param[in] item
9814 : : * Flow pattern to translate.
9815 : : * @param[in] pattern_flags
9816 : : * Item pattern flags.
9817 : : * @param[in] key_type
9818 : : * Set flow matcher mask or value.
9819 : : */
9820 : :
9821 : : static void
9822 : 0 : flow_dv_translate_item_geneve(void *key, const struct rte_flow_item *item,
9823 : : uint64_t pattern_flags, uint32_t key_type)
9824 : : {
9825 : : static const struct rte_flow_item_geneve empty_geneve = {0,};
9826 : 0 : const struct rte_flow_item_geneve *geneve_m = item->mask;
9827 : 0 : const struct rte_flow_item_geneve *geneve_v = item->spec;
9828 : : /* GENEVE flow item validation allows single tunnel item */
9829 : : void *headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9830 : : void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
9831 : : uint16_t gbhdr_m;
9832 : : uint16_t gbhdr_v;
9833 : 0 : char *vni_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, geneve_vni);
9834 : : size_t size = sizeof(geneve_m->vni), i;
9835 : : uint16_t protocol_m, protocol_v;
9836 : :
9837 [ # # # # ]: 0 : if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
9838 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
9839 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
9840 : : 0xFFFF);
9841 : : else
9842 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
9843 : : MLX5_UDP_PORT_GENEVE);
9844 : : }
9845 [ # # ]: 0 : if (!geneve_v) {
9846 : : geneve_v = &empty_geneve;
9847 : : geneve_m = &empty_geneve;
9848 : : } else {
9849 [ # # ]: 0 : if (!geneve_m)
9850 : : geneve_m = &rte_flow_item_geneve_mask;
9851 : : }
9852 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
9853 : : geneve_v = geneve_m;
9854 [ # # ]: 0 : else if (key_type == MLX5_SET_MATCHER_HS_V)
9855 : : geneve_m = geneve_v;
9856 [ # # ]: 0 : for (i = 0; i < size; ++i)
9857 : 0 : vni_v[i] = geneve_m->vni[i] & geneve_v->vni[i];
9858 [ # # ]: 0 : gbhdr_m = rte_be_to_cpu_16(geneve_m->ver_opt_len_o_c_rsvd0);
9859 [ # # ]: 0 : gbhdr_v = rte_be_to_cpu_16(geneve_v->ver_opt_len_o_c_rsvd0);
9860 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, geneve_oam,
9861 : : MLX5_GENEVE_OAMF_VAL(gbhdr_v) & MLX5_GENEVE_OAMF_VAL(gbhdr_m));
9862 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, geneve_opt_len,
9863 : : MLX5_GENEVE_OPTLEN_VAL(gbhdr_v) &
9864 : : MLX5_GENEVE_OPTLEN_VAL(gbhdr_m));
9865 [ # # ]: 0 : protocol_m = rte_be_to_cpu_16(geneve_m->protocol);
9866 [ # # ]: 0 : protocol_v = rte_be_to_cpu_16(geneve_v->protocol);
9867 [ # # ]: 0 : if (!protocol_m) {
9868 : : /* Force next protocol to prevent matchers duplication */
9869 : : protocol_v = mlx5_translate_tunnel_etypes(pattern_flags);
9870 : : if (protocol_v)
9871 : : protocol_m = 0xFFFF;
9872 : : /* Restore the value to mask in mask case. */
9873 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
9874 : : protocol_v = protocol_m;
9875 : : }
9876 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, geneve_protocol_type,
9877 : : protocol_m & protocol_v);
9878 : 0 : }
9879 : :
9880 : : /**
9881 : : * Create Geneve TLV option resource.
9882 : : *
9883 : : * @param dev[in, out]
9884 : : * Pointer to rte_eth_dev structure.
9885 : : * @param[in] item
9886 : : * Flow pattern to translate.
9887 : : * @param[out] error
9888 : : * pointer to error structure.
9889 : : *
9890 : : * @return
9891 : : * 0 on success otherwise -errno and errno is set.
9892 : : */
9893 : :
9894 : : int
9895 : 0 : flow_dev_geneve_tlv_option_resource_register(struct rte_eth_dev *dev,
9896 : : const struct rte_flow_item *item,
9897 : : struct rte_flow_error *error)
9898 : : {
9899 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
9900 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
9901 : 0 : struct mlx5_geneve_tlv_option_resource *geneve_opt_resource =
9902 : : sh->geneve_tlv_option_resource;
9903 : : struct mlx5_devx_obj *obj;
9904 : 0 : const struct rte_flow_item_geneve_opt *geneve_opt_v = item->spec;
9905 : : int ret = 0;
9906 : :
9907 [ # # ]: 0 : if (!geneve_opt_v)
9908 : : return -1;
9909 : 0 : rte_spinlock_lock(&sh->geneve_tlv_opt_sl);
9910 [ # # ]: 0 : if (geneve_opt_resource != NULL) {
9911 : 0 : if (geneve_opt_resource->option_class ==
9912 : : geneve_opt_v->option_class &&
9913 : : geneve_opt_resource->option_type ==
9914 [ # # ]: 0 : geneve_opt_v->option_type &&
9915 : : geneve_opt_resource->length ==
9916 : : geneve_opt_v->option_len) {
9917 : : /*
9918 : : * We already have GENEVE TLV option obj allocated.
9919 : : * Increasing refcnt only in SWS. HWS uses it as global.
9920 : : */
9921 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 1)
9922 : 0 : __atomic_fetch_add(&geneve_opt_resource->refcnt, 1,
9923 : : __ATOMIC_RELAXED);
9924 : : } else {
9925 : 0 : ret = rte_flow_error_set(error, ENOMEM,
9926 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
9927 : : "Only one GENEVE TLV option supported");
9928 : 0 : goto exit;
9929 : : }
9930 : : } else {
9931 : : /* Create a GENEVE TLV object and resource. */
9932 : 0 : obj = mlx5_devx_cmd_create_geneve_tlv_option(sh->cdev->ctx,
9933 : 0 : geneve_opt_v->option_class,
9934 : 0 : geneve_opt_v->option_type,
9935 : 0 : geneve_opt_v->option_len);
9936 [ # # ]: 0 : if (!obj) {
9937 : 0 : ret = rte_flow_error_set(error, ENODATA,
9938 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
9939 : : "Failed to create GENEVE TLV Devx object");
9940 : 0 : goto exit;
9941 : : }
9942 : 0 : sh->geneve_tlv_option_resource =
9943 : 0 : mlx5_malloc(MLX5_MEM_ZERO,
9944 : : sizeof(*geneve_opt_resource),
9945 : : 0, SOCKET_ID_ANY);
9946 [ # # ]: 0 : if (!sh->geneve_tlv_option_resource) {
9947 : 0 : claim_zero(mlx5_devx_cmd_destroy(obj));
9948 : 0 : ret = rte_flow_error_set(error, ENOMEM,
9949 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
9950 : : "GENEVE TLV object memory allocation failed");
9951 : 0 : goto exit;
9952 : : }
9953 : : geneve_opt_resource = sh->geneve_tlv_option_resource;
9954 : 0 : geneve_opt_resource->obj = obj;
9955 : 0 : geneve_opt_resource->option_class = geneve_opt_v->option_class;
9956 : 0 : geneve_opt_resource->option_type = geneve_opt_v->option_type;
9957 : 0 : geneve_opt_resource->length = geneve_opt_v->option_len;
9958 : 0 : __atomic_store_n(&geneve_opt_resource->refcnt, 1,
9959 : : __ATOMIC_RELAXED);
9960 : : }
9961 : 0 : exit:
9962 : : rte_spinlock_unlock(&sh->geneve_tlv_opt_sl);
9963 : 0 : return ret;
9964 : : }
9965 : :
9966 : : /**
9967 : : * Add Geneve TLV option item to value.
9968 : : *
9969 : : * @param[in, out] dev
9970 : : * Pointer to rte_eth_dev structure.
9971 : : * @param[in, out] key
9972 : : * Flow matcher value.
9973 : : * @param[in] item
9974 : : * Flow pattern to translate.
9975 : : * @param[in] key_type
9976 : : * Set flow matcher mask or value.
9977 : : * @param[out] error
9978 : : * Pointer to error structure.
9979 : : */
9980 : : static int
9981 : 0 : flow_dv_translate_item_geneve_opt(struct rte_eth_dev *dev, void *key,
9982 : : const struct rte_flow_item *item,
9983 : : uint32_t key_type,
9984 : : struct rte_flow_error *error)
9985 : : {
9986 : : const struct rte_flow_item_geneve_opt *geneve_opt_m;
9987 : : const struct rte_flow_item_geneve_opt *geneve_opt_v;
9988 : 0 : const struct rte_flow_item_geneve_opt *geneve_opt_vv = item->spec;
9989 : : void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
9990 : : void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
9991 : 0 : rte_be32_t opt_data_key = 0, opt_data_mask = 0;
9992 : : uint32_t *data;
9993 : : int ret = 0;
9994 : :
9995 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9996 : : return -1;
9997 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, geneve_opt_v, geneve_opt_m,
# # # # ]
9998 : : &rte_flow_item_geneve_opt_mask);
9999 : : /* Register resource requires item spec. */
10000 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_V) {
10001 : 0 : ret = flow_dev_geneve_tlv_option_resource_register(dev, item,
10002 : : error);
10003 [ # # ]: 0 : if (ret) {
10004 : 0 : DRV_LOG(ERR, "Failed to create geneve_tlv_obj");
10005 : 0 : return ret;
10006 : : }
10007 : : }
10008 : : /*
10009 : : * Set the option length in GENEVE header if not requested.
10010 : : * The GENEVE TLV option length is expressed by the option length field
10011 : : * in the GENEVE header.
10012 : : * If the option length was not requested but the GENEVE TLV option item
10013 : : * is present we set the option length field implicitly.
10014 : : */
10015 [ # # # # ]: 0 : if (!MLX5_GET16(fte_match_set_misc, misc_v, geneve_opt_len)) {
10016 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10017 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, geneve_opt_len,
10018 : : MLX5_GENEVE_OPTLEN_MASK);
10019 : : else
10020 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, geneve_opt_len,
10021 : : geneve_opt_v->option_len + 1);
10022 : : }
10023 : : /* Set the data. */
10024 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_SW_V)
10025 : 0 : data = geneve_opt_vv->data;
10026 : : else
10027 : 0 : data = geneve_opt_v->data;
10028 [ # # ]: 0 : if (data) {
10029 : : memcpy(&opt_data_key, data,
10030 [ # # ]: 0 : RTE_MIN((uint32_t)(geneve_opt_v->option_len * 4),
10031 : : sizeof(opt_data_key)));
10032 : 0 : memcpy(&opt_data_mask, geneve_opt_m->data,
10033 : : RTE_MIN((uint32_t)(geneve_opt_v->option_len * 4),
10034 : : sizeof(opt_data_mask)));
10035 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v,
10036 : : geneve_tlv_option_0_data,
10037 : : rte_be_to_cpu_32(opt_data_key & opt_data_mask));
10038 : : }
10039 : : return ret;
10040 : : }
10041 : :
10042 : : /**
10043 : : * Add MPLS item to the value.
10044 : : *
10045 : : * @param[in, out] key
10046 : : * Flow matcher value.
10047 : : * @param[in] item
10048 : : * Flow pattern to translate.
10049 : : * @param[in] prev_layer
10050 : : * The protocol layer indicated in previous item.
10051 : : * @param[in] inner
10052 : : * Item is inner pattern.
10053 : : * @param[in] key_type
10054 : : * Set flow matcher mask or value.
10055 : : */
10056 : : static void
10057 : 0 : flow_dv_translate_item_mpls(void *key, const struct rte_flow_item *item,
10058 : : uint64_t prev_layer, int inner,
10059 : : uint32_t key_type)
10060 : : {
10061 : : const uint32_t *in_mpls_m;
10062 : : const uint32_t *in_mpls_v;
10063 : : uint32_t *out_mpls_v = 0;
10064 : : void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
10065 : 0 : void *misc2_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_2);
10066 : : void *headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
10067 : :
10068 [ # # # ]: 0 : switch (prev_layer) {
10069 : 0 : case MLX5_FLOW_LAYER_OUTER_L4_UDP:
10070 [ # # # # ]: 0 : if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
10071 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10072 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
10073 : : udp_dport, 0xffff);
10074 : : else
10075 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
10076 : : udp_dport, MLX5_UDP_PORT_MPLS);
10077 : : }
10078 : : break;
10079 : 0 : case MLX5_FLOW_LAYER_GRE:
10080 : : /* Fall-through. */
10081 : : case MLX5_FLOW_LAYER_GRE_KEY:
10082 [ # # # # ]: 0 : if (!MLX5_GET16(fte_match_set_misc, misc_v, gre_protocol)) {
10083 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10084 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v,
10085 : : gre_protocol, 0xffff);
10086 : : else
10087 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v,
10088 : : gre_protocol, RTE_ETHER_TYPE_MPLS);
10089 : : }
10090 : : break;
10091 : : default:
10092 : : break;
10093 : : }
10094 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
10095 : : return;
10096 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, in_mpls_v, in_mpls_m,
# # # # ]
10097 : : &rte_flow_item_mpls_mask);
10098 [ # # # ]: 0 : switch (prev_layer) {
10099 : 0 : case MLX5_FLOW_LAYER_OUTER_L4_UDP:
10100 : 0 : out_mpls_v =
10101 : : (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_v,
10102 : : outer_first_mpls_over_udp);
10103 : 0 : break;
10104 : 0 : case MLX5_FLOW_LAYER_GRE:
10105 : 0 : out_mpls_v =
10106 : : (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_v,
10107 : : outer_first_mpls_over_gre);
10108 : 0 : break;
10109 : 0 : default:
10110 : : /* Inner MPLS not over GRE is not supported. */
10111 [ # # ]: 0 : if (!inner)
10112 : : out_mpls_v =
10113 : : (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2,
10114 : : misc2_v,
10115 : : outer_first_mpls);
10116 : : break;
10117 : : }
10118 : : if (out_mpls_v)
10119 : 0 : *out_mpls_v = *in_mpls_v & *in_mpls_m;
10120 : : }
10121 : :
10122 : : /**
10123 : : * Add metadata register item to matcher
10124 : : *
10125 : : * @param[in, out] key
10126 : : * Flow matcher value.
10127 : : * @param[in] reg_type
10128 : : * Type of device metadata register
10129 : : * @param[in] data
10130 : : * Register data
10131 : : * @param[in] mask
10132 : : * Register mask
10133 : : */
10134 : : static void
10135 : 0 : flow_dv_match_meta_reg(void *key, enum modify_reg reg_type,
10136 : : uint32_t data, uint32_t mask)
10137 : : {
10138 : : void *misc2_v =
10139 : : MLX5_ADDR_OF(fte_match_param, key, misc_parameters_2);
10140 : : uint32_t temp;
10141 : :
10142 : 0 : data &= mask;
10143 [ # # # # : 0 : switch (reg_type) {
# # # # #
# # ]
10144 : 0 : case REG_A:
10145 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_a, data);
10146 : 0 : break;
10147 : 0 : case REG_B:
10148 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_b, data);
10149 : 0 : break;
10150 : 0 : case REG_C_0:
10151 : : /*
10152 : : * The metadata register C0 field might be divided into
10153 : : * source vport index and META item value, we should set
10154 : : * this field according to specified mask, not as whole one.
10155 : : */
10156 [ # # ]: 0 : temp = MLX5_GET(fte_match_set_misc2, misc2_v, metadata_reg_c_0);
10157 [ # # # # ]: 0 : if (mask)
10158 : 0 : temp &= ~mask;
10159 : 0 : temp |= data;
10160 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_0, temp);
10161 : 0 : break;
10162 : 0 : case REG_C_1:
10163 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_1, data);
10164 : 0 : break;
10165 : 0 : case REG_C_2:
10166 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_2, data);
10167 : 0 : break;
10168 : 0 : case REG_C_3:
10169 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_3, data);
10170 : 0 : break;
10171 : 0 : case REG_C_4:
10172 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_4, data);
10173 : 0 : break;
10174 : 0 : case REG_C_5:
10175 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_5, data);
10176 : 0 : break;
10177 : 0 : case REG_C_6:
10178 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_6, data);
10179 : 0 : break;
10180 : 0 : case REG_C_7:
10181 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_7, data);
10182 : 0 : break;
10183 : : default:
10184 : : MLX5_ASSERT(false);
10185 : : break;
10186 : : }
10187 : 0 : }
10188 : :
10189 : : /**
10190 : : * Add metadata register item to matcher
10191 : : *
10192 : : * @param[in, out] matcher
10193 : : * Flow matcher.
10194 : : * @param[in, out] key
10195 : : * Flow matcher value.
10196 : : * @param[in] reg_type
10197 : : * Type of device metadata register
10198 : : * @param[in] value
10199 : : * Register value
10200 : : * @param[in] mask
10201 : : * Register mask
10202 : : */
10203 : : static void
10204 : : flow_dv_match_meta_reg_all(void *matcher, void *key, enum modify_reg reg_type,
10205 : : uint32_t data, uint32_t mask)
10206 : : {
10207 : 0 : flow_dv_match_meta_reg(key, reg_type, data, mask);
10208 : 0 : flow_dv_match_meta_reg(matcher, reg_type, mask, mask);
10209 : : }
10210 : :
10211 : : /**
10212 : : * Add MARK item to matcher
10213 : : *
10214 : : * @param[in] dev
10215 : : * The device to configure through.
10216 : : * @param[in, out] key
10217 : : * Flow matcher value.
10218 : : * @param[in] item
10219 : : * Flow pattern to translate.
10220 : : * @param[in] key_type
10221 : : * Set flow matcher mask or value.
10222 : : */
10223 : : static void
10224 : 0 : flow_dv_translate_item_mark(struct rte_eth_dev *dev, void *key,
10225 : : const struct rte_flow_item *item,
10226 : : uint32_t key_type)
10227 : : {
10228 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10229 : : const struct rte_flow_item_mark *mark;
10230 : : uint32_t value;
10231 : : uint32_t mask = 0;
10232 : :
10233 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_SW) {
10234 [ # # ]: 0 : mark = item->mask ? (const void *)item->mask :
10235 : : &rte_flow_item_mark_mask;
10236 : 0 : mask = mark->id;
10237 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_SW_M) {
10238 : : value = mask;
10239 : : } else {
10240 : 0 : mark = (const void *)item->spec;
10241 : : MLX5_ASSERT(mark);
10242 : 0 : value = mark->id;
10243 : : }
10244 : : } else {
10245 [ # # ]: 0 : mark = (key_type == MLX5_SET_MATCHER_HS_V) ?
10246 : : (const void *)item->spec : (const void *)item->mask;
10247 : : MLX5_ASSERT(mark);
10248 : 0 : value = mark->id;
10249 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_HS_M)
10250 : : mask = value;
10251 : : }
10252 : 0 : mask &= priv->sh->dv_mark_mask;
10253 : 0 : value &= mask;
10254 [ # # ]: 0 : if (mask) {
10255 : : enum modify_reg reg;
10256 : :
10257 : : /* Get the metadata register index for the mark. */
10258 : 0 : reg = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, NULL);
10259 : : MLX5_ASSERT(reg > 0);
10260 [ # # ]: 0 : if (reg == REG_C_0) {
10261 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10262 : 0 : uint32_t msk_c0 = priv->sh->dv_regc0_mask;
10263 : : uint32_t shl_c0 = rte_bsf32(msk_c0);
10264 : :
10265 : 0 : mask &= msk_c0;
10266 : 0 : mask <<= shl_c0;
10267 : 0 : value <<= shl_c0;
10268 : : }
10269 : 0 : flow_dv_match_meta_reg(key, reg, value, mask);
10270 : : }
10271 : 0 : }
10272 : :
10273 : : /**
10274 : : * Add META item to matcher
10275 : : *
10276 : : * @param[in] dev
10277 : : * The devich to configure through.
10278 : : * @param[in, out] key
10279 : : * Flow matcher value.
10280 : : * @param[in] attr
10281 : : * Attributes of flow that includes this item.
10282 : : * @param[in] item
10283 : : * Flow pattern to translate.
10284 : : * @param[in] key_type
10285 : : * Set flow matcher mask or value.
10286 : : */
10287 : : static void
10288 : 0 : flow_dv_translate_item_meta(struct rte_eth_dev *dev,
10289 : : void *key,
10290 : : const struct rte_flow_attr *attr,
10291 : : const struct rte_flow_item *item,
10292 : : uint32_t key_type)
10293 : : {
10294 : : const struct rte_flow_item_meta *meta_m;
10295 : : const struct rte_flow_item_meta *meta_v;
10296 : : uint32_t value;
10297 : : uint32_t mask = 0;
10298 : : int reg;
10299 : :
10300 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
10301 : : return;
10302 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, meta_v, meta_m,
# # # # ]
10303 : : &rte_flow_item_meta_mask);
10304 : 0 : value = meta_v->data;
10305 : 0 : mask = meta_m->data;
10306 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_HS_M)
10307 : : mask = value;
10308 : : /*
10309 : : * In the current implementation, REG_B cannot be used to match.
10310 : : * Force to use REG_C_1 in HWS root table as other tables.
10311 : : * This map may change.
10312 : : * NIC: modify - REG_B to be present in SW
10313 : : * match - REG_C_1 when copied from FDB, different from SWS
10314 : : * FDB: modify - REG_C_1 in Xmeta mode, REG_NON in legacy mode
10315 : : * match - REG_C_1 in FDB
10316 : : */
10317 [ # # ]: 0 : if (!!(key_type & MLX5_SET_MATCHER_SW))
10318 : 0 : reg = flow_dv_get_metadata_reg(dev, attr, NULL);
10319 : : else
10320 : : reg = flow_hw_get_reg_id(dev, RTE_FLOW_ITEM_TYPE_META, 0);
10321 [ # # ]: 0 : if (reg < 0)
10322 : : return;
10323 : : MLX5_ASSERT(reg != REG_NON);
10324 [ # # ]: 0 : if (reg == REG_C_0) {
10325 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10326 : 0 : uint32_t msk_c0 = priv->sh->dv_regc0_mask;
10327 : : uint32_t shl_c0 = rte_bsf32(msk_c0);
10328 : :
10329 : 0 : mask &= msk_c0;
10330 : 0 : mask <<= shl_c0;
10331 : 0 : value <<= shl_c0;
10332 : : }
10333 : 0 : flow_dv_match_meta_reg(key, reg, value, mask);
10334 : : }
10335 : :
10336 : : /**
10337 : : * Add vport metadata Reg C0 item to matcher
10338 : : *
10339 : : * @param[in, out] key
10340 : : * Flow matcher value.
10341 : : * @param[in] value
10342 : : * Register value
10343 : : * @param[in] mask
10344 : : * Register mask
10345 : : */
10346 : : static void
10347 [ # # ]: 0 : flow_dv_translate_item_meta_vport(void *key, uint32_t value, uint32_t mask)
10348 : : {
10349 : : flow_dv_match_meta_reg(key, REG_C_0, value, mask);
10350 : 0 : }
10351 : :
10352 : : /**
10353 : : * Add tag item to matcher
10354 : : *
10355 : : * @param[in] dev
10356 : : * The devich to configure through.
10357 : : * @param[in, out] key
10358 : : * Flow matcher value.
10359 : : * @param[in] item
10360 : : * Flow pattern to translate.
10361 : : * @param[in] key_type
10362 : : * Set flow matcher mask or value.
10363 : : */
10364 : : static void
10365 : 0 : flow_dv_translate_mlx5_item_tag(struct rte_eth_dev *dev, void *key,
10366 : : const struct rte_flow_item *item,
10367 : : uint32_t key_type)
10368 : : {
10369 : 0 : const struct mlx5_rte_flow_item_tag *tag_v = item->spec;
10370 : 0 : const struct mlx5_rte_flow_item_tag *tag_m = item->mask;
10371 : : uint32_t mask, value;
10372 : :
10373 : : MLX5_ASSERT(tag_v);
10374 : 0 : value = tag_v->data;
10375 [ # # ]: 0 : mask = tag_m ? tag_m->data : UINT32_MAX;
10376 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10377 : : value = mask;
10378 [ # # ]: 0 : if (tag_v->id == REG_C_0) {
10379 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10380 : 0 : uint32_t msk_c0 = priv->sh->dv_regc0_mask;
10381 : : uint32_t shl_c0 = rte_bsf32(msk_c0);
10382 : :
10383 : 0 : mask &= msk_c0;
10384 : 0 : mask <<= shl_c0;
10385 : 0 : value <<= shl_c0;
10386 : : }
10387 : 0 : flow_dv_match_meta_reg(key, tag_v->id, value, mask);
10388 : 0 : }
10389 : :
10390 : : /**
10391 : : * Add TAG item to matcher
10392 : : *
10393 : : * @param[in] dev
10394 : : * The devich to configure through.
10395 : : * @param[in, out] key
10396 : : * Flow matcher value.
10397 : : * @param[in] item
10398 : : * Flow pattern to translate.
10399 : : * @param[in] key_type
10400 : : * Set flow matcher mask or value.
10401 : : */
10402 : : static void
10403 : 0 : flow_dv_translate_item_tag(struct rte_eth_dev *dev, void *key,
10404 : : const struct rte_flow_item *item,
10405 : : uint32_t key_type)
10406 : : {
10407 : 0 : const struct rte_flow_item_tag *tag_vv = item->spec;
10408 : : const struct rte_flow_item_tag *tag_v;
10409 : : const struct rte_flow_item_tag *tag_m;
10410 : : int reg;
10411 : : uint32_t index;
10412 : :
10413 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
10414 : : return;
10415 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, tag_v, tag_m,
# # # # ]
10416 : : &rte_flow_item_tag_mask);
10417 : : /* When set mask, the index should be from spec. */
10418 [ # # ]: 0 : index = tag_vv ? tag_vv->index : tag_v->index;
10419 : : /* Get the metadata register index for the tag. */
10420 [ # # ]: 0 : if (!!(key_type & MLX5_SET_MATCHER_SW))
10421 : 0 : reg = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, index, NULL);
10422 : : else
10423 : : reg = flow_hw_get_reg_id(dev, RTE_FLOW_ITEM_TYPE_TAG, index);
10424 : : MLX5_ASSERT(reg > 0);
10425 : 0 : flow_dv_match_meta_reg(key, (enum modify_reg)reg, tag_v->data, tag_m->data);
10426 : : }
10427 : :
10428 : : /**
10429 : : * Add source vport match to the specified matcher.
10430 : : *
10431 : : * @param[in, out] key
10432 : : * Flow matcher value.
10433 : : * @param[in] port
10434 : : * Source vport value to match
10435 : : */
10436 : : static void
10437 : : flow_dv_translate_item_source_vport(void *key,
10438 : : int16_t port)
10439 : : {
10440 : : void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
10441 : :
10442 [ # # # # : 0 : MLX5_SET(fte_match_set_misc, misc_v, source_port, port);
# # ]
10443 : 0 : }
10444 : :
10445 : : /**
10446 : : * Translate port-id item to eswitch match on port-id.
10447 : : *
10448 : : * @param[in] dev
10449 : : * The devich to configure through.
10450 : : * @param[in, out] key
10451 : : * Flow matcher value.
10452 : : * @param[in] item
10453 : : * Flow pattern to translate.
10454 : : * @param[in] attr
10455 : : * Flow attributes.
10456 : : * @param[in] key_type
10457 : : * Set flow matcher mask or value.
10458 : : *
10459 : : * @return
10460 : : * 0 on success, a negative errno value otherwise.
10461 : : */
10462 : : static int
10463 : 0 : flow_dv_translate_item_port_id(struct rte_eth_dev *dev, void *key,
10464 : : const struct rte_flow_item *item,
10465 : : const struct rte_flow_attr *attr,
10466 : : uint32_t key_type)
10467 : : {
10468 [ # # ]: 0 : const struct rte_flow_item_port_id *pid_m = item ? item->mask : NULL;
10469 [ # # ]: 0 : const struct rte_flow_item_port_id *pid_v = item ? item->spec : NULL;
10470 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
10471 : : struct mlx5_priv *priv;
10472 : : uint16_t mask, id;
10473 : : uint32_t vport_meta;
10474 : :
10475 : : MLX5_ASSERT(wks);
10476 [ # # # # ]: 0 : if (pid_v && pid_v->id == MLX5_PORT_ESW_MGR) {
10477 : 0 : flow_dv_translate_item_source_vport(key,
10478 [ # # ]: 0 : key_type & MLX5_SET_MATCHER_V ?
10479 : 0 : mlx5_flow_get_esw_manager_vport_id(dev) : 0xffff);
10480 : 0 : return 0;
10481 : : }
10482 [ # # ]: 0 : mask = pid_m ? pid_m->id : 0xffff;
10483 [ # # ]: 0 : id = pid_v ? pid_v->id : dev->data->port_id;
10484 : 0 : priv = mlx5_port_to_eswitch_info(id, item == NULL);
10485 [ # # ]: 0 : if (!priv)
10486 : 0 : return -rte_errno;
10487 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M) {
10488 : : id = mask;
10489 : 0 : vport_meta = priv->vport_meta_mask;
10490 : : } else {
10491 : 0 : id = priv->vport_id;
10492 : 0 : vport_meta = priv->vport_meta_tag;
10493 : 0 : wks->vport_meta_tag = vport_meta;
10494 : : }
10495 : : /*
10496 : : * Translate to vport field or to metadata, depending on mode.
10497 : : * Kernel can use either misc.source_port or half of C0 metadata
10498 : : * register.
10499 : : */
10500 [ # # ]: 0 : if (priv->vport_meta_mask) {
10501 : : /*
10502 : : * Provide the hint for SW steering library
10503 : : * to insert the flow into ingress domain and
10504 : : * save the extra vport match.
10505 : : */
10506 [ # # # # ]: 0 : if (mask == 0xffff && priv->vport_id == 0xffff &&
10507 [ # # # # ]: 0 : priv->pf_bond < 0 && attr->transfer)
10508 [ # # ]: 0 : flow_dv_translate_item_source_vport(key, id);
10509 : : /*
10510 : : * We should always set the vport metadata register,
10511 : : * otherwise the SW steering library can drop
10512 : : * the rule if wire vport metadata value is not zero,
10513 : : * it depends on kernel configuration.
10514 : : */
10515 : 0 : flow_dv_translate_item_meta_vport
10516 : : (key, vport_meta, priv->vport_meta_mask);
10517 : : } else {
10518 [ # # ]: 0 : flow_dv_translate_item_source_vport(key, id);
10519 : : }
10520 : : return 0;
10521 : : }
10522 : :
10523 : : /**
10524 : : * Translate port representor item to eswitch match on port id.
10525 : : *
10526 : : * @param[in] dev
10527 : : * The devich to configure through.
10528 : : * @param[in, out] key
10529 : : * Flow matcher value.
10530 : : * @param[in] key_type
10531 : : * Set flow matcher mask or value.
10532 : : *
10533 : : * @return
10534 : : * 0 on success, a negative errno value otherwise.
10535 : : */
10536 : : static int
10537 : 0 : flow_dv_translate_item_port_representor(struct rte_eth_dev *dev, void *key,
10538 : : uint32_t key_type)
10539 : : {
10540 : 0 : flow_dv_translate_item_source_vport(key,
10541 [ # # ]: 0 : key_type & MLX5_SET_MATCHER_V ?
10542 : 0 : mlx5_flow_get_esw_manager_vport_id(dev) : 0xffff);
10543 : 0 : return 0;
10544 : : }
10545 : :
10546 : : /**
10547 : : * Translate represented port item to eswitch match on port id.
10548 : : *
10549 : : * @param[in] dev
10550 : : * The devich to configure through.
10551 : : * @param[in, out] key
10552 : : * Flow matcher value.
10553 : : * @param[in] item
10554 : : * Flow pattern to translate.
10555 : : * @param[in]
10556 : : * Flow attributes.
10557 : : *
10558 : : * @return
10559 : : * 0 on success, a negative errno value otherwise.
10560 : : */
10561 : : static int
10562 : 0 : flow_dv_translate_item_represented_port(struct rte_eth_dev *dev, void *key,
10563 : : const struct rte_flow_item *item,
10564 : : const struct rte_flow_attr *attr,
10565 : : uint32_t key_type)
10566 : : {
10567 [ # # ]: 0 : const struct rte_flow_item_ethdev *pid_m = item ? item->mask : NULL;
10568 [ # # ]: 0 : const struct rte_flow_item_ethdev *pid_v = item ? item->spec : NULL;
10569 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
10570 : : struct mlx5_priv *priv;
10571 : : uint16_t mask, id;
10572 : : uint32_t vport_meta;
10573 : :
10574 : : MLX5_ASSERT(wks);
10575 [ # # ]: 0 : if (!pid_m && !pid_v)
10576 : : return 0;
10577 [ # # # # ]: 0 : if (pid_v && pid_v->port_id == UINT16_MAX) {
10578 : 0 : flow_dv_translate_item_source_vport(key,
10579 [ # # ]: 0 : key_type & MLX5_SET_MATCHER_V ?
10580 : 0 : mlx5_flow_get_esw_manager_vport_id(dev) : 0xffff);
10581 : 0 : return 0;
10582 : : }
10583 [ # # ]: 0 : mask = pid_m ? pid_m->port_id : UINT16_MAX;
10584 [ # # ]: 0 : id = pid_v ? pid_v->port_id : dev->data->port_id;
10585 : 0 : priv = mlx5_port_to_eswitch_info(id, item == NULL);
10586 [ # # ]: 0 : if (!priv)
10587 : 0 : return -rte_errno;
10588 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M) {
10589 : : id = mask;
10590 : 0 : vport_meta = priv->vport_meta_mask;
10591 : : } else {
10592 : 0 : id = priv->vport_id;
10593 : 0 : vport_meta = priv->vport_meta_tag;
10594 : 0 : wks->vport_meta_tag = vport_meta;
10595 : : }
10596 : : /*
10597 : : * Translate to vport field or to metadata, depending on mode.
10598 : : * Kernel can use either misc.source_port or half of C0 metadata
10599 : : * register.
10600 : : */
10601 [ # # ]: 0 : if (priv->vport_meta_mask) {
10602 : : /*
10603 : : * Provide the hint for SW steering library
10604 : : * to insert the flow into ingress domain and
10605 : : * save the extra vport match.
10606 : : */
10607 [ # # # # ]: 0 : if (mask == UINT16_MAX && priv->vport_id == UINT16_MAX &&
10608 [ # # # # ]: 0 : priv->pf_bond < 0 && attr->transfer &&
10609 [ # # ]: 0 : priv->sh->config.dv_flow_en != 2)
10610 [ # # ]: 0 : flow_dv_translate_item_source_vport(key, id);
10611 : : /*
10612 : : * We should always set the vport metadata register,
10613 : : * otherwise the SW steering library can drop
10614 : : * the rule if wire vport metadata value is not zero,
10615 : : * it depends on kernel configuration.
10616 : : */
10617 : 0 : flow_dv_translate_item_meta_vport(key, vport_meta,
10618 : : priv->vport_meta_mask);
10619 : : } else {
10620 [ # # ]: 0 : flow_dv_translate_item_source_vport(key, id);
10621 : : }
10622 : : return 0;
10623 : : }
10624 : :
10625 : : /**
10626 : : * Translate port-id item to eswitch match on port-id.
10627 : : *
10628 : : * @param[in] dev
10629 : : * The devich to configure through.
10630 : : * @param[in, out] matcher
10631 : : * Flow matcher.
10632 : : * @param[in, out] key
10633 : : * Flow matcher value.
10634 : : * @param[in] item
10635 : : * Flow pattern to translate.
10636 : : * @param[in] attr
10637 : : * Flow attributes.
10638 : : *
10639 : : * @return
10640 : : * 0 on success, a negative errno value otherwise.
10641 : : */
10642 : : static int
10643 : 0 : flow_dv_translate_item_port_id_all(struct rte_eth_dev *dev,
10644 : : void *matcher, void *key,
10645 : : const struct rte_flow_item *item,
10646 : : const struct rte_flow_attr *attr)
10647 : : {
10648 : : int ret;
10649 : :
10650 : 0 : ret = flow_dv_translate_item_port_id
10651 : : (dev, matcher, item, attr, MLX5_SET_MATCHER_SW_M);
10652 [ # # ]: 0 : if (ret)
10653 : : return ret;
10654 : 0 : ret = flow_dv_translate_item_port_id
10655 : : (dev, key, item, attr, MLX5_SET_MATCHER_SW_V);
10656 : 0 : return ret;
10657 : : }
10658 : :
10659 : :
10660 : : /**
10661 : : * Add ICMP6 item to the value.
10662 : : *
10663 : : * @param[in, out] key
10664 : : * Flow matcher value.
10665 : : * @param[in] item
10666 : : * Flow pattern to translate.
10667 : : * @param[in] inner
10668 : : * Item is inner pattern.
10669 : : * @param[in] key_type
10670 : : * Set flow matcher mask or value.
10671 : : */
10672 : : static void
10673 : 0 : flow_dv_translate_item_icmp6(void *key, const struct rte_flow_item *item,
10674 : : int inner, uint32_t key_type)
10675 : : {
10676 : : const struct rte_flow_item_icmp6 *icmp6_m;
10677 : : const struct rte_flow_item_icmp6 *icmp6_v;
10678 : : void *headers_v;
10679 : : void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
10680 : :
10681 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
10682 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
10683 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10684 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, 0xFF);
10685 : : else
10686 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
10687 : : IPPROTO_ICMPV6);
10688 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
10689 : : return;
10690 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, icmp6_v, icmp6_m,
# # # # ]
10691 : : &rte_flow_item_icmp6_mask);
10692 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_type,
10693 : : icmp6_v->type & icmp6_m->type);
10694 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_code,
10695 : : icmp6_v->code & icmp6_m->code);
10696 : : }
10697 : :
10698 : : /**
10699 : : * Add ICMP6 echo request/reply item to the value.
10700 : : *
10701 : : * @param[in, out] key
10702 : : * Flow matcher value.
10703 : : * @param[in] item
10704 : : * Flow pattern to translate.
10705 : : * @param[in] inner
10706 : : * Item is inner pattern.
10707 : : * @param[in] key_type
10708 : : * Set flow matcher mask or value.
10709 : : */
10710 : : static void
10711 [ # # ]: 0 : flow_dv_translate_item_icmp6_echo(void *key, const struct rte_flow_item *item,
10712 : : int inner, uint32_t key_type)
10713 : : {
10714 : : const struct rte_flow_item_icmp6_echo *icmp6_m;
10715 : : const struct rte_flow_item_icmp6_echo *icmp6_v;
10716 : : uint32_t icmp6_header_data_m = 0;
10717 : : uint32_t icmp6_header_data_v = 0;
10718 : : void *headers_v;
10719 : : void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
10720 : : uint8_t icmp6_type = 0;
10721 : : struct rte_flow_item_icmp6_echo zero_mask;
10722 : :
10723 : : memset(&zero_mask, 0, sizeof(zero_mask));
10724 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
10725 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
10726 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10727 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, 0xFF);
10728 : : else
10729 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
10730 : : IPPROTO_ICMPV6);
10731 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, icmp6_v, icmp6_m, &zero_mask);
# # # # ]
10732 : : /* Set fixed type and code for icmpv6 echo request or reply */
10733 [ # # ]: 0 : icmp6_type = (item->type == RTE_FLOW_ITEM_TYPE_ICMP6_ECHO_REQUEST ?
10734 : : RTE_ICMP6_ECHO_REQUEST : RTE_ICMP6_ECHO_REPLY);
10735 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M) {
10736 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_type, 0xFF);
10737 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_code, 0xFF);
10738 : : } else {
10739 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_type, icmp6_type);
10740 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_code, 0);
10741 : : }
10742 [ # # ]: 0 : if (icmp6_v == NULL)
10743 : 0 : return;
10744 : : /* Set icmp6 header data (identifier & sequence) accordingly */
10745 : 0 : icmp6_header_data_m =
10746 [ # # ]: 0 : (rte_be_to_cpu_16(icmp6_m->hdr.identifier) << 16) |
10747 [ # # ]: 0 : rte_be_to_cpu_16(icmp6_m->hdr.sequence);
10748 [ # # ]: 0 : if (icmp6_header_data_m) {
10749 : 0 : icmp6_header_data_v =
10750 [ # # ]: 0 : (rte_be_to_cpu_16(icmp6_v->hdr.identifier) << 16) |
10751 [ # # ]: 0 : rte_be_to_cpu_16(icmp6_v->hdr.sequence);
10752 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_header_data,
10753 : : icmp6_header_data_v & icmp6_header_data_m);
10754 : : }
10755 : : }
10756 : :
10757 : : /**
10758 : : * Add ICMP item to the value.
10759 : : *
10760 : : * @param[in, out] key
10761 : : * Flow matcher value.
10762 : : * @param[in] item
10763 : : * Flow pattern to translate.
10764 : : * @param[in] inner
10765 : : * Item is inner pattern.
10766 : : * @param[in] key_type
10767 : : * Set flow matcher mask or value.
10768 : : */
10769 : : static void
10770 : 0 : flow_dv_translate_item_icmp(void *key, const struct rte_flow_item *item,
10771 : : int inner, uint32_t key_type)
10772 : : {
10773 : : const struct rte_flow_item_icmp *icmp_m;
10774 : : const struct rte_flow_item_icmp *icmp_v;
10775 : : uint32_t icmp_header_data_m = 0;
10776 : : uint32_t icmp_header_data_v = 0;
10777 : : void *headers_v;
10778 : : void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
10779 : :
10780 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
10781 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
10782 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10783 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
10784 : : ip_protocol, 0xFF);
10785 : : else
10786 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
10787 : : ip_protocol, IPPROTO_ICMP);
10788 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
10789 : : return;
10790 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, icmp_v, icmp_m,
# # # # ]
10791 : : &rte_flow_item_icmp_mask);
10792 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmp_type,
10793 : : icmp_v->hdr.icmp_type & icmp_m->hdr.icmp_type);
10794 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmp_code,
10795 : : icmp_v->hdr.icmp_code & icmp_m->hdr.icmp_code);
10796 [ # # ]: 0 : icmp_header_data_m = rte_be_to_cpu_16(icmp_m->hdr.icmp_seq_nb);
10797 [ # # ]: 0 : icmp_header_data_m |= rte_be_to_cpu_16(icmp_m->hdr.icmp_ident) << 16;
10798 [ # # ]: 0 : if (icmp_header_data_m) {
10799 [ # # ]: 0 : icmp_header_data_v = rte_be_to_cpu_16(icmp_v->hdr.icmp_seq_nb);
10800 : 0 : icmp_header_data_v |=
10801 [ # # ]: 0 : rte_be_to_cpu_16(icmp_v->hdr.icmp_ident) << 16;
10802 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmp_header_data,
10803 : : icmp_header_data_v & icmp_header_data_m);
10804 : : }
10805 : : }
10806 : :
10807 : : /**
10808 : : * Add GTP item to the value.
10809 : : *
10810 : : * @param[in, out] key
10811 : : * Flow matcher value.
10812 : : * @param[in] item
10813 : : * Flow pattern to translate.
10814 : : * @param[in] inner
10815 : : * Item is inner pattern.
10816 : : * @param[in] key_type
10817 : : * Set flow matcher mask or value.
10818 : : */
10819 : : static void
10820 : 0 : flow_dv_translate_item_gtp(void *key, const struct rte_flow_item *item,
10821 : : int inner, uint32_t key_type)
10822 : : {
10823 : : const struct rte_flow_item_gtp *gtp_m;
10824 : : const struct rte_flow_item_gtp *gtp_v;
10825 : : void *headers_v;
10826 : : void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
10827 : : uint16_t dport = RTE_GTPU_UDP_PORT;
10828 : :
10829 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
10830 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
10831 [ # # # # ]: 0 : if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
10832 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10833 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
10834 : : udp_dport, 0xFFFF);
10835 : : else
10836 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
10837 : : udp_dport, dport);
10838 : : }
10839 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
10840 : : return;
10841 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, gtp_v, gtp_m,
# # # # ]
10842 : : &rte_flow_item_gtp_mask);
10843 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_msg_flags,
10844 : : gtp_v->hdr.gtp_hdr_info & gtp_m->hdr.gtp_hdr_info);
10845 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_msg_type,
10846 : : gtp_v->hdr.msg_type & gtp_m->hdr.msg_type);
10847 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_teid,
10848 : : rte_be_to_cpu_32(gtp_v->hdr.teid & gtp_m->hdr.teid));
10849 : : }
10850 : :
10851 : : /**
10852 : : * Add GTP PSC item to matcher.
10853 : : *
10854 : : * @param[in, out] key
10855 : : * Flow matcher value.
10856 : : * @param[in] item
10857 : : * Flow pattern to translate.
10858 : : * @param[in] key_type
10859 : : * Set flow matcher mask or value.
10860 : : */
10861 : : static int
10862 : 0 : flow_dv_translate_item_gtp_psc(void *key, const struct rte_flow_item *item,
10863 : : uint32_t key_type)
10864 : : {
10865 : : const struct rte_flow_item_gtp_psc *gtp_psc_m;
10866 : : const struct rte_flow_item_gtp_psc *gtp_psc_v;
10867 : : void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
10868 : : union {
10869 : : uint32_t w32;
10870 : : struct {
10871 : : uint16_t seq_num;
10872 : : uint8_t npdu_num;
10873 : : uint8_t next_ext_header_type;
10874 : : };
10875 : : } dw_2;
10876 : : union {
10877 : : uint32_t w32;
10878 : : struct {
10879 : : uint8_t len;
10880 : : uint8_t type_flags;
10881 : : uint8_t qfi;
10882 : : uint8_t reserved;
10883 : : };
10884 : : } dw_0;
10885 : : uint8_t gtp_flags;
10886 : :
10887 : : /* Always set E-flag match on one, regardless of GTP item settings. */
10888 [ # # ]: 0 : gtp_flags = MLX5_GET(fte_match_set_misc3, misc3_v, gtpu_msg_flags);
10889 : 0 : gtp_flags |= MLX5_GTP_EXT_HEADER_FLAG;
10890 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_msg_flags, gtp_flags);
10891 : : /*Set next extension header type. */
10892 : 0 : dw_2.seq_num = 0;
10893 : 0 : dw_2.npdu_num = 0;
10894 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10895 : 0 : dw_2.next_ext_header_type = 0xff;
10896 : : else
10897 : 0 : dw_2.next_ext_header_type = 0x85;
10898 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_dw_2,
10899 : : rte_cpu_to_be_32(dw_2.w32));
10900 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
10901 : : return 0;
10902 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, gtp_psc_v,
# # # # ]
10903 : : gtp_psc_m, &rte_flow_item_gtp_psc_mask);
10904 : 0 : dw_0.w32 = 0;
10905 : 0 : dw_0.type_flags = MLX5_GTP_PDU_TYPE_SHIFT(gtp_psc_v->hdr.type &
10906 : : gtp_psc_m->hdr.type);
10907 : 0 : dw_0.qfi = gtp_psc_v->hdr.qfi & gtp_psc_m->hdr.qfi;
10908 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_first_ext_dw_0,
10909 : : rte_cpu_to_be_32(dw_0.w32));
10910 : 0 : return 0;
10911 : : }
10912 : :
10913 : : /**
10914 : : * Add eCPRI item to matcher and to the value.
10915 : : *
10916 : : * @param[in] dev
10917 : : * The devich to configure through.
10918 : : * @param[in, out] key
10919 : : * Flow matcher value.
10920 : : * @param[in] item
10921 : : * Flow pattern to translate.
10922 : : * @param[in] last_item
10923 : : * Last item flags.
10924 : : * @param[in] key_type
10925 : : * Set flow matcher mask or value.
10926 : : */
10927 : : static void
10928 : 0 : flow_dv_translate_item_ecpri(struct rte_eth_dev *dev, void *key,
10929 : : const struct rte_flow_item *item,
10930 : : uint64_t last_item, uint32_t key_type)
10931 : : {
10932 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10933 : : const struct rte_flow_item_ecpri *ecpri_m;
10934 : : const struct rte_flow_item_ecpri *ecpri_v;
10935 : 0 : const struct rte_flow_item_ecpri *ecpri_vv = item->spec;
10936 : : struct rte_ecpri_common_hdr common;
10937 : : void *misc4_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_4);
10938 : : uint32_t *samples;
10939 : : void *dw_v;
10940 : :
10941 : : /*
10942 : : * In case of eCPRI over Ethernet, if EtherType is not specified,
10943 : : * match on eCPRI EtherType implicitly.
10944 : : */
10945 [ # # ]: 0 : if (last_item & MLX5_FLOW_LAYER_OUTER_L2) {
10946 : : void *hdrs_v, *l2v;
10947 : :
10948 : : hdrs_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
10949 : : l2v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_v, ethertype);
10950 [ # # ]: 0 : if (*(uint16_t *)l2v == 0) {
10951 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10952 : 0 : *(uint16_t *)l2v = UINT16_MAX;
10953 : : else
10954 : 0 : *(uint16_t *)l2v =
10955 : : RTE_BE16(RTE_ETHER_TYPE_ECPRI);
10956 : : }
10957 : : }
10958 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
10959 : 0 : return;
10960 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, ecpri_v, ecpri_m,
# # # # ]
10961 : : &rte_flow_item_ecpri_mask);
10962 : : /*
10963 : : * Maximal four DW samples are supported in a single matching now.
10964 : : * Two are used now for a eCPRI matching:
10965 : : * 1. Type: one byte, mask should be 0x00ff0000 in network order
10966 : : * 2. ID of a message: one or two bytes, mask 0xffff0000 or 0xff000000
10967 : : * if any.
10968 : : */
10969 [ # # ]: 0 : if (!ecpri_m->hdr.common.u32)
10970 : : return;
10971 : 0 : samples = priv->sh->ecpri_parser.ids;
10972 : : /* Need to take the whole DW as the mask to fill the entry. */
10973 : : dw_v = MLX5_ADDR_OF(fte_match_set_misc4, misc4_v,
10974 : : prog_sample_field_value_0);
10975 : : /* Already big endian (network order) in the header. */
10976 : 0 : *(uint32_t *)dw_v = ecpri_v->hdr.common.u32 & ecpri_m->hdr.common.u32;
10977 : : /* Sample#0, used for matching type, offset 0. */
10978 : : /* It makes no sense to set the sample ID in the mask field. */
10979 [ # # ]: 0 : MLX5_SET(fte_match_set_misc4, misc4_v,
10980 : : prog_sample_field_id_0, samples[0]);
10981 : : /*
10982 : : * Checking if message body part needs to be matched.
10983 : : * Some wildcard rules only matching type field should be supported.
10984 : : */
10985 [ # # ]: 0 : if (ecpri_m->hdr.dummy[0]) {
10986 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_SW_M)
10987 [ # # ]: 0 : common.u32 = rte_be_to_cpu_32(ecpri_vv->hdr.common.u32);
10988 : : else
10989 [ # # ]: 0 : common.u32 = rte_be_to_cpu_32(ecpri_v->hdr.common.u32);
10990 [ # # ]: 0 : switch (common.type) {
10991 : 0 : case RTE_ECPRI_MSG_TYPE_IQ_DATA:
10992 : : case RTE_ECPRI_MSG_TYPE_RTC_CTRL:
10993 : : case RTE_ECPRI_MSG_TYPE_DLY_MSR:
10994 : : dw_v = MLX5_ADDR_OF(fte_match_set_misc4, misc4_v,
10995 : : prog_sample_field_value_1);
10996 : 0 : *(uint32_t *)dw_v = ecpri_v->hdr.dummy[0] &
10997 : : ecpri_m->hdr.dummy[0];
10998 : : /* Sample#1, to match message body, offset 4. */
10999 [ # # ]: 0 : MLX5_SET(fte_match_set_misc4, misc4_v,
11000 : : prog_sample_field_id_1, samples[1]);
11001 : 0 : break;
11002 : : default:
11003 : : /* Others, do not match any sample ID. */
11004 : : break;
11005 : : }
11006 : : }
11007 : : }
11008 : :
11009 : : /*
11010 : : * Add connection tracking status item to matcher
11011 : : *
11012 : : * @param[in] dev
11013 : : * The devich to configure through.
11014 : : * @param[in, out] matcher
11015 : : * Flow matcher.
11016 : : * @param[in, out] key
11017 : : * Flow matcher value.
11018 : : * @param[in] item
11019 : : * Flow pattern to translate.
11020 : : */
11021 : : static void
11022 : 0 : flow_dv_translate_item_aso_ct(struct rte_eth_dev *dev,
11023 : : void *matcher, void *key,
11024 : : const struct rte_flow_item *item)
11025 : : {
11026 : : uint32_t reg_value = 0;
11027 : : int reg_id;
11028 : : /* 8LSB 0b 11/0000/11, middle 4 bits are reserved. */
11029 : : uint32_t reg_mask = 0;
11030 : 0 : const struct rte_flow_item_conntrack *spec = item->spec;
11031 : 0 : const struct rte_flow_item_conntrack *mask = item->mask;
11032 : : uint32_t flags;
11033 : : struct rte_flow_error error;
11034 : :
11035 [ # # ]: 0 : if (!mask)
11036 : : mask = &rte_flow_item_conntrack_mask;
11037 [ # # # # ]: 0 : if (!spec || !mask->flags)
11038 : 0 : return;
11039 : 0 : flags = spec->flags & mask->flags;
11040 : : /* The conflict should be checked in the validation. */
11041 : : if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_VALID)
11042 : : reg_value |= MLX5_CT_SYNDROME_VALID;
11043 [ # # ]: 0 : if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_CHANGED)
11044 : : reg_value |= MLX5_CT_SYNDROME_STATE_CHANGE;
11045 [ # # ]: 0 : if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_INVALID)
11046 : 0 : reg_value |= MLX5_CT_SYNDROME_INVALID;
11047 [ # # ]: 0 : if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_DISABLED)
11048 : 0 : reg_value |= MLX5_CT_SYNDROME_TRAP;
11049 [ # # ]: 0 : if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_BAD)
11050 : 0 : reg_value |= MLX5_CT_SYNDROME_BAD_PACKET;
11051 [ # # ]: 0 : if (mask->flags & (RTE_FLOW_CONNTRACK_PKT_STATE_VALID |
11052 : : RTE_FLOW_CONNTRACK_PKT_STATE_INVALID |
11053 : : RTE_FLOW_CONNTRACK_PKT_STATE_DISABLED))
11054 : : reg_mask |= 0xc0;
11055 [ # # ]: 0 : if (mask->flags & RTE_FLOW_CONNTRACK_PKT_STATE_CHANGED)
11056 : 0 : reg_mask |= MLX5_CT_SYNDROME_STATE_CHANGE;
11057 [ # # ]: 0 : if (mask->flags & RTE_FLOW_CONNTRACK_PKT_STATE_BAD)
11058 : 0 : reg_mask |= MLX5_CT_SYNDROME_BAD_PACKET;
11059 : : /* The REG_C_x value could be saved during startup. */
11060 : 0 : reg_id = mlx5_flow_get_reg_id(dev, MLX5_ASO_CONNTRACK, 0, &error);
11061 [ # # ]: 0 : if (reg_id == REG_NON)
11062 : : return;
11063 : 0 : flow_dv_match_meta_reg_all(matcher, key, (enum modify_reg)reg_id,
11064 : : reg_value, reg_mask);
11065 : : }
11066 : :
11067 : : static void
11068 : 0 : flow_dv_translate_item_flex(struct rte_eth_dev *dev, void *matcher, void *key,
11069 : : const struct rte_flow_item *item,
11070 : : struct mlx5_flow *dev_flow, bool is_inner)
11071 : : {
11072 : 0 : const struct rte_flow_item_flex *spec =
11073 : : (const struct rte_flow_item_flex *)item->spec;
11074 : 0 : int index = mlx5_flex_acquire_index(dev, spec->handle, false);
11075 : :
11076 : : MLX5_ASSERT(index >= 0 && index < (int)(sizeof(uint32_t) * CHAR_BIT));
11077 [ # # ]: 0 : if (index < 0)
11078 : : return;
11079 [ # # ]: 0 : if (!(dev_flow->handle->flex_item & RTE_BIT32(index))) {
11080 : : /* Don't count both inner and outer flex items in one rule. */
11081 : 0 : if (mlx5_flex_acquire_index(dev, spec->handle, true) != index)
11082 : : MLX5_ASSERT(false);
11083 : 0 : dev_flow->handle->flex_item |= (uint8_t)RTE_BIT32(index);
11084 : : }
11085 : 0 : mlx5_flex_flow_translate_item(dev, matcher, key, item, is_inner);
11086 : : }
11087 : :
11088 : : /**
11089 : : * Add METER_COLOR item to matcher
11090 : : *
11091 : : * @param[in] dev
11092 : : * The device to configure through.
11093 : : * @param[in, out] key
11094 : : * Flow matcher value.
11095 : : * @param[in] item
11096 : : * Flow pattern to translate.
11097 : : * @param[in] key_type
11098 : : * Set flow matcher mask or value.
11099 : : */
11100 : : static void
11101 : 0 : flow_dv_translate_item_meter_color(struct rte_eth_dev *dev, void *key,
11102 : : const struct rte_flow_item *item,
11103 : : uint32_t key_type)
11104 : : {
11105 : 0 : const struct rte_flow_item_meter_color *color_m = item->mask;
11106 : 0 : const struct rte_flow_item_meter_color *color_v = item->spec;
11107 : : uint32_t value, mask;
11108 : : int reg = REG_NON;
11109 : :
11110 : : MLX5_ASSERT(color_v);
11111 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
11112 : : return;
11113 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, color_v, color_m,
# # # # ]
11114 : : &rte_flow_item_meter_color_mask);
11115 [ # # ]: 0 : value = rte_col_2_mlx5_col(color_v->color);
11116 : : mask = color_m ?
11117 [ # # ]: 0 : color_m->color : (UINT32_C(1) << MLX5_MTR_COLOR_BITS) - 1;
11118 [ # # ]: 0 : if (!!(key_type & MLX5_SET_MATCHER_SW))
11119 : 0 : reg = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, NULL);
11120 : : else
11121 : : reg = flow_hw_get_reg_id(dev,
11122 : : RTE_FLOW_ITEM_TYPE_METER_COLOR, 0);
11123 [ # # ]: 0 : if (reg == REG_NON)
11124 : : return;
11125 : 0 : flow_dv_match_meta_reg(key, (enum modify_reg)reg, value, mask);
11126 : : }
11127 : :
11128 : : static void
11129 : 0 : flow_dv_translate_item_aggr_affinity(void *key,
11130 : : const struct rte_flow_item *item,
11131 : : uint32_t key_type)
11132 : : {
11133 : : const struct rte_flow_item_aggr_affinity *affinity_v;
11134 : : const struct rte_flow_item_aggr_affinity *affinity_m;
11135 : : void *misc_v;
11136 : :
11137 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, affinity_v, affinity_m,
# # # # ]
11138 : : &rte_flow_item_aggr_affinity_mask);
11139 : : misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
11140 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, lag_rx_port_affinity,
11141 : : affinity_v->affinity & affinity_m->affinity);
11142 : 0 : }
11143 : :
11144 : : static void
11145 : 0 : flow_dv_translate_item_ib_bth(void *key,
11146 : : const struct rte_flow_item *item,
11147 : : int inner, uint32_t key_type)
11148 : : {
11149 : : const struct rte_flow_item_ib_bth *bth_m;
11150 : : const struct rte_flow_item_ib_bth *bth_v;
11151 : : void *headers_v, *misc_v;
11152 : : uint16_t udp_dport;
11153 : : char *qpn_v;
11154 : : int i, size;
11155 : :
11156 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
11157 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
11158 [ # # # # ]: 0 : if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
11159 [ # # ]: 0 : udp_dport = key_type & MLX5_SET_MATCHER_M ?
11160 : : 0xFFFF : MLX5_UDP_PORT_ROCEv2;
11161 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, udp_dport);
11162 : : }
11163 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
11164 : : return;
11165 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, bth_v, bth_m, &rte_flow_item_ib_bth_mask);
# # # # ]
11166 : : misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
11167 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, bth_opcode,
11168 : : bth_v->hdr.opcode & bth_m->hdr.opcode);
11169 : 0 : qpn_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, bth_dst_qp);
11170 : : size = sizeof(bth_m->hdr.dst_qp);
11171 [ # # ]: 0 : for (i = 0; i < size; ++i)
11172 : 0 : qpn_v[i] = bth_m->hdr.dst_qp[i] & bth_v->hdr.dst_qp[i];
11173 : : }
11174 : :
11175 : : static uint32_t matcher_zero[MLX5_ST_SZ_DW(fte_match_param)] = { 0 };
11176 : :
11177 : : #define HEADER_IS_ZERO(match_criteria, headers) \
11178 : : !(memcmp(MLX5_ADDR_OF(fte_match_param, match_criteria, headers), \
11179 : : matcher_zero, MLX5_FLD_SZ_BYTES(fte_match_param, headers))) \
11180 : :
11181 : : /**
11182 : : * Calculate flow matcher enable bitmap.
11183 : : *
11184 : : * @param match_criteria
11185 : : * Pointer to flow matcher criteria.
11186 : : *
11187 : : * @return
11188 : : * Bitmap of enabled fields.
11189 : : */
11190 : : static uint8_t
11191 : 0 : flow_dv_matcher_enable(uint32_t *match_criteria)
11192 : : {
11193 : : uint8_t match_criteria_enable;
11194 : :
11195 : : match_criteria_enable =
11196 : 0 : (!HEADER_IS_ZERO(match_criteria, outer_headers)) <<
11197 : : MLX5_MATCH_CRITERIA_ENABLE_OUTER_BIT;
11198 : 0 : match_criteria_enable |=
11199 [ # # ]: 0 : (!HEADER_IS_ZERO(match_criteria, misc_parameters)) <<
11200 : : MLX5_MATCH_CRITERIA_ENABLE_MISC_BIT;
11201 : 0 : match_criteria_enable |=
11202 [ # # ]: 0 : (!HEADER_IS_ZERO(match_criteria, inner_headers)) <<
11203 : : MLX5_MATCH_CRITERIA_ENABLE_INNER_BIT;
11204 : 0 : match_criteria_enable |=
11205 [ # # ]: 0 : (!HEADER_IS_ZERO(match_criteria, misc_parameters_2)) <<
11206 : : MLX5_MATCH_CRITERIA_ENABLE_MISC2_BIT;
11207 : 0 : match_criteria_enable |=
11208 [ # # ]: 0 : (!HEADER_IS_ZERO(match_criteria, misc_parameters_3)) <<
11209 : : MLX5_MATCH_CRITERIA_ENABLE_MISC3_BIT;
11210 : 0 : match_criteria_enable |=
11211 [ # # ]: 0 : (!HEADER_IS_ZERO(match_criteria, misc_parameters_4)) <<
11212 : : MLX5_MATCH_CRITERIA_ENABLE_MISC4_BIT;
11213 : 0 : match_criteria_enable |=
11214 [ # # ]: 0 : (!HEADER_IS_ZERO(match_criteria, misc_parameters_5)) <<
11215 : : MLX5_MATCH_CRITERIA_ENABLE_MISC5_BIT;
11216 : 0 : return match_criteria_enable;
11217 : : }
11218 : :
11219 : : static void
11220 : : __flow_dv_adjust_buf_size(size_t *size, uint8_t match_criteria)
11221 : : {
11222 : : /*
11223 : : * Check flow matching criteria first, subtract misc5/4 length if flow
11224 : : * doesn't own misc5/4 parameters. In some old rdma-core releases,
11225 : : * misc5/4 are not supported, and matcher creation failure is expected
11226 : : * w/o subtraction. If misc5 is provided, misc4 must be counted in since
11227 : : * misc5 is right after misc4.
11228 : : */
11229 : 0 : if (!(match_criteria & (1 << MLX5_MATCH_CRITERIA_ENABLE_MISC5_BIT))) {
11230 : 0 : *size = MLX5_ST_SZ_BYTES(fte_match_param) -
11231 : : MLX5_ST_SZ_BYTES(fte_match_set_misc5);
11232 [ # # # # : 0 : if (!(match_criteria & (1 <<
# # # # #
# # # # #
# # # # #
# ]
11233 : : MLX5_MATCH_CRITERIA_ENABLE_MISC4_BIT))) {
11234 : 0 : *size -= MLX5_ST_SZ_BYTES(fte_match_set_misc4);
11235 : : }
11236 : : }
11237 : : }
11238 : :
11239 : : static struct mlx5_list_entry *
11240 : 0 : flow_dv_matcher_clone_cb(void *tool_ctx __rte_unused,
11241 : : struct mlx5_list_entry *entry, void *cb_ctx)
11242 : : {
11243 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11244 : 0 : struct mlx5_flow_dv_matcher *ref = ctx->data;
11245 : 0 : struct mlx5_flow_tbl_data_entry *tbl = container_of(ref->tbl,
11246 : : typeof(*tbl), tbl);
11247 : 0 : struct mlx5_flow_dv_matcher *resource = mlx5_malloc(MLX5_MEM_ANY,
11248 : : sizeof(*resource),
11249 : : 0, SOCKET_ID_ANY);
11250 : :
11251 [ # # ]: 0 : if (!resource) {
11252 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
11253 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
11254 : : "cannot create matcher");
11255 : 0 : return NULL;
11256 : : }
11257 : : memcpy(resource, entry, sizeof(*resource));
11258 : 0 : resource->tbl = &tbl->tbl;
11259 : 0 : return &resource->entry;
11260 : : }
11261 : :
11262 : : static void
11263 : 0 : flow_dv_matcher_clone_free_cb(void *tool_ctx __rte_unused,
11264 : : struct mlx5_list_entry *entry)
11265 : : {
11266 : 0 : mlx5_free(entry);
11267 : 0 : }
11268 : :
11269 : : struct mlx5_list_entry *
11270 : 0 : flow_dv_tbl_create_cb(void *tool_ctx, void *cb_ctx)
11271 : 0 : {
11272 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
11273 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11274 : 0 : struct rte_eth_dev *dev = ctx->dev;
11275 : : struct mlx5_flow_tbl_data_entry *tbl_data;
11276 : 0 : struct mlx5_flow_tbl_tunnel_prm *tt_prm = ctx->data2;
11277 : 0 : struct rte_flow_error *error = ctx->error;
11278 : 0 : union mlx5_flow_tbl_key key = { .v64 = *(uint64_t *)(ctx->data) };
11279 : : struct mlx5_flow_tbl_resource *tbl;
11280 : : void *domain;
11281 : 0 : uint32_t idx = 0;
11282 : : int ret;
11283 : :
11284 : 0 : tbl_data = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_JUMP], &idx);
11285 [ # # ]: 0 : if (!tbl_data) {
11286 : 0 : rte_flow_error_set(error, ENOMEM,
11287 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11288 : : NULL,
11289 : : "cannot allocate flow table data entry");
11290 : 0 : return NULL;
11291 : : }
11292 : 0 : tbl_data->idx = idx;
11293 : 0 : tbl_data->tunnel = tt_prm->tunnel;
11294 : 0 : tbl_data->group_id = tt_prm->group_id;
11295 [ # # ]: 0 : tbl_data->external = !!tt_prm->external;
11296 : 0 : tbl_data->tunnel_offload = is_tunnel_offload_active(dev);
11297 : 0 : tbl_data->is_egress = !!key.is_egress;
11298 : 0 : tbl_data->is_transfer = !!key.is_fdb;
11299 : 0 : tbl_data->dummy = !!key.dummy;
11300 : 0 : tbl_data->level = key.level;
11301 : 0 : tbl_data->id = key.id;
11302 : : tbl = &tbl_data->tbl;
11303 [ # # ]: 0 : if (key.dummy)
11304 : 0 : return &tbl_data->entry;
11305 [ # # ]: 0 : if (key.is_fdb)
11306 : 0 : domain = sh->fdb_domain;
11307 [ # # ]: 0 : else if (key.is_egress)
11308 : 0 : domain = sh->tx_domain;
11309 : : else
11310 : 0 : domain = sh->rx_domain;
11311 : : ret = mlx5_flow_os_create_flow_tbl(domain, key.level, &tbl->obj);
11312 : : if (ret) {
11313 : 0 : rte_flow_error_set(error, ENOMEM,
11314 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11315 : : NULL, "cannot create flow table object");
11316 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], idx);
11317 : 0 : return NULL;
11318 : : }
11319 [ # # ]: 0 : if (key.level != 0) {
11320 : : ret = mlx5_flow_os_create_flow_action_dest_flow_tbl
11321 : : (tbl->obj, &tbl_data->jump.action);
11322 : : if (ret) {
11323 : 0 : rte_flow_error_set(error, ENOMEM,
11324 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11325 : : NULL,
11326 : : "cannot create flow jump action");
11327 : 0 : mlx5_flow_os_destroy_flow_tbl(tbl->obj);
11328 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], idx);
11329 : 0 : return NULL;
11330 : : }
11331 : : }
11332 [ # # # # ]: 0 : MKSTR(matcher_name, "%s_%s_%u_%u_matcher_list",
11333 : : key.is_fdb ? "FDB" : "NIC", key.is_egress ? "egress" : "ingress",
11334 : : key.level, key.id);
11335 : 0 : tbl_data->matchers = mlx5_list_create(matcher_name, sh, true,
11336 : : flow_dv_matcher_create_cb,
11337 : : flow_dv_matcher_match_cb,
11338 : : flow_dv_matcher_remove_cb,
11339 : : flow_dv_matcher_clone_cb,
11340 : : flow_dv_matcher_clone_free_cb);
11341 [ # # ]: 0 : if (!tbl_data->matchers) {
11342 : 0 : rte_flow_error_set(error, ENOMEM,
11343 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11344 : : NULL,
11345 : : "cannot create tbl matcher list");
11346 : 0 : mlx5_flow_os_destroy_flow_action(tbl_data->jump.action);
11347 : 0 : mlx5_flow_os_destroy_flow_tbl(tbl->obj);
11348 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], idx);
11349 : 0 : return NULL;
11350 : : }
11351 : 0 : return &tbl_data->entry;
11352 : : }
11353 : :
11354 : : int
11355 : 0 : flow_dv_tbl_match_cb(void *tool_ctx __rte_unused, struct mlx5_list_entry *entry,
11356 : : void *cb_ctx)
11357 : : {
11358 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11359 : : struct mlx5_flow_tbl_data_entry *tbl_data =
11360 : : container_of(entry, struct mlx5_flow_tbl_data_entry, entry);
11361 : 0 : union mlx5_flow_tbl_key key = { .v64 = *(uint64_t *)(ctx->data) };
11362 : :
11363 : 0 : return tbl_data->level != key.level ||
11364 [ # # ]: 0 : tbl_data->id != key.id ||
11365 [ # # ]: 0 : tbl_data->dummy != key.dummy ||
11366 [ # # # # ]: 0 : tbl_data->is_transfer != !!key.is_fdb ||
11367 [ # # ]: 0 : tbl_data->is_egress != !!key.is_egress;
11368 : : }
11369 : :
11370 : : struct mlx5_list_entry *
11371 : 0 : flow_dv_tbl_clone_cb(void *tool_ctx, struct mlx5_list_entry *oentry,
11372 : : void *cb_ctx)
11373 : : {
11374 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
11375 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11376 : : struct mlx5_flow_tbl_data_entry *tbl_data;
11377 : 0 : struct rte_flow_error *error = ctx->error;
11378 : 0 : uint32_t idx = 0;
11379 : :
11380 : 0 : tbl_data = mlx5_ipool_malloc(sh->ipool[MLX5_IPOOL_JUMP], &idx);
11381 [ # # ]: 0 : if (!tbl_data) {
11382 : 0 : rte_flow_error_set(error, ENOMEM,
11383 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11384 : : NULL,
11385 : : "cannot allocate flow table data entry");
11386 : 0 : return NULL;
11387 : : }
11388 : : memcpy(tbl_data, oentry, sizeof(*tbl_data));
11389 : 0 : tbl_data->idx = idx;
11390 : 0 : return &tbl_data->entry;
11391 : : }
11392 : :
11393 : : void
11394 : 0 : flow_dv_tbl_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
11395 : : {
11396 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
11397 : : struct mlx5_flow_tbl_data_entry *tbl_data =
11398 : : container_of(entry, struct mlx5_flow_tbl_data_entry, entry);
11399 : :
11400 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], tbl_data->idx);
11401 : 0 : }
11402 : :
11403 : : /**
11404 : : * Get a flow table.
11405 : : *
11406 : : * @param[in, out] dev
11407 : : * Pointer to rte_eth_dev structure.
11408 : : * @param[in] table_level
11409 : : * Table level to use.
11410 : : * @param[in] egress
11411 : : * Direction of the table.
11412 : : * @param[in] transfer
11413 : : * E-Switch or NIC flow.
11414 : : * @param[in] dummy
11415 : : * Dummy entry for dv API.
11416 : : * @param[in] table_id
11417 : : * Table id to use.
11418 : : * @param[out] error
11419 : : * pointer to error structure.
11420 : : *
11421 : : * @return
11422 : : * Returns tables resource based on the index, NULL in case of failed.
11423 : : */
11424 : : struct mlx5_flow_tbl_resource *
11425 : 0 : flow_dv_tbl_resource_get(struct rte_eth_dev *dev,
11426 : : uint32_t table_level, uint8_t egress,
11427 : : uint8_t transfer,
11428 : : bool external,
11429 : : const struct mlx5_flow_tunnel *tunnel,
11430 : : uint32_t group_id, uint8_t dummy,
11431 : : uint32_t table_id,
11432 : : struct rte_flow_error *error)
11433 : : {
11434 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11435 : 0 : union mlx5_flow_tbl_key table_key = {
11436 : : {
11437 : : .level = table_level,
11438 : : .id = table_id,
11439 : : .reserved = 0,
11440 : 0 : .dummy = !!dummy,
11441 : 0 : .is_fdb = !!transfer,
11442 : 0 : .is_egress = !!egress,
11443 : : }
11444 : : };
11445 : 0 : struct mlx5_flow_tbl_tunnel_prm tt_prm = {
11446 : : .tunnel = tunnel,
11447 : : .group_id = group_id,
11448 : : .external = external,
11449 : : };
11450 : 0 : struct mlx5_flow_cb_ctx ctx = {
11451 : : .dev = dev,
11452 : : .error = error,
11453 : : .data = &table_key.v64,
11454 : : .data2 = &tt_prm,
11455 : : };
11456 : : struct mlx5_list_entry *entry;
11457 : : struct mlx5_flow_tbl_data_entry *tbl_data;
11458 : :
11459 : 0 : entry = mlx5_hlist_register(priv->sh->flow_tbls, table_key.v64, &ctx);
11460 [ # # ]: 0 : if (!entry) {
11461 : 0 : rte_flow_error_set(error, ENOMEM,
11462 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
11463 : : "cannot get table");
11464 : 0 : return NULL;
11465 : : }
11466 [ # # ]: 0 : DRV_LOG(DEBUG, "table_level %u table_id %u "
11467 : : "tunnel %u group %u registered.",
11468 : : table_level, table_id,
11469 : : tunnel ? tunnel->tunnel_id : 0, group_id);
11470 : : tbl_data = container_of(entry, struct mlx5_flow_tbl_data_entry, entry);
11471 : 0 : return &tbl_data->tbl;
11472 : : }
11473 : :
11474 : : void
11475 : 0 : flow_dv_tbl_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
11476 : : {
11477 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
11478 : : struct mlx5_flow_tbl_data_entry *tbl_data =
11479 : : container_of(entry, struct mlx5_flow_tbl_data_entry, entry);
11480 : :
11481 : : MLX5_ASSERT(entry && sh);
11482 [ # # ]: 0 : if (tbl_data->jump.action)
11483 : : mlx5_flow_os_destroy_flow_action(tbl_data->jump.action);
11484 [ # # ]: 0 : if (tbl_data->tbl.obj)
11485 : : mlx5_flow_os_destroy_flow_tbl(tbl_data->tbl.obj);
11486 [ # # ]: 0 : if (tbl_data->tunnel_offload && tbl_data->external) {
11487 : : struct mlx5_list_entry *he;
11488 : : struct mlx5_hlist *tunnel_grp_hash;
11489 : 0 : struct mlx5_flow_tunnel_hub *thub = sh->tunnel_hub;
11490 : 0 : union tunnel_tbl_key tunnel_key = {
11491 : 0 : .tunnel_id = tbl_data->tunnel ?
11492 [ # # ]: 0 : tbl_data->tunnel->tunnel_id : 0,
11493 : 0 : .group = tbl_data->group_id
11494 : : };
11495 : 0 : uint32_t table_level = tbl_data->level;
11496 : 0 : struct mlx5_flow_cb_ctx ctx = {
11497 : : .data = (void *)&tunnel_key.val,
11498 : : };
11499 : :
11500 : : tunnel_grp_hash = tbl_data->tunnel ?
11501 [ # # ]: 0 : tbl_data->tunnel->groups :
11502 : : thub->groups;
11503 : 0 : he = mlx5_hlist_lookup(tunnel_grp_hash, tunnel_key.val, &ctx);
11504 [ # # ]: 0 : if (he)
11505 : 0 : mlx5_hlist_unregister(tunnel_grp_hash, he);
11506 [ # # ]: 0 : DRV_LOG(DEBUG,
11507 : : "table_level %u id %u tunnel %u group %u released.",
11508 : : table_level,
11509 : : tbl_data->id,
11510 : : tbl_data->tunnel ?
11511 : : tbl_data->tunnel->tunnel_id : 0,
11512 : : tbl_data->group_id);
11513 : : }
11514 [ # # ]: 0 : if (tbl_data->matchers)
11515 : 0 : mlx5_list_destroy(tbl_data->matchers);
11516 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], tbl_data->idx);
11517 : 0 : }
11518 : :
11519 : : /**
11520 : : * Release a flow table.
11521 : : *
11522 : : * @param[in] sh
11523 : : * Pointer to device shared structure.
11524 : : * @param[in] tbl
11525 : : * Table resource to be released.
11526 : : *
11527 : : * @return
11528 : : * Returns 0 if table was released, else return 1;
11529 : : */
11530 : : int
11531 : 0 : flow_dv_tbl_resource_release(struct mlx5_dev_ctx_shared *sh,
11532 : : struct mlx5_flow_tbl_resource *tbl)
11533 : : {
11534 : : struct mlx5_flow_tbl_data_entry *tbl_data =
11535 : 0 : container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
11536 : :
11537 [ # # ]: 0 : if (!tbl)
11538 : : return 0;
11539 : 0 : return mlx5_hlist_unregister(sh->flow_tbls, &tbl_data->entry);
11540 : : }
11541 : :
11542 : : int
11543 : 0 : flow_dv_matcher_match_cb(void *tool_ctx __rte_unused,
11544 : : struct mlx5_list_entry *entry, void *cb_ctx)
11545 : : {
11546 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11547 : 0 : struct mlx5_flow_dv_matcher *ref = ctx->data;
11548 : : struct mlx5_flow_dv_matcher *cur = container_of(entry, typeof(*cur),
11549 : : entry);
11550 : :
11551 : 0 : return cur->crc != ref->crc ||
11552 [ # # ]: 0 : cur->priority != ref->priority ||
11553 : 0 : memcmp((const void *)cur->mask.buf,
11554 [ # # ]: 0 : (const void *)ref->mask.buf, ref->mask.size);
11555 : : }
11556 : :
11557 : : struct mlx5_list_entry *
11558 : 0 : flow_dv_matcher_create_cb(void *tool_ctx, void *cb_ctx)
11559 : : {
11560 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
11561 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11562 : 0 : struct mlx5_flow_dv_matcher *ref = ctx->data;
11563 : : struct mlx5_flow_dv_matcher *resource;
11564 : 0 : struct mlx5dv_flow_matcher_attr dv_attr = {
11565 : : .type = IBV_FLOW_ATTR_NORMAL,
11566 : 0 : .match_mask = (void *)&ref->mask,
11567 : : };
11568 : 0 : struct mlx5_flow_tbl_data_entry *tbl = container_of(ref->tbl,
11569 : : typeof(*tbl), tbl);
11570 : : int ret;
11571 : :
11572 : 0 : resource = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*resource), 0,
11573 : : SOCKET_ID_ANY);
11574 [ # # ]: 0 : if (!resource) {
11575 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
11576 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
11577 : : "cannot create matcher");
11578 : 0 : return NULL;
11579 : : }
11580 : 0 : *resource = *ref;
11581 : 0 : dv_attr.match_criteria_enable =
11582 [ # # ]: 0 : flow_dv_matcher_enable(resource->mask.buf);
11583 : : __flow_dv_adjust_buf_size(&ref->mask.size,
11584 : : dv_attr.match_criteria_enable);
11585 : 0 : dv_attr.priority = ref->priority;
11586 [ # # ]: 0 : if (tbl->is_egress)
11587 : 0 : dv_attr.flags |= IBV_FLOW_ATTR_FLAGS_EGRESS;
11588 : 0 : ret = mlx5_flow_os_create_flow_matcher(sh->cdev->ctx, &dv_attr,
11589 : : tbl->tbl.obj,
11590 : : &resource->matcher_object);
11591 : : if (ret) {
11592 : 0 : mlx5_free(resource);
11593 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
11594 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
11595 : : "cannot create matcher");
11596 : 0 : return NULL;
11597 : : }
11598 : 0 : return &resource->entry;
11599 : : }
11600 : :
11601 : : /**
11602 : : * Register the flow matcher.
11603 : : *
11604 : : * @param[in, out] dev
11605 : : * Pointer to rte_eth_dev structure.
11606 : : * @param[in, out] matcher
11607 : : * Pointer to flow matcher.
11608 : : * @param[in, out] key
11609 : : * Pointer to flow table key.
11610 : : * @parm[in, out] dev_flow
11611 : : * Pointer to the dev_flow.
11612 : : * @param[out] error
11613 : : * pointer to error structure.
11614 : : *
11615 : : * @return
11616 : : * 0 on success otherwise -errno and errno is set.
11617 : : */
11618 : : static int
11619 : 0 : flow_dv_matcher_register(struct rte_eth_dev *dev,
11620 : : struct mlx5_flow_dv_matcher *ref,
11621 : : union mlx5_flow_tbl_key *key,
11622 : : struct mlx5_flow *dev_flow,
11623 : : const struct mlx5_flow_tunnel *tunnel,
11624 : : uint32_t group_id,
11625 : : struct rte_flow_error *error)
11626 : : {
11627 : : struct mlx5_list_entry *entry;
11628 : : struct mlx5_flow_dv_matcher *resource;
11629 : : struct mlx5_flow_tbl_resource *tbl;
11630 : : struct mlx5_flow_tbl_data_entry *tbl_data;
11631 : 0 : struct mlx5_flow_cb_ctx ctx = {
11632 : : .error = error,
11633 : : .data = ref,
11634 : : };
11635 : : /**
11636 : : * tunnel offload API requires this registration for cases when
11637 : : * tunnel match rule was inserted before tunnel set rule.
11638 : : */
11639 : 0 : tbl = flow_dv_tbl_resource_get(dev, key->level,
11640 : 0 : key->is_egress, key->is_fdb,
11641 : 0 : dev_flow->external, tunnel,
11642 : 0 : group_id, 0, key->id, error);
11643 [ # # ]: 0 : if (!tbl)
11644 : 0 : return -rte_errno; /* No need to refill the error info */
11645 : 0 : tbl_data = container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
11646 : 0 : ref->tbl = tbl;
11647 : 0 : entry = mlx5_list_register(tbl_data->matchers, &ctx);
11648 [ # # ]: 0 : if (!entry) {
11649 : 0 : flow_dv_tbl_resource_release(MLX5_SH(dev), tbl);
11650 : 0 : return rte_flow_error_set(error, ENOMEM,
11651 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
11652 : : "cannot allocate ref memory");
11653 : : }
11654 : : resource = container_of(entry, typeof(*resource), entry);
11655 : 0 : dev_flow->handle->dvh.matcher = resource;
11656 : 0 : return 0;
11657 : : }
11658 : :
11659 : : struct mlx5_list_entry *
11660 : 0 : flow_dv_tag_create_cb(void *tool_ctx, void *cb_ctx)
11661 : : {
11662 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
11663 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11664 : : struct mlx5_flow_dv_tag_resource *entry;
11665 : 0 : uint32_t idx = 0;
11666 : : int ret;
11667 : :
11668 : 0 : entry = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_TAG], &idx);
11669 [ # # ]: 0 : if (!entry) {
11670 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
11671 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
11672 : : "cannot allocate resource memory");
11673 : 0 : return NULL;
11674 : : }
11675 : 0 : entry->idx = idx;
11676 : 0 : entry->tag_id = *(uint32_t *)(ctx->data);
11677 : : ret = mlx5_flow_os_create_flow_action_tag(entry->tag_id,
11678 : : &entry->action);
11679 : : if (ret) {
11680 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TAG], idx);
11681 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
11682 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11683 : : NULL, "cannot create action");
11684 : 0 : return NULL;
11685 : : }
11686 : 0 : return &entry->entry;
11687 : : }
11688 : :
11689 : : int
11690 : 0 : flow_dv_tag_match_cb(void *tool_ctx __rte_unused, struct mlx5_list_entry *entry,
11691 : : void *cb_ctx)
11692 : : {
11693 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11694 : : struct mlx5_flow_dv_tag_resource *tag =
11695 : : container_of(entry, struct mlx5_flow_dv_tag_resource, entry);
11696 : :
11697 : 0 : return *(uint32_t *)(ctx->data) != tag->tag_id;
11698 : : }
11699 : :
11700 : : struct mlx5_list_entry *
11701 : 0 : flow_dv_tag_clone_cb(void *tool_ctx, struct mlx5_list_entry *oentry,
11702 : : void *cb_ctx)
11703 : : {
11704 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
11705 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11706 : : struct mlx5_flow_dv_tag_resource *entry;
11707 : 0 : uint32_t idx = 0;
11708 : :
11709 : 0 : entry = mlx5_ipool_malloc(sh->ipool[MLX5_IPOOL_TAG], &idx);
11710 [ # # ]: 0 : if (!entry) {
11711 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
11712 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
11713 : : "cannot allocate tag resource memory");
11714 : 0 : return NULL;
11715 : : }
11716 : : memcpy(entry, oentry, sizeof(*entry));
11717 : 0 : entry->idx = idx;
11718 : 0 : return &entry->entry;
11719 : : }
11720 : :
11721 : : void
11722 : 0 : flow_dv_tag_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
11723 : : {
11724 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
11725 : : struct mlx5_flow_dv_tag_resource *tag =
11726 : : container_of(entry, struct mlx5_flow_dv_tag_resource, entry);
11727 : :
11728 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TAG], tag->idx);
11729 : 0 : }
11730 : :
11731 : : /**
11732 : : * Find existing tag resource or create and register a new one.
11733 : : *
11734 : : * @param dev[in, out]
11735 : : * Pointer to rte_eth_dev structure.
11736 : : * @param[in, out] tag_be24
11737 : : * Tag value in big endian then R-shift 8.
11738 : : * @parm[in, out] dev_flow
11739 : : * Pointer to the dev_flow.
11740 : : * @param[out] error
11741 : : * pointer to error structure.
11742 : : *
11743 : : * @return
11744 : : * 0 on success otherwise -errno and errno is set.
11745 : : */
11746 : : static int
11747 : 0 : flow_dv_tag_resource_register
11748 : : (struct rte_eth_dev *dev,
11749 : : uint32_t tag_be24,
11750 : : struct mlx5_flow *dev_flow,
11751 : : struct rte_flow_error *error)
11752 : : {
11753 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11754 : : struct mlx5_flow_dv_tag_resource *resource;
11755 : : struct mlx5_list_entry *entry;
11756 : 0 : struct mlx5_flow_cb_ctx ctx = {
11757 : : .error = error,
11758 : : .data = &tag_be24,
11759 : : };
11760 : : struct mlx5_hlist *tag_table;
11761 : :
11762 : 0 : tag_table = flow_dv_hlist_prepare(priv->sh, &priv->sh->tag_table,
11763 : : "tags",
11764 : : MLX5_TAGS_HLIST_ARRAY_SIZE,
11765 : 0 : false, false, priv->sh,
11766 : : flow_dv_tag_create_cb,
11767 : : flow_dv_tag_match_cb,
11768 : : flow_dv_tag_remove_cb,
11769 : : flow_dv_tag_clone_cb,
11770 : : flow_dv_tag_clone_free_cb,
11771 : : error);
11772 [ # # ]: 0 : if (unlikely(!tag_table))
11773 : 0 : return -rte_errno;
11774 : 0 : entry = mlx5_hlist_register(tag_table, tag_be24, &ctx);
11775 [ # # ]: 0 : if (entry) {
11776 : : resource = container_of(entry, struct mlx5_flow_dv_tag_resource,
11777 : : entry);
11778 : 0 : dev_flow->handle->dvh.rix_tag = resource->idx;
11779 : 0 : dev_flow->dv.tag_resource = resource;
11780 : 0 : return 0;
11781 : : }
11782 : 0 : return -rte_errno;
11783 : : }
11784 : :
11785 : : void
11786 : 0 : flow_dv_tag_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
11787 : : {
11788 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
11789 : : struct mlx5_flow_dv_tag_resource *tag =
11790 : : container_of(entry, struct mlx5_flow_dv_tag_resource, entry);
11791 : :
11792 : : MLX5_ASSERT(tag && sh && tag->action);
11793 : 0 : claim_zero(mlx5_flow_os_destroy_flow_action(tag->action));
11794 : 0 : DRV_LOG(DEBUG, "Tag %p: removed.", (void *)tag);
11795 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TAG], tag->idx);
11796 : 0 : }
11797 : :
11798 : : /**
11799 : : * Release the tag.
11800 : : *
11801 : : * @param dev
11802 : : * Pointer to Ethernet device.
11803 : : * @param tag_idx
11804 : : * Tag index.
11805 : : *
11806 : : * @return
11807 : : * 1 while a reference on it exists, 0 when freed.
11808 : : */
11809 : : static int
11810 : 0 : flow_dv_tag_release(struct rte_eth_dev *dev,
11811 : : uint32_t tag_idx)
11812 : : {
11813 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11814 : : struct mlx5_flow_dv_tag_resource *tag;
11815 : :
11816 : 0 : tag = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_TAG], tag_idx);
11817 [ # # ]: 0 : if (!tag)
11818 : : return 0;
11819 : 0 : DRV_LOG(DEBUG, "port %u tag %p: refcnt %d--",
11820 : : dev->data->port_id, (void *)tag, tag->entry.ref_cnt);
11821 : 0 : return mlx5_hlist_unregister(priv->sh->tag_table, &tag->entry);
11822 : : }
11823 : :
11824 : : /**
11825 : : * Translate action PORT_ID / REPRESENTED_PORT to vport.
11826 : : *
11827 : : * @param[in] dev
11828 : : * Pointer to rte_eth_dev structure.
11829 : : * @param[in] action
11830 : : * Pointer to action PORT_ID / REPRESENTED_PORT.
11831 : : * @param[out] dst_port_id
11832 : : * The target port ID.
11833 : : * @param[out] error
11834 : : * Pointer to the error structure.
11835 : : *
11836 : : * @return
11837 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
11838 : : */
11839 : : static int
11840 : 0 : flow_dv_translate_action_port_id(struct rte_eth_dev *dev,
11841 : : const struct rte_flow_action *action,
11842 : : uint32_t *dst_port_id,
11843 : : struct rte_flow_error *error)
11844 : : {
11845 : : uint32_t port;
11846 : : struct mlx5_priv *priv;
11847 : :
11848 [ # # # ]: 0 : switch (action->type) {
11849 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_ID: {
11850 : : const struct rte_flow_action_port_id *conf;
11851 : :
11852 : 0 : conf = (const struct rte_flow_action_port_id *)action->conf;
11853 [ # # ]: 0 : port = conf->original ? dev->data->port_id : conf->id;
11854 : : break;
11855 : : }
11856 : 0 : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT: {
11857 : : const struct rte_flow_action_ethdev *ethdev;
11858 : :
11859 : 0 : ethdev = (const struct rte_flow_action_ethdev *)action->conf;
11860 : 0 : port = ethdev->port_id;
11861 : 0 : break;
11862 : : }
11863 : 0 : default:
11864 : : MLX5_ASSERT(false);
11865 : 0 : return rte_flow_error_set(error, EINVAL,
11866 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
11867 : : "unknown E-Switch action");
11868 : : }
11869 : :
11870 : 0 : priv = mlx5_port_to_eswitch_info(port, false);
11871 [ # # ]: 0 : if (!priv)
11872 : 0 : return rte_flow_error_set(error, -rte_errno,
11873 : : RTE_FLOW_ERROR_TYPE_ACTION,
11874 : : NULL,
11875 : : "No eswitch info was found for port");
11876 : : #ifdef HAVE_MLX5DV_DR_CREATE_DEST_IB_PORT
11877 : : /*
11878 : : * This parameter is transferred to
11879 : : * mlx5dv_dr_action_create_dest_ib_port().
11880 : : */
11881 : 0 : *dst_port_id = priv->dev_port;
11882 : : #else
11883 : : /*
11884 : : * Legacy mode, no LAG configurations is supported.
11885 : : * This parameter is transferred to
11886 : : * mlx5dv_dr_action_create_dest_vport().
11887 : : */
11888 : : *dst_port_id = priv->vport_id;
11889 : : #endif
11890 : 0 : return 0;
11891 : : }
11892 : :
11893 : : /**
11894 : : * Create a counter with aging configuration.
11895 : : *
11896 : : * @param[in] dev
11897 : : * Pointer to rte_eth_dev structure.
11898 : : * @param[in] dev_flow
11899 : : * Pointer to the mlx5_flow.
11900 : : * @param[out] count
11901 : : * Pointer to the counter action configuration.
11902 : : * @param[in] age
11903 : : * Pointer to the aging action configuration.
11904 : : *
11905 : : * @return
11906 : : * Index to flow counter on success, 0 otherwise.
11907 : : */
11908 : : static uint32_t
11909 : 0 : flow_dv_translate_create_counter(struct rte_eth_dev *dev,
11910 : : struct mlx5_flow *dev_flow,
11911 : : const struct rte_flow_action_count *count
11912 : : __rte_unused,
11913 : : const struct rte_flow_action_age *age)
11914 : : {
11915 : : uint32_t counter;
11916 : : struct mlx5_age_param *age_param;
11917 : :
11918 : 0 : counter = flow_dv_counter_alloc(dev, !!age);
11919 [ # # ]: 0 : if (!counter || age == NULL)
11920 : : return counter;
11921 : : age_param = flow_dv_counter_idx_get_age(dev, counter);
11922 [ # # ]: 0 : age_param->context = age->context ? age->context :
11923 : 0 : (void *)(uintptr_t)(dev_flow->flow_idx);
11924 : 0 : age_param->timeout = age->timeout;
11925 : 0 : age_param->port_id = dev->data->port_id;
11926 : 0 : __atomic_store_n(&age_param->sec_since_last_hit, 0, __ATOMIC_RELAXED);
11927 : 0 : __atomic_store_n(&age_param->state, AGE_CANDIDATE, __ATOMIC_RELAXED);
11928 : 0 : return counter;
11929 : : }
11930 : :
11931 : : /**
11932 : : * Add SQ matcher
11933 : : *
11934 : : * @param[in, out] matcher
11935 : : * Flow matcher.
11936 : : * @param[in, out] key
11937 : : * Flow matcher value.
11938 : : * @param[in] item
11939 : : * Flow pattern to translate.
11940 : : * @param[in] key_type
11941 : : * Set flow matcher mask or value.
11942 : : */
11943 : : static void
11944 : 0 : flow_dv_translate_item_sq(void *key,
11945 : : const struct rte_flow_item *item,
11946 : : uint32_t key_type)
11947 : : {
11948 : : const struct mlx5_rte_flow_item_sq *queue_m;
11949 : : const struct mlx5_rte_flow_item_sq *queue_v;
11950 : 0 : const struct mlx5_rte_flow_item_sq queue_mask = {
11951 : : .queue = UINT32_MAX,
11952 : : };
11953 : : void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
11954 : : uint32_t queue;
11955 : :
11956 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, queue_v, queue_m, &queue_mask);
# # # # ]
11957 [ # # ]: 0 : if (!queue_m || !queue_v)
11958 : 0 : return;
11959 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_V) {
11960 : 0 : queue = queue_v->queue;
11961 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_SW_V)
11962 : 0 : queue &= queue_m->queue;
11963 : : } else {
11964 : 0 : queue = queue_m->queue;
11965 : : }
11966 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, source_sqn, queue);
11967 : : }
11968 : :
11969 : : /**
11970 : : * Set the hash fields according to the @p flow information.
11971 : : *
11972 : : * @param[in] item_flags
11973 : : * The match pattern item flags.
11974 : : * @param[in] rss_desc
11975 : : * Pointer to the mlx5_flow_rss_desc.
11976 : : * @param[out] hash_fields
11977 : : * Pointer to the RSS hash fields.
11978 : : */
11979 : : void
11980 : 0 : flow_dv_hashfields_set(uint64_t item_flags,
11981 : : struct mlx5_flow_rss_desc *rss_desc,
11982 : : uint64_t *hash_fields)
11983 : : {
11984 : : uint64_t items = item_flags;
11985 : : uint64_t fields = 0;
11986 : : int rss_inner = 0;
11987 [ # # ]: 0 : uint64_t rss_types = rte_eth_rss_hf_refine(rss_desc->types);
11988 : :
11989 : : *hash_fields = 0;
11990 : : #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
11991 [ # # ]: 0 : if (rss_desc->level >= 2)
11992 : : rss_inner = 1;
11993 : : #endif
11994 [ # # # # ]: 0 : if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L3_IPV4)) ||
11995 [ # # ]: 0 : (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L3_IPV4))) {
11996 [ # # ]: 0 : if (rss_types & MLX5_IPV4_LAYER_TYPES) {
11997 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_L3_SRC_ONLY)
11998 : : fields |= IBV_RX_HASH_SRC_IPV4;
11999 [ # # ]: 0 : else if (rss_types & RTE_ETH_RSS_L3_DST_ONLY)
12000 : : fields |= IBV_RX_HASH_DST_IPV4;
12001 : : else
12002 : : fields |= MLX5_IPV4_IBV_RX_HASH;
12003 : : }
12004 [ # # # # : 0 : } else if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L3_IPV6)) ||
# # ]
12005 [ # # ]: 0 : (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L3_IPV6))) {
12006 [ # # ]: 0 : if (rss_types & MLX5_IPV6_LAYER_TYPES) {
12007 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_L3_SRC_ONLY)
12008 : : fields |= IBV_RX_HASH_SRC_IPV6;
12009 [ # # ]: 0 : else if (rss_types & RTE_ETH_RSS_L3_DST_ONLY)
12010 : : fields |= IBV_RX_HASH_DST_IPV6;
12011 : : else
12012 : : fields |= MLX5_IPV6_IBV_RX_HASH;
12013 : : }
12014 : : }
12015 [ # # ]: 0 : if (items & MLX5_FLOW_ITEM_ESP) {
12016 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_ESP)
12017 : 0 : fields |= IBV_RX_HASH_IPSEC_SPI;
12018 : : }
12019 [ # # ]: 0 : if ((fields & ~IBV_RX_HASH_IPSEC_SPI) == 0) {
12020 : 0 : *hash_fields = fields;
12021 : : /*
12022 : : * There is no match between the RSS types and the
12023 : : * L3 protocol (IPv4/IPv6) defined in the flow rule.
12024 : : */
12025 : 0 : return;
12026 : : }
12027 [ # # # # : 0 : if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L4_UDP)) ||
# # ]
12028 [ # # ]: 0 : (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L4_UDP))) {
12029 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_UDP) {
12030 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_L4_SRC_ONLY)
12031 : 0 : fields |= IBV_RX_HASH_SRC_PORT_UDP;
12032 [ # # ]: 0 : else if (rss_types & RTE_ETH_RSS_L4_DST_ONLY)
12033 : 0 : fields |= IBV_RX_HASH_DST_PORT_UDP;
12034 : : else
12035 : 0 : fields |= MLX5_UDP_IBV_RX_HASH;
12036 : : }
12037 [ # # # # : 0 : } else if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L4_TCP)) ||
# # ]
12038 [ # # ]: 0 : (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L4_TCP))) {
12039 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_TCP) {
12040 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_L4_SRC_ONLY)
12041 : 0 : fields |= IBV_RX_HASH_SRC_PORT_TCP;
12042 [ # # ]: 0 : else if (rss_types & RTE_ETH_RSS_L4_DST_ONLY)
12043 : 0 : fields |= IBV_RX_HASH_DST_PORT_TCP;
12044 : : else
12045 : 0 : fields |= MLX5_TCP_IBV_RX_HASH;
12046 : : }
12047 : : }
12048 [ # # ]: 0 : if (rss_inner)
12049 : 0 : fields |= IBV_RX_HASH_INNER;
12050 : 0 : *hash_fields = fields;
12051 : : }
12052 : :
12053 : : /**
12054 : : * Prepare an Rx Hash queue.
12055 : : *
12056 : : * @param dev
12057 : : * Pointer to Ethernet device.
12058 : : * @param[in] dev_flow
12059 : : * Pointer to the mlx5_flow.
12060 : : * @param[in] rss_desc
12061 : : * Pointer to the mlx5_flow_rss_desc.
12062 : : * @param[out] hrxq_idx
12063 : : * Hash Rx queue index.
12064 : : *
12065 : : * @return
12066 : : * The Verbs/DevX object initialised, NULL otherwise and rte_errno is set.
12067 : : */
12068 : : static struct mlx5_hrxq *
12069 : 0 : flow_dv_hrxq_prepare(struct rte_eth_dev *dev,
12070 : : struct mlx5_flow *dev_flow,
12071 : : struct mlx5_flow_rss_desc *rss_desc,
12072 : : uint32_t *hrxq_idx)
12073 : : {
12074 : 0 : struct mlx5_flow_handle *dh = dev_flow->handle;
12075 : 0 : uint32_t shared_rss = rss_desc->shared_rss;
12076 : : struct mlx5_hrxq *hrxq;
12077 : :
12078 : : MLX5_ASSERT(rss_desc->queue_num);
12079 : 0 : rss_desc->symmetric_hash_function = dev_flow->symmetric_hash_function;
12080 : 0 : rss_desc->key_len = MLX5_RSS_HASH_KEY_LEN;
12081 : 0 : rss_desc->hash_fields = dev_flow->hash_fields;
12082 : 0 : rss_desc->tunnel = !!(dh->layers & MLX5_FLOW_LAYER_TUNNEL);
12083 : 0 : rss_desc->shared_rss = 0;
12084 [ # # ]: 0 : if (rss_desc->hash_fields == 0)
12085 : 0 : rss_desc->queue_num = 1;
12086 : 0 : hrxq = mlx5_hrxq_get(dev, rss_desc);
12087 [ # # ]: 0 : *hrxq_idx = hrxq ? hrxq->idx : 0;
12088 : 0 : rss_desc->shared_rss = shared_rss;
12089 : 0 : return hrxq;
12090 : : }
12091 : :
12092 : : /**
12093 : : * Release sample sub action resource.
12094 : : *
12095 : : * @param[in, out] dev
12096 : : * Pointer to rte_eth_dev structure.
12097 : : * @param[in] act_res
12098 : : * Pointer to sample sub action resource.
12099 : : */
12100 : : static void
12101 : 0 : flow_dv_sample_sub_actions_release(struct rte_eth_dev *dev,
12102 : : struct mlx5_flow_sub_actions_idx *act_res)
12103 : : {
12104 [ # # ]: 0 : if (act_res->rix_hrxq) {
12105 : 0 : mlx5_hrxq_release(dev, act_res->rix_hrxq);
12106 : 0 : act_res->rix_hrxq = 0;
12107 : : }
12108 [ # # ]: 0 : if (act_res->rix_encap_decap) {
12109 : 0 : flow_dv_encap_decap_resource_release(dev,
12110 : : act_res->rix_encap_decap);
12111 : 0 : act_res->rix_encap_decap = 0;
12112 : : }
12113 [ # # ]: 0 : if (act_res->rix_port_id_action) {
12114 : 0 : flow_dv_port_id_action_resource_release(dev,
12115 : : act_res->rix_port_id_action);
12116 : 0 : act_res->rix_port_id_action = 0;
12117 : : }
12118 [ # # ]: 0 : if (act_res->rix_tag) {
12119 : 0 : flow_dv_tag_release(dev, act_res->rix_tag);
12120 : 0 : act_res->rix_tag = 0;
12121 : : }
12122 [ # # ]: 0 : if (act_res->rix_jump) {
12123 : 0 : flow_dv_jump_tbl_resource_release(dev, act_res->rix_jump);
12124 : 0 : act_res->rix_jump = 0;
12125 : : }
12126 : 0 : }
12127 : :
12128 : : int
12129 : 0 : flow_dv_sample_match_cb(void *tool_ctx __rte_unused,
12130 : : struct mlx5_list_entry *entry, void *cb_ctx)
12131 : : {
12132 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
12133 : 0 : struct rte_eth_dev *dev = ctx->dev;
12134 : 0 : struct mlx5_flow_dv_sample_resource *ctx_resource = ctx->data;
12135 : : struct mlx5_flow_dv_sample_resource *resource = container_of(entry,
12136 : : typeof(*resource),
12137 : : entry);
12138 : :
12139 [ # # ]: 0 : if (ctx_resource->ratio == resource->ratio &&
12140 [ # # ]: 0 : ctx_resource->ft_type == resource->ft_type &&
12141 [ # # ]: 0 : ctx_resource->ft_id == resource->ft_id &&
12142 [ # # ]: 0 : ctx_resource->set_action == resource->set_action &&
12143 : 0 : !memcmp((void *)&ctx_resource->sample_act,
12144 [ # # ]: 0 : (void *)&resource->sample_act,
12145 : : sizeof(struct mlx5_flow_sub_actions_list))) {
12146 : : /*
12147 : : * Existing sample action should release the prepared
12148 : : * sub-actions reference counter.
12149 : : */
12150 : 0 : flow_dv_sample_sub_actions_release(dev,
12151 : : &ctx_resource->sample_idx);
12152 : 0 : return 0;
12153 : : }
12154 : : return 1;
12155 : : }
12156 : :
12157 : : struct mlx5_list_entry *
12158 : 0 : flow_dv_sample_create_cb(void *tool_ctx __rte_unused, void *cb_ctx)
12159 : : {
12160 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
12161 : 0 : struct rte_eth_dev *dev = ctx->dev;
12162 : 0 : struct mlx5_flow_dv_sample_resource *ctx_resource = ctx->data;
12163 : 0 : void **sample_dv_actions = ctx_resource->sub_actions;
12164 : : struct mlx5_flow_dv_sample_resource *resource;
12165 : : struct mlx5dv_dr_flow_sampler_attr sampler_attr;
12166 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12167 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
12168 : : struct mlx5_flow_tbl_resource *tbl;
12169 : 0 : uint32_t idx = 0;
12170 : : const uint32_t next_ft_step = 1;
12171 : 0 : uint32_t next_ft_id = ctx_resource->ft_id + next_ft_step;
12172 : : uint8_t is_egress = 0;
12173 : : uint8_t is_transfer = 0;
12174 : 0 : struct rte_flow_error *error = ctx->error;
12175 : :
12176 : : /* Register new sample resource. */
12177 : 0 : resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_SAMPLE], &idx);
12178 [ # # ]: 0 : if (!resource) {
12179 : 0 : rte_flow_error_set(error, ENOMEM,
12180 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12181 : : NULL,
12182 : : "cannot allocate resource memory");
12183 : 0 : return NULL;
12184 : : }
12185 : 0 : *resource = *ctx_resource;
12186 : : /* Create normal path table level */
12187 [ # # ]: 0 : if (ctx_resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
12188 : : is_transfer = 1;
12189 [ # # ]: 0 : else if (ctx_resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_TX)
12190 : : is_egress = 1;
12191 : 0 : tbl = flow_dv_tbl_resource_get(dev, next_ft_id,
12192 : : is_egress, is_transfer,
12193 : : true, NULL, 0, 0, 0, error);
12194 [ # # ]: 0 : if (!tbl) {
12195 : 0 : rte_flow_error_set(error, ENOMEM,
12196 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12197 : : NULL,
12198 : : "fail to create normal path table "
12199 : : "for sample");
12200 : 0 : goto error;
12201 : : }
12202 : 0 : resource->normal_path_tbl = tbl;
12203 [ # # ]: 0 : if (ctx_resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB) {
12204 [ # # ]: 0 : if (!sh->default_miss_action) {
12205 : 0 : rte_flow_error_set(error, ENOMEM,
12206 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12207 : : NULL,
12208 : : "default miss action was not "
12209 : : "created");
12210 : 0 : goto error;
12211 : : }
12212 : 0 : sample_dv_actions[ctx_resource->sample_act.actions_num++] =
12213 : : sh->default_miss_action;
12214 : : }
12215 : : /* Create a DR sample action */
12216 : 0 : sampler_attr.sample_ratio = resource->ratio;
12217 : 0 : sampler_attr.default_next_table = tbl->obj;
12218 : 0 : sampler_attr.num_sample_actions = ctx_resource->sample_act.actions_num;
12219 : 0 : sampler_attr.sample_actions = (struct mlx5dv_dr_action **)
12220 : : &sample_dv_actions[0];
12221 : 0 : sampler_attr.action = resource->set_action;
12222 : : if (mlx5_os_flow_dr_create_flow_action_sampler
12223 : : (&sampler_attr, &resource->verbs_action)) {
12224 : 0 : rte_flow_error_set(error, ENOMEM,
12225 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12226 : : NULL, "cannot create sample action");
12227 : 0 : goto error;
12228 : : }
12229 : 0 : resource->idx = idx;
12230 : 0 : resource->dev = dev;
12231 : 0 : return &resource->entry;
12232 : 0 : error:
12233 [ # # ]: 0 : if (resource->ft_type != MLX5DV_FLOW_TABLE_TYPE_FDB)
12234 : 0 : flow_dv_sample_sub_actions_release(dev,
12235 : : &resource->sample_idx);
12236 [ # # ]: 0 : if (resource->normal_path_tbl)
12237 : 0 : flow_dv_tbl_resource_release(MLX5_SH(dev),
12238 : : resource->normal_path_tbl);
12239 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_SAMPLE], idx);
12240 : 0 : return NULL;
12241 : :
12242 : : }
12243 : :
12244 : : struct mlx5_list_entry *
12245 : 0 : flow_dv_sample_clone_cb(void *tool_ctx __rte_unused,
12246 : : struct mlx5_list_entry *entry __rte_unused,
12247 : : void *cb_ctx)
12248 : : {
12249 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
12250 : 0 : struct rte_eth_dev *dev = ctx->dev;
12251 : : struct mlx5_flow_dv_sample_resource *resource;
12252 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12253 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
12254 : 0 : uint32_t idx = 0;
12255 : :
12256 : 0 : resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_SAMPLE], &idx);
12257 [ # # ]: 0 : if (!resource) {
12258 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
12259 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12260 : : NULL,
12261 : : "cannot allocate resource memory");
12262 : 0 : return NULL;
12263 : : }
12264 : : memcpy(resource, entry, sizeof(*resource));
12265 : 0 : resource->idx = idx;
12266 : 0 : resource->dev = dev;
12267 : 0 : return &resource->entry;
12268 : : }
12269 : :
12270 : : void
12271 : 0 : flow_dv_sample_clone_free_cb(void *tool_ctx __rte_unused,
12272 : : struct mlx5_list_entry *entry)
12273 : : {
12274 : : struct mlx5_flow_dv_sample_resource *resource =
12275 : : container_of(entry, typeof(*resource), entry);
12276 : 0 : struct rte_eth_dev *dev = resource->dev;
12277 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12278 : :
12279 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_SAMPLE], resource->idx);
12280 : 0 : }
12281 : :
12282 : : /**
12283 : : * Find existing sample resource or create and register a new one.
12284 : : *
12285 : : * @param[in, out] dev
12286 : : * Pointer to rte_eth_dev structure.
12287 : : * @param[in] ref
12288 : : * Pointer to sample resource reference.
12289 : : * @parm[in, out] dev_flow
12290 : : * Pointer to the dev_flow.
12291 : : * @param[out] error
12292 : : * pointer to error structure.
12293 : : *
12294 : : * @return
12295 : : * 0 on success otherwise -errno and errno is set.
12296 : : */
12297 : : static int
12298 : 0 : flow_dv_sample_resource_register(struct rte_eth_dev *dev,
12299 : : struct mlx5_flow_dv_sample_resource *ref,
12300 : : struct mlx5_flow *dev_flow,
12301 : : struct rte_flow_error *error)
12302 : : {
12303 : : struct mlx5_flow_dv_sample_resource *resource;
12304 : : struct mlx5_list_entry *entry;
12305 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12306 : 0 : struct mlx5_flow_cb_ctx ctx = {
12307 : : .dev = dev,
12308 : : .error = error,
12309 : : .data = ref,
12310 : : };
12311 : :
12312 : 0 : entry = mlx5_list_register(priv->sh->sample_action_list, &ctx);
12313 [ # # ]: 0 : if (!entry)
12314 : 0 : return -rte_errno;
12315 : : resource = container_of(entry, typeof(*resource), entry);
12316 : 0 : dev_flow->handle->dvh.rix_sample = resource->idx;
12317 : 0 : dev_flow->dv.sample_res = resource;
12318 : 0 : return 0;
12319 : : }
12320 : :
12321 : : int
12322 : 0 : flow_dv_dest_array_match_cb(void *tool_ctx __rte_unused,
12323 : : struct mlx5_list_entry *entry, void *cb_ctx)
12324 : : {
12325 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
12326 : 0 : struct mlx5_flow_dv_dest_array_resource *ctx_resource = ctx->data;
12327 : 0 : struct rte_eth_dev *dev = ctx->dev;
12328 : : struct mlx5_flow_dv_dest_array_resource *resource =
12329 : : container_of(entry, typeof(*resource), entry);
12330 : : uint32_t idx = 0;
12331 : :
12332 [ # # ]: 0 : if (ctx_resource->num_of_dest == resource->num_of_dest &&
12333 : 0 : ctx_resource->ft_type == resource->ft_type &&
12334 : 0 : !memcmp((void *)resource->sample_act,
12335 : 0 : (void *)ctx_resource->sample_act,
12336 [ # # ]: 0 : (ctx_resource->num_of_dest *
12337 : : sizeof(struct mlx5_flow_sub_actions_list)))) {
12338 : : /*
12339 : : * Existing sample action should release the prepared
12340 : : * sub-actions reference counter.
12341 : : */
12342 [ # # ]: 0 : for (idx = 0; idx < ctx_resource->num_of_dest; idx++)
12343 : 0 : flow_dv_sample_sub_actions_release(dev,
12344 : : &ctx_resource->sample_idx[idx]);
12345 : : return 0;
12346 : : }
12347 : : return 1;
12348 : : }
12349 : :
12350 : : struct mlx5_list_entry *
12351 : 0 : flow_dv_dest_array_create_cb(void *tool_ctx __rte_unused, void *cb_ctx)
12352 : : {
12353 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
12354 : 0 : struct rte_eth_dev *dev = ctx->dev;
12355 : : struct mlx5_flow_dv_dest_array_resource *resource;
12356 : 0 : struct mlx5_flow_dv_dest_array_resource *ctx_resource = ctx->data;
12357 : 0 : struct mlx5dv_dr_action_dest_attr *dest_attr[MLX5_MAX_DEST_NUM] = { 0 };
12358 : : struct mlx5dv_dr_action_dest_reformat dest_reformat[MLX5_MAX_DEST_NUM];
12359 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12360 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
12361 : : struct mlx5_flow_sub_actions_list *sample_act;
12362 : : struct mlx5dv_dr_domain *domain;
12363 : 0 : uint32_t idx = 0, res_idx = 0;
12364 : 0 : struct rte_flow_error *error = ctx->error;
12365 : : uint64_t action_flags;
12366 : : int ret;
12367 : :
12368 : : /* Register new destination array resource. */
12369 : 0 : resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_DEST_ARRAY],
12370 : : &res_idx);
12371 [ # # ]: 0 : if (!resource) {
12372 : 0 : rte_flow_error_set(error, ENOMEM,
12373 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12374 : : NULL,
12375 : : "cannot allocate resource memory");
12376 : 0 : return NULL;
12377 : : }
12378 : 0 : *resource = *ctx_resource;
12379 [ # # ]: 0 : if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
12380 : 0 : domain = sh->fdb_domain;
12381 [ # # ]: 0 : else if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_RX)
12382 : 0 : domain = sh->rx_domain;
12383 : : else
12384 : 0 : domain = sh->tx_domain;
12385 [ # # ]: 0 : for (idx = 0; idx < ctx_resource->num_of_dest; idx++) {
12386 : 0 : dest_attr[idx] = (struct mlx5dv_dr_action_dest_attr *)
12387 : 0 : mlx5_malloc(MLX5_MEM_ZERO,
12388 : : sizeof(struct mlx5dv_dr_action_dest_attr),
12389 : : 0, SOCKET_ID_ANY);
12390 [ # # ]: 0 : if (!dest_attr[idx]) {
12391 : 0 : rte_flow_error_set(error, ENOMEM,
12392 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12393 : : NULL,
12394 : : "cannot allocate resource memory");
12395 : 0 : goto error;
12396 : : }
12397 : 0 : dest_attr[idx]->type = MLX5DV_DR_ACTION_DEST;
12398 : : sample_act = &ctx_resource->sample_act[idx];
12399 : 0 : action_flags = sample_act->action_flags;
12400 [ # # # # : 0 : switch (action_flags) {
# ]
12401 : 0 : case MLX5_FLOW_ACTION_QUEUE:
12402 : 0 : dest_attr[idx]->dest = sample_act->dr_queue_action;
12403 : 0 : break;
12404 : 0 : case (MLX5_FLOW_ACTION_PORT_ID | MLX5_FLOW_ACTION_ENCAP):
12405 : 0 : dest_attr[idx]->type = MLX5DV_DR_ACTION_DEST_REFORMAT;
12406 : 0 : dest_attr[idx]->dest_reformat = &dest_reformat[idx];
12407 : 0 : dest_attr[idx]->dest_reformat->reformat =
12408 : 0 : sample_act->dr_encap_action;
12409 : 0 : dest_attr[idx]->dest_reformat->dest =
12410 : 0 : sample_act->dr_port_id_action;
12411 : 0 : break;
12412 : 0 : case MLX5_FLOW_ACTION_PORT_ID:
12413 : 0 : dest_attr[idx]->dest = sample_act->dr_port_id_action;
12414 : 0 : break;
12415 : 0 : case MLX5_FLOW_ACTION_JUMP:
12416 : 0 : dest_attr[idx]->dest = sample_act->dr_jump_action;
12417 : 0 : break;
12418 : 0 : default:
12419 : 0 : rte_flow_error_set(error, EINVAL,
12420 : : RTE_FLOW_ERROR_TYPE_ACTION,
12421 : : NULL,
12422 : : "unsupported actions type");
12423 : 0 : goto error;
12424 : : }
12425 : : }
12426 : : /* create a dest array action */
12427 : 0 : ret = mlx5_os_flow_dr_create_flow_action_dest_array
12428 : : (domain,
12429 : 0 : resource->num_of_dest,
12430 : : dest_attr,
12431 : : &resource->action);
12432 : : if (ret) {
12433 : 0 : rte_flow_error_set(error, ENOMEM,
12434 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12435 : : NULL,
12436 : : "cannot create destination array action");
12437 : 0 : goto error;
12438 : : }
12439 : 0 : resource->idx = res_idx;
12440 : 0 : resource->dev = dev;
12441 [ # # ]: 0 : for (idx = 0; idx < ctx_resource->num_of_dest; idx++)
12442 : 0 : mlx5_free(dest_attr[idx]);
12443 : 0 : return &resource->entry;
12444 : : error:
12445 [ # # ]: 0 : for (idx = 0; idx < ctx_resource->num_of_dest; idx++) {
12446 : 0 : flow_dv_sample_sub_actions_release(dev,
12447 : : &resource->sample_idx[idx]);
12448 [ # # ]: 0 : if (dest_attr[idx])
12449 : 0 : mlx5_free(dest_attr[idx]);
12450 : : }
12451 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_DEST_ARRAY], res_idx);
12452 : 0 : return NULL;
12453 : : }
12454 : :
12455 : : struct mlx5_list_entry *
12456 : 0 : flow_dv_dest_array_clone_cb(void *tool_ctx __rte_unused,
12457 : : struct mlx5_list_entry *entry __rte_unused,
12458 : : void *cb_ctx)
12459 : : {
12460 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
12461 : 0 : struct rte_eth_dev *dev = ctx->dev;
12462 : : struct mlx5_flow_dv_dest_array_resource *resource;
12463 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12464 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
12465 : 0 : uint32_t res_idx = 0;
12466 : 0 : struct rte_flow_error *error = ctx->error;
12467 : :
12468 : 0 : resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_DEST_ARRAY],
12469 : : &res_idx);
12470 [ # # ]: 0 : if (!resource) {
12471 : 0 : rte_flow_error_set(error, ENOMEM,
12472 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12473 : : NULL,
12474 : : "cannot allocate dest-array memory");
12475 : 0 : return NULL;
12476 : : }
12477 : : memcpy(resource, entry, sizeof(*resource));
12478 : 0 : resource->idx = res_idx;
12479 : 0 : resource->dev = dev;
12480 : 0 : return &resource->entry;
12481 : : }
12482 : :
12483 : : void
12484 : 0 : flow_dv_dest_array_clone_free_cb(void *tool_ctx __rte_unused,
12485 : : struct mlx5_list_entry *entry)
12486 : : {
12487 : : struct mlx5_flow_dv_dest_array_resource *resource =
12488 : : container_of(entry, typeof(*resource), entry);
12489 : 0 : struct rte_eth_dev *dev = resource->dev;
12490 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12491 : :
12492 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_DEST_ARRAY], resource->idx);
12493 : 0 : }
12494 : :
12495 : : /**
12496 : : * Find existing destination array resource or create and register a new one.
12497 : : *
12498 : : * @param[in, out] dev
12499 : : * Pointer to rte_eth_dev structure.
12500 : : * @param[in] ref
12501 : : * Pointer to destination array resource reference.
12502 : : * @parm[in, out] dev_flow
12503 : : * Pointer to the dev_flow.
12504 : : * @param[out] error
12505 : : * pointer to error structure.
12506 : : *
12507 : : * @return
12508 : : * 0 on success otherwise -errno and errno is set.
12509 : : */
12510 : : static int
12511 : 0 : flow_dv_dest_array_resource_register(struct rte_eth_dev *dev,
12512 : : struct mlx5_flow_dv_dest_array_resource *ref,
12513 : : struct mlx5_flow *dev_flow,
12514 : : struct rte_flow_error *error)
12515 : : {
12516 : : struct mlx5_flow_dv_dest_array_resource *resource;
12517 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12518 : : struct mlx5_list_entry *entry;
12519 : 0 : struct mlx5_flow_cb_ctx ctx = {
12520 : : .dev = dev,
12521 : : .error = error,
12522 : : .data = ref,
12523 : : };
12524 : :
12525 : 0 : entry = mlx5_list_register(priv->sh->dest_array_list, &ctx);
12526 [ # # ]: 0 : if (!entry)
12527 : 0 : return -rte_errno;
12528 : : resource = container_of(entry, typeof(*resource), entry);
12529 : 0 : dev_flow->handle->dvh.rix_dest_array = resource->idx;
12530 : 0 : dev_flow->dv.dest_array_res = resource;
12531 : 0 : return 0;
12532 : : }
12533 : :
12534 : : /**
12535 : : * Convert Sample action to DV specification.
12536 : : *
12537 : : * @param[in] dev
12538 : : * Pointer to rte_eth_dev structure.
12539 : : * @param[in] action
12540 : : * Pointer to sample action structure.
12541 : : * @param[in, out] dev_flow
12542 : : * Pointer to the mlx5_flow.
12543 : : * @param[in] attr
12544 : : * Pointer to the flow attributes.
12545 : : * @param[in, out] num_of_dest
12546 : : * Pointer to the num of destination.
12547 : : * @param[in, out] sample_actions
12548 : : * Pointer to sample actions list.
12549 : : * @param[in, out] res
12550 : : * Pointer to sample resource.
12551 : : * @param[out] error
12552 : : * Pointer to the error structure.
12553 : : *
12554 : : * @return
12555 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
12556 : : */
12557 : : static int
12558 : 0 : flow_dv_translate_action_sample(struct rte_eth_dev *dev,
12559 : : const struct rte_flow_action_sample *action,
12560 : : struct mlx5_flow *dev_flow,
12561 : : const struct rte_flow_attr *attr,
12562 : : uint32_t *num_of_dest,
12563 : : void **sample_actions,
12564 : : struct mlx5_flow_dv_sample_resource *res,
12565 : : struct rte_flow_error *error)
12566 : : {
12567 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12568 : : const struct rte_flow_action *sub_actions;
12569 : : struct mlx5_flow_sub_actions_list *sample_act;
12570 : : struct mlx5_flow_sub_actions_idx *sample_idx;
12571 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
12572 : 0 : struct rte_flow *flow = dev_flow->flow;
12573 : : struct mlx5_flow_rss_desc *rss_desc;
12574 : : uint64_t action_flags = 0;
12575 : :
12576 : : MLX5_ASSERT(wks);
12577 : 0 : rss_desc = &wks->rss_desc;
12578 : : sample_act = &res->sample_act;
12579 : : sample_idx = &res->sample_idx;
12580 : 0 : res->ratio = action->ratio;
12581 : 0 : sub_actions = action->actions;
12582 [ # # ]: 0 : for (; sub_actions->type != RTE_FLOW_ACTION_TYPE_END; sub_actions++) {
12583 : : int type = sub_actions->type;
12584 : : uint32_t pre_rix = 0;
12585 : : void *pre_r;
12586 [ # # # # : 0 : switch (type) {
# # # ]
12587 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
12588 : : {
12589 : : const struct rte_flow_action_queue *queue;
12590 : : struct mlx5_hrxq *hrxq;
12591 : : uint32_t hrxq_idx;
12592 : :
12593 : 0 : queue = sub_actions->conf;
12594 : 0 : rss_desc->queue_num = 1;
12595 : 0 : rss_desc->queue[0] = queue->index;
12596 : 0 : hrxq = flow_dv_hrxq_prepare(dev, dev_flow,
12597 : : rss_desc, &hrxq_idx);
12598 [ # # ]: 0 : if (!hrxq)
12599 : 0 : return rte_flow_error_set
12600 : : (error, rte_errno,
12601 : : RTE_FLOW_ERROR_TYPE_ACTION,
12602 : : NULL,
12603 : : "cannot create fate queue");
12604 : 0 : sample_act->dr_queue_action = hrxq->action;
12605 : 0 : sample_idx->rix_hrxq = hrxq_idx;
12606 : 0 : sample_actions[sample_act->actions_num++] =
12607 : : hrxq->action;
12608 : 0 : (*num_of_dest)++;
12609 : 0 : action_flags |= MLX5_FLOW_ACTION_QUEUE;
12610 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_MARK)
12611 : 0 : dev_flow->handle->rix_hrxq = hrxq_idx;
12612 : 0 : dev_flow->handle->fate_action =
12613 : : MLX5_FLOW_FATE_QUEUE;
12614 : 0 : break;
12615 : : }
12616 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
12617 : : {
12618 : : struct mlx5_hrxq *hrxq;
12619 : : uint32_t hrxq_idx;
12620 : : const struct rte_flow_action_rss *rss;
12621 : : const uint8_t *rss_key;
12622 : :
12623 : 0 : rss = sub_actions->conf;
12624 : 0 : rss_desc->symmetric_hash_function =
12625 : 0 : MLX5_RSS_IS_SYMM(rss->func);
12626 : 0 : memcpy(rss_desc->queue, rss->queue,
12627 [ # # ]: 0 : rss->queue_num * sizeof(uint16_t));
12628 : 0 : rss_desc->queue_num = rss->queue_num;
12629 : : /* NULL RSS key indicates default RSS key. */
12630 [ # # ]: 0 : rss_key = !rss->key ? rss_hash_default_key : rss->key;
12631 : 0 : memcpy(rss_desc->key, rss_key, MLX5_RSS_HASH_KEY_LEN);
12632 : : /*
12633 : : * rss->level and rss.types should be set in advance
12634 : : * when expanding items for RSS.
12635 : : */
12636 : 0 : flow_dv_hashfields_set(dev_flow->handle->layers,
12637 : : rss_desc,
12638 : : &dev_flow->hash_fields);
12639 : 0 : hrxq = flow_dv_hrxq_prepare(dev, dev_flow,
12640 : : rss_desc, &hrxq_idx);
12641 [ # # ]: 0 : if (!hrxq)
12642 : 0 : return rte_flow_error_set
12643 : : (error, rte_errno,
12644 : : RTE_FLOW_ERROR_TYPE_ACTION,
12645 : : NULL,
12646 : : "cannot create fate queue");
12647 : 0 : sample_act->dr_queue_action = hrxq->action;
12648 : 0 : sample_idx->rix_hrxq = hrxq_idx;
12649 : 0 : sample_actions[sample_act->actions_num++] =
12650 : : hrxq->action;
12651 : 0 : (*num_of_dest)++;
12652 : 0 : action_flags |= MLX5_FLOW_ACTION_RSS;
12653 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_MARK)
12654 : 0 : dev_flow->handle->rix_hrxq = hrxq_idx;
12655 : 0 : dev_flow->handle->fate_action =
12656 : : MLX5_FLOW_FATE_QUEUE;
12657 : 0 : break;
12658 : : }
12659 : 0 : case RTE_FLOW_ACTION_TYPE_MARK:
12660 : : {
12661 : : uint32_t tag_be = mlx5_flow_mark_set
12662 : : (((const struct rte_flow_action_mark *)
12663 [ # # ]: 0 : (sub_actions->conf))->id);
12664 : :
12665 : 0 : wks->mark = 1;
12666 : 0 : pre_rix = dev_flow->handle->dvh.rix_tag;
12667 : : /* Save the mark resource before sample */
12668 : 0 : pre_r = dev_flow->dv.tag_resource;
12669 [ # # ]: 0 : if (flow_dv_tag_resource_register(dev, tag_be,
12670 : : dev_flow, error))
12671 : 0 : return -rte_errno;
12672 : : MLX5_ASSERT(dev_flow->dv.tag_resource);
12673 : 0 : sample_act->dr_tag_action =
12674 : 0 : dev_flow->dv.tag_resource->action;
12675 : 0 : sample_idx->rix_tag =
12676 : 0 : dev_flow->handle->dvh.rix_tag;
12677 : 0 : sample_actions[sample_act->actions_num++] =
12678 : : sample_act->dr_tag_action;
12679 : : /* Recover the mark resource after sample */
12680 : 0 : dev_flow->dv.tag_resource = pre_r;
12681 : 0 : dev_flow->handle->dvh.rix_tag = pre_rix;
12682 : 0 : action_flags |= MLX5_FLOW_ACTION_MARK;
12683 : 0 : break;
12684 : : }
12685 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
12686 : : {
12687 [ # # ]: 0 : if (!flow->counter) {
12688 : 0 : flow->counter =
12689 : 0 : flow_dv_translate_create_counter(dev,
12690 : 0 : dev_flow, sub_actions->conf,
12691 : : 0);
12692 [ # # ]: 0 : if (!flow->counter)
12693 : 0 : return rte_flow_error_set
12694 : : (error, rte_errno,
12695 : : RTE_FLOW_ERROR_TYPE_ACTION,
12696 : : NULL,
12697 : : "cannot create counter"
12698 : : " object.");
12699 : : }
12700 : 0 : sample_act->dr_cnt_action =
12701 [ # # ]: 0 : (flow_dv_counter_get_by_idx(dev,
12702 : 0 : flow->counter, NULL))->action;
12703 : 0 : sample_actions[sample_act->actions_num++] =
12704 : : sample_act->dr_cnt_action;
12705 : 0 : action_flags |= MLX5_FLOW_ACTION_COUNT;
12706 : 0 : break;
12707 : : }
12708 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_ID:
12709 : : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
12710 : : {
12711 : : struct mlx5_flow_dv_port_id_action_resource
12712 : : port_id_resource;
12713 : 0 : uint32_t port_id = 0;
12714 : :
12715 : : memset(&port_id_resource, 0, sizeof(port_id_resource));
12716 : : /* Save the port id resource before sample */
12717 : 0 : pre_rix = dev_flow->handle->rix_port_id_action;
12718 : 0 : pre_r = dev_flow->dv.port_id_action;
12719 [ # # ]: 0 : if (flow_dv_translate_action_port_id(dev, sub_actions,
12720 : : &port_id, error))
12721 : 0 : return -rte_errno;
12722 : 0 : port_id_resource.port_id = port_id;
12723 [ # # ]: 0 : if (flow_dv_port_id_action_resource_register
12724 : : (dev, &port_id_resource, dev_flow, error))
12725 : 0 : return -rte_errno;
12726 : 0 : sample_act->dr_port_id_action =
12727 : 0 : dev_flow->dv.port_id_action->action;
12728 : 0 : sample_idx->rix_port_id_action =
12729 : 0 : dev_flow->handle->rix_port_id_action;
12730 : 0 : sample_actions[sample_act->actions_num++] =
12731 : : sample_act->dr_port_id_action;
12732 : : /* Recover the port id resource after sample */
12733 : 0 : dev_flow->dv.port_id_action = pre_r;
12734 : 0 : dev_flow->handle->rix_port_id_action = pre_rix;
12735 : 0 : (*num_of_dest)++;
12736 : 0 : action_flags |= MLX5_FLOW_ACTION_PORT_ID;
12737 : 0 : break;
12738 : : }
12739 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
12740 : : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
12741 : : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
12742 : : /* Save the encap resource before sample */
12743 : 0 : pre_rix = dev_flow->handle->dvh.rix_encap_decap;
12744 : 0 : pre_r = dev_flow->dv.encap_decap;
12745 [ # # ]: 0 : if (flow_dv_create_action_l2_encap(dev, sub_actions,
12746 : : dev_flow,
12747 : 0 : attr->transfer,
12748 : : error))
12749 : 0 : return -rte_errno;
12750 : 0 : sample_act->dr_encap_action =
12751 : 0 : dev_flow->dv.encap_decap->action;
12752 : 0 : sample_idx->rix_encap_decap =
12753 : 0 : dev_flow->handle->dvh.rix_encap_decap;
12754 : 0 : sample_actions[sample_act->actions_num++] =
12755 : : sample_act->dr_encap_action;
12756 : : /* Recover the encap resource after sample */
12757 : 0 : dev_flow->dv.encap_decap = pre_r;
12758 : 0 : dev_flow->handle->dvh.rix_encap_decap = pre_rix;
12759 : 0 : action_flags |= MLX5_FLOW_ACTION_ENCAP;
12760 : 0 : break;
12761 : 0 : default:
12762 : 0 : return rte_flow_error_set(error, EINVAL,
12763 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12764 : : NULL,
12765 : : "Not support for sampler action");
12766 : : }
12767 : : }
12768 : 0 : sample_act->action_flags = action_flags;
12769 : 0 : res->ft_id = dev_flow->dv.group;
12770 [ # # ]: 0 : if (attr->transfer) {
12771 : : union {
12772 : : uint32_t action_in[MLX5_ST_SZ_DW(set_action_in)];
12773 : : uint64_t set_action;
12774 : : } action_ctx = { .set_action = 0 };
12775 : 0 : uint32_t vport_meta_tag = wks->vport_meta_tag ?
12776 [ # # ]: 0 : wks->vport_meta_tag :
12777 : : priv->vport_meta_tag;
12778 : :
12779 : 0 : res->ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
12780 : : MLX5_SET(set_action_in, action_ctx.action_in, action_type,
12781 : : MLX5_MODIFICATION_TYPE_SET);
12782 [ # # ]: 0 : MLX5_SET(set_action_in, action_ctx.action_in, field,
12783 : : MLX5_MODI_META_REG_C_0);
12784 : 0 : MLX5_SET(set_action_in, action_ctx.action_in, data,
12785 : : vport_meta_tag);
12786 : 0 : res->set_action = action_ctx.set_action;
12787 [ # # ]: 0 : } else if (attr->ingress) {
12788 : 0 : res->ft_type = MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
12789 : : } else {
12790 : 0 : res->ft_type = MLX5DV_FLOW_TABLE_TYPE_NIC_TX;
12791 : : }
12792 : : return 0;
12793 : : }
12794 : :
12795 : : static void *
12796 : 0 : flow_dv_translate_action_send_to_kernel(struct rte_eth_dev *dev,
12797 : : const struct rte_flow_attr *attr,
12798 : : struct rte_flow_error *error)
12799 : : {
12800 : : struct mlx5_flow_tbl_resource *tbl;
12801 : : struct mlx5_dev_ctx_shared *sh;
12802 : : uint32_t priority;
12803 : : void *action;
12804 : : int ft_type;
12805 : : int ret;
12806 : :
12807 : 0 : sh = MLX5_SH(dev);
12808 [ # # ]: 0 : ft_type = (attr->ingress) ? MLX5DR_TABLE_TYPE_NIC_RX :
12809 [ # # ]: 0 : ((attr->transfer) ? MLX5DR_TABLE_TYPE_FDB :
12810 : : MLX5DR_TABLE_TYPE_NIC_TX);
12811 [ # # ]: 0 : if (sh->send_to_kernel_action[ft_type].action)
12812 : : return sh->send_to_kernel_action[ft_type].action;
12813 : 0 : priority = mlx5_get_send_to_kernel_priority(dev);
12814 [ # # ]: 0 : if (priority == (uint32_t)-1) {
12815 : 0 : rte_flow_error_set(error, ENOTSUP,
12816 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
12817 : : "required priority is not available");
12818 : 0 : return NULL;
12819 : : }
12820 : 0 : tbl = flow_dv_tbl_resource_get(dev, 0, attr->egress, attr->transfer, false, NULL, 0, 0, 0,
12821 : : error);
12822 [ # # ]: 0 : if (!tbl) {
12823 : 0 : rte_flow_error_set(error, ENODATA,
12824 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
12825 : : "cannot find destination root table");
12826 : 0 : return NULL;
12827 : : }
12828 : 0 : ret = mlx5_flow_os_create_flow_action_send_to_kernel(tbl->obj,
12829 : : priority, &action);
12830 : : if (ret) {
12831 : 0 : rte_flow_error_set(error, ENOMEM,
12832 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
12833 : : "cannot create action");
12834 : 0 : goto err;
12835 : : }
12836 : : MLX5_ASSERT(action);
12837 : 0 : sh->send_to_kernel_action[ft_type].action = action;
12838 : 0 : sh->send_to_kernel_action[ft_type].tbl = tbl;
12839 : 0 : return action;
12840 : : err:
12841 : 0 : flow_dv_tbl_resource_release(sh, tbl);
12842 : 0 : return NULL;
12843 : : }
12844 : :
12845 : : /**
12846 : : * Convert Sample action to DV specification.
12847 : : *
12848 : : * @param[in] dev
12849 : : * Pointer to rte_eth_dev structure.
12850 : : * @param[in, out] dev_flow
12851 : : * Pointer to the mlx5_flow.
12852 : : * @param[in] num_of_dest
12853 : : * The num of destination.
12854 : : * @param[in, out] res
12855 : : * Pointer to sample resource.
12856 : : * @param[in, out] mdest_res
12857 : : * Pointer to destination array resource.
12858 : : * @param[in] sample_actions
12859 : : * Pointer to sample path actions list.
12860 : : * @param[in] action_flags
12861 : : * Holds the actions detected until now.
12862 : : * @param[out] error
12863 : : * Pointer to the error structure.
12864 : : *
12865 : : * @return
12866 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
12867 : : */
12868 : : static int
12869 : 0 : flow_dv_create_action_sample(struct rte_eth_dev *dev,
12870 : : struct mlx5_flow *dev_flow,
12871 : : uint32_t num_of_dest,
12872 : : struct mlx5_flow_dv_sample_resource *res,
12873 : : struct mlx5_flow_dv_dest_array_resource *mdest_res,
12874 : : void **sample_actions,
12875 : : uint64_t action_flags,
12876 : : struct rte_flow_error *error)
12877 : : {
12878 : : /* update normal path action resource into last index of array */
12879 : : uint32_t dest_index = MLX5_MAX_DEST_NUM - 1;
12880 : : struct mlx5_flow_sub_actions_list *sample_act =
12881 : : &mdest_res->sample_act[dest_index];
12882 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
12883 : : struct mlx5_flow_rss_desc *rss_desc;
12884 : : uint32_t normal_idx = 0;
12885 : : struct mlx5_hrxq *hrxq;
12886 : : uint32_t hrxq_idx;
12887 : :
12888 : : MLX5_ASSERT(wks);
12889 : 0 : rss_desc = &wks->rss_desc;
12890 [ # # ]: 0 : if (num_of_dest > 1) {
12891 [ # # ]: 0 : if (sample_act->action_flags & MLX5_FLOW_ACTION_QUEUE) {
12892 : : /* Handle QP action for mirroring */
12893 : 0 : hrxq = flow_dv_hrxq_prepare(dev, dev_flow,
12894 : : rss_desc, &hrxq_idx);
12895 [ # # ]: 0 : if (!hrxq)
12896 : 0 : return rte_flow_error_set
12897 : : (error, rte_errno,
12898 : : RTE_FLOW_ERROR_TYPE_ACTION,
12899 : : NULL,
12900 : : "cannot create rx queue");
12901 : : normal_idx++;
12902 : 0 : mdest_res->sample_idx[dest_index].rix_hrxq = hrxq_idx;
12903 : 0 : sample_act->dr_queue_action = hrxq->action;
12904 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_MARK)
12905 : 0 : dev_flow->handle->rix_hrxq = hrxq_idx;
12906 : 0 : dev_flow->handle->fate_action = MLX5_FLOW_FATE_QUEUE;
12907 : : }
12908 [ # # ]: 0 : if (sample_act->action_flags & MLX5_FLOW_ACTION_ENCAP) {
12909 : 0 : normal_idx++;
12910 : 0 : mdest_res->sample_idx[dest_index].rix_encap_decap =
12911 : 0 : dev_flow->handle->dvh.rix_encap_decap;
12912 : 0 : sample_act->dr_encap_action =
12913 : 0 : dev_flow->dv.encap_decap->action;
12914 : 0 : dev_flow->handle->dvh.rix_encap_decap = 0;
12915 : : }
12916 [ # # ]: 0 : if (sample_act->action_flags & MLX5_FLOW_ACTION_PORT_ID) {
12917 : 0 : normal_idx++;
12918 : 0 : mdest_res->sample_idx[dest_index].rix_port_id_action =
12919 : 0 : dev_flow->handle->rix_port_id_action;
12920 : 0 : sample_act->dr_port_id_action =
12921 : 0 : dev_flow->dv.port_id_action->action;
12922 : 0 : dev_flow->handle->rix_port_id_action = 0;
12923 : : }
12924 [ # # ]: 0 : if (sample_act->action_flags & MLX5_FLOW_ACTION_JUMP) {
12925 : 0 : normal_idx++;
12926 : 0 : mdest_res->sample_idx[dest_index].rix_jump =
12927 : 0 : dev_flow->handle->rix_jump;
12928 : 0 : sample_act->dr_jump_action =
12929 : 0 : dev_flow->dv.jump->action;
12930 : 0 : dev_flow->handle->rix_jump = 0;
12931 : : }
12932 : 0 : sample_act->actions_num = normal_idx;
12933 : : /* update sample action resource into first index of array */
12934 : 0 : mdest_res->ft_type = res->ft_type;
12935 : 0 : memcpy(&mdest_res->sample_idx[0], &res->sample_idx,
12936 : : sizeof(struct mlx5_flow_sub_actions_idx));
12937 : 0 : memcpy(&mdest_res->sample_act[0], &res->sample_act,
12938 : : sizeof(struct mlx5_flow_sub_actions_list));
12939 : 0 : mdest_res->num_of_dest = num_of_dest;
12940 [ # # ]: 0 : if (flow_dv_dest_array_resource_register(dev, mdest_res,
12941 : : dev_flow, error))
12942 : 0 : return rte_flow_error_set(error, EINVAL,
12943 : : RTE_FLOW_ERROR_TYPE_ACTION,
12944 : : NULL, "can't create sample "
12945 : : "action");
12946 : : } else {
12947 : 0 : res->sub_actions = sample_actions;
12948 [ # # ]: 0 : if (flow_dv_sample_resource_register(dev, res, dev_flow, error))
12949 : 0 : return rte_flow_error_set(error, EINVAL,
12950 : : RTE_FLOW_ERROR_TYPE_ACTION,
12951 : : NULL,
12952 : : "can't create sample action");
12953 : : }
12954 : : return 0;
12955 : : }
12956 : :
12957 : : /**
12958 : : * Remove an ASO age action from age actions list.
12959 : : *
12960 : : * @param[in] dev
12961 : : * Pointer to the Ethernet device structure.
12962 : : * @param[in] age
12963 : : * Pointer to the aso age action handler.
12964 : : */
12965 : : static void
12966 : 0 : flow_dv_aso_age_remove_from_age(struct rte_eth_dev *dev,
12967 : : struct mlx5_aso_age_action *age)
12968 : : {
12969 : : struct mlx5_age_info *age_info;
12970 : : struct mlx5_age_param *age_param = &age->age_params;
12971 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12972 : : uint16_t expected = AGE_CANDIDATE;
12973 : :
12974 : 0 : age_info = GET_PORT_AGE_INFO(priv);
12975 [ # # ]: 0 : if (!__atomic_compare_exchange_n(&age_param->state, &expected,
12976 : : AGE_FREE, false, __ATOMIC_RELAXED,
12977 : : __ATOMIC_RELAXED)) {
12978 : : /**
12979 : : * We need the lock even it is age timeout,
12980 : : * since age action may still in process.
12981 : : */
12982 : 0 : rte_spinlock_lock(&age_info->aged_sl);
12983 [ # # ]: 0 : LIST_REMOVE(age, next);
12984 : : rte_spinlock_unlock(&age_info->aged_sl);
12985 : 0 : __atomic_store_n(&age_param->state, AGE_FREE, __ATOMIC_RELAXED);
12986 : : }
12987 : 0 : }
12988 : :
12989 : : /**
12990 : : * Release an ASO age action.
12991 : : *
12992 : : * @param[in] dev
12993 : : * Pointer to the Ethernet device structure.
12994 : : * @param[in] age_idx
12995 : : * Index of ASO age action to release.
12996 : : * @param[in] flow
12997 : : * True if the release operation is during flow destroy operation.
12998 : : * False if the release operation is during action destroy operation.
12999 : : *
13000 : : * @return
13001 : : * 0 when age action was removed, otherwise the number of references.
13002 : : */
13003 : : static int
13004 : 0 : flow_dv_aso_age_release(struct rte_eth_dev *dev, uint32_t age_idx)
13005 : : {
13006 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13007 : 0 : struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
13008 : 0 : struct mlx5_aso_age_action *age = flow_aso_age_get_by_idx(dev, age_idx);
13009 : 0 : uint32_t ret = __atomic_fetch_sub(&age->refcnt, 1, __ATOMIC_RELAXED) - 1;
13010 : :
13011 [ # # ]: 0 : if (!ret) {
13012 : 0 : flow_dv_aso_age_remove_from_age(dev, age);
13013 : 0 : rte_spinlock_lock(&mng->free_sl);
13014 [ # # ]: 0 : LIST_INSERT_HEAD(&mng->free, age, next);
13015 : : rte_spinlock_unlock(&mng->free_sl);
13016 : : }
13017 : 0 : return ret;
13018 : : }
13019 : :
13020 : : /**
13021 : : * Resize the ASO age pools array by MLX5_ASO_AGE_CONTAINER_RESIZE pools.
13022 : : *
13023 : : * @param[in] dev
13024 : : * Pointer to the Ethernet device structure.
13025 : : *
13026 : : * @return
13027 : : * 0 on success, otherwise negative errno value and rte_errno is set.
13028 : : */
13029 : : static int
13030 : 0 : flow_dv_aso_age_pools_resize(struct rte_eth_dev *dev)
13031 : : {
13032 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13033 : 0 : struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
13034 : 0 : void *old_pools = mng->pools;
13035 : 0 : uint32_t resize = mng->n + MLX5_ASO_AGE_CONTAINER_RESIZE;
13036 : 0 : uint32_t mem_size = sizeof(struct mlx5_aso_age_pool *) * resize;
13037 : 0 : void *pools = mlx5_malloc(MLX5_MEM_ZERO, mem_size, 0, SOCKET_ID_ANY);
13038 : :
13039 [ # # ]: 0 : if (!pools) {
13040 : 0 : rte_errno = ENOMEM;
13041 : 0 : return -ENOMEM;
13042 : : }
13043 [ # # ]: 0 : if (old_pools) {
13044 : 0 : memcpy(pools, old_pools,
13045 : 0 : mng->n * sizeof(struct mlx5_flow_counter_pool *));
13046 : 0 : mlx5_free(old_pools);
13047 : : } else {
13048 : : /* First ASO flow hit allocation - starting ASO data-path. */
13049 : 0 : int ret = mlx5_aso_flow_hit_queue_poll_start(priv->sh);
13050 : :
13051 [ # # ]: 0 : if (ret) {
13052 : 0 : mlx5_free(pools);
13053 : 0 : return ret;
13054 : : }
13055 : : }
13056 : 0 : mng->n = resize;
13057 : 0 : mng->pools = pools;
13058 : 0 : return 0;
13059 : : }
13060 : :
13061 : : /**
13062 : : * Create and initialize a new ASO aging pool.
13063 : : *
13064 : : * @param[in] dev
13065 : : * Pointer to the Ethernet device structure.
13066 : : * @param[out] age_free
13067 : : * Where to put the pointer of a new age action.
13068 : : *
13069 : : * @return
13070 : : * The age actions pool pointer and @p age_free is set on success,
13071 : : * NULL otherwise and rte_errno is set.
13072 : : */
13073 : : static struct mlx5_aso_age_pool *
13074 : 0 : flow_dv_age_pool_create(struct rte_eth_dev *dev,
13075 : : struct mlx5_aso_age_action **age_free)
13076 : : {
13077 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13078 : 0 : struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
13079 : : struct mlx5_aso_age_pool *pool = NULL;
13080 : : struct mlx5_devx_obj *obj = NULL;
13081 : : uint32_t i;
13082 : :
13083 : 0 : obj = mlx5_devx_cmd_create_flow_hit_aso_obj(priv->sh->cdev->ctx,
13084 : 0 : priv->sh->cdev->pdn);
13085 [ # # ]: 0 : if (!obj) {
13086 : 0 : rte_errno = ENODATA;
13087 : 0 : DRV_LOG(ERR, "Failed to create flow_hit_aso_obj using DevX.");
13088 : 0 : return NULL;
13089 : : }
13090 : 0 : pool = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*pool), 0, SOCKET_ID_ANY);
13091 [ # # ]: 0 : if (!pool) {
13092 : 0 : claim_zero(mlx5_devx_cmd_destroy(obj));
13093 : 0 : rte_errno = ENOMEM;
13094 : 0 : return NULL;
13095 : : }
13096 : 0 : pool->flow_hit_aso_obj = obj;
13097 : 0 : pool->time_of_last_age_check = MLX5_CURR_TIME_SEC;
13098 : 0 : rte_rwlock_write_lock(&mng->resize_rwl);
13099 : 0 : pool->index = mng->next;
13100 : : /* Resize pools array if there is no room for the new pool in it. */
13101 [ # # # # ]: 0 : if (pool->index == mng->n && flow_dv_aso_age_pools_resize(dev)) {
13102 : 0 : claim_zero(mlx5_devx_cmd_destroy(obj));
13103 : 0 : mlx5_free(pool);
13104 : : rte_rwlock_write_unlock(&mng->resize_rwl);
13105 : 0 : return NULL;
13106 : : }
13107 : 0 : mng->pools[pool->index] = pool;
13108 : 0 : mng->next++;
13109 : : rte_rwlock_write_unlock(&mng->resize_rwl);
13110 : : /* Assign the first action in the new pool, the rest go to free list. */
13111 : 0 : *age_free = &pool->actions[0];
13112 [ # # ]: 0 : for (i = 1; i < MLX5_ASO_AGE_ACTIONS_PER_POOL; i++) {
13113 : 0 : pool->actions[i].offset = i;
13114 [ # # ]: 0 : LIST_INSERT_HEAD(&mng->free, &pool->actions[i], next);
13115 : : }
13116 : : return pool;
13117 : : }
13118 : :
13119 : : /**
13120 : : * Allocate a ASO aging bit.
13121 : : *
13122 : : * @param[in] dev
13123 : : * Pointer to the Ethernet device structure.
13124 : : * @param[out] error
13125 : : * Pointer to the error structure.
13126 : : *
13127 : : * @return
13128 : : * Index to ASO age action on success, 0 otherwise and rte_errno is set.
13129 : : */
13130 : : static uint32_t
13131 : 0 : flow_dv_aso_age_alloc(struct rte_eth_dev *dev, struct rte_flow_error *error)
13132 : : {
13133 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13134 : : const struct mlx5_aso_age_pool *pool;
13135 : 0 : struct mlx5_aso_age_action *age_free = NULL;
13136 : 0 : struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
13137 : :
13138 : : MLX5_ASSERT(mng);
13139 : : /* Try to get the next free age action bit. */
13140 : 0 : rte_spinlock_lock(&mng->free_sl);
13141 : 0 : age_free = LIST_FIRST(&mng->free);
13142 [ # # ]: 0 : if (age_free) {
13143 [ # # ]: 0 : LIST_REMOVE(age_free, next);
13144 [ # # ]: 0 : } else if (!flow_dv_age_pool_create(dev, &age_free)) {
13145 : : rte_spinlock_unlock(&mng->free_sl);
13146 : 0 : rte_flow_error_set(error, rte_errno, RTE_FLOW_ERROR_TYPE_ACTION,
13147 : : NULL, "failed to create ASO age pool");
13148 : 0 : return 0; /* 0 is an error. */
13149 : : }
13150 : : rte_spinlock_unlock(&mng->free_sl);
13151 : 0 : pool = container_of
13152 : : ((const struct mlx5_aso_age_action (*)[MLX5_ASO_AGE_ACTIONS_PER_POOL])
13153 : : (age_free - age_free->offset), const struct mlx5_aso_age_pool,
13154 : : actions);
13155 [ # # ]: 0 : if (!age_free->dr_action) {
13156 : 0 : int reg_c = mlx5_flow_get_reg_id(dev, MLX5_ASO_FLOW_HIT, 0,
13157 : : error);
13158 : :
13159 [ # # ]: 0 : if (reg_c < 0) {
13160 : 0 : rte_flow_error_set(error, rte_errno,
13161 : : RTE_FLOW_ERROR_TYPE_ACTION,
13162 : : NULL, "failed to get reg_c "
13163 : : "for ASO flow hit");
13164 : 0 : return 0; /* 0 is an error. */
13165 : : }
13166 : : #ifdef HAVE_MLX5_DR_CREATE_ACTION_ASO
13167 : 0 : age_free->dr_action = mlx5_glue->dv_create_flow_action_aso
13168 : 0 : (priv->sh->rx_domain,
13169 : 0 : pool->flow_hit_aso_obj->obj, age_free->offset,
13170 : : MLX5DV_DR_ACTION_FLAGS_ASO_FIRST_HIT_SET,
13171 : 0 : (reg_c - REG_C_0));
13172 : : #endif /* HAVE_MLX5_DR_CREATE_ACTION_ASO */
13173 [ # # ]: 0 : if (!age_free->dr_action) {
13174 : 0 : rte_errno = errno;
13175 : : rte_spinlock_lock(&mng->free_sl);
13176 [ # # ]: 0 : LIST_INSERT_HEAD(&mng->free, age_free, next);
13177 : : rte_spinlock_unlock(&mng->free_sl);
13178 : 0 : rte_flow_error_set(error, rte_errno,
13179 : : RTE_FLOW_ERROR_TYPE_ACTION,
13180 : : NULL, "failed to create ASO "
13181 : : "flow hit action");
13182 : 0 : return 0; /* 0 is an error. */
13183 : : }
13184 : : }
13185 : 0 : __atomic_store_n(&age_free->refcnt, 1, __ATOMIC_RELAXED);
13186 : 0 : return pool->index | ((age_free->offset + 1) << 16);
13187 : : }
13188 : :
13189 : : /**
13190 : : * Initialize flow ASO age parameters.
13191 : : *
13192 : : * @param[in] dev
13193 : : * Pointer to rte_eth_dev structure.
13194 : : * @param[in] age_idx
13195 : : * Index of ASO age action.
13196 : : * @param[in] context
13197 : : * Pointer to flow counter age context.
13198 : : * @param[in] timeout
13199 : : * Aging timeout in seconds.
13200 : : *
13201 : : */
13202 : : static void
13203 : 0 : flow_dv_aso_age_params_init(struct rte_eth_dev *dev,
13204 : : uint32_t age_idx,
13205 : : void *context,
13206 : : uint32_t timeout)
13207 : : {
13208 : : struct mlx5_aso_age_action *aso_age;
13209 : :
13210 : 0 : aso_age = flow_aso_age_get_by_idx(dev, age_idx);
13211 : : MLX5_ASSERT(aso_age);
13212 : 0 : aso_age->age_params.context = context;
13213 : 0 : aso_age->age_params.timeout = timeout;
13214 : 0 : aso_age->age_params.port_id = dev->data->port_id;
13215 : 0 : __atomic_store_n(&aso_age->age_params.sec_since_last_hit, 0,
13216 : : __ATOMIC_RELAXED);
13217 : 0 : __atomic_store_n(&aso_age->age_params.state, AGE_CANDIDATE,
13218 : : __ATOMIC_RELAXED);
13219 : 0 : }
13220 : :
13221 : : static void
13222 : 0 : flow_dv_translate_integrity_l4(const struct rte_flow_item_integrity *mask,
13223 : : void *headers)
13224 : : {
13225 : : /*
13226 : : * In HWS mode MLX5_ITEM_UPDATE() macro assigns the same pointer to
13227 : : * both mask and value, therefore ether can be used.
13228 : : * In SWS SW_V mode mask points to item mask and value points to item
13229 : : * spec. Integrity item value is used only if matching mask is set.
13230 : : * Use mask reference here to keep SWS functionality.
13231 : : */
13232 [ # # ]: 0 : if (mask->l4_ok) {
13233 : : /* RTE l4_ok filter aggregates hardware l4_ok and
13234 : : * l4_checksum_ok filters.
13235 : : * Positive RTE l4_ok match requires hardware match on both L4
13236 : : * hardware integrity bits.
13237 : : * PMD supports positive integrity item semantics only.
13238 : : */
13239 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers, l4_ok, 1);
13240 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers, l4_checksum_ok, 1);
13241 [ # # ]: 0 : } else if (mask->l4_csum_ok) {
13242 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers, l4_checksum_ok, 1);
13243 : : }
13244 : 0 : }
13245 : :
13246 : : static void
13247 : 0 : flow_dv_translate_integrity_l3(const struct rte_flow_item_integrity *mask,
13248 : : void *headers, bool is_ipv4)
13249 : : {
13250 : : /*
13251 : : * In HWS mode MLX5_ITEM_UPDATE() macro assigns the same pointer to
13252 : : * both mask and value, therefore ether can be used.
13253 : : * In SWS SW_V mode mask points to item mask and value points to item
13254 : : * spec. Integrity item value used only if matching mask is set.
13255 : : * Use mask reference here to keep SWS functionality.
13256 : : */
13257 [ # # ]: 0 : if (mask->l3_ok) {
13258 : : /* RTE l3_ok filter aggregates for IPv4 hardware l3_ok and
13259 : : * ipv4_csum_ok filters.
13260 : : * Positive RTE l3_ok match requires hardware match on both L3
13261 : : * hardware integrity bits.
13262 : : * PMD supports positive integrity item semantics only.
13263 : : */
13264 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers, l3_ok, 1);
13265 [ # # ]: 0 : if (is_ipv4) {
13266 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers,
13267 : : ipv4_checksum_ok, 1);
13268 : : }
13269 [ # # # # ]: 0 : } else if (is_ipv4 && mask->ipv4_csum_ok) {
13270 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers, ipv4_checksum_ok, 1);
13271 : : }
13272 : 0 : }
13273 : :
13274 : : static void
13275 : 0 : set_integrity_bits(void *headers, const struct rte_flow_item *integrity_item,
13276 : : bool is_l3_ip4, uint32_t key_type)
13277 : : {
13278 : : const struct rte_flow_item_integrity *spec;
13279 : : const struct rte_flow_item_integrity *mask;
13280 : :
13281 : : /* Integrity bits validation cleared spec pointer */
13282 [ # # # # : 0 : if (MLX5_ITEM_VALID(integrity_item, key_type))
# # # # #
# ]
13283 : : return;
13284 [ # # # # : 0 : MLX5_ITEM_UPDATE(integrity_item, key_type, spec, mask,
# # # # ]
13285 : : &rte_flow_item_integrity_mask);
13286 : 0 : flow_dv_translate_integrity_l3(mask, headers, is_l3_ip4);
13287 : 0 : flow_dv_translate_integrity_l4(mask, headers);
13288 : : }
13289 : :
13290 : : static void
13291 : 0 : flow_dv_translate_item_integrity_post(void *key,
13292 : : const
13293 : : struct rte_flow_item *integrity_items[2],
13294 : : uint64_t pattern_flags, uint32_t key_type)
13295 : : {
13296 : : void *headers;
13297 : : bool is_l3_ip4;
13298 : :
13299 [ # # ]: 0 : if (pattern_flags & MLX5_FLOW_ITEM_INNER_INTEGRITY) {
13300 : 0 : headers = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
13301 : 0 : is_l3_ip4 = (pattern_flags & MLX5_FLOW_LAYER_INNER_L3_IPV4) !=
13302 : : 0;
13303 : 0 : set_integrity_bits(headers, integrity_items[1], is_l3_ip4,
13304 : : key_type);
13305 : : }
13306 [ # # ]: 0 : if (pattern_flags & MLX5_FLOW_ITEM_OUTER_INTEGRITY) {
13307 : : headers = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
13308 : 0 : is_l3_ip4 = (pattern_flags & MLX5_FLOW_LAYER_OUTER_L3_IPV4) !=
13309 : : 0;
13310 : 0 : set_integrity_bits(headers, integrity_items[0], is_l3_ip4,
13311 : : key_type);
13312 : : }
13313 : 0 : }
13314 : :
13315 : : static uint64_t
13316 : : flow_dv_translate_item_integrity(const struct rte_flow_item *item,
13317 : : struct mlx5_dv_matcher_workspace *wks,
13318 : : uint64_t key_type)
13319 : : {
13320 : 0 : if ((key_type & MLX5_SET_MATCHER_SW) != 0) {
13321 : : const struct rte_flow_item_integrity
13322 : 0 : *spec = (typeof(spec))item->spec;
13323 : :
13324 : : /* SWS integrity bits validation cleared spec pointer */
13325 [ # # ]: 0 : if (spec->level > 1) {
13326 : 0 : wks->integrity_items[1] = item;
13327 : 0 : wks->last_item |= MLX5_FLOW_ITEM_INNER_INTEGRITY;
13328 : : } else {
13329 : 0 : wks->integrity_items[0] = item;
13330 : 0 : wks->last_item |= MLX5_FLOW_ITEM_OUTER_INTEGRITY;
13331 : : }
13332 : : } else {
13333 : : /* HWS supports outer integrity only */
13334 : 0 : wks->integrity_items[0] = item;
13335 : 0 : wks->last_item |= MLX5_FLOW_ITEM_OUTER_INTEGRITY;
13336 : : }
13337 : 0 : return wks->last_item;
13338 : : }
13339 : :
13340 : : /**
13341 : : * Prepares DV flow counter with aging configuration.
13342 : : * Gets it by index when exists, creates a new one when doesn't.
13343 : : *
13344 : : * @param[in] dev
13345 : : * Pointer to rte_eth_dev structure.
13346 : : * @param[in] dev_flow
13347 : : * Pointer to the mlx5_flow.
13348 : : * @param[in, out] flow
13349 : : * Pointer to the sub flow.
13350 : : * @param[in] count
13351 : : * Pointer to the counter action configuration.
13352 : : * @param[in] age
13353 : : * Pointer to the aging action configuration.
13354 : : * @param[out] error
13355 : : * Pointer to the error structure.
13356 : : *
13357 : : * @return
13358 : : * Pointer to the counter, NULL otherwise.
13359 : : */
13360 : : static struct mlx5_flow_counter *
13361 : 0 : flow_dv_prepare_counter(struct rte_eth_dev *dev,
13362 : : struct mlx5_flow *dev_flow,
13363 : : struct rte_flow *flow,
13364 : : const struct rte_flow_action_count *count,
13365 : : const struct rte_flow_action_age *age,
13366 : : struct rte_flow_error *error)
13367 : : {
13368 [ # # ]: 0 : if (!flow->counter) {
13369 : 0 : flow->counter = flow_dv_translate_create_counter(dev, dev_flow,
13370 : : count, age);
13371 [ # # ]: 0 : if (!flow->counter) {
13372 : 0 : rte_flow_error_set(error, rte_errno,
13373 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
13374 : : "cannot create counter object.");
13375 : 0 : return NULL;
13376 : : }
13377 : : }
13378 [ # # ]: 0 : return flow_dv_counter_get_by_idx(dev, flow->counter, NULL);
13379 : : }
13380 : :
13381 : : /*
13382 : : * Release an ASO CT action by its own device.
13383 : : *
13384 : : * @param[in] dev
13385 : : * Pointer to the Ethernet device structure.
13386 : : * @param[in] idx
13387 : : * Index of ASO CT action to release.
13388 : : *
13389 : : * @return
13390 : : * 0 when CT action was removed, otherwise the number of references.
13391 : : */
13392 : : static inline int
13393 : 0 : flow_dv_aso_ct_dev_release(struct rte_eth_dev *dev, uint32_t idx)
13394 : : {
13395 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13396 : 0 : struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
13397 : : uint32_t ret;
13398 : 0 : struct mlx5_aso_ct_action *ct = flow_aso_ct_get_by_dev_idx(dev, idx);
13399 : : enum mlx5_aso_ct_state state =
13400 : 0 : __atomic_load_n(&ct->state, __ATOMIC_RELAXED);
13401 : :
13402 : : /* Cannot release when CT is in the ASO SQ. */
13403 [ # # ]: 0 : if (state == ASO_CONNTRACK_WAIT || state == ASO_CONNTRACK_QUERY)
13404 : : return -1;
13405 : 0 : ret = __atomic_fetch_sub(&ct->refcnt, 1, __ATOMIC_RELAXED) - 1;
13406 [ # # ]: 0 : if (!ret) {
13407 [ # # ]: 0 : if (ct->dr_action_orig) {
13408 : : #ifdef HAVE_MLX5_DR_ACTION_ASO_CT
13409 : 0 : claim_zero(mlx5_glue->destroy_flow_action
13410 : : (ct->dr_action_orig));
13411 : : #endif
13412 : 0 : ct->dr_action_orig = NULL;
13413 : : }
13414 [ # # ]: 0 : if (ct->dr_action_rply) {
13415 : : #ifdef HAVE_MLX5_DR_ACTION_ASO_CT
13416 : 0 : claim_zero(mlx5_glue->destroy_flow_action
13417 : : (ct->dr_action_rply));
13418 : : #endif
13419 : 0 : ct->dr_action_rply = NULL;
13420 : : }
13421 : : /* Clear the state to free, no need in 1st allocation. */
13422 : 0 : MLX5_ASO_CT_UPDATE_STATE(ct, ASO_CONNTRACK_FREE);
13423 : 0 : rte_spinlock_lock(&mng->ct_sl);
13424 [ # # ]: 0 : LIST_INSERT_HEAD(&mng->free_cts, ct, next);
13425 : : rte_spinlock_unlock(&mng->ct_sl);
13426 : : }
13427 : 0 : return (int)ret;
13428 : : }
13429 : :
13430 : : static inline int
13431 : 0 : flow_dv_aso_ct_release(struct rte_eth_dev *dev, uint32_t own_idx,
13432 : : struct rte_flow_error *error)
13433 : : {
13434 : 0 : uint16_t owner = (uint16_t)MLX5_INDIRECT_ACT_CT_GET_OWNER(own_idx);
13435 : 0 : uint32_t idx = MLX5_INDIRECT_ACT_CT_GET_IDX(own_idx);
13436 : 0 : struct rte_eth_dev *owndev = &rte_eth_devices[owner];
13437 : : int ret;
13438 : :
13439 : : MLX5_ASSERT(owner < RTE_MAX_ETHPORTS);
13440 [ # # ]: 0 : if (dev->data->dev_started != 1)
13441 : 0 : return rte_flow_error_set(error, EAGAIN,
13442 : : RTE_FLOW_ERROR_TYPE_ACTION,
13443 : : NULL,
13444 : : "Indirect CT action cannot be destroyed when the port is stopped");
13445 : 0 : ret = flow_dv_aso_ct_dev_release(owndev, idx);
13446 [ # # ]: 0 : if (ret < 0)
13447 : 0 : return rte_flow_error_set(error, EAGAIN,
13448 : : RTE_FLOW_ERROR_TYPE_ACTION,
13449 : : NULL,
13450 : : "Current state prevents indirect CT action from being destroyed");
13451 : : return ret;
13452 : : }
13453 : :
13454 : : /*
13455 : : * Resize the ASO CT pools array by 64 pools.
13456 : : *
13457 : : * @param[in] dev
13458 : : * Pointer to the Ethernet device structure.
13459 : : *
13460 : : * @return
13461 : : * 0 on success, otherwise negative errno value and rte_errno is set.
13462 : : */
13463 : : static int
13464 : 0 : flow_dv_aso_ct_pools_resize(struct rte_eth_dev *dev)
13465 : : {
13466 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13467 : 0 : struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
13468 : 0 : void *old_pools = mng->pools;
13469 : : /* Magic number now, need a macro. */
13470 : 0 : uint32_t resize = mng->n + 64;
13471 : 0 : uint32_t mem_size = sizeof(struct mlx5_aso_ct_pool *) * resize;
13472 : 0 : void *pools = mlx5_malloc(MLX5_MEM_ZERO, mem_size, 0, SOCKET_ID_ANY);
13473 : :
13474 [ # # ]: 0 : if (!pools) {
13475 : 0 : rte_errno = ENOMEM;
13476 : 0 : return -rte_errno;
13477 : : }
13478 : 0 : rte_rwlock_write_lock(&mng->resize_rwl);
13479 : : /* ASO SQ/QP was already initialized in the startup. */
13480 [ # # ]: 0 : if (old_pools) {
13481 : : /* Realloc could be an alternative choice. */
13482 : 0 : rte_memcpy(pools, old_pools,
13483 [ # # ]: 0 : mng->n * sizeof(struct mlx5_aso_ct_pool *));
13484 : 0 : mlx5_free(old_pools);
13485 : : }
13486 : 0 : mng->n = resize;
13487 : 0 : mng->pools = pools;
13488 : : rte_rwlock_write_unlock(&mng->resize_rwl);
13489 : 0 : return 0;
13490 : : }
13491 : :
13492 : : /*
13493 : : * Create and initialize a new ASO CT pool.
13494 : : *
13495 : : * @param[in] dev
13496 : : * Pointer to the Ethernet device structure.
13497 : : * @param[out] ct_free
13498 : : * Where to put the pointer of a new CT action.
13499 : : *
13500 : : * @return
13501 : : * The CT actions pool pointer and @p ct_free is set on success,
13502 : : * NULL otherwise and rte_errno is set.
13503 : : */
13504 : : static struct mlx5_aso_ct_pool *
13505 : 0 : flow_dv_ct_pool_create(struct rte_eth_dev *dev,
13506 : : struct mlx5_aso_ct_action **ct_free)
13507 : : {
13508 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13509 : 0 : struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
13510 : : struct mlx5_aso_ct_pool *pool = NULL;
13511 : : struct mlx5_devx_obj *obj = NULL;
13512 : : uint32_t i;
13513 : : uint32_t log_obj_size = rte_log2_u32(MLX5_ASO_CT_ACTIONS_PER_POOL);
13514 : : size_t mem_size;
13515 : :
13516 : 0 : obj = mlx5_devx_cmd_create_conn_track_offload_obj(priv->sh->cdev->ctx,
13517 : 0 : priv->sh->cdev->pdn,
13518 : : log_obj_size);
13519 [ # # ]: 0 : if (!obj) {
13520 : 0 : rte_errno = ENODATA;
13521 : 0 : DRV_LOG(ERR, "Failed to create conn_track_offload_obj using DevX.");
13522 : 0 : return NULL;
13523 : : }
13524 : : mem_size = sizeof(struct mlx5_aso_ct_action) *
13525 : : MLX5_ASO_CT_ACTIONS_PER_POOL +
13526 : : sizeof(*pool);
13527 : 0 : pool = mlx5_malloc(MLX5_MEM_ZERO, mem_size, 0, SOCKET_ID_ANY);
13528 [ # # ]: 0 : if (!pool) {
13529 : 0 : rte_errno = ENOMEM;
13530 : 0 : claim_zero(mlx5_devx_cmd_destroy(obj));
13531 : 0 : return NULL;
13532 : : }
13533 : 0 : pool->devx_obj = obj;
13534 : 0 : pool->index = mng->next;
13535 : : /* Resize pools array if there is no room for the new pool in it. */
13536 [ # # # # ]: 0 : if (pool->index == mng->n && flow_dv_aso_ct_pools_resize(dev)) {
13537 : 0 : claim_zero(mlx5_devx_cmd_destroy(obj));
13538 : 0 : mlx5_free(pool);
13539 : 0 : return NULL;
13540 : : }
13541 : 0 : mng->pools[pool->index] = pool;
13542 : 0 : mng->next++;
13543 : : /* Assign the first action in the new pool, the rest go to free list. */
13544 : 0 : *ct_free = &pool->actions[0];
13545 : : /* Lock outside, the list operation is safe here. */
13546 [ # # ]: 0 : for (i = 1; i < MLX5_ASO_CT_ACTIONS_PER_POOL; i++) {
13547 : : /* refcnt is 0 when allocating the memory. */
13548 : 0 : pool->actions[i].offset = i;
13549 [ # # ]: 0 : LIST_INSERT_HEAD(&mng->free_cts, &pool->actions[i], next);
13550 : : }
13551 : : return pool;
13552 : : }
13553 : :
13554 : : /*
13555 : : * Allocate a ASO CT action from free list.
13556 : : *
13557 : : * @param[in] dev
13558 : : * Pointer to the Ethernet device structure.
13559 : : * @param[out] error
13560 : : * Pointer to the error structure.
13561 : : *
13562 : : * @return
13563 : : * Index to ASO CT action on success, 0 otherwise and rte_errno is set.
13564 : : */
13565 : : static uint32_t
13566 : 0 : flow_dv_aso_ct_alloc(struct rte_eth_dev *dev, struct rte_flow_error *error)
13567 : : {
13568 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13569 : 0 : struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
13570 : 0 : struct mlx5_aso_ct_action *ct = NULL;
13571 : : struct mlx5_aso_ct_pool *pool;
13572 : : uint8_t reg_c;
13573 : : uint32_t ct_idx;
13574 : :
13575 : : MLX5_ASSERT(mng);
13576 [ # # ]: 0 : if (!priv->sh->cdev->config.devx) {
13577 : 0 : rte_errno = ENOTSUP;
13578 : 0 : return 0;
13579 : : }
13580 : : /* Get a free CT action, if no, a new pool will be created. */
13581 : 0 : rte_spinlock_lock(&mng->ct_sl);
13582 : 0 : ct = LIST_FIRST(&mng->free_cts);
13583 [ # # ]: 0 : if (ct) {
13584 [ # # ]: 0 : LIST_REMOVE(ct, next);
13585 [ # # ]: 0 : } else if (!flow_dv_ct_pool_create(dev, &ct)) {
13586 : : rte_spinlock_unlock(&mng->ct_sl);
13587 : 0 : rte_flow_error_set(error, rte_errno, RTE_FLOW_ERROR_TYPE_ACTION,
13588 : : NULL, "failed to create ASO CT pool");
13589 : 0 : return 0;
13590 : : }
13591 : : rte_spinlock_unlock(&mng->ct_sl);
13592 : 0 : pool = container_of(ct, struct mlx5_aso_ct_pool, actions[ct->offset]);
13593 : 0 : ct_idx = MLX5_MAKE_CT_IDX(pool->index, ct->offset);
13594 : : /* 0: inactive, 1: created, 2+: used by flows. */
13595 : 0 : __atomic_store_n(&ct->refcnt, 1, __ATOMIC_RELAXED);
13596 : 0 : reg_c = mlx5_flow_get_reg_id(dev, MLX5_ASO_CONNTRACK, 0, error);
13597 [ # # ]: 0 : if (!ct->dr_action_orig) {
13598 : : #ifdef HAVE_MLX5_DR_ACTION_ASO_CT
13599 : 0 : ct->dr_action_orig = mlx5_glue->dv_create_flow_action_aso
13600 : 0 : (priv->sh->rx_domain, pool->devx_obj->obj,
13601 : : ct->offset,
13602 : : MLX5DV_DR_ACTION_FLAGS_ASO_CT_DIRECTION_INITIATOR,
13603 : 0 : reg_c - REG_C_0);
13604 : : #else
13605 : : RTE_SET_USED(reg_c);
13606 : : #endif
13607 [ # # ]: 0 : if (!ct->dr_action_orig) {
13608 : 0 : flow_dv_aso_ct_dev_release(dev, ct_idx);
13609 : 0 : rte_flow_error_set(error, rte_errno,
13610 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
13611 : : "failed to create ASO CT action");
13612 : 0 : return 0;
13613 : : }
13614 : : }
13615 [ # # ]: 0 : if (!ct->dr_action_rply) {
13616 : : #ifdef HAVE_MLX5_DR_ACTION_ASO_CT
13617 : 0 : ct->dr_action_rply = mlx5_glue->dv_create_flow_action_aso
13618 : 0 : (priv->sh->rx_domain, pool->devx_obj->obj,
13619 : : ct->offset,
13620 : : MLX5DV_DR_ACTION_FLAGS_ASO_CT_DIRECTION_RESPONDER,
13621 : 0 : reg_c - REG_C_0);
13622 : : #endif
13623 [ # # ]: 0 : if (!ct->dr_action_rply) {
13624 : 0 : flow_dv_aso_ct_dev_release(dev, ct_idx);
13625 : 0 : rte_flow_error_set(error, rte_errno,
13626 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
13627 : : "failed to create ASO CT action");
13628 : 0 : return 0;
13629 : : }
13630 : : }
13631 : : return ct_idx;
13632 : : }
13633 : :
13634 : : /*
13635 : : * Create a conntrack object with context and actions by using ASO mechanism.
13636 : : *
13637 : : * @param[in] dev
13638 : : * Pointer to rte_eth_dev structure.
13639 : : * @param[in] pro
13640 : : * Pointer to conntrack information profile.
13641 : : * @param[out] error
13642 : : * Pointer to the error structure.
13643 : : *
13644 : : * @return
13645 : : * Index to conntrack object on success, 0 otherwise.
13646 : : */
13647 : : static uint32_t
13648 : 0 : flow_dv_translate_create_conntrack(struct rte_eth_dev *dev,
13649 : : const struct rte_flow_action_conntrack *pro,
13650 : : struct rte_flow_error *error)
13651 : : {
13652 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13653 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
13654 : : struct mlx5_aso_ct_action *ct;
13655 : : uint32_t idx;
13656 : :
13657 [ # # ]: 0 : if (!sh->ct_aso_en)
13658 : 0 : return rte_flow_error_set(error, ENOTSUP,
13659 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
13660 : : "Connection is not supported");
13661 : 0 : idx = flow_dv_aso_ct_alloc(dev, error);
13662 [ # # ]: 0 : if (!idx)
13663 : 0 : return rte_flow_error_set(error, rte_errno,
13664 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
13665 : : "Failed to allocate CT object");
13666 : 0 : ct = flow_aso_ct_get_by_dev_idx(dev, idx);
13667 [ # # ]: 0 : if (mlx5_aso_ct_update_by_wqe(sh, MLX5_HW_INV_QUEUE, ct, pro, NULL, true)) {
13668 : 0 : flow_dv_aso_ct_dev_release(dev, idx);
13669 : 0 : rte_flow_error_set(error, EBUSY,
13670 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
13671 : : "Failed to update CT");
13672 : 0 : return 0;
13673 : : }
13674 : 0 : ct->is_original = !!pro->is_original_dir;
13675 : 0 : ct->peer = pro->peer_port;
13676 : 0 : return idx;
13677 : : }
13678 : :
13679 : : /**
13680 : : * Fill the flow matcher with DV spec.
13681 : : *
13682 : : * @param[in] dev
13683 : : * Pointer to rte_eth_dev structure.
13684 : : * @param[in] items
13685 : : * Pointer to the list of items.
13686 : : * @param[in] wks
13687 : : * Pointer to the matcher workspace.
13688 : : * @param[in] key
13689 : : * Pointer to the flow matcher key.
13690 : : * @param[in] key_type
13691 : : * Key type.
13692 : : * @param[out] error
13693 : : * Pointer to the error structure.
13694 : : *
13695 : : * @return
13696 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
13697 : : */
13698 : : static int
13699 : 0 : flow_dv_translate_items(struct rte_eth_dev *dev,
13700 : : const struct rte_flow_item *items,
13701 : : struct mlx5_dv_matcher_workspace *wks,
13702 : : void *key, uint32_t key_type,
13703 : : struct rte_flow_error *error)
13704 : : {
13705 : 0 : struct mlx5_flow_rss_desc *rss_desc = wks->rss_desc;
13706 : 0 : uint8_t next_protocol = wks->next_protocol;
13707 : 0 : int tunnel = !!(wks->item_flags & MLX5_FLOW_LAYER_TUNNEL);
13708 : 0 : int item_type = items->type;
13709 : 0 : uint64_t last_item = wks->last_item;
13710 : : int ret;
13711 : :
13712 [ # # # # : 0 : switch (item_type) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # ]
13713 : 0 : case RTE_FLOW_ITEM_TYPE_ESP:
13714 : 0 : flow_dv_translate_item_esp(key, items, tunnel, key_type);
13715 : 0 : wks->priority = MLX5_PRIORITY_MAP_L4;
13716 : : last_item = MLX5_FLOW_ITEM_ESP;
13717 : 0 : break;
13718 : 0 : case RTE_FLOW_ITEM_TYPE_PORT_ID:
13719 : 0 : flow_dv_translate_item_port_id
13720 : : (dev, key, items, wks->attr, key_type);
13721 : : last_item = MLX5_FLOW_ITEM_PORT_ID;
13722 : 0 : break;
13723 : 0 : case RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR:
13724 : 0 : flow_dv_translate_item_port_representor
13725 : : (dev, key, key_type);
13726 : : last_item = MLX5_FLOW_ITEM_PORT_REPRESENTOR;
13727 : 0 : break;
13728 : 0 : case RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT:
13729 : 0 : flow_dv_translate_item_represented_port
13730 : : (dev, key, items, wks->attr, key_type);
13731 : : last_item = MLX5_FLOW_ITEM_REPRESENTED_PORT;
13732 : 0 : break;
13733 : 0 : case RTE_FLOW_ITEM_TYPE_ETH:
13734 : 0 : flow_dv_translate_item_eth(key, items, tunnel,
13735 : : wks->group, key_type);
13736 [ # # ]: 0 : wks->priority = wks->action_flags &
13737 : 0 : MLX5_FLOW_ACTION_DEFAULT_MISS &&
13738 [ # # ]: 0 : !wks->external ?
13739 : : MLX5_PRIORITY_MAP_L3 :
13740 : : MLX5_PRIORITY_MAP_L2;
13741 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
13742 : : MLX5_FLOW_LAYER_OUTER_L2;
13743 : : break;
13744 : 0 : case RTE_FLOW_ITEM_TYPE_VLAN:
13745 : 0 : flow_dv_translate_item_vlan(key, items, tunnel, wks, key_type);
13746 : 0 : wks->priority = MLX5_PRIORITY_MAP_L2;
13747 : : last_item = tunnel ? (MLX5_FLOW_LAYER_INNER_L2 |
13748 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_VLAN) :
13749 : : (MLX5_FLOW_LAYER_OUTER_L2 |
13750 : : MLX5_FLOW_LAYER_OUTER_VLAN);
13751 : : break;
13752 [ # # ]: 0 : case RTE_FLOW_ITEM_TYPE_IPV4:
13753 : : mlx5_flow_tunnel_ip_check(items, next_protocol,
13754 : : &wks->item_flags, &tunnel);
13755 : 0 : flow_dv_translate_item_ipv4(key, items, tunnel,
13756 : : wks->group, key_type);
13757 : 0 : wks->priority = MLX5_PRIORITY_MAP_L3;
13758 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
13759 : : MLX5_FLOW_LAYER_OUTER_L3_IPV4;
13760 [ # # ]: 0 : if (items->mask != NULL &&
13761 [ # # ]: 0 : items->spec != NULL &&
13762 : : ((const struct rte_flow_item_ipv4 *)
13763 [ # # ]: 0 : items->mask)->hdr.next_proto_id) {
13764 : 0 : next_protocol =
13765 : : ((const struct rte_flow_item_ipv4 *)
13766 : : (items->spec))->hdr.next_proto_id;
13767 : 0 : next_protocol &=
13768 : : ((const struct rte_flow_item_ipv4 *)
13769 : : (items->mask))->hdr.next_proto_id;
13770 [ # # # # ]: 0 : } else if (key_type == MLX5_SET_MATCHER_HS_M &&
13771 : : items->mask != NULL) {
13772 : 0 : next_protocol = ((const struct rte_flow_item_ipv4 *)
13773 : : (items->mask))->hdr.next_proto_id;
13774 [ # # ]: 0 : } else if (key_type == MLX5_SET_MATCHER_HS_V &&
13775 [ # # ]: 0 : items->spec != NULL) {
13776 : 0 : next_protocol = ((const struct rte_flow_item_ipv4 *)
13777 : : (items->spec))->hdr.next_proto_id;
13778 : : } else {
13779 : : /* Reset for inner layer. */
13780 : : next_protocol = 0xff;
13781 : : }
13782 : : break;
13783 [ # # ]: 0 : case RTE_FLOW_ITEM_TYPE_IPV6:
13784 : : mlx5_flow_tunnel_ip_check(items, next_protocol,
13785 : : &wks->item_flags, &tunnel);
13786 : 0 : flow_dv_translate_item_ipv6(key, items, tunnel,
13787 : : wks->group, key_type);
13788 : 0 : wks->priority = MLX5_PRIORITY_MAP_L3;
13789 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
13790 : : MLX5_FLOW_LAYER_OUTER_L3_IPV6;
13791 [ # # ]: 0 : if (items->mask != NULL &&
13792 [ # # ]: 0 : items->spec != NULL &&
13793 : : ((const struct rte_flow_item_ipv6 *)
13794 [ # # ]: 0 : items->mask)->hdr.proto) {
13795 : 0 : next_protocol =
13796 : : ((const struct rte_flow_item_ipv6 *)
13797 : : items->spec)->hdr.proto;
13798 : 0 : next_protocol &=
13799 : : ((const struct rte_flow_item_ipv6 *)
13800 : : items->mask)->hdr.proto;
13801 [ # # # # ]: 0 : } else if (key_type == MLX5_SET_MATCHER_HS_M &&
13802 : : items->mask != NULL) {
13803 : 0 : next_protocol = ((const struct rte_flow_item_ipv6 *)
13804 : : (items->mask))->hdr.proto;
13805 [ # # ]: 0 : } else if (key_type == MLX5_SET_MATCHER_HS_V &&
13806 [ # # ]: 0 : items->spec != NULL) {
13807 : 0 : next_protocol = ((const struct rte_flow_item_ipv6 *)
13808 : : (items->spec))->hdr.proto;
13809 : : } else {
13810 : : /* Reset for inner layer. */
13811 : : next_protocol = 0xff;
13812 : : }
13813 : : break;
13814 : 0 : case RTE_FLOW_ITEM_TYPE_IPV6_FRAG_EXT:
13815 : 0 : flow_dv_translate_item_ipv6_frag_ext
13816 : : (key, items, tunnel, key_type);
13817 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6_FRAG_EXT :
13818 : : MLX5_FLOW_LAYER_OUTER_L3_IPV6_FRAG_EXT;
13819 [ # # ]: 0 : if (items->mask != NULL &&
13820 [ # # ]: 0 : items->spec != NULL &&
13821 : : ((const struct rte_flow_item_ipv6_frag_ext *)
13822 [ # # ]: 0 : items->mask)->hdr.next_header) {
13823 : 0 : next_protocol =
13824 : : ((const struct rte_flow_item_ipv6_frag_ext *)
13825 : : items->spec)->hdr.next_header;
13826 : 0 : next_protocol &=
13827 : : ((const struct rte_flow_item_ipv6_frag_ext *)
13828 : : items->mask)->hdr.next_header;
13829 [ # # # # ]: 0 : } else if (key_type == MLX5_SET_MATCHER_HS_M &&
13830 : : items->mask != NULL) {
13831 : 0 : next_protocol = ((const struct rte_flow_item_ipv6_frag_ext *)
13832 : : (items->mask))->hdr.next_header;
13833 [ # # ]: 0 : } else if (key_type == MLX5_SET_MATCHER_HS_V &&
13834 [ # # ]: 0 : items->spec != NULL) {
13835 : 0 : next_protocol = ((const struct rte_flow_item_ipv6_frag_ext *)
13836 : : (items->spec))->hdr.next_header;
13837 : : } else {
13838 : : /* Reset for inner layer. */
13839 : : next_protocol = 0xff;
13840 : : }
13841 : : break;
13842 : 0 : case RTE_FLOW_ITEM_TYPE_TCP:
13843 : 0 : flow_dv_translate_item_tcp(key, items, tunnel, key_type);
13844 : 0 : wks->priority = MLX5_PRIORITY_MAP_L4;
13845 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_TCP :
13846 : : MLX5_FLOW_LAYER_OUTER_L4_TCP;
13847 : : break;
13848 : 0 : case RTE_FLOW_ITEM_TYPE_UDP:
13849 : 0 : flow_dv_translate_item_udp(key, items, tunnel, wks, key_type);
13850 : 0 : wks->priority = MLX5_PRIORITY_MAP_L4;
13851 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_UDP :
13852 : : MLX5_FLOW_LAYER_OUTER_L4_UDP;
13853 : : break;
13854 : 0 : case RTE_FLOW_ITEM_TYPE_GRE:
13855 [ # # ]: 0 : wks->priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
13856 : 0 : wks->tunnel_item = items;
13857 : 0 : wks->gre_item = items;
13858 : : last_item = MLX5_FLOW_LAYER_GRE;
13859 : 0 : break;
13860 : 0 : case RTE_FLOW_ITEM_TYPE_GRE_KEY:
13861 : 0 : flow_dv_translate_item_gre_key(key, items, key_type);
13862 : : last_item = MLX5_FLOW_LAYER_GRE_KEY;
13863 : 0 : break;
13864 : 0 : case RTE_FLOW_ITEM_TYPE_GRE_OPTION:
13865 [ # # ]: 0 : wks->priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
13866 : 0 : wks->tunnel_item = items;
13867 : : last_item = MLX5_FLOW_LAYER_GRE;
13868 : 0 : break;
13869 : 0 : case RTE_FLOW_ITEM_TYPE_NVGRE:
13870 [ # # ]: 0 : wks->priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
13871 : 0 : wks->tunnel_item = items;
13872 : : last_item = MLX5_FLOW_LAYER_GRE;
13873 : 0 : break;
13874 : 0 : case RTE_FLOW_ITEM_TYPE_VXLAN:
13875 : 0 : flow_dv_translate_item_vxlan(dev, wks->attr, key,
13876 : : items, tunnel, wks, key_type);
13877 [ # # ]: 0 : wks->priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
13878 : : last_item = MLX5_FLOW_LAYER_VXLAN;
13879 : 0 : break;
13880 : 0 : case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
13881 [ # # ]: 0 : wks->priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
13882 : 0 : wks->tunnel_item = items;
13883 : : last_item = MLX5_FLOW_LAYER_VXLAN_GPE;
13884 : 0 : break;
13885 : 0 : case RTE_FLOW_ITEM_TYPE_GENEVE:
13886 [ # # ]: 0 : wks->priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
13887 : 0 : wks->tunnel_item = items;
13888 : : last_item = MLX5_FLOW_LAYER_GENEVE;
13889 : 0 : break;
13890 : 0 : case RTE_FLOW_ITEM_TYPE_GENEVE_OPT:
13891 : 0 : ret = flow_dv_translate_item_geneve_opt
13892 : : (dev, key, items, key_type, error);
13893 [ # # ]: 0 : if (ret)
13894 : 0 : return rte_flow_error_set(error, -ret,
13895 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
13896 : : "cannot create GENEVE TLV option");
13897 : 0 : wks->geneve_tlv_option = 1;
13898 : : last_item = MLX5_FLOW_LAYER_GENEVE_OPT;
13899 : 0 : break;
13900 : 0 : case RTE_FLOW_ITEM_TYPE_MPLS:
13901 : 0 : flow_dv_translate_item_mpls(key, items, last_item,
13902 : : tunnel, key_type);
13903 [ # # ]: 0 : wks->priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
13904 : : last_item = MLX5_FLOW_LAYER_MPLS;
13905 : 0 : break;
13906 : 0 : case RTE_FLOW_ITEM_TYPE_MARK:
13907 : 0 : flow_dv_translate_item_mark(dev, key, items, key_type);
13908 : : last_item = MLX5_FLOW_ITEM_MARK;
13909 : 0 : break;
13910 : 0 : case RTE_FLOW_ITEM_TYPE_META:
13911 : 0 : flow_dv_translate_item_meta
13912 : : (dev, key, wks->attr, items, key_type);
13913 : : last_item = MLX5_FLOW_ITEM_METADATA;
13914 : 0 : break;
13915 : 0 : case RTE_FLOW_ITEM_TYPE_ICMP:
13916 : 0 : flow_dv_translate_item_icmp(key, items, tunnel, key_type);
13917 : 0 : wks->priority = MLX5_PRIORITY_MAP_L4;
13918 : : last_item = MLX5_FLOW_LAYER_ICMP;
13919 : 0 : break;
13920 : 0 : case RTE_FLOW_ITEM_TYPE_ICMP6:
13921 : 0 : flow_dv_translate_item_icmp6(key, items, tunnel, key_type);
13922 : 0 : wks->priority = MLX5_PRIORITY_MAP_L4;
13923 : : last_item = MLX5_FLOW_LAYER_ICMP6;
13924 : 0 : break;
13925 : 0 : case RTE_FLOW_ITEM_TYPE_ICMP6_ECHO_REQUEST:
13926 : : case RTE_FLOW_ITEM_TYPE_ICMP6_ECHO_REPLY:
13927 : 0 : flow_dv_translate_item_icmp6_echo(key, items, tunnel, key_type);
13928 : 0 : wks->priority = MLX5_PRIORITY_MAP_L4;
13929 : : last_item = MLX5_FLOW_LAYER_ICMP6;
13930 : 0 : break;
13931 : 0 : case RTE_FLOW_ITEM_TYPE_TAG:
13932 : 0 : flow_dv_translate_item_tag(dev, key, items, key_type);
13933 : : last_item = MLX5_FLOW_ITEM_TAG;
13934 : 0 : break;
13935 : 0 : case MLX5_RTE_FLOW_ITEM_TYPE_TAG:
13936 : 0 : flow_dv_translate_mlx5_item_tag(dev, key, items, key_type);
13937 : : last_item = MLX5_FLOW_ITEM_TAG;
13938 : 0 : break;
13939 : 0 : case MLX5_RTE_FLOW_ITEM_TYPE_SQ:
13940 : 0 : flow_dv_translate_item_sq(key, items, key_type);
13941 : : last_item = MLX5_FLOW_ITEM_SQ;
13942 : 0 : break;
13943 : 0 : case RTE_FLOW_ITEM_TYPE_GTP:
13944 : 0 : flow_dv_translate_item_gtp(key, items, tunnel, key_type);
13945 [ # # ]: 0 : wks->priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
13946 : : last_item = MLX5_FLOW_LAYER_GTP;
13947 : 0 : break;
13948 : 0 : case RTE_FLOW_ITEM_TYPE_GTP_PSC:
13949 : 0 : ret = flow_dv_translate_item_gtp_psc(key, items, key_type);
13950 [ # # ]: 0 : if (ret)
13951 : 0 : return rte_flow_error_set(error, -ret,
13952 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
13953 : : "cannot create GTP PSC item");
13954 : : last_item = MLX5_FLOW_LAYER_GTP_PSC;
13955 : : break;
13956 : 0 : case RTE_FLOW_ITEM_TYPE_ECPRI:
13957 [ # # ]: 0 : if (!mlx5_flex_parser_ecpri_exist(dev)) {
13958 : : /* Create it only the first time to be used. */
13959 : 0 : ret = mlx5_flex_parser_ecpri_alloc(dev);
13960 [ # # ]: 0 : if (ret)
13961 : 0 : return rte_flow_error_set
13962 : : (error, -ret,
13963 : : RTE_FLOW_ERROR_TYPE_ITEM,
13964 : : NULL,
13965 : : "cannot create eCPRI parser");
13966 : : }
13967 : 0 : flow_dv_translate_item_ecpri
13968 : : (dev, key, items, last_item, key_type);
13969 : : /* No other protocol should follow eCPRI layer. */
13970 : : last_item = MLX5_FLOW_LAYER_ECPRI;
13971 : 0 : break;
13972 : 0 : case RTE_FLOW_ITEM_TYPE_METER_COLOR:
13973 : 0 : flow_dv_translate_item_meter_color(dev, key, items, key_type);
13974 : : last_item = MLX5_FLOW_ITEM_METER_COLOR;
13975 : 0 : break;
13976 [ # # ]: 0 : case RTE_FLOW_ITEM_TYPE_INTEGRITY:
13977 : : last_item = flow_dv_translate_item_integrity(items,
13978 : : wks, key_type);
13979 : 0 : break;
13980 : 0 : case RTE_FLOW_ITEM_TYPE_AGGR_AFFINITY:
13981 : 0 : flow_dv_translate_item_aggr_affinity(key, items, key_type);
13982 : : last_item = MLX5_FLOW_ITEM_AGGR_AFFINITY;
13983 : 0 : break;
13984 : 0 : case RTE_FLOW_ITEM_TYPE_IB_BTH:
13985 : 0 : flow_dv_translate_item_ib_bth(key, items, tunnel, key_type);
13986 : : last_item = MLX5_FLOW_ITEM_IB_BTH;
13987 : 0 : break;
13988 : 0 : case RTE_FLOW_ITEM_TYPE_NSH:
13989 : : last_item = MLX5_FLOW_ITEM_NSH;
13990 : 0 : break;
13991 : : default:
13992 : : break;
13993 : : }
13994 : 0 : wks->item_flags |= last_item;
13995 : 0 : wks->last_item = last_item;
13996 : 0 : wks->next_protocol = next_protocol;
13997 : 0 : return 0;
13998 : : }
13999 : :
14000 : : /**
14001 : : * Fill the HW steering flow with DV spec.
14002 : : *
14003 : : * @param[in] items
14004 : : * Pointer to the list of items.
14005 : : * @param[in] attr
14006 : : * Pointer to the flow attributes.
14007 : : * @param[in] key
14008 : : * Pointer to the flow matcher key.
14009 : : * @param[in] key_type
14010 : : * Key type.
14011 : : * @param[in, out] item_flags
14012 : : * Pointer to the flow item flags.
14013 : : * @param[out] error
14014 : : * Pointer to the error structure.
14015 : : *
14016 : : * @return
14017 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
14018 : : */
14019 : : int
14020 : 0 : flow_dv_translate_items_hws(const struct rte_flow_item *items,
14021 : : struct mlx5_flow_attr *attr, void *key,
14022 : : uint32_t key_type, uint64_t *item_flags,
14023 : : uint8_t *match_criteria,
14024 : : struct rte_flow_error *error)
14025 : : {
14026 : 0 : struct mlx5_flow_workspace *flow_wks = mlx5_flow_push_thread_workspace();
14027 : 0 : struct mlx5_flow_rss_desc rss_desc = { .level = attr->rss_level };
14028 : 0 : struct rte_flow_attr rattr = {
14029 : 0 : .group = attr->group,
14030 : 0 : .priority = attr->priority,
14031 : 0 : .ingress = !!(attr->tbl_type == MLX5DR_TABLE_TYPE_NIC_RX),
14032 : 0 : .egress = !!(attr->tbl_type == MLX5DR_TABLE_TYPE_NIC_TX),
14033 : 0 : .transfer = !!(attr->tbl_type == MLX5DR_TABLE_TYPE_FDB),
14034 : : };
14035 : 0 : struct mlx5_dv_matcher_workspace wks = {
14036 : 0 : .action_flags = attr->act_flags,
14037 [ # # ]: 0 : .item_flags = item_flags ? *item_flags : 0,
14038 : : .external = 0,
14039 : : .next_protocol = 0xff,
14040 : : .attr = &rattr,
14041 : : .rss_desc = &rss_desc,
14042 : : };
14043 : : int ret = 0;
14044 : :
14045 : : RTE_SET_USED(flow_wks);
14046 [ # # ]: 0 : for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
14047 : : if (!mlx5_flow_os_item_supported(items->type)) {
14048 : : ret = rte_flow_error_set(error, ENOTSUP,
14049 : : RTE_FLOW_ERROR_TYPE_ITEM,
14050 : : NULL, "item not supported");
14051 : : goto exit;
14052 : : }
14053 : 0 : ret = flow_dv_translate_items(&rte_eth_devices[attr->port_id],
14054 : : items, &wks, key, key_type, NULL);
14055 [ # # ]: 0 : if (ret)
14056 : 0 : goto exit;
14057 : : }
14058 [ # # ]: 0 : if (wks.item_flags & MLX5_FLOW_ITEM_INTEGRITY) {
14059 : 0 : flow_dv_translate_item_integrity_post(key,
14060 : : wks.integrity_items,
14061 : : wks.item_flags,
14062 : : key_type);
14063 : : }
14064 [ # # ]: 0 : if (wks.item_flags & MLX5_FLOW_LAYER_VXLAN_GPE) {
14065 : 0 : flow_dv_translate_item_vxlan_gpe(key,
14066 : : wks.tunnel_item,
14067 : : wks.item_flags,
14068 : : key_type);
14069 [ # # ]: 0 : } else if (wks.item_flags & MLX5_FLOW_LAYER_GENEVE) {
14070 : 0 : flow_dv_translate_item_geneve(key,
14071 : : wks.tunnel_item,
14072 : : wks.item_flags,
14073 : : key_type);
14074 [ # # ]: 0 : } else if (wks.item_flags & MLX5_FLOW_LAYER_GRE) {
14075 [ # # ]: 0 : if (wks.tunnel_item->type == RTE_FLOW_ITEM_TYPE_GRE) {
14076 : 0 : flow_dv_translate_item_gre(key,
14077 : : wks.tunnel_item,
14078 : : wks.item_flags,
14079 : : key_type);
14080 [ # # ]: 0 : } else if (wks.tunnel_item->type == RTE_FLOW_ITEM_TYPE_GRE_OPTION) {
14081 : 0 : flow_dv_translate_item_gre_option(key,
14082 : : wks.tunnel_item,
14083 : : wks.gre_item,
14084 : : wks.item_flags,
14085 : : key_type);
14086 [ # # ]: 0 : } else if (wks.tunnel_item->type == RTE_FLOW_ITEM_TYPE_NVGRE) {
14087 : 0 : flow_dv_translate_item_nvgre(key,
14088 : : wks.tunnel_item,
14089 : : wks.item_flags,
14090 : : key_type);
14091 : : } else {
14092 : : MLX5_ASSERT(false);
14093 : : }
14094 : : }
14095 : :
14096 [ # # ]: 0 : if (match_criteria)
14097 : 0 : *match_criteria = flow_dv_matcher_enable(key);
14098 [ # # ]: 0 : if (item_flags)
14099 : 0 : *item_flags = wks.item_flags;
14100 : 0 : exit:
14101 : 0 : mlx5_flow_pop_thread_workspace();
14102 : 0 : return ret;
14103 : : }
14104 : :
14105 : : /**
14106 : : * Fill the SW steering flow with DV spec.
14107 : : *
14108 : : * @param[in] dev
14109 : : * Pointer to rte_eth_dev structure.
14110 : : * @param[in, out] dev_flow
14111 : : * Pointer to the sub flow.
14112 : : * @param[in] attr
14113 : : * Pointer to the flow attributes.
14114 : : * @param[in] items
14115 : : * Pointer to the list of items.
14116 : : * @param[in, out] matcher
14117 : : * Pointer to the flow matcher.
14118 : : * @param[out] error
14119 : : * Pointer to the error structure.
14120 : : *
14121 : : * @return
14122 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
14123 : : */
14124 : : static int
14125 : 0 : flow_dv_translate_items_sws(struct rte_eth_dev *dev,
14126 : : struct mlx5_flow *dev_flow,
14127 : : const struct rte_flow_attr *attr,
14128 : : const struct rte_flow_item *items,
14129 : : struct mlx5_flow_dv_matcher *matcher,
14130 : : struct rte_flow_error *error)
14131 : : {
14132 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
14133 : 0 : void *match_mask = matcher->mask.buf;
14134 : 0 : void *match_value = dev_flow->dv.value.buf;
14135 : 0 : struct mlx5_dv_matcher_workspace wks = {
14136 : 0 : .action_flags = dev_flow->act_flags,
14137 : : .item_flags = 0,
14138 : 0 : .external = dev_flow->external,
14139 : : .next_protocol = 0xff,
14140 : 0 : .group = dev_flow->dv.group,
14141 : : .attr = attr,
14142 : 0 : .rss_desc = &((struct mlx5_flow_workspace *)
14143 : : mlx5_flow_get_thread_workspace())->rss_desc,
14144 : : };
14145 : 0 : struct mlx5_dv_matcher_workspace wks_m = wks;
14146 : : int item_type;
14147 : : int ret = 0;
14148 : : int tunnel;
14149 : :
14150 [ # # ]: 0 : for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
14151 : 0 : if (!mlx5_flow_os_item_supported(items->type))
14152 : : return rte_flow_error_set(error, ENOTSUP,
14153 : : RTE_FLOW_ERROR_TYPE_ITEM,
14154 : : NULL, "item not supported");
14155 : 0 : tunnel = !!(wks.item_flags & MLX5_FLOW_LAYER_TUNNEL);
14156 : : item_type = items->type;
14157 [ # # # # ]: 0 : switch (item_type) {
14158 : 0 : case RTE_FLOW_ITEM_TYPE_CONNTRACK:
14159 : 0 : flow_dv_translate_item_aso_ct(dev, match_mask,
14160 : : match_value, items);
14161 : 0 : break;
14162 : 0 : case RTE_FLOW_ITEM_TYPE_FLEX:
14163 : 0 : flow_dv_translate_item_flex(dev, match_mask,
14164 : : match_value, items,
14165 : : dev_flow, tunnel != 0);
14166 [ # # ]: 0 : wks.last_item = tunnel ? MLX5_FLOW_ITEM_INNER_FLEX :
14167 : : MLX5_FLOW_ITEM_OUTER_FLEX;
14168 : 0 : break;
14169 : 0 : case MLX5_RTE_FLOW_ITEM_TYPE_SQ:
14170 : 0 : flow_dv_translate_item_sq(match_value, items,
14171 : : MLX5_SET_MATCHER_SW_V);
14172 : 0 : flow_dv_translate_item_sq(match_mask, items,
14173 : : MLX5_SET_MATCHER_SW_M);
14174 : 0 : break;
14175 : 0 : default:
14176 : 0 : ret = flow_dv_translate_items(dev, items, &wks_m,
14177 : : match_mask, MLX5_SET_MATCHER_SW_M, error);
14178 [ # # ]: 0 : if (ret)
14179 : 0 : return ret;
14180 : 0 : ret = flow_dv_translate_items(dev, items, &wks,
14181 : : match_value, MLX5_SET_MATCHER_SW_V, error);
14182 [ # # ]: 0 : if (ret)
14183 : 0 : return ret;
14184 : : break;
14185 : : }
14186 : 0 : wks.item_flags |= wks.last_item;
14187 : : }
14188 : : /*
14189 : : * When E-Switch mode is enabled, we have two cases where we need to
14190 : : * set the source port manually.
14191 : : * The first one, is in case of NIC ingress steering rule, and the
14192 : : * second is E-Switch rule where no port_id item was found.
14193 : : * In both cases the source port is set according the current port
14194 : : * in use.
14195 : : */
14196 : 0 : if (!(wks.item_flags & MLX5_FLOW_ITEM_PORT_ID) &&
14197 [ # # ]: 0 : !(wks.item_flags & MLX5_FLOW_ITEM_REPRESENTED_PORT) &&
14198 : 0 : !(wks.item_flags & MLX5_FLOW_ITEM_PORT_REPRESENTOR) &&
14199 [ # # ]: 0 : priv->sh->esw_mode &&
14200 [ # # ]: 0 : !attr->egress &&
14201 [ # # ]: 0 : attr->group != MLX5_FLOW_MREG_CP_TABLE_GROUP) {
14202 [ # # ]: 0 : if (flow_dv_translate_item_port_id_all(dev, match_mask,
14203 : : match_value, NULL, attr))
14204 : 0 : return -rte_errno;
14205 : : }
14206 [ # # ]: 0 : if (wks.item_flags & MLX5_FLOW_ITEM_INTEGRITY) {
14207 : 0 : flow_dv_translate_item_integrity_post(match_mask,
14208 : : wks_m.integrity_items,
14209 : : wks_m.item_flags,
14210 : : MLX5_SET_MATCHER_SW_M);
14211 : 0 : flow_dv_translate_item_integrity_post(match_value,
14212 : : wks.integrity_items,
14213 : : wks.item_flags,
14214 : : MLX5_SET_MATCHER_SW_V);
14215 : : }
14216 [ # # ]: 0 : if (wks.item_flags & MLX5_FLOW_LAYER_VXLAN_GPE) {
14217 : 0 : flow_dv_translate_item_vxlan_gpe(match_mask,
14218 : : wks.tunnel_item,
14219 : : wks.item_flags,
14220 : : MLX5_SET_MATCHER_SW_M);
14221 : 0 : flow_dv_translate_item_vxlan_gpe(match_value,
14222 : : wks.tunnel_item,
14223 : : wks.item_flags,
14224 : : MLX5_SET_MATCHER_SW_V);
14225 [ # # ]: 0 : } else if (wks.item_flags & MLX5_FLOW_LAYER_GENEVE) {
14226 : 0 : flow_dv_translate_item_geneve(match_mask,
14227 : : wks.tunnel_item,
14228 : : wks.item_flags,
14229 : : MLX5_SET_MATCHER_SW_M);
14230 : 0 : flow_dv_translate_item_geneve(match_value,
14231 : : wks.tunnel_item,
14232 : : wks.item_flags,
14233 : : MLX5_SET_MATCHER_SW_V);
14234 [ # # ]: 0 : } else if (wks.item_flags & MLX5_FLOW_LAYER_GRE) {
14235 [ # # ]: 0 : if (wks.tunnel_item->type == RTE_FLOW_ITEM_TYPE_GRE) {
14236 : 0 : flow_dv_translate_item_gre(match_mask,
14237 : : wks.tunnel_item,
14238 : : wks.item_flags,
14239 : : MLX5_SET_MATCHER_SW_M);
14240 : 0 : flow_dv_translate_item_gre(match_value,
14241 : : wks.tunnel_item,
14242 : : wks.item_flags,
14243 : : MLX5_SET_MATCHER_SW_V);
14244 [ # # ]: 0 : } else if (wks.tunnel_item->type == RTE_FLOW_ITEM_TYPE_NVGRE) {
14245 : 0 : flow_dv_translate_item_nvgre(match_mask,
14246 : : wks.tunnel_item,
14247 : : wks.item_flags,
14248 : : MLX5_SET_MATCHER_SW_M);
14249 : 0 : flow_dv_translate_item_nvgre(match_value,
14250 : : wks.tunnel_item,
14251 : : wks.item_flags,
14252 : : MLX5_SET_MATCHER_SW_V);
14253 [ # # ]: 0 : } else if (wks.tunnel_item->type == RTE_FLOW_ITEM_TYPE_GRE_OPTION) {
14254 : 0 : flow_dv_translate_item_gre_option(match_mask,
14255 : : wks.tunnel_item,
14256 : : wks.gre_item,
14257 : : wks.item_flags,
14258 : : MLX5_SET_MATCHER_SW_M);
14259 : 0 : flow_dv_translate_item_gre_option(match_value,
14260 : : wks.tunnel_item,
14261 : : wks.gre_item,
14262 : : wks.item_flags,
14263 : : MLX5_SET_MATCHER_SW_V);
14264 : : } else {
14265 : : MLX5_ASSERT(false);
14266 : : }
14267 : : }
14268 : 0 : dev_flow->handle->vf_vlan.tag = wks.vlan_tag;
14269 : 0 : matcher->priority = wks.priority;
14270 : : #ifdef RTE_LIBRTE_MLX5_DEBUG
14271 : : MLX5_ASSERT(!flow_dv_check_valid_spec(match_mask, match_value));
14272 : : #endif
14273 : : /*
14274 : : * Layers may be already initialized from prefix flow if this dev_flow
14275 : : * is the suffix flow.
14276 : : */
14277 : 0 : dev_flow->handle->layers |= wks.item_flags;
14278 : : /*
14279 : : * Update geneve_tlv_option flag only it is set in workspace.
14280 : : * Avoid be overwritten by other sub mlx5_flows.
14281 : : */
14282 [ # # ]: 0 : if (wks.geneve_tlv_option)
14283 : 0 : dev_flow->flow->geneve_tlv_option = wks.geneve_tlv_option;
14284 : : return 0;
14285 : : }
14286 : :
14287 : : /**
14288 : : * Fill the flow with DV spec, lock free
14289 : : * (mutex should be acquired by caller).
14290 : : *
14291 : : * @param[in] dev
14292 : : * Pointer to rte_eth_dev structure.
14293 : : * @param[in, out] dev_flow
14294 : : * Pointer to the sub flow.
14295 : : * @param[in] attr
14296 : : * Pointer to the flow attributes.
14297 : : * @param[in] items
14298 : : * Pointer to the list of items.
14299 : : * @param[in] actions
14300 : : * Pointer to the list of actions.
14301 : : * @param[out] error
14302 : : * Pointer to the error structure.
14303 : : *
14304 : : * @return
14305 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
14306 : : */
14307 : : static int
14308 : 0 : flow_dv_translate(struct rte_eth_dev *dev,
14309 : : struct mlx5_flow *dev_flow,
14310 : : const struct rte_flow_attr *attr,
14311 : : const struct rte_flow_item items[],
14312 : : const struct rte_flow_action actions[],
14313 : : struct rte_flow_error *error)
14314 : : {
14315 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
14316 : 0 : struct mlx5_sh_config *dev_conf = &priv->sh->config;
14317 : 0 : struct rte_flow *flow = dev_flow->flow;
14318 : 0 : struct mlx5_flow_handle *handle = dev_flow->handle;
14319 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
14320 : : struct mlx5_flow_rss_desc *rss_desc;
14321 : : uint64_t action_flags = 0;
14322 : 0 : struct mlx5_flow_dv_matcher matcher = {
14323 : : .mask = {
14324 : : .size = sizeof(matcher.mask.buf),
14325 : : },
14326 : : };
14327 : : int actions_n = 0;
14328 : : bool actions_end = false;
14329 : : union {
14330 : : struct mlx5_flow_dv_modify_hdr_resource res;
14331 : : uint8_t len[sizeof(struct mlx5_flow_dv_modify_hdr_resource) +
14332 : : sizeof(struct mlx5_modification_cmd) *
14333 : : (MLX5_MAX_MODIFY_NUM + 1)];
14334 : : } mhdr_dummy;
14335 : : struct mlx5_flow_dv_modify_hdr_resource *mhdr_res = &mhdr_dummy.res;
14336 : : const struct rte_flow_action_count *count = NULL;
14337 : : const struct rte_flow_action_age *non_shared_age = NULL;
14338 : 0 : union flow_dv_attr flow_attr = { .attr = 0 };
14339 : : uint32_t tag_be;
14340 : : union mlx5_flow_tbl_key tbl_key;
14341 : : uint32_t modify_action_position = UINT32_MAX;
14342 : 0 : struct rte_vlan_hdr vlan = { 0 };
14343 : : struct mlx5_flow_dv_dest_array_resource mdest_res;
14344 : : struct mlx5_flow_dv_sample_resource sample_res;
14345 : 0 : void *sample_actions[MLX5_DV_MAX_NUMBER_OF_ACTIONS] = {0};
14346 : : const struct rte_flow_action_sample *sample = NULL;
14347 : : struct mlx5_flow_sub_actions_list *sample_act;
14348 : : uint32_t sample_act_pos = UINT32_MAX;
14349 : : uint32_t age_act_pos = UINT32_MAX;
14350 : 0 : uint32_t num_of_dest = 0;
14351 : : int tmp_actions_n = 0;
14352 : : uint32_t table;
14353 : : int ret = 0;
14354 : : const struct mlx5_flow_tunnel *tunnel = NULL;
14355 : 0 : struct flow_grp_info grp_info = {
14356 : 0 : .external = !!dev_flow->external,
14357 : 0 : .transfer = !!attr->transfer,
14358 : 0 : .fdb_def_rule = !!priv->fdb_def_rule,
14359 : 0 : .skip_scale = dev_flow->skip_scale &
14360 : : (1 << MLX5_SCALE_FLOW_GROUP_BIT),
14361 : : .std_tbl_fix = true,
14362 : : };
14363 : :
14364 [ # # ]: 0 : if (!wks)
14365 : 0 : return rte_flow_error_set(error, ENOMEM,
14366 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
14367 : : NULL,
14368 : : "failed to push flow workspace");
14369 [ # # ]: 0 : rss_desc = &wks->rss_desc;
14370 : : memset(&mdest_res, 0, sizeof(struct mlx5_flow_dv_dest_array_resource));
14371 : : memset(&sample_res, 0, sizeof(struct mlx5_flow_dv_sample_resource));
14372 [ # # ]: 0 : mhdr_res->ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
14373 : : MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
14374 : : /* update normal path action resource into last index of array */
14375 : : sample_act = &mdest_res.sample_act[MLX5_MAX_DEST_NUM - 1];
14376 [ # # ]: 0 : if (is_tunnel_offload_active(dev)) {
14377 [ # # ]: 0 : if (dev_flow->tunnel) {
14378 [ # # ]: 0 : RTE_VERIFY(dev_flow->tof_type ==
14379 : : MLX5_TUNNEL_OFFLOAD_MISS_RULE);
14380 : : tunnel = dev_flow->tunnel;
14381 : : } else {
14382 : 0 : tunnel = mlx5_get_tof(items, actions,
14383 : : &dev_flow->tof_type);
14384 : 0 : dev_flow->tunnel = tunnel;
14385 : : }
14386 [ # # ]: 0 : grp_info.std_tbl_fix = tunnel_use_standard_attr_group_translate
14387 : : (dev, attr, tunnel, dev_flow->tof_type);
14388 : : }
14389 : 0 : mhdr_res->ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
14390 : : MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
14391 : 0 : ret = mlx5_flow_group_to_table(dev, tunnel, attr->group, &table,
14392 : : &grp_info, error);
14393 [ # # ]: 0 : if (ret)
14394 : : return ret;
14395 : 0 : dev_flow->dv.group = table;
14396 [ # # ]: 0 : if (attr->transfer)
14397 : 0 : mhdr_res->ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
14398 : : /* number of actions must be set to 0 in case of dirty stack. */
14399 : 0 : mhdr_res->actions_num = 0;
14400 [ # # ]: 0 : if (is_flow_tunnel_match_rule(dev_flow->tof_type)) {
14401 : : /*
14402 : : * do not add decap action if match rule drops packet
14403 : : * HW rejects rules with decap & drop
14404 : : *
14405 : : * if tunnel match rule was inserted before matching tunnel set
14406 : : * rule flow table used in the match rule must be registered.
14407 : : * current implementation handles that in the
14408 : : * flow_dv_match_register() at the function end.
14409 : : */
14410 : : bool add_decap = true;
14411 : : const struct rte_flow_action *ptr = actions;
14412 : :
14413 [ # # ]: 0 : for (; ptr->type != RTE_FLOW_ACTION_TYPE_END; ptr++) {
14414 [ # # ]: 0 : if (ptr->type == RTE_FLOW_ACTION_TYPE_DROP) {
14415 : : add_decap = false;
14416 : : break;
14417 : : }
14418 : : }
14419 [ # # ]: 0 : if (add_decap) {
14420 [ # # ]: 0 : if (flow_dv_create_action_l2_decap(dev, dev_flow,
14421 : 0 : attr->transfer,
14422 : : error))
14423 : 0 : return -rte_errno;
14424 : 0 : dev_flow->dv.actions[actions_n++] =
14425 : 0 : dev_flow->dv.encap_decap->action;
14426 : : action_flags |= MLX5_FLOW_ACTION_DECAP;
14427 : : }
14428 : : }
14429 [ # # ]: 0 : for (; !actions_end ; actions++) {
14430 : : const struct rte_flow_action_queue *queue;
14431 : : const struct rte_flow_action_rss *rss;
14432 : : const struct rte_flow_action *action = actions;
14433 : : const uint8_t *rss_key;
14434 : : struct mlx5_flow_tbl_resource *tbl;
14435 : : struct mlx5_aso_age_action *age_act;
14436 : : struct mlx5_flow_counter *cnt_act;
14437 : 0 : uint32_t port_id = 0;
14438 : : struct mlx5_flow_dv_port_id_action_resource port_id_resource;
14439 : 0 : int action_type = actions->type;
14440 : : const struct rte_flow_action *found_action = NULL;
14441 : : uint32_t jump_group = 0;
14442 : : uint32_t owner_idx;
14443 : : struct mlx5_aso_ct_action *ct;
14444 : :
14445 : : if (!mlx5_flow_os_action_supported(action_type))
14446 : 0 : return rte_flow_error_set(error, ENOTSUP,
14447 : : RTE_FLOW_ERROR_TYPE_ACTION,
14448 : : actions,
14449 : : "action not supported");
14450 [ # # # # : 0 : switch (action_type) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # ]
14451 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET:
14452 : 0 : action_flags |= MLX5_FLOW_ACTION_TUNNEL_SET;
14453 : 0 : break;
14454 : : case RTE_FLOW_ACTION_TYPE_VOID:
14455 : : break;
14456 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_ID:
14457 : : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
14458 [ # # ]: 0 : if (flow_dv_translate_action_port_id(dev, action,
14459 : : &port_id, error))
14460 : 0 : return -rte_errno;
14461 : 0 : port_id_resource.port_id = port_id;
14462 : : MLX5_ASSERT(!handle->rix_port_id_action);
14463 [ # # ]: 0 : if (flow_dv_port_id_action_resource_register
14464 : : (dev, &port_id_resource, dev_flow, error))
14465 : 0 : return -rte_errno;
14466 : 0 : dev_flow->dv.actions[actions_n++] =
14467 : 0 : dev_flow->dv.port_id_action->action;
14468 : 0 : action_flags |= MLX5_FLOW_ACTION_PORT_ID;
14469 : 0 : dev_flow->handle->fate_action = MLX5_FLOW_FATE_PORT_ID;
14470 : 0 : sample_act->action_flags |= MLX5_FLOW_ACTION_PORT_ID;
14471 : 0 : num_of_dest++;
14472 : 0 : break;
14473 : 0 : case RTE_FLOW_ACTION_TYPE_FLAG:
14474 : 0 : action_flags |= MLX5_FLOW_ACTION_FLAG;
14475 : 0 : wks->mark = 1;
14476 [ # # ]: 0 : if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
14477 : 0 : struct rte_flow_action_mark mark = {
14478 : : .id = MLX5_FLOW_MARK_DEFAULT,
14479 : : };
14480 : :
14481 [ # # ]: 0 : if (flow_dv_convert_action_mark(dev, &mark,
14482 : : mhdr_res,
14483 : : error))
14484 : 0 : return -rte_errno;
14485 : 0 : action_flags |= MLX5_FLOW_ACTION_MARK_EXT;
14486 : 0 : break;
14487 : : }
14488 : : tag_be = mlx5_flow_mark_set(MLX5_FLOW_MARK_DEFAULT);
14489 : : /*
14490 : : * Only one FLAG or MARK is supported per device flow
14491 : : * right now. So the pointer to the tag resource must be
14492 : : * zero before the register process.
14493 : : */
14494 : : MLX5_ASSERT(!handle->dvh.rix_tag);
14495 [ # # ]: 0 : if (flow_dv_tag_resource_register(dev, tag_be,
14496 : : dev_flow, error))
14497 : 0 : return -rte_errno;
14498 : : MLX5_ASSERT(dev_flow->dv.tag_resource);
14499 : 0 : dev_flow->dv.actions[actions_n++] =
14500 : 0 : dev_flow->dv.tag_resource->action;
14501 : 0 : break;
14502 : 0 : case RTE_FLOW_ACTION_TYPE_MARK:
14503 : 0 : action_flags |= MLX5_FLOW_ACTION_MARK;
14504 : 0 : wks->mark = 1;
14505 [ # # ]: 0 : if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
14506 : 0 : const struct rte_flow_action_mark *mark =
14507 : : (const struct rte_flow_action_mark *)
14508 : : actions->conf;
14509 : :
14510 [ # # ]: 0 : if (flow_dv_convert_action_mark(dev, mark,
14511 : : mhdr_res,
14512 : : error))
14513 : 0 : return -rte_errno;
14514 : 0 : action_flags |= MLX5_FLOW_ACTION_MARK_EXT;
14515 : 0 : break;
14516 : : }
14517 : : /* Fall-through */
14518 : : case MLX5_RTE_FLOW_ACTION_TYPE_MARK:
14519 : : /* Legacy (non-extensive) MARK action. */
14520 : : tag_be = mlx5_flow_mark_set
14521 : : (((const struct rte_flow_action_mark *)
14522 [ # # ]: 0 : (actions->conf))->id);
14523 : : MLX5_ASSERT(!handle->dvh.rix_tag);
14524 [ # # ]: 0 : if (flow_dv_tag_resource_register(dev, tag_be,
14525 : : dev_flow, error))
14526 : 0 : return -rte_errno;
14527 : : MLX5_ASSERT(dev_flow->dv.tag_resource);
14528 : 0 : dev_flow->dv.actions[actions_n++] =
14529 : 0 : dev_flow->dv.tag_resource->action;
14530 : 0 : break;
14531 : 0 : case RTE_FLOW_ACTION_TYPE_SET_META:
14532 [ # # ]: 0 : if (flow_dv_convert_action_set_meta
14533 : : (dev, mhdr_res, attr,
14534 : : (const struct rte_flow_action_set_meta *)
14535 : 0 : actions->conf, error))
14536 : 0 : return -rte_errno;
14537 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_META;
14538 : 0 : break;
14539 : 0 : case RTE_FLOW_ACTION_TYPE_SET_TAG:
14540 [ # # ]: 0 : if (flow_dv_convert_action_set_tag
14541 : : (dev, mhdr_res,
14542 : : (const struct rte_flow_action_set_tag *)
14543 : 0 : actions->conf, error))
14544 : 0 : return -rte_errno;
14545 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_TAG;
14546 : 0 : break;
14547 : 0 : case RTE_FLOW_ACTION_TYPE_DROP:
14548 : 0 : action_flags |= MLX5_FLOW_ACTION_DROP;
14549 : 0 : dev_flow->handle->fate_action = MLX5_FLOW_FATE_DROP;
14550 : 0 : break;
14551 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
14552 : 0 : queue = actions->conf;
14553 : 0 : rss_desc->queue_num = 1;
14554 : 0 : rss_desc->queue[0] = queue->index;
14555 : 0 : action_flags |= MLX5_FLOW_ACTION_QUEUE;
14556 : 0 : dev_flow->handle->fate_action = MLX5_FLOW_FATE_QUEUE;
14557 : 0 : sample_act->action_flags |= MLX5_FLOW_ACTION_QUEUE;
14558 : 0 : num_of_dest++;
14559 : 0 : break;
14560 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
14561 : 0 : rss = actions->conf;
14562 : 0 : rss_desc->symmetric_hash_function =
14563 : 0 : MLX5_RSS_IS_SYMM(rss->func);
14564 : 0 : memcpy(rss_desc->queue, rss->queue,
14565 [ # # ]: 0 : rss->queue_num * sizeof(uint16_t));
14566 : 0 : rss_desc->queue_num = rss->queue_num;
14567 : : /* NULL RSS key indicates default RSS key. */
14568 [ # # ]: 0 : rss_key = !rss->key ? rss_hash_default_key : rss->key;
14569 [ # # ]: 0 : memcpy(rss_desc->key, rss_key, MLX5_RSS_HASH_KEY_LEN);
14570 : : /*
14571 : : * rss->level and rss.types should be set in advance
14572 : : * when expanding items for RSS.
14573 : : */
14574 : 0 : action_flags |= MLX5_FLOW_ACTION_RSS;
14575 : 0 : dev_flow->handle->fate_action = rss_desc->shared_rss ?
14576 [ # # ]: 0 : MLX5_FLOW_FATE_SHARED_RSS :
14577 : : MLX5_FLOW_FATE_QUEUE;
14578 : 0 : break;
14579 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_AGE:
14580 : 0 : owner_idx = (uint32_t)(uintptr_t)action->conf;
14581 : 0 : age_act = flow_aso_age_get_by_idx(dev, owner_idx);
14582 [ # # ]: 0 : if (flow->age == 0) {
14583 : 0 : flow->age = owner_idx;
14584 : 0 : __atomic_fetch_add(&age_act->refcnt, 1,
14585 : : __ATOMIC_RELAXED);
14586 : : }
14587 : 0 : age_act_pos = actions_n++;
14588 : 0 : action_flags |= MLX5_FLOW_ACTION_AGE;
14589 : 0 : break;
14590 : 0 : case RTE_FLOW_ACTION_TYPE_SEND_TO_KERNEL:
14591 : 0 : dev_flow->dv.actions[actions_n] =
14592 : 0 : flow_dv_translate_action_send_to_kernel(dev, attr,
14593 : : error);
14594 [ # # ]: 0 : if (!dev_flow->dv.actions[actions_n])
14595 : 0 : return -rte_errno;
14596 : 0 : actions_n++;
14597 : 0 : action_flags |= MLX5_FLOW_ACTION_SEND_TO_KERNEL;
14598 : 0 : dev_flow->handle->fate_action =
14599 : : MLX5_FLOW_FATE_SEND_TO_KERNEL;
14600 : 0 : break;
14601 : 0 : case RTE_FLOW_ACTION_TYPE_AGE:
14602 : 0 : non_shared_age = action->conf;
14603 : 0 : age_act_pos = actions_n++;
14604 : 0 : action_flags |= MLX5_FLOW_ACTION_AGE;
14605 : 0 : break;
14606 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_COUNT:
14607 [ # # ]: 0 : owner_idx = (uint32_t)(uintptr_t)action->conf;
14608 : : cnt_act = flow_dv_counter_get_by_idx(dev, owner_idx,
14609 : : NULL);
14610 : : MLX5_ASSERT(cnt_act != NULL);
14611 : : /**
14612 : : * When creating meter drop flow in drop table, the
14613 : : * counter should not overwrite the rte flow counter.
14614 : : */
14615 [ # # ]: 0 : if (attr->group == MLX5_FLOW_TABLE_LEVEL_METER &&
14616 [ # # ]: 0 : dev_flow->dv.table_id == MLX5_MTR_TABLE_ID_DROP) {
14617 : 0 : dev_flow->dv.actions[actions_n++] =
14618 : 0 : cnt_act->action;
14619 : : } else {
14620 [ # # ]: 0 : if (flow->counter == 0) {
14621 : 0 : flow->counter = owner_idx;
14622 : 0 : __atomic_fetch_add
14623 : 0 : (&cnt_act->shared_info.refcnt,
14624 : : 1, __ATOMIC_RELAXED);
14625 : : }
14626 : : /* Save information first, will apply later. */
14627 : 0 : action_flags |= MLX5_FLOW_ACTION_COUNT;
14628 : : }
14629 : : break;
14630 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
14631 [ # # ]: 0 : if (!priv->sh->cdev->config.devx) {
14632 : 0 : return rte_flow_error_set
14633 : : (error, ENOTSUP,
14634 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
14635 : : NULL,
14636 : : "count action not supported");
14637 : : }
14638 : : /* Save information first, will apply later. */
14639 : 0 : count = action->conf;
14640 : 0 : action_flags |= MLX5_FLOW_ACTION_COUNT;
14641 : 0 : break;
14642 : 0 : case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
14643 : 0 : dev_flow->dv.actions[actions_n++] =
14644 : 0 : priv->sh->pop_vlan_action;
14645 : 0 : action_flags |= MLX5_FLOW_ACTION_OF_POP_VLAN;
14646 : 0 : break;
14647 : 0 : case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
14648 [ # # ]: 0 : if (!(action_flags &
14649 : : MLX5_FLOW_ACTION_OF_SET_VLAN_VID))
14650 : 0 : flow_dev_get_vlan_info_from_items(items, &vlan);
14651 [ # # ]: 0 : vlan.eth_proto = rte_be_to_cpu_16
14652 : : ((((const struct rte_flow_action_of_push_vlan *)
14653 : : actions->conf)->ethertype));
14654 : 0 : found_action = mlx5_flow_find_action
14655 : : (actions + 1,
14656 : : RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID);
14657 [ # # ]: 0 : if (found_action)
14658 : 0 : mlx5_update_vlan_vid_pcp(found_action, &vlan);
14659 : 0 : found_action = mlx5_flow_find_action
14660 : : (actions + 1,
14661 : : RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP);
14662 [ # # ]: 0 : if (found_action)
14663 : 0 : mlx5_update_vlan_vid_pcp(found_action, &vlan);
14664 [ # # ]: 0 : if (flow_dv_create_action_push_vlan
14665 : : (dev, attr, &vlan, dev_flow, error))
14666 : 0 : return -rte_errno;
14667 : 0 : dev_flow->dv.actions[actions_n++] =
14668 : 0 : dev_flow->dv.push_vlan_res->action;
14669 : 0 : action_flags |= MLX5_FLOW_ACTION_OF_PUSH_VLAN;
14670 : 0 : break;
14671 : : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
14672 : : /* of_vlan_push action handled this action */
14673 : : MLX5_ASSERT(action_flags &
14674 : : MLX5_FLOW_ACTION_OF_PUSH_VLAN);
14675 : : break;
14676 : 0 : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
14677 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN)
14678 : : break;
14679 : 0 : flow_dev_get_vlan_info_from_items(items, &vlan);
14680 : 0 : mlx5_update_vlan_vid_pcp(actions, &vlan);
14681 : : /* If no VLAN push - this is a modify header action */
14682 [ # # ]: 0 : if (flow_dv_convert_action_modify_vlan_vid
14683 : : (mhdr_res, actions, error))
14684 : 0 : return -rte_errno;
14685 : 0 : action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_VID;
14686 : 0 : break;
14687 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
14688 : : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
14689 [ # # ]: 0 : if (flow_dv_create_action_l2_encap(dev, actions,
14690 : : dev_flow,
14691 : 0 : attr->transfer,
14692 : : error))
14693 : 0 : return -rte_errno;
14694 : 0 : dev_flow->dv.actions[actions_n++] =
14695 : 0 : dev_flow->dv.encap_decap->action;
14696 : 0 : action_flags |= MLX5_FLOW_ACTION_ENCAP;
14697 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
14698 : 0 : sample_act->action_flags |=
14699 : : MLX5_FLOW_ACTION_ENCAP;
14700 : : break;
14701 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
14702 : : case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
14703 [ # # ]: 0 : if (flow_dv_create_action_l2_decap(dev, dev_flow,
14704 : 0 : attr->transfer,
14705 : : error))
14706 : 0 : return -rte_errno;
14707 : 0 : dev_flow->dv.actions[actions_n++] =
14708 : 0 : dev_flow->dv.encap_decap->action;
14709 : 0 : action_flags |= MLX5_FLOW_ACTION_DECAP;
14710 : 0 : break;
14711 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
14712 : : /* Handle encap with preceding decap. */
14713 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_DECAP) {
14714 [ # # ]: 0 : if (flow_dv_create_action_raw_encap
14715 : : (dev, actions, dev_flow, attr, error))
14716 : 0 : return -rte_errno;
14717 : 0 : dev_flow->dv.actions[actions_n++] =
14718 : 0 : dev_flow->dv.encap_decap->action;
14719 : : } else {
14720 : : /* Handle encap without preceding decap. */
14721 [ # # ]: 0 : if (flow_dv_create_action_l2_encap
14722 : 0 : (dev, actions, dev_flow, attr->transfer,
14723 : : error))
14724 : 0 : return -rte_errno;
14725 : 0 : dev_flow->dv.actions[actions_n++] =
14726 : 0 : dev_flow->dv.encap_decap->action;
14727 : : }
14728 : 0 : action_flags |= MLX5_FLOW_ACTION_ENCAP;
14729 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
14730 : 0 : sample_act->action_flags |=
14731 : : MLX5_FLOW_ACTION_ENCAP;
14732 : : break;
14733 : : case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
14734 [ # # ]: 0 : while ((++action)->type == RTE_FLOW_ACTION_TYPE_VOID)
14735 : : ;
14736 [ # # ]: 0 : if (action->type != RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
14737 [ # # ]: 0 : if (flow_dv_create_action_l2_decap
14738 : 0 : (dev, dev_flow, attr->transfer, error))
14739 : 0 : return -rte_errno;
14740 : 0 : dev_flow->dv.actions[actions_n++] =
14741 : 0 : dev_flow->dv.encap_decap->action;
14742 : : }
14743 : : /* If decap is followed by encap, handle it at encap. */
14744 : 0 : action_flags |= MLX5_FLOW_ACTION_DECAP;
14745 : 0 : break;
14746 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_JUMP:
14747 : 0 : dev_flow->dv.actions[actions_n++] =
14748 : 0 : (void *)(uintptr_t)action->conf;
14749 : 0 : action_flags |= MLX5_FLOW_ACTION_JUMP;
14750 : 0 : break;
14751 : 0 : case RTE_FLOW_ACTION_TYPE_JUMP:
14752 : 0 : jump_group = ((const struct rte_flow_action_jump *)
14753 : 0 : action->conf)->group;
14754 : 0 : grp_info.std_tbl_fix = 0;
14755 [ # # ]: 0 : if (dev_flow->skip_scale &
14756 : : (1 << MLX5_SCALE_JUMP_FLOW_GROUP_BIT))
14757 : 0 : grp_info.skip_scale = 1;
14758 : : else
14759 : 0 : grp_info.skip_scale = 0;
14760 : 0 : ret = mlx5_flow_group_to_table(dev, tunnel,
14761 : : jump_group,
14762 : : &table,
14763 : : &grp_info, error);
14764 [ # # ]: 0 : if (ret)
14765 : 0 : return ret;
14766 : 0 : tbl = flow_dv_tbl_resource_get(dev, table, attr->egress,
14767 : 0 : attr->transfer,
14768 : 0 : !!dev_flow->external,
14769 : : tunnel, jump_group, 0,
14770 : : 0, error);
14771 [ # # ]: 0 : if (!tbl)
14772 : 0 : return rte_flow_error_set
14773 : 0 : (error, errno,
14774 : : RTE_FLOW_ERROR_TYPE_ACTION,
14775 : : NULL,
14776 : : "cannot create jump action.");
14777 : : if (flow_dv_jump_tbl_resource_register
14778 : : (dev, tbl, dev_flow, error)) {
14779 : : flow_dv_tbl_resource_release(MLX5_SH(dev), tbl);
14780 : : return rte_flow_error_set
14781 : : (error, errno,
14782 : : RTE_FLOW_ERROR_TYPE_ACTION,
14783 : : NULL,
14784 : : "cannot create jump action.");
14785 : : }
14786 : 0 : dev_flow->dv.actions[actions_n++] =
14787 : 0 : dev_flow->dv.jump->action;
14788 : 0 : action_flags |= MLX5_FLOW_ACTION_JUMP;
14789 : 0 : dev_flow->handle->fate_action = MLX5_FLOW_FATE_JUMP;
14790 : 0 : sample_act->action_flags |= MLX5_FLOW_ACTION_JUMP;
14791 : 0 : num_of_dest++;
14792 : 0 : break;
14793 : 0 : case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
14794 : : case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
14795 [ # # ]: 0 : if (flow_dv_convert_action_modify_mac
14796 : : (mhdr_res, actions, error))
14797 : 0 : return -rte_errno;
14798 : 0 : action_flags |= actions->type ==
14799 : : RTE_FLOW_ACTION_TYPE_SET_MAC_SRC ?
14800 [ # # ]: 0 : MLX5_FLOW_ACTION_SET_MAC_SRC :
14801 : : MLX5_FLOW_ACTION_SET_MAC_DST;
14802 : 0 : break;
14803 : 0 : case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
14804 : : case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
14805 [ # # ]: 0 : if (flow_dv_convert_action_modify_ipv4
14806 : : (mhdr_res, actions, error))
14807 : 0 : return -rte_errno;
14808 : 0 : action_flags |= actions->type ==
14809 : : RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC ?
14810 [ # # ]: 0 : MLX5_FLOW_ACTION_SET_IPV4_SRC :
14811 : : MLX5_FLOW_ACTION_SET_IPV4_DST;
14812 : 0 : break;
14813 : 0 : case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
14814 : : case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
14815 [ # # ]: 0 : if (flow_dv_convert_action_modify_ipv6
14816 : : (mhdr_res, actions, error))
14817 : 0 : return -rte_errno;
14818 : 0 : action_flags |= actions->type ==
14819 : : RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC ?
14820 [ # # ]: 0 : MLX5_FLOW_ACTION_SET_IPV6_SRC :
14821 : : MLX5_FLOW_ACTION_SET_IPV6_DST;
14822 : 0 : break;
14823 : 0 : case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
14824 : : case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
14825 [ # # ]: 0 : if (flow_dv_convert_action_modify_tp
14826 : : (mhdr_res, actions, items,
14827 : 0 : &flow_attr, dev_flow, !!(action_flags &
14828 : : MLX5_FLOW_ACTION_DECAP), error))
14829 : 0 : return -rte_errno;
14830 : 0 : action_flags |= actions->type ==
14831 : : RTE_FLOW_ACTION_TYPE_SET_TP_SRC ?
14832 [ # # ]: 0 : MLX5_FLOW_ACTION_SET_TP_SRC :
14833 : : MLX5_FLOW_ACTION_SET_TP_DST;
14834 : 0 : break;
14835 : 0 : case RTE_FLOW_ACTION_TYPE_DEC_TTL:
14836 [ # # ]: 0 : if (flow_dv_convert_action_modify_dec_ttl
14837 : : (mhdr_res, items, &flow_attr, dev_flow,
14838 : 0 : !!(action_flags &
14839 : : MLX5_FLOW_ACTION_DECAP), error))
14840 : 0 : return -rte_errno;
14841 : 0 : action_flags |= MLX5_FLOW_ACTION_DEC_TTL;
14842 : 0 : break;
14843 : 0 : case RTE_FLOW_ACTION_TYPE_SET_TTL:
14844 [ # # ]: 0 : if (flow_dv_convert_action_modify_ttl
14845 : : (mhdr_res, actions, items, &flow_attr,
14846 : 0 : dev_flow, !!(action_flags &
14847 : : MLX5_FLOW_ACTION_DECAP), error))
14848 : 0 : return -rte_errno;
14849 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_TTL;
14850 : 0 : break;
14851 : 0 : case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
14852 : : case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
14853 [ # # ]: 0 : if (flow_dv_convert_action_modify_tcp_seq
14854 : : (mhdr_res, actions, error))
14855 : 0 : return -rte_errno;
14856 : 0 : action_flags |= actions->type ==
14857 : : RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ ?
14858 [ # # ]: 0 : MLX5_FLOW_ACTION_INC_TCP_SEQ :
14859 : : MLX5_FLOW_ACTION_DEC_TCP_SEQ;
14860 : 0 : break;
14861 : :
14862 : 0 : case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
14863 : : case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
14864 [ # # ]: 0 : if (flow_dv_convert_action_modify_tcp_ack
14865 : : (mhdr_res, actions, error))
14866 : 0 : return -rte_errno;
14867 : 0 : action_flags |= actions->type ==
14868 : : RTE_FLOW_ACTION_TYPE_INC_TCP_ACK ?
14869 [ # # ]: 0 : MLX5_FLOW_ACTION_INC_TCP_ACK :
14870 : : MLX5_FLOW_ACTION_DEC_TCP_ACK;
14871 : 0 : break;
14872 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_TAG:
14873 [ # # ]: 0 : if (flow_dv_convert_action_set_reg
14874 : : (mhdr_res, actions, error))
14875 : 0 : return -rte_errno;
14876 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_TAG;
14877 : 0 : break;
14878 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG:
14879 [ # # ]: 0 : if (flow_dv_convert_action_copy_mreg
14880 : : (dev, mhdr_res, actions, error))
14881 : 0 : return -rte_errno;
14882 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_TAG;
14883 : 0 : break;
14884 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS:
14885 : 0 : action_flags |= MLX5_FLOW_ACTION_DEFAULT_MISS;
14886 : 0 : dev_flow->handle->fate_action =
14887 : : MLX5_FLOW_FATE_DEFAULT_MISS;
14888 : 0 : break;
14889 : 0 : case RTE_FLOW_ACTION_TYPE_METER:
14890 [ # # ]: 0 : if (!wks->fm)
14891 : 0 : return rte_flow_error_set(error, rte_errno,
14892 : : RTE_FLOW_ERROR_TYPE_ACTION,
14893 : : NULL, "Failed to get meter in flow.");
14894 : : /* Set the meter action. */
14895 : 0 : dev_flow->dv.actions[actions_n++] =
14896 : 0 : wks->fm->meter_action_g;
14897 : 0 : action_flags |= MLX5_FLOW_ACTION_METER;
14898 : 0 : break;
14899 : 0 : case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
14900 [ # # ]: 0 : if (flow_dv_convert_action_modify_ipv4_dscp(mhdr_res,
14901 : : actions, error))
14902 : 0 : return -rte_errno;
14903 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_IPV4_DSCP;
14904 : 0 : break;
14905 : 0 : case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
14906 [ # # ]: 0 : if (flow_dv_convert_action_modify_ipv6_dscp(mhdr_res,
14907 : : actions, error))
14908 : 0 : return -rte_errno;
14909 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_IPV6_DSCP;
14910 : 0 : break;
14911 : 0 : case RTE_FLOW_ACTION_TYPE_SAMPLE:
14912 : 0 : sample_act_pos = actions_n;
14913 : 0 : sample = (const struct rte_flow_action_sample *)
14914 : : action->conf;
14915 : 0 : actions_n++;
14916 : 0 : action_flags |= MLX5_FLOW_ACTION_SAMPLE;
14917 : : /* put encap action into group if work with port id */
14918 [ # # ]: 0 : if ((action_flags & MLX5_FLOW_ACTION_ENCAP) &&
14919 : : (action_flags & MLX5_FLOW_ACTION_PORT_ID))
14920 : 0 : sample_act->action_flags |=
14921 : : MLX5_FLOW_ACTION_ENCAP;
14922 : : break;
14923 : 0 : case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
14924 [ # # ]: 0 : if (flow_dv_convert_action_modify_field
14925 : : (dev, mhdr_res, actions, attr, error))
14926 : 0 : return -rte_errno;
14927 : 0 : action_flags |= MLX5_FLOW_ACTION_MODIFY_FIELD;
14928 : 0 : break;
14929 : 0 : case RTE_FLOW_ACTION_TYPE_CONNTRACK:
14930 : 0 : owner_idx = (uint32_t)(uintptr_t)action->conf;
14931 : 0 : ct = flow_aso_ct_get_by_idx(dev, owner_idx);
14932 [ # # ]: 0 : if (!ct)
14933 : 0 : return rte_flow_error_set(error, EINVAL,
14934 : : RTE_FLOW_ERROR_TYPE_ACTION,
14935 : : NULL,
14936 : : "Failed to get CT object.");
14937 [ # # ]: 0 : if (mlx5_aso_ct_available(priv->sh, MLX5_HW_INV_QUEUE, ct))
14938 : 0 : return rte_flow_error_set(error, rte_errno,
14939 : : RTE_FLOW_ERROR_TYPE_ACTION,
14940 : : NULL,
14941 : : "CT is unavailable.");
14942 [ # # ]: 0 : if (ct->is_original)
14943 : 0 : dev_flow->dv.actions[actions_n] =
14944 : 0 : ct->dr_action_orig;
14945 : : else
14946 : 0 : dev_flow->dv.actions[actions_n] =
14947 : 0 : ct->dr_action_rply;
14948 [ # # ]: 0 : if (flow->ct == 0) {
14949 : 0 : flow->indirect_type =
14950 : : MLX5_INDIRECT_ACTION_TYPE_CT;
14951 : 0 : flow->ct = owner_idx;
14952 : 0 : __atomic_fetch_add(&ct->refcnt, 1,
14953 : : __ATOMIC_RELAXED);
14954 : : }
14955 : 0 : actions_n++;
14956 : 0 : action_flags |= MLX5_FLOW_ACTION_CT;
14957 : 0 : break;
14958 : 0 : case RTE_FLOW_ACTION_TYPE_END:
14959 : : actions_end = true;
14960 [ # # ]: 0 : if (mhdr_res->actions_num) {
14961 : : /* create modify action if needed. */
14962 [ # # ]: 0 : if (flow_dv_modify_hdr_resource_register
14963 : : (dev, mhdr_res, dev_flow, error))
14964 : 0 : return -rte_errno;
14965 : 0 : dev_flow->dv.actions[modify_action_position] =
14966 : 0 : handle->dvh.modify_hdr->action;
14967 : : }
14968 : : /*
14969 : : * Handle AGE and COUNT action by single HW counter
14970 : : * when they are not shared.
14971 : : */
14972 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_AGE) {
14973 [ # # # # ]: 0 : if ((non_shared_age && count) ||
14974 [ # # ]: 0 : !flow_hit_aso_supported(priv, !dev_flow->dv.group)) {
14975 : : /* Creates age by counters. */
14976 : 0 : cnt_act = flow_dv_prepare_counter
14977 : : (dev, dev_flow,
14978 : : flow, count,
14979 : : non_shared_age,
14980 : : error);
14981 [ # # ]: 0 : if (!cnt_act)
14982 : 0 : return -rte_errno;
14983 : 0 : dev_flow->dv.actions[age_act_pos] =
14984 : 0 : cnt_act->action;
14985 : 0 : break;
14986 : : }
14987 [ # # # # ]: 0 : if (!flow->age && non_shared_age) {
14988 : 0 : flow->age = flow_dv_aso_age_alloc
14989 : : (dev, error);
14990 [ # # ]: 0 : if (!flow->age)
14991 : 0 : return -rte_errno;
14992 : 0 : flow_dv_aso_age_params_init
14993 : : (dev, flow->age,
14994 : 0 : non_shared_age->context ?
14995 : : non_shared_age->context :
14996 : 0 : (void *)(uintptr_t)
14997 : 0 : (dev_flow->flow_idx),
14998 [ # # ]: 0 : non_shared_age->timeout);
14999 : : }
15000 : 0 : age_act = flow_aso_age_get_by_idx(dev,
15001 : : flow->age);
15002 : 0 : dev_flow->dv.actions[age_act_pos] =
15003 : 0 : age_act->dr_action;
15004 : : }
15005 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_COUNT) {
15006 : : /*
15007 : : * Create one count action, to be used
15008 : : * by all sub-flows.
15009 : : */
15010 : 0 : cnt_act = flow_dv_prepare_counter(dev, dev_flow,
15011 : : flow, count,
15012 : : NULL, error);
15013 [ # # ]: 0 : if (!cnt_act)
15014 : 0 : return -rte_errno;
15015 : 0 : dev_flow->dv.actions[actions_n++] =
15016 : 0 : cnt_act->action;
15017 : : }
15018 : : default:
15019 : : break;
15020 : : }
15021 [ # # # # ]: 0 : if (mhdr_res->actions_num &&
15022 : : modify_action_position == UINT32_MAX)
15023 : 0 : modify_action_position = actions_n++;
15024 : : }
15025 : 0 : dev_flow->act_flags = action_flags;
15026 : 0 : ret = flow_dv_translate_items_sws(dev, dev_flow, attr, items, &matcher,
15027 : : error);
15028 [ # # ]: 0 : if (ret)
15029 : 0 : return -rte_errno;
15030 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_RSS) {
15031 : 0 : dev_flow->symmetric_hash_function = rss_desc->symmetric_hash_function;
15032 : 0 : flow_dv_hashfields_set(dev_flow->handle->layers,
15033 : : rss_desc,
15034 : : &dev_flow->hash_fields);
15035 : : }
15036 : : /* If has RSS action in the sample action, the Sample/Mirror resource
15037 : : * should be registered after the hash filed be update.
15038 : : */
15039 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE) {
15040 : 0 : ret = flow_dv_translate_action_sample(dev,
15041 : : sample,
15042 : : dev_flow, attr,
15043 : : &num_of_dest,
15044 : : sample_actions,
15045 : : &sample_res,
15046 : : error);
15047 [ # # ]: 0 : if (ret < 0)
15048 : : return ret;
15049 : 0 : ret = flow_dv_create_action_sample(dev,
15050 : : dev_flow,
15051 : : num_of_dest,
15052 : : &sample_res,
15053 : : &mdest_res,
15054 : : sample_actions,
15055 : : action_flags,
15056 : : error);
15057 [ # # ]: 0 : if (ret < 0)
15058 : 0 : return rte_flow_error_set
15059 : : (error, rte_errno,
15060 : : RTE_FLOW_ERROR_TYPE_ACTION,
15061 : : NULL,
15062 : : "cannot create sample action");
15063 [ # # ]: 0 : if (num_of_dest > 1) {
15064 : 0 : dev_flow->dv.actions[sample_act_pos] =
15065 : 0 : dev_flow->dv.dest_array_res->action;
15066 : : } else {
15067 : 0 : dev_flow->dv.actions[sample_act_pos] =
15068 : 0 : dev_flow->dv.sample_res->verbs_action;
15069 : : }
15070 : : }
15071 : : /*
15072 : : * For multiple destination (sample action with ratio=1), the encap
15073 : : * action and port id action will be combined into group action.
15074 : : * So need remove the original these actions in the flow and only
15075 : : * use the sample action instead of.
15076 : : */
15077 [ # # ]: 0 : if (num_of_dest > 1 &&
15078 [ # # # # ]: 0 : (sample_act->dr_port_id_action || sample_act->dr_jump_action)) {
15079 : : int i;
15080 : 0 : void *temp_actions[MLX5_DV_MAX_NUMBER_OF_ACTIONS] = {0};
15081 : :
15082 [ # # ]: 0 : for (i = 0; i < actions_n; i++) {
15083 [ # # ]: 0 : if ((sample_act->dr_encap_action &&
15084 : : sample_act->dr_encap_action ==
15085 [ # # # # ]: 0 : dev_flow->dv.actions[i]) ||
15086 : 0 : (sample_act->dr_port_id_action &&
15087 : : sample_act->dr_port_id_action ==
15088 [ # # ]: 0 : dev_flow->dv.actions[i]) ||
15089 [ # # ]: 0 : (sample_act->dr_jump_action &&
15090 : : sample_act->dr_jump_action ==
15091 [ # # ]: 0 : dev_flow->dv.actions[i]))
15092 : 0 : continue;
15093 : 0 : temp_actions[tmp_actions_n++] = dev_flow->dv.actions[i];
15094 : : }
15095 : 0 : memcpy((void *)dev_flow->dv.actions,
15096 : : (void *)temp_actions,
15097 : : tmp_actions_n * sizeof(void *));
15098 : : actions_n = tmp_actions_n;
15099 : : }
15100 : 0 : dev_flow->dv.actions_n = actions_n;
15101 [ # # ]: 0 : if (wks->skip_matcher_reg)
15102 : : return 0;
15103 : : /* Register matcher. */
15104 : 0 : matcher.crc = rte_raw_cksum((const void *)matcher.mask.buf,
15105 : : matcher.mask.size);
15106 : 0 : matcher.priority = mlx5_get_matcher_priority(dev, attr,
15107 : 0 : matcher.priority,
15108 : 0 : dev_flow->external);
15109 : : /**
15110 : : * When creating meter drop flow in drop table, using original
15111 : : * 5-tuple match, the matcher priority should be lower than
15112 : : * mtr_id matcher.
15113 : : */
15114 [ # # ]: 0 : if (attr->group == MLX5_FLOW_TABLE_LEVEL_METER &&
15115 [ # # # # ]: 0 : dev_flow->dv.table_id == MLX5_MTR_TABLE_ID_DROP &&
15116 : : matcher.priority <= MLX5_REG_BITS)
15117 : 0 : matcher.priority += MLX5_REG_BITS;
15118 : : /* reserved field no needs to be set to 0 here. */
15119 : 0 : tbl_key.is_fdb = attr->transfer;
15120 : 0 : tbl_key.is_egress = attr->egress;
15121 : 0 : tbl_key.level = dev_flow->dv.group;
15122 : 0 : tbl_key.id = dev_flow->dv.table_id;
15123 [ # # ]: 0 : if (flow_dv_matcher_register(dev, &matcher, &tbl_key, dev_flow,
15124 : : tunnel, attr->group, error))
15125 : 0 : return -rte_errno;
15126 : : return 0;
15127 : : }
15128 : :
15129 : : /**
15130 : : * Set hash RX queue by hash fields (see enum ibv_rx_hash_fields)
15131 : : * and tunnel.
15132 : : *
15133 : : * @param[in, out] action
15134 : : * Shred RSS action holding hash RX queue objects.
15135 : : * @param[in] hash_fields
15136 : : * Defines combination of packet fields to participate in RX hash.
15137 : : * @param[in] tunnel
15138 : : * Tunnel type
15139 : : * @param[in] hrxq_idx
15140 : : * Hash RX queue index to set.
15141 : : *
15142 : : * @return
15143 : : * 0 on success, otherwise negative errno value.
15144 : : */
15145 : : static int
15146 : 0 : __flow_dv_action_rss_hrxq_set(struct mlx5_shared_action_rss *action,
15147 : : const uint64_t hash_fields,
15148 : : uint32_t hrxq_idx)
15149 : : {
15150 : : uint32_t *hrxqs = action->hrxq;
15151 : :
15152 [ # # # # : 0 : switch (hash_fields & ~IBV_RX_HASH_INNER) {
# # # # #
# # ]
15153 : 0 : case MLX5_RSS_HASH_IPV4:
15154 : : /* fall-through. */
15155 : : case MLX5_RSS_HASH_IPV4_DST_ONLY:
15156 : : /* fall-through. */
15157 : : case MLX5_RSS_HASH_IPV4_SRC_ONLY:
15158 : 0 : hrxqs[0] = hrxq_idx;
15159 : 0 : return 0;
15160 : 0 : case MLX5_RSS_HASH_IPV4_TCP:
15161 : : /* fall-through. */
15162 : : case MLX5_RSS_HASH_IPV4_TCP_DST_ONLY:
15163 : : /* fall-through. */
15164 : : case MLX5_RSS_HASH_IPV4_TCP_SRC_ONLY:
15165 : 0 : hrxqs[1] = hrxq_idx;
15166 : 0 : return 0;
15167 : 0 : case MLX5_RSS_HASH_IPV4_UDP:
15168 : : /* fall-through. */
15169 : : case MLX5_RSS_HASH_IPV4_UDP_DST_ONLY:
15170 : : /* fall-through. */
15171 : : case MLX5_RSS_HASH_IPV4_UDP_SRC_ONLY:
15172 : 0 : hrxqs[2] = hrxq_idx;
15173 : 0 : return 0;
15174 : 0 : case MLX5_RSS_HASH_IPV6:
15175 : : /* fall-through. */
15176 : : case MLX5_RSS_HASH_IPV6_DST_ONLY:
15177 : : /* fall-through. */
15178 : : case MLX5_RSS_HASH_IPV6_SRC_ONLY:
15179 : 0 : hrxqs[3] = hrxq_idx;
15180 : 0 : return 0;
15181 : 0 : case MLX5_RSS_HASH_IPV6_TCP:
15182 : : /* fall-through. */
15183 : : case MLX5_RSS_HASH_IPV6_TCP_DST_ONLY:
15184 : : /* fall-through. */
15185 : : case MLX5_RSS_HASH_IPV6_TCP_SRC_ONLY:
15186 : 0 : hrxqs[4] = hrxq_idx;
15187 : 0 : return 0;
15188 : 0 : case MLX5_RSS_HASH_IPV6_UDP:
15189 : : /* fall-through. */
15190 : : case MLX5_RSS_HASH_IPV6_UDP_DST_ONLY:
15191 : : /* fall-through. */
15192 : : case MLX5_RSS_HASH_IPV6_UDP_SRC_ONLY:
15193 : 0 : hrxqs[5] = hrxq_idx;
15194 : 0 : return 0;
15195 : 0 : case MLX5_RSS_HASH_NONE:
15196 : 0 : hrxqs[6] = hrxq_idx;
15197 : 0 : return 0;
15198 : 0 : case MLX5_RSS_HASH_IPV4_ESP:
15199 : 0 : hrxqs[7] = hrxq_idx;
15200 : 0 : return 0;
15201 : 0 : case MLX5_RSS_HASH_IPV6_ESP:
15202 : 0 : hrxqs[8] = hrxq_idx;
15203 : 0 : return 0;
15204 : 0 : case MLX5_RSS_HASH_ESP_SPI:
15205 : 0 : hrxqs[9] = hrxq_idx;
15206 : 0 : return 0;
15207 : : default:
15208 : : return -1;
15209 : : }
15210 : : }
15211 : :
15212 : : /**
15213 : : * Look up for hash RX queue by hash fields (see enum ibv_rx_hash_fields)
15214 : : * and tunnel.
15215 : : *
15216 : : * @param[in] dev
15217 : : * Pointer to the Ethernet device structure.
15218 : : * @param[in] idx
15219 : : * Shared RSS action ID holding hash RX queue objects.
15220 : : * @param[in] hash_fields
15221 : : * Defines combination of packet fields to participate in RX hash.
15222 : : * @param[in] tunnel
15223 : : * Tunnel type
15224 : : *
15225 : : * @return
15226 : : * Valid hash RX queue index, otherwise 0.
15227 : : */
15228 : : uint32_t
15229 : 0 : flow_dv_action_rss_hrxq_lookup(struct rte_eth_dev *dev, uint32_t idx,
15230 : : const uint64_t hash_fields)
15231 : : {
15232 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
15233 : : struct mlx5_shared_action_rss *shared_rss =
15234 : 0 : mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
15235 : : const uint32_t *hrxqs = shared_rss->hrxq;
15236 : :
15237 [ # # # # : 0 : switch (hash_fields & ~IBV_RX_HASH_INNER) {
# # # # #
# # ]
15238 : 0 : case MLX5_RSS_HASH_IPV4:
15239 : : /* fall-through. */
15240 : : case MLX5_RSS_HASH_IPV4_DST_ONLY:
15241 : : /* fall-through. */
15242 : : case MLX5_RSS_HASH_IPV4_SRC_ONLY:
15243 : 0 : return hrxqs[0];
15244 : 0 : case MLX5_RSS_HASH_IPV4_TCP:
15245 : : /* fall-through. */
15246 : : case MLX5_RSS_HASH_IPV4_TCP_DST_ONLY:
15247 : : /* fall-through. */
15248 : : case MLX5_RSS_HASH_IPV4_TCP_SRC_ONLY:
15249 : 0 : return hrxqs[1];
15250 : 0 : case MLX5_RSS_HASH_IPV4_UDP:
15251 : : /* fall-through. */
15252 : : case MLX5_RSS_HASH_IPV4_UDP_DST_ONLY:
15253 : : /* fall-through. */
15254 : : case MLX5_RSS_HASH_IPV4_UDP_SRC_ONLY:
15255 : 0 : return hrxqs[2];
15256 : 0 : case MLX5_RSS_HASH_IPV6:
15257 : : /* fall-through. */
15258 : : case MLX5_RSS_HASH_IPV6_DST_ONLY:
15259 : : /* fall-through. */
15260 : : case MLX5_RSS_HASH_IPV6_SRC_ONLY:
15261 : 0 : return hrxqs[3];
15262 : 0 : case MLX5_RSS_HASH_IPV6_TCP:
15263 : : /* fall-through. */
15264 : : case MLX5_RSS_HASH_IPV6_TCP_DST_ONLY:
15265 : : /* fall-through. */
15266 : : case MLX5_RSS_HASH_IPV6_TCP_SRC_ONLY:
15267 : 0 : return hrxqs[4];
15268 : 0 : case MLX5_RSS_HASH_IPV6_UDP:
15269 : : /* fall-through. */
15270 : : case MLX5_RSS_HASH_IPV6_UDP_DST_ONLY:
15271 : : /* fall-through. */
15272 : : case MLX5_RSS_HASH_IPV6_UDP_SRC_ONLY:
15273 : 0 : return hrxqs[5];
15274 : 0 : case MLX5_RSS_HASH_NONE:
15275 : 0 : return hrxqs[6];
15276 : 0 : case MLX5_RSS_HASH_IPV4_ESP:
15277 : 0 : return hrxqs[7];
15278 : 0 : case MLX5_RSS_HASH_IPV6_ESP:
15279 : 0 : return hrxqs[8];
15280 : 0 : case MLX5_RSS_HASH_ESP_SPI:
15281 : 0 : return hrxqs[9];
15282 : : default:
15283 : : return 0;
15284 : : }
15285 : :
15286 : : }
15287 : :
15288 : : /**
15289 : : * Apply the flow to the NIC, lock free,
15290 : : * (mutex should be acquired by caller).
15291 : : *
15292 : : * @param[in] dev
15293 : : * Pointer to the Ethernet device structure.
15294 : : * @param[in, out] flow
15295 : : * Pointer to flow structure.
15296 : : * @param[out] error
15297 : : * Pointer to error structure.
15298 : : *
15299 : : * @return
15300 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
15301 : : */
15302 : : static int
15303 : 0 : flow_dv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
15304 : : struct rte_flow_error *error)
15305 : : {
15306 : : struct mlx5_flow_dv_workspace *dv;
15307 : : struct mlx5_flow_handle *dh;
15308 : : struct mlx5_flow_handle_dv *dv_h;
15309 : : struct mlx5_flow *dev_flow;
15310 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
15311 : : uint32_t handle_idx;
15312 : : int n;
15313 : : int err;
15314 : : int idx;
15315 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
15316 : 0 : struct mlx5_flow_rss_desc *rss_desc = &wks->rss_desc;
15317 : : uint8_t misc_mask;
15318 : :
15319 : : MLX5_ASSERT(wks);
15320 [ # # ]: 0 : for (idx = wks->flow_idx - 1; idx >= 0; idx--) {
15321 : 0 : dev_flow = &wks->flows[idx];
15322 : : dv = &dev_flow->dv;
15323 : 0 : dh = dev_flow->handle;
15324 : : dv_h = &dh->dvh;
15325 : 0 : n = dv->actions_n;
15326 [ # # ]: 0 : if (dh->fate_action == MLX5_FLOW_FATE_DROP) {
15327 [ # # ]: 0 : if (dv->transfer) {
15328 : : MLX5_ASSERT(priv->sh->dr_drop_action);
15329 : 0 : dv->actions[n++] = priv->sh->dr_drop_action;
15330 : : } else {
15331 : : #ifdef HAVE_MLX5DV_DR
15332 : : /* DR supports drop action placeholder. */
15333 : : MLX5_ASSERT(priv->sh->dr_drop_action);
15334 : 0 : dv->actions[n++] = dv->group ?
15335 [ # # ]: 0 : priv->sh->dr_drop_action :
15336 : : priv->root_drop_action;
15337 : : #else
15338 : : /* For DV we use the explicit drop queue. */
15339 : : MLX5_ASSERT(priv->drop_queue.hrxq);
15340 : : dv->actions[n++] =
15341 : : priv->drop_queue.hrxq->action;
15342 : : #endif
15343 : : }
15344 [ # # ]: 0 : } else if ((dh->fate_action == MLX5_FLOW_FATE_QUEUE &&
15345 [ # # # # ]: 0 : !dv_h->rix_sample && !dv_h->rix_dest_array)) {
15346 : : struct mlx5_hrxq *hrxq;
15347 : : uint32_t hrxq_idx;
15348 : :
15349 : 0 : hrxq = flow_dv_hrxq_prepare(dev, dev_flow, rss_desc,
15350 : : &hrxq_idx);
15351 [ # # ]: 0 : if (!hrxq) {
15352 : 0 : rte_flow_error_set
15353 : : (error, rte_errno,
15354 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
15355 : : "cannot get hash queue");
15356 : 0 : goto error;
15357 : : }
15358 : 0 : dh->rix_hrxq = hrxq_idx;
15359 : 0 : dv->actions[n++] = hrxq->action;
15360 [ # # ]: 0 : } else if (dh->fate_action == MLX5_FLOW_FATE_SHARED_RSS) {
15361 : : struct mlx5_hrxq *hrxq = NULL;
15362 : : uint32_t hrxq_idx;
15363 : :
15364 : 0 : hrxq_idx = flow_dv_action_rss_hrxq_lookup(dev,
15365 : : rss_desc->shared_rss,
15366 : : dev_flow->hash_fields);
15367 [ # # ]: 0 : if (hrxq_idx)
15368 : 0 : hrxq = mlx5_ipool_get
15369 : 0 : (priv->sh->ipool[MLX5_IPOOL_HRXQ],
15370 : : hrxq_idx);
15371 [ # # ]: 0 : if (!hrxq) {
15372 : 0 : rte_flow_error_set
15373 : : (error, rte_errno,
15374 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
15375 : : "cannot get hash queue");
15376 : 0 : goto error;
15377 : : }
15378 : 0 : dh->rix_srss = rss_desc->shared_rss;
15379 : 0 : dv->actions[n++] = hrxq->action;
15380 [ # # ]: 0 : } else if (dh->fate_action == MLX5_FLOW_FATE_DEFAULT_MISS) {
15381 [ # # ]: 0 : if (!priv->sh->default_miss_action) {
15382 : 0 : rte_flow_error_set
15383 : : (error, rte_errno,
15384 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
15385 : : "default miss action not be created.");
15386 : 0 : goto error;
15387 : : }
15388 : 0 : dv->actions[n++] = priv->sh->default_miss_action;
15389 : : }
15390 [ # # ]: 0 : misc_mask = flow_dv_matcher_enable(dv_h->matcher->mask.buf);
15391 : : __flow_dv_adjust_buf_size(&dv->value.size, misc_mask);
15392 : 0 : err = mlx5_flow_os_create_flow(dv_h->matcher->matcher_object,
15393 : 0 : (void *)&dv->value, n,
15394 : 0 : dv->actions, &dh->drv_flow);
15395 : : if (err) {
15396 : 0 : rte_flow_error_set
15397 : 0 : (error, errno,
15398 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15399 : : NULL,
15400 [ # # ]: 0 : (!priv->sh->config.allow_duplicate_pattern &&
15401 [ # # ]: 0 : errno == EEXIST) ?
15402 : : "duplicating pattern is not allowed" :
15403 : : "hardware refuses to create flow");
15404 : 0 : goto error;
15405 : : }
15406 [ # # ]: 0 : if (priv->vmwa_context &&
15407 [ # # # # ]: 0 : dh->vf_vlan.tag && !dh->vf_vlan.created) {
15408 : : /*
15409 : : * The rule contains the VLAN pattern.
15410 : : * For VF we are going to create VLAN
15411 : : * interface to make hypervisor set correct
15412 : : * e-Switch vport context.
15413 : : */
15414 : 0 : mlx5_vlan_vmwa_acquire(dev, &dh->vf_vlan);
15415 : : }
15416 : : }
15417 : : return 0;
15418 : 0 : error:
15419 : 0 : err = rte_errno; /* Save rte_errno before cleanup. */
15420 [ # # # # : 0 : SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
# # ]
15421 : : handle_idx, dh, next) {
15422 : : /* hrxq is union, don't clear it if the flag is not set. */
15423 [ # # # # ]: 0 : if (dh->fate_action == MLX5_FLOW_FATE_QUEUE && dh->rix_hrxq) {
15424 : 0 : mlx5_hrxq_release(dev, dh->rix_hrxq);
15425 : 0 : dh->rix_hrxq = 0;
15426 [ # # ]: 0 : } else if (dh->fate_action == MLX5_FLOW_FATE_SHARED_RSS) {
15427 : 0 : dh->rix_srss = 0;
15428 : : }
15429 [ # # # # ]: 0 : if (dh->vf_vlan.tag && dh->vf_vlan.created)
15430 : 0 : mlx5_vlan_vmwa_release(dev, &dh->vf_vlan);
15431 : : }
15432 : 0 : rte_errno = err; /* Restore rte_errno. */
15433 : 0 : return -rte_errno;
15434 : : }
15435 : :
15436 : : void
15437 : 0 : flow_dv_matcher_remove_cb(void *tool_ctx __rte_unused,
15438 : : struct mlx5_list_entry *entry)
15439 : : {
15440 : : struct mlx5_flow_dv_matcher *resource = container_of(entry,
15441 : : typeof(*resource),
15442 : : entry);
15443 : :
15444 : 0 : claim_zero(mlx5_flow_os_destroy_flow_matcher(resource->matcher_object));
15445 : 0 : mlx5_free(resource);
15446 : 0 : }
15447 : :
15448 : : /**
15449 : : * Release the flow matcher.
15450 : : *
15451 : : * @param dev
15452 : : * Pointer to Ethernet device.
15453 : : * @param port_id
15454 : : * Index to port ID action resource.
15455 : : *
15456 : : * @return
15457 : : * 1 while a reference on it exists, 0 when freed.
15458 : : */
15459 : : static int
15460 : 0 : flow_dv_matcher_release(struct rte_eth_dev *dev,
15461 : : struct mlx5_flow_handle *handle)
15462 : : {
15463 : 0 : struct mlx5_flow_dv_matcher *matcher = handle->dvh.matcher;
15464 : 0 : struct mlx5_flow_tbl_data_entry *tbl = container_of(matcher->tbl,
15465 : : typeof(*tbl), tbl);
15466 : : int ret;
15467 : :
15468 : : MLX5_ASSERT(matcher->matcher_object);
15469 : 0 : ret = mlx5_list_unregister(tbl->matchers, &matcher->entry);
15470 : 0 : flow_dv_tbl_resource_release(MLX5_SH(dev), &tbl->tbl);
15471 : 0 : return ret;
15472 : : }
15473 : :
15474 : : void
15475 : 0 : flow_dv_encap_decap_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
15476 : : {
15477 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
15478 : : struct mlx5_flow_dv_encap_decap_resource *res =
15479 : : container_of(entry, typeof(*res), entry);
15480 : :
15481 : 0 : claim_zero(mlx5_flow_os_destroy_flow_action(res->action));
15482 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_DECAP_ENCAP], res->idx);
15483 : 0 : }
15484 : :
15485 : : /**
15486 : : * Release an encap/decap resource.
15487 : : *
15488 : : * @param dev
15489 : : * Pointer to Ethernet device.
15490 : : * @param encap_decap_idx
15491 : : * Index of encap decap resource.
15492 : : *
15493 : : * @return
15494 : : * 1 while a reference on it exists, 0 when freed.
15495 : : */
15496 : : static int
15497 : 0 : flow_dv_encap_decap_resource_release(struct rte_eth_dev *dev,
15498 : : uint32_t encap_decap_idx)
15499 : : {
15500 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
15501 : : struct mlx5_flow_dv_encap_decap_resource *resource;
15502 : :
15503 : 0 : resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_DECAP_ENCAP],
15504 : : encap_decap_idx);
15505 [ # # ]: 0 : if (!resource)
15506 : : return 0;
15507 : : MLX5_ASSERT(resource->action);
15508 : 0 : return mlx5_hlist_unregister(priv->sh->encaps_decaps, &resource->entry);
15509 : : }
15510 : :
15511 : : /**
15512 : : * Release an jump to table action resource.
15513 : : *
15514 : : * @param dev
15515 : : * Pointer to Ethernet device.
15516 : : * @param rix_jump
15517 : : * Index to the jump action resource.
15518 : : *
15519 : : * @return
15520 : : * 1 while a reference on it exists, 0 when freed.
15521 : : */
15522 : : static int
15523 : 0 : flow_dv_jump_tbl_resource_release(struct rte_eth_dev *dev,
15524 : : uint32_t rix_jump)
15525 : : {
15526 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
15527 : : struct mlx5_flow_tbl_data_entry *tbl_data;
15528 : :
15529 : 0 : tbl_data = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_JUMP],
15530 : : rix_jump);
15531 [ # # ]: 0 : if (!tbl_data)
15532 : : return 0;
15533 : 0 : return flow_dv_tbl_resource_release(MLX5_SH(dev), &tbl_data->tbl);
15534 : : }
15535 : :
15536 : : void
15537 : 0 : flow_dv_modify_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
15538 : : {
15539 : : struct mlx5_flow_dv_modify_hdr_resource *res =
15540 : : container_of(entry, typeof(*res), entry);
15541 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
15542 : :
15543 : 0 : claim_zero(mlx5_flow_os_destroy_flow_action(res->action));
15544 : 0 : mlx5_ipool_free(sh->mdh_ipools[res->actions_num - 1], res->idx);
15545 : 0 : }
15546 : :
15547 : : /**
15548 : : * Release a modify-header resource.
15549 : : *
15550 : : * @param dev
15551 : : * Pointer to Ethernet device.
15552 : : * @param handle
15553 : : * Pointer to mlx5_flow_handle.
15554 : : *
15555 : : * @return
15556 : : * 1 while a reference on it exists, 0 when freed.
15557 : : */
15558 : : static int
15559 : : flow_dv_modify_hdr_resource_release(struct rte_eth_dev *dev,
15560 : : struct mlx5_flow_handle *handle)
15561 : : {
15562 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
15563 : : struct mlx5_flow_dv_modify_hdr_resource *entry = handle->dvh.modify_hdr;
15564 : :
15565 : : MLX5_ASSERT(entry->action);
15566 : 0 : return mlx5_hlist_unregister(priv->sh->modify_cmds, &entry->entry);
15567 : : }
15568 : :
15569 : : void
15570 : 0 : flow_dv_port_id_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
15571 : : {
15572 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
15573 : : struct mlx5_flow_dv_port_id_action_resource *resource =
15574 : : container_of(entry, typeof(*resource), entry);
15575 : :
15576 : 0 : claim_zero(mlx5_flow_os_destroy_flow_action(resource->action));
15577 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PORT_ID], resource->idx);
15578 : 0 : }
15579 : :
15580 : : /**
15581 : : * Release port ID action resource.
15582 : : *
15583 : : * @param dev
15584 : : * Pointer to Ethernet device.
15585 : : * @param handle
15586 : : * Pointer to mlx5_flow_handle.
15587 : : *
15588 : : * @return
15589 : : * 1 while a reference on it exists, 0 when freed.
15590 : : */
15591 : : static int
15592 : 0 : flow_dv_port_id_action_resource_release(struct rte_eth_dev *dev,
15593 : : uint32_t port_id)
15594 : : {
15595 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
15596 : : struct mlx5_flow_dv_port_id_action_resource *resource;
15597 : :
15598 : 0 : resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_PORT_ID], port_id);
15599 [ # # ]: 0 : if (!resource)
15600 : : return 0;
15601 : : MLX5_ASSERT(resource->action);
15602 : 0 : return mlx5_list_unregister(priv->sh->port_id_action_list,
15603 : : &resource->entry);
15604 : : }
15605 : :
15606 : : /**
15607 : : * Release shared RSS action resource.
15608 : : *
15609 : : * @param dev
15610 : : * Pointer to Ethernet device.
15611 : : * @param srss
15612 : : * Shared RSS action index.
15613 : : */
15614 : : static void
15615 : 0 : flow_dv_shared_rss_action_release(struct rte_eth_dev *dev, uint32_t srss)
15616 : : {
15617 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
15618 : : struct mlx5_shared_action_rss *shared_rss;
15619 : :
15620 : 0 : shared_rss = mlx5_ipool_get
15621 : 0 : (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], srss);
15622 : 0 : __atomic_fetch_sub(&shared_rss->refcnt, 1, __ATOMIC_RELAXED);
15623 : 0 : }
15624 : :
15625 : : void
15626 : 0 : flow_dv_push_vlan_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
15627 : : {
15628 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
15629 : : struct mlx5_flow_dv_push_vlan_action_resource *resource =
15630 : : container_of(entry, typeof(*resource), entry);
15631 : :
15632 : 0 : claim_zero(mlx5_flow_os_destroy_flow_action(resource->action));
15633 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PUSH_VLAN], resource->idx);
15634 : 0 : }
15635 : :
15636 : : /**
15637 : : * Release push vlan action resource.
15638 : : *
15639 : : * @param dev
15640 : : * Pointer to Ethernet device.
15641 : : * @param handle
15642 : : * Pointer to mlx5_flow_handle.
15643 : : *
15644 : : * @return
15645 : : * 1 while a reference on it exists, 0 when freed.
15646 : : */
15647 : : static int
15648 : 0 : flow_dv_push_vlan_action_resource_release(struct rte_eth_dev *dev,
15649 : : struct mlx5_flow_handle *handle)
15650 : : {
15651 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
15652 : : struct mlx5_flow_dv_push_vlan_action_resource *resource;
15653 : 0 : uint32_t idx = handle->dvh.rix_push_vlan;
15654 : :
15655 : 0 : resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_PUSH_VLAN], idx);
15656 [ # # ]: 0 : if (!resource)
15657 : : return 0;
15658 : : MLX5_ASSERT(resource->action);
15659 : 0 : return mlx5_list_unregister(priv->sh->push_vlan_action_list,
15660 : : &resource->entry);
15661 : : }
15662 : :
15663 : : /**
15664 : : * Release the fate resource.
15665 : : *
15666 : : * @param dev
15667 : : * Pointer to Ethernet device.
15668 : : * @param handle
15669 : : * Pointer to mlx5_flow_handle.
15670 : : */
15671 : : static void
15672 : 0 : flow_dv_fate_resource_release(struct rte_eth_dev *dev,
15673 : : struct mlx5_flow_handle *handle)
15674 : : {
15675 [ # # ]: 0 : if (!handle->rix_fate)
15676 : : return;
15677 [ # # # # : 0 : switch (handle->fate_action) {
# ]
15678 : 0 : case MLX5_FLOW_FATE_QUEUE:
15679 [ # # # # ]: 0 : if (!handle->dvh.rix_sample && !handle->dvh.rix_dest_array)
15680 : 0 : mlx5_hrxq_release(dev, handle->rix_hrxq);
15681 : : break;
15682 : 0 : case MLX5_FLOW_FATE_JUMP:
15683 : 0 : flow_dv_jump_tbl_resource_release(dev, handle->rix_jump);
15684 : 0 : break;
15685 : 0 : case MLX5_FLOW_FATE_PORT_ID:
15686 : 0 : flow_dv_port_id_action_resource_release(dev,
15687 : : handle->rix_port_id_action);
15688 : 0 : break;
15689 : : case MLX5_FLOW_FATE_SEND_TO_KERNEL:
15690 : : /* In case of send_to_kernel action the actual release of
15691 : : * resource is done when all shared DR resources are released
15692 : : * since this resource is created once and always reused.
15693 : : */
15694 : : break;
15695 : 0 : default:
15696 : 0 : DRV_LOG(DEBUG, "Incorrect fate action:%d", handle->fate_action);
15697 : 0 : break;
15698 : : }
15699 : 0 : handle->rix_fate = 0;
15700 : : }
15701 : :
15702 : : void
15703 : 0 : flow_dv_sample_remove_cb(void *tool_ctx __rte_unused,
15704 : : struct mlx5_list_entry *entry)
15705 : : {
15706 : : struct mlx5_flow_dv_sample_resource *resource = container_of(entry,
15707 : : typeof(*resource),
15708 : : entry);
15709 : 0 : struct rte_eth_dev *dev = resource->dev;
15710 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
15711 : :
15712 [ # # ]: 0 : if (resource->verbs_action)
15713 : : claim_zero(mlx5_flow_os_destroy_flow_action
15714 : : (resource->verbs_action));
15715 [ # # ]: 0 : if (resource->normal_path_tbl)
15716 : 0 : flow_dv_tbl_resource_release(MLX5_SH(dev),
15717 : : resource->normal_path_tbl);
15718 : 0 : flow_dv_sample_sub_actions_release(dev, &resource->sample_idx);
15719 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_SAMPLE], resource->idx);
15720 : 0 : DRV_LOG(DEBUG, "sample resource %p: removed", (void *)resource);
15721 : 0 : }
15722 : :
15723 : : /**
15724 : : * Release an sample resource.
15725 : : *
15726 : : * @param dev
15727 : : * Pointer to Ethernet device.
15728 : : * @param handle
15729 : : * Pointer to mlx5_flow_handle.
15730 : : *
15731 : : * @return
15732 : : * 1 while a reference on it exists, 0 when freed.
15733 : : */
15734 : : static int
15735 : 0 : flow_dv_sample_resource_release(struct rte_eth_dev *dev,
15736 : : struct mlx5_flow_handle *handle)
15737 : : {
15738 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
15739 : : struct mlx5_flow_dv_sample_resource *resource;
15740 : :
15741 : 0 : resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_SAMPLE],
15742 : : handle->dvh.rix_sample);
15743 [ # # ]: 0 : if (!resource)
15744 : : return 0;
15745 : : MLX5_ASSERT(resource->verbs_action);
15746 : 0 : return mlx5_list_unregister(priv->sh->sample_action_list,
15747 : : &resource->entry);
15748 : : }
15749 : :
15750 : : void
15751 : 0 : flow_dv_dest_array_remove_cb(void *tool_ctx __rte_unused,
15752 : : struct mlx5_list_entry *entry)
15753 : : {
15754 : : struct mlx5_flow_dv_dest_array_resource *resource =
15755 : : container_of(entry, typeof(*resource), entry);
15756 : 0 : struct rte_eth_dev *dev = resource->dev;
15757 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
15758 : : uint32_t i = 0;
15759 : :
15760 : : MLX5_ASSERT(resource->action);
15761 [ # # ]: 0 : if (resource->action)
15762 : : claim_zero(mlx5_flow_os_destroy_flow_action(resource->action));
15763 [ # # ]: 0 : for (; i < resource->num_of_dest; i++)
15764 : 0 : flow_dv_sample_sub_actions_release(dev,
15765 : : &resource->sample_idx[i]);
15766 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_DEST_ARRAY], resource->idx);
15767 : 0 : DRV_LOG(DEBUG, "destination array resource %p: removed",
15768 : : (void *)resource);
15769 : 0 : }
15770 : :
15771 : : /**
15772 : : * Release an destination array resource.
15773 : : *
15774 : : * @param dev
15775 : : * Pointer to Ethernet device.
15776 : : * @param handle
15777 : : * Pointer to mlx5_flow_handle.
15778 : : *
15779 : : * @return
15780 : : * 1 while a reference on it exists, 0 when freed.
15781 : : */
15782 : : static int
15783 : 0 : flow_dv_dest_array_resource_release(struct rte_eth_dev *dev,
15784 : : struct mlx5_flow_handle *handle)
15785 : : {
15786 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
15787 : : struct mlx5_flow_dv_dest_array_resource *resource;
15788 : :
15789 : 0 : resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_DEST_ARRAY],
15790 : : handle->dvh.rix_dest_array);
15791 [ # # ]: 0 : if (!resource)
15792 : : return 0;
15793 : : MLX5_ASSERT(resource->action);
15794 : 0 : return mlx5_list_unregister(priv->sh->dest_array_list,
15795 : : &resource->entry);
15796 : : }
15797 : :
15798 : : void
15799 : 0 : flow_dev_geneve_tlv_option_resource_release(struct mlx5_dev_ctx_shared *sh)
15800 : : {
15801 : 0 : struct mlx5_geneve_tlv_option_resource *geneve_opt_resource =
15802 : : sh->geneve_tlv_option_resource;
15803 : 0 : rte_spinlock_lock(&sh->geneve_tlv_opt_sl);
15804 [ # # ]: 0 : if (geneve_opt_resource) {
15805 [ # # ]: 0 : if (!(__atomic_fetch_sub(&geneve_opt_resource->refcnt, 1,
15806 : : __ATOMIC_RELAXED) - 1)) {
15807 : 0 : claim_zero(mlx5_devx_cmd_destroy
15808 : : (geneve_opt_resource->obj));
15809 : 0 : mlx5_free(sh->geneve_tlv_option_resource);
15810 : 0 : sh->geneve_tlv_option_resource = NULL;
15811 : : }
15812 : : }
15813 : : rte_spinlock_unlock(&sh->geneve_tlv_opt_sl);
15814 : 0 : }
15815 : :
15816 : : /**
15817 : : * Remove the flow from the NIC but keeps it in memory.
15818 : : * Lock free, (mutex should be acquired by caller).
15819 : : *
15820 : : * @param[in] dev
15821 : : * Pointer to Ethernet device.
15822 : : * @param[in, out] flow
15823 : : * Pointer to flow structure.
15824 : : */
15825 : : static void
15826 : 0 : flow_dv_remove(struct rte_eth_dev *dev, struct rte_flow *flow)
15827 : : {
15828 : : struct mlx5_flow_handle *dh;
15829 : : uint32_t handle_idx;
15830 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
15831 : :
15832 [ # # ]: 0 : if (!flow)
15833 : : return;
15834 : 0 : handle_idx = flow->dev_handles;
15835 [ # # ]: 0 : while (handle_idx) {
15836 : 0 : dh = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
15837 : : handle_idx);
15838 [ # # ]: 0 : if (!dh)
15839 : : return;
15840 [ # # ]: 0 : if (dh->drv_flow) {
15841 : : claim_zero(mlx5_flow_os_destroy_flow(dh->drv_flow));
15842 : 0 : dh->drv_flow = NULL;
15843 : : }
15844 [ # # ]: 0 : if (dh->fate_action == MLX5_FLOW_FATE_QUEUE)
15845 : 0 : flow_dv_fate_resource_release(dev, dh);
15846 [ # # # # ]: 0 : if (dh->vf_vlan.tag && dh->vf_vlan.created)
15847 : 0 : mlx5_vlan_vmwa_release(dev, &dh->vf_vlan);
15848 : 0 : handle_idx = dh->next.next;
15849 : : }
15850 : : }
15851 : :
15852 : : /**
15853 : : * Remove the flow from the NIC and the memory.
15854 : : * Lock free, (mutex should be acquired by caller).
15855 : : *
15856 : : * @param[in] dev
15857 : : * Pointer to the Ethernet device structure.
15858 : : * @param[in, out] flow
15859 : : * Pointer to flow structure.
15860 : : */
15861 : : static void
15862 : 0 : flow_dv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
15863 : : {
15864 : : struct mlx5_flow_handle *dev_handle;
15865 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
15866 : : struct mlx5_flow_meter_info *fm = NULL;
15867 : : uint32_t srss = 0;
15868 : :
15869 [ # # ]: 0 : if (!flow)
15870 : : return;
15871 : 0 : flow_dv_remove(dev, flow);
15872 [ # # ]: 0 : if (flow->counter) {
15873 : 0 : flow_dv_counter_free(dev, flow->counter);
15874 : 0 : flow->counter = 0;
15875 : : }
15876 [ # # ]: 0 : if (flow->meter) {
15877 : 0 : fm = flow_dv_meter_find_by_idx(priv, flow->meter);
15878 [ # # ]: 0 : if (fm)
15879 : 0 : mlx5_flow_meter_detach(priv, fm);
15880 : 0 : flow->meter = 0;
15881 : : }
15882 : : /* Keep the current age handling by default. */
15883 [ # # # # ]: 0 : if (flow->indirect_type == MLX5_INDIRECT_ACTION_TYPE_CT && flow->ct)
15884 : 0 : flow_dv_aso_ct_release(dev, flow->ct, NULL);
15885 [ # # ]: 0 : else if (flow->age)
15886 : 0 : flow_dv_aso_age_release(dev, flow->age);
15887 [ # # ]: 0 : if (flow->geneve_tlv_option) {
15888 : 0 : flow_dev_geneve_tlv_option_resource_release(priv->sh);
15889 : 0 : flow->geneve_tlv_option = 0;
15890 : : }
15891 [ # # ]: 0 : while (flow->dev_handles) {
15892 : : uint32_t tmp_idx = flow->dev_handles;
15893 : :
15894 : 0 : dev_handle = mlx5_ipool_get(priv->sh->ipool
15895 : : [MLX5_IPOOL_MLX5_FLOW], tmp_idx);
15896 [ # # ]: 0 : if (!dev_handle)
15897 : : return;
15898 : 0 : flow->dev_handles = dev_handle->next.next;
15899 [ # # ]: 0 : while (dev_handle->flex_item) {
15900 : 0 : int index = rte_bsf32(dev_handle->flex_item);
15901 : :
15902 : 0 : mlx5_flex_release_index(dev, index);
15903 : 0 : dev_handle->flex_item &= ~(uint8_t)RTE_BIT32(index);
15904 : : }
15905 [ # # ]: 0 : if (dev_handle->dvh.matcher)
15906 : 0 : flow_dv_matcher_release(dev, dev_handle);
15907 [ # # ]: 0 : if (dev_handle->dvh.rix_sample)
15908 : 0 : flow_dv_sample_resource_release(dev, dev_handle);
15909 [ # # ]: 0 : if (dev_handle->dvh.rix_dest_array)
15910 : 0 : flow_dv_dest_array_resource_release(dev, dev_handle);
15911 [ # # ]: 0 : if (dev_handle->dvh.rix_encap_decap)
15912 : 0 : flow_dv_encap_decap_resource_release(dev,
15913 : : dev_handle->dvh.rix_encap_decap);
15914 [ # # ]: 0 : if (dev_handle->dvh.modify_hdr)
15915 : : flow_dv_modify_hdr_resource_release(dev, dev_handle);
15916 [ # # ]: 0 : if (dev_handle->dvh.rix_push_vlan)
15917 : 0 : flow_dv_push_vlan_action_resource_release(dev,
15918 : : dev_handle);
15919 [ # # ]: 0 : if (dev_handle->dvh.rix_tag)
15920 : 0 : flow_dv_tag_release(dev,
15921 : : dev_handle->dvh.rix_tag);
15922 [ # # ]: 0 : if (dev_handle->fate_action != MLX5_FLOW_FATE_SHARED_RSS)
15923 : 0 : flow_dv_fate_resource_release(dev, dev_handle);
15924 [ # # ]: 0 : else if (!srss)
15925 : 0 : srss = dev_handle->rix_srss;
15926 [ # # # # ]: 0 : if (fm && dev_handle->is_meter_flow_id &&
15927 [ # # ]: 0 : dev_handle->split_flow_id)
15928 : 0 : mlx5_ipool_free(fm->flow_ipool,
15929 : : dev_handle->split_flow_id);
15930 [ # # ]: 0 : else if (dev_handle->split_flow_id &&
15931 [ # # ]: 0 : !dev_handle->is_meter_flow_id)
15932 : 0 : mlx5_ipool_free(priv->sh->ipool
15933 : : [MLX5_IPOOL_RSS_EXPANTION_FLOW_ID],
15934 : : dev_handle->split_flow_id);
15935 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
15936 : : tmp_idx);
15937 : : }
15938 [ # # ]: 0 : if (srss)
15939 : 0 : flow_dv_shared_rss_action_release(dev, srss);
15940 : : }
15941 : :
15942 : : /**
15943 : : * Release array of hash RX queue objects.
15944 : : * Helper function.
15945 : : *
15946 : : * @param[in] dev
15947 : : * Pointer to the Ethernet device structure.
15948 : : * @param[in, out] hrxqs
15949 : : * Array of hash RX queue objects.
15950 : : *
15951 : : * @return
15952 : : * Total number of references to hash RX queue objects in *hrxqs* array
15953 : : * after this operation.
15954 : : */
15955 : : static int
15956 : 0 : __flow_dv_hrxqs_release(struct rte_eth_dev *dev,
15957 : : uint32_t (*hrxqs)[MLX5_RSS_HASH_FIELDS_LEN])
15958 : : {
15959 : : size_t i;
15960 : : int remaining = 0;
15961 : :
15962 [ # # ]: 0 : for (i = 0; i < RTE_DIM(*hrxqs); i++) {
15963 : 0 : int ret = mlx5_hrxq_release(dev, (*hrxqs)[i]);
15964 : :
15965 [ # # ]: 0 : if (!ret)
15966 : 0 : (*hrxqs)[i] = 0;
15967 : 0 : remaining += ret;
15968 : : }
15969 : 0 : return remaining;
15970 : : }
15971 : :
15972 : : /**
15973 : : * Release all hash RX queue objects representing shared RSS action.
15974 : : *
15975 : : * @param[in] dev
15976 : : * Pointer to the Ethernet device structure.
15977 : : * @param[in, out] action
15978 : : * Shared RSS action to remove hash RX queue objects from.
15979 : : *
15980 : : * @return
15981 : : * Total number of references to hash RX queue objects stored in *action*
15982 : : * after this operation.
15983 : : * Expected to be 0 if no external references held.
15984 : : */
15985 : : static int
15986 : : __flow_dv_action_rss_hrxqs_release(struct rte_eth_dev *dev,
15987 : : struct mlx5_shared_action_rss *shared_rss)
15988 : : {
15989 : 0 : return __flow_dv_hrxqs_release(dev, &shared_rss->hrxq);
15990 : : }
15991 : :
15992 : : /**
15993 : : * Adjust L3/L4 hash value of pre-created shared RSS hrxq according to
15994 : : * user input.
15995 : : *
15996 : : * Only one hash value is available for one L3+L4 combination:
15997 : : * for example:
15998 : : * MLX5_RSS_HASH_IPV4, MLX5_RSS_HASH_IPV4_SRC_ONLY, and
15999 : : * MLX5_RSS_HASH_IPV4_DST_ONLY are mutually exclusive so they can share
16000 : : * same slot in mlx5_rss_hash_fields.
16001 : : *
16002 : : * @param[in] orig_rss_types
16003 : : * RSS type as provided in shared RSS action.
16004 : : * @param[in, out] hash_field
16005 : : * hash_field variable needed to be adjusted.
16006 : : *
16007 : : * @return
16008 : : * void
16009 : : */
16010 : : void
16011 [ # # ]: 0 : flow_dv_action_rss_l34_hash_adjust(uint64_t orig_rss_types,
16012 : : uint64_t *hash_field)
16013 : : {
16014 : : uint64_t rss_types = rte_eth_rss_hf_refine(orig_rss_types);
16015 : :
16016 [ # # # # : 0 : switch (*hash_field & ~IBV_RX_HASH_INNER) {
# ]
16017 : 0 : case MLX5_RSS_HASH_IPV4:
16018 [ # # ]: 0 : if (rss_types & MLX5_IPV4_LAYER_TYPES) {
16019 : 0 : *hash_field &= ~MLX5_RSS_HASH_IPV4;
16020 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_L3_DST_ONLY)
16021 : 0 : *hash_field |= IBV_RX_HASH_DST_IPV4;
16022 [ # # ]: 0 : else if (rss_types & RTE_ETH_RSS_L3_SRC_ONLY)
16023 : 0 : *hash_field |= IBV_RX_HASH_SRC_IPV4;
16024 : : else
16025 : 0 : *hash_field |= MLX5_RSS_HASH_IPV4;
16026 : : }
16027 : : return;
16028 : 0 : case MLX5_RSS_HASH_IPV6:
16029 [ # # ]: 0 : if (rss_types & MLX5_IPV6_LAYER_TYPES) {
16030 : 0 : *hash_field &= ~MLX5_RSS_HASH_IPV6;
16031 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_L3_DST_ONLY)
16032 : 0 : *hash_field |= IBV_RX_HASH_DST_IPV6;
16033 [ # # ]: 0 : else if (rss_types & RTE_ETH_RSS_L3_SRC_ONLY)
16034 : 0 : *hash_field |= IBV_RX_HASH_SRC_IPV6;
16035 : : else
16036 : 0 : *hash_field |= MLX5_RSS_HASH_IPV6;
16037 : : }
16038 : : return;
16039 : 0 : case MLX5_RSS_HASH_IPV4_UDP:
16040 : : /* fall-through. */
16041 : : case MLX5_RSS_HASH_IPV6_UDP:
16042 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_UDP) {
16043 : 0 : *hash_field &= ~MLX5_UDP_IBV_RX_HASH;
16044 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_L4_DST_ONLY)
16045 : 0 : *hash_field |= IBV_RX_HASH_DST_PORT_UDP;
16046 [ # # ]: 0 : else if (rss_types & RTE_ETH_RSS_L4_SRC_ONLY)
16047 : 0 : *hash_field |= IBV_RX_HASH_SRC_PORT_UDP;
16048 : : else
16049 : 0 : *hash_field |= MLX5_UDP_IBV_RX_HASH;
16050 : : }
16051 : : return;
16052 : 0 : case MLX5_RSS_HASH_IPV4_TCP:
16053 : : /* fall-through. */
16054 : : case MLX5_RSS_HASH_IPV6_TCP:
16055 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_TCP) {
16056 : 0 : *hash_field &= ~MLX5_TCP_IBV_RX_HASH;
16057 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_L4_DST_ONLY)
16058 : 0 : *hash_field |= IBV_RX_HASH_DST_PORT_TCP;
16059 [ # # ]: 0 : else if (rss_types & RTE_ETH_RSS_L4_SRC_ONLY)
16060 : 0 : *hash_field |= IBV_RX_HASH_SRC_PORT_TCP;
16061 : : else
16062 : 0 : *hash_field |= MLX5_TCP_IBV_RX_HASH;
16063 : : }
16064 : : return;
16065 : : default:
16066 : : return;
16067 : : }
16068 : : }
16069 : :
16070 : : /**
16071 : : * Setup shared RSS action.
16072 : : * Prepare set of hash RX queue objects sufficient to handle all valid
16073 : : * hash_fields combinations (see enum ibv_rx_hash_fields).
16074 : : *
16075 : : * @param[in] dev
16076 : : * Pointer to the Ethernet device structure.
16077 : : * @param[in] action_idx
16078 : : * Shared RSS action ipool index.
16079 : : * @param[in, out] action
16080 : : * Partially initialized shared RSS action.
16081 : : * @param[out] error
16082 : : * Perform verbose error reporting if not NULL. Initialized in case of
16083 : : * error only.
16084 : : *
16085 : : * @return
16086 : : * 0 on success, otherwise negative errno value.
16087 : : */
16088 : : static int
16089 : 0 : __flow_dv_action_rss_setup(struct rte_eth_dev *dev,
16090 : : uint32_t action_idx,
16091 : : struct mlx5_shared_action_rss *shared_rss,
16092 : : struct rte_flow_error *error)
16093 : : {
16094 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16095 : 0 : struct mlx5_flow_rss_desc rss_desc = { 0 };
16096 : : size_t i;
16097 : : int err;
16098 : :
16099 : 0 : shared_rss->ind_tbl = mlx5_ind_table_obj_new
16100 : : (dev, shared_rss->origin.queue,
16101 : : shared_rss->origin.queue_num,
16102 : : true,
16103 : 0 : !!dev->data->dev_started);
16104 [ # # ]: 0 : if (!shared_rss->ind_tbl)
16105 : 0 : return rte_flow_error_set(error, rte_errno,
16106 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
16107 : : "cannot setup indirection table");
16108 : 0 : memcpy(rss_desc.key, shared_rss->origin.key, MLX5_RSS_HASH_KEY_LEN);
16109 : 0 : rss_desc.key_len = MLX5_RSS_HASH_KEY_LEN;
16110 : 0 : rss_desc.symmetric_hash_function =
16111 : 0 : MLX5_RSS_IS_SYMM(shared_rss->origin.func);
16112 : 0 : rss_desc.const_q = shared_rss->origin.queue;
16113 : 0 : rss_desc.queue_num = shared_rss->origin.queue_num;
16114 : : /* Set non-zero value to indicate a shared RSS. */
16115 : 0 : rss_desc.shared_rss = action_idx;
16116 : 0 : rss_desc.ind_tbl = shared_rss->ind_tbl;
16117 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2)
16118 : 0 : rss_desc.hws_flags = MLX5DR_ACTION_FLAG_HWS_RX;
16119 [ # # ]: 0 : for (i = 0; i < MLX5_RSS_HASH_FIELDS_LEN; i++) {
16120 : : struct mlx5_hrxq *hrxq;
16121 : 0 : uint64_t hash_fields = mlx5_rss_hash_fields[i];
16122 : : int tunnel = 0;
16123 : :
16124 : 0 : flow_dv_action_rss_l34_hash_adjust(shared_rss->origin.types,
16125 : : &hash_fields);
16126 [ # # ]: 0 : if (shared_rss->origin.level > 1) {
16127 : 0 : hash_fields |= IBV_RX_HASH_INNER;
16128 : : tunnel = 1;
16129 : : }
16130 : 0 : rss_desc.tunnel = tunnel;
16131 : 0 : rss_desc.hash_fields = hash_fields;
16132 : 0 : hrxq = mlx5_hrxq_get(dev, &rss_desc);
16133 [ # # ]: 0 : if (!hrxq) {
16134 : 0 : rte_flow_error_set
16135 : : (error, rte_errno,
16136 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
16137 : : "cannot get hash queue");
16138 : 0 : goto error_hrxq_new;
16139 : : }
16140 : 0 : err = __flow_dv_action_rss_hrxq_set
16141 : : (shared_rss, hash_fields, hrxq->idx);
16142 : : MLX5_ASSERT(!err);
16143 : : }
16144 : : return 0;
16145 : : error_hrxq_new:
16146 : 0 : err = rte_errno;
16147 : : __flow_dv_action_rss_hrxqs_release(dev, shared_rss);
16148 [ # # ]: 0 : if (!mlx5_ind_table_obj_release(dev, shared_rss->ind_tbl, true))
16149 : 0 : shared_rss->ind_tbl = NULL;
16150 : 0 : rte_errno = err;
16151 : 0 : return -rte_errno;
16152 : : }
16153 : :
16154 : : /**
16155 : : * Create shared RSS action.
16156 : : *
16157 : : * @param[in] dev
16158 : : * Pointer to the Ethernet device structure.
16159 : : * @param[in] conf
16160 : : * Shared action configuration.
16161 : : * @param[in] rss
16162 : : * RSS action specification used to create shared action.
16163 : : * @param[out] error
16164 : : * Perform verbose error reporting if not NULL. Initialized in case of
16165 : : * error only.
16166 : : *
16167 : : * @return
16168 : : * A valid shared action ID in case of success, 0 otherwise and
16169 : : * rte_errno is set.
16170 : : */
16171 : : static uint32_t
16172 : 0 : __flow_dv_action_rss_create(struct rte_eth_dev *dev,
16173 : : const struct rte_flow_indir_action_conf *conf,
16174 : : const struct rte_flow_action_rss *rss,
16175 : : struct rte_flow_error *error)
16176 : : {
16177 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16178 : : struct mlx5_shared_action_rss *shared_rss = NULL;
16179 : : struct rte_flow_action_rss *origin;
16180 : : const uint8_t *rss_key;
16181 : : uint32_t idx;
16182 : :
16183 : : RTE_SET_USED(conf);
16184 : 0 : shared_rss = mlx5_ipool_zmalloc
16185 : 0 : (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], &idx);
16186 [ # # ]: 0 : if (!shared_rss) {
16187 : 0 : rte_flow_error_set(error, ENOMEM,
16188 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
16189 : : "cannot allocate resource memory");
16190 : 0 : goto error_rss_init;
16191 : : }
16192 [ # # ]: 0 : if (idx > (1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET)) {
16193 : 0 : rte_flow_error_set(error, E2BIG,
16194 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
16195 : : "rss action number out of range");
16196 : 0 : goto error_rss_init;
16197 : : }
16198 : : origin = &shared_rss->origin;
16199 : 0 : origin->func = rss->func;
16200 : 0 : origin->level = rss->level;
16201 : : /* RSS type 0 indicates default RSS type (RTE_ETH_RSS_IP). */
16202 [ # # ]: 0 : origin->types = !rss->types ? RTE_ETH_RSS_IP : rss->types;
16203 : : /* NULL RSS key indicates default RSS key. */
16204 [ # # ]: 0 : rss_key = !rss->key ? rss_hash_default_key : rss->key;
16205 : 0 : memcpy(shared_rss->key, rss_key, MLX5_RSS_HASH_KEY_LEN);
16206 : 0 : origin->key = &shared_rss->key[0];
16207 : 0 : origin->key_len = MLX5_RSS_HASH_KEY_LEN;
16208 : 0 : origin->queue = rss->queue;
16209 : 0 : origin->queue_num = rss->queue_num;
16210 [ # # ]: 0 : if (__flow_dv_action_rss_setup(dev, idx, shared_rss, error))
16211 : 0 : goto error_rss_init;
16212 : : /* Update queue with indirect table queue memoyr. */
16213 : 0 : origin->queue = shared_rss->ind_tbl->queues;
16214 : : rte_spinlock_init(&shared_rss->action_rss_sl);
16215 : 0 : __atomic_fetch_add(&shared_rss->refcnt, 1, __ATOMIC_RELAXED);
16216 : 0 : rte_spinlock_lock(&priv->shared_act_sl);
16217 [ # # # # ]: 0 : ILIST_INSERT(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
16218 : : &priv->rss_shared_actions, idx, shared_rss, next);
16219 : : rte_spinlock_unlock(&priv->shared_act_sl);
16220 : 0 : return idx;
16221 : 0 : error_rss_init:
16222 [ # # ]: 0 : if (shared_rss) {
16223 [ # # ]: 0 : if (shared_rss->ind_tbl)
16224 : 0 : mlx5_ind_table_obj_release(dev, shared_rss->ind_tbl,
16225 : 0 : !!dev->data->dev_started);
16226 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
16227 : : idx);
16228 : : }
16229 : : return 0;
16230 : : }
16231 : :
16232 : : /**
16233 : : * Destroy the shared RSS action.
16234 : : * Release related hash RX queue objects.
16235 : : *
16236 : : * @param[in] dev
16237 : : * Pointer to the Ethernet device structure.
16238 : : * @param[in] idx
16239 : : * The shared RSS action object ID to be removed.
16240 : : * @param[out] error
16241 : : * Perform verbose error reporting if not NULL. Initialized in case of
16242 : : * error only.
16243 : : *
16244 : : * @return
16245 : : * 0 on success, otherwise negative errno value.
16246 : : */
16247 : : static int
16248 : 0 : __flow_dv_action_rss_release(struct rte_eth_dev *dev, uint32_t idx,
16249 : : struct rte_flow_error *error)
16250 : : {
16251 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16252 : : struct mlx5_shared_action_rss *shared_rss =
16253 : 0 : mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
16254 : : uint32_t old_refcnt = 1;
16255 : : int remaining;
16256 : :
16257 [ # # ]: 0 : if (!shared_rss)
16258 : 0 : return rte_flow_error_set(error, EINVAL,
16259 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
16260 : : "invalid shared action");
16261 [ # # ]: 0 : if (!__atomic_compare_exchange_n(&shared_rss->refcnt, &old_refcnt,
16262 : : 0, 0, __ATOMIC_ACQUIRE,
16263 : : __ATOMIC_RELAXED))
16264 : 0 : return rte_flow_error_set(error, EBUSY,
16265 : : RTE_FLOW_ERROR_TYPE_ACTION,
16266 : : NULL,
16267 : : "shared rss has references");
16268 : : remaining = __flow_dv_action_rss_hrxqs_release(dev, shared_rss);
16269 [ # # ]: 0 : if (remaining)
16270 : 0 : return rte_flow_error_set(error, EBUSY,
16271 : : RTE_FLOW_ERROR_TYPE_ACTION,
16272 : : NULL,
16273 : : "shared rss hrxq has references");
16274 : 0 : remaining = mlx5_ind_table_obj_release(dev, shared_rss->ind_tbl,
16275 : 0 : !!dev->data->dev_started);
16276 [ # # ]: 0 : if (remaining)
16277 : 0 : return rte_flow_error_set(error, EBUSY,
16278 : : RTE_FLOW_ERROR_TYPE_ACTION,
16279 : : NULL,
16280 : : "shared rss indirection table has"
16281 : : " references");
16282 : 0 : rte_spinlock_lock(&priv->shared_act_sl);
16283 [ # # # # : 0 : ILIST_REMOVE(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
# # # # #
# ]
16284 : : &priv->rss_shared_actions, idx, shared_rss, next);
16285 : : rte_spinlock_unlock(&priv->shared_act_sl);
16286 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
16287 : : idx);
16288 : 0 : return 0;
16289 : : }
16290 : :
16291 : : /**
16292 : : * Create indirect action, lock free,
16293 : : * (mutex should be acquired by caller).
16294 : : * Dispatcher for action type specific call.
16295 : : *
16296 : : * @param[in] dev
16297 : : * Pointer to the Ethernet device structure.
16298 : : * @param[in] conf
16299 : : * Shared action configuration.
16300 : : * @param[in] action
16301 : : * Action specification used to create indirect action.
16302 : : * @param[out] error
16303 : : * Perform verbose error reporting if not NULL. Initialized in case of
16304 : : * error only.
16305 : : *
16306 : : * @return
16307 : : * A valid shared action handle in case of success, NULL otherwise and
16308 : : * rte_errno is set.
16309 : : */
16310 : : struct rte_flow_action_handle *
16311 : 0 : flow_dv_action_create(struct rte_eth_dev *dev,
16312 : : const struct rte_flow_indir_action_conf *conf,
16313 : : const struct rte_flow_action *action,
16314 : : struct rte_flow_error *err)
16315 : : {
16316 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16317 : : uint32_t age_idx = 0;
16318 : : uint32_t idx = 0;
16319 : : uint32_t ret = 0;
16320 : :
16321 [ # # # # : 0 : switch (action->type) {
# ]
16322 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
16323 : 0 : ret = __flow_dv_action_rss_create(dev, conf, action->conf, err);
16324 : : idx = (MLX5_INDIRECT_ACTION_TYPE_RSS <<
16325 : : MLX5_INDIRECT_ACTION_TYPE_OFFSET) | ret;
16326 : 0 : break;
16327 : 0 : case RTE_FLOW_ACTION_TYPE_AGE:
16328 : 0 : age_idx = flow_dv_aso_age_alloc(dev, err);
16329 [ # # ]: 0 : if (!age_idx) {
16330 : 0 : ret = -rte_errno;
16331 : 0 : break;
16332 : : }
16333 : 0 : idx = (MLX5_INDIRECT_ACTION_TYPE_AGE <<
16334 : : MLX5_INDIRECT_ACTION_TYPE_OFFSET) | age_idx;
16335 : 0 : flow_dv_aso_age_params_init(dev, age_idx,
16336 : : ((const struct rte_flow_action_age *)
16337 : 0 : action->conf)->context ?
16338 : : ((const struct rte_flow_action_age *)
16339 : : action->conf)->context :
16340 : 0 : (void *)(uintptr_t)idx,
16341 : : ((const struct rte_flow_action_age *)
16342 [ # # ]: 0 : action->conf)->timeout);
16343 : : ret = age_idx;
16344 : 0 : break;
16345 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
16346 : 0 : ret = flow_dv_translate_create_counter(dev, NULL, NULL, NULL);
16347 : 0 : idx = (MLX5_INDIRECT_ACTION_TYPE_COUNT <<
16348 : : MLX5_INDIRECT_ACTION_TYPE_OFFSET) | ret;
16349 : 0 : break;
16350 : 0 : case RTE_FLOW_ACTION_TYPE_CONNTRACK:
16351 : 0 : ret = flow_dv_translate_create_conntrack(dev, action->conf,
16352 : : err);
16353 : 0 : idx = MLX5_INDIRECT_ACT_CT_GEN_IDX(PORT_ID(priv), ret);
16354 : 0 : break;
16355 : 0 : default:
16356 : 0 : rte_flow_error_set(err, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
16357 : : NULL, "action type not supported");
16358 : : break;
16359 : : }
16360 [ # # ]: 0 : return ret ? (struct rte_flow_action_handle *)(uintptr_t)idx : NULL;
16361 : : }
16362 : :
16363 : : /**
16364 : : * Destroy the indirect action.
16365 : : * Release action related resources on the NIC and the memory.
16366 : : * Lock free, (mutex should be acquired by caller).
16367 : : * Dispatcher for action type specific call.
16368 : : *
16369 : : * @param[in] dev
16370 : : * Pointer to the Ethernet device structure.
16371 : : * @param[in] handle
16372 : : * The indirect action object handle to be removed.
16373 : : * @param[out] error
16374 : : * Perform verbose error reporting if not NULL. Initialized in case of
16375 : : * error only.
16376 : : *
16377 : : * @return
16378 : : * 0 on success, otherwise negative errno value.
16379 : : */
16380 : : int
16381 : 0 : flow_dv_action_destroy(struct rte_eth_dev *dev,
16382 : : struct rte_flow_action_handle *handle,
16383 : : struct rte_flow_error *error)
16384 : : {
16385 : 0 : uint32_t act_idx = (uint32_t)(uintptr_t)handle;
16386 : 0 : uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
16387 : 0 : uint32_t idx = act_idx & ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
16388 : : struct mlx5_flow_counter *cnt;
16389 : : uint32_t no_flow_refcnt = 1;
16390 : : int ret;
16391 : :
16392 [ # # # # : 0 : switch (type) {
# ]
16393 : 0 : case MLX5_INDIRECT_ACTION_TYPE_RSS:
16394 : 0 : return __flow_dv_action_rss_release(dev, idx, error);
16395 : : case MLX5_INDIRECT_ACTION_TYPE_COUNT:
16396 : : cnt = flow_dv_counter_get_by_idx(dev, idx, NULL);
16397 [ # # ]: 0 : if (!__atomic_compare_exchange_n(&cnt->shared_info.refcnt,
16398 : : &no_flow_refcnt, 1, false,
16399 : : __ATOMIC_ACQUIRE,
16400 : : __ATOMIC_RELAXED))
16401 : 0 : return rte_flow_error_set(error, EBUSY,
16402 : : RTE_FLOW_ERROR_TYPE_ACTION,
16403 : : NULL,
16404 : : "Indirect count action has references");
16405 : 0 : flow_dv_counter_free(dev, idx);
16406 : 0 : return 0;
16407 : 0 : case MLX5_INDIRECT_ACTION_TYPE_AGE:
16408 : 0 : ret = flow_dv_aso_age_release(dev, idx);
16409 [ # # ]: 0 : if (ret)
16410 : : /*
16411 : : * In this case, the last flow has a reference will
16412 : : * actually release the age action.
16413 : : */
16414 : 0 : DRV_LOG(DEBUG, "Indirect age action %" PRIu32 " was"
16415 : : " released with references %d.", idx, ret);
16416 : : return 0;
16417 : 0 : case MLX5_INDIRECT_ACTION_TYPE_CT:
16418 : 0 : ret = flow_dv_aso_ct_release(dev, idx, error);
16419 [ # # ]: 0 : if (ret < 0)
16420 : : return ret;
16421 [ # # ]: 0 : if (ret > 0)
16422 : 0 : DRV_LOG(DEBUG, "Connection tracking object %u still "
16423 : : "has references %d.", idx, ret);
16424 : : return 0;
16425 : 0 : default:
16426 : 0 : return rte_flow_error_set(error, ENOTSUP,
16427 : : RTE_FLOW_ERROR_TYPE_ACTION,
16428 : : NULL,
16429 : : "action type not supported");
16430 : : }
16431 : : }
16432 : :
16433 : : /**
16434 : : * Updates in place shared RSS action configuration.
16435 : : *
16436 : : * @param[in] dev
16437 : : * Pointer to the Ethernet device structure.
16438 : : * @param[in] idx
16439 : : * The shared RSS action object ID to be updated.
16440 : : * @param[in] action_conf
16441 : : * RSS action specification used to modify *shared_rss*.
16442 : : * @param[out] error
16443 : : * Perform verbose error reporting if not NULL. Initialized in case of
16444 : : * error only.
16445 : : *
16446 : : * @return
16447 : : * 0 on success, otherwise negative errno value.
16448 : : * @note: currently only support update of RSS queues.
16449 : : */
16450 : : static int
16451 : 0 : __flow_dv_action_rss_update(struct rte_eth_dev *dev, uint32_t idx,
16452 : : const struct rte_flow_action_rss *action_conf,
16453 : : struct rte_flow_error *error)
16454 : : {
16455 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16456 : : struct mlx5_shared_action_rss *shared_rss =
16457 : 0 : mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
16458 : : int ret = 0;
16459 : : void *queue = NULL;
16460 : : void *queue_i = NULL;
16461 : 0 : uint32_t queue_size = action_conf->queue_num * sizeof(uint16_t);
16462 : 0 : bool dev_started = !!dev->data->dev_started;
16463 : :
16464 [ # # ]: 0 : if (!shared_rss)
16465 : 0 : return rte_flow_error_set(error, EINVAL,
16466 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
16467 : : "invalid shared action to update");
16468 [ # # ]: 0 : if (priv->obj_ops.ind_table_modify == NULL)
16469 : 0 : return rte_flow_error_set(error, ENOTSUP,
16470 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
16471 : : "cannot modify indirection table");
16472 : 0 : queue = mlx5_malloc(MLX5_MEM_ZERO,
16473 : 0 : RTE_ALIGN_CEIL(queue_size, sizeof(void *)),
16474 : : 0, SOCKET_ID_ANY);
16475 [ # # ]: 0 : if (!queue)
16476 : 0 : return rte_flow_error_set(error, ENOMEM,
16477 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
16478 : : NULL,
16479 : : "cannot allocate resource memory");
16480 : 0 : memcpy(queue, action_conf->queue, queue_size);
16481 : : MLX5_ASSERT(shared_rss->ind_tbl);
16482 : 0 : rte_spinlock_lock(&shared_rss->action_rss_sl);
16483 : 0 : queue_i = shared_rss->ind_tbl->queues;
16484 : 0 : ret = mlx5_ind_table_obj_modify(dev, shared_rss->ind_tbl,
16485 : 0 : queue, action_conf->queue_num,
16486 : : true /* standalone */,
16487 : : dev_started /* ref_new_qs */,
16488 : : dev_started /* deref_old_qs */);
16489 [ # # ]: 0 : if (ret) {
16490 : 0 : ret = rte_flow_error_set(error, rte_errno,
16491 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
16492 : : "cannot update indirection table");
16493 : : } else {
16494 : : /* Restore the queue to indirect table internal queue. */
16495 : : memcpy(queue_i, queue, queue_size);
16496 : 0 : shared_rss->ind_tbl->queues = queue_i;
16497 : 0 : shared_rss->origin.queue_num = action_conf->queue_num;
16498 : : }
16499 : 0 : mlx5_free(queue);
16500 : : rte_spinlock_unlock(&shared_rss->action_rss_sl);
16501 : 0 : return ret;
16502 : : }
16503 : :
16504 : : /*
16505 : : * Updates in place conntrack context or direction.
16506 : : * Context update should be synchronized.
16507 : : *
16508 : : * @param[in] dev
16509 : : * Pointer to the Ethernet device structure.
16510 : : * @param[in] idx
16511 : : * The conntrack object ID to be updated.
16512 : : * @param[in] update
16513 : : * Pointer to the structure of information to update.
16514 : : * @param[out] error
16515 : : * Perform verbose error reporting if not NULL. Initialized in case of
16516 : : * error only.
16517 : : *
16518 : : * @return
16519 : : * 0 on success, otherwise negative errno value.
16520 : : */
16521 : : static int
16522 : 0 : __flow_dv_action_ct_update(struct rte_eth_dev *dev, uint32_t idx,
16523 : : const struct rte_flow_modify_conntrack *update,
16524 : : struct rte_flow_error *error)
16525 : : {
16526 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16527 : : struct mlx5_aso_ct_action *ct;
16528 : : const struct rte_flow_action_conntrack *new_prf;
16529 : : int ret = 0;
16530 : 0 : uint16_t owner = (uint16_t)MLX5_INDIRECT_ACT_CT_GET_OWNER(idx);
16531 : : uint32_t dev_idx;
16532 : :
16533 [ # # ]: 0 : if (PORT_ID(priv) != owner)
16534 : 0 : return rte_flow_error_set(error, EACCES,
16535 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
16536 : : NULL,
16537 : : "CT object owned by another port");
16538 : 0 : dev_idx = MLX5_INDIRECT_ACT_CT_GET_IDX(idx);
16539 : 0 : ct = flow_aso_ct_get_by_dev_idx(dev, dev_idx);
16540 [ # # ]: 0 : if (!ct->refcnt)
16541 : 0 : return rte_flow_error_set(error, ENOMEM,
16542 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
16543 : : NULL,
16544 : : "CT object is inactive");
16545 : 0 : new_prf = &update->new_ct;
16546 [ # # ]: 0 : if (update->direction)
16547 : 0 : ct->is_original = !!new_prf->is_original_dir;
16548 [ # # ]: 0 : if (update->state) {
16549 : : /* Only validate the profile when it needs to be updated. */
16550 : 0 : ret = mlx5_validate_action_ct(dev, new_prf, error);
16551 [ # # ]: 0 : if (ret)
16552 : : return ret;
16553 : 0 : ret = mlx5_aso_ct_update_by_wqe(priv->sh, MLX5_HW_INV_QUEUE,
16554 : : ct, new_prf, NULL, true);
16555 [ # # ]: 0 : if (ret)
16556 : 0 : return rte_flow_error_set(error, EIO,
16557 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
16558 : : NULL,
16559 : : "Failed to send CT context update WQE");
16560 : : /* Block until ready or a failure, default is asynchronous. */
16561 : 0 : ret = mlx5_aso_ct_available(priv->sh, MLX5_HW_INV_QUEUE, ct);
16562 [ # # ]: 0 : if (ret)
16563 : 0 : rte_flow_error_set(error, rte_errno,
16564 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
16565 : : NULL,
16566 : : "Timeout to get the CT update");
16567 : : }
16568 : : return ret;
16569 : : }
16570 : :
16571 : : /**
16572 : : * Updates in place shared action configuration, lock free,
16573 : : * (mutex should be acquired by caller).
16574 : : *
16575 : : * @param[in] dev
16576 : : * Pointer to the Ethernet device structure.
16577 : : * @param[in] handle
16578 : : * The indirect action object handle to be updated.
16579 : : * @param[in] update
16580 : : * Action specification used to modify the action pointed by *handle*.
16581 : : * *update* could be of same type with the action pointed by the *handle*
16582 : : * handle argument, or some other structures like a wrapper, depending on
16583 : : * the indirect action type.
16584 : : * @param[out] error
16585 : : * Perform verbose error reporting if not NULL. Initialized in case of
16586 : : * error only.
16587 : : *
16588 : : * @return
16589 : : * 0 on success, otherwise negative errno value.
16590 : : */
16591 : : int
16592 : 0 : flow_dv_action_update(struct rte_eth_dev *dev,
16593 : : struct rte_flow_action_handle *handle,
16594 : : const void *update,
16595 : : struct rte_flow_error *err)
16596 : : {
16597 : 0 : uint32_t act_idx = (uint32_t)(uintptr_t)handle;
16598 : 0 : uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
16599 : 0 : uint32_t idx = act_idx & ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
16600 : : const void *action_conf;
16601 : :
16602 [ # # # ]: 0 : switch (type) {
16603 : 0 : case MLX5_INDIRECT_ACTION_TYPE_RSS:
16604 : 0 : action_conf = ((const struct rte_flow_action *)update)->conf;
16605 : 0 : return __flow_dv_action_rss_update(dev, idx, action_conf, err);
16606 : 0 : case MLX5_INDIRECT_ACTION_TYPE_CT:
16607 : 0 : return __flow_dv_action_ct_update(dev, idx, update, err);
16608 : 0 : default:
16609 : 0 : return rte_flow_error_set(err, ENOTSUP,
16610 : : RTE_FLOW_ERROR_TYPE_ACTION,
16611 : : NULL,
16612 : : "action type update not supported");
16613 : : }
16614 : : }
16615 : :
16616 : : /**
16617 : : * Destroy the meter sub policy table rules.
16618 : : * Lock free, (mutex should be acquired by caller).
16619 : : *
16620 : : * @param[in] dev
16621 : : * Pointer to Ethernet device.
16622 : : * @param[in] sub_policy
16623 : : * Pointer to meter sub policy table.
16624 : : */
16625 : : static void
16626 : 0 : __flow_dv_destroy_sub_policy_rules(struct rte_eth_dev *dev,
16627 : : struct mlx5_flow_meter_sub_policy *sub_policy)
16628 : : {
16629 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16630 : : struct mlx5_flow_tbl_data_entry *tbl;
16631 : 0 : struct mlx5_flow_meter_policy *policy = sub_policy->main_policy;
16632 : : struct mlx5_flow_meter_info *next_fm;
16633 : : struct mlx5_sub_policy_color_rule *color_rule;
16634 : : void *tmp;
16635 : : uint32_t i;
16636 : :
16637 [ # # ]: 0 : for (i = 0; i < RTE_COLORS; i++) {
16638 : : next_fm = NULL;
16639 [ # # ]: 0 : if (i <= RTE_COLOR_YELLOW && policy &&
16640 [ # # ]: 0 : policy->act_cnt[i].fate_action == MLX5_FLOW_FATE_MTR)
16641 : 0 : next_fm = mlx5_flow_meter_find(priv,
16642 : : policy->act_cnt[i].next_mtr_id, NULL);
16643 [ # # ]: 0 : RTE_TAILQ_FOREACH_SAFE(color_rule, &sub_policy->color_rules[i],
16644 : : next_port, tmp) {
16645 : 0 : claim_zero(mlx5_flow_os_destroy_flow(color_rule->rule));
16646 : 0 : tbl = container_of(color_rule->matcher->tbl,
16647 : : typeof(*tbl), tbl);
16648 : 0 : mlx5_list_unregister(tbl->matchers,
16649 : : &color_rule->matcher->entry);
16650 [ # # ]: 0 : TAILQ_REMOVE(&sub_policy->color_rules[i],
16651 : : color_rule, next_port);
16652 : 0 : mlx5_free(color_rule);
16653 [ # # ]: 0 : if (next_fm)
16654 : 0 : mlx5_flow_meter_detach(priv, next_fm);
16655 : : }
16656 : : }
16657 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
16658 [ # # ]: 0 : if (sub_policy->rix_hrxq[i]) {
16659 [ # # # # ]: 0 : if (policy && !policy->is_hierarchy)
16660 : 0 : mlx5_hrxq_release(dev, sub_policy->rix_hrxq[i]);
16661 : 0 : sub_policy->rix_hrxq[i] = 0;
16662 : : }
16663 [ # # ]: 0 : if (sub_policy->jump_tbl[i]) {
16664 : 0 : flow_dv_tbl_resource_release(MLX5_SH(dev),
16665 : : sub_policy->jump_tbl[i]);
16666 : 0 : sub_policy->jump_tbl[i] = NULL;
16667 : : }
16668 : : }
16669 [ # # ]: 0 : if (sub_policy->tbl_rsc) {
16670 : 0 : flow_dv_tbl_resource_release(MLX5_SH(dev),
16671 : : sub_policy->tbl_rsc);
16672 : 0 : sub_policy->tbl_rsc = NULL;
16673 : : }
16674 : 0 : }
16675 : :
16676 : : /**
16677 : : * Destroy policy rules, lock free,
16678 : : * (mutex should be acquired by caller).
16679 : : * Dispatcher for action type specific call.
16680 : : *
16681 : : * @param[in] dev
16682 : : * Pointer to the Ethernet device structure.
16683 : : * @param[in] mtr_policy
16684 : : * Meter policy struct.
16685 : : */
16686 : : static void
16687 : 0 : flow_dv_destroy_policy_rules(struct rte_eth_dev *dev,
16688 : : struct mlx5_flow_meter_policy *mtr_policy)
16689 : : {
16690 : : uint32_t i, j;
16691 : : struct mlx5_flow_meter_sub_policy *sub_policy;
16692 : : uint16_t sub_policy_num;
16693 : :
16694 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
16695 : 0 : sub_policy_num = (mtr_policy->sub_policy_num >>
16696 : 0 : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i)) &
16697 : : MLX5_MTR_SUB_POLICY_NUM_MASK;
16698 [ # # ]: 0 : for (j = 0; j < sub_policy_num; j++) {
16699 : 0 : sub_policy = mtr_policy->sub_policys[i][j];
16700 [ # # ]: 0 : if (sub_policy)
16701 : 0 : __flow_dv_destroy_sub_policy_rules(dev,
16702 : : sub_policy);
16703 : : }
16704 : : }
16705 : 0 : }
16706 : :
16707 : : /**
16708 : : * Destroy policy action, lock free,
16709 : : * (mutex should be acquired by caller).
16710 : : * Dispatcher for action type specific call.
16711 : : *
16712 : : * @param[in] dev
16713 : : * Pointer to the Ethernet device structure.
16714 : : * @param[in] mtr_policy
16715 : : * Meter policy struct.
16716 : : */
16717 : : static void
16718 : 0 : flow_dv_destroy_mtr_policy_acts(struct rte_eth_dev *dev,
16719 : : struct mlx5_flow_meter_policy *mtr_policy)
16720 : : {
16721 : : struct rte_flow_action *rss_action;
16722 : : struct mlx5_flow_handle dev_handle;
16723 : : uint32_t i, j;
16724 : :
16725 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
16726 [ # # ]: 0 : if (mtr_policy->act_cnt[i].rix_mark) {
16727 : 0 : flow_dv_tag_release(dev,
16728 : : mtr_policy->act_cnt[i].rix_mark);
16729 : 0 : mtr_policy->act_cnt[i].rix_mark = 0;
16730 : : }
16731 [ # # ]: 0 : if (mtr_policy->act_cnt[i].modify_hdr) {
16732 : : dev_handle.dvh.modify_hdr =
16733 : : mtr_policy->act_cnt[i].modify_hdr;
16734 : : flow_dv_modify_hdr_resource_release(dev, &dev_handle);
16735 : : }
16736 [ # # # # ]: 0 : switch (mtr_policy->act_cnt[i].fate_action) {
16737 : 0 : case MLX5_FLOW_FATE_SHARED_RSS:
16738 : 0 : rss_action = mtr_policy->act_cnt[i].rss;
16739 : 0 : mlx5_free(rss_action);
16740 : 0 : break;
16741 : 0 : case MLX5_FLOW_FATE_PORT_ID:
16742 [ # # ]: 0 : if (mtr_policy->act_cnt[i].rix_port_id_action) {
16743 : 0 : flow_dv_port_id_action_resource_release(dev,
16744 : : mtr_policy->act_cnt[i].rix_port_id_action);
16745 : 0 : mtr_policy->act_cnt[i].rix_port_id_action = 0;
16746 : : }
16747 : : break;
16748 : : case MLX5_FLOW_FATE_DROP:
16749 : : case MLX5_FLOW_FATE_JUMP:
16750 [ # # ]: 0 : for (j = 0; j < MLX5_MTR_DOMAIN_MAX; j++)
16751 : 0 : mtr_policy->act_cnt[i].dr_jump_action[j] =
16752 : : NULL;
16753 : : break;
16754 : : default:
16755 : : /*Queue action do nothing*/
16756 : : break;
16757 : : }
16758 : : }
16759 [ # # ]: 0 : for (j = 0; j < MLX5_MTR_DOMAIN_MAX; j++)
16760 : 0 : mtr_policy->dr_drop_action[j] = NULL;
16761 : 0 : }
16762 : :
16763 : : /**
16764 : : * Create yellow action for color aware meter.
16765 : : *
16766 : : * @param[in] dev
16767 : : * Pointer to the Ethernet device structure.
16768 : : * @param[in] fm
16769 : : * Meter information table.
16770 : : * @param[out] error
16771 : : * Perform verbose error reporting if not NULL. Initialized in case of
16772 : : * error only.
16773 : : *
16774 : : * @return
16775 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
16776 : : */
16777 : : static int
16778 : 0 : __flow_dv_create_mtr_yellow_action(struct rte_eth_dev *dev,
16779 : : struct mlx5_flow_meter_info *fm,
16780 : : struct rte_mtr_error *error)
16781 : : {
16782 : : #ifdef HAVE_MLX5_DR_CREATE_ACTION_ASO
16783 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16784 : : struct rte_flow_error flow_err;
16785 : : struct mlx5_aso_mtr *aso_mtr;
16786 : : struct mlx5_aso_mtr_pool *pool;
16787 : : uint8_t reg_id;
16788 : :
16789 : 0 : aso_mtr = container_of(fm, struct mlx5_aso_mtr, fm);
16790 : 0 : pool = container_of(aso_mtr, struct mlx5_aso_mtr_pool, mtrs[aso_mtr->offset]);
16791 : 0 : reg_id = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, &flow_err);
16792 : 0 : fm->meter_action_y =
16793 : 0 : mlx5_glue->dv_create_flow_action_aso(priv->sh->rx_domain,
16794 : 0 : pool->devx_obj->obj,
16795 : : aso_mtr->offset,
16796 : : (1 << MLX5_FLOW_COLOR_YELLOW),
16797 : 0 : reg_id - REG_C_0);
16798 : : #else
16799 : : RTE_SET_USED(dev);
16800 : : #endif
16801 [ # # ]: 0 : if (!fm->meter_action_y) {
16802 : 0 : return -rte_mtr_error_set(error, EINVAL, RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
16803 : : "Fail to create yellow meter action.");
16804 : : }
16805 : : return 0;
16806 : : }
16807 : :
16808 : : /**
16809 : : * Create policy action per domain, lock free,
16810 : : * (mutex should be acquired by caller).
16811 : : * Dispatcher for action type specific call.
16812 : : *
16813 : : * @param[in] dev
16814 : : * Pointer to the Ethernet device structure.
16815 : : * @param[in] mtr_policy
16816 : : * Meter policy struct.
16817 : : * @param[in] action
16818 : : * Action specification used to create meter actions.
16819 : : * @param[in] attr
16820 : : * Pointer to the flow attributes.
16821 : : * @param[out] error
16822 : : * Perform verbose error reporting if not NULL. Initialized in case of
16823 : : * error only.
16824 : : *
16825 : : * @return
16826 : : * 0 on success, otherwise negative errno value.
16827 : : */
16828 : : static int
16829 : 0 : __flow_dv_create_domain_policy_acts(struct rte_eth_dev *dev,
16830 : : struct mlx5_flow_meter_policy *mtr_policy,
16831 : : const struct rte_flow_action *actions[RTE_COLORS],
16832 : : struct rte_flow_attr *attr,
16833 : : enum mlx5_meter_domain domain,
16834 : : struct rte_mtr_error *error)
16835 : : {
16836 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16837 : : struct rte_flow_error flow_err;
16838 : : const struct rte_flow_action *act;
16839 : : uint64_t action_flags;
16840 : : struct mlx5_flow_handle dh;
16841 : : struct mlx5_flow dev_flow;
16842 : : struct mlx5_flow_dv_port_id_action_resource port_id_action;
16843 : : int i, ret;
16844 : : uint8_t egress, transfer;
16845 : : struct mlx5_meter_policy_action_container *act_cnt = NULL;
16846 : : union {
16847 : : struct mlx5_flow_dv_modify_hdr_resource res;
16848 : : uint8_t len[sizeof(struct mlx5_flow_dv_modify_hdr_resource) +
16849 : : sizeof(struct mlx5_modification_cmd) *
16850 : : (MLX5_MAX_MODIFY_NUM + 1)];
16851 : : } mhdr_dummy;
16852 : : struct mlx5_flow_dv_modify_hdr_resource *mhdr_res = &mhdr_dummy.res;
16853 : :
16854 : 0 : egress = (domain == MLX5_MTR_DOMAIN_EGRESS) ? 1 : 0;
16855 [ # # ]: 0 : transfer = (domain == MLX5_MTR_DOMAIN_TRANSFER) ? 1 : 0;
16856 : : memset(&dh, 0, sizeof(struct mlx5_flow_handle));
16857 : : memset(&dev_flow, 0, sizeof(struct mlx5_flow));
16858 : : memset(&port_id_action, 0,
16859 : : sizeof(struct mlx5_flow_dv_port_id_action_resource));
16860 : : memset(mhdr_res, 0, sizeof(*mhdr_res));
16861 [ # # ]: 0 : mhdr_res->ft_type = transfer ? MLX5DV_FLOW_TABLE_TYPE_FDB :
16862 : : (egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
16863 : : MLX5DV_FLOW_TABLE_TYPE_NIC_RX);
16864 : 0 : dev_flow.handle = &dh;
16865 : 0 : dev_flow.dv.port_id_action = &port_id_action;
16866 : 0 : dev_flow.external = true;
16867 [ # # ]: 0 : for (i = 0; i < RTE_COLORS; i++) {
16868 [ # # ]: 0 : if (i < MLX5_MTR_RTE_COLORS)
16869 : 0 : act_cnt = &mtr_policy->act_cnt[i];
16870 : : /* Skip the color policy actions creation. */
16871 [ # # # # : 0 : if ((i == RTE_COLOR_YELLOW && mtr_policy->skip_y) ||
# # ]
16872 [ # # ]: 0 : (i == RTE_COLOR_GREEN && mtr_policy->skip_g))
16873 : 0 : continue;
16874 : : action_flags = 0;
16875 : 0 : for (act = actions[i];
16876 [ # # # # ]: 0 : act && act->type != RTE_FLOW_ACTION_TYPE_END; act++) {
16877 [ # # # # : 0 : switch (act->type) {
# # # # #
# ]
16878 : 0 : case RTE_FLOW_ACTION_TYPE_MARK:
16879 : : {
16880 : : uint32_t tag_be = mlx5_flow_mark_set
16881 : : (((const struct rte_flow_action_mark *)
16882 [ # # ]: 0 : (act->conf))->id);
16883 : :
16884 [ # # ]: 0 : if (i >= MLX5_MTR_RTE_COLORS)
16885 : 0 : return -rte_mtr_error_set(error,
16886 : : ENOTSUP,
16887 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
16888 : : NULL,
16889 : : "cannot create policy "
16890 : : "mark action for this color");
16891 [ # # ]: 0 : if (flow_dv_tag_resource_register(dev, tag_be,
16892 : : &dev_flow, &flow_err))
16893 : 0 : return -rte_mtr_error_set(error,
16894 : : ENOTSUP,
16895 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
16896 : : NULL,
16897 : : "cannot setup policy mark action");
16898 : : MLX5_ASSERT(dev_flow.dv.tag_resource);
16899 : 0 : act_cnt->rix_mark =
16900 : 0 : dev_flow.handle->dvh.rix_tag;
16901 : 0 : action_flags |= MLX5_FLOW_ACTION_MARK;
16902 : 0 : mtr_policy->mark = 1;
16903 : 0 : break;
16904 : : }
16905 : 0 : case RTE_FLOW_ACTION_TYPE_SET_TAG:
16906 [ # # ]: 0 : if (i >= MLX5_MTR_RTE_COLORS)
16907 : 0 : return -rte_mtr_error_set(error,
16908 : : ENOTSUP,
16909 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
16910 : : NULL,
16911 : : "cannot create policy "
16912 : : "set tag action for this color");
16913 [ # # ]: 0 : if (flow_dv_convert_action_set_tag
16914 : : (dev, mhdr_res,
16915 : : (const struct rte_flow_action_set_tag *)
16916 : 0 : act->conf, &flow_err))
16917 : 0 : return -rte_mtr_error_set(error,
16918 : : ENOTSUP,
16919 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
16920 : : NULL, "cannot convert policy "
16921 : : "set tag action");
16922 [ # # ]: 0 : if (!mhdr_res->actions_num)
16923 : 0 : return -rte_mtr_error_set(error,
16924 : : ENOTSUP,
16925 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
16926 : : NULL, "cannot find policy "
16927 : : "set tag action");
16928 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_TAG;
16929 : 0 : break;
16930 : 0 : case RTE_FLOW_ACTION_TYPE_DROP:
16931 : : {
16932 : 0 : struct mlx5_flow_mtr_mng *mtrmng =
16933 : 0 : priv->sh->mtrmng;
16934 : : struct mlx5_flow_tbl_data_entry *tbl_data;
16935 : :
16936 : : /*
16937 : : * Create the drop table with
16938 : : * METER DROP level.
16939 : : */
16940 [ # # ]: 0 : if (!mtrmng->drop_tbl[domain]) {
16941 : 0 : mtrmng->drop_tbl[domain] =
16942 : 0 : flow_dv_tbl_resource_get(dev,
16943 : : MLX5_FLOW_TABLE_LEVEL_METER,
16944 : : egress, transfer, false, NULL, 0,
16945 : : 0, MLX5_MTR_TABLE_ID_DROP, &flow_err);
16946 [ # # ]: 0 : if (!mtrmng->drop_tbl[domain])
16947 : 0 : return -rte_mtr_error_set
16948 : : (error, ENOTSUP,
16949 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
16950 : : NULL,
16951 : : "Failed to create meter drop table");
16952 : : }
16953 : 0 : tbl_data = container_of
16954 : : (mtrmng->drop_tbl[domain],
16955 : : struct mlx5_flow_tbl_data_entry, tbl);
16956 [ # # ]: 0 : if (i < MLX5_MTR_RTE_COLORS) {
16957 : 0 : act_cnt->dr_jump_action[domain] =
16958 : 0 : tbl_data->jump.action;
16959 : 0 : act_cnt->fate_action =
16960 : : MLX5_FLOW_FATE_DROP;
16961 : : }
16962 [ # # ]: 0 : if (i == RTE_COLOR_RED)
16963 : 0 : mtr_policy->dr_drop_action[domain] =
16964 : 0 : tbl_data->jump.action;
16965 : 0 : action_flags |= MLX5_FLOW_ACTION_DROP;
16966 : 0 : break;
16967 : : }
16968 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
16969 : : {
16970 [ # # ]: 0 : if (i >= MLX5_MTR_RTE_COLORS)
16971 : 0 : return -rte_mtr_error_set(error,
16972 : : ENOTSUP,
16973 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
16974 : : NULL, "cannot create policy "
16975 : : "fate queue for this color");
16976 : 0 : act_cnt->queue =
16977 : : ((const struct rte_flow_action_queue *)
16978 : 0 : (act->conf))->index;
16979 : 0 : act_cnt->fate_action =
16980 : : MLX5_FLOW_FATE_QUEUE;
16981 : 0 : dev_flow.handle->fate_action =
16982 : : MLX5_FLOW_FATE_QUEUE;
16983 : 0 : mtr_policy->is_queue = 1;
16984 : 0 : action_flags |= MLX5_FLOW_ACTION_QUEUE;
16985 : 0 : break;
16986 : : }
16987 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
16988 : : {
16989 : : int rss_size;
16990 : :
16991 [ # # ]: 0 : if (i >= MLX5_MTR_RTE_COLORS)
16992 : 0 : return -rte_mtr_error_set(error,
16993 : : ENOTSUP,
16994 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
16995 : : NULL,
16996 : : "cannot create policy "
16997 : : "rss action for this color");
16998 : : /*
16999 : : * Save RSS conf into policy struct
17000 : : * for translate stage.
17001 : : */
17002 : 0 : rss_size = (int)rte_flow_conv
17003 : : (RTE_FLOW_CONV_OP_ACTION,
17004 : : NULL, 0, act, &flow_err);
17005 [ # # ]: 0 : if (rss_size <= 0)
17006 : 0 : return -rte_mtr_error_set(error,
17007 : : ENOTSUP,
17008 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17009 : : NULL, "Get the wrong "
17010 : : "rss action struct size");
17011 : 0 : act_cnt->rss = mlx5_malloc(MLX5_MEM_ZERO,
17012 : : rss_size, 0, SOCKET_ID_ANY);
17013 [ # # ]: 0 : if (!act_cnt->rss)
17014 : 0 : return -rte_mtr_error_set(error,
17015 : : ENOTSUP,
17016 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17017 : : NULL,
17018 : : "Fail to malloc rss action memory");
17019 : 0 : ret = rte_flow_conv(RTE_FLOW_CONV_OP_ACTION,
17020 : : act_cnt->rss, rss_size,
17021 : : act, &flow_err);
17022 [ # # ]: 0 : if (ret < 0)
17023 : 0 : return -rte_mtr_error_set(error,
17024 : : ENOTSUP,
17025 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17026 : : NULL, "Fail to save "
17027 : : "rss action into policy struct");
17028 : 0 : act_cnt->fate_action =
17029 : : MLX5_FLOW_FATE_SHARED_RSS;
17030 : 0 : action_flags |= MLX5_FLOW_ACTION_RSS;
17031 : 0 : break;
17032 : : }
17033 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_ID:
17034 : : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
17035 : : {
17036 : : struct mlx5_flow_dv_port_id_action_resource
17037 : : port_id_resource;
17038 : 0 : uint32_t port_id = 0;
17039 : :
17040 [ # # ]: 0 : if (i >= MLX5_MTR_RTE_COLORS)
17041 : 0 : return -rte_mtr_error_set(error,
17042 : : ENOTSUP,
17043 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17044 : : NULL, "cannot create policy "
17045 : : "port action for this color");
17046 : : memset(&port_id_resource, 0,
17047 : : sizeof(port_id_resource));
17048 [ # # ]: 0 : if (flow_dv_translate_action_port_id(dev, act,
17049 : : &port_id, &flow_err))
17050 : 0 : return -rte_mtr_error_set(error,
17051 : : ENOTSUP,
17052 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17053 : : NULL, "cannot translate "
17054 : : "policy port action");
17055 : 0 : port_id_resource.port_id = port_id;
17056 [ # # ]: 0 : if (flow_dv_port_id_action_resource_register
17057 : : (dev, &port_id_resource,
17058 : : &dev_flow, &flow_err))
17059 : 0 : return -rte_mtr_error_set(error,
17060 : : ENOTSUP,
17061 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17062 : : NULL, "cannot setup "
17063 : : "policy port action");
17064 : 0 : act_cnt->rix_port_id_action =
17065 : 0 : dev_flow.handle->rix_port_id_action;
17066 : 0 : act_cnt->fate_action =
17067 : : MLX5_FLOW_FATE_PORT_ID;
17068 : 0 : action_flags |= MLX5_FLOW_ACTION_PORT_ID;
17069 : 0 : break;
17070 : : }
17071 : 0 : case RTE_FLOW_ACTION_TYPE_JUMP:
17072 : : {
17073 : : uint32_t jump_group = 0;
17074 : 0 : uint32_t table = 0;
17075 : : struct mlx5_flow_tbl_data_entry *tbl_data;
17076 : 0 : struct flow_grp_info grp_info = {
17077 : 0 : .external = !!dev_flow.external,
17078 : : .transfer = !!transfer,
17079 : 0 : .fdb_def_rule = !!priv->fdb_def_rule,
17080 : : .std_tbl_fix = 0,
17081 : 0 : .skip_scale = dev_flow.skip_scale &
17082 : : (1 << MLX5_SCALE_FLOW_GROUP_BIT),
17083 : : };
17084 : 0 : struct mlx5_flow_meter_sub_policy *sub_policy =
17085 : 0 : mtr_policy->sub_policys[domain][0];
17086 : :
17087 [ # # ]: 0 : if (i >= MLX5_MTR_RTE_COLORS)
17088 : 0 : return -rte_mtr_error_set(error,
17089 : : ENOTSUP,
17090 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17091 : : NULL,
17092 : : "cannot create policy "
17093 : : "jump action for this color");
17094 : 0 : jump_group =
17095 : : ((const struct rte_flow_action_jump *)
17096 : 0 : act->conf)->group;
17097 [ # # ]: 0 : if (mlx5_flow_group_to_table(dev, NULL,
17098 : : jump_group,
17099 : : &table,
17100 : : &grp_info, &flow_err))
17101 : 0 : return -rte_mtr_error_set(error,
17102 : : ENOTSUP,
17103 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17104 : : NULL, "cannot setup "
17105 : : "policy jump action");
17106 : 0 : sub_policy->jump_tbl[i] =
17107 : 0 : flow_dv_tbl_resource_get(dev,
17108 : : table, egress,
17109 : : transfer,
17110 : : !!dev_flow.external,
17111 : : NULL, jump_group, 0,
17112 : : 0, &flow_err);
17113 : : if
17114 [ # # ]: 0 : (!sub_policy->jump_tbl[i])
17115 : 0 : return -rte_mtr_error_set(error,
17116 : : ENOTSUP,
17117 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17118 : : NULL, "cannot create jump action.");
17119 : 0 : tbl_data = container_of
17120 : : (sub_policy->jump_tbl[i],
17121 : : struct mlx5_flow_tbl_data_entry, tbl);
17122 : 0 : act_cnt->dr_jump_action[domain] =
17123 : 0 : tbl_data->jump.action;
17124 : 0 : act_cnt->fate_action =
17125 : : MLX5_FLOW_FATE_JUMP;
17126 : 0 : action_flags |= MLX5_FLOW_ACTION_JUMP;
17127 : 0 : break;
17128 : : }
17129 : 0 : case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
17130 : : {
17131 [ # # ]: 0 : if (i >= MLX5_MTR_RTE_COLORS)
17132 : 0 : return -rte_mtr_error_set(error,
17133 : : ENOTSUP,
17134 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17135 : : NULL,
17136 : : "cannot create policy modify field for this color");
17137 [ # # ]: 0 : if (flow_dv_convert_action_modify_field
17138 : : (dev, mhdr_res, act, attr, &flow_err))
17139 : 0 : return -rte_mtr_error_set(error,
17140 : : ENOTSUP,
17141 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17142 : : NULL, "cannot setup policy modify field action");
17143 [ # # ]: 0 : if (!mhdr_res->actions_num)
17144 : 0 : return -rte_mtr_error_set(error,
17145 : : ENOTSUP,
17146 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17147 : : NULL, "cannot find policy modify field action");
17148 : 0 : action_flags |= MLX5_FLOW_ACTION_MODIFY_FIELD;
17149 : 0 : break;
17150 : : }
17151 : : /*
17152 : : * No need to check meter hierarchy for R colors
17153 : : * here since it is done in the validation stage.
17154 : : */
17155 : 0 : case RTE_FLOW_ACTION_TYPE_METER:
17156 : : {
17157 : : const struct rte_flow_action_meter *mtr;
17158 : : struct mlx5_flow_meter_info *next_fm;
17159 : : struct mlx5_flow_meter_policy *next_policy;
17160 : : struct rte_flow_action tag_action;
17161 : : struct mlx5_rte_flow_action_set_tag set_tag;
17162 : 0 : uint32_t next_mtr_idx = 0;
17163 : :
17164 : 0 : mtr = act->conf;
17165 : 0 : next_fm = mlx5_flow_meter_find(priv,
17166 : 0 : mtr->mtr_id,
17167 : : &next_mtr_idx);
17168 [ # # ]: 0 : if (!next_fm)
17169 : 0 : return -rte_mtr_error_set(error, EINVAL,
17170 : : RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
17171 : : "Fail to find next meter.");
17172 [ # # ]: 0 : if (next_fm->def_policy)
17173 : 0 : return -rte_mtr_error_set(error, EINVAL,
17174 : : RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
17175 : : "Hierarchy only supports termination meter.");
17176 : 0 : next_policy = mlx5_flow_meter_policy_find(dev,
17177 : : next_fm->policy_id, NULL);
17178 : : MLX5_ASSERT(next_policy);
17179 [ # # ]: 0 : if (next_fm->drop_cnt) {
17180 : 0 : set_tag.id =
17181 : 0 : (enum modify_reg)
17182 : 0 : mlx5_flow_get_reg_id(dev,
17183 : : MLX5_MTR_ID,
17184 : : 0,
17185 : : (struct rte_flow_error *)error);
17186 : 0 : set_tag.offset = (priv->mtr_reg_share ?
17187 : 0 : MLX5_MTR_COLOR_BITS : 0);
17188 [ # # ]: 0 : set_tag.length = (priv->mtr_reg_share ?
17189 : : MLX5_MTR_IDLE_BITS_IN_COLOR_REG :
17190 : : MLX5_REG_BITS);
17191 : 0 : set_tag.data = next_mtr_idx;
17192 : 0 : tag_action.type =
17193 : : (enum rte_flow_action_type)
17194 : : MLX5_RTE_FLOW_ACTION_TYPE_TAG;
17195 : 0 : tag_action.conf = &set_tag;
17196 [ # # ]: 0 : if (flow_dv_convert_action_set_reg
17197 : : (mhdr_res, &tag_action,
17198 : : (struct rte_flow_error *)error))
17199 : 0 : return -rte_errno;
17200 : 0 : action_flags |=
17201 : : MLX5_FLOW_ACTION_SET_TAG;
17202 : : }
17203 [ # # # # ]: 0 : if (i == RTE_COLOR_YELLOW && next_fm->color_aware &&
17204 [ # # ]: 0 : !next_fm->meter_action_y)
17205 [ # # ]: 0 : if (__flow_dv_create_mtr_yellow_action(dev, next_fm, error))
17206 : 0 : return -rte_errno;
17207 : 0 : act_cnt->fate_action = MLX5_FLOW_FATE_MTR;
17208 : 0 : act_cnt->next_mtr_id = next_fm->meter_id;
17209 : 0 : act_cnt->next_sub_policy = NULL;
17210 : 0 : mtr_policy->is_hierarchy = 1;
17211 [ # # ]: 0 : if (next_policy->mark)
17212 : 0 : mtr_policy->mark = 1;
17213 : 0 : mtr_policy->hierarchy_match_port =
17214 : 0 : next_policy->hierarchy_match_port;
17215 : 0 : action_flags |=
17216 : : MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY;
17217 : 0 : break;
17218 : : }
17219 : : default:
17220 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
17221 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17222 : : NULL, "action type not supported");
17223 : : }
17224 [ # # ]: 0 : if ((action_flags & MLX5_FLOW_ACTION_SET_TAG) ||
17225 : : (action_flags & MLX5_FLOW_ACTION_MODIFY_FIELD)) {
17226 : : /* create modify action if needed. */
17227 : 0 : dev_flow.dv.group = 1;
17228 [ # # ]: 0 : if (flow_dv_modify_hdr_resource_register
17229 : : (dev, mhdr_res, &dev_flow, &flow_err))
17230 : 0 : return -rte_mtr_error_set(error,
17231 : : ENOTSUP,
17232 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17233 : : NULL, "cannot register policy set tag/modify field action");
17234 : 0 : act_cnt->modify_hdr =
17235 : 0 : dev_flow.handle->dvh.modify_hdr;
17236 : : }
17237 : : }
17238 : : }
17239 : : return 0;
17240 : : }
17241 : :
17242 : : /**
17243 : : * Create policy action per domain, lock free,
17244 : : * (mutex should be acquired by caller).
17245 : : * Dispatcher for action type specific call.
17246 : : *
17247 : : * @param[in] dev
17248 : : * Pointer to the Ethernet device structure.
17249 : : * @param[in] mtr_policy
17250 : : * Meter policy struct.
17251 : : * @param[in] action
17252 : : * Action specification used to create meter actions.
17253 : : * @param[in] attr
17254 : : * Pointer to the flow attributes.
17255 : : * @param[out] error
17256 : : * Perform verbose error reporting if not NULL. Initialized in case of
17257 : : * error only.
17258 : : *
17259 : : * @return
17260 : : * 0 on success, otherwise negative errno value.
17261 : : */
17262 : : static int
17263 : 0 : flow_dv_create_mtr_policy_acts(struct rte_eth_dev *dev,
17264 : : struct mlx5_flow_meter_policy *mtr_policy,
17265 : : const struct rte_flow_action *actions[RTE_COLORS],
17266 : : struct rte_flow_attr *attr,
17267 : : struct rte_mtr_error *error)
17268 : : {
17269 : : int ret, i;
17270 : : uint16_t sub_policy_num;
17271 : :
17272 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
17273 : 0 : sub_policy_num = (mtr_policy->sub_policy_num >>
17274 : 0 : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i)) &
17275 : : MLX5_MTR_SUB_POLICY_NUM_MASK;
17276 [ # # ]: 0 : if (sub_policy_num) {
17277 : 0 : ret = __flow_dv_create_domain_policy_acts(dev,
17278 : : mtr_policy, actions, attr,
17279 : : (enum mlx5_meter_domain)i, error);
17280 : : /* Cleaning resource is done in the caller level. */
17281 [ # # ]: 0 : if (ret)
17282 : 0 : return ret;
17283 : : }
17284 : : }
17285 : : return 0;
17286 : : }
17287 : :
17288 : : /**
17289 : : * Query a DV flow rule for its statistics via DevX.
17290 : : *
17291 : : * @param[in] dev
17292 : : * Pointer to Ethernet device.
17293 : : * @param[in] cnt_idx
17294 : : * Index to the flow counter.
17295 : : * @param[out] data
17296 : : * Data retrieved by the query.
17297 : : * @param[out] error
17298 : : * Perform verbose error reporting if not NULL.
17299 : : *
17300 : : * @return
17301 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
17302 : : */
17303 : : static int
17304 : 0 : flow_dv_query_count(struct rte_eth_dev *dev, uint32_t cnt_idx, void *data,
17305 : : struct rte_flow_error *error)
17306 : : {
17307 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
17308 : : struct rte_flow_query_count *qc = data;
17309 : :
17310 [ # # ]: 0 : if (!priv->sh->cdev->config.devx)
17311 : 0 : return rte_flow_error_set(error, ENOTSUP,
17312 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
17313 : : NULL,
17314 : : "counters are not supported");
17315 [ # # ]: 0 : if (cnt_idx) {
17316 : : uint64_t pkts, bytes;
17317 : : struct mlx5_flow_counter *cnt;
17318 : 0 : int err = _flow_dv_query_count(dev, cnt_idx, &pkts, &bytes);
17319 : :
17320 [ # # ]: 0 : if (err)
17321 : 0 : return rte_flow_error_set(error, -err,
17322 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
17323 : : NULL, "cannot read counters");
17324 : : cnt = flow_dv_counter_get_by_idx(dev, cnt_idx, NULL);
17325 : 0 : qc->hits_set = 1;
17326 : 0 : qc->bytes_set = 1;
17327 : 0 : qc->hits = pkts - cnt->hits;
17328 : 0 : qc->bytes = bytes - cnt->bytes;
17329 [ # # ]: 0 : if (qc->reset) {
17330 : 0 : cnt->hits = pkts;
17331 : 0 : cnt->bytes = bytes;
17332 : : }
17333 : 0 : return 0;
17334 : : }
17335 : 0 : return rte_flow_error_set(error, EINVAL,
17336 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
17337 : : NULL,
17338 : : "counters are not available");
17339 : : }
17340 : :
17341 : : int
17342 : 0 : flow_dv_action_query(struct rte_eth_dev *dev,
17343 : : const struct rte_flow_action_handle *handle, void *data,
17344 : : struct rte_flow_error *error)
17345 : : {
17346 : : struct mlx5_age_param *age_param;
17347 : : struct rte_flow_query_age *resp;
17348 : 0 : uint32_t act_idx = (uint32_t)(uintptr_t)handle;
17349 : 0 : uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
17350 : 0 : uint32_t idx = act_idx & ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
17351 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
17352 : : struct mlx5_aso_ct_action *ct;
17353 : : uint16_t owner;
17354 : : uint32_t dev_idx;
17355 : :
17356 [ # # # # ]: 0 : switch (type) {
17357 : 0 : case MLX5_INDIRECT_ACTION_TYPE_AGE:
17358 : 0 : age_param = &flow_aso_age_get_by_idx(dev, idx)->age_params;
17359 : : resp = data;
17360 : 0 : resp->aged = __atomic_load_n(&age_param->state,
17361 : : __ATOMIC_RELAXED) == AGE_TMOUT ?
17362 : 0 : 1 : 0;
17363 : 0 : resp->sec_since_last_hit_valid = !resp->aged;
17364 [ # # ]: 0 : if (resp->sec_since_last_hit_valid)
17365 : 0 : resp->sec_since_last_hit = __atomic_load_n
17366 : 0 : (&age_param->sec_since_last_hit, __ATOMIC_RELAXED);
17367 : : return 0;
17368 : 0 : case MLX5_INDIRECT_ACTION_TYPE_COUNT:
17369 : 0 : return flow_dv_query_count(dev, idx, data, error);
17370 : 0 : case MLX5_INDIRECT_ACTION_TYPE_CT:
17371 : 0 : owner = (uint16_t)MLX5_INDIRECT_ACT_CT_GET_OWNER(idx);
17372 [ # # ]: 0 : if (owner != PORT_ID(priv))
17373 : 0 : return rte_flow_error_set(error, EACCES,
17374 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
17375 : : NULL,
17376 : : "CT object owned by another port");
17377 : 0 : dev_idx = MLX5_INDIRECT_ACT_CT_GET_IDX(idx);
17378 : 0 : ct = flow_aso_ct_get_by_dev_idx(dev, dev_idx);
17379 : : MLX5_ASSERT(ct);
17380 [ # # ]: 0 : if (!ct->refcnt)
17381 : 0 : return rte_flow_error_set(error, EFAULT,
17382 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
17383 : : NULL,
17384 : : "CT object is inactive");
17385 : 0 : ((struct rte_flow_action_conntrack *)data)->peer_port =
17386 : 0 : ct->peer;
17387 : 0 : ((struct rte_flow_action_conntrack *)data)->is_original_dir =
17388 : 0 : ct->is_original;
17389 [ # # ]: 0 : if (mlx5_aso_ct_query_by_wqe(priv->sh, MLX5_HW_INV_QUEUE, ct,
17390 : : data, NULL, true))
17391 : 0 : return rte_flow_error_set(error, EIO,
17392 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
17393 : : NULL,
17394 : : "Failed to query CT context");
17395 : : return 0;
17396 : 0 : default:
17397 : 0 : return rte_flow_error_set(error, ENOTSUP,
17398 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
17399 : : "action type query not supported");
17400 : : }
17401 : : }
17402 : :
17403 : : /**
17404 : : * Query a flow rule AGE action for aging information.
17405 : : *
17406 : : * @param[in] dev
17407 : : * Pointer to Ethernet device.
17408 : : * @param[in] flow
17409 : : * Pointer to the sub flow.
17410 : : * @param[out] data
17411 : : * data retrieved by the query.
17412 : : * @param[out] error
17413 : : * Perform verbose error reporting if not NULL.
17414 : : *
17415 : : * @return
17416 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
17417 : : */
17418 : : static int
17419 : 0 : flow_dv_query_age(struct rte_eth_dev *dev, struct rte_flow *flow,
17420 : : void *data, struct rte_flow_error *error)
17421 : : {
17422 : : struct rte_flow_query_age *resp = data;
17423 : : struct mlx5_age_param *age_param;
17424 : :
17425 [ # # ]: 0 : if (flow->age) {
17426 : : struct mlx5_aso_age_action *act =
17427 : 0 : flow_aso_age_get_by_idx(dev, flow->age);
17428 : :
17429 : 0 : age_param = &act->age_params;
17430 [ # # ]: 0 : } else if (flow->counter) {
17431 : : age_param = flow_dv_counter_idx_get_age(dev, flow->counter);
17432 : :
17433 [ # # ]: 0 : if (!age_param || !age_param->timeout)
17434 : 0 : return rte_flow_error_set
17435 : : (error, EINVAL,
17436 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
17437 : : NULL, "cannot read age data");
17438 : : } else {
17439 : 0 : return rte_flow_error_set(error, EINVAL,
17440 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
17441 : : NULL, "age data not available");
17442 : : }
17443 : 0 : resp->aged = __atomic_load_n(&age_param->state, __ATOMIC_RELAXED) ==
17444 : 0 : AGE_TMOUT ? 1 : 0;
17445 : 0 : resp->sec_since_last_hit_valid = !resp->aged;
17446 [ # # ]: 0 : if (resp->sec_since_last_hit_valid)
17447 : 0 : resp->sec_since_last_hit = __atomic_load_n
17448 : 0 : (&age_param->sec_since_last_hit, __ATOMIC_RELAXED);
17449 : : return 0;
17450 : : }
17451 : :
17452 : : /**
17453 : : * Query a flow.
17454 : : *
17455 : : * @see rte_flow_query()
17456 : : * @see rte_flow_ops
17457 : : */
17458 : : static int
17459 : 0 : flow_dv_query(struct rte_eth_dev *dev,
17460 : : struct rte_flow *flow __rte_unused,
17461 : : const struct rte_flow_action *actions __rte_unused,
17462 : : void *data __rte_unused,
17463 : : struct rte_flow_error *error __rte_unused)
17464 : : {
17465 : : int ret = -EINVAL;
17466 : :
17467 [ # # ]: 0 : for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
17468 [ # # # # ]: 0 : switch (actions->type) {
17469 : : case RTE_FLOW_ACTION_TYPE_VOID:
17470 : : break;
17471 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
17472 : 0 : ret = flow_dv_query_count(dev, flow->counter, data,
17473 : : error);
17474 : 0 : break;
17475 : 0 : case RTE_FLOW_ACTION_TYPE_AGE:
17476 : 0 : ret = flow_dv_query_age(dev, flow, data, error);
17477 : 0 : break;
17478 : 0 : default:
17479 : 0 : return rte_flow_error_set(error, ENOTSUP,
17480 : : RTE_FLOW_ERROR_TYPE_ACTION,
17481 : : actions,
17482 : : "action not supported");
17483 : : }
17484 : : }
17485 : : return ret;
17486 : : }
17487 : :
17488 : : /**
17489 : : * Destroy the meter table set.
17490 : : * Lock free, (mutex should be acquired by caller).
17491 : : *
17492 : : * @param[in] dev
17493 : : * Pointer to Ethernet device.
17494 : : * @param[in] fm
17495 : : * Meter information table.
17496 : : */
17497 : : static void
17498 : 0 : flow_dv_destroy_mtr_tbls(struct rte_eth_dev *dev,
17499 : : struct mlx5_flow_meter_info *fm)
17500 : : {
17501 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
17502 : : int i;
17503 : :
17504 [ # # # # ]: 0 : if (!fm || !priv->sh->config.dv_flow_en)
17505 : : return;
17506 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
17507 [ # # ]: 0 : if (fm->drop_rule[i]) {
17508 : : claim_zero(mlx5_flow_os_destroy_flow(fm->drop_rule[i]));
17509 : 0 : fm->drop_rule[i] = NULL;
17510 : : }
17511 : : }
17512 : : }
17513 : :
17514 : : static void
17515 : 0 : flow_dv_destroy_mtr_drop_tbls(struct rte_eth_dev *dev)
17516 : : {
17517 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
17518 : 0 : struct mlx5_flow_mtr_mng *mtrmng = priv->sh->mtrmng;
17519 : : struct mlx5_flow_tbl_data_entry *tbl;
17520 : : int i, j;
17521 : :
17522 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
17523 [ # # ]: 0 : if (mtrmng->def_rule[i]) {
17524 : : claim_zero(mlx5_flow_os_destroy_flow
17525 : : (mtrmng->def_rule[i]));
17526 : 0 : mtrmng->def_rule[i] = NULL;
17527 : : }
17528 [ # # ]: 0 : if (mtrmng->def_matcher[i]) {
17529 : 0 : tbl = container_of(mtrmng->def_matcher[i]->tbl,
17530 : : struct mlx5_flow_tbl_data_entry, tbl);
17531 : 0 : mlx5_list_unregister(tbl->matchers,
17532 : : &mtrmng->def_matcher[i]->entry);
17533 : 0 : mtrmng->def_matcher[i] = NULL;
17534 : : }
17535 [ # # ]: 0 : for (j = 0; j < MLX5_REG_BITS; j++) {
17536 [ # # ]: 0 : if (mtrmng->drop_matcher[i][j]) {
17537 : : tbl =
17538 : 0 : container_of(mtrmng->drop_matcher[i][j]->tbl,
17539 : : struct mlx5_flow_tbl_data_entry,
17540 : : tbl);
17541 : 0 : mlx5_list_unregister(tbl->matchers,
17542 : : &mtrmng->drop_matcher[i][j]->entry);
17543 : 0 : mtrmng->drop_matcher[i][j] = NULL;
17544 : : }
17545 : : }
17546 [ # # ]: 0 : if (mtrmng->drop_tbl[i]) {
17547 : 0 : flow_dv_tbl_resource_release(MLX5_SH(dev),
17548 : : mtrmng->drop_tbl[i]);
17549 : 0 : mtrmng->drop_tbl[i] = NULL;
17550 : : }
17551 : : }
17552 : 0 : }
17553 : :
17554 : : /* Number of meter flow actions, count and jump or count and drop. */
17555 : : #define METER_ACTIONS 2
17556 : :
17557 : : static void
17558 : 0 : __flow_dv_destroy_domain_def_policy(struct rte_eth_dev *dev,
17559 : : enum mlx5_meter_domain domain)
17560 : : {
17561 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
17562 : 0 : struct mlx5_flow_meter_def_policy *def_policy =
17563 : 0 : priv->sh->mtrmng->def_policy[domain];
17564 : :
17565 : 0 : __flow_dv_destroy_sub_policy_rules(dev, &def_policy->sub_policy);
17566 : 0 : mlx5_free(def_policy);
17567 : 0 : priv->sh->mtrmng->def_policy[domain] = NULL;
17568 : 0 : }
17569 : :
17570 : : /**
17571 : : * Destroy the default policy table set.
17572 : : *
17573 : : * @param[in] dev
17574 : : * Pointer to Ethernet device.
17575 : : */
17576 : : static void
17577 : 0 : flow_dv_destroy_def_policy(struct rte_eth_dev *dev)
17578 : : {
17579 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
17580 : : int i;
17581 : :
17582 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++)
17583 [ # # ]: 0 : if (priv->sh->mtrmng->def_policy[i])
17584 : 0 : __flow_dv_destroy_domain_def_policy(dev,
17585 : : (enum mlx5_meter_domain)i);
17586 : 0 : priv->sh->mtrmng->def_policy_id = MLX5_INVALID_POLICY_ID;
17587 : 0 : }
17588 : :
17589 : : static int
17590 : 0 : __flow_dv_create_policy_flow(struct rte_eth_dev *dev,
17591 : : uint32_t color_reg_c_idx,
17592 : : enum rte_color color, struct mlx5_flow_dv_matcher *matcher,
17593 : : int actions_n, void *actions,
17594 : : bool match_src_port, const struct rte_flow_item *item,
17595 : : void **rule, const struct rte_flow_attr *attr)
17596 : : {
17597 : : int ret;
17598 : 0 : struct mlx5_flow_dv_match_params value = {
17599 : : .size = sizeof(value.buf),
17600 : : };
17601 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
17602 : : uint8_t misc_mask;
17603 : :
17604 [ # # # # ]: 0 : if (match_src_port && priv->sh->esw_mode) {
17605 [ # # # # ]: 0 : if (item && item->type == RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT)
17606 : 0 : ret = flow_dv_translate_item_represented_port(dev, value.buf,
17607 : : item, attr, MLX5_SET_MATCHER_SW_V);
17608 [ # # # # ]: 0 : else if (item && item->type == RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR)
17609 : 0 : ret = flow_dv_translate_item_port_representor(dev, value.buf,
17610 : : MLX5_SET_MATCHER_SW_V);
17611 : : else
17612 : 0 : ret = flow_dv_translate_item_port_id(dev, value.buf,
17613 : : item, attr, MLX5_SET_MATCHER_SW_V);
17614 [ # # ]: 0 : if (ret) {
17615 : 0 : DRV_LOG(ERR, "Failed to create meter policy%d flow's"
17616 : : " value with port.", color);
17617 : 0 : return -1;
17618 : : }
17619 : : }
17620 : 0 : flow_dv_match_meta_reg(value.buf, (enum modify_reg)color_reg_c_idx,
17621 : : rte_col_2_mlx5_col(color), UINT32_MAX);
17622 [ # # ]: 0 : misc_mask = flow_dv_matcher_enable(matcher->mask.buf);
17623 : : __flow_dv_adjust_buf_size(&value.size, misc_mask);
17624 : 0 : ret = mlx5_flow_os_create_flow(matcher->matcher_object, (void *)&value,
17625 : : actions_n, actions, rule);
17626 : : if (ret) {
17627 : 0 : DRV_LOG(ERR, "Failed to create meter policy%d flow.", color);
17628 : 0 : return -1;
17629 : : }
17630 : : return 0;
17631 : : }
17632 : :
17633 : : static int
17634 : 0 : __flow_dv_create_policy_matcher(struct rte_eth_dev *dev,
17635 : : uint32_t color_reg_c_idx,
17636 : : uint16_t priority,
17637 : : struct mlx5_flow_meter_sub_policy *sub_policy,
17638 : : const struct rte_flow_attr *attr,
17639 : : bool match_src_port,
17640 : : const struct rte_flow_item *item,
17641 : : struct mlx5_flow_dv_matcher **policy_matcher,
17642 : : struct rte_flow_error *error)
17643 : : {
17644 : : struct mlx5_list_entry *entry;
17645 : 0 : struct mlx5_flow_tbl_resource *tbl_rsc = sub_policy->tbl_rsc;
17646 : 0 : struct mlx5_flow_dv_matcher matcher = {
17647 : : .mask = {
17648 : : .size = sizeof(matcher.mask.buf),
17649 : : },
17650 : : .tbl = tbl_rsc,
17651 : : };
17652 : 0 : struct mlx5_flow_cb_ctx ctx = {
17653 : : .error = error,
17654 : : .data = &matcher,
17655 : : };
17656 : : struct mlx5_flow_tbl_data_entry *tbl_data;
17657 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
17658 : : const uint32_t color_mask = (UINT32_C(1) << MLX5_MTR_COLOR_BITS) - 1;
17659 : : int ret;
17660 : :
17661 [ # # # # ]: 0 : if (match_src_port && priv->sh->esw_mode) {
17662 [ # # # # ]: 0 : if (item && item->type == RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT)
17663 : 0 : ret = flow_dv_translate_item_represented_port(dev, matcher.mask.buf,
17664 : : item, attr, MLX5_SET_MATCHER_SW_M);
17665 [ # # # # ]: 0 : else if (item && item->type == RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR)
17666 : 0 : ret = flow_dv_translate_item_port_representor(dev, matcher.mask.buf,
17667 : : MLX5_SET_MATCHER_SW_M);
17668 : : else
17669 : 0 : ret = flow_dv_translate_item_port_id(dev, matcher.mask.buf,
17670 : : item, attr, MLX5_SET_MATCHER_SW_M);
17671 [ # # ]: 0 : if (ret) {
17672 : 0 : DRV_LOG(ERR, "Failed to register meter policy%d matcher"
17673 : : " with port.", priority);
17674 : 0 : return -1;
17675 : : }
17676 : : }
17677 : 0 : tbl_data = container_of(tbl_rsc, struct mlx5_flow_tbl_data_entry, tbl);
17678 [ # # ]: 0 : if (priority < RTE_COLOR_RED)
17679 : 0 : flow_dv_match_meta_reg(matcher.mask.buf,
17680 : : (enum modify_reg)color_reg_c_idx, color_mask, color_mask);
17681 : 0 : matcher.priority = priority;
17682 : 0 : matcher.crc = rte_raw_cksum((const void *)matcher.mask.buf,
17683 : : matcher.mask.size);
17684 : 0 : entry = mlx5_list_register(tbl_data->matchers, &ctx);
17685 [ # # ]: 0 : if (!entry) {
17686 : 0 : DRV_LOG(ERR, "Failed to register meter drop matcher.");
17687 : 0 : return -1;
17688 : : }
17689 : 0 : *policy_matcher =
17690 : : container_of(entry, struct mlx5_flow_dv_matcher, entry);
17691 : 0 : return 0;
17692 : : }
17693 : :
17694 : : /**
17695 : : * Create the policy rules per domain.
17696 : : *
17697 : : * @param[in] dev
17698 : : * Pointer to Ethernet device.
17699 : : * @param[in] sub_policy
17700 : : * Pointer to sub policy table..
17701 : : * @param[in] egress
17702 : : * Direction of the table.
17703 : : * @param[in] transfer
17704 : : * E-Switch or NIC flow.
17705 : : * @param[in] acts
17706 : : * Pointer to policy action list per color.
17707 : : *
17708 : : * @return
17709 : : * 0 on success, -1 otherwise.
17710 : : */
17711 : : static int
17712 : 0 : __flow_dv_create_domain_policy_rules(struct rte_eth_dev *dev,
17713 : : struct mlx5_flow_meter_sub_policy *sub_policy,
17714 : : uint8_t egress, uint8_t transfer, bool match_src_port,
17715 : : struct mlx5_meter_policy_acts acts[RTE_COLORS])
17716 : : {
17717 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
17718 : : struct rte_flow_error flow_err;
17719 : : uint32_t color_reg_c_idx;
17720 : 0 : struct rte_flow_attr attr = {
17721 : : .group = MLX5_FLOW_TABLE_LEVEL_POLICY,
17722 : : .priority = 0,
17723 : : .ingress = 0,
17724 : 0 : .egress = !!egress,
17725 : 0 : .transfer = !!transfer,
17726 : : .reserved = 0,
17727 : : };
17728 : : int i;
17729 : 0 : int ret = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, &flow_err);
17730 : : struct mlx5_sub_policy_color_rule *color_rule;
17731 : : bool svport_match;
17732 : 0 : struct mlx5_sub_policy_color_rule *tmp_rules[RTE_COLORS] = {NULL};
17733 : :
17734 [ # # ]: 0 : if (ret < 0)
17735 : : return -1;
17736 : : /* Create policy table with POLICY level. */
17737 [ # # ]: 0 : if (!sub_policy->tbl_rsc)
17738 : 0 : sub_policy->tbl_rsc = flow_dv_tbl_resource_get(dev,
17739 : : MLX5_FLOW_TABLE_LEVEL_POLICY,
17740 : : egress, transfer, false, NULL, 0, 0,
17741 : 0 : sub_policy->idx, &flow_err);
17742 [ # # ]: 0 : if (!sub_policy->tbl_rsc) {
17743 : 0 : DRV_LOG(ERR,
17744 : : "Failed to create meter sub policy table.");
17745 : 0 : return -1;
17746 : : }
17747 : : /* Prepare matchers. */
17748 : 0 : color_reg_c_idx = ret;
17749 [ # # ]: 0 : for (i = 0; i < RTE_COLORS; i++) {
17750 : 0 : TAILQ_INIT(&sub_policy->color_rules[i]);
17751 [ # # ]: 0 : if (!acts[i].actions_n)
17752 : 0 : continue;
17753 : 0 : color_rule = mlx5_malloc(MLX5_MEM_ZERO,
17754 : : sizeof(struct mlx5_sub_policy_color_rule),
17755 : : 0, SOCKET_ID_ANY);
17756 [ # # ]: 0 : if (!color_rule) {
17757 : 0 : DRV_LOG(ERR, "No memory to create color rule.");
17758 : 0 : goto err_exit;
17759 : : }
17760 : 0 : tmp_rules[i] = color_rule;
17761 : 0 : TAILQ_INSERT_TAIL(&sub_policy->color_rules[i],
17762 : : color_rule, next_port);
17763 : 0 : color_rule->src_port = priv->representor_id;
17764 : : /* No use. */
17765 : 0 : attr.priority = i;
17766 : : /* Create matchers for colors. */
17767 [ # # # # ]: 0 : svport_match = (i != RTE_COLOR_RED) ? match_src_port : false;
17768 [ # # ]: 0 : if (__flow_dv_create_policy_matcher(dev, color_reg_c_idx,
17769 : : MLX5_MTR_POLICY_MATCHER_PRIO, sub_policy,
17770 : : &attr, svport_match, NULL,
17771 : : &color_rule->matcher, &flow_err)) {
17772 : 0 : DRV_LOG(ERR, "Failed to create color%u matcher.", i);
17773 : 0 : goto err_exit;
17774 : : }
17775 : : /* Create flow, matching color. */
17776 [ # # ]: 0 : if (__flow_dv_create_policy_flow(dev,
17777 : : color_reg_c_idx, (enum rte_color)i,
17778 : : color_rule->matcher,
17779 : 0 : acts[i].actions_n, acts[i].dv_actions,
17780 : : svport_match, NULL, &color_rule->rule,
17781 : : &attr)) {
17782 : 0 : DRV_LOG(ERR, "Failed to create color%u rule.", i);
17783 : 0 : goto err_exit;
17784 : : }
17785 : : }
17786 : : return 0;
17787 : : err_exit:
17788 : : /* All the policy rules will be cleared. */
17789 : : do {
17790 : 0 : color_rule = tmp_rules[i];
17791 [ # # ]: 0 : if (color_rule) {
17792 [ # # ]: 0 : if (color_rule->rule)
17793 : : mlx5_flow_os_destroy_flow(color_rule->rule);
17794 [ # # ]: 0 : if (color_rule->matcher) {
17795 : : struct mlx5_flow_tbl_data_entry *tbl =
17796 : 0 : container_of(color_rule->matcher->tbl,
17797 : : typeof(*tbl), tbl);
17798 : 0 : mlx5_list_unregister(tbl->matchers,
17799 : : &color_rule->matcher->entry);
17800 : : }
17801 [ # # ]: 0 : TAILQ_REMOVE(&sub_policy->color_rules[i],
17802 : : color_rule, next_port);
17803 : 0 : mlx5_free(color_rule);
17804 : : }
17805 [ # # ]: 0 : } while (i--);
17806 : : return -1;
17807 : : }
17808 : :
17809 : : static int
17810 : 0 : __flow_dv_create_policy_acts_rules(struct rte_eth_dev *dev,
17811 : : struct mlx5_flow_meter_policy *mtr_policy,
17812 : : struct mlx5_flow_meter_sub_policy *sub_policy,
17813 : : uint32_t domain)
17814 : : {
17815 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
17816 : : struct mlx5_meter_policy_acts acts[RTE_COLORS];
17817 : : struct mlx5_flow_dv_tag_resource *tag;
17818 : : struct mlx5_flow_dv_port_id_action_resource *port_action;
17819 : : struct mlx5_hrxq *hrxq;
17820 : 0 : struct mlx5_flow_meter_info *next_fm[RTE_COLORS] = {NULL};
17821 : : struct mlx5_flow_meter_policy *next_policy;
17822 : : struct mlx5_flow_meter_sub_policy *next_sub_policy;
17823 : : struct mlx5_flow_tbl_data_entry *tbl_data;
17824 : : struct rte_flow_error error;
17825 : 0 : uint8_t egress = (domain == MLX5_MTR_DOMAIN_EGRESS) ? 1 : 0;
17826 : 0 : uint8_t transfer = (domain == MLX5_MTR_DOMAIN_TRANSFER) ? 1 : 0;
17827 [ # # # # : 0 : bool mtr_first = egress || (transfer && priv->representor_id != UINT16_MAX);
# # ]
17828 : : bool match_src_port = false;
17829 : : int i;
17830 : :
17831 : : /* If RSS or Queue, no previous actions / rules is created. */
17832 [ # # ]: 0 : for (i = 0; i < RTE_COLORS; i++) {
17833 : 0 : acts[i].actions_n = 0;
17834 [ # # ]: 0 : if (i == RTE_COLOR_RED) {
17835 : : /* Only support drop on red. */
17836 : 0 : acts[i].dv_actions[0] =
17837 : 0 : mtr_policy->dr_drop_action[domain];
17838 : 0 : acts[i].actions_n = 1;
17839 : 0 : continue;
17840 : : }
17841 [ # # ]: 0 : if (mtr_policy->act_cnt[i].fate_action == MLX5_FLOW_FATE_MTR) {
17842 : 0 : struct rte_flow_attr attr = {
17843 : : .transfer = transfer
17844 : : };
17845 : :
17846 : 0 : next_fm[i] = mlx5_flow_meter_find(priv,
17847 : : mtr_policy->act_cnt[i].next_mtr_id,
17848 : : NULL);
17849 [ # # ]: 0 : if (!next_fm[i]) {
17850 : 0 : DRV_LOG(ERR,
17851 : : "Failed to get next hierarchy meter.");
17852 : 0 : goto err_exit;
17853 : : }
17854 [ # # ]: 0 : if (mlx5_flow_meter_attach(priv, next_fm[i],
17855 : : &attr, &error)) {
17856 : 0 : DRV_LOG(ERR, "%s", error.message);
17857 : 0 : next_fm[i] = NULL;
17858 : 0 : goto err_exit;
17859 : : }
17860 : : /* Meter action must be the first for TX. */
17861 [ # # ]: 0 : if (mtr_first) {
17862 : 0 : acts[i].dv_actions[acts[i].actions_n] =
17863 [ # # ]: 0 : (next_fm[i]->color_aware && i == RTE_COLOR_YELLOW) ?
17864 [ # # ]: 0 : next_fm[i]->meter_action_y :
17865 : : next_fm[i]->meter_action_g;
17866 : 0 : acts[i].actions_n++;
17867 : : }
17868 : : }
17869 [ # # ]: 0 : if (mtr_policy->act_cnt[i].rix_mark) {
17870 : 0 : tag = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_TAG],
17871 : : mtr_policy->act_cnt[i].rix_mark);
17872 [ # # ]: 0 : if (!tag) {
17873 : 0 : DRV_LOG(ERR, "Failed to find "
17874 : : "mark action for policy.");
17875 : 0 : goto err_exit;
17876 : : }
17877 : 0 : acts[i].dv_actions[acts[i].actions_n] = tag->action;
17878 : 0 : acts[i].actions_n++;
17879 : : }
17880 [ # # ]: 0 : if (mtr_policy->act_cnt[i].modify_hdr) {
17881 : 0 : acts[i].dv_actions[acts[i].actions_n] =
17882 : 0 : mtr_policy->act_cnt[i].modify_hdr->action;
17883 : 0 : acts[i].actions_n++;
17884 : : }
17885 [ # # ]: 0 : if (mtr_policy->act_cnt[i].fate_action) {
17886 [ # # # # : 0 : switch (mtr_policy->act_cnt[i].fate_action) {
# ]
17887 : 0 : case MLX5_FLOW_FATE_PORT_ID:
17888 : 0 : port_action = mlx5_ipool_get
17889 : 0 : (priv->sh->ipool[MLX5_IPOOL_PORT_ID],
17890 : : mtr_policy->act_cnt[i].rix_port_id_action);
17891 [ # # ]: 0 : if (!port_action) {
17892 : 0 : DRV_LOG(ERR, "Failed to find "
17893 : : "port action for policy.");
17894 : 0 : goto err_exit;
17895 : : }
17896 : 0 : acts[i].dv_actions[acts[i].actions_n] =
17897 : 0 : port_action->action;
17898 : 0 : acts[i].actions_n++;
17899 : : match_src_port = true;
17900 : 0 : break;
17901 : 0 : case MLX5_FLOW_FATE_DROP:
17902 : : case MLX5_FLOW_FATE_JUMP:
17903 : 0 : acts[i].dv_actions[acts[i].actions_n] =
17904 : 0 : mtr_policy->act_cnt[i].dr_jump_action[domain];
17905 : 0 : acts[i].actions_n++;
17906 : 0 : break;
17907 : 0 : case MLX5_FLOW_FATE_SHARED_RSS:
17908 : : case MLX5_FLOW_FATE_QUEUE:
17909 : 0 : hrxq = mlx5_ipool_get
17910 : 0 : (priv->sh->ipool[MLX5_IPOOL_HRXQ],
17911 : : sub_policy->rix_hrxq[i]);
17912 [ # # ]: 0 : if (!hrxq) {
17913 : 0 : DRV_LOG(ERR, "Failed to find "
17914 : : "queue action for policy.");
17915 : 0 : goto err_exit;
17916 : : }
17917 : 0 : acts[i].dv_actions[acts[i].actions_n] =
17918 : 0 : hrxq->action;
17919 : 0 : acts[i].actions_n++;
17920 : 0 : break;
17921 : 0 : case MLX5_FLOW_FATE_MTR:
17922 [ # # ]: 0 : if (!next_fm[i]) {
17923 : 0 : DRV_LOG(ERR,
17924 : : "No next hierarchy meter.");
17925 : 0 : goto err_exit;
17926 : : }
17927 [ # # ]: 0 : if (!mtr_first) {
17928 : 0 : acts[i].dv_actions[acts[i].actions_n] =
17929 [ # # ]: 0 : (next_fm[i]->color_aware && i == RTE_COLOR_YELLOW) ?
17930 [ # # ]: 0 : next_fm[i]->meter_action_y :
17931 : : next_fm[i]->meter_action_g;
17932 : 0 : acts[i].actions_n++;
17933 : : }
17934 [ # # ]: 0 : if (mtr_policy->act_cnt[i].next_sub_policy) {
17935 : : next_sub_policy =
17936 : : mtr_policy->act_cnt[i].next_sub_policy;
17937 : : } else {
17938 : : next_policy =
17939 : 0 : mlx5_flow_meter_policy_find(dev,
17940 : : next_fm[i]->policy_id, NULL);
17941 : : MLX5_ASSERT(next_policy);
17942 : 0 : next_sub_policy =
17943 : 0 : next_policy->sub_policys[domain][0];
17944 : : }
17945 : : tbl_data =
17946 : 0 : container_of(next_sub_policy->tbl_rsc,
17947 : : struct mlx5_flow_tbl_data_entry, tbl);
17948 : 0 : acts[i].dv_actions[acts[i].actions_n++] =
17949 : 0 : tbl_data->jump.action;
17950 [ # # ]: 0 : if (mtr_policy->act_cnt[i].modify_hdr)
17951 : : match_src_port = !!transfer;
17952 : : break;
17953 : : default:
17954 : : /*Queue action do nothing*/
17955 : : break;
17956 : : }
17957 : : }
17958 : : }
17959 [ # # ]: 0 : if (__flow_dv_create_domain_policy_rules(dev, sub_policy,
17960 : : egress, transfer, match_src_port, acts)) {
17961 : 0 : DRV_LOG(ERR,
17962 : : "Failed to create policy rules per domain.");
17963 : 0 : goto err_exit;
17964 : : }
17965 [ # # ]: 0 : if (match_src_port) {
17966 : 0 : mtr_policy->match_port = match_src_port;
17967 : 0 : mtr_policy->hierarchy_match_port = match_src_port;
17968 : : }
17969 : : return 0;
17970 : : err_exit:
17971 [ # # ]: 0 : for (i = 0; i < RTE_COLORS; i++)
17972 [ # # ]: 0 : if (next_fm[i])
17973 : 0 : mlx5_flow_meter_detach(priv, next_fm[i]);
17974 : : return -1;
17975 : : }
17976 : :
17977 : : /**
17978 : : * Create the policy rules.
17979 : : *
17980 : : * @param[in] dev
17981 : : * Pointer to Ethernet device.
17982 : : * @param[in,out] mtr_policy
17983 : : * Pointer to meter policy table.
17984 : : *
17985 : : * @return
17986 : : * 0 on success, -1 otherwise.
17987 : : */
17988 : : static int
17989 : 0 : flow_dv_create_policy_rules(struct rte_eth_dev *dev,
17990 : : struct mlx5_flow_meter_policy *mtr_policy)
17991 : : {
17992 : : int i;
17993 : : int ret = 0;
17994 : : uint16_t sub_policy_num;
17995 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_push_thread_workspace();
17996 : :
17997 : : RTE_SET_USED(wks);
17998 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
17999 : 0 : sub_policy_num = (mtr_policy->sub_policy_num >>
18000 : 0 : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i)) &
18001 : : MLX5_MTR_SUB_POLICY_NUM_MASK;
18002 [ # # ]: 0 : if (!sub_policy_num)
18003 : 0 : continue;
18004 : : /* Prepare actions list and create policy rules. */
18005 [ # # ]: 0 : if (__flow_dv_create_policy_acts_rules(dev, mtr_policy,
18006 : 0 : mtr_policy->sub_policys[i][0], i)) {
18007 : 0 : DRV_LOG(ERR, "Failed to create policy action "
18008 : : "list per domain.");
18009 : : ret = -1;
18010 : 0 : goto exit;
18011 : : }
18012 : : }
18013 : 0 : exit:
18014 : 0 : mlx5_flow_pop_thread_workspace();
18015 : 0 : return ret;
18016 : : }
18017 : :
18018 : : static int
18019 : 0 : __flow_dv_create_domain_def_policy(struct rte_eth_dev *dev, uint32_t domain)
18020 : : {
18021 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18022 : 0 : struct mlx5_flow_mtr_mng *mtrmng = priv->sh->mtrmng;
18023 : : struct mlx5_flow_meter_def_policy *def_policy;
18024 : : struct mlx5_flow_tbl_resource *jump_tbl;
18025 : : struct mlx5_flow_tbl_data_entry *tbl_data;
18026 : : uint8_t egress, transfer;
18027 : : struct rte_flow_error error;
18028 : : struct mlx5_meter_policy_acts acts[RTE_COLORS];
18029 : : int ret;
18030 : :
18031 : 0 : egress = (domain == MLX5_MTR_DOMAIN_EGRESS) ? 1 : 0;
18032 : 0 : transfer = (domain == MLX5_MTR_DOMAIN_TRANSFER) ? 1 : 0;
18033 : 0 : def_policy = mtrmng->def_policy[domain];
18034 [ # # ]: 0 : if (!def_policy) {
18035 : 0 : def_policy = mlx5_malloc(MLX5_MEM_ZERO,
18036 : : sizeof(struct mlx5_flow_meter_def_policy),
18037 : : RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY);
18038 [ # # ]: 0 : if (!def_policy) {
18039 : 0 : DRV_LOG(ERR, "Failed to alloc default policy table.");
18040 : 0 : goto def_policy_error;
18041 : : }
18042 : 0 : mtrmng->def_policy[domain] = def_policy;
18043 : : /* Create the meter suffix table with SUFFIX level. */
18044 : 0 : jump_tbl = flow_dv_tbl_resource_get(dev,
18045 : : MLX5_FLOW_TABLE_LEVEL_METER,
18046 : : egress, transfer, false, NULL, 0,
18047 : : 0, MLX5_MTR_TABLE_ID_SUFFIX, &error);
18048 [ # # ]: 0 : if (!jump_tbl) {
18049 : 0 : DRV_LOG(ERR,
18050 : : "Failed to create meter suffix table.");
18051 : 0 : goto def_policy_error;
18052 : : }
18053 : 0 : def_policy->sub_policy.jump_tbl[RTE_COLOR_GREEN] = jump_tbl;
18054 : 0 : tbl_data = container_of(jump_tbl,
18055 : : struct mlx5_flow_tbl_data_entry, tbl);
18056 : 0 : def_policy->dr_jump_action[RTE_COLOR_GREEN] =
18057 : 0 : tbl_data->jump.action;
18058 : 0 : acts[RTE_COLOR_GREEN].dv_actions[0] = tbl_data->jump.action;
18059 : 0 : acts[RTE_COLOR_GREEN].actions_n = 1;
18060 : : /*
18061 : : * YELLOW has the same default policy as GREEN does.
18062 : : * G & Y share the same table and action. The 2nd time of table
18063 : : * resource getting is just to update the reference count for
18064 : : * the releasing stage.
18065 : : */
18066 : 0 : jump_tbl = flow_dv_tbl_resource_get(dev,
18067 : : MLX5_FLOW_TABLE_LEVEL_METER,
18068 : : egress, transfer, false, NULL, 0,
18069 : : 0, MLX5_MTR_TABLE_ID_SUFFIX, &error);
18070 [ # # ]: 0 : if (!jump_tbl) {
18071 : 0 : DRV_LOG(ERR,
18072 : : "Failed to get meter suffix table.");
18073 : 0 : goto def_policy_error;
18074 : : }
18075 : 0 : def_policy->sub_policy.jump_tbl[RTE_COLOR_YELLOW] = jump_tbl;
18076 : 0 : tbl_data = container_of(jump_tbl,
18077 : : struct mlx5_flow_tbl_data_entry, tbl);
18078 : 0 : def_policy->dr_jump_action[RTE_COLOR_YELLOW] =
18079 : 0 : tbl_data->jump.action;
18080 : 0 : acts[RTE_COLOR_YELLOW].dv_actions[0] = tbl_data->jump.action;
18081 : 0 : acts[RTE_COLOR_YELLOW].actions_n = 1;
18082 : : /* Create jump action to the drop table. */
18083 [ # # ]: 0 : if (!mtrmng->drop_tbl[domain]) {
18084 : 0 : mtrmng->drop_tbl[domain] = flow_dv_tbl_resource_get
18085 : : (dev, MLX5_FLOW_TABLE_LEVEL_METER,
18086 : : egress, transfer, false, NULL, 0,
18087 : : 0, MLX5_MTR_TABLE_ID_DROP, &error);
18088 [ # # ]: 0 : if (!mtrmng->drop_tbl[domain]) {
18089 : 0 : DRV_LOG(ERR, "Failed to create meter "
18090 : : "drop table for default policy.");
18091 : 0 : goto def_policy_error;
18092 : : }
18093 : : }
18094 : : /* all RED: unique Drop table for jump action. */
18095 : 0 : tbl_data = container_of(mtrmng->drop_tbl[domain],
18096 : : struct mlx5_flow_tbl_data_entry, tbl);
18097 : 0 : def_policy->dr_jump_action[RTE_COLOR_RED] =
18098 : 0 : tbl_data->jump.action;
18099 : 0 : acts[RTE_COLOR_RED].dv_actions[0] = tbl_data->jump.action;
18100 : 0 : acts[RTE_COLOR_RED].actions_n = 1;
18101 : : /* Create default policy rules. */
18102 : 0 : ret = __flow_dv_create_domain_policy_rules(dev,
18103 : : &def_policy->sub_policy,
18104 : : egress, transfer, false, acts);
18105 [ # # ]: 0 : if (ret) {
18106 : 0 : DRV_LOG(ERR, "Failed to create default policy rules.");
18107 : 0 : goto def_policy_error;
18108 : : }
18109 : : }
18110 : : return 0;
18111 : 0 : def_policy_error:
18112 : 0 : __flow_dv_destroy_domain_def_policy(dev,
18113 : : (enum mlx5_meter_domain)domain);
18114 : 0 : return -1;
18115 : : }
18116 : :
18117 : : /**
18118 : : * Create the default policy table set.
18119 : : *
18120 : : * @param[in] dev
18121 : : * Pointer to Ethernet device.
18122 : : * @return
18123 : : * 0 on success, -1 otherwise.
18124 : : */
18125 : : static int
18126 : 0 : flow_dv_create_def_policy(struct rte_eth_dev *dev)
18127 : : {
18128 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18129 : : int i;
18130 : :
18131 : : /* Non-termination policy table. */
18132 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
18133 [ # # # # ]: 0 : if (!priv->sh->config.dv_esw_en &&
18134 : : i == MLX5_MTR_DOMAIN_TRANSFER)
18135 : 0 : continue;
18136 [ # # ]: 0 : if (__flow_dv_create_domain_def_policy(dev, i)) {
18137 : 0 : DRV_LOG(ERR, "Failed to create default policy");
18138 : : /* Rollback the created default policies for others. */
18139 : 0 : flow_dv_destroy_def_policy(dev);
18140 : 0 : return -1;
18141 : : }
18142 : : }
18143 : : return 0;
18144 : : }
18145 : :
18146 : : /**
18147 : : * Create the needed meter tables.
18148 : : * Lock free, (mutex should be acquired by caller).
18149 : : *
18150 : : * @param[in] dev
18151 : : * Pointer to Ethernet device.
18152 : : * @param[in] fm
18153 : : * Meter information table.
18154 : : * @param[in] mtr_idx
18155 : : * Meter index.
18156 : : * @param[in] domain_bitmap
18157 : : * Domain bitmap.
18158 : : * @return
18159 : : * 0 on success, -1 otherwise.
18160 : : */
18161 : : static int
18162 : 0 : flow_dv_create_mtr_tbls(struct rte_eth_dev *dev,
18163 : : struct mlx5_flow_meter_info *fm,
18164 : : uint32_t mtr_idx,
18165 : : uint8_t domain_bitmap)
18166 : : {
18167 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18168 : 0 : struct mlx5_flow_mtr_mng *mtrmng = priv->sh->mtrmng;
18169 : : struct rte_flow_error error;
18170 : : struct mlx5_flow_tbl_data_entry *tbl_data;
18171 : : uint8_t egress, transfer;
18172 : : void *actions[METER_ACTIONS];
18173 : : int domain, ret, i;
18174 : : struct mlx5_flow_counter *cnt;
18175 : 0 : struct mlx5_flow_dv_match_params value = {
18176 : : .size = sizeof(value.buf),
18177 : : };
18178 : 0 : struct mlx5_flow_dv_match_params matcher_para = {
18179 : : .size = sizeof(matcher_para.buf),
18180 : : };
18181 : 0 : int mtr_id_reg_c = mlx5_flow_get_reg_id(dev, MLX5_MTR_ID,
18182 : : 0, &error);
18183 : 0 : uint32_t mtr_id_mask = (UINT32_C(1) << mtrmng->max_mtr_bits) - 1;
18184 : 0 : uint8_t mtr_id_offset = priv->mtr_reg_share ? MLX5_MTR_COLOR_BITS : 0;
18185 : : struct mlx5_list_entry *entry;
18186 : 0 : struct mlx5_flow_dv_matcher matcher = {
18187 : : .mask = {
18188 : : .size = sizeof(matcher.mask.buf),
18189 : : },
18190 : : };
18191 : : struct mlx5_flow_dv_matcher *drop_matcher;
18192 : 0 : struct mlx5_flow_cb_ctx ctx = {
18193 : : .error = &error,
18194 : : .data = &matcher,
18195 : : };
18196 : : uint8_t misc_mask;
18197 : :
18198 [ # # # # ]: 0 : if (!priv->mtr_en || mtr_id_reg_c < 0) {
18199 : 0 : rte_errno = ENOTSUP;
18200 : 0 : return -1;
18201 : : }
18202 [ # # ]: 0 : for (domain = 0; domain < MLX5_MTR_DOMAIN_MAX; domain++) {
18203 [ # # ]: 0 : if (!(domain_bitmap & (1 << domain)) ||
18204 [ # # # # ]: 0 : (mtrmng->def_rule[domain] && !fm->drop_cnt))
18205 : 0 : continue;
18206 : 0 : egress = (domain == MLX5_MTR_DOMAIN_EGRESS) ? 1 : 0;
18207 : 0 : transfer = (domain == MLX5_MTR_DOMAIN_TRANSFER) ? 1 : 0;
18208 : : /* Create the drop table with METER DROP level. */
18209 [ # # ]: 0 : if (!mtrmng->drop_tbl[domain]) {
18210 : 0 : mtrmng->drop_tbl[domain] = flow_dv_tbl_resource_get(dev,
18211 : : MLX5_FLOW_TABLE_LEVEL_METER,
18212 : : egress, transfer, false, NULL, 0,
18213 : : 0, MLX5_MTR_TABLE_ID_DROP, &error);
18214 [ # # ]: 0 : if (!mtrmng->drop_tbl[domain]) {
18215 : 0 : DRV_LOG(ERR, "Failed to create meter drop table.");
18216 : 0 : goto policy_error;
18217 : : }
18218 : : }
18219 : : /* Create default matcher in drop table. */
18220 : 0 : matcher.tbl = mtrmng->drop_tbl[domain],
18221 : 0 : tbl_data = container_of(mtrmng->drop_tbl[domain],
18222 : : struct mlx5_flow_tbl_data_entry, tbl);
18223 [ # # ]: 0 : if (!mtrmng->def_matcher[domain]) {
18224 : 0 : flow_dv_match_meta_reg_all(matcher.mask.buf, value.buf,
18225 : : (enum modify_reg)mtr_id_reg_c,
18226 : : 0, 0);
18227 : 0 : matcher.priority = MLX5_MTRS_DEFAULT_RULE_PRIORITY;
18228 : 0 : matcher.crc = rte_raw_cksum
18229 : : ((const void *)matcher.mask.buf,
18230 : : matcher.mask.size);
18231 : 0 : entry = mlx5_list_register(tbl_data->matchers, &ctx);
18232 [ # # ]: 0 : if (!entry) {
18233 : 0 : DRV_LOG(ERR, "Failed to register meter "
18234 : : "drop default matcher.");
18235 : 0 : goto policy_error;
18236 : : }
18237 : 0 : mtrmng->def_matcher[domain] = container_of(entry,
18238 : : struct mlx5_flow_dv_matcher, entry);
18239 : : }
18240 : : /* Create default rule in drop table. */
18241 [ # # ]: 0 : if (!mtrmng->def_rule[domain]) {
18242 : : i = 0;
18243 : 0 : actions[i++] = priv->sh->dr_drop_action;
18244 : 0 : flow_dv_match_meta_reg_all(matcher_para.buf, value.buf,
18245 : : (enum modify_reg)mtr_id_reg_c, 0, 0);
18246 [ # # ]: 0 : misc_mask = flow_dv_matcher_enable(mtrmng->def_matcher[domain]->mask.buf);
18247 : : __flow_dv_adjust_buf_size(&value.size, misc_mask);
18248 : 0 : ret = mlx5_flow_os_create_flow
18249 : : (mtrmng->def_matcher[domain]->matcher_object,
18250 : : (void *)&value, i, actions,
18251 : : &mtrmng->def_rule[domain]);
18252 : : if (ret) {
18253 : 0 : DRV_LOG(ERR, "Failed to create meter "
18254 : : "default drop rule for drop table.");
18255 : 0 : goto policy_error;
18256 : : }
18257 : : }
18258 [ # # ]: 0 : if (!fm->drop_cnt)
18259 : 0 : continue;
18260 : : MLX5_ASSERT(mtrmng->max_mtr_bits);
18261 [ # # ]: 0 : if (!mtrmng->drop_matcher[domain][mtrmng->max_mtr_bits - 1]) {
18262 : : /* Create matchers for Drop. */
18263 : 0 : flow_dv_match_meta_reg_all(matcher.mask.buf, value.buf,
18264 : : (enum modify_reg)mtr_id_reg_c, 0,
18265 : : (mtr_id_mask << mtr_id_offset));
18266 : 0 : matcher.priority = MLX5_REG_BITS - mtrmng->max_mtr_bits;
18267 : 0 : matcher.crc = rte_raw_cksum
18268 : : ((const void *)matcher.mask.buf,
18269 : : matcher.mask.size);
18270 : 0 : entry = mlx5_list_register(tbl_data->matchers, &ctx);
18271 [ # # ]: 0 : if (!entry) {
18272 : 0 : DRV_LOG(ERR,
18273 : : "Failed to register meter drop matcher.");
18274 : 0 : goto policy_error;
18275 : : }
18276 : 0 : mtrmng->drop_matcher[domain][mtrmng->max_mtr_bits - 1] =
18277 : : container_of(entry, struct mlx5_flow_dv_matcher,
18278 : : entry);
18279 : : }
18280 : 0 : drop_matcher =
18281 : 0 : mtrmng->drop_matcher[domain][mtrmng->max_mtr_bits - 1];
18282 : : /* Create drop rule, matching meter_id only. */
18283 : 0 : flow_dv_match_meta_reg_all(matcher_para.buf, value.buf,
18284 : : (enum modify_reg)mtr_id_reg_c,
18285 : : (mtr_idx << mtr_id_offset), UINT32_MAX);
18286 : : i = 0;
18287 [ # # ]: 0 : cnt = flow_dv_counter_get_by_idx(dev,
18288 : : fm->drop_cnt, NULL);
18289 : 0 : actions[i++] = cnt->action;
18290 : 0 : actions[i++] = priv->sh->dr_drop_action;
18291 [ # # ]: 0 : misc_mask = flow_dv_matcher_enable(drop_matcher->mask.buf);
18292 : : __flow_dv_adjust_buf_size(&value.size, misc_mask);
18293 : 0 : ret = mlx5_flow_os_create_flow(drop_matcher->matcher_object,
18294 : : (void *)&value, i, actions,
18295 : : &fm->drop_rule[domain]);
18296 : : if (ret) {
18297 : 0 : DRV_LOG(ERR, "Failed to create meter "
18298 : : "drop rule for drop table.");
18299 : 0 : goto policy_error;
18300 : : }
18301 : : }
18302 : : return 0;
18303 : : policy_error:
18304 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
18305 [ # # ]: 0 : if (fm->drop_rule[i]) {
18306 : : claim_zero(mlx5_flow_os_destroy_flow
18307 : : (fm->drop_rule[i]));
18308 : 0 : fm->drop_rule[i] = NULL;
18309 : : }
18310 : : }
18311 : : return -1;
18312 : : }
18313 : :
18314 : : static struct mlx5_flow_meter_sub_policy *
18315 : 0 : __flow_dv_meter_get_rss_sub_policy(struct rte_eth_dev *dev,
18316 : : struct mlx5_flow_meter_policy *mtr_policy,
18317 : : struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS],
18318 : : struct mlx5_flow_meter_sub_policy *next_sub_policy,
18319 : : bool *is_reuse)
18320 : : {
18321 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18322 : : struct mlx5_flow_meter_sub_policy *sub_policy = NULL;
18323 : 0 : uint32_t sub_policy_idx = 0;
18324 : 0 : uint32_t hrxq_idx[MLX5_MTR_RTE_COLORS] = {0};
18325 : : uint32_t i, j;
18326 : : struct mlx5_hrxq *hrxq;
18327 : : struct mlx5_flow_handle dh;
18328 : : struct mlx5_meter_policy_action_container *act_cnt;
18329 : : uint32_t domain = MLX5_MTR_DOMAIN_INGRESS;
18330 : : uint16_t sub_policy_num;
18331 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
18332 : :
18333 : : MLX5_ASSERT(wks);
18334 : 0 : rte_spinlock_lock(&mtr_policy->sl);
18335 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
18336 [ # # ]: 0 : if (!rss_desc[i])
18337 : 0 : continue;
18338 : 0 : hrxq = mlx5_hrxq_get(dev, rss_desc[i]);
18339 [ # # ]: 0 : if (!hrxq) {
18340 : : rte_spinlock_unlock(&mtr_policy->sl);
18341 : 0 : return NULL;
18342 : : }
18343 : 0 : hrxq_idx[i] = hrxq->idx;
18344 : : }
18345 : 0 : sub_policy_num = (mtr_policy->sub_policy_num >>
18346 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
18347 : : MLX5_MTR_SUB_POLICY_NUM_MASK;
18348 [ # # ]: 0 : for (j = 0; j < sub_policy_num; j++) {
18349 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
18350 [ # # ]: 0 : if (rss_desc[i] &&
18351 : 0 : hrxq_idx[i] !=
18352 [ # # ]: 0 : mtr_policy->sub_policys[domain][j]->rix_hrxq[i])
18353 : : break;
18354 : : }
18355 [ # # ]: 0 : if (i >= MLX5_MTR_RTE_COLORS) {
18356 : : /*
18357 : : * Found the sub policy table with
18358 : : * the same queue per color.
18359 : : */
18360 : : rte_spinlock_unlock(&mtr_policy->sl);
18361 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++)
18362 : 0 : mlx5_hrxq_release(dev, hrxq_idx[i]);
18363 : 0 : *is_reuse = true;
18364 : 0 : return mtr_policy->sub_policys[domain][j];
18365 : : }
18366 : : }
18367 : : /* Create sub policy. */
18368 [ # # ]: 0 : if (!mtr_policy->sub_policys[domain][0]->rix_hrxq[RTE_COLOR_GREEN] &&
18369 : : !mtr_policy->sub_policys[domain][0]->rix_hrxq[RTE_COLOR_YELLOW]) {
18370 : : /* Reuse the first pre-allocated sub_policy. */
18371 : : sub_policy = mtr_policy->sub_policys[domain][0];
18372 : 0 : sub_policy_idx = sub_policy->idx;
18373 : : } else {
18374 : 0 : sub_policy = mlx5_ipool_zmalloc
18375 : 0 : (priv->sh->ipool[MLX5_IPOOL_MTR_POLICY],
18376 : : &sub_policy_idx);
18377 [ # # ]: 0 : if (!sub_policy ||
18378 [ # # ]: 0 : sub_policy_idx > MLX5_MAX_SUB_POLICY_TBL_NUM) {
18379 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++)
18380 : 0 : mlx5_hrxq_release(dev, hrxq_idx[i]);
18381 : 0 : goto rss_sub_policy_error;
18382 : : }
18383 : 0 : sub_policy->idx = sub_policy_idx;
18384 : 0 : sub_policy->main_policy = mtr_policy;
18385 : : }
18386 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
18387 [ # # ]: 0 : if (!rss_desc[i])
18388 : 0 : continue;
18389 : 0 : sub_policy->rix_hrxq[i] = hrxq_idx[i];
18390 [ # # ]: 0 : if (mtr_policy->is_hierarchy) {
18391 : : act_cnt = &mtr_policy->act_cnt[i];
18392 : 0 : act_cnt->next_sub_policy = next_sub_policy;
18393 : 0 : mlx5_hrxq_release(dev, hrxq_idx[i]);
18394 : : } else {
18395 : : /*
18396 : : * Overwrite the last action from
18397 : : * RSS action to Queue action.
18398 : : */
18399 : 0 : hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
18400 : : hrxq_idx[i]);
18401 [ # # ]: 0 : if (!hrxq) {
18402 : 0 : DRV_LOG(ERR, "Failed to get policy hrxq");
18403 : 0 : goto rss_sub_policy_error;
18404 : : }
18405 : : act_cnt = &mtr_policy->act_cnt[i];
18406 [ # # # # ]: 0 : if (act_cnt->rix_mark || act_cnt->modify_hdr) {
18407 : : memset(&dh, 0, sizeof(struct mlx5_flow_handle));
18408 [ # # ]: 0 : if (act_cnt->rix_mark)
18409 : 0 : wks->mark = 1;
18410 : 0 : dh.fate_action = MLX5_FLOW_FATE_QUEUE;
18411 : 0 : dh.rix_hrxq = hrxq_idx[i];
18412 : 0 : flow_drv_rxq_flags_set(dev, &dh);
18413 : : }
18414 : : }
18415 : : }
18416 [ # # ]: 0 : if (__flow_dv_create_policy_acts_rules(dev, mtr_policy,
18417 : : sub_policy, domain)) {
18418 : 0 : DRV_LOG(ERR, "Failed to create policy "
18419 : : "rules for ingress domain.");
18420 : 0 : goto rss_sub_policy_error;
18421 : : }
18422 [ # # ]: 0 : if (sub_policy != mtr_policy->sub_policys[domain][0]) {
18423 : 0 : i = (mtr_policy->sub_policy_num >>
18424 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
18425 : : MLX5_MTR_SUB_POLICY_NUM_MASK;
18426 [ # # ]: 0 : if (i >= MLX5_MTR_RSS_MAX_SUB_POLICY) {
18427 : 0 : DRV_LOG(ERR, "No free sub-policy slot.");
18428 : 0 : goto rss_sub_policy_error;
18429 : : }
18430 : 0 : mtr_policy->sub_policys[domain][i] = sub_policy;
18431 : 0 : i++;
18432 : 0 : mtr_policy->sub_policy_num &= ~(MLX5_MTR_SUB_POLICY_NUM_MASK <<
18433 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain));
18434 : 0 : mtr_policy->sub_policy_num |=
18435 : 0 : (i & MLX5_MTR_SUB_POLICY_NUM_MASK) <<
18436 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain);
18437 : : }
18438 : : rte_spinlock_unlock(&mtr_policy->sl);
18439 : 0 : *is_reuse = false;
18440 : 0 : return sub_policy;
18441 : 0 : rss_sub_policy_error:
18442 [ # # ]: 0 : if (sub_policy) {
18443 : 0 : __flow_dv_destroy_sub_policy_rules(dev, sub_policy);
18444 [ # # ]: 0 : if (sub_policy != mtr_policy->sub_policys[domain][0]) {
18445 : 0 : i = (mtr_policy->sub_policy_num >>
18446 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
18447 : : MLX5_MTR_SUB_POLICY_NUM_MASK;
18448 : 0 : mtr_policy->sub_policys[domain][i] = NULL;
18449 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MTR_POLICY],
18450 : 0 : sub_policy->idx);
18451 : : }
18452 : : }
18453 : : rte_spinlock_unlock(&mtr_policy->sl);
18454 : 0 : return NULL;
18455 : : }
18456 : :
18457 : : /**
18458 : : * Find the policy table for prefix table with RSS.
18459 : : *
18460 : : * @param[in] dev
18461 : : * Pointer to Ethernet device.
18462 : : * @param[in] mtr_policy
18463 : : * Pointer to meter policy table.
18464 : : * @param[in] rss_desc
18465 : : * Pointer to rss_desc
18466 : : * @return
18467 : : * Pointer to table set on success, NULL otherwise and rte_errno is set.
18468 : : */
18469 : : static struct mlx5_flow_meter_sub_policy *
18470 : 0 : flow_dv_meter_sub_policy_rss_prepare(struct rte_eth_dev *dev,
18471 : : struct mlx5_flow_meter_policy *mtr_policy,
18472 : : struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS])
18473 : : {
18474 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18475 : : struct mlx5_flow_meter_sub_policy *sub_policy = NULL;
18476 : : struct mlx5_flow_meter_info *next_fm;
18477 : : struct mlx5_flow_meter_policy *next_policy;
18478 : : struct mlx5_flow_meter_sub_policy *next_sub_policy = NULL;
18479 : : struct mlx5_flow_meter_policy *policies[MLX5_MTR_CHAIN_MAX_NUM];
18480 : : struct mlx5_flow_meter_sub_policy *sub_policies[MLX5_MTR_CHAIN_MAX_NUM];
18481 : : uint32_t domain = MLX5_MTR_DOMAIN_INGRESS;
18482 : : bool reuse_sub_policy;
18483 : : uint32_t i = 0;
18484 : : uint32_t j = 0;
18485 : :
18486 : : while (true) {
18487 : : /* Iterate hierarchy to get all policies in this hierarchy. */
18488 : 0 : policies[i++] = mtr_policy;
18489 [ # # ]: 0 : if (!mtr_policy->is_hierarchy)
18490 : : break;
18491 [ # # ]: 0 : if (i >= MLX5_MTR_CHAIN_MAX_NUM) {
18492 : 0 : DRV_LOG(ERR, "Exceed max meter number in hierarchy.");
18493 : 0 : return NULL;
18494 : : }
18495 : 0 : rte_spinlock_lock(&mtr_policy->sl);
18496 : 0 : next_fm = mlx5_flow_meter_hierarchy_next_meter(priv, mtr_policy, NULL);
18497 : : rte_spinlock_unlock(&mtr_policy->sl);
18498 [ # # ]: 0 : if (!next_fm) {
18499 : 0 : DRV_LOG(ERR, "Failed to get next meter in hierarchy.");
18500 : 0 : return NULL;
18501 : : }
18502 : : next_policy =
18503 : 0 : mlx5_flow_meter_policy_find(dev, next_fm->policy_id,
18504 : : NULL);
18505 : : MLX5_ASSERT(next_policy);
18506 : : mtr_policy = next_policy;
18507 : : }
18508 [ # # ]: 0 : while (i) {
18509 : : /**
18510 : : * From last policy to the first one in hierarchy,
18511 : : * create / get the sub policy for each of them.
18512 : : */
18513 : 0 : sub_policy = __flow_dv_meter_get_rss_sub_policy(dev,
18514 : : policies[--i],
18515 : : rss_desc,
18516 : : next_sub_policy,
18517 : : &reuse_sub_policy);
18518 [ # # ]: 0 : if (!sub_policy) {
18519 : 0 : DRV_LOG(ERR, "Failed to get the sub policy.");
18520 : 0 : goto err_exit;
18521 : : }
18522 [ # # ]: 0 : if (!reuse_sub_policy)
18523 : 0 : sub_policies[j++] = sub_policy;
18524 : : next_sub_policy = sub_policy;
18525 : : }
18526 : : return sub_policy;
18527 : : err_exit:
18528 [ # # ]: 0 : while (j) {
18529 : : uint16_t sub_policy_num;
18530 : :
18531 : 0 : sub_policy = sub_policies[--j];
18532 : 0 : mtr_policy = sub_policy->main_policy;
18533 : 0 : __flow_dv_destroy_sub_policy_rules(dev, sub_policy);
18534 [ # # ]: 0 : if (sub_policy != mtr_policy->sub_policys[domain][0]) {
18535 : 0 : sub_policy_num = (mtr_policy->sub_policy_num >>
18536 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
18537 : : MLX5_MTR_SUB_POLICY_NUM_MASK;
18538 : 0 : mtr_policy->sub_policys[domain][sub_policy_num - 1] =
18539 : : NULL;
18540 : 0 : sub_policy_num--;
18541 : 0 : mtr_policy->sub_policy_num &=
18542 : 0 : ~(MLX5_MTR_SUB_POLICY_NUM_MASK <<
18543 : 0 : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i));
18544 : 0 : mtr_policy->sub_policy_num |=
18545 : 0 : (sub_policy_num & MLX5_MTR_SUB_POLICY_NUM_MASK) <<
18546 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i);
18547 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MTR_POLICY],
18548 : 0 : sub_policy->idx);
18549 : : }
18550 : : }
18551 : : return NULL;
18552 : : }
18553 : :
18554 : : /**
18555 : : * Check if need to create hierarchy tag rule.
18556 : : *
18557 : : * @param[in] priv
18558 : : * Pointer to mlx5_priv.
18559 : : * @param[in] mtr_policy
18560 : : * Pointer to current meter policy.
18561 : : * @param[in] src_port
18562 : : * The src port this extra rule should use.
18563 : : * @param[out] next_fm
18564 : : * Pointer to next meter in hierarchy.
18565 : : * @param[out] skip
18566 : : * Indicate if skip the tag rule creation.
18567 : : * @param[out] error
18568 : : * Perform verbose error reporting if not NULL.
18569 : : * @return
18570 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
18571 : : */
18572 : : static int
18573 : 0 : mlx5_meter_hierarchy_skip_tag_rule(struct mlx5_priv *priv,
18574 : : struct mlx5_flow_meter_policy *mtr_policy,
18575 : : int32_t src_port,
18576 : : struct mlx5_flow_meter_info **next_fm,
18577 : : bool *skip,
18578 : : struct rte_flow_error *error)
18579 : : {
18580 : : struct mlx5_flow_meter_sub_policy *sub_policy;
18581 : : struct mlx5_sub_policy_color_rule *color_rule;
18582 : : uint32_t domain = MLX5_MTR_DOMAIN_TRANSFER;
18583 : : int ret = 0;
18584 : : int i;
18585 : :
18586 : 0 : *next_fm = NULL;
18587 : 0 : *skip = false;
18588 : 0 : rte_spinlock_lock(&mtr_policy->sl);
18589 [ # # ]: 0 : if (mtr_policy->is_hierarchy) {
18590 : 0 : *next_fm = mlx5_flow_meter_hierarchy_next_meter(priv, mtr_policy, NULL);
18591 [ # # ]: 0 : if (!*next_fm) {
18592 : 0 : ret = rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
18593 : : NULL, "Failed to find next meter in hierarchy.");
18594 : 0 : goto exit;
18595 : : }
18596 : : }
18597 [ # # ]: 0 : if (!mtr_policy->match_port) {
18598 : 0 : *skip = true;
18599 : 0 : goto exit;
18600 : : }
18601 : 0 : sub_policy = mtr_policy->sub_policys[domain][0];
18602 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
18603 [ # # ]: 0 : if (mtr_policy->act_cnt[i].fate_action != MLX5_FLOW_FATE_MTR &&
18604 : : mtr_policy->act_cnt[i].fate_action != MLX5_FLOW_FATE_PORT_ID)
18605 : 0 : continue;
18606 [ # # ]: 0 : TAILQ_FOREACH(color_rule, &sub_policy->color_rules[i], next_port)
18607 [ # # ]: 0 : if (color_rule->src_port == src_port) {
18608 : 0 : *skip = true;
18609 : 0 : goto exit;
18610 : : }
18611 : : }
18612 : 0 : exit:
18613 : : rte_spinlock_unlock(&mtr_policy->sl);
18614 : 0 : return ret;
18615 : : }
18616 : :
18617 : : /**
18618 : : * Create the sub policy tag rule for all meters in hierarchy.
18619 : : *
18620 : : * @param[in] dev
18621 : : * Pointer to Ethernet device.
18622 : : * @param[in] fm
18623 : : * Meter information table.
18624 : : * @param[in] src_port
18625 : : * The src port this extra rule should use.
18626 : : * @param[in] item
18627 : : * The src port match item.
18628 : : * @param[out] error
18629 : : * Perform verbose error reporting if not NULL.
18630 : : * @return
18631 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
18632 : : */
18633 : : static int
18634 : 0 : flow_dv_meter_hierarchy_rule_create(struct rte_eth_dev *dev,
18635 : : struct mlx5_flow_meter_info *fm,
18636 : : int32_t src_port,
18637 : : const struct rte_flow_item *item,
18638 : : struct rte_flow_error *error)
18639 : : {
18640 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18641 : : struct mlx5_flow_meter_policy *mtr_policy;
18642 : : struct mlx5_flow_meter_sub_policy *sub_policy;
18643 : 0 : struct mlx5_flow_meter_info *next_fm = NULL;
18644 : : struct mlx5_flow_meter_policy *next_policy;
18645 : : struct mlx5_flow_meter_sub_policy *next_sub_policy;
18646 : : struct mlx5_flow_tbl_data_entry *tbl_data;
18647 : : struct mlx5_sub_policy_color_rule *color_rule;
18648 : : struct mlx5_meter_policy_acts acts;
18649 : : uint32_t color_reg_c_idx;
18650 : : bool mtr_first = (src_port != UINT16_MAX) ? true : false;
18651 : 0 : struct rte_flow_attr attr = {
18652 : : .group = MLX5_FLOW_TABLE_LEVEL_POLICY,
18653 : : .priority = 0,
18654 : : .ingress = 0,
18655 : : .egress = 0,
18656 : : .transfer = 1,
18657 : : .reserved = 0,
18658 : : };
18659 : : uint32_t domain = MLX5_MTR_DOMAIN_TRANSFER;
18660 : : struct {
18661 : : struct mlx5_flow_meter_policy *fm_policy;
18662 : : struct mlx5_flow_meter_info *next_fm;
18663 : : struct mlx5_sub_policy_color_rule *tag_rule[MLX5_MTR_RTE_COLORS];
18664 : 0 : } fm_info[MLX5_MTR_CHAIN_MAX_NUM] = { {0} };
18665 : : uint32_t fm_cnt = 0;
18666 : : uint32_t i, j;
18667 : :
18668 : 0 : color_reg_c_idx = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, error);
18669 : : /* Get all fms who need to create the tag color rule. */
18670 : : do {
18671 : 0 : bool skip = false;
18672 : :
18673 : 0 : mtr_policy = mlx5_flow_meter_policy_find(dev, fm->policy_id, NULL);
18674 : : MLX5_ASSERT(mtr_policy);
18675 [ # # ]: 0 : if (mlx5_meter_hierarchy_skip_tag_rule(priv, mtr_policy, src_port,
18676 : : &next_fm, &skip, error))
18677 : 0 : goto err_exit;
18678 [ # # ]: 0 : if (!skip) {
18679 : 0 : fm_info[fm_cnt].fm_policy = mtr_policy;
18680 : 0 : fm_info[fm_cnt].next_fm = next_fm;
18681 [ # # ]: 0 : if (++fm_cnt >= MLX5_MTR_CHAIN_MAX_NUM) {
18682 : 0 : rte_flow_error_set(error, errno,
18683 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
18684 : : "Exceed max meter number in hierarchy.");
18685 : 0 : goto err_exit;
18686 : : }
18687 : : }
18688 : 0 : fm = next_fm;
18689 [ # # ]: 0 : } while (fm);
18690 : : /* Create tag color rules for all needed fms. */
18691 [ # # ]: 0 : for (i = 0; i < fm_cnt; i++) {
18692 : : void *mtr_action;
18693 : :
18694 : 0 : mtr_policy = fm_info[i].fm_policy;
18695 : 0 : rte_spinlock_lock(&mtr_policy->sl);
18696 : 0 : sub_policy = mtr_policy->sub_policys[domain][0];
18697 [ # # ]: 0 : for (j = 0; j < MLX5_MTR_RTE_COLORS; j++) {
18698 : : uint8_t act_n = 0;
18699 : : struct mlx5_flow_dv_modify_hdr_resource *modify_hdr;
18700 : : struct mlx5_flow_dv_port_id_action_resource *port_action;
18701 : :
18702 [ # # ]: 0 : if (mtr_policy->act_cnt[j].fate_action != MLX5_FLOW_FATE_MTR &&
18703 : : mtr_policy->act_cnt[j].fate_action != MLX5_FLOW_FATE_PORT_ID)
18704 : 0 : continue;
18705 : 0 : color_rule = mlx5_malloc(MLX5_MEM_ZERO,
18706 : : sizeof(struct mlx5_sub_policy_color_rule),
18707 : : 0, SOCKET_ID_ANY);
18708 [ # # ]: 0 : if (!color_rule) {
18709 : : rte_spinlock_unlock(&mtr_policy->sl);
18710 : 0 : rte_flow_error_set(error, ENOMEM,
18711 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
18712 : : "No memory to create tag color rule.");
18713 : 0 : goto err_exit;
18714 : : }
18715 : 0 : color_rule->src_port = src_port;
18716 : 0 : modify_hdr = mtr_policy->act_cnt[j].modify_hdr;
18717 : : /* Prepare to create color rule. */
18718 [ # # ]: 0 : if (mtr_policy->act_cnt[j].fate_action == MLX5_FLOW_FATE_MTR) {
18719 : 0 : next_fm = fm_info[i].next_fm;
18720 [ # # ]: 0 : if (mlx5_flow_meter_attach(priv, next_fm, &attr, error)) {
18721 : 0 : mlx5_free(color_rule);
18722 : : rte_spinlock_unlock(&mtr_policy->sl);
18723 : 0 : goto err_exit;
18724 : : }
18725 [ # # ]: 0 : mtr_action = (next_fm->color_aware && j == RTE_COLOR_YELLOW) ?
18726 [ # # ]: 0 : next_fm->meter_action_y :
18727 : : next_fm->meter_action_g;
18728 : 0 : next_policy = mlx5_flow_meter_policy_find(dev, next_fm->policy_id,
18729 : : NULL);
18730 : : MLX5_ASSERT(next_policy);
18731 : 0 : next_sub_policy = next_policy->sub_policys[domain][0];
18732 : 0 : tbl_data = container_of(next_sub_policy->tbl_rsc,
18733 : : struct mlx5_flow_tbl_data_entry, tbl);
18734 [ # # ]: 0 : if (mtr_first) {
18735 : 0 : acts.dv_actions[act_n++] = mtr_action;
18736 [ # # ]: 0 : if (modify_hdr)
18737 : 0 : acts.dv_actions[act_n++] = modify_hdr->action;
18738 : : } else {
18739 [ # # ]: 0 : if (modify_hdr)
18740 : 0 : acts.dv_actions[act_n++] = modify_hdr->action;
18741 : 0 : acts.dv_actions[act_n++] = mtr_action;
18742 : : }
18743 : 0 : acts.dv_actions[act_n++] = tbl_data->jump.action;
18744 : 0 : acts.actions_n = act_n;
18745 : : } else {
18746 : : port_action =
18747 : 0 : mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_PORT_ID],
18748 : : mtr_policy->act_cnt[j].rix_port_id_action);
18749 [ # # ]: 0 : if (!port_action) {
18750 : 0 : mlx5_free(color_rule);
18751 : : rte_spinlock_unlock(&mtr_policy->sl);
18752 : 0 : goto err_exit;
18753 : : }
18754 [ # # ]: 0 : if (modify_hdr)
18755 : 0 : acts.dv_actions[act_n++] = modify_hdr->action;
18756 : 0 : acts.dv_actions[act_n++] = port_action->action;
18757 : 0 : acts.actions_n = act_n;
18758 : : }
18759 : 0 : fm_info[i].tag_rule[j] = color_rule;
18760 : 0 : TAILQ_INSERT_TAIL(&sub_policy->color_rules[j], color_rule, next_port);
18761 [ # # ]: 0 : if (__flow_dv_create_policy_matcher(dev, color_reg_c_idx,
18762 : : MLX5_MTR_POLICY_MATCHER_PRIO, sub_policy,
18763 : : &attr, true, item, &color_rule->matcher, error)) {
18764 : : rte_spinlock_unlock(&mtr_policy->sl);
18765 : 0 : rte_flow_error_set(error, errno,
18766 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
18767 : : "Failed to create hierarchy meter matcher.");
18768 : 0 : goto err_exit;
18769 : : }
18770 [ # # ]: 0 : if (__flow_dv_create_policy_flow(dev, color_reg_c_idx, (enum rte_color)j,
18771 : : color_rule->matcher,
18772 : 0 : acts.actions_n, acts.dv_actions,
18773 : : true, item, &color_rule->rule, &attr)) {
18774 : : rte_spinlock_unlock(&mtr_policy->sl);
18775 : 0 : rte_flow_error_set(error, errno,
18776 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
18777 : : "Failed to create hierarchy meter rule.");
18778 : 0 : goto err_exit;
18779 : : }
18780 : : }
18781 : : rte_spinlock_unlock(&mtr_policy->sl);
18782 : : }
18783 : : return 0;
18784 : 0 : err_exit:
18785 [ # # ]: 0 : for (i = 0; i < fm_cnt; i++) {
18786 : 0 : mtr_policy = fm_info[i].fm_policy;
18787 : 0 : rte_spinlock_lock(&mtr_policy->sl);
18788 : 0 : sub_policy = mtr_policy->sub_policys[domain][0];
18789 [ # # ]: 0 : for (j = 0; j < MLX5_MTR_RTE_COLORS; j++) {
18790 : 0 : color_rule = fm_info[i].tag_rule[j];
18791 [ # # ]: 0 : if (!color_rule)
18792 : 0 : continue;
18793 [ # # ]: 0 : if (color_rule->rule)
18794 : : mlx5_flow_os_destroy_flow(color_rule->rule);
18795 [ # # ]: 0 : if (color_rule->matcher) {
18796 : : struct mlx5_flow_tbl_data_entry *tbl =
18797 : 0 : container_of(color_rule->matcher->tbl, typeof(*tbl), tbl);
18798 : 0 : mlx5_list_unregister(tbl->matchers, &color_rule->matcher->entry);
18799 : : }
18800 [ # # ]: 0 : if (fm_info[i].next_fm)
18801 : 0 : mlx5_flow_meter_detach(priv, fm_info[i].next_fm);
18802 [ # # ]: 0 : TAILQ_REMOVE(&sub_policy->color_rules[j], color_rule, next_port);
18803 : 0 : mlx5_free(color_rule);
18804 : : }
18805 : : rte_spinlock_unlock(&mtr_policy->sl);
18806 : : }
18807 : 0 : return -rte_errno;
18808 : : }
18809 : :
18810 : : /**
18811 : : * Destroy the sub policy table with RX queue.
18812 : : *
18813 : : * @param[in] dev
18814 : : * Pointer to Ethernet device.
18815 : : * @param[in] mtr_policy
18816 : : * Pointer to meter policy table.
18817 : : */
18818 : : static void
18819 : 0 : flow_dv_destroy_sub_policy_with_rxq(struct rte_eth_dev *dev,
18820 : : struct mlx5_flow_meter_policy *mtr_policy)
18821 : : {
18822 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18823 : : struct mlx5_flow_meter_sub_policy *sub_policy = NULL;
18824 : : uint32_t domain = MLX5_MTR_DOMAIN_INGRESS;
18825 : : uint32_t i, j;
18826 : : uint16_t sub_policy_num, new_policy_num;
18827 : :
18828 : 0 : rte_spinlock_lock(&mtr_policy->sl);
18829 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
18830 [ # # # ]: 0 : switch (mtr_policy->act_cnt[i].fate_action) {
18831 : 0 : case MLX5_FLOW_FATE_SHARED_RSS:
18832 : 0 : sub_policy_num = (mtr_policy->sub_policy_num >>
18833 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
18834 : : MLX5_MTR_SUB_POLICY_NUM_MASK;
18835 : : new_policy_num = sub_policy_num;
18836 [ # # ]: 0 : for (j = 0; j < sub_policy_num; j++) {
18837 : 0 : sub_policy =
18838 : 0 : mtr_policy->sub_policys[domain][j];
18839 [ # # ]: 0 : if (sub_policy) {
18840 : 0 : __flow_dv_destroy_sub_policy_rules(dev,
18841 : : sub_policy);
18842 : 0 : if (sub_policy !=
18843 [ # # ]: 0 : mtr_policy->sub_policys[domain][0]) {
18844 : 0 : mtr_policy->sub_policys[domain][j] =
18845 : : NULL;
18846 : 0 : mlx5_ipool_free
18847 : 0 : (priv->sh->ipool[MLX5_IPOOL_MTR_POLICY],
18848 : 0 : sub_policy->idx);
18849 : 0 : new_policy_num--;
18850 : : }
18851 : : }
18852 : : }
18853 [ # # ]: 0 : if (new_policy_num != sub_policy_num) {
18854 : 0 : mtr_policy->sub_policy_num &=
18855 : : ~(MLX5_MTR_SUB_POLICY_NUM_MASK <<
18856 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain));
18857 : 0 : mtr_policy->sub_policy_num |=
18858 : : (new_policy_num &
18859 : : MLX5_MTR_SUB_POLICY_NUM_MASK) <<
18860 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain);
18861 : : }
18862 : : break;
18863 : 0 : case MLX5_FLOW_FATE_QUEUE:
18864 : 0 : sub_policy = mtr_policy->sub_policys[domain][0];
18865 : 0 : __flow_dv_destroy_sub_policy_rules(dev,
18866 : : sub_policy);
18867 : 0 : break;
18868 : : default:
18869 : : /*Other actions without queue and do nothing*/
18870 : : break;
18871 : : }
18872 : : }
18873 : : rte_spinlock_unlock(&mtr_policy->sl);
18874 : 0 : }
18875 : : /**
18876 : : * Check whether the DR drop action is supported on the root table or not.
18877 : : *
18878 : : * Create a simple flow with DR drop action on root table to validate
18879 : : * if DR drop action on root table is supported or not.
18880 : : *
18881 : : * @param[in] dev
18882 : : * Pointer to rte_eth_dev structure.
18883 : : *
18884 : : * @return
18885 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
18886 : : */
18887 : : int
18888 : 0 : mlx5_flow_discover_dr_action_support(struct rte_eth_dev *dev)
18889 : : {
18890 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18891 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
18892 : 0 : struct mlx5_flow_dv_match_params mask = {
18893 : : .size = sizeof(mask.buf),
18894 : : };
18895 : 0 : struct mlx5_flow_dv_match_params value = {
18896 : : .size = sizeof(value.buf),
18897 : : };
18898 : 0 : struct mlx5dv_flow_matcher_attr dv_attr = {
18899 : : .type = IBV_FLOW_ATTR_NORMAL,
18900 : : .priority = 0,
18901 : : .match_criteria_enable = 0,
18902 : : .match_mask = (void *)&mask,
18903 : : };
18904 : : struct mlx5_flow_tbl_resource *tbl = NULL;
18905 : : void *matcher = NULL;
18906 : : void *flow = NULL;
18907 : : int ret = -1;
18908 : :
18909 : 0 : tbl = flow_dv_tbl_resource_get(dev, 0, 0, 0, false, NULL,
18910 : : 0, 0, 0, NULL);
18911 [ # # ]: 0 : if (!tbl)
18912 : 0 : goto err;
18913 [ # # ]: 0 : dv_attr.match_criteria_enable = flow_dv_matcher_enable(mask.buf);
18914 : : __flow_dv_adjust_buf_size(&mask.size, dv_attr.match_criteria_enable);
18915 : 0 : ret = mlx5_flow_os_create_flow_matcher(sh->cdev->ctx, &dv_attr,
18916 : : tbl->obj, &matcher);
18917 : : if (ret)
18918 : 0 : goto err;
18919 [ # # ]: 0 : __flow_dv_adjust_buf_size(&value.size, dv_attr.match_criteria_enable);
18920 : 0 : ret = mlx5_flow_os_create_flow(matcher, (void *)&value, 1,
18921 : : &sh->dr_drop_action, &flow);
18922 : 0 : err:
18923 : : /*
18924 : : * If DR drop action is not supported on root table, flow create will
18925 : : * be failed with EOPNOTSUPP or EPROTONOSUPPORT.
18926 : : */
18927 [ # # ]: 0 : if (!flow) {
18928 [ # # ]: 0 : if (matcher &&
18929 [ # # ]: 0 : (errno == EPROTONOSUPPORT || errno == EOPNOTSUPP))
18930 : 0 : DRV_LOG(INFO, "DR drop action is not supported in root table.");
18931 : : else
18932 : 0 : DRV_LOG(ERR, "Unexpected error in DR drop action support detection");
18933 : : ret = -1;
18934 : : } else {
18935 : : claim_zero(mlx5_flow_os_destroy_flow(flow));
18936 : : }
18937 [ # # ]: 0 : if (matcher)
18938 : : claim_zero(mlx5_flow_os_destroy_flow_matcher(matcher));
18939 [ # # ]: 0 : if (tbl)
18940 : 0 : flow_dv_tbl_resource_release(MLX5_SH(dev), tbl);
18941 : 0 : return ret;
18942 : : }
18943 : :
18944 : : /**
18945 : : * Validate the batch counter support in root table.
18946 : : *
18947 : : * Create a simple flow with invalid counter and drop action on root table to
18948 : : * validate if batch counter with offset on root table is supported or not.
18949 : : *
18950 : : * @param[in] dev
18951 : : * Pointer to rte_eth_dev structure.
18952 : : *
18953 : : * @return
18954 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
18955 : : */
18956 : : int
18957 : 0 : mlx5_flow_dv_discover_counter_offset_support(struct rte_eth_dev *dev)
18958 : : {
18959 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18960 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
18961 : 0 : struct mlx5_flow_dv_match_params mask = {
18962 : : .size = sizeof(mask.buf),
18963 : : };
18964 : 0 : struct mlx5_flow_dv_match_params value = {
18965 : : .size = sizeof(value.buf),
18966 : : };
18967 : 0 : struct mlx5dv_flow_matcher_attr dv_attr = {
18968 : : .type = IBV_FLOW_ATTR_NORMAL | IBV_FLOW_ATTR_FLAGS_EGRESS,
18969 : : .priority = 0,
18970 : : .match_criteria_enable = 0,
18971 : : .match_mask = (void *)&mask,
18972 : : };
18973 : 0 : void *actions[2] = { 0 };
18974 : : struct mlx5_flow_tbl_resource *tbl = NULL;
18975 : : struct mlx5_devx_obj *dcs = NULL;
18976 : : void *matcher = NULL;
18977 : : void *flow = NULL;
18978 : : int ret = -1;
18979 : :
18980 : 0 : tbl = flow_dv_tbl_resource_get(dev, 0, 1, 0, false, NULL,
18981 : : 0, 0, 0, NULL);
18982 [ # # ]: 0 : if (!tbl)
18983 : 0 : goto err;
18984 : 0 : dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->cdev->ctx, 0x4);
18985 [ # # ]: 0 : if (!dcs)
18986 : 0 : goto err;
18987 : 0 : ret = mlx5_flow_os_create_flow_action_count(dcs->obj, UINT16_MAX,
18988 : : &actions[0]);
18989 : : if (ret)
18990 : 0 : goto err;
18991 [ # # ]: 0 : dv_attr.match_criteria_enable = flow_dv_matcher_enable(mask.buf);
18992 : : __flow_dv_adjust_buf_size(&mask.size, dv_attr.match_criteria_enable);
18993 : 0 : ret = mlx5_flow_os_create_flow_matcher(sh->cdev->ctx, &dv_attr,
18994 : : tbl->obj, &matcher);
18995 : : if (ret)
18996 : 0 : goto err;
18997 [ # # ]: 0 : __flow_dv_adjust_buf_size(&value.size, dv_attr.match_criteria_enable);
18998 : : ret = mlx5_flow_os_create_flow(matcher, (void *)&value, 1,
18999 : : actions, &flow);
19000 : 0 : err:
19001 : : /*
19002 : : * If batch counter with offset is not supported, the driver will not
19003 : : * validate the invalid offset value, flow create should success.
19004 : : * In this case, it means batch counter is not supported in root table.
19005 : : *
19006 : : * Otherwise, if flow create is failed, counter offset is supported.
19007 : : */
19008 [ # # ]: 0 : if (flow) {
19009 : 0 : DRV_LOG(INFO, "Batch counter is not supported in root "
19010 : : "table. Switch to fallback mode.");
19011 : 0 : rte_errno = ENOTSUP;
19012 : : ret = -rte_errno;
19013 : : claim_zero(mlx5_flow_os_destroy_flow(flow));
19014 : : } else {
19015 : : /* Check matcher to make sure validate fail at flow create. */
19016 [ # # # # ]: 0 : if (!matcher || (matcher && errno != EINVAL))
19017 : 0 : DRV_LOG(ERR, "Unexpected error in counter offset "
19018 : : "support detection");
19019 : : ret = 0;
19020 : : }
19021 [ # # ]: 0 : if (actions[0])
19022 : : claim_zero(mlx5_flow_os_destroy_flow_action(actions[0]));
19023 [ # # ]: 0 : if (matcher)
19024 : : claim_zero(mlx5_flow_os_destroy_flow_matcher(matcher));
19025 [ # # ]: 0 : if (tbl)
19026 : 0 : flow_dv_tbl_resource_release(MLX5_SH(dev), tbl);
19027 [ # # ]: 0 : if (dcs)
19028 : 0 : claim_zero(mlx5_devx_cmd_destroy(dcs));
19029 : 0 : return ret;
19030 : : }
19031 : :
19032 : : /**
19033 : : * Query a devx counter.
19034 : : *
19035 : : * @param[in] dev
19036 : : * Pointer to the Ethernet device structure.
19037 : : * @param[in] cnt
19038 : : * Index to the flow counter.
19039 : : * @param[in] clear
19040 : : * Set to clear the counter statistics.
19041 : : * @param[out] pkts
19042 : : * The statistics value of packets.
19043 : : * @param[out] bytes
19044 : : * The statistics value of bytes.
19045 : : *
19046 : : * @return
19047 : : * 0 on success, otherwise return -1.
19048 : : */
19049 : : static int
19050 : 0 : flow_dv_counter_query(struct rte_eth_dev *dev, uint32_t counter, bool clear,
19051 : : uint64_t *pkts, uint64_t *bytes, void **action)
19052 : : {
19053 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19054 : : struct mlx5_flow_counter *cnt;
19055 : : uint64_t inn_pkts, inn_bytes;
19056 : : int ret;
19057 : :
19058 [ # # ]: 0 : if (!priv->sh->cdev->config.devx)
19059 : : return -1;
19060 : :
19061 : 0 : ret = _flow_dv_query_count(dev, counter, &inn_pkts, &inn_bytes);
19062 [ # # ]: 0 : if (ret)
19063 : : return -1;
19064 : : cnt = flow_dv_counter_get_by_idx(dev, counter, NULL);
19065 [ # # ]: 0 : if (cnt && action)
19066 : 0 : *action = cnt->action;
19067 : :
19068 : 0 : *pkts = inn_pkts - cnt->hits;
19069 : 0 : *bytes = inn_bytes - cnt->bytes;
19070 [ # # ]: 0 : if (clear) {
19071 : 0 : cnt->hits = inn_pkts;
19072 : 0 : cnt->bytes = inn_bytes;
19073 : : }
19074 : : return 0;
19075 : : }
19076 : :
19077 : : /**
19078 : : * Get aged-out flows.
19079 : : *
19080 : : * @param[in] dev
19081 : : * Pointer to the Ethernet device structure.
19082 : : * @param[in] context
19083 : : * The address of an array of pointers to the aged-out flows contexts.
19084 : : * @param[in] nb_contexts
19085 : : * The length of context array pointers.
19086 : : * @param[out] error
19087 : : * Perform verbose error reporting if not NULL. Initialized in case of
19088 : : * error only.
19089 : : *
19090 : : * @return
19091 : : * how many contexts get in success, otherwise negative errno value.
19092 : : * if nb_contexts is 0, return the amount of all aged contexts.
19093 : : * if nb_contexts is not 0 , return the amount of aged flows reported
19094 : : * in the context array.
19095 : : * @note: only stub for now
19096 : : */
19097 : : static int
19098 : 0 : flow_dv_get_aged_flows(struct rte_eth_dev *dev,
19099 : : void **context,
19100 : : uint32_t nb_contexts,
19101 : : struct rte_flow_error *error)
19102 : : {
19103 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19104 : : struct mlx5_age_info *age_info;
19105 : : struct mlx5_age_param *age_param;
19106 : : struct mlx5_flow_counter *counter;
19107 : : struct mlx5_aso_age_action *act;
19108 : : int nb_flows = 0;
19109 : :
19110 [ # # ]: 0 : if (nb_contexts && !context)
19111 : 0 : return rte_flow_error_set(error, EINVAL,
19112 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
19113 : : NULL, "empty context");
19114 : 0 : age_info = GET_PORT_AGE_INFO(priv);
19115 : 0 : rte_spinlock_lock(&age_info->aged_sl);
19116 [ # # ]: 0 : LIST_FOREACH(act, &age_info->aged_aso, next) {
19117 : 0 : nb_flows++;
19118 [ # # ]: 0 : if (nb_contexts) {
19119 : 0 : context[nb_flows - 1] =
19120 : 0 : act->age_params.context;
19121 [ # # ]: 0 : if (!(--nb_contexts))
19122 : : break;
19123 : : }
19124 : : }
19125 [ # # ]: 0 : TAILQ_FOREACH(counter, &age_info->aged_counters, next) {
19126 : 0 : nb_flows++;
19127 [ # # ]: 0 : if (nb_contexts) {
19128 : : age_param = MLX5_CNT_TO_AGE(counter);
19129 : 0 : context[nb_flows - 1] = age_param->context;
19130 [ # # ]: 0 : if (!(--nb_contexts))
19131 : : break;
19132 : : }
19133 : : }
19134 : : rte_spinlock_unlock(&age_info->aged_sl);
19135 : 0 : MLX5_AGE_SET(age_info, MLX5_AGE_TRIGGER);
19136 : 0 : return nb_flows;
19137 : : }
19138 : :
19139 : : /*
19140 : : * Mutex-protected thunk to lock-free flow_dv_counter_alloc().
19141 : : */
19142 : : static uint32_t
19143 : 0 : flow_dv_counter_allocate(struct rte_eth_dev *dev)
19144 : : {
19145 : 0 : return flow_dv_counter_alloc(dev, 0);
19146 : : }
19147 : :
19148 : : /**
19149 : : * Validate indirect action.
19150 : : * Dispatcher for action type specific validation.
19151 : : *
19152 : : * @param[in] dev
19153 : : * Pointer to the Ethernet device structure.
19154 : : * @param[in] conf
19155 : : * Indirect action configuration.
19156 : : * @param[in] action
19157 : : * The indirect action object to validate.
19158 : : * @param[out] error
19159 : : * Perform verbose error reporting if not NULL. Initialized in case of
19160 : : * error only.
19161 : : *
19162 : : * @return
19163 : : * 0 on success, otherwise negative errno value.
19164 : : */
19165 : : int
19166 : 0 : flow_dv_action_validate(struct rte_eth_dev *dev,
19167 : : const struct rte_flow_indir_action_conf *conf,
19168 : : const struct rte_flow_action *action,
19169 : : struct rte_flow_error *err)
19170 : : {
19171 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19172 : : /* called from RTE API */
19173 : :
19174 : : RTE_SET_USED(conf);
19175 [ # # # # : 0 : switch (action->type) {
# ]
19176 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
19177 : : /*
19178 : : * priv->obj_ops is set according to driver capabilities.
19179 : : * When DevX capabilities are
19180 : : * sufficient, it is set to devx_obj_ops.
19181 : : * Otherwise, it is set to ibv_obj_ops.
19182 : : * ibv_obj_ops doesn't support ind_table_modify operation.
19183 : : * In this case the indirect RSS action can't be used.
19184 : : */
19185 [ # # ]: 0 : if (priv->obj_ops.ind_table_modify == NULL)
19186 : 0 : return rte_flow_error_set
19187 : : (err, ENOTSUP,
19188 : : RTE_FLOW_ERROR_TYPE_ACTION,
19189 : : NULL,
19190 : : "Indirect RSS action not supported");
19191 : 0 : return mlx5_validate_action_rss(dev, action, err);
19192 : 0 : case RTE_FLOW_ACTION_TYPE_AGE:
19193 [ # # ]: 0 : if (!priv->sh->aso_age_mng)
19194 : 0 : return rte_flow_error_set(err, ENOTSUP,
19195 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
19196 : : NULL,
19197 : : "Indirect age action not supported");
19198 : 0 : return flow_dv_validate_action_age(0, action, dev, err);
19199 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
19200 : 0 : return flow_dv_validate_action_count(dev, true, 0, false, err);
19201 : 0 : case RTE_FLOW_ACTION_TYPE_CONNTRACK:
19202 [ # # ]: 0 : if (!priv->sh->ct_aso_en)
19203 : 0 : return rte_flow_error_set(err, ENOTSUP,
19204 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
19205 : : "ASO CT is not supported");
19206 : 0 : return mlx5_validate_action_ct(dev, action->conf, err);
19207 : 0 : default:
19208 : 0 : return rte_flow_error_set(err, ENOTSUP,
19209 : : RTE_FLOW_ERROR_TYPE_ACTION,
19210 : : NULL,
19211 : : "action type not supported");
19212 : : }
19213 : : }
19214 : :
19215 : : /*
19216 : : * Check if the RSS configurations for colors of a meter policy match
19217 : : * each other, except the queues.
19218 : : *
19219 : : * @param[in] r1
19220 : : * Pointer to the first RSS flow action.
19221 : : * @param[in] r2
19222 : : * Pointer to the second RSS flow action.
19223 : : *
19224 : : * @return
19225 : : * 0 on match, 1 on conflict.
19226 : : */
19227 : : static inline int
19228 : 0 : flow_dv_mtr_policy_rss_compare(const struct rte_flow_action_rss *r1,
19229 : : const struct rte_flow_action_rss *r2)
19230 : : {
19231 [ # # ]: 0 : if (r1 == NULL || r2 == NULL)
19232 : : return 0;
19233 [ # # # # : 0 : if (!(r1->level <= 1 && r2->level <= 1) &&
# # ]
19234 [ # # ]: 0 : !(r1->level > 1 && r2->level > 1))
19235 : : return 1;
19236 [ # # ]: 0 : if (r1->func != r2->func)
19237 : : return 1;
19238 [ # # ]: 0 : if (r1->types != r2->types &&
19239 [ # # ]: 0 : !((r1->types == 0 || r1->types == RTE_ETH_RSS_IP) &&
19240 [ # # ]: 0 : (r2->types == 0 || r2->types == RTE_ETH_RSS_IP)))
19241 : : return 1;
19242 [ # # # # ]: 0 : if (r1->key || r2->key) {
19243 [ # # ]: 0 : const void *key1 = r1->key ? r1->key : rss_hash_default_key;
19244 [ # # ]: 0 : const void *key2 = r2->key ? r2->key : rss_hash_default_key;
19245 : :
19246 [ # # ]: 0 : if (memcmp(key1, key2, MLX5_RSS_HASH_KEY_LEN))
19247 : 0 : return 1;
19248 : : }
19249 : : return 0;
19250 : : }
19251 : :
19252 : : /**
19253 : : * Validate the meter hierarchy chain for meter policy.
19254 : : *
19255 : : * @param[in] dev
19256 : : * Pointer to the Ethernet device structure.
19257 : : * @param[in] meter_id
19258 : : * Meter id.
19259 : : * @param[in] action_flags
19260 : : * Holds the actions detected until now.
19261 : : * @param[out] is_rss
19262 : : * Is RSS or not.
19263 : : * @param[out] hierarchy_domain
19264 : : * The domain bitmap for hierarchy policy.
19265 : : * @param[out] error
19266 : : * Perform verbose error reporting if not NULL. Initialized in case of
19267 : : * error only.
19268 : : *
19269 : : * @return
19270 : : * 0 on success, otherwise negative errno value with error set.
19271 : : */
19272 : : static int
19273 : 0 : flow_dv_validate_policy_mtr_hierarchy(struct rte_eth_dev *dev,
19274 : : uint32_t meter_id,
19275 : : uint64_t action_flags,
19276 : : bool *is_rss,
19277 : : uint8_t *hierarchy_domain,
19278 : : struct rte_mtr_error *error)
19279 : : {
19280 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19281 : : struct mlx5_flow_meter_info *fm;
19282 : : struct mlx5_flow_meter_policy *policy;
19283 : : uint8_t cnt = 1;
19284 : :
19285 [ # # ]: 0 : if (action_flags & (MLX5_FLOW_FATE_ACTIONS |
19286 : : MLX5_FLOW_FATE_ESWITCH_ACTIONS))
19287 : 0 : return -rte_mtr_error_set(error, EINVAL,
19288 : : RTE_MTR_ERROR_TYPE_POLICER_ACTION_GREEN,
19289 : : NULL,
19290 : : "Multiple fate actions not supported.");
19291 : 0 : *hierarchy_domain = 0;
19292 : 0 : fm = mlx5_flow_meter_find(priv, meter_id, NULL);
19293 : : while (true) {
19294 [ # # ]: 0 : if (!fm)
19295 : 0 : return -rte_mtr_error_set(error, EINVAL,
19296 : : RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
19297 : : "Meter not found in meter hierarchy.");
19298 [ # # ]: 0 : if (fm->def_policy)
19299 : 0 : return -rte_mtr_error_set(error, EINVAL,
19300 : : RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
19301 : : "Non termination meter not supported in hierarchy.");
19302 [ # # ]: 0 : if (!fm->shared)
19303 : 0 : return -rte_mtr_error_set(error, EINVAL,
19304 : : RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
19305 : : "Only shared meter supported in hierarchy.");
19306 : 0 : policy = mlx5_flow_meter_policy_find(dev, fm->policy_id, NULL);
19307 : : MLX5_ASSERT(policy);
19308 : : /**
19309 : : * Only inherit the supported domains of the first meter in
19310 : : * hierarchy.
19311 : : * One meter supports at least one domain.
19312 : : */
19313 [ # # ]: 0 : if (!*hierarchy_domain) {
19314 [ # # ]: 0 : if (policy->transfer)
19315 : 0 : *hierarchy_domain |=
19316 : : MLX5_MTR_DOMAIN_TRANSFER_BIT;
19317 [ # # ]: 0 : if (policy->ingress)
19318 : 0 : *hierarchy_domain |=
19319 : : MLX5_MTR_DOMAIN_INGRESS_BIT;
19320 [ # # ]: 0 : if (policy->egress)
19321 : 0 : *hierarchy_domain |= MLX5_MTR_DOMAIN_EGRESS_BIT;
19322 : : }
19323 [ # # ]: 0 : if (!policy->is_hierarchy) {
19324 : 0 : *is_rss = policy->is_rss;
19325 : : break;
19326 : : }
19327 : 0 : rte_spinlock_lock(&policy->sl);
19328 : 0 : fm = mlx5_flow_meter_hierarchy_next_meter(priv, policy, NULL);
19329 : : rte_spinlock_unlock(&policy->sl);
19330 [ # # ]: 0 : if (++cnt >= MLX5_MTR_CHAIN_MAX_NUM)
19331 : 0 : return -rte_mtr_error_set(error, EINVAL,
19332 : : RTE_MTR_ERROR_TYPE_METER_POLICY, NULL,
19333 : : "Exceed max hierarchy meter number.");
19334 : : }
19335 : 0 : return 0;
19336 : : }
19337 : :
19338 : : /**
19339 : : * Validate meter policy actions.
19340 : : * Dispatcher for action type specific validation.
19341 : : *
19342 : : * @param[in] dev
19343 : : * Pointer to the Ethernet device structure.
19344 : : * @param[in] action
19345 : : * The meter policy action object to validate.
19346 : : * @param[in] attr
19347 : : * Attributes of flow to determine steering domain.
19348 : : * @param[out] error
19349 : : * Perform verbose error reporting if not NULL. Initialized in case of
19350 : : * error only.
19351 : : *
19352 : : * @return
19353 : : * 0 on success, otherwise negative errno value.
19354 : : */
19355 : : static int
19356 : 0 : flow_dv_validate_mtr_policy_acts(struct rte_eth_dev *dev,
19357 : : const struct rte_flow_action *actions[RTE_COLORS],
19358 : : struct rte_flow_attr *attr,
19359 : : bool *is_rss,
19360 : : uint8_t *domain_bitmap,
19361 : : uint8_t *policy_mode,
19362 : : struct rte_mtr_error *error)
19363 : : {
19364 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19365 : 0 : struct mlx5_sh_config *dev_conf = &priv->sh->config;
19366 : : const struct rte_flow_action *act;
19367 : 0 : uint64_t action_flags[RTE_COLORS] = {0};
19368 : : int actions_n;
19369 : : int i, ret;
19370 : : struct rte_flow_error flow_err;
19371 : 0 : uint8_t domain_color[RTE_COLORS] = {0};
19372 : : uint8_t def_domain = MLX5_MTR_ALL_DOMAIN_BIT;
19373 : 0 : uint8_t hierarchy_domain = 0;
19374 : : const struct rte_flow_action_meter *mtr;
19375 : : const struct rte_flow_action_meter *next_mtr = NULL;
19376 : : bool def_green = false;
19377 : : bool def_yellow = false;
19378 : 0 : const struct rte_flow_action_rss *rss_color[RTE_COLORS] = {NULL};
19379 : : /* Called from RTE API */
19380 [ # # # # : 0 : bool is_root = !(attr->group || (attr->transfer && priv->fdb_def_rule));
# # ]
19381 : :
19382 [ # # ]: 0 : if (!dev_conf->dv_esw_en)
19383 : : def_domain &= ~MLX5_MTR_DOMAIN_TRANSFER_BIT;
19384 : 0 : *domain_bitmap = def_domain;
19385 : : /* Red color could only support DROP action. */
19386 [ # # ]: 0 : if (!actions[RTE_COLOR_RED] ||
19387 [ # # ]: 0 : actions[RTE_COLOR_RED]->type != RTE_FLOW_ACTION_TYPE_DROP)
19388 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
19389 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
19390 : : NULL, "Red color only supports drop action.");
19391 : : /*
19392 : : * Check default policy actions:
19393 : : * Green / Yellow: no action, Red: drop action
19394 : : * Either G or Y will trigger default policy actions to be created.
19395 : : */
19396 [ # # ]: 0 : if (!actions[RTE_COLOR_GREEN] ||
19397 [ # # ]: 0 : actions[RTE_COLOR_GREEN]->type == RTE_FLOW_ACTION_TYPE_END)
19398 : : def_green = true;
19399 [ # # ]: 0 : if (!actions[RTE_COLOR_YELLOW] ||
19400 [ # # ]: 0 : actions[RTE_COLOR_YELLOW]->type == RTE_FLOW_ACTION_TYPE_END)
19401 : : def_yellow = true;
19402 [ # # ]: 0 : if (def_green && def_yellow) {
19403 : 0 : *policy_mode = MLX5_MTR_POLICY_MODE_DEF;
19404 : 0 : return 0;
19405 [ # # ]: 0 : } else if (!def_green && def_yellow) {
19406 : 0 : *policy_mode = MLX5_MTR_POLICY_MODE_OG;
19407 [ # # ]: 0 : } else if (def_green && !def_yellow) {
19408 : 0 : *policy_mode = MLX5_MTR_POLICY_MODE_OY;
19409 : : } else {
19410 : 0 : *policy_mode = MLX5_MTR_POLICY_MODE_ALL;
19411 : : }
19412 : : /* Set to empty string in case of NULL pointer access by user. */
19413 : 0 : flow_err.message = "";
19414 [ # # ]: 0 : for (i = 0; i < RTE_COLORS; i++) {
19415 : 0 : act = actions[i];
19416 : 0 : for (action_flags[i] = 0, actions_n = 0;
19417 [ # # # # ]: 0 : act && act->type != RTE_FLOW_ACTION_TYPE_END;
19418 : 0 : act++) {
19419 [ # # ]: 0 : if (actions_n == MLX5_DV_MAX_NUMBER_OF_ACTIONS)
19420 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
19421 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
19422 : : NULL, "too many actions");
19423 [ # # # # : 0 : switch (act->type) {
# # # # #
# ]
19424 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_ID:
19425 : : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
19426 [ # # ]: 0 : if (!dev_conf->dv_esw_en)
19427 : 0 : return -rte_mtr_error_set(error,
19428 : : ENOTSUP,
19429 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
19430 : : NULL, "PORT action validate check"
19431 : : " fail for ESW disable");
19432 : 0 : ret = flow_dv_validate_action_port_id(dev,
19433 : : action_flags[i],
19434 : : act, attr, &flow_err);
19435 [ # # ]: 0 : if (ret)
19436 : 0 : return -rte_mtr_error_set(error,
19437 : : ENOTSUP,
19438 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
19439 [ # # ]: 0 : NULL, flow_err.message ?
19440 : : flow_err.message :
19441 : : "PORT action validate check fail");
19442 : 0 : ++actions_n;
19443 : 0 : action_flags[i] |= MLX5_FLOW_ACTION_PORT_ID;
19444 : 0 : break;
19445 : 0 : case RTE_FLOW_ACTION_TYPE_MARK:
19446 : 0 : ret = flow_dv_validate_action_mark(dev, act,
19447 : : action_flags[i],
19448 : : attr, &flow_err);
19449 [ # # ]: 0 : if (ret < 0)
19450 : 0 : return -rte_mtr_error_set(error,
19451 : : ENOTSUP,
19452 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
19453 [ # # ]: 0 : NULL, flow_err.message ?
19454 : : flow_err.message :
19455 : : "Mark action validate check fail");
19456 [ # # ]: 0 : if (dev_conf->dv_xmeta_en !=
19457 : : MLX5_XMETA_MODE_LEGACY)
19458 : 0 : return -rte_mtr_error_set(error,
19459 : : ENOTSUP,
19460 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
19461 : : NULL, "Extend MARK action is "
19462 : : "not supported. Please try use "
19463 : : "default policy for meter.");
19464 : 0 : action_flags[i] |= MLX5_FLOW_ACTION_MARK;
19465 : 0 : ++actions_n;
19466 : 0 : break;
19467 : 0 : case RTE_FLOW_ACTION_TYPE_SET_TAG:
19468 : 0 : ret = flow_dv_validate_action_set_tag(dev,
19469 : : act, action_flags[i],
19470 : : attr, &flow_err);
19471 [ # # ]: 0 : if (ret)
19472 : 0 : return -rte_mtr_error_set(error,
19473 : : ENOTSUP,
19474 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
19475 [ # # ]: 0 : NULL, flow_err.message ?
19476 : : flow_err.message :
19477 : : "Set tag action validate check fail");
19478 : 0 : action_flags[i] |= MLX5_FLOW_ACTION_SET_TAG;
19479 : 0 : ++actions_n;
19480 : 0 : break;
19481 : 0 : case RTE_FLOW_ACTION_TYPE_DROP:
19482 : 0 : ret = mlx5_flow_validate_action_drop
19483 : : (dev, false, attr, &flow_err);
19484 [ # # ]: 0 : if (ret < 0)
19485 : 0 : return -rte_mtr_error_set(error,
19486 : : ENOTSUP,
19487 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
19488 [ # # ]: 0 : NULL, flow_err.message ?
19489 : : flow_err.message :
19490 : : "Drop action validate check fail");
19491 : 0 : action_flags[i] |= MLX5_FLOW_ACTION_DROP;
19492 : 0 : ++actions_n;
19493 : 0 : break;
19494 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
19495 : : /*
19496 : : * Check whether extensive
19497 : : * metadata feature is engaged.
19498 : : */
19499 [ # # ]: 0 : if (dev_conf->dv_flow_en &&
19500 [ # # ]: 0 : (dev_conf->dv_xmeta_en !=
19501 [ # # ]: 0 : MLX5_XMETA_MODE_LEGACY) &&
19502 : 0 : mlx5_flow_ext_mreg_supported(dev))
19503 : 0 : return -rte_mtr_error_set(error,
19504 : : ENOTSUP,
19505 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
19506 : : NULL, "Queue action with meta "
19507 : : "is not supported. Please try use "
19508 : : "default policy for meter.");
19509 : 0 : ret = mlx5_flow_validate_action_queue(act,
19510 : : action_flags[i], dev,
19511 : : attr, &flow_err);
19512 [ # # ]: 0 : if (ret < 0)
19513 : 0 : return -rte_mtr_error_set(error,
19514 : : ENOTSUP,
19515 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
19516 [ # # ]: 0 : NULL, flow_err.message ?
19517 : : flow_err.message :
19518 : : "Queue action validate check fail");
19519 : 0 : action_flags[i] |= MLX5_FLOW_ACTION_QUEUE;
19520 : 0 : ++actions_n;
19521 : 0 : break;
19522 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
19523 [ # # ]: 0 : if (dev_conf->dv_flow_en &&
19524 [ # # ]: 0 : (dev_conf->dv_xmeta_en !=
19525 [ # # ]: 0 : MLX5_XMETA_MODE_LEGACY) &&
19526 : 0 : mlx5_flow_ext_mreg_supported(dev))
19527 : 0 : return -rte_mtr_error_set(error,
19528 : : ENOTSUP,
19529 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
19530 : : NULL, "RSS action with meta "
19531 : : "is not supported. Please try use "
19532 : : "default policy for meter.");
19533 : 0 : ret = mlx5_validate_action_rss(dev, act,
19534 : : &flow_err);
19535 [ # # ]: 0 : if (ret < 0)
19536 : 0 : return -rte_mtr_error_set(error,
19537 : : ENOTSUP,
19538 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
19539 [ # # ]: 0 : NULL, flow_err.message ?
19540 : : flow_err.message :
19541 : : "RSS action validate check fail");
19542 : 0 : action_flags[i] |= MLX5_FLOW_ACTION_RSS;
19543 : 0 : ++actions_n;
19544 : : /* Either G or Y will set the RSS. */
19545 : 0 : rss_color[i] = act->conf;
19546 : 0 : break;
19547 : 0 : case RTE_FLOW_ACTION_TYPE_JUMP:
19548 : 0 : ret = flow_dv_validate_action_jump(dev,
19549 : : NULL, act, action_flags[i],
19550 : : attr, true, &flow_err);
19551 [ # # ]: 0 : if (ret)
19552 : 0 : return -rte_mtr_error_set(error,
19553 : : ENOTSUP,
19554 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
19555 [ # # ]: 0 : NULL, flow_err.message ?
19556 : : flow_err.message :
19557 : : "Jump action validate check fail");
19558 : 0 : ++actions_n;
19559 : 0 : action_flags[i] |= MLX5_FLOW_ACTION_JUMP;
19560 : 0 : break;
19561 : 0 : case RTE_FLOW_ACTION_TYPE_METER:
19562 : 0 : mtr = act->conf;
19563 [ # # # # ]: 0 : if (next_mtr && next_mtr->mtr_id != mtr->mtr_id)
19564 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
19565 : : RTE_MTR_ERROR_TYPE_METER_POLICY, NULL,
19566 : : "Green and Yellow must use the same meter.");
19567 : 0 : ret = flow_dv_validate_policy_mtr_hierarchy(dev,
19568 : 0 : mtr->mtr_id,
19569 : : action_flags[i],
19570 : : is_rss,
19571 : : &hierarchy_domain,
19572 : : error);
19573 [ # # ]: 0 : if (ret)
19574 : 0 : return ret;
19575 : 0 : ++actions_n;
19576 : 0 : action_flags[i] |=
19577 : : MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY;
19578 : : next_mtr = mtr;
19579 : 0 : break;
19580 : 0 : case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
19581 : 0 : ret = flow_dv_validate_action_modify_field(dev,
19582 : : action_flags[i], act, attr, is_root, &flow_err);
19583 [ # # ]: 0 : if (ret < 0)
19584 : 0 : return -rte_mtr_error_set(error,
19585 : : ENOTSUP,
19586 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
19587 [ # # ]: 0 : NULL, flow_err.message ?
19588 : : flow_err.message :
19589 : : "Modify field action validate check fail");
19590 : 0 : ++actions_n;
19591 : 0 : action_flags[i] |= MLX5_FLOW_ACTION_MODIFY_FIELD;
19592 : 0 : break;
19593 : : default:
19594 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
19595 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
19596 : : NULL,
19597 : : "Doesn't support optional action");
19598 : : }
19599 : : }
19600 [ # # ]: 0 : if (action_flags[i] & MLX5_FLOW_ACTION_PORT_ID) {
19601 : 0 : domain_color[i] = MLX5_MTR_DOMAIN_TRANSFER_BIT;
19602 [ # # ]: 0 : } else if ((action_flags[i] &
19603 : 0 : (MLX5_FLOW_ACTION_RSS | MLX5_FLOW_ACTION_QUEUE)) ||
19604 [ # # ]: 0 : (action_flags[i] & MLX5_FLOW_ACTION_MARK)) {
19605 : : /*
19606 : : * Only support MLX5_XMETA_MODE_LEGACY
19607 : : * so MARK action is only in ingress domain.
19608 : : */
19609 : 0 : domain_color[i] = MLX5_MTR_DOMAIN_INGRESS_BIT;
19610 : : } else {
19611 : 0 : domain_color[i] = def_domain;
19612 [ # # ]: 0 : if (action_flags[i] &&
19613 [ # # ]: 0 : !(action_flags[i] & MLX5_FLOW_FATE_ESWITCH_ACTIONS))
19614 : 0 : domain_color[i] &=
19615 : : ~MLX5_MTR_DOMAIN_TRANSFER_BIT;
19616 : : }
19617 [ # # ]: 0 : if (action_flags[i] &
19618 : : MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY)
19619 : 0 : domain_color[i] &= hierarchy_domain;
19620 : : /*
19621 : : * Non-termination actions only support NIC Tx domain.
19622 : : * The adjustion should be skipped when there is no
19623 : : * action or only END is provided. The default domains
19624 : : * bit-mask is set to find the MIN intersection.
19625 : : * The action flags checking should also be skipped.
19626 : : */
19627 [ # # ]: 0 : if ((def_green && i == RTE_COLOR_GREEN) ||
19628 [ # # ]: 0 : (def_yellow && i == RTE_COLOR_YELLOW))
19629 : 0 : continue;
19630 : : /*
19631 : : * Validate the drop action mutual exclusion
19632 : : * with other actions. Drop action is mutually-exclusive
19633 : : * with any other action, except for Count action.
19634 : : */
19635 [ # # ]: 0 : if ((action_flags[i] & MLX5_FLOW_ACTION_DROP) &&
19636 [ # # ]: 0 : (action_flags[i] & ~MLX5_FLOW_ACTION_DROP)) {
19637 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
19638 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
19639 : : NULL, "Drop action is mutually-exclusive "
19640 : : "with any other action");
19641 : : }
19642 : : /* Eswitch has few restrictions on using items and actions */
19643 [ # # ]: 0 : if (domain_color[i] & MLX5_MTR_DOMAIN_TRANSFER_BIT) {
19644 [ # # ]: 0 : if (!mlx5_flow_ext_mreg_supported(dev) &&
19645 [ # # ]: 0 : action_flags[i] & MLX5_FLOW_ACTION_MARK)
19646 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
19647 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
19648 : : NULL, "unsupported action MARK");
19649 [ # # ]: 0 : if (action_flags[i] & MLX5_FLOW_ACTION_QUEUE)
19650 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
19651 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
19652 : : NULL, "unsupported action QUEUE");
19653 [ # # ]: 0 : if (action_flags[i] & MLX5_FLOW_ACTION_RSS)
19654 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
19655 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
19656 : : NULL, "unsupported action RSS");
19657 [ # # ]: 0 : if (!(action_flags[i] & MLX5_FLOW_FATE_ESWITCH_ACTIONS))
19658 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
19659 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
19660 : : NULL, "no fate action is found");
19661 : : } else {
19662 [ # # # # ]: 0 : if (!(action_flags[i] & MLX5_FLOW_FATE_ACTIONS) &&
19663 : : (domain_color[i] & MLX5_MTR_DOMAIN_INGRESS_BIT)) {
19664 [ # # ]: 0 : if ((domain_color[i] &
19665 : : MLX5_MTR_DOMAIN_EGRESS_BIT))
19666 : 0 : domain_color[i] =
19667 : : MLX5_MTR_DOMAIN_EGRESS_BIT;
19668 : : else
19669 : 0 : return -rte_mtr_error_set(error,
19670 : : ENOTSUP,
19671 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
19672 : : NULL,
19673 : : "no fate action is found");
19674 : : }
19675 : : }
19676 : : }
19677 [ # # # # ]: 0 : if (next_mtr && *policy_mode == MLX5_MTR_POLICY_MODE_ALL) {
19678 [ # # ]: 0 : if (!(action_flags[RTE_COLOR_GREEN] & action_flags[RTE_COLOR_YELLOW] &
19679 : : MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY))
19680 : 0 : return -rte_mtr_error_set(error, EINVAL, RTE_MTR_ERROR_TYPE_METER_POLICY,
19681 : : NULL,
19682 : : "Meter hierarchy supports meter action only.");
19683 : : }
19684 : : /* If both colors have RSS, the attributes should be the same. */
19685 [ # # ]: 0 : if (flow_dv_mtr_policy_rss_compare(rss_color[RTE_COLOR_GREEN],
19686 : : rss_color[RTE_COLOR_YELLOW]))
19687 : 0 : return -rte_mtr_error_set(error, EINVAL,
19688 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
19689 : : NULL, "policy RSS attr conflict");
19690 [ # # # # ]: 0 : if (rss_color[RTE_COLOR_GREEN] || rss_color[RTE_COLOR_YELLOW])
19691 : 0 : *is_rss = true;
19692 : : /* "domain_color[C]" is non-zero for each color, default is ALL. */
19693 [ # # ]: 0 : if (!def_green && !def_yellow &&
19694 [ # # ]: 0 : domain_color[RTE_COLOR_GREEN] != domain_color[RTE_COLOR_YELLOW] &&
19695 [ # # ]: 0 : !(action_flags[RTE_COLOR_GREEN] & MLX5_FLOW_ACTION_DROP) &&
19696 [ # # ]: 0 : !(action_flags[RTE_COLOR_YELLOW] & MLX5_FLOW_ACTION_DROP))
19697 : 0 : return -rte_mtr_error_set(error, EINVAL,
19698 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
19699 : : NULL, "policy domains conflict");
19700 : : /*
19701 : : * At least one color policy is listed in the actions, the domains
19702 : : * to be supported should be the intersection.
19703 : : */
19704 : 0 : *domain_bitmap = domain_color[RTE_COLOR_GREEN] &
19705 : 0 : domain_color[RTE_COLOR_YELLOW];
19706 : 0 : return 0;
19707 : : }
19708 : :
19709 : : static int
19710 : 0 : flow_dv_sync_domain(struct rte_eth_dev *dev, uint32_t domains, uint32_t flags)
19711 : : {
19712 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19713 : : int ret = 0;
19714 : :
19715 [ # # # # ]: 0 : if ((domains & RTE_PMD_MLX5_DOMAIN_BIT_NIC_RX) && priv->sh->rx_domain != NULL) {
19716 : : ret = mlx5_os_flow_dr_sync_domain(priv->sh->rx_domain,
19717 : : flags);
19718 [ # # ]: 0 : if (ret != 0)
19719 : : return ret;
19720 : : }
19721 [ # # # # ]: 0 : if ((domains & RTE_PMD_MLX5_DOMAIN_BIT_NIC_TX) && priv->sh->tx_domain != NULL) {
19722 : : ret = mlx5_os_flow_dr_sync_domain(priv->sh->tx_domain, flags);
19723 [ # # ]: 0 : if (ret != 0)
19724 : : return ret;
19725 : : }
19726 [ # # # # ]: 0 : if ((domains & RTE_PMD_MLX5_DOMAIN_BIT_FDB) && priv->sh->fdb_domain != NULL) {
19727 : : ret = mlx5_os_flow_dr_sync_domain(priv->sh->fdb_domain, flags);
19728 [ # # ]: 0 : if (ret != 0)
19729 : 0 : return ret;
19730 : : }
19731 : : return 0;
19732 : : }
19733 : :
19734 : : /**
19735 : : * Discover the number of available flow priorities
19736 : : * by trying to create a flow with the highest priority value
19737 : : * for each possible number.
19738 : : *
19739 : : * @param[in] dev
19740 : : * Ethernet device.
19741 : : * @param[in] vprio
19742 : : * List of possible number of available priorities.
19743 : : * @param[in] vprio_n
19744 : : * Size of @p vprio array.
19745 : : * @return
19746 : : * On success, number of available flow priorities.
19747 : : * On failure, a negative errno-style code and rte_errno is set.
19748 : : */
19749 : : static int
19750 : 0 : flow_dv_discover_priorities(struct rte_eth_dev *dev,
19751 : : const uint16_t *vprio, int vprio_n)
19752 : : {
19753 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19754 : 0 : struct mlx5_indexed_pool *pool = priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW];
19755 : : struct rte_flow_item_eth eth;
19756 : 0 : struct rte_flow_item item = {
19757 : : .type = RTE_FLOW_ITEM_TYPE_ETH,
19758 : : .spec = ð,
19759 : : .mask = ð,
19760 : : };
19761 : 0 : struct mlx5_flow_dv_matcher matcher = {
19762 : : .mask = {
19763 : : .size = sizeof(matcher.mask.buf),
19764 : : },
19765 : : };
19766 : : union mlx5_flow_tbl_key tbl_key;
19767 : : struct mlx5_flow flow;
19768 : : void *action;
19769 : : struct rte_flow_error error;
19770 : : uint8_t misc_mask;
19771 : : int i, err, ret = -ENOTSUP;
19772 : :
19773 : : /*
19774 : : * Prepare a flow with a catch-all pattern and a drop action.
19775 : : * Use drop queue, because shared drop action may be unavailable.
19776 : : */
19777 : 0 : action = priv->drop_queue.hrxq->action;
19778 [ # # ]: 0 : if (action == NULL) {
19779 : 0 : DRV_LOG(ERR, "Priority discovery requires a drop action");
19780 : 0 : rte_errno = ENOTSUP;
19781 : 0 : return -rte_errno;
19782 : : }
19783 : : memset(&flow, 0, sizeof(flow));
19784 : 0 : flow.handle = mlx5_ipool_zmalloc(pool, &flow.handle_idx);
19785 [ # # ]: 0 : if (flow.handle == NULL) {
19786 : 0 : DRV_LOG(ERR, "Cannot create flow handle");
19787 : 0 : rte_errno = ENOMEM;
19788 : 0 : return -rte_errno;
19789 : : }
19790 : 0 : flow.ingress = true;
19791 : 0 : flow.dv.value.size = MLX5_ST_SZ_BYTES(fte_match_param);
19792 : 0 : flow.dv.actions[0] = action;
19793 : 0 : flow.dv.actions_n = 1;
19794 : : memset(ð, 0, sizeof(eth));
19795 : 0 : flow_dv_translate_item_eth(matcher.mask.buf, &item,
19796 : : /* inner */ false, /* group */ 0,
19797 : : MLX5_SET_MATCHER_SW_M);
19798 : 0 : flow_dv_translate_item_eth(flow.dv.value.buf, &item,
19799 : : /* inner */ false, /* group */ 0,
19800 : : MLX5_SET_MATCHER_SW_V);
19801 : 0 : matcher.crc = rte_raw_cksum(matcher.mask.buf, matcher.mask.size);
19802 [ # # ]: 0 : for (i = 0; i < vprio_n; i++) {
19803 : : /* Configure the next proposed maximum priority. */
19804 : 0 : matcher.priority = vprio[i] - 1;
19805 : : memset(&tbl_key, 0, sizeof(tbl_key));
19806 : 0 : err = flow_dv_matcher_register(dev, &matcher, &tbl_key, &flow,
19807 : : /* tunnel */ NULL,
19808 : : /* group */ 0,
19809 : : &error);
19810 [ # # ]: 0 : if (err != 0) {
19811 : : /* This action is pure SW and must always succeed. */
19812 : 0 : DRV_LOG(ERR, "Cannot register matcher");
19813 : 0 : ret = -rte_errno;
19814 : 0 : break;
19815 : : }
19816 : : /* Try to apply the flow to HW. */
19817 [ # # ]: 0 : misc_mask = flow_dv_matcher_enable(flow.handle->dvh.matcher->mask.buf);
19818 : : __flow_dv_adjust_buf_size(&flow.dv.value.size, misc_mask);
19819 : 0 : err = mlx5_flow_os_create_flow
19820 : : (flow.handle->dvh.matcher->matcher_object,
19821 : 0 : (void *)&flow.dv.value, flow.dv.actions_n,
19822 : : flow.dv.actions, &flow.handle->drv_flow);
19823 : : if (err == 0) {
19824 : 0 : claim_zero(mlx5_flow_os_destroy_flow
19825 : : (flow.handle->drv_flow));
19826 : 0 : flow.handle->drv_flow = NULL;
19827 : : }
19828 : 0 : claim_zero(flow_dv_matcher_release(dev, flow.handle));
19829 [ # # ]: 0 : if (err != 0)
19830 : : break;
19831 : 0 : ret = vprio[i];
19832 : : }
19833 : 0 : mlx5_ipool_free(pool, flow.handle_idx);
19834 : : /* Set rte_errno if no expected priority value matched. */
19835 [ # # ]: 0 : if (ret < 0)
19836 : 0 : rte_errno = -ret;
19837 : : return ret;
19838 : : }
19839 : :
19840 : : const struct mlx5_flow_driver_ops mlx5_flow_dv_drv_ops = {
19841 : : .validate = flow_dv_validate,
19842 : : .prepare = flow_dv_prepare,
19843 : : .translate = flow_dv_translate,
19844 : : .apply = flow_dv_apply,
19845 : : .remove = flow_dv_remove,
19846 : : .destroy = flow_dv_destroy,
19847 : : .query = flow_dv_query,
19848 : : .create_mtr_tbls = flow_dv_create_mtr_tbls,
19849 : : .destroy_mtr_tbls = flow_dv_destroy_mtr_tbls,
19850 : : .destroy_mtr_drop_tbls = flow_dv_destroy_mtr_drop_tbls,
19851 : : .create_meter = flow_dv_mtr_alloc,
19852 : : .free_meter = flow_dv_aso_mtr_release_to_pool,
19853 : : .validate_mtr_acts = flow_dv_validate_mtr_policy_acts,
19854 : : .create_mtr_acts = flow_dv_create_mtr_policy_acts,
19855 : : .destroy_mtr_acts = flow_dv_destroy_mtr_policy_acts,
19856 : : .create_policy_rules = flow_dv_create_policy_rules,
19857 : : .destroy_policy_rules = flow_dv_destroy_policy_rules,
19858 : : .create_def_policy = flow_dv_create_def_policy,
19859 : : .destroy_def_policy = flow_dv_destroy_def_policy,
19860 : : .meter_sub_policy_rss_prepare = flow_dv_meter_sub_policy_rss_prepare,
19861 : : .meter_hierarchy_rule_create = flow_dv_meter_hierarchy_rule_create,
19862 : : .destroy_sub_policy_with_rxq = flow_dv_destroy_sub_policy_with_rxq,
19863 : : .counter_alloc = flow_dv_counter_allocate,
19864 : : .counter_free = flow_dv_counter_free,
19865 : : .counter_query = flow_dv_counter_query,
19866 : : .get_aged_flows = flow_dv_get_aged_flows,
19867 : : .action_validate = flow_dv_action_validate,
19868 : : .action_create = flow_dv_action_create,
19869 : : .action_destroy = flow_dv_action_destroy,
19870 : : .action_update = flow_dv_action_update,
19871 : : .action_query = flow_dv_action_query,
19872 : : .sync_domain = flow_dv_sync_domain,
19873 : : .discover_priorities = flow_dv_discover_priorities,
19874 : : .item_create = flow_dv_item_create,
19875 : : .item_release = flow_dv_item_release,
19876 : : };
19877 : :
19878 : : #endif /* HAVE_IBV_FLOW_DV_SUPPORT */
|