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,
79 [MLX5_FLOW_TYPE_HW] = &mlx5_flow_hw_drv_ops,
81 [MLX5_FLOW_TYPE_VERBS] = &mlx5_flow_verbs_drv_ops,
82 [MLX5_FLOW_TYPE_MAX] = &mlx5_flow_null_drv_ops
85 /** Helper macro to build input graph for mlx5_flow_expand_rss(). */
86 #define MLX5_FLOW_EXPAND_RSS_NEXT(...) \
91 /** Node object of input graph for mlx5_flow_expand_rss(). */
92 struct mlx5_flow_expand_node {
93 const int *const next;
95 * List of next node indexes. Index 0 is interpreted as a terminator.
97 const enum rte_flow_item_type type;
98 /**< Pattern item type of current node. */
101 * RSS types bit-field associated with this node
102 * (see RTE_ETH_RSS_* definitions).
106 * Bit-fields that define how the node is used in the expansion.
107 * (see MLX5_EXPANSION_NODE_* definitions).
111 /* Optional expand field. The expansion alg will not go deeper. */
112 #define MLX5_EXPANSION_NODE_OPTIONAL (UINT64_C(1) << 0)
114 /* The node is not added implicitly as expansion to the flow pattern.
115 * If the node type does not match the flow pattern item type, the
116 * expansion alg will go deeper to its next items.
117 * In the current implementation, the list of next nodes indexes can
118 * have up to one node with this flag set and it has to be the last
119 * node index (before the list terminator).
121 #define MLX5_EXPANSION_NODE_EXPLICIT (UINT64_C(1) << 1)
123 /** Object returned by mlx5_flow_expand_rss(). */
124 struct mlx5_flow_expand_rss {
126 /**< Number of entries @p patterns and @p priorities. */
128 struct rte_flow_item *pattern; /**< Expanded pattern array. */
129 uint32_t priority; /**< Priority offset for each expansion. */
134 mlx5_dbg__print_pattern(const struct rte_flow_item *item);
136 static const struct mlx5_flow_expand_node *
137 mlx5_flow_expand_rss_adjust_node(const struct rte_flow_item *pattern,
138 unsigned int item_idx,
139 const struct mlx5_flow_expand_node graph[],
140 const struct mlx5_flow_expand_node *node);
143 mlx5_flow_is_rss_expandable_item(const struct rte_flow_item *item)
145 switch (item->type) {
146 case RTE_FLOW_ITEM_TYPE_ETH:
147 case RTE_FLOW_ITEM_TYPE_VLAN:
148 case RTE_FLOW_ITEM_TYPE_IPV4:
149 case RTE_FLOW_ITEM_TYPE_IPV6:
150 case RTE_FLOW_ITEM_TYPE_UDP:
151 case RTE_FLOW_ITEM_TYPE_TCP:
152 case RTE_FLOW_ITEM_TYPE_VXLAN:
153 case RTE_FLOW_ITEM_TYPE_NVGRE:
154 case RTE_FLOW_ITEM_TYPE_GRE:
155 case RTE_FLOW_ITEM_TYPE_GENEVE:
156 case RTE_FLOW_ITEM_TYPE_MPLS:
157 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
158 case RTE_FLOW_ITEM_TYPE_GRE_KEY:
159 case RTE_FLOW_ITEM_TYPE_IPV6_FRAG_EXT:
160 case RTE_FLOW_ITEM_TYPE_GTP:
169 * Network Service Header (NSH) and its next protocol values
170 * are described in RFC-8393.
172 static enum rte_flow_item_type
173 mlx5_nsh_proto_to_item_type(uint8_t proto_spec, uint8_t proto_mask)
175 enum rte_flow_item_type type;
177 switch (proto_mask & proto_spec) {
178 case RTE_VXLAN_GPE_TYPE_IPV4:
179 type = RTE_FLOW_ITEM_TYPE_IPV4;
181 case RTE_VXLAN_GPE_TYPE_IPV6:
182 type = RTE_VXLAN_GPE_TYPE_IPV6;
184 case RTE_VXLAN_GPE_TYPE_ETH:
185 type = RTE_FLOW_ITEM_TYPE_ETH;
188 type = RTE_FLOW_ITEM_TYPE_END;
193 static enum rte_flow_item_type
194 mlx5_inet_proto_to_item_type(uint8_t proto_spec, uint8_t proto_mask)
196 enum rte_flow_item_type type;
198 switch (proto_mask & proto_spec) {
200 type = RTE_FLOW_ITEM_TYPE_UDP;
203 type = RTE_FLOW_ITEM_TYPE_TCP;
206 type = RTE_FLOW_ITEM_TYPE_IPV4;
209 type = RTE_FLOW_ITEM_TYPE_IPV6;
212 type = RTE_FLOW_ITEM_TYPE_END;
217 static enum rte_flow_item_type
218 mlx5_ethertype_to_item_type(rte_be16_t type_spec,
219 rte_be16_t type_mask, bool is_tunnel)
221 enum rte_flow_item_type type;
223 switch (rte_be_to_cpu_16(type_spec & type_mask)) {
224 case RTE_ETHER_TYPE_TEB:
226 RTE_FLOW_ITEM_TYPE_ETH : RTE_FLOW_ITEM_TYPE_END;
228 case RTE_ETHER_TYPE_VLAN:
230 RTE_FLOW_ITEM_TYPE_VLAN : RTE_FLOW_ITEM_TYPE_END;
232 case RTE_ETHER_TYPE_IPV4:
233 type = RTE_FLOW_ITEM_TYPE_IPV4;
235 case RTE_ETHER_TYPE_IPV6:
236 type = RTE_FLOW_ITEM_TYPE_IPV6;
239 type = RTE_FLOW_ITEM_TYPE_END;
244 static enum rte_flow_item_type
245 mlx5_flow_expand_rss_item_complete(const struct rte_flow_item *item)
247 #define MLX5_XSET_ITEM_MASK_SPEC(type, fld) \
249 const void *m = item->mask; \
250 const void *s = item->spec; \
252 ((const struct rte_flow_item_##type *)m)->fld : \
253 rte_flow_item_##type##_mask.fld; \
254 spec = ((const struct rte_flow_item_##type *)s)->fld; \
257 enum rte_flow_item_type ret;
260 if (item == NULL || item->spec == NULL)
261 return RTE_FLOW_ITEM_TYPE_VOID;
262 switch (item->type) {
263 case RTE_FLOW_ITEM_TYPE_ETH:
264 MLX5_XSET_ITEM_MASK_SPEC(eth, type);
266 return RTE_FLOW_ITEM_TYPE_VOID;
267 ret = mlx5_ethertype_to_item_type(spec, mask, false);
269 case RTE_FLOW_ITEM_TYPE_VLAN:
270 MLX5_XSET_ITEM_MASK_SPEC(vlan, inner_type);
272 return RTE_FLOW_ITEM_TYPE_VOID;
273 ret = mlx5_ethertype_to_item_type(spec, mask, false);
275 case RTE_FLOW_ITEM_TYPE_IPV4:
276 MLX5_XSET_ITEM_MASK_SPEC(ipv4, hdr.next_proto_id);
278 return RTE_FLOW_ITEM_TYPE_VOID;
279 ret = mlx5_inet_proto_to_item_type(spec, mask);
281 case RTE_FLOW_ITEM_TYPE_IPV6:
282 MLX5_XSET_ITEM_MASK_SPEC(ipv6, hdr.proto);
284 return RTE_FLOW_ITEM_TYPE_VOID;
285 ret = mlx5_inet_proto_to_item_type(spec, mask);
287 case RTE_FLOW_ITEM_TYPE_GENEVE:
288 MLX5_XSET_ITEM_MASK_SPEC(geneve, protocol);
289 ret = mlx5_ethertype_to_item_type(spec, mask, true);
291 case RTE_FLOW_ITEM_TYPE_GRE:
292 MLX5_XSET_ITEM_MASK_SPEC(gre, protocol);
293 ret = mlx5_ethertype_to_item_type(spec, mask, true);
295 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
296 MLX5_XSET_ITEM_MASK_SPEC(vxlan_gpe, protocol);
297 ret = mlx5_nsh_proto_to_item_type(spec, mask);
300 ret = RTE_FLOW_ITEM_TYPE_VOID;
304 #undef MLX5_XSET_ITEM_MASK_SPEC
308 mlx5_flow_expand_rss_skip_explicit(const struct mlx5_flow_expand_node graph[],
309 const int *next_node)
311 const struct mlx5_flow_expand_node *node = NULL;
312 const int *next = next_node;
314 while (next && *next) {
316 * Skip the nodes with the MLX5_EXPANSION_NODE_EXPLICIT
317 * flag set, because they were not found in the flow pattern.
319 node = &graph[*next];
320 if (!(node->node_flags & MLX5_EXPANSION_NODE_EXPLICIT))
327 #define MLX5_RSS_EXP_ELT_N 16
330 * Expand RSS flows into several possible flows according to the RSS hash
331 * fields requested and the driver capabilities.
334 * Buffer to store the result expansion.
336 * Buffer size in bytes. If 0, @p buf can be NULL.
340 * RSS types to expand (see RTE_ETH_RSS_* definitions).
342 * Input graph to expand @p pattern according to @p types.
343 * @param[in] graph_root_index
344 * Index of root node in @p graph, typically 0.
347 * A positive value representing the size of @p buf in bytes regardless of
348 * @p size on success, a negative errno value otherwise and rte_errno is
349 * set, the following errors are defined:
351 * -E2BIG: graph-depth @p graph is too deep.
352 * -EINVAL: @p size has not enough space for expanded pattern.
355 mlx5_flow_expand_rss(struct mlx5_flow_expand_rss *buf, size_t size,
356 const struct rte_flow_item *pattern, uint64_t types,
357 const struct mlx5_flow_expand_node graph[],
358 int graph_root_index)
360 const struct rte_flow_item *item;
361 const struct mlx5_flow_expand_node *node = &graph[graph_root_index];
362 const int *next_node;
363 const int *stack[MLX5_RSS_EXP_ELT_N];
365 struct rte_flow_item flow_items[MLX5_RSS_EXP_ELT_N];
366 unsigned int i, item_idx, last_expand_item_idx = 0;
368 size_t user_pattern_size = 0;
370 const struct mlx5_flow_expand_node *next = NULL;
371 struct rte_flow_item missed_item;
374 const struct rte_flow_item *last_expand_item = NULL;
376 memset(&missed_item, 0, sizeof(missed_item));
377 lsize = offsetof(struct mlx5_flow_expand_rss, entry) +
378 MLX5_RSS_EXP_ELT_N * sizeof(buf->entry[0]);
381 buf->entry[0].priority = 0;
382 buf->entry[0].pattern = (void *)&buf->entry[MLX5_RSS_EXP_ELT_N];
384 addr = buf->entry[0].pattern;
385 for (item = pattern, item_idx = 0;
386 item->type != RTE_FLOW_ITEM_TYPE_END;
387 item++, item_idx++) {
388 if (!mlx5_flow_is_rss_expandable_item(item)) {
389 user_pattern_size += sizeof(*item);
392 last_expand_item = item;
393 last_expand_item_idx = item_idx;
395 while (node->next && node->next[i]) {
396 next = &graph[node->next[i]];
397 if (next->type == item->type)
399 if (next->node_flags & MLX5_EXPANSION_NODE_EXPLICIT) {
408 user_pattern_size += sizeof(*item);
410 user_pattern_size += sizeof(*item); /* Handle END item. */
411 lsize += user_pattern_size;
414 /* Copy the user pattern in the first entry of the buffer. */
415 rte_memcpy(addr, pattern, user_pattern_size);
416 addr = (void *)(((uintptr_t)addr) + user_pattern_size);
418 /* Start expanding. */
419 memset(flow_items, 0, sizeof(flow_items));
420 user_pattern_size -= sizeof(*item);
422 * Check if the last valid item has spec set, need complete pattern,
423 * and the pattern can be used for expansion.
425 missed_item.type = mlx5_flow_expand_rss_item_complete(last_expand_item);
426 if (missed_item.type == RTE_FLOW_ITEM_TYPE_END) {
427 /* Item type END indicates expansion is not required. */
430 if (missed_item.type != RTE_FLOW_ITEM_TYPE_VOID) {
434 while (node->next && node->next[i]) {
435 next = &graph[node->next[i]];
436 if (next->type == missed_item.type) {
437 flow_items[0].type = missed_item.type;
438 flow_items[1].type = RTE_FLOW_ITEM_TYPE_END;
441 if (next->node_flags & MLX5_EXPANSION_NODE_EXPLICIT) {
450 if (next && missed) {
451 elt = 2; /* missed item + item end. */
453 lsize += elt * sizeof(*item) + user_pattern_size;
456 if (node->rss_types & types) {
457 buf->entry[buf->entries].priority = 1;
458 buf->entry[buf->entries].pattern = addr;
460 rte_memcpy(addr, buf->entry[0].pattern,
462 addr = (void *)(((uintptr_t)addr) + user_pattern_size);
463 rte_memcpy(addr, flow_items, elt * sizeof(*item));
464 addr = (void *)(((uintptr_t)addr) +
465 elt * sizeof(*item));
467 } else if (last_expand_item != NULL) {
468 node = mlx5_flow_expand_rss_adjust_node(pattern,
469 last_expand_item_idx, graph, node);
471 memset(flow_items, 0, sizeof(flow_items));
472 next_node = mlx5_flow_expand_rss_skip_explicit(graph,
474 stack[stack_pos] = next_node;
475 node = next_node ? &graph[*next_node] : NULL;
477 flow_items[stack_pos].type = node->type;
478 if (node->rss_types & types) {
481 * compute the number of items to copy from the
482 * expansion and copy it.
483 * When the stack_pos is 0, there are 1 element in it,
484 * plus the addition END item.
487 flow_items[stack_pos + 1].type = RTE_FLOW_ITEM_TYPE_END;
488 lsize += elt * sizeof(*item) + user_pattern_size;
491 n = elt * sizeof(*item);
492 buf->entry[buf->entries].priority =
493 stack_pos + 1 + missed;
494 buf->entry[buf->entries].pattern = addr;
496 rte_memcpy(addr, buf->entry[0].pattern,
498 addr = (void *)(((uintptr_t)addr) +
500 rte_memcpy(addr, &missed_item,
501 missed * sizeof(*item));
502 addr = (void *)(((uintptr_t)addr) +
503 missed * sizeof(*item));
504 rte_memcpy(addr, flow_items, n);
505 addr = (void *)(((uintptr_t)addr) + n);
508 if (!(node->node_flags & MLX5_EXPANSION_NODE_OPTIONAL) &&
510 next_node = mlx5_flow_expand_rss_skip_explicit(graph,
512 if (stack_pos++ == MLX5_RSS_EXP_ELT_N) {
516 stack[stack_pos] = next_node;
517 } else if (*(next_node + 1)) {
518 /* Follow up with the next possibility. */
519 next_node = mlx5_flow_expand_rss_skip_explicit(graph,
521 } else if (!stack_pos) {
523 * Completing the traverse over the different paths.
524 * The next_node is advanced to the terminator.
528 /* Move to the next path. */
530 next_node = stack[--stack_pos];
535 next_node = mlx5_flow_expand_rss_skip_explicit(graph,
537 stack[stack_pos] = next_node;
539 node = next_node && *next_node ? &graph[*next_node] : NULL;
544 enum mlx5_expansion {
546 MLX5_EXPANSION_ROOT_OUTER,
547 MLX5_EXPANSION_OUTER_ETH,
548 MLX5_EXPANSION_OUTER_VLAN,
549 MLX5_EXPANSION_OUTER_IPV4,
550 MLX5_EXPANSION_OUTER_IPV4_UDP,
551 MLX5_EXPANSION_OUTER_IPV4_TCP,
552 MLX5_EXPANSION_OUTER_IPV6,
553 MLX5_EXPANSION_OUTER_IPV6_UDP,
554 MLX5_EXPANSION_OUTER_IPV6_TCP,
555 MLX5_EXPANSION_VXLAN,
556 MLX5_EXPANSION_STD_VXLAN,
557 MLX5_EXPANSION_L3_VXLAN,
558 MLX5_EXPANSION_VXLAN_GPE,
560 MLX5_EXPANSION_NVGRE,
561 MLX5_EXPANSION_GRE_KEY,
566 MLX5_EXPANSION_IPV4_UDP,
567 MLX5_EXPANSION_IPV4_TCP,
569 MLX5_EXPANSION_IPV6_UDP,
570 MLX5_EXPANSION_IPV6_TCP,
571 MLX5_EXPANSION_IPV6_FRAG_EXT,
573 MLX5_EXPANSION_GENEVE,
576 /** Supported expansion of items. */
577 static const struct mlx5_flow_expand_node mlx5_support_expansion[] = {
578 [MLX5_EXPANSION_ROOT] = {
579 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
581 MLX5_EXPANSION_IPV6),
582 .type = RTE_FLOW_ITEM_TYPE_END,
584 [MLX5_EXPANSION_ROOT_OUTER] = {
585 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_ETH,
586 MLX5_EXPANSION_OUTER_IPV4,
587 MLX5_EXPANSION_OUTER_IPV6),
588 .type = RTE_FLOW_ITEM_TYPE_END,
590 [MLX5_EXPANSION_OUTER_ETH] = {
591 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_VLAN),
592 .type = RTE_FLOW_ITEM_TYPE_ETH,
595 [MLX5_EXPANSION_OUTER_VLAN] = {
596 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_IPV4,
597 MLX5_EXPANSION_OUTER_IPV6),
598 .type = RTE_FLOW_ITEM_TYPE_VLAN,
599 .node_flags = MLX5_EXPANSION_NODE_EXPLICIT,
601 [MLX5_EXPANSION_OUTER_IPV4] = {
602 .next = MLX5_FLOW_EXPAND_RSS_NEXT
603 (MLX5_EXPANSION_OUTER_IPV4_UDP,
604 MLX5_EXPANSION_OUTER_IPV4_TCP,
606 MLX5_EXPANSION_NVGRE,
608 MLX5_EXPANSION_IPV6),
609 .type = RTE_FLOW_ITEM_TYPE_IPV4,
610 .rss_types = RTE_ETH_RSS_IPV4 | RTE_ETH_RSS_FRAG_IPV4 |
611 RTE_ETH_RSS_NONFRAG_IPV4_OTHER,
613 [MLX5_EXPANSION_OUTER_IPV4_UDP] = {
614 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VXLAN,
615 MLX5_EXPANSION_VXLAN_GPE,
617 MLX5_EXPANSION_GENEVE,
619 .type = RTE_FLOW_ITEM_TYPE_UDP,
620 .rss_types = RTE_ETH_RSS_NONFRAG_IPV4_UDP,
622 [MLX5_EXPANSION_OUTER_IPV4_TCP] = {
623 .type = RTE_FLOW_ITEM_TYPE_TCP,
624 .rss_types = RTE_ETH_RSS_NONFRAG_IPV4_TCP,
626 [MLX5_EXPANSION_OUTER_IPV6] = {
627 .next = MLX5_FLOW_EXPAND_RSS_NEXT
628 (MLX5_EXPANSION_OUTER_IPV6_UDP,
629 MLX5_EXPANSION_OUTER_IPV6_TCP,
633 MLX5_EXPANSION_NVGRE),
634 .type = RTE_FLOW_ITEM_TYPE_IPV6,
635 .rss_types = RTE_ETH_RSS_IPV6 | RTE_ETH_RSS_FRAG_IPV6 |
636 RTE_ETH_RSS_NONFRAG_IPV6_OTHER,
638 [MLX5_EXPANSION_OUTER_IPV6_UDP] = {
639 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VXLAN,
640 MLX5_EXPANSION_VXLAN_GPE,
642 MLX5_EXPANSION_GENEVE,
644 .type = RTE_FLOW_ITEM_TYPE_UDP,
645 .rss_types = RTE_ETH_RSS_NONFRAG_IPV6_UDP,
647 [MLX5_EXPANSION_OUTER_IPV6_TCP] = {
648 .type = RTE_FLOW_ITEM_TYPE_TCP,
649 .rss_types = RTE_ETH_RSS_NONFRAG_IPV6_TCP,
651 [MLX5_EXPANSION_VXLAN] = {
652 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
654 MLX5_EXPANSION_IPV6),
655 .type = RTE_FLOW_ITEM_TYPE_VXLAN,
657 [MLX5_EXPANSION_STD_VXLAN] = {
658 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH),
659 .type = RTE_FLOW_ITEM_TYPE_VXLAN,
661 [MLX5_EXPANSION_L3_VXLAN] = {
662 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
663 MLX5_EXPANSION_IPV6),
664 .type = RTE_FLOW_ITEM_TYPE_VXLAN,
666 [MLX5_EXPANSION_VXLAN_GPE] = {
667 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
669 MLX5_EXPANSION_IPV6),
670 .type = RTE_FLOW_ITEM_TYPE_VXLAN_GPE,
672 [MLX5_EXPANSION_GRE] = {
673 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
676 MLX5_EXPANSION_GRE_KEY,
677 MLX5_EXPANSION_MPLS),
678 .type = RTE_FLOW_ITEM_TYPE_GRE,
680 [MLX5_EXPANSION_GRE_KEY] = {
681 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
683 MLX5_EXPANSION_MPLS),
684 .type = RTE_FLOW_ITEM_TYPE_GRE_KEY,
685 .node_flags = MLX5_EXPANSION_NODE_OPTIONAL,
687 [MLX5_EXPANSION_NVGRE] = {
688 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH),
689 .type = RTE_FLOW_ITEM_TYPE_NVGRE,
691 [MLX5_EXPANSION_MPLS] = {
692 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
695 .type = RTE_FLOW_ITEM_TYPE_MPLS,
696 .node_flags = MLX5_EXPANSION_NODE_OPTIONAL,
698 [MLX5_EXPANSION_ETH] = {
699 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VLAN),
700 .type = RTE_FLOW_ITEM_TYPE_ETH,
702 [MLX5_EXPANSION_VLAN] = {
703 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
704 MLX5_EXPANSION_IPV6),
705 .type = RTE_FLOW_ITEM_TYPE_VLAN,
706 .node_flags = MLX5_EXPANSION_NODE_EXPLICIT,
708 [MLX5_EXPANSION_IPV4] = {
709 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4_UDP,
710 MLX5_EXPANSION_IPV4_TCP),
711 .type = RTE_FLOW_ITEM_TYPE_IPV4,
712 .rss_types = RTE_ETH_RSS_IPV4 | RTE_ETH_RSS_FRAG_IPV4 |
713 RTE_ETH_RSS_NONFRAG_IPV4_OTHER,
715 [MLX5_EXPANSION_IPV4_UDP] = {
716 .type = RTE_FLOW_ITEM_TYPE_UDP,
717 .rss_types = RTE_ETH_RSS_NONFRAG_IPV4_UDP,
719 [MLX5_EXPANSION_IPV4_TCP] = {
720 .type = RTE_FLOW_ITEM_TYPE_TCP,
721 .rss_types = RTE_ETH_RSS_NONFRAG_IPV4_TCP,
723 [MLX5_EXPANSION_IPV6] = {
724 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV6_UDP,
725 MLX5_EXPANSION_IPV6_TCP,
726 MLX5_EXPANSION_IPV6_FRAG_EXT),
727 .type = RTE_FLOW_ITEM_TYPE_IPV6,
728 .rss_types = RTE_ETH_RSS_IPV6 | RTE_ETH_RSS_FRAG_IPV6 |
729 RTE_ETH_RSS_NONFRAG_IPV6_OTHER,
731 [MLX5_EXPANSION_IPV6_UDP] = {
732 .type = RTE_FLOW_ITEM_TYPE_UDP,
733 .rss_types = RTE_ETH_RSS_NONFRAG_IPV6_UDP,
735 [MLX5_EXPANSION_IPV6_TCP] = {
736 .type = RTE_FLOW_ITEM_TYPE_TCP,
737 .rss_types = RTE_ETH_RSS_NONFRAG_IPV6_TCP,
739 [MLX5_EXPANSION_IPV6_FRAG_EXT] = {
740 .type = RTE_FLOW_ITEM_TYPE_IPV6_FRAG_EXT,
742 [MLX5_EXPANSION_GTP] = {
743 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
744 MLX5_EXPANSION_IPV6),
745 .type = RTE_FLOW_ITEM_TYPE_GTP,
747 [MLX5_EXPANSION_GENEVE] = {
748 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
750 MLX5_EXPANSION_IPV6),
751 .type = RTE_FLOW_ITEM_TYPE_GENEVE,
755 static struct rte_flow_action_handle *
756 mlx5_action_handle_create(struct rte_eth_dev *dev,
757 const struct rte_flow_indir_action_conf *conf,
758 const struct rte_flow_action *action,
759 struct rte_flow_error *error);
760 static int mlx5_action_handle_destroy
761 (struct rte_eth_dev *dev,
762 struct rte_flow_action_handle *handle,
763 struct rte_flow_error *error);
764 static int mlx5_action_handle_update
765 (struct rte_eth_dev *dev,
766 struct rte_flow_action_handle *handle,
768 struct rte_flow_error *error);
769 static int mlx5_action_handle_query
770 (struct rte_eth_dev *dev,
771 const struct rte_flow_action_handle *handle,
773 struct rte_flow_error *error);
775 mlx5_flow_tunnel_decap_set(struct rte_eth_dev *dev,
776 struct rte_flow_tunnel *app_tunnel,
777 struct rte_flow_action **actions,
778 uint32_t *num_of_actions,
779 struct rte_flow_error *error);
781 mlx5_flow_tunnel_match(struct rte_eth_dev *dev,
782 struct rte_flow_tunnel *app_tunnel,
783 struct rte_flow_item **items,
784 uint32_t *num_of_items,
785 struct rte_flow_error *error);
787 mlx5_flow_tunnel_item_release(struct rte_eth_dev *dev,
788 struct rte_flow_item *pmd_items,
789 uint32_t num_items, struct rte_flow_error *err);
791 mlx5_flow_tunnel_action_release(struct rte_eth_dev *dev,
792 struct rte_flow_action *pmd_actions,
793 uint32_t num_actions,
794 struct rte_flow_error *err);
796 mlx5_flow_tunnel_get_restore_info(struct rte_eth_dev *dev,
798 struct rte_flow_restore_info *info,
799 struct rte_flow_error *err);
800 static struct rte_flow_item_flex_handle *
801 mlx5_flow_flex_item_create(struct rte_eth_dev *dev,
802 const struct rte_flow_item_flex_conf *conf,
803 struct rte_flow_error *error);
805 mlx5_flow_flex_item_release(struct rte_eth_dev *dev,
806 const struct rte_flow_item_flex_handle *handle,
807 struct rte_flow_error *error);
809 mlx5_flow_info_get(struct rte_eth_dev *dev,
810 struct rte_flow_port_info *port_info,
811 struct rte_flow_queue_info *queue_info,
812 struct rte_flow_error *error);
814 mlx5_flow_port_configure(struct rte_eth_dev *dev,
815 const struct rte_flow_port_attr *port_attr,
817 const struct rte_flow_queue_attr *queue_attr[],
818 struct rte_flow_error *err);
820 static struct rte_flow_pattern_template *
821 mlx5_flow_pattern_template_create(struct rte_eth_dev *dev,
822 const struct rte_flow_pattern_template_attr *attr,
823 const struct rte_flow_item items[],
824 struct rte_flow_error *error);
827 mlx5_flow_pattern_template_destroy(struct rte_eth_dev *dev,
828 struct rte_flow_pattern_template *template,
829 struct rte_flow_error *error);
830 static struct rte_flow_actions_template *
831 mlx5_flow_actions_template_create(struct rte_eth_dev *dev,
832 const struct rte_flow_actions_template_attr *attr,
833 const struct rte_flow_action actions[],
834 const struct rte_flow_action masks[],
835 struct rte_flow_error *error);
837 mlx5_flow_actions_template_destroy(struct rte_eth_dev *dev,
838 struct rte_flow_actions_template *template,
839 struct rte_flow_error *error);
841 static const struct rte_flow_ops mlx5_flow_ops = {
842 .validate = mlx5_flow_validate,
843 .create = mlx5_flow_create,
844 .destroy = mlx5_flow_destroy,
845 .flush = mlx5_flow_flush,
846 .isolate = mlx5_flow_isolate,
847 .query = mlx5_flow_query,
848 .dev_dump = mlx5_flow_dev_dump,
849 .get_aged_flows = mlx5_flow_get_aged_flows,
850 .action_handle_create = mlx5_action_handle_create,
851 .action_handle_destroy = mlx5_action_handle_destroy,
852 .action_handle_update = mlx5_action_handle_update,
853 .action_handle_query = mlx5_action_handle_query,
854 .tunnel_decap_set = mlx5_flow_tunnel_decap_set,
855 .tunnel_match = mlx5_flow_tunnel_match,
856 .tunnel_action_decap_release = mlx5_flow_tunnel_action_release,
857 .tunnel_item_release = mlx5_flow_tunnel_item_release,
858 .get_restore_info = mlx5_flow_tunnel_get_restore_info,
859 .flex_item_create = mlx5_flow_flex_item_create,
860 .flex_item_release = mlx5_flow_flex_item_release,
861 .info_get = mlx5_flow_info_get,
862 .configure = mlx5_flow_port_configure,
863 .pattern_template_create = mlx5_flow_pattern_template_create,
864 .pattern_template_destroy = mlx5_flow_pattern_template_destroy,
865 .actions_template_create = mlx5_flow_actions_template_create,
866 .actions_template_destroy = mlx5_flow_actions_template_destroy,
869 /* Tunnel information. */
870 struct mlx5_flow_tunnel_info {
871 uint64_t tunnel; /**< Tunnel bit (see MLX5_FLOW_*). */
872 uint32_t ptype; /**< Tunnel Ptype (see RTE_PTYPE_*). */
875 static struct mlx5_flow_tunnel_info tunnels_info[] = {
877 .tunnel = MLX5_FLOW_LAYER_VXLAN,
878 .ptype = RTE_PTYPE_TUNNEL_VXLAN | RTE_PTYPE_L4_UDP,
881 .tunnel = MLX5_FLOW_LAYER_GENEVE,
882 .ptype = RTE_PTYPE_TUNNEL_GENEVE | RTE_PTYPE_L4_UDP,
885 .tunnel = MLX5_FLOW_LAYER_VXLAN_GPE,
886 .ptype = RTE_PTYPE_TUNNEL_VXLAN_GPE | RTE_PTYPE_L4_UDP,
889 .tunnel = MLX5_FLOW_LAYER_GRE,
890 .ptype = RTE_PTYPE_TUNNEL_GRE,
893 .tunnel = MLX5_FLOW_LAYER_MPLS | MLX5_FLOW_LAYER_OUTER_L4_UDP,
894 .ptype = RTE_PTYPE_TUNNEL_MPLS_IN_UDP | RTE_PTYPE_L4_UDP,
897 .tunnel = MLX5_FLOW_LAYER_MPLS,
898 .ptype = RTE_PTYPE_TUNNEL_MPLS_IN_GRE,
901 .tunnel = MLX5_FLOW_LAYER_NVGRE,
902 .ptype = RTE_PTYPE_TUNNEL_NVGRE,
905 .tunnel = MLX5_FLOW_LAYER_IPIP,
906 .ptype = RTE_PTYPE_TUNNEL_IP,
909 .tunnel = MLX5_FLOW_LAYER_IPV6_ENCAP,
910 .ptype = RTE_PTYPE_TUNNEL_IP,
913 .tunnel = MLX5_FLOW_LAYER_GTP,
914 .ptype = RTE_PTYPE_TUNNEL_GTPU,
921 * Translate tag ID to register.
924 * Pointer to the Ethernet device structure.
926 * The feature that request the register.
928 * The request register ID.
930 * Error description in case of any.
933 * The request register on success, a negative errno
934 * value otherwise and rte_errno is set.
937 mlx5_flow_get_reg_id(struct rte_eth_dev *dev,
938 enum mlx5_feature_name feature,
940 struct rte_flow_error *error)
942 struct mlx5_priv *priv = dev->data->dev_private;
943 struct mlx5_sh_config *config = &priv->sh->config;
944 enum modify_reg start_reg;
945 bool skip_mtr_reg = false;
948 case MLX5_HAIRPIN_RX:
950 case MLX5_HAIRPIN_TX:
952 case MLX5_METADATA_RX:
953 switch (config->dv_xmeta_en) {
954 case MLX5_XMETA_MODE_LEGACY:
956 case MLX5_XMETA_MODE_META16:
958 case MLX5_XMETA_MODE_META32:
962 case MLX5_METADATA_TX:
964 case MLX5_METADATA_FDB:
965 switch (config->dv_xmeta_en) {
966 case MLX5_XMETA_MODE_LEGACY:
968 case MLX5_XMETA_MODE_META16:
970 case MLX5_XMETA_MODE_META32:
975 switch (config->dv_xmeta_en) {
976 case MLX5_XMETA_MODE_LEGACY:
978 case MLX5_XMETA_MODE_META16:
980 case MLX5_XMETA_MODE_META32:
986 * If meter color and meter id share one register, flow match
987 * should use the meter color register for match.
989 if (priv->mtr_reg_share)
990 return priv->mtr_color_reg;
992 return priv->mtr_color_reg != REG_C_2 ? REG_C_2 :
995 case MLX5_ASO_FLOW_HIT:
996 case MLX5_ASO_CONNTRACK:
998 /* All features use the same REG_C. */
999 MLX5_ASSERT(priv->mtr_color_reg != REG_NON);
1000 return priv->mtr_color_reg;
1001 case MLX5_COPY_MARK:
1003 * Metadata COPY_MARK register using is in meter suffix sub
1004 * flow while with meter. It's safe to share the same register.
1006 return priv->mtr_color_reg != REG_C_2 ? REG_C_2 : REG_C_3;
1009 * If meter is enable, it will engage the register for color
1010 * match and flow match. If meter color match is not using the
1011 * REG_C_2, need to skip the REG_C_x be used by meter color
1013 * If meter is disable, free to use all available registers.
1015 start_reg = priv->mtr_color_reg != REG_C_2 ? REG_C_2 :
1016 (priv->mtr_reg_share ? REG_C_3 : REG_C_4);
1017 skip_mtr_reg = !!(priv->mtr_en && start_reg == REG_C_2);
1018 if (id > (uint32_t)(REG_C_7 - start_reg))
1019 return rte_flow_error_set(error, EINVAL,
1020 RTE_FLOW_ERROR_TYPE_ITEM,
1021 NULL, "invalid tag id");
1022 if (priv->sh->flow_mreg_c[id + start_reg - REG_C_0] == REG_NON)
1023 return rte_flow_error_set(error, ENOTSUP,
1024 RTE_FLOW_ERROR_TYPE_ITEM,
1025 NULL, "unsupported tag id");
1027 * This case means meter is using the REG_C_x great than 2.
1028 * Take care not to conflict with meter color REG_C_x.
1029 * If the available index REG_C_y >= REG_C_x, skip the
1032 if (skip_mtr_reg && priv->sh->flow_mreg_c
1033 [id + start_reg - REG_C_0] >= priv->mtr_color_reg) {
1034 if (id >= (uint32_t)(REG_C_7 - start_reg))
1035 return rte_flow_error_set(error, EINVAL,
1036 RTE_FLOW_ERROR_TYPE_ITEM,
1037 NULL, "invalid tag id");
1038 if (priv->sh->flow_mreg_c
1039 [id + 1 + start_reg - REG_C_0] != REG_NON)
1040 return priv->sh->flow_mreg_c
1041 [id + 1 + start_reg - REG_C_0];
1042 return rte_flow_error_set(error, ENOTSUP,
1043 RTE_FLOW_ERROR_TYPE_ITEM,
1044 NULL, "unsupported tag id");
1046 return priv->sh->flow_mreg_c[id + start_reg - REG_C_0];
1049 return rte_flow_error_set(error, EINVAL,
1050 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1051 NULL, "invalid feature name");
1055 * Check extensive flow metadata register support.
1058 * Pointer to rte_eth_dev structure.
1061 * True if device supports extensive flow metadata register, otherwise false.
1064 mlx5_flow_ext_mreg_supported(struct rte_eth_dev *dev)
1066 struct mlx5_priv *priv = dev->data->dev_private;
1069 * Having available reg_c can be regarded inclusively as supporting
1070 * extensive flow metadata register, which could mean,
1071 * - metadata register copy action by modify header.
1072 * - 16 modify header actions is supported.
1073 * - reg_c's are preserved across different domain (FDB and NIC) on
1074 * packet loopback by flow lookup miss.
1076 return priv->sh->flow_mreg_c[2] != REG_NON;
1080 * Get the lowest priority.
1083 * Pointer to the Ethernet device structure.
1084 * @param[in] attributes
1085 * Pointer to device flow rule attributes.
1088 * The value of lowest priority of flow.
1091 mlx5_get_lowest_priority(struct rte_eth_dev *dev,
1092 const struct rte_flow_attr *attr)
1094 struct mlx5_priv *priv = dev->data->dev_private;
1096 if (!attr->group && !attr->transfer)
1097 return priv->sh->flow_max_priority - 2;
1098 return MLX5_NON_ROOT_FLOW_MAX_PRIO - 1;
1102 * Calculate matcher priority of the flow.
1105 * Pointer to the Ethernet device structure.
1107 * Pointer to device flow rule attributes.
1108 * @param[in] subpriority
1109 * The priority based on the items.
1110 * @param[in] external
1111 * Flow is user flow.
1113 * The matcher priority of the flow.
1116 mlx5_get_matcher_priority(struct rte_eth_dev *dev,
1117 const struct rte_flow_attr *attr,
1118 uint32_t subpriority, bool external)
1120 uint16_t priority = (uint16_t)attr->priority;
1121 struct mlx5_priv *priv = dev->data->dev_private;
1123 if (!attr->group && !attr->transfer) {
1124 if (attr->priority == MLX5_FLOW_LOWEST_PRIO_INDICATOR)
1125 priority = priv->sh->flow_max_priority - 1;
1126 return mlx5_os_flow_adjust_priority(dev, priority, subpriority);
1127 } else if (!external && attr->transfer && attr->group == 0 &&
1128 attr->priority == MLX5_FLOW_LOWEST_PRIO_INDICATOR) {
1129 return (priv->sh->flow_max_priority - 1) * 3;
1131 if (attr->priority == MLX5_FLOW_LOWEST_PRIO_INDICATOR)
1132 priority = MLX5_NON_ROOT_FLOW_MAX_PRIO;
1133 return priority * 3 + subpriority;
1137 * Verify the @p item specifications (spec, last, mask) are compatible with the
1141 * Item specification.
1143 * @p item->mask or flow default bit-masks.
1144 * @param[in] nic_mask
1145 * Bit-masks covering supported fields by the NIC to compare with user mask.
1147 * Bit-masks size in bytes.
1148 * @param[in] range_accepted
1149 * True if range of values is accepted for specific fields, false otherwise.
1151 * Pointer to error structure.
1154 * 0 on success, a negative errno value otherwise and rte_errno is set.
1157 mlx5_flow_item_acceptable(const struct rte_flow_item *item,
1158 const uint8_t *mask,
1159 const uint8_t *nic_mask,
1161 bool range_accepted,
1162 struct rte_flow_error *error)
1166 MLX5_ASSERT(nic_mask);
1167 for (i = 0; i < size; ++i)
1168 if ((nic_mask[i] | mask[i]) != nic_mask[i])
1169 return rte_flow_error_set(error, ENOTSUP,
1170 RTE_FLOW_ERROR_TYPE_ITEM,
1172 "mask enables non supported"
1174 if (!item->spec && (item->mask || item->last))
1175 return rte_flow_error_set(error, EINVAL,
1176 RTE_FLOW_ERROR_TYPE_ITEM, item,
1177 "mask/last without a spec is not"
1179 if (item->spec && item->last && !range_accepted) {
1185 for (i = 0; i < size; ++i) {
1186 spec[i] = ((const uint8_t *)item->spec)[i] & mask[i];
1187 last[i] = ((const uint8_t *)item->last)[i] & mask[i];
1189 ret = memcmp(spec, last, size);
1191 return rte_flow_error_set(error, EINVAL,
1192 RTE_FLOW_ERROR_TYPE_ITEM,
1194 "range is not valid");
1200 * Adjust the hash fields according to the @p flow information.
1202 * @param[in] dev_flow.
1203 * Pointer to the mlx5_flow.
1205 * 1 when the hash field is for a tunnel item.
1206 * @param[in] layer_types
1207 * RTE_ETH_RSS_* types.
1208 * @param[in] hash_fields
1212 * The hash fields that should be used.
1215 mlx5_flow_hashfields_adjust(struct mlx5_flow_rss_desc *rss_desc,
1216 int tunnel __rte_unused, uint64_t layer_types,
1217 uint64_t hash_fields)
1219 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
1220 int rss_request_inner = rss_desc->level >= 2;
1222 /* Check RSS hash level for tunnel. */
1223 if (tunnel && rss_request_inner)
1224 hash_fields |= IBV_RX_HASH_INNER;
1225 else if (tunnel || rss_request_inner)
1228 /* Check if requested layer matches RSS hash fields. */
1229 if (!(rss_desc->types & layer_types))
1235 * Lookup and set the ptype in the data Rx part. A single Ptype can be used,
1236 * if several tunnel rules are used on this queue, the tunnel ptype will be
1240 * Rx queue to update.
1243 flow_rxq_tunnel_ptype_update(struct mlx5_rxq_ctrl *rxq_ctrl)
1246 uint32_t tunnel_ptype = 0;
1248 /* Look up for the ptype to use. */
1249 for (i = 0; i != MLX5_FLOW_TUNNEL; ++i) {
1250 if (!rxq_ctrl->flow_tunnels_n[i])
1252 if (!tunnel_ptype) {
1253 tunnel_ptype = tunnels_info[i].ptype;
1259 rxq_ctrl->rxq.tunnel = tunnel_ptype;
1263 * Set the Rx queue flags (Mark/Flag and Tunnel Ptypes) according to the device
1267 * Pointer to the Ethernet device structure.
1268 * @param[in] dev_handle
1269 * Pointer to device flow handle structure.
1272 flow_drv_rxq_flags_set(struct rte_eth_dev *dev,
1273 struct mlx5_flow_handle *dev_handle)
1275 struct mlx5_priv *priv = dev->data->dev_private;
1276 const int tunnel = !!(dev_handle->layers & MLX5_FLOW_LAYER_TUNNEL);
1277 struct mlx5_ind_table_obj *ind_tbl = NULL;
1280 if (dev_handle->fate_action == MLX5_FLOW_FATE_QUEUE) {
1281 struct mlx5_hrxq *hrxq;
1283 hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
1284 dev_handle->rix_hrxq);
1286 ind_tbl = hrxq->ind_table;
1287 } else if (dev_handle->fate_action == MLX5_FLOW_FATE_SHARED_RSS) {
1288 struct mlx5_shared_action_rss *shared_rss;
1290 shared_rss = mlx5_ipool_get
1291 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
1292 dev_handle->rix_srss);
1294 ind_tbl = shared_rss->ind_tbl;
1298 for (i = 0; i != ind_tbl->queues_n; ++i) {
1299 int idx = ind_tbl->queues[i];
1300 struct mlx5_rxq_ctrl *rxq_ctrl = mlx5_rxq_ctrl_get(dev, idx);
1302 MLX5_ASSERT(rxq_ctrl != NULL);
1303 if (rxq_ctrl == NULL)
1306 * To support metadata register copy on Tx loopback,
1307 * this must be always enabled (metadata may arive
1308 * from other port - not from local flows only.
1313 /* Increase the counter matching the flow. */
1314 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j) {
1315 if ((tunnels_info[j].tunnel &
1316 dev_handle->layers) ==
1317 tunnels_info[j].tunnel) {
1318 rxq_ctrl->flow_tunnels_n[j]++;
1322 flow_rxq_tunnel_ptype_update(rxq_ctrl);
1328 flow_rxq_mark_flag_set(struct rte_eth_dev *dev)
1330 struct mlx5_priv *priv = dev->data->dev_private;
1331 struct mlx5_rxq_ctrl *rxq_ctrl;
1333 if (priv->mark_enabled)
1335 LIST_FOREACH(rxq_ctrl, &priv->rxqsctrl, next) {
1336 rxq_ctrl->rxq.mark = 1;
1338 priv->mark_enabled = 1;
1342 * Set the Rx queue flags (Mark/Flag and Tunnel Ptypes) for a flow
1345 * Pointer to the Ethernet device structure.
1347 * Pointer to flow structure.
1350 flow_rxq_flags_set(struct rte_eth_dev *dev, struct rte_flow *flow)
1352 struct mlx5_priv *priv = dev->data->dev_private;
1353 uint32_t handle_idx;
1354 struct mlx5_flow_handle *dev_handle;
1355 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
1359 flow_rxq_mark_flag_set(dev);
1360 SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
1361 handle_idx, dev_handle, next)
1362 flow_drv_rxq_flags_set(dev, dev_handle);
1366 * Clear the Rx queue flags (Mark/Flag and Tunnel Ptype) associated with the
1367 * device flow if no other flow uses it with the same kind of request.
1370 * Pointer to Ethernet device.
1371 * @param[in] dev_handle
1372 * Pointer to the device flow handle structure.
1375 flow_drv_rxq_flags_trim(struct rte_eth_dev *dev,
1376 struct mlx5_flow_handle *dev_handle)
1378 struct mlx5_priv *priv = dev->data->dev_private;
1379 const int tunnel = !!(dev_handle->layers & MLX5_FLOW_LAYER_TUNNEL);
1380 struct mlx5_ind_table_obj *ind_tbl = NULL;
1383 if (dev_handle->fate_action == MLX5_FLOW_FATE_QUEUE) {
1384 struct mlx5_hrxq *hrxq;
1386 hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
1387 dev_handle->rix_hrxq);
1389 ind_tbl = hrxq->ind_table;
1390 } else if (dev_handle->fate_action == MLX5_FLOW_FATE_SHARED_RSS) {
1391 struct mlx5_shared_action_rss *shared_rss;
1393 shared_rss = mlx5_ipool_get
1394 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
1395 dev_handle->rix_srss);
1397 ind_tbl = shared_rss->ind_tbl;
1401 MLX5_ASSERT(dev->data->dev_started);
1402 for (i = 0; i != ind_tbl->queues_n; ++i) {
1403 int idx = ind_tbl->queues[i];
1404 struct mlx5_rxq_ctrl *rxq_ctrl = mlx5_rxq_ctrl_get(dev, idx);
1406 MLX5_ASSERT(rxq_ctrl != NULL);
1407 if (rxq_ctrl == NULL)
1412 /* Decrease the counter matching the flow. */
1413 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j) {
1414 if ((tunnels_info[j].tunnel &
1415 dev_handle->layers) ==
1416 tunnels_info[j].tunnel) {
1417 rxq_ctrl->flow_tunnels_n[j]--;
1421 flow_rxq_tunnel_ptype_update(rxq_ctrl);
1427 * Clear the Rx queue flags (Mark/Flag and Tunnel Ptype) associated with the
1428 * @p flow if no other flow uses it with the same kind of request.
1431 * Pointer to Ethernet device.
1433 * Pointer to the flow.
1436 flow_rxq_flags_trim(struct rte_eth_dev *dev, struct rte_flow *flow)
1438 struct mlx5_priv *priv = dev->data->dev_private;
1439 uint32_t handle_idx;
1440 struct mlx5_flow_handle *dev_handle;
1442 SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
1443 handle_idx, dev_handle, next)
1444 flow_drv_rxq_flags_trim(dev, dev_handle);
1448 * Clear the Mark/Flag and Tunnel ptype information in all Rx queues.
1451 * Pointer to Ethernet device.
1454 flow_rxq_flags_clear(struct rte_eth_dev *dev)
1456 struct mlx5_priv *priv = dev->data->dev_private;
1459 for (i = 0; i != priv->rxqs_n; ++i) {
1460 struct mlx5_rxq_priv *rxq = mlx5_rxq_get(dev, i);
1463 if (rxq == NULL || rxq->ctrl == NULL)
1465 rxq->ctrl->rxq.mark = 0;
1466 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j)
1467 rxq->ctrl->flow_tunnels_n[j] = 0;
1468 rxq->ctrl->rxq.tunnel = 0;
1470 priv->mark_enabled = 0;
1474 * Set the Rx queue dynamic metadata (mask and offset) for a flow
1477 * Pointer to the Ethernet device structure.
1480 mlx5_flow_rxq_dynf_metadata_set(struct rte_eth_dev *dev)
1482 struct mlx5_priv *priv = dev->data->dev_private;
1485 for (i = 0; i != priv->rxqs_n; ++i) {
1486 struct mlx5_rxq_priv *rxq = mlx5_rxq_get(dev, i);
1487 struct mlx5_rxq_data *data;
1489 if (rxq == NULL || rxq->ctrl == NULL)
1491 data = &rxq->ctrl->rxq;
1492 if (!rte_flow_dynf_metadata_avail()) {
1493 data->dynf_meta = 0;
1494 data->flow_meta_mask = 0;
1495 data->flow_meta_offset = -1;
1496 data->flow_meta_port_mask = 0;
1498 data->dynf_meta = 1;
1499 data->flow_meta_mask = rte_flow_dynf_metadata_mask;
1500 data->flow_meta_offset = rte_flow_dynf_metadata_offs;
1501 data->flow_meta_port_mask = priv->sh->dv_meta_mask;
1507 * return a pointer to the desired action in the list of actions.
1509 * @param[in] actions
1510 * The list of actions to search the action in.
1512 * The action to find.
1515 * Pointer to the action in the list, if found. NULL otherwise.
1517 const struct rte_flow_action *
1518 mlx5_flow_find_action(const struct rte_flow_action *actions,
1519 enum rte_flow_action_type action)
1521 if (actions == NULL)
1523 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++)
1524 if (actions->type == action)
1530 * Validate the flag action.
1532 * @param[in] action_flags
1533 * Bit-fields that holds the actions detected until now.
1535 * Attributes of flow that includes this action.
1537 * Pointer to error structure.
1540 * 0 on success, a negative errno value otherwise and rte_errno is set.
1543 mlx5_flow_validate_action_flag(uint64_t action_flags,
1544 const struct rte_flow_attr *attr,
1545 struct rte_flow_error *error)
1547 if (action_flags & MLX5_FLOW_ACTION_MARK)
1548 return rte_flow_error_set(error, EINVAL,
1549 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1550 "can't mark and flag in same flow");
1551 if (action_flags & MLX5_FLOW_ACTION_FLAG)
1552 return rte_flow_error_set(error, EINVAL,
1553 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1555 " actions in same flow");
1557 return rte_flow_error_set(error, ENOTSUP,
1558 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1559 "flag action not supported for "
1565 * Validate the mark action.
1568 * Pointer to the queue action.
1569 * @param[in] action_flags
1570 * Bit-fields that holds the actions detected until now.
1572 * Attributes of flow that includes this action.
1574 * Pointer to error structure.
1577 * 0 on success, a negative errno value otherwise and rte_errno is set.
1580 mlx5_flow_validate_action_mark(const struct rte_flow_action *action,
1581 uint64_t action_flags,
1582 const struct rte_flow_attr *attr,
1583 struct rte_flow_error *error)
1585 const struct rte_flow_action_mark *mark = action->conf;
1588 return rte_flow_error_set(error, EINVAL,
1589 RTE_FLOW_ERROR_TYPE_ACTION,
1591 "configuration cannot be null");
1592 if (mark->id >= MLX5_FLOW_MARK_MAX)
1593 return rte_flow_error_set(error, EINVAL,
1594 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1596 "mark id must in 0 <= id < "
1597 RTE_STR(MLX5_FLOW_MARK_MAX));
1598 if (action_flags & MLX5_FLOW_ACTION_FLAG)
1599 return rte_flow_error_set(error, EINVAL,
1600 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1601 "can't flag and mark in same flow");
1602 if (action_flags & MLX5_FLOW_ACTION_MARK)
1603 return rte_flow_error_set(error, EINVAL,
1604 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1605 "can't have 2 mark actions in same"
1608 return rte_flow_error_set(error, ENOTSUP,
1609 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1610 "mark action not supported for "
1616 * Validate the drop action.
1618 * @param[in] action_flags
1619 * Bit-fields that holds the actions detected until now.
1621 * Attributes of flow that includes this action.
1623 * Pointer to error structure.
1626 * 0 on success, a negative errno value otherwise and rte_errno is set.
1629 mlx5_flow_validate_action_drop(uint64_t action_flags __rte_unused,
1630 const struct rte_flow_attr *attr,
1631 struct rte_flow_error *error)
1634 return rte_flow_error_set(error, ENOTSUP,
1635 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1636 "drop action not supported for "
1642 * Validate the queue action.
1645 * Pointer to the queue action.
1646 * @param[in] action_flags
1647 * Bit-fields that holds the actions detected until now.
1649 * Pointer to the Ethernet device structure.
1651 * Attributes of flow that includes this action.
1653 * Pointer to error structure.
1656 * 0 on success, a negative errno value otherwise and rte_errno is set.
1659 mlx5_flow_validate_action_queue(const struct rte_flow_action *action,
1660 uint64_t action_flags,
1661 struct rte_eth_dev *dev,
1662 const struct rte_flow_attr *attr,
1663 struct rte_flow_error *error)
1665 struct mlx5_priv *priv = dev->data->dev_private;
1666 const struct rte_flow_action_queue *queue = action->conf;
1668 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
1669 return rte_flow_error_set(error, EINVAL,
1670 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1671 "can't have 2 fate actions in"
1674 return rte_flow_error_set(error, EINVAL,
1675 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1676 NULL, "No Rx queues configured");
1677 if (queue->index >= priv->rxqs_n)
1678 return rte_flow_error_set(error, EINVAL,
1679 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1681 "queue index out of range");
1682 if (mlx5_rxq_get(dev, queue->index) == NULL)
1683 return rte_flow_error_set(error, EINVAL,
1684 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1686 "queue is not configured");
1688 return rte_flow_error_set(error, ENOTSUP,
1689 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1690 "queue action not supported for "
1696 * Validate queue numbers for device RSS.
1699 * Configured device.
1701 * Array of queue numbers.
1702 * @param[in] queues_n
1703 * Size of the @p queues array.
1705 * On error, filled with a textual error description.
1707 * On error, filled with an offending queue index in @p queues array.
1710 * 0 on success, a negative errno code on error.
1713 mlx5_validate_rss_queues(struct rte_eth_dev *dev,
1714 const uint16_t *queues, uint32_t queues_n,
1715 const char **error, uint32_t *queue_idx)
1717 const struct mlx5_priv *priv = dev->data->dev_private;
1718 enum mlx5_rxq_type rxq_type = MLX5_RXQ_TYPE_UNDEFINED;
1721 for (i = 0; i != queues_n; ++i) {
1722 struct mlx5_rxq_ctrl *rxq_ctrl = mlx5_rxq_ctrl_get(dev,
1725 if (queues[i] >= priv->rxqs_n) {
1726 *error = "queue index out of range";
1730 if (rxq_ctrl == NULL) {
1731 *error = "queue is not configured";
1736 rxq_type = rxq_ctrl->type;
1737 if (rxq_type != rxq_ctrl->type) {
1738 *error = "combining hairpin and regular RSS queues is not supported";
1747 * Validate the rss action.
1750 * Pointer to the Ethernet device structure.
1752 * Pointer to the queue action.
1754 * Pointer to error structure.
1757 * 0 on success, a negative errno value otherwise and rte_errno is set.
1760 mlx5_validate_action_rss(struct rte_eth_dev *dev,
1761 const struct rte_flow_action *action,
1762 struct rte_flow_error *error)
1764 struct mlx5_priv *priv = dev->data->dev_private;
1765 const struct rte_flow_action_rss *rss = action->conf;
1767 const char *message;
1770 if (rss->func != RTE_ETH_HASH_FUNCTION_DEFAULT &&
1771 rss->func != RTE_ETH_HASH_FUNCTION_TOEPLITZ)
1772 return rte_flow_error_set(error, ENOTSUP,
1773 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1775 "RSS hash function not supported");
1776 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
1781 return rte_flow_error_set(error, ENOTSUP,
1782 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1784 "tunnel RSS is not supported");
1785 /* allow RSS key_len 0 in case of NULL (default) RSS key. */
1786 if (rss->key_len == 0 && rss->key != NULL)
1787 return rte_flow_error_set(error, ENOTSUP,
1788 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1790 "RSS hash key length 0");
1791 if (rss->key_len > 0 && rss->key_len < MLX5_RSS_HASH_KEY_LEN)
1792 return rte_flow_error_set(error, ENOTSUP,
1793 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1795 "RSS hash key too small");
1796 if (rss->key_len > MLX5_RSS_HASH_KEY_LEN)
1797 return rte_flow_error_set(error, ENOTSUP,
1798 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1800 "RSS hash key too large");
1801 if (rss->queue_num > priv->sh->dev_cap.ind_table_max_size)
1802 return rte_flow_error_set(error, ENOTSUP,
1803 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1805 "number of queues too large");
1806 if (rss->types & MLX5_RSS_HF_MASK)
1807 return rte_flow_error_set(error, ENOTSUP,
1808 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1810 "some RSS protocols are not"
1812 if ((rss->types & (RTE_ETH_RSS_L3_SRC_ONLY | RTE_ETH_RSS_L3_DST_ONLY)) &&
1813 !(rss->types & RTE_ETH_RSS_IP))
1814 return rte_flow_error_set(error, EINVAL,
1815 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1816 "L3 partial RSS requested but L3 RSS"
1817 " type not specified");
1818 if ((rss->types & (RTE_ETH_RSS_L4_SRC_ONLY | RTE_ETH_RSS_L4_DST_ONLY)) &&
1819 !(rss->types & (RTE_ETH_RSS_UDP | RTE_ETH_RSS_TCP)))
1820 return rte_flow_error_set(error, EINVAL,
1821 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1822 "L4 partial RSS requested but L4 RSS"
1823 " type not specified");
1825 return rte_flow_error_set(error, EINVAL,
1826 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1827 NULL, "No Rx queues configured");
1828 if (!rss->queue_num)
1829 return rte_flow_error_set(error, EINVAL,
1830 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1831 NULL, "No queues configured");
1832 ret = mlx5_validate_rss_queues(dev, rss->queue, rss->queue_num,
1833 &message, &queue_idx);
1835 return rte_flow_error_set(error, -ret,
1836 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1837 &rss->queue[queue_idx], message);
1843 * Validate the rss action.
1846 * Pointer to the queue action.
1847 * @param[in] action_flags
1848 * Bit-fields that holds the actions detected until now.
1850 * Pointer to the Ethernet device structure.
1852 * Attributes of flow that includes this action.
1853 * @param[in] item_flags
1854 * Items that were detected.
1856 * Pointer to error structure.
1859 * 0 on success, a negative errno value otherwise and rte_errno is set.
1862 mlx5_flow_validate_action_rss(const struct rte_flow_action *action,
1863 uint64_t action_flags,
1864 struct rte_eth_dev *dev,
1865 const struct rte_flow_attr *attr,
1866 uint64_t item_flags,
1867 struct rte_flow_error *error)
1869 const struct rte_flow_action_rss *rss = action->conf;
1870 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1873 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
1874 return rte_flow_error_set(error, EINVAL,
1875 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1876 "can't have 2 fate actions"
1878 ret = mlx5_validate_action_rss(dev, action, error);
1882 return rte_flow_error_set(error, ENOTSUP,
1883 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1884 "rss action not supported for "
1886 if (rss->level > 1 && !tunnel)
1887 return rte_flow_error_set(error, EINVAL,
1888 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1889 "inner RSS is not supported for "
1890 "non-tunnel flows");
1891 if ((item_flags & MLX5_FLOW_LAYER_ECPRI) &&
1892 !(item_flags & MLX5_FLOW_LAYER_INNER_L4_UDP)) {
1893 return rte_flow_error_set(error, EINVAL,
1894 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1895 "RSS on eCPRI is not supported now");
1897 if ((item_flags & MLX5_FLOW_LAYER_MPLS) &&
1899 (MLX5_FLOW_LAYER_INNER_L2 | MLX5_FLOW_LAYER_INNER_L3)) &&
1901 return rte_flow_error_set(error, EINVAL,
1902 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
1903 "MPLS inner RSS needs to specify inner L2/L3 items after MPLS in pattern");
1908 * Validate the default miss action.
1910 * @param[in] action_flags
1911 * Bit-fields that holds the actions detected until now.
1913 * Pointer to error structure.
1916 * 0 on success, a negative errno value otherwise and rte_errno is set.
1919 mlx5_flow_validate_action_default_miss(uint64_t action_flags,
1920 const struct rte_flow_attr *attr,
1921 struct rte_flow_error *error)
1923 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
1924 return rte_flow_error_set(error, EINVAL,
1925 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1926 "can't have 2 fate actions in"
1929 return rte_flow_error_set(error, ENOTSUP,
1930 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1931 "default miss action not supported "
1934 return rte_flow_error_set(error, ENOTSUP,
1935 RTE_FLOW_ERROR_TYPE_ATTR_GROUP, NULL,
1936 "only group 0 is supported");
1938 return rte_flow_error_set(error, ENOTSUP,
1939 RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
1940 NULL, "transfer is not supported");
1945 * Validate the count action.
1948 * Pointer to the Ethernet device structure.
1950 * Attributes of flow that includes this action.
1952 * Pointer to error structure.
1955 * 0 on success, a negative errno value otherwise and rte_errno is set.
1958 mlx5_flow_validate_action_count(struct rte_eth_dev *dev __rte_unused,
1959 const struct rte_flow_attr *attr,
1960 struct rte_flow_error *error)
1963 return rte_flow_error_set(error, ENOTSUP,
1964 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1965 "count action not supported for "
1971 * Validate the ASO CT action.
1974 * Pointer to the Ethernet device structure.
1975 * @param[in] conntrack
1976 * Pointer to the CT action profile.
1978 * Pointer to error structure.
1981 * 0 on success, a negative errno value otherwise and rte_errno is set.
1984 mlx5_validate_action_ct(struct rte_eth_dev *dev,
1985 const struct rte_flow_action_conntrack *conntrack,
1986 struct rte_flow_error *error)
1990 if (conntrack->state > RTE_FLOW_CONNTRACK_STATE_TIME_WAIT)
1991 return rte_flow_error_set(error, EINVAL,
1992 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1993 "Invalid CT state");
1994 if (conntrack->last_index > RTE_FLOW_CONNTRACK_FLAG_RST)
1995 return rte_flow_error_set(error, EINVAL,
1996 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1997 "Invalid last TCP packet flag");
2002 * Verify the @p attributes will be correctly understood by the NIC and store
2003 * them in the @p flow if everything is correct.
2006 * Pointer to the Ethernet device structure.
2007 * @param[in] attributes
2008 * Pointer to flow attributes
2010 * Pointer to error structure.
2013 * 0 on success, a negative errno value otherwise and rte_errno is set.
2016 mlx5_flow_validate_attributes(struct rte_eth_dev *dev,
2017 const struct rte_flow_attr *attributes,
2018 struct rte_flow_error *error)
2020 struct mlx5_priv *priv = dev->data->dev_private;
2021 uint32_t priority_max = priv->sh->flow_max_priority - 1;
2023 if (attributes->group)
2024 return rte_flow_error_set(error, ENOTSUP,
2025 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
2026 NULL, "groups is not supported");
2027 if (attributes->priority != MLX5_FLOW_LOWEST_PRIO_INDICATOR &&
2028 attributes->priority >= priority_max)
2029 return rte_flow_error_set(error, ENOTSUP,
2030 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
2031 NULL, "priority out of range");
2032 if (attributes->egress)
2033 return rte_flow_error_set(error, ENOTSUP,
2034 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
2035 "egress is not supported");
2036 if (attributes->transfer && !priv->sh->config.dv_esw_en)
2037 return rte_flow_error_set(error, ENOTSUP,
2038 RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
2039 NULL, "transfer is not supported");
2040 if (!attributes->ingress)
2041 return rte_flow_error_set(error, EINVAL,
2042 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
2044 "ingress attribute is mandatory");
2049 * Validate ICMP6 item.
2052 * Item specification.
2053 * @param[in] item_flags
2054 * Bit-fields that holds the items detected until now.
2055 * @param[in] ext_vlan_sup
2056 * Whether extended VLAN features are supported or not.
2058 * Pointer to error structure.
2061 * 0 on success, a negative errno value otherwise and rte_errno is set.
2064 mlx5_flow_validate_item_icmp6(const struct rte_flow_item *item,
2065 uint64_t item_flags,
2066 uint8_t target_protocol,
2067 struct rte_flow_error *error)
2069 const struct rte_flow_item_icmp6 *mask = item->mask;
2070 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2071 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
2072 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
2073 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2074 MLX5_FLOW_LAYER_OUTER_L4;
2077 if (target_protocol != 0xFF && target_protocol != IPPROTO_ICMPV6)
2078 return rte_flow_error_set(error, EINVAL,
2079 RTE_FLOW_ERROR_TYPE_ITEM, item,
2080 "protocol filtering not compatible"
2081 " with ICMP6 layer");
2082 if (!(item_flags & l3m))
2083 return rte_flow_error_set(error, EINVAL,
2084 RTE_FLOW_ERROR_TYPE_ITEM, item,
2085 "IPv6 is mandatory to filter on"
2087 if (item_flags & l4m)
2088 return rte_flow_error_set(error, EINVAL,
2089 RTE_FLOW_ERROR_TYPE_ITEM, item,
2090 "multiple L4 layers not supported");
2092 mask = &rte_flow_item_icmp6_mask;
2093 ret = mlx5_flow_item_acceptable
2094 (item, (const uint8_t *)mask,
2095 (const uint8_t *)&rte_flow_item_icmp6_mask,
2096 sizeof(struct rte_flow_item_icmp6),
2097 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2104 * Validate ICMP item.
2107 * Item specification.
2108 * @param[in] item_flags
2109 * Bit-fields that holds the items detected until now.
2111 * Pointer to error structure.
2114 * 0 on success, a negative errno value otherwise and rte_errno is set.
2117 mlx5_flow_validate_item_icmp(const struct rte_flow_item *item,
2118 uint64_t item_flags,
2119 uint8_t target_protocol,
2120 struct rte_flow_error *error)
2122 const struct rte_flow_item_icmp *mask = item->mask;
2123 const struct rte_flow_item_icmp nic_mask = {
2124 .hdr.icmp_type = 0xff,
2125 .hdr.icmp_code = 0xff,
2126 .hdr.icmp_ident = RTE_BE16(0xffff),
2127 .hdr.icmp_seq_nb = RTE_BE16(0xffff),
2129 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2130 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
2131 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
2132 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2133 MLX5_FLOW_LAYER_OUTER_L4;
2136 if (target_protocol != 0xFF && target_protocol != IPPROTO_ICMP)
2137 return rte_flow_error_set(error, EINVAL,
2138 RTE_FLOW_ERROR_TYPE_ITEM, item,
2139 "protocol filtering not compatible"
2140 " with ICMP layer");
2141 if (!(item_flags & l3m))
2142 return rte_flow_error_set(error, EINVAL,
2143 RTE_FLOW_ERROR_TYPE_ITEM, item,
2144 "IPv4 is mandatory to filter"
2146 if (item_flags & l4m)
2147 return rte_flow_error_set(error, EINVAL,
2148 RTE_FLOW_ERROR_TYPE_ITEM, item,
2149 "multiple L4 layers not supported");
2152 ret = mlx5_flow_item_acceptable
2153 (item, (const uint8_t *)mask,
2154 (const uint8_t *)&nic_mask,
2155 sizeof(struct rte_flow_item_icmp),
2156 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2163 * Validate Ethernet item.
2166 * Item specification.
2167 * @param[in] item_flags
2168 * Bit-fields that holds the items detected until now.
2170 * Pointer to error structure.
2173 * 0 on success, a negative errno value otherwise and rte_errno is set.
2176 mlx5_flow_validate_item_eth(const struct rte_flow_item *item,
2177 uint64_t item_flags, bool ext_vlan_sup,
2178 struct rte_flow_error *error)
2180 const struct rte_flow_item_eth *mask = item->mask;
2181 const struct rte_flow_item_eth nic_mask = {
2182 .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
2183 .src.addr_bytes = "\xff\xff\xff\xff\xff\xff",
2184 .type = RTE_BE16(0xffff),
2185 .has_vlan = ext_vlan_sup ? 1 : 0,
2188 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2189 const uint64_t ethm = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
2190 MLX5_FLOW_LAYER_OUTER_L2;
2192 if (item_flags & ethm)
2193 return rte_flow_error_set(error, ENOTSUP,
2194 RTE_FLOW_ERROR_TYPE_ITEM, item,
2195 "multiple L2 layers not supported");
2196 if ((!tunnel && (item_flags & MLX5_FLOW_LAYER_OUTER_L3)) ||
2197 (tunnel && (item_flags & MLX5_FLOW_LAYER_INNER_L3)))
2198 return rte_flow_error_set(error, EINVAL,
2199 RTE_FLOW_ERROR_TYPE_ITEM, item,
2200 "L2 layer should not follow "
2202 if ((!tunnel && (item_flags & MLX5_FLOW_LAYER_OUTER_VLAN)) ||
2203 (tunnel && (item_flags & MLX5_FLOW_LAYER_INNER_VLAN)))
2204 return rte_flow_error_set(error, EINVAL,
2205 RTE_FLOW_ERROR_TYPE_ITEM, item,
2206 "L2 layer should not follow VLAN");
2207 if (item_flags & MLX5_FLOW_LAYER_GTP)
2208 return rte_flow_error_set(error, EINVAL,
2209 RTE_FLOW_ERROR_TYPE_ITEM, item,
2210 "L2 layer should not follow GTP");
2212 mask = &rte_flow_item_eth_mask;
2213 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2214 (const uint8_t *)&nic_mask,
2215 sizeof(struct rte_flow_item_eth),
2216 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2221 * Validate VLAN item.
2224 * Item specification.
2225 * @param[in] item_flags
2226 * Bit-fields that holds the items detected until now.
2228 * Ethernet device flow is being created on.
2230 * Pointer to error structure.
2233 * 0 on success, a negative errno value otherwise and rte_errno is set.
2236 mlx5_flow_validate_item_vlan(const struct rte_flow_item *item,
2237 uint64_t item_flags,
2238 struct rte_eth_dev *dev,
2239 struct rte_flow_error *error)
2241 const struct rte_flow_item_vlan *spec = item->spec;
2242 const struct rte_flow_item_vlan *mask = item->mask;
2243 const struct rte_flow_item_vlan nic_mask = {
2244 .tci = RTE_BE16(UINT16_MAX),
2245 .inner_type = RTE_BE16(UINT16_MAX),
2247 uint16_t vlan_tag = 0;
2248 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2250 const uint64_t l34m = tunnel ? (MLX5_FLOW_LAYER_INNER_L3 |
2251 MLX5_FLOW_LAYER_INNER_L4) :
2252 (MLX5_FLOW_LAYER_OUTER_L3 |
2253 MLX5_FLOW_LAYER_OUTER_L4);
2254 const uint64_t vlanm = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
2255 MLX5_FLOW_LAYER_OUTER_VLAN;
2257 if (item_flags & vlanm)
2258 return rte_flow_error_set(error, EINVAL,
2259 RTE_FLOW_ERROR_TYPE_ITEM, item,
2260 "multiple VLAN layers not supported");
2261 else if ((item_flags & l34m) != 0)
2262 return rte_flow_error_set(error, EINVAL,
2263 RTE_FLOW_ERROR_TYPE_ITEM, item,
2264 "VLAN cannot follow L3/L4 layer");
2266 mask = &rte_flow_item_vlan_mask;
2267 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2268 (const uint8_t *)&nic_mask,
2269 sizeof(struct rte_flow_item_vlan),
2270 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2273 if (!tunnel && mask->tci != RTE_BE16(0x0fff)) {
2274 struct mlx5_priv *priv = dev->data->dev_private;
2276 if (priv->vmwa_context) {
2278 * Non-NULL context means we have a virtual machine
2279 * and SR-IOV enabled, we have to create VLAN interface
2280 * to make hypervisor to setup E-Switch vport
2281 * context correctly. We avoid creating the multiple
2282 * VLAN interfaces, so we cannot support VLAN tag mask.
2284 return rte_flow_error_set(error, EINVAL,
2285 RTE_FLOW_ERROR_TYPE_ITEM,
2287 "VLAN tag mask is not"
2288 " supported in virtual"
2293 vlan_tag = spec->tci;
2294 vlan_tag &= mask->tci;
2297 * From verbs perspective an empty VLAN is equivalent
2298 * to a packet without VLAN layer.
2301 return rte_flow_error_set(error, EINVAL,
2302 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
2304 "VLAN cannot be empty");
2309 * Validate IPV4 item.
2312 * Item specification.
2313 * @param[in] item_flags
2314 * Bit-fields that holds the items detected until now.
2315 * @param[in] last_item
2316 * Previous validated item in the pattern items.
2317 * @param[in] ether_type
2318 * Type in the ethernet layer header (including dot1q).
2319 * @param[in] acc_mask
2320 * Acceptable mask, if NULL default internal default mask
2321 * will be used to check whether item fields are supported.
2322 * @param[in] range_accepted
2323 * True if range of values is accepted for specific fields, false otherwise.
2325 * Pointer to error structure.
2328 * 0 on success, a negative errno value otherwise and rte_errno is set.
2331 mlx5_flow_validate_item_ipv4(const struct rte_flow_item *item,
2332 uint64_t item_flags,
2334 uint16_t ether_type,
2335 const struct rte_flow_item_ipv4 *acc_mask,
2336 bool range_accepted,
2337 struct rte_flow_error *error)
2339 const struct rte_flow_item_ipv4 *mask = item->mask;
2340 const struct rte_flow_item_ipv4 *spec = item->spec;
2341 const struct rte_flow_item_ipv4 nic_mask = {
2343 .src_addr = RTE_BE32(0xffffffff),
2344 .dst_addr = RTE_BE32(0xffffffff),
2345 .type_of_service = 0xff,
2346 .next_proto_id = 0xff,
2349 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2350 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2351 MLX5_FLOW_LAYER_OUTER_L3;
2352 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2353 MLX5_FLOW_LAYER_OUTER_L4;
2355 uint8_t next_proto = 0xFF;
2356 const uint64_t l2_vlan = (MLX5_FLOW_LAYER_L2 |
2357 MLX5_FLOW_LAYER_OUTER_VLAN |
2358 MLX5_FLOW_LAYER_INNER_VLAN);
2360 if ((last_item & l2_vlan) && ether_type &&
2361 ether_type != RTE_ETHER_TYPE_IPV4)
2362 return rte_flow_error_set(error, EINVAL,
2363 RTE_FLOW_ERROR_TYPE_ITEM, item,
2364 "IPv4 cannot follow L2/VLAN layer "
2365 "which ether type is not IPv4");
2366 if (item_flags & MLX5_FLOW_LAYER_TUNNEL) {
2368 next_proto = mask->hdr.next_proto_id &
2369 spec->hdr.next_proto_id;
2370 if (next_proto == IPPROTO_IPIP || next_proto == IPPROTO_IPV6)
2371 return rte_flow_error_set(error, EINVAL,
2372 RTE_FLOW_ERROR_TYPE_ITEM,
2377 if (item_flags & MLX5_FLOW_LAYER_IPV6_ENCAP)
2378 return rte_flow_error_set(error, EINVAL,
2379 RTE_FLOW_ERROR_TYPE_ITEM, item,
2380 "wrong tunnel type - IPv6 specified "
2381 "but IPv4 item provided");
2382 if (item_flags & l3m)
2383 return rte_flow_error_set(error, ENOTSUP,
2384 RTE_FLOW_ERROR_TYPE_ITEM, item,
2385 "multiple L3 layers not supported");
2386 else if (item_flags & l4m)
2387 return rte_flow_error_set(error, EINVAL,
2388 RTE_FLOW_ERROR_TYPE_ITEM, item,
2389 "L3 cannot follow an L4 layer.");
2390 else if ((item_flags & MLX5_FLOW_LAYER_NVGRE) &&
2391 !(item_flags & MLX5_FLOW_LAYER_INNER_L2))
2392 return rte_flow_error_set(error, EINVAL,
2393 RTE_FLOW_ERROR_TYPE_ITEM, item,
2394 "L3 cannot follow an NVGRE layer.");
2396 mask = &rte_flow_item_ipv4_mask;
2397 else if (mask->hdr.next_proto_id != 0 &&
2398 mask->hdr.next_proto_id != 0xff)
2399 return rte_flow_error_set(error, EINVAL,
2400 RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
2401 "partial mask is not supported"
2403 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2404 acc_mask ? (const uint8_t *)acc_mask
2405 : (const uint8_t *)&nic_mask,
2406 sizeof(struct rte_flow_item_ipv4),
2407 range_accepted, error);
2414 * Validate IPV6 item.
2417 * Item specification.
2418 * @param[in] item_flags
2419 * Bit-fields that holds the items detected until now.
2420 * @param[in] last_item
2421 * Previous validated item in the pattern items.
2422 * @param[in] ether_type
2423 * Type in the ethernet layer header (including dot1q).
2424 * @param[in] acc_mask
2425 * Acceptable mask, if NULL default internal default mask
2426 * will be used to check whether item fields are supported.
2428 * Pointer to error structure.
2431 * 0 on success, a negative errno value otherwise and rte_errno is set.
2434 mlx5_flow_validate_item_ipv6(const struct rte_flow_item *item,
2435 uint64_t item_flags,
2437 uint16_t ether_type,
2438 const struct rte_flow_item_ipv6 *acc_mask,
2439 struct rte_flow_error *error)
2441 const struct rte_flow_item_ipv6 *mask = item->mask;
2442 const struct rte_flow_item_ipv6 *spec = item->spec;
2443 const struct rte_flow_item_ipv6 nic_mask = {
2446 "\xff\xff\xff\xff\xff\xff\xff\xff"
2447 "\xff\xff\xff\xff\xff\xff\xff\xff",
2449 "\xff\xff\xff\xff\xff\xff\xff\xff"
2450 "\xff\xff\xff\xff\xff\xff\xff\xff",
2451 .vtc_flow = RTE_BE32(0xffffffff),
2455 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2456 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2457 MLX5_FLOW_LAYER_OUTER_L3;
2458 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2459 MLX5_FLOW_LAYER_OUTER_L4;
2461 uint8_t next_proto = 0xFF;
2462 const uint64_t l2_vlan = (MLX5_FLOW_LAYER_L2 |
2463 MLX5_FLOW_LAYER_OUTER_VLAN |
2464 MLX5_FLOW_LAYER_INNER_VLAN);
2466 if ((last_item & l2_vlan) && ether_type &&
2467 ether_type != RTE_ETHER_TYPE_IPV6)
2468 return rte_flow_error_set(error, EINVAL,
2469 RTE_FLOW_ERROR_TYPE_ITEM, item,
2470 "IPv6 cannot follow L2/VLAN layer "
2471 "which ether type is not IPv6");
2472 if (mask && mask->hdr.proto == UINT8_MAX && spec)
2473 next_proto = spec->hdr.proto;
2474 if (item_flags & MLX5_FLOW_LAYER_TUNNEL) {
2475 if (next_proto == IPPROTO_IPIP || next_proto == IPPROTO_IPV6)
2476 return rte_flow_error_set(error, EINVAL,
2477 RTE_FLOW_ERROR_TYPE_ITEM,
2482 if (next_proto == IPPROTO_HOPOPTS ||
2483 next_proto == IPPROTO_ROUTING ||
2484 next_proto == IPPROTO_FRAGMENT ||
2485 next_proto == IPPROTO_ESP ||
2486 next_proto == IPPROTO_AH ||
2487 next_proto == IPPROTO_DSTOPTS)
2488 return rte_flow_error_set(error, EINVAL,
2489 RTE_FLOW_ERROR_TYPE_ITEM, item,
2490 "IPv6 proto (next header) should "
2491 "not be set as extension header");
2492 if (item_flags & MLX5_FLOW_LAYER_IPIP)
2493 return rte_flow_error_set(error, EINVAL,
2494 RTE_FLOW_ERROR_TYPE_ITEM, item,
2495 "wrong tunnel type - IPv4 specified "
2496 "but IPv6 item provided");
2497 if (item_flags & l3m)
2498 return rte_flow_error_set(error, ENOTSUP,
2499 RTE_FLOW_ERROR_TYPE_ITEM, item,
2500 "multiple L3 layers not supported");
2501 else if (item_flags & l4m)
2502 return rte_flow_error_set(error, EINVAL,
2503 RTE_FLOW_ERROR_TYPE_ITEM, item,
2504 "L3 cannot follow an L4 layer.");
2505 else if ((item_flags & MLX5_FLOW_LAYER_NVGRE) &&
2506 !(item_flags & MLX5_FLOW_LAYER_INNER_L2))
2507 return rte_flow_error_set(error, EINVAL,
2508 RTE_FLOW_ERROR_TYPE_ITEM, item,
2509 "L3 cannot follow an NVGRE layer.");
2511 mask = &rte_flow_item_ipv6_mask;
2512 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2513 acc_mask ? (const uint8_t *)acc_mask
2514 : (const uint8_t *)&nic_mask,
2515 sizeof(struct rte_flow_item_ipv6),
2516 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2523 * Validate UDP item.
2526 * Item specification.
2527 * @param[in] item_flags
2528 * Bit-fields that holds the items detected until now.
2529 * @param[in] target_protocol
2530 * The next protocol in the previous item.
2531 * @param[in] flow_mask
2532 * mlx5 flow-specific (DV, verbs, etc.) supported header fields mask.
2534 * Pointer to error structure.
2537 * 0 on success, a negative errno value otherwise and rte_errno is set.
2540 mlx5_flow_validate_item_udp(const struct rte_flow_item *item,
2541 uint64_t item_flags,
2542 uint8_t target_protocol,
2543 struct rte_flow_error *error)
2545 const struct rte_flow_item_udp *mask = item->mask;
2546 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2547 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2548 MLX5_FLOW_LAYER_OUTER_L3;
2549 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2550 MLX5_FLOW_LAYER_OUTER_L4;
2553 if (target_protocol != 0xff && target_protocol != IPPROTO_UDP)
2554 return rte_flow_error_set(error, EINVAL,
2555 RTE_FLOW_ERROR_TYPE_ITEM, item,
2556 "protocol filtering not compatible"
2558 if (!(item_flags & l3m))
2559 return rte_flow_error_set(error, EINVAL,
2560 RTE_FLOW_ERROR_TYPE_ITEM, item,
2561 "L3 is mandatory to filter on L4");
2562 if (item_flags & l4m)
2563 return rte_flow_error_set(error, EINVAL,
2564 RTE_FLOW_ERROR_TYPE_ITEM, item,
2565 "multiple L4 layers not supported");
2567 mask = &rte_flow_item_udp_mask;
2568 ret = mlx5_flow_item_acceptable
2569 (item, (const uint8_t *)mask,
2570 (const uint8_t *)&rte_flow_item_udp_mask,
2571 sizeof(struct rte_flow_item_udp), MLX5_ITEM_RANGE_NOT_ACCEPTED,
2579 * Validate TCP item.
2582 * Item specification.
2583 * @param[in] item_flags
2584 * Bit-fields that holds the items detected until now.
2585 * @param[in] target_protocol
2586 * The next protocol in the previous item.
2588 * Pointer to error structure.
2591 * 0 on success, a negative errno value otherwise and rte_errno is set.
2594 mlx5_flow_validate_item_tcp(const struct rte_flow_item *item,
2595 uint64_t item_flags,
2596 uint8_t target_protocol,
2597 const struct rte_flow_item_tcp *flow_mask,
2598 struct rte_flow_error *error)
2600 const struct rte_flow_item_tcp *mask = item->mask;
2601 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2602 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2603 MLX5_FLOW_LAYER_OUTER_L3;
2604 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2605 MLX5_FLOW_LAYER_OUTER_L4;
2608 MLX5_ASSERT(flow_mask);
2609 if (target_protocol != 0xff && target_protocol != IPPROTO_TCP)
2610 return rte_flow_error_set(error, EINVAL,
2611 RTE_FLOW_ERROR_TYPE_ITEM, item,
2612 "protocol filtering not compatible"
2614 if (!(item_flags & l3m))
2615 return rte_flow_error_set(error, EINVAL,
2616 RTE_FLOW_ERROR_TYPE_ITEM, item,
2617 "L3 is mandatory to filter on L4");
2618 if (item_flags & l4m)
2619 return rte_flow_error_set(error, EINVAL,
2620 RTE_FLOW_ERROR_TYPE_ITEM, item,
2621 "multiple L4 layers not supported");
2623 mask = &rte_flow_item_tcp_mask;
2624 ret = mlx5_flow_item_acceptable
2625 (item, (const uint8_t *)mask,
2626 (const uint8_t *)flow_mask,
2627 sizeof(struct rte_flow_item_tcp), MLX5_ITEM_RANGE_NOT_ACCEPTED,
2635 * Validate VXLAN item.
2638 * Pointer to the Ethernet device structure.
2639 * @param[in] udp_dport
2640 * UDP destination port
2642 * Item specification.
2643 * @param[in] item_flags
2644 * Bit-fields that holds the items detected until now.
2646 * Flow rule attributes.
2648 * Pointer to error structure.
2651 * 0 on success, a negative errno value otherwise and rte_errno is set.
2654 mlx5_flow_validate_item_vxlan(struct rte_eth_dev *dev,
2656 const struct rte_flow_item *item,
2657 uint64_t item_flags,
2658 const struct rte_flow_attr *attr,
2659 struct rte_flow_error *error)
2661 const struct rte_flow_item_vxlan *spec = item->spec;
2662 const struct rte_flow_item_vxlan *mask = item->mask;
2664 struct mlx5_priv *priv = dev->data->dev_private;
2668 } id = { .vlan_id = 0, };
2669 const struct rte_flow_item_vxlan nic_mask = {
2670 .vni = "\xff\xff\xff",
2673 const struct rte_flow_item_vxlan *valid_mask;
2675 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2676 return rte_flow_error_set(error, ENOTSUP,
2677 RTE_FLOW_ERROR_TYPE_ITEM, item,
2678 "multiple tunnel layers not"
2680 valid_mask = &rte_flow_item_vxlan_mask;
2682 * Verify only UDPv4 is present as defined in
2683 * https://tools.ietf.org/html/rfc7348
2685 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2686 return rte_flow_error_set(error, EINVAL,
2687 RTE_FLOW_ERROR_TYPE_ITEM, item,
2688 "no outer UDP layer found");
2690 mask = &rte_flow_item_vxlan_mask;
2692 if (priv->sh->steering_format_version !=
2693 MLX5_STEERING_LOGIC_FORMAT_CONNECTX_5 ||
2694 !udp_dport || udp_dport == MLX5_UDP_PORT_VXLAN) {
2695 /* FDB domain & NIC domain non-zero group */
2696 if ((attr->transfer || attr->group) && priv->sh->misc5_cap)
2697 valid_mask = &nic_mask;
2698 /* Group zero in NIC domain */
2699 if (!attr->group && !attr->transfer &&
2700 priv->sh->tunnel_header_0_1)
2701 valid_mask = &nic_mask;
2703 ret = mlx5_flow_item_acceptable
2704 (item, (const uint8_t *)mask,
2705 (const uint8_t *)valid_mask,
2706 sizeof(struct rte_flow_item_vxlan),
2707 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2711 memcpy(&id.vni[1], spec->vni, 3);
2712 memcpy(&id.vni[1], mask->vni, 3);
2714 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
2715 return rte_flow_error_set(error, ENOTSUP,
2716 RTE_FLOW_ERROR_TYPE_ITEM, item,
2717 "VXLAN tunnel must be fully defined");
2722 * Validate VXLAN_GPE item.
2725 * Item specification.
2726 * @param[in] item_flags
2727 * Bit-fields that holds the items detected until now.
2729 * Pointer to the private data structure.
2730 * @param[in] target_protocol
2731 * The next protocol in the previous item.
2733 * Pointer to error structure.
2736 * 0 on success, a negative errno value otherwise and rte_errno is set.
2739 mlx5_flow_validate_item_vxlan_gpe(const struct rte_flow_item *item,
2740 uint64_t item_flags,
2741 struct rte_eth_dev *dev,
2742 struct rte_flow_error *error)
2744 struct mlx5_priv *priv = dev->data->dev_private;
2745 const struct rte_flow_item_vxlan_gpe *spec = item->spec;
2746 const struct rte_flow_item_vxlan_gpe *mask = item->mask;
2751 } id = { .vlan_id = 0, };
2753 if (!priv->sh->config.l3_vxlan_en)
2754 return rte_flow_error_set(error, ENOTSUP,
2755 RTE_FLOW_ERROR_TYPE_ITEM, item,
2756 "L3 VXLAN is not enabled by device"
2757 " parameter and/or not configured in"
2759 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2760 return rte_flow_error_set(error, ENOTSUP,
2761 RTE_FLOW_ERROR_TYPE_ITEM, item,
2762 "multiple tunnel layers not"
2765 * Verify only UDPv4 is present as defined in
2766 * https://tools.ietf.org/html/rfc7348
2768 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2769 return rte_flow_error_set(error, EINVAL,
2770 RTE_FLOW_ERROR_TYPE_ITEM, item,
2771 "no outer UDP layer found");
2773 mask = &rte_flow_item_vxlan_gpe_mask;
2774 ret = mlx5_flow_item_acceptable
2775 (item, (const uint8_t *)mask,
2776 (const uint8_t *)&rte_flow_item_vxlan_gpe_mask,
2777 sizeof(struct rte_flow_item_vxlan_gpe),
2778 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2783 return rte_flow_error_set(error, ENOTSUP,
2784 RTE_FLOW_ERROR_TYPE_ITEM,
2786 "VxLAN-GPE protocol"
2788 memcpy(&id.vni[1], spec->vni, 3);
2789 memcpy(&id.vni[1], mask->vni, 3);
2791 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
2792 return rte_flow_error_set(error, ENOTSUP,
2793 RTE_FLOW_ERROR_TYPE_ITEM, item,
2794 "VXLAN-GPE tunnel must be fully"
2799 * Validate GRE Key item.
2802 * Item specification.
2803 * @param[in] item_flags
2804 * Bit flags to mark detected items.
2805 * @param[in] gre_item
2806 * Pointer to gre_item
2808 * Pointer to error structure.
2811 * 0 on success, a negative errno value otherwise and rte_errno is set.
2814 mlx5_flow_validate_item_gre_key(const struct rte_flow_item *item,
2815 uint64_t item_flags,
2816 const struct rte_flow_item *gre_item,
2817 struct rte_flow_error *error)
2819 const rte_be32_t *mask = item->mask;
2821 rte_be32_t gre_key_default_mask = RTE_BE32(UINT32_MAX);
2822 const struct rte_flow_item_gre *gre_spec;
2823 const struct rte_flow_item_gre *gre_mask;
2825 if (item_flags & MLX5_FLOW_LAYER_GRE_KEY)
2826 return rte_flow_error_set(error, ENOTSUP,
2827 RTE_FLOW_ERROR_TYPE_ITEM, item,
2828 "Multiple GRE key not support");
2829 if (!(item_flags & MLX5_FLOW_LAYER_GRE))
2830 return rte_flow_error_set(error, ENOTSUP,
2831 RTE_FLOW_ERROR_TYPE_ITEM, item,
2832 "No preceding GRE header");
2833 if (item_flags & MLX5_FLOW_LAYER_INNER)
2834 return rte_flow_error_set(error, ENOTSUP,
2835 RTE_FLOW_ERROR_TYPE_ITEM, item,
2836 "GRE key following a wrong item");
2837 gre_mask = gre_item->mask;
2839 gre_mask = &rte_flow_item_gre_mask;
2840 gre_spec = gre_item->spec;
2841 if (gre_spec && (gre_mask->c_rsvd0_ver & RTE_BE16(0x2000)) &&
2842 !(gre_spec->c_rsvd0_ver & RTE_BE16(0x2000)))
2843 return rte_flow_error_set(error, EINVAL,
2844 RTE_FLOW_ERROR_TYPE_ITEM, item,
2845 "Key bit must be on");
2848 mask = &gre_key_default_mask;
2849 ret = mlx5_flow_item_acceptable
2850 (item, (const uint8_t *)mask,
2851 (const uint8_t *)&gre_key_default_mask,
2852 sizeof(rte_be32_t), MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2857 * Validate GRE item.
2860 * Item specification.
2861 * @param[in] item_flags
2862 * Bit flags to mark detected items.
2863 * @param[in] target_protocol
2864 * The next protocol in the previous item.
2866 * Pointer to error structure.
2869 * 0 on success, a negative errno value otherwise and rte_errno is set.
2872 mlx5_flow_validate_item_gre(const struct rte_flow_item *item,
2873 uint64_t item_flags,
2874 uint8_t target_protocol,
2875 struct rte_flow_error *error)
2877 const struct rte_flow_item_gre *spec __rte_unused = item->spec;
2878 const struct rte_flow_item_gre *mask = item->mask;
2880 const struct rte_flow_item_gre nic_mask = {
2881 .c_rsvd0_ver = RTE_BE16(0xB000),
2882 .protocol = RTE_BE16(UINT16_MAX),
2885 if (target_protocol != 0xff && target_protocol != IPPROTO_GRE)
2886 return rte_flow_error_set(error, EINVAL,
2887 RTE_FLOW_ERROR_TYPE_ITEM, item,
2888 "protocol filtering not compatible"
2889 " with this GRE layer");
2890 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2891 return rte_flow_error_set(error, ENOTSUP,
2892 RTE_FLOW_ERROR_TYPE_ITEM, item,
2893 "multiple tunnel layers not"
2895 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3))
2896 return rte_flow_error_set(error, ENOTSUP,
2897 RTE_FLOW_ERROR_TYPE_ITEM, item,
2898 "L3 Layer is missing");
2900 mask = &rte_flow_item_gre_mask;
2901 ret = mlx5_flow_item_acceptable
2902 (item, (const uint8_t *)mask,
2903 (const uint8_t *)&nic_mask,
2904 sizeof(struct rte_flow_item_gre), MLX5_ITEM_RANGE_NOT_ACCEPTED,
2908 #ifndef HAVE_MLX5DV_DR
2909 #ifndef HAVE_IBV_DEVICE_MPLS_SUPPORT
2910 if (spec && (spec->protocol & mask->protocol))
2911 return rte_flow_error_set(error, ENOTSUP,
2912 RTE_FLOW_ERROR_TYPE_ITEM, item,
2913 "without MPLS support the"
2914 " specification cannot be used for"
2922 * Validate Geneve item.
2925 * Item specification.
2926 * @param[in] itemFlags
2927 * Bit-fields that holds the items detected until now.
2929 * Pointer to the private data structure.
2931 * Pointer to error structure.
2934 * 0 on success, a negative errno value otherwise and rte_errno is set.
2938 mlx5_flow_validate_item_geneve(const struct rte_flow_item *item,
2939 uint64_t item_flags,
2940 struct rte_eth_dev *dev,
2941 struct rte_flow_error *error)
2943 struct mlx5_priv *priv = dev->data->dev_private;
2944 const struct rte_flow_item_geneve *spec = item->spec;
2945 const struct rte_flow_item_geneve *mask = item->mask;
2948 uint8_t opt_len = priv->sh->cdev->config.hca_attr.geneve_max_opt_len ?
2949 MLX5_GENEVE_OPT_LEN_1 : MLX5_GENEVE_OPT_LEN_0;
2950 const struct rte_flow_item_geneve nic_mask = {
2951 .ver_opt_len_o_c_rsvd0 = RTE_BE16(0x3f80),
2952 .vni = "\xff\xff\xff",
2953 .protocol = RTE_BE16(UINT16_MAX),
2956 if (!priv->sh->cdev->config.hca_attr.tunnel_stateless_geneve_rx)
2957 return rte_flow_error_set(error, ENOTSUP,
2958 RTE_FLOW_ERROR_TYPE_ITEM, item,
2959 "L3 Geneve is not enabled by device"
2960 " parameter and/or not configured in"
2962 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2963 return rte_flow_error_set(error, ENOTSUP,
2964 RTE_FLOW_ERROR_TYPE_ITEM, item,
2965 "multiple tunnel layers not"
2968 * Verify only UDPv4 is present as defined in
2969 * https://tools.ietf.org/html/rfc7348
2971 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2972 return rte_flow_error_set(error, EINVAL,
2973 RTE_FLOW_ERROR_TYPE_ITEM, item,
2974 "no outer UDP layer found");
2976 mask = &rte_flow_item_geneve_mask;
2977 ret = mlx5_flow_item_acceptable
2978 (item, (const uint8_t *)mask,
2979 (const uint8_t *)&nic_mask,
2980 sizeof(struct rte_flow_item_geneve),
2981 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2985 gbhdr = rte_be_to_cpu_16(spec->ver_opt_len_o_c_rsvd0);
2986 if (MLX5_GENEVE_VER_VAL(gbhdr) ||
2987 MLX5_GENEVE_CRITO_VAL(gbhdr) ||
2988 MLX5_GENEVE_RSVD_VAL(gbhdr) || spec->rsvd1)
2989 return rte_flow_error_set(error, ENOTSUP,
2990 RTE_FLOW_ERROR_TYPE_ITEM,
2992 "Geneve protocol unsupported"
2993 " fields are being used");
2994 if (MLX5_GENEVE_OPTLEN_VAL(gbhdr) > opt_len)
2995 return rte_flow_error_set
2997 RTE_FLOW_ERROR_TYPE_ITEM,
2999 "Unsupported Geneve options length");
3001 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
3002 return rte_flow_error_set
3004 RTE_FLOW_ERROR_TYPE_ITEM, item,
3005 "Geneve tunnel must be fully defined");
3010 * Validate Geneve TLV option item.
3013 * Item specification.
3014 * @param[in] last_item
3015 * Previous validated item in the pattern items.
3016 * @param[in] geneve_item
3017 * Previous GENEVE item specification.
3019 * Pointer to the rte_eth_dev structure.
3021 * Pointer to error structure.
3024 * 0 on success, a negative errno value otherwise and rte_errno is set.
3027 mlx5_flow_validate_item_geneve_opt(const struct rte_flow_item *item,
3029 const struct rte_flow_item *geneve_item,
3030 struct rte_eth_dev *dev,
3031 struct rte_flow_error *error)
3033 struct mlx5_priv *priv = dev->data->dev_private;
3034 struct mlx5_dev_ctx_shared *sh = priv->sh;
3035 struct mlx5_geneve_tlv_option_resource *geneve_opt_resource;
3036 struct mlx5_hca_attr *hca_attr = &sh->cdev->config.hca_attr;
3037 uint8_t data_max_supported =
3038 hca_attr->max_geneve_tlv_option_data_len * 4;
3039 const struct rte_flow_item_geneve *geneve_spec;
3040 const struct rte_flow_item_geneve *geneve_mask;
3041 const struct rte_flow_item_geneve_opt *spec = item->spec;
3042 const struct rte_flow_item_geneve_opt *mask = item->mask;
3044 unsigned int data_len;
3045 uint8_t tlv_option_len;
3046 uint16_t optlen_m, optlen_v;
3047 const struct rte_flow_item_geneve_opt full_mask = {
3048 .option_class = RTE_BE16(0xffff),
3049 .option_type = 0xff,
3054 mask = &rte_flow_item_geneve_opt_mask;
3056 return rte_flow_error_set
3057 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
3058 "Geneve TLV opt class/type/length must be specified");
3059 if ((uint32_t)spec->option_len > MLX5_GENEVE_OPTLEN_MASK)
3060 return rte_flow_error_set
3061 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
3062 "Geneve TLV opt length exceeds the limit (31)");
3063 /* Check if class type and length masks are full. */
3064 if (full_mask.option_class != mask->option_class ||
3065 full_mask.option_type != mask->option_type ||
3066 full_mask.option_len != (mask->option_len & full_mask.option_len))
3067 return rte_flow_error_set
3068 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
3069 "Geneve TLV opt class/type/length masks must be full");
3070 /* Check if length is supported */
3071 if ((uint32_t)spec->option_len >
3072 hca_attr->max_geneve_tlv_option_data_len)
3073 return rte_flow_error_set
3074 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
3075 "Geneve TLV opt length not supported");
3076 if (hca_attr->max_geneve_tlv_options > 1)
3078 "max_geneve_tlv_options supports more than 1 option");
3079 /* Check GENEVE item preceding. */
3080 if (!geneve_item || !(last_item & MLX5_FLOW_LAYER_GENEVE))
3081 return rte_flow_error_set
3082 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
3083 "Geneve opt item must be preceded with Geneve item");
3084 geneve_spec = geneve_item->spec;
3085 geneve_mask = geneve_item->mask ? geneve_item->mask :
3086 &rte_flow_item_geneve_mask;
3087 /* Check if GENEVE TLV option size doesn't exceed option length */
3088 if (geneve_spec && (geneve_mask->ver_opt_len_o_c_rsvd0 ||
3089 geneve_spec->ver_opt_len_o_c_rsvd0)) {
3090 tlv_option_len = spec->option_len & mask->option_len;
3091 optlen_v = rte_be_to_cpu_16(geneve_spec->ver_opt_len_o_c_rsvd0);
3092 optlen_v = MLX5_GENEVE_OPTLEN_VAL(optlen_v);
3093 optlen_m = rte_be_to_cpu_16(geneve_mask->ver_opt_len_o_c_rsvd0);
3094 optlen_m = MLX5_GENEVE_OPTLEN_VAL(optlen_m);
3095 if ((optlen_v & optlen_m) <= tlv_option_len)
3096 return rte_flow_error_set
3097 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
3098 "GENEVE TLV option length exceeds optlen");
3100 /* Check if length is 0 or data is 0. */
3101 if (spec->data == NULL || spec->option_len == 0)
3102 return rte_flow_error_set
3103 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
3104 "Geneve TLV opt with zero data/length not supported");
3105 /* Check not all data & mask are 0. */
3106 data_len = spec->option_len * 4;
3107 if (mask->data == NULL) {
3108 for (i = 0; i < data_len; i++)
3112 return rte_flow_error_set(error, ENOTSUP,
3113 RTE_FLOW_ERROR_TYPE_ITEM, item,
3114 "Can't match on Geneve option data 0");
3116 for (i = 0; i < data_len; i++)
3117 if (spec->data[i] & mask->data[i])
3120 return rte_flow_error_set(error, ENOTSUP,
3121 RTE_FLOW_ERROR_TYPE_ITEM, item,
3122 "Can't match on Geneve option data and mask 0");
3123 /* Check data mask supported. */
3124 for (i = data_max_supported; i < data_len ; i++)
3126 return rte_flow_error_set(error, ENOTSUP,
3127 RTE_FLOW_ERROR_TYPE_ITEM, item,
3128 "Data mask is of unsupported size");
3130 /* Check GENEVE option is supported in NIC. */
3131 if (!hca_attr->geneve_tlv_opt)
3132 return rte_flow_error_set
3133 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
3134 "Geneve TLV opt not supported");
3135 /* Check if we already have geneve option with different type/class. */
3136 rte_spinlock_lock(&sh->geneve_tlv_opt_sl);
3137 geneve_opt_resource = sh->geneve_tlv_option_resource;
3138 if (geneve_opt_resource != NULL)
3139 if (geneve_opt_resource->option_class != spec->option_class ||
3140 geneve_opt_resource->option_type != spec->option_type ||
3141 geneve_opt_resource->length != spec->option_len) {
3142 rte_spinlock_unlock(&sh->geneve_tlv_opt_sl);
3143 return rte_flow_error_set(error, ENOTSUP,
3144 RTE_FLOW_ERROR_TYPE_ITEM, item,
3145 "Only one Geneve TLV option supported");
3147 rte_spinlock_unlock(&sh->geneve_tlv_opt_sl);
3152 * Validate MPLS item.
3155 * Pointer to the rte_eth_dev structure.
3157 * Item specification.
3158 * @param[in] item_flags
3159 * Bit-fields that holds the items detected until now.
3160 * @param[in] prev_layer
3161 * The protocol layer indicated in previous item.
3163 * Pointer to error structure.
3166 * 0 on success, a negative errno value otherwise and rte_errno is set.
3169 mlx5_flow_validate_item_mpls(struct rte_eth_dev *dev __rte_unused,
3170 const struct rte_flow_item *item __rte_unused,
3171 uint64_t item_flags __rte_unused,
3172 uint64_t prev_layer __rte_unused,
3173 struct rte_flow_error *error)
3175 #ifdef HAVE_IBV_DEVICE_MPLS_SUPPORT
3176 const struct rte_flow_item_mpls *mask = item->mask;
3177 struct mlx5_priv *priv = dev->data->dev_private;
3180 if (!priv->sh->dev_cap.mpls_en)
3181 return rte_flow_error_set(error, ENOTSUP,
3182 RTE_FLOW_ERROR_TYPE_ITEM, item,
3183 "MPLS not supported or"
3184 " disabled in firmware"
3186 /* MPLS over UDP, GRE is allowed */
3187 if (!(prev_layer & (MLX5_FLOW_LAYER_OUTER_L4_UDP |
3188 MLX5_FLOW_LAYER_GRE |
3189 MLX5_FLOW_LAYER_GRE_KEY)))
3190 return rte_flow_error_set(error, EINVAL,
3191 RTE_FLOW_ERROR_TYPE_ITEM, item,
3192 "protocol filtering not compatible"
3193 " with MPLS layer");
3194 /* Multi-tunnel isn't allowed but MPLS over GRE is an exception. */
3195 if ((item_flags & MLX5_FLOW_LAYER_TUNNEL) &&
3196 !(item_flags & MLX5_FLOW_LAYER_GRE))
3197 return rte_flow_error_set(error, ENOTSUP,
3198 RTE_FLOW_ERROR_TYPE_ITEM, item,
3199 "multiple tunnel layers not"
3202 mask = &rte_flow_item_mpls_mask;
3203 ret = mlx5_flow_item_acceptable
3204 (item, (const uint8_t *)mask,
3205 (const uint8_t *)&rte_flow_item_mpls_mask,
3206 sizeof(struct rte_flow_item_mpls),
3207 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
3212 return rte_flow_error_set(error, ENOTSUP,
3213 RTE_FLOW_ERROR_TYPE_ITEM, item,
3214 "MPLS is not supported by Verbs, please"
3220 * Validate NVGRE item.
3223 * Item specification.
3224 * @param[in] item_flags
3225 * Bit flags to mark detected items.
3226 * @param[in] target_protocol
3227 * The next protocol in the previous item.
3229 * Pointer to error structure.
3232 * 0 on success, a negative errno value otherwise and rte_errno is set.
3235 mlx5_flow_validate_item_nvgre(const struct rte_flow_item *item,
3236 uint64_t item_flags,
3237 uint8_t target_protocol,
3238 struct rte_flow_error *error)
3240 const struct rte_flow_item_nvgre *mask = item->mask;
3243 if (target_protocol != 0xff && target_protocol != IPPROTO_GRE)
3244 return rte_flow_error_set(error, EINVAL,
3245 RTE_FLOW_ERROR_TYPE_ITEM, item,
3246 "protocol filtering not compatible"
3247 " with this GRE layer");
3248 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
3249 return rte_flow_error_set(error, ENOTSUP,
3250 RTE_FLOW_ERROR_TYPE_ITEM, item,
3251 "multiple tunnel layers not"
3253 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3))
3254 return rte_flow_error_set(error, ENOTSUP,
3255 RTE_FLOW_ERROR_TYPE_ITEM, item,
3256 "L3 Layer is missing");
3258 mask = &rte_flow_item_nvgre_mask;
3259 ret = mlx5_flow_item_acceptable
3260 (item, (const uint8_t *)mask,
3261 (const uint8_t *)&rte_flow_item_nvgre_mask,
3262 sizeof(struct rte_flow_item_nvgre),
3263 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
3270 * Validate eCPRI item.
3273 * Item specification.
3274 * @param[in] item_flags
3275 * Bit-fields that holds the items detected until now.
3276 * @param[in] last_item
3277 * Previous validated item in the pattern items.
3278 * @param[in] ether_type
3279 * Type in the ethernet layer header (including dot1q).
3280 * @param[in] acc_mask
3281 * Acceptable mask, if NULL default internal default mask
3282 * will be used to check whether item fields are supported.
3284 * Pointer to error structure.
3287 * 0 on success, a negative errno value otherwise and rte_errno is set.
3290 mlx5_flow_validate_item_ecpri(const struct rte_flow_item *item,
3291 uint64_t item_flags,
3293 uint16_t ether_type,
3294 const struct rte_flow_item_ecpri *acc_mask,
3295 struct rte_flow_error *error)
3297 const struct rte_flow_item_ecpri *mask = item->mask;
3298 const struct rte_flow_item_ecpri nic_mask = {
3302 RTE_BE32(((const struct rte_ecpri_common_hdr) {
3306 .dummy[0] = 0xFFFFFFFF,
3309 const uint64_t outer_l2_vlan = (MLX5_FLOW_LAYER_OUTER_L2 |
3310 MLX5_FLOW_LAYER_OUTER_VLAN);
3311 struct rte_flow_item_ecpri mask_lo;
3313 if (!(last_item & outer_l2_vlan) &&
3314 last_item != MLX5_FLOW_LAYER_OUTER_L4_UDP)
3315 return rte_flow_error_set(error, EINVAL,
3316 RTE_FLOW_ERROR_TYPE_ITEM, item,
3317 "eCPRI can only follow L2/VLAN layer or UDP layer");
3318 if ((last_item & outer_l2_vlan) && ether_type &&
3319 ether_type != RTE_ETHER_TYPE_ECPRI)
3320 return rte_flow_error_set(error, EINVAL,
3321 RTE_FLOW_ERROR_TYPE_ITEM, item,
3322 "eCPRI cannot follow L2/VLAN layer which ether type is not 0xAEFE");
3323 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
3324 return rte_flow_error_set(error, EINVAL,
3325 RTE_FLOW_ERROR_TYPE_ITEM, item,
3326 "eCPRI with tunnel is not supported right now");
3327 if (item_flags & MLX5_FLOW_LAYER_OUTER_L3)
3328 return rte_flow_error_set(error, ENOTSUP,
3329 RTE_FLOW_ERROR_TYPE_ITEM, item,
3330 "multiple L3 layers not supported");
3331 else if (item_flags & MLX5_FLOW_LAYER_OUTER_L4_TCP)
3332 return rte_flow_error_set(error, EINVAL,
3333 RTE_FLOW_ERROR_TYPE_ITEM, item,
3334 "eCPRI cannot coexist with a TCP layer");
3335 /* In specification, eCPRI could be over UDP layer. */
3336 else if (item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP)
3337 return rte_flow_error_set(error, EINVAL,
3338 RTE_FLOW_ERROR_TYPE_ITEM, item,
3339 "eCPRI over UDP layer is not yet supported right now");
3340 /* Mask for type field in common header could be zero. */
3342 mask = &rte_flow_item_ecpri_mask;
3343 mask_lo.hdr.common.u32 = rte_be_to_cpu_32(mask->hdr.common.u32);
3344 /* Input mask is in big-endian format. */
3345 if (mask_lo.hdr.common.type != 0 && mask_lo.hdr.common.type != 0xff)
3346 return rte_flow_error_set(error, EINVAL,
3347 RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
3348 "partial mask is not supported for protocol");
3349 else if (mask_lo.hdr.common.type == 0 && mask->hdr.dummy[0] != 0)
3350 return rte_flow_error_set(error, EINVAL,
3351 RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
3352 "message header mask must be after a type mask");
3353 return mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
3354 acc_mask ? (const uint8_t *)acc_mask
3355 : (const uint8_t *)&nic_mask,
3356 sizeof(struct rte_flow_item_ecpri),
3357 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
3361 flow_null_validate(struct rte_eth_dev *dev __rte_unused,
3362 const struct rte_flow_attr *attr __rte_unused,
3363 const struct rte_flow_item items[] __rte_unused,
3364 const struct rte_flow_action actions[] __rte_unused,
3365 bool external __rte_unused,
3366 int hairpin __rte_unused,
3367 struct rte_flow_error *error)
3369 return rte_flow_error_set(error, ENOTSUP,
3370 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
3373 static struct mlx5_flow *
3374 flow_null_prepare(struct rte_eth_dev *dev __rte_unused,
3375 const struct rte_flow_attr *attr __rte_unused,
3376 const struct rte_flow_item items[] __rte_unused,
3377 const struct rte_flow_action actions[] __rte_unused,
3378 struct rte_flow_error *error)
3380 rte_flow_error_set(error, ENOTSUP,
3381 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
3386 flow_null_translate(struct rte_eth_dev *dev __rte_unused,
3387 struct mlx5_flow *dev_flow __rte_unused,
3388 const struct rte_flow_attr *attr __rte_unused,
3389 const struct rte_flow_item items[] __rte_unused,
3390 const struct rte_flow_action actions[] __rte_unused,
3391 struct rte_flow_error *error)
3393 return rte_flow_error_set(error, ENOTSUP,
3394 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
3398 flow_null_apply(struct rte_eth_dev *dev __rte_unused,
3399 struct rte_flow *flow __rte_unused,
3400 struct rte_flow_error *error)
3402 return rte_flow_error_set(error, ENOTSUP,
3403 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
3407 flow_null_remove(struct rte_eth_dev *dev __rte_unused,
3408 struct rte_flow *flow __rte_unused)
3413 flow_null_destroy(struct rte_eth_dev *dev __rte_unused,
3414 struct rte_flow *flow __rte_unused)
3419 flow_null_query(struct rte_eth_dev *dev __rte_unused,
3420 struct rte_flow *flow __rte_unused,
3421 const struct rte_flow_action *actions __rte_unused,
3422 void *data __rte_unused,
3423 struct rte_flow_error *error)
3425 return rte_flow_error_set(error, ENOTSUP,
3426 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
3430 flow_null_sync_domain(struct rte_eth_dev *dev __rte_unused,
3431 uint32_t domains __rte_unused,
3432 uint32_t flags __rte_unused)
3437 /* Void driver to protect from null pointer reference. */
3438 const struct mlx5_flow_driver_ops mlx5_flow_null_drv_ops = {
3439 .validate = flow_null_validate,
3440 .prepare = flow_null_prepare,
3441 .translate = flow_null_translate,
3442 .apply = flow_null_apply,
3443 .remove = flow_null_remove,
3444 .destroy = flow_null_destroy,
3445 .query = flow_null_query,
3446 .sync_domain = flow_null_sync_domain,
3450 * Select flow driver type according to flow attributes and device
3454 * Pointer to the dev structure.
3456 * Pointer to the flow attributes.
3459 * flow driver type, MLX5_FLOW_TYPE_MAX otherwise.
3461 static enum mlx5_flow_drv_type
3462 flow_get_drv_type(struct rte_eth_dev *dev, const struct rte_flow_attr *attr)
3464 struct mlx5_priv *priv = dev->data->dev_private;
3465 /* The OS can determine first a specific flow type (DV, VERBS) */
3466 enum mlx5_flow_drv_type type = mlx5_flow_os_get_type();
3468 if (type != MLX5_FLOW_TYPE_MAX)
3471 * Currently when dv_flow_en == 2, only HW steering engine is
3472 * supported. New engines can also be chosen here if ready.
3474 if (priv->sh->config.dv_flow_en == 2)
3475 return MLX5_FLOW_TYPE_HW;
3476 /* If no OS specific type - continue with DV/VERBS selection */
3477 if (attr->transfer && priv->sh->config.dv_esw_en)
3478 type = MLX5_FLOW_TYPE_DV;
3479 if (!attr->transfer)
3480 type = priv->sh->config.dv_flow_en ? MLX5_FLOW_TYPE_DV :
3481 MLX5_FLOW_TYPE_VERBS;
3485 #define flow_get_drv_ops(type) flow_drv_ops[type]
3488 * Flow driver validation API. This abstracts calling driver specific functions.
3489 * The type of flow driver is determined according to flow attributes.
3492 * Pointer to the dev structure.
3494 * Pointer to the flow attributes.
3496 * Pointer to the list of items.
3497 * @param[in] actions
3498 * Pointer to the list of actions.
3499 * @param[in] external
3500 * This flow rule is created by request external to PMD.
3501 * @param[in] hairpin
3502 * Number of hairpin TX actions, 0 means classic flow.
3504 * Pointer to the error structure.
3507 * 0 on success, a negative errno value otherwise and rte_errno is set.
3510 flow_drv_validate(struct rte_eth_dev *dev,
3511 const struct rte_flow_attr *attr,
3512 const struct rte_flow_item items[],
3513 const struct rte_flow_action actions[],
3514 bool external, int hairpin, struct rte_flow_error *error)
3516 const struct mlx5_flow_driver_ops *fops;
3517 enum mlx5_flow_drv_type type = flow_get_drv_type(dev, attr);
3519 fops = flow_get_drv_ops(type);
3520 return fops->validate(dev, attr, items, actions, external,
3525 * Flow driver preparation API. This abstracts calling driver specific
3526 * functions. Parent flow (rte_flow) should have driver type (drv_type). It
3527 * calculates the size of memory required for device flow, allocates the memory,
3528 * initializes the device flow and returns the pointer.
3531 * This function initializes device flow structure such as dv or verbs in
3532 * struct mlx5_flow. However, it is caller's responsibility to initialize the
3533 * rest. For example, adding returning device flow to flow->dev_flow list and
3534 * setting backward reference to the flow should be done out of this function.
3535 * layers field is not filled either.
3538 * Pointer to the dev structure.
3540 * Pointer to the flow attributes.
3542 * Pointer to the list of items.
3543 * @param[in] actions
3544 * Pointer to the list of actions.
3545 * @param[in] flow_idx
3546 * This memory pool index to the flow.
3548 * Pointer to the error structure.
3551 * Pointer to device flow on success, otherwise NULL and rte_errno is set.
3553 static inline struct mlx5_flow *
3554 flow_drv_prepare(struct rte_eth_dev *dev,
3555 const struct rte_flow *flow,
3556 const struct rte_flow_attr *attr,
3557 const struct rte_flow_item items[],
3558 const struct rte_flow_action actions[],
3560 struct rte_flow_error *error)
3562 const struct mlx5_flow_driver_ops *fops;
3563 enum mlx5_flow_drv_type type = flow->drv_type;
3564 struct mlx5_flow *mlx5_flow = NULL;
3566 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3567 fops = flow_get_drv_ops(type);
3568 mlx5_flow = fops->prepare(dev, attr, items, actions, error);
3570 mlx5_flow->flow_idx = flow_idx;
3575 * Flow driver translation API. This abstracts calling driver specific
3576 * functions. Parent flow (rte_flow) should have driver type (drv_type). It
3577 * translates a generic flow into a driver flow. flow_drv_prepare() must
3581 * dev_flow->layers could be filled as a result of parsing during translation
3582 * if needed by flow_drv_apply(). dev_flow->flow->actions can also be filled
3583 * if necessary. As a flow can have multiple dev_flows by RSS flow expansion,
3584 * flow->actions could be overwritten even though all the expanded dev_flows
3585 * have the same actions.
3588 * Pointer to the rte dev structure.
3589 * @param[in, out] dev_flow
3590 * Pointer to the mlx5 flow.
3592 * Pointer to the flow attributes.
3594 * Pointer to the list of items.
3595 * @param[in] actions
3596 * Pointer to the list of actions.
3598 * Pointer to the error structure.
3601 * 0 on success, a negative errno value otherwise and rte_errno is set.
3604 flow_drv_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
3605 const struct rte_flow_attr *attr,
3606 const struct rte_flow_item items[],
3607 const struct rte_flow_action actions[],
3608 struct rte_flow_error *error)
3610 const struct mlx5_flow_driver_ops *fops;
3611 enum mlx5_flow_drv_type type = dev_flow->flow->drv_type;
3613 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3614 fops = flow_get_drv_ops(type);
3615 return fops->translate(dev, dev_flow, attr, items, actions, error);
3619 * Flow driver apply API. This abstracts calling driver specific functions.
3620 * Parent flow (rte_flow) should have driver type (drv_type). It applies
3621 * translated driver flows on to device. flow_drv_translate() must precede.
3624 * Pointer to Ethernet device structure.
3625 * @param[in, out] flow
3626 * Pointer to flow structure.
3628 * Pointer to error structure.
3631 * 0 on success, a negative errno value otherwise and rte_errno is set.
3634 flow_drv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
3635 struct rte_flow_error *error)
3637 const struct mlx5_flow_driver_ops *fops;
3638 enum mlx5_flow_drv_type type = flow->drv_type;
3640 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3641 fops = flow_get_drv_ops(type);
3642 return fops->apply(dev, flow, error);
3646 * Flow driver destroy API. This abstracts calling driver specific functions.
3647 * Parent flow (rte_flow) should have driver type (drv_type). It removes a flow
3648 * on device and releases resources of the flow.
3651 * Pointer to Ethernet device.
3652 * @param[in, out] flow
3653 * Pointer to flow structure.
3656 flow_drv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
3658 const struct mlx5_flow_driver_ops *fops;
3659 enum mlx5_flow_drv_type type = flow->drv_type;
3661 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3662 fops = flow_get_drv_ops(type);
3663 fops->destroy(dev, flow);
3667 * Flow driver find RSS policy tbl API. This abstracts calling driver
3668 * specific functions. Parent flow (rte_flow) should have driver
3669 * type (drv_type). It will find the RSS policy table that has the rss_desc.
3672 * Pointer to Ethernet device.
3673 * @param[in, out] flow
3674 * Pointer to flow structure.
3676 * Pointer to meter policy table.
3677 * @param[in] rss_desc
3678 * Pointer to rss_desc
3680 static struct mlx5_flow_meter_sub_policy *
3681 flow_drv_meter_sub_policy_rss_prepare(struct rte_eth_dev *dev,
3682 struct rte_flow *flow,
3683 struct mlx5_flow_meter_policy *policy,
3684 struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS])
3686 const struct mlx5_flow_driver_ops *fops;
3687 enum mlx5_flow_drv_type type = flow->drv_type;
3689 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3690 fops = flow_get_drv_ops(type);
3691 return fops->meter_sub_policy_rss_prepare(dev, policy, rss_desc);
3695 * Flow driver color tag rule API. This abstracts calling driver
3696 * specific functions. Parent flow (rte_flow) should have driver
3697 * type (drv_type). It will create the color tag rules in hierarchy meter.
3700 * Pointer to Ethernet device.
3701 * @param[in, out] flow
3702 * Pointer to flow structure.
3704 * Pointer to flow meter structure.
3705 * @param[in] src_port
3706 * The src port this extra rule should use.
3708 * The src port id match item.
3710 * Pointer to error structure.
3713 flow_drv_mtr_hierarchy_rule_create(struct rte_eth_dev *dev,
3714 struct rte_flow *flow,
3715 struct mlx5_flow_meter_info *fm,
3717 const struct rte_flow_item *item,
3718 struct rte_flow_error *error)
3720 const struct mlx5_flow_driver_ops *fops;
3721 enum mlx5_flow_drv_type type = flow->drv_type;
3723 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3724 fops = flow_get_drv_ops(type);
3725 return fops->meter_hierarchy_rule_create(dev, fm,
3726 src_port, item, error);
3730 * Get RSS action from the action list.
3733 * Pointer to Ethernet device.
3734 * @param[in] actions
3735 * Pointer to the list of actions.
3737 * Parent flow structure pointer.
3740 * Pointer to the RSS action if exist, else return NULL.
3742 static const struct rte_flow_action_rss*
3743 flow_get_rss_action(struct rte_eth_dev *dev,
3744 const struct rte_flow_action actions[])
3746 struct mlx5_priv *priv = dev->data->dev_private;
3747 const struct rte_flow_action_rss *rss = NULL;
3748 struct mlx5_meter_policy_action_container *acg;
3749 struct mlx5_meter_policy_action_container *acy;
3751 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3752 switch (actions->type) {
3753 case RTE_FLOW_ACTION_TYPE_RSS:
3754 rss = actions->conf;
3756 case RTE_FLOW_ACTION_TYPE_SAMPLE:
3758 const struct rte_flow_action_sample *sample =
3760 const struct rte_flow_action *act = sample->actions;
3761 for (; act->type != RTE_FLOW_ACTION_TYPE_END; act++)
3762 if (act->type == RTE_FLOW_ACTION_TYPE_RSS)
3766 case RTE_FLOW_ACTION_TYPE_METER:
3769 struct mlx5_flow_meter_info *fm;
3770 struct mlx5_flow_meter_policy *policy;
3771 const struct rte_flow_action_meter *mtr = actions->conf;
3773 fm = mlx5_flow_meter_find(priv, mtr->mtr_id, &mtr_idx);
3774 if (fm && !fm->def_policy) {
3775 policy = mlx5_flow_meter_policy_find(dev,
3776 fm->policy_id, NULL);
3777 MLX5_ASSERT(policy);
3778 if (policy->is_hierarchy) {
3780 mlx5_flow_meter_hierarchy_get_final_policy(dev,
3785 if (policy->is_rss) {
3787 &policy->act_cnt[RTE_COLOR_GREEN];
3789 &policy->act_cnt[RTE_COLOR_YELLOW];
3790 if (acg->fate_action ==
3791 MLX5_FLOW_FATE_SHARED_RSS)
3792 rss = acg->rss->conf;
3793 else if (acy->fate_action ==
3794 MLX5_FLOW_FATE_SHARED_RSS)
3795 rss = acy->rss->conf;
3808 * Get ASO age action by index.
3811 * Pointer to the Ethernet device structure.
3812 * @param[in] age_idx
3813 * Index to the ASO age action.
3816 * The specified ASO age action.
3818 struct mlx5_aso_age_action*
3819 flow_aso_age_get_by_idx(struct rte_eth_dev *dev, uint32_t age_idx)
3821 uint16_t pool_idx = age_idx & UINT16_MAX;
3822 uint16_t offset = (age_idx >> 16) & UINT16_MAX;
3823 struct mlx5_priv *priv = dev->data->dev_private;
3824 struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
3825 struct mlx5_aso_age_pool *pool;
3827 rte_rwlock_read_lock(&mng->resize_rwl);
3828 pool = mng->pools[pool_idx];
3829 rte_rwlock_read_unlock(&mng->resize_rwl);
3830 return &pool->actions[offset - 1];
3833 /* maps indirect action to translated direct in some actions array */
3834 struct mlx5_translated_action_handle {
3835 struct rte_flow_action_handle *action; /**< Indirect action handle. */
3836 int index; /**< Index in related array of rte_flow_action. */
3840 * Translates actions of type RTE_FLOW_ACTION_TYPE_INDIRECT to related
3841 * direct action if translation possible.
3842 * This functionality used to run same execution path for both direct and
3843 * indirect actions on flow create. All necessary preparations for indirect
3844 * action handling should be performed on *handle* actions list returned
3848 * Pointer to Ethernet device.
3849 * @param[in] actions
3850 * List of actions to translate.
3851 * @param[out] handle
3852 * List to store translated indirect action object handles.
3853 * @param[in, out] indir_n
3854 * Size of *handle* array. On return should be updated with number of
3855 * indirect actions retrieved from the *actions* list.
3856 * @param[out] translated_actions
3857 * List of actions where all indirect actions were translated to direct
3858 * if possible. NULL if no translation took place.
3860 * Pointer to the error structure.
3863 * 0 on success, a negative errno value otherwise and rte_errno is set.
3866 flow_action_handles_translate(struct rte_eth_dev *dev,
3867 const struct rte_flow_action actions[],
3868 struct mlx5_translated_action_handle *handle,
3870 struct rte_flow_action **translated_actions,
3871 struct rte_flow_error *error)
3873 struct mlx5_priv *priv = dev->data->dev_private;
3874 struct rte_flow_action *translated = NULL;
3875 size_t actions_size;
3878 struct mlx5_translated_action_handle *handle_end = NULL;
3880 for (n = 0; actions[n].type != RTE_FLOW_ACTION_TYPE_END; n++) {
3881 if (actions[n].type != RTE_FLOW_ACTION_TYPE_INDIRECT)
3883 if (copied_n == *indir_n) {
3884 return rte_flow_error_set
3885 (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION_NUM,
3886 NULL, "too many shared actions");
3888 rte_memcpy(&handle[copied_n].action, &actions[n].conf,
3889 sizeof(actions[n].conf));
3890 handle[copied_n].index = n;
3894 *indir_n = copied_n;
3897 actions_size = sizeof(struct rte_flow_action) * n;
3898 translated = mlx5_malloc(MLX5_MEM_ZERO, actions_size, 0, SOCKET_ID_ANY);
3903 memcpy(translated, actions, actions_size);
3904 for (handle_end = handle + copied_n; handle < handle_end; handle++) {
3905 struct mlx5_shared_action_rss *shared_rss;
3906 uint32_t act_idx = (uint32_t)(uintptr_t)handle->action;
3907 uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
3908 uint32_t idx = act_idx &
3909 ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
3912 case MLX5_INDIRECT_ACTION_TYPE_RSS:
3913 shared_rss = mlx5_ipool_get
3914 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
3915 translated[handle->index].type =
3916 RTE_FLOW_ACTION_TYPE_RSS;
3917 translated[handle->index].conf =
3918 &shared_rss->origin;
3920 case MLX5_INDIRECT_ACTION_TYPE_COUNT:
3921 translated[handle->index].type =
3922 (enum rte_flow_action_type)
3923 MLX5_RTE_FLOW_ACTION_TYPE_COUNT;
3924 translated[handle->index].conf = (void *)(uintptr_t)idx;
3926 case MLX5_INDIRECT_ACTION_TYPE_AGE:
3927 if (priv->sh->flow_hit_aso_en) {
3928 translated[handle->index].type =
3929 (enum rte_flow_action_type)
3930 MLX5_RTE_FLOW_ACTION_TYPE_AGE;
3931 translated[handle->index].conf =
3932 (void *)(uintptr_t)idx;
3936 case MLX5_INDIRECT_ACTION_TYPE_CT:
3937 if (priv->sh->ct_aso_en) {
3938 translated[handle->index].type =
3939 RTE_FLOW_ACTION_TYPE_CONNTRACK;
3940 translated[handle->index].conf =
3941 (void *)(uintptr_t)idx;
3946 mlx5_free(translated);
3947 return rte_flow_error_set
3948 (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
3949 NULL, "invalid indirect action type");
3952 *translated_actions = translated;
3957 * Get Shared RSS action from the action list.
3960 * Pointer to Ethernet device.
3962 * Pointer to the list of actions.
3963 * @param[in] shared_n
3964 * Actions list length.
3967 * The MLX5 RSS action ID if exists, otherwise return 0.
3970 flow_get_shared_rss_action(struct rte_eth_dev *dev,
3971 struct mlx5_translated_action_handle *handle,
3974 struct mlx5_translated_action_handle *handle_end;
3975 struct mlx5_priv *priv = dev->data->dev_private;
3976 struct mlx5_shared_action_rss *shared_rss;
3979 for (handle_end = handle + shared_n; handle < handle_end; handle++) {
3980 uint32_t act_idx = (uint32_t)(uintptr_t)handle->action;
3981 uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
3982 uint32_t idx = act_idx &
3983 ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
3985 case MLX5_INDIRECT_ACTION_TYPE_RSS:
3986 shared_rss = mlx5_ipool_get
3987 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
3989 __atomic_add_fetch(&shared_rss->refcnt, 1,
4000 find_graph_root(uint32_t rss_level)
4002 return rss_level < 2 ? MLX5_EXPANSION_ROOT :
4003 MLX5_EXPANSION_ROOT_OUTER;
4007 * Get layer flags from the prefix flow.
4009 * Some flows may be split to several subflows, the prefix subflow gets the
4010 * match items and the suffix sub flow gets the actions.
4011 * Some actions need the user defined match item flags to get the detail for
4013 * This function helps the suffix flow to get the item layer flags from prefix
4016 * @param[in] dev_flow
4017 * Pointer the created prefix subflow.
4020 * The layers get from prefix subflow.
4022 static inline uint64_t
4023 flow_get_prefix_layer_flags(struct mlx5_flow *dev_flow)
4025 uint64_t layers = 0;
4028 * Layers bits could be localization, but usually the compiler will
4029 * help to do the optimization work for source code.
4030 * If no decap actions, use the layers directly.
4032 if (!(dev_flow->act_flags & MLX5_FLOW_ACTION_DECAP))
4033 return dev_flow->handle->layers;
4034 /* Convert L3 layers with decap action. */
4035 if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L3_IPV4)
4036 layers |= MLX5_FLOW_LAYER_OUTER_L3_IPV4;
4037 else if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L3_IPV6)
4038 layers |= MLX5_FLOW_LAYER_OUTER_L3_IPV6;
4039 /* Convert L4 layers with decap action. */
4040 if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L4_TCP)
4041 layers |= MLX5_FLOW_LAYER_OUTER_L4_TCP;
4042 else if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L4_UDP)
4043 layers |= MLX5_FLOW_LAYER_OUTER_L4_UDP;
4048 * Get metadata split action information.
4050 * @param[in] actions
4051 * Pointer to the list of actions.
4053 * Pointer to the return pointer.
4054 * @param[out] qrss_type
4055 * Pointer to the action type to return. RTE_FLOW_ACTION_TYPE_END is returned
4056 * if no QUEUE/RSS is found.
4057 * @param[out] encap_idx
4058 * Pointer to the index of the encap action if exists, otherwise the last
4062 * Total number of actions.
4065 flow_parse_metadata_split_actions_info(const struct rte_flow_action actions[],
4066 const struct rte_flow_action **qrss,
4069 const struct rte_flow_action_raw_encap *raw_encap;
4071 int raw_decap_idx = -1;
4074 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4075 switch (actions->type) {
4076 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
4077 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
4078 *encap_idx = actions_n;
4080 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
4081 raw_decap_idx = actions_n;
4083 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
4084 raw_encap = actions->conf;
4085 if (raw_encap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
4086 *encap_idx = raw_decap_idx != -1 ?
4087 raw_decap_idx : actions_n;
4089 case RTE_FLOW_ACTION_TYPE_QUEUE:
4090 case RTE_FLOW_ACTION_TYPE_RSS:
4098 if (*encap_idx == -1)
4099 *encap_idx = actions_n;
4100 /* Count RTE_FLOW_ACTION_TYPE_END. */
4101 return actions_n + 1;
4105 * Check if the action will change packet.
4108 * Pointer to Ethernet device.
4113 * true if action will change packet, false otherwise.
4115 static bool flow_check_modify_action_type(struct rte_eth_dev *dev,
4116 enum rte_flow_action_type type)
4118 struct mlx5_priv *priv = dev->data->dev_private;
4121 case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
4122 case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
4123 case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
4124 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
4125 case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
4126 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
4127 case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
4128 case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
4129 case RTE_FLOW_ACTION_TYPE_DEC_TTL:
4130 case RTE_FLOW_ACTION_TYPE_SET_TTL:
4131 case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
4132 case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
4133 case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
4134 case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
4135 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
4136 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
4137 case RTE_FLOW_ACTION_TYPE_SET_META:
4138 case RTE_FLOW_ACTION_TYPE_SET_TAG:
4139 case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
4140 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
4141 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
4142 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
4143 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
4144 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
4145 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
4146 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
4147 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
4148 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
4149 case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
4151 case RTE_FLOW_ACTION_TYPE_FLAG:
4152 case RTE_FLOW_ACTION_TYPE_MARK:
4153 if (priv->sh->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY)
4163 * Check meter action from the action list.
4166 * Pointer to Ethernet device.
4167 * @param[in] actions
4168 * Pointer to the list of actions.
4169 * @param[out] has_mtr
4170 * Pointer to the meter exist flag.
4171 * @param[out] has_modify
4172 * Pointer to the flag showing there's packet change action.
4173 * @param[out] meter_id
4174 * Pointer to the meter id.
4177 * Total number of actions.
4180 flow_check_meter_action(struct rte_eth_dev *dev,
4181 const struct rte_flow_action actions[],
4182 bool *has_mtr, bool *has_modify, uint32_t *meter_id)
4184 const struct rte_flow_action_meter *mtr = NULL;
4187 MLX5_ASSERT(has_mtr);
4189 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4190 switch (actions->type) {
4191 case RTE_FLOW_ACTION_TYPE_METER:
4192 mtr = actions->conf;
4193 *meter_id = mtr->mtr_id;
4200 *has_modify |= flow_check_modify_action_type(dev,
4204 /* Count RTE_FLOW_ACTION_TYPE_END. */
4205 return actions_n + 1;
4209 * Check if the flow should be split due to hairpin.
4210 * The reason for the split is that in current HW we can't
4211 * support encap and push-vlan on Rx, so if a flow contains
4212 * these actions we move it to Tx.
4215 * Pointer to Ethernet device.
4217 * Flow rule attributes.
4218 * @param[in] actions
4219 * Associated actions (list terminated by the END action).
4222 * > 0 the number of actions and the flow should be split,
4223 * 0 when no split required.
4226 flow_check_hairpin_split(struct rte_eth_dev *dev,
4227 const struct rte_flow_attr *attr,
4228 const struct rte_flow_action actions[])
4230 int queue_action = 0;
4233 const struct rte_flow_action_queue *queue;
4234 const struct rte_flow_action_rss *rss;
4235 const struct rte_flow_action_raw_encap *raw_encap;
4236 const struct rte_eth_hairpin_conf *conf;
4240 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4241 switch (actions->type) {
4242 case RTE_FLOW_ACTION_TYPE_QUEUE:
4243 queue = actions->conf;
4246 conf = mlx5_rxq_get_hairpin_conf(dev, queue->index);
4247 if (conf == NULL || conf->tx_explicit != 0)
4252 case RTE_FLOW_ACTION_TYPE_RSS:
4253 rss = actions->conf;
4254 if (rss == NULL || rss->queue_num == 0)
4256 conf = mlx5_rxq_get_hairpin_conf(dev, rss->queue[0]);
4257 if (conf == NULL || conf->tx_explicit != 0)
4262 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
4263 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
4264 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
4265 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
4266 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
4270 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
4271 raw_encap = actions->conf;
4272 if (raw_encap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
4281 if (split && queue_action)
4286 /* Declare flow create/destroy prototype in advance. */
4288 flow_list_create(struct rte_eth_dev *dev, enum mlx5_flow_type type,
4289 const struct rte_flow_attr *attr,
4290 const struct rte_flow_item items[],
4291 const struct rte_flow_action actions[],
4292 bool external, struct rte_flow_error *error);
4295 flow_list_destroy(struct rte_eth_dev *dev, enum mlx5_flow_type type,
4299 flow_dv_mreg_match_cb(void *tool_ctx __rte_unused,
4300 struct mlx5_list_entry *entry, void *cb_ctx)
4302 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4303 struct mlx5_flow_mreg_copy_resource *mcp_res =
4304 container_of(entry, typeof(*mcp_res), hlist_ent);
4306 return mcp_res->mark_id != *(uint32_t *)(ctx->data);
4309 struct mlx5_list_entry *
4310 flow_dv_mreg_create_cb(void *tool_ctx, void *cb_ctx)
4312 struct rte_eth_dev *dev = tool_ctx;
4313 struct mlx5_priv *priv = dev->data->dev_private;
4314 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4315 struct mlx5_flow_mreg_copy_resource *mcp_res;
4316 struct rte_flow_error *error = ctx->error;
4319 uint32_t mark_id = *(uint32_t *)(ctx->data);
4320 struct rte_flow_attr attr = {
4321 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
4324 struct mlx5_rte_flow_item_tag tag_spec = {
4327 struct rte_flow_item items[] = {
4328 [1] = { .type = RTE_FLOW_ITEM_TYPE_END, },
4330 struct rte_flow_action_mark ftag = {
4333 struct mlx5_flow_action_copy_mreg cp_mreg = {
4337 struct rte_flow_action_jump jump = {
4338 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
4340 struct rte_flow_action actions[] = {
4341 [3] = { .type = RTE_FLOW_ACTION_TYPE_END, },
4344 /* Fill the register fields in the flow. */
4345 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
4349 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_RX, 0, error);
4353 /* Provide the full width of FLAG specific value. */
4354 if (mark_id == (priv->sh->dv_regc0_mask & MLX5_FLOW_MARK_DEFAULT))
4355 tag_spec.data = MLX5_FLOW_MARK_DEFAULT;
4356 /* Build a new flow. */
4357 if (mark_id != MLX5_DEFAULT_COPY_ID) {
4358 items[0] = (struct rte_flow_item){
4359 .type = (enum rte_flow_item_type)
4360 MLX5_RTE_FLOW_ITEM_TYPE_TAG,
4363 items[1] = (struct rte_flow_item){
4364 .type = RTE_FLOW_ITEM_TYPE_END,
4366 actions[0] = (struct rte_flow_action){
4367 .type = (enum rte_flow_action_type)
4368 MLX5_RTE_FLOW_ACTION_TYPE_MARK,
4371 actions[1] = (struct rte_flow_action){
4372 .type = (enum rte_flow_action_type)
4373 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
4376 actions[2] = (struct rte_flow_action){
4377 .type = RTE_FLOW_ACTION_TYPE_JUMP,
4380 actions[3] = (struct rte_flow_action){
4381 .type = RTE_FLOW_ACTION_TYPE_END,
4384 /* Default rule, wildcard match. */
4385 attr.priority = MLX5_FLOW_LOWEST_PRIO_INDICATOR;
4386 items[0] = (struct rte_flow_item){
4387 .type = RTE_FLOW_ITEM_TYPE_END,
4389 actions[0] = (struct rte_flow_action){
4390 .type = (enum rte_flow_action_type)
4391 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
4394 actions[1] = (struct rte_flow_action){
4395 .type = RTE_FLOW_ACTION_TYPE_JUMP,
4398 actions[2] = (struct rte_flow_action){
4399 .type = RTE_FLOW_ACTION_TYPE_END,
4402 /* Build a new entry. */
4403 mcp_res = mlx5_ipool_zmalloc(priv->sh->ipool[MLX5_IPOOL_MCP], &idx);
4409 mcp_res->mark_id = mark_id;
4411 * The copy Flows are not included in any list. There
4412 * ones are referenced from other Flows and can not
4413 * be applied, removed, deleted in arbitrary order
4414 * by list traversing.
4416 mcp_res->rix_flow = flow_list_create(dev, MLX5_FLOW_TYPE_MCP,
4417 &attr, items, actions, false, error);
4418 if (!mcp_res->rix_flow) {
4419 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], idx);
4422 return &mcp_res->hlist_ent;
4425 struct mlx5_list_entry *
4426 flow_dv_mreg_clone_cb(void *tool_ctx, struct mlx5_list_entry *oentry,
4427 void *cb_ctx __rte_unused)
4429 struct rte_eth_dev *dev = tool_ctx;
4430 struct mlx5_priv *priv = dev->data->dev_private;
4431 struct mlx5_flow_mreg_copy_resource *mcp_res;
4434 mcp_res = mlx5_ipool_malloc(priv->sh->ipool[MLX5_IPOOL_MCP], &idx);
4439 memcpy(mcp_res, oentry, sizeof(*mcp_res));
4441 return &mcp_res->hlist_ent;
4445 flow_dv_mreg_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
4447 struct mlx5_flow_mreg_copy_resource *mcp_res =
4448 container_of(entry, typeof(*mcp_res), hlist_ent);
4449 struct rte_eth_dev *dev = tool_ctx;
4450 struct mlx5_priv *priv = dev->data->dev_private;
4452 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], mcp_res->idx);
4456 * Add a flow of copying flow metadata registers in RX_CP_TBL.
4458 * As mark_id is unique, if there's already a registered flow for the mark_id,
4459 * return by increasing the reference counter of the resource. Otherwise, create
4460 * the resource (mcp_res) and flow.
4463 * - If ingress port is ANY and reg_c[1] is mark_id,
4464 * flow_tag := mark_id, reg_b := reg_c[0] and jump to RX_ACT_TBL.
4466 * For default flow (zero mark_id), flow is like,
4467 * - If ingress port is ANY,
4468 * reg_b := reg_c[0] and jump to RX_ACT_TBL.
4471 * Pointer to Ethernet device.
4473 * ID of MARK action, zero means default flow for META.
4475 * Perform verbose error reporting if not NULL.
4478 * Associated resource on success, NULL otherwise and rte_errno is set.
4480 static struct mlx5_flow_mreg_copy_resource *
4481 flow_mreg_add_copy_action(struct rte_eth_dev *dev, uint32_t mark_id,
4482 struct rte_flow_error *error)
4484 struct mlx5_priv *priv = dev->data->dev_private;
4485 struct mlx5_list_entry *entry;
4486 struct mlx5_flow_cb_ctx ctx = {
4492 /* Check if already registered. */
4493 MLX5_ASSERT(priv->mreg_cp_tbl);
4494 entry = mlx5_hlist_register(priv->mreg_cp_tbl, mark_id, &ctx);
4497 return container_of(entry, struct mlx5_flow_mreg_copy_resource,
4502 flow_dv_mreg_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
4504 struct mlx5_flow_mreg_copy_resource *mcp_res =
4505 container_of(entry, typeof(*mcp_res), hlist_ent);
4506 struct rte_eth_dev *dev = tool_ctx;
4507 struct mlx5_priv *priv = dev->data->dev_private;
4509 MLX5_ASSERT(mcp_res->rix_flow);
4510 flow_list_destroy(dev, MLX5_FLOW_TYPE_MCP, mcp_res->rix_flow);
4511 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], mcp_res->idx);
4515 * Release flow in RX_CP_TBL.
4518 * Pointer to Ethernet device.
4520 * Parent flow for wich copying is provided.
4523 flow_mreg_del_copy_action(struct rte_eth_dev *dev,
4524 struct rte_flow *flow)
4526 struct mlx5_flow_mreg_copy_resource *mcp_res;
4527 struct mlx5_priv *priv = dev->data->dev_private;
4529 if (!flow->rix_mreg_copy)
4531 mcp_res = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MCP],
4532 flow->rix_mreg_copy);
4533 if (!mcp_res || !priv->mreg_cp_tbl)
4535 MLX5_ASSERT(mcp_res->rix_flow);
4536 mlx5_hlist_unregister(priv->mreg_cp_tbl, &mcp_res->hlist_ent);
4537 flow->rix_mreg_copy = 0;
4541 * Remove the default copy action from RX_CP_TBL.
4543 * This functions is called in the mlx5_dev_start(). No thread safe
4547 * Pointer to Ethernet device.
4550 flow_mreg_del_default_copy_action(struct rte_eth_dev *dev)
4552 struct mlx5_list_entry *entry;
4553 struct mlx5_priv *priv = dev->data->dev_private;
4554 struct mlx5_flow_cb_ctx ctx;
4557 /* Check if default flow is registered. */
4558 if (!priv->mreg_cp_tbl)
4560 mark_id = MLX5_DEFAULT_COPY_ID;
4561 ctx.data = &mark_id;
4562 entry = mlx5_hlist_lookup(priv->mreg_cp_tbl, mark_id, &ctx);
4565 mlx5_hlist_unregister(priv->mreg_cp_tbl, entry);
4569 * Add the default copy action in in RX_CP_TBL.
4571 * This functions is called in the mlx5_dev_start(). No thread safe
4575 * Pointer to Ethernet device.
4577 * Perform verbose error reporting if not NULL.
4580 * 0 for success, negative value otherwise and rte_errno is set.
4583 flow_mreg_add_default_copy_action(struct rte_eth_dev *dev,
4584 struct rte_flow_error *error)
4586 struct mlx5_priv *priv = dev->data->dev_private;
4587 struct mlx5_flow_mreg_copy_resource *mcp_res;
4588 struct mlx5_flow_cb_ctx ctx;
4591 /* Check whether extensive metadata feature is engaged. */
4592 if (!priv->sh->config.dv_flow_en ||
4593 priv->sh->config.dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
4594 !mlx5_flow_ext_mreg_supported(dev) ||
4595 !priv->sh->dv_regc0_mask)
4598 * Add default mreg copy flow may be called multiple time, but
4599 * only be called once in stop. Avoid register it twice.
4601 mark_id = MLX5_DEFAULT_COPY_ID;
4602 ctx.data = &mark_id;
4603 if (mlx5_hlist_lookup(priv->mreg_cp_tbl, mark_id, &ctx))
4605 mcp_res = flow_mreg_add_copy_action(dev, mark_id, error);
4612 * Add a flow of copying flow metadata registers in RX_CP_TBL.
4614 * All the flow having Q/RSS action should be split by
4615 * flow_mreg_split_qrss_prep() to pass by RX_CP_TBL. A flow in the RX_CP_TBL
4616 * performs the following,
4617 * - CQE->flow_tag := reg_c[1] (MARK)
4618 * - CQE->flow_table_metadata (reg_b) := reg_c[0] (META)
4619 * As CQE's flow_tag is not a register, it can't be simply copied from reg_c[1]
4620 * but there should be a flow per each MARK ID set by MARK action.
4622 * For the aforementioned reason, if there's a MARK action in flow's action
4623 * list, a corresponding flow should be added to the RX_CP_TBL in order to copy
4624 * the MARK ID to CQE's flow_tag like,
4625 * - If reg_c[1] is mark_id,
4626 * flow_tag := mark_id, reg_b := reg_c[0] and jump to RX_ACT_TBL.
4628 * For SET_META action which stores value in reg_c[0], as the destination is
4629 * also a flow metadata register (reg_b), adding a default flow is enough. Zero
4630 * MARK ID means the default flow. The default flow looks like,
4631 * - For all flow, reg_b := reg_c[0] and jump to RX_ACT_TBL.
4634 * Pointer to Ethernet device.
4636 * Pointer to flow structure.
4637 * @param[in] actions
4638 * Pointer to the list of actions.
4640 * Perform verbose error reporting if not NULL.
4643 * 0 on success, negative value otherwise and rte_errno is set.
4646 flow_mreg_update_copy_table(struct rte_eth_dev *dev,
4647 struct rte_flow *flow,
4648 const struct rte_flow_action *actions,
4649 struct rte_flow_error *error)
4651 struct mlx5_priv *priv = dev->data->dev_private;
4652 struct mlx5_sh_config *config = &priv->sh->config;
4653 struct mlx5_flow_mreg_copy_resource *mcp_res;
4654 const struct rte_flow_action_mark *mark;
4656 /* Check whether extensive metadata feature is engaged. */
4657 if (!config->dv_flow_en ||
4658 config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
4659 !mlx5_flow_ext_mreg_supported(dev) ||
4660 !priv->sh->dv_regc0_mask)
4662 /* Find MARK action. */
4663 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4664 switch (actions->type) {
4665 case RTE_FLOW_ACTION_TYPE_FLAG:
4666 mcp_res = flow_mreg_add_copy_action
4667 (dev, MLX5_FLOW_MARK_DEFAULT, error);
4670 flow->rix_mreg_copy = mcp_res->idx;
4672 case RTE_FLOW_ACTION_TYPE_MARK:
4673 mark = (const struct rte_flow_action_mark *)
4676 flow_mreg_add_copy_action(dev, mark->id, error);
4679 flow->rix_mreg_copy = mcp_res->idx;
4688 #define MLX5_MAX_SPLIT_ACTIONS 24
4689 #define MLX5_MAX_SPLIT_ITEMS 24
4692 * Split the hairpin flow.
4693 * Since HW can't support encap and push-vlan on Rx, we move these
4695 * If the count action is after the encap then we also
4696 * move the count action. in this case the count will also measure
4700 * Pointer to Ethernet device.
4701 * @param[in] actions
4702 * Associated actions (list terminated by the END action).
4703 * @param[out] actions_rx
4705 * @param[out] actions_tx
4707 * @param[out] pattern_tx
4708 * The pattern items for the Tx flow.
4709 * @param[out] flow_id
4710 * The flow ID connected to this flow.
4716 flow_hairpin_split(struct rte_eth_dev *dev,
4717 const struct rte_flow_action actions[],
4718 struct rte_flow_action actions_rx[],
4719 struct rte_flow_action actions_tx[],
4720 struct rte_flow_item pattern_tx[],
4723 const struct rte_flow_action_raw_encap *raw_encap;
4724 const struct rte_flow_action_raw_decap *raw_decap;
4725 struct mlx5_rte_flow_action_set_tag *set_tag;
4726 struct rte_flow_action *tag_action;
4727 struct mlx5_rte_flow_item_tag *tag_item;
4728 struct rte_flow_item *item;
4732 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4733 switch (actions->type) {
4734 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
4735 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
4736 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
4737 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
4738 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
4739 rte_memcpy(actions_tx, actions,
4740 sizeof(struct rte_flow_action));
4743 case RTE_FLOW_ACTION_TYPE_COUNT:
4745 rte_memcpy(actions_tx, actions,
4746 sizeof(struct rte_flow_action));
4749 rte_memcpy(actions_rx, actions,
4750 sizeof(struct rte_flow_action));
4754 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
4755 raw_encap = actions->conf;
4756 if (raw_encap->size > MLX5_ENCAPSULATION_DECISION_SIZE) {
4757 memcpy(actions_tx, actions,
4758 sizeof(struct rte_flow_action));
4762 rte_memcpy(actions_rx, actions,
4763 sizeof(struct rte_flow_action));
4767 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
4768 raw_decap = actions->conf;
4769 if (raw_decap->size < MLX5_ENCAPSULATION_DECISION_SIZE) {
4770 memcpy(actions_tx, actions,
4771 sizeof(struct rte_flow_action));
4774 rte_memcpy(actions_rx, actions,
4775 sizeof(struct rte_flow_action));
4780 rte_memcpy(actions_rx, actions,
4781 sizeof(struct rte_flow_action));
4786 /* Add set meta action and end action for the Rx flow. */
4787 tag_action = actions_rx;
4788 tag_action->type = (enum rte_flow_action_type)
4789 MLX5_RTE_FLOW_ACTION_TYPE_TAG;
4791 rte_memcpy(actions_rx, actions, sizeof(struct rte_flow_action));
4793 set_tag = (void *)actions_rx;
4794 *set_tag = (struct mlx5_rte_flow_action_set_tag) {
4795 .id = mlx5_flow_get_reg_id(dev, MLX5_HAIRPIN_RX, 0, NULL),
4798 MLX5_ASSERT(set_tag->id > REG_NON);
4799 tag_action->conf = set_tag;
4800 /* Create Tx item list. */
4801 rte_memcpy(actions_tx, actions, sizeof(struct rte_flow_action));
4802 addr = (void *)&pattern_tx[2];
4804 item->type = (enum rte_flow_item_type)
4805 MLX5_RTE_FLOW_ITEM_TYPE_TAG;
4806 tag_item = (void *)addr;
4807 tag_item->data = flow_id;
4808 tag_item->id = mlx5_flow_get_reg_id(dev, MLX5_HAIRPIN_TX, 0, NULL);
4809 MLX5_ASSERT(set_tag->id > REG_NON);
4810 item->spec = tag_item;
4811 addr += sizeof(struct mlx5_rte_flow_item_tag);
4812 tag_item = (void *)addr;
4813 tag_item->data = UINT32_MAX;
4814 tag_item->id = UINT16_MAX;
4815 item->mask = tag_item;
4818 item->type = RTE_FLOW_ITEM_TYPE_END;
4823 * The last stage of splitting chain, just creates the subflow
4824 * without any modification.
4827 * Pointer to Ethernet device.
4829 * Parent flow structure pointer.
4830 * @param[in, out] sub_flow
4831 * Pointer to return the created subflow, may be NULL.
4833 * Flow rule attributes.
4835 * Pattern specification (list terminated by the END pattern item).
4836 * @param[in] actions
4837 * Associated actions (list terminated by the END action).
4838 * @param[in] flow_split_info
4839 * Pointer to flow split info structure.
4841 * Perform verbose error reporting if not NULL.
4843 * 0 on success, negative value otherwise
4846 flow_create_split_inner(struct rte_eth_dev *dev,
4847 struct rte_flow *flow,
4848 struct mlx5_flow **sub_flow,
4849 const struct rte_flow_attr *attr,
4850 const struct rte_flow_item items[],
4851 const struct rte_flow_action actions[],
4852 struct mlx5_flow_split_info *flow_split_info,
4853 struct rte_flow_error *error)
4855 struct mlx5_flow *dev_flow;
4856 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
4858 dev_flow = flow_drv_prepare(dev, flow, attr, items, actions,
4859 flow_split_info->flow_idx, error);
4862 dev_flow->flow = flow;
4863 dev_flow->external = flow_split_info->external;
4864 dev_flow->skip_scale = flow_split_info->skip_scale;
4865 /* Subflow object was created, we must include one in the list. */
4866 SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
4867 dev_flow->handle, next);
4869 * If dev_flow is as one of the suffix flow, some actions in suffix
4870 * flow may need some user defined item layer flags, and pass the
4871 * Metadata rxq mark flag to suffix flow as well.
4873 if (flow_split_info->prefix_layers)
4874 dev_flow->handle->layers = flow_split_info->prefix_layers;
4875 if (flow_split_info->prefix_mark) {
4880 *sub_flow = dev_flow;
4881 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
4882 dev_flow->dv.table_id = flow_split_info->table_id;
4884 return flow_drv_translate(dev, dev_flow, attr, items, actions, error);
4888 * Get the sub policy of a meter.
4891 * Pointer to Ethernet device.
4893 * Parent flow structure pointer.
4895 * Pointer to thread flow work space.
4897 * Flow rule attributes.
4899 * Pattern specification (list terminated by the END pattern item).
4901 * Perform verbose error reporting if not NULL.
4904 * Pointer to the meter sub policy, NULL otherwise and rte_errno is set.
4906 static struct mlx5_flow_meter_sub_policy *
4907 get_meter_sub_policy(struct rte_eth_dev *dev,
4908 struct rte_flow *flow,
4909 struct mlx5_flow_workspace *wks,
4910 const struct rte_flow_attr *attr,
4911 const struct rte_flow_item items[],
4912 struct rte_flow_error *error)
4914 struct mlx5_flow_meter_policy *policy;
4915 struct mlx5_flow_meter_policy *final_policy;
4916 struct mlx5_flow_meter_sub_policy *sub_policy = NULL;
4918 policy = wks->policy;
4919 final_policy = policy->is_hierarchy ? wks->final_policy : policy;
4920 if (final_policy->is_rss || final_policy->is_queue) {
4921 struct mlx5_flow_rss_desc rss_desc_v[MLX5_MTR_RTE_COLORS];
4922 struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS] = {0};
4926 * This is a tmp dev_flow,
4927 * no need to register any matcher for it in translate.
4929 wks->skip_matcher_reg = 1;
4930 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
4931 struct mlx5_flow dev_flow = {0};
4932 struct mlx5_flow_handle dev_handle = { {0} };
4933 uint8_t fate = final_policy->act_cnt[i].fate_action;
4935 if (fate == MLX5_FLOW_FATE_SHARED_RSS) {
4936 const struct rte_flow_action_rss *rss_act =
4937 final_policy->act_cnt[i].rss->conf;
4938 struct rte_flow_action rss_actions[2] = {
4940 .type = RTE_FLOW_ACTION_TYPE_RSS,
4944 .type = RTE_FLOW_ACTION_TYPE_END,
4949 dev_flow.handle = &dev_handle;
4950 dev_flow.ingress = attr->ingress;
4951 dev_flow.flow = flow;
4952 dev_flow.external = 0;
4953 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
4954 dev_flow.dv.transfer = attr->transfer;
4957 * Translate RSS action to get rss hash fields.
4959 if (flow_drv_translate(dev, &dev_flow, attr,
4960 items, rss_actions, error))
4962 rss_desc_v[i] = wks->rss_desc;
4963 rss_desc_v[i].key_len = MLX5_RSS_HASH_KEY_LEN;
4964 rss_desc_v[i].hash_fields =
4965 dev_flow.hash_fields;
4966 rss_desc_v[i].queue_num =
4967 rss_desc_v[i].hash_fields ?
4968 rss_desc_v[i].queue_num : 1;
4969 rss_desc_v[i].tunnel =
4970 !!(dev_flow.handle->layers &
4971 MLX5_FLOW_LAYER_TUNNEL);
4972 /* Use the RSS queues in the containers. */
4973 rss_desc_v[i].queue =
4974 (uint16_t *)(uintptr_t)rss_act->queue;
4975 rss_desc[i] = &rss_desc_v[i];
4976 } else if (fate == MLX5_FLOW_FATE_QUEUE) {
4977 /* This is queue action. */
4978 rss_desc_v[i] = wks->rss_desc;
4979 rss_desc_v[i].key_len = 0;
4980 rss_desc_v[i].hash_fields = 0;
4981 rss_desc_v[i].queue =
4982 &final_policy->act_cnt[i].queue;
4983 rss_desc_v[i].queue_num = 1;
4984 rss_desc[i] = &rss_desc_v[i];
4989 sub_policy = flow_drv_meter_sub_policy_rss_prepare(dev,
4990 flow, policy, rss_desc);
4992 enum mlx5_meter_domain mtr_domain =
4993 attr->transfer ? MLX5_MTR_DOMAIN_TRANSFER :
4994 (attr->egress ? MLX5_MTR_DOMAIN_EGRESS :
4995 MLX5_MTR_DOMAIN_INGRESS);
4996 sub_policy = policy->sub_policys[mtr_domain][0];
4999 rte_flow_error_set(error, EINVAL,
5000 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
5001 "Failed to get meter sub-policy.");
5007 * Split the meter flow.
5009 * As meter flow will split to three sub flow, other than meter
5010 * action, the other actions make sense to only meter accepts
5011 * the packet. If it need to be dropped, no other additional
5012 * actions should be take.
5014 * One kind of special action which decapsulates the L3 tunnel
5015 * header will be in the prefix sub flow, as not to take the
5016 * L3 tunnel header into account.
5019 * Pointer to Ethernet device.
5021 * Parent flow structure pointer.
5023 * Pointer to thread flow work space.
5025 * Flow rule attributes.
5027 * Pattern specification (list terminated by the END pattern item).
5028 * @param[out] sfx_items
5029 * Suffix flow match items (list terminated by the END pattern item).
5030 * @param[in] actions
5031 * Associated actions (list terminated by the END action).
5032 * @param[out] actions_sfx
5033 * Suffix flow actions.
5034 * @param[out] actions_pre
5035 * Prefix flow actions.
5036 * @param[out] mtr_flow_id
5037 * Pointer to meter flow id.
5039 * Perform verbose error reporting if not NULL.
5042 * 0 on success, a negative errno value otherwise and rte_errno is set.
5045 flow_meter_split_prep(struct rte_eth_dev *dev,
5046 struct rte_flow *flow,
5047 struct mlx5_flow_workspace *wks,
5048 const struct rte_flow_attr *attr,
5049 const struct rte_flow_item items[],
5050 struct rte_flow_item sfx_items[],
5051 const struct rte_flow_action actions[],
5052 struct rte_flow_action actions_sfx[],
5053 struct rte_flow_action actions_pre[],
5054 uint32_t *mtr_flow_id,
5055 struct rte_flow_error *error)
5057 struct mlx5_priv *priv = dev->data->dev_private;
5058 struct mlx5_flow_meter_info *fm = wks->fm;
5059 struct rte_flow_action *tag_action = NULL;
5060 struct rte_flow_item *tag_item;
5061 struct mlx5_rte_flow_action_set_tag *set_tag;
5062 const struct rte_flow_action_raw_encap *raw_encap;
5063 const struct rte_flow_action_raw_decap *raw_decap;
5064 struct mlx5_rte_flow_item_tag *tag_item_spec;
5065 struct mlx5_rte_flow_item_tag *tag_item_mask;
5066 uint32_t tag_id = 0;
5067 struct rte_flow_item *vlan_item_dst = NULL;
5068 const struct rte_flow_item *vlan_item_src = NULL;
5069 const struct rte_flow_item *orig_items = items;
5070 struct rte_flow_action *hw_mtr_action;
5071 struct rte_flow_action *action_pre_head = NULL;
5072 int32_t flow_src_port = priv->representor_id;
5074 uint8_t mtr_id_offset = priv->mtr_reg_share ? MLX5_MTR_COLOR_BITS : 0;
5075 uint8_t mtr_reg_bits = priv->mtr_reg_share ?
5076 MLX5_MTR_IDLE_BITS_IN_COLOR_REG : MLX5_REG_BITS;
5077 uint32_t flow_id = 0;
5078 uint32_t flow_id_reversed = 0;
5079 uint8_t flow_id_bits = 0;
5082 /* Prepare the suffix subflow items. */
5083 tag_item = sfx_items++;
5084 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
5085 struct mlx5_priv *port_priv;
5086 const struct rte_flow_item_port_id *pid_v;
5087 int item_type = items->type;
5089 switch (item_type) {
5090 case RTE_FLOW_ITEM_TYPE_PORT_ID:
5091 pid_v = items->spec;
5093 port_priv = mlx5_port_to_eswitch_info(pid_v->id, false);
5095 return rte_flow_error_set(error,
5097 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
5099 "Failed to get port info.");
5100 flow_src_port = port_priv->representor_id;
5101 if (!fm->def_policy && wks->policy->is_hierarchy &&
5102 flow_src_port != priv->representor_id) {
5103 if (flow_drv_mtr_hierarchy_rule_create(dev,
5110 memcpy(sfx_items, items, sizeof(*sfx_items));
5113 case RTE_FLOW_ITEM_TYPE_VLAN:
5114 /* Determine if copy vlan item below. */
5115 vlan_item_src = items;
5116 vlan_item_dst = sfx_items++;
5117 vlan_item_dst->type = RTE_FLOW_ITEM_TYPE_VOID;
5123 sfx_items->type = RTE_FLOW_ITEM_TYPE_END;
5125 mtr_first = priv->sh->meter_aso_en &&
5126 (attr->egress || (attr->transfer && flow_src_port != UINT16_MAX));
5127 /* For ASO meter, meter must be before tag in TX direction. */
5129 action_pre_head = actions_pre++;
5130 /* Leave space for tag action. */
5131 tag_action = actions_pre++;
5133 /* Prepare the actions for prefix and suffix flow. */
5134 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
5135 struct rte_flow_action *action_cur = NULL;
5137 switch (actions->type) {
5138 case RTE_FLOW_ACTION_TYPE_METER:
5140 action_cur = action_pre_head;
5142 /* Leave space for tag action. */
5143 tag_action = actions_pre++;
5144 action_cur = actions_pre++;
5147 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
5148 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
5149 action_cur = actions_pre++;
5151 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
5152 raw_encap = actions->conf;
5153 if (raw_encap->size < MLX5_ENCAPSULATION_DECISION_SIZE)
5154 action_cur = actions_pre++;
5156 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
5157 raw_decap = actions->conf;
5158 if (raw_decap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
5159 action_cur = actions_pre++;
5161 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
5162 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
5163 if (vlan_item_dst && vlan_item_src) {
5164 memcpy(vlan_item_dst, vlan_item_src,
5165 sizeof(*vlan_item_dst));
5167 * Convert to internal match item, it is used
5168 * for vlan push and set vid.
5170 vlan_item_dst->type = (enum rte_flow_item_type)
5171 MLX5_RTE_FLOW_ITEM_TYPE_VLAN;
5178 action_cur = (fm->def_policy) ?
5179 actions_sfx++ : actions_pre++;
5180 memcpy(action_cur, actions, sizeof(struct rte_flow_action));
5182 /* Add end action to the actions. */
5183 actions_sfx->type = RTE_FLOW_ACTION_TYPE_END;
5184 if (priv->sh->meter_aso_en) {
5186 * For ASO meter, need to add an extra jump action explicitly,
5187 * to jump from meter to policer table.
5189 struct mlx5_flow_meter_sub_policy *sub_policy;
5190 struct mlx5_flow_tbl_data_entry *tbl_data;
5192 if (!fm->def_policy) {
5193 sub_policy = get_meter_sub_policy(dev, flow, wks,
5199 enum mlx5_meter_domain mtr_domain =
5200 attr->transfer ? MLX5_MTR_DOMAIN_TRANSFER :
5201 (attr->egress ? MLX5_MTR_DOMAIN_EGRESS :
5202 MLX5_MTR_DOMAIN_INGRESS);
5205 &priv->sh->mtrmng->def_policy[mtr_domain]->sub_policy;
5207 tbl_data = container_of(sub_policy->tbl_rsc,
5208 struct mlx5_flow_tbl_data_entry, tbl);
5209 hw_mtr_action = actions_pre++;
5210 hw_mtr_action->type = (enum rte_flow_action_type)
5211 MLX5_RTE_FLOW_ACTION_TYPE_JUMP;
5212 hw_mtr_action->conf = tbl_data->jump.action;
5214 actions_pre->type = RTE_FLOW_ACTION_TYPE_END;
5217 return rte_flow_error_set(error, ENOMEM,
5218 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5219 NULL, "No tag action space.");
5221 tag_action->type = RTE_FLOW_ACTION_TYPE_VOID;
5224 /* Only default-policy Meter creates mtr flow id. */
5225 if (fm->def_policy) {
5226 mlx5_ipool_malloc(fm->flow_ipool, &tag_id);
5228 return rte_flow_error_set(error, ENOMEM,
5229 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
5230 "Failed to allocate meter flow id.");
5231 flow_id = tag_id - 1;
5232 flow_id_bits = (!flow_id) ? 1 :
5233 (MLX5_REG_BITS - __builtin_clz(flow_id));
5234 if ((flow_id_bits + priv->sh->mtrmng->max_mtr_bits) >
5236 mlx5_ipool_free(fm->flow_ipool, tag_id);
5237 return rte_flow_error_set(error, EINVAL,
5238 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
5239 "Meter flow id exceeds max limit.");
5241 if (flow_id_bits > priv->sh->mtrmng->max_mtr_flow_bits)
5242 priv->sh->mtrmng->max_mtr_flow_bits = flow_id_bits;
5244 /* Build tag actions and items for meter_id/meter flow_id. */
5245 set_tag = (struct mlx5_rte_flow_action_set_tag *)actions_pre;
5246 tag_item_spec = (struct mlx5_rte_flow_item_tag *)sfx_items;
5247 tag_item_mask = tag_item_spec + 1;
5248 /* Both flow_id and meter_id share the same register. */
5249 *set_tag = (struct mlx5_rte_flow_action_set_tag) {
5250 .id = (enum modify_reg)mlx5_flow_get_reg_id(dev, MLX5_MTR_ID,
5252 .offset = mtr_id_offset,
5253 .length = mtr_reg_bits,
5254 .data = flow->meter,
5257 * The color Reg bits used by flow_id are growing from
5258 * msb to lsb, so must do bit reverse for flow_id val in RegC.
5260 for (shift = 0; shift < flow_id_bits; shift++)
5261 flow_id_reversed = (flow_id_reversed << 1) |
5262 ((flow_id >> shift) & 0x1);
5264 flow_id_reversed << (mtr_reg_bits - flow_id_bits);
5265 tag_item_spec->id = set_tag->id;
5266 tag_item_spec->data = set_tag->data << mtr_id_offset;
5267 tag_item_mask->data = UINT32_MAX << mtr_id_offset;
5268 tag_action->type = (enum rte_flow_action_type)
5269 MLX5_RTE_FLOW_ACTION_TYPE_TAG;
5270 tag_action->conf = set_tag;
5271 tag_item->type = (enum rte_flow_item_type)
5272 MLX5_RTE_FLOW_ITEM_TYPE_TAG;
5273 tag_item->spec = tag_item_spec;
5274 tag_item->last = NULL;
5275 tag_item->mask = tag_item_mask;
5278 *mtr_flow_id = tag_id;
5283 * Split action list having QUEUE/RSS for metadata register copy.
5285 * Once Q/RSS action is detected in user's action list, the flow action
5286 * should be split in order to copy metadata registers, which will happen in
5288 * - CQE->flow_tag := reg_c[1] (MARK)
5289 * - CQE->flow_table_metadata (reg_b) := reg_c[0] (META)
5290 * The Q/RSS action will be performed on RX_ACT_TBL after passing by RX_CP_TBL.
5291 * This is because the last action of each flow must be a terminal action
5292 * (QUEUE, RSS or DROP).
5294 * Flow ID must be allocated to identify actions in the RX_ACT_TBL and it is
5295 * stored and kept in the mlx5_flow structure per each sub_flow.
5297 * The Q/RSS action is replaced with,
5298 * - SET_TAG, setting the allocated flow ID to reg_c[2].
5299 * And the following JUMP action is added at the end,
5300 * - JUMP, to RX_CP_TBL.
5302 * A flow to perform remained Q/RSS action will be created in RX_ACT_TBL by
5303 * flow_create_split_metadata() routine. The flow will look like,
5304 * - If flow ID matches (reg_c[2]), perform Q/RSS.
5307 * Pointer to Ethernet device.
5308 * @param[out] split_actions
5309 * Pointer to store split actions to jump to CP_TBL.
5310 * @param[in] actions
5311 * Pointer to the list of original flow actions.
5313 * Pointer to the Q/RSS action.
5314 * @param[in] actions_n
5315 * Number of original actions.
5316 * @param[in] mtr_sfx
5317 * Check if it is in meter suffix table.
5319 * Perform verbose error reporting if not NULL.
5322 * non-zero unique flow_id on success, otherwise 0 and
5323 * error/rte_error are set.
5326 flow_mreg_split_qrss_prep(struct rte_eth_dev *dev,
5327 struct rte_flow_action *split_actions,
5328 const struct rte_flow_action *actions,
5329 const struct rte_flow_action *qrss,
5330 int actions_n, int mtr_sfx,
5331 struct rte_flow_error *error)
5333 struct mlx5_priv *priv = dev->data->dev_private;
5334 struct mlx5_rte_flow_action_set_tag *set_tag;
5335 struct rte_flow_action_jump *jump;
5336 const int qrss_idx = qrss - actions;
5337 uint32_t flow_id = 0;
5341 * Given actions will be split
5342 * - Replace QUEUE/RSS action with SET_TAG to set flow ID.
5343 * - Add jump to mreg CP_TBL.
5344 * As a result, there will be one more action.
5346 memcpy(split_actions, actions, sizeof(*split_actions) * actions_n);
5347 /* Count MLX5_RTE_FLOW_ACTION_TYPE_TAG. */
5349 set_tag = (void *)(split_actions + actions_n);
5351 * If we are not the meter suffix flow, add the tag action.
5352 * Since meter suffix flow already has the tag added.
5356 * Allocate the new subflow ID. This one is unique within
5357 * device and not shared with representors. Otherwise,
5358 * we would have to resolve multi-thread access synch
5359 * issue. Each flow on the shared device is appended
5360 * with source vport identifier, so the resulting
5361 * flows will be unique in the shared (by master and
5362 * representors) domain even if they have coinciding
5365 mlx5_ipool_malloc(priv->sh->ipool
5366 [MLX5_IPOOL_RSS_EXPANTION_FLOW_ID], &flow_id);
5368 return rte_flow_error_set(error, ENOMEM,
5369 RTE_FLOW_ERROR_TYPE_ACTION,
5370 NULL, "can't allocate id "
5371 "for split Q/RSS subflow");
5372 /* Internal SET_TAG action to set flow ID. */
5373 *set_tag = (struct mlx5_rte_flow_action_set_tag){
5376 ret = mlx5_flow_get_reg_id(dev, MLX5_COPY_MARK, 0, error);
5380 /* Construct new actions array. */
5381 /* Replace QUEUE/RSS action. */
5382 split_actions[qrss_idx] = (struct rte_flow_action){
5383 .type = (enum rte_flow_action_type)
5384 MLX5_RTE_FLOW_ACTION_TYPE_TAG,
5389 * If we are the suffix flow of meter, tag already exist.
5390 * Set the QUEUE/RSS action to void.
5392 split_actions[qrss_idx].type = RTE_FLOW_ACTION_TYPE_VOID;
5394 /* JUMP action to jump to mreg copy table (CP_TBL). */
5395 jump = (void *)(set_tag + 1);
5396 *jump = (struct rte_flow_action_jump){
5397 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
5399 split_actions[actions_n - 2] = (struct rte_flow_action){
5400 .type = RTE_FLOW_ACTION_TYPE_JUMP,
5403 split_actions[actions_n - 1] = (struct rte_flow_action){
5404 .type = RTE_FLOW_ACTION_TYPE_END,
5410 * Extend the given action list for Tx metadata copy.
5412 * Copy the given action list to the ext_actions and add flow metadata register
5413 * copy action in order to copy reg_a set by WQE to reg_c[0].
5415 * @param[out] ext_actions
5416 * Pointer to the extended action list.
5417 * @param[in] actions
5418 * Pointer to the list of actions.
5419 * @param[in] actions_n
5420 * Number of actions in the list.
5422 * Perform verbose error reporting if not NULL.
5423 * @param[in] encap_idx
5424 * The encap action index.
5427 * 0 on success, negative value otherwise
5430 flow_mreg_tx_copy_prep(struct rte_eth_dev *dev,
5431 struct rte_flow_action *ext_actions,
5432 const struct rte_flow_action *actions,
5433 int actions_n, struct rte_flow_error *error,
5436 struct mlx5_flow_action_copy_mreg *cp_mreg =
5437 (struct mlx5_flow_action_copy_mreg *)
5438 (ext_actions + actions_n + 1);
5441 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_RX, 0, error);
5445 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_TX, 0, error);
5450 memcpy(ext_actions, actions, sizeof(*ext_actions) * encap_idx);
5451 if (encap_idx == actions_n - 1) {
5452 ext_actions[actions_n - 1] = (struct rte_flow_action){
5453 .type = (enum rte_flow_action_type)
5454 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
5457 ext_actions[actions_n] = (struct rte_flow_action){
5458 .type = RTE_FLOW_ACTION_TYPE_END,
5461 ext_actions[encap_idx] = (struct rte_flow_action){
5462 .type = (enum rte_flow_action_type)
5463 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
5466 memcpy(ext_actions + encap_idx + 1, actions + encap_idx,
5467 sizeof(*ext_actions) * (actions_n - encap_idx));
5473 * Check the match action from the action list.
5475 * @param[in] actions
5476 * Pointer to the list of actions.
5478 * Flow rule attributes.
5480 * The action to be check if exist.
5481 * @param[out] match_action_pos
5482 * Pointer to the position of the matched action if exists, otherwise is -1.
5483 * @param[out] qrss_action_pos
5484 * Pointer to the position of the Queue/RSS action if exists, otherwise is -1.
5485 * @param[out] modify_after_mirror
5486 * Pointer to the flag of modify action after FDB mirroring.
5489 * > 0 the total number of actions.
5490 * 0 if not found match action in action list.
5493 flow_check_match_action(const struct rte_flow_action actions[],
5494 const struct rte_flow_attr *attr,
5495 enum rte_flow_action_type action,
5496 int *match_action_pos, int *qrss_action_pos,
5497 int *modify_after_mirror)
5499 const struct rte_flow_action_sample *sample;
5500 const struct rte_flow_action_raw_decap *decap;
5507 *match_action_pos = -1;
5508 *qrss_action_pos = -1;
5509 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
5510 if (actions->type == action) {
5512 *match_action_pos = actions_n;
5514 switch (actions->type) {
5515 case RTE_FLOW_ACTION_TYPE_QUEUE:
5516 case RTE_FLOW_ACTION_TYPE_RSS:
5517 *qrss_action_pos = actions_n;
5519 case RTE_FLOW_ACTION_TYPE_SAMPLE:
5520 sample = actions->conf;
5521 ratio = sample->ratio;
5522 sub_type = ((const struct rte_flow_action *)
5523 (sample->actions))->type;
5524 if (ratio == 1 && attr->transfer)
5527 case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
5528 case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
5529 case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
5530 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
5531 case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
5532 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
5533 case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
5534 case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
5535 case RTE_FLOW_ACTION_TYPE_DEC_TTL:
5536 case RTE_FLOW_ACTION_TYPE_SET_TTL:
5537 case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
5538 case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
5539 case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
5540 case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
5541 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
5542 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
5543 case RTE_FLOW_ACTION_TYPE_FLAG:
5544 case RTE_FLOW_ACTION_TYPE_MARK:
5545 case RTE_FLOW_ACTION_TYPE_SET_META:
5546 case RTE_FLOW_ACTION_TYPE_SET_TAG:
5547 case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
5548 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
5549 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
5550 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
5551 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
5552 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
5553 case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
5554 case RTE_FLOW_ACTION_TYPE_METER:
5556 *modify_after_mirror = 1;
5558 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
5559 decap = actions->conf;
5560 while ((++actions)->type == RTE_FLOW_ACTION_TYPE_VOID)
5563 if (actions->type == RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
5564 const struct rte_flow_action_raw_encap *encap =
5567 MLX5_ENCAPSULATION_DECISION_SIZE &&
5569 MLX5_ENCAPSULATION_DECISION_SIZE)
5574 *modify_after_mirror = 1;
5581 if (flag && fdb_mirror && !*modify_after_mirror) {
5582 /* FDB mirroring uses the destination array to implement
5583 * instead of FLOW_SAMPLER object.
5585 if (sub_type != RTE_FLOW_ACTION_TYPE_END)
5588 /* Count RTE_FLOW_ACTION_TYPE_END. */
5589 return flag ? actions_n + 1 : 0;
5592 #define SAMPLE_SUFFIX_ITEM 2
5595 * Split the sample flow.
5597 * As sample flow will split to two sub flow, sample flow with
5598 * sample action, the other actions will move to new suffix flow.
5600 * Also add unique tag id with tag action in the sample flow,
5601 * the same tag id will be as match in the suffix flow.
5604 * Pointer to Ethernet device.
5605 * @param[in] add_tag
5606 * Add extra tag action flag.
5607 * @param[out] sfx_items
5608 * Suffix flow match items (list terminated by the END pattern item).
5609 * @param[in] actions
5610 * Associated actions (list terminated by the END action).
5611 * @param[out] actions_sfx
5612 * Suffix flow actions.
5613 * @param[out] actions_pre
5614 * Prefix flow actions.
5615 * @param[in] actions_n
5616 * The total number of actions.
5617 * @param[in] sample_action_pos
5618 * The sample action position.
5619 * @param[in] qrss_action_pos
5620 * The Queue/RSS action position.
5621 * @param[in] jump_table
5622 * Add extra jump action flag.
5624 * Perform verbose error reporting if not NULL.
5627 * 0 on success, or unique flow_id, a negative errno value
5628 * otherwise and rte_errno is set.
5631 flow_sample_split_prep(struct rte_eth_dev *dev,
5633 struct rte_flow_item sfx_items[],
5634 const struct rte_flow_action actions[],
5635 struct rte_flow_action actions_sfx[],
5636 struct rte_flow_action actions_pre[],
5638 int sample_action_pos,
5639 int qrss_action_pos,
5641 struct rte_flow_error *error)
5643 struct mlx5_priv *priv = dev->data->dev_private;
5644 struct mlx5_rte_flow_action_set_tag *set_tag;
5645 struct mlx5_rte_flow_item_tag *tag_spec;
5646 struct mlx5_rte_flow_item_tag *tag_mask;
5647 struct rte_flow_action_jump *jump_action;
5648 uint32_t tag_id = 0;
5650 int append_index = 0;
5653 if (sample_action_pos < 0)
5654 return rte_flow_error_set(error, EINVAL,
5655 RTE_FLOW_ERROR_TYPE_ACTION,
5656 NULL, "invalid position of sample "
5658 /* Prepare the actions for prefix and suffix flow. */
5659 if (qrss_action_pos >= 0 && qrss_action_pos < sample_action_pos) {
5660 index = qrss_action_pos;
5661 /* Put the preceding the Queue/RSS action into prefix flow. */
5663 memcpy(actions_pre, actions,
5664 sizeof(struct rte_flow_action) * index);
5665 /* Put others preceding the sample action into prefix flow. */
5666 if (sample_action_pos > index + 1)
5667 memcpy(actions_pre + index, actions + index + 1,
5668 sizeof(struct rte_flow_action) *
5669 (sample_action_pos - index - 1));
5670 index = sample_action_pos - 1;
5671 /* Put Queue/RSS action into Suffix flow. */
5672 memcpy(actions_sfx, actions + qrss_action_pos,
5673 sizeof(struct rte_flow_action));
5676 index = sample_action_pos;
5678 memcpy(actions_pre, actions,
5679 sizeof(struct rte_flow_action) * index);
5681 /* For CX5, add an extra tag action for NIC-RX and E-Switch ingress.
5682 * For CX6DX and above, metadata registers Cx preserve their value,
5683 * add an extra tag action for NIC-RX and E-Switch Domain.
5686 /* Prepare the prefix tag action. */
5688 set_tag = (void *)(actions_pre + actions_n + append_index);
5689 ret = mlx5_flow_get_reg_id(dev, MLX5_SAMPLE_ID, 0, error);
5692 mlx5_ipool_malloc(priv->sh->ipool
5693 [MLX5_IPOOL_RSS_EXPANTION_FLOW_ID], &tag_id);
5694 *set_tag = (struct mlx5_rte_flow_action_set_tag) {
5698 /* Prepare the suffix subflow items. */
5699 tag_spec = (void *)(sfx_items + SAMPLE_SUFFIX_ITEM);
5700 tag_spec->data = tag_id;
5701 tag_spec->id = set_tag->id;
5702 tag_mask = tag_spec + 1;
5703 tag_mask->data = UINT32_MAX;
5704 sfx_items[0] = (struct rte_flow_item){
5705 .type = (enum rte_flow_item_type)
5706 MLX5_RTE_FLOW_ITEM_TYPE_TAG,
5711 sfx_items[1] = (struct rte_flow_item){
5712 .type = (enum rte_flow_item_type)
5713 RTE_FLOW_ITEM_TYPE_END,
5715 /* Prepare the tag action in prefix subflow. */
5716 actions_pre[index++] =
5717 (struct rte_flow_action){
5718 .type = (enum rte_flow_action_type)
5719 MLX5_RTE_FLOW_ACTION_TYPE_TAG,
5723 memcpy(actions_pre + index, actions + sample_action_pos,
5724 sizeof(struct rte_flow_action));
5726 /* For the modify action after the sample action in E-Switch mirroring,
5727 * Add the extra jump action in prefix subflow and jump into the next
5728 * table, then do the modify action in the new table.
5731 /* Prepare the prefix jump action. */
5733 jump_action = (void *)(actions_pre + actions_n + append_index);
5734 jump_action->group = jump_table;
5735 actions_pre[index++] =
5736 (struct rte_flow_action){
5737 .type = (enum rte_flow_action_type)
5738 RTE_FLOW_ACTION_TYPE_JUMP,
5739 .conf = jump_action,
5742 actions_pre[index] = (struct rte_flow_action){
5743 .type = (enum rte_flow_action_type)
5744 RTE_FLOW_ACTION_TYPE_END,
5746 /* Put the actions after sample into Suffix flow. */
5747 memcpy(actions_sfx, actions + sample_action_pos + 1,
5748 sizeof(struct rte_flow_action) *
5749 (actions_n - sample_action_pos - 1));
5754 * The splitting for metadata feature.
5756 * - Q/RSS action on NIC Rx should be split in order to pass by
5757 * the mreg copy table (RX_CP_TBL) and then it jumps to the
5758 * action table (RX_ACT_TBL) which has the split Q/RSS action.
5760 * - All the actions on NIC Tx should have a mreg copy action to
5761 * copy reg_a from WQE to reg_c[0].
5764 * Pointer to Ethernet device.
5766 * Parent flow structure pointer.
5768 * Flow rule attributes.
5770 * Pattern specification (list terminated by the END pattern item).
5771 * @param[in] actions
5772 * Associated actions (list terminated by the END action).
5773 * @param[in] flow_split_info
5774 * Pointer to flow split info structure.
5776 * Perform verbose error reporting if not NULL.
5778 * 0 on success, negative value otherwise
5781 flow_create_split_metadata(struct rte_eth_dev *dev,
5782 struct rte_flow *flow,
5783 const struct rte_flow_attr *attr,
5784 const struct rte_flow_item items[],
5785 const struct rte_flow_action actions[],
5786 struct mlx5_flow_split_info *flow_split_info,
5787 struct rte_flow_error *error)
5789 struct mlx5_priv *priv = dev->data->dev_private;
5790 struct mlx5_sh_config *config = &priv->sh->config;
5791 const struct rte_flow_action *qrss = NULL;
5792 struct rte_flow_action *ext_actions = NULL;
5793 struct mlx5_flow *dev_flow = NULL;
5794 uint32_t qrss_id = 0;
5801 /* Check whether extensive metadata feature is engaged. */
5802 if (!config->dv_flow_en ||
5803 config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
5804 !mlx5_flow_ext_mreg_supported(dev))
5805 return flow_create_split_inner(dev, flow, NULL, attr, items,
5806 actions, flow_split_info, error);
5807 actions_n = flow_parse_metadata_split_actions_info(actions, &qrss,
5810 /* Exclude hairpin flows from splitting. */
5811 if (qrss->type == RTE_FLOW_ACTION_TYPE_QUEUE) {
5812 const struct rte_flow_action_queue *queue;
5815 if (mlx5_rxq_get_type(dev, queue->index) ==
5816 MLX5_RXQ_TYPE_HAIRPIN)
5818 } else if (qrss->type == RTE_FLOW_ACTION_TYPE_RSS) {
5819 const struct rte_flow_action_rss *rss;
5822 if (mlx5_rxq_get_type(dev, rss->queue[0]) ==
5823 MLX5_RXQ_TYPE_HAIRPIN)
5828 /* Check if it is in meter suffix table. */
5829 mtr_sfx = attr->group == (attr->transfer ?
5830 (MLX5_FLOW_TABLE_LEVEL_METER - 1) :
5831 MLX5_FLOW_TABLE_LEVEL_METER);
5833 * Q/RSS action on NIC Rx should be split in order to pass by
5834 * the mreg copy table (RX_CP_TBL) and then it jumps to the
5835 * action table (RX_ACT_TBL) which has the split Q/RSS action.
5837 act_size = sizeof(struct rte_flow_action) * (actions_n + 1) +
5838 sizeof(struct rte_flow_action_set_tag) +
5839 sizeof(struct rte_flow_action_jump);
5840 ext_actions = mlx5_malloc(MLX5_MEM_ZERO, act_size, 0,
5843 return rte_flow_error_set(error, ENOMEM,
5844 RTE_FLOW_ERROR_TYPE_ACTION,
5845 NULL, "no memory to split "
5848 * Create the new actions list with removed Q/RSS action
5849 * and appended set tag and jump to register copy table
5850 * (RX_CP_TBL). We should preallocate unique tag ID here
5851 * in advance, because it is needed for set tag action.
5853 qrss_id = flow_mreg_split_qrss_prep(dev, ext_actions, actions,
5856 if (!mtr_sfx && !qrss_id) {
5860 } else if (attr->egress && !attr->transfer) {
5862 * All the actions on NIC Tx should have a metadata register
5863 * copy action to copy reg_a from WQE to reg_c[meta]
5865 act_size = sizeof(struct rte_flow_action) * (actions_n + 1) +
5866 sizeof(struct mlx5_flow_action_copy_mreg);
5867 ext_actions = mlx5_malloc(MLX5_MEM_ZERO, act_size, 0,
5870 return rte_flow_error_set(error, ENOMEM,
5871 RTE_FLOW_ERROR_TYPE_ACTION,
5872 NULL, "no memory to split "
5874 /* Create the action list appended with copy register. */
5875 ret = flow_mreg_tx_copy_prep(dev, ext_actions, actions,
5876 actions_n, error, encap_idx);
5880 /* Add the unmodified original or prefix subflow. */
5881 ret = flow_create_split_inner(dev, flow, &dev_flow, attr,
5882 items, ext_actions ? ext_actions :
5883 actions, flow_split_info, error);
5886 MLX5_ASSERT(dev_flow);
5888 const struct rte_flow_attr q_attr = {
5889 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
5892 /* Internal PMD action to set register. */
5893 struct mlx5_rte_flow_item_tag q_tag_spec = {
5897 struct rte_flow_item q_items[] = {
5899 .type = (enum rte_flow_item_type)
5900 MLX5_RTE_FLOW_ITEM_TYPE_TAG,
5901 .spec = &q_tag_spec,
5906 .type = RTE_FLOW_ITEM_TYPE_END,
5909 struct rte_flow_action q_actions[] = {
5915 .type = RTE_FLOW_ACTION_TYPE_END,
5918 uint64_t layers = flow_get_prefix_layer_flags(dev_flow);
5921 * Configure the tag item only if there is no meter subflow.
5922 * Since tag is already marked in the meter suffix subflow
5923 * we can just use the meter suffix items as is.
5926 /* Not meter subflow. */
5927 MLX5_ASSERT(!mtr_sfx);
5929 * Put unique id in prefix flow due to it is destroyed
5930 * after suffix flow and id will be freed after there
5931 * is no actual flows with this id and identifier
5932 * reallocation becomes possible (for example, for
5933 * other flows in other threads).
5935 dev_flow->handle->split_flow_id = qrss_id;
5936 ret = mlx5_flow_get_reg_id(dev, MLX5_COPY_MARK, 0,
5940 q_tag_spec.id = ret;
5943 /* Add suffix subflow to execute Q/RSS. */
5944 flow_split_info->prefix_layers = layers;
5945 flow_split_info->prefix_mark = 0;
5946 flow_split_info->table_id = 0;
5947 ret = flow_create_split_inner(dev, flow, &dev_flow,
5948 &q_attr, mtr_sfx ? items :
5950 flow_split_info, error);
5953 /* qrss ID should be freed if failed. */
5955 MLX5_ASSERT(dev_flow);
5960 * We do not destroy the partially created sub_flows in case of error.
5961 * These ones are included into parent flow list and will be destroyed
5962 * by flow_drv_destroy.
5964 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RSS_EXPANTION_FLOW_ID],
5966 mlx5_free(ext_actions);
5971 * Create meter internal drop flow with the original pattern.
5974 * Pointer to Ethernet device.
5976 * Parent flow structure pointer.
5978 * Flow rule attributes.
5980 * Pattern specification (list terminated by the END pattern item).
5981 * @param[in] flow_split_info
5982 * Pointer to flow split info structure.
5984 * Pointer to flow meter structure.
5986 * Perform verbose error reporting if not NULL.
5988 * 0 on success, negative value otherwise
5991 flow_meter_create_drop_flow_with_org_pattern(struct rte_eth_dev *dev,
5992 struct rte_flow *flow,
5993 const struct rte_flow_attr *attr,
5994 const struct rte_flow_item items[],
5995 struct mlx5_flow_split_info *flow_split_info,
5996 struct mlx5_flow_meter_info *fm,
5997 struct rte_flow_error *error)
5999 struct mlx5_flow *dev_flow = NULL;
6000 struct rte_flow_attr drop_attr = *attr;
6001 struct rte_flow_action drop_actions[3];
6002 struct mlx5_flow_split_info drop_split_info = *flow_split_info;
6004 MLX5_ASSERT(fm->drop_cnt);
6005 drop_actions[0].type =
6006 (enum rte_flow_action_type)MLX5_RTE_FLOW_ACTION_TYPE_COUNT;
6007 drop_actions[0].conf = (void *)(uintptr_t)fm->drop_cnt;
6008 drop_actions[1].type = RTE_FLOW_ACTION_TYPE_DROP;
6009 drop_actions[1].conf = NULL;
6010 drop_actions[2].type = RTE_FLOW_ACTION_TYPE_END;
6011 drop_actions[2].conf = NULL;
6012 drop_split_info.external = false;
6013 drop_split_info.skip_scale |= 1 << MLX5_SCALE_FLOW_GROUP_BIT;
6014 drop_split_info.table_id = MLX5_MTR_TABLE_ID_DROP;
6015 drop_attr.group = MLX5_FLOW_TABLE_LEVEL_METER;
6016 return flow_create_split_inner(dev, flow, &dev_flow,
6017 &drop_attr, items, drop_actions,
6018 &drop_split_info, error);
6022 * The splitting for meter feature.
6024 * - The meter flow will be split to two flows as prefix and
6025 * suffix flow. The packets make sense only it pass the prefix
6028 * - Reg_C_5 is used for the packet to match betweend prefix and
6032 * Pointer to Ethernet device.
6034 * Parent flow structure pointer.
6036 * Flow rule attributes.
6038 * Pattern specification (list terminated by the END pattern item).
6039 * @param[in] actions
6040 * Associated actions (list terminated by the END action).
6041 * @param[in] flow_split_info
6042 * Pointer to flow split info structure.
6044 * Perform verbose error reporting if not NULL.
6046 * 0 on success, negative value otherwise
6049 flow_create_split_meter(struct rte_eth_dev *dev,
6050 struct rte_flow *flow,
6051 const struct rte_flow_attr *attr,
6052 const struct rte_flow_item items[],
6053 const struct rte_flow_action actions[],
6054 struct mlx5_flow_split_info *flow_split_info,
6055 struct rte_flow_error *error)
6057 struct mlx5_priv *priv = dev->data->dev_private;
6058 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
6059 struct rte_flow_action *sfx_actions = NULL;
6060 struct rte_flow_action *pre_actions = NULL;
6061 struct rte_flow_item *sfx_items = NULL;
6062 struct mlx5_flow *dev_flow = NULL;
6063 struct rte_flow_attr sfx_attr = *attr;
6064 struct mlx5_flow_meter_info *fm = NULL;
6065 uint8_t skip_scale_restore;
6066 bool has_mtr = false;
6067 bool has_modify = false;
6068 bool set_mtr_reg = true;
6069 bool is_mtr_hierarchy = false;
6070 uint32_t meter_id = 0;
6071 uint32_t mtr_idx = 0;
6072 uint32_t mtr_flow_id = 0;
6079 actions_n = flow_check_meter_action(dev, actions, &has_mtr,
6080 &has_modify, &meter_id);
6083 fm = flow_dv_meter_find_by_idx(priv, flow->meter);
6085 return rte_flow_error_set(error, EINVAL,
6086 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6087 NULL, "Meter not found.");
6089 fm = mlx5_flow_meter_find(priv, meter_id, &mtr_idx);
6091 return rte_flow_error_set(error, EINVAL,
6092 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6093 NULL, "Meter not found.");
6094 ret = mlx5_flow_meter_attach(priv, fm,
6098 flow->meter = mtr_idx;
6102 if (!fm->def_policy) {
6103 wks->policy = mlx5_flow_meter_policy_find(dev,
6106 MLX5_ASSERT(wks->policy);
6107 if (wks->policy->is_hierarchy) {
6109 mlx5_flow_meter_hierarchy_get_final_policy(dev,
6111 if (!wks->final_policy)
6112 return rte_flow_error_set(error,
6114 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
6115 "Failed to find terminal policy of hierarchy.");
6116 is_mtr_hierarchy = true;
6120 * If it isn't default-policy Meter, and
6121 * 1. There's no action in flow to change
6122 * packet (modify/encap/decap etc.), OR
6123 * 2. No drop count needed for this meter.
6124 * 3. It's not meter hierarchy.
6125 * Then no need to use regC to save meter id anymore.
6127 if (!fm->def_policy && !is_mtr_hierarchy &&
6128 (!has_modify || !fm->drop_cnt))
6129 set_mtr_reg = false;
6130 /* Prefix actions: meter, decap, encap, tag, jump, end. */
6131 act_size = sizeof(struct rte_flow_action) * (actions_n + 6) +
6132 sizeof(struct mlx5_rte_flow_action_set_tag);
6133 /* Suffix items: tag, vlan, port id, end. */
6134 #define METER_SUFFIX_ITEM 4
6135 item_size = sizeof(struct rte_flow_item) * METER_SUFFIX_ITEM +
6136 sizeof(struct mlx5_rte_flow_item_tag) * 2;
6137 sfx_actions = mlx5_malloc(MLX5_MEM_ZERO, (act_size + item_size),
6140 return rte_flow_error_set(error, ENOMEM,
6141 RTE_FLOW_ERROR_TYPE_ACTION,
6142 NULL, "no memory to split "
6144 sfx_items = (struct rte_flow_item *)((char *)sfx_actions +
6146 /* There's no suffix flow for meter of non-default policy. */
6147 if (!fm->def_policy)
6148 pre_actions = sfx_actions + 1;
6150 pre_actions = sfx_actions + actions_n;
6151 ret = flow_meter_split_prep(dev, flow, wks, &sfx_attr,
6152 items, sfx_items, actions,
6153 sfx_actions, pre_actions,
6154 (set_mtr_reg ? &mtr_flow_id : NULL),
6160 /* Add the prefix subflow. */
6161 skip_scale_restore = flow_split_info->skip_scale;
6162 flow_split_info->skip_scale |=
6163 1 << MLX5_SCALE_JUMP_FLOW_GROUP_BIT;
6164 ret = flow_create_split_inner(dev, flow, &dev_flow,
6165 attr, items, pre_actions,
6166 flow_split_info, error);
6167 flow_split_info->skip_scale = skip_scale_restore;
6170 mlx5_ipool_free(fm->flow_ipool, mtr_flow_id);
6175 dev_flow->handle->split_flow_id = mtr_flow_id;
6176 dev_flow->handle->is_meter_flow_id = 1;
6178 if (!fm->def_policy) {
6179 if (!set_mtr_reg && fm->drop_cnt)
6181 flow_meter_create_drop_flow_with_org_pattern(dev, flow,
6187 /* Setting the sfx group atrr. */
6188 sfx_attr.group = sfx_attr.transfer ?
6189 (MLX5_FLOW_TABLE_LEVEL_METER - 1) :
6190 MLX5_FLOW_TABLE_LEVEL_METER;
6191 flow_split_info->prefix_layers =
6192 flow_get_prefix_layer_flags(dev_flow);
6193 flow_split_info->prefix_mark |= wks->mark;
6194 flow_split_info->table_id = MLX5_MTR_TABLE_ID_SUFFIX;
6196 /* Add the prefix subflow. */
6197 ret = flow_create_split_metadata(dev, flow,
6198 &sfx_attr, sfx_items ?
6200 sfx_actions ? sfx_actions : actions,
6201 flow_split_info, error);
6204 mlx5_free(sfx_actions);
6209 * The splitting for sample feature.
6211 * Once Sample action is detected in the action list, the flow actions should
6212 * be split into prefix sub flow and suffix sub flow.
6214 * The original items remain in the prefix sub flow, all actions preceding the
6215 * sample action and the sample action itself will be copied to the prefix
6216 * sub flow, the actions following the sample action will be copied to the
6217 * suffix sub flow, Queue action always be located in the suffix sub flow.
6219 * In order to make the packet from prefix sub flow matches with suffix sub
6220 * flow, an extra tag action be added into prefix sub flow, and the suffix sub
6221 * flow uses tag item with the unique flow id.
6224 * Pointer to Ethernet device.
6226 * Parent flow structure pointer.
6228 * Flow rule attributes.
6230 * Pattern specification (list terminated by the END pattern item).
6231 * @param[in] actions
6232 * Associated actions (list terminated by the END action).
6233 * @param[in] flow_split_info
6234 * Pointer to flow split info structure.
6236 * Perform verbose error reporting if not NULL.
6238 * 0 on success, negative value otherwise
6241 flow_create_split_sample(struct rte_eth_dev *dev,
6242 struct rte_flow *flow,
6243 const struct rte_flow_attr *attr,
6244 const struct rte_flow_item items[],
6245 const struct rte_flow_action actions[],
6246 struct mlx5_flow_split_info *flow_split_info,
6247 struct rte_flow_error *error)
6249 struct mlx5_priv *priv = dev->data->dev_private;
6250 struct rte_flow_action *sfx_actions = NULL;
6251 struct rte_flow_action *pre_actions = NULL;
6252 struct rte_flow_item *sfx_items = NULL;
6253 struct mlx5_flow *dev_flow = NULL;
6254 struct rte_flow_attr sfx_attr = *attr;
6255 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
6256 struct mlx5_flow_dv_sample_resource *sample_res;
6257 struct mlx5_flow_tbl_data_entry *sfx_tbl_data;
6258 struct mlx5_flow_tbl_resource *sfx_tbl;
6259 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
6263 uint32_t fdb_tx = 0;
6266 int sample_action_pos;
6267 int qrss_action_pos;
6269 int modify_after_mirror = 0;
6270 uint16_t jump_table = 0;
6271 const uint32_t next_ft_step = 1;
6274 if (priv->sampler_en)
6275 actions_n = flow_check_match_action(actions, attr,
6276 RTE_FLOW_ACTION_TYPE_SAMPLE,
6277 &sample_action_pos, &qrss_action_pos,
6278 &modify_after_mirror);
6280 /* The prefix actions must includes sample, tag, end. */
6281 act_size = sizeof(struct rte_flow_action) * (actions_n * 2 + 1)
6282 + sizeof(struct mlx5_rte_flow_action_set_tag);
6283 item_size = sizeof(struct rte_flow_item) * SAMPLE_SUFFIX_ITEM +
6284 sizeof(struct mlx5_rte_flow_item_tag) * 2;
6285 sfx_actions = mlx5_malloc(MLX5_MEM_ZERO, (act_size +
6286 item_size), 0, SOCKET_ID_ANY);
6288 return rte_flow_error_set(error, ENOMEM,
6289 RTE_FLOW_ERROR_TYPE_ACTION,
6290 NULL, "no memory to split "
6292 /* The representor_id is UINT16_MAX for uplink. */
6293 fdb_tx = (attr->transfer && priv->representor_id != UINT16_MAX);
6295 * When reg_c_preserve is set, metadata registers Cx preserve
6296 * their value even through packet duplication.
6298 add_tag = (!fdb_tx ||
6299 priv->sh->cdev->config.hca_attr.reg_c_preserve);
6301 sfx_items = (struct rte_flow_item *)((char *)sfx_actions
6303 if (modify_after_mirror)
6304 jump_table = attr->group * MLX5_FLOW_TABLE_FACTOR +
6306 pre_actions = sfx_actions + actions_n;
6307 tag_id = flow_sample_split_prep(dev, add_tag, sfx_items,
6308 actions, sfx_actions,
6309 pre_actions, actions_n,
6311 qrss_action_pos, jump_table,
6313 if (tag_id < 0 || (add_tag && !tag_id)) {
6317 if (modify_after_mirror)
6318 flow_split_info->skip_scale =
6319 1 << MLX5_SCALE_JUMP_FLOW_GROUP_BIT;
6320 /* Add the prefix subflow. */
6321 ret = flow_create_split_inner(dev, flow, &dev_flow, attr,
6323 flow_split_info, error);
6328 dev_flow->handle->split_flow_id = tag_id;
6329 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
6330 if (!modify_after_mirror) {
6331 /* Set the sfx group attr. */
6332 sample_res = (struct mlx5_flow_dv_sample_resource *)
6333 dev_flow->dv.sample_res;
6334 sfx_tbl = (struct mlx5_flow_tbl_resource *)
6335 sample_res->normal_path_tbl;
6336 sfx_tbl_data = container_of(sfx_tbl,
6337 struct mlx5_flow_tbl_data_entry,
6339 sfx_attr.group = sfx_attr.transfer ?
6340 (sfx_tbl_data->level - 1) : sfx_tbl_data->level;
6342 MLX5_ASSERT(attr->transfer);
6343 sfx_attr.group = jump_table;
6345 flow_split_info->prefix_layers =
6346 flow_get_prefix_layer_flags(dev_flow);
6348 flow_split_info->prefix_mark |= wks->mark;
6349 /* Suffix group level already be scaled with factor, set
6350 * MLX5_SCALE_FLOW_GROUP_BIT of skip_scale to 1 to avoid scale
6351 * again in translation.
6353 flow_split_info->skip_scale = 1 << MLX5_SCALE_FLOW_GROUP_BIT;
6356 /* Add the suffix subflow. */
6357 ret = flow_create_split_meter(dev, flow, &sfx_attr,
6358 sfx_items ? sfx_items : items,
6359 sfx_actions ? sfx_actions : actions,
6360 flow_split_info, error);
6363 mlx5_free(sfx_actions);
6368 * Split the flow to subflow set. The splitters might be linked
6369 * in the chain, like this:
6370 * flow_create_split_outer() calls:
6371 * flow_create_split_meter() calls:
6372 * flow_create_split_metadata(meter_subflow_0) calls:
6373 * flow_create_split_inner(metadata_subflow_0)
6374 * flow_create_split_inner(metadata_subflow_1)
6375 * flow_create_split_inner(metadata_subflow_2)
6376 * flow_create_split_metadata(meter_subflow_1) calls:
6377 * flow_create_split_inner(metadata_subflow_0)
6378 * flow_create_split_inner(metadata_subflow_1)
6379 * flow_create_split_inner(metadata_subflow_2)
6381 * This provide flexible way to add new levels of flow splitting.
6382 * The all of successfully created subflows are included to the
6383 * parent flow dev_flow list.
6386 * Pointer to Ethernet device.
6388 * Parent flow structure pointer.
6390 * Flow rule attributes.
6392 * Pattern specification (list terminated by the END pattern item).
6393 * @param[in] actions
6394 * Associated actions (list terminated by the END action).
6395 * @param[in] flow_split_info
6396 * Pointer to flow split info structure.
6398 * Perform verbose error reporting if not NULL.
6400 * 0 on success, negative value otherwise
6403 flow_create_split_outer(struct rte_eth_dev *dev,
6404 struct rte_flow *flow,
6405 const struct rte_flow_attr *attr,
6406 const struct rte_flow_item items[],
6407 const struct rte_flow_action actions[],
6408 struct mlx5_flow_split_info *flow_split_info,
6409 struct rte_flow_error *error)
6413 ret = flow_create_split_sample(dev, flow, attr, items,
6414 actions, flow_split_info, error);
6415 MLX5_ASSERT(ret <= 0);
6419 static inline struct mlx5_flow_tunnel *
6420 flow_tunnel_from_rule(const struct mlx5_flow *flow)
6422 struct mlx5_flow_tunnel *tunnel;
6424 #pragma GCC diagnostic push
6425 #pragma GCC diagnostic ignored "-Wcast-qual"
6426 tunnel = (typeof(tunnel))flow->tunnel;
6427 #pragma GCC diagnostic pop
6433 * Adjust flow RSS workspace if needed.
6436 * Pointer to thread flow work space.
6438 * Pointer to RSS descriptor.
6439 * @param[in] nrssq_num
6440 * New RSS queue number.
6443 * 0 on success, -1 otherwise and rte_errno is set.
6446 flow_rss_workspace_adjust(struct mlx5_flow_workspace *wks,
6447 struct mlx5_flow_rss_desc *rss_desc,
6450 if (likely(nrssq_num <= wks->rssq_num))
6452 rss_desc->queue = realloc(rss_desc->queue,
6453 sizeof(*rss_desc->queue) * RTE_ALIGN(nrssq_num, 2));
6454 if (!rss_desc->queue) {
6458 wks->rssq_num = RTE_ALIGN(nrssq_num, 2);
6463 * Create a flow and add it to @p list.
6466 * Pointer to Ethernet device.
6468 * Pointer to a TAILQ flow list. If this parameter NULL,
6469 * no list insertion occurred, flow is just created,
6470 * this is caller's responsibility to track the
6473 * Flow rule attributes.
6475 * Pattern specification (list terminated by the END pattern item).
6476 * @param[in] actions
6477 * Associated actions (list terminated by the END action).
6478 * @param[in] external
6479 * This flow rule is created by request external to PMD.
6481 * Perform verbose error reporting if not NULL.
6484 * A flow index on success, 0 otherwise and rte_errno is set.
6487 flow_list_create(struct rte_eth_dev *dev, enum mlx5_flow_type type,
6488 const struct rte_flow_attr *attr,
6489 const struct rte_flow_item items[],
6490 const struct rte_flow_action original_actions[],
6491 bool external, struct rte_flow_error *error)
6493 struct mlx5_priv *priv = dev->data->dev_private;
6494 struct rte_flow *flow = NULL;
6495 struct mlx5_flow *dev_flow;
6496 const struct rte_flow_action_rss *rss = NULL;
6497 struct mlx5_translated_action_handle
6498 indir_actions[MLX5_MAX_INDIRECT_ACTIONS];
6499 int indir_actions_n = MLX5_MAX_INDIRECT_ACTIONS;
6501 struct mlx5_flow_expand_rss buf;
6502 uint8_t buffer[4096];
6505 struct rte_flow_action actions[MLX5_MAX_SPLIT_ACTIONS];
6506 uint8_t buffer[2048];
6509 struct rte_flow_action actions[MLX5_MAX_SPLIT_ACTIONS];
6510 uint8_t buffer[2048];
6511 } actions_hairpin_tx;
6513 struct rte_flow_item items[MLX5_MAX_SPLIT_ITEMS];
6514 uint8_t buffer[2048];
6516 struct mlx5_flow_expand_rss *buf = &expand_buffer.buf;
6517 struct mlx5_flow_rss_desc *rss_desc;
6518 const struct rte_flow_action *p_actions_rx;
6522 struct rte_flow_attr attr_tx = { .priority = 0 };
6523 const struct rte_flow_action *actions;
6524 struct rte_flow_action *translated_actions = NULL;
6525 struct mlx5_flow_tunnel *tunnel;
6526 struct tunnel_default_miss_ctx default_miss_ctx = { 0, };
6527 struct mlx5_flow_workspace *wks = mlx5_flow_push_thread_workspace();
6528 struct mlx5_flow_split_info flow_split_info = {
6529 .external = !!external,
6539 rss_desc = &wks->rss_desc;
6540 ret = flow_action_handles_translate(dev, original_actions,
6543 &translated_actions, error);
6545 MLX5_ASSERT(translated_actions == NULL);
6548 actions = translated_actions ? translated_actions : original_actions;
6549 p_actions_rx = actions;
6550 hairpin_flow = flow_check_hairpin_split(dev, attr, actions);
6551 ret = flow_drv_validate(dev, attr, items, p_actions_rx,
6552 external, hairpin_flow, error);
6554 goto error_before_hairpin_split;
6555 flow = mlx5_ipool_zmalloc(priv->flows[type], &idx);
6558 goto error_before_hairpin_split;
6560 if (hairpin_flow > 0) {
6561 if (hairpin_flow > MLX5_MAX_SPLIT_ACTIONS) {
6563 goto error_before_hairpin_split;
6565 flow_hairpin_split(dev, actions, actions_rx.actions,
6566 actions_hairpin_tx.actions, items_tx.items,
6568 p_actions_rx = actions_rx.actions;
6570 flow_split_info.flow_idx = idx;
6571 flow->drv_type = flow_get_drv_type(dev, attr);
6572 MLX5_ASSERT(flow->drv_type > MLX5_FLOW_TYPE_MIN &&
6573 flow->drv_type < MLX5_FLOW_TYPE_MAX);
6574 memset(rss_desc, 0, offsetof(struct mlx5_flow_rss_desc, queue));
6575 /* RSS Action only works on NIC RX domain */
6576 if (attr->ingress && !attr->transfer)
6577 rss = flow_get_rss_action(dev, p_actions_rx);
6579 if (flow_rss_workspace_adjust(wks, rss_desc, rss->queue_num))
6582 * The following information is required by
6583 * mlx5_flow_hashfields_adjust() in advance.
6585 rss_desc->level = rss->level;
6586 /* RSS type 0 indicates default RSS type (RTE_ETH_RSS_IP). */
6587 rss_desc->types = !rss->types ? RTE_ETH_RSS_IP : rss->types;
6589 flow->dev_handles = 0;
6590 if (rss && rss->types) {
6591 unsigned int graph_root;
6593 graph_root = find_graph_root(rss->level);
6594 ret = mlx5_flow_expand_rss(buf, sizeof(expand_buffer.buffer),
6596 mlx5_support_expansion, graph_root);
6597 MLX5_ASSERT(ret > 0 &&
6598 (unsigned int)ret < sizeof(expand_buffer.buffer));
6599 if (rte_log_can_log(mlx5_logtype, RTE_LOG_DEBUG)) {
6600 for (i = 0; i < buf->entries; ++i)
6601 mlx5_dbg__print_pattern(buf->entry[i].pattern);
6605 buf->entry[0].pattern = (void *)(uintptr_t)items;
6607 rss_desc->shared_rss = flow_get_shared_rss_action(dev, indir_actions,
6609 for (i = 0; i < buf->entries; ++i) {
6610 /* Initialize flow split data. */
6611 flow_split_info.prefix_layers = 0;
6612 flow_split_info.prefix_mark = 0;
6613 flow_split_info.skip_scale = 0;
6615 * The splitter may create multiple dev_flows,
6616 * depending on configuration. In the simplest
6617 * case it just creates unmodified original flow.
6619 ret = flow_create_split_outer(dev, flow, attr,
6620 buf->entry[i].pattern,
6621 p_actions_rx, &flow_split_info,
6625 if (is_flow_tunnel_steer_rule(wks->flows[0].tof_type)) {
6626 ret = flow_tunnel_add_default_miss(dev, flow, attr,
6629 wks->flows[0].tunnel,
6633 mlx5_free(default_miss_ctx.queue);
6638 /* Create the tx flow. */
6640 attr_tx.group = MLX5_HAIRPIN_TX_TABLE;
6641 attr_tx.ingress = 0;
6643 dev_flow = flow_drv_prepare(dev, flow, &attr_tx, items_tx.items,
6644 actions_hairpin_tx.actions,
6648 dev_flow->flow = flow;
6649 dev_flow->external = 0;
6650 SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
6651 dev_flow->handle, next);
6652 ret = flow_drv_translate(dev, dev_flow, &attr_tx,
6654 actions_hairpin_tx.actions, error);
6659 * Update the metadata register copy table. If extensive
6660 * metadata feature is enabled and registers are supported
6661 * we might create the extra rte_flow for each unique
6662 * MARK/FLAG action ID.
6664 * The table is updated for ingress Flows only, because
6665 * the egress Flows belong to the different device and
6666 * copy table should be updated in peer NIC Rx domain.
6668 if (attr->ingress &&
6669 (external || attr->group != MLX5_FLOW_MREG_CP_TABLE_GROUP)) {
6670 ret = flow_mreg_update_copy_table(dev, flow, actions, error);
6675 * If the flow is external (from application) OR device is started,
6676 * OR mreg discover, then apply immediately.
6678 if (external || dev->data->dev_started ||
6679 (attr->group == MLX5_FLOW_MREG_CP_TABLE_GROUP &&
6680 attr->priority == MLX5_FLOW_LOWEST_PRIO_INDICATOR)) {
6681 ret = flow_drv_apply(dev, flow, error);
6686 flow_rxq_flags_set(dev, flow);
6687 rte_free(translated_actions);
6688 tunnel = flow_tunnel_from_rule(wks->flows);
6691 flow->tunnel_id = tunnel->tunnel_id;
6692 __atomic_add_fetch(&tunnel->refctn, 1, __ATOMIC_RELAXED);
6693 mlx5_free(default_miss_ctx.queue);
6695 mlx5_flow_pop_thread_workspace();
6699 ret = rte_errno; /* Save rte_errno before cleanup. */
6700 flow_mreg_del_copy_action(dev, flow);
6701 flow_drv_destroy(dev, flow);
6702 if (rss_desc->shared_rss)
6703 __atomic_sub_fetch(&((struct mlx5_shared_action_rss *)
6705 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
6706 rss_desc->shared_rss))->refcnt, 1, __ATOMIC_RELAXED);
6707 mlx5_ipool_free(priv->flows[type], idx);
6708 rte_errno = ret; /* Restore rte_errno. */
6711 mlx5_flow_pop_thread_workspace();
6712 error_before_hairpin_split:
6713 rte_free(translated_actions);
6718 * Create a dedicated flow rule on e-switch table 0 (root table), to direct all
6719 * incoming packets to table 1.
6721 * Other flow rules, requested for group n, will be created in
6722 * e-switch table n+1.
6723 * Jump action to e-switch group n will be created to group n+1.
6725 * Used when working in switchdev mode, to utilise advantages of table 1
6729 * Pointer to Ethernet device.
6732 * Pointer to flow on success, NULL otherwise and rte_errno is set.
6735 mlx5_flow_create_esw_table_zero_flow(struct rte_eth_dev *dev)
6737 const struct rte_flow_attr attr = {
6744 const struct rte_flow_item pattern = {
6745 .type = RTE_FLOW_ITEM_TYPE_END,
6747 struct rte_flow_action_jump jump = {
6750 const struct rte_flow_action actions[] = {
6752 .type = RTE_FLOW_ACTION_TYPE_JUMP,
6756 .type = RTE_FLOW_ACTION_TYPE_END,
6759 struct rte_flow_error error;
6761 return (void *)(uintptr_t)flow_list_create(dev, MLX5_FLOW_TYPE_CTL,
6763 actions, false, &error);
6767 * Create a dedicated flow rule on e-switch table 1, matches ESW manager
6768 * and sq number, directs all packets to peer vport.
6771 * Pointer to Ethernet device.
6776 * Flow ID on success, 0 otherwise and rte_errno is set.
6779 mlx5_flow_create_devx_sq_miss_flow(struct rte_eth_dev *dev, uint32_t txq)
6781 struct rte_flow_attr attr = {
6783 .priority = MLX5_FLOW_LOWEST_PRIO_INDICATOR,
6788 struct rte_flow_item_port_id port_spec = {
6789 .id = MLX5_PORT_ESW_MGR,
6791 struct mlx5_rte_flow_item_tx_queue txq_spec = {
6794 struct rte_flow_item pattern[] = {
6796 .type = RTE_FLOW_ITEM_TYPE_PORT_ID,
6800 .type = (enum rte_flow_item_type)
6801 MLX5_RTE_FLOW_ITEM_TYPE_TX_QUEUE,
6805 .type = RTE_FLOW_ITEM_TYPE_END,
6808 struct rte_flow_action_jump jump = {
6811 struct rte_flow_action_port_id port = {
6812 .id = dev->data->port_id,
6814 struct rte_flow_action actions[] = {
6816 .type = RTE_FLOW_ACTION_TYPE_JUMP,
6820 .type = RTE_FLOW_ACTION_TYPE_END,
6823 struct rte_flow_error error;
6826 * Creates group 0, highest priority jump flow.
6827 * Matches txq to bypass kernel packets.
6829 if (flow_list_create(dev, MLX5_FLOW_TYPE_CTL, &attr, pattern, actions,
6830 false, &error) == 0)
6832 /* Create group 1, lowest priority redirect flow for txq. */
6834 actions[0].conf = &port;
6835 actions[0].type = RTE_FLOW_ACTION_TYPE_PORT_ID;
6836 return flow_list_create(dev, MLX5_FLOW_TYPE_CTL, &attr, pattern,
6837 actions, false, &error);
6841 * Validate a flow supported by the NIC.
6843 * @see rte_flow_validate()
6847 mlx5_flow_validate(struct rte_eth_dev *dev,
6848 const struct rte_flow_attr *attr,
6849 const struct rte_flow_item items[],
6850 const struct rte_flow_action original_actions[],
6851 struct rte_flow_error *error)
6854 struct mlx5_translated_action_handle
6855 indir_actions[MLX5_MAX_INDIRECT_ACTIONS];
6856 int indir_actions_n = MLX5_MAX_INDIRECT_ACTIONS;
6857 const struct rte_flow_action *actions;
6858 struct rte_flow_action *translated_actions = NULL;
6859 int ret = flow_action_handles_translate(dev, original_actions,
6862 &translated_actions, error);
6866 actions = translated_actions ? translated_actions : original_actions;
6867 hairpin_flow = flow_check_hairpin_split(dev, attr, actions);
6868 ret = flow_drv_validate(dev, attr, items, actions,
6869 true, hairpin_flow, error);
6870 rte_free(translated_actions);
6877 * @see rte_flow_create()
6881 mlx5_flow_create(struct rte_eth_dev *dev,
6882 const struct rte_flow_attr *attr,
6883 const struct rte_flow_item items[],
6884 const struct rte_flow_action actions[],
6885 struct rte_flow_error *error)
6887 struct mlx5_priv *priv = dev->data->dev_private;
6889 if (priv->sh->config.dv_flow_en == 2) {
6890 rte_flow_error_set(error, ENOTSUP,
6891 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6893 "Flow non-Q creation not supported");
6897 * If the device is not started yet, it is not allowed to created a
6898 * flow from application. PMD default flows and traffic control flows
6901 if (unlikely(!dev->data->dev_started)) {
6902 DRV_LOG(DEBUG, "port %u is not started when "
6903 "inserting a flow", dev->data->port_id);
6904 rte_flow_error_set(error, ENODEV,
6905 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6907 "port not started");
6911 return (void *)(uintptr_t)flow_list_create(dev, MLX5_FLOW_TYPE_GEN,
6912 attr, items, actions,
6917 * Destroy a flow in a list.
6920 * Pointer to Ethernet device.
6921 * @param[in] flow_idx
6922 * Index of flow to destroy.
6925 flow_list_destroy(struct rte_eth_dev *dev, enum mlx5_flow_type type,
6928 struct mlx5_priv *priv = dev->data->dev_private;
6929 struct rte_flow *flow = mlx5_ipool_get(priv->flows[type], flow_idx);
6933 MLX5_ASSERT(flow->type == type);
6935 * Update RX queue flags only if port is started, otherwise it is
6938 if (dev->data->dev_started)
6939 flow_rxq_flags_trim(dev, flow);
6940 flow_drv_destroy(dev, flow);
6942 struct mlx5_flow_tunnel *tunnel;
6944 tunnel = mlx5_find_tunnel_id(dev, flow->tunnel_id);
6946 if (!__atomic_sub_fetch(&tunnel->refctn, 1, __ATOMIC_RELAXED))
6947 mlx5_flow_tunnel_free(dev, tunnel);
6949 flow_mreg_del_copy_action(dev, flow);
6950 mlx5_ipool_free(priv->flows[type], flow_idx);
6954 * Destroy all flows.
6957 * Pointer to Ethernet device.
6959 * Flow type to be flushed.
6961 * If flushing is called actively.
6964 mlx5_flow_list_flush(struct rte_eth_dev *dev, enum mlx5_flow_type type,
6967 struct mlx5_priv *priv = dev->data->dev_private;
6968 uint32_t num_flushed = 0, fidx = 1;
6969 struct rte_flow *flow;
6971 MLX5_IPOOL_FOREACH(priv->flows[type], fidx, flow) {
6972 flow_list_destroy(dev, type, fidx);
6976 DRV_LOG(INFO, "port %u: %u flows flushed before stopping",
6977 dev->data->port_id, num_flushed);
6982 * Stop all default actions for flows.
6985 * Pointer to Ethernet device.
6988 mlx5_flow_stop_default(struct rte_eth_dev *dev)
6990 flow_mreg_del_default_copy_action(dev);
6991 flow_rxq_flags_clear(dev);
6995 * Start all default actions for flows.
6998 * Pointer to Ethernet device.
7000 * 0 on success, a negative errno value otherwise and rte_errno is set.
7003 mlx5_flow_start_default(struct rte_eth_dev *dev)
7005 struct rte_flow_error error;
7007 /* Make sure default copy action (reg_c[0] -> reg_b) is created. */
7008 return flow_mreg_add_default_copy_action(dev, &error);
7012 * Release key of thread specific flow workspace data.
7015 flow_release_workspace(void *data)
7017 struct mlx5_flow_workspace *wks = data;
7018 struct mlx5_flow_workspace *next;
7022 free(wks->rss_desc.queue);
7029 * Get thread specific current flow workspace.
7031 * @return pointer to thread specific flow workspace data, NULL on error.
7033 struct mlx5_flow_workspace*
7034 mlx5_flow_get_thread_workspace(void)
7036 struct mlx5_flow_workspace *data;
7038 data = mlx5_flow_os_get_specific_workspace();
7039 MLX5_ASSERT(data && data->inuse);
7040 if (!data || !data->inuse)
7041 DRV_LOG(ERR, "flow workspace not initialized.");
7046 * Allocate and init new flow workspace.
7048 * @return pointer to flow workspace data, NULL on error.
7050 static struct mlx5_flow_workspace*
7051 flow_alloc_thread_workspace(void)
7053 struct mlx5_flow_workspace *data = calloc(1, sizeof(*data));
7056 DRV_LOG(ERR, "Failed to allocate flow workspace "
7060 data->rss_desc.queue = calloc(1,
7061 sizeof(uint16_t) * MLX5_RSSQ_DEFAULT_NUM);
7062 if (!data->rss_desc.queue)
7064 data->rssq_num = MLX5_RSSQ_DEFAULT_NUM;
7067 free(data->rss_desc.queue);
7073 * Get new thread specific flow workspace.
7075 * If current workspace inuse, create new one and set as current.
7077 * @return pointer to thread specific flow workspace data, NULL on error.
7079 static struct mlx5_flow_workspace*
7080 mlx5_flow_push_thread_workspace(void)
7082 struct mlx5_flow_workspace *curr;
7083 struct mlx5_flow_workspace *data;
7085 curr = mlx5_flow_os_get_specific_workspace();
7087 data = flow_alloc_thread_workspace();
7090 } else if (!curr->inuse) {
7092 } else if (curr->next) {
7095 data = flow_alloc_thread_workspace();
7103 /* Set as current workspace */
7104 if (mlx5_flow_os_set_specific_workspace(data))
7105 DRV_LOG(ERR, "Failed to set flow workspace to thread.");
7110 * Close current thread specific flow workspace.
7112 * If previous workspace available, set it as current.
7114 * @return pointer to thread specific flow workspace data, NULL on error.
7117 mlx5_flow_pop_thread_workspace(void)
7119 struct mlx5_flow_workspace *data = mlx5_flow_get_thread_workspace();
7124 DRV_LOG(ERR, "Failed to close unused flow workspace.");
7130 if (mlx5_flow_os_set_specific_workspace(data->prev))
7131 DRV_LOG(ERR, "Failed to set flow workspace to thread.");
7135 * Verify the flow list is empty
7138 * Pointer to Ethernet device.
7140 * @return the number of flows not released.
7143 mlx5_flow_verify(struct rte_eth_dev *dev __rte_unused)
7145 struct mlx5_priv *priv = dev->data->dev_private;
7146 struct rte_flow *flow;
7150 for (i = 0; i < MLX5_FLOW_TYPE_MAXI; i++) {
7151 MLX5_IPOOL_FOREACH(priv->flows[i], idx, flow) {
7152 DRV_LOG(DEBUG, "port %u flow %p still referenced",
7153 dev->data->port_id, (void *)flow);
7161 * Enable default hairpin egress flow.
7164 * Pointer to Ethernet device.
7169 * 0 on success, a negative errno value otherwise and rte_errno is set.
7172 mlx5_ctrl_flow_source_queue(struct rte_eth_dev *dev,
7175 const struct rte_flow_attr attr = {
7179 struct mlx5_rte_flow_item_tx_queue queue_spec = {
7182 struct mlx5_rte_flow_item_tx_queue queue_mask = {
7183 .queue = UINT32_MAX,
7185 struct rte_flow_item items[] = {
7187 .type = (enum rte_flow_item_type)
7188 MLX5_RTE_FLOW_ITEM_TYPE_TX_QUEUE,
7189 .spec = &queue_spec,
7191 .mask = &queue_mask,
7194 .type = RTE_FLOW_ITEM_TYPE_END,
7197 struct rte_flow_action_jump jump = {
7198 .group = MLX5_HAIRPIN_TX_TABLE,
7200 struct rte_flow_action actions[2];
7202 struct rte_flow_error error;
7204 actions[0].type = RTE_FLOW_ACTION_TYPE_JUMP;
7205 actions[0].conf = &jump;
7206 actions[1].type = RTE_FLOW_ACTION_TYPE_END;
7207 flow_idx = flow_list_create(dev, MLX5_FLOW_TYPE_CTL,
7208 &attr, items, actions, false, &error);
7211 "Failed to create ctrl flow: rte_errno(%d),"
7212 " type(%d), message(%s)",
7213 rte_errno, error.type,
7214 error.message ? error.message : " (no stated reason)");
7221 * Enable a control flow configured from the control plane.
7224 * Pointer to Ethernet device.
7226 * An Ethernet flow spec to apply.
7228 * An Ethernet flow mask to apply.
7230 * A VLAN flow spec to apply.
7232 * A VLAN flow mask to apply.
7235 * 0 on success, a negative errno value otherwise and rte_errno is set.
7238 mlx5_ctrl_flow_vlan(struct rte_eth_dev *dev,
7239 struct rte_flow_item_eth *eth_spec,
7240 struct rte_flow_item_eth *eth_mask,
7241 struct rte_flow_item_vlan *vlan_spec,
7242 struct rte_flow_item_vlan *vlan_mask)
7244 struct mlx5_priv *priv = dev->data->dev_private;
7245 const struct rte_flow_attr attr = {
7247 .priority = MLX5_FLOW_LOWEST_PRIO_INDICATOR,
7249 struct rte_flow_item items[] = {
7251 .type = RTE_FLOW_ITEM_TYPE_ETH,
7257 .type = (vlan_spec) ? RTE_FLOW_ITEM_TYPE_VLAN :
7258 RTE_FLOW_ITEM_TYPE_END,
7264 .type = RTE_FLOW_ITEM_TYPE_END,
7267 uint16_t queue[priv->reta_idx_n];
7268 struct rte_flow_action_rss action_rss = {
7269 .func = RTE_ETH_HASH_FUNCTION_DEFAULT,
7271 .types = priv->rss_conf.rss_hf,
7272 .key_len = priv->rss_conf.rss_key_len,
7273 .queue_num = priv->reta_idx_n,
7274 .key = priv->rss_conf.rss_key,
7277 struct rte_flow_action actions[] = {
7279 .type = RTE_FLOW_ACTION_TYPE_RSS,
7280 .conf = &action_rss,
7283 .type = RTE_FLOW_ACTION_TYPE_END,
7287 struct rte_flow_error error;
7290 if (!priv->reta_idx_n || !priv->rxqs_n) {
7293 if (!(dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_RSS_FLAG))
7294 action_rss.types = 0;
7295 for (i = 0; i != priv->reta_idx_n; ++i)
7296 queue[i] = (*priv->reta_idx)[i];
7297 flow_idx = flow_list_create(dev, MLX5_FLOW_TYPE_CTL,
7298 &attr, items, actions, false, &error);
7305 * Enable a flow control configured from the control plane.
7308 * Pointer to Ethernet device.
7310 * An Ethernet flow spec to apply.
7312 * An Ethernet flow mask to apply.
7315 * 0 on success, a negative errno value otherwise and rte_errno is set.
7318 mlx5_ctrl_flow(struct rte_eth_dev *dev,
7319 struct rte_flow_item_eth *eth_spec,
7320 struct rte_flow_item_eth *eth_mask)
7322 return mlx5_ctrl_flow_vlan(dev, eth_spec, eth_mask, NULL, NULL);
7326 * Create default miss flow rule matching lacp traffic
7329 * Pointer to Ethernet device.
7331 * An Ethernet flow spec to apply.
7334 * 0 on success, a negative errno value otherwise and rte_errno is set.
7337 mlx5_flow_lacp_miss(struct rte_eth_dev *dev)
7340 * The LACP matching is done by only using ether type since using
7341 * a multicast dst mac causes kernel to give low priority to this flow.
7343 static const struct rte_flow_item_eth lacp_spec = {
7344 .type = RTE_BE16(0x8809),
7346 static const struct rte_flow_item_eth lacp_mask = {
7349 const struct rte_flow_attr attr = {
7352 struct rte_flow_item items[] = {
7354 .type = RTE_FLOW_ITEM_TYPE_ETH,
7359 .type = RTE_FLOW_ITEM_TYPE_END,
7362 struct rte_flow_action actions[] = {
7364 .type = (enum rte_flow_action_type)
7365 MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS,
7368 .type = RTE_FLOW_ACTION_TYPE_END,
7371 struct rte_flow_error error;
7372 uint32_t flow_idx = flow_list_create(dev, MLX5_FLOW_TYPE_CTL,
7373 &attr, items, actions,
7384 * @see rte_flow_destroy()
7388 mlx5_flow_destroy(struct rte_eth_dev *dev,
7389 struct rte_flow *flow,
7390 struct rte_flow_error *error __rte_unused)
7392 struct mlx5_priv *priv = dev->data->dev_private;
7394 if (priv->sh->config.dv_flow_en == 2)
7395 return rte_flow_error_set(error, ENOTSUP,
7396 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7398 "Flow non-Q destruction not supported");
7399 flow_list_destroy(dev, MLX5_FLOW_TYPE_GEN,
7400 (uintptr_t)(void *)flow);
7405 * Destroy all flows.
7407 * @see rte_flow_flush()
7411 mlx5_flow_flush(struct rte_eth_dev *dev,
7412 struct rte_flow_error *error __rte_unused)
7414 mlx5_flow_list_flush(dev, MLX5_FLOW_TYPE_GEN, false);
7421 * @see rte_flow_isolate()
7425 mlx5_flow_isolate(struct rte_eth_dev *dev,
7427 struct rte_flow_error *error)
7429 struct mlx5_priv *priv = dev->data->dev_private;
7431 if (dev->data->dev_started) {
7432 rte_flow_error_set(error, EBUSY,
7433 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7435 "port must be stopped first");
7438 priv->isolated = !!enable;
7440 dev->dev_ops = &mlx5_dev_ops_isolate;
7442 dev->dev_ops = &mlx5_dev_ops;
7444 dev->rx_descriptor_status = mlx5_rx_descriptor_status;
7445 dev->tx_descriptor_status = mlx5_tx_descriptor_status;
7453 * @see rte_flow_query()
7457 flow_drv_query(struct rte_eth_dev *dev,
7459 const struct rte_flow_action *actions,
7461 struct rte_flow_error *error)
7463 struct mlx5_priv *priv = dev->data->dev_private;
7464 const struct mlx5_flow_driver_ops *fops;
7465 struct rte_flow *flow = mlx5_ipool_get(priv->flows[MLX5_FLOW_TYPE_GEN],
7467 enum mlx5_flow_drv_type ftype;
7470 return rte_flow_error_set(error, ENOENT,
7471 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7473 "invalid flow handle");
7475 ftype = flow->drv_type;
7476 MLX5_ASSERT(ftype > MLX5_FLOW_TYPE_MIN && ftype < MLX5_FLOW_TYPE_MAX);
7477 fops = flow_get_drv_ops(ftype);
7479 return fops->query(dev, flow, actions, data, error);
7485 * @see rte_flow_query()
7489 mlx5_flow_query(struct rte_eth_dev *dev,
7490 struct rte_flow *flow,
7491 const struct rte_flow_action *actions,
7493 struct rte_flow_error *error)
7496 struct mlx5_priv *priv = dev->data->dev_private;
7498 if (priv->sh->config.dv_flow_en == 2)
7499 return rte_flow_error_set(error, ENOTSUP,
7500 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7502 "Flow non-Q query not supported");
7503 ret = flow_drv_query(dev, (uintptr_t)(void *)flow, actions, data,
7511 * Get rte_flow callbacks.
7514 * Pointer to Ethernet device structure.
7516 * Pointer to operation-specific structure.
7521 mlx5_flow_ops_get(struct rte_eth_dev *dev __rte_unused,
7522 const struct rte_flow_ops **ops)
7524 *ops = &mlx5_flow_ops;
7529 * Validate meter policy actions.
7530 * Dispatcher for action type specific validation.
7533 * Pointer to the Ethernet device structure.
7535 * The meter policy action object to validate.
7537 * Attributes of flow to determine steering domain.
7538 * @param[out] is_rss
7540 * @param[out] domain_bitmap
7542 * @param[out] is_def_policy
7543 * Is default policy or not.
7545 * Perform verbose error reporting if not NULL. Initialized in case of
7549 * 0 on success, otherwise negative errno value.
7552 mlx5_flow_validate_mtr_acts(struct rte_eth_dev *dev,
7553 const struct rte_flow_action *actions[RTE_COLORS],
7554 struct rte_flow_attr *attr,
7556 uint8_t *domain_bitmap,
7557 uint8_t *policy_mode,
7558 struct rte_mtr_error *error)
7560 const struct mlx5_flow_driver_ops *fops;
7562 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7563 return fops->validate_mtr_acts(dev, actions, attr, is_rss,
7564 domain_bitmap, policy_mode, error);
7568 * Destroy the meter table set.
7571 * Pointer to Ethernet device.
7572 * @param[in] mtr_policy
7573 * Meter policy struct.
7576 mlx5_flow_destroy_mtr_acts(struct rte_eth_dev *dev,
7577 struct mlx5_flow_meter_policy *mtr_policy)
7579 const struct mlx5_flow_driver_ops *fops;
7581 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7582 fops->destroy_mtr_acts(dev, mtr_policy);
7586 * Create policy action, lock free,
7587 * (mutex should be acquired by caller).
7588 * Dispatcher for action type specific call.
7591 * Pointer to the Ethernet device structure.
7592 * @param[in] mtr_policy
7593 * Meter policy struct.
7595 * Action specification used to create meter actions.
7597 * Perform verbose error reporting if not NULL. Initialized in case of
7601 * 0 on success, otherwise negative errno value.
7604 mlx5_flow_create_mtr_acts(struct rte_eth_dev *dev,
7605 struct mlx5_flow_meter_policy *mtr_policy,
7606 const struct rte_flow_action *actions[RTE_COLORS],
7607 struct rte_mtr_error *error)
7609 const struct mlx5_flow_driver_ops *fops;
7611 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7612 return fops->create_mtr_acts(dev, mtr_policy, actions, error);
7616 * Create policy rules, lock free,
7617 * (mutex should be acquired by caller).
7618 * Dispatcher for action type specific call.
7621 * Pointer to the Ethernet device structure.
7622 * @param[in] mtr_policy
7623 * Meter policy struct.
7626 * 0 on success, -1 otherwise.
7629 mlx5_flow_create_policy_rules(struct rte_eth_dev *dev,
7630 struct mlx5_flow_meter_policy *mtr_policy)
7632 const struct mlx5_flow_driver_ops *fops;
7634 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7635 return fops->create_policy_rules(dev, mtr_policy);
7639 * Destroy policy rules, lock free,
7640 * (mutex should be acquired by caller).
7641 * Dispatcher for action type specific call.
7644 * Pointer to the Ethernet device structure.
7645 * @param[in] mtr_policy
7646 * Meter policy struct.
7649 mlx5_flow_destroy_policy_rules(struct rte_eth_dev *dev,
7650 struct mlx5_flow_meter_policy *mtr_policy)
7652 const struct mlx5_flow_driver_ops *fops;
7654 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7655 fops->destroy_policy_rules(dev, mtr_policy);
7659 * Destroy the default policy table set.
7662 * Pointer to Ethernet device.
7665 mlx5_flow_destroy_def_policy(struct rte_eth_dev *dev)
7667 const struct mlx5_flow_driver_ops *fops;
7669 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7670 fops->destroy_def_policy(dev);
7674 * Destroy the default policy table set.
7677 * Pointer to Ethernet device.
7680 * 0 on success, -1 otherwise.
7683 mlx5_flow_create_def_policy(struct rte_eth_dev *dev)
7685 const struct mlx5_flow_driver_ops *fops;
7687 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7688 return fops->create_def_policy(dev);
7692 * Create the needed meter and suffix tables.
7695 * Pointer to Ethernet device.
7698 * 0 on success, -1 otherwise.
7701 mlx5_flow_create_mtr_tbls(struct rte_eth_dev *dev,
7702 struct mlx5_flow_meter_info *fm,
7704 uint8_t domain_bitmap)
7706 const struct mlx5_flow_driver_ops *fops;
7708 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7709 return fops->create_mtr_tbls(dev, fm, mtr_idx, domain_bitmap);
7713 * Destroy the meter table set.
7716 * Pointer to Ethernet device.
7718 * Pointer to the meter table set.
7721 mlx5_flow_destroy_mtr_tbls(struct rte_eth_dev *dev,
7722 struct mlx5_flow_meter_info *fm)
7724 const struct mlx5_flow_driver_ops *fops;
7726 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7727 fops->destroy_mtr_tbls(dev, fm);
7731 * Destroy the global meter drop table.
7734 * Pointer to Ethernet device.
7737 mlx5_flow_destroy_mtr_drop_tbls(struct rte_eth_dev *dev)
7739 const struct mlx5_flow_driver_ops *fops;
7741 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7742 fops->destroy_mtr_drop_tbls(dev);
7746 * Destroy the sub policy table with RX queue.
7749 * Pointer to Ethernet device.
7750 * @param[in] mtr_policy
7751 * Pointer to meter policy table.
7754 mlx5_flow_destroy_sub_policy_with_rxq(struct rte_eth_dev *dev,
7755 struct mlx5_flow_meter_policy *mtr_policy)
7757 const struct mlx5_flow_driver_ops *fops;
7759 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7760 fops->destroy_sub_policy_with_rxq(dev, mtr_policy);
7764 * Allocate the needed aso flow meter id.
7767 * Pointer to Ethernet device.
7770 * Index to aso flow meter on success, NULL otherwise.
7773 mlx5_flow_mtr_alloc(struct rte_eth_dev *dev)
7775 const struct mlx5_flow_driver_ops *fops;
7777 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7778 return fops->create_meter(dev);
7782 * Free the aso flow meter id.
7785 * Pointer to Ethernet device.
7786 * @param[in] mtr_idx
7787 * Index to aso flow meter to be free.
7793 mlx5_flow_mtr_free(struct rte_eth_dev *dev, uint32_t mtr_idx)
7795 const struct mlx5_flow_driver_ops *fops;
7797 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7798 fops->free_meter(dev, mtr_idx);
7802 * Allocate a counter.
7805 * Pointer to Ethernet device structure.
7808 * Index to allocated counter on success, 0 otherwise.
7811 mlx5_counter_alloc(struct rte_eth_dev *dev)
7813 const struct mlx5_flow_driver_ops *fops;
7814 struct rte_flow_attr attr = { .transfer = 0 };
7816 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
7817 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7818 return fops->counter_alloc(dev);
7821 "port %u counter allocate is not supported.",
7822 dev->data->port_id);
7830 * Pointer to Ethernet device structure.
7832 * Index to counter to be free.
7835 mlx5_counter_free(struct rte_eth_dev *dev, uint32_t cnt)
7837 const struct mlx5_flow_driver_ops *fops;
7838 struct rte_flow_attr attr = { .transfer = 0 };
7840 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
7841 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7842 fops->counter_free(dev, cnt);
7846 "port %u counter free is not supported.",
7847 dev->data->port_id);
7851 * Query counter statistics.
7854 * Pointer to Ethernet device structure.
7856 * Index to counter to query.
7858 * Set to clear counter statistics.
7860 * The counter hits packets number to save.
7862 * The counter hits bytes number to save.
7865 * 0 on success, a negative errno value otherwise.
7868 mlx5_counter_query(struct rte_eth_dev *dev, uint32_t cnt,
7869 bool clear, uint64_t *pkts, uint64_t *bytes, void **action)
7871 const struct mlx5_flow_driver_ops *fops;
7872 struct rte_flow_attr attr = { .transfer = 0 };
7874 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
7875 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7876 return fops->counter_query(dev, cnt, clear, pkts,
7880 "port %u counter query is not supported.",
7881 dev->data->port_id);
7886 * Get information about HWS pre-configurable resources.
7889 * Pointer to the rte_eth_dev structure.
7890 * @param[out] port_info
7891 * Pointer to port information.
7892 * @param[out] queue_info
7893 * Pointer to queue information.
7895 * Pointer to error structure.
7898 * 0 on success, a negative errno value otherwise and rte_errno is set.
7901 mlx5_flow_info_get(struct rte_eth_dev *dev,
7902 struct rte_flow_port_info *port_info,
7903 struct rte_flow_queue_info *queue_info,
7904 struct rte_flow_error *error)
7906 const struct mlx5_flow_driver_ops *fops;
7908 if (flow_get_drv_type(dev, NULL) != MLX5_FLOW_TYPE_HW)
7909 return rte_flow_error_set(error, ENOTSUP,
7910 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7912 "info get with incorrect steering mode");
7913 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
7914 return fops->info_get(dev, port_info, queue_info, error);
7918 * Configure port HWS resources.
7921 * Pointer to the rte_eth_dev structure.
7922 * @param[in] port_attr
7923 * Port configuration attributes.
7924 * @param[in] nb_queue
7926 * @param[in] queue_attr
7927 * Array that holds attributes for each flow queue.
7929 * Pointer to error structure.
7932 * 0 on success, a negative errno value otherwise and rte_errno is set.
7935 mlx5_flow_port_configure(struct rte_eth_dev *dev,
7936 const struct rte_flow_port_attr *port_attr,
7938 const struct rte_flow_queue_attr *queue_attr[],
7939 struct rte_flow_error *error)
7941 const struct mlx5_flow_driver_ops *fops;
7943 if (flow_get_drv_type(dev, NULL) != MLX5_FLOW_TYPE_HW)
7944 return rte_flow_error_set(error, ENOTSUP,
7945 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7947 "port configure with incorrect steering mode");
7948 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
7949 return fops->configure(dev, port_attr, nb_queue, queue_attr, error);
7953 * Create flow item template.
7956 * Pointer to the rte_eth_dev structure.
7958 * Pointer to the item template attributes.
7960 * The template item pattern.
7962 * Pointer to error structure.
7965 * 0 on success, a negative errno value otherwise and rte_errno is set.
7967 static struct rte_flow_pattern_template *
7968 mlx5_flow_pattern_template_create(struct rte_eth_dev *dev,
7969 const struct rte_flow_pattern_template_attr *attr,
7970 const struct rte_flow_item items[],
7971 struct rte_flow_error *error)
7973 const struct mlx5_flow_driver_ops *fops;
7975 if (flow_get_drv_type(dev, NULL) != MLX5_FLOW_TYPE_HW) {
7976 rte_flow_error_set(error, ENOTSUP,
7977 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7979 "pattern create with incorrect steering mode");
7982 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
7983 return fops->pattern_template_create(dev, attr, items, error);
7987 * Destroy flow item template.
7990 * Pointer to the rte_eth_dev structure.
7991 * @param[in] template
7992 * Pointer to the item template to be destroyed.
7994 * Pointer to error structure.
7997 * 0 on success, a negative errno value otherwise and rte_errno is set.
8000 mlx5_flow_pattern_template_destroy(struct rte_eth_dev *dev,
8001 struct rte_flow_pattern_template *template,
8002 struct rte_flow_error *error)
8004 const struct mlx5_flow_driver_ops *fops;
8006 if (flow_get_drv_type(dev, NULL) != MLX5_FLOW_TYPE_HW)
8007 return rte_flow_error_set(error, ENOTSUP,
8008 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8010 "pattern destroy with incorrect steering mode");
8011 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
8012 return fops->pattern_template_destroy(dev, template, error);
8016 * Create flow item template.
8019 * Pointer to the rte_eth_dev structure.
8021 * Pointer to the action template attributes.
8022 * @param[in] actions
8023 * Associated actions (list terminated by the END action).
8025 * List of actions that marks which of the action's member is constant.
8027 * Pointer to error structure.
8030 * 0 on success, a negative errno value otherwise and rte_errno is set.
8032 static struct rte_flow_actions_template *
8033 mlx5_flow_actions_template_create(struct rte_eth_dev *dev,
8034 const struct rte_flow_actions_template_attr *attr,
8035 const struct rte_flow_action actions[],
8036 const struct rte_flow_action masks[],
8037 struct rte_flow_error *error)
8039 const struct mlx5_flow_driver_ops *fops;
8041 if (flow_get_drv_type(dev, NULL) != MLX5_FLOW_TYPE_HW) {
8042 rte_flow_error_set(error, ENOTSUP,
8043 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8045 "action create with incorrect steering mode");
8048 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
8049 return fops->actions_template_create(dev, attr, actions, masks, error);
8053 * Destroy flow action template.
8056 * Pointer to the rte_eth_dev structure.
8057 * @param[in] template
8058 * Pointer to the action template to be destroyed.
8060 * Pointer to error structure.
8063 * 0 on success, a negative errno value otherwise and rte_errno is set.
8066 mlx5_flow_actions_template_destroy(struct rte_eth_dev *dev,
8067 struct rte_flow_actions_template *template,
8068 struct rte_flow_error *error)
8070 const struct mlx5_flow_driver_ops *fops;
8072 if (flow_get_drv_type(dev, NULL) != MLX5_FLOW_TYPE_HW)
8073 return rte_flow_error_set(error, ENOTSUP,
8074 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8076 "action destroy with incorrect steering mode");
8077 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
8078 return fops->actions_template_destroy(dev, template, error);
8082 * Allocate a new memory for the counter values wrapped by all the needed
8086 * Pointer to mlx5_dev_ctx_shared object.
8089 * 0 on success, a negative errno value otherwise.
8092 mlx5_flow_create_counter_stat_mem_mng(struct mlx5_dev_ctx_shared *sh)
8094 struct mlx5_counter_stats_mem_mng *mem_mng;
8095 volatile struct flow_counter_stats *raw_data;
8096 int raws_n = MLX5_CNT_CONTAINER_RESIZE + MLX5_MAX_PENDING_QUERIES;
8097 int size = (sizeof(struct flow_counter_stats) *
8098 MLX5_COUNTERS_PER_POOL +
8099 sizeof(struct mlx5_counter_stats_raw)) * raws_n +
8100 sizeof(struct mlx5_counter_stats_mem_mng);
8101 size_t pgsize = rte_mem_page_size();
8106 if (pgsize == (size_t)-1) {
8107 DRV_LOG(ERR, "Failed to get mem page size");
8111 mem = mlx5_malloc(MLX5_MEM_ZERO, size, pgsize, SOCKET_ID_ANY);
8116 mem_mng = (struct mlx5_counter_stats_mem_mng *)(mem + size) - 1;
8117 size = sizeof(*raw_data) * MLX5_COUNTERS_PER_POOL * raws_n;
8118 ret = mlx5_os_wrapped_mkey_create(sh->cdev->ctx, sh->cdev->pd,
8119 sh->cdev->pdn, mem, size,
8126 mem_mng->raws = (struct mlx5_counter_stats_raw *)(mem + size);
8127 raw_data = (volatile struct flow_counter_stats *)mem;
8128 for (i = 0; i < raws_n; ++i) {
8129 mem_mng->raws[i].mem_mng = mem_mng;
8130 mem_mng->raws[i].data = raw_data + i * MLX5_COUNTERS_PER_POOL;
8132 for (i = 0; i < MLX5_MAX_PENDING_QUERIES; ++i)
8133 LIST_INSERT_HEAD(&sh->cmng.free_stat_raws,
8134 mem_mng->raws + MLX5_CNT_CONTAINER_RESIZE + i,
8136 LIST_INSERT_HEAD(&sh->cmng.mem_mngs, mem_mng, next);
8137 sh->cmng.mem_mng = mem_mng;
8142 * Set the statistic memory to the new counter pool.
8145 * Pointer to mlx5_dev_ctx_shared object.
8147 * Pointer to the pool to set the statistic memory.
8150 * 0 on success, a negative errno value otherwise.
8153 mlx5_flow_set_counter_stat_mem(struct mlx5_dev_ctx_shared *sh,
8154 struct mlx5_flow_counter_pool *pool)
8156 struct mlx5_flow_counter_mng *cmng = &sh->cmng;
8157 /* Resize statistic memory once used out. */
8158 if (!(pool->index % MLX5_CNT_CONTAINER_RESIZE) &&
8159 mlx5_flow_create_counter_stat_mem_mng(sh)) {
8160 DRV_LOG(ERR, "Cannot resize counter stat mem.");
8163 rte_spinlock_lock(&pool->sl);
8164 pool->raw = cmng->mem_mng->raws + pool->index %
8165 MLX5_CNT_CONTAINER_RESIZE;
8166 rte_spinlock_unlock(&pool->sl);
8167 pool->raw_hw = NULL;
8171 #define MLX5_POOL_QUERY_FREQ_US 1000000
8174 * Set the periodic procedure for triggering asynchronous batch queries for all
8175 * the counter pools.
8178 * Pointer to mlx5_dev_ctx_shared object.
8181 mlx5_set_query_alarm(struct mlx5_dev_ctx_shared *sh)
8183 uint32_t pools_n, us;
8185 pools_n = __atomic_load_n(&sh->cmng.n_valid, __ATOMIC_RELAXED);
8186 us = MLX5_POOL_QUERY_FREQ_US / pools_n;
8187 DRV_LOG(DEBUG, "Set alarm for %u pools each %u us", pools_n, us);
8188 if (rte_eal_alarm_set(us, mlx5_flow_query_alarm, sh)) {
8189 sh->cmng.query_thread_on = 0;
8190 DRV_LOG(ERR, "Cannot reinitialize query alarm");
8192 sh->cmng.query_thread_on = 1;
8197 * The periodic procedure for triggering asynchronous batch queries for all the
8198 * counter pools. This function is probably called by the host thread.
8201 * The parameter for the alarm process.
8204 mlx5_flow_query_alarm(void *arg)
8206 struct mlx5_dev_ctx_shared *sh = arg;
8208 uint16_t pool_index = sh->cmng.pool_index;
8209 struct mlx5_flow_counter_mng *cmng = &sh->cmng;
8210 struct mlx5_flow_counter_pool *pool;
8213 if (sh->cmng.pending_queries >= MLX5_MAX_PENDING_QUERIES)
8215 rte_spinlock_lock(&cmng->pool_update_sl);
8216 pool = cmng->pools[pool_index];
8217 n_valid = cmng->n_valid;
8218 rte_spinlock_unlock(&cmng->pool_update_sl);
8219 /* Set the statistic memory to the new created pool. */
8220 if ((!pool->raw && mlx5_flow_set_counter_stat_mem(sh, pool)))
8223 /* There is a pool query in progress. */
8226 LIST_FIRST(&sh->cmng.free_stat_raws);
8228 /* No free counter statistics raw memory. */
8231 * Identify the counters released between query trigger and query
8232 * handle more efficiently. The counter released in this gap period
8233 * should wait for a new round of query as the new arrived packets
8234 * will not be taken into account.
8237 ret = mlx5_devx_cmd_flow_counter_query(pool->min_dcs, 0,
8238 MLX5_COUNTERS_PER_POOL,
8240 pool->raw_hw->mem_mng->wm.lkey,
8244 (uint64_t)(uintptr_t)pool);
8246 DRV_LOG(ERR, "Failed to trigger asynchronous query for dcs ID"
8247 " %d", pool->min_dcs->id);
8248 pool->raw_hw = NULL;
8251 LIST_REMOVE(pool->raw_hw, next);
8252 sh->cmng.pending_queries++;
8254 if (pool_index >= n_valid)
8257 sh->cmng.pool_index = pool_index;
8258 mlx5_set_query_alarm(sh);
8262 * Check and callback event for new aged flow in the counter pool
8265 * Pointer to mlx5_dev_ctx_shared object.
8267 * Pointer to Current counter pool.
8270 mlx5_flow_aging_check(struct mlx5_dev_ctx_shared *sh,
8271 struct mlx5_flow_counter_pool *pool)
8273 struct mlx5_priv *priv;
8274 struct mlx5_flow_counter *cnt;
8275 struct mlx5_age_info *age_info;
8276 struct mlx5_age_param *age_param;
8277 struct mlx5_counter_stats_raw *cur = pool->raw_hw;
8278 struct mlx5_counter_stats_raw *prev = pool->raw;
8279 const uint64_t curr_time = MLX5_CURR_TIME_SEC;
8280 const uint32_t time_delta = curr_time - pool->time_of_last_age_check;
8281 uint16_t expected = AGE_CANDIDATE;
8284 pool->time_of_last_age_check = curr_time;
8285 for (i = 0; i < MLX5_COUNTERS_PER_POOL; ++i) {
8286 cnt = MLX5_POOL_GET_CNT(pool, i);
8287 age_param = MLX5_CNT_TO_AGE(cnt);
8288 if (__atomic_load_n(&age_param->state,
8289 __ATOMIC_RELAXED) != AGE_CANDIDATE)
8291 if (cur->data[i].hits != prev->data[i].hits) {
8292 __atomic_store_n(&age_param->sec_since_last_hit, 0,
8296 if (__atomic_add_fetch(&age_param->sec_since_last_hit,
8298 __ATOMIC_RELAXED) <= age_param->timeout)
8301 * Hold the lock first, or if between the
8302 * state AGE_TMOUT and tailq operation the
8303 * release happened, the release procedure
8304 * may delete a non-existent tailq node.
8306 priv = rte_eth_devices[age_param->port_id].data->dev_private;
8307 age_info = GET_PORT_AGE_INFO(priv);
8308 rte_spinlock_lock(&age_info->aged_sl);
8309 if (__atomic_compare_exchange_n(&age_param->state, &expected,
8312 __ATOMIC_RELAXED)) {
8313 TAILQ_INSERT_TAIL(&age_info->aged_counters, cnt, next);
8314 MLX5_AGE_SET(age_info, MLX5_AGE_EVENT_NEW);
8316 rte_spinlock_unlock(&age_info->aged_sl);
8318 mlx5_age_event_prepare(sh);
8322 * Handler for the HW respond about ready values from an asynchronous batch
8323 * query. This function is probably called by the host thread.
8326 * The pointer to the shared device context.
8327 * @param[in] async_id
8328 * The Devx async ID.
8330 * The status of the completion.
8333 mlx5_flow_async_pool_query_handle(struct mlx5_dev_ctx_shared *sh,
8334 uint64_t async_id, int status)
8336 struct mlx5_flow_counter_pool *pool =
8337 (struct mlx5_flow_counter_pool *)(uintptr_t)async_id;
8338 struct mlx5_counter_stats_raw *raw_to_free;
8339 uint8_t query_gen = pool->query_gen ^ 1;
8340 struct mlx5_flow_counter_mng *cmng = &sh->cmng;
8341 enum mlx5_counter_type cnt_type =
8342 pool->is_aged ? MLX5_COUNTER_TYPE_AGE :
8343 MLX5_COUNTER_TYPE_ORIGIN;
8345 if (unlikely(status)) {
8346 raw_to_free = pool->raw_hw;
8348 raw_to_free = pool->raw;
8350 mlx5_flow_aging_check(sh, pool);
8351 rte_spinlock_lock(&pool->sl);
8352 pool->raw = pool->raw_hw;
8353 rte_spinlock_unlock(&pool->sl);
8354 /* Be sure the new raw counters data is updated in memory. */
8356 if (!TAILQ_EMPTY(&pool->counters[query_gen])) {
8357 rte_spinlock_lock(&cmng->csl[cnt_type]);
8358 TAILQ_CONCAT(&cmng->counters[cnt_type],
8359 &pool->counters[query_gen], next);
8360 rte_spinlock_unlock(&cmng->csl[cnt_type]);
8363 LIST_INSERT_HEAD(&sh->cmng.free_stat_raws, raw_to_free, next);
8364 pool->raw_hw = NULL;
8365 sh->cmng.pending_queries--;
8369 flow_group_to_table(uint32_t port_id, uint32_t group, uint32_t *table,
8370 const struct flow_grp_info *grp_info,
8371 struct rte_flow_error *error)
8373 if (grp_info->transfer && grp_info->external &&
8374 grp_info->fdb_def_rule) {
8375 if (group == UINT32_MAX)
8376 return rte_flow_error_set
8378 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
8380 "group index not supported");
8385 DRV_LOG(DEBUG, "port %u group=%#x table=%#x", port_id, group, *table);
8390 * Translate the rte_flow group index to HW table value.
8392 * If tunnel offload is disabled, all group ids converted to flow table
8393 * id using the standard method.
8394 * If tunnel offload is enabled, group id can be converted using the
8395 * standard or tunnel conversion method. Group conversion method
8396 * selection depends on flags in `grp_info` parameter:
8397 * - Internal (grp_info.external == 0) groups conversion uses the
8399 * - Group ids in JUMP action converted with the tunnel conversion.
8400 * - Group id in rule attribute conversion depends on a rule type and
8402 * ** non zero group attributes converted with the tunnel method
8403 * ** zero group attribute in non-tunnel rule is converted using the
8404 * standard method - there's only one root table
8405 * ** zero group attribute in steer tunnel rule is converted with the
8406 * standard method - single root table
8407 * ** zero group attribute in match tunnel rule is a special OvS
8408 * case: that value is used for portability reasons. That group
8409 * id is converted with the tunnel conversion method.
8414 * PMD tunnel offload object
8416 * rte_flow group index value.
8419 * @param[in] grp_info
8420 * flags used for conversion
8422 * Pointer to error structure.
8425 * 0 on success, a negative errno value otherwise and rte_errno is set.
8428 mlx5_flow_group_to_table(struct rte_eth_dev *dev,
8429 const struct mlx5_flow_tunnel *tunnel,
8430 uint32_t group, uint32_t *table,
8431 const struct flow_grp_info *grp_info,
8432 struct rte_flow_error *error)
8435 bool standard_translation;
8437 if (!grp_info->skip_scale && grp_info->external &&
8438 group < MLX5_MAX_TABLES_EXTERNAL)
8439 group *= MLX5_FLOW_TABLE_FACTOR;
8440 if (is_tunnel_offload_active(dev)) {
8441 standard_translation = !grp_info->external ||
8442 grp_info->std_tbl_fix;
8444 standard_translation = true;
8447 "port %u group=%u transfer=%d external=%d fdb_def_rule=%d translate=%s",
8448 dev->data->port_id, group, grp_info->transfer,
8449 grp_info->external, grp_info->fdb_def_rule,
8450 standard_translation ? "STANDARD" : "TUNNEL");
8451 if (standard_translation)
8452 ret = flow_group_to_table(dev->data->port_id, group, table,
8455 ret = tunnel_flow_group_to_flow_table(dev, tunnel, group,
8462 * Discover availability of metadata reg_c's.
8464 * Iteratively use test flows to check availability.
8467 * Pointer to the Ethernet device structure.
8470 * 0 on success, a negative errno value otherwise and rte_errno is set.
8473 mlx5_flow_discover_mreg_c(struct rte_eth_dev *dev)
8475 struct mlx5_priv *priv = dev->data->dev_private;
8476 enum modify_reg idx;
8479 /* reg_c[0] and reg_c[1] are reserved. */
8480 priv->sh->flow_mreg_c[n++] = REG_C_0;
8481 priv->sh->flow_mreg_c[n++] = REG_C_1;
8482 /* Discover availability of other reg_c's. */
8483 for (idx = REG_C_2; idx <= REG_C_7; ++idx) {
8484 struct rte_flow_attr attr = {
8485 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
8486 .priority = MLX5_FLOW_LOWEST_PRIO_INDICATOR,
8489 struct rte_flow_item items[] = {
8491 .type = RTE_FLOW_ITEM_TYPE_END,
8494 struct rte_flow_action actions[] = {
8496 .type = (enum rte_flow_action_type)
8497 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
8498 .conf = &(struct mlx5_flow_action_copy_mreg){
8504 .type = RTE_FLOW_ACTION_TYPE_JUMP,
8505 .conf = &(struct rte_flow_action_jump){
8506 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
8510 .type = RTE_FLOW_ACTION_TYPE_END,
8514 struct rte_flow *flow;
8515 struct rte_flow_error error;
8517 if (!priv->sh->config.dv_flow_en)
8519 /* Create internal flow, validation skips copy action. */
8520 flow_idx = flow_list_create(dev, MLX5_FLOW_TYPE_GEN, &attr,
8521 items, actions, false, &error);
8522 flow = mlx5_ipool_get(priv->flows[MLX5_FLOW_TYPE_GEN],
8526 priv->sh->flow_mreg_c[n++] = idx;
8527 flow_list_destroy(dev, MLX5_FLOW_TYPE_GEN, flow_idx);
8529 for (; n < MLX5_MREG_C_NUM; ++n)
8530 priv->sh->flow_mreg_c[n] = REG_NON;
8531 priv->sh->metadata_regc_check_flag = 1;
8536 save_dump_file(const uint8_t *data, uint32_t size,
8537 uint32_t type, uint64_t id, void *arg, FILE *file)
8539 char line[BUF_SIZE];
8542 uint32_t actions_num;
8543 struct rte_flow_query_count *count;
8545 memset(line, 0, BUF_SIZE);
8547 case DR_DUMP_REC_TYPE_PMD_MODIFY_HDR:
8548 actions_num = *(uint32_t *)(arg);
8549 out += snprintf(line + out, BUF_SIZE - out, "%d,0x%" PRIx64 ",%d,",
8550 type, id, actions_num);
8552 case DR_DUMP_REC_TYPE_PMD_PKT_REFORMAT:
8553 out += snprintf(line + out, BUF_SIZE - out, "%d,0x%" PRIx64 ",",
8556 case DR_DUMP_REC_TYPE_PMD_COUNTER:
8557 count = (struct rte_flow_query_count *)arg;
8559 "%d,0x%" PRIx64 ",%" PRIu64 ",%" PRIu64 "\n",
8560 type, id, count->hits, count->bytes);
8566 for (k = 0; k < size; k++) {
8567 /* Make sure we do not overrun the line buffer length. */
8568 if (out >= BUF_SIZE - 4) {
8572 out += snprintf(line + out, BUF_SIZE - out, "%02x",
8575 fprintf(file, "%s\n", line);
8580 mlx5_flow_query_counter(struct rte_eth_dev *dev, struct rte_flow *flow,
8581 struct rte_flow_query_count *count, struct rte_flow_error *error)
8583 struct rte_flow_action action[2];
8584 enum mlx5_flow_drv_type ftype;
8585 const struct mlx5_flow_driver_ops *fops;
8588 return rte_flow_error_set(error, ENOENT,
8589 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8591 "invalid flow handle");
8593 action[0].type = RTE_FLOW_ACTION_TYPE_COUNT;
8594 action[1].type = RTE_FLOW_ACTION_TYPE_END;
8595 if (flow->counter) {
8596 memset(count, 0, sizeof(struct rte_flow_query_count));
8597 ftype = (enum mlx5_flow_drv_type)(flow->drv_type);
8598 MLX5_ASSERT(ftype > MLX5_FLOW_TYPE_MIN &&
8599 ftype < MLX5_FLOW_TYPE_MAX);
8600 fops = flow_get_drv_ops(ftype);
8601 return fops->query(dev, flow, action, count, error);
8606 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
8608 * Dump flow ipool data to file
8611 * The pointer to Ethernet device.
8613 * A pointer to a file for output.
8615 * Perform verbose error reporting if not NULL. PMDs initialize this
8616 * structure in case of error only.
8618 * 0 on success, a negative value otherwise.
8621 mlx5_flow_dev_dump_ipool(struct rte_eth_dev *dev,
8622 struct rte_flow *flow, FILE *file,
8623 struct rte_flow_error *error)
8625 struct mlx5_priv *priv = dev->data->dev_private;
8626 struct mlx5_flow_dv_modify_hdr_resource *modify_hdr;
8627 struct mlx5_flow_dv_encap_decap_resource *encap_decap;
8628 uint32_t handle_idx;
8629 struct mlx5_flow_handle *dh;
8630 struct rte_flow_query_count count;
8631 uint32_t actions_num;
8632 const uint8_t *data;
8636 void *action = NULL;
8639 return rte_flow_error_set(error, ENOENT,
8640 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8642 "invalid flow handle");
8644 handle_idx = flow->dev_handles;
8646 if (flow->counter &&
8647 (!mlx5_counter_query(dev, flow->counter, false,
8648 &count.hits, &count.bytes, &action)) && action) {
8649 id = (uint64_t)(uintptr_t)action;
8650 type = DR_DUMP_REC_TYPE_PMD_COUNTER;
8651 save_dump_file(NULL, 0, type,
8652 id, (void *)&count, file);
8655 while (handle_idx) {
8656 dh = mlx5_ipool_get(priv->sh->ipool
8657 [MLX5_IPOOL_MLX5_FLOW], handle_idx);
8660 handle_idx = dh->next.next;
8662 /* Get modify_hdr and encap_decap buf from ipools. */
8664 modify_hdr = dh->dvh.modify_hdr;
8666 if (dh->dvh.rix_encap_decap) {
8667 encap_decap = mlx5_ipool_get(priv->sh->ipool
8668 [MLX5_IPOOL_DECAP_ENCAP],
8669 dh->dvh.rix_encap_decap);
8672 data = (const uint8_t *)modify_hdr->actions;
8673 size = (size_t)(modify_hdr->actions_num) * 8;
8674 id = (uint64_t)(uintptr_t)modify_hdr->action;
8675 actions_num = modify_hdr->actions_num;
8676 type = DR_DUMP_REC_TYPE_PMD_MODIFY_HDR;
8677 save_dump_file(data, size, type, id,
8678 (void *)(&actions_num), file);
8681 data = encap_decap->buf;
8682 size = encap_decap->size;
8683 id = (uint64_t)(uintptr_t)encap_decap->action;
8684 type = DR_DUMP_REC_TYPE_PMD_PKT_REFORMAT;
8685 save_dump_file(data, size, type,
8693 * Dump all flow's encap_decap/modify_hdr/counter data to file
8696 * The pointer to Ethernet device.
8698 * A pointer to a file for output.
8700 * Perform verbose error reporting if not NULL. PMDs initialize this
8701 * structure in case of error only.
8703 * 0 on success, a negative value otherwise.
8706 mlx5_flow_dev_dump_sh_all(struct rte_eth_dev *dev,
8707 FILE *file, struct rte_flow_error *error __rte_unused)
8709 struct mlx5_priv *priv = dev->data->dev_private;
8710 struct mlx5_dev_ctx_shared *sh = priv->sh;
8711 struct mlx5_hlist *h;
8712 struct mlx5_flow_dv_modify_hdr_resource *modify_hdr;
8713 struct mlx5_flow_dv_encap_decap_resource *encap_decap;
8714 struct rte_flow_query_count count;
8715 uint32_t actions_num;
8716 const uint8_t *data;
8722 struct mlx5_list_inconst *l_inconst;
8723 struct mlx5_list_entry *e;
8725 struct mlx5_flow_counter_mng *cmng = &priv->sh->cmng;
8729 /* encap_decap hlist is lcore_share, get global core cache. */
8730 i = MLX5_LIST_GLOBAL;
8731 h = sh->encaps_decaps;
8733 for (j = 0; j <= h->mask; j++) {
8734 l_inconst = &h->buckets[j].l;
8735 if (!l_inconst || !l_inconst->cache[i])
8738 e = LIST_FIRST(&l_inconst->cache[i]->h);
8741 (struct mlx5_flow_dv_encap_decap_resource *)e;
8742 data = encap_decap->buf;
8743 size = encap_decap->size;
8744 id = (uint64_t)(uintptr_t)encap_decap->action;
8745 type = DR_DUMP_REC_TYPE_PMD_PKT_REFORMAT;
8746 save_dump_file(data, size, type,
8748 e = LIST_NEXT(e, next);
8753 /* get modify_hdr */
8754 h = sh->modify_cmds;
8756 lcore_index = rte_lcore_index(rte_lcore_id());
8757 if (unlikely(lcore_index == -1)) {
8758 lcore_index = MLX5_LIST_NLCORE;
8759 rte_spinlock_lock(&h->l_const.lcore_lock);
8763 for (j = 0; j <= h->mask; j++) {
8764 l_inconst = &h->buckets[j].l;
8765 if (!l_inconst || !l_inconst->cache[i])
8768 e = LIST_FIRST(&l_inconst->cache[i]->h);
8771 (struct mlx5_flow_dv_modify_hdr_resource *)e;
8772 data = (const uint8_t *)modify_hdr->actions;
8773 size = (size_t)(modify_hdr->actions_num) * 8;
8774 actions_num = modify_hdr->actions_num;
8775 id = (uint64_t)(uintptr_t)modify_hdr->action;
8776 type = DR_DUMP_REC_TYPE_PMD_MODIFY_HDR;
8777 save_dump_file(data, size, type, id,
8778 (void *)(&actions_num), file);
8779 e = LIST_NEXT(e, next);
8783 if (unlikely(lcore_index == MLX5_LIST_NLCORE))
8784 rte_spinlock_unlock(&h->l_const.lcore_lock);
8788 MLX5_ASSERT(cmng->n_valid <= cmng->n);
8789 max = MLX5_COUNTERS_PER_POOL * cmng->n_valid;
8790 for (j = 1; j <= max; j++) {
8792 if ((!mlx5_counter_query(dev, j, false, &count.hits,
8793 &count.bytes, &action)) && action) {
8794 id = (uint64_t)(uintptr_t)action;
8795 type = DR_DUMP_REC_TYPE_PMD_COUNTER;
8796 save_dump_file(NULL, 0, type,
8797 id, (void *)&count, file);
8805 * Dump flow raw hw data to file
8808 * The pointer to Ethernet device.
8810 * A pointer to a file for output.
8812 * Perform verbose error reporting if not NULL. PMDs initialize this
8813 * structure in case of error only.
8815 * 0 on success, a negative value otherwise.
8818 mlx5_flow_dev_dump(struct rte_eth_dev *dev, struct rte_flow *flow_idx,
8820 struct rte_flow_error *error __rte_unused)
8822 struct mlx5_priv *priv = dev->data->dev_private;
8823 struct mlx5_dev_ctx_shared *sh = priv->sh;
8824 uint32_t handle_idx;
8826 struct mlx5_flow_handle *dh;
8827 struct rte_flow *flow;
8829 if (!sh->config.dv_flow_en) {
8830 if (fputs("device dv flow disabled\n", file) <= 0)
8837 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
8838 if (mlx5_flow_dev_dump_sh_all(dev, file, error))
8841 return mlx5_devx_cmd_flow_dump(sh->fdb_domain,
8843 sh->tx_domain, file);
8846 flow = mlx5_ipool_get(priv->flows[MLX5_FLOW_TYPE_GEN],
8847 (uintptr_t)(void *)flow_idx);
8851 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
8852 mlx5_flow_dev_dump_ipool(dev, flow, file, error);
8854 handle_idx = flow->dev_handles;
8855 while (handle_idx) {
8856 dh = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
8861 ret = mlx5_devx_cmd_flow_single_dump(dh->drv_flow,
8866 handle_idx = dh->next.next;
8872 * Get aged-out flows.
8875 * Pointer to the Ethernet device structure.
8876 * @param[in] context
8877 * The address of an array of pointers to the aged-out flows contexts.
8878 * @param[in] nb_countexts
8879 * The length of context array pointers.
8881 * Perform verbose error reporting if not NULL. Initialized in case of
8885 * how many contexts get in success, otherwise negative errno value.
8886 * if nb_contexts is 0, return the amount of all aged contexts.
8887 * if nb_contexts is not 0 , return the amount of aged flows reported
8888 * in the context array.
8891 mlx5_flow_get_aged_flows(struct rte_eth_dev *dev, void **contexts,
8892 uint32_t nb_contexts, struct rte_flow_error *error)
8894 const struct mlx5_flow_driver_ops *fops;
8895 struct rte_flow_attr attr = { .transfer = 0 };
8897 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
8898 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
8899 return fops->get_aged_flows(dev, contexts, nb_contexts,
8903 "port %u get aged flows is not supported.",
8904 dev->data->port_id);
8908 /* Wrapper for driver action_validate op callback */
8910 flow_drv_action_validate(struct rte_eth_dev *dev,
8911 const struct rte_flow_indir_action_conf *conf,
8912 const struct rte_flow_action *action,
8913 const struct mlx5_flow_driver_ops *fops,
8914 struct rte_flow_error *error)
8916 static const char err_msg[] = "indirect action validation unsupported";
8918 if (!fops->action_validate) {
8919 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
8920 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
8924 return fops->action_validate(dev, conf, action, error);
8928 * Destroys the shared action by handle.
8931 * Pointer to Ethernet device structure.
8933 * Handle for the indirect action object to be destroyed.
8935 * Perform verbose error reporting if not NULL. PMDs initialize this
8936 * structure in case of error only.
8939 * 0 on success, a negative errno value otherwise and rte_errno is set.
8941 * @note: wrapper for driver action_create op callback.
8944 mlx5_action_handle_destroy(struct rte_eth_dev *dev,
8945 struct rte_flow_action_handle *handle,
8946 struct rte_flow_error *error)
8948 static const char err_msg[] = "indirect action destruction unsupported";
8949 struct rte_flow_attr attr = { .transfer = 0 };
8950 const struct mlx5_flow_driver_ops *fops =
8951 flow_get_drv_ops(flow_get_drv_type(dev, &attr));
8953 if (!fops->action_destroy) {
8954 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
8955 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
8959 return fops->action_destroy(dev, handle, error);
8962 /* Wrapper for driver action_destroy op callback */
8964 flow_drv_action_update(struct rte_eth_dev *dev,
8965 struct rte_flow_action_handle *handle,
8967 const struct mlx5_flow_driver_ops *fops,
8968 struct rte_flow_error *error)
8970 static const char err_msg[] = "indirect action update unsupported";
8972 if (!fops->action_update) {
8973 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
8974 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
8978 return fops->action_update(dev, handle, update, error);
8981 /* Wrapper for driver action_destroy op callback */
8983 flow_drv_action_query(struct rte_eth_dev *dev,
8984 const struct rte_flow_action_handle *handle,
8986 const struct mlx5_flow_driver_ops *fops,
8987 struct rte_flow_error *error)
8989 static const char err_msg[] = "indirect action query unsupported";
8991 if (!fops->action_query) {
8992 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
8993 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
8997 return fops->action_query(dev, handle, data, error);
9001 * Create indirect action for reuse in multiple flow rules.
9004 * Pointer to Ethernet device structure.
9006 * Pointer to indirect action object configuration.
9008 * Action configuration for indirect action object creation.
9010 * Perform verbose error reporting if not NULL. PMDs initialize this
9011 * structure in case of error only.
9013 * A valid handle in case of success, NULL otherwise and rte_errno is set.
9015 static struct rte_flow_action_handle *
9016 mlx5_action_handle_create(struct rte_eth_dev *dev,
9017 const struct rte_flow_indir_action_conf *conf,
9018 const struct rte_flow_action *action,
9019 struct rte_flow_error *error)
9021 static const char err_msg[] = "indirect action creation unsupported";
9022 struct rte_flow_attr attr = { .transfer = 0 };
9023 const struct mlx5_flow_driver_ops *fops =
9024 flow_get_drv_ops(flow_get_drv_type(dev, &attr));
9026 if (flow_drv_action_validate(dev, conf, action, fops, error))
9028 if (!fops->action_create) {
9029 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
9030 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
9034 return fops->action_create(dev, conf, action, error);
9038 * Updates inplace the indirect action configuration pointed by *handle*
9039 * with the configuration provided as *update* argument.
9040 * The update of the indirect action configuration effects all flow rules
9041 * reusing the action via handle.
9044 * Pointer to Ethernet device structure.
9046 * Handle for the indirect action to be updated.
9048 * Action specification used to modify the action pointed by handle.
9049 * *update* could be of same type with the action pointed by the *handle*
9050 * handle argument, or some other structures like a wrapper, depending on
9051 * the indirect action type.
9053 * Perform verbose error reporting if not NULL. PMDs initialize this
9054 * structure in case of error only.
9057 * 0 on success, a negative errno value otherwise and rte_errno is set.
9060 mlx5_action_handle_update(struct rte_eth_dev *dev,
9061 struct rte_flow_action_handle *handle,
9063 struct rte_flow_error *error)
9065 struct rte_flow_attr attr = { .transfer = 0 };
9066 const struct mlx5_flow_driver_ops *fops =
9067 flow_get_drv_ops(flow_get_drv_type(dev, &attr));
9070 ret = flow_drv_action_validate(dev, NULL,
9071 (const struct rte_flow_action *)update, fops, error);
9074 return flow_drv_action_update(dev, handle, update, fops,
9079 * Query the indirect action by handle.
9081 * This function allows retrieving action-specific data such as counters.
9082 * Data is gathered by special action which may be present/referenced in
9083 * more than one flow rule definition.
9085 * see @RTE_FLOW_ACTION_TYPE_COUNT
9088 * Pointer to Ethernet device structure.
9090 * Handle for the indirect action to query.
9091 * @param[in, out] data
9092 * Pointer to storage for the associated query data type.
9094 * Perform verbose error reporting if not NULL. PMDs initialize this
9095 * structure in case of error only.
9098 * 0 on success, a negative errno value otherwise and rte_errno is set.
9101 mlx5_action_handle_query(struct rte_eth_dev *dev,
9102 const struct rte_flow_action_handle *handle,
9104 struct rte_flow_error *error)
9106 struct rte_flow_attr attr = { .transfer = 0 };
9107 const struct mlx5_flow_driver_ops *fops =
9108 flow_get_drv_ops(flow_get_drv_type(dev, &attr));
9110 return flow_drv_action_query(dev, handle, data, fops, error);
9114 * Destroy all indirect actions (shared RSS).
9117 * Pointer to Ethernet device.
9120 * 0 on success, a negative errno value otherwise and rte_errno is set.
9123 mlx5_action_handle_flush(struct rte_eth_dev *dev)
9125 struct rte_flow_error error;
9126 struct mlx5_priv *priv = dev->data->dev_private;
9127 struct mlx5_shared_action_rss *shared_rss;
9131 ILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
9132 priv->rss_shared_actions, idx, shared_rss, next) {
9133 ret |= mlx5_action_handle_destroy(dev,
9134 (struct rte_flow_action_handle *)(uintptr_t)idx, &error);
9140 * Validate existing indirect actions against current device configuration
9141 * and attach them to device resources.
9144 * Pointer to Ethernet device.
9147 * 0 on success, a negative errno value otherwise and rte_errno is set.
9150 mlx5_action_handle_attach(struct rte_eth_dev *dev)
9152 struct mlx5_priv *priv = dev->data->dev_private;
9153 struct mlx5_indexed_pool *ipool =
9154 priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS];
9155 struct mlx5_shared_action_rss *shared_rss, *shared_rss_last;
9159 ILIST_FOREACH(ipool, priv->rss_shared_actions, idx, shared_rss, next) {
9160 struct mlx5_ind_table_obj *ind_tbl = shared_rss->ind_tbl;
9161 const char *message;
9164 ret = mlx5_validate_rss_queues(dev, ind_tbl->queues,
9166 &message, &queue_idx);
9168 DRV_LOG(ERR, "Port %u cannot use queue %u in RSS: %s",
9169 dev->data->port_id, ind_tbl->queues[queue_idx],
9176 ILIST_FOREACH(ipool, priv->rss_shared_actions, idx, shared_rss, next) {
9177 struct mlx5_ind_table_obj *ind_tbl = shared_rss->ind_tbl;
9179 ret = mlx5_ind_table_obj_attach(dev, ind_tbl);
9181 DRV_LOG(ERR, "Port %u could not attach "
9182 "indirection table obj %p",
9183 dev->data->port_id, (void *)ind_tbl);
9189 shared_rss_last = shared_rss;
9190 ILIST_FOREACH(ipool, priv->rss_shared_actions, idx, shared_rss, next) {
9191 struct mlx5_ind_table_obj *ind_tbl = shared_rss->ind_tbl;
9193 if (shared_rss == shared_rss_last)
9195 if (mlx5_ind_table_obj_detach(dev, ind_tbl) != 0)
9196 DRV_LOG(CRIT, "Port %u could not detach "
9197 "indirection table obj %p on rollback",
9198 dev->data->port_id, (void *)ind_tbl);
9204 * Detach indirect actions of the device from its resources.
9207 * Pointer to Ethernet device.
9210 * 0 on success, a negative errno value otherwise and rte_errno is set.
9213 mlx5_action_handle_detach(struct rte_eth_dev *dev)
9215 struct mlx5_priv *priv = dev->data->dev_private;
9216 struct mlx5_indexed_pool *ipool =
9217 priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS];
9218 struct mlx5_shared_action_rss *shared_rss, *shared_rss_last;
9222 ILIST_FOREACH(ipool, priv->rss_shared_actions, idx, shared_rss, next) {
9223 struct mlx5_ind_table_obj *ind_tbl = shared_rss->ind_tbl;
9225 ret = mlx5_ind_table_obj_detach(dev, ind_tbl);
9227 DRV_LOG(ERR, "Port %u could not detach "
9228 "indirection table obj %p",
9229 dev->data->port_id, (void *)ind_tbl);
9235 shared_rss_last = shared_rss;
9236 ILIST_FOREACH(ipool, priv->rss_shared_actions, idx, shared_rss, next) {
9237 struct mlx5_ind_table_obj *ind_tbl = shared_rss->ind_tbl;
9239 if (shared_rss == shared_rss_last)
9241 if (mlx5_ind_table_obj_attach(dev, ind_tbl) != 0)
9242 DRV_LOG(CRIT, "Port %u could not attach "
9243 "indirection table obj %p on rollback",
9244 dev->data->port_id, (void *)ind_tbl);
9249 #ifndef HAVE_MLX5DV_DR
9250 #define MLX5_DOMAIN_SYNC_FLOW ((1 << 0) | (1 << 1))
9252 #define MLX5_DOMAIN_SYNC_FLOW \
9253 (MLX5DV_DR_DOMAIN_SYNC_FLAGS_SW | MLX5DV_DR_DOMAIN_SYNC_FLAGS_HW)
9256 int rte_pmd_mlx5_sync_flow(uint16_t port_id, uint32_t domains)
9258 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
9259 const struct mlx5_flow_driver_ops *fops;
9261 struct rte_flow_attr attr = { .transfer = 0 };
9263 fops = flow_get_drv_ops(flow_get_drv_type(dev, &attr));
9264 ret = fops->sync_domain(dev, domains, MLX5_DOMAIN_SYNC_FLOW);
9270 const struct mlx5_flow_tunnel *
9271 mlx5_get_tof(const struct rte_flow_item *item,
9272 const struct rte_flow_action *action,
9273 enum mlx5_tof_rule_type *rule_type)
9275 for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
9276 if (item->type == (typeof(item->type))
9277 MLX5_RTE_FLOW_ITEM_TYPE_TUNNEL) {
9278 *rule_type = MLX5_TUNNEL_OFFLOAD_MATCH_RULE;
9279 return flow_items_to_tunnel(item);
9282 for (; action->conf != RTE_FLOW_ACTION_TYPE_END; action++) {
9283 if (action->type == (typeof(action->type))
9284 MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET) {
9285 *rule_type = MLX5_TUNNEL_OFFLOAD_SET_RULE;
9286 return flow_actions_to_tunnel(action);
9293 * tunnel offload functionality is defined for DV environment only
9295 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
9297 union tunnel_offload_mark {
9300 uint32_t app_reserve:8;
9301 uint32_t table_id:15;
9302 uint32_t transfer:1;
9303 uint32_t _unused_:8;
9308 mlx5_access_tunnel_offload_db
9309 (struct rte_eth_dev *dev,
9310 bool (*match)(struct rte_eth_dev *,
9311 struct mlx5_flow_tunnel *, const void *),
9312 void (*hit)(struct rte_eth_dev *, struct mlx5_flow_tunnel *, void *),
9313 void (*miss)(struct rte_eth_dev *, void *),
9314 void *ctx, bool lock_op);
9317 flow_tunnel_add_default_miss(struct rte_eth_dev *dev,
9318 struct rte_flow *flow,
9319 const struct rte_flow_attr *attr,
9320 const struct rte_flow_action *app_actions,
9322 const struct mlx5_flow_tunnel *tunnel,
9323 struct tunnel_default_miss_ctx *ctx,
9324 struct rte_flow_error *error)
9326 struct mlx5_priv *priv = dev->data->dev_private;
9327 struct mlx5_flow *dev_flow;
9328 struct rte_flow_attr miss_attr = *attr;
9329 const struct rte_flow_item miss_items[2] = {
9331 .type = RTE_FLOW_ITEM_TYPE_ETH,
9337 .type = RTE_FLOW_ITEM_TYPE_END,
9343 union tunnel_offload_mark mark_id;
9344 struct rte_flow_action_mark miss_mark;
9345 struct rte_flow_action miss_actions[3] = {
9346 [0] = { .type = RTE_FLOW_ACTION_TYPE_MARK, .conf = &miss_mark },
9347 [2] = { .type = RTE_FLOW_ACTION_TYPE_END, .conf = NULL }
9349 const struct rte_flow_action_jump *jump_data;
9350 uint32_t i, flow_table = 0; /* prevent compilation warning */
9351 struct flow_grp_info grp_info = {
9353 .transfer = attr->transfer,
9354 .fdb_def_rule = !!priv->fdb_def_rule,
9359 if (!attr->transfer) {
9362 miss_actions[1].type = RTE_FLOW_ACTION_TYPE_RSS;
9363 q_size = priv->reta_idx_n * sizeof(ctx->queue[0]);
9364 ctx->queue = mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO, q_size,
9367 return rte_flow_error_set
9369 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
9370 NULL, "invalid default miss RSS");
9371 ctx->action_rss.func = RTE_ETH_HASH_FUNCTION_DEFAULT,
9372 ctx->action_rss.level = 0,
9373 ctx->action_rss.types = priv->rss_conf.rss_hf,
9374 ctx->action_rss.key_len = priv->rss_conf.rss_key_len,
9375 ctx->action_rss.queue_num = priv->reta_idx_n,
9376 ctx->action_rss.key = priv->rss_conf.rss_key,
9377 ctx->action_rss.queue = ctx->queue;
9378 if (!priv->reta_idx_n || !priv->rxqs_n)
9379 return rte_flow_error_set
9381 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
9382 NULL, "invalid port configuration");
9383 if (!(dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_RSS_FLAG))
9384 ctx->action_rss.types = 0;
9385 for (i = 0; i != priv->reta_idx_n; ++i)
9386 ctx->queue[i] = (*priv->reta_idx)[i];
9388 miss_actions[1].type = RTE_FLOW_ACTION_TYPE_JUMP;
9389 ctx->miss_jump.group = MLX5_TNL_MISS_FDB_JUMP_GRP;
9391 miss_actions[1].conf = (typeof(miss_actions[1].conf))ctx->raw;
9392 for (; app_actions->type != RTE_FLOW_ACTION_TYPE_JUMP; app_actions++);
9393 jump_data = app_actions->conf;
9394 miss_attr.priority = MLX5_TNL_MISS_RULE_PRIORITY;
9395 miss_attr.group = jump_data->group;
9396 ret = mlx5_flow_group_to_table(dev, tunnel, jump_data->group,
9397 &flow_table, &grp_info, error);
9399 return rte_flow_error_set(error, EINVAL,
9400 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
9401 NULL, "invalid tunnel id");
9402 mark_id.app_reserve = 0;
9403 mark_id.table_id = tunnel_flow_tbl_to_id(flow_table);
9404 mark_id.transfer = !!attr->transfer;
9405 mark_id._unused_ = 0;
9406 miss_mark.id = mark_id.val;
9407 dev_flow = flow_drv_prepare(dev, flow, &miss_attr,
9408 miss_items, miss_actions, flow_idx, error);
9411 dev_flow->flow = flow;
9412 dev_flow->external = true;
9413 dev_flow->tunnel = tunnel;
9414 dev_flow->tof_type = MLX5_TUNNEL_OFFLOAD_MISS_RULE;
9415 /* Subflow object was created, we must include one in the list. */
9416 SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
9417 dev_flow->handle, next);
9419 "port %u tunnel type=%d id=%u miss rule priority=%u group=%u",
9420 dev->data->port_id, tunnel->app_tunnel.type,
9421 tunnel->tunnel_id, miss_attr.priority, miss_attr.group);
9422 ret = flow_drv_translate(dev, dev_flow, &miss_attr, miss_items,
9423 miss_actions, error);
9425 ret = flow_mreg_update_copy_table(dev, flow, miss_actions,
9431 static const struct mlx5_flow_tbl_data_entry *
9432 tunnel_mark_decode(struct rte_eth_dev *dev, uint32_t mark)
9434 struct mlx5_priv *priv = dev->data->dev_private;
9435 struct mlx5_dev_ctx_shared *sh = priv->sh;
9436 struct mlx5_list_entry *he;
9437 union tunnel_offload_mark mbits = { .val = mark };
9438 union mlx5_flow_tbl_key table_key = {
9440 .level = tunnel_id_to_flow_tbl(mbits.table_id),
9444 .is_fdb = !!mbits.transfer,
9448 struct mlx5_flow_cb_ctx ctx = {
9449 .data = &table_key.v64,
9452 he = mlx5_hlist_lookup(sh->flow_tbls, table_key.v64, &ctx);
9454 container_of(he, struct mlx5_flow_tbl_data_entry, entry) : NULL;
9458 mlx5_flow_tunnel_grp2tbl_remove_cb(void *tool_ctx,
9459 struct mlx5_list_entry *entry)
9461 struct mlx5_dev_ctx_shared *sh = tool_ctx;
9462 struct tunnel_tbl_entry *tte = container_of(entry, typeof(*tte), hash);
9464 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TNL_TBL_ID],
9465 tunnel_flow_tbl_to_id(tte->flow_table));
9470 mlx5_flow_tunnel_grp2tbl_match_cb(void *tool_ctx __rte_unused,
9471 struct mlx5_list_entry *entry, void *cb_ctx)
9473 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
9474 union tunnel_tbl_key tbl = {
9475 .val = *(uint64_t *)(ctx->data),
9477 struct tunnel_tbl_entry *tte = container_of(entry, typeof(*tte), hash);
9479 return tbl.tunnel_id != tte->tunnel_id || tbl.group != tte->group;
9482 static struct mlx5_list_entry *
9483 mlx5_flow_tunnel_grp2tbl_create_cb(void *tool_ctx, void *cb_ctx)
9485 struct mlx5_dev_ctx_shared *sh = tool_ctx;
9486 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
9487 struct tunnel_tbl_entry *tte;
9488 union tunnel_tbl_key tbl = {
9489 .val = *(uint64_t *)(ctx->data),
9492 tte = mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO,
9497 mlx5_ipool_malloc(sh->ipool[MLX5_IPOOL_TNL_TBL_ID],
9499 if (tte->flow_table >= MLX5_MAX_TABLES) {
9500 DRV_LOG(ERR, "Tunnel TBL ID %d exceed max limit.",
9502 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TNL_TBL_ID],
9505 } else if (!tte->flow_table) {
9508 tte->flow_table = tunnel_id_to_flow_tbl(tte->flow_table);
9509 tte->tunnel_id = tbl.tunnel_id;
9510 tte->group = tbl.group;
9518 static struct mlx5_list_entry *
9519 mlx5_flow_tunnel_grp2tbl_clone_cb(void *tool_ctx __rte_unused,
9520 struct mlx5_list_entry *oentry,
9521 void *cb_ctx __rte_unused)
9523 struct tunnel_tbl_entry *tte = mlx5_malloc(MLX5_MEM_SYS, sizeof(*tte),
9528 memcpy(tte, oentry, sizeof(*tte));
9533 mlx5_flow_tunnel_grp2tbl_clone_free_cb(void *tool_ctx __rte_unused,
9534 struct mlx5_list_entry *entry)
9536 struct tunnel_tbl_entry *tte = container_of(entry, typeof(*tte), hash);
9542 tunnel_flow_group_to_flow_table(struct rte_eth_dev *dev,
9543 const struct mlx5_flow_tunnel *tunnel,
9544 uint32_t group, uint32_t *table,
9545 struct rte_flow_error *error)
9547 struct mlx5_list_entry *he;
9548 struct tunnel_tbl_entry *tte;
9549 union tunnel_tbl_key key = {
9550 .tunnel_id = tunnel ? tunnel->tunnel_id : 0,
9553 struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
9554 struct mlx5_hlist *group_hash;
9555 struct mlx5_flow_cb_ctx ctx = {
9559 group_hash = tunnel ? tunnel->groups : thub->groups;
9560 he = mlx5_hlist_register(group_hash, key.val, &ctx);
9562 return rte_flow_error_set(error, EINVAL,
9563 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
9565 "tunnel group index not supported");
9566 tte = container_of(he, typeof(*tte), hash);
9567 *table = tte->flow_table;
9568 DRV_LOG(DEBUG, "port %u tunnel %u group=%#x table=%#x",
9569 dev->data->port_id, key.tunnel_id, group, *table);
9574 mlx5_flow_tunnel_free(struct rte_eth_dev *dev,
9575 struct mlx5_flow_tunnel *tunnel)
9577 struct mlx5_priv *priv = dev->data->dev_private;
9578 struct mlx5_indexed_pool *ipool;
9580 DRV_LOG(DEBUG, "port %u release pmd tunnel id=0x%x",
9581 dev->data->port_id, tunnel->tunnel_id);
9582 LIST_REMOVE(tunnel, chain);
9583 mlx5_hlist_destroy(tunnel->groups);
9584 ipool = priv->sh->ipool[MLX5_IPOOL_TUNNEL_ID];
9585 mlx5_ipool_free(ipool, tunnel->tunnel_id);
9589 mlx5_access_tunnel_offload_db
9590 (struct rte_eth_dev *dev,
9591 bool (*match)(struct rte_eth_dev *,
9592 struct mlx5_flow_tunnel *, const void *),
9593 void (*hit)(struct rte_eth_dev *, struct mlx5_flow_tunnel *, void *),
9594 void (*miss)(struct rte_eth_dev *, void *),
9595 void *ctx, bool lock_op)
9597 bool verdict = false;
9598 struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
9599 struct mlx5_flow_tunnel *tunnel;
9601 rte_spinlock_lock(&thub->sl);
9602 LIST_FOREACH(tunnel, &thub->tunnels, chain) {
9603 verdict = match(dev, tunnel, (const void *)ctx);
9608 rte_spinlock_unlock(&thub->sl);
9610 hit(dev, tunnel, ctx);
9611 if (!verdict && miss)
9614 rte_spinlock_unlock(&thub->sl);
9619 struct tunnel_db_find_tunnel_id_ctx {
9621 struct mlx5_flow_tunnel *tunnel;
9625 find_tunnel_id_match(struct rte_eth_dev *dev,
9626 struct mlx5_flow_tunnel *tunnel, const void *x)
9628 const struct tunnel_db_find_tunnel_id_ctx *ctx = x;
9631 return tunnel->tunnel_id == ctx->tunnel_id;
9635 find_tunnel_id_hit(struct rte_eth_dev *dev,
9636 struct mlx5_flow_tunnel *tunnel, void *x)
9638 struct tunnel_db_find_tunnel_id_ctx *ctx = x;
9640 ctx->tunnel = tunnel;
9643 static struct mlx5_flow_tunnel *
9644 mlx5_find_tunnel_id(struct rte_eth_dev *dev, uint32_t id)
9646 struct tunnel_db_find_tunnel_id_ctx ctx = {
9650 mlx5_access_tunnel_offload_db(dev, find_tunnel_id_match,
9651 find_tunnel_id_hit, NULL, &ctx, true);
9656 static struct mlx5_flow_tunnel *
9657 mlx5_flow_tunnel_allocate(struct rte_eth_dev *dev,
9658 const struct rte_flow_tunnel *app_tunnel)
9660 struct mlx5_priv *priv = dev->data->dev_private;
9661 struct mlx5_indexed_pool *ipool;
9662 struct mlx5_flow_tunnel *tunnel;
9665 ipool = priv->sh->ipool[MLX5_IPOOL_TUNNEL_ID];
9666 tunnel = mlx5_ipool_zmalloc(ipool, &id);
9669 if (id >= MLX5_MAX_TUNNELS) {
9670 mlx5_ipool_free(ipool, id);
9671 DRV_LOG(ERR, "Tunnel ID %d exceed max limit.", id);
9674 tunnel->groups = mlx5_hlist_create("tunnel groups", 64, false, true,
9676 mlx5_flow_tunnel_grp2tbl_create_cb,
9677 mlx5_flow_tunnel_grp2tbl_match_cb,
9678 mlx5_flow_tunnel_grp2tbl_remove_cb,
9679 mlx5_flow_tunnel_grp2tbl_clone_cb,
9680 mlx5_flow_tunnel_grp2tbl_clone_free_cb);
9681 if (!tunnel->groups) {
9682 mlx5_ipool_free(ipool, id);
9685 /* initiate new PMD tunnel */
9686 memcpy(&tunnel->app_tunnel, app_tunnel, sizeof(*app_tunnel));
9687 tunnel->tunnel_id = id;
9688 tunnel->action.type = (typeof(tunnel->action.type))
9689 MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET;
9690 tunnel->action.conf = tunnel;
9691 tunnel->item.type = (typeof(tunnel->item.type))
9692 MLX5_RTE_FLOW_ITEM_TYPE_TUNNEL;
9693 tunnel->item.spec = tunnel;
9694 tunnel->item.last = NULL;
9695 tunnel->item.mask = NULL;
9697 DRV_LOG(DEBUG, "port %u new pmd tunnel id=0x%x",
9698 dev->data->port_id, tunnel->tunnel_id);
9703 struct tunnel_db_get_tunnel_ctx {
9704 const struct rte_flow_tunnel *app_tunnel;
9705 struct mlx5_flow_tunnel *tunnel;
9708 static bool get_tunnel_match(struct rte_eth_dev *dev,
9709 struct mlx5_flow_tunnel *tunnel, const void *x)
9711 const struct tunnel_db_get_tunnel_ctx *ctx = x;
9714 return !memcmp(ctx->app_tunnel, &tunnel->app_tunnel,
9715 sizeof(*ctx->app_tunnel));
9718 static void get_tunnel_hit(struct rte_eth_dev *dev,
9719 struct mlx5_flow_tunnel *tunnel, void *x)
9721 /* called under tunnel spinlock protection */
9722 struct tunnel_db_get_tunnel_ctx *ctx = x;
9726 ctx->tunnel = tunnel;
9729 static void get_tunnel_miss(struct rte_eth_dev *dev, void *x)
9731 /* called under tunnel spinlock protection */
9732 struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
9733 struct tunnel_db_get_tunnel_ctx *ctx = x;
9735 rte_spinlock_unlock(&thub->sl);
9736 ctx->tunnel = mlx5_flow_tunnel_allocate(dev, ctx->app_tunnel);
9737 rte_spinlock_lock(&thub->sl);
9739 ctx->tunnel->refctn = 1;
9740 LIST_INSERT_HEAD(&thub->tunnels, ctx->tunnel, chain);
9746 mlx5_get_flow_tunnel(struct rte_eth_dev *dev,
9747 const struct rte_flow_tunnel *app_tunnel,
9748 struct mlx5_flow_tunnel **tunnel)
9750 struct tunnel_db_get_tunnel_ctx ctx = {
9751 .app_tunnel = app_tunnel,
9754 mlx5_access_tunnel_offload_db(dev, get_tunnel_match, get_tunnel_hit,
9755 get_tunnel_miss, &ctx, true);
9756 *tunnel = ctx.tunnel;
9757 return ctx.tunnel ? 0 : -ENOMEM;
9760 void mlx5_release_tunnel_hub(struct mlx5_dev_ctx_shared *sh, uint16_t port_id)
9762 struct mlx5_flow_tunnel_hub *thub = sh->tunnel_hub;
9766 if (!LIST_EMPTY(&thub->tunnels))
9767 DRV_LOG(WARNING, "port %u tunnels present", port_id);
9768 mlx5_hlist_destroy(thub->groups);
9772 int mlx5_alloc_tunnel_hub(struct mlx5_dev_ctx_shared *sh)
9775 struct mlx5_flow_tunnel_hub *thub;
9777 thub = mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO, sizeof(*thub),
9781 LIST_INIT(&thub->tunnels);
9782 rte_spinlock_init(&thub->sl);
9783 thub->groups = mlx5_hlist_create("flow groups", 64,
9785 mlx5_flow_tunnel_grp2tbl_create_cb,
9786 mlx5_flow_tunnel_grp2tbl_match_cb,
9787 mlx5_flow_tunnel_grp2tbl_remove_cb,
9788 mlx5_flow_tunnel_grp2tbl_clone_cb,
9789 mlx5_flow_tunnel_grp2tbl_clone_free_cb);
9790 if (!thub->groups) {
9794 sh->tunnel_hub = thub;
9800 mlx5_hlist_destroy(thub->groups);
9807 mlx5_flow_tunnel_validate(struct rte_eth_dev *dev,
9808 struct rte_flow_tunnel *tunnel,
9809 struct rte_flow_error *error)
9811 struct mlx5_priv *priv = dev->data->dev_private;
9813 if (!priv->sh->config.dv_flow_en)
9814 return rte_flow_error_set(error, ENOTSUP,
9815 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
9816 "flow DV interface is off");
9817 if (!is_tunnel_offload_active(dev))
9818 return rte_flow_error_set(error, ENOTSUP,
9819 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
9820 "tunnel offload was not activated");
9822 return rte_flow_error_set(error, EINVAL,
9823 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
9824 "no application tunnel");
9825 switch (tunnel->type) {
9827 return rte_flow_error_set(error, EINVAL,
9828 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
9829 "unsupported tunnel type");
9830 case RTE_FLOW_ITEM_TYPE_VXLAN:
9831 case RTE_FLOW_ITEM_TYPE_GRE:
9832 case RTE_FLOW_ITEM_TYPE_NVGRE:
9833 case RTE_FLOW_ITEM_TYPE_GENEVE:
9840 mlx5_flow_tunnel_decap_set(struct rte_eth_dev *dev,
9841 struct rte_flow_tunnel *app_tunnel,
9842 struct rte_flow_action **actions,
9843 uint32_t *num_of_actions,
9844 struct rte_flow_error *error)
9846 struct mlx5_flow_tunnel *tunnel;
9847 int ret = mlx5_flow_tunnel_validate(dev, app_tunnel, error);
9851 ret = mlx5_get_flow_tunnel(dev, app_tunnel, &tunnel);
9853 return rte_flow_error_set(error, ret,
9854 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
9855 "failed to initialize pmd tunnel");
9857 *actions = &tunnel->action;
9858 *num_of_actions = 1;
9863 mlx5_flow_tunnel_match(struct rte_eth_dev *dev,
9864 struct rte_flow_tunnel *app_tunnel,
9865 struct rte_flow_item **items,
9866 uint32_t *num_of_items,
9867 struct rte_flow_error *error)
9869 struct mlx5_flow_tunnel *tunnel;
9870 int ret = mlx5_flow_tunnel_validate(dev, app_tunnel, error);
9874 ret = mlx5_get_flow_tunnel(dev, app_tunnel, &tunnel);
9876 return rte_flow_error_set(error, ret,
9877 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
9878 "failed to initialize pmd tunnel");
9880 *items = &tunnel->item;
9885 struct tunnel_db_element_release_ctx {
9886 struct rte_flow_item *items;
9887 struct rte_flow_action *actions;
9888 uint32_t num_elements;
9889 struct rte_flow_error *error;
9894 tunnel_element_release_match(struct rte_eth_dev *dev,
9895 struct mlx5_flow_tunnel *tunnel, const void *x)
9897 const struct tunnel_db_element_release_ctx *ctx = x;
9900 if (ctx->num_elements != 1)
9902 else if (ctx->items)
9903 return ctx->items == &tunnel->item;
9904 else if (ctx->actions)
9905 return ctx->actions == &tunnel->action;
9911 tunnel_element_release_hit(struct rte_eth_dev *dev,
9912 struct mlx5_flow_tunnel *tunnel, void *x)
9914 struct tunnel_db_element_release_ctx *ctx = x;
9916 if (!__atomic_sub_fetch(&tunnel->refctn, 1, __ATOMIC_RELAXED))
9917 mlx5_flow_tunnel_free(dev, tunnel);
9921 tunnel_element_release_miss(struct rte_eth_dev *dev, void *x)
9923 struct tunnel_db_element_release_ctx *ctx = x;
9925 ctx->ret = rte_flow_error_set(ctx->error, EINVAL,
9926 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
9927 "invalid argument");
9931 mlx5_flow_tunnel_item_release(struct rte_eth_dev *dev,
9932 struct rte_flow_item *pmd_items,
9933 uint32_t num_items, struct rte_flow_error *err)
9935 struct tunnel_db_element_release_ctx ctx = {
9938 .num_elements = num_items,
9942 mlx5_access_tunnel_offload_db(dev, tunnel_element_release_match,
9943 tunnel_element_release_hit,
9944 tunnel_element_release_miss, &ctx, false);
9950 mlx5_flow_tunnel_action_release(struct rte_eth_dev *dev,
9951 struct rte_flow_action *pmd_actions,
9952 uint32_t num_actions, struct rte_flow_error *err)
9954 struct tunnel_db_element_release_ctx ctx = {
9956 .actions = pmd_actions,
9957 .num_elements = num_actions,
9961 mlx5_access_tunnel_offload_db(dev, tunnel_element_release_match,
9962 tunnel_element_release_hit,
9963 tunnel_element_release_miss, &ctx, false);
9969 mlx5_flow_tunnel_get_restore_info(struct rte_eth_dev *dev,
9971 struct rte_flow_restore_info *info,
9972 struct rte_flow_error *err)
9974 uint64_t ol_flags = m->ol_flags;
9975 const struct mlx5_flow_tbl_data_entry *tble;
9976 const uint64_t mask = RTE_MBUF_F_RX_FDIR | RTE_MBUF_F_RX_FDIR_ID;
9978 if (!is_tunnel_offload_active(dev)) {
9983 if ((ol_flags & mask) != mask)
9985 tble = tunnel_mark_decode(dev, m->hash.fdir.hi);
9987 DRV_LOG(DEBUG, "port %u invalid miss tunnel mark %#x",
9988 dev->data->port_id, m->hash.fdir.hi);
9991 MLX5_ASSERT(tble->tunnel);
9992 memcpy(&info->tunnel, &tble->tunnel->app_tunnel, sizeof(info->tunnel));
9993 info->group_id = tble->group_id;
9994 info->flags = RTE_FLOW_RESTORE_INFO_TUNNEL |
9995 RTE_FLOW_RESTORE_INFO_GROUP_ID |
9996 RTE_FLOW_RESTORE_INFO_ENCAPSULATED;
10001 return rte_flow_error_set(err, EINVAL,
10002 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10003 "failed to get restore info");
10006 #else /* HAVE_IBV_FLOW_DV_SUPPORT */
10008 mlx5_flow_tunnel_decap_set(__rte_unused struct rte_eth_dev *dev,
10009 __rte_unused struct rte_flow_tunnel *app_tunnel,
10010 __rte_unused struct rte_flow_action **actions,
10011 __rte_unused uint32_t *num_of_actions,
10012 __rte_unused struct rte_flow_error *error)
10018 mlx5_flow_tunnel_match(__rte_unused struct rte_eth_dev *dev,
10019 __rte_unused struct rte_flow_tunnel *app_tunnel,
10020 __rte_unused struct rte_flow_item **items,
10021 __rte_unused uint32_t *num_of_items,
10022 __rte_unused struct rte_flow_error *error)
10028 mlx5_flow_tunnel_item_release(__rte_unused struct rte_eth_dev *dev,
10029 __rte_unused struct rte_flow_item *pmd_items,
10030 __rte_unused uint32_t num_items,
10031 __rte_unused struct rte_flow_error *err)
10037 mlx5_flow_tunnel_action_release(__rte_unused struct rte_eth_dev *dev,
10038 __rte_unused struct rte_flow_action *pmd_action,
10039 __rte_unused uint32_t num_actions,
10040 __rte_unused struct rte_flow_error *err)
10046 mlx5_flow_tunnel_get_restore_info(__rte_unused struct rte_eth_dev *dev,
10047 __rte_unused struct rte_mbuf *m,
10048 __rte_unused struct rte_flow_restore_info *i,
10049 __rte_unused struct rte_flow_error *err)
10055 flow_tunnel_add_default_miss(__rte_unused struct rte_eth_dev *dev,
10056 __rte_unused struct rte_flow *flow,
10057 __rte_unused const struct rte_flow_attr *attr,
10058 __rte_unused const struct rte_flow_action *actions,
10059 __rte_unused uint32_t flow_idx,
10060 __rte_unused const struct mlx5_flow_tunnel *tunnel,
10061 __rte_unused struct tunnel_default_miss_ctx *ctx,
10062 __rte_unused struct rte_flow_error *error)
10067 static struct mlx5_flow_tunnel *
10068 mlx5_find_tunnel_id(__rte_unused struct rte_eth_dev *dev,
10069 __rte_unused uint32_t id)
10075 mlx5_flow_tunnel_free(__rte_unused struct rte_eth_dev *dev,
10076 __rte_unused struct mlx5_flow_tunnel *tunnel)
10081 tunnel_flow_group_to_flow_table(__rte_unused struct rte_eth_dev *dev,
10082 __rte_unused const struct mlx5_flow_tunnel *t,
10083 __rte_unused uint32_t group,
10084 __rte_unused uint32_t *table,
10085 struct rte_flow_error *error)
10087 return rte_flow_error_set(error, ENOTSUP,
10088 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10089 "tunnel offload requires DV support");
10093 mlx5_release_tunnel_hub(__rte_unused struct mlx5_dev_ctx_shared *sh,
10094 __rte_unused uint16_t port_id)
10097 #endif /* HAVE_IBV_FLOW_DV_SUPPORT */
10099 /* Flex flow item API */
10100 static struct rte_flow_item_flex_handle *
10101 mlx5_flow_flex_item_create(struct rte_eth_dev *dev,
10102 const struct rte_flow_item_flex_conf *conf,
10103 struct rte_flow_error *error)
10105 static const char err_msg[] = "flex item creation unsupported";
10106 struct rte_flow_attr attr = { .transfer = 0 };
10107 const struct mlx5_flow_driver_ops *fops =
10108 flow_get_drv_ops(flow_get_drv_type(dev, &attr));
10110 if (!fops->item_create) {
10111 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
10112 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
10116 return fops->item_create(dev, conf, error);
10120 mlx5_flow_flex_item_release(struct rte_eth_dev *dev,
10121 const struct rte_flow_item_flex_handle *handle,
10122 struct rte_flow_error *error)
10124 static const char err_msg[] = "flex item release unsupported";
10125 struct rte_flow_attr attr = { .transfer = 0 };
10126 const struct mlx5_flow_driver_ops *fops =
10127 flow_get_drv_ops(flow_get_drv_type(dev, &attr));
10129 if (!fops->item_release) {
10130 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
10131 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
10135 return fops->item_release(dev, handle, error);
10139 mlx5_dbg__print_pattern(const struct rte_flow_item *item)
10142 struct rte_flow_error error;
10144 for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
10146 ret = rte_flow_conv(RTE_FLOW_CONV_OP_ITEM_NAME_PTR, &item_name,
10148 (void *)(uintptr_t)item->type, &error);
10150 printf("%s ", item_name);
10152 printf("%d\n", (int)item->type);
10158 mlx5_flow_is_std_vxlan_port(const struct rte_flow_item *udp_item)
10160 const struct rte_flow_item_udp *spec = udp_item->spec;
10161 const struct rte_flow_item_udp *mask = udp_item->mask;
10162 uint16_t udp_dport = 0;
10164 if (spec != NULL) {
10166 mask = &rte_flow_item_udp_mask;
10167 udp_dport = rte_be_to_cpu_16(spec->hdr.dst_port &
10168 mask->hdr.dst_port);
10170 return (!udp_dport || udp_dport == MLX5_UDP_PORT_VXLAN);
10173 static const struct mlx5_flow_expand_node *
10174 mlx5_flow_expand_rss_adjust_node(const struct rte_flow_item *pattern,
10175 unsigned int item_idx,
10176 const struct mlx5_flow_expand_node graph[],
10177 const struct mlx5_flow_expand_node *node)
10179 const struct rte_flow_item *item = pattern + item_idx, *prev_item;
10181 if (item->type == RTE_FLOW_ITEM_TYPE_VXLAN &&
10183 node->type == RTE_FLOW_ITEM_TYPE_VXLAN) {
10185 * The expansion node is VXLAN and it is also the last
10186 * expandable item in the pattern, so need to continue
10187 * expansion of the inner tunnel.
10189 MLX5_ASSERT(item_idx > 0);
10190 prev_item = pattern + item_idx - 1;
10191 MLX5_ASSERT(prev_item->type == RTE_FLOW_ITEM_TYPE_UDP);
10192 if (mlx5_flow_is_std_vxlan_port(prev_item))
10193 return &graph[MLX5_EXPANSION_STD_VXLAN];
10194 return &graph[MLX5_EXPANSION_L3_VXLAN];
10199 /* Map of Verbs to Flow priority with 8 Verbs priorities. */
10200 static const uint32_t priority_map_3[][MLX5_PRIORITY_MAP_MAX] = {
10201 { 0, 1, 2 }, { 2, 3, 4 }, { 5, 6, 7 },
10204 /* Map of Verbs to Flow priority with 16 Verbs priorities. */
10205 static const uint32_t priority_map_5[][MLX5_PRIORITY_MAP_MAX] = {
10206 { 0, 1, 2 }, { 3, 4, 5 }, { 6, 7, 8 },
10207 { 9, 10, 11 }, { 12, 13, 14 },
10211 * Discover the number of available flow priorities.
10217 * On success, number of available flow priorities.
10218 * On failure, a negative errno-style code and rte_errno is set.
10221 mlx5_flow_discover_priorities(struct rte_eth_dev *dev)
10223 static const uint16_t vprio[] = {8, 16};
10224 const struct mlx5_priv *priv = dev->data->dev_private;
10225 const struct mlx5_flow_driver_ops *fops;
10226 enum mlx5_flow_drv_type type;
10229 type = mlx5_flow_os_get_type();
10230 if (type == MLX5_FLOW_TYPE_MAX) {
10231 type = MLX5_FLOW_TYPE_VERBS;
10232 if (priv->sh->cdev->config.devx && priv->sh->config.dv_flow_en)
10233 type = MLX5_FLOW_TYPE_DV;
10235 fops = flow_get_drv_ops(type);
10236 if (fops->discover_priorities == NULL) {
10237 DRV_LOG(ERR, "Priority discovery not supported");
10238 rte_errno = ENOTSUP;
10241 ret = fops->discover_priorities(dev, vprio, RTE_DIM(vprio));
10246 ret = RTE_DIM(priority_map_3);
10249 ret = RTE_DIM(priority_map_5);
10252 rte_errno = ENOTSUP;
10254 "port %u maximum priority: %d expected 8/16",
10255 dev->data->port_id, ret);
10258 DRV_LOG(INFO, "port %u supported flow priorities:"
10259 " 0-%d for ingress or egress root table,"
10260 " 0-%d for non-root table or transfer root table.",
10261 dev->data->port_id, ret - 2,
10262 MLX5_NON_ROOT_FLOW_MAX_PRIO - 1);
10267 * Adjust flow priority based on the highest layer and the request priority.
10270 * Pointer to the Ethernet device structure.
10271 * @param[in] priority
10272 * The rule base priority.
10273 * @param[in] subpriority
10274 * The priority based on the items.
10277 * The new priority.
10280 mlx5_flow_adjust_priority(struct rte_eth_dev *dev, int32_t priority,
10281 uint32_t subpriority)
10284 struct mlx5_priv *priv = dev->data->dev_private;
10286 switch (priv->sh->flow_max_priority) {
10287 case RTE_DIM(priority_map_3):
10288 res = priority_map_3[priority][subpriority];
10290 case RTE_DIM(priority_map_5):
10291 res = priority_map_5[priority][subpriority];