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 struct rte_flow_template_table *
842 mlx5_flow_table_create(struct rte_eth_dev *dev,
843 const struct rte_flow_template_table_attr *attr,
844 struct rte_flow_pattern_template *item_templates[],
845 uint8_t nb_item_templates,
846 struct rte_flow_actions_template *action_templates[],
847 uint8_t nb_action_templates,
848 struct rte_flow_error *error);
850 mlx5_flow_table_destroy(struct rte_eth_dev *dev,
851 struct rte_flow_template_table *table,
852 struct rte_flow_error *error);
854 static const struct rte_flow_ops mlx5_flow_ops = {
855 .validate = mlx5_flow_validate,
856 .create = mlx5_flow_create,
857 .destroy = mlx5_flow_destroy,
858 .flush = mlx5_flow_flush,
859 .isolate = mlx5_flow_isolate,
860 .query = mlx5_flow_query,
861 .dev_dump = mlx5_flow_dev_dump,
862 .get_aged_flows = mlx5_flow_get_aged_flows,
863 .action_handle_create = mlx5_action_handle_create,
864 .action_handle_destroy = mlx5_action_handle_destroy,
865 .action_handle_update = mlx5_action_handle_update,
866 .action_handle_query = mlx5_action_handle_query,
867 .tunnel_decap_set = mlx5_flow_tunnel_decap_set,
868 .tunnel_match = mlx5_flow_tunnel_match,
869 .tunnel_action_decap_release = mlx5_flow_tunnel_action_release,
870 .tunnel_item_release = mlx5_flow_tunnel_item_release,
871 .get_restore_info = mlx5_flow_tunnel_get_restore_info,
872 .flex_item_create = mlx5_flow_flex_item_create,
873 .flex_item_release = mlx5_flow_flex_item_release,
874 .info_get = mlx5_flow_info_get,
875 .configure = mlx5_flow_port_configure,
876 .pattern_template_create = mlx5_flow_pattern_template_create,
877 .pattern_template_destroy = mlx5_flow_pattern_template_destroy,
878 .actions_template_create = mlx5_flow_actions_template_create,
879 .actions_template_destroy = mlx5_flow_actions_template_destroy,
880 .template_table_create = mlx5_flow_table_create,
881 .template_table_destroy = mlx5_flow_table_destroy,
884 /* Tunnel information. */
885 struct mlx5_flow_tunnel_info {
886 uint64_t tunnel; /**< Tunnel bit (see MLX5_FLOW_*). */
887 uint32_t ptype; /**< Tunnel Ptype (see RTE_PTYPE_*). */
890 static struct mlx5_flow_tunnel_info tunnels_info[] = {
892 .tunnel = MLX5_FLOW_LAYER_VXLAN,
893 .ptype = RTE_PTYPE_TUNNEL_VXLAN | RTE_PTYPE_L4_UDP,
896 .tunnel = MLX5_FLOW_LAYER_GENEVE,
897 .ptype = RTE_PTYPE_TUNNEL_GENEVE | RTE_PTYPE_L4_UDP,
900 .tunnel = MLX5_FLOW_LAYER_VXLAN_GPE,
901 .ptype = RTE_PTYPE_TUNNEL_VXLAN_GPE | RTE_PTYPE_L4_UDP,
904 .tunnel = MLX5_FLOW_LAYER_GRE,
905 .ptype = RTE_PTYPE_TUNNEL_GRE,
908 .tunnel = MLX5_FLOW_LAYER_MPLS | MLX5_FLOW_LAYER_OUTER_L4_UDP,
909 .ptype = RTE_PTYPE_TUNNEL_MPLS_IN_UDP | RTE_PTYPE_L4_UDP,
912 .tunnel = MLX5_FLOW_LAYER_MPLS,
913 .ptype = RTE_PTYPE_TUNNEL_MPLS_IN_GRE,
916 .tunnel = MLX5_FLOW_LAYER_NVGRE,
917 .ptype = RTE_PTYPE_TUNNEL_NVGRE,
920 .tunnel = MLX5_FLOW_LAYER_IPIP,
921 .ptype = RTE_PTYPE_TUNNEL_IP,
924 .tunnel = MLX5_FLOW_LAYER_IPV6_ENCAP,
925 .ptype = RTE_PTYPE_TUNNEL_IP,
928 .tunnel = MLX5_FLOW_LAYER_GTP,
929 .ptype = RTE_PTYPE_TUNNEL_GTPU,
936 * Translate tag ID to register.
939 * Pointer to the Ethernet device structure.
941 * The feature that request the register.
943 * The request register ID.
945 * Error description in case of any.
948 * The request register on success, a negative errno
949 * value otherwise and rte_errno is set.
952 mlx5_flow_get_reg_id(struct rte_eth_dev *dev,
953 enum mlx5_feature_name feature,
955 struct rte_flow_error *error)
957 struct mlx5_priv *priv = dev->data->dev_private;
958 struct mlx5_sh_config *config = &priv->sh->config;
959 enum modify_reg start_reg;
960 bool skip_mtr_reg = false;
963 case MLX5_HAIRPIN_RX:
965 case MLX5_HAIRPIN_TX:
967 case MLX5_METADATA_RX:
968 switch (config->dv_xmeta_en) {
969 case MLX5_XMETA_MODE_LEGACY:
971 case MLX5_XMETA_MODE_META16:
973 case MLX5_XMETA_MODE_META32:
977 case MLX5_METADATA_TX:
979 case MLX5_METADATA_FDB:
980 switch (config->dv_xmeta_en) {
981 case MLX5_XMETA_MODE_LEGACY:
983 case MLX5_XMETA_MODE_META16:
985 case MLX5_XMETA_MODE_META32:
990 switch (config->dv_xmeta_en) {
991 case MLX5_XMETA_MODE_LEGACY:
993 case MLX5_XMETA_MODE_META16:
995 case MLX5_XMETA_MODE_META32:
1001 * If meter color and meter id share one register, flow match
1002 * should use the meter color register for match.
1004 if (priv->mtr_reg_share)
1005 return priv->mtr_color_reg;
1007 return priv->mtr_color_reg != REG_C_2 ? REG_C_2 :
1009 case MLX5_MTR_COLOR:
1010 case MLX5_ASO_FLOW_HIT:
1011 case MLX5_ASO_CONNTRACK:
1012 case MLX5_SAMPLE_ID:
1013 /* All features use the same REG_C. */
1014 MLX5_ASSERT(priv->mtr_color_reg != REG_NON);
1015 return priv->mtr_color_reg;
1016 case MLX5_COPY_MARK:
1018 * Metadata COPY_MARK register using is in meter suffix sub
1019 * flow while with meter. It's safe to share the same register.
1021 return priv->mtr_color_reg != REG_C_2 ? REG_C_2 : REG_C_3;
1024 * If meter is enable, it will engage the register for color
1025 * match and flow match. If meter color match is not using the
1026 * REG_C_2, need to skip the REG_C_x be used by meter color
1028 * If meter is disable, free to use all available registers.
1030 start_reg = priv->mtr_color_reg != REG_C_2 ? REG_C_2 :
1031 (priv->mtr_reg_share ? REG_C_3 : REG_C_4);
1032 skip_mtr_reg = !!(priv->mtr_en && start_reg == REG_C_2);
1033 if (id > (uint32_t)(REG_C_7 - start_reg))
1034 return rte_flow_error_set(error, EINVAL,
1035 RTE_FLOW_ERROR_TYPE_ITEM,
1036 NULL, "invalid tag id");
1037 if (priv->sh->flow_mreg_c[id + start_reg - REG_C_0] == REG_NON)
1038 return rte_flow_error_set(error, ENOTSUP,
1039 RTE_FLOW_ERROR_TYPE_ITEM,
1040 NULL, "unsupported tag id");
1042 * This case means meter is using the REG_C_x great than 2.
1043 * Take care not to conflict with meter color REG_C_x.
1044 * If the available index REG_C_y >= REG_C_x, skip the
1047 if (skip_mtr_reg && priv->sh->flow_mreg_c
1048 [id + start_reg - REG_C_0] >= priv->mtr_color_reg) {
1049 if (id >= (uint32_t)(REG_C_7 - start_reg))
1050 return rte_flow_error_set(error, EINVAL,
1051 RTE_FLOW_ERROR_TYPE_ITEM,
1052 NULL, "invalid tag id");
1053 if (priv->sh->flow_mreg_c
1054 [id + 1 + start_reg - REG_C_0] != REG_NON)
1055 return priv->sh->flow_mreg_c
1056 [id + 1 + start_reg - REG_C_0];
1057 return rte_flow_error_set(error, ENOTSUP,
1058 RTE_FLOW_ERROR_TYPE_ITEM,
1059 NULL, "unsupported tag id");
1061 return priv->sh->flow_mreg_c[id + start_reg - REG_C_0];
1064 return rte_flow_error_set(error, EINVAL,
1065 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1066 NULL, "invalid feature name");
1070 * Check extensive flow metadata register support.
1073 * Pointer to rte_eth_dev structure.
1076 * True if device supports extensive flow metadata register, otherwise false.
1079 mlx5_flow_ext_mreg_supported(struct rte_eth_dev *dev)
1081 struct mlx5_priv *priv = dev->data->dev_private;
1084 * Having available reg_c can be regarded inclusively as supporting
1085 * extensive flow metadata register, which could mean,
1086 * - metadata register copy action by modify header.
1087 * - 16 modify header actions is supported.
1088 * - reg_c's are preserved across different domain (FDB and NIC) on
1089 * packet loopback by flow lookup miss.
1091 return priv->sh->flow_mreg_c[2] != REG_NON;
1095 * Get the lowest priority.
1098 * Pointer to the Ethernet device structure.
1099 * @param[in] attributes
1100 * Pointer to device flow rule attributes.
1103 * The value of lowest priority of flow.
1106 mlx5_get_lowest_priority(struct rte_eth_dev *dev,
1107 const struct rte_flow_attr *attr)
1109 struct mlx5_priv *priv = dev->data->dev_private;
1111 if (!attr->group && !attr->transfer)
1112 return priv->sh->flow_max_priority - 2;
1113 return MLX5_NON_ROOT_FLOW_MAX_PRIO - 1;
1117 * Calculate matcher priority of the flow.
1120 * Pointer to the Ethernet device structure.
1122 * Pointer to device flow rule attributes.
1123 * @param[in] subpriority
1124 * The priority based on the items.
1125 * @param[in] external
1126 * Flow is user flow.
1128 * The matcher priority of the flow.
1131 mlx5_get_matcher_priority(struct rte_eth_dev *dev,
1132 const struct rte_flow_attr *attr,
1133 uint32_t subpriority, bool external)
1135 uint16_t priority = (uint16_t)attr->priority;
1136 struct mlx5_priv *priv = dev->data->dev_private;
1138 if (!attr->group && !attr->transfer) {
1139 if (attr->priority == MLX5_FLOW_LOWEST_PRIO_INDICATOR)
1140 priority = priv->sh->flow_max_priority - 1;
1141 return mlx5_os_flow_adjust_priority(dev, priority, subpriority);
1142 } else if (!external && attr->transfer && attr->group == 0 &&
1143 attr->priority == MLX5_FLOW_LOWEST_PRIO_INDICATOR) {
1144 return (priv->sh->flow_max_priority - 1) * 3;
1146 if (attr->priority == MLX5_FLOW_LOWEST_PRIO_INDICATOR)
1147 priority = MLX5_NON_ROOT_FLOW_MAX_PRIO;
1148 return priority * 3 + subpriority;
1152 * Verify the @p item specifications (spec, last, mask) are compatible with the
1156 * Item specification.
1158 * @p item->mask or flow default bit-masks.
1159 * @param[in] nic_mask
1160 * Bit-masks covering supported fields by the NIC to compare with user mask.
1162 * Bit-masks size in bytes.
1163 * @param[in] range_accepted
1164 * True if range of values is accepted for specific fields, false otherwise.
1166 * Pointer to error structure.
1169 * 0 on success, a negative errno value otherwise and rte_errno is set.
1172 mlx5_flow_item_acceptable(const struct rte_flow_item *item,
1173 const uint8_t *mask,
1174 const uint8_t *nic_mask,
1176 bool range_accepted,
1177 struct rte_flow_error *error)
1181 MLX5_ASSERT(nic_mask);
1182 for (i = 0; i < size; ++i)
1183 if ((nic_mask[i] | mask[i]) != nic_mask[i])
1184 return rte_flow_error_set(error, ENOTSUP,
1185 RTE_FLOW_ERROR_TYPE_ITEM,
1187 "mask enables non supported"
1189 if (!item->spec && (item->mask || item->last))
1190 return rte_flow_error_set(error, EINVAL,
1191 RTE_FLOW_ERROR_TYPE_ITEM, item,
1192 "mask/last without a spec is not"
1194 if (item->spec && item->last && !range_accepted) {
1200 for (i = 0; i < size; ++i) {
1201 spec[i] = ((const uint8_t *)item->spec)[i] & mask[i];
1202 last[i] = ((const uint8_t *)item->last)[i] & mask[i];
1204 ret = memcmp(spec, last, size);
1206 return rte_flow_error_set(error, EINVAL,
1207 RTE_FLOW_ERROR_TYPE_ITEM,
1209 "range is not valid");
1215 * Adjust the hash fields according to the @p flow information.
1217 * @param[in] dev_flow.
1218 * Pointer to the mlx5_flow.
1220 * 1 when the hash field is for a tunnel item.
1221 * @param[in] layer_types
1222 * RTE_ETH_RSS_* types.
1223 * @param[in] hash_fields
1227 * The hash fields that should be used.
1230 mlx5_flow_hashfields_adjust(struct mlx5_flow_rss_desc *rss_desc,
1231 int tunnel __rte_unused, uint64_t layer_types,
1232 uint64_t hash_fields)
1234 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
1235 int rss_request_inner = rss_desc->level >= 2;
1237 /* Check RSS hash level for tunnel. */
1238 if (tunnel && rss_request_inner)
1239 hash_fields |= IBV_RX_HASH_INNER;
1240 else if (tunnel || rss_request_inner)
1243 /* Check if requested layer matches RSS hash fields. */
1244 if (!(rss_desc->types & layer_types))
1250 * Lookup and set the ptype in the data Rx part. A single Ptype can be used,
1251 * if several tunnel rules are used on this queue, the tunnel ptype will be
1255 * Rx queue to update.
1258 flow_rxq_tunnel_ptype_update(struct mlx5_rxq_ctrl *rxq_ctrl)
1261 uint32_t tunnel_ptype = 0;
1263 /* Look up for the ptype to use. */
1264 for (i = 0; i != MLX5_FLOW_TUNNEL; ++i) {
1265 if (!rxq_ctrl->flow_tunnels_n[i])
1267 if (!tunnel_ptype) {
1268 tunnel_ptype = tunnels_info[i].ptype;
1274 rxq_ctrl->rxq.tunnel = tunnel_ptype;
1278 * Set the Rx queue flags (Mark/Flag and Tunnel Ptypes) according to the device
1282 * Pointer to the Ethernet device structure.
1283 * @param[in] dev_handle
1284 * Pointer to device flow handle structure.
1287 flow_drv_rxq_flags_set(struct rte_eth_dev *dev,
1288 struct mlx5_flow_handle *dev_handle)
1290 struct mlx5_priv *priv = dev->data->dev_private;
1291 const int tunnel = !!(dev_handle->layers & MLX5_FLOW_LAYER_TUNNEL);
1292 struct mlx5_ind_table_obj *ind_tbl = NULL;
1295 if (dev_handle->fate_action == MLX5_FLOW_FATE_QUEUE) {
1296 struct mlx5_hrxq *hrxq;
1298 hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
1299 dev_handle->rix_hrxq);
1301 ind_tbl = hrxq->ind_table;
1302 } else if (dev_handle->fate_action == MLX5_FLOW_FATE_SHARED_RSS) {
1303 struct mlx5_shared_action_rss *shared_rss;
1305 shared_rss = mlx5_ipool_get
1306 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
1307 dev_handle->rix_srss);
1309 ind_tbl = shared_rss->ind_tbl;
1313 for (i = 0; i != ind_tbl->queues_n; ++i) {
1314 int idx = ind_tbl->queues[i];
1315 struct mlx5_rxq_ctrl *rxq_ctrl = mlx5_rxq_ctrl_get(dev, idx);
1317 MLX5_ASSERT(rxq_ctrl != NULL);
1318 if (rxq_ctrl == NULL)
1321 * To support metadata register copy on Tx loopback,
1322 * this must be always enabled (metadata may arive
1323 * from other port - not from local flows only.
1328 /* Increase the counter matching the flow. */
1329 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j) {
1330 if ((tunnels_info[j].tunnel &
1331 dev_handle->layers) ==
1332 tunnels_info[j].tunnel) {
1333 rxq_ctrl->flow_tunnels_n[j]++;
1337 flow_rxq_tunnel_ptype_update(rxq_ctrl);
1343 flow_rxq_mark_flag_set(struct rte_eth_dev *dev)
1345 struct mlx5_priv *priv = dev->data->dev_private;
1346 struct mlx5_rxq_ctrl *rxq_ctrl;
1348 if (priv->mark_enabled)
1350 LIST_FOREACH(rxq_ctrl, &priv->rxqsctrl, next) {
1351 rxq_ctrl->rxq.mark = 1;
1353 priv->mark_enabled = 1;
1357 * Set the Rx queue flags (Mark/Flag and Tunnel Ptypes) for a flow
1360 * Pointer to the Ethernet device structure.
1362 * Pointer to flow structure.
1365 flow_rxq_flags_set(struct rte_eth_dev *dev, struct rte_flow *flow)
1367 struct mlx5_priv *priv = dev->data->dev_private;
1368 uint32_t handle_idx;
1369 struct mlx5_flow_handle *dev_handle;
1370 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
1374 flow_rxq_mark_flag_set(dev);
1375 SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
1376 handle_idx, dev_handle, next)
1377 flow_drv_rxq_flags_set(dev, dev_handle);
1381 * Clear the Rx queue flags (Mark/Flag and Tunnel Ptype) associated with the
1382 * device flow if no other flow uses it with the same kind of request.
1385 * Pointer to Ethernet device.
1386 * @param[in] dev_handle
1387 * Pointer to the device flow handle structure.
1390 flow_drv_rxq_flags_trim(struct rte_eth_dev *dev,
1391 struct mlx5_flow_handle *dev_handle)
1393 struct mlx5_priv *priv = dev->data->dev_private;
1394 const int tunnel = !!(dev_handle->layers & MLX5_FLOW_LAYER_TUNNEL);
1395 struct mlx5_ind_table_obj *ind_tbl = NULL;
1398 if (dev_handle->fate_action == MLX5_FLOW_FATE_QUEUE) {
1399 struct mlx5_hrxq *hrxq;
1401 hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
1402 dev_handle->rix_hrxq);
1404 ind_tbl = hrxq->ind_table;
1405 } else if (dev_handle->fate_action == MLX5_FLOW_FATE_SHARED_RSS) {
1406 struct mlx5_shared_action_rss *shared_rss;
1408 shared_rss = mlx5_ipool_get
1409 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
1410 dev_handle->rix_srss);
1412 ind_tbl = shared_rss->ind_tbl;
1416 MLX5_ASSERT(dev->data->dev_started);
1417 for (i = 0; i != ind_tbl->queues_n; ++i) {
1418 int idx = ind_tbl->queues[i];
1419 struct mlx5_rxq_ctrl *rxq_ctrl = mlx5_rxq_ctrl_get(dev, idx);
1421 MLX5_ASSERT(rxq_ctrl != NULL);
1422 if (rxq_ctrl == NULL)
1427 /* Decrease the counter matching the flow. */
1428 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j) {
1429 if ((tunnels_info[j].tunnel &
1430 dev_handle->layers) ==
1431 tunnels_info[j].tunnel) {
1432 rxq_ctrl->flow_tunnels_n[j]--;
1436 flow_rxq_tunnel_ptype_update(rxq_ctrl);
1442 * Clear the Rx queue flags (Mark/Flag and Tunnel Ptype) associated with the
1443 * @p flow if no other flow uses it with the same kind of request.
1446 * Pointer to Ethernet device.
1448 * Pointer to the flow.
1451 flow_rxq_flags_trim(struct rte_eth_dev *dev, struct rte_flow *flow)
1453 struct mlx5_priv *priv = dev->data->dev_private;
1454 uint32_t handle_idx;
1455 struct mlx5_flow_handle *dev_handle;
1457 SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
1458 handle_idx, dev_handle, next)
1459 flow_drv_rxq_flags_trim(dev, dev_handle);
1463 * Clear the Mark/Flag and Tunnel ptype information in all Rx queues.
1466 * Pointer to Ethernet device.
1469 flow_rxq_flags_clear(struct rte_eth_dev *dev)
1471 struct mlx5_priv *priv = dev->data->dev_private;
1474 for (i = 0; i != priv->rxqs_n; ++i) {
1475 struct mlx5_rxq_priv *rxq = mlx5_rxq_get(dev, i);
1478 if (rxq == NULL || rxq->ctrl == NULL)
1480 rxq->ctrl->rxq.mark = 0;
1481 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j)
1482 rxq->ctrl->flow_tunnels_n[j] = 0;
1483 rxq->ctrl->rxq.tunnel = 0;
1485 priv->mark_enabled = 0;
1489 * Set the Rx queue dynamic metadata (mask and offset) for a flow
1492 * Pointer to the Ethernet device structure.
1495 mlx5_flow_rxq_dynf_metadata_set(struct rte_eth_dev *dev)
1497 struct mlx5_priv *priv = dev->data->dev_private;
1500 for (i = 0; i != priv->rxqs_n; ++i) {
1501 struct mlx5_rxq_priv *rxq = mlx5_rxq_get(dev, i);
1502 struct mlx5_rxq_data *data;
1504 if (rxq == NULL || rxq->ctrl == NULL)
1506 data = &rxq->ctrl->rxq;
1507 if (!rte_flow_dynf_metadata_avail()) {
1508 data->dynf_meta = 0;
1509 data->flow_meta_mask = 0;
1510 data->flow_meta_offset = -1;
1511 data->flow_meta_port_mask = 0;
1513 data->dynf_meta = 1;
1514 data->flow_meta_mask = rte_flow_dynf_metadata_mask;
1515 data->flow_meta_offset = rte_flow_dynf_metadata_offs;
1516 data->flow_meta_port_mask = priv->sh->dv_meta_mask;
1522 * return a pointer to the desired action in the list of actions.
1524 * @param[in] actions
1525 * The list of actions to search the action in.
1527 * The action to find.
1530 * Pointer to the action in the list, if found. NULL otherwise.
1532 const struct rte_flow_action *
1533 mlx5_flow_find_action(const struct rte_flow_action *actions,
1534 enum rte_flow_action_type action)
1536 if (actions == NULL)
1538 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++)
1539 if (actions->type == action)
1545 * Validate the flag action.
1547 * @param[in] action_flags
1548 * Bit-fields that holds the actions detected until now.
1550 * Attributes of flow that includes this action.
1552 * Pointer to error structure.
1555 * 0 on success, a negative errno value otherwise and rte_errno is set.
1558 mlx5_flow_validate_action_flag(uint64_t action_flags,
1559 const struct rte_flow_attr *attr,
1560 struct rte_flow_error *error)
1562 if (action_flags & MLX5_FLOW_ACTION_MARK)
1563 return rte_flow_error_set(error, EINVAL,
1564 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1565 "can't mark and flag in same flow");
1566 if (action_flags & MLX5_FLOW_ACTION_FLAG)
1567 return rte_flow_error_set(error, EINVAL,
1568 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1570 " actions in same flow");
1572 return rte_flow_error_set(error, ENOTSUP,
1573 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1574 "flag action not supported for "
1580 * Validate the mark action.
1583 * Pointer to the queue action.
1584 * @param[in] action_flags
1585 * Bit-fields that holds the actions detected until now.
1587 * Attributes of flow that includes this action.
1589 * Pointer to error structure.
1592 * 0 on success, a negative errno value otherwise and rte_errno is set.
1595 mlx5_flow_validate_action_mark(const struct rte_flow_action *action,
1596 uint64_t action_flags,
1597 const struct rte_flow_attr *attr,
1598 struct rte_flow_error *error)
1600 const struct rte_flow_action_mark *mark = action->conf;
1603 return rte_flow_error_set(error, EINVAL,
1604 RTE_FLOW_ERROR_TYPE_ACTION,
1606 "configuration cannot be null");
1607 if (mark->id >= MLX5_FLOW_MARK_MAX)
1608 return rte_flow_error_set(error, EINVAL,
1609 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1611 "mark id must in 0 <= id < "
1612 RTE_STR(MLX5_FLOW_MARK_MAX));
1613 if (action_flags & MLX5_FLOW_ACTION_FLAG)
1614 return rte_flow_error_set(error, EINVAL,
1615 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1616 "can't flag and mark in same flow");
1617 if (action_flags & MLX5_FLOW_ACTION_MARK)
1618 return rte_flow_error_set(error, EINVAL,
1619 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1620 "can't have 2 mark actions in same"
1623 return rte_flow_error_set(error, ENOTSUP,
1624 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1625 "mark action not supported for "
1631 * Validate the drop action.
1633 * @param[in] action_flags
1634 * Bit-fields that holds the actions detected until now.
1636 * Attributes of flow that includes this action.
1638 * Pointer to error structure.
1641 * 0 on success, a negative errno value otherwise and rte_errno is set.
1644 mlx5_flow_validate_action_drop(uint64_t action_flags __rte_unused,
1645 const struct rte_flow_attr *attr,
1646 struct rte_flow_error *error)
1649 return rte_flow_error_set(error, ENOTSUP,
1650 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1651 "drop action not supported for "
1657 * Validate the queue action.
1660 * Pointer to the queue action.
1661 * @param[in] action_flags
1662 * Bit-fields that holds the actions detected until now.
1664 * Pointer to the Ethernet device structure.
1666 * Attributes of flow that includes this action.
1668 * Pointer to error structure.
1671 * 0 on success, a negative errno value otherwise and rte_errno is set.
1674 mlx5_flow_validate_action_queue(const struct rte_flow_action *action,
1675 uint64_t action_flags,
1676 struct rte_eth_dev *dev,
1677 const struct rte_flow_attr *attr,
1678 struct rte_flow_error *error)
1680 struct mlx5_priv *priv = dev->data->dev_private;
1681 const struct rte_flow_action_queue *queue = action->conf;
1683 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
1684 return rte_flow_error_set(error, EINVAL,
1685 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1686 "can't have 2 fate actions in"
1689 return rte_flow_error_set(error, EINVAL,
1690 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1691 NULL, "No Rx queues configured");
1692 if (queue->index >= priv->rxqs_n)
1693 return rte_flow_error_set(error, EINVAL,
1694 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1696 "queue index out of range");
1697 if (mlx5_rxq_get(dev, queue->index) == NULL)
1698 return rte_flow_error_set(error, EINVAL,
1699 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1701 "queue is not configured");
1703 return rte_flow_error_set(error, ENOTSUP,
1704 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1705 "queue action not supported for "
1711 * Validate queue numbers for device RSS.
1714 * Configured device.
1716 * Array of queue numbers.
1717 * @param[in] queues_n
1718 * Size of the @p queues array.
1720 * On error, filled with a textual error description.
1722 * On error, filled with an offending queue index in @p queues array.
1725 * 0 on success, a negative errno code on error.
1728 mlx5_validate_rss_queues(struct rte_eth_dev *dev,
1729 const uint16_t *queues, uint32_t queues_n,
1730 const char **error, uint32_t *queue_idx)
1732 const struct mlx5_priv *priv = dev->data->dev_private;
1733 enum mlx5_rxq_type rxq_type = MLX5_RXQ_TYPE_UNDEFINED;
1736 for (i = 0; i != queues_n; ++i) {
1737 struct mlx5_rxq_ctrl *rxq_ctrl = mlx5_rxq_ctrl_get(dev,
1740 if (queues[i] >= priv->rxqs_n) {
1741 *error = "queue index out of range";
1745 if (rxq_ctrl == NULL) {
1746 *error = "queue is not configured";
1751 rxq_type = rxq_ctrl->type;
1752 if (rxq_type != rxq_ctrl->type) {
1753 *error = "combining hairpin and regular RSS queues is not supported";
1762 * Validate the rss action.
1765 * Pointer to the Ethernet device structure.
1767 * Pointer to the queue action.
1769 * Pointer to error structure.
1772 * 0 on success, a negative errno value otherwise and rte_errno is set.
1775 mlx5_validate_action_rss(struct rte_eth_dev *dev,
1776 const struct rte_flow_action *action,
1777 struct rte_flow_error *error)
1779 struct mlx5_priv *priv = dev->data->dev_private;
1780 const struct rte_flow_action_rss *rss = action->conf;
1782 const char *message;
1785 if (rss->func != RTE_ETH_HASH_FUNCTION_DEFAULT &&
1786 rss->func != RTE_ETH_HASH_FUNCTION_TOEPLITZ)
1787 return rte_flow_error_set(error, ENOTSUP,
1788 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1790 "RSS hash function not supported");
1791 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
1796 return rte_flow_error_set(error, ENOTSUP,
1797 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1799 "tunnel RSS is not supported");
1800 /* allow RSS key_len 0 in case of NULL (default) RSS key. */
1801 if (rss->key_len == 0 && rss->key != NULL)
1802 return rte_flow_error_set(error, ENOTSUP,
1803 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1805 "RSS hash key length 0");
1806 if (rss->key_len > 0 && rss->key_len < MLX5_RSS_HASH_KEY_LEN)
1807 return rte_flow_error_set(error, ENOTSUP,
1808 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1810 "RSS hash key too small");
1811 if (rss->key_len > MLX5_RSS_HASH_KEY_LEN)
1812 return rte_flow_error_set(error, ENOTSUP,
1813 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1815 "RSS hash key too large");
1816 if (rss->queue_num > priv->sh->dev_cap.ind_table_max_size)
1817 return rte_flow_error_set(error, ENOTSUP,
1818 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1820 "number of queues too large");
1821 if (rss->types & MLX5_RSS_HF_MASK)
1822 return rte_flow_error_set(error, ENOTSUP,
1823 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1825 "some RSS protocols are not"
1827 if ((rss->types & (RTE_ETH_RSS_L3_SRC_ONLY | RTE_ETH_RSS_L3_DST_ONLY)) &&
1828 !(rss->types & RTE_ETH_RSS_IP))
1829 return rte_flow_error_set(error, EINVAL,
1830 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1831 "L3 partial RSS requested but L3 RSS"
1832 " type not specified");
1833 if ((rss->types & (RTE_ETH_RSS_L4_SRC_ONLY | RTE_ETH_RSS_L4_DST_ONLY)) &&
1834 !(rss->types & (RTE_ETH_RSS_UDP | RTE_ETH_RSS_TCP)))
1835 return rte_flow_error_set(error, EINVAL,
1836 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1837 "L4 partial RSS requested but L4 RSS"
1838 " type not specified");
1840 return rte_flow_error_set(error, EINVAL,
1841 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1842 NULL, "No Rx queues configured");
1843 if (!rss->queue_num)
1844 return rte_flow_error_set(error, EINVAL,
1845 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1846 NULL, "No queues configured");
1847 ret = mlx5_validate_rss_queues(dev, rss->queue, rss->queue_num,
1848 &message, &queue_idx);
1850 return rte_flow_error_set(error, -ret,
1851 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1852 &rss->queue[queue_idx], message);
1858 * Validate the rss action.
1861 * Pointer to the queue action.
1862 * @param[in] action_flags
1863 * Bit-fields that holds the actions detected until now.
1865 * Pointer to the Ethernet device structure.
1867 * Attributes of flow that includes this action.
1868 * @param[in] item_flags
1869 * Items that were detected.
1871 * Pointer to error structure.
1874 * 0 on success, a negative errno value otherwise and rte_errno is set.
1877 mlx5_flow_validate_action_rss(const struct rte_flow_action *action,
1878 uint64_t action_flags,
1879 struct rte_eth_dev *dev,
1880 const struct rte_flow_attr *attr,
1881 uint64_t item_flags,
1882 struct rte_flow_error *error)
1884 const struct rte_flow_action_rss *rss = action->conf;
1885 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1888 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
1889 return rte_flow_error_set(error, EINVAL,
1890 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1891 "can't have 2 fate actions"
1893 ret = mlx5_validate_action_rss(dev, action, error);
1897 return rte_flow_error_set(error, ENOTSUP,
1898 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1899 "rss action not supported for "
1901 if (rss->level > 1 && !tunnel)
1902 return rte_flow_error_set(error, EINVAL,
1903 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1904 "inner RSS is not supported for "
1905 "non-tunnel flows");
1906 if ((item_flags & MLX5_FLOW_LAYER_ECPRI) &&
1907 !(item_flags & MLX5_FLOW_LAYER_INNER_L4_UDP)) {
1908 return rte_flow_error_set(error, EINVAL,
1909 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1910 "RSS on eCPRI is not supported now");
1912 if ((item_flags & MLX5_FLOW_LAYER_MPLS) &&
1914 (MLX5_FLOW_LAYER_INNER_L2 | MLX5_FLOW_LAYER_INNER_L3)) &&
1916 return rte_flow_error_set(error, EINVAL,
1917 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
1918 "MPLS inner RSS needs to specify inner L2/L3 items after MPLS in pattern");
1923 * Validate the default miss action.
1925 * @param[in] action_flags
1926 * Bit-fields that holds the actions detected until now.
1928 * Pointer to error structure.
1931 * 0 on success, a negative errno value otherwise and rte_errno is set.
1934 mlx5_flow_validate_action_default_miss(uint64_t action_flags,
1935 const struct rte_flow_attr *attr,
1936 struct rte_flow_error *error)
1938 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
1939 return rte_flow_error_set(error, EINVAL,
1940 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1941 "can't have 2 fate actions in"
1944 return rte_flow_error_set(error, ENOTSUP,
1945 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1946 "default miss action not supported "
1949 return rte_flow_error_set(error, ENOTSUP,
1950 RTE_FLOW_ERROR_TYPE_ATTR_GROUP, NULL,
1951 "only group 0 is supported");
1953 return rte_flow_error_set(error, ENOTSUP,
1954 RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
1955 NULL, "transfer is not supported");
1960 * Validate the count action.
1963 * Pointer to the Ethernet device structure.
1965 * Attributes of flow that includes this action.
1967 * Pointer to error structure.
1970 * 0 on success, a negative errno value otherwise and rte_errno is set.
1973 mlx5_flow_validate_action_count(struct rte_eth_dev *dev __rte_unused,
1974 const struct rte_flow_attr *attr,
1975 struct rte_flow_error *error)
1978 return rte_flow_error_set(error, ENOTSUP,
1979 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1980 "count action not supported for "
1986 * Validate the ASO CT action.
1989 * Pointer to the Ethernet device structure.
1990 * @param[in] conntrack
1991 * Pointer to the CT action profile.
1993 * Pointer to error structure.
1996 * 0 on success, a negative errno value otherwise and rte_errno is set.
1999 mlx5_validate_action_ct(struct rte_eth_dev *dev,
2000 const struct rte_flow_action_conntrack *conntrack,
2001 struct rte_flow_error *error)
2005 if (conntrack->state > RTE_FLOW_CONNTRACK_STATE_TIME_WAIT)
2006 return rte_flow_error_set(error, EINVAL,
2007 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2008 "Invalid CT state");
2009 if (conntrack->last_index > RTE_FLOW_CONNTRACK_FLAG_RST)
2010 return rte_flow_error_set(error, EINVAL,
2011 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2012 "Invalid last TCP packet flag");
2017 * Verify the @p attributes will be correctly understood by the NIC and store
2018 * them in the @p flow if everything is correct.
2021 * Pointer to the Ethernet device structure.
2022 * @param[in] attributes
2023 * Pointer to flow attributes
2025 * Pointer to error structure.
2028 * 0 on success, a negative errno value otherwise and rte_errno is set.
2031 mlx5_flow_validate_attributes(struct rte_eth_dev *dev,
2032 const struct rte_flow_attr *attributes,
2033 struct rte_flow_error *error)
2035 struct mlx5_priv *priv = dev->data->dev_private;
2036 uint32_t priority_max = priv->sh->flow_max_priority - 1;
2038 if (attributes->group)
2039 return rte_flow_error_set(error, ENOTSUP,
2040 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
2041 NULL, "groups is not supported");
2042 if (attributes->priority != MLX5_FLOW_LOWEST_PRIO_INDICATOR &&
2043 attributes->priority >= priority_max)
2044 return rte_flow_error_set(error, ENOTSUP,
2045 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
2046 NULL, "priority out of range");
2047 if (attributes->egress)
2048 return rte_flow_error_set(error, ENOTSUP,
2049 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
2050 "egress is not supported");
2051 if (attributes->transfer && !priv->sh->config.dv_esw_en)
2052 return rte_flow_error_set(error, ENOTSUP,
2053 RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
2054 NULL, "transfer is not supported");
2055 if (!attributes->ingress)
2056 return rte_flow_error_set(error, EINVAL,
2057 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
2059 "ingress attribute is mandatory");
2064 * Validate ICMP6 item.
2067 * Item specification.
2068 * @param[in] item_flags
2069 * Bit-fields that holds the items detected until now.
2070 * @param[in] ext_vlan_sup
2071 * Whether extended VLAN features are supported or not.
2073 * Pointer to error structure.
2076 * 0 on success, a negative errno value otherwise and rte_errno is set.
2079 mlx5_flow_validate_item_icmp6(const struct rte_flow_item *item,
2080 uint64_t item_flags,
2081 uint8_t target_protocol,
2082 struct rte_flow_error *error)
2084 const struct rte_flow_item_icmp6 *mask = item->mask;
2085 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2086 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
2087 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
2088 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2089 MLX5_FLOW_LAYER_OUTER_L4;
2092 if (target_protocol != 0xFF && target_protocol != IPPROTO_ICMPV6)
2093 return rte_flow_error_set(error, EINVAL,
2094 RTE_FLOW_ERROR_TYPE_ITEM, item,
2095 "protocol filtering not compatible"
2096 " with ICMP6 layer");
2097 if (!(item_flags & l3m))
2098 return rte_flow_error_set(error, EINVAL,
2099 RTE_FLOW_ERROR_TYPE_ITEM, item,
2100 "IPv6 is mandatory to filter on"
2102 if (item_flags & l4m)
2103 return rte_flow_error_set(error, EINVAL,
2104 RTE_FLOW_ERROR_TYPE_ITEM, item,
2105 "multiple L4 layers not supported");
2107 mask = &rte_flow_item_icmp6_mask;
2108 ret = mlx5_flow_item_acceptable
2109 (item, (const uint8_t *)mask,
2110 (const uint8_t *)&rte_flow_item_icmp6_mask,
2111 sizeof(struct rte_flow_item_icmp6),
2112 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2119 * Validate ICMP item.
2122 * Item specification.
2123 * @param[in] item_flags
2124 * Bit-fields that holds the items detected until now.
2126 * Pointer to error structure.
2129 * 0 on success, a negative errno value otherwise and rte_errno is set.
2132 mlx5_flow_validate_item_icmp(const struct rte_flow_item *item,
2133 uint64_t item_flags,
2134 uint8_t target_protocol,
2135 struct rte_flow_error *error)
2137 const struct rte_flow_item_icmp *mask = item->mask;
2138 const struct rte_flow_item_icmp nic_mask = {
2139 .hdr.icmp_type = 0xff,
2140 .hdr.icmp_code = 0xff,
2141 .hdr.icmp_ident = RTE_BE16(0xffff),
2142 .hdr.icmp_seq_nb = RTE_BE16(0xffff),
2144 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2145 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
2146 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
2147 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2148 MLX5_FLOW_LAYER_OUTER_L4;
2151 if (target_protocol != 0xFF && target_protocol != IPPROTO_ICMP)
2152 return rte_flow_error_set(error, EINVAL,
2153 RTE_FLOW_ERROR_TYPE_ITEM, item,
2154 "protocol filtering not compatible"
2155 " with ICMP layer");
2156 if (!(item_flags & l3m))
2157 return rte_flow_error_set(error, EINVAL,
2158 RTE_FLOW_ERROR_TYPE_ITEM, item,
2159 "IPv4 is mandatory to filter"
2161 if (item_flags & l4m)
2162 return rte_flow_error_set(error, EINVAL,
2163 RTE_FLOW_ERROR_TYPE_ITEM, item,
2164 "multiple L4 layers not supported");
2167 ret = mlx5_flow_item_acceptable
2168 (item, (const uint8_t *)mask,
2169 (const uint8_t *)&nic_mask,
2170 sizeof(struct rte_flow_item_icmp),
2171 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2178 * Validate Ethernet item.
2181 * Item specification.
2182 * @param[in] item_flags
2183 * Bit-fields that holds the items detected until now.
2185 * Pointer to error structure.
2188 * 0 on success, a negative errno value otherwise and rte_errno is set.
2191 mlx5_flow_validate_item_eth(const struct rte_flow_item *item,
2192 uint64_t item_flags, bool ext_vlan_sup,
2193 struct rte_flow_error *error)
2195 const struct rte_flow_item_eth *mask = item->mask;
2196 const struct rte_flow_item_eth nic_mask = {
2197 .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
2198 .src.addr_bytes = "\xff\xff\xff\xff\xff\xff",
2199 .type = RTE_BE16(0xffff),
2200 .has_vlan = ext_vlan_sup ? 1 : 0,
2203 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2204 const uint64_t ethm = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
2205 MLX5_FLOW_LAYER_OUTER_L2;
2207 if (item_flags & ethm)
2208 return rte_flow_error_set(error, ENOTSUP,
2209 RTE_FLOW_ERROR_TYPE_ITEM, item,
2210 "multiple L2 layers not supported");
2211 if ((!tunnel && (item_flags & MLX5_FLOW_LAYER_OUTER_L3)) ||
2212 (tunnel && (item_flags & MLX5_FLOW_LAYER_INNER_L3)))
2213 return rte_flow_error_set(error, EINVAL,
2214 RTE_FLOW_ERROR_TYPE_ITEM, item,
2215 "L2 layer should not follow "
2217 if ((!tunnel && (item_flags & MLX5_FLOW_LAYER_OUTER_VLAN)) ||
2218 (tunnel && (item_flags & MLX5_FLOW_LAYER_INNER_VLAN)))
2219 return rte_flow_error_set(error, EINVAL,
2220 RTE_FLOW_ERROR_TYPE_ITEM, item,
2221 "L2 layer should not follow VLAN");
2222 if (item_flags & MLX5_FLOW_LAYER_GTP)
2223 return rte_flow_error_set(error, EINVAL,
2224 RTE_FLOW_ERROR_TYPE_ITEM, item,
2225 "L2 layer should not follow GTP");
2227 mask = &rte_flow_item_eth_mask;
2228 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2229 (const uint8_t *)&nic_mask,
2230 sizeof(struct rte_flow_item_eth),
2231 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2236 * Validate VLAN item.
2239 * Item specification.
2240 * @param[in] item_flags
2241 * Bit-fields that holds the items detected until now.
2243 * Ethernet device flow is being created on.
2245 * Pointer to error structure.
2248 * 0 on success, a negative errno value otherwise and rte_errno is set.
2251 mlx5_flow_validate_item_vlan(const struct rte_flow_item *item,
2252 uint64_t item_flags,
2253 struct rte_eth_dev *dev,
2254 struct rte_flow_error *error)
2256 const struct rte_flow_item_vlan *spec = item->spec;
2257 const struct rte_flow_item_vlan *mask = item->mask;
2258 const struct rte_flow_item_vlan nic_mask = {
2259 .tci = RTE_BE16(UINT16_MAX),
2260 .inner_type = RTE_BE16(UINT16_MAX),
2262 uint16_t vlan_tag = 0;
2263 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2265 const uint64_t l34m = tunnel ? (MLX5_FLOW_LAYER_INNER_L3 |
2266 MLX5_FLOW_LAYER_INNER_L4) :
2267 (MLX5_FLOW_LAYER_OUTER_L3 |
2268 MLX5_FLOW_LAYER_OUTER_L4);
2269 const uint64_t vlanm = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
2270 MLX5_FLOW_LAYER_OUTER_VLAN;
2272 if (item_flags & vlanm)
2273 return rte_flow_error_set(error, EINVAL,
2274 RTE_FLOW_ERROR_TYPE_ITEM, item,
2275 "multiple VLAN layers not supported");
2276 else if ((item_flags & l34m) != 0)
2277 return rte_flow_error_set(error, EINVAL,
2278 RTE_FLOW_ERROR_TYPE_ITEM, item,
2279 "VLAN cannot follow L3/L4 layer");
2281 mask = &rte_flow_item_vlan_mask;
2282 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2283 (const uint8_t *)&nic_mask,
2284 sizeof(struct rte_flow_item_vlan),
2285 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2288 if (!tunnel && mask->tci != RTE_BE16(0x0fff)) {
2289 struct mlx5_priv *priv = dev->data->dev_private;
2291 if (priv->vmwa_context) {
2293 * Non-NULL context means we have a virtual machine
2294 * and SR-IOV enabled, we have to create VLAN interface
2295 * to make hypervisor to setup E-Switch vport
2296 * context correctly. We avoid creating the multiple
2297 * VLAN interfaces, so we cannot support VLAN tag mask.
2299 return rte_flow_error_set(error, EINVAL,
2300 RTE_FLOW_ERROR_TYPE_ITEM,
2302 "VLAN tag mask is not"
2303 " supported in virtual"
2308 vlan_tag = spec->tci;
2309 vlan_tag &= mask->tci;
2312 * From verbs perspective an empty VLAN is equivalent
2313 * to a packet without VLAN layer.
2316 return rte_flow_error_set(error, EINVAL,
2317 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
2319 "VLAN cannot be empty");
2324 * Validate IPV4 item.
2327 * Item specification.
2328 * @param[in] item_flags
2329 * Bit-fields that holds the items detected until now.
2330 * @param[in] last_item
2331 * Previous validated item in the pattern items.
2332 * @param[in] ether_type
2333 * Type in the ethernet layer header (including dot1q).
2334 * @param[in] acc_mask
2335 * Acceptable mask, if NULL default internal default mask
2336 * will be used to check whether item fields are supported.
2337 * @param[in] range_accepted
2338 * True if range of values is accepted for specific fields, false otherwise.
2340 * Pointer to error structure.
2343 * 0 on success, a negative errno value otherwise and rte_errno is set.
2346 mlx5_flow_validate_item_ipv4(const struct rte_flow_item *item,
2347 uint64_t item_flags,
2349 uint16_t ether_type,
2350 const struct rte_flow_item_ipv4 *acc_mask,
2351 bool range_accepted,
2352 struct rte_flow_error *error)
2354 const struct rte_flow_item_ipv4 *mask = item->mask;
2355 const struct rte_flow_item_ipv4 *spec = item->spec;
2356 const struct rte_flow_item_ipv4 nic_mask = {
2358 .src_addr = RTE_BE32(0xffffffff),
2359 .dst_addr = RTE_BE32(0xffffffff),
2360 .type_of_service = 0xff,
2361 .next_proto_id = 0xff,
2364 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2365 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2366 MLX5_FLOW_LAYER_OUTER_L3;
2367 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2368 MLX5_FLOW_LAYER_OUTER_L4;
2370 uint8_t next_proto = 0xFF;
2371 const uint64_t l2_vlan = (MLX5_FLOW_LAYER_L2 |
2372 MLX5_FLOW_LAYER_OUTER_VLAN |
2373 MLX5_FLOW_LAYER_INNER_VLAN);
2375 if ((last_item & l2_vlan) && ether_type &&
2376 ether_type != RTE_ETHER_TYPE_IPV4)
2377 return rte_flow_error_set(error, EINVAL,
2378 RTE_FLOW_ERROR_TYPE_ITEM, item,
2379 "IPv4 cannot follow L2/VLAN layer "
2380 "which ether type is not IPv4");
2381 if (item_flags & MLX5_FLOW_LAYER_TUNNEL) {
2383 next_proto = mask->hdr.next_proto_id &
2384 spec->hdr.next_proto_id;
2385 if (next_proto == IPPROTO_IPIP || next_proto == IPPROTO_IPV6)
2386 return rte_flow_error_set(error, EINVAL,
2387 RTE_FLOW_ERROR_TYPE_ITEM,
2392 if (item_flags & MLX5_FLOW_LAYER_IPV6_ENCAP)
2393 return rte_flow_error_set(error, EINVAL,
2394 RTE_FLOW_ERROR_TYPE_ITEM, item,
2395 "wrong tunnel type - IPv6 specified "
2396 "but IPv4 item provided");
2397 if (item_flags & l3m)
2398 return rte_flow_error_set(error, ENOTSUP,
2399 RTE_FLOW_ERROR_TYPE_ITEM, item,
2400 "multiple L3 layers not supported");
2401 else if (item_flags & l4m)
2402 return rte_flow_error_set(error, EINVAL,
2403 RTE_FLOW_ERROR_TYPE_ITEM, item,
2404 "L3 cannot follow an L4 layer.");
2405 else if ((item_flags & MLX5_FLOW_LAYER_NVGRE) &&
2406 !(item_flags & MLX5_FLOW_LAYER_INNER_L2))
2407 return rte_flow_error_set(error, EINVAL,
2408 RTE_FLOW_ERROR_TYPE_ITEM, item,
2409 "L3 cannot follow an NVGRE layer.");
2411 mask = &rte_flow_item_ipv4_mask;
2412 else if (mask->hdr.next_proto_id != 0 &&
2413 mask->hdr.next_proto_id != 0xff)
2414 return rte_flow_error_set(error, EINVAL,
2415 RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
2416 "partial mask is not supported"
2418 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2419 acc_mask ? (const uint8_t *)acc_mask
2420 : (const uint8_t *)&nic_mask,
2421 sizeof(struct rte_flow_item_ipv4),
2422 range_accepted, error);
2429 * Validate IPV6 item.
2432 * Item specification.
2433 * @param[in] item_flags
2434 * Bit-fields that holds the items detected until now.
2435 * @param[in] last_item
2436 * Previous validated item in the pattern items.
2437 * @param[in] ether_type
2438 * Type in the ethernet layer header (including dot1q).
2439 * @param[in] acc_mask
2440 * Acceptable mask, if NULL default internal default mask
2441 * will be used to check whether item fields are supported.
2443 * Pointer to error structure.
2446 * 0 on success, a negative errno value otherwise and rte_errno is set.
2449 mlx5_flow_validate_item_ipv6(const struct rte_flow_item *item,
2450 uint64_t item_flags,
2452 uint16_t ether_type,
2453 const struct rte_flow_item_ipv6 *acc_mask,
2454 struct rte_flow_error *error)
2456 const struct rte_flow_item_ipv6 *mask = item->mask;
2457 const struct rte_flow_item_ipv6 *spec = item->spec;
2458 const struct rte_flow_item_ipv6 nic_mask = {
2461 "\xff\xff\xff\xff\xff\xff\xff\xff"
2462 "\xff\xff\xff\xff\xff\xff\xff\xff",
2464 "\xff\xff\xff\xff\xff\xff\xff\xff"
2465 "\xff\xff\xff\xff\xff\xff\xff\xff",
2466 .vtc_flow = RTE_BE32(0xffffffff),
2470 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2471 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2472 MLX5_FLOW_LAYER_OUTER_L3;
2473 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2474 MLX5_FLOW_LAYER_OUTER_L4;
2476 uint8_t next_proto = 0xFF;
2477 const uint64_t l2_vlan = (MLX5_FLOW_LAYER_L2 |
2478 MLX5_FLOW_LAYER_OUTER_VLAN |
2479 MLX5_FLOW_LAYER_INNER_VLAN);
2481 if ((last_item & l2_vlan) && ether_type &&
2482 ether_type != RTE_ETHER_TYPE_IPV6)
2483 return rte_flow_error_set(error, EINVAL,
2484 RTE_FLOW_ERROR_TYPE_ITEM, item,
2485 "IPv6 cannot follow L2/VLAN layer "
2486 "which ether type is not IPv6");
2487 if (mask && mask->hdr.proto == UINT8_MAX && spec)
2488 next_proto = spec->hdr.proto;
2489 if (item_flags & MLX5_FLOW_LAYER_TUNNEL) {
2490 if (next_proto == IPPROTO_IPIP || next_proto == IPPROTO_IPV6)
2491 return rte_flow_error_set(error, EINVAL,
2492 RTE_FLOW_ERROR_TYPE_ITEM,
2497 if (next_proto == IPPROTO_HOPOPTS ||
2498 next_proto == IPPROTO_ROUTING ||
2499 next_proto == IPPROTO_FRAGMENT ||
2500 next_proto == IPPROTO_ESP ||
2501 next_proto == IPPROTO_AH ||
2502 next_proto == IPPROTO_DSTOPTS)
2503 return rte_flow_error_set(error, EINVAL,
2504 RTE_FLOW_ERROR_TYPE_ITEM, item,
2505 "IPv6 proto (next header) should "
2506 "not be set as extension header");
2507 if (item_flags & MLX5_FLOW_LAYER_IPIP)
2508 return rte_flow_error_set(error, EINVAL,
2509 RTE_FLOW_ERROR_TYPE_ITEM, item,
2510 "wrong tunnel type - IPv4 specified "
2511 "but IPv6 item provided");
2512 if (item_flags & l3m)
2513 return rte_flow_error_set(error, ENOTSUP,
2514 RTE_FLOW_ERROR_TYPE_ITEM, item,
2515 "multiple L3 layers not supported");
2516 else if (item_flags & l4m)
2517 return rte_flow_error_set(error, EINVAL,
2518 RTE_FLOW_ERROR_TYPE_ITEM, item,
2519 "L3 cannot follow an L4 layer.");
2520 else if ((item_flags & MLX5_FLOW_LAYER_NVGRE) &&
2521 !(item_flags & MLX5_FLOW_LAYER_INNER_L2))
2522 return rte_flow_error_set(error, EINVAL,
2523 RTE_FLOW_ERROR_TYPE_ITEM, item,
2524 "L3 cannot follow an NVGRE layer.");
2526 mask = &rte_flow_item_ipv6_mask;
2527 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2528 acc_mask ? (const uint8_t *)acc_mask
2529 : (const uint8_t *)&nic_mask,
2530 sizeof(struct rte_flow_item_ipv6),
2531 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2538 * Validate UDP item.
2541 * Item specification.
2542 * @param[in] item_flags
2543 * Bit-fields that holds the items detected until now.
2544 * @param[in] target_protocol
2545 * The next protocol in the previous item.
2546 * @param[in] flow_mask
2547 * mlx5 flow-specific (DV, verbs, etc.) supported header fields mask.
2549 * Pointer to error structure.
2552 * 0 on success, a negative errno value otherwise and rte_errno is set.
2555 mlx5_flow_validate_item_udp(const struct rte_flow_item *item,
2556 uint64_t item_flags,
2557 uint8_t target_protocol,
2558 struct rte_flow_error *error)
2560 const struct rte_flow_item_udp *mask = item->mask;
2561 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2562 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2563 MLX5_FLOW_LAYER_OUTER_L3;
2564 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2565 MLX5_FLOW_LAYER_OUTER_L4;
2568 if (target_protocol != 0xff && target_protocol != IPPROTO_UDP)
2569 return rte_flow_error_set(error, EINVAL,
2570 RTE_FLOW_ERROR_TYPE_ITEM, item,
2571 "protocol filtering not compatible"
2573 if (!(item_flags & l3m))
2574 return rte_flow_error_set(error, EINVAL,
2575 RTE_FLOW_ERROR_TYPE_ITEM, item,
2576 "L3 is mandatory to filter on L4");
2577 if (item_flags & l4m)
2578 return rte_flow_error_set(error, EINVAL,
2579 RTE_FLOW_ERROR_TYPE_ITEM, item,
2580 "multiple L4 layers not supported");
2582 mask = &rte_flow_item_udp_mask;
2583 ret = mlx5_flow_item_acceptable
2584 (item, (const uint8_t *)mask,
2585 (const uint8_t *)&rte_flow_item_udp_mask,
2586 sizeof(struct rte_flow_item_udp), MLX5_ITEM_RANGE_NOT_ACCEPTED,
2594 * Validate TCP item.
2597 * Item specification.
2598 * @param[in] item_flags
2599 * Bit-fields that holds the items detected until now.
2600 * @param[in] target_protocol
2601 * The next protocol in the previous item.
2603 * Pointer to error structure.
2606 * 0 on success, a negative errno value otherwise and rte_errno is set.
2609 mlx5_flow_validate_item_tcp(const struct rte_flow_item *item,
2610 uint64_t item_flags,
2611 uint8_t target_protocol,
2612 const struct rte_flow_item_tcp *flow_mask,
2613 struct rte_flow_error *error)
2615 const struct rte_flow_item_tcp *mask = item->mask;
2616 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2617 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2618 MLX5_FLOW_LAYER_OUTER_L3;
2619 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2620 MLX5_FLOW_LAYER_OUTER_L4;
2623 MLX5_ASSERT(flow_mask);
2624 if (target_protocol != 0xff && target_protocol != IPPROTO_TCP)
2625 return rte_flow_error_set(error, EINVAL,
2626 RTE_FLOW_ERROR_TYPE_ITEM, item,
2627 "protocol filtering not compatible"
2629 if (!(item_flags & l3m))
2630 return rte_flow_error_set(error, EINVAL,
2631 RTE_FLOW_ERROR_TYPE_ITEM, item,
2632 "L3 is mandatory to filter on L4");
2633 if (item_flags & l4m)
2634 return rte_flow_error_set(error, EINVAL,
2635 RTE_FLOW_ERROR_TYPE_ITEM, item,
2636 "multiple L4 layers not supported");
2638 mask = &rte_flow_item_tcp_mask;
2639 ret = mlx5_flow_item_acceptable
2640 (item, (const uint8_t *)mask,
2641 (const uint8_t *)flow_mask,
2642 sizeof(struct rte_flow_item_tcp), MLX5_ITEM_RANGE_NOT_ACCEPTED,
2650 * Validate VXLAN item.
2653 * Pointer to the Ethernet device structure.
2654 * @param[in] udp_dport
2655 * UDP destination port
2657 * Item specification.
2658 * @param[in] item_flags
2659 * Bit-fields that holds the items detected until now.
2661 * Flow rule attributes.
2663 * Pointer to error structure.
2666 * 0 on success, a negative errno value otherwise and rte_errno is set.
2669 mlx5_flow_validate_item_vxlan(struct rte_eth_dev *dev,
2671 const struct rte_flow_item *item,
2672 uint64_t item_flags,
2673 const struct rte_flow_attr *attr,
2674 struct rte_flow_error *error)
2676 const struct rte_flow_item_vxlan *spec = item->spec;
2677 const struct rte_flow_item_vxlan *mask = item->mask;
2679 struct mlx5_priv *priv = dev->data->dev_private;
2683 } id = { .vlan_id = 0, };
2684 const struct rte_flow_item_vxlan nic_mask = {
2685 .vni = "\xff\xff\xff",
2688 const struct rte_flow_item_vxlan *valid_mask;
2690 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2691 return rte_flow_error_set(error, ENOTSUP,
2692 RTE_FLOW_ERROR_TYPE_ITEM, item,
2693 "multiple tunnel layers not"
2695 valid_mask = &rte_flow_item_vxlan_mask;
2697 * Verify only UDPv4 is present as defined in
2698 * https://tools.ietf.org/html/rfc7348
2700 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2701 return rte_flow_error_set(error, EINVAL,
2702 RTE_FLOW_ERROR_TYPE_ITEM, item,
2703 "no outer UDP layer found");
2705 mask = &rte_flow_item_vxlan_mask;
2707 if (priv->sh->steering_format_version !=
2708 MLX5_STEERING_LOGIC_FORMAT_CONNECTX_5 ||
2709 !udp_dport || udp_dport == MLX5_UDP_PORT_VXLAN) {
2710 /* FDB domain & NIC domain non-zero group */
2711 if ((attr->transfer || attr->group) && priv->sh->misc5_cap)
2712 valid_mask = &nic_mask;
2713 /* Group zero in NIC domain */
2714 if (!attr->group && !attr->transfer &&
2715 priv->sh->tunnel_header_0_1)
2716 valid_mask = &nic_mask;
2718 ret = mlx5_flow_item_acceptable
2719 (item, (const uint8_t *)mask,
2720 (const uint8_t *)valid_mask,
2721 sizeof(struct rte_flow_item_vxlan),
2722 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2726 memcpy(&id.vni[1], spec->vni, 3);
2727 memcpy(&id.vni[1], mask->vni, 3);
2729 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
2730 return rte_flow_error_set(error, ENOTSUP,
2731 RTE_FLOW_ERROR_TYPE_ITEM, item,
2732 "VXLAN tunnel must be fully defined");
2737 * Validate VXLAN_GPE item.
2740 * Item specification.
2741 * @param[in] item_flags
2742 * Bit-fields that holds the items detected until now.
2744 * Pointer to the private data structure.
2745 * @param[in] target_protocol
2746 * The next protocol in the previous item.
2748 * Pointer to error structure.
2751 * 0 on success, a negative errno value otherwise and rte_errno is set.
2754 mlx5_flow_validate_item_vxlan_gpe(const struct rte_flow_item *item,
2755 uint64_t item_flags,
2756 struct rte_eth_dev *dev,
2757 struct rte_flow_error *error)
2759 struct mlx5_priv *priv = dev->data->dev_private;
2760 const struct rte_flow_item_vxlan_gpe *spec = item->spec;
2761 const struct rte_flow_item_vxlan_gpe *mask = item->mask;
2766 } id = { .vlan_id = 0, };
2768 if (!priv->sh->config.l3_vxlan_en)
2769 return rte_flow_error_set(error, ENOTSUP,
2770 RTE_FLOW_ERROR_TYPE_ITEM, item,
2771 "L3 VXLAN is not enabled by device"
2772 " parameter and/or not configured in"
2774 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2775 return rte_flow_error_set(error, ENOTSUP,
2776 RTE_FLOW_ERROR_TYPE_ITEM, item,
2777 "multiple tunnel layers not"
2780 * Verify only UDPv4 is present as defined in
2781 * https://tools.ietf.org/html/rfc7348
2783 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2784 return rte_flow_error_set(error, EINVAL,
2785 RTE_FLOW_ERROR_TYPE_ITEM, item,
2786 "no outer UDP layer found");
2788 mask = &rte_flow_item_vxlan_gpe_mask;
2789 ret = mlx5_flow_item_acceptable
2790 (item, (const uint8_t *)mask,
2791 (const uint8_t *)&rte_flow_item_vxlan_gpe_mask,
2792 sizeof(struct rte_flow_item_vxlan_gpe),
2793 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2798 return rte_flow_error_set(error, ENOTSUP,
2799 RTE_FLOW_ERROR_TYPE_ITEM,
2801 "VxLAN-GPE protocol"
2803 memcpy(&id.vni[1], spec->vni, 3);
2804 memcpy(&id.vni[1], mask->vni, 3);
2806 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
2807 return rte_flow_error_set(error, ENOTSUP,
2808 RTE_FLOW_ERROR_TYPE_ITEM, item,
2809 "VXLAN-GPE tunnel must be fully"
2814 * Validate GRE Key item.
2817 * Item specification.
2818 * @param[in] item_flags
2819 * Bit flags to mark detected items.
2820 * @param[in] gre_item
2821 * Pointer to gre_item
2823 * Pointer to error structure.
2826 * 0 on success, a negative errno value otherwise and rte_errno is set.
2829 mlx5_flow_validate_item_gre_key(const struct rte_flow_item *item,
2830 uint64_t item_flags,
2831 const struct rte_flow_item *gre_item,
2832 struct rte_flow_error *error)
2834 const rte_be32_t *mask = item->mask;
2836 rte_be32_t gre_key_default_mask = RTE_BE32(UINT32_MAX);
2837 const struct rte_flow_item_gre *gre_spec;
2838 const struct rte_flow_item_gre *gre_mask;
2840 if (item_flags & MLX5_FLOW_LAYER_GRE_KEY)
2841 return rte_flow_error_set(error, ENOTSUP,
2842 RTE_FLOW_ERROR_TYPE_ITEM, item,
2843 "Multiple GRE key not support");
2844 if (!(item_flags & MLX5_FLOW_LAYER_GRE))
2845 return rte_flow_error_set(error, ENOTSUP,
2846 RTE_FLOW_ERROR_TYPE_ITEM, item,
2847 "No preceding GRE header");
2848 if (item_flags & MLX5_FLOW_LAYER_INNER)
2849 return rte_flow_error_set(error, ENOTSUP,
2850 RTE_FLOW_ERROR_TYPE_ITEM, item,
2851 "GRE key following a wrong item");
2852 gre_mask = gre_item->mask;
2854 gre_mask = &rte_flow_item_gre_mask;
2855 gre_spec = gre_item->spec;
2856 if (gre_spec && (gre_mask->c_rsvd0_ver & RTE_BE16(0x2000)) &&
2857 !(gre_spec->c_rsvd0_ver & RTE_BE16(0x2000)))
2858 return rte_flow_error_set(error, EINVAL,
2859 RTE_FLOW_ERROR_TYPE_ITEM, item,
2860 "Key bit must be on");
2863 mask = &gre_key_default_mask;
2864 ret = mlx5_flow_item_acceptable
2865 (item, (const uint8_t *)mask,
2866 (const uint8_t *)&gre_key_default_mask,
2867 sizeof(rte_be32_t), MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2872 * Validate GRE item.
2875 * Item specification.
2876 * @param[in] item_flags
2877 * Bit flags to mark detected items.
2878 * @param[in] target_protocol
2879 * The next protocol in the previous item.
2881 * Pointer to error structure.
2884 * 0 on success, a negative errno value otherwise and rte_errno is set.
2887 mlx5_flow_validate_item_gre(const struct rte_flow_item *item,
2888 uint64_t item_flags,
2889 uint8_t target_protocol,
2890 struct rte_flow_error *error)
2892 const struct rte_flow_item_gre *spec __rte_unused = item->spec;
2893 const struct rte_flow_item_gre *mask = item->mask;
2895 const struct rte_flow_item_gre nic_mask = {
2896 .c_rsvd0_ver = RTE_BE16(0xB000),
2897 .protocol = RTE_BE16(UINT16_MAX),
2900 if (target_protocol != 0xff && target_protocol != IPPROTO_GRE)
2901 return rte_flow_error_set(error, EINVAL,
2902 RTE_FLOW_ERROR_TYPE_ITEM, item,
2903 "protocol filtering not compatible"
2904 " with this GRE layer");
2905 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2906 return rte_flow_error_set(error, ENOTSUP,
2907 RTE_FLOW_ERROR_TYPE_ITEM, item,
2908 "multiple tunnel layers not"
2910 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3))
2911 return rte_flow_error_set(error, ENOTSUP,
2912 RTE_FLOW_ERROR_TYPE_ITEM, item,
2913 "L3 Layer is missing");
2915 mask = &rte_flow_item_gre_mask;
2916 ret = mlx5_flow_item_acceptable
2917 (item, (const uint8_t *)mask,
2918 (const uint8_t *)&nic_mask,
2919 sizeof(struct rte_flow_item_gre), MLX5_ITEM_RANGE_NOT_ACCEPTED,
2923 #ifndef HAVE_MLX5DV_DR
2924 #ifndef HAVE_IBV_DEVICE_MPLS_SUPPORT
2925 if (spec && (spec->protocol & mask->protocol))
2926 return rte_flow_error_set(error, ENOTSUP,
2927 RTE_FLOW_ERROR_TYPE_ITEM, item,
2928 "without MPLS support the"
2929 " specification cannot be used for"
2937 * Validate Geneve item.
2940 * Item specification.
2941 * @param[in] itemFlags
2942 * Bit-fields that holds the items detected until now.
2944 * Pointer to the private data structure.
2946 * Pointer to error structure.
2949 * 0 on success, a negative errno value otherwise and rte_errno is set.
2953 mlx5_flow_validate_item_geneve(const struct rte_flow_item *item,
2954 uint64_t item_flags,
2955 struct rte_eth_dev *dev,
2956 struct rte_flow_error *error)
2958 struct mlx5_priv *priv = dev->data->dev_private;
2959 const struct rte_flow_item_geneve *spec = item->spec;
2960 const struct rte_flow_item_geneve *mask = item->mask;
2963 uint8_t opt_len = priv->sh->cdev->config.hca_attr.geneve_max_opt_len ?
2964 MLX5_GENEVE_OPT_LEN_1 : MLX5_GENEVE_OPT_LEN_0;
2965 const struct rte_flow_item_geneve nic_mask = {
2966 .ver_opt_len_o_c_rsvd0 = RTE_BE16(0x3f80),
2967 .vni = "\xff\xff\xff",
2968 .protocol = RTE_BE16(UINT16_MAX),
2971 if (!priv->sh->cdev->config.hca_attr.tunnel_stateless_geneve_rx)
2972 return rte_flow_error_set(error, ENOTSUP,
2973 RTE_FLOW_ERROR_TYPE_ITEM, item,
2974 "L3 Geneve is not enabled by device"
2975 " parameter and/or not configured in"
2977 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2978 return rte_flow_error_set(error, ENOTSUP,
2979 RTE_FLOW_ERROR_TYPE_ITEM, item,
2980 "multiple tunnel layers not"
2983 * Verify only UDPv4 is present as defined in
2984 * https://tools.ietf.org/html/rfc7348
2986 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2987 return rte_flow_error_set(error, EINVAL,
2988 RTE_FLOW_ERROR_TYPE_ITEM, item,
2989 "no outer UDP layer found");
2991 mask = &rte_flow_item_geneve_mask;
2992 ret = mlx5_flow_item_acceptable
2993 (item, (const uint8_t *)mask,
2994 (const uint8_t *)&nic_mask,
2995 sizeof(struct rte_flow_item_geneve),
2996 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
3000 gbhdr = rte_be_to_cpu_16(spec->ver_opt_len_o_c_rsvd0);
3001 if (MLX5_GENEVE_VER_VAL(gbhdr) ||
3002 MLX5_GENEVE_CRITO_VAL(gbhdr) ||
3003 MLX5_GENEVE_RSVD_VAL(gbhdr) || spec->rsvd1)
3004 return rte_flow_error_set(error, ENOTSUP,
3005 RTE_FLOW_ERROR_TYPE_ITEM,
3007 "Geneve protocol unsupported"
3008 " fields are being used");
3009 if (MLX5_GENEVE_OPTLEN_VAL(gbhdr) > opt_len)
3010 return rte_flow_error_set
3012 RTE_FLOW_ERROR_TYPE_ITEM,
3014 "Unsupported Geneve options length");
3016 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
3017 return rte_flow_error_set
3019 RTE_FLOW_ERROR_TYPE_ITEM, item,
3020 "Geneve tunnel must be fully defined");
3025 * Validate Geneve TLV option item.
3028 * Item specification.
3029 * @param[in] last_item
3030 * Previous validated item in the pattern items.
3031 * @param[in] geneve_item
3032 * Previous GENEVE item specification.
3034 * Pointer to the rte_eth_dev structure.
3036 * Pointer to error structure.
3039 * 0 on success, a negative errno value otherwise and rte_errno is set.
3042 mlx5_flow_validate_item_geneve_opt(const struct rte_flow_item *item,
3044 const struct rte_flow_item *geneve_item,
3045 struct rte_eth_dev *dev,
3046 struct rte_flow_error *error)
3048 struct mlx5_priv *priv = dev->data->dev_private;
3049 struct mlx5_dev_ctx_shared *sh = priv->sh;
3050 struct mlx5_geneve_tlv_option_resource *geneve_opt_resource;
3051 struct mlx5_hca_attr *hca_attr = &sh->cdev->config.hca_attr;
3052 uint8_t data_max_supported =
3053 hca_attr->max_geneve_tlv_option_data_len * 4;
3054 const struct rte_flow_item_geneve *geneve_spec;
3055 const struct rte_flow_item_geneve *geneve_mask;
3056 const struct rte_flow_item_geneve_opt *spec = item->spec;
3057 const struct rte_flow_item_geneve_opt *mask = item->mask;
3059 unsigned int data_len;
3060 uint8_t tlv_option_len;
3061 uint16_t optlen_m, optlen_v;
3062 const struct rte_flow_item_geneve_opt full_mask = {
3063 .option_class = RTE_BE16(0xffff),
3064 .option_type = 0xff,
3069 mask = &rte_flow_item_geneve_opt_mask;
3071 return rte_flow_error_set
3072 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
3073 "Geneve TLV opt class/type/length must be specified");
3074 if ((uint32_t)spec->option_len > MLX5_GENEVE_OPTLEN_MASK)
3075 return rte_flow_error_set
3076 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
3077 "Geneve TLV opt length exceeds the limit (31)");
3078 /* Check if class type and length masks are full. */
3079 if (full_mask.option_class != mask->option_class ||
3080 full_mask.option_type != mask->option_type ||
3081 full_mask.option_len != (mask->option_len & full_mask.option_len))
3082 return rte_flow_error_set
3083 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
3084 "Geneve TLV opt class/type/length masks must be full");
3085 /* Check if length is supported */
3086 if ((uint32_t)spec->option_len >
3087 hca_attr->max_geneve_tlv_option_data_len)
3088 return rte_flow_error_set
3089 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
3090 "Geneve TLV opt length not supported");
3091 if (hca_attr->max_geneve_tlv_options > 1)
3093 "max_geneve_tlv_options supports more than 1 option");
3094 /* Check GENEVE item preceding. */
3095 if (!geneve_item || !(last_item & MLX5_FLOW_LAYER_GENEVE))
3096 return rte_flow_error_set
3097 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
3098 "Geneve opt item must be preceded with Geneve item");
3099 geneve_spec = geneve_item->spec;
3100 geneve_mask = geneve_item->mask ? geneve_item->mask :
3101 &rte_flow_item_geneve_mask;
3102 /* Check if GENEVE TLV option size doesn't exceed option length */
3103 if (geneve_spec && (geneve_mask->ver_opt_len_o_c_rsvd0 ||
3104 geneve_spec->ver_opt_len_o_c_rsvd0)) {
3105 tlv_option_len = spec->option_len & mask->option_len;
3106 optlen_v = rte_be_to_cpu_16(geneve_spec->ver_opt_len_o_c_rsvd0);
3107 optlen_v = MLX5_GENEVE_OPTLEN_VAL(optlen_v);
3108 optlen_m = rte_be_to_cpu_16(geneve_mask->ver_opt_len_o_c_rsvd0);
3109 optlen_m = MLX5_GENEVE_OPTLEN_VAL(optlen_m);
3110 if ((optlen_v & optlen_m) <= tlv_option_len)
3111 return rte_flow_error_set
3112 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
3113 "GENEVE TLV option length exceeds optlen");
3115 /* Check if length is 0 or data is 0. */
3116 if (spec->data == NULL || spec->option_len == 0)
3117 return rte_flow_error_set
3118 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
3119 "Geneve TLV opt with zero data/length not supported");
3120 /* Check not all data & mask are 0. */
3121 data_len = spec->option_len * 4;
3122 if (mask->data == NULL) {
3123 for (i = 0; i < data_len; i++)
3127 return rte_flow_error_set(error, ENOTSUP,
3128 RTE_FLOW_ERROR_TYPE_ITEM, item,
3129 "Can't match on Geneve option data 0");
3131 for (i = 0; i < data_len; i++)
3132 if (spec->data[i] & mask->data[i])
3135 return rte_flow_error_set(error, ENOTSUP,
3136 RTE_FLOW_ERROR_TYPE_ITEM, item,
3137 "Can't match on Geneve option data and mask 0");
3138 /* Check data mask supported. */
3139 for (i = data_max_supported; i < data_len ; i++)
3141 return rte_flow_error_set(error, ENOTSUP,
3142 RTE_FLOW_ERROR_TYPE_ITEM, item,
3143 "Data mask is of unsupported size");
3145 /* Check GENEVE option is supported in NIC. */
3146 if (!hca_attr->geneve_tlv_opt)
3147 return rte_flow_error_set
3148 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
3149 "Geneve TLV opt not supported");
3150 /* Check if we already have geneve option with different type/class. */
3151 rte_spinlock_lock(&sh->geneve_tlv_opt_sl);
3152 geneve_opt_resource = sh->geneve_tlv_option_resource;
3153 if (geneve_opt_resource != NULL)
3154 if (geneve_opt_resource->option_class != spec->option_class ||
3155 geneve_opt_resource->option_type != spec->option_type ||
3156 geneve_opt_resource->length != spec->option_len) {
3157 rte_spinlock_unlock(&sh->geneve_tlv_opt_sl);
3158 return rte_flow_error_set(error, ENOTSUP,
3159 RTE_FLOW_ERROR_TYPE_ITEM, item,
3160 "Only one Geneve TLV option supported");
3162 rte_spinlock_unlock(&sh->geneve_tlv_opt_sl);
3167 * Validate MPLS item.
3170 * Pointer to the rte_eth_dev structure.
3172 * Item specification.
3173 * @param[in] item_flags
3174 * Bit-fields that holds the items detected until now.
3175 * @param[in] prev_layer
3176 * The protocol layer indicated in previous item.
3178 * Pointer to error structure.
3181 * 0 on success, a negative errno value otherwise and rte_errno is set.
3184 mlx5_flow_validate_item_mpls(struct rte_eth_dev *dev __rte_unused,
3185 const struct rte_flow_item *item __rte_unused,
3186 uint64_t item_flags __rte_unused,
3187 uint64_t prev_layer __rte_unused,
3188 struct rte_flow_error *error)
3190 #ifdef HAVE_IBV_DEVICE_MPLS_SUPPORT
3191 const struct rte_flow_item_mpls *mask = item->mask;
3192 struct mlx5_priv *priv = dev->data->dev_private;
3195 if (!priv->sh->dev_cap.mpls_en)
3196 return rte_flow_error_set(error, ENOTSUP,
3197 RTE_FLOW_ERROR_TYPE_ITEM, item,
3198 "MPLS not supported or"
3199 " disabled in firmware"
3201 /* MPLS over UDP, GRE is allowed */
3202 if (!(prev_layer & (MLX5_FLOW_LAYER_OUTER_L4_UDP |
3203 MLX5_FLOW_LAYER_GRE |
3204 MLX5_FLOW_LAYER_GRE_KEY)))
3205 return rte_flow_error_set(error, EINVAL,
3206 RTE_FLOW_ERROR_TYPE_ITEM, item,
3207 "protocol filtering not compatible"
3208 " with MPLS layer");
3209 /* Multi-tunnel isn't allowed but MPLS over GRE is an exception. */
3210 if ((item_flags & MLX5_FLOW_LAYER_TUNNEL) &&
3211 !(item_flags & MLX5_FLOW_LAYER_GRE))
3212 return rte_flow_error_set(error, ENOTSUP,
3213 RTE_FLOW_ERROR_TYPE_ITEM, item,
3214 "multiple tunnel layers not"
3217 mask = &rte_flow_item_mpls_mask;
3218 ret = mlx5_flow_item_acceptable
3219 (item, (const uint8_t *)mask,
3220 (const uint8_t *)&rte_flow_item_mpls_mask,
3221 sizeof(struct rte_flow_item_mpls),
3222 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
3227 return rte_flow_error_set(error, ENOTSUP,
3228 RTE_FLOW_ERROR_TYPE_ITEM, item,
3229 "MPLS is not supported by Verbs, please"
3235 * Validate NVGRE item.
3238 * Item specification.
3239 * @param[in] item_flags
3240 * Bit flags to mark detected items.
3241 * @param[in] target_protocol
3242 * The next protocol in the previous item.
3244 * Pointer to error structure.
3247 * 0 on success, a negative errno value otherwise and rte_errno is set.
3250 mlx5_flow_validate_item_nvgre(const struct rte_flow_item *item,
3251 uint64_t item_flags,
3252 uint8_t target_protocol,
3253 struct rte_flow_error *error)
3255 const struct rte_flow_item_nvgre *mask = item->mask;
3258 if (target_protocol != 0xff && target_protocol != IPPROTO_GRE)
3259 return rte_flow_error_set(error, EINVAL,
3260 RTE_FLOW_ERROR_TYPE_ITEM, item,
3261 "protocol filtering not compatible"
3262 " with this GRE layer");
3263 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
3264 return rte_flow_error_set(error, ENOTSUP,
3265 RTE_FLOW_ERROR_TYPE_ITEM, item,
3266 "multiple tunnel layers not"
3268 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3))
3269 return rte_flow_error_set(error, ENOTSUP,
3270 RTE_FLOW_ERROR_TYPE_ITEM, item,
3271 "L3 Layer is missing");
3273 mask = &rte_flow_item_nvgre_mask;
3274 ret = mlx5_flow_item_acceptable
3275 (item, (const uint8_t *)mask,
3276 (const uint8_t *)&rte_flow_item_nvgre_mask,
3277 sizeof(struct rte_flow_item_nvgre),
3278 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
3285 * Validate eCPRI item.
3288 * Item specification.
3289 * @param[in] item_flags
3290 * Bit-fields that holds the items detected until now.
3291 * @param[in] last_item
3292 * Previous validated item in the pattern items.
3293 * @param[in] ether_type
3294 * Type in the ethernet layer header (including dot1q).
3295 * @param[in] acc_mask
3296 * Acceptable mask, if NULL default internal default mask
3297 * will be used to check whether item fields are supported.
3299 * Pointer to error structure.
3302 * 0 on success, a negative errno value otherwise and rte_errno is set.
3305 mlx5_flow_validate_item_ecpri(const struct rte_flow_item *item,
3306 uint64_t item_flags,
3308 uint16_t ether_type,
3309 const struct rte_flow_item_ecpri *acc_mask,
3310 struct rte_flow_error *error)
3312 const struct rte_flow_item_ecpri *mask = item->mask;
3313 const struct rte_flow_item_ecpri nic_mask = {
3317 RTE_BE32(((const struct rte_ecpri_common_hdr) {
3321 .dummy[0] = 0xFFFFFFFF,
3324 const uint64_t outer_l2_vlan = (MLX5_FLOW_LAYER_OUTER_L2 |
3325 MLX5_FLOW_LAYER_OUTER_VLAN);
3326 struct rte_flow_item_ecpri mask_lo;
3328 if (!(last_item & outer_l2_vlan) &&
3329 last_item != MLX5_FLOW_LAYER_OUTER_L4_UDP)
3330 return rte_flow_error_set(error, EINVAL,
3331 RTE_FLOW_ERROR_TYPE_ITEM, item,
3332 "eCPRI can only follow L2/VLAN layer or UDP layer");
3333 if ((last_item & outer_l2_vlan) && ether_type &&
3334 ether_type != RTE_ETHER_TYPE_ECPRI)
3335 return rte_flow_error_set(error, EINVAL,
3336 RTE_FLOW_ERROR_TYPE_ITEM, item,
3337 "eCPRI cannot follow L2/VLAN layer which ether type is not 0xAEFE");
3338 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
3339 return rte_flow_error_set(error, EINVAL,
3340 RTE_FLOW_ERROR_TYPE_ITEM, item,
3341 "eCPRI with tunnel is not supported right now");
3342 if (item_flags & MLX5_FLOW_LAYER_OUTER_L3)
3343 return rte_flow_error_set(error, ENOTSUP,
3344 RTE_FLOW_ERROR_TYPE_ITEM, item,
3345 "multiple L3 layers not supported");
3346 else if (item_flags & MLX5_FLOW_LAYER_OUTER_L4_TCP)
3347 return rte_flow_error_set(error, EINVAL,
3348 RTE_FLOW_ERROR_TYPE_ITEM, item,
3349 "eCPRI cannot coexist with a TCP layer");
3350 /* In specification, eCPRI could be over UDP layer. */
3351 else if (item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP)
3352 return rte_flow_error_set(error, EINVAL,
3353 RTE_FLOW_ERROR_TYPE_ITEM, item,
3354 "eCPRI over UDP layer is not yet supported right now");
3355 /* Mask for type field in common header could be zero. */
3357 mask = &rte_flow_item_ecpri_mask;
3358 mask_lo.hdr.common.u32 = rte_be_to_cpu_32(mask->hdr.common.u32);
3359 /* Input mask is in big-endian format. */
3360 if (mask_lo.hdr.common.type != 0 && mask_lo.hdr.common.type != 0xff)
3361 return rte_flow_error_set(error, EINVAL,
3362 RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
3363 "partial mask is not supported for protocol");
3364 else if (mask_lo.hdr.common.type == 0 && mask->hdr.dummy[0] != 0)
3365 return rte_flow_error_set(error, EINVAL,
3366 RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
3367 "message header mask must be after a type mask");
3368 return mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
3369 acc_mask ? (const uint8_t *)acc_mask
3370 : (const uint8_t *)&nic_mask,
3371 sizeof(struct rte_flow_item_ecpri),
3372 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
3376 flow_null_validate(struct rte_eth_dev *dev __rte_unused,
3377 const struct rte_flow_attr *attr __rte_unused,
3378 const struct rte_flow_item items[] __rte_unused,
3379 const struct rte_flow_action actions[] __rte_unused,
3380 bool external __rte_unused,
3381 int hairpin __rte_unused,
3382 struct rte_flow_error *error)
3384 return rte_flow_error_set(error, ENOTSUP,
3385 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
3388 static struct mlx5_flow *
3389 flow_null_prepare(struct rte_eth_dev *dev __rte_unused,
3390 const struct rte_flow_attr *attr __rte_unused,
3391 const struct rte_flow_item items[] __rte_unused,
3392 const struct rte_flow_action actions[] __rte_unused,
3393 struct rte_flow_error *error)
3395 rte_flow_error_set(error, ENOTSUP,
3396 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
3401 flow_null_translate(struct rte_eth_dev *dev __rte_unused,
3402 struct mlx5_flow *dev_flow __rte_unused,
3403 const struct rte_flow_attr *attr __rte_unused,
3404 const struct rte_flow_item items[] __rte_unused,
3405 const struct rte_flow_action actions[] __rte_unused,
3406 struct rte_flow_error *error)
3408 return rte_flow_error_set(error, ENOTSUP,
3409 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
3413 flow_null_apply(struct rte_eth_dev *dev __rte_unused,
3414 struct rte_flow *flow __rte_unused,
3415 struct rte_flow_error *error)
3417 return rte_flow_error_set(error, ENOTSUP,
3418 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
3422 flow_null_remove(struct rte_eth_dev *dev __rte_unused,
3423 struct rte_flow *flow __rte_unused)
3428 flow_null_destroy(struct rte_eth_dev *dev __rte_unused,
3429 struct rte_flow *flow __rte_unused)
3434 flow_null_query(struct rte_eth_dev *dev __rte_unused,
3435 struct rte_flow *flow __rte_unused,
3436 const struct rte_flow_action *actions __rte_unused,
3437 void *data __rte_unused,
3438 struct rte_flow_error *error)
3440 return rte_flow_error_set(error, ENOTSUP,
3441 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
3445 flow_null_sync_domain(struct rte_eth_dev *dev __rte_unused,
3446 uint32_t domains __rte_unused,
3447 uint32_t flags __rte_unused)
3452 /* Void driver to protect from null pointer reference. */
3453 const struct mlx5_flow_driver_ops mlx5_flow_null_drv_ops = {
3454 .validate = flow_null_validate,
3455 .prepare = flow_null_prepare,
3456 .translate = flow_null_translate,
3457 .apply = flow_null_apply,
3458 .remove = flow_null_remove,
3459 .destroy = flow_null_destroy,
3460 .query = flow_null_query,
3461 .sync_domain = flow_null_sync_domain,
3465 * Select flow driver type according to flow attributes and device
3469 * Pointer to the dev structure.
3471 * Pointer to the flow attributes.
3474 * flow driver type, MLX5_FLOW_TYPE_MAX otherwise.
3476 static enum mlx5_flow_drv_type
3477 flow_get_drv_type(struct rte_eth_dev *dev, const struct rte_flow_attr *attr)
3479 struct mlx5_priv *priv = dev->data->dev_private;
3480 /* The OS can determine first a specific flow type (DV, VERBS) */
3481 enum mlx5_flow_drv_type type = mlx5_flow_os_get_type();
3483 if (type != MLX5_FLOW_TYPE_MAX)
3486 * Currently when dv_flow_en == 2, only HW steering engine is
3487 * supported. New engines can also be chosen here if ready.
3489 if (priv->sh->config.dv_flow_en == 2)
3490 return MLX5_FLOW_TYPE_HW;
3491 /* If no OS specific type - continue with DV/VERBS selection */
3492 if (attr->transfer && priv->sh->config.dv_esw_en)
3493 type = MLX5_FLOW_TYPE_DV;
3494 if (!attr->transfer)
3495 type = priv->sh->config.dv_flow_en ? MLX5_FLOW_TYPE_DV :
3496 MLX5_FLOW_TYPE_VERBS;
3500 #define flow_get_drv_ops(type) flow_drv_ops[type]
3503 * Flow driver validation API. This abstracts calling driver specific functions.
3504 * The type of flow driver is determined according to flow attributes.
3507 * Pointer to the dev structure.
3509 * Pointer to the flow attributes.
3511 * Pointer to the list of items.
3512 * @param[in] actions
3513 * Pointer to the list of actions.
3514 * @param[in] external
3515 * This flow rule is created by request external to PMD.
3516 * @param[in] hairpin
3517 * Number of hairpin TX actions, 0 means classic flow.
3519 * Pointer to the error structure.
3522 * 0 on success, a negative errno value otherwise and rte_errno is set.
3525 flow_drv_validate(struct rte_eth_dev *dev,
3526 const struct rte_flow_attr *attr,
3527 const struct rte_flow_item items[],
3528 const struct rte_flow_action actions[],
3529 bool external, int hairpin, struct rte_flow_error *error)
3531 const struct mlx5_flow_driver_ops *fops;
3532 enum mlx5_flow_drv_type type = flow_get_drv_type(dev, attr);
3534 fops = flow_get_drv_ops(type);
3535 return fops->validate(dev, attr, items, actions, external,
3540 * Flow driver preparation API. This abstracts calling driver specific
3541 * functions. Parent flow (rte_flow) should have driver type (drv_type). It
3542 * calculates the size of memory required for device flow, allocates the memory,
3543 * initializes the device flow and returns the pointer.
3546 * This function initializes device flow structure such as dv or verbs in
3547 * struct mlx5_flow. However, it is caller's responsibility to initialize the
3548 * rest. For example, adding returning device flow to flow->dev_flow list and
3549 * setting backward reference to the flow should be done out of this function.
3550 * layers field is not filled either.
3553 * Pointer to the dev structure.
3555 * Pointer to the flow attributes.
3557 * Pointer to the list of items.
3558 * @param[in] actions
3559 * Pointer to the list of actions.
3560 * @param[in] flow_idx
3561 * This memory pool index to the flow.
3563 * Pointer to the error structure.
3566 * Pointer to device flow on success, otherwise NULL and rte_errno is set.
3568 static inline struct mlx5_flow *
3569 flow_drv_prepare(struct rte_eth_dev *dev,
3570 const struct rte_flow *flow,
3571 const struct rte_flow_attr *attr,
3572 const struct rte_flow_item items[],
3573 const struct rte_flow_action actions[],
3575 struct rte_flow_error *error)
3577 const struct mlx5_flow_driver_ops *fops;
3578 enum mlx5_flow_drv_type type = flow->drv_type;
3579 struct mlx5_flow *mlx5_flow = NULL;
3581 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3582 fops = flow_get_drv_ops(type);
3583 mlx5_flow = fops->prepare(dev, attr, items, actions, error);
3585 mlx5_flow->flow_idx = flow_idx;
3590 * Flow driver translation API. This abstracts calling driver specific
3591 * functions. Parent flow (rte_flow) should have driver type (drv_type). It
3592 * translates a generic flow into a driver flow. flow_drv_prepare() must
3596 * dev_flow->layers could be filled as a result of parsing during translation
3597 * if needed by flow_drv_apply(). dev_flow->flow->actions can also be filled
3598 * if necessary. As a flow can have multiple dev_flows by RSS flow expansion,
3599 * flow->actions could be overwritten even though all the expanded dev_flows
3600 * have the same actions.
3603 * Pointer to the rte dev structure.
3604 * @param[in, out] dev_flow
3605 * Pointer to the mlx5 flow.
3607 * Pointer to the flow attributes.
3609 * Pointer to the list of items.
3610 * @param[in] actions
3611 * Pointer to the list of actions.
3613 * Pointer to the error structure.
3616 * 0 on success, a negative errno value otherwise and rte_errno is set.
3619 flow_drv_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
3620 const struct rte_flow_attr *attr,
3621 const struct rte_flow_item items[],
3622 const struct rte_flow_action actions[],
3623 struct rte_flow_error *error)
3625 const struct mlx5_flow_driver_ops *fops;
3626 enum mlx5_flow_drv_type type = dev_flow->flow->drv_type;
3628 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3629 fops = flow_get_drv_ops(type);
3630 return fops->translate(dev, dev_flow, attr, items, actions, error);
3634 * Flow driver apply API. This abstracts calling driver specific functions.
3635 * Parent flow (rte_flow) should have driver type (drv_type). It applies
3636 * translated driver flows on to device. flow_drv_translate() must precede.
3639 * Pointer to Ethernet device structure.
3640 * @param[in, out] flow
3641 * Pointer to flow structure.
3643 * Pointer to error structure.
3646 * 0 on success, a negative errno value otherwise and rte_errno is set.
3649 flow_drv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
3650 struct rte_flow_error *error)
3652 const struct mlx5_flow_driver_ops *fops;
3653 enum mlx5_flow_drv_type type = flow->drv_type;
3655 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3656 fops = flow_get_drv_ops(type);
3657 return fops->apply(dev, flow, error);
3661 * Flow driver destroy API. This abstracts calling driver specific functions.
3662 * Parent flow (rte_flow) should have driver type (drv_type). It removes a flow
3663 * on device and releases resources of the flow.
3666 * Pointer to Ethernet device.
3667 * @param[in, out] flow
3668 * Pointer to flow structure.
3671 flow_drv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
3673 const struct mlx5_flow_driver_ops *fops;
3674 enum mlx5_flow_drv_type type = flow->drv_type;
3676 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3677 fops = flow_get_drv_ops(type);
3678 fops->destroy(dev, flow);
3682 * Flow driver find RSS policy tbl API. This abstracts calling driver
3683 * specific functions. Parent flow (rte_flow) should have driver
3684 * type (drv_type). It will find the RSS policy table that has the rss_desc.
3687 * Pointer to Ethernet device.
3688 * @param[in, out] flow
3689 * Pointer to flow structure.
3691 * Pointer to meter policy table.
3692 * @param[in] rss_desc
3693 * Pointer to rss_desc
3695 static struct mlx5_flow_meter_sub_policy *
3696 flow_drv_meter_sub_policy_rss_prepare(struct rte_eth_dev *dev,
3697 struct rte_flow *flow,
3698 struct mlx5_flow_meter_policy *policy,
3699 struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS])
3701 const struct mlx5_flow_driver_ops *fops;
3702 enum mlx5_flow_drv_type type = flow->drv_type;
3704 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3705 fops = flow_get_drv_ops(type);
3706 return fops->meter_sub_policy_rss_prepare(dev, policy, rss_desc);
3710 * Flow driver color tag rule API. This abstracts calling driver
3711 * specific functions. Parent flow (rte_flow) should have driver
3712 * type (drv_type). It will create the color tag rules in hierarchy meter.
3715 * Pointer to Ethernet device.
3716 * @param[in, out] flow
3717 * Pointer to flow structure.
3719 * Pointer to flow meter structure.
3720 * @param[in] src_port
3721 * The src port this extra rule should use.
3723 * The src port id match item.
3725 * Pointer to error structure.
3728 flow_drv_mtr_hierarchy_rule_create(struct rte_eth_dev *dev,
3729 struct rte_flow *flow,
3730 struct mlx5_flow_meter_info *fm,
3732 const struct rte_flow_item *item,
3733 struct rte_flow_error *error)
3735 const struct mlx5_flow_driver_ops *fops;
3736 enum mlx5_flow_drv_type type = flow->drv_type;
3738 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3739 fops = flow_get_drv_ops(type);
3740 return fops->meter_hierarchy_rule_create(dev, fm,
3741 src_port, item, error);
3745 * Get RSS action from the action list.
3748 * Pointer to Ethernet device.
3749 * @param[in] actions
3750 * Pointer to the list of actions.
3752 * Parent flow structure pointer.
3755 * Pointer to the RSS action if exist, else return NULL.
3757 static const struct rte_flow_action_rss*
3758 flow_get_rss_action(struct rte_eth_dev *dev,
3759 const struct rte_flow_action actions[])
3761 struct mlx5_priv *priv = dev->data->dev_private;
3762 const struct rte_flow_action_rss *rss = NULL;
3763 struct mlx5_meter_policy_action_container *acg;
3764 struct mlx5_meter_policy_action_container *acy;
3766 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3767 switch (actions->type) {
3768 case RTE_FLOW_ACTION_TYPE_RSS:
3769 rss = actions->conf;
3771 case RTE_FLOW_ACTION_TYPE_SAMPLE:
3773 const struct rte_flow_action_sample *sample =
3775 const struct rte_flow_action *act = sample->actions;
3776 for (; act->type != RTE_FLOW_ACTION_TYPE_END; act++)
3777 if (act->type == RTE_FLOW_ACTION_TYPE_RSS)
3781 case RTE_FLOW_ACTION_TYPE_METER:
3784 struct mlx5_flow_meter_info *fm;
3785 struct mlx5_flow_meter_policy *policy;
3786 const struct rte_flow_action_meter *mtr = actions->conf;
3788 fm = mlx5_flow_meter_find(priv, mtr->mtr_id, &mtr_idx);
3789 if (fm && !fm->def_policy) {
3790 policy = mlx5_flow_meter_policy_find(dev,
3791 fm->policy_id, NULL);
3792 MLX5_ASSERT(policy);
3793 if (policy->is_hierarchy) {
3795 mlx5_flow_meter_hierarchy_get_final_policy(dev,
3800 if (policy->is_rss) {
3802 &policy->act_cnt[RTE_COLOR_GREEN];
3804 &policy->act_cnt[RTE_COLOR_YELLOW];
3805 if (acg->fate_action ==
3806 MLX5_FLOW_FATE_SHARED_RSS)
3807 rss = acg->rss->conf;
3808 else if (acy->fate_action ==
3809 MLX5_FLOW_FATE_SHARED_RSS)
3810 rss = acy->rss->conf;
3823 * Get ASO age action by index.
3826 * Pointer to the Ethernet device structure.
3827 * @param[in] age_idx
3828 * Index to the ASO age action.
3831 * The specified ASO age action.
3833 struct mlx5_aso_age_action*
3834 flow_aso_age_get_by_idx(struct rte_eth_dev *dev, uint32_t age_idx)
3836 uint16_t pool_idx = age_idx & UINT16_MAX;
3837 uint16_t offset = (age_idx >> 16) & UINT16_MAX;
3838 struct mlx5_priv *priv = dev->data->dev_private;
3839 struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
3840 struct mlx5_aso_age_pool *pool;
3842 rte_rwlock_read_lock(&mng->resize_rwl);
3843 pool = mng->pools[pool_idx];
3844 rte_rwlock_read_unlock(&mng->resize_rwl);
3845 return &pool->actions[offset - 1];
3848 /* maps indirect action to translated direct in some actions array */
3849 struct mlx5_translated_action_handle {
3850 struct rte_flow_action_handle *action; /**< Indirect action handle. */
3851 int index; /**< Index in related array of rte_flow_action. */
3855 * Translates actions of type RTE_FLOW_ACTION_TYPE_INDIRECT to related
3856 * direct action if translation possible.
3857 * This functionality used to run same execution path for both direct and
3858 * indirect actions on flow create. All necessary preparations for indirect
3859 * action handling should be performed on *handle* actions list returned
3863 * Pointer to Ethernet device.
3864 * @param[in] actions
3865 * List of actions to translate.
3866 * @param[out] handle
3867 * List to store translated indirect action object handles.
3868 * @param[in, out] indir_n
3869 * Size of *handle* array. On return should be updated with number of
3870 * indirect actions retrieved from the *actions* list.
3871 * @param[out] translated_actions
3872 * List of actions where all indirect actions were translated to direct
3873 * if possible. NULL if no translation took place.
3875 * Pointer to the error structure.
3878 * 0 on success, a negative errno value otherwise and rte_errno is set.
3881 flow_action_handles_translate(struct rte_eth_dev *dev,
3882 const struct rte_flow_action actions[],
3883 struct mlx5_translated_action_handle *handle,
3885 struct rte_flow_action **translated_actions,
3886 struct rte_flow_error *error)
3888 struct mlx5_priv *priv = dev->data->dev_private;
3889 struct rte_flow_action *translated = NULL;
3890 size_t actions_size;
3893 struct mlx5_translated_action_handle *handle_end = NULL;
3895 for (n = 0; actions[n].type != RTE_FLOW_ACTION_TYPE_END; n++) {
3896 if (actions[n].type != RTE_FLOW_ACTION_TYPE_INDIRECT)
3898 if (copied_n == *indir_n) {
3899 return rte_flow_error_set
3900 (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION_NUM,
3901 NULL, "too many shared actions");
3903 rte_memcpy(&handle[copied_n].action, &actions[n].conf,
3904 sizeof(actions[n].conf));
3905 handle[copied_n].index = n;
3909 *indir_n = copied_n;
3912 actions_size = sizeof(struct rte_flow_action) * n;
3913 translated = mlx5_malloc(MLX5_MEM_ZERO, actions_size, 0, SOCKET_ID_ANY);
3918 memcpy(translated, actions, actions_size);
3919 for (handle_end = handle + copied_n; handle < handle_end; handle++) {
3920 struct mlx5_shared_action_rss *shared_rss;
3921 uint32_t act_idx = (uint32_t)(uintptr_t)handle->action;
3922 uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
3923 uint32_t idx = act_idx &
3924 ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
3927 case MLX5_INDIRECT_ACTION_TYPE_RSS:
3928 shared_rss = mlx5_ipool_get
3929 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
3930 translated[handle->index].type =
3931 RTE_FLOW_ACTION_TYPE_RSS;
3932 translated[handle->index].conf =
3933 &shared_rss->origin;
3935 case MLX5_INDIRECT_ACTION_TYPE_COUNT:
3936 translated[handle->index].type =
3937 (enum rte_flow_action_type)
3938 MLX5_RTE_FLOW_ACTION_TYPE_COUNT;
3939 translated[handle->index].conf = (void *)(uintptr_t)idx;
3941 case MLX5_INDIRECT_ACTION_TYPE_AGE:
3942 if (priv->sh->flow_hit_aso_en) {
3943 translated[handle->index].type =
3944 (enum rte_flow_action_type)
3945 MLX5_RTE_FLOW_ACTION_TYPE_AGE;
3946 translated[handle->index].conf =
3947 (void *)(uintptr_t)idx;
3951 case MLX5_INDIRECT_ACTION_TYPE_CT:
3952 if (priv->sh->ct_aso_en) {
3953 translated[handle->index].type =
3954 RTE_FLOW_ACTION_TYPE_CONNTRACK;
3955 translated[handle->index].conf =
3956 (void *)(uintptr_t)idx;
3961 mlx5_free(translated);
3962 return rte_flow_error_set
3963 (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
3964 NULL, "invalid indirect action type");
3967 *translated_actions = translated;
3972 * Get Shared RSS action from the action list.
3975 * Pointer to Ethernet device.
3977 * Pointer to the list of actions.
3978 * @param[in] shared_n
3979 * Actions list length.
3982 * The MLX5 RSS action ID if exists, otherwise return 0.
3985 flow_get_shared_rss_action(struct rte_eth_dev *dev,
3986 struct mlx5_translated_action_handle *handle,
3989 struct mlx5_translated_action_handle *handle_end;
3990 struct mlx5_priv *priv = dev->data->dev_private;
3991 struct mlx5_shared_action_rss *shared_rss;
3994 for (handle_end = handle + shared_n; handle < handle_end; handle++) {
3995 uint32_t act_idx = (uint32_t)(uintptr_t)handle->action;
3996 uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
3997 uint32_t idx = act_idx &
3998 ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
4000 case MLX5_INDIRECT_ACTION_TYPE_RSS:
4001 shared_rss = mlx5_ipool_get
4002 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
4004 __atomic_add_fetch(&shared_rss->refcnt, 1,
4015 find_graph_root(uint32_t rss_level)
4017 return rss_level < 2 ? MLX5_EXPANSION_ROOT :
4018 MLX5_EXPANSION_ROOT_OUTER;
4022 * Get layer flags from the prefix flow.
4024 * Some flows may be split to several subflows, the prefix subflow gets the
4025 * match items and the suffix sub flow gets the actions.
4026 * Some actions need the user defined match item flags to get the detail for
4028 * This function helps the suffix flow to get the item layer flags from prefix
4031 * @param[in] dev_flow
4032 * Pointer the created prefix subflow.
4035 * The layers get from prefix subflow.
4037 static inline uint64_t
4038 flow_get_prefix_layer_flags(struct mlx5_flow *dev_flow)
4040 uint64_t layers = 0;
4043 * Layers bits could be localization, but usually the compiler will
4044 * help to do the optimization work for source code.
4045 * If no decap actions, use the layers directly.
4047 if (!(dev_flow->act_flags & MLX5_FLOW_ACTION_DECAP))
4048 return dev_flow->handle->layers;
4049 /* Convert L3 layers with decap action. */
4050 if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L3_IPV4)
4051 layers |= MLX5_FLOW_LAYER_OUTER_L3_IPV4;
4052 else if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L3_IPV6)
4053 layers |= MLX5_FLOW_LAYER_OUTER_L3_IPV6;
4054 /* Convert L4 layers with decap action. */
4055 if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L4_TCP)
4056 layers |= MLX5_FLOW_LAYER_OUTER_L4_TCP;
4057 else if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L4_UDP)
4058 layers |= MLX5_FLOW_LAYER_OUTER_L4_UDP;
4063 * Get metadata split action information.
4065 * @param[in] actions
4066 * Pointer to the list of actions.
4068 * Pointer to the return pointer.
4069 * @param[out] qrss_type
4070 * Pointer to the action type to return. RTE_FLOW_ACTION_TYPE_END is returned
4071 * if no QUEUE/RSS is found.
4072 * @param[out] encap_idx
4073 * Pointer to the index of the encap action if exists, otherwise the last
4077 * Total number of actions.
4080 flow_parse_metadata_split_actions_info(const struct rte_flow_action actions[],
4081 const struct rte_flow_action **qrss,
4084 const struct rte_flow_action_raw_encap *raw_encap;
4086 int raw_decap_idx = -1;
4089 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4090 switch (actions->type) {
4091 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
4092 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
4093 *encap_idx = actions_n;
4095 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
4096 raw_decap_idx = actions_n;
4098 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
4099 raw_encap = actions->conf;
4100 if (raw_encap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
4101 *encap_idx = raw_decap_idx != -1 ?
4102 raw_decap_idx : actions_n;
4104 case RTE_FLOW_ACTION_TYPE_QUEUE:
4105 case RTE_FLOW_ACTION_TYPE_RSS:
4113 if (*encap_idx == -1)
4114 *encap_idx = actions_n;
4115 /* Count RTE_FLOW_ACTION_TYPE_END. */
4116 return actions_n + 1;
4120 * Check if the action will change packet.
4123 * Pointer to Ethernet device.
4128 * true if action will change packet, false otherwise.
4130 static bool flow_check_modify_action_type(struct rte_eth_dev *dev,
4131 enum rte_flow_action_type type)
4133 struct mlx5_priv *priv = dev->data->dev_private;
4136 case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
4137 case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
4138 case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
4139 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
4140 case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
4141 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
4142 case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
4143 case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
4144 case RTE_FLOW_ACTION_TYPE_DEC_TTL:
4145 case RTE_FLOW_ACTION_TYPE_SET_TTL:
4146 case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
4147 case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
4148 case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
4149 case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
4150 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
4151 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
4152 case RTE_FLOW_ACTION_TYPE_SET_META:
4153 case RTE_FLOW_ACTION_TYPE_SET_TAG:
4154 case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
4155 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
4156 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
4157 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
4158 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
4159 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
4160 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
4161 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
4162 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
4163 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
4164 case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
4166 case RTE_FLOW_ACTION_TYPE_FLAG:
4167 case RTE_FLOW_ACTION_TYPE_MARK:
4168 if (priv->sh->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY)
4178 * Check meter action from the action list.
4181 * Pointer to Ethernet device.
4182 * @param[in] actions
4183 * Pointer to the list of actions.
4184 * @param[out] has_mtr
4185 * Pointer to the meter exist flag.
4186 * @param[out] has_modify
4187 * Pointer to the flag showing there's packet change action.
4188 * @param[out] meter_id
4189 * Pointer to the meter id.
4192 * Total number of actions.
4195 flow_check_meter_action(struct rte_eth_dev *dev,
4196 const struct rte_flow_action actions[],
4197 bool *has_mtr, bool *has_modify, uint32_t *meter_id)
4199 const struct rte_flow_action_meter *mtr = NULL;
4202 MLX5_ASSERT(has_mtr);
4204 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4205 switch (actions->type) {
4206 case RTE_FLOW_ACTION_TYPE_METER:
4207 mtr = actions->conf;
4208 *meter_id = mtr->mtr_id;
4215 *has_modify |= flow_check_modify_action_type(dev,
4219 /* Count RTE_FLOW_ACTION_TYPE_END. */
4220 return actions_n + 1;
4224 * Check if the flow should be split due to hairpin.
4225 * The reason for the split is that in current HW we can't
4226 * support encap and push-vlan on Rx, so if a flow contains
4227 * these actions we move it to Tx.
4230 * Pointer to Ethernet device.
4232 * Flow rule attributes.
4233 * @param[in] actions
4234 * Associated actions (list terminated by the END action).
4237 * > 0 the number of actions and the flow should be split,
4238 * 0 when no split required.
4241 flow_check_hairpin_split(struct rte_eth_dev *dev,
4242 const struct rte_flow_attr *attr,
4243 const struct rte_flow_action actions[])
4245 int queue_action = 0;
4248 const struct rte_flow_action_queue *queue;
4249 const struct rte_flow_action_rss *rss;
4250 const struct rte_flow_action_raw_encap *raw_encap;
4251 const struct rte_eth_hairpin_conf *conf;
4255 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4256 switch (actions->type) {
4257 case RTE_FLOW_ACTION_TYPE_QUEUE:
4258 queue = actions->conf;
4261 conf = mlx5_rxq_get_hairpin_conf(dev, queue->index);
4262 if (conf == NULL || conf->tx_explicit != 0)
4267 case RTE_FLOW_ACTION_TYPE_RSS:
4268 rss = actions->conf;
4269 if (rss == NULL || rss->queue_num == 0)
4271 conf = mlx5_rxq_get_hairpin_conf(dev, rss->queue[0]);
4272 if (conf == NULL || conf->tx_explicit != 0)
4277 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
4278 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
4279 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
4280 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
4281 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
4285 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
4286 raw_encap = actions->conf;
4287 if (raw_encap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
4296 if (split && queue_action)
4301 /* Declare flow create/destroy prototype in advance. */
4303 flow_list_create(struct rte_eth_dev *dev, enum mlx5_flow_type type,
4304 const struct rte_flow_attr *attr,
4305 const struct rte_flow_item items[],
4306 const struct rte_flow_action actions[],
4307 bool external, struct rte_flow_error *error);
4310 flow_list_destroy(struct rte_eth_dev *dev, enum mlx5_flow_type type,
4314 flow_dv_mreg_match_cb(void *tool_ctx __rte_unused,
4315 struct mlx5_list_entry *entry, void *cb_ctx)
4317 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4318 struct mlx5_flow_mreg_copy_resource *mcp_res =
4319 container_of(entry, typeof(*mcp_res), hlist_ent);
4321 return mcp_res->mark_id != *(uint32_t *)(ctx->data);
4324 struct mlx5_list_entry *
4325 flow_dv_mreg_create_cb(void *tool_ctx, void *cb_ctx)
4327 struct rte_eth_dev *dev = tool_ctx;
4328 struct mlx5_priv *priv = dev->data->dev_private;
4329 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4330 struct mlx5_flow_mreg_copy_resource *mcp_res;
4331 struct rte_flow_error *error = ctx->error;
4334 uint32_t mark_id = *(uint32_t *)(ctx->data);
4335 struct rte_flow_attr attr = {
4336 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
4339 struct mlx5_rte_flow_item_tag tag_spec = {
4342 struct rte_flow_item items[] = {
4343 [1] = { .type = RTE_FLOW_ITEM_TYPE_END, },
4345 struct rte_flow_action_mark ftag = {
4348 struct mlx5_flow_action_copy_mreg cp_mreg = {
4352 struct rte_flow_action_jump jump = {
4353 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
4355 struct rte_flow_action actions[] = {
4356 [3] = { .type = RTE_FLOW_ACTION_TYPE_END, },
4359 /* Fill the register fields in the flow. */
4360 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
4364 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_RX, 0, error);
4368 /* Provide the full width of FLAG specific value. */
4369 if (mark_id == (priv->sh->dv_regc0_mask & MLX5_FLOW_MARK_DEFAULT))
4370 tag_spec.data = MLX5_FLOW_MARK_DEFAULT;
4371 /* Build a new flow. */
4372 if (mark_id != MLX5_DEFAULT_COPY_ID) {
4373 items[0] = (struct rte_flow_item){
4374 .type = (enum rte_flow_item_type)
4375 MLX5_RTE_FLOW_ITEM_TYPE_TAG,
4378 items[1] = (struct rte_flow_item){
4379 .type = RTE_FLOW_ITEM_TYPE_END,
4381 actions[0] = (struct rte_flow_action){
4382 .type = (enum rte_flow_action_type)
4383 MLX5_RTE_FLOW_ACTION_TYPE_MARK,
4386 actions[1] = (struct rte_flow_action){
4387 .type = (enum rte_flow_action_type)
4388 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
4391 actions[2] = (struct rte_flow_action){
4392 .type = RTE_FLOW_ACTION_TYPE_JUMP,
4395 actions[3] = (struct rte_flow_action){
4396 .type = RTE_FLOW_ACTION_TYPE_END,
4399 /* Default rule, wildcard match. */
4400 attr.priority = MLX5_FLOW_LOWEST_PRIO_INDICATOR;
4401 items[0] = (struct rte_flow_item){
4402 .type = RTE_FLOW_ITEM_TYPE_END,
4404 actions[0] = (struct rte_flow_action){
4405 .type = (enum rte_flow_action_type)
4406 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
4409 actions[1] = (struct rte_flow_action){
4410 .type = RTE_FLOW_ACTION_TYPE_JUMP,
4413 actions[2] = (struct rte_flow_action){
4414 .type = RTE_FLOW_ACTION_TYPE_END,
4417 /* Build a new entry. */
4418 mcp_res = mlx5_ipool_zmalloc(priv->sh->ipool[MLX5_IPOOL_MCP], &idx);
4424 mcp_res->mark_id = mark_id;
4426 * The copy Flows are not included in any list. There
4427 * ones are referenced from other Flows and can not
4428 * be applied, removed, deleted in arbitrary order
4429 * by list traversing.
4431 mcp_res->rix_flow = flow_list_create(dev, MLX5_FLOW_TYPE_MCP,
4432 &attr, items, actions, false, error);
4433 if (!mcp_res->rix_flow) {
4434 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], idx);
4437 return &mcp_res->hlist_ent;
4440 struct mlx5_list_entry *
4441 flow_dv_mreg_clone_cb(void *tool_ctx, struct mlx5_list_entry *oentry,
4442 void *cb_ctx __rte_unused)
4444 struct rte_eth_dev *dev = tool_ctx;
4445 struct mlx5_priv *priv = dev->data->dev_private;
4446 struct mlx5_flow_mreg_copy_resource *mcp_res;
4449 mcp_res = mlx5_ipool_malloc(priv->sh->ipool[MLX5_IPOOL_MCP], &idx);
4454 memcpy(mcp_res, oentry, sizeof(*mcp_res));
4456 return &mcp_res->hlist_ent;
4460 flow_dv_mreg_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
4462 struct mlx5_flow_mreg_copy_resource *mcp_res =
4463 container_of(entry, typeof(*mcp_res), hlist_ent);
4464 struct rte_eth_dev *dev = tool_ctx;
4465 struct mlx5_priv *priv = dev->data->dev_private;
4467 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], mcp_res->idx);
4471 * Add a flow of copying flow metadata registers in RX_CP_TBL.
4473 * As mark_id is unique, if there's already a registered flow for the mark_id,
4474 * return by increasing the reference counter of the resource. Otherwise, create
4475 * the resource (mcp_res) and flow.
4478 * - If ingress port is ANY and reg_c[1] is mark_id,
4479 * flow_tag := mark_id, reg_b := reg_c[0] and jump to RX_ACT_TBL.
4481 * For default flow (zero mark_id), flow is like,
4482 * - If ingress port is ANY,
4483 * reg_b := reg_c[0] and jump to RX_ACT_TBL.
4486 * Pointer to Ethernet device.
4488 * ID of MARK action, zero means default flow for META.
4490 * Perform verbose error reporting if not NULL.
4493 * Associated resource on success, NULL otherwise and rte_errno is set.
4495 static struct mlx5_flow_mreg_copy_resource *
4496 flow_mreg_add_copy_action(struct rte_eth_dev *dev, uint32_t mark_id,
4497 struct rte_flow_error *error)
4499 struct mlx5_priv *priv = dev->data->dev_private;
4500 struct mlx5_list_entry *entry;
4501 struct mlx5_flow_cb_ctx ctx = {
4507 /* Check if already registered. */
4508 MLX5_ASSERT(priv->mreg_cp_tbl);
4509 entry = mlx5_hlist_register(priv->mreg_cp_tbl, mark_id, &ctx);
4512 return container_of(entry, struct mlx5_flow_mreg_copy_resource,
4517 flow_dv_mreg_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
4519 struct mlx5_flow_mreg_copy_resource *mcp_res =
4520 container_of(entry, typeof(*mcp_res), hlist_ent);
4521 struct rte_eth_dev *dev = tool_ctx;
4522 struct mlx5_priv *priv = dev->data->dev_private;
4524 MLX5_ASSERT(mcp_res->rix_flow);
4525 flow_list_destroy(dev, MLX5_FLOW_TYPE_MCP, mcp_res->rix_flow);
4526 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], mcp_res->idx);
4530 * Release flow in RX_CP_TBL.
4533 * Pointer to Ethernet device.
4535 * Parent flow for wich copying is provided.
4538 flow_mreg_del_copy_action(struct rte_eth_dev *dev,
4539 struct rte_flow *flow)
4541 struct mlx5_flow_mreg_copy_resource *mcp_res;
4542 struct mlx5_priv *priv = dev->data->dev_private;
4544 if (!flow->rix_mreg_copy)
4546 mcp_res = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MCP],
4547 flow->rix_mreg_copy);
4548 if (!mcp_res || !priv->mreg_cp_tbl)
4550 MLX5_ASSERT(mcp_res->rix_flow);
4551 mlx5_hlist_unregister(priv->mreg_cp_tbl, &mcp_res->hlist_ent);
4552 flow->rix_mreg_copy = 0;
4556 * Remove the default copy action from RX_CP_TBL.
4558 * This functions is called in the mlx5_dev_start(). No thread safe
4562 * Pointer to Ethernet device.
4565 flow_mreg_del_default_copy_action(struct rte_eth_dev *dev)
4567 struct mlx5_list_entry *entry;
4568 struct mlx5_priv *priv = dev->data->dev_private;
4569 struct mlx5_flow_cb_ctx ctx;
4572 /* Check if default flow is registered. */
4573 if (!priv->mreg_cp_tbl)
4575 mark_id = MLX5_DEFAULT_COPY_ID;
4576 ctx.data = &mark_id;
4577 entry = mlx5_hlist_lookup(priv->mreg_cp_tbl, mark_id, &ctx);
4580 mlx5_hlist_unregister(priv->mreg_cp_tbl, entry);
4584 * Add the default copy action in in RX_CP_TBL.
4586 * This functions is called in the mlx5_dev_start(). No thread safe
4590 * Pointer to Ethernet device.
4592 * Perform verbose error reporting if not NULL.
4595 * 0 for success, negative value otherwise and rte_errno is set.
4598 flow_mreg_add_default_copy_action(struct rte_eth_dev *dev,
4599 struct rte_flow_error *error)
4601 struct mlx5_priv *priv = dev->data->dev_private;
4602 struct mlx5_flow_mreg_copy_resource *mcp_res;
4603 struct mlx5_flow_cb_ctx ctx;
4606 /* Check whether extensive metadata feature is engaged. */
4607 if (!priv->sh->config.dv_flow_en ||
4608 priv->sh->config.dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
4609 !mlx5_flow_ext_mreg_supported(dev) ||
4610 !priv->sh->dv_regc0_mask)
4613 * Add default mreg copy flow may be called multiple time, but
4614 * only be called once in stop. Avoid register it twice.
4616 mark_id = MLX5_DEFAULT_COPY_ID;
4617 ctx.data = &mark_id;
4618 if (mlx5_hlist_lookup(priv->mreg_cp_tbl, mark_id, &ctx))
4620 mcp_res = flow_mreg_add_copy_action(dev, mark_id, error);
4627 * Add a flow of copying flow metadata registers in RX_CP_TBL.
4629 * All the flow having Q/RSS action should be split by
4630 * flow_mreg_split_qrss_prep() to pass by RX_CP_TBL. A flow in the RX_CP_TBL
4631 * performs the following,
4632 * - CQE->flow_tag := reg_c[1] (MARK)
4633 * - CQE->flow_table_metadata (reg_b) := reg_c[0] (META)
4634 * As CQE's flow_tag is not a register, it can't be simply copied from reg_c[1]
4635 * but there should be a flow per each MARK ID set by MARK action.
4637 * For the aforementioned reason, if there's a MARK action in flow's action
4638 * list, a corresponding flow should be added to the RX_CP_TBL in order to copy
4639 * the MARK ID to CQE's flow_tag like,
4640 * - If reg_c[1] is mark_id,
4641 * flow_tag := mark_id, reg_b := reg_c[0] and jump to RX_ACT_TBL.
4643 * For SET_META action which stores value in reg_c[0], as the destination is
4644 * also a flow metadata register (reg_b), adding a default flow is enough. Zero
4645 * MARK ID means the default flow. The default flow looks like,
4646 * - For all flow, reg_b := reg_c[0] and jump to RX_ACT_TBL.
4649 * Pointer to Ethernet device.
4651 * Pointer to flow structure.
4652 * @param[in] actions
4653 * Pointer to the list of actions.
4655 * Perform verbose error reporting if not NULL.
4658 * 0 on success, negative value otherwise and rte_errno is set.
4661 flow_mreg_update_copy_table(struct rte_eth_dev *dev,
4662 struct rte_flow *flow,
4663 const struct rte_flow_action *actions,
4664 struct rte_flow_error *error)
4666 struct mlx5_priv *priv = dev->data->dev_private;
4667 struct mlx5_sh_config *config = &priv->sh->config;
4668 struct mlx5_flow_mreg_copy_resource *mcp_res;
4669 const struct rte_flow_action_mark *mark;
4671 /* Check whether extensive metadata feature is engaged. */
4672 if (!config->dv_flow_en ||
4673 config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
4674 !mlx5_flow_ext_mreg_supported(dev) ||
4675 !priv->sh->dv_regc0_mask)
4677 /* Find MARK action. */
4678 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4679 switch (actions->type) {
4680 case RTE_FLOW_ACTION_TYPE_FLAG:
4681 mcp_res = flow_mreg_add_copy_action
4682 (dev, MLX5_FLOW_MARK_DEFAULT, error);
4685 flow->rix_mreg_copy = mcp_res->idx;
4687 case RTE_FLOW_ACTION_TYPE_MARK:
4688 mark = (const struct rte_flow_action_mark *)
4691 flow_mreg_add_copy_action(dev, mark->id, error);
4694 flow->rix_mreg_copy = mcp_res->idx;
4703 #define MLX5_MAX_SPLIT_ACTIONS 24
4704 #define MLX5_MAX_SPLIT_ITEMS 24
4707 * Split the hairpin flow.
4708 * Since HW can't support encap and push-vlan on Rx, we move these
4710 * If the count action is after the encap then we also
4711 * move the count action. in this case the count will also measure
4715 * Pointer to Ethernet device.
4716 * @param[in] actions
4717 * Associated actions (list terminated by the END action).
4718 * @param[out] actions_rx
4720 * @param[out] actions_tx
4722 * @param[out] pattern_tx
4723 * The pattern items for the Tx flow.
4724 * @param[out] flow_id
4725 * The flow ID connected to this flow.
4731 flow_hairpin_split(struct rte_eth_dev *dev,
4732 const struct rte_flow_action actions[],
4733 struct rte_flow_action actions_rx[],
4734 struct rte_flow_action actions_tx[],
4735 struct rte_flow_item pattern_tx[],
4738 const struct rte_flow_action_raw_encap *raw_encap;
4739 const struct rte_flow_action_raw_decap *raw_decap;
4740 struct mlx5_rte_flow_action_set_tag *set_tag;
4741 struct rte_flow_action *tag_action;
4742 struct mlx5_rte_flow_item_tag *tag_item;
4743 struct rte_flow_item *item;
4747 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4748 switch (actions->type) {
4749 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
4750 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
4751 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
4752 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
4753 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
4754 rte_memcpy(actions_tx, actions,
4755 sizeof(struct rte_flow_action));
4758 case RTE_FLOW_ACTION_TYPE_COUNT:
4760 rte_memcpy(actions_tx, actions,
4761 sizeof(struct rte_flow_action));
4764 rte_memcpy(actions_rx, actions,
4765 sizeof(struct rte_flow_action));
4769 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
4770 raw_encap = actions->conf;
4771 if (raw_encap->size > MLX5_ENCAPSULATION_DECISION_SIZE) {
4772 memcpy(actions_tx, actions,
4773 sizeof(struct rte_flow_action));
4777 rte_memcpy(actions_rx, actions,
4778 sizeof(struct rte_flow_action));
4782 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
4783 raw_decap = actions->conf;
4784 if (raw_decap->size < MLX5_ENCAPSULATION_DECISION_SIZE) {
4785 memcpy(actions_tx, actions,
4786 sizeof(struct rte_flow_action));
4789 rte_memcpy(actions_rx, actions,
4790 sizeof(struct rte_flow_action));
4795 rte_memcpy(actions_rx, actions,
4796 sizeof(struct rte_flow_action));
4801 /* Add set meta action and end action for the Rx flow. */
4802 tag_action = actions_rx;
4803 tag_action->type = (enum rte_flow_action_type)
4804 MLX5_RTE_FLOW_ACTION_TYPE_TAG;
4806 rte_memcpy(actions_rx, actions, sizeof(struct rte_flow_action));
4808 set_tag = (void *)actions_rx;
4809 *set_tag = (struct mlx5_rte_flow_action_set_tag) {
4810 .id = mlx5_flow_get_reg_id(dev, MLX5_HAIRPIN_RX, 0, NULL),
4813 MLX5_ASSERT(set_tag->id > REG_NON);
4814 tag_action->conf = set_tag;
4815 /* Create Tx item list. */
4816 rte_memcpy(actions_tx, actions, sizeof(struct rte_flow_action));
4817 addr = (void *)&pattern_tx[2];
4819 item->type = (enum rte_flow_item_type)
4820 MLX5_RTE_FLOW_ITEM_TYPE_TAG;
4821 tag_item = (void *)addr;
4822 tag_item->data = flow_id;
4823 tag_item->id = mlx5_flow_get_reg_id(dev, MLX5_HAIRPIN_TX, 0, NULL);
4824 MLX5_ASSERT(set_tag->id > REG_NON);
4825 item->spec = tag_item;
4826 addr += sizeof(struct mlx5_rte_flow_item_tag);
4827 tag_item = (void *)addr;
4828 tag_item->data = UINT32_MAX;
4829 tag_item->id = UINT16_MAX;
4830 item->mask = tag_item;
4833 item->type = RTE_FLOW_ITEM_TYPE_END;
4838 * The last stage of splitting chain, just creates the subflow
4839 * without any modification.
4842 * Pointer to Ethernet device.
4844 * Parent flow structure pointer.
4845 * @param[in, out] sub_flow
4846 * Pointer to return the created subflow, may be NULL.
4848 * Flow rule attributes.
4850 * Pattern specification (list terminated by the END pattern item).
4851 * @param[in] actions
4852 * Associated actions (list terminated by the END action).
4853 * @param[in] flow_split_info
4854 * Pointer to flow split info structure.
4856 * Perform verbose error reporting if not NULL.
4858 * 0 on success, negative value otherwise
4861 flow_create_split_inner(struct rte_eth_dev *dev,
4862 struct rte_flow *flow,
4863 struct mlx5_flow **sub_flow,
4864 const struct rte_flow_attr *attr,
4865 const struct rte_flow_item items[],
4866 const struct rte_flow_action actions[],
4867 struct mlx5_flow_split_info *flow_split_info,
4868 struct rte_flow_error *error)
4870 struct mlx5_flow *dev_flow;
4871 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
4873 dev_flow = flow_drv_prepare(dev, flow, attr, items, actions,
4874 flow_split_info->flow_idx, error);
4877 dev_flow->flow = flow;
4878 dev_flow->external = flow_split_info->external;
4879 dev_flow->skip_scale = flow_split_info->skip_scale;
4880 /* Subflow object was created, we must include one in the list. */
4881 SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
4882 dev_flow->handle, next);
4884 * If dev_flow is as one of the suffix flow, some actions in suffix
4885 * flow may need some user defined item layer flags, and pass the
4886 * Metadata rxq mark flag to suffix flow as well.
4888 if (flow_split_info->prefix_layers)
4889 dev_flow->handle->layers = flow_split_info->prefix_layers;
4890 if (flow_split_info->prefix_mark) {
4895 *sub_flow = dev_flow;
4896 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
4897 dev_flow->dv.table_id = flow_split_info->table_id;
4899 return flow_drv_translate(dev, dev_flow, attr, items, actions, error);
4903 * Get the sub policy of a meter.
4906 * Pointer to Ethernet device.
4908 * Parent flow structure pointer.
4910 * Pointer to thread flow work space.
4912 * Flow rule attributes.
4914 * Pattern specification (list terminated by the END pattern item).
4916 * Perform verbose error reporting if not NULL.
4919 * Pointer to the meter sub policy, NULL otherwise and rte_errno is set.
4921 static struct mlx5_flow_meter_sub_policy *
4922 get_meter_sub_policy(struct rte_eth_dev *dev,
4923 struct rte_flow *flow,
4924 struct mlx5_flow_workspace *wks,
4925 const struct rte_flow_attr *attr,
4926 const struct rte_flow_item items[],
4927 struct rte_flow_error *error)
4929 struct mlx5_flow_meter_policy *policy;
4930 struct mlx5_flow_meter_policy *final_policy;
4931 struct mlx5_flow_meter_sub_policy *sub_policy = NULL;
4933 policy = wks->policy;
4934 final_policy = policy->is_hierarchy ? wks->final_policy : policy;
4935 if (final_policy->is_rss || final_policy->is_queue) {
4936 struct mlx5_flow_rss_desc rss_desc_v[MLX5_MTR_RTE_COLORS];
4937 struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS] = {0};
4941 * This is a tmp dev_flow,
4942 * no need to register any matcher for it in translate.
4944 wks->skip_matcher_reg = 1;
4945 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
4946 struct mlx5_flow dev_flow = {0};
4947 struct mlx5_flow_handle dev_handle = { {0} };
4948 uint8_t fate = final_policy->act_cnt[i].fate_action;
4950 if (fate == MLX5_FLOW_FATE_SHARED_RSS) {
4951 const struct rte_flow_action_rss *rss_act =
4952 final_policy->act_cnt[i].rss->conf;
4953 struct rte_flow_action rss_actions[2] = {
4955 .type = RTE_FLOW_ACTION_TYPE_RSS,
4959 .type = RTE_FLOW_ACTION_TYPE_END,
4964 dev_flow.handle = &dev_handle;
4965 dev_flow.ingress = attr->ingress;
4966 dev_flow.flow = flow;
4967 dev_flow.external = 0;
4968 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
4969 dev_flow.dv.transfer = attr->transfer;
4972 * Translate RSS action to get rss hash fields.
4974 if (flow_drv_translate(dev, &dev_flow, attr,
4975 items, rss_actions, error))
4977 rss_desc_v[i] = wks->rss_desc;
4978 rss_desc_v[i].key_len = MLX5_RSS_HASH_KEY_LEN;
4979 rss_desc_v[i].hash_fields =
4980 dev_flow.hash_fields;
4981 rss_desc_v[i].queue_num =
4982 rss_desc_v[i].hash_fields ?
4983 rss_desc_v[i].queue_num : 1;
4984 rss_desc_v[i].tunnel =
4985 !!(dev_flow.handle->layers &
4986 MLX5_FLOW_LAYER_TUNNEL);
4987 /* Use the RSS queues in the containers. */
4988 rss_desc_v[i].queue =
4989 (uint16_t *)(uintptr_t)rss_act->queue;
4990 rss_desc[i] = &rss_desc_v[i];
4991 } else if (fate == MLX5_FLOW_FATE_QUEUE) {
4992 /* This is queue action. */
4993 rss_desc_v[i] = wks->rss_desc;
4994 rss_desc_v[i].key_len = 0;
4995 rss_desc_v[i].hash_fields = 0;
4996 rss_desc_v[i].queue =
4997 &final_policy->act_cnt[i].queue;
4998 rss_desc_v[i].queue_num = 1;
4999 rss_desc[i] = &rss_desc_v[i];
5004 sub_policy = flow_drv_meter_sub_policy_rss_prepare(dev,
5005 flow, policy, rss_desc);
5007 enum mlx5_meter_domain mtr_domain =
5008 attr->transfer ? MLX5_MTR_DOMAIN_TRANSFER :
5009 (attr->egress ? MLX5_MTR_DOMAIN_EGRESS :
5010 MLX5_MTR_DOMAIN_INGRESS);
5011 sub_policy = policy->sub_policys[mtr_domain][0];
5014 rte_flow_error_set(error, EINVAL,
5015 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
5016 "Failed to get meter sub-policy.");
5022 * Split the meter flow.
5024 * As meter flow will split to three sub flow, other than meter
5025 * action, the other actions make sense to only meter accepts
5026 * the packet. If it need to be dropped, no other additional
5027 * actions should be take.
5029 * One kind of special action which decapsulates the L3 tunnel
5030 * header will be in the prefix sub flow, as not to take the
5031 * L3 tunnel header into account.
5034 * Pointer to Ethernet device.
5036 * Parent flow structure pointer.
5038 * Pointer to thread flow work space.
5040 * Flow rule attributes.
5042 * Pattern specification (list terminated by the END pattern item).
5043 * @param[out] sfx_items
5044 * Suffix flow match items (list terminated by the END pattern item).
5045 * @param[in] actions
5046 * Associated actions (list terminated by the END action).
5047 * @param[out] actions_sfx
5048 * Suffix flow actions.
5049 * @param[out] actions_pre
5050 * Prefix flow actions.
5051 * @param[out] mtr_flow_id
5052 * Pointer to meter flow id.
5054 * Perform verbose error reporting if not NULL.
5057 * 0 on success, a negative errno value otherwise and rte_errno is set.
5060 flow_meter_split_prep(struct rte_eth_dev *dev,
5061 struct rte_flow *flow,
5062 struct mlx5_flow_workspace *wks,
5063 const struct rte_flow_attr *attr,
5064 const struct rte_flow_item items[],
5065 struct rte_flow_item sfx_items[],
5066 const struct rte_flow_action actions[],
5067 struct rte_flow_action actions_sfx[],
5068 struct rte_flow_action actions_pre[],
5069 uint32_t *mtr_flow_id,
5070 struct rte_flow_error *error)
5072 struct mlx5_priv *priv = dev->data->dev_private;
5073 struct mlx5_flow_meter_info *fm = wks->fm;
5074 struct rte_flow_action *tag_action = NULL;
5075 struct rte_flow_item *tag_item;
5076 struct mlx5_rte_flow_action_set_tag *set_tag;
5077 const struct rte_flow_action_raw_encap *raw_encap;
5078 const struct rte_flow_action_raw_decap *raw_decap;
5079 struct mlx5_rte_flow_item_tag *tag_item_spec;
5080 struct mlx5_rte_flow_item_tag *tag_item_mask;
5081 uint32_t tag_id = 0;
5082 struct rte_flow_item *vlan_item_dst = NULL;
5083 const struct rte_flow_item *vlan_item_src = NULL;
5084 const struct rte_flow_item *orig_items = items;
5085 struct rte_flow_action *hw_mtr_action;
5086 struct rte_flow_action *action_pre_head = NULL;
5087 int32_t flow_src_port = priv->representor_id;
5089 uint8_t mtr_id_offset = priv->mtr_reg_share ? MLX5_MTR_COLOR_BITS : 0;
5090 uint8_t mtr_reg_bits = priv->mtr_reg_share ?
5091 MLX5_MTR_IDLE_BITS_IN_COLOR_REG : MLX5_REG_BITS;
5092 uint32_t flow_id = 0;
5093 uint32_t flow_id_reversed = 0;
5094 uint8_t flow_id_bits = 0;
5097 /* Prepare the suffix subflow items. */
5098 tag_item = sfx_items++;
5099 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
5100 struct mlx5_priv *port_priv;
5101 const struct rte_flow_item_port_id *pid_v;
5102 int item_type = items->type;
5104 switch (item_type) {
5105 case RTE_FLOW_ITEM_TYPE_PORT_ID:
5106 pid_v = items->spec;
5108 port_priv = mlx5_port_to_eswitch_info(pid_v->id, false);
5110 return rte_flow_error_set(error,
5112 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
5114 "Failed to get port info.");
5115 flow_src_port = port_priv->representor_id;
5116 if (!fm->def_policy && wks->policy->is_hierarchy &&
5117 flow_src_port != priv->representor_id) {
5118 if (flow_drv_mtr_hierarchy_rule_create(dev,
5125 memcpy(sfx_items, items, sizeof(*sfx_items));
5128 case RTE_FLOW_ITEM_TYPE_VLAN:
5129 /* Determine if copy vlan item below. */
5130 vlan_item_src = items;
5131 vlan_item_dst = sfx_items++;
5132 vlan_item_dst->type = RTE_FLOW_ITEM_TYPE_VOID;
5138 sfx_items->type = RTE_FLOW_ITEM_TYPE_END;
5140 mtr_first = priv->sh->meter_aso_en &&
5141 (attr->egress || (attr->transfer && flow_src_port != UINT16_MAX));
5142 /* For ASO meter, meter must be before tag in TX direction. */
5144 action_pre_head = actions_pre++;
5145 /* Leave space for tag action. */
5146 tag_action = actions_pre++;
5148 /* Prepare the actions for prefix and suffix flow. */
5149 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
5150 struct rte_flow_action *action_cur = NULL;
5152 switch (actions->type) {
5153 case RTE_FLOW_ACTION_TYPE_METER:
5155 action_cur = action_pre_head;
5157 /* Leave space for tag action. */
5158 tag_action = actions_pre++;
5159 action_cur = actions_pre++;
5162 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
5163 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
5164 action_cur = actions_pre++;
5166 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
5167 raw_encap = actions->conf;
5168 if (raw_encap->size < MLX5_ENCAPSULATION_DECISION_SIZE)
5169 action_cur = actions_pre++;
5171 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
5172 raw_decap = actions->conf;
5173 if (raw_decap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
5174 action_cur = actions_pre++;
5176 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
5177 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
5178 if (vlan_item_dst && vlan_item_src) {
5179 memcpy(vlan_item_dst, vlan_item_src,
5180 sizeof(*vlan_item_dst));
5182 * Convert to internal match item, it is used
5183 * for vlan push and set vid.
5185 vlan_item_dst->type = (enum rte_flow_item_type)
5186 MLX5_RTE_FLOW_ITEM_TYPE_VLAN;
5193 action_cur = (fm->def_policy) ?
5194 actions_sfx++ : actions_pre++;
5195 memcpy(action_cur, actions, sizeof(struct rte_flow_action));
5197 /* Add end action to the actions. */
5198 actions_sfx->type = RTE_FLOW_ACTION_TYPE_END;
5199 if (priv->sh->meter_aso_en) {
5201 * For ASO meter, need to add an extra jump action explicitly,
5202 * to jump from meter to policer table.
5204 struct mlx5_flow_meter_sub_policy *sub_policy;
5205 struct mlx5_flow_tbl_data_entry *tbl_data;
5207 if (!fm->def_policy) {
5208 sub_policy = get_meter_sub_policy(dev, flow, wks,
5214 enum mlx5_meter_domain mtr_domain =
5215 attr->transfer ? MLX5_MTR_DOMAIN_TRANSFER :
5216 (attr->egress ? MLX5_MTR_DOMAIN_EGRESS :
5217 MLX5_MTR_DOMAIN_INGRESS);
5220 &priv->sh->mtrmng->def_policy[mtr_domain]->sub_policy;
5222 tbl_data = container_of(sub_policy->tbl_rsc,
5223 struct mlx5_flow_tbl_data_entry, tbl);
5224 hw_mtr_action = actions_pre++;
5225 hw_mtr_action->type = (enum rte_flow_action_type)
5226 MLX5_RTE_FLOW_ACTION_TYPE_JUMP;
5227 hw_mtr_action->conf = tbl_data->jump.action;
5229 actions_pre->type = RTE_FLOW_ACTION_TYPE_END;
5232 return rte_flow_error_set(error, ENOMEM,
5233 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5234 NULL, "No tag action space.");
5236 tag_action->type = RTE_FLOW_ACTION_TYPE_VOID;
5239 /* Only default-policy Meter creates mtr flow id. */
5240 if (fm->def_policy) {
5241 mlx5_ipool_malloc(fm->flow_ipool, &tag_id);
5243 return rte_flow_error_set(error, ENOMEM,
5244 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
5245 "Failed to allocate meter flow id.");
5246 flow_id = tag_id - 1;
5247 flow_id_bits = (!flow_id) ? 1 :
5248 (MLX5_REG_BITS - __builtin_clz(flow_id));
5249 if ((flow_id_bits + priv->sh->mtrmng->max_mtr_bits) >
5251 mlx5_ipool_free(fm->flow_ipool, tag_id);
5252 return rte_flow_error_set(error, EINVAL,
5253 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
5254 "Meter flow id exceeds max limit.");
5256 if (flow_id_bits > priv->sh->mtrmng->max_mtr_flow_bits)
5257 priv->sh->mtrmng->max_mtr_flow_bits = flow_id_bits;
5259 /* Build tag actions and items for meter_id/meter flow_id. */
5260 set_tag = (struct mlx5_rte_flow_action_set_tag *)actions_pre;
5261 tag_item_spec = (struct mlx5_rte_flow_item_tag *)sfx_items;
5262 tag_item_mask = tag_item_spec + 1;
5263 /* Both flow_id and meter_id share the same register. */
5264 *set_tag = (struct mlx5_rte_flow_action_set_tag) {
5265 .id = (enum modify_reg)mlx5_flow_get_reg_id(dev, MLX5_MTR_ID,
5267 .offset = mtr_id_offset,
5268 .length = mtr_reg_bits,
5269 .data = flow->meter,
5272 * The color Reg bits used by flow_id are growing from
5273 * msb to lsb, so must do bit reverse for flow_id val in RegC.
5275 for (shift = 0; shift < flow_id_bits; shift++)
5276 flow_id_reversed = (flow_id_reversed << 1) |
5277 ((flow_id >> shift) & 0x1);
5279 flow_id_reversed << (mtr_reg_bits - flow_id_bits);
5280 tag_item_spec->id = set_tag->id;
5281 tag_item_spec->data = set_tag->data << mtr_id_offset;
5282 tag_item_mask->data = UINT32_MAX << mtr_id_offset;
5283 tag_action->type = (enum rte_flow_action_type)
5284 MLX5_RTE_FLOW_ACTION_TYPE_TAG;
5285 tag_action->conf = set_tag;
5286 tag_item->type = (enum rte_flow_item_type)
5287 MLX5_RTE_FLOW_ITEM_TYPE_TAG;
5288 tag_item->spec = tag_item_spec;
5289 tag_item->last = NULL;
5290 tag_item->mask = tag_item_mask;
5293 *mtr_flow_id = tag_id;
5298 * Split action list having QUEUE/RSS for metadata register copy.
5300 * Once Q/RSS action is detected in user's action list, the flow action
5301 * should be split in order to copy metadata registers, which will happen in
5303 * - CQE->flow_tag := reg_c[1] (MARK)
5304 * - CQE->flow_table_metadata (reg_b) := reg_c[0] (META)
5305 * The Q/RSS action will be performed on RX_ACT_TBL after passing by RX_CP_TBL.
5306 * This is because the last action of each flow must be a terminal action
5307 * (QUEUE, RSS or DROP).
5309 * Flow ID must be allocated to identify actions in the RX_ACT_TBL and it is
5310 * stored and kept in the mlx5_flow structure per each sub_flow.
5312 * The Q/RSS action is replaced with,
5313 * - SET_TAG, setting the allocated flow ID to reg_c[2].
5314 * And the following JUMP action is added at the end,
5315 * - JUMP, to RX_CP_TBL.
5317 * A flow to perform remained Q/RSS action will be created in RX_ACT_TBL by
5318 * flow_create_split_metadata() routine. The flow will look like,
5319 * - If flow ID matches (reg_c[2]), perform Q/RSS.
5322 * Pointer to Ethernet device.
5323 * @param[out] split_actions
5324 * Pointer to store split actions to jump to CP_TBL.
5325 * @param[in] actions
5326 * Pointer to the list of original flow actions.
5328 * Pointer to the Q/RSS action.
5329 * @param[in] actions_n
5330 * Number of original actions.
5331 * @param[in] mtr_sfx
5332 * Check if it is in meter suffix table.
5334 * Perform verbose error reporting if not NULL.
5337 * non-zero unique flow_id on success, otherwise 0 and
5338 * error/rte_error are set.
5341 flow_mreg_split_qrss_prep(struct rte_eth_dev *dev,
5342 struct rte_flow_action *split_actions,
5343 const struct rte_flow_action *actions,
5344 const struct rte_flow_action *qrss,
5345 int actions_n, int mtr_sfx,
5346 struct rte_flow_error *error)
5348 struct mlx5_priv *priv = dev->data->dev_private;
5349 struct mlx5_rte_flow_action_set_tag *set_tag;
5350 struct rte_flow_action_jump *jump;
5351 const int qrss_idx = qrss - actions;
5352 uint32_t flow_id = 0;
5356 * Given actions will be split
5357 * - Replace QUEUE/RSS action with SET_TAG to set flow ID.
5358 * - Add jump to mreg CP_TBL.
5359 * As a result, there will be one more action.
5361 memcpy(split_actions, actions, sizeof(*split_actions) * actions_n);
5362 /* Count MLX5_RTE_FLOW_ACTION_TYPE_TAG. */
5364 set_tag = (void *)(split_actions + actions_n);
5366 * If we are not the meter suffix flow, add the tag action.
5367 * Since meter suffix flow already has the tag added.
5371 * Allocate the new subflow ID. This one is unique within
5372 * device and not shared with representors. Otherwise,
5373 * we would have to resolve multi-thread access synch
5374 * issue. Each flow on the shared device is appended
5375 * with source vport identifier, so the resulting
5376 * flows will be unique in the shared (by master and
5377 * representors) domain even if they have coinciding
5380 mlx5_ipool_malloc(priv->sh->ipool
5381 [MLX5_IPOOL_RSS_EXPANTION_FLOW_ID], &flow_id);
5383 return rte_flow_error_set(error, ENOMEM,
5384 RTE_FLOW_ERROR_TYPE_ACTION,
5385 NULL, "can't allocate id "
5386 "for split Q/RSS subflow");
5387 /* Internal SET_TAG action to set flow ID. */
5388 *set_tag = (struct mlx5_rte_flow_action_set_tag){
5391 ret = mlx5_flow_get_reg_id(dev, MLX5_COPY_MARK, 0, error);
5395 /* Construct new actions array. */
5396 /* Replace QUEUE/RSS action. */
5397 split_actions[qrss_idx] = (struct rte_flow_action){
5398 .type = (enum rte_flow_action_type)
5399 MLX5_RTE_FLOW_ACTION_TYPE_TAG,
5404 * If we are the suffix flow of meter, tag already exist.
5405 * Set the QUEUE/RSS action to void.
5407 split_actions[qrss_idx].type = RTE_FLOW_ACTION_TYPE_VOID;
5409 /* JUMP action to jump to mreg copy table (CP_TBL). */
5410 jump = (void *)(set_tag + 1);
5411 *jump = (struct rte_flow_action_jump){
5412 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
5414 split_actions[actions_n - 2] = (struct rte_flow_action){
5415 .type = RTE_FLOW_ACTION_TYPE_JUMP,
5418 split_actions[actions_n - 1] = (struct rte_flow_action){
5419 .type = RTE_FLOW_ACTION_TYPE_END,
5425 * Extend the given action list for Tx metadata copy.
5427 * Copy the given action list to the ext_actions and add flow metadata register
5428 * copy action in order to copy reg_a set by WQE to reg_c[0].
5430 * @param[out] ext_actions
5431 * Pointer to the extended action list.
5432 * @param[in] actions
5433 * Pointer to the list of actions.
5434 * @param[in] actions_n
5435 * Number of actions in the list.
5437 * Perform verbose error reporting if not NULL.
5438 * @param[in] encap_idx
5439 * The encap action index.
5442 * 0 on success, negative value otherwise
5445 flow_mreg_tx_copy_prep(struct rte_eth_dev *dev,
5446 struct rte_flow_action *ext_actions,
5447 const struct rte_flow_action *actions,
5448 int actions_n, struct rte_flow_error *error,
5451 struct mlx5_flow_action_copy_mreg *cp_mreg =
5452 (struct mlx5_flow_action_copy_mreg *)
5453 (ext_actions + actions_n + 1);
5456 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_RX, 0, error);
5460 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_TX, 0, error);
5465 memcpy(ext_actions, actions, sizeof(*ext_actions) * encap_idx);
5466 if (encap_idx == actions_n - 1) {
5467 ext_actions[actions_n - 1] = (struct rte_flow_action){
5468 .type = (enum rte_flow_action_type)
5469 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
5472 ext_actions[actions_n] = (struct rte_flow_action){
5473 .type = RTE_FLOW_ACTION_TYPE_END,
5476 ext_actions[encap_idx] = (struct rte_flow_action){
5477 .type = (enum rte_flow_action_type)
5478 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
5481 memcpy(ext_actions + encap_idx + 1, actions + encap_idx,
5482 sizeof(*ext_actions) * (actions_n - encap_idx));
5488 * Check the match action from the action list.
5490 * @param[in] actions
5491 * Pointer to the list of actions.
5493 * Flow rule attributes.
5495 * The action to be check if exist.
5496 * @param[out] match_action_pos
5497 * Pointer to the position of the matched action if exists, otherwise is -1.
5498 * @param[out] qrss_action_pos
5499 * Pointer to the position of the Queue/RSS action if exists, otherwise is -1.
5500 * @param[out] modify_after_mirror
5501 * Pointer to the flag of modify action after FDB mirroring.
5504 * > 0 the total number of actions.
5505 * 0 if not found match action in action list.
5508 flow_check_match_action(const struct rte_flow_action actions[],
5509 const struct rte_flow_attr *attr,
5510 enum rte_flow_action_type action,
5511 int *match_action_pos, int *qrss_action_pos,
5512 int *modify_after_mirror)
5514 const struct rte_flow_action_sample *sample;
5515 const struct rte_flow_action_raw_decap *decap;
5522 *match_action_pos = -1;
5523 *qrss_action_pos = -1;
5524 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
5525 if (actions->type == action) {
5527 *match_action_pos = actions_n;
5529 switch (actions->type) {
5530 case RTE_FLOW_ACTION_TYPE_QUEUE:
5531 case RTE_FLOW_ACTION_TYPE_RSS:
5532 *qrss_action_pos = actions_n;
5534 case RTE_FLOW_ACTION_TYPE_SAMPLE:
5535 sample = actions->conf;
5536 ratio = sample->ratio;
5537 sub_type = ((const struct rte_flow_action *)
5538 (sample->actions))->type;
5539 if (ratio == 1 && attr->transfer)
5542 case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
5543 case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
5544 case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
5545 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
5546 case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
5547 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
5548 case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
5549 case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
5550 case RTE_FLOW_ACTION_TYPE_DEC_TTL:
5551 case RTE_FLOW_ACTION_TYPE_SET_TTL:
5552 case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
5553 case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
5554 case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
5555 case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
5556 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
5557 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
5558 case RTE_FLOW_ACTION_TYPE_FLAG:
5559 case RTE_FLOW_ACTION_TYPE_MARK:
5560 case RTE_FLOW_ACTION_TYPE_SET_META:
5561 case RTE_FLOW_ACTION_TYPE_SET_TAG:
5562 case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
5563 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
5564 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
5565 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
5566 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
5567 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
5568 case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
5569 case RTE_FLOW_ACTION_TYPE_METER:
5571 *modify_after_mirror = 1;
5573 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
5574 decap = actions->conf;
5575 while ((++actions)->type == RTE_FLOW_ACTION_TYPE_VOID)
5578 if (actions->type == RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
5579 const struct rte_flow_action_raw_encap *encap =
5582 MLX5_ENCAPSULATION_DECISION_SIZE &&
5584 MLX5_ENCAPSULATION_DECISION_SIZE)
5589 *modify_after_mirror = 1;
5596 if (flag && fdb_mirror && !*modify_after_mirror) {
5597 /* FDB mirroring uses the destination array to implement
5598 * instead of FLOW_SAMPLER object.
5600 if (sub_type != RTE_FLOW_ACTION_TYPE_END)
5603 /* Count RTE_FLOW_ACTION_TYPE_END. */
5604 return flag ? actions_n + 1 : 0;
5607 #define SAMPLE_SUFFIX_ITEM 2
5610 * Split the sample flow.
5612 * As sample flow will split to two sub flow, sample flow with
5613 * sample action, the other actions will move to new suffix flow.
5615 * Also add unique tag id with tag action in the sample flow,
5616 * the same tag id will be as match in the suffix flow.
5619 * Pointer to Ethernet device.
5620 * @param[in] add_tag
5621 * Add extra tag action flag.
5622 * @param[out] sfx_items
5623 * Suffix flow match items (list terminated by the END pattern item).
5624 * @param[in] actions
5625 * Associated actions (list terminated by the END action).
5626 * @param[out] actions_sfx
5627 * Suffix flow actions.
5628 * @param[out] actions_pre
5629 * Prefix flow actions.
5630 * @param[in] actions_n
5631 * The total number of actions.
5632 * @param[in] sample_action_pos
5633 * The sample action position.
5634 * @param[in] qrss_action_pos
5635 * The Queue/RSS action position.
5636 * @param[in] jump_table
5637 * Add extra jump action flag.
5639 * Perform verbose error reporting if not NULL.
5642 * 0 on success, or unique flow_id, a negative errno value
5643 * otherwise and rte_errno is set.
5646 flow_sample_split_prep(struct rte_eth_dev *dev,
5648 struct rte_flow_item sfx_items[],
5649 const struct rte_flow_action actions[],
5650 struct rte_flow_action actions_sfx[],
5651 struct rte_flow_action actions_pre[],
5653 int sample_action_pos,
5654 int qrss_action_pos,
5656 struct rte_flow_error *error)
5658 struct mlx5_priv *priv = dev->data->dev_private;
5659 struct mlx5_rte_flow_action_set_tag *set_tag;
5660 struct mlx5_rte_flow_item_tag *tag_spec;
5661 struct mlx5_rte_flow_item_tag *tag_mask;
5662 struct rte_flow_action_jump *jump_action;
5663 uint32_t tag_id = 0;
5665 int append_index = 0;
5668 if (sample_action_pos < 0)
5669 return rte_flow_error_set(error, EINVAL,
5670 RTE_FLOW_ERROR_TYPE_ACTION,
5671 NULL, "invalid position of sample "
5673 /* Prepare the actions for prefix and suffix flow. */
5674 if (qrss_action_pos >= 0 && qrss_action_pos < sample_action_pos) {
5675 index = qrss_action_pos;
5676 /* Put the preceding the Queue/RSS action into prefix flow. */
5678 memcpy(actions_pre, actions,
5679 sizeof(struct rte_flow_action) * index);
5680 /* Put others preceding the sample action into prefix flow. */
5681 if (sample_action_pos > index + 1)
5682 memcpy(actions_pre + index, actions + index + 1,
5683 sizeof(struct rte_flow_action) *
5684 (sample_action_pos - index - 1));
5685 index = sample_action_pos - 1;
5686 /* Put Queue/RSS action into Suffix flow. */
5687 memcpy(actions_sfx, actions + qrss_action_pos,
5688 sizeof(struct rte_flow_action));
5691 index = sample_action_pos;
5693 memcpy(actions_pre, actions,
5694 sizeof(struct rte_flow_action) * index);
5696 /* For CX5, add an extra tag action for NIC-RX and E-Switch ingress.
5697 * For CX6DX and above, metadata registers Cx preserve their value,
5698 * add an extra tag action for NIC-RX and E-Switch Domain.
5701 /* Prepare the prefix tag action. */
5703 set_tag = (void *)(actions_pre + actions_n + append_index);
5704 ret = mlx5_flow_get_reg_id(dev, MLX5_SAMPLE_ID, 0, error);
5707 mlx5_ipool_malloc(priv->sh->ipool
5708 [MLX5_IPOOL_RSS_EXPANTION_FLOW_ID], &tag_id);
5709 *set_tag = (struct mlx5_rte_flow_action_set_tag) {
5713 /* Prepare the suffix subflow items. */
5714 tag_spec = (void *)(sfx_items + SAMPLE_SUFFIX_ITEM);
5715 tag_spec->data = tag_id;
5716 tag_spec->id = set_tag->id;
5717 tag_mask = tag_spec + 1;
5718 tag_mask->data = UINT32_MAX;
5719 sfx_items[0] = (struct rte_flow_item){
5720 .type = (enum rte_flow_item_type)
5721 MLX5_RTE_FLOW_ITEM_TYPE_TAG,
5726 sfx_items[1] = (struct rte_flow_item){
5727 .type = (enum rte_flow_item_type)
5728 RTE_FLOW_ITEM_TYPE_END,
5730 /* Prepare the tag action in prefix subflow. */
5731 actions_pre[index++] =
5732 (struct rte_flow_action){
5733 .type = (enum rte_flow_action_type)
5734 MLX5_RTE_FLOW_ACTION_TYPE_TAG,
5738 memcpy(actions_pre + index, actions + sample_action_pos,
5739 sizeof(struct rte_flow_action));
5741 /* For the modify action after the sample action in E-Switch mirroring,
5742 * Add the extra jump action in prefix subflow and jump into the next
5743 * table, then do the modify action in the new table.
5746 /* Prepare the prefix jump action. */
5748 jump_action = (void *)(actions_pre + actions_n + append_index);
5749 jump_action->group = jump_table;
5750 actions_pre[index++] =
5751 (struct rte_flow_action){
5752 .type = (enum rte_flow_action_type)
5753 RTE_FLOW_ACTION_TYPE_JUMP,
5754 .conf = jump_action,
5757 actions_pre[index] = (struct rte_flow_action){
5758 .type = (enum rte_flow_action_type)
5759 RTE_FLOW_ACTION_TYPE_END,
5761 /* Put the actions after sample into Suffix flow. */
5762 memcpy(actions_sfx, actions + sample_action_pos + 1,
5763 sizeof(struct rte_flow_action) *
5764 (actions_n - sample_action_pos - 1));
5769 * The splitting for metadata feature.
5771 * - Q/RSS action on NIC Rx should be split in order to pass by
5772 * the mreg copy table (RX_CP_TBL) and then it jumps to the
5773 * action table (RX_ACT_TBL) which has the split Q/RSS action.
5775 * - All the actions on NIC Tx should have a mreg copy action to
5776 * copy reg_a from WQE to reg_c[0].
5779 * Pointer to Ethernet device.
5781 * Parent flow structure pointer.
5783 * Flow rule attributes.
5785 * Pattern specification (list terminated by the END pattern item).
5786 * @param[in] actions
5787 * Associated actions (list terminated by the END action).
5788 * @param[in] flow_split_info
5789 * Pointer to flow split info structure.
5791 * Perform verbose error reporting if not NULL.
5793 * 0 on success, negative value otherwise
5796 flow_create_split_metadata(struct rte_eth_dev *dev,
5797 struct rte_flow *flow,
5798 const struct rte_flow_attr *attr,
5799 const struct rte_flow_item items[],
5800 const struct rte_flow_action actions[],
5801 struct mlx5_flow_split_info *flow_split_info,
5802 struct rte_flow_error *error)
5804 struct mlx5_priv *priv = dev->data->dev_private;
5805 struct mlx5_sh_config *config = &priv->sh->config;
5806 const struct rte_flow_action *qrss = NULL;
5807 struct rte_flow_action *ext_actions = NULL;
5808 struct mlx5_flow *dev_flow = NULL;
5809 uint32_t qrss_id = 0;
5816 /* Check whether extensive metadata feature is engaged. */
5817 if (!config->dv_flow_en ||
5818 config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
5819 !mlx5_flow_ext_mreg_supported(dev))
5820 return flow_create_split_inner(dev, flow, NULL, attr, items,
5821 actions, flow_split_info, error);
5822 actions_n = flow_parse_metadata_split_actions_info(actions, &qrss,
5825 /* Exclude hairpin flows from splitting. */
5826 if (qrss->type == RTE_FLOW_ACTION_TYPE_QUEUE) {
5827 const struct rte_flow_action_queue *queue;
5830 if (mlx5_rxq_get_type(dev, queue->index) ==
5831 MLX5_RXQ_TYPE_HAIRPIN)
5833 } else if (qrss->type == RTE_FLOW_ACTION_TYPE_RSS) {
5834 const struct rte_flow_action_rss *rss;
5837 if (mlx5_rxq_get_type(dev, rss->queue[0]) ==
5838 MLX5_RXQ_TYPE_HAIRPIN)
5843 /* Check if it is in meter suffix table. */
5844 mtr_sfx = attr->group == (attr->transfer ?
5845 (MLX5_FLOW_TABLE_LEVEL_METER - 1) :
5846 MLX5_FLOW_TABLE_LEVEL_METER);
5848 * Q/RSS action on NIC Rx should be split in order to pass by
5849 * the mreg copy table (RX_CP_TBL) and then it jumps to the
5850 * action table (RX_ACT_TBL) which has the split Q/RSS action.
5852 act_size = sizeof(struct rte_flow_action) * (actions_n + 1) +
5853 sizeof(struct rte_flow_action_set_tag) +
5854 sizeof(struct rte_flow_action_jump);
5855 ext_actions = mlx5_malloc(MLX5_MEM_ZERO, act_size, 0,
5858 return rte_flow_error_set(error, ENOMEM,
5859 RTE_FLOW_ERROR_TYPE_ACTION,
5860 NULL, "no memory to split "
5863 * Create the new actions list with removed Q/RSS action
5864 * and appended set tag and jump to register copy table
5865 * (RX_CP_TBL). We should preallocate unique tag ID here
5866 * in advance, because it is needed for set tag action.
5868 qrss_id = flow_mreg_split_qrss_prep(dev, ext_actions, actions,
5871 if (!mtr_sfx && !qrss_id) {
5875 } else if (attr->egress && !attr->transfer) {
5877 * All the actions on NIC Tx should have a metadata register
5878 * copy action to copy reg_a from WQE to reg_c[meta]
5880 act_size = sizeof(struct rte_flow_action) * (actions_n + 1) +
5881 sizeof(struct mlx5_flow_action_copy_mreg);
5882 ext_actions = mlx5_malloc(MLX5_MEM_ZERO, act_size, 0,
5885 return rte_flow_error_set(error, ENOMEM,
5886 RTE_FLOW_ERROR_TYPE_ACTION,
5887 NULL, "no memory to split "
5889 /* Create the action list appended with copy register. */
5890 ret = flow_mreg_tx_copy_prep(dev, ext_actions, actions,
5891 actions_n, error, encap_idx);
5895 /* Add the unmodified original or prefix subflow. */
5896 ret = flow_create_split_inner(dev, flow, &dev_flow, attr,
5897 items, ext_actions ? ext_actions :
5898 actions, flow_split_info, error);
5901 MLX5_ASSERT(dev_flow);
5903 const struct rte_flow_attr q_attr = {
5904 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
5907 /* Internal PMD action to set register. */
5908 struct mlx5_rte_flow_item_tag q_tag_spec = {
5912 struct rte_flow_item q_items[] = {
5914 .type = (enum rte_flow_item_type)
5915 MLX5_RTE_FLOW_ITEM_TYPE_TAG,
5916 .spec = &q_tag_spec,
5921 .type = RTE_FLOW_ITEM_TYPE_END,
5924 struct rte_flow_action q_actions[] = {
5930 .type = RTE_FLOW_ACTION_TYPE_END,
5933 uint64_t layers = flow_get_prefix_layer_flags(dev_flow);
5936 * Configure the tag item only if there is no meter subflow.
5937 * Since tag is already marked in the meter suffix subflow
5938 * we can just use the meter suffix items as is.
5941 /* Not meter subflow. */
5942 MLX5_ASSERT(!mtr_sfx);
5944 * Put unique id in prefix flow due to it is destroyed
5945 * after suffix flow and id will be freed after there
5946 * is no actual flows with this id and identifier
5947 * reallocation becomes possible (for example, for
5948 * other flows in other threads).
5950 dev_flow->handle->split_flow_id = qrss_id;
5951 ret = mlx5_flow_get_reg_id(dev, MLX5_COPY_MARK, 0,
5955 q_tag_spec.id = ret;
5958 /* Add suffix subflow to execute Q/RSS. */
5959 flow_split_info->prefix_layers = layers;
5960 flow_split_info->prefix_mark = 0;
5961 flow_split_info->table_id = 0;
5962 ret = flow_create_split_inner(dev, flow, &dev_flow,
5963 &q_attr, mtr_sfx ? items :
5965 flow_split_info, error);
5968 /* qrss ID should be freed if failed. */
5970 MLX5_ASSERT(dev_flow);
5975 * We do not destroy the partially created sub_flows in case of error.
5976 * These ones are included into parent flow list and will be destroyed
5977 * by flow_drv_destroy.
5979 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RSS_EXPANTION_FLOW_ID],
5981 mlx5_free(ext_actions);
5986 * Create meter internal drop flow with the original pattern.
5989 * Pointer to Ethernet device.
5991 * Parent flow structure pointer.
5993 * Flow rule attributes.
5995 * Pattern specification (list terminated by the END pattern item).
5996 * @param[in] flow_split_info
5997 * Pointer to flow split info structure.
5999 * Pointer to flow meter structure.
6001 * Perform verbose error reporting if not NULL.
6003 * 0 on success, negative value otherwise
6006 flow_meter_create_drop_flow_with_org_pattern(struct rte_eth_dev *dev,
6007 struct rte_flow *flow,
6008 const struct rte_flow_attr *attr,
6009 const struct rte_flow_item items[],
6010 struct mlx5_flow_split_info *flow_split_info,
6011 struct mlx5_flow_meter_info *fm,
6012 struct rte_flow_error *error)
6014 struct mlx5_flow *dev_flow = NULL;
6015 struct rte_flow_attr drop_attr = *attr;
6016 struct rte_flow_action drop_actions[3];
6017 struct mlx5_flow_split_info drop_split_info = *flow_split_info;
6019 MLX5_ASSERT(fm->drop_cnt);
6020 drop_actions[0].type =
6021 (enum rte_flow_action_type)MLX5_RTE_FLOW_ACTION_TYPE_COUNT;
6022 drop_actions[0].conf = (void *)(uintptr_t)fm->drop_cnt;
6023 drop_actions[1].type = RTE_FLOW_ACTION_TYPE_DROP;
6024 drop_actions[1].conf = NULL;
6025 drop_actions[2].type = RTE_FLOW_ACTION_TYPE_END;
6026 drop_actions[2].conf = NULL;
6027 drop_split_info.external = false;
6028 drop_split_info.skip_scale |= 1 << MLX5_SCALE_FLOW_GROUP_BIT;
6029 drop_split_info.table_id = MLX5_MTR_TABLE_ID_DROP;
6030 drop_attr.group = MLX5_FLOW_TABLE_LEVEL_METER;
6031 return flow_create_split_inner(dev, flow, &dev_flow,
6032 &drop_attr, items, drop_actions,
6033 &drop_split_info, error);
6037 * The splitting for meter feature.
6039 * - The meter flow will be split to two flows as prefix and
6040 * suffix flow. The packets make sense only it pass the prefix
6043 * - Reg_C_5 is used for the packet to match betweend prefix and
6047 * Pointer to Ethernet device.
6049 * Parent flow structure pointer.
6051 * Flow rule attributes.
6053 * Pattern specification (list terminated by the END pattern item).
6054 * @param[in] actions
6055 * Associated actions (list terminated by the END action).
6056 * @param[in] flow_split_info
6057 * Pointer to flow split info structure.
6059 * Perform verbose error reporting if not NULL.
6061 * 0 on success, negative value otherwise
6064 flow_create_split_meter(struct rte_eth_dev *dev,
6065 struct rte_flow *flow,
6066 const struct rte_flow_attr *attr,
6067 const struct rte_flow_item items[],
6068 const struct rte_flow_action actions[],
6069 struct mlx5_flow_split_info *flow_split_info,
6070 struct rte_flow_error *error)
6072 struct mlx5_priv *priv = dev->data->dev_private;
6073 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
6074 struct rte_flow_action *sfx_actions = NULL;
6075 struct rte_flow_action *pre_actions = NULL;
6076 struct rte_flow_item *sfx_items = NULL;
6077 struct mlx5_flow *dev_flow = NULL;
6078 struct rte_flow_attr sfx_attr = *attr;
6079 struct mlx5_flow_meter_info *fm = NULL;
6080 uint8_t skip_scale_restore;
6081 bool has_mtr = false;
6082 bool has_modify = false;
6083 bool set_mtr_reg = true;
6084 bool is_mtr_hierarchy = false;
6085 uint32_t meter_id = 0;
6086 uint32_t mtr_idx = 0;
6087 uint32_t mtr_flow_id = 0;
6094 actions_n = flow_check_meter_action(dev, actions, &has_mtr,
6095 &has_modify, &meter_id);
6098 fm = flow_dv_meter_find_by_idx(priv, flow->meter);
6100 return rte_flow_error_set(error, EINVAL,
6101 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6102 NULL, "Meter not found.");
6104 fm = mlx5_flow_meter_find(priv, meter_id, &mtr_idx);
6106 return rte_flow_error_set(error, EINVAL,
6107 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6108 NULL, "Meter not found.");
6109 ret = mlx5_flow_meter_attach(priv, fm,
6113 flow->meter = mtr_idx;
6117 if (!fm->def_policy) {
6118 wks->policy = mlx5_flow_meter_policy_find(dev,
6121 MLX5_ASSERT(wks->policy);
6122 if (wks->policy->is_hierarchy) {
6124 mlx5_flow_meter_hierarchy_get_final_policy(dev,
6126 if (!wks->final_policy)
6127 return rte_flow_error_set(error,
6129 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
6130 "Failed to find terminal policy of hierarchy.");
6131 is_mtr_hierarchy = true;
6135 * If it isn't default-policy Meter, and
6136 * 1. There's no action in flow to change
6137 * packet (modify/encap/decap etc.), OR
6138 * 2. No drop count needed for this meter.
6139 * 3. It's not meter hierarchy.
6140 * Then no need to use regC to save meter id anymore.
6142 if (!fm->def_policy && !is_mtr_hierarchy &&
6143 (!has_modify || !fm->drop_cnt))
6144 set_mtr_reg = false;
6145 /* Prefix actions: meter, decap, encap, tag, jump, end. */
6146 act_size = sizeof(struct rte_flow_action) * (actions_n + 6) +
6147 sizeof(struct mlx5_rte_flow_action_set_tag);
6148 /* Suffix items: tag, vlan, port id, end. */
6149 #define METER_SUFFIX_ITEM 4
6150 item_size = sizeof(struct rte_flow_item) * METER_SUFFIX_ITEM +
6151 sizeof(struct mlx5_rte_flow_item_tag) * 2;
6152 sfx_actions = mlx5_malloc(MLX5_MEM_ZERO, (act_size + item_size),
6155 return rte_flow_error_set(error, ENOMEM,
6156 RTE_FLOW_ERROR_TYPE_ACTION,
6157 NULL, "no memory to split "
6159 sfx_items = (struct rte_flow_item *)((char *)sfx_actions +
6161 /* There's no suffix flow for meter of non-default policy. */
6162 if (!fm->def_policy)
6163 pre_actions = sfx_actions + 1;
6165 pre_actions = sfx_actions + actions_n;
6166 ret = flow_meter_split_prep(dev, flow, wks, &sfx_attr,
6167 items, sfx_items, actions,
6168 sfx_actions, pre_actions,
6169 (set_mtr_reg ? &mtr_flow_id : NULL),
6175 /* Add the prefix subflow. */
6176 skip_scale_restore = flow_split_info->skip_scale;
6177 flow_split_info->skip_scale |=
6178 1 << MLX5_SCALE_JUMP_FLOW_GROUP_BIT;
6179 ret = flow_create_split_inner(dev, flow, &dev_flow,
6180 attr, items, pre_actions,
6181 flow_split_info, error);
6182 flow_split_info->skip_scale = skip_scale_restore;
6185 mlx5_ipool_free(fm->flow_ipool, mtr_flow_id);
6190 dev_flow->handle->split_flow_id = mtr_flow_id;
6191 dev_flow->handle->is_meter_flow_id = 1;
6193 if (!fm->def_policy) {
6194 if (!set_mtr_reg && fm->drop_cnt)
6196 flow_meter_create_drop_flow_with_org_pattern(dev, flow,
6202 /* Setting the sfx group atrr. */
6203 sfx_attr.group = sfx_attr.transfer ?
6204 (MLX5_FLOW_TABLE_LEVEL_METER - 1) :
6205 MLX5_FLOW_TABLE_LEVEL_METER;
6206 flow_split_info->prefix_layers =
6207 flow_get_prefix_layer_flags(dev_flow);
6208 flow_split_info->prefix_mark |= wks->mark;
6209 flow_split_info->table_id = MLX5_MTR_TABLE_ID_SUFFIX;
6211 /* Add the prefix subflow. */
6212 ret = flow_create_split_metadata(dev, flow,
6213 &sfx_attr, sfx_items ?
6215 sfx_actions ? sfx_actions : actions,
6216 flow_split_info, error);
6219 mlx5_free(sfx_actions);
6224 * The splitting for sample feature.
6226 * Once Sample action is detected in the action list, the flow actions should
6227 * be split into prefix sub flow and suffix sub flow.
6229 * The original items remain in the prefix sub flow, all actions preceding the
6230 * sample action and the sample action itself will be copied to the prefix
6231 * sub flow, the actions following the sample action will be copied to the
6232 * suffix sub flow, Queue action always be located in the suffix sub flow.
6234 * In order to make the packet from prefix sub flow matches with suffix sub
6235 * flow, an extra tag action be added into prefix sub flow, and the suffix sub
6236 * flow uses tag item with the unique flow id.
6239 * Pointer to Ethernet device.
6241 * Parent flow structure pointer.
6243 * Flow rule attributes.
6245 * Pattern specification (list terminated by the END pattern item).
6246 * @param[in] actions
6247 * Associated actions (list terminated by the END action).
6248 * @param[in] flow_split_info
6249 * Pointer to flow split info structure.
6251 * Perform verbose error reporting if not NULL.
6253 * 0 on success, negative value otherwise
6256 flow_create_split_sample(struct rte_eth_dev *dev,
6257 struct rte_flow *flow,
6258 const struct rte_flow_attr *attr,
6259 const struct rte_flow_item items[],
6260 const struct rte_flow_action actions[],
6261 struct mlx5_flow_split_info *flow_split_info,
6262 struct rte_flow_error *error)
6264 struct mlx5_priv *priv = dev->data->dev_private;
6265 struct rte_flow_action *sfx_actions = NULL;
6266 struct rte_flow_action *pre_actions = NULL;
6267 struct rte_flow_item *sfx_items = NULL;
6268 struct mlx5_flow *dev_flow = NULL;
6269 struct rte_flow_attr sfx_attr = *attr;
6270 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
6271 struct mlx5_flow_dv_sample_resource *sample_res;
6272 struct mlx5_flow_tbl_data_entry *sfx_tbl_data;
6273 struct mlx5_flow_tbl_resource *sfx_tbl;
6274 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
6278 uint32_t fdb_tx = 0;
6281 int sample_action_pos;
6282 int qrss_action_pos;
6284 int modify_after_mirror = 0;
6285 uint16_t jump_table = 0;
6286 const uint32_t next_ft_step = 1;
6289 if (priv->sampler_en)
6290 actions_n = flow_check_match_action(actions, attr,
6291 RTE_FLOW_ACTION_TYPE_SAMPLE,
6292 &sample_action_pos, &qrss_action_pos,
6293 &modify_after_mirror);
6295 /* The prefix actions must includes sample, tag, end. */
6296 act_size = sizeof(struct rte_flow_action) * (actions_n * 2 + 1)
6297 + sizeof(struct mlx5_rte_flow_action_set_tag);
6298 item_size = sizeof(struct rte_flow_item) * SAMPLE_SUFFIX_ITEM +
6299 sizeof(struct mlx5_rte_flow_item_tag) * 2;
6300 sfx_actions = mlx5_malloc(MLX5_MEM_ZERO, (act_size +
6301 item_size), 0, SOCKET_ID_ANY);
6303 return rte_flow_error_set(error, ENOMEM,
6304 RTE_FLOW_ERROR_TYPE_ACTION,
6305 NULL, "no memory to split "
6307 /* The representor_id is UINT16_MAX for uplink. */
6308 fdb_tx = (attr->transfer && priv->representor_id != UINT16_MAX);
6310 * When reg_c_preserve is set, metadata registers Cx preserve
6311 * their value even through packet duplication.
6313 add_tag = (!fdb_tx ||
6314 priv->sh->cdev->config.hca_attr.reg_c_preserve);
6316 sfx_items = (struct rte_flow_item *)((char *)sfx_actions
6318 if (modify_after_mirror)
6319 jump_table = attr->group * MLX5_FLOW_TABLE_FACTOR +
6321 pre_actions = sfx_actions + actions_n;
6322 tag_id = flow_sample_split_prep(dev, add_tag, sfx_items,
6323 actions, sfx_actions,
6324 pre_actions, actions_n,
6326 qrss_action_pos, jump_table,
6328 if (tag_id < 0 || (add_tag && !tag_id)) {
6332 if (modify_after_mirror)
6333 flow_split_info->skip_scale =
6334 1 << MLX5_SCALE_JUMP_FLOW_GROUP_BIT;
6335 /* Add the prefix subflow. */
6336 ret = flow_create_split_inner(dev, flow, &dev_flow, attr,
6338 flow_split_info, error);
6343 dev_flow->handle->split_flow_id = tag_id;
6344 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
6345 if (!modify_after_mirror) {
6346 /* Set the sfx group attr. */
6347 sample_res = (struct mlx5_flow_dv_sample_resource *)
6348 dev_flow->dv.sample_res;
6349 sfx_tbl = (struct mlx5_flow_tbl_resource *)
6350 sample_res->normal_path_tbl;
6351 sfx_tbl_data = container_of(sfx_tbl,
6352 struct mlx5_flow_tbl_data_entry,
6354 sfx_attr.group = sfx_attr.transfer ?
6355 (sfx_tbl_data->level - 1) : sfx_tbl_data->level;
6357 MLX5_ASSERT(attr->transfer);
6358 sfx_attr.group = jump_table;
6360 flow_split_info->prefix_layers =
6361 flow_get_prefix_layer_flags(dev_flow);
6363 flow_split_info->prefix_mark |= wks->mark;
6364 /* Suffix group level already be scaled with factor, set
6365 * MLX5_SCALE_FLOW_GROUP_BIT of skip_scale to 1 to avoid scale
6366 * again in translation.
6368 flow_split_info->skip_scale = 1 << MLX5_SCALE_FLOW_GROUP_BIT;
6371 /* Add the suffix subflow. */
6372 ret = flow_create_split_meter(dev, flow, &sfx_attr,
6373 sfx_items ? sfx_items : items,
6374 sfx_actions ? sfx_actions : actions,
6375 flow_split_info, error);
6378 mlx5_free(sfx_actions);
6383 * Split the flow to subflow set. The splitters might be linked
6384 * in the chain, like this:
6385 * flow_create_split_outer() calls:
6386 * flow_create_split_meter() calls:
6387 * flow_create_split_metadata(meter_subflow_0) calls:
6388 * flow_create_split_inner(metadata_subflow_0)
6389 * flow_create_split_inner(metadata_subflow_1)
6390 * flow_create_split_inner(metadata_subflow_2)
6391 * flow_create_split_metadata(meter_subflow_1) calls:
6392 * flow_create_split_inner(metadata_subflow_0)
6393 * flow_create_split_inner(metadata_subflow_1)
6394 * flow_create_split_inner(metadata_subflow_2)
6396 * This provide flexible way to add new levels of flow splitting.
6397 * The all of successfully created subflows are included to the
6398 * parent flow dev_flow list.
6401 * Pointer to Ethernet device.
6403 * Parent flow structure pointer.
6405 * Flow rule attributes.
6407 * Pattern specification (list terminated by the END pattern item).
6408 * @param[in] actions
6409 * Associated actions (list terminated by the END action).
6410 * @param[in] flow_split_info
6411 * Pointer to flow split info structure.
6413 * Perform verbose error reporting if not NULL.
6415 * 0 on success, negative value otherwise
6418 flow_create_split_outer(struct rte_eth_dev *dev,
6419 struct rte_flow *flow,
6420 const struct rte_flow_attr *attr,
6421 const struct rte_flow_item items[],
6422 const struct rte_flow_action actions[],
6423 struct mlx5_flow_split_info *flow_split_info,
6424 struct rte_flow_error *error)
6428 ret = flow_create_split_sample(dev, flow, attr, items,
6429 actions, flow_split_info, error);
6430 MLX5_ASSERT(ret <= 0);
6434 static inline struct mlx5_flow_tunnel *
6435 flow_tunnel_from_rule(const struct mlx5_flow *flow)
6437 struct mlx5_flow_tunnel *tunnel;
6439 #pragma GCC diagnostic push
6440 #pragma GCC diagnostic ignored "-Wcast-qual"
6441 tunnel = (typeof(tunnel))flow->tunnel;
6442 #pragma GCC diagnostic pop
6448 * Adjust flow RSS workspace if needed.
6451 * Pointer to thread flow work space.
6453 * Pointer to RSS descriptor.
6454 * @param[in] nrssq_num
6455 * New RSS queue number.
6458 * 0 on success, -1 otherwise and rte_errno is set.
6461 flow_rss_workspace_adjust(struct mlx5_flow_workspace *wks,
6462 struct mlx5_flow_rss_desc *rss_desc,
6465 if (likely(nrssq_num <= wks->rssq_num))
6467 rss_desc->queue = realloc(rss_desc->queue,
6468 sizeof(*rss_desc->queue) * RTE_ALIGN(nrssq_num, 2));
6469 if (!rss_desc->queue) {
6473 wks->rssq_num = RTE_ALIGN(nrssq_num, 2);
6478 * Create a flow and add it to @p list.
6481 * Pointer to Ethernet device.
6483 * Pointer to a TAILQ flow list. If this parameter NULL,
6484 * no list insertion occurred, flow is just created,
6485 * this is caller's responsibility to track the
6488 * Flow rule attributes.
6490 * Pattern specification (list terminated by the END pattern item).
6491 * @param[in] actions
6492 * Associated actions (list terminated by the END action).
6493 * @param[in] external
6494 * This flow rule is created by request external to PMD.
6496 * Perform verbose error reporting if not NULL.
6499 * A flow index on success, 0 otherwise and rte_errno is set.
6502 flow_list_create(struct rte_eth_dev *dev, enum mlx5_flow_type type,
6503 const struct rte_flow_attr *attr,
6504 const struct rte_flow_item items[],
6505 const struct rte_flow_action original_actions[],
6506 bool external, struct rte_flow_error *error)
6508 struct mlx5_priv *priv = dev->data->dev_private;
6509 struct rte_flow *flow = NULL;
6510 struct mlx5_flow *dev_flow;
6511 const struct rte_flow_action_rss *rss = NULL;
6512 struct mlx5_translated_action_handle
6513 indir_actions[MLX5_MAX_INDIRECT_ACTIONS];
6514 int indir_actions_n = MLX5_MAX_INDIRECT_ACTIONS;
6516 struct mlx5_flow_expand_rss buf;
6517 uint8_t buffer[4096];
6520 struct rte_flow_action actions[MLX5_MAX_SPLIT_ACTIONS];
6521 uint8_t buffer[2048];
6524 struct rte_flow_action actions[MLX5_MAX_SPLIT_ACTIONS];
6525 uint8_t buffer[2048];
6526 } actions_hairpin_tx;
6528 struct rte_flow_item items[MLX5_MAX_SPLIT_ITEMS];
6529 uint8_t buffer[2048];
6531 struct mlx5_flow_expand_rss *buf = &expand_buffer.buf;
6532 struct mlx5_flow_rss_desc *rss_desc;
6533 const struct rte_flow_action *p_actions_rx;
6537 struct rte_flow_attr attr_tx = { .priority = 0 };
6538 const struct rte_flow_action *actions;
6539 struct rte_flow_action *translated_actions = NULL;
6540 struct mlx5_flow_tunnel *tunnel;
6541 struct tunnel_default_miss_ctx default_miss_ctx = { 0, };
6542 struct mlx5_flow_workspace *wks = mlx5_flow_push_thread_workspace();
6543 struct mlx5_flow_split_info flow_split_info = {
6544 .external = !!external,
6554 rss_desc = &wks->rss_desc;
6555 ret = flow_action_handles_translate(dev, original_actions,
6558 &translated_actions, error);
6560 MLX5_ASSERT(translated_actions == NULL);
6563 actions = translated_actions ? translated_actions : original_actions;
6564 p_actions_rx = actions;
6565 hairpin_flow = flow_check_hairpin_split(dev, attr, actions);
6566 ret = flow_drv_validate(dev, attr, items, p_actions_rx,
6567 external, hairpin_flow, error);
6569 goto error_before_hairpin_split;
6570 flow = mlx5_ipool_zmalloc(priv->flows[type], &idx);
6573 goto error_before_hairpin_split;
6575 if (hairpin_flow > 0) {
6576 if (hairpin_flow > MLX5_MAX_SPLIT_ACTIONS) {
6578 goto error_before_hairpin_split;
6580 flow_hairpin_split(dev, actions, actions_rx.actions,
6581 actions_hairpin_tx.actions, items_tx.items,
6583 p_actions_rx = actions_rx.actions;
6585 flow_split_info.flow_idx = idx;
6586 flow->drv_type = flow_get_drv_type(dev, attr);
6587 MLX5_ASSERT(flow->drv_type > MLX5_FLOW_TYPE_MIN &&
6588 flow->drv_type < MLX5_FLOW_TYPE_MAX);
6589 memset(rss_desc, 0, offsetof(struct mlx5_flow_rss_desc, queue));
6590 /* RSS Action only works on NIC RX domain */
6591 if (attr->ingress && !attr->transfer)
6592 rss = flow_get_rss_action(dev, p_actions_rx);
6594 if (flow_rss_workspace_adjust(wks, rss_desc, rss->queue_num))
6597 * The following information is required by
6598 * mlx5_flow_hashfields_adjust() in advance.
6600 rss_desc->level = rss->level;
6601 /* RSS type 0 indicates default RSS type (RTE_ETH_RSS_IP). */
6602 rss_desc->types = !rss->types ? RTE_ETH_RSS_IP : rss->types;
6604 flow->dev_handles = 0;
6605 if (rss && rss->types) {
6606 unsigned int graph_root;
6608 graph_root = find_graph_root(rss->level);
6609 ret = mlx5_flow_expand_rss(buf, sizeof(expand_buffer.buffer),
6611 mlx5_support_expansion, graph_root);
6612 MLX5_ASSERT(ret > 0 &&
6613 (unsigned int)ret < sizeof(expand_buffer.buffer));
6614 if (rte_log_can_log(mlx5_logtype, RTE_LOG_DEBUG)) {
6615 for (i = 0; i < buf->entries; ++i)
6616 mlx5_dbg__print_pattern(buf->entry[i].pattern);
6620 buf->entry[0].pattern = (void *)(uintptr_t)items;
6622 rss_desc->shared_rss = flow_get_shared_rss_action(dev, indir_actions,
6624 for (i = 0; i < buf->entries; ++i) {
6625 /* Initialize flow split data. */
6626 flow_split_info.prefix_layers = 0;
6627 flow_split_info.prefix_mark = 0;
6628 flow_split_info.skip_scale = 0;
6630 * The splitter may create multiple dev_flows,
6631 * depending on configuration. In the simplest
6632 * case it just creates unmodified original flow.
6634 ret = flow_create_split_outer(dev, flow, attr,
6635 buf->entry[i].pattern,
6636 p_actions_rx, &flow_split_info,
6640 if (is_flow_tunnel_steer_rule(wks->flows[0].tof_type)) {
6641 ret = flow_tunnel_add_default_miss(dev, flow, attr,
6644 wks->flows[0].tunnel,
6648 mlx5_free(default_miss_ctx.queue);
6653 /* Create the tx flow. */
6655 attr_tx.group = MLX5_HAIRPIN_TX_TABLE;
6656 attr_tx.ingress = 0;
6658 dev_flow = flow_drv_prepare(dev, flow, &attr_tx, items_tx.items,
6659 actions_hairpin_tx.actions,
6663 dev_flow->flow = flow;
6664 dev_flow->external = 0;
6665 SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
6666 dev_flow->handle, next);
6667 ret = flow_drv_translate(dev, dev_flow, &attr_tx,
6669 actions_hairpin_tx.actions, error);
6674 * Update the metadata register copy table. If extensive
6675 * metadata feature is enabled and registers are supported
6676 * we might create the extra rte_flow for each unique
6677 * MARK/FLAG action ID.
6679 * The table is updated for ingress Flows only, because
6680 * the egress Flows belong to the different device and
6681 * copy table should be updated in peer NIC Rx domain.
6683 if (attr->ingress &&
6684 (external || attr->group != MLX5_FLOW_MREG_CP_TABLE_GROUP)) {
6685 ret = flow_mreg_update_copy_table(dev, flow, actions, error);
6690 * If the flow is external (from application) OR device is started,
6691 * OR mreg discover, then apply immediately.
6693 if (external || dev->data->dev_started ||
6694 (attr->group == MLX5_FLOW_MREG_CP_TABLE_GROUP &&
6695 attr->priority == MLX5_FLOW_LOWEST_PRIO_INDICATOR)) {
6696 ret = flow_drv_apply(dev, flow, error);
6701 flow_rxq_flags_set(dev, flow);
6702 rte_free(translated_actions);
6703 tunnel = flow_tunnel_from_rule(wks->flows);
6706 flow->tunnel_id = tunnel->tunnel_id;
6707 __atomic_add_fetch(&tunnel->refctn, 1, __ATOMIC_RELAXED);
6708 mlx5_free(default_miss_ctx.queue);
6710 mlx5_flow_pop_thread_workspace();
6714 ret = rte_errno; /* Save rte_errno before cleanup. */
6715 flow_mreg_del_copy_action(dev, flow);
6716 flow_drv_destroy(dev, flow);
6717 if (rss_desc->shared_rss)
6718 __atomic_sub_fetch(&((struct mlx5_shared_action_rss *)
6720 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
6721 rss_desc->shared_rss))->refcnt, 1, __ATOMIC_RELAXED);
6722 mlx5_ipool_free(priv->flows[type], idx);
6723 rte_errno = ret; /* Restore rte_errno. */
6726 mlx5_flow_pop_thread_workspace();
6727 error_before_hairpin_split:
6728 rte_free(translated_actions);
6733 * Create a dedicated flow rule on e-switch table 0 (root table), to direct all
6734 * incoming packets to table 1.
6736 * Other flow rules, requested for group n, will be created in
6737 * e-switch table n+1.
6738 * Jump action to e-switch group n will be created to group n+1.
6740 * Used when working in switchdev mode, to utilise advantages of table 1
6744 * Pointer to Ethernet device.
6747 * Pointer to flow on success, NULL otherwise and rte_errno is set.
6750 mlx5_flow_create_esw_table_zero_flow(struct rte_eth_dev *dev)
6752 const struct rte_flow_attr attr = {
6759 const struct rte_flow_item pattern = {
6760 .type = RTE_FLOW_ITEM_TYPE_END,
6762 struct rte_flow_action_jump jump = {
6765 const struct rte_flow_action actions[] = {
6767 .type = RTE_FLOW_ACTION_TYPE_JUMP,
6771 .type = RTE_FLOW_ACTION_TYPE_END,
6774 struct rte_flow_error error;
6776 return (void *)(uintptr_t)flow_list_create(dev, MLX5_FLOW_TYPE_CTL,
6778 actions, false, &error);
6782 * Create a dedicated flow rule on e-switch table 1, matches ESW manager
6783 * and sq number, directs all packets to peer vport.
6786 * Pointer to Ethernet device.
6791 * Flow ID on success, 0 otherwise and rte_errno is set.
6794 mlx5_flow_create_devx_sq_miss_flow(struct rte_eth_dev *dev, uint32_t txq)
6796 struct rte_flow_attr attr = {
6798 .priority = MLX5_FLOW_LOWEST_PRIO_INDICATOR,
6803 struct rte_flow_item_port_id port_spec = {
6804 .id = MLX5_PORT_ESW_MGR,
6806 struct mlx5_rte_flow_item_tx_queue txq_spec = {
6809 struct rte_flow_item pattern[] = {
6811 .type = RTE_FLOW_ITEM_TYPE_PORT_ID,
6815 .type = (enum rte_flow_item_type)
6816 MLX5_RTE_FLOW_ITEM_TYPE_TX_QUEUE,
6820 .type = RTE_FLOW_ITEM_TYPE_END,
6823 struct rte_flow_action_jump jump = {
6826 struct rte_flow_action_port_id port = {
6827 .id = dev->data->port_id,
6829 struct rte_flow_action actions[] = {
6831 .type = RTE_FLOW_ACTION_TYPE_JUMP,
6835 .type = RTE_FLOW_ACTION_TYPE_END,
6838 struct rte_flow_error error;
6841 * Creates group 0, highest priority jump flow.
6842 * Matches txq to bypass kernel packets.
6844 if (flow_list_create(dev, MLX5_FLOW_TYPE_CTL, &attr, pattern, actions,
6845 false, &error) == 0)
6847 /* Create group 1, lowest priority redirect flow for txq. */
6849 actions[0].conf = &port;
6850 actions[0].type = RTE_FLOW_ACTION_TYPE_PORT_ID;
6851 return flow_list_create(dev, MLX5_FLOW_TYPE_CTL, &attr, pattern,
6852 actions, false, &error);
6856 * Validate a flow supported by the NIC.
6858 * @see rte_flow_validate()
6862 mlx5_flow_validate(struct rte_eth_dev *dev,
6863 const struct rte_flow_attr *attr,
6864 const struct rte_flow_item items[],
6865 const struct rte_flow_action original_actions[],
6866 struct rte_flow_error *error)
6869 struct mlx5_translated_action_handle
6870 indir_actions[MLX5_MAX_INDIRECT_ACTIONS];
6871 int indir_actions_n = MLX5_MAX_INDIRECT_ACTIONS;
6872 const struct rte_flow_action *actions;
6873 struct rte_flow_action *translated_actions = NULL;
6874 int ret = flow_action_handles_translate(dev, original_actions,
6877 &translated_actions, error);
6881 actions = translated_actions ? translated_actions : original_actions;
6882 hairpin_flow = flow_check_hairpin_split(dev, attr, actions);
6883 ret = flow_drv_validate(dev, attr, items, actions,
6884 true, hairpin_flow, error);
6885 rte_free(translated_actions);
6892 * @see rte_flow_create()
6896 mlx5_flow_create(struct rte_eth_dev *dev,
6897 const struct rte_flow_attr *attr,
6898 const struct rte_flow_item items[],
6899 const struct rte_flow_action actions[],
6900 struct rte_flow_error *error)
6902 struct mlx5_priv *priv = dev->data->dev_private;
6904 if (priv->sh->config.dv_flow_en == 2) {
6905 rte_flow_error_set(error, ENOTSUP,
6906 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6908 "Flow non-Q creation not supported");
6912 * If the device is not started yet, it is not allowed to created a
6913 * flow from application. PMD default flows and traffic control flows
6916 if (unlikely(!dev->data->dev_started)) {
6917 DRV_LOG(DEBUG, "port %u is not started when "
6918 "inserting a flow", dev->data->port_id);
6919 rte_flow_error_set(error, ENODEV,
6920 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6922 "port not started");
6926 return (void *)(uintptr_t)flow_list_create(dev, MLX5_FLOW_TYPE_GEN,
6927 attr, items, actions,
6932 * Destroy a flow in a list.
6935 * Pointer to Ethernet device.
6936 * @param[in] flow_idx
6937 * Index of flow to destroy.
6940 flow_list_destroy(struct rte_eth_dev *dev, enum mlx5_flow_type type,
6943 struct mlx5_priv *priv = dev->data->dev_private;
6944 struct rte_flow *flow = mlx5_ipool_get(priv->flows[type], flow_idx);
6948 MLX5_ASSERT(flow->type == type);
6950 * Update RX queue flags only if port is started, otherwise it is
6953 if (dev->data->dev_started)
6954 flow_rxq_flags_trim(dev, flow);
6955 flow_drv_destroy(dev, flow);
6957 struct mlx5_flow_tunnel *tunnel;
6959 tunnel = mlx5_find_tunnel_id(dev, flow->tunnel_id);
6961 if (!__atomic_sub_fetch(&tunnel->refctn, 1, __ATOMIC_RELAXED))
6962 mlx5_flow_tunnel_free(dev, tunnel);
6964 flow_mreg_del_copy_action(dev, flow);
6965 mlx5_ipool_free(priv->flows[type], flow_idx);
6969 * Destroy all flows.
6972 * Pointer to Ethernet device.
6974 * Flow type to be flushed.
6976 * If flushing is called actively.
6979 mlx5_flow_list_flush(struct rte_eth_dev *dev, enum mlx5_flow_type type,
6982 struct mlx5_priv *priv = dev->data->dev_private;
6983 uint32_t num_flushed = 0, fidx = 1;
6984 struct rte_flow *flow;
6986 MLX5_IPOOL_FOREACH(priv->flows[type], fidx, flow) {
6987 flow_list_destroy(dev, type, fidx);
6991 DRV_LOG(INFO, "port %u: %u flows flushed before stopping",
6992 dev->data->port_id, num_flushed);
6997 * Stop all default actions for flows.
7000 * Pointer to Ethernet device.
7003 mlx5_flow_stop_default(struct rte_eth_dev *dev)
7005 flow_mreg_del_default_copy_action(dev);
7006 flow_rxq_flags_clear(dev);
7010 * Start all default actions for flows.
7013 * Pointer to Ethernet device.
7015 * 0 on success, a negative errno value otherwise and rte_errno is set.
7018 mlx5_flow_start_default(struct rte_eth_dev *dev)
7020 struct rte_flow_error error;
7022 /* Make sure default copy action (reg_c[0] -> reg_b) is created. */
7023 return flow_mreg_add_default_copy_action(dev, &error);
7027 * Release key of thread specific flow workspace data.
7030 flow_release_workspace(void *data)
7032 struct mlx5_flow_workspace *wks = data;
7033 struct mlx5_flow_workspace *next;
7037 free(wks->rss_desc.queue);
7044 * Get thread specific current flow workspace.
7046 * @return pointer to thread specific flow workspace data, NULL on error.
7048 struct mlx5_flow_workspace*
7049 mlx5_flow_get_thread_workspace(void)
7051 struct mlx5_flow_workspace *data;
7053 data = mlx5_flow_os_get_specific_workspace();
7054 MLX5_ASSERT(data && data->inuse);
7055 if (!data || !data->inuse)
7056 DRV_LOG(ERR, "flow workspace not initialized.");
7061 * Allocate and init new flow workspace.
7063 * @return pointer to flow workspace data, NULL on error.
7065 static struct mlx5_flow_workspace*
7066 flow_alloc_thread_workspace(void)
7068 struct mlx5_flow_workspace *data = calloc(1, sizeof(*data));
7071 DRV_LOG(ERR, "Failed to allocate flow workspace "
7075 data->rss_desc.queue = calloc(1,
7076 sizeof(uint16_t) * MLX5_RSSQ_DEFAULT_NUM);
7077 if (!data->rss_desc.queue)
7079 data->rssq_num = MLX5_RSSQ_DEFAULT_NUM;
7082 free(data->rss_desc.queue);
7088 * Get new thread specific flow workspace.
7090 * If current workspace inuse, create new one and set as current.
7092 * @return pointer to thread specific flow workspace data, NULL on error.
7094 static struct mlx5_flow_workspace*
7095 mlx5_flow_push_thread_workspace(void)
7097 struct mlx5_flow_workspace *curr;
7098 struct mlx5_flow_workspace *data;
7100 curr = mlx5_flow_os_get_specific_workspace();
7102 data = flow_alloc_thread_workspace();
7105 } else if (!curr->inuse) {
7107 } else if (curr->next) {
7110 data = flow_alloc_thread_workspace();
7118 /* Set as current workspace */
7119 if (mlx5_flow_os_set_specific_workspace(data))
7120 DRV_LOG(ERR, "Failed to set flow workspace to thread.");
7125 * Close current thread specific flow workspace.
7127 * If previous workspace available, set it as current.
7129 * @return pointer to thread specific flow workspace data, NULL on error.
7132 mlx5_flow_pop_thread_workspace(void)
7134 struct mlx5_flow_workspace *data = mlx5_flow_get_thread_workspace();
7139 DRV_LOG(ERR, "Failed to close unused flow workspace.");
7145 if (mlx5_flow_os_set_specific_workspace(data->prev))
7146 DRV_LOG(ERR, "Failed to set flow workspace to thread.");
7150 * Verify the flow list is empty
7153 * Pointer to Ethernet device.
7155 * @return the number of flows not released.
7158 mlx5_flow_verify(struct rte_eth_dev *dev __rte_unused)
7160 struct mlx5_priv *priv = dev->data->dev_private;
7161 struct rte_flow *flow;
7165 for (i = 0; i < MLX5_FLOW_TYPE_MAXI; i++) {
7166 MLX5_IPOOL_FOREACH(priv->flows[i], idx, flow) {
7167 DRV_LOG(DEBUG, "port %u flow %p still referenced",
7168 dev->data->port_id, (void *)flow);
7176 * Enable default hairpin egress flow.
7179 * Pointer to Ethernet device.
7184 * 0 on success, a negative errno value otherwise and rte_errno is set.
7187 mlx5_ctrl_flow_source_queue(struct rte_eth_dev *dev,
7190 const struct rte_flow_attr attr = {
7194 struct mlx5_rte_flow_item_tx_queue queue_spec = {
7197 struct mlx5_rte_flow_item_tx_queue queue_mask = {
7198 .queue = UINT32_MAX,
7200 struct rte_flow_item items[] = {
7202 .type = (enum rte_flow_item_type)
7203 MLX5_RTE_FLOW_ITEM_TYPE_TX_QUEUE,
7204 .spec = &queue_spec,
7206 .mask = &queue_mask,
7209 .type = RTE_FLOW_ITEM_TYPE_END,
7212 struct rte_flow_action_jump jump = {
7213 .group = MLX5_HAIRPIN_TX_TABLE,
7215 struct rte_flow_action actions[2];
7217 struct rte_flow_error error;
7219 actions[0].type = RTE_FLOW_ACTION_TYPE_JUMP;
7220 actions[0].conf = &jump;
7221 actions[1].type = RTE_FLOW_ACTION_TYPE_END;
7222 flow_idx = flow_list_create(dev, MLX5_FLOW_TYPE_CTL,
7223 &attr, items, actions, false, &error);
7226 "Failed to create ctrl flow: rte_errno(%d),"
7227 " type(%d), message(%s)",
7228 rte_errno, error.type,
7229 error.message ? error.message : " (no stated reason)");
7236 * Enable a control flow configured from the control plane.
7239 * Pointer to Ethernet device.
7241 * An Ethernet flow spec to apply.
7243 * An Ethernet flow mask to apply.
7245 * A VLAN flow spec to apply.
7247 * A VLAN flow mask to apply.
7250 * 0 on success, a negative errno value otherwise and rte_errno is set.
7253 mlx5_ctrl_flow_vlan(struct rte_eth_dev *dev,
7254 struct rte_flow_item_eth *eth_spec,
7255 struct rte_flow_item_eth *eth_mask,
7256 struct rte_flow_item_vlan *vlan_spec,
7257 struct rte_flow_item_vlan *vlan_mask)
7259 struct mlx5_priv *priv = dev->data->dev_private;
7260 const struct rte_flow_attr attr = {
7262 .priority = MLX5_FLOW_LOWEST_PRIO_INDICATOR,
7264 struct rte_flow_item items[] = {
7266 .type = RTE_FLOW_ITEM_TYPE_ETH,
7272 .type = (vlan_spec) ? RTE_FLOW_ITEM_TYPE_VLAN :
7273 RTE_FLOW_ITEM_TYPE_END,
7279 .type = RTE_FLOW_ITEM_TYPE_END,
7282 uint16_t queue[priv->reta_idx_n];
7283 struct rte_flow_action_rss action_rss = {
7284 .func = RTE_ETH_HASH_FUNCTION_DEFAULT,
7286 .types = priv->rss_conf.rss_hf,
7287 .key_len = priv->rss_conf.rss_key_len,
7288 .queue_num = priv->reta_idx_n,
7289 .key = priv->rss_conf.rss_key,
7292 struct rte_flow_action actions[] = {
7294 .type = RTE_FLOW_ACTION_TYPE_RSS,
7295 .conf = &action_rss,
7298 .type = RTE_FLOW_ACTION_TYPE_END,
7302 struct rte_flow_error error;
7305 if (!priv->reta_idx_n || !priv->rxqs_n) {
7308 if (!(dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_RSS_FLAG))
7309 action_rss.types = 0;
7310 for (i = 0; i != priv->reta_idx_n; ++i)
7311 queue[i] = (*priv->reta_idx)[i];
7312 flow_idx = flow_list_create(dev, MLX5_FLOW_TYPE_CTL,
7313 &attr, items, actions, false, &error);
7320 * Enable a flow control configured from the control plane.
7323 * Pointer to Ethernet device.
7325 * An Ethernet flow spec to apply.
7327 * An Ethernet flow mask to apply.
7330 * 0 on success, a negative errno value otherwise and rte_errno is set.
7333 mlx5_ctrl_flow(struct rte_eth_dev *dev,
7334 struct rte_flow_item_eth *eth_spec,
7335 struct rte_flow_item_eth *eth_mask)
7337 return mlx5_ctrl_flow_vlan(dev, eth_spec, eth_mask, NULL, NULL);
7341 * Create default miss flow rule matching lacp traffic
7344 * Pointer to Ethernet device.
7346 * An Ethernet flow spec to apply.
7349 * 0 on success, a negative errno value otherwise and rte_errno is set.
7352 mlx5_flow_lacp_miss(struct rte_eth_dev *dev)
7355 * The LACP matching is done by only using ether type since using
7356 * a multicast dst mac causes kernel to give low priority to this flow.
7358 static const struct rte_flow_item_eth lacp_spec = {
7359 .type = RTE_BE16(0x8809),
7361 static const struct rte_flow_item_eth lacp_mask = {
7364 const struct rte_flow_attr attr = {
7367 struct rte_flow_item items[] = {
7369 .type = RTE_FLOW_ITEM_TYPE_ETH,
7374 .type = RTE_FLOW_ITEM_TYPE_END,
7377 struct rte_flow_action actions[] = {
7379 .type = (enum rte_flow_action_type)
7380 MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS,
7383 .type = RTE_FLOW_ACTION_TYPE_END,
7386 struct rte_flow_error error;
7387 uint32_t flow_idx = flow_list_create(dev, MLX5_FLOW_TYPE_CTL,
7388 &attr, items, actions,
7399 * @see rte_flow_destroy()
7403 mlx5_flow_destroy(struct rte_eth_dev *dev,
7404 struct rte_flow *flow,
7405 struct rte_flow_error *error __rte_unused)
7407 struct mlx5_priv *priv = dev->data->dev_private;
7409 if (priv->sh->config.dv_flow_en == 2)
7410 return rte_flow_error_set(error, ENOTSUP,
7411 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7413 "Flow non-Q destruction not supported");
7414 flow_list_destroy(dev, MLX5_FLOW_TYPE_GEN,
7415 (uintptr_t)(void *)flow);
7420 * Destroy all flows.
7422 * @see rte_flow_flush()
7426 mlx5_flow_flush(struct rte_eth_dev *dev,
7427 struct rte_flow_error *error __rte_unused)
7429 mlx5_flow_list_flush(dev, MLX5_FLOW_TYPE_GEN, false);
7436 * @see rte_flow_isolate()
7440 mlx5_flow_isolate(struct rte_eth_dev *dev,
7442 struct rte_flow_error *error)
7444 struct mlx5_priv *priv = dev->data->dev_private;
7446 if (dev->data->dev_started) {
7447 rte_flow_error_set(error, EBUSY,
7448 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7450 "port must be stopped first");
7453 priv->isolated = !!enable;
7455 dev->dev_ops = &mlx5_dev_ops_isolate;
7457 dev->dev_ops = &mlx5_dev_ops;
7459 dev->rx_descriptor_status = mlx5_rx_descriptor_status;
7460 dev->tx_descriptor_status = mlx5_tx_descriptor_status;
7468 * @see rte_flow_query()
7472 flow_drv_query(struct rte_eth_dev *dev,
7474 const struct rte_flow_action *actions,
7476 struct rte_flow_error *error)
7478 struct mlx5_priv *priv = dev->data->dev_private;
7479 const struct mlx5_flow_driver_ops *fops;
7480 struct rte_flow *flow = mlx5_ipool_get(priv->flows[MLX5_FLOW_TYPE_GEN],
7482 enum mlx5_flow_drv_type ftype;
7485 return rte_flow_error_set(error, ENOENT,
7486 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7488 "invalid flow handle");
7490 ftype = flow->drv_type;
7491 MLX5_ASSERT(ftype > MLX5_FLOW_TYPE_MIN && ftype < MLX5_FLOW_TYPE_MAX);
7492 fops = flow_get_drv_ops(ftype);
7494 return fops->query(dev, flow, actions, data, error);
7500 * @see rte_flow_query()
7504 mlx5_flow_query(struct rte_eth_dev *dev,
7505 struct rte_flow *flow,
7506 const struct rte_flow_action *actions,
7508 struct rte_flow_error *error)
7511 struct mlx5_priv *priv = dev->data->dev_private;
7513 if (priv->sh->config.dv_flow_en == 2)
7514 return rte_flow_error_set(error, ENOTSUP,
7515 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7517 "Flow non-Q query not supported");
7518 ret = flow_drv_query(dev, (uintptr_t)(void *)flow, actions, data,
7526 * Get rte_flow callbacks.
7529 * Pointer to Ethernet device structure.
7531 * Pointer to operation-specific structure.
7536 mlx5_flow_ops_get(struct rte_eth_dev *dev __rte_unused,
7537 const struct rte_flow_ops **ops)
7539 *ops = &mlx5_flow_ops;
7544 * Validate meter policy actions.
7545 * Dispatcher for action type specific validation.
7548 * Pointer to the Ethernet device structure.
7550 * The meter policy action object to validate.
7552 * Attributes of flow to determine steering domain.
7553 * @param[out] is_rss
7555 * @param[out] domain_bitmap
7557 * @param[out] is_def_policy
7558 * Is default policy or not.
7560 * Perform verbose error reporting if not NULL. Initialized in case of
7564 * 0 on success, otherwise negative errno value.
7567 mlx5_flow_validate_mtr_acts(struct rte_eth_dev *dev,
7568 const struct rte_flow_action *actions[RTE_COLORS],
7569 struct rte_flow_attr *attr,
7571 uint8_t *domain_bitmap,
7572 uint8_t *policy_mode,
7573 struct rte_mtr_error *error)
7575 const struct mlx5_flow_driver_ops *fops;
7577 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7578 return fops->validate_mtr_acts(dev, actions, attr, is_rss,
7579 domain_bitmap, policy_mode, error);
7583 * Destroy the meter table set.
7586 * Pointer to Ethernet device.
7587 * @param[in] mtr_policy
7588 * Meter policy struct.
7591 mlx5_flow_destroy_mtr_acts(struct rte_eth_dev *dev,
7592 struct mlx5_flow_meter_policy *mtr_policy)
7594 const struct mlx5_flow_driver_ops *fops;
7596 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7597 fops->destroy_mtr_acts(dev, mtr_policy);
7601 * Create policy action, lock free,
7602 * (mutex should be acquired by caller).
7603 * Dispatcher for action type specific call.
7606 * Pointer to the Ethernet device structure.
7607 * @param[in] mtr_policy
7608 * Meter policy struct.
7610 * Action specification used to create meter actions.
7612 * Perform verbose error reporting if not NULL. Initialized in case of
7616 * 0 on success, otherwise negative errno value.
7619 mlx5_flow_create_mtr_acts(struct rte_eth_dev *dev,
7620 struct mlx5_flow_meter_policy *mtr_policy,
7621 const struct rte_flow_action *actions[RTE_COLORS],
7622 struct rte_mtr_error *error)
7624 const struct mlx5_flow_driver_ops *fops;
7626 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7627 return fops->create_mtr_acts(dev, mtr_policy, actions, error);
7631 * Create policy rules, lock free,
7632 * (mutex should be acquired by caller).
7633 * Dispatcher for action type specific call.
7636 * Pointer to the Ethernet device structure.
7637 * @param[in] mtr_policy
7638 * Meter policy struct.
7641 * 0 on success, -1 otherwise.
7644 mlx5_flow_create_policy_rules(struct rte_eth_dev *dev,
7645 struct mlx5_flow_meter_policy *mtr_policy)
7647 const struct mlx5_flow_driver_ops *fops;
7649 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7650 return fops->create_policy_rules(dev, mtr_policy);
7654 * Destroy policy rules, lock free,
7655 * (mutex should be acquired by caller).
7656 * Dispatcher for action type specific call.
7659 * Pointer to the Ethernet device structure.
7660 * @param[in] mtr_policy
7661 * Meter policy struct.
7664 mlx5_flow_destroy_policy_rules(struct rte_eth_dev *dev,
7665 struct mlx5_flow_meter_policy *mtr_policy)
7667 const struct mlx5_flow_driver_ops *fops;
7669 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7670 fops->destroy_policy_rules(dev, mtr_policy);
7674 * Destroy the default policy table set.
7677 * Pointer to Ethernet device.
7680 mlx5_flow_destroy_def_policy(struct rte_eth_dev *dev)
7682 const struct mlx5_flow_driver_ops *fops;
7684 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7685 fops->destroy_def_policy(dev);
7689 * Destroy the default policy table set.
7692 * Pointer to Ethernet device.
7695 * 0 on success, -1 otherwise.
7698 mlx5_flow_create_def_policy(struct rte_eth_dev *dev)
7700 const struct mlx5_flow_driver_ops *fops;
7702 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7703 return fops->create_def_policy(dev);
7707 * Create the needed meter and suffix tables.
7710 * Pointer to Ethernet device.
7713 * 0 on success, -1 otherwise.
7716 mlx5_flow_create_mtr_tbls(struct rte_eth_dev *dev,
7717 struct mlx5_flow_meter_info *fm,
7719 uint8_t domain_bitmap)
7721 const struct mlx5_flow_driver_ops *fops;
7723 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7724 return fops->create_mtr_tbls(dev, fm, mtr_idx, domain_bitmap);
7728 * Destroy the meter table set.
7731 * Pointer to Ethernet device.
7733 * Pointer to the meter table set.
7736 mlx5_flow_destroy_mtr_tbls(struct rte_eth_dev *dev,
7737 struct mlx5_flow_meter_info *fm)
7739 const struct mlx5_flow_driver_ops *fops;
7741 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7742 fops->destroy_mtr_tbls(dev, fm);
7746 * Destroy the global meter drop table.
7749 * Pointer to Ethernet device.
7752 mlx5_flow_destroy_mtr_drop_tbls(struct rte_eth_dev *dev)
7754 const struct mlx5_flow_driver_ops *fops;
7756 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7757 fops->destroy_mtr_drop_tbls(dev);
7761 * Destroy the sub policy table with RX queue.
7764 * Pointer to Ethernet device.
7765 * @param[in] mtr_policy
7766 * Pointer to meter policy table.
7769 mlx5_flow_destroy_sub_policy_with_rxq(struct rte_eth_dev *dev,
7770 struct mlx5_flow_meter_policy *mtr_policy)
7772 const struct mlx5_flow_driver_ops *fops;
7774 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7775 fops->destroy_sub_policy_with_rxq(dev, mtr_policy);
7779 * Allocate the needed aso flow meter id.
7782 * Pointer to Ethernet device.
7785 * Index to aso flow meter on success, NULL otherwise.
7788 mlx5_flow_mtr_alloc(struct rte_eth_dev *dev)
7790 const struct mlx5_flow_driver_ops *fops;
7792 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7793 return fops->create_meter(dev);
7797 * Free the aso flow meter id.
7800 * Pointer to Ethernet device.
7801 * @param[in] mtr_idx
7802 * Index to aso flow meter to be free.
7808 mlx5_flow_mtr_free(struct rte_eth_dev *dev, uint32_t mtr_idx)
7810 const struct mlx5_flow_driver_ops *fops;
7812 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7813 fops->free_meter(dev, mtr_idx);
7817 * Allocate a counter.
7820 * Pointer to Ethernet device structure.
7823 * Index to allocated counter on success, 0 otherwise.
7826 mlx5_counter_alloc(struct rte_eth_dev *dev)
7828 const struct mlx5_flow_driver_ops *fops;
7829 struct rte_flow_attr attr = { .transfer = 0 };
7831 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
7832 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7833 return fops->counter_alloc(dev);
7836 "port %u counter allocate is not supported.",
7837 dev->data->port_id);
7845 * Pointer to Ethernet device structure.
7847 * Index to counter to be free.
7850 mlx5_counter_free(struct rte_eth_dev *dev, uint32_t cnt)
7852 const struct mlx5_flow_driver_ops *fops;
7853 struct rte_flow_attr attr = { .transfer = 0 };
7855 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
7856 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7857 fops->counter_free(dev, cnt);
7861 "port %u counter free is not supported.",
7862 dev->data->port_id);
7866 * Query counter statistics.
7869 * Pointer to Ethernet device structure.
7871 * Index to counter to query.
7873 * Set to clear counter statistics.
7875 * The counter hits packets number to save.
7877 * The counter hits bytes number to save.
7880 * 0 on success, a negative errno value otherwise.
7883 mlx5_counter_query(struct rte_eth_dev *dev, uint32_t cnt,
7884 bool clear, uint64_t *pkts, uint64_t *bytes, void **action)
7886 const struct mlx5_flow_driver_ops *fops;
7887 struct rte_flow_attr attr = { .transfer = 0 };
7889 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
7890 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7891 return fops->counter_query(dev, cnt, clear, pkts,
7895 "port %u counter query is not supported.",
7896 dev->data->port_id);
7901 * Get information about HWS pre-configurable resources.
7904 * Pointer to the rte_eth_dev structure.
7905 * @param[out] port_info
7906 * Pointer to port information.
7907 * @param[out] queue_info
7908 * Pointer to queue information.
7910 * Pointer to error structure.
7913 * 0 on success, a negative errno value otherwise and rte_errno is set.
7916 mlx5_flow_info_get(struct rte_eth_dev *dev,
7917 struct rte_flow_port_info *port_info,
7918 struct rte_flow_queue_info *queue_info,
7919 struct rte_flow_error *error)
7921 const struct mlx5_flow_driver_ops *fops;
7923 if (flow_get_drv_type(dev, NULL) != MLX5_FLOW_TYPE_HW)
7924 return rte_flow_error_set(error, ENOTSUP,
7925 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7927 "info get with incorrect steering mode");
7928 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
7929 return fops->info_get(dev, port_info, queue_info, error);
7933 * Configure port HWS resources.
7936 * Pointer to the rte_eth_dev structure.
7937 * @param[in] port_attr
7938 * Port configuration attributes.
7939 * @param[in] nb_queue
7941 * @param[in] queue_attr
7942 * Array that holds attributes for each flow queue.
7944 * Pointer to error structure.
7947 * 0 on success, a negative errno value otherwise and rte_errno is set.
7950 mlx5_flow_port_configure(struct rte_eth_dev *dev,
7951 const struct rte_flow_port_attr *port_attr,
7953 const struct rte_flow_queue_attr *queue_attr[],
7954 struct rte_flow_error *error)
7956 const struct mlx5_flow_driver_ops *fops;
7958 if (flow_get_drv_type(dev, NULL) != MLX5_FLOW_TYPE_HW)
7959 return rte_flow_error_set(error, ENOTSUP,
7960 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7962 "port configure with incorrect steering mode");
7963 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
7964 return fops->configure(dev, port_attr, nb_queue, queue_attr, error);
7968 * Create flow item template.
7971 * Pointer to the rte_eth_dev structure.
7973 * Pointer to the item template attributes.
7975 * The template item pattern.
7977 * Pointer to error structure.
7980 * 0 on success, a negative errno value otherwise and rte_errno is set.
7982 static struct rte_flow_pattern_template *
7983 mlx5_flow_pattern_template_create(struct rte_eth_dev *dev,
7984 const struct rte_flow_pattern_template_attr *attr,
7985 const struct rte_flow_item items[],
7986 struct rte_flow_error *error)
7988 const struct mlx5_flow_driver_ops *fops;
7990 if (flow_get_drv_type(dev, NULL) != MLX5_FLOW_TYPE_HW) {
7991 rte_flow_error_set(error, ENOTSUP,
7992 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7994 "pattern create with incorrect steering mode");
7997 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
7998 return fops->pattern_template_create(dev, attr, items, error);
8002 * Destroy flow item template.
8005 * Pointer to the rte_eth_dev structure.
8006 * @param[in] template
8007 * Pointer to the item template to be destroyed.
8009 * Pointer to error structure.
8012 * 0 on success, a negative errno value otherwise and rte_errno is set.
8015 mlx5_flow_pattern_template_destroy(struct rte_eth_dev *dev,
8016 struct rte_flow_pattern_template *template,
8017 struct rte_flow_error *error)
8019 const struct mlx5_flow_driver_ops *fops;
8021 if (flow_get_drv_type(dev, NULL) != MLX5_FLOW_TYPE_HW)
8022 return rte_flow_error_set(error, ENOTSUP,
8023 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8025 "pattern destroy with incorrect steering mode");
8026 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
8027 return fops->pattern_template_destroy(dev, template, error);
8031 * Create flow item template.
8034 * Pointer to the rte_eth_dev structure.
8036 * Pointer to the action template attributes.
8037 * @param[in] actions
8038 * Associated actions (list terminated by the END action).
8040 * List of actions that marks which of the action's member is constant.
8042 * Pointer to error structure.
8045 * 0 on success, a negative errno value otherwise and rte_errno is set.
8047 static struct rte_flow_actions_template *
8048 mlx5_flow_actions_template_create(struct rte_eth_dev *dev,
8049 const struct rte_flow_actions_template_attr *attr,
8050 const struct rte_flow_action actions[],
8051 const struct rte_flow_action masks[],
8052 struct rte_flow_error *error)
8054 const struct mlx5_flow_driver_ops *fops;
8056 if (flow_get_drv_type(dev, NULL) != MLX5_FLOW_TYPE_HW) {
8057 rte_flow_error_set(error, ENOTSUP,
8058 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8060 "action create with incorrect steering mode");
8063 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
8064 return fops->actions_template_create(dev, attr, actions, masks, error);
8068 * Destroy flow action template.
8071 * Pointer to the rte_eth_dev structure.
8072 * @param[in] template
8073 * Pointer to the action template to be destroyed.
8075 * Pointer to error structure.
8078 * 0 on success, a negative errno value otherwise and rte_errno is set.
8081 mlx5_flow_actions_template_destroy(struct rte_eth_dev *dev,
8082 struct rte_flow_actions_template *template,
8083 struct rte_flow_error *error)
8085 const struct mlx5_flow_driver_ops *fops;
8087 if (flow_get_drv_type(dev, NULL) != MLX5_FLOW_TYPE_HW)
8088 return rte_flow_error_set(error, ENOTSUP,
8089 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8091 "action destroy with incorrect steering mode");
8092 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
8093 return fops->actions_template_destroy(dev, template, error);
8097 * Create flow table.
8100 * Pointer to the rte_eth_dev structure.
8102 * Pointer to the table attributes.
8103 * @param[in] item_templates
8104 * Item template array to be binded to the table.
8105 * @param[in] nb_item_templates
8106 * Number of item template.
8107 * @param[in] action_templates
8108 * Action template array to be binded to the table.
8109 * @param[in] nb_action_templates
8110 * Number of action template.
8112 * Pointer to error structure.
8115 * Table on success, NULL otherwise and rte_errno is set.
8117 static struct rte_flow_template_table *
8118 mlx5_flow_table_create(struct rte_eth_dev *dev,
8119 const struct rte_flow_template_table_attr *attr,
8120 struct rte_flow_pattern_template *item_templates[],
8121 uint8_t nb_item_templates,
8122 struct rte_flow_actions_template *action_templates[],
8123 uint8_t nb_action_templates,
8124 struct rte_flow_error *error)
8126 const struct mlx5_flow_driver_ops *fops;
8128 if (flow_get_drv_type(dev, NULL) != MLX5_FLOW_TYPE_HW) {
8129 rte_flow_error_set(error, ENOTSUP,
8130 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8132 "table create with incorrect steering mode");
8135 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
8136 return fops->template_table_create(dev,
8141 nb_action_templates,
8146 * PMD destroy flow table.
8149 * Pointer to the rte_eth_dev structure.
8151 * Pointer to the table to be destroyed.
8153 * Pointer to error structure.
8156 * 0 on success, a negative errno value otherwise and rte_errno is set.
8159 mlx5_flow_table_destroy(struct rte_eth_dev *dev,
8160 struct rte_flow_template_table *table,
8161 struct rte_flow_error *error)
8163 const struct mlx5_flow_driver_ops *fops;
8165 if (flow_get_drv_type(dev, NULL) != MLX5_FLOW_TYPE_HW)
8166 return rte_flow_error_set(error, ENOTSUP,
8167 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8169 "table destroy with incorrect steering mode");
8170 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
8171 return fops->template_table_destroy(dev, table, error);
8175 * Allocate a new memory for the counter values wrapped by all the needed
8179 * Pointer to mlx5_dev_ctx_shared object.
8182 * 0 on success, a negative errno value otherwise.
8185 mlx5_flow_create_counter_stat_mem_mng(struct mlx5_dev_ctx_shared *sh)
8187 struct mlx5_counter_stats_mem_mng *mem_mng;
8188 volatile struct flow_counter_stats *raw_data;
8189 int raws_n = MLX5_CNT_CONTAINER_RESIZE + MLX5_MAX_PENDING_QUERIES;
8190 int size = (sizeof(struct flow_counter_stats) *
8191 MLX5_COUNTERS_PER_POOL +
8192 sizeof(struct mlx5_counter_stats_raw)) * raws_n +
8193 sizeof(struct mlx5_counter_stats_mem_mng);
8194 size_t pgsize = rte_mem_page_size();
8199 if (pgsize == (size_t)-1) {
8200 DRV_LOG(ERR, "Failed to get mem page size");
8204 mem = mlx5_malloc(MLX5_MEM_ZERO, size, pgsize, SOCKET_ID_ANY);
8209 mem_mng = (struct mlx5_counter_stats_mem_mng *)(mem + size) - 1;
8210 size = sizeof(*raw_data) * MLX5_COUNTERS_PER_POOL * raws_n;
8211 ret = mlx5_os_wrapped_mkey_create(sh->cdev->ctx, sh->cdev->pd,
8212 sh->cdev->pdn, mem, size,
8219 mem_mng->raws = (struct mlx5_counter_stats_raw *)(mem + size);
8220 raw_data = (volatile struct flow_counter_stats *)mem;
8221 for (i = 0; i < raws_n; ++i) {
8222 mem_mng->raws[i].mem_mng = mem_mng;
8223 mem_mng->raws[i].data = raw_data + i * MLX5_COUNTERS_PER_POOL;
8225 for (i = 0; i < MLX5_MAX_PENDING_QUERIES; ++i)
8226 LIST_INSERT_HEAD(&sh->cmng.free_stat_raws,
8227 mem_mng->raws + MLX5_CNT_CONTAINER_RESIZE + i,
8229 LIST_INSERT_HEAD(&sh->cmng.mem_mngs, mem_mng, next);
8230 sh->cmng.mem_mng = mem_mng;
8235 * Set the statistic memory to the new counter pool.
8238 * Pointer to mlx5_dev_ctx_shared object.
8240 * Pointer to the pool to set the statistic memory.
8243 * 0 on success, a negative errno value otherwise.
8246 mlx5_flow_set_counter_stat_mem(struct mlx5_dev_ctx_shared *sh,
8247 struct mlx5_flow_counter_pool *pool)
8249 struct mlx5_flow_counter_mng *cmng = &sh->cmng;
8250 /* Resize statistic memory once used out. */
8251 if (!(pool->index % MLX5_CNT_CONTAINER_RESIZE) &&
8252 mlx5_flow_create_counter_stat_mem_mng(sh)) {
8253 DRV_LOG(ERR, "Cannot resize counter stat mem.");
8256 rte_spinlock_lock(&pool->sl);
8257 pool->raw = cmng->mem_mng->raws + pool->index %
8258 MLX5_CNT_CONTAINER_RESIZE;
8259 rte_spinlock_unlock(&pool->sl);
8260 pool->raw_hw = NULL;
8264 #define MLX5_POOL_QUERY_FREQ_US 1000000
8267 * Set the periodic procedure for triggering asynchronous batch queries for all
8268 * the counter pools.
8271 * Pointer to mlx5_dev_ctx_shared object.
8274 mlx5_set_query_alarm(struct mlx5_dev_ctx_shared *sh)
8276 uint32_t pools_n, us;
8278 pools_n = __atomic_load_n(&sh->cmng.n_valid, __ATOMIC_RELAXED);
8279 us = MLX5_POOL_QUERY_FREQ_US / pools_n;
8280 DRV_LOG(DEBUG, "Set alarm for %u pools each %u us", pools_n, us);
8281 if (rte_eal_alarm_set(us, mlx5_flow_query_alarm, sh)) {
8282 sh->cmng.query_thread_on = 0;
8283 DRV_LOG(ERR, "Cannot reinitialize query alarm");
8285 sh->cmng.query_thread_on = 1;
8290 * The periodic procedure for triggering asynchronous batch queries for all the
8291 * counter pools. This function is probably called by the host thread.
8294 * The parameter for the alarm process.
8297 mlx5_flow_query_alarm(void *arg)
8299 struct mlx5_dev_ctx_shared *sh = arg;
8301 uint16_t pool_index = sh->cmng.pool_index;
8302 struct mlx5_flow_counter_mng *cmng = &sh->cmng;
8303 struct mlx5_flow_counter_pool *pool;
8306 if (sh->cmng.pending_queries >= MLX5_MAX_PENDING_QUERIES)
8308 rte_spinlock_lock(&cmng->pool_update_sl);
8309 pool = cmng->pools[pool_index];
8310 n_valid = cmng->n_valid;
8311 rte_spinlock_unlock(&cmng->pool_update_sl);
8312 /* Set the statistic memory to the new created pool. */
8313 if ((!pool->raw && mlx5_flow_set_counter_stat_mem(sh, pool)))
8316 /* There is a pool query in progress. */
8319 LIST_FIRST(&sh->cmng.free_stat_raws);
8321 /* No free counter statistics raw memory. */
8324 * Identify the counters released between query trigger and query
8325 * handle more efficiently. The counter released in this gap period
8326 * should wait for a new round of query as the new arrived packets
8327 * will not be taken into account.
8330 ret = mlx5_devx_cmd_flow_counter_query(pool->min_dcs, 0,
8331 MLX5_COUNTERS_PER_POOL,
8333 pool->raw_hw->mem_mng->wm.lkey,
8337 (uint64_t)(uintptr_t)pool);
8339 DRV_LOG(ERR, "Failed to trigger asynchronous query for dcs ID"
8340 " %d", pool->min_dcs->id);
8341 pool->raw_hw = NULL;
8344 LIST_REMOVE(pool->raw_hw, next);
8345 sh->cmng.pending_queries++;
8347 if (pool_index >= n_valid)
8350 sh->cmng.pool_index = pool_index;
8351 mlx5_set_query_alarm(sh);
8355 * Check and callback event for new aged flow in the counter pool
8358 * Pointer to mlx5_dev_ctx_shared object.
8360 * Pointer to Current counter pool.
8363 mlx5_flow_aging_check(struct mlx5_dev_ctx_shared *sh,
8364 struct mlx5_flow_counter_pool *pool)
8366 struct mlx5_priv *priv;
8367 struct mlx5_flow_counter *cnt;
8368 struct mlx5_age_info *age_info;
8369 struct mlx5_age_param *age_param;
8370 struct mlx5_counter_stats_raw *cur = pool->raw_hw;
8371 struct mlx5_counter_stats_raw *prev = pool->raw;
8372 const uint64_t curr_time = MLX5_CURR_TIME_SEC;
8373 const uint32_t time_delta = curr_time - pool->time_of_last_age_check;
8374 uint16_t expected = AGE_CANDIDATE;
8377 pool->time_of_last_age_check = curr_time;
8378 for (i = 0; i < MLX5_COUNTERS_PER_POOL; ++i) {
8379 cnt = MLX5_POOL_GET_CNT(pool, i);
8380 age_param = MLX5_CNT_TO_AGE(cnt);
8381 if (__atomic_load_n(&age_param->state,
8382 __ATOMIC_RELAXED) != AGE_CANDIDATE)
8384 if (cur->data[i].hits != prev->data[i].hits) {
8385 __atomic_store_n(&age_param->sec_since_last_hit, 0,
8389 if (__atomic_add_fetch(&age_param->sec_since_last_hit,
8391 __ATOMIC_RELAXED) <= age_param->timeout)
8394 * Hold the lock first, or if between the
8395 * state AGE_TMOUT and tailq operation the
8396 * release happened, the release procedure
8397 * may delete a non-existent tailq node.
8399 priv = rte_eth_devices[age_param->port_id].data->dev_private;
8400 age_info = GET_PORT_AGE_INFO(priv);
8401 rte_spinlock_lock(&age_info->aged_sl);
8402 if (__atomic_compare_exchange_n(&age_param->state, &expected,
8405 __ATOMIC_RELAXED)) {
8406 TAILQ_INSERT_TAIL(&age_info->aged_counters, cnt, next);
8407 MLX5_AGE_SET(age_info, MLX5_AGE_EVENT_NEW);
8409 rte_spinlock_unlock(&age_info->aged_sl);
8411 mlx5_age_event_prepare(sh);
8415 * Handler for the HW respond about ready values from an asynchronous batch
8416 * query. This function is probably called by the host thread.
8419 * The pointer to the shared device context.
8420 * @param[in] async_id
8421 * The Devx async ID.
8423 * The status of the completion.
8426 mlx5_flow_async_pool_query_handle(struct mlx5_dev_ctx_shared *sh,
8427 uint64_t async_id, int status)
8429 struct mlx5_flow_counter_pool *pool =
8430 (struct mlx5_flow_counter_pool *)(uintptr_t)async_id;
8431 struct mlx5_counter_stats_raw *raw_to_free;
8432 uint8_t query_gen = pool->query_gen ^ 1;
8433 struct mlx5_flow_counter_mng *cmng = &sh->cmng;
8434 enum mlx5_counter_type cnt_type =
8435 pool->is_aged ? MLX5_COUNTER_TYPE_AGE :
8436 MLX5_COUNTER_TYPE_ORIGIN;
8438 if (unlikely(status)) {
8439 raw_to_free = pool->raw_hw;
8441 raw_to_free = pool->raw;
8443 mlx5_flow_aging_check(sh, pool);
8444 rte_spinlock_lock(&pool->sl);
8445 pool->raw = pool->raw_hw;
8446 rte_spinlock_unlock(&pool->sl);
8447 /* Be sure the new raw counters data is updated in memory. */
8449 if (!TAILQ_EMPTY(&pool->counters[query_gen])) {
8450 rte_spinlock_lock(&cmng->csl[cnt_type]);
8451 TAILQ_CONCAT(&cmng->counters[cnt_type],
8452 &pool->counters[query_gen], next);
8453 rte_spinlock_unlock(&cmng->csl[cnt_type]);
8456 LIST_INSERT_HEAD(&sh->cmng.free_stat_raws, raw_to_free, next);
8457 pool->raw_hw = NULL;
8458 sh->cmng.pending_queries--;
8462 flow_group_to_table(uint32_t port_id, uint32_t group, uint32_t *table,
8463 const struct flow_grp_info *grp_info,
8464 struct rte_flow_error *error)
8466 if (grp_info->transfer && grp_info->external &&
8467 grp_info->fdb_def_rule) {
8468 if (group == UINT32_MAX)
8469 return rte_flow_error_set
8471 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
8473 "group index not supported");
8478 DRV_LOG(DEBUG, "port %u group=%#x table=%#x", port_id, group, *table);
8483 * Translate the rte_flow group index to HW table value.
8485 * If tunnel offload is disabled, all group ids converted to flow table
8486 * id using the standard method.
8487 * If tunnel offload is enabled, group id can be converted using the
8488 * standard or tunnel conversion method. Group conversion method
8489 * selection depends on flags in `grp_info` parameter:
8490 * - Internal (grp_info.external == 0) groups conversion uses the
8492 * - Group ids in JUMP action converted with the tunnel conversion.
8493 * - Group id in rule attribute conversion depends on a rule type and
8495 * ** non zero group attributes converted with the tunnel method
8496 * ** zero group attribute in non-tunnel rule is converted using the
8497 * standard method - there's only one root table
8498 * ** zero group attribute in steer tunnel rule is converted with the
8499 * standard method - single root table
8500 * ** zero group attribute in match tunnel rule is a special OvS
8501 * case: that value is used for portability reasons. That group
8502 * id is converted with the tunnel conversion method.
8507 * PMD tunnel offload object
8509 * rte_flow group index value.
8512 * @param[in] grp_info
8513 * flags used for conversion
8515 * Pointer to error structure.
8518 * 0 on success, a negative errno value otherwise and rte_errno is set.
8521 mlx5_flow_group_to_table(struct rte_eth_dev *dev,
8522 const struct mlx5_flow_tunnel *tunnel,
8523 uint32_t group, uint32_t *table,
8524 const struct flow_grp_info *grp_info,
8525 struct rte_flow_error *error)
8528 bool standard_translation;
8530 if (!grp_info->skip_scale && grp_info->external &&
8531 group < MLX5_MAX_TABLES_EXTERNAL)
8532 group *= MLX5_FLOW_TABLE_FACTOR;
8533 if (is_tunnel_offload_active(dev)) {
8534 standard_translation = !grp_info->external ||
8535 grp_info->std_tbl_fix;
8537 standard_translation = true;
8540 "port %u group=%u transfer=%d external=%d fdb_def_rule=%d translate=%s",
8541 dev->data->port_id, group, grp_info->transfer,
8542 grp_info->external, grp_info->fdb_def_rule,
8543 standard_translation ? "STANDARD" : "TUNNEL");
8544 if (standard_translation)
8545 ret = flow_group_to_table(dev->data->port_id, group, table,
8548 ret = tunnel_flow_group_to_flow_table(dev, tunnel, group,
8555 * Discover availability of metadata reg_c's.
8557 * Iteratively use test flows to check availability.
8560 * Pointer to the Ethernet device structure.
8563 * 0 on success, a negative errno value otherwise and rte_errno is set.
8566 mlx5_flow_discover_mreg_c(struct rte_eth_dev *dev)
8568 struct mlx5_priv *priv = dev->data->dev_private;
8569 enum modify_reg idx;
8572 /* reg_c[0] and reg_c[1] are reserved. */
8573 priv->sh->flow_mreg_c[n++] = REG_C_0;
8574 priv->sh->flow_mreg_c[n++] = REG_C_1;
8575 /* Discover availability of other reg_c's. */
8576 for (idx = REG_C_2; idx <= REG_C_7; ++idx) {
8577 struct rte_flow_attr attr = {
8578 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
8579 .priority = MLX5_FLOW_LOWEST_PRIO_INDICATOR,
8582 struct rte_flow_item items[] = {
8584 .type = RTE_FLOW_ITEM_TYPE_END,
8587 struct rte_flow_action actions[] = {
8589 .type = (enum rte_flow_action_type)
8590 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
8591 .conf = &(struct mlx5_flow_action_copy_mreg){
8597 .type = RTE_FLOW_ACTION_TYPE_JUMP,
8598 .conf = &(struct rte_flow_action_jump){
8599 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
8603 .type = RTE_FLOW_ACTION_TYPE_END,
8607 struct rte_flow *flow;
8608 struct rte_flow_error error;
8610 if (!priv->sh->config.dv_flow_en)
8612 /* Create internal flow, validation skips copy action. */
8613 flow_idx = flow_list_create(dev, MLX5_FLOW_TYPE_GEN, &attr,
8614 items, actions, false, &error);
8615 flow = mlx5_ipool_get(priv->flows[MLX5_FLOW_TYPE_GEN],
8619 priv->sh->flow_mreg_c[n++] = idx;
8620 flow_list_destroy(dev, MLX5_FLOW_TYPE_GEN, flow_idx);
8622 for (; n < MLX5_MREG_C_NUM; ++n)
8623 priv->sh->flow_mreg_c[n] = REG_NON;
8624 priv->sh->metadata_regc_check_flag = 1;
8629 save_dump_file(const uint8_t *data, uint32_t size,
8630 uint32_t type, uint64_t id, void *arg, FILE *file)
8632 char line[BUF_SIZE];
8635 uint32_t actions_num;
8636 struct rte_flow_query_count *count;
8638 memset(line, 0, BUF_SIZE);
8640 case DR_DUMP_REC_TYPE_PMD_MODIFY_HDR:
8641 actions_num = *(uint32_t *)(arg);
8642 out += snprintf(line + out, BUF_SIZE - out, "%d,0x%" PRIx64 ",%d,",
8643 type, id, actions_num);
8645 case DR_DUMP_REC_TYPE_PMD_PKT_REFORMAT:
8646 out += snprintf(line + out, BUF_SIZE - out, "%d,0x%" PRIx64 ",",
8649 case DR_DUMP_REC_TYPE_PMD_COUNTER:
8650 count = (struct rte_flow_query_count *)arg;
8652 "%d,0x%" PRIx64 ",%" PRIu64 ",%" PRIu64 "\n",
8653 type, id, count->hits, count->bytes);
8659 for (k = 0; k < size; k++) {
8660 /* Make sure we do not overrun the line buffer length. */
8661 if (out >= BUF_SIZE - 4) {
8665 out += snprintf(line + out, BUF_SIZE - out, "%02x",
8668 fprintf(file, "%s\n", line);
8673 mlx5_flow_query_counter(struct rte_eth_dev *dev, struct rte_flow *flow,
8674 struct rte_flow_query_count *count, struct rte_flow_error *error)
8676 struct rte_flow_action action[2];
8677 enum mlx5_flow_drv_type ftype;
8678 const struct mlx5_flow_driver_ops *fops;
8681 return rte_flow_error_set(error, ENOENT,
8682 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8684 "invalid flow handle");
8686 action[0].type = RTE_FLOW_ACTION_TYPE_COUNT;
8687 action[1].type = RTE_FLOW_ACTION_TYPE_END;
8688 if (flow->counter) {
8689 memset(count, 0, sizeof(struct rte_flow_query_count));
8690 ftype = (enum mlx5_flow_drv_type)(flow->drv_type);
8691 MLX5_ASSERT(ftype > MLX5_FLOW_TYPE_MIN &&
8692 ftype < MLX5_FLOW_TYPE_MAX);
8693 fops = flow_get_drv_ops(ftype);
8694 return fops->query(dev, flow, action, count, error);
8699 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
8701 * Dump flow ipool data to file
8704 * The pointer to Ethernet device.
8706 * A pointer to a file for output.
8708 * Perform verbose error reporting if not NULL. PMDs initialize this
8709 * structure in case of error only.
8711 * 0 on success, a negative value otherwise.
8714 mlx5_flow_dev_dump_ipool(struct rte_eth_dev *dev,
8715 struct rte_flow *flow, FILE *file,
8716 struct rte_flow_error *error)
8718 struct mlx5_priv *priv = dev->data->dev_private;
8719 struct mlx5_flow_dv_modify_hdr_resource *modify_hdr;
8720 struct mlx5_flow_dv_encap_decap_resource *encap_decap;
8721 uint32_t handle_idx;
8722 struct mlx5_flow_handle *dh;
8723 struct rte_flow_query_count count;
8724 uint32_t actions_num;
8725 const uint8_t *data;
8729 void *action = NULL;
8732 return rte_flow_error_set(error, ENOENT,
8733 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8735 "invalid flow handle");
8737 handle_idx = flow->dev_handles;
8739 if (flow->counter &&
8740 (!mlx5_counter_query(dev, flow->counter, false,
8741 &count.hits, &count.bytes, &action)) && action) {
8742 id = (uint64_t)(uintptr_t)action;
8743 type = DR_DUMP_REC_TYPE_PMD_COUNTER;
8744 save_dump_file(NULL, 0, type,
8745 id, (void *)&count, file);
8748 while (handle_idx) {
8749 dh = mlx5_ipool_get(priv->sh->ipool
8750 [MLX5_IPOOL_MLX5_FLOW], handle_idx);
8753 handle_idx = dh->next.next;
8755 /* Get modify_hdr and encap_decap buf from ipools. */
8757 modify_hdr = dh->dvh.modify_hdr;
8759 if (dh->dvh.rix_encap_decap) {
8760 encap_decap = mlx5_ipool_get(priv->sh->ipool
8761 [MLX5_IPOOL_DECAP_ENCAP],
8762 dh->dvh.rix_encap_decap);
8765 data = (const uint8_t *)modify_hdr->actions;
8766 size = (size_t)(modify_hdr->actions_num) * 8;
8767 id = (uint64_t)(uintptr_t)modify_hdr->action;
8768 actions_num = modify_hdr->actions_num;
8769 type = DR_DUMP_REC_TYPE_PMD_MODIFY_HDR;
8770 save_dump_file(data, size, type, id,
8771 (void *)(&actions_num), file);
8774 data = encap_decap->buf;
8775 size = encap_decap->size;
8776 id = (uint64_t)(uintptr_t)encap_decap->action;
8777 type = DR_DUMP_REC_TYPE_PMD_PKT_REFORMAT;
8778 save_dump_file(data, size, type,
8786 * Dump all flow's encap_decap/modify_hdr/counter data to file
8789 * The pointer to Ethernet device.
8791 * A pointer to a file for output.
8793 * Perform verbose error reporting if not NULL. PMDs initialize this
8794 * structure in case of error only.
8796 * 0 on success, a negative value otherwise.
8799 mlx5_flow_dev_dump_sh_all(struct rte_eth_dev *dev,
8800 FILE *file, struct rte_flow_error *error __rte_unused)
8802 struct mlx5_priv *priv = dev->data->dev_private;
8803 struct mlx5_dev_ctx_shared *sh = priv->sh;
8804 struct mlx5_hlist *h;
8805 struct mlx5_flow_dv_modify_hdr_resource *modify_hdr;
8806 struct mlx5_flow_dv_encap_decap_resource *encap_decap;
8807 struct rte_flow_query_count count;
8808 uint32_t actions_num;
8809 const uint8_t *data;
8815 struct mlx5_list_inconst *l_inconst;
8816 struct mlx5_list_entry *e;
8818 struct mlx5_flow_counter_mng *cmng = &priv->sh->cmng;
8822 /* encap_decap hlist is lcore_share, get global core cache. */
8823 i = MLX5_LIST_GLOBAL;
8824 h = sh->encaps_decaps;
8826 for (j = 0; j <= h->mask; j++) {
8827 l_inconst = &h->buckets[j].l;
8828 if (!l_inconst || !l_inconst->cache[i])
8831 e = LIST_FIRST(&l_inconst->cache[i]->h);
8834 (struct mlx5_flow_dv_encap_decap_resource *)e;
8835 data = encap_decap->buf;
8836 size = encap_decap->size;
8837 id = (uint64_t)(uintptr_t)encap_decap->action;
8838 type = DR_DUMP_REC_TYPE_PMD_PKT_REFORMAT;
8839 save_dump_file(data, size, type,
8841 e = LIST_NEXT(e, next);
8846 /* get modify_hdr */
8847 h = sh->modify_cmds;
8849 lcore_index = rte_lcore_index(rte_lcore_id());
8850 if (unlikely(lcore_index == -1)) {
8851 lcore_index = MLX5_LIST_NLCORE;
8852 rte_spinlock_lock(&h->l_const.lcore_lock);
8856 for (j = 0; j <= h->mask; j++) {
8857 l_inconst = &h->buckets[j].l;
8858 if (!l_inconst || !l_inconst->cache[i])
8861 e = LIST_FIRST(&l_inconst->cache[i]->h);
8864 (struct mlx5_flow_dv_modify_hdr_resource *)e;
8865 data = (const uint8_t *)modify_hdr->actions;
8866 size = (size_t)(modify_hdr->actions_num) * 8;
8867 actions_num = modify_hdr->actions_num;
8868 id = (uint64_t)(uintptr_t)modify_hdr->action;
8869 type = DR_DUMP_REC_TYPE_PMD_MODIFY_HDR;
8870 save_dump_file(data, size, type, id,
8871 (void *)(&actions_num), file);
8872 e = LIST_NEXT(e, next);
8876 if (unlikely(lcore_index == MLX5_LIST_NLCORE))
8877 rte_spinlock_unlock(&h->l_const.lcore_lock);
8881 MLX5_ASSERT(cmng->n_valid <= cmng->n);
8882 max = MLX5_COUNTERS_PER_POOL * cmng->n_valid;
8883 for (j = 1; j <= max; j++) {
8885 if ((!mlx5_counter_query(dev, j, false, &count.hits,
8886 &count.bytes, &action)) && action) {
8887 id = (uint64_t)(uintptr_t)action;
8888 type = DR_DUMP_REC_TYPE_PMD_COUNTER;
8889 save_dump_file(NULL, 0, type,
8890 id, (void *)&count, file);
8898 * Dump flow raw hw data to file
8901 * The pointer to Ethernet device.
8903 * A pointer to a file for output.
8905 * Perform verbose error reporting if not NULL. PMDs initialize this
8906 * structure in case of error only.
8908 * 0 on success, a negative value otherwise.
8911 mlx5_flow_dev_dump(struct rte_eth_dev *dev, struct rte_flow *flow_idx,
8913 struct rte_flow_error *error __rte_unused)
8915 struct mlx5_priv *priv = dev->data->dev_private;
8916 struct mlx5_dev_ctx_shared *sh = priv->sh;
8917 uint32_t handle_idx;
8919 struct mlx5_flow_handle *dh;
8920 struct rte_flow *flow;
8922 if (!sh->config.dv_flow_en) {
8923 if (fputs("device dv flow disabled\n", file) <= 0)
8930 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
8931 if (mlx5_flow_dev_dump_sh_all(dev, file, error))
8934 return mlx5_devx_cmd_flow_dump(sh->fdb_domain,
8936 sh->tx_domain, file);
8939 flow = mlx5_ipool_get(priv->flows[MLX5_FLOW_TYPE_GEN],
8940 (uintptr_t)(void *)flow_idx);
8944 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
8945 mlx5_flow_dev_dump_ipool(dev, flow, file, error);
8947 handle_idx = flow->dev_handles;
8948 while (handle_idx) {
8949 dh = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
8954 ret = mlx5_devx_cmd_flow_single_dump(dh->drv_flow,
8959 handle_idx = dh->next.next;
8965 * Get aged-out flows.
8968 * Pointer to the Ethernet device structure.
8969 * @param[in] context
8970 * The address of an array of pointers to the aged-out flows contexts.
8971 * @param[in] nb_countexts
8972 * The length of context array pointers.
8974 * Perform verbose error reporting if not NULL. Initialized in case of
8978 * how many contexts get in success, otherwise negative errno value.
8979 * if nb_contexts is 0, return the amount of all aged contexts.
8980 * if nb_contexts is not 0 , return the amount of aged flows reported
8981 * in the context array.
8984 mlx5_flow_get_aged_flows(struct rte_eth_dev *dev, void **contexts,
8985 uint32_t nb_contexts, struct rte_flow_error *error)
8987 const struct mlx5_flow_driver_ops *fops;
8988 struct rte_flow_attr attr = { .transfer = 0 };
8990 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
8991 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
8992 return fops->get_aged_flows(dev, contexts, nb_contexts,
8996 "port %u get aged flows is not supported.",
8997 dev->data->port_id);
9001 /* Wrapper for driver action_validate op callback */
9003 flow_drv_action_validate(struct rte_eth_dev *dev,
9004 const struct rte_flow_indir_action_conf *conf,
9005 const struct rte_flow_action *action,
9006 const struct mlx5_flow_driver_ops *fops,
9007 struct rte_flow_error *error)
9009 static const char err_msg[] = "indirect action validation unsupported";
9011 if (!fops->action_validate) {
9012 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
9013 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
9017 return fops->action_validate(dev, conf, action, error);
9021 * Destroys the shared action by handle.
9024 * Pointer to Ethernet device structure.
9026 * Handle for the indirect action object to be destroyed.
9028 * Perform verbose error reporting if not NULL. PMDs initialize this
9029 * structure in case of error only.
9032 * 0 on success, a negative errno value otherwise and rte_errno is set.
9034 * @note: wrapper for driver action_create op callback.
9037 mlx5_action_handle_destroy(struct rte_eth_dev *dev,
9038 struct rte_flow_action_handle *handle,
9039 struct rte_flow_error *error)
9041 static const char err_msg[] = "indirect action destruction unsupported";
9042 struct rte_flow_attr attr = { .transfer = 0 };
9043 const struct mlx5_flow_driver_ops *fops =
9044 flow_get_drv_ops(flow_get_drv_type(dev, &attr));
9046 if (!fops->action_destroy) {
9047 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
9048 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
9052 return fops->action_destroy(dev, handle, error);
9055 /* Wrapper for driver action_destroy op callback */
9057 flow_drv_action_update(struct rte_eth_dev *dev,
9058 struct rte_flow_action_handle *handle,
9060 const struct mlx5_flow_driver_ops *fops,
9061 struct rte_flow_error *error)
9063 static const char err_msg[] = "indirect action update unsupported";
9065 if (!fops->action_update) {
9066 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
9067 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
9071 return fops->action_update(dev, handle, update, error);
9074 /* Wrapper for driver action_destroy op callback */
9076 flow_drv_action_query(struct rte_eth_dev *dev,
9077 const struct rte_flow_action_handle *handle,
9079 const struct mlx5_flow_driver_ops *fops,
9080 struct rte_flow_error *error)
9082 static const char err_msg[] = "indirect action query unsupported";
9084 if (!fops->action_query) {
9085 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
9086 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
9090 return fops->action_query(dev, handle, data, error);
9094 * Create indirect action for reuse in multiple flow rules.
9097 * Pointer to Ethernet device structure.
9099 * Pointer to indirect action object configuration.
9101 * Action configuration for indirect action object creation.
9103 * Perform verbose error reporting if not NULL. PMDs initialize this
9104 * structure in case of error only.
9106 * A valid handle in case of success, NULL otherwise and rte_errno is set.
9108 static struct rte_flow_action_handle *
9109 mlx5_action_handle_create(struct rte_eth_dev *dev,
9110 const struct rte_flow_indir_action_conf *conf,
9111 const struct rte_flow_action *action,
9112 struct rte_flow_error *error)
9114 static const char err_msg[] = "indirect action creation unsupported";
9115 struct rte_flow_attr attr = { .transfer = 0 };
9116 const struct mlx5_flow_driver_ops *fops =
9117 flow_get_drv_ops(flow_get_drv_type(dev, &attr));
9119 if (flow_drv_action_validate(dev, conf, action, fops, error))
9121 if (!fops->action_create) {
9122 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
9123 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
9127 return fops->action_create(dev, conf, action, error);
9131 * Updates inplace the indirect action configuration pointed by *handle*
9132 * with the configuration provided as *update* argument.
9133 * The update of the indirect action configuration effects all flow rules
9134 * reusing the action via handle.
9137 * Pointer to Ethernet device structure.
9139 * Handle for the indirect action to be updated.
9141 * Action specification used to modify the action pointed by handle.
9142 * *update* could be of same type with the action pointed by the *handle*
9143 * handle argument, or some other structures like a wrapper, depending on
9144 * the indirect action type.
9146 * Perform verbose error reporting if not NULL. PMDs initialize this
9147 * structure in case of error only.
9150 * 0 on success, a negative errno value otherwise and rte_errno is set.
9153 mlx5_action_handle_update(struct rte_eth_dev *dev,
9154 struct rte_flow_action_handle *handle,
9156 struct rte_flow_error *error)
9158 struct rte_flow_attr attr = { .transfer = 0 };
9159 const struct mlx5_flow_driver_ops *fops =
9160 flow_get_drv_ops(flow_get_drv_type(dev, &attr));
9163 ret = flow_drv_action_validate(dev, NULL,
9164 (const struct rte_flow_action *)update, fops, error);
9167 return flow_drv_action_update(dev, handle, update, fops,
9172 * Query the indirect action by handle.
9174 * This function allows retrieving action-specific data such as counters.
9175 * Data is gathered by special action which may be present/referenced in
9176 * more than one flow rule definition.
9178 * see @RTE_FLOW_ACTION_TYPE_COUNT
9181 * Pointer to Ethernet device structure.
9183 * Handle for the indirect action to query.
9184 * @param[in, out] data
9185 * Pointer to storage for the associated query data type.
9187 * Perform verbose error reporting if not NULL. PMDs initialize this
9188 * structure in case of error only.
9191 * 0 on success, a negative errno value otherwise and rte_errno is set.
9194 mlx5_action_handle_query(struct rte_eth_dev *dev,
9195 const struct rte_flow_action_handle *handle,
9197 struct rte_flow_error *error)
9199 struct rte_flow_attr attr = { .transfer = 0 };
9200 const struct mlx5_flow_driver_ops *fops =
9201 flow_get_drv_ops(flow_get_drv_type(dev, &attr));
9203 return flow_drv_action_query(dev, handle, data, fops, error);
9207 * Destroy all indirect actions (shared RSS).
9210 * Pointer to Ethernet device.
9213 * 0 on success, a negative errno value otherwise and rte_errno is set.
9216 mlx5_action_handle_flush(struct rte_eth_dev *dev)
9218 struct rte_flow_error error;
9219 struct mlx5_priv *priv = dev->data->dev_private;
9220 struct mlx5_shared_action_rss *shared_rss;
9224 ILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
9225 priv->rss_shared_actions, idx, shared_rss, next) {
9226 ret |= mlx5_action_handle_destroy(dev,
9227 (struct rte_flow_action_handle *)(uintptr_t)idx, &error);
9233 * Validate existing indirect actions against current device configuration
9234 * and attach them to device resources.
9237 * Pointer to Ethernet device.
9240 * 0 on success, a negative errno value otherwise and rte_errno is set.
9243 mlx5_action_handle_attach(struct rte_eth_dev *dev)
9245 struct mlx5_priv *priv = dev->data->dev_private;
9246 struct mlx5_indexed_pool *ipool =
9247 priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS];
9248 struct mlx5_shared_action_rss *shared_rss, *shared_rss_last;
9252 ILIST_FOREACH(ipool, priv->rss_shared_actions, idx, shared_rss, next) {
9253 struct mlx5_ind_table_obj *ind_tbl = shared_rss->ind_tbl;
9254 const char *message;
9257 ret = mlx5_validate_rss_queues(dev, ind_tbl->queues,
9259 &message, &queue_idx);
9261 DRV_LOG(ERR, "Port %u cannot use queue %u in RSS: %s",
9262 dev->data->port_id, ind_tbl->queues[queue_idx],
9269 ILIST_FOREACH(ipool, priv->rss_shared_actions, idx, shared_rss, next) {
9270 struct mlx5_ind_table_obj *ind_tbl = shared_rss->ind_tbl;
9272 ret = mlx5_ind_table_obj_attach(dev, ind_tbl);
9274 DRV_LOG(ERR, "Port %u could not attach "
9275 "indirection table obj %p",
9276 dev->data->port_id, (void *)ind_tbl);
9282 shared_rss_last = shared_rss;
9283 ILIST_FOREACH(ipool, priv->rss_shared_actions, idx, shared_rss, next) {
9284 struct mlx5_ind_table_obj *ind_tbl = shared_rss->ind_tbl;
9286 if (shared_rss == shared_rss_last)
9288 if (mlx5_ind_table_obj_detach(dev, ind_tbl) != 0)
9289 DRV_LOG(CRIT, "Port %u could not detach "
9290 "indirection table obj %p on rollback",
9291 dev->data->port_id, (void *)ind_tbl);
9297 * Detach indirect actions of the device from its resources.
9300 * Pointer to Ethernet device.
9303 * 0 on success, a negative errno value otherwise and rte_errno is set.
9306 mlx5_action_handle_detach(struct rte_eth_dev *dev)
9308 struct mlx5_priv *priv = dev->data->dev_private;
9309 struct mlx5_indexed_pool *ipool =
9310 priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS];
9311 struct mlx5_shared_action_rss *shared_rss, *shared_rss_last;
9315 ILIST_FOREACH(ipool, priv->rss_shared_actions, idx, shared_rss, next) {
9316 struct mlx5_ind_table_obj *ind_tbl = shared_rss->ind_tbl;
9318 ret = mlx5_ind_table_obj_detach(dev, ind_tbl);
9320 DRV_LOG(ERR, "Port %u could not detach "
9321 "indirection table obj %p",
9322 dev->data->port_id, (void *)ind_tbl);
9328 shared_rss_last = shared_rss;
9329 ILIST_FOREACH(ipool, priv->rss_shared_actions, idx, shared_rss, next) {
9330 struct mlx5_ind_table_obj *ind_tbl = shared_rss->ind_tbl;
9332 if (shared_rss == shared_rss_last)
9334 if (mlx5_ind_table_obj_attach(dev, ind_tbl) != 0)
9335 DRV_LOG(CRIT, "Port %u could not attach "
9336 "indirection table obj %p on rollback",
9337 dev->data->port_id, (void *)ind_tbl);
9342 #ifndef HAVE_MLX5DV_DR
9343 #define MLX5_DOMAIN_SYNC_FLOW ((1 << 0) | (1 << 1))
9345 #define MLX5_DOMAIN_SYNC_FLOW \
9346 (MLX5DV_DR_DOMAIN_SYNC_FLAGS_SW | MLX5DV_DR_DOMAIN_SYNC_FLAGS_HW)
9349 int rte_pmd_mlx5_sync_flow(uint16_t port_id, uint32_t domains)
9351 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
9352 const struct mlx5_flow_driver_ops *fops;
9354 struct rte_flow_attr attr = { .transfer = 0 };
9356 fops = flow_get_drv_ops(flow_get_drv_type(dev, &attr));
9357 ret = fops->sync_domain(dev, domains, MLX5_DOMAIN_SYNC_FLOW);
9363 const struct mlx5_flow_tunnel *
9364 mlx5_get_tof(const struct rte_flow_item *item,
9365 const struct rte_flow_action *action,
9366 enum mlx5_tof_rule_type *rule_type)
9368 for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
9369 if (item->type == (typeof(item->type))
9370 MLX5_RTE_FLOW_ITEM_TYPE_TUNNEL) {
9371 *rule_type = MLX5_TUNNEL_OFFLOAD_MATCH_RULE;
9372 return flow_items_to_tunnel(item);
9375 for (; action->conf != RTE_FLOW_ACTION_TYPE_END; action++) {
9376 if (action->type == (typeof(action->type))
9377 MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET) {
9378 *rule_type = MLX5_TUNNEL_OFFLOAD_SET_RULE;
9379 return flow_actions_to_tunnel(action);
9386 * tunnel offload functionality is defined for DV environment only
9388 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
9390 union tunnel_offload_mark {
9393 uint32_t app_reserve:8;
9394 uint32_t table_id:15;
9395 uint32_t transfer:1;
9396 uint32_t _unused_:8;
9401 mlx5_access_tunnel_offload_db
9402 (struct rte_eth_dev *dev,
9403 bool (*match)(struct rte_eth_dev *,
9404 struct mlx5_flow_tunnel *, const void *),
9405 void (*hit)(struct rte_eth_dev *, struct mlx5_flow_tunnel *, void *),
9406 void (*miss)(struct rte_eth_dev *, void *),
9407 void *ctx, bool lock_op);
9410 flow_tunnel_add_default_miss(struct rte_eth_dev *dev,
9411 struct rte_flow *flow,
9412 const struct rte_flow_attr *attr,
9413 const struct rte_flow_action *app_actions,
9415 const struct mlx5_flow_tunnel *tunnel,
9416 struct tunnel_default_miss_ctx *ctx,
9417 struct rte_flow_error *error)
9419 struct mlx5_priv *priv = dev->data->dev_private;
9420 struct mlx5_flow *dev_flow;
9421 struct rte_flow_attr miss_attr = *attr;
9422 const struct rte_flow_item miss_items[2] = {
9424 .type = RTE_FLOW_ITEM_TYPE_ETH,
9430 .type = RTE_FLOW_ITEM_TYPE_END,
9436 union tunnel_offload_mark mark_id;
9437 struct rte_flow_action_mark miss_mark;
9438 struct rte_flow_action miss_actions[3] = {
9439 [0] = { .type = RTE_FLOW_ACTION_TYPE_MARK, .conf = &miss_mark },
9440 [2] = { .type = RTE_FLOW_ACTION_TYPE_END, .conf = NULL }
9442 const struct rte_flow_action_jump *jump_data;
9443 uint32_t i, flow_table = 0; /* prevent compilation warning */
9444 struct flow_grp_info grp_info = {
9446 .transfer = attr->transfer,
9447 .fdb_def_rule = !!priv->fdb_def_rule,
9452 if (!attr->transfer) {
9455 miss_actions[1].type = RTE_FLOW_ACTION_TYPE_RSS;
9456 q_size = priv->reta_idx_n * sizeof(ctx->queue[0]);
9457 ctx->queue = mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO, q_size,
9460 return rte_flow_error_set
9462 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
9463 NULL, "invalid default miss RSS");
9464 ctx->action_rss.func = RTE_ETH_HASH_FUNCTION_DEFAULT,
9465 ctx->action_rss.level = 0,
9466 ctx->action_rss.types = priv->rss_conf.rss_hf,
9467 ctx->action_rss.key_len = priv->rss_conf.rss_key_len,
9468 ctx->action_rss.queue_num = priv->reta_idx_n,
9469 ctx->action_rss.key = priv->rss_conf.rss_key,
9470 ctx->action_rss.queue = ctx->queue;
9471 if (!priv->reta_idx_n || !priv->rxqs_n)
9472 return rte_flow_error_set
9474 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
9475 NULL, "invalid port configuration");
9476 if (!(dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_RSS_FLAG))
9477 ctx->action_rss.types = 0;
9478 for (i = 0; i != priv->reta_idx_n; ++i)
9479 ctx->queue[i] = (*priv->reta_idx)[i];
9481 miss_actions[1].type = RTE_FLOW_ACTION_TYPE_JUMP;
9482 ctx->miss_jump.group = MLX5_TNL_MISS_FDB_JUMP_GRP;
9484 miss_actions[1].conf = (typeof(miss_actions[1].conf))ctx->raw;
9485 for (; app_actions->type != RTE_FLOW_ACTION_TYPE_JUMP; app_actions++);
9486 jump_data = app_actions->conf;
9487 miss_attr.priority = MLX5_TNL_MISS_RULE_PRIORITY;
9488 miss_attr.group = jump_data->group;
9489 ret = mlx5_flow_group_to_table(dev, tunnel, jump_data->group,
9490 &flow_table, &grp_info, error);
9492 return rte_flow_error_set(error, EINVAL,
9493 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
9494 NULL, "invalid tunnel id");
9495 mark_id.app_reserve = 0;
9496 mark_id.table_id = tunnel_flow_tbl_to_id(flow_table);
9497 mark_id.transfer = !!attr->transfer;
9498 mark_id._unused_ = 0;
9499 miss_mark.id = mark_id.val;
9500 dev_flow = flow_drv_prepare(dev, flow, &miss_attr,
9501 miss_items, miss_actions, flow_idx, error);
9504 dev_flow->flow = flow;
9505 dev_flow->external = true;
9506 dev_flow->tunnel = tunnel;
9507 dev_flow->tof_type = MLX5_TUNNEL_OFFLOAD_MISS_RULE;
9508 /* Subflow object was created, we must include one in the list. */
9509 SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
9510 dev_flow->handle, next);
9512 "port %u tunnel type=%d id=%u miss rule priority=%u group=%u",
9513 dev->data->port_id, tunnel->app_tunnel.type,
9514 tunnel->tunnel_id, miss_attr.priority, miss_attr.group);
9515 ret = flow_drv_translate(dev, dev_flow, &miss_attr, miss_items,
9516 miss_actions, error);
9518 ret = flow_mreg_update_copy_table(dev, flow, miss_actions,
9524 static const struct mlx5_flow_tbl_data_entry *
9525 tunnel_mark_decode(struct rte_eth_dev *dev, uint32_t mark)
9527 struct mlx5_priv *priv = dev->data->dev_private;
9528 struct mlx5_dev_ctx_shared *sh = priv->sh;
9529 struct mlx5_list_entry *he;
9530 union tunnel_offload_mark mbits = { .val = mark };
9531 union mlx5_flow_tbl_key table_key = {
9533 .level = tunnel_id_to_flow_tbl(mbits.table_id),
9537 .is_fdb = !!mbits.transfer,
9541 struct mlx5_flow_cb_ctx ctx = {
9542 .data = &table_key.v64,
9545 he = mlx5_hlist_lookup(sh->flow_tbls, table_key.v64, &ctx);
9547 container_of(he, struct mlx5_flow_tbl_data_entry, entry) : NULL;
9551 mlx5_flow_tunnel_grp2tbl_remove_cb(void *tool_ctx,
9552 struct mlx5_list_entry *entry)
9554 struct mlx5_dev_ctx_shared *sh = tool_ctx;
9555 struct tunnel_tbl_entry *tte = container_of(entry, typeof(*tte), hash);
9557 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TNL_TBL_ID],
9558 tunnel_flow_tbl_to_id(tte->flow_table));
9563 mlx5_flow_tunnel_grp2tbl_match_cb(void *tool_ctx __rte_unused,
9564 struct mlx5_list_entry *entry, void *cb_ctx)
9566 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
9567 union tunnel_tbl_key tbl = {
9568 .val = *(uint64_t *)(ctx->data),
9570 struct tunnel_tbl_entry *tte = container_of(entry, typeof(*tte), hash);
9572 return tbl.tunnel_id != tte->tunnel_id || tbl.group != tte->group;
9575 static struct mlx5_list_entry *
9576 mlx5_flow_tunnel_grp2tbl_create_cb(void *tool_ctx, void *cb_ctx)
9578 struct mlx5_dev_ctx_shared *sh = tool_ctx;
9579 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
9580 struct tunnel_tbl_entry *tte;
9581 union tunnel_tbl_key tbl = {
9582 .val = *(uint64_t *)(ctx->data),
9585 tte = mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO,
9590 mlx5_ipool_malloc(sh->ipool[MLX5_IPOOL_TNL_TBL_ID],
9592 if (tte->flow_table >= MLX5_MAX_TABLES) {
9593 DRV_LOG(ERR, "Tunnel TBL ID %d exceed max limit.",
9595 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TNL_TBL_ID],
9598 } else if (!tte->flow_table) {
9601 tte->flow_table = tunnel_id_to_flow_tbl(tte->flow_table);
9602 tte->tunnel_id = tbl.tunnel_id;
9603 tte->group = tbl.group;
9611 static struct mlx5_list_entry *
9612 mlx5_flow_tunnel_grp2tbl_clone_cb(void *tool_ctx __rte_unused,
9613 struct mlx5_list_entry *oentry,
9614 void *cb_ctx __rte_unused)
9616 struct tunnel_tbl_entry *tte = mlx5_malloc(MLX5_MEM_SYS, sizeof(*tte),
9621 memcpy(tte, oentry, sizeof(*tte));
9626 mlx5_flow_tunnel_grp2tbl_clone_free_cb(void *tool_ctx __rte_unused,
9627 struct mlx5_list_entry *entry)
9629 struct tunnel_tbl_entry *tte = container_of(entry, typeof(*tte), hash);
9635 tunnel_flow_group_to_flow_table(struct rte_eth_dev *dev,
9636 const struct mlx5_flow_tunnel *tunnel,
9637 uint32_t group, uint32_t *table,
9638 struct rte_flow_error *error)
9640 struct mlx5_list_entry *he;
9641 struct tunnel_tbl_entry *tte;
9642 union tunnel_tbl_key key = {
9643 .tunnel_id = tunnel ? tunnel->tunnel_id : 0,
9646 struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
9647 struct mlx5_hlist *group_hash;
9648 struct mlx5_flow_cb_ctx ctx = {
9652 group_hash = tunnel ? tunnel->groups : thub->groups;
9653 he = mlx5_hlist_register(group_hash, key.val, &ctx);
9655 return rte_flow_error_set(error, EINVAL,
9656 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
9658 "tunnel group index not supported");
9659 tte = container_of(he, typeof(*tte), hash);
9660 *table = tte->flow_table;
9661 DRV_LOG(DEBUG, "port %u tunnel %u group=%#x table=%#x",
9662 dev->data->port_id, key.tunnel_id, group, *table);
9667 mlx5_flow_tunnel_free(struct rte_eth_dev *dev,
9668 struct mlx5_flow_tunnel *tunnel)
9670 struct mlx5_priv *priv = dev->data->dev_private;
9671 struct mlx5_indexed_pool *ipool;
9673 DRV_LOG(DEBUG, "port %u release pmd tunnel id=0x%x",
9674 dev->data->port_id, tunnel->tunnel_id);
9675 LIST_REMOVE(tunnel, chain);
9676 mlx5_hlist_destroy(tunnel->groups);
9677 ipool = priv->sh->ipool[MLX5_IPOOL_TUNNEL_ID];
9678 mlx5_ipool_free(ipool, tunnel->tunnel_id);
9682 mlx5_access_tunnel_offload_db
9683 (struct rte_eth_dev *dev,
9684 bool (*match)(struct rte_eth_dev *,
9685 struct mlx5_flow_tunnel *, const void *),
9686 void (*hit)(struct rte_eth_dev *, struct mlx5_flow_tunnel *, void *),
9687 void (*miss)(struct rte_eth_dev *, void *),
9688 void *ctx, bool lock_op)
9690 bool verdict = false;
9691 struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
9692 struct mlx5_flow_tunnel *tunnel;
9694 rte_spinlock_lock(&thub->sl);
9695 LIST_FOREACH(tunnel, &thub->tunnels, chain) {
9696 verdict = match(dev, tunnel, (const void *)ctx);
9701 rte_spinlock_unlock(&thub->sl);
9703 hit(dev, tunnel, ctx);
9704 if (!verdict && miss)
9707 rte_spinlock_unlock(&thub->sl);
9712 struct tunnel_db_find_tunnel_id_ctx {
9714 struct mlx5_flow_tunnel *tunnel;
9718 find_tunnel_id_match(struct rte_eth_dev *dev,
9719 struct mlx5_flow_tunnel *tunnel, const void *x)
9721 const struct tunnel_db_find_tunnel_id_ctx *ctx = x;
9724 return tunnel->tunnel_id == ctx->tunnel_id;
9728 find_tunnel_id_hit(struct rte_eth_dev *dev,
9729 struct mlx5_flow_tunnel *tunnel, void *x)
9731 struct tunnel_db_find_tunnel_id_ctx *ctx = x;
9733 ctx->tunnel = tunnel;
9736 static struct mlx5_flow_tunnel *
9737 mlx5_find_tunnel_id(struct rte_eth_dev *dev, uint32_t id)
9739 struct tunnel_db_find_tunnel_id_ctx ctx = {
9743 mlx5_access_tunnel_offload_db(dev, find_tunnel_id_match,
9744 find_tunnel_id_hit, NULL, &ctx, true);
9749 static struct mlx5_flow_tunnel *
9750 mlx5_flow_tunnel_allocate(struct rte_eth_dev *dev,
9751 const struct rte_flow_tunnel *app_tunnel)
9753 struct mlx5_priv *priv = dev->data->dev_private;
9754 struct mlx5_indexed_pool *ipool;
9755 struct mlx5_flow_tunnel *tunnel;
9758 ipool = priv->sh->ipool[MLX5_IPOOL_TUNNEL_ID];
9759 tunnel = mlx5_ipool_zmalloc(ipool, &id);
9762 if (id >= MLX5_MAX_TUNNELS) {
9763 mlx5_ipool_free(ipool, id);
9764 DRV_LOG(ERR, "Tunnel ID %d exceed max limit.", id);
9767 tunnel->groups = mlx5_hlist_create("tunnel groups", 64, false, true,
9769 mlx5_flow_tunnel_grp2tbl_create_cb,
9770 mlx5_flow_tunnel_grp2tbl_match_cb,
9771 mlx5_flow_tunnel_grp2tbl_remove_cb,
9772 mlx5_flow_tunnel_grp2tbl_clone_cb,
9773 mlx5_flow_tunnel_grp2tbl_clone_free_cb);
9774 if (!tunnel->groups) {
9775 mlx5_ipool_free(ipool, id);
9778 /* initiate new PMD tunnel */
9779 memcpy(&tunnel->app_tunnel, app_tunnel, sizeof(*app_tunnel));
9780 tunnel->tunnel_id = id;
9781 tunnel->action.type = (typeof(tunnel->action.type))
9782 MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET;
9783 tunnel->action.conf = tunnel;
9784 tunnel->item.type = (typeof(tunnel->item.type))
9785 MLX5_RTE_FLOW_ITEM_TYPE_TUNNEL;
9786 tunnel->item.spec = tunnel;
9787 tunnel->item.last = NULL;
9788 tunnel->item.mask = NULL;
9790 DRV_LOG(DEBUG, "port %u new pmd tunnel id=0x%x",
9791 dev->data->port_id, tunnel->tunnel_id);
9796 struct tunnel_db_get_tunnel_ctx {
9797 const struct rte_flow_tunnel *app_tunnel;
9798 struct mlx5_flow_tunnel *tunnel;
9801 static bool get_tunnel_match(struct rte_eth_dev *dev,
9802 struct mlx5_flow_tunnel *tunnel, const void *x)
9804 const struct tunnel_db_get_tunnel_ctx *ctx = x;
9807 return !memcmp(ctx->app_tunnel, &tunnel->app_tunnel,
9808 sizeof(*ctx->app_tunnel));
9811 static void get_tunnel_hit(struct rte_eth_dev *dev,
9812 struct mlx5_flow_tunnel *tunnel, void *x)
9814 /* called under tunnel spinlock protection */
9815 struct tunnel_db_get_tunnel_ctx *ctx = x;
9819 ctx->tunnel = tunnel;
9822 static void get_tunnel_miss(struct rte_eth_dev *dev, void *x)
9824 /* called under tunnel spinlock protection */
9825 struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
9826 struct tunnel_db_get_tunnel_ctx *ctx = x;
9828 rte_spinlock_unlock(&thub->sl);
9829 ctx->tunnel = mlx5_flow_tunnel_allocate(dev, ctx->app_tunnel);
9830 rte_spinlock_lock(&thub->sl);
9832 ctx->tunnel->refctn = 1;
9833 LIST_INSERT_HEAD(&thub->tunnels, ctx->tunnel, chain);
9839 mlx5_get_flow_tunnel(struct rte_eth_dev *dev,
9840 const struct rte_flow_tunnel *app_tunnel,
9841 struct mlx5_flow_tunnel **tunnel)
9843 struct tunnel_db_get_tunnel_ctx ctx = {
9844 .app_tunnel = app_tunnel,
9847 mlx5_access_tunnel_offload_db(dev, get_tunnel_match, get_tunnel_hit,
9848 get_tunnel_miss, &ctx, true);
9849 *tunnel = ctx.tunnel;
9850 return ctx.tunnel ? 0 : -ENOMEM;
9853 void mlx5_release_tunnel_hub(struct mlx5_dev_ctx_shared *sh, uint16_t port_id)
9855 struct mlx5_flow_tunnel_hub *thub = sh->tunnel_hub;
9859 if (!LIST_EMPTY(&thub->tunnels))
9860 DRV_LOG(WARNING, "port %u tunnels present", port_id);
9861 mlx5_hlist_destroy(thub->groups);
9865 int mlx5_alloc_tunnel_hub(struct mlx5_dev_ctx_shared *sh)
9868 struct mlx5_flow_tunnel_hub *thub;
9870 thub = mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO, sizeof(*thub),
9874 LIST_INIT(&thub->tunnels);
9875 rte_spinlock_init(&thub->sl);
9876 thub->groups = mlx5_hlist_create("flow groups", 64,
9878 mlx5_flow_tunnel_grp2tbl_create_cb,
9879 mlx5_flow_tunnel_grp2tbl_match_cb,
9880 mlx5_flow_tunnel_grp2tbl_remove_cb,
9881 mlx5_flow_tunnel_grp2tbl_clone_cb,
9882 mlx5_flow_tunnel_grp2tbl_clone_free_cb);
9883 if (!thub->groups) {
9887 sh->tunnel_hub = thub;
9893 mlx5_hlist_destroy(thub->groups);
9900 mlx5_flow_tunnel_validate(struct rte_eth_dev *dev,
9901 struct rte_flow_tunnel *tunnel,
9902 struct rte_flow_error *error)
9904 struct mlx5_priv *priv = dev->data->dev_private;
9906 if (!priv->sh->config.dv_flow_en)
9907 return rte_flow_error_set(error, ENOTSUP,
9908 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
9909 "flow DV interface is off");
9910 if (!is_tunnel_offload_active(dev))
9911 return rte_flow_error_set(error, ENOTSUP,
9912 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
9913 "tunnel offload was not activated");
9915 return rte_flow_error_set(error, EINVAL,
9916 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
9917 "no application tunnel");
9918 switch (tunnel->type) {
9920 return rte_flow_error_set(error, EINVAL,
9921 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
9922 "unsupported tunnel type");
9923 case RTE_FLOW_ITEM_TYPE_VXLAN:
9924 case RTE_FLOW_ITEM_TYPE_GRE:
9925 case RTE_FLOW_ITEM_TYPE_NVGRE:
9926 case RTE_FLOW_ITEM_TYPE_GENEVE:
9933 mlx5_flow_tunnel_decap_set(struct rte_eth_dev *dev,
9934 struct rte_flow_tunnel *app_tunnel,
9935 struct rte_flow_action **actions,
9936 uint32_t *num_of_actions,
9937 struct rte_flow_error *error)
9939 struct mlx5_flow_tunnel *tunnel;
9940 int ret = mlx5_flow_tunnel_validate(dev, app_tunnel, error);
9944 ret = mlx5_get_flow_tunnel(dev, app_tunnel, &tunnel);
9946 return rte_flow_error_set(error, ret,
9947 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
9948 "failed to initialize pmd tunnel");
9950 *actions = &tunnel->action;
9951 *num_of_actions = 1;
9956 mlx5_flow_tunnel_match(struct rte_eth_dev *dev,
9957 struct rte_flow_tunnel *app_tunnel,
9958 struct rte_flow_item **items,
9959 uint32_t *num_of_items,
9960 struct rte_flow_error *error)
9962 struct mlx5_flow_tunnel *tunnel;
9963 int ret = mlx5_flow_tunnel_validate(dev, app_tunnel, error);
9967 ret = mlx5_get_flow_tunnel(dev, app_tunnel, &tunnel);
9969 return rte_flow_error_set(error, ret,
9970 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
9971 "failed to initialize pmd tunnel");
9973 *items = &tunnel->item;
9978 struct tunnel_db_element_release_ctx {
9979 struct rte_flow_item *items;
9980 struct rte_flow_action *actions;
9981 uint32_t num_elements;
9982 struct rte_flow_error *error;
9987 tunnel_element_release_match(struct rte_eth_dev *dev,
9988 struct mlx5_flow_tunnel *tunnel, const void *x)
9990 const struct tunnel_db_element_release_ctx *ctx = x;
9993 if (ctx->num_elements != 1)
9995 else if (ctx->items)
9996 return ctx->items == &tunnel->item;
9997 else if (ctx->actions)
9998 return ctx->actions == &tunnel->action;
10004 tunnel_element_release_hit(struct rte_eth_dev *dev,
10005 struct mlx5_flow_tunnel *tunnel, void *x)
10007 struct tunnel_db_element_release_ctx *ctx = x;
10009 if (!__atomic_sub_fetch(&tunnel->refctn, 1, __ATOMIC_RELAXED))
10010 mlx5_flow_tunnel_free(dev, tunnel);
10014 tunnel_element_release_miss(struct rte_eth_dev *dev, void *x)
10016 struct tunnel_db_element_release_ctx *ctx = x;
10018 ctx->ret = rte_flow_error_set(ctx->error, EINVAL,
10019 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
10020 "invalid argument");
10024 mlx5_flow_tunnel_item_release(struct rte_eth_dev *dev,
10025 struct rte_flow_item *pmd_items,
10026 uint32_t num_items, struct rte_flow_error *err)
10028 struct tunnel_db_element_release_ctx ctx = {
10029 .items = pmd_items,
10031 .num_elements = num_items,
10035 mlx5_access_tunnel_offload_db(dev, tunnel_element_release_match,
10036 tunnel_element_release_hit,
10037 tunnel_element_release_miss, &ctx, false);
10043 mlx5_flow_tunnel_action_release(struct rte_eth_dev *dev,
10044 struct rte_flow_action *pmd_actions,
10045 uint32_t num_actions, struct rte_flow_error *err)
10047 struct tunnel_db_element_release_ctx ctx = {
10049 .actions = pmd_actions,
10050 .num_elements = num_actions,
10054 mlx5_access_tunnel_offload_db(dev, tunnel_element_release_match,
10055 tunnel_element_release_hit,
10056 tunnel_element_release_miss, &ctx, false);
10062 mlx5_flow_tunnel_get_restore_info(struct rte_eth_dev *dev,
10063 struct rte_mbuf *m,
10064 struct rte_flow_restore_info *info,
10065 struct rte_flow_error *err)
10067 uint64_t ol_flags = m->ol_flags;
10068 const struct mlx5_flow_tbl_data_entry *tble;
10069 const uint64_t mask = RTE_MBUF_F_RX_FDIR | RTE_MBUF_F_RX_FDIR_ID;
10071 if (!is_tunnel_offload_active(dev)) {
10076 if ((ol_flags & mask) != mask)
10078 tble = tunnel_mark_decode(dev, m->hash.fdir.hi);
10080 DRV_LOG(DEBUG, "port %u invalid miss tunnel mark %#x",
10081 dev->data->port_id, m->hash.fdir.hi);
10084 MLX5_ASSERT(tble->tunnel);
10085 memcpy(&info->tunnel, &tble->tunnel->app_tunnel, sizeof(info->tunnel));
10086 info->group_id = tble->group_id;
10087 info->flags = RTE_FLOW_RESTORE_INFO_TUNNEL |
10088 RTE_FLOW_RESTORE_INFO_GROUP_ID |
10089 RTE_FLOW_RESTORE_INFO_ENCAPSULATED;
10094 return rte_flow_error_set(err, EINVAL,
10095 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10096 "failed to get restore info");
10099 #else /* HAVE_IBV_FLOW_DV_SUPPORT */
10101 mlx5_flow_tunnel_decap_set(__rte_unused struct rte_eth_dev *dev,
10102 __rte_unused struct rte_flow_tunnel *app_tunnel,
10103 __rte_unused struct rte_flow_action **actions,
10104 __rte_unused uint32_t *num_of_actions,
10105 __rte_unused struct rte_flow_error *error)
10111 mlx5_flow_tunnel_match(__rte_unused struct rte_eth_dev *dev,
10112 __rte_unused struct rte_flow_tunnel *app_tunnel,
10113 __rte_unused struct rte_flow_item **items,
10114 __rte_unused uint32_t *num_of_items,
10115 __rte_unused struct rte_flow_error *error)
10121 mlx5_flow_tunnel_item_release(__rte_unused struct rte_eth_dev *dev,
10122 __rte_unused struct rte_flow_item *pmd_items,
10123 __rte_unused uint32_t num_items,
10124 __rte_unused struct rte_flow_error *err)
10130 mlx5_flow_tunnel_action_release(__rte_unused struct rte_eth_dev *dev,
10131 __rte_unused struct rte_flow_action *pmd_action,
10132 __rte_unused uint32_t num_actions,
10133 __rte_unused struct rte_flow_error *err)
10139 mlx5_flow_tunnel_get_restore_info(__rte_unused struct rte_eth_dev *dev,
10140 __rte_unused struct rte_mbuf *m,
10141 __rte_unused struct rte_flow_restore_info *i,
10142 __rte_unused struct rte_flow_error *err)
10148 flow_tunnel_add_default_miss(__rte_unused struct rte_eth_dev *dev,
10149 __rte_unused struct rte_flow *flow,
10150 __rte_unused const struct rte_flow_attr *attr,
10151 __rte_unused const struct rte_flow_action *actions,
10152 __rte_unused uint32_t flow_idx,
10153 __rte_unused const struct mlx5_flow_tunnel *tunnel,
10154 __rte_unused struct tunnel_default_miss_ctx *ctx,
10155 __rte_unused struct rte_flow_error *error)
10160 static struct mlx5_flow_tunnel *
10161 mlx5_find_tunnel_id(__rte_unused struct rte_eth_dev *dev,
10162 __rte_unused uint32_t id)
10168 mlx5_flow_tunnel_free(__rte_unused struct rte_eth_dev *dev,
10169 __rte_unused struct mlx5_flow_tunnel *tunnel)
10174 tunnel_flow_group_to_flow_table(__rte_unused struct rte_eth_dev *dev,
10175 __rte_unused const struct mlx5_flow_tunnel *t,
10176 __rte_unused uint32_t group,
10177 __rte_unused uint32_t *table,
10178 struct rte_flow_error *error)
10180 return rte_flow_error_set(error, ENOTSUP,
10181 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10182 "tunnel offload requires DV support");
10186 mlx5_release_tunnel_hub(__rte_unused struct mlx5_dev_ctx_shared *sh,
10187 __rte_unused uint16_t port_id)
10190 #endif /* HAVE_IBV_FLOW_DV_SUPPORT */
10192 /* Flex flow item API */
10193 static struct rte_flow_item_flex_handle *
10194 mlx5_flow_flex_item_create(struct rte_eth_dev *dev,
10195 const struct rte_flow_item_flex_conf *conf,
10196 struct rte_flow_error *error)
10198 static const char err_msg[] = "flex item creation unsupported";
10199 struct rte_flow_attr attr = { .transfer = 0 };
10200 const struct mlx5_flow_driver_ops *fops =
10201 flow_get_drv_ops(flow_get_drv_type(dev, &attr));
10203 if (!fops->item_create) {
10204 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
10205 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
10209 return fops->item_create(dev, conf, error);
10213 mlx5_flow_flex_item_release(struct rte_eth_dev *dev,
10214 const struct rte_flow_item_flex_handle *handle,
10215 struct rte_flow_error *error)
10217 static const char err_msg[] = "flex item release unsupported";
10218 struct rte_flow_attr attr = { .transfer = 0 };
10219 const struct mlx5_flow_driver_ops *fops =
10220 flow_get_drv_ops(flow_get_drv_type(dev, &attr));
10222 if (!fops->item_release) {
10223 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
10224 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
10228 return fops->item_release(dev, handle, error);
10232 mlx5_dbg__print_pattern(const struct rte_flow_item *item)
10235 struct rte_flow_error error;
10237 for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
10239 ret = rte_flow_conv(RTE_FLOW_CONV_OP_ITEM_NAME_PTR, &item_name,
10241 (void *)(uintptr_t)item->type, &error);
10243 printf("%s ", item_name);
10245 printf("%d\n", (int)item->type);
10251 mlx5_flow_is_std_vxlan_port(const struct rte_flow_item *udp_item)
10253 const struct rte_flow_item_udp *spec = udp_item->spec;
10254 const struct rte_flow_item_udp *mask = udp_item->mask;
10255 uint16_t udp_dport = 0;
10257 if (spec != NULL) {
10259 mask = &rte_flow_item_udp_mask;
10260 udp_dport = rte_be_to_cpu_16(spec->hdr.dst_port &
10261 mask->hdr.dst_port);
10263 return (!udp_dport || udp_dport == MLX5_UDP_PORT_VXLAN);
10266 static const struct mlx5_flow_expand_node *
10267 mlx5_flow_expand_rss_adjust_node(const struct rte_flow_item *pattern,
10268 unsigned int item_idx,
10269 const struct mlx5_flow_expand_node graph[],
10270 const struct mlx5_flow_expand_node *node)
10272 const struct rte_flow_item *item = pattern + item_idx, *prev_item;
10274 if (item->type == RTE_FLOW_ITEM_TYPE_VXLAN &&
10276 node->type == RTE_FLOW_ITEM_TYPE_VXLAN) {
10278 * The expansion node is VXLAN and it is also the last
10279 * expandable item in the pattern, so need to continue
10280 * expansion of the inner tunnel.
10282 MLX5_ASSERT(item_idx > 0);
10283 prev_item = pattern + item_idx - 1;
10284 MLX5_ASSERT(prev_item->type == RTE_FLOW_ITEM_TYPE_UDP);
10285 if (mlx5_flow_is_std_vxlan_port(prev_item))
10286 return &graph[MLX5_EXPANSION_STD_VXLAN];
10287 return &graph[MLX5_EXPANSION_L3_VXLAN];
10292 /* Map of Verbs to Flow priority with 8 Verbs priorities. */
10293 static const uint32_t priority_map_3[][MLX5_PRIORITY_MAP_MAX] = {
10294 { 0, 1, 2 }, { 2, 3, 4 }, { 5, 6, 7 },
10297 /* Map of Verbs to Flow priority with 16 Verbs priorities. */
10298 static const uint32_t priority_map_5[][MLX5_PRIORITY_MAP_MAX] = {
10299 { 0, 1, 2 }, { 3, 4, 5 }, { 6, 7, 8 },
10300 { 9, 10, 11 }, { 12, 13, 14 },
10304 * Discover the number of available flow priorities.
10310 * On success, number of available flow priorities.
10311 * On failure, a negative errno-style code and rte_errno is set.
10314 mlx5_flow_discover_priorities(struct rte_eth_dev *dev)
10316 static const uint16_t vprio[] = {8, 16};
10317 const struct mlx5_priv *priv = dev->data->dev_private;
10318 const struct mlx5_flow_driver_ops *fops;
10319 enum mlx5_flow_drv_type type;
10322 type = mlx5_flow_os_get_type();
10323 if (type == MLX5_FLOW_TYPE_MAX) {
10324 type = MLX5_FLOW_TYPE_VERBS;
10325 if (priv->sh->cdev->config.devx && priv->sh->config.dv_flow_en)
10326 type = MLX5_FLOW_TYPE_DV;
10328 fops = flow_get_drv_ops(type);
10329 if (fops->discover_priorities == NULL) {
10330 DRV_LOG(ERR, "Priority discovery not supported");
10331 rte_errno = ENOTSUP;
10334 ret = fops->discover_priorities(dev, vprio, RTE_DIM(vprio));
10339 ret = RTE_DIM(priority_map_3);
10342 ret = RTE_DIM(priority_map_5);
10345 rte_errno = ENOTSUP;
10347 "port %u maximum priority: %d expected 8/16",
10348 dev->data->port_id, ret);
10351 DRV_LOG(INFO, "port %u supported flow priorities:"
10352 " 0-%d for ingress or egress root table,"
10353 " 0-%d for non-root table or transfer root table.",
10354 dev->data->port_id, ret - 2,
10355 MLX5_NON_ROOT_FLOW_MAX_PRIO - 1);
10360 * Adjust flow priority based on the highest layer and the request priority.
10363 * Pointer to the Ethernet device structure.
10364 * @param[in] priority
10365 * The rule base priority.
10366 * @param[in] subpriority
10367 * The priority based on the items.
10370 * The new priority.
10373 mlx5_flow_adjust_priority(struct rte_eth_dev *dev, int32_t priority,
10374 uint32_t subpriority)
10377 struct mlx5_priv *priv = dev->data->dev_private;
10379 switch (priv->sh->flow_max_priority) {
10380 case RTE_DIM(priority_map_3):
10381 res = priority_map_3[priority][subpriority];
10383 case RTE_DIM(priority_map_5):
10384 res = priority_map_5[priority][subpriority];