1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2016 6WIND S.A.
3 * Copyright 2016 Mellanox Technologies, Ltd
10 #include <sys/queue.h>
12 #include <rte_common.h>
13 #include <rte_ether.h>
14 #include <ethdev_driver.h>
15 #include <rte_eal_paging.h>
17 #include <rte_cycles.h>
18 #include <rte_flow_driver.h>
19 #include <rte_malloc.h>
22 #include <mlx5_glue.h>
23 #include <mlx5_devx_cmds.h>
25 #include <mlx5_malloc.h>
27 #include "mlx5_defs.h"
29 #include "mlx5_flow.h"
30 #include "mlx5_flow_os.h"
33 #include "mlx5_common_os.h"
34 #include "rte_pmd_mlx5.h"
36 struct tunnel_default_miss_ctx {
40 struct rte_flow_action_rss action_rss;
41 struct rte_flow_action_queue miss_queue;
42 struct rte_flow_action_jump miss_jump;
48 flow_tunnel_add_default_miss(struct rte_eth_dev *dev,
49 struct rte_flow *flow,
50 const struct rte_flow_attr *attr,
51 const struct rte_flow_action *app_actions,
53 const struct mlx5_flow_tunnel *tunnel,
54 struct tunnel_default_miss_ctx *ctx,
55 struct rte_flow_error *error);
56 static struct mlx5_flow_tunnel *
57 mlx5_find_tunnel_id(struct rte_eth_dev *dev, uint32_t id);
59 mlx5_flow_tunnel_free(struct rte_eth_dev *dev, struct mlx5_flow_tunnel *tunnel);
61 tunnel_flow_group_to_flow_table(struct rte_eth_dev *dev,
62 const struct mlx5_flow_tunnel *tunnel,
63 uint32_t group, uint32_t *table,
64 struct rte_flow_error *error);
66 static struct mlx5_flow_workspace *mlx5_flow_push_thread_workspace(void);
67 static void mlx5_flow_pop_thread_workspace(void);
70 /** Device flow drivers. */
71 extern const struct mlx5_flow_driver_ops mlx5_flow_verbs_drv_ops;
73 const struct mlx5_flow_driver_ops mlx5_flow_null_drv_ops;
75 const struct mlx5_flow_driver_ops *flow_drv_ops[] = {
76 [MLX5_FLOW_TYPE_MIN] = &mlx5_flow_null_drv_ops,
77 #if defined(HAVE_IBV_FLOW_DV_SUPPORT) || !defined(HAVE_INFINIBAND_VERBS_H)
78 [MLX5_FLOW_TYPE_DV] = &mlx5_flow_dv_drv_ops,
80 [MLX5_FLOW_TYPE_VERBS] = &mlx5_flow_verbs_drv_ops,
81 [MLX5_FLOW_TYPE_MAX] = &mlx5_flow_null_drv_ops
84 /** Helper macro to build input graph for mlx5_flow_expand_rss(). */
85 #define MLX5_FLOW_EXPAND_RSS_NEXT(...) \
90 /** Node object of input graph for mlx5_flow_expand_rss(). */
91 struct mlx5_flow_expand_node {
92 const int *const next;
94 * List of next node indexes. Index 0 is interpreted as a terminator.
96 const enum rte_flow_item_type type;
97 /**< Pattern item type of current node. */
100 * RSS types bit-field associated with this node
101 * (see ETH_RSS_* definitions).
105 * Bit-fields that define how the node is used in the expansion.
106 * (see MLX5_EXPANSION_NODE_* definitions).
110 /* Optional expand field. The expansion alg will not go deeper. */
111 #define MLX5_EXPANSION_NODE_OPTIONAL (UINT64_C(1) << 0)
113 /* The node is not added implicitly as expansion to the flow pattern.
114 * If the node type does not match the flow pattern item type, the
115 * expansion alg will go deeper to its next items.
116 * In the current implementation, the list of next nodes indexes can
117 * have up to one node with this flag set and it has to be the last
118 * node index (before the list terminator).
120 #define MLX5_EXPANSION_NODE_EXPLICIT (UINT64_C(1) << 1)
122 /** Object returned by mlx5_flow_expand_rss(). */
123 struct mlx5_flow_expand_rss {
125 /**< Number of entries @p patterns and @p priorities. */
127 struct rte_flow_item *pattern; /**< Expanded pattern array. */
128 uint32_t priority; /**< Priority offset for each expansion. */
133 mlx5_dbg__print_pattern(const struct rte_flow_item *item);
136 mlx5_flow_is_rss_expandable_item(const struct rte_flow_item *item)
138 switch (item->type) {
139 case RTE_FLOW_ITEM_TYPE_ETH:
140 case RTE_FLOW_ITEM_TYPE_VLAN:
141 case RTE_FLOW_ITEM_TYPE_IPV4:
142 case RTE_FLOW_ITEM_TYPE_IPV6:
143 case RTE_FLOW_ITEM_TYPE_UDP:
144 case RTE_FLOW_ITEM_TYPE_TCP:
145 case RTE_FLOW_ITEM_TYPE_VXLAN:
146 case RTE_FLOW_ITEM_TYPE_NVGRE:
147 case RTE_FLOW_ITEM_TYPE_GRE:
148 case RTE_FLOW_ITEM_TYPE_GENEVE:
149 case RTE_FLOW_ITEM_TYPE_MPLS:
150 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
151 case RTE_FLOW_ITEM_TYPE_GRE_KEY:
152 case RTE_FLOW_ITEM_TYPE_IPV6_FRAG_EXT:
153 case RTE_FLOW_ITEM_TYPE_GTP:
161 static enum rte_flow_item_type
162 mlx5_flow_expand_rss_item_complete(const struct rte_flow_item *item)
164 enum rte_flow_item_type ret = RTE_FLOW_ITEM_TYPE_VOID;
165 uint16_t ether_type = 0;
166 uint16_t ether_type_m;
167 uint8_t ip_next_proto = 0;
168 uint8_t ip_next_proto_m;
170 if (item == NULL || item->spec == NULL)
172 switch (item->type) {
173 case RTE_FLOW_ITEM_TYPE_ETH:
175 ether_type_m = ((const struct rte_flow_item_eth *)
178 ether_type_m = rte_flow_item_eth_mask.type;
179 if (ether_type_m != RTE_BE16(0xFFFF))
181 ether_type = ((const struct rte_flow_item_eth *)
183 if (rte_be_to_cpu_16(ether_type) == RTE_ETHER_TYPE_IPV4)
184 ret = RTE_FLOW_ITEM_TYPE_IPV4;
185 else if (rte_be_to_cpu_16(ether_type) == RTE_ETHER_TYPE_IPV6)
186 ret = RTE_FLOW_ITEM_TYPE_IPV6;
187 else if (rte_be_to_cpu_16(ether_type) == RTE_ETHER_TYPE_VLAN)
188 ret = RTE_FLOW_ITEM_TYPE_VLAN;
190 ret = RTE_FLOW_ITEM_TYPE_END;
192 case RTE_FLOW_ITEM_TYPE_VLAN:
194 ether_type_m = ((const struct rte_flow_item_vlan *)
195 (item->mask))->inner_type;
197 ether_type_m = rte_flow_item_vlan_mask.inner_type;
198 if (ether_type_m != RTE_BE16(0xFFFF))
200 ether_type = ((const struct rte_flow_item_vlan *)
201 (item->spec))->inner_type;
202 if (rte_be_to_cpu_16(ether_type) == RTE_ETHER_TYPE_IPV4)
203 ret = RTE_FLOW_ITEM_TYPE_IPV4;
204 else if (rte_be_to_cpu_16(ether_type) == RTE_ETHER_TYPE_IPV6)
205 ret = RTE_FLOW_ITEM_TYPE_IPV6;
206 else if (rte_be_to_cpu_16(ether_type) == RTE_ETHER_TYPE_VLAN)
207 ret = RTE_FLOW_ITEM_TYPE_VLAN;
209 ret = RTE_FLOW_ITEM_TYPE_END;
211 case RTE_FLOW_ITEM_TYPE_IPV4:
213 ip_next_proto_m = ((const struct rte_flow_item_ipv4 *)
214 (item->mask))->hdr.next_proto_id;
217 rte_flow_item_ipv4_mask.hdr.next_proto_id;
218 if (ip_next_proto_m != 0xFF)
220 ip_next_proto = ((const struct rte_flow_item_ipv4 *)
221 (item->spec))->hdr.next_proto_id;
222 if (ip_next_proto == IPPROTO_UDP)
223 ret = RTE_FLOW_ITEM_TYPE_UDP;
224 else if (ip_next_proto == IPPROTO_TCP)
225 ret = RTE_FLOW_ITEM_TYPE_TCP;
226 else if (ip_next_proto == IPPROTO_IP)
227 ret = RTE_FLOW_ITEM_TYPE_IPV4;
228 else if (ip_next_proto == IPPROTO_IPV6)
229 ret = RTE_FLOW_ITEM_TYPE_IPV6;
231 ret = RTE_FLOW_ITEM_TYPE_END;
233 case RTE_FLOW_ITEM_TYPE_IPV6:
235 ip_next_proto_m = ((const struct rte_flow_item_ipv6 *)
236 (item->mask))->hdr.proto;
239 rte_flow_item_ipv6_mask.hdr.proto;
240 if (ip_next_proto_m != 0xFF)
242 ip_next_proto = ((const struct rte_flow_item_ipv6 *)
243 (item->spec))->hdr.proto;
244 if (ip_next_proto == IPPROTO_UDP)
245 ret = RTE_FLOW_ITEM_TYPE_UDP;
246 else if (ip_next_proto == IPPROTO_TCP)
247 ret = RTE_FLOW_ITEM_TYPE_TCP;
248 else if (ip_next_proto == IPPROTO_IP)
249 ret = RTE_FLOW_ITEM_TYPE_IPV4;
250 else if (ip_next_proto == IPPROTO_IPV6)
251 ret = RTE_FLOW_ITEM_TYPE_IPV6;
253 ret = RTE_FLOW_ITEM_TYPE_END;
256 ret = RTE_FLOW_ITEM_TYPE_VOID;
262 #define MLX5_RSS_EXP_ELT_N 16
265 * Expand RSS flows into several possible flows according to the RSS hash
266 * fields requested and the driver capabilities.
269 * Buffer to store the result expansion.
271 * Buffer size in bytes. If 0, @p buf can be NULL.
275 * RSS types to expand (see ETH_RSS_* definitions).
277 * Input graph to expand @p pattern according to @p types.
278 * @param[in] graph_root_index
279 * Index of root node in @p graph, typically 0.
282 * A positive value representing the size of @p buf in bytes regardless of
283 * @p size on success, a negative errno value otherwise and rte_errno is
284 * set, the following errors are defined:
286 * -E2BIG: graph-depth @p graph is too deep.
287 * -EINVAL: @p size has not enough space for expanded pattern.
290 mlx5_flow_expand_rss(struct mlx5_flow_expand_rss *buf, size_t size,
291 const struct rte_flow_item *pattern, uint64_t types,
292 const struct mlx5_flow_expand_node graph[],
293 int graph_root_index)
295 const struct rte_flow_item *item;
296 const struct mlx5_flow_expand_node *node = &graph[graph_root_index];
297 const int *next_node;
298 const int *stack[MLX5_RSS_EXP_ELT_N];
300 struct rte_flow_item flow_items[MLX5_RSS_EXP_ELT_N];
303 size_t user_pattern_size = 0;
305 const struct mlx5_flow_expand_node *next = NULL;
306 struct rte_flow_item missed_item;
309 const struct rte_flow_item *last_item = NULL;
311 memset(&missed_item, 0, sizeof(missed_item));
312 lsize = offsetof(struct mlx5_flow_expand_rss, entry) +
313 MLX5_RSS_EXP_ELT_N * sizeof(buf->entry[0]);
316 buf->entry[0].priority = 0;
317 buf->entry[0].pattern = (void *)&buf->entry[MLX5_RSS_EXP_ELT_N];
319 addr = buf->entry[0].pattern;
320 for (item = pattern; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
321 if (!mlx5_flow_is_rss_expandable_item(item)) {
322 user_pattern_size += sizeof(*item);
327 while (node->next && node->next[i]) {
328 next = &graph[node->next[i]];
329 if (next->type == item->type)
331 if (next->node_flags & MLX5_EXPANSION_NODE_EXPLICIT) {
340 user_pattern_size += sizeof(*item);
342 user_pattern_size += sizeof(*item); /* Handle END item. */
343 lsize += user_pattern_size;
346 /* Copy the user pattern in the first entry of the buffer. */
347 rte_memcpy(addr, pattern, user_pattern_size);
348 addr = (void *)(((uintptr_t)addr) + user_pattern_size);
350 /* Start expanding. */
351 memset(flow_items, 0, sizeof(flow_items));
352 user_pattern_size -= sizeof(*item);
354 * Check if the last valid item has spec set, need complete pattern,
355 * and the pattern can be used for expansion.
357 missed_item.type = mlx5_flow_expand_rss_item_complete(last_item);
358 if (missed_item.type == RTE_FLOW_ITEM_TYPE_END) {
359 /* Item type END indicates expansion is not required. */
362 if (missed_item.type != RTE_FLOW_ITEM_TYPE_VOID) {
365 for (i = 0; node->next && node->next[i]; ++i) {
366 next = &graph[node->next[i]];
367 if (next->type == missed_item.type) {
368 flow_items[0].type = missed_item.type;
369 flow_items[1].type = RTE_FLOW_ITEM_TYPE_END;
375 if (next && missed) {
376 elt = 2; /* missed item + item end. */
378 lsize += elt * sizeof(*item) + user_pattern_size;
381 if (node->rss_types & types) {
382 buf->entry[buf->entries].priority = 1;
383 buf->entry[buf->entries].pattern = addr;
385 rte_memcpy(addr, buf->entry[0].pattern,
387 addr = (void *)(((uintptr_t)addr) + user_pattern_size);
388 rte_memcpy(addr, flow_items, elt * sizeof(*item));
389 addr = (void *)(((uintptr_t)addr) +
390 elt * sizeof(*item));
393 memset(flow_items, 0, sizeof(flow_items));
394 next_node = node->next;
397 * Skip the nodes with the MLX5_EXPANSION_NODE_EXPLICIT
398 * flag set, because they were not found in the flow pattern.
400 node = &graph[*next_node];
401 if (!(node->node_flags & MLX5_EXPANSION_NODE_EXPLICIT))
403 next_node = node->next;
405 stack[stack_pos] = next_node;
406 node = next_node ? &graph[*next_node] : NULL;
408 flow_items[stack_pos].type = node->type;
409 if (node->rss_types & types) {
412 * compute the number of items to copy from the
413 * expansion and copy it.
414 * When the stack_pos is 0, there are 1 element in it,
415 * plus the addition END item.
418 flow_items[stack_pos + 1].type = RTE_FLOW_ITEM_TYPE_END;
419 lsize += elt * sizeof(*item) + user_pattern_size;
422 n = elt * sizeof(*item);
423 buf->entry[buf->entries].priority =
424 stack_pos + 1 + missed;
425 buf->entry[buf->entries].pattern = addr;
427 rte_memcpy(addr, buf->entry[0].pattern,
429 addr = (void *)(((uintptr_t)addr) +
431 rte_memcpy(addr, &missed_item,
432 missed * sizeof(*item));
433 addr = (void *)(((uintptr_t)addr) +
434 missed * sizeof(*item));
435 rte_memcpy(addr, flow_items, n);
436 addr = (void *)(((uintptr_t)addr) + n);
439 if (!(node->node_flags & MLX5_EXPANSION_NODE_OPTIONAL) &&
441 next_node = node->next;
442 if (stack_pos++ == MLX5_RSS_EXP_ELT_N) {
446 stack[stack_pos] = next_node;
447 } else if (*(next_node + 1)) {
448 /* Follow up with the next possibility. */
451 /* Move to the next path. */
453 next_node = stack[--stack_pos];
455 stack[stack_pos] = next_node;
457 node = *next_node ? &graph[*next_node] : NULL;
462 enum mlx5_expansion {
464 MLX5_EXPANSION_ROOT_OUTER,
465 MLX5_EXPANSION_OUTER_ETH,
466 MLX5_EXPANSION_OUTER_VLAN,
467 MLX5_EXPANSION_OUTER_IPV4,
468 MLX5_EXPANSION_OUTER_IPV4_UDP,
469 MLX5_EXPANSION_OUTER_IPV4_TCP,
470 MLX5_EXPANSION_OUTER_IPV6,
471 MLX5_EXPANSION_OUTER_IPV6_UDP,
472 MLX5_EXPANSION_OUTER_IPV6_TCP,
473 MLX5_EXPANSION_VXLAN,
474 MLX5_EXPANSION_VXLAN_GPE,
476 MLX5_EXPANSION_NVGRE,
477 MLX5_EXPANSION_GRE_KEY,
482 MLX5_EXPANSION_IPV4_UDP,
483 MLX5_EXPANSION_IPV4_TCP,
485 MLX5_EXPANSION_IPV6_UDP,
486 MLX5_EXPANSION_IPV6_TCP,
487 MLX5_EXPANSION_IPV6_FRAG_EXT,
491 /** Supported expansion of items. */
492 static const struct mlx5_flow_expand_node mlx5_support_expansion[] = {
493 [MLX5_EXPANSION_ROOT] = {
494 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
496 MLX5_EXPANSION_IPV6),
497 .type = RTE_FLOW_ITEM_TYPE_END,
499 [MLX5_EXPANSION_ROOT_OUTER] = {
500 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_ETH,
501 MLX5_EXPANSION_OUTER_IPV4,
502 MLX5_EXPANSION_OUTER_IPV6),
503 .type = RTE_FLOW_ITEM_TYPE_END,
505 [MLX5_EXPANSION_OUTER_ETH] = {
506 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_VLAN),
507 .type = RTE_FLOW_ITEM_TYPE_ETH,
510 [MLX5_EXPANSION_OUTER_VLAN] = {
511 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_IPV4,
512 MLX5_EXPANSION_OUTER_IPV6),
513 .type = RTE_FLOW_ITEM_TYPE_VLAN,
514 .node_flags = MLX5_EXPANSION_NODE_EXPLICIT,
516 [MLX5_EXPANSION_OUTER_IPV4] = {
517 .next = MLX5_FLOW_EXPAND_RSS_NEXT
518 (MLX5_EXPANSION_OUTER_IPV4_UDP,
519 MLX5_EXPANSION_OUTER_IPV4_TCP,
521 MLX5_EXPANSION_NVGRE,
523 MLX5_EXPANSION_IPV6),
524 .type = RTE_FLOW_ITEM_TYPE_IPV4,
525 .rss_types = ETH_RSS_IPV4 | ETH_RSS_FRAG_IPV4 |
526 ETH_RSS_NONFRAG_IPV4_OTHER,
528 [MLX5_EXPANSION_OUTER_IPV4_UDP] = {
529 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VXLAN,
530 MLX5_EXPANSION_VXLAN_GPE,
533 .type = RTE_FLOW_ITEM_TYPE_UDP,
534 .rss_types = ETH_RSS_NONFRAG_IPV4_UDP,
536 [MLX5_EXPANSION_OUTER_IPV4_TCP] = {
537 .type = RTE_FLOW_ITEM_TYPE_TCP,
538 .rss_types = ETH_RSS_NONFRAG_IPV4_TCP,
540 [MLX5_EXPANSION_OUTER_IPV6] = {
541 .next = MLX5_FLOW_EXPAND_RSS_NEXT
542 (MLX5_EXPANSION_OUTER_IPV6_UDP,
543 MLX5_EXPANSION_OUTER_IPV6_TCP,
547 MLX5_EXPANSION_NVGRE),
548 .type = RTE_FLOW_ITEM_TYPE_IPV6,
549 .rss_types = ETH_RSS_IPV6 | ETH_RSS_FRAG_IPV6 |
550 ETH_RSS_NONFRAG_IPV6_OTHER,
552 [MLX5_EXPANSION_OUTER_IPV6_UDP] = {
553 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VXLAN,
554 MLX5_EXPANSION_VXLAN_GPE,
557 .type = RTE_FLOW_ITEM_TYPE_UDP,
558 .rss_types = ETH_RSS_NONFRAG_IPV6_UDP,
560 [MLX5_EXPANSION_OUTER_IPV6_TCP] = {
561 .type = RTE_FLOW_ITEM_TYPE_TCP,
562 .rss_types = ETH_RSS_NONFRAG_IPV6_TCP,
564 [MLX5_EXPANSION_VXLAN] = {
565 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
567 MLX5_EXPANSION_IPV6),
568 .type = RTE_FLOW_ITEM_TYPE_VXLAN,
570 [MLX5_EXPANSION_VXLAN_GPE] = {
571 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
573 MLX5_EXPANSION_IPV6),
574 .type = RTE_FLOW_ITEM_TYPE_VXLAN_GPE,
576 [MLX5_EXPANSION_GRE] = {
577 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
579 MLX5_EXPANSION_GRE_KEY,
580 MLX5_EXPANSION_MPLS),
581 .type = RTE_FLOW_ITEM_TYPE_GRE,
583 [MLX5_EXPANSION_GRE_KEY] = {
584 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
586 MLX5_EXPANSION_MPLS),
587 .type = RTE_FLOW_ITEM_TYPE_GRE_KEY,
588 .node_flags = MLX5_EXPANSION_NODE_OPTIONAL,
590 [MLX5_EXPANSION_NVGRE] = {
591 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH),
592 .type = RTE_FLOW_ITEM_TYPE_NVGRE,
594 [MLX5_EXPANSION_MPLS] = {
595 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
598 .type = RTE_FLOW_ITEM_TYPE_MPLS,
599 .node_flags = MLX5_EXPANSION_NODE_OPTIONAL,
601 [MLX5_EXPANSION_ETH] = {
602 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VLAN),
603 .type = RTE_FLOW_ITEM_TYPE_ETH,
605 [MLX5_EXPANSION_VLAN] = {
606 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
607 MLX5_EXPANSION_IPV6),
608 .type = RTE_FLOW_ITEM_TYPE_VLAN,
609 .node_flags = MLX5_EXPANSION_NODE_EXPLICIT,
611 [MLX5_EXPANSION_IPV4] = {
612 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4_UDP,
613 MLX5_EXPANSION_IPV4_TCP),
614 .type = RTE_FLOW_ITEM_TYPE_IPV4,
615 .rss_types = ETH_RSS_IPV4 | ETH_RSS_FRAG_IPV4 |
616 ETH_RSS_NONFRAG_IPV4_OTHER,
618 [MLX5_EXPANSION_IPV4_UDP] = {
619 .type = RTE_FLOW_ITEM_TYPE_UDP,
620 .rss_types = ETH_RSS_NONFRAG_IPV4_UDP,
622 [MLX5_EXPANSION_IPV4_TCP] = {
623 .type = RTE_FLOW_ITEM_TYPE_TCP,
624 .rss_types = ETH_RSS_NONFRAG_IPV4_TCP,
626 [MLX5_EXPANSION_IPV6] = {
627 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV6_UDP,
628 MLX5_EXPANSION_IPV6_TCP,
629 MLX5_EXPANSION_IPV6_FRAG_EXT),
630 .type = RTE_FLOW_ITEM_TYPE_IPV6,
631 .rss_types = ETH_RSS_IPV6 | ETH_RSS_FRAG_IPV6 |
632 ETH_RSS_NONFRAG_IPV6_OTHER,
634 [MLX5_EXPANSION_IPV6_UDP] = {
635 .type = RTE_FLOW_ITEM_TYPE_UDP,
636 .rss_types = ETH_RSS_NONFRAG_IPV6_UDP,
638 [MLX5_EXPANSION_IPV6_TCP] = {
639 .type = RTE_FLOW_ITEM_TYPE_TCP,
640 .rss_types = ETH_RSS_NONFRAG_IPV6_TCP,
642 [MLX5_EXPANSION_IPV6_FRAG_EXT] = {
643 .type = RTE_FLOW_ITEM_TYPE_IPV6_FRAG_EXT,
645 [MLX5_EXPANSION_GTP] = {
646 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
647 MLX5_EXPANSION_IPV6),
648 .type = RTE_FLOW_ITEM_TYPE_GTP,
652 static struct rte_flow_action_handle *
653 mlx5_action_handle_create(struct rte_eth_dev *dev,
654 const struct rte_flow_indir_action_conf *conf,
655 const struct rte_flow_action *action,
656 struct rte_flow_error *error);
657 static int mlx5_action_handle_destroy
658 (struct rte_eth_dev *dev,
659 struct rte_flow_action_handle *handle,
660 struct rte_flow_error *error);
661 static int mlx5_action_handle_update
662 (struct rte_eth_dev *dev,
663 struct rte_flow_action_handle *handle,
665 struct rte_flow_error *error);
666 static int mlx5_action_handle_query
667 (struct rte_eth_dev *dev,
668 const struct rte_flow_action_handle *handle,
670 struct rte_flow_error *error);
672 mlx5_flow_tunnel_decap_set(struct rte_eth_dev *dev,
673 struct rte_flow_tunnel *app_tunnel,
674 struct rte_flow_action **actions,
675 uint32_t *num_of_actions,
676 struct rte_flow_error *error);
678 mlx5_flow_tunnel_match(struct rte_eth_dev *dev,
679 struct rte_flow_tunnel *app_tunnel,
680 struct rte_flow_item **items,
681 uint32_t *num_of_items,
682 struct rte_flow_error *error);
684 mlx5_flow_tunnel_item_release(struct rte_eth_dev *dev,
685 struct rte_flow_item *pmd_items,
686 uint32_t num_items, struct rte_flow_error *err);
688 mlx5_flow_tunnel_action_release(struct rte_eth_dev *dev,
689 struct rte_flow_action *pmd_actions,
690 uint32_t num_actions,
691 struct rte_flow_error *err);
693 mlx5_flow_tunnel_get_restore_info(struct rte_eth_dev *dev,
695 struct rte_flow_restore_info *info,
696 struct rte_flow_error *err);
698 static const struct rte_flow_ops mlx5_flow_ops = {
699 .validate = mlx5_flow_validate,
700 .create = mlx5_flow_create,
701 .destroy = mlx5_flow_destroy,
702 .flush = mlx5_flow_flush,
703 .isolate = mlx5_flow_isolate,
704 .query = mlx5_flow_query,
705 .dev_dump = mlx5_flow_dev_dump,
706 .get_aged_flows = mlx5_flow_get_aged_flows,
707 .action_handle_create = mlx5_action_handle_create,
708 .action_handle_destroy = mlx5_action_handle_destroy,
709 .action_handle_update = mlx5_action_handle_update,
710 .action_handle_query = mlx5_action_handle_query,
711 .tunnel_decap_set = mlx5_flow_tunnel_decap_set,
712 .tunnel_match = mlx5_flow_tunnel_match,
713 .tunnel_action_decap_release = mlx5_flow_tunnel_action_release,
714 .tunnel_item_release = mlx5_flow_tunnel_item_release,
715 .get_restore_info = mlx5_flow_tunnel_get_restore_info,
718 /* Tunnel information. */
719 struct mlx5_flow_tunnel_info {
720 uint64_t tunnel; /**< Tunnel bit (see MLX5_FLOW_*). */
721 uint32_t ptype; /**< Tunnel Ptype (see RTE_PTYPE_*). */
724 static struct mlx5_flow_tunnel_info tunnels_info[] = {
726 .tunnel = MLX5_FLOW_LAYER_VXLAN,
727 .ptype = RTE_PTYPE_TUNNEL_VXLAN | RTE_PTYPE_L4_UDP,
730 .tunnel = MLX5_FLOW_LAYER_GENEVE,
731 .ptype = RTE_PTYPE_TUNNEL_GENEVE | RTE_PTYPE_L4_UDP,
734 .tunnel = MLX5_FLOW_LAYER_VXLAN_GPE,
735 .ptype = RTE_PTYPE_TUNNEL_VXLAN_GPE | RTE_PTYPE_L4_UDP,
738 .tunnel = MLX5_FLOW_LAYER_GRE,
739 .ptype = RTE_PTYPE_TUNNEL_GRE,
742 .tunnel = MLX5_FLOW_LAYER_MPLS | MLX5_FLOW_LAYER_OUTER_L4_UDP,
743 .ptype = RTE_PTYPE_TUNNEL_MPLS_IN_UDP | RTE_PTYPE_L4_UDP,
746 .tunnel = MLX5_FLOW_LAYER_MPLS,
747 .ptype = RTE_PTYPE_TUNNEL_MPLS_IN_GRE,
750 .tunnel = MLX5_FLOW_LAYER_NVGRE,
751 .ptype = RTE_PTYPE_TUNNEL_NVGRE,
754 .tunnel = MLX5_FLOW_LAYER_IPIP,
755 .ptype = RTE_PTYPE_TUNNEL_IP,
758 .tunnel = MLX5_FLOW_LAYER_IPV6_ENCAP,
759 .ptype = RTE_PTYPE_TUNNEL_IP,
762 .tunnel = MLX5_FLOW_LAYER_GTP,
763 .ptype = RTE_PTYPE_TUNNEL_GTPU,
770 * Translate tag ID to register.
773 * Pointer to the Ethernet device structure.
775 * The feature that request the register.
777 * The request register ID.
779 * Error description in case of any.
782 * The request register on success, a negative errno
783 * value otherwise and rte_errno is set.
786 mlx5_flow_get_reg_id(struct rte_eth_dev *dev,
787 enum mlx5_feature_name feature,
789 struct rte_flow_error *error)
791 struct mlx5_priv *priv = dev->data->dev_private;
792 struct mlx5_dev_config *config = &priv->config;
793 enum modify_reg start_reg;
794 bool skip_mtr_reg = false;
797 case MLX5_HAIRPIN_RX:
799 case MLX5_HAIRPIN_TX:
801 case MLX5_METADATA_RX:
802 switch (config->dv_xmeta_en) {
803 case MLX5_XMETA_MODE_LEGACY:
805 case MLX5_XMETA_MODE_META16:
807 case MLX5_XMETA_MODE_META32:
811 case MLX5_METADATA_TX:
813 case MLX5_METADATA_FDB:
814 switch (config->dv_xmeta_en) {
815 case MLX5_XMETA_MODE_LEGACY:
817 case MLX5_XMETA_MODE_META16:
819 case MLX5_XMETA_MODE_META32:
824 switch (config->dv_xmeta_en) {
825 case MLX5_XMETA_MODE_LEGACY:
827 case MLX5_XMETA_MODE_META16:
829 case MLX5_XMETA_MODE_META32:
835 * If meter color and meter id share one register, flow match
836 * should use the meter color register for match.
838 if (priv->mtr_reg_share)
839 return priv->mtr_color_reg;
841 return priv->mtr_color_reg != REG_C_2 ? REG_C_2 :
844 case MLX5_ASO_FLOW_HIT:
845 case MLX5_ASO_CONNTRACK:
846 /* All features use the same REG_C. */
847 MLX5_ASSERT(priv->mtr_color_reg != REG_NON);
848 return priv->mtr_color_reg;
851 * Metadata COPY_MARK register using is in meter suffix sub
852 * flow while with meter. It's safe to share the same register.
854 return priv->mtr_color_reg != REG_C_2 ? REG_C_2 : REG_C_3;
857 * If meter is enable, it will engage the register for color
858 * match and flow match. If meter color match is not using the
859 * REG_C_2, need to skip the REG_C_x be used by meter color
861 * If meter is disable, free to use all available registers.
863 start_reg = priv->mtr_color_reg != REG_C_2 ? REG_C_2 :
864 (priv->mtr_reg_share ? REG_C_3 : REG_C_4);
865 skip_mtr_reg = !!(priv->mtr_en && start_reg == REG_C_2);
866 if (id > (uint32_t)(REG_C_7 - start_reg))
867 return rte_flow_error_set(error, EINVAL,
868 RTE_FLOW_ERROR_TYPE_ITEM,
869 NULL, "invalid tag id");
870 if (config->flow_mreg_c[id + start_reg - REG_C_0] == REG_NON)
871 return rte_flow_error_set(error, ENOTSUP,
872 RTE_FLOW_ERROR_TYPE_ITEM,
873 NULL, "unsupported tag id");
875 * This case means meter is using the REG_C_x great than 2.
876 * Take care not to conflict with meter color REG_C_x.
877 * If the available index REG_C_y >= REG_C_x, skip the
880 if (skip_mtr_reg && config->flow_mreg_c
881 [id + start_reg - REG_C_0] >= priv->mtr_color_reg) {
882 if (id >= (uint32_t)(REG_C_7 - start_reg))
883 return rte_flow_error_set(error, EINVAL,
884 RTE_FLOW_ERROR_TYPE_ITEM,
885 NULL, "invalid tag id");
886 if (config->flow_mreg_c
887 [id + 1 + start_reg - REG_C_0] != REG_NON)
888 return config->flow_mreg_c
889 [id + 1 + start_reg - REG_C_0];
890 return rte_flow_error_set(error, ENOTSUP,
891 RTE_FLOW_ERROR_TYPE_ITEM,
892 NULL, "unsupported tag id");
894 return config->flow_mreg_c[id + start_reg - REG_C_0];
897 return rte_flow_error_set(error, EINVAL,
898 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
899 NULL, "invalid feature name");
903 * Check extensive flow metadata register support.
906 * Pointer to rte_eth_dev structure.
909 * True if device supports extensive flow metadata register, otherwise false.
912 mlx5_flow_ext_mreg_supported(struct rte_eth_dev *dev)
914 struct mlx5_priv *priv = dev->data->dev_private;
915 struct mlx5_dev_config *config = &priv->config;
918 * Having available reg_c can be regarded inclusively as supporting
919 * extensive flow metadata register, which could mean,
920 * - metadata register copy action by modify header.
921 * - 16 modify header actions is supported.
922 * - reg_c's are preserved across different domain (FDB and NIC) on
923 * packet loopback by flow lookup miss.
925 return config->flow_mreg_c[2] != REG_NON;
929 * Get the lowest priority.
932 * Pointer to the Ethernet device structure.
933 * @param[in] attributes
934 * Pointer to device flow rule attributes.
937 * The value of lowest priority of flow.
940 mlx5_get_lowest_priority(struct rte_eth_dev *dev,
941 const struct rte_flow_attr *attr)
943 struct mlx5_priv *priv = dev->data->dev_private;
945 if (!attr->group && !attr->transfer)
946 return priv->config.flow_prio - 2;
947 return MLX5_NON_ROOT_FLOW_MAX_PRIO - 1;
951 * Calculate matcher priority of the flow.
954 * Pointer to the Ethernet device structure.
956 * Pointer to device flow rule attributes.
957 * @param[in] subpriority
958 * The priority based on the items.
960 * The matcher priority of the flow.
963 mlx5_get_matcher_priority(struct rte_eth_dev *dev,
964 const struct rte_flow_attr *attr,
965 uint32_t subpriority)
967 uint16_t priority = (uint16_t)attr->priority;
968 struct mlx5_priv *priv = dev->data->dev_private;
970 if (!attr->group && !attr->transfer) {
971 if (attr->priority == MLX5_FLOW_LOWEST_PRIO_INDICATOR)
972 priority = priv->config.flow_prio - 1;
973 return mlx5_os_flow_adjust_priority(dev, priority, subpriority);
975 if (attr->priority == MLX5_FLOW_LOWEST_PRIO_INDICATOR)
976 priority = MLX5_NON_ROOT_FLOW_MAX_PRIO;
977 return priority * 3 + subpriority;
981 * Verify the @p item specifications (spec, last, mask) are compatible with the
985 * Item specification.
987 * @p item->mask or flow default bit-masks.
988 * @param[in] nic_mask
989 * Bit-masks covering supported fields by the NIC to compare with user mask.
991 * Bit-masks size in bytes.
992 * @param[in] range_accepted
993 * True if range of values is accepted for specific fields, false otherwise.
995 * Pointer to error structure.
998 * 0 on success, a negative errno value otherwise and rte_errno is set.
1001 mlx5_flow_item_acceptable(const struct rte_flow_item *item,
1002 const uint8_t *mask,
1003 const uint8_t *nic_mask,
1005 bool range_accepted,
1006 struct rte_flow_error *error)
1010 MLX5_ASSERT(nic_mask);
1011 for (i = 0; i < size; ++i)
1012 if ((nic_mask[i] | mask[i]) != nic_mask[i])
1013 return rte_flow_error_set(error, ENOTSUP,
1014 RTE_FLOW_ERROR_TYPE_ITEM,
1016 "mask enables non supported"
1018 if (!item->spec && (item->mask || item->last))
1019 return rte_flow_error_set(error, EINVAL,
1020 RTE_FLOW_ERROR_TYPE_ITEM, item,
1021 "mask/last without a spec is not"
1023 if (item->spec && item->last && !range_accepted) {
1029 for (i = 0; i < size; ++i) {
1030 spec[i] = ((const uint8_t *)item->spec)[i] & mask[i];
1031 last[i] = ((const uint8_t *)item->last)[i] & mask[i];
1033 ret = memcmp(spec, last, size);
1035 return rte_flow_error_set(error, EINVAL,
1036 RTE_FLOW_ERROR_TYPE_ITEM,
1038 "range is not valid");
1044 * Adjust the hash fields according to the @p flow information.
1046 * @param[in] dev_flow.
1047 * Pointer to the mlx5_flow.
1049 * 1 when the hash field is for a tunnel item.
1050 * @param[in] layer_types
1052 * @param[in] hash_fields
1056 * The hash fields that should be used.
1059 mlx5_flow_hashfields_adjust(struct mlx5_flow_rss_desc *rss_desc,
1060 int tunnel __rte_unused, uint64_t layer_types,
1061 uint64_t hash_fields)
1063 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
1064 int rss_request_inner = rss_desc->level >= 2;
1066 /* Check RSS hash level for tunnel. */
1067 if (tunnel && rss_request_inner)
1068 hash_fields |= IBV_RX_HASH_INNER;
1069 else if (tunnel || rss_request_inner)
1072 /* Check if requested layer matches RSS hash fields. */
1073 if (!(rss_desc->types & layer_types))
1079 * Lookup and set the ptype in the data Rx part. A single Ptype can be used,
1080 * if several tunnel rules are used on this queue, the tunnel ptype will be
1084 * Rx queue to update.
1087 flow_rxq_tunnel_ptype_update(struct mlx5_rxq_ctrl *rxq_ctrl)
1090 uint32_t tunnel_ptype = 0;
1092 /* Look up for the ptype to use. */
1093 for (i = 0; i != MLX5_FLOW_TUNNEL; ++i) {
1094 if (!rxq_ctrl->flow_tunnels_n[i])
1096 if (!tunnel_ptype) {
1097 tunnel_ptype = tunnels_info[i].ptype;
1103 rxq_ctrl->rxq.tunnel = tunnel_ptype;
1107 * Set the Rx queue flags (Mark/Flag and Tunnel Ptypes) according to the devive
1111 * Pointer to the Ethernet device structure.
1112 * @param[in] dev_handle
1113 * Pointer to device flow handle structure.
1116 flow_drv_rxq_flags_set(struct rte_eth_dev *dev,
1117 struct mlx5_flow_handle *dev_handle)
1119 struct mlx5_priv *priv = dev->data->dev_private;
1120 const int mark = dev_handle->mark;
1121 const int tunnel = !!(dev_handle->layers & MLX5_FLOW_LAYER_TUNNEL);
1122 struct mlx5_ind_table_obj *ind_tbl = NULL;
1125 if (dev_handle->fate_action == MLX5_FLOW_FATE_QUEUE) {
1126 struct mlx5_hrxq *hrxq;
1128 hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
1129 dev_handle->rix_hrxq);
1131 ind_tbl = hrxq->ind_table;
1132 } else if (dev_handle->fate_action == MLX5_FLOW_FATE_SHARED_RSS) {
1133 struct mlx5_shared_action_rss *shared_rss;
1135 shared_rss = mlx5_ipool_get
1136 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
1137 dev_handle->rix_srss);
1139 ind_tbl = shared_rss->ind_tbl;
1143 for (i = 0; i != ind_tbl->queues_n; ++i) {
1144 int idx = ind_tbl->queues[i];
1145 struct mlx5_rxq_ctrl *rxq_ctrl =
1146 container_of((*priv->rxqs)[idx],
1147 struct mlx5_rxq_ctrl, rxq);
1150 * To support metadata register copy on Tx loopback,
1151 * this must be always enabled (metadata may arive
1152 * from other port - not from local flows only.
1154 if (priv->config.dv_flow_en &&
1155 priv->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
1156 mlx5_flow_ext_mreg_supported(dev)) {
1157 rxq_ctrl->rxq.mark = 1;
1158 rxq_ctrl->flow_mark_n = 1;
1160 rxq_ctrl->rxq.mark = 1;
1161 rxq_ctrl->flow_mark_n++;
1166 /* Increase the counter matching the flow. */
1167 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j) {
1168 if ((tunnels_info[j].tunnel &
1169 dev_handle->layers) ==
1170 tunnels_info[j].tunnel) {
1171 rxq_ctrl->flow_tunnels_n[j]++;
1175 flow_rxq_tunnel_ptype_update(rxq_ctrl);
1181 * Set the Rx queue flags (Mark/Flag and Tunnel Ptypes) for a flow
1184 * Pointer to the Ethernet device structure.
1186 * Pointer to flow structure.
1189 flow_rxq_flags_set(struct rte_eth_dev *dev, struct rte_flow *flow)
1191 struct mlx5_priv *priv = dev->data->dev_private;
1192 uint32_t handle_idx;
1193 struct mlx5_flow_handle *dev_handle;
1195 SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
1196 handle_idx, dev_handle, next)
1197 flow_drv_rxq_flags_set(dev, dev_handle);
1201 * Clear the Rx queue flags (Mark/Flag and Tunnel Ptype) associated with the
1202 * device flow if no other flow uses it with the same kind of request.
1205 * Pointer to Ethernet device.
1206 * @param[in] dev_handle
1207 * Pointer to the device flow handle structure.
1210 flow_drv_rxq_flags_trim(struct rte_eth_dev *dev,
1211 struct mlx5_flow_handle *dev_handle)
1213 struct mlx5_priv *priv = dev->data->dev_private;
1214 const int mark = dev_handle->mark;
1215 const int tunnel = !!(dev_handle->layers & MLX5_FLOW_LAYER_TUNNEL);
1216 struct mlx5_ind_table_obj *ind_tbl = NULL;
1219 if (dev_handle->fate_action == MLX5_FLOW_FATE_QUEUE) {
1220 struct mlx5_hrxq *hrxq;
1222 hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
1223 dev_handle->rix_hrxq);
1225 ind_tbl = hrxq->ind_table;
1226 } else if (dev_handle->fate_action == MLX5_FLOW_FATE_SHARED_RSS) {
1227 struct mlx5_shared_action_rss *shared_rss;
1229 shared_rss = mlx5_ipool_get
1230 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
1231 dev_handle->rix_srss);
1233 ind_tbl = shared_rss->ind_tbl;
1237 MLX5_ASSERT(dev->data->dev_started);
1238 for (i = 0; i != ind_tbl->queues_n; ++i) {
1239 int idx = ind_tbl->queues[i];
1240 struct mlx5_rxq_ctrl *rxq_ctrl =
1241 container_of((*priv->rxqs)[idx],
1242 struct mlx5_rxq_ctrl, rxq);
1244 if (priv->config.dv_flow_en &&
1245 priv->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
1246 mlx5_flow_ext_mreg_supported(dev)) {
1247 rxq_ctrl->rxq.mark = 1;
1248 rxq_ctrl->flow_mark_n = 1;
1250 rxq_ctrl->flow_mark_n--;
1251 rxq_ctrl->rxq.mark = !!rxq_ctrl->flow_mark_n;
1256 /* Decrease the counter matching the flow. */
1257 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j) {
1258 if ((tunnels_info[j].tunnel &
1259 dev_handle->layers) ==
1260 tunnels_info[j].tunnel) {
1261 rxq_ctrl->flow_tunnels_n[j]--;
1265 flow_rxq_tunnel_ptype_update(rxq_ctrl);
1271 * Clear the Rx queue flags (Mark/Flag and Tunnel Ptype) associated with the
1272 * @p flow if no other flow uses it with the same kind of request.
1275 * Pointer to Ethernet device.
1277 * Pointer to the flow.
1280 flow_rxq_flags_trim(struct rte_eth_dev *dev, struct rte_flow *flow)
1282 struct mlx5_priv *priv = dev->data->dev_private;
1283 uint32_t handle_idx;
1284 struct mlx5_flow_handle *dev_handle;
1286 SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
1287 handle_idx, dev_handle, next)
1288 flow_drv_rxq_flags_trim(dev, dev_handle);
1292 * Clear the Mark/Flag and Tunnel ptype information in all Rx queues.
1295 * Pointer to Ethernet device.
1298 flow_rxq_flags_clear(struct rte_eth_dev *dev)
1300 struct mlx5_priv *priv = dev->data->dev_private;
1303 for (i = 0; i != priv->rxqs_n; ++i) {
1304 struct mlx5_rxq_ctrl *rxq_ctrl;
1307 if (!(*priv->rxqs)[i])
1309 rxq_ctrl = container_of((*priv->rxqs)[i],
1310 struct mlx5_rxq_ctrl, rxq);
1311 rxq_ctrl->flow_mark_n = 0;
1312 rxq_ctrl->rxq.mark = 0;
1313 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j)
1314 rxq_ctrl->flow_tunnels_n[j] = 0;
1315 rxq_ctrl->rxq.tunnel = 0;
1320 * Set the Rx queue dynamic metadata (mask and offset) for a flow
1323 * Pointer to the Ethernet device structure.
1326 mlx5_flow_rxq_dynf_metadata_set(struct rte_eth_dev *dev)
1328 struct mlx5_priv *priv = dev->data->dev_private;
1329 struct mlx5_rxq_data *data;
1332 for (i = 0; i != priv->rxqs_n; ++i) {
1333 if (!(*priv->rxqs)[i])
1335 data = (*priv->rxqs)[i];
1336 if (!rte_flow_dynf_metadata_avail()) {
1337 data->dynf_meta = 0;
1338 data->flow_meta_mask = 0;
1339 data->flow_meta_offset = -1;
1340 data->flow_meta_port_mask = 0;
1342 data->dynf_meta = 1;
1343 data->flow_meta_mask = rte_flow_dynf_metadata_mask;
1344 data->flow_meta_offset = rte_flow_dynf_metadata_offs;
1345 data->flow_meta_port_mask = priv->sh->dv_meta_mask;
1351 * return a pointer to the desired action in the list of actions.
1353 * @param[in] actions
1354 * The list of actions to search the action in.
1356 * The action to find.
1359 * Pointer to the action in the list, if found. NULL otherwise.
1361 const struct rte_flow_action *
1362 mlx5_flow_find_action(const struct rte_flow_action *actions,
1363 enum rte_flow_action_type action)
1365 if (actions == NULL)
1367 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++)
1368 if (actions->type == action)
1374 * Validate the flag action.
1376 * @param[in] action_flags
1377 * Bit-fields that holds the actions detected until now.
1379 * Attributes of flow that includes this action.
1381 * Pointer to error structure.
1384 * 0 on success, a negative errno value otherwise and rte_errno is set.
1387 mlx5_flow_validate_action_flag(uint64_t action_flags,
1388 const struct rte_flow_attr *attr,
1389 struct rte_flow_error *error)
1391 if (action_flags & MLX5_FLOW_ACTION_MARK)
1392 return rte_flow_error_set(error, EINVAL,
1393 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1394 "can't mark and flag in same flow");
1395 if (action_flags & MLX5_FLOW_ACTION_FLAG)
1396 return rte_flow_error_set(error, EINVAL,
1397 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1399 " actions in same flow");
1401 return rte_flow_error_set(error, ENOTSUP,
1402 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1403 "flag action not supported for "
1409 * Validate the mark action.
1412 * Pointer to the queue action.
1413 * @param[in] action_flags
1414 * Bit-fields that holds the actions detected until now.
1416 * Attributes of flow that includes this action.
1418 * Pointer to error structure.
1421 * 0 on success, a negative errno value otherwise and rte_errno is set.
1424 mlx5_flow_validate_action_mark(const struct rte_flow_action *action,
1425 uint64_t action_flags,
1426 const struct rte_flow_attr *attr,
1427 struct rte_flow_error *error)
1429 const struct rte_flow_action_mark *mark = action->conf;
1432 return rte_flow_error_set(error, EINVAL,
1433 RTE_FLOW_ERROR_TYPE_ACTION,
1435 "configuration cannot be null");
1436 if (mark->id >= MLX5_FLOW_MARK_MAX)
1437 return rte_flow_error_set(error, EINVAL,
1438 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1440 "mark id must in 0 <= id < "
1441 RTE_STR(MLX5_FLOW_MARK_MAX));
1442 if (action_flags & MLX5_FLOW_ACTION_FLAG)
1443 return rte_flow_error_set(error, EINVAL,
1444 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1445 "can't flag and mark in same flow");
1446 if (action_flags & MLX5_FLOW_ACTION_MARK)
1447 return rte_flow_error_set(error, EINVAL,
1448 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1449 "can't have 2 mark actions in same"
1452 return rte_flow_error_set(error, ENOTSUP,
1453 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1454 "mark action not supported for "
1460 * Validate the drop action.
1462 * @param[in] action_flags
1463 * Bit-fields that holds the actions detected until now.
1465 * Attributes of flow that includes this action.
1467 * Pointer to error structure.
1470 * 0 on success, a negative errno value otherwise and rte_errno is set.
1473 mlx5_flow_validate_action_drop(uint64_t action_flags __rte_unused,
1474 const struct rte_flow_attr *attr,
1475 struct rte_flow_error *error)
1478 return rte_flow_error_set(error, ENOTSUP,
1479 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1480 "drop action not supported for "
1486 * Validate the queue action.
1489 * Pointer to the queue action.
1490 * @param[in] action_flags
1491 * Bit-fields that holds the actions detected until now.
1493 * Pointer to the Ethernet device structure.
1495 * Attributes of flow that includes this action.
1497 * Pointer to error structure.
1500 * 0 on success, a negative errno value otherwise and rte_errno is set.
1503 mlx5_flow_validate_action_queue(const struct rte_flow_action *action,
1504 uint64_t action_flags,
1505 struct rte_eth_dev *dev,
1506 const struct rte_flow_attr *attr,
1507 struct rte_flow_error *error)
1509 struct mlx5_priv *priv = dev->data->dev_private;
1510 const struct rte_flow_action_queue *queue = action->conf;
1512 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
1513 return rte_flow_error_set(error, EINVAL,
1514 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1515 "can't have 2 fate actions in"
1518 return rte_flow_error_set(error, EINVAL,
1519 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1520 NULL, "No Rx queues configured");
1521 if (queue->index >= priv->rxqs_n)
1522 return rte_flow_error_set(error, EINVAL,
1523 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1525 "queue index out of range");
1526 if (!(*priv->rxqs)[queue->index])
1527 return rte_flow_error_set(error, EINVAL,
1528 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1530 "queue is not configured");
1532 return rte_flow_error_set(error, ENOTSUP,
1533 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1534 "queue action not supported for "
1540 * Validate the rss action.
1543 * Pointer to the Ethernet device structure.
1545 * Pointer to the queue action.
1547 * Pointer to error structure.
1550 * 0 on success, a negative errno value otherwise and rte_errno is set.
1553 mlx5_validate_action_rss(struct rte_eth_dev *dev,
1554 const struct rte_flow_action *action,
1555 struct rte_flow_error *error)
1557 struct mlx5_priv *priv = dev->data->dev_private;
1558 const struct rte_flow_action_rss *rss = action->conf;
1559 enum mlx5_rxq_type rxq_type = MLX5_RXQ_TYPE_UNDEFINED;
1562 if (rss->func != RTE_ETH_HASH_FUNCTION_DEFAULT &&
1563 rss->func != RTE_ETH_HASH_FUNCTION_TOEPLITZ)
1564 return rte_flow_error_set(error, ENOTSUP,
1565 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1567 "RSS hash function not supported");
1568 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
1573 return rte_flow_error_set(error, ENOTSUP,
1574 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1576 "tunnel RSS is not supported");
1577 /* allow RSS key_len 0 in case of NULL (default) RSS key. */
1578 if (rss->key_len == 0 && rss->key != NULL)
1579 return rte_flow_error_set(error, ENOTSUP,
1580 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1582 "RSS hash key length 0");
1583 if (rss->key_len > 0 && rss->key_len < MLX5_RSS_HASH_KEY_LEN)
1584 return rte_flow_error_set(error, ENOTSUP,
1585 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1587 "RSS hash key too small");
1588 if (rss->key_len > MLX5_RSS_HASH_KEY_LEN)
1589 return rte_flow_error_set(error, ENOTSUP,
1590 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1592 "RSS hash key too large");
1593 if (rss->queue_num > priv->config.ind_table_max_size)
1594 return rte_flow_error_set(error, ENOTSUP,
1595 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1597 "number of queues too large");
1598 if (rss->types & MLX5_RSS_HF_MASK)
1599 return rte_flow_error_set(error, ENOTSUP,
1600 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1602 "some RSS protocols are not"
1604 if ((rss->types & (ETH_RSS_L3_SRC_ONLY | ETH_RSS_L3_DST_ONLY)) &&
1605 !(rss->types & ETH_RSS_IP))
1606 return rte_flow_error_set(error, EINVAL,
1607 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1608 "L3 partial RSS requested but L3 RSS"
1609 " type not specified");
1610 if ((rss->types & (ETH_RSS_L4_SRC_ONLY | ETH_RSS_L4_DST_ONLY)) &&
1611 !(rss->types & (ETH_RSS_UDP | ETH_RSS_TCP)))
1612 return rte_flow_error_set(error, EINVAL,
1613 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1614 "L4 partial RSS requested but L4 RSS"
1615 " type not specified");
1617 return rte_flow_error_set(error, EINVAL,
1618 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1619 NULL, "No Rx queues configured");
1620 if (!rss->queue_num)
1621 return rte_flow_error_set(error, EINVAL,
1622 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1623 NULL, "No queues configured");
1624 for (i = 0; i != rss->queue_num; ++i) {
1625 struct mlx5_rxq_ctrl *rxq_ctrl;
1627 if (rss->queue[i] >= priv->rxqs_n)
1628 return rte_flow_error_set
1630 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1631 &rss->queue[i], "queue index out of range");
1632 if (!(*priv->rxqs)[rss->queue[i]])
1633 return rte_flow_error_set
1634 (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1635 &rss->queue[i], "queue is not configured");
1636 rxq_ctrl = container_of((*priv->rxqs)[rss->queue[i]],
1637 struct mlx5_rxq_ctrl, rxq);
1639 rxq_type = rxq_ctrl->type;
1640 if (rxq_type != rxq_ctrl->type)
1641 return rte_flow_error_set
1642 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1644 "combining hairpin and regular RSS queues is not supported");
1650 * Validate the rss action.
1653 * Pointer to the queue action.
1654 * @param[in] action_flags
1655 * Bit-fields that holds the actions detected until now.
1657 * Pointer to the Ethernet device structure.
1659 * Attributes of flow that includes this action.
1660 * @param[in] item_flags
1661 * Items that were detected.
1663 * Pointer to error structure.
1666 * 0 on success, a negative errno value otherwise and rte_errno is set.
1669 mlx5_flow_validate_action_rss(const struct rte_flow_action *action,
1670 uint64_t action_flags,
1671 struct rte_eth_dev *dev,
1672 const struct rte_flow_attr *attr,
1673 uint64_t item_flags,
1674 struct rte_flow_error *error)
1676 const struct rte_flow_action_rss *rss = action->conf;
1677 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1680 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
1681 return rte_flow_error_set(error, EINVAL,
1682 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1683 "can't have 2 fate actions"
1685 ret = mlx5_validate_action_rss(dev, action, error);
1689 return rte_flow_error_set(error, ENOTSUP,
1690 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1691 "rss action not supported for "
1693 if (rss->level > 1 && !tunnel)
1694 return rte_flow_error_set(error, EINVAL,
1695 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1696 "inner RSS is not supported for "
1697 "non-tunnel flows");
1698 if ((item_flags & MLX5_FLOW_LAYER_ECPRI) &&
1699 !(item_flags & MLX5_FLOW_LAYER_INNER_L4_UDP)) {
1700 return rte_flow_error_set(error, EINVAL,
1701 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1702 "RSS on eCPRI is not supported now");
1704 if ((item_flags & MLX5_FLOW_LAYER_MPLS) &&
1706 (MLX5_FLOW_LAYER_INNER_L2 | MLX5_FLOW_LAYER_INNER_L3)) &&
1708 return rte_flow_error_set(error, EINVAL,
1709 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
1710 "MPLS inner RSS needs to specify inner L2/L3 items after MPLS in pattern");
1715 * Validate the default miss action.
1717 * @param[in] action_flags
1718 * Bit-fields that holds the actions detected until now.
1720 * Pointer to error structure.
1723 * 0 on success, a negative errno value otherwise and rte_errno is set.
1726 mlx5_flow_validate_action_default_miss(uint64_t action_flags,
1727 const struct rte_flow_attr *attr,
1728 struct rte_flow_error *error)
1730 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
1731 return rte_flow_error_set(error, EINVAL,
1732 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1733 "can't have 2 fate actions in"
1736 return rte_flow_error_set(error, ENOTSUP,
1737 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1738 "default miss action not supported "
1741 return rte_flow_error_set(error, ENOTSUP,
1742 RTE_FLOW_ERROR_TYPE_ATTR_GROUP, NULL,
1743 "only group 0 is supported");
1745 return rte_flow_error_set(error, ENOTSUP,
1746 RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
1747 NULL, "transfer is not supported");
1752 * Validate the count action.
1755 * Pointer to the Ethernet device structure.
1757 * Attributes of flow that includes this action.
1759 * Pointer to error structure.
1762 * 0 on success, a negative errno value otherwise and rte_errno is set.
1765 mlx5_flow_validate_action_count(struct rte_eth_dev *dev __rte_unused,
1766 const struct rte_flow_attr *attr,
1767 struct rte_flow_error *error)
1770 return rte_flow_error_set(error, ENOTSUP,
1771 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1772 "count action not supported for "
1778 * Validate the ASO CT action.
1781 * Pointer to the Ethernet device structure.
1782 * @param[in] conntrack
1783 * Pointer to the CT action profile.
1785 * Pointer to error structure.
1788 * 0 on success, a negative errno value otherwise and rte_errno is set.
1791 mlx5_validate_action_ct(struct rte_eth_dev *dev,
1792 const struct rte_flow_action_conntrack *conntrack,
1793 struct rte_flow_error *error)
1797 if (conntrack->state > RTE_FLOW_CONNTRACK_STATE_TIME_WAIT)
1798 return rte_flow_error_set(error, EINVAL,
1799 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1800 "Invalid CT state");
1801 if (conntrack->last_index > RTE_FLOW_CONNTRACK_FLAG_RST)
1802 return rte_flow_error_set(error, EINVAL,
1803 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1804 "Invalid last TCP packet flag");
1809 * Verify the @p attributes will be correctly understood by the NIC and store
1810 * them in the @p flow if everything is correct.
1813 * Pointer to the Ethernet device structure.
1814 * @param[in] attributes
1815 * Pointer to flow attributes
1817 * Pointer to error structure.
1820 * 0 on success, a negative errno value otherwise and rte_errno is set.
1823 mlx5_flow_validate_attributes(struct rte_eth_dev *dev,
1824 const struct rte_flow_attr *attributes,
1825 struct rte_flow_error *error)
1827 struct mlx5_priv *priv = dev->data->dev_private;
1828 uint32_t priority_max = priv->config.flow_prio - 1;
1830 if (attributes->group)
1831 return rte_flow_error_set(error, ENOTSUP,
1832 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
1833 NULL, "groups is not supported");
1834 if (attributes->priority != MLX5_FLOW_LOWEST_PRIO_INDICATOR &&
1835 attributes->priority >= priority_max)
1836 return rte_flow_error_set(error, ENOTSUP,
1837 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
1838 NULL, "priority out of range");
1839 if (attributes->egress)
1840 return rte_flow_error_set(error, ENOTSUP,
1841 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1842 "egress is not supported");
1843 if (attributes->transfer && !priv->config.dv_esw_en)
1844 return rte_flow_error_set(error, ENOTSUP,
1845 RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
1846 NULL, "transfer is not supported");
1847 if (!attributes->ingress)
1848 return rte_flow_error_set(error, EINVAL,
1849 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
1851 "ingress attribute is mandatory");
1856 * Validate ICMP6 item.
1859 * Item specification.
1860 * @param[in] item_flags
1861 * Bit-fields that holds the items detected until now.
1862 * @param[in] ext_vlan_sup
1863 * Whether extended VLAN features are supported or not.
1865 * Pointer to error structure.
1868 * 0 on success, a negative errno value otherwise and rte_errno is set.
1871 mlx5_flow_validate_item_icmp6(const struct rte_flow_item *item,
1872 uint64_t item_flags,
1873 uint8_t target_protocol,
1874 struct rte_flow_error *error)
1876 const struct rte_flow_item_icmp6 *mask = item->mask;
1877 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1878 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
1879 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
1880 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1881 MLX5_FLOW_LAYER_OUTER_L4;
1884 if (target_protocol != 0xFF && target_protocol != IPPROTO_ICMPV6)
1885 return rte_flow_error_set(error, EINVAL,
1886 RTE_FLOW_ERROR_TYPE_ITEM, item,
1887 "protocol filtering not compatible"
1888 " with ICMP6 layer");
1889 if (!(item_flags & l3m))
1890 return rte_flow_error_set(error, EINVAL,
1891 RTE_FLOW_ERROR_TYPE_ITEM, item,
1892 "IPv6 is mandatory to filter on"
1894 if (item_flags & l4m)
1895 return rte_flow_error_set(error, EINVAL,
1896 RTE_FLOW_ERROR_TYPE_ITEM, item,
1897 "multiple L4 layers not supported");
1899 mask = &rte_flow_item_icmp6_mask;
1900 ret = mlx5_flow_item_acceptable
1901 (item, (const uint8_t *)mask,
1902 (const uint8_t *)&rte_flow_item_icmp6_mask,
1903 sizeof(struct rte_flow_item_icmp6),
1904 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
1911 * Validate ICMP item.
1914 * Item specification.
1915 * @param[in] item_flags
1916 * Bit-fields that holds the items detected until now.
1918 * Pointer to error structure.
1921 * 0 on success, a negative errno value otherwise and rte_errno is set.
1924 mlx5_flow_validate_item_icmp(const struct rte_flow_item *item,
1925 uint64_t item_flags,
1926 uint8_t target_protocol,
1927 struct rte_flow_error *error)
1929 const struct rte_flow_item_icmp *mask = item->mask;
1930 const struct rte_flow_item_icmp nic_mask = {
1931 .hdr.icmp_type = 0xff,
1932 .hdr.icmp_code = 0xff,
1933 .hdr.icmp_ident = RTE_BE16(0xffff),
1934 .hdr.icmp_seq_nb = RTE_BE16(0xffff),
1936 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1937 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
1938 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
1939 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1940 MLX5_FLOW_LAYER_OUTER_L4;
1943 if (target_protocol != 0xFF && target_protocol != IPPROTO_ICMP)
1944 return rte_flow_error_set(error, EINVAL,
1945 RTE_FLOW_ERROR_TYPE_ITEM, item,
1946 "protocol filtering not compatible"
1947 " with ICMP layer");
1948 if (!(item_flags & l3m))
1949 return rte_flow_error_set(error, EINVAL,
1950 RTE_FLOW_ERROR_TYPE_ITEM, item,
1951 "IPv4 is mandatory to filter"
1953 if (item_flags & l4m)
1954 return rte_flow_error_set(error, EINVAL,
1955 RTE_FLOW_ERROR_TYPE_ITEM, item,
1956 "multiple L4 layers not supported");
1959 ret = mlx5_flow_item_acceptable
1960 (item, (const uint8_t *)mask,
1961 (const uint8_t *)&nic_mask,
1962 sizeof(struct rte_flow_item_icmp),
1963 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
1970 * Validate Ethernet item.
1973 * Item specification.
1974 * @param[in] item_flags
1975 * Bit-fields that holds the items detected until now.
1977 * Pointer to error structure.
1980 * 0 on success, a negative errno value otherwise and rte_errno is set.
1983 mlx5_flow_validate_item_eth(const struct rte_flow_item *item,
1984 uint64_t item_flags, bool ext_vlan_sup,
1985 struct rte_flow_error *error)
1987 const struct rte_flow_item_eth *mask = item->mask;
1988 const struct rte_flow_item_eth nic_mask = {
1989 .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
1990 .src.addr_bytes = "\xff\xff\xff\xff\xff\xff",
1991 .type = RTE_BE16(0xffff),
1992 .has_vlan = ext_vlan_sup ? 1 : 0,
1995 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1996 const uint64_t ethm = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
1997 MLX5_FLOW_LAYER_OUTER_L2;
1999 if (item_flags & ethm)
2000 return rte_flow_error_set(error, ENOTSUP,
2001 RTE_FLOW_ERROR_TYPE_ITEM, item,
2002 "multiple L2 layers not supported");
2003 if ((!tunnel && (item_flags & MLX5_FLOW_LAYER_OUTER_L3)) ||
2004 (tunnel && (item_flags & MLX5_FLOW_LAYER_INNER_L3)))
2005 return rte_flow_error_set(error, EINVAL,
2006 RTE_FLOW_ERROR_TYPE_ITEM, item,
2007 "L2 layer should not follow "
2009 if ((!tunnel && (item_flags & MLX5_FLOW_LAYER_OUTER_VLAN)) ||
2010 (tunnel && (item_flags & MLX5_FLOW_LAYER_INNER_VLAN)))
2011 return rte_flow_error_set(error, EINVAL,
2012 RTE_FLOW_ERROR_TYPE_ITEM, item,
2013 "L2 layer should not follow VLAN");
2014 if (item_flags & MLX5_FLOW_LAYER_GTP)
2015 return rte_flow_error_set(error, EINVAL,
2016 RTE_FLOW_ERROR_TYPE_ITEM, item,
2017 "L2 layer should not follow GTP");
2019 mask = &rte_flow_item_eth_mask;
2020 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2021 (const uint8_t *)&nic_mask,
2022 sizeof(struct rte_flow_item_eth),
2023 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2028 * Validate VLAN item.
2031 * Item specification.
2032 * @param[in] item_flags
2033 * Bit-fields that holds the items detected until now.
2035 * Ethernet device flow is being created on.
2037 * Pointer to error structure.
2040 * 0 on success, a negative errno value otherwise and rte_errno is set.
2043 mlx5_flow_validate_item_vlan(const struct rte_flow_item *item,
2044 uint64_t item_flags,
2045 struct rte_eth_dev *dev,
2046 struct rte_flow_error *error)
2048 const struct rte_flow_item_vlan *spec = item->spec;
2049 const struct rte_flow_item_vlan *mask = item->mask;
2050 const struct rte_flow_item_vlan nic_mask = {
2051 .tci = RTE_BE16(UINT16_MAX),
2052 .inner_type = RTE_BE16(UINT16_MAX),
2054 uint16_t vlan_tag = 0;
2055 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2057 const uint64_t l34m = tunnel ? (MLX5_FLOW_LAYER_INNER_L3 |
2058 MLX5_FLOW_LAYER_INNER_L4) :
2059 (MLX5_FLOW_LAYER_OUTER_L3 |
2060 MLX5_FLOW_LAYER_OUTER_L4);
2061 const uint64_t vlanm = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
2062 MLX5_FLOW_LAYER_OUTER_VLAN;
2064 if (item_flags & vlanm)
2065 return rte_flow_error_set(error, EINVAL,
2066 RTE_FLOW_ERROR_TYPE_ITEM, item,
2067 "multiple VLAN layers not supported");
2068 else if ((item_flags & l34m) != 0)
2069 return rte_flow_error_set(error, EINVAL,
2070 RTE_FLOW_ERROR_TYPE_ITEM, item,
2071 "VLAN cannot follow L3/L4 layer");
2073 mask = &rte_flow_item_vlan_mask;
2074 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2075 (const uint8_t *)&nic_mask,
2076 sizeof(struct rte_flow_item_vlan),
2077 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2080 if (!tunnel && mask->tci != RTE_BE16(0x0fff)) {
2081 struct mlx5_priv *priv = dev->data->dev_private;
2083 if (priv->vmwa_context) {
2085 * Non-NULL context means we have a virtual machine
2086 * and SR-IOV enabled, we have to create VLAN interface
2087 * to make hypervisor to setup E-Switch vport
2088 * context correctly. We avoid creating the multiple
2089 * VLAN interfaces, so we cannot support VLAN tag mask.
2091 return rte_flow_error_set(error, EINVAL,
2092 RTE_FLOW_ERROR_TYPE_ITEM,
2094 "VLAN tag mask is not"
2095 " supported in virtual"
2100 vlan_tag = spec->tci;
2101 vlan_tag &= mask->tci;
2104 * From verbs perspective an empty VLAN is equivalent
2105 * to a packet without VLAN layer.
2108 return rte_flow_error_set(error, EINVAL,
2109 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
2111 "VLAN cannot be empty");
2116 * Validate IPV4 item.
2119 * Item specification.
2120 * @param[in] item_flags
2121 * Bit-fields that holds the items detected until now.
2122 * @param[in] last_item
2123 * Previous validated item in the pattern items.
2124 * @param[in] ether_type
2125 * Type in the ethernet layer header (including dot1q).
2126 * @param[in] acc_mask
2127 * Acceptable mask, if NULL default internal default mask
2128 * will be used to check whether item fields are supported.
2129 * @param[in] range_accepted
2130 * True if range of values is accepted for specific fields, false otherwise.
2132 * Pointer to error structure.
2135 * 0 on success, a negative errno value otherwise and rte_errno is set.
2138 mlx5_flow_validate_item_ipv4(const struct rte_flow_item *item,
2139 uint64_t item_flags,
2141 uint16_t ether_type,
2142 const struct rte_flow_item_ipv4 *acc_mask,
2143 bool range_accepted,
2144 struct rte_flow_error *error)
2146 const struct rte_flow_item_ipv4 *mask = item->mask;
2147 const struct rte_flow_item_ipv4 *spec = item->spec;
2148 const struct rte_flow_item_ipv4 nic_mask = {
2150 .src_addr = RTE_BE32(0xffffffff),
2151 .dst_addr = RTE_BE32(0xffffffff),
2152 .type_of_service = 0xff,
2153 .next_proto_id = 0xff,
2156 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2157 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2158 MLX5_FLOW_LAYER_OUTER_L3;
2159 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2160 MLX5_FLOW_LAYER_OUTER_L4;
2162 uint8_t next_proto = 0xFF;
2163 const uint64_t l2_vlan = (MLX5_FLOW_LAYER_L2 |
2164 MLX5_FLOW_LAYER_OUTER_VLAN |
2165 MLX5_FLOW_LAYER_INNER_VLAN);
2167 if ((last_item & l2_vlan) && ether_type &&
2168 ether_type != RTE_ETHER_TYPE_IPV4)
2169 return rte_flow_error_set(error, EINVAL,
2170 RTE_FLOW_ERROR_TYPE_ITEM, item,
2171 "IPv4 cannot follow L2/VLAN layer "
2172 "which ether type is not IPv4");
2173 if (item_flags & MLX5_FLOW_LAYER_TUNNEL) {
2175 next_proto = mask->hdr.next_proto_id &
2176 spec->hdr.next_proto_id;
2177 if (next_proto == IPPROTO_IPIP || next_proto == IPPROTO_IPV6)
2178 return rte_flow_error_set(error, EINVAL,
2179 RTE_FLOW_ERROR_TYPE_ITEM,
2184 if (item_flags & MLX5_FLOW_LAYER_IPV6_ENCAP)
2185 return rte_flow_error_set(error, EINVAL,
2186 RTE_FLOW_ERROR_TYPE_ITEM, item,
2187 "wrong tunnel type - IPv6 specified "
2188 "but IPv4 item provided");
2189 if (item_flags & l3m)
2190 return rte_flow_error_set(error, ENOTSUP,
2191 RTE_FLOW_ERROR_TYPE_ITEM, item,
2192 "multiple L3 layers not supported");
2193 else if (item_flags & l4m)
2194 return rte_flow_error_set(error, EINVAL,
2195 RTE_FLOW_ERROR_TYPE_ITEM, item,
2196 "L3 cannot follow an L4 layer.");
2197 else if ((item_flags & MLX5_FLOW_LAYER_NVGRE) &&
2198 !(item_flags & MLX5_FLOW_LAYER_INNER_L2))
2199 return rte_flow_error_set(error, EINVAL,
2200 RTE_FLOW_ERROR_TYPE_ITEM, item,
2201 "L3 cannot follow an NVGRE layer.");
2203 mask = &rte_flow_item_ipv4_mask;
2204 else if (mask->hdr.next_proto_id != 0 &&
2205 mask->hdr.next_proto_id != 0xff)
2206 return rte_flow_error_set(error, EINVAL,
2207 RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
2208 "partial mask is not supported"
2210 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2211 acc_mask ? (const uint8_t *)acc_mask
2212 : (const uint8_t *)&nic_mask,
2213 sizeof(struct rte_flow_item_ipv4),
2214 range_accepted, error);
2221 * Validate IPV6 item.
2224 * Item specification.
2225 * @param[in] item_flags
2226 * Bit-fields that holds the items detected until now.
2227 * @param[in] last_item
2228 * Previous validated item in the pattern items.
2229 * @param[in] ether_type
2230 * Type in the ethernet layer header (including dot1q).
2231 * @param[in] acc_mask
2232 * Acceptable mask, if NULL default internal default mask
2233 * will be used to check whether item fields are supported.
2235 * Pointer to error structure.
2238 * 0 on success, a negative errno value otherwise and rte_errno is set.
2241 mlx5_flow_validate_item_ipv6(const struct rte_flow_item *item,
2242 uint64_t item_flags,
2244 uint16_t ether_type,
2245 const struct rte_flow_item_ipv6 *acc_mask,
2246 struct rte_flow_error *error)
2248 const struct rte_flow_item_ipv6 *mask = item->mask;
2249 const struct rte_flow_item_ipv6 *spec = item->spec;
2250 const struct rte_flow_item_ipv6 nic_mask = {
2253 "\xff\xff\xff\xff\xff\xff\xff\xff"
2254 "\xff\xff\xff\xff\xff\xff\xff\xff",
2256 "\xff\xff\xff\xff\xff\xff\xff\xff"
2257 "\xff\xff\xff\xff\xff\xff\xff\xff",
2258 .vtc_flow = RTE_BE32(0xffffffff),
2262 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2263 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2264 MLX5_FLOW_LAYER_OUTER_L3;
2265 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2266 MLX5_FLOW_LAYER_OUTER_L4;
2268 uint8_t next_proto = 0xFF;
2269 const uint64_t l2_vlan = (MLX5_FLOW_LAYER_L2 |
2270 MLX5_FLOW_LAYER_OUTER_VLAN |
2271 MLX5_FLOW_LAYER_INNER_VLAN);
2273 if ((last_item & l2_vlan) && ether_type &&
2274 ether_type != RTE_ETHER_TYPE_IPV6)
2275 return rte_flow_error_set(error, EINVAL,
2276 RTE_FLOW_ERROR_TYPE_ITEM, item,
2277 "IPv6 cannot follow L2/VLAN layer "
2278 "which ether type is not IPv6");
2279 if (mask && mask->hdr.proto == UINT8_MAX && spec)
2280 next_proto = spec->hdr.proto;
2281 if (item_flags & MLX5_FLOW_LAYER_TUNNEL) {
2282 if (next_proto == IPPROTO_IPIP || next_proto == IPPROTO_IPV6)
2283 return rte_flow_error_set(error, EINVAL,
2284 RTE_FLOW_ERROR_TYPE_ITEM,
2289 if (next_proto == IPPROTO_HOPOPTS ||
2290 next_proto == IPPROTO_ROUTING ||
2291 next_proto == IPPROTO_FRAGMENT ||
2292 next_proto == IPPROTO_ESP ||
2293 next_proto == IPPROTO_AH ||
2294 next_proto == IPPROTO_DSTOPTS)
2295 return rte_flow_error_set(error, EINVAL,
2296 RTE_FLOW_ERROR_TYPE_ITEM, item,
2297 "IPv6 proto (next header) should "
2298 "not be set as extension header");
2299 if (item_flags & MLX5_FLOW_LAYER_IPIP)
2300 return rte_flow_error_set(error, EINVAL,
2301 RTE_FLOW_ERROR_TYPE_ITEM, item,
2302 "wrong tunnel type - IPv4 specified "
2303 "but IPv6 item provided");
2304 if (item_flags & l3m)
2305 return rte_flow_error_set(error, ENOTSUP,
2306 RTE_FLOW_ERROR_TYPE_ITEM, item,
2307 "multiple L3 layers not supported");
2308 else if (item_flags & l4m)
2309 return rte_flow_error_set(error, EINVAL,
2310 RTE_FLOW_ERROR_TYPE_ITEM, item,
2311 "L3 cannot follow an L4 layer.");
2312 else if ((item_flags & MLX5_FLOW_LAYER_NVGRE) &&
2313 !(item_flags & MLX5_FLOW_LAYER_INNER_L2))
2314 return rte_flow_error_set(error, EINVAL,
2315 RTE_FLOW_ERROR_TYPE_ITEM, item,
2316 "L3 cannot follow an NVGRE layer.");
2318 mask = &rte_flow_item_ipv6_mask;
2319 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2320 acc_mask ? (const uint8_t *)acc_mask
2321 : (const uint8_t *)&nic_mask,
2322 sizeof(struct rte_flow_item_ipv6),
2323 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2330 * Validate UDP item.
2333 * Item specification.
2334 * @param[in] item_flags
2335 * Bit-fields that holds the items detected until now.
2336 * @param[in] target_protocol
2337 * The next protocol in the previous item.
2338 * @param[in] flow_mask
2339 * mlx5 flow-specific (DV, verbs, etc.) supported header fields mask.
2341 * Pointer to error structure.
2344 * 0 on success, a negative errno value otherwise and rte_errno is set.
2347 mlx5_flow_validate_item_udp(const struct rte_flow_item *item,
2348 uint64_t item_flags,
2349 uint8_t target_protocol,
2350 struct rte_flow_error *error)
2352 const struct rte_flow_item_udp *mask = item->mask;
2353 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2354 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2355 MLX5_FLOW_LAYER_OUTER_L3;
2356 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2357 MLX5_FLOW_LAYER_OUTER_L4;
2360 if (target_protocol != 0xff && target_protocol != IPPROTO_UDP)
2361 return rte_flow_error_set(error, EINVAL,
2362 RTE_FLOW_ERROR_TYPE_ITEM, item,
2363 "protocol filtering not compatible"
2365 if (!(item_flags & l3m))
2366 return rte_flow_error_set(error, EINVAL,
2367 RTE_FLOW_ERROR_TYPE_ITEM, item,
2368 "L3 is mandatory to filter on L4");
2369 if (item_flags & l4m)
2370 return rte_flow_error_set(error, EINVAL,
2371 RTE_FLOW_ERROR_TYPE_ITEM, item,
2372 "multiple L4 layers not supported");
2374 mask = &rte_flow_item_udp_mask;
2375 ret = mlx5_flow_item_acceptable
2376 (item, (const uint8_t *)mask,
2377 (const uint8_t *)&rte_flow_item_udp_mask,
2378 sizeof(struct rte_flow_item_udp), MLX5_ITEM_RANGE_NOT_ACCEPTED,
2386 * Validate TCP item.
2389 * Item specification.
2390 * @param[in] item_flags
2391 * Bit-fields that holds the items detected until now.
2392 * @param[in] target_protocol
2393 * The next protocol in the previous item.
2395 * Pointer to error structure.
2398 * 0 on success, a negative errno value otherwise and rte_errno is set.
2401 mlx5_flow_validate_item_tcp(const struct rte_flow_item *item,
2402 uint64_t item_flags,
2403 uint8_t target_protocol,
2404 const struct rte_flow_item_tcp *flow_mask,
2405 struct rte_flow_error *error)
2407 const struct rte_flow_item_tcp *mask = item->mask;
2408 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2409 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2410 MLX5_FLOW_LAYER_OUTER_L3;
2411 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2412 MLX5_FLOW_LAYER_OUTER_L4;
2415 MLX5_ASSERT(flow_mask);
2416 if (target_protocol != 0xff && target_protocol != IPPROTO_TCP)
2417 return rte_flow_error_set(error, EINVAL,
2418 RTE_FLOW_ERROR_TYPE_ITEM, item,
2419 "protocol filtering not compatible"
2421 if (!(item_flags & l3m))
2422 return rte_flow_error_set(error, EINVAL,
2423 RTE_FLOW_ERROR_TYPE_ITEM, item,
2424 "L3 is mandatory to filter on L4");
2425 if (item_flags & l4m)
2426 return rte_flow_error_set(error, EINVAL,
2427 RTE_FLOW_ERROR_TYPE_ITEM, item,
2428 "multiple L4 layers not supported");
2430 mask = &rte_flow_item_tcp_mask;
2431 ret = mlx5_flow_item_acceptable
2432 (item, (const uint8_t *)mask,
2433 (const uint8_t *)flow_mask,
2434 sizeof(struct rte_flow_item_tcp), MLX5_ITEM_RANGE_NOT_ACCEPTED,
2442 * Validate VXLAN item.
2445 * Pointer to the Ethernet device structure.
2446 * @param[in] udp_dport
2447 * UDP destination port
2449 * Item specification.
2450 * @param[in] item_flags
2451 * Bit-fields that holds the items detected until now.
2453 * Flow rule attributes.
2455 * Pointer to error structure.
2458 * 0 on success, a negative errno value otherwise and rte_errno is set.
2461 mlx5_flow_validate_item_vxlan(struct rte_eth_dev *dev,
2463 const struct rte_flow_item *item,
2464 uint64_t item_flags,
2465 const struct rte_flow_attr *attr,
2466 struct rte_flow_error *error)
2468 const struct rte_flow_item_vxlan *spec = item->spec;
2469 const struct rte_flow_item_vxlan *mask = item->mask;
2471 struct mlx5_priv *priv = dev->data->dev_private;
2475 } id = { .vlan_id = 0, };
2476 const struct rte_flow_item_vxlan nic_mask = {
2477 .vni = "\xff\xff\xff",
2480 const struct rte_flow_item_vxlan *valid_mask;
2482 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2483 return rte_flow_error_set(error, ENOTSUP,
2484 RTE_FLOW_ERROR_TYPE_ITEM, item,
2485 "multiple tunnel layers not"
2487 valid_mask = &rte_flow_item_vxlan_mask;
2489 * Verify only UDPv4 is present as defined in
2490 * https://tools.ietf.org/html/rfc7348
2492 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2493 return rte_flow_error_set(error, EINVAL,
2494 RTE_FLOW_ERROR_TYPE_ITEM, item,
2495 "no outer UDP layer found");
2497 mask = &rte_flow_item_vxlan_mask;
2499 if (priv->sh->steering_format_version !=
2500 MLX5_STEERING_LOGIC_FORMAT_CONNECTX_5 ||
2501 !udp_dport || udp_dport == MLX5_UDP_PORT_VXLAN) {
2502 /* FDB domain & NIC domain non-zero group */
2503 if ((attr->transfer || attr->group) && priv->sh->misc5_cap)
2504 valid_mask = &nic_mask;
2505 /* Group zero in NIC domain */
2506 if (!attr->group && !attr->transfer &&
2507 priv->sh->tunnel_header_0_1)
2508 valid_mask = &nic_mask;
2510 ret = mlx5_flow_item_acceptable
2511 (item, (const uint8_t *)mask,
2512 (const uint8_t *)valid_mask,
2513 sizeof(struct rte_flow_item_vxlan),
2514 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2518 memcpy(&id.vni[1], spec->vni, 3);
2519 memcpy(&id.vni[1], mask->vni, 3);
2521 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
2522 return rte_flow_error_set(error, ENOTSUP,
2523 RTE_FLOW_ERROR_TYPE_ITEM, item,
2524 "VXLAN tunnel must be fully defined");
2529 * Validate VXLAN_GPE item.
2532 * Item specification.
2533 * @param[in] item_flags
2534 * Bit-fields that holds the items detected until now.
2536 * Pointer to the private data structure.
2537 * @param[in] target_protocol
2538 * The next protocol in the previous item.
2540 * Pointer to error structure.
2543 * 0 on success, a negative errno value otherwise and rte_errno is set.
2546 mlx5_flow_validate_item_vxlan_gpe(const struct rte_flow_item *item,
2547 uint64_t item_flags,
2548 struct rte_eth_dev *dev,
2549 struct rte_flow_error *error)
2551 struct mlx5_priv *priv = dev->data->dev_private;
2552 const struct rte_flow_item_vxlan_gpe *spec = item->spec;
2553 const struct rte_flow_item_vxlan_gpe *mask = item->mask;
2558 } id = { .vlan_id = 0, };
2560 if (!priv->config.l3_vxlan_en)
2561 return rte_flow_error_set(error, ENOTSUP,
2562 RTE_FLOW_ERROR_TYPE_ITEM, item,
2563 "L3 VXLAN is not enabled by device"
2564 " parameter and/or not configured in"
2566 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2567 return rte_flow_error_set(error, ENOTSUP,
2568 RTE_FLOW_ERROR_TYPE_ITEM, item,
2569 "multiple tunnel layers not"
2572 * Verify only UDPv4 is present as defined in
2573 * https://tools.ietf.org/html/rfc7348
2575 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2576 return rte_flow_error_set(error, EINVAL,
2577 RTE_FLOW_ERROR_TYPE_ITEM, item,
2578 "no outer UDP layer found");
2580 mask = &rte_flow_item_vxlan_gpe_mask;
2581 ret = mlx5_flow_item_acceptable
2582 (item, (const uint8_t *)mask,
2583 (const uint8_t *)&rte_flow_item_vxlan_gpe_mask,
2584 sizeof(struct rte_flow_item_vxlan_gpe),
2585 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2590 return rte_flow_error_set(error, ENOTSUP,
2591 RTE_FLOW_ERROR_TYPE_ITEM,
2593 "VxLAN-GPE protocol"
2595 memcpy(&id.vni[1], spec->vni, 3);
2596 memcpy(&id.vni[1], mask->vni, 3);
2598 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
2599 return rte_flow_error_set(error, ENOTSUP,
2600 RTE_FLOW_ERROR_TYPE_ITEM, item,
2601 "VXLAN-GPE tunnel must be fully"
2606 * Validate GRE Key item.
2609 * Item specification.
2610 * @param[in] item_flags
2611 * Bit flags to mark detected items.
2612 * @param[in] gre_item
2613 * Pointer to gre_item
2615 * Pointer to error structure.
2618 * 0 on success, a negative errno value otherwise and rte_errno is set.
2621 mlx5_flow_validate_item_gre_key(const struct rte_flow_item *item,
2622 uint64_t item_flags,
2623 const struct rte_flow_item *gre_item,
2624 struct rte_flow_error *error)
2626 const rte_be32_t *mask = item->mask;
2628 rte_be32_t gre_key_default_mask = RTE_BE32(UINT32_MAX);
2629 const struct rte_flow_item_gre *gre_spec;
2630 const struct rte_flow_item_gre *gre_mask;
2632 if (item_flags & MLX5_FLOW_LAYER_GRE_KEY)
2633 return rte_flow_error_set(error, ENOTSUP,
2634 RTE_FLOW_ERROR_TYPE_ITEM, item,
2635 "Multiple GRE key not support");
2636 if (!(item_flags & MLX5_FLOW_LAYER_GRE))
2637 return rte_flow_error_set(error, ENOTSUP,
2638 RTE_FLOW_ERROR_TYPE_ITEM, item,
2639 "No preceding GRE header");
2640 if (item_flags & MLX5_FLOW_LAYER_INNER)
2641 return rte_flow_error_set(error, ENOTSUP,
2642 RTE_FLOW_ERROR_TYPE_ITEM, item,
2643 "GRE key following a wrong item");
2644 gre_mask = gre_item->mask;
2646 gre_mask = &rte_flow_item_gre_mask;
2647 gre_spec = gre_item->spec;
2648 if (gre_spec && (gre_mask->c_rsvd0_ver & RTE_BE16(0x2000)) &&
2649 !(gre_spec->c_rsvd0_ver & RTE_BE16(0x2000)))
2650 return rte_flow_error_set(error, EINVAL,
2651 RTE_FLOW_ERROR_TYPE_ITEM, item,
2652 "Key bit must be on");
2655 mask = &gre_key_default_mask;
2656 ret = mlx5_flow_item_acceptable
2657 (item, (const uint8_t *)mask,
2658 (const uint8_t *)&gre_key_default_mask,
2659 sizeof(rte_be32_t), MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2664 * Validate GRE item.
2667 * Item specification.
2668 * @param[in] item_flags
2669 * Bit flags to mark detected items.
2670 * @param[in] target_protocol
2671 * The next protocol in the previous item.
2673 * Pointer to error structure.
2676 * 0 on success, a negative errno value otherwise and rte_errno is set.
2679 mlx5_flow_validate_item_gre(const struct rte_flow_item *item,
2680 uint64_t item_flags,
2681 uint8_t target_protocol,
2682 struct rte_flow_error *error)
2684 const struct rte_flow_item_gre *spec __rte_unused = item->spec;
2685 const struct rte_flow_item_gre *mask = item->mask;
2687 const struct rte_flow_item_gre nic_mask = {
2688 .c_rsvd0_ver = RTE_BE16(0xB000),
2689 .protocol = RTE_BE16(UINT16_MAX),
2692 if (target_protocol != 0xff && target_protocol != IPPROTO_GRE)
2693 return rte_flow_error_set(error, EINVAL,
2694 RTE_FLOW_ERROR_TYPE_ITEM, item,
2695 "protocol filtering not compatible"
2696 " with this GRE layer");
2697 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2698 return rte_flow_error_set(error, ENOTSUP,
2699 RTE_FLOW_ERROR_TYPE_ITEM, item,
2700 "multiple tunnel layers not"
2702 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3))
2703 return rte_flow_error_set(error, ENOTSUP,
2704 RTE_FLOW_ERROR_TYPE_ITEM, item,
2705 "L3 Layer is missing");
2707 mask = &rte_flow_item_gre_mask;
2708 ret = mlx5_flow_item_acceptable
2709 (item, (const uint8_t *)mask,
2710 (const uint8_t *)&nic_mask,
2711 sizeof(struct rte_flow_item_gre), MLX5_ITEM_RANGE_NOT_ACCEPTED,
2715 #ifndef HAVE_MLX5DV_DR
2716 #ifndef HAVE_IBV_DEVICE_MPLS_SUPPORT
2717 if (spec && (spec->protocol & mask->protocol))
2718 return rte_flow_error_set(error, ENOTSUP,
2719 RTE_FLOW_ERROR_TYPE_ITEM, item,
2720 "without MPLS support the"
2721 " specification cannot be used for"
2729 * Validate Geneve item.
2732 * Item specification.
2733 * @param[in] itemFlags
2734 * Bit-fields that holds the items detected until now.
2736 * Pointer to the private data structure.
2738 * Pointer to error structure.
2741 * 0 on success, a negative errno value otherwise and rte_errno is set.
2745 mlx5_flow_validate_item_geneve(const struct rte_flow_item *item,
2746 uint64_t item_flags,
2747 struct rte_eth_dev *dev,
2748 struct rte_flow_error *error)
2750 struct mlx5_priv *priv = dev->data->dev_private;
2751 const struct rte_flow_item_geneve *spec = item->spec;
2752 const struct rte_flow_item_geneve *mask = item->mask;
2755 uint8_t opt_len = priv->config.hca_attr.geneve_max_opt_len ?
2756 MLX5_GENEVE_OPT_LEN_1 : MLX5_GENEVE_OPT_LEN_0;
2757 const struct rte_flow_item_geneve nic_mask = {
2758 .ver_opt_len_o_c_rsvd0 = RTE_BE16(0x3f80),
2759 .vni = "\xff\xff\xff",
2760 .protocol = RTE_BE16(UINT16_MAX),
2763 if (!priv->config.hca_attr.tunnel_stateless_geneve_rx)
2764 return rte_flow_error_set(error, ENOTSUP,
2765 RTE_FLOW_ERROR_TYPE_ITEM, item,
2766 "L3 Geneve is not enabled by device"
2767 " parameter and/or not configured in"
2769 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2770 return rte_flow_error_set(error, ENOTSUP,
2771 RTE_FLOW_ERROR_TYPE_ITEM, item,
2772 "multiple tunnel layers not"
2775 * Verify only UDPv4 is present as defined in
2776 * https://tools.ietf.org/html/rfc7348
2778 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2779 return rte_flow_error_set(error, EINVAL,
2780 RTE_FLOW_ERROR_TYPE_ITEM, item,
2781 "no outer UDP layer found");
2783 mask = &rte_flow_item_geneve_mask;
2784 ret = mlx5_flow_item_acceptable
2785 (item, (const uint8_t *)mask,
2786 (const uint8_t *)&nic_mask,
2787 sizeof(struct rte_flow_item_geneve),
2788 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2792 gbhdr = rte_be_to_cpu_16(spec->ver_opt_len_o_c_rsvd0);
2793 if (MLX5_GENEVE_VER_VAL(gbhdr) ||
2794 MLX5_GENEVE_CRITO_VAL(gbhdr) ||
2795 MLX5_GENEVE_RSVD_VAL(gbhdr) || spec->rsvd1)
2796 return rte_flow_error_set(error, ENOTSUP,
2797 RTE_FLOW_ERROR_TYPE_ITEM,
2799 "Geneve protocol unsupported"
2800 " fields are being used");
2801 if (MLX5_GENEVE_OPTLEN_VAL(gbhdr) > opt_len)
2802 return rte_flow_error_set
2804 RTE_FLOW_ERROR_TYPE_ITEM,
2806 "Unsupported Geneve options length");
2808 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
2809 return rte_flow_error_set
2811 RTE_FLOW_ERROR_TYPE_ITEM, item,
2812 "Geneve tunnel must be fully defined");
2817 * Validate Geneve TLV option item.
2820 * Item specification.
2821 * @param[in] last_item
2822 * Previous validated item in the pattern items.
2823 * @param[in] geneve_item
2824 * Previous GENEVE item specification.
2826 * Pointer to the rte_eth_dev structure.
2828 * Pointer to error structure.
2831 * 0 on success, a negative errno value otherwise and rte_errno is set.
2834 mlx5_flow_validate_item_geneve_opt(const struct rte_flow_item *item,
2836 const struct rte_flow_item *geneve_item,
2837 struct rte_eth_dev *dev,
2838 struct rte_flow_error *error)
2840 struct mlx5_priv *priv = dev->data->dev_private;
2841 struct mlx5_dev_ctx_shared *sh = priv->sh;
2842 struct mlx5_geneve_tlv_option_resource *geneve_opt_resource;
2843 struct mlx5_hca_attr *hca_attr = &priv->config.hca_attr;
2844 uint8_t data_max_supported =
2845 hca_attr->max_geneve_tlv_option_data_len * 4;
2846 struct mlx5_dev_config *config = &priv->config;
2847 const struct rte_flow_item_geneve *geneve_spec;
2848 const struct rte_flow_item_geneve *geneve_mask;
2849 const struct rte_flow_item_geneve_opt *spec = item->spec;
2850 const struct rte_flow_item_geneve_opt *mask = item->mask;
2852 unsigned int data_len;
2853 uint8_t tlv_option_len;
2854 uint16_t optlen_m, optlen_v;
2855 const struct rte_flow_item_geneve_opt full_mask = {
2856 .option_class = RTE_BE16(0xffff),
2857 .option_type = 0xff,
2862 mask = &rte_flow_item_geneve_opt_mask;
2864 return rte_flow_error_set
2865 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2866 "Geneve TLV opt class/type/length must be specified");
2867 if ((uint32_t)spec->option_len > MLX5_GENEVE_OPTLEN_MASK)
2868 return rte_flow_error_set
2869 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2870 "Geneve TLV opt length exceeeds the limit (31)");
2871 /* Check if class type and length masks are full. */
2872 if (full_mask.option_class != mask->option_class ||
2873 full_mask.option_type != mask->option_type ||
2874 full_mask.option_len != (mask->option_len & full_mask.option_len))
2875 return rte_flow_error_set
2876 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2877 "Geneve TLV opt class/type/length masks must be full");
2878 /* Check if length is supported */
2879 if ((uint32_t)spec->option_len >
2880 config->hca_attr.max_geneve_tlv_option_data_len)
2881 return rte_flow_error_set
2882 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2883 "Geneve TLV opt length not supported");
2884 if (config->hca_attr.max_geneve_tlv_options > 1)
2886 "max_geneve_tlv_options supports more than 1 option");
2887 /* Check GENEVE item preceding. */
2888 if (!geneve_item || !(last_item & MLX5_FLOW_LAYER_GENEVE))
2889 return rte_flow_error_set
2890 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2891 "Geneve opt item must be preceded with Geneve item");
2892 geneve_spec = geneve_item->spec;
2893 geneve_mask = geneve_item->mask ? geneve_item->mask :
2894 &rte_flow_item_geneve_mask;
2895 /* Check if GENEVE TLV option size doesn't exceed option length */
2896 if (geneve_spec && (geneve_mask->ver_opt_len_o_c_rsvd0 ||
2897 geneve_spec->ver_opt_len_o_c_rsvd0)) {
2898 tlv_option_len = spec->option_len & mask->option_len;
2899 optlen_v = rte_be_to_cpu_16(geneve_spec->ver_opt_len_o_c_rsvd0);
2900 optlen_v = MLX5_GENEVE_OPTLEN_VAL(optlen_v);
2901 optlen_m = rte_be_to_cpu_16(geneve_mask->ver_opt_len_o_c_rsvd0);
2902 optlen_m = MLX5_GENEVE_OPTLEN_VAL(optlen_m);
2903 if ((optlen_v & optlen_m) <= tlv_option_len)
2904 return rte_flow_error_set
2905 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2906 "GENEVE TLV option length exceeds optlen");
2908 /* Check if length is 0 or data is 0. */
2909 if (spec->data == NULL || spec->option_len == 0)
2910 return rte_flow_error_set
2911 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2912 "Geneve TLV opt with zero data/length not supported");
2913 /* Check not all data & mask are 0. */
2914 data_len = spec->option_len * 4;
2915 if (mask->data == NULL) {
2916 for (i = 0; i < data_len; i++)
2920 return rte_flow_error_set(error, ENOTSUP,
2921 RTE_FLOW_ERROR_TYPE_ITEM, item,
2922 "Can't match on Geneve option data 0");
2924 for (i = 0; i < data_len; i++)
2925 if (spec->data[i] & mask->data[i])
2928 return rte_flow_error_set(error, ENOTSUP,
2929 RTE_FLOW_ERROR_TYPE_ITEM, item,
2930 "Can't match on Geneve option data and mask 0");
2931 /* Check data mask supported. */
2932 for (i = data_max_supported; i < data_len ; i++)
2934 return rte_flow_error_set(error, ENOTSUP,
2935 RTE_FLOW_ERROR_TYPE_ITEM, item,
2936 "Data mask is of unsupported size");
2938 /* Check GENEVE option is supported in NIC. */
2939 if (!config->hca_attr.geneve_tlv_opt)
2940 return rte_flow_error_set
2941 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2942 "Geneve TLV opt not supported");
2943 /* Check if we already have geneve option with different type/class. */
2944 rte_spinlock_lock(&sh->geneve_tlv_opt_sl);
2945 geneve_opt_resource = sh->geneve_tlv_option_resource;
2946 if (geneve_opt_resource != NULL)
2947 if (geneve_opt_resource->option_class != spec->option_class ||
2948 geneve_opt_resource->option_type != spec->option_type ||
2949 geneve_opt_resource->length != spec->option_len) {
2950 rte_spinlock_unlock(&sh->geneve_tlv_opt_sl);
2951 return rte_flow_error_set(error, ENOTSUP,
2952 RTE_FLOW_ERROR_TYPE_ITEM, item,
2953 "Only one Geneve TLV option supported");
2955 rte_spinlock_unlock(&sh->geneve_tlv_opt_sl);
2960 * Validate MPLS item.
2963 * Pointer to the rte_eth_dev structure.
2965 * Item specification.
2966 * @param[in] item_flags
2967 * Bit-fields that holds the items detected until now.
2968 * @param[in] prev_layer
2969 * The protocol layer indicated in previous item.
2971 * Pointer to error structure.
2974 * 0 on success, a negative errno value otherwise and rte_errno is set.
2977 mlx5_flow_validate_item_mpls(struct rte_eth_dev *dev __rte_unused,
2978 const struct rte_flow_item *item __rte_unused,
2979 uint64_t item_flags __rte_unused,
2980 uint64_t prev_layer __rte_unused,
2981 struct rte_flow_error *error)
2983 #ifdef HAVE_IBV_DEVICE_MPLS_SUPPORT
2984 const struct rte_flow_item_mpls *mask = item->mask;
2985 struct mlx5_priv *priv = dev->data->dev_private;
2988 if (!priv->config.mpls_en)
2989 return rte_flow_error_set(error, ENOTSUP,
2990 RTE_FLOW_ERROR_TYPE_ITEM, item,
2991 "MPLS not supported or"
2992 " disabled in firmware"
2994 /* MPLS over UDP, GRE is allowed */
2995 if (!(prev_layer & (MLX5_FLOW_LAYER_OUTER_L4_UDP |
2996 MLX5_FLOW_LAYER_GRE |
2997 MLX5_FLOW_LAYER_GRE_KEY)))
2998 return rte_flow_error_set(error, EINVAL,
2999 RTE_FLOW_ERROR_TYPE_ITEM, item,
3000 "protocol filtering not compatible"
3001 " with MPLS layer");
3002 /* Multi-tunnel isn't allowed but MPLS over GRE is an exception. */
3003 if ((item_flags & MLX5_FLOW_LAYER_TUNNEL) &&
3004 !(item_flags & MLX5_FLOW_LAYER_GRE))
3005 return rte_flow_error_set(error, ENOTSUP,
3006 RTE_FLOW_ERROR_TYPE_ITEM, item,
3007 "multiple tunnel layers not"
3010 mask = &rte_flow_item_mpls_mask;
3011 ret = mlx5_flow_item_acceptable
3012 (item, (const uint8_t *)mask,
3013 (const uint8_t *)&rte_flow_item_mpls_mask,
3014 sizeof(struct rte_flow_item_mpls),
3015 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
3020 return rte_flow_error_set(error, ENOTSUP,
3021 RTE_FLOW_ERROR_TYPE_ITEM, item,
3022 "MPLS is not supported by Verbs, please"
3028 * Validate NVGRE item.
3031 * Item specification.
3032 * @param[in] item_flags
3033 * Bit flags to mark detected items.
3034 * @param[in] target_protocol
3035 * The next protocol in the previous item.
3037 * Pointer to error structure.
3040 * 0 on success, a negative errno value otherwise and rte_errno is set.
3043 mlx5_flow_validate_item_nvgre(const struct rte_flow_item *item,
3044 uint64_t item_flags,
3045 uint8_t target_protocol,
3046 struct rte_flow_error *error)
3048 const struct rte_flow_item_nvgre *mask = item->mask;
3051 if (target_protocol != 0xff && target_protocol != IPPROTO_GRE)
3052 return rte_flow_error_set(error, EINVAL,
3053 RTE_FLOW_ERROR_TYPE_ITEM, item,
3054 "protocol filtering not compatible"
3055 " with this GRE layer");
3056 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
3057 return rte_flow_error_set(error, ENOTSUP,
3058 RTE_FLOW_ERROR_TYPE_ITEM, item,
3059 "multiple tunnel layers not"
3061 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3))
3062 return rte_flow_error_set(error, ENOTSUP,
3063 RTE_FLOW_ERROR_TYPE_ITEM, item,
3064 "L3 Layer is missing");
3066 mask = &rte_flow_item_nvgre_mask;
3067 ret = mlx5_flow_item_acceptable
3068 (item, (const uint8_t *)mask,
3069 (const uint8_t *)&rte_flow_item_nvgre_mask,
3070 sizeof(struct rte_flow_item_nvgre),
3071 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
3078 * Validate eCPRI item.
3081 * Item specification.
3082 * @param[in] item_flags
3083 * Bit-fields that holds the items detected until now.
3084 * @param[in] last_item
3085 * Previous validated item in the pattern items.
3086 * @param[in] ether_type
3087 * Type in the ethernet layer header (including dot1q).
3088 * @param[in] acc_mask
3089 * Acceptable mask, if NULL default internal default mask
3090 * will be used to check whether item fields are supported.
3092 * Pointer to error structure.
3095 * 0 on success, a negative errno value otherwise and rte_errno is set.
3098 mlx5_flow_validate_item_ecpri(const struct rte_flow_item *item,
3099 uint64_t item_flags,
3101 uint16_t ether_type,
3102 const struct rte_flow_item_ecpri *acc_mask,
3103 struct rte_flow_error *error)
3105 const struct rte_flow_item_ecpri *mask = item->mask;
3106 const struct rte_flow_item_ecpri nic_mask = {
3110 RTE_BE32(((const struct rte_ecpri_common_hdr) {
3114 .dummy[0] = 0xFFFFFFFF,
3117 const uint64_t outer_l2_vlan = (MLX5_FLOW_LAYER_OUTER_L2 |
3118 MLX5_FLOW_LAYER_OUTER_VLAN);
3119 struct rte_flow_item_ecpri mask_lo;
3121 if (!(last_item & outer_l2_vlan) &&
3122 last_item != MLX5_FLOW_LAYER_OUTER_L4_UDP)
3123 return rte_flow_error_set(error, EINVAL,
3124 RTE_FLOW_ERROR_TYPE_ITEM, item,
3125 "eCPRI can only follow L2/VLAN layer or UDP layer");
3126 if ((last_item & outer_l2_vlan) && ether_type &&
3127 ether_type != RTE_ETHER_TYPE_ECPRI)
3128 return rte_flow_error_set(error, EINVAL,
3129 RTE_FLOW_ERROR_TYPE_ITEM, item,
3130 "eCPRI cannot follow L2/VLAN layer which ether type is not 0xAEFE");
3131 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
3132 return rte_flow_error_set(error, EINVAL,
3133 RTE_FLOW_ERROR_TYPE_ITEM, item,
3134 "eCPRI with tunnel is not supported right now");
3135 if (item_flags & MLX5_FLOW_LAYER_OUTER_L3)
3136 return rte_flow_error_set(error, ENOTSUP,
3137 RTE_FLOW_ERROR_TYPE_ITEM, item,
3138 "multiple L3 layers not supported");
3139 else if (item_flags & MLX5_FLOW_LAYER_OUTER_L4_TCP)
3140 return rte_flow_error_set(error, EINVAL,
3141 RTE_FLOW_ERROR_TYPE_ITEM, item,
3142 "eCPRI cannot coexist with a TCP layer");
3143 /* In specification, eCPRI could be over UDP layer. */
3144 else if (item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP)
3145 return rte_flow_error_set(error, EINVAL,
3146 RTE_FLOW_ERROR_TYPE_ITEM, item,
3147 "eCPRI over UDP layer is not yet supported right now");
3148 /* Mask for type field in common header could be zero. */
3150 mask = &rte_flow_item_ecpri_mask;
3151 mask_lo.hdr.common.u32 = rte_be_to_cpu_32(mask->hdr.common.u32);
3152 /* Input mask is in big-endian format. */
3153 if (mask_lo.hdr.common.type != 0 && mask_lo.hdr.common.type != 0xff)
3154 return rte_flow_error_set(error, EINVAL,
3155 RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
3156 "partial mask is not supported for protocol");
3157 else if (mask_lo.hdr.common.type == 0 && mask->hdr.dummy[0] != 0)
3158 return rte_flow_error_set(error, EINVAL,
3159 RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
3160 "message header mask must be after a type mask");
3161 return mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
3162 acc_mask ? (const uint8_t *)acc_mask
3163 : (const uint8_t *)&nic_mask,
3164 sizeof(struct rte_flow_item_ecpri),
3165 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
3169 flow_null_validate(struct rte_eth_dev *dev __rte_unused,
3170 const struct rte_flow_attr *attr __rte_unused,
3171 const struct rte_flow_item items[] __rte_unused,
3172 const struct rte_flow_action actions[] __rte_unused,
3173 bool external __rte_unused,
3174 int hairpin __rte_unused,
3175 struct rte_flow_error *error)
3177 return rte_flow_error_set(error, ENOTSUP,
3178 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
3181 static struct mlx5_flow *
3182 flow_null_prepare(struct rte_eth_dev *dev __rte_unused,
3183 const struct rte_flow_attr *attr __rte_unused,
3184 const struct rte_flow_item items[] __rte_unused,
3185 const struct rte_flow_action actions[] __rte_unused,
3186 struct rte_flow_error *error)
3188 rte_flow_error_set(error, ENOTSUP,
3189 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
3194 flow_null_translate(struct rte_eth_dev *dev __rte_unused,
3195 struct mlx5_flow *dev_flow __rte_unused,
3196 const struct rte_flow_attr *attr __rte_unused,
3197 const struct rte_flow_item items[] __rte_unused,
3198 const struct rte_flow_action actions[] __rte_unused,
3199 struct rte_flow_error *error)
3201 return rte_flow_error_set(error, ENOTSUP,
3202 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
3206 flow_null_apply(struct rte_eth_dev *dev __rte_unused,
3207 struct rte_flow *flow __rte_unused,
3208 struct rte_flow_error *error)
3210 return rte_flow_error_set(error, ENOTSUP,
3211 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
3215 flow_null_remove(struct rte_eth_dev *dev __rte_unused,
3216 struct rte_flow *flow __rte_unused)
3221 flow_null_destroy(struct rte_eth_dev *dev __rte_unused,
3222 struct rte_flow *flow __rte_unused)
3227 flow_null_query(struct rte_eth_dev *dev __rte_unused,
3228 struct rte_flow *flow __rte_unused,
3229 const struct rte_flow_action *actions __rte_unused,
3230 void *data __rte_unused,
3231 struct rte_flow_error *error)
3233 return rte_flow_error_set(error, ENOTSUP,
3234 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
3238 flow_null_sync_domain(struct rte_eth_dev *dev __rte_unused,
3239 uint32_t domains __rte_unused,
3240 uint32_t flags __rte_unused)
3245 /* Void driver to protect from null pointer reference. */
3246 const struct mlx5_flow_driver_ops mlx5_flow_null_drv_ops = {
3247 .validate = flow_null_validate,
3248 .prepare = flow_null_prepare,
3249 .translate = flow_null_translate,
3250 .apply = flow_null_apply,
3251 .remove = flow_null_remove,
3252 .destroy = flow_null_destroy,
3253 .query = flow_null_query,
3254 .sync_domain = flow_null_sync_domain,
3258 * Select flow driver type according to flow attributes and device
3262 * Pointer to the dev structure.
3264 * Pointer to the flow attributes.
3267 * flow driver type, MLX5_FLOW_TYPE_MAX otherwise.
3269 static enum mlx5_flow_drv_type
3270 flow_get_drv_type(struct rte_eth_dev *dev, const struct rte_flow_attr *attr)
3272 struct mlx5_priv *priv = dev->data->dev_private;
3273 /* The OS can determine first a specific flow type (DV, VERBS) */
3274 enum mlx5_flow_drv_type type = mlx5_flow_os_get_type();
3276 if (type != MLX5_FLOW_TYPE_MAX)
3278 /* If no OS specific type - continue with DV/VERBS selection */
3279 if (attr->transfer && priv->config.dv_esw_en)
3280 type = MLX5_FLOW_TYPE_DV;
3281 if (!attr->transfer)
3282 type = priv->config.dv_flow_en ? MLX5_FLOW_TYPE_DV :
3283 MLX5_FLOW_TYPE_VERBS;
3287 #define flow_get_drv_ops(type) flow_drv_ops[type]
3290 * Flow driver validation API. This abstracts calling driver specific functions.
3291 * The type of flow driver is determined according to flow attributes.
3294 * Pointer to the dev structure.
3296 * Pointer to the flow attributes.
3298 * Pointer to the list of items.
3299 * @param[in] actions
3300 * Pointer to the list of actions.
3301 * @param[in] external
3302 * This flow rule is created by request external to PMD.
3303 * @param[in] hairpin
3304 * Number of hairpin TX actions, 0 means classic flow.
3306 * Pointer to the error structure.
3309 * 0 on success, a negative errno value otherwise and rte_errno is set.
3312 flow_drv_validate(struct rte_eth_dev *dev,
3313 const struct rte_flow_attr *attr,
3314 const struct rte_flow_item items[],
3315 const struct rte_flow_action actions[],
3316 bool external, int hairpin, struct rte_flow_error *error)
3318 const struct mlx5_flow_driver_ops *fops;
3319 enum mlx5_flow_drv_type type = flow_get_drv_type(dev, attr);
3321 fops = flow_get_drv_ops(type);
3322 return fops->validate(dev, attr, items, actions, external,
3327 * Flow driver preparation API. This abstracts calling driver specific
3328 * functions. Parent flow (rte_flow) should have driver type (drv_type). It
3329 * calculates the size of memory required for device flow, allocates the memory,
3330 * initializes the device flow and returns the pointer.
3333 * This function initializes device flow structure such as dv or verbs in
3334 * struct mlx5_flow. However, it is caller's responsibility to initialize the
3335 * rest. For example, adding returning device flow to flow->dev_flow list and
3336 * setting backward reference to the flow should be done out of this function.
3337 * layers field is not filled either.
3340 * Pointer to the dev structure.
3342 * Pointer to the flow attributes.
3344 * Pointer to the list of items.
3345 * @param[in] actions
3346 * Pointer to the list of actions.
3347 * @param[in] flow_idx
3348 * This memory pool index to the flow.
3350 * Pointer to the error structure.
3353 * Pointer to device flow on success, otherwise NULL and rte_errno is set.
3355 static inline struct mlx5_flow *
3356 flow_drv_prepare(struct rte_eth_dev *dev,
3357 const struct rte_flow *flow,
3358 const struct rte_flow_attr *attr,
3359 const struct rte_flow_item items[],
3360 const struct rte_flow_action actions[],
3362 struct rte_flow_error *error)
3364 const struct mlx5_flow_driver_ops *fops;
3365 enum mlx5_flow_drv_type type = flow->drv_type;
3366 struct mlx5_flow *mlx5_flow = NULL;
3368 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3369 fops = flow_get_drv_ops(type);
3370 mlx5_flow = fops->prepare(dev, attr, items, actions, error);
3372 mlx5_flow->flow_idx = flow_idx;
3377 * Flow driver translation API. This abstracts calling driver specific
3378 * functions. Parent flow (rte_flow) should have driver type (drv_type). It
3379 * translates a generic flow into a driver flow. flow_drv_prepare() must
3383 * dev_flow->layers could be filled as a result of parsing during translation
3384 * if needed by flow_drv_apply(). dev_flow->flow->actions can also be filled
3385 * if necessary. As a flow can have multiple dev_flows by RSS flow expansion,
3386 * flow->actions could be overwritten even though all the expanded dev_flows
3387 * have the same actions.
3390 * Pointer to the rte dev structure.
3391 * @param[in, out] dev_flow
3392 * Pointer to the mlx5 flow.
3394 * Pointer to the flow attributes.
3396 * Pointer to the list of items.
3397 * @param[in] actions
3398 * Pointer to the list of actions.
3400 * Pointer to the error structure.
3403 * 0 on success, a negative errno value otherwise and rte_errno is set.
3406 flow_drv_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
3407 const struct rte_flow_attr *attr,
3408 const struct rte_flow_item items[],
3409 const struct rte_flow_action actions[],
3410 struct rte_flow_error *error)
3412 const struct mlx5_flow_driver_ops *fops;
3413 enum mlx5_flow_drv_type type = dev_flow->flow->drv_type;
3415 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3416 fops = flow_get_drv_ops(type);
3417 return fops->translate(dev, dev_flow, attr, items, actions, error);
3421 * Flow driver apply API. This abstracts calling driver specific functions.
3422 * Parent flow (rte_flow) should have driver type (drv_type). It applies
3423 * translated driver flows on to device. flow_drv_translate() must precede.
3426 * Pointer to Ethernet device structure.
3427 * @param[in, out] flow
3428 * Pointer to flow structure.
3430 * Pointer to error structure.
3433 * 0 on success, a negative errno value otherwise and rte_errno is set.
3436 flow_drv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
3437 struct rte_flow_error *error)
3439 const struct mlx5_flow_driver_ops *fops;
3440 enum mlx5_flow_drv_type type = flow->drv_type;
3442 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3443 fops = flow_get_drv_ops(type);
3444 return fops->apply(dev, flow, error);
3448 * Flow driver destroy API. This abstracts calling driver specific functions.
3449 * Parent flow (rte_flow) should have driver type (drv_type). It removes a flow
3450 * on device and releases resources of the flow.
3453 * Pointer to Ethernet device.
3454 * @param[in, out] flow
3455 * Pointer to flow structure.
3458 flow_drv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
3460 const struct mlx5_flow_driver_ops *fops;
3461 enum mlx5_flow_drv_type type = flow->drv_type;
3463 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3464 fops = flow_get_drv_ops(type);
3465 fops->destroy(dev, flow);
3469 * Flow driver find RSS policy tbl API. This abstracts calling driver
3470 * specific functions. Parent flow (rte_flow) should have driver
3471 * type (drv_type). It will find the RSS policy table that has the rss_desc.
3474 * Pointer to Ethernet device.
3475 * @param[in, out] flow
3476 * Pointer to flow structure.
3478 * Pointer to meter policy table.
3479 * @param[in] rss_desc
3480 * Pointer to rss_desc
3482 static struct mlx5_flow_meter_sub_policy *
3483 flow_drv_meter_sub_policy_rss_prepare(struct rte_eth_dev *dev,
3484 struct rte_flow *flow,
3485 struct mlx5_flow_meter_policy *policy,
3486 struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS])
3488 const struct mlx5_flow_driver_ops *fops;
3489 enum mlx5_flow_drv_type type = flow->drv_type;
3491 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3492 fops = flow_get_drv_ops(type);
3493 return fops->meter_sub_policy_rss_prepare(dev, policy, rss_desc);
3497 * Flow driver color tag rule API. This abstracts calling driver
3498 * specific functions. Parent flow (rte_flow) should have driver
3499 * type (drv_type). It will create the color tag rules in hierarchy meter.
3502 * Pointer to Ethernet device.
3503 * @param[in, out] flow
3504 * Pointer to flow structure.
3506 * Pointer to flow meter structure.
3507 * @param[in] src_port
3508 * The src port this extra rule should use.
3510 * The src port id match item.
3512 * Pointer to error structure.
3515 flow_drv_mtr_hierarchy_rule_create(struct rte_eth_dev *dev,
3516 struct rte_flow *flow,
3517 struct mlx5_flow_meter_info *fm,
3519 const struct rte_flow_item *item,
3520 struct rte_flow_error *error)
3522 const struct mlx5_flow_driver_ops *fops;
3523 enum mlx5_flow_drv_type type = flow->drv_type;
3525 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3526 fops = flow_get_drv_ops(type);
3527 return fops->meter_hierarchy_rule_create(dev, fm,
3528 src_port, item, error);
3532 * Get RSS action from the action list.
3535 * Pointer to Ethernet device.
3536 * @param[in] actions
3537 * Pointer to the list of actions.
3539 * Parent flow structure pointer.
3542 * Pointer to the RSS action if exist, else return NULL.
3544 static const struct rte_flow_action_rss*
3545 flow_get_rss_action(struct rte_eth_dev *dev,
3546 const struct rte_flow_action actions[])
3548 struct mlx5_priv *priv = dev->data->dev_private;
3549 const struct rte_flow_action_rss *rss = NULL;
3551 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3552 switch (actions->type) {
3553 case RTE_FLOW_ACTION_TYPE_RSS:
3554 rss = actions->conf;
3556 case RTE_FLOW_ACTION_TYPE_SAMPLE:
3558 const struct rte_flow_action_sample *sample =
3560 const struct rte_flow_action *act = sample->actions;
3561 for (; act->type != RTE_FLOW_ACTION_TYPE_END; act++)
3562 if (act->type == RTE_FLOW_ACTION_TYPE_RSS)
3566 case RTE_FLOW_ACTION_TYPE_METER:
3569 struct mlx5_flow_meter_info *fm;
3570 struct mlx5_flow_meter_policy *policy;
3571 const struct rte_flow_action_meter *mtr = actions->conf;
3573 fm = mlx5_flow_meter_find(priv, mtr->mtr_id, &mtr_idx);
3574 if (fm && !fm->def_policy) {
3575 policy = mlx5_flow_meter_policy_find(dev,
3576 fm->policy_id, NULL);
3577 MLX5_ASSERT(policy);
3578 if (policy->is_hierarchy) {
3580 mlx5_flow_meter_hierarchy_get_final_policy(dev,
3587 policy->act_cnt[RTE_COLOR_GREEN].rss->conf;
3599 * Get ASO age action by index.
3602 * Pointer to the Ethernet device structure.
3603 * @param[in] age_idx
3604 * Index to the ASO age action.
3607 * The specified ASO age action.
3609 struct mlx5_aso_age_action*
3610 flow_aso_age_get_by_idx(struct rte_eth_dev *dev, uint32_t age_idx)
3612 uint16_t pool_idx = age_idx & UINT16_MAX;
3613 uint16_t offset = (age_idx >> 16) & UINT16_MAX;
3614 struct mlx5_priv *priv = dev->data->dev_private;
3615 struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
3616 struct mlx5_aso_age_pool *pool = mng->pools[pool_idx];
3618 return &pool->actions[offset - 1];
3621 /* maps indirect action to translated direct in some actions array */
3622 struct mlx5_translated_action_handle {
3623 struct rte_flow_action_handle *action; /**< Indirect action handle. */
3624 int index; /**< Index in related array of rte_flow_action. */
3628 * Translates actions of type RTE_FLOW_ACTION_TYPE_INDIRECT to related
3629 * direct action if translation possible.
3630 * This functionality used to run same execution path for both direct and
3631 * indirect actions on flow create. All necessary preparations for indirect
3632 * action handling should be performed on *handle* actions list returned
3636 * Pointer to Ethernet device.
3637 * @param[in] actions
3638 * List of actions to translate.
3639 * @param[out] handle
3640 * List to store translated indirect action object handles.
3641 * @param[in, out] indir_n
3642 * Size of *handle* array. On return should be updated with number of
3643 * indirect actions retrieved from the *actions* list.
3644 * @param[out] translated_actions
3645 * List of actions where all indirect actions were translated to direct
3646 * if possible. NULL if no translation took place.
3648 * Pointer to the error structure.
3651 * 0 on success, a negative errno value otherwise and rte_errno is set.
3654 flow_action_handles_translate(struct rte_eth_dev *dev,
3655 const struct rte_flow_action actions[],
3656 struct mlx5_translated_action_handle *handle,
3658 struct rte_flow_action **translated_actions,
3659 struct rte_flow_error *error)
3661 struct mlx5_priv *priv = dev->data->dev_private;
3662 struct rte_flow_action *translated = NULL;
3663 size_t actions_size;
3666 struct mlx5_translated_action_handle *handle_end = NULL;
3668 for (n = 0; actions[n].type != RTE_FLOW_ACTION_TYPE_END; n++) {
3669 if (actions[n].type != RTE_FLOW_ACTION_TYPE_INDIRECT)
3671 if (copied_n == *indir_n) {
3672 return rte_flow_error_set
3673 (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION_NUM,
3674 NULL, "too many shared actions");
3676 rte_memcpy(&handle[copied_n].action, &actions[n].conf,
3677 sizeof(actions[n].conf));
3678 handle[copied_n].index = n;
3682 *indir_n = copied_n;
3685 actions_size = sizeof(struct rte_flow_action) * n;
3686 translated = mlx5_malloc(MLX5_MEM_ZERO, actions_size, 0, SOCKET_ID_ANY);
3691 memcpy(translated, actions, actions_size);
3692 for (handle_end = handle + copied_n; handle < handle_end; handle++) {
3693 struct mlx5_shared_action_rss *shared_rss;
3694 uint32_t act_idx = (uint32_t)(uintptr_t)handle->action;
3695 uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
3696 uint32_t idx = act_idx &
3697 ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
3700 case MLX5_INDIRECT_ACTION_TYPE_RSS:
3701 shared_rss = mlx5_ipool_get
3702 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
3703 translated[handle->index].type =
3704 RTE_FLOW_ACTION_TYPE_RSS;
3705 translated[handle->index].conf =
3706 &shared_rss->origin;
3708 case MLX5_INDIRECT_ACTION_TYPE_COUNT:
3709 translated[handle->index].type =
3710 (enum rte_flow_action_type)
3711 MLX5_RTE_FLOW_ACTION_TYPE_COUNT;
3712 translated[handle->index].conf = (void *)(uintptr_t)idx;
3714 case MLX5_INDIRECT_ACTION_TYPE_AGE:
3715 if (priv->sh->flow_hit_aso_en) {
3716 translated[handle->index].type =
3717 (enum rte_flow_action_type)
3718 MLX5_RTE_FLOW_ACTION_TYPE_AGE;
3719 translated[handle->index].conf =
3720 (void *)(uintptr_t)idx;
3724 case MLX5_INDIRECT_ACTION_TYPE_CT:
3725 if (priv->sh->ct_aso_en) {
3726 translated[handle->index].type =
3727 RTE_FLOW_ACTION_TYPE_CONNTRACK;
3728 translated[handle->index].conf =
3729 (void *)(uintptr_t)idx;
3734 mlx5_free(translated);
3735 return rte_flow_error_set
3736 (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
3737 NULL, "invalid indirect action type");
3740 *translated_actions = translated;
3745 * Get Shared RSS action from the action list.
3748 * Pointer to Ethernet device.
3750 * Pointer to the list of actions.
3751 * @param[in] shared_n
3752 * Actions list length.
3755 * The MLX5 RSS action ID if exists, otherwise return 0.
3758 flow_get_shared_rss_action(struct rte_eth_dev *dev,
3759 struct mlx5_translated_action_handle *handle,
3762 struct mlx5_translated_action_handle *handle_end;
3763 struct mlx5_priv *priv = dev->data->dev_private;
3764 struct mlx5_shared_action_rss *shared_rss;
3767 for (handle_end = handle + shared_n; handle < handle_end; handle++) {
3768 uint32_t act_idx = (uint32_t)(uintptr_t)handle->action;
3769 uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
3770 uint32_t idx = act_idx &
3771 ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
3773 case MLX5_INDIRECT_ACTION_TYPE_RSS:
3774 shared_rss = mlx5_ipool_get
3775 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
3777 __atomic_add_fetch(&shared_rss->refcnt, 1,
3788 find_graph_root(uint32_t rss_level)
3790 return rss_level < 2 ? MLX5_EXPANSION_ROOT :
3791 MLX5_EXPANSION_ROOT_OUTER;
3795 * Get layer flags from the prefix flow.
3797 * Some flows may be split to several subflows, the prefix subflow gets the
3798 * match items and the suffix sub flow gets the actions.
3799 * Some actions need the user defined match item flags to get the detail for
3801 * This function helps the suffix flow to get the item layer flags from prefix
3804 * @param[in] dev_flow
3805 * Pointer the created preifx subflow.
3808 * The layers get from prefix subflow.
3810 static inline uint64_t
3811 flow_get_prefix_layer_flags(struct mlx5_flow *dev_flow)
3813 uint64_t layers = 0;
3816 * Layers bits could be localization, but usually the compiler will
3817 * help to do the optimization work for source code.
3818 * If no decap actions, use the layers directly.
3820 if (!(dev_flow->act_flags & MLX5_FLOW_ACTION_DECAP))
3821 return dev_flow->handle->layers;
3822 /* Convert L3 layers with decap action. */
3823 if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L3_IPV4)
3824 layers |= MLX5_FLOW_LAYER_OUTER_L3_IPV4;
3825 else if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L3_IPV6)
3826 layers |= MLX5_FLOW_LAYER_OUTER_L3_IPV6;
3827 /* Convert L4 layers with decap action. */
3828 if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L4_TCP)
3829 layers |= MLX5_FLOW_LAYER_OUTER_L4_TCP;
3830 else if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L4_UDP)
3831 layers |= MLX5_FLOW_LAYER_OUTER_L4_UDP;
3836 * Get metadata split action information.
3838 * @param[in] actions
3839 * Pointer to the list of actions.
3841 * Pointer to the return pointer.
3842 * @param[out] qrss_type
3843 * Pointer to the action type to return. RTE_FLOW_ACTION_TYPE_END is returned
3844 * if no QUEUE/RSS is found.
3845 * @param[out] encap_idx
3846 * Pointer to the index of the encap action if exists, otherwise the last
3850 * Total number of actions.
3853 flow_parse_metadata_split_actions_info(const struct rte_flow_action actions[],
3854 const struct rte_flow_action **qrss,
3857 const struct rte_flow_action_raw_encap *raw_encap;
3859 int raw_decap_idx = -1;
3862 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3863 switch (actions->type) {
3864 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
3865 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
3866 *encap_idx = actions_n;
3868 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
3869 raw_decap_idx = actions_n;
3871 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
3872 raw_encap = actions->conf;
3873 if (raw_encap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
3874 *encap_idx = raw_decap_idx != -1 ?
3875 raw_decap_idx : actions_n;
3877 case RTE_FLOW_ACTION_TYPE_QUEUE:
3878 case RTE_FLOW_ACTION_TYPE_RSS:
3886 if (*encap_idx == -1)
3887 *encap_idx = actions_n;
3888 /* Count RTE_FLOW_ACTION_TYPE_END. */
3889 return actions_n + 1;
3893 * Check if the action will change packet.
3896 * Pointer to Ethernet device.
3901 * true if action will change packet, false otherwise.
3903 static bool flow_check_modify_action_type(struct rte_eth_dev *dev,
3904 enum rte_flow_action_type type)
3906 struct mlx5_priv *priv = dev->data->dev_private;
3909 case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
3910 case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
3911 case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
3912 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
3913 case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
3914 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
3915 case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
3916 case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
3917 case RTE_FLOW_ACTION_TYPE_DEC_TTL:
3918 case RTE_FLOW_ACTION_TYPE_SET_TTL:
3919 case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
3920 case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
3921 case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
3922 case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
3923 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
3924 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
3925 case RTE_FLOW_ACTION_TYPE_SET_META:
3926 case RTE_FLOW_ACTION_TYPE_SET_TAG:
3927 case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
3928 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
3929 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
3930 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
3931 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
3932 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
3933 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
3934 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
3935 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
3936 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
3937 case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
3939 case RTE_FLOW_ACTION_TYPE_FLAG:
3940 case RTE_FLOW_ACTION_TYPE_MARK:
3941 if (priv->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY)
3951 * Check meter action from the action list.
3954 * Pointer to Ethernet device.
3955 * @param[in] actions
3956 * Pointer to the list of actions.
3957 * @param[out] has_mtr
3958 * Pointer to the meter exist flag.
3959 * @param[out] has_modify
3960 * Pointer to the flag showing there's packet change action.
3961 * @param[out] meter_id
3962 * Pointer to the meter id.
3965 * Total number of actions.
3968 flow_check_meter_action(struct rte_eth_dev *dev,
3969 const struct rte_flow_action actions[],
3970 bool *has_mtr, bool *has_modify, uint32_t *meter_id)
3972 const struct rte_flow_action_meter *mtr = NULL;
3975 MLX5_ASSERT(has_mtr);
3977 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3978 switch (actions->type) {
3979 case RTE_FLOW_ACTION_TYPE_METER:
3980 mtr = actions->conf;
3981 *meter_id = mtr->mtr_id;
3988 *has_modify |= flow_check_modify_action_type(dev,
3992 /* Count RTE_FLOW_ACTION_TYPE_END. */
3993 return actions_n + 1;
3997 * Check if the flow should be split due to hairpin.
3998 * The reason for the split is that in current HW we can't
3999 * support encap and push-vlan on Rx, so if a flow contains
4000 * these actions we move it to Tx.
4003 * Pointer to Ethernet device.
4005 * Flow rule attributes.
4006 * @param[in] actions
4007 * Associated actions (list terminated by the END action).
4010 * > 0 the number of actions and the flow should be split,
4011 * 0 when no split required.
4014 flow_check_hairpin_split(struct rte_eth_dev *dev,
4015 const struct rte_flow_attr *attr,
4016 const struct rte_flow_action actions[])
4018 int queue_action = 0;
4021 const struct rte_flow_action_queue *queue;
4022 const struct rte_flow_action_rss *rss;
4023 const struct rte_flow_action_raw_encap *raw_encap;
4024 const struct rte_eth_hairpin_conf *conf;
4028 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4029 switch (actions->type) {
4030 case RTE_FLOW_ACTION_TYPE_QUEUE:
4031 queue = actions->conf;
4034 conf = mlx5_rxq_get_hairpin_conf(dev, queue->index);
4035 if (conf == NULL || conf->tx_explicit != 0)
4040 case RTE_FLOW_ACTION_TYPE_RSS:
4041 rss = actions->conf;
4042 if (rss == NULL || rss->queue_num == 0)
4044 conf = mlx5_rxq_get_hairpin_conf(dev, rss->queue[0]);
4045 if (conf == NULL || conf->tx_explicit != 0)
4050 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
4051 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
4052 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
4053 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
4054 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
4058 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
4059 raw_encap = actions->conf;
4060 if (raw_encap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
4069 if (split && queue_action)
4074 /* Declare flow create/destroy prototype in advance. */
4076 flow_list_create(struct rte_eth_dev *dev, enum mlx5_flow_type type,
4077 const struct rte_flow_attr *attr,
4078 const struct rte_flow_item items[],
4079 const struct rte_flow_action actions[],
4080 bool external, struct rte_flow_error *error);
4083 flow_list_destroy(struct rte_eth_dev *dev, enum mlx5_flow_type type,
4087 flow_dv_mreg_match_cb(void *tool_ctx __rte_unused,
4088 struct mlx5_list_entry *entry, void *cb_ctx)
4090 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4091 struct mlx5_flow_mreg_copy_resource *mcp_res =
4092 container_of(entry, typeof(*mcp_res), hlist_ent);
4094 return mcp_res->mark_id != *(uint32_t *)(ctx->data);
4097 struct mlx5_list_entry *
4098 flow_dv_mreg_create_cb(void *tool_ctx, void *cb_ctx)
4100 struct rte_eth_dev *dev = tool_ctx;
4101 struct mlx5_priv *priv = dev->data->dev_private;
4102 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4103 struct mlx5_flow_mreg_copy_resource *mcp_res;
4104 struct rte_flow_error *error = ctx->error;
4107 uint32_t mark_id = *(uint32_t *)(ctx->data);
4108 struct rte_flow_attr attr = {
4109 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
4112 struct mlx5_rte_flow_item_tag tag_spec = {
4115 struct rte_flow_item items[] = {
4116 [1] = { .type = RTE_FLOW_ITEM_TYPE_END, },
4118 struct rte_flow_action_mark ftag = {
4121 struct mlx5_flow_action_copy_mreg cp_mreg = {
4125 struct rte_flow_action_jump jump = {
4126 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
4128 struct rte_flow_action actions[] = {
4129 [3] = { .type = RTE_FLOW_ACTION_TYPE_END, },
4132 /* Fill the register fileds in the flow. */
4133 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
4137 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_RX, 0, error);
4141 /* Provide the full width of FLAG specific value. */
4142 if (mark_id == (priv->sh->dv_regc0_mask & MLX5_FLOW_MARK_DEFAULT))
4143 tag_spec.data = MLX5_FLOW_MARK_DEFAULT;
4144 /* Build a new flow. */
4145 if (mark_id != MLX5_DEFAULT_COPY_ID) {
4146 items[0] = (struct rte_flow_item){
4147 .type = (enum rte_flow_item_type)
4148 MLX5_RTE_FLOW_ITEM_TYPE_TAG,
4151 items[1] = (struct rte_flow_item){
4152 .type = RTE_FLOW_ITEM_TYPE_END,
4154 actions[0] = (struct rte_flow_action){
4155 .type = (enum rte_flow_action_type)
4156 MLX5_RTE_FLOW_ACTION_TYPE_MARK,
4159 actions[1] = (struct rte_flow_action){
4160 .type = (enum rte_flow_action_type)
4161 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
4164 actions[2] = (struct rte_flow_action){
4165 .type = RTE_FLOW_ACTION_TYPE_JUMP,
4168 actions[3] = (struct rte_flow_action){
4169 .type = RTE_FLOW_ACTION_TYPE_END,
4172 /* Default rule, wildcard match. */
4173 attr.priority = MLX5_FLOW_LOWEST_PRIO_INDICATOR;
4174 items[0] = (struct rte_flow_item){
4175 .type = RTE_FLOW_ITEM_TYPE_END,
4177 actions[0] = (struct rte_flow_action){
4178 .type = (enum rte_flow_action_type)
4179 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
4182 actions[1] = (struct rte_flow_action){
4183 .type = RTE_FLOW_ACTION_TYPE_JUMP,
4186 actions[2] = (struct rte_flow_action){
4187 .type = RTE_FLOW_ACTION_TYPE_END,
4190 /* Build a new entry. */
4191 mcp_res = mlx5_ipool_zmalloc(priv->sh->ipool[MLX5_IPOOL_MCP], &idx);
4197 mcp_res->mark_id = mark_id;
4199 * The copy Flows are not included in any list. There
4200 * ones are referenced from other Flows and can not
4201 * be applied, removed, deleted in ardbitrary order
4202 * by list traversing.
4204 mcp_res->rix_flow = flow_list_create(dev, MLX5_FLOW_TYPE_MCP,
4205 &attr, items, actions, false, error);
4206 if (!mcp_res->rix_flow) {
4207 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], idx);
4210 return &mcp_res->hlist_ent;
4213 struct mlx5_list_entry *
4214 flow_dv_mreg_clone_cb(void *tool_ctx, struct mlx5_list_entry *oentry,
4215 void *cb_ctx __rte_unused)
4217 struct rte_eth_dev *dev = tool_ctx;
4218 struct mlx5_priv *priv = dev->data->dev_private;
4219 struct mlx5_flow_mreg_copy_resource *mcp_res;
4222 mcp_res = mlx5_ipool_malloc(priv->sh->ipool[MLX5_IPOOL_MCP], &idx);
4227 memcpy(mcp_res, oentry, sizeof(*mcp_res));
4229 return &mcp_res->hlist_ent;
4233 flow_dv_mreg_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
4235 struct mlx5_flow_mreg_copy_resource *mcp_res =
4236 container_of(entry, typeof(*mcp_res), hlist_ent);
4237 struct rte_eth_dev *dev = tool_ctx;
4238 struct mlx5_priv *priv = dev->data->dev_private;
4240 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], mcp_res->idx);
4244 * Add a flow of copying flow metadata registers in RX_CP_TBL.
4246 * As mark_id is unique, if there's already a registered flow for the mark_id,
4247 * return by increasing the reference counter of the resource. Otherwise, create
4248 * the resource (mcp_res) and flow.
4251 * - If ingress port is ANY and reg_c[1] is mark_id,
4252 * flow_tag := mark_id, reg_b := reg_c[0] and jump to RX_ACT_TBL.
4254 * For default flow (zero mark_id), flow is like,
4255 * - If ingress port is ANY,
4256 * reg_b := reg_c[0] and jump to RX_ACT_TBL.
4259 * Pointer to Ethernet device.
4261 * ID of MARK action, zero means default flow for META.
4263 * Perform verbose error reporting if not NULL.
4266 * Associated resource on success, NULL otherwise and rte_errno is set.
4268 static struct mlx5_flow_mreg_copy_resource *
4269 flow_mreg_add_copy_action(struct rte_eth_dev *dev, uint32_t mark_id,
4270 struct rte_flow_error *error)
4272 struct mlx5_priv *priv = dev->data->dev_private;
4273 struct mlx5_list_entry *entry;
4274 struct mlx5_flow_cb_ctx ctx = {
4280 /* Check if already registered. */
4281 MLX5_ASSERT(priv->mreg_cp_tbl);
4282 entry = mlx5_hlist_register(priv->mreg_cp_tbl, mark_id, &ctx);
4285 return container_of(entry, struct mlx5_flow_mreg_copy_resource,
4290 flow_dv_mreg_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
4292 struct mlx5_flow_mreg_copy_resource *mcp_res =
4293 container_of(entry, typeof(*mcp_res), hlist_ent);
4294 struct rte_eth_dev *dev = tool_ctx;
4295 struct mlx5_priv *priv = dev->data->dev_private;
4297 MLX5_ASSERT(mcp_res->rix_flow);
4298 flow_list_destroy(dev, MLX5_FLOW_TYPE_MCP, mcp_res->rix_flow);
4299 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], mcp_res->idx);
4303 * Release flow in RX_CP_TBL.
4306 * Pointer to Ethernet device.
4308 * Parent flow for wich copying is provided.
4311 flow_mreg_del_copy_action(struct rte_eth_dev *dev,
4312 struct rte_flow *flow)
4314 struct mlx5_flow_mreg_copy_resource *mcp_res;
4315 struct mlx5_priv *priv = dev->data->dev_private;
4317 if (!flow->rix_mreg_copy)
4319 mcp_res = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MCP],
4320 flow->rix_mreg_copy);
4321 if (!mcp_res || !priv->mreg_cp_tbl)
4323 MLX5_ASSERT(mcp_res->rix_flow);
4324 mlx5_hlist_unregister(priv->mreg_cp_tbl, &mcp_res->hlist_ent);
4325 flow->rix_mreg_copy = 0;
4329 * Remove the default copy action from RX_CP_TBL.
4331 * This functions is called in the mlx5_dev_start(). No thread safe
4335 * Pointer to Ethernet device.
4338 flow_mreg_del_default_copy_action(struct rte_eth_dev *dev)
4340 struct mlx5_list_entry *entry;
4341 struct mlx5_priv *priv = dev->data->dev_private;
4342 struct mlx5_flow_cb_ctx ctx;
4345 /* Check if default flow is registered. */
4346 if (!priv->mreg_cp_tbl)
4348 mark_id = MLX5_DEFAULT_COPY_ID;
4349 ctx.data = &mark_id;
4350 entry = mlx5_hlist_lookup(priv->mreg_cp_tbl, mark_id, &ctx);
4353 mlx5_hlist_unregister(priv->mreg_cp_tbl, entry);
4357 * Add the default copy action in in RX_CP_TBL.
4359 * This functions is called in the mlx5_dev_start(). No thread safe
4363 * Pointer to Ethernet device.
4365 * Perform verbose error reporting if not NULL.
4368 * 0 for success, negative value otherwise and rte_errno is set.
4371 flow_mreg_add_default_copy_action(struct rte_eth_dev *dev,
4372 struct rte_flow_error *error)
4374 struct mlx5_priv *priv = dev->data->dev_private;
4375 struct mlx5_flow_mreg_copy_resource *mcp_res;
4376 struct mlx5_flow_cb_ctx ctx;
4379 /* Check whether extensive metadata feature is engaged. */
4380 if (!priv->config.dv_flow_en ||
4381 priv->config.dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
4382 !mlx5_flow_ext_mreg_supported(dev) ||
4383 !priv->sh->dv_regc0_mask)
4386 * Add default mreg copy flow may be called multiple time, but
4387 * only be called once in stop. Avoid register it twice.
4389 mark_id = MLX5_DEFAULT_COPY_ID;
4390 ctx.data = &mark_id;
4391 if (mlx5_hlist_lookup(priv->mreg_cp_tbl, mark_id, &ctx))
4393 mcp_res = flow_mreg_add_copy_action(dev, mark_id, error);
4400 * Add a flow of copying flow metadata registers in RX_CP_TBL.
4402 * All the flow having Q/RSS action should be split by
4403 * flow_mreg_split_qrss_prep() to pass by RX_CP_TBL. A flow in the RX_CP_TBL
4404 * performs the following,
4405 * - CQE->flow_tag := reg_c[1] (MARK)
4406 * - CQE->flow_table_metadata (reg_b) := reg_c[0] (META)
4407 * As CQE's flow_tag is not a register, it can't be simply copied from reg_c[1]
4408 * but there should be a flow per each MARK ID set by MARK action.
4410 * For the aforementioned reason, if there's a MARK action in flow's action
4411 * list, a corresponding flow should be added to the RX_CP_TBL in order to copy
4412 * the MARK ID to CQE's flow_tag like,
4413 * - If reg_c[1] is mark_id,
4414 * flow_tag := mark_id, reg_b := reg_c[0] and jump to RX_ACT_TBL.
4416 * For SET_META action which stores value in reg_c[0], as the destination is
4417 * also a flow metadata register (reg_b), adding a default flow is enough. Zero
4418 * MARK ID means the default flow. The default flow looks like,
4419 * - For all flow, reg_b := reg_c[0] and jump to RX_ACT_TBL.
4422 * Pointer to Ethernet device.
4424 * Pointer to flow structure.
4425 * @param[in] actions
4426 * Pointer to the list of actions.
4428 * Perform verbose error reporting if not NULL.
4431 * 0 on success, negative value otherwise and rte_errno is set.
4434 flow_mreg_update_copy_table(struct rte_eth_dev *dev,
4435 struct rte_flow *flow,
4436 const struct rte_flow_action *actions,
4437 struct rte_flow_error *error)
4439 struct mlx5_priv *priv = dev->data->dev_private;
4440 struct mlx5_dev_config *config = &priv->config;
4441 struct mlx5_flow_mreg_copy_resource *mcp_res;
4442 const struct rte_flow_action_mark *mark;
4444 /* Check whether extensive metadata feature is engaged. */
4445 if (!config->dv_flow_en ||
4446 config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
4447 !mlx5_flow_ext_mreg_supported(dev) ||
4448 !priv->sh->dv_regc0_mask)
4450 /* Find MARK action. */
4451 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4452 switch (actions->type) {
4453 case RTE_FLOW_ACTION_TYPE_FLAG:
4454 mcp_res = flow_mreg_add_copy_action
4455 (dev, MLX5_FLOW_MARK_DEFAULT, error);
4458 flow->rix_mreg_copy = mcp_res->idx;
4460 case RTE_FLOW_ACTION_TYPE_MARK:
4461 mark = (const struct rte_flow_action_mark *)
4464 flow_mreg_add_copy_action(dev, mark->id, error);
4467 flow->rix_mreg_copy = mcp_res->idx;
4476 #define MLX5_MAX_SPLIT_ACTIONS 24
4477 #define MLX5_MAX_SPLIT_ITEMS 24
4480 * Split the hairpin flow.
4481 * Since HW can't support encap and push-vlan on Rx, we move these
4483 * If the count action is after the encap then we also
4484 * move the count action. in this case the count will also measure
4488 * Pointer to Ethernet device.
4489 * @param[in] actions
4490 * Associated actions (list terminated by the END action).
4491 * @param[out] actions_rx
4493 * @param[out] actions_tx
4495 * @param[out] pattern_tx
4496 * The pattern items for the Tx flow.
4497 * @param[out] flow_id
4498 * The flow ID connected to this flow.
4504 flow_hairpin_split(struct rte_eth_dev *dev,
4505 const struct rte_flow_action actions[],
4506 struct rte_flow_action actions_rx[],
4507 struct rte_flow_action actions_tx[],
4508 struct rte_flow_item pattern_tx[],
4511 const struct rte_flow_action_raw_encap *raw_encap;
4512 const struct rte_flow_action_raw_decap *raw_decap;
4513 struct mlx5_rte_flow_action_set_tag *set_tag;
4514 struct rte_flow_action *tag_action;
4515 struct mlx5_rte_flow_item_tag *tag_item;
4516 struct rte_flow_item *item;
4520 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4521 switch (actions->type) {
4522 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
4523 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
4524 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
4525 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
4526 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
4527 rte_memcpy(actions_tx, actions,
4528 sizeof(struct rte_flow_action));
4531 case RTE_FLOW_ACTION_TYPE_COUNT:
4533 rte_memcpy(actions_tx, actions,
4534 sizeof(struct rte_flow_action));
4537 rte_memcpy(actions_rx, actions,
4538 sizeof(struct rte_flow_action));
4542 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
4543 raw_encap = actions->conf;
4544 if (raw_encap->size > MLX5_ENCAPSULATION_DECISION_SIZE) {
4545 memcpy(actions_tx, actions,
4546 sizeof(struct rte_flow_action));
4550 rte_memcpy(actions_rx, actions,
4551 sizeof(struct rte_flow_action));
4555 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
4556 raw_decap = actions->conf;
4557 if (raw_decap->size < MLX5_ENCAPSULATION_DECISION_SIZE) {
4558 memcpy(actions_tx, actions,
4559 sizeof(struct rte_flow_action));
4562 rte_memcpy(actions_rx, actions,
4563 sizeof(struct rte_flow_action));
4568 rte_memcpy(actions_rx, actions,
4569 sizeof(struct rte_flow_action));
4574 /* Add set meta action and end action for the Rx flow. */
4575 tag_action = actions_rx;
4576 tag_action->type = (enum rte_flow_action_type)
4577 MLX5_RTE_FLOW_ACTION_TYPE_TAG;
4579 rte_memcpy(actions_rx, actions, sizeof(struct rte_flow_action));
4581 set_tag = (void *)actions_rx;
4582 *set_tag = (struct mlx5_rte_flow_action_set_tag) {
4583 .id = mlx5_flow_get_reg_id(dev, MLX5_HAIRPIN_RX, 0, NULL),
4586 MLX5_ASSERT(set_tag->id > REG_NON);
4587 tag_action->conf = set_tag;
4588 /* Create Tx item list. */
4589 rte_memcpy(actions_tx, actions, sizeof(struct rte_flow_action));
4590 addr = (void *)&pattern_tx[2];
4592 item->type = (enum rte_flow_item_type)
4593 MLX5_RTE_FLOW_ITEM_TYPE_TAG;
4594 tag_item = (void *)addr;
4595 tag_item->data = flow_id;
4596 tag_item->id = mlx5_flow_get_reg_id(dev, MLX5_HAIRPIN_TX, 0, NULL);
4597 MLX5_ASSERT(set_tag->id > REG_NON);
4598 item->spec = tag_item;
4599 addr += sizeof(struct mlx5_rte_flow_item_tag);
4600 tag_item = (void *)addr;
4601 tag_item->data = UINT32_MAX;
4602 tag_item->id = UINT16_MAX;
4603 item->mask = tag_item;
4606 item->type = RTE_FLOW_ITEM_TYPE_END;
4611 * The last stage of splitting chain, just creates the subflow
4612 * without any modification.
4615 * Pointer to Ethernet device.
4617 * Parent flow structure pointer.
4618 * @param[in, out] sub_flow
4619 * Pointer to return the created subflow, may be NULL.
4621 * Flow rule attributes.
4623 * Pattern specification (list terminated by the END pattern item).
4624 * @param[in] actions
4625 * Associated actions (list terminated by the END action).
4626 * @param[in] flow_split_info
4627 * Pointer to flow split info structure.
4629 * Perform verbose error reporting if not NULL.
4631 * 0 on success, negative value otherwise
4634 flow_create_split_inner(struct rte_eth_dev *dev,
4635 struct rte_flow *flow,
4636 struct mlx5_flow **sub_flow,
4637 const struct rte_flow_attr *attr,
4638 const struct rte_flow_item items[],
4639 const struct rte_flow_action actions[],
4640 struct mlx5_flow_split_info *flow_split_info,
4641 struct rte_flow_error *error)
4643 struct mlx5_flow *dev_flow;
4645 dev_flow = flow_drv_prepare(dev, flow, attr, items, actions,
4646 flow_split_info->flow_idx, error);
4649 dev_flow->flow = flow;
4650 dev_flow->external = flow_split_info->external;
4651 dev_flow->skip_scale = flow_split_info->skip_scale;
4652 /* Subflow object was created, we must include one in the list. */
4653 SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
4654 dev_flow->handle, next);
4656 * If dev_flow is as one of the suffix flow, some actions in suffix
4657 * flow may need some user defined item layer flags, and pass the
4658 * Metadate rxq mark flag to suffix flow as well.
4660 if (flow_split_info->prefix_layers)
4661 dev_flow->handle->layers = flow_split_info->prefix_layers;
4662 if (flow_split_info->prefix_mark)
4663 dev_flow->handle->mark = 1;
4665 *sub_flow = dev_flow;
4666 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
4667 dev_flow->dv.table_id = flow_split_info->table_id;
4669 return flow_drv_translate(dev, dev_flow, attr, items, actions, error);
4673 * Get the sub policy of a meter.
4676 * Pointer to Ethernet device.
4678 * Parent flow structure pointer.
4680 * Pointer to thread flow work space.
4682 * Flow rule attributes.
4684 * Pattern specification (list terminated by the END pattern item).
4686 * Perform verbose error reporting if not NULL.
4689 * Pointer to the meter sub policy, NULL otherwise and rte_errno is set.
4691 static struct mlx5_flow_meter_sub_policy *
4692 get_meter_sub_policy(struct rte_eth_dev *dev,
4693 struct rte_flow *flow,
4694 struct mlx5_flow_workspace *wks,
4695 const struct rte_flow_attr *attr,
4696 const struct rte_flow_item items[],
4697 struct rte_flow_error *error)
4699 struct mlx5_flow_meter_policy *policy;
4700 struct mlx5_flow_meter_policy *final_policy;
4701 struct mlx5_flow_meter_sub_policy *sub_policy = NULL;
4703 policy = wks->policy;
4704 final_policy = policy->is_hierarchy ? wks->final_policy : policy;
4705 if (final_policy->is_rss || final_policy->is_queue) {
4706 struct mlx5_flow_rss_desc rss_desc_v[MLX5_MTR_RTE_COLORS];
4707 struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS] = {0};
4711 * This is a tmp dev_flow,
4712 * no need to register any matcher for it in translate.
4714 wks->skip_matcher_reg = 1;
4715 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
4716 struct mlx5_flow dev_flow = {0};
4717 struct mlx5_flow_handle dev_handle = { {0} };
4718 uint8_t fate = final_policy->act_cnt[i].fate_action;
4720 if (fate == MLX5_FLOW_FATE_SHARED_RSS) {
4721 const struct rte_flow_action_rss *rss_act =
4722 final_policy->act_cnt[i].rss->conf;
4723 struct rte_flow_action rss_actions[2] = {
4725 .type = RTE_FLOW_ACTION_TYPE_RSS,
4729 .type = RTE_FLOW_ACTION_TYPE_END,
4734 dev_flow.handle = &dev_handle;
4735 dev_flow.ingress = attr->ingress;
4736 dev_flow.flow = flow;
4737 dev_flow.external = 0;
4738 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
4739 dev_flow.dv.transfer = attr->transfer;
4742 * Translate RSS action to get rss hash fields.
4744 if (flow_drv_translate(dev, &dev_flow, attr,
4745 items, rss_actions, error))
4747 rss_desc_v[i] = wks->rss_desc;
4748 rss_desc_v[i].key_len = MLX5_RSS_HASH_KEY_LEN;
4749 rss_desc_v[i].hash_fields =
4750 dev_flow.hash_fields;
4751 rss_desc_v[i].queue_num =
4752 rss_desc_v[i].hash_fields ?
4753 rss_desc_v[i].queue_num : 1;
4754 rss_desc_v[i].tunnel =
4755 !!(dev_flow.handle->layers &
4756 MLX5_FLOW_LAYER_TUNNEL);
4757 /* Use the RSS queues in the containers. */
4758 rss_desc_v[i].queue =
4759 (uint16_t *)(uintptr_t)rss_act->queue;
4760 rss_desc[i] = &rss_desc_v[i];
4761 } else if (fate == MLX5_FLOW_FATE_QUEUE) {
4762 /* This is queue action. */
4763 rss_desc_v[i] = wks->rss_desc;
4764 rss_desc_v[i].key_len = 0;
4765 rss_desc_v[i].hash_fields = 0;
4766 rss_desc_v[i].queue =
4767 &final_policy->act_cnt[i].queue;
4768 rss_desc_v[i].queue_num = 1;
4769 rss_desc[i] = &rss_desc_v[i];
4774 sub_policy = flow_drv_meter_sub_policy_rss_prepare(dev,
4775 flow, policy, rss_desc);
4777 enum mlx5_meter_domain mtr_domain =
4778 attr->transfer ? MLX5_MTR_DOMAIN_TRANSFER :
4779 (attr->egress ? MLX5_MTR_DOMAIN_EGRESS :
4780 MLX5_MTR_DOMAIN_INGRESS);
4781 sub_policy = policy->sub_policys[mtr_domain][0];
4784 rte_flow_error_set(error, EINVAL,
4785 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4786 "Failed to get meter sub-policy.");
4792 * Split the meter flow.
4794 * As meter flow will split to three sub flow, other than meter
4795 * action, the other actions make sense to only meter accepts
4796 * the packet. If it need to be dropped, no other additional
4797 * actions should be take.
4799 * One kind of special action which decapsulates the L3 tunnel
4800 * header will be in the prefix sub flow, as not to take the
4801 * L3 tunnel header into account.
4804 * Pointer to Ethernet device.
4806 * Parent flow structure pointer.
4808 * Pointer to thread flow work space.
4810 * Flow rule attributes.
4812 * Pattern specification (list terminated by the END pattern item).
4813 * @param[out] sfx_items
4814 * Suffix flow match items (list terminated by the END pattern item).
4815 * @param[in] actions
4816 * Associated actions (list terminated by the END action).
4817 * @param[out] actions_sfx
4818 * Suffix flow actions.
4819 * @param[out] actions_pre
4820 * Prefix flow actions.
4821 * @param[out] mtr_flow_id
4822 * Pointer to meter flow id.
4824 * Perform verbose error reporting if not NULL.
4827 * 0 on success, a negative errno value otherwise and rte_errno is set.
4830 flow_meter_split_prep(struct rte_eth_dev *dev,
4831 struct rte_flow *flow,
4832 struct mlx5_flow_workspace *wks,
4833 const struct rte_flow_attr *attr,
4834 const struct rte_flow_item items[],
4835 struct rte_flow_item sfx_items[],
4836 const struct rte_flow_action actions[],
4837 struct rte_flow_action actions_sfx[],
4838 struct rte_flow_action actions_pre[],
4839 uint32_t *mtr_flow_id,
4840 struct rte_flow_error *error)
4842 struct mlx5_priv *priv = dev->data->dev_private;
4843 struct mlx5_flow_meter_info *fm = wks->fm;
4844 struct rte_flow_action *tag_action = NULL;
4845 struct rte_flow_item *tag_item;
4846 struct mlx5_rte_flow_action_set_tag *set_tag;
4847 const struct rte_flow_action_raw_encap *raw_encap;
4848 const struct rte_flow_action_raw_decap *raw_decap;
4849 struct mlx5_rte_flow_item_tag *tag_item_spec;
4850 struct mlx5_rte_flow_item_tag *tag_item_mask;
4851 uint32_t tag_id = 0;
4852 struct rte_flow_item *vlan_item_dst = NULL;
4853 const struct rte_flow_item *vlan_item_src = NULL;
4854 struct rte_flow_action *hw_mtr_action;
4855 struct rte_flow_action *action_pre_head = NULL;
4856 int32_t flow_src_port = priv->representor_id;
4858 uint8_t mtr_id_offset = priv->mtr_reg_share ? MLX5_MTR_COLOR_BITS : 0;
4859 uint8_t mtr_reg_bits = priv->mtr_reg_share ?
4860 MLX5_MTR_IDLE_BITS_IN_COLOR_REG : MLX5_REG_BITS;
4861 uint32_t flow_id = 0;
4862 uint32_t flow_id_reversed = 0;
4863 uint8_t flow_id_bits = 0;
4866 /* Prepare the suffix subflow items. */
4867 tag_item = sfx_items++;
4868 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
4869 struct mlx5_priv *port_priv;
4870 const struct rte_flow_item_port_id *pid_v;
4871 int item_type = items->type;
4873 switch (item_type) {
4874 case RTE_FLOW_ITEM_TYPE_PORT_ID:
4875 pid_v = items->spec;
4877 port_priv = mlx5_port_to_eswitch_info(pid_v->id, false);
4879 return rte_flow_error_set(error,
4881 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
4883 "Failed to get port info.");
4884 flow_src_port = port_priv->representor_id;
4885 if (!fm->def_policy && wks->policy->is_hierarchy &&
4886 flow_src_port != priv->representor_id) {
4887 if (flow_drv_mtr_hierarchy_rule_create(dev,
4894 memcpy(sfx_items, items, sizeof(*sfx_items));
4897 case RTE_FLOW_ITEM_TYPE_VLAN:
4898 /* Determine if copy vlan item below. */
4899 vlan_item_src = items;
4900 vlan_item_dst = sfx_items++;
4901 vlan_item_dst->type = RTE_FLOW_ITEM_TYPE_VOID;
4907 sfx_items->type = RTE_FLOW_ITEM_TYPE_END;
4909 mtr_first = priv->sh->meter_aso_en &&
4910 (attr->egress || (attr->transfer && flow_src_port != UINT16_MAX));
4911 /* For ASO meter, meter must be before tag in TX direction. */
4913 action_pre_head = actions_pre++;
4914 /* Leave space for tag action. */
4915 tag_action = actions_pre++;
4917 /* Prepare the actions for prefix and suffix flow. */
4918 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4919 struct rte_flow_action *action_cur = NULL;
4921 switch (actions->type) {
4922 case RTE_FLOW_ACTION_TYPE_METER:
4924 action_cur = action_pre_head;
4926 /* Leave space for tag action. */
4927 tag_action = actions_pre++;
4928 action_cur = actions_pre++;
4931 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
4932 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
4933 action_cur = actions_pre++;
4935 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
4936 raw_encap = actions->conf;
4937 if (raw_encap->size < MLX5_ENCAPSULATION_DECISION_SIZE)
4938 action_cur = actions_pre++;
4940 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
4941 raw_decap = actions->conf;
4942 if (raw_decap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
4943 action_cur = actions_pre++;
4945 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
4946 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
4947 if (vlan_item_dst && vlan_item_src) {
4948 memcpy(vlan_item_dst, vlan_item_src,
4949 sizeof(*vlan_item_dst));
4951 * Convert to internal match item, it is used
4952 * for vlan push and set vid.
4954 vlan_item_dst->type = (enum rte_flow_item_type)
4955 MLX5_RTE_FLOW_ITEM_TYPE_VLAN;
4962 action_cur = (fm->def_policy) ?
4963 actions_sfx++ : actions_pre++;
4964 memcpy(action_cur, actions, sizeof(struct rte_flow_action));
4966 /* Add end action to the actions. */
4967 actions_sfx->type = RTE_FLOW_ACTION_TYPE_END;
4968 if (priv->sh->meter_aso_en) {
4970 * For ASO meter, need to add an extra jump action explicitly,
4971 * to jump from meter to policer table.
4973 struct mlx5_flow_meter_sub_policy *sub_policy;
4974 struct mlx5_flow_tbl_data_entry *tbl_data;
4976 if (!fm->def_policy) {
4977 sub_policy = get_meter_sub_policy(dev, flow, wks,
4978 attr, items, error);
4982 enum mlx5_meter_domain mtr_domain =
4983 attr->transfer ? MLX5_MTR_DOMAIN_TRANSFER :
4984 (attr->egress ? MLX5_MTR_DOMAIN_EGRESS :
4985 MLX5_MTR_DOMAIN_INGRESS);
4988 &priv->sh->mtrmng->def_policy[mtr_domain]->sub_policy;
4990 tbl_data = container_of(sub_policy->tbl_rsc,
4991 struct mlx5_flow_tbl_data_entry, tbl);
4992 hw_mtr_action = actions_pre++;
4993 hw_mtr_action->type = (enum rte_flow_action_type)
4994 MLX5_RTE_FLOW_ACTION_TYPE_JUMP;
4995 hw_mtr_action->conf = tbl_data->jump.action;
4997 actions_pre->type = RTE_FLOW_ACTION_TYPE_END;
5000 return rte_flow_error_set(error, ENOMEM,
5001 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5002 NULL, "No tag action space.");
5004 tag_action->type = RTE_FLOW_ACTION_TYPE_VOID;
5007 /* Only default-policy Meter creates mtr flow id. */
5008 if (fm->def_policy) {
5009 mlx5_ipool_malloc(fm->flow_ipool, &tag_id);
5011 return rte_flow_error_set(error, ENOMEM,
5012 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
5013 "Failed to allocate meter flow id.");
5014 flow_id = tag_id - 1;
5015 flow_id_bits = (!flow_id) ? 1 :
5016 (MLX5_REG_BITS - __builtin_clz(flow_id));
5017 if ((flow_id_bits + priv->sh->mtrmng->max_mtr_bits) >
5019 mlx5_ipool_free(fm->flow_ipool, tag_id);
5020 return rte_flow_error_set(error, EINVAL,
5021 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
5022 "Meter flow id exceeds max limit.");
5024 if (flow_id_bits > priv->sh->mtrmng->max_mtr_flow_bits)
5025 priv->sh->mtrmng->max_mtr_flow_bits = flow_id_bits;
5027 /* Build tag actions and items for meter_id/meter flow_id. */
5028 set_tag = (struct mlx5_rte_flow_action_set_tag *)actions_pre;
5029 tag_item_spec = (struct mlx5_rte_flow_item_tag *)sfx_items;
5030 tag_item_mask = tag_item_spec + 1;
5031 /* Both flow_id and meter_id share the same register. */
5032 *set_tag = (struct mlx5_rte_flow_action_set_tag) {
5033 .id = (enum modify_reg)mlx5_flow_get_reg_id(dev, MLX5_MTR_ID,
5035 .offset = mtr_id_offset,
5036 .length = mtr_reg_bits,
5037 .data = flow->meter,
5040 * The color Reg bits used by flow_id are growing from
5041 * msb to lsb, so must do bit reverse for flow_id val in RegC.
5043 for (shift = 0; shift < flow_id_bits; shift++)
5044 flow_id_reversed = (flow_id_reversed << 1) |
5045 ((flow_id >> shift) & 0x1);
5047 flow_id_reversed << (mtr_reg_bits - flow_id_bits);
5048 tag_item_spec->id = set_tag->id;
5049 tag_item_spec->data = set_tag->data << mtr_id_offset;
5050 tag_item_mask->data = UINT32_MAX << mtr_id_offset;
5051 tag_action->type = (enum rte_flow_action_type)
5052 MLX5_RTE_FLOW_ACTION_TYPE_TAG;
5053 tag_action->conf = set_tag;
5054 tag_item->type = (enum rte_flow_item_type)
5055 MLX5_RTE_FLOW_ITEM_TYPE_TAG;
5056 tag_item->spec = tag_item_spec;
5057 tag_item->last = NULL;
5058 tag_item->mask = tag_item_mask;
5061 *mtr_flow_id = tag_id;
5066 * Split action list having QUEUE/RSS for metadata register copy.
5068 * Once Q/RSS action is detected in user's action list, the flow action
5069 * should be split in order to copy metadata registers, which will happen in
5071 * - CQE->flow_tag := reg_c[1] (MARK)
5072 * - CQE->flow_table_metadata (reg_b) := reg_c[0] (META)
5073 * The Q/RSS action will be performed on RX_ACT_TBL after passing by RX_CP_TBL.
5074 * This is because the last action of each flow must be a terminal action
5075 * (QUEUE, RSS or DROP).
5077 * Flow ID must be allocated to identify actions in the RX_ACT_TBL and it is
5078 * stored and kept in the mlx5_flow structure per each sub_flow.
5080 * The Q/RSS action is replaced with,
5081 * - SET_TAG, setting the allocated flow ID to reg_c[2].
5082 * And the following JUMP action is added at the end,
5083 * - JUMP, to RX_CP_TBL.
5085 * A flow to perform remained Q/RSS action will be created in RX_ACT_TBL by
5086 * flow_create_split_metadata() routine. The flow will look like,
5087 * - If flow ID matches (reg_c[2]), perform Q/RSS.
5090 * Pointer to Ethernet device.
5091 * @param[out] split_actions
5092 * Pointer to store split actions to jump to CP_TBL.
5093 * @param[in] actions
5094 * Pointer to the list of original flow actions.
5096 * Pointer to the Q/RSS action.
5097 * @param[in] actions_n
5098 * Number of original actions.
5100 * Perform verbose error reporting if not NULL.
5103 * non-zero unique flow_id on success, otherwise 0 and
5104 * error/rte_error are set.
5107 flow_mreg_split_qrss_prep(struct rte_eth_dev *dev,
5108 struct rte_flow_action *split_actions,
5109 const struct rte_flow_action *actions,
5110 const struct rte_flow_action *qrss,
5111 int actions_n, struct rte_flow_error *error)
5113 struct mlx5_priv *priv = dev->data->dev_private;
5114 struct mlx5_rte_flow_action_set_tag *set_tag;
5115 struct rte_flow_action_jump *jump;
5116 const int qrss_idx = qrss - actions;
5117 uint32_t flow_id = 0;
5121 * Given actions will be split
5122 * - Replace QUEUE/RSS action with SET_TAG to set flow ID.
5123 * - Add jump to mreg CP_TBL.
5124 * As a result, there will be one more action.
5127 memcpy(split_actions, actions, sizeof(*split_actions) * actions_n);
5128 set_tag = (void *)(split_actions + actions_n);
5130 * If tag action is not set to void(it means we are not the meter
5131 * suffix flow), add the tag action. Since meter suffix flow already
5132 * has the tag added.
5134 if (split_actions[qrss_idx].type != RTE_FLOW_ACTION_TYPE_VOID) {
5136 * Allocate the new subflow ID. This one is unique within
5137 * device and not shared with representors. Otherwise,
5138 * we would have to resolve multi-thread access synch
5139 * issue. Each flow on the shared device is appended
5140 * with source vport identifier, so the resulting
5141 * flows will be unique in the shared (by master and
5142 * representors) domain even if they have coinciding
5145 mlx5_ipool_malloc(priv->sh->ipool
5146 [MLX5_IPOOL_RSS_EXPANTION_FLOW_ID], &flow_id);
5148 return rte_flow_error_set(error, ENOMEM,
5149 RTE_FLOW_ERROR_TYPE_ACTION,
5150 NULL, "can't allocate id "
5151 "for split Q/RSS subflow");
5152 /* Internal SET_TAG action to set flow ID. */
5153 *set_tag = (struct mlx5_rte_flow_action_set_tag){
5156 ret = mlx5_flow_get_reg_id(dev, MLX5_COPY_MARK, 0, error);
5160 /* Construct new actions array. */
5161 /* Replace QUEUE/RSS action. */
5162 split_actions[qrss_idx] = (struct rte_flow_action){
5163 .type = (enum rte_flow_action_type)
5164 MLX5_RTE_FLOW_ACTION_TYPE_TAG,
5168 /* JUMP action to jump to mreg copy table (CP_TBL). */
5169 jump = (void *)(set_tag + 1);
5170 *jump = (struct rte_flow_action_jump){
5171 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
5173 split_actions[actions_n - 2] = (struct rte_flow_action){
5174 .type = RTE_FLOW_ACTION_TYPE_JUMP,
5177 split_actions[actions_n - 1] = (struct rte_flow_action){
5178 .type = RTE_FLOW_ACTION_TYPE_END,
5184 * Extend the given action list for Tx metadata copy.
5186 * Copy the given action list to the ext_actions and add flow metadata register
5187 * copy action in order to copy reg_a set by WQE to reg_c[0].
5189 * @param[out] ext_actions
5190 * Pointer to the extended action list.
5191 * @param[in] actions
5192 * Pointer to the list of actions.
5193 * @param[in] actions_n
5194 * Number of actions in the list.
5196 * Perform verbose error reporting if not NULL.
5197 * @param[in] encap_idx
5198 * The encap action inndex.
5201 * 0 on success, negative value otherwise
5204 flow_mreg_tx_copy_prep(struct rte_eth_dev *dev,
5205 struct rte_flow_action *ext_actions,
5206 const struct rte_flow_action *actions,
5207 int actions_n, struct rte_flow_error *error,
5210 struct mlx5_flow_action_copy_mreg *cp_mreg =
5211 (struct mlx5_flow_action_copy_mreg *)
5212 (ext_actions + actions_n + 1);
5215 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_RX, 0, error);
5219 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_TX, 0, error);
5224 memcpy(ext_actions, actions, sizeof(*ext_actions) * encap_idx);
5225 if (encap_idx == actions_n - 1) {
5226 ext_actions[actions_n - 1] = (struct rte_flow_action){
5227 .type = (enum rte_flow_action_type)
5228 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
5231 ext_actions[actions_n] = (struct rte_flow_action){
5232 .type = RTE_FLOW_ACTION_TYPE_END,
5235 ext_actions[encap_idx] = (struct rte_flow_action){
5236 .type = (enum rte_flow_action_type)
5237 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
5240 memcpy(ext_actions + encap_idx + 1, actions + encap_idx,
5241 sizeof(*ext_actions) * (actions_n - encap_idx));
5247 * Check the match action from the action list.
5249 * @param[in] actions
5250 * Pointer to the list of actions.
5252 * Flow rule attributes.
5254 * The action to be check if exist.
5255 * @param[out] match_action_pos
5256 * Pointer to the position of the matched action if exists, otherwise is -1.
5257 * @param[out] qrss_action_pos
5258 * Pointer to the position of the Queue/RSS action if exists, otherwise is -1.
5259 * @param[out] modify_after_mirror
5260 * Pointer to the flag of modify action after FDB mirroring.
5263 * > 0 the total number of actions.
5264 * 0 if not found match action in action list.
5267 flow_check_match_action(const struct rte_flow_action actions[],
5268 const struct rte_flow_attr *attr,
5269 enum rte_flow_action_type action,
5270 int *match_action_pos, int *qrss_action_pos,
5271 int *modify_after_mirror)
5273 const struct rte_flow_action_sample *sample;
5274 const struct rte_flow_action_raw_decap *decap;
5281 *match_action_pos = -1;
5282 *qrss_action_pos = -1;
5283 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
5284 if (actions->type == action) {
5286 *match_action_pos = actions_n;
5288 switch (actions->type) {
5289 case RTE_FLOW_ACTION_TYPE_QUEUE:
5290 case RTE_FLOW_ACTION_TYPE_RSS:
5291 *qrss_action_pos = actions_n;
5293 case RTE_FLOW_ACTION_TYPE_SAMPLE:
5294 sample = actions->conf;
5295 ratio = sample->ratio;
5296 sub_type = ((const struct rte_flow_action *)
5297 (sample->actions))->type;
5298 if (ratio == 1 && attr->transfer)
5301 case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
5302 case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
5303 case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
5304 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
5305 case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
5306 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
5307 case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
5308 case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
5309 case RTE_FLOW_ACTION_TYPE_DEC_TTL:
5310 case RTE_FLOW_ACTION_TYPE_SET_TTL:
5311 case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
5312 case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
5313 case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
5314 case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
5315 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
5316 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
5317 case RTE_FLOW_ACTION_TYPE_FLAG:
5318 case RTE_FLOW_ACTION_TYPE_MARK:
5319 case RTE_FLOW_ACTION_TYPE_SET_META:
5320 case RTE_FLOW_ACTION_TYPE_SET_TAG:
5321 case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
5322 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
5323 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
5324 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
5325 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
5326 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
5327 case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
5328 case RTE_FLOW_ACTION_TYPE_METER:
5330 *modify_after_mirror = 1;
5332 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
5333 decap = actions->conf;
5334 while ((++actions)->type == RTE_FLOW_ACTION_TYPE_VOID)
5337 if (actions->type == RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
5338 const struct rte_flow_action_raw_encap *encap =
5341 MLX5_ENCAPSULATION_DECISION_SIZE &&
5343 MLX5_ENCAPSULATION_DECISION_SIZE)
5348 *modify_after_mirror = 1;
5355 if (flag && fdb_mirror && !*modify_after_mirror) {
5356 /* FDB mirroring uses the destination array to implement
5357 * instead of FLOW_SAMPLER object.
5359 if (sub_type != RTE_FLOW_ACTION_TYPE_END)
5362 /* Count RTE_FLOW_ACTION_TYPE_END. */
5363 return flag ? actions_n + 1 : 0;
5366 #define SAMPLE_SUFFIX_ITEM 2
5369 * Split the sample flow.
5371 * As sample flow will split to two sub flow, sample flow with
5372 * sample action, the other actions will move to new suffix flow.
5374 * Also add unique tag id with tag action in the sample flow,
5375 * the same tag id will be as match in the suffix flow.
5378 * Pointer to Ethernet device.
5379 * @param[in] add_tag
5380 * Add extra tag action flag.
5381 * @param[out] sfx_items
5382 * Suffix flow match items (list terminated by the END pattern item).
5383 * @param[in] actions
5384 * Associated actions (list terminated by the END action).
5385 * @param[out] actions_sfx
5386 * Suffix flow actions.
5387 * @param[out] actions_pre
5388 * Prefix flow actions.
5389 * @param[in] actions_n
5390 * The total number of actions.
5391 * @param[in] sample_action_pos
5392 * The sample action position.
5393 * @param[in] qrss_action_pos
5394 * The Queue/RSS action position.
5395 * @param[in] jump_table
5396 * Add extra jump action flag.
5398 * Perform verbose error reporting if not NULL.
5401 * 0 on success, or unique flow_id, a negative errno value
5402 * otherwise and rte_errno is set.
5405 flow_sample_split_prep(struct rte_eth_dev *dev,
5407 struct rte_flow_item sfx_items[],
5408 const struct rte_flow_action actions[],
5409 struct rte_flow_action actions_sfx[],
5410 struct rte_flow_action actions_pre[],
5412 int sample_action_pos,
5413 int qrss_action_pos,
5415 struct rte_flow_error *error)
5417 struct mlx5_priv *priv = dev->data->dev_private;
5418 struct mlx5_rte_flow_action_set_tag *set_tag;
5419 struct mlx5_rte_flow_item_tag *tag_spec;
5420 struct mlx5_rte_flow_item_tag *tag_mask;
5421 struct rte_flow_action_jump *jump_action;
5422 uint32_t tag_id = 0;
5424 int append_index = 0;
5427 if (sample_action_pos < 0)
5428 return rte_flow_error_set(error, EINVAL,
5429 RTE_FLOW_ERROR_TYPE_ACTION,
5430 NULL, "invalid position of sample "
5432 /* Prepare the actions for prefix and suffix flow. */
5433 if (qrss_action_pos >= 0 && qrss_action_pos < sample_action_pos) {
5434 index = qrss_action_pos;
5435 /* Put the preceding the Queue/RSS action into prefix flow. */
5437 memcpy(actions_pre, actions,
5438 sizeof(struct rte_flow_action) * index);
5439 /* Put others preceding the sample action into prefix flow. */
5440 if (sample_action_pos > index + 1)
5441 memcpy(actions_pre + index, actions + index + 1,
5442 sizeof(struct rte_flow_action) *
5443 (sample_action_pos - index - 1));
5444 index = sample_action_pos - 1;
5445 /* Put Queue/RSS action into Suffix flow. */
5446 memcpy(actions_sfx, actions + qrss_action_pos,
5447 sizeof(struct rte_flow_action));
5450 index = sample_action_pos;
5452 memcpy(actions_pre, actions,
5453 sizeof(struct rte_flow_action) * index);
5455 /* For CX5, add an extra tag action for NIC-RX and E-Switch ingress.
5456 * For CX6DX and above, metadata registers Cx preserve their value,
5457 * add an extra tag action for NIC-RX and E-Switch Domain.
5460 /* Prepare the prefix tag action. */
5462 set_tag = (void *)(actions_pre + actions_n + append_index);
5463 ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, 0, error);
5466 mlx5_ipool_malloc(priv->sh->ipool
5467 [MLX5_IPOOL_RSS_EXPANTION_FLOW_ID], &tag_id);
5468 *set_tag = (struct mlx5_rte_flow_action_set_tag) {
5472 /* Prepare the suffix subflow items. */
5473 tag_spec = (void *)(sfx_items + SAMPLE_SUFFIX_ITEM);
5474 tag_spec->data = tag_id;
5475 tag_spec->id = set_tag->id;
5476 tag_mask = tag_spec + 1;
5477 tag_mask->data = UINT32_MAX;
5478 sfx_items[0] = (struct rte_flow_item){
5479 .type = (enum rte_flow_item_type)
5480 MLX5_RTE_FLOW_ITEM_TYPE_TAG,
5485 sfx_items[1] = (struct rte_flow_item){
5486 .type = (enum rte_flow_item_type)
5487 RTE_FLOW_ITEM_TYPE_END,
5489 /* Prepare the tag action in prefix subflow. */
5490 actions_pre[index++] =
5491 (struct rte_flow_action){
5492 .type = (enum rte_flow_action_type)
5493 MLX5_RTE_FLOW_ACTION_TYPE_TAG,
5497 memcpy(actions_pre + index, actions + sample_action_pos,
5498 sizeof(struct rte_flow_action));
5500 /* For the modify action after the sample action in E-Switch mirroring,
5501 * Add the extra jump action in prefix subflow and jump into the next
5502 * table, then do the modify action in the new table.
5505 /* Prepare the prefix jump action. */
5507 jump_action = (void *)(actions_pre + actions_n + append_index);
5508 jump_action->group = jump_table;
5509 actions_pre[index++] =
5510 (struct rte_flow_action){
5511 .type = (enum rte_flow_action_type)
5512 RTE_FLOW_ACTION_TYPE_JUMP,
5513 .conf = jump_action,
5516 actions_pre[index] = (struct rte_flow_action){
5517 .type = (enum rte_flow_action_type)
5518 RTE_FLOW_ACTION_TYPE_END,
5520 /* Put the actions after sample into Suffix flow. */
5521 memcpy(actions_sfx, actions + sample_action_pos + 1,
5522 sizeof(struct rte_flow_action) *
5523 (actions_n - sample_action_pos - 1));
5528 * The splitting for metadata feature.
5530 * - Q/RSS action on NIC Rx should be split in order to pass by
5531 * the mreg copy table (RX_CP_TBL) and then it jumps to the
5532 * action table (RX_ACT_TBL) which has the split Q/RSS action.
5534 * - All the actions on NIC Tx should have a mreg copy action to
5535 * copy reg_a from WQE to reg_c[0].
5538 * Pointer to Ethernet device.
5540 * Parent flow structure pointer.
5542 * Flow rule attributes.
5544 * Pattern specification (list terminated by the END pattern item).
5545 * @param[in] actions
5546 * Associated actions (list terminated by the END action).
5547 * @param[in] flow_split_info
5548 * Pointer to flow split info structure.
5550 * Perform verbose error reporting if not NULL.
5552 * 0 on success, negative value otherwise
5555 flow_create_split_metadata(struct rte_eth_dev *dev,
5556 struct rte_flow *flow,
5557 const struct rte_flow_attr *attr,
5558 const struct rte_flow_item items[],
5559 const struct rte_flow_action actions[],
5560 struct mlx5_flow_split_info *flow_split_info,
5561 struct rte_flow_error *error)
5563 struct mlx5_priv *priv = dev->data->dev_private;
5564 struct mlx5_dev_config *config = &priv->config;
5565 const struct rte_flow_action *qrss = NULL;
5566 struct rte_flow_action *ext_actions = NULL;
5567 struct mlx5_flow *dev_flow = NULL;
5568 uint32_t qrss_id = 0;
5575 /* Check whether extensive metadata feature is engaged. */
5576 if (!config->dv_flow_en ||
5577 config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
5578 !mlx5_flow_ext_mreg_supported(dev))
5579 return flow_create_split_inner(dev, flow, NULL, attr, items,
5580 actions, flow_split_info, error);
5581 actions_n = flow_parse_metadata_split_actions_info(actions, &qrss,
5584 /* Exclude hairpin flows from splitting. */
5585 if (qrss->type == RTE_FLOW_ACTION_TYPE_QUEUE) {
5586 const struct rte_flow_action_queue *queue;
5589 if (mlx5_rxq_get_type(dev, queue->index) ==
5590 MLX5_RXQ_TYPE_HAIRPIN)
5592 } else if (qrss->type == RTE_FLOW_ACTION_TYPE_RSS) {
5593 const struct rte_flow_action_rss *rss;
5596 if (mlx5_rxq_get_type(dev, rss->queue[0]) ==
5597 MLX5_RXQ_TYPE_HAIRPIN)
5602 /* Check if it is in meter suffix table. */
5603 mtr_sfx = attr->group == (attr->transfer ?
5604 (MLX5_FLOW_TABLE_LEVEL_METER - 1) :
5605 MLX5_FLOW_TABLE_LEVEL_METER);
5607 * Q/RSS action on NIC Rx should be split in order to pass by
5608 * the mreg copy table (RX_CP_TBL) and then it jumps to the
5609 * action table (RX_ACT_TBL) which has the split Q/RSS action.
5611 act_size = sizeof(struct rte_flow_action) * (actions_n + 1) +
5612 sizeof(struct rte_flow_action_set_tag) +
5613 sizeof(struct rte_flow_action_jump);
5614 ext_actions = mlx5_malloc(MLX5_MEM_ZERO, act_size, 0,
5617 return rte_flow_error_set(error, ENOMEM,
5618 RTE_FLOW_ERROR_TYPE_ACTION,
5619 NULL, "no memory to split "
5622 * If we are the suffix flow of meter, tag already exist.
5623 * Set the tag action to void.
5626 ext_actions[qrss - actions].type =
5627 RTE_FLOW_ACTION_TYPE_VOID;
5629 ext_actions[qrss - actions].type =
5630 (enum rte_flow_action_type)
5631 MLX5_RTE_FLOW_ACTION_TYPE_TAG;
5633 * Create the new actions list with removed Q/RSS action
5634 * and appended set tag and jump to register copy table
5635 * (RX_CP_TBL). We should preallocate unique tag ID here
5636 * in advance, because it is needed for set tag action.
5638 qrss_id = flow_mreg_split_qrss_prep(dev, ext_actions, actions,
5639 qrss, actions_n, error);
5640 if (!mtr_sfx && !qrss_id) {
5644 } else if (attr->egress && !attr->transfer) {
5646 * All the actions on NIC Tx should have a metadata register
5647 * copy action to copy reg_a from WQE to reg_c[meta]
5649 act_size = sizeof(struct rte_flow_action) * (actions_n + 1) +
5650 sizeof(struct mlx5_flow_action_copy_mreg);
5651 ext_actions = mlx5_malloc(MLX5_MEM_ZERO, act_size, 0,
5654 return rte_flow_error_set(error, ENOMEM,
5655 RTE_FLOW_ERROR_TYPE_ACTION,
5656 NULL, "no memory to split "
5658 /* Create the action list appended with copy register. */
5659 ret = flow_mreg_tx_copy_prep(dev, ext_actions, actions,
5660 actions_n, error, encap_idx);
5664 /* Add the unmodified original or prefix subflow. */
5665 ret = flow_create_split_inner(dev, flow, &dev_flow, attr,
5666 items, ext_actions ? ext_actions :
5667 actions, flow_split_info, error);
5670 MLX5_ASSERT(dev_flow);
5672 const struct rte_flow_attr q_attr = {
5673 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
5676 /* Internal PMD action to set register. */
5677 struct mlx5_rte_flow_item_tag q_tag_spec = {
5681 struct rte_flow_item q_items[] = {
5683 .type = (enum rte_flow_item_type)
5684 MLX5_RTE_FLOW_ITEM_TYPE_TAG,
5685 .spec = &q_tag_spec,
5690 .type = RTE_FLOW_ITEM_TYPE_END,
5693 struct rte_flow_action q_actions[] = {
5699 .type = RTE_FLOW_ACTION_TYPE_END,
5702 uint64_t layers = flow_get_prefix_layer_flags(dev_flow);
5705 * Configure the tag item only if there is no meter subflow.
5706 * Since tag is already marked in the meter suffix subflow
5707 * we can just use the meter suffix items as is.
5710 /* Not meter subflow. */
5711 MLX5_ASSERT(!mtr_sfx);
5713 * Put unique id in prefix flow due to it is destroyed
5714 * after suffix flow and id will be freed after there
5715 * is no actual flows with this id and identifier
5716 * reallocation becomes possible (for example, for
5717 * other flows in other threads).
5719 dev_flow->handle->split_flow_id = qrss_id;
5720 ret = mlx5_flow_get_reg_id(dev, MLX5_COPY_MARK, 0,
5724 q_tag_spec.id = ret;
5727 /* Add suffix subflow to execute Q/RSS. */
5728 flow_split_info->prefix_layers = layers;
5729 flow_split_info->prefix_mark = 0;
5730 ret = flow_create_split_inner(dev, flow, &dev_flow,
5731 &q_attr, mtr_sfx ? items :
5733 flow_split_info, error);
5736 /* qrss ID should be freed if failed. */
5738 MLX5_ASSERT(dev_flow);
5743 * We do not destroy the partially created sub_flows in case of error.
5744 * These ones are included into parent flow list and will be destroyed
5745 * by flow_drv_destroy.
5747 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RSS_EXPANTION_FLOW_ID],
5749 mlx5_free(ext_actions);
5754 * Create meter internal drop flow with the original pattern.
5757 * Pointer to Ethernet device.
5759 * Parent flow structure pointer.
5761 * Flow rule attributes.
5763 * Pattern specification (list terminated by the END pattern item).
5764 * @param[in] flow_split_info
5765 * Pointer to flow split info structure.
5767 * Pointer to flow meter structure.
5769 * Perform verbose error reporting if not NULL.
5771 * 0 on success, negative value otherwise
5774 flow_meter_create_drop_flow_with_org_pattern(struct rte_eth_dev *dev,
5775 struct rte_flow *flow,
5776 const struct rte_flow_attr *attr,
5777 const struct rte_flow_item items[],
5778 struct mlx5_flow_split_info *flow_split_info,
5779 struct mlx5_flow_meter_info *fm,
5780 struct rte_flow_error *error)
5782 struct mlx5_flow *dev_flow = NULL;
5783 struct rte_flow_attr drop_attr = *attr;
5784 struct rte_flow_action drop_actions[3];
5785 struct mlx5_flow_split_info drop_split_info = *flow_split_info;
5787 MLX5_ASSERT(fm->drop_cnt);
5788 drop_actions[0].type =
5789 (enum rte_flow_action_type)MLX5_RTE_FLOW_ACTION_TYPE_COUNT;
5790 drop_actions[0].conf = (void *)(uintptr_t)fm->drop_cnt;
5791 drop_actions[1].type = RTE_FLOW_ACTION_TYPE_DROP;
5792 drop_actions[1].conf = NULL;
5793 drop_actions[2].type = RTE_FLOW_ACTION_TYPE_END;
5794 drop_actions[2].conf = NULL;
5795 drop_split_info.external = false;
5796 drop_split_info.skip_scale |= 1 << MLX5_SCALE_FLOW_GROUP_BIT;
5797 drop_split_info.table_id = MLX5_MTR_TABLE_ID_DROP;
5798 drop_attr.group = MLX5_FLOW_TABLE_LEVEL_METER;
5799 return flow_create_split_inner(dev, flow, &dev_flow,
5800 &drop_attr, items, drop_actions,
5801 &drop_split_info, error);
5805 * The splitting for meter feature.
5807 * - The meter flow will be split to two flows as prefix and
5808 * suffix flow. The packets make sense only it pass the prefix
5811 * - Reg_C_5 is used for the packet to match betweend prefix and
5815 * Pointer to Ethernet device.
5817 * Parent flow structure pointer.
5819 * Flow rule attributes.
5821 * Pattern specification (list terminated by the END pattern item).
5822 * @param[in] actions
5823 * Associated actions (list terminated by the END action).
5824 * @param[in] flow_split_info
5825 * Pointer to flow split info structure.
5827 * Perform verbose error reporting if not NULL.
5829 * 0 on success, negative value otherwise
5832 flow_create_split_meter(struct rte_eth_dev *dev,
5833 struct rte_flow *flow,
5834 const struct rte_flow_attr *attr,
5835 const struct rte_flow_item items[],
5836 const struct rte_flow_action actions[],
5837 struct mlx5_flow_split_info *flow_split_info,
5838 struct rte_flow_error *error)
5840 struct mlx5_priv *priv = dev->data->dev_private;
5841 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
5842 struct rte_flow_action *sfx_actions = NULL;
5843 struct rte_flow_action *pre_actions = NULL;
5844 struct rte_flow_item *sfx_items = NULL;
5845 struct mlx5_flow *dev_flow = NULL;
5846 struct rte_flow_attr sfx_attr = *attr;
5847 struct mlx5_flow_meter_info *fm = NULL;
5848 uint8_t skip_scale_restore;
5849 bool has_mtr = false;
5850 bool has_modify = false;
5851 bool set_mtr_reg = true;
5852 bool is_mtr_hierarchy = false;
5853 uint32_t meter_id = 0;
5854 uint32_t mtr_idx = 0;
5855 uint32_t mtr_flow_id = 0;
5862 actions_n = flow_check_meter_action(dev, actions, &has_mtr,
5863 &has_modify, &meter_id);
5866 fm = flow_dv_meter_find_by_idx(priv, flow->meter);
5868 return rte_flow_error_set(error, EINVAL,
5869 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5870 NULL, "Meter not found.");
5872 fm = mlx5_flow_meter_find(priv, meter_id, &mtr_idx);
5874 return rte_flow_error_set(error, EINVAL,
5875 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5876 NULL, "Meter not found.");
5877 ret = mlx5_flow_meter_attach(priv, fm,
5881 flow->meter = mtr_idx;
5885 if (!fm->def_policy) {
5886 wks->policy = mlx5_flow_meter_policy_find(dev,
5889 MLX5_ASSERT(wks->policy);
5890 if (wks->policy->is_hierarchy) {
5892 mlx5_flow_meter_hierarchy_get_final_policy(dev,
5894 if (!wks->final_policy)
5895 return rte_flow_error_set(error,
5897 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5898 "Failed to find terminal policy of hierarchy.");
5899 is_mtr_hierarchy = true;
5903 * If it isn't default-policy Meter, and
5904 * 1. There's no action in flow to change
5905 * packet (modify/encap/decap etc.), OR
5906 * 2. No drop count needed for this meter.
5907 * 3. It's not meter hierarchy.
5908 * Then no need to use regC to save meter id anymore.
5910 if (!fm->def_policy && !is_mtr_hierarchy &&
5911 (!has_modify || !fm->drop_cnt))
5912 set_mtr_reg = false;
5913 /* Prefix actions: meter, decap, encap, tag, jump, end. */
5914 act_size = sizeof(struct rte_flow_action) * (actions_n + 6) +
5915 sizeof(struct mlx5_rte_flow_action_set_tag);
5916 /* Suffix items: tag, vlan, port id, end. */
5917 #define METER_SUFFIX_ITEM 4
5918 item_size = sizeof(struct rte_flow_item) * METER_SUFFIX_ITEM +
5919 sizeof(struct mlx5_rte_flow_item_tag) * 2;
5920 sfx_actions = mlx5_malloc(MLX5_MEM_ZERO, (act_size + item_size),
5923 return rte_flow_error_set(error, ENOMEM,
5924 RTE_FLOW_ERROR_TYPE_ACTION,
5925 NULL, "no memory to split "
5927 sfx_items = (struct rte_flow_item *)((char *)sfx_actions +
5929 /* There's no suffix flow for meter of non-default policy. */
5930 if (!fm->def_policy)
5931 pre_actions = sfx_actions + 1;
5933 pre_actions = sfx_actions + actions_n;
5934 ret = flow_meter_split_prep(dev, flow, wks, &sfx_attr,
5935 items, sfx_items, actions,
5936 sfx_actions, pre_actions,
5937 (set_mtr_reg ? &mtr_flow_id : NULL),
5943 /* Add the prefix subflow. */
5944 flow_split_info->prefix_mark = 0;
5945 skip_scale_restore = flow_split_info->skip_scale;
5946 flow_split_info->skip_scale |=
5947 1 << MLX5_SCALE_JUMP_FLOW_GROUP_BIT;
5948 ret = flow_create_split_inner(dev, flow, &dev_flow,
5949 attr, items, pre_actions,
5950 flow_split_info, error);
5951 flow_split_info->skip_scale = skip_scale_restore;
5954 mlx5_ipool_free(fm->flow_ipool, mtr_flow_id);
5959 dev_flow->handle->split_flow_id = mtr_flow_id;
5960 dev_flow->handle->is_meter_flow_id = 1;
5962 if (!fm->def_policy) {
5963 if (!set_mtr_reg && fm->drop_cnt)
5965 flow_meter_create_drop_flow_with_org_pattern(dev, flow,
5971 /* Setting the sfx group atrr. */
5972 sfx_attr.group = sfx_attr.transfer ?
5973 (MLX5_FLOW_TABLE_LEVEL_METER - 1) :
5974 MLX5_FLOW_TABLE_LEVEL_METER;
5975 flow_split_info->prefix_layers =
5976 flow_get_prefix_layer_flags(dev_flow);
5977 flow_split_info->prefix_mark = dev_flow->handle->mark;
5978 flow_split_info->table_id = MLX5_MTR_TABLE_ID_SUFFIX;
5980 /* Add the prefix subflow. */
5981 ret = flow_create_split_metadata(dev, flow,
5982 &sfx_attr, sfx_items ?
5984 sfx_actions ? sfx_actions : actions,
5985 flow_split_info, error);
5988 mlx5_free(sfx_actions);
5993 * The splitting for sample feature.
5995 * Once Sample action is detected in the action list, the flow actions should
5996 * be split into prefix sub flow and suffix sub flow.
5998 * The original items remain in the prefix sub flow, all actions preceding the
5999 * sample action and the sample action itself will be copied to the prefix
6000 * sub flow, the actions following the sample action will be copied to the
6001 * suffix sub flow, Queue action always be located in the suffix sub flow.
6003 * In order to make the packet from prefix sub flow matches with suffix sub
6004 * flow, an extra tag action be added into prefix sub flow, and the suffix sub
6005 * flow uses tag item with the unique flow id.
6008 * Pointer to Ethernet device.
6010 * Parent flow structure pointer.
6012 * Flow rule attributes.
6014 * Pattern specification (list terminated by the END pattern item).
6015 * @param[in] actions
6016 * Associated actions (list terminated by the END action).
6017 * @param[in] flow_split_info
6018 * Pointer to flow split info structure.
6020 * Perform verbose error reporting if not NULL.
6022 * 0 on success, negative value otherwise
6025 flow_create_split_sample(struct rte_eth_dev *dev,
6026 struct rte_flow *flow,
6027 const struct rte_flow_attr *attr,
6028 const struct rte_flow_item items[],
6029 const struct rte_flow_action actions[],
6030 struct mlx5_flow_split_info *flow_split_info,
6031 struct rte_flow_error *error)
6033 struct mlx5_priv *priv = dev->data->dev_private;
6034 struct rte_flow_action *sfx_actions = NULL;
6035 struct rte_flow_action *pre_actions = NULL;
6036 struct rte_flow_item *sfx_items = NULL;
6037 struct mlx5_flow *dev_flow = NULL;
6038 struct rte_flow_attr sfx_attr = *attr;
6039 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
6040 struct mlx5_flow_dv_sample_resource *sample_res;
6041 struct mlx5_flow_tbl_data_entry *sfx_tbl_data;
6042 struct mlx5_flow_tbl_resource *sfx_tbl;
6046 uint32_t fdb_tx = 0;
6049 int sample_action_pos;
6050 int qrss_action_pos;
6052 int modify_after_mirror = 0;
6053 uint16_t jump_table = 0;
6054 const uint32_t next_ft_step = 1;
6057 if (priv->sampler_en)
6058 actions_n = flow_check_match_action(actions, attr,
6059 RTE_FLOW_ACTION_TYPE_SAMPLE,
6060 &sample_action_pos, &qrss_action_pos,
6061 &modify_after_mirror);
6063 /* The prefix actions must includes sample, tag, end. */
6064 act_size = sizeof(struct rte_flow_action) * (actions_n * 2 + 1)
6065 + sizeof(struct mlx5_rte_flow_action_set_tag);
6066 item_size = sizeof(struct rte_flow_item) * SAMPLE_SUFFIX_ITEM +
6067 sizeof(struct mlx5_rte_flow_item_tag) * 2;
6068 sfx_actions = mlx5_malloc(MLX5_MEM_ZERO, (act_size +
6069 item_size), 0, SOCKET_ID_ANY);
6071 return rte_flow_error_set(error, ENOMEM,
6072 RTE_FLOW_ERROR_TYPE_ACTION,
6073 NULL, "no memory to split "
6075 /* The representor_id is UINT16_MAX for uplink. */
6076 fdb_tx = (attr->transfer && priv->representor_id != UINT16_MAX);
6078 * When reg_c_preserve is set, metadata registers Cx preserve
6079 * their value even through packet duplication.
6081 add_tag = (!fdb_tx || priv->config.hca_attr.reg_c_preserve);
6083 sfx_items = (struct rte_flow_item *)((char *)sfx_actions
6085 if (modify_after_mirror)
6086 jump_table = attr->group * MLX5_FLOW_TABLE_FACTOR +
6088 pre_actions = sfx_actions + actions_n;
6089 tag_id = flow_sample_split_prep(dev, add_tag, sfx_items,
6090 actions, sfx_actions,
6091 pre_actions, actions_n,
6093 qrss_action_pos, jump_table,
6095 if (tag_id < 0 || (add_tag && !tag_id)) {
6099 if (modify_after_mirror)
6100 flow_split_info->skip_scale =
6101 1 << MLX5_SCALE_JUMP_FLOW_GROUP_BIT;
6102 /* Add the prefix subflow. */
6103 ret = flow_create_split_inner(dev, flow, &dev_flow, attr,
6105 flow_split_info, error);
6110 dev_flow->handle->split_flow_id = tag_id;
6111 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
6112 if (!modify_after_mirror) {
6113 /* Set the sfx group attr. */
6114 sample_res = (struct mlx5_flow_dv_sample_resource *)
6115 dev_flow->dv.sample_res;
6116 sfx_tbl = (struct mlx5_flow_tbl_resource *)
6117 sample_res->normal_path_tbl;
6118 sfx_tbl_data = container_of(sfx_tbl,
6119 struct mlx5_flow_tbl_data_entry,
6121 sfx_attr.group = sfx_attr.transfer ?
6122 (sfx_tbl_data->level - 1) : sfx_tbl_data->level;
6124 MLX5_ASSERT(attr->transfer);
6125 sfx_attr.group = jump_table;
6127 flow_split_info->prefix_layers =
6128 flow_get_prefix_layer_flags(dev_flow);
6129 flow_split_info->prefix_mark = dev_flow->handle->mark;
6130 /* Suffix group level already be scaled with factor, set
6131 * MLX5_SCALE_FLOW_GROUP_BIT of skip_scale to 1 to avoid scale
6132 * again in translation.
6134 flow_split_info->skip_scale = 1 << MLX5_SCALE_FLOW_GROUP_BIT;
6137 /* Add the suffix subflow. */
6138 ret = flow_create_split_meter(dev, flow, &sfx_attr,
6139 sfx_items ? sfx_items : items,
6140 sfx_actions ? sfx_actions : actions,
6141 flow_split_info, error);
6144 mlx5_free(sfx_actions);
6149 * Split the flow to subflow set. The splitters might be linked
6150 * in the chain, like this:
6151 * flow_create_split_outer() calls:
6152 * flow_create_split_meter() calls:
6153 * flow_create_split_metadata(meter_subflow_0) calls:
6154 * flow_create_split_inner(metadata_subflow_0)
6155 * flow_create_split_inner(metadata_subflow_1)
6156 * flow_create_split_inner(metadata_subflow_2)
6157 * flow_create_split_metadata(meter_subflow_1) calls:
6158 * flow_create_split_inner(metadata_subflow_0)
6159 * flow_create_split_inner(metadata_subflow_1)
6160 * flow_create_split_inner(metadata_subflow_2)
6162 * This provide flexible way to add new levels of flow splitting.
6163 * The all of successfully created subflows are included to the
6164 * parent flow dev_flow list.
6167 * Pointer to Ethernet device.
6169 * Parent flow structure pointer.
6171 * Flow rule attributes.
6173 * Pattern specification (list terminated by the END pattern item).
6174 * @param[in] actions
6175 * Associated actions (list terminated by the END action).
6176 * @param[in] flow_split_info
6177 * Pointer to flow split info structure.
6179 * Perform verbose error reporting if not NULL.
6181 * 0 on success, negative value otherwise
6184 flow_create_split_outer(struct rte_eth_dev *dev,
6185 struct rte_flow *flow,
6186 const struct rte_flow_attr *attr,
6187 const struct rte_flow_item items[],
6188 const struct rte_flow_action actions[],
6189 struct mlx5_flow_split_info *flow_split_info,
6190 struct rte_flow_error *error)
6194 ret = flow_create_split_sample(dev, flow, attr, items,
6195 actions, flow_split_info, error);
6196 MLX5_ASSERT(ret <= 0);
6200 static inline struct mlx5_flow_tunnel *
6201 flow_tunnel_from_rule(const struct mlx5_flow *flow)
6203 struct mlx5_flow_tunnel *tunnel;
6205 #pragma GCC diagnostic push
6206 #pragma GCC diagnostic ignored "-Wcast-qual"
6207 tunnel = (typeof(tunnel))flow->tunnel;
6208 #pragma GCC diagnostic pop
6214 * Adjust flow RSS workspace if needed.
6217 * Pointer to thread flow work space.
6219 * Pointer to RSS descriptor.
6220 * @param[in] nrssq_num
6221 * New RSS queue number.
6224 * 0 on success, -1 otherwise and rte_errno is set.
6227 flow_rss_workspace_adjust(struct mlx5_flow_workspace *wks,
6228 struct mlx5_flow_rss_desc *rss_desc,
6231 if (likely(nrssq_num <= wks->rssq_num))
6233 rss_desc->queue = realloc(rss_desc->queue,
6234 sizeof(*rss_desc->queue) * RTE_ALIGN(nrssq_num, 2));
6235 if (!rss_desc->queue) {
6239 wks->rssq_num = RTE_ALIGN(nrssq_num, 2);
6244 * Create a flow and add it to @p list.
6247 * Pointer to Ethernet device.
6249 * Pointer to a TAILQ flow list. If this parameter NULL,
6250 * no list insertion occurred, flow is just created,
6251 * this is caller's responsibility to track the
6254 * Flow rule attributes.
6256 * Pattern specification (list terminated by the END pattern item).
6257 * @param[in] actions
6258 * Associated actions (list terminated by the END action).
6259 * @param[in] external
6260 * This flow rule is created by request external to PMD.
6262 * Perform verbose error reporting if not NULL.
6265 * A flow index on success, 0 otherwise and rte_errno is set.
6268 flow_list_create(struct rte_eth_dev *dev, enum mlx5_flow_type type,
6269 const struct rte_flow_attr *attr,
6270 const struct rte_flow_item items[],
6271 const struct rte_flow_action original_actions[],
6272 bool external, struct rte_flow_error *error)
6274 struct mlx5_priv *priv = dev->data->dev_private;
6275 struct rte_flow *flow = NULL;
6276 struct mlx5_flow *dev_flow;
6277 const struct rte_flow_action_rss *rss = NULL;
6278 struct mlx5_translated_action_handle
6279 indir_actions[MLX5_MAX_INDIRECT_ACTIONS];
6280 int indir_actions_n = MLX5_MAX_INDIRECT_ACTIONS;
6282 struct mlx5_flow_expand_rss buf;
6283 uint8_t buffer[4096];
6286 struct rte_flow_action actions[MLX5_MAX_SPLIT_ACTIONS];
6287 uint8_t buffer[2048];
6290 struct rte_flow_action actions[MLX5_MAX_SPLIT_ACTIONS];
6291 uint8_t buffer[2048];
6292 } actions_hairpin_tx;
6294 struct rte_flow_item items[MLX5_MAX_SPLIT_ITEMS];
6295 uint8_t buffer[2048];
6297 struct mlx5_flow_expand_rss *buf = &expand_buffer.buf;
6298 struct mlx5_flow_rss_desc *rss_desc;
6299 const struct rte_flow_action *p_actions_rx;
6303 struct rte_flow_attr attr_tx = { .priority = 0 };
6304 const struct rte_flow_action *actions;
6305 struct rte_flow_action *translated_actions = NULL;
6306 struct mlx5_flow_tunnel *tunnel;
6307 struct tunnel_default_miss_ctx default_miss_ctx = { 0, };
6308 struct mlx5_flow_workspace *wks = mlx5_flow_push_thread_workspace();
6309 struct mlx5_flow_split_info flow_split_info = {
6310 .external = !!external,
6320 rss_desc = &wks->rss_desc;
6321 ret = flow_action_handles_translate(dev, original_actions,
6324 &translated_actions, error);
6326 MLX5_ASSERT(translated_actions == NULL);
6329 actions = translated_actions ? translated_actions : original_actions;
6330 p_actions_rx = actions;
6331 hairpin_flow = flow_check_hairpin_split(dev, attr, actions);
6332 ret = flow_drv_validate(dev, attr, items, p_actions_rx,
6333 external, hairpin_flow, error);
6335 goto error_before_hairpin_split;
6336 flow = mlx5_ipool_zmalloc(priv->flows[type], &idx);
6339 goto error_before_hairpin_split;
6341 if (hairpin_flow > 0) {
6342 if (hairpin_flow > MLX5_MAX_SPLIT_ACTIONS) {
6344 goto error_before_hairpin_split;
6346 flow_hairpin_split(dev, actions, actions_rx.actions,
6347 actions_hairpin_tx.actions, items_tx.items,
6349 p_actions_rx = actions_rx.actions;
6351 flow_split_info.flow_idx = idx;
6352 flow->drv_type = flow_get_drv_type(dev, attr);
6353 MLX5_ASSERT(flow->drv_type > MLX5_FLOW_TYPE_MIN &&
6354 flow->drv_type < MLX5_FLOW_TYPE_MAX);
6355 memset(rss_desc, 0, offsetof(struct mlx5_flow_rss_desc, queue));
6356 /* RSS Action only works on NIC RX domain */
6357 if (attr->ingress && !attr->transfer)
6358 rss = flow_get_rss_action(dev, p_actions_rx);
6360 if (flow_rss_workspace_adjust(wks, rss_desc, rss->queue_num))
6363 * The following information is required by
6364 * mlx5_flow_hashfields_adjust() in advance.
6366 rss_desc->level = rss->level;
6367 /* RSS type 0 indicates default RSS type (ETH_RSS_IP). */
6368 rss_desc->types = !rss->types ? ETH_RSS_IP : rss->types;
6370 flow->dev_handles = 0;
6371 if (rss && rss->types) {
6372 unsigned int graph_root;
6374 graph_root = find_graph_root(rss->level);
6375 ret = mlx5_flow_expand_rss(buf, sizeof(expand_buffer.buffer),
6377 mlx5_support_expansion, graph_root);
6378 MLX5_ASSERT(ret > 0 &&
6379 (unsigned int)ret < sizeof(expand_buffer.buffer));
6380 if (rte_log_can_log(mlx5_logtype, RTE_LOG_DEBUG)) {
6381 for (i = 0; i < buf->entries; ++i)
6382 mlx5_dbg__print_pattern(buf->entry[i].pattern);
6386 buf->entry[0].pattern = (void *)(uintptr_t)items;
6388 rss_desc->shared_rss = flow_get_shared_rss_action(dev, indir_actions,
6390 for (i = 0; i < buf->entries; ++i) {
6391 /* Initialize flow split data. */
6392 flow_split_info.prefix_layers = 0;
6393 flow_split_info.prefix_mark = 0;
6394 flow_split_info.skip_scale = 0;
6396 * The splitter may create multiple dev_flows,
6397 * depending on configuration. In the simplest
6398 * case it just creates unmodified original flow.
6400 ret = flow_create_split_outer(dev, flow, attr,
6401 buf->entry[i].pattern,
6402 p_actions_rx, &flow_split_info,
6406 if (is_flow_tunnel_steer_rule(wks->flows[0].tof_type)) {
6407 ret = flow_tunnel_add_default_miss(dev, flow, attr,
6410 wks->flows[0].tunnel,
6414 mlx5_free(default_miss_ctx.queue);
6419 /* Create the tx flow. */
6421 attr_tx.group = MLX5_HAIRPIN_TX_TABLE;
6422 attr_tx.ingress = 0;
6424 dev_flow = flow_drv_prepare(dev, flow, &attr_tx, items_tx.items,
6425 actions_hairpin_tx.actions,
6429 dev_flow->flow = flow;
6430 dev_flow->external = 0;
6431 SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
6432 dev_flow->handle, next);
6433 ret = flow_drv_translate(dev, dev_flow, &attr_tx,
6435 actions_hairpin_tx.actions, error);
6440 * Update the metadata register copy table. If extensive
6441 * metadata feature is enabled and registers are supported
6442 * we might create the extra rte_flow for each unique
6443 * MARK/FLAG action ID.
6445 * The table is updated for ingress Flows only, because
6446 * the egress Flows belong to the different device and
6447 * copy table should be updated in peer NIC Rx domain.
6449 if (attr->ingress &&
6450 (external || attr->group != MLX5_FLOW_MREG_CP_TABLE_GROUP)) {
6451 ret = flow_mreg_update_copy_table(dev, flow, actions, error);
6456 * If the flow is external (from application) OR device is started,
6457 * OR mreg discover, then apply immediately.
6459 if (external || dev->data->dev_started ||
6460 (attr->group == MLX5_FLOW_MREG_CP_TABLE_GROUP &&
6461 attr->priority == MLX5_FLOW_LOWEST_PRIO_INDICATOR)) {
6462 ret = flow_drv_apply(dev, flow, error);
6467 flow_rxq_flags_set(dev, flow);
6468 rte_free(translated_actions);
6469 tunnel = flow_tunnel_from_rule(wks->flows);
6472 flow->tunnel_id = tunnel->tunnel_id;
6473 __atomic_add_fetch(&tunnel->refctn, 1, __ATOMIC_RELAXED);
6474 mlx5_free(default_miss_ctx.queue);
6476 mlx5_flow_pop_thread_workspace();
6480 ret = rte_errno; /* Save rte_errno before cleanup. */
6481 flow_mreg_del_copy_action(dev, flow);
6482 flow_drv_destroy(dev, flow);
6483 if (rss_desc->shared_rss)
6484 __atomic_sub_fetch(&((struct mlx5_shared_action_rss *)
6486 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
6487 rss_desc->shared_rss))->refcnt, 1, __ATOMIC_RELAXED);
6488 mlx5_ipool_free(priv->flows[type], idx);
6489 rte_errno = ret; /* Restore rte_errno. */
6492 mlx5_flow_pop_thread_workspace();
6493 error_before_hairpin_split:
6494 rte_free(translated_actions);
6499 * Create a dedicated flow rule on e-switch table 0 (root table), to direct all
6500 * incoming packets to table 1.
6502 * Other flow rules, requested for group n, will be created in
6503 * e-switch table n+1.
6504 * Jump action to e-switch group n will be created to group n+1.
6506 * Used when working in switchdev mode, to utilise advantages of table 1
6510 * Pointer to Ethernet device.
6513 * Pointer to flow on success, NULL otherwise and rte_errno is set.
6516 mlx5_flow_create_esw_table_zero_flow(struct rte_eth_dev *dev)
6518 const struct rte_flow_attr attr = {
6525 const struct rte_flow_item pattern = {
6526 .type = RTE_FLOW_ITEM_TYPE_END,
6528 struct rte_flow_action_jump jump = {
6531 const struct rte_flow_action actions[] = {
6533 .type = RTE_FLOW_ACTION_TYPE_JUMP,
6537 .type = RTE_FLOW_ACTION_TYPE_END,
6540 struct rte_flow_error error;
6542 return (void *)(uintptr_t)flow_list_create(dev, MLX5_FLOW_TYPE_CTL,
6544 actions, false, &error);
6548 * Validate a flow supported by the NIC.
6550 * @see rte_flow_validate()
6554 mlx5_flow_validate(struct rte_eth_dev *dev,
6555 const struct rte_flow_attr *attr,
6556 const struct rte_flow_item items[],
6557 const struct rte_flow_action original_actions[],
6558 struct rte_flow_error *error)
6561 struct mlx5_translated_action_handle
6562 indir_actions[MLX5_MAX_INDIRECT_ACTIONS];
6563 int indir_actions_n = MLX5_MAX_INDIRECT_ACTIONS;
6564 const struct rte_flow_action *actions;
6565 struct rte_flow_action *translated_actions = NULL;
6566 int ret = flow_action_handles_translate(dev, original_actions,
6569 &translated_actions, error);
6573 actions = translated_actions ? translated_actions : original_actions;
6574 hairpin_flow = flow_check_hairpin_split(dev, attr, actions);
6575 ret = flow_drv_validate(dev, attr, items, actions,
6576 true, hairpin_flow, error);
6577 rte_free(translated_actions);
6584 * @see rte_flow_create()
6588 mlx5_flow_create(struct rte_eth_dev *dev,
6589 const struct rte_flow_attr *attr,
6590 const struct rte_flow_item items[],
6591 const struct rte_flow_action actions[],
6592 struct rte_flow_error *error)
6595 * If the device is not started yet, it is not allowed to created a
6596 * flow from application. PMD default flows and traffic control flows
6599 if (unlikely(!dev->data->dev_started)) {
6600 DRV_LOG(DEBUG, "port %u is not started when "
6601 "inserting a flow", dev->data->port_id);
6602 rte_flow_error_set(error, ENODEV,
6603 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6605 "port not started");
6609 return (void *)(uintptr_t)flow_list_create(dev, MLX5_FLOW_TYPE_GEN,
6610 attr, items, actions,
6615 * Destroy a flow in a list.
6618 * Pointer to Ethernet device.
6619 * @param[in] flow_idx
6620 * Index of flow to destroy.
6623 flow_list_destroy(struct rte_eth_dev *dev, enum mlx5_flow_type type,
6626 struct mlx5_priv *priv = dev->data->dev_private;
6627 struct rte_flow *flow = mlx5_ipool_get(priv->flows[type], flow_idx);
6631 MLX5_ASSERT(flow->type == type);
6633 * Update RX queue flags only if port is started, otherwise it is
6636 if (dev->data->dev_started)
6637 flow_rxq_flags_trim(dev, flow);
6638 flow_drv_destroy(dev, flow);
6640 struct mlx5_flow_tunnel *tunnel;
6642 tunnel = mlx5_find_tunnel_id(dev, flow->tunnel_id);
6644 if (!__atomic_sub_fetch(&tunnel->refctn, 1, __ATOMIC_RELAXED))
6645 mlx5_flow_tunnel_free(dev, tunnel);
6647 flow_mreg_del_copy_action(dev, flow);
6648 mlx5_ipool_free(priv->flows[type], flow_idx);
6652 * Destroy all flows.
6655 * Pointer to Ethernet device.
6657 * Flow type to be flushed.
6659 * If flushing is called avtively.
6662 mlx5_flow_list_flush(struct rte_eth_dev *dev, enum mlx5_flow_type type,
6665 struct mlx5_priv *priv = dev->data->dev_private;
6666 uint32_t num_flushed = 0, fidx = 1;
6667 struct rte_flow *flow;
6669 MLX5_IPOOL_FOREACH(priv->flows[type], fidx, flow) {
6670 flow_list_destroy(dev, type, fidx);
6674 DRV_LOG(INFO, "port %u: %u flows flushed before stopping",
6675 dev->data->port_id, num_flushed);
6680 * Stop all default actions for flows.
6683 * Pointer to Ethernet device.
6686 mlx5_flow_stop_default(struct rte_eth_dev *dev)
6688 flow_mreg_del_default_copy_action(dev);
6689 flow_rxq_flags_clear(dev);
6693 * Start all default actions for flows.
6696 * Pointer to Ethernet device.
6698 * 0 on success, a negative errno value otherwise and rte_errno is set.
6701 mlx5_flow_start_default(struct rte_eth_dev *dev)
6703 struct rte_flow_error error;
6705 /* Make sure default copy action (reg_c[0] -> reg_b) is created. */
6706 return flow_mreg_add_default_copy_action(dev, &error);
6710 * Release key of thread specific flow workspace data.
6713 flow_release_workspace(void *data)
6715 struct mlx5_flow_workspace *wks = data;
6716 struct mlx5_flow_workspace *next;
6720 free(wks->rss_desc.queue);
6727 * Get thread specific current flow workspace.
6729 * @return pointer to thread specific flow workspace data, NULL on error.
6731 struct mlx5_flow_workspace*
6732 mlx5_flow_get_thread_workspace(void)
6734 struct mlx5_flow_workspace *data;
6736 data = mlx5_flow_os_get_specific_workspace();
6737 MLX5_ASSERT(data && data->inuse);
6738 if (!data || !data->inuse)
6739 DRV_LOG(ERR, "flow workspace not initialized.");
6744 * Allocate and init new flow workspace.
6746 * @return pointer to flow workspace data, NULL on error.
6748 static struct mlx5_flow_workspace*
6749 flow_alloc_thread_workspace(void)
6751 struct mlx5_flow_workspace *data = calloc(1, sizeof(*data));
6754 DRV_LOG(ERR, "Failed to allocate flow workspace "
6758 data->rss_desc.queue = calloc(1,
6759 sizeof(uint16_t) * MLX5_RSSQ_DEFAULT_NUM);
6760 if (!data->rss_desc.queue)
6762 data->rssq_num = MLX5_RSSQ_DEFAULT_NUM;
6765 if (data->rss_desc.queue)
6766 free(data->rss_desc.queue);
6772 * Get new thread specific flow workspace.
6774 * If current workspace inuse, create new one and set as current.
6776 * @return pointer to thread specific flow workspace data, NULL on error.
6778 static struct mlx5_flow_workspace*
6779 mlx5_flow_push_thread_workspace(void)
6781 struct mlx5_flow_workspace *curr;
6782 struct mlx5_flow_workspace *data;
6784 curr = mlx5_flow_os_get_specific_workspace();
6786 data = flow_alloc_thread_workspace();
6789 } else if (!curr->inuse) {
6791 } else if (curr->next) {
6794 data = flow_alloc_thread_workspace();
6802 /* Set as current workspace */
6803 if (mlx5_flow_os_set_specific_workspace(data))
6804 DRV_LOG(ERR, "Failed to set flow workspace to thread.");
6809 * Close current thread specific flow workspace.
6811 * If previous workspace available, set it as current.
6813 * @return pointer to thread specific flow workspace data, NULL on error.
6816 mlx5_flow_pop_thread_workspace(void)
6818 struct mlx5_flow_workspace *data = mlx5_flow_get_thread_workspace();
6823 DRV_LOG(ERR, "Failed to close unused flow workspace.");
6829 if (mlx5_flow_os_set_specific_workspace(data->prev))
6830 DRV_LOG(ERR, "Failed to set flow workspace to thread.");
6834 * Verify the flow list is empty
6837 * Pointer to Ethernet device.
6839 * @return the number of flows not released.
6842 mlx5_flow_verify(struct rte_eth_dev *dev __rte_unused)
6844 struct mlx5_priv *priv = dev->data->dev_private;
6845 struct rte_flow *flow;
6849 for (i = 0; i < MLX5_FLOW_TYPE_MAXI; i++) {
6850 MLX5_IPOOL_FOREACH(priv->flows[i], idx, flow) {
6851 DRV_LOG(DEBUG, "port %u flow %p still referenced",
6852 dev->data->port_id, (void *)flow);
6860 * Enable default hairpin egress flow.
6863 * Pointer to Ethernet device.
6868 * 0 on success, a negative errno value otherwise and rte_errno is set.
6871 mlx5_ctrl_flow_source_queue(struct rte_eth_dev *dev,
6874 const struct rte_flow_attr attr = {
6878 struct mlx5_rte_flow_item_tx_queue queue_spec = {
6881 struct mlx5_rte_flow_item_tx_queue queue_mask = {
6882 .queue = UINT32_MAX,
6884 struct rte_flow_item items[] = {
6886 .type = (enum rte_flow_item_type)
6887 MLX5_RTE_FLOW_ITEM_TYPE_TX_QUEUE,
6888 .spec = &queue_spec,
6890 .mask = &queue_mask,
6893 .type = RTE_FLOW_ITEM_TYPE_END,
6896 struct rte_flow_action_jump jump = {
6897 .group = MLX5_HAIRPIN_TX_TABLE,
6899 struct rte_flow_action actions[2];
6901 struct rte_flow_error error;
6903 actions[0].type = RTE_FLOW_ACTION_TYPE_JUMP;
6904 actions[0].conf = &jump;
6905 actions[1].type = RTE_FLOW_ACTION_TYPE_END;
6906 flow_idx = flow_list_create(dev, MLX5_FLOW_TYPE_CTL,
6907 &attr, items, actions, false, &error);
6910 "Failed to create ctrl flow: rte_errno(%d),"
6911 " type(%d), message(%s)",
6912 rte_errno, error.type,
6913 error.message ? error.message : " (no stated reason)");
6920 * Enable a control flow configured from the control plane.
6923 * Pointer to Ethernet device.
6925 * An Ethernet flow spec to apply.
6927 * An Ethernet flow mask to apply.
6929 * A VLAN flow spec to apply.
6931 * A VLAN flow mask to apply.
6934 * 0 on success, a negative errno value otherwise and rte_errno is set.
6937 mlx5_ctrl_flow_vlan(struct rte_eth_dev *dev,
6938 struct rte_flow_item_eth *eth_spec,
6939 struct rte_flow_item_eth *eth_mask,
6940 struct rte_flow_item_vlan *vlan_spec,
6941 struct rte_flow_item_vlan *vlan_mask)
6943 struct mlx5_priv *priv = dev->data->dev_private;
6944 const struct rte_flow_attr attr = {
6946 .priority = MLX5_FLOW_LOWEST_PRIO_INDICATOR,
6948 struct rte_flow_item items[] = {
6950 .type = RTE_FLOW_ITEM_TYPE_ETH,
6956 .type = (vlan_spec) ? RTE_FLOW_ITEM_TYPE_VLAN :
6957 RTE_FLOW_ITEM_TYPE_END,
6963 .type = RTE_FLOW_ITEM_TYPE_END,
6966 uint16_t queue[priv->reta_idx_n];
6967 struct rte_flow_action_rss action_rss = {
6968 .func = RTE_ETH_HASH_FUNCTION_DEFAULT,
6970 .types = priv->rss_conf.rss_hf,
6971 .key_len = priv->rss_conf.rss_key_len,
6972 .queue_num = priv->reta_idx_n,
6973 .key = priv->rss_conf.rss_key,
6976 struct rte_flow_action actions[] = {
6978 .type = RTE_FLOW_ACTION_TYPE_RSS,
6979 .conf = &action_rss,
6982 .type = RTE_FLOW_ACTION_TYPE_END,
6986 struct rte_flow_error error;
6989 if (!priv->reta_idx_n || !priv->rxqs_n) {
6992 if (!(dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG))
6993 action_rss.types = 0;
6994 for (i = 0; i != priv->reta_idx_n; ++i)
6995 queue[i] = (*priv->reta_idx)[i];
6996 flow_idx = flow_list_create(dev, MLX5_FLOW_TYPE_CTL,
6997 &attr, items, actions, false, &error);
7004 * Enable a flow control configured from the control plane.
7007 * Pointer to Ethernet device.
7009 * An Ethernet flow spec to apply.
7011 * An Ethernet flow mask to apply.
7014 * 0 on success, a negative errno value otherwise and rte_errno is set.
7017 mlx5_ctrl_flow(struct rte_eth_dev *dev,
7018 struct rte_flow_item_eth *eth_spec,
7019 struct rte_flow_item_eth *eth_mask)
7021 return mlx5_ctrl_flow_vlan(dev, eth_spec, eth_mask, NULL, NULL);
7025 * Create default miss flow rule matching lacp traffic
7028 * Pointer to Ethernet device.
7030 * An Ethernet flow spec to apply.
7033 * 0 on success, a negative errno value otherwise and rte_errno is set.
7036 mlx5_flow_lacp_miss(struct rte_eth_dev *dev)
7039 * The LACP matching is done by only using ether type since using
7040 * a multicast dst mac causes kernel to give low priority to this flow.
7042 static const struct rte_flow_item_eth lacp_spec = {
7043 .type = RTE_BE16(0x8809),
7045 static const struct rte_flow_item_eth lacp_mask = {
7048 const struct rte_flow_attr attr = {
7051 struct rte_flow_item items[] = {
7053 .type = RTE_FLOW_ITEM_TYPE_ETH,
7058 .type = RTE_FLOW_ITEM_TYPE_END,
7061 struct rte_flow_action actions[] = {
7063 .type = (enum rte_flow_action_type)
7064 MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS,
7067 .type = RTE_FLOW_ACTION_TYPE_END,
7070 struct rte_flow_error error;
7071 uint32_t flow_idx = flow_list_create(dev, MLX5_FLOW_TYPE_CTL,
7072 &attr, items, actions,
7083 * @see rte_flow_destroy()
7087 mlx5_flow_destroy(struct rte_eth_dev *dev,
7088 struct rte_flow *flow,
7089 struct rte_flow_error *error __rte_unused)
7091 flow_list_destroy(dev, MLX5_FLOW_TYPE_GEN,
7092 (uintptr_t)(void *)flow);
7097 * Destroy all flows.
7099 * @see rte_flow_flush()
7103 mlx5_flow_flush(struct rte_eth_dev *dev,
7104 struct rte_flow_error *error __rte_unused)
7106 mlx5_flow_list_flush(dev, MLX5_FLOW_TYPE_GEN, false);
7113 * @see rte_flow_isolate()
7117 mlx5_flow_isolate(struct rte_eth_dev *dev,
7119 struct rte_flow_error *error)
7121 struct mlx5_priv *priv = dev->data->dev_private;
7123 if (dev->data->dev_started) {
7124 rte_flow_error_set(error, EBUSY,
7125 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7127 "port must be stopped first");
7130 priv->isolated = !!enable;
7132 dev->dev_ops = &mlx5_dev_ops_isolate;
7134 dev->dev_ops = &mlx5_dev_ops;
7136 dev->rx_descriptor_status = mlx5_rx_descriptor_status;
7137 dev->tx_descriptor_status = mlx5_tx_descriptor_status;
7145 * @see rte_flow_query()
7149 flow_drv_query(struct rte_eth_dev *dev,
7151 const struct rte_flow_action *actions,
7153 struct rte_flow_error *error)
7155 struct mlx5_priv *priv = dev->data->dev_private;
7156 const struct mlx5_flow_driver_ops *fops;
7157 struct rte_flow *flow = mlx5_ipool_get(priv->flows[MLX5_FLOW_TYPE_GEN],
7159 enum mlx5_flow_drv_type ftype;
7162 return rte_flow_error_set(error, ENOENT,
7163 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7165 "invalid flow handle");
7167 ftype = flow->drv_type;
7168 MLX5_ASSERT(ftype > MLX5_FLOW_TYPE_MIN && ftype < MLX5_FLOW_TYPE_MAX);
7169 fops = flow_get_drv_ops(ftype);
7171 return fops->query(dev, flow, actions, data, error);
7177 * @see rte_flow_query()
7181 mlx5_flow_query(struct rte_eth_dev *dev,
7182 struct rte_flow *flow,
7183 const struct rte_flow_action *actions,
7185 struct rte_flow_error *error)
7189 ret = flow_drv_query(dev, (uintptr_t)(void *)flow, actions, data,
7197 * Get rte_flow callbacks.
7200 * Pointer to Ethernet device structure.
7202 * Pointer to operation-specific structure.
7207 mlx5_flow_ops_get(struct rte_eth_dev *dev __rte_unused,
7208 const struct rte_flow_ops **ops)
7210 *ops = &mlx5_flow_ops;
7215 * Validate meter policy actions.
7216 * Dispatcher for action type specific validation.
7219 * Pointer to the Ethernet device structure.
7221 * The meter policy action object to validate.
7223 * Attributes of flow to determine steering domain.
7224 * @param[out] is_rss
7226 * @param[out] domain_bitmap
7228 * @param[out] is_def_policy
7229 * Is default policy or not.
7231 * Perform verbose error reporting if not NULL. Initialized in case of
7235 * 0 on success, otherwise negative errno value.
7238 mlx5_flow_validate_mtr_acts(struct rte_eth_dev *dev,
7239 const struct rte_flow_action *actions[RTE_COLORS],
7240 struct rte_flow_attr *attr,
7242 uint8_t *domain_bitmap,
7243 uint8_t *policy_mode,
7244 struct rte_mtr_error *error)
7246 const struct mlx5_flow_driver_ops *fops;
7248 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7249 return fops->validate_mtr_acts(dev, actions, attr, is_rss,
7250 domain_bitmap, policy_mode, error);
7254 * Destroy the meter table set.
7257 * Pointer to Ethernet device.
7258 * @param[in] mtr_policy
7259 * Meter policy struct.
7262 mlx5_flow_destroy_mtr_acts(struct rte_eth_dev *dev,
7263 struct mlx5_flow_meter_policy *mtr_policy)
7265 const struct mlx5_flow_driver_ops *fops;
7267 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7268 fops->destroy_mtr_acts(dev, mtr_policy);
7272 * Create policy action, lock free,
7273 * (mutex should be acquired by caller).
7274 * Dispatcher for action type specific call.
7277 * Pointer to the Ethernet device structure.
7278 * @param[in] mtr_policy
7279 * Meter policy struct.
7281 * Action specification used to create meter actions.
7283 * Perform verbose error reporting if not NULL. Initialized in case of
7287 * 0 on success, otherwise negative errno value.
7290 mlx5_flow_create_mtr_acts(struct rte_eth_dev *dev,
7291 struct mlx5_flow_meter_policy *mtr_policy,
7292 const struct rte_flow_action *actions[RTE_COLORS],
7293 struct rte_mtr_error *error)
7295 const struct mlx5_flow_driver_ops *fops;
7297 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7298 return fops->create_mtr_acts(dev, mtr_policy, actions, error);
7302 * Create policy rules, lock free,
7303 * (mutex should be acquired by caller).
7304 * Dispatcher for action type specific call.
7307 * Pointer to the Ethernet device structure.
7308 * @param[in] mtr_policy
7309 * Meter policy struct.
7312 * 0 on success, -1 otherwise.
7315 mlx5_flow_create_policy_rules(struct rte_eth_dev *dev,
7316 struct mlx5_flow_meter_policy *mtr_policy)
7318 const struct mlx5_flow_driver_ops *fops;
7320 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7321 return fops->create_policy_rules(dev, mtr_policy);
7325 * Destroy policy rules, lock free,
7326 * (mutex should be acquired by caller).
7327 * Dispatcher for action type specific call.
7330 * Pointer to the Ethernet device structure.
7331 * @param[in] mtr_policy
7332 * Meter policy struct.
7335 mlx5_flow_destroy_policy_rules(struct rte_eth_dev *dev,
7336 struct mlx5_flow_meter_policy *mtr_policy)
7338 const struct mlx5_flow_driver_ops *fops;
7340 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7341 fops->destroy_policy_rules(dev, mtr_policy);
7345 * Destroy the default policy table set.
7348 * Pointer to Ethernet device.
7351 mlx5_flow_destroy_def_policy(struct rte_eth_dev *dev)
7353 const struct mlx5_flow_driver_ops *fops;
7355 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7356 fops->destroy_def_policy(dev);
7360 * Destroy the default policy table set.
7363 * Pointer to Ethernet device.
7366 * 0 on success, -1 otherwise.
7369 mlx5_flow_create_def_policy(struct rte_eth_dev *dev)
7371 const struct mlx5_flow_driver_ops *fops;
7373 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7374 return fops->create_def_policy(dev);
7378 * Create the needed meter and suffix tables.
7381 * Pointer to Ethernet device.
7384 * 0 on success, -1 otherwise.
7387 mlx5_flow_create_mtr_tbls(struct rte_eth_dev *dev,
7388 struct mlx5_flow_meter_info *fm,
7390 uint8_t domain_bitmap)
7392 const struct mlx5_flow_driver_ops *fops;
7394 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7395 return fops->create_mtr_tbls(dev, fm, mtr_idx, domain_bitmap);
7399 * Destroy the meter table set.
7402 * Pointer to Ethernet device.
7404 * Pointer to the meter table set.
7407 mlx5_flow_destroy_mtr_tbls(struct rte_eth_dev *dev,
7408 struct mlx5_flow_meter_info *fm)
7410 const struct mlx5_flow_driver_ops *fops;
7412 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7413 fops->destroy_mtr_tbls(dev, fm);
7417 * Destroy the global meter drop table.
7420 * Pointer to Ethernet device.
7423 mlx5_flow_destroy_mtr_drop_tbls(struct rte_eth_dev *dev)
7425 const struct mlx5_flow_driver_ops *fops;
7427 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7428 fops->destroy_mtr_drop_tbls(dev);
7432 * Destroy the sub policy table with RX queue.
7435 * Pointer to Ethernet device.
7436 * @param[in] mtr_policy
7437 * Pointer to meter policy table.
7440 mlx5_flow_destroy_sub_policy_with_rxq(struct rte_eth_dev *dev,
7441 struct mlx5_flow_meter_policy *mtr_policy)
7443 const struct mlx5_flow_driver_ops *fops;
7445 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7446 fops->destroy_sub_policy_with_rxq(dev, mtr_policy);
7450 * Allocate the needed aso flow meter id.
7453 * Pointer to Ethernet device.
7456 * Index to aso flow meter on success, NULL otherwise.
7459 mlx5_flow_mtr_alloc(struct rte_eth_dev *dev)
7461 const struct mlx5_flow_driver_ops *fops;
7463 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7464 return fops->create_meter(dev);
7468 * Free the aso flow meter id.
7471 * Pointer to Ethernet device.
7472 * @param[in] mtr_idx
7473 * Index to aso flow meter to be free.
7479 mlx5_flow_mtr_free(struct rte_eth_dev *dev, uint32_t mtr_idx)
7481 const struct mlx5_flow_driver_ops *fops;
7483 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7484 fops->free_meter(dev, mtr_idx);
7488 * Allocate a counter.
7491 * Pointer to Ethernet device structure.
7494 * Index to allocated counter on success, 0 otherwise.
7497 mlx5_counter_alloc(struct rte_eth_dev *dev)
7499 const struct mlx5_flow_driver_ops *fops;
7500 struct rte_flow_attr attr = { .transfer = 0 };
7502 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
7503 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7504 return fops->counter_alloc(dev);
7507 "port %u counter allocate is not supported.",
7508 dev->data->port_id);
7516 * Pointer to Ethernet device structure.
7518 * Index to counter to be free.
7521 mlx5_counter_free(struct rte_eth_dev *dev, uint32_t cnt)
7523 const struct mlx5_flow_driver_ops *fops;
7524 struct rte_flow_attr attr = { .transfer = 0 };
7526 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
7527 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7528 fops->counter_free(dev, cnt);
7532 "port %u counter free is not supported.",
7533 dev->data->port_id);
7537 * Query counter statistics.
7540 * Pointer to Ethernet device structure.
7542 * Index to counter to query.
7544 * Set to clear counter statistics.
7546 * The counter hits packets number to save.
7548 * The counter hits bytes number to save.
7551 * 0 on success, a negative errno value otherwise.
7554 mlx5_counter_query(struct rte_eth_dev *dev, uint32_t cnt,
7555 bool clear, uint64_t *pkts, uint64_t *bytes)
7557 const struct mlx5_flow_driver_ops *fops;
7558 struct rte_flow_attr attr = { .transfer = 0 };
7560 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
7561 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7562 return fops->counter_query(dev, cnt, clear, pkts, bytes);
7565 "port %u counter query is not supported.",
7566 dev->data->port_id);
7571 * Allocate a new memory for the counter values wrapped by all the needed
7575 * Pointer to mlx5_dev_ctx_shared object.
7578 * 0 on success, a negative errno value otherwise.
7581 mlx5_flow_create_counter_stat_mem_mng(struct mlx5_dev_ctx_shared *sh)
7583 struct mlx5_devx_mkey_attr mkey_attr;
7584 struct mlx5_counter_stats_mem_mng *mem_mng;
7585 volatile struct flow_counter_stats *raw_data;
7586 int raws_n = MLX5_CNT_CONTAINER_RESIZE + MLX5_MAX_PENDING_QUERIES;
7587 int size = (sizeof(struct flow_counter_stats) *
7588 MLX5_COUNTERS_PER_POOL +
7589 sizeof(struct mlx5_counter_stats_raw)) * raws_n +
7590 sizeof(struct mlx5_counter_stats_mem_mng);
7591 size_t pgsize = rte_mem_page_size();
7595 if (pgsize == (size_t)-1) {
7596 DRV_LOG(ERR, "Failed to get mem page size");
7600 mem = mlx5_malloc(MLX5_MEM_ZERO, size, pgsize, SOCKET_ID_ANY);
7605 mem_mng = (struct mlx5_counter_stats_mem_mng *)(mem + size) - 1;
7606 size = sizeof(*raw_data) * MLX5_COUNTERS_PER_POOL * raws_n;
7607 mem_mng->umem = mlx5_os_umem_reg(sh->ctx, mem, size,
7608 IBV_ACCESS_LOCAL_WRITE);
7609 if (!mem_mng->umem) {
7614 memset(&mkey_attr, 0, sizeof(mkey_attr));
7615 mkey_attr.addr = (uintptr_t)mem;
7616 mkey_attr.size = size;
7617 mkey_attr.umem_id = mlx5_os_get_umem_id(mem_mng->umem);
7618 mkey_attr.pd = sh->pdn;
7619 mkey_attr.relaxed_ordering_write = sh->cmng.relaxed_ordering_write;
7620 mkey_attr.relaxed_ordering_read = sh->cmng.relaxed_ordering_read;
7621 mem_mng->dm = mlx5_devx_cmd_mkey_create(sh->ctx, &mkey_attr);
7623 mlx5_os_umem_dereg(mem_mng->umem);
7628 mem_mng->raws = (struct mlx5_counter_stats_raw *)(mem + size);
7629 raw_data = (volatile struct flow_counter_stats *)mem;
7630 for (i = 0; i < raws_n; ++i) {
7631 mem_mng->raws[i].mem_mng = mem_mng;
7632 mem_mng->raws[i].data = raw_data + i * MLX5_COUNTERS_PER_POOL;
7634 for (i = 0; i < MLX5_MAX_PENDING_QUERIES; ++i)
7635 LIST_INSERT_HEAD(&sh->cmng.free_stat_raws,
7636 mem_mng->raws + MLX5_CNT_CONTAINER_RESIZE + i,
7638 LIST_INSERT_HEAD(&sh->cmng.mem_mngs, mem_mng, next);
7639 sh->cmng.mem_mng = mem_mng;
7644 * Set the statistic memory to the new counter pool.
7647 * Pointer to mlx5_dev_ctx_shared object.
7649 * Pointer to the pool to set the statistic memory.
7652 * 0 on success, a negative errno value otherwise.
7655 mlx5_flow_set_counter_stat_mem(struct mlx5_dev_ctx_shared *sh,
7656 struct mlx5_flow_counter_pool *pool)
7658 struct mlx5_flow_counter_mng *cmng = &sh->cmng;
7659 /* Resize statistic memory once used out. */
7660 if (!(pool->index % MLX5_CNT_CONTAINER_RESIZE) &&
7661 mlx5_flow_create_counter_stat_mem_mng(sh)) {
7662 DRV_LOG(ERR, "Cannot resize counter stat mem.");
7665 rte_spinlock_lock(&pool->sl);
7666 pool->raw = cmng->mem_mng->raws + pool->index %
7667 MLX5_CNT_CONTAINER_RESIZE;
7668 rte_spinlock_unlock(&pool->sl);
7669 pool->raw_hw = NULL;
7673 #define MLX5_POOL_QUERY_FREQ_US 1000000
7676 * Set the periodic procedure for triggering asynchronous batch queries for all
7677 * the counter pools.
7680 * Pointer to mlx5_dev_ctx_shared object.
7683 mlx5_set_query_alarm(struct mlx5_dev_ctx_shared *sh)
7685 uint32_t pools_n, us;
7687 pools_n = __atomic_load_n(&sh->cmng.n_valid, __ATOMIC_RELAXED);
7688 us = MLX5_POOL_QUERY_FREQ_US / pools_n;
7689 DRV_LOG(DEBUG, "Set alarm for %u pools each %u us", pools_n, us);
7690 if (rte_eal_alarm_set(us, mlx5_flow_query_alarm, sh)) {
7691 sh->cmng.query_thread_on = 0;
7692 DRV_LOG(ERR, "Cannot reinitialize query alarm");
7694 sh->cmng.query_thread_on = 1;
7699 * The periodic procedure for triggering asynchronous batch queries for all the
7700 * counter pools. This function is probably called by the host thread.
7703 * The parameter for the alarm process.
7706 mlx5_flow_query_alarm(void *arg)
7708 struct mlx5_dev_ctx_shared *sh = arg;
7710 uint16_t pool_index = sh->cmng.pool_index;
7711 struct mlx5_flow_counter_mng *cmng = &sh->cmng;
7712 struct mlx5_flow_counter_pool *pool;
7715 if (sh->cmng.pending_queries >= MLX5_MAX_PENDING_QUERIES)
7717 rte_spinlock_lock(&cmng->pool_update_sl);
7718 pool = cmng->pools[pool_index];
7719 n_valid = cmng->n_valid;
7720 rte_spinlock_unlock(&cmng->pool_update_sl);
7721 /* Set the statistic memory to the new created pool. */
7722 if ((!pool->raw && mlx5_flow_set_counter_stat_mem(sh, pool)))
7725 /* There is a pool query in progress. */
7728 LIST_FIRST(&sh->cmng.free_stat_raws);
7730 /* No free counter statistics raw memory. */
7733 * Identify the counters released between query trigger and query
7734 * handle more efficiently. The counter released in this gap period
7735 * should wait for a new round of query as the new arrived packets
7736 * will not be taken into account.
7739 ret = mlx5_devx_cmd_flow_counter_query(pool->min_dcs, 0,
7740 MLX5_COUNTERS_PER_POOL,
7742 pool->raw_hw->mem_mng->dm->id,
7746 (uint64_t)(uintptr_t)pool);
7748 DRV_LOG(ERR, "Failed to trigger asynchronous query for dcs ID"
7749 " %d", pool->min_dcs->id);
7750 pool->raw_hw = NULL;
7753 LIST_REMOVE(pool->raw_hw, next);
7754 sh->cmng.pending_queries++;
7756 if (pool_index >= n_valid)
7759 sh->cmng.pool_index = pool_index;
7760 mlx5_set_query_alarm(sh);
7764 * Check and callback event for new aged flow in the counter pool
7767 * Pointer to mlx5_dev_ctx_shared object.
7769 * Pointer to Current counter pool.
7772 mlx5_flow_aging_check(struct mlx5_dev_ctx_shared *sh,
7773 struct mlx5_flow_counter_pool *pool)
7775 struct mlx5_priv *priv;
7776 struct mlx5_flow_counter *cnt;
7777 struct mlx5_age_info *age_info;
7778 struct mlx5_age_param *age_param;
7779 struct mlx5_counter_stats_raw *cur = pool->raw_hw;
7780 struct mlx5_counter_stats_raw *prev = pool->raw;
7781 const uint64_t curr_time = MLX5_CURR_TIME_SEC;
7782 const uint32_t time_delta = curr_time - pool->time_of_last_age_check;
7783 uint16_t expected = AGE_CANDIDATE;
7786 pool->time_of_last_age_check = curr_time;
7787 for (i = 0; i < MLX5_COUNTERS_PER_POOL; ++i) {
7788 cnt = MLX5_POOL_GET_CNT(pool, i);
7789 age_param = MLX5_CNT_TO_AGE(cnt);
7790 if (__atomic_load_n(&age_param->state,
7791 __ATOMIC_RELAXED) != AGE_CANDIDATE)
7793 if (cur->data[i].hits != prev->data[i].hits) {
7794 __atomic_store_n(&age_param->sec_since_last_hit, 0,
7798 if (__atomic_add_fetch(&age_param->sec_since_last_hit,
7800 __ATOMIC_RELAXED) <= age_param->timeout)
7803 * Hold the lock first, or if between the
7804 * state AGE_TMOUT and tailq operation the
7805 * release happened, the release procedure
7806 * may delete a non-existent tailq node.
7808 priv = rte_eth_devices[age_param->port_id].data->dev_private;
7809 age_info = GET_PORT_AGE_INFO(priv);
7810 rte_spinlock_lock(&age_info->aged_sl);
7811 if (__atomic_compare_exchange_n(&age_param->state, &expected,
7814 __ATOMIC_RELAXED)) {
7815 TAILQ_INSERT_TAIL(&age_info->aged_counters, cnt, next);
7816 MLX5_AGE_SET(age_info, MLX5_AGE_EVENT_NEW);
7818 rte_spinlock_unlock(&age_info->aged_sl);
7820 mlx5_age_event_prepare(sh);
7824 * Handler for the HW respond about ready values from an asynchronous batch
7825 * query. This function is probably called by the host thread.
7828 * The pointer to the shared device context.
7829 * @param[in] async_id
7830 * The Devx async ID.
7832 * The status of the completion.
7835 mlx5_flow_async_pool_query_handle(struct mlx5_dev_ctx_shared *sh,
7836 uint64_t async_id, int status)
7838 struct mlx5_flow_counter_pool *pool =
7839 (struct mlx5_flow_counter_pool *)(uintptr_t)async_id;
7840 struct mlx5_counter_stats_raw *raw_to_free;
7841 uint8_t query_gen = pool->query_gen ^ 1;
7842 struct mlx5_flow_counter_mng *cmng = &sh->cmng;
7843 enum mlx5_counter_type cnt_type =
7844 pool->is_aged ? MLX5_COUNTER_TYPE_AGE :
7845 MLX5_COUNTER_TYPE_ORIGIN;
7847 if (unlikely(status)) {
7848 raw_to_free = pool->raw_hw;
7850 raw_to_free = pool->raw;
7852 mlx5_flow_aging_check(sh, pool);
7853 rte_spinlock_lock(&pool->sl);
7854 pool->raw = pool->raw_hw;
7855 rte_spinlock_unlock(&pool->sl);
7856 /* Be sure the new raw counters data is updated in memory. */
7858 if (!TAILQ_EMPTY(&pool->counters[query_gen])) {
7859 rte_spinlock_lock(&cmng->csl[cnt_type]);
7860 TAILQ_CONCAT(&cmng->counters[cnt_type],
7861 &pool->counters[query_gen], next);
7862 rte_spinlock_unlock(&cmng->csl[cnt_type]);
7865 LIST_INSERT_HEAD(&sh->cmng.free_stat_raws, raw_to_free, next);
7866 pool->raw_hw = NULL;
7867 sh->cmng.pending_queries--;
7871 flow_group_to_table(uint32_t port_id, uint32_t group, uint32_t *table,
7872 const struct flow_grp_info *grp_info,
7873 struct rte_flow_error *error)
7875 if (grp_info->transfer && grp_info->external &&
7876 grp_info->fdb_def_rule) {
7877 if (group == UINT32_MAX)
7878 return rte_flow_error_set
7880 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
7882 "group index not supported");
7887 DRV_LOG(DEBUG, "port %u group=%#x table=%#x", port_id, group, *table);
7892 * Translate the rte_flow group index to HW table value.
7894 * If tunnel offload is disabled, all group ids converted to flow table
7895 * id using the standard method.
7896 * If tunnel offload is enabled, group id can be converted using the
7897 * standard or tunnel conversion method. Group conversion method
7898 * selection depends on flags in `grp_info` parameter:
7899 * - Internal (grp_info.external == 0) groups conversion uses the
7901 * - Group ids in JUMP action converted with the tunnel conversion.
7902 * - Group id in rule attribute conversion depends on a rule type and
7904 * ** non zero group attributes converted with the tunnel method
7905 * ** zero group attribute in non-tunnel rule is converted using the
7906 * standard method - there's only one root table
7907 * ** zero group attribute in steer tunnel rule is converted with the
7908 * standard method - single root table
7909 * ** zero group attribute in match tunnel rule is a special OvS
7910 * case: that value is used for portability reasons. That group
7911 * id is converted with the tunnel conversion method.
7916 * PMD tunnel offload object
7918 * rte_flow group index value.
7921 * @param[in] grp_info
7922 * flags used for conversion
7924 * Pointer to error structure.
7927 * 0 on success, a negative errno value otherwise and rte_errno is set.
7930 mlx5_flow_group_to_table(struct rte_eth_dev *dev,
7931 const struct mlx5_flow_tunnel *tunnel,
7932 uint32_t group, uint32_t *table,
7933 const struct flow_grp_info *grp_info,
7934 struct rte_flow_error *error)
7937 bool standard_translation;
7939 if (!grp_info->skip_scale && grp_info->external &&
7940 group < MLX5_MAX_TABLES_EXTERNAL)
7941 group *= MLX5_FLOW_TABLE_FACTOR;
7942 if (is_tunnel_offload_active(dev)) {
7943 standard_translation = !grp_info->external ||
7944 grp_info->std_tbl_fix;
7946 standard_translation = true;
7949 "port %u group=%u transfer=%d external=%d fdb_def_rule=%d translate=%s",
7950 dev->data->port_id, group, grp_info->transfer,
7951 grp_info->external, grp_info->fdb_def_rule,
7952 standard_translation ? "STANDARD" : "TUNNEL");
7953 if (standard_translation)
7954 ret = flow_group_to_table(dev->data->port_id, group, table,
7957 ret = tunnel_flow_group_to_flow_table(dev, tunnel, group,
7964 * Discover availability of metadata reg_c's.
7966 * Iteratively use test flows to check availability.
7969 * Pointer to the Ethernet device structure.
7972 * 0 on success, a negative errno value otherwise and rte_errno is set.
7975 mlx5_flow_discover_mreg_c(struct rte_eth_dev *dev)
7977 struct mlx5_priv *priv = dev->data->dev_private;
7978 struct mlx5_dev_config *config = &priv->config;
7979 enum modify_reg idx;
7982 /* reg_c[0] and reg_c[1] are reserved. */
7983 config->flow_mreg_c[n++] = REG_C_0;
7984 config->flow_mreg_c[n++] = REG_C_1;
7985 /* Discover availability of other reg_c's. */
7986 for (idx = REG_C_2; idx <= REG_C_7; ++idx) {
7987 struct rte_flow_attr attr = {
7988 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
7989 .priority = MLX5_FLOW_LOWEST_PRIO_INDICATOR,
7992 struct rte_flow_item items[] = {
7994 .type = RTE_FLOW_ITEM_TYPE_END,
7997 struct rte_flow_action actions[] = {
7999 .type = (enum rte_flow_action_type)
8000 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
8001 .conf = &(struct mlx5_flow_action_copy_mreg){
8007 .type = RTE_FLOW_ACTION_TYPE_JUMP,
8008 .conf = &(struct rte_flow_action_jump){
8009 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
8013 .type = RTE_FLOW_ACTION_TYPE_END,
8017 struct rte_flow *flow;
8018 struct rte_flow_error error;
8020 if (!config->dv_flow_en)
8022 /* Create internal flow, validation skips copy action. */
8023 flow_idx = flow_list_create(dev, MLX5_FLOW_TYPE_GEN, &attr,
8024 items, actions, false, &error);
8025 flow = mlx5_ipool_get(priv->flows[MLX5_FLOW_TYPE_GEN],
8029 config->flow_mreg_c[n++] = idx;
8030 flow_list_destroy(dev, MLX5_FLOW_TYPE_GEN, flow_idx);
8032 for (; n < MLX5_MREG_C_NUM; ++n)
8033 config->flow_mreg_c[n] = REG_NON;
8038 save_dump_file(const uint8_t *data, uint32_t size,
8039 uint32_t type, uint32_t id, void *arg, FILE *file)
8041 char line[BUF_SIZE];
8044 uint32_t actions_num;
8045 struct rte_flow_query_count *count;
8047 memset(line, 0, BUF_SIZE);
8049 case DR_DUMP_REC_TYPE_PMD_MODIFY_HDR:
8050 actions_num = *(uint32_t *)(arg);
8051 out += snprintf(line + out, BUF_SIZE - out, "%d,0x%x,%d,",
8052 type, id, actions_num);
8054 case DR_DUMP_REC_TYPE_PMD_PKT_REFORMAT:
8055 out += snprintf(line + out, BUF_SIZE - out, "%d,0x%x,",
8058 case DR_DUMP_REC_TYPE_PMD_COUNTER:
8059 count = (struct rte_flow_query_count *)arg;
8060 fprintf(file, "%d,0x%x,%" PRIu64 ",%" PRIu64 "\n", type,
8061 id, count->hits, count->bytes);
8067 for (k = 0; k < size; k++) {
8068 /* Make sure we do not overrun the line buffer length. */
8069 if (out >= BUF_SIZE - 4) {
8073 out += snprintf(line + out, BUF_SIZE - out, "%02x",
8076 fprintf(file, "%s\n", line);
8081 mlx5_flow_query_counter(struct rte_eth_dev *dev, struct rte_flow *flow,
8082 struct rte_flow_query_count *count, struct rte_flow_error *error)
8084 struct rte_flow_action action[2];
8085 enum mlx5_flow_drv_type ftype;
8086 const struct mlx5_flow_driver_ops *fops;
8089 return rte_flow_error_set(error, ENOENT,
8090 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8092 "invalid flow handle");
8094 action[0].type = RTE_FLOW_ACTION_TYPE_COUNT;
8095 action[1].type = RTE_FLOW_ACTION_TYPE_END;
8096 if (flow->counter) {
8097 memset(count, 0, sizeof(struct rte_flow_query_count));
8098 ftype = (enum mlx5_flow_drv_type)(flow->drv_type);
8099 MLX5_ASSERT(ftype > MLX5_FLOW_TYPE_MIN &&
8100 ftype < MLX5_FLOW_TYPE_MAX);
8101 fops = flow_get_drv_ops(ftype);
8102 return fops->query(dev, flow, action, count, error);
8107 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
8109 * Dump flow ipool data to file
8112 * The pointer to Ethernet device.
8114 * A pointer to a file for output.
8116 * Perform verbose error reporting if not NULL. PMDs initialize this
8117 * structure in case of error only.
8119 * 0 on success, a negative value otherwise.
8122 mlx5_flow_dev_dump_ipool(struct rte_eth_dev *dev,
8123 struct rte_flow *flow, FILE *file,
8124 struct rte_flow_error *error)
8126 struct mlx5_priv *priv = dev->data->dev_private;
8127 struct mlx5_flow_dv_modify_hdr_resource *modify_hdr;
8128 struct mlx5_flow_dv_encap_decap_resource *encap_decap;
8129 uint32_t handle_idx;
8130 struct mlx5_flow_handle *dh;
8131 struct rte_flow_query_count count;
8132 uint32_t actions_num;
8133 const uint8_t *data;
8139 return rte_flow_error_set(error, ENOENT,
8140 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8142 "invalid flow handle");
8144 handle_idx = flow->dev_handles;
8145 while (handle_idx) {
8146 dh = mlx5_ipool_get(priv->sh->ipool
8147 [MLX5_IPOOL_MLX5_FLOW], handle_idx);
8150 handle_idx = dh->next.next;
8151 id = (uint32_t)(uintptr_t)dh->drv_flow;
8154 type = DR_DUMP_REC_TYPE_PMD_COUNTER;
8155 if (!mlx5_flow_query_counter(dev, flow, &count, error))
8156 save_dump_file(NULL, 0, type,
8157 id, (void *)&count, file);
8159 /* Get modify_hdr and encap_decap buf from ipools. */
8161 modify_hdr = dh->dvh.modify_hdr;
8163 if (dh->dvh.rix_encap_decap) {
8164 encap_decap = mlx5_ipool_get(priv->sh->ipool
8165 [MLX5_IPOOL_DECAP_ENCAP],
8166 dh->dvh.rix_encap_decap);
8169 data = (const uint8_t *)modify_hdr->actions;
8170 size = (size_t)(modify_hdr->actions_num) * 8;
8171 actions_num = modify_hdr->actions_num;
8172 type = DR_DUMP_REC_TYPE_PMD_MODIFY_HDR;
8173 save_dump_file(data, size, type, id,
8174 (void *)(&actions_num), file);
8177 data = encap_decap->buf;
8178 size = encap_decap->size;
8179 type = DR_DUMP_REC_TYPE_PMD_PKT_REFORMAT;
8180 save_dump_file(data, size, type,
8189 * Dump flow raw hw data to file
8192 * The pointer to Ethernet device.
8194 * A pointer to a file for output.
8196 * Perform verbose error reporting if not NULL. PMDs initialize this
8197 * structure in case of error only.
8199 * 0 on success, a nagative value otherwise.
8202 mlx5_flow_dev_dump(struct rte_eth_dev *dev, struct rte_flow *flow_idx,
8204 struct rte_flow_error *error __rte_unused)
8206 struct mlx5_priv *priv = dev->data->dev_private;
8207 struct mlx5_dev_ctx_shared *sh = priv->sh;
8208 uint32_t handle_idx;
8210 struct mlx5_flow_handle *dh;
8211 struct rte_flow *flow;
8212 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
8216 if (!priv->config.dv_flow_en) {
8217 if (fputs("device dv flow disabled\n", file) <= 0)
8224 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
8225 MLX5_IPOOL_FOREACH(priv->flows[MLX5_FLOW_TYPE_GEN], idx, flow)
8226 mlx5_flow_dev_dump_ipool(dev, flow, file, error);
8228 return mlx5_devx_cmd_flow_dump(sh->fdb_domain,
8230 sh->tx_domain, file);
8233 flow = mlx5_ipool_get(priv->flows[MLX5_FLOW_TYPE_GEN],
8234 (uintptr_t)(void *)flow_idx);
8238 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
8239 mlx5_flow_dev_dump_ipool(dev, flow, file, error);
8241 handle_idx = flow->dev_handles;
8242 while (handle_idx) {
8243 dh = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
8248 ret = mlx5_devx_cmd_flow_single_dump(dh->drv_flow,
8253 handle_idx = dh->next.next;
8259 * Get aged-out flows.
8262 * Pointer to the Ethernet device structure.
8263 * @param[in] context
8264 * The address of an array of pointers to the aged-out flows contexts.
8265 * @param[in] nb_countexts
8266 * The length of context array pointers.
8268 * Perform verbose error reporting if not NULL. Initialized in case of
8272 * how many contexts get in success, otherwise negative errno value.
8273 * if nb_contexts is 0, return the amount of all aged contexts.
8274 * if nb_contexts is not 0 , return the amount of aged flows reported
8275 * in the context array.
8278 mlx5_flow_get_aged_flows(struct rte_eth_dev *dev, void **contexts,
8279 uint32_t nb_contexts, struct rte_flow_error *error)
8281 const struct mlx5_flow_driver_ops *fops;
8282 struct rte_flow_attr attr = { .transfer = 0 };
8284 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
8285 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
8286 return fops->get_aged_flows(dev, contexts, nb_contexts,
8290 "port %u get aged flows is not supported.",
8291 dev->data->port_id);
8295 /* Wrapper for driver action_validate op callback */
8297 flow_drv_action_validate(struct rte_eth_dev *dev,
8298 const struct rte_flow_indir_action_conf *conf,
8299 const struct rte_flow_action *action,
8300 const struct mlx5_flow_driver_ops *fops,
8301 struct rte_flow_error *error)
8303 static const char err_msg[] = "indirect action validation unsupported";
8305 if (!fops->action_validate) {
8306 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
8307 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
8311 return fops->action_validate(dev, conf, action, error);
8315 * Destroys the shared action by handle.
8318 * Pointer to Ethernet device structure.
8320 * Handle for the indirect action object to be destroyed.
8322 * Perform verbose error reporting if not NULL. PMDs initialize this
8323 * structure in case of error only.
8326 * 0 on success, a negative errno value otherwise and rte_errno is set.
8328 * @note: wrapper for driver action_create op callback.
8331 mlx5_action_handle_destroy(struct rte_eth_dev *dev,
8332 struct rte_flow_action_handle *handle,
8333 struct rte_flow_error *error)
8335 static const char err_msg[] = "indirect action destruction unsupported";
8336 struct rte_flow_attr attr = { .transfer = 0 };
8337 const struct mlx5_flow_driver_ops *fops =
8338 flow_get_drv_ops(flow_get_drv_type(dev, &attr));
8340 if (!fops->action_destroy) {
8341 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
8342 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
8346 return fops->action_destroy(dev, handle, error);
8349 /* Wrapper for driver action_destroy op callback */
8351 flow_drv_action_update(struct rte_eth_dev *dev,
8352 struct rte_flow_action_handle *handle,
8354 const struct mlx5_flow_driver_ops *fops,
8355 struct rte_flow_error *error)
8357 static const char err_msg[] = "indirect action update unsupported";
8359 if (!fops->action_update) {
8360 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
8361 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
8365 return fops->action_update(dev, handle, update, error);
8368 /* Wrapper for driver action_destroy op callback */
8370 flow_drv_action_query(struct rte_eth_dev *dev,
8371 const struct rte_flow_action_handle *handle,
8373 const struct mlx5_flow_driver_ops *fops,
8374 struct rte_flow_error *error)
8376 static const char err_msg[] = "indirect action query unsupported";
8378 if (!fops->action_query) {
8379 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
8380 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
8384 return fops->action_query(dev, handle, data, error);
8388 * Create indirect action for reuse in multiple flow rules.
8391 * Pointer to Ethernet device structure.
8393 * Pointer to indirect action object configuration.
8395 * Action configuration for indirect action object creation.
8397 * Perform verbose error reporting if not NULL. PMDs initialize this
8398 * structure in case of error only.
8400 * A valid handle in case of success, NULL otherwise and rte_errno is set.
8402 static struct rte_flow_action_handle *
8403 mlx5_action_handle_create(struct rte_eth_dev *dev,
8404 const struct rte_flow_indir_action_conf *conf,
8405 const struct rte_flow_action *action,
8406 struct rte_flow_error *error)
8408 static const char err_msg[] = "indirect action creation unsupported";
8409 struct rte_flow_attr attr = { .transfer = 0 };
8410 const struct mlx5_flow_driver_ops *fops =
8411 flow_get_drv_ops(flow_get_drv_type(dev, &attr));
8413 if (flow_drv_action_validate(dev, conf, action, fops, error))
8415 if (!fops->action_create) {
8416 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
8417 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
8421 return fops->action_create(dev, conf, action, error);
8425 * Updates inplace the indirect action configuration pointed by *handle*
8426 * with the configuration provided as *update* argument.
8427 * The update of the indirect action configuration effects all flow rules
8428 * reusing the action via handle.
8431 * Pointer to Ethernet device structure.
8433 * Handle for the indirect action to be updated.
8435 * Action specification used to modify the action pointed by handle.
8436 * *update* could be of same type with the action pointed by the *handle*
8437 * handle argument, or some other structures like a wrapper, depending on
8438 * the indirect action type.
8440 * Perform verbose error reporting if not NULL. PMDs initialize this
8441 * structure in case of error only.
8444 * 0 on success, a negative errno value otherwise and rte_errno is set.
8447 mlx5_action_handle_update(struct rte_eth_dev *dev,
8448 struct rte_flow_action_handle *handle,
8450 struct rte_flow_error *error)
8452 struct rte_flow_attr attr = { .transfer = 0 };
8453 const struct mlx5_flow_driver_ops *fops =
8454 flow_get_drv_ops(flow_get_drv_type(dev, &attr));
8457 ret = flow_drv_action_validate(dev, NULL,
8458 (const struct rte_flow_action *)update, fops, error);
8461 return flow_drv_action_update(dev, handle, update, fops,
8466 * Query the indirect action by handle.
8468 * This function allows retrieving action-specific data such as counters.
8469 * Data is gathered by special action which may be present/referenced in
8470 * more than one flow rule definition.
8472 * see @RTE_FLOW_ACTION_TYPE_COUNT
8475 * Pointer to Ethernet device structure.
8477 * Handle for the indirect action to query.
8478 * @param[in, out] data
8479 * Pointer to storage for the associated query data type.
8481 * Perform verbose error reporting if not NULL. PMDs initialize this
8482 * structure in case of error only.
8485 * 0 on success, a negative errno value otherwise and rte_errno is set.
8488 mlx5_action_handle_query(struct rte_eth_dev *dev,
8489 const struct rte_flow_action_handle *handle,
8491 struct rte_flow_error *error)
8493 struct rte_flow_attr attr = { .transfer = 0 };
8494 const struct mlx5_flow_driver_ops *fops =
8495 flow_get_drv_ops(flow_get_drv_type(dev, &attr));
8497 return flow_drv_action_query(dev, handle, data, fops, error);
8501 * Destroy all indirect actions (shared RSS).
8504 * Pointer to Ethernet device.
8507 * 0 on success, a negative errno value otherwise and rte_errno is set.
8510 mlx5_action_handle_flush(struct rte_eth_dev *dev)
8512 struct rte_flow_error error;
8513 struct mlx5_priv *priv = dev->data->dev_private;
8514 struct mlx5_shared_action_rss *shared_rss;
8518 ILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
8519 priv->rss_shared_actions, idx, shared_rss, next) {
8520 ret |= mlx5_action_handle_destroy(dev,
8521 (struct rte_flow_action_handle *)(uintptr_t)idx, &error);
8526 #ifndef HAVE_MLX5DV_DR
8527 #define MLX5_DOMAIN_SYNC_FLOW ((1 << 0) | (1 << 1))
8529 #define MLX5_DOMAIN_SYNC_FLOW \
8530 (MLX5DV_DR_DOMAIN_SYNC_FLAGS_SW | MLX5DV_DR_DOMAIN_SYNC_FLAGS_HW)
8533 int rte_pmd_mlx5_sync_flow(uint16_t port_id, uint32_t domains)
8535 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
8536 const struct mlx5_flow_driver_ops *fops;
8538 struct rte_flow_attr attr = { .transfer = 0 };
8540 fops = flow_get_drv_ops(flow_get_drv_type(dev, &attr));
8541 ret = fops->sync_domain(dev, domains, MLX5_DOMAIN_SYNC_FLOW);
8547 const struct mlx5_flow_tunnel *
8548 mlx5_get_tof(const struct rte_flow_item *item,
8549 const struct rte_flow_action *action,
8550 enum mlx5_tof_rule_type *rule_type)
8552 for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
8553 if (item->type == (typeof(item->type))
8554 MLX5_RTE_FLOW_ITEM_TYPE_TUNNEL) {
8555 *rule_type = MLX5_TUNNEL_OFFLOAD_MATCH_RULE;
8556 return flow_items_to_tunnel(item);
8559 for (; action->conf != RTE_FLOW_ACTION_TYPE_END; action++) {
8560 if (action->type == (typeof(action->type))
8561 MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET) {
8562 *rule_type = MLX5_TUNNEL_OFFLOAD_SET_RULE;
8563 return flow_actions_to_tunnel(action);
8570 * tunnel offload functionalilty is defined for DV environment only
8572 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
8574 union tunnel_offload_mark {
8577 uint32_t app_reserve:8;
8578 uint32_t table_id:15;
8579 uint32_t transfer:1;
8580 uint32_t _unused_:8;
8585 mlx5_access_tunnel_offload_db
8586 (struct rte_eth_dev *dev,
8587 bool (*match)(struct rte_eth_dev *,
8588 struct mlx5_flow_tunnel *, const void *),
8589 void (*hit)(struct rte_eth_dev *, struct mlx5_flow_tunnel *, void *),
8590 void (*miss)(struct rte_eth_dev *, void *),
8591 void *ctx, bool lock_op);
8594 flow_tunnel_add_default_miss(struct rte_eth_dev *dev,
8595 struct rte_flow *flow,
8596 const struct rte_flow_attr *attr,
8597 const struct rte_flow_action *app_actions,
8599 const struct mlx5_flow_tunnel *tunnel,
8600 struct tunnel_default_miss_ctx *ctx,
8601 struct rte_flow_error *error)
8603 struct mlx5_priv *priv = dev->data->dev_private;
8604 struct mlx5_flow *dev_flow;
8605 struct rte_flow_attr miss_attr = *attr;
8606 const struct rte_flow_item miss_items[2] = {
8608 .type = RTE_FLOW_ITEM_TYPE_ETH,
8614 .type = RTE_FLOW_ITEM_TYPE_END,
8620 union tunnel_offload_mark mark_id;
8621 struct rte_flow_action_mark miss_mark;
8622 struct rte_flow_action miss_actions[3] = {
8623 [0] = { .type = RTE_FLOW_ACTION_TYPE_MARK, .conf = &miss_mark },
8624 [2] = { .type = RTE_FLOW_ACTION_TYPE_END, .conf = NULL }
8626 const struct rte_flow_action_jump *jump_data;
8627 uint32_t i, flow_table = 0; /* prevent compilation warning */
8628 struct flow_grp_info grp_info = {
8630 .transfer = attr->transfer,
8631 .fdb_def_rule = !!priv->fdb_def_rule,
8636 if (!attr->transfer) {
8639 miss_actions[1].type = RTE_FLOW_ACTION_TYPE_RSS;
8640 q_size = priv->reta_idx_n * sizeof(ctx->queue[0]);
8641 ctx->queue = mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO, q_size,
8644 return rte_flow_error_set
8646 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
8647 NULL, "invalid default miss RSS");
8648 ctx->action_rss.func = RTE_ETH_HASH_FUNCTION_DEFAULT,
8649 ctx->action_rss.level = 0,
8650 ctx->action_rss.types = priv->rss_conf.rss_hf,
8651 ctx->action_rss.key_len = priv->rss_conf.rss_key_len,
8652 ctx->action_rss.queue_num = priv->reta_idx_n,
8653 ctx->action_rss.key = priv->rss_conf.rss_key,
8654 ctx->action_rss.queue = ctx->queue;
8655 if (!priv->reta_idx_n || !priv->rxqs_n)
8656 return rte_flow_error_set
8658 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
8659 NULL, "invalid port configuration");
8660 if (!(dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG))
8661 ctx->action_rss.types = 0;
8662 for (i = 0; i != priv->reta_idx_n; ++i)
8663 ctx->queue[i] = (*priv->reta_idx)[i];
8665 miss_actions[1].type = RTE_FLOW_ACTION_TYPE_JUMP;
8666 ctx->miss_jump.group = MLX5_TNL_MISS_FDB_JUMP_GRP;
8668 miss_actions[1].conf = (typeof(miss_actions[1].conf))ctx->raw;
8669 for (; app_actions->type != RTE_FLOW_ACTION_TYPE_JUMP; app_actions++);
8670 jump_data = app_actions->conf;
8671 miss_attr.priority = MLX5_TNL_MISS_RULE_PRIORITY;
8672 miss_attr.group = jump_data->group;
8673 ret = mlx5_flow_group_to_table(dev, tunnel, jump_data->group,
8674 &flow_table, &grp_info, error);
8676 return rte_flow_error_set(error, EINVAL,
8677 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
8678 NULL, "invalid tunnel id");
8679 mark_id.app_reserve = 0;
8680 mark_id.table_id = tunnel_flow_tbl_to_id(flow_table);
8681 mark_id.transfer = !!attr->transfer;
8682 mark_id._unused_ = 0;
8683 miss_mark.id = mark_id.val;
8684 dev_flow = flow_drv_prepare(dev, flow, &miss_attr,
8685 miss_items, miss_actions, flow_idx, error);
8688 dev_flow->flow = flow;
8689 dev_flow->external = true;
8690 dev_flow->tunnel = tunnel;
8691 dev_flow->tof_type = MLX5_TUNNEL_OFFLOAD_MISS_RULE;
8692 /* Subflow object was created, we must include one in the list. */
8693 SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
8694 dev_flow->handle, next);
8696 "port %u tunnel type=%d id=%u miss rule priority=%u group=%u",
8697 dev->data->port_id, tunnel->app_tunnel.type,
8698 tunnel->tunnel_id, miss_attr.priority, miss_attr.group);
8699 ret = flow_drv_translate(dev, dev_flow, &miss_attr, miss_items,
8700 miss_actions, error);
8702 ret = flow_mreg_update_copy_table(dev, flow, miss_actions,
8708 static const struct mlx5_flow_tbl_data_entry *
8709 tunnel_mark_decode(struct rte_eth_dev *dev, uint32_t mark)
8711 struct mlx5_priv *priv = dev->data->dev_private;
8712 struct mlx5_dev_ctx_shared *sh = priv->sh;
8713 struct mlx5_list_entry *he;
8714 union tunnel_offload_mark mbits = { .val = mark };
8715 union mlx5_flow_tbl_key table_key = {
8717 .level = tunnel_id_to_flow_tbl(mbits.table_id),
8721 .is_fdb = !!mbits.transfer,
8725 struct mlx5_flow_cb_ctx ctx = {
8726 .data = &table_key.v64,
8729 he = mlx5_hlist_lookup(sh->flow_tbls, table_key.v64, &ctx);
8731 container_of(he, struct mlx5_flow_tbl_data_entry, entry) : NULL;
8735 mlx5_flow_tunnel_grp2tbl_remove_cb(void *tool_ctx,
8736 struct mlx5_list_entry *entry)
8738 struct mlx5_dev_ctx_shared *sh = tool_ctx;
8739 struct tunnel_tbl_entry *tte = container_of(entry, typeof(*tte), hash);
8741 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TNL_TBL_ID],
8742 tunnel_flow_tbl_to_id(tte->flow_table));
8747 mlx5_flow_tunnel_grp2tbl_match_cb(void *tool_ctx __rte_unused,
8748 struct mlx5_list_entry *entry, void *cb_ctx)
8750 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
8751 union tunnel_tbl_key tbl = {
8752 .val = *(uint64_t *)(ctx->data),
8754 struct tunnel_tbl_entry *tte = container_of(entry, typeof(*tte), hash);
8756 return tbl.tunnel_id != tte->tunnel_id || tbl.group != tte->group;
8759 static struct mlx5_list_entry *
8760 mlx5_flow_tunnel_grp2tbl_create_cb(void *tool_ctx, void *cb_ctx)
8762 struct mlx5_dev_ctx_shared *sh = tool_ctx;
8763 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
8764 struct tunnel_tbl_entry *tte;
8765 union tunnel_tbl_key tbl = {
8766 .val = *(uint64_t *)(ctx->data),
8769 tte = mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO,
8774 mlx5_ipool_malloc(sh->ipool[MLX5_IPOOL_TNL_TBL_ID],
8776 if (tte->flow_table >= MLX5_MAX_TABLES) {
8777 DRV_LOG(ERR, "Tunnel TBL ID %d exceed max limit.",
8779 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TNL_TBL_ID],
8782 } else if (!tte->flow_table) {
8785 tte->flow_table = tunnel_id_to_flow_tbl(tte->flow_table);
8786 tte->tunnel_id = tbl.tunnel_id;
8787 tte->group = tbl.group;
8795 static struct mlx5_list_entry *
8796 mlx5_flow_tunnel_grp2tbl_clone_cb(void *tool_ctx __rte_unused,
8797 struct mlx5_list_entry *oentry,
8798 void *cb_ctx __rte_unused)
8800 struct tunnel_tbl_entry *tte = mlx5_malloc(MLX5_MEM_SYS, sizeof(*tte),
8805 memcpy(tte, oentry, sizeof(*tte));
8810 mlx5_flow_tunnel_grp2tbl_clone_free_cb(void *tool_ctx __rte_unused,
8811 struct mlx5_list_entry *entry)
8813 struct tunnel_tbl_entry *tte = container_of(entry, typeof(*tte), hash);
8819 tunnel_flow_group_to_flow_table(struct rte_eth_dev *dev,
8820 const struct mlx5_flow_tunnel *tunnel,
8821 uint32_t group, uint32_t *table,
8822 struct rte_flow_error *error)
8824 struct mlx5_list_entry *he;
8825 struct tunnel_tbl_entry *tte;
8826 union tunnel_tbl_key key = {
8827 .tunnel_id = tunnel ? tunnel->tunnel_id : 0,
8830 struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
8831 struct mlx5_hlist *group_hash;
8832 struct mlx5_flow_cb_ctx ctx = {
8836 group_hash = tunnel ? tunnel->groups : thub->groups;
8837 he = mlx5_hlist_register(group_hash, key.val, &ctx);
8839 return rte_flow_error_set(error, EINVAL,
8840 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
8842 "tunnel group index not supported");
8843 tte = container_of(he, typeof(*tte), hash);
8844 *table = tte->flow_table;
8845 DRV_LOG(DEBUG, "port %u tunnel %u group=%#x table=%#x",
8846 dev->data->port_id, key.tunnel_id, group, *table);
8851 mlx5_flow_tunnel_free(struct rte_eth_dev *dev,
8852 struct mlx5_flow_tunnel *tunnel)
8854 struct mlx5_priv *priv = dev->data->dev_private;
8855 struct mlx5_indexed_pool *ipool;
8857 DRV_LOG(DEBUG, "port %u release pmd tunnel id=0x%x",
8858 dev->data->port_id, tunnel->tunnel_id);
8859 LIST_REMOVE(tunnel, chain);
8860 mlx5_hlist_destroy(tunnel->groups);
8861 ipool = priv->sh->ipool[MLX5_IPOOL_TUNNEL_ID];
8862 mlx5_ipool_free(ipool, tunnel->tunnel_id);
8866 mlx5_access_tunnel_offload_db
8867 (struct rte_eth_dev *dev,
8868 bool (*match)(struct rte_eth_dev *,
8869 struct mlx5_flow_tunnel *, const void *),
8870 void (*hit)(struct rte_eth_dev *, struct mlx5_flow_tunnel *, void *),
8871 void (*miss)(struct rte_eth_dev *, void *),
8872 void *ctx, bool lock_op)
8874 bool verdict = false;
8875 struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
8876 struct mlx5_flow_tunnel *tunnel;
8878 rte_spinlock_lock(&thub->sl);
8879 LIST_FOREACH(tunnel, &thub->tunnels, chain) {
8880 verdict = match(dev, tunnel, (const void *)ctx);
8885 rte_spinlock_unlock(&thub->sl);
8887 hit(dev, tunnel, ctx);
8888 if (!verdict && miss)
8891 rte_spinlock_unlock(&thub->sl);
8896 struct tunnel_db_find_tunnel_id_ctx {
8898 struct mlx5_flow_tunnel *tunnel;
8902 find_tunnel_id_match(struct rte_eth_dev *dev,
8903 struct mlx5_flow_tunnel *tunnel, const void *x)
8905 const struct tunnel_db_find_tunnel_id_ctx *ctx = x;
8908 return tunnel->tunnel_id == ctx->tunnel_id;
8912 find_tunnel_id_hit(struct rte_eth_dev *dev,
8913 struct mlx5_flow_tunnel *tunnel, void *x)
8915 struct tunnel_db_find_tunnel_id_ctx *ctx = x;
8917 ctx->tunnel = tunnel;
8920 static struct mlx5_flow_tunnel *
8921 mlx5_find_tunnel_id(struct rte_eth_dev *dev, uint32_t id)
8923 struct tunnel_db_find_tunnel_id_ctx ctx = {
8927 mlx5_access_tunnel_offload_db(dev, find_tunnel_id_match,
8928 find_tunnel_id_hit, NULL, &ctx, true);
8933 static struct mlx5_flow_tunnel *
8934 mlx5_flow_tunnel_allocate(struct rte_eth_dev *dev,
8935 const struct rte_flow_tunnel *app_tunnel)
8937 struct mlx5_priv *priv = dev->data->dev_private;
8938 struct mlx5_indexed_pool *ipool;
8939 struct mlx5_flow_tunnel *tunnel;
8942 ipool = priv->sh->ipool[MLX5_IPOOL_TUNNEL_ID];
8943 tunnel = mlx5_ipool_zmalloc(ipool, &id);
8946 if (id >= MLX5_MAX_TUNNELS) {
8947 mlx5_ipool_free(ipool, id);
8948 DRV_LOG(ERR, "Tunnel ID %d exceed max limit.", id);
8951 tunnel->groups = mlx5_hlist_create("tunnel groups", 64, false, true,
8953 mlx5_flow_tunnel_grp2tbl_create_cb,
8954 mlx5_flow_tunnel_grp2tbl_match_cb,
8955 mlx5_flow_tunnel_grp2tbl_remove_cb,
8956 mlx5_flow_tunnel_grp2tbl_clone_cb,
8957 mlx5_flow_tunnel_grp2tbl_clone_free_cb);
8958 if (!tunnel->groups) {
8959 mlx5_ipool_free(ipool, id);
8962 /* initiate new PMD tunnel */
8963 memcpy(&tunnel->app_tunnel, app_tunnel, sizeof(*app_tunnel));
8964 tunnel->tunnel_id = id;
8965 tunnel->action.type = (typeof(tunnel->action.type))
8966 MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET;
8967 tunnel->action.conf = tunnel;
8968 tunnel->item.type = (typeof(tunnel->item.type))
8969 MLX5_RTE_FLOW_ITEM_TYPE_TUNNEL;
8970 tunnel->item.spec = tunnel;
8971 tunnel->item.last = NULL;
8972 tunnel->item.mask = NULL;
8974 DRV_LOG(DEBUG, "port %u new pmd tunnel id=0x%x",
8975 dev->data->port_id, tunnel->tunnel_id);
8980 struct tunnel_db_get_tunnel_ctx {
8981 const struct rte_flow_tunnel *app_tunnel;
8982 struct mlx5_flow_tunnel *tunnel;
8985 static bool get_tunnel_match(struct rte_eth_dev *dev,
8986 struct mlx5_flow_tunnel *tunnel, const void *x)
8988 const struct tunnel_db_get_tunnel_ctx *ctx = x;
8991 return !memcmp(ctx->app_tunnel, &tunnel->app_tunnel,
8992 sizeof(*ctx->app_tunnel));
8995 static void get_tunnel_hit(struct rte_eth_dev *dev,
8996 struct mlx5_flow_tunnel *tunnel, void *x)
8998 /* called under tunnel spinlock protection */
8999 struct tunnel_db_get_tunnel_ctx *ctx = x;
9003 ctx->tunnel = tunnel;
9006 static void get_tunnel_miss(struct rte_eth_dev *dev, void *x)
9008 /* called under tunnel spinlock protection */
9009 struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
9010 struct tunnel_db_get_tunnel_ctx *ctx = x;
9012 rte_spinlock_unlock(&thub->sl);
9013 ctx->tunnel = mlx5_flow_tunnel_allocate(dev, ctx->app_tunnel);
9014 rte_spinlock_lock(&thub->sl);
9016 ctx->tunnel->refctn = 1;
9017 LIST_INSERT_HEAD(&thub->tunnels, ctx->tunnel, chain);
9023 mlx5_get_flow_tunnel(struct rte_eth_dev *dev,
9024 const struct rte_flow_tunnel *app_tunnel,
9025 struct mlx5_flow_tunnel **tunnel)
9027 struct tunnel_db_get_tunnel_ctx ctx = {
9028 .app_tunnel = app_tunnel,
9031 mlx5_access_tunnel_offload_db(dev, get_tunnel_match, get_tunnel_hit,
9032 get_tunnel_miss, &ctx, true);
9033 *tunnel = ctx.tunnel;
9034 return ctx.tunnel ? 0 : -ENOMEM;
9037 void mlx5_release_tunnel_hub(struct mlx5_dev_ctx_shared *sh, uint16_t port_id)
9039 struct mlx5_flow_tunnel_hub *thub = sh->tunnel_hub;
9043 if (!LIST_EMPTY(&thub->tunnels))
9044 DRV_LOG(WARNING, "port %u tunnels present", port_id);
9045 mlx5_hlist_destroy(thub->groups);
9049 int mlx5_alloc_tunnel_hub(struct mlx5_dev_ctx_shared *sh)
9052 struct mlx5_flow_tunnel_hub *thub;
9054 thub = mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO, sizeof(*thub),
9058 LIST_INIT(&thub->tunnels);
9059 rte_spinlock_init(&thub->sl);
9060 thub->groups = mlx5_hlist_create("flow groups", 64,
9062 mlx5_flow_tunnel_grp2tbl_create_cb,
9063 mlx5_flow_tunnel_grp2tbl_match_cb,
9064 mlx5_flow_tunnel_grp2tbl_remove_cb,
9065 mlx5_flow_tunnel_grp2tbl_clone_cb,
9066 mlx5_flow_tunnel_grp2tbl_clone_free_cb);
9067 if (!thub->groups) {
9071 sh->tunnel_hub = thub;
9077 mlx5_hlist_destroy(thub->groups);
9084 mlx5_flow_tunnel_validate(struct rte_eth_dev *dev,
9085 struct rte_flow_tunnel *tunnel,
9086 const char *err_msg)
9089 if (!is_tunnel_offload_active(dev)) {
9090 err_msg = "tunnel offload was not activated";
9092 } else if (!tunnel) {
9093 err_msg = "no application tunnel";
9097 switch (tunnel->type) {
9099 err_msg = "unsupported tunnel type";
9101 case RTE_FLOW_ITEM_TYPE_VXLAN:
9110 mlx5_flow_tunnel_decap_set(struct rte_eth_dev *dev,
9111 struct rte_flow_tunnel *app_tunnel,
9112 struct rte_flow_action **actions,
9113 uint32_t *num_of_actions,
9114 struct rte_flow_error *error)
9117 struct mlx5_flow_tunnel *tunnel;
9118 const char *err_msg = NULL;
9119 bool verdict = mlx5_flow_tunnel_validate(dev, app_tunnel, err_msg);
9122 return rte_flow_error_set(error, EINVAL,
9123 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
9125 ret = mlx5_get_flow_tunnel(dev, app_tunnel, &tunnel);
9127 return rte_flow_error_set(error, ret,
9128 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
9129 "failed to initialize pmd tunnel");
9131 *actions = &tunnel->action;
9132 *num_of_actions = 1;
9137 mlx5_flow_tunnel_match(struct rte_eth_dev *dev,
9138 struct rte_flow_tunnel *app_tunnel,
9139 struct rte_flow_item **items,
9140 uint32_t *num_of_items,
9141 struct rte_flow_error *error)
9144 struct mlx5_flow_tunnel *tunnel;
9145 const char *err_msg = NULL;
9146 bool verdict = mlx5_flow_tunnel_validate(dev, app_tunnel, err_msg);
9149 return rte_flow_error_set(error, EINVAL,
9150 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
9152 ret = mlx5_get_flow_tunnel(dev, app_tunnel, &tunnel);
9154 return rte_flow_error_set(error, ret,
9155 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
9156 "failed to initialize pmd tunnel");
9158 *items = &tunnel->item;
9163 struct tunnel_db_element_release_ctx {
9164 struct rte_flow_item *items;
9165 struct rte_flow_action *actions;
9166 uint32_t num_elements;
9167 struct rte_flow_error *error;
9172 tunnel_element_release_match(struct rte_eth_dev *dev,
9173 struct mlx5_flow_tunnel *tunnel, const void *x)
9175 const struct tunnel_db_element_release_ctx *ctx = x;
9178 if (ctx->num_elements != 1)
9180 else if (ctx->items)
9181 return ctx->items == &tunnel->item;
9182 else if (ctx->actions)
9183 return ctx->actions == &tunnel->action;
9189 tunnel_element_release_hit(struct rte_eth_dev *dev,
9190 struct mlx5_flow_tunnel *tunnel, void *x)
9192 struct tunnel_db_element_release_ctx *ctx = x;
9194 if (!__atomic_sub_fetch(&tunnel->refctn, 1, __ATOMIC_RELAXED))
9195 mlx5_flow_tunnel_free(dev, tunnel);
9199 tunnel_element_release_miss(struct rte_eth_dev *dev, void *x)
9201 struct tunnel_db_element_release_ctx *ctx = x;
9203 ctx->ret = rte_flow_error_set(ctx->error, EINVAL,
9204 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
9205 "invalid argument");
9209 mlx5_flow_tunnel_item_release(struct rte_eth_dev *dev,
9210 struct rte_flow_item *pmd_items,
9211 uint32_t num_items, struct rte_flow_error *err)
9213 struct tunnel_db_element_release_ctx ctx = {
9216 .num_elements = num_items,
9220 mlx5_access_tunnel_offload_db(dev, tunnel_element_release_match,
9221 tunnel_element_release_hit,
9222 tunnel_element_release_miss, &ctx, false);
9228 mlx5_flow_tunnel_action_release(struct rte_eth_dev *dev,
9229 struct rte_flow_action *pmd_actions,
9230 uint32_t num_actions, struct rte_flow_error *err)
9232 struct tunnel_db_element_release_ctx ctx = {
9234 .actions = pmd_actions,
9235 .num_elements = num_actions,
9239 mlx5_access_tunnel_offload_db(dev, tunnel_element_release_match,
9240 tunnel_element_release_hit,
9241 tunnel_element_release_miss, &ctx, false);
9247 mlx5_flow_tunnel_get_restore_info(struct rte_eth_dev *dev,
9249 struct rte_flow_restore_info *info,
9250 struct rte_flow_error *err)
9252 uint64_t ol_flags = m->ol_flags;
9253 const struct mlx5_flow_tbl_data_entry *tble;
9254 const uint64_t mask = PKT_RX_FDIR | PKT_RX_FDIR_ID;
9256 if (!is_tunnel_offload_active(dev)) {
9261 if ((ol_flags & mask) != mask)
9263 tble = tunnel_mark_decode(dev, m->hash.fdir.hi);
9265 DRV_LOG(DEBUG, "port %u invalid miss tunnel mark %#x",
9266 dev->data->port_id, m->hash.fdir.hi);
9269 MLX5_ASSERT(tble->tunnel);
9270 memcpy(&info->tunnel, &tble->tunnel->app_tunnel, sizeof(info->tunnel));
9271 info->group_id = tble->group_id;
9272 info->flags = RTE_FLOW_RESTORE_INFO_TUNNEL |
9273 RTE_FLOW_RESTORE_INFO_GROUP_ID |
9274 RTE_FLOW_RESTORE_INFO_ENCAPSULATED;
9279 return rte_flow_error_set(err, EINVAL,
9280 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
9281 "failed to get restore info");
9284 #else /* HAVE_IBV_FLOW_DV_SUPPORT */
9286 mlx5_flow_tunnel_decap_set(__rte_unused struct rte_eth_dev *dev,
9287 __rte_unused struct rte_flow_tunnel *app_tunnel,
9288 __rte_unused struct rte_flow_action **actions,
9289 __rte_unused uint32_t *num_of_actions,
9290 __rte_unused struct rte_flow_error *error)
9296 mlx5_flow_tunnel_match(__rte_unused struct rte_eth_dev *dev,
9297 __rte_unused struct rte_flow_tunnel *app_tunnel,
9298 __rte_unused struct rte_flow_item **items,
9299 __rte_unused uint32_t *num_of_items,
9300 __rte_unused struct rte_flow_error *error)
9306 mlx5_flow_tunnel_item_release(__rte_unused struct rte_eth_dev *dev,
9307 __rte_unused struct rte_flow_item *pmd_items,
9308 __rte_unused uint32_t num_items,
9309 __rte_unused struct rte_flow_error *err)
9315 mlx5_flow_tunnel_action_release(__rte_unused struct rte_eth_dev *dev,
9316 __rte_unused struct rte_flow_action *pmd_action,
9317 __rte_unused uint32_t num_actions,
9318 __rte_unused struct rte_flow_error *err)
9324 mlx5_flow_tunnel_get_restore_info(__rte_unused struct rte_eth_dev *dev,
9325 __rte_unused struct rte_mbuf *m,
9326 __rte_unused struct rte_flow_restore_info *i,
9327 __rte_unused struct rte_flow_error *err)
9333 flow_tunnel_add_default_miss(__rte_unused struct rte_eth_dev *dev,
9334 __rte_unused struct rte_flow *flow,
9335 __rte_unused const struct rte_flow_attr *attr,
9336 __rte_unused const struct rte_flow_action *actions,
9337 __rte_unused uint32_t flow_idx,
9338 __rte_unused const struct mlx5_flow_tunnel *tunnel,
9339 __rte_unused struct tunnel_default_miss_ctx *ctx,
9340 __rte_unused struct rte_flow_error *error)
9345 static struct mlx5_flow_tunnel *
9346 mlx5_find_tunnel_id(__rte_unused struct rte_eth_dev *dev,
9347 __rte_unused uint32_t id)
9353 mlx5_flow_tunnel_free(__rte_unused struct rte_eth_dev *dev,
9354 __rte_unused struct mlx5_flow_tunnel *tunnel)
9359 tunnel_flow_group_to_flow_table(__rte_unused struct rte_eth_dev *dev,
9360 __rte_unused const struct mlx5_flow_tunnel *t,
9361 __rte_unused uint32_t group,
9362 __rte_unused uint32_t *table,
9363 struct rte_flow_error *error)
9365 return rte_flow_error_set(error, ENOTSUP,
9366 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
9367 "tunnel offload requires DV support");
9371 mlx5_release_tunnel_hub(__rte_unused struct mlx5_dev_ctx_shared *sh,
9372 __rte_unused uint16_t port_id)
9375 #endif /* HAVE_IBV_FLOW_DV_SUPPORT */
9378 mlx5_dbg__print_pattern(const struct rte_flow_item *item)
9381 struct rte_flow_error error;
9383 for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
9385 ret = rte_flow_conv(RTE_FLOW_CONV_OP_ITEM_NAME_PTR, &item_name,
9387 (void *)(uintptr_t)item->type, &error);
9389 printf("%s ", item_name);
9391 printf("%d\n", (int)item->type);