1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2016 6WIND S.A.
3 * Copyright 2016 Mellanox Technologies, Ltd
10 #include <sys/queue.h>
12 #include <rte_common.h>
13 #include <rte_ether.h>
14 #include <ethdev_driver.h>
15 #include <rte_eal_paging.h>
17 #include <rte_cycles.h>
18 #include <rte_flow_driver.h>
19 #include <rte_malloc.h>
22 #include <mlx5_glue.h>
23 #include <mlx5_devx_cmds.h>
25 #include <mlx5_malloc.h>
27 #include "mlx5_defs.h"
29 #include "mlx5_flow.h"
30 #include "mlx5_flow_os.h"
33 #include "mlx5_common_os.h"
34 #include "rte_pmd_mlx5.h"
36 struct tunnel_default_miss_ctx {
40 struct rte_flow_action_rss action_rss;
41 struct rte_flow_action_queue miss_queue;
42 struct rte_flow_action_jump miss_jump;
48 flow_tunnel_add_default_miss(struct rte_eth_dev *dev,
49 struct rte_flow *flow,
50 const struct rte_flow_attr *attr,
51 const struct rte_flow_action *app_actions,
53 const struct mlx5_flow_tunnel *tunnel,
54 struct tunnel_default_miss_ctx *ctx,
55 struct rte_flow_error *error);
56 static struct mlx5_flow_tunnel *
57 mlx5_find_tunnel_id(struct rte_eth_dev *dev, uint32_t id);
59 mlx5_flow_tunnel_free(struct rte_eth_dev *dev, struct mlx5_flow_tunnel *tunnel);
61 tunnel_flow_group_to_flow_table(struct rte_eth_dev *dev,
62 const struct mlx5_flow_tunnel *tunnel,
63 uint32_t group, uint32_t *table,
64 struct rte_flow_error *error);
66 static struct mlx5_flow_workspace *mlx5_flow_push_thread_workspace(void);
67 static void mlx5_flow_pop_thread_workspace(void);
70 /** Device flow drivers. */
71 extern const struct mlx5_flow_driver_ops mlx5_flow_verbs_drv_ops;
73 const struct mlx5_flow_driver_ops mlx5_flow_null_drv_ops;
75 const struct mlx5_flow_driver_ops *flow_drv_ops[] = {
76 [MLX5_FLOW_TYPE_MIN] = &mlx5_flow_null_drv_ops,
77 #if defined(HAVE_IBV_FLOW_DV_SUPPORT) || !defined(HAVE_INFINIBAND_VERBS_H)
78 [MLX5_FLOW_TYPE_DV] = &mlx5_flow_dv_drv_ops,
80 [MLX5_FLOW_TYPE_VERBS] = &mlx5_flow_verbs_drv_ops,
81 [MLX5_FLOW_TYPE_MAX] = &mlx5_flow_null_drv_ops
84 /** Helper macro to build input graph for mlx5_flow_expand_rss(). */
85 #define MLX5_FLOW_EXPAND_RSS_NEXT(...) \
90 /** Node object of input graph for mlx5_flow_expand_rss(). */
91 struct mlx5_flow_expand_node {
92 const int *const next;
94 * List of next node indexes. Index 0 is interpreted as a terminator.
96 const enum rte_flow_item_type type;
97 /**< Pattern item type of current node. */
100 * RSS types bit-field associated with this node
101 * (see ETH_RSS_* definitions).
104 /**< optional expand field. Default 0 to expand, 1 not go deeper. */
107 /** Object returned by mlx5_flow_expand_rss(). */
108 struct mlx5_flow_expand_rss {
110 /**< Number of entries @p patterns and @p priorities. */
112 struct rte_flow_item *pattern; /**< Expanded pattern array. */
113 uint32_t priority; /**< Priority offset for each expansion. */
118 mlx5_dbg__print_pattern(const struct rte_flow_item *item);
121 mlx5_flow_is_rss_expandable_item(const struct rte_flow_item *item)
123 switch (item->type) {
124 case RTE_FLOW_ITEM_TYPE_ETH:
125 case RTE_FLOW_ITEM_TYPE_VLAN:
126 case RTE_FLOW_ITEM_TYPE_IPV4:
127 case RTE_FLOW_ITEM_TYPE_IPV6:
128 case RTE_FLOW_ITEM_TYPE_UDP:
129 case RTE_FLOW_ITEM_TYPE_TCP:
130 case RTE_FLOW_ITEM_TYPE_VXLAN:
131 case RTE_FLOW_ITEM_TYPE_NVGRE:
132 case RTE_FLOW_ITEM_TYPE_GRE:
133 case RTE_FLOW_ITEM_TYPE_GENEVE:
141 static enum rte_flow_item_type
142 mlx5_flow_expand_rss_item_complete(const struct rte_flow_item *item)
144 enum rte_flow_item_type ret = RTE_FLOW_ITEM_TYPE_VOID;
145 uint16_t ether_type = 0;
146 uint16_t ether_type_m;
147 uint8_t ip_next_proto = 0;
148 uint8_t ip_next_proto_m;
150 if (item == NULL || item->spec == NULL)
152 switch (item->type) {
153 case RTE_FLOW_ITEM_TYPE_ETH:
155 ether_type_m = ((const struct rte_flow_item_eth *)
158 ether_type_m = rte_flow_item_eth_mask.type;
159 if (ether_type_m != RTE_BE16(0xFFFF))
161 ether_type = ((const struct rte_flow_item_eth *)
163 if (rte_be_to_cpu_16(ether_type) == RTE_ETHER_TYPE_IPV4)
164 ret = RTE_FLOW_ITEM_TYPE_IPV4;
165 else if (rte_be_to_cpu_16(ether_type) == RTE_ETHER_TYPE_IPV6)
166 ret = RTE_FLOW_ITEM_TYPE_IPV6;
167 else if (rte_be_to_cpu_16(ether_type) == RTE_ETHER_TYPE_VLAN)
168 ret = RTE_FLOW_ITEM_TYPE_VLAN;
170 ret = RTE_FLOW_ITEM_TYPE_END;
172 case RTE_FLOW_ITEM_TYPE_VLAN:
174 ether_type_m = ((const struct rte_flow_item_vlan *)
175 (item->mask))->inner_type;
177 ether_type_m = rte_flow_item_vlan_mask.inner_type;
178 if (ether_type_m != RTE_BE16(0xFFFF))
180 ether_type = ((const struct rte_flow_item_vlan *)
181 (item->spec))->inner_type;
182 if (rte_be_to_cpu_16(ether_type) == RTE_ETHER_TYPE_IPV4)
183 ret = RTE_FLOW_ITEM_TYPE_IPV4;
184 else if (rte_be_to_cpu_16(ether_type) == RTE_ETHER_TYPE_IPV6)
185 ret = RTE_FLOW_ITEM_TYPE_IPV6;
186 else if (rte_be_to_cpu_16(ether_type) == RTE_ETHER_TYPE_VLAN)
187 ret = RTE_FLOW_ITEM_TYPE_VLAN;
189 ret = RTE_FLOW_ITEM_TYPE_END;
191 case RTE_FLOW_ITEM_TYPE_IPV4:
193 ip_next_proto_m = ((const struct rte_flow_item_ipv4 *)
194 (item->mask))->hdr.next_proto_id;
197 rte_flow_item_ipv4_mask.hdr.next_proto_id;
198 if (ip_next_proto_m != 0xFF)
200 ip_next_proto = ((const struct rte_flow_item_ipv4 *)
201 (item->spec))->hdr.next_proto_id;
202 if (ip_next_proto == IPPROTO_UDP)
203 ret = RTE_FLOW_ITEM_TYPE_UDP;
204 else if (ip_next_proto == IPPROTO_TCP)
205 ret = RTE_FLOW_ITEM_TYPE_TCP;
206 else if (ip_next_proto == IPPROTO_IP)
207 ret = RTE_FLOW_ITEM_TYPE_IPV4;
208 else if (ip_next_proto == IPPROTO_IPV6)
209 ret = RTE_FLOW_ITEM_TYPE_IPV6;
211 ret = RTE_FLOW_ITEM_TYPE_END;
213 case RTE_FLOW_ITEM_TYPE_IPV6:
215 ip_next_proto_m = ((const struct rte_flow_item_ipv6 *)
216 (item->mask))->hdr.proto;
219 rte_flow_item_ipv6_mask.hdr.proto;
220 if (ip_next_proto_m != 0xFF)
222 ip_next_proto = ((const struct rte_flow_item_ipv6 *)
223 (item->spec))->hdr.proto;
224 if (ip_next_proto == IPPROTO_UDP)
225 ret = RTE_FLOW_ITEM_TYPE_UDP;
226 else if (ip_next_proto == IPPROTO_TCP)
227 ret = RTE_FLOW_ITEM_TYPE_TCP;
228 else if (ip_next_proto == IPPROTO_IP)
229 ret = RTE_FLOW_ITEM_TYPE_IPV4;
230 else if (ip_next_proto == IPPROTO_IPV6)
231 ret = RTE_FLOW_ITEM_TYPE_IPV6;
233 ret = RTE_FLOW_ITEM_TYPE_END;
236 ret = RTE_FLOW_ITEM_TYPE_VOID;
242 #define MLX5_RSS_EXP_ELT_N 16
245 * Expand RSS flows into several possible flows according to the RSS hash
246 * fields requested and the driver capabilities.
249 * Buffer to store the result expansion.
251 * Buffer size in bytes. If 0, @p buf can be NULL.
255 * RSS types to expand (see ETH_RSS_* definitions).
257 * Input graph to expand @p pattern according to @p types.
258 * @param[in] graph_root_index
259 * Index of root node in @p graph, typically 0.
262 * A positive value representing the size of @p buf in bytes regardless of
263 * @p size on success, a negative errno value otherwise and rte_errno is
264 * set, the following errors are defined:
266 * -E2BIG: graph-depth @p graph is too deep.
267 * -EINVAL: @p size has not enough space for expanded pattern.
270 mlx5_flow_expand_rss(struct mlx5_flow_expand_rss *buf, size_t size,
271 const struct rte_flow_item *pattern, uint64_t types,
272 const struct mlx5_flow_expand_node graph[],
273 int graph_root_index)
275 const struct rte_flow_item *item;
276 const struct mlx5_flow_expand_node *node = &graph[graph_root_index];
277 const int *next_node;
278 const int *stack[MLX5_RSS_EXP_ELT_N];
280 struct rte_flow_item flow_items[MLX5_RSS_EXP_ELT_N];
283 size_t user_pattern_size = 0;
285 const struct mlx5_flow_expand_node *next = NULL;
286 struct rte_flow_item missed_item;
289 const struct rte_flow_item *last_item = NULL;
291 memset(&missed_item, 0, sizeof(missed_item));
292 lsize = offsetof(struct mlx5_flow_expand_rss, entry) +
293 MLX5_RSS_EXP_ELT_N * sizeof(buf->entry[0]);
296 buf->entry[0].priority = 0;
297 buf->entry[0].pattern = (void *)&buf->entry[MLX5_RSS_EXP_ELT_N];
299 addr = buf->entry[0].pattern;
300 for (item = pattern; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
301 if (!mlx5_flow_is_rss_expandable_item(item)) {
302 user_pattern_size += sizeof(*item);
306 for (i = 0; node->next && node->next[i]; ++i) {
307 next = &graph[node->next[i]];
308 if (next->type == item->type)
313 user_pattern_size += sizeof(*item);
315 user_pattern_size += sizeof(*item); /* Handle END item. */
316 lsize += user_pattern_size;
319 /* Copy the user pattern in the first entry of the buffer. */
320 rte_memcpy(addr, pattern, user_pattern_size);
321 addr = (void *)(((uintptr_t)addr) + user_pattern_size);
323 /* Start expanding. */
324 memset(flow_items, 0, sizeof(flow_items));
325 user_pattern_size -= sizeof(*item);
327 * Check if the last valid item has spec set, need complete pattern,
328 * and the pattern can be used for expansion.
330 missed_item.type = mlx5_flow_expand_rss_item_complete(last_item);
331 if (missed_item.type == RTE_FLOW_ITEM_TYPE_END) {
332 /* Item type END indicates expansion is not required. */
335 if (missed_item.type != RTE_FLOW_ITEM_TYPE_VOID) {
338 for (i = 0; node->next && node->next[i]; ++i) {
339 next = &graph[node->next[i]];
340 if (next->type == missed_item.type) {
341 flow_items[0].type = missed_item.type;
342 flow_items[1].type = RTE_FLOW_ITEM_TYPE_END;
348 if (next && missed) {
349 elt = 2; /* missed item + item end. */
351 lsize += elt * sizeof(*item) + user_pattern_size;
354 if (node->rss_types & types) {
355 buf->entry[buf->entries].priority = 1;
356 buf->entry[buf->entries].pattern = addr;
358 rte_memcpy(addr, buf->entry[0].pattern,
360 addr = (void *)(((uintptr_t)addr) + user_pattern_size);
361 rte_memcpy(addr, flow_items, elt * sizeof(*item));
362 addr = (void *)(((uintptr_t)addr) +
363 elt * sizeof(*item));
366 memset(flow_items, 0, sizeof(flow_items));
367 next_node = node->next;
368 stack[stack_pos] = next_node;
369 node = next_node ? &graph[*next_node] : NULL;
371 flow_items[stack_pos].type = node->type;
372 if (node->rss_types & types) {
375 * compute the number of items to copy from the
376 * expansion and copy it.
377 * When the stack_pos is 0, there are 1 element in it,
378 * plus the addition END item.
381 flow_items[stack_pos + 1].type = RTE_FLOW_ITEM_TYPE_END;
382 lsize += elt * sizeof(*item) + user_pattern_size;
385 n = elt * sizeof(*item);
386 buf->entry[buf->entries].priority =
387 stack_pos + 1 + missed;
388 buf->entry[buf->entries].pattern = addr;
390 rte_memcpy(addr, buf->entry[0].pattern,
392 addr = (void *)(((uintptr_t)addr) +
394 rte_memcpy(addr, &missed_item,
395 missed * sizeof(*item));
396 addr = (void *)(((uintptr_t)addr) +
397 missed * sizeof(*item));
398 rte_memcpy(addr, flow_items, n);
399 addr = (void *)(((uintptr_t)addr) + n);
402 if (!node->optional && node->next) {
403 next_node = node->next;
404 if (stack_pos++ == MLX5_RSS_EXP_ELT_N) {
408 stack[stack_pos] = next_node;
409 } else if (*(next_node + 1)) {
410 /* Follow up with the next possibility. */
413 /* Move to the next path. */
415 next_node = stack[--stack_pos];
417 stack[stack_pos] = next_node;
419 node = *next_node ? &graph[*next_node] : NULL;
424 enum mlx5_expansion {
426 MLX5_EXPANSION_ROOT_OUTER,
427 MLX5_EXPANSION_ROOT_ETH_VLAN,
428 MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN,
429 MLX5_EXPANSION_OUTER_ETH,
430 MLX5_EXPANSION_OUTER_ETH_VLAN,
431 MLX5_EXPANSION_OUTER_VLAN,
432 MLX5_EXPANSION_OUTER_IPV4,
433 MLX5_EXPANSION_OUTER_IPV4_UDP,
434 MLX5_EXPANSION_OUTER_IPV4_TCP,
435 MLX5_EXPANSION_OUTER_IPV6,
436 MLX5_EXPANSION_OUTER_IPV6_UDP,
437 MLX5_EXPANSION_OUTER_IPV6_TCP,
438 MLX5_EXPANSION_VXLAN,
439 MLX5_EXPANSION_VXLAN_GPE,
441 MLX5_EXPANSION_NVGRE,
442 MLX5_EXPANSION_GRE_KEY,
445 MLX5_EXPANSION_ETH_VLAN,
448 MLX5_EXPANSION_IPV4_UDP,
449 MLX5_EXPANSION_IPV4_TCP,
451 MLX5_EXPANSION_IPV6_UDP,
452 MLX5_EXPANSION_IPV6_TCP,
455 /** Supported expansion of items. */
456 static const struct mlx5_flow_expand_node mlx5_support_expansion[] = {
457 [MLX5_EXPANSION_ROOT] = {
458 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
460 MLX5_EXPANSION_IPV6),
461 .type = RTE_FLOW_ITEM_TYPE_END,
463 [MLX5_EXPANSION_ROOT_OUTER] = {
464 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_ETH,
465 MLX5_EXPANSION_OUTER_IPV4,
466 MLX5_EXPANSION_OUTER_IPV6),
467 .type = RTE_FLOW_ITEM_TYPE_END,
469 [MLX5_EXPANSION_ROOT_ETH_VLAN] = {
470 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH_VLAN),
471 .type = RTE_FLOW_ITEM_TYPE_END,
473 [MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN] = {
474 .next = MLX5_FLOW_EXPAND_RSS_NEXT
475 (MLX5_EXPANSION_OUTER_ETH_VLAN),
476 .type = RTE_FLOW_ITEM_TYPE_END,
478 [MLX5_EXPANSION_OUTER_ETH] = {
479 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_IPV4,
480 MLX5_EXPANSION_OUTER_IPV6,
481 MLX5_EXPANSION_MPLS),
482 .type = RTE_FLOW_ITEM_TYPE_ETH,
485 [MLX5_EXPANSION_OUTER_ETH_VLAN] = {
486 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_VLAN),
487 .type = RTE_FLOW_ITEM_TYPE_ETH,
490 [MLX5_EXPANSION_OUTER_VLAN] = {
491 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_IPV4,
492 MLX5_EXPANSION_OUTER_IPV6),
493 .type = RTE_FLOW_ITEM_TYPE_VLAN,
495 [MLX5_EXPANSION_OUTER_IPV4] = {
496 .next = MLX5_FLOW_EXPAND_RSS_NEXT
497 (MLX5_EXPANSION_OUTER_IPV4_UDP,
498 MLX5_EXPANSION_OUTER_IPV4_TCP,
500 MLX5_EXPANSION_NVGRE,
502 MLX5_EXPANSION_IPV6),
503 .type = RTE_FLOW_ITEM_TYPE_IPV4,
504 .rss_types = ETH_RSS_IPV4 | ETH_RSS_FRAG_IPV4 |
505 ETH_RSS_NONFRAG_IPV4_OTHER,
507 [MLX5_EXPANSION_OUTER_IPV4_UDP] = {
508 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VXLAN,
509 MLX5_EXPANSION_VXLAN_GPE),
510 .type = RTE_FLOW_ITEM_TYPE_UDP,
511 .rss_types = ETH_RSS_NONFRAG_IPV4_UDP,
513 [MLX5_EXPANSION_OUTER_IPV4_TCP] = {
514 .type = RTE_FLOW_ITEM_TYPE_TCP,
515 .rss_types = ETH_RSS_NONFRAG_IPV4_TCP,
517 [MLX5_EXPANSION_OUTER_IPV6] = {
518 .next = MLX5_FLOW_EXPAND_RSS_NEXT
519 (MLX5_EXPANSION_OUTER_IPV6_UDP,
520 MLX5_EXPANSION_OUTER_IPV6_TCP,
524 MLX5_EXPANSION_NVGRE),
525 .type = RTE_FLOW_ITEM_TYPE_IPV6,
526 .rss_types = ETH_RSS_IPV6 | ETH_RSS_FRAG_IPV6 |
527 ETH_RSS_NONFRAG_IPV6_OTHER,
529 [MLX5_EXPANSION_OUTER_IPV6_UDP] = {
530 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VXLAN,
531 MLX5_EXPANSION_VXLAN_GPE),
532 .type = RTE_FLOW_ITEM_TYPE_UDP,
533 .rss_types = ETH_RSS_NONFRAG_IPV6_UDP,
535 [MLX5_EXPANSION_OUTER_IPV6_TCP] = {
536 .type = RTE_FLOW_ITEM_TYPE_TCP,
537 .rss_types = ETH_RSS_NONFRAG_IPV6_TCP,
539 [MLX5_EXPANSION_VXLAN] = {
540 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
542 MLX5_EXPANSION_IPV6),
543 .type = RTE_FLOW_ITEM_TYPE_VXLAN,
545 [MLX5_EXPANSION_VXLAN_GPE] = {
546 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
548 MLX5_EXPANSION_IPV6),
549 .type = RTE_FLOW_ITEM_TYPE_VXLAN_GPE,
551 [MLX5_EXPANSION_GRE] = {
552 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
554 MLX5_EXPANSION_GRE_KEY),
555 .type = RTE_FLOW_ITEM_TYPE_GRE,
557 [MLX5_EXPANSION_GRE_KEY] = {
558 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
559 MLX5_EXPANSION_IPV6),
560 .type = RTE_FLOW_ITEM_TYPE_GRE_KEY,
563 [MLX5_EXPANSION_NVGRE] = {
564 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH),
565 .type = RTE_FLOW_ITEM_TYPE_NVGRE,
567 [MLX5_EXPANSION_MPLS] = {
568 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
569 MLX5_EXPANSION_IPV6),
570 .type = RTE_FLOW_ITEM_TYPE_MPLS,
572 [MLX5_EXPANSION_ETH] = {
573 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
574 MLX5_EXPANSION_IPV6),
575 .type = RTE_FLOW_ITEM_TYPE_ETH,
577 [MLX5_EXPANSION_ETH_VLAN] = {
578 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VLAN),
579 .type = RTE_FLOW_ITEM_TYPE_ETH,
581 [MLX5_EXPANSION_VLAN] = {
582 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
583 MLX5_EXPANSION_IPV6),
584 .type = RTE_FLOW_ITEM_TYPE_VLAN,
586 [MLX5_EXPANSION_IPV4] = {
587 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4_UDP,
588 MLX5_EXPANSION_IPV4_TCP),
589 .type = RTE_FLOW_ITEM_TYPE_IPV4,
590 .rss_types = ETH_RSS_IPV4 | ETH_RSS_FRAG_IPV4 |
591 ETH_RSS_NONFRAG_IPV4_OTHER,
593 [MLX5_EXPANSION_IPV4_UDP] = {
594 .type = RTE_FLOW_ITEM_TYPE_UDP,
595 .rss_types = ETH_RSS_NONFRAG_IPV4_UDP,
597 [MLX5_EXPANSION_IPV4_TCP] = {
598 .type = RTE_FLOW_ITEM_TYPE_TCP,
599 .rss_types = ETH_RSS_NONFRAG_IPV4_TCP,
601 [MLX5_EXPANSION_IPV6] = {
602 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV6_UDP,
603 MLX5_EXPANSION_IPV6_TCP),
604 .type = RTE_FLOW_ITEM_TYPE_IPV6,
605 .rss_types = ETH_RSS_IPV6 | ETH_RSS_FRAG_IPV6 |
606 ETH_RSS_NONFRAG_IPV6_OTHER,
608 [MLX5_EXPANSION_IPV6_UDP] = {
609 .type = RTE_FLOW_ITEM_TYPE_UDP,
610 .rss_types = ETH_RSS_NONFRAG_IPV6_UDP,
612 [MLX5_EXPANSION_IPV6_TCP] = {
613 .type = RTE_FLOW_ITEM_TYPE_TCP,
614 .rss_types = ETH_RSS_NONFRAG_IPV6_TCP,
618 static struct rte_flow_action_handle *
619 mlx5_action_handle_create(struct rte_eth_dev *dev,
620 const struct rte_flow_indir_action_conf *conf,
621 const struct rte_flow_action *action,
622 struct rte_flow_error *error);
623 static int mlx5_action_handle_destroy
624 (struct rte_eth_dev *dev,
625 struct rte_flow_action_handle *handle,
626 struct rte_flow_error *error);
627 static int mlx5_action_handle_update
628 (struct rte_eth_dev *dev,
629 struct rte_flow_action_handle *handle,
631 struct rte_flow_error *error);
632 static int mlx5_action_handle_query
633 (struct rte_eth_dev *dev,
634 const struct rte_flow_action_handle *handle,
636 struct rte_flow_error *error);
638 mlx5_flow_tunnel_decap_set(struct rte_eth_dev *dev,
639 struct rte_flow_tunnel *app_tunnel,
640 struct rte_flow_action **actions,
641 uint32_t *num_of_actions,
642 struct rte_flow_error *error);
644 mlx5_flow_tunnel_match(struct rte_eth_dev *dev,
645 struct rte_flow_tunnel *app_tunnel,
646 struct rte_flow_item **items,
647 uint32_t *num_of_items,
648 struct rte_flow_error *error);
650 mlx5_flow_tunnel_item_release(struct rte_eth_dev *dev,
651 struct rte_flow_item *pmd_items,
652 uint32_t num_items, struct rte_flow_error *err);
654 mlx5_flow_tunnel_action_release(struct rte_eth_dev *dev,
655 struct rte_flow_action *pmd_actions,
656 uint32_t num_actions,
657 struct rte_flow_error *err);
659 mlx5_flow_tunnel_get_restore_info(struct rte_eth_dev *dev,
661 struct rte_flow_restore_info *info,
662 struct rte_flow_error *err);
664 static const struct rte_flow_ops mlx5_flow_ops = {
665 .validate = mlx5_flow_validate,
666 .create = mlx5_flow_create,
667 .destroy = mlx5_flow_destroy,
668 .flush = mlx5_flow_flush,
669 .isolate = mlx5_flow_isolate,
670 .query = mlx5_flow_query,
671 .dev_dump = mlx5_flow_dev_dump,
672 .get_aged_flows = mlx5_flow_get_aged_flows,
673 .action_handle_create = mlx5_action_handle_create,
674 .action_handle_destroy = mlx5_action_handle_destroy,
675 .action_handle_update = mlx5_action_handle_update,
676 .action_handle_query = mlx5_action_handle_query,
677 .tunnel_decap_set = mlx5_flow_tunnel_decap_set,
678 .tunnel_match = mlx5_flow_tunnel_match,
679 .tunnel_action_decap_release = mlx5_flow_tunnel_action_release,
680 .tunnel_item_release = mlx5_flow_tunnel_item_release,
681 .get_restore_info = mlx5_flow_tunnel_get_restore_info,
684 /* Tunnel information. */
685 struct mlx5_flow_tunnel_info {
686 uint64_t tunnel; /**< Tunnel bit (see MLX5_FLOW_*). */
687 uint32_t ptype; /**< Tunnel Ptype (see RTE_PTYPE_*). */
690 static struct mlx5_flow_tunnel_info tunnels_info[] = {
692 .tunnel = MLX5_FLOW_LAYER_VXLAN,
693 .ptype = RTE_PTYPE_TUNNEL_VXLAN | RTE_PTYPE_L4_UDP,
696 .tunnel = MLX5_FLOW_LAYER_GENEVE,
697 .ptype = RTE_PTYPE_TUNNEL_GENEVE | RTE_PTYPE_L4_UDP,
700 .tunnel = MLX5_FLOW_LAYER_VXLAN_GPE,
701 .ptype = RTE_PTYPE_TUNNEL_VXLAN_GPE | RTE_PTYPE_L4_UDP,
704 .tunnel = MLX5_FLOW_LAYER_GRE,
705 .ptype = RTE_PTYPE_TUNNEL_GRE,
708 .tunnel = MLX5_FLOW_LAYER_MPLS | MLX5_FLOW_LAYER_OUTER_L4_UDP,
709 .ptype = RTE_PTYPE_TUNNEL_MPLS_IN_UDP | RTE_PTYPE_L4_UDP,
712 .tunnel = MLX5_FLOW_LAYER_MPLS,
713 .ptype = RTE_PTYPE_TUNNEL_MPLS_IN_GRE,
716 .tunnel = MLX5_FLOW_LAYER_NVGRE,
717 .ptype = RTE_PTYPE_TUNNEL_NVGRE,
720 .tunnel = MLX5_FLOW_LAYER_IPIP,
721 .ptype = RTE_PTYPE_TUNNEL_IP,
724 .tunnel = MLX5_FLOW_LAYER_IPV6_ENCAP,
725 .ptype = RTE_PTYPE_TUNNEL_IP,
728 .tunnel = MLX5_FLOW_LAYER_GTP,
729 .ptype = RTE_PTYPE_TUNNEL_GTPU,
736 * Translate tag ID to register.
739 * Pointer to the Ethernet device structure.
741 * The feature that request the register.
743 * The request register ID.
745 * Error description in case of any.
748 * The request register on success, a negative errno
749 * value otherwise and rte_errno is set.
752 mlx5_flow_get_reg_id(struct rte_eth_dev *dev,
753 enum mlx5_feature_name feature,
755 struct rte_flow_error *error)
757 struct mlx5_priv *priv = dev->data->dev_private;
758 struct mlx5_dev_config *config = &priv->config;
759 enum modify_reg start_reg;
760 bool skip_mtr_reg = false;
763 case MLX5_HAIRPIN_RX:
765 case MLX5_HAIRPIN_TX:
767 case MLX5_METADATA_RX:
768 switch (config->dv_xmeta_en) {
769 case MLX5_XMETA_MODE_LEGACY:
771 case MLX5_XMETA_MODE_META16:
773 case MLX5_XMETA_MODE_META32:
777 case MLX5_METADATA_TX:
779 case MLX5_METADATA_FDB:
780 switch (config->dv_xmeta_en) {
781 case MLX5_XMETA_MODE_LEGACY:
783 case MLX5_XMETA_MODE_META16:
785 case MLX5_XMETA_MODE_META32:
790 switch (config->dv_xmeta_en) {
791 case MLX5_XMETA_MODE_LEGACY:
793 case MLX5_XMETA_MODE_META16:
795 case MLX5_XMETA_MODE_META32:
801 * If meter color and meter id share one register, flow match
802 * should use the meter color register for match.
804 if (priv->mtr_reg_share)
805 return priv->mtr_color_reg;
807 return priv->mtr_color_reg != REG_C_2 ? REG_C_2 :
810 case MLX5_ASO_FLOW_HIT:
811 case MLX5_ASO_CONNTRACK:
812 /* All features use the same REG_C. */
813 MLX5_ASSERT(priv->mtr_color_reg != REG_NON);
814 return priv->mtr_color_reg;
817 * Metadata COPY_MARK register using is in meter suffix sub
818 * flow while with meter. It's safe to share the same register.
820 return priv->mtr_color_reg != REG_C_2 ? REG_C_2 : REG_C_3;
823 * If meter is enable, it will engage the register for color
824 * match and flow match. If meter color match is not using the
825 * REG_C_2, need to skip the REG_C_x be used by meter color
827 * If meter is disable, free to use all available registers.
829 start_reg = priv->mtr_color_reg != REG_C_2 ? REG_C_2 :
830 (priv->mtr_reg_share ? REG_C_3 : REG_C_4);
831 skip_mtr_reg = !!(priv->mtr_en && start_reg == REG_C_2);
832 if (id > (uint32_t)(REG_C_7 - start_reg))
833 return rte_flow_error_set(error, EINVAL,
834 RTE_FLOW_ERROR_TYPE_ITEM,
835 NULL, "invalid tag id");
836 if (config->flow_mreg_c[id + start_reg - REG_C_0] == REG_NON)
837 return rte_flow_error_set(error, ENOTSUP,
838 RTE_FLOW_ERROR_TYPE_ITEM,
839 NULL, "unsupported tag id");
841 * This case means meter is using the REG_C_x great than 2.
842 * Take care not to conflict with meter color REG_C_x.
843 * If the available index REG_C_y >= REG_C_x, skip the
846 if (skip_mtr_reg && config->flow_mreg_c
847 [id + start_reg - REG_C_0] >= priv->mtr_color_reg) {
848 if (id >= (uint32_t)(REG_C_7 - start_reg))
849 return rte_flow_error_set(error, EINVAL,
850 RTE_FLOW_ERROR_TYPE_ITEM,
851 NULL, "invalid tag id");
852 if (config->flow_mreg_c
853 [id + 1 + start_reg - REG_C_0] != REG_NON)
854 return config->flow_mreg_c
855 [id + 1 + start_reg - REG_C_0];
856 return rte_flow_error_set(error, ENOTSUP,
857 RTE_FLOW_ERROR_TYPE_ITEM,
858 NULL, "unsupported tag id");
860 return config->flow_mreg_c[id + start_reg - REG_C_0];
863 return rte_flow_error_set(error, EINVAL,
864 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
865 NULL, "invalid feature name");
869 * Check extensive flow metadata register support.
872 * Pointer to rte_eth_dev structure.
875 * True if device supports extensive flow metadata register, otherwise false.
878 mlx5_flow_ext_mreg_supported(struct rte_eth_dev *dev)
880 struct mlx5_priv *priv = dev->data->dev_private;
881 struct mlx5_dev_config *config = &priv->config;
884 * Having available reg_c can be regarded inclusively as supporting
885 * extensive flow metadata register, which could mean,
886 * - metadata register copy action by modify header.
887 * - 16 modify header actions is supported.
888 * - reg_c's are preserved across different domain (FDB and NIC) on
889 * packet loopback by flow lookup miss.
891 return config->flow_mreg_c[2] != REG_NON;
895 * Get the lowest priority.
898 * Pointer to the Ethernet device structure.
899 * @param[in] attributes
900 * Pointer to device flow rule attributes.
903 * The value of lowest priority of flow.
906 mlx5_get_lowest_priority(struct rte_eth_dev *dev,
907 const struct rte_flow_attr *attr)
909 struct mlx5_priv *priv = dev->data->dev_private;
911 if (!attr->group && !attr->transfer)
912 return priv->config.flow_prio - 2;
913 return MLX5_NON_ROOT_FLOW_MAX_PRIO - 1;
917 * Calculate matcher priority of the flow.
920 * Pointer to the Ethernet device structure.
922 * Pointer to device flow rule attributes.
923 * @param[in] subpriority
924 * The priority based on the items.
926 * The matcher priority of the flow.
929 mlx5_get_matcher_priority(struct rte_eth_dev *dev,
930 const struct rte_flow_attr *attr,
931 uint32_t subpriority)
933 uint16_t priority = (uint16_t)attr->priority;
934 struct mlx5_priv *priv = dev->data->dev_private;
936 if (!attr->group && !attr->transfer) {
937 if (attr->priority == MLX5_FLOW_LOWEST_PRIO_INDICATOR)
938 priority = priv->config.flow_prio - 1;
939 return mlx5_os_flow_adjust_priority(dev, priority, subpriority);
941 if (attr->priority == MLX5_FLOW_LOWEST_PRIO_INDICATOR)
942 priority = MLX5_NON_ROOT_FLOW_MAX_PRIO;
943 return priority * 3 + subpriority;
947 * Verify the @p item specifications (spec, last, mask) are compatible with the
951 * Item specification.
953 * @p item->mask or flow default bit-masks.
954 * @param[in] nic_mask
955 * Bit-masks covering supported fields by the NIC to compare with user mask.
957 * Bit-masks size in bytes.
958 * @param[in] range_accepted
959 * True if range of values is accepted for specific fields, false otherwise.
961 * Pointer to error structure.
964 * 0 on success, a negative errno value otherwise and rte_errno is set.
967 mlx5_flow_item_acceptable(const struct rte_flow_item *item,
969 const uint8_t *nic_mask,
972 struct rte_flow_error *error)
976 MLX5_ASSERT(nic_mask);
977 for (i = 0; i < size; ++i)
978 if ((nic_mask[i] | mask[i]) != nic_mask[i])
979 return rte_flow_error_set(error, ENOTSUP,
980 RTE_FLOW_ERROR_TYPE_ITEM,
982 "mask enables non supported"
984 if (!item->spec && (item->mask || item->last))
985 return rte_flow_error_set(error, EINVAL,
986 RTE_FLOW_ERROR_TYPE_ITEM, item,
987 "mask/last without a spec is not"
989 if (item->spec && item->last && !range_accepted) {
995 for (i = 0; i < size; ++i) {
996 spec[i] = ((const uint8_t *)item->spec)[i] & mask[i];
997 last[i] = ((const uint8_t *)item->last)[i] & mask[i];
999 ret = memcmp(spec, last, size);
1001 return rte_flow_error_set(error, EINVAL,
1002 RTE_FLOW_ERROR_TYPE_ITEM,
1004 "range is not valid");
1010 * Adjust the hash fields according to the @p flow information.
1012 * @param[in] dev_flow.
1013 * Pointer to the mlx5_flow.
1015 * 1 when the hash field is for a tunnel item.
1016 * @param[in] layer_types
1018 * @param[in] hash_fields
1022 * The hash fields that should be used.
1025 mlx5_flow_hashfields_adjust(struct mlx5_flow_rss_desc *rss_desc,
1026 int tunnel __rte_unused, uint64_t layer_types,
1027 uint64_t hash_fields)
1029 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
1030 int rss_request_inner = rss_desc->level >= 2;
1032 /* Check RSS hash level for tunnel. */
1033 if (tunnel && rss_request_inner)
1034 hash_fields |= IBV_RX_HASH_INNER;
1035 else if (tunnel || rss_request_inner)
1038 /* Check if requested layer matches RSS hash fields. */
1039 if (!(rss_desc->types & layer_types))
1045 * Lookup and set the ptype in the data Rx part. A single Ptype can be used,
1046 * if several tunnel rules are used on this queue, the tunnel ptype will be
1050 * Rx queue to update.
1053 flow_rxq_tunnel_ptype_update(struct mlx5_rxq_ctrl *rxq_ctrl)
1056 uint32_t tunnel_ptype = 0;
1058 /* Look up for the ptype to use. */
1059 for (i = 0; i != MLX5_FLOW_TUNNEL; ++i) {
1060 if (!rxq_ctrl->flow_tunnels_n[i])
1062 if (!tunnel_ptype) {
1063 tunnel_ptype = tunnels_info[i].ptype;
1069 rxq_ctrl->rxq.tunnel = tunnel_ptype;
1073 * Set the Rx queue flags (Mark/Flag and Tunnel Ptypes) according to the devive
1077 * Pointer to the Ethernet device structure.
1078 * @param[in] dev_handle
1079 * Pointer to device flow handle structure.
1082 flow_drv_rxq_flags_set(struct rte_eth_dev *dev,
1083 struct mlx5_flow_handle *dev_handle)
1085 struct mlx5_priv *priv = dev->data->dev_private;
1086 const int mark = dev_handle->mark;
1087 const int tunnel = !!(dev_handle->layers & MLX5_FLOW_LAYER_TUNNEL);
1088 struct mlx5_ind_table_obj *ind_tbl = NULL;
1091 if (dev_handle->fate_action == MLX5_FLOW_FATE_QUEUE) {
1092 struct mlx5_hrxq *hrxq;
1094 hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
1095 dev_handle->rix_hrxq);
1097 ind_tbl = hrxq->ind_table;
1098 } else if (dev_handle->fate_action == MLX5_FLOW_FATE_SHARED_RSS) {
1099 struct mlx5_shared_action_rss *shared_rss;
1101 shared_rss = mlx5_ipool_get
1102 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
1103 dev_handle->rix_srss);
1105 ind_tbl = shared_rss->ind_tbl;
1109 for (i = 0; i != ind_tbl->queues_n; ++i) {
1110 int idx = ind_tbl->queues[i];
1111 struct mlx5_rxq_ctrl *rxq_ctrl =
1112 container_of((*priv->rxqs)[idx],
1113 struct mlx5_rxq_ctrl, rxq);
1116 * To support metadata register copy on Tx loopback,
1117 * this must be always enabled (metadata may arive
1118 * from other port - not from local flows only.
1120 if (priv->config.dv_flow_en &&
1121 priv->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
1122 mlx5_flow_ext_mreg_supported(dev)) {
1123 rxq_ctrl->rxq.mark = 1;
1124 rxq_ctrl->flow_mark_n = 1;
1126 rxq_ctrl->rxq.mark = 1;
1127 rxq_ctrl->flow_mark_n++;
1132 /* Increase the counter matching the flow. */
1133 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j) {
1134 if ((tunnels_info[j].tunnel &
1135 dev_handle->layers) ==
1136 tunnels_info[j].tunnel) {
1137 rxq_ctrl->flow_tunnels_n[j]++;
1141 flow_rxq_tunnel_ptype_update(rxq_ctrl);
1147 * Set the Rx queue flags (Mark/Flag and Tunnel Ptypes) for a flow
1150 * Pointer to the Ethernet device structure.
1152 * Pointer to flow structure.
1155 flow_rxq_flags_set(struct rte_eth_dev *dev, struct rte_flow *flow)
1157 struct mlx5_priv *priv = dev->data->dev_private;
1158 uint32_t handle_idx;
1159 struct mlx5_flow_handle *dev_handle;
1161 SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
1162 handle_idx, dev_handle, next)
1163 flow_drv_rxq_flags_set(dev, dev_handle);
1167 * Clear the Rx queue flags (Mark/Flag and Tunnel Ptype) associated with the
1168 * device flow if no other flow uses it with the same kind of request.
1171 * Pointer to Ethernet device.
1172 * @param[in] dev_handle
1173 * Pointer to the device flow handle structure.
1176 flow_drv_rxq_flags_trim(struct rte_eth_dev *dev,
1177 struct mlx5_flow_handle *dev_handle)
1179 struct mlx5_priv *priv = dev->data->dev_private;
1180 const int mark = dev_handle->mark;
1181 const int tunnel = !!(dev_handle->layers & MLX5_FLOW_LAYER_TUNNEL);
1182 struct mlx5_ind_table_obj *ind_tbl = NULL;
1185 if (dev_handle->fate_action == MLX5_FLOW_FATE_QUEUE) {
1186 struct mlx5_hrxq *hrxq;
1188 hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
1189 dev_handle->rix_hrxq);
1191 ind_tbl = hrxq->ind_table;
1192 } else if (dev_handle->fate_action == MLX5_FLOW_FATE_SHARED_RSS) {
1193 struct mlx5_shared_action_rss *shared_rss;
1195 shared_rss = mlx5_ipool_get
1196 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
1197 dev_handle->rix_srss);
1199 ind_tbl = shared_rss->ind_tbl;
1203 MLX5_ASSERT(dev->data->dev_started);
1204 for (i = 0; i != ind_tbl->queues_n; ++i) {
1205 int idx = ind_tbl->queues[i];
1206 struct mlx5_rxq_ctrl *rxq_ctrl =
1207 container_of((*priv->rxqs)[idx],
1208 struct mlx5_rxq_ctrl, rxq);
1210 if (priv->config.dv_flow_en &&
1211 priv->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
1212 mlx5_flow_ext_mreg_supported(dev)) {
1213 rxq_ctrl->rxq.mark = 1;
1214 rxq_ctrl->flow_mark_n = 1;
1216 rxq_ctrl->flow_mark_n--;
1217 rxq_ctrl->rxq.mark = !!rxq_ctrl->flow_mark_n;
1222 /* Decrease the counter matching the flow. */
1223 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j) {
1224 if ((tunnels_info[j].tunnel &
1225 dev_handle->layers) ==
1226 tunnels_info[j].tunnel) {
1227 rxq_ctrl->flow_tunnels_n[j]--;
1231 flow_rxq_tunnel_ptype_update(rxq_ctrl);
1237 * Clear the Rx queue flags (Mark/Flag and Tunnel Ptype) associated with the
1238 * @p flow if no other flow uses it with the same kind of request.
1241 * Pointer to Ethernet device.
1243 * Pointer to the flow.
1246 flow_rxq_flags_trim(struct rte_eth_dev *dev, struct rte_flow *flow)
1248 struct mlx5_priv *priv = dev->data->dev_private;
1249 uint32_t handle_idx;
1250 struct mlx5_flow_handle *dev_handle;
1252 SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
1253 handle_idx, dev_handle, next)
1254 flow_drv_rxq_flags_trim(dev, dev_handle);
1258 * Clear the Mark/Flag and Tunnel ptype information in all Rx queues.
1261 * Pointer to Ethernet device.
1264 flow_rxq_flags_clear(struct rte_eth_dev *dev)
1266 struct mlx5_priv *priv = dev->data->dev_private;
1269 for (i = 0; i != priv->rxqs_n; ++i) {
1270 struct mlx5_rxq_ctrl *rxq_ctrl;
1273 if (!(*priv->rxqs)[i])
1275 rxq_ctrl = container_of((*priv->rxqs)[i],
1276 struct mlx5_rxq_ctrl, rxq);
1277 rxq_ctrl->flow_mark_n = 0;
1278 rxq_ctrl->rxq.mark = 0;
1279 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j)
1280 rxq_ctrl->flow_tunnels_n[j] = 0;
1281 rxq_ctrl->rxq.tunnel = 0;
1286 * Set the Rx queue dynamic metadata (mask and offset) for a flow
1289 * Pointer to the Ethernet device structure.
1292 mlx5_flow_rxq_dynf_metadata_set(struct rte_eth_dev *dev)
1294 struct mlx5_priv *priv = dev->data->dev_private;
1295 struct mlx5_rxq_data *data;
1298 for (i = 0; i != priv->rxqs_n; ++i) {
1299 if (!(*priv->rxqs)[i])
1301 data = (*priv->rxqs)[i];
1302 if (!rte_flow_dynf_metadata_avail()) {
1303 data->dynf_meta = 0;
1304 data->flow_meta_mask = 0;
1305 data->flow_meta_offset = -1;
1306 data->flow_meta_port_mask = 0;
1308 data->dynf_meta = 1;
1309 data->flow_meta_mask = rte_flow_dynf_metadata_mask;
1310 data->flow_meta_offset = rte_flow_dynf_metadata_offs;
1311 data->flow_meta_port_mask = (uint32_t)~0;
1312 if (priv->config.dv_xmeta_en == MLX5_XMETA_MODE_META16)
1313 data->flow_meta_port_mask >>= 16;
1319 * return a pointer to the desired action in the list of actions.
1321 * @param[in] actions
1322 * The list of actions to search the action in.
1324 * The action to find.
1327 * Pointer to the action in the list, if found. NULL otherwise.
1329 const struct rte_flow_action *
1330 mlx5_flow_find_action(const struct rte_flow_action *actions,
1331 enum rte_flow_action_type action)
1333 if (actions == NULL)
1335 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++)
1336 if (actions->type == action)
1342 * Validate the flag action.
1344 * @param[in] action_flags
1345 * Bit-fields that holds the actions detected until now.
1347 * Attributes of flow that includes this action.
1349 * Pointer to error structure.
1352 * 0 on success, a negative errno value otherwise and rte_errno is set.
1355 mlx5_flow_validate_action_flag(uint64_t action_flags,
1356 const struct rte_flow_attr *attr,
1357 struct rte_flow_error *error)
1359 if (action_flags & MLX5_FLOW_ACTION_MARK)
1360 return rte_flow_error_set(error, EINVAL,
1361 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1362 "can't mark and flag in same flow");
1363 if (action_flags & MLX5_FLOW_ACTION_FLAG)
1364 return rte_flow_error_set(error, EINVAL,
1365 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1367 " actions in same flow");
1369 return rte_flow_error_set(error, ENOTSUP,
1370 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1371 "flag action not supported for "
1377 * Validate the mark action.
1380 * Pointer to the queue action.
1381 * @param[in] action_flags
1382 * Bit-fields that holds the actions detected until now.
1384 * Attributes of flow that includes this action.
1386 * Pointer to error structure.
1389 * 0 on success, a negative errno value otherwise and rte_errno is set.
1392 mlx5_flow_validate_action_mark(const struct rte_flow_action *action,
1393 uint64_t action_flags,
1394 const struct rte_flow_attr *attr,
1395 struct rte_flow_error *error)
1397 const struct rte_flow_action_mark *mark = action->conf;
1400 return rte_flow_error_set(error, EINVAL,
1401 RTE_FLOW_ERROR_TYPE_ACTION,
1403 "configuration cannot be null");
1404 if (mark->id >= MLX5_FLOW_MARK_MAX)
1405 return rte_flow_error_set(error, EINVAL,
1406 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1408 "mark id must in 0 <= id < "
1409 RTE_STR(MLX5_FLOW_MARK_MAX));
1410 if (action_flags & MLX5_FLOW_ACTION_FLAG)
1411 return rte_flow_error_set(error, EINVAL,
1412 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1413 "can't flag and mark in same flow");
1414 if (action_flags & MLX5_FLOW_ACTION_MARK)
1415 return rte_flow_error_set(error, EINVAL,
1416 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1417 "can't have 2 mark actions in same"
1420 return rte_flow_error_set(error, ENOTSUP,
1421 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1422 "mark action not supported for "
1428 * Validate the drop action.
1430 * @param[in] action_flags
1431 * Bit-fields that holds the actions detected until now.
1433 * Attributes of flow that includes this action.
1435 * Pointer to error structure.
1438 * 0 on success, a negative errno value otherwise and rte_errno is set.
1441 mlx5_flow_validate_action_drop(uint64_t action_flags __rte_unused,
1442 const struct rte_flow_attr *attr,
1443 struct rte_flow_error *error)
1446 return rte_flow_error_set(error, ENOTSUP,
1447 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1448 "drop action not supported for "
1454 * Validate the queue action.
1457 * Pointer to the queue action.
1458 * @param[in] action_flags
1459 * Bit-fields that holds the actions detected until now.
1461 * Pointer to the Ethernet device structure.
1463 * Attributes of flow that includes this action.
1465 * Pointer to error structure.
1468 * 0 on success, a negative errno value otherwise and rte_errno is set.
1471 mlx5_flow_validate_action_queue(const struct rte_flow_action *action,
1472 uint64_t action_flags,
1473 struct rte_eth_dev *dev,
1474 const struct rte_flow_attr *attr,
1475 struct rte_flow_error *error)
1477 struct mlx5_priv *priv = dev->data->dev_private;
1478 const struct rte_flow_action_queue *queue = action->conf;
1480 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
1481 return rte_flow_error_set(error, EINVAL,
1482 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1483 "can't have 2 fate actions in"
1486 return rte_flow_error_set(error, EINVAL,
1487 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1488 NULL, "No Rx queues configured");
1489 if (queue->index >= priv->rxqs_n)
1490 return rte_flow_error_set(error, EINVAL,
1491 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1493 "queue index out of range");
1494 if (!(*priv->rxqs)[queue->index])
1495 return rte_flow_error_set(error, EINVAL,
1496 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1498 "queue is not configured");
1500 return rte_flow_error_set(error, ENOTSUP,
1501 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1502 "queue action not supported for "
1508 * Validate the rss action.
1511 * Pointer to the Ethernet device structure.
1513 * Pointer to the queue action.
1515 * Pointer to error structure.
1518 * 0 on success, a negative errno value otherwise and rte_errno is set.
1521 mlx5_validate_action_rss(struct rte_eth_dev *dev,
1522 const struct rte_flow_action *action,
1523 struct rte_flow_error *error)
1525 struct mlx5_priv *priv = dev->data->dev_private;
1526 const struct rte_flow_action_rss *rss = action->conf;
1527 enum mlx5_rxq_type rxq_type = MLX5_RXQ_TYPE_UNDEFINED;
1530 if (rss->func != RTE_ETH_HASH_FUNCTION_DEFAULT &&
1531 rss->func != RTE_ETH_HASH_FUNCTION_TOEPLITZ)
1532 return rte_flow_error_set(error, ENOTSUP,
1533 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1535 "RSS hash function not supported");
1536 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
1541 return rte_flow_error_set(error, ENOTSUP,
1542 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1544 "tunnel RSS is not supported");
1545 /* allow RSS key_len 0 in case of NULL (default) RSS key. */
1546 if (rss->key_len == 0 && rss->key != NULL)
1547 return rte_flow_error_set(error, ENOTSUP,
1548 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1550 "RSS hash key length 0");
1551 if (rss->key_len > 0 && rss->key_len < MLX5_RSS_HASH_KEY_LEN)
1552 return rte_flow_error_set(error, ENOTSUP,
1553 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1555 "RSS hash key too small");
1556 if (rss->key_len > MLX5_RSS_HASH_KEY_LEN)
1557 return rte_flow_error_set(error, ENOTSUP,
1558 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1560 "RSS hash key too large");
1561 if (rss->queue_num > priv->config.ind_table_max_size)
1562 return rte_flow_error_set(error, ENOTSUP,
1563 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1565 "number of queues too large");
1566 if (rss->types & MLX5_RSS_HF_MASK)
1567 return rte_flow_error_set(error, ENOTSUP,
1568 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1570 "some RSS protocols are not"
1572 if ((rss->types & (ETH_RSS_L3_SRC_ONLY | ETH_RSS_L3_DST_ONLY)) &&
1573 !(rss->types & ETH_RSS_IP))
1574 return rte_flow_error_set(error, EINVAL,
1575 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1576 "L3 partial RSS requested but L3 RSS"
1577 " type not specified");
1578 if ((rss->types & (ETH_RSS_L4_SRC_ONLY | ETH_RSS_L4_DST_ONLY)) &&
1579 !(rss->types & (ETH_RSS_UDP | ETH_RSS_TCP)))
1580 return rte_flow_error_set(error, EINVAL,
1581 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1582 "L4 partial RSS requested but L4 RSS"
1583 " type not specified");
1585 return rte_flow_error_set(error, EINVAL,
1586 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1587 NULL, "No Rx queues configured");
1588 if (!rss->queue_num)
1589 return rte_flow_error_set(error, EINVAL,
1590 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1591 NULL, "No queues configured");
1592 for (i = 0; i != rss->queue_num; ++i) {
1593 struct mlx5_rxq_ctrl *rxq_ctrl;
1595 if (rss->queue[i] >= priv->rxqs_n)
1596 return rte_flow_error_set
1598 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1599 &rss->queue[i], "queue index out of range");
1600 if (!(*priv->rxqs)[rss->queue[i]])
1601 return rte_flow_error_set
1602 (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1603 &rss->queue[i], "queue is not configured");
1604 rxq_ctrl = container_of((*priv->rxqs)[rss->queue[i]],
1605 struct mlx5_rxq_ctrl, rxq);
1607 rxq_type = rxq_ctrl->type;
1608 if (rxq_type != rxq_ctrl->type)
1609 return rte_flow_error_set
1610 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1612 "combining hairpin and regular RSS queues is not supported");
1618 * Validate the rss action.
1621 * Pointer to the queue action.
1622 * @param[in] action_flags
1623 * Bit-fields that holds the actions detected until now.
1625 * Pointer to the Ethernet device structure.
1627 * Attributes of flow that includes this action.
1628 * @param[in] item_flags
1629 * Items that were detected.
1631 * Pointer to error structure.
1634 * 0 on success, a negative errno value otherwise and rte_errno is set.
1637 mlx5_flow_validate_action_rss(const struct rte_flow_action *action,
1638 uint64_t action_flags,
1639 struct rte_eth_dev *dev,
1640 const struct rte_flow_attr *attr,
1641 uint64_t item_flags,
1642 struct rte_flow_error *error)
1644 const struct rte_flow_action_rss *rss = action->conf;
1645 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1648 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
1649 return rte_flow_error_set(error, EINVAL,
1650 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1651 "can't have 2 fate actions"
1653 ret = mlx5_validate_action_rss(dev, action, error);
1657 return rte_flow_error_set(error, ENOTSUP,
1658 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1659 "rss action not supported for "
1661 if (rss->level > 1 && !tunnel)
1662 return rte_flow_error_set(error, EINVAL,
1663 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1664 "inner RSS is not supported for "
1665 "non-tunnel flows");
1666 if ((item_flags & MLX5_FLOW_LAYER_ECPRI) &&
1667 !(item_flags & MLX5_FLOW_LAYER_INNER_L4_UDP)) {
1668 return rte_flow_error_set(error, EINVAL,
1669 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1670 "RSS on eCPRI is not supported now");
1676 * Validate the default miss action.
1678 * @param[in] action_flags
1679 * Bit-fields that holds the actions detected until now.
1681 * Pointer to error structure.
1684 * 0 on success, a negative errno value otherwise and rte_errno is set.
1687 mlx5_flow_validate_action_default_miss(uint64_t action_flags,
1688 const struct rte_flow_attr *attr,
1689 struct rte_flow_error *error)
1691 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
1692 return rte_flow_error_set(error, EINVAL,
1693 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1694 "can't have 2 fate actions in"
1697 return rte_flow_error_set(error, ENOTSUP,
1698 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1699 "default miss action not supported "
1702 return rte_flow_error_set(error, ENOTSUP,
1703 RTE_FLOW_ERROR_TYPE_ATTR_GROUP, NULL,
1704 "only group 0 is supported");
1706 return rte_flow_error_set(error, ENOTSUP,
1707 RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
1708 NULL, "transfer is not supported");
1713 * Validate the count action.
1716 * Pointer to the Ethernet device structure.
1718 * Attributes of flow that includes this action.
1720 * Pointer to error structure.
1723 * 0 on success, a negative errno value otherwise and rte_errno is set.
1726 mlx5_flow_validate_action_count(struct rte_eth_dev *dev __rte_unused,
1727 const struct rte_flow_attr *attr,
1728 struct rte_flow_error *error)
1731 return rte_flow_error_set(error, ENOTSUP,
1732 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1733 "count action not supported for "
1739 * Validate the ASO CT action.
1742 * Pointer to the Ethernet device structure.
1743 * @param[in] conntrack
1744 * Pointer to the CT action profile.
1746 * Pointer to error structure.
1749 * 0 on success, a negative errno value otherwise and rte_errno is set.
1752 mlx5_validate_action_ct(struct rte_eth_dev *dev,
1753 const struct rte_flow_action_conntrack *conntrack,
1754 struct rte_flow_error *error)
1758 if (conntrack->state > RTE_FLOW_CONNTRACK_STATE_TIME_WAIT)
1759 return rte_flow_error_set(error, EINVAL,
1760 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1761 "Invalid CT state");
1762 if (conntrack->last_index > RTE_FLOW_CONNTRACK_FLAG_RST)
1763 return rte_flow_error_set(error, EINVAL,
1764 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1765 "Invalid last TCP packet flag");
1770 * Verify the @p attributes will be correctly understood by the NIC and store
1771 * them in the @p flow if everything is correct.
1774 * Pointer to the Ethernet device structure.
1775 * @param[in] attributes
1776 * Pointer to flow attributes
1778 * Pointer to error structure.
1781 * 0 on success, a negative errno value otherwise and rte_errno is set.
1784 mlx5_flow_validate_attributes(struct rte_eth_dev *dev,
1785 const struct rte_flow_attr *attributes,
1786 struct rte_flow_error *error)
1788 struct mlx5_priv *priv = dev->data->dev_private;
1789 uint32_t priority_max = priv->config.flow_prio - 1;
1791 if (attributes->group)
1792 return rte_flow_error_set(error, ENOTSUP,
1793 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
1794 NULL, "groups is not supported");
1795 if (attributes->priority != MLX5_FLOW_LOWEST_PRIO_INDICATOR &&
1796 attributes->priority >= priority_max)
1797 return rte_flow_error_set(error, ENOTSUP,
1798 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
1799 NULL, "priority out of range");
1800 if (attributes->egress)
1801 return rte_flow_error_set(error, ENOTSUP,
1802 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1803 "egress is not supported");
1804 if (attributes->transfer && !priv->config.dv_esw_en)
1805 return rte_flow_error_set(error, ENOTSUP,
1806 RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
1807 NULL, "transfer is not supported");
1808 if (!attributes->ingress)
1809 return rte_flow_error_set(error, EINVAL,
1810 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
1812 "ingress attribute is mandatory");
1817 * Validate ICMP6 item.
1820 * Item specification.
1821 * @param[in] item_flags
1822 * Bit-fields that holds the items detected until now.
1823 * @param[in] ext_vlan_sup
1824 * Whether extended VLAN features are supported or not.
1826 * Pointer to error structure.
1829 * 0 on success, a negative errno value otherwise and rte_errno is set.
1832 mlx5_flow_validate_item_icmp6(const struct rte_flow_item *item,
1833 uint64_t item_flags,
1834 uint8_t target_protocol,
1835 struct rte_flow_error *error)
1837 const struct rte_flow_item_icmp6 *mask = item->mask;
1838 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1839 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
1840 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
1841 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1842 MLX5_FLOW_LAYER_OUTER_L4;
1845 if (target_protocol != 0xFF && target_protocol != IPPROTO_ICMPV6)
1846 return rte_flow_error_set(error, EINVAL,
1847 RTE_FLOW_ERROR_TYPE_ITEM, item,
1848 "protocol filtering not compatible"
1849 " with ICMP6 layer");
1850 if (!(item_flags & l3m))
1851 return rte_flow_error_set(error, EINVAL,
1852 RTE_FLOW_ERROR_TYPE_ITEM, item,
1853 "IPv6 is mandatory to filter on"
1855 if (item_flags & l4m)
1856 return rte_flow_error_set(error, EINVAL,
1857 RTE_FLOW_ERROR_TYPE_ITEM, item,
1858 "multiple L4 layers not supported");
1860 mask = &rte_flow_item_icmp6_mask;
1861 ret = mlx5_flow_item_acceptable
1862 (item, (const uint8_t *)mask,
1863 (const uint8_t *)&rte_flow_item_icmp6_mask,
1864 sizeof(struct rte_flow_item_icmp6),
1865 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
1872 * Validate ICMP item.
1875 * Item specification.
1876 * @param[in] item_flags
1877 * Bit-fields that holds the items detected until now.
1879 * Pointer to error structure.
1882 * 0 on success, a negative errno value otherwise and rte_errno is set.
1885 mlx5_flow_validate_item_icmp(const struct rte_flow_item *item,
1886 uint64_t item_flags,
1887 uint8_t target_protocol,
1888 struct rte_flow_error *error)
1890 const struct rte_flow_item_icmp *mask = item->mask;
1891 const struct rte_flow_item_icmp nic_mask = {
1892 .hdr.icmp_type = 0xff,
1893 .hdr.icmp_code = 0xff,
1894 .hdr.icmp_ident = RTE_BE16(0xffff),
1895 .hdr.icmp_seq_nb = RTE_BE16(0xffff),
1897 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1898 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
1899 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
1900 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1901 MLX5_FLOW_LAYER_OUTER_L4;
1904 if (target_protocol != 0xFF && target_protocol != IPPROTO_ICMP)
1905 return rte_flow_error_set(error, EINVAL,
1906 RTE_FLOW_ERROR_TYPE_ITEM, item,
1907 "protocol filtering not compatible"
1908 " with ICMP layer");
1909 if (!(item_flags & l3m))
1910 return rte_flow_error_set(error, EINVAL,
1911 RTE_FLOW_ERROR_TYPE_ITEM, item,
1912 "IPv4 is mandatory to filter"
1914 if (item_flags & l4m)
1915 return rte_flow_error_set(error, EINVAL,
1916 RTE_FLOW_ERROR_TYPE_ITEM, item,
1917 "multiple L4 layers not supported");
1920 ret = mlx5_flow_item_acceptable
1921 (item, (const uint8_t *)mask,
1922 (const uint8_t *)&nic_mask,
1923 sizeof(struct rte_flow_item_icmp),
1924 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
1931 * Validate Ethernet item.
1934 * Item specification.
1935 * @param[in] item_flags
1936 * Bit-fields that holds the items detected until now.
1938 * Pointer to error structure.
1941 * 0 on success, a negative errno value otherwise and rte_errno is set.
1944 mlx5_flow_validate_item_eth(const struct rte_flow_item *item,
1945 uint64_t item_flags, bool ext_vlan_sup,
1946 struct rte_flow_error *error)
1948 const struct rte_flow_item_eth *mask = item->mask;
1949 const struct rte_flow_item_eth nic_mask = {
1950 .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
1951 .src.addr_bytes = "\xff\xff\xff\xff\xff\xff",
1952 .type = RTE_BE16(0xffff),
1953 .has_vlan = ext_vlan_sup ? 1 : 0,
1956 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1957 const uint64_t ethm = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
1958 MLX5_FLOW_LAYER_OUTER_L2;
1960 if (item_flags & ethm)
1961 return rte_flow_error_set(error, ENOTSUP,
1962 RTE_FLOW_ERROR_TYPE_ITEM, item,
1963 "multiple L2 layers not supported");
1964 if ((!tunnel && (item_flags & MLX5_FLOW_LAYER_OUTER_L3)) ||
1965 (tunnel && (item_flags & MLX5_FLOW_LAYER_INNER_L3)))
1966 return rte_flow_error_set(error, EINVAL,
1967 RTE_FLOW_ERROR_TYPE_ITEM, item,
1968 "L2 layer should not follow "
1970 if ((!tunnel && (item_flags & MLX5_FLOW_LAYER_OUTER_VLAN)) ||
1971 (tunnel && (item_flags & MLX5_FLOW_LAYER_INNER_VLAN)))
1972 return rte_flow_error_set(error, EINVAL,
1973 RTE_FLOW_ERROR_TYPE_ITEM, item,
1974 "L2 layer should not follow VLAN");
1976 mask = &rte_flow_item_eth_mask;
1977 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1978 (const uint8_t *)&nic_mask,
1979 sizeof(struct rte_flow_item_eth),
1980 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
1985 * Validate VLAN item.
1988 * Item specification.
1989 * @param[in] item_flags
1990 * Bit-fields that holds the items detected until now.
1992 * Ethernet device flow is being created on.
1994 * Pointer to error structure.
1997 * 0 on success, a negative errno value otherwise and rte_errno is set.
2000 mlx5_flow_validate_item_vlan(const struct rte_flow_item *item,
2001 uint64_t item_flags,
2002 struct rte_eth_dev *dev,
2003 struct rte_flow_error *error)
2005 const struct rte_flow_item_vlan *spec = item->spec;
2006 const struct rte_flow_item_vlan *mask = item->mask;
2007 const struct rte_flow_item_vlan nic_mask = {
2008 .tci = RTE_BE16(UINT16_MAX),
2009 .inner_type = RTE_BE16(UINT16_MAX),
2011 uint16_t vlan_tag = 0;
2012 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2014 const uint64_t l34m = tunnel ? (MLX5_FLOW_LAYER_INNER_L3 |
2015 MLX5_FLOW_LAYER_INNER_L4) :
2016 (MLX5_FLOW_LAYER_OUTER_L3 |
2017 MLX5_FLOW_LAYER_OUTER_L4);
2018 const uint64_t vlanm = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
2019 MLX5_FLOW_LAYER_OUTER_VLAN;
2021 if (item_flags & vlanm)
2022 return rte_flow_error_set(error, EINVAL,
2023 RTE_FLOW_ERROR_TYPE_ITEM, item,
2024 "multiple VLAN layers not supported");
2025 else if ((item_flags & l34m) != 0)
2026 return rte_flow_error_set(error, EINVAL,
2027 RTE_FLOW_ERROR_TYPE_ITEM, item,
2028 "VLAN cannot follow L3/L4 layer");
2030 mask = &rte_flow_item_vlan_mask;
2031 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2032 (const uint8_t *)&nic_mask,
2033 sizeof(struct rte_flow_item_vlan),
2034 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2037 if (!tunnel && mask->tci != RTE_BE16(0x0fff)) {
2038 struct mlx5_priv *priv = dev->data->dev_private;
2040 if (priv->vmwa_context) {
2042 * Non-NULL context means we have a virtual machine
2043 * and SR-IOV enabled, we have to create VLAN interface
2044 * to make hypervisor to setup E-Switch vport
2045 * context correctly. We avoid creating the multiple
2046 * VLAN interfaces, so we cannot support VLAN tag mask.
2048 return rte_flow_error_set(error, EINVAL,
2049 RTE_FLOW_ERROR_TYPE_ITEM,
2051 "VLAN tag mask is not"
2052 " supported in virtual"
2057 vlan_tag = spec->tci;
2058 vlan_tag &= mask->tci;
2061 * From verbs perspective an empty VLAN is equivalent
2062 * to a packet without VLAN layer.
2065 return rte_flow_error_set(error, EINVAL,
2066 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
2068 "VLAN cannot be empty");
2073 * Validate IPV4 item.
2076 * Item specification.
2077 * @param[in] item_flags
2078 * Bit-fields that holds the items detected until now.
2079 * @param[in] last_item
2080 * Previous validated item in the pattern items.
2081 * @param[in] ether_type
2082 * Type in the ethernet layer header (including dot1q).
2083 * @param[in] acc_mask
2084 * Acceptable mask, if NULL default internal default mask
2085 * will be used to check whether item fields are supported.
2086 * @param[in] range_accepted
2087 * True if range of values is accepted for specific fields, false otherwise.
2089 * Pointer to error structure.
2092 * 0 on success, a negative errno value otherwise and rte_errno is set.
2095 mlx5_flow_validate_item_ipv4(const struct rte_flow_item *item,
2096 uint64_t item_flags,
2098 uint16_t ether_type,
2099 const struct rte_flow_item_ipv4 *acc_mask,
2100 bool range_accepted,
2101 struct rte_flow_error *error)
2103 const struct rte_flow_item_ipv4 *mask = item->mask;
2104 const struct rte_flow_item_ipv4 *spec = item->spec;
2105 const struct rte_flow_item_ipv4 nic_mask = {
2107 .src_addr = RTE_BE32(0xffffffff),
2108 .dst_addr = RTE_BE32(0xffffffff),
2109 .type_of_service = 0xff,
2110 .next_proto_id = 0xff,
2113 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2114 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2115 MLX5_FLOW_LAYER_OUTER_L3;
2116 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2117 MLX5_FLOW_LAYER_OUTER_L4;
2119 uint8_t next_proto = 0xFF;
2120 const uint64_t l2_vlan = (MLX5_FLOW_LAYER_L2 |
2121 MLX5_FLOW_LAYER_OUTER_VLAN |
2122 MLX5_FLOW_LAYER_INNER_VLAN);
2124 if ((last_item & l2_vlan) && ether_type &&
2125 ether_type != RTE_ETHER_TYPE_IPV4)
2126 return rte_flow_error_set(error, EINVAL,
2127 RTE_FLOW_ERROR_TYPE_ITEM, item,
2128 "IPv4 cannot follow L2/VLAN layer "
2129 "which ether type is not IPv4");
2130 if (item_flags & MLX5_FLOW_LAYER_TUNNEL) {
2132 next_proto = mask->hdr.next_proto_id &
2133 spec->hdr.next_proto_id;
2134 if (next_proto == IPPROTO_IPIP || next_proto == IPPROTO_IPV6)
2135 return rte_flow_error_set(error, EINVAL,
2136 RTE_FLOW_ERROR_TYPE_ITEM,
2141 if (item_flags & MLX5_FLOW_LAYER_IPV6_ENCAP)
2142 return rte_flow_error_set(error, EINVAL,
2143 RTE_FLOW_ERROR_TYPE_ITEM, item,
2144 "wrong tunnel type - IPv6 specified "
2145 "but IPv4 item provided");
2146 if (item_flags & l3m)
2147 return rte_flow_error_set(error, ENOTSUP,
2148 RTE_FLOW_ERROR_TYPE_ITEM, item,
2149 "multiple L3 layers not supported");
2150 else if (item_flags & l4m)
2151 return rte_flow_error_set(error, EINVAL,
2152 RTE_FLOW_ERROR_TYPE_ITEM, item,
2153 "L3 cannot follow an L4 layer.");
2154 else if ((item_flags & MLX5_FLOW_LAYER_NVGRE) &&
2155 !(item_flags & MLX5_FLOW_LAYER_INNER_L2))
2156 return rte_flow_error_set(error, EINVAL,
2157 RTE_FLOW_ERROR_TYPE_ITEM, item,
2158 "L3 cannot follow an NVGRE layer.");
2160 mask = &rte_flow_item_ipv4_mask;
2161 else if (mask->hdr.next_proto_id != 0 &&
2162 mask->hdr.next_proto_id != 0xff)
2163 return rte_flow_error_set(error, EINVAL,
2164 RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
2165 "partial mask is not supported"
2167 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2168 acc_mask ? (const uint8_t *)acc_mask
2169 : (const uint8_t *)&nic_mask,
2170 sizeof(struct rte_flow_item_ipv4),
2171 range_accepted, error);
2178 * Validate IPV6 item.
2181 * Item specification.
2182 * @param[in] item_flags
2183 * Bit-fields that holds the items detected until now.
2184 * @param[in] last_item
2185 * Previous validated item in the pattern items.
2186 * @param[in] ether_type
2187 * Type in the ethernet layer header (including dot1q).
2188 * @param[in] acc_mask
2189 * Acceptable mask, if NULL default internal default mask
2190 * will be used to check whether item fields are supported.
2192 * Pointer to error structure.
2195 * 0 on success, a negative errno value otherwise and rte_errno is set.
2198 mlx5_flow_validate_item_ipv6(const struct rte_flow_item *item,
2199 uint64_t item_flags,
2201 uint16_t ether_type,
2202 const struct rte_flow_item_ipv6 *acc_mask,
2203 struct rte_flow_error *error)
2205 const struct rte_flow_item_ipv6 *mask = item->mask;
2206 const struct rte_flow_item_ipv6 *spec = item->spec;
2207 const struct rte_flow_item_ipv6 nic_mask = {
2210 "\xff\xff\xff\xff\xff\xff\xff\xff"
2211 "\xff\xff\xff\xff\xff\xff\xff\xff",
2213 "\xff\xff\xff\xff\xff\xff\xff\xff"
2214 "\xff\xff\xff\xff\xff\xff\xff\xff",
2215 .vtc_flow = RTE_BE32(0xffffffff),
2219 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2220 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2221 MLX5_FLOW_LAYER_OUTER_L3;
2222 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2223 MLX5_FLOW_LAYER_OUTER_L4;
2225 uint8_t next_proto = 0xFF;
2226 const uint64_t l2_vlan = (MLX5_FLOW_LAYER_L2 |
2227 MLX5_FLOW_LAYER_OUTER_VLAN |
2228 MLX5_FLOW_LAYER_INNER_VLAN);
2230 if ((last_item & l2_vlan) && ether_type &&
2231 ether_type != RTE_ETHER_TYPE_IPV6)
2232 return rte_flow_error_set(error, EINVAL,
2233 RTE_FLOW_ERROR_TYPE_ITEM, item,
2234 "IPv6 cannot follow L2/VLAN layer "
2235 "which ether type is not IPv6");
2236 if (mask && mask->hdr.proto == UINT8_MAX && spec)
2237 next_proto = spec->hdr.proto;
2238 if (item_flags & MLX5_FLOW_LAYER_TUNNEL) {
2239 if (next_proto == IPPROTO_IPIP || next_proto == IPPROTO_IPV6)
2240 return rte_flow_error_set(error, EINVAL,
2241 RTE_FLOW_ERROR_TYPE_ITEM,
2246 if (next_proto == IPPROTO_HOPOPTS ||
2247 next_proto == IPPROTO_ROUTING ||
2248 next_proto == IPPROTO_FRAGMENT ||
2249 next_proto == IPPROTO_ESP ||
2250 next_proto == IPPROTO_AH ||
2251 next_proto == IPPROTO_DSTOPTS)
2252 return rte_flow_error_set(error, EINVAL,
2253 RTE_FLOW_ERROR_TYPE_ITEM, item,
2254 "IPv6 proto (next header) should "
2255 "not be set as extension header");
2256 if (item_flags & MLX5_FLOW_LAYER_IPIP)
2257 return rte_flow_error_set(error, EINVAL,
2258 RTE_FLOW_ERROR_TYPE_ITEM, item,
2259 "wrong tunnel type - IPv4 specified "
2260 "but IPv6 item provided");
2261 if (item_flags & l3m)
2262 return rte_flow_error_set(error, ENOTSUP,
2263 RTE_FLOW_ERROR_TYPE_ITEM, item,
2264 "multiple L3 layers not supported");
2265 else if (item_flags & l4m)
2266 return rte_flow_error_set(error, EINVAL,
2267 RTE_FLOW_ERROR_TYPE_ITEM, item,
2268 "L3 cannot follow an L4 layer.");
2269 else if ((item_flags & MLX5_FLOW_LAYER_NVGRE) &&
2270 !(item_flags & MLX5_FLOW_LAYER_INNER_L2))
2271 return rte_flow_error_set(error, EINVAL,
2272 RTE_FLOW_ERROR_TYPE_ITEM, item,
2273 "L3 cannot follow an NVGRE layer.");
2275 mask = &rte_flow_item_ipv6_mask;
2276 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2277 acc_mask ? (const uint8_t *)acc_mask
2278 : (const uint8_t *)&nic_mask,
2279 sizeof(struct rte_flow_item_ipv6),
2280 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2287 * Validate UDP item.
2290 * Item specification.
2291 * @param[in] item_flags
2292 * Bit-fields that holds the items detected until now.
2293 * @param[in] target_protocol
2294 * The next protocol in the previous item.
2295 * @param[in] flow_mask
2296 * mlx5 flow-specific (DV, verbs, etc.) supported header fields mask.
2298 * Pointer to error structure.
2301 * 0 on success, a negative errno value otherwise and rte_errno is set.
2304 mlx5_flow_validate_item_udp(const struct rte_flow_item *item,
2305 uint64_t item_flags,
2306 uint8_t target_protocol,
2307 struct rte_flow_error *error)
2309 const struct rte_flow_item_udp *mask = item->mask;
2310 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2311 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2312 MLX5_FLOW_LAYER_OUTER_L3;
2313 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2314 MLX5_FLOW_LAYER_OUTER_L4;
2317 if (target_protocol != 0xff && target_protocol != IPPROTO_UDP)
2318 return rte_flow_error_set(error, EINVAL,
2319 RTE_FLOW_ERROR_TYPE_ITEM, item,
2320 "protocol filtering not compatible"
2322 if (!(item_flags & l3m))
2323 return rte_flow_error_set(error, EINVAL,
2324 RTE_FLOW_ERROR_TYPE_ITEM, item,
2325 "L3 is mandatory to filter on L4");
2326 if (item_flags & l4m)
2327 return rte_flow_error_set(error, EINVAL,
2328 RTE_FLOW_ERROR_TYPE_ITEM, item,
2329 "multiple L4 layers not supported");
2331 mask = &rte_flow_item_udp_mask;
2332 ret = mlx5_flow_item_acceptable
2333 (item, (const uint8_t *)mask,
2334 (const uint8_t *)&rte_flow_item_udp_mask,
2335 sizeof(struct rte_flow_item_udp), MLX5_ITEM_RANGE_NOT_ACCEPTED,
2343 * Validate TCP item.
2346 * Item specification.
2347 * @param[in] item_flags
2348 * Bit-fields that holds the items detected until now.
2349 * @param[in] target_protocol
2350 * The next protocol in the previous item.
2352 * Pointer to error structure.
2355 * 0 on success, a negative errno value otherwise and rte_errno is set.
2358 mlx5_flow_validate_item_tcp(const struct rte_flow_item *item,
2359 uint64_t item_flags,
2360 uint8_t target_protocol,
2361 const struct rte_flow_item_tcp *flow_mask,
2362 struct rte_flow_error *error)
2364 const struct rte_flow_item_tcp *mask = item->mask;
2365 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2366 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2367 MLX5_FLOW_LAYER_OUTER_L3;
2368 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2369 MLX5_FLOW_LAYER_OUTER_L4;
2372 MLX5_ASSERT(flow_mask);
2373 if (target_protocol != 0xff && target_protocol != IPPROTO_TCP)
2374 return rte_flow_error_set(error, EINVAL,
2375 RTE_FLOW_ERROR_TYPE_ITEM, item,
2376 "protocol filtering not compatible"
2378 if (!(item_flags & l3m))
2379 return rte_flow_error_set(error, EINVAL,
2380 RTE_FLOW_ERROR_TYPE_ITEM, item,
2381 "L3 is mandatory to filter on L4");
2382 if (item_flags & l4m)
2383 return rte_flow_error_set(error, EINVAL,
2384 RTE_FLOW_ERROR_TYPE_ITEM, item,
2385 "multiple L4 layers not supported");
2387 mask = &rte_flow_item_tcp_mask;
2388 ret = mlx5_flow_item_acceptable
2389 (item, (const uint8_t *)mask,
2390 (const uint8_t *)flow_mask,
2391 sizeof(struct rte_flow_item_tcp), MLX5_ITEM_RANGE_NOT_ACCEPTED,
2399 * Validate VXLAN item.
2402 * Item specification.
2403 * @param[in] item_flags
2404 * Bit-fields that holds the items detected until now.
2405 * @param[in] target_protocol
2406 * The next protocol in the previous item.
2408 * Pointer to error structure.
2411 * 0 on success, a negative errno value otherwise and rte_errno is set.
2414 mlx5_flow_validate_item_vxlan(const struct rte_flow_item *item,
2415 uint64_t item_flags,
2416 struct rte_flow_error *error)
2418 const struct rte_flow_item_vxlan *spec = item->spec;
2419 const struct rte_flow_item_vxlan *mask = item->mask;
2424 } id = { .vlan_id = 0, };
2427 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2428 return rte_flow_error_set(error, ENOTSUP,
2429 RTE_FLOW_ERROR_TYPE_ITEM, item,
2430 "multiple tunnel layers not"
2433 * Verify only UDPv4 is present as defined in
2434 * https://tools.ietf.org/html/rfc7348
2436 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2437 return rte_flow_error_set(error, EINVAL,
2438 RTE_FLOW_ERROR_TYPE_ITEM, item,
2439 "no outer UDP layer found");
2441 mask = &rte_flow_item_vxlan_mask;
2442 ret = mlx5_flow_item_acceptable
2443 (item, (const uint8_t *)mask,
2444 (const uint8_t *)&rte_flow_item_vxlan_mask,
2445 sizeof(struct rte_flow_item_vxlan),
2446 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2450 memcpy(&id.vni[1], spec->vni, 3);
2451 memcpy(&id.vni[1], mask->vni, 3);
2453 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
2454 return rte_flow_error_set(error, ENOTSUP,
2455 RTE_FLOW_ERROR_TYPE_ITEM, item,
2456 "VXLAN tunnel must be fully defined");
2461 * Validate VXLAN_GPE item.
2464 * Item specification.
2465 * @param[in] item_flags
2466 * Bit-fields that holds the items detected until now.
2468 * Pointer to the private data structure.
2469 * @param[in] target_protocol
2470 * The next protocol in the previous item.
2472 * Pointer to error structure.
2475 * 0 on success, a negative errno value otherwise and rte_errno is set.
2478 mlx5_flow_validate_item_vxlan_gpe(const struct rte_flow_item *item,
2479 uint64_t item_flags,
2480 struct rte_eth_dev *dev,
2481 struct rte_flow_error *error)
2483 struct mlx5_priv *priv = dev->data->dev_private;
2484 const struct rte_flow_item_vxlan_gpe *spec = item->spec;
2485 const struct rte_flow_item_vxlan_gpe *mask = item->mask;
2490 } id = { .vlan_id = 0, };
2492 if (!priv->config.l3_vxlan_en)
2493 return rte_flow_error_set(error, ENOTSUP,
2494 RTE_FLOW_ERROR_TYPE_ITEM, item,
2495 "L3 VXLAN is not enabled by device"
2496 " parameter and/or not configured in"
2498 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2499 return rte_flow_error_set(error, ENOTSUP,
2500 RTE_FLOW_ERROR_TYPE_ITEM, item,
2501 "multiple tunnel layers not"
2504 * Verify only UDPv4 is present as defined in
2505 * https://tools.ietf.org/html/rfc7348
2507 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2508 return rte_flow_error_set(error, EINVAL,
2509 RTE_FLOW_ERROR_TYPE_ITEM, item,
2510 "no outer UDP layer found");
2512 mask = &rte_flow_item_vxlan_gpe_mask;
2513 ret = mlx5_flow_item_acceptable
2514 (item, (const uint8_t *)mask,
2515 (const uint8_t *)&rte_flow_item_vxlan_gpe_mask,
2516 sizeof(struct rte_flow_item_vxlan_gpe),
2517 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2522 return rte_flow_error_set(error, ENOTSUP,
2523 RTE_FLOW_ERROR_TYPE_ITEM,
2525 "VxLAN-GPE protocol"
2527 memcpy(&id.vni[1], spec->vni, 3);
2528 memcpy(&id.vni[1], mask->vni, 3);
2530 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
2531 return rte_flow_error_set(error, ENOTSUP,
2532 RTE_FLOW_ERROR_TYPE_ITEM, item,
2533 "VXLAN-GPE tunnel must be fully"
2538 * Validate GRE Key item.
2541 * Item specification.
2542 * @param[in] item_flags
2543 * Bit flags to mark detected items.
2544 * @param[in] gre_item
2545 * Pointer to gre_item
2547 * Pointer to error structure.
2550 * 0 on success, a negative errno value otherwise and rte_errno is set.
2553 mlx5_flow_validate_item_gre_key(const struct rte_flow_item *item,
2554 uint64_t item_flags,
2555 const struct rte_flow_item *gre_item,
2556 struct rte_flow_error *error)
2558 const rte_be32_t *mask = item->mask;
2560 rte_be32_t gre_key_default_mask = RTE_BE32(UINT32_MAX);
2561 const struct rte_flow_item_gre *gre_spec;
2562 const struct rte_flow_item_gre *gre_mask;
2564 if (item_flags & MLX5_FLOW_LAYER_GRE_KEY)
2565 return rte_flow_error_set(error, ENOTSUP,
2566 RTE_FLOW_ERROR_TYPE_ITEM, item,
2567 "Multiple GRE key not support");
2568 if (!(item_flags & MLX5_FLOW_LAYER_GRE))
2569 return rte_flow_error_set(error, ENOTSUP,
2570 RTE_FLOW_ERROR_TYPE_ITEM, item,
2571 "No preceding GRE header");
2572 if (item_flags & MLX5_FLOW_LAYER_INNER)
2573 return rte_flow_error_set(error, ENOTSUP,
2574 RTE_FLOW_ERROR_TYPE_ITEM, item,
2575 "GRE key following a wrong item");
2576 gre_mask = gre_item->mask;
2578 gre_mask = &rte_flow_item_gre_mask;
2579 gre_spec = gre_item->spec;
2580 if (gre_spec && (gre_mask->c_rsvd0_ver & RTE_BE16(0x2000)) &&
2581 !(gre_spec->c_rsvd0_ver & RTE_BE16(0x2000)))
2582 return rte_flow_error_set(error, EINVAL,
2583 RTE_FLOW_ERROR_TYPE_ITEM, item,
2584 "Key bit must be on");
2587 mask = &gre_key_default_mask;
2588 ret = mlx5_flow_item_acceptable
2589 (item, (const uint8_t *)mask,
2590 (const uint8_t *)&gre_key_default_mask,
2591 sizeof(rte_be32_t), MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2596 * Validate GRE item.
2599 * Item specification.
2600 * @param[in] item_flags
2601 * Bit flags to mark detected items.
2602 * @param[in] target_protocol
2603 * The next protocol in the previous item.
2605 * Pointer to error structure.
2608 * 0 on success, a negative errno value otherwise and rte_errno is set.
2611 mlx5_flow_validate_item_gre(const struct rte_flow_item *item,
2612 uint64_t item_flags,
2613 uint8_t target_protocol,
2614 struct rte_flow_error *error)
2616 const struct rte_flow_item_gre *spec __rte_unused = item->spec;
2617 const struct rte_flow_item_gre *mask = item->mask;
2619 const struct rte_flow_item_gre nic_mask = {
2620 .c_rsvd0_ver = RTE_BE16(0xB000),
2621 .protocol = RTE_BE16(UINT16_MAX),
2624 if (target_protocol != 0xff && target_protocol != IPPROTO_GRE)
2625 return rte_flow_error_set(error, EINVAL,
2626 RTE_FLOW_ERROR_TYPE_ITEM, item,
2627 "protocol filtering not compatible"
2628 " with this GRE layer");
2629 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2630 return rte_flow_error_set(error, ENOTSUP,
2631 RTE_FLOW_ERROR_TYPE_ITEM, item,
2632 "multiple tunnel layers not"
2634 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3))
2635 return rte_flow_error_set(error, ENOTSUP,
2636 RTE_FLOW_ERROR_TYPE_ITEM, item,
2637 "L3 Layer is missing");
2639 mask = &rte_flow_item_gre_mask;
2640 ret = mlx5_flow_item_acceptable
2641 (item, (const uint8_t *)mask,
2642 (const uint8_t *)&nic_mask,
2643 sizeof(struct rte_flow_item_gre), MLX5_ITEM_RANGE_NOT_ACCEPTED,
2647 #ifndef HAVE_MLX5DV_DR
2648 #ifndef HAVE_IBV_DEVICE_MPLS_SUPPORT
2649 if (spec && (spec->protocol & mask->protocol))
2650 return rte_flow_error_set(error, ENOTSUP,
2651 RTE_FLOW_ERROR_TYPE_ITEM, item,
2652 "without MPLS support the"
2653 " specification cannot be used for"
2661 * Validate Geneve item.
2664 * Item specification.
2665 * @param[in] itemFlags
2666 * Bit-fields that holds the items detected until now.
2668 * Pointer to the private data structure.
2670 * Pointer to error structure.
2673 * 0 on success, a negative errno value otherwise and rte_errno is set.
2677 mlx5_flow_validate_item_geneve(const struct rte_flow_item *item,
2678 uint64_t item_flags,
2679 struct rte_eth_dev *dev,
2680 struct rte_flow_error *error)
2682 struct mlx5_priv *priv = dev->data->dev_private;
2683 const struct rte_flow_item_geneve *spec = item->spec;
2684 const struct rte_flow_item_geneve *mask = item->mask;
2687 uint8_t opt_len = priv->config.hca_attr.geneve_max_opt_len ?
2688 MLX5_GENEVE_OPT_LEN_1 : MLX5_GENEVE_OPT_LEN_0;
2689 const struct rte_flow_item_geneve nic_mask = {
2690 .ver_opt_len_o_c_rsvd0 = RTE_BE16(0x3f80),
2691 .vni = "\xff\xff\xff",
2692 .protocol = RTE_BE16(UINT16_MAX),
2695 if (!priv->config.hca_attr.tunnel_stateless_geneve_rx)
2696 return rte_flow_error_set(error, ENOTSUP,
2697 RTE_FLOW_ERROR_TYPE_ITEM, item,
2698 "L3 Geneve is not enabled by device"
2699 " parameter and/or not configured in"
2701 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2702 return rte_flow_error_set(error, ENOTSUP,
2703 RTE_FLOW_ERROR_TYPE_ITEM, item,
2704 "multiple tunnel layers not"
2707 * Verify only UDPv4 is present as defined in
2708 * https://tools.ietf.org/html/rfc7348
2710 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2711 return rte_flow_error_set(error, EINVAL,
2712 RTE_FLOW_ERROR_TYPE_ITEM, item,
2713 "no outer UDP layer found");
2715 mask = &rte_flow_item_geneve_mask;
2716 ret = mlx5_flow_item_acceptable
2717 (item, (const uint8_t *)mask,
2718 (const uint8_t *)&nic_mask,
2719 sizeof(struct rte_flow_item_geneve),
2720 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2724 gbhdr = rte_be_to_cpu_16(spec->ver_opt_len_o_c_rsvd0);
2725 if (MLX5_GENEVE_VER_VAL(gbhdr) ||
2726 MLX5_GENEVE_CRITO_VAL(gbhdr) ||
2727 MLX5_GENEVE_RSVD_VAL(gbhdr) || spec->rsvd1)
2728 return rte_flow_error_set(error, ENOTSUP,
2729 RTE_FLOW_ERROR_TYPE_ITEM,
2731 "Geneve protocol unsupported"
2732 " fields are being used");
2733 if (MLX5_GENEVE_OPTLEN_VAL(gbhdr) > opt_len)
2734 return rte_flow_error_set
2736 RTE_FLOW_ERROR_TYPE_ITEM,
2738 "Unsupported Geneve options length");
2740 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
2741 return rte_flow_error_set
2743 RTE_FLOW_ERROR_TYPE_ITEM, item,
2744 "Geneve tunnel must be fully defined");
2749 * Validate Geneve TLV option item.
2752 * Item specification.
2753 * @param[in] last_item
2754 * Previous validated item in the pattern items.
2755 * @param[in] geneve_item
2756 * Previous GENEVE item specification.
2758 * Pointer to the rte_eth_dev structure.
2760 * Pointer to error structure.
2763 * 0 on success, a negative errno value otherwise and rte_errno is set.
2766 mlx5_flow_validate_item_geneve_opt(const struct rte_flow_item *item,
2768 const struct rte_flow_item *geneve_item,
2769 struct rte_eth_dev *dev,
2770 struct rte_flow_error *error)
2772 struct mlx5_priv *priv = dev->data->dev_private;
2773 struct mlx5_dev_ctx_shared *sh = priv->sh;
2774 struct mlx5_geneve_tlv_option_resource *geneve_opt_resource;
2775 struct mlx5_hca_attr *hca_attr = &priv->config.hca_attr;
2776 uint8_t data_max_supported =
2777 hca_attr->max_geneve_tlv_option_data_len * 4;
2778 struct mlx5_dev_config *config = &priv->config;
2779 const struct rte_flow_item_geneve *geneve_spec;
2780 const struct rte_flow_item_geneve *geneve_mask;
2781 const struct rte_flow_item_geneve_opt *spec = item->spec;
2782 const struct rte_flow_item_geneve_opt *mask = item->mask;
2784 unsigned int data_len;
2785 uint8_t tlv_option_len;
2786 uint16_t optlen_m, optlen_v;
2787 const struct rte_flow_item_geneve_opt full_mask = {
2788 .option_class = RTE_BE16(0xffff),
2789 .option_type = 0xff,
2794 mask = &rte_flow_item_geneve_opt_mask;
2796 return rte_flow_error_set
2797 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2798 "Geneve TLV opt class/type/length must be specified");
2799 if ((uint32_t)spec->option_len > MLX5_GENEVE_OPTLEN_MASK)
2800 return rte_flow_error_set
2801 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2802 "Geneve TLV opt length exceeeds the limit (31)");
2803 /* Check if class type and length masks are full. */
2804 if (full_mask.option_class != mask->option_class ||
2805 full_mask.option_type != mask->option_type ||
2806 full_mask.option_len != (mask->option_len & full_mask.option_len))
2807 return rte_flow_error_set
2808 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2809 "Geneve TLV opt class/type/length masks must be full");
2810 /* Check if length is supported */
2811 if ((uint32_t)spec->option_len >
2812 config->hca_attr.max_geneve_tlv_option_data_len)
2813 return rte_flow_error_set
2814 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2815 "Geneve TLV opt length not supported");
2816 if (config->hca_attr.max_geneve_tlv_options > 1)
2818 "max_geneve_tlv_options supports more than 1 option");
2819 /* Check GENEVE item preceding. */
2820 if (!geneve_item || !(last_item & MLX5_FLOW_LAYER_GENEVE))
2821 return rte_flow_error_set
2822 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2823 "Geneve opt item must be preceded with Geneve item");
2824 geneve_spec = geneve_item->spec;
2825 geneve_mask = geneve_item->mask ? geneve_item->mask :
2826 &rte_flow_item_geneve_mask;
2827 /* Check if GENEVE TLV option size doesn't exceed option length */
2828 if (geneve_spec && (geneve_mask->ver_opt_len_o_c_rsvd0 ||
2829 geneve_spec->ver_opt_len_o_c_rsvd0)) {
2830 tlv_option_len = spec->option_len & mask->option_len;
2831 optlen_v = rte_be_to_cpu_16(geneve_spec->ver_opt_len_o_c_rsvd0);
2832 optlen_v = MLX5_GENEVE_OPTLEN_VAL(optlen_v);
2833 optlen_m = rte_be_to_cpu_16(geneve_mask->ver_opt_len_o_c_rsvd0);
2834 optlen_m = MLX5_GENEVE_OPTLEN_VAL(optlen_m);
2835 if ((optlen_v & optlen_m) <= tlv_option_len)
2836 return rte_flow_error_set
2837 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2838 "GENEVE TLV option length exceeds optlen");
2840 /* Check if length is 0 or data is 0. */
2841 if (spec->data == NULL || spec->option_len == 0)
2842 return rte_flow_error_set
2843 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2844 "Geneve TLV opt with zero data/length not supported");
2845 /* Check not all data & mask are 0. */
2846 data_len = spec->option_len * 4;
2847 if (mask->data == NULL) {
2848 for (i = 0; i < data_len; i++)
2852 return rte_flow_error_set(error, ENOTSUP,
2853 RTE_FLOW_ERROR_TYPE_ITEM, item,
2854 "Can't match on Geneve option data 0");
2856 for (i = 0; i < data_len; i++)
2857 if (spec->data[i] & mask->data[i])
2860 return rte_flow_error_set(error, ENOTSUP,
2861 RTE_FLOW_ERROR_TYPE_ITEM, item,
2862 "Can't match on Geneve option data and mask 0");
2863 /* Check data mask supported. */
2864 for (i = data_max_supported; i < data_len ; i++)
2866 return rte_flow_error_set(error, ENOTSUP,
2867 RTE_FLOW_ERROR_TYPE_ITEM, item,
2868 "Data mask is of unsupported size");
2870 /* Check GENEVE option is supported in NIC. */
2871 if (!config->hca_attr.geneve_tlv_opt)
2872 return rte_flow_error_set
2873 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2874 "Geneve TLV opt not supported");
2875 /* Check if we already have geneve option with different type/class. */
2876 rte_spinlock_lock(&sh->geneve_tlv_opt_sl);
2877 geneve_opt_resource = sh->geneve_tlv_option_resource;
2878 if (geneve_opt_resource != NULL)
2879 if (geneve_opt_resource->option_class != spec->option_class ||
2880 geneve_opt_resource->option_type != spec->option_type ||
2881 geneve_opt_resource->length != spec->option_len) {
2882 rte_spinlock_unlock(&sh->geneve_tlv_opt_sl);
2883 return rte_flow_error_set(error, ENOTSUP,
2884 RTE_FLOW_ERROR_TYPE_ITEM, item,
2885 "Only one Geneve TLV option supported");
2887 rte_spinlock_unlock(&sh->geneve_tlv_opt_sl);
2892 * Validate MPLS item.
2895 * Pointer to the rte_eth_dev structure.
2897 * Item specification.
2898 * @param[in] item_flags
2899 * Bit-fields that holds the items detected until now.
2900 * @param[in] prev_layer
2901 * The protocol layer indicated in previous item.
2903 * Pointer to error structure.
2906 * 0 on success, a negative errno value otherwise and rte_errno is set.
2909 mlx5_flow_validate_item_mpls(struct rte_eth_dev *dev __rte_unused,
2910 const struct rte_flow_item *item __rte_unused,
2911 uint64_t item_flags __rte_unused,
2912 uint64_t prev_layer __rte_unused,
2913 struct rte_flow_error *error)
2915 #ifdef HAVE_IBV_DEVICE_MPLS_SUPPORT
2916 const struct rte_flow_item_mpls *mask = item->mask;
2917 struct mlx5_priv *priv = dev->data->dev_private;
2920 if (!priv->config.mpls_en)
2921 return rte_flow_error_set(error, ENOTSUP,
2922 RTE_FLOW_ERROR_TYPE_ITEM, item,
2923 "MPLS not supported or"
2924 " disabled in firmware"
2926 /* MPLS over UDP, GRE is allowed */
2927 if (!(prev_layer & (MLX5_FLOW_LAYER_OUTER_L4_UDP |
2928 MLX5_FLOW_LAYER_GRE |
2929 MLX5_FLOW_LAYER_GRE_KEY)))
2930 return rte_flow_error_set(error, EINVAL,
2931 RTE_FLOW_ERROR_TYPE_ITEM, item,
2932 "protocol filtering not compatible"
2933 " with MPLS layer");
2934 /* Multi-tunnel isn't allowed but MPLS over GRE is an exception. */
2935 if ((item_flags & MLX5_FLOW_LAYER_TUNNEL) &&
2936 !(item_flags & MLX5_FLOW_LAYER_GRE))
2937 return rte_flow_error_set(error, ENOTSUP,
2938 RTE_FLOW_ERROR_TYPE_ITEM, item,
2939 "multiple tunnel layers not"
2942 mask = &rte_flow_item_mpls_mask;
2943 ret = mlx5_flow_item_acceptable
2944 (item, (const uint8_t *)mask,
2945 (const uint8_t *)&rte_flow_item_mpls_mask,
2946 sizeof(struct rte_flow_item_mpls),
2947 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2952 return rte_flow_error_set(error, ENOTSUP,
2953 RTE_FLOW_ERROR_TYPE_ITEM, item,
2954 "MPLS is not supported by Verbs, please"
2960 * Validate NVGRE item.
2963 * Item specification.
2964 * @param[in] item_flags
2965 * Bit flags to mark detected items.
2966 * @param[in] target_protocol
2967 * The next protocol in the previous item.
2969 * Pointer to error structure.
2972 * 0 on success, a negative errno value otherwise and rte_errno is set.
2975 mlx5_flow_validate_item_nvgre(const struct rte_flow_item *item,
2976 uint64_t item_flags,
2977 uint8_t target_protocol,
2978 struct rte_flow_error *error)
2980 const struct rte_flow_item_nvgre *mask = item->mask;
2983 if (target_protocol != 0xff && target_protocol != IPPROTO_GRE)
2984 return rte_flow_error_set(error, EINVAL,
2985 RTE_FLOW_ERROR_TYPE_ITEM, item,
2986 "protocol filtering not compatible"
2987 " with this GRE layer");
2988 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2989 return rte_flow_error_set(error, ENOTSUP,
2990 RTE_FLOW_ERROR_TYPE_ITEM, item,
2991 "multiple tunnel layers not"
2993 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3))
2994 return rte_flow_error_set(error, ENOTSUP,
2995 RTE_FLOW_ERROR_TYPE_ITEM, item,
2996 "L3 Layer is missing");
2998 mask = &rte_flow_item_nvgre_mask;
2999 ret = mlx5_flow_item_acceptable
3000 (item, (const uint8_t *)mask,
3001 (const uint8_t *)&rte_flow_item_nvgre_mask,
3002 sizeof(struct rte_flow_item_nvgre),
3003 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
3010 * Validate eCPRI item.
3013 * Item specification.
3014 * @param[in] item_flags
3015 * Bit-fields that holds the items detected until now.
3016 * @param[in] last_item
3017 * Previous validated item in the pattern items.
3018 * @param[in] ether_type
3019 * Type in the ethernet layer header (including dot1q).
3020 * @param[in] acc_mask
3021 * Acceptable mask, if NULL default internal default mask
3022 * will be used to check whether item fields are supported.
3024 * Pointer to error structure.
3027 * 0 on success, a negative errno value otherwise and rte_errno is set.
3030 mlx5_flow_validate_item_ecpri(const struct rte_flow_item *item,
3031 uint64_t item_flags,
3033 uint16_t ether_type,
3034 const struct rte_flow_item_ecpri *acc_mask,
3035 struct rte_flow_error *error)
3037 const struct rte_flow_item_ecpri *mask = item->mask;
3038 const struct rte_flow_item_ecpri nic_mask = {
3042 RTE_BE32(((const struct rte_ecpri_common_hdr) {
3046 .dummy[0] = 0xFFFFFFFF,
3049 const uint64_t outer_l2_vlan = (MLX5_FLOW_LAYER_OUTER_L2 |
3050 MLX5_FLOW_LAYER_OUTER_VLAN);
3051 struct rte_flow_item_ecpri mask_lo;
3053 if (!(last_item & outer_l2_vlan) &&
3054 last_item != MLX5_FLOW_LAYER_OUTER_L4_UDP)
3055 return rte_flow_error_set(error, EINVAL,
3056 RTE_FLOW_ERROR_TYPE_ITEM, item,
3057 "eCPRI can only follow L2/VLAN layer or UDP layer");
3058 if ((last_item & outer_l2_vlan) && ether_type &&
3059 ether_type != RTE_ETHER_TYPE_ECPRI)
3060 return rte_flow_error_set(error, EINVAL,
3061 RTE_FLOW_ERROR_TYPE_ITEM, item,
3062 "eCPRI cannot follow L2/VLAN layer which ether type is not 0xAEFE");
3063 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
3064 return rte_flow_error_set(error, EINVAL,
3065 RTE_FLOW_ERROR_TYPE_ITEM, item,
3066 "eCPRI with tunnel is not supported right now");
3067 if (item_flags & MLX5_FLOW_LAYER_OUTER_L3)
3068 return rte_flow_error_set(error, ENOTSUP,
3069 RTE_FLOW_ERROR_TYPE_ITEM, item,
3070 "multiple L3 layers not supported");
3071 else if (item_flags & MLX5_FLOW_LAYER_OUTER_L4_TCP)
3072 return rte_flow_error_set(error, EINVAL,
3073 RTE_FLOW_ERROR_TYPE_ITEM, item,
3074 "eCPRI cannot coexist with a TCP layer");
3075 /* In specification, eCPRI could be over UDP layer. */
3076 else if (item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP)
3077 return rte_flow_error_set(error, EINVAL,
3078 RTE_FLOW_ERROR_TYPE_ITEM, item,
3079 "eCPRI over UDP layer is not yet supported right now");
3080 /* Mask for type field in common header could be zero. */
3082 mask = &rte_flow_item_ecpri_mask;
3083 mask_lo.hdr.common.u32 = rte_be_to_cpu_32(mask->hdr.common.u32);
3084 /* Input mask is in big-endian format. */
3085 if (mask_lo.hdr.common.type != 0 && mask_lo.hdr.common.type != 0xff)
3086 return rte_flow_error_set(error, EINVAL,
3087 RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
3088 "partial mask is not supported for protocol");
3089 else if (mask_lo.hdr.common.type == 0 && mask->hdr.dummy[0] != 0)
3090 return rte_flow_error_set(error, EINVAL,
3091 RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
3092 "message header mask must be after a type mask");
3093 return mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
3094 acc_mask ? (const uint8_t *)acc_mask
3095 : (const uint8_t *)&nic_mask,
3096 sizeof(struct rte_flow_item_ecpri),
3097 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
3101 * Release resource related QUEUE/RSS action split.
3104 * Pointer to Ethernet device.
3106 * Flow to release id's from.
3109 flow_mreg_split_qrss_release(struct rte_eth_dev *dev,
3110 struct rte_flow *flow)
3112 struct mlx5_priv *priv = dev->data->dev_private;
3113 uint32_t handle_idx;
3114 struct mlx5_flow_handle *dev_handle;
3116 SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
3117 handle_idx, dev_handle, next)
3118 if (dev_handle->split_flow_id &&
3119 !dev_handle->is_meter_flow_id)
3120 mlx5_ipool_free(priv->sh->ipool
3121 [MLX5_IPOOL_RSS_EXPANTION_FLOW_ID],
3122 dev_handle->split_flow_id);
3126 flow_null_validate(struct rte_eth_dev *dev __rte_unused,
3127 const struct rte_flow_attr *attr __rte_unused,
3128 const struct rte_flow_item items[] __rte_unused,
3129 const struct rte_flow_action actions[] __rte_unused,
3130 bool external __rte_unused,
3131 int hairpin __rte_unused,
3132 struct rte_flow_error *error)
3134 return rte_flow_error_set(error, ENOTSUP,
3135 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
3138 static struct mlx5_flow *
3139 flow_null_prepare(struct rte_eth_dev *dev __rte_unused,
3140 const struct rte_flow_attr *attr __rte_unused,
3141 const struct rte_flow_item items[] __rte_unused,
3142 const struct rte_flow_action actions[] __rte_unused,
3143 struct rte_flow_error *error)
3145 rte_flow_error_set(error, ENOTSUP,
3146 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
3151 flow_null_translate(struct rte_eth_dev *dev __rte_unused,
3152 struct mlx5_flow *dev_flow __rte_unused,
3153 const struct rte_flow_attr *attr __rte_unused,
3154 const struct rte_flow_item items[] __rte_unused,
3155 const struct rte_flow_action actions[] __rte_unused,
3156 struct rte_flow_error *error)
3158 return rte_flow_error_set(error, ENOTSUP,
3159 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
3163 flow_null_apply(struct rte_eth_dev *dev __rte_unused,
3164 struct rte_flow *flow __rte_unused,
3165 struct rte_flow_error *error)
3167 return rte_flow_error_set(error, ENOTSUP,
3168 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
3172 flow_null_remove(struct rte_eth_dev *dev __rte_unused,
3173 struct rte_flow *flow __rte_unused)
3178 flow_null_destroy(struct rte_eth_dev *dev __rte_unused,
3179 struct rte_flow *flow __rte_unused)
3184 flow_null_query(struct rte_eth_dev *dev __rte_unused,
3185 struct rte_flow *flow __rte_unused,
3186 const struct rte_flow_action *actions __rte_unused,
3187 void *data __rte_unused,
3188 struct rte_flow_error *error)
3190 return rte_flow_error_set(error, ENOTSUP,
3191 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
3195 flow_null_sync_domain(struct rte_eth_dev *dev __rte_unused,
3196 uint32_t domains __rte_unused,
3197 uint32_t flags __rte_unused)
3202 /* Void driver to protect from null pointer reference. */
3203 const struct mlx5_flow_driver_ops mlx5_flow_null_drv_ops = {
3204 .validate = flow_null_validate,
3205 .prepare = flow_null_prepare,
3206 .translate = flow_null_translate,
3207 .apply = flow_null_apply,
3208 .remove = flow_null_remove,
3209 .destroy = flow_null_destroy,
3210 .query = flow_null_query,
3211 .sync_domain = flow_null_sync_domain,
3215 * Select flow driver type according to flow attributes and device
3219 * Pointer to the dev structure.
3221 * Pointer to the flow attributes.
3224 * flow driver type, MLX5_FLOW_TYPE_MAX otherwise.
3226 static enum mlx5_flow_drv_type
3227 flow_get_drv_type(struct rte_eth_dev *dev, const struct rte_flow_attr *attr)
3229 struct mlx5_priv *priv = dev->data->dev_private;
3230 /* The OS can determine first a specific flow type (DV, VERBS) */
3231 enum mlx5_flow_drv_type type = mlx5_flow_os_get_type();
3233 if (type != MLX5_FLOW_TYPE_MAX)
3235 /* If no OS specific type - continue with DV/VERBS selection */
3236 if (attr->transfer && priv->config.dv_esw_en)
3237 type = MLX5_FLOW_TYPE_DV;
3238 if (!attr->transfer)
3239 type = priv->config.dv_flow_en ? MLX5_FLOW_TYPE_DV :
3240 MLX5_FLOW_TYPE_VERBS;
3244 #define flow_get_drv_ops(type) flow_drv_ops[type]
3247 * Flow driver validation API. This abstracts calling driver specific functions.
3248 * The type of flow driver is determined according to flow attributes.
3251 * Pointer to the dev structure.
3253 * Pointer to the flow attributes.
3255 * Pointer to the list of items.
3256 * @param[in] actions
3257 * Pointer to the list of actions.
3258 * @param[in] external
3259 * This flow rule is created by request external to PMD.
3260 * @param[in] hairpin
3261 * Number of hairpin TX actions, 0 means classic flow.
3263 * Pointer to the error structure.
3266 * 0 on success, a negative errno value otherwise and rte_errno is set.
3269 flow_drv_validate(struct rte_eth_dev *dev,
3270 const struct rte_flow_attr *attr,
3271 const struct rte_flow_item items[],
3272 const struct rte_flow_action actions[],
3273 bool external, int hairpin, struct rte_flow_error *error)
3275 const struct mlx5_flow_driver_ops *fops;
3276 enum mlx5_flow_drv_type type = flow_get_drv_type(dev, attr);
3278 fops = flow_get_drv_ops(type);
3279 return fops->validate(dev, attr, items, actions, external,
3284 * Flow driver preparation API. This abstracts calling driver specific
3285 * functions. Parent flow (rte_flow) should have driver type (drv_type). It
3286 * calculates the size of memory required for device flow, allocates the memory,
3287 * initializes the device flow and returns the pointer.
3290 * This function initializes device flow structure such as dv or verbs in
3291 * struct mlx5_flow. However, it is caller's responsibility to initialize the
3292 * rest. For example, adding returning device flow to flow->dev_flow list and
3293 * setting backward reference to the flow should be done out of this function.
3294 * layers field is not filled either.
3297 * Pointer to the dev structure.
3299 * Pointer to the flow attributes.
3301 * Pointer to the list of items.
3302 * @param[in] actions
3303 * Pointer to the list of actions.
3304 * @param[in] flow_idx
3305 * This memory pool index to the flow.
3307 * Pointer to the error structure.
3310 * Pointer to device flow on success, otherwise NULL and rte_errno is set.
3312 static inline struct mlx5_flow *
3313 flow_drv_prepare(struct rte_eth_dev *dev,
3314 const struct rte_flow *flow,
3315 const struct rte_flow_attr *attr,
3316 const struct rte_flow_item items[],
3317 const struct rte_flow_action actions[],
3319 struct rte_flow_error *error)
3321 const struct mlx5_flow_driver_ops *fops;
3322 enum mlx5_flow_drv_type type = flow->drv_type;
3323 struct mlx5_flow *mlx5_flow = NULL;
3325 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3326 fops = flow_get_drv_ops(type);
3327 mlx5_flow = fops->prepare(dev, attr, items, actions, error);
3329 mlx5_flow->flow_idx = flow_idx;
3334 * Flow driver translation API. This abstracts calling driver specific
3335 * functions. Parent flow (rte_flow) should have driver type (drv_type). It
3336 * translates a generic flow into a driver flow. flow_drv_prepare() must
3340 * dev_flow->layers could be filled as a result of parsing during translation
3341 * if needed by flow_drv_apply(). dev_flow->flow->actions can also be filled
3342 * if necessary. As a flow can have multiple dev_flows by RSS flow expansion,
3343 * flow->actions could be overwritten even though all the expanded dev_flows
3344 * have the same actions.
3347 * Pointer to the rte dev structure.
3348 * @param[in, out] dev_flow
3349 * Pointer to the mlx5 flow.
3351 * Pointer to the flow attributes.
3353 * Pointer to the list of items.
3354 * @param[in] actions
3355 * Pointer to the list of actions.
3357 * Pointer to the error structure.
3360 * 0 on success, a negative errno value otherwise and rte_errno is set.
3363 flow_drv_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
3364 const struct rte_flow_attr *attr,
3365 const struct rte_flow_item items[],
3366 const struct rte_flow_action actions[],
3367 struct rte_flow_error *error)
3369 const struct mlx5_flow_driver_ops *fops;
3370 enum mlx5_flow_drv_type type = dev_flow->flow->drv_type;
3372 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3373 fops = flow_get_drv_ops(type);
3374 return fops->translate(dev, dev_flow, attr, items, actions, error);
3378 * Flow driver apply API. This abstracts calling driver specific functions.
3379 * Parent flow (rte_flow) should have driver type (drv_type). It applies
3380 * translated driver flows on to device. flow_drv_translate() must precede.
3383 * Pointer to Ethernet device structure.
3384 * @param[in, out] flow
3385 * Pointer to flow structure.
3387 * Pointer to error structure.
3390 * 0 on success, a negative errno value otherwise and rte_errno is set.
3393 flow_drv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
3394 struct rte_flow_error *error)
3396 const struct mlx5_flow_driver_ops *fops;
3397 enum mlx5_flow_drv_type type = flow->drv_type;
3399 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3400 fops = flow_get_drv_ops(type);
3401 return fops->apply(dev, flow, error);
3405 * Flow driver destroy API. This abstracts calling driver specific functions.
3406 * Parent flow (rte_flow) should have driver type (drv_type). It removes a flow
3407 * on device and releases resources of the flow.
3410 * Pointer to Ethernet device.
3411 * @param[in, out] flow
3412 * Pointer to flow structure.
3415 flow_drv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
3417 const struct mlx5_flow_driver_ops *fops;
3418 enum mlx5_flow_drv_type type = flow->drv_type;
3420 flow_mreg_split_qrss_release(dev, flow);
3421 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3422 fops = flow_get_drv_ops(type);
3423 fops->destroy(dev, flow);
3427 * Flow driver find RSS policy tbl API. This abstracts calling driver
3428 * specific functions. Parent flow (rte_flow) should have driver
3429 * type (drv_type). It will find the RSS policy table that has the rss_desc.
3432 * Pointer to Ethernet device.
3433 * @param[in, out] flow
3434 * Pointer to flow structure.
3436 * Pointer to meter policy table.
3437 * @param[in] rss_desc
3438 * Pointer to rss_desc
3440 static struct mlx5_flow_meter_sub_policy *
3441 flow_drv_meter_sub_policy_rss_prepare(struct rte_eth_dev *dev,
3442 struct rte_flow *flow,
3443 struct mlx5_flow_meter_policy *policy,
3444 struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS])
3446 const struct mlx5_flow_driver_ops *fops;
3447 enum mlx5_flow_drv_type type = flow->drv_type;
3449 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3450 fops = flow_get_drv_ops(type);
3451 return fops->meter_sub_policy_rss_prepare(dev, policy, rss_desc);
3455 * Get RSS action from the action list.
3458 * Pointer to Ethernet device.
3459 * @param[in] actions
3460 * Pointer to the list of actions.
3462 * Parent flow structure pointer.
3465 * Pointer to the RSS action if exist, else return NULL.
3467 static const struct rte_flow_action_rss*
3468 flow_get_rss_action(struct rte_eth_dev *dev,
3469 const struct rte_flow_action actions[])
3471 struct mlx5_priv *priv = dev->data->dev_private;
3472 const struct rte_flow_action_rss *rss = NULL;
3474 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3475 switch (actions->type) {
3476 case RTE_FLOW_ACTION_TYPE_RSS:
3477 rss = actions->conf;
3479 case RTE_FLOW_ACTION_TYPE_SAMPLE:
3481 const struct rte_flow_action_sample *sample =
3483 const struct rte_flow_action *act = sample->actions;
3484 for (; act->type != RTE_FLOW_ACTION_TYPE_END; act++)
3485 if (act->type == RTE_FLOW_ACTION_TYPE_RSS)
3489 case RTE_FLOW_ACTION_TYPE_METER:
3492 struct mlx5_flow_meter_info *fm;
3493 struct mlx5_flow_meter_policy *policy;
3494 const struct rte_flow_action_meter *mtr = actions->conf;
3496 fm = mlx5_flow_meter_find(priv, mtr->mtr_id, &mtr_idx);
3498 policy = mlx5_flow_meter_policy_find(dev,
3499 fm->policy_id, NULL);
3500 if (policy && policy->is_rss)
3502 policy->act_cnt[RTE_COLOR_GREEN].rss->conf;
3514 * Get ASO age action by index.
3517 * Pointer to the Ethernet device structure.
3518 * @param[in] age_idx
3519 * Index to the ASO age action.
3522 * The specified ASO age action.
3524 struct mlx5_aso_age_action*
3525 flow_aso_age_get_by_idx(struct rte_eth_dev *dev, uint32_t age_idx)
3527 uint16_t pool_idx = age_idx & UINT16_MAX;
3528 uint16_t offset = (age_idx >> 16) & UINT16_MAX;
3529 struct mlx5_priv *priv = dev->data->dev_private;
3530 struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
3531 struct mlx5_aso_age_pool *pool = mng->pools[pool_idx];
3533 return &pool->actions[offset - 1];
3536 /* maps indirect action to translated direct in some actions array */
3537 struct mlx5_translated_action_handle {
3538 struct rte_flow_action_handle *action; /**< Indirect action handle. */
3539 int index; /**< Index in related array of rte_flow_action. */
3543 * Translates actions of type RTE_FLOW_ACTION_TYPE_INDIRECT to related
3544 * direct action if translation possible.
3545 * This functionality used to run same execution path for both direct and
3546 * indirect actions on flow create. All necessary preparations for indirect
3547 * action handling should be performed on *handle* actions list returned
3551 * Pointer to Ethernet device.
3552 * @param[in] actions
3553 * List of actions to translate.
3554 * @param[out] handle
3555 * List to store translated indirect action object handles.
3556 * @param[in, out] indir_n
3557 * Size of *handle* array. On return should be updated with number of
3558 * indirect actions retrieved from the *actions* list.
3559 * @param[out] translated_actions
3560 * List of actions where all indirect actions were translated to direct
3561 * if possible. NULL if no translation took place.
3563 * Pointer to the error structure.
3566 * 0 on success, a negative errno value otherwise and rte_errno is set.
3569 flow_action_handles_translate(struct rte_eth_dev *dev,
3570 const struct rte_flow_action actions[],
3571 struct mlx5_translated_action_handle *handle,
3573 struct rte_flow_action **translated_actions,
3574 struct rte_flow_error *error)
3576 struct mlx5_priv *priv = dev->data->dev_private;
3577 struct rte_flow_action *translated = NULL;
3578 size_t actions_size;
3581 struct mlx5_translated_action_handle *handle_end = NULL;
3583 for (n = 0; actions[n].type != RTE_FLOW_ACTION_TYPE_END; n++) {
3584 if (actions[n].type != RTE_FLOW_ACTION_TYPE_INDIRECT)
3586 if (copied_n == *indir_n) {
3587 return rte_flow_error_set
3588 (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION_NUM,
3589 NULL, "too many shared actions");
3591 rte_memcpy(&handle[copied_n].action, &actions[n].conf,
3592 sizeof(actions[n].conf));
3593 handle[copied_n].index = n;
3597 *indir_n = copied_n;
3600 actions_size = sizeof(struct rte_flow_action) * n;
3601 translated = mlx5_malloc(MLX5_MEM_ZERO, actions_size, 0, SOCKET_ID_ANY);
3606 memcpy(translated, actions, actions_size);
3607 for (handle_end = handle + copied_n; handle < handle_end; handle++) {
3608 struct mlx5_shared_action_rss *shared_rss;
3609 uint32_t act_idx = (uint32_t)(uintptr_t)handle->action;
3610 uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
3611 uint32_t idx = act_idx &
3612 ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
3615 case MLX5_INDIRECT_ACTION_TYPE_RSS:
3616 shared_rss = mlx5_ipool_get
3617 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
3618 translated[handle->index].type =
3619 RTE_FLOW_ACTION_TYPE_RSS;
3620 translated[handle->index].conf =
3621 &shared_rss->origin;
3623 case MLX5_INDIRECT_ACTION_TYPE_COUNT:
3624 translated[handle->index].type =
3625 (enum rte_flow_action_type)
3626 MLX5_RTE_FLOW_ACTION_TYPE_COUNT;
3627 translated[handle->index].conf = (void *)(uintptr_t)idx;
3629 case MLX5_INDIRECT_ACTION_TYPE_AGE:
3630 if (priv->sh->flow_hit_aso_en) {
3631 translated[handle->index].type =
3632 (enum rte_flow_action_type)
3633 MLX5_RTE_FLOW_ACTION_TYPE_AGE;
3634 translated[handle->index].conf =
3635 (void *)(uintptr_t)idx;
3639 case MLX5_INDIRECT_ACTION_TYPE_CT:
3640 if (priv->sh->ct_aso_en) {
3641 translated[handle->index].type =
3642 RTE_FLOW_ACTION_TYPE_CONNTRACK;
3643 translated[handle->index].conf =
3644 (void *)(uintptr_t)idx;
3649 mlx5_free(translated);
3650 return rte_flow_error_set
3651 (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
3652 NULL, "invalid indirect action type");
3655 *translated_actions = translated;
3660 * Get Shared RSS action from the action list.
3663 * Pointer to Ethernet device.
3665 * Pointer to the list of actions.
3666 * @param[in] shared_n
3667 * Actions list length.
3670 * The MLX5 RSS action ID if exists, otherwise return 0.
3673 flow_get_shared_rss_action(struct rte_eth_dev *dev,
3674 struct mlx5_translated_action_handle *handle,
3677 struct mlx5_translated_action_handle *handle_end;
3678 struct mlx5_priv *priv = dev->data->dev_private;
3679 struct mlx5_shared_action_rss *shared_rss;
3682 for (handle_end = handle + shared_n; handle < handle_end; handle++) {
3683 uint32_t act_idx = (uint32_t)(uintptr_t)handle->action;
3684 uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
3685 uint32_t idx = act_idx &
3686 ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
3688 case MLX5_INDIRECT_ACTION_TYPE_RSS:
3689 shared_rss = mlx5_ipool_get
3690 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
3692 __atomic_add_fetch(&shared_rss->refcnt, 1,
3703 find_graph_root(const struct rte_flow_item pattern[], uint32_t rss_level)
3705 const struct rte_flow_item *item;
3706 unsigned int has_vlan = 0;
3708 for (item = pattern; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
3709 if (item->type == RTE_FLOW_ITEM_TYPE_VLAN) {
3715 return rss_level < 2 ? MLX5_EXPANSION_ROOT_ETH_VLAN :
3716 MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN;
3717 return rss_level < 2 ? MLX5_EXPANSION_ROOT :
3718 MLX5_EXPANSION_ROOT_OUTER;
3722 * Get layer flags from the prefix flow.
3724 * Some flows may be split to several subflows, the prefix subflow gets the
3725 * match items and the suffix sub flow gets the actions.
3726 * Some actions need the user defined match item flags to get the detail for
3728 * This function helps the suffix flow to get the item layer flags from prefix
3731 * @param[in] dev_flow
3732 * Pointer the created preifx subflow.
3735 * The layers get from prefix subflow.
3737 static inline uint64_t
3738 flow_get_prefix_layer_flags(struct mlx5_flow *dev_flow)
3740 uint64_t layers = 0;
3743 * Layers bits could be localization, but usually the compiler will
3744 * help to do the optimization work for source code.
3745 * If no decap actions, use the layers directly.
3747 if (!(dev_flow->act_flags & MLX5_FLOW_ACTION_DECAP))
3748 return dev_flow->handle->layers;
3749 /* Convert L3 layers with decap action. */
3750 if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L3_IPV4)
3751 layers |= MLX5_FLOW_LAYER_OUTER_L3_IPV4;
3752 else if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L3_IPV6)
3753 layers |= MLX5_FLOW_LAYER_OUTER_L3_IPV6;
3754 /* Convert L4 layers with decap action. */
3755 if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L4_TCP)
3756 layers |= MLX5_FLOW_LAYER_OUTER_L4_TCP;
3757 else if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L4_UDP)
3758 layers |= MLX5_FLOW_LAYER_OUTER_L4_UDP;
3763 * Get metadata split action information.
3765 * @param[in] actions
3766 * Pointer to the list of actions.
3768 * Pointer to the return pointer.
3769 * @param[out] qrss_type
3770 * Pointer to the action type to return. RTE_FLOW_ACTION_TYPE_END is returned
3771 * if no QUEUE/RSS is found.
3772 * @param[out] encap_idx
3773 * Pointer to the index of the encap action if exists, otherwise the last
3777 * Total number of actions.
3780 flow_parse_metadata_split_actions_info(const struct rte_flow_action actions[],
3781 const struct rte_flow_action **qrss,
3784 const struct rte_flow_action_raw_encap *raw_encap;
3786 int raw_decap_idx = -1;
3789 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3790 switch (actions->type) {
3791 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
3792 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
3793 *encap_idx = actions_n;
3795 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
3796 raw_decap_idx = actions_n;
3798 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
3799 raw_encap = actions->conf;
3800 if (raw_encap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
3801 *encap_idx = raw_decap_idx != -1 ?
3802 raw_decap_idx : actions_n;
3804 case RTE_FLOW_ACTION_TYPE_QUEUE:
3805 case RTE_FLOW_ACTION_TYPE_RSS:
3813 if (*encap_idx == -1)
3814 *encap_idx = actions_n;
3815 /* Count RTE_FLOW_ACTION_TYPE_END. */
3816 return actions_n + 1;
3820 * Check if the action will change packet.
3823 * Pointer to Ethernet device.
3828 * true if action will change packet, false otherwise.
3830 static bool flow_check_modify_action_type(struct rte_eth_dev *dev,
3831 enum rte_flow_action_type type)
3833 struct mlx5_priv *priv = dev->data->dev_private;
3836 case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
3837 case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
3838 case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
3839 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
3840 case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
3841 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
3842 case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
3843 case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
3844 case RTE_FLOW_ACTION_TYPE_DEC_TTL:
3845 case RTE_FLOW_ACTION_TYPE_SET_TTL:
3846 case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
3847 case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
3848 case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
3849 case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
3850 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
3851 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
3852 case RTE_FLOW_ACTION_TYPE_SET_META:
3853 case RTE_FLOW_ACTION_TYPE_SET_TAG:
3854 case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
3855 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
3856 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
3857 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
3858 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
3859 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
3860 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
3861 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
3862 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
3863 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
3864 case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
3866 case RTE_FLOW_ACTION_TYPE_FLAG:
3867 case RTE_FLOW_ACTION_TYPE_MARK:
3868 if (priv->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY)
3878 * Check meter action from the action list.
3881 * Pointer to Ethernet device.
3882 * @param[in] actions
3883 * Pointer to the list of actions.
3884 * @param[out] has_mtr
3885 * Pointer to the meter exist flag.
3886 * @param[out] has_modify
3887 * Pointer to the flag showing there's packet change action.
3888 * @param[out] meter_id
3889 * Pointer to the meter id.
3892 * Total number of actions.
3895 flow_check_meter_action(struct rte_eth_dev *dev,
3896 const struct rte_flow_action actions[],
3897 bool *has_mtr, bool *has_modify, uint32_t *meter_id)
3899 const struct rte_flow_action_meter *mtr = NULL;
3902 MLX5_ASSERT(has_mtr);
3904 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3905 switch (actions->type) {
3906 case RTE_FLOW_ACTION_TYPE_METER:
3907 mtr = actions->conf;
3908 *meter_id = mtr->mtr_id;
3915 *has_modify |= flow_check_modify_action_type(dev,
3919 /* Count RTE_FLOW_ACTION_TYPE_END. */
3920 return actions_n + 1;
3924 * Check if the flow should be split due to hairpin.
3925 * The reason for the split is that in current HW we can't
3926 * support encap and push-vlan on Rx, so if a flow contains
3927 * these actions we move it to Tx.
3930 * Pointer to Ethernet device.
3932 * Flow rule attributes.
3933 * @param[in] actions
3934 * Associated actions (list terminated by the END action).
3937 * > 0 the number of actions and the flow should be split,
3938 * 0 when no split required.
3941 flow_check_hairpin_split(struct rte_eth_dev *dev,
3942 const struct rte_flow_attr *attr,
3943 const struct rte_flow_action actions[])
3945 int queue_action = 0;
3948 const struct rte_flow_action_queue *queue;
3949 const struct rte_flow_action_rss *rss;
3950 const struct rte_flow_action_raw_encap *raw_encap;
3951 const struct rte_eth_hairpin_conf *conf;
3955 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3956 switch (actions->type) {
3957 case RTE_FLOW_ACTION_TYPE_QUEUE:
3958 queue = actions->conf;
3961 conf = mlx5_rxq_get_hairpin_conf(dev, queue->index);
3962 if (conf == NULL || conf->tx_explicit != 0)
3967 case RTE_FLOW_ACTION_TYPE_RSS:
3968 rss = actions->conf;
3969 if (rss == NULL || rss->queue_num == 0)
3971 conf = mlx5_rxq_get_hairpin_conf(dev, rss->queue[0]);
3972 if (conf == NULL || conf->tx_explicit != 0)
3977 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
3978 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
3979 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
3980 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
3981 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
3985 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
3986 raw_encap = actions->conf;
3987 if (raw_encap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
3996 if (split && queue_action)
4001 /* Declare flow create/destroy prototype in advance. */
4003 flow_list_create(struct rte_eth_dev *dev, uint32_t *list,
4004 const struct rte_flow_attr *attr,
4005 const struct rte_flow_item items[],
4006 const struct rte_flow_action actions[],
4007 bool external, struct rte_flow_error *error);
4010 flow_list_destroy(struct rte_eth_dev *dev, uint32_t *list,
4014 flow_dv_mreg_match_cb(struct mlx5_hlist *list __rte_unused,
4015 struct mlx5_hlist_entry *entry,
4016 uint64_t key, void *cb_ctx __rte_unused)
4018 struct mlx5_flow_mreg_copy_resource *mcp_res =
4019 container_of(entry, typeof(*mcp_res), hlist_ent);
4021 return mcp_res->mark_id != key;
4024 struct mlx5_hlist_entry *
4025 flow_dv_mreg_create_cb(struct mlx5_hlist *list, uint64_t key,
4028 struct rte_eth_dev *dev = list->ctx;
4029 struct mlx5_priv *priv = dev->data->dev_private;
4030 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4031 struct mlx5_flow_mreg_copy_resource *mcp_res;
4032 struct rte_flow_error *error = ctx->error;
4035 uint32_t mark_id = key;
4036 struct rte_flow_attr attr = {
4037 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
4040 struct mlx5_rte_flow_item_tag tag_spec = {
4043 struct rte_flow_item items[] = {
4044 [1] = { .type = RTE_FLOW_ITEM_TYPE_END, },
4046 struct rte_flow_action_mark ftag = {
4049 struct mlx5_flow_action_copy_mreg cp_mreg = {
4053 struct rte_flow_action_jump jump = {
4054 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
4056 struct rte_flow_action actions[] = {
4057 [3] = { .type = RTE_FLOW_ACTION_TYPE_END, },
4060 /* Fill the register fileds in the flow. */
4061 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
4065 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_RX, 0, error);
4069 /* Provide the full width of FLAG specific value. */
4070 if (mark_id == (priv->sh->dv_regc0_mask & MLX5_FLOW_MARK_DEFAULT))
4071 tag_spec.data = MLX5_FLOW_MARK_DEFAULT;
4072 /* Build a new flow. */
4073 if (mark_id != MLX5_DEFAULT_COPY_ID) {
4074 items[0] = (struct rte_flow_item){
4075 .type = (enum rte_flow_item_type)
4076 MLX5_RTE_FLOW_ITEM_TYPE_TAG,
4079 items[1] = (struct rte_flow_item){
4080 .type = RTE_FLOW_ITEM_TYPE_END,
4082 actions[0] = (struct rte_flow_action){
4083 .type = (enum rte_flow_action_type)
4084 MLX5_RTE_FLOW_ACTION_TYPE_MARK,
4087 actions[1] = (struct rte_flow_action){
4088 .type = (enum rte_flow_action_type)
4089 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
4092 actions[2] = (struct rte_flow_action){
4093 .type = RTE_FLOW_ACTION_TYPE_JUMP,
4096 actions[3] = (struct rte_flow_action){
4097 .type = RTE_FLOW_ACTION_TYPE_END,
4100 /* Default rule, wildcard match. */
4101 attr.priority = MLX5_FLOW_LOWEST_PRIO_INDICATOR;
4102 items[0] = (struct rte_flow_item){
4103 .type = RTE_FLOW_ITEM_TYPE_END,
4105 actions[0] = (struct rte_flow_action){
4106 .type = (enum rte_flow_action_type)
4107 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
4110 actions[1] = (struct rte_flow_action){
4111 .type = RTE_FLOW_ACTION_TYPE_JUMP,
4114 actions[2] = (struct rte_flow_action){
4115 .type = RTE_FLOW_ACTION_TYPE_END,
4118 /* Build a new entry. */
4119 mcp_res = mlx5_ipool_zmalloc(priv->sh->ipool[MLX5_IPOOL_MCP], &idx);
4125 mcp_res->mark_id = mark_id;
4127 * The copy Flows are not included in any list. There
4128 * ones are referenced from other Flows and can not
4129 * be applied, removed, deleted in ardbitrary order
4130 * by list traversing.
4132 mcp_res->rix_flow = flow_list_create(dev, NULL, &attr, items,
4133 actions, false, error);
4134 if (!mcp_res->rix_flow) {
4135 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], idx);
4138 return &mcp_res->hlist_ent;
4142 * Add a flow of copying flow metadata registers in RX_CP_TBL.
4144 * As mark_id is unique, if there's already a registered flow for the mark_id,
4145 * return by increasing the reference counter of the resource. Otherwise, create
4146 * the resource (mcp_res) and flow.
4149 * - If ingress port is ANY and reg_c[1] is mark_id,
4150 * flow_tag := mark_id, reg_b := reg_c[0] and jump to RX_ACT_TBL.
4152 * For default flow (zero mark_id), flow is like,
4153 * - If ingress port is ANY,
4154 * reg_b := reg_c[0] and jump to RX_ACT_TBL.
4157 * Pointer to Ethernet device.
4159 * ID of MARK action, zero means default flow for META.
4161 * Perform verbose error reporting if not NULL.
4164 * Associated resource on success, NULL otherwise and rte_errno is set.
4166 static struct mlx5_flow_mreg_copy_resource *
4167 flow_mreg_add_copy_action(struct rte_eth_dev *dev, uint32_t mark_id,
4168 struct rte_flow_error *error)
4170 struct mlx5_priv *priv = dev->data->dev_private;
4171 struct mlx5_hlist_entry *entry;
4172 struct mlx5_flow_cb_ctx ctx = {
4177 /* Check if already registered. */
4178 MLX5_ASSERT(priv->mreg_cp_tbl);
4179 entry = mlx5_hlist_register(priv->mreg_cp_tbl, mark_id, &ctx);
4182 return container_of(entry, struct mlx5_flow_mreg_copy_resource,
4187 flow_dv_mreg_remove_cb(struct mlx5_hlist *list, struct mlx5_hlist_entry *entry)
4189 struct mlx5_flow_mreg_copy_resource *mcp_res =
4190 container_of(entry, typeof(*mcp_res), hlist_ent);
4191 struct rte_eth_dev *dev = list->ctx;
4192 struct mlx5_priv *priv = dev->data->dev_private;
4194 MLX5_ASSERT(mcp_res->rix_flow);
4195 flow_list_destroy(dev, NULL, mcp_res->rix_flow);
4196 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], mcp_res->idx);
4200 * Release flow in RX_CP_TBL.
4203 * Pointer to Ethernet device.
4205 * Parent flow for wich copying is provided.
4208 flow_mreg_del_copy_action(struct rte_eth_dev *dev,
4209 struct rte_flow *flow)
4211 struct mlx5_flow_mreg_copy_resource *mcp_res;
4212 struct mlx5_priv *priv = dev->data->dev_private;
4214 if (!flow->rix_mreg_copy)
4216 mcp_res = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MCP],
4217 flow->rix_mreg_copy);
4218 if (!mcp_res || !priv->mreg_cp_tbl)
4220 MLX5_ASSERT(mcp_res->rix_flow);
4221 mlx5_hlist_unregister(priv->mreg_cp_tbl, &mcp_res->hlist_ent);
4222 flow->rix_mreg_copy = 0;
4226 * Remove the default copy action from RX_CP_TBL.
4228 * This functions is called in the mlx5_dev_start(). No thread safe
4232 * Pointer to Ethernet device.
4235 flow_mreg_del_default_copy_action(struct rte_eth_dev *dev)
4237 struct mlx5_hlist_entry *entry;
4238 struct mlx5_priv *priv = dev->data->dev_private;
4240 /* Check if default flow is registered. */
4241 if (!priv->mreg_cp_tbl)
4243 entry = mlx5_hlist_lookup(priv->mreg_cp_tbl,
4244 MLX5_DEFAULT_COPY_ID, NULL);
4247 mlx5_hlist_unregister(priv->mreg_cp_tbl, entry);
4251 * Add the default copy action in in RX_CP_TBL.
4253 * This functions is called in the mlx5_dev_start(). No thread safe
4257 * Pointer to Ethernet device.
4259 * Perform verbose error reporting if not NULL.
4262 * 0 for success, negative value otherwise and rte_errno is set.
4265 flow_mreg_add_default_copy_action(struct rte_eth_dev *dev,
4266 struct rte_flow_error *error)
4268 struct mlx5_priv *priv = dev->data->dev_private;
4269 struct mlx5_flow_mreg_copy_resource *mcp_res;
4271 /* Check whether extensive metadata feature is engaged. */
4272 if (!priv->config.dv_flow_en ||
4273 priv->config.dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
4274 !mlx5_flow_ext_mreg_supported(dev) ||
4275 !priv->sh->dv_regc0_mask)
4278 * Add default mreg copy flow may be called multiple time, but
4279 * only be called once in stop. Avoid register it twice.
4281 if (mlx5_hlist_lookup(priv->mreg_cp_tbl, MLX5_DEFAULT_COPY_ID, NULL))
4283 mcp_res = flow_mreg_add_copy_action(dev, MLX5_DEFAULT_COPY_ID, error);
4290 * Add a flow of copying flow metadata registers in RX_CP_TBL.
4292 * All the flow having Q/RSS action should be split by
4293 * flow_mreg_split_qrss_prep() to pass by RX_CP_TBL. A flow in the RX_CP_TBL
4294 * performs the following,
4295 * - CQE->flow_tag := reg_c[1] (MARK)
4296 * - CQE->flow_table_metadata (reg_b) := reg_c[0] (META)
4297 * As CQE's flow_tag is not a register, it can't be simply copied from reg_c[1]
4298 * but there should be a flow per each MARK ID set by MARK action.
4300 * For the aforementioned reason, if there's a MARK action in flow's action
4301 * list, a corresponding flow should be added to the RX_CP_TBL in order to copy
4302 * the MARK ID to CQE's flow_tag like,
4303 * - If reg_c[1] is mark_id,
4304 * flow_tag := mark_id, reg_b := reg_c[0] and jump to RX_ACT_TBL.
4306 * For SET_META action which stores value in reg_c[0], as the destination is
4307 * also a flow metadata register (reg_b), adding a default flow is enough. Zero
4308 * MARK ID means the default flow. The default flow looks like,
4309 * - For all flow, reg_b := reg_c[0] and jump to RX_ACT_TBL.
4312 * Pointer to Ethernet device.
4314 * Pointer to flow structure.
4315 * @param[in] actions
4316 * Pointer to the list of actions.
4318 * Perform verbose error reporting if not NULL.
4321 * 0 on success, negative value otherwise and rte_errno is set.
4324 flow_mreg_update_copy_table(struct rte_eth_dev *dev,
4325 struct rte_flow *flow,
4326 const struct rte_flow_action *actions,
4327 struct rte_flow_error *error)
4329 struct mlx5_priv *priv = dev->data->dev_private;
4330 struct mlx5_dev_config *config = &priv->config;
4331 struct mlx5_flow_mreg_copy_resource *mcp_res;
4332 const struct rte_flow_action_mark *mark;
4334 /* Check whether extensive metadata feature is engaged. */
4335 if (!config->dv_flow_en ||
4336 config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
4337 !mlx5_flow_ext_mreg_supported(dev) ||
4338 !priv->sh->dv_regc0_mask)
4340 /* Find MARK action. */
4341 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4342 switch (actions->type) {
4343 case RTE_FLOW_ACTION_TYPE_FLAG:
4344 mcp_res = flow_mreg_add_copy_action
4345 (dev, MLX5_FLOW_MARK_DEFAULT, error);
4348 flow->rix_mreg_copy = mcp_res->idx;
4350 case RTE_FLOW_ACTION_TYPE_MARK:
4351 mark = (const struct rte_flow_action_mark *)
4354 flow_mreg_add_copy_action(dev, mark->id, error);
4357 flow->rix_mreg_copy = mcp_res->idx;
4366 #define MLX5_MAX_SPLIT_ACTIONS 24
4367 #define MLX5_MAX_SPLIT_ITEMS 24
4370 * Split the hairpin flow.
4371 * Since HW can't support encap and push-vlan on Rx, we move these
4373 * If the count action is after the encap then we also
4374 * move the count action. in this case the count will also measure
4378 * Pointer to Ethernet device.
4379 * @param[in] actions
4380 * Associated actions (list terminated by the END action).
4381 * @param[out] actions_rx
4383 * @param[out] actions_tx
4385 * @param[out] pattern_tx
4386 * The pattern items for the Tx flow.
4387 * @param[out] flow_id
4388 * The flow ID connected to this flow.
4394 flow_hairpin_split(struct rte_eth_dev *dev,
4395 const struct rte_flow_action actions[],
4396 struct rte_flow_action actions_rx[],
4397 struct rte_flow_action actions_tx[],
4398 struct rte_flow_item pattern_tx[],
4401 const struct rte_flow_action_raw_encap *raw_encap;
4402 const struct rte_flow_action_raw_decap *raw_decap;
4403 struct mlx5_rte_flow_action_set_tag *set_tag;
4404 struct rte_flow_action *tag_action;
4405 struct mlx5_rte_flow_item_tag *tag_item;
4406 struct rte_flow_item *item;
4410 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4411 switch (actions->type) {
4412 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
4413 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
4414 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
4415 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
4416 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
4417 rte_memcpy(actions_tx, actions,
4418 sizeof(struct rte_flow_action));
4421 case RTE_FLOW_ACTION_TYPE_COUNT:
4423 rte_memcpy(actions_tx, actions,
4424 sizeof(struct rte_flow_action));
4427 rte_memcpy(actions_rx, actions,
4428 sizeof(struct rte_flow_action));
4432 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
4433 raw_encap = actions->conf;
4434 if (raw_encap->size > MLX5_ENCAPSULATION_DECISION_SIZE) {
4435 memcpy(actions_tx, actions,
4436 sizeof(struct rte_flow_action));
4440 rte_memcpy(actions_rx, actions,
4441 sizeof(struct rte_flow_action));
4445 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
4446 raw_decap = actions->conf;
4447 if (raw_decap->size < MLX5_ENCAPSULATION_DECISION_SIZE) {
4448 memcpy(actions_tx, actions,
4449 sizeof(struct rte_flow_action));
4452 rte_memcpy(actions_rx, actions,
4453 sizeof(struct rte_flow_action));
4458 rte_memcpy(actions_rx, actions,
4459 sizeof(struct rte_flow_action));
4464 /* Add set meta action and end action for the Rx flow. */
4465 tag_action = actions_rx;
4466 tag_action->type = (enum rte_flow_action_type)
4467 MLX5_RTE_FLOW_ACTION_TYPE_TAG;
4469 rte_memcpy(actions_rx, actions, sizeof(struct rte_flow_action));
4471 set_tag = (void *)actions_rx;
4472 *set_tag = (struct mlx5_rte_flow_action_set_tag) {
4473 .id = mlx5_flow_get_reg_id(dev, MLX5_HAIRPIN_RX, 0, NULL),
4476 MLX5_ASSERT(set_tag->id > REG_NON);
4477 tag_action->conf = set_tag;
4478 /* Create Tx item list. */
4479 rte_memcpy(actions_tx, actions, sizeof(struct rte_flow_action));
4480 addr = (void *)&pattern_tx[2];
4482 item->type = (enum rte_flow_item_type)
4483 MLX5_RTE_FLOW_ITEM_TYPE_TAG;
4484 tag_item = (void *)addr;
4485 tag_item->data = flow_id;
4486 tag_item->id = mlx5_flow_get_reg_id(dev, MLX5_HAIRPIN_TX, 0, NULL);
4487 MLX5_ASSERT(set_tag->id > REG_NON);
4488 item->spec = tag_item;
4489 addr += sizeof(struct mlx5_rte_flow_item_tag);
4490 tag_item = (void *)addr;
4491 tag_item->data = UINT32_MAX;
4492 tag_item->id = UINT16_MAX;
4493 item->mask = tag_item;
4496 item->type = RTE_FLOW_ITEM_TYPE_END;
4501 * The last stage of splitting chain, just creates the subflow
4502 * without any modification.
4505 * Pointer to Ethernet device.
4507 * Parent flow structure pointer.
4508 * @param[in, out] sub_flow
4509 * Pointer to return the created subflow, may be NULL.
4511 * Flow rule attributes.
4513 * Pattern specification (list terminated by the END pattern item).
4514 * @param[in] actions
4515 * Associated actions (list terminated by the END action).
4516 * @param[in] flow_split_info
4517 * Pointer to flow split info structure.
4519 * Perform verbose error reporting if not NULL.
4521 * 0 on success, negative value otherwise
4524 flow_create_split_inner(struct rte_eth_dev *dev,
4525 struct rte_flow *flow,
4526 struct mlx5_flow **sub_flow,
4527 const struct rte_flow_attr *attr,
4528 const struct rte_flow_item items[],
4529 const struct rte_flow_action actions[],
4530 struct mlx5_flow_split_info *flow_split_info,
4531 struct rte_flow_error *error)
4533 struct mlx5_flow *dev_flow;
4535 dev_flow = flow_drv_prepare(dev, flow, attr, items, actions,
4536 flow_split_info->flow_idx, error);
4539 dev_flow->flow = flow;
4540 dev_flow->external = flow_split_info->external;
4541 dev_flow->skip_scale = flow_split_info->skip_scale;
4542 /* Subflow object was created, we must include one in the list. */
4543 SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
4544 dev_flow->handle, next);
4546 * If dev_flow is as one of the suffix flow, some actions in suffix
4547 * flow may need some user defined item layer flags, and pass the
4548 * Metadate rxq mark flag to suffix flow as well.
4550 if (flow_split_info->prefix_layers)
4551 dev_flow->handle->layers = flow_split_info->prefix_layers;
4552 if (flow_split_info->prefix_mark)
4553 dev_flow->handle->mark = 1;
4555 *sub_flow = dev_flow;
4556 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
4557 dev_flow->dv.table_id = flow_split_info->table_id;
4559 return flow_drv_translate(dev, dev_flow, attr, items, actions, error);
4563 * Get the sub policy of a meter.
4566 * Pointer to Ethernet device.
4568 * Parent flow structure pointer.
4569 * @param[in] policy_id;
4572 * Flow rule attributes.
4574 * Pattern specification (list terminated by the END pattern item).
4576 * Perform verbose error reporting if not NULL.
4579 * Pointer to the meter sub policy, NULL otherwise and rte_errno is set.
4581 static struct mlx5_flow_meter_sub_policy *
4582 get_meter_sub_policy(struct rte_eth_dev *dev,
4583 struct rte_flow *flow,
4585 const struct rte_flow_attr *attr,
4586 const struct rte_flow_item items[],
4587 struct rte_flow_error *error)
4589 struct mlx5_flow_meter_policy *policy;
4590 struct mlx5_flow_meter_sub_policy *sub_policy = NULL;
4592 policy = mlx5_flow_meter_policy_find(dev, policy_id, NULL);
4594 rte_flow_error_set(error, EINVAL,
4595 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4596 "Failed to find Meter Policy.");
4599 if (policy->is_rss ||
4600 (policy->is_queue &&
4601 !policy->sub_policys[MLX5_MTR_DOMAIN_INGRESS][0]->rix_hrxq[0])) {
4602 struct mlx5_flow_workspace *wks =
4603 mlx5_flow_get_thread_workspace();
4604 struct mlx5_flow_rss_desc rss_desc_v[MLX5_MTR_RTE_COLORS];
4605 struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS] = {0};
4610 * This is a tmp dev_flow,
4611 * no need to register any matcher for it in translate.
4613 wks->skip_matcher_reg = 1;
4614 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
4615 struct mlx5_flow dev_flow = {0};
4616 struct mlx5_flow_handle dev_handle = { {0} };
4618 if (policy->is_rss) {
4619 const void *rss_act =
4620 policy->act_cnt[i].rss->conf;
4621 struct rte_flow_action rss_actions[2] = {
4623 .type = RTE_FLOW_ACTION_TYPE_RSS,
4627 .type = RTE_FLOW_ACTION_TYPE_END,
4632 dev_flow.handle = &dev_handle;
4633 dev_flow.ingress = attr->ingress;
4634 dev_flow.flow = flow;
4635 dev_flow.external = 0;
4636 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
4637 dev_flow.dv.transfer = attr->transfer;
4640 * Translate RSS action to get rss hash fields.
4642 if (flow_drv_translate(dev, &dev_flow, attr,
4643 items, rss_actions, error))
4645 rss_desc_v[i] = wks->rss_desc;
4646 rss_desc_v[i].key_len = MLX5_RSS_HASH_KEY_LEN;
4647 rss_desc_v[i].hash_fields =
4648 dev_flow.hash_fields;
4649 rss_desc_v[i].queue_num =
4650 rss_desc_v[i].hash_fields ?
4651 rss_desc_v[i].queue_num : 1;
4652 rss_desc_v[i].tunnel =
4653 !!(dev_flow.handle->layers &
4654 MLX5_FLOW_LAYER_TUNNEL);
4656 /* This is queue action. */
4657 rss_desc_v[i] = wks->rss_desc;
4658 rss_desc_v[i].key_len = 0;
4659 rss_desc_v[i].hash_fields = 0;
4660 rss_desc_v[i].queue =
4661 &policy->act_cnt[i].queue;
4662 rss_desc_v[i].queue_num = 1;
4664 rss_desc[i] = &rss_desc_v[i];
4666 sub_policy = flow_drv_meter_sub_policy_rss_prepare(dev,
4667 flow, policy, rss_desc);
4669 enum mlx5_meter_domain mtr_domain =
4670 attr->transfer ? MLX5_MTR_DOMAIN_TRANSFER :
4671 attr->egress ? MLX5_MTR_DOMAIN_EGRESS :
4672 MLX5_MTR_DOMAIN_INGRESS;
4673 sub_policy = policy->sub_policys[mtr_domain][0];
4676 rte_flow_error_set(error, EINVAL,
4677 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4678 "Failed to get meter sub-policy.");
4686 * Split the meter flow.
4688 * As meter flow will split to three sub flow, other than meter
4689 * action, the other actions make sense to only meter accepts
4690 * the packet. If it need to be dropped, no other additional
4691 * actions should be take.
4693 * One kind of special action which decapsulates the L3 tunnel
4694 * header will be in the prefix sub flow, as not to take the
4695 * L3 tunnel header into account.
4698 * Pointer to Ethernet device.
4700 * Parent flow structure pointer.
4702 * Pointer to flow meter structure.
4704 * Flow rule attributes.
4706 * Pattern specification (list terminated by the END pattern item).
4707 * @param[out] sfx_items
4708 * Suffix flow match items (list terminated by the END pattern item).
4709 * @param[in] actions
4710 * Associated actions (list terminated by the END action).
4711 * @param[out] actions_sfx
4712 * Suffix flow actions.
4713 * @param[out] actions_pre
4714 * Prefix flow actions.
4715 * @param[out] mtr_flow_id
4716 * Pointer to meter flow id.
4718 * Perform verbose error reporting if not NULL.
4721 * 0 on success, a negative errno value otherwise and rte_errno is set.
4724 flow_meter_split_prep(struct rte_eth_dev *dev,
4725 struct rte_flow *flow,
4726 struct mlx5_flow_meter_info *fm,
4727 const struct rte_flow_attr *attr,
4728 const struct rte_flow_item items[],
4729 struct rte_flow_item sfx_items[],
4730 const struct rte_flow_action actions[],
4731 struct rte_flow_action actions_sfx[],
4732 struct rte_flow_action actions_pre[],
4733 uint32_t *mtr_flow_id,
4734 struct rte_flow_error *error)
4736 struct mlx5_priv *priv = dev->data->dev_private;
4737 struct rte_flow_action *tag_action = NULL;
4738 struct rte_flow_item *tag_item;
4739 struct mlx5_rte_flow_action_set_tag *set_tag;
4740 const struct rte_flow_action_raw_encap *raw_encap;
4741 const struct rte_flow_action_raw_decap *raw_decap;
4742 struct mlx5_rte_flow_item_tag *tag_item_spec;
4743 struct mlx5_rte_flow_item_tag *tag_item_mask;
4744 uint32_t tag_id = 0;
4745 struct rte_flow_item *vlan_item_dst = NULL;
4746 const struct rte_flow_item *vlan_item_src = NULL;
4747 struct rte_flow_action *hw_mtr_action;
4748 struct rte_flow_action *action_pre_head = NULL;
4749 int32_t flow_src_port = priv->representor_id;
4751 uint8_t mtr_id_offset = priv->mtr_reg_share ? MLX5_MTR_COLOR_BITS : 0;
4752 uint8_t mtr_reg_bits = priv->mtr_reg_share ?
4753 MLX5_MTR_IDLE_BITS_IN_COLOR_REG : MLX5_REG_BITS;
4754 uint32_t flow_id = 0;
4755 uint32_t flow_id_reversed = 0;
4756 uint8_t flow_id_bits = 0;
4759 /* Prepare the suffix subflow items. */
4760 tag_item = sfx_items++;
4761 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
4762 struct mlx5_priv *port_priv;
4763 const struct rte_flow_item_port_id *pid_v;
4764 int item_type = items->type;
4766 switch (item_type) {
4767 case RTE_FLOW_ITEM_TYPE_PORT_ID:
4768 pid_v = items->spec;
4770 port_priv = mlx5_port_to_eswitch_info(pid_v->id, false);
4772 return rte_flow_error_set(error,
4774 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
4776 "Failed to get port info.");
4777 flow_src_port = port_priv->representor_id;
4778 memcpy(sfx_items, items, sizeof(*sfx_items));
4781 case RTE_FLOW_ITEM_TYPE_VLAN:
4782 /* Determine if copy vlan item below. */
4783 vlan_item_src = items;
4784 vlan_item_dst = sfx_items++;
4785 vlan_item_dst->type = RTE_FLOW_ITEM_TYPE_VOID;
4791 sfx_items->type = RTE_FLOW_ITEM_TYPE_END;
4793 mtr_first = priv->sh->meter_aso_en &&
4794 (attr->egress || (attr->transfer && flow_src_port != UINT16_MAX));
4795 /* For ASO meter, meter must be before tag in TX direction. */
4797 action_pre_head = actions_pre++;
4798 /* Leave space for tag action. */
4799 tag_action = actions_pre++;
4801 /* Prepare the actions for prefix and suffix flow. */
4802 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4803 struct rte_flow_action *action_cur = NULL;
4805 switch (actions->type) {
4806 case RTE_FLOW_ACTION_TYPE_METER:
4808 action_cur = action_pre_head;
4810 /* Leave space for tag action. */
4811 tag_action = actions_pre++;
4812 action_cur = actions_pre++;
4815 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
4816 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
4817 action_cur = actions_pre++;
4819 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
4820 raw_encap = actions->conf;
4821 if (raw_encap->size < MLX5_ENCAPSULATION_DECISION_SIZE)
4822 action_cur = actions_pre++;
4824 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
4825 raw_decap = actions->conf;
4826 if (raw_decap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
4827 action_cur = actions_pre++;
4829 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
4830 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
4831 if (vlan_item_dst && vlan_item_src) {
4832 memcpy(vlan_item_dst, vlan_item_src,
4833 sizeof(*vlan_item_dst));
4835 * Convert to internal match item, it is used
4836 * for vlan push and set vid.
4838 vlan_item_dst->type = (enum rte_flow_item_type)
4839 MLX5_RTE_FLOW_ITEM_TYPE_VLAN;
4846 action_cur = (fm->def_policy) ?
4847 actions_sfx++ : actions_pre++;
4848 memcpy(action_cur, actions, sizeof(struct rte_flow_action));
4850 /* Add end action to the actions. */
4851 actions_sfx->type = RTE_FLOW_ACTION_TYPE_END;
4852 if (priv->sh->meter_aso_en) {
4854 * For ASO meter, need to add an extra jump action explicitly,
4855 * to jump from meter to policer table.
4857 struct mlx5_flow_meter_sub_policy *sub_policy;
4858 struct mlx5_flow_tbl_data_entry *tbl_data;
4860 if (!fm->def_policy) {
4861 sub_policy = get_meter_sub_policy(dev, flow,
4862 fm->policy_id, attr,
4867 enum mlx5_meter_domain mtr_domain =
4868 attr->transfer ? MLX5_MTR_DOMAIN_TRANSFER :
4869 attr->egress ? MLX5_MTR_DOMAIN_EGRESS :
4870 MLX5_MTR_DOMAIN_INGRESS;
4873 &priv->sh->mtrmng->def_policy[mtr_domain]->sub_policy;
4875 tbl_data = container_of(sub_policy->tbl_rsc,
4876 struct mlx5_flow_tbl_data_entry, tbl);
4877 hw_mtr_action = actions_pre++;
4878 hw_mtr_action->type = (enum rte_flow_action_type)
4879 MLX5_RTE_FLOW_ACTION_TYPE_JUMP;
4880 hw_mtr_action->conf = tbl_data->jump.action;
4882 actions_pre->type = RTE_FLOW_ACTION_TYPE_END;
4885 return rte_flow_error_set(error, ENOMEM,
4886 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4887 "No tag action space.");
4889 tag_action->type = RTE_FLOW_ACTION_TYPE_VOID;
4892 /* Only default-policy Meter creates mtr flow id. */
4893 if (fm->def_policy) {
4894 mlx5_ipool_malloc(fm->flow_ipool, &tag_id);
4896 return rte_flow_error_set(error, ENOMEM,
4897 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4898 "Failed to allocate meter flow id.");
4899 flow_id = tag_id - 1;
4900 flow_id_bits = (!flow_id) ? 1 :
4901 (MLX5_REG_BITS - __builtin_clz(flow_id));
4902 if ((flow_id_bits + priv->sh->mtrmng->max_mtr_bits) >
4904 mlx5_ipool_free(fm->flow_ipool, tag_id);
4905 return rte_flow_error_set(error, EINVAL,
4906 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4907 "Meter flow id exceeds max limit.");
4909 if (flow_id_bits > priv->sh->mtrmng->max_mtr_flow_bits)
4910 priv->sh->mtrmng->max_mtr_flow_bits = flow_id_bits;
4912 /* Build tag actions and items for meter_id/meter flow_id. */
4913 set_tag = (struct mlx5_rte_flow_action_set_tag *)actions_pre;
4914 tag_item_spec = (struct mlx5_rte_flow_item_tag *)sfx_items;
4915 tag_item_mask = tag_item_spec + 1;
4916 /* Both flow_id and meter_id share the same register. */
4917 *set_tag = (struct mlx5_rte_flow_action_set_tag) {
4918 .id = (enum modify_reg)mlx5_flow_get_reg_id(dev, MLX5_MTR_ID,
4920 .offset = mtr_id_offset,
4921 .length = mtr_reg_bits,
4922 .data = flow->meter,
4925 * The color Reg bits used by flow_id are growing from
4926 * msb to lsb, so must do bit reverse for flow_id val in RegC.
4928 for (shift = 0; shift < flow_id_bits; shift++)
4929 flow_id_reversed = (flow_id_reversed << 1) |
4930 ((flow_id >> shift) & 0x1);
4932 flow_id_reversed << (mtr_reg_bits - flow_id_bits);
4933 tag_item_spec->id = set_tag->id;
4934 tag_item_spec->data = set_tag->data << mtr_id_offset;
4935 tag_item_mask->data = UINT32_MAX << mtr_id_offset;
4936 tag_action->type = (enum rte_flow_action_type)
4937 MLX5_RTE_FLOW_ACTION_TYPE_TAG;
4938 tag_action->conf = set_tag;
4939 tag_item->type = (enum rte_flow_item_type)
4940 MLX5_RTE_FLOW_ITEM_TYPE_TAG;
4941 tag_item->spec = tag_item_spec;
4942 tag_item->last = NULL;
4943 tag_item->mask = tag_item_mask;
4946 *mtr_flow_id = tag_id;
4951 * Split action list having QUEUE/RSS for metadata register copy.
4953 * Once Q/RSS action is detected in user's action list, the flow action
4954 * should be split in order to copy metadata registers, which will happen in
4956 * - CQE->flow_tag := reg_c[1] (MARK)
4957 * - CQE->flow_table_metadata (reg_b) := reg_c[0] (META)
4958 * The Q/RSS action will be performed on RX_ACT_TBL after passing by RX_CP_TBL.
4959 * This is because the last action of each flow must be a terminal action
4960 * (QUEUE, RSS or DROP).
4962 * Flow ID must be allocated to identify actions in the RX_ACT_TBL and it is
4963 * stored and kept in the mlx5_flow structure per each sub_flow.
4965 * The Q/RSS action is replaced with,
4966 * - SET_TAG, setting the allocated flow ID to reg_c[2].
4967 * And the following JUMP action is added at the end,
4968 * - JUMP, to RX_CP_TBL.
4970 * A flow to perform remained Q/RSS action will be created in RX_ACT_TBL by
4971 * flow_create_split_metadata() routine. The flow will look like,
4972 * - If flow ID matches (reg_c[2]), perform Q/RSS.
4975 * Pointer to Ethernet device.
4976 * @param[out] split_actions
4977 * Pointer to store split actions to jump to CP_TBL.
4978 * @param[in] actions
4979 * Pointer to the list of original flow actions.
4981 * Pointer to the Q/RSS action.
4982 * @param[in] actions_n
4983 * Number of original actions.
4985 * Perform verbose error reporting if not NULL.
4988 * non-zero unique flow_id on success, otherwise 0 and
4989 * error/rte_error are set.
4992 flow_mreg_split_qrss_prep(struct rte_eth_dev *dev,
4993 struct rte_flow_action *split_actions,
4994 const struct rte_flow_action *actions,
4995 const struct rte_flow_action *qrss,
4996 int actions_n, struct rte_flow_error *error)
4998 struct mlx5_priv *priv = dev->data->dev_private;
4999 struct mlx5_rte_flow_action_set_tag *set_tag;
5000 struct rte_flow_action_jump *jump;
5001 const int qrss_idx = qrss - actions;
5002 uint32_t flow_id = 0;
5006 * Given actions will be split
5007 * - Replace QUEUE/RSS action with SET_TAG to set flow ID.
5008 * - Add jump to mreg CP_TBL.
5009 * As a result, there will be one more action.
5012 memcpy(split_actions, actions, sizeof(*split_actions) * actions_n);
5013 set_tag = (void *)(split_actions + actions_n);
5015 * If tag action is not set to void(it means we are not the meter
5016 * suffix flow), add the tag action. Since meter suffix flow already
5017 * has the tag added.
5019 if (split_actions[qrss_idx].type != RTE_FLOW_ACTION_TYPE_VOID) {
5021 * Allocate the new subflow ID. This one is unique within
5022 * device and not shared with representors. Otherwise,
5023 * we would have to resolve multi-thread access synch
5024 * issue. Each flow on the shared device is appended
5025 * with source vport identifier, so the resulting
5026 * flows will be unique in the shared (by master and
5027 * representors) domain even if they have coinciding
5030 mlx5_ipool_malloc(priv->sh->ipool
5031 [MLX5_IPOOL_RSS_EXPANTION_FLOW_ID], &flow_id);
5033 return rte_flow_error_set(error, ENOMEM,
5034 RTE_FLOW_ERROR_TYPE_ACTION,
5035 NULL, "can't allocate id "
5036 "for split Q/RSS subflow");
5037 /* Internal SET_TAG action to set flow ID. */
5038 *set_tag = (struct mlx5_rte_flow_action_set_tag){
5041 ret = mlx5_flow_get_reg_id(dev, MLX5_COPY_MARK, 0, error);
5045 /* Construct new actions array. */
5046 /* Replace QUEUE/RSS action. */
5047 split_actions[qrss_idx] = (struct rte_flow_action){
5048 .type = (enum rte_flow_action_type)
5049 MLX5_RTE_FLOW_ACTION_TYPE_TAG,
5053 /* JUMP action to jump to mreg copy table (CP_TBL). */
5054 jump = (void *)(set_tag + 1);
5055 *jump = (struct rte_flow_action_jump){
5056 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
5058 split_actions[actions_n - 2] = (struct rte_flow_action){
5059 .type = RTE_FLOW_ACTION_TYPE_JUMP,
5062 split_actions[actions_n - 1] = (struct rte_flow_action){
5063 .type = RTE_FLOW_ACTION_TYPE_END,
5069 * Extend the given action list for Tx metadata copy.
5071 * Copy the given action list to the ext_actions and add flow metadata register
5072 * copy action in order to copy reg_a set by WQE to reg_c[0].
5074 * @param[out] ext_actions
5075 * Pointer to the extended action list.
5076 * @param[in] actions
5077 * Pointer to the list of actions.
5078 * @param[in] actions_n
5079 * Number of actions in the list.
5081 * Perform verbose error reporting if not NULL.
5082 * @param[in] encap_idx
5083 * The encap action inndex.
5086 * 0 on success, negative value otherwise
5089 flow_mreg_tx_copy_prep(struct rte_eth_dev *dev,
5090 struct rte_flow_action *ext_actions,
5091 const struct rte_flow_action *actions,
5092 int actions_n, struct rte_flow_error *error,
5095 struct mlx5_flow_action_copy_mreg *cp_mreg =
5096 (struct mlx5_flow_action_copy_mreg *)
5097 (ext_actions + actions_n + 1);
5100 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_RX, 0, error);
5104 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_TX, 0, error);
5109 memcpy(ext_actions, actions, sizeof(*ext_actions) * encap_idx);
5110 if (encap_idx == actions_n - 1) {
5111 ext_actions[actions_n - 1] = (struct rte_flow_action){
5112 .type = (enum rte_flow_action_type)
5113 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
5116 ext_actions[actions_n] = (struct rte_flow_action){
5117 .type = RTE_FLOW_ACTION_TYPE_END,
5120 ext_actions[encap_idx] = (struct rte_flow_action){
5121 .type = (enum rte_flow_action_type)
5122 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
5125 memcpy(ext_actions + encap_idx + 1, actions + encap_idx,
5126 sizeof(*ext_actions) * (actions_n - encap_idx));
5132 * Check the match action from the action list.
5134 * @param[in] actions
5135 * Pointer to the list of actions.
5137 * Flow rule attributes.
5139 * The action to be check if exist.
5140 * @param[out] match_action_pos
5141 * Pointer to the position of the matched action if exists, otherwise is -1.
5142 * @param[out] qrss_action_pos
5143 * Pointer to the position of the Queue/RSS action if exists, otherwise is -1.
5144 * @param[out] modify_after_mirror
5145 * Pointer to the flag of modify action after FDB mirroring.
5148 * > 0 the total number of actions.
5149 * 0 if not found match action in action list.
5152 flow_check_match_action(const struct rte_flow_action actions[],
5153 const struct rte_flow_attr *attr,
5154 enum rte_flow_action_type action,
5155 int *match_action_pos, int *qrss_action_pos,
5156 int *modify_after_mirror)
5158 const struct rte_flow_action_sample *sample;
5165 *match_action_pos = -1;
5166 *qrss_action_pos = -1;
5167 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
5168 if (actions->type == action) {
5170 *match_action_pos = actions_n;
5172 switch (actions->type) {
5173 case RTE_FLOW_ACTION_TYPE_QUEUE:
5174 case RTE_FLOW_ACTION_TYPE_RSS:
5175 *qrss_action_pos = actions_n;
5177 case RTE_FLOW_ACTION_TYPE_SAMPLE:
5178 sample = actions->conf;
5179 ratio = sample->ratio;
5180 sub_type = ((const struct rte_flow_action *)
5181 (sample->actions))->type;
5182 if (ratio == 1 && attr->transfer)
5185 case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
5186 case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
5187 case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
5188 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
5189 case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
5190 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
5191 case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
5192 case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
5193 case RTE_FLOW_ACTION_TYPE_DEC_TTL:
5194 case RTE_FLOW_ACTION_TYPE_SET_TTL:
5195 case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
5196 case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
5197 case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
5198 case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
5199 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
5200 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
5201 case RTE_FLOW_ACTION_TYPE_FLAG:
5202 case RTE_FLOW_ACTION_TYPE_MARK:
5203 case RTE_FLOW_ACTION_TYPE_SET_META:
5204 case RTE_FLOW_ACTION_TYPE_SET_TAG:
5205 case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
5206 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
5207 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
5208 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
5209 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
5210 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
5211 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
5212 case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
5213 case RTE_FLOW_ACTION_TYPE_METER:
5215 *modify_after_mirror = 1;
5222 if (flag && fdb_mirror && !*modify_after_mirror) {
5223 /* FDB mirroring uses the destination array to implement
5224 * instead of FLOW_SAMPLER object.
5226 if (sub_type != RTE_FLOW_ACTION_TYPE_END)
5229 /* Count RTE_FLOW_ACTION_TYPE_END. */
5230 return flag ? actions_n + 1 : 0;
5233 #define SAMPLE_SUFFIX_ITEM 2
5236 * Split the sample flow.
5238 * As sample flow will split to two sub flow, sample flow with
5239 * sample action, the other actions will move to new suffix flow.
5241 * Also add unique tag id with tag action in the sample flow,
5242 * the same tag id will be as match in the suffix flow.
5245 * Pointer to Ethernet device.
5246 * @param[in] add_tag
5247 * Add extra tag action flag.
5248 * @param[out] sfx_items
5249 * Suffix flow match items (list terminated by the END pattern item).
5250 * @param[in] actions
5251 * Associated actions (list terminated by the END action).
5252 * @param[out] actions_sfx
5253 * Suffix flow actions.
5254 * @param[out] actions_pre
5255 * Prefix flow actions.
5256 * @param[in] actions_n
5257 * The total number of actions.
5258 * @param[in] sample_action_pos
5259 * The sample action position.
5260 * @param[in] qrss_action_pos
5261 * The Queue/RSS action position.
5262 * @param[in] jump_table
5263 * Add extra jump action flag.
5265 * Perform verbose error reporting if not NULL.
5268 * 0 on success, or unique flow_id, a negative errno value
5269 * otherwise and rte_errno is set.
5272 flow_sample_split_prep(struct rte_eth_dev *dev,
5274 struct rte_flow_item sfx_items[],
5275 const struct rte_flow_action actions[],
5276 struct rte_flow_action actions_sfx[],
5277 struct rte_flow_action actions_pre[],
5279 int sample_action_pos,
5280 int qrss_action_pos,
5282 struct rte_flow_error *error)
5284 struct mlx5_priv *priv = dev->data->dev_private;
5285 struct mlx5_rte_flow_action_set_tag *set_tag;
5286 struct mlx5_rte_flow_item_tag *tag_spec;
5287 struct mlx5_rte_flow_item_tag *tag_mask;
5288 struct rte_flow_action_jump *jump_action;
5289 uint32_t tag_id = 0;
5291 int append_index = 0;
5294 if (sample_action_pos < 0)
5295 return rte_flow_error_set(error, EINVAL,
5296 RTE_FLOW_ERROR_TYPE_ACTION,
5297 NULL, "invalid position of sample "
5299 /* Prepare the actions for prefix and suffix flow. */
5300 if (qrss_action_pos >= 0 && qrss_action_pos < sample_action_pos) {
5301 index = qrss_action_pos;
5302 /* Put the preceding the Queue/RSS action into prefix flow. */
5304 memcpy(actions_pre, actions,
5305 sizeof(struct rte_flow_action) * index);
5306 /* Put others preceding the sample action into prefix flow. */
5307 if (sample_action_pos > index + 1)
5308 memcpy(actions_pre + index, actions + index + 1,
5309 sizeof(struct rte_flow_action) *
5310 (sample_action_pos - index - 1));
5311 index = sample_action_pos - 1;
5312 /* Put Queue/RSS action into Suffix flow. */
5313 memcpy(actions_sfx, actions + qrss_action_pos,
5314 sizeof(struct rte_flow_action));
5317 index = sample_action_pos;
5319 memcpy(actions_pre, actions,
5320 sizeof(struct rte_flow_action) * index);
5322 /* For CX5, add an extra tag action for NIC-RX and E-Switch ingress.
5323 * For CX6DX and above, metadata registers Cx preserve their value,
5324 * add an extra tag action for NIC-RX and E-Switch Domain.
5327 /* Prepare the prefix tag action. */
5329 set_tag = (void *)(actions_pre + actions_n + append_index);
5330 ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, 0, error);
5333 mlx5_ipool_malloc(priv->sh->ipool
5334 [MLX5_IPOOL_RSS_EXPANTION_FLOW_ID], &tag_id);
5335 *set_tag = (struct mlx5_rte_flow_action_set_tag) {
5339 /* Prepare the suffix subflow items. */
5340 tag_spec = (void *)(sfx_items + SAMPLE_SUFFIX_ITEM);
5341 tag_spec->data = tag_id;
5342 tag_spec->id = set_tag->id;
5343 tag_mask = tag_spec + 1;
5344 tag_mask->data = UINT32_MAX;
5345 sfx_items[0] = (struct rte_flow_item){
5346 .type = (enum rte_flow_item_type)
5347 MLX5_RTE_FLOW_ITEM_TYPE_TAG,
5352 sfx_items[1] = (struct rte_flow_item){
5353 .type = (enum rte_flow_item_type)
5354 RTE_FLOW_ITEM_TYPE_END,
5356 /* Prepare the tag action in prefix subflow. */
5357 actions_pre[index++] =
5358 (struct rte_flow_action){
5359 .type = (enum rte_flow_action_type)
5360 MLX5_RTE_FLOW_ACTION_TYPE_TAG,
5364 memcpy(actions_pre + index, actions + sample_action_pos,
5365 sizeof(struct rte_flow_action));
5367 /* For the modify action after the sample action in E-Switch mirroring,
5368 * Add the extra jump action in prefix subflow and jump into the next
5369 * table, then do the modify action in the new table.
5372 /* Prepare the prefix jump action. */
5374 jump_action = (void *)(actions_pre + actions_n + append_index);
5375 jump_action->group = jump_table;
5376 actions_pre[index++] =
5377 (struct rte_flow_action){
5378 .type = (enum rte_flow_action_type)
5379 RTE_FLOW_ACTION_TYPE_JUMP,
5380 .conf = jump_action,
5383 actions_pre[index] = (struct rte_flow_action){
5384 .type = (enum rte_flow_action_type)
5385 RTE_FLOW_ACTION_TYPE_END,
5387 /* Put the actions after sample into Suffix flow. */
5388 memcpy(actions_sfx, actions + sample_action_pos + 1,
5389 sizeof(struct rte_flow_action) *
5390 (actions_n - sample_action_pos - 1));
5395 * The splitting for metadata feature.
5397 * - Q/RSS action on NIC Rx should be split in order to pass by
5398 * the mreg copy table (RX_CP_TBL) and then it jumps to the
5399 * action table (RX_ACT_TBL) which has the split Q/RSS action.
5401 * - All the actions on NIC Tx should have a mreg copy action to
5402 * copy reg_a from WQE to reg_c[0].
5405 * Pointer to Ethernet device.
5407 * Parent flow structure pointer.
5409 * Flow rule attributes.
5411 * Pattern specification (list terminated by the END pattern item).
5412 * @param[in] actions
5413 * Associated actions (list terminated by the END action).
5414 * @param[in] flow_split_info
5415 * Pointer to flow split info structure.
5417 * Perform verbose error reporting if not NULL.
5419 * 0 on success, negative value otherwise
5422 flow_create_split_metadata(struct rte_eth_dev *dev,
5423 struct rte_flow *flow,
5424 const struct rte_flow_attr *attr,
5425 const struct rte_flow_item items[],
5426 const struct rte_flow_action actions[],
5427 struct mlx5_flow_split_info *flow_split_info,
5428 struct rte_flow_error *error)
5430 struct mlx5_priv *priv = dev->data->dev_private;
5431 struct mlx5_dev_config *config = &priv->config;
5432 const struct rte_flow_action *qrss = NULL;
5433 struct rte_flow_action *ext_actions = NULL;
5434 struct mlx5_flow *dev_flow = NULL;
5435 uint32_t qrss_id = 0;
5442 /* Check whether extensive metadata feature is engaged. */
5443 if (!config->dv_flow_en ||
5444 config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
5445 !mlx5_flow_ext_mreg_supported(dev))
5446 return flow_create_split_inner(dev, flow, NULL, attr, items,
5447 actions, flow_split_info, error);
5448 actions_n = flow_parse_metadata_split_actions_info(actions, &qrss,
5451 /* Exclude hairpin flows from splitting. */
5452 if (qrss->type == RTE_FLOW_ACTION_TYPE_QUEUE) {
5453 const struct rte_flow_action_queue *queue;
5456 if (mlx5_rxq_get_type(dev, queue->index) ==
5457 MLX5_RXQ_TYPE_HAIRPIN)
5459 } else if (qrss->type == RTE_FLOW_ACTION_TYPE_RSS) {
5460 const struct rte_flow_action_rss *rss;
5463 if (mlx5_rxq_get_type(dev, rss->queue[0]) ==
5464 MLX5_RXQ_TYPE_HAIRPIN)
5469 /* Check if it is in meter suffix table. */
5470 mtr_sfx = attr->group == (attr->transfer ?
5471 (MLX5_FLOW_TABLE_LEVEL_METER - 1) :
5472 MLX5_FLOW_TABLE_LEVEL_METER);
5474 * Q/RSS action on NIC Rx should be split in order to pass by
5475 * the mreg copy table (RX_CP_TBL) and then it jumps to the
5476 * action table (RX_ACT_TBL) which has the split Q/RSS action.
5478 act_size = sizeof(struct rte_flow_action) * (actions_n + 1) +
5479 sizeof(struct rte_flow_action_set_tag) +
5480 sizeof(struct rte_flow_action_jump);
5481 ext_actions = mlx5_malloc(MLX5_MEM_ZERO, act_size, 0,
5484 return rte_flow_error_set(error, ENOMEM,
5485 RTE_FLOW_ERROR_TYPE_ACTION,
5486 NULL, "no memory to split "
5489 * If we are the suffix flow of meter, tag already exist.
5490 * Set the tag action to void.
5493 ext_actions[qrss - actions].type =
5494 RTE_FLOW_ACTION_TYPE_VOID;
5496 ext_actions[qrss - actions].type =
5497 (enum rte_flow_action_type)
5498 MLX5_RTE_FLOW_ACTION_TYPE_TAG;
5500 * Create the new actions list with removed Q/RSS action
5501 * and appended set tag and jump to register copy table
5502 * (RX_CP_TBL). We should preallocate unique tag ID here
5503 * in advance, because it is needed for set tag action.
5505 qrss_id = flow_mreg_split_qrss_prep(dev, ext_actions, actions,
5506 qrss, actions_n, error);
5507 if (!mtr_sfx && !qrss_id) {
5511 } else if (attr->egress && !attr->transfer) {
5513 * All the actions on NIC Tx should have a metadata register
5514 * copy action to copy reg_a from WQE to reg_c[meta]
5516 act_size = sizeof(struct rte_flow_action) * (actions_n + 1) +
5517 sizeof(struct mlx5_flow_action_copy_mreg);
5518 ext_actions = mlx5_malloc(MLX5_MEM_ZERO, act_size, 0,
5521 return rte_flow_error_set(error, ENOMEM,
5522 RTE_FLOW_ERROR_TYPE_ACTION,
5523 NULL, "no memory to split "
5525 /* Create the action list appended with copy register. */
5526 ret = flow_mreg_tx_copy_prep(dev, ext_actions, actions,
5527 actions_n, error, encap_idx);
5531 /* Add the unmodified original or prefix subflow. */
5532 ret = flow_create_split_inner(dev, flow, &dev_flow, attr,
5533 items, ext_actions ? ext_actions :
5534 actions, flow_split_info, error);
5537 MLX5_ASSERT(dev_flow);
5539 const struct rte_flow_attr q_attr = {
5540 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
5543 /* Internal PMD action to set register. */
5544 struct mlx5_rte_flow_item_tag q_tag_spec = {
5548 struct rte_flow_item q_items[] = {
5550 .type = (enum rte_flow_item_type)
5551 MLX5_RTE_FLOW_ITEM_TYPE_TAG,
5552 .spec = &q_tag_spec,
5557 .type = RTE_FLOW_ITEM_TYPE_END,
5560 struct rte_flow_action q_actions[] = {
5566 .type = RTE_FLOW_ACTION_TYPE_END,
5569 uint64_t layers = flow_get_prefix_layer_flags(dev_flow);
5572 * Configure the tag item only if there is no meter subflow.
5573 * Since tag is already marked in the meter suffix subflow
5574 * we can just use the meter suffix items as is.
5577 /* Not meter subflow. */
5578 MLX5_ASSERT(!mtr_sfx);
5580 * Put unique id in prefix flow due to it is destroyed
5581 * after suffix flow and id will be freed after there
5582 * is no actual flows with this id and identifier
5583 * reallocation becomes possible (for example, for
5584 * other flows in other threads).
5586 dev_flow->handle->split_flow_id = qrss_id;
5587 ret = mlx5_flow_get_reg_id(dev, MLX5_COPY_MARK, 0,
5591 q_tag_spec.id = ret;
5594 /* Add suffix subflow to execute Q/RSS. */
5595 flow_split_info->prefix_layers = layers;
5596 flow_split_info->prefix_mark = 0;
5597 ret = flow_create_split_inner(dev, flow, &dev_flow,
5598 &q_attr, mtr_sfx ? items :
5600 flow_split_info, error);
5603 /* qrss ID should be freed if failed. */
5605 MLX5_ASSERT(dev_flow);
5610 * We do not destroy the partially created sub_flows in case of error.
5611 * These ones are included into parent flow list and will be destroyed
5612 * by flow_drv_destroy.
5614 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RSS_EXPANTION_FLOW_ID],
5616 mlx5_free(ext_actions);
5621 * Create meter internal drop flow with the original pattern.
5624 * Pointer to Ethernet device.
5626 * Parent flow structure pointer.
5628 * Flow rule attributes.
5630 * Pattern specification (list terminated by the END pattern item).
5631 * @param[in] flow_split_info
5632 * Pointer to flow split info structure.
5634 * Pointer to flow meter structure.
5636 * Perform verbose error reporting if not NULL.
5638 * 0 on success, negative value otherwise
5641 flow_meter_create_drop_flow_with_org_pattern(struct rte_eth_dev *dev,
5642 struct rte_flow *flow,
5643 const struct rte_flow_attr *attr,
5644 const struct rte_flow_item items[],
5645 struct mlx5_flow_split_info *flow_split_info,
5646 struct mlx5_flow_meter_info *fm,
5647 struct rte_flow_error *error)
5649 struct mlx5_flow *dev_flow = NULL;
5650 struct rte_flow_attr drop_attr = *attr;
5651 struct rte_flow_action drop_actions[3];
5652 struct mlx5_flow_split_info drop_split_info = *flow_split_info;
5654 MLX5_ASSERT(fm->drop_cnt);
5655 drop_actions[0].type =
5656 (enum rte_flow_action_type)MLX5_RTE_FLOW_ACTION_TYPE_COUNT;
5657 drop_actions[0].conf = (void *)(uintptr_t)fm->drop_cnt;
5658 drop_actions[1].type = RTE_FLOW_ACTION_TYPE_DROP;
5659 drop_actions[1].conf = NULL;
5660 drop_actions[2].type = RTE_FLOW_ACTION_TYPE_END;
5661 drop_actions[2].conf = NULL;
5662 drop_split_info.external = false;
5663 drop_split_info.skip_scale |= 1 << MLX5_SCALE_FLOW_GROUP_BIT;
5664 drop_split_info.table_id = MLX5_MTR_TABLE_ID_DROP;
5665 drop_attr.group = MLX5_FLOW_TABLE_LEVEL_METER;
5666 return flow_create_split_inner(dev, flow, &dev_flow,
5667 &drop_attr, items, drop_actions,
5668 &drop_split_info, error);
5672 * The splitting for meter feature.
5674 * - The meter flow will be split to two flows as prefix and
5675 * suffix flow. The packets make sense only it pass the prefix
5678 * - Reg_C_5 is used for the packet to match betweend prefix and
5682 * Pointer to Ethernet device.
5684 * Parent flow structure pointer.
5686 * Flow rule attributes.
5688 * Pattern specification (list terminated by the END pattern item).
5689 * @param[in] actions
5690 * Associated actions (list terminated by the END action).
5691 * @param[in] flow_split_info
5692 * Pointer to flow split info structure.
5694 * Perform verbose error reporting if not NULL.
5696 * 0 on success, negative value otherwise
5699 flow_create_split_meter(struct rte_eth_dev *dev,
5700 struct rte_flow *flow,
5701 const struct rte_flow_attr *attr,
5702 const struct rte_flow_item items[],
5703 const struct rte_flow_action actions[],
5704 struct mlx5_flow_split_info *flow_split_info,
5705 struct rte_flow_error *error)
5707 struct mlx5_priv *priv = dev->data->dev_private;
5708 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
5709 struct rte_flow_action *sfx_actions = NULL;
5710 struct rte_flow_action *pre_actions = NULL;
5711 struct rte_flow_item *sfx_items = NULL;
5712 struct mlx5_flow *dev_flow = NULL;
5713 struct rte_flow_attr sfx_attr = *attr;
5714 struct mlx5_flow_meter_info *fm = NULL;
5715 uint8_t skip_scale_restore;
5716 bool has_mtr = false;
5717 bool has_modify = false;
5718 bool set_mtr_reg = true;
5719 uint32_t meter_id = 0;
5720 uint32_t mtr_idx = 0;
5721 uint32_t mtr_flow_id = 0;
5728 actions_n = flow_check_meter_action(dev, actions, &has_mtr,
5729 &has_modify, &meter_id);
5732 fm = flow_dv_meter_find_by_idx(priv, flow->meter);
5734 return rte_flow_error_set(error, EINVAL,
5735 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5736 NULL, "Meter not found.");
5738 fm = mlx5_flow_meter_find(priv, meter_id, &mtr_idx);
5740 return rte_flow_error_set(error, EINVAL,
5741 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5742 NULL, "Meter not found.");
5743 ret = mlx5_flow_meter_attach(priv, fm,
5747 flow->meter = mtr_idx;
5752 * If it isn't default-policy Meter, and
5753 * 1. There's no action in flow to change
5754 * packet (modify/encap/decap etc.), OR
5755 * 2. No drop count needed for this meter.
5756 * no need to use regC to save meter id anymore.
5758 if (!fm->def_policy && (!has_modify || !fm->drop_cnt))
5759 set_mtr_reg = false;
5760 /* Prefix actions: meter, decap, encap, tag, jump, end. */
5761 act_size = sizeof(struct rte_flow_action) * (actions_n + 6) +
5762 sizeof(struct mlx5_rte_flow_action_set_tag);
5763 /* Suffix items: tag, vlan, port id, end. */
5764 #define METER_SUFFIX_ITEM 4
5765 item_size = sizeof(struct rte_flow_item) * METER_SUFFIX_ITEM +
5766 sizeof(struct mlx5_rte_flow_item_tag) * 2;
5767 sfx_actions = mlx5_malloc(MLX5_MEM_ZERO, (act_size + item_size),
5770 return rte_flow_error_set(error, ENOMEM,
5771 RTE_FLOW_ERROR_TYPE_ACTION,
5772 NULL, "no memory to split "
5774 sfx_items = (struct rte_flow_item *)((char *)sfx_actions +
5776 /* There's no suffix flow for meter of non-default policy. */
5777 if (!fm->def_policy)
5778 pre_actions = sfx_actions + 1;
5780 pre_actions = sfx_actions + actions_n;
5781 ret = flow_meter_split_prep(dev, flow, fm, &sfx_attr,
5782 items, sfx_items, actions,
5783 sfx_actions, pre_actions,
5784 (set_mtr_reg ? &mtr_flow_id : NULL),
5790 /* Add the prefix subflow. */
5791 flow_split_info->prefix_mark = 0;
5792 skip_scale_restore = flow_split_info->skip_scale;
5793 flow_split_info->skip_scale |=
5794 1 << MLX5_SCALE_JUMP_FLOW_GROUP_BIT;
5795 ret = flow_create_split_inner(dev, flow, &dev_flow,
5796 attr, items, pre_actions,
5797 flow_split_info, error);
5798 flow_split_info->skip_scale = skip_scale_restore;
5801 mlx5_ipool_free(fm->flow_ipool, mtr_flow_id);
5806 dev_flow->handle->split_flow_id = mtr_flow_id;
5807 dev_flow->handle->is_meter_flow_id = 1;
5809 if (!fm->def_policy) {
5810 if (!set_mtr_reg && fm->drop_cnt)
5812 flow_meter_create_drop_flow_with_org_pattern(dev, flow,
5818 /* Setting the sfx group atrr. */
5819 sfx_attr.group = sfx_attr.transfer ?
5820 (MLX5_FLOW_TABLE_LEVEL_METER - 1) :
5821 MLX5_FLOW_TABLE_LEVEL_METER;
5822 flow_split_info->prefix_layers =
5823 flow_get_prefix_layer_flags(dev_flow);
5824 flow_split_info->prefix_mark = dev_flow->handle->mark;
5825 flow_split_info->table_id = MLX5_MTR_TABLE_ID_SUFFIX;
5827 /* Add the prefix subflow. */
5828 ret = flow_create_split_metadata(dev, flow,
5829 &sfx_attr, sfx_items ?
5831 sfx_actions ? sfx_actions : actions,
5832 flow_split_info, error);
5835 mlx5_free(sfx_actions);
5840 * The splitting for sample feature.
5842 * Once Sample action is detected in the action list, the flow actions should
5843 * be split into prefix sub flow and suffix sub flow.
5845 * The original items remain in the prefix sub flow, all actions preceding the
5846 * sample action and the sample action itself will be copied to the prefix
5847 * sub flow, the actions following the sample action will be copied to the
5848 * suffix sub flow, Queue action always be located in the suffix sub flow.
5850 * In order to make the packet from prefix sub flow matches with suffix sub
5851 * flow, an extra tag action be added into prefix sub flow, and the suffix sub
5852 * flow uses tag item with the unique flow id.
5855 * Pointer to Ethernet device.
5857 * Parent flow structure pointer.
5859 * Flow rule attributes.
5861 * Pattern specification (list terminated by the END pattern item).
5862 * @param[in] actions
5863 * Associated actions (list terminated by the END action).
5864 * @param[in] flow_split_info
5865 * Pointer to flow split info structure.
5867 * Perform verbose error reporting if not NULL.
5869 * 0 on success, negative value otherwise
5872 flow_create_split_sample(struct rte_eth_dev *dev,
5873 struct rte_flow *flow,
5874 const struct rte_flow_attr *attr,
5875 const struct rte_flow_item items[],
5876 const struct rte_flow_action actions[],
5877 struct mlx5_flow_split_info *flow_split_info,
5878 struct rte_flow_error *error)
5880 struct mlx5_priv *priv = dev->data->dev_private;
5881 struct rte_flow_action *sfx_actions = NULL;
5882 struct rte_flow_action *pre_actions = NULL;
5883 struct rte_flow_item *sfx_items = NULL;
5884 struct mlx5_flow *dev_flow = NULL;
5885 struct rte_flow_attr sfx_attr = *attr;
5886 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
5887 struct mlx5_flow_dv_sample_resource *sample_res;
5888 struct mlx5_flow_tbl_data_entry *sfx_tbl_data;
5889 struct mlx5_flow_tbl_resource *sfx_tbl;
5893 uint32_t fdb_tx = 0;
5896 int sample_action_pos;
5897 int qrss_action_pos;
5899 int modify_after_mirror = 0;
5900 uint16_t jump_table = 0;
5901 const uint32_t next_ft_step = 1;
5904 if (priv->sampler_en)
5905 actions_n = flow_check_match_action(actions, attr,
5906 RTE_FLOW_ACTION_TYPE_SAMPLE,
5907 &sample_action_pos, &qrss_action_pos,
5908 &modify_after_mirror);
5910 /* The prefix actions must includes sample, tag, end. */
5911 act_size = sizeof(struct rte_flow_action) * (actions_n * 2 + 1)
5912 + sizeof(struct mlx5_rte_flow_action_set_tag);
5913 item_size = sizeof(struct rte_flow_item) * SAMPLE_SUFFIX_ITEM +
5914 sizeof(struct mlx5_rte_flow_item_tag) * 2;
5915 sfx_actions = mlx5_malloc(MLX5_MEM_ZERO, (act_size +
5916 item_size), 0, SOCKET_ID_ANY);
5918 return rte_flow_error_set(error, ENOMEM,
5919 RTE_FLOW_ERROR_TYPE_ACTION,
5920 NULL, "no memory to split "
5922 /* The representor_id is UINT16_MAX for uplink. */
5923 fdb_tx = (attr->transfer && priv->representor_id != UINT16_MAX);
5925 * When reg_c_preserve is set, metadata registers Cx preserve
5926 * their value even through packet duplication.
5928 add_tag = (!fdb_tx || priv->config.hca_attr.reg_c_preserve);
5930 sfx_items = (struct rte_flow_item *)((char *)sfx_actions
5932 if (modify_after_mirror)
5933 jump_table = attr->group * MLX5_FLOW_TABLE_FACTOR +
5935 pre_actions = sfx_actions + actions_n;
5936 tag_id = flow_sample_split_prep(dev, add_tag, sfx_items,
5937 actions, sfx_actions,
5938 pre_actions, actions_n,
5940 qrss_action_pos, jump_table,
5942 if (tag_id < 0 || (add_tag && !tag_id)) {
5946 if (modify_after_mirror)
5947 flow_split_info->skip_scale =
5948 1 << MLX5_SCALE_JUMP_FLOW_GROUP_BIT;
5949 /* Add the prefix subflow. */
5950 ret = flow_create_split_inner(dev, flow, &dev_flow, attr,
5952 flow_split_info, error);
5957 dev_flow->handle->split_flow_id = tag_id;
5958 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
5959 if (!modify_after_mirror) {
5960 /* Set the sfx group attr. */
5961 sample_res = (struct mlx5_flow_dv_sample_resource *)
5962 dev_flow->dv.sample_res;
5963 sfx_tbl = (struct mlx5_flow_tbl_resource *)
5964 sample_res->normal_path_tbl;
5965 sfx_tbl_data = container_of(sfx_tbl,
5966 struct mlx5_flow_tbl_data_entry,
5968 sfx_attr.group = sfx_attr.transfer ?
5969 (sfx_tbl_data->level - 1) : sfx_tbl_data->level;
5971 MLX5_ASSERT(attr->transfer);
5972 sfx_attr.group = jump_table;
5974 flow_split_info->prefix_layers =
5975 flow_get_prefix_layer_flags(dev_flow);
5976 flow_split_info->prefix_mark = dev_flow->handle->mark;
5977 /* Suffix group level already be scaled with factor, set
5978 * MLX5_SCALE_FLOW_GROUP_BIT of skip_scale to 1 to avoid scale
5979 * again in translation.
5981 flow_split_info->skip_scale = 1 << MLX5_SCALE_FLOW_GROUP_BIT;
5984 /* Add the suffix subflow. */
5985 ret = flow_create_split_meter(dev, flow, &sfx_attr,
5986 sfx_items ? sfx_items : items,
5987 sfx_actions ? sfx_actions : actions,
5988 flow_split_info, error);
5991 mlx5_free(sfx_actions);
5996 * Split the flow to subflow set. The splitters might be linked
5997 * in the chain, like this:
5998 * flow_create_split_outer() calls:
5999 * flow_create_split_meter() calls:
6000 * flow_create_split_metadata(meter_subflow_0) calls:
6001 * flow_create_split_inner(metadata_subflow_0)
6002 * flow_create_split_inner(metadata_subflow_1)
6003 * flow_create_split_inner(metadata_subflow_2)
6004 * flow_create_split_metadata(meter_subflow_1) calls:
6005 * flow_create_split_inner(metadata_subflow_0)
6006 * flow_create_split_inner(metadata_subflow_1)
6007 * flow_create_split_inner(metadata_subflow_2)
6009 * This provide flexible way to add new levels of flow splitting.
6010 * The all of successfully created subflows are included to the
6011 * parent flow dev_flow list.
6014 * Pointer to Ethernet device.
6016 * Parent flow structure pointer.
6018 * Flow rule attributes.
6020 * Pattern specification (list terminated by the END pattern item).
6021 * @param[in] actions
6022 * Associated actions (list terminated by the END action).
6023 * @param[in] flow_split_info
6024 * Pointer to flow split info structure.
6026 * Perform verbose error reporting if not NULL.
6028 * 0 on success, negative value otherwise
6031 flow_create_split_outer(struct rte_eth_dev *dev,
6032 struct rte_flow *flow,
6033 const struct rte_flow_attr *attr,
6034 const struct rte_flow_item items[],
6035 const struct rte_flow_action actions[],
6036 struct mlx5_flow_split_info *flow_split_info,
6037 struct rte_flow_error *error)
6041 ret = flow_create_split_sample(dev, flow, attr, items,
6042 actions, flow_split_info, error);
6043 MLX5_ASSERT(ret <= 0);
6047 static inline struct mlx5_flow_tunnel *
6048 flow_tunnel_from_rule(const struct mlx5_flow *flow)
6050 struct mlx5_flow_tunnel *tunnel;
6052 #pragma GCC diagnostic push
6053 #pragma GCC diagnostic ignored "-Wcast-qual"
6054 tunnel = (typeof(tunnel))flow->tunnel;
6055 #pragma GCC diagnostic pop
6061 * Adjust flow RSS workspace if needed.
6064 * Pointer to thread flow work space.
6066 * Pointer to RSS descriptor.
6067 * @param[in] nrssq_num
6068 * New RSS queue number.
6071 * 0 on success, -1 otherwise and rte_errno is set.
6074 flow_rss_workspace_adjust(struct mlx5_flow_workspace *wks,
6075 struct mlx5_flow_rss_desc *rss_desc,
6078 if (likely(nrssq_num <= wks->rssq_num))
6080 rss_desc->queue = realloc(rss_desc->queue,
6081 sizeof(*rss_desc->queue) * RTE_ALIGN(nrssq_num, 2));
6082 if (!rss_desc->queue) {
6086 wks->rssq_num = RTE_ALIGN(nrssq_num, 2);
6091 * Create a flow and add it to @p list.
6094 * Pointer to Ethernet device.
6096 * Pointer to a TAILQ flow list. If this parameter NULL,
6097 * no list insertion occurred, flow is just created,
6098 * this is caller's responsibility to track the
6101 * Flow rule attributes.
6103 * Pattern specification (list terminated by the END pattern item).
6104 * @param[in] actions
6105 * Associated actions (list terminated by the END action).
6106 * @param[in] external
6107 * This flow rule is created by request external to PMD.
6109 * Perform verbose error reporting if not NULL.
6112 * A flow index on success, 0 otherwise and rte_errno is set.
6115 flow_list_create(struct rte_eth_dev *dev, uint32_t *list,
6116 const struct rte_flow_attr *attr,
6117 const struct rte_flow_item items[],
6118 const struct rte_flow_action original_actions[],
6119 bool external, struct rte_flow_error *error)
6121 struct mlx5_priv *priv = dev->data->dev_private;
6122 struct rte_flow *flow = NULL;
6123 struct mlx5_flow *dev_flow;
6124 const struct rte_flow_action_rss *rss = NULL;
6125 struct mlx5_translated_action_handle
6126 indir_actions[MLX5_MAX_INDIRECT_ACTIONS];
6127 int indir_actions_n = MLX5_MAX_INDIRECT_ACTIONS;
6129 struct mlx5_flow_expand_rss buf;
6130 uint8_t buffer[2048];
6133 struct rte_flow_action actions[MLX5_MAX_SPLIT_ACTIONS];
6134 uint8_t buffer[2048];
6137 struct rte_flow_action actions[MLX5_MAX_SPLIT_ACTIONS];
6138 uint8_t buffer[2048];
6139 } actions_hairpin_tx;
6141 struct rte_flow_item items[MLX5_MAX_SPLIT_ITEMS];
6142 uint8_t buffer[2048];
6144 struct mlx5_flow_expand_rss *buf = &expand_buffer.buf;
6145 struct mlx5_flow_rss_desc *rss_desc;
6146 const struct rte_flow_action *p_actions_rx;
6150 struct rte_flow_attr attr_tx = { .priority = 0 };
6151 const struct rte_flow_action *actions;
6152 struct rte_flow_action *translated_actions = NULL;
6153 struct mlx5_flow_tunnel *tunnel;
6154 struct tunnel_default_miss_ctx default_miss_ctx = { 0, };
6155 struct mlx5_flow_workspace *wks = mlx5_flow_push_thread_workspace();
6156 struct mlx5_flow_split_info flow_split_info = {
6157 .external = !!external,
6167 rss_desc = &wks->rss_desc;
6168 ret = flow_action_handles_translate(dev, original_actions,
6171 &translated_actions, error);
6173 MLX5_ASSERT(translated_actions == NULL);
6176 actions = translated_actions ? translated_actions : original_actions;
6177 p_actions_rx = actions;
6178 hairpin_flow = flow_check_hairpin_split(dev, attr, actions);
6179 ret = flow_drv_validate(dev, attr, items, p_actions_rx,
6180 external, hairpin_flow, error);
6182 goto error_before_hairpin_split;
6183 flow = mlx5_ipool_zmalloc(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], &idx);
6186 goto error_before_hairpin_split;
6188 if (hairpin_flow > 0) {
6189 if (hairpin_flow > MLX5_MAX_SPLIT_ACTIONS) {
6191 goto error_before_hairpin_split;
6193 flow_hairpin_split(dev, actions, actions_rx.actions,
6194 actions_hairpin_tx.actions, items_tx.items,
6196 p_actions_rx = actions_rx.actions;
6198 flow_split_info.flow_idx = idx;
6199 flow->drv_type = flow_get_drv_type(dev, attr);
6200 MLX5_ASSERT(flow->drv_type > MLX5_FLOW_TYPE_MIN &&
6201 flow->drv_type < MLX5_FLOW_TYPE_MAX);
6202 memset(rss_desc, 0, offsetof(struct mlx5_flow_rss_desc, queue));
6203 /* RSS Action only works on NIC RX domain */
6204 if (attr->ingress && !attr->transfer)
6205 rss = flow_get_rss_action(dev, p_actions_rx);
6207 if (flow_rss_workspace_adjust(wks, rss_desc, rss->queue_num))
6210 * The following information is required by
6211 * mlx5_flow_hashfields_adjust() in advance.
6213 rss_desc->level = rss->level;
6214 /* RSS type 0 indicates default RSS type (ETH_RSS_IP). */
6215 rss_desc->types = !rss->types ? ETH_RSS_IP : rss->types;
6217 flow->dev_handles = 0;
6218 if (rss && rss->types) {
6219 unsigned int graph_root;
6221 graph_root = find_graph_root(items, rss->level);
6222 ret = mlx5_flow_expand_rss(buf, sizeof(expand_buffer.buffer),
6224 mlx5_support_expansion, graph_root);
6225 MLX5_ASSERT(ret > 0 &&
6226 (unsigned int)ret < sizeof(expand_buffer.buffer));
6227 if (rte_log_can_log(mlx5_logtype, RTE_LOG_DEBUG)) {
6228 for (i = 0; i < buf->entries; ++i)
6229 mlx5_dbg__print_pattern(buf->entry[i].pattern);
6233 buf->entry[0].pattern = (void *)(uintptr_t)items;
6235 rss_desc->shared_rss = flow_get_shared_rss_action(dev, indir_actions,
6237 for (i = 0; i < buf->entries; ++i) {
6238 /* Initialize flow split data. */
6239 flow_split_info.prefix_layers = 0;
6240 flow_split_info.prefix_mark = 0;
6241 flow_split_info.skip_scale = 0;
6243 * The splitter may create multiple dev_flows,
6244 * depending on configuration. In the simplest
6245 * case it just creates unmodified original flow.
6247 ret = flow_create_split_outer(dev, flow, attr,
6248 buf->entry[i].pattern,
6249 p_actions_rx, &flow_split_info,
6253 if (is_flow_tunnel_steer_rule(wks->flows[0].tof_type)) {
6254 ret = flow_tunnel_add_default_miss(dev, flow, attr,
6257 wks->flows[0].tunnel,
6261 mlx5_free(default_miss_ctx.queue);
6266 /* Create the tx flow. */
6268 attr_tx.group = MLX5_HAIRPIN_TX_TABLE;
6269 attr_tx.ingress = 0;
6271 dev_flow = flow_drv_prepare(dev, flow, &attr_tx, items_tx.items,
6272 actions_hairpin_tx.actions,
6276 dev_flow->flow = flow;
6277 dev_flow->external = 0;
6278 SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
6279 dev_flow->handle, next);
6280 ret = flow_drv_translate(dev, dev_flow, &attr_tx,
6282 actions_hairpin_tx.actions, error);
6287 * Update the metadata register copy table. If extensive
6288 * metadata feature is enabled and registers are supported
6289 * we might create the extra rte_flow for each unique
6290 * MARK/FLAG action ID.
6292 * The table is updated for ingress Flows only, because
6293 * the egress Flows belong to the different device and
6294 * copy table should be updated in peer NIC Rx domain.
6296 if (attr->ingress &&
6297 (external || attr->group != MLX5_FLOW_MREG_CP_TABLE_GROUP)) {
6298 ret = flow_mreg_update_copy_table(dev, flow, actions, error);
6303 * If the flow is external (from application) OR device is started,
6304 * OR mreg discover, then apply immediately.
6306 if (external || dev->data->dev_started ||
6307 (attr->group == MLX5_FLOW_MREG_CP_TABLE_GROUP &&
6308 attr->priority == MLX5_FLOW_LOWEST_PRIO_INDICATOR)) {
6309 ret = flow_drv_apply(dev, flow, error);
6314 rte_spinlock_lock(&priv->flow_list_lock);
6315 ILIST_INSERT(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], list, idx,
6317 rte_spinlock_unlock(&priv->flow_list_lock);
6319 flow_rxq_flags_set(dev, flow);
6320 rte_free(translated_actions);
6321 tunnel = flow_tunnel_from_rule(wks->flows);
6324 flow->tunnel_id = tunnel->tunnel_id;
6325 __atomic_add_fetch(&tunnel->refctn, 1, __ATOMIC_RELAXED);
6326 mlx5_free(default_miss_ctx.queue);
6328 mlx5_flow_pop_thread_workspace();
6332 ret = rte_errno; /* Save rte_errno before cleanup. */
6333 flow_mreg_del_copy_action(dev, flow);
6334 flow_drv_destroy(dev, flow);
6335 if (rss_desc->shared_rss)
6336 __atomic_sub_fetch(&((struct mlx5_shared_action_rss *)
6338 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
6339 rss_desc->shared_rss))->refcnt, 1, __ATOMIC_RELAXED);
6340 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], idx);
6341 rte_errno = ret; /* Restore rte_errno. */
6344 mlx5_flow_pop_thread_workspace();
6345 error_before_hairpin_split:
6346 rte_free(translated_actions);
6351 * Create a dedicated flow rule on e-switch table 0 (root table), to direct all
6352 * incoming packets to table 1.
6354 * Other flow rules, requested for group n, will be created in
6355 * e-switch table n+1.
6356 * Jump action to e-switch group n will be created to group n+1.
6358 * Used when working in switchdev mode, to utilise advantages of table 1
6362 * Pointer to Ethernet device.
6365 * Pointer to flow on success, NULL otherwise and rte_errno is set.
6368 mlx5_flow_create_esw_table_zero_flow(struct rte_eth_dev *dev)
6370 const struct rte_flow_attr attr = {
6377 const struct rte_flow_item pattern = {
6378 .type = RTE_FLOW_ITEM_TYPE_END,
6380 struct rte_flow_action_jump jump = {
6383 const struct rte_flow_action actions[] = {
6385 .type = RTE_FLOW_ACTION_TYPE_JUMP,
6389 .type = RTE_FLOW_ACTION_TYPE_END,
6392 struct mlx5_priv *priv = dev->data->dev_private;
6393 struct rte_flow_error error;
6395 return (void *)(uintptr_t)flow_list_create(dev, &priv->ctrl_flows,
6397 actions, false, &error);
6401 * Validate a flow supported by the NIC.
6403 * @see rte_flow_validate()
6407 mlx5_flow_validate(struct rte_eth_dev *dev,
6408 const struct rte_flow_attr *attr,
6409 const struct rte_flow_item items[],
6410 const struct rte_flow_action original_actions[],
6411 struct rte_flow_error *error)
6414 struct mlx5_translated_action_handle
6415 indir_actions[MLX5_MAX_INDIRECT_ACTIONS];
6416 int indir_actions_n = MLX5_MAX_INDIRECT_ACTIONS;
6417 const struct rte_flow_action *actions;
6418 struct rte_flow_action *translated_actions = NULL;
6419 int ret = flow_action_handles_translate(dev, original_actions,
6422 &translated_actions, error);
6426 actions = translated_actions ? translated_actions : original_actions;
6427 hairpin_flow = flow_check_hairpin_split(dev, attr, actions);
6428 ret = flow_drv_validate(dev, attr, items, actions,
6429 true, hairpin_flow, error);
6430 rte_free(translated_actions);
6437 * @see rte_flow_create()
6441 mlx5_flow_create(struct rte_eth_dev *dev,
6442 const struct rte_flow_attr *attr,
6443 const struct rte_flow_item items[],
6444 const struct rte_flow_action actions[],
6445 struct rte_flow_error *error)
6447 struct mlx5_priv *priv = dev->data->dev_private;
6450 * If the device is not started yet, it is not allowed to created a
6451 * flow from application. PMD default flows and traffic control flows
6454 if (unlikely(!dev->data->dev_started)) {
6455 DRV_LOG(DEBUG, "port %u is not started when "
6456 "inserting a flow", dev->data->port_id);
6457 rte_flow_error_set(error, ENODEV,
6458 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6460 "port not started");
6464 return (void *)(uintptr_t)flow_list_create(dev, &priv->flows,
6465 attr, items, actions, true, error);
6469 * Destroy a flow in a list.
6472 * Pointer to Ethernet device.
6474 * Pointer to the Indexed flow list. If this parameter NULL,
6475 * there is no flow removal from the list. Be noted that as
6476 * flow is add to the indexed list, memory of the indexed
6477 * list points to maybe changed as flow destroyed.
6478 * @param[in] flow_idx
6479 * Index of flow to destroy.
6482 flow_list_destroy(struct rte_eth_dev *dev, uint32_t *list,
6485 struct mlx5_priv *priv = dev->data->dev_private;
6486 struct rte_flow *flow = mlx5_ipool_get(priv->sh->ipool
6487 [MLX5_IPOOL_RTE_FLOW], flow_idx);
6492 * Update RX queue flags only if port is started, otherwise it is
6495 if (dev->data->dev_started)
6496 flow_rxq_flags_trim(dev, flow);
6497 flow_drv_destroy(dev, flow);
6499 rte_spinlock_lock(&priv->flow_list_lock);
6500 ILIST_REMOVE(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], list,
6501 flow_idx, flow, next);
6502 rte_spinlock_unlock(&priv->flow_list_lock);
6505 struct mlx5_flow_tunnel *tunnel;
6507 tunnel = mlx5_find_tunnel_id(dev, flow->tunnel_id);
6509 if (!__atomic_sub_fetch(&tunnel->refctn, 1, __ATOMIC_RELAXED))
6510 mlx5_flow_tunnel_free(dev, tunnel);
6512 flow_mreg_del_copy_action(dev, flow);
6513 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], flow_idx);
6517 * Destroy all flows.
6520 * Pointer to Ethernet device.
6522 * Pointer to the Indexed flow list.
6524 * If flushing is called avtively.
6527 mlx5_flow_list_flush(struct rte_eth_dev *dev, uint32_t *list, bool active)
6529 uint32_t num_flushed = 0;
6532 flow_list_destroy(dev, list, *list);
6536 DRV_LOG(INFO, "port %u: %u flows flushed before stopping",
6537 dev->data->port_id, num_flushed);
6542 * Stop all default actions for flows.
6545 * Pointer to Ethernet device.
6548 mlx5_flow_stop_default(struct rte_eth_dev *dev)
6550 flow_mreg_del_default_copy_action(dev);
6551 flow_rxq_flags_clear(dev);
6555 * Start all default actions for flows.
6558 * Pointer to Ethernet device.
6560 * 0 on success, a negative errno value otherwise and rte_errno is set.
6563 mlx5_flow_start_default(struct rte_eth_dev *dev)
6565 struct rte_flow_error error;
6567 /* Make sure default copy action (reg_c[0] -> reg_b) is created. */
6568 return flow_mreg_add_default_copy_action(dev, &error);
6572 * Release key of thread specific flow workspace data.
6575 flow_release_workspace(void *data)
6577 struct mlx5_flow_workspace *wks = data;
6578 struct mlx5_flow_workspace *next;
6582 free(wks->rss_desc.queue);
6589 * Get thread specific current flow workspace.
6591 * @return pointer to thread specific flow workspace data, NULL on error.
6593 struct mlx5_flow_workspace*
6594 mlx5_flow_get_thread_workspace(void)
6596 struct mlx5_flow_workspace *data;
6598 data = mlx5_flow_os_get_specific_workspace();
6599 MLX5_ASSERT(data && data->inuse);
6600 if (!data || !data->inuse)
6601 DRV_LOG(ERR, "flow workspace not initialized.");
6606 * Allocate and init new flow workspace.
6608 * @return pointer to flow workspace data, NULL on error.
6610 static struct mlx5_flow_workspace*
6611 flow_alloc_thread_workspace(void)
6613 struct mlx5_flow_workspace *data = calloc(1, sizeof(*data));
6616 DRV_LOG(ERR, "Failed to allocate flow workspace "
6620 data->rss_desc.queue = calloc(1,
6621 sizeof(uint16_t) * MLX5_RSSQ_DEFAULT_NUM);
6622 if (!data->rss_desc.queue)
6624 data->rssq_num = MLX5_RSSQ_DEFAULT_NUM;
6627 if (data->rss_desc.queue)
6628 free(data->rss_desc.queue);
6634 * Get new thread specific flow workspace.
6636 * If current workspace inuse, create new one and set as current.
6638 * @return pointer to thread specific flow workspace data, NULL on error.
6640 static struct mlx5_flow_workspace*
6641 mlx5_flow_push_thread_workspace(void)
6643 struct mlx5_flow_workspace *curr;
6644 struct mlx5_flow_workspace *data;
6646 curr = mlx5_flow_os_get_specific_workspace();
6648 data = flow_alloc_thread_workspace();
6651 } else if (!curr->inuse) {
6653 } else if (curr->next) {
6656 data = flow_alloc_thread_workspace();
6664 /* Set as current workspace */
6665 if (mlx5_flow_os_set_specific_workspace(data))
6666 DRV_LOG(ERR, "Failed to set flow workspace to thread.");
6671 * Close current thread specific flow workspace.
6673 * If previous workspace available, set it as current.
6675 * @return pointer to thread specific flow workspace data, NULL on error.
6678 mlx5_flow_pop_thread_workspace(void)
6680 struct mlx5_flow_workspace *data = mlx5_flow_get_thread_workspace();
6685 DRV_LOG(ERR, "Failed to close unused flow workspace.");
6691 if (mlx5_flow_os_set_specific_workspace(data->prev))
6692 DRV_LOG(ERR, "Failed to set flow workspace to thread.");
6696 * Verify the flow list is empty
6699 * Pointer to Ethernet device.
6701 * @return the number of flows not released.
6704 mlx5_flow_verify(struct rte_eth_dev *dev)
6706 struct mlx5_priv *priv = dev->data->dev_private;
6707 struct rte_flow *flow;
6711 ILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], priv->flows, idx,
6713 DRV_LOG(DEBUG, "port %u flow %p still referenced",
6714 dev->data->port_id, (void *)flow);
6721 * Enable default hairpin egress flow.
6724 * Pointer to Ethernet device.
6729 * 0 on success, a negative errno value otherwise and rte_errno is set.
6732 mlx5_ctrl_flow_source_queue(struct rte_eth_dev *dev,
6735 struct mlx5_priv *priv = dev->data->dev_private;
6736 const struct rte_flow_attr attr = {
6740 struct mlx5_rte_flow_item_tx_queue queue_spec = {
6743 struct mlx5_rte_flow_item_tx_queue queue_mask = {
6744 .queue = UINT32_MAX,
6746 struct rte_flow_item items[] = {
6748 .type = (enum rte_flow_item_type)
6749 MLX5_RTE_FLOW_ITEM_TYPE_TX_QUEUE,
6750 .spec = &queue_spec,
6752 .mask = &queue_mask,
6755 .type = RTE_FLOW_ITEM_TYPE_END,
6758 struct rte_flow_action_jump jump = {
6759 .group = MLX5_HAIRPIN_TX_TABLE,
6761 struct rte_flow_action actions[2];
6763 struct rte_flow_error error;
6765 actions[0].type = RTE_FLOW_ACTION_TYPE_JUMP;
6766 actions[0].conf = &jump;
6767 actions[1].type = RTE_FLOW_ACTION_TYPE_END;
6768 flow_idx = flow_list_create(dev, &priv->ctrl_flows,
6769 &attr, items, actions, false, &error);
6772 "Failed to create ctrl flow: rte_errno(%d),"
6773 " type(%d), message(%s)",
6774 rte_errno, error.type,
6775 error.message ? error.message : " (no stated reason)");
6782 * Enable a control flow configured from the control plane.
6785 * Pointer to Ethernet device.
6787 * An Ethernet flow spec to apply.
6789 * An Ethernet flow mask to apply.
6791 * A VLAN flow spec to apply.
6793 * A VLAN flow mask to apply.
6796 * 0 on success, a negative errno value otherwise and rte_errno is set.
6799 mlx5_ctrl_flow_vlan(struct rte_eth_dev *dev,
6800 struct rte_flow_item_eth *eth_spec,
6801 struct rte_flow_item_eth *eth_mask,
6802 struct rte_flow_item_vlan *vlan_spec,
6803 struct rte_flow_item_vlan *vlan_mask)
6805 struct mlx5_priv *priv = dev->data->dev_private;
6806 const struct rte_flow_attr attr = {
6808 .priority = MLX5_FLOW_LOWEST_PRIO_INDICATOR,
6810 struct rte_flow_item items[] = {
6812 .type = RTE_FLOW_ITEM_TYPE_ETH,
6818 .type = (vlan_spec) ? RTE_FLOW_ITEM_TYPE_VLAN :
6819 RTE_FLOW_ITEM_TYPE_END,
6825 .type = RTE_FLOW_ITEM_TYPE_END,
6828 uint16_t queue[priv->reta_idx_n];
6829 struct rte_flow_action_rss action_rss = {
6830 .func = RTE_ETH_HASH_FUNCTION_DEFAULT,
6832 .types = priv->rss_conf.rss_hf,
6833 .key_len = priv->rss_conf.rss_key_len,
6834 .queue_num = priv->reta_idx_n,
6835 .key = priv->rss_conf.rss_key,
6838 struct rte_flow_action actions[] = {
6840 .type = RTE_FLOW_ACTION_TYPE_RSS,
6841 .conf = &action_rss,
6844 .type = RTE_FLOW_ACTION_TYPE_END,
6848 struct rte_flow_error error;
6851 if (!priv->reta_idx_n || !priv->rxqs_n) {
6854 if (!(dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG))
6855 action_rss.types = 0;
6856 for (i = 0; i != priv->reta_idx_n; ++i)
6857 queue[i] = (*priv->reta_idx)[i];
6858 flow_idx = flow_list_create(dev, &priv->ctrl_flows,
6859 &attr, items, actions, false, &error);
6866 * Enable a flow control configured from the control plane.
6869 * Pointer to Ethernet device.
6871 * An Ethernet flow spec to apply.
6873 * An Ethernet flow mask to apply.
6876 * 0 on success, a negative errno value otherwise and rte_errno is set.
6879 mlx5_ctrl_flow(struct rte_eth_dev *dev,
6880 struct rte_flow_item_eth *eth_spec,
6881 struct rte_flow_item_eth *eth_mask)
6883 return mlx5_ctrl_flow_vlan(dev, eth_spec, eth_mask, NULL, NULL);
6887 * Create default miss flow rule matching lacp traffic
6890 * Pointer to Ethernet device.
6892 * An Ethernet flow spec to apply.
6895 * 0 on success, a negative errno value otherwise and rte_errno is set.
6898 mlx5_flow_lacp_miss(struct rte_eth_dev *dev)
6900 struct mlx5_priv *priv = dev->data->dev_private;
6902 * The LACP matching is done by only using ether type since using
6903 * a multicast dst mac causes kernel to give low priority to this flow.
6905 static const struct rte_flow_item_eth lacp_spec = {
6906 .type = RTE_BE16(0x8809),
6908 static const struct rte_flow_item_eth lacp_mask = {
6911 const struct rte_flow_attr attr = {
6914 struct rte_flow_item items[] = {
6916 .type = RTE_FLOW_ITEM_TYPE_ETH,
6921 .type = RTE_FLOW_ITEM_TYPE_END,
6924 struct rte_flow_action actions[] = {
6926 .type = (enum rte_flow_action_type)
6927 MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS,
6930 .type = RTE_FLOW_ACTION_TYPE_END,
6933 struct rte_flow_error error;
6934 uint32_t flow_idx = flow_list_create(dev, &priv->ctrl_flows,
6935 &attr, items, actions, false, &error);
6945 * @see rte_flow_destroy()
6949 mlx5_flow_destroy(struct rte_eth_dev *dev,
6950 struct rte_flow *flow,
6951 struct rte_flow_error *error __rte_unused)
6953 struct mlx5_priv *priv = dev->data->dev_private;
6955 flow_list_destroy(dev, &priv->flows, (uintptr_t)(void *)flow);
6960 * Destroy all flows.
6962 * @see rte_flow_flush()
6966 mlx5_flow_flush(struct rte_eth_dev *dev,
6967 struct rte_flow_error *error __rte_unused)
6969 struct mlx5_priv *priv = dev->data->dev_private;
6971 mlx5_flow_list_flush(dev, &priv->flows, false);
6978 * @see rte_flow_isolate()
6982 mlx5_flow_isolate(struct rte_eth_dev *dev,
6984 struct rte_flow_error *error)
6986 struct mlx5_priv *priv = dev->data->dev_private;
6988 if (dev->data->dev_started) {
6989 rte_flow_error_set(error, EBUSY,
6990 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6992 "port must be stopped first");
6995 priv->isolated = !!enable;
6997 dev->dev_ops = &mlx5_dev_ops_isolate;
6999 dev->dev_ops = &mlx5_dev_ops;
7001 dev->rx_descriptor_status = mlx5_rx_descriptor_status;
7002 dev->tx_descriptor_status = mlx5_tx_descriptor_status;
7010 * @see rte_flow_query()
7014 flow_drv_query(struct rte_eth_dev *dev,
7016 const struct rte_flow_action *actions,
7018 struct rte_flow_error *error)
7020 struct mlx5_priv *priv = dev->data->dev_private;
7021 const struct mlx5_flow_driver_ops *fops;
7022 struct rte_flow *flow = mlx5_ipool_get(priv->sh->ipool
7023 [MLX5_IPOOL_RTE_FLOW],
7025 enum mlx5_flow_drv_type ftype;
7028 return rte_flow_error_set(error, ENOENT,
7029 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7031 "invalid flow handle");
7033 ftype = flow->drv_type;
7034 MLX5_ASSERT(ftype > MLX5_FLOW_TYPE_MIN && ftype < MLX5_FLOW_TYPE_MAX);
7035 fops = flow_get_drv_ops(ftype);
7037 return fops->query(dev, flow, actions, data, error);
7043 * @see rte_flow_query()
7047 mlx5_flow_query(struct rte_eth_dev *dev,
7048 struct rte_flow *flow,
7049 const struct rte_flow_action *actions,
7051 struct rte_flow_error *error)
7055 ret = flow_drv_query(dev, (uintptr_t)(void *)flow, actions, data,
7063 * Get rte_flow callbacks.
7066 * Pointer to Ethernet device structure.
7068 * Pointer to operation-specific structure.
7073 mlx5_flow_ops_get(struct rte_eth_dev *dev __rte_unused,
7074 const struct rte_flow_ops **ops)
7076 *ops = &mlx5_flow_ops;
7081 * Validate meter policy actions.
7082 * Dispatcher for action type specific validation.
7085 * Pointer to the Ethernet device structure.
7087 * The meter policy action object to validate.
7089 * Attributes of flow to determine steering domain.
7090 * @param[out] is_rss
7092 * @param[out] domain_bitmap
7094 * @param[out] is_def_policy
7095 * Is default policy or not.
7097 * Perform verbose error reporting if not NULL. Initialized in case of
7101 * 0 on success, otherwise negative errno value.
7104 mlx5_flow_validate_mtr_acts(struct rte_eth_dev *dev,
7105 const struct rte_flow_action *actions[RTE_COLORS],
7106 struct rte_flow_attr *attr,
7108 uint8_t *domain_bitmap,
7109 bool *is_def_policy,
7110 struct rte_mtr_error *error)
7112 const struct mlx5_flow_driver_ops *fops;
7114 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7115 return fops->validate_mtr_acts(dev, actions, attr,
7116 is_rss, domain_bitmap, is_def_policy, error);
7120 * Destroy the meter table set.
7123 * Pointer to Ethernet device.
7124 * @param[in] mtr_policy
7125 * Meter policy struct.
7128 mlx5_flow_destroy_mtr_acts(struct rte_eth_dev *dev,
7129 struct mlx5_flow_meter_policy *mtr_policy)
7131 const struct mlx5_flow_driver_ops *fops;
7133 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7134 fops->destroy_mtr_acts(dev, mtr_policy);
7138 * Create policy action, lock free,
7139 * (mutex should be acquired by caller).
7140 * Dispatcher for action type specific call.
7143 * Pointer to the Ethernet device structure.
7144 * @param[in] mtr_policy
7145 * Meter policy struct.
7147 * Action specification used to create meter actions.
7149 * Perform verbose error reporting if not NULL. Initialized in case of
7153 * 0 on success, otherwise negative errno value.
7156 mlx5_flow_create_mtr_acts(struct rte_eth_dev *dev,
7157 struct mlx5_flow_meter_policy *mtr_policy,
7158 const struct rte_flow_action *actions[RTE_COLORS],
7159 struct rte_mtr_error *error)
7161 const struct mlx5_flow_driver_ops *fops;
7163 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7164 return fops->create_mtr_acts(dev, mtr_policy, actions, error);
7168 * Create policy rules, lock free,
7169 * (mutex should be acquired by caller).
7170 * Dispatcher for action type specific call.
7173 * Pointer to the Ethernet device structure.
7174 * @param[in] mtr_policy
7175 * Meter policy struct.
7178 * 0 on success, -1 otherwise.
7181 mlx5_flow_create_policy_rules(struct rte_eth_dev *dev,
7182 struct mlx5_flow_meter_policy *mtr_policy)
7184 const struct mlx5_flow_driver_ops *fops;
7186 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7187 return fops->create_policy_rules(dev, mtr_policy);
7191 * Destroy policy rules, lock free,
7192 * (mutex should be acquired by caller).
7193 * Dispatcher for action type specific call.
7196 * Pointer to the Ethernet device structure.
7197 * @param[in] mtr_policy
7198 * Meter policy struct.
7201 mlx5_flow_destroy_policy_rules(struct rte_eth_dev *dev,
7202 struct mlx5_flow_meter_policy *mtr_policy)
7204 const struct mlx5_flow_driver_ops *fops;
7206 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7207 fops->destroy_policy_rules(dev, mtr_policy);
7211 * Destroy the default policy table set.
7214 * Pointer to Ethernet device.
7217 mlx5_flow_destroy_def_policy(struct rte_eth_dev *dev)
7219 const struct mlx5_flow_driver_ops *fops;
7221 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7222 fops->destroy_def_policy(dev);
7226 * Destroy the default policy table set.
7229 * Pointer to Ethernet device.
7232 * 0 on success, -1 otherwise.
7235 mlx5_flow_create_def_policy(struct rte_eth_dev *dev)
7237 const struct mlx5_flow_driver_ops *fops;
7239 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7240 return fops->create_def_policy(dev);
7244 * Create the needed meter and suffix tables.
7247 * Pointer to Ethernet device.
7250 * 0 on success, -1 otherwise.
7253 mlx5_flow_create_mtr_tbls(struct rte_eth_dev *dev,
7254 struct mlx5_flow_meter_info *fm,
7256 uint8_t domain_bitmap)
7258 const struct mlx5_flow_driver_ops *fops;
7260 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7261 return fops->create_mtr_tbls(dev, fm, mtr_idx, domain_bitmap);
7265 * Destroy the meter table set.
7268 * Pointer to Ethernet device.
7270 * Pointer to the meter table set.
7273 mlx5_flow_destroy_mtr_tbls(struct rte_eth_dev *dev,
7274 struct mlx5_flow_meter_info *fm)
7276 const struct mlx5_flow_driver_ops *fops;
7278 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7279 fops->destroy_mtr_tbls(dev, fm);
7283 * Destroy the global meter drop table.
7286 * Pointer to Ethernet device.
7289 mlx5_flow_destroy_mtr_drop_tbls(struct rte_eth_dev *dev)
7291 const struct mlx5_flow_driver_ops *fops;
7293 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7294 fops->destroy_mtr_drop_tbls(dev);
7298 * Destroy the sub policy table with RX queue.
7301 * Pointer to Ethernet device.
7302 * @param[in] mtr_policy
7303 * Pointer to meter policy table.
7306 mlx5_flow_destroy_sub_policy_with_rxq(struct rte_eth_dev *dev,
7307 struct mlx5_flow_meter_policy *mtr_policy)
7309 const struct mlx5_flow_driver_ops *fops;
7311 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7312 fops->destroy_sub_policy_with_rxq(dev, mtr_policy);
7316 * Allocate the needed aso flow meter id.
7319 * Pointer to Ethernet device.
7322 * Index to aso flow meter on success, NULL otherwise.
7325 mlx5_flow_mtr_alloc(struct rte_eth_dev *dev)
7327 const struct mlx5_flow_driver_ops *fops;
7329 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7330 return fops->create_meter(dev);
7334 * Free the aso flow meter id.
7337 * Pointer to Ethernet device.
7338 * @param[in] mtr_idx
7339 * Index to aso flow meter to be free.
7345 mlx5_flow_mtr_free(struct rte_eth_dev *dev, uint32_t mtr_idx)
7347 const struct mlx5_flow_driver_ops *fops;
7349 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7350 fops->free_meter(dev, mtr_idx);
7354 * Allocate a counter.
7357 * Pointer to Ethernet device structure.
7360 * Index to allocated counter on success, 0 otherwise.
7363 mlx5_counter_alloc(struct rte_eth_dev *dev)
7365 const struct mlx5_flow_driver_ops *fops;
7366 struct rte_flow_attr attr = { .transfer = 0 };
7368 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
7369 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7370 return fops->counter_alloc(dev);
7373 "port %u counter allocate is not supported.",
7374 dev->data->port_id);
7382 * Pointer to Ethernet device structure.
7384 * Index to counter to be free.
7387 mlx5_counter_free(struct rte_eth_dev *dev, uint32_t cnt)
7389 const struct mlx5_flow_driver_ops *fops;
7390 struct rte_flow_attr attr = { .transfer = 0 };
7392 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
7393 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7394 fops->counter_free(dev, cnt);
7398 "port %u counter free is not supported.",
7399 dev->data->port_id);
7403 * Query counter statistics.
7406 * Pointer to Ethernet device structure.
7408 * Index to counter to query.
7410 * Set to clear counter statistics.
7412 * The counter hits packets number to save.
7414 * The counter hits bytes number to save.
7417 * 0 on success, a negative errno value otherwise.
7420 mlx5_counter_query(struct rte_eth_dev *dev, uint32_t cnt,
7421 bool clear, uint64_t *pkts, uint64_t *bytes)
7423 const struct mlx5_flow_driver_ops *fops;
7424 struct rte_flow_attr attr = { .transfer = 0 };
7426 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
7427 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7428 return fops->counter_query(dev, cnt, clear, pkts, bytes);
7431 "port %u counter query is not supported.",
7432 dev->data->port_id);
7437 * Allocate a new memory for the counter values wrapped by all the needed
7441 * Pointer to mlx5_dev_ctx_shared object.
7444 * 0 on success, a negative errno value otherwise.
7447 mlx5_flow_create_counter_stat_mem_mng(struct mlx5_dev_ctx_shared *sh)
7449 struct mlx5_devx_mkey_attr mkey_attr;
7450 struct mlx5_counter_stats_mem_mng *mem_mng;
7451 volatile struct flow_counter_stats *raw_data;
7452 int raws_n = MLX5_CNT_CONTAINER_RESIZE + MLX5_MAX_PENDING_QUERIES;
7453 int size = (sizeof(struct flow_counter_stats) *
7454 MLX5_COUNTERS_PER_POOL +
7455 sizeof(struct mlx5_counter_stats_raw)) * raws_n +
7456 sizeof(struct mlx5_counter_stats_mem_mng);
7457 size_t pgsize = rte_mem_page_size();
7461 if (pgsize == (size_t)-1) {
7462 DRV_LOG(ERR, "Failed to get mem page size");
7466 mem = mlx5_malloc(MLX5_MEM_ZERO, size, pgsize, SOCKET_ID_ANY);
7471 mem_mng = (struct mlx5_counter_stats_mem_mng *)(mem + size) - 1;
7472 size = sizeof(*raw_data) * MLX5_COUNTERS_PER_POOL * raws_n;
7473 mem_mng->umem = mlx5_os_umem_reg(sh->ctx, mem, size,
7474 IBV_ACCESS_LOCAL_WRITE);
7475 if (!mem_mng->umem) {
7480 memset(&mkey_attr, 0, sizeof(mkey_attr));
7481 mkey_attr.addr = (uintptr_t)mem;
7482 mkey_attr.size = size;
7483 mkey_attr.umem_id = mlx5_os_get_umem_id(mem_mng->umem);
7484 mkey_attr.pd = sh->pdn;
7485 mkey_attr.relaxed_ordering_write = sh->cmng.relaxed_ordering_write;
7486 mkey_attr.relaxed_ordering_read = sh->cmng.relaxed_ordering_read;
7487 mem_mng->dm = mlx5_devx_cmd_mkey_create(sh->ctx, &mkey_attr);
7489 mlx5_os_umem_dereg(mem_mng->umem);
7494 mem_mng->raws = (struct mlx5_counter_stats_raw *)(mem + size);
7495 raw_data = (volatile struct flow_counter_stats *)mem;
7496 for (i = 0; i < raws_n; ++i) {
7497 mem_mng->raws[i].mem_mng = mem_mng;
7498 mem_mng->raws[i].data = raw_data + i * MLX5_COUNTERS_PER_POOL;
7500 for (i = 0; i < MLX5_MAX_PENDING_QUERIES; ++i)
7501 LIST_INSERT_HEAD(&sh->cmng.free_stat_raws,
7502 mem_mng->raws + MLX5_CNT_CONTAINER_RESIZE + i,
7504 LIST_INSERT_HEAD(&sh->cmng.mem_mngs, mem_mng, next);
7505 sh->cmng.mem_mng = mem_mng;
7510 * Set the statistic memory to the new counter pool.
7513 * Pointer to mlx5_dev_ctx_shared object.
7515 * Pointer to the pool to set the statistic memory.
7518 * 0 on success, a negative errno value otherwise.
7521 mlx5_flow_set_counter_stat_mem(struct mlx5_dev_ctx_shared *sh,
7522 struct mlx5_flow_counter_pool *pool)
7524 struct mlx5_flow_counter_mng *cmng = &sh->cmng;
7525 /* Resize statistic memory once used out. */
7526 if (!(pool->index % MLX5_CNT_CONTAINER_RESIZE) &&
7527 mlx5_flow_create_counter_stat_mem_mng(sh)) {
7528 DRV_LOG(ERR, "Cannot resize counter stat mem.");
7531 rte_spinlock_lock(&pool->sl);
7532 pool->raw = cmng->mem_mng->raws + pool->index %
7533 MLX5_CNT_CONTAINER_RESIZE;
7534 rte_spinlock_unlock(&pool->sl);
7535 pool->raw_hw = NULL;
7539 #define MLX5_POOL_QUERY_FREQ_US 1000000
7542 * Set the periodic procedure for triggering asynchronous batch queries for all
7543 * the counter pools.
7546 * Pointer to mlx5_dev_ctx_shared object.
7549 mlx5_set_query_alarm(struct mlx5_dev_ctx_shared *sh)
7551 uint32_t pools_n, us;
7553 pools_n = __atomic_load_n(&sh->cmng.n_valid, __ATOMIC_RELAXED);
7554 us = MLX5_POOL_QUERY_FREQ_US / pools_n;
7555 DRV_LOG(DEBUG, "Set alarm for %u pools each %u us", pools_n, us);
7556 if (rte_eal_alarm_set(us, mlx5_flow_query_alarm, sh)) {
7557 sh->cmng.query_thread_on = 0;
7558 DRV_LOG(ERR, "Cannot reinitialize query alarm");
7560 sh->cmng.query_thread_on = 1;
7565 * The periodic procedure for triggering asynchronous batch queries for all the
7566 * counter pools. This function is probably called by the host thread.
7569 * The parameter for the alarm process.
7572 mlx5_flow_query_alarm(void *arg)
7574 struct mlx5_dev_ctx_shared *sh = arg;
7576 uint16_t pool_index = sh->cmng.pool_index;
7577 struct mlx5_flow_counter_mng *cmng = &sh->cmng;
7578 struct mlx5_flow_counter_pool *pool;
7581 if (sh->cmng.pending_queries >= MLX5_MAX_PENDING_QUERIES)
7583 rte_spinlock_lock(&cmng->pool_update_sl);
7584 pool = cmng->pools[pool_index];
7585 n_valid = cmng->n_valid;
7586 rte_spinlock_unlock(&cmng->pool_update_sl);
7587 /* Set the statistic memory to the new created pool. */
7588 if ((!pool->raw && mlx5_flow_set_counter_stat_mem(sh, pool)))
7591 /* There is a pool query in progress. */
7594 LIST_FIRST(&sh->cmng.free_stat_raws);
7596 /* No free counter statistics raw memory. */
7599 * Identify the counters released between query trigger and query
7600 * handle more efficiently. The counter released in this gap period
7601 * should wait for a new round of query as the new arrived packets
7602 * will not be taken into account.
7605 ret = mlx5_devx_cmd_flow_counter_query(pool->min_dcs, 0,
7606 MLX5_COUNTERS_PER_POOL,
7608 pool->raw_hw->mem_mng->dm->id,
7612 (uint64_t)(uintptr_t)pool);
7614 DRV_LOG(ERR, "Failed to trigger asynchronous query for dcs ID"
7615 " %d", pool->min_dcs->id);
7616 pool->raw_hw = NULL;
7619 LIST_REMOVE(pool->raw_hw, next);
7620 sh->cmng.pending_queries++;
7622 if (pool_index >= n_valid)
7625 sh->cmng.pool_index = pool_index;
7626 mlx5_set_query_alarm(sh);
7630 * Check and callback event for new aged flow in the counter pool
7633 * Pointer to mlx5_dev_ctx_shared object.
7635 * Pointer to Current counter pool.
7638 mlx5_flow_aging_check(struct mlx5_dev_ctx_shared *sh,
7639 struct mlx5_flow_counter_pool *pool)
7641 struct mlx5_priv *priv;
7642 struct mlx5_flow_counter *cnt;
7643 struct mlx5_age_info *age_info;
7644 struct mlx5_age_param *age_param;
7645 struct mlx5_counter_stats_raw *cur = pool->raw_hw;
7646 struct mlx5_counter_stats_raw *prev = pool->raw;
7647 const uint64_t curr_time = MLX5_CURR_TIME_SEC;
7648 const uint32_t time_delta = curr_time - pool->time_of_last_age_check;
7649 uint16_t expected = AGE_CANDIDATE;
7652 pool->time_of_last_age_check = curr_time;
7653 for (i = 0; i < MLX5_COUNTERS_PER_POOL; ++i) {
7654 cnt = MLX5_POOL_GET_CNT(pool, i);
7655 age_param = MLX5_CNT_TO_AGE(cnt);
7656 if (__atomic_load_n(&age_param->state,
7657 __ATOMIC_RELAXED) != AGE_CANDIDATE)
7659 if (cur->data[i].hits != prev->data[i].hits) {
7660 __atomic_store_n(&age_param->sec_since_last_hit, 0,
7664 if (__atomic_add_fetch(&age_param->sec_since_last_hit,
7666 __ATOMIC_RELAXED) <= age_param->timeout)
7669 * Hold the lock first, or if between the
7670 * state AGE_TMOUT and tailq operation the
7671 * release happened, the release procedure
7672 * may delete a non-existent tailq node.
7674 priv = rte_eth_devices[age_param->port_id].data->dev_private;
7675 age_info = GET_PORT_AGE_INFO(priv);
7676 rte_spinlock_lock(&age_info->aged_sl);
7677 if (__atomic_compare_exchange_n(&age_param->state, &expected,
7680 __ATOMIC_RELAXED)) {
7681 TAILQ_INSERT_TAIL(&age_info->aged_counters, cnt, next);
7682 MLX5_AGE_SET(age_info, MLX5_AGE_EVENT_NEW);
7684 rte_spinlock_unlock(&age_info->aged_sl);
7686 mlx5_age_event_prepare(sh);
7690 * Handler for the HW respond about ready values from an asynchronous batch
7691 * query. This function is probably called by the host thread.
7694 * The pointer to the shared device context.
7695 * @param[in] async_id
7696 * The Devx async ID.
7698 * The status of the completion.
7701 mlx5_flow_async_pool_query_handle(struct mlx5_dev_ctx_shared *sh,
7702 uint64_t async_id, int status)
7704 struct mlx5_flow_counter_pool *pool =
7705 (struct mlx5_flow_counter_pool *)(uintptr_t)async_id;
7706 struct mlx5_counter_stats_raw *raw_to_free;
7707 uint8_t query_gen = pool->query_gen ^ 1;
7708 struct mlx5_flow_counter_mng *cmng = &sh->cmng;
7709 enum mlx5_counter_type cnt_type =
7710 pool->is_aged ? MLX5_COUNTER_TYPE_AGE :
7711 MLX5_COUNTER_TYPE_ORIGIN;
7713 if (unlikely(status)) {
7714 raw_to_free = pool->raw_hw;
7716 raw_to_free = pool->raw;
7718 mlx5_flow_aging_check(sh, pool);
7719 rte_spinlock_lock(&pool->sl);
7720 pool->raw = pool->raw_hw;
7721 rte_spinlock_unlock(&pool->sl);
7722 /* Be sure the new raw counters data is updated in memory. */
7724 if (!TAILQ_EMPTY(&pool->counters[query_gen])) {
7725 rte_spinlock_lock(&cmng->csl[cnt_type]);
7726 TAILQ_CONCAT(&cmng->counters[cnt_type],
7727 &pool->counters[query_gen], next);
7728 rte_spinlock_unlock(&cmng->csl[cnt_type]);
7731 LIST_INSERT_HEAD(&sh->cmng.free_stat_raws, raw_to_free, next);
7732 pool->raw_hw = NULL;
7733 sh->cmng.pending_queries--;
7737 flow_group_to_table(uint32_t port_id, uint32_t group, uint32_t *table,
7738 const struct flow_grp_info *grp_info,
7739 struct rte_flow_error *error)
7741 if (grp_info->transfer && grp_info->external &&
7742 grp_info->fdb_def_rule) {
7743 if (group == UINT32_MAX)
7744 return rte_flow_error_set
7746 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
7748 "group index not supported");
7753 DRV_LOG(DEBUG, "port %u group=%#x table=%#x", port_id, group, *table);
7758 * Translate the rte_flow group index to HW table value.
7760 * If tunnel offload is disabled, all group ids converted to flow table
7761 * id using the standard method.
7762 * If tunnel offload is enabled, group id can be converted using the
7763 * standard or tunnel conversion method. Group conversion method
7764 * selection depends on flags in `grp_info` parameter:
7765 * - Internal (grp_info.external == 0) groups conversion uses the
7767 * - Group ids in JUMP action converted with the tunnel conversion.
7768 * - Group id in rule attribute conversion depends on a rule type and
7770 * ** non zero group attributes converted with the tunnel method
7771 * ** zero group attribute in non-tunnel rule is converted using the
7772 * standard method - there's only one root table
7773 * ** zero group attribute in steer tunnel rule is converted with the
7774 * standard method - single root table
7775 * ** zero group attribute in match tunnel rule is a special OvS
7776 * case: that value is used for portability reasons. That group
7777 * id is converted with the tunnel conversion method.
7782 * PMD tunnel offload object
7784 * rte_flow group index value.
7787 * @param[in] grp_info
7788 * flags used for conversion
7790 * Pointer to error structure.
7793 * 0 on success, a negative errno value otherwise and rte_errno is set.
7796 mlx5_flow_group_to_table(struct rte_eth_dev *dev,
7797 const struct mlx5_flow_tunnel *tunnel,
7798 uint32_t group, uint32_t *table,
7799 const struct flow_grp_info *grp_info,
7800 struct rte_flow_error *error)
7803 bool standard_translation;
7805 if (!grp_info->skip_scale && grp_info->external &&
7806 group < MLX5_MAX_TABLES_EXTERNAL)
7807 group *= MLX5_FLOW_TABLE_FACTOR;
7808 if (is_tunnel_offload_active(dev)) {
7809 standard_translation = !grp_info->external ||
7810 grp_info->std_tbl_fix;
7812 standard_translation = true;
7815 "port %u group=%u transfer=%d external=%d fdb_def_rule=%d translate=%s",
7816 dev->data->port_id, group, grp_info->transfer,
7817 grp_info->external, grp_info->fdb_def_rule,
7818 standard_translation ? "STANDARD" : "TUNNEL");
7819 if (standard_translation)
7820 ret = flow_group_to_table(dev->data->port_id, group, table,
7823 ret = tunnel_flow_group_to_flow_table(dev, tunnel, group,
7830 * Discover availability of metadata reg_c's.
7832 * Iteratively use test flows to check availability.
7835 * Pointer to the Ethernet device structure.
7838 * 0 on success, a negative errno value otherwise and rte_errno is set.
7841 mlx5_flow_discover_mreg_c(struct rte_eth_dev *dev)
7843 struct mlx5_priv *priv = dev->data->dev_private;
7844 struct mlx5_dev_config *config = &priv->config;
7845 enum modify_reg idx;
7848 /* reg_c[0] and reg_c[1] are reserved. */
7849 config->flow_mreg_c[n++] = REG_C_0;
7850 config->flow_mreg_c[n++] = REG_C_1;
7851 /* Discover availability of other reg_c's. */
7852 for (idx = REG_C_2; idx <= REG_C_7; ++idx) {
7853 struct rte_flow_attr attr = {
7854 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
7855 .priority = MLX5_FLOW_LOWEST_PRIO_INDICATOR,
7858 struct rte_flow_item items[] = {
7860 .type = RTE_FLOW_ITEM_TYPE_END,
7863 struct rte_flow_action actions[] = {
7865 .type = (enum rte_flow_action_type)
7866 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
7867 .conf = &(struct mlx5_flow_action_copy_mreg){
7873 .type = RTE_FLOW_ACTION_TYPE_JUMP,
7874 .conf = &(struct rte_flow_action_jump){
7875 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
7879 .type = RTE_FLOW_ACTION_TYPE_END,
7883 struct rte_flow *flow;
7884 struct rte_flow_error error;
7886 if (!config->dv_flow_en)
7888 /* Create internal flow, validation skips copy action. */
7889 flow_idx = flow_list_create(dev, NULL, &attr, items,
7890 actions, false, &error);
7891 flow = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW],
7895 config->flow_mreg_c[n++] = idx;
7896 flow_list_destroy(dev, NULL, flow_idx);
7898 for (; n < MLX5_MREG_C_NUM; ++n)
7899 config->flow_mreg_c[n] = REG_NON;
7904 save_dump_file(const uint8_t *data, uint32_t size,
7905 uint32_t type, uint32_t id, void *arg, FILE *file)
7907 char line[BUF_SIZE];
7910 uint32_t actions_num;
7911 struct rte_flow_query_count *count;
7913 memset(line, 0, BUF_SIZE);
7915 case DR_DUMP_REC_TYPE_PMD_MODIFY_HDR:
7916 actions_num = *(uint32_t *)(arg);
7917 out += snprintf(line + out, BUF_SIZE - out, "%d,0x%x,%d,",
7918 type, id, actions_num);
7920 case DR_DUMP_REC_TYPE_PMD_PKT_REFORMAT:
7921 out += snprintf(line + out, BUF_SIZE - out, "%d,0x%x,",
7924 case DR_DUMP_REC_TYPE_PMD_COUNTER:
7925 count = (struct rte_flow_query_count *)arg;
7926 fprintf(file, "%d,0x%x,%" PRIu64 ",%" PRIu64 "\n", type,
7927 id, count->hits, count->bytes);
7933 for (k = 0; k < size; k++) {
7934 /* Make sure we do not overrun the line buffer length. */
7935 if (out >= BUF_SIZE - 4) {
7939 out += snprintf(line + out, BUF_SIZE - out, "%02x",
7942 fprintf(file, "%s\n", line);
7947 mlx5_flow_query_counter(struct rte_eth_dev *dev, struct rte_flow *flow,
7948 struct rte_flow_query_count *count, struct rte_flow_error *error)
7950 struct rte_flow_action action[2];
7951 enum mlx5_flow_drv_type ftype;
7952 const struct mlx5_flow_driver_ops *fops;
7955 return rte_flow_error_set(error, ENOENT,
7956 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7958 "invalid flow handle");
7960 action[0].type = RTE_FLOW_ACTION_TYPE_COUNT;
7961 action[1].type = RTE_FLOW_ACTION_TYPE_END;
7962 if (flow->counter) {
7963 memset(count, 0, sizeof(struct rte_flow_query_count));
7964 ftype = (enum mlx5_flow_drv_type)(flow->drv_type);
7965 MLX5_ASSERT(ftype > MLX5_FLOW_TYPE_MIN &&
7966 ftype < MLX5_FLOW_TYPE_MAX);
7967 fops = flow_get_drv_ops(ftype);
7968 return fops->query(dev, flow, action, count, error);
7973 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
7975 * Dump flow ipool data to file
7978 * The pointer to Ethernet device.
7980 * A pointer to a file for output.
7982 * Perform verbose error reporting if not NULL. PMDs initialize this
7983 * structure in case of error only.
7985 * 0 on success, a negative value otherwise.
7988 mlx5_flow_dev_dump_ipool(struct rte_eth_dev *dev,
7989 struct rte_flow *flow, FILE *file,
7990 struct rte_flow_error *error)
7992 struct mlx5_priv *priv = dev->data->dev_private;
7993 struct mlx5_flow_dv_modify_hdr_resource *modify_hdr;
7994 struct mlx5_flow_dv_encap_decap_resource *encap_decap;
7995 uint32_t handle_idx;
7996 struct mlx5_flow_handle *dh;
7997 struct rte_flow_query_count count;
7998 uint32_t actions_num;
7999 const uint8_t *data;
8005 return rte_flow_error_set(error, ENOENT,
8006 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8008 "invalid flow handle");
8010 handle_idx = flow->dev_handles;
8011 while (handle_idx) {
8012 dh = mlx5_ipool_get(priv->sh->ipool
8013 [MLX5_IPOOL_MLX5_FLOW], handle_idx);
8016 handle_idx = dh->next.next;
8017 id = (uint32_t)(uintptr_t)dh->drv_flow;
8020 type = DR_DUMP_REC_TYPE_PMD_COUNTER;
8021 if (!mlx5_flow_query_counter(dev, flow, &count, error))
8022 save_dump_file(NULL, 0, type,
8023 id, (void *)&count, file);
8025 /* Get modify_hdr and encap_decap buf from ipools. */
8027 modify_hdr = dh->dvh.modify_hdr;
8029 if (dh->dvh.rix_encap_decap) {
8030 encap_decap = mlx5_ipool_get(priv->sh->ipool
8031 [MLX5_IPOOL_DECAP_ENCAP],
8032 dh->dvh.rix_encap_decap);
8035 data = (const uint8_t *)modify_hdr->actions;
8036 size = (size_t)(modify_hdr->actions_num) * 8;
8037 actions_num = modify_hdr->actions_num;
8038 type = DR_DUMP_REC_TYPE_PMD_MODIFY_HDR;
8039 save_dump_file(data, size, type, id,
8040 (void *)(&actions_num), file);
8043 data = encap_decap->buf;
8044 size = encap_decap->size;
8045 type = DR_DUMP_REC_TYPE_PMD_PKT_REFORMAT;
8046 save_dump_file(data, size, type,
8055 * Dump flow raw hw data to file
8058 * The pointer to Ethernet device.
8060 * A pointer to a file for output.
8062 * Perform verbose error reporting if not NULL. PMDs initialize this
8063 * structure in case of error only.
8065 * 0 on success, a nagative value otherwise.
8068 mlx5_flow_dev_dump(struct rte_eth_dev *dev, struct rte_flow *flow_idx,
8070 struct rte_flow_error *error __rte_unused)
8072 struct mlx5_priv *priv = dev->data->dev_private;
8073 struct mlx5_dev_ctx_shared *sh = priv->sh;
8074 uint32_t handle_idx;
8076 struct mlx5_flow_handle *dh;
8077 struct rte_flow *flow;
8078 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
8082 if (!priv->config.dv_flow_en) {
8083 if (fputs("device dv flow disabled\n", file) <= 0)
8090 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
8091 ILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW],
8092 priv->flows, idx, flow, next)
8093 mlx5_flow_dev_dump_ipool(dev, flow, file, error);
8095 return mlx5_devx_cmd_flow_dump(sh->fdb_domain,
8097 sh->tx_domain, file);
8100 flow = mlx5_ipool_get(priv->sh->ipool
8101 [MLX5_IPOOL_RTE_FLOW], (uintptr_t)(void *)flow_idx);
8105 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
8106 mlx5_flow_dev_dump_ipool(dev, flow, file, error);
8108 handle_idx = flow->dev_handles;
8109 while (handle_idx) {
8110 dh = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
8115 ret = mlx5_devx_cmd_flow_single_dump(dh->drv_flow,
8120 handle_idx = dh->next.next;
8126 * Get aged-out flows.
8129 * Pointer to the Ethernet device structure.
8130 * @param[in] context
8131 * The address of an array of pointers to the aged-out flows contexts.
8132 * @param[in] nb_countexts
8133 * The length of context array pointers.
8135 * Perform verbose error reporting if not NULL. Initialized in case of
8139 * how many contexts get in success, otherwise negative errno value.
8140 * if nb_contexts is 0, return the amount of all aged contexts.
8141 * if nb_contexts is not 0 , return the amount of aged flows reported
8142 * in the context array.
8145 mlx5_flow_get_aged_flows(struct rte_eth_dev *dev, void **contexts,
8146 uint32_t nb_contexts, struct rte_flow_error *error)
8148 const struct mlx5_flow_driver_ops *fops;
8149 struct rte_flow_attr attr = { .transfer = 0 };
8151 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
8152 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
8153 return fops->get_aged_flows(dev, contexts, nb_contexts,
8157 "port %u get aged flows is not supported.",
8158 dev->data->port_id);
8162 /* Wrapper for driver action_validate op callback */
8164 flow_drv_action_validate(struct rte_eth_dev *dev,
8165 const struct rte_flow_indir_action_conf *conf,
8166 const struct rte_flow_action *action,
8167 const struct mlx5_flow_driver_ops *fops,
8168 struct rte_flow_error *error)
8170 static const char err_msg[] = "indirect action validation unsupported";
8172 if (!fops->action_validate) {
8173 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
8174 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
8178 return fops->action_validate(dev, conf, action, error);
8182 * Destroys the shared action by handle.
8185 * Pointer to Ethernet device structure.
8187 * Handle for the indirect action object to be destroyed.
8189 * Perform verbose error reporting if not NULL. PMDs initialize this
8190 * structure in case of error only.
8193 * 0 on success, a negative errno value otherwise and rte_errno is set.
8195 * @note: wrapper for driver action_create op callback.
8198 mlx5_action_handle_destroy(struct rte_eth_dev *dev,
8199 struct rte_flow_action_handle *handle,
8200 struct rte_flow_error *error)
8202 static const char err_msg[] = "indirect action destruction unsupported";
8203 struct rte_flow_attr attr = { .transfer = 0 };
8204 const struct mlx5_flow_driver_ops *fops =
8205 flow_get_drv_ops(flow_get_drv_type(dev, &attr));
8207 if (!fops->action_destroy) {
8208 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
8209 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
8213 return fops->action_destroy(dev, handle, error);
8216 /* Wrapper for driver action_destroy op callback */
8218 flow_drv_action_update(struct rte_eth_dev *dev,
8219 struct rte_flow_action_handle *handle,
8221 const struct mlx5_flow_driver_ops *fops,
8222 struct rte_flow_error *error)
8224 static const char err_msg[] = "indirect action update unsupported";
8226 if (!fops->action_update) {
8227 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
8228 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
8232 return fops->action_update(dev, handle, update, error);
8235 /* Wrapper for driver action_destroy op callback */
8237 flow_drv_action_query(struct rte_eth_dev *dev,
8238 const struct rte_flow_action_handle *handle,
8240 const struct mlx5_flow_driver_ops *fops,
8241 struct rte_flow_error *error)
8243 static const char err_msg[] = "indirect action query unsupported";
8245 if (!fops->action_query) {
8246 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
8247 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
8251 return fops->action_query(dev, handle, data, error);
8255 * Create indirect action for reuse in multiple flow rules.
8258 * Pointer to Ethernet device structure.
8260 * Pointer to indirect action object configuration.
8262 * Action configuration for indirect action object creation.
8264 * Perform verbose error reporting if not NULL. PMDs initialize this
8265 * structure in case of error only.
8267 * A valid handle in case of success, NULL otherwise and rte_errno is set.
8269 static struct rte_flow_action_handle *
8270 mlx5_action_handle_create(struct rte_eth_dev *dev,
8271 const struct rte_flow_indir_action_conf *conf,
8272 const struct rte_flow_action *action,
8273 struct rte_flow_error *error)
8275 static const char err_msg[] = "indirect action creation unsupported";
8276 struct rte_flow_attr attr = { .transfer = 0 };
8277 const struct mlx5_flow_driver_ops *fops =
8278 flow_get_drv_ops(flow_get_drv_type(dev, &attr));
8280 if (flow_drv_action_validate(dev, conf, action, fops, error))
8282 if (!fops->action_create) {
8283 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
8284 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
8288 return fops->action_create(dev, conf, action, error);
8292 * Updates inplace the indirect action configuration pointed by *handle*
8293 * with the configuration provided as *update* argument.
8294 * The update of the indirect action configuration effects all flow rules
8295 * reusing the action via handle.
8298 * Pointer to Ethernet device structure.
8300 * Handle for the indirect action to be updated.
8302 * Action specification used to modify the action pointed by handle.
8303 * *update* could be of same type with the action pointed by the *handle*
8304 * handle argument, or some other structures like a wrapper, depending on
8305 * the indirect action type.
8307 * Perform verbose error reporting if not NULL. PMDs initialize this
8308 * structure in case of error only.
8311 * 0 on success, a negative errno value otherwise and rte_errno is set.
8314 mlx5_action_handle_update(struct rte_eth_dev *dev,
8315 struct rte_flow_action_handle *handle,
8317 struct rte_flow_error *error)
8319 struct rte_flow_attr attr = { .transfer = 0 };
8320 const struct mlx5_flow_driver_ops *fops =
8321 flow_get_drv_ops(flow_get_drv_type(dev, &attr));
8324 ret = flow_drv_action_validate(dev, NULL,
8325 (const struct rte_flow_action *)update, fops, error);
8328 return flow_drv_action_update(dev, handle, update, fops,
8333 * Query the indirect action by handle.
8335 * This function allows retrieving action-specific data such as counters.
8336 * Data is gathered by special action which may be present/referenced in
8337 * more than one flow rule definition.
8339 * see @RTE_FLOW_ACTION_TYPE_COUNT
8342 * Pointer to Ethernet device structure.
8344 * Handle for the indirect action to query.
8345 * @param[in, out] data
8346 * Pointer to storage for the associated query data type.
8348 * Perform verbose error reporting if not NULL. PMDs initialize this
8349 * structure in case of error only.
8352 * 0 on success, a negative errno value otherwise and rte_errno is set.
8355 mlx5_action_handle_query(struct rte_eth_dev *dev,
8356 const struct rte_flow_action_handle *handle,
8358 struct rte_flow_error *error)
8360 struct rte_flow_attr attr = { .transfer = 0 };
8361 const struct mlx5_flow_driver_ops *fops =
8362 flow_get_drv_ops(flow_get_drv_type(dev, &attr));
8364 return flow_drv_action_query(dev, handle, data, fops, error);
8368 * Destroy all indirect actions (shared RSS).
8371 * Pointer to Ethernet device.
8374 * 0 on success, a negative errno value otherwise and rte_errno is set.
8377 mlx5_action_handle_flush(struct rte_eth_dev *dev)
8379 struct rte_flow_error error;
8380 struct mlx5_priv *priv = dev->data->dev_private;
8381 struct mlx5_shared_action_rss *shared_rss;
8385 ILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
8386 priv->rss_shared_actions, idx, shared_rss, next) {
8387 ret |= mlx5_action_handle_destroy(dev,
8388 (struct rte_flow_action_handle *)(uintptr_t)idx, &error);
8393 #ifndef HAVE_MLX5DV_DR
8394 #define MLX5_DOMAIN_SYNC_FLOW ((1 << 0) | (1 << 1))
8396 #define MLX5_DOMAIN_SYNC_FLOW \
8397 (MLX5DV_DR_DOMAIN_SYNC_FLAGS_SW | MLX5DV_DR_DOMAIN_SYNC_FLAGS_HW)
8400 int rte_pmd_mlx5_sync_flow(uint16_t port_id, uint32_t domains)
8402 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
8403 const struct mlx5_flow_driver_ops *fops;
8405 struct rte_flow_attr attr = { .transfer = 0 };
8407 fops = flow_get_drv_ops(flow_get_drv_type(dev, &attr));
8408 ret = fops->sync_domain(dev, domains, MLX5_DOMAIN_SYNC_FLOW);
8414 const struct mlx5_flow_tunnel *
8415 mlx5_get_tof(const struct rte_flow_item *item,
8416 const struct rte_flow_action *action,
8417 enum mlx5_tof_rule_type *rule_type)
8419 for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
8420 if (item->type == (typeof(item->type))
8421 MLX5_RTE_FLOW_ITEM_TYPE_TUNNEL) {
8422 *rule_type = MLX5_TUNNEL_OFFLOAD_MATCH_RULE;
8423 return flow_items_to_tunnel(item);
8426 for (; action->conf != RTE_FLOW_ACTION_TYPE_END; action++) {
8427 if (action->type == (typeof(action->type))
8428 MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET) {
8429 *rule_type = MLX5_TUNNEL_OFFLOAD_SET_RULE;
8430 return flow_actions_to_tunnel(action);
8437 * tunnel offload functionalilty is defined for DV environment only
8439 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
8441 union tunnel_offload_mark {
8444 uint32_t app_reserve:8;
8445 uint32_t table_id:15;
8446 uint32_t transfer:1;
8447 uint32_t _unused_:8;
8452 mlx5_access_tunnel_offload_db
8453 (struct rte_eth_dev *dev,
8454 bool (*match)(struct rte_eth_dev *,
8455 struct mlx5_flow_tunnel *, const void *),
8456 void (*hit)(struct rte_eth_dev *, struct mlx5_flow_tunnel *, void *),
8457 void (*miss)(struct rte_eth_dev *, void *),
8458 void *ctx, bool lock_op);
8461 flow_tunnel_add_default_miss(struct rte_eth_dev *dev,
8462 struct rte_flow *flow,
8463 const struct rte_flow_attr *attr,
8464 const struct rte_flow_action *app_actions,
8466 const struct mlx5_flow_tunnel *tunnel,
8467 struct tunnel_default_miss_ctx *ctx,
8468 struct rte_flow_error *error)
8470 struct mlx5_priv *priv = dev->data->dev_private;
8471 struct mlx5_flow *dev_flow;
8472 struct rte_flow_attr miss_attr = *attr;
8473 const struct rte_flow_item miss_items[2] = {
8475 .type = RTE_FLOW_ITEM_TYPE_ETH,
8481 .type = RTE_FLOW_ITEM_TYPE_END,
8487 union tunnel_offload_mark mark_id;
8488 struct rte_flow_action_mark miss_mark;
8489 struct rte_flow_action miss_actions[3] = {
8490 [0] = { .type = RTE_FLOW_ACTION_TYPE_MARK, .conf = &miss_mark },
8491 [2] = { .type = RTE_FLOW_ACTION_TYPE_END, .conf = NULL }
8493 const struct rte_flow_action_jump *jump_data;
8494 uint32_t i, flow_table = 0; /* prevent compilation warning */
8495 struct flow_grp_info grp_info = {
8497 .transfer = attr->transfer,
8498 .fdb_def_rule = !!priv->fdb_def_rule,
8503 if (!attr->transfer) {
8506 miss_actions[1].type = RTE_FLOW_ACTION_TYPE_RSS;
8507 q_size = priv->reta_idx_n * sizeof(ctx->queue[0]);
8508 ctx->queue = mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO, q_size,
8511 return rte_flow_error_set
8513 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
8514 NULL, "invalid default miss RSS");
8515 ctx->action_rss.func = RTE_ETH_HASH_FUNCTION_DEFAULT,
8516 ctx->action_rss.level = 0,
8517 ctx->action_rss.types = priv->rss_conf.rss_hf,
8518 ctx->action_rss.key_len = priv->rss_conf.rss_key_len,
8519 ctx->action_rss.queue_num = priv->reta_idx_n,
8520 ctx->action_rss.key = priv->rss_conf.rss_key,
8521 ctx->action_rss.queue = ctx->queue;
8522 if (!priv->reta_idx_n || !priv->rxqs_n)
8523 return rte_flow_error_set
8525 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
8526 NULL, "invalid port configuration");
8527 if (!(dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG))
8528 ctx->action_rss.types = 0;
8529 for (i = 0; i != priv->reta_idx_n; ++i)
8530 ctx->queue[i] = (*priv->reta_idx)[i];
8532 miss_actions[1].type = RTE_FLOW_ACTION_TYPE_JUMP;
8533 ctx->miss_jump.group = MLX5_TNL_MISS_FDB_JUMP_GRP;
8535 miss_actions[1].conf = (typeof(miss_actions[1].conf))ctx->raw;
8536 for (; app_actions->type != RTE_FLOW_ACTION_TYPE_JUMP; app_actions++);
8537 jump_data = app_actions->conf;
8538 miss_attr.priority = MLX5_TNL_MISS_RULE_PRIORITY;
8539 miss_attr.group = jump_data->group;
8540 ret = mlx5_flow_group_to_table(dev, tunnel, jump_data->group,
8541 &flow_table, &grp_info, error);
8543 return rte_flow_error_set(error, EINVAL,
8544 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
8545 NULL, "invalid tunnel id");
8546 mark_id.app_reserve = 0;
8547 mark_id.table_id = tunnel_flow_tbl_to_id(flow_table);
8548 mark_id.transfer = !!attr->transfer;
8549 mark_id._unused_ = 0;
8550 miss_mark.id = mark_id.val;
8551 dev_flow = flow_drv_prepare(dev, flow, &miss_attr,
8552 miss_items, miss_actions, flow_idx, error);
8555 dev_flow->flow = flow;
8556 dev_flow->external = true;
8557 dev_flow->tunnel = tunnel;
8558 dev_flow->tof_type = MLX5_TUNNEL_OFFLOAD_MISS_RULE;
8559 /* Subflow object was created, we must include one in the list. */
8560 SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
8561 dev_flow->handle, next);
8563 "port %u tunnel type=%d id=%u miss rule priority=%u group=%u",
8564 dev->data->port_id, tunnel->app_tunnel.type,
8565 tunnel->tunnel_id, miss_attr.priority, miss_attr.group);
8566 ret = flow_drv_translate(dev, dev_flow, &miss_attr, miss_items,
8567 miss_actions, error);
8569 ret = flow_mreg_update_copy_table(dev, flow, miss_actions,
8575 static const struct mlx5_flow_tbl_data_entry *
8576 tunnel_mark_decode(struct rte_eth_dev *dev, uint32_t mark)
8578 struct mlx5_priv *priv = dev->data->dev_private;
8579 struct mlx5_dev_ctx_shared *sh = priv->sh;
8580 struct mlx5_hlist_entry *he;
8581 union tunnel_offload_mark mbits = { .val = mark };
8582 union mlx5_flow_tbl_key table_key = {
8584 .level = tunnel_id_to_flow_tbl(mbits.table_id),
8588 .is_fdb = !!mbits.transfer,
8592 he = mlx5_hlist_lookup(sh->flow_tbls, table_key.v64, NULL);
8594 container_of(he, struct mlx5_flow_tbl_data_entry, entry) : NULL;
8598 mlx5_flow_tunnel_grp2tbl_remove_cb(struct mlx5_hlist *list,
8599 struct mlx5_hlist_entry *entry)
8601 struct mlx5_dev_ctx_shared *sh = list->ctx;
8602 struct tunnel_tbl_entry *tte = container_of(entry, typeof(*tte), hash);
8604 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TNL_TBL_ID],
8605 tunnel_flow_tbl_to_id(tte->flow_table));
8610 mlx5_flow_tunnel_grp2tbl_match_cb(struct mlx5_hlist *list __rte_unused,
8611 struct mlx5_hlist_entry *entry,
8612 uint64_t key, void *cb_ctx __rte_unused)
8614 union tunnel_tbl_key tbl = {
8617 struct tunnel_tbl_entry *tte = container_of(entry, typeof(*tte), hash);
8619 return tbl.tunnel_id != tte->tunnel_id || tbl.group != tte->group;
8622 static struct mlx5_hlist_entry *
8623 mlx5_flow_tunnel_grp2tbl_create_cb(struct mlx5_hlist *list, uint64_t key,
8624 void *ctx __rte_unused)
8626 struct mlx5_dev_ctx_shared *sh = list->ctx;
8627 struct tunnel_tbl_entry *tte;
8628 union tunnel_tbl_key tbl = {
8632 tte = mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO,
8637 mlx5_ipool_malloc(sh->ipool[MLX5_IPOOL_TNL_TBL_ID],
8639 if (tte->flow_table >= MLX5_MAX_TABLES) {
8640 DRV_LOG(ERR, "Tunnel TBL ID %d exceed max limit.",
8642 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TNL_TBL_ID],
8645 } else if (!tte->flow_table) {
8648 tte->flow_table = tunnel_id_to_flow_tbl(tte->flow_table);
8649 tte->tunnel_id = tbl.tunnel_id;
8650 tte->group = tbl.group;
8659 tunnel_flow_group_to_flow_table(struct rte_eth_dev *dev,
8660 const struct mlx5_flow_tunnel *tunnel,
8661 uint32_t group, uint32_t *table,
8662 struct rte_flow_error *error)
8664 struct mlx5_hlist_entry *he;
8665 struct tunnel_tbl_entry *tte;
8666 union tunnel_tbl_key key = {
8667 .tunnel_id = tunnel ? tunnel->tunnel_id : 0,
8670 struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
8671 struct mlx5_hlist *group_hash;
8673 group_hash = tunnel ? tunnel->groups : thub->groups;
8674 he = mlx5_hlist_register(group_hash, key.val, NULL);
8676 return rte_flow_error_set(error, EINVAL,
8677 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
8679 "tunnel group index not supported");
8680 tte = container_of(he, typeof(*tte), hash);
8681 *table = tte->flow_table;
8682 DRV_LOG(DEBUG, "port %u tunnel %u group=%#x table=%#x",
8683 dev->data->port_id, key.tunnel_id, group, *table);
8688 mlx5_flow_tunnel_free(struct rte_eth_dev *dev,
8689 struct mlx5_flow_tunnel *tunnel)
8691 struct mlx5_priv *priv = dev->data->dev_private;
8692 struct mlx5_indexed_pool *ipool;
8694 DRV_LOG(DEBUG, "port %u release pmd tunnel id=0x%x",
8695 dev->data->port_id, tunnel->tunnel_id);
8696 LIST_REMOVE(tunnel, chain);
8697 mlx5_hlist_destroy(tunnel->groups);
8698 ipool = priv->sh->ipool[MLX5_IPOOL_TUNNEL_ID];
8699 mlx5_ipool_free(ipool, tunnel->tunnel_id);
8703 mlx5_access_tunnel_offload_db
8704 (struct rte_eth_dev *dev,
8705 bool (*match)(struct rte_eth_dev *,
8706 struct mlx5_flow_tunnel *, const void *),
8707 void (*hit)(struct rte_eth_dev *, struct mlx5_flow_tunnel *, void *),
8708 void (*miss)(struct rte_eth_dev *, void *),
8709 void *ctx, bool lock_op)
8711 bool verdict = false;
8712 struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
8713 struct mlx5_flow_tunnel *tunnel;
8715 rte_spinlock_lock(&thub->sl);
8716 LIST_FOREACH(tunnel, &thub->tunnels, chain) {
8717 verdict = match(dev, tunnel, (const void *)ctx);
8722 rte_spinlock_unlock(&thub->sl);
8724 hit(dev, tunnel, ctx);
8725 if (!verdict && miss)
8728 rte_spinlock_unlock(&thub->sl);
8733 struct tunnel_db_find_tunnel_id_ctx {
8735 struct mlx5_flow_tunnel *tunnel;
8739 find_tunnel_id_match(struct rte_eth_dev *dev,
8740 struct mlx5_flow_tunnel *tunnel, const void *x)
8742 const struct tunnel_db_find_tunnel_id_ctx *ctx = x;
8745 return tunnel->tunnel_id == ctx->tunnel_id;
8749 find_tunnel_id_hit(struct rte_eth_dev *dev,
8750 struct mlx5_flow_tunnel *tunnel, void *x)
8752 struct tunnel_db_find_tunnel_id_ctx *ctx = x;
8754 ctx->tunnel = tunnel;
8757 static struct mlx5_flow_tunnel *
8758 mlx5_find_tunnel_id(struct rte_eth_dev *dev, uint32_t id)
8760 struct tunnel_db_find_tunnel_id_ctx ctx = {
8764 mlx5_access_tunnel_offload_db(dev, find_tunnel_id_match,
8765 find_tunnel_id_hit, NULL, &ctx, true);
8770 static struct mlx5_flow_tunnel *
8771 mlx5_flow_tunnel_allocate(struct rte_eth_dev *dev,
8772 const struct rte_flow_tunnel *app_tunnel)
8774 struct mlx5_priv *priv = dev->data->dev_private;
8775 struct mlx5_indexed_pool *ipool;
8776 struct mlx5_flow_tunnel *tunnel;
8779 ipool = priv->sh->ipool[MLX5_IPOOL_TUNNEL_ID];
8780 tunnel = mlx5_ipool_zmalloc(ipool, &id);
8783 if (id >= MLX5_MAX_TUNNELS) {
8784 mlx5_ipool_free(ipool, id);
8785 DRV_LOG(ERR, "Tunnel ID %d exceed max limit.", id);
8788 tunnel->groups = mlx5_hlist_create("tunnel groups", 1024, 0, 0,
8789 mlx5_flow_tunnel_grp2tbl_create_cb,
8790 mlx5_flow_tunnel_grp2tbl_match_cb,
8791 mlx5_flow_tunnel_grp2tbl_remove_cb);
8792 if (!tunnel->groups) {
8793 mlx5_ipool_free(ipool, id);
8796 tunnel->groups->ctx = priv->sh;
8797 /* initiate new PMD tunnel */
8798 memcpy(&tunnel->app_tunnel, app_tunnel, sizeof(*app_tunnel));
8799 tunnel->tunnel_id = id;
8800 tunnel->action.type = (typeof(tunnel->action.type))
8801 MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET;
8802 tunnel->action.conf = tunnel;
8803 tunnel->item.type = (typeof(tunnel->item.type))
8804 MLX5_RTE_FLOW_ITEM_TYPE_TUNNEL;
8805 tunnel->item.spec = tunnel;
8806 tunnel->item.last = NULL;
8807 tunnel->item.mask = NULL;
8809 DRV_LOG(DEBUG, "port %u new pmd tunnel id=0x%x",
8810 dev->data->port_id, tunnel->tunnel_id);
8815 struct tunnel_db_get_tunnel_ctx {
8816 const struct rte_flow_tunnel *app_tunnel;
8817 struct mlx5_flow_tunnel *tunnel;
8820 static bool get_tunnel_match(struct rte_eth_dev *dev,
8821 struct mlx5_flow_tunnel *tunnel, const void *x)
8823 const struct tunnel_db_get_tunnel_ctx *ctx = x;
8826 return !memcmp(ctx->app_tunnel, &tunnel->app_tunnel,
8827 sizeof(*ctx->app_tunnel));
8830 static void get_tunnel_hit(struct rte_eth_dev *dev,
8831 struct mlx5_flow_tunnel *tunnel, void *x)
8833 /* called under tunnel spinlock protection */
8834 struct tunnel_db_get_tunnel_ctx *ctx = x;
8838 ctx->tunnel = tunnel;
8841 static void get_tunnel_miss(struct rte_eth_dev *dev, void *x)
8843 /* called under tunnel spinlock protection */
8844 struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
8845 struct tunnel_db_get_tunnel_ctx *ctx = x;
8847 rte_spinlock_unlock(&thub->sl);
8848 ctx->tunnel = mlx5_flow_tunnel_allocate(dev, ctx->app_tunnel);
8849 rte_spinlock_lock(&thub->sl);
8851 ctx->tunnel->refctn = 1;
8852 LIST_INSERT_HEAD(&thub->tunnels, ctx->tunnel, chain);
8858 mlx5_get_flow_tunnel(struct rte_eth_dev *dev,
8859 const struct rte_flow_tunnel *app_tunnel,
8860 struct mlx5_flow_tunnel **tunnel)
8862 struct tunnel_db_get_tunnel_ctx ctx = {
8863 .app_tunnel = app_tunnel,
8866 mlx5_access_tunnel_offload_db(dev, get_tunnel_match, get_tunnel_hit,
8867 get_tunnel_miss, &ctx, true);
8868 *tunnel = ctx.tunnel;
8869 return ctx.tunnel ? 0 : -ENOMEM;
8872 void mlx5_release_tunnel_hub(struct mlx5_dev_ctx_shared *sh, uint16_t port_id)
8874 struct mlx5_flow_tunnel_hub *thub = sh->tunnel_hub;
8878 if (!LIST_EMPTY(&thub->tunnels))
8879 DRV_LOG(WARNING, "port %u tunnels present", port_id);
8880 mlx5_hlist_destroy(thub->groups);
8884 int mlx5_alloc_tunnel_hub(struct mlx5_dev_ctx_shared *sh)
8887 struct mlx5_flow_tunnel_hub *thub;
8889 thub = mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO, sizeof(*thub),
8893 LIST_INIT(&thub->tunnels);
8894 rte_spinlock_init(&thub->sl);
8895 thub->groups = mlx5_hlist_create("flow groups",
8896 rte_align32pow2(MLX5_MAX_TABLES), 0,
8897 0, mlx5_flow_tunnel_grp2tbl_create_cb,
8898 mlx5_flow_tunnel_grp2tbl_match_cb,
8899 mlx5_flow_tunnel_grp2tbl_remove_cb);
8900 if (!thub->groups) {
8904 thub->groups->ctx = sh;
8905 sh->tunnel_hub = thub;
8911 mlx5_hlist_destroy(thub->groups);
8918 mlx5_flow_tunnel_validate(struct rte_eth_dev *dev,
8919 struct rte_flow_tunnel *tunnel,
8920 const char *err_msg)
8923 if (!is_tunnel_offload_active(dev)) {
8924 err_msg = "tunnel offload was not activated";
8926 } else if (!tunnel) {
8927 err_msg = "no application tunnel";
8931 switch (tunnel->type) {
8933 err_msg = "unsupported tunnel type";
8935 case RTE_FLOW_ITEM_TYPE_VXLAN:
8944 mlx5_flow_tunnel_decap_set(struct rte_eth_dev *dev,
8945 struct rte_flow_tunnel *app_tunnel,
8946 struct rte_flow_action **actions,
8947 uint32_t *num_of_actions,
8948 struct rte_flow_error *error)
8951 struct mlx5_flow_tunnel *tunnel;
8952 const char *err_msg = NULL;
8953 bool verdict = mlx5_flow_tunnel_validate(dev, app_tunnel, err_msg);
8956 return rte_flow_error_set(error, EINVAL,
8957 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
8959 ret = mlx5_get_flow_tunnel(dev, app_tunnel, &tunnel);
8961 return rte_flow_error_set(error, ret,
8962 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
8963 "failed to initialize pmd tunnel");
8965 *actions = &tunnel->action;
8966 *num_of_actions = 1;
8971 mlx5_flow_tunnel_match(struct rte_eth_dev *dev,
8972 struct rte_flow_tunnel *app_tunnel,
8973 struct rte_flow_item **items,
8974 uint32_t *num_of_items,
8975 struct rte_flow_error *error)
8978 struct mlx5_flow_tunnel *tunnel;
8979 const char *err_msg = NULL;
8980 bool verdict = mlx5_flow_tunnel_validate(dev, app_tunnel, err_msg);
8983 return rte_flow_error_set(error, EINVAL,
8984 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
8986 ret = mlx5_get_flow_tunnel(dev, app_tunnel, &tunnel);
8988 return rte_flow_error_set(error, ret,
8989 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
8990 "failed to initialize pmd tunnel");
8992 *items = &tunnel->item;
8997 struct tunnel_db_element_release_ctx {
8998 struct rte_flow_item *items;
8999 struct rte_flow_action *actions;
9000 uint32_t num_elements;
9001 struct rte_flow_error *error;
9006 tunnel_element_release_match(struct rte_eth_dev *dev,
9007 struct mlx5_flow_tunnel *tunnel, const void *x)
9009 const struct tunnel_db_element_release_ctx *ctx = x;
9012 if (ctx->num_elements != 1)
9014 else if (ctx->items)
9015 return ctx->items == &tunnel->item;
9016 else if (ctx->actions)
9017 return ctx->actions == &tunnel->action;
9023 tunnel_element_release_hit(struct rte_eth_dev *dev,
9024 struct mlx5_flow_tunnel *tunnel, void *x)
9026 struct tunnel_db_element_release_ctx *ctx = x;
9028 if (!__atomic_sub_fetch(&tunnel->refctn, 1, __ATOMIC_RELAXED))
9029 mlx5_flow_tunnel_free(dev, tunnel);
9033 tunnel_element_release_miss(struct rte_eth_dev *dev, void *x)
9035 struct tunnel_db_element_release_ctx *ctx = x;
9037 ctx->ret = rte_flow_error_set(ctx->error, EINVAL,
9038 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
9039 "invalid argument");
9043 mlx5_flow_tunnel_item_release(struct rte_eth_dev *dev,
9044 struct rte_flow_item *pmd_items,
9045 uint32_t num_items, struct rte_flow_error *err)
9047 struct tunnel_db_element_release_ctx ctx = {
9050 .num_elements = num_items,
9054 mlx5_access_tunnel_offload_db(dev, tunnel_element_release_match,
9055 tunnel_element_release_hit,
9056 tunnel_element_release_miss, &ctx, false);
9062 mlx5_flow_tunnel_action_release(struct rte_eth_dev *dev,
9063 struct rte_flow_action *pmd_actions,
9064 uint32_t num_actions, struct rte_flow_error *err)
9066 struct tunnel_db_element_release_ctx ctx = {
9068 .actions = pmd_actions,
9069 .num_elements = num_actions,
9073 mlx5_access_tunnel_offload_db(dev, tunnel_element_release_match,
9074 tunnel_element_release_hit,
9075 tunnel_element_release_miss, &ctx, false);
9081 mlx5_flow_tunnel_get_restore_info(struct rte_eth_dev *dev,
9083 struct rte_flow_restore_info *info,
9084 struct rte_flow_error *err)
9086 uint64_t ol_flags = m->ol_flags;
9087 const struct mlx5_flow_tbl_data_entry *tble;
9088 const uint64_t mask = PKT_RX_FDIR | PKT_RX_FDIR_ID;
9090 if (!is_tunnel_offload_active(dev)) {
9095 if ((ol_flags & mask) != mask)
9097 tble = tunnel_mark_decode(dev, m->hash.fdir.hi);
9099 DRV_LOG(DEBUG, "port %u invalid miss tunnel mark %#x",
9100 dev->data->port_id, m->hash.fdir.hi);
9103 MLX5_ASSERT(tble->tunnel);
9104 memcpy(&info->tunnel, &tble->tunnel->app_tunnel, sizeof(info->tunnel));
9105 info->group_id = tble->group_id;
9106 info->flags = RTE_FLOW_RESTORE_INFO_TUNNEL |
9107 RTE_FLOW_RESTORE_INFO_GROUP_ID |
9108 RTE_FLOW_RESTORE_INFO_ENCAPSULATED;
9113 return rte_flow_error_set(err, EINVAL,
9114 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
9115 "failed to get restore info");
9118 #else /* HAVE_IBV_FLOW_DV_SUPPORT */
9120 mlx5_flow_tunnel_decap_set(__rte_unused struct rte_eth_dev *dev,
9121 __rte_unused struct rte_flow_tunnel *app_tunnel,
9122 __rte_unused struct rte_flow_action **actions,
9123 __rte_unused uint32_t *num_of_actions,
9124 __rte_unused struct rte_flow_error *error)
9130 mlx5_flow_tunnel_match(__rte_unused struct rte_eth_dev *dev,
9131 __rte_unused struct rte_flow_tunnel *app_tunnel,
9132 __rte_unused struct rte_flow_item **items,
9133 __rte_unused uint32_t *num_of_items,
9134 __rte_unused struct rte_flow_error *error)
9140 mlx5_flow_tunnel_item_release(__rte_unused struct rte_eth_dev *dev,
9141 __rte_unused struct rte_flow_item *pmd_items,
9142 __rte_unused uint32_t num_items,
9143 __rte_unused struct rte_flow_error *err)
9149 mlx5_flow_tunnel_action_release(__rte_unused struct rte_eth_dev *dev,
9150 __rte_unused struct rte_flow_action *pmd_action,
9151 __rte_unused uint32_t num_actions,
9152 __rte_unused struct rte_flow_error *err)
9158 mlx5_flow_tunnel_get_restore_info(__rte_unused struct rte_eth_dev *dev,
9159 __rte_unused struct rte_mbuf *m,
9160 __rte_unused struct rte_flow_restore_info *i,
9161 __rte_unused struct rte_flow_error *err)
9167 flow_tunnel_add_default_miss(__rte_unused struct rte_eth_dev *dev,
9168 __rte_unused struct rte_flow *flow,
9169 __rte_unused const struct rte_flow_attr *attr,
9170 __rte_unused const struct rte_flow_action *actions,
9171 __rte_unused uint32_t flow_idx,
9172 __rte_unused const struct mlx5_flow_tunnel *tunnel,
9173 __rte_unused struct tunnel_default_miss_ctx *ctx,
9174 __rte_unused struct rte_flow_error *error)
9179 static struct mlx5_flow_tunnel *
9180 mlx5_find_tunnel_id(__rte_unused struct rte_eth_dev *dev,
9181 __rte_unused uint32_t id)
9187 mlx5_flow_tunnel_free(__rte_unused struct rte_eth_dev *dev,
9188 __rte_unused struct mlx5_flow_tunnel *tunnel)
9193 tunnel_flow_group_to_flow_table(__rte_unused struct rte_eth_dev *dev,
9194 __rte_unused const struct mlx5_flow_tunnel *t,
9195 __rte_unused uint32_t group,
9196 __rte_unused uint32_t *table,
9197 struct rte_flow_error *error)
9199 return rte_flow_error_set(error, ENOTSUP,
9200 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
9201 "tunnel offload requires DV support");
9205 mlx5_release_tunnel_hub(__rte_unused struct mlx5_dev_ctx_shared *sh,
9206 __rte_unused uint16_t port_id)
9209 #endif /* HAVE_IBV_FLOW_DV_SUPPORT */
9212 mlx5_dbg__print_pattern(const struct rte_flow_item *item)
9215 struct rte_flow_error error;
9217 for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
9219 ret = rte_flow_conv(RTE_FLOW_CONV_OP_ITEM_NAME_PTR, &item_name,
9221 (void *)(uintptr_t)item->type, &error);
9223 printf("%s ", item_name);
9225 printf("%d\n", (int)item->type);