1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2016 6WIND S.A.
3 * Copyright 2016 Mellanox Technologies, Ltd
10 #include <sys/queue.h>
12 #include <rte_common.h>
13 #include <rte_ether.h>
14 #include <ethdev_driver.h>
15 #include <rte_eal_paging.h>
17 #include <rte_cycles.h>
18 #include <rte_flow_driver.h>
19 #include <rte_malloc.h>
22 #include <mlx5_glue.h>
23 #include <mlx5_devx_cmds.h>
25 #include <mlx5_malloc.h>
27 #include "mlx5_defs.h"
29 #include "mlx5_flow.h"
30 #include "mlx5_flow_os.h"
33 #include "mlx5_common_os.h"
34 #include "rte_pmd_mlx5.h"
36 struct tunnel_default_miss_ctx {
40 struct rte_flow_action_rss action_rss;
41 struct rte_flow_action_queue miss_queue;
42 struct rte_flow_action_jump miss_jump;
48 flow_tunnel_add_default_miss(struct rte_eth_dev *dev,
49 struct rte_flow *flow,
50 const struct rte_flow_attr *attr,
51 const struct rte_flow_action *app_actions,
53 const struct mlx5_flow_tunnel *tunnel,
54 struct tunnel_default_miss_ctx *ctx,
55 struct rte_flow_error *error);
56 static struct mlx5_flow_tunnel *
57 mlx5_find_tunnel_id(struct rte_eth_dev *dev, uint32_t id);
59 mlx5_flow_tunnel_free(struct rte_eth_dev *dev, struct mlx5_flow_tunnel *tunnel);
61 tunnel_flow_group_to_flow_table(struct rte_eth_dev *dev,
62 const struct mlx5_flow_tunnel *tunnel,
63 uint32_t group, uint32_t *table,
64 struct rte_flow_error *error);
66 static struct mlx5_flow_workspace *mlx5_flow_push_thread_workspace(void);
67 static void mlx5_flow_pop_thread_workspace(void);
70 /** Device flow drivers. */
71 extern const struct mlx5_flow_driver_ops mlx5_flow_verbs_drv_ops;
73 const struct mlx5_flow_driver_ops mlx5_flow_null_drv_ops;
75 const struct mlx5_flow_driver_ops *flow_drv_ops[] = {
76 [MLX5_FLOW_TYPE_MIN] = &mlx5_flow_null_drv_ops,
77 #if defined(HAVE_IBV_FLOW_DV_SUPPORT) || !defined(HAVE_INFINIBAND_VERBS_H)
78 [MLX5_FLOW_TYPE_DV] = &mlx5_flow_dv_drv_ops,
80 [MLX5_FLOW_TYPE_VERBS] = &mlx5_flow_verbs_drv_ops,
81 [MLX5_FLOW_TYPE_MAX] = &mlx5_flow_null_drv_ops
84 /** Helper macro to build input graph for mlx5_flow_expand_rss(). */
85 #define MLX5_FLOW_EXPAND_RSS_NEXT(...) \
90 /** Node object of input graph for mlx5_flow_expand_rss(). */
91 struct mlx5_flow_expand_node {
92 const int *const next;
94 * List of next node indexes. Index 0 is interpreted as a terminator.
96 const enum rte_flow_item_type type;
97 /**< Pattern item type of current node. */
100 * RSS types bit-field associated with this node
101 * (see ETH_RSS_* definitions).
104 /**< optional expand field. Default 0 to expand, 1 not go deeper. */
107 /** Object returned by mlx5_flow_expand_rss(). */
108 struct mlx5_flow_expand_rss {
110 /**< Number of entries @p patterns and @p priorities. */
112 struct rte_flow_item *pattern; /**< Expanded pattern array. */
113 uint32_t priority; /**< Priority offset for each expansion. */
118 mlx5_dbg__print_pattern(const struct rte_flow_item *item);
121 mlx5_flow_is_rss_expandable_item(const struct rte_flow_item *item)
123 switch (item->type) {
124 case RTE_FLOW_ITEM_TYPE_ETH:
125 case RTE_FLOW_ITEM_TYPE_VLAN:
126 case RTE_FLOW_ITEM_TYPE_IPV4:
127 case RTE_FLOW_ITEM_TYPE_IPV6:
128 case RTE_FLOW_ITEM_TYPE_UDP:
129 case RTE_FLOW_ITEM_TYPE_TCP:
130 case RTE_FLOW_ITEM_TYPE_VXLAN:
131 case RTE_FLOW_ITEM_TYPE_NVGRE:
132 case RTE_FLOW_ITEM_TYPE_GRE:
133 case RTE_FLOW_ITEM_TYPE_GENEVE:
134 case RTE_FLOW_ITEM_TYPE_MPLS:
135 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
136 case RTE_FLOW_ITEM_TYPE_GRE_KEY:
144 static enum rte_flow_item_type
145 mlx5_flow_expand_rss_item_complete(const struct rte_flow_item *item)
147 enum rte_flow_item_type ret = RTE_FLOW_ITEM_TYPE_VOID;
148 uint16_t ether_type = 0;
149 uint16_t ether_type_m;
150 uint8_t ip_next_proto = 0;
151 uint8_t ip_next_proto_m;
153 if (item == NULL || item->spec == NULL)
155 switch (item->type) {
156 case RTE_FLOW_ITEM_TYPE_ETH:
158 ether_type_m = ((const struct rte_flow_item_eth *)
161 ether_type_m = rte_flow_item_eth_mask.type;
162 if (ether_type_m != RTE_BE16(0xFFFF))
164 ether_type = ((const struct rte_flow_item_eth *)
166 if (rte_be_to_cpu_16(ether_type) == RTE_ETHER_TYPE_IPV4)
167 ret = RTE_FLOW_ITEM_TYPE_IPV4;
168 else if (rte_be_to_cpu_16(ether_type) == RTE_ETHER_TYPE_IPV6)
169 ret = RTE_FLOW_ITEM_TYPE_IPV6;
170 else if (rte_be_to_cpu_16(ether_type) == RTE_ETHER_TYPE_VLAN)
171 ret = RTE_FLOW_ITEM_TYPE_VLAN;
173 ret = RTE_FLOW_ITEM_TYPE_END;
175 case RTE_FLOW_ITEM_TYPE_VLAN:
177 ether_type_m = ((const struct rte_flow_item_vlan *)
178 (item->mask))->inner_type;
180 ether_type_m = rte_flow_item_vlan_mask.inner_type;
181 if (ether_type_m != RTE_BE16(0xFFFF))
183 ether_type = ((const struct rte_flow_item_vlan *)
184 (item->spec))->inner_type;
185 if (rte_be_to_cpu_16(ether_type) == RTE_ETHER_TYPE_IPV4)
186 ret = RTE_FLOW_ITEM_TYPE_IPV4;
187 else if (rte_be_to_cpu_16(ether_type) == RTE_ETHER_TYPE_IPV6)
188 ret = RTE_FLOW_ITEM_TYPE_IPV6;
189 else if (rte_be_to_cpu_16(ether_type) == RTE_ETHER_TYPE_VLAN)
190 ret = RTE_FLOW_ITEM_TYPE_VLAN;
192 ret = RTE_FLOW_ITEM_TYPE_END;
194 case RTE_FLOW_ITEM_TYPE_IPV4:
196 ip_next_proto_m = ((const struct rte_flow_item_ipv4 *)
197 (item->mask))->hdr.next_proto_id;
200 rte_flow_item_ipv4_mask.hdr.next_proto_id;
201 if (ip_next_proto_m != 0xFF)
203 ip_next_proto = ((const struct rte_flow_item_ipv4 *)
204 (item->spec))->hdr.next_proto_id;
205 if (ip_next_proto == IPPROTO_UDP)
206 ret = RTE_FLOW_ITEM_TYPE_UDP;
207 else if (ip_next_proto == IPPROTO_TCP)
208 ret = RTE_FLOW_ITEM_TYPE_TCP;
209 else if (ip_next_proto == IPPROTO_IP)
210 ret = RTE_FLOW_ITEM_TYPE_IPV4;
211 else if (ip_next_proto == IPPROTO_IPV6)
212 ret = RTE_FLOW_ITEM_TYPE_IPV6;
214 ret = RTE_FLOW_ITEM_TYPE_END;
216 case RTE_FLOW_ITEM_TYPE_IPV6:
218 ip_next_proto_m = ((const struct rte_flow_item_ipv6 *)
219 (item->mask))->hdr.proto;
222 rte_flow_item_ipv6_mask.hdr.proto;
223 if (ip_next_proto_m != 0xFF)
225 ip_next_proto = ((const struct rte_flow_item_ipv6 *)
226 (item->spec))->hdr.proto;
227 if (ip_next_proto == IPPROTO_UDP)
228 ret = RTE_FLOW_ITEM_TYPE_UDP;
229 else if (ip_next_proto == IPPROTO_TCP)
230 ret = RTE_FLOW_ITEM_TYPE_TCP;
231 else if (ip_next_proto == IPPROTO_IP)
232 ret = RTE_FLOW_ITEM_TYPE_IPV4;
233 else if (ip_next_proto == IPPROTO_IPV6)
234 ret = RTE_FLOW_ITEM_TYPE_IPV6;
236 ret = RTE_FLOW_ITEM_TYPE_END;
239 ret = RTE_FLOW_ITEM_TYPE_VOID;
245 #define MLX5_RSS_EXP_ELT_N 16
248 * Expand RSS flows into several possible flows according to the RSS hash
249 * fields requested and the driver capabilities.
252 * Buffer to store the result expansion.
254 * Buffer size in bytes. If 0, @p buf can be NULL.
258 * RSS types to expand (see ETH_RSS_* definitions).
260 * Input graph to expand @p pattern according to @p types.
261 * @param[in] graph_root_index
262 * Index of root node in @p graph, typically 0.
265 * A positive value representing the size of @p buf in bytes regardless of
266 * @p size on success, a negative errno value otherwise and rte_errno is
267 * set, the following errors are defined:
269 * -E2BIG: graph-depth @p graph is too deep.
270 * -EINVAL: @p size has not enough space for expanded pattern.
273 mlx5_flow_expand_rss(struct mlx5_flow_expand_rss *buf, size_t size,
274 const struct rte_flow_item *pattern, uint64_t types,
275 const struct mlx5_flow_expand_node graph[],
276 int graph_root_index)
278 const struct rte_flow_item *item;
279 const struct mlx5_flow_expand_node *node = &graph[graph_root_index];
280 const int *next_node;
281 const int *stack[MLX5_RSS_EXP_ELT_N];
283 struct rte_flow_item flow_items[MLX5_RSS_EXP_ELT_N];
286 size_t user_pattern_size = 0;
288 const struct mlx5_flow_expand_node *next = NULL;
289 struct rte_flow_item missed_item;
292 const struct rte_flow_item *last_item = NULL;
294 memset(&missed_item, 0, sizeof(missed_item));
295 lsize = offsetof(struct mlx5_flow_expand_rss, entry) +
296 MLX5_RSS_EXP_ELT_N * sizeof(buf->entry[0]);
299 buf->entry[0].priority = 0;
300 buf->entry[0].pattern = (void *)&buf->entry[MLX5_RSS_EXP_ELT_N];
302 addr = buf->entry[0].pattern;
303 for (item = pattern; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
304 if (!mlx5_flow_is_rss_expandable_item(item)) {
305 user_pattern_size += sizeof(*item);
309 for (i = 0; node->next && node->next[i]; ++i) {
310 next = &graph[node->next[i]];
311 if (next->type == item->type)
316 user_pattern_size += sizeof(*item);
318 user_pattern_size += sizeof(*item); /* Handle END item. */
319 lsize += user_pattern_size;
322 /* Copy the user pattern in the first entry of the buffer. */
323 rte_memcpy(addr, pattern, user_pattern_size);
324 addr = (void *)(((uintptr_t)addr) + user_pattern_size);
326 /* Start expanding. */
327 memset(flow_items, 0, sizeof(flow_items));
328 user_pattern_size -= sizeof(*item);
330 * Check if the last valid item has spec set, need complete pattern,
331 * and the pattern can be used for expansion.
333 missed_item.type = mlx5_flow_expand_rss_item_complete(last_item);
334 if (missed_item.type == RTE_FLOW_ITEM_TYPE_END) {
335 /* Item type END indicates expansion is not required. */
338 if (missed_item.type != RTE_FLOW_ITEM_TYPE_VOID) {
341 for (i = 0; node->next && node->next[i]; ++i) {
342 next = &graph[node->next[i]];
343 if (next->type == missed_item.type) {
344 flow_items[0].type = missed_item.type;
345 flow_items[1].type = RTE_FLOW_ITEM_TYPE_END;
351 if (next && missed) {
352 elt = 2; /* missed item + item end. */
354 lsize += elt * sizeof(*item) + user_pattern_size;
357 if (node->rss_types & types) {
358 buf->entry[buf->entries].priority = 1;
359 buf->entry[buf->entries].pattern = addr;
361 rte_memcpy(addr, buf->entry[0].pattern,
363 addr = (void *)(((uintptr_t)addr) + user_pattern_size);
364 rte_memcpy(addr, flow_items, elt * sizeof(*item));
365 addr = (void *)(((uintptr_t)addr) +
366 elt * sizeof(*item));
369 memset(flow_items, 0, sizeof(flow_items));
370 next_node = node->next;
371 stack[stack_pos] = next_node;
372 node = next_node ? &graph[*next_node] : NULL;
374 flow_items[stack_pos].type = node->type;
375 if (node->rss_types & types) {
378 * compute the number of items to copy from the
379 * expansion and copy it.
380 * When the stack_pos is 0, there are 1 element in it,
381 * plus the addition END item.
384 flow_items[stack_pos + 1].type = RTE_FLOW_ITEM_TYPE_END;
385 lsize += elt * sizeof(*item) + user_pattern_size;
388 n = elt * sizeof(*item);
389 buf->entry[buf->entries].priority =
390 stack_pos + 1 + missed;
391 buf->entry[buf->entries].pattern = addr;
393 rte_memcpy(addr, buf->entry[0].pattern,
395 addr = (void *)(((uintptr_t)addr) +
397 rte_memcpy(addr, &missed_item,
398 missed * sizeof(*item));
399 addr = (void *)(((uintptr_t)addr) +
400 missed * sizeof(*item));
401 rte_memcpy(addr, flow_items, n);
402 addr = (void *)(((uintptr_t)addr) + n);
405 if (!node->optional && node->next) {
406 next_node = node->next;
407 if (stack_pos++ == MLX5_RSS_EXP_ELT_N) {
411 stack[stack_pos] = next_node;
412 } else if (*(next_node + 1)) {
413 /* Follow up with the next possibility. */
416 /* Move to the next path. */
418 next_node = stack[--stack_pos];
420 stack[stack_pos] = next_node;
422 node = *next_node ? &graph[*next_node] : NULL;
427 enum mlx5_expansion {
429 MLX5_EXPANSION_ROOT_OUTER,
430 MLX5_EXPANSION_ROOT_ETH_VLAN,
431 MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN,
432 MLX5_EXPANSION_OUTER_ETH,
433 MLX5_EXPANSION_OUTER_ETH_VLAN,
434 MLX5_EXPANSION_OUTER_VLAN,
435 MLX5_EXPANSION_OUTER_IPV4,
436 MLX5_EXPANSION_OUTER_IPV4_UDP,
437 MLX5_EXPANSION_OUTER_IPV4_TCP,
438 MLX5_EXPANSION_OUTER_IPV6,
439 MLX5_EXPANSION_OUTER_IPV6_UDP,
440 MLX5_EXPANSION_OUTER_IPV6_TCP,
441 MLX5_EXPANSION_VXLAN,
442 MLX5_EXPANSION_VXLAN_GPE,
444 MLX5_EXPANSION_NVGRE,
445 MLX5_EXPANSION_GRE_KEY,
448 MLX5_EXPANSION_ETH_VLAN,
451 MLX5_EXPANSION_IPV4_UDP,
452 MLX5_EXPANSION_IPV4_TCP,
454 MLX5_EXPANSION_IPV6_UDP,
455 MLX5_EXPANSION_IPV6_TCP,
458 /** Supported expansion of items. */
459 static const struct mlx5_flow_expand_node mlx5_support_expansion[] = {
460 [MLX5_EXPANSION_ROOT] = {
461 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
463 MLX5_EXPANSION_IPV6),
464 .type = RTE_FLOW_ITEM_TYPE_END,
466 [MLX5_EXPANSION_ROOT_OUTER] = {
467 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_ETH,
468 MLX5_EXPANSION_OUTER_IPV4,
469 MLX5_EXPANSION_OUTER_IPV6),
470 .type = RTE_FLOW_ITEM_TYPE_END,
472 [MLX5_EXPANSION_ROOT_ETH_VLAN] = {
473 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH_VLAN),
474 .type = RTE_FLOW_ITEM_TYPE_END,
476 [MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN] = {
477 .next = MLX5_FLOW_EXPAND_RSS_NEXT
478 (MLX5_EXPANSION_OUTER_ETH_VLAN),
479 .type = RTE_FLOW_ITEM_TYPE_END,
481 [MLX5_EXPANSION_OUTER_ETH] = {
482 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_IPV4,
483 MLX5_EXPANSION_OUTER_IPV6),
484 .type = RTE_FLOW_ITEM_TYPE_ETH,
487 [MLX5_EXPANSION_OUTER_ETH_VLAN] = {
488 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_VLAN),
489 .type = RTE_FLOW_ITEM_TYPE_ETH,
492 [MLX5_EXPANSION_OUTER_VLAN] = {
493 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_IPV4,
494 MLX5_EXPANSION_OUTER_IPV6),
495 .type = RTE_FLOW_ITEM_TYPE_VLAN,
497 [MLX5_EXPANSION_OUTER_IPV4] = {
498 .next = MLX5_FLOW_EXPAND_RSS_NEXT
499 (MLX5_EXPANSION_OUTER_IPV4_UDP,
500 MLX5_EXPANSION_OUTER_IPV4_TCP,
502 MLX5_EXPANSION_NVGRE,
504 MLX5_EXPANSION_IPV6),
505 .type = RTE_FLOW_ITEM_TYPE_IPV4,
506 .rss_types = ETH_RSS_IPV4 | ETH_RSS_FRAG_IPV4 |
507 ETH_RSS_NONFRAG_IPV4_OTHER,
509 [MLX5_EXPANSION_OUTER_IPV4_UDP] = {
510 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VXLAN,
511 MLX5_EXPANSION_VXLAN_GPE,
512 MLX5_EXPANSION_MPLS),
513 .type = RTE_FLOW_ITEM_TYPE_UDP,
514 .rss_types = ETH_RSS_NONFRAG_IPV4_UDP,
516 [MLX5_EXPANSION_OUTER_IPV4_TCP] = {
517 .type = RTE_FLOW_ITEM_TYPE_TCP,
518 .rss_types = ETH_RSS_NONFRAG_IPV4_TCP,
520 [MLX5_EXPANSION_OUTER_IPV6] = {
521 .next = MLX5_FLOW_EXPAND_RSS_NEXT
522 (MLX5_EXPANSION_OUTER_IPV6_UDP,
523 MLX5_EXPANSION_OUTER_IPV6_TCP,
527 MLX5_EXPANSION_NVGRE),
528 .type = RTE_FLOW_ITEM_TYPE_IPV6,
529 .rss_types = ETH_RSS_IPV6 | ETH_RSS_FRAG_IPV6 |
530 ETH_RSS_NONFRAG_IPV6_OTHER,
532 [MLX5_EXPANSION_OUTER_IPV6_UDP] = {
533 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VXLAN,
534 MLX5_EXPANSION_VXLAN_GPE,
535 MLX5_EXPANSION_MPLS),
536 .type = RTE_FLOW_ITEM_TYPE_UDP,
537 .rss_types = ETH_RSS_NONFRAG_IPV6_UDP,
539 [MLX5_EXPANSION_OUTER_IPV6_TCP] = {
540 .type = RTE_FLOW_ITEM_TYPE_TCP,
541 .rss_types = ETH_RSS_NONFRAG_IPV6_TCP,
543 [MLX5_EXPANSION_VXLAN] = {
544 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
546 MLX5_EXPANSION_IPV6),
547 .type = RTE_FLOW_ITEM_TYPE_VXLAN,
549 [MLX5_EXPANSION_VXLAN_GPE] = {
550 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
552 MLX5_EXPANSION_IPV6),
553 .type = RTE_FLOW_ITEM_TYPE_VXLAN_GPE,
555 [MLX5_EXPANSION_GRE] = {
556 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
558 MLX5_EXPANSION_GRE_KEY,
559 MLX5_EXPANSION_MPLS),
560 .type = RTE_FLOW_ITEM_TYPE_GRE,
562 [MLX5_EXPANSION_GRE_KEY] = {
563 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
565 MLX5_EXPANSION_MPLS),
566 .type = RTE_FLOW_ITEM_TYPE_GRE_KEY,
569 [MLX5_EXPANSION_NVGRE] = {
570 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH),
571 .type = RTE_FLOW_ITEM_TYPE_NVGRE,
573 [MLX5_EXPANSION_MPLS] = {
574 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
577 .type = RTE_FLOW_ITEM_TYPE_MPLS,
579 [MLX5_EXPANSION_ETH] = {
580 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
581 MLX5_EXPANSION_IPV6),
582 .type = RTE_FLOW_ITEM_TYPE_ETH,
584 [MLX5_EXPANSION_ETH_VLAN] = {
585 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VLAN),
586 .type = RTE_FLOW_ITEM_TYPE_ETH,
588 [MLX5_EXPANSION_VLAN] = {
589 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
590 MLX5_EXPANSION_IPV6),
591 .type = RTE_FLOW_ITEM_TYPE_VLAN,
593 [MLX5_EXPANSION_IPV4] = {
594 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4_UDP,
595 MLX5_EXPANSION_IPV4_TCP),
596 .type = RTE_FLOW_ITEM_TYPE_IPV4,
597 .rss_types = ETH_RSS_IPV4 | ETH_RSS_FRAG_IPV4 |
598 ETH_RSS_NONFRAG_IPV4_OTHER,
600 [MLX5_EXPANSION_IPV4_UDP] = {
601 .type = RTE_FLOW_ITEM_TYPE_UDP,
602 .rss_types = ETH_RSS_NONFRAG_IPV4_UDP,
604 [MLX5_EXPANSION_IPV4_TCP] = {
605 .type = RTE_FLOW_ITEM_TYPE_TCP,
606 .rss_types = ETH_RSS_NONFRAG_IPV4_TCP,
608 [MLX5_EXPANSION_IPV6] = {
609 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV6_UDP,
610 MLX5_EXPANSION_IPV6_TCP),
611 .type = RTE_FLOW_ITEM_TYPE_IPV6,
612 .rss_types = ETH_RSS_IPV6 | ETH_RSS_FRAG_IPV6 |
613 ETH_RSS_NONFRAG_IPV6_OTHER,
615 [MLX5_EXPANSION_IPV6_UDP] = {
616 .type = RTE_FLOW_ITEM_TYPE_UDP,
617 .rss_types = ETH_RSS_NONFRAG_IPV6_UDP,
619 [MLX5_EXPANSION_IPV6_TCP] = {
620 .type = RTE_FLOW_ITEM_TYPE_TCP,
621 .rss_types = ETH_RSS_NONFRAG_IPV6_TCP,
625 static struct rte_flow_action_handle *
626 mlx5_action_handle_create(struct rte_eth_dev *dev,
627 const struct rte_flow_indir_action_conf *conf,
628 const struct rte_flow_action *action,
629 struct rte_flow_error *error);
630 static int mlx5_action_handle_destroy
631 (struct rte_eth_dev *dev,
632 struct rte_flow_action_handle *handle,
633 struct rte_flow_error *error);
634 static int mlx5_action_handle_update
635 (struct rte_eth_dev *dev,
636 struct rte_flow_action_handle *handle,
638 struct rte_flow_error *error);
639 static int mlx5_action_handle_query
640 (struct rte_eth_dev *dev,
641 const struct rte_flow_action_handle *handle,
643 struct rte_flow_error *error);
645 mlx5_flow_tunnel_decap_set(struct rte_eth_dev *dev,
646 struct rte_flow_tunnel *app_tunnel,
647 struct rte_flow_action **actions,
648 uint32_t *num_of_actions,
649 struct rte_flow_error *error);
651 mlx5_flow_tunnel_match(struct rte_eth_dev *dev,
652 struct rte_flow_tunnel *app_tunnel,
653 struct rte_flow_item **items,
654 uint32_t *num_of_items,
655 struct rte_flow_error *error);
657 mlx5_flow_tunnel_item_release(struct rte_eth_dev *dev,
658 struct rte_flow_item *pmd_items,
659 uint32_t num_items, struct rte_flow_error *err);
661 mlx5_flow_tunnel_action_release(struct rte_eth_dev *dev,
662 struct rte_flow_action *pmd_actions,
663 uint32_t num_actions,
664 struct rte_flow_error *err);
666 mlx5_flow_tunnel_get_restore_info(struct rte_eth_dev *dev,
668 struct rte_flow_restore_info *info,
669 struct rte_flow_error *err);
671 static const struct rte_flow_ops mlx5_flow_ops = {
672 .validate = mlx5_flow_validate,
673 .create = mlx5_flow_create,
674 .destroy = mlx5_flow_destroy,
675 .flush = mlx5_flow_flush,
676 .isolate = mlx5_flow_isolate,
677 .query = mlx5_flow_query,
678 .dev_dump = mlx5_flow_dev_dump,
679 .get_aged_flows = mlx5_flow_get_aged_flows,
680 .action_handle_create = mlx5_action_handle_create,
681 .action_handle_destroy = mlx5_action_handle_destroy,
682 .action_handle_update = mlx5_action_handle_update,
683 .action_handle_query = mlx5_action_handle_query,
684 .tunnel_decap_set = mlx5_flow_tunnel_decap_set,
685 .tunnel_match = mlx5_flow_tunnel_match,
686 .tunnel_action_decap_release = mlx5_flow_tunnel_action_release,
687 .tunnel_item_release = mlx5_flow_tunnel_item_release,
688 .get_restore_info = mlx5_flow_tunnel_get_restore_info,
691 /* Tunnel information. */
692 struct mlx5_flow_tunnel_info {
693 uint64_t tunnel; /**< Tunnel bit (see MLX5_FLOW_*). */
694 uint32_t ptype; /**< Tunnel Ptype (see RTE_PTYPE_*). */
697 static struct mlx5_flow_tunnel_info tunnels_info[] = {
699 .tunnel = MLX5_FLOW_LAYER_VXLAN,
700 .ptype = RTE_PTYPE_TUNNEL_VXLAN | RTE_PTYPE_L4_UDP,
703 .tunnel = MLX5_FLOW_LAYER_GENEVE,
704 .ptype = RTE_PTYPE_TUNNEL_GENEVE | RTE_PTYPE_L4_UDP,
707 .tunnel = MLX5_FLOW_LAYER_VXLAN_GPE,
708 .ptype = RTE_PTYPE_TUNNEL_VXLAN_GPE | RTE_PTYPE_L4_UDP,
711 .tunnel = MLX5_FLOW_LAYER_GRE,
712 .ptype = RTE_PTYPE_TUNNEL_GRE,
715 .tunnel = MLX5_FLOW_LAYER_MPLS | MLX5_FLOW_LAYER_OUTER_L4_UDP,
716 .ptype = RTE_PTYPE_TUNNEL_MPLS_IN_UDP | RTE_PTYPE_L4_UDP,
719 .tunnel = MLX5_FLOW_LAYER_MPLS,
720 .ptype = RTE_PTYPE_TUNNEL_MPLS_IN_GRE,
723 .tunnel = MLX5_FLOW_LAYER_NVGRE,
724 .ptype = RTE_PTYPE_TUNNEL_NVGRE,
727 .tunnel = MLX5_FLOW_LAYER_IPIP,
728 .ptype = RTE_PTYPE_TUNNEL_IP,
731 .tunnel = MLX5_FLOW_LAYER_IPV6_ENCAP,
732 .ptype = RTE_PTYPE_TUNNEL_IP,
735 .tunnel = MLX5_FLOW_LAYER_GTP,
736 .ptype = RTE_PTYPE_TUNNEL_GTPU,
743 * Translate tag ID to register.
746 * Pointer to the Ethernet device structure.
748 * The feature that request the register.
750 * The request register ID.
752 * Error description in case of any.
755 * The request register on success, a negative errno
756 * value otherwise and rte_errno is set.
759 mlx5_flow_get_reg_id(struct rte_eth_dev *dev,
760 enum mlx5_feature_name feature,
762 struct rte_flow_error *error)
764 struct mlx5_priv *priv = dev->data->dev_private;
765 struct mlx5_dev_config *config = &priv->config;
766 enum modify_reg start_reg;
767 bool skip_mtr_reg = false;
770 case MLX5_HAIRPIN_RX:
772 case MLX5_HAIRPIN_TX:
774 case MLX5_METADATA_RX:
775 switch (config->dv_xmeta_en) {
776 case MLX5_XMETA_MODE_LEGACY:
778 case MLX5_XMETA_MODE_META16:
780 case MLX5_XMETA_MODE_META32:
784 case MLX5_METADATA_TX:
786 case MLX5_METADATA_FDB:
787 switch (config->dv_xmeta_en) {
788 case MLX5_XMETA_MODE_LEGACY:
790 case MLX5_XMETA_MODE_META16:
792 case MLX5_XMETA_MODE_META32:
797 switch (config->dv_xmeta_en) {
798 case MLX5_XMETA_MODE_LEGACY:
800 case MLX5_XMETA_MODE_META16:
802 case MLX5_XMETA_MODE_META32:
808 * If meter color and meter id share one register, flow match
809 * should use the meter color register for match.
811 if (priv->mtr_reg_share)
812 return priv->mtr_color_reg;
814 return priv->mtr_color_reg != REG_C_2 ? REG_C_2 :
817 case MLX5_ASO_FLOW_HIT:
818 case MLX5_ASO_CONNTRACK:
819 /* All features use the same REG_C. */
820 MLX5_ASSERT(priv->mtr_color_reg != REG_NON);
821 return priv->mtr_color_reg;
824 * Metadata COPY_MARK register using is in meter suffix sub
825 * flow while with meter. It's safe to share the same register.
827 return priv->mtr_color_reg != REG_C_2 ? REG_C_2 : REG_C_3;
830 * If meter is enable, it will engage the register for color
831 * match and flow match. If meter color match is not using the
832 * REG_C_2, need to skip the REG_C_x be used by meter color
834 * If meter is disable, free to use all available registers.
836 start_reg = priv->mtr_color_reg != REG_C_2 ? REG_C_2 :
837 (priv->mtr_reg_share ? REG_C_3 : REG_C_4);
838 skip_mtr_reg = !!(priv->mtr_en && start_reg == REG_C_2);
839 if (id > (uint32_t)(REG_C_7 - start_reg))
840 return rte_flow_error_set(error, EINVAL,
841 RTE_FLOW_ERROR_TYPE_ITEM,
842 NULL, "invalid tag id");
843 if (config->flow_mreg_c[id + start_reg - REG_C_0] == REG_NON)
844 return rte_flow_error_set(error, ENOTSUP,
845 RTE_FLOW_ERROR_TYPE_ITEM,
846 NULL, "unsupported tag id");
848 * This case means meter is using the REG_C_x great than 2.
849 * Take care not to conflict with meter color REG_C_x.
850 * If the available index REG_C_y >= REG_C_x, skip the
853 if (skip_mtr_reg && config->flow_mreg_c
854 [id + start_reg - REG_C_0] >= priv->mtr_color_reg) {
855 if (id >= (uint32_t)(REG_C_7 - start_reg))
856 return rte_flow_error_set(error, EINVAL,
857 RTE_FLOW_ERROR_TYPE_ITEM,
858 NULL, "invalid tag id");
859 if (config->flow_mreg_c
860 [id + 1 + start_reg - REG_C_0] != REG_NON)
861 return config->flow_mreg_c
862 [id + 1 + start_reg - REG_C_0];
863 return rte_flow_error_set(error, ENOTSUP,
864 RTE_FLOW_ERROR_TYPE_ITEM,
865 NULL, "unsupported tag id");
867 return config->flow_mreg_c[id + start_reg - REG_C_0];
870 return rte_flow_error_set(error, EINVAL,
871 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
872 NULL, "invalid feature name");
876 * Check extensive flow metadata register support.
879 * Pointer to rte_eth_dev structure.
882 * True if device supports extensive flow metadata register, otherwise false.
885 mlx5_flow_ext_mreg_supported(struct rte_eth_dev *dev)
887 struct mlx5_priv *priv = dev->data->dev_private;
888 struct mlx5_dev_config *config = &priv->config;
891 * Having available reg_c can be regarded inclusively as supporting
892 * extensive flow metadata register, which could mean,
893 * - metadata register copy action by modify header.
894 * - 16 modify header actions is supported.
895 * - reg_c's are preserved across different domain (FDB and NIC) on
896 * packet loopback by flow lookup miss.
898 return config->flow_mreg_c[2] != REG_NON;
902 * Get the lowest priority.
905 * Pointer to the Ethernet device structure.
906 * @param[in] attributes
907 * Pointer to device flow rule attributes.
910 * The value of lowest priority of flow.
913 mlx5_get_lowest_priority(struct rte_eth_dev *dev,
914 const struct rte_flow_attr *attr)
916 struct mlx5_priv *priv = dev->data->dev_private;
918 if (!attr->group && !attr->transfer)
919 return priv->config.flow_prio - 2;
920 return MLX5_NON_ROOT_FLOW_MAX_PRIO - 1;
924 * Calculate matcher priority of the flow.
927 * Pointer to the Ethernet device structure.
929 * Pointer to device flow rule attributes.
930 * @param[in] subpriority
931 * The priority based on the items.
933 * The matcher priority of the flow.
936 mlx5_get_matcher_priority(struct rte_eth_dev *dev,
937 const struct rte_flow_attr *attr,
938 uint32_t subpriority)
940 uint16_t priority = (uint16_t)attr->priority;
941 struct mlx5_priv *priv = dev->data->dev_private;
943 if (!attr->group && !attr->transfer) {
944 if (attr->priority == MLX5_FLOW_LOWEST_PRIO_INDICATOR)
945 priority = priv->config.flow_prio - 1;
946 return mlx5_os_flow_adjust_priority(dev, priority, subpriority);
948 if (attr->priority == MLX5_FLOW_LOWEST_PRIO_INDICATOR)
949 priority = MLX5_NON_ROOT_FLOW_MAX_PRIO;
950 return priority * 3 + subpriority;
954 * Verify the @p item specifications (spec, last, mask) are compatible with the
958 * Item specification.
960 * @p item->mask or flow default bit-masks.
961 * @param[in] nic_mask
962 * Bit-masks covering supported fields by the NIC to compare with user mask.
964 * Bit-masks size in bytes.
965 * @param[in] range_accepted
966 * True if range of values is accepted for specific fields, false otherwise.
968 * Pointer to error structure.
971 * 0 on success, a negative errno value otherwise and rte_errno is set.
974 mlx5_flow_item_acceptable(const struct rte_flow_item *item,
976 const uint8_t *nic_mask,
979 struct rte_flow_error *error)
983 MLX5_ASSERT(nic_mask);
984 for (i = 0; i < size; ++i)
985 if ((nic_mask[i] | mask[i]) != nic_mask[i])
986 return rte_flow_error_set(error, ENOTSUP,
987 RTE_FLOW_ERROR_TYPE_ITEM,
989 "mask enables non supported"
991 if (!item->spec && (item->mask || item->last))
992 return rte_flow_error_set(error, EINVAL,
993 RTE_FLOW_ERROR_TYPE_ITEM, item,
994 "mask/last without a spec is not"
996 if (item->spec && item->last && !range_accepted) {
1002 for (i = 0; i < size; ++i) {
1003 spec[i] = ((const uint8_t *)item->spec)[i] & mask[i];
1004 last[i] = ((const uint8_t *)item->last)[i] & mask[i];
1006 ret = memcmp(spec, last, size);
1008 return rte_flow_error_set(error, EINVAL,
1009 RTE_FLOW_ERROR_TYPE_ITEM,
1011 "range is not valid");
1017 * Adjust the hash fields according to the @p flow information.
1019 * @param[in] dev_flow.
1020 * Pointer to the mlx5_flow.
1022 * 1 when the hash field is for a tunnel item.
1023 * @param[in] layer_types
1025 * @param[in] hash_fields
1029 * The hash fields that should be used.
1032 mlx5_flow_hashfields_adjust(struct mlx5_flow_rss_desc *rss_desc,
1033 int tunnel __rte_unused, uint64_t layer_types,
1034 uint64_t hash_fields)
1036 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
1037 int rss_request_inner = rss_desc->level >= 2;
1039 /* Check RSS hash level for tunnel. */
1040 if (tunnel && rss_request_inner)
1041 hash_fields |= IBV_RX_HASH_INNER;
1042 else if (tunnel || rss_request_inner)
1045 /* Check if requested layer matches RSS hash fields. */
1046 if (!(rss_desc->types & layer_types))
1052 * Lookup and set the ptype in the data Rx part. A single Ptype can be used,
1053 * if several tunnel rules are used on this queue, the tunnel ptype will be
1057 * Rx queue to update.
1060 flow_rxq_tunnel_ptype_update(struct mlx5_rxq_ctrl *rxq_ctrl)
1063 uint32_t tunnel_ptype = 0;
1065 /* Look up for the ptype to use. */
1066 for (i = 0; i != MLX5_FLOW_TUNNEL; ++i) {
1067 if (!rxq_ctrl->flow_tunnels_n[i])
1069 if (!tunnel_ptype) {
1070 tunnel_ptype = tunnels_info[i].ptype;
1076 rxq_ctrl->rxq.tunnel = tunnel_ptype;
1080 * Set the Rx queue flags (Mark/Flag and Tunnel Ptypes) according to the devive
1084 * Pointer to the Ethernet device structure.
1085 * @param[in] dev_handle
1086 * Pointer to device flow handle structure.
1089 flow_drv_rxq_flags_set(struct rte_eth_dev *dev,
1090 struct mlx5_flow_handle *dev_handle)
1092 struct mlx5_priv *priv = dev->data->dev_private;
1093 const int mark = dev_handle->mark;
1094 const int tunnel = !!(dev_handle->layers & MLX5_FLOW_LAYER_TUNNEL);
1095 struct mlx5_ind_table_obj *ind_tbl = NULL;
1098 if (dev_handle->fate_action == MLX5_FLOW_FATE_QUEUE) {
1099 struct mlx5_hrxq *hrxq;
1101 hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
1102 dev_handle->rix_hrxq);
1104 ind_tbl = hrxq->ind_table;
1105 } else if (dev_handle->fate_action == MLX5_FLOW_FATE_SHARED_RSS) {
1106 struct mlx5_shared_action_rss *shared_rss;
1108 shared_rss = mlx5_ipool_get
1109 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
1110 dev_handle->rix_srss);
1112 ind_tbl = shared_rss->ind_tbl;
1116 for (i = 0; i != ind_tbl->queues_n; ++i) {
1117 int idx = ind_tbl->queues[i];
1118 struct mlx5_rxq_ctrl *rxq_ctrl =
1119 container_of((*priv->rxqs)[idx],
1120 struct mlx5_rxq_ctrl, rxq);
1123 * To support metadata register copy on Tx loopback,
1124 * this must be always enabled (metadata may arive
1125 * from other port - not from local flows only.
1127 if (priv->config.dv_flow_en &&
1128 priv->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
1129 mlx5_flow_ext_mreg_supported(dev)) {
1130 rxq_ctrl->rxq.mark = 1;
1131 rxq_ctrl->flow_mark_n = 1;
1133 rxq_ctrl->rxq.mark = 1;
1134 rxq_ctrl->flow_mark_n++;
1139 /* Increase the counter matching the flow. */
1140 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j) {
1141 if ((tunnels_info[j].tunnel &
1142 dev_handle->layers) ==
1143 tunnels_info[j].tunnel) {
1144 rxq_ctrl->flow_tunnels_n[j]++;
1148 flow_rxq_tunnel_ptype_update(rxq_ctrl);
1154 * Set the Rx queue flags (Mark/Flag and Tunnel Ptypes) for a flow
1157 * Pointer to the Ethernet device structure.
1159 * Pointer to flow structure.
1162 flow_rxq_flags_set(struct rte_eth_dev *dev, struct rte_flow *flow)
1164 struct mlx5_priv *priv = dev->data->dev_private;
1165 uint32_t handle_idx;
1166 struct mlx5_flow_handle *dev_handle;
1168 SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
1169 handle_idx, dev_handle, next)
1170 flow_drv_rxq_flags_set(dev, dev_handle);
1174 * Clear the Rx queue flags (Mark/Flag and Tunnel Ptype) associated with the
1175 * device flow if no other flow uses it with the same kind of request.
1178 * Pointer to Ethernet device.
1179 * @param[in] dev_handle
1180 * Pointer to the device flow handle structure.
1183 flow_drv_rxq_flags_trim(struct rte_eth_dev *dev,
1184 struct mlx5_flow_handle *dev_handle)
1186 struct mlx5_priv *priv = dev->data->dev_private;
1187 const int mark = dev_handle->mark;
1188 const int tunnel = !!(dev_handle->layers & MLX5_FLOW_LAYER_TUNNEL);
1189 struct mlx5_ind_table_obj *ind_tbl = NULL;
1192 if (dev_handle->fate_action == MLX5_FLOW_FATE_QUEUE) {
1193 struct mlx5_hrxq *hrxq;
1195 hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
1196 dev_handle->rix_hrxq);
1198 ind_tbl = hrxq->ind_table;
1199 } else if (dev_handle->fate_action == MLX5_FLOW_FATE_SHARED_RSS) {
1200 struct mlx5_shared_action_rss *shared_rss;
1202 shared_rss = mlx5_ipool_get
1203 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
1204 dev_handle->rix_srss);
1206 ind_tbl = shared_rss->ind_tbl;
1210 MLX5_ASSERT(dev->data->dev_started);
1211 for (i = 0; i != ind_tbl->queues_n; ++i) {
1212 int idx = ind_tbl->queues[i];
1213 struct mlx5_rxq_ctrl *rxq_ctrl =
1214 container_of((*priv->rxqs)[idx],
1215 struct mlx5_rxq_ctrl, rxq);
1217 if (priv->config.dv_flow_en &&
1218 priv->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
1219 mlx5_flow_ext_mreg_supported(dev)) {
1220 rxq_ctrl->rxq.mark = 1;
1221 rxq_ctrl->flow_mark_n = 1;
1223 rxq_ctrl->flow_mark_n--;
1224 rxq_ctrl->rxq.mark = !!rxq_ctrl->flow_mark_n;
1229 /* Decrease the counter matching the flow. */
1230 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j) {
1231 if ((tunnels_info[j].tunnel &
1232 dev_handle->layers) ==
1233 tunnels_info[j].tunnel) {
1234 rxq_ctrl->flow_tunnels_n[j]--;
1238 flow_rxq_tunnel_ptype_update(rxq_ctrl);
1244 * Clear the Rx queue flags (Mark/Flag and Tunnel Ptype) associated with the
1245 * @p flow if no other flow uses it with the same kind of request.
1248 * Pointer to Ethernet device.
1250 * Pointer to the flow.
1253 flow_rxq_flags_trim(struct rte_eth_dev *dev, struct rte_flow *flow)
1255 struct mlx5_priv *priv = dev->data->dev_private;
1256 uint32_t handle_idx;
1257 struct mlx5_flow_handle *dev_handle;
1259 SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
1260 handle_idx, dev_handle, next)
1261 flow_drv_rxq_flags_trim(dev, dev_handle);
1265 * Clear the Mark/Flag and Tunnel ptype information in all Rx queues.
1268 * Pointer to Ethernet device.
1271 flow_rxq_flags_clear(struct rte_eth_dev *dev)
1273 struct mlx5_priv *priv = dev->data->dev_private;
1276 for (i = 0; i != priv->rxqs_n; ++i) {
1277 struct mlx5_rxq_ctrl *rxq_ctrl;
1280 if (!(*priv->rxqs)[i])
1282 rxq_ctrl = container_of((*priv->rxqs)[i],
1283 struct mlx5_rxq_ctrl, rxq);
1284 rxq_ctrl->flow_mark_n = 0;
1285 rxq_ctrl->rxq.mark = 0;
1286 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j)
1287 rxq_ctrl->flow_tunnels_n[j] = 0;
1288 rxq_ctrl->rxq.tunnel = 0;
1293 * Set the Rx queue dynamic metadata (mask and offset) for a flow
1296 * Pointer to the Ethernet device structure.
1299 mlx5_flow_rxq_dynf_metadata_set(struct rte_eth_dev *dev)
1301 struct mlx5_priv *priv = dev->data->dev_private;
1302 struct mlx5_rxq_data *data;
1305 for (i = 0; i != priv->rxqs_n; ++i) {
1306 if (!(*priv->rxqs)[i])
1308 data = (*priv->rxqs)[i];
1309 if (!rte_flow_dynf_metadata_avail()) {
1310 data->dynf_meta = 0;
1311 data->flow_meta_mask = 0;
1312 data->flow_meta_offset = -1;
1313 data->flow_meta_port_mask = 0;
1315 data->dynf_meta = 1;
1316 data->flow_meta_mask = rte_flow_dynf_metadata_mask;
1317 data->flow_meta_offset = rte_flow_dynf_metadata_offs;
1318 data->flow_meta_port_mask = (uint32_t)~0;
1319 if (priv->config.dv_xmeta_en == MLX5_XMETA_MODE_META16)
1320 data->flow_meta_port_mask >>= 16;
1326 * return a pointer to the desired action in the list of actions.
1328 * @param[in] actions
1329 * The list of actions to search the action in.
1331 * The action to find.
1334 * Pointer to the action in the list, if found. NULL otherwise.
1336 const struct rte_flow_action *
1337 mlx5_flow_find_action(const struct rte_flow_action *actions,
1338 enum rte_flow_action_type action)
1340 if (actions == NULL)
1342 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++)
1343 if (actions->type == action)
1349 * Validate the flag action.
1351 * @param[in] action_flags
1352 * Bit-fields that holds the actions detected until now.
1354 * Attributes of flow that includes this action.
1356 * Pointer to error structure.
1359 * 0 on success, a negative errno value otherwise and rte_errno is set.
1362 mlx5_flow_validate_action_flag(uint64_t action_flags,
1363 const struct rte_flow_attr *attr,
1364 struct rte_flow_error *error)
1366 if (action_flags & MLX5_FLOW_ACTION_MARK)
1367 return rte_flow_error_set(error, EINVAL,
1368 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1369 "can't mark and flag in same flow");
1370 if (action_flags & MLX5_FLOW_ACTION_FLAG)
1371 return rte_flow_error_set(error, EINVAL,
1372 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1374 " actions in same flow");
1376 return rte_flow_error_set(error, ENOTSUP,
1377 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1378 "flag action not supported for "
1384 * Validate the mark action.
1387 * Pointer to the queue action.
1388 * @param[in] action_flags
1389 * Bit-fields that holds the actions detected until now.
1391 * Attributes of flow that includes this action.
1393 * Pointer to error structure.
1396 * 0 on success, a negative errno value otherwise and rte_errno is set.
1399 mlx5_flow_validate_action_mark(const struct rte_flow_action *action,
1400 uint64_t action_flags,
1401 const struct rte_flow_attr *attr,
1402 struct rte_flow_error *error)
1404 const struct rte_flow_action_mark *mark = action->conf;
1407 return rte_flow_error_set(error, EINVAL,
1408 RTE_FLOW_ERROR_TYPE_ACTION,
1410 "configuration cannot be null");
1411 if (mark->id >= MLX5_FLOW_MARK_MAX)
1412 return rte_flow_error_set(error, EINVAL,
1413 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1415 "mark id must in 0 <= id < "
1416 RTE_STR(MLX5_FLOW_MARK_MAX));
1417 if (action_flags & MLX5_FLOW_ACTION_FLAG)
1418 return rte_flow_error_set(error, EINVAL,
1419 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1420 "can't flag and mark in same flow");
1421 if (action_flags & MLX5_FLOW_ACTION_MARK)
1422 return rte_flow_error_set(error, EINVAL,
1423 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1424 "can't have 2 mark actions in same"
1427 return rte_flow_error_set(error, ENOTSUP,
1428 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1429 "mark action not supported for "
1435 * Validate the drop action.
1437 * @param[in] action_flags
1438 * Bit-fields that holds the actions detected until now.
1440 * Attributes of flow that includes this action.
1442 * Pointer to error structure.
1445 * 0 on success, a negative errno value otherwise and rte_errno is set.
1448 mlx5_flow_validate_action_drop(uint64_t action_flags __rte_unused,
1449 const struct rte_flow_attr *attr,
1450 struct rte_flow_error *error)
1453 return rte_flow_error_set(error, ENOTSUP,
1454 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1455 "drop action not supported for "
1461 * Validate the queue action.
1464 * Pointer to the queue action.
1465 * @param[in] action_flags
1466 * Bit-fields that holds the actions detected until now.
1468 * Pointer to the Ethernet device structure.
1470 * Attributes of flow that includes this action.
1472 * Pointer to error structure.
1475 * 0 on success, a negative errno value otherwise and rte_errno is set.
1478 mlx5_flow_validate_action_queue(const struct rte_flow_action *action,
1479 uint64_t action_flags,
1480 struct rte_eth_dev *dev,
1481 const struct rte_flow_attr *attr,
1482 struct rte_flow_error *error)
1484 struct mlx5_priv *priv = dev->data->dev_private;
1485 const struct rte_flow_action_queue *queue = action->conf;
1487 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
1488 return rte_flow_error_set(error, EINVAL,
1489 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1490 "can't have 2 fate actions in"
1493 return rte_flow_error_set(error, EINVAL,
1494 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1495 NULL, "No Rx queues configured");
1496 if (queue->index >= priv->rxqs_n)
1497 return rte_flow_error_set(error, EINVAL,
1498 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1500 "queue index out of range");
1501 if (!(*priv->rxqs)[queue->index])
1502 return rte_flow_error_set(error, EINVAL,
1503 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1505 "queue is not configured");
1507 return rte_flow_error_set(error, ENOTSUP,
1508 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1509 "queue action not supported for "
1515 * Validate the rss action.
1518 * Pointer to the Ethernet device structure.
1520 * Pointer to the queue action.
1522 * Pointer to error structure.
1525 * 0 on success, a negative errno value otherwise and rte_errno is set.
1528 mlx5_validate_action_rss(struct rte_eth_dev *dev,
1529 const struct rte_flow_action *action,
1530 struct rte_flow_error *error)
1532 struct mlx5_priv *priv = dev->data->dev_private;
1533 const struct rte_flow_action_rss *rss = action->conf;
1534 enum mlx5_rxq_type rxq_type = MLX5_RXQ_TYPE_UNDEFINED;
1537 if (rss->func != RTE_ETH_HASH_FUNCTION_DEFAULT &&
1538 rss->func != RTE_ETH_HASH_FUNCTION_TOEPLITZ)
1539 return rte_flow_error_set(error, ENOTSUP,
1540 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1542 "RSS hash function not supported");
1543 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
1548 return rte_flow_error_set(error, ENOTSUP,
1549 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1551 "tunnel RSS is not supported");
1552 /* allow RSS key_len 0 in case of NULL (default) RSS key. */
1553 if (rss->key_len == 0 && rss->key != NULL)
1554 return rte_flow_error_set(error, ENOTSUP,
1555 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1557 "RSS hash key length 0");
1558 if (rss->key_len > 0 && rss->key_len < MLX5_RSS_HASH_KEY_LEN)
1559 return rte_flow_error_set(error, ENOTSUP,
1560 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1562 "RSS hash key too small");
1563 if (rss->key_len > MLX5_RSS_HASH_KEY_LEN)
1564 return rte_flow_error_set(error, ENOTSUP,
1565 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1567 "RSS hash key too large");
1568 if (rss->queue_num > priv->config.ind_table_max_size)
1569 return rte_flow_error_set(error, ENOTSUP,
1570 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1572 "number of queues too large");
1573 if (rss->types & MLX5_RSS_HF_MASK)
1574 return rte_flow_error_set(error, ENOTSUP,
1575 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1577 "some RSS protocols are not"
1579 if ((rss->types & (ETH_RSS_L3_SRC_ONLY | ETH_RSS_L3_DST_ONLY)) &&
1580 !(rss->types & ETH_RSS_IP))
1581 return rte_flow_error_set(error, EINVAL,
1582 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1583 "L3 partial RSS requested but L3 RSS"
1584 " type not specified");
1585 if ((rss->types & (ETH_RSS_L4_SRC_ONLY | ETH_RSS_L4_DST_ONLY)) &&
1586 !(rss->types & (ETH_RSS_UDP | ETH_RSS_TCP)))
1587 return rte_flow_error_set(error, EINVAL,
1588 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1589 "L4 partial RSS requested but L4 RSS"
1590 " type not specified");
1592 return rte_flow_error_set(error, EINVAL,
1593 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1594 NULL, "No Rx queues configured");
1595 if (!rss->queue_num)
1596 return rte_flow_error_set(error, EINVAL,
1597 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1598 NULL, "No queues configured");
1599 for (i = 0; i != rss->queue_num; ++i) {
1600 struct mlx5_rxq_ctrl *rxq_ctrl;
1602 if (rss->queue[i] >= priv->rxqs_n)
1603 return rte_flow_error_set
1605 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1606 &rss->queue[i], "queue index out of range");
1607 if (!(*priv->rxqs)[rss->queue[i]])
1608 return rte_flow_error_set
1609 (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1610 &rss->queue[i], "queue is not configured");
1611 rxq_ctrl = container_of((*priv->rxqs)[rss->queue[i]],
1612 struct mlx5_rxq_ctrl, rxq);
1614 rxq_type = rxq_ctrl->type;
1615 if (rxq_type != rxq_ctrl->type)
1616 return rte_flow_error_set
1617 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1619 "combining hairpin and regular RSS queues is not supported");
1625 * Validate the rss action.
1628 * Pointer to the queue action.
1629 * @param[in] action_flags
1630 * Bit-fields that holds the actions detected until now.
1632 * Pointer to the Ethernet device structure.
1634 * Attributes of flow that includes this action.
1635 * @param[in] item_flags
1636 * Items that were detected.
1638 * Pointer to error structure.
1641 * 0 on success, a negative errno value otherwise and rte_errno is set.
1644 mlx5_flow_validate_action_rss(const struct rte_flow_action *action,
1645 uint64_t action_flags,
1646 struct rte_eth_dev *dev,
1647 const struct rte_flow_attr *attr,
1648 uint64_t item_flags,
1649 struct rte_flow_error *error)
1651 const struct rte_flow_action_rss *rss = action->conf;
1652 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1655 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
1656 return rte_flow_error_set(error, EINVAL,
1657 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1658 "can't have 2 fate actions"
1660 ret = mlx5_validate_action_rss(dev, action, error);
1664 return rte_flow_error_set(error, ENOTSUP,
1665 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1666 "rss action not supported for "
1668 if (rss->level > 1 && !tunnel)
1669 return rte_flow_error_set(error, EINVAL,
1670 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1671 "inner RSS is not supported for "
1672 "non-tunnel flows");
1673 if ((item_flags & MLX5_FLOW_LAYER_ECPRI) &&
1674 !(item_flags & MLX5_FLOW_LAYER_INNER_L4_UDP)) {
1675 return rte_flow_error_set(error, EINVAL,
1676 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1677 "RSS on eCPRI is not supported now");
1679 if ((item_flags & MLX5_FLOW_LAYER_MPLS) &&
1681 (MLX5_FLOW_LAYER_INNER_L2 | MLX5_FLOW_LAYER_INNER_L3)) &&
1683 return rte_flow_error_set(error, EINVAL,
1684 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
1685 "MPLS inner RSS needs to specify inner L2/L3 items after MPLS in pattern");
1690 * Validate the default miss action.
1692 * @param[in] action_flags
1693 * Bit-fields that holds the actions detected until now.
1695 * Pointer to error structure.
1698 * 0 on success, a negative errno value otherwise and rte_errno is set.
1701 mlx5_flow_validate_action_default_miss(uint64_t action_flags,
1702 const struct rte_flow_attr *attr,
1703 struct rte_flow_error *error)
1705 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
1706 return rte_flow_error_set(error, EINVAL,
1707 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1708 "can't have 2 fate actions in"
1711 return rte_flow_error_set(error, ENOTSUP,
1712 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1713 "default miss action not supported "
1716 return rte_flow_error_set(error, ENOTSUP,
1717 RTE_FLOW_ERROR_TYPE_ATTR_GROUP, NULL,
1718 "only group 0 is supported");
1720 return rte_flow_error_set(error, ENOTSUP,
1721 RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
1722 NULL, "transfer is not supported");
1727 * Validate the count action.
1730 * Pointer to the Ethernet device structure.
1732 * Attributes of flow that includes this action.
1734 * Pointer to error structure.
1737 * 0 on success, a negative errno value otherwise and rte_errno is set.
1740 mlx5_flow_validate_action_count(struct rte_eth_dev *dev __rte_unused,
1741 const struct rte_flow_attr *attr,
1742 struct rte_flow_error *error)
1745 return rte_flow_error_set(error, ENOTSUP,
1746 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1747 "count action not supported for "
1753 * Validate the ASO CT action.
1756 * Pointer to the Ethernet device structure.
1757 * @param[in] conntrack
1758 * Pointer to the CT action profile.
1760 * Pointer to error structure.
1763 * 0 on success, a negative errno value otherwise and rte_errno is set.
1766 mlx5_validate_action_ct(struct rte_eth_dev *dev,
1767 const struct rte_flow_action_conntrack *conntrack,
1768 struct rte_flow_error *error)
1772 if (conntrack->state > RTE_FLOW_CONNTRACK_STATE_TIME_WAIT)
1773 return rte_flow_error_set(error, EINVAL,
1774 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1775 "Invalid CT state");
1776 if (conntrack->last_index > RTE_FLOW_CONNTRACK_FLAG_RST)
1777 return rte_flow_error_set(error, EINVAL,
1778 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1779 "Invalid last TCP packet flag");
1784 * Verify the @p attributes will be correctly understood by the NIC and store
1785 * them in the @p flow if everything is correct.
1788 * Pointer to the Ethernet device structure.
1789 * @param[in] attributes
1790 * Pointer to flow attributes
1792 * Pointer to error structure.
1795 * 0 on success, a negative errno value otherwise and rte_errno is set.
1798 mlx5_flow_validate_attributes(struct rte_eth_dev *dev,
1799 const struct rte_flow_attr *attributes,
1800 struct rte_flow_error *error)
1802 struct mlx5_priv *priv = dev->data->dev_private;
1803 uint32_t priority_max = priv->config.flow_prio - 1;
1805 if (attributes->group)
1806 return rte_flow_error_set(error, ENOTSUP,
1807 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
1808 NULL, "groups is not supported");
1809 if (attributes->priority != MLX5_FLOW_LOWEST_PRIO_INDICATOR &&
1810 attributes->priority >= priority_max)
1811 return rte_flow_error_set(error, ENOTSUP,
1812 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
1813 NULL, "priority out of range");
1814 if (attributes->egress)
1815 return rte_flow_error_set(error, ENOTSUP,
1816 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1817 "egress is not supported");
1818 if (attributes->transfer && !priv->config.dv_esw_en)
1819 return rte_flow_error_set(error, ENOTSUP,
1820 RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
1821 NULL, "transfer is not supported");
1822 if (!attributes->ingress)
1823 return rte_flow_error_set(error, EINVAL,
1824 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
1826 "ingress attribute is mandatory");
1831 * Validate ICMP6 item.
1834 * Item specification.
1835 * @param[in] item_flags
1836 * Bit-fields that holds the items detected until now.
1837 * @param[in] ext_vlan_sup
1838 * Whether extended VLAN features are supported or not.
1840 * Pointer to error structure.
1843 * 0 on success, a negative errno value otherwise and rte_errno is set.
1846 mlx5_flow_validate_item_icmp6(const struct rte_flow_item *item,
1847 uint64_t item_flags,
1848 uint8_t target_protocol,
1849 struct rte_flow_error *error)
1851 const struct rte_flow_item_icmp6 *mask = item->mask;
1852 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1853 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
1854 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
1855 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1856 MLX5_FLOW_LAYER_OUTER_L4;
1859 if (target_protocol != 0xFF && target_protocol != IPPROTO_ICMPV6)
1860 return rte_flow_error_set(error, EINVAL,
1861 RTE_FLOW_ERROR_TYPE_ITEM, item,
1862 "protocol filtering not compatible"
1863 " with ICMP6 layer");
1864 if (!(item_flags & l3m))
1865 return rte_flow_error_set(error, EINVAL,
1866 RTE_FLOW_ERROR_TYPE_ITEM, item,
1867 "IPv6 is mandatory to filter on"
1869 if (item_flags & l4m)
1870 return rte_flow_error_set(error, EINVAL,
1871 RTE_FLOW_ERROR_TYPE_ITEM, item,
1872 "multiple L4 layers not supported");
1874 mask = &rte_flow_item_icmp6_mask;
1875 ret = mlx5_flow_item_acceptable
1876 (item, (const uint8_t *)mask,
1877 (const uint8_t *)&rte_flow_item_icmp6_mask,
1878 sizeof(struct rte_flow_item_icmp6),
1879 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
1886 * Validate ICMP item.
1889 * Item specification.
1890 * @param[in] item_flags
1891 * Bit-fields that holds the items detected until now.
1893 * Pointer to error structure.
1896 * 0 on success, a negative errno value otherwise and rte_errno is set.
1899 mlx5_flow_validate_item_icmp(const struct rte_flow_item *item,
1900 uint64_t item_flags,
1901 uint8_t target_protocol,
1902 struct rte_flow_error *error)
1904 const struct rte_flow_item_icmp *mask = item->mask;
1905 const struct rte_flow_item_icmp nic_mask = {
1906 .hdr.icmp_type = 0xff,
1907 .hdr.icmp_code = 0xff,
1908 .hdr.icmp_ident = RTE_BE16(0xffff),
1909 .hdr.icmp_seq_nb = RTE_BE16(0xffff),
1911 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1912 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
1913 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
1914 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1915 MLX5_FLOW_LAYER_OUTER_L4;
1918 if (target_protocol != 0xFF && target_protocol != IPPROTO_ICMP)
1919 return rte_flow_error_set(error, EINVAL,
1920 RTE_FLOW_ERROR_TYPE_ITEM, item,
1921 "protocol filtering not compatible"
1922 " with ICMP layer");
1923 if (!(item_flags & l3m))
1924 return rte_flow_error_set(error, EINVAL,
1925 RTE_FLOW_ERROR_TYPE_ITEM, item,
1926 "IPv4 is mandatory to filter"
1928 if (item_flags & l4m)
1929 return rte_flow_error_set(error, EINVAL,
1930 RTE_FLOW_ERROR_TYPE_ITEM, item,
1931 "multiple L4 layers not supported");
1934 ret = mlx5_flow_item_acceptable
1935 (item, (const uint8_t *)mask,
1936 (const uint8_t *)&nic_mask,
1937 sizeof(struct rte_flow_item_icmp),
1938 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
1945 * Validate Ethernet item.
1948 * Item specification.
1949 * @param[in] item_flags
1950 * Bit-fields that holds the items detected until now.
1952 * Pointer to error structure.
1955 * 0 on success, a negative errno value otherwise and rte_errno is set.
1958 mlx5_flow_validate_item_eth(const struct rte_flow_item *item,
1959 uint64_t item_flags, bool ext_vlan_sup,
1960 struct rte_flow_error *error)
1962 const struct rte_flow_item_eth *mask = item->mask;
1963 const struct rte_flow_item_eth nic_mask = {
1964 .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
1965 .src.addr_bytes = "\xff\xff\xff\xff\xff\xff",
1966 .type = RTE_BE16(0xffff),
1967 .has_vlan = ext_vlan_sup ? 1 : 0,
1970 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1971 const uint64_t ethm = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
1972 MLX5_FLOW_LAYER_OUTER_L2;
1974 if (item_flags & ethm)
1975 return rte_flow_error_set(error, ENOTSUP,
1976 RTE_FLOW_ERROR_TYPE_ITEM, item,
1977 "multiple L2 layers not supported");
1978 if ((!tunnel && (item_flags & MLX5_FLOW_LAYER_OUTER_L3)) ||
1979 (tunnel && (item_flags & MLX5_FLOW_LAYER_INNER_L3)))
1980 return rte_flow_error_set(error, EINVAL,
1981 RTE_FLOW_ERROR_TYPE_ITEM, item,
1982 "L2 layer should not follow "
1984 if ((!tunnel && (item_flags & MLX5_FLOW_LAYER_OUTER_VLAN)) ||
1985 (tunnel && (item_flags & MLX5_FLOW_LAYER_INNER_VLAN)))
1986 return rte_flow_error_set(error, EINVAL,
1987 RTE_FLOW_ERROR_TYPE_ITEM, item,
1988 "L2 layer should not follow VLAN");
1990 mask = &rte_flow_item_eth_mask;
1991 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1992 (const uint8_t *)&nic_mask,
1993 sizeof(struct rte_flow_item_eth),
1994 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
1999 * Validate VLAN item.
2002 * Item specification.
2003 * @param[in] item_flags
2004 * Bit-fields that holds the items detected until now.
2006 * Ethernet device flow is being created on.
2008 * Pointer to error structure.
2011 * 0 on success, a negative errno value otherwise and rte_errno is set.
2014 mlx5_flow_validate_item_vlan(const struct rte_flow_item *item,
2015 uint64_t item_flags,
2016 struct rte_eth_dev *dev,
2017 struct rte_flow_error *error)
2019 const struct rte_flow_item_vlan *spec = item->spec;
2020 const struct rte_flow_item_vlan *mask = item->mask;
2021 const struct rte_flow_item_vlan nic_mask = {
2022 .tci = RTE_BE16(UINT16_MAX),
2023 .inner_type = RTE_BE16(UINT16_MAX),
2025 uint16_t vlan_tag = 0;
2026 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2028 const uint64_t l34m = tunnel ? (MLX5_FLOW_LAYER_INNER_L3 |
2029 MLX5_FLOW_LAYER_INNER_L4) :
2030 (MLX5_FLOW_LAYER_OUTER_L3 |
2031 MLX5_FLOW_LAYER_OUTER_L4);
2032 const uint64_t vlanm = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
2033 MLX5_FLOW_LAYER_OUTER_VLAN;
2035 if (item_flags & vlanm)
2036 return rte_flow_error_set(error, EINVAL,
2037 RTE_FLOW_ERROR_TYPE_ITEM, item,
2038 "multiple VLAN layers not supported");
2039 else if ((item_flags & l34m) != 0)
2040 return rte_flow_error_set(error, EINVAL,
2041 RTE_FLOW_ERROR_TYPE_ITEM, item,
2042 "VLAN cannot follow L3/L4 layer");
2044 mask = &rte_flow_item_vlan_mask;
2045 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2046 (const uint8_t *)&nic_mask,
2047 sizeof(struct rte_flow_item_vlan),
2048 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2051 if (!tunnel && mask->tci != RTE_BE16(0x0fff)) {
2052 struct mlx5_priv *priv = dev->data->dev_private;
2054 if (priv->vmwa_context) {
2056 * Non-NULL context means we have a virtual machine
2057 * and SR-IOV enabled, we have to create VLAN interface
2058 * to make hypervisor to setup E-Switch vport
2059 * context correctly. We avoid creating the multiple
2060 * VLAN interfaces, so we cannot support VLAN tag mask.
2062 return rte_flow_error_set(error, EINVAL,
2063 RTE_FLOW_ERROR_TYPE_ITEM,
2065 "VLAN tag mask is not"
2066 " supported in virtual"
2071 vlan_tag = spec->tci;
2072 vlan_tag &= mask->tci;
2075 * From verbs perspective an empty VLAN is equivalent
2076 * to a packet without VLAN layer.
2079 return rte_flow_error_set(error, EINVAL,
2080 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
2082 "VLAN cannot be empty");
2087 * Validate IPV4 item.
2090 * Item specification.
2091 * @param[in] item_flags
2092 * Bit-fields that holds the items detected until now.
2093 * @param[in] last_item
2094 * Previous validated item in the pattern items.
2095 * @param[in] ether_type
2096 * Type in the ethernet layer header (including dot1q).
2097 * @param[in] acc_mask
2098 * Acceptable mask, if NULL default internal default mask
2099 * will be used to check whether item fields are supported.
2100 * @param[in] range_accepted
2101 * True if range of values is accepted for specific fields, false otherwise.
2103 * Pointer to error structure.
2106 * 0 on success, a negative errno value otherwise and rte_errno is set.
2109 mlx5_flow_validate_item_ipv4(const struct rte_flow_item *item,
2110 uint64_t item_flags,
2112 uint16_t ether_type,
2113 const struct rte_flow_item_ipv4 *acc_mask,
2114 bool range_accepted,
2115 struct rte_flow_error *error)
2117 const struct rte_flow_item_ipv4 *mask = item->mask;
2118 const struct rte_flow_item_ipv4 *spec = item->spec;
2119 const struct rte_flow_item_ipv4 nic_mask = {
2121 .src_addr = RTE_BE32(0xffffffff),
2122 .dst_addr = RTE_BE32(0xffffffff),
2123 .type_of_service = 0xff,
2124 .next_proto_id = 0xff,
2127 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2128 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2129 MLX5_FLOW_LAYER_OUTER_L3;
2130 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2131 MLX5_FLOW_LAYER_OUTER_L4;
2133 uint8_t next_proto = 0xFF;
2134 const uint64_t l2_vlan = (MLX5_FLOW_LAYER_L2 |
2135 MLX5_FLOW_LAYER_OUTER_VLAN |
2136 MLX5_FLOW_LAYER_INNER_VLAN);
2138 if ((last_item & l2_vlan) && ether_type &&
2139 ether_type != RTE_ETHER_TYPE_IPV4)
2140 return rte_flow_error_set(error, EINVAL,
2141 RTE_FLOW_ERROR_TYPE_ITEM, item,
2142 "IPv4 cannot follow L2/VLAN layer "
2143 "which ether type is not IPv4");
2144 if (item_flags & MLX5_FLOW_LAYER_TUNNEL) {
2146 next_proto = mask->hdr.next_proto_id &
2147 spec->hdr.next_proto_id;
2148 if (next_proto == IPPROTO_IPIP || next_proto == IPPROTO_IPV6)
2149 return rte_flow_error_set(error, EINVAL,
2150 RTE_FLOW_ERROR_TYPE_ITEM,
2155 if (item_flags & MLX5_FLOW_LAYER_IPV6_ENCAP)
2156 return rte_flow_error_set(error, EINVAL,
2157 RTE_FLOW_ERROR_TYPE_ITEM, item,
2158 "wrong tunnel type - IPv6 specified "
2159 "but IPv4 item provided");
2160 if (item_flags & l3m)
2161 return rte_flow_error_set(error, ENOTSUP,
2162 RTE_FLOW_ERROR_TYPE_ITEM, item,
2163 "multiple L3 layers not supported");
2164 else if (item_flags & l4m)
2165 return rte_flow_error_set(error, EINVAL,
2166 RTE_FLOW_ERROR_TYPE_ITEM, item,
2167 "L3 cannot follow an L4 layer.");
2168 else if ((item_flags & MLX5_FLOW_LAYER_NVGRE) &&
2169 !(item_flags & MLX5_FLOW_LAYER_INNER_L2))
2170 return rte_flow_error_set(error, EINVAL,
2171 RTE_FLOW_ERROR_TYPE_ITEM, item,
2172 "L3 cannot follow an NVGRE layer.");
2174 mask = &rte_flow_item_ipv4_mask;
2175 else if (mask->hdr.next_proto_id != 0 &&
2176 mask->hdr.next_proto_id != 0xff)
2177 return rte_flow_error_set(error, EINVAL,
2178 RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
2179 "partial mask is not supported"
2181 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2182 acc_mask ? (const uint8_t *)acc_mask
2183 : (const uint8_t *)&nic_mask,
2184 sizeof(struct rte_flow_item_ipv4),
2185 range_accepted, error);
2192 * Validate IPV6 item.
2195 * Item specification.
2196 * @param[in] item_flags
2197 * Bit-fields that holds the items detected until now.
2198 * @param[in] last_item
2199 * Previous validated item in the pattern items.
2200 * @param[in] ether_type
2201 * Type in the ethernet layer header (including dot1q).
2202 * @param[in] acc_mask
2203 * Acceptable mask, if NULL default internal default mask
2204 * will be used to check whether item fields are supported.
2206 * Pointer to error structure.
2209 * 0 on success, a negative errno value otherwise and rte_errno is set.
2212 mlx5_flow_validate_item_ipv6(const struct rte_flow_item *item,
2213 uint64_t item_flags,
2215 uint16_t ether_type,
2216 const struct rte_flow_item_ipv6 *acc_mask,
2217 struct rte_flow_error *error)
2219 const struct rte_flow_item_ipv6 *mask = item->mask;
2220 const struct rte_flow_item_ipv6 *spec = item->spec;
2221 const struct rte_flow_item_ipv6 nic_mask = {
2224 "\xff\xff\xff\xff\xff\xff\xff\xff"
2225 "\xff\xff\xff\xff\xff\xff\xff\xff",
2227 "\xff\xff\xff\xff\xff\xff\xff\xff"
2228 "\xff\xff\xff\xff\xff\xff\xff\xff",
2229 .vtc_flow = RTE_BE32(0xffffffff),
2233 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2234 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2235 MLX5_FLOW_LAYER_OUTER_L3;
2236 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2237 MLX5_FLOW_LAYER_OUTER_L4;
2239 uint8_t next_proto = 0xFF;
2240 const uint64_t l2_vlan = (MLX5_FLOW_LAYER_L2 |
2241 MLX5_FLOW_LAYER_OUTER_VLAN |
2242 MLX5_FLOW_LAYER_INNER_VLAN);
2244 if ((last_item & l2_vlan) && ether_type &&
2245 ether_type != RTE_ETHER_TYPE_IPV6)
2246 return rte_flow_error_set(error, EINVAL,
2247 RTE_FLOW_ERROR_TYPE_ITEM, item,
2248 "IPv6 cannot follow L2/VLAN layer "
2249 "which ether type is not IPv6");
2250 if (mask && mask->hdr.proto == UINT8_MAX && spec)
2251 next_proto = spec->hdr.proto;
2252 if (item_flags & MLX5_FLOW_LAYER_TUNNEL) {
2253 if (next_proto == IPPROTO_IPIP || next_proto == IPPROTO_IPV6)
2254 return rte_flow_error_set(error, EINVAL,
2255 RTE_FLOW_ERROR_TYPE_ITEM,
2260 if (next_proto == IPPROTO_HOPOPTS ||
2261 next_proto == IPPROTO_ROUTING ||
2262 next_proto == IPPROTO_FRAGMENT ||
2263 next_proto == IPPROTO_ESP ||
2264 next_proto == IPPROTO_AH ||
2265 next_proto == IPPROTO_DSTOPTS)
2266 return rte_flow_error_set(error, EINVAL,
2267 RTE_FLOW_ERROR_TYPE_ITEM, item,
2268 "IPv6 proto (next header) should "
2269 "not be set as extension header");
2270 if (item_flags & MLX5_FLOW_LAYER_IPIP)
2271 return rte_flow_error_set(error, EINVAL,
2272 RTE_FLOW_ERROR_TYPE_ITEM, item,
2273 "wrong tunnel type - IPv4 specified "
2274 "but IPv6 item provided");
2275 if (item_flags & l3m)
2276 return rte_flow_error_set(error, ENOTSUP,
2277 RTE_FLOW_ERROR_TYPE_ITEM, item,
2278 "multiple L3 layers not supported");
2279 else if (item_flags & l4m)
2280 return rte_flow_error_set(error, EINVAL,
2281 RTE_FLOW_ERROR_TYPE_ITEM, item,
2282 "L3 cannot follow an L4 layer.");
2283 else if ((item_flags & MLX5_FLOW_LAYER_NVGRE) &&
2284 !(item_flags & MLX5_FLOW_LAYER_INNER_L2))
2285 return rte_flow_error_set(error, EINVAL,
2286 RTE_FLOW_ERROR_TYPE_ITEM, item,
2287 "L3 cannot follow an NVGRE layer.");
2289 mask = &rte_flow_item_ipv6_mask;
2290 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2291 acc_mask ? (const uint8_t *)acc_mask
2292 : (const uint8_t *)&nic_mask,
2293 sizeof(struct rte_flow_item_ipv6),
2294 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2301 * Validate UDP item.
2304 * Item specification.
2305 * @param[in] item_flags
2306 * Bit-fields that holds the items detected until now.
2307 * @param[in] target_protocol
2308 * The next protocol in the previous item.
2309 * @param[in] flow_mask
2310 * mlx5 flow-specific (DV, verbs, etc.) supported header fields mask.
2312 * Pointer to error structure.
2315 * 0 on success, a negative errno value otherwise and rte_errno is set.
2318 mlx5_flow_validate_item_udp(const struct rte_flow_item *item,
2319 uint64_t item_flags,
2320 uint8_t target_protocol,
2321 struct rte_flow_error *error)
2323 const struct rte_flow_item_udp *mask = item->mask;
2324 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2325 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2326 MLX5_FLOW_LAYER_OUTER_L3;
2327 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2328 MLX5_FLOW_LAYER_OUTER_L4;
2331 if (target_protocol != 0xff && target_protocol != IPPROTO_UDP)
2332 return rte_flow_error_set(error, EINVAL,
2333 RTE_FLOW_ERROR_TYPE_ITEM, item,
2334 "protocol filtering not compatible"
2336 if (!(item_flags & l3m))
2337 return rte_flow_error_set(error, EINVAL,
2338 RTE_FLOW_ERROR_TYPE_ITEM, item,
2339 "L3 is mandatory to filter on L4");
2340 if (item_flags & l4m)
2341 return rte_flow_error_set(error, EINVAL,
2342 RTE_FLOW_ERROR_TYPE_ITEM, item,
2343 "multiple L4 layers not supported");
2345 mask = &rte_flow_item_udp_mask;
2346 ret = mlx5_flow_item_acceptable
2347 (item, (const uint8_t *)mask,
2348 (const uint8_t *)&rte_flow_item_udp_mask,
2349 sizeof(struct rte_flow_item_udp), MLX5_ITEM_RANGE_NOT_ACCEPTED,
2357 * Validate TCP item.
2360 * Item specification.
2361 * @param[in] item_flags
2362 * Bit-fields that holds the items detected until now.
2363 * @param[in] target_protocol
2364 * The next protocol in the previous item.
2366 * Pointer to error structure.
2369 * 0 on success, a negative errno value otherwise and rte_errno is set.
2372 mlx5_flow_validate_item_tcp(const struct rte_flow_item *item,
2373 uint64_t item_flags,
2374 uint8_t target_protocol,
2375 const struct rte_flow_item_tcp *flow_mask,
2376 struct rte_flow_error *error)
2378 const struct rte_flow_item_tcp *mask = item->mask;
2379 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2380 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2381 MLX5_FLOW_LAYER_OUTER_L3;
2382 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2383 MLX5_FLOW_LAYER_OUTER_L4;
2386 MLX5_ASSERT(flow_mask);
2387 if (target_protocol != 0xff && target_protocol != IPPROTO_TCP)
2388 return rte_flow_error_set(error, EINVAL,
2389 RTE_FLOW_ERROR_TYPE_ITEM, item,
2390 "protocol filtering not compatible"
2392 if (!(item_flags & l3m))
2393 return rte_flow_error_set(error, EINVAL,
2394 RTE_FLOW_ERROR_TYPE_ITEM, item,
2395 "L3 is mandatory to filter on L4");
2396 if (item_flags & l4m)
2397 return rte_flow_error_set(error, EINVAL,
2398 RTE_FLOW_ERROR_TYPE_ITEM, item,
2399 "multiple L4 layers not supported");
2401 mask = &rte_flow_item_tcp_mask;
2402 ret = mlx5_flow_item_acceptable
2403 (item, (const uint8_t *)mask,
2404 (const uint8_t *)flow_mask,
2405 sizeof(struct rte_flow_item_tcp), MLX5_ITEM_RANGE_NOT_ACCEPTED,
2413 * Validate VXLAN item.
2416 * Pointer to the Ethernet device structure.
2418 * Item specification.
2419 * @param[in] item_flags
2420 * Bit-fields that holds the items detected until now.
2422 * Flow rule attributes.
2424 * Pointer to error structure.
2427 * 0 on success, a negative errno value otherwise and rte_errno is set.
2430 mlx5_flow_validate_item_vxlan(struct rte_eth_dev *dev,
2431 const struct rte_flow_item *item,
2432 uint64_t item_flags,
2433 const struct rte_flow_attr *attr,
2434 struct rte_flow_error *error)
2436 const struct rte_flow_item_vxlan *spec = item->spec;
2437 const struct rte_flow_item_vxlan *mask = item->mask;
2439 struct mlx5_priv *priv = dev->data->dev_private;
2443 } id = { .vlan_id = 0, };
2444 const struct rte_flow_item_vxlan nic_mask = {
2445 .vni = "\xff\xff\xff",
2448 const struct rte_flow_item_vxlan *valid_mask;
2450 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2451 return rte_flow_error_set(error, ENOTSUP,
2452 RTE_FLOW_ERROR_TYPE_ITEM, item,
2453 "multiple tunnel layers not"
2455 valid_mask = &rte_flow_item_vxlan_mask;
2457 * Verify only UDPv4 is present as defined in
2458 * https://tools.ietf.org/html/rfc7348
2460 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2461 return rte_flow_error_set(error, EINVAL,
2462 RTE_FLOW_ERROR_TYPE_ITEM, item,
2463 "no outer UDP layer found");
2465 mask = &rte_flow_item_vxlan_mask;
2466 /* FDB domain & NIC domain non-zero group */
2467 if ((attr->transfer || attr->group) && priv->sh->misc5_cap)
2468 valid_mask = &nic_mask;
2469 /* Group zero in NIC domain */
2470 if (!attr->group && !attr->transfer && priv->sh->tunnel_header_0_1)
2471 valid_mask = &nic_mask;
2472 ret = mlx5_flow_item_acceptable
2473 (item, (const uint8_t *)mask,
2474 (const uint8_t *)valid_mask,
2475 sizeof(struct rte_flow_item_vxlan),
2476 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2480 memcpy(&id.vni[1], spec->vni, 3);
2481 memcpy(&id.vni[1], mask->vni, 3);
2483 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
2484 return rte_flow_error_set(error, ENOTSUP,
2485 RTE_FLOW_ERROR_TYPE_ITEM, item,
2486 "VXLAN tunnel must be fully defined");
2491 * Validate VXLAN_GPE item.
2494 * Item specification.
2495 * @param[in] item_flags
2496 * Bit-fields that holds the items detected until now.
2498 * Pointer to the private data structure.
2499 * @param[in] target_protocol
2500 * The next protocol in the previous item.
2502 * Pointer to error structure.
2505 * 0 on success, a negative errno value otherwise and rte_errno is set.
2508 mlx5_flow_validate_item_vxlan_gpe(const struct rte_flow_item *item,
2509 uint64_t item_flags,
2510 struct rte_eth_dev *dev,
2511 struct rte_flow_error *error)
2513 struct mlx5_priv *priv = dev->data->dev_private;
2514 const struct rte_flow_item_vxlan_gpe *spec = item->spec;
2515 const struct rte_flow_item_vxlan_gpe *mask = item->mask;
2520 } id = { .vlan_id = 0, };
2522 if (!priv->config.l3_vxlan_en)
2523 return rte_flow_error_set(error, ENOTSUP,
2524 RTE_FLOW_ERROR_TYPE_ITEM, item,
2525 "L3 VXLAN is not enabled by device"
2526 " parameter and/or not configured in"
2528 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2529 return rte_flow_error_set(error, ENOTSUP,
2530 RTE_FLOW_ERROR_TYPE_ITEM, item,
2531 "multiple tunnel layers not"
2534 * Verify only UDPv4 is present as defined in
2535 * https://tools.ietf.org/html/rfc7348
2537 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2538 return rte_flow_error_set(error, EINVAL,
2539 RTE_FLOW_ERROR_TYPE_ITEM, item,
2540 "no outer UDP layer found");
2542 mask = &rte_flow_item_vxlan_gpe_mask;
2543 ret = mlx5_flow_item_acceptable
2544 (item, (const uint8_t *)mask,
2545 (const uint8_t *)&rte_flow_item_vxlan_gpe_mask,
2546 sizeof(struct rte_flow_item_vxlan_gpe),
2547 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2552 return rte_flow_error_set(error, ENOTSUP,
2553 RTE_FLOW_ERROR_TYPE_ITEM,
2555 "VxLAN-GPE protocol"
2557 memcpy(&id.vni[1], spec->vni, 3);
2558 memcpy(&id.vni[1], mask->vni, 3);
2560 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
2561 return rte_flow_error_set(error, ENOTSUP,
2562 RTE_FLOW_ERROR_TYPE_ITEM, item,
2563 "VXLAN-GPE tunnel must be fully"
2568 * Validate GRE Key item.
2571 * Item specification.
2572 * @param[in] item_flags
2573 * Bit flags to mark detected items.
2574 * @param[in] gre_item
2575 * Pointer to gre_item
2577 * Pointer to error structure.
2580 * 0 on success, a negative errno value otherwise and rte_errno is set.
2583 mlx5_flow_validate_item_gre_key(const struct rte_flow_item *item,
2584 uint64_t item_flags,
2585 const struct rte_flow_item *gre_item,
2586 struct rte_flow_error *error)
2588 const rte_be32_t *mask = item->mask;
2590 rte_be32_t gre_key_default_mask = RTE_BE32(UINT32_MAX);
2591 const struct rte_flow_item_gre *gre_spec;
2592 const struct rte_flow_item_gre *gre_mask;
2594 if (item_flags & MLX5_FLOW_LAYER_GRE_KEY)
2595 return rte_flow_error_set(error, ENOTSUP,
2596 RTE_FLOW_ERROR_TYPE_ITEM, item,
2597 "Multiple GRE key not support");
2598 if (!(item_flags & MLX5_FLOW_LAYER_GRE))
2599 return rte_flow_error_set(error, ENOTSUP,
2600 RTE_FLOW_ERROR_TYPE_ITEM, item,
2601 "No preceding GRE header");
2602 if (item_flags & MLX5_FLOW_LAYER_INNER)
2603 return rte_flow_error_set(error, ENOTSUP,
2604 RTE_FLOW_ERROR_TYPE_ITEM, item,
2605 "GRE key following a wrong item");
2606 gre_mask = gre_item->mask;
2608 gre_mask = &rte_flow_item_gre_mask;
2609 gre_spec = gre_item->spec;
2610 if (gre_spec && (gre_mask->c_rsvd0_ver & RTE_BE16(0x2000)) &&
2611 !(gre_spec->c_rsvd0_ver & RTE_BE16(0x2000)))
2612 return rte_flow_error_set(error, EINVAL,
2613 RTE_FLOW_ERROR_TYPE_ITEM, item,
2614 "Key bit must be on");
2617 mask = &gre_key_default_mask;
2618 ret = mlx5_flow_item_acceptable
2619 (item, (const uint8_t *)mask,
2620 (const uint8_t *)&gre_key_default_mask,
2621 sizeof(rte_be32_t), MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2626 * Validate GRE item.
2629 * Item specification.
2630 * @param[in] item_flags
2631 * Bit flags to mark detected items.
2632 * @param[in] target_protocol
2633 * The next protocol in the previous item.
2635 * Pointer to error structure.
2638 * 0 on success, a negative errno value otherwise and rte_errno is set.
2641 mlx5_flow_validate_item_gre(const struct rte_flow_item *item,
2642 uint64_t item_flags,
2643 uint8_t target_protocol,
2644 struct rte_flow_error *error)
2646 const struct rte_flow_item_gre *spec __rte_unused = item->spec;
2647 const struct rte_flow_item_gre *mask = item->mask;
2649 const struct rte_flow_item_gre nic_mask = {
2650 .c_rsvd0_ver = RTE_BE16(0xB000),
2651 .protocol = RTE_BE16(UINT16_MAX),
2654 if (target_protocol != 0xff && target_protocol != IPPROTO_GRE)
2655 return rte_flow_error_set(error, EINVAL,
2656 RTE_FLOW_ERROR_TYPE_ITEM, item,
2657 "protocol filtering not compatible"
2658 " with this GRE layer");
2659 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2660 return rte_flow_error_set(error, ENOTSUP,
2661 RTE_FLOW_ERROR_TYPE_ITEM, item,
2662 "multiple tunnel layers not"
2664 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3))
2665 return rte_flow_error_set(error, ENOTSUP,
2666 RTE_FLOW_ERROR_TYPE_ITEM, item,
2667 "L3 Layer is missing");
2669 mask = &rte_flow_item_gre_mask;
2670 ret = mlx5_flow_item_acceptable
2671 (item, (const uint8_t *)mask,
2672 (const uint8_t *)&nic_mask,
2673 sizeof(struct rte_flow_item_gre), MLX5_ITEM_RANGE_NOT_ACCEPTED,
2677 #ifndef HAVE_MLX5DV_DR
2678 #ifndef HAVE_IBV_DEVICE_MPLS_SUPPORT
2679 if (spec && (spec->protocol & mask->protocol))
2680 return rte_flow_error_set(error, ENOTSUP,
2681 RTE_FLOW_ERROR_TYPE_ITEM, item,
2682 "without MPLS support the"
2683 " specification cannot be used for"
2691 * Validate Geneve item.
2694 * Item specification.
2695 * @param[in] itemFlags
2696 * Bit-fields that holds the items detected until now.
2698 * Pointer to the private data structure.
2700 * Pointer to error structure.
2703 * 0 on success, a negative errno value otherwise and rte_errno is set.
2707 mlx5_flow_validate_item_geneve(const struct rte_flow_item *item,
2708 uint64_t item_flags,
2709 struct rte_eth_dev *dev,
2710 struct rte_flow_error *error)
2712 struct mlx5_priv *priv = dev->data->dev_private;
2713 const struct rte_flow_item_geneve *spec = item->spec;
2714 const struct rte_flow_item_geneve *mask = item->mask;
2717 uint8_t opt_len = priv->config.hca_attr.geneve_max_opt_len ?
2718 MLX5_GENEVE_OPT_LEN_1 : MLX5_GENEVE_OPT_LEN_0;
2719 const struct rte_flow_item_geneve nic_mask = {
2720 .ver_opt_len_o_c_rsvd0 = RTE_BE16(0x3f80),
2721 .vni = "\xff\xff\xff",
2722 .protocol = RTE_BE16(UINT16_MAX),
2725 if (!priv->config.hca_attr.tunnel_stateless_geneve_rx)
2726 return rte_flow_error_set(error, ENOTSUP,
2727 RTE_FLOW_ERROR_TYPE_ITEM, item,
2728 "L3 Geneve is not enabled by device"
2729 " parameter and/or not configured in"
2731 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2732 return rte_flow_error_set(error, ENOTSUP,
2733 RTE_FLOW_ERROR_TYPE_ITEM, item,
2734 "multiple tunnel layers not"
2737 * Verify only UDPv4 is present as defined in
2738 * https://tools.ietf.org/html/rfc7348
2740 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2741 return rte_flow_error_set(error, EINVAL,
2742 RTE_FLOW_ERROR_TYPE_ITEM, item,
2743 "no outer UDP layer found");
2745 mask = &rte_flow_item_geneve_mask;
2746 ret = mlx5_flow_item_acceptable
2747 (item, (const uint8_t *)mask,
2748 (const uint8_t *)&nic_mask,
2749 sizeof(struct rte_flow_item_geneve),
2750 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2754 gbhdr = rte_be_to_cpu_16(spec->ver_opt_len_o_c_rsvd0);
2755 if (MLX5_GENEVE_VER_VAL(gbhdr) ||
2756 MLX5_GENEVE_CRITO_VAL(gbhdr) ||
2757 MLX5_GENEVE_RSVD_VAL(gbhdr) || spec->rsvd1)
2758 return rte_flow_error_set(error, ENOTSUP,
2759 RTE_FLOW_ERROR_TYPE_ITEM,
2761 "Geneve protocol unsupported"
2762 " fields are being used");
2763 if (MLX5_GENEVE_OPTLEN_VAL(gbhdr) > opt_len)
2764 return rte_flow_error_set
2766 RTE_FLOW_ERROR_TYPE_ITEM,
2768 "Unsupported Geneve options length");
2770 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
2771 return rte_flow_error_set
2773 RTE_FLOW_ERROR_TYPE_ITEM, item,
2774 "Geneve tunnel must be fully defined");
2779 * Validate Geneve TLV option item.
2782 * Item specification.
2783 * @param[in] last_item
2784 * Previous validated item in the pattern items.
2785 * @param[in] geneve_item
2786 * Previous GENEVE item specification.
2788 * Pointer to the rte_eth_dev structure.
2790 * Pointer to error structure.
2793 * 0 on success, a negative errno value otherwise and rte_errno is set.
2796 mlx5_flow_validate_item_geneve_opt(const struct rte_flow_item *item,
2798 const struct rte_flow_item *geneve_item,
2799 struct rte_eth_dev *dev,
2800 struct rte_flow_error *error)
2802 struct mlx5_priv *priv = dev->data->dev_private;
2803 struct mlx5_dev_ctx_shared *sh = priv->sh;
2804 struct mlx5_geneve_tlv_option_resource *geneve_opt_resource;
2805 struct mlx5_hca_attr *hca_attr = &priv->config.hca_attr;
2806 uint8_t data_max_supported =
2807 hca_attr->max_geneve_tlv_option_data_len * 4;
2808 struct mlx5_dev_config *config = &priv->config;
2809 const struct rte_flow_item_geneve *geneve_spec;
2810 const struct rte_flow_item_geneve *geneve_mask;
2811 const struct rte_flow_item_geneve_opt *spec = item->spec;
2812 const struct rte_flow_item_geneve_opt *mask = item->mask;
2814 unsigned int data_len;
2815 uint8_t tlv_option_len;
2816 uint16_t optlen_m, optlen_v;
2817 const struct rte_flow_item_geneve_opt full_mask = {
2818 .option_class = RTE_BE16(0xffff),
2819 .option_type = 0xff,
2824 mask = &rte_flow_item_geneve_opt_mask;
2826 return rte_flow_error_set
2827 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2828 "Geneve TLV opt class/type/length must be specified");
2829 if ((uint32_t)spec->option_len > MLX5_GENEVE_OPTLEN_MASK)
2830 return rte_flow_error_set
2831 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2832 "Geneve TLV opt length exceeeds the limit (31)");
2833 /* Check if class type and length masks are full. */
2834 if (full_mask.option_class != mask->option_class ||
2835 full_mask.option_type != mask->option_type ||
2836 full_mask.option_len != (mask->option_len & full_mask.option_len))
2837 return rte_flow_error_set
2838 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2839 "Geneve TLV opt class/type/length masks must be full");
2840 /* Check if length is supported */
2841 if ((uint32_t)spec->option_len >
2842 config->hca_attr.max_geneve_tlv_option_data_len)
2843 return rte_flow_error_set
2844 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2845 "Geneve TLV opt length not supported");
2846 if (config->hca_attr.max_geneve_tlv_options > 1)
2848 "max_geneve_tlv_options supports more than 1 option");
2849 /* Check GENEVE item preceding. */
2850 if (!geneve_item || !(last_item & MLX5_FLOW_LAYER_GENEVE))
2851 return rte_flow_error_set
2852 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2853 "Geneve opt item must be preceded with Geneve item");
2854 geneve_spec = geneve_item->spec;
2855 geneve_mask = geneve_item->mask ? geneve_item->mask :
2856 &rte_flow_item_geneve_mask;
2857 /* Check if GENEVE TLV option size doesn't exceed option length */
2858 if (geneve_spec && (geneve_mask->ver_opt_len_o_c_rsvd0 ||
2859 geneve_spec->ver_opt_len_o_c_rsvd0)) {
2860 tlv_option_len = spec->option_len & mask->option_len;
2861 optlen_v = rte_be_to_cpu_16(geneve_spec->ver_opt_len_o_c_rsvd0);
2862 optlen_v = MLX5_GENEVE_OPTLEN_VAL(optlen_v);
2863 optlen_m = rte_be_to_cpu_16(geneve_mask->ver_opt_len_o_c_rsvd0);
2864 optlen_m = MLX5_GENEVE_OPTLEN_VAL(optlen_m);
2865 if ((optlen_v & optlen_m) <= tlv_option_len)
2866 return rte_flow_error_set
2867 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2868 "GENEVE TLV option length exceeds optlen");
2870 /* Check if length is 0 or data is 0. */
2871 if (spec->data == NULL || spec->option_len == 0)
2872 return rte_flow_error_set
2873 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2874 "Geneve TLV opt with zero data/length not supported");
2875 /* Check not all data & mask are 0. */
2876 data_len = spec->option_len * 4;
2877 if (mask->data == NULL) {
2878 for (i = 0; i < data_len; i++)
2882 return rte_flow_error_set(error, ENOTSUP,
2883 RTE_FLOW_ERROR_TYPE_ITEM, item,
2884 "Can't match on Geneve option data 0");
2886 for (i = 0; i < data_len; i++)
2887 if (spec->data[i] & mask->data[i])
2890 return rte_flow_error_set(error, ENOTSUP,
2891 RTE_FLOW_ERROR_TYPE_ITEM, item,
2892 "Can't match on Geneve option data and mask 0");
2893 /* Check data mask supported. */
2894 for (i = data_max_supported; i < data_len ; i++)
2896 return rte_flow_error_set(error, ENOTSUP,
2897 RTE_FLOW_ERROR_TYPE_ITEM, item,
2898 "Data mask is of unsupported size");
2900 /* Check GENEVE option is supported in NIC. */
2901 if (!config->hca_attr.geneve_tlv_opt)
2902 return rte_flow_error_set
2903 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2904 "Geneve TLV opt not supported");
2905 /* Check if we already have geneve option with different type/class. */
2906 rte_spinlock_lock(&sh->geneve_tlv_opt_sl);
2907 geneve_opt_resource = sh->geneve_tlv_option_resource;
2908 if (geneve_opt_resource != NULL)
2909 if (geneve_opt_resource->option_class != spec->option_class ||
2910 geneve_opt_resource->option_type != spec->option_type ||
2911 geneve_opt_resource->length != spec->option_len) {
2912 rte_spinlock_unlock(&sh->geneve_tlv_opt_sl);
2913 return rte_flow_error_set(error, ENOTSUP,
2914 RTE_FLOW_ERROR_TYPE_ITEM, item,
2915 "Only one Geneve TLV option supported");
2917 rte_spinlock_unlock(&sh->geneve_tlv_opt_sl);
2922 * Validate MPLS item.
2925 * Pointer to the rte_eth_dev structure.
2927 * Item specification.
2928 * @param[in] item_flags
2929 * Bit-fields that holds the items detected until now.
2930 * @param[in] prev_layer
2931 * The protocol layer indicated in previous item.
2933 * Pointer to error structure.
2936 * 0 on success, a negative errno value otherwise and rte_errno is set.
2939 mlx5_flow_validate_item_mpls(struct rte_eth_dev *dev __rte_unused,
2940 const struct rte_flow_item *item __rte_unused,
2941 uint64_t item_flags __rte_unused,
2942 uint64_t prev_layer __rte_unused,
2943 struct rte_flow_error *error)
2945 #ifdef HAVE_IBV_DEVICE_MPLS_SUPPORT
2946 const struct rte_flow_item_mpls *mask = item->mask;
2947 struct mlx5_priv *priv = dev->data->dev_private;
2950 if (!priv->config.mpls_en)
2951 return rte_flow_error_set(error, ENOTSUP,
2952 RTE_FLOW_ERROR_TYPE_ITEM, item,
2953 "MPLS not supported or"
2954 " disabled in firmware"
2956 /* MPLS over UDP, GRE is allowed */
2957 if (!(prev_layer & (MLX5_FLOW_LAYER_OUTER_L4_UDP |
2958 MLX5_FLOW_LAYER_GRE |
2959 MLX5_FLOW_LAYER_GRE_KEY)))
2960 return rte_flow_error_set(error, EINVAL,
2961 RTE_FLOW_ERROR_TYPE_ITEM, item,
2962 "protocol filtering not compatible"
2963 " with MPLS layer");
2964 /* Multi-tunnel isn't allowed but MPLS over GRE is an exception. */
2965 if ((item_flags & MLX5_FLOW_LAYER_TUNNEL) &&
2966 !(item_flags & MLX5_FLOW_LAYER_GRE))
2967 return rte_flow_error_set(error, ENOTSUP,
2968 RTE_FLOW_ERROR_TYPE_ITEM, item,
2969 "multiple tunnel layers not"
2972 mask = &rte_flow_item_mpls_mask;
2973 ret = mlx5_flow_item_acceptable
2974 (item, (const uint8_t *)mask,
2975 (const uint8_t *)&rte_flow_item_mpls_mask,
2976 sizeof(struct rte_flow_item_mpls),
2977 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2982 return rte_flow_error_set(error, ENOTSUP,
2983 RTE_FLOW_ERROR_TYPE_ITEM, item,
2984 "MPLS is not supported by Verbs, please"
2990 * Validate NVGRE item.
2993 * Item specification.
2994 * @param[in] item_flags
2995 * Bit flags to mark detected items.
2996 * @param[in] target_protocol
2997 * The next protocol in the previous item.
2999 * Pointer to error structure.
3002 * 0 on success, a negative errno value otherwise and rte_errno is set.
3005 mlx5_flow_validate_item_nvgre(const struct rte_flow_item *item,
3006 uint64_t item_flags,
3007 uint8_t target_protocol,
3008 struct rte_flow_error *error)
3010 const struct rte_flow_item_nvgre *mask = item->mask;
3013 if (target_protocol != 0xff && target_protocol != IPPROTO_GRE)
3014 return rte_flow_error_set(error, EINVAL,
3015 RTE_FLOW_ERROR_TYPE_ITEM, item,
3016 "protocol filtering not compatible"
3017 " with this GRE layer");
3018 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
3019 return rte_flow_error_set(error, ENOTSUP,
3020 RTE_FLOW_ERROR_TYPE_ITEM, item,
3021 "multiple tunnel layers not"
3023 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3))
3024 return rte_flow_error_set(error, ENOTSUP,
3025 RTE_FLOW_ERROR_TYPE_ITEM, item,
3026 "L3 Layer is missing");
3028 mask = &rte_flow_item_nvgre_mask;
3029 ret = mlx5_flow_item_acceptable
3030 (item, (const uint8_t *)mask,
3031 (const uint8_t *)&rte_flow_item_nvgre_mask,
3032 sizeof(struct rte_flow_item_nvgre),
3033 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
3040 * Validate eCPRI item.
3043 * Item specification.
3044 * @param[in] item_flags
3045 * Bit-fields that holds the items detected until now.
3046 * @param[in] last_item
3047 * Previous validated item in the pattern items.
3048 * @param[in] ether_type
3049 * Type in the ethernet layer header (including dot1q).
3050 * @param[in] acc_mask
3051 * Acceptable mask, if NULL default internal default mask
3052 * will be used to check whether item fields are supported.
3054 * Pointer to error structure.
3057 * 0 on success, a negative errno value otherwise and rte_errno is set.
3060 mlx5_flow_validate_item_ecpri(const struct rte_flow_item *item,
3061 uint64_t item_flags,
3063 uint16_t ether_type,
3064 const struct rte_flow_item_ecpri *acc_mask,
3065 struct rte_flow_error *error)
3067 const struct rte_flow_item_ecpri *mask = item->mask;
3068 const struct rte_flow_item_ecpri nic_mask = {
3072 RTE_BE32(((const struct rte_ecpri_common_hdr) {
3076 .dummy[0] = 0xFFFFFFFF,
3079 const uint64_t outer_l2_vlan = (MLX5_FLOW_LAYER_OUTER_L2 |
3080 MLX5_FLOW_LAYER_OUTER_VLAN);
3081 struct rte_flow_item_ecpri mask_lo;
3083 if (!(last_item & outer_l2_vlan) &&
3084 last_item != MLX5_FLOW_LAYER_OUTER_L4_UDP)
3085 return rte_flow_error_set(error, EINVAL,
3086 RTE_FLOW_ERROR_TYPE_ITEM, item,
3087 "eCPRI can only follow L2/VLAN layer or UDP layer");
3088 if ((last_item & outer_l2_vlan) && ether_type &&
3089 ether_type != RTE_ETHER_TYPE_ECPRI)
3090 return rte_flow_error_set(error, EINVAL,
3091 RTE_FLOW_ERROR_TYPE_ITEM, item,
3092 "eCPRI cannot follow L2/VLAN layer which ether type is not 0xAEFE");
3093 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
3094 return rte_flow_error_set(error, EINVAL,
3095 RTE_FLOW_ERROR_TYPE_ITEM, item,
3096 "eCPRI with tunnel is not supported right now");
3097 if (item_flags & MLX5_FLOW_LAYER_OUTER_L3)
3098 return rte_flow_error_set(error, ENOTSUP,
3099 RTE_FLOW_ERROR_TYPE_ITEM, item,
3100 "multiple L3 layers not supported");
3101 else if (item_flags & MLX5_FLOW_LAYER_OUTER_L4_TCP)
3102 return rte_flow_error_set(error, EINVAL,
3103 RTE_FLOW_ERROR_TYPE_ITEM, item,
3104 "eCPRI cannot coexist with a TCP layer");
3105 /* In specification, eCPRI could be over UDP layer. */
3106 else if (item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP)
3107 return rte_flow_error_set(error, EINVAL,
3108 RTE_FLOW_ERROR_TYPE_ITEM, item,
3109 "eCPRI over UDP layer is not yet supported right now");
3110 /* Mask for type field in common header could be zero. */
3112 mask = &rte_flow_item_ecpri_mask;
3113 mask_lo.hdr.common.u32 = rte_be_to_cpu_32(mask->hdr.common.u32);
3114 /* Input mask is in big-endian format. */
3115 if (mask_lo.hdr.common.type != 0 && mask_lo.hdr.common.type != 0xff)
3116 return rte_flow_error_set(error, EINVAL,
3117 RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
3118 "partial mask is not supported for protocol");
3119 else if (mask_lo.hdr.common.type == 0 && mask->hdr.dummy[0] != 0)
3120 return rte_flow_error_set(error, EINVAL,
3121 RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
3122 "message header mask must be after a type mask");
3123 return mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
3124 acc_mask ? (const uint8_t *)acc_mask
3125 : (const uint8_t *)&nic_mask,
3126 sizeof(struct rte_flow_item_ecpri),
3127 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
3131 flow_null_validate(struct rte_eth_dev *dev __rte_unused,
3132 const struct rte_flow_attr *attr __rte_unused,
3133 const struct rte_flow_item items[] __rte_unused,
3134 const struct rte_flow_action actions[] __rte_unused,
3135 bool external __rte_unused,
3136 int hairpin __rte_unused,
3137 struct rte_flow_error *error)
3139 return rte_flow_error_set(error, ENOTSUP,
3140 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
3143 static struct mlx5_flow *
3144 flow_null_prepare(struct rte_eth_dev *dev __rte_unused,
3145 const struct rte_flow_attr *attr __rte_unused,
3146 const struct rte_flow_item items[] __rte_unused,
3147 const struct rte_flow_action actions[] __rte_unused,
3148 struct rte_flow_error *error)
3150 rte_flow_error_set(error, ENOTSUP,
3151 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
3156 flow_null_translate(struct rte_eth_dev *dev __rte_unused,
3157 struct mlx5_flow *dev_flow __rte_unused,
3158 const struct rte_flow_attr *attr __rte_unused,
3159 const struct rte_flow_item items[] __rte_unused,
3160 const struct rte_flow_action actions[] __rte_unused,
3161 struct rte_flow_error *error)
3163 return rte_flow_error_set(error, ENOTSUP,
3164 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
3168 flow_null_apply(struct rte_eth_dev *dev __rte_unused,
3169 struct rte_flow *flow __rte_unused,
3170 struct rte_flow_error *error)
3172 return rte_flow_error_set(error, ENOTSUP,
3173 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
3177 flow_null_remove(struct rte_eth_dev *dev __rte_unused,
3178 struct rte_flow *flow __rte_unused)
3183 flow_null_destroy(struct rte_eth_dev *dev __rte_unused,
3184 struct rte_flow *flow __rte_unused)
3189 flow_null_query(struct rte_eth_dev *dev __rte_unused,
3190 struct rte_flow *flow __rte_unused,
3191 const struct rte_flow_action *actions __rte_unused,
3192 void *data __rte_unused,
3193 struct rte_flow_error *error)
3195 return rte_flow_error_set(error, ENOTSUP,
3196 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
3200 flow_null_sync_domain(struct rte_eth_dev *dev __rte_unused,
3201 uint32_t domains __rte_unused,
3202 uint32_t flags __rte_unused)
3207 /* Void driver to protect from null pointer reference. */
3208 const struct mlx5_flow_driver_ops mlx5_flow_null_drv_ops = {
3209 .validate = flow_null_validate,
3210 .prepare = flow_null_prepare,
3211 .translate = flow_null_translate,
3212 .apply = flow_null_apply,
3213 .remove = flow_null_remove,
3214 .destroy = flow_null_destroy,
3215 .query = flow_null_query,
3216 .sync_domain = flow_null_sync_domain,
3220 * Select flow driver type according to flow attributes and device
3224 * Pointer to the dev structure.
3226 * Pointer to the flow attributes.
3229 * flow driver type, MLX5_FLOW_TYPE_MAX otherwise.
3231 static enum mlx5_flow_drv_type
3232 flow_get_drv_type(struct rte_eth_dev *dev, const struct rte_flow_attr *attr)
3234 struct mlx5_priv *priv = dev->data->dev_private;
3235 /* The OS can determine first a specific flow type (DV, VERBS) */
3236 enum mlx5_flow_drv_type type = mlx5_flow_os_get_type();
3238 if (type != MLX5_FLOW_TYPE_MAX)
3240 /* If no OS specific type - continue with DV/VERBS selection */
3241 if (attr->transfer && priv->config.dv_esw_en)
3242 type = MLX5_FLOW_TYPE_DV;
3243 if (!attr->transfer)
3244 type = priv->config.dv_flow_en ? MLX5_FLOW_TYPE_DV :
3245 MLX5_FLOW_TYPE_VERBS;
3249 #define flow_get_drv_ops(type) flow_drv_ops[type]
3252 * Flow driver validation API. This abstracts calling driver specific functions.
3253 * The type of flow driver is determined according to flow attributes.
3256 * Pointer to the dev structure.
3258 * Pointer to the flow attributes.
3260 * Pointer to the list of items.
3261 * @param[in] actions
3262 * Pointer to the list of actions.
3263 * @param[in] external
3264 * This flow rule is created by request external to PMD.
3265 * @param[in] hairpin
3266 * Number of hairpin TX actions, 0 means classic flow.
3268 * Pointer to the error structure.
3271 * 0 on success, a negative errno value otherwise and rte_errno is set.
3274 flow_drv_validate(struct rte_eth_dev *dev,
3275 const struct rte_flow_attr *attr,
3276 const struct rte_flow_item items[],
3277 const struct rte_flow_action actions[],
3278 bool external, int hairpin, struct rte_flow_error *error)
3280 const struct mlx5_flow_driver_ops *fops;
3281 enum mlx5_flow_drv_type type = flow_get_drv_type(dev, attr);
3283 fops = flow_get_drv_ops(type);
3284 return fops->validate(dev, attr, items, actions, external,
3289 * Flow driver preparation API. This abstracts calling driver specific
3290 * functions. Parent flow (rte_flow) should have driver type (drv_type). It
3291 * calculates the size of memory required for device flow, allocates the memory,
3292 * initializes the device flow and returns the pointer.
3295 * This function initializes device flow structure such as dv or verbs in
3296 * struct mlx5_flow. However, it is caller's responsibility to initialize the
3297 * rest. For example, adding returning device flow to flow->dev_flow list and
3298 * setting backward reference to the flow should be done out of this function.
3299 * layers field is not filled either.
3302 * Pointer to the dev structure.
3304 * Pointer to the flow attributes.
3306 * Pointer to the list of items.
3307 * @param[in] actions
3308 * Pointer to the list of actions.
3309 * @param[in] flow_idx
3310 * This memory pool index to the flow.
3312 * Pointer to the error structure.
3315 * Pointer to device flow on success, otherwise NULL and rte_errno is set.
3317 static inline struct mlx5_flow *
3318 flow_drv_prepare(struct rte_eth_dev *dev,
3319 const struct rte_flow *flow,
3320 const struct rte_flow_attr *attr,
3321 const struct rte_flow_item items[],
3322 const struct rte_flow_action actions[],
3324 struct rte_flow_error *error)
3326 const struct mlx5_flow_driver_ops *fops;
3327 enum mlx5_flow_drv_type type = flow->drv_type;
3328 struct mlx5_flow *mlx5_flow = NULL;
3330 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3331 fops = flow_get_drv_ops(type);
3332 mlx5_flow = fops->prepare(dev, attr, items, actions, error);
3334 mlx5_flow->flow_idx = flow_idx;
3339 * Flow driver translation API. This abstracts calling driver specific
3340 * functions. Parent flow (rte_flow) should have driver type (drv_type). It
3341 * translates a generic flow into a driver flow. flow_drv_prepare() must
3345 * dev_flow->layers could be filled as a result of parsing during translation
3346 * if needed by flow_drv_apply(). dev_flow->flow->actions can also be filled
3347 * if necessary. As a flow can have multiple dev_flows by RSS flow expansion,
3348 * flow->actions could be overwritten even though all the expanded dev_flows
3349 * have the same actions.
3352 * Pointer to the rte dev structure.
3353 * @param[in, out] dev_flow
3354 * Pointer to the mlx5 flow.
3356 * Pointer to the flow attributes.
3358 * Pointer to the list of items.
3359 * @param[in] actions
3360 * Pointer to the list of actions.
3362 * Pointer to the error structure.
3365 * 0 on success, a negative errno value otherwise and rte_errno is set.
3368 flow_drv_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
3369 const struct rte_flow_attr *attr,
3370 const struct rte_flow_item items[],
3371 const struct rte_flow_action actions[],
3372 struct rte_flow_error *error)
3374 const struct mlx5_flow_driver_ops *fops;
3375 enum mlx5_flow_drv_type type = dev_flow->flow->drv_type;
3377 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3378 fops = flow_get_drv_ops(type);
3379 return fops->translate(dev, dev_flow, attr, items, actions, error);
3383 * Flow driver apply API. This abstracts calling driver specific functions.
3384 * Parent flow (rte_flow) should have driver type (drv_type). It applies
3385 * translated driver flows on to device. flow_drv_translate() must precede.
3388 * Pointer to Ethernet device structure.
3389 * @param[in, out] flow
3390 * Pointer to flow structure.
3392 * Pointer to error structure.
3395 * 0 on success, a negative errno value otherwise and rte_errno is set.
3398 flow_drv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
3399 struct rte_flow_error *error)
3401 const struct mlx5_flow_driver_ops *fops;
3402 enum mlx5_flow_drv_type type = flow->drv_type;
3404 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3405 fops = flow_get_drv_ops(type);
3406 return fops->apply(dev, flow, error);
3410 * Flow driver destroy API. This abstracts calling driver specific functions.
3411 * Parent flow (rte_flow) should have driver type (drv_type). It removes a flow
3412 * on device and releases resources of the flow.
3415 * Pointer to Ethernet device.
3416 * @param[in, out] flow
3417 * Pointer to flow structure.
3420 flow_drv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
3422 const struct mlx5_flow_driver_ops *fops;
3423 enum mlx5_flow_drv_type type = flow->drv_type;
3425 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3426 fops = flow_get_drv_ops(type);
3427 fops->destroy(dev, flow);
3431 * Flow driver find RSS policy tbl API. This abstracts calling driver
3432 * specific functions. Parent flow (rte_flow) should have driver
3433 * type (drv_type). It will find the RSS policy table that has the rss_desc.
3436 * Pointer to Ethernet device.
3437 * @param[in, out] flow
3438 * Pointer to flow structure.
3440 * Pointer to meter policy table.
3441 * @param[in] rss_desc
3442 * Pointer to rss_desc
3444 static struct mlx5_flow_meter_sub_policy *
3445 flow_drv_meter_sub_policy_rss_prepare(struct rte_eth_dev *dev,
3446 struct rte_flow *flow,
3447 struct mlx5_flow_meter_policy *policy,
3448 struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS])
3450 const struct mlx5_flow_driver_ops *fops;
3451 enum mlx5_flow_drv_type type = flow->drv_type;
3453 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3454 fops = flow_get_drv_ops(type);
3455 return fops->meter_sub_policy_rss_prepare(dev, policy, rss_desc);
3459 * Flow driver color tag rule API. This abstracts calling driver
3460 * specific functions. Parent flow (rte_flow) should have driver
3461 * type (drv_type). It will create the color tag rules in hierarchy meter.
3464 * Pointer to Ethernet device.
3465 * @param[in, out] flow
3466 * Pointer to flow structure.
3468 * Pointer to flow meter structure.
3469 * @param[in] src_port
3470 * The src port this extra rule should use.
3472 * The src port id match item.
3474 * Pointer to error structure.
3477 flow_drv_mtr_hierarchy_rule_create(struct rte_eth_dev *dev,
3478 struct rte_flow *flow,
3479 struct mlx5_flow_meter_info *fm,
3481 const struct rte_flow_item *item,
3482 struct rte_flow_error *error)
3484 const struct mlx5_flow_driver_ops *fops;
3485 enum mlx5_flow_drv_type type = flow->drv_type;
3487 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3488 fops = flow_get_drv_ops(type);
3489 return fops->meter_hierarchy_rule_create(dev, fm,
3490 src_port, item, error);
3494 * Get RSS action from the action list.
3497 * Pointer to Ethernet device.
3498 * @param[in] actions
3499 * Pointer to the list of actions.
3501 * Parent flow structure pointer.
3504 * Pointer to the RSS action if exist, else return NULL.
3506 static const struct rte_flow_action_rss*
3507 flow_get_rss_action(struct rte_eth_dev *dev,
3508 const struct rte_flow_action actions[])
3510 struct mlx5_priv *priv = dev->data->dev_private;
3511 const struct rte_flow_action_rss *rss = NULL;
3513 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3514 switch (actions->type) {
3515 case RTE_FLOW_ACTION_TYPE_RSS:
3516 rss = actions->conf;
3518 case RTE_FLOW_ACTION_TYPE_SAMPLE:
3520 const struct rte_flow_action_sample *sample =
3522 const struct rte_flow_action *act = sample->actions;
3523 for (; act->type != RTE_FLOW_ACTION_TYPE_END; act++)
3524 if (act->type == RTE_FLOW_ACTION_TYPE_RSS)
3528 case RTE_FLOW_ACTION_TYPE_METER:
3531 struct mlx5_flow_meter_info *fm;
3532 struct mlx5_flow_meter_policy *policy;
3533 const struct rte_flow_action_meter *mtr = actions->conf;
3535 fm = mlx5_flow_meter_find(priv, mtr->mtr_id, &mtr_idx);
3536 if (fm && !fm->def_policy) {
3537 policy = mlx5_flow_meter_policy_find(dev,
3538 fm->policy_id, NULL);
3539 MLX5_ASSERT(policy);
3540 if (policy->is_hierarchy) {
3542 mlx5_flow_meter_hierarchy_get_final_policy(dev,
3549 policy->act_cnt[RTE_COLOR_GREEN].rss->conf;
3561 * Get ASO age action by index.
3564 * Pointer to the Ethernet device structure.
3565 * @param[in] age_idx
3566 * Index to the ASO age action.
3569 * The specified ASO age action.
3571 struct mlx5_aso_age_action*
3572 flow_aso_age_get_by_idx(struct rte_eth_dev *dev, uint32_t age_idx)
3574 uint16_t pool_idx = age_idx & UINT16_MAX;
3575 uint16_t offset = (age_idx >> 16) & UINT16_MAX;
3576 struct mlx5_priv *priv = dev->data->dev_private;
3577 struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
3578 struct mlx5_aso_age_pool *pool = mng->pools[pool_idx];
3580 return &pool->actions[offset - 1];
3583 /* maps indirect action to translated direct in some actions array */
3584 struct mlx5_translated_action_handle {
3585 struct rte_flow_action_handle *action; /**< Indirect action handle. */
3586 int index; /**< Index in related array of rte_flow_action. */
3590 * Translates actions of type RTE_FLOW_ACTION_TYPE_INDIRECT to related
3591 * direct action if translation possible.
3592 * This functionality used to run same execution path for both direct and
3593 * indirect actions on flow create. All necessary preparations for indirect
3594 * action handling should be performed on *handle* actions list returned
3598 * Pointer to Ethernet device.
3599 * @param[in] actions
3600 * List of actions to translate.
3601 * @param[out] handle
3602 * List to store translated indirect action object handles.
3603 * @param[in, out] indir_n
3604 * Size of *handle* array. On return should be updated with number of
3605 * indirect actions retrieved from the *actions* list.
3606 * @param[out] translated_actions
3607 * List of actions where all indirect actions were translated to direct
3608 * if possible. NULL if no translation took place.
3610 * Pointer to the error structure.
3613 * 0 on success, a negative errno value otherwise and rte_errno is set.
3616 flow_action_handles_translate(struct rte_eth_dev *dev,
3617 const struct rte_flow_action actions[],
3618 struct mlx5_translated_action_handle *handle,
3620 struct rte_flow_action **translated_actions,
3621 struct rte_flow_error *error)
3623 struct mlx5_priv *priv = dev->data->dev_private;
3624 struct rte_flow_action *translated = NULL;
3625 size_t actions_size;
3628 struct mlx5_translated_action_handle *handle_end = NULL;
3630 for (n = 0; actions[n].type != RTE_FLOW_ACTION_TYPE_END; n++) {
3631 if (actions[n].type != RTE_FLOW_ACTION_TYPE_INDIRECT)
3633 if (copied_n == *indir_n) {
3634 return rte_flow_error_set
3635 (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION_NUM,
3636 NULL, "too many shared actions");
3638 rte_memcpy(&handle[copied_n].action, &actions[n].conf,
3639 sizeof(actions[n].conf));
3640 handle[copied_n].index = n;
3644 *indir_n = copied_n;
3647 actions_size = sizeof(struct rte_flow_action) * n;
3648 translated = mlx5_malloc(MLX5_MEM_ZERO, actions_size, 0, SOCKET_ID_ANY);
3653 memcpy(translated, actions, actions_size);
3654 for (handle_end = handle + copied_n; handle < handle_end; handle++) {
3655 struct mlx5_shared_action_rss *shared_rss;
3656 uint32_t act_idx = (uint32_t)(uintptr_t)handle->action;
3657 uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
3658 uint32_t idx = act_idx &
3659 ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
3662 case MLX5_INDIRECT_ACTION_TYPE_RSS:
3663 shared_rss = mlx5_ipool_get
3664 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
3665 translated[handle->index].type =
3666 RTE_FLOW_ACTION_TYPE_RSS;
3667 translated[handle->index].conf =
3668 &shared_rss->origin;
3670 case MLX5_INDIRECT_ACTION_TYPE_COUNT:
3671 translated[handle->index].type =
3672 (enum rte_flow_action_type)
3673 MLX5_RTE_FLOW_ACTION_TYPE_COUNT;
3674 translated[handle->index].conf = (void *)(uintptr_t)idx;
3676 case MLX5_INDIRECT_ACTION_TYPE_AGE:
3677 if (priv->sh->flow_hit_aso_en) {
3678 translated[handle->index].type =
3679 (enum rte_flow_action_type)
3680 MLX5_RTE_FLOW_ACTION_TYPE_AGE;
3681 translated[handle->index].conf =
3682 (void *)(uintptr_t)idx;
3686 case MLX5_INDIRECT_ACTION_TYPE_CT:
3687 if (priv->sh->ct_aso_en) {
3688 translated[handle->index].type =
3689 RTE_FLOW_ACTION_TYPE_CONNTRACK;
3690 translated[handle->index].conf =
3691 (void *)(uintptr_t)idx;
3696 mlx5_free(translated);
3697 return rte_flow_error_set
3698 (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
3699 NULL, "invalid indirect action type");
3702 *translated_actions = translated;
3707 * Get Shared RSS action from the action list.
3710 * Pointer to Ethernet device.
3712 * Pointer to the list of actions.
3713 * @param[in] shared_n
3714 * Actions list length.
3717 * The MLX5 RSS action ID if exists, otherwise return 0.
3720 flow_get_shared_rss_action(struct rte_eth_dev *dev,
3721 struct mlx5_translated_action_handle *handle,
3724 struct mlx5_translated_action_handle *handle_end;
3725 struct mlx5_priv *priv = dev->data->dev_private;
3726 struct mlx5_shared_action_rss *shared_rss;
3729 for (handle_end = handle + shared_n; handle < handle_end; handle++) {
3730 uint32_t act_idx = (uint32_t)(uintptr_t)handle->action;
3731 uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
3732 uint32_t idx = act_idx &
3733 ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
3735 case MLX5_INDIRECT_ACTION_TYPE_RSS:
3736 shared_rss = mlx5_ipool_get
3737 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
3739 __atomic_add_fetch(&shared_rss->refcnt, 1,
3750 find_graph_root(const struct rte_flow_item pattern[], uint32_t rss_level)
3752 const struct rte_flow_item *item;
3753 unsigned int has_vlan = 0;
3755 for (item = pattern; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
3756 if (item->type == RTE_FLOW_ITEM_TYPE_VLAN) {
3762 return rss_level < 2 ? MLX5_EXPANSION_ROOT_ETH_VLAN :
3763 MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN;
3764 return rss_level < 2 ? MLX5_EXPANSION_ROOT :
3765 MLX5_EXPANSION_ROOT_OUTER;
3769 * Get layer flags from the prefix flow.
3771 * Some flows may be split to several subflows, the prefix subflow gets the
3772 * match items and the suffix sub flow gets the actions.
3773 * Some actions need the user defined match item flags to get the detail for
3775 * This function helps the suffix flow to get the item layer flags from prefix
3778 * @param[in] dev_flow
3779 * Pointer the created preifx subflow.
3782 * The layers get from prefix subflow.
3784 static inline uint64_t
3785 flow_get_prefix_layer_flags(struct mlx5_flow *dev_flow)
3787 uint64_t layers = 0;
3790 * Layers bits could be localization, but usually the compiler will
3791 * help to do the optimization work for source code.
3792 * If no decap actions, use the layers directly.
3794 if (!(dev_flow->act_flags & MLX5_FLOW_ACTION_DECAP))
3795 return dev_flow->handle->layers;
3796 /* Convert L3 layers with decap action. */
3797 if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L3_IPV4)
3798 layers |= MLX5_FLOW_LAYER_OUTER_L3_IPV4;
3799 else if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L3_IPV6)
3800 layers |= MLX5_FLOW_LAYER_OUTER_L3_IPV6;
3801 /* Convert L4 layers with decap action. */
3802 if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L4_TCP)
3803 layers |= MLX5_FLOW_LAYER_OUTER_L4_TCP;
3804 else if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L4_UDP)
3805 layers |= MLX5_FLOW_LAYER_OUTER_L4_UDP;
3810 * Get metadata split action information.
3812 * @param[in] actions
3813 * Pointer to the list of actions.
3815 * Pointer to the return pointer.
3816 * @param[out] qrss_type
3817 * Pointer to the action type to return. RTE_FLOW_ACTION_TYPE_END is returned
3818 * if no QUEUE/RSS is found.
3819 * @param[out] encap_idx
3820 * Pointer to the index of the encap action if exists, otherwise the last
3824 * Total number of actions.
3827 flow_parse_metadata_split_actions_info(const struct rte_flow_action actions[],
3828 const struct rte_flow_action **qrss,
3831 const struct rte_flow_action_raw_encap *raw_encap;
3833 int raw_decap_idx = -1;
3836 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3837 switch (actions->type) {
3838 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
3839 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
3840 *encap_idx = actions_n;
3842 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
3843 raw_decap_idx = actions_n;
3845 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
3846 raw_encap = actions->conf;
3847 if (raw_encap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
3848 *encap_idx = raw_decap_idx != -1 ?
3849 raw_decap_idx : actions_n;
3851 case RTE_FLOW_ACTION_TYPE_QUEUE:
3852 case RTE_FLOW_ACTION_TYPE_RSS:
3860 if (*encap_idx == -1)
3861 *encap_idx = actions_n;
3862 /* Count RTE_FLOW_ACTION_TYPE_END. */
3863 return actions_n + 1;
3867 * Check if the action will change packet.
3870 * Pointer to Ethernet device.
3875 * true if action will change packet, false otherwise.
3877 static bool flow_check_modify_action_type(struct rte_eth_dev *dev,
3878 enum rte_flow_action_type type)
3880 struct mlx5_priv *priv = dev->data->dev_private;
3883 case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
3884 case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
3885 case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
3886 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
3887 case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
3888 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
3889 case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
3890 case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
3891 case RTE_FLOW_ACTION_TYPE_DEC_TTL:
3892 case RTE_FLOW_ACTION_TYPE_SET_TTL:
3893 case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
3894 case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
3895 case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
3896 case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
3897 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
3898 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
3899 case RTE_FLOW_ACTION_TYPE_SET_META:
3900 case RTE_FLOW_ACTION_TYPE_SET_TAG:
3901 case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
3902 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
3903 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
3904 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
3905 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
3906 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
3907 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
3908 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
3909 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
3910 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
3911 case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
3913 case RTE_FLOW_ACTION_TYPE_FLAG:
3914 case RTE_FLOW_ACTION_TYPE_MARK:
3915 if (priv->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY)
3925 * Check meter action from the action list.
3928 * Pointer to Ethernet device.
3929 * @param[in] actions
3930 * Pointer to the list of actions.
3931 * @param[out] has_mtr
3932 * Pointer to the meter exist flag.
3933 * @param[out] has_modify
3934 * Pointer to the flag showing there's packet change action.
3935 * @param[out] meter_id
3936 * Pointer to the meter id.
3939 * Total number of actions.
3942 flow_check_meter_action(struct rte_eth_dev *dev,
3943 const struct rte_flow_action actions[],
3944 bool *has_mtr, bool *has_modify, uint32_t *meter_id)
3946 const struct rte_flow_action_meter *mtr = NULL;
3949 MLX5_ASSERT(has_mtr);
3951 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3952 switch (actions->type) {
3953 case RTE_FLOW_ACTION_TYPE_METER:
3954 mtr = actions->conf;
3955 *meter_id = mtr->mtr_id;
3962 *has_modify |= flow_check_modify_action_type(dev,
3966 /* Count RTE_FLOW_ACTION_TYPE_END. */
3967 return actions_n + 1;
3971 * Check if the flow should be split due to hairpin.
3972 * The reason for the split is that in current HW we can't
3973 * support encap and push-vlan on Rx, so if a flow contains
3974 * these actions we move it to Tx.
3977 * Pointer to Ethernet device.
3979 * Flow rule attributes.
3980 * @param[in] actions
3981 * Associated actions (list terminated by the END action).
3984 * > 0 the number of actions and the flow should be split,
3985 * 0 when no split required.
3988 flow_check_hairpin_split(struct rte_eth_dev *dev,
3989 const struct rte_flow_attr *attr,
3990 const struct rte_flow_action actions[])
3992 int queue_action = 0;
3995 const struct rte_flow_action_queue *queue;
3996 const struct rte_flow_action_rss *rss;
3997 const struct rte_flow_action_raw_encap *raw_encap;
3998 const struct rte_eth_hairpin_conf *conf;
4002 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4003 switch (actions->type) {
4004 case RTE_FLOW_ACTION_TYPE_QUEUE:
4005 queue = actions->conf;
4008 conf = mlx5_rxq_get_hairpin_conf(dev, queue->index);
4009 if (conf == NULL || conf->tx_explicit != 0)
4014 case RTE_FLOW_ACTION_TYPE_RSS:
4015 rss = actions->conf;
4016 if (rss == NULL || rss->queue_num == 0)
4018 conf = mlx5_rxq_get_hairpin_conf(dev, rss->queue[0]);
4019 if (conf == NULL || conf->tx_explicit != 0)
4024 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
4025 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
4026 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
4027 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
4028 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
4032 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
4033 raw_encap = actions->conf;
4034 if (raw_encap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
4043 if (split && queue_action)
4048 /* Declare flow create/destroy prototype in advance. */
4050 flow_list_create(struct rte_eth_dev *dev, enum mlx5_flow_type type,
4051 const struct rte_flow_attr *attr,
4052 const struct rte_flow_item items[],
4053 const struct rte_flow_action actions[],
4054 bool external, struct rte_flow_error *error);
4057 flow_list_destroy(struct rte_eth_dev *dev, enum mlx5_flow_type type,
4061 flow_dv_mreg_match_cb(void *tool_ctx __rte_unused,
4062 struct mlx5_list_entry *entry, void *cb_ctx)
4064 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4065 struct mlx5_flow_mreg_copy_resource *mcp_res =
4066 container_of(entry, typeof(*mcp_res), hlist_ent);
4068 return mcp_res->mark_id != *(uint32_t *)(ctx->data);
4071 struct mlx5_list_entry *
4072 flow_dv_mreg_create_cb(void *tool_ctx, void *cb_ctx)
4074 struct rte_eth_dev *dev = tool_ctx;
4075 struct mlx5_priv *priv = dev->data->dev_private;
4076 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4077 struct mlx5_flow_mreg_copy_resource *mcp_res;
4078 struct rte_flow_error *error = ctx->error;
4081 uint32_t mark_id = *(uint32_t *)(ctx->data);
4082 struct rte_flow_attr attr = {
4083 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
4086 struct mlx5_rte_flow_item_tag tag_spec = {
4089 struct rte_flow_item items[] = {
4090 [1] = { .type = RTE_FLOW_ITEM_TYPE_END, },
4092 struct rte_flow_action_mark ftag = {
4095 struct mlx5_flow_action_copy_mreg cp_mreg = {
4099 struct rte_flow_action_jump jump = {
4100 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
4102 struct rte_flow_action actions[] = {
4103 [3] = { .type = RTE_FLOW_ACTION_TYPE_END, },
4106 /* Fill the register fileds in the flow. */
4107 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
4111 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_RX, 0, error);
4115 /* Provide the full width of FLAG specific value. */
4116 if (mark_id == (priv->sh->dv_regc0_mask & MLX5_FLOW_MARK_DEFAULT))
4117 tag_spec.data = MLX5_FLOW_MARK_DEFAULT;
4118 /* Build a new flow. */
4119 if (mark_id != MLX5_DEFAULT_COPY_ID) {
4120 items[0] = (struct rte_flow_item){
4121 .type = (enum rte_flow_item_type)
4122 MLX5_RTE_FLOW_ITEM_TYPE_TAG,
4125 items[1] = (struct rte_flow_item){
4126 .type = RTE_FLOW_ITEM_TYPE_END,
4128 actions[0] = (struct rte_flow_action){
4129 .type = (enum rte_flow_action_type)
4130 MLX5_RTE_FLOW_ACTION_TYPE_MARK,
4133 actions[1] = (struct rte_flow_action){
4134 .type = (enum rte_flow_action_type)
4135 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
4138 actions[2] = (struct rte_flow_action){
4139 .type = RTE_FLOW_ACTION_TYPE_JUMP,
4142 actions[3] = (struct rte_flow_action){
4143 .type = RTE_FLOW_ACTION_TYPE_END,
4146 /* Default rule, wildcard match. */
4147 attr.priority = MLX5_FLOW_LOWEST_PRIO_INDICATOR;
4148 items[0] = (struct rte_flow_item){
4149 .type = RTE_FLOW_ITEM_TYPE_END,
4151 actions[0] = (struct rte_flow_action){
4152 .type = (enum rte_flow_action_type)
4153 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
4156 actions[1] = (struct rte_flow_action){
4157 .type = RTE_FLOW_ACTION_TYPE_JUMP,
4160 actions[2] = (struct rte_flow_action){
4161 .type = RTE_FLOW_ACTION_TYPE_END,
4164 /* Build a new entry. */
4165 mcp_res = mlx5_ipool_zmalloc(priv->sh->ipool[MLX5_IPOOL_MCP], &idx);
4171 mcp_res->mark_id = mark_id;
4173 * The copy Flows are not included in any list. There
4174 * ones are referenced from other Flows and can not
4175 * be applied, removed, deleted in ardbitrary order
4176 * by list traversing.
4178 mcp_res->rix_flow = flow_list_create(dev, MLX5_FLOW_TYPE_MCP,
4179 &attr, items, actions, false, error);
4180 if (!mcp_res->rix_flow) {
4181 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], idx);
4184 return &mcp_res->hlist_ent;
4187 struct mlx5_list_entry *
4188 flow_dv_mreg_clone_cb(void *tool_ctx, struct mlx5_list_entry *oentry,
4189 void *cb_ctx __rte_unused)
4191 struct rte_eth_dev *dev = tool_ctx;
4192 struct mlx5_priv *priv = dev->data->dev_private;
4193 struct mlx5_flow_mreg_copy_resource *mcp_res;
4196 mcp_res = mlx5_ipool_malloc(priv->sh->ipool[MLX5_IPOOL_MCP], &idx);
4201 memcpy(mcp_res, oentry, sizeof(*mcp_res));
4203 return &mcp_res->hlist_ent;
4207 flow_dv_mreg_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
4209 struct mlx5_flow_mreg_copy_resource *mcp_res =
4210 container_of(entry, typeof(*mcp_res), hlist_ent);
4211 struct rte_eth_dev *dev = tool_ctx;
4212 struct mlx5_priv *priv = dev->data->dev_private;
4214 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], mcp_res->idx);
4218 * Add a flow of copying flow metadata registers in RX_CP_TBL.
4220 * As mark_id is unique, if there's already a registered flow for the mark_id,
4221 * return by increasing the reference counter of the resource. Otherwise, create
4222 * the resource (mcp_res) and flow.
4225 * - If ingress port is ANY and reg_c[1] is mark_id,
4226 * flow_tag := mark_id, reg_b := reg_c[0] and jump to RX_ACT_TBL.
4228 * For default flow (zero mark_id), flow is like,
4229 * - If ingress port is ANY,
4230 * reg_b := reg_c[0] and jump to RX_ACT_TBL.
4233 * Pointer to Ethernet device.
4235 * ID of MARK action, zero means default flow for META.
4237 * Perform verbose error reporting if not NULL.
4240 * Associated resource on success, NULL otherwise and rte_errno is set.
4242 static struct mlx5_flow_mreg_copy_resource *
4243 flow_mreg_add_copy_action(struct rte_eth_dev *dev, uint32_t mark_id,
4244 struct rte_flow_error *error)
4246 struct mlx5_priv *priv = dev->data->dev_private;
4247 struct mlx5_list_entry *entry;
4248 struct mlx5_flow_cb_ctx ctx = {
4254 /* Check if already registered. */
4255 MLX5_ASSERT(priv->mreg_cp_tbl);
4256 entry = mlx5_hlist_register(priv->mreg_cp_tbl, mark_id, &ctx);
4259 return container_of(entry, struct mlx5_flow_mreg_copy_resource,
4264 flow_dv_mreg_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
4266 struct mlx5_flow_mreg_copy_resource *mcp_res =
4267 container_of(entry, typeof(*mcp_res), hlist_ent);
4268 struct rte_eth_dev *dev = tool_ctx;
4269 struct mlx5_priv *priv = dev->data->dev_private;
4271 MLX5_ASSERT(mcp_res->rix_flow);
4272 flow_list_destroy(dev, MLX5_FLOW_TYPE_MCP, mcp_res->rix_flow);
4273 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], mcp_res->idx);
4277 * Release flow in RX_CP_TBL.
4280 * Pointer to Ethernet device.
4282 * Parent flow for wich copying is provided.
4285 flow_mreg_del_copy_action(struct rte_eth_dev *dev,
4286 struct rte_flow *flow)
4288 struct mlx5_flow_mreg_copy_resource *mcp_res;
4289 struct mlx5_priv *priv = dev->data->dev_private;
4291 if (!flow->rix_mreg_copy)
4293 mcp_res = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MCP],
4294 flow->rix_mreg_copy);
4295 if (!mcp_res || !priv->mreg_cp_tbl)
4297 MLX5_ASSERT(mcp_res->rix_flow);
4298 mlx5_hlist_unregister(priv->mreg_cp_tbl, &mcp_res->hlist_ent);
4299 flow->rix_mreg_copy = 0;
4303 * Remove the default copy action from RX_CP_TBL.
4305 * This functions is called in the mlx5_dev_start(). No thread safe
4309 * Pointer to Ethernet device.
4312 flow_mreg_del_default_copy_action(struct rte_eth_dev *dev)
4314 struct mlx5_list_entry *entry;
4315 struct mlx5_priv *priv = dev->data->dev_private;
4316 struct mlx5_flow_cb_ctx ctx;
4319 /* Check if default flow is registered. */
4320 if (!priv->mreg_cp_tbl)
4322 mark_id = MLX5_DEFAULT_COPY_ID;
4323 ctx.data = &mark_id;
4324 entry = mlx5_hlist_lookup(priv->mreg_cp_tbl, mark_id, &ctx);
4327 mlx5_hlist_unregister(priv->mreg_cp_tbl, entry);
4331 * Add the default copy action in in RX_CP_TBL.
4333 * This functions is called in the mlx5_dev_start(). No thread safe
4337 * Pointer to Ethernet device.
4339 * Perform verbose error reporting if not NULL.
4342 * 0 for success, negative value otherwise and rte_errno is set.
4345 flow_mreg_add_default_copy_action(struct rte_eth_dev *dev,
4346 struct rte_flow_error *error)
4348 struct mlx5_priv *priv = dev->data->dev_private;
4349 struct mlx5_flow_mreg_copy_resource *mcp_res;
4350 struct mlx5_flow_cb_ctx ctx;
4353 /* Check whether extensive metadata feature is engaged. */
4354 if (!priv->config.dv_flow_en ||
4355 priv->config.dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
4356 !mlx5_flow_ext_mreg_supported(dev) ||
4357 !priv->sh->dv_regc0_mask)
4360 * Add default mreg copy flow may be called multiple time, but
4361 * only be called once in stop. Avoid register it twice.
4363 mark_id = MLX5_DEFAULT_COPY_ID;
4364 ctx.data = &mark_id;
4365 if (mlx5_hlist_lookup(priv->mreg_cp_tbl, mark_id, &ctx))
4367 mcp_res = flow_mreg_add_copy_action(dev, mark_id, error);
4374 * Add a flow of copying flow metadata registers in RX_CP_TBL.
4376 * All the flow having Q/RSS action should be split by
4377 * flow_mreg_split_qrss_prep() to pass by RX_CP_TBL. A flow in the RX_CP_TBL
4378 * performs the following,
4379 * - CQE->flow_tag := reg_c[1] (MARK)
4380 * - CQE->flow_table_metadata (reg_b) := reg_c[0] (META)
4381 * As CQE's flow_tag is not a register, it can't be simply copied from reg_c[1]
4382 * but there should be a flow per each MARK ID set by MARK action.
4384 * For the aforementioned reason, if there's a MARK action in flow's action
4385 * list, a corresponding flow should be added to the RX_CP_TBL in order to copy
4386 * the MARK ID to CQE's flow_tag like,
4387 * - If reg_c[1] is mark_id,
4388 * flow_tag := mark_id, reg_b := reg_c[0] and jump to RX_ACT_TBL.
4390 * For SET_META action which stores value in reg_c[0], as the destination is
4391 * also a flow metadata register (reg_b), adding a default flow is enough. Zero
4392 * MARK ID means the default flow. The default flow looks like,
4393 * - For all flow, reg_b := reg_c[0] and jump to RX_ACT_TBL.
4396 * Pointer to Ethernet device.
4398 * Pointer to flow structure.
4399 * @param[in] actions
4400 * Pointer to the list of actions.
4402 * Perform verbose error reporting if not NULL.
4405 * 0 on success, negative value otherwise and rte_errno is set.
4408 flow_mreg_update_copy_table(struct rte_eth_dev *dev,
4409 struct rte_flow *flow,
4410 const struct rte_flow_action *actions,
4411 struct rte_flow_error *error)
4413 struct mlx5_priv *priv = dev->data->dev_private;
4414 struct mlx5_dev_config *config = &priv->config;
4415 struct mlx5_flow_mreg_copy_resource *mcp_res;
4416 const struct rte_flow_action_mark *mark;
4418 /* Check whether extensive metadata feature is engaged. */
4419 if (!config->dv_flow_en ||
4420 config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
4421 !mlx5_flow_ext_mreg_supported(dev) ||
4422 !priv->sh->dv_regc0_mask)
4424 /* Find MARK action. */
4425 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4426 switch (actions->type) {
4427 case RTE_FLOW_ACTION_TYPE_FLAG:
4428 mcp_res = flow_mreg_add_copy_action
4429 (dev, MLX5_FLOW_MARK_DEFAULT, error);
4432 flow->rix_mreg_copy = mcp_res->idx;
4434 case RTE_FLOW_ACTION_TYPE_MARK:
4435 mark = (const struct rte_flow_action_mark *)
4438 flow_mreg_add_copy_action(dev, mark->id, error);
4441 flow->rix_mreg_copy = mcp_res->idx;
4450 #define MLX5_MAX_SPLIT_ACTIONS 24
4451 #define MLX5_MAX_SPLIT_ITEMS 24
4454 * Split the hairpin flow.
4455 * Since HW can't support encap and push-vlan on Rx, we move these
4457 * If the count action is after the encap then we also
4458 * move the count action. in this case the count will also measure
4462 * Pointer to Ethernet device.
4463 * @param[in] actions
4464 * Associated actions (list terminated by the END action).
4465 * @param[out] actions_rx
4467 * @param[out] actions_tx
4469 * @param[out] pattern_tx
4470 * The pattern items for the Tx flow.
4471 * @param[out] flow_id
4472 * The flow ID connected to this flow.
4478 flow_hairpin_split(struct rte_eth_dev *dev,
4479 const struct rte_flow_action actions[],
4480 struct rte_flow_action actions_rx[],
4481 struct rte_flow_action actions_tx[],
4482 struct rte_flow_item pattern_tx[],
4485 const struct rte_flow_action_raw_encap *raw_encap;
4486 const struct rte_flow_action_raw_decap *raw_decap;
4487 struct mlx5_rte_flow_action_set_tag *set_tag;
4488 struct rte_flow_action *tag_action;
4489 struct mlx5_rte_flow_item_tag *tag_item;
4490 struct rte_flow_item *item;
4494 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4495 switch (actions->type) {
4496 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
4497 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
4498 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
4499 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
4500 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
4501 rte_memcpy(actions_tx, actions,
4502 sizeof(struct rte_flow_action));
4505 case RTE_FLOW_ACTION_TYPE_COUNT:
4507 rte_memcpy(actions_tx, actions,
4508 sizeof(struct rte_flow_action));
4511 rte_memcpy(actions_rx, actions,
4512 sizeof(struct rte_flow_action));
4516 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
4517 raw_encap = actions->conf;
4518 if (raw_encap->size > MLX5_ENCAPSULATION_DECISION_SIZE) {
4519 memcpy(actions_tx, actions,
4520 sizeof(struct rte_flow_action));
4524 rte_memcpy(actions_rx, actions,
4525 sizeof(struct rte_flow_action));
4529 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
4530 raw_decap = actions->conf;
4531 if (raw_decap->size < MLX5_ENCAPSULATION_DECISION_SIZE) {
4532 memcpy(actions_tx, actions,
4533 sizeof(struct rte_flow_action));
4536 rte_memcpy(actions_rx, actions,
4537 sizeof(struct rte_flow_action));
4542 rte_memcpy(actions_rx, actions,
4543 sizeof(struct rte_flow_action));
4548 /* Add set meta action and end action for the Rx flow. */
4549 tag_action = actions_rx;
4550 tag_action->type = (enum rte_flow_action_type)
4551 MLX5_RTE_FLOW_ACTION_TYPE_TAG;
4553 rte_memcpy(actions_rx, actions, sizeof(struct rte_flow_action));
4555 set_tag = (void *)actions_rx;
4556 *set_tag = (struct mlx5_rte_flow_action_set_tag) {
4557 .id = mlx5_flow_get_reg_id(dev, MLX5_HAIRPIN_RX, 0, NULL),
4560 MLX5_ASSERT(set_tag->id > REG_NON);
4561 tag_action->conf = set_tag;
4562 /* Create Tx item list. */
4563 rte_memcpy(actions_tx, actions, sizeof(struct rte_flow_action));
4564 addr = (void *)&pattern_tx[2];
4566 item->type = (enum rte_flow_item_type)
4567 MLX5_RTE_FLOW_ITEM_TYPE_TAG;
4568 tag_item = (void *)addr;
4569 tag_item->data = flow_id;
4570 tag_item->id = mlx5_flow_get_reg_id(dev, MLX5_HAIRPIN_TX, 0, NULL);
4571 MLX5_ASSERT(set_tag->id > REG_NON);
4572 item->spec = tag_item;
4573 addr += sizeof(struct mlx5_rte_flow_item_tag);
4574 tag_item = (void *)addr;
4575 tag_item->data = UINT32_MAX;
4576 tag_item->id = UINT16_MAX;
4577 item->mask = tag_item;
4580 item->type = RTE_FLOW_ITEM_TYPE_END;
4585 * The last stage of splitting chain, just creates the subflow
4586 * without any modification.
4589 * Pointer to Ethernet device.
4591 * Parent flow structure pointer.
4592 * @param[in, out] sub_flow
4593 * Pointer to return the created subflow, may be NULL.
4595 * Flow rule attributes.
4597 * Pattern specification (list terminated by the END pattern item).
4598 * @param[in] actions
4599 * Associated actions (list terminated by the END action).
4600 * @param[in] flow_split_info
4601 * Pointer to flow split info structure.
4603 * Perform verbose error reporting if not NULL.
4605 * 0 on success, negative value otherwise
4608 flow_create_split_inner(struct rte_eth_dev *dev,
4609 struct rte_flow *flow,
4610 struct mlx5_flow **sub_flow,
4611 const struct rte_flow_attr *attr,
4612 const struct rte_flow_item items[],
4613 const struct rte_flow_action actions[],
4614 struct mlx5_flow_split_info *flow_split_info,
4615 struct rte_flow_error *error)
4617 struct mlx5_flow *dev_flow;
4619 dev_flow = flow_drv_prepare(dev, flow, attr, items, actions,
4620 flow_split_info->flow_idx, error);
4623 dev_flow->flow = flow;
4624 dev_flow->external = flow_split_info->external;
4625 dev_flow->skip_scale = flow_split_info->skip_scale;
4626 /* Subflow object was created, we must include one in the list. */
4627 SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
4628 dev_flow->handle, next);
4630 * If dev_flow is as one of the suffix flow, some actions in suffix
4631 * flow may need some user defined item layer flags, and pass the
4632 * Metadate rxq mark flag to suffix flow as well.
4634 if (flow_split_info->prefix_layers)
4635 dev_flow->handle->layers = flow_split_info->prefix_layers;
4636 if (flow_split_info->prefix_mark)
4637 dev_flow->handle->mark = 1;
4639 *sub_flow = dev_flow;
4640 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
4641 dev_flow->dv.table_id = flow_split_info->table_id;
4643 return flow_drv_translate(dev, dev_flow, attr, items, actions, error);
4647 * Get the sub policy of a meter.
4650 * Pointer to Ethernet device.
4652 * Parent flow structure pointer.
4654 * Pointer to thread flow work space.
4656 * Flow rule attributes.
4658 * Pattern specification (list terminated by the END pattern item).
4660 * Perform verbose error reporting if not NULL.
4663 * Pointer to the meter sub policy, NULL otherwise and rte_errno is set.
4665 static struct mlx5_flow_meter_sub_policy *
4666 get_meter_sub_policy(struct rte_eth_dev *dev,
4667 struct rte_flow *flow,
4668 struct mlx5_flow_workspace *wks,
4669 const struct rte_flow_attr *attr,
4670 const struct rte_flow_item items[],
4671 struct rte_flow_error *error)
4673 struct mlx5_flow_meter_policy *policy;
4674 struct mlx5_flow_meter_policy *final_policy;
4675 struct mlx5_flow_meter_sub_policy *sub_policy = NULL;
4677 policy = wks->policy;
4678 final_policy = policy->is_hierarchy ? wks->final_policy : policy;
4679 if (final_policy->is_rss || final_policy->is_queue) {
4680 struct mlx5_flow_rss_desc rss_desc_v[MLX5_MTR_RTE_COLORS];
4681 struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS] = {0};
4685 * This is a tmp dev_flow,
4686 * no need to register any matcher for it in translate.
4688 wks->skip_matcher_reg = 1;
4689 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
4690 struct mlx5_flow dev_flow = {0};
4691 struct mlx5_flow_handle dev_handle = { {0} };
4693 if (final_policy->is_rss) {
4694 const void *rss_act =
4695 final_policy->act_cnt[i].rss->conf;
4696 struct rte_flow_action rss_actions[2] = {
4698 .type = RTE_FLOW_ACTION_TYPE_RSS,
4702 .type = RTE_FLOW_ACTION_TYPE_END,
4707 dev_flow.handle = &dev_handle;
4708 dev_flow.ingress = attr->ingress;
4709 dev_flow.flow = flow;
4710 dev_flow.external = 0;
4711 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
4712 dev_flow.dv.transfer = attr->transfer;
4715 * Translate RSS action to get rss hash fields.
4717 if (flow_drv_translate(dev, &dev_flow, attr,
4718 items, rss_actions, error))
4720 rss_desc_v[i] = wks->rss_desc;
4721 rss_desc_v[i].key_len = MLX5_RSS_HASH_KEY_LEN;
4722 rss_desc_v[i].hash_fields =
4723 dev_flow.hash_fields;
4724 rss_desc_v[i].queue_num =
4725 rss_desc_v[i].hash_fields ?
4726 rss_desc_v[i].queue_num : 1;
4727 rss_desc_v[i].tunnel =
4728 !!(dev_flow.handle->layers &
4729 MLX5_FLOW_LAYER_TUNNEL);
4731 /* This is queue action. */
4732 rss_desc_v[i] = wks->rss_desc;
4733 rss_desc_v[i].key_len = 0;
4734 rss_desc_v[i].hash_fields = 0;
4735 rss_desc_v[i].queue =
4736 &final_policy->act_cnt[i].queue;
4737 rss_desc_v[i].queue_num = 1;
4739 rss_desc[i] = &rss_desc_v[i];
4741 sub_policy = flow_drv_meter_sub_policy_rss_prepare(dev,
4742 flow, policy, rss_desc);
4744 enum mlx5_meter_domain mtr_domain =
4745 attr->transfer ? MLX5_MTR_DOMAIN_TRANSFER :
4746 attr->egress ? MLX5_MTR_DOMAIN_EGRESS :
4747 MLX5_MTR_DOMAIN_INGRESS;
4748 sub_policy = policy->sub_policys[mtr_domain][0];
4751 rte_flow_error_set(error, EINVAL,
4752 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4753 "Failed to get meter sub-policy.");
4761 * Split the meter flow.
4763 * As meter flow will split to three sub flow, other than meter
4764 * action, the other actions make sense to only meter accepts
4765 * the packet. If it need to be dropped, no other additional
4766 * actions should be take.
4768 * One kind of special action which decapsulates the L3 tunnel
4769 * header will be in the prefix sub flow, as not to take the
4770 * L3 tunnel header into account.
4773 * Pointer to Ethernet device.
4775 * Parent flow structure pointer.
4777 * Pointer to thread flow work space.
4779 * Flow rule attributes.
4781 * Pattern specification (list terminated by the END pattern item).
4782 * @param[out] sfx_items
4783 * Suffix flow match items (list terminated by the END pattern item).
4784 * @param[in] actions
4785 * Associated actions (list terminated by the END action).
4786 * @param[out] actions_sfx
4787 * Suffix flow actions.
4788 * @param[out] actions_pre
4789 * Prefix flow actions.
4790 * @param[out] mtr_flow_id
4791 * Pointer to meter flow id.
4793 * Perform verbose error reporting if not NULL.
4796 * 0 on success, a negative errno value otherwise and rte_errno is set.
4799 flow_meter_split_prep(struct rte_eth_dev *dev,
4800 struct rte_flow *flow,
4801 struct mlx5_flow_workspace *wks,
4802 const struct rte_flow_attr *attr,
4803 const struct rte_flow_item items[],
4804 struct rte_flow_item sfx_items[],
4805 const struct rte_flow_action actions[],
4806 struct rte_flow_action actions_sfx[],
4807 struct rte_flow_action actions_pre[],
4808 uint32_t *mtr_flow_id,
4809 struct rte_flow_error *error)
4811 struct mlx5_priv *priv = dev->data->dev_private;
4812 struct mlx5_flow_meter_info *fm = wks->fm;
4813 struct rte_flow_action *tag_action = NULL;
4814 struct rte_flow_item *tag_item;
4815 struct mlx5_rte_flow_action_set_tag *set_tag;
4816 const struct rte_flow_action_raw_encap *raw_encap;
4817 const struct rte_flow_action_raw_decap *raw_decap;
4818 struct mlx5_rte_flow_item_tag *tag_item_spec;
4819 struct mlx5_rte_flow_item_tag *tag_item_mask;
4820 uint32_t tag_id = 0;
4821 struct rte_flow_item *vlan_item_dst = NULL;
4822 const struct rte_flow_item *vlan_item_src = NULL;
4823 struct rte_flow_action *hw_mtr_action;
4824 struct rte_flow_action *action_pre_head = NULL;
4825 int32_t flow_src_port = priv->representor_id;
4827 uint8_t mtr_id_offset = priv->mtr_reg_share ? MLX5_MTR_COLOR_BITS : 0;
4828 uint8_t mtr_reg_bits = priv->mtr_reg_share ?
4829 MLX5_MTR_IDLE_BITS_IN_COLOR_REG : MLX5_REG_BITS;
4830 uint32_t flow_id = 0;
4831 uint32_t flow_id_reversed = 0;
4832 uint8_t flow_id_bits = 0;
4835 /* Prepare the suffix subflow items. */
4836 tag_item = sfx_items++;
4837 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
4838 struct mlx5_priv *port_priv;
4839 const struct rte_flow_item_port_id *pid_v;
4840 int item_type = items->type;
4842 switch (item_type) {
4843 case RTE_FLOW_ITEM_TYPE_PORT_ID:
4844 pid_v = items->spec;
4846 port_priv = mlx5_port_to_eswitch_info(pid_v->id, false);
4848 return rte_flow_error_set(error,
4850 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
4852 "Failed to get port info.");
4853 flow_src_port = port_priv->representor_id;
4854 if (!fm->def_policy && wks->policy->is_hierarchy &&
4855 flow_src_port != priv->representor_id) {
4856 if (flow_drv_mtr_hierarchy_rule_create(dev,
4863 memcpy(sfx_items, items, sizeof(*sfx_items));
4866 case RTE_FLOW_ITEM_TYPE_VLAN:
4867 /* Determine if copy vlan item below. */
4868 vlan_item_src = items;
4869 vlan_item_dst = sfx_items++;
4870 vlan_item_dst->type = RTE_FLOW_ITEM_TYPE_VOID;
4876 sfx_items->type = RTE_FLOW_ITEM_TYPE_END;
4878 mtr_first = priv->sh->meter_aso_en &&
4879 (attr->egress || (attr->transfer && flow_src_port != UINT16_MAX));
4880 /* For ASO meter, meter must be before tag in TX direction. */
4882 action_pre_head = actions_pre++;
4883 /* Leave space for tag action. */
4884 tag_action = actions_pre++;
4886 /* Prepare the actions for prefix and suffix flow. */
4887 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4888 struct rte_flow_action *action_cur = NULL;
4890 switch (actions->type) {
4891 case RTE_FLOW_ACTION_TYPE_METER:
4893 action_cur = action_pre_head;
4895 /* Leave space for tag action. */
4896 tag_action = actions_pre++;
4897 action_cur = actions_pre++;
4900 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
4901 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
4902 action_cur = actions_pre++;
4904 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
4905 raw_encap = actions->conf;
4906 if (raw_encap->size < MLX5_ENCAPSULATION_DECISION_SIZE)
4907 action_cur = actions_pre++;
4909 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
4910 raw_decap = actions->conf;
4911 if (raw_decap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
4912 action_cur = actions_pre++;
4914 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
4915 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
4916 if (vlan_item_dst && vlan_item_src) {
4917 memcpy(vlan_item_dst, vlan_item_src,
4918 sizeof(*vlan_item_dst));
4920 * Convert to internal match item, it is used
4921 * for vlan push and set vid.
4923 vlan_item_dst->type = (enum rte_flow_item_type)
4924 MLX5_RTE_FLOW_ITEM_TYPE_VLAN;
4931 action_cur = (fm->def_policy) ?
4932 actions_sfx++ : actions_pre++;
4933 memcpy(action_cur, actions, sizeof(struct rte_flow_action));
4935 /* Add end action to the actions. */
4936 actions_sfx->type = RTE_FLOW_ACTION_TYPE_END;
4937 if (priv->sh->meter_aso_en) {
4939 * For ASO meter, need to add an extra jump action explicitly,
4940 * to jump from meter to policer table.
4942 struct mlx5_flow_meter_sub_policy *sub_policy;
4943 struct mlx5_flow_tbl_data_entry *tbl_data;
4945 if (!fm->def_policy) {
4946 sub_policy = get_meter_sub_policy(dev, flow, wks,
4947 attr, items, error);
4951 enum mlx5_meter_domain mtr_domain =
4952 attr->transfer ? MLX5_MTR_DOMAIN_TRANSFER :
4953 attr->egress ? MLX5_MTR_DOMAIN_EGRESS :
4954 MLX5_MTR_DOMAIN_INGRESS;
4957 &priv->sh->mtrmng->def_policy[mtr_domain]->sub_policy;
4959 tbl_data = container_of(sub_policy->tbl_rsc,
4960 struct mlx5_flow_tbl_data_entry, tbl);
4961 hw_mtr_action = actions_pre++;
4962 hw_mtr_action->type = (enum rte_flow_action_type)
4963 MLX5_RTE_FLOW_ACTION_TYPE_JUMP;
4964 hw_mtr_action->conf = tbl_data->jump.action;
4966 actions_pre->type = RTE_FLOW_ACTION_TYPE_END;
4969 return rte_flow_error_set(error, ENOMEM,
4970 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4971 "No tag action space.");
4973 tag_action->type = RTE_FLOW_ACTION_TYPE_VOID;
4976 /* Only default-policy Meter creates mtr flow id. */
4977 if (fm->def_policy) {
4978 mlx5_ipool_malloc(fm->flow_ipool, &tag_id);
4980 return rte_flow_error_set(error, ENOMEM,
4981 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4982 "Failed to allocate meter flow id.");
4983 flow_id = tag_id - 1;
4984 flow_id_bits = (!flow_id) ? 1 :
4985 (MLX5_REG_BITS - __builtin_clz(flow_id));
4986 if ((flow_id_bits + priv->sh->mtrmng->max_mtr_bits) >
4988 mlx5_ipool_free(fm->flow_ipool, tag_id);
4989 return rte_flow_error_set(error, EINVAL,
4990 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4991 "Meter flow id exceeds max limit.");
4993 if (flow_id_bits > priv->sh->mtrmng->max_mtr_flow_bits)
4994 priv->sh->mtrmng->max_mtr_flow_bits = flow_id_bits;
4996 /* Build tag actions and items for meter_id/meter flow_id. */
4997 set_tag = (struct mlx5_rte_flow_action_set_tag *)actions_pre;
4998 tag_item_spec = (struct mlx5_rte_flow_item_tag *)sfx_items;
4999 tag_item_mask = tag_item_spec + 1;
5000 /* Both flow_id and meter_id share the same register. */
5001 *set_tag = (struct mlx5_rte_flow_action_set_tag) {
5002 .id = (enum modify_reg)mlx5_flow_get_reg_id(dev, MLX5_MTR_ID,
5004 .offset = mtr_id_offset,
5005 .length = mtr_reg_bits,
5006 .data = flow->meter,
5009 * The color Reg bits used by flow_id are growing from
5010 * msb to lsb, so must do bit reverse for flow_id val in RegC.
5012 for (shift = 0; shift < flow_id_bits; shift++)
5013 flow_id_reversed = (flow_id_reversed << 1) |
5014 ((flow_id >> shift) & 0x1);
5016 flow_id_reversed << (mtr_reg_bits - flow_id_bits);
5017 tag_item_spec->id = set_tag->id;
5018 tag_item_spec->data = set_tag->data << mtr_id_offset;
5019 tag_item_mask->data = UINT32_MAX << mtr_id_offset;
5020 tag_action->type = (enum rte_flow_action_type)
5021 MLX5_RTE_FLOW_ACTION_TYPE_TAG;
5022 tag_action->conf = set_tag;
5023 tag_item->type = (enum rte_flow_item_type)
5024 MLX5_RTE_FLOW_ITEM_TYPE_TAG;
5025 tag_item->spec = tag_item_spec;
5026 tag_item->last = NULL;
5027 tag_item->mask = tag_item_mask;
5030 *mtr_flow_id = tag_id;
5035 * Split action list having QUEUE/RSS for metadata register copy.
5037 * Once Q/RSS action is detected in user's action list, the flow action
5038 * should be split in order to copy metadata registers, which will happen in
5040 * - CQE->flow_tag := reg_c[1] (MARK)
5041 * - CQE->flow_table_metadata (reg_b) := reg_c[0] (META)
5042 * The Q/RSS action will be performed on RX_ACT_TBL after passing by RX_CP_TBL.
5043 * This is because the last action of each flow must be a terminal action
5044 * (QUEUE, RSS or DROP).
5046 * Flow ID must be allocated to identify actions in the RX_ACT_TBL and it is
5047 * stored and kept in the mlx5_flow structure per each sub_flow.
5049 * The Q/RSS action is replaced with,
5050 * - SET_TAG, setting the allocated flow ID to reg_c[2].
5051 * And the following JUMP action is added at the end,
5052 * - JUMP, to RX_CP_TBL.
5054 * A flow to perform remained Q/RSS action will be created in RX_ACT_TBL by
5055 * flow_create_split_metadata() routine. The flow will look like,
5056 * - If flow ID matches (reg_c[2]), perform Q/RSS.
5059 * Pointer to Ethernet device.
5060 * @param[out] split_actions
5061 * Pointer to store split actions to jump to CP_TBL.
5062 * @param[in] actions
5063 * Pointer to the list of original flow actions.
5065 * Pointer to the Q/RSS action.
5066 * @param[in] actions_n
5067 * Number of original actions.
5069 * Perform verbose error reporting if not NULL.
5072 * non-zero unique flow_id on success, otherwise 0 and
5073 * error/rte_error are set.
5076 flow_mreg_split_qrss_prep(struct rte_eth_dev *dev,
5077 struct rte_flow_action *split_actions,
5078 const struct rte_flow_action *actions,
5079 const struct rte_flow_action *qrss,
5080 int actions_n, struct rte_flow_error *error)
5082 struct mlx5_priv *priv = dev->data->dev_private;
5083 struct mlx5_rte_flow_action_set_tag *set_tag;
5084 struct rte_flow_action_jump *jump;
5085 const int qrss_idx = qrss - actions;
5086 uint32_t flow_id = 0;
5090 * Given actions will be split
5091 * - Replace QUEUE/RSS action with SET_TAG to set flow ID.
5092 * - Add jump to mreg CP_TBL.
5093 * As a result, there will be one more action.
5096 memcpy(split_actions, actions, sizeof(*split_actions) * actions_n);
5097 set_tag = (void *)(split_actions + actions_n);
5099 * If tag action is not set to void(it means we are not the meter
5100 * suffix flow), add the tag action. Since meter suffix flow already
5101 * has the tag added.
5103 if (split_actions[qrss_idx].type != RTE_FLOW_ACTION_TYPE_VOID) {
5105 * Allocate the new subflow ID. This one is unique within
5106 * device and not shared with representors. Otherwise,
5107 * we would have to resolve multi-thread access synch
5108 * issue. Each flow on the shared device is appended
5109 * with source vport identifier, so the resulting
5110 * flows will be unique in the shared (by master and
5111 * representors) domain even if they have coinciding
5114 mlx5_ipool_malloc(priv->sh->ipool
5115 [MLX5_IPOOL_RSS_EXPANTION_FLOW_ID], &flow_id);
5117 return rte_flow_error_set(error, ENOMEM,
5118 RTE_FLOW_ERROR_TYPE_ACTION,
5119 NULL, "can't allocate id "
5120 "for split Q/RSS subflow");
5121 /* Internal SET_TAG action to set flow ID. */
5122 *set_tag = (struct mlx5_rte_flow_action_set_tag){
5125 ret = mlx5_flow_get_reg_id(dev, MLX5_COPY_MARK, 0, error);
5129 /* Construct new actions array. */
5130 /* Replace QUEUE/RSS action. */
5131 split_actions[qrss_idx] = (struct rte_flow_action){
5132 .type = (enum rte_flow_action_type)
5133 MLX5_RTE_FLOW_ACTION_TYPE_TAG,
5137 /* JUMP action to jump to mreg copy table (CP_TBL). */
5138 jump = (void *)(set_tag + 1);
5139 *jump = (struct rte_flow_action_jump){
5140 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
5142 split_actions[actions_n - 2] = (struct rte_flow_action){
5143 .type = RTE_FLOW_ACTION_TYPE_JUMP,
5146 split_actions[actions_n - 1] = (struct rte_flow_action){
5147 .type = RTE_FLOW_ACTION_TYPE_END,
5153 * Extend the given action list for Tx metadata copy.
5155 * Copy the given action list to the ext_actions and add flow metadata register
5156 * copy action in order to copy reg_a set by WQE to reg_c[0].
5158 * @param[out] ext_actions
5159 * Pointer to the extended action list.
5160 * @param[in] actions
5161 * Pointer to the list of actions.
5162 * @param[in] actions_n
5163 * Number of actions in the list.
5165 * Perform verbose error reporting if not NULL.
5166 * @param[in] encap_idx
5167 * The encap action inndex.
5170 * 0 on success, negative value otherwise
5173 flow_mreg_tx_copy_prep(struct rte_eth_dev *dev,
5174 struct rte_flow_action *ext_actions,
5175 const struct rte_flow_action *actions,
5176 int actions_n, struct rte_flow_error *error,
5179 struct mlx5_flow_action_copy_mreg *cp_mreg =
5180 (struct mlx5_flow_action_copy_mreg *)
5181 (ext_actions + actions_n + 1);
5184 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_RX, 0, error);
5188 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_TX, 0, error);
5193 memcpy(ext_actions, actions, sizeof(*ext_actions) * encap_idx);
5194 if (encap_idx == actions_n - 1) {
5195 ext_actions[actions_n - 1] = (struct rte_flow_action){
5196 .type = (enum rte_flow_action_type)
5197 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
5200 ext_actions[actions_n] = (struct rte_flow_action){
5201 .type = RTE_FLOW_ACTION_TYPE_END,
5204 ext_actions[encap_idx] = (struct rte_flow_action){
5205 .type = (enum rte_flow_action_type)
5206 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
5209 memcpy(ext_actions + encap_idx + 1, actions + encap_idx,
5210 sizeof(*ext_actions) * (actions_n - encap_idx));
5216 * Check the match action from the action list.
5218 * @param[in] actions
5219 * Pointer to the list of actions.
5221 * Flow rule attributes.
5223 * The action to be check if exist.
5224 * @param[out] match_action_pos
5225 * Pointer to the position of the matched action if exists, otherwise is -1.
5226 * @param[out] qrss_action_pos
5227 * Pointer to the position of the Queue/RSS action if exists, otherwise is -1.
5228 * @param[out] modify_after_mirror
5229 * Pointer to the flag of modify action after FDB mirroring.
5232 * > 0 the total number of actions.
5233 * 0 if not found match action in action list.
5236 flow_check_match_action(const struct rte_flow_action actions[],
5237 const struct rte_flow_attr *attr,
5238 enum rte_flow_action_type action,
5239 int *match_action_pos, int *qrss_action_pos,
5240 int *modify_after_mirror)
5242 const struct rte_flow_action_sample *sample;
5249 *match_action_pos = -1;
5250 *qrss_action_pos = -1;
5251 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
5252 if (actions->type == action) {
5254 *match_action_pos = actions_n;
5256 switch (actions->type) {
5257 case RTE_FLOW_ACTION_TYPE_QUEUE:
5258 case RTE_FLOW_ACTION_TYPE_RSS:
5259 *qrss_action_pos = actions_n;
5261 case RTE_FLOW_ACTION_TYPE_SAMPLE:
5262 sample = actions->conf;
5263 ratio = sample->ratio;
5264 sub_type = ((const struct rte_flow_action *)
5265 (sample->actions))->type;
5266 if (ratio == 1 && attr->transfer)
5269 case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
5270 case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
5271 case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
5272 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
5273 case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
5274 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
5275 case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
5276 case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
5277 case RTE_FLOW_ACTION_TYPE_DEC_TTL:
5278 case RTE_FLOW_ACTION_TYPE_SET_TTL:
5279 case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
5280 case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
5281 case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
5282 case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
5283 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
5284 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
5285 case RTE_FLOW_ACTION_TYPE_FLAG:
5286 case RTE_FLOW_ACTION_TYPE_MARK:
5287 case RTE_FLOW_ACTION_TYPE_SET_META:
5288 case RTE_FLOW_ACTION_TYPE_SET_TAG:
5289 case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
5290 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
5291 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
5292 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
5293 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
5294 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
5295 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
5296 case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
5297 case RTE_FLOW_ACTION_TYPE_METER:
5299 *modify_after_mirror = 1;
5306 if (flag && fdb_mirror && !*modify_after_mirror) {
5307 /* FDB mirroring uses the destination array to implement
5308 * instead of FLOW_SAMPLER object.
5310 if (sub_type != RTE_FLOW_ACTION_TYPE_END)
5313 /* Count RTE_FLOW_ACTION_TYPE_END. */
5314 return flag ? actions_n + 1 : 0;
5317 #define SAMPLE_SUFFIX_ITEM 2
5320 * Split the sample flow.
5322 * As sample flow will split to two sub flow, sample flow with
5323 * sample action, the other actions will move to new suffix flow.
5325 * Also add unique tag id with tag action in the sample flow,
5326 * the same tag id will be as match in the suffix flow.
5329 * Pointer to Ethernet device.
5330 * @param[in] add_tag
5331 * Add extra tag action flag.
5332 * @param[out] sfx_items
5333 * Suffix flow match items (list terminated by the END pattern item).
5334 * @param[in] actions
5335 * Associated actions (list terminated by the END action).
5336 * @param[out] actions_sfx
5337 * Suffix flow actions.
5338 * @param[out] actions_pre
5339 * Prefix flow actions.
5340 * @param[in] actions_n
5341 * The total number of actions.
5342 * @param[in] sample_action_pos
5343 * The sample action position.
5344 * @param[in] qrss_action_pos
5345 * The Queue/RSS action position.
5346 * @param[in] jump_table
5347 * Add extra jump action flag.
5349 * Perform verbose error reporting if not NULL.
5352 * 0 on success, or unique flow_id, a negative errno value
5353 * otherwise and rte_errno is set.
5356 flow_sample_split_prep(struct rte_eth_dev *dev,
5358 struct rte_flow_item sfx_items[],
5359 const struct rte_flow_action actions[],
5360 struct rte_flow_action actions_sfx[],
5361 struct rte_flow_action actions_pre[],
5363 int sample_action_pos,
5364 int qrss_action_pos,
5366 struct rte_flow_error *error)
5368 struct mlx5_priv *priv = dev->data->dev_private;
5369 struct mlx5_rte_flow_action_set_tag *set_tag;
5370 struct mlx5_rte_flow_item_tag *tag_spec;
5371 struct mlx5_rte_flow_item_tag *tag_mask;
5372 struct rte_flow_action_jump *jump_action;
5373 uint32_t tag_id = 0;
5375 int append_index = 0;
5378 if (sample_action_pos < 0)
5379 return rte_flow_error_set(error, EINVAL,
5380 RTE_FLOW_ERROR_TYPE_ACTION,
5381 NULL, "invalid position of sample "
5383 /* Prepare the actions for prefix and suffix flow. */
5384 if (qrss_action_pos >= 0 && qrss_action_pos < sample_action_pos) {
5385 index = qrss_action_pos;
5386 /* Put the preceding the Queue/RSS action into prefix flow. */
5388 memcpy(actions_pre, actions,
5389 sizeof(struct rte_flow_action) * index);
5390 /* Put others preceding the sample action into prefix flow. */
5391 if (sample_action_pos > index + 1)
5392 memcpy(actions_pre + index, actions + index + 1,
5393 sizeof(struct rte_flow_action) *
5394 (sample_action_pos - index - 1));
5395 index = sample_action_pos - 1;
5396 /* Put Queue/RSS action into Suffix flow. */
5397 memcpy(actions_sfx, actions + qrss_action_pos,
5398 sizeof(struct rte_flow_action));
5401 index = sample_action_pos;
5403 memcpy(actions_pre, actions,
5404 sizeof(struct rte_flow_action) * index);
5406 /* For CX5, add an extra tag action for NIC-RX and E-Switch ingress.
5407 * For CX6DX and above, metadata registers Cx preserve their value,
5408 * add an extra tag action for NIC-RX and E-Switch Domain.
5411 /* Prepare the prefix tag action. */
5413 set_tag = (void *)(actions_pre + actions_n + append_index);
5414 ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, 0, error);
5417 mlx5_ipool_malloc(priv->sh->ipool
5418 [MLX5_IPOOL_RSS_EXPANTION_FLOW_ID], &tag_id);
5419 *set_tag = (struct mlx5_rte_flow_action_set_tag) {
5423 /* Prepare the suffix subflow items. */
5424 tag_spec = (void *)(sfx_items + SAMPLE_SUFFIX_ITEM);
5425 tag_spec->data = tag_id;
5426 tag_spec->id = set_tag->id;
5427 tag_mask = tag_spec + 1;
5428 tag_mask->data = UINT32_MAX;
5429 sfx_items[0] = (struct rte_flow_item){
5430 .type = (enum rte_flow_item_type)
5431 MLX5_RTE_FLOW_ITEM_TYPE_TAG,
5436 sfx_items[1] = (struct rte_flow_item){
5437 .type = (enum rte_flow_item_type)
5438 RTE_FLOW_ITEM_TYPE_END,
5440 /* Prepare the tag action in prefix subflow. */
5441 actions_pre[index++] =
5442 (struct rte_flow_action){
5443 .type = (enum rte_flow_action_type)
5444 MLX5_RTE_FLOW_ACTION_TYPE_TAG,
5448 memcpy(actions_pre + index, actions + sample_action_pos,
5449 sizeof(struct rte_flow_action));
5451 /* For the modify action after the sample action in E-Switch mirroring,
5452 * Add the extra jump action in prefix subflow and jump into the next
5453 * table, then do the modify action in the new table.
5456 /* Prepare the prefix jump action. */
5458 jump_action = (void *)(actions_pre + actions_n + append_index);
5459 jump_action->group = jump_table;
5460 actions_pre[index++] =
5461 (struct rte_flow_action){
5462 .type = (enum rte_flow_action_type)
5463 RTE_FLOW_ACTION_TYPE_JUMP,
5464 .conf = jump_action,
5467 actions_pre[index] = (struct rte_flow_action){
5468 .type = (enum rte_flow_action_type)
5469 RTE_FLOW_ACTION_TYPE_END,
5471 /* Put the actions after sample into Suffix flow. */
5472 memcpy(actions_sfx, actions + sample_action_pos + 1,
5473 sizeof(struct rte_flow_action) *
5474 (actions_n - sample_action_pos - 1));
5479 * The splitting for metadata feature.
5481 * - Q/RSS action on NIC Rx should be split in order to pass by
5482 * the mreg copy table (RX_CP_TBL) and then it jumps to the
5483 * action table (RX_ACT_TBL) which has the split Q/RSS action.
5485 * - All the actions on NIC Tx should have a mreg copy action to
5486 * copy reg_a from WQE to reg_c[0].
5489 * Pointer to Ethernet device.
5491 * Parent flow structure pointer.
5493 * Flow rule attributes.
5495 * Pattern specification (list terminated by the END pattern item).
5496 * @param[in] actions
5497 * Associated actions (list terminated by the END action).
5498 * @param[in] flow_split_info
5499 * Pointer to flow split info structure.
5501 * Perform verbose error reporting if not NULL.
5503 * 0 on success, negative value otherwise
5506 flow_create_split_metadata(struct rte_eth_dev *dev,
5507 struct rte_flow *flow,
5508 const struct rte_flow_attr *attr,
5509 const struct rte_flow_item items[],
5510 const struct rte_flow_action actions[],
5511 struct mlx5_flow_split_info *flow_split_info,
5512 struct rte_flow_error *error)
5514 struct mlx5_priv *priv = dev->data->dev_private;
5515 struct mlx5_dev_config *config = &priv->config;
5516 const struct rte_flow_action *qrss = NULL;
5517 struct rte_flow_action *ext_actions = NULL;
5518 struct mlx5_flow *dev_flow = NULL;
5519 uint32_t qrss_id = 0;
5526 /* Check whether extensive metadata feature is engaged. */
5527 if (!config->dv_flow_en ||
5528 config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
5529 !mlx5_flow_ext_mreg_supported(dev))
5530 return flow_create_split_inner(dev, flow, NULL, attr, items,
5531 actions, flow_split_info, error);
5532 actions_n = flow_parse_metadata_split_actions_info(actions, &qrss,
5535 /* Exclude hairpin flows from splitting. */
5536 if (qrss->type == RTE_FLOW_ACTION_TYPE_QUEUE) {
5537 const struct rte_flow_action_queue *queue;
5540 if (mlx5_rxq_get_type(dev, queue->index) ==
5541 MLX5_RXQ_TYPE_HAIRPIN)
5543 } else if (qrss->type == RTE_FLOW_ACTION_TYPE_RSS) {
5544 const struct rte_flow_action_rss *rss;
5547 if (mlx5_rxq_get_type(dev, rss->queue[0]) ==
5548 MLX5_RXQ_TYPE_HAIRPIN)
5553 /* Check if it is in meter suffix table. */
5554 mtr_sfx = attr->group == (attr->transfer ?
5555 (MLX5_FLOW_TABLE_LEVEL_METER - 1) :
5556 MLX5_FLOW_TABLE_LEVEL_METER);
5558 * Q/RSS action on NIC Rx should be split in order to pass by
5559 * the mreg copy table (RX_CP_TBL) and then it jumps to the
5560 * action table (RX_ACT_TBL) which has the split Q/RSS action.
5562 act_size = sizeof(struct rte_flow_action) * (actions_n + 1) +
5563 sizeof(struct rte_flow_action_set_tag) +
5564 sizeof(struct rte_flow_action_jump);
5565 ext_actions = mlx5_malloc(MLX5_MEM_ZERO, act_size, 0,
5568 return rte_flow_error_set(error, ENOMEM,
5569 RTE_FLOW_ERROR_TYPE_ACTION,
5570 NULL, "no memory to split "
5573 * If we are the suffix flow of meter, tag already exist.
5574 * Set the tag action to void.
5577 ext_actions[qrss - actions].type =
5578 RTE_FLOW_ACTION_TYPE_VOID;
5580 ext_actions[qrss - actions].type =
5581 (enum rte_flow_action_type)
5582 MLX5_RTE_FLOW_ACTION_TYPE_TAG;
5584 * Create the new actions list with removed Q/RSS action
5585 * and appended set tag and jump to register copy table
5586 * (RX_CP_TBL). We should preallocate unique tag ID here
5587 * in advance, because it is needed for set tag action.
5589 qrss_id = flow_mreg_split_qrss_prep(dev, ext_actions, actions,
5590 qrss, actions_n, error);
5591 if (!mtr_sfx && !qrss_id) {
5595 } else if (attr->egress && !attr->transfer) {
5597 * All the actions on NIC Tx should have a metadata register
5598 * copy action to copy reg_a from WQE to reg_c[meta]
5600 act_size = sizeof(struct rte_flow_action) * (actions_n + 1) +
5601 sizeof(struct mlx5_flow_action_copy_mreg);
5602 ext_actions = mlx5_malloc(MLX5_MEM_ZERO, act_size, 0,
5605 return rte_flow_error_set(error, ENOMEM,
5606 RTE_FLOW_ERROR_TYPE_ACTION,
5607 NULL, "no memory to split "
5609 /* Create the action list appended with copy register. */
5610 ret = flow_mreg_tx_copy_prep(dev, ext_actions, actions,
5611 actions_n, error, encap_idx);
5615 /* Add the unmodified original or prefix subflow. */
5616 ret = flow_create_split_inner(dev, flow, &dev_flow, attr,
5617 items, ext_actions ? ext_actions :
5618 actions, flow_split_info, error);
5621 MLX5_ASSERT(dev_flow);
5623 const struct rte_flow_attr q_attr = {
5624 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
5627 /* Internal PMD action to set register. */
5628 struct mlx5_rte_flow_item_tag q_tag_spec = {
5632 struct rte_flow_item q_items[] = {
5634 .type = (enum rte_flow_item_type)
5635 MLX5_RTE_FLOW_ITEM_TYPE_TAG,
5636 .spec = &q_tag_spec,
5641 .type = RTE_FLOW_ITEM_TYPE_END,
5644 struct rte_flow_action q_actions[] = {
5650 .type = RTE_FLOW_ACTION_TYPE_END,
5653 uint64_t layers = flow_get_prefix_layer_flags(dev_flow);
5656 * Configure the tag item only if there is no meter subflow.
5657 * Since tag is already marked in the meter suffix subflow
5658 * we can just use the meter suffix items as is.
5661 /* Not meter subflow. */
5662 MLX5_ASSERT(!mtr_sfx);
5664 * Put unique id in prefix flow due to it is destroyed
5665 * after suffix flow and id will be freed after there
5666 * is no actual flows with this id and identifier
5667 * reallocation becomes possible (for example, for
5668 * other flows in other threads).
5670 dev_flow->handle->split_flow_id = qrss_id;
5671 ret = mlx5_flow_get_reg_id(dev, MLX5_COPY_MARK, 0,
5675 q_tag_spec.id = ret;
5678 /* Add suffix subflow to execute Q/RSS. */
5679 flow_split_info->prefix_layers = layers;
5680 flow_split_info->prefix_mark = 0;
5681 ret = flow_create_split_inner(dev, flow, &dev_flow,
5682 &q_attr, mtr_sfx ? items :
5684 flow_split_info, error);
5687 /* qrss ID should be freed if failed. */
5689 MLX5_ASSERT(dev_flow);
5694 * We do not destroy the partially created sub_flows in case of error.
5695 * These ones are included into parent flow list and will be destroyed
5696 * by flow_drv_destroy.
5698 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RSS_EXPANTION_FLOW_ID],
5700 mlx5_free(ext_actions);
5705 * Create meter internal drop flow with the original pattern.
5708 * Pointer to Ethernet device.
5710 * Parent flow structure pointer.
5712 * Flow rule attributes.
5714 * Pattern specification (list terminated by the END pattern item).
5715 * @param[in] flow_split_info
5716 * Pointer to flow split info structure.
5718 * Pointer to flow meter structure.
5720 * Perform verbose error reporting if not NULL.
5722 * 0 on success, negative value otherwise
5725 flow_meter_create_drop_flow_with_org_pattern(struct rte_eth_dev *dev,
5726 struct rte_flow *flow,
5727 const struct rte_flow_attr *attr,
5728 const struct rte_flow_item items[],
5729 struct mlx5_flow_split_info *flow_split_info,
5730 struct mlx5_flow_meter_info *fm,
5731 struct rte_flow_error *error)
5733 struct mlx5_flow *dev_flow = NULL;
5734 struct rte_flow_attr drop_attr = *attr;
5735 struct rte_flow_action drop_actions[3];
5736 struct mlx5_flow_split_info drop_split_info = *flow_split_info;
5738 MLX5_ASSERT(fm->drop_cnt);
5739 drop_actions[0].type =
5740 (enum rte_flow_action_type)MLX5_RTE_FLOW_ACTION_TYPE_COUNT;
5741 drop_actions[0].conf = (void *)(uintptr_t)fm->drop_cnt;
5742 drop_actions[1].type = RTE_FLOW_ACTION_TYPE_DROP;
5743 drop_actions[1].conf = NULL;
5744 drop_actions[2].type = RTE_FLOW_ACTION_TYPE_END;
5745 drop_actions[2].conf = NULL;
5746 drop_split_info.external = false;
5747 drop_split_info.skip_scale |= 1 << MLX5_SCALE_FLOW_GROUP_BIT;
5748 drop_split_info.table_id = MLX5_MTR_TABLE_ID_DROP;
5749 drop_attr.group = MLX5_FLOW_TABLE_LEVEL_METER;
5750 return flow_create_split_inner(dev, flow, &dev_flow,
5751 &drop_attr, items, drop_actions,
5752 &drop_split_info, error);
5756 * The splitting for meter feature.
5758 * - The meter flow will be split to two flows as prefix and
5759 * suffix flow. The packets make sense only it pass the prefix
5762 * - Reg_C_5 is used for the packet to match betweend prefix and
5766 * Pointer to Ethernet device.
5768 * Parent flow structure pointer.
5770 * Flow rule attributes.
5772 * Pattern specification (list terminated by the END pattern item).
5773 * @param[in] actions
5774 * Associated actions (list terminated by the END action).
5775 * @param[in] flow_split_info
5776 * Pointer to flow split info structure.
5778 * Perform verbose error reporting if not NULL.
5780 * 0 on success, negative value otherwise
5783 flow_create_split_meter(struct rte_eth_dev *dev,
5784 struct rte_flow *flow,
5785 const struct rte_flow_attr *attr,
5786 const struct rte_flow_item items[],
5787 const struct rte_flow_action actions[],
5788 struct mlx5_flow_split_info *flow_split_info,
5789 struct rte_flow_error *error)
5791 struct mlx5_priv *priv = dev->data->dev_private;
5792 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
5793 struct rte_flow_action *sfx_actions = NULL;
5794 struct rte_flow_action *pre_actions = NULL;
5795 struct rte_flow_item *sfx_items = NULL;
5796 struct mlx5_flow *dev_flow = NULL;
5797 struct rte_flow_attr sfx_attr = *attr;
5798 struct mlx5_flow_meter_info *fm = NULL;
5799 uint8_t skip_scale_restore;
5800 bool has_mtr = false;
5801 bool has_modify = false;
5802 bool set_mtr_reg = true;
5803 bool is_mtr_hierarchy = false;
5804 uint32_t meter_id = 0;
5805 uint32_t mtr_idx = 0;
5806 uint32_t mtr_flow_id = 0;
5813 actions_n = flow_check_meter_action(dev, actions, &has_mtr,
5814 &has_modify, &meter_id);
5817 fm = flow_dv_meter_find_by_idx(priv, flow->meter);
5819 return rte_flow_error_set(error, EINVAL,
5820 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5821 NULL, "Meter not found.");
5823 fm = mlx5_flow_meter_find(priv, meter_id, &mtr_idx);
5825 return rte_flow_error_set(error, EINVAL,
5826 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5827 NULL, "Meter not found.");
5828 ret = mlx5_flow_meter_attach(priv, fm,
5832 flow->meter = mtr_idx;
5836 if (!fm->def_policy) {
5837 wks->policy = mlx5_flow_meter_policy_find(dev,
5840 MLX5_ASSERT(wks->policy);
5841 if (wks->policy->is_hierarchy) {
5843 mlx5_flow_meter_hierarchy_get_final_policy(dev,
5845 if (!wks->final_policy)
5846 return rte_flow_error_set(error,
5848 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5849 "Failed to find terminal policy of hierarchy.");
5850 is_mtr_hierarchy = true;
5854 * If it isn't default-policy Meter, and
5855 * 1. There's no action in flow to change
5856 * packet (modify/encap/decap etc.), OR
5857 * 2. No drop count needed for this meter.
5858 * 3. It's not meter hierarchy.
5859 * Then no need to use regC to save meter id anymore.
5861 if (!fm->def_policy && !is_mtr_hierarchy &&
5862 (!has_modify || !fm->drop_cnt))
5863 set_mtr_reg = false;
5864 /* Prefix actions: meter, decap, encap, tag, jump, end. */
5865 act_size = sizeof(struct rte_flow_action) * (actions_n + 6) +
5866 sizeof(struct mlx5_rte_flow_action_set_tag);
5867 /* Suffix items: tag, vlan, port id, end. */
5868 #define METER_SUFFIX_ITEM 4
5869 item_size = sizeof(struct rte_flow_item) * METER_SUFFIX_ITEM +
5870 sizeof(struct mlx5_rte_flow_item_tag) * 2;
5871 sfx_actions = mlx5_malloc(MLX5_MEM_ZERO, (act_size + item_size),
5874 return rte_flow_error_set(error, ENOMEM,
5875 RTE_FLOW_ERROR_TYPE_ACTION,
5876 NULL, "no memory to split "
5878 sfx_items = (struct rte_flow_item *)((char *)sfx_actions +
5880 /* There's no suffix flow for meter of non-default policy. */
5881 if (!fm->def_policy)
5882 pre_actions = sfx_actions + 1;
5884 pre_actions = sfx_actions + actions_n;
5885 ret = flow_meter_split_prep(dev, flow, wks, &sfx_attr,
5886 items, sfx_items, actions,
5887 sfx_actions, pre_actions,
5888 (set_mtr_reg ? &mtr_flow_id : NULL),
5894 /* Add the prefix subflow. */
5895 flow_split_info->prefix_mark = 0;
5896 skip_scale_restore = flow_split_info->skip_scale;
5897 flow_split_info->skip_scale |=
5898 1 << MLX5_SCALE_JUMP_FLOW_GROUP_BIT;
5899 ret = flow_create_split_inner(dev, flow, &dev_flow,
5900 attr, items, pre_actions,
5901 flow_split_info, error);
5902 flow_split_info->skip_scale = skip_scale_restore;
5905 mlx5_ipool_free(fm->flow_ipool, mtr_flow_id);
5910 dev_flow->handle->split_flow_id = mtr_flow_id;
5911 dev_flow->handle->is_meter_flow_id = 1;
5913 if (!fm->def_policy) {
5914 if (!set_mtr_reg && fm->drop_cnt)
5916 flow_meter_create_drop_flow_with_org_pattern(dev, flow,
5922 /* Setting the sfx group atrr. */
5923 sfx_attr.group = sfx_attr.transfer ?
5924 (MLX5_FLOW_TABLE_LEVEL_METER - 1) :
5925 MLX5_FLOW_TABLE_LEVEL_METER;
5926 flow_split_info->prefix_layers =
5927 flow_get_prefix_layer_flags(dev_flow);
5928 flow_split_info->prefix_mark = dev_flow->handle->mark;
5929 flow_split_info->table_id = MLX5_MTR_TABLE_ID_SUFFIX;
5931 /* Add the prefix subflow. */
5932 ret = flow_create_split_metadata(dev, flow,
5933 &sfx_attr, sfx_items ?
5935 sfx_actions ? sfx_actions : actions,
5936 flow_split_info, error);
5939 mlx5_free(sfx_actions);
5944 * The splitting for sample feature.
5946 * Once Sample action is detected in the action list, the flow actions should
5947 * be split into prefix sub flow and suffix sub flow.
5949 * The original items remain in the prefix sub flow, all actions preceding the
5950 * sample action and the sample action itself will be copied to the prefix
5951 * sub flow, the actions following the sample action will be copied to the
5952 * suffix sub flow, Queue action always be located in the suffix sub flow.
5954 * In order to make the packet from prefix sub flow matches with suffix sub
5955 * flow, an extra tag action be added into prefix sub flow, and the suffix sub
5956 * flow uses tag item with the unique flow id.
5959 * Pointer to Ethernet device.
5961 * Parent flow structure pointer.
5963 * Flow rule attributes.
5965 * Pattern specification (list terminated by the END pattern item).
5966 * @param[in] actions
5967 * Associated actions (list terminated by the END action).
5968 * @param[in] flow_split_info
5969 * Pointer to flow split info structure.
5971 * Perform verbose error reporting if not NULL.
5973 * 0 on success, negative value otherwise
5976 flow_create_split_sample(struct rte_eth_dev *dev,
5977 struct rte_flow *flow,
5978 const struct rte_flow_attr *attr,
5979 const struct rte_flow_item items[],
5980 const struct rte_flow_action actions[],
5981 struct mlx5_flow_split_info *flow_split_info,
5982 struct rte_flow_error *error)
5984 struct mlx5_priv *priv = dev->data->dev_private;
5985 struct rte_flow_action *sfx_actions = NULL;
5986 struct rte_flow_action *pre_actions = NULL;
5987 struct rte_flow_item *sfx_items = NULL;
5988 struct mlx5_flow *dev_flow = NULL;
5989 struct rte_flow_attr sfx_attr = *attr;
5990 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
5991 struct mlx5_flow_dv_sample_resource *sample_res;
5992 struct mlx5_flow_tbl_data_entry *sfx_tbl_data;
5993 struct mlx5_flow_tbl_resource *sfx_tbl;
5997 uint32_t fdb_tx = 0;
6000 int sample_action_pos;
6001 int qrss_action_pos;
6003 int modify_after_mirror = 0;
6004 uint16_t jump_table = 0;
6005 const uint32_t next_ft_step = 1;
6008 if (priv->sampler_en)
6009 actions_n = flow_check_match_action(actions, attr,
6010 RTE_FLOW_ACTION_TYPE_SAMPLE,
6011 &sample_action_pos, &qrss_action_pos,
6012 &modify_after_mirror);
6014 /* The prefix actions must includes sample, tag, end. */
6015 act_size = sizeof(struct rte_flow_action) * (actions_n * 2 + 1)
6016 + sizeof(struct mlx5_rte_flow_action_set_tag);
6017 item_size = sizeof(struct rte_flow_item) * SAMPLE_SUFFIX_ITEM +
6018 sizeof(struct mlx5_rte_flow_item_tag) * 2;
6019 sfx_actions = mlx5_malloc(MLX5_MEM_ZERO, (act_size +
6020 item_size), 0, SOCKET_ID_ANY);
6022 return rte_flow_error_set(error, ENOMEM,
6023 RTE_FLOW_ERROR_TYPE_ACTION,
6024 NULL, "no memory to split "
6026 /* The representor_id is UINT16_MAX for uplink. */
6027 fdb_tx = (attr->transfer && priv->representor_id != UINT16_MAX);
6029 * When reg_c_preserve is set, metadata registers Cx preserve
6030 * their value even through packet duplication.
6032 add_tag = (!fdb_tx || priv->config.hca_attr.reg_c_preserve);
6034 sfx_items = (struct rte_flow_item *)((char *)sfx_actions
6036 if (modify_after_mirror)
6037 jump_table = attr->group * MLX5_FLOW_TABLE_FACTOR +
6039 pre_actions = sfx_actions + actions_n;
6040 tag_id = flow_sample_split_prep(dev, add_tag, sfx_items,
6041 actions, sfx_actions,
6042 pre_actions, actions_n,
6044 qrss_action_pos, jump_table,
6046 if (tag_id < 0 || (add_tag && !tag_id)) {
6050 if (modify_after_mirror)
6051 flow_split_info->skip_scale =
6052 1 << MLX5_SCALE_JUMP_FLOW_GROUP_BIT;
6053 /* Add the prefix subflow. */
6054 ret = flow_create_split_inner(dev, flow, &dev_flow, attr,
6056 flow_split_info, error);
6061 dev_flow->handle->split_flow_id = tag_id;
6062 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
6063 if (!modify_after_mirror) {
6064 /* Set the sfx group attr. */
6065 sample_res = (struct mlx5_flow_dv_sample_resource *)
6066 dev_flow->dv.sample_res;
6067 sfx_tbl = (struct mlx5_flow_tbl_resource *)
6068 sample_res->normal_path_tbl;
6069 sfx_tbl_data = container_of(sfx_tbl,
6070 struct mlx5_flow_tbl_data_entry,
6072 sfx_attr.group = sfx_attr.transfer ?
6073 (sfx_tbl_data->level - 1) : sfx_tbl_data->level;
6075 MLX5_ASSERT(attr->transfer);
6076 sfx_attr.group = jump_table;
6078 flow_split_info->prefix_layers =
6079 flow_get_prefix_layer_flags(dev_flow);
6080 flow_split_info->prefix_mark = dev_flow->handle->mark;
6081 /* Suffix group level already be scaled with factor, set
6082 * MLX5_SCALE_FLOW_GROUP_BIT of skip_scale to 1 to avoid scale
6083 * again in translation.
6085 flow_split_info->skip_scale = 1 << MLX5_SCALE_FLOW_GROUP_BIT;
6088 /* Add the suffix subflow. */
6089 ret = flow_create_split_meter(dev, flow, &sfx_attr,
6090 sfx_items ? sfx_items : items,
6091 sfx_actions ? sfx_actions : actions,
6092 flow_split_info, error);
6095 mlx5_free(sfx_actions);
6100 * Split the flow to subflow set. The splitters might be linked
6101 * in the chain, like this:
6102 * flow_create_split_outer() calls:
6103 * flow_create_split_meter() calls:
6104 * flow_create_split_metadata(meter_subflow_0) calls:
6105 * flow_create_split_inner(metadata_subflow_0)
6106 * flow_create_split_inner(metadata_subflow_1)
6107 * flow_create_split_inner(metadata_subflow_2)
6108 * flow_create_split_metadata(meter_subflow_1) calls:
6109 * flow_create_split_inner(metadata_subflow_0)
6110 * flow_create_split_inner(metadata_subflow_1)
6111 * flow_create_split_inner(metadata_subflow_2)
6113 * This provide flexible way to add new levels of flow splitting.
6114 * The all of successfully created subflows are included to the
6115 * parent flow dev_flow list.
6118 * Pointer to Ethernet device.
6120 * Parent flow structure pointer.
6122 * Flow rule attributes.
6124 * Pattern specification (list terminated by the END pattern item).
6125 * @param[in] actions
6126 * Associated actions (list terminated by the END action).
6127 * @param[in] flow_split_info
6128 * Pointer to flow split info structure.
6130 * Perform verbose error reporting if not NULL.
6132 * 0 on success, negative value otherwise
6135 flow_create_split_outer(struct rte_eth_dev *dev,
6136 struct rte_flow *flow,
6137 const struct rte_flow_attr *attr,
6138 const struct rte_flow_item items[],
6139 const struct rte_flow_action actions[],
6140 struct mlx5_flow_split_info *flow_split_info,
6141 struct rte_flow_error *error)
6145 ret = flow_create_split_sample(dev, flow, attr, items,
6146 actions, flow_split_info, error);
6147 MLX5_ASSERT(ret <= 0);
6151 static inline struct mlx5_flow_tunnel *
6152 flow_tunnel_from_rule(const struct mlx5_flow *flow)
6154 struct mlx5_flow_tunnel *tunnel;
6156 #pragma GCC diagnostic push
6157 #pragma GCC diagnostic ignored "-Wcast-qual"
6158 tunnel = (typeof(tunnel))flow->tunnel;
6159 #pragma GCC diagnostic pop
6165 * Adjust flow RSS workspace if needed.
6168 * Pointer to thread flow work space.
6170 * Pointer to RSS descriptor.
6171 * @param[in] nrssq_num
6172 * New RSS queue number.
6175 * 0 on success, -1 otherwise and rte_errno is set.
6178 flow_rss_workspace_adjust(struct mlx5_flow_workspace *wks,
6179 struct mlx5_flow_rss_desc *rss_desc,
6182 if (likely(nrssq_num <= wks->rssq_num))
6184 rss_desc->queue = realloc(rss_desc->queue,
6185 sizeof(*rss_desc->queue) * RTE_ALIGN(nrssq_num, 2));
6186 if (!rss_desc->queue) {
6190 wks->rssq_num = RTE_ALIGN(nrssq_num, 2);
6195 * Create a flow and add it to @p list.
6198 * Pointer to Ethernet device.
6200 * Pointer to a TAILQ flow list. If this parameter NULL,
6201 * no list insertion occurred, flow is just created,
6202 * this is caller's responsibility to track the
6205 * Flow rule attributes.
6207 * Pattern specification (list terminated by the END pattern item).
6208 * @param[in] actions
6209 * Associated actions (list terminated by the END action).
6210 * @param[in] external
6211 * This flow rule is created by request external to PMD.
6213 * Perform verbose error reporting if not NULL.
6216 * A flow index on success, 0 otherwise and rte_errno is set.
6219 flow_list_create(struct rte_eth_dev *dev, enum mlx5_flow_type type,
6220 const struct rte_flow_attr *attr,
6221 const struct rte_flow_item items[],
6222 const struct rte_flow_action original_actions[],
6223 bool external, struct rte_flow_error *error)
6225 struct mlx5_priv *priv = dev->data->dev_private;
6226 struct rte_flow *flow = NULL;
6227 struct mlx5_flow *dev_flow;
6228 const struct rte_flow_action_rss *rss = NULL;
6229 struct mlx5_translated_action_handle
6230 indir_actions[MLX5_MAX_INDIRECT_ACTIONS];
6231 int indir_actions_n = MLX5_MAX_INDIRECT_ACTIONS;
6233 struct mlx5_flow_expand_rss buf;
6234 uint8_t buffer[2048];
6237 struct rte_flow_action actions[MLX5_MAX_SPLIT_ACTIONS];
6238 uint8_t buffer[2048];
6241 struct rte_flow_action actions[MLX5_MAX_SPLIT_ACTIONS];
6242 uint8_t buffer[2048];
6243 } actions_hairpin_tx;
6245 struct rte_flow_item items[MLX5_MAX_SPLIT_ITEMS];
6246 uint8_t buffer[2048];
6248 struct mlx5_flow_expand_rss *buf = &expand_buffer.buf;
6249 struct mlx5_flow_rss_desc *rss_desc;
6250 const struct rte_flow_action *p_actions_rx;
6254 struct rte_flow_attr attr_tx = { .priority = 0 };
6255 const struct rte_flow_action *actions;
6256 struct rte_flow_action *translated_actions = NULL;
6257 struct mlx5_flow_tunnel *tunnel;
6258 struct tunnel_default_miss_ctx default_miss_ctx = { 0, };
6259 struct mlx5_flow_workspace *wks = mlx5_flow_push_thread_workspace();
6260 struct mlx5_flow_split_info flow_split_info = {
6261 .external = !!external,
6271 rss_desc = &wks->rss_desc;
6272 ret = flow_action_handles_translate(dev, original_actions,
6275 &translated_actions, error);
6277 MLX5_ASSERT(translated_actions == NULL);
6280 actions = translated_actions ? translated_actions : original_actions;
6281 p_actions_rx = actions;
6282 hairpin_flow = flow_check_hairpin_split(dev, attr, actions);
6283 ret = flow_drv_validate(dev, attr, items, p_actions_rx,
6284 external, hairpin_flow, error);
6286 goto error_before_hairpin_split;
6287 flow = mlx5_ipool_zmalloc(priv->flows[type], &idx);
6290 goto error_before_hairpin_split;
6292 if (hairpin_flow > 0) {
6293 if (hairpin_flow > MLX5_MAX_SPLIT_ACTIONS) {
6295 goto error_before_hairpin_split;
6297 flow_hairpin_split(dev, actions, actions_rx.actions,
6298 actions_hairpin_tx.actions, items_tx.items,
6300 p_actions_rx = actions_rx.actions;
6302 flow_split_info.flow_idx = idx;
6303 flow->drv_type = flow_get_drv_type(dev, attr);
6304 MLX5_ASSERT(flow->drv_type > MLX5_FLOW_TYPE_MIN &&
6305 flow->drv_type < MLX5_FLOW_TYPE_MAX);
6306 memset(rss_desc, 0, offsetof(struct mlx5_flow_rss_desc, queue));
6307 /* RSS Action only works on NIC RX domain */
6308 if (attr->ingress && !attr->transfer)
6309 rss = flow_get_rss_action(dev, p_actions_rx);
6311 if (flow_rss_workspace_adjust(wks, rss_desc, rss->queue_num))
6314 * The following information is required by
6315 * mlx5_flow_hashfields_adjust() in advance.
6317 rss_desc->level = rss->level;
6318 /* RSS type 0 indicates default RSS type (ETH_RSS_IP). */
6319 rss_desc->types = !rss->types ? ETH_RSS_IP : rss->types;
6321 flow->dev_handles = 0;
6322 if (rss && rss->types) {
6323 unsigned int graph_root;
6325 graph_root = find_graph_root(items, rss->level);
6326 ret = mlx5_flow_expand_rss(buf, sizeof(expand_buffer.buffer),
6328 mlx5_support_expansion, graph_root);
6329 MLX5_ASSERT(ret > 0 &&
6330 (unsigned int)ret < sizeof(expand_buffer.buffer));
6331 if (rte_log_can_log(mlx5_logtype, RTE_LOG_DEBUG)) {
6332 for (i = 0; i < buf->entries; ++i)
6333 mlx5_dbg__print_pattern(buf->entry[i].pattern);
6337 buf->entry[0].pattern = (void *)(uintptr_t)items;
6339 rss_desc->shared_rss = flow_get_shared_rss_action(dev, indir_actions,
6341 for (i = 0; i < buf->entries; ++i) {
6342 /* Initialize flow split data. */
6343 flow_split_info.prefix_layers = 0;
6344 flow_split_info.prefix_mark = 0;
6345 flow_split_info.skip_scale = 0;
6347 * The splitter may create multiple dev_flows,
6348 * depending on configuration. In the simplest
6349 * case it just creates unmodified original flow.
6351 ret = flow_create_split_outer(dev, flow, attr,
6352 buf->entry[i].pattern,
6353 p_actions_rx, &flow_split_info,
6357 if (is_flow_tunnel_steer_rule(wks->flows[0].tof_type)) {
6358 ret = flow_tunnel_add_default_miss(dev, flow, attr,
6361 wks->flows[0].tunnel,
6365 mlx5_free(default_miss_ctx.queue);
6370 /* Create the tx flow. */
6372 attr_tx.group = MLX5_HAIRPIN_TX_TABLE;
6373 attr_tx.ingress = 0;
6375 dev_flow = flow_drv_prepare(dev, flow, &attr_tx, items_tx.items,
6376 actions_hairpin_tx.actions,
6380 dev_flow->flow = flow;
6381 dev_flow->external = 0;
6382 SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
6383 dev_flow->handle, next);
6384 ret = flow_drv_translate(dev, dev_flow, &attr_tx,
6386 actions_hairpin_tx.actions, error);
6391 * Update the metadata register copy table. If extensive
6392 * metadata feature is enabled and registers are supported
6393 * we might create the extra rte_flow for each unique
6394 * MARK/FLAG action ID.
6396 * The table is updated for ingress Flows only, because
6397 * the egress Flows belong to the different device and
6398 * copy table should be updated in peer NIC Rx domain.
6400 if (attr->ingress &&
6401 (external || attr->group != MLX5_FLOW_MREG_CP_TABLE_GROUP)) {
6402 ret = flow_mreg_update_copy_table(dev, flow, actions, error);
6407 * If the flow is external (from application) OR device is started,
6408 * OR mreg discover, then apply immediately.
6410 if (external || dev->data->dev_started ||
6411 (attr->group == MLX5_FLOW_MREG_CP_TABLE_GROUP &&
6412 attr->priority == MLX5_FLOW_LOWEST_PRIO_INDICATOR)) {
6413 ret = flow_drv_apply(dev, flow, error);
6418 flow_rxq_flags_set(dev, flow);
6419 rte_free(translated_actions);
6420 tunnel = flow_tunnel_from_rule(wks->flows);
6423 flow->tunnel_id = tunnel->tunnel_id;
6424 __atomic_add_fetch(&tunnel->refctn, 1, __ATOMIC_RELAXED);
6425 mlx5_free(default_miss_ctx.queue);
6427 mlx5_flow_pop_thread_workspace();
6431 ret = rte_errno; /* Save rte_errno before cleanup. */
6432 flow_mreg_del_copy_action(dev, flow);
6433 flow_drv_destroy(dev, flow);
6434 if (rss_desc->shared_rss)
6435 __atomic_sub_fetch(&((struct mlx5_shared_action_rss *)
6437 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
6438 rss_desc->shared_rss))->refcnt, 1, __ATOMIC_RELAXED);
6439 mlx5_ipool_free(priv->flows[type], idx);
6440 rte_errno = ret; /* Restore rte_errno. */
6443 mlx5_flow_pop_thread_workspace();
6444 error_before_hairpin_split:
6445 rte_free(translated_actions);
6450 * Create a dedicated flow rule on e-switch table 0 (root table), to direct all
6451 * incoming packets to table 1.
6453 * Other flow rules, requested for group n, will be created in
6454 * e-switch table n+1.
6455 * Jump action to e-switch group n will be created to group n+1.
6457 * Used when working in switchdev mode, to utilise advantages of table 1
6461 * Pointer to Ethernet device.
6464 * Pointer to flow on success, NULL otherwise and rte_errno is set.
6467 mlx5_flow_create_esw_table_zero_flow(struct rte_eth_dev *dev)
6469 const struct rte_flow_attr attr = {
6476 const struct rte_flow_item pattern = {
6477 .type = RTE_FLOW_ITEM_TYPE_END,
6479 struct rte_flow_action_jump jump = {
6482 const struct rte_flow_action actions[] = {
6484 .type = RTE_FLOW_ACTION_TYPE_JUMP,
6488 .type = RTE_FLOW_ACTION_TYPE_END,
6491 struct rte_flow_error error;
6493 return (void *)(uintptr_t)flow_list_create(dev, MLX5_FLOW_TYPE_CTL,
6495 actions, false, &error);
6499 * Validate a flow supported by the NIC.
6501 * @see rte_flow_validate()
6505 mlx5_flow_validate(struct rte_eth_dev *dev,
6506 const struct rte_flow_attr *attr,
6507 const struct rte_flow_item items[],
6508 const struct rte_flow_action original_actions[],
6509 struct rte_flow_error *error)
6512 struct mlx5_translated_action_handle
6513 indir_actions[MLX5_MAX_INDIRECT_ACTIONS];
6514 int indir_actions_n = MLX5_MAX_INDIRECT_ACTIONS;
6515 const struct rte_flow_action *actions;
6516 struct rte_flow_action *translated_actions = NULL;
6517 int ret = flow_action_handles_translate(dev, original_actions,
6520 &translated_actions, error);
6524 actions = translated_actions ? translated_actions : original_actions;
6525 hairpin_flow = flow_check_hairpin_split(dev, attr, actions);
6526 ret = flow_drv_validate(dev, attr, items, actions,
6527 true, hairpin_flow, error);
6528 rte_free(translated_actions);
6535 * @see rte_flow_create()
6539 mlx5_flow_create(struct rte_eth_dev *dev,
6540 const struct rte_flow_attr *attr,
6541 const struct rte_flow_item items[],
6542 const struct rte_flow_action actions[],
6543 struct rte_flow_error *error)
6546 * If the device is not started yet, it is not allowed to created a
6547 * flow from application. PMD default flows and traffic control flows
6550 if (unlikely(!dev->data->dev_started)) {
6551 DRV_LOG(DEBUG, "port %u is not started when "
6552 "inserting a flow", dev->data->port_id);
6553 rte_flow_error_set(error, ENODEV,
6554 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6556 "port not started");
6560 return (void *)(uintptr_t)flow_list_create(dev, MLX5_FLOW_TYPE_GEN,
6561 attr, items, actions,
6566 * Destroy a flow in a list.
6569 * Pointer to Ethernet device.
6570 * @param[in] flow_idx
6571 * Index of flow to destroy.
6574 flow_list_destroy(struct rte_eth_dev *dev, enum mlx5_flow_type type,
6577 struct mlx5_priv *priv = dev->data->dev_private;
6578 struct rte_flow *flow = mlx5_ipool_get(priv->flows[type], flow_idx);
6582 MLX5_ASSERT(flow->type == type);
6584 * Update RX queue flags only if port is started, otherwise it is
6587 if (dev->data->dev_started)
6588 flow_rxq_flags_trim(dev, flow);
6589 flow_drv_destroy(dev, flow);
6591 struct mlx5_flow_tunnel *tunnel;
6593 tunnel = mlx5_find_tunnel_id(dev, flow->tunnel_id);
6595 if (!__atomic_sub_fetch(&tunnel->refctn, 1, __ATOMIC_RELAXED))
6596 mlx5_flow_tunnel_free(dev, tunnel);
6598 flow_mreg_del_copy_action(dev, flow);
6599 mlx5_ipool_free(priv->flows[type], flow_idx);
6603 * Destroy all flows.
6606 * Pointer to Ethernet device.
6608 * Flow type to be flushed.
6610 * If flushing is called avtively.
6613 mlx5_flow_list_flush(struct rte_eth_dev *dev, enum mlx5_flow_type type,
6616 struct mlx5_priv *priv = dev->data->dev_private;
6617 uint32_t num_flushed = 0, fidx = 1;
6618 struct rte_flow *flow;
6620 MLX5_IPOOL_FOREACH(priv->flows[type], fidx, flow) {
6621 flow_list_destroy(dev, type, fidx);
6625 DRV_LOG(INFO, "port %u: %u flows flushed before stopping",
6626 dev->data->port_id, num_flushed);
6631 * Stop all default actions for flows.
6634 * Pointer to Ethernet device.
6637 mlx5_flow_stop_default(struct rte_eth_dev *dev)
6639 flow_mreg_del_default_copy_action(dev);
6640 flow_rxq_flags_clear(dev);
6644 * Start all default actions for flows.
6647 * Pointer to Ethernet device.
6649 * 0 on success, a negative errno value otherwise and rte_errno is set.
6652 mlx5_flow_start_default(struct rte_eth_dev *dev)
6654 struct rte_flow_error error;
6656 /* Make sure default copy action (reg_c[0] -> reg_b) is created. */
6657 return flow_mreg_add_default_copy_action(dev, &error);
6661 * Release key of thread specific flow workspace data.
6664 flow_release_workspace(void *data)
6666 struct mlx5_flow_workspace *wks = data;
6667 struct mlx5_flow_workspace *next;
6671 free(wks->rss_desc.queue);
6678 * Get thread specific current flow workspace.
6680 * @return pointer to thread specific flow workspace data, NULL on error.
6682 struct mlx5_flow_workspace*
6683 mlx5_flow_get_thread_workspace(void)
6685 struct mlx5_flow_workspace *data;
6687 data = mlx5_flow_os_get_specific_workspace();
6688 MLX5_ASSERT(data && data->inuse);
6689 if (!data || !data->inuse)
6690 DRV_LOG(ERR, "flow workspace not initialized.");
6695 * Allocate and init new flow workspace.
6697 * @return pointer to flow workspace data, NULL on error.
6699 static struct mlx5_flow_workspace*
6700 flow_alloc_thread_workspace(void)
6702 struct mlx5_flow_workspace *data = calloc(1, sizeof(*data));
6705 DRV_LOG(ERR, "Failed to allocate flow workspace "
6709 data->rss_desc.queue = calloc(1,
6710 sizeof(uint16_t) * MLX5_RSSQ_DEFAULT_NUM);
6711 if (!data->rss_desc.queue)
6713 data->rssq_num = MLX5_RSSQ_DEFAULT_NUM;
6716 if (data->rss_desc.queue)
6717 free(data->rss_desc.queue);
6723 * Get new thread specific flow workspace.
6725 * If current workspace inuse, create new one and set as current.
6727 * @return pointer to thread specific flow workspace data, NULL on error.
6729 static struct mlx5_flow_workspace*
6730 mlx5_flow_push_thread_workspace(void)
6732 struct mlx5_flow_workspace *curr;
6733 struct mlx5_flow_workspace *data;
6735 curr = mlx5_flow_os_get_specific_workspace();
6737 data = flow_alloc_thread_workspace();
6740 } else if (!curr->inuse) {
6742 } else if (curr->next) {
6745 data = flow_alloc_thread_workspace();
6753 /* Set as current workspace */
6754 if (mlx5_flow_os_set_specific_workspace(data))
6755 DRV_LOG(ERR, "Failed to set flow workspace to thread.");
6760 * Close current thread specific flow workspace.
6762 * If previous workspace available, set it as current.
6764 * @return pointer to thread specific flow workspace data, NULL on error.
6767 mlx5_flow_pop_thread_workspace(void)
6769 struct mlx5_flow_workspace *data = mlx5_flow_get_thread_workspace();
6774 DRV_LOG(ERR, "Failed to close unused flow workspace.");
6780 if (mlx5_flow_os_set_specific_workspace(data->prev))
6781 DRV_LOG(ERR, "Failed to set flow workspace to thread.");
6785 * Verify the flow list is empty
6788 * Pointer to Ethernet device.
6790 * @return the number of flows not released.
6793 mlx5_flow_verify(struct rte_eth_dev *dev __rte_unused)
6795 struct mlx5_priv *priv = dev->data->dev_private;
6796 struct rte_flow *flow;
6800 for (i = 0; i < MLX5_FLOW_TYPE_MAXI; i++) {
6801 MLX5_IPOOL_FOREACH(priv->flows[i], idx, flow) {
6802 DRV_LOG(DEBUG, "port %u flow %p still referenced",
6803 dev->data->port_id, (void *)flow);
6811 * Enable default hairpin egress flow.
6814 * Pointer to Ethernet device.
6819 * 0 on success, a negative errno value otherwise and rte_errno is set.
6822 mlx5_ctrl_flow_source_queue(struct rte_eth_dev *dev,
6825 const struct rte_flow_attr attr = {
6829 struct mlx5_rte_flow_item_tx_queue queue_spec = {
6832 struct mlx5_rte_flow_item_tx_queue queue_mask = {
6833 .queue = UINT32_MAX,
6835 struct rte_flow_item items[] = {
6837 .type = (enum rte_flow_item_type)
6838 MLX5_RTE_FLOW_ITEM_TYPE_TX_QUEUE,
6839 .spec = &queue_spec,
6841 .mask = &queue_mask,
6844 .type = RTE_FLOW_ITEM_TYPE_END,
6847 struct rte_flow_action_jump jump = {
6848 .group = MLX5_HAIRPIN_TX_TABLE,
6850 struct rte_flow_action actions[2];
6852 struct rte_flow_error error;
6854 actions[0].type = RTE_FLOW_ACTION_TYPE_JUMP;
6855 actions[0].conf = &jump;
6856 actions[1].type = RTE_FLOW_ACTION_TYPE_END;
6857 flow_idx = flow_list_create(dev, MLX5_FLOW_TYPE_CTL,
6858 &attr, items, actions, false, &error);
6861 "Failed to create ctrl flow: rte_errno(%d),"
6862 " type(%d), message(%s)",
6863 rte_errno, error.type,
6864 error.message ? error.message : " (no stated reason)");
6871 * Enable a control flow configured from the control plane.
6874 * Pointer to Ethernet device.
6876 * An Ethernet flow spec to apply.
6878 * An Ethernet flow mask to apply.
6880 * A VLAN flow spec to apply.
6882 * A VLAN flow mask to apply.
6885 * 0 on success, a negative errno value otherwise and rte_errno is set.
6888 mlx5_ctrl_flow_vlan(struct rte_eth_dev *dev,
6889 struct rte_flow_item_eth *eth_spec,
6890 struct rte_flow_item_eth *eth_mask,
6891 struct rte_flow_item_vlan *vlan_spec,
6892 struct rte_flow_item_vlan *vlan_mask)
6894 struct mlx5_priv *priv = dev->data->dev_private;
6895 const struct rte_flow_attr attr = {
6897 .priority = MLX5_FLOW_LOWEST_PRIO_INDICATOR,
6899 struct rte_flow_item items[] = {
6901 .type = RTE_FLOW_ITEM_TYPE_ETH,
6907 .type = (vlan_spec) ? RTE_FLOW_ITEM_TYPE_VLAN :
6908 RTE_FLOW_ITEM_TYPE_END,
6914 .type = RTE_FLOW_ITEM_TYPE_END,
6917 uint16_t queue[priv->reta_idx_n];
6918 struct rte_flow_action_rss action_rss = {
6919 .func = RTE_ETH_HASH_FUNCTION_DEFAULT,
6921 .types = priv->rss_conf.rss_hf,
6922 .key_len = priv->rss_conf.rss_key_len,
6923 .queue_num = priv->reta_idx_n,
6924 .key = priv->rss_conf.rss_key,
6927 struct rte_flow_action actions[] = {
6929 .type = RTE_FLOW_ACTION_TYPE_RSS,
6930 .conf = &action_rss,
6933 .type = RTE_FLOW_ACTION_TYPE_END,
6937 struct rte_flow_error error;
6940 if (!priv->reta_idx_n || !priv->rxqs_n) {
6943 if (!(dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG))
6944 action_rss.types = 0;
6945 for (i = 0; i != priv->reta_idx_n; ++i)
6946 queue[i] = (*priv->reta_idx)[i];
6947 flow_idx = flow_list_create(dev, MLX5_FLOW_TYPE_CTL,
6948 &attr, items, actions, false, &error);
6955 * Enable a flow control configured from the control plane.
6958 * Pointer to Ethernet device.
6960 * An Ethernet flow spec to apply.
6962 * An Ethernet flow mask to apply.
6965 * 0 on success, a negative errno value otherwise and rte_errno is set.
6968 mlx5_ctrl_flow(struct rte_eth_dev *dev,
6969 struct rte_flow_item_eth *eth_spec,
6970 struct rte_flow_item_eth *eth_mask)
6972 return mlx5_ctrl_flow_vlan(dev, eth_spec, eth_mask, NULL, NULL);
6976 * Create default miss flow rule matching lacp traffic
6979 * Pointer to Ethernet device.
6981 * An Ethernet flow spec to apply.
6984 * 0 on success, a negative errno value otherwise and rte_errno is set.
6987 mlx5_flow_lacp_miss(struct rte_eth_dev *dev)
6990 * The LACP matching is done by only using ether type since using
6991 * a multicast dst mac causes kernel to give low priority to this flow.
6993 static const struct rte_flow_item_eth lacp_spec = {
6994 .type = RTE_BE16(0x8809),
6996 static const struct rte_flow_item_eth lacp_mask = {
6999 const struct rte_flow_attr attr = {
7002 struct rte_flow_item items[] = {
7004 .type = RTE_FLOW_ITEM_TYPE_ETH,
7009 .type = RTE_FLOW_ITEM_TYPE_END,
7012 struct rte_flow_action actions[] = {
7014 .type = (enum rte_flow_action_type)
7015 MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS,
7018 .type = RTE_FLOW_ACTION_TYPE_END,
7021 struct rte_flow_error error;
7022 uint32_t flow_idx = flow_list_create(dev, MLX5_FLOW_TYPE_CTL,
7023 &attr, items, actions,
7034 * @see rte_flow_destroy()
7038 mlx5_flow_destroy(struct rte_eth_dev *dev,
7039 struct rte_flow *flow,
7040 struct rte_flow_error *error __rte_unused)
7042 flow_list_destroy(dev, MLX5_FLOW_TYPE_GEN,
7043 (uintptr_t)(void *)flow);
7048 * Destroy all flows.
7050 * @see rte_flow_flush()
7054 mlx5_flow_flush(struct rte_eth_dev *dev,
7055 struct rte_flow_error *error __rte_unused)
7057 mlx5_flow_list_flush(dev, MLX5_FLOW_TYPE_GEN, false);
7064 * @see rte_flow_isolate()
7068 mlx5_flow_isolate(struct rte_eth_dev *dev,
7070 struct rte_flow_error *error)
7072 struct mlx5_priv *priv = dev->data->dev_private;
7074 if (dev->data->dev_started) {
7075 rte_flow_error_set(error, EBUSY,
7076 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7078 "port must be stopped first");
7081 priv->isolated = !!enable;
7083 dev->dev_ops = &mlx5_dev_ops_isolate;
7085 dev->dev_ops = &mlx5_dev_ops;
7087 dev->rx_descriptor_status = mlx5_rx_descriptor_status;
7088 dev->tx_descriptor_status = mlx5_tx_descriptor_status;
7096 * @see rte_flow_query()
7100 flow_drv_query(struct rte_eth_dev *dev,
7102 const struct rte_flow_action *actions,
7104 struct rte_flow_error *error)
7106 struct mlx5_priv *priv = dev->data->dev_private;
7107 const struct mlx5_flow_driver_ops *fops;
7108 struct rte_flow *flow = mlx5_ipool_get(priv->flows[MLX5_FLOW_TYPE_GEN],
7110 enum mlx5_flow_drv_type ftype;
7113 return rte_flow_error_set(error, ENOENT,
7114 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7116 "invalid flow handle");
7118 ftype = flow->drv_type;
7119 MLX5_ASSERT(ftype > MLX5_FLOW_TYPE_MIN && ftype < MLX5_FLOW_TYPE_MAX);
7120 fops = flow_get_drv_ops(ftype);
7122 return fops->query(dev, flow, actions, data, error);
7128 * @see rte_flow_query()
7132 mlx5_flow_query(struct rte_eth_dev *dev,
7133 struct rte_flow *flow,
7134 const struct rte_flow_action *actions,
7136 struct rte_flow_error *error)
7140 ret = flow_drv_query(dev, (uintptr_t)(void *)flow, actions, data,
7148 * Get rte_flow callbacks.
7151 * Pointer to Ethernet device structure.
7153 * Pointer to operation-specific structure.
7158 mlx5_flow_ops_get(struct rte_eth_dev *dev __rte_unused,
7159 const struct rte_flow_ops **ops)
7161 *ops = &mlx5_flow_ops;
7166 * Validate meter policy actions.
7167 * Dispatcher for action type specific validation.
7170 * Pointer to the Ethernet device structure.
7172 * The meter policy action object to validate.
7174 * Attributes of flow to determine steering domain.
7175 * @param[out] is_rss
7177 * @param[out] domain_bitmap
7179 * @param[out] is_def_policy
7180 * Is default policy or not.
7182 * Perform verbose error reporting if not NULL. Initialized in case of
7186 * 0 on success, otherwise negative errno value.
7189 mlx5_flow_validate_mtr_acts(struct rte_eth_dev *dev,
7190 const struct rte_flow_action *actions[RTE_COLORS],
7191 struct rte_flow_attr *attr,
7193 uint8_t *domain_bitmap,
7194 bool *is_def_policy,
7195 struct rte_mtr_error *error)
7197 const struct mlx5_flow_driver_ops *fops;
7199 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7200 return fops->validate_mtr_acts(dev, actions, attr,
7201 is_rss, domain_bitmap, is_def_policy, error);
7205 * Destroy the meter table set.
7208 * Pointer to Ethernet device.
7209 * @param[in] mtr_policy
7210 * Meter policy struct.
7213 mlx5_flow_destroy_mtr_acts(struct rte_eth_dev *dev,
7214 struct mlx5_flow_meter_policy *mtr_policy)
7216 const struct mlx5_flow_driver_ops *fops;
7218 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7219 fops->destroy_mtr_acts(dev, mtr_policy);
7223 * Create policy action, lock free,
7224 * (mutex should be acquired by caller).
7225 * Dispatcher for action type specific call.
7228 * Pointer to the Ethernet device structure.
7229 * @param[in] mtr_policy
7230 * Meter policy struct.
7232 * Action specification used to create meter actions.
7234 * Perform verbose error reporting if not NULL. Initialized in case of
7238 * 0 on success, otherwise negative errno value.
7241 mlx5_flow_create_mtr_acts(struct rte_eth_dev *dev,
7242 struct mlx5_flow_meter_policy *mtr_policy,
7243 const struct rte_flow_action *actions[RTE_COLORS],
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->create_mtr_acts(dev, mtr_policy, actions, error);
7253 * Create policy rules, lock free,
7254 * (mutex should be acquired by caller).
7255 * Dispatcher for action type specific call.
7258 * Pointer to the Ethernet device structure.
7259 * @param[in] mtr_policy
7260 * Meter policy struct.
7263 * 0 on success, -1 otherwise.
7266 mlx5_flow_create_policy_rules(struct rte_eth_dev *dev,
7267 struct mlx5_flow_meter_policy *mtr_policy)
7269 const struct mlx5_flow_driver_ops *fops;
7271 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7272 return fops->create_policy_rules(dev, mtr_policy);
7276 * Destroy policy rules, lock free,
7277 * (mutex should be acquired by caller).
7278 * Dispatcher for action type specific call.
7281 * Pointer to the Ethernet device structure.
7282 * @param[in] mtr_policy
7283 * Meter policy struct.
7286 mlx5_flow_destroy_policy_rules(struct rte_eth_dev *dev,
7287 struct mlx5_flow_meter_policy *mtr_policy)
7289 const struct mlx5_flow_driver_ops *fops;
7291 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7292 fops->destroy_policy_rules(dev, mtr_policy);
7296 * Destroy the default policy table set.
7299 * Pointer to Ethernet device.
7302 mlx5_flow_destroy_def_policy(struct rte_eth_dev *dev)
7304 const struct mlx5_flow_driver_ops *fops;
7306 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7307 fops->destroy_def_policy(dev);
7311 * Destroy the default policy table set.
7314 * Pointer to Ethernet device.
7317 * 0 on success, -1 otherwise.
7320 mlx5_flow_create_def_policy(struct rte_eth_dev *dev)
7322 const struct mlx5_flow_driver_ops *fops;
7324 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7325 return fops->create_def_policy(dev);
7329 * Create the needed meter and suffix tables.
7332 * Pointer to Ethernet device.
7335 * 0 on success, -1 otherwise.
7338 mlx5_flow_create_mtr_tbls(struct rte_eth_dev *dev,
7339 struct mlx5_flow_meter_info *fm,
7341 uint8_t domain_bitmap)
7343 const struct mlx5_flow_driver_ops *fops;
7345 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7346 return fops->create_mtr_tbls(dev, fm, mtr_idx, domain_bitmap);
7350 * Destroy the meter table set.
7353 * Pointer to Ethernet device.
7355 * Pointer to the meter table set.
7358 mlx5_flow_destroy_mtr_tbls(struct rte_eth_dev *dev,
7359 struct mlx5_flow_meter_info *fm)
7361 const struct mlx5_flow_driver_ops *fops;
7363 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7364 fops->destroy_mtr_tbls(dev, fm);
7368 * Destroy the global meter drop table.
7371 * Pointer to Ethernet device.
7374 mlx5_flow_destroy_mtr_drop_tbls(struct rte_eth_dev *dev)
7376 const struct mlx5_flow_driver_ops *fops;
7378 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7379 fops->destroy_mtr_drop_tbls(dev);
7383 * Destroy the sub policy table with RX queue.
7386 * Pointer to Ethernet device.
7387 * @param[in] mtr_policy
7388 * Pointer to meter policy table.
7391 mlx5_flow_destroy_sub_policy_with_rxq(struct rte_eth_dev *dev,
7392 struct mlx5_flow_meter_policy *mtr_policy)
7394 const struct mlx5_flow_driver_ops *fops;
7396 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7397 fops->destroy_sub_policy_with_rxq(dev, mtr_policy);
7401 * Allocate the needed aso flow meter id.
7404 * Pointer to Ethernet device.
7407 * Index to aso flow meter on success, NULL otherwise.
7410 mlx5_flow_mtr_alloc(struct rte_eth_dev *dev)
7412 const struct mlx5_flow_driver_ops *fops;
7414 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7415 return fops->create_meter(dev);
7419 * Free the aso flow meter id.
7422 * Pointer to Ethernet device.
7423 * @param[in] mtr_idx
7424 * Index to aso flow meter to be free.
7430 mlx5_flow_mtr_free(struct rte_eth_dev *dev, uint32_t mtr_idx)
7432 const struct mlx5_flow_driver_ops *fops;
7434 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7435 fops->free_meter(dev, mtr_idx);
7439 * Allocate a counter.
7442 * Pointer to Ethernet device structure.
7445 * Index to allocated counter on success, 0 otherwise.
7448 mlx5_counter_alloc(struct rte_eth_dev *dev)
7450 const struct mlx5_flow_driver_ops *fops;
7451 struct rte_flow_attr attr = { .transfer = 0 };
7453 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
7454 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7455 return fops->counter_alloc(dev);
7458 "port %u counter allocate is not supported.",
7459 dev->data->port_id);
7467 * Pointer to Ethernet device structure.
7469 * Index to counter to be free.
7472 mlx5_counter_free(struct rte_eth_dev *dev, uint32_t cnt)
7474 const struct mlx5_flow_driver_ops *fops;
7475 struct rte_flow_attr attr = { .transfer = 0 };
7477 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
7478 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7479 fops->counter_free(dev, cnt);
7483 "port %u counter free is not supported.",
7484 dev->data->port_id);
7488 * Query counter statistics.
7491 * Pointer to Ethernet device structure.
7493 * Index to counter to query.
7495 * Set to clear counter statistics.
7497 * The counter hits packets number to save.
7499 * The counter hits bytes number to save.
7502 * 0 on success, a negative errno value otherwise.
7505 mlx5_counter_query(struct rte_eth_dev *dev, uint32_t cnt,
7506 bool clear, uint64_t *pkts, uint64_t *bytes)
7508 const struct mlx5_flow_driver_ops *fops;
7509 struct rte_flow_attr attr = { .transfer = 0 };
7511 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
7512 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7513 return fops->counter_query(dev, cnt, clear, pkts, bytes);
7516 "port %u counter query is not supported.",
7517 dev->data->port_id);
7522 * Allocate a new memory for the counter values wrapped by all the needed
7526 * Pointer to mlx5_dev_ctx_shared object.
7529 * 0 on success, a negative errno value otherwise.
7532 mlx5_flow_create_counter_stat_mem_mng(struct mlx5_dev_ctx_shared *sh)
7534 struct mlx5_devx_mkey_attr mkey_attr;
7535 struct mlx5_counter_stats_mem_mng *mem_mng;
7536 volatile struct flow_counter_stats *raw_data;
7537 int raws_n = MLX5_CNT_CONTAINER_RESIZE + MLX5_MAX_PENDING_QUERIES;
7538 int size = (sizeof(struct flow_counter_stats) *
7539 MLX5_COUNTERS_PER_POOL +
7540 sizeof(struct mlx5_counter_stats_raw)) * raws_n +
7541 sizeof(struct mlx5_counter_stats_mem_mng);
7542 size_t pgsize = rte_mem_page_size();
7546 if (pgsize == (size_t)-1) {
7547 DRV_LOG(ERR, "Failed to get mem page size");
7551 mem = mlx5_malloc(MLX5_MEM_ZERO, size, pgsize, SOCKET_ID_ANY);
7556 mem_mng = (struct mlx5_counter_stats_mem_mng *)(mem + size) - 1;
7557 size = sizeof(*raw_data) * MLX5_COUNTERS_PER_POOL * raws_n;
7558 mem_mng->umem = mlx5_os_umem_reg(sh->ctx, mem, size,
7559 IBV_ACCESS_LOCAL_WRITE);
7560 if (!mem_mng->umem) {
7565 memset(&mkey_attr, 0, sizeof(mkey_attr));
7566 mkey_attr.addr = (uintptr_t)mem;
7567 mkey_attr.size = size;
7568 mkey_attr.umem_id = mlx5_os_get_umem_id(mem_mng->umem);
7569 mkey_attr.pd = sh->pdn;
7570 mkey_attr.relaxed_ordering_write = sh->cmng.relaxed_ordering_write;
7571 mkey_attr.relaxed_ordering_read = sh->cmng.relaxed_ordering_read;
7572 mem_mng->dm = mlx5_devx_cmd_mkey_create(sh->ctx, &mkey_attr);
7574 mlx5_os_umem_dereg(mem_mng->umem);
7579 mem_mng->raws = (struct mlx5_counter_stats_raw *)(mem + size);
7580 raw_data = (volatile struct flow_counter_stats *)mem;
7581 for (i = 0; i < raws_n; ++i) {
7582 mem_mng->raws[i].mem_mng = mem_mng;
7583 mem_mng->raws[i].data = raw_data + i * MLX5_COUNTERS_PER_POOL;
7585 for (i = 0; i < MLX5_MAX_PENDING_QUERIES; ++i)
7586 LIST_INSERT_HEAD(&sh->cmng.free_stat_raws,
7587 mem_mng->raws + MLX5_CNT_CONTAINER_RESIZE + i,
7589 LIST_INSERT_HEAD(&sh->cmng.mem_mngs, mem_mng, next);
7590 sh->cmng.mem_mng = mem_mng;
7595 * Set the statistic memory to the new counter pool.
7598 * Pointer to mlx5_dev_ctx_shared object.
7600 * Pointer to the pool to set the statistic memory.
7603 * 0 on success, a negative errno value otherwise.
7606 mlx5_flow_set_counter_stat_mem(struct mlx5_dev_ctx_shared *sh,
7607 struct mlx5_flow_counter_pool *pool)
7609 struct mlx5_flow_counter_mng *cmng = &sh->cmng;
7610 /* Resize statistic memory once used out. */
7611 if (!(pool->index % MLX5_CNT_CONTAINER_RESIZE) &&
7612 mlx5_flow_create_counter_stat_mem_mng(sh)) {
7613 DRV_LOG(ERR, "Cannot resize counter stat mem.");
7616 rte_spinlock_lock(&pool->sl);
7617 pool->raw = cmng->mem_mng->raws + pool->index %
7618 MLX5_CNT_CONTAINER_RESIZE;
7619 rte_spinlock_unlock(&pool->sl);
7620 pool->raw_hw = NULL;
7624 #define MLX5_POOL_QUERY_FREQ_US 1000000
7627 * Set the periodic procedure for triggering asynchronous batch queries for all
7628 * the counter pools.
7631 * Pointer to mlx5_dev_ctx_shared object.
7634 mlx5_set_query_alarm(struct mlx5_dev_ctx_shared *sh)
7636 uint32_t pools_n, us;
7638 pools_n = __atomic_load_n(&sh->cmng.n_valid, __ATOMIC_RELAXED);
7639 us = MLX5_POOL_QUERY_FREQ_US / pools_n;
7640 DRV_LOG(DEBUG, "Set alarm for %u pools each %u us", pools_n, us);
7641 if (rte_eal_alarm_set(us, mlx5_flow_query_alarm, sh)) {
7642 sh->cmng.query_thread_on = 0;
7643 DRV_LOG(ERR, "Cannot reinitialize query alarm");
7645 sh->cmng.query_thread_on = 1;
7650 * The periodic procedure for triggering asynchronous batch queries for all the
7651 * counter pools. This function is probably called by the host thread.
7654 * The parameter for the alarm process.
7657 mlx5_flow_query_alarm(void *arg)
7659 struct mlx5_dev_ctx_shared *sh = arg;
7661 uint16_t pool_index = sh->cmng.pool_index;
7662 struct mlx5_flow_counter_mng *cmng = &sh->cmng;
7663 struct mlx5_flow_counter_pool *pool;
7666 if (sh->cmng.pending_queries >= MLX5_MAX_PENDING_QUERIES)
7668 rte_spinlock_lock(&cmng->pool_update_sl);
7669 pool = cmng->pools[pool_index];
7670 n_valid = cmng->n_valid;
7671 rte_spinlock_unlock(&cmng->pool_update_sl);
7672 /* Set the statistic memory to the new created pool. */
7673 if ((!pool->raw && mlx5_flow_set_counter_stat_mem(sh, pool)))
7676 /* There is a pool query in progress. */
7679 LIST_FIRST(&sh->cmng.free_stat_raws);
7681 /* No free counter statistics raw memory. */
7684 * Identify the counters released between query trigger and query
7685 * handle more efficiently. The counter released in this gap period
7686 * should wait for a new round of query as the new arrived packets
7687 * will not be taken into account.
7690 ret = mlx5_devx_cmd_flow_counter_query(pool->min_dcs, 0,
7691 MLX5_COUNTERS_PER_POOL,
7693 pool->raw_hw->mem_mng->dm->id,
7697 (uint64_t)(uintptr_t)pool);
7699 DRV_LOG(ERR, "Failed to trigger asynchronous query for dcs ID"
7700 " %d", pool->min_dcs->id);
7701 pool->raw_hw = NULL;
7704 LIST_REMOVE(pool->raw_hw, next);
7705 sh->cmng.pending_queries++;
7707 if (pool_index >= n_valid)
7710 sh->cmng.pool_index = pool_index;
7711 mlx5_set_query_alarm(sh);
7715 * Check and callback event for new aged flow in the counter pool
7718 * Pointer to mlx5_dev_ctx_shared object.
7720 * Pointer to Current counter pool.
7723 mlx5_flow_aging_check(struct mlx5_dev_ctx_shared *sh,
7724 struct mlx5_flow_counter_pool *pool)
7726 struct mlx5_priv *priv;
7727 struct mlx5_flow_counter *cnt;
7728 struct mlx5_age_info *age_info;
7729 struct mlx5_age_param *age_param;
7730 struct mlx5_counter_stats_raw *cur = pool->raw_hw;
7731 struct mlx5_counter_stats_raw *prev = pool->raw;
7732 const uint64_t curr_time = MLX5_CURR_TIME_SEC;
7733 const uint32_t time_delta = curr_time - pool->time_of_last_age_check;
7734 uint16_t expected = AGE_CANDIDATE;
7737 pool->time_of_last_age_check = curr_time;
7738 for (i = 0; i < MLX5_COUNTERS_PER_POOL; ++i) {
7739 cnt = MLX5_POOL_GET_CNT(pool, i);
7740 age_param = MLX5_CNT_TO_AGE(cnt);
7741 if (__atomic_load_n(&age_param->state,
7742 __ATOMIC_RELAXED) != AGE_CANDIDATE)
7744 if (cur->data[i].hits != prev->data[i].hits) {
7745 __atomic_store_n(&age_param->sec_since_last_hit, 0,
7749 if (__atomic_add_fetch(&age_param->sec_since_last_hit,
7751 __ATOMIC_RELAXED) <= age_param->timeout)
7754 * Hold the lock first, or if between the
7755 * state AGE_TMOUT and tailq operation the
7756 * release happened, the release procedure
7757 * may delete a non-existent tailq node.
7759 priv = rte_eth_devices[age_param->port_id].data->dev_private;
7760 age_info = GET_PORT_AGE_INFO(priv);
7761 rte_spinlock_lock(&age_info->aged_sl);
7762 if (__atomic_compare_exchange_n(&age_param->state, &expected,
7765 __ATOMIC_RELAXED)) {
7766 TAILQ_INSERT_TAIL(&age_info->aged_counters, cnt, next);
7767 MLX5_AGE_SET(age_info, MLX5_AGE_EVENT_NEW);
7769 rte_spinlock_unlock(&age_info->aged_sl);
7771 mlx5_age_event_prepare(sh);
7775 * Handler for the HW respond about ready values from an asynchronous batch
7776 * query. This function is probably called by the host thread.
7779 * The pointer to the shared device context.
7780 * @param[in] async_id
7781 * The Devx async ID.
7783 * The status of the completion.
7786 mlx5_flow_async_pool_query_handle(struct mlx5_dev_ctx_shared *sh,
7787 uint64_t async_id, int status)
7789 struct mlx5_flow_counter_pool *pool =
7790 (struct mlx5_flow_counter_pool *)(uintptr_t)async_id;
7791 struct mlx5_counter_stats_raw *raw_to_free;
7792 uint8_t query_gen = pool->query_gen ^ 1;
7793 struct mlx5_flow_counter_mng *cmng = &sh->cmng;
7794 enum mlx5_counter_type cnt_type =
7795 pool->is_aged ? MLX5_COUNTER_TYPE_AGE :
7796 MLX5_COUNTER_TYPE_ORIGIN;
7798 if (unlikely(status)) {
7799 raw_to_free = pool->raw_hw;
7801 raw_to_free = pool->raw;
7803 mlx5_flow_aging_check(sh, pool);
7804 rte_spinlock_lock(&pool->sl);
7805 pool->raw = pool->raw_hw;
7806 rte_spinlock_unlock(&pool->sl);
7807 /* Be sure the new raw counters data is updated in memory. */
7809 if (!TAILQ_EMPTY(&pool->counters[query_gen])) {
7810 rte_spinlock_lock(&cmng->csl[cnt_type]);
7811 TAILQ_CONCAT(&cmng->counters[cnt_type],
7812 &pool->counters[query_gen], next);
7813 rte_spinlock_unlock(&cmng->csl[cnt_type]);
7816 LIST_INSERT_HEAD(&sh->cmng.free_stat_raws, raw_to_free, next);
7817 pool->raw_hw = NULL;
7818 sh->cmng.pending_queries--;
7822 flow_group_to_table(uint32_t port_id, uint32_t group, uint32_t *table,
7823 const struct flow_grp_info *grp_info,
7824 struct rte_flow_error *error)
7826 if (grp_info->transfer && grp_info->external &&
7827 grp_info->fdb_def_rule) {
7828 if (group == UINT32_MAX)
7829 return rte_flow_error_set
7831 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
7833 "group index not supported");
7838 DRV_LOG(DEBUG, "port %u group=%#x table=%#x", port_id, group, *table);
7843 * Translate the rte_flow group index to HW table value.
7845 * If tunnel offload is disabled, all group ids converted to flow table
7846 * id using the standard method.
7847 * If tunnel offload is enabled, group id can be converted using the
7848 * standard or tunnel conversion method. Group conversion method
7849 * selection depends on flags in `grp_info` parameter:
7850 * - Internal (grp_info.external == 0) groups conversion uses the
7852 * - Group ids in JUMP action converted with the tunnel conversion.
7853 * - Group id in rule attribute conversion depends on a rule type and
7855 * ** non zero group attributes converted with the tunnel method
7856 * ** zero group attribute in non-tunnel rule is converted using the
7857 * standard method - there's only one root table
7858 * ** zero group attribute in steer tunnel rule is converted with the
7859 * standard method - single root table
7860 * ** zero group attribute in match tunnel rule is a special OvS
7861 * case: that value is used for portability reasons. That group
7862 * id is converted with the tunnel conversion method.
7867 * PMD tunnel offload object
7869 * rte_flow group index value.
7872 * @param[in] grp_info
7873 * flags used for conversion
7875 * Pointer to error structure.
7878 * 0 on success, a negative errno value otherwise and rte_errno is set.
7881 mlx5_flow_group_to_table(struct rte_eth_dev *dev,
7882 const struct mlx5_flow_tunnel *tunnel,
7883 uint32_t group, uint32_t *table,
7884 const struct flow_grp_info *grp_info,
7885 struct rte_flow_error *error)
7888 bool standard_translation;
7890 if (!grp_info->skip_scale && grp_info->external &&
7891 group < MLX5_MAX_TABLES_EXTERNAL)
7892 group *= MLX5_FLOW_TABLE_FACTOR;
7893 if (is_tunnel_offload_active(dev)) {
7894 standard_translation = !grp_info->external ||
7895 grp_info->std_tbl_fix;
7897 standard_translation = true;
7900 "port %u group=%u transfer=%d external=%d fdb_def_rule=%d translate=%s",
7901 dev->data->port_id, group, grp_info->transfer,
7902 grp_info->external, grp_info->fdb_def_rule,
7903 standard_translation ? "STANDARD" : "TUNNEL");
7904 if (standard_translation)
7905 ret = flow_group_to_table(dev->data->port_id, group, table,
7908 ret = tunnel_flow_group_to_flow_table(dev, tunnel, group,
7915 * Discover availability of metadata reg_c's.
7917 * Iteratively use test flows to check availability.
7920 * Pointer to the Ethernet device structure.
7923 * 0 on success, a negative errno value otherwise and rte_errno is set.
7926 mlx5_flow_discover_mreg_c(struct rte_eth_dev *dev)
7928 struct mlx5_priv *priv = dev->data->dev_private;
7929 struct mlx5_dev_config *config = &priv->config;
7930 enum modify_reg idx;
7933 /* reg_c[0] and reg_c[1] are reserved. */
7934 config->flow_mreg_c[n++] = REG_C_0;
7935 config->flow_mreg_c[n++] = REG_C_1;
7936 /* Discover availability of other reg_c's. */
7937 for (idx = REG_C_2; idx <= REG_C_7; ++idx) {
7938 struct rte_flow_attr attr = {
7939 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
7940 .priority = MLX5_FLOW_LOWEST_PRIO_INDICATOR,
7943 struct rte_flow_item items[] = {
7945 .type = RTE_FLOW_ITEM_TYPE_END,
7948 struct rte_flow_action actions[] = {
7950 .type = (enum rte_flow_action_type)
7951 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
7952 .conf = &(struct mlx5_flow_action_copy_mreg){
7958 .type = RTE_FLOW_ACTION_TYPE_JUMP,
7959 .conf = &(struct rte_flow_action_jump){
7960 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
7964 .type = RTE_FLOW_ACTION_TYPE_END,
7968 struct rte_flow *flow;
7969 struct rte_flow_error error;
7971 if (!config->dv_flow_en)
7973 /* Create internal flow, validation skips copy action. */
7974 flow_idx = flow_list_create(dev, MLX5_FLOW_TYPE_GEN, &attr,
7975 items, actions, false, &error);
7976 flow = mlx5_ipool_get(priv->flows[MLX5_FLOW_TYPE_GEN],
7980 config->flow_mreg_c[n++] = idx;
7981 flow_list_destroy(dev, MLX5_FLOW_TYPE_GEN, flow_idx);
7983 for (; n < MLX5_MREG_C_NUM; ++n)
7984 config->flow_mreg_c[n] = REG_NON;
7989 save_dump_file(const uint8_t *data, uint32_t size,
7990 uint32_t type, uint32_t id, void *arg, FILE *file)
7992 char line[BUF_SIZE];
7995 uint32_t actions_num;
7996 struct rte_flow_query_count *count;
7998 memset(line, 0, BUF_SIZE);
8000 case DR_DUMP_REC_TYPE_PMD_MODIFY_HDR:
8001 actions_num = *(uint32_t *)(arg);
8002 out += snprintf(line + out, BUF_SIZE - out, "%d,0x%x,%d,",
8003 type, id, actions_num);
8005 case DR_DUMP_REC_TYPE_PMD_PKT_REFORMAT:
8006 out += snprintf(line + out, BUF_SIZE - out, "%d,0x%x,",
8009 case DR_DUMP_REC_TYPE_PMD_COUNTER:
8010 count = (struct rte_flow_query_count *)arg;
8011 fprintf(file, "%d,0x%x,%" PRIu64 ",%" PRIu64 "\n", type,
8012 id, count->hits, count->bytes);
8018 for (k = 0; k < size; k++) {
8019 /* Make sure we do not overrun the line buffer length. */
8020 if (out >= BUF_SIZE - 4) {
8024 out += snprintf(line + out, BUF_SIZE - out, "%02x",
8027 fprintf(file, "%s\n", line);
8032 mlx5_flow_query_counter(struct rte_eth_dev *dev, struct rte_flow *flow,
8033 struct rte_flow_query_count *count, struct rte_flow_error *error)
8035 struct rte_flow_action action[2];
8036 enum mlx5_flow_drv_type ftype;
8037 const struct mlx5_flow_driver_ops *fops;
8040 return rte_flow_error_set(error, ENOENT,
8041 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8043 "invalid flow handle");
8045 action[0].type = RTE_FLOW_ACTION_TYPE_COUNT;
8046 action[1].type = RTE_FLOW_ACTION_TYPE_END;
8047 if (flow->counter) {
8048 memset(count, 0, sizeof(struct rte_flow_query_count));
8049 ftype = (enum mlx5_flow_drv_type)(flow->drv_type);
8050 MLX5_ASSERT(ftype > MLX5_FLOW_TYPE_MIN &&
8051 ftype < MLX5_FLOW_TYPE_MAX);
8052 fops = flow_get_drv_ops(ftype);
8053 return fops->query(dev, flow, action, count, error);
8058 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
8060 * Dump flow ipool data to file
8063 * The pointer to Ethernet device.
8065 * A pointer to a file for output.
8067 * Perform verbose error reporting if not NULL. PMDs initialize this
8068 * structure in case of error only.
8070 * 0 on success, a negative value otherwise.
8073 mlx5_flow_dev_dump_ipool(struct rte_eth_dev *dev,
8074 struct rte_flow *flow, FILE *file,
8075 struct rte_flow_error *error)
8077 struct mlx5_priv *priv = dev->data->dev_private;
8078 struct mlx5_flow_dv_modify_hdr_resource *modify_hdr;
8079 struct mlx5_flow_dv_encap_decap_resource *encap_decap;
8080 uint32_t handle_idx;
8081 struct mlx5_flow_handle *dh;
8082 struct rte_flow_query_count count;
8083 uint32_t actions_num;
8084 const uint8_t *data;
8090 return rte_flow_error_set(error, ENOENT,
8091 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8093 "invalid flow handle");
8095 handle_idx = flow->dev_handles;
8096 while (handle_idx) {
8097 dh = mlx5_ipool_get(priv->sh->ipool
8098 [MLX5_IPOOL_MLX5_FLOW], handle_idx);
8101 handle_idx = dh->next.next;
8102 id = (uint32_t)(uintptr_t)dh->drv_flow;
8105 type = DR_DUMP_REC_TYPE_PMD_COUNTER;
8106 if (!mlx5_flow_query_counter(dev, flow, &count, error))
8107 save_dump_file(NULL, 0, type,
8108 id, (void *)&count, file);
8110 /* Get modify_hdr and encap_decap buf from ipools. */
8112 modify_hdr = dh->dvh.modify_hdr;
8114 if (dh->dvh.rix_encap_decap) {
8115 encap_decap = mlx5_ipool_get(priv->sh->ipool
8116 [MLX5_IPOOL_DECAP_ENCAP],
8117 dh->dvh.rix_encap_decap);
8120 data = (const uint8_t *)modify_hdr->actions;
8121 size = (size_t)(modify_hdr->actions_num) * 8;
8122 actions_num = modify_hdr->actions_num;
8123 type = DR_DUMP_REC_TYPE_PMD_MODIFY_HDR;
8124 save_dump_file(data, size, type, id,
8125 (void *)(&actions_num), file);
8128 data = encap_decap->buf;
8129 size = encap_decap->size;
8130 type = DR_DUMP_REC_TYPE_PMD_PKT_REFORMAT;
8131 save_dump_file(data, size, type,
8140 * Dump flow raw hw data to file
8143 * The pointer to Ethernet device.
8145 * A pointer to a file for output.
8147 * Perform verbose error reporting if not NULL. PMDs initialize this
8148 * structure in case of error only.
8150 * 0 on success, a nagative value otherwise.
8153 mlx5_flow_dev_dump(struct rte_eth_dev *dev, struct rte_flow *flow_idx,
8155 struct rte_flow_error *error __rte_unused)
8157 struct mlx5_priv *priv = dev->data->dev_private;
8158 struct mlx5_dev_ctx_shared *sh = priv->sh;
8159 uint32_t handle_idx;
8161 struct mlx5_flow_handle *dh;
8162 struct rte_flow *flow;
8163 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
8167 if (!priv->config.dv_flow_en) {
8168 if (fputs("device dv flow disabled\n", file) <= 0)
8175 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
8176 MLX5_IPOOL_FOREACH(priv->flows[MLX5_FLOW_TYPE_GEN], idx, flow)
8177 mlx5_flow_dev_dump_ipool(dev, flow, file, error);
8179 return mlx5_devx_cmd_flow_dump(sh->fdb_domain,
8181 sh->tx_domain, file);
8184 flow = mlx5_ipool_get(priv->flows[MLX5_FLOW_TYPE_GEN],
8185 (uintptr_t)(void *)flow_idx);
8189 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
8190 mlx5_flow_dev_dump_ipool(dev, flow, file, error);
8192 handle_idx = flow->dev_handles;
8193 while (handle_idx) {
8194 dh = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
8199 ret = mlx5_devx_cmd_flow_single_dump(dh->drv_flow,
8204 handle_idx = dh->next.next;
8210 * Get aged-out flows.
8213 * Pointer to the Ethernet device structure.
8214 * @param[in] context
8215 * The address of an array of pointers to the aged-out flows contexts.
8216 * @param[in] nb_countexts
8217 * The length of context array pointers.
8219 * Perform verbose error reporting if not NULL. Initialized in case of
8223 * how many contexts get in success, otherwise negative errno value.
8224 * if nb_contexts is 0, return the amount of all aged contexts.
8225 * if nb_contexts is not 0 , return the amount of aged flows reported
8226 * in the context array.
8229 mlx5_flow_get_aged_flows(struct rte_eth_dev *dev, void **contexts,
8230 uint32_t nb_contexts, struct rte_flow_error *error)
8232 const struct mlx5_flow_driver_ops *fops;
8233 struct rte_flow_attr attr = { .transfer = 0 };
8235 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
8236 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
8237 return fops->get_aged_flows(dev, contexts, nb_contexts,
8241 "port %u get aged flows is not supported.",
8242 dev->data->port_id);
8246 /* Wrapper for driver action_validate op callback */
8248 flow_drv_action_validate(struct rte_eth_dev *dev,
8249 const struct rte_flow_indir_action_conf *conf,
8250 const struct rte_flow_action *action,
8251 const struct mlx5_flow_driver_ops *fops,
8252 struct rte_flow_error *error)
8254 static const char err_msg[] = "indirect action validation unsupported";
8256 if (!fops->action_validate) {
8257 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
8258 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
8262 return fops->action_validate(dev, conf, action, error);
8266 * Destroys the shared action by handle.
8269 * Pointer to Ethernet device structure.
8271 * Handle for the indirect action object to be destroyed.
8273 * Perform verbose error reporting if not NULL. PMDs initialize this
8274 * structure in case of error only.
8277 * 0 on success, a negative errno value otherwise and rte_errno is set.
8279 * @note: wrapper for driver action_create op callback.
8282 mlx5_action_handle_destroy(struct rte_eth_dev *dev,
8283 struct rte_flow_action_handle *handle,
8284 struct rte_flow_error *error)
8286 static const char err_msg[] = "indirect action destruction unsupported";
8287 struct rte_flow_attr attr = { .transfer = 0 };
8288 const struct mlx5_flow_driver_ops *fops =
8289 flow_get_drv_ops(flow_get_drv_type(dev, &attr));
8291 if (!fops->action_destroy) {
8292 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
8293 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
8297 return fops->action_destroy(dev, handle, error);
8300 /* Wrapper for driver action_destroy op callback */
8302 flow_drv_action_update(struct rte_eth_dev *dev,
8303 struct rte_flow_action_handle *handle,
8305 const struct mlx5_flow_driver_ops *fops,
8306 struct rte_flow_error *error)
8308 static const char err_msg[] = "indirect action update unsupported";
8310 if (!fops->action_update) {
8311 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
8312 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
8316 return fops->action_update(dev, handle, update, error);
8319 /* Wrapper for driver action_destroy op callback */
8321 flow_drv_action_query(struct rte_eth_dev *dev,
8322 const struct rte_flow_action_handle *handle,
8324 const struct mlx5_flow_driver_ops *fops,
8325 struct rte_flow_error *error)
8327 static const char err_msg[] = "indirect action query unsupported";
8329 if (!fops->action_query) {
8330 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
8331 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
8335 return fops->action_query(dev, handle, data, error);
8339 * Create indirect action for reuse in multiple flow rules.
8342 * Pointer to Ethernet device structure.
8344 * Pointer to indirect action object configuration.
8346 * Action configuration for indirect action object creation.
8348 * Perform verbose error reporting if not NULL. PMDs initialize this
8349 * structure in case of error only.
8351 * A valid handle in case of success, NULL otherwise and rte_errno is set.
8353 static struct rte_flow_action_handle *
8354 mlx5_action_handle_create(struct rte_eth_dev *dev,
8355 const struct rte_flow_indir_action_conf *conf,
8356 const struct rte_flow_action *action,
8357 struct rte_flow_error *error)
8359 static const char err_msg[] = "indirect action creation unsupported";
8360 struct rte_flow_attr attr = { .transfer = 0 };
8361 const struct mlx5_flow_driver_ops *fops =
8362 flow_get_drv_ops(flow_get_drv_type(dev, &attr));
8364 if (flow_drv_action_validate(dev, conf, action, fops, error))
8366 if (!fops->action_create) {
8367 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
8368 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
8372 return fops->action_create(dev, conf, action, error);
8376 * Updates inplace the indirect action configuration pointed by *handle*
8377 * with the configuration provided as *update* argument.
8378 * The update of the indirect action configuration effects all flow rules
8379 * reusing the action via handle.
8382 * Pointer to Ethernet device structure.
8384 * Handle for the indirect action to be updated.
8386 * Action specification used to modify the action pointed by handle.
8387 * *update* could be of same type with the action pointed by the *handle*
8388 * handle argument, or some other structures like a wrapper, depending on
8389 * the indirect action type.
8391 * Perform verbose error reporting if not NULL. PMDs initialize this
8392 * structure in case of error only.
8395 * 0 on success, a negative errno value otherwise and rte_errno is set.
8398 mlx5_action_handle_update(struct rte_eth_dev *dev,
8399 struct rte_flow_action_handle *handle,
8401 struct rte_flow_error *error)
8403 struct rte_flow_attr attr = { .transfer = 0 };
8404 const struct mlx5_flow_driver_ops *fops =
8405 flow_get_drv_ops(flow_get_drv_type(dev, &attr));
8408 ret = flow_drv_action_validate(dev, NULL,
8409 (const struct rte_flow_action *)update, fops, error);
8412 return flow_drv_action_update(dev, handle, update, fops,
8417 * Query the indirect action by handle.
8419 * This function allows retrieving action-specific data such as counters.
8420 * Data is gathered by special action which may be present/referenced in
8421 * more than one flow rule definition.
8423 * see @RTE_FLOW_ACTION_TYPE_COUNT
8426 * Pointer to Ethernet device structure.
8428 * Handle for the indirect action to query.
8429 * @param[in, out] data
8430 * Pointer to storage for the associated query data type.
8432 * Perform verbose error reporting if not NULL. PMDs initialize this
8433 * structure in case of error only.
8436 * 0 on success, a negative errno value otherwise and rte_errno is set.
8439 mlx5_action_handle_query(struct rte_eth_dev *dev,
8440 const struct rte_flow_action_handle *handle,
8442 struct rte_flow_error *error)
8444 struct rte_flow_attr attr = { .transfer = 0 };
8445 const struct mlx5_flow_driver_ops *fops =
8446 flow_get_drv_ops(flow_get_drv_type(dev, &attr));
8448 return flow_drv_action_query(dev, handle, data, fops, error);
8452 * Destroy all indirect actions (shared RSS).
8455 * Pointer to Ethernet device.
8458 * 0 on success, a negative errno value otherwise and rte_errno is set.
8461 mlx5_action_handle_flush(struct rte_eth_dev *dev)
8463 struct rte_flow_error error;
8464 struct mlx5_priv *priv = dev->data->dev_private;
8465 struct mlx5_shared_action_rss *shared_rss;
8469 ILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
8470 priv->rss_shared_actions, idx, shared_rss, next) {
8471 ret |= mlx5_action_handle_destroy(dev,
8472 (struct rte_flow_action_handle *)(uintptr_t)idx, &error);
8477 #ifndef HAVE_MLX5DV_DR
8478 #define MLX5_DOMAIN_SYNC_FLOW ((1 << 0) | (1 << 1))
8480 #define MLX5_DOMAIN_SYNC_FLOW \
8481 (MLX5DV_DR_DOMAIN_SYNC_FLAGS_SW | MLX5DV_DR_DOMAIN_SYNC_FLAGS_HW)
8484 int rte_pmd_mlx5_sync_flow(uint16_t port_id, uint32_t domains)
8486 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
8487 const struct mlx5_flow_driver_ops *fops;
8489 struct rte_flow_attr attr = { .transfer = 0 };
8491 fops = flow_get_drv_ops(flow_get_drv_type(dev, &attr));
8492 ret = fops->sync_domain(dev, domains, MLX5_DOMAIN_SYNC_FLOW);
8498 const struct mlx5_flow_tunnel *
8499 mlx5_get_tof(const struct rte_flow_item *item,
8500 const struct rte_flow_action *action,
8501 enum mlx5_tof_rule_type *rule_type)
8503 for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
8504 if (item->type == (typeof(item->type))
8505 MLX5_RTE_FLOW_ITEM_TYPE_TUNNEL) {
8506 *rule_type = MLX5_TUNNEL_OFFLOAD_MATCH_RULE;
8507 return flow_items_to_tunnel(item);
8510 for (; action->conf != RTE_FLOW_ACTION_TYPE_END; action++) {
8511 if (action->type == (typeof(action->type))
8512 MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET) {
8513 *rule_type = MLX5_TUNNEL_OFFLOAD_SET_RULE;
8514 return flow_actions_to_tunnel(action);
8521 * tunnel offload functionalilty is defined for DV environment only
8523 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
8525 union tunnel_offload_mark {
8528 uint32_t app_reserve:8;
8529 uint32_t table_id:15;
8530 uint32_t transfer:1;
8531 uint32_t _unused_:8;
8536 mlx5_access_tunnel_offload_db
8537 (struct rte_eth_dev *dev,
8538 bool (*match)(struct rte_eth_dev *,
8539 struct mlx5_flow_tunnel *, const void *),
8540 void (*hit)(struct rte_eth_dev *, struct mlx5_flow_tunnel *, void *),
8541 void (*miss)(struct rte_eth_dev *, void *),
8542 void *ctx, bool lock_op);
8545 flow_tunnel_add_default_miss(struct rte_eth_dev *dev,
8546 struct rte_flow *flow,
8547 const struct rte_flow_attr *attr,
8548 const struct rte_flow_action *app_actions,
8550 const struct mlx5_flow_tunnel *tunnel,
8551 struct tunnel_default_miss_ctx *ctx,
8552 struct rte_flow_error *error)
8554 struct mlx5_priv *priv = dev->data->dev_private;
8555 struct mlx5_flow *dev_flow;
8556 struct rte_flow_attr miss_attr = *attr;
8557 const struct rte_flow_item miss_items[2] = {
8559 .type = RTE_FLOW_ITEM_TYPE_ETH,
8565 .type = RTE_FLOW_ITEM_TYPE_END,
8571 union tunnel_offload_mark mark_id;
8572 struct rte_flow_action_mark miss_mark;
8573 struct rte_flow_action miss_actions[3] = {
8574 [0] = { .type = RTE_FLOW_ACTION_TYPE_MARK, .conf = &miss_mark },
8575 [2] = { .type = RTE_FLOW_ACTION_TYPE_END, .conf = NULL }
8577 const struct rte_flow_action_jump *jump_data;
8578 uint32_t i, flow_table = 0; /* prevent compilation warning */
8579 struct flow_grp_info grp_info = {
8581 .transfer = attr->transfer,
8582 .fdb_def_rule = !!priv->fdb_def_rule,
8587 if (!attr->transfer) {
8590 miss_actions[1].type = RTE_FLOW_ACTION_TYPE_RSS;
8591 q_size = priv->reta_idx_n * sizeof(ctx->queue[0]);
8592 ctx->queue = mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO, q_size,
8595 return rte_flow_error_set
8597 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
8598 NULL, "invalid default miss RSS");
8599 ctx->action_rss.func = RTE_ETH_HASH_FUNCTION_DEFAULT,
8600 ctx->action_rss.level = 0,
8601 ctx->action_rss.types = priv->rss_conf.rss_hf,
8602 ctx->action_rss.key_len = priv->rss_conf.rss_key_len,
8603 ctx->action_rss.queue_num = priv->reta_idx_n,
8604 ctx->action_rss.key = priv->rss_conf.rss_key,
8605 ctx->action_rss.queue = ctx->queue;
8606 if (!priv->reta_idx_n || !priv->rxqs_n)
8607 return rte_flow_error_set
8609 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
8610 NULL, "invalid port configuration");
8611 if (!(dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG))
8612 ctx->action_rss.types = 0;
8613 for (i = 0; i != priv->reta_idx_n; ++i)
8614 ctx->queue[i] = (*priv->reta_idx)[i];
8616 miss_actions[1].type = RTE_FLOW_ACTION_TYPE_JUMP;
8617 ctx->miss_jump.group = MLX5_TNL_MISS_FDB_JUMP_GRP;
8619 miss_actions[1].conf = (typeof(miss_actions[1].conf))ctx->raw;
8620 for (; app_actions->type != RTE_FLOW_ACTION_TYPE_JUMP; app_actions++);
8621 jump_data = app_actions->conf;
8622 miss_attr.priority = MLX5_TNL_MISS_RULE_PRIORITY;
8623 miss_attr.group = jump_data->group;
8624 ret = mlx5_flow_group_to_table(dev, tunnel, jump_data->group,
8625 &flow_table, &grp_info, error);
8627 return rte_flow_error_set(error, EINVAL,
8628 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
8629 NULL, "invalid tunnel id");
8630 mark_id.app_reserve = 0;
8631 mark_id.table_id = tunnel_flow_tbl_to_id(flow_table);
8632 mark_id.transfer = !!attr->transfer;
8633 mark_id._unused_ = 0;
8634 miss_mark.id = mark_id.val;
8635 dev_flow = flow_drv_prepare(dev, flow, &miss_attr,
8636 miss_items, miss_actions, flow_idx, error);
8639 dev_flow->flow = flow;
8640 dev_flow->external = true;
8641 dev_flow->tunnel = tunnel;
8642 dev_flow->tof_type = MLX5_TUNNEL_OFFLOAD_MISS_RULE;
8643 /* Subflow object was created, we must include one in the list. */
8644 SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
8645 dev_flow->handle, next);
8647 "port %u tunnel type=%d id=%u miss rule priority=%u group=%u",
8648 dev->data->port_id, tunnel->app_tunnel.type,
8649 tunnel->tunnel_id, miss_attr.priority, miss_attr.group);
8650 ret = flow_drv_translate(dev, dev_flow, &miss_attr, miss_items,
8651 miss_actions, error);
8653 ret = flow_mreg_update_copy_table(dev, flow, miss_actions,
8659 static const struct mlx5_flow_tbl_data_entry *
8660 tunnel_mark_decode(struct rte_eth_dev *dev, uint32_t mark)
8662 struct mlx5_priv *priv = dev->data->dev_private;
8663 struct mlx5_dev_ctx_shared *sh = priv->sh;
8664 struct mlx5_list_entry *he;
8665 union tunnel_offload_mark mbits = { .val = mark };
8666 union mlx5_flow_tbl_key table_key = {
8668 .level = tunnel_id_to_flow_tbl(mbits.table_id),
8672 .is_fdb = !!mbits.transfer,
8676 struct mlx5_flow_cb_ctx ctx = {
8677 .data = &table_key.v64,
8680 he = mlx5_hlist_lookup(sh->flow_tbls, table_key.v64, &ctx);
8682 container_of(he, struct mlx5_flow_tbl_data_entry, entry) : NULL;
8686 mlx5_flow_tunnel_grp2tbl_remove_cb(void *tool_ctx,
8687 struct mlx5_list_entry *entry)
8689 struct mlx5_dev_ctx_shared *sh = tool_ctx;
8690 struct tunnel_tbl_entry *tte = container_of(entry, typeof(*tte), hash);
8692 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TNL_TBL_ID],
8693 tunnel_flow_tbl_to_id(tte->flow_table));
8698 mlx5_flow_tunnel_grp2tbl_match_cb(void *tool_ctx __rte_unused,
8699 struct mlx5_list_entry *entry, void *cb_ctx)
8701 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
8702 union tunnel_tbl_key tbl = {
8703 .val = *(uint64_t *)(ctx->data),
8705 struct tunnel_tbl_entry *tte = container_of(entry, typeof(*tte), hash);
8707 return tbl.tunnel_id != tte->tunnel_id || tbl.group != tte->group;
8710 static struct mlx5_list_entry *
8711 mlx5_flow_tunnel_grp2tbl_create_cb(void *tool_ctx, void *cb_ctx)
8713 struct mlx5_dev_ctx_shared *sh = tool_ctx;
8714 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
8715 struct tunnel_tbl_entry *tte;
8716 union tunnel_tbl_key tbl = {
8717 .val = *(uint64_t *)(ctx->data),
8720 tte = mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO,
8725 mlx5_ipool_malloc(sh->ipool[MLX5_IPOOL_TNL_TBL_ID],
8727 if (tte->flow_table >= MLX5_MAX_TABLES) {
8728 DRV_LOG(ERR, "Tunnel TBL ID %d exceed max limit.",
8730 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TNL_TBL_ID],
8733 } else if (!tte->flow_table) {
8736 tte->flow_table = tunnel_id_to_flow_tbl(tte->flow_table);
8737 tte->tunnel_id = tbl.tunnel_id;
8738 tte->group = tbl.group;
8746 static struct mlx5_list_entry *
8747 mlx5_flow_tunnel_grp2tbl_clone_cb(void *tool_ctx __rte_unused,
8748 struct mlx5_list_entry *oentry,
8749 void *cb_ctx __rte_unused)
8751 struct tunnel_tbl_entry *tte = mlx5_malloc(MLX5_MEM_SYS, sizeof(*tte),
8756 memcpy(tte, oentry, sizeof(*tte));
8761 mlx5_flow_tunnel_grp2tbl_clone_free_cb(void *tool_ctx __rte_unused,
8762 struct mlx5_list_entry *entry)
8764 struct tunnel_tbl_entry *tte = container_of(entry, typeof(*tte), hash);
8770 tunnel_flow_group_to_flow_table(struct rte_eth_dev *dev,
8771 const struct mlx5_flow_tunnel *tunnel,
8772 uint32_t group, uint32_t *table,
8773 struct rte_flow_error *error)
8775 struct mlx5_list_entry *he;
8776 struct tunnel_tbl_entry *tte;
8777 union tunnel_tbl_key key = {
8778 .tunnel_id = tunnel ? tunnel->tunnel_id : 0,
8781 struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
8782 struct mlx5_hlist *group_hash;
8783 struct mlx5_flow_cb_ctx ctx = {
8787 group_hash = tunnel ? tunnel->groups : thub->groups;
8788 he = mlx5_hlist_register(group_hash, key.val, &ctx);
8790 return rte_flow_error_set(error, EINVAL,
8791 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
8793 "tunnel group index not supported");
8794 tte = container_of(he, typeof(*tte), hash);
8795 *table = tte->flow_table;
8796 DRV_LOG(DEBUG, "port %u tunnel %u group=%#x table=%#x",
8797 dev->data->port_id, key.tunnel_id, group, *table);
8802 mlx5_flow_tunnel_free(struct rte_eth_dev *dev,
8803 struct mlx5_flow_tunnel *tunnel)
8805 struct mlx5_priv *priv = dev->data->dev_private;
8806 struct mlx5_indexed_pool *ipool;
8808 DRV_LOG(DEBUG, "port %u release pmd tunnel id=0x%x",
8809 dev->data->port_id, tunnel->tunnel_id);
8810 LIST_REMOVE(tunnel, chain);
8811 mlx5_hlist_destroy(tunnel->groups);
8812 ipool = priv->sh->ipool[MLX5_IPOOL_TUNNEL_ID];
8813 mlx5_ipool_free(ipool, tunnel->tunnel_id);
8817 mlx5_access_tunnel_offload_db
8818 (struct rte_eth_dev *dev,
8819 bool (*match)(struct rte_eth_dev *,
8820 struct mlx5_flow_tunnel *, const void *),
8821 void (*hit)(struct rte_eth_dev *, struct mlx5_flow_tunnel *, void *),
8822 void (*miss)(struct rte_eth_dev *, void *),
8823 void *ctx, bool lock_op)
8825 bool verdict = false;
8826 struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
8827 struct mlx5_flow_tunnel *tunnel;
8829 rte_spinlock_lock(&thub->sl);
8830 LIST_FOREACH(tunnel, &thub->tunnels, chain) {
8831 verdict = match(dev, tunnel, (const void *)ctx);
8836 rte_spinlock_unlock(&thub->sl);
8838 hit(dev, tunnel, ctx);
8839 if (!verdict && miss)
8842 rte_spinlock_unlock(&thub->sl);
8847 struct tunnel_db_find_tunnel_id_ctx {
8849 struct mlx5_flow_tunnel *tunnel;
8853 find_tunnel_id_match(struct rte_eth_dev *dev,
8854 struct mlx5_flow_tunnel *tunnel, const void *x)
8856 const struct tunnel_db_find_tunnel_id_ctx *ctx = x;
8859 return tunnel->tunnel_id == ctx->tunnel_id;
8863 find_tunnel_id_hit(struct rte_eth_dev *dev,
8864 struct mlx5_flow_tunnel *tunnel, void *x)
8866 struct tunnel_db_find_tunnel_id_ctx *ctx = x;
8868 ctx->tunnel = tunnel;
8871 static struct mlx5_flow_tunnel *
8872 mlx5_find_tunnel_id(struct rte_eth_dev *dev, uint32_t id)
8874 struct tunnel_db_find_tunnel_id_ctx ctx = {
8878 mlx5_access_tunnel_offload_db(dev, find_tunnel_id_match,
8879 find_tunnel_id_hit, NULL, &ctx, true);
8884 static struct mlx5_flow_tunnel *
8885 mlx5_flow_tunnel_allocate(struct rte_eth_dev *dev,
8886 const struct rte_flow_tunnel *app_tunnel)
8888 struct mlx5_priv *priv = dev->data->dev_private;
8889 struct mlx5_indexed_pool *ipool;
8890 struct mlx5_flow_tunnel *tunnel;
8893 ipool = priv->sh->ipool[MLX5_IPOOL_TUNNEL_ID];
8894 tunnel = mlx5_ipool_zmalloc(ipool, &id);
8897 if (id >= MLX5_MAX_TUNNELS) {
8898 mlx5_ipool_free(ipool, id);
8899 DRV_LOG(ERR, "Tunnel ID %d exceed max limit.", id);
8902 tunnel->groups = mlx5_hlist_create("tunnel groups", 64, false, true,
8904 mlx5_flow_tunnel_grp2tbl_create_cb,
8905 mlx5_flow_tunnel_grp2tbl_match_cb,
8906 mlx5_flow_tunnel_grp2tbl_remove_cb,
8907 mlx5_flow_tunnel_grp2tbl_clone_cb,
8908 mlx5_flow_tunnel_grp2tbl_clone_free_cb);
8909 if (!tunnel->groups) {
8910 mlx5_ipool_free(ipool, id);
8913 /* initiate new PMD tunnel */
8914 memcpy(&tunnel->app_tunnel, app_tunnel, sizeof(*app_tunnel));
8915 tunnel->tunnel_id = id;
8916 tunnel->action.type = (typeof(tunnel->action.type))
8917 MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET;
8918 tunnel->action.conf = tunnel;
8919 tunnel->item.type = (typeof(tunnel->item.type))
8920 MLX5_RTE_FLOW_ITEM_TYPE_TUNNEL;
8921 tunnel->item.spec = tunnel;
8922 tunnel->item.last = NULL;
8923 tunnel->item.mask = NULL;
8925 DRV_LOG(DEBUG, "port %u new pmd tunnel id=0x%x",
8926 dev->data->port_id, tunnel->tunnel_id);
8931 struct tunnel_db_get_tunnel_ctx {
8932 const struct rte_flow_tunnel *app_tunnel;
8933 struct mlx5_flow_tunnel *tunnel;
8936 static bool get_tunnel_match(struct rte_eth_dev *dev,
8937 struct mlx5_flow_tunnel *tunnel, const void *x)
8939 const struct tunnel_db_get_tunnel_ctx *ctx = x;
8942 return !memcmp(ctx->app_tunnel, &tunnel->app_tunnel,
8943 sizeof(*ctx->app_tunnel));
8946 static void get_tunnel_hit(struct rte_eth_dev *dev,
8947 struct mlx5_flow_tunnel *tunnel, void *x)
8949 /* called under tunnel spinlock protection */
8950 struct tunnel_db_get_tunnel_ctx *ctx = x;
8954 ctx->tunnel = tunnel;
8957 static void get_tunnel_miss(struct rte_eth_dev *dev, void *x)
8959 /* called under tunnel spinlock protection */
8960 struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
8961 struct tunnel_db_get_tunnel_ctx *ctx = x;
8963 rte_spinlock_unlock(&thub->sl);
8964 ctx->tunnel = mlx5_flow_tunnel_allocate(dev, ctx->app_tunnel);
8965 rte_spinlock_lock(&thub->sl);
8967 ctx->tunnel->refctn = 1;
8968 LIST_INSERT_HEAD(&thub->tunnels, ctx->tunnel, chain);
8974 mlx5_get_flow_tunnel(struct rte_eth_dev *dev,
8975 const struct rte_flow_tunnel *app_tunnel,
8976 struct mlx5_flow_tunnel **tunnel)
8978 struct tunnel_db_get_tunnel_ctx ctx = {
8979 .app_tunnel = app_tunnel,
8982 mlx5_access_tunnel_offload_db(dev, get_tunnel_match, get_tunnel_hit,
8983 get_tunnel_miss, &ctx, true);
8984 *tunnel = ctx.tunnel;
8985 return ctx.tunnel ? 0 : -ENOMEM;
8988 void mlx5_release_tunnel_hub(struct mlx5_dev_ctx_shared *sh, uint16_t port_id)
8990 struct mlx5_flow_tunnel_hub *thub = sh->tunnel_hub;
8994 if (!LIST_EMPTY(&thub->tunnels))
8995 DRV_LOG(WARNING, "port %u tunnels present", port_id);
8996 mlx5_hlist_destroy(thub->groups);
9000 int mlx5_alloc_tunnel_hub(struct mlx5_dev_ctx_shared *sh)
9003 struct mlx5_flow_tunnel_hub *thub;
9005 thub = mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO, sizeof(*thub),
9009 LIST_INIT(&thub->tunnels);
9010 rte_spinlock_init(&thub->sl);
9011 thub->groups = mlx5_hlist_create("flow groups", 64,
9013 mlx5_flow_tunnel_grp2tbl_create_cb,
9014 mlx5_flow_tunnel_grp2tbl_match_cb,
9015 mlx5_flow_tunnel_grp2tbl_remove_cb,
9016 mlx5_flow_tunnel_grp2tbl_clone_cb,
9017 mlx5_flow_tunnel_grp2tbl_clone_free_cb);
9018 if (!thub->groups) {
9022 sh->tunnel_hub = thub;
9028 mlx5_hlist_destroy(thub->groups);
9035 mlx5_flow_tunnel_validate(struct rte_eth_dev *dev,
9036 struct rte_flow_tunnel *tunnel,
9037 const char *err_msg)
9040 if (!is_tunnel_offload_active(dev)) {
9041 err_msg = "tunnel offload was not activated";
9043 } else if (!tunnel) {
9044 err_msg = "no application tunnel";
9048 switch (tunnel->type) {
9050 err_msg = "unsupported tunnel type";
9052 case RTE_FLOW_ITEM_TYPE_VXLAN:
9061 mlx5_flow_tunnel_decap_set(struct rte_eth_dev *dev,
9062 struct rte_flow_tunnel *app_tunnel,
9063 struct rte_flow_action **actions,
9064 uint32_t *num_of_actions,
9065 struct rte_flow_error *error)
9068 struct mlx5_flow_tunnel *tunnel;
9069 const char *err_msg = NULL;
9070 bool verdict = mlx5_flow_tunnel_validate(dev, app_tunnel, err_msg);
9073 return rte_flow_error_set(error, EINVAL,
9074 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
9076 ret = mlx5_get_flow_tunnel(dev, app_tunnel, &tunnel);
9078 return rte_flow_error_set(error, ret,
9079 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
9080 "failed to initialize pmd tunnel");
9082 *actions = &tunnel->action;
9083 *num_of_actions = 1;
9088 mlx5_flow_tunnel_match(struct rte_eth_dev *dev,
9089 struct rte_flow_tunnel *app_tunnel,
9090 struct rte_flow_item **items,
9091 uint32_t *num_of_items,
9092 struct rte_flow_error *error)
9095 struct mlx5_flow_tunnel *tunnel;
9096 const char *err_msg = NULL;
9097 bool verdict = mlx5_flow_tunnel_validate(dev, app_tunnel, err_msg);
9100 return rte_flow_error_set(error, EINVAL,
9101 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
9103 ret = mlx5_get_flow_tunnel(dev, app_tunnel, &tunnel);
9105 return rte_flow_error_set(error, ret,
9106 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
9107 "failed to initialize pmd tunnel");
9109 *items = &tunnel->item;
9114 struct tunnel_db_element_release_ctx {
9115 struct rte_flow_item *items;
9116 struct rte_flow_action *actions;
9117 uint32_t num_elements;
9118 struct rte_flow_error *error;
9123 tunnel_element_release_match(struct rte_eth_dev *dev,
9124 struct mlx5_flow_tunnel *tunnel, const void *x)
9126 const struct tunnel_db_element_release_ctx *ctx = x;
9129 if (ctx->num_elements != 1)
9131 else if (ctx->items)
9132 return ctx->items == &tunnel->item;
9133 else if (ctx->actions)
9134 return ctx->actions == &tunnel->action;
9140 tunnel_element_release_hit(struct rte_eth_dev *dev,
9141 struct mlx5_flow_tunnel *tunnel, void *x)
9143 struct tunnel_db_element_release_ctx *ctx = x;
9145 if (!__atomic_sub_fetch(&tunnel->refctn, 1, __ATOMIC_RELAXED))
9146 mlx5_flow_tunnel_free(dev, tunnel);
9150 tunnel_element_release_miss(struct rte_eth_dev *dev, void *x)
9152 struct tunnel_db_element_release_ctx *ctx = x;
9154 ctx->ret = rte_flow_error_set(ctx->error, EINVAL,
9155 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
9156 "invalid argument");
9160 mlx5_flow_tunnel_item_release(struct rte_eth_dev *dev,
9161 struct rte_flow_item *pmd_items,
9162 uint32_t num_items, struct rte_flow_error *err)
9164 struct tunnel_db_element_release_ctx ctx = {
9167 .num_elements = num_items,
9171 mlx5_access_tunnel_offload_db(dev, tunnel_element_release_match,
9172 tunnel_element_release_hit,
9173 tunnel_element_release_miss, &ctx, false);
9179 mlx5_flow_tunnel_action_release(struct rte_eth_dev *dev,
9180 struct rte_flow_action *pmd_actions,
9181 uint32_t num_actions, struct rte_flow_error *err)
9183 struct tunnel_db_element_release_ctx ctx = {
9185 .actions = pmd_actions,
9186 .num_elements = num_actions,
9190 mlx5_access_tunnel_offload_db(dev, tunnel_element_release_match,
9191 tunnel_element_release_hit,
9192 tunnel_element_release_miss, &ctx, false);
9198 mlx5_flow_tunnel_get_restore_info(struct rte_eth_dev *dev,
9200 struct rte_flow_restore_info *info,
9201 struct rte_flow_error *err)
9203 uint64_t ol_flags = m->ol_flags;
9204 const struct mlx5_flow_tbl_data_entry *tble;
9205 const uint64_t mask = PKT_RX_FDIR | PKT_RX_FDIR_ID;
9207 if (!is_tunnel_offload_active(dev)) {
9212 if ((ol_flags & mask) != mask)
9214 tble = tunnel_mark_decode(dev, m->hash.fdir.hi);
9216 DRV_LOG(DEBUG, "port %u invalid miss tunnel mark %#x",
9217 dev->data->port_id, m->hash.fdir.hi);
9220 MLX5_ASSERT(tble->tunnel);
9221 memcpy(&info->tunnel, &tble->tunnel->app_tunnel, sizeof(info->tunnel));
9222 info->group_id = tble->group_id;
9223 info->flags = RTE_FLOW_RESTORE_INFO_TUNNEL |
9224 RTE_FLOW_RESTORE_INFO_GROUP_ID |
9225 RTE_FLOW_RESTORE_INFO_ENCAPSULATED;
9230 return rte_flow_error_set(err, EINVAL,
9231 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
9232 "failed to get restore info");
9235 #else /* HAVE_IBV_FLOW_DV_SUPPORT */
9237 mlx5_flow_tunnel_decap_set(__rte_unused struct rte_eth_dev *dev,
9238 __rte_unused struct rte_flow_tunnel *app_tunnel,
9239 __rte_unused struct rte_flow_action **actions,
9240 __rte_unused uint32_t *num_of_actions,
9241 __rte_unused struct rte_flow_error *error)
9247 mlx5_flow_tunnel_match(__rte_unused struct rte_eth_dev *dev,
9248 __rte_unused struct rte_flow_tunnel *app_tunnel,
9249 __rte_unused struct rte_flow_item **items,
9250 __rte_unused uint32_t *num_of_items,
9251 __rte_unused struct rte_flow_error *error)
9257 mlx5_flow_tunnel_item_release(__rte_unused struct rte_eth_dev *dev,
9258 __rte_unused struct rte_flow_item *pmd_items,
9259 __rte_unused uint32_t num_items,
9260 __rte_unused struct rte_flow_error *err)
9266 mlx5_flow_tunnel_action_release(__rte_unused struct rte_eth_dev *dev,
9267 __rte_unused struct rte_flow_action *pmd_action,
9268 __rte_unused uint32_t num_actions,
9269 __rte_unused struct rte_flow_error *err)
9275 mlx5_flow_tunnel_get_restore_info(__rte_unused struct rte_eth_dev *dev,
9276 __rte_unused struct rte_mbuf *m,
9277 __rte_unused struct rte_flow_restore_info *i,
9278 __rte_unused struct rte_flow_error *err)
9284 flow_tunnel_add_default_miss(__rte_unused struct rte_eth_dev *dev,
9285 __rte_unused struct rte_flow *flow,
9286 __rte_unused const struct rte_flow_attr *attr,
9287 __rte_unused const struct rte_flow_action *actions,
9288 __rte_unused uint32_t flow_idx,
9289 __rte_unused const struct mlx5_flow_tunnel *tunnel,
9290 __rte_unused struct tunnel_default_miss_ctx *ctx,
9291 __rte_unused struct rte_flow_error *error)
9296 static struct mlx5_flow_tunnel *
9297 mlx5_find_tunnel_id(__rte_unused struct rte_eth_dev *dev,
9298 __rte_unused uint32_t id)
9304 mlx5_flow_tunnel_free(__rte_unused struct rte_eth_dev *dev,
9305 __rte_unused struct mlx5_flow_tunnel *tunnel)
9310 tunnel_flow_group_to_flow_table(__rte_unused struct rte_eth_dev *dev,
9311 __rte_unused const struct mlx5_flow_tunnel *t,
9312 __rte_unused uint32_t group,
9313 __rte_unused uint32_t *table,
9314 struct rte_flow_error *error)
9316 return rte_flow_error_set(error, ENOTSUP,
9317 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
9318 "tunnel offload requires DV support");
9322 mlx5_release_tunnel_hub(__rte_unused struct mlx5_dev_ctx_shared *sh,
9323 __rte_unused uint16_t port_id)
9326 #endif /* HAVE_IBV_FLOW_DV_SUPPORT */
9329 mlx5_dbg__print_pattern(const struct rte_flow_item *item)
9332 struct rte_flow_error error;
9334 for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
9336 ret = rte_flow_conv(RTE_FLOW_CONV_OP_ITEM_NAME_PTR, &item_name,
9338 (void *)(uintptr_t)item->type, &error);
9340 printf("%s ", item_name);
9342 printf("%d\n", (int)item->type);