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);
853 static struct rte_flow *
854 mlx5_flow_async_flow_create(struct rte_eth_dev *dev,
856 const struct rte_flow_op_attr *attr,
857 struct rte_flow_template_table *table,
858 const struct rte_flow_item items[],
859 uint8_t pattern_template_index,
860 const struct rte_flow_action actions[],
861 uint8_t action_template_index,
863 struct rte_flow_error *error);
865 mlx5_flow_async_flow_destroy(struct rte_eth_dev *dev,
867 const struct rte_flow_op_attr *attr,
868 struct rte_flow *flow,
870 struct rte_flow_error *error);
872 mlx5_flow_pull(struct rte_eth_dev *dev,
874 struct rte_flow_op_result res[],
876 struct rte_flow_error *error);
878 mlx5_flow_push(struct rte_eth_dev *dev,
880 struct rte_flow_error *error);
882 static struct rte_flow_action_handle *
883 mlx5_flow_async_action_handle_create(struct rte_eth_dev *dev, uint32_t queue,
884 const struct rte_flow_op_attr *attr,
885 const struct rte_flow_indir_action_conf *conf,
886 const struct rte_flow_action *action,
888 struct rte_flow_error *error);
891 mlx5_flow_async_action_handle_update(struct rte_eth_dev *dev, uint32_t queue,
892 const struct rte_flow_op_attr *attr,
893 struct rte_flow_action_handle *handle,
896 struct rte_flow_error *error);
899 mlx5_flow_async_action_handle_destroy(struct rte_eth_dev *dev, uint32_t queue,
900 const struct rte_flow_op_attr *attr,
901 struct rte_flow_action_handle *handle,
903 struct rte_flow_error *error);
905 static const struct rte_flow_ops mlx5_flow_ops = {
906 .validate = mlx5_flow_validate,
907 .create = mlx5_flow_create,
908 .destroy = mlx5_flow_destroy,
909 .flush = mlx5_flow_flush,
910 .isolate = mlx5_flow_isolate,
911 .query = mlx5_flow_query,
912 .dev_dump = mlx5_flow_dev_dump,
913 .get_aged_flows = mlx5_flow_get_aged_flows,
914 .action_handle_create = mlx5_action_handle_create,
915 .action_handle_destroy = mlx5_action_handle_destroy,
916 .action_handle_update = mlx5_action_handle_update,
917 .action_handle_query = mlx5_action_handle_query,
918 .tunnel_decap_set = mlx5_flow_tunnel_decap_set,
919 .tunnel_match = mlx5_flow_tunnel_match,
920 .tunnel_action_decap_release = mlx5_flow_tunnel_action_release,
921 .tunnel_item_release = mlx5_flow_tunnel_item_release,
922 .get_restore_info = mlx5_flow_tunnel_get_restore_info,
923 .flex_item_create = mlx5_flow_flex_item_create,
924 .flex_item_release = mlx5_flow_flex_item_release,
925 .info_get = mlx5_flow_info_get,
926 .configure = mlx5_flow_port_configure,
927 .pattern_template_create = mlx5_flow_pattern_template_create,
928 .pattern_template_destroy = mlx5_flow_pattern_template_destroy,
929 .actions_template_create = mlx5_flow_actions_template_create,
930 .actions_template_destroy = mlx5_flow_actions_template_destroy,
931 .template_table_create = mlx5_flow_table_create,
932 .template_table_destroy = mlx5_flow_table_destroy,
933 .async_create = mlx5_flow_async_flow_create,
934 .async_destroy = mlx5_flow_async_flow_destroy,
935 .pull = mlx5_flow_pull,
936 .push = mlx5_flow_push,
937 .async_action_handle_create = mlx5_flow_async_action_handle_create,
938 .async_action_handle_update = mlx5_flow_async_action_handle_update,
939 .async_action_handle_destroy = mlx5_flow_async_action_handle_destroy,
942 /* Tunnel information. */
943 struct mlx5_flow_tunnel_info {
944 uint64_t tunnel; /**< Tunnel bit (see MLX5_FLOW_*). */
945 uint32_t ptype; /**< Tunnel Ptype (see RTE_PTYPE_*). */
948 static struct mlx5_flow_tunnel_info tunnels_info[] = {
950 .tunnel = MLX5_FLOW_LAYER_VXLAN,
951 .ptype = RTE_PTYPE_TUNNEL_VXLAN | RTE_PTYPE_L4_UDP,
954 .tunnel = MLX5_FLOW_LAYER_GENEVE,
955 .ptype = RTE_PTYPE_TUNNEL_GENEVE | RTE_PTYPE_L4_UDP,
958 .tunnel = MLX5_FLOW_LAYER_VXLAN_GPE,
959 .ptype = RTE_PTYPE_TUNNEL_VXLAN_GPE | RTE_PTYPE_L4_UDP,
962 .tunnel = MLX5_FLOW_LAYER_GRE,
963 .ptype = RTE_PTYPE_TUNNEL_GRE,
966 .tunnel = MLX5_FLOW_LAYER_MPLS | MLX5_FLOW_LAYER_OUTER_L4_UDP,
967 .ptype = RTE_PTYPE_TUNNEL_MPLS_IN_UDP | RTE_PTYPE_L4_UDP,
970 .tunnel = MLX5_FLOW_LAYER_MPLS,
971 .ptype = RTE_PTYPE_TUNNEL_MPLS_IN_GRE,
974 .tunnel = MLX5_FLOW_LAYER_NVGRE,
975 .ptype = RTE_PTYPE_TUNNEL_NVGRE,
978 .tunnel = MLX5_FLOW_LAYER_IPIP,
979 .ptype = RTE_PTYPE_TUNNEL_IP,
982 .tunnel = MLX5_FLOW_LAYER_IPV6_ENCAP,
983 .ptype = RTE_PTYPE_TUNNEL_IP,
986 .tunnel = MLX5_FLOW_LAYER_GTP,
987 .ptype = RTE_PTYPE_TUNNEL_GTPU,
994 * Translate tag ID to register.
997 * Pointer to the Ethernet device structure.
999 * The feature that request the register.
1001 * The request register ID.
1003 * Error description in case of any.
1006 * The request register on success, a negative errno
1007 * value otherwise and rte_errno is set.
1010 mlx5_flow_get_reg_id(struct rte_eth_dev *dev,
1011 enum mlx5_feature_name feature,
1013 struct rte_flow_error *error)
1015 struct mlx5_priv *priv = dev->data->dev_private;
1016 struct mlx5_sh_config *config = &priv->sh->config;
1017 enum modify_reg start_reg;
1018 bool skip_mtr_reg = false;
1021 case MLX5_HAIRPIN_RX:
1023 case MLX5_HAIRPIN_TX:
1025 case MLX5_METADATA_RX:
1026 switch (config->dv_xmeta_en) {
1027 case MLX5_XMETA_MODE_LEGACY:
1029 case MLX5_XMETA_MODE_META16:
1031 case MLX5_XMETA_MODE_META32:
1035 case MLX5_METADATA_TX:
1037 case MLX5_METADATA_FDB:
1038 switch (config->dv_xmeta_en) {
1039 case MLX5_XMETA_MODE_LEGACY:
1041 case MLX5_XMETA_MODE_META16:
1043 case MLX5_XMETA_MODE_META32:
1047 case MLX5_FLOW_MARK:
1048 switch (config->dv_xmeta_en) {
1049 case MLX5_XMETA_MODE_LEGACY:
1051 case MLX5_XMETA_MODE_META16:
1053 case MLX5_XMETA_MODE_META32:
1059 * If meter color and meter id share one register, flow match
1060 * should use the meter color register for match.
1062 if (priv->mtr_reg_share)
1063 return priv->mtr_color_reg;
1065 return priv->mtr_color_reg != REG_C_2 ? REG_C_2 :
1067 case MLX5_MTR_COLOR:
1068 case MLX5_ASO_FLOW_HIT:
1069 case MLX5_ASO_CONNTRACK:
1070 case MLX5_SAMPLE_ID:
1071 /* All features use the same REG_C. */
1072 MLX5_ASSERT(priv->mtr_color_reg != REG_NON);
1073 return priv->mtr_color_reg;
1074 case MLX5_COPY_MARK:
1076 * Metadata COPY_MARK register using is in meter suffix sub
1077 * flow while with meter. It's safe to share the same register.
1079 return priv->mtr_color_reg != REG_C_2 ? REG_C_2 : REG_C_3;
1082 * If meter is enable, it will engage the register for color
1083 * match and flow match. If meter color match is not using the
1084 * REG_C_2, need to skip the REG_C_x be used by meter color
1086 * If meter is disable, free to use all available registers.
1088 start_reg = priv->mtr_color_reg != REG_C_2 ? REG_C_2 :
1089 (priv->mtr_reg_share ? REG_C_3 : REG_C_4);
1090 skip_mtr_reg = !!(priv->mtr_en && start_reg == REG_C_2);
1091 if (id > (uint32_t)(REG_C_7 - start_reg))
1092 return rte_flow_error_set(error, EINVAL,
1093 RTE_FLOW_ERROR_TYPE_ITEM,
1094 NULL, "invalid tag id");
1095 if (priv->sh->flow_mreg_c[id + start_reg - REG_C_0] == REG_NON)
1096 return rte_flow_error_set(error, ENOTSUP,
1097 RTE_FLOW_ERROR_TYPE_ITEM,
1098 NULL, "unsupported tag id");
1100 * This case means meter is using the REG_C_x great than 2.
1101 * Take care not to conflict with meter color REG_C_x.
1102 * If the available index REG_C_y >= REG_C_x, skip the
1105 if (skip_mtr_reg && priv->sh->flow_mreg_c
1106 [id + start_reg - REG_C_0] >= priv->mtr_color_reg) {
1107 if (id >= (uint32_t)(REG_C_7 - start_reg))
1108 return rte_flow_error_set(error, EINVAL,
1109 RTE_FLOW_ERROR_TYPE_ITEM,
1110 NULL, "invalid tag id");
1111 if (priv->sh->flow_mreg_c
1112 [id + 1 + start_reg - REG_C_0] != REG_NON)
1113 return priv->sh->flow_mreg_c
1114 [id + 1 + start_reg - REG_C_0];
1115 return rte_flow_error_set(error, ENOTSUP,
1116 RTE_FLOW_ERROR_TYPE_ITEM,
1117 NULL, "unsupported tag id");
1119 return priv->sh->flow_mreg_c[id + start_reg - REG_C_0];
1122 return rte_flow_error_set(error, EINVAL,
1123 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1124 NULL, "invalid feature name");
1128 * Check extensive flow metadata register support.
1131 * Pointer to rte_eth_dev structure.
1134 * True if device supports extensive flow metadata register, otherwise false.
1137 mlx5_flow_ext_mreg_supported(struct rte_eth_dev *dev)
1139 struct mlx5_priv *priv = dev->data->dev_private;
1142 * Having available reg_c can be regarded inclusively as supporting
1143 * extensive flow metadata register, which could mean,
1144 * - metadata register copy action by modify header.
1145 * - 16 modify header actions is supported.
1146 * - reg_c's are preserved across different domain (FDB and NIC) on
1147 * packet loopback by flow lookup miss.
1149 return priv->sh->flow_mreg_c[2] != REG_NON;
1153 * Get the lowest priority.
1156 * Pointer to the Ethernet device structure.
1157 * @param[in] attributes
1158 * Pointer to device flow rule attributes.
1161 * The value of lowest priority of flow.
1164 mlx5_get_lowest_priority(struct rte_eth_dev *dev,
1165 const struct rte_flow_attr *attr)
1167 struct mlx5_priv *priv = dev->data->dev_private;
1169 if (!attr->group && !attr->transfer)
1170 return priv->sh->flow_max_priority - 2;
1171 return MLX5_NON_ROOT_FLOW_MAX_PRIO - 1;
1175 * Calculate matcher priority of the flow.
1178 * Pointer to the Ethernet device structure.
1180 * Pointer to device flow rule attributes.
1181 * @param[in] subpriority
1182 * The priority based on the items.
1183 * @param[in] external
1184 * Flow is user flow.
1186 * The matcher priority of the flow.
1189 mlx5_get_matcher_priority(struct rte_eth_dev *dev,
1190 const struct rte_flow_attr *attr,
1191 uint32_t subpriority, bool external)
1193 uint16_t priority = (uint16_t)attr->priority;
1194 struct mlx5_priv *priv = dev->data->dev_private;
1196 if (!attr->group && !attr->transfer) {
1197 if (attr->priority == MLX5_FLOW_LOWEST_PRIO_INDICATOR)
1198 priority = priv->sh->flow_max_priority - 1;
1199 return mlx5_os_flow_adjust_priority(dev, priority, subpriority);
1200 } else if (!external && attr->transfer && attr->group == 0 &&
1201 attr->priority == MLX5_FLOW_LOWEST_PRIO_INDICATOR) {
1202 return (priv->sh->flow_max_priority - 1) * 3;
1204 if (attr->priority == MLX5_FLOW_LOWEST_PRIO_INDICATOR)
1205 priority = MLX5_NON_ROOT_FLOW_MAX_PRIO;
1206 return priority * 3 + subpriority;
1210 * Verify the @p item specifications (spec, last, mask) are compatible with the
1214 * Item specification.
1216 * @p item->mask or flow default bit-masks.
1217 * @param[in] nic_mask
1218 * Bit-masks covering supported fields by the NIC to compare with user mask.
1220 * Bit-masks size in bytes.
1221 * @param[in] range_accepted
1222 * True if range of values is accepted for specific fields, false otherwise.
1224 * Pointer to error structure.
1227 * 0 on success, a negative errno value otherwise and rte_errno is set.
1230 mlx5_flow_item_acceptable(const struct rte_flow_item *item,
1231 const uint8_t *mask,
1232 const uint8_t *nic_mask,
1234 bool range_accepted,
1235 struct rte_flow_error *error)
1239 MLX5_ASSERT(nic_mask);
1240 for (i = 0; i < size; ++i)
1241 if ((nic_mask[i] | mask[i]) != nic_mask[i])
1242 return rte_flow_error_set(error, ENOTSUP,
1243 RTE_FLOW_ERROR_TYPE_ITEM,
1245 "mask enables non supported"
1247 if (!item->spec && (item->mask || item->last))
1248 return rte_flow_error_set(error, EINVAL,
1249 RTE_FLOW_ERROR_TYPE_ITEM, item,
1250 "mask/last without a spec is not"
1252 if (item->spec && item->last && !range_accepted) {
1258 for (i = 0; i < size; ++i) {
1259 spec[i] = ((const uint8_t *)item->spec)[i] & mask[i];
1260 last[i] = ((const uint8_t *)item->last)[i] & mask[i];
1262 ret = memcmp(spec, last, size);
1264 return rte_flow_error_set(error, EINVAL,
1265 RTE_FLOW_ERROR_TYPE_ITEM,
1267 "range is not valid");
1273 * Adjust the hash fields according to the @p flow information.
1275 * @param[in] dev_flow.
1276 * Pointer to the mlx5_flow.
1278 * 1 when the hash field is for a tunnel item.
1279 * @param[in] layer_types
1280 * RTE_ETH_RSS_* types.
1281 * @param[in] hash_fields
1285 * The hash fields that should be used.
1288 mlx5_flow_hashfields_adjust(struct mlx5_flow_rss_desc *rss_desc,
1289 int tunnel __rte_unused, uint64_t layer_types,
1290 uint64_t hash_fields)
1292 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
1293 int rss_request_inner = rss_desc->level >= 2;
1295 /* Check RSS hash level for tunnel. */
1296 if (tunnel && rss_request_inner)
1297 hash_fields |= IBV_RX_HASH_INNER;
1298 else if (tunnel || rss_request_inner)
1301 /* Check if requested layer matches RSS hash fields. */
1302 if (!(rss_desc->types & layer_types))
1308 * Lookup and set the ptype in the data Rx part. A single Ptype can be used,
1309 * if several tunnel rules are used on this queue, the tunnel ptype will be
1313 * Rx queue to update.
1316 flow_rxq_tunnel_ptype_update(struct mlx5_rxq_ctrl *rxq_ctrl)
1319 uint32_t tunnel_ptype = 0;
1321 /* Look up for the ptype to use. */
1322 for (i = 0; i != MLX5_FLOW_TUNNEL; ++i) {
1323 if (!rxq_ctrl->flow_tunnels_n[i])
1325 if (!tunnel_ptype) {
1326 tunnel_ptype = tunnels_info[i].ptype;
1332 rxq_ctrl->rxq.tunnel = tunnel_ptype;
1336 * Set the Rx queue flags (Mark/Flag and Tunnel Ptypes) according to the device
1340 * Pointer to the Ethernet device structure.
1341 * @param[in] dev_handle
1342 * Pointer to device flow handle structure.
1345 flow_drv_rxq_flags_set(struct rte_eth_dev *dev,
1346 struct mlx5_flow_handle *dev_handle)
1348 struct mlx5_priv *priv = dev->data->dev_private;
1349 const int tunnel = !!(dev_handle->layers & MLX5_FLOW_LAYER_TUNNEL);
1350 struct mlx5_ind_table_obj *ind_tbl = NULL;
1353 if (dev_handle->fate_action == MLX5_FLOW_FATE_QUEUE) {
1354 struct mlx5_hrxq *hrxq;
1356 hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
1357 dev_handle->rix_hrxq);
1359 ind_tbl = hrxq->ind_table;
1360 } else if (dev_handle->fate_action == MLX5_FLOW_FATE_SHARED_RSS) {
1361 struct mlx5_shared_action_rss *shared_rss;
1363 shared_rss = mlx5_ipool_get
1364 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
1365 dev_handle->rix_srss);
1367 ind_tbl = shared_rss->ind_tbl;
1371 for (i = 0; i != ind_tbl->queues_n; ++i) {
1372 int idx = ind_tbl->queues[i];
1373 struct mlx5_rxq_ctrl *rxq_ctrl = mlx5_rxq_ctrl_get(dev, idx);
1375 MLX5_ASSERT(rxq_ctrl != NULL);
1376 if (rxq_ctrl == NULL)
1379 * To support metadata register copy on Tx loopback,
1380 * this must be always enabled (metadata may arive
1381 * from other port - not from local flows only.
1386 /* Increase the counter matching the flow. */
1387 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j) {
1388 if ((tunnels_info[j].tunnel &
1389 dev_handle->layers) ==
1390 tunnels_info[j].tunnel) {
1391 rxq_ctrl->flow_tunnels_n[j]++;
1395 flow_rxq_tunnel_ptype_update(rxq_ctrl);
1401 flow_rxq_mark_flag_set(struct rte_eth_dev *dev)
1403 struct mlx5_priv *priv = dev->data->dev_private;
1404 struct mlx5_rxq_ctrl *rxq_ctrl;
1406 if (priv->mark_enabled)
1408 LIST_FOREACH(rxq_ctrl, &priv->rxqsctrl, next) {
1409 rxq_ctrl->rxq.mark = 1;
1411 priv->mark_enabled = 1;
1415 * Set the Rx queue flags (Mark/Flag and Tunnel Ptypes) for a flow
1418 * Pointer to the Ethernet device structure.
1420 * Pointer to flow structure.
1423 flow_rxq_flags_set(struct rte_eth_dev *dev, struct rte_flow *flow)
1425 struct mlx5_priv *priv = dev->data->dev_private;
1426 uint32_t handle_idx;
1427 struct mlx5_flow_handle *dev_handle;
1428 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
1432 flow_rxq_mark_flag_set(dev);
1433 SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
1434 handle_idx, dev_handle, next)
1435 flow_drv_rxq_flags_set(dev, dev_handle);
1439 * Clear the Rx queue flags (Mark/Flag and Tunnel Ptype) associated with the
1440 * device flow if no other flow uses it with the same kind of request.
1443 * Pointer to Ethernet device.
1444 * @param[in] dev_handle
1445 * Pointer to the device flow handle structure.
1448 flow_drv_rxq_flags_trim(struct rte_eth_dev *dev,
1449 struct mlx5_flow_handle *dev_handle)
1451 struct mlx5_priv *priv = dev->data->dev_private;
1452 const int tunnel = !!(dev_handle->layers & MLX5_FLOW_LAYER_TUNNEL);
1453 struct mlx5_ind_table_obj *ind_tbl = NULL;
1456 if (dev_handle->fate_action == MLX5_FLOW_FATE_QUEUE) {
1457 struct mlx5_hrxq *hrxq;
1459 hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
1460 dev_handle->rix_hrxq);
1462 ind_tbl = hrxq->ind_table;
1463 } else if (dev_handle->fate_action == MLX5_FLOW_FATE_SHARED_RSS) {
1464 struct mlx5_shared_action_rss *shared_rss;
1466 shared_rss = mlx5_ipool_get
1467 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
1468 dev_handle->rix_srss);
1470 ind_tbl = shared_rss->ind_tbl;
1474 MLX5_ASSERT(dev->data->dev_started);
1475 for (i = 0; i != ind_tbl->queues_n; ++i) {
1476 int idx = ind_tbl->queues[i];
1477 struct mlx5_rxq_ctrl *rxq_ctrl = mlx5_rxq_ctrl_get(dev, idx);
1479 MLX5_ASSERT(rxq_ctrl != NULL);
1480 if (rxq_ctrl == NULL)
1485 /* Decrease the counter matching the flow. */
1486 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j) {
1487 if ((tunnels_info[j].tunnel &
1488 dev_handle->layers) ==
1489 tunnels_info[j].tunnel) {
1490 rxq_ctrl->flow_tunnels_n[j]--;
1494 flow_rxq_tunnel_ptype_update(rxq_ctrl);
1500 * Clear the Rx queue flags (Mark/Flag and Tunnel Ptype) associated with the
1501 * @p flow if no other flow uses it with the same kind of request.
1504 * Pointer to Ethernet device.
1506 * Pointer to the flow.
1509 flow_rxq_flags_trim(struct rte_eth_dev *dev, struct rte_flow *flow)
1511 struct mlx5_priv *priv = dev->data->dev_private;
1512 uint32_t handle_idx;
1513 struct mlx5_flow_handle *dev_handle;
1515 SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
1516 handle_idx, dev_handle, next)
1517 flow_drv_rxq_flags_trim(dev, dev_handle);
1521 * Clear the Mark/Flag and Tunnel ptype information in all Rx queues.
1524 * Pointer to Ethernet device.
1527 flow_rxq_flags_clear(struct rte_eth_dev *dev)
1529 struct mlx5_priv *priv = dev->data->dev_private;
1532 for (i = 0; i != priv->rxqs_n; ++i) {
1533 struct mlx5_rxq_priv *rxq = mlx5_rxq_get(dev, i);
1536 if (rxq == NULL || rxq->ctrl == NULL)
1538 rxq->ctrl->rxq.mark = 0;
1539 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j)
1540 rxq->ctrl->flow_tunnels_n[j] = 0;
1541 rxq->ctrl->rxq.tunnel = 0;
1543 priv->mark_enabled = 0;
1547 * Set the Rx queue dynamic metadata (mask and offset) for a flow
1550 * Pointer to the Ethernet device structure.
1553 mlx5_flow_rxq_dynf_metadata_set(struct rte_eth_dev *dev)
1555 struct mlx5_priv *priv = dev->data->dev_private;
1558 for (i = 0; i != priv->rxqs_n; ++i) {
1559 struct mlx5_rxq_priv *rxq = mlx5_rxq_get(dev, i);
1560 struct mlx5_rxq_data *data;
1562 if (rxq == NULL || rxq->ctrl == NULL)
1564 data = &rxq->ctrl->rxq;
1565 if (!rte_flow_dynf_metadata_avail()) {
1566 data->dynf_meta = 0;
1567 data->flow_meta_mask = 0;
1568 data->flow_meta_offset = -1;
1569 data->flow_meta_port_mask = 0;
1571 data->dynf_meta = 1;
1572 data->flow_meta_mask = rte_flow_dynf_metadata_mask;
1573 data->flow_meta_offset = rte_flow_dynf_metadata_offs;
1574 data->flow_meta_port_mask = priv->sh->dv_meta_mask;
1580 * return a pointer to the desired action in the list of actions.
1582 * @param[in] actions
1583 * The list of actions to search the action in.
1585 * The action to find.
1588 * Pointer to the action in the list, if found. NULL otherwise.
1590 const struct rte_flow_action *
1591 mlx5_flow_find_action(const struct rte_flow_action *actions,
1592 enum rte_flow_action_type action)
1594 if (actions == NULL)
1596 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++)
1597 if (actions->type == action)
1603 * Validate the flag action.
1605 * @param[in] action_flags
1606 * Bit-fields that holds the actions detected until now.
1608 * Attributes of flow that includes this action.
1610 * Pointer to error structure.
1613 * 0 on success, a negative errno value otherwise and rte_errno is set.
1616 mlx5_flow_validate_action_flag(uint64_t action_flags,
1617 const struct rte_flow_attr *attr,
1618 struct rte_flow_error *error)
1620 if (action_flags & MLX5_FLOW_ACTION_MARK)
1621 return rte_flow_error_set(error, EINVAL,
1622 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1623 "can't mark and flag in same flow");
1624 if (action_flags & MLX5_FLOW_ACTION_FLAG)
1625 return rte_flow_error_set(error, EINVAL,
1626 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1628 " actions in same flow");
1630 return rte_flow_error_set(error, ENOTSUP,
1631 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1632 "flag action not supported for "
1638 * Validate the mark action.
1641 * Pointer to the queue action.
1642 * @param[in] action_flags
1643 * Bit-fields that holds the actions detected until now.
1645 * Attributes of flow that includes this action.
1647 * Pointer to error structure.
1650 * 0 on success, a negative errno value otherwise and rte_errno is set.
1653 mlx5_flow_validate_action_mark(const struct rte_flow_action *action,
1654 uint64_t action_flags,
1655 const struct rte_flow_attr *attr,
1656 struct rte_flow_error *error)
1658 const struct rte_flow_action_mark *mark = action->conf;
1661 return rte_flow_error_set(error, EINVAL,
1662 RTE_FLOW_ERROR_TYPE_ACTION,
1664 "configuration cannot be null");
1665 if (mark->id >= MLX5_FLOW_MARK_MAX)
1666 return rte_flow_error_set(error, EINVAL,
1667 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1669 "mark id must in 0 <= id < "
1670 RTE_STR(MLX5_FLOW_MARK_MAX));
1671 if (action_flags & MLX5_FLOW_ACTION_FLAG)
1672 return rte_flow_error_set(error, EINVAL,
1673 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1674 "can't flag and mark in same flow");
1675 if (action_flags & MLX5_FLOW_ACTION_MARK)
1676 return rte_flow_error_set(error, EINVAL,
1677 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1678 "can't have 2 mark actions in same"
1681 return rte_flow_error_set(error, ENOTSUP,
1682 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1683 "mark action not supported for "
1689 * Validate the drop action.
1691 * @param[in] action_flags
1692 * Bit-fields that holds the actions detected until now.
1694 * Attributes of flow that includes this action.
1696 * Pointer to error structure.
1699 * 0 on success, a negative errno value otherwise and rte_errno is set.
1702 mlx5_flow_validate_action_drop(uint64_t action_flags __rte_unused,
1703 const struct rte_flow_attr *attr,
1704 struct rte_flow_error *error)
1707 return rte_flow_error_set(error, ENOTSUP,
1708 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1709 "drop action not supported for "
1715 * Validate the queue action.
1718 * Pointer to the queue action.
1719 * @param[in] action_flags
1720 * Bit-fields that holds the actions detected until now.
1722 * Pointer to the Ethernet device structure.
1724 * Attributes of flow that includes this action.
1726 * Pointer to error structure.
1729 * 0 on success, a negative errno value otherwise and rte_errno is set.
1732 mlx5_flow_validate_action_queue(const struct rte_flow_action *action,
1733 uint64_t action_flags,
1734 struct rte_eth_dev *dev,
1735 const struct rte_flow_attr *attr,
1736 struct rte_flow_error *error)
1738 struct mlx5_priv *priv = dev->data->dev_private;
1739 const struct rte_flow_action_queue *queue = action->conf;
1741 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
1742 return rte_flow_error_set(error, EINVAL,
1743 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1744 "can't have 2 fate actions in"
1747 return rte_flow_error_set(error, EINVAL,
1748 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1749 NULL, "No Rx queues configured");
1750 if (queue->index >= priv->rxqs_n)
1751 return rte_flow_error_set(error, EINVAL,
1752 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1754 "queue index out of range");
1755 if (mlx5_rxq_get(dev, queue->index) == NULL)
1756 return rte_flow_error_set(error, EINVAL,
1757 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1759 "queue is not configured");
1761 return rte_flow_error_set(error, ENOTSUP,
1762 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1763 "queue action not supported for "
1769 * Validate queue numbers for device RSS.
1772 * Configured device.
1774 * Array of queue numbers.
1775 * @param[in] queues_n
1776 * Size of the @p queues array.
1778 * On error, filled with a textual error description.
1780 * On error, filled with an offending queue index in @p queues array.
1783 * 0 on success, a negative errno code on error.
1786 mlx5_validate_rss_queues(struct rte_eth_dev *dev,
1787 const uint16_t *queues, uint32_t queues_n,
1788 const char **error, uint32_t *queue_idx)
1790 const struct mlx5_priv *priv = dev->data->dev_private;
1791 enum mlx5_rxq_type rxq_type = MLX5_RXQ_TYPE_UNDEFINED;
1794 for (i = 0; i != queues_n; ++i) {
1795 struct mlx5_rxq_ctrl *rxq_ctrl = mlx5_rxq_ctrl_get(dev,
1798 if (queues[i] >= priv->rxqs_n) {
1799 *error = "queue index out of range";
1803 if (rxq_ctrl == NULL) {
1804 *error = "queue is not configured";
1809 rxq_type = rxq_ctrl->type;
1810 if (rxq_type != rxq_ctrl->type) {
1811 *error = "combining hairpin and regular RSS queues is not supported";
1820 * Validate the rss action.
1823 * Pointer to the Ethernet device structure.
1825 * Pointer to the queue action.
1827 * Pointer to error structure.
1830 * 0 on success, a negative errno value otherwise and rte_errno is set.
1833 mlx5_validate_action_rss(struct rte_eth_dev *dev,
1834 const struct rte_flow_action *action,
1835 struct rte_flow_error *error)
1837 struct mlx5_priv *priv = dev->data->dev_private;
1838 const struct rte_flow_action_rss *rss = action->conf;
1840 const char *message;
1843 if (rss->func != RTE_ETH_HASH_FUNCTION_DEFAULT &&
1844 rss->func != RTE_ETH_HASH_FUNCTION_TOEPLITZ)
1845 return rte_flow_error_set(error, ENOTSUP,
1846 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1848 "RSS hash function not supported");
1849 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
1854 return rte_flow_error_set(error, ENOTSUP,
1855 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1857 "tunnel RSS is not supported");
1858 /* allow RSS key_len 0 in case of NULL (default) RSS key. */
1859 if (rss->key_len == 0 && rss->key != NULL)
1860 return rte_flow_error_set(error, ENOTSUP,
1861 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1863 "RSS hash key length 0");
1864 if (rss->key_len > 0 && rss->key_len < MLX5_RSS_HASH_KEY_LEN)
1865 return rte_flow_error_set(error, ENOTSUP,
1866 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1868 "RSS hash key too small");
1869 if (rss->key_len > MLX5_RSS_HASH_KEY_LEN)
1870 return rte_flow_error_set(error, ENOTSUP,
1871 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1873 "RSS hash key too large");
1874 if (rss->queue_num > priv->sh->dev_cap.ind_table_max_size)
1875 return rte_flow_error_set(error, ENOTSUP,
1876 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1878 "number of queues too large");
1879 if (rss->types & MLX5_RSS_HF_MASK)
1880 return rte_flow_error_set(error, ENOTSUP,
1881 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1883 "some RSS protocols are not"
1885 if ((rss->types & (RTE_ETH_RSS_L3_SRC_ONLY | RTE_ETH_RSS_L3_DST_ONLY)) &&
1886 !(rss->types & RTE_ETH_RSS_IP))
1887 return rte_flow_error_set(error, EINVAL,
1888 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1889 "L3 partial RSS requested but L3 RSS"
1890 " type not specified");
1891 if ((rss->types & (RTE_ETH_RSS_L4_SRC_ONLY | RTE_ETH_RSS_L4_DST_ONLY)) &&
1892 !(rss->types & (RTE_ETH_RSS_UDP | RTE_ETH_RSS_TCP)))
1893 return rte_flow_error_set(error, EINVAL,
1894 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1895 "L4 partial RSS requested but L4 RSS"
1896 " type not specified");
1898 return rte_flow_error_set(error, EINVAL,
1899 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1900 NULL, "No Rx queues configured");
1901 if (!rss->queue_num)
1902 return rte_flow_error_set(error, EINVAL,
1903 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1904 NULL, "No queues configured");
1905 ret = mlx5_validate_rss_queues(dev, rss->queue, rss->queue_num,
1906 &message, &queue_idx);
1908 return rte_flow_error_set(error, -ret,
1909 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1910 &rss->queue[queue_idx], message);
1916 * Validate the rss action.
1919 * Pointer to the queue action.
1920 * @param[in] action_flags
1921 * Bit-fields that holds the actions detected until now.
1923 * Pointer to the Ethernet device structure.
1925 * Attributes of flow that includes this action.
1926 * @param[in] item_flags
1927 * Items that were detected.
1929 * Pointer to error structure.
1932 * 0 on success, a negative errno value otherwise and rte_errno is set.
1935 mlx5_flow_validate_action_rss(const struct rte_flow_action *action,
1936 uint64_t action_flags,
1937 struct rte_eth_dev *dev,
1938 const struct rte_flow_attr *attr,
1939 uint64_t item_flags,
1940 struct rte_flow_error *error)
1942 const struct rte_flow_action_rss *rss = action->conf;
1943 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1946 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
1947 return rte_flow_error_set(error, EINVAL,
1948 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1949 "can't have 2 fate actions"
1951 ret = mlx5_validate_action_rss(dev, action, error);
1955 return rte_flow_error_set(error, ENOTSUP,
1956 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1957 "rss action not supported for "
1959 if (rss->level > 1 && !tunnel)
1960 return rte_flow_error_set(error, EINVAL,
1961 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1962 "inner RSS is not supported for "
1963 "non-tunnel flows");
1964 if ((item_flags & MLX5_FLOW_LAYER_ECPRI) &&
1965 !(item_flags & MLX5_FLOW_LAYER_INNER_L4_UDP)) {
1966 return rte_flow_error_set(error, EINVAL,
1967 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1968 "RSS on eCPRI is not supported now");
1970 if ((item_flags & MLX5_FLOW_LAYER_MPLS) &&
1972 (MLX5_FLOW_LAYER_INNER_L2 | MLX5_FLOW_LAYER_INNER_L3)) &&
1974 return rte_flow_error_set(error, EINVAL,
1975 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
1976 "MPLS inner RSS needs to specify inner L2/L3 items after MPLS in pattern");
1981 * Validate the default miss action.
1983 * @param[in] action_flags
1984 * Bit-fields that holds the actions detected until now.
1986 * Pointer to error structure.
1989 * 0 on success, a negative errno value otherwise and rte_errno is set.
1992 mlx5_flow_validate_action_default_miss(uint64_t action_flags,
1993 const struct rte_flow_attr *attr,
1994 struct rte_flow_error *error)
1996 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
1997 return rte_flow_error_set(error, EINVAL,
1998 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1999 "can't have 2 fate actions in"
2002 return rte_flow_error_set(error, ENOTSUP,
2003 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
2004 "default miss action not supported "
2007 return rte_flow_error_set(error, ENOTSUP,
2008 RTE_FLOW_ERROR_TYPE_ATTR_GROUP, NULL,
2009 "only group 0 is supported");
2011 return rte_flow_error_set(error, ENOTSUP,
2012 RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
2013 NULL, "transfer is not supported");
2018 * Validate the count action.
2021 * Pointer to the Ethernet device structure.
2023 * Attributes of flow that includes this action.
2025 * Pointer to error structure.
2028 * 0 on success, a negative errno value otherwise and rte_errno is set.
2031 mlx5_flow_validate_action_count(struct rte_eth_dev *dev __rte_unused,
2032 const struct rte_flow_attr *attr,
2033 struct rte_flow_error *error)
2036 return rte_flow_error_set(error, ENOTSUP,
2037 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
2038 "count action not supported for "
2044 * Validate the ASO CT action.
2047 * Pointer to the Ethernet device structure.
2048 * @param[in] conntrack
2049 * Pointer to the CT action profile.
2051 * Pointer to error structure.
2054 * 0 on success, a negative errno value otherwise and rte_errno is set.
2057 mlx5_validate_action_ct(struct rte_eth_dev *dev,
2058 const struct rte_flow_action_conntrack *conntrack,
2059 struct rte_flow_error *error)
2063 if (conntrack->state > RTE_FLOW_CONNTRACK_STATE_TIME_WAIT)
2064 return rte_flow_error_set(error, EINVAL,
2065 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2066 "Invalid CT state");
2067 if (conntrack->last_index > RTE_FLOW_CONNTRACK_FLAG_RST)
2068 return rte_flow_error_set(error, EINVAL,
2069 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2070 "Invalid last TCP packet flag");
2075 * Verify the @p attributes will be correctly understood by the NIC and store
2076 * them in the @p flow if everything is correct.
2079 * Pointer to the Ethernet device structure.
2080 * @param[in] attributes
2081 * Pointer to flow attributes
2083 * Pointer to error structure.
2086 * 0 on success, a negative errno value otherwise and rte_errno is set.
2089 mlx5_flow_validate_attributes(struct rte_eth_dev *dev,
2090 const struct rte_flow_attr *attributes,
2091 struct rte_flow_error *error)
2093 struct mlx5_priv *priv = dev->data->dev_private;
2094 uint32_t priority_max = priv->sh->flow_max_priority - 1;
2096 if (attributes->group)
2097 return rte_flow_error_set(error, ENOTSUP,
2098 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
2099 NULL, "groups is not supported");
2100 if (attributes->priority != MLX5_FLOW_LOWEST_PRIO_INDICATOR &&
2101 attributes->priority >= priority_max)
2102 return rte_flow_error_set(error, ENOTSUP,
2103 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
2104 NULL, "priority out of range");
2105 if (attributes->egress)
2106 return rte_flow_error_set(error, ENOTSUP,
2107 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
2108 "egress is not supported");
2109 if (attributes->transfer && !priv->sh->config.dv_esw_en)
2110 return rte_flow_error_set(error, ENOTSUP,
2111 RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
2112 NULL, "transfer is not supported");
2113 if (!attributes->ingress)
2114 return rte_flow_error_set(error, EINVAL,
2115 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
2117 "ingress attribute is mandatory");
2122 * Validate ICMP6 item.
2125 * Item specification.
2126 * @param[in] item_flags
2127 * Bit-fields that holds the items detected until now.
2128 * @param[in] ext_vlan_sup
2129 * Whether extended VLAN features are supported or not.
2131 * Pointer to error structure.
2134 * 0 on success, a negative errno value otherwise and rte_errno is set.
2137 mlx5_flow_validate_item_icmp6(const struct rte_flow_item *item,
2138 uint64_t item_flags,
2139 uint8_t target_protocol,
2140 struct rte_flow_error *error)
2142 const struct rte_flow_item_icmp6 *mask = item->mask;
2143 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2144 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
2145 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
2146 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2147 MLX5_FLOW_LAYER_OUTER_L4;
2150 if (target_protocol != 0xFF && target_protocol != IPPROTO_ICMPV6)
2151 return rte_flow_error_set(error, EINVAL,
2152 RTE_FLOW_ERROR_TYPE_ITEM, item,
2153 "protocol filtering not compatible"
2154 " with ICMP6 layer");
2155 if (!(item_flags & l3m))
2156 return rte_flow_error_set(error, EINVAL,
2157 RTE_FLOW_ERROR_TYPE_ITEM, item,
2158 "IPv6 is mandatory to filter on"
2160 if (item_flags & l4m)
2161 return rte_flow_error_set(error, EINVAL,
2162 RTE_FLOW_ERROR_TYPE_ITEM, item,
2163 "multiple L4 layers not supported");
2165 mask = &rte_flow_item_icmp6_mask;
2166 ret = mlx5_flow_item_acceptable
2167 (item, (const uint8_t *)mask,
2168 (const uint8_t *)&rte_flow_item_icmp6_mask,
2169 sizeof(struct rte_flow_item_icmp6),
2170 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2177 * Validate ICMP item.
2180 * Item specification.
2181 * @param[in] item_flags
2182 * Bit-fields that holds the items detected until now.
2184 * Pointer to error structure.
2187 * 0 on success, a negative errno value otherwise and rte_errno is set.
2190 mlx5_flow_validate_item_icmp(const struct rte_flow_item *item,
2191 uint64_t item_flags,
2192 uint8_t target_protocol,
2193 struct rte_flow_error *error)
2195 const struct rte_flow_item_icmp *mask = item->mask;
2196 const struct rte_flow_item_icmp nic_mask = {
2197 .hdr.icmp_type = 0xff,
2198 .hdr.icmp_code = 0xff,
2199 .hdr.icmp_ident = RTE_BE16(0xffff),
2200 .hdr.icmp_seq_nb = RTE_BE16(0xffff),
2202 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2203 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
2204 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
2205 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2206 MLX5_FLOW_LAYER_OUTER_L4;
2209 if (target_protocol != 0xFF && target_protocol != IPPROTO_ICMP)
2210 return rte_flow_error_set(error, EINVAL,
2211 RTE_FLOW_ERROR_TYPE_ITEM, item,
2212 "protocol filtering not compatible"
2213 " with ICMP layer");
2214 if (!(item_flags & l3m))
2215 return rte_flow_error_set(error, EINVAL,
2216 RTE_FLOW_ERROR_TYPE_ITEM, item,
2217 "IPv4 is mandatory to filter"
2219 if (item_flags & l4m)
2220 return rte_flow_error_set(error, EINVAL,
2221 RTE_FLOW_ERROR_TYPE_ITEM, item,
2222 "multiple L4 layers not supported");
2225 ret = mlx5_flow_item_acceptable
2226 (item, (const uint8_t *)mask,
2227 (const uint8_t *)&nic_mask,
2228 sizeof(struct rte_flow_item_icmp),
2229 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2236 * Validate Ethernet item.
2239 * Item specification.
2240 * @param[in] item_flags
2241 * Bit-fields that holds the items detected until now.
2243 * Pointer to error structure.
2246 * 0 on success, a negative errno value otherwise and rte_errno is set.
2249 mlx5_flow_validate_item_eth(const struct rte_flow_item *item,
2250 uint64_t item_flags, bool ext_vlan_sup,
2251 struct rte_flow_error *error)
2253 const struct rte_flow_item_eth *mask = item->mask;
2254 const struct rte_flow_item_eth nic_mask = {
2255 .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
2256 .src.addr_bytes = "\xff\xff\xff\xff\xff\xff",
2257 .type = RTE_BE16(0xffff),
2258 .has_vlan = ext_vlan_sup ? 1 : 0,
2261 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2262 const uint64_t ethm = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
2263 MLX5_FLOW_LAYER_OUTER_L2;
2265 if (item_flags & ethm)
2266 return rte_flow_error_set(error, ENOTSUP,
2267 RTE_FLOW_ERROR_TYPE_ITEM, item,
2268 "multiple L2 layers not supported");
2269 if ((!tunnel && (item_flags & MLX5_FLOW_LAYER_OUTER_L3)) ||
2270 (tunnel && (item_flags & MLX5_FLOW_LAYER_INNER_L3)))
2271 return rte_flow_error_set(error, EINVAL,
2272 RTE_FLOW_ERROR_TYPE_ITEM, item,
2273 "L2 layer should not follow "
2275 if ((!tunnel && (item_flags & MLX5_FLOW_LAYER_OUTER_VLAN)) ||
2276 (tunnel && (item_flags & MLX5_FLOW_LAYER_INNER_VLAN)))
2277 return rte_flow_error_set(error, EINVAL,
2278 RTE_FLOW_ERROR_TYPE_ITEM, item,
2279 "L2 layer should not follow VLAN");
2280 if (item_flags & MLX5_FLOW_LAYER_GTP)
2281 return rte_flow_error_set(error, EINVAL,
2282 RTE_FLOW_ERROR_TYPE_ITEM, item,
2283 "L2 layer should not follow GTP");
2285 mask = &rte_flow_item_eth_mask;
2286 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2287 (const uint8_t *)&nic_mask,
2288 sizeof(struct rte_flow_item_eth),
2289 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2294 * Validate VLAN item.
2297 * Item specification.
2298 * @param[in] item_flags
2299 * Bit-fields that holds the items detected until now.
2301 * Ethernet device flow is being created on.
2303 * Pointer to error structure.
2306 * 0 on success, a negative errno value otherwise and rte_errno is set.
2309 mlx5_flow_validate_item_vlan(const struct rte_flow_item *item,
2310 uint64_t item_flags,
2311 struct rte_eth_dev *dev,
2312 struct rte_flow_error *error)
2314 const struct rte_flow_item_vlan *spec = item->spec;
2315 const struct rte_flow_item_vlan *mask = item->mask;
2316 const struct rte_flow_item_vlan nic_mask = {
2317 .tci = RTE_BE16(UINT16_MAX),
2318 .inner_type = RTE_BE16(UINT16_MAX),
2320 uint16_t vlan_tag = 0;
2321 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2323 const uint64_t l34m = tunnel ? (MLX5_FLOW_LAYER_INNER_L3 |
2324 MLX5_FLOW_LAYER_INNER_L4) :
2325 (MLX5_FLOW_LAYER_OUTER_L3 |
2326 MLX5_FLOW_LAYER_OUTER_L4);
2327 const uint64_t vlanm = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
2328 MLX5_FLOW_LAYER_OUTER_VLAN;
2330 if (item_flags & vlanm)
2331 return rte_flow_error_set(error, EINVAL,
2332 RTE_FLOW_ERROR_TYPE_ITEM, item,
2333 "multiple VLAN layers not supported");
2334 else if ((item_flags & l34m) != 0)
2335 return rte_flow_error_set(error, EINVAL,
2336 RTE_FLOW_ERROR_TYPE_ITEM, item,
2337 "VLAN cannot follow L3/L4 layer");
2339 mask = &rte_flow_item_vlan_mask;
2340 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2341 (const uint8_t *)&nic_mask,
2342 sizeof(struct rte_flow_item_vlan),
2343 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2346 if (!tunnel && mask->tci != RTE_BE16(0x0fff)) {
2347 struct mlx5_priv *priv = dev->data->dev_private;
2349 if (priv->vmwa_context) {
2351 * Non-NULL context means we have a virtual machine
2352 * and SR-IOV enabled, we have to create VLAN interface
2353 * to make hypervisor to setup E-Switch vport
2354 * context correctly. We avoid creating the multiple
2355 * VLAN interfaces, so we cannot support VLAN tag mask.
2357 return rte_flow_error_set(error, EINVAL,
2358 RTE_FLOW_ERROR_TYPE_ITEM,
2360 "VLAN tag mask is not"
2361 " supported in virtual"
2366 vlan_tag = spec->tci;
2367 vlan_tag &= mask->tci;
2370 * From verbs perspective an empty VLAN is equivalent
2371 * to a packet without VLAN layer.
2374 return rte_flow_error_set(error, EINVAL,
2375 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
2377 "VLAN cannot be empty");
2382 * Validate IPV4 item.
2385 * Item specification.
2386 * @param[in] item_flags
2387 * Bit-fields that holds the items detected until now.
2388 * @param[in] last_item
2389 * Previous validated item in the pattern items.
2390 * @param[in] ether_type
2391 * Type in the ethernet layer header (including dot1q).
2392 * @param[in] acc_mask
2393 * Acceptable mask, if NULL default internal default mask
2394 * will be used to check whether item fields are supported.
2395 * @param[in] range_accepted
2396 * True if range of values is accepted for specific fields, false otherwise.
2398 * Pointer to error structure.
2401 * 0 on success, a negative errno value otherwise and rte_errno is set.
2404 mlx5_flow_validate_item_ipv4(const struct rte_flow_item *item,
2405 uint64_t item_flags,
2407 uint16_t ether_type,
2408 const struct rte_flow_item_ipv4 *acc_mask,
2409 bool range_accepted,
2410 struct rte_flow_error *error)
2412 const struct rte_flow_item_ipv4 *mask = item->mask;
2413 const struct rte_flow_item_ipv4 *spec = item->spec;
2414 const struct rte_flow_item_ipv4 nic_mask = {
2416 .src_addr = RTE_BE32(0xffffffff),
2417 .dst_addr = RTE_BE32(0xffffffff),
2418 .type_of_service = 0xff,
2419 .next_proto_id = 0xff,
2422 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2423 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2424 MLX5_FLOW_LAYER_OUTER_L3;
2425 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2426 MLX5_FLOW_LAYER_OUTER_L4;
2428 uint8_t next_proto = 0xFF;
2429 const uint64_t l2_vlan = (MLX5_FLOW_LAYER_L2 |
2430 MLX5_FLOW_LAYER_OUTER_VLAN |
2431 MLX5_FLOW_LAYER_INNER_VLAN);
2433 if ((last_item & l2_vlan) && ether_type &&
2434 ether_type != RTE_ETHER_TYPE_IPV4)
2435 return rte_flow_error_set(error, EINVAL,
2436 RTE_FLOW_ERROR_TYPE_ITEM, item,
2437 "IPv4 cannot follow L2/VLAN layer "
2438 "which ether type is not IPv4");
2439 if (item_flags & MLX5_FLOW_LAYER_TUNNEL) {
2441 next_proto = mask->hdr.next_proto_id &
2442 spec->hdr.next_proto_id;
2443 if (next_proto == IPPROTO_IPIP || next_proto == IPPROTO_IPV6)
2444 return rte_flow_error_set(error, EINVAL,
2445 RTE_FLOW_ERROR_TYPE_ITEM,
2450 if (item_flags & MLX5_FLOW_LAYER_IPV6_ENCAP)
2451 return rte_flow_error_set(error, EINVAL,
2452 RTE_FLOW_ERROR_TYPE_ITEM, item,
2453 "wrong tunnel type - IPv6 specified "
2454 "but IPv4 item provided");
2455 if (item_flags & l3m)
2456 return rte_flow_error_set(error, ENOTSUP,
2457 RTE_FLOW_ERROR_TYPE_ITEM, item,
2458 "multiple L3 layers not supported");
2459 else if (item_flags & l4m)
2460 return rte_flow_error_set(error, EINVAL,
2461 RTE_FLOW_ERROR_TYPE_ITEM, item,
2462 "L3 cannot follow an L4 layer.");
2463 else if ((item_flags & MLX5_FLOW_LAYER_NVGRE) &&
2464 !(item_flags & MLX5_FLOW_LAYER_INNER_L2))
2465 return rte_flow_error_set(error, EINVAL,
2466 RTE_FLOW_ERROR_TYPE_ITEM, item,
2467 "L3 cannot follow an NVGRE layer.");
2469 mask = &rte_flow_item_ipv4_mask;
2470 else if (mask->hdr.next_proto_id != 0 &&
2471 mask->hdr.next_proto_id != 0xff)
2472 return rte_flow_error_set(error, EINVAL,
2473 RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
2474 "partial mask is not supported"
2476 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2477 acc_mask ? (const uint8_t *)acc_mask
2478 : (const uint8_t *)&nic_mask,
2479 sizeof(struct rte_flow_item_ipv4),
2480 range_accepted, error);
2487 * Validate IPV6 item.
2490 * Item specification.
2491 * @param[in] item_flags
2492 * Bit-fields that holds the items detected until now.
2493 * @param[in] last_item
2494 * Previous validated item in the pattern items.
2495 * @param[in] ether_type
2496 * Type in the ethernet layer header (including dot1q).
2497 * @param[in] acc_mask
2498 * Acceptable mask, if NULL default internal default mask
2499 * will be used to check whether item fields are supported.
2501 * Pointer to error structure.
2504 * 0 on success, a negative errno value otherwise and rte_errno is set.
2507 mlx5_flow_validate_item_ipv6(const struct rte_flow_item *item,
2508 uint64_t item_flags,
2510 uint16_t ether_type,
2511 const struct rte_flow_item_ipv6 *acc_mask,
2512 struct rte_flow_error *error)
2514 const struct rte_flow_item_ipv6 *mask = item->mask;
2515 const struct rte_flow_item_ipv6 *spec = item->spec;
2516 const struct rte_flow_item_ipv6 nic_mask = {
2519 "\xff\xff\xff\xff\xff\xff\xff\xff"
2520 "\xff\xff\xff\xff\xff\xff\xff\xff",
2522 "\xff\xff\xff\xff\xff\xff\xff\xff"
2523 "\xff\xff\xff\xff\xff\xff\xff\xff",
2524 .vtc_flow = RTE_BE32(0xffffffff),
2528 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2529 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2530 MLX5_FLOW_LAYER_OUTER_L3;
2531 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2532 MLX5_FLOW_LAYER_OUTER_L4;
2534 uint8_t next_proto = 0xFF;
2535 const uint64_t l2_vlan = (MLX5_FLOW_LAYER_L2 |
2536 MLX5_FLOW_LAYER_OUTER_VLAN |
2537 MLX5_FLOW_LAYER_INNER_VLAN);
2539 if ((last_item & l2_vlan) && ether_type &&
2540 ether_type != RTE_ETHER_TYPE_IPV6)
2541 return rte_flow_error_set(error, EINVAL,
2542 RTE_FLOW_ERROR_TYPE_ITEM, item,
2543 "IPv6 cannot follow L2/VLAN layer "
2544 "which ether type is not IPv6");
2545 if (mask && mask->hdr.proto == UINT8_MAX && spec)
2546 next_proto = spec->hdr.proto;
2547 if (item_flags & MLX5_FLOW_LAYER_TUNNEL) {
2548 if (next_proto == IPPROTO_IPIP || next_proto == IPPROTO_IPV6)
2549 return rte_flow_error_set(error, EINVAL,
2550 RTE_FLOW_ERROR_TYPE_ITEM,
2555 if (next_proto == IPPROTO_HOPOPTS ||
2556 next_proto == IPPROTO_ROUTING ||
2557 next_proto == IPPROTO_FRAGMENT ||
2558 next_proto == IPPROTO_ESP ||
2559 next_proto == IPPROTO_AH ||
2560 next_proto == IPPROTO_DSTOPTS)
2561 return rte_flow_error_set(error, EINVAL,
2562 RTE_FLOW_ERROR_TYPE_ITEM, item,
2563 "IPv6 proto (next header) should "
2564 "not be set as extension header");
2565 if (item_flags & MLX5_FLOW_LAYER_IPIP)
2566 return rte_flow_error_set(error, EINVAL,
2567 RTE_FLOW_ERROR_TYPE_ITEM, item,
2568 "wrong tunnel type - IPv4 specified "
2569 "but IPv6 item provided");
2570 if (item_flags & l3m)
2571 return rte_flow_error_set(error, ENOTSUP,
2572 RTE_FLOW_ERROR_TYPE_ITEM, item,
2573 "multiple L3 layers not supported");
2574 else if (item_flags & l4m)
2575 return rte_flow_error_set(error, EINVAL,
2576 RTE_FLOW_ERROR_TYPE_ITEM, item,
2577 "L3 cannot follow an L4 layer.");
2578 else if ((item_flags & MLX5_FLOW_LAYER_NVGRE) &&
2579 !(item_flags & MLX5_FLOW_LAYER_INNER_L2))
2580 return rte_flow_error_set(error, EINVAL,
2581 RTE_FLOW_ERROR_TYPE_ITEM, item,
2582 "L3 cannot follow an NVGRE layer.");
2584 mask = &rte_flow_item_ipv6_mask;
2585 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2586 acc_mask ? (const uint8_t *)acc_mask
2587 : (const uint8_t *)&nic_mask,
2588 sizeof(struct rte_flow_item_ipv6),
2589 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2596 * Validate UDP item.
2599 * Item specification.
2600 * @param[in] item_flags
2601 * Bit-fields that holds the items detected until now.
2602 * @param[in] target_protocol
2603 * The next protocol in the previous item.
2604 * @param[in] flow_mask
2605 * mlx5 flow-specific (DV, verbs, etc.) supported header fields mask.
2607 * Pointer to error structure.
2610 * 0 on success, a negative errno value otherwise and rte_errno is set.
2613 mlx5_flow_validate_item_udp(const struct rte_flow_item *item,
2614 uint64_t item_flags,
2615 uint8_t target_protocol,
2616 struct rte_flow_error *error)
2618 const struct rte_flow_item_udp *mask = item->mask;
2619 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2620 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2621 MLX5_FLOW_LAYER_OUTER_L3;
2622 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2623 MLX5_FLOW_LAYER_OUTER_L4;
2626 if (target_protocol != 0xff && target_protocol != IPPROTO_UDP)
2627 return rte_flow_error_set(error, EINVAL,
2628 RTE_FLOW_ERROR_TYPE_ITEM, item,
2629 "protocol filtering not compatible"
2631 if (!(item_flags & l3m))
2632 return rte_flow_error_set(error, EINVAL,
2633 RTE_FLOW_ERROR_TYPE_ITEM, item,
2634 "L3 is mandatory to filter on L4");
2635 if (item_flags & l4m)
2636 return rte_flow_error_set(error, EINVAL,
2637 RTE_FLOW_ERROR_TYPE_ITEM, item,
2638 "multiple L4 layers not supported");
2640 mask = &rte_flow_item_udp_mask;
2641 ret = mlx5_flow_item_acceptable
2642 (item, (const uint8_t *)mask,
2643 (const uint8_t *)&rte_flow_item_udp_mask,
2644 sizeof(struct rte_flow_item_udp), MLX5_ITEM_RANGE_NOT_ACCEPTED,
2652 * Validate TCP item.
2655 * Item specification.
2656 * @param[in] item_flags
2657 * Bit-fields that holds the items detected until now.
2658 * @param[in] target_protocol
2659 * The next protocol in the previous item.
2661 * Pointer to error structure.
2664 * 0 on success, a negative errno value otherwise and rte_errno is set.
2667 mlx5_flow_validate_item_tcp(const struct rte_flow_item *item,
2668 uint64_t item_flags,
2669 uint8_t target_protocol,
2670 const struct rte_flow_item_tcp *flow_mask,
2671 struct rte_flow_error *error)
2673 const struct rte_flow_item_tcp *mask = item->mask;
2674 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2675 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2676 MLX5_FLOW_LAYER_OUTER_L3;
2677 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2678 MLX5_FLOW_LAYER_OUTER_L4;
2681 MLX5_ASSERT(flow_mask);
2682 if (target_protocol != 0xff && target_protocol != IPPROTO_TCP)
2683 return rte_flow_error_set(error, EINVAL,
2684 RTE_FLOW_ERROR_TYPE_ITEM, item,
2685 "protocol filtering not compatible"
2687 if (!(item_flags & l3m))
2688 return rte_flow_error_set(error, EINVAL,
2689 RTE_FLOW_ERROR_TYPE_ITEM, item,
2690 "L3 is mandatory to filter on L4");
2691 if (item_flags & l4m)
2692 return rte_flow_error_set(error, EINVAL,
2693 RTE_FLOW_ERROR_TYPE_ITEM, item,
2694 "multiple L4 layers not supported");
2696 mask = &rte_flow_item_tcp_mask;
2697 ret = mlx5_flow_item_acceptable
2698 (item, (const uint8_t *)mask,
2699 (const uint8_t *)flow_mask,
2700 sizeof(struct rte_flow_item_tcp), MLX5_ITEM_RANGE_NOT_ACCEPTED,
2708 * Validate VXLAN item.
2711 * Pointer to the Ethernet device structure.
2712 * @param[in] udp_dport
2713 * UDP destination port
2715 * Item specification.
2716 * @param[in] item_flags
2717 * Bit-fields that holds the items detected until now.
2719 * Flow rule attributes.
2721 * Pointer to error structure.
2724 * 0 on success, a negative errno value otherwise and rte_errno is set.
2727 mlx5_flow_validate_item_vxlan(struct rte_eth_dev *dev,
2729 const struct rte_flow_item *item,
2730 uint64_t item_flags,
2731 const struct rte_flow_attr *attr,
2732 struct rte_flow_error *error)
2734 const struct rte_flow_item_vxlan *spec = item->spec;
2735 const struct rte_flow_item_vxlan *mask = item->mask;
2737 struct mlx5_priv *priv = dev->data->dev_private;
2741 } id = { .vlan_id = 0, };
2742 const struct rte_flow_item_vxlan nic_mask = {
2743 .vni = "\xff\xff\xff",
2746 const struct rte_flow_item_vxlan *valid_mask;
2748 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2749 return rte_flow_error_set(error, ENOTSUP,
2750 RTE_FLOW_ERROR_TYPE_ITEM, item,
2751 "multiple tunnel layers not"
2753 valid_mask = &rte_flow_item_vxlan_mask;
2755 * Verify only UDPv4 is present as defined in
2756 * https://tools.ietf.org/html/rfc7348
2758 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2759 return rte_flow_error_set(error, EINVAL,
2760 RTE_FLOW_ERROR_TYPE_ITEM, item,
2761 "no outer UDP layer found");
2763 mask = &rte_flow_item_vxlan_mask;
2765 if (priv->sh->steering_format_version !=
2766 MLX5_STEERING_LOGIC_FORMAT_CONNECTX_5 ||
2767 !udp_dport || udp_dport == MLX5_UDP_PORT_VXLAN) {
2768 /* FDB domain & NIC domain non-zero group */
2769 if ((attr->transfer || attr->group) && priv->sh->misc5_cap)
2770 valid_mask = &nic_mask;
2771 /* Group zero in NIC domain */
2772 if (!attr->group && !attr->transfer &&
2773 priv->sh->tunnel_header_0_1)
2774 valid_mask = &nic_mask;
2776 ret = mlx5_flow_item_acceptable
2777 (item, (const uint8_t *)mask,
2778 (const uint8_t *)valid_mask,
2779 sizeof(struct rte_flow_item_vxlan),
2780 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2784 memcpy(&id.vni[1], spec->vni, 3);
2785 memcpy(&id.vni[1], mask->vni, 3);
2787 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
2788 return rte_flow_error_set(error, ENOTSUP,
2789 RTE_FLOW_ERROR_TYPE_ITEM, item,
2790 "VXLAN tunnel must be fully defined");
2795 * Validate VXLAN_GPE item.
2798 * Item specification.
2799 * @param[in] item_flags
2800 * Bit-fields that holds the items detected until now.
2802 * Pointer to the private data structure.
2803 * @param[in] target_protocol
2804 * The next protocol in the previous item.
2806 * Pointer to error structure.
2809 * 0 on success, a negative errno value otherwise and rte_errno is set.
2812 mlx5_flow_validate_item_vxlan_gpe(const struct rte_flow_item *item,
2813 uint64_t item_flags,
2814 struct rte_eth_dev *dev,
2815 struct rte_flow_error *error)
2817 struct mlx5_priv *priv = dev->data->dev_private;
2818 const struct rte_flow_item_vxlan_gpe *spec = item->spec;
2819 const struct rte_flow_item_vxlan_gpe *mask = item->mask;
2824 } id = { .vlan_id = 0, };
2826 if (!priv->sh->config.l3_vxlan_en)
2827 return rte_flow_error_set(error, ENOTSUP,
2828 RTE_FLOW_ERROR_TYPE_ITEM, item,
2829 "L3 VXLAN is not enabled by device"
2830 " parameter and/or not configured in"
2832 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2833 return rte_flow_error_set(error, ENOTSUP,
2834 RTE_FLOW_ERROR_TYPE_ITEM, item,
2835 "multiple tunnel layers not"
2838 * Verify only UDPv4 is present as defined in
2839 * https://tools.ietf.org/html/rfc7348
2841 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2842 return rte_flow_error_set(error, EINVAL,
2843 RTE_FLOW_ERROR_TYPE_ITEM, item,
2844 "no outer UDP layer found");
2846 mask = &rte_flow_item_vxlan_gpe_mask;
2847 ret = mlx5_flow_item_acceptable
2848 (item, (const uint8_t *)mask,
2849 (const uint8_t *)&rte_flow_item_vxlan_gpe_mask,
2850 sizeof(struct rte_flow_item_vxlan_gpe),
2851 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2856 return rte_flow_error_set(error, ENOTSUP,
2857 RTE_FLOW_ERROR_TYPE_ITEM,
2859 "VxLAN-GPE protocol"
2861 memcpy(&id.vni[1], spec->vni, 3);
2862 memcpy(&id.vni[1], mask->vni, 3);
2864 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
2865 return rte_flow_error_set(error, ENOTSUP,
2866 RTE_FLOW_ERROR_TYPE_ITEM, item,
2867 "VXLAN-GPE tunnel must be fully"
2872 * Validate GRE Key item.
2875 * Item specification.
2876 * @param[in] item_flags
2877 * Bit flags to mark detected items.
2878 * @param[in] gre_item
2879 * Pointer to gre_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_key(const struct rte_flow_item *item,
2888 uint64_t item_flags,
2889 const struct rte_flow_item *gre_item,
2890 struct rte_flow_error *error)
2892 const rte_be32_t *mask = item->mask;
2894 rte_be32_t gre_key_default_mask = RTE_BE32(UINT32_MAX);
2895 const struct rte_flow_item_gre *gre_spec;
2896 const struct rte_flow_item_gre *gre_mask;
2898 if (item_flags & MLX5_FLOW_LAYER_GRE_KEY)
2899 return rte_flow_error_set(error, ENOTSUP,
2900 RTE_FLOW_ERROR_TYPE_ITEM, item,
2901 "Multiple GRE key not support");
2902 if (!(item_flags & MLX5_FLOW_LAYER_GRE))
2903 return rte_flow_error_set(error, ENOTSUP,
2904 RTE_FLOW_ERROR_TYPE_ITEM, item,
2905 "No preceding GRE header");
2906 if (item_flags & MLX5_FLOW_LAYER_INNER)
2907 return rte_flow_error_set(error, ENOTSUP,
2908 RTE_FLOW_ERROR_TYPE_ITEM, item,
2909 "GRE key following a wrong item");
2910 gre_mask = gre_item->mask;
2912 gre_mask = &rte_flow_item_gre_mask;
2913 gre_spec = gre_item->spec;
2914 if (gre_spec && (gre_mask->c_rsvd0_ver & RTE_BE16(0x2000)) &&
2915 !(gre_spec->c_rsvd0_ver & RTE_BE16(0x2000)))
2916 return rte_flow_error_set(error, EINVAL,
2917 RTE_FLOW_ERROR_TYPE_ITEM, item,
2918 "Key bit must be on");
2921 mask = &gre_key_default_mask;
2922 ret = mlx5_flow_item_acceptable
2923 (item, (const uint8_t *)mask,
2924 (const uint8_t *)&gre_key_default_mask,
2925 sizeof(rte_be32_t), MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2930 * Validate GRE item.
2933 * Item specification.
2934 * @param[in] item_flags
2935 * Bit flags to mark detected items.
2936 * @param[in] target_protocol
2937 * The next protocol in the previous item.
2939 * Pointer to error structure.
2942 * 0 on success, a negative errno value otherwise and rte_errno is set.
2945 mlx5_flow_validate_item_gre(const struct rte_flow_item *item,
2946 uint64_t item_flags,
2947 uint8_t target_protocol,
2948 struct rte_flow_error *error)
2950 const struct rte_flow_item_gre *spec __rte_unused = item->spec;
2951 const struct rte_flow_item_gre *mask = item->mask;
2953 const struct rte_flow_item_gre nic_mask = {
2954 .c_rsvd0_ver = RTE_BE16(0xB000),
2955 .protocol = RTE_BE16(UINT16_MAX),
2958 if (target_protocol != 0xff && target_protocol != IPPROTO_GRE)
2959 return rte_flow_error_set(error, EINVAL,
2960 RTE_FLOW_ERROR_TYPE_ITEM, item,
2961 "protocol filtering not compatible"
2962 " with this GRE layer");
2963 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2964 return rte_flow_error_set(error, ENOTSUP,
2965 RTE_FLOW_ERROR_TYPE_ITEM, item,
2966 "multiple tunnel layers not"
2968 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3))
2969 return rte_flow_error_set(error, ENOTSUP,
2970 RTE_FLOW_ERROR_TYPE_ITEM, item,
2971 "L3 Layer is missing");
2973 mask = &rte_flow_item_gre_mask;
2974 ret = mlx5_flow_item_acceptable
2975 (item, (const uint8_t *)mask,
2976 (const uint8_t *)&nic_mask,
2977 sizeof(struct rte_flow_item_gre), MLX5_ITEM_RANGE_NOT_ACCEPTED,
2981 #ifndef HAVE_MLX5DV_DR
2982 #ifndef HAVE_IBV_DEVICE_MPLS_SUPPORT
2983 if (spec && (spec->protocol & mask->protocol))
2984 return rte_flow_error_set(error, ENOTSUP,
2985 RTE_FLOW_ERROR_TYPE_ITEM, item,
2986 "without MPLS support the"
2987 " specification cannot be used for"
2995 * Validate Geneve item.
2998 * Item specification.
2999 * @param[in] itemFlags
3000 * Bit-fields that holds the items detected until now.
3002 * Pointer to the private data structure.
3004 * Pointer to error structure.
3007 * 0 on success, a negative errno value otherwise and rte_errno is set.
3011 mlx5_flow_validate_item_geneve(const struct rte_flow_item *item,
3012 uint64_t item_flags,
3013 struct rte_eth_dev *dev,
3014 struct rte_flow_error *error)
3016 struct mlx5_priv *priv = dev->data->dev_private;
3017 const struct rte_flow_item_geneve *spec = item->spec;
3018 const struct rte_flow_item_geneve *mask = item->mask;
3021 uint8_t opt_len = priv->sh->cdev->config.hca_attr.geneve_max_opt_len ?
3022 MLX5_GENEVE_OPT_LEN_1 : MLX5_GENEVE_OPT_LEN_0;
3023 const struct rte_flow_item_geneve nic_mask = {
3024 .ver_opt_len_o_c_rsvd0 = RTE_BE16(0x3f80),
3025 .vni = "\xff\xff\xff",
3026 .protocol = RTE_BE16(UINT16_MAX),
3029 if (!priv->sh->cdev->config.hca_attr.tunnel_stateless_geneve_rx)
3030 return rte_flow_error_set(error, ENOTSUP,
3031 RTE_FLOW_ERROR_TYPE_ITEM, item,
3032 "L3 Geneve is not enabled by device"
3033 " parameter and/or not configured in"
3035 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
3036 return rte_flow_error_set(error, ENOTSUP,
3037 RTE_FLOW_ERROR_TYPE_ITEM, item,
3038 "multiple tunnel layers not"
3041 * Verify only UDPv4 is present as defined in
3042 * https://tools.ietf.org/html/rfc7348
3044 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
3045 return rte_flow_error_set(error, EINVAL,
3046 RTE_FLOW_ERROR_TYPE_ITEM, item,
3047 "no outer UDP layer found");
3049 mask = &rte_flow_item_geneve_mask;
3050 ret = mlx5_flow_item_acceptable
3051 (item, (const uint8_t *)mask,
3052 (const uint8_t *)&nic_mask,
3053 sizeof(struct rte_flow_item_geneve),
3054 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
3058 gbhdr = rte_be_to_cpu_16(spec->ver_opt_len_o_c_rsvd0);
3059 if (MLX5_GENEVE_VER_VAL(gbhdr) ||
3060 MLX5_GENEVE_CRITO_VAL(gbhdr) ||
3061 MLX5_GENEVE_RSVD_VAL(gbhdr) || spec->rsvd1)
3062 return rte_flow_error_set(error, ENOTSUP,
3063 RTE_FLOW_ERROR_TYPE_ITEM,
3065 "Geneve protocol unsupported"
3066 " fields are being used");
3067 if (MLX5_GENEVE_OPTLEN_VAL(gbhdr) > opt_len)
3068 return rte_flow_error_set
3070 RTE_FLOW_ERROR_TYPE_ITEM,
3072 "Unsupported Geneve options length");
3074 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
3075 return rte_flow_error_set
3077 RTE_FLOW_ERROR_TYPE_ITEM, item,
3078 "Geneve tunnel must be fully defined");
3083 * Validate Geneve TLV option item.
3086 * Item specification.
3087 * @param[in] last_item
3088 * Previous validated item in the pattern items.
3089 * @param[in] geneve_item
3090 * Previous GENEVE item specification.
3092 * Pointer to the rte_eth_dev structure.
3094 * Pointer to error structure.
3097 * 0 on success, a negative errno value otherwise and rte_errno is set.
3100 mlx5_flow_validate_item_geneve_opt(const struct rte_flow_item *item,
3102 const struct rte_flow_item *geneve_item,
3103 struct rte_eth_dev *dev,
3104 struct rte_flow_error *error)
3106 struct mlx5_priv *priv = dev->data->dev_private;
3107 struct mlx5_dev_ctx_shared *sh = priv->sh;
3108 struct mlx5_geneve_tlv_option_resource *geneve_opt_resource;
3109 struct mlx5_hca_attr *hca_attr = &sh->cdev->config.hca_attr;
3110 uint8_t data_max_supported =
3111 hca_attr->max_geneve_tlv_option_data_len * 4;
3112 const struct rte_flow_item_geneve *geneve_spec;
3113 const struct rte_flow_item_geneve *geneve_mask;
3114 const struct rte_flow_item_geneve_opt *spec = item->spec;
3115 const struct rte_flow_item_geneve_opt *mask = item->mask;
3117 unsigned int data_len;
3118 uint8_t tlv_option_len;
3119 uint16_t optlen_m, optlen_v;
3120 const struct rte_flow_item_geneve_opt full_mask = {
3121 .option_class = RTE_BE16(0xffff),
3122 .option_type = 0xff,
3127 mask = &rte_flow_item_geneve_opt_mask;
3129 return rte_flow_error_set
3130 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
3131 "Geneve TLV opt class/type/length must be specified");
3132 if ((uint32_t)spec->option_len > MLX5_GENEVE_OPTLEN_MASK)
3133 return rte_flow_error_set
3134 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
3135 "Geneve TLV opt length exceeds the limit (31)");
3136 /* Check if class type and length masks are full. */
3137 if (full_mask.option_class != mask->option_class ||
3138 full_mask.option_type != mask->option_type ||
3139 full_mask.option_len != (mask->option_len & full_mask.option_len))
3140 return rte_flow_error_set
3141 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
3142 "Geneve TLV opt class/type/length masks must be full");
3143 /* Check if length is supported */
3144 if ((uint32_t)spec->option_len >
3145 hca_attr->max_geneve_tlv_option_data_len)
3146 return rte_flow_error_set
3147 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
3148 "Geneve TLV opt length not supported");
3149 if (hca_attr->max_geneve_tlv_options > 1)
3151 "max_geneve_tlv_options supports more than 1 option");
3152 /* Check GENEVE item preceding. */
3153 if (!geneve_item || !(last_item & MLX5_FLOW_LAYER_GENEVE))
3154 return rte_flow_error_set
3155 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
3156 "Geneve opt item must be preceded with Geneve item");
3157 geneve_spec = geneve_item->spec;
3158 geneve_mask = geneve_item->mask ? geneve_item->mask :
3159 &rte_flow_item_geneve_mask;
3160 /* Check if GENEVE TLV option size doesn't exceed option length */
3161 if (geneve_spec && (geneve_mask->ver_opt_len_o_c_rsvd0 ||
3162 geneve_spec->ver_opt_len_o_c_rsvd0)) {
3163 tlv_option_len = spec->option_len & mask->option_len;
3164 optlen_v = rte_be_to_cpu_16(geneve_spec->ver_opt_len_o_c_rsvd0);
3165 optlen_v = MLX5_GENEVE_OPTLEN_VAL(optlen_v);
3166 optlen_m = rte_be_to_cpu_16(geneve_mask->ver_opt_len_o_c_rsvd0);
3167 optlen_m = MLX5_GENEVE_OPTLEN_VAL(optlen_m);
3168 if ((optlen_v & optlen_m) <= tlv_option_len)
3169 return rte_flow_error_set
3170 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
3171 "GENEVE TLV option length exceeds optlen");
3173 /* Check if length is 0 or data is 0. */
3174 if (spec->data == NULL || spec->option_len == 0)
3175 return rte_flow_error_set
3176 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
3177 "Geneve TLV opt with zero data/length not supported");
3178 /* Check not all data & mask are 0. */
3179 data_len = spec->option_len * 4;
3180 if (mask->data == NULL) {
3181 for (i = 0; i < data_len; i++)
3185 return rte_flow_error_set(error, ENOTSUP,
3186 RTE_FLOW_ERROR_TYPE_ITEM, item,
3187 "Can't match on Geneve option data 0");
3189 for (i = 0; i < data_len; i++)
3190 if (spec->data[i] & mask->data[i])
3193 return rte_flow_error_set(error, ENOTSUP,
3194 RTE_FLOW_ERROR_TYPE_ITEM, item,
3195 "Can't match on Geneve option data and mask 0");
3196 /* Check data mask supported. */
3197 for (i = data_max_supported; i < data_len ; i++)
3199 return rte_flow_error_set(error, ENOTSUP,
3200 RTE_FLOW_ERROR_TYPE_ITEM, item,
3201 "Data mask is of unsupported size");
3203 /* Check GENEVE option is supported in NIC. */
3204 if (!hca_attr->geneve_tlv_opt)
3205 return rte_flow_error_set
3206 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
3207 "Geneve TLV opt not supported");
3208 /* Check if we already have geneve option with different type/class. */
3209 rte_spinlock_lock(&sh->geneve_tlv_opt_sl);
3210 geneve_opt_resource = sh->geneve_tlv_option_resource;
3211 if (geneve_opt_resource != NULL)
3212 if (geneve_opt_resource->option_class != spec->option_class ||
3213 geneve_opt_resource->option_type != spec->option_type ||
3214 geneve_opt_resource->length != spec->option_len) {
3215 rte_spinlock_unlock(&sh->geneve_tlv_opt_sl);
3216 return rte_flow_error_set(error, ENOTSUP,
3217 RTE_FLOW_ERROR_TYPE_ITEM, item,
3218 "Only one Geneve TLV option supported");
3220 rte_spinlock_unlock(&sh->geneve_tlv_opt_sl);
3225 * Validate MPLS item.
3228 * Pointer to the rte_eth_dev structure.
3230 * Item specification.
3231 * @param[in] item_flags
3232 * Bit-fields that holds the items detected until now.
3233 * @param[in] prev_layer
3234 * The protocol layer indicated in previous item.
3236 * Pointer to error structure.
3239 * 0 on success, a negative errno value otherwise and rte_errno is set.
3242 mlx5_flow_validate_item_mpls(struct rte_eth_dev *dev __rte_unused,
3243 const struct rte_flow_item *item __rte_unused,
3244 uint64_t item_flags __rte_unused,
3245 uint64_t prev_layer __rte_unused,
3246 struct rte_flow_error *error)
3248 #ifdef HAVE_IBV_DEVICE_MPLS_SUPPORT
3249 const struct rte_flow_item_mpls *mask = item->mask;
3250 struct mlx5_priv *priv = dev->data->dev_private;
3253 if (!priv->sh->dev_cap.mpls_en)
3254 return rte_flow_error_set(error, ENOTSUP,
3255 RTE_FLOW_ERROR_TYPE_ITEM, item,
3256 "MPLS not supported or"
3257 " disabled in firmware"
3259 /* MPLS over UDP, GRE is allowed */
3260 if (!(prev_layer & (MLX5_FLOW_LAYER_OUTER_L4_UDP |
3261 MLX5_FLOW_LAYER_GRE |
3262 MLX5_FLOW_LAYER_GRE_KEY)))
3263 return rte_flow_error_set(error, EINVAL,
3264 RTE_FLOW_ERROR_TYPE_ITEM, item,
3265 "protocol filtering not compatible"
3266 " with MPLS layer");
3267 /* Multi-tunnel isn't allowed but MPLS over GRE is an exception. */
3268 if ((item_flags & MLX5_FLOW_LAYER_TUNNEL) &&
3269 !(item_flags & MLX5_FLOW_LAYER_GRE))
3270 return rte_flow_error_set(error, ENOTSUP,
3271 RTE_FLOW_ERROR_TYPE_ITEM, item,
3272 "multiple tunnel layers not"
3275 mask = &rte_flow_item_mpls_mask;
3276 ret = mlx5_flow_item_acceptable
3277 (item, (const uint8_t *)mask,
3278 (const uint8_t *)&rte_flow_item_mpls_mask,
3279 sizeof(struct rte_flow_item_mpls),
3280 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
3285 return rte_flow_error_set(error, ENOTSUP,
3286 RTE_FLOW_ERROR_TYPE_ITEM, item,
3287 "MPLS is not supported by Verbs, please"
3293 * Validate NVGRE item.
3296 * Item specification.
3297 * @param[in] item_flags
3298 * Bit flags to mark detected items.
3299 * @param[in] target_protocol
3300 * The next protocol in the previous item.
3302 * Pointer to error structure.
3305 * 0 on success, a negative errno value otherwise and rte_errno is set.
3308 mlx5_flow_validate_item_nvgre(const struct rte_flow_item *item,
3309 uint64_t item_flags,
3310 uint8_t target_protocol,
3311 struct rte_flow_error *error)
3313 const struct rte_flow_item_nvgre *mask = item->mask;
3316 if (target_protocol != 0xff && target_protocol != IPPROTO_GRE)
3317 return rte_flow_error_set(error, EINVAL,
3318 RTE_FLOW_ERROR_TYPE_ITEM, item,
3319 "protocol filtering not compatible"
3320 " with this GRE layer");
3321 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
3322 return rte_flow_error_set(error, ENOTSUP,
3323 RTE_FLOW_ERROR_TYPE_ITEM, item,
3324 "multiple tunnel layers not"
3326 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3))
3327 return rte_flow_error_set(error, ENOTSUP,
3328 RTE_FLOW_ERROR_TYPE_ITEM, item,
3329 "L3 Layer is missing");
3331 mask = &rte_flow_item_nvgre_mask;
3332 ret = mlx5_flow_item_acceptable
3333 (item, (const uint8_t *)mask,
3334 (const uint8_t *)&rte_flow_item_nvgre_mask,
3335 sizeof(struct rte_flow_item_nvgre),
3336 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
3343 * Validate eCPRI item.
3346 * Item specification.
3347 * @param[in] item_flags
3348 * Bit-fields that holds the items detected until now.
3349 * @param[in] last_item
3350 * Previous validated item in the pattern items.
3351 * @param[in] ether_type
3352 * Type in the ethernet layer header (including dot1q).
3353 * @param[in] acc_mask
3354 * Acceptable mask, if NULL default internal default mask
3355 * will be used to check whether item fields are supported.
3357 * Pointer to error structure.
3360 * 0 on success, a negative errno value otherwise and rte_errno is set.
3363 mlx5_flow_validate_item_ecpri(const struct rte_flow_item *item,
3364 uint64_t item_flags,
3366 uint16_t ether_type,
3367 const struct rte_flow_item_ecpri *acc_mask,
3368 struct rte_flow_error *error)
3370 const struct rte_flow_item_ecpri *mask = item->mask;
3371 const struct rte_flow_item_ecpri nic_mask = {
3375 RTE_BE32(((const struct rte_ecpri_common_hdr) {
3379 .dummy[0] = 0xFFFFFFFF,
3382 const uint64_t outer_l2_vlan = (MLX5_FLOW_LAYER_OUTER_L2 |
3383 MLX5_FLOW_LAYER_OUTER_VLAN);
3384 struct rte_flow_item_ecpri mask_lo;
3386 if (!(last_item & outer_l2_vlan) &&
3387 last_item != MLX5_FLOW_LAYER_OUTER_L4_UDP)
3388 return rte_flow_error_set(error, EINVAL,
3389 RTE_FLOW_ERROR_TYPE_ITEM, item,
3390 "eCPRI can only follow L2/VLAN layer or UDP layer");
3391 if ((last_item & outer_l2_vlan) && ether_type &&
3392 ether_type != RTE_ETHER_TYPE_ECPRI)
3393 return rte_flow_error_set(error, EINVAL,
3394 RTE_FLOW_ERROR_TYPE_ITEM, item,
3395 "eCPRI cannot follow L2/VLAN layer which ether type is not 0xAEFE");
3396 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
3397 return rte_flow_error_set(error, EINVAL,
3398 RTE_FLOW_ERROR_TYPE_ITEM, item,
3399 "eCPRI with tunnel is not supported right now");
3400 if (item_flags & MLX5_FLOW_LAYER_OUTER_L3)
3401 return rte_flow_error_set(error, ENOTSUP,
3402 RTE_FLOW_ERROR_TYPE_ITEM, item,
3403 "multiple L3 layers not supported");
3404 else if (item_flags & MLX5_FLOW_LAYER_OUTER_L4_TCP)
3405 return rte_flow_error_set(error, EINVAL,
3406 RTE_FLOW_ERROR_TYPE_ITEM, item,
3407 "eCPRI cannot coexist with a TCP layer");
3408 /* In specification, eCPRI could be over UDP layer. */
3409 else if (item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP)
3410 return rte_flow_error_set(error, EINVAL,
3411 RTE_FLOW_ERROR_TYPE_ITEM, item,
3412 "eCPRI over UDP layer is not yet supported right now");
3413 /* Mask for type field in common header could be zero. */
3415 mask = &rte_flow_item_ecpri_mask;
3416 mask_lo.hdr.common.u32 = rte_be_to_cpu_32(mask->hdr.common.u32);
3417 /* Input mask is in big-endian format. */
3418 if (mask_lo.hdr.common.type != 0 && mask_lo.hdr.common.type != 0xff)
3419 return rte_flow_error_set(error, EINVAL,
3420 RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
3421 "partial mask is not supported for protocol");
3422 else if (mask_lo.hdr.common.type == 0 && mask->hdr.dummy[0] != 0)
3423 return rte_flow_error_set(error, EINVAL,
3424 RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
3425 "message header mask must be after a type mask");
3426 return mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
3427 acc_mask ? (const uint8_t *)acc_mask
3428 : (const uint8_t *)&nic_mask,
3429 sizeof(struct rte_flow_item_ecpri),
3430 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
3434 flow_null_validate(struct rte_eth_dev *dev __rte_unused,
3435 const struct rte_flow_attr *attr __rte_unused,
3436 const struct rte_flow_item items[] __rte_unused,
3437 const struct rte_flow_action actions[] __rte_unused,
3438 bool external __rte_unused,
3439 int hairpin __rte_unused,
3440 struct rte_flow_error *error)
3442 return rte_flow_error_set(error, ENOTSUP,
3443 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
3446 static struct mlx5_flow *
3447 flow_null_prepare(struct rte_eth_dev *dev __rte_unused,
3448 const struct rte_flow_attr *attr __rte_unused,
3449 const struct rte_flow_item items[] __rte_unused,
3450 const struct rte_flow_action actions[] __rte_unused,
3451 struct rte_flow_error *error)
3453 rte_flow_error_set(error, ENOTSUP,
3454 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
3459 flow_null_translate(struct rte_eth_dev *dev __rte_unused,
3460 struct mlx5_flow *dev_flow __rte_unused,
3461 const struct rte_flow_attr *attr __rte_unused,
3462 const struct rte_flow_item items[] __rte_unused,
3463 const struct rte_flow_action actions[] __rte_unused,
3464 struct rte_flow_error *error)
3466 return rte_flow_error_set(error, ENOTSUP,
3467 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
3471 flow_null_apply(struct rte_eth_dev *dev __rte_unused,
3472 struct rte_flow *flow __rte_unused,
3473 struct rte_flow_error *error)
3475 return rte_flow_error_set(error, ENOTSUP,
3476 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
3480 flow_null_remove(struct rte_eth_dev *dev __rte_unused,
3481 struct rte_flow *flow __rte_unused)
3486 flow_null_destroy(struct rte_eth_dev *dev __rte_unused,
3487 struct rte_flow *flow __rte_unused)
3492 flow_null_query(struct rte_eth_dev *dev __rte_unused,
3493 struct rte_flow *flow __rte_unused,
3494 const struct rte_flow_action *actions __rte_unused,
3495 void *data __rte_unused,
3496 struct rte_flow_error *error)
3498 return rte_flow_error_set(error, ENOTSUP,
3499 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
3503 flow_null_sync_domain(struct rte_eth_dev *dev __rte_unused,
3504 uint32_t domains __rte_unused,
3505 uint32_t flags __rte_unused)
3510 /* Void driver to protect from null pointer reference. */
3511 const struct mlx5_flow_driver_ops mlx5_flow_null_drv_ops = {
3512 .validate = flow_null_validate,
3513 .prepare = flow_null_prepare,
3514 .translate = flow_null_translate,
3515 .apply = flow_null_apply,
3516 .remove = flow_null_remove,
3517 .destroy = flow_null_destroy,
3518 .query = flow_null_query,
3519 .sync_domain = flow_null_sync_domain,
3523 * Select flow driver type according to flow attributes and device
3527 * Pointer to the dev structure.
3529 * Pointer to the flow attributes.
3532 * flow driver type, MLX5_FLOW_TYPE_MAX otherwise.
3534 static enum mlx5_flow_drv_type
3535 flow_get_drv_type(struct rte_eth_dev *dev, const struct rte_flow_attr *attr)
3537 struct mlx5_priv *priv = dev->data->dev_private;
3538 /* The OS can determine first a specific flow type (DV, VERBS) */
3539 enum mlx5_flow_drv_type type = mlx5_flow_os_get_type();
3541 if (type != MLX5_FLOW_TYPE_MAX)
3544 * Currently when dv_flow_en == 2, only HW steering engine is
3545 * supported. New engines can also be chosen here if ready.
3547 if (priv->sh->config.dv_flow_en == 2)
3548 return MLX5_FLOW_TYPE_HW;
3549 /* If no OS specific type - continue with DV/VERBS selection */
3550 if (attr->transfer && priv->sh->config.dv_esw_en)
3551 type = MLX5_FLOW_TYPE_DV;
3552 if (!attr->transfer)
3553 type = priv->sh->config.dv_flow_en ? MLX5_FLOW_TYPE_DV :
3554 MLX5_FLOW_TYPE_VERBS;
3558 #define flow_get_drv_ops(type) flow_drv_ops[type]
3561 * Flow driver validation API. This abstracts calling driver specific functions.
3562 * The type of flow driver is determined according to flow attributes.
3565 * Pointer to the dev structure.
3567 * Pointer to the flow attributes.
3569 * Pointer to the list of items.
3570 * @param[in] actions
3571 * Pointer to the list of actions.
3572 * @param[in] external
3573 * This flow rule is created by request external to PMD.
3574 * @param[in] hairpin
3575 * Number of hairpin TX actions, 0 means classic flow.
3577 * Pointer to the error structure.
3580 * 0 on success, a negative errno value otherwise and rte_errno is set.
3583 flow_drv_validate(struct rte_eth_dev *dev,
3584 const struct rte_flow_attr *attr,
3585 const struct rte_flow_item items[],
3586 const struct rte_flow_action actions[],
3587 bool external, int hairpin, struct rte_flow_error *error)
3589 const struct mlx5_flow_driver_ops *fops;
3590 enum mlx5_flow_drv_type type = flow_get_drv_type(dev, attr);
3592 fops = flow_get_drv_ops(type);
3593 return fops->validate(dev, attr, items, actions, external,
3598 * Flow driver preparation API. This abstracts calling driver specific
3599 * functions. Parent flow (rte_flow) should have driver type (drv_type). It
3600 * calculates the size of memory required for device flow, allocates the memory,
3601 * initializes the device flow and returns the pointer.
3604 * This function initializes device flow structure such as dv or verbs in
3605 * struct mlx5_flow. However, it is caller's responsibility to initialize the
3606 * rest. For example, adding returning device flow to flow->dev_flow list and
3607 * setting backward reference to the flow should be done out of this function.
3608 * layers field is not filled either.
3611 * Pointer to the dev structure.
3613 * Pointer to the flow attributes.
3615 * Pointer to the list of items.
3616 * @param[in] actions
3617 * Pointer to the list of actions.
3618 * @param[in] flow_idx
3619 * This memory pool index to the flow.
3621 * Pointer to the error structure.
3624 * Pointer to device flow on success, otherwise NULL and rte_errno is set.
3626 static inline struct mlx5_flow *
3627 flow_drv_prepare(struct rte_eth_dev *dev,
3628 const struct rte_flow *flow,
3629 const struct rte_flow_attr *attr,
3630 const struct rte_flow_item items[],
3631 const struct rte_flow_action actions[],
3633 struct rte_flow_error *error)
3635 const struct mlx5_flow_driver_ops *fops;
3636 enum mlx5_flow_drv_type type = flow->drv_type;
3637 struct mlx5_flow *mlx5_flow = NULL;
3639 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3640 fops = flow_get_drv_ops(type);
3641 mlx5_flow = fops->prepare(dev, attr, items, actions, error);
3643 mlx5_flow->flow_idx = flow_idx;
3648 * Flow driver translation API. This abstracts calling driver specific
3649 * functions. Parent flow (rte_flow) should have driver type (drv_type). It
3650 * translates a generic flow into a driver flow. flow_drv_prepare() must
3654 * dev_flow->layers could be filled as a result of parsing during translation
3655 * if needed by flow_drv_apply(). dev_flow->flow->actions can also be filled
3656 * if necessary. As a flow can have multiple dev_flows by RSS flow expansion,
3657 * flow->actions could be overwritten even though all the expanded dev_flows
3658 * have the same actions.
3661 * Pointer to the rte dev structure.
3662 * @param[in, out] dev_flow
3663 * Pointer to the mlx5 flow.
3665 * Pointer to the flow attributes.
3667 * Pointer to the list of items.
3668 * @param[in] actions
3669 * Pointer to the list of actions.
3671 * Pointer to the error structure.
3674 * 0 on success, a negative errno value otherwise and rte_errno is set.
3677 flow_drv_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
3678 const struct rte_flow_attr *attr,
3679 const struct rte_flow_item items[],
3680 const struct rte_flow_action actions[],
3681 struct rte_flow_error *error)
3683 const struct mlx5_flow_driver_ops *fops;
3684 enum mlx5_flow_drv_type type = dev_flow->flow->drv_type;
3686 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3687 fops = flow_get_drv_ops(type);
3688 return fops->translate(dev, dev_flow, attr, items, actions, error);
3692 * Flow driver apply API. This abstracts calling driver specific functions.
3693 * Parent flow (rte_flow) should have driver type (drv_type). It applies
3694 * translated driver flows on to device. flow_drv_translate() must precede.
3697 * Pointer to Ethernet device structure.
3698 * @param[in, out] flow
3699 * Pointer to flow structure.
3701 * Pointer to error structure.
3704 * 0 on success, a negative errno value otherwise and rte_errno is set.
3707 flow_drv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
3708 struct rte_flow_error *error)
3710 const struct mlx5_flow_driver_ops *fops;
3711 enum mlx5_flow_drv_type type = flow->drv_type;
3713 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3714 fops = flow_get_drv_ops(type);
3715 return fops->apply(dev, flow, error);
3719 * Flow driver destroy API. This abstracts calling driver specific functions.
3720 * Parent flow (rte_flow) should have driver type (drv_type). It removes a flow
3721 * on device and releases resources of the flow.
3724 * Pointer to Ethernet device.
3725 * @param[in, out] flow
3726 * Pointer to flow structure.
3729 flow_drv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
3731 const struct mlx5_flow_driver_ops *fops;
3732 enum mlx5_flow_drv_type type = flow->drv_type;
3734 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3735 fops = flow_get_drv_ops(type);
3736 fops->destroy(dev, flow);
3740 * Flow driver find RSS policy tbl API. This abstracts calling driver
3741 * specific functions. Parent flow (rte_flow) should have driver
3742 * type (drv_type). It will find the RSS policy table that has the rss_desc.
3745 * Pointer to Ethernet device.
3746 * @param[in, out] flow
3747 * Pointer to flow structure.
3749 * Pointer to meter policy table.
3750 * @param[in] rss_desc
3751 * Pointer to rss_desc
3753 static struct mlx5_flow_meter_sub_policy *
3754 flow_drv_meter_sub_policy_rss_prepare(struct rte_eth_dev *dev,
3755 struct rte_flow *flow,
3756 struct mlx5_flow_meter_policy *policy,
3757 struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS])
3759 const struct mlx5_flow_driver_ops *fops;
3760 enum mlx5_flow_drv_type type = flow->drv_type;
3762 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3763 fops = flow_get_drv_ops(type);
3764 return fops->meter_sub_policy_rss_prepare(dev, policy, rss_desc);
3768 * Flow driver color tag rule API. This abstracts calling driver
3769 * specific functions. Parent flow (rte_flow) should have driver
3770 * type (drv_type). It will create the color tag rules in hierarchy meter.
3773 * Pointer to Ethernet device.
3774 * @param[in, out] flow
3775 * Pointer to flow structure.
3777 * Pointer to flow meter structure.
3778 * @param[in] src_port
3779 * The src port this extra rule should use.
3781 * The src port id match item.
3783 * Pointer to error structure.
3786 flow_drv_mtr_hierarchy_rule_create(struct rte_eth_dev *dev,
3787 struct rte_flow *flow,
3788 struct mlx5_flow_meter_info *fm,
3790 const struct rte_flow_item *item,
3791 struct rte_flow_error *error)
3793 const struct mlx5_flow_driver_ops *fops;
3794 enum mlx5_flow_drv_type type = flow->drv_type;
3796 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3797 fops = flow_get_drv_ops(type);
3798 return fops->meter_hierarchy_rule_create(dev, fm,
3799 src_port, item, error);
3803 * Get RSS action from the action list.
3806 * Pointer to Ethernet device.
3807 * @param[in] actions
3808 * Pointer to the list of actions.
3810 * Parent flow structure pointer.
3813 * Pointer to the RSS action if exist, else return NULL.
3815 static const struct rte_flow_action_rss*
3816 flow_get_rss_action(struct rte_eth_dev *dev,
3817 const struct rte_flow_action actions[])
3819 struct mlx5_priv *priv = dev->data->dev_private;
3820 const struct rte_flow_action_rss *rss = NULL;
3821 struct mlx5_meter_policy_action_container *acg;
3822 struct mlx5_meter_policy_action_container *acy;
3824 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3825 switch (actions->type) {
3826 case RTE_FLOW_ACTION_TYPE_RSS:
3827 rss = actions->conf;
3829 case RTE_FLOW_ACTION_TYPE_SAMPLE:
3831 const struct rte_flow_action_sample *sample =
3833 const struct rte_flow_action *act = sample->actions;
3834 for (; act->type != RTE_FLOW_ACTION_TYPE_END; act++)
3835 if (act->type == RTE_FLOW_ACTION_TYPE_RSS)
3839 case RTE_FLOW_ACTION_TYPE_METER:
3842 struct mlx5_flow_meter_info *fm;
3843 struct mlx5_flow_meter_policy *policy;
3844 const struct rte_flow_action_meter *mtr = actions->conf;
3846 fm = mlx5_flow_meter_find(priv, mtr->mtr_id, &mtr_idx);
3847 if (fm && !fm->def_policy) {
3848 policy = mlx5_flow_meter_policy_find(dev,
3849 fm->policy_id, NULL);
3850 MLX5_ASSERT(policy);
3851 if (policy->is_hierarchy) {
3853 mlx5_flow_meter_hierarchy_get_final_policy(dev,
3858 if (policy->is_rss) {
3860 &policy->act_cnt[RTE_COLOR_GREEN];
3862 &policy->act_cnt[RTE_COLOR_YELLOW];
3863 if (acg->fate_action ==
3864 MLX5_FLOW_FATE_SHARED_RSS)
3865 rss = acg->rss->conf;
3866 else if (acy->fate_action ==
3867 MLX5_FLOW_FATE_SHARED_RSS)
3868 rss = acy->rss->conf;
3881 * Get ASO age action by index.
3884 * Pointer to the Ethernet device structure.
3885 * @param[in] age_idx
3886 * Index to the ASO age action.
3889 * The specified ASO age action.
3891 struct mlx5_aso_age_action*
3892 flow_aso_age_get_by_idx(struct rte_eth_dev *dev, uint32_t age_idx)
3894 uint16_t pool_idx = age_idx & UINT16_MAX;
3895 uint16_t offset = (age_idx >> 16) & UINT16_MAX;
3896 struct mlx5_priv *priv = dev->data->dev_private;
3897 struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
3898 struct mlx5_aso_age_pool *pool;
3900 rte_rwlock_read_lock(&mng->resize_rwl);
3901 pool = mng->pools[pool_idx];
3902 rte_rwlock_read_unlock(&mng->resize_rwl);
3903 return &pool->actions[offset - 1];
3906 /* maps indirect action to translated direct in some actions array */
3907 struct mlx5_translated_action_handle {
3908 struct rte_flow_action_handle *action; /**< Indirect action handle. */
3909 int index; /**< Index in related array of rte_flow_action. */
3913 * Translates actions of type RTE_FLOW_ACTION_TYPE_INDIRECT to related
3914 * direct action if translation possible.
3915 * This functionality used to run same execution path for both direct and
3916 * indirect actions on flow create. All necessary preparations for indirect
3917 * action handling should be performed on *handle* actions list returned
3921 * Pointer to Ethernet device.
3922 * @param[in] actions
3923 * List of actions to translate.
3924 * @param[out] handle
3925 * List to store translated indirect action object handles.
3926 * @param[in, out] indir_n
3927 * Size of *handle* array. On return should be updated with number of
3928 * indirect actions retrieved from the *actions* list.
3929 * @param[out] translated_actions
3930 * List of actions where all indirect actions were translated to direct
3931 * if possible. NULL if no translation took place.
3933 * Pointer to the error structure.
3936 * 0 on success, a negative errno value otherwise and rte_errno is set.
3939 flow_action_handles_translate(struct rte_eth_dev *dev,
3940 const struct rte_flow_action actions[],
3941 struct mlx5_translated_action_handle *handle,
3943 struct rte_flow_action **translated_actions,
3944 struct rte_flow_error *error)
3946 struct mlx5_priv *priv = dev->data->dev_private;
3947 struct rte_flow_action *translated = NULL;
3948 size_t actions_size;
3951 struct mlx5_translated_action_handle *handle_end = NULL;
3953 for (n = 0; actions[n].type != RTE_FLOW_ACTION_TYPE_END; n++) {
3954 if (actions[n].type != RTE_FLOW_ACTION_TYPE_INDIRECT)
3956 if (copied_n == *indir_n) {
3957 return rte_flow_error_set
3958 (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION_NUM,
3959 NULL, "too many shared actions");
3961 rte_memcpy(&handle[copied_n].action, &actions[n].conf,
3962 sizeof(actions[n].conf));
3963 handle[copied_n].index = n;
3967 *indir_n = copied_n;
3970 actions_size = sizeof(struct rte_flow_action) * n;
3971 translated = mlx5_malloc(MLX5_MEM_ZERO, actions_size, 0, SOCKET_ID_ANY);
3976 memcpy(translated, actions, actions_size);
3977 for (handle_end = handle + copied_n; handle < handle_end; handle++) {
3978 struct mlx5_shared_action_rss *shared_rss;
3979 uint32_t act_idx = (uint32_t)(uintptr_t)handle->action;
3980 uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
3981 uint32_t idx = act_idx &
3982 ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
3985 case MLX5_INDIRECT_ACTION_TYPE_RSS:
3986 shared_rss = mlx5_ipool_get
3987 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
3988 translated[handle->index].type =
3989 RTE_FLOW_ACTION_TYPE_RSS;
3990 translated[handle->index].conf =
3991 &shared_rss->origin;
3993 case MLX5_INDIRECT_ACTION_TYPE_COUNT:
3994 translated[handle->index].type =
3995 (enum rte_flow_action_type)
3996 MLX5_RTE_FLOW_ACTION_TYPE_COUNT;
3997 translated[handle->index].conf = (void *)(uintptr_t)idx;
3999 case MLX5_INDIRECT_ACTION_TYPE_AGE:
4000 if (priv->sh->flow_hit_aso_en) {
4001 translated[handle->index].type =
4002 (enum rte_flow_action_type)
4003 MLX5_RTE_FLOW_ACTION_TYPE_AGE;
4004 translated[handle->index].conf =
4005 (void *)(uintptr_t)idx;
4009 case MLX5_INDIRECT_ACTION_TYPE_CT:
4010 if (priv->sh->ct_aso_en) {
4011 translated[handle->index].type =
4012 RTE_FLOW_ACTION_TYPE_CONNTRACK;
4013 translated[handle->index].conf =
4014 (void *)(uintptr_t)idx;
4019 mlx5_free(translated);
4020 return rte_flow_error_set
4021 (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
4022 NULL, "invalid indirect action type");
4025 *translated_actions = translated;
4030 * Get Shared RSS action from the action list.
4033 * Pointer to Ethernet device.
4035 * Pointer to the list of actions.
4036 * @param[in] shared_n
4037 * Actions list length.
4040 * The MLX5 RSS action ID if exists, otherwise return 0.
4043 flow_get_shared_rss_action(struct rte_eth_dev *dev,
4044 struct mlx5_translated_action_handle *handle,
4047 struct mlx5_translated_action_handle *handle_end;
4048 struct mlx5_priv *priv = dev->data->dev_private;
4049 struct mlx5_shared_action_rss *shared_rss;
4052 for (handle_end = handle + shared_n; handle < handle_end; handle++) {
4053 uint32_t act_idx = (uint32_t)(uintptr_t)handle->action;
4054 uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
4055 uint32_t idx = act_idx &
4056 ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
4058 case MLX5_INDIRECT_ACTION_TYPE_RSS:
4059 shared_rss = mlx5_ipool_get
4060 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
4062 __atomic_add_fetch(&shared_rss->refcnt, 1,
4073 find_graph_root(uint32_t rss_level)
4075 return rss_level < 2 ? MLX5_EXPANSION_ROOT :
4076 MLX5_EXPANSION_ROOT_OUTER;
4080 * Get layer flags from the prefix flow.
4082 * Some flows may be split to several subflows, the prefix subflow gets the
4083 * match items and the suffix sub flow gets the actions.
4084 * Some actions need the user defined match item flags to get the detail for
4086 * This function helps the suffix flow to get the item layer flags from prefix
4089 * @param[in] dev_flow
4090 * Pointer the created prefix subflow.
4093 * The layers get from prefix subflow.
4095 static inline uint64_t
4096 flow_get_prefix_layer_flags(struct mlx5_flow *dev_flow)
4098 uint64_t layers = 0;
4101 * Layers bits could be localization, but usually the compiler will
4102 * help to do the optimization work for source code.
4103 * If no decap actions, use the layers directly.
4105 if (!(dev_flow->act_flags & MLX5_FLOW_ACTION_DECAP))
4106 return dev_flow->handle->layers;
4107 /* Convert L3 layers with decap action. */
4108 if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L3_IPV4)
4109 layers |= MLX5_FLOW_LAYER_OUTER_L3_IPV4;
4110 else if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L3_IPV6)
4111 layers |= MLX5_FLOW_LAYER_OUTER_L3_IPV6;
4112 /* Convert L4 layers with decap action. */
4113 if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L4_TCP)
4114 layers |= MLX5_FLOW_LAYER_OUTER_L4_TCP;
4115 else if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L4_UDP)
4116 layers |= MLX5_FLOW_LAYER_OUTER_L4_UDP;
4121 * Get metadata split action information.
4123 * @param[in] actions
4124 * Pointer to the list of actions.
4126 * Pointer to the return pointer.
4127 * @param[out] qrss_type
4128 * Pointer to the action type to return. RTE_FLOW_ACTION_TYPE_END is returned
4129 * if no QUEUE/RSS is found.
4130 * @param[out] encap_idx
4131 * Pointer to the index of the encap action if exists, otherwise the last
4135 * Total number of actions.
4138 flow_parse_metadata_split_actions_info(const struct rte_flow_action actions[],
4139 const struct rte_flow_action **qrss,
4142 const struct rte_flow_action_raw_encap *raw_encap;
4144 int raw_decap_idx = -1;
4147 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4148 switch (actions->type) {
4149 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
4150 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
4151 *encap_idx = actions_n;
4153 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
4154 raw_decap_idx = actions_n;
4156 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
4157 raw_encap = actions->conf;
4158 if (raw_encap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
4159 *encap_idx = raw_decap_idx != -1 ?
4160 raw_decap_idx : actions_n;
4162 case RTE_FLOW_ACTION_TYPE_QUEUE:
4163 case RTE_FLOW_ACTION_TYPE_RSS:
4171 if (*encap_idx == -1)
4172 *encap_idx = actions_n;
4173 /* Count RTE_FLOW_ACTION_TYPE_END. */
4174 return actions_n + 1;
4178 * Check if the action will change packet.
4181 * Pointer to Ethernet device.
4186 * true if action will change packet, false otherwise.
4188 static bool flow_check_modify_action_type(struct rte_eth_dev *dev,
4189 enum rte_flow_action_type type)
4191 struct mlx5_priv *priv = dev->data->dev_private;
4194 case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
4195 case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
4196 case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
4197 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
4198 case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
4199 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
4200 case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
4201 case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
4202 case RTE_FLOW_ACTION_TYPE_DEC_TTL:
4203 case RTE_FLOW_ACTION_TYPE_SET_TTL:
4204 case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
4205 case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
4206 case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
4207 case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
4208 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
4209 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
4210 case RTE_FLOW_ACTION_TYPE_SET_META:
4211 case RTE_FLOW_ACTION_TYPE_SET_TAG:
4212 case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
4213 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
4214 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
4215 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
4216 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
4217 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
4218 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
4219 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
4220 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
4221 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
4222 case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
4224 case RTE_FLOW_ACTION_TYPE_FLAG:
4225 case RTE_FLOW_ACTION_TYPE_MARK:
4226 if (priv->sh->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY)
4236 * Check meter action from the action list.
4239 * Pointer to Ethernet device.
4240 * @param[in] actions
4241 * Pointer to the list of actions.
4242 * @param[out] has_mtr
4243 * Pointer to the meter exist flag.
4244 * @param[out] has_modify
4245 * Pointer to the flag showing there's packet change action.
4246 * @param[out] meter_id
4247 * Pointer to the meter id.
4250 * Total number of actions.
4253 flow_check_meter_action(struct rte_eth_dev *dev,
4254 const struct rte_flow_action actions[],
4255 bool *has_mtr, bool *has_modify, uint32_t *meter_id)
4257 const struct rte_flow_action_meter *mtr = NULL;
4260 MLX5_ASSERT(has_mtr);
4262 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4263 switch (actions->type) {
4264 case RTE_FLOW_ACTION_TYPE_METER:
4265 mtr = actions->conf;
4266 *meter_id = mtr->mtr_id;
4273 *has_modify |= flow_check_modify_action_type(dev,
4277 /* Count RTE_FLOW_ACTION_TYPE_END. */
4278 return actions_n + 1;
4282 * Check if the flow should be split due to hairpin.
4283 * The reason for the split is that in current HW we can't
4284 * support encap and push-vlan on Rx, so if a flow contains
4285 * these actions we move it to Tx.
4288 * Pointer to Ethernet device.
4290 * Flow rule attributes.
4291 * @param[in] actions
4292 * Associated actions (list terminated by the END action).
4295 * > 0 the number of actions and the flow should be split,
4296 * 0 when no split required.
4299 flow_check_hairpin_split(struct rte_eth_dev *dev,
4300 const struct rte_flow_attr *attr,
4301 const struct rte_flow_action actions[])
4303 int queue_action = 0;
4306 const struct rte_flow_action_queue *queue;
4307 const struct rte_flow_action_rss *rss;
4308 const struct rte_flow_action_raw_encap *raw_encap;
4309 const struct rte_eth_hairpin_conf *conf;
4313 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4314 switch (actions->type) {
4315 case RTE_FLOW_ACTION_TYPE_QUEUE:
4316 queue = actions->conf;
4319 conf = mlx5_rxq_get_hairpin_conf(dev, queue->index);
4320 if (conf == NULL || conf->tx_explicit != 0)
4325 case RTE_FLOW_ACTION_TYPE_RSS:
4326 rss = actions->conf;
4327 if (rss == NULL || rss->queue_num == 0)
4329 conf = mlx5_rxq_get_hairpin_conf(dev, rss->queue[0]);
4330 if (conf == NULL || conf->tx_explicit != 0)
4335 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
4336 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
4337 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
4338 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
4339 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
4343 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
4344 raw_encap = actions->conf;
4345 if (raw_encap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
4354 if (split && queue_action)
4359 /* Declare flow create/destroy prototype in advance. */
4361 flow_list_create(struct rte_eth_dev *dev, enum mlx5_flow_type type,
4362 const struct rte_flow_attr *attr,
4363 const struct rte_flow_item items[],
4364 const struct rte_flow_action actions[],
4365 bool external, struct rte_flow_error *error);
4368 flow_list_destroy(struct rte_eth_dev *dev, enum mlx5_flow_type type,
4372 flow_dv_mreg_match_cb(void *tool_ctx __rte_unused,
4373 struct mlx5_list_entry *entry, void *cb_ctx)
4375 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4376 struct mlx5_flow_mreg_copy_resource *mcp_res =
4377 container_of(entry, typeof(*mcp_res), hlist_ent);
4379 return mcp_res->mark_id != *(uint32_t *)(ctx->data);
4382 struct mlx5_list_entry *
4383 flow_dv_mreg_create_cb(void *tool_ctx, void *cb_ctx)
4385 struct rte_eth_dev *dev = tool_ctx;
4386 struct mlx5_priv *priv = dev->data->dev_private;
4387 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4388 struct mlx5_flow_mreg_copy_resource *mcp_res;
4389 struct rte_flow_error *error = ctx->error;
4392 uint32_t mark_id = *(uint32_t *)(ctx->data);
4393 struct rte_flow_attr attr = {
4394 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
4397 struct mlx5_rte_flow_item_tag tag_spec = {
4400 struct rte_flow_item items[] = {
4401 [1] = { .type = RTE_FLOW_ITEM_TYPE_END, },
4403 struct rte_flow_action_mark ftag = {
4406 struct mlx5_flow_action_copy_mreg cp_mreg = {
4410 struct rte_flow_action_jump jump = {
4411 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
4413 struct rte_flow_action actions[] = {
4414 [3] = { .type = RTE_FLOW_ACTION_TYPE_END, },
4417 /* Fill the register fields in the flow. */
4418 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
4422 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_RX, 0, error);
4426 /* Provide the full width of FLAG specific value. */
4427 if (mark_id == (priv->sh->dv_regc0_mask & MLX5_FLOW_MARK_DEFAULT))
4428 tag_spec.data = MLX5_FLOW_MARK_DEFAULT;
4429 /* Build a new flow. */
4430 if (mark_id != MLX5_DEFAULT_COPY_ID) {
4431 items[0] = (struct rte_flow_item){
4432 .type = (enum rte_flow_item_type)
4433 MLX5_RTE_FLOW_ITEM_TYPE_TAG,
4436 items[1] = (struct rte_flow_item){
4437 .type = RTE_FLOW_ITEM_TYPE_END,
4439 actions[0] = (struct rte_flow_action){
4440 .type = (enum rte_flow_action_type)
4441 MLX5_RTE_FLOW_ACTION_TYPE_MARK,
4444 actions[1] = (struct rte_flow_action){
4445 .type = (enum rte_flow_action_type)
4446 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
4449 actions[2] = (struct rte_flow_action){
4450 .type = RTE_FLOW_ACTION_TYPE_JUMP,
4453 actions[3] = (struct rte_flow_action){
4454 .type = RTE_FLOW_ACTION_TYPE_END,
4457 /* Default rule, wildcard match. */
4458 attr.priority = MLX5_FLOW_LOWEST_PRIO_INDICATOR;
4459 items[0] = (struct rte_flow_item){
4460 .type = RTE_FLOW_ITEM_TYPE_END,
4462 actions[0] = (struct rte_flow_action){
4463 .type = (enum rte_flow_action_type)
4464 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
4467 actions[1] = (struct rte_flow_action){
4468 .type = RTE_FLOW_ACTION_TYPE_JUMP,
4471 actions[2] = (struct rte_flow_action){
4472 .type = RTE_FLOW_ACTION_TYPE_END,
4475 /* Build a new entry. */
4476 mcp_res = mlx5_ipool_zmalloc(priv->sh->ipool[MLX5_IPOOL_MCP], &idx);
4482 mcp_res->mark_id = mark_id;
4484 * The copy Flows are not included in any list. There
4485 * ones are referenced from other Flows and can not
4486 * be applied, removed, deleted in arbitrary order
4487 * by list traversing.
4489 mcp_res->rix_flow = flow_list_create(dev, MLX5_FLOW_TYPE_MCP,
4490 &attr, items, actions, false, error);
4491 if (!mcp_res->rix_flow) {
4492 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], idx);
4495 return &mcp_res->hlist_ent;
4498 struct mlx5_list_entry *
4499 flow_dv_mreg_clone_cb(void *tool_ctx, struct mlx5_list_entry *oentry,
4500 void *cb_ctx __rte_unused)
4502 struct rte_eth_dev *dev = tool_ctx;
4503 struct mlx5_priv *priv = dev->data->dev_private;
4504 struct mlx5_flow_mreg_copy_resource *mcp_res;
4507 mcp_res = mlx5_ipool_malloc(priv->sh->ipool[MLX5_IPOOL_MCP], &idx);
4512 memcpy(mcp_res, oentry, sizeof(*mcp_res));
4514 return &mcp_res->hlist_ent;
4518 flow_dv_mreg_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
4520 struct mlx5_flow_mreg_copy_resource *mcp_res =
4521 container_of(entry, typeof(*mcp_res), hlist_ent);
4522 struct rte_eth_dev *dev = tool_ctx;
4523 struct mlx5_priv *priv = dev->data->dev_private;
4525 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], mcp_res->idx);
4529 * Add a flow of copying flow metadata registers in RX_CP_TBL.
4531 * As mark_id is unique, if there's already a registered flow for the mark_id,
4532 * return by increasing the reference counter of the resource. Otherwise, create
4533 * the resource (mcp_res) and flow.
4536 * - If ingress port is ANY and reg_c[1] is mark_id,
4537 * flow_tag := mark_id, reg_b := reg_c[0] and jump to RX_ACT_TBL.
4539 * For default flow (zero mark_id), flow is like,
4540 * - If ingress port is ANY,
4541 * reg_b := reg_c[0] and jump to RX_ACT_TBL.
4544 * Pointer to Ethernet device.
4546 * ID of MARK action, zero means default flow for META.
4548 * Perform verbose error reporting if not NULL.
4551 * Associated resource on success, NULL otherwise and rte_errno is set.
4553 static struct mlx5_flow_mreg_copy_resource *
4554 flow_mreg_add_copy_action(struct rte_eth_dev *dev, uint32_t mark_id,
4555 struct rte_flow_error *error)
4557 struct mlx5_priv *priv = dev->data->dev_private;
4558 struct mlx5_list_entry *entry;
4559 struct mlx5_flow_cb_ctx ctx = {
4565 /* Check if already registered. */
4566 MLX5_ASSERT(priv->mreg_cp_tbl);
4567 entry = mlx5_hlist_register(priv->mreg_cp_tbl, mark_id, &ctx);
4570 return container_of(entry, struct mlx5_flow_mreg_copy_resource,
4575 flow_dv_mreg_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
4577 struct mlx5_flow_mreg_copy_resource *mcp_res =
4578 container_of(entry, typeof(*mcp_res), hlist_ent);
4579 struct rte_eth_dev *dev = tool_ctx;
4580 struct mlx5_priv *priv = dev->data->dev_private;
4582 MLX5_ASSERT(mcp_res->rix_flow);
4583 flow_list_destroy(dev, MLX5_FLOW_TYPE_MCP, mcp_res->rix_flow);
4584 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], mcp_res->idx);
4588 * Release flow in RX_CP_TBL.
4591 * Pointer to Ethernet device.
4593 * Parent flow for wich copying is provided.
4596 flow_mreg_del_copy_action(struct rte_eth_dev *dev,
4597 struct rte_flow *flow)
4599 struct mlx5_flow_mreg_copy_resource *mcp_res;
4600 struct mlx5_priv *priv = dev->data->dev_private;
4602 if (!flow->rix_mreg_copy)
4604 mcp_res = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MCP],
4605 flow->rix_mreg_copy);
4606 if (!mcp_res || !priv->mreg_cp_tbl)
4608 MLX5_ASSERT(mcp_res->rix_flow);
4609 mlx5_hlist_unregister(priv->mreg_cp_tbl, &mcp_res->hlist_ent);
4610 flow->rix_mreg_copy = 0;
4614 * Remove the default copy action from RX_CP_TBL.
4616 * This functions is called in the mlx5_dev_start(). No thread safe
4620 * Pointer to Ethernet device.
4623 flow_mreg_del_default_copy_action(struct rte_eth_dev *dev)
4625 struct mlx5_list_entry *entry;
4626 struct mlx5_priv *priv = dev->data->dev_private;
4627 struct mlx5_flow_cb_ctx ctx;
4630 /* Check if default flow is registered. */
4631 if (!priv->mreg_cp_tbl)
4633 mark_id = MLX5_DEFAULT_COPY_ID;
4634 ctx.data = &mark_id;
4635 entry = mlx5_hlist_lookup(priv->mreg_cp_tbl, mark_id, &ctx);
4638 mlx5_hlist_unregister(priv->mreg_cp_tbl, entry);
4642 * Add the default copy action in in RX_CP_TBL.
4644 * This functions is called in the mlx5_dev_start(). No thread safe
4648 * Pointer to Ethernet device.
4650 * Perform verbose error reporting if not NULL.
4653 * 0 for success, negative value otherwise and rte_errno is set.
4656 flow_mreg_add_default_copy_action(struct rte_eth_dev *dev,
4657 struct rte_flow_error *error)
4659 struct mlx5_priv *priv = dev->data->dev_private;
4660 struct mlx5_flow_mreg_copy_resource *mcp_res;
4661 struct mlx5_flow_cb_ctx ctx;
4664 /* Check whether extensive metadata feature is engaged. */
4665 if (!priv->sh->config.dv_flow_en ||
4666 priv->sh->config.dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
4667 !mlx5_flow_ext_mreg_supported(dev) ||
4668 !priv->sh->dv_regc0_mask)
4671 * Add default mreg copy flow may be called multiple time, but
4672 * only be called once in stop. Avoid register it twice.
4674 mark_id = MLX5_DEFAULT_COPY_ID;
4675 ctx.data = &mark_id;
4676 if (mlx5_hlist_lookup(priv->mreg_cp_tbl, mark_id, &ctx))
4678 mcp_res = flow_mreg_add_copy_action(dev, mark_id, error);
4685 * Add a flow of copying flow metadata registers in RX_CP_TBL.
4687 * All the flow having Q/RSS action should be split by
4688 * flow_mreg_split_qrss_prep() to pass by RX_CP_TBL. A flow in the RX_CP_TBL
4689 * performs the following,
4690 * - CQE->flow_tag := reg_c[1] (MARK)
4691 * - CQE->flow_table_metadata (reg_b) := reg_c[0] (META)
4692 * As CQE's flow_tag is not a register, it can't be simply copied from reg_c[1]
4693 * but there should be a flow per each MARK ID set by MARK action.
4695 * For the aforementioned reason, if there's a MARK action in flow's action
4696 * list, a corresponding flow should be added to the RX_CP_TBL in order to copy
4697 * the MARK ID to CQE's flow_tag like,
4698 * - If reg_c[1] is mark_id,
4699 * flow_tag := mark_id, reg_b := reg_c[0] and jump to RX_ACT_TBL.
4701 * For SET_META action which stores value in reg_c[0], as the destination is
4702 * also a flow metadata register (reg_b), adding a default flow is enough. Zero
4703 * MARK ID means the default flow. The default flow looks like,
4704 * - For all flow, reg_b := reg_c[0] and jump to RX_ACT_TBL.
4707 * Pointer to Ethernet device.
4709 * Pointer to flow structure.
4710 * @param[in] actions
4711 * Pointer to the list of actions.
4713 * Perform verbose error reporting if not NULL.
4716 * 0 on success, negative value otherwise and rte_errno is set.
4719 flow_mreg_update_copy_table(struct rte_eth_dev *dev,
4720 struct rte_flow *flow,
4721 const struct rte_flow_action *actions,
4722 struct rte_flow_error *error)
4724 struct mlx5_priv *priv = dev->data->dev_private;
4725 struct mlx5_sh_config *config = &priv->sh->config;
4726 struct mlx5_flow_mreg_copy_resource *mcp_res;
4727 const struct rte_flow_action_mark *mark;
4729 /* Check whether extensive metadata feature is engaged. */
4730 if (!config->dv_flow_en ||
4731 config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
4732 !mlx5_flow_ext_mreg_supported(dev) ||
4733 !priv->sh->dv_regc0_mask)
4735 /* Find MARK action. */
4736 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4737 switch (actions->type) {
4738 case RTE_FLOW_ACTION_TYPE_FLAG:
4739 mcp_res = flow_mreg_add_copy_action
4740 (dev, MLX5_FLOW_MARK_DEFAULT, error);
4743 flow->rix_mreg_copy = mcp_res->idx;
4745 case RTE_FLOW_ACTION_TYPE_MARK:
4746 mark = (const struct rte_flow_action_mark *)
4749 flow_mreg_add_copy_action(dev, mark->id, error);
4752 flow->rix_mreg_copy = mcp_res->idx;
4761 #define MLX5_MAX_SPLIT_ACTIONS 24
4762 #define MLX5_MAX_SPLIT_ITEMS 24
4765 * Split the hairpin flow.
4766 * Since HW can't support encap and push-vlan on Rx, we move these
4768 * If the count action is after the encap then we also
4769 * move the count action. in this case the count will also measure
4773 * Pointer to Ethernet device.
4774 * @param[in] actions
4775 * Associated actions (list terminated by the END action).
4776 * @param[out] actions_rx
4778 * @param[out] actions_tx
4780 * @param[out] pattern_tx
4781 * The pattern items for the Tx flow.
4782 * @param[out] flow_id
4783 * The flow ID connected to this flow.
4789 flow_hairpin_split(struct rte_eth_dev *dev,
4790 const struct rte_flow_action actions[],
4791 struct rte_flow_action actions_rx[],
4792 struct rte_flow_action actions_tx[],
4793 struct rte_flow_item pattern_tx[],
4796 const struct rte_flow_action_raw_encap *raw_encap;
4797 const struct rte_flow_action_raw_decap *raw_decap;
4798 struct mlx5_rte_flow_action_set_tag *set_tag;
4799 struct rte_flow_action *tag_action;
4800 struct mlx5_rte_flow_item_tag *tag_item;
4801 struct rte_flow_item *item;
4805 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4806 switch (actions->type) {
4807 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
4808 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
4809 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
4810 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
4811 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
4812 rte_memcpy(actions_tx, actions,
4813 sizeof(struct rte_flow_action));
4816 case RTE_FLOW_ACTION_TYPE_COUNT:
4818 rte_memcpy(actions_tx, actions,
4819 sizeof(struct rte_flow_action));
4822 rte_memcpy(actions_rx, actions,
4823 sizeof(struct rte_flow_action));
4827 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
4828 raw_encap = actions->conf;
4829 if (raw_encap->size > MLX5_ENCAPSULATION_DECISION_SIZE) {
4830 memcpy(actions_tx, actions,
4831 sizeof(struct rte_flow_action));
4835 rte_memcpy(actions_rx, actions,
4836 sizeof(struct rte_flow_action));
4840 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
4841 raw_decap = actions->conf;
4842 if (raw_decap->size < MLX5_ENCAPSULATION_DECISION_SIZE) {
4843 memcpy(actions_tx, actions,
4844 sizeof(struct rte_flow_action));
4847 rte_memcpy(actions_rx, actions,
4848 sizeof(struct rte_flow_action));
4853 rte_memcpy(actions_rx, actions,
4854 sizeof(struct rte_flow_action));
4859 /* Add set meta action and end action for the Rx flow. */
4860 tag_action = actions_rx;
4861 tag_action->type = (enum rte_flow_action_type)
4862 MLX5_RTE_FLOW_ACTION_TYPE_TAG;
4864 rte_memcpy(actions_rx, actions, sizeof(struct rte_flow_action));
4866 set_tag = (void *)actions_rx;
4867 *set_tag = (struct mlx5_rte_flow_action_set_tag) {
4868 .id = mlx5_flow_get_reg_id(dev, MLX5_HAIRPIN_RX, 0, NULL),
4871 MLX5_ASSERT(set_tag->id > REG_NON);
4872 tag_action->conf = set_tag;
4873 /* Create Tx item list. */
4874 rte_memcpy(actions_tx, actions, sizeof(struct rte_flow_action));
4875 addr = (void *)&pattern_tx[2];
4877 item->type = (enum rte_flow_item_type)
4878 MLX5_RTE_FLOW_ITEM_TYPE_TAG;
4879 tag_item = (void *)addr;
4880 tag_item->data = flow_id;
4881 tag_item->id = mlx5_flow_get_reg_id(dev, MLX5_HAIRPIN_TX, 0, NULL);
4882 MLX5_ASSERT(set_tag->id > REG_NON);
4883 item->spec = tag_item;
4884 addr += sizeof(struct mlx5_rte_flow_item_tag);
4885 tag_item = (void *)addr;
4886 tag_item->data = UINT32_MAX;
4887 tag_item->id = UINT16_MAX;
4888 item->mask = tag_item;
4891 item->type = RTE_FLOW_ITEM_TYPE_END;
4896 * The last stage of splitting chain, just creates the subflow
4897 * without any modification.
4900 * Pointer to Ethernet device.
4902 * Parent flow structure pointer.
4903 * @param[in, out] sub_flow
4904 * Pointer to return the created subflow, may be NULL.
4906 * Flow rule attributes.
4908 * Pattern specification (list terminated by the END pattern item).
4909 * @param[in] actions
4910 * Associated actions (list terminated by the END action).
4911 * @param[in] flow_split_info
4912 * Pointer to flow split info structure.
4914 * Perform verbose error reporting if not NULL.
4916 * 0 on success, negative value otherwise
4919 flow_create_split_inner(struct rte_eth_dev *dev,
4920 struct rte_flow *flow,
4921 struct mlx5_flow **sub_flow,
4922 const struct rte_flow_attr *attr,
4923 const struct rte_flow_item items[],
4924 const struct rte_flow_action actions[],
4925 struct mlx5_flow_split_info *flow_split_info,
4926 struct rte_flow_error *error)
4928 struct mlx5_flow *dev_flow;
4929 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
4931 dev_flow = flow_drv_prepare(dev, flow, attr, items, actions,
4932 flow_split_info->flow_idx, error);
4935 dev_flow->flow = flow;
4936 dev_flow->external = flow_split_info->external;
4937 dev_flow->skip_scale = flow_split_info->skip_scale;
4938 /* Subflow object was created, we must include one in the list. */
4939 SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
4940 dev_flow->handle, next);
4942 * If dev_flow is as one of the suffix flow, some actions in suffix
4943 * flow may need some user defined item layer flags, and pass the
4944 * Metadata rxq mark flag to suffix flow as well.
4946 if (flow_split_info->prefix_layers)
4947 dev_flow->handle->layers = flow_split_info->prefix_layers;
4948 if (flow_split_info->prefix_mark) {
4953 *sub_flow = dev_flow;
4954 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
4955 dev_flow->dv.table_id = flow_split_info->table_id;
4957 return flow_drv_translate(dev, dev_flow, attr, items, actions, error);
4961 * Get the sub policy of a meter.
4964 * Pointer to Ethernet device.
4966 * Parent flow structure pointer.
4968 * Pointer to thread flow work space.
4970 * Flow rule attributes.
4972 * Pattern specification (list terminated by the END pattern item).
4974 * Perform verbose error reporting if not NULL.
4977 * Pointer to the meter sub policy, NULL otherwise and rte_errno is set.
4979 static struct mlx5_flow_meter_sub_policy *
4980 get_meter_sub_policy(struct rte_eth_dev *dev,
4981 struct rte_flow *flow,
4982 struct mlx5_flow_workspace *wks,
4983 const struct rte_flow_attr *attr,
4984 const struct rte_flow_item items[],
4985 struct rte_flow_error *error)
4987 struct mlx5_flow_meter_policy *policy;
4988 struct mlx5_flow_meter_policy *final_policy;
4989 struct mlx5_flow_meter_sub_policy *sub_policy = NULL;
4991 policy = wks->policy;
4992 final_policy = policy->is_hierarchy ? wks->final_policy : policy;
4993 if (final_policy->is_rss || final_policy->is_queue) {
4994 struct mlx5_flow_rss_desc rss_desc_v[MLX5_MTR_RTE_COLORS];
4995 struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS] = {0};
4999 * This is a tmp dev_flow,
5000 * no need to register any matcher for it in translate.
5002 wks->skip_matcher_reg = 1;
5003 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
5004 struct mlx5_flow dev_flow = {0};
5005 struct mlx5_flow_handle dev_handle = { {0} };
5006 uint8_t fate = final_policy->act_cnt[i].fate_action;
5008 if (fate == MLX5_FLOW_FATE_SHARED_RSS) {
5009 const struct rte_flow_action_rss *rss_act =
5010 final_policy->act_cnt[i].rss->conf;
5011 struct rte_flow_action rss_actions[2] = {
5013 .type = RTE_FLOW_ACTION_TYPE_RSS,
5017 .type = RTE_FLOW_ACTION_TYPE_END,
5022 dev_flow.handle = &dev_handle;
5023 dev_flow.ingress = attr->ingress;
5024 dev_flow.flow = flow;
5025 dev_flow.external = 0;
5026 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
5027 dev_flow.dv.transfer = attr->transfer;
5030 * Translate RSS action to get rss hash fields.
5032 if (flow_drv_translate(dev, &dev_flow, attr,
5033 items, rss_actions, error))
5035 rss_desc_v[i] = wks->rss_desc;
5036 rss_desc_v[i].key_len = MLX5_RSS_HASH_KEY_LEN;
5037 rss_desc_v[i].hash_fields =
5038 dev_flow.hash_fields;
5039 rss_desc_v[i].queue_num =
5040 rss_desc_v[i].hash_fields ?
5041 rss_desc_v[i].queue_num : 1;
5042 rss_desc_v[i].tunnel =
5043 !!(dev_flow.handle->layers &
5044 MLX5_FLOW_LAYER_TUNNEL);
5045 /* Use the RSS queues in the containers. */
5046 rss_desc_v[i].queue =
5047 (uint16_t *)(uintptr_t)rss_act->queue;
5048 rss_desc[i] = &rss_desc_v[i];
5049 } else if (fate == MLX5_FLOW_FATE_QUEUE) {
5050 /* This is queue action. */
5051 rss_desc_v[i] = wks->rss_desc;
5052 rss_desc_v[i].key_len = 0;
5053 rss_desc_v[i].hash_fields = 0;
5054 rss_desc_v[i].queue =
5055 &final_policy->act_cnt[i].queue;
5056 rss_desc_v[i].queue_num = 1;
5057 rss_desc[i] = &rss_desc_v[i];
5062 sub_policy = flow_drv_meter_sub_policy_rss_prepare(dev,
5063 flow, policy, rss_desc);
5065 enum mlx5_meter_domain mtr_domain =
5066 attr->transfer ? MLX5_MTR_DOMAIN_TRANSFER :
5067 (attr->egress ? MLX5_MTR_DOMAIN_EGRESS :
5068 MLX5_MTR_DOMAIN_INGRESS);
5069 sub_policy = policy->sub_policys[mtr_domain][0];
5072 rte_flow_error_set(error, EINVAL,
5073 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
5074 "Failed to get meter sub-policy.");
5080 * Split the meter flow.
5082 * As meter flow will split to three sub flow, other than meter
5083 * action, the other actions make sense to only meter accepts
5084 * the packet. If it need to be dropped, no other additional
5085 * actions should be take.
5087 * One kind of special action which decapsulates the L3 tunnel
5088 * header will be in the prefix sub flow, as not to take the
5089 * L3 tunnel header into account.
5092 * Pointer to Ethernet device.
5094 * Parent flow structure pointer.
5096 * Pointer to thread flow work space.
5098 * Flow rule attributes.
5100 * Pattern specification (list terminated by the END pattern item).
5101 * @param[out] sfx_items
5102 * Suffix flow match items (list terminated by the END pattern item).
5103 * @param[in] actions
5104 * Associated actions (list terminated by the END action).
5105 * @param[out] actions_sfx
5106 * Suffix flow actions.
5107 * @param[out] actions_pre
5108 * Prefix flow actions.
5109 * @param[out] mtr_flow_id
5110 * Pointer to meter flow id.
5112 * Perform verbose error reporting if not NULL.
5115 * 0 on success, a negative errno value otherwise and rte_errno is set.
5118 flow_meter_split_prep(struct rte_eth_dev *dev,
5119 struct rte_flow *flow,
5120 struct mlx5_flow_workspace *wks,
5121 const struct rte_flow_attr *attr,
5122 const struct rte_flow_item items[],
5123 struct rte_flow_item sfx_items[],
5124 const struct rte_flow_action actions[],
5125 struct rte_flow_action actions_sfx[],
5126 struct rte_flow_action actions_pre[],
5127 uint32_t *mtr_flow_id,
5128 struct rte_flow_error *error)
5130 struct mlx5_priv *priv = dev->data->dev_private;
5131 struct mlx5_flow_meter_info *fm = wks->fm;
5132 struct rte_flow_action *tag_action = NULL;
5133 struct rte_flow_item *tag_item;
5134 struct mlx5_rte_flow_action_set_tag *set_tag;
5135 const struct rte_flow_action_raw_encap *raw_encap;
5136 const struct rte_flow_action_raw_decap *raw_decap;
5137 struct mlx5_rte_flow_item_tag *tag_item_spec;
5138 struct mlx5_rte_flow_item_tag *tag_item_mask;
5139 uint32_t tag_id = 0;
5140 struct rte_flow_item *vlan_item_dst = NULL;
5141 const struct rte_flow_item *vlan_item_src = NULL;
5142 const struct rte_flow_item *orig_items = items;
5143 struct rte_flow_action *hw_mtr_action;
5144 struct rte_flow_action *action_pre_head = NULL;
5145 int32_t flow_src_port = priv->representor_id;
5147 uint8_t mtr_id_offset = priv->mtr_reg_share ? MLX5_MTR_COLOR_BITS : 0;
5148 uint8_t mtr_reg_bits = priv->mtr_reg_share ?
5149 MLX5_MTR_IDLE_BITS_IN_COLOR_REG : MLX5_REG_BITS;
5150 uint32_t flow_id = 0;
5151 uint32_t flow_id_reversed = 0;
5152 uint8_t flow_id_bits = 0;
5155 /* Prepare the suffix subflow items. */
5156 tag_item = sfx_items++;
5157 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
5158 struct mlx5_priv *port_priv;
5159 const struct rte_flow_item_port_id *pid_v;
5160 int item_type = items->type;
5162 switch (item_type) {
5163 case RTE_FLOW_ITEM_TYPE_PORT_ID:
5164 pid_v = items->spec;
5166 port_priv = mlx5_port_to_eswitch_info(pid_v->id, false);
5168 return rte_flow_error_set(error,
5170 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
5172 "Failed to get port info.");
5173 flow_src_port = port_priv->representor_id;
5174 if (!fm->def_policy && wks->policy->is_hierarchy &&
5175 flow_src_port != priv->representor_id) {
5176 if (flow_drv_mtr_hierarchy_rule_create(dev,
5183 memcpy(sfx_items, items, sizeof(*sfx_items));
5186 case RTE_FLOW_ITEM_TYPE_VLAN:
5187 /* Determine if copy vlan item below. */
5188 vlan_item_src = items;
5189 vlan_item_dst = sfx_items++;
5190 vlan_item_dst->type = RTE_FLOW_ITEM_TYPE_VOID;
5196 sfx_items->type = RTE_FLOW_ITEM_TYPE_END;
5198 mtr_first = priv->sh->meter_aso_en &&
5199 (attr->egress || (attr->transfer && flow_src_port != UINT16_MAX));
5200 /* For ASO meter, meter must be before tag in TX direction. */
5202 action_pre_head = actions_pre++;
5203 /* Leave space for tag action. */
5204 tag_action = actions_pre++;
5206 /* Prepare the actions for prefix and suffix flow. */
5207 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
5208 struct rte_flow_action *action_cur = NULL;
5210 switch (actions->type) {
5211 case RTE_FLOW_ACTION_TYPE_METER:
5213 action_cur = action_pre_head;
5215 /* Leave space for tag action. */
5216 tag_action = actions_pre++;
5217 action_cur = actions_pre++;
5220 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
5221 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
5222 action_cur = actions_pre++;
5224 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
5225 raw_encap = actions->conf;
5226 if (raw_encap->size < MLX5_ENCAPSULATION_DECISION_SIZE)
5227 action_cur = actions_pre++;
5229 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
5230 raw_decap = actions->conf;
5231 if (raw_decap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
5232 action_cur = actions_pre++;
5234 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
5235 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
5236 if (vlan_item_dst && vlan_item_src) {
5237 memcpy(vlan_item_dst, vlan_item_src,
5238 sizeof(*vlan_item_dst));
5240 * Convert to internal match item, it is used
5241 * for vlan push and set vid.
5243 vlan_item_dst->type = (enum rte_flow_item_type)
5244 MLX5_RTE_FLOW_ITEM_TYPE_VLAN;
5251 action_cur = (fm->def_policy) ?
5252 actions_sfx++ : actions_pre++;
5253 memcpy(action_cur, actions, sizeof(struct rte_flow_action));
5255 /* Add end action to the actions. */
5256 actions_sfx->type = RTE_FLOW_ACTION_TYPE_END;
5257 if (priv->sh->meter_aso_en) {
5259 * For ASO meter, need to add an extra jump action explicitly,
5260 * to jump from meter to policer table.
5262 struct mlx5_flow_meter_sub_policy *sub_policy;
5263 struct mlx5_flow_tbl_data_entry *tbl_data;
5265 if (!fm->def_policy) {
5266 sub_policy = get_meter_sub_policy(dev, flow, wks,
5272 enum mlx5_meter_domain mtr_domain =
5273 attr->transfer ? MLX5_MTR_DOMAIN_TRANSFER :
5274 (attr->egress ? MLX5_MTR_DOMAIN_EGRESS :
5275 MLX5_MTR_DOMAIN_INGRESS);
5278 &priv->sh->mtrmng->def_policy[mtr_domain]->sub_policy;
5280 tbl_data = container_of(sub_policy->tbl_rsc,
5281 struct mlx5_flow_tbl_data_entry, tbl);
5282 hw_mtr_action = actions_pre++;
5283 hw_mtr_action->type = (enum rte_flow_action_type)
5284 MLX5_RTE_FLOW_ACTION_TYPE_JUMP;
5285 hw_mtr_action->conf = tbl_data->jump.action;
5287 actions_pre->type = RTE_FLOW_ACTION_TYPE_END;
5290 return rte_flow_error_set(error, ENOMEM,
5291 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5292 NULL, "No tag action space.");
5294 tag_action->type = RTE_FLOW_ACTION_TYPE_VOID;
5297 /* Only default-policy Meter creates mtr flow id. */
5298 if (fm->def_policy) {
5299 mlx5_ipool_malloc(fm->flow_ipool, &tag_id);
5301 return rte_flow_error_set(error, ENOMEM,
5302 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
5303 "Failed to allocate meter flow id.");
5304 flow_id = tag_id - 1;
5305 flow_id_bits = (!flow_id) ? 1 :
5306 (MLX5_REG_BITS - __builtin_clz(flow_id));
5307 if ((flow_id_bits + priv->sh->mtrmng->max_mtr_bits) >
5309 mlx5_ipool_free(fm->flow_ipool, tag_id);
5310 return rte_flow_error_set(error, EINVAL,
5311 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
5312 "Meter flow id exceeds max limit.");
5314 if (flow_id_bits > priv->sh->mtrmng->max_mtr_flow_bits)
5315 priv->sh->mtrmng->max_mtr_flow_bits = flow_id_bits;
5317 /* Build tag actions and items for meter_id/meter flow_id. */
5318 set_tag = (struct mlx5_rte_flow_action_set_tag *)actions_pre;
5319 tag_item_spec = (struct mlx5_rte_flow_item_tag *)sfx_items;
5320 tag_item_mask = tag_item_spec + 1;
5321 /* Both flow_id and meter_id share the same register. */
5322 *set_tag = (struct mlx5_rte_flow_action_set_tag) {
5323 .id = (enum modify_reg)mlx5_flow_get_reg_id(dev, MLX5_MTR_ID,
5325 .offset = mtr_id_offset,
5326 .length = mtr_reg_bits,
5327 .data = flow->meter,
5330 * The color Reg bits used by flow_id are growing from
5331 * msb to lsb, so must do bit reverse for flow_id val in RegC.
5333 for (shift = 0; shift < flow_id_bits; shift++)
5334 flow_id_reversed = (flow_id_reversed << 1) |
5335 ((flow_id >> shift) & 0x1);
5337 flow_id_reversed << (mtr_reg_bits - flow_id_bits);
5338 tag_item_spec->id = set_tag->id;
5339 tag_item_spec->data = set_tag->data << mtr_id_offset;
5340 tag_item_mask->data = UINT32_MAX << mtr_id_offset;
5341 tag_action->type = (enum rte_flow_action_type)
5342 MLX5_RTE_FLOW_ACTION_TYPE_TAG;
5343 tag_action->conf = set_tag;
5344 tag_item->type = (enum rte_flow_item_type)
5345 MLX5_RTE_FLOW_ITEM_TYPE_TAG;
5346 tag_item->spec = tag_item_spec;
5347 tag_item->last = NULL;
5348 tag_item->mask = tag_item_mask;
5351 *mtr_flow_id = tag_id;
5356 * Split action list having QUEUE/RSS for metadata register copy.
5358 * Once Q/RSS action is detected in user's action list, the flow action
5359 * should be split in order to copy metadata registers, which will happen in
5361 * - CQE->flow_tag := reg_c[1] (MARK)
5362 * - CQE->flow_table_metadata (reg_b) := reg_c[0] (META)
5363 * The Q/RSS action will be performed on RX_ACT_TBL after passing by RX_CP_TBL.
5364 * This is because the last action of each flow must be a terminal action
5365 * (QUEUE, RSS or DROP).
5367 * Flow ID must be allocated to identify actions in the RX_ACT_TBL and it is
5368 * stored and kept in the mlx5_flow structure per each sub_flow.
5370 * The Q/RSS action is replaced with,
5371 * - SET_TAG, setting the allocated flow ID to reg_c[2].
5372 * And the following JUMP action is added at the end,
5373 * - JUMP, to RX_CP_TBL.
5375 * A flow to perform remained Q/RSS action will be created in RX_ACT_TBL by
5376 * flow_create_split_metadata() routine. The flow will look like,
5377 * - If flow ID matches (reg_c[2]), perform Q/RSS.
5380 * Pointer to Ethernet device.
5381 * @param[out] split_actions
5382 * Pointer to store split actions to jump to CP_TBL.
5383 * @param[in] actions
5384 * Pointer to the list of original flow actions.
5386 * Pointer to the Q/RSS action.
5387 * @param[in] actions_n
5388 * Number of original actions.
5389 * @param[in] mtr_sfx
5390 * Check if it is in meter suffix table.
5392 * Perform verbose error reporting if not NULL.
5395 * non-zero unique flow_id on success, otherwise 0 and
5396 * error/rte_error are set.
5399 flow_mreg_split_qrss_prep(struct rte_eth_dev *dev,
5400 struct rte_flow_action *split_actions,
5401 const struct rte_flow_action *actions,
5402 const struct rte_flow_action *qrss,
5403 int actions_n, int mtr_sfx,
5404 struct rte_flow_error *error)
5406 struct mlx5_priv *priv = dev->data->dev_private;
5407 struct mlx5_rte_flow_action_set_tag *set_tag;
5408 struct rte_flow_action_jump *jump;
5409 const int qrss_idx = qrss - actions;
5410 uint32_t flow_id = 0;
5414 * Given actions will be split
5415 * - Replace QUEUE/RSS action with SET_TAG to set flow ID.
5416 * - Add jump to mreg CP_TBL.
5417 * As a result, there will be one more action.
5419 memcpy(split_actions, actions, sizeof(*split_actions) * actions_n);
5420 /* Count MLX5_RTE_FLOW_ACTION_TYPE_TAG. */
5422 set_tag = (void *)(split_actions + actions_n);
5424 * If we are not the meter suffix flow, add the tag action.
5425 * Since meter suffix flow already has the tag added.
5429 * Allocate the new subflow ID. This one is unique within
5430 * device and not shared with representors. Otherwise,
5431 * we would have to resolve multi-thread access synch
5432 * issue. Each flow on the shared device is appended
5433 * with source vport identifier, so the resulting
5434 * flows will be unique in the shared (by master and
5435 * representors) domain even if they have coinciding
5438 mlx5_ipool_malloc(priv->sh->ipool
5439 [MLX5_IPOOL_RSS_EXPANTION_FLOW_ID], &flow_id);
5441 return rte_flow_error_set(error, ENOMEM,
5442 RTE_FLOW_ERROR_TYPE_ACTION,
5443 NULL, "can't allocate id "
5444 "for split Q/RSS subflow");
5445 /* Internal SET_TAG action to set flow ID. */
5446 *set_tag = (struct mlx5_rte_flow_action_set_tag){
5449 ret = mlx5_flow_get_reg_id(dev, MLX5_COPY_MARK, 0, error);
5453 /* Construct new actions array. */
5454 /* Replace QUEUE/RSS action. */
5455 split_actions[qrss_idx] = (struct rte_flow_action){
5456 .type = (enum rte_flow_action_type)
5457 MLX5_RTE_FLOW_ACTION_TYPE_TAG,
5462 * If we are the suffix flow of meter, tag already exist.
5463 * Set the QUEUE/RSS action to void.
5465 split_actions[qrss_idx].type = RTE_FLOW_ACTION_TYPE_VOID;
5467 /* JUMP action to jump to mreg copy table (CP_TBL). */
5468 jump = (void *)(set_tag + 1);
5469 *jump = (struct rte_flow_action_jump){
5470 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
5472 split_actions[actions_n - 2] = (struct rte_flow_action){
5473 .type = RTE_FLOW_ACTION_TYPE_JUMP,
5476 split_actions[actions_n - 1] = (struct rte_flow_action){
5477 .type = RTE_FLOW_ACTION_TYPE_END,
5483 * Extend the given action list for Tx metadata copy.
5485 * Copy the given action list to the ext_actions and add flow metadata register
5486 * copy action in order to copy reg_a set by WQE to reg_c[0].
5488 * @param[out] ext_actions
5489 * Pointer to the extended action list.
5490 * @param[in] actions
5491 * Pointer to the list of actions.
5492 * @param[in] actions_n
5493 * Number of actions in the list.
5495 * Perform verbose error reporting if not NULL.
5496 * @param[in] encap_idx
5497 * The encap action index.
5500 * 0 on success, negative value otherwise
5503 flow_mreg_tx_copy_prep(struct rte_eth_dev *dev,
5504 struct rte_flow_action *ext_actions,
5505 const struct rte_flow_action *actions,
5506 int actions_n, struct rte_flow_error *error,
5509 struct mlx5_flow_action_copy_mreg *cp_mreg =
5510 (struct mlx5_flow_action_copy_mreg *)
5511 (ext_actions + actions_n + 1);
5514 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_RX, 0, error);
5518 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_TX, 0, error);
5523 memcpy(ext_actions, actions, sizeof(*ext_actions) * encap_idx);
5524 if (encap_idx == actions_n - 1) {
5525 ext_actions[actions_n - 1] = (struct rte_flow_action){
5526 .type = (enum rte_flow_action_type)
5527 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
5530 ext_actions[actions_n] = (struct rte_flow_action){
5531 .type = RTE_FLOW_ACTION_TYPE_END,
5534 ext_actions[encap_idx] = (struct rte_flow_action){
5535 .type = (enum rte_flow_action_type)
5536 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
5539 memcpy(ext_actions + encap_idx + 1, actions + encap_idx,
5540 sizeof(*ext_actions) * (actions_n - encap_idx));
5546 * Check the match action from the action list.
5548 * @param[in] actions
5549 * Pointer to the list of actions.
5551 * Flow rule attributes.
5553 * The action to be check if exist.
5554 * @param[out] match_action_pos
5555 * Pointer to the position of the matched action if exists, otherwise is -1.
5556 * @param[out] qrss_action_pos
5557 * Pointer to the position of the Queue/RSS action if exists, otherwise is -1.
5558 * @param[out] modify_after_mirror
5559 * Pointer to the flag of modify action after FDB mirroring.
5562 * > 0 the total number of actions.
5563 * 0 if not found match action in action list.
5566 flow_check_match_action(const struct rte_flow_action actions[],
5567 const struct rte_flow_attr *attr,
5568 enum rte_flow_action_type action,
5569 int *match_action_pos, int *qrss_action_pos,
5570 int *modify_after_mirror)
5572 const struct rte_flow_action_sample *sample;
5573 const struct rte_flow_action_raw_decap *decap;
5580 *match_action_pos = -1;
5581 *qrss_action_pos = -1;
5582 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
5583 if (actions->type == action) {
5585 *match_action_pos = actions_n;
5587 switch (actions->type) {
5588 case RTE_FLOW_ACTION_TYPE_QUEUE:
5589 case RTE_FLOW_ACTION_TYPE_RSS:
5590 *qrss_action_pos = actions_n;
5592 case RTE_FLOW_ACTION_TYPE_SAMPLE:
5593 sample = actions->conf;
5594 ratio = sample->ratio;
5595 sub_type = ((const struct rte_flow_action *)
5596 (sample->actions))->type;
5597 if (ratio == 1 && attr->transfer)
5600 case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
5601 case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
5602 case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
5603 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
5604 case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
5605 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
5606 case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
5607 case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
5608 case RTE_FLOW_ACTION_TYPE_DEC_TTL:
5609 case RTE_FLOW_ACTION_TYPE_SET_TTL:
5610 case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
5611 case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
5612 case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
5613 case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
5614 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
5615 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
5616 case RTE_FLOW_ACTION_TYPE_FLAG:
5617 case RTE_FLOW_ACTION_TYPE_MARK:
5618 case RTE_FLOW_ACTION_TYPE_SET_META:
5619 case RTE_FLOW_ACTION_TYPE_SET_TAG:
5620 case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
5621 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
5622 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
5623 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
5624 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
5625 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
5626 case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
5627 case RTE_FLOW_ACTION_TYPE_METER:
5629 *modify_after_mirror = 1;
5631 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
5632 decap = actions->conf;
5633 while ((++actions)->type == RTE_FLOW_ACTION_TYPE_VOID)
5636 if (actions->type == RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
5637 const struct rte_flow_action_raw_encap *encap =
5640 MLX5_ENCAPSULATION_DECISION_SIZE &&
5642 MLX5_ENCAPSULATION_DECISION_SIZE)
5647 *modify_after_mirror = 1;
5654 if (flag && fdb_mirror && !*modify_after_mirror) {
5655 /* FDB mirroring uses the destination array to implement
5656 * instead of FLOW_SAMPLER object.
5658 if (sub_type != RTE_FLOW_ACTION_TYPE_END)
5661 /* Count RTE_FLOW_ACTION_TYPE_END. */
5662 return flag ? actions_n + 1 : 0;
5665 #define SAMPLE_SUFFIX_ITEM 2
5668 * Split the sample flow.
5670 * As sample flow will split to two sub flow, sample flow with
5671 * sample action, the other actions will move to new suffix flow.
5673 * Also add unique tag id with tag action in the sample flow,
5674 * the same tag id will be as match in the suffix flow.
5677 * Pointer to Ethernet device.
5678 * @param[in] add_tag
5679 * Add extra tag action flag.
5680 * @param[out] sfx_items
5681 * Suffix flow match items (list terminated by the END pattern item).
5682 * @param[in] actions
5683 * Associated actions (list terminated by the END action).
5684 * @param[out] actions_sfx
5685 * Suffix flow actions.
5686 * @param[out] actions_pre
5687 * Prefix flow actions.
5688 * @param[in] actions_n
5689 * The total number of actions.
5690 * @param[in] sample_action_pos
5691 * The sample action position.
5692 * @param[in] qrss_action_pos
5693 * The Queue/RSS action position.
5694 * @param[in] jump_table
5695 * Add extra jump action flag.
5697 * Perform verbose error reporting if not NULL.
5700 * 0 on success, or unique flow_id, a negative errno value
5701 * otherwise and rte_errno is set.
5704 flow_sample_split_prep(struct rte_eth_dev *dev,
5706 struct rte_flow_item sfx_items[],
5707 const struct rte_flow_action actions[],
5708 struct rte_flow_action actions_sfx[],
5709 struct rte_flow_action actions_pre[],
5711 int sample_action_pos,
5712 int qrss_action_pos,
5714 struct rte_flow_error *error)
5716 struct mlx5_priv *priv = dev->data->dev_private;
5717 struct mlx5_rte_flow_action_set_tag *set_tag;
5718 struct mlx5_rte_flow_item_tag *tag_spec;
5719 struct mlx5_rte_flow_item_tag *tag_mask;
5720 struct rte_flow_action_jump *jump_action;
5721 uint32_t tag_id = 0;
5723 int append_index = 0;
5726 if (sample_action_pos < 0)
5727 return rte_flow_error_set(error, EINVAL,
5728 RTE_FLOW_ERROR_TYPE_ACTION,
5729 NULL, "invalid position of sample "
5731 /* Prepare the actions for prefix and suffix flow. */
5732 if (qrss_action_pos >= 0 && qrss_action_pos < sample_action_pos) {
5733 index = qrss_action_pos;
5734 /* Put the preceding the Queue/RSS action into prefix flow. */
5736 memcpy(actions_pre, actions,
5737 sizeof(struct rte_flow_action) * index);
5738 /* Put others preceding the sample action into prefix flow. */
5739 if (sample_action_pos > index + 1)
5740 memcpy(actions_pre + index, actions + index + 1,
5741 sizeof(struct rte_flow_action) *
5742 (sample_action_pos - index - 1));
5743 index = sample_action_pos - 1;
5744 /* Put Queue/RSS action into Suffix flow. */
5745 memcpy(actions_sfx, actions + qrss_action_pos,
5746 sizeof(struct rte_flow_action));
5749 index = sample_action_pos;
5751 memcpy(actions_pre, actions,
5752 sizeof(struct rte_flow_action) * index);
5754 /* For CX5, add an extra tag action for NIC-RX and E-Switch ingress.
5755 * For CX6DX and above, metadata registers Cx preserve their value,
5756 * add an extra tag action for NIC-RX and E-Switch Domain.
5759 /* Prepare the prefix tag action. */
5761 set_tag = (void *)(actions_pre + actions_n + append_index);
5762 ret = mlx5_flow_get_reg_id(dev, MLX5_SAMPLE_ID, 0, error);
5765 mlx5_ipool_malloc(priv->sh->ipool
5766 [MLX5_IPOOL_RSS_EXPANTION_FLOW_ID], &tag_id);
5767 *set_tag = (struct mlx5_rte_flow_action_set_tag) {
5771 /* Prepare the suffix subflow items. */
5772 tag_spec = (void *)(sfx_items + SAMPLE_SUFFIX_ITEM);
5773 tag_spec->data = tag_id;
5774 tag_spec->id = set_tag->id;
5775 tag_mask = tag_spec + 1;
5776 tag_mask->data = UINT32_MAX;
5777 sfx_items[0] = (struct rte_flow_item){
5778 .type = (enum rte_flow_item_type)
5779 MLX5_RTE_FLOW_ITEM_TYPE_TAG,
5784 sfx_items[1] = (struct rte_flow_item){
5785 .type = (enum rte_flow_item_type)
5786 RTE_FLOW_ITEM_TYPE_END,
5788 /* Prepare the tag action in prefix subflow. */
5789 actions_pre[index++] =
5790 (struct rte_flow_action){
5791 .type = (enum rte_flow_action_type)
5792 MLX5_RTE_FLOW_ACTION_TYPE_TAG,
5796 memcpy(actions_pre + index, actions + sample_action_pos,
5797 sizeof(struct rte_flow_action));
5799 /* For the modify action after the sample action in E-Switch mirroring,
5800 * Add the extra jump action in prefix subflow and jump into the next
5801 * table, then do the modify action in the new table.
5804 /* Prepare the prefix jump action. */
5806 jump_action = (void *)(actions_pre + actions_n + append_index);
5807 jump_action->group = jump_table;
5808 actions_pre[index++] =
5809 (struct rte_flow_action){
5810 .type = (enum rte_flow_action_type)
5811 RTE_FLOW_ACTION_TYPE_JUMP,
5812 .conf = jump_action,
5815 actions_pre[index] = (struct rte_flow_action){
5816 .type = (enum rte_flow_action_type)
5817 RTE_FLOW_ACTION_TYPE_END,
5819 /* Put the actions after sample into Suffix flow. */
5820 memcpy(actions_sfx, actions + sample_action_pos + 1,
5821 sizeof(struct rte_flow_action) *
5822 (actions_n - sample_action_pos - 1));
5827 * The splitting for metadata feature.
5829 * - Q/RSS action on NIC Rx should be split in order to pass by
5830 * the mreg copy table (RX_CP_TBL) and then it jumps to the
5831 * action table (RX_ACT_TBL) which has the split Q/RSS action.
5833 * - All the actions on NIC Tx should have a mreg copy action to
5834 * copy reg_a from WQE to reg_c[0].
5837 * Pointer to Ethernet device.
5839 * Parent flow structure pointer.
5841 * Flow rule attributes.
5843 * Pattern specification (list terminated by the END pattern item).
5844 * @param[in] actions
5845 * Associated actions (list terminated by the END action).
5846 * @param[in] flow_split_info
5847 * Pointer to flow split info structure.
5849 * Perform verbose error reporting if not NULL.
5851 * 0 on success, negative value otherwise
5854 flow_create_split_metadata(struct rte_eth_dev *dev,
5855 struct rte_flow *flow,
5856 const struct rte_flow_attr *attr,
5857 const struct rte_flow_item items[],
5858 const struct rte_flow_action actions[],
5859 struct mlx5_flow_split_info *flow_split_info,
5860 struct rte_flow_error *error)
5862 struct mlx5_priv *priv = dev->data->dev_private;
5863 struct mlx5_sh_config *config = &priv->sh->config;
5864 const struct rte_flow_action *qrss = NULL;
5865 struct rte_flow_action *ext_actions = NULL;
5866 struct mlx5_flow *dev_flow = NULL;
5867 uint32_t qrss_id = 0;
5874 /* Check whether extensive metadata feature is engaged. */
5875 if (!config->dv_flow_en ||
5876 config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
5877 !mlx5_flow_ext_mreg_supported(dev))
5878 return flow_create_split_inner(dev, flow, NULL, attr, items,
5879 actions, flow_split_info, error);
5880 actions_n = flow_parse_metadata_split_actions_info(actions, &qrss,
5883 /* Exclude hairpin flows from splitting. */
5884 if (qrss->type == RTE_FLOW_ACTION_TYPE_QUEUE) {
5885 const struct rte_flow_action_queue *queue;
5888 if (mlx5_rxq_get_type(dev, queue->index) ==
5889 MLX5_RXQ_TYPE_HAIRPIN)
5891 } else if (qrss->type == RTE_FLOW_ACTION_TYPE_RSS) {
5892 const struct rte_flow_action_rss *rss;
5895 if (mlx5_rxq_get_type(dev, rss->queue[0]) ==
5896 MLX5_RXQ_TYPE_HAIRPIN)
5901 /* Check if it is in meter suffix table. */
5902 mtr_sfx = attr->group == (attr->transfer ?
5903 (MLX5_FLOW_TABLE_LEVEL_METER - 1) :
5904 MLX5_FLOW_TABLE_LEVEL_METER);
5906 * Q/RSS action on NIC Rx should be split in order to pass by
5907 * the mreg copy table (RX_CP_TBL) and then it jumps to the
5908 * action table (RX_ACT_TBL) which has the split Q/RSS action.
5910 act_size = sizeof(struct rte_flow_action) * (actions_n + 1) +
5911 sizeof(struct rte_flow_action_set_tag) +
5912 sizeof(struct rte_flow_action_jump);
5913 ext_actions = mlx5_malloc(MLX5_MEM_ZERO, act_size, 0,
5916 return rte_flow_error_set(error, ENOMEM,
5917 RTE_FLOW_ERROR_TYPE_ACTION,
5918 NULL, "no memory to split "
5921 * Create the new actions list with removed Q/RSS action
5922 * and appended set tag and jump to register copy table
5923 * (RX_CP_TBL). We should preallocate unique tag ID here
5924 * in advance, because it is needed for set tag action.
5926 qrss_id = flow_mreg_split_qrss_prep(dev, ext_actions, actions,
5929 if (!mtr_sfx && !qrss_id) {
5933 } else if (attr->egress && !attr->transfer) {
5935 * All the actions on NIC Tx should have a metadata register
5936 * copy action to copy reg_a from WQE to reg_c[meta]
5938 act_size = sizeof(struct rte_flow_action) * (actions_n + 1) +
5939 sizeof(struct mlx5_flow_action_copy_mreg);
5940 ext_actions = mlx5_malloc(MLX5_MEM_ZERO, act_size, 0,
5943 return rte_flow_error_set(error, ENOMEM,
5944 RTE_FLOW_ERROR_TYPE_ACTION,
5945 NULL, "no memory to split "
5947 /* Create the action list appended with copy register. */
5948 ret = flow_mreg_tx_copy_prep(dev, ext_actions, actions,
5949 actions_n, error, encap_idx);
5953 /* Add the unmodified original or prefix subflow. */
5954 ret = flow_create_split_inner(dev, flow, &dev_flow, attr,
5955 items, ext_actions ? ext_actions :
5956 actions, flow_split_info, error);
5959 MLX5_ASSERT(dev_flow);
5961 const struct rte_flow_attr q_attr = {
5962 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
5965 /* Internal PMD action to set register. */
5966 struct mlx5_rte_flow_item_tag q_tag_spec = {
5970 struct rte_flow_item q_items[] = {
5972 .type = (enum rte_flow_item_type)
5973 MLX5_RTE_FLOW_ITEM_TYPE_TAG,
5974 .spec = &q_tag_spec,
5979 .type = RTE_FLOW_ITEM_TYPE_END,
5982 struct rte_flow_action q_actions[] = {
5988 .type = RTE_FLOW_ACTION_TYPE_END,
5991 uint64_t layers = flow_get_prefix_layer_flags(dev_flow);
5994 * Configure the tag item only if there is no meter subflow.
5995 * Since tag is already marked in the meter suffix subflow
5996 * we can just use the meter suffix items as is.
5999 /* Not meter subflow. */
6000 MLX5_ASSERT(!mtr_sfx);
6002 * Put unique id in prefix flow due to it is destroyed
6003 * after suffix flow and id will be freed after there
6004 * is no actual flows with this id and identifier
6005 * reallocation becomes possible (for example, for
6006 * other flows in other threads).
6008 dev_flow->handle->split_flow_id = qrss_id;
6009 ret = mlx5_flow_get_reg_id(dev, MLX5_COPY_MARK, 0,
6013 q_tag_spec.id = ret;
6016 /* Add suffix subflow to execute Q/RSS. */
6017 flow_split_info->prefix_layers = layers;
6018 flow_split_info->prefix_mark = 0;
6019 flow_split_info->table_id = 0;
6020 ret = flow_create_split_inner(dev, flow, &dev_flow,
6021 &q_attr, mtr_sfx ? items :
6023 flow_split_info, error);
6026 /* qrss ID should be freed if failed. */
6028 MLX5_ASSERT(dev_flow);
6033 * We do not destroy the partially created sub_flows in case of error.
6034 * These ones are included into parent flow list and will be destroyed
6035 * by flow_drv_destroy.
6037 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RSS_EXPANTION_FLOW_ID],
6039 mlx5_free(ext_actions);
6044 * Create meter internal drop flow with the original pattern.
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] flow_split_info
6055 * Pointer to flow split info structure.
6057 * Pointer to flow meter structure.
6059 * Perform verbose error reporting if not NULL.
6061 * 0 on success, negative value otherwise
6064 flow_meter_create_drop_flow_with_org_pattern(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 struct mlx5_flow_split_info *flow_split_info,
6069 struct mlx5_flow_meter_info *fm,
6070 struct rte_flow_error *error)
6072 struct mlx5_flow *dev_flow = NULL;
6073 struct rte_flow_attr drop_attr = *attr;
6074 struct rte_flow_action drop_actions[3];
6075 struct mlx5_flow_split_info drop_split_info = *flow_split_info;
6077 MLX5_ASSERT(fm->drop_cnt);
6078 drop_actions[0].type =
6079 (enum rte_flow_action_type)MLX5_RTE_FLOW_ACTION_TYPE_COUNT;
6080 drop_actions[0].conf = (void *)(uintptr_t)fm->drop_cnt;
6081 drop_actions[1].type = RTE_FLOW_ACTION_TYPE_DROP;
6082 drop_actions[1].conf = NULL;
6083 drop_actions[2].type = RTE_FLOW_ACTION_TYPE_END;
6084 drop_actions[2].conf = NULL;
6085 drop_split_info.external = false;
6086 drop_split_info.skip_scale |= 1 << MLX5_SCALE_FLOW_GROUP_BIT;
6087 drop_split_info.table_id = MLX5_MTR_TABLE_ID_DROP;
6088 drop_attr.group = MLX5_FLOW_TABLE_LEVEL_METER;
6089 return flow_create_split_inner(dev, flow, &dev_flow,
6090 &drop_attr, items, drop_actions,
6091 &drop_split_info, error);
6095 * The splitting for meter feature.
6097 * - The meter flow will be split to two flows as prefix and
6098 * suffix flow. The packets make sense only it pass the prefix
6101 * - Reg_C_5 is used for the packet to match betweend prefix and
6105 * Pointer to Ethernet device.
6107 * Parent flow structure pointer.
6109 * Flow rule attributes.
6111 * Pattern specification (list terminated by the END pattern item).
6112 * @param[in] actions
6113 * Associated actions (list terminated by the END action).
6114 * @param[in] flow_split_info
6115 * Pointer to flow split info structure.
6117 * Perform verbose error reporting if not NULL.
6119 * 0 on success, negative value otherwise
6122 flow_create_split_meter(struct rte_eth_dev *dev,
6123 struct rte_flow *flow,
6124 const struct rte_flow_attr *attr,
6125 const struct rte_flow_item items[],
6126 const struct rte_flow_action actions[],
6127 struct mlx5_flow_split_info *flow_split_info,
6128 struct rte_flow_error *error)
6130 struct mlx5_priv *priv = dev->data->dev_private;
6131 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
6132 struct rte_flow_action *sfx_actions = NULL;
6133 struct rte_flow_action *pre_actions = NULL;
6134 struct rte_flow_item *sfx_items = NULL;
6135 struct mlx5_flow *dev_flow = NULL;
6136 struct rte_flow_attr sfx_attr = *attr;
6137 struct mlx5_flow_meter_info *fm = NULL;
6138 uint8_t skip_scale_restore;
6139 bool has_mtr = false;
6140 bool has_modify = false;
6141 bool set_mtr_reg = true;
6142 bool is_mtr_hierarchy = false;
6143 uint32_t meter_id = 0;
6144 uint32_t mtr_idx = 0;
6145 uint32_t mtr_flow_id = 0;
6152 actions_n = flow_check_meter_action(dev, actions, &has_mtr,
6153 &has_modify, &meter_id);
6156 fm = flow_dv_meter_find_by_idx(priv, flow->meter);
6158 return rte_flow_error_set(error, EINVAL,
6159 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6160 NULL, "Meter not found.");
6162 fm = mlx5_flow_meter_find(priv, meter_id, &mtr_idx);
6164 return rte_flow_error_set(error, EINVAL,
6165 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6166 NULL, "Meter not found.");
6167 ret = mlx5_flow_meter_attach(priv, fm,
6171 flow->meter = mtr_idx;
6175 if (!fm->def_policy) {
6176 wks->policy = mlx5_flow_meter_policy_find(dev,
6179 MLX5_ASSERT(wks->policy);
6180 if (wks->policy->is_hierarchy) {
6182 mlx5_flow_meter_hierarchy_get_final_policy(dev,
6184 if (!wks->final_policy)
6185 return rte_flow_error_set(error,
6187 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
6188 "Failed to find terminal policy of hierarchy.");
6189 is_mtr_hierarchy = true;
6193 * If it isn't default-policy Meter, and
6194 * 1. There's no action in flow to change
6195 * packet (modify/encap/decap etc.), OR
6196 * 2. No drop count needed for this meter.
6197 * 3. It's not meter hierarchy.
6198 * Then no need to use regC to save meter id anymore.
6200 if (!fm->def_policy && !is_mtr_hierarchy &&
6201 (!has_modify || !fm->drop_cnt))
6202 set_mtr_reg = false;
6203 /* Prefix actions: meter, decap, encap, tag, jump, end. */
6204 act_size = sizeof(struct rte_flow_action) * (actions_n + 6) +
6205 sizeof(struct mlx5_rte_flow_action_set_tag);
6206 /* Suffix items: tag, vlan, port id, end. */
6207 #define METER_SUFFIX_ITEM 4
6208 item_size = sizeof(struct rte_flow_item) * METER_SUFFIX_ITEM +
6209 sizeof(struct mlx5_rte_flow_item_tag) * 2;
6210 sfx_actions = mlx5_malloc(MLX5_MEM_ZERO, (act_size + item_size),
6213 return rte_flow_error_set(error, ENOMEM,
6214 RTE_FLOW_ERROR_TYPE_ACTION,
6215 NULL, "no memory to split "
6217 sfx_items = (struct rte_flow_item *)((char *)sfx_actions +
6219 /* There's no suffix flow for meter of non-default policy. */
6220 if (!fm->def_policy)
6221 pre_actions = sfx_actions + 1;
6223 pre_actions = sfx_actions + actions_n;
6224 ret = flow_meter_split_prep(dev, flow, wks, &sfx_attr,
6225 items, sfx_items, actions,
6226 sfx_actions, pre_actions,
6227 (set_mtr_reg ? &mtr_flow_id : NULL),
6233 /* Add the prefix subflow. */
6234 skip_scale_restore = flow_split_info->skip_scale;
6235 flow_split_info->skip_scale |=
6236 1 << MLX5_SCALE_JUMP_FLOW_GROUP_BIT;
6237 ret = flow_create_split_inner(dev, flow, &dev_flow,
6238 attr, items, pre_actions,
6239 flow_split_info, error);
6240 flow_split_info->skip_scale = skip_scale_restore;
6243 mlx5_ipool_free(fm->flow_ipool, mtr_flow_id);
6248 dev_flow->handle->split_flow_id = mtr_flow_id;
6249 dev_flow->handle->is_meter_flow_id = 1;
6251 if (!fm->def_policy) {
6252 if (!set_mtr_reg && fm->drop_cnt)
6254 flow_meter_create_drop_flow_with_org_pattern(dev, flow,
6260 /* Setting the sfx group atrr. */
6261 sfx_attr.group = sfx_attr.transfer ?
6262 (MLX5_FLOW_TABLE_LEVEL_METER - 1) :
6263 MLX5_FLOW_TABLE_LEVEL_METER;
6264 flow_split_info->prefix_layers =
6265 flow_get_prefix_layer_flags(dev_flow);
6266 flow_split_info->prefix_mark |= wks->mark;
6267 flow_split_info->table_id = MLX5_MTR_TABLE_ID_SUFFIX;
6269 /* Add the prefix subflow. */
6270 ret = flow_create_split_metadata(dev, flow,
6271 &sfx_attr, sfx_items ?
6273 sfx_actions ? sfx_actions : actions,
6274 flow_split_info, error);
6277 mlx5_free(sfx_actions);
6282 * The splitting for sample feature.
6284 * Once Sample action is detected in the action list, the flow actions should
6285 * be split into prefix sub flow and suffix sub flow.
6287 * The original items remain in the prefix sub flow, all actions preceding the
6288 * sample action and the sample action itself will be copied to the prefix
6289 * sub flow, the actions following the sample action will be copied to the
6290 * suffix sub flow, Queue action always be located in the suffix sub flow.
6292 * In order to make the packet from prefix sub flow matches with suffix sub
6293 * flow, an extra tag action be added into prefix sub flow, and the suffix sub
6294 * flow uses tag item with the unique flow id.
6297 * Pointer to Ethernet device.
6299 * Parent flow structure pointer.
6301 * Flow rule attributes.
6303 * Pattern specification (list terminated by the END pattern item).
6304 * @param[in] actions
6305 * Associated actions (list terminated by the END action).
6306 * @param[in] flow_split_info
6307 * Pointer to flow split info structure.
6309 * Perform verbose error reporting if not NULL.
6311 * 0 on success, negative value otherwise
6314 flow_create_split_sample(struct rte_eth_dev *dev,
6315 struct rte_flow *flow,
6316 const struct rte_flow_attr *attr,
6317 const struct rte_flow_item items[],
6318 const struct rte_flow_action actions[],
6319 struct mlx5_flow_split_info *flow_split_info,
6320 struct rte_flow_error *error)
6322 struct mlx5_priv *priv = dev->data->dev_private;
6323 struct rte_flow_action *sfx_actions = NULL;
6324 struct rte_flow_action *pre_actions = NULL;
6325 struct rte_flow_item *sfx_items = NULL;
6326 struct mlx5_flow *dev_flow = NULL;
6327 struct rte_flow_attr sfx_attr = *attr;
6328 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
6329 struct mlx5_flow_dv_sample_resource *sample_res;
6330 struct mlx5_flow_tbl_data_entry *sfx_tbl_data;
6331 struct mlx5_flow_tbl_resource *sfx_tbl;
6332 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
6336 uint32_t fdb_tx = 0;
6339 int sample_action_pos;
6340 int qrss_action_pos;
6342 int modify_after_mirror = 0;
6343 uint16_t jump_table = 0;
6344 const uint32_t next_ft_step = 1;
6347 if (priv->sampler_en)
6348 actions_n = flow_check_match_action(actions, attr,
6349 RTE_FLOW_ACTION_TYPE_SAMPLE,
6350 &sample_action_pos, &qrss_action_pos,
6351 &modify_after_mirror);
6353 /* The prefix actions must includes sample, tag, end. */
6354 act_size = sizeof(struct rte_flow_action) * (actions_n * 2 + 1)
6355 + sizeof(struct mlx5_rte_flow_action_set_tag);
6356 item_size = sizeof(struct rte_flow_item) * SAMPLE_SUFFIX_ITEM +
6357 sizeof(struct mlx5_rte_flow_item_tag) * 2;
6358 sfx_actions = mlx5_malloc(MLX5_MEM_ZERO, (act_size +
6359 item_size), 0, SOCKET_ID_ANY);
6361 return rte_flow_error_set(error, ENOMEM,
6362 RTE_FLOW_ERROR_TYPE_ACTION,
6363 NULL, "no memory to split "
6365 /* The representor_id is UINT16_MAX for uplink. */
6366 fdb_tx = (attr->transfer && priv->representor_id != UINT16_MAX);
6368 * When reg_c_preserve is set, metadata registers Cx preserve
6369 * their value even through packet duplication.
6371 add_tag = (!fdb_tx ||
6372 priv->sh->cdev->config.hca_attr.reg_c_preserve);
6374 sfx_items = (struct rte_flow_item *)((char *)sfx_actions
6376 if (modify_after_mirror)
6377 jump_table = attr->group * MLX5_FLOW_TABLE_FACTOR +
6379 pre_actions = sfx_actions + actions_n;
6380 tag_id = flow_sample_split_prep(dev, add_tag, sfx_items,
6381 actions, sfx_actions,
6382 pre_actions, actions_n,
6384 qrss_action_pos, jump_table,
6386 if (tag_id < 0 || (add_tag && !tag_id)) {
6390 if (modify_after_mirror)
6391 flow_split_info->skip_scale =
6392 1 << MLX5_SCALE_JUMP_FLOW_GROUP_BIT;
6393 /* Add the prefix subflow. */
6394 ret = flow_create_split_inner(dev, flow, &dev_flow, attr,
6396 flow_split_info, error);
6401 dev_flow->handle->split_flow_id = tag_id;
6402 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
6403 if (!modify_after_mirror) {
6404 /* Set the sfx group attr. */
6405 sample_res = (struct mlx5_flow_dv_sample_resource *)
6406 dev_flow->dv.sample_res;
6407 sfx_tbl = (struct mlx5_flow_tbl_resource *)
6408 sample_res->normal_path_tbl;
6409 sfx_tbl_data = container_of(sfx_tbl,
6410 struct mlx5_flow_tbl_data_entry,
6412 sfx_attr.group = sfx_attr.transfer ?
6413 (sfx_tbl_data->level - 1) : sfx_tbl_data->level;
6415 MLX5_ASSERT(attr->transfer);
6416 sfx_attr.group = jump_table;
6418 flow_split_info->prefix_layers =
6419 flow_get_prefix_layer_flags(dev_flow);
6421 flow_split_info->prefix_mark |= wks->mark;
6422 /* Suffix group level already be scaled with factor, set
6423 * MLX5_SCALE_FLOW_GROUP_BIT of skip_scale to 1 to avoid scale
6424 * again in translation.
6426 flow_split_info->skip_scale = 1 << MLX5_SCALE_FLOW_GROUP_BIT;
6429 /* Add the suffix subflow. */
6430 ret = flow_create_split_meter(dev, flow, &sfx_attr,
6431 sfx_items ? sfx_items : items,
6432 sfx_actions ? sfx_actions : actions,
6433 flow_split_info, error);
6436 mlx5_free(sfx_actions);
6441 * Split the flow to subflow set. The splitters might be linked
6442 * in the chain, like this:
6443 * flow_create_split_outer() calls:
6444 * flow_create_split_meter() calls:
6445 * flow_create_split_metadata(meter_subflow_0) calls:
6446 * flow_create_split_inner(metadata_subflow_0)
6447 * flow_create_split_inner(metadata_subflow_1)
6448 * flow_create_split_inner(metadata_subflow_2)
6449 * flow_create_split_metadata(meter_subflow_1) calls:
6450 * flow_create_split_inner(metadata_subflow_0)
6451 * flow_create_split_inner(metadata_subflow_1)
6452 * flow_create_split_inner(metadata_subflow_2)
6454 * This provide flexible way to add new levels of flow splitting.
6455 * The all of successfully created subflows are included to the
6456 * parent flow dev_flow list.
6459 * Pointer to Ethernet device.
6461 * Parent flow structure pointer.
6463 * Flow rule attributes.
6465 * Pattern specification (list terminated by the END pattern item).
6466 * @param[in] actions
6467 * Associated actions (list terminated by the END action).
6468 * @param[in] flow_split_info
6469 * Pointer to flow split info structure.
6471 * Perform verbose error reporting if not NULL.
6473 * 0 on success, negative value otherwise
6476 flow_create_split_outer(struct rte_eth_dev *dev,
6477 struct rte_flow *flow,
6478 const struct rte_flow_attr *attr,
6479 const struct rte_flow_item items[],
6480 const struct rte_flow_action actions[],
6481 struct mlx5_flow_split_info *flow_split_info,
6482 struct rte_flow_error *error)
6486 ret = flow_create_split_sample(dev, flow, attr, items,
6487 actions, flow_split_info, error);
6488 MLX5_ASSERT(ret <= 0);
6492 static inline struct mlx5_flow_tunnel *
6493 flow_tunnel_from_rule(const struct mlx5_flow *flow)
6495 struct mlx5_flow_tunnel *tunnel;
6497 #pragma GCC diagnostic push
6498 #pragma GCC diagnostic ignored "-Wcast-qual"
6499 tunnel = (typeof(tunnel))flow->tunnel;
6500 #pragma GCC diagnostic pop
6506 * Adjust flow RSS workspace if needed.
6509 * Pointer to thread flow work space.
6511 * Pointer to RSS descriptor.
6512 * @param[in] nrssq_num
6513 * New RSS queue number.
6516 * 0 on success, -1 otherwise and rte_errno is set.
6519 flow_rss_workspace_adjust(struct mlx5_flow_workspace *wks,
6520 struct mlx5_flow_rss_desc *rss_desc,
6523 if (likely(nrssq_num <= wks->rssq_num))
6525 rss_desc->queue = realloc(rss_desc->queue,
6526 sizeof(*rss_desc->queue) * RTE_ALIGN(nrssq_num, 2));
6527 if (!rss_desc->queue) {
6531 wks->rssq_num = RTE_ALIGN(nrssq_num, 2);
6536 * Create a flow and add it to @p list.
6539 * Pointer to Ethernet device.
6541 * Pointer to a TAILQ flow list. If this parameter NULL,
6542 * no list insertion occurred, flow is just created,
6543 * this is caller's responsibility to track the
6546 * Flow rule attributes.
6548 * Pattern specification (list terminated by the END pattern item).
6549 * @param[in] actions
6550 * Associated actions (list terminated by the END action).
6551 * @param[in] external
6552 * This flow rule is created by request external to PMD.
6554 * Perform verbose error reporting if not NULL.
6557 * A flow index on success, 0 otherwise and rte_errno is set.
6560 flow_list_create(struct rte_eth_dev *dev, enum mlx5_flow_type type,
6561 const struct rte_flow_attr *attr,
6562 const struct rte_flow_item items[],
6563 const struct rte_flow_action original_actions[],
6564 bool external, struct rte_flow_error *error)
6566 struct mlx5_priv *priv = dev->data->dev_private;
6567 struct rte_flow *flow = NULL;
6568 struct mlx5_flow *dev_flow;
6569 const struct rte_flow_action_rss *rss = NULL;
6570 struct mlx5_translated_action_handle
6571 indir_actions[MLX5_MAX_INDIRECT_ACTIONS];
6572 int indir_actions_n = MLX5_MAX_INDIRECT_ACTIONS;
6574 struct mlx5_flow_expand_rss buf;
6575 uint8_t buffer[4096];
6578 struct rte_flow_action actions[MLX5_MAX_SPLIT_ACTIONS];
6579 uint8_t buffer[2048];
6582 struct rte_flow_action actions[MLX5_MAX_SPLIT_ACTIONS];
6583 uint8_t buffer[2048];
6584 } actions_hairpin_tx;
6586 struct rte_flow_item items[MLX5_MAX_SPLIT_ITEMS];
6587 uint8_t buffer[2048];
6589 struct mlx5_flow_expand_rss *buf = &expand_buffer.buf;
6590 struct mlx5_flow_rss_desc *rss_desc;
6591 const struct rte_flow_action *p_actions_rx;
6595 struct rte_flow_attr attr_tx = { .priority = 0 };
6596 const struct rte_flow_action *actions;
6597 struct rte_flow_action *translated_actions = NULL;
6598 struct mlx5_flow_tunnel *tunnel;
6599 struct tunnel_default_miss_ctx default_miss_ctx = { 0, };
6600 struct mlx5_flow_workspace *wks = mlx5_flow_push_thread_workspace();
6601 struct mlx5_flow_split_info flow_split_info = {
6602 .external = !!external,
6612 rss_desc = &wks->rss_desc;
6613 ret = flow_action_handles_translate(dev, original_actions,
6616 &translated_actions, error);
6618 MLX5_ASSERT(translated_actions == NULL);
6621 actions = translated_actions ? translated_actions : original_actions;
6622 p_actions_rx = actions;
6623 hairpin_flow = flow_check_hairpin_split(dev, attr, actions);
6624 ret = flow_drv_validate(dev, attr, items, p_actions_rx,
6625 external, hairpin_flow, error);
6627 goto error_before_hairpin_split;
6628 flow = mlx5_ipool_zmalloc(priv->flows[type], &idx);
6631 goto error_before_hairpin_split;
6633 if (hairpin_flow > 0) {
6634 if (hairpin_flow > MLX5_MAX_SPLIT_ACTIONS) {
6636 goto error_before_hairpin_split;
6638 flow_hairpin_split(dev, actions, actions_rx.actions,
6639 actions_hairpin_tx.actions, items_tx.items,
6641 p_actions_rx = actions_rx.actions;
6643 flow_split_info.flow_idx = idx;
6644 flow->drv_type = flow_get_drv_type(dev, attr);
6645 MLX5_ASSERT(flow->drv_type > MLX5_FLOW_TYPE_MIN &&
6646 flow->drv_type < MLX5_FLOW_TYPE_MAX);
6647 memset(rss_desc, 0, offsetof(struct mlx5_flow_rss_desc, queue));
6648 /* RSS Action only works on NIC RX domain */
6649 if (attr->ingress && !attr->transfer)
6650 rss = flow_get_rss_action(dev, p_actions_rx);
6652 if (flow_rss_workspace_adjust(wks, rss_desc, rss->queue_num))
6655 * The following information is required by
6656 * mlx5_flow_hashfields_adjust() in advance.
6658 rss_desc->level = rss->level;
6659 /* RSS type 0 indicates default RSS type (RTE_ETH_RSS_IP). */
6660 rss_desc->types = !rss->types ? RTE_ETH_RSS_IP : rss->types;
6662 flow->dev_handles = 0;
6663 if (rss && rss->types) {
6664 unsigned int graph_root;
6666 graph_root = find_graph_root(rss->level);
6667 ret = mlx5_flow_expand_rss(buf, sizeof(expand_buffer.buffer),
6669 mlx5_support_expansion, graph_root);
6670 MLX5_ASSERT(ret > 0 &&
6671 (unsigned int)ret < sizeof(expand_buffer.buffer));
6672 if (rte_log_can_log(mlx5_logtype, RTE_LOG_DEBUG)) {
6673 for (i = 0; i < buf->entries; ++i)
6674 mlx5_dbg__print_pattern(buf->entry[i].pattern);
6678 buf->entry[0].pattern = (void *)(uintptr_t)items;
6680 rss_desc->shared_rss = flow_get_shared_rss_action(dev, indir_actions,
6682 for (i = 0; i < buf->entries; ++i) {
6683 /* Initialize flow split data. */
6684 flow_split_info.prefix_layers = 0;
6685 flow_split_info.prefix_mark = 0;
6686 flow_split_info.skip_scale = 0;
6688 * The splitter may create multiple dev_flows,
6689 * depending on configuration. In the simplest
6690 * case it just creates unmodified original flow.
6692 ret = flow_create_split_outer(dev, flow, attr,
6693 buf->entry[i].pattern,
6694 p_actions_rx, &flow_split_info,
6698 if (is_flow_tunnel_steer_rule(wks->flows[0].tof_type)) {
6699 ret = flow_tunnel_add_default_miss(dev, flow, attr,
6702 wks->flows[0].tunnel,
6706 mlx5_free(default_miss_ctx.queue);
6711 /* Create the tx flow. */
6713 attr_tx.group = MLX5_HAIRPIN_TX_TABLE;
6714 attr_tx.ingress = 0;
6716 dev_flow = flow_drv_prepare(dev, flow, &attr_tx, items_tx.items,
6717 actions_hairpin_tx.actions,
6721 dev_flow->flow = flow;
6722 dev_flow->external = 0;
6723 SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
6724 dev_flow->handle, next);
6725 ret = flow_drv_translate(dev, dev_flow, &attr_tx,
6727 actions_hairpin_tx.actions, error);
6732 * Update the metadata register copy table. If extensive
6733 * metadata feature is enabled and registers are supported
6734 * we might create the extra rte_flow for each unique
6735 * MARK/FLAG action ID.
6737 * The table is updated for ingress Flows only, because
6738 * the egress Flows belong to the different device and
6739 * copy table should be updated in peer NIC Rx domain.
6741 if (attr->ingress &&
6742 (external || attr->group != MLX5_FLOW_MREG_CP_TABLE_GROUP)) {
6743 ret = flow_mreg_update_copy_table(dev, flow, actions, error);
6748 * If the flow is external (from application) OR device is started,
6749 * OR mreg discover, then apply immediately.
6751 if (external || dev->data->dev_started ||
6752 (attr->group == MLX5_FLOW_MREG_CP_TABLE_GROUP &&
6753 attr->priority == MLX5_FLOW_LOWEST_PRIO_INDICATOR)) {
6754 ret = flow_drv_apply(dev, flow, error);
6759 flow_rxq_flags_set(dev, flow);
6760 rte_free(translated_actions);
6761 tunnel = flow_tunnel_from_rule(wks->flows);
6764 flow->tunnel_id = tunnel->tunnel_id;
6765 __atomic_add_fetch(&tunnel->refctn, 1, __ATOMIC_RELAXED);
6766 mlx5_free(default_miss_ctx.queue);
6768 mlx5_flow_pop_thread_workspace();
6772 ret = rte_errno; /* Save rte_errno before cleanup. */
6773 flow_mreg_del_copy_action(dev, flow);
6774 flow_drv_destroy(dev, flow);
6775 if (rss_desc->shared_rss)
6776 __atomic_sub_fetch(&((struct mlx5_shared_action_rss *)
6778 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
6779 rss_desc->shared_rss))->refcnt, 1, __ATOMIC_RELAXED);
6780 mlx5_ipool_free(priv->flows[type], idx);
6781 rte_errno = ret; /* Restore rte_errno. */
6784 mlx5_flow_pop_thread_workspace();
6785 error_before_hairpin_split:
6786 rte_free(translated_actions);
6791 * Create a dedicated flow rule on e-switch table 0 (root table), to direct all
6792 * incoming packets to table 1.
6794 * Other flow rules, requested for group n, will be created in
6795 * e-switch table n+1.
6796 * Jump action to e-switch group n will be created to group n+1.
6798 * Used when working in switchdev mode, to utilise advantages of table 1
6802 * Pointer to Ethernet device.
6805 * Pointer to flow on success, NULL otherwise and rte_errno is set.
6808 mlx5_flow_create_esw_table_zero_flow(struct rte_eth_dev *dev)
6810 const struct rte_flow_attr attr = {
6817 const struct rte_flow_item pattern = {
6818 .type = RTE_FLOW_ITEM_TYPE_END,
6820 struct rte_flow_action_jump jump = {
6823 const struct rte_flow_action actions[] = {
6825 .type = RTE_FLOW_ACTION_TYPE_JUMP,
6829 .type = RTE_FLOW_ACTION_TYPE_END,
6832 struct rte_flow_error error;
6834 return (void *)(uintptr_t)flow_list_create(dev, MLX5_FLOW_TYPE_CTL,
6836 actions, false, &error);
6840 * Create a dedicated flow rule on e-switch table 1, matches ESW manager
6841 * and sq number, directs all packets to peer vport.
6844 * Pointer to Ethernet device.
6849 * Flow ID on success, 0 otherwise and rte_errno is set.
6852 mlx5_flow_create_devx_sq_miss_flow(struct rte_eth_dev *dev, uint32_t txq)
6854 struct rte_flow_attr attr = {
6856 .priority = MLX5_FLOW_LOWEST_PRIO_INDICATOR,
6861 struct rte_flow_item_port_id port_spec = {
6862 .id = MLX5_PORT_ESW_MGR,
6864 struct mlx5_rte_flow_item_tx_queue txq_spec = {
6867 struct rte_flow_item pattern[] = {
6869 .type = RTE_FLOW_ITEM_TYPE_PORT_ID,
6873 .type = (enum rte_flow_item_type)
6874 MLX5_RTE_FLOW_ITEM_TYPE_TX_QUEUE,
6878 .type = RTE_FLOW_ITEM_TYPE_END,
6881 struct rte_flow_action_jump jump = {
6884 struct rte_flow_action_port_id port = {
6885 .id = dev->data->port_id,
6887 struct rte_flow_action actions[] = {
6889 .type = RTE_FLOW_ACTION_TYPE_JUMP,
6893 .type = RTE_FLOW_ACTION_TYPE_END,
6896 struct rte_flow_error error;
6899 * Creates group 0, highest priority jump flow.
6900 * Matches txq to bypass kernel packets.
6902 if (flow_list_create(dev, MLX5_FLOW_TYPE_CTL, &attr, pattern, actions,
6903 false, &error) == 0)
6905 /* Create group 1, lowest priority redirect flow for txq. */
6907 actions[0].conf = &port;
6908 actions[0].type = RTE_FLOW_ACTION_TYPE_PORT_ID;
6909 return flow_list_create(dev, MLX5_FLOW_TYPE_CTL, &attr, pattern,
6910 actions, false, &error);
6914 * Validate a flow supported by the NIC.
6916 * @see rte_flow_validate()
6920 mlx5_flow_validate(struct rte_eth_dev *dev,
6921 const struct rte_flow_attr *attr,
6922 const struct rte_flow_item items[],
6923 const struct rte_flow_action original_actions[],
6924 struct rte_flow_error *error)
6927 struct mlx5_translated_action_handle
6928 indir_actions[MLX5_MAX_INDIRECT_ACTIONS];
6929 int indir_actions_n = MLX5_MAX_INDIRECT_ACTIONS;
6930 const struct rte_flow_action *actions;
6931 struct rte_flow_action *translated_actions = NULL;
6932 int ret = flow_action_handles_translate(dev, original_actions,
6935 &translated_actions, error);
6939 actions = translated_actions ? translated_actions : original_actions;
6940 hairpin_flow = flow_check_hairpin_split(dev, attr, actions);
6941 ret = flow_drv_validate(dev, attr, items, actions,
6942 true, hairpin_flow, error);
6943 rte_free(translated_actions);
6950 * @see rte_flow_create()
6954 mlx5_flow_create(struct rte_eth_dev *dev,
6955 const struct rte_flow_attr *attr,
6956 const struct rte_flow_item items[],
6957 const struct rte_flow_action actions[],
6958 struct rte_flow_error *error)
6960 struct mlx5_priv *priv = dev->data->dev_private;
6962 if (priv->sh->config.dv_flow_en == 2) {
6963 rte_flow_error_set(error, ENOTSUP,
6964 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6966 "Flow non-Q creation not supported");
6970 * If the device is not started yet, it is not allowed to created a
6971 * flow from application. PMD default flows and traffic control flows
6974 if (unlikely(!dev->data->dev_started)) {
6975 DRV_LOG(DEBUG, "port %u is not started when "
6976 "inserting a flow", dev->data->port_id);
6977 rte_flow_error_set(error, ENODEV,
6978 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6980 "port not started");
6984 return (void *)(uintptr_t)flow_list_create(dev, MLX5_FLOW_TYPE_GEN,
6985 attr, items, actions,
6990 * Destroy a flow in a list.
6993 * Pointer to Ethernet device.
6994 * @param[in] flow_idx
6995 * Index of flow to destroy.
6998 flow_list_destroy(struct rte_eth_dev *dev, enum mlx5_flow_type type,
7001 struct mlx5_priv *priv = dev->data->dev_private;
7002 struct rte_flow *flow = mlx5_ipool_get(priv->flows[type], flow_idx);
7006 MLX5_ASSERT(flow->type == type);
7008 * Update RX queue flags only if port is started, otherwise it is
7011 if (dev->data->dev_started)
7012 flow_rxq_flags_trim(dev, flow);
7013 flow_drv_destroy(dev, flow);
7015 struct mlx5_flow_tunnel *tunnel;
7017 tunnel = mlx5_find_tunnel_id(dev, flow->tunnel_id);
7019 if (!__atomic_sub_fetch(&tunnel->refctn, 1, __ATOMIC_RELAXED))
7020 mlx5_flow_tunnel_free(dev, tunnel);
7022 flow_mreg_del_copy_action(dev, flow);
7023 mlx5_ipool_free(priv->flows[type], flow_idx);
7027 * Destroy all flows.
7030 * Pointer to Ethernet device.
7032 * Flow type to be flushed.
7034 * If flushing is called actively.
7037 mlx5_flow_list_flush(struct rte_eth_dev *dev, enum mlx5_flow_type type,
7040 struct mlx5_priv *priv = dev->data->dev_private;
7041 uint32_t num_flushed = 0, fidx = 1;
7042 struct rte_flow *flow;
7044 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
7045 if (priv->sh->config.dv_flow_en == 2 &&
7046 type == MLX5_FLOW_TYPE_GEN) {
7047 flow_hw_q_flow_flush(dev, NULL);
7052 MLX5_IPOOL_FOREACH(priv->flows[type], fidx, flow) {
7053 flow_list_destroy(dev, type, fidx);
7057 DRV_LOG(INFO, "port %u: %u flows flushed before stopping",
7058 dev->data->port_id, num_flushed);
7063 * Stop all default actions for flows.
7066 * Pointer to Ethernet device.
7069 mlx5_flow_stop_default(struct rte_eth_dev *dev)
7071 flow_mreg_del_default_copy_action(dev);
7072 flow_rxq_flags_clear(dev);
7076 * Start all default actions for flows.
7079 * Pointer to Ethernet device.
7081 * 0 on success, a negative errno value otherwise and rte_errno is set.
7084 mlx5_flow_start_default(struct rte_eth_dev *dev)
7086 struct rte_flow_error error;
7088 /* Make sure default copy action (reg_c[0] -> reg_b) is created. */
7089 return flow_mreg_add_default_copy_action(dev, &error);
7093 * Release key of thread specific flow workspace data.
7096 flow_release_workspace(void *data)
7098 struct mlx5_flow_workspace *wks = data;
7099 struct mlx5_flow_workspace *next;
7103 free(wks->rss_desc.queue);
7110 * Get thread specific current flow workspace.
7112 * @return pointer to thread specific flow workspace data, NULL on error.
7114 struct mlx5_flow_workspace*
7115 mlx5_flow_get_thread_workspace(void)
7117 struct mlx5_flow_workspace *data;
7119 data = mlx5_flow_os_get_specific_workspace();
7120 MLX5_ASSERT(data && data->inuse);
7121 if (!data || !data->inuse)
7122 DRV_LOG(ERR, "flow workspace not initialized.");
7127 * Allocate and init new flow workspace.
7129 * @return pointer to flow workspace data, NULL on error.
7131 static struct mlx5_flow_workspace*
7132 flow_alloc_thread_workspace(void)
7134 struct mlx5_flow_workspace *data = calloc(1, sizeof(*data));
7137 DRV_LOG(ERR, "Failed to allocate flow workspace "
7141 data->rss_desc.queue = calloc(1,
7142 sizeof(uint16_t) * MLX5_RSSQ_DEFAULT_NUM);
7143 if (!data->rss_desc.queue)
7145 data->rssq_num = MLX5_RSSQ_DEFAULT_NUM;
7148 free(data->rss_desc.queue);
7154 * Get new thread specific flow workspace.
7156 * If current workspace inuse, create new one and set as current.
7158 * @return pointer to thread specific flow workspace data, NULL on error.
7160 static struct mlx5_flow_workspace*
7161 mlx5_flow_push_thread_workspace(void)
7163 struct mlx5_flow_workspace *curr;
7164 struct mlx5_flow_workspace *data;
7166 curr = mlx5_flow_os_get_specific_workspace();
7168 data = flow_alloc_thread_workspace();
7171 } else if (!curr->inuse) {
7173 } else if (curr->next) {
7176 data = flow_alloc_thread_workspace();
7184 /* Set as current workspace */
7185 if (mlx5_flow_os_set_specific_workspace(data))
7186 DRV_LOG(ERR, "Failed to set flow workspace to thread.");
7191 * Close current thread specific flow workspace.
7193 * If previous workspace available, set it as current.
7195 * @return pointer to thread specific flow workspace data, NULL on error.
7198 mlx5_flow_pop_thread_workspace(void)
7200 struct mlx5_flow_workspace *data = mlx5_flow_get_thread_workspace();
7205 DRV_LOG(ERR, "Failed to close unused flow workspace.");
7211 if (mlx5_flow_os_set_specific_workspace(data->prev))
7212 DRV_LOG(ERR, "Failed to set flow workspace to thread.");
7216 * Verify the flow list is empty
7219 * Pointer to Ethernet device.
7221 * @return the number of flows not released.
7224 mlx5_flow_verify(struct rte_eth_dev *dev __rte_unused)
7226 struct mlx5_priv *priv = dev->data->dev_private;
7227 struct rte_flow *flow;
7231 for (i = 0; i < MLX5_FLOW_TYPE_MAXI; i++) {
7232 MLX5_IPOOL_FOREACH(priv->flows[i], idx, flow) {
7233 DRV_LOG(DEBUG, "port %u flow %p still referenced",
7234 dev->data->port_id, (void *)flow);
7242 * Enable default hairpin egress flow.
7245 * Pointer to Ethernet device.
7250 * 0 on success, a negative errno value otherwise and rte_errno is set.
7253 mlx5_ctrl_flow_source_queue(struct rte_eth_dev *dev,
7256 const struct rte_flow_attr attr = {
7260 struct mlx5_rte_flow_item_tx_queue queue_spec = {
7263 struct mlx5_rte_flow_item_tx_queue queue_mask = {
7264 .queue = UINT32_MAX,
7266 struct rte_flow_item items[] = {
7268 .type = (enum rte_flow_item_type)
7269 MLX5_RTE_FLOW_ITEM_TYPE_TX_QUEUE,
7270 .spec = &queue_spec,
7272 .mask = &queue_mask,
7275 .type = RTE_FLOW_ITEM_TYPE_END,
7278 struct rte_flow_action_jump jump = {
7279 .group = MLX5_HAIRPIN_TX_TABLE,
7281 struct rte_flow_action actions[2];
7283 struct rte_flow_error error;
7285 actions[0].type = RTE_FLOW_ACTION_TYPE_JUMP;
7286 actions[0].conf = &jump;
7287 actions[1].type = RTE_FLOW_ACTION_TYPE_END;
7288 flow_idx = flow_list_create(dev, MLX5_FLOW_TYPE_CTL,
7289 &attr, items, actions, false, &error);
7292 "Failed to create ctrl flow: rte_errno(%d),"
7293 " type(%d), message(%s)",
7294 rte_errno, error.type,
7295 error.message ? error.message : " (no stated reason)");
7302 * Enable a control flow configured from the control plane.
7305 * Pointer to Ethernet device.
7307 * An Ethernet flow spec to apply.
7309 * An Ethernet flow mask to apply.
7311 * A VLAN flow spec to apply.
7313 * A VLAN flow mask to apply.
7316 * 0 on success, a negative errno value otherwise and rte_errno is set.
7319 mlx5_ctrl_flow_vlan(struct rte_eth_dev *dev,
7320 struct rte_flow_item_eth *eth_spec,
7321 struct rte_flow_item_eth *eth_mask,
7322 struct rte_flow_item_vlan *vlan_spec,
7323 struct rte_flow_item_vlan *vlan_mask)
7325 struct mlx5_priv *priv = dev->data->dev_private;
7326 const struct rte_flow_attr attr = {
7328 .priority = MLX5_FLOW_LOWEST_PRIO_INDICATOR,
7330 struct rte_flow_item items[] = {
7332 .type = RTE_FLOW_ITEM_TYPE_ETH,
7338 .type = (vlan_spec) ? RTE_FLOW_ITEM_TYPE_VLAN :
7339 RTE_FLOW_ITEM_TYPE_END,
7345 .type = RTE_FLOW_ITEM_TYPE_END,
7348 uint16_t queue[priv->reta_idx_n];
7349 struct rte_flow_action_rss action_rss = {
7350 .func = RTE_ETH_HASH_FUNCTION_DEFAULT,
7352 .types = priv->rss_conf.rss_hf,
7353 .key_len = priv->rss_conf.rss_key_len,
7354 .queue_num = priv->reta_idx_n,
7355 .key = priv->rss_conf.rss_key,
7358 struct rte_flow_action actions[] = {
7360 .type = RTE_FLOW_ACTION_TYPE_RSS,
7361 .conf = &action_rss,
7364 .type = RTE_FLOW_ACTION_TYPE_END,
7368 struct rte_flow_error error;
7371 if (!priv->reta_idx_n || !priv->rxqs_n) {
7374 if (!(dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_RSS_FLAG))
7375 action_rss.types = 0;
7376 for (i = 0; i != priv->reta_idx_n; ++i)
7377 queue[i] = (*priv->reta_idx)[i];
7378 flow_idx = flow_list_create(dev, MLX5_FLOW_TYPE_CTL,
7379 &attr, items, actions, false, &error);
7386 * Enable a flow control configured from the control plane.
7389 * Pointer to Ethernet device.
7391 * An Ethernet flow spec to apply.
7393 * An Ethernet flow mask to apply.
7396 * 0 on success, a negative errno value otherwise and rte_errno is set.
7399 mlx5_ctrl_flow(struct rte_eth_dev *dev,
7400 struct rte_flow_item_eth *eth_spec,
7401 struct rte_flow_item_eth *eth_mask)
7403 return mlx5_ctrl_flow_vlan(dev, eth_spec, eth_mask, NULL, NULL);
7407 * Create default miss flow rule matching lacp traffic
7410 * Pointer to Ethernet device.
7412 * An Ethernet flow spec to apply.
7415 * 0 on success, a negative errno value otherwise and rte_errno is set.
7418 mlx5_flow_lacp_miss(struct rte_eth_dev *dev)
7421 * The LACP matching is done by only using ether type since using
7422 * a multicast dst mac causes kernel to give low priority to this flow.
7424 static const struct rte_flow_item_eth lacp_spec = {
7425 .type = RTE_BE16(0x8809),
7427 static const struct rte_flow_item_eth lacp_mask = {
7430 const struct rte_flow_attr attr = {
7433 struct rte_flow_item items[] = {
7435 .type = RTE_FLOW_ITEM_TYPE_ETH,
7440 .type = RTE_FLOW_ITEM_TYPE_END,
7443 struct rte_flow_action actions[] = {
7445 .type = (enum rte_flow_action_type)
7446 MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS,
7449 .type = RTE_FLOW_ACTION_TYPE_END,
7452 struct rte_flow_error error;
7453 uint32_t flow_idx = flow_list_create(dev, MLX5_FLOW_TYPE_CTL,
7454 &attr, items, actions,
7465 * @see rte_flow_destroy()
7469 mlx5_flow_destroy(struct rte_eth_dev *dev,
7470 struct rte_flow *flow,
7471 struct rte_flow_error *error __rte_unused)
7473 struct mlx5_priv *priv = dev->data->dev_private;
7475 if (priv->sh->config.dv_flow_en == 2)
7476 return rte_flow_error_set(error, ENOTSUP,
7477 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7479 "Flow non-Q destruction not supported");
7480 flow_list_destroy(dev, MLX5_FLOW_TYPE_GEN,
7481 (uintptr_t)(void *)flow);
7486 * Destroy all flows.
7488 * @see rte_flow_flush()
7492 mlx5_flow_flush(struct rte_eth_dev *dev,
7493 struct rte_flow_error *error __rte_unused)
7495 mlx5_flow_list_flush(dev, MLX5_FLOW_TYPE_GEN, false);
7502 * @see rte_flow_isolate()
7506 mlx5_flow_isolate(struct rte_eth_dev *dev,
7508 struct rte_flow_error *error)
7510 struct mlx5_priv *priv = dev->data->dev_private;
7512 if (dev->data->dev_started) {
7513 rte_flow_error_set(error, EBUSY,
7514 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7516 "port must be stopped first");
7519 priv->isolated = !!enable;
7521 dev->dev_ops = &mlx5_dev_ops_isolate;
7523 dev->dev_ops = &mlx5_dev_ops;
7525 dev->rx_descriptor_status = mlx5_rx_descriptor_status;
7526 dev->tx_descriptor_status = mlx5_tx_descriptor_status;
7534 * @see rte_flow_query()
7538 flow_drv_query(struct rte_eth_dev *dev,
7540 const struct rte_flow_action *actions,
7542 struct rte_flow_error *error)
7544 struct mlx5_priv *priv = dev->data->dev_private;
7545 const struct mlx5_flow_driver_ops *fops;
7546 struct rte_flow *flow = mlx5_ipool_get(priv->flows[MLX5_FLOW_TYPE_GEN],
7548 enum mlx5_flow_drv_type ftype;
7551 return rte_flow_error_set(error, ENOENT,
7552 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7554 "invalid flow handle");
7556 ftype = flow->drv_type;
7557 MLX5_ASSERT(ftype > MLX5_FLOW_TYPE_MIN && ftype < MLX5_FLOW_TYPE_MAX);
7558 fops = flow_get_drv_ops(ftype);
7560 return fops->query(dev, flow, actions, data, error);
7566 * @see rte_flow_query()
7570 mlx5_flow_query(struct rte_eth_dev *dev,
7571 struct rte_flow *flow,
7572 const struct rte_flow_action *actions,
7574 struct rte_flow_error *error)
7577 struct mlx5_priv *priv = dev->data->dev_private;
7579 if (priv->sh->config.dv_flow_en == 2)
7580 return rte_flow_error_set(error, ENOTSUP,
7581 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7583 "Flow non-Q query not supported");
7584 ret = flow_drv_query(dev, (uintptr_t)(void *)flow, actions, data,
7592 * Get rte_flow callbacks.
7595 * Pointer to Ethernet device structure.
7597 * Pointer to operation-specific structure.
7602 mlx5_flow_ops_get(struct rte_eth_dev *dev __rte_unused,
7603 const struct rte_flow_ops **ops)
7605 *ops = &mlx5_flow_ops;
7610 * Validate meter policy actions.
7611 * Dispatcher for action type specific validation.
7614 * Pointer to the Ethernet device structure.
7616 * The meter policy action object to validate.
7618 * Attributes of flow to determine steering domain.
7619 * @param[out] is_rss
7621 * @param[out] domain_bitmap
7623 * @param[out] is_def_policy
7624 * Is default policy or not.
7626 * Perform verbose error reporting if not NULL. Initialized in case of
7630 * 0 on success, otherwise negative errno value.
7633 mlx5_flow_validate_mtr_acts(struct rte_eth_dev *dev,
7634 const struct rte_flow_action *actions[RTE_COLORS],
7635 struct rte_flow_attr *attr,
7637 uint8_t *domain_bitmap,
7638 uint8_t *policy_mode,
7639 struct rte_mtr_error *error)
7641 const struct mlx5_flow_driver_ops *fops;
7643 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7644 return fops->validate_mtr_acts(dev, actions, attr, is_rss,
7645 domain_bitmap, policy_mode, error);
7649 * Destroy the meter table set.
7652 * Pointer to Ethernet device.
7653 * @param[in] mtr_policy
7654 * Meter policy struct.
7657 mlx5_flow_destroy_mtr_acts(struct rte_eth_dev *dev,
7658 struct mlx5_flow_meter_policy *mtr_policy)
7660 const struct mlx5_flow_driver_ops *fops;
7662 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7663 fops->destroy_mtr_acts(dev, mtr_policy);
7667 * Create policy action, lock free,
7668 * (mutex should be acquired by caller).
7669 * Dispatcher for action type specific call.
7672 * Pointer to the Ethernet device structure.
7673 * @param[in] mtr_policy
7674 * Meter policy struct.
7676 * Action specification used to create meter actions.
7678 * Perform verbose error reporting if not NULL. Initialized in case of
7682 * 0 on success, otherwise negative errno value.
7685 mlx5_flow_create_mtr_acts(struct rte_eth_dev *dev,
7686 struct mlx5_flow_meter_policy *mtr_policy,
7687 const struct rte_flow_action *actions[RTE_COLORS],
7688 struct rte_mtr_error *error)
7690 const struct mlx5_flow_driver_ops *fops;
7692 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7693 return fops->create_mtr_acts(dev, mtr_policy, actions, error);
7697 * Create policy rules, lock free,
7698 * (mutex should be acquired by caller).
7699 * Dispatcher for action type specific call.
7702 * Pointer to the Ethernet device structure.
7703 * @param[in] mtr_policy
7704 * Meter policy struct.
7707 * 0 on success, -1 otherwise.
7710 mlx5_flow_create_policy_rules(struct rte_eth_dev *dev,
7711 struct mlx5_flow_meter_policy *mtr_policy)
7713 const struct mlx5_flow_driver_ops *fops;
7715 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7716 return fops->create_policy_rules(dev, mtr_policy);
7720 * Destroy policy rules, lock free,
7721 * (mutex should be acquired by caller).
7722 * Dispatcher for action type specific call.
7725 * Pointer to the Ethernet device structure.
7726 * @param[in] mtr_policy
7727 * Meter policy struct.
7730 mlx5_flow_destroy_policy_rules(struct rte_eth_dev *dev,
7731 struct mlx5_flow_meter_policy *mtr_policy)
7733 const struct mlx5_flow_driver_ops *fops;
7735 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7736 fops->destroy_policy_rules(dev, mtr_policy);
7740 * Destroy the default policy table set.
7743 * Pointer to Ethernet device.
7746 mlx5_flow_destroy_def_policy(struct rte_eth_dev *dev)
7748 const struct mlx5_flow_driver_ops *fops;
7750 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7751 fops->destroy_def_policy(dev);
7755 * Destroy the default policy table set.
7758 * Pointer to Ethernet device.
7761 * 0 on success, -1 otherwise.
7764 mlx5_flow_create_def_policy(struct rte_eth_dev *dev)
7766 const struct mlx5_flow_driver_ops *fops;
7768 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7769 return fops->create_def_policy(dev);
7773 * Create the needed meter and suffix tables.
7776 * Pointer to Ethernet device.
7779 * 0 on success, -1 otherwise.
7782 mlx5_flow_create_mtr_tbls(struct rte_eth_dev *dev,
7783 struct mlx5_flow_meter_info *fm,
7785 uint8_t domain_bitmap)
7787 const struct mlx5_flow_driver_ops *fops;
7789 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7790 return fops->create_mtr_tbls(dev, fm, mtr_idx, domain_bitmap);
7794 * Destroy the meter table set.
7797 * Pointer to Ethernet device.
7799 * Pointer to the meter table set.
7802 mlx5_flow_destroy_mtr_tbls(struct rte_eth_dev *dev,
7803 struct mlx5_flow_meter_info *fm)
7805 const struct mlx5_flow_driver_ops *fops;
7807 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7808 fops->destroy_mtr_tbls(dev, fm);
7812 * Destroy the global meter drop table.
7815 * Pointer to Ethernet device.
7818 mlx5_flow_destroy_mtr_drop_tbls(struct rte_eth_dev *dev)
7820 const struct mlx5_flow_driver_ops *fops;
7822 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7823 fops->destroy_mtr_drop_tbls(dev);
7827 * Destroy the sub policy table with RX queue.
7830 * Pointer to Ethernet device.
7831 * @param[in] mtr_policy
7832 * Pointer to meter policy table.
7835 mlx5_flow_destroy_sub_policy_with_rxq(struct rte_eth_dev *dev,
7836 struct mlx5_flow_meter_policy *mtr_policy)
7838 const struct mlx5_flow_driver_ops *fops;
7840 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7841 fops->destroy_sub_policy_with_rxq(dev, mtr_policy);
7845 * Allocate the needed aso flow meter id.
7848 * Pointer to Ethernet device.
7851 * Index to aso flow meter on success, NULL otherwise.
7854 mlx5_flow_mtr_alloc(struct rte_eth_dev *dev)
7856 const struct mlx5_flow_driver_ops *fops;
7858 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7859 return fops->create_meter(dev);
7863 * Free the aso flow meter id.
7866 * Pointer to Ethernet device.
7867 * @param[in] mtr_idx
7868 * Index to aso flow meter to be free.
7874 mlx5_flow_mtr_free(struct rte_eth_dev *dev, uint32_t mtr_idx)
7876 const struct mlx5_flow_driver_ops *fops;
7878 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7879 fops->free_meter(dev, mtr_idx);
7883 * Allocate a counter.
7886 * Pointer to Ethernet device structure.
7889 * Index to allocated counter on success, 0 otherwise.
7892 mlx5_counter_alloc(struct rte_eth_dev *dev)
7894 const struct mlx5_flow_driver_ops *fops;
7895 struct rte_flow_attr attr = { .transfer = 0 };
7897 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
7898 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7899 return fops->counter_alloc(dev);
7902 "port %u counter allocate is not supported.",
7903 dev->data->port_id);
7911 * Pointer to Ethernet device structure.
7913 * Index to counter to be free.
7916 mlx5_counter_free(struct rte_eth_dev *dev, uint32_t cnt)
7918 const struct mlx5_flow_driver_ops *fops;
7919 struct rte_flow_attr attr = { .transfer = 0 };
7921 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
7922 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7923 fops->counter_free(dev, cnt);
7927 "port %u counter free is not supported.",
7928 dev->data->port_id);
7932 * Query counter statistics.
7935 * Pointer to Ethernet device structure.
7937 * Index to counter to query.
7939 * Set to clear counter statistics.
7941 * The counter hits packets number to save.
7943 * The counter hits bytes number to save.
7946 * 0 on success, a negative errno value otherwise.
7949 mlx5_counter_query(struct rte_eth_dev *dev, uint32_t cnt,
7950 bool clear, uint64_t *pkts, uint64_t *bytes, void **action)
7952 const struct mlx5_flow_driver_ops *fops;
7953 struct rte_flow_attr attr = { .transfer = 0 };
7955 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
7956 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7957 return fops->counter_query(dev, cnt, clear, pkts,
7961 "port %u counter query is not supported.",
7962 dev->data->port_id);
7967 * Get information about HWS pre-configurable resources.
7970 * Pointer to the rte_eth_dev structure.
7971 * @param[out] port_info
7972 * Pointer to port information.
7973 * @param[out] queue_info
7974 * Pointer to queue information.
7976 * Pointer to error structure.
7979 * 0 on success, a negative errno value otherwise and rte_errno is set.
7982 mlx5_flow_info_get(struct rte_eth_dev *dev,
7983 struct rte_flow_port_info *port_info,
7984 struct rte_flow_queue_info *queue_info,
7985 struct rte_flow_error *error)
7987 const struct mlx5_flow_driver_ops *fops;
7989 if (flow_get_drv_type(dev, NULL) != MLX5_FLOW_TYPE_HW)
7990 return rte_flow_error_set(error, ENOTSUP,
7991 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7993 "info get with incorrect steering mode");
7994 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
7995 return fops->info_get(dev, port_info, queue_info, error);
7999 * Configure port HWS resources.
8002 * Pointer to the rte_eth_dev structure.
8003 * @param[in] port_attr
8004 * Port configuration attributes.
8005 * @param[in] nb_queue
8007 * @param[in] queue_attr
8008 * Array that holds attributes for each flow queue.
8010 * Pointer to error structure.
8013 * 0 on success, a negative errno value otherwise and rte_errno is set.
8016 mlx5_flow_port_configure(struct rte_eth_dev *dev,
8017 const struct rte_flow_port_attr *port_attr,
8019 const struct rte_flow_queue_attr *queue_attr[],
8020 struct rte_flow_error *error)
8022 const struct mlx5_flow_driver_ops *fops;
8024 if (flow_get_drv_type(dev, NULL) != MLX5_FLOW_TYPE_HW)
8025 return rte_flow_error_set(error, ENOTSUP,
8026 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8028 "port configure with incorrect steering mode");
8029 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
8030 return fops->configure(dev, port_attr, nb_queue, queue_attr, error);
8034 * Create flow item template.
8037 * Pointer to the rte_eth_dev structure.
8039 * Pointer to the item template attributes.
8041 * The template item pattern.
8043 * Pointer to error structure.
8046 * 0 on success, a negative errno value otherwise and rte_errno is set.
8048 static struct rte_flow_pattern_template *
8049 mlx5_flow_pattern_template_create(struct rte_eth_dev *dev,
8050 const struct rte_flow_pattern_template_attr *attr,
8051 const struct rte_flow_item items[],
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 "pattern create with incorrect steering mode");
8063 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
8064 return fops->pattern_template_create(dev, attr, items, error);
8068 * Destroy flow item template.
8071 * Pointer to the rte_eth_dev structure.
8072 * @param[in] template
8073 * Pointer to the item 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_pattern_template_destroy(struct rte_eth_dev *dev,
8082 struct rte_flow_pattern_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 "pattern destroy with incorrect steering mode");
8092 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
8093 return fops->pattern_template_destroy(dev, template, error);
8097 * Create flow item template.
8100 * Pointer to the rte_eth_dev structure.
8102 * Pointer to the action template attributes.
8103 * @param[in] actions
8104 * Associated actions (list terminated by the END action).
8106 * List of actions that marks which of the action's member is constant.
8108 * Pointer to error structure.
8111 * 0 on success, a negative errno value otherwise and rte_errno is set.
8113 static struct rte_flow_actions_template *
8114 mlx5_flow_actions_template_create(struct rte_eth_dev *dev,
8115 const struct rte_flow_actions_template_attr *attr,
8116 const struct rte_flow_action actions[],
8117 const struct rte_flow_action masks[],
8118 struct rte_flow_error *error)
8120 const struct mlx5_flow_driver_ops *fops;
8122 if (flow_get_drv_type(dev, NULL) != MLX5_FLOW_TYPE_HW) {
8123 rte_flow_error_set(error, ENOTSUP,
8124 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8126 "action create with incorrect steering mode");
8129 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
8130 return fops->actions_template_create(dev, attr, actions, masks, error);
8134 * Destroy flow action template.
8137 * Pointer to the rte_eth_dev structure.
8138 * @param[in] template
8139 * Pointer to the action template to be destroyed.
8141 * Pointer to error structure.
8144 * 0 on success, a negative errno value otherwise and rte_errno is set.
8147 mlx5_flow_actions_template_destroy(struct rte_eth_dev *dev,
8148 struct rte_flow_actions_template *template,
8149 struct rte_flow_error *error)
8151 const struct mlx5_flow_driver_ops *fops;
8153 if (flow_get_drv_type(dev, NULL) != MLX5_FLOW_TYPE_HW)
8154 return rte_flow_error_set(error, ENOTSUP,
8155 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8157 "action destroy with incorrect steering mode");
8158 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
8159 return fops->actions_template_destroy(dev, template, error);
8163 * Create flow table.
8166 * Pointer to the rte_eth_dev structure.
8168 * Pointer to the table attributes.
8169 * @param[in] item_templates
8170 * Item template array to be binded to the table.
8171 * @param[in] nb_item_templates
8172 * Number of item template.
8173 * @param[in] action_templates
8174 * Action template array to be binded to the table.
8175 * @param[in] nb_action_templates
8176 * Number of action template.
8178 * Pointer to error structure.
8181 * Table on success, NULL otherwise and rte_errno is set.
8183 static struct rte_flow_template_table *
8184 mlx5_flow_table_create(struct rte_eth_dev *dev,
8185 const struct rte_flow_template_table_attr *attr,
8186 struct rte_flow_pattern_template *item_templates[],
8187 uint8_t nb_item_templates,
8188 struct rte_flow_actions_template *action_templates[],
8189 uint8_t nb_action_templates,
8190 struct rte_flow_error *error)
8192 const struct mlx5_flow_driver_ops *fops;
8194 if (flow_get_drv_type(dev, NULL) != MLX5_FLOW_TYPE_HW) {
8195 rte_flow_error_set(error, ENOTSUP,
8196 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8198 "table create with incorrect steering mode");
8201 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
8202 return fops->template_table_create(dev,
8207 nb_action_templates,
8212 * PMD destroy flow table.
8215 * Pointer to the rte_eth_dev structure.
8217 * Pointer to the table to be destroyed.
8219 * Pointer to error structure.
8222 * 0 on success, a negative errno value otherwise and rte_errno is set.
8225 mlx5_flow_table_destroy(struct rte_eth_dev *dev,
8226 struct rte_flow_template_table *table,
8227 struct rte_flow_error *error)
8229 const struct mlx5_flow_driver_ops *fops;
8231 if (flow_get_drv_type(dev, NULL) != MLX5_FLOW_TYPE_HW)
8232 return rte_flow_error_set(error, ENOTSUP,
8233 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8235 "table destroy with incorrect steering mode");
8236 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
8237 return fops->template_table_destroy(dev, table, error);
8241 * Enqueue flow creation.
8244 * Pointer to the rte_eth_dev structure.
8245 * @param[in] queue_id
8246 * The queue to create the flow.
8248 * Pointer to the flow operation attributes.
8250 * Items with flow spec value.
8251 * @param[in] pattern_template_index
8252 * The item pattern flow follows from the table.
8253 * @param[in] actions
8254 * Action with flow spec value.
8255 * @param[in] action_template_index
8256 * The action pattern flow follows from the table.
8257 * @param[in] user_data
8258 * Pointer to the user_data.
8260 * Pointer to error structure.
8263 * Flow pointer on success, NULL otherwise and rte_errno is set.
8265 static struct rte_flow *
8266 mlx5_flow_async_flow_create(struct rte_eth_dev *dev,
8268 const struct rte_flow_op_attr *attr,
8269 struct rte_flow_template_table *table,
8270 const struct rte_flow_item items[],
8271 uint8_t pattern_template_index,
8272 const struct rte_flow_action actions[],
8273 uint8_t action_template_index,
8275 struct rte_flow_error *error)
8277 const struct mlx5_flow_driver_ops *fops;
8279 if (flow_get_drv_type(dev, NULL) != MLX5_FLOW_TYPE_HW) {
8280 rte_flow_error_set(error, ENOTSUP,
8281 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8283 "flow_q create with incorrect steering mode");
8286 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
8287 return fops->async_flow_create(dev, queue_id, attr, table,
8288 items, pattern_template_index,
8289 actions, action_template_index,
8294 * Enqueue flow destruction.
8297 * Pointer to the rte_eth_dev structure.
8299 * The queue to destroy the flow.
8301 * Pointer to the flow operation attributes.
8303 * Pointer to the flow to be destroyed.
8304 * @param[in] user_data
8305 * Pointer to the user_data.
8307 * Pointer to error structure.
8310 * 0 on success, negative value otherwise and rte_errno is set.
8313 mlx5_flow_async_flow_destroy(struct rte_eth_dev *dev,
8315 const struct rte_flow_op_attr *attr,
8316 struct rte_flow *flow,
8318 struct rte_flow_error *error)
8320 const struct mlx5_flow_driver_ops *fops;
8322 if (flow_get_drv_type(dev, NULL) != MLX5_FLOW_TYPE_HW)
8323 return rte_flow_error_set(error, ENOTSUP,
8324 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8326 "flow_q destroy with incorrect steering mode");
8327 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
8328 return fops->async_flow_destroy(dev, queue, attr, flow,
8333 * Pull the enqueued flows.
8336 * Pointer to the rte_eth_dev structure.
8338 * The queue to pull the result.
8339 * @param[in/out] res
8340 * Array to save the results.
8342 * Available result with the array.
8344 * Pointer to error structure.
8347 * Result number on success, negative value otherwise and rte_errno is set.
8350 mlx5_flow_pull(struct rte_eth_dev *dev,
8352 struct rte_flow_op_result res[],
8354 struct rte_flow_error *error)
8356 const struct mlx5_flow_driver_ops *fops;
8358 if (flow_get_drv_type(dev, NULL) != MLX5_FLOW_TYPE_HW)
8359 return rte_flow_error_set(error, ENOTSUP,
8360 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8362 "flow_q pull with incorrect steering mode");
8363 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
8364 return fops->pull(dev, queue, res, n_res, error);
8368 * Push the enqueued flows.
8371 * Pointer to the rte_eth_dev structure.
8373 * The queue to push the flows.
8375 * Pointer to error structure.
8378 * 0 on success, negative value otherwise and rte_errno is set.
8381 mlx5_flow_push(struct rte_eth_dev *dev,
8383 struct rte_flow_error *error)
8385 const struct mlx5_flow_driver_ops *fops;
8387 if (flow_get_drv_type(dev, NULL) != MLX5_FLOW_TYPE_HW)
8388 return rte_flow_error_set(error, ENOTSUP,
8389 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8391 "flow_q push with incorrect steering mode");
8392 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
8393 return fops->push(dev, queue, error);
8397 * Create shared action.
8400 * Pointer to the rte_eth_dev structure.
8402 * Which queue to be used..
8404 * Operation attribute.
8406 * Indirect action configuration.
8408 * rte_flow action detail.
8409 * @param[in] user_data
8410 * Pointer to the user_data.
8412 * Pointer to error structure.
8415 * Action handle on success, NULL otherwise and rte_errno is set.
8417 static struct rte_flow_action_handle *
8418 mlx5_flow_async_action_handle_create(struct rte_eth_dev *dev, uint32_t queue,
8419 const struct rte_flow_op_attr *attr,
8420 const struct rte_flow_indir_action_conf *conf,
8421 const struct rte_flow_action *action,
8423 struct rte_flow_error *error)
8425 const struct mlx5_flow_driver_ops *fops =
8426 flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
8428 return fops->async_action_create(dev, queue, attr, conf, action,
8433 * Update shared action.
8436 * Pointer to the rte_eth_dev structure.
8438 * Which queue to be used..
8440 * Operation attribute.
8442 * Action handle to be updated.
8445 * @param[in] user_data
8446 * Pointer to the user_data.
8448 * Pointer to error structure.
8451 * 0 on success, negative value otherwise and rte_errno is set.
8454 mlx5_flow_async_action_handle_update(struct rte_eth_dev *dev, uint32_t queue,
8455 const struct rte_flow_op_attr *attr,
8456 struct rte_flow_action_handle *handle,
8459 struct rte_flow_error *error)
8461 const struct mlx5_flow_driver_ops *fops =
8462 flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
8464 return fops->async_action_update(dev, queue, attr, handle,
8465 update, user_data, error);
8469 * Destroy shared action.
8472 * Pointer to the rte_eth_dev structure.
8474 * Which queue to be used..
8476 * Operation attribute.
8478 * Action handle to be destroyed.
8479 * @param[in] user_data
8480 * Pointer to the user_data.
8482 * Pointer to error structure.
8485 * 0 on success, negative value otherwise and rte_errno is set.
8488 mlx5_flow_async_action_handle_destroy(struct rte_eth_dev *dev, uint32_t queue,
8489 const struct rte_flow_op_attr *attr,
8490 struct rte_flow_action_handle *handle,
8492 struct rte_flow_error *error)
8494 const struct mlx5_flow_driver_ops *fops =
8495 flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
8497 return fops->async_action_destroy(dev, queue, attr, handle,
8502 * Allocate a new memory for the counter values wrapped by all the needed
8506 * Pointer to mlx5_dev_ctx_shared object.
8509 * 0 on success, a negative errno value otherwise.
8512 mlx5_flow_create_counter_stat_mem_mng(struct mlx5_dev_ctx_shared *sh)
8514 struct mlx5_counter_stats_mem_mng *mem_mng;
8515 volatile struct flow_counter_stats *raw_data;
8516 int raws_n = MLX5_CNT_CONTAINER_RESIZE + MLX5_MAX_PENDING_QUERIES;
8517 int size = (sizeof(struct flow_counter_stats) *
8518 MLX5_COUNTERS_PER_POOL +
8519 sizeof(struct mlx5_counter_stats_raw)) * raws_n +
8520 sizeof(struct mlx5_counter_stats_mem_mng);
8521 size_t pgsize = rte_mem_page_size();
8526 if (pgsize == (size_t)-1) {
8527 DRV_LOG(ERR, "Failed to get mem page size");
8531 mem = mlx5_malloc(MLX5_MEM_ZERO, size, pgsize, SOCKET_ID_ANY);
8536 mem_mng = (struct mlx5_counter_stats_mem_mng *)(mem + size) - 1;
8537 size = sizeof(*raw_data) * MLX5_COUNTERS_PER_POOL * raws_n;
8538 ret = mlx5_os_wrapped_mkey_create(sh->cdev->ctx, sh->cdev->pd,
8539 sh->cdev->pdn, mem, size,
8546 mem_mng->raws = (struct mlx5_counter_stats_raw *)(mem + size);
8547 raw_data = (volatile struct flow_counter_stats *)mem;
8548 for (i = 0; i < raws_n; ++i) {
8549 mem_mng->raws[i].mem_mng = mem_mng;
8550 mem_mng->raws[i].data = raw_data + i * MLX5_COUNTERS_PER_POOL;
8552 for (i = 0; i < MLX5_MAX_PENDING_QUERIES; ++i)
8553 LIST_INSERT_HEAD(&sh->cmng.free_stat_raws,
8554 mem_mng->raws + MLX5_CNT_CONTAINER_RESIZE + i,
8556 LIST_INSERT_HEAD(&sh->cmng.mem_mngs, mem_mng, next);
8557 sh->cmng.mem_mng = mem_mng;
8562 * Set the statistic memory to the new counter pool.
8565 * Pointer to mlx5_dev_ctx_shared object.
8567 * Pointer to the pool to set the statistic memory.
8570 * 0 on success, a negative errno value otherwise.
8573 mlx5_flow_set_counter_stat_mem(struct mlx5_dev_ctx_shared *sh,
8574 struct mlx5_flow_counter_pool *pool)
8576 struct mlx5_flow_counter_mng *cmng = &sh->cmng;
8577 /* Resize statistic memory once used out. */
8578 if (!(pool->index % MLX5_CNT_CONTAINER_RESIZE) &&
8579 mlx5_flow_create_counter_stat_mem_mng(sh)) {
8580 DRV_LOG(ERR, "Cannot resize counter stat mem.");
8583 rte_spinlock_lock(&pool->sl);
8584 pool->raw = cmng->mem_mng->raws + pool->index %
8585 MLX5_CNT_CONTAINER_RESIZE;
8586 rte_spinlock_unlock(&pool->sl);
8587 pool->raw_hw = NULL;
8591 #define MLX5_POOL_QUERY_FREQ_US 1000000
8594 * Set the periodic procedure for triggering asynchronous batch queries for all
8595 * the counter pools.
8598 * Pointer to mlx5_dev_ctx_shared object.
8601 mlx5_set_query_alarm(struct mlx5_dev_ctx_shared *sh)
8603 uint32_t pools_n, us;
8605 pools_n = __atomic_load_n(&sh->cmng.n_valid, __ATOMIC_RELAXED);
8606 us = MLX5_POOL_QUERY_FREQ_US / pools_n;
8607 DRV_LOG(DEBUG, "Set alarm for %u pools each %u us", pools_n, us);
8608 if (rte_eal_alarm_set(us, mlx5_flow_query_alarm, sh)) {
8609 sh->cmng.query_thread_on = 0;
8610 DRV_LOG(ERR, "Cannot reinitialize query alarm");
8612 sh->cmng.query_thread_on = 1;
8617 * The periodic procedure for triggering asynchronous batch queries for all the
8618 * counter pools. This function is probably called by the host thread.
8621 * The parameter for the alarm process.
8624 mlx5_flow_query_alarm(void *arg)
8626 struct mlx5_dev_ctx_shared *sh = arg;
8628 uint16_t pool_index = sh->cmng.pool_index;
8629 struct mlx5_flow_counter_mng *cmng = &sh->cmng;
8630 struct mlx5_flow_counter_pool *pool;
8633 if (sh->cmng.pending_queries >= MLX5_MAX_PENDING_QUERIES)
8635 rte_spinlock_lock(&cmng->pool_update_sl);
8636 pool = cmng->pools[pool_index];
8637 n_valid = cmng->n_valid;
8638 rte_spinlock_unlock(&cmng->pool_update_sl);
8639 /* Set the statistic memory to the new created pool. */
8640 if ((!pool->raw && mlx5_flow_set_counter_stat_mem(sh, pool)))
8643 /* There is a pool query in progress. */
8646 LIST_FIRST(&sh->cmng.free_stat_raws);
8648 /* No free counter statistics raw memory. */
8651 * Identify the counters released between query trigger and query
8652 * handle more efficiently. The counter released in this gap period
8653 * should wait for a new round of query as the new arrived packets
8654 * will not be taken into account.
8657 ret = mlx5_devx_cmd_flow_counter_query(pool->min_dcs, 0,
8658 MLX5_COUNTERS_PER_POOL,
8660 pool->raw_hw->mem_mng->wm.lkey,
8664 (uint64_t)(uintptr_t)pool);
8666 DRV_LOG(ERR, "Failed to trigger asynchronous query for dcs ID"
8667 " %d", pool->min_dcs->id);
8668 pool->raw_hw = NULL;
8671 LIST_REMOVE(pool->raw_hw, next);
8672 sh->cmng.pending_queries++;
8674 if (pool_index >= n_valid)
8677 sh->cmng.pool_index = pool_index;
8678 mlx5_set_query_alarm(sh);
8682 * Check and callback event for new aged flow in the counter pool
8685 * Pointer to mlx5_dev_ctx_shared object.
8687 * Pointer to Current counter pool.
8690 mlx5_flow_aging_check(struct mlx5_dev_ctx_shared *sh,
8691 struct mlx5_flow_counter_pool *pool)
8693 struct mlx5_priv *priv;
8694 struct mlx5_flow_counter *cnt;
8695 struct mlx5_age_info *age_info;
8696 struct mlx5_age_param *age_param;
8697 struct mlx5_counter_stats_raw *cur = pool->raw_hw;
8698 struct mlx5_counter_stats_raw *prev = pool->raw;
8699 const uint64_t curr_time = MLX5_CURR_TIME_SEC;
8700 const uint32_t time_delta = curr_time - pool->time_of_last_age_check;
8701 uint16_t expected = AGE_CANDIDATE;
8704 pool->time_of_last_age_check = curr_time;
8705 for (i = 0; i < MLX5_COUNTERS_PER_POOL; ++i) {
8706 cnt = MLX5_POOL_GET_CNT(pool, i);
8707 age_param = MLX5_CNT_TO_AGE(cnt);
8708 if (__atomic_load_n(&age_param->state,
8709 __ATOMIC_RELAXED) != AGE_CANDIDATE)
8711 if (cur->data[i].hits != prev->data[i].hits) {
8712 __atomic_store_n(&age_param->sec_since_last_hit, 0,
8716 if (__atomic_add_fetch(&age_param->sec_since_last_hit,
8718 __ATOMIC_RELAXED) <= age_param->timeout)
8721 * Hold the lock first, or if between the
8722 * state AGE_TMOUT and tailq operation the
8723 * release happened, the release procedure
8724 * may delete a non-existent tailq node.
8726 priv = rte_eth_devices[age_param->port_id].data->dev_private;
8727 age_info = GET_PORT_AGE_INFO(priv);
8728 rte_spinlock_lock(&age_info->aged_sl);
8729 if (__atomic_compare_exchange_n(&age_param->state, &expected,
8732 __ATOMIC_RELAXED)) {
8733 TAILQ_INSERT_TAIL(&age_info->aged_counters, cnt, next);
8734 MLX5_AGE_SET(age_info, MLX5_AGE_EVENT_NEW);
8736 rte_spinlock_unlock(&age_info->aged_sl);
8738 mlx5_age_event_prepare(sh);
8742 * Handler for the HW respond about ready values from an asynchronous batch
8743 * query. This function is probably called by the host thread.
8746 * The pointer to the shared device context.
8747 * @param[in] async_id
8748 * The Devx async ID.
8750 * The status of the completion.
8753 mlx5_flow_async_pool_query_handle(struct mlx5_dev_ctx_shared *sh,
8754 uint64_t async_id, int status)
8756 struct mlx5_flow_counter_pool *pool =
8757 (struct mlx5_flow_counter_pool *)(uintptr_t)async_id;
8758 struct mlx5_counter_stats_raw *raw_to_free;
8759 uint8_t query_gen = pool->query_gen ^ 1;
8760 struct mlx5_flow_counter_mng *cmng = &sh->cmng;
8761 enum mlx5_counter_type cnt_type =
8762 pool->is_aged ? MLX5_COUNTER_TYPE_AGE :
8763 MLX5_COUNTER_TYPE_ORIGIN;
8765 if (unlikely(status)) {
8766 raw_to_free = pool->raw_hw;
8768 raw_to_free = pool->raw;
8770 mlx5_flow_aging_check(sh, pool);
8771 rte_spinlock_lock(&pool->sl);
8772 pool->raw = pool->raw_hw;
8773 rte_spinlock_unlock(&pool->sl);
8774 /* Be sure the new raw counters data is updated in memory. */
8776 if (!TAILQ_EMPTY(&pool->counters[query_gen])) {
8777 rte_spinlock_lock(&cmng->csl[cnt_type]);
8778 TAILQ_CONCAT(&cmng->counters[cnt_type],
8779 &pool->counters[query_gen], next);
8780 rte_spinlock_unlock(&cmng->csl[cnt_type]);
8783 LIST_INSERT_HEAD(&sh->cmng.free_stat_raws, raw_to_free, next);
8784 pool->raw_hw = NULL;
8785 sh->cmng.pending_queries--;
8789 flow_group_to_table(uint32_t port_id, uint32_t group, uint32_t *table,
8790 const struct flow_grp_info *grp_info,
8791 struct rte_flow_error *error)
8793 if (grp_info->transfer && grp_info->external &&
8794 grp_info->fdb_def_rule) {
8795 if (group == UINT32_MAX)
8796 return rte_flow_error_set
8798 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
8800 "group index not supported");
8805 DRV_LOG(DEBUG, "port %u group=%#x table=%#x", port_id, group, *table);
8810 * Translate the rte_flow group index to HW table value.
8812 * If tunnel offload is disabled, all group ids converted to flow table
8813 * id using the standard method.
8814 * If tunnel offload is enabled, group id can be converted using the
8815 * standard or tunnel conversion method. Group conversion method
8816 * selection depends on flags in `grp_info` parameter:
8817 * - Internal (grp_info.external == 0) groups conversion uses the
8819 * - Group ids in JUMP action converted with the tunnel conversion.
8820 * - Group id in rule attribute conversion depends on a rule type and
8822 * ** non zero group attributes converted with the tunnel method
8823 * ** zero group attribute in non-tunnel rule is converted using the
8824 * standard method - there's only one root table
8825 * ** zero group attribute in steer tunnel rule is converted with the
8826 * standard method - single root table
8827 * ** zero group attribute in match tunnel rule is a special OvS
8828 * case: that value is used for portability reasons. That group
8829 * id is converted with the tunnel conversion method.
8834 * PMD tunnel offload object
8836 * rte_flow group index value.
8839 * @param[in] grp_info
8840 * flags used for conversion
8842 * Pointer to error structure.
8845 * 0 on success, a negative errno value otherwise and rte_errno is set.
8848 mlx5_flow_group_to_table(struct rte_eth_dev *dev,
8849 const struct mlx5_flow_tunnel *tunnel,
8850 uint32_t group, uint32_t *table,
8851 const struct flow_grp_info *grp_info,
8852 struct rte_flow_error *error)
8855 bool standard_translation;
8857 if (!grp_info->skip_scale && grp_info->external &&
8858 group < MLX5_MAX_TABLES_EXTERNAL)
8859 group *= MLX5_FLOW_TABLE_FACTOR;
8860 if (is_tunnel_offload_active(dev)) {
8861 standard_translation = !grp_info->external ||
8862 grp_info->std_tbl_fix;
8864 standard_translation = true;
8867 "port %u group=%u transfer=%d external=%d fdb_def_rule=%d translate=%s",
8868 dev->data->port_id, group, grp_info->transfer,
8869 grp_info->external, grp_info->fdb_def_rule,
8870 standard_translation ? "STANDARD" : "TUNNEL");
8871 if (standard_translation)
8872 ret = flow_group_to_table(dev->data->port_id, group, table,
8875 ret = tunnel_flow_group_to_flow_table(dev, tunnel, group,
8882 * Discover availability of metadata reg_c's.
8884 * Iteratively use test flows to check availability.
8887 * Pointer to the Ethernet device structure.
8890 * 0 on success, a negative errno value otherwise and rte_errno is set.
8893 mlx5_flow_discover_mreg_c(struct rte_eth_dev *dev)
8895 struct mlx5_priv *priv = dev->data->dev_private;
8896 enum modify_reg idx;
8899 /* reg_c[0] and reg_c[1] are reserved. */
8900 priv->sh->flow_mreg_c[n++] = REG_C_0;
8901 priv->sh->flow_mreg_c[n++] = REG_C_1;
8902 /* Discover availability of other reg_c's. */
8903 for (idx = REG_C_2; idx <= REG_C_7; ++idx) {
8904 struct rte_flow_attr attr = {
8905 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
8906 .priority = MLX5_FLOW_LOWEST_PRIO_INDICATOR,
8909 struct rte_flow_item items[] = {
8911 .type = RTE_FLOW_ITEM_TYPE_END,
8914 struct rte_flow_action actions[] = {
8916 .type = (enum rte_flow_action_type)
8917 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
8918 .conf = &(struct mlx5_flow_action_copy_mreg){
8924 .type = RTE_FLOW_ACTION_TYPE_JUMP,
8925 .conf = &(struct rte_flow_action_jump){
8926 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
8930 .type = RTE_FLOW_ACTION_TYPE_END,
8934 struct rte_flow *flow;
8935 struct rte_flow_error error;
8937 if (!priv->sh->config.dv_flow_en)
8939 /* Create internal flow, validation skips copy action. */
8940 flow_idx = flow_list_create(dev, MLX5_FLOW_TYPE_GEN, &attr,
8941 items, actions, false, &error);
8942 flow = mlx5_ipool_get(priv->flows[MLX5_FLOW_TYPE_GEN],
8946 priv->sh->flow_mreg_c[n++] = idx;
8947 flow_list_destroy(dev, MLX5_FLOW_TYPE_GEN, flow_idx);
8949 for (; n < MLX5_MREG_C_NUM; ++n)
8950 priv->sh->flow_mreg_c[n] = REG_NON;
8951 priv->sh->metadata_regc_check_flag = 1;
8956 save_dump_file(const uint8_t *data, uint32_t size,
8957 uint32_t type, uint64_t id, void *arg, FILE *file)
8959 char line[BUF_SIZE];
8962 uint32_t actions_num;
8963 struct rte_flow_query_count *count;
8965 memset(line, 0, BUF_SIZE);
8967 case DR_DUMP_REC_TYPE_PMD_MODIFY_HDR:
8968 actions_num = *(uint32_t *)(arg);
8969 out += snprintf(line + out, BUF_SIZE - out, "%d,0x%" PRIx64 ",%d,",
8970 type, id, actions_num);
8972 case DR_DUMP_REC_TYPE_PMD_PKT_REFORMAT:
8973 out += snprintf(line + out, BUF_SIZE - out, "%d,0x%" PRIx64 ",",
8976 case DR_DUMP_REC_TYPE_PMD_COUNTER:
8977 count = (struct rte_flow_query_count *)arg;
8979 "%d,0x%" PRIx64 ",%" PRIu64 ",%" PRIu64 "\n",
8980 type, id, count->hits, count->bytes);
8986 for (k = 0; k < size; k++) {
8987 /* Make sure we do not overrun the line buffer length. */
8988 if (out >= BUF_SIZE - 4) {
8992 out += snprintf(line + out, BUF_SIZE - out, "%02x",
8995 fprintf(file, "%s\n", line);
9000 mlx5_flow_query_counter(struct rte_eth_dev *dev, struct rte_flow *flow,
9001 struct rte_flow_query_count *count, struct rte_flow_error *error)
9003 struct rte_flow_action action[2];
9004 enum mlx5_flow_drv_type ftype;
9005 const struct mlx5_flow_driver_ops *fops;
9008 return rte_flow_error_set(error, ENOENT,
9009 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9011 "invalid flow handle");
9013 action[0].type = RTE_FLOW_ACTION_TYPE_COUNT;
9014 action[1].type = RTE_FLOW_ACTION_TYPE_END;
9015 if (flow->counter) {
9016 memset(count, 0, sizeof(struct rte_flow_query_count));
9017 ftype = (enum mlx5_flow_drv_type)(flow->drv_type);
9018 MLX5_ASSERT(ftype > MLX5_FLOW_TYPE_MIN &&
9019 ftype < MLX5_FLOW_TYPE_MAX);
9020 fops = flow_get_drv_ops(ftype);
9021 return fops->query(dev, flow, action, count, error);
9026 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
9028 * Dump flow ipool data to file
9031 * The pointer to Ethernet device.
9033 * A pointer to a file for output.
9035 * Perform verbose error reporting if not NULL. PMDs initialize this
9036 * structure in case of error only.
9038 * 0 on success, a negative value otherwise.
9041 mlx5_flow_dev_dump_ipool(struct rte_eth_dev *dev,
9042 struct rte_flow *flow, FILE *file,
9043 struct rte_flow_error *error)
9045 struct mlx5_priv *priv = dev->data->dev_private;
9046 struct mlx5_flow_dv_modify_hdr_resource *modify_hdr;
9047 struct mlx5_flow_dv_encap_decap_resource *encap_decap;
9048 uint32_t handle_idx;
9049 struct mlx5_flow_handle *dh;
9050 struct rte_flow_query_count count;
9051 uint32_t actions_num;
9052 const uint8_t *data;
9056 void *action = NULL;
9059 return rte_flow_error_set(error, ENOENT,
9060 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9062 "invalid flow handle");
9064 handle_idx = flow->dev_handles;
9066 if (flow->counter &&
9067 (!mlx5_counter_query(dev, flow->counter, false,
9068 &count.hits, &count.bytes, &action)) && action) {
9069 id = (uint64_t)(uintptr_t)action;
9070 type = DR_DUMP_REC_TYPE_PMD_COUNTER;
9071 save_dump_file(NULL, 0, type,
9072 id, (void *)&count, file);
9075 while (handle_idx) {
9076 dh = mlx5_ipool_get(priv->sh->ipool
9077 [MLX5_IPOOL_MLX5_FLOW], handle_idx);
9080 handle_idx = dh->next.next;
9082 /* Get modify_hdr and encap_decap buf from ipools. */
9084 modify_hdr = dh->dvh.modify_hdr;
9086 if (dh->dvh.rix_encap_decap) {
9087 encap_decap = mlx5_ipool_get(priv->sh->ipool
9088 [MLX5_IPOOL_DECAP_ENCAP],
9089 dh->dvh.rix_encap_decap);
9092 data = (const uint8_t *)modify_hdr->actions;
9093 size = (size_t)(modify_hdr->actions_num) * 8;
9094 id = (uint64_t)(uintptr_t)modify_hdr->action;
9095 actions_num = modify_hdr->actions_num;
9096 type = DR_DUMP_REC_TYPE_PMD_MODIFY_HDR;
9097 save_dump_file(data, size, type, id,
9098 (void *)(&actions_num), file);
9101 data = encap_decap->buf;
9102 size = encap_decap->size;
9103 id = (uint64_t)(uintptr_t)encap_decap->action;
9104 type = DR_DUMP_REC_TYPE_PMD_PKT_REFORMAT;
9105 save_dump_file(data, size, type,
9113 * Dump all flow's encap_decap/modify_hdr/counter data to file
9116 * The pointer to Ethernet device.
9118 * A pointer to a file for output.
9120 * Perform verbose error reporting if not NULL. PMDs initialize this
9121 * structure in case of error only.
9123 * 0 on success, a negative value otherwise.
9126 mlx5_flow_dev_dump_sh_all(struct rte_eth_dev *dev,
9127 FILE *file, struct rte_flow_error *error __rte_unused)
9129 struct mlx5_priv *priv = dev->data->dev_private;
9130 struct mlx5_dev_ctx_shared *sh = priv->sh;
9131 struct mlx5_hlist *h;
9132 struct mlx5_flow_dv_modify_hdr_resource *modify_hdr;
9133 struct mlx5_flow_dv_encap_decap_resource *encap_decap;
9134 struct rte_flow_query_count count;
9135 uint32_t actions_num;
9136 const uint8_t *data;
9142 struct mlx5_list_inconst *l_inconst;
9143 struct mlx5_list_entry *e;
9145 struct mlx5_flow_counter_mng *cmng = &priv->sh->cmng;
9149 /* encap_decap hlist is lcore_share, get global core cache. */
9150 i = MLX5_LIST_GLOBAL;
9151 h = sh->encaps_decaps;
9153 for (j = 0; j <= h->mask; j++) {
9154 l_inconst = &h->buckets[j].l;
9155 if (!l_inconst || !l_inconst->cache[i])
9158 e = LIST_FIRST(&l_inconst->cache[i]->h);
9161 (struct mlx5_flow_dv_encap_decap_resource *)e;
9162 data = encap_decap->buf;
9163 size = encap_decap->size;
9164 id = (uint64_t)(uintptr_t)encap_decap->action;
9165 type = DR_DUMP_REC_TYPE_PMD_PKT_REFORMAT;
9166 save_dump_file(data, size, type,
9168 e = LIST_NEXT(e, next);
9173 /* get modify_hdr */
9174 h = sh->modify_cmds;
9176 lcore_index = rte_lcore_index(rte_lcore_id());
9177 if (unlikely(lcore_index == -1)) {
9178 lcore_index = MLX5_LIST_NLCORE;
9179 rte_spinlock_lock(&h->l_const.lcore_lock);
9183 for (j = 0; j <= h->mask; j++) {
9184 l_inconst = &h->buckets[j].l;
9185 if (!l_inconst || !l_inconst->cache[i])
9188 e = LIST_FIRST(&l_inconst->cache[i]->h);
9191 (struct mlx5_flow_dv_modify_hdr_resource *)e;
9192 data = (const uint8_t *)modify_hdr->actions;
9193 size = (size_t)(modify_hdr->actions_num) * 8;
9194 actions_num = modify_hdr->actions_num;
9195 id = (uint64_t)(uintptr_t)modify_hdr->action;
9196 type = DR_DUMP_REC_TYPE_PMD_MODIFY_HDR;
9197 save_dump_file(data, size, type, id,
9198 (void *)(&actions_num), file);
9199 e = LIST_NEXT(e, next);
9203 if (unlikely(lcore_index == MLX5_LIST_NLCORE))
9204 rte_spinlock_unlock(&h->l_const.lcore_lock);
9208 MLX5_ASSERT(cmng->n_valid <= cmng->n);
9209 max = MLX5_COUNTERS_PER_POOL * cmng->n_valid;
9210 for (j = 1; j <= max; j++) {
9212 if ((!mlx5_counter_query(dev, j, false, &count.hits,
9213 &count.bytes, &action)) && action) {
9214 id = (uint64_t)(uintptr_t)action;
9215 type = DR_DUMP_REC_TYPE_PMD_COUNTER;
9216 save_dump_file(NULL, 0, type,
9217 id, (void *)&count, file);
9225 * Dump flow raw hw data to file
9228 * The pointer to Ethernet device.
9230 * A pointer to a file for output.
9232 * Perform verbose error reporting if not NULL. PMDs initialize this
9233 * structure in case of error only.
9235 * 0 on success, a negative value otherwise.
9238 mlx5_flow_dev_dump(struct rte_eth_dev *dev, struct rte_flow *flow_idx,
9240 struct rte_flow_error *error __rte_unused)
9242 struct mlx5_priv *priv = dev->data->dev_private;
9243 struct mlx5_dev_ctx_shared *sh = priv->sh;
9244 uint32_t handle_idx;
9246 struct mlx5_flow_handle *dh;
9247 struct rte_flow *flow;
9249 if (!sh->config.dv_flow_en) {
9250 if (fputs("device dv flow disabled\n", file) <= 0)
9257 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
9258 if (mlx5_flow_dev_dump_sh_all(dev, file, error))
9261 return mlx5_devx_cmd_flow_dump(sh->fdb_domain,
9263 sh->tx_domain, file);
9266 flow = mlx5_ipool_get(priv->flows[MLX5_FLOW_TYPE_GEN],
9267 (uintptr_t)(void *)flow_idx);
9271 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
9272 mlx5_flow_dev_dump_ipool(dev, flow, file, error);
9274 handle_idx = flow->dev_handles;
9275 while (handle_idx) {
9276 dh = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
9281 ret = mlx5_devx_cmd_flow_single_dump(dh->drv_flow,
9286 handle_idx = dh->next.next;
9292 * Get aged-out flows.
9295 * Pointer to the Ethernet device structure.
9296 * @param[in] context
9297 * The address of an array of pointers to the aged-out flows contexts.
9298 * @param[in] nb_countexts
9299 * The length of context array pointers.
9301 * Perform verbose error reporting if not NULL. Initialized in case of
9305 * how many contexts get in success, otherwise negative errno value.
9306 * if nb_contexts is 0, return the amount of all aged contexts.
9307 * if nb_contexts is not 0 , return the amount of aged flows reported
9308 * in the context array.
9311 mlx5_flow_get_aged_flows(struct rte_eth_dev *dev, void **contexts,
9312 uint32_t nb_contexts, struct rte_flow_error *error)
9314 const struct mlx5_flow_driver_ops *fops;
9315 struct rte_flow_attr attr = { .transfer = 0 };
9317 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
9318 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
9319 return fops->get_aged_flows(dev, contexts, nb_contexts,
9323 "port %u get aged flows is not supported.",
9324 dev->data->port_id);
9328 /* Wrapper for driver action_validate op callback */
9330 flow_drv_action_validate(struct rte_eth_dev *dev,
9331 const struct rte_flow_indir_action_conf *conf,
9332 const struct rte_flow_action *action,
9333 const struct mlx5_flow_driver_ops *fops,
9334 struct rte_flow_error *error)
9336 static const char err_msg[] = "indirect action validation unsupported";
9338 if (!fops->action_validate) {
9339 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
9340 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
9344 return fops->action_validate(dev, conf, action, error);
9348 * Destroys the shared action by handle.
9351 * Pointer to Ethernet device structure.
9353 * Handle for the indirect action object to be destroyed.
9355 * Perform verbose error reporting if not NULL. PMDs initialize this
9356 * structure in case of error only.
9359 * 0 on success, a negative errno value otherwise and rte_errno is set.
9361 * @note: wrapper for driver action_create op callback.
9364 mlx5_action_handle_destroy(struct rte_eth_dev *dev,
9365 struct rte_flow_action_handle *handle,
9366 struct rte_flow_error *error)
9368 static const char err_msg[] = "indirect action destruction unsupported";
9369 struct rte_flow_attr attr = { .transfer = 0 };
9370 const struct mlx5_flow_driver_ops *fops =
9371 flow_get_drv_ops(flow_get_drv_type(dev, &attr));
9373 if (!fops->action_destroy) {
9374 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
9375 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
9379 return fops->action_destroy(dev, handle, error);
9382 /* Wrapper for driver action_destroy op callback */
9384 flow_drv_action_update(struct rte_eth_dev *dev,
9385 struct rte_flow_action_handle *handle,
9387 const struct mlx5_flow_driver_ops *fops,
9388 struct rte_flow_error *error)
9390 static const char err_msg[] = "indirect action update unsupported";
9392 if (!fops->action_update) {
9393 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
9394 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
9398 return fops->action_update(dev, handle, update, error);
9401 /* Wrapper for driver action_destroy op callback */
9403 flow_drv_action_query(struct rte_eth_dev *dev,
9404 const struct rte_flow_action_handle *handle,
9406 const struct mlx5_flow_driver_ops *fops,
9407 struct rte_flow_error *error)
9409 static const char err_msg[] = "indirect action query unsupported";
9411 if (!fops->action_query) {
9412 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
9413 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
9417 return fops->action_query(dev, handle, data, error);
9421 * Create indirect action for reuse in multiple flow rules.
9424 * Pointer to Ethernet device structure.
9426 * Pointer to indirect action object configuration.
9428 * Action configuration for indirect action object creation.
9430 * Perform verbose error reporting if not NULL. PMDs initialize this
9431 * structure in case of error only.
9433 * A valid handle in case of success, NULL otherwise and rte_errno is set.
9435 static struct rte_flow_action_handle *
9436 mlx5_action_handle_create(struct rte_eth_dev *dev,
9437 const struct rte_flow_indir_action_conf *conf,
9438 const struct rte_flow_action *action,
9439 struct rte_flow_error *error)
9441 static const char err_msg[] = "indirect action creation unsupported";
9442 struct rte_flow_attr attr = { .transfer = 0 };
9443 const struct mlx5_flow_driver_ops *fops =
9444 flow_get_drv_ops(flow_get_drv_type(dev, &attr));
9446 if (flow_drv_action_validate(dev, conf, action, fops, error))
9448 if (!fops->action_create) {
9449 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
9450 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
9454 return fops->action_create(dev, conf, action, error);
9458 * Updates inplace the indirect action configuration pointed by *handle*
9459 * with the configuration provided as *update* argument.
9460 * The update of the indirect action configuration effects all flow rules
9461 * reusing the action via handle.
9464 * Pointer to Ethernet device structure.
9466 * Handle for the indirect action to be updated.
9468 * Action specification used to modify the action pointed by handle.
9469 * *update* could be of same type with the action pointed by the *handle*
9470 * handle argument, or some other structures like a wrapper, depending on
9471 * the indirect action type.
9473 * Perform verbose error reporting if not NULL. PMDs initialize this
9474 * structure in case of error only.
9477 * 0 on success, a negative errno value otherwise and rte_errno is set.
9480 mlx5_action_handle_update(struct rte_eth_dev *dev,
9481 struct rte_flow_action_handle *handle,
9483 struct rte_flow_error *error)
9485 struct rte_flow_attr attr = { .transfer = 0 };
9486 const struct mlx5_flow_driver_ops *fops =
9487 flow_get_drv_ops(flow_get_drv_type(dev, &attr));
9490 ret = flow_drv_action_validate(dev, NULL,
9491 (const struct rte_flow_action *)update, fops, error);
9494 return flow_drv_action_update(dev, handle, update, fops,
9499 * Query the indirect action by handle.
9501 * This function allows retrieving action-specific data such as counters.
9502 * Data is gathered by special action which may be present/referenced in
9503 * more than one flow rule definition.
9505 * see @RTE_FLOW_ACTION_TYPE_COUNT
9508 * Pointer to Ethernet device structure.
9510 * Handle for the indirect action to query.
9511 * @param[in, out] data
9512 * Pointer to storage for the associated query data type.
9514 * Perform verbose error reporting if not NULL. PMDs initialize this
9515 * structure in case of error only.
9518 * 0 on success, a negative errno value otherwise and rte_errno is set.
9521 mlx5_action_handle_query(struct rte_eth_dev *dev,
9522 const struct rte_flow_action_handle *handle,
9524 struct rte_flow_error *error)
9526 struct rte_flow_attr attr = { .transfer = 0 };
9527 const struct mlx5_flow_driver_ops *fops =
9528 flow_get_drv_ops(flow_get_drv_type(dev, &attr));
9530 return flow_drv_action_query(dev, handle, data, fops, error);
9534 * Destroy all indirect actions (shared RSS).
9537 * Pointer to Ethernet device.
9540 * 0 on success, a negative errno value otherwise and rte_errno is set.
9543 mlx5_action_handle_flush(struct rte_eth_dev *dev)
9545 struct rte_flow_error error;
9546 struct mlx5_priv *priv = dev->data->dev_private;
9547 struct mlx5_shared_action_rss *shared_rss;
9551 ILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
9552 priv->rss_shared_actions, idx, shared_rss, next) {
9553 ret |= mlx5_action_handle_destroy(dev,
9554 (struct rte_flow_action_handle *)(uintptr_t)idx, &error);
9560 * Validate existing indirect actions against current device configuration
9561 * and attach them to device resources.
9564 * Pointer to Ethernet device.
9567 * 0 on success, a negative errno value otherwise and rte_errno is set.
9570 mlx5_action_handle_attach(struct rte_eth_dev *dev)
9572 struct mlx5_priv *priv = dev->data->dev_private;
9574 struct mlx5_ind_table_obj *ind_tbl, *ind_tbl_last;
9576 LIST_FOREACH(ind_tbl, &priv->standalone_ind_tbls, next) {
9577 const char *message;
9580 ret = mlx5_validate_rss_queues(dev, ind_tbl->queues,
9582 &message, &queue_idx);
9584 DRV_LOG(ERR, "Port %u cannot use queue %u in RSS: %s",
9585 dev->data->port_id, ind_tbl->queues[queue_idx],
9592 LIST_FOREACH(ind_tbl, &priv->standalone_ind_tbls, next) {
9593 ret = mlx5_ind_table_obj_attach(dev, ind_tbl);
9595 DRV_LOG(ERR, "Port %u could not attach "
9596 "indirection table obj %p",
9597 dev->data->port_id, (void *)ind_tbl);
9604 ind_tbl_last = ind_tbl;
9605 LIST_FOREACH(ind_tbl, &priv->standalone_ind_tbls, next) {
9606 if (ind_tbl == ind_tbl_last)
9608 if (mlx5_ind_table_obj_detach(dev, ind_tbl) != 0)
9609 DRV_LOG(CRIT, "Port %u could not detach "
9610 "indirection table obj %p on rollback",
9611 dev->data->port_id, (void *)ind_tbl);
9617 * Detach indirect actions of the device from its resources.
9620 * Pointer to Ethernet device.
9623 * 0 on success, a negative errno value otherwise and rte_errno is set.
9626 mlx5_action_handle_detach(struct rte_eth_dev *dev)
9628 struct mlx5_priv *priv = dev->data->dev_private;
9630 struct mlx5_ind_table_obj *ind_tbl, *ind_tbl_last;
9632 LIST_FOREACH(ind_tbl, &priv->standalone_ind_tbls, next) {
9633 ret = mlx5_ind_table_obj_detach(dev, ind_tbl);
9635 DRV_LOG(ERR, "Port %u could not detach "
9636 "indirection table obj %p",
9637 dev->data->port_id, (void *)ind_tbl);
9643 ind_tbl_last = ind_tbl;
9644 LIST_FOREACH(ind_tbl, &priv->standalone_ind_tbls, next) {
9645 if (ind_tbl == ind_tbl_last)
9647 if (mlx5_ind_table_obj_attach(dev, ind_tbl) != 0)
9648 DRV_LOG(CRIT, "Port %u could not attach "
9649 "indirection table obj %p on rollback",
9650 dev->data->port_id, (void *)ind_tbl);
9655 #ifndef HAVE_MLX5DV_DR
9656 #define MLX5_DOMAIN_SYNC_FLOW ((1 << 0) | (1 << 1))
9658 #define MLX5_DOMAIN_SYNC_FLOW \
9659 (MLX5DV_DR_DOMAIN_SYNC_FLAGS_SW | MLX5DV_DR_DOMAIN_SYNC_FLAGS_HW)
9662 int rte_pmd_mlx5_sync_flow(uint16_t port_id, uint32_t domains)
9664 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
9665 const struct mlx5_flow_driver_ops *fops;
9667 struct rte_flow_attr attr = { .transfer = 0 };
9669 fops = flow_get_drv_ops(flow_get_drv_type(dev, &attr));
9670 ret = fops->sync_domain(dev, domains, MLX5_DOMAIN_SYNC_FLOW);
9676 const struct mlx5_flow_tunnel *
9677 mlx5_get_tof(const struct rte_flow_item *item,
9678 const struct rte_flow_action *action,
9679 enum mlx5_tof_rule_type *rule_type)
9681 for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
9682 if (item->type == (typeof(item->type))
9683 MLX5_RTE_FLOW_ITEM_TYPE_TUNNEL) {
9684 *rule_type = MLX5_TUNNEL_OFFLOAD_MATCH_RULE;
9685 return flow_items_to_tunnel(item);
9688 for (; action->conf != RTE_FLOW_ACTION_TYPE_END; action++) {
9689 if (action->type == (typeof(action->type))
9690 MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET) {
9691 *rule_type = MLX5_TUNNEL_OFFLOAD_SET_RULE;
9692 return flow_actions_to_tunnel(action);
9699 * tunnel offload functionality is defined for DV environment only
9701 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
9703 union tunnel_offload_mark {
9706 uint32_t app_reserve:8;
9707 uint32_t table_id:15;
9708 uint32_t transfer:1;
9709 uint32_t _unused_:8;
9714 mlx5_access_tunnel_offload_db
9715 (struct rte_eth_dev *dev,
9716 bool (*match)(struct rte_eth_dev *,
9717 struct mlx5_flow_tunnel *, const void *),
9718 void (*hit)(struct rte_eth_dev *, struct mlx5_flow_tunnel *, void *),
9719 void (*miss)(struct rte_eth_dev *, void *),
9720 void *ctx, bool lock_op);
9723 flow_tunnel_add_default_miss(struct rte_eth_dev *dev,
9724 struct rte_flow *flow,
9725 const struct rte_flow_attr *attr,
9726 const struct rte_flow_action *app_actions,
9728 const struct mlx5_flow_tunnel *tunnel,
9729 struct tunnel_default_miss_ctx *ctx,
9730 struct rte_flow_error *error)
9732 struct mlx5_priv *priv = dev->data->dev_private;
9733 struct mlx5_flow *dev_flow;
9734 struct rte_flow_attr miss_attr = *attr;
9735 const struct rte_flow_item miss_items[2] = {
9737 .type = RTE_FLOW_ITEM_TYPE_ETH,
9743 .type = RTE_FLOW_ITEM_TYPE_END,
9749 union tunnel_offload_mark mark_id;
9750 struct rte_flow_action_mark miss_mark;
9751 struct rte_flow_action miss_actions[3] = {
9752 [0] = { .type = RTE_FLOW_ACTION_TYPE_MARK, .conf = &miss_mark },
9753 [2] = { .type = RTE_FLOW_ACTION_TYPE_END, .conf = NULL }
9755 const struct rte_flow_action_jump *jump_data;
9756 uint32_t i, flow_table = 0; /* prevent compilation warning */
9757 struct flow_grp_info grp_info = {
9759 .transfer = attr->transfer,
9760 .fdb_def_rule = !!priv->fdb_def_rule,
9765 if (!attr->transfer) {
9768 miss_actions[1].type = RTE_FLOW_ACTION_TYPE_RSS;
9769 q_size = priv->reta_idx_n * sizeof(ctx->queue[0]);
9770 ctx->queue = mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO, q_size,
9773 return rte_flow_error_set
9775 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
9776 NULL, "invalid default miss RSS");
9777 ctx->action_rss.func = RTE_ETH_HASH_FUNCTION_DEFAULT,
9778 ctx->action_rss.level = 0,
9779 ctx->action_rss.types = priv->rss_conf.rss_hf,
9780 ctx->action_rss.key_len = priv->rss_conf.rss_key_len,
9781 ctx->action_rss.queue_num = priv->reta_idx_n,
9782 ctx->action_rss.key = priv->rss_conf.rss_key,
9783 ctx->action_rss.queue = ctx->queue;
9784 if (!priv->reta_idx_n || !priv->rxqs_n)
9785 return rte_flow_error_set
9787 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
9788 NULL, "invalid port configuration");
9789 if (!(dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_RSS_FLAG))
9790 ctx->action_rss.types = 0;
9791 for (i = 0; i != priv->reta_idx_n; ++i)
9792 ctx->queue[i] = (*priv->reta_idx)[i];
9794 miss_actions[1].type = RTE_FLOW_ACTION_TYPE_JUMP;
9795 ctx->miss_jump.group = MLX5_TNL_MISS_FDB_JUMP_GRP;
9797 miss_actions[1].conf = (typeof(miss_actions[1].conf))ctx->raw;
9798 for (; app_actions->type != RTE_FLOW_ACTION_TYPE_JUMP; app_actions++);
9799 jump_data = app_actions->conf;
9800 miss_attr.priority = MLX5_TNL_MISS_RULE_PRIORITY;
9801 miss_attr.group = jump_data->group;
9802 ret = mlx5_flow_group_to_table(dev, tunnel, jump_data->group,
9803 &flow_table, &grp_info, error);
9805 return rte_flow_error_set(error, EINVAL,
9806 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
9807 NULL, "invalid tunnel id");
9808 mark_id.app_reserve = 0;
9809 mark_id.table_id = tunnel_flow_tbl_to_id(flow_table);
9810 mark_id.transfer = !!attr->transfer;
9811 mark_id._unused_ = 0;
9812 miss_mark.id = mark_id.val;
9813 dev_flow = flow_drv_prepare(dev, flow, &miss_attr,
9814 miss_items, miss_actions, flow_idx, error);
9817 dev_flow->flow = flow;
9818 dev_flow->external = true;
9819 dev_flow->tunnel = tunnel;
9820 dev_flow->tof_type = MLX5_TUNNEL_OFFLOAD_MISS_RULE;
9821 /* Subflow object was created, we must include one in the list. */
9822 SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
9823 dev_flow->handle, next);
9825 "port %u tunnel type=%d id=%u miss rule priority=%u group=%u",
9826 dev->data->port_id, tunnel->app_tunnel.type,
9827 tunnel->tunnel_id, miss_attr.priority, miss_attr.group);
9828 ret = flow_drv_translate(dev, dev_flow, &miss_attr, miss_items,
9829 miss_actions, error);
9831 ret = flow_mreg_update_copy_table(dev, flow, miss_actions,
9837 static const struct mlx5_flow_tbl_data_entry *
9838 tunnel_mark_decode(struct rte_eth_dev *dev, uint32_t mark)
9840 struct mlx5_priv *priv = dev->data->dev_private;
9841 struct mlx5_dev_ctx_shared *sh = priv->sh;
9842 struct mlx5_list_entry *he;
9843 union tunnel_offload_mark mbits = { .val = mark };
9844 union mlx5_flow_tbl_key table_key = {
9846 .level = tunnel_id_to_flow_tbl(mbits.table_id),
9850 .is_fdb = !!mbits.transfer,
9854 struct mlx5_flow_cb_ctx ctx = {
9855 .data = &table_key.v64,
9858 he = mlx5_hlist_lookup(sh->flow_tbls, table_key.v64, &ctx);
9860 container_of(he, struct mlx5_flow_tbl_data_entry, entry) : NULL;
9864 mlx5_flow_tunnel_grp2tbl_remove_cb(void *tool_ctx,
9865 struct mlx5_list_entry *entry)
9867 struct mlx5_dev_ctx_shared *sh = tool_ctx;
9868 struct tunnel_tbl_entry *tte = container_of(entry, typeof(*tte), hash);
9870 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TNL_TBL_ID],
9871 tunnel_flow_tbl_to_id(tte->flow_table));
9876 mlx5_flow_tunnel_grp2tbl_match_cb(void *tool_ctx __rte_unused,
9877 struct mlx5_list_entry *entry, void *cb_ctx)
9879 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
9880 union tunnel_tbl_key tbl = {
9881 .val = *(uint64_t *)(ctx->data),
9883 struct tunnel_tbl_entry *tte = container_of(entry, typeof(*tte), hash);
9885 return tbl.tunnel_id != tte->tunnel_id || tbl.group != tte->group;
9888 static struct mlx5_list_entry *
9889 mlx5_flow_tunnel_grp2tbl_create_cb(void *tool_ctx, void *cb_ctx)
9891 struct mlx5_dev_ctx_shared *sh = tool_ctx;
9892 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
9893 struct tunnel_tbl_entry *tte;
9894 union tunnel_tbl_key tbl = {
9895 .val = *(uint64_t *)(ctx->data),
9898 tte = mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO,
9903 mlx5_ipool_malloc(sh->ipool[MLX5_IPOOL_TNL_TBL_ID],
9905 if (tte->flow_table >= MLX5_MAX_TABLES) {
9906 DRV_LOG(ERR, "Tunnel TBL ID %d exceed max limit.",
9908 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TNL_TBL_ID],
9911 } else if (!tte->flow_table) {
9914 tte->flow_table = tunnel_id_to_flow_tbl(tte->flow_table);
9915 tte->tunnel_id = tbl.tunnel_id;
9916 tte->group = tbl.group;
9924 static struct mlx5_list_entry *
9925 mlx5_flow_tunnel_grp2tbl_clone_cb(void *tool_ctx __rte_unused,
9926 struct mlx5_list_entry *oentry,
9927 void *cb_ctx __rte_unused)
9929 struct tunnel_tbl_entry *tte = mlx5_malloc(MLX5_MEM_SYS, sizeof(*tte),
9934 memcpy(tte, oentry, sizeof(*tte));
9939 mlx5_flow_tunnel_grp2tbl_clone_free_cb(void *tool_ctx __rte_unused,
9940 struct mlx5_list_entry *entry)
9942 struct tunnel_tbl_entry *tte = container_of(entry, typeof(*tte), hash);
9948 tunnel_flow_group_to_flow_table(struct rte_eth_dev *dev,
9949 const struct mlx5_flow_tunnel *tunnel,
9950 uint32_t group, uint32_t *table,
9951 struct rte_flow_error *error)
9953 struct mlx5_list_entry *he;
9954 struct tunnel_tbl_entry *tte;
9955 union tunnel_tbl_key key = {
9956 .tunnel_id = tunnel ? tunnel->tunnel_id : 0,
9959 struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
9960 struct mlx5_hlist *group_hash;
9961 struct mlx5_flow_cb_ctx ctx = {
9965 group_hash = tunnel ? tunnel->groups : thub->groups;
9966 he = mlx5_hlist_register(group_hash, key.val, &ctx);
9968 return rte_flow_error_set(error, EINVAL,
9969 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
9971 "tunnel group index not supported");
9972 tte = container_of(he, typeof(*tte), hash);
9973 *table = tte->flow_table;
9974 DRV_LOG(DEBUG, "port %u tunnel %u group=%#x table=%#x",
9975 dev->data->port_id, key.tunnel_id, group, *table);
9980 mlx5_flow_tunnel_free(struct rte_eth_dev *dev,
9981 struct mlx5_flow_tunnel *tunnel)
9983 struct mlx5_priv *priv = dev->data->dev_private;
9984 struct mlx5_indexed_pool *ipool;
9986 DRV_LOG(DEBUG, "port %u release pmd tunnel id=0x%x",
9987 dev->data->port_id, tunnel->tunnel_id);
9988 LIST_REMOVE(tunnel, chain);
9989 mlx5_hlist_destroy(tunnel->groups);
9990 ipool = priv->sh->ipool[MLX5_IPOOL_TUNNEL_ID];
9991 mlx5_ipool_free(ipool, tunnel->tunnel_id);
9995 mlx5_access_tunnel_offload_db
9996 (struct rte_eth_dev *dev,
9997 bool (*match)(struct rte_eth_dev *,
9998 struct mlx5_flow_tunnel *, const void *),
9999 void (*hit)(struct rte_eth_dev *, struct mlx5_flow_tunnel *, void *),
10000 void (*miss)(struct rte_eth_dev *, void *),
10001 void *ctx, bool lock_op)
10003 bool verdict = false;
10004 struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
10005 struct mlx5_flow_tunnel *tunnel;
10007 rte_spinlock_lock(&thub->sl);
10008 LIST_FOREACH(tunnel, &thub->tunnels, chain) {
10009 verdict = match(dev, tunnel, (const void *)ctx);
10014 rte_spinlock_unlock(&thub->sl);
10015 if (verdict && hit)
10016 hit(dev, tunnel, ctx);
10017 if (!verdict && miss)
10020 rte_spinlock_unlock(&thub->sl);
10025 struct tunnel_db_find_tunnel_id_ctx {
10026 uint32_t tunnel_id;
10027 struct mlx5_flow_tunnel *tunnel;
10031 find_tunnel_id_match(struct rte_eth_dev *dev,
10032 struct mlx5_flow_tunnel *tunnel, const void *x)
10034 const struct tunnel_db_find_tunnel_id_ctx *ctx = x;
10037 return tunnel->tunnel_id == ctx->tunnel_id;
10041 find_tunnel_id_hit(struct rte_eth_dev *dev,
10042 struct mlx5_flow_tunnel *tunnel, void *x)
10044 struct tunnel_db_find_tunnel_id_ctx *ctx = x;
10046 ctx->tunnel = tunnel;
10049 static struct mlx5_flow_tunnel *
10050 mlx5_find_tunnel_id(struct rte_eth_dev *dev, uint32_t id)
10052 struct tunnel_db_find_tunnel_id_ctx ctx = {
10056 mlx5_access_tunnel_offload_db(dev, find_tunnel_id_match,
10057 find_tunnel_id_hit, NULL, &ctx, true);
10062 static struct mlx5_flow_tunnel *
10063 mlx5_flow_tunnel_allocate(struct rte_eth_dev *dev,
10064 const struct rte_flow_tunnel *app_tunnel)
10066 struct mlx5_priv *priv = dev->data->dev_private;
10067 struct mlx5_indexed_pool *ipool;
10068 struct mlx5_flow_tunnel *tunnel;
10071 ipool = priv->sh->ipool[MLX5_IPOOL_TUNNEL_ID];
10072 tunnel = mlx5_ipool_zmalloc(ipool, &id);
10075 if (id >= MLX5_MAX_TUNNELS) {
10076 mlx5_ipool_free(ipool, id);
10077 DRV_LOG(ERR, "Tunnel ID %d exceed max limit.", id);
10080 tunnel->groups = mlx5_hlist_create("tunnel groups", 64, false, true,
10082 mlx5_flow_tunnel_grp2tbl_create_cb,
10083 mlx5_flow_tunnel_grp2tbl_match_cb,
10084 mlx5_flow_tunnel_grp2tbl_remove_cb,
10085 mlx5_flow_tunnel_grp2tbl_clone_cb,
10086 mlx5_flow_tunnel_grp2tbl_clone_free_cb);
10087 if (!tunnel->groups) {
10088 mlx5_ipool_free(ipool, id);
10091 /* initiate new PMD tunnel */
10092 memcpy(&tunnel->app_tunnel, app_tunnel, sizeof(*app_tunnel));
10093 tunnel->tunnel_id = id;
10094 tunnel->action.type = (typeof(tunnel->action.type))
10095 MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET;
10096 tunnel->action.conf = tunnel;
10097 tunnel->item.type = (typeof(tunnel->item.type))
10098 MLX5_RTE_FLOW_ITEM_TYPE_TUNNEL;
10099 tunnel->item.spec = tunnel;
10100 tunnel->item.last = NULL;
10101 tunnel->item.mask = NULL;
10103 DRV_LOG(DEBUG, "port %u new pmd tunnel id=0x%x",
10104 dev->data->port_id, tunnel->tunnel_id);
10109 struct tunnel_db_get_tunnel_ctx {
10110 const struct rte_flow_tunnel *app_tunnel;
10111 struct mlx5_flow_tunnel *tunnel;
10114 static bool get_tunnel_match(struct rte_eth_dev *dev,
10115 struct mlx5_flow_tunnel *tunnel, const void *x)
10117 const struct tunnel_db_get_tunnel_ctx *ctx = x;
10120 return !memcmp(ctx->app_tunnel, &tunnel->app_tunnel,
10121 sizeof(*ctx->app_tunnel));
10124 static void get_tunnel_hit(struct rte_eth_dev *dev,
10125 struct mlx5_flow_tunnel *tunnel, void *x)
10127 /* called under tunnel spinlock protection */
10128 struct tunnel_db_get_tunnel_ctx *ctx = x;
10132 ctx->tunnel = tunnel;
10135 static void get_tunnel_miss(struct rte_eth_dev *dev, void *x)
10137 /* called under tunnel spinlock protection */
10138 struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
10139 struct tunnel_db_get_tunnel_ctx *ctx = x;
10141 rte_spinlock_unlock(&thub->sl);
10142 ctx->tunnel = mlx5_flow_tunnel_allocate(dev, ctx->app_tunnel);
10143 rte_spinlock_lock(&thub->sl);
10145 ctx->tunnel->refctn = 1;
10146 LIST_INSERT_HEAD(&thub->tunnels, ctx->tunnel, chain);
10152 mlx5_get_flow_tunnel(struct rte_eth_dev *dev,
10153 const struct rte_flow_tunnel *app_tunnel,
10154 struct mlx5_flow_tunnel **tunnel)
10156 struct tunnel_db_get_tunnel_ctx ctx = {
10157 .app_tunnel = app_tunnel,
10160 mlx5_access_tunnel_offload_db(dev, get_tunnel_match, get_tunnel_hit,
10161 get_tunnel_miss, &ctx, true);
10162 *tunnel = ctx.tunnel;
10163 return ctx.tunnel ? 0 : -ENOMEM;
10166 void mlx5_release_tunnel_hub(struct mlx5_dev_ctx_shared *sh, uint16_t port_id)
10168 struct mlx5_flow_tunnel_hub *thub = sh->tunnel_hub;
10172 if (!LIST_EMPTY(&thub->tunnels))
10173 DRV_LOG(WARNING, "port %u tunnels present", port_id);
10174 mlx5_hlist_destroy(thub->groups);
10178 int mlx5_alloc_tunnel_hub(struct mlx5_dev_ctx_shared *sh)
10181 struct mlx5_flow_tunnel_hub *thub;
10183 thub = mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO, sizeof(*thub),
10187 LIST_INIT(&thub->tunnels);
10188 rte_spinlock_init(&thub->sl);
10189 thub->groups = mlx5_hlist_create("flow groups", 64,
10191 mlx5_flow_tunnel_grp2tbl_create_cb,
10192 mlx5_flow_tunnel_grp2tbl_match_cb,
10193 mlx5_flow_tunnel_grp2tbl_remove_cb,
10194 mlx5_flow_tunnel_grp2tbl_clone_cb,
10195 mlx5_flow_tunnel_grp2tbl_clone_free_cb);
10196 if (!thub->groups) {
10200 sh->tunnel_hub = thub;
10206 mlx5_hlist_destroy(thub->groups);
10213 mlx5_flow_tunnel_validate(struct rte_eth_dev *dev,
10214 struct rte_flow_tunnel *tunnel,
10215 struct rte_flow_error *error)
10217 struct mlx5_priv *priv = dev->data->dev_private;
10219 if (!priv->sh->config.dv_flow_en)
10220 return rte_flow_error_set(error, ENOTSUP,
10221 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
10222 "flow DV interface is off");
10223 if (!is_tunnel_offload_active(dev))
10224 return rte_flow_error_set(error, ENOTSUP,
10225 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
10226 "tunnel offload was not activated");
10228 return rte_flow_error_set(error, EINVAL,
10229 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
10230 "no application tunnel");
10231 switch (tunnel->type) {
10233 return rte_flow_error_set(error, EINVAL,
10234 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
10235 "unsupported tunnel type");
10236 case RTE_FLOW_ITEM_TYPE_VXLAN:
10237 case RTE_FLOW_ITEM_TYPE_GRE:
10238 case RTE_FLOW_ITEM_TYPE_NVGRE:
10239 case RTE_FLOW_ITEM_TYPE_GENEVE:
10246 mlx5_flow_tunnel_decap_set(struct rte_eth_dev *dev,
10247 struct rte_flow_tunnel *app_tunnel,
10248 struct rte_flow_action **actions,
10249 uint32_t *num_of_actions,
10250 struct rte_flow_error *error)
10252 struct mlx5_flow_tunnel *tunnel;
10253 int ret = mlx5_flow_tunnel_validate(dev, app_tunnel, error);
10257 ret = mlx5_get_flow_tunnel(dev, app_tunnel, &tunnel);
10259 return rte_flow_error_set(error, ret,
10260 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
10261 "failed to initialize pmd tunnel");
10263 *actions = &tunnel->action;
10264 *num_of_actions = 1;
10269 mlx5_flow_tunnel_match(struct rte_eth_dev *dev,
10270 struct rte_flow_tunnel *app_tunnel,
10271 struct rte_flow_item **items,
10272 uint32_t *num_of_items,
10273 struct rte_flow_error *error)
10275 struct mlx5_flow_tunnel *tunnel;
10276 int ret = mlx5_flow_tunnel_validate(dev, app_tunnel, error);
10280 ret = mlx5_get_flow_tunnel(dev, app_tunnel, &tunnel);
10282 return rte_flow_error_set(error, ret,
10283 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
10284 "failed to initialize pmd tunnel");
10286 *items = &tunnel->item;
10291 struct tunnel_db_element_release_ctx {
10292 struct rte_flow_item *items;
10293 struct rte_flow_action *actions;
10294 uint32_t num_elements;
10295 struct rte_flow_error *error;
10300 tunnel_element_release_match(struct rte_eth_dev *dev,
10301 struct mlx5_flow_tunnel *tunnel, const void *x)
10303 const struct tunnel_db_element_release_ctx *ctx = x;
10306 if (ctx->num_elements != 1)
10308 else if (ctx->items)
10309 return ctx->items == &tunnel->item;
10310 else if (ctx->actions)
10311 return ctx->actions == &tunnel->action;
10317 tunnel_element_release_hit(struct rte_eth_dev *dev,
10318 struct mlx5_flow_tunnel *tunnel, void *x)
10320 struct tunnel_db_element_release_ctx *ctx = x;
10322 if (!__atomic_sub_fetch(&tunnel->refctn, 1, __ATOMIC_RELAXED))
10323 mlx5_flow_tunnel_free(dev, tunnel);
10327 tunnel_element_release_miss(struct rte_eth_dev *dev, void *x)
10329 struct tunnel_db_element_release_ctx *ctx = x;
10331 ctx->ret = rte_flow_error_set(ctx->error, EINVAL,
10332 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
10333 "invalid argument");
10337 mlx5_flow_tunnel_item_release(struct rte_eth_dev *dev,
10338 struct rte_flow_item *pmd_items,
10339 uint32_t num_items, struct rte_flow_error *err)
10341 struct tunnel_db_element_release_ctx ctx = {
10342 .items = pmd_items,
10344 .num_elements = num_items,
10348 mlx5_access_tunnel_offload_db(dev, tunnel_element_release_match,
10349 tunnel_element_release_hit,
10350 tunnel_element_release_miss, &ctx, false);
10356 mlx5_flow_tunnel_action_release(struct rte_eth_dev *dev,
10357 struct rte_flow_action *pmd_actions,
10358 uint32_t num_actions, struct rte_flow_error *err)
10360 struct tunnel_db_element_release_ctx ctx = {
10362 .actions = pmd_actions,
10363 .num_elements = num_actions,
10367 mlx5_access_tunnel_offload_db(dev, tunnel_element_release_match,
10368 tunnel_element_release_hit,
10369 tunnel_element_release_miss, &ctx, false);
10375 mlx5_flow_tunnel_get_restore_info(struct rte_eth_dev *dev,
10376 struct rte_mbuf *m,
10377 struct rte_flow_restore_info *info,
10378 struct rte_flow_error *err)
10380 uint64_t ol_flags = m->ol_flags;
10381 const struct mlx5_flow_tbl_data_entry *tble;
10382 const uint64_t mask = RTE_MBUF_F_RX_FDIR | RTE_MBUF_F_RX_FDIR_ID;
10384 if (!is_tunnel_offload_active(dev)) {
10389 if ((ol_flags & mask) != mask)
10391 tble = tunnel_mark_decode(dev, m->hash.fdir.hi);
10393 DRV_LOG(DEBUG, "port %u invalid miss tunnel mark %#x",
10394 dev->data->port_id, m->hash.fdir.hi);
10397 MLX5_ASSERT(tble->tunnel);
10398 memcpy(&info->tunnel, &tble->tunnel->app_tunnel, sizeof(info->tunnel));
10399 info->group_id = tble->group_id;
10400 info->flags = RTE_FLOW_RESTORE_INFO_TUNNEL |
10401 RTE_FLOW_RESTORE_INFO_GROUP_ID |
10402 RTE_FLOW_RESTORE_INFO_ENCAPSULATED;
10407 return rte_flow_error_set(err, EINVAL,
10408 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10409 "failed to get restore info");
10412 #else /* HAVE_IBV_FLOW_DV_SUPPORT */
10414 mlx5_flow_tunnel_decap_set(__rte_unused struct rte_eth_dev *dev,
10415 __rte_unused struct rte_flow_tunnel *app_tunnel,
10416 __rte_unused struct rte_flow_action **actions,
10417 __rte_unused uint32_t *num_of_actions,
10418 __rte_unused struct rte_flow_error *error)
10424 mlx5_flow_tunnel_match(__rte_unused struct rte_eth_dev *dev,
10425 __rte_unused struct rte_flow_tunnel *app_tunnel,
10426 __rte_unused struct rte_flow_item **items,
10427 __rte_unused uint32_t *num_of_items,
10428 __rte_unused struct rte_flow_error *error)
10434 mlx5_flow_tunnel_item_release(__rte_unused struct rte_eth_dev *dev,
10435 __rte_unused struct rte_flow_item *pmd_items,
10436 __rte_unused uint32_t num_items,
10437 __rte_unused struct rte_flow_error *err)
10443 mlx5_flow_tunnel_action_release(__rte_unused struct rte_eth_dev *dev,
10444 __rte_unused struct rte_flow_action *pmd_action,
10445 __rte_unused uint32_t num_actions,
10446 __rte_unused struct rte_flow_error *err)
10452 mlx5_flow_tunnel_get_restore_info(__rte_unused struct rte_eth_dev *dev,
10453 __rte_unused struct rte_mbuf *m,
10454 __rte_unused struct rte_flow_restore_info *i,
10455 __rte_unused struct rte_flow_error *err)
10461 flow_tunnel_add_default_miss(__rte_unused struct rte_eth_dev *dev,
10462 __rte_unused struct rte_flow *flow,
10463 __rte_unused const struct rte_flow_attr *attr,
10464 __rte_unused const struct rte_flow_action *actions,
10465 __rte_unused uint32_t flow_idx,
10466 __rte_unused const struct mlx5_flow_tunnel *tunnel,
10467 __rte_unused struct tunnel_default_miss_ctx *ctx,
10468 __rte_unused struct rte_flow_error *error)
10473 static struct mlx5_flow_tunnel *
10474 mlx5_find_tunnel_id(__rte_unused struct rte_eth_dev *dev,
10475 __rte_unused uint32_t id)
10481 mlx5_flow_tunnel_free(__rte_unused struct rte_eth_dev *dev,
10482 __rte_unused struct mlx5_flow_tunnel *tunnel)
10487 tunnel_flow_group_to_flow_table(__rte_unused struct rte_eth_dev *dev,
10488 __rte_unused const struct mlx5_flow_tunnel *t,
10489 __rte_unused uint32_t group,
10490 __rte_unused uint32_t *table,
10491 struct rte_flow_error *error)
10493 return rte_flow_error_set(error, ENOTSUP,
10494 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10495 "tunnel offload requires DV support");
10499 mlx5_release_tunnel_hub(__rte_unused struct mlx5_dev_ctx_shared *sh,
10500 __rte_unused uint16_t port_id)
10503 #endif /* HAVE_IBV_FLOW_DV_SUPPORT */
10505 /* Flex flow item API */
10506 static struct rte_flow_item_flex_handle *
10507 mlx5_flow_flex_item_create(struct rte_eth_dev *dev,
10508 const struct rte_flow_item_flex_conf *conf,
10509 struct rte_flow_error *error)
10511 static const char err_msg[] = "flex item creation unsupported";
10512 struct rte_flow_attr attr = { .transfer = 0 };
10513 const struct mlx5_flow_driver_ops *fops =
10514 flow_get_drv_ops(flow_get_drv_type(dev, &attr));
10516 if (!fops->item_create) {
10517 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
10518 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
10522 return fops->item_create(dev, conf, error);
10526 mlx5_flow_flex_item_release(struct rte_eth_dev *dev,
10527 const struct rte_flow_item_flex_handle *handle,
10528 struct rte_flow_error *error)
10530 static const char err_msg[] = "flex item release unsupported";
10531 struct rte_flow_attr attr = { .transfer = 0 };
10532 const struct mlx5_flow_driver_ops *fops =
10533 flow_get_drv_ops(flow_get_drv_type(dev, &attr));
10535 if (!fops->item_release) {
10536 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
10537 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
10541 return fops->item_release(dev, handle, error);
10545 mlx5_dbg__print_pattern(const struct rte_flow_item *item)
10548 struct rte_flow_error error;
10550 for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
10552 ret = rte_flow_conv(RTE_FLOW_CONV_OP_ITEM_NAME_PTR, &item_name,
10554 (void *)(uintptr_t)item->type, &error);
10556 printf("%s ", item_name);
10558 printf("%d\n", (int)item->type);
10564 mlx5_flow_is_std_vxlan_port(const struct rte_flow_item *udp_item)
10566 const struct rte_flow_item_udp *spec = udp_item->spec;
10567 const struct rte_flow_item_udp *mask = udp_item->mask;
10568 uint16_t udp_dport = 0;
10570 if (spec != NULL) {
10572 mask = &rte_flow_item_udp_mask;
10573 udp_dport = rte_be_to_cpu_16(spec->hdr.dst_port &
10574 mask->hdr.dst_port);
10576 return (!udp_dport || udp_dport == MLX5_UDP_PORT_VXLAN);
10579 static const struct mlx5_flow_expand_node *
10580 mlx5_flow_expand_rss_adjust_node(const struct rte_flow_item *pattern,
10581 unsigned int item_idx,
10582 const struct mlx5_flow_expand_node graph[],
10583 const struct mlx5_flow_expand_node *node)
10585 const struct rte_flow_item *item = pattern + item_idx, *prev_item;
10587 if (item->type == RTE_FLOW_ITEM_TYPE_VXLAN &&
10589 node->type == RTE_FLOW_ITEM_TYPE_VXLAN) {
10591 * The expansion node is VXLAN and it is also the last
10592 * expandable item in the pattern, so need to continue
10593 * expansion of the inner tunnel.
10595 MLX5_ASSERT(item_idx > 0);
10596 prev_item = pattern + item_idx - 1;
10597 MLX5_ASSERT(prev_item->type == RTE_FLOW_ITEM_TYPE_UDP);
10598 if (mlx5_flow_is_std_vxlan_port(prev_item))
10599 return &graph[MLX5_EXPANSION_STD_VXLAN];
10600 return &graph[MLX5_EXPANSION_L3_VXLAN];
10605 /* Map of Verbs to Flow priority with 8 Verbs priorities. */
10606 static const uint32_t priority_map_3[][MLX5_PRIORITY_MAP_MAX] = {
10607 { 0, 1, 2 }, { 2, 3, 4 }, { 5, 6, 7 },
10610 /* Map of Verbs to Flow priority with 16 Verbs priorities. */
10611 static const uint32_t priority_map_5[][MLX5_PRIORITY_MAP_MAX] = {
10612 { 0, 1, 2 }, { 3, 4, 5 }, { 6, 7, 8 },
10613 { 9, 10, 11 }, { 12, 13, 14 },
10617 * Discover the number of available flow priorities.
10623 * On success, number of available flow priorities.
10624 * On failure, a negative errno-style code and rte_errno is set.
10627 mlx5_flow_discover_priorities(struct rte_eth_dev *dev)
10629 static const uint16_t vprio[] = {8, 16};
10630 const struct mlx5_priv *priv = dev->data->dev_private;
10631 const struct mlx5_flow_driver_ops *fops;
10632 enum mlx5_flow_drv_type type;
10635 type = mlx5_flow_os_get_type();
10636 if (type == MLX5_FLOW_TYPE_MAX) {
10637 type = MLX5_FLOW_TYPE_VERBS;
10638 if (priv->sh->cdev->config.devx && priv->sh->config.dv_flow_en)
10639 type = MLX5_FLOW_TYPE_DV;
10641 fops = flow_get_drv_ops(type);
10642 if (fops->discover_priorities == NULL) {
10643 DRV_LOG(ERR, "Priority discovery not supported");
10644 rte_errno = ENOTSUP;
10647 ret = fops->discover_priorities(dev, vprio, RTE_DIM(vprio));
10652 ret = RTE_DIM(priority_map_3);
10655 ret = RTE_DIM(priority_map_5);
10658 rte_errno = ENOTSUP;
10660 "port %u maximum priority: %d expected 8/16",
10661 dev->data->port_id, ret);
10664 DRV_LOG(INFO, "port %u supported flow priorities:"
10665 " 0-%d for ingress or egress root table,"
10666 " 0-%d for non-root table or transfer root table.",
10667 dev->data->port_id, ret - 2,
10668 MLX5_NON_ROOT_FLOW_MAX_PRIO - 1);
10673 * Adjust flow priority based on the highest layer and the request priority.
10676 * Pointer to the Ethernet device structure.
10677 * @param[in] priority
10678 * The rule base priority.
10679 * @param[in] subpriority
10680 * The priority based on the items.
10683 * The new priority.
10686 mlx5_flow_adjust_priority(struct rte_eth_dev *dev, int32_t priority,
10687 uint32_t subpriority)
10690 struct mlx5_priv *priv = dev->data->dev_private;
10692 switch (priv->sh->flow_max_priority) {
10693 case RTE_DIM(priority_map_3):
10694 res = priority_map_3[priority][subpriority];
10696 case RTE_DIM(priority_map_5):
10697 res = priority_map_5[priority][subpriority];