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:
137 case RTE_FLOW_ITEM_TYPE_IPV6_FRAG_EXT:
138 case RTE_FLOW_ITEM_TYPE_GTP:
146 static enum rte_flow_item_type
147 mlx5_flow_expand_rss_item_complete(const struct rte_flow_item *item)
149 enum rte_flow_item_type ret = RTE_FLOW_ITEM_TYPE_VOID;
150 uint16_t ether_type = 0;
151 uint16_t ether_type_m;
152 uint8_t ip_next_proto = 0;
153 uint8_t ip_next_proto_m;
155 if (item == NULL || item->spec == NULL)
157 switch (item->type) {
158 case RTE_FLOW_ITEM_TYPE_ETH:
160 ether_type_m = ((const struct rte_flow_item_eth *)
163 ether_type_m = rte_flow_item_eth_mask.type;
164 if (ether_type_m != RTE_BE16(0xFFFF))
166 ether_type = ((const struct rte_flow_item_eth *)
168 if (rte_be_to_cpu_16(ether_type) == RTE_ETHER_TYPE_IPV4)
169 ret = RTE_FLOW_ITEM_TYPE_IPV4;
170 else if (rte_be_to_cpu_16(ether_type) == RTE_ETHER_TYPE_IPV6)
171 ret = RTE_FLOW_ITEM_TYPE_IPV6;
172 else if (rte_be_to_cpu_16(ether_type) == RTE_ETHER_TYPE_VLAN)
173 ret = RTE_FLOW_ITEM_TYPE_VLAN;
175 ret = RTE_FLOW_ITEM_TYPE_END;
177 case RTE_FLOW_ITEM_TYPE_VLAN:
179 ether_type_m = ((const struct rte_flow_item_vlan *)
180 (item->mask))->inner_type;
182 ether_type_m = rte_flow_item_vlan_mask.inner_type;
183 if (ether_type_m != RTE_BE16(0xFFFF))
185 ether_type = ((const struct rte_flow_item_vlan *)
186 (item->spec))->inner_type;
187 if (rte_be_to_cpu_16(ether_type) == RTE_ETHER_TYPE_IPV4)
188 ret = RTE_FLOW_ITEM_TYPE_IPV4;
189 else if (rte_be_to_cpu_16(ether_type) == RTE_ETHER_TYPE_IPV6)
190 ret = RTE_FLOW_ITEM_TYPE_IPV6;
191 else if (rte_be_to_cpu_16(ether_type) == RTE_ETHER_TYPE_VLAN)
192 ret = RTE_FLOW_ITEM_TYPE_VLAN;
194 ret = RTE_FLOW_ITEM_TYPE_END;
196 case RTE_FLOW_ITEM_TYPE_IPV4:
198 ip_next_proto_m = ((const struct rte_flow_item_ipv4 *)
199 (item->mask))->hdr.next_proto_id;
202 rte_flow_item_ipv4_mask.hdr.next_proto_id;
203 if (ip_next_proto_m != 0xFF)
205 ip_next_proto = ((const struct rte_flow_item_ipv4 *)
206 (item->spec))->hdr.next_proto_id;
207 if (ip_next_proto == IPPROTO_UDP)
208 ret = RTE_FLOW_ITEM_TYPE_UDP;
209 else if (ip_next_proto == IPPROTO_TCP)
210 ret = RTE_FLOW_ITEM_TYPE_TCP;
211 else if (ip_next_proto == IPPROTO_IP)
212 ret = RTE_FLOW_ITEM_TYPE_IPV4;
213 else if (ip_next_proto == IPPROTO_IPV6)
214 ret = RTE_FLOW_ITEM_TYPE_IPV6;
216 ret = RTE_FLOW_ITEM_TYPE_END;
218 case RTE_FLOW_ITEM_TYPE_IPV6:
220 ip_next_proto_m = ((const struct rte_flow_item_ipv6 *)
221 (item->mask))->hdr.proto;
224 rte_flow_item_ipv6_mask.hdr.proto;
225 if (ip_next_proto_m != 0xFF)
227 ip_next_proto = ((const struct rte_flow_item_ipv6 *)
228 (item->spec))->hdr.proto;
229 if (ip_next_proto == IPPROTO_UDP)
230 ret = RTE_FLOW_ITEM_TYPE_UDP;
231 else if (ip_next_proto == IPPROTO_TCP)
232 ret = RTE_FLOW_ITEM_TYPE_TCP;
233 else if (ip_next_proto == IPPROTO_IP)
234 ret = RTE_FLOW_ITEM_TYPE_IPV4;
235 else if (ip_next_proto == IPPROTO_IPV6)
236 ret = RTE_FLOW_ITEM_TYPE_IPV6;
238 ret = RTE_FLOW_ITEM_TYPE_END;
241 ret = RTE_FLOW_ITEM_TYPE_VOID;
247 #define MLX5_RSS_EXP_ELT_N 16
250 * Expand RSS flows into several possible flows according to the RSS hash
251 * fields requested and the driver capabilities.
254 * Buffer to store the result expansion.
256 * Buffer size in bytes. If 0, @p buf can be NULL.
260 * RSS types to expand (see ETH_RSS_* definitions).
262 * Input graph to expand @p pattern according to @p types.
263 * @param[in] graph_root_index
264 * Index of root node in @p graph, typically 0.
267 * A positive value representing the size of @p buf in bytes regardless of
268 * @p size on success, a negative errno value otherwise and rte_errno is
269 * set, the following errors are defined:
271 * -E2BIG: graph-depth @p graph is too deep.
272 * -EINVAL: @p size has not enough space for expanded pattern.
275 mlx5_flow_expand_rss(struct mlx5_flow_expand_rss *buf, size_t size,
276 const struct rte_flow_item *pattern, uint64_t types,
277 const struct mlx5_flow_expand_node graph[],
278 int graph_root_index)
280 const struct rte_flow_item *item;
281 const struct mlx5_flow_expand_node *node = &graph[graph_root_index];
282 const int *next_node;
283 const int *stack[MLX5_RSS_EXP_ELT_N];
285 struct rte_flow_item flow_items[MLX5_RSS_EXP_ELT_N];
288 size_t user_pattern_size = 0;
290 const struct mlx5_flow_expand_node *next = NULL;
291 struct rte_flow_item missed_item;
294 const struct rte_flow_item *last_item = NULL;
296 memset(&missed_item, 0, sizeof(missed_item));
297 lsize = offsetof(struct mlx5_flow_expand_rss, entry) +
298 MLX5_RSS_EXP_ELT_N * sizeof(buf->entry[0]);
301 buf->entry[0].priority = 0;
302 buf->entry[0].pattern = (void *)&buf->entry[MLX5_RSS_EXP_ELT_N];
304 addr = buf->entry[0].pattern;
305 for (item = pattern; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
306 if (!mlx5_flow_is_rss_expandable_item(item)) {
307 user_pattern_size += sizeof(*item);
311 for (i = 0; node->next && node->next[i]; ++i) {
312 next = &graph[node->next[i]];
313 if (next->type == item->type)
318 user_pattern_size += sizeof(*item);
320 user_pattern_size += sizeof(*item); /* Handle END item. */
321 lsize += user_pattern_size;
324 /* Copy the user pattern in the first entry of the buffer. */
325 rte_memcpy(addr, pattern, user_pattern_size);
326 addr = (void *)(((uintptr_t)addr) + user_pattern_size);
328 /* Start expanding. */
329 memset(flow_items, 0, sizeof(flow_items));
330 user_pattern_size -= sizeof(*item);
332 * Check if the last valid item has spec set, need complete pattern,
333 * and the pattern can be used for expansion.
335 missed_item.type = mlx5_flow_expand_rss_item_complete(last_item);
336 if (missed_item.type == RTE_FLOW_ITEM_TYPE_END) {
337 /* Item type END indicates expansion is not required. */
340 if (missed_item.type != RTE_FLOW_ITEM_TYPE_VOID) {
343 for (i = 0; node->next && node->next[i]; ++i) {
344 next = &graph[node->next[i]];
345 if (next->type == missed_item.type) {
346 flow_items[0].type = missed_item.type;
347 flow_items[1].type = RTE_FLOW_ITEM_TYPE_END;
353 if (next && missed) {
354 elt = 2; /* missed item + item end. */
356 lsize += elt * sizeof(*item) + user_pattern_size;
359 if (node->rss_types & types) {
360 buf->entry[buf->entries].priority = 1;
361 buf->entry[buf->entries].pattern = addr;
363 rte_memcpy(addr, buf->entry[0].pattern,
365 addr = (void *)(((uintptr_t)addr) + user_pattern_size);
366 rte_memcpy(addr, flow_items, elt * sizeof(*item));
367 addr = (void *)(((uintptr_t)addr) +
368 elt * sizeof(*item));
371 memset(flow_items, 0, sizeof(flow_items));
372 next_node = node->next;
373 stack[stack_pos] = next_node;
374 node = next_node ? &graph[*next_node] : NULL;
376 flow_items[stack_pos].type = node->type;
377 if (node->rss_types & types) {
380 * compute the number of items to copy from the
381 * expansion and copy it.
382 * When the stack_pos is 0, there are 1 element in it,
383 * plus the addition END item.
386 flow_items[stack_pos + 1].type = RTE_FLOW_ITEM_TYPE_END;
387 lsize += elt * sizeof(*item) + user_pattern_size;
390 n = elt * sizeof(*item);
391 buf->entry[buf->entries].priority =
392 stack_pos + 1 + missed;
393 buf->entry[buf->entries].pattern = addr;
395 rte_memcpy(addr, buf->entry[0].pattern,
397 addr = (void *)(((uintptr_t)addr) +
399 rte_memcpy(addr, &missed_item,
400 missed * sizeof(*item));
401 addr = (void *)(((uintptr_t)addr) +
402 missed * sizeof(*item));
403 rte_memcpy(addr, flow_items, n);
404 addr = (void *)(((uintptr_t)addr) + n);
407 if (!node->optional && node->next) {
408 next_node = node->next;
409 if (stack_pos++ == MLX5_RSS_EXP_ELT_N) {
413 stack[stack_pos] = next_node;
414 } else if (*(next_node + 1)) {
415 /* Follow up with the next possibility. */
418 /* Move to the next path. */
420 next_node = stack[--stack_pos];
422 stack[stack_pos] = next_node;
424 node = *next_node ? &graph[*next_node] : NULL;
429 enum mlx5_expansion {
431 MLX5_EXPANSION_ROOT_OUTER,
432 MLX5_EXPANSION_ROOT_ETH_VLAN,
433 MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN,
434 MLX5_EXPANSION_OUTER_ETH,
435 MLX5_EXPANSION_OUTER_ETH_VLAN,
436 MLX5_EXPANSION_OUTER_VLAN,
437 MLX5_EXPANSION_OUTER_IPV4,
438 MLX5_EXPANSION_OUTER_IPV4_UDP,
439 MLX5_EXPANSION_OUTER_IPV4_TCP,
440 MLX5_EXPANSION_OUTER_IPV6,
441 MLX5_EXPANSION_OUTER_IPV6_UDP,
442 MLX5_EXPANSION_OUTER_IPV6_TCP,
443 MLX5_EXPANSION_VXLAN,
444 MLX5_EXPANSION_VXLAN_GPE,
446 MLX5_EXPANSION_NVGRE,
447 MLX5_EXPANSION_GRE_KEY,
450 MLX5_EXPANSION_ETH_VLAN,
453 MLX5_EXPANSION_IPV4_UDP,
454 MLX5_EXPANSION_IPV4_TCP,
456 MLX5_EXPANSION_IPV6_UDP,
457 MLX5_EXPANSION_IPV6_TCP,
458 MLX5_EXPANSION_IPV6_FRAG_EXT,
462 /** Supported expansion of items. */
463 static const struct mlx5_flow_expand_node mlx5_support_expansion[] = {
464 [MLX5_EXPANSION_ROOT] = {
465 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
467 MLX5_EXPANSION_IPV6),
468 .type = RTE_FLOW_ITEM_TYPE_END,
470 [MLX5_EXPANSION_ROOT_OUTER] = {
471 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_ETH,
472 MLX5_EXPANSION_OUTER_IPV4,
473 MLX5_EXPANSION_OUTER_IPV6),
474 .type = RTE_FLOW_ITEM_TYPE_END,
476 [MLX5_EXPANSION_ROOT_ETH_VLAN] = {
477 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH_VLAN),
478 .type = RTE_FLOW_ITEM_TYPE_END,
480 [MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN] = {
481 .next = MLX5_FLOW_EXPAND_RSS_NEXT
482 (MLX5_EXPANSION_OUTER_ETH_VLAN),
483 .type = RTE_FLOW_ITEM_TYPE_END,
485 [MLX5_EXPANSION_OUTER_ETH] = {
486 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_IPV4,
487 MLX5_EXPANSION_OUTER_IPV6),
488 .type = RTE_FLOW_ITEM_TYPE_ETH,
491 [MLX5_EXPANSION_OUTER_ETH_VLAN] = {
492 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_VLAN),
493 .type = RTE_FLOW_ITEM_TYPE_ETH,
496 [MLX5_EXPANSION_OUTER_VLAN] = {
497 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_IPV4,
498 MLX5_EXPANSION_OUTER_IPV6),
499 .type = RTE_FLOW_ITEM_TYPE_VLAN,
501 [MLX5_EXPANSION_OUTER_IPV4] = {
502 .next = MLX5_FLOW_EXPAND_RSS_NEXT
503 (MLX5_EXPANSION_OUTER_IPV4_UDP,
504 MLX5_EXPANSION_OUTER_IPV4_TCP,
506 MLX5_EXPANSION_NVGRE,
508 MLX5_EXPANSION_IPV6),
509 .type = RTE_FLOW_ITEM_TYPE_IPV4,
510 .rss_types = ETH_RSS_IPV4 | ETH_RSS_FRAG_IPV4 |
511 ETH_RSS_NONFRAG_IPV4_OTHER,
513 [MLX5_EXPANSION_OUTER_IPV4_UDP] = {
514 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VXLAN,
515 MLX5_EXPANSION_VXLAN_GPE,
518 .type = RTE_FLOW_ITEM_TYPE_UDP,
519 .rss_types = ETH_RSS_NONFRAG_IPV4_UDP,
521 [MLX5_EXPANSION_OUTER_IPV4_TCP] = {
522 .type = RTE_FLOW_ITEM_TYPE_TCP,
523 .rss_types = ETH_RSS_NONFRAG_IPV4_TCP,
525 [MLX5_EXPANSION_OUTER_IPV6] = {
526 .next = MLX5_FLOW_EXPAND_RSS_NEXT
527 (MLX5_EXPANSION_OUTER_IPV6_UDP,
528 MLX5_EXPANSION_OUTER_IPV6_TCP,
532 MLX5_EXPANSION_NVGRE),
533 .type = RTE_FLOW_ITEM_TYPE_IPV6,
534 .rss_types = ETH_RSS_IPV6 | ETH_RSS_FRAG_IPV6 |
535 ETH_RSS_NONFRAG_IPV6_OTHER,
537 [MLX5_EXPANSION_OUTER_IPV6_UDP] = {
538 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VXLAN,
539 MLX5_EXPANSION_VXLAN_GPE,
542 .type = RTE_FLOW_ITEM_TYPE_UDP,
543 .rss_types = ETH_RSS_NONFRAG_IPV6_UDP,
545 [MLX5_EXPANSION_OUTER_IPV6_TCP] = {
546 .type = RTE_FLOW_ITEM_TYPE_TCP,
547 .rss_types = ETH_RSS_NONFRAG_IPV6_TCP,
549 [MLX5_EXPANSION_VXLAN] = {
550 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
552 MLX5_EXPANSION_IPV6),
553 .type = RTE_FLOW_ITEM_TYPE_VXLAN,
555 [MLX5_EXPANSION_VXLAN_GPE] = {
556 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
558 MLX5_EXPANSION_IPV6),
559 .type = RTE_FLOW_ITEM_TYPE_VXLAN_GPE,
561 [MLX5_EXPANSION_GRE] = {
562 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
564 MLX5_EXPANSION_GRE_KEY,
565 MLX5_EXPANSION_MPLS),
566 .type = RTE_FLOW_ITEM_TYPE_GRE,
568 [MLX5_EXPANSION_GRE_KEY] = {
569 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
571 MLX5_EXPANSION_MPLS),
572 .type = RTE_FLOW_ITEM_TYPE_GRE_KEY,
575 [MLX5_EXPANSION_NVGRE] = {
576 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH),
577 .type = RTE_FLOW_ITEM_TYPE_NVGRE,
579 [MLX5_EXPANSION_MPLS] = {
580 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
583 .type = RTE_FLOW_ITEM_TYPE_MPLS,
585 [MLX5_EXPANSION_ETH] = {
586 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
587 MLX5_EXPANSION_IPV6),
588 .type = RTE_FLOW_ITEM_TYPE_ETH,
590 [MLX5_EXPANSION_ETH_VLAN] = {
591 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VLAN),
592 .type = RTE_FLOW_ITEM_TYPE_ETH,
594 [MLX5_EXPANSION_VLAN] = {
595 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
596 MLX5_EXPANSION_IPV6),
597 .type = RTE_FLOW_ITEM_TYPE_VLAN,
599 [MLX5_EXPANSION_IPV4] = {
600 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4_UDP,
601 MLX5_EXPANSION_IPV4_TCP),
602 .type = RTE_FLOW_ITEM_TYPE_IPV4,
603 .rss_types = ETH_RSS_IPV4 | ETH_RSS_FRAG_IPV4 |
604 ETH_RSS_NONFRAG_IPV4_OTHER,
606 [MLX5_EXPANSION_IPV4_UDP] = {
607 .type = RTE_FLOW_ITEM_TYPE_UDP,
608 .rss_types = ETH_RSS_NONFRAG_IPV4_UDP,
610 [MLX5_EXPANSION_IPV4_TCP] = {
611 .type = RTE_FLOW_ITEM_TYPE_TCP,
612 .rss_types = ETH_RSS_NONFRAG_IPV4_TCP,
614 [MLX5_EXPANSION_IPV6] = {
615 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV6_UDP,
616 MLX5_EXPANSION_IPV6_TCP,
617 MLX5_EXPANSION_IPV6_FRAG_EXT),
618 .type = RTE_FLOW_ITEM_TYPE_IPV6,
619 .rss_types = ETH_RSS_IPV6 | ETH_RSS_FRAG_IPV6 |
620 ETH_RSS_NONFRAG_IPV6_OTHER,
622 [MLX5_EXPANSION_IPV6_UDP] = {
623 .type = RTE_FLOW_ITEM_TYPE_UDP,
624 .rss_types = ETH_RSS_NONFRAG_IPV6_UDP,
626 [MLX5_EXPANSION_IPV6_TCP] = {
627 .type = RTE_FLOW_ITEM_TYPE_TCP,
628 .rss_types = ETH_RSS_NONFRAG_IPV6_TCP,
630 [MLX5_EXPANSION_IPV6_FRAG_EXT] = {
631 .type = RTE_FLOW_ITEM_TYPE_IPV6_FRAG_EXT,
633 [MLX5_EXPANSION_GTP] = {
634 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
635 MLX5_EXPANSION_IPV6),
636 .type = RTE_FLOW_ITEM_TYPE_GTP
640 static struct rte_flow_action_handle *
641 mlx5_action_handle_create(struct rte_eth_dev *dev,
642 const struct rte_flow_indir_action_conf *conf,
643 const struct rte_flow_action *action,
644 struct rte_flow_error *error);
645 static int mlx5_action_handle_destroy
646 (struct rte_eth_dev *dev,
647 struct rte_flow_action_handle *handle,
648 struct rte_flow_error *error);
649 static int mlx5_action_handle_update
650 (struct rte_eth_dev *dev,
651 struct rte_flow_action_handle *handle,
653 struct rte_flow_error *error);
654 static int mlx5_action_handle_query
655 (struct rte_eth_dev *dev,
656 const struct rte_flow_action_handle *handle,
658 struct rte_flow_error *error);
660 mlx5_flow_tunnel_decap_set(struct rte_eth_dev *dev,
661 struct rte_flow_tunnel *app_tunnel,
662 struct rte_flow_action **actions,
663 uint32_t *num_of_actions,
664 struct rte_flow_error *error);
666 mlx5_flow_tunnel_match(struct rte_eth_dev *dev,
667 struct rte_flow_tunnel *app_tunnel,
668 struct rte_flow_item **items,
669 uint32_t *num_of_items,
670 struct rte_flow_error *error);
672 mlx5_flow_tunnel_item_release(struct rte_eth_dev *dev,
673 struct rte_flow_item *pmd_items,
674 uint32_t num_items, struct rte_flow_error *err);
676 mlx5_flow_tunnel_action_release(struct rte_eth_dev *dev,
677 struct rte_flow_action *pmd_actions,
678 uint32_t num_actions,
679 struct rte_flow_error *err);
681 mlx5_flow_tunnel_get_restore_info(struct rte_eth_dev *dev,
683 struct rte_flow_restore_info *info,
684 struct rte_flow_error *err);
686 static const struct rte_flow_ops mlx5_flow_ops = {
687 .validate = mlx5_flow_validate,
688 .create = mlx5_flow_create,
689 .destroy = mlx5_flow_destroy,
690 .flush = mlx5_flow_flush,
691 .isolate = mlx5_flow_isolate,
692 .query = mlx5_flow_query,
693 .dev_dump = mlx5_flow_dev_dump,
694 .get_aged_flows = mlx5_flow_get_aged_flows,
695 .action_handle_create = mlx5_action_handle_create,
696 .action_handle_destroy = mlx5_action_handle_destroy,
697 .action_handle_update = mlx5_action_handle_update,
698 .action_handle_query = mlx5_action_handle_query,
699 .tunnel_decap_set = mlx5_flow_tunnel_decap_set,
700 .tunnel_match = mlx5_flow_tunnel_match,
701 .tunnel_action_decap_release = mlx5_flow_tunnel_action_release,
702 .tunnel_item_release = mlx5_flow_tunnel_item_release,
703 .get_restore_info = mlx5_flow_tunnel_get_restore_info,
706 /* Tunnel information. */
707 struct mlx5_flow_tunnel_info {
708 uint64_t tunnel; /**< Tunnel bit (see MLX5_FLOW_*). */
709 uint32_t ptype; /**< Tunnel Ptype (see RTE_PTYPE_*). */
712 static struct mlx5_flow_tunnel_info tunnels_info[] = {
714 .tunnel = MLX5_FLOW_LAYER_VXLAN,
715 .ptype = RTE_PTYPE_TUNNEL_VXLAN | RTE_PTYPE_L4_UDP,
718 .tunnel = MLX5_FLOW_LAYER_GENEVE,
719 .ptype = RTE_PTYPE_TUNNEL_GENEVE | RTE_PTYPE_L4_UDP,
722 .tunnel = MLX5_FLOW_LAYER_VXLAN_GPE,
723 .ptype = RTE_PTYPE_TUNNEL_VXLAN_GPE | RTE_PTYPE_L4_UDP,
726 .tunnel = MLX5_FLOW_LAYER_GRE,
727 .ptype = RTE_PTYPE_TUNNEL_GRE,
730 .tunnel = MLX5_FLOW_LAYER_MPLS | MLX5_FLOW_LAYER_OUTER_L4_UDP,
731 .ptype = RTE_PTYPE_TUNNEL_MPLS_IN_UDP | RTE_PTYPE_L4_UDP,
734 .tunnel = MLX5_FLOW_LAYER_MPLS,
735 .ptype = RTE_PTYPE_TUNNEL_MPLS_IN_GRE,
738 .tunnel = MLX5_FLOW_LAYER_NVGRE,
739 .ptype = RTE_PTYPE_TUNNEL_NVGRE,
742 .tunnel = MLX5_FLOW_LAYER_IPIP,
743 .ptype = RTE_PTYPE_TUNNEL_IP,
746 .tunnel = MLX5_FLOW_LAYER_IPV6_ENCAP,
747 .ptype = RTE_PTYPE_TUNNEL_IP,
750 .tunnel = MLX5_FLOW_LAYER_GTP,
751 .ptype = RTE_PTYPE_TUNNEL_GTPU,
758 * Translate tag ID to register.
761 * Pointer to the Ethernet device structure.
763 * The feature that request the register.
765 * The request register ID.
767 * Error description in case of any.
770 * The request register on success, a negative errno
771 * value otherwise and rte_errno is set.
774 mlx5_flow_get_reg_id(struct rte_eth_dev *dev,
775 enum mlx5_feature_name feature,
777 struct rte_flow_error *error)
779 struct mlx5_priv *priv = dev->data->dev_private;
780 struct mlx5_dev_config *config = &priv->config;
781 enum modify_reg start_reg;
782 bool skip_mtr_reg = false;
785 case MLX5_HAIRPIN_RX:
787 case MLX5_HAIRPIN_TX:
789 case MLX5_METADATA_RX:
790 switch (config->dv_xmeta_en) {
791 case MLX5_XMETA_MODE_LEGACY:
793 case MLX5_XMETA_MODE_META16:
795 case MLX5_XMETA_MODE_META32:
799 case MLX5_METADATA_TX:
801 case MLX5_METADATA_FDB:
802 switch (config->dv_xmeta_en) {
803 case MLX5_XMETA_MODE_LEGACY:
805 case MLX5_XMETA_MODE_META16:
807 case MLX5_XMETA_MODE_META32:
812 switch (config->dv_xmeta_en) {
813 case MLX5_XMETA_MODE_LEGACY:
815 case MLX5_XMETA_MODE_META16:
817 case MLX5_XMETA_MODE_META32:
823 * If meter color and meter id share one register, flow match
824 * should use the meter color register for match.
826 if (priv->mtr_reg_share)
827 return priv->mtr_color_reg;
829 return priv->mtr_color_reg != REG_C_2 ? REG_C_2 :
832 case MLX5_ASO_FLOW_HIT:
833 case MLX5_ASO_CONNTRACK:
834 /* All features use the same REG_C. */
835 MLX5_ASSERT(priv->mtr_color_reg != REG_NON);
836 return priv->mtr_color_reg;
839 * Metadata COPY_MARK register using is in meter suffix sub
840 * flow while with meter. It's safe to share the same register.
842 return priv->mtr_color_reg != REG_C_2 ? REG_C_2 : REG_C_3;
845 * If meter is enable, it will engage the register for color
846 * match and flow match. If meter color match is not using the
847 * REG_C_2, need to skip the REG_C_x be used by meter color
849 * If meter is disable, free to use all available registers.
851 start_reg = priv->mtr_color_reg != REG_C_2 ? REG_C_2 :
852 (priv->mtr_reg_share ? REG_C_3 : REG_C_4);
853 skip_mtr_reg = !!(priv->mtr_en && start_reg == REG_C_2);
854 if (id > (uint32_t)(REG_C_7 - start_reg))
855 return rte_flow_error_set(error, EINVAL,
856 RTE_FLOW_ERROR_TYPE_ITEM,
857 NULL, "invalid tag id");
858 if (config->flow_mreg_c[id + start_reg - REG_C_0] == REG_NON)
859 return rte_flow_error_set(error, ENOTSUP,
860 RTE_FLOW_ERROR_TYPE_ITEM,
861 NULL, "unsupported tag id");
863 * This case means meter is using the REG_C_x great than 2.
864 * Take care not to conflict with meter color REG_C_x.
865 * If the available index REG_C_y >= REG_C_x, skip the
868 if (skip_mtr_reg && config->flow_mreg_c
869 [id + start_reg - REG_C_0] >= priv->mtr_color_reg) {
870 if (id >= (uint32_t)(REG_C_7 - start_reg))
871 return rte_flow_error_set(error, EINVAL,
872 RTE_FLOW_ERROR_TYPE_ITEM,
873 NULL, "invalid tag id");
874 if (config->flow_mreg_c
875 [id + 1 + start_reg - REG_C_0] != REG_NON)
876 return config->flow_mreg_c
877 [id + 1 + start_reg - REG_C_0];
878 return rte_flow_error_set(error, ENOTSUP,
879 RTE_FLOW_ERROR_TYPE_ITEM,
880 NULL, "unsupported tag id");
882 return config->flow_mreg_c[id + start_reg - REG_C_0];
885 return rte_flow_error_set(error, EINVAL,
886 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
887 NULL, "invalid feature name");
891 * Check extensive flow metadata register support.
894 * Pointer to rte_eth_dev structure.
897 * True if device supports extensive flow metadata register, otherwise false.
900 mlx5_flow_ext_mreg_supported(struct rte_eth_dev *dev)
902 struct mlx5_priv *priv = dev->data->dev_private;
903 struct mlx5_dev_config *config = &priv->config;
906 * Having available reg_c can be regarded inclusively as supporting
907 * extensive flow metadata register, which could mean,
908 * - metadata register copy action by modify header.
909 * - 16 modify header actions is supported.
910 * - reg_c's are preserved across different domain (FDB and NIC) on
911 * packet loopback by flow lookup miss.
913 return config->flow_mreg_c[2] != REG_NON;
917 * Get the lowest priority.
920 * Pointer to the Ethernet device structure.
921 * @param[in] attributes
922 * Pointer to device flow rule attributes.
925 * The value of lowest priority of flow.
928 mlx5_get_lowest_priority(struct rte_eth_dev *dev,
929 const struct rte_flow_attr *attr)
931 struct mlx5_priv *priv = dev->data->dev_private;
933 if (!attr->group && !attr->transfer)
934 return priv->config.flow_prio - 2;
935 return MLX5_NON_ROOT_FLOW_MAX_PRIO - 1;
939 * Calculate matcher priority of the flow.
942 * Pointer to the Ethernet device structure.
944 * Pointer to device flow rule attributes.
945 * @param[in] subpriority
946 * The priority based on the items.
948 * The matcher priority of the flow.
951 mlx5_get_matcher_priority(struct rte_eth_dev *dev,
952 const struct rte_flow_attr *attr,
953 uint32_t subpriority)
955 uint16_t priority = (uint16_t)attr->priority;
956 struct mlx5_priv *priv = dev->data->dev_private;
958 if (!attr->group && !attr->transfer) {
959 if (attr->priority == MLX5_FLOW_LOWEST_PRIO_INDICATOR)
960 priority = priv->config.flow_prio - 1;
961 return mlx5_os_flow_adjust_priority(dev, priority, subpriority);
963 if (attr->priority == MLX5_FLOW_LOWEST_PRIO_INDICATOR)
964 priority = MLX5_NON_ROOT_FLOW_MAX_PRIO;
965 return priority * 3 + subpriority;
969 * Verify the @p item specifications (spec, last, mask) are compatible with the
973 * Item specification.
975 * @p item->mask or flow default bit-masks.
976 * @param[in] nic_mask
977 * Bit-masks covering supported fields by the NIC to compare with user mask.
979 * Bit-masks size in bytes.
980 * @param[in] range_accepted
981 * True if range of values is accepted for specific fields, false otherwise.
983 * Pointer to error structure.
986 * 0 on success, a negative errno value otherwise and rte_errno is set.
989 mlx5_flow_item_acceptable(const struct rte_flow_item *item,
991 const uint8_t *nic_mask,
994 struct rte_flow_error *error)
998 MLX5_ASSERT(nic_mask);
999 for (i = 0; i < size; ++i)
1000 if ((nic_mask[i] | mask[i]) != nic_mask[i])
1001 return rte_flow_error_set(error, ENOTSUP,
1002 RTE_FLOW_ERROR_TYPE_ITEM,
1004 "mask enables non supported"
1006 if (!item->spec && (item->mask || item->last))
1007 return rte_flow_error_set(error, EINVAL,
1008 RTE_FLOW_ERROR_TYPE_ITEM, item,
1009 "mask/last without a spec is not"
1011 if (item->spec && item->last && !range_accepted) {
1017 for (i = 0; i < size; ++i) {
1018 spec[i] = ((const uint8_t *)item->spec)[i] & mask[i];
1019 last[i] = ((const uint8_t *)item->last)[i] & mask[i];
1021 ret = memcmp(spec, last, size);
1023 return rte_flow_error_set(error, EINVAL,
1024 RTE_FLOW_ERROR_TYPE_ITEM,
1026 "range is not valid");
1032 * Adjust the hash fields according to the @p flow information.
1034 * @param[in] dev_flow.
1035 * Pointer to the mlx5_flow.
1037 * 1 when the hash field is for a tunnel item.
1038 * @param[in] layer_types
1040 * @param[in] hash_fields
1044 * The hash fields that should be used.
1047 mlx5_flow_hashfields_adjust(struct mlx5_flow_rss_desc *rss_desc,
1048 int tunnel __rte_unused, uint64_t layer_types,
1049 uint64_t hash_fields)
1051 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
1052 int rss_request_inner = rss_desc->level >= 2;
1054 /* Check RSS hash level for tunnel. */
1055 if (tunnel && rss_request_inner)
1056 hash_fields |= IBV_RX_HASH_INNER;
1057 else if (tunnel || rss_request_inner)
1060 /* Check if requested layer matches RSS hash fields. */
1061 if (!(rss_desc->types & layer_types))
1067 * Lookup and set the ptype in the data Rx part. A single Ptype can be used,
1068 * if several tunnel rules are used on this queue, the tunnel ptype will be
1072 * Rx queue to update.
1075 flow_rxq_tunnel_ptype_update(struct mlx5_rxq_ctrl *rxq_ctrl)
1078 uint32_t tunnel_ptype = 0;
1080 /* Look up for the ptype to use. */
1081 for (i = 0; i != MLX5_FLOW_TUNNEL; ++i) {
1082 if (!rxq_ctrl->flow_tunnels_n[i])
1084 if (!tunnel_ptype) {
1085 tunnel_ptype = tunnels_info[i].ptype;
1091 rxq_ctrl->rxq.tunnel = tunnel_ptype;
1095 * Set the Rx queue flags (Mark/Flag and Tunnel Ptypes) according to the devive
1099 * Pointer to the Ethernet device structure.
1100 * @param[in] dev_handle
1101 * Pointer to device flow handle structure.
1104 flow_drv_rxq_flags_set(struct rte_eth_dev *dev,
1105 struct mlx5_flow_handle *dev_handle)
1107 struct mlx5_priv *priv = dev->data->dev_private;
1108 const int mark = dev_handle->mark;
1109 const int tunnel = !!(dev_handle->layers & MLX5_FLOW_LAYER_TUNNEL);
1110 struct mlx5_ind_table_obj *ind_tbl = NULL;
1113 if (dev_handle->fate_action == MLX5_FLOW_FATE_QUEUE) {
1114 struct mlx5_hrxq *hrxq;
1116 hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
1117 dev_handle->rix_hrxq);
1119 ind_tbl = hrxq->ind_table;
1120 } else if (dev_handle->fate_action == MLX5_FLOW_FATE_SHARED_RSS) {
1121 struct mlx5_shared_action_rss *shared_rss;
1123 shared_rss = mlx5_ipool_get
1124 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
1125 dev_handle->rix_srss);
1127 ind_tbl = shared_rss->ind_tbl;
1131 for (i = 0; i != ind_tbl->queues_n; ++i) {
1132 int idx = ind_tbl->queues[i];
1133 struct mlx5_rxq_ctrl *rxq_ctrl =
1134 container_of((*priv->rxqs)[idx],
1135 struct mlx5_rxq_ctrl, rxq);
1138 * To support metadata register copy on Tx loopback,
1139 * this must be always enabled (metadata may arive
1140 * from other port - not from local flows only.
1142 if (priv->config.dv_flow_en &&
1143 priv->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
1144 mlx5_flow_ext_mreg_supported(dev)) {
1145 rxq_ctrl->rxq.mark = 1;
1146 rxq_ctrl->flow_mark_n = 1;
1148 rxq_ctrl->rxq.mark = 1;
1149 rxq_ctrl->flow_mark_n++;
1154 /* Increase the counter matching the flow. */
1155 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j) {
1156 if ((tunnels_info[j].tunnel &
1157 dev_handle->layers) ==
1158 tunnels_info[j].tunnel) {
1159 rxq_ctrl->flow_tunnels_n[j]++;
1163 flow_rxq_tunnel_ptype_update(rxq_ctrl);
1169 * Set the Rx queue flags (Mark/Flag and Tunnel Ptypes) for a flow
1172 * Pointer to the Ethernet device structure.
1174 * Pointer to flow structure.
1177 flow_rxq_flags_set(struct rte_eth_dev *dev, struct rte_flow *flow)
1179 struct mlx5_priv *priv = dev->data->dev_private;
1180 uint32_t handle_idx;
1181 struct mlx5_flow_handle *dev_handle;
1183 SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
1184 handle_idx, dev_handle, next)
1185 flow_drv_rxq_flags_set(dev, dev_handle);
1189 * Clear the Rx queue flags (Mark/Flag and Tunnel Ptype) associated with the
1190 * device flow if no other flow uses it with the same kind of request.
1193 * Pointer to Ethernet device.
1194 * @param[in] dev_handle
1195 * Pointer to the device flow handle structure.
1198 flow_drv_rxq_flags_trim(struct rte_eth_dev *dev,
1199 struct mlx5_flow_handle *dev_handle)
1201 struct mlx5_priv *priv = dev->data->dev_private;
1202 const int mark = dev_handle->mark;
1203 const int tunnel = !!(dev_handle->layers & MLX5_FLOW_LAYER_TUNNEL);
1204 struct mlx5_ind_table_obj *ind_tbl = NULL;
1207 if (dev_handle->fate_action == MLX5_FLOW_FATE_QUEUE) {
1208 struct mlx5_hrxq *hrxq;
1210 hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
1211 dev_handle->rix_hrxq);
1213 ind_tbl = hrxq->ind_table;
1214 } else if (dev_handle->fate_action == MLX5_FLOW_FATE_SHARED_RSS) {
1215 struct mlx5_shared_action_rss *shared_rss;
1217 shared_rss = mlx5_ipool_get
1218 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
1219 dev_handle->rix_srss);
1221 ind_tbl = shared_rss->ind_tbl;
1225 MLX5_ASSERT(dev->data->dev_started);
1226 for (i = 0; i != ind_tbl->queues_n; ++i) {
1227 int idx = ind_tbl->queues[i];
1228 struct mlx5_rxq_ctrl *rxq_ctrl =
1229 container_of((*priv->rxqs)[idx],
1230 struct mlx5_rxq_ctrl, rxq);
1232 if (priv->config.dv_flow_en &&
1233 priv->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
1234 mlx5_flow_ext_mreg_supported(dev)) {
1235 rxq_ctrl->rxq.mark = 1;
1236 rxq_ctrl->flow_mark_n = 1;
1238 rxq_ctrl->flow_mark_n--;
1239 rxq_ctrl->rxq.mark = !!rxq_ctrl->flow_mark_n;
1244 /* Decrease the counter matching the flow. */
1245 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j) {
1246 if ((tunnels_info[j].tunnel &
1247 dev_handle->layers) ==
1248 tunnels_info[j].tunnel) {
1249 rxq_ctrl->flow_tunnels_n[j]--;
1253 flow_rxq_tunnel_ptype_update(rxq_ctrl);
1259 * Clear the Rx queue flags (Mark/Flag and Tunnel Ptype) associated with the
1260 * @p flow if no other flow uses it with the same kind of request.
1263 * Pointer to Ethernet device.
1265 * Pointer to the flow.
1268 flow_rxq_flags_trim(struct rte_eth_dev *dev, struct rte_flow *flow)
1270 struct mlx5_priv *priv = dev->data->dev_private;
1271 uint32_t handle_idx;
1272 struct mlx5_flow_handle *dev_handle;
1274 SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
1275 handle_idx, dev_handle, next)
1276 flow_drv_rxq_flags_trim(dev, dev_handle);
1280 * Clear the Mark/Flag and Tunnel ptype information in all Rx queues.
1283 * Pointer to Ethernet device.
1286 flow_rxq_flags_clear(struct rte_eth_dev *dev)
1288 struct mlx5_priv *priv = dev->data->dev_private;
1291 for (i = 0; i != priv->rxqs_n; ++i) {
1292 struct mlx5_rxq_ctrl *rxq_ctrl;
1295 if (!(*priv->rxqs)[i])
1297 rxq_ctrl = container_of((*priv->rxqs)[i],
1298 struct mlx5_rxq_ctrl, rxq);
1299 rxq_ctrl->flow_mark_n = 0;
1300 rxq_ctrl->rxq.mark = 0;
1301 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j)
1302 rxq_ctrl->flow_tunnels_n[j] = 0;
1303 rxq_ctrl->rxq.tunnel = 0;
1308 * Set the Rx queue dynamic metadata (mask and offset) for a flow
1311 * Pointer to the Ethernet device structure.
1314 mlx5_flow_rxq_dynf_metadata_set(struct rte_eth_dev *dev)
1316 struct mlx5_priv *priv = dev->data->dev_private;
1317 struct mlx5_rxq_data *data;
1320 for (i = 0; i != priv->rxqs_n; ++i) {
1321 if (!(*priv->rxqs)[i])
1323 data = (*priv->rxqs)[i];
1324 if (!rte_flow_dynf_metadata_avail()) {
1325 data->dynf_meta = 0;
1326 data->flow_meta_mask = 0;
1327 data->flow_meta_offset = -1;
1328 data->flow_meta_port_mask = 0;
1330 data->dynf_meta = 1;
1331 data->flow_meta_mask = rte_flow_dynf_metadata_mask;
1332 data->flow_meta_offset = rte_flow_dynf_metadata_offs;
1333 data->flow_meta_port_mask = priv->sh->dv_meta_mask;
1339 * return a pointer to the desired action in the list of actions.
1341 * @param[in] actions
1342 * The list of actions to search the action in.
1344 * The action to find.
1347 * Pointer to the action in the list, if found. NULL otherwise.
1349 const struct rte_flow_action *
1350 mlx5_flow_find_action(const struct rte_flow_action *actions,
1351 enum rte_flow_action_type action)
1353 if (actions == NULL)
1355 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++)
1356 if (actions->type == action)
1362 * Validate the flag action.
1364 * @param[in] action_flags
1365 * Bit-fields that holds the actions detected until now.
1367 * Attributes of flow that includes this action.
1369 * Pointer to error structure.
1372 * 0 on success, a negative errno value otherwise and rte_errno is set.
1375 mlx5_flow_validate_action_flag(uint64_t action_flags,
1376 const struct rte_flow_attr *attr,
1377 struct rte_flow_error *error)
1379 if (action_flags & MLX5_FLOW_ACTION_MARK)
1380 return rte_flow_error_set(error, EINVAL,
1381 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1382 "can't mark and flag in same flow");
1383 if (action_flags & MLX5_FLOW_ACTION_FLAG)
1384 return rte_flow_error_set(error, EINVAL,
1385 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1387 " actions in same flow");
1389 return rte_flow_error_set(error, ENOTSUP,
1390 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1391 "flag action not supported for "
1397 * Validate the mark action.
1400 * Pointer to the queue action.
1401 * @param[in] action_flags
1402 * Bit-fields that holds the actions detected until now.
1404 * Attributes of flow that includes this action.
1406 * Pointer to error structure.
1409 * 0 on success, a negative errno value otherwise and rte_errno is set.
1412 mlx5_flow_validate_action_mark(const struct rte_flow_action *action,
1413 uint64_t action_flags,
1414 const struct rte_flow_attr *attr,
1415 struct rte_flow_error *error)
1417 const struct rte_flow_action_mark *mark = action->conf;
1420 return rte_flow_error_set(error, EINVAL,
1421 RTE_FLOW_ERROR_TYPE_ACTION,
1423 "configuration cannot be null");
1424 if (mark->id >= MLX5_FLOW_MARK_MAX)
1425 return rte_flow_error_set(error, EINVAL,
1426 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1428 "mark id must in 0 <= id < "
1429 RTE_STR(MLX5_FLOW_MARK_MAX));
1430 if (action_flags & MLX5_FLOW_ACTION_FLAG)
1431 return rte_flow_error_set(error, EINVAL,
1432 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1433 "can't flag and mark in same flow");
1434 if (action_flags & MLX5_FLOW_ACTION_MARK)
1435 return rte_flow_error_set(error, EINVAL,
1436 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1437 "can't have 2 mark actions in same"
1440 return rte_flow_error_set(error, ENOTSUP,
1441 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1442 "mark action not supported for "
1448 * Validate the drop action.
1450 * @param[in] action_flags
1451 * Bit-fields that holds the actions detected until now.
1453 * Attributes of flow that includes this action.
1455 * Pointer to error structure.
1458 * 0 on success, a negative errno value otherwise and rte_errno is set.
1461 mlx5_flow_validate_action_drop(uint64_t action_flags __rte_unused,
1462 const struct rte_flow_attr *attr,
1463 struct rte_flow_error *error)
1466 return rte_flow_error_set(error, ENOTSUP,
1467 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1468 "drop action not supported for "
1474 * Validate the queue action.
1477 * Pointer to the queue action.
1478 * @param[in] action_flags
1479 * Bit-fields that holds the actions detected until now.
1481 * Pointer to the Ethernet device structure.
1483 * Attributes of flow that includes this action.
1485 * Pointer to error structure.
1488 * 0 on success, a negative errno value otherwise and rte_errno is set.
1491 mlx5_flow_validate_action_queue(const struct rte_flow_action *action,
1492 uint64_t action_flags,
1493 struct rte_eth_dev *dev,
1494 const struct rte_flow_attr *attr,
1495 struct rte_flow_error *error)
1497 struct mlx5_priv *priv = dev->data->dev_private;
1498 const struct rte_flow_action_queue *queue = action->conf;
1500 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
1501 return rte_flow_error_set(error, EINVAL,
1502 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1503 "can't have 2 fate actions in"
1506 return rte_flow_error_set(error, EINVAL,
1507 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1508 NULL, "No Rx queues configured");
1509 if (queue->index >= priv->rxqs_n)
1510 return rte_flow_error_set(error, EINVAL,
1511 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1513 "queue index out of range");
1514 if (!(*priv->rxqs)[queue->index])
1515 return rte_flow_error_set(error, EINVAL,
1516 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1518 "queue is not configured");
1520 return rte_flow_error_set(error, ENOTSUP,
1521 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1522 "queue action not supported for "
1528 * Validate the rss action.
1531 * Pointer to the Ethernet device structure.
1533 * Pointer to the queue action.
1535 * Pointer to error structure.
1538 * 0 on success, a negative errno value otherwise and rte_errno is set.
1541 mlx5_validate_action_rss(struct rte_eth_dev *dev,
1542 const struct rte_flow_action *action,
1543 struct rte_flow_error *error)
1545 struct mlx5_priv *priv = dev->data->dev_private;
1546 const struct rte_flow_action_rss *rss = action->conf;
1547 enum mlx5_rxq_type rxq_type = MLX5_RXQ_TYPE_UNDEFINED;
1550 if (rss->func != RTE_ETH_HASH_FUNCTION_DEFAULT &&
1551 rss->func != RTE_ETH_HASH_FUNCTION_TOEPLITZ)
1552 return rte_flow_error_set(error, ENOTSUP,
1553 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1555 "RSS hash function not supported");
1556 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
1561 return rte_flow_error_set(error, ENOTSUP,
1562 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1564 "tunnel RSS is not supported");
1565 /* allow RSS key_len 0 in case of NULL (default) RSS key. */
1566 if (rss->key_len == 0 && rss->key != NULL)
1567 return rte_flow_error_set(error, ENOTSUP,
1568 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1570 "RSS hash key length 0");
1571 if (rss->key_len > 0 && rss->key_len < MLX5_RSS_HASH_KEY_LEN)
1572 return rte_flow_error_set(error, ENOTSUP,
1573 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1575 "RSS hash key too small");
1576 if (rss->key_len > MLX5_RSS_HASH_KEY_LEN)
1577 return rte_flow_error_set(error, ENOTSUP,
1578 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1580 "RSS hash key too large");
1581 if (rss->queue_num > priv->config.ind_table_max_size)
1582 return rte_flow_error_set(error, ENOTSUP,
1583 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1585 "number of queues too large");
1586 if (rss->types & MLX5_RSS_HF_MASK)
1587 return rte_flow_error_set(error, ENOTSUP,
1588 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1590 "some RSS protocols are not"
1592 if ((rss->types & (ETH_RSS_L3_SRC_ONLY | ETH_RSS_L3_DST_ONLY)) &&
1593 !(rss->types & ETH_RSS_IP))
1594 return rte_flow_error_set(error, EINVAL,
1595 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1596 "L3 partial RSS requested but L3 RSS"
1597 " type not specified");
1598 if ((rss->types & (ETH_RSS_L4_SRC_ONLY | ETH_RSS_L4_DST_ONLY)) &&
1599 !(rss->types & (ETH_RSS_UDP | ETH_RSS_TCP)))
1600 return rte_flow_error_set(error, EINVAL,
1601 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1602 "L4 partial RSS requested but L4 RSS"
1603 " type not specified");
1605 return rte_flow_error_set(error, EINVAL,
1606 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1607 NULL, "No Rx queues configured");
1608 if (!rss->queue_num)
1609 return rte_flow_error_set(error, EINVAL,
1610 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1611 NULL, "No queues configured");
1612 for (i = 0; i != rss->queue_num; ++i) {
1613 struct mlx5_rxq_ctrl *rxq_ctrl;
1615 if (rss->queue[i] >= priv->rxqs_n)
1616 return rte_flow_error_set
1618 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1619 &rss->queue[i], "queue index out of range");
1620 if (!(*priv->rxqs)[rss->queue[i]])
1621 return rte_flow_error_set
1622 (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1623 &rss->queue[i], "queue is not configured");
1624 rxq_ctrl = container_of((*priv->rxqs)[rss->queue[i]],
1625 struct mlx5_rxq_ctrl, rxq);
1627 rxq_type = rxq_ctrl->type;
1628 if (rxq_type != rxq_ctrl->type)
1629 return rte_flow_error_set
1630 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1632 "combining hairpin and regular RSS queues is not supported");
1638 * Validate the rss action.
1641 * Pointer to the queue action.
1642 * @param[in] action_flags
1643 * Bit-fields that holds the actions detected until now.
1645 * Pointer to the Ethernet device structure.
1647 * Attributes of flow that includes this action.
1648 * @param[in] item_flags
1649 * Items that were detected.
1651 * Pointer to error structure.
1654 * 0 on success, a negative errno value otherwise and rte_errno is set.
1657 mlx5_flow_validate_action_rss(const struct rte_flow_action *action,
1658 uint64_t action_flags,
1659 struct rte_eth_dev *dev,
1660 const struct rte_flow_attr *attr,
1661 uint64_t item_flags,
1662 struct rte_flow_error *error)
1664 const struct rte_flow_action_rss *rss = action->conf;
1665 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1668 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
1669 return rte_flow_error_set(error, EINVAL,
1670 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1671 "can't have 2 fate actions"
1673 ret = mlx5_validate_action_rss(dev, action, error);
1677 return rte_flow_error_set(error, ENOTSUP,
1678 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1679 "rss action not supported for "
1681 if (rss->level > 1 && !tunnel)
1682 return rte_flow_error_set(error, EINVAL,
1683 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1684 "inner RSS is not supported for "
1685 "non-tunnel flows");
1686 if ((item_flags & MLX5_FLOW_LAYER_ECPRI) &&
1687 !(item_flags & MLX5_FLOW_LAYER_INNER_L4_UDP)) {
1688 return rte_flow_error_set(error, EINVAL,
1689 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1690 "RSS on eCPRI is not supported now");
1692 if ((item_flags & MLX5_FLOW_LAYER_MPLS) &&
1694 (MLX5_FLOW_LAYER_INNER_L2 | MLX5_FLOW_LAYER_INNER_L3)) &&
1696 return rte_flow_error_set(error, EINVAL,
1697 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
1698 "MPLS inner RSS needs to specify inner L2/L3 items after MPLS in pattern");
1703 * Validate the default miss action.
1705 * @param[in] action_flags
1706 * Bit-fields that holds the actions detected until now.
1708 * Pointer to error structure.
1711 * 0 on success, a negative errno value otherwise and rte_errno is set.
1714 mlx5_flow_validate_action_default_miss(uint64_t action_flags,
1715 const struct rte_flow_attr *attr,
1716 struct rte_flow_error *error)
1718 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
1719 return rte_flow_error_set(error, EINVAL,
1720 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1721 "can't have 2 fate actions in"
1724 return rte_flow_error_set(error, ENOTSUP,
1725 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1726 "default miss action not supported "
1729 return rte_flow_error_set(error, ENOTSUP,
1730 RTE_FLOW_ERROR_TYPE_ATTR_GROUP, NULL,
1731 "only group 0 is supported");
1733 return rte_flow_error_set(error, ENOTSUP,
1734 RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
1735 NULL, "transfer is not supported");
1740 * Validate the count action.
1743 * Pointer to the Ethernet device structure.
1745 * Attributes of flow that includes this action.
1747 * Pointer to error structure.
1750 * 0 on success, a negative errno value otherwise and rte_errno is set.
1753 mlx5_flow_validate_action_count(struct rte_eth_dev *dev __rte_unused,
1754 const struct rte_flow_attr *attr,
1755 struct rte_flow_error *error)
1758 return rte_flow_error_set(error, ENOTSUP,
1759 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1760 "count action not supported for "
1766 * Validate the ASO CT action.
1769 * Pointer to the Ethernet device structure.
1770 * @param[in] conntrack
1771 * Pointer to the CT action profile.
1773 * Pointer to error structure.
1776 * 0 on success, a negative errno value otherwise and rte_errno is set.
1779 mlx5_validate_action_ct(struct rte_eth_dev *dev,
1780 const struct rte_flow_action_conntrack *conntrack,
1781 struct rte_flow_error *error)
1785 if (conntrack->state > RTE_FLOW_CONNTRACK_STATE_TIME_WAIT)
1786 return rte_flow_error_set(error, EINVAL,
1787 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1788 "Invalid CT state");
1789 if (conntrack->last_index > RTE_FLOW_CONNTRACK_FLAG_RST)
1790 return rte_flow_error_set(error, EINVAL,
1791 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1792 "Invalid last TCP packet flag");
1797 * Verify the @p attributes will be correctly understood by the NIC and store
1798 * them in the @p flow if everything is correct.
1801 * Pointer to the Ethernet device structure.
1802 * @param[in] attributes
1803 * Pointer to flow attributes
1805 * Pointer to error structure.
1808 * 0 on success, a negative errno value otherwise and rte_errno is set.
1811 mlx5_flow_validate_attributes(struct rte_eth_dev *dev,
1812 const struct rte_flow_attr *attributes,
1813 struct rte_flow_error *error)
1815 struct mlx5_priv *priv = dev->data->dev_private;
1816 uint32_t priority_max = priv->config.flow_prio - 1;
1818 if (attributes->group)
1819 return rte_flow_error_set(error, ENOTSUP,
1820 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
1821 NULL, "groups is not supported");
1822 if (attributes->priority != MLX5_FLOW_LOWEST_PRIO_INDICATOR &&
1823 attributes->priority >= priority_max)
1824 return rte_flow_error_set(error, ENOTSUP,
1825 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
1826 NULL, "priority out of range");
1827 if (attributes->egress)
1828 return rte_flow_error_set(error, ENOTSUP,
1829 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1830 "egress is not supported");
1831 if (attributes->transfer && !priv->config.dv_esw_en)
1832 return rte_flow_error_set(error, ENOTSUP,
1833 RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
1834 NULL, "transfer is not supported");
1835 if (!attributes->ingress)
1836 return rte_flow_error_set(error, EINVAL,
1837 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
1839 "ingress attribute is mandatory");
1844 * Validate ICMP6 item.
1847 * Item specification.
1848 * @param[in] item_flags
1849 * Bit-fields that holds the items detected until now.
1850 * @param[in] ext_vlan_sup
1851 * Whether extended VLAN features are supported or not.
1853 * Pointer to error structure.
1856 * 0 on success, a negative errno value otherwise and rte_errno is set.
1859 mlx5_flow_validate_item_icmp6(const struct rte_flow_item *item,
1860 uint64_t item_flags,
1861 uint8_t target_protocol,
1862 struct rte_flow_error *error)
1864 const struct rte_flow_item_icmp6 *mask = item->mask;
1865 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1866 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
1867 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
1868 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1869 MLX5_FLOW_LAYER_OUTER_L4;
1872 if (target_protocol != 0xFF && target_protocol != IPPROTO_ICMPV6)
1873 return rte_flow_error_set(error, EINVAL,
1874 RTE_FLOW_ERROR_TYPE_ITEM, item,
1875 "protocol filtering not compatible"
1876 " with ICMP6 layer");
1877 if (!(item_flags & l3m))
1878 return rte_flow_error_set(error, EINVAL,
1879 RTE_FLOW_ERROR_TYPE_ITEM, item,
1880 "IPv6 is mandatory to filter on"
1882 if (item_flags & l4m)
1883 return rte_flow_error_set(error, EINVAL,
1884 RTE_FLOW_ERROR_TYPE_ITEM, item,
1885 "multiple L4 layers not supported");
1887 mask = &rte_flow_item_icmp6_mask;
1888 ret = mlx5_flow_item_acceptable
1889 (item, (const uint8_t *)mask,
1890 (const uint8_t *)&rte_flow_item_icmp6_mask,
1891 sizeof(struct rte_flow_item_icmp6),
1892 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
1899 * Validate ICMP item.
1902 * Item specification.
1903 * @param[in] item_flags
1904 * Bit-fields that holds the items detected until now.
1906 * Pointer to error structure.
1909 * 0 on success, a negative errno value otherwise and rte_errno is set.
1912 mlx5_flow_validate_item_icmp(const struct rte_flow_item *item,
1913 uint64_t item_flags,
1914 uint8_t target_protocol,
1915 struct rte_flow_error *error)
1917 const struct rte_flow_item_icmp *mask = item->mask;
1918 const struct rte_flow_item_icmp nic_mask = {
1919 .hdr.icmp_type = 0xff,
1920 .hdr.icmp_code = 0xff,
1921 .hdr.icmp_ident = RTE_BE16(0xffff),
1922 .hdr.icmp_seq_nb = RTE_BE16(0xffff),
1924 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1925 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
1926 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
1927 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1928 MLX5_FLOW_LAYER_OUTER_L4;
1931 if (target_protocol != 0xFF && target_protocol != IPPROTO_ICMP)
1932 return rte_flow_error_set(error, EINVAL,
1933 RTE_FLOW_ERROR_TYPE_ITEM, item,
1934 "protocol filtering not compatible"
1935 " with ICMP layer");
1936 if (!(item_flags & l3m))
1937 return rte_flow_error_set(error, EINVAL,
1938 RTE_FLOW_ERROR_TYPE_ITEM, item,
1939 "IPv4 is mandatory to filter"
1941 if (item_flags & l4m)
1942 return rte_flow_error_set(error, EINVAL,
1943 RTE_FLOW_ERROR_TYPE_ITEM, item,
1944 "multiple L4 layers not supported");
1947 ret = mlx5_flow_item_acceptable
1948 (item, (const uint8_t *)mask,
1949 (const uint8_t *)&nic_mask,
1950 sizeof(struct rte_flow_item_icmp),
1951 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
1958 * Validate Ethernet item.
1961 * Item specification.
1962 * @param[in] item_flags
1963 * Bit-fields that holds the items detected until now.
1965 * Pointer to error structure.
1968 * 0 on success, a negative errno value otherwise and rte_errno is set.
1971 mlx5_flow_validate_item_eth(const struct rte_flow_item *item,
1972 uint64_t item_flags, bool ext_vlan_sup,
1973 struct rte_flow_error *error)
1975 const struct rte_flow_item_eth *mask = item->mask;
1976 const struct rte_flow_item_eth nic_mask = {
1977 .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
1978 .src.addr_bytes = "\xff\xff\xff\xff\xff\xff",
1979 .type = RTE_BE16(0xffff),
1980 .has_vlan = ext_vlan_sup ? 1 : 0,
1983 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1984 const uint64_t ethm = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
1985 MLX5_FLOW_LAYER_OUTER_L2;
1987 if (item_flags & ethm)
1988 return rte_flow_error_set(error, ENOTSUP,
1989 RTE_FLOW_ERROR_TYPE_ITEM, item,
1990 "multiple L2 layers not supported");
1991 if ((!tunnel && (item_flags & MLX5_FLOW_LAYER_OUTER_L3)) ||
1992 (tunnel && (item_flags & MLX5_FLOW_LAYER_INNER_L3)))
1993 return rte_flow_error_set(error, EINVAL,
1994 RTE_FLOW_ERROR_TYPE_ITEM, item,
1995 "L2 layer should not follow "
1997 if ((!tunnel && (item_flags & MLX5_FLOW_LAYER_OUTER_VLAN)) ||
1998 (tunnel && (item_flags & MLX5_FLOW_LAYER_INNER_VLAN)))
1999 return rte_flow_error_set(error, EINVAL,
2000 RTE_FLOW_ERROR_TYPE_ITEM, item,
2001 "L2 layer should not follow VLAN");
2002 if (item_flags & MLX5_FLOW_LAYER_GTP)
2003 return rte_flow_error_set(error, EINVAL,
2004 RTE_FLOW_ERROR_TYPE_ITEM, item,
2005 "L2 layer should not follow GTP");
2007 mask = &rte_flow_item_eth_mask;
2008 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2009 (const uint8_t *)&nic_mask,
2010 sizeof(struct rte_flow_item_eth),
2011 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2016 * Validate VLAN item.
2019 * Item specification.
2020 * @param[in] item_flags
2021 * Bit-fields that holds the items detected until now.
2023 * Ethernet device flow is being created on.
2025 * Pointer to error structure.
2028 * 0 on success, a negative errno value otherwise and rte_errno is set.
2031 mlx5_flow_validate_item_vlan(const struct rte_flow_item *item,
2032 uint64_t item_flags,
2033 struct rte_eth_dev *dev,
2034 struct rte_flow_error *error)
2036 const struct rte_flow_item_vlan *spec = item->spec;
2037 const struct rte_flow_item_vlan *mask = item->mask;
2038 const struct rte_flow_item_vlan nic_mask = {
2039 .tci = RTE_BE16(UINT16_MAX),
2040 .inner_type = RTE_BE16(UINT16_MAX),
2042 uint16_t vlan_tag = 0;
2043 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2045 const uint64_t l34m = tunnel ? (MLX5_FLOW_LAYER_INNER_L3 |
2046 MLX5_FLOW_LAYER_INNER_L4) :
2047 (MLX5_FLOW_LAYER_OUTER_L3 |
2048 MLX5_FLOW_LAYER_OUTER_L4);
2049 const uint64_t vlanm = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
2050 MLX5_FLOW_LAYER_OUTER_VLAN;
2052 if (item_flags & vlanm)
2053 return rte_flow_error_set(error, EINVAL,
2054 RTE_FLOW_ERROR_TYPE_ITEM, item,
2055 "multiple VLAN layers not supported");
2056 else if ((item_flags & l34m) != 0)
2057 return rte_flow_error_set(error, EINVAL,
2058 RTE_FLOW_ERROR_TYPE_ITEM, item,
2059 "VLAN cannot follow L3/L4 layer");
2061 mask = &rte_flow_item_vlan_mask;
2062 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2063 (const uint8_t *)&nic_mask,
2064 sizeof(struct rte_flow_item_vlan),
2065 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2068 if (!tunnel && mask->tci != RTE_BE16(0x0fff)) {
2069 struct mlx5_priv *priv = dev->data->dev_private;
2071 if (priv->vmwa_context) {
2073 * Non-NULL context means we have a virtual machine
2074 * and SR-IOV enabled, we have to create VLAN interface
2075 * to make hypervisor to setup E-Switch vport
2076 * context correctly. We avoid creating the multiple
2077 * VLAN interfaces, so we cannot support VLAN tag mask.
2079 return rte_flow_error_set(error, EINVAL,
2080 RTE_FLOW_ERROR_TYPE_ITEM,
2082 "VLAN tag mask is not"
2083 " supported in virtual"
2088 vlan_tag = spec->tci;
2089 vlan_tag &= mask->tci;
2092 * From verbs perspective an empty VLAN is equivalent
2093 * to a packet without VLAN layer.
2096 return rte_flow_error_set(error, EINVAL,
2097 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
2099 "VLAN cannot be empty");
2104 * Validate IPV4 item.
2107 * Item specification.
2108 * @param[in] item_flags
2109 * Bit-fields that holds the items detected until now.
2110 * @param[in] last_item
2111 * Previous validated item in the pattern items.
2112 * @param[in] ether_type
2113 * Type in the ethernet layer header (including dot1q).
2114 * @param[in] acc_mask
2115 * Acceptable mask, if NULL default internal default mask
2116 * will be used to check whether item fields are supported.
2117 * @param[in] range_accepted
2118 * True if range of values is accepted for specific fields, false otherwise.
2120 * Pointer to error structure.
2123 * 0 on success, a negative errno value otherwise and rte_errno is set.
2126 mlx5_flow_validate_item_ipv4(const struct rte_flow_item *item,
2127 uint64_t item_flags,
2129 uint16_t ether_type,
2130 const struct rte_flow_item_ipv4 *acc_mask,
2131 bool range_accepted,
2132 struct rte_flow_error *error)
2134 const struct rte_flow_item_ipv4 *mask = item->mask;
2135 const struct rte_flow_item_ipv4 *spec = item->spec;
2136 const struct rte_flow_item_ipv4 nic_mask = {
2138 .src_addr = RTE_BE32(0xffffffff),
2139 .dst_addr = RTE_BE32(0xffffffff),
2140 .type_of_service = 0xff,
2141 .next_proto_id = 0xff,
2144 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2145 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2146 MLX5_FLOW_LAYER_OUTER_L3;
2147 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2148 MLX5_FLOW_LAYER_OUTER_L4;
2150 uint8_t next_proto = 0xFF;
2151 const uint64_t l2_vlan = (MLX5_FLOW_LAYER_L2 |
2152 MLX5_FLOW_LAYER_OUTER_VLAN |
2153 MLX5_FLOW_LAYER_INNER_VLAN);
2155 if ((last_item & l2_vlan) && ether_type &&
2156 ether_type != RTE_ETHER_TYPE_IPV4)
2157 return rte_flow_error_set(error, EINVAL,
2158 RTE_FLOW_ERROR_TYPE_ITEM, item,
2159 "IPv4 cannot follow L2/VLAN layer "
2160 "which ether type is not IPv4");
2161 if (item_flags & MLX5_FLOW_LAYER_TUNNEL) {
2163 next_proto = mask->hdr.next_proto_id &
2164 spec->hdr.next_proto_id;
2165 if (next_proto == IPPROTO_IPIP || next_proto == IPPROTO_IPV6)
2166 return rte_flow_error_set(error, EINVAL,
2167 RTE_FLOW_ERROR_TYPE_ITEM,
2172 if (item_flags & MLX5_FLOW_LAYER_IPV6_ENCAP)
2173 return rte_flow_error_set(error, EINVAL,
2174 RTE_FLOW_ERROR_TYPE_ITEM, item,
2175 "wrong tunnel type - IPv6 specified "
2176 "but IPv4 item provided");
2177 if (item_flags & l3m)
2178 return rte_flow_error_set(error, ENOTSUP,
2179 RTE_FLOW_ERROR_TYPE_ITEM, item,
2180 "multiple L3 layers not supported");
2181 else if (item_flags & l4m)
2182 return rte_flow_error_set(error, EINVAL,
2183 RTE_FLOW_ERROR_TYPE_ITEM, item,
2184 "L3 cannot follow an L4 layer.");
2185 else if ((item_flags & MLX5_FLOW_LAYER_NVGRE) &&
2186 !(item_flags & MLX5_FLOW_LAYER_INNER_L2))
2187 return rte_flow_error_set(error, EINVAL,
2188 RTE_FLOW_ERROR_TYPE_ITEM, item,
2189 "L3 cannot follow an NVGRE layer.");
2191 mask = &rte_flow_item_ipv4_mask;
2192 else if (mask->hdr.next_proto_id != 0 &&
2193 mask->hdr.next_proto_id != 0xff)
2194 return rte_flow_error_set(error, EINVAL,
2195 RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
2196 "partial mask is not supported"
2198 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2199 acc_mask ? (const uint8_t *)acc_mask
2200 : (const uint8_t *)&nic_mask,
2201 sizeof(struct rte_flow_item_ipv4),
2202 range_accepted, error);
2209 * Validate IPV6 item.
2212 * Item specification.
2213 * @param[in] item_flags
2214 * Bit-fields that holds the items detected until now.
2215 * @param[in] last_item
2216 * Previous validated item in the pattern items.
2217 * @param[in] ether_type
2218 * Type in the ethernet layer header (including dot1q).
2219 * @param[in] acc_mask
2220 * Acceptable mask, if NULL default internal default mask
2221 * will be used to check whether item fields are supported.
2223 * Pointer to error structure.
2226 * 0 on success, a negative errno value otherwise and rte_errno is set.
2229 mlx5_flow_validate_item_ipv6(const struct rte_flow_item *item,
2230 uint64_t item_flags,
2232 uint16_t ether_type,
2233 const struct rte_flow_item_ipv6 *acc_mask,
2234 struct rte_flow_error *error)
2236 const struct rte_flow_item_ipv6 *mask = item->mask;
2237 const struct rte_flow_item_ipv6 *spec = item->spec;
2238 const struct rte_flow_item_ipv6 nic_mask = {
2241 "\xff\xff\xff\xff\xff\xff\xff\xff"
2242 "\xff\xff\xff\xff\xff\xff\xff\xff",
2244 "\xff\xff\xff\xff\xff\xff\xff\xff"
2245 "\xff\xff\xff\xff\xff\xff\xff\xff",
2246 .vtc_flow = RTE_BE32(0xffffffff),
2250 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2251 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2252 MLX5_FLOW_LAYER_OUTER_L3;
2253 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2254 MLX5_FLOW_LAYER_OUTER_L4;
2256 uint8_t next_proto = 0xFF;
2257 const uint64_t l2_vlan = (MLX5_FLOW_LAYER_L2 |
2258 MLX5_FLOW_LAYER_OUTER_VLAN |
2259 MLX5_FLOW_LAYER_INNER_VLAN);
2261 if ((last_item & l2_vlan) && ether_type &&
2262 ether_type != RTE_ETHER_TYPE_IPV6)
2263 return rte_flow_error_set(error, EINVAL,
2264 RTE_FLOW_ERROR_TYPE_ITEM, item,
2265 "IPv6 cannot follow L2/VLAN layer "
2266 "which ether type is not IPv6");
2267 if (mask && mask->hdr.proto == UINT8_MAX && spec)
2268 next_proto = spec->hdr.proto;
2269 if (item_flags & MLX5_FLOW_LAYER_TUNNEL) {
2270 if (next_proto == IPPROTO_IPIP || next_proto == IPPROTO_IPV6)
2271 return rte_flow_error_set(error, EINVAL,
2272 RTE_FLOW_ERROR_TYPE_ITEM,
2277 if (next_proto == IPPROTO_HOPOPTS ||
2278 next_proto == IPPROTO_ROUTING ||
2279 next_proto == IPPROTO_FRAGMENT ||
2280 next_proto == IPPROTO_ESP ||
2281 next_proto == IPPROTO_AH ||
2282 next_proto == IPPROTO_DSTOPTS)
2283 return rte_flow_error_set(error, EINVAL,
2284 RTE_FLOW_ERROR_TYPE_ITEM, item,
2285 "IPv6 proto (next header) should "
2286 "not be set as extension header");
2287 if (item_flags & MLX5_FLOW_LAYER_IPIP)
2288 return rte_flow_error_set(error, EINVAL,
2289 RTE_FLOW_ERROR_TYPE_ITEM, item,
2290 "wrong tunnel type - IPv4 specified "
2291 "but IPv6 item provided");
2292 if (item_flags & l3m)
2293 return rte_flow_error_set(error, ENOTSUP,
2294 RTE_FLOW_ERROR_TYPE_ITEM, item,
2295 "multiple L3 layers not supported");
2296 else if (item_flags & l4m)
2297 return rte_flow_error_set(error, EINVAL,
2298 RTE_FLOW_ERROR_TYPE_ITEM, item,
2299 "L3 cannot follow an L4 layer.");
2300 else if ((item_flags & MLX5_FLOW_LAYER_NVGRE) &&
2301 !(item_flags & MLX5_FLOW_LAYER_INNER_L2))
2302 return rte_flow_error_set(error, EINVAL,
2303 RTE_FLOW_ERROR_TYPE_ITEM, item,
2304 "L3 cannot follow an NVGRE layer.");
2306 mask = &rte_flow_item_ipv6_mask;
2307 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2308 acc_mask ? (const uint8_t *)acc_mask
2309 : (const uint8_t *)&nic_mask,
2310 sizeof(struct rte_flow_item_ipv6),
2311 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2318 * Validate UDP item.
2321 * Item specification.
2322 * @param[in] item_flags
2323 * Bit-fields that holds the items detected until now.
2324 * @param[in] target_protocol
2325 * The next protocol in the previous item.
2326 * @param[in] flow_mask
2327 * mlx5 flow-specific (DV, verbs, etc.) supported header fields mask.
2329 * Pointer to error structure.
2332 * 0 on success, a negative errno value otherwise and rte_errno is set.
2335 mlx5_flow_validate_item_udp(const struct rte_flow_item *item,
2336 uint64_t item_flags,
2337 uint8_t target_protocol,
2338 struct rte_flow_error *error)
2340 const struct rte_flow_item_udp *mask = item->mask;
2341 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2342 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2343 MLX5_FLOW_LAYER_OUTER_L3;
2344 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2345 MLX5_FLOW_LAYER_OUTER_L4;
2348 if (target_protocol != 0xff && target_protocol != IPPROTO_UDP)
2349 return rte_flow_error_set(error, EINVAL,
2350 RTE_FLOW_ERROR_TYPE_ITEM, item,
2351 "protocol filtering not compatible"
2353 if (!(item_flags & l3m))
2354 return rte_flow_error_set(error, EINVAL,
2355 RTE_FLOW_ERROR_TYPE_ITEM, item,
2356 "L3 is mandatory to filter on L4");
2357 if (item_flags & l4m)
2358 return rte_flow_error_set(error, EINVAL,
2359 RTE_FLOW_ERROR_TYPE_ITEM, item,
2360 "multiple L4 layers not supported");
2362 mask = &rte_flow_item_udp_mask;
2363 ret = mlx5_flow_item_acceptable
2364 (item, (const uint8_t *)mask,
2365 (const uint8_t *)&rte_flow_item_udp_mask,
2366 sizeof(struct rte_flow_item_udp), MLX5_ITEM_RANGE_NOT_ACCEPTED,
2374 * Validate TCP item.
2377 * Item specification.
2378 * @param[in] item_flags
2379 * Bit-fields that holds the items detected until now.
2380 * @param[in] target_protocol
2381 * The next protocol in the previous item.
2383 * Pointer to error structure.
2386 * 0 on success, a negative errno value otherwise and rte_errno is set.
2389 mlx5_flow_validate_item_tcp(const struct rte_flow_item *item,
2390 uint64_t item_flags,
2391 uint8_t target_protocol,
2392 const struct rte_flow_item_tcp *flow_mask,
2393 struct rte_flow_error *error)
2395 const struct rte_flow_item_tcp *mask = item->mask;
2396 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2397 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2398 MLX5_FLOW_LAYER_OUTER_L3;
2399 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2400 MLX5_FLOW_LAYER_OUTER_L4;
2403 MLX5_ASSERT(flow_mask);
2404 if (target_protocol != 0xff && target_protocol != IPPROTO_TCP)
2405 return rte_flow_error_set(error, EINVAL,
2406 RTE_FLOW_ERROR_TYPE_ITEM, item,
2407 "protocol filtering not compatible"
2409 if (!(item_flags & l3m))
2410 return rte_flow_error_set(error, EINVAL,
2411 RTE_FLOW_ERROR_TYPE_ITEM, item,
2412 "L3 is mandatory to filter on L4");
2413 if (item_flags & l4m)
2414 return rte_flow_error_set(error, EINVAL,
2415 RTE_FLOW_ERROR_TYPE_ITEM, item,
2416 "multiple L4 layers not supported");
2418 mask = &rte_flow_item_tcp_mask;
2419 ret = mlx5_flow_item_acceptable
2420 (item, (const uint8_t *)mask,
2421 (const uint8_t *)flow_mask,
2422 sizeof(struct rte_flow_item_tcp), MLX5_ITEM_RANGE_NOT_ACCEPTED,
2430 * Validate VXLAN item.
2433 * Pointer to the Ethernet device structure.
2435 * Item specification.
2436 * @param[in] item_flags
2437 * Bit-fields that holds the items detected until now.
2439 * Flow rule attributes.
2441 * Pointer to error structure.
2444 * 0 on success, a negative errno value otherwise and rte_errno is set.
2447 mlx5_flow_validate_item_vxlan(struct rte_eth_dev *dev,
2448 const struct rte_flow_item *item,
2449 uint64_t item_flags,
2450 const struct rte_flow_attr *attr,
2451 struct rte_flow_error *error)
2453 const struct rte_flow_item_vxlan *spec = item->spec;
2454 const struct rte_flow_item_vxlan *mask = item->mask;
2456 struct mlx5_priv *priv = dev->data->dev_private;
2460 } id = { .vlan_id = 0, };
2461 const struct rte_flow_item_vxlan nic_mask = {
2462 .vni = "\xff\xff\xff",
2465 const struct rte_flow_item_vxlan *valid_mask;
2467 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2468 return rte_flow_error_set(error, ENOTSUP,
2469 RTE_FLOW_ERROR_TYPE_ITEM, item,
2470 "multiple tunnel layers not"
2472 valid_mask = &rte_flow_item_vxlan_mask;
2474 * Verify only UDPv4 is present as defined in
2475 * https://tools.ietf.org/html/rfc7348
2477 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2478 return rte_flow_error_set(error, EINVAL,
2479 RTE_FLOW_ERROR_TYPE_ITEM, item,
2480 "no outer UDP layer found");
2482 mask = &rte_flow_item_vxlan_mask;
2483 /* FDB domain & NIC domain non-zero group */
2484 if ((attr->transfer || attr->group) && priv->sh->misc5_cap)
2485 valid_mask = &nic_mask;
2486 /* Group zero in NIC domain */
2487 if (!attr->group && !attr->transfer && priv->sh->tunnel_header_0_1)
2488 valid_mask = &nic_mask;
2489 ret = mlx5_flow_item_acceptable
2490 (item, (const uint8_t *)mask,
2491 (const uint8_t *)valid_mask,
2492 sizeof(struct rte_flow_item_vxlan),
2493 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2497 memcpy(&id.vni[1], spec->vni, 3);
2498 memcpy(&id.vni[1], mask->vni, 3);
2500 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
2501 return rte_flow_error_set(error, ENOTSUP,
2502 RTE_FLOW_ERROR_TYPE_ITEM, item,
2503 "VXLAN tunnel must be fully defined");
2508 * Validate VXLAN_GPE item.
2511 * Item specification.
2512 * @param[in] item_flags
2513 * Bit-fields that holds the items detected until now.
2515 * Pointer to the private data structure.
2516 * @param[in] target_protocol
2517 * The next protocol in the previous item.
2519 * Pointer to error structure.
2522 * 0 on success, a negative errno value otherwise and rte_errno is set.
2525 mlx5_flow_validate_item_vxlan_gpe(const struct rte_flow_item *item,
2526 uint64_t item_flags,
2527 struct rte_eth_dev *dev,
2528 struct rte_flow_error *error)
2530 struct mlx5_priv *priv = dev->data->dev_private;
2531 const struct rte_flow_item_vxlan_gpe *spec = item->spec;
2532 const struct rte_flow_item_vxlan_gpe *mask = item->mask;
2537 } id = { .vlan_id = 0, };
2539 if (!priv->config.l3_vxlan_en)
2540 return rte_flow_error_set(error, ENOTSUP,
2541 RTE_FLOW_ERROR_TYPE_ITEM, item,
2542 "L3 VXLAN is not enabled by device"
2543 " parameter and/or not configured in"
2545 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2546 return rte_flow_error_set(error, ENOTSUP,
2547 RTE_FLOW_ERROR_TYPE_ITEM, item,
2548 "multiple tunnel layers not"
2551 * Verify only UDPv4 is present as defined in
2552 * https://tools.ietf.org/html/rfc7348
2554 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2555 return rte_flow_error_set(error, EINVAL,
2556 RTE_FLOW_ERROR_TYPE_ITEM, item,
2557 "no outer UDP layer found");
2559 mask = &rte_flow_item_vxlan_gpe_mask;
2560 ret = mlx5_flow_item_acceptable
2561 (item, (const uint8_t *)mask,
2562 (const uint8_t *)&rte_flow_item_vxlan_gpe_mask,
2563 sizeof(struct rte_flow_item_vxlan_gpe),
2564 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2569 return rte_flow_error_set(error, ENOTSUP,
2570 RTE_FLOW_ERROR_TYPE_ITEM,
2572 "VxLAN-GPE protocol"
2574 memcpy(&id.vni[1], spec->vni, 3);
2575 memcpy(&id.vni[1], mask->vni, 3);
2577 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
2578 return rte_flow_error_set(error, ENOTSUP,
2579 RTE_FLOW_ERROR_TYPE_ITEM, item,
2580 "VXLAN-GPE tunnel must be fully"
2585 * Validate GRE Key item.
2588 * Item specification.
2589 * @param[in] item_flags
2590 * Bit flags to mark detected items.
2591 * @param[in] gre_item
2592 * Pointer to gre_item
2594 * Pointer to error structure.
2597 * 0 on success, a negative errno value otherwise and rte_errno is set.
2600 mlx5_flow_validate_item_gre_key(const struct rte_flow_item *item,
2601 uint64_t item_flags,
2602 const struct rte_flow_item *gre_item,
2603 struct rte_flow_error *error)
2605 const rte_be32_t *mask = item->mask;
2607 rte_be32_t gre_key_default_mask = RTE_BE32(UINT32_MAX);
2608 const struct rte_flow_item_gre *gre_spec;
2609 const struct rte_flow_item_gre *gre_mask;
2611 if (item_flags & MLX5_FLOW_LAYER_GRE_KEY)
2612 return rte_flow_error_set(error, ENOTSUP,
2613 RTE_FLOW_ERROR_TYPE_ITEM, item,
2614 "Multiple GRE key not support");
2615 if (!(item_flags & MLX5_FLOW_LAYER_GRE))
2616 return rte_flow_error_set(error, ENOTSUP,
2617 RTE_FLOW_ERROR_TYPE_ITEM, item,
2618 "No preceding GRE header");
2619 if (item_flags & MLX5_FLOW_LAYER_INNER)
2620 return rte_flow_error_set(error, ENOTSUP,
2621 RTE_FLOW_ERROR_TYPE_ITEM, item,
2622 "GRE key following a wrong item");
2623 gre_mask = gre_item->mask;
2625 gre_mask = &rte_flow_item_gre_mask;
2626 gre_spec = gre_item->spec;
2627 if (gre_spec && (gre_mask->c_rsvd0_ver & RTE_BE16(0x2000)) &&
2628 !(gre_spec->c_rsvd0_ver & RTE_BE16(0x2000)))
2629 return rte_flow_error_set(error, EINVAL,
2630 RTE_FLOW_ERROR_TYPE_ITEM, item,
2631 "Key bit must be on");
2634 mask = &gre_key_default_mask;
2635 ret = mlx5_flow_item_acceptable
2636 (item, (const uint8_t *)mask,
2637 (const uint8_t *)&gre_key_default_mask,
2638 sizeof(rte_be32_t), MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2643 * Validate GRE item.
2646 * Item specification.
2647 * @param[in] item_flags
2648 * Bit flags to mark detected items.
2649 * @param[in] target_protocol
2650 * The next protocol in the previous item.
2652 * Pointer to error structure.
2655 * 0 on success, a negative errno value otherwise and rte_errno is set.
2658 mlx5_flow_validate_item_gre(const struct rte_flow_item *item,
2659 uint64_t item_flags,
2660 uint8_t target_protocol,
2661 struct rte_flow_error *error)
2663 const struct rte_flow_item_gre *spec __rte_unused = item->spec;
2664 const struct rte_flow_item_gre *mask = item->mask;
2666 const struct rte_flow_item_gre nic_mask = {
2667 .c_rsvd0_ver = RTE_BE16(0xB000),
2668 .protocol = RTE_BE16(UINT16_MAX),
2671 if (target_protocol != 0xff && target_protocol != IPPROTO_GRE)
2672 return rte_flow_error_set(error, EINVAL,
2673 RTE_FLOW_ERROR_TYPE_ITEM, item,
2674 "protocol filtering not compatible"
2675 " with this GRE layer");
2676 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2677 return rte_flow_error_set(error, ENOTSUP,
2678 RTE_FLOW_ERROR_TYPE_ITEM, item,
2679 "multiple tunnel layers not"
2681 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3))
2682 return rte_flow_error_set(error, ENOTSUP,
2683 RTE_FLOW_ERROR_TYPE_ITEM, item,
2684 "L3 Layer is missing");
2686 mask = &rte_flow_item_gre_mask;
2687 ret = mlx5_flow_item_acceptable
2688 (item, (const uint8_t *)mask,
2689 (const uint8_t *)&nic_mask,
2690 sizeof(struct rte_flow_item_gre), MLX5_ITEM_RANGE_NOT_ACCEPTED,
2694 #ifndef HAVE_MLX5DV_DR
2695 #ifndef HAVE_IBV_DEVICE_MPLS_SUPPORT
2696 if (spec && (spec->protocol & mask->protocol))
2697 return rte_flow_error_set(error, ENOTSUP,
2698 RTE_FLOW_ERROR_TYPE_ITEM, item,
2699 "without MPLS support the"
2700 " specification cannot be used for"
2708 * Validate Geneve item.
2711 * Item specification.
2712 * @param[in] itemFlags
2713 * Bit-fields that holds the items detected until now.
2715 * Pointer to the private data structure.
2717 * Pointer to error structure.
2720 * 0 on success, a negative errno value otherwise and rte_errno is set.
2724 mlx5_flow_validate_item_geneve(const struct rte_flow_item *item,
2725 uint64_t item_flags,
2726 struct rte_eth_dev *dev,
2727 struct rte_flow_error *error)
2729 struct mlx5_priv *priv = dev->data->dev_private;
2730 const struct rte_flow_item_geneve *spec = item->spec;
2731 const struct rte_flow_item_geneve *mask = item->mask;
2734 uint8_t opt_len = priv->config.hca_attr.geneve_max_opt_len ?
2735 MLX5_GENEVE_OPT_LEN_1 : MLX5_GENEVE_OPT_LEN_0;
2736 const struct rte_flow_item_geneve nic_mask = {
2737 .ver_opt_len_o_c_rsvd0 = RTE_BE16(0x3f80),
2738 .vni = "\xff\xff\xff",
2739 .protocol = RTE_BE16(UINT16_MAX),
2742 if (!priv->config.hca_attr.tunnel_stateless_geneve_rx)
2743 return rte_flow_error_set(error, ENOTSUP,
2744 RTE_FLOW_ERROR_TYPE_ITEM, item,
2745 "L3 Geneve is not enabled by device"
2746 " parameter and/or not configured in"
2748 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2749 return rte_flow_error_set(error, ENOTSUP,
2750 RTE_FLOW_ERROR_TYPE_ITEM, item,
2751 "multiple tunnel layers not"
2754 * Verify only UDPv4 is present as defined in
2755 * https://tools.ietf.org/html/rfc7348
2757 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2758 return rte_flow_error_set(error, EINVAL,
2759 RTE_FLOW_ERROR_TYPE_ITEM, item,
2760 "no outer UDP layer found");
2762 mask = &rte_flow_item_geneve_mask;
2763 ret = mlx5_flow_item_acceptable
2764 (item, (const uint8_t *)mask,
2765 (const uint8_t *)&nic_mask,
2766 sizeof(struct rte_flow_item_geneve),
2767 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2771 gbhdr = rte_be_to_cpu_16(spec->ver_opt_len_o_c_rsvd0);
2772 if (MLX5_GENEVE_VER_VAL(gbhdr) ||
2773 MLX5_GENEVE_CRITO_VAL(gbhdr) ||
2774 MLX5_GENEVE_RSVD_VAL(gbhdr) || spec->rsvd1)
2775 return rte_flow_error_set(error, ENOTSUP,
2776 RTE_FLOW_ERROR_TYPE_ITEM,
2778 "Geneve protocol unsupported"
2779 " fields are being used");
2780 if (MLX5_GENEVE_OPTLEN_VAL(gbhdr) > opt_len)
2781 return rte_flow_error_set
2783 RTE_FLOW_ERROR_TYPE_ITEM,
2785 "Unsupported Geneve options length");
2787 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
2788 return rte_flow_error_set
2790 RTE_FLOW_ERROR_TYPE_ITEM, item,
2791 "Geneve tunnel must be fully defined");
2796 * Validate Geneve TLV option item.
2799 * Item specification.
2800 * @param[in] last_item
2801 * Previous validated item in the pattern items.
2802 * @param[in] geneve_item
2803 * Previous GENEVE item specification.
2805 * Pointer to the rte_eth_dev structure.
2807 * Pointer to error structure.
2810 * 0 on success, a negative errno value otherwise and rte_errno is set.
2813 mlx5_flow_validate_item_geneve_opt(const struct rte_flow_item *item,
2815 const struct rte_flow_item *geneve_item,
2816 struct rte_eth_dev *dev,
2817 struct rte_flow_error *error)
2819 struct mlx5_priv *priv = dev->data->dev_private;
2820 struct mlx5_dev_ctx_shared *sh = priv->sh;
2821 struct mlx5_geneve_tlv_option_resource *geneve_opt_resource;
2822 struct mlx5_hca_attr *hca_attr = &priv->config.hca_attr;
2823 uint8_t data_max_supported =
2824 hca_attr->max_geneve_tlv_option_data_len * 4;
2825 struct mlx5_dev_config *config = &priv->config;
2826 const struct rte_flow_item_geneve *geneve_spec;
2827 const struct rte_flow_item_geneve *geneve_mask;
2828 const struct rte_flow_item_geneve_opt *spec = item->spec;
2829 const struct rte_flow_item_geneve_opt *mask = item->mask;
2831 unsigned int data_len;
2832 uint8_t tlv_option_len;
2833 uint16_t optlen_m, optlen_v;
2834 const struct rte_flow_item_geneve_opt full_mask = {
2835 .option_class = RTE_BE16(0xffff),
2836 .option_type = 0xff,
2841 mask = &rte_flow_item_geneve_opt_mask;
2843 return rte_flow_error_set
2844 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2845 "Geneve TLV opt class/type/length must be specified");
2846 if ((uint32_t)spec->option_len > MLX5_GENEVE_OPTLEN_MASK)
2847 return rte_flow_error_set
2848 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2849 "Geneve TLV opt length exceeeds the limit (31)");
2850 /* Check if class type and length masks are full. */
2851 if (full_mask.option_class != mask->option_class ||
2852 full_mask.option_type != mask->option_type ||
2853 full_mask.option_len != (mask->option_len & full_mask.option_len))
2854 return rte_flow_error_set
2855 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2856 "Geneve TLV opt class/type/length masks must be full");
2857 /* Check if length is supported */
2858 if ((uint32_t)spec->option_len >
2859 config->hca_attr.max_geneve_tlv_option_data_len)
2860 return rte_flow_error_set
2861 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2862 "Geneve TLV opt length not supported");
2863 if (config->hca_attr.max_geneve_tlv_options > 1)
2865 "max_geneve_tlv_options supports more than 1 option");
2866 /* Check GENEVE item preceding. */
2867 if (!geneve_item || !(last_item & MLX5_FLOW_LAYER_GENEVE))
2868 return rte_flow_error_set
2869 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2870 "Geneve opt item must be preceded with Geneve item");
2871 geneve_spec = geneve_item->spec;
2872 geneve_mask = geneve_item->mask ? geneve_item->mask :
2873 &rte_flow_item_geneve_mask;
2874 /* Check if GENEVE TLV option size doesn't exceed option length */
2875 if (geneve_spec && (geneve_mask->ver_opt_len_o_c_rsvd0 ||
2876 geneve_spec->ver_opt_len_o_c_rsvd0)) {
2877 tlv_option_len = spec->option_len & mask->option_len;
2878 optlen_v = rte_be_to_cpu_16(geneve_spec->ver_opt_len_o_c_rsvd0);
2879 optlen_v = MLX5_GENEVE_OPTLEN_VAL(optlen_v);
2880 optlen_m = rte_be_to_cpu_16(geneve_mask->ver_opt_len_o_c_rsvd0);
2881 optlen_m = MLX5_GENEVE_OPTLEN_VAL(optlen_m);
2882 if ((optlen_v & optlen_m) <= tlv_option_len)
2883 return rte_flow_error_set
2884 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2885 "GENEVE TLV option length exceeds optlen");
2887 /* Check if length is 0 or data is 0. */
2888 if (spec->data == NULL || spec->option_len == 0)
2889 return rte_flow_error_set
2890 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2891 "Geneve TLV opt with zero data/length not supported");
2892 /* Check not all data & mask are 0. */
2893 data_len = spec->option_len * 4;
2894 if (mask->data == NULL) {
2895 for (i = 0; i < data_len; i++)
2899 return rte_flow_error_set(error, ENOTSUP,
2900 RTE_FLOW_ERROR_TYPE_ITEM, item,
2901 "Can't match on Geneve option data 0");
2903 for (i = 0; i < data_len; i++)
2904 if (spec->data[i] & mask->data[i])
2907 return rte_flow_error_set(error, ENOTSUP,
2908 RTE_FLOW_ERROR_TYPE_ITEM, item,
2909 "Can't match on Geneve option data and mask 0");
2910 /* Check data mask supported. */
2911 for (i = data_max_supported; i < data_len ; i++)
2913 return rte_flow_error_set(error, ENOTSUP,
2914 RTE_FLOW_ERROR_TYPE_ITEM, item,
2915 "Data mask is of unsupported size");
2917 /* Check GENEVE option is supported in NIC. */
2918 if (!config->hca_attr.geneve_tlv_opt)
2919 return rte_flow_error_set
2920 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2921 "Geneve TLV opt not supported");
2922 /* Check if we already have geneve option with different type/class. */
2923 rte_spinlock_lock(&sh->geneve_tlv_opt_sl);
2924 geneve_opt_resource = sh->geneve_tlv_option_resource;
2925 if (geneve_opt_resource != NULL)
2926 if (geneve_opt_resource->option_class != spec->option_class ||
2927 geneve_opt_resource->option_type != spec->option_type ||
2928 geneve_opt_resource->length != spec->option_len) {
2929 rte_spinlock_unlock(&sh->geneve_tlv_opt_sl);
2930 return rte_flow_error_set(error, ENOTSUP,
2931 RTE_FLOW_ERROR_TYPE_ITEM, item,
2932 "Only one Geneve TLV option supported");
2934 rte_spinlock_unlock(&sh->geneve_tlv_opt_sl);
2939 * Validate MPLS item.
2942 * Pointer to the rte_eth_dev structure.
2944 * Item specification.
2945 * @param[in] item_flags
2946 * Bit-fields that holds the items detected until now.
2947 * @param[in] prev_layer
2948 * The protocol layer indicated in previous item.
2950 * Pointer to error structure.
2953 * 0 on success, a negative errno value otherwise and rte_errno is set.
2956 mlx5_flow_validate_item_mpls(struct rte_eth_dev *dev __rte_unused,
2957 const struct rte_flow_item *item __rte_unused,
2958 uint64_t item_flags __rte_unused,
2959 uint64_t prev_layer __rte_unused,
2960 struct rte_flow_error *error)
2962 #ifdef HAVE_IBV_DEVICE_MPLS_SUPPORT
2963 const struct rte_flow_item_mpls *mask = item->mask;
2964 struct mlx5_priv *priv = dev->data->dev_private;
2967 if (!priv->config.mpls_en)
2968 return rte_flow_error_set(error, ENOTSUP,
2969 RTE_FLOW_ERROR_TYPE_ITEM, item,
2970 "MPLS not supported or"
2971 " disabled in firmware"
2973 /* MPLS over UDP, GRE is allowed */
2974 if (!(prev_layer & (MLX5_FLOW_LAYER_OUTER_L4_UDP |
2975 MLX5_FLOW_LAYER_GRE |
2976 MLX5_FLOW_LAYER_GRE_KEY)))
2977 return rte_flow_error_set(error, EINVAL,
2978 RTE_FLOW_ERROR_TYPE_ITEM, item,
2979 "protocol filtering not compatible"
2980 " with MPLS layer");
2981 /* Multi-tunnel isn't allowed but MPLS over GRE is an exception. */
2982 if ((item_flags & MLX5_FLOW_LAYER_TUNNEL) &&
2983 !(item_flags & MLX5_FLOW_LAYER_GRE))
2984 return rte_flow_error_set(error, ENOTSUP,
2985 RTE_FLOW_ERROR_TYPE_ITEM, item,
2986 "multiple tunnel layers not"
2989 mask = &rte_flow_item_mpls_mask;
2990 ret = mlx5_flow_item_acceptable
2991 (item, (const uint8_t *)mask,
2992 (const uint8_t *)&rte_flow_item_mpls_mask,
2993 sizeof(struct rte_flow_item_mpls),
2994 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2999 return rte_flow_error_set(error, ENOTSUP,
3000 RTE_FLOW_ERROR_TYPE_ITEM, item,
3001 "MPLS is not supported by Verbs, please"
3007 * Validate NVGRE item.
3010 * Item specification.
3011 * @param[in] item_flags
3012 * Bit flags to mark detected items.
3013 * @param[in] target_protocol
3014 * The next protocol in the previous item.
3016 * Pointer to error structure.
3019 * 0 on success, a negative errno value otherwise and rte_errno is set.
3022 mlx5_flow_validate_item_nvgre(const struct rte_flow_item *item,
3023 uint64_t item_flags,
3024 uint8_t target_protocol,
3025 struct rte_flow_error *error)
3027 const struct rte_flow_item_nvgre *mask = item->mask;
3030 if (target_protocol != 0xff && target_protocol != IPPROTO_GRE)
3031 return rte_flow_error_set(error, EINVAL,
3032 RTE_FLOW_ERROR_TYPE_ITEM, item,
3033 "protocol filtering not compatible"
3034 " with this GRE layer");
3035 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
3036 return rte_flow_error_set(error, ENOTSUP,
3037 RTE_FLOW_ERROR_TYPE_ITEM, item,
3038 "multiple tunnel layers not"
3040 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3))
3041 return rte_flow_error_set(error, ENOTSUP,
3042 RTE_FLOW_ERROR_TYPE_ITEM, item,
3043 "L3 Layer is missing");
3045 mask = &rte_flow_item_nvgre_mask;
3046 ret = mlx5_flow_item_acceptable
3047 (item, (const uint8_t *)mask,
3048 (const uint8_t *)&rte_flow_item_nvgre_mask,
3049 sizeof(struct rte_flow_item_nvgre),
3050 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
3057 * Validate eCPRI item.
3060 * Item specification.
3061 * @param[in] item_flags
3062 * Bit-fields that holds the items detected until now.
3063 * @param[in] last_item
3064 * Previous validated item in the pattern items.
3065 * @param[in] ether_type
3066 * Type in the ethernet layer header (including dot1q).
3067 * @param[in] acc_mask
3068 * Acceptable mask, if NULL default internal default mask
3069 * will be used to check whether item fields are supported.
3071 * Pointer to error structure.
3074 * 0 on success, a negative errno value otherwise and rte_errno is set.
3077 mlx5_flow_validate_item_ecpri(const struct rte_flow_item *item,
3078 uint64_t item_flags,
3080 uint16_t ether_type,
3081 const struct rte_flow_item_ecpri *acc_mask,
3082 struct rte_flow_error *error)
3084 const struct rte_flow_item_ecpri *mask = item->mask;
3085 const struct rte_flow_item_ecpri nic_mask = {
3089 RTE_BE32(((const struct rte_ecpri_common_hdr) {
3093 .dummy[0] = 0xFFFFFFFF,
3096 const uint64_t outer_l2_vlan = (MLX5_FLOW_LAYER_OUTER_L2 |
3097 MLX5_FLOW_LAYER_OUTER_VLAN);
3098 struct rte_flow_item_ecpri mask_lo;
3100 if (!(last_item & outer_l2_vlan) &&
3101 last_item != MLX5_FLOW_LAYER_OUTER_L4_UDP)
3102 return rte_flow_error_set(error, EINVAL,
3103 RTE_FLOW_ERROR_TYPE_ITEM, item,
3104 "eCPRI can only follow L2/VLAN layer or UDP layer");
3105 if ((last_item & outer_l2_vlan) && ether_type &&
3106 ether_type != RTE_ETHER_TYPE_ECPRI)
3107 return rte_flow_error_set(error, EINVAL,
3108 RTE_FLOW_ERROR_TYPE_ITEM, item,
3109 "eCPRI cannot follow L2/VLAN layer which ether type is not 0xAEFE");
3110 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
3111 return rte_flow_error_set(error, EINVAL,
3112 RTE_FLOW_ERROR_TYPE_ITEM, item,
3113 "eCPRI with tunnel is not supported right now");
3114 if (item_flags & MLX5_FLOW_LAYER_OUTER_L3)
3115 return rte_flow_error_set(error, ENOTSUP,
3116 RTE_FLOW_ERROR_TYPE_ITEM, item,
3117 "multiple L3 layers not supported");
3118 else if (item_flags & MLX5_FLOW_LAYER_OUTER_L4_TCP)
3119 return rte_flow_error_set(error, EINVAL,
3120 RTE_FLOW_ERROR_TYPE_ITEM, item,
3121 "eCPRI cannot coexist with a TCP layer");
3122 /* In specification, eCPRI could be over UDP layer. */
3123 else if (item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP)
3124 return rte_flow_error_set(error, EINVAL,
3125 RTE_FLOW_ERROR_TYPE_ITEM, item,
3126 "eCPRI over UDP layer is not yet supported right now");
3127 /* Mask for type field in common header could be zero. */
3129 mask = &rte_flow_item_ecpri_mask;
3130 mask_lo.hdr.common.u32 = rte_be_to_cpu_32(mask->hdr.common.u32);
3131 /* Input mask is in big-endian format. */
3132 if (mask_lo.hdr.common.type != 0 && mask_lo.hdr.common.type != 0xff)
3133 return rte_flow_error_set(error, EINVAL,
3134 RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
3135 "partial mask is not supported for protocol");
3136 else if (mask_lo.hdr.common.type == 0 && mask->hdr.dummy[0] != 0)
3137 return rte_flow_error_set(error, EINVAL,
3138 RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
3139 "message header mask must be after a type mask");
3140 return mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
3141 acc_mask ? (const uint8_t *)acc_mask
3142 : (const uint8_t *)&nic_mask,
3143 sizeof(struct rte_flow_item_ecpri),
3144 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
3148 flow_null_validate(struct rte_eth_dev *dev __rte_unused,
3149 const struct rte_flow_attr *attr __rte_unused,
3150 const struct rte_flow_item items[] __rte_unused,
3151 const struct rte_flow_action actions[] __rte_unused,
3152 bool external __rte_unused,
3153 int hairpin __rte_unused,
3154 struct rte_flow_error *error)
3156 return rte_flow_error_set(error, ENOTSUP,
3157 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
3160 static struct mlx5_flow *
3161 flow_null_prepare(struct rte_eth_dev *dev __rte_unused,
3162 const struct rte_flow_attr *attr __rte_unused,
3163 const struct rte_flow_item items[] __rte_unused,
3164 const struct rte_flow_action actions[] __rte_unused,
3165 struct rte_flow_error *error)
3167 rte_flow_error_set(error, ENOTSUP,
3168 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
3173 flow_null_translate(struct rte_eth_dev *dev __rte_unused,
3174 struct mlx5_flow *dev_flow __rte_unused,
3175 const struct rte_flow_attr *attr __rte_unused,
3176 const struct rte_flow_item items[] __rte_unused,
3177 const struct rte_flow_action actions[] __rte_unused,
3178 struct rte_flow_error *error)
3180 return rte_flow_error_set(error, ENOTSUP,
3181 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
3185 flow_null_apply(struct rte_eth_dev *dev __rte_unused,
3186 struct rte_flow *flow __rte_unused,
3187 struct rte_flow_error *error)
3189 return rte_flow_error_set(error, ENOTSUP,
3190 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
3194 flow_null_remove(struct rte_eth_dev *dev __rte_unused,
3195 struct rte_flow *flow __rte_unused)
3200 flow_null_destroy(struct rte_eth_dev *dev __rte_unused,
3201 struct rte_flow *flow __rte_unused)
3206 flow_null_query(struct rte_eth_dev *dev __rte_unused,
3207 struct rte_flow *flow __rte_unused,
3208 const struct rte_flow_action *actions __rte_unused,
3209 void *data __rte_unused,
3210 struct rte_flow_error *error)
3212 return rte_flow_error_set(error, ENOTSUP,
3213 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
3217 flow_null_sync_domain(struct rte_eth_dev *dev __rte_unused,
3218 uint32_t domains __rte_unused,
3219 uint32_t flags __rte_unused)
3224 /* Void driver to protect from null pointer reference. */
3225 const struct mlx5_flow_driver_ops mlx5_flow_null_drv_ops = {
3226 .validate = flow_null_validate,
3227 .prepare = flow_null_prepare,
3228 .translate = flow_null_translate,
3229 .apply = flow_null_apply,
3230 .remove = flow_null_remove,
3231 .destroy = flow_null_destroy,
3232 .query = flow_null_query,
3233 .sync_domain = flow_null_sync_domain,
3237 * Select flow driver type according to flow attributes and device
3241 * Pointer to the dev structure.
3243 * Pointer to the flow attributes.
3246 * flow driver type, MLX5_FLOW_TYPE_MAX otherwise.
3248 static enum mlx5_flow_drv_type
3249 flow_get_drv_type(struct rte_eth_dev *dev, const struct rte_flow_attr *attr)
3251 struct mlx5_priv *priv = dev->data->dev_private;
3252 /* The OS can determine first a specific flow type (DV, VERBS) */
3253 enum mlx5_flow_drv_type type = mlx5_flow_os_get_type();
3255 if (type != MLX5_FLOW_TYPE_MAX)
3257 /* If no OS specific type - continue with DV/VERBS selection */
3258 if (attr->transfer && priv->config.dv_esw_en)
3259 type = MLX5_FLOW_TYPE_DV;
3260 if (!attr->transfer)
3261 type = priv->config.dv_flow_en ? MLX5_FLOW_TYPE_DV :
3262 MLX5_FLOW_TYPE_VERBS;
3266 #define flow_get_drv_ops(type) flow_drv_ops[type]
3269 * Flow driver validation API. This abstracts calling driver specific functions.
3270 * The type of flow driver is determined according to flow attributes.
3273 * Pointer to the dev structure.
3275 * Pointer to the flow attributes.
3277 * Pointer to the list of items.
3278 * @param[in] actions
3279 * Pointer to the list of actions.
3280 * @param[in] external
3281 * This flow rule is created by request external to PMD.
3282 * @param[in] hairpin
3283 * Number of hairpin TX actions, 0 means classic flow.
3285 * Pointer to the error structure.
3288 * 0 on success, a negative errno value otherwise and rte_errno is set.
3291 flow_drv_validate(struct rte_eth_dev *dev,
3292 const struct rte_flow_attr *attr,
3293 const struct rte_flow_item items[],
3294 const struct rte_flow_action actions[],
3295 bool external, int hairpin, struct rte_flow_error *error)
3297 const struct mlx5_flow_driver_ops *fops;
3298 enum mlx5_flow_drv_type type = flow_get_drv_type(dev, attr);
3300 fops = flow_get_drv_ops(type);
3301 return fops->validate(dev, attr, items, actions, external,
3306 * Flow driver preparation API. This abstracts calling driver specific
3307 * functions. Parent flow (rte_flow) should have driver type (drv_type). It
3308 * calculates the size of memory required for device flow, allocates the memory,
3309 * initializes the device flow and returns the pointer.
3312 * This function initializes device flow structure such as dv or verbs in
3313 * struct mlx5_flow. However, it is caller's responsibility to initialize the
3314 * rest. For example, adding returning device flow to flow->dev_flow list and
3315 * setting backward reference to the flow should be done out of this function.
3316 * layers field is not filled either.
3319 * Pointer to the dev structure.
3321 * Pointer to the flow attributes.
3323 * Pointer to the list of items.
3324 * @param[in] actions
3325 * Pointer to the list of actions.
3326 * @param[in] flow_idx
3327 * This memory pool index to the flow.
3329 * Pointer to the error structure.
3332 * Pointer to device flow on success, otherwise NULL and rte_errno is set.
3334 static inline struct mlx5_flow *
3335 flow_drv_prepare(struct rte_eth_dev *dev,
3336 const struct rte_flow *flow,
3337 const struct rte_flow_attr *attr,
3338 const struct rte_flow_item items[],
3339 const struct rte_flow_action actions[],
3341 struct rte_flow_error *error)
3343 const struct mlx5_flow_driver_ops *fops;
3344 enum mlx5_flow_drv_type type = flow->drv_type;
3345 struct mlx5_flow *mlx5_flow = NULL;
3347 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3348 fops = flow_get_drv_ops(type);
3349 mlx5_flow = fops->prepare(dev, attr, items, actions, error);
3351 mlx5_flow->flow_idx = flow_idx;
3356 * Flow driver translation API. This abstracts calling driver specific
3357 * functions. Parent flow (rte_flow) should have driver type (drv_type). It
3358 * translates a generic flow into a driver flow. flow_drv_prepare() must
3362 * dev_flow->layers could be filled as a result of parsing during translation
3363 * if needed by flow_drv_apply(). dev_flow->flow->actions can also be filled
3364 * if necessary. As a flow can have multiple dev_flows by RSS flow expansion,
3365 * flow->actions could be overwritten even though all the expanded dev_flows
3366 * have the same actions.
3369 * Pointer to the rte dev structure.
3370 * @param[in, out] dev_flow
3371 * Pointer to the mlx5 flow.
3373 * Pointer to the flow attributes.
3375 * Pointer to the list of items.
3376 * @param[in] actions
3377 * Pointer to the list of actions.
3379 * Pointer to the error structure.
3382 * 0 on success, a negative errno value otherwise and rte_errno is set.
3385 flow_drv_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
3386 const struct rte_flow_attr *attr,
3387 const struct rte_flow_item items[],
3388 const struct rte_flow_action actions[],
3389 struct rte_flow_error *error)
3391 const struct mlx5_flow_driver_ops *fops;
3392 enum mlx5_flow_drv_type type = dev_flow->flow->drv_type;
3394 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3395 fops = flow_get_drv_ops(type);
3396 return fops->translate(dev, dev_flow, attr, items, actions, error);
3400 * Flow driver apply API. This abstracts calling driver specific functions.
3401 * Parent flow (rte_flow) should have driver type (drv_type). It applies
3402 * translated driver flows on to device. flow_drv_translate() must precede.
3405 * Pointer to Ethernet device structure.
3406 * @param[in, out] flow
3407 * Pointer to flow structure.
3409 * Pointer to error structure.
3412 * 0 on success, a negative errno value otherwise and rte_errno is set.
3415 flow_drv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
3416 struct rte_flow_error *error)
3418 const struct mlx5_flow_driver_ops *fops;
3419 enum mlx5_flow_drv_type type = flow->drv_type;
3421 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3422 fops = flow_get_drv_ops(type);
3423 return fops->apply(dev, flow, error);
3427 * Flow driver destroy API. This abstracts calling driver specific functions.
3428 * Parent flow (rte_flow) should have driver type (drv_type). It removes a flow
3429 * on device and releases resources of the flow.
3432 * Pointer to Ethernet device.
3433 * @param[in, out] flow
3434 * Pointer to flow structure.
3437 flow_drv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
3439 const struct mlx5_flow_driver_ops *fops;
3440 enum mlx5_flow_drv_type type = flow->drv_type;
3442 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3443 fops = flow_get_drv_ops(type);
3444 fops->destroy(dev, flow);
3448 * Flow driver find RSS policy tbl API. This abstracts calling driver
3449 * specific functions. Parent flow (rte_flow) should have driver
3450 * type (drv_type). It will find the RSS policy table that has the rss_desc.
3453 * Pointer to Ethernet device.
3454 * @param[in, out] flow
3455 * Pointer to flow structure.
3457 * Pointer to meter policy table.
3458 * @param[in] rss_desc
3459 * Pointer to rss_desc
3461 static struct mlx5_flow_meter_sub_policy *
3462 flow_drv_meter_sub_policy_rss_prepare(struct rte_eth_dev *dev,
3463 struct rte_flow *flow,
3464 struct mlx5_flow_meter_policy *policy,
3465 struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS])
3467 const struct mlx5_flow_driver_ops *fops;
3468 enum mlx5_flow_drv_type type = flow->drv_type;
3470 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3471 fops = flow_get_drv_ops(type);
3472 return fops->meter_sub_policy_rss_prepare(dev, policy, rss_desc);
3476 * Flow driver color tag rule API. This abstracts calling driver
3477 * specific functions. Parent flow (rte_flow) should have driver
3478 * type (drv_type). It will create the color tag rules in hierarchy meter.
3481 * Pointer to Ethernet device.
3482 * @param[in, out] flow
3483 * Pointer to flow structure.
3485 * Pointer to flow meter structure.
3486 * @param[in] src_port
3487 * The src port this extra rule should use.
3489 * The src port id match item.
3491 * Pointer to error structure.
3494 flow_drv_mtr_hierarchy_rule_create(struct rte_eth_dev *dev,
3495 struct rte_flow *flow,
3496 struct mlx5_flow_meter_info *fm,
3498 const struct rte_flow_item *item,
3499 struct rte_flow_error *error)
3501 const struct mlx5_flow_driver_ops *fops;
3502 enum mlx5_flow_drv_type type = flow->drv_type;
3504 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3505 fops = flow_get_drv_ops(type);
3506 return fops->meter_hierarchy_rule_create(dev, fm,
3507 src_port, item, error);
3511 * Get RSS action from the action list.
3514 * Pointer to Ethernet device.
3515 * @param[in] actions
3516 * Pointer to the list of actions.
3518 * Parent flow structure pointer.
3521 * Pointer to the RSS action if exist, else return NULL.
3523 static const struct rte_flow_action_rss*
3524 flow_get_rss_action(struct rte_eth_dev *dev,
3525 const struct rte_flow_action actions[])
3527 struct mlx5_priv *priv = dev->data->dev_private;
3528 const struct rte_flow_action_rss *rss = NULL;
3530 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3531 switch (actions->type) {
3532 case RTE_FLOW_ACTION_TYPE_RSS:
3533 rss = actions->conf;
3535 case RTE_FLOW_ACTION_TYPE_SAMPLE:
3537 const struct rte_flow_action_sample *sample =
3539 const struct rte_flow_action *act = sample->actions;
3540 for (; act->type != RTE_FLOW_ACTION_TYPE_END; act++)
3541 if (act->type == RTE_FLOW_ACTION_TYPE_RSS)
3545 case RTE_FLOW_ACTION_TYPE_METER:
3548 struct mlx5_flow_meter_info *fm;
3549 struct mlx5_flow_meter_policy *policy;
3550 const struct rte_flow_action_meter *mtr = actions->conf;
3552 fm = mlx5_flow_meter_find(priv, mtr->mtr_id, &mtr_idx);
3553 if (fm && !fm->def_policy) {
3554 policy = mlx5_flow_meter_policy_find(dev,
3555 fm->policy_id, NULL);
3556 MLX5_ASSERT(policy);
3557 if (policy->is_hierarchy) {
3559 mlx5_flow_meter_hierarchy_get_final_policy(dev,
3566 policy->act_cnt[RTE_COLOR_GREEN].rss->conf;
3578 * Get ASO age action by index.
3581 * Pointer to the Ethernet device structure.
3582 * @param[in] age_idx
3583 * Index to the ASO age action.
3586 * The specified ASO age action.
3588 struct mlx5_aso_age_action*
3589 flow_aso_age_get_by_idx(struct rte_eth_dev *dev, uint32_t age_idx)
3591 uint16_t pool_idx = age_idx & UINT16_MAX;
3592 uint16_t offset = (age_idx >> 16) & UINT16_MAX;
3593 struct mlx5_priv *priv = dev->data->dev_private;
3594 struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
3595 struct mlx5_aso_age_pool *pool = mng->pools[pool_idx];
3597 return &pool->actions[offset - 1];
3600 /* maps indirect action to translated direct in some actions array */
3601 struct mlx5_translated_action_handle {
3602 struct rte_flow_action_handle *action; /**< Indirect action handle. */
3603 int index; /**< Index in related array of rte_flow_action. */
3607 * Translates actions of type RTE_FLOW_ACTION_TYPE_INDIRECT to related
3608 * direct action if translation possible.
3609 * This functionality used to run same execution path for both direct and
3610 * indirect actions on flow create. All necessary preparations for indirect
3611 * action handling should be performed on *handle* actions list returned
3615 * Pointer to Ethernet device.
3616 * @param[in] actions
3617 * List of actions to translate.
3618 * @param[out] handle
3619 * List to store translated indirect action object handles.
3620 * @param[in, out] indir_n
3621 * Size of *handle* array. On return should be updated with number of
3622 * indirect actions retrieved from the *actions* list.
3623 * @param[out] translated_actions
3624 * List of actions where all indirect actions were translated to direct
3625 * if possible. NULL if no translation took place.
3627 * Pointer to the error structure.
3630 * 0 on success, a negative errno value otherwise and rte_errno is set.
3633 flow_action_handles_translate(struct rte_eth_dev *dev,
3634 const struct rte_flow_action actions[],
3635 struct mlx5_translated_action_handle *handle,
3637 struct rte_flow_action **translated_actions,
3638 struct rte_flow_error *error)
3640 struct mlx5_priv *priv = dev->data->dev_private;
3641 struct rte_flow_action *translated = NULL;
3642 size_t actions_size;
3645 struct mlx5_translated_action_handle *handle_end = NULL;
3647 for (n = 0; actions[n].type != RTE_FLOW_ACTION_TYPE_END; n++) {
3648 if (actions[n].type != RTE_FLOW_ACTION_TYPE_INDIRECT)
3650 if (copied_n == *indir_n) {
3651 return rte_flow_error_set
3652 (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION_NUM,
3653 NULL, "too many shared actions");
3655 rte_memcpy(&handle[copied_n].action, &actions[n].conf,
3656 sizeof(actions[n].conf));
3657 handle[copied_n].index = n;
3661 *indir_n = copied_n;
3664 actions_size = sizeof(struct rte_flow_action) * n;
3665 translated = mlx5_malloc(MLX5_MEM_ZERO, actions_size, 0, SOCKET_ID_ANY);
3670 memcpy(translated, actions, actions_size);
3671 for (handle_end = handle + copied_n; handle < handle_end; handle++) {
3672 struct mlx5_shared_action_rss *shared_rss;
3673 uint32_t act_idx = (uint32_t)(uintptr_t)handle->action;
3674 uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
3675 uint32_t idx = act_idx &
3676 ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
3679 case MLX5_INDIRECT_ACTION_TYPE_RSS:
3680 shared_rss = mlx5_ipool_get
3681 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
3682 translated[handle->index].type =
3683 RTE_FLOW_ACTION_TYPE_RSS;
3684 translated[handle->index].conf =
3685 &shared_rss->origin;
3687 case MLX5_INDIRECT_ACTION_TYPE_COUNT:
3688 translated[handle->index].type =
3689 (enum rte_flow_action_type)
3690 MLX5_RTE_FLOW_ACTION_TYPE_COUNT;
3691 translated[handle->index].conf = (void *)(uintptr_t)idx;
3693 case MLX5_INDIRECT_ACTION_TYPE_AGE:
3694 if (priv->sh->flow_hit_aso_en) {
3695 translated[handle->index].type =
3696 (enum rte_flow_action_type)
3697 MLX5_RTE_FLOW_ACTION_TYPE_AGE;
3698 translated[handle->index].conf =
3699 (void *)(uintptr_t)idx;
3703 case MLX5_INDIRECT_ACTION_TYPE_CT:
3704 if (priv->sh->ct_aso_en) {
3705 translated[handle->index].type =
3706 RTE_FLOW_ACTION_TYPE_CONNTRACK;
3707 translated[handle->index].conf =
3708 (void *)(uintptr_t)idx;
3713 mlx5_free(translated);
3714 return rte_flow_error_set
3715 (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
3716 NULL, "invalid indirect action type");
3719 *translated_actions = translated;
3724 * Get Shared RSS action from the action list.
3727 * Pointer to Ethernet device.
3729 * Pointer to the list of actions.
3730 * @param[in] shared_n
3731 * Actions list length.
3734 * The MLX5 RSS action ID if exists, otherwise return 0.
3737 flow_get_shared_rss_action(struct rte_eth_dev *dev,
3738 struct mlx5_translated_action_handle *handle,
3741 struct mlx5_translated_action_handle *handle_end;
3742 struct mlx5_priv *priv = dev->data->dev_private;
3743 struct mlx5_shared_action_rss *shared_rss;
3746 for (handle_end = handle + shared_n; handle < handle_end; handle++) {
3747 uint32_t act_idx = (uint32_t)(uintptr_t)handle->action;
3748 uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
3749 uint32_t idx = act_idx &
3750 ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
3752 case MLX5_INDIRECT_ACTION_TYPE_RSS:
3753 shared_rss = mlx5_ipool_get
3754 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
3756 __atomic_add_fetch(&shared_rss->refcnt, 1,
3767 find_graph_root(const struct rte_flow_item pattern[], uint32_t rss_level)
3769 const struct rte_flow_item *item;
3770 unsigned int has_vlan = 0;
3772 for (item = pattern; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
3773 if (item->type == RTE_FLOW_ITEM_TYPE_VLAN) {
3779 return rss_level < 2 ? MLX5_EXPANSION_ROOT_ETH_VLAN :
3780 MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN;
3781 return rss_level < 2 ? MLX5_EXPANSION_ROOT :
3782 MLX5_EXPANSION_ROOT_OUTER;
3786 * Get layer flags from the prefix flow.
3788 * Some flows may be split to several subflows, the prefix subflow gets the
3789 * match items and the suffix sub flow gets the actions.
3790 * Some actions need the user defined match item flags to get the detail for
3792 * This function helps the suffix flow to get the item layer flags from prefix
3795 * @param[in] dev_flow
3796 * Pointer the created preifx subflow.
3799 * The layers get from prefix subflow.
3801 static inline uint64_t
3802 flow_get_prefix_layer_flags(struct mlx5_flow *dev_flow)
3804 uint64_t layers = 0;
3807 * Layers bits could be localization, but usually the compiler will
3808 * help to do the optimization work for source code.
3809 * If no decap actions, use the layers directly.
3811 if (!(dev_flow->act_flags & MLX5_FLOW_ACTION_DECAP))
3812 return dev_flow->handle->layers;
3813 /* Convert L3 layers with decap action. */
3814 if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L3_IPV4)
3815 layers |= MLX5_FLOW_LAYER_OUTER_L3_IPV4;
3816 else if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L3_IPV6)
3817 layers |= MLX5_FLOW_LAYER_OUTER_L3_IPV6;
3818 /* Convert L4 layers with decap action. */
3819 if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L4_TCP)
3820 layers |= MLX5_FLOW_LAYER_OUTER_L4_TCP;
3821 else if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L4_UDP)
3822 layers |= MLX5_FLOW_LAYER_OUTER_L4_UDP;
3827 * Get metadata split action information.
3829 * @param[in] actions
3830 * Pointer to the list of actions.
3832 * Pointer to the return pointer.
3833 * @param[out] qrss_type
3834 * Pointer to the action type to return. RTE_FLOW_ACTION_TYPE_END is returned
3835 * if no QUEUE/RSS is found.
3836 * @param[out] encap_idx
3837 * Pointer to the index of the encap action if exists, otherwise the last
3841 * Total number of actions.
3844 flow_parse_metadata_split_actions_info(const struct rte_flow_action actions[],
3845 const struct rte_flow_action **qrss,
3848 const struct rte_flow_action_raw_encap *raw_encap;
3850 int raw_decap_idx = -1;
3853 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3854 switch (actions->type) {
3855 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
3856 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
3857 *encap_idx = actions_n;
3859 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
3860 raw_decap_idx = actions_n;
3862 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
3863 raw_encap = actions->conf;
3864 if (raw_encap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
3865 *encap_idx = raw_decap_idx != -1 ?
3866 raw_decap_idx : actions_n;
3868 case RTE_FLOW_ACTION_TYPE_QUEUE:
3869 case RTE_FLOW_ACTION_TYPE_RSS:
3877 if (*encap_idx == -1)
3878 *encap_idx = actions_n;
3879 /* Count RTE_FLOW_ACTION_TYPE_END. */
3880 return actions_n + 1;
3884 * Check if the action will change packet.
3887 * Pointer to Ethernet device.
3892 * true if action will change packet, false otherwise.
3894 static bool flow_check_modify_action_type(struct rte_eth_dev *dev,
3895 enum rte_flow_action_type type)
3897 struct mlx5_priv *priv = dev->data->dev_private;
3900 case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
3901 case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
3902 case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
3903 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
3904 case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
3905 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
3906 case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
3907 case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
3908 case RTE_FLOW_ACTION_TYPE_DEC_TTL:
3909 case RTE_FLOW_ACTION_TYPE_SET_TTL:
3910 case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
3911 case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
3912 case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
3913 case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
3914 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
3915 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
3916 case RTE_FLOW_ACTION_TYPE_SET_META:
3917 case RTE_FLOW_ACTION_TYPE_SET_TAG:
3918 case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
3919 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
3920 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
3921 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
3922 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
3923 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
3924 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
3925 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
3926 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
3927 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
3928 case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
3930 case RTE_FLOW_ACTION_TYPE_FLAG:
3931 case RTE_FLOW_ACTION_TYPE_MARK:
3932 if (priv->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY)
3942 * Check meter action from the action list.
3945 * Pointer to Ethernet device.
3946 * @param[in] actions
3947 * Pointer to the list of actions.
3948 * @param[out] has_mtr
3949 * Pointer to the meter exist flag.
3950 * @param[out] has_modify
3951 * Pointer to the flag showing there's packet change action.
3952 * @param[out] meter_id
3953 * Pointer to the meter id.
3956 * Total number of actions.
3959 flow_check_meter_action(struct rte_eth_dev *dev,
3960 const struct rte_flow_action actions[],
3961 bool *has_mtr, bool *has_modify, uint32_t *meter_id)
3963 const struct rte_flow_action_meter *mtr = NULL;
3966 MLX5_ASSERT(has_mtr);
3968 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3969 switch (actions->type) {
3970 case RTE_FLOW_ACTION_TYPE_METER:
3971 mtr = actions->conf;
3972 *meter_id = mtr->mtr_id;
3979 *has_modify |= flow_check_modify_action_type(dev,
3983 /* Count RTE_FLOW_ACTION_TYPE_END. */
3984 return actions_n + 1;
3988 * Check if the flow should be split due to hairpin.
3989 * The reason for the split is that in current HW we can't
3990 * support encap and push-vlan on Rx, so if a flow contains
3991 * these actions we move it to Tx.
3994 * Pointer to Ethernet device.
3996 * Flow rule attributes.
3997 * @param[in] actions
3998 * Associated actions (list terminated by the END action).
4001 * > 0 the number of actions and the flow should be split,
4002 * 0 when no split required.
4005 flow_check_hairpin_split(struct rte_eth_dev *dev,
4006 const struct rte_flow_attr *attr,
4007 const struct rte_flow_action actions[])
4009 int queue_action = 0;
4012 const struct rte_flow_action_queue *queue;
4013 const struct rte_flow_action_rss *rss;
4014 const struct rte_flow_action_raw_encap *raw_encap;
4015 const struct rte_eth_hairpin_conf *conf;
4019 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4020 switch (actions->type) {
4021 case RTE_FLOW_ACTION_TYPE_QUEUE:
4022 queue = actions->conf;
4025 conf = mlx5_rxq_get_hairpin_conf(dev, queue->index);
4026 if (conf == NULL || conf->tx_explicit != 0)
4031 case RTE_FLOW_ACTION_TYPE_RSS:
4032 rss = actions->conf;
4033 if (rss == NULL || rss->queue_num == 0)
4035 conf = mlx5_rxq_get_hairpin_conf(dev, rss->queue[0]);
4036 if (conf == NULL || conf->tx_explicit != 0)
4041 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
4042 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
4043 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
4044 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
4045 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
4049 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
4050 raw_encap = actions->conf;
4051 if (raw_encap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
4060 if (split && queue_action)
4065 /* Declare flow create/destroy prototype in advance. */
4067 flow_list_create(struct rte_eth_dev *dev, enum mlx5_flow_type type,
4068 const struct rte_flow_attr *attr,
4069 const struct rte_flow_item items[],
4070 const struct rte_flow_action actions[],
4071 bool external, struct rte_flow_error *error);
4074 flow_list_destroy(struct rte_eth_dev *dev, enum mlx5_flow_type type,
4078 flow_dv_mreg_match_cb(void *tool_ctx __rte_unused,
4079 struct mlx5_list_entry *entry, void *cb_ctx)
4081 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4082 struct mlx5_flow_mreg_copy_resource *mcp_res =
4083 container_of(entry, typeof(*mcp_res), hlist_ent);
4085 return mcp_res->mark_id != *(uint32_t *)(ctx->data);
4088 struct mlx5_list_entry *
4089 flow_dv_mreg_create_cb(void *tool_ctx, void *cb_ctx)
4091 struct rte_eth_dev *dev = tool_ctx;
4092 struct mlx5_priv *priv = dev->data->dev_private;
4093 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4094 struct mlx5_flow_mreg_copy_resource *mcp_res;
4095 struct rte_flow_error *error = ctx->error;
4098 uint32_t mark_id = *(uint32_t *)(ctx->data);
4099 struct rte_flow_attr attr = {
4100 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
4103 struct mlx5_rte_flow_item_tag tag_spec = {
4106 struct rte_flow_item items[] = {
4107 [1] = { .type = RTE_FLOW_ITEM_TYPE_END, },
4109 struct rte_flow_action_mark ftag = {
4112 struct mlx5_flow_action_copy_mreg cp_mreg = {
4116 struct rte_flow_action_jump jump = {
4117 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
4119 struct rte_flow_action actions[] = {
4120 [3] = { .type = RTE_FLOW_ACTION_TYPE_END, },
4123 /* Fill the register fileds in the flow. */
4124 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
4128 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_RX, 0, error);
4132 /* Provide the full width of FLAG specific value. */
4133 if (mark_id == (priv->sh->dv_regc0_mask & MLX5_FLOW_MARK_DEFAULT))
4134 tag_spec.data = MLX5_FLOW_MARK_DEFAULT;
4135 /* Build a new flow. */
4136 if (mark_id != MLX5_DEFAULT_COPY_ID) {
4137 items[0] = (struct rte_flow_item){
4138 .type = (enum rte_flow_item_type)
4139 MLX5_RTE_FLOW_ITEM_TYPE_TAG,
4142 items[1] = (struct rte_flow_item){
4143 .type = RTE_FLOW_ITEM_TYPE_END,
4145 actions[0] = (struct rte_flow_action){
4146 .type = (enum rte_flow_action_type)
4147 MLX5_RTE_FLOW_ACTION_TYPE_MARK,
4150 actions[1] = (struct rte_flow_action){
4151 .type = (enum rte_flow_action_type)
4152 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
4155 actions[2] = (struct rte_flow_action){
4156 .type = RTE_FLOW_ACTION_TYPE_JUMP,
4159 actions[3] = (struct rte_flow_action){
4160 .type = RTE_FLOW_ACTION_TYPE_END,
4163 /* Default rule, wildcard match. */
4164 attr.priority = MLX5_FLOW_LOWEST_PRIO_INDICATOR;
4165 items[0] = (struct rte_flow_item){
4166 .type = RTE_FLOW_ITEM_TYPE_END,
4168 actions[0] = (struct rte_flow_action){
4169 .type = (enum rte_flow_action_type)
4170 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
4173 actions[1] = (struct rte_flow_action){
4174 .type = RTE_FLOW_ACTION_TYPE_JUMP,
4177 actions[2] = (struct rte_flow_action){
4178 .type = RTE_FLOW_ACTION_TYPE_END,
4181 /* Build a new entry. */
4182 mcp_res = mlx5_ipool_zmalloc(priv->sh->ipool[MLX5_IPOOL_MCP], &idx);
4188 mcp_res->mark_id = mark_id;
4190 * The copy Flows are not included in any list. There
4191 * ones are referenced from other Flows and can not
4192 * be applied, removed, deleted in ardbitrary order
4193 * by list traversing.
4195 mcp_res->rix_flow = flow_list_create(dev, MLX5_FLOW_TYPE_MCP,
4196 &attr, items, actions, false, error);
4197 if (!mcp_res->rix_flow) {
4198 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], idx);
4201 return &mcp_res->hlist_ent;
4204 struct mlx5_list_entry *
4205 flow_dv_mreg_clone_cb(void *tool_ctx, struct mlx5_list_entry *oentry,
4206 void *cb_ctx __rte_unused)
4208 struct rte_eth_dev *dev = tool_ctx;
4209 struct mlx5_priv *priv = dev->data->dev_private;
4210 struct mlx5_flow_mreg_copy_resource *mcp_res;
4213 mcp_res = mlx5_ipool_malloc(priv->sh->ipool[MLX5_IPOOL_MCP], &idx);
4218 memcpy(mcp_res, oentry, sizeof(*mcp_res));
4220 return &mcp_res->hlist_ent;
4224 flow_dv_mreg_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
4226 struct mlx5_flow_mreg_copy_resource *mcp_res =
4227 container_of(entry, typeof(*mcp_res), hlist_ent);
4228 struct rte_eth_dev *dev = tool_ctx;
4229 struct mlx5_priv *priv = dev->data->dev_private;
4231 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], mcp_res->idx);
4235 * Add a flow of copying flow metadata registers in RX_CP_TBL.
4237 * As mark_id is unique, if there's already a registered flow for the mark_id,
4238 * return by increasing the reference counter of the resource. Otherwise, create
4239 * the resource (mcp_res) and flow.
4242 * - If ingress port is ANY and reg_c[1] is mark_id,
4243 * flow_tag := mark_id, reg_b := reg_c[0] and jump to RX_ACT_TBL.
4245 * For default flow (zero mark_id), flow is like,
4246 * - If ingress port is ANY,
4247 * reg_b := reg_c[0] and jump to RX_ACT_TBL.
4250 * Pointer to Ethernet device.
4252 * ID of MARK action, zero means default flow for META.
4254 * Perform verbose error reporting if not NULL.
4257 * Associated resource on success, NULL otherwise and rte_errno is set.
4259 static struct mlx5_flow_mreg_copy_resource *
4260 flow_mreg_add_copy_action(struct rte_eth_dev *dev, uint32_t mark_id,
4261 struct rte_flow_error *error)
4263 struct mlx5_priv *priv = dev->data->dev_private;
4264 struct mlx5_list_entry *entry;
4265 struct mlx5_flow_cb_ctx ctx = {
4271 /* Check if already registered. */
4272 MLX5_ASSERT(priv->mreg_cp_tbl);
4273 entry = mlx5_hlist_register(priv->mreg_cp_tbl, mark_id, &ctx);
4276 return container_of(entry, struct mlx5_flow_mreg_copy_resource,
4281 flow_dv_mreg_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
4283 struct mlx5_flow_mreg_copy_resource *mcp_res =
4284 container_of(entry, typeof(*mcp_res), hlist_ent);
4285 struct rte_eth_dev *dev = tool_ctx;
4286 struct mlx5_priv *priv = dev->data->dev_private;
4288 MLX5_ASSERT(mcp_res->rix_flow);
4289 flow_list_destroy(dev, MLX5_FLOW_TYPE_MCP, mcp_res->rix_flow);
4290 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], mcp_res->idx);
4294 * Release flow in RX_CP_TBL.
4297 * Pointer to Ethernet device.
4299 * Parent flow for wich copying is provided.
4302 flow_mreg_del_copy_action(struct rte_eth_dev *dev,
4303 struct rte_flow *flow)
4305 struct mlx5_flow_mreg_copy_resource *mcp_res;
4306 struct mlx5_priv *priv = dev->data->dev_private;
4308 if (!flow->rix_mreg_copy)
4310 mcp_res = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MCP],
4311 flow->rix_mreg_copy);
4312 if (!mcp_res || !priv->mreg_cp_tbl)
4314 MLX5_ASSERT(mcp_res->rix_flow);
4315 mlx5_hlist_unregister(priv->mreg_cp_tbl, &mcp_res->hlist_ent);
4316 flow->rix_mreg_copy = 0;
4320 * Remove the default copy action from RX_CP_TBL.
4322 * This functions is called in the mlx5_dev_start(). No thread safe
4326 * Pointer to Ethernet device.
4329 flow_mreg_del_default_copy_action(struct rte_eth_dev *dev)
4331 struct mlx5_list_entry *entry;
4332 struct mlx5_priv *priv = dev->data->dev_private;
4333 struct mlx5_flow_cb_ctx ctx;
4336 /* Check if default flow is registered. */
4337 if (!priv->mreg_cp_tbl)
4339 mark_id = MLX5_DEFAULT_COPY_ID;
4340 ctx.data = &mark_id;
4341 entry = mlx5_hlist_lookup(priv->mreg_cp_tbl, mark_id, &ctx);
4344 mlx5_hlist_unregister(priv->mreg_cp_tbl, entry);
4348 * Add the default copy action in in RX_CP_TBL.
4350 * This functions is called in the mlx5_dev_start(). No thread safe
4354 * Pointer to Ethernet device.
4356 * Perform verbose error reporting if not NULL.
4359 * 0 for success, negative value otherwise and rte_errno is set.
4362 flow_mreg_add_default_copy_action(struct rte_eth_dev *dev,
4363 struct rte_flow_error *error)
4365 struct mlx5_priv *priv = dev->data->dev_private;
4366 struct mlx5_flow_mreg_copy_resource *mcp_res;
4367 struct mlx5_flow_cb_ctx ctx;
4370 /* Check whether extensive metadata feature is engaged. */
4371 if (!priv->config.dv_flow_en ||
4372 priv->config.dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
4373 !mlx5_flow_ext_mreg_supported(dev) ||
4374 !priv->sh->dv_regc0_mask)
4377 * Add default mreg copy flow may be called multiple time, but
4378 * only be called once in stop. Avoid register it twice.
4380 mark_id = MLX5_DEFAULT_COPY_ID;
4381 ctx.data = &mark_id;
4382 if (mlx5_hlist_lookup(priv->mreg_cp_tbl, mark_id, &ctx))
4384 mcp_res = flow_mreg_add_copy_action(dev, mark_id, error);
4391 * Add a flow of copying flow metadata registers in RX_CP_TBL.
4393 * All the flow having Q/RSS action should be split by
4394 * flow_mreg_split_qrss_prep() to pass by RX_CP_TBL. A flow in the RX_CP_TBL
4395 * performs the following,
4396 * - CQE->flow_tag := reg_c[1] (MARK)
4397 * - CQE->flow_table_metadata (reg_b) := reg_c[0] (META)
4398 * As CQE's flow_tag is not a register, it can't be simply copied from reg_c[1]
4399 * but there should be a flow per each MARK ID set by MARK action.
4401 * For the aforementioned reason, if there's a MARK action in flow's action
4402 * list, a corresponding flow should be added to the RX_CP_TBL in order to copy
4403 * the MARK ID to CQE's flow_tag like,
4404 * - If reg_c[1] is mark_id,
4405 * flow_tag := mark_id, reg_b := reg_c[0] and jump to RX_ACT_TBL.
4407 * For SET_META action which stores value in reg_c[0], as the destination is
4408 * also a flow metadata register (reg_b), adding a default flow is enough. Zero
4409 * MARK ID means the default flow. The default flow looks like,
4410 * - For all flow, reg_b := reg_c[0] and jump to RX_ACT_TBL.
4413 * Pointer to Ethernet device.
4415 * Pointer to flow structure.
4416 * @param[in] actions
4417 * Pointer to the list of actions.
4419 * Perform verbose error reporting if not NULL.
4422 * 0 on success, negative value otherwise and rte_errno is set.
4425 flow_mreg_update_copy_table(struct rte_eth_dev *dev,
4426 struct rte_flow *flow,
4427 const struct rte_flow_action *actions,
4428 struct rte_flow_error *error)
4430 struct mlx5_priv *priv = dev->data->dev_private;
4431 struct mlx5_dev_config *config = &priv->config;
4432 struct mlx5_flow_mreg_copy_resource *mcp_res;
4433 const struct rte_flow_action_mark *mark;
4435 /* Check whether extensive metadata feature is engaged. */
4436 if (!config->dv_flow_en ||
4437 config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
4438 !mlx5_flow_ext_mreg_supported(dev) ||
4439 !priv->sh->dv_regc0_mask)
4441 /* Find MARK action. */
4442 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4443 switch (actions->type) {
4444 case RTE_FLOW_ACTION_TYPE_FLAG:
4445 mcp_res = flow_mreg_add_copy_action
4446 (dev, MLX5_FLOW_MARK_DEFAULT, error);
4449 flow->rix_mreg_copy = mcp_res->idx;
4451 case RTE_FLOW_ACTION_TYPE_MARK:
4452 mark = (const struct rte_flow_action_mark *)
4455 flow_mreg_add_copy_action(dev, mark->id, error);
4458 flow->rix_mreg_copy = mcp_res->idx;
4467 #define MLX5_MAX_SPLIT_ACTIONS 24
4468 #define MLX5_MAX_SPLIT_ITEMS 24
4471 * Split the hairpin flow.
4472 * Since HW can't support encap and push-vlan on Rx, we move these
4474 * If the count action is after the encap then we also
4475 * move the count action. in this case the count will also measure
4479 * Pointer to Ethernet device.
4480 * @param[in] actions
4481 * Associated actions (list terminated by the END action).
4482 * @param[out] actions_rx
4484 * @param[out] actions_tx
4486 * @param[out] pattern_tx
4487 * The pattern items for the Tx flow.
4488 * @param[out] flow_id
4489 * The flow ID connected to this flow.
4495 flow_hairpin_split(struct rte_eth_dev *dev,
4496 const struct rte_flow_action actions[],
4497 struct rte_flow_action actions_rx[],
4498 struct rte_flow_action actions_tx[],
4499 struct rte_flow_item pattern_tx[],
4502 const struct rte_flow_action_raw_encap *raw_encap;
4503 const struct rte_flow_action_raw_decap *raw_decap;
4504 struct mlx5_rte_flow_action_set_tag *set_tag;
4505 struct rte_flow_action *tag_action;
4506 struct mlx5_rte_flow_item_tag *tag_item;
4507 struct rte_flow_item *item;
4511 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4512 switch (actions->type) {
4513 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
4514 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
4515 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
4516 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
4517 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
4518 rte_memcpy(actions_tx, actions,
4519 sizeof(struct rte_flow_action));
4522 case RTE_FLOW_ACTION_TYPE_COUNT:
4524 rte_memcpy(actions_tx, actions,
4525 sizeof(struct rte_flow_action));
4528 rte_memcpy(actions_rx, actions,
4529 sizeof(struct rte_flow_action));
4533 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
4534 raw_encap = actions->conf;
4535 if (raw_encap->size > MLX5_ENCAPSULATION_DECISION_SIZE) {
4536 memcpy(actions_tx, actions,
4537 sizeof(struct rte_flow_action));
4541 rte_memcpy(actions_rx, actions,
4542 sizeof(struct rte_flow_action));
4546 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
4547 raw_decap = actions->conf;
4548 if (raw_decap->size < MLX5_ENCAPSULATION_DECISION_SIZE) {
4549 memcpy(actions_tx, actions,
4550 sizeof(struct rte_flow_action));
4553 rte_memcpy(actions_rx, actions,
4554 sizeof(struct rte_flow_action));
4559 rte_memcpy(actions_rx, actions,
4560 sizeof(struct rte_flow_action));
4565 /* Add set meta action and end action for the Rx flow. */
4566 tag_action = actions_rx;
4567 tag_action->type = (enum rte_flow_action_type)
4568 MLX5_RTE_FLOW_ACTION_TYPE_TAG;
4570 rte_memcpy(actions_rx, actions, sizeof(struct rte_flow_action));
4572 set_tag = (void *)actions_rx;
4573 *set_tag = (struct mlx5_rte_flow_action_set_tag) {
4574 .id = mlx5_flow_get_reg_id(dev, MLX5_HAIRPIN_RX, 0, NULL),
4577 MLX5_ASSERT(set_tag->id > REG_NON);
4578 tag_action->conf = set_tag;
4579 /* Create Tx item list. */
4580 rte_memcpy(actions_tx, actions, sizeof(struct rte_flow_action));
4581 addr = (void *)&pattern_tx[2];
4583 item->type = (enum rte_flow_item_type)
4584 MLX5_RTE_FLOW_ITEM_TYPE_TAG;
4585 tag_item = (void *)addr;
4586 tag_item->data = flow_id;
4587 tag_item->id = mlx5_flow_get_reg_id(dev, MLX5_HAIRPIN_TX, 0, NULL);
4588 MLX5_ASSERT(set_tag->id > REG_NON);
4589 item->spec = tag_item;
4590 addr += sizeof(struct mlx5_rte_flow_item_tag);
4591 tag_item = (void *)addr;
4592 tag_item->data = UINT32_MAX;
4593 tag_item->id = UINT16_MAX;
4594 item->mask = tag_item;
4597 item->type = RTE_FLOW_ITEM_TYPE_END;
4602 * The last stage of splitting chain, just creates the subflow
4603 * without any modification.
4606 * Pointer to Ethernet device.
4608 * Parent flow structure pointer.
4609 * @param[in, out] sub_flow
4610 * Pointer to return the created subflow, may be NULL.
4612 * Flow rule attributes.
4614 * Pattern specification (list terminated by the END pattern item).
4615 * @param[in] actions
4616 * Associated actions (list terminated by the END action).
4617 * @param[in] flow_split_info
4618 * Pointer to flow split info structure.
4620 * Perform verbose error reporting if not NULL.
4622 * 0 on success, negative value otherwise
4625 flow_create_split_inner(struct rte_eth_dev *dev,
4626 struct rte_flow *flow,
4627 struct mlx5_flow **sub_flow,
4628 const struct rte_flow_attr *attr,
4629 const struct rte_flow_item items[],
4630 const struct rte_flow_action actions[],
4631 struct mlx5_flow_split_info *flow_split_info,
4632 struct rte_flow_error *error)
4634 struct mlx5_flow *dev_flow;
4636 dev_flow = flow_drv_prepare(dev, flow, attr, items, actions,
4637 flow_split_info->flow_idx, error);
4640 dev_flow->flow = flow;
4641 dev_flow->external = flow_split_info->external;
4642 dev_flow->skip_scale = flow_split_info->skip_scale;
4643 /* Subflow object was created, we must include one in the list. */
4644 SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
4645 dev_flow->handle, next);
4647 * If dev_flow is as one of the suffix flow, some actions in suffix
4648 * flow may need some user defined item layer flags, and pass the
4649 * Metadate rxq mark flag to suffix flow as well.
4651 if (flow_split_info->prefix_layers)
4652 dev_flow->handle->layers = flow_split_info->prefix_layers;
4653 if (flow_split_info->prefix_mark)
4654 dev_flow->handle->mark = 1;
4656 *sub_flow = dev_flow;
4657 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
4658 dev_flow->dv.table_id = flow_split_info->table_id;
4660 return flow_drv_translate(dev, dev_flow, attr, items, actions, error);
4664 * Get the sub policy of a meter.
4667 * Pointer to Ethernet device.
4669 * Parent flow structure pointer.
4671 * Pointer to thread flow work space.
4673 * Flow rule attributes.
4675 * Pattern specification (list terminated by the END pattern item).
4677 * Perform verbose error reporting if not NULL.
4680 * Pointer to the meter sub policy, NULL otherwise and rte_errno is set.
4682 static struct mlx5_flow_meter_sub_policy *
4683 get_meter_sub_policy(struct rte_eth_dev *dev,
4684 struct rte_flow *flow,
4685 struct mlx5_flow_workspace *wks,
4686 const struct rte_flow_attr *attr,
4687 const struct rte_flow_item items[],
4688 struct rte_flow_error *error)
4690 struct mlx5_flow_meter_policy *policy;
4691 struct mlx5_flow_meter_policy *final_policy;
4692 struct mlx5_flow_meter_sub_policy *sub_policy = NULL;
4694 policy = wks->policy;
4695 final_policy = policy->is_hierarchy ? wks->final_policy : policy;
4696 if (final_policy->is_rss || final_policy->is_queue) {
4697 struct mlx5_flow_rss_desc rss_desc_v[MLX5_MTR_RTE_COLORS];
4698 struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS] = {0};
4702 * This is a tmp dev_flow,
4703 * no need to register any matcher for it in translate.
4705 wks->skip_matcher_reg = 1;
4706 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
4707 struct mlx5_flow dev_flow = {0};
4708 struct mlx5_flow_handle dev_handle = { {0} };
4709 uint8_t fate = final_policy->act_cnt[i].fate_action;
4711 if (fate == MLX5_FLOW_FATE_SHARED_RSS) {
4712 const void *rss_act =
4713 final_policy->act_cnt[i].rss->conf;
4714 struct rte_flow_action rss_actions[2] = {
4716 .type = RTE_FLOW_ACTION_TYPE_RSS,
4720 .type = RTE_FLOW_ACTION_TYPE_END,
4725 dev_flow.handle = &dev_handle;
4726 dev_flow.ingress = attr->ingress;
4727 dev_flow.flow = flow;
4728 dev_flow.external = 0;
4729 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
4730 dev_flow.dv.transfer = attr->transfer;
4733 * Translate RSS action to get rss hash fields.
4735 if (flow_drv_translate(dev, &dev_flow, attr,
4736 items, rss_actions, error))
4738 rss_desc_v[i] = wks->rss_desc;
4739 rss_desc_v[i].key_len = MLX5_RSS_HASH_KEY_LEN;
4740 rss_desc_v[i].hash_fields =
4741 dev_flow.hash_fields;
4742 rss_desc_v[i].queue_num =
4743 rss_desc_v[i].hash_fields ?
4744 rss_desc_v[i].queue_num : 1;
4745 rss_desc_v[i].tunnel =
4746 !!(dev_flow.handle->layers &
4747 MLX5_FLOW_LAYER_TUNNEL);
4748 rss_desc[i] = &rss_desc_v[i];
4749 } else if (fate == MLX5_FLOW_FATE_QUEUE) {
4750 /* This is queue action. */
4751 rss_desc_v[i] = wks->rss_desc;
4752 rss_desc_v[i].key_len = 0;
4753 rss_desc_v[i].hash_fields = 0;
4754 rss_desc_v[i].queue =
4755 &final_policy->act_cnt[i].queue;
4756 rss_desc_v[i].queue_num = 1;
4757 rss_desc[i] = &rss_desc_v[i];
4762 sub_policy = flow_drv_meter_sub_policy_rss_prepare(dev,
4763 flow, policy, rss_desc);
4765 enum mlx5_meter_domain mtr_domain =
4766 attr->transfer ? MLX5_MTR_DOMAIN_TRANSFER :
4767 (attr->egress ? MLX5_MTR_DOMAIN_EGRESS :
4768 MLX5_MTR_DOMAIN_INGRESS);
4769 sub_policy = policy->sub_policys[mtr_domain][0];
4772 rte_flow_error_set(error, EINVAL,
4773 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4774 "Failed to get meter sub-policy.");
4780 * Split the meter flow.
4782 * As meter flow will split to three sub flow, other than meter
4783 * action, the other actions make sense to only meter accepts
4784 * the packet. If it need to be dropped, no other additional
4785 * actions should be take.
4787 * One kind of special action which decapsulates the L3 tunnel
4788 * header will be in the prefix sub flow, as not to take the
4789 * L3 tunnel header into account.
4792 * Pointer to Ethernet device.
4794 * Parent flow structure pointer.
4796 * Pointer to thread flow work space.
4798 * Flow rule attributes.
4800 * Pattern specification (list terminated by the END pattern item).
4801 * @param[out] sfx_items
4802 * Suffix flow match items (list terminated by the END pattern item).
4803 * @param[in] actions
4804 * Associated actions (list terminated by the END action).
4805 * @param[out] actions_sfx
4806 * Suffix flow actions.
4807 * @param[out] actions_pre
4808 * Prefix flow actions.
4809 * @param[out] mtr_flow_id
4810 * Pointer to meter flow id.
4812 * Perform verbose error reporting if not NULL.
4815 * 0 on success, a negative errno value otherwise and rte_errno is set.
4818 flow_meter_split_prep(struct rte_eth_dev *dev,
4819 struct rte_flow *flow,
4820 struct mlx5_flow_workspace *wks,
4821 const struct rte_flow_attr *attr,
4822 const struct rte_flow_item items[],
4823 struct rte_flow_item sfx_items[],
4824 const struct rte_flow_action actions[],
4825 struct rte_flow_action actions_sfx[],
4826 struct rte_flow_action actions_pre[],
4827 uint32_t *mtr_flow_id,
4828 struct rte_flow_error *error)
4830 struct mlx5_priv *priv = dev->data->dev_private;
4831 struct mlx5_flow_meter_info *fm = wks->fm;
4832 struct rte_flow_action *tag_action = NULL;
4833 struct rte_flow_item *tag_item;
4834 struct mlx5_rte_flow_action_set_tag *set_tag;
4835 const struct rte_flow_action_raw_encap *raw_encap;
4836 const struct rte_flow_action_raw_decap *raw_decap;
4837 struct mlx5_rte_flow_item_tag *tag_item_spec;
4838 struct mlx5_rte_flow_item_tag *tag_item_mask;
4839 uint32_t tag_id = 0;
4840 struct rte_flow_item *vlan_item_dst = NULL;
4841 const struct rte_flow_item *vlan_item_src = NULL;
4842 struct rte_flow_action *hw_mtr_action;
4843 struct rte_flow_action *action_pre_head = NULL;
4844 int32_t flow_src_port = priv->representor_id;
4846 uint8_t mtr_id_offset = priv->mtr_reg_share ? MLX5_MTR_COLOR_BITS : 0;
4847 uint8_t mtr_reg_bits = priv->mtr_reg_share ?
4848 MLX5_MTR_IDLE_BITS_IN_COLOR_REG : MLX5_REG_BITS;
4849 uint32_t flow_id = 0;
4850 uint32_t flow_id_reversed = 0;
4851 uint8_t flow_id_bits = 0;
4854 /* Prepare the suffix subflow items. */
4855 tag_item = sfx_items++;
4856 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
4857 struct mlx5_priv *port_priv;
4858 const struct rte_flow_item_port_id *pid_v;
4859 int item_type = items->type;
4861 switch (item_type) {
4862 case RTE_FLOW_ITEM_TYPE_PORT_ID:
4863 pid_v = items->spec;
4865 port_priv = mlx5_port_to_eswitch_info(pid_v->id, false);
4867 return rte_flow_error_set(error,
4869 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
4871 "Failed to get port info.");
4872 flow_src_port = port_priv->representor_id;
4873 if (!fm->def_policy && wks->policy->is_hierarchy &&
4874 flow_src_port != priv->representor_id) {
4875 if (flow_drv_mtr_hierarchy_rule_create(dev,
4882 memcpy(sfx_items, items, sizeof(*sfx_items));
4885 case RTE_FLOW_ITEM_TYPE_VLAN:
4886 /* Determine if copy vlan item below. */
4887 vlan_item_src = items;
4888 vlan_item_dst = sfx_items++;
4889 vlan_item_dst->type = RTE_FLOW_ITEM_TYPE_VOID;
4895 sfx_items->type = RTE_FLOW_ITEM_TYPE_END;
4897 mtr_first = priv->sh->meter_aso_en &&
4898 (attr->egress || (attr->transfer && flow_src_port != UINT16_MAX));
4899 /* For ASO meter, meter must be before tag in TX direction. */
4901 action_pre_head = actions_pre++;
4902 /* Leave space for tag action. */
4903 tag_action = actions_pre++;
4905 /* Prepare the actions for prefix and suffix flow. */
4906 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4907 struct rte_flow_action *action_cur = NULL;
4909 switch (actions->type) {
4910 case RTE_FLOW_ACTION_TYPE_METER:
4912 action_cur = action_pre_head;
4914 /* Leave space for tag action. */
4915 tag_action = actions_pre++;
4916 action_cur = actions_pre++;
4919 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
4920 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
4921 action_cur = actions_pre++;
4923 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
4924 raw_encap = actions->conf;
4925 if (raw_encap->size < MLX5_ENCAPSULATION_DECISION_SIZE)
4926 action_cur = actions_pre++;
4928 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
4929 raw_decap = actions->conf;
4930 if (raw_decap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
4931 action_cur = actions_pre++;
4933 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
4934 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
4935 if (vlan_item_dst && vlan_item_src) {
4936 memcpy(vlan_item_dst, vlan_item_src,
4937 sizeof(*vlan_item_dst));
4939 * Convert to internal match item, it is used
4940 * for vlan push and set vid.
4942 vlan_item_dst->type = (enum rte_flow_item_type)
4943 MLX5_RTE_FLOW_ITEM_TYPE_VLAN;
4950 action_cur = (fm->def_policy) ?
4951 actions_sfx++ : actions_pre++;
4952 memcpy(action_cur, actions, sizeof(struct rte_flow_action));
4954 /* Add end action to the actions. */
4955 actions_sfx->type = RTE_FLOW_ACTION_TYPE_END;
4956 if (priv->sh->meter_aso_en) {
4958 * For ASO meter, need to add an extra jump action explicitly,
4959 * to jump from meter to policer table.
4961 struct mlx5_flow_meter_sub_policy *sub_policy;
4962 struct mlx5_flow_tbl_data_entry *tbl_data;
4964 if (!fm->def_policy) {
4965 sub_policy = get_meter_sub_policy(dev, flow, wks,
4966 attr, items, error);
4970 enum mlx5_meter_domain mtr_domain =
4971 attr->transfer ? MLX5_MTR_DOMAIN_TRANSFER :
4972 (attr->egress ? MLX5_MTR_DOMAIN_EGRESS :
4973 MLX5_MTR_DOMAIN_INGRESS);
4976 &priv->sh->mtrmng->def_policy[mtr_domain]->sub_policy;
4978 tbl_data = container_of(sub_policy->tbl_rsc,
4979 struct mlx5_flow_tbl_data_entry, tbl);
4980 hw_mtr_action = actions_pre++;
4981 hw_mtr_action->type = (enum rte_flow_action_type)
4982 MLX5_RTE_FLOW_ACTION_TYPE_JUMP;
4983 hw_mtr_action->conf = tbl_data->jump.action;
4985 actions_pre->type = RTE_FLOW_ACTION_TYPE_END;
4988 return rte_flow_error_set(error, ENOMEM,
4989 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
4990 NULL, "No tag action space.");
4992 tag_action->type = RTE_FLOW_ACTION_TYPE_VOID;
4995 /* Only default-policy Meter creates mtr flow id. */
4996 if (fm->def_policy) {
4997 mlx5_ipool_malloc(fm->flow_ipool, &tag_id);
4999 return rte_flow_error_set(error, ENOMEM,
5000 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
5001 "Failed to allocate meter flow id.");
5002 flow_id = tag_id - 1;
5003 flow_id_bits = (!flow_id) ? 1 :
5004 (MLX5_REG_BITS - __builtin_clz(flow_id));
5005 if ((flow_id_bits + priv->sh->mtrmng->max_mtr_bits) >
5007 mlx5_ipool_free(fm->flow_ipool, tag_id);
5008 return rte_flow_error_set(error, EINVAL,
5009 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
5010 "Meter flow id exceeds max limit.");
5012 if (flow_id_bits > priv->sh->mtrmng->max_mtr_flow_bits)
5013 priv->sh->mtrmng->max_mtr_flow_bits = flow_id_bits;
5015 /* Build tag actions and items for meter_id/meter flow_id. */
5016 set_tag = (struct mlx5_rte_flow_action_set_tag *)actions_pre;
5017 tag_item_spec = (struct mlx5_rte_flow_item_tag *)sfx_items;
5018 tag_item_mask = tag_item_spec + 1;
5019 /* Both flow_id and meter_id share the same register. */
5020 *set_tag = (struct mlx5_rte_flow_action_set_tag) {
5021 .id = (enum modify_reg)mlx5_flow_get_reg_id(dev, MLX5_MTR_ID,
5023 .offset = mtr_id_offset,
5024 .length = mtr_reg_bits,
5025 .data = flow->meter,
5028 * The color Reg bits used by flow_id are growing from
5029 * msb to lsb, so must do bit reverse for flow_id val in RegC.
5031 for (shift = 0; shift < flow_id_bits; shift++)
5032 flow_id_reversed = (flow_id_reversed << 1) |
5033 ((flow_id >> shift) & 0x1);
5035 flow_id_reversed << (mtr_reg_bits - flow_id_bits);
5036 tag_item_spec->id = set_tag->id;
5037 tag_item_spec->data = set_tag->data << mtr_id_offset;
5038 tag_item_mask->data = UINT32_MAX << mtr_id_offset;
5039 tag_action->type = (enum rte_flow_action_type)
5040 MLX5_RTE_FLOW_ACTION_TYPE_TAG;
5041 tag_action->conf = set_tag;
5042 tag_item->type = (enum rte_flow_item_type)
5043 MLX5_RTE_FLOW_ITEM_TYPE_TAG;
5044 tag_item->spec = tag_item_spec;
5045 tag_item->last = NULL;
5046 tag_item->mask = tag_item_mask;
5049 *mtr_flow_id = tag_id;
5054 * Split action list having QUEUE/RSS for metadata register copy.
5056 * Once Q/RSS action is detected in user's action list, the flow action
5057 * should be split in order to copy metadata registers, which will happen in
5059 * - CQE->flow_tag := reg_c[1] (MARK)
5060 * - CQE->flow_table_metadata (reg_b) := reg_c[0] (META)
5061 * The Q/RSS action will be performed on RX_ACT_TBL after passing by RX_CP_TBL.
5062 * This is because the last action of each flow must be a terminal action
5063 * (QUEUE, RSS or DROP).
5065 * Flow ID must be allocated to identify actions in the RX_ACT_TBL and it is
5066 * stored and kept in the mlx5_flow structure per each sub_flow.
5068 * The Q/RSS action is replaced with,
5069 * - SET_TAG, setting the allocated flow ID to reg_c[2].
5070 * And the following JUMP action is added at the end,
5071 * - JUMP, to RX_CP_TBL.
5073 * A flow to perform remained Q/RSS action will be created in RX_ACT_TBL by
5074 * flow_create_split_metadata() routine. The flow will look like,
5075 * - If flow ID matches (reg_c[2]), perform Q/RSS.
5078 * Pointer to Ethernet device.
5079 * @param[out] split_actions
5080 * Pointer to store split actions to jump to CP_TBL.
5081 * @param[in] actions
5082 * Pointer to the list of original flow actions.
5084 * Pointer to the Q/RSS action.
5085 * @param[in] actions_n
5086 * Number of original actions.
5088 * Perform verbose error reporting if not NULL.
5091 * non-zero unique flow_id on success, otherwise 0 and
5092 * error/rte_error are set.
5095 flow_mreg_split_qrss_prep(struct rte_eth_dev *dev,
5096 struct rte_flow_action *split_actions,
5097 const struct rte_flow_action *actions,
5098 const struct rte_flow_action *qrss,
5099 int actions_n, struct rte_flow_error *error)
5101 struct mlx5_priv *priv = dev->data->dev_private;
5102 struct mlx5_rte_flow_action_set_tag *set_tag;
5103 struct rte_flow_action_jump *jump;
5104 const int qrss_idx = qrss - actions;
5105 uint32_t flow_id = 0;
5109 * Given actions will be split
5110 * - Replace QUEUE/RSS action with SET_TAG to set flow ID.
5111 * - Add jump to mreg CP_TBL.
5112 * As a result, there will be one more action.
5115 memcpy(split_actions, actions, sizeof(*split_actions) * actions_n);
5116 set_tag = (void *)(split_actions + actions_n);
5118 * If tag action is not set to void(it means we are not the meter
5119 * suffix flow), add the tag action. Since meter suffix flow already
5120 * has the tag added.
5122 if (split_actions[qrss_idx].type != RTE_FLOW_ACTION_TYPE_VOID) {
5124 * Allocate the new subflow ID. This one is unique within
5125 * device and not shared with representors. Otherwise,
5126 * we would have to resolve multi-thread access synch
5127 * issue. Each flow on the shared device is appended
5128 * with source vport identifier, so the resulting
5129 * flows will be unique in the shared (by master and
5130 * representors) domain even if they have coinciding
5133 mlx5_ipool_malloc(priv->sh->ipool
5134 [MLX5_IPOOL_RSS_EXPANTION_FLOW_ID], &flow_id);
5136 return rte_flow_error_set(error, ENOMEM,
5137 RTE_FLOW_ERROR_TYPE_ACTION,
5138 NULL, "can't allocate id "
5139 "for split Q/RSS subflow");
5140 /* Internal SET_TAG action to set flow ID. */
5141 *set_tag = (struct mlx5_rte_flow_action_set_tag){
5144 ret = mlx5_flow_get_reg_id(dev, MLX5_COPY_MARK, 0, error);
5148 /* Construct new actions array. */
5149 /* Replace QUEUE/RSS action. */
5150 split_actions[qrss_idx] = (struct rte_flow_action){
5151 .type = (enum rte_flow_action_type)
5152 MLX5_RTE_FLOW_ACTION_TYPE_TAG,
5156 /* JUMP action to jump to mreg copy table (CP_TBL). */
5157 jump = (void *)(set_tag + 1);
5158 *jump = (struct rte_flow_action_jump){
5159 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
5161 split_actions[actions_n - 2] = (struct rte_flow_action){
5162 .type = RTE_FLOW_ACTION_TYPE_JUMP,
5165 split_actions[actions_n - 1] = (struct rte_flow_action){
5166 .type = RTE_FLOW_ACTION_TYPE_END,
5172 * Extend the given action list for Tx metadata copy.
5174 * Copy the given action list to the ext_actions and add flow metadata register
5175 * copy action in order to copy reg_a set by WQE to reg_c[0].
5177 * @param[out] ext_actions
5178 * Pointer to the extended action list.
5179 * @param[in] actions
5180 * Pointer to the list of actions.
5181 * @param[in] actions_n
5182 * Number of actions in the list.
5184 * Perform verbose error reporting if not NULL.
5185 * @param[in] encap_idx
5186 * The encap action inndex.
5189 * 0 on success, negative value otherwise
5192 flow_mreg_tx_copy_prep(struct rte_eth_dev *dev,
5193 struct rte_flow_action *ext_actions,
5194 const struct rte_flow_action *actions,
5195 int actions_n, struct rte_flow_error *error,
5198 struct mlx5_flow_action_copy_mreg *cp_mreg =
5199 (struct mlx5_flow_action_copy_mreg *)
5200 (ext_actions + actions_n + 1);
5203 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_RX, 0, error);
5207 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_TX, 0, error);
5212 memcpy(ext_actions, actions, sizeof(*ext_actions) * encap_idx);
5213 if (encap_idx == actions_n - 1) {
5214 ext_actions[actions_n - 1] = (struct rte_flow_action){
5215 .type = (enum rte_flow_action_type)
5216 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
5219 ext_actions[actions_n] = (struct rte_flow_action){
5220 .type = RTE_FLOW_ACTION_TYPE_END,
5223 ext_actions[encap_idx] = (struct rte_flow_action){
5224 .type = (enum rte_flow_action_type)
5225 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
5228 memcpy(ext_actions + encap_idx + 1, actions + encap_idx,
5229 sizeof(*ext_actions) * (actions_n - encap_idx));
5235 * Check the match action from the action list.
5237 * @param[in] actions
5238 * Pointer to the list of actions.
5240 * Flow rule attributes.
5242 * The action to be check if exist.
5243 * @param[out] match_action_pos
5244 * Pointer to the position of the matched action if exists, otherwise is -1.
5245 * @param[out] qrss_action_pos
5246 * Pointer to the position of the Queue/RSS action if exists, otherwise is -1.
5247 * @param[out] modify_after_mirror
5248 * Pointer to the flag of modify action after FDB mirroring.
5251 * > 0 the total number of actions.
5252 * 0 if not found match action in action list.
5255 flow_check_match_action(const struct rte_flow_action actions[],
5256 const struct rte_flow_attr *attr,
5257 enum rte_flow_action_type action,
5258 int *match_action_pos, int *qrss_action_pos,
5259 int *modify_after_mirror)
5261 const struct rte_flow_action_sample *sample;
5268 *match_action_pos = -1;
5269 *qrss_action_pos = -1;
5270 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
5271 if (actions->type == action) {
5273 *match_action_pos = actions_n;
5275 switch (actions->type) {
5276 case RTE_FLOW_ACTION_TYPE_QUEUE:
5277 case RTE_FLOW_ACTION_TYPE_RSS:
5278 *qrss_action_pos = actions_n;
5280 case RTE_FLOW_ACTION_TYPE_SAMPLE:
5281 sample = actions->conf;
5282 ratio = sample->ratio;
5283 sub_type = ((const struct rte_flow_action *)
5284 (sample->actions))->type;
5285 if (ratio == 1 && attr->transfer)
5288 case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
5289 case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
5290 case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
5291 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
5292 case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
5293 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
5294 case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
5295 case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
5296 case RTE_FLOW_ACTION_TYPE_DEC_TTL:
5297 case RTE_FLOW_ACTION_TYPE_SET_TTL:
5298 case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
5299 case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
5300 case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
5301 case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
5302 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
5303 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
5304 case RTE_FLOW_ACTION_TYPE_FLAG:
5305 case RTE_FLOW_ACTION_TYPE_MARK:
5306 case RTE_FLOW_ACTION_TYPE_SET_META:
5307 case RTE_FLOW_ACTION_TYPE_SET_TAG:
5308 case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
5309 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
5310 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
5311 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
5312 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
5313 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
5314 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
5315 case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
5316 case RTE_FLOW_ACTION_TYPE_METER:
5318 *modify_after_mirror = 1;
5325 if (flag && fdb_mirror && !*modify_after_mirror) {
5326 /* FDB mirroring uses the destination array to implement
5327 * instead of FLOW_SAMPLER object.
5329 if (sub_type != RTE_FLOW_ACTION_TYPE_END)
5332 /* Count RTE_FLOW_ACTION_TYPE_END. */
5333 return flag ? actions_n + 1 : 0;
5336 #define SAMPLE_SUFFIX_ITEM 2
5339 * Split the sample flow.
5341 * As sample flow will split to two sub flow, sample flow with
5342 * sample action, the other actions will move to new suffix flow.
5344 * Also add unique tag id with tag action in the sample flow,
5345 * the same tag id will be as match in the suffix flow.
5348 * Pointer to Ethernet device.
5349 * @param[in] add_tag
5350 * Add extra tag action flag.
5351 * @param[out] sfx_items
5352 * Suffix flow match items (list terminated by the END pattern item).
5353 * @param[in] actions
5354 * Associated actions (list terminated by the END action).
5355 * @param[out] actions_sfx
5356 * Suffix flow actions.
5357 * @param[out] actions_pre
5358 * Prefix flow actions.
5359 * @param[in] actions_n
5360 * The total number of actions.
5361 * @param[in] sample_action_pos
5362 * The sample action position.
5363 * @param[in] qrss_action_pos
5364 * The Queue/RSS action position.
5365 * @param[in] jump_table
5366 * Add extra jump action flag.
5368 * Perform verbose error reporting if not NULL.
5371 * 0 on success, or unique flow_id, a negative errno value
5372 * otherwise and rte_errno is set.
5375 flow_sample_split_prep(struct rte_eth_dev *dev,
5377 struct rte_flow_item sfx_items[],
5378 const struct rte_flow_action actions[],
5379 struct rte_flow_action actions_sfx[],
5380 struct rte_flow_action actions_pre[],
5382 int sample_action_pos,
5383 int qrss_action_pos,
5385 struct rte_flow_error *error)
5387 struct mlx5_priv *priv = dev->data->dev_private;
5388 struct mlx5_rte_flow_action_set_tag *set_tag;
5389 struct mlx5_rte_flow_item_tag *tag_spec;
5390 struct mlx5_rte_flow_item_tag *tag_mask;
5391 struct rte_flow_action_jump *jump_action;
5392 uint32_t tag_id = 0;
5394 int append_index = 0;
5397 if (sample_action_pos < 0)
5398 return rte_flow_error_set(error, EINVAL,
5399 RTE_FLOW_ERROR_TYPE_ACTION,
5400 NULL, "invalid position of sample "
5402 /* Prepare the actions for prefix and suffix flow. */
5403 if (qrss_action_pos >= 0 && qrss_action_pos < sample_action_pos) {
5404 index = qrss_action_pos;
5405 /* Put the preceding the Queue/RSS action into prefix flow. */
5407 memcpy(actions_pre, actions,
5408 sizeof(struct rte_flow_action) * index);
5409 /* Put others preceding the sample action into prefix flow. */
5410 if (sample_action_pos > index + 1)
5411 memcpy(actions_pre + index, actions + index + 1,
5412 sizeof(struct rte_flow_action) *
5413 (sample_action_pos - index - 1));
5414 index = sample_action_pos - 1;
5415 /* Put Queue/RSS action into Suffix flow. */
5416 memcpy(actions_sfx, actions + qrss_action_pos,
5417 sizeof(struct rte_flow_action));
5420 index = sample_action_pos;
5422 memcpy(actions_pre, actions,
5423 sizeof(struct rte_flow_action) * index);
5425 /* For CX5, add an extra tag action for NIC-RX and E-Switch ingress.
5426 * For CX6DX and above, metadata registers Cx preserve their value,
5427 * add an extra tag action for NIC-RX and E-Switch Domain.
5430 /* Prepare the prefix tag action. */
5432 set_tag = (void *)(actions_pre + actions_n + append_index);
5433 ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, 0, error);
5436 mlx5_ipool_malloc(priv->sh->ipool
5437 [MLX5_IPOOL_RSS_EXPANTION_FLOW_ID], &tag_id);
5438 *set_tag = (struct mlx5_rte_flow_action_set_tag) {
5442 /* Prepare the suffix subflow items. */
5443 tag_spec = (void *)(sfx_items + SAMPLE_SUFFIX_ITEM);
5444 tag_spec->data = tag_id;
5445 tag_spec->id = set_tag->id;
5446 tag_mask = tag_spec + 1;
5447 tag_mask->data = UINT32_MAX;
5448 sfx_items[0] = (struct rte_flow_item){
5449 .type = (enum rte_flow_item_type)
5450 MLX5_RTE_FLOW_ITEM_TYPE_TAG,
5455 sfx_items[1] = (struct rte_flow_item){
5456 .type = (enum rte_flow_item_type)
5457 RTE_FLOW_ITEM_TYPE_END,
5459 /* Prepare the tag action in prefix subflow. */
5460 actions_pre[index++] =
5461 (struct rte_flow_action){
5462 .type = (enum rte_flow_action_type)
5463 MLX5_RTE_FLOW_ACTION_TYPE_TAG,
5467 memcpy(actions_pre + index, actions + sample_action_pos,
5468 sizeof(struct rte_flow_action));
5470 /* For the modify action after the sample action in E-Switch mirroring,
5471 * Add the extra jump action in prefix subflow and jump into the next
5472 * table, then do the modify action in the new table.
5475 /* Prepare the prefix jump action. */
5477 jump_action = (void *)(actions_pre + actions_n + append_index);
5478 jump_action->group = jump_table;
5479 actions_pre[index++] =
5480 (struct rte_flow_action){
5481 .type = (enum rte_flow_action_type)
5482 RTE_FLOW_ACTION_TYPE_JUMP,
5483 .conf = jump_action,
5486 actions_pre[index] = (struct rte_flow_action){
5487 .type = (enum rte_flow_action_type)
5488 RTE_FLOW_ACTION_TYPE_END,
5490 /* Put the actions after sample into Suffix flow. */
5491 memcpy(actions_sfx, actions + sample_action_pos + 1,
5492 sizeof(struct rte_flow_action) *
5493 (actions_n - sample_action_pos - 1));
5498 * The splitting for metadata feature.
5500 * - Q/RSS action on NIC Rx should be split in order to pass by
5501 * the mreg copy table (RX_CP_TBL) and then it jumps to the
5502 * action table (RX_ACT_TBL) which has the split Q/RSS action.
5504 * - All the actions on NIC Tx should have a mreg copy action to
5505 * copy reg_a from WQE to reg_c[0].
5508 * Pointer to Ethernet device.
5510 * Parent flow structure pointer.
5512 * Flow rule attributes.
5514 * Pattern specification (list terminated by the END pattern item).
5515 * @param[in] actions
5516 * Associated actions (list terminated by the END action).
5517 * @param[in] flow_split_info
5518 * Pointer to flow split info structure.
5520 * Perform verbose error reporting if not NULL.
5522 * 0 on success, negative value otherwise
5525 flow_create_split_metadata(struct rte_eth_dev *dev,
5526 struct rte_flow *flow,
5527 const struct rte_flow_attr *attr,
5528 const struct rte_flow_item items[],
5529 const struct rte_flow_action actions[],
5530 struct mlx5_flow_split_info *flow_split_info,
5531 struct rte_flow_error *error)
5533 struct mlx5_priv *priv = dev->data->dev_private;
5534 struct mlx5_dev_config *config = &priv->config;
5535 const struct rte_flow_action *qrss = NULL;
5536 struct rte_flow_action *ext_actions = NULL;
5537 struct mlx5_flow *dev_flow = NULL;
5538 uint32_t qrss_id = 0;
5545 /* Check whether extensive metadata feature is engaged. */
5546 if (!config->dv_flow_en ||
5547 config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
5548 !mlx5_flow_ext_mreg_supported(dev))
5549 return flow_create_split_inner(dev, flow, NULL, attr, items,
5550 actions, flow_split_info, error);
5551 actions_n = flow_parse_metadata_split_actions_info(actions, &qrss,
5554 /* Exclude hairpin flows from splitting. */
5555 if (qrss->type == RTE_FLOW_ACTION_TYPE_QUEUE) {
5556 const struct rte_flow_action_queue *queue;
5559 if (mlx5_rxq_get_type(dev, queue->index) ==
5560 MLX5_RXQ_TYPE_HAIRPIN)
5562 } else if (qrss->type == RTE_FLOW_ACTION_TYPE_RSS) {
5563 const struct rte_flow_action_rss *rss;
5566 if (mlx5_rxq_get_type(dev, rss->queue[0]) ==
5567 MLX5_RXQ_TYPE_HAIRPIN)
5572 /* Check if it is in meter suffix table. */
5573 mtr_sfx = attr->group == (attr->transfer ?
5574 (MLX5_FLOW_TABLE_LEVEL_METER - 1) :
5575 MLX5_FLOW_TABLE_LEVEL_METER);
5577 * Q/RSS action on NIC Rx should be split in order to pass by
5578 * the mreg copy table (RX_CP_TBL) and then it jumps to the
5579 * action table (RX_ACT_TBL) which has the split Q/RSS action.
5581 act_size = sizeof(struct rte_flow_action) * (actions_n + 1) +
5582 sizeof(struct rte_flow_action_set_tag) +
5583 sizeof(struct rte_flow_action_jump);
5584 ext_actions = mlx5_malloc(MLX5_MEM_ZERO, act_size, 0,
5587 return rte_flow_error_set(error, ENOMEM,
5588 RTE_FLOW_ERROR_TYPE_ACTION,
5589 NULL, "no memory to split "
5592 * If we are the suffix flow of meter, tag already exist.
5593 * Set the tag action to void.
5596 ext_actions[qrss - actions].type =
5597 RTE_FLOW_ACTION_TYPE_VOID;
5599 ext_actions[qrss - actions].type =
5600 (enum rte_flow_action_type)
5601 MLX5_RTE_FLOW_ACTION_TYPE_TAG;
5603 * Create the new actions list with removed Q/RSS action
5604 * and appended set tag and jump to register copy table
5605 * (RX_CP_TBL). We should preallocate unique tag ID here
5606 * in advance, because it is needed for set tag action.
5608 qrss_id = flow_mreg_split_qrss_prep(dev, ext_actions, actions,
5609 qrss, actions_n, error);
5610 if (!mtr_sfx && !qrss_id) {
5614 } else if (attr->egress && !attr->transfer) {
5616 * All the actions on NIC Tx should have a metadata register
5617 * copy action to copy reg_a from WQE to reg_c[meta]
5619 act_size = sizeof(struct rte_flow_action) * (actions_n + 1) +
5620 sizeof(struct mlx5_flow_action_copy_mreg);
5621 ext_actions = mlx5_malloc(MLX5_MEM_ZERO, act_size, 0,
5624 return rte_flow_error_set(error, ENOMEM,
5625 RTE_FLOW_ERROR_TYPE_ACTION,
5626 NULL, "no memory to split "
5628 /* Create the action list appended with copy register. */
5629 ret = flow_mreg_tx_copy_prep(dev, ext_actions, actions,
5630 actions_n, error, encap_idx);
5634 /* Add the unmodified original or prefix subflow. */
5635 ret = flow_create_split_inner(dev, flow, &dev_flow, attr,
5636 items, ext_actions ? ext_actions :
5637 actions, flow_split_info, error);
5640 MLX5_ASSERT(dev_flow);
5642 const struct rte_flow_attr q_attr = {
5643 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
5646 /* Internal PMD action to set register. */
5647 struct mlx5_rte_flow_item_tag q_tag_spec = {
5651 struct rte_flow_item q_items[] = {
5653 .type = (enum rte_flow_item_type)
5654 MLX5_RTE_FLOW_ITEM_TYPE_TAG,
5655 .spec = &q_tag_spec,
5660 .type = RTE_FLOW_ITEM_TYPE_END,
5663 struct rte_flow_action q_actions[] = {
5669 .type = RTE_FLOW_ACTION_TYPE_END,
5672 uint64_t layers = flow_get_prefix_layer_flags(dev_flow);
5675 * Configure the tag item only if there is no meter subflow.
5676 * Since tag is already marked in the meter suffix subflow
5677 * we can just use the meter suffix items as is.
5680 /* Not meter subflow. */
5681 MLX5_ASSERT(!mtr_sfx);
5683 * Put unique id in prefix flow due to it is destroyed
5684 * after suffix flow and id will be freed after there
5685 * is no actual flows with this id and identifier
5686 * reallocation becomes possible (for example, for
5687 * other flows in other threads).
5689 dev_flow->handle->split_flow_id = qrss_id;
5690 ret = mlx5_flow_get_reg_id(dev, MLX5_COPY_MARK, 0,
5694 q_tag_spec.id = ret;
5697 /* Add suffix subflow to execute Q/RSS. */
5698 flow_split_info->prefix_layers = layers;
5699 flow_split_info->prefix_mark = 0;
5700 ret = flow_create_split_inner(dev, flow, &dev_flow,
5701 &q_attr, mtr_sfx ? items :
5703 flow_split_info, error);
5706 /* qrss ID should be freed if failed. */
5708 MLX5_ASSERT(dev_flow);
5713 * We do not destroy the partially created sub_flows in case of error.
5714 * These ones are included into parent flow list and will be destroyed
5715 * by flow_drv_destroy.
5717 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RSS_EXPANTION_FLOW_ID],
5719 mlx5_free(ext_actions);
5724 * Create meter internal drop flow with the original pattern.
5727 * Pointer to Ethernet device.
5729 * Parent flow structure pointer.
5731 * Flow rule attributes.
5733 * Pattern specification (list terminated by the END pattern item).
5734 * @param[in] flow_split_info
5735 * Pointer to flow split info structure.
5737 * Pointer to flow meter structure.
5739 * Perform verbose error reporting if not NULL.
5741 * 0 on success, negative value otherwise
5744 flow_meter_create_drop_flow_with_org_pattern(struct rte_eth_dev *dev,
5745 struct rte_flow *flow,
5746 const struct rte_flow_attr *attr,
5747 const struct rte_flow_item items[],
5748 struct mlx5_flow_split_info *flow_split_info,
5749 struct mlx5_flow_meter_info *fm,
5750 struct rte_flow_error *error)
5752 struct mlx5_flow *dev_flow = NULL;
5753 struct rte_flow_attr drop_attr = *attr;
5754 struct rte_flow_action drop_actions[3];
5755 struct mlx5_flow_split_info drop_split_info = *flow_split_info;
5757 MLX5_ASSERT(fm->drop_cnt);
5758 drop_actions[0].type =
5759 (enum rte_flow_action_type)MLX5_RTE_FLOW_ACTION_TYPE_COUNT;
5760 drop_actions[0].conf = (void *)(uintptr_t)fm->drop_cnt;
5761 drop_actions[1].type = RTE_FLOW_ACTION_TYPE_DROP;
5762 drop_actions[1].conf = NULL;
5763 drop_actions[2].type = RTE_FLOW_ACTION_TYPE_END;
5764 drop_actions[2].conf = NULL;
5765 drop_split_info.external = false;
5766 drop_split_info.skip_scale |= 1 << MLX5_SCALE_FLOW_GROUP_BIT;
5767 drop_split_info.table_id = MLX5_MTR_TABLE_ID_DROP;
5768 drop_attr.group = MLX5_FLOW_TABLE_LEVEL_METER;
5769 return flow_create_split_inner(dev, flow, &dev_flow,
5770 &drop_attr, items, drop_actions,
5771 &drop_split_info, error);
5775 * The splitting for meter feature.
5777 * - The meter flow will be split to two flows as prefix and
5778 * suffix flow. The packets make sense only it pass the prefix
5781 * - Reg_C_5 is used for the packet to match betweend prefix and
5785 * Pointer to Ethernet device.
5787 * Parent flow structure pointer.
5789 * Flow rule attributes.
5791 * Pattern specification (list terminated by the END pattern item).
5792 * @param[in] actions
5793 * Associated actions (list terminated by the END action).
5794 * @param[in] flow_split_info
5795 * Pointer to flow split info structure.
5797 * Perform verbose error reporting if not NULL.
5799 * 0 on success, negative value otherwise
5802 flow_create_split_meter(struct rte_eth_dev *dev,
5803 struct rte_flow *flow,
5804 const struct rte_flow_attr *attr,
5805 const struct rte_flow_item items[],
5806 const struct rte_flow_action actions[],
5807 struct mlx5_flow_split_info *flow_split_info,
5808 struct rte_flow_error *error)
5810 struct mlx5_priv *priv = dev->data->dev_private;
5811 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
5812 struct rte_flow_action *sfx_actions = NULL;
5813 struct rte_flow_action *pre_actions = NULL;
5814 struct rte_flow_item *sfx_items = NULL;
5815 struct mlx5_flow *dev_flow = NULL;
5816 struct rte_flow_attr sfx_attr = *attr;
5817 struct mlx5_flow_meter_info *fm = NULL;
5818 uint8_t skip_scale_restore;
5819 bool has_mtr = false;
5820 bool has_modify = false;
5821 bool set_mtr_reg = true;
5822 bool is_mtr_hierarchy = false;
5823 uint32_t meter_id = 0;
5824 uint32_t mtr_idx = 0;
5825 uint32_t mtr_flow_id = 0;
5832 actions_n = flow_check_meter_action(dev, actions, &has_mtr,
5833 &has_modify, &meter_id);
5836 fm = flow_dv_meter_find_by_idx(priv, flow->meter);
5838 return rte_flow_error_set(error, EINVAL,
5839 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5840 NULL, "Meter not found.");
5842 fm = mlx5_flow_meter_find(priv, meter_id, &mtr_idx);
5844 return rte_flow_error_set(error, EINVAL,
5845 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5846 NULL, "Meter not found.");
5847 ret = mlx5_flow_meter_attach(priv, fm,
5851 flow->meter = mtr_idx;
5855 if (!fm->def_policy) {
5856 wks->policy = mlx5_flow_meter_policy_find(dev,
5859 MLX5_ASSERT(wks->policy);
5860 if (wks->policy->is_hierarchy) {
5862 mlx5_flow_meter_hierarchy_get_final_policy(dev,
5864 if (!wks->final_policy)
5865 return rte_flow_error_set(error,
5867 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5868 "Failed to find terminal policy of hierarchy.");
5869 is_mtr_hierarchy = true;
5873 * If it isn't default-policy Meter, and
5874 * 1. There's no action in flow to change
5875 * packet (modify/encap/decap etc.), OR
5876 * 2. No drop count needed for this meter.
5877 * 3. It's not meter hierarchy.
5878 * Then no need to use regC to save meter id anymore.
5880 if (!fm->def_policy && !is_mtr_hierarchy &&
5881 (!has_modify || !fm->drop_cnt))
5882 set_mtr_reg = false;
5883 /* Prefix actions: meter, decap, encap, tag, jump, end. */
5884 act_size = sizeof(struct rte_flow_action) * (actions_n + 6) +
5885 sizeof(struct mlx5_rte_flow_action_set_tag);
5886 /* Suffix items: tag, vlan, port id, end. */
5887 #define METER_SUFFIX_ITEM 4
5888 item_size = sizeof(struct rte_flow_item) * METER_SUFFIX_ITEM +
5889 sizeof(struct mlx5_rte_flow_item_tag) * 2;
5890 sfx_actions = mlx5_malloc(MLX5_MEM_ZERO, (act_size + item_size),
5893 return rte_flow_error_set(error, ENOMEM,
5894 RTE_FLOW_ERROR_TYPE_ACTION,
5895 NULL, "no memory to split "
5897 sfx_items = (struct rte_flow_item *)((char *)sfx_actions +
5899 /* There's no suffix flow for meter of non-default policy. */
5900 if (!fm->def_policy)
5901 pre_actions = sfx_actions + 1;
5903 pre_actions = sfx_actions + actions_n;
5904 ret = flow_meter_split_prep(dev, flow, wks, &sfx_attr,
5905 items, sfx_items, actions,
5906 sfx_actions, pre_actions,
5907 (set_mtr_reg ? &mtr_flow_id : NULL),
5913 /* Add the prefix subflow. */
5914 flow_split_info->prefix_mark = 0;
5915 skip_scale_restore = flow_split_info->skip_scale;
5916 flow_split_info->skip_scale |=
5917 1 << MLX5_SCALE_JUMP_FLOW_GROUP_BIT;
5918 ret = flow_create_split_inner(dev, flow, &dev_flow,
5919 attr, items, pre_actions,
5920 flow_split_info, error);
5921 flow_split_info->skip_scale = skip_scale_restore;
5924 mlx5_ipool_free(fm->flow_ipool, mtr_flow_id);
5929 dev_flow->handle->split_flow_id = mtr_flow_id;
5930 dev_flow->handle->is_meter_flow_id = 1;
5932 if (!fm->def_policy) {
5933 if (!set_mtr_reg && fm->drop_cnt)
5935 flow_meter_create_drop_flow_with_org_pattern(dev, flow,
5941 /* Setting the sfx group atrr. */
5942 sfx_attr.group = sfx_attr.transfer ?
5943 (MLX5_FLOW_TABLE_LEVEL_METER - 1) :
5944 MLX5_FLOW_TABLE_LEVEL_METER;
5945 flow_split_info->prefix_layers =
5946 flow_get_prefix_layer_flags(dev_flow);
5947 flow_split_info->prefix_mark = dev_flow->handle->mark;
5948 flow_split_info->table_id = MLX5_MTR_TABLE_ID_SUFFIX;
5950 /* Add the prefix subflow. */
5951 ret = flow_create_split_metadata(dev, flow,
5952 &sfx_attr, sfx_items ?
5954 sfx_actions ? sfx_actions : actions,
5955 flow_split_info, error);
5958 mlx5_free(sfx_actions);
5963 * The splitting for sample feature.
5965 * Once Sample action is detected in the action list, the flow actions should
5966 * be split into prefix sub flow and suffix sub flow.
5968 * The original items remain in the prefix sub flow, all actions preceding the
5969 * sample action and the sample action itself will be copied to the prefix
5970 * sub flow, the actions following the sample action will be copied to the
5971 * suffix sub flow, Queue action always be located in the suffix sub flow.
5973 * In order to make the packet from prefix sub flow matches with suffix sub
5974 * flow, an extra tag action be added into prefix sub flow, and the suffix sub
5975 * flow uses tag item with the unique flow id.
5978 * Pointer to Ethernet device.
5980 * Parent flow structure pointer.
5982 * Flow rule attributes.
5984 * Pattern specification (list terminated by the END pattern item).
5985 * @param[in] actions
5986 * Associated actions (list terminated by the END action).
5987 * @param[in] flow_split_info
5988 * Pointer to flow split info structure.
5990 * Perform verbose error reporting if not NULL.
5992 * 0 on success, negative value otherwise
5995 flow_create_split_sample(struct rte_eth_dev *dev,
5996 struct rte_flow *flow,
5997 const struct rte_flow_attr *attr,
5998 const struct rte_flow_item items[],
5999 const struct rte_flow_action actions[],
6000 struct mlx5_flow_split_info *flow_split_info,
6001 struct rte_flow_error *error)
6003 struct mlx5_priv *priv = dev->data->dev_private;
6004 struct rte_flow_action *sfx_actions = NULL;
6005 struct rte_flow_action *pre_actions = NULL;
6006 struct rte_flow_item *sfx_items = NULL;
6007 struct mlx5_flow *dev_flow = NULL;
6008 struct rte_flow_attr sfx_attr = *attr;
6009 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
6010 struct mlx5_flow_dv_sample_resource *sample_res;
6011 struct mlx5_flow_tbl_data_entry *sfx_tbl_data;
6012 struct mlx5_flow_tbl_resource *sfx_tbl;
6016 uint32_t fdb_tx = 0;
6019 int sample_action_pos;
6020 int qrss_action_pos;
6022 int modify_after_mirror = 0;
6023 uint16_t jump_table = 0;
6024 const uint32_t next_ft_step = 1;
6027 if (priv->sampler_en)
6028 actions_n = flow_check_match_action(actions, attr,
6029 RTE_FLOW_ACTION_TYPE_SAMPLE,
6030 &sample_action_pos, &qrss_action_pos,
6031 &modify_after_mirror);
6033 /* The prefix actions must includes sample, tag, end. */
6034 act_size = sizeof(struct rte_flow_action) * (actions_n * 2 + 1)
6035 + sizeof(struct mlx5_rte_flow_action_set_tag);
6036 item_size = sizeof(struct rte_flow_item) * SAMPLE_SUFFIX_ITEM +
6037 sizeof(struct mlx5_rte_flow_item_tag) * 2;
6038 sfx_actions = mlx5_malloc(MLX5_MEM_ZERO, (act_size +
6039 item_size), 0, SOCKET_ID_ANY);
6041 return rte_flow_error_set(error, ENOMEM,
6042 RTE_FLOW_ERROR_TYPE_ACTION,
6043 NULL, "no memory to split "
6045 /* The representor_id is UINT16_MAX for uplink. */
6046 fdb_tx = (attr->transfer && priv->representor_id != UINT16_MAX);
6048 * When reg_c_preserve is set, metadata registers Cx preserve
6049 * their value even through packet duplication.
6051 add_tag = (!fdb_tx || priv->config.hca_attr.reg_c_preserve);
6053 sfx_items = (struct rte_flow_item *)((char *)sfx_actions
6055 if (modify_after_mirror)
6056 jump_table = attr->group * MLX5_FLOW_TABLE_FACTOR +
6058 pre_actions = sfx_actions + actions_n;
6059 tag_id = flow_sample_split_prep(dev, add_tag, sfx_items,
6060 actions, sfx_actions,
6061 pre_actions, actions_n,
6063 qrss_action_pos, jump_table,
6065 if (tag_id < 0 || (add_tag && !tag_id)) {
6069 if (modify_after_mirror)
6070 flow_split_info->skip_scale =
6071 1 << MLX5_SCALE_JUMP_FLOW_GROUP_BIT;
6072 /* Add the prefix subflow. */
6073 ret = flow_create_split_inner(dev, flow, &dev_flow, attr,
6075 flow_split_info, error);
6080 dev_flow->handle->split_flow_id = tag_id;
6081 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
6082 if (!modify_after_mirror) {
6083 /* Set the sfx group attr. */
6084 sample_res = (struct mlx5_flow_dv_sample_resource *)
6085 dev_flow->dv.sample_res;
6086 sfx_tbl = (struct mlx5_flow_tbl_resource *)
6087 sample_res->normal_path_tbl;
6088 sfx_tbl_data = container_of(sfx_tbl,
6089 struct mlx5_flow_tbl_data_entry,
6091 sfx_attr.group = sfx_attr.transfer ?
6092 (sfx_tbl_data->level - 1) : sfx_tbl_data->level;
6094 MLX5_ASSERT(attr->transfer);
6095 sfx_attr.group = jump_table;
6097 flow_split_info->prefix_layers =
6098 flow_get_prefix_layer_flags(dev_flow);
6099 flow_split_info->prefix_mark = dev_flow->handle->mark;
6100 /* Suffix group level already be scaled with factor, set
6101 * MLX5_SCALE_FLOW_GROUP_BIT of skip_scale to 1 to avoid scale
6102 * again in translation.
6104 flow_split_info->skip_scale = 1 << MLX5_SCALE_FLOW_GROUP_BIT;
6107 /* Add the suffix subflow. */
6108 ret = flow_create_split_meter(dev, flow, &sfx_attr,
6109 sfx_items ? sfx_items : items,
6110 sfx_actions ? sfx_actions : actions,
6111 flow_split_info, error);
6114 mlx5_free(sfx_actions);
6119 * Split the flow to subflow set. The splitters might be linked
6120 * in the chain, like this:
6121 * flow_create_split_outer() calls:
6122 * flow_create_split_meter() calls:
6123 * flow_create_split_metadata(meter_subflow_0) calls:
6124 * flow_create_split_inner(metadata_subflow_0)
6125 * flow_create_split_inner(metadata_subflow_1)
6126 * flow_create_split_inner(metadata_subflow_2)
6127 * flow_create_split_metadata(meter_subflow_1) calls:
6128 * flow_create_split_inner(metadata_subflow_0)
6129 * flow_create_split_inner(metadata_subflow_1)
6130 * flow_create_split_inner(metadata_subflow_2)
6132 * This provide flexible way to add new levels of flow splitting.
6133 * The all of successfully created subflows are included to the
6134 * parent flow dev_flow list.
6137 * Pointer to Ethernet device.
6139 * Parent flow structure pointer.
6141 * Flow rule attributes.
6143 * Pattern specification (list terminated by the END pattern item).
6144 * @param[in] actions
6145 * Associated actions (list terminated by the END action).
6146 * @param[in] flow_split_info
6147 * Pointer to flow split info structure.
6149 * Perform verbose error reporting if not NULL.
6151 * 0 on success, negative value otherwise
6154 flow_create_split_outer(struct rte_eth_dev *dev,
6155 struct rte_flow *flow,
6156 const struct rte_flow_attr *attr,
6157 const struct rte_flow_item items[],
6158 const struct rte_flow_action actions[],
6159 struct mlx5_flow_split_info *flow_split_info,
6160 struct rte_flow_error *error)
6164 ret = flow_create_split_sample(dev, flow, attr, items,
6165 actions, flow_split_info, error);
6166 MLX5_ASSERT(ret <= 0);
6170 static inline struct mlx5_flow_tunnel *
6171 flow_tunnel_from_rule(const struct mlx5_flow *flow)
6173 struct mlx5_flow_tunnel *tunnel;
6175 #pragma GCC diagnostic push
6176 #pragma GCC diagnostic ignored "-Wcast-qual"
6177 tunnel = (typeof(tunnel))flow->tunnel;
6178 #pragma GCC diagnostic pop
6184 * Adjust flow RSS workspace if needed.
6187 * Pointer to thread flow work space.
6189 * Pointer to RSS descriptor.
6190 * @param[in] nrssq_num
6191 * New RSS queue number.
6194 * 0 on success, -1 otherwise and rte_errno is set.
6197 flow_rss_workspace_adjust(struct mlx5_flow_workspace *wks,
6198 struct mlx5_flow_rss_desc *rss_desc,
6201 if (likely(nrssq_num <= wks->rssq_num))
6203 rss_desc->queue = realloc(rss_desc->queue,
6204 sizeof(*rss_desc->queue) * RTE_ALIGN(nrssq_num, 2));
6205 if (!rss_desc->queue) {
6209 wks->rssq_num = RTE_ALIGN(nrssq_num, 2);
6214 * Create a flow and add it to @p list.
6217 * Pointer to Ethernet device.
6219 * Pointer to a TAILQ flow list. If this parameter NULL,
6220 * no list insertion occurred, flow is just created,
6221 * this is caller's responsibility to track the
6224 * Flow rule attributes.
6226 * Pattern specification (list terminated by the END pattern item).
6227 * @param[in] actions
6228 * Associated actions (list terminated by the END action).
6229 * @param[in] external
6230 * This flow rule is created by request external to PMD.
6232 * Perform verbose error reporting if not NULL.
6235 * A flow index on success, 0 otherwise and rte_errno is set.
6238 flow_list_create(struct rte_eth_dev *dev, enum mlx5_flow_type type,
6239 const struct rte_flow_attr *attr,
6240 const struct rte_flow_item items[],
6241 const struct rte_flow_action original_actions[],
6242 bool external, struct rte_flow_error *error)
6244 struct mlx5_priv *priv = dev->data->dev_private;
6245 struct rte_flow *flow = NULL;
6246 struct mlx5_flow *dev_flow;
6247 const struct rte_flow_action_rss *rss = NULL;
6248 struct mlx5_translated_action_handle
6249 indir_actions[MLX5_MAX_INDIRECT_ACTIONS];
6250 int indir_actions_n = MLX5_MAX_INDIRECT_ACTIONS;
6252 struct mlx5_flow_expand_rss buf;
6253 uint8_t buffer[2048];
6256 struct rte_flow_action actions[MLX5_MAX_SPLIT_ACTIONS];
6257 uint8_t buffer[2048];
6260 struct rte_flow_action actions[MLX5_MAX_SPLIT_ACTIONS];
6261 uint8_t buffer[2048];
6262 } actions_hairpin_tx;
6264 struct rte_flow_item items[MLX5_MAX_SPLIT_ITEMS];
6265 uint8_t buffer[2048];
6267 struct mlx5_flow_expand_rss *buf = &expand_buffer.buf;
6268 struct mlx5_flow_rss_desc *rss_desc;
6269 const struct rte_flow_action *p_actions_rx;
6273 struct rte_flow_attr attr_tx = { .priority = 0 };
6274 const struct rte_flow_action *actions;
6275 struct rte_flow_action *translated_actions = NULL;
6276 struct mlx5_flow_tunnel *tunnel;
6277 struct tunnel_default_miss_ctx default_miss_ctx = { 0, };
6278 struct mlx5_flow_workspace *wks = mlx5_flow_push_thread_workspace();
6279 struct mlx5_flow_split_info flow_split_info = {
6280 .external = !!external,
6290 rss_desc = &wks->rss_desc;
6291 ret = flow_action_handles_translate(dev, original_actions,
6294 &translated_actions, error);
6296 MLX5_ASSERT(translated_actions == NULL);
6299 actions = translated_actions ? translated_actions : original_actions;
6300 p_actions_rx = actions;
6301 hairpin_flow = flow_check_hairpin_split(dev, attr, actions);
6302 ret = flow_drv_validate(dev, attr, items, p_actions_rx,
6303 external, hairpin_flow, error);
6305 goto error_before_hairpin_split;
6306 flow = mlx5_ipool_zmalloc(priv->flows[type], &idx);
6309 goto error_before_hairpin_split;
6311 if (hairpin_flow > 0) {
6312 if (hairpin_flow > MLX5_MAX_SPLIT_ACTIONS) {
6314 goto error_before_hairpin_split;
6316 flow_hairpin_split(dev, actions, actions_rx.actions,
6317 actions_hairpin_tx.actions, items_tx.items,
6319 p_actions_rx = actions_rx.actions;
6321 flow_split_info.flow_idx = idx;
6322 flow->drv_type = flow_get_drv_type(dev, attr);
6323 MLX5_ASSERT(flow->drv_type > MLX5_FLOW_TYPE_MIN &&
6324 flow->drv_type < MLX5_FLOW_TYPE_MAX);
6325 memset(rss_desc, 0, offsetof(struct mlx5_flow_rss_desc, queue));
6326 /* RSS Action only works on NIC RX domain */
6327 if (attr->ingress && !attr->transfer)
6328 rss = flow_get_rss_action(dev, p_actions_rx);
6330 if (flow_rss_workspace_adjust(wks, rss_desc, rss->queue_num))
6333 * The following information is required by
6334 * mlx5_flow_hashfields_adjust() in advance.
6336 rss_desc->level = rss->level;
6337 /* RSS type 0 indicates default RSS type (ETH_RSS_IP). */
6338 rss_desc->types = !rss->types ? ETH_RSS_IP : rss->types;
6340 flow->dev_handles = 0;
6341 if (rss && rss->types) {
6342 unsigned int graph_root;
6344 graph_root = find_graph_root(items, rss->level);
6345 ret = mlx5_flow_expand_rss(buf, sizeof(expand_buffer.buffer),
6347 mlx5_support_expansion, graph_root);
6348 MLX5_ASSERT(ret > 0 &&
6349 (unsigned int)ret < sizeof(expand_buffer.buffer));
6350 if (rte_log_can_log(mlx5_logtype, RTE_LOG_DEBUG)) {
6351 for (i = 0; i < buf->entries; ++i)
6352 mlx5_dbg__print_pattern(buf->entry[i].pattern);
6356 buf->entry[0].pattern = (void *)(uintptr_t)items;
6358 rss_desc->shared_rss = flow_get_shared_rss_action(dev, indir_actions,
6360 for (i = 0; i < buf->entries; ++i) {
6361 /* Initialize flow split data. */
6362 flow_split_info.prefix_layers = 0;
6363 flow_split_info.prefix_mark = 0;
6364 flow_split_info.skip_scale = 0;
6366 * The splitter may create multiple dev_flows,
6367 * depending on configuration. In the simplest
6368 * case it just creates unmodified original flow.
6370 ret = flow_create_split_outer(dev, flow, attr,
6371 buf->entry[i].pattern,
6372 p_actions_rx, &flow_split_info,
6376 if (is_flow_tunnel_steer_rule(wks->flows[0].tof_type)) {
6377 ret = flow_tunnel_add_default_miss(dev, flow, attr,
6380 wks->flows[0].tunnel,
6384 mlx5_free(default_miss_ctx.queue);
6389 /* Create the tx flow. */
6391 attr_tx.group = MLX5_HAIRPIN_TX_TABLE;
6392 attr_tx.ingress = 0;
6394 dev_flow = flow_drv_prepare(dev, flow, &attr_tx, items_tx.items,
6395 actions_hairpin_tx.actions,
6399 dev_flow->flow = flow;
6400 dev_flow->external = 0;
6401 SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
6402 dev_flow->handle, next);
6403 ret = flow_drv_translate(dev, dev_flow, &attr_tx,
6405 actions_hairpin_tx.actions, error);
6410 * Update the metadata register copy table. If extensive
6411 * metadata feature is enabled and registers are supported
6412 * we might create the extra rte_flow for each unique
6413 * MARK/FLAG action ID.
6415 * The table is updated for ingress Flows only, because
6416 * the egress Flows belong to the different device and
6417 * copy table should be updated in peer NIC Rx domain.
6419 if (attr->ingress &&
6420 (external || attr->group != MLX5_FLOW_MREG_CP_TABLE_GROUP)) {
6421 ret = flow_mreg_update_copy_table(dev, flow, actions, error);
6426 * If the flow is external (from application) OR device is started,
6427 * OR mreg discover, then apply immediately.
6429 if (external || dev->data->dev_started ||
6430 (attr->group == MLX5_FLOW_MREG_CP_TABLE_GROUP &&
6431 attr->priority == MLX5_FLOW_LOWEST_PRIO_INDICATOR)) {
6432 ret = flow_drv_apply(dev, flow, error);
6437 flow_rxq_flags_set(dev, flow);
6438 rte_free(translated_actions);
6439 tunnel = flow_tunnel_from_rule(wks->flows);
6442 flow->tunnel_id = tunnel->tunnel_id;
6443 __atomic_add_fetch(&tunnel->refctn, 1, __ATOMIC_RELAXED);
6444 mlx5_free(default_miss_ctx.queue);
6446 mlx5_flow_pop_thread_workspace();
6450 ret = rte_errno; /* Save rte_errno before cleanup. */
6451 flow_mreg_del_copy_action(dev, flow);
6452 flow_drv_destroy(dev, flow);
6453 if (rss_desc->shared_rss)
6454 __atomic_sub_fetch(&((struct mlx5_shared_action_rss *)
6456 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
6457 rss_desc->shared_rss))->refcnt, 1, __ATOMIC_RELAXED);
6458 mlx5_ipool_free(priv->flows[type], idx);
6459 rte_errno = ret; /* Restore rte_errno. */
6462 mlx5_flow_pop_thread_workspace();
6463 error_before_hairpin_split:
6464 rte_free(translated_actions);
6469 * Create a dedicated flow rule on e-switch table 0 (root table), to direct all
6470 * incoming packets to table 1.
6472 * Other flow rules, requested for group n, will be created in
6473 * e-switch table n+1.
6474 * Jump action to e-switch group n will be created to group n+1.
6476 * Used when working in switchdev mode, to utilise advantages of table 1
6480 * Pointer to Ethernet device.
6483 * Pointer to flow on success, NULL otherwise and rte_errno is set.
6486 mlx5_flow_create_esw_table_zero_flow(struct rte_eth_dev *dev)
6488 const struct rte_flow_attr attr = {
6495 const struct rte_flow_item pattern = {
6496 .type = RTE_FLOW_ITEM_TYPE_END,
6498 struct rte_flow_action_jump jump = {
6501 const struct rte_flow_action actions[] = {
6503 .type = RTE_FLOW_ACTION_TYPE_JUMP,
6507 .type = RTE_FLOW_ACTION_TYPE_END,
6510 struct rte_flow_error error;
6512 return (void *)(uintptr_t)flow_list_create(dev, MLX5_FLOW_TYPE_CTL,
6514 actions, false, &error);
6518 * Validate a flow supported by the NIC.
6520 * @see rte_flow_validate()
6524 mlx5_flow_validate(struct rte_eth_dev *dev,
6525 const struct rte_flow_attr *attr,
6526 const struct rte_flow_item items[],
6527 const struct rte_flow_action original_actions[],
6528 struct rte_flow_error *error)
6531 struct mlx5_translated_action_handle
6532 indir_actions[MLX5_MAX_INDIRECT_ACTIONS];
6533 int indir_actions_n = MLX5_MAX_INDIRECT_ACTIONS;
6534 const struct rte_flow_action *actions;
6535 struct rte_flow_action *translated_actions = NULL;
6536 int ret = flow_action_handles_translate(dev, original_actions,
6539 &translated_actions, error);
6543 actions = translated_actions ? translated_actions : original_actions;
6544 hairpin_flow = flow_check_hairpin_split(dev, attr, actions);
6545 ret = flow_drv_validate(dev, attr, items, actions,
6546 true, hairpin_flow, error);
6547 rte_free(translated_actions);
6554 * @see rte_flow_create()
6558 mlx5_flow_create(struct rte_eth_dev *dev,
6559 const struct rte_flow_attr *attr,
6560 const struct rte_flow_item items[],
6561 const struct rte_flow_action actions[],
6562 struct rte_flow_error *error)
6565 * If the device is not started yet, it is not allowed to created a
6566 * flow from application. PMD default flows and traffic control flows
6569 if (unlikely(!dev->data->dev_started)) {
6570 DRV_LOG(DEBUG, "port %u is not started when "
6571 "inserting a flow", dev->data->port_id);
6572 rte_flow_error_set(error, ENODEV,
6573 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6575 "port not started");
6579 return (void *)(uintptr_t)flow_list_create(dev, MLX5_FLOW_TYPE_GEN,
6580 attr, items, actions,
6585 * Destroy a flow in a list.
6588 * Pointer to Ethernet device.
6589 * @param[in] flow_idx
6590 * Index of flow to destroy.
6593 flow_list_destroy(struct rte_eth_dev *dev, enum mlx5_flow_type type,
6596 struct mlx5_priv *priv = dev->data->dev_private;
6597 struct rte_flow *flow = mlx5_ipool_get(priv->flows[type], flow_idx);
6601 MLX5_ASSERT(flow->type == type);
6603 * Update RX queue flags only if port is started, otherwise it is
6606 if (dev->data->dev_started)
6607 flow_rxq_flags_trim(dev, flow);
6608 flow_drv_destroy(dev, flow);
6610 struct mlx5_flow_tunnel *tunnel;
6612 tunnel = mlx5_find_tunnel_id(dev, flow->tunnel_id);
6614 if (!__atomic_sub_fetch(&tunnel->refctn, 1, __ATOMIC_RELAXED))
6615 mlx5_flow_tunnel_free(dev, tunnel);
6617 flow_mreg_del_copy_action(dev, flow);
6618 mlx5_ipool_free(priv->flows[type], flow_idx);
6622 * Destroy all flows.
6625 * Pointer to Ethernet device.
6627 * Flow type to be flushed.
6629 * If flushing is called avtively.
6632 mlx5_flow_list_flush(struct rte_eth_dev *dev, enum mlx5_flow_type type,
6635 struct mlx5_priv *priv = dev->data->dev_private;
6636 uint32_t num_flushed = 0, fidx = 1;
6637 struct rte_flow *flow;
6639 MLX5_IPOOL_FOREACH(priv->flows[type], fidx, flow) {
6640 flow_list_destroy(dev, type, fidx);
6644 DRV_LOG(INFO, "port %u: %u flows flushed before stopping",
6645 dev->data->port_id, num_flushed);
6650 * Stop all default actions for flows.
6653 * Pointer to Ethernet device.
6656 mlx5_flow_stop_default(struct rte_eth_dev *dev)
6658 flow_mreg_del_default_copy_action(dev);
6659 flow_rxq_flags_clear(dev);
6663 * Start all default actions for flows.
6666 * Pointer to Ethernet device.
6668 * 0 on success, a negative errno value otherwise and rte_errno is set.
6671 mlx5_flow_start_default(struct rte_eth_dev *dev)
6673 struct rte_flow_error error;
6675 /* Make sure default copy action (reg_c[0] -> reg_b) is created. */
6676 return flow_mreg_add_default_copy_action(dev, &error);
6680 * Release key of thread specific flow workspace data.
6683 flow_release_workspace(void *data)
6685 struct mlx5_flow_workspace *wks = data;
6686 struct mlx5_flow_workspace *next;
6690 free(wks->rss_desc.queue);
6697 * Get thread specific current flow workspace.
6699 * @return pointer to thread specific flow workspace data, NULL on error.
6701 struct mlx5_flow_workspace*
6702 mlx5_flow_get_thread_workspace(void)
6704 struct mlx5_flow_workspace *data;
6706 data = mlx5_flow_os_get_specific_workspace();
6707 MLX5_ASSERT(data && data->inuse);
6708 if (!data || !data->inuse)
6709 DRV_LOG(ERR, "flow workspace not initialized.");
6714 * Allocate and init new flow workspace.
6716 * @return pointer to flow workspace data, NULL on error.
6718 static struct mlx5_flow_workspace*
6719 flow_alloc_thread_workspace(void)
6721 struct mlx5_flow_workspace *data = calloc(1, sizeof(*data));
6724 DRV_LOG(ERR, "Failed to allocate flow workspace "
6728 data->rss_desc.queue = calloc(1,
6729 sizeof(uint16_t) * MLX5_RSSQ_DEFAULT_NUM);
6730 if (!data->rss_desc.queue)
6732 data->rssq_num = MLX5_RSSQ_DEFAULT_NUM;
6735 if (data->rss_desc.queue)
6736 free(data->rss_desc.queue);
6742 * Get new thread specific flow workspace.
6744 * If current workspace inuse, create new one and set as current.
6746 * @return pointer to thread specific flow workspace data, NULL on error.
6748 static struct mlx5_flow_workspace*
6749 mlx5_flow_push_thread_workspace(void)
6751 struct mlx5_flow_workspace *curr;
6752 struct mlx5_flow_workspace *data;
6754 curr = mlx5_flow_os_get_specific_workspace();
6756 data = flow_alloc_thread_workspace();
6759 } else if (!curr->inuse) {
6761 } else if (curr->next) {
6764 data = flow_alloc_thread_workspace();
6772 /* Set as current workspace */
6773 if (mlx5_flow_os_set_specific_workspace(data))
6774 DRV_LOG(ERR, "Failed to set flow workspace to thread.");
6779 * Close current thread specific flow workspace.
6781 * If previous workspace available, set it as current.
6783 * @return pointer to thread specific flow workspace data, NULL on error.
6786 mlx5_flow_pop_thread_workspace(void)
6788 struct mlx5_flow_workspace *data = mlx5_flow_get_thread_workspace();
6793 DRV_LOG(ERR, "Failed to close unused flow workspace.");
6799 if (mlx5_flow_os_set_specific_workspace(data->prev))
6800 DRV_LOG(ERR, "Failed to set flow workspace to thread.");
6804 * Verify the flow list is empty
6807 * Pointer to Ethernet device.
6809 * @return the number of flows not released.
6812 mlx5_flow_verify(struct rte_eth_dev *dev __rte_unused)
6814 struct mlx5_priv *priv = dev->data->dev_private;
6815 struct rte_flow *flow;
6819 for (i = 0; i < MLX5_FLOW_TYPE_MAXI; i++) {
6820 MLX5_IPOOL_FOREACH(priv->flows[i], idx, flow) {
6821 DRV_LOG(DEBUG, "port %u flow %p still referenced",
6822 dev->data->port_id, (void *)flow);
6830 * Enable default hairpin egress flow.
6833 * Pointer to Ethernet device.
6838 * 0 on success, a negative errno value otherwise and rte_errno is set.
6841 mlx5_ctrl_flow_source_queue(struct rte_eth_dev *dev,
6844 const struct rte_flow_attr attr = {
6848 struct mlx5_rte_flow_item_tx_queue queue_spec = {
6851 struct mlx5_rte_flow_item_tx_queue queue_mask = {
6852 .queue = UINT32_MAX,
6854 struct rte_flow_item items[] = {
6856 .type = (enum rte_flow_item_type)
6857 MLX5_RTE_FLOW_ITEM_TYPE_TX_QUEUE,
6858 .spec = &queue_spec,
6860 .mask = &queue_mask,
6863 .type = RTE_FLOW_ITEM_TYPE_END,
6866 struct rte_flow_action_jump jump = {
6867 .group = MLX5_HAIRPIN_TX_TABLE,
6869 struct rte_flow_action actions[2];
6871 struct rte_flow_error error;
6873 actions[0].type = RTE_FLOW_ACTION_TYPE_JUMP;
6874 actions[0].conf = &jump;
6875 actions[1].type = RTE_FLOW_ACTION_TYPE_END;
6876 flow_idx = flow_list_create(dev, MLX5_FLOW_TYPE_CTL,
6877 &attr, items, actions, false, &error);
6880 "Failed to create ctrl flow: rte_errno(%d),"
6881 " type(%d), message(%s)",
6882 rte_errno, error.type,
6883 error.message ? error.message : " (no stated reason)");
6890 * Enable a control flow configured from the control plane.
6893 * Pointer to Ethernet device.
6895 * An Ethernet flow spec to apply.
6897 * An Ethernet flow mask to apply.
6899 * A VLAN flow spec to apply.
6901 * A VLAN flow mask to apply.
6904 * 0 on success, a negative errno value otherwise and rte_errno is set.
6907 mlx5_ctrl_flow_vlan(struct rte_eth_dev *dev,
6908 struct rte_flow_item_eth *eth_spec,
6909 struct rte_flow_item_eth *eth_mask,
6910 struct rte_flow_item_vlan *vlan_spec,
6911 struct rte_flow_item_vlan *vlan_mask)
6913 struct mlx5_priv *priv = dev->data->dev_private;
6914 const struct rte_flow_attr attr = {
6916 .priority = MLX5_FLOW_LOWEST_PRIO_INDICATOR,
6918 struct rte_flow_item items[] = {
6920 .type = RTE_FLOW_ITEM_TYPE_ETH,
6926 .type = (vlan_spec) ? RTE_FLOW_ITEM_TYPE_VLAN :
6927 RTE_FLOW_ITEM_TYPE_END,
6933 .type = RTE_FLOW_ITEM_TYPE_END,
6936 uint16_t queue[priv->reta_idx_n];
6937 struct rte_flow_action_rss action_rss = {
6938 .func = RTE_ETH_HASH_FUNCTION_DEFAULT,
6940 .types = priv->rss_conf.rss_hf,
6941 .key_len = priv->rss_conf.rss_key_len,
6942 .queue_num = priv->reta_idx_n,
6943 .key = priv->rss_conf.rss_key,
6946 struct rte_flow_action actions[] = {
6948 .type = RTE_FLOW_ACTION_TYPE_RSS,
6949 .conf = &action_rss,
6952 .type = RTE_FLOW_ACTION_TYPE_END,
6956 struct rte_flow_error error;
6959 if (!priv->reta_idx_n || !priv->rxqs_n) {
6962 if (!(dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG))
6963 action_rss.types = 0;
6964 for (i = 0; i != priv->reta_idx_n; ++i)
6965 queue[i] = (*priv->reta_idx)[i];
6966 flow_idx = flow_list_create(dev, MLX5_FLOW_TYPE_CTL,
6967 &attr, items, actions, false, &error);
6974 * Enable a flow control configured from the control plane.
6977 * Pointer to Ethernet device.
6979 * An Ethernet flow spec to apply.
6981 * An Ethernet flow mask to apply.
6984 * 0 on success, a negative errno value otherwise and rte_errno is set.
6987 mlx5_ctrl_flow(struct rte_eth_dev *dev,
6988 struct rte_flow_item_eth *eth_spec,
6989 struct rte_flow_item_eth *eth_mask)
6991 return mlx5_ctrl_flow_vlan(dev, eth_spec, eth_mask, NULL, NULL);
6995 * Create default miss flow rule matching lacp traffic
6998 * Pointer to Ethernet device.
7000 * An Ethernet flow spec to apply.
7003 * 0 on success, a negative errno value otherwise and rte_errno is set.
7006 mlx5_flow_lacp_miss(struct rte_eth_dev *dev)
7009 * The LACP matching is done by only using ether type since using
7010 * a multicast dst mac causes kernel to give low priority to this flow.
7012 static const struct rte_flow_item_eth lacp_spec = {
7013 .type = RTE_BE16(0x8809),
7015 static const struct rte_flow_item_eth lacp_mask = {
7018 const struct rte_flow_attr attr = {
7021 struct rte_flow_item items[] = {
7023 .type = RTE_FLOW_ITEM_TYPE_ETH,
7028 .type = RTE_FLOW_ITEM_TYPE_END,
7031 struct rte_flow_action actions[] = {
7033 .type = (enum rte_flow_action_type)
7034 MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS,
7037 .type = RTE_FLOW_ACTION_TYPE_END,
7040 struct rte_flow_error error;
7041 uint32_t flow_idx = flow_list_create(dev, MLX5_FLOW_TYPE_CTL,
7042 &attr, items, actions,
7053 * @see rte_flow_destroy()
7057 mlx5_flow_destroy(struct rte_eth_dev *dev,
7058 struct rte_flow *flow,
7059 struct rte_flow_error *error __rte_unused)
7061 flow_list_destroy(dev, MLX5_FLOW_TYPE_GEN,
7062 (uintptr_t)(void *)flow);
7067 * Destroy all flows.
7069 * @see rte_flow_flush()
7073 mlx5_flow_flush(struct rte_eth_dev *dev,
7074 struct rte_flow_error *error __rte_unused)
7076 mlx5_flow_list_flush(dev, MLX5_FLOW_TYPE_GEN, false);
7083 * @see rte_flow_isolate()
7087 mlx5_flow_isolate(struct rte_eth_dev *dev,
7089 struct rte_flow_error *error)
7091 struct mlx5_priv *priv = dev->data->dev_private;
7093 if (dev->data->dev_started) {
7094 rte_flow_error_set(error, EBUSY,
7095 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7097 "port must be stopped first");
7100 priv->isolated = !!enable;
7102 dev->dev_ops = &mlx5_dev_ops_isolate;
7104 dev->dev_ops = &mlx5_dev_ops;
7106 dev->rx_descriptor_status = mlx5_rx_descriptor_status;
7107 dev->tx_descriptor_status = mlx5_tx_descriptor_status;
7115 * @see rte_flow_query()
7119 flow_drv_query(struct rte_eth_dev *dev,
7121 const struct rte_flow_action *actions,
7123 struct rte_flow_error *error)
7125 struct mlx5_priv *priv = dev->data->dev_private;
7126 const struct mlx5_flow_driver_ops *fops;
7127 struct rte_flow *flow = mlx5_ipool_get(priv->flows[MLX5_FLOW_TYPE_GEN],
7129 enum mlx5_flow_drv_type ftype;
7132 return rte_flow_error_set(error, ENOENT,
7133 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7135 "invalid flow handle");
7137 ftype = flow->drv_type;
7138 MLX5_ASSERT(ftype > MLX5_FLOW_TYPE_MIN && ftype < MLX5_FLOW_TYPE_MAX);
7139 fops = flow_get_drv_ops(ftype);
7141 return fops->query(dev, flow, actions, data, error);
7147 * @see rte_flow_query()
7151 mlx5_flow_query(struct rte_eth_dev *dev,
7152 struct rte_flow *flow,
7153 const struct rte_flow_action *actions,
7155 struct rte_flow_error *error)
7159 ret = flow_drv_query(dev, (uintptr_t)(void *)flow, actions, data,
7167 * Get rte_flow callbacks.
7170 * Pointer to Ethernet device structure.
7172 * Pointer to operation-specific structure.
7177 mlx5_flow_ops_get(struct rte_eth_dev *dev __rte_unused,
7178 const struct rte_flow_ops **ops)
7180 *ops = &mlx5_flow_ops;
7185 * Validate meter policy actions.
7186 * Dispatcher for action type specific validation.
7189 * Pointer to the Ethernet device structure.
7191 * The meter policy action object to validate.
7193 * Attributes of flow to determine steering domain.
7194 * @param[out] is_rss
7196 * @param[out] domain_bitmap
7198 * @param[out] is_def_policy
7199 * Is default policy or not.
7201 * Perform verbose error reporting if not NULL. Initialized in case of
7205 * 0 on success, otherwise negative errno value.
7208 mlx5_flow_validate_mtr_acts(struct rte_eth_dev *dev,
7209 const struct rte_flow_action *actions[RTE_COLORS],
7210 struct rte_flow_attr *attr,
7212 uint8_t *domain_bitmap,
7213 uint8_t *policy_mode,
7214 struct rte_mtr_error *error)
7216 const struct mlx5_flow_driver_ops *fops;
7218 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7219 return fops->validate_mtr_acts(dev, actions, attr, is_rss,
7220 domain_bitmap, policy_mode, error);
7224 * Destroy the meter table set.
7227 * Pointer to Ethernet device.
7228 * @param[in] mtr_policy
7229 * Meter policy struct.
7232 mlx5_flow_destroy_mtr_acts(struct rte_eth_dev *dev,
7233 struct mlx5_flow_meter_policy *mtr_policy)
7235 const struct mlx5_flow_driver_ops *fops;
7237 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7238 fops->destroy_mtr_acts(dev, mtr_policy);
7242 * Create policy action, lock free,
7243 * (mutex should be acquired by caller).
7244 * Dispatcher for action type specific call.
7247 * Pointer to the Ethernet device structure.
7248 * @param[in] mtr_policy
7249 * Meter policy struct.
7251 * Action specification used to create meter actions.
7253 * Perform verbose error reporting if not NULL. Initialized in case of
7257 * 0 on success, otherwise negative errno value.
7260 mlx5_flow_create_mtr_acts(struct rte_eth_dev *dev,
7261 struct mlx5_flow_meter_policy *mtr_policy,
7262 const struct rte_flow_action *actions[RTE_COLORS],
7263 struct rte_mtr_error *error)
7265 const struct mlx5_flow_driver_ops *fops;
7267 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7268 return fops->create_mtr_acts(dev, mtr_policy, actions, error);
7272 * Create policy rules, lock free,
7273 * (mutex should be acquired by caller).
7274 * Dispatcher for action type specific call.
7277 * Pointer to the Ethernet device structure.
7278 * @param[in] mtr_policy
7279 * Meter policy struct.
7282 * 0 on success, -1 otherwise.
7285 mlx5_flow_create_policy_rules(struct rte_eth_dev *dev,
7286 struct mlx5_flow_meter_policy *mtr_policy)
7288 const struct mlx5_flow_driver_ops *fops;
7290 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7291 return fops->create_policy_rules(dev, mtr_policy);
7295 * Destroy policy rules, lock free,
7296 * (mutex should be acquired by caller).
7297 * Dispatcher for action type specific call.
7300 * Pointer to the Ethernet device structure.
7301 * @param[in] mtr_policy
7302 * Meter policy struct.
7305 mlx5_flow_destroy_policy_rules(struct rte_eth_dev *dev,
7306 struct mlx5_flow_meter_policy *mtr_policy)
7308 const struct mlx5_flow_driver_ops *fops;
7310 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7311 fops->destroy_policy_rules(dev, mtr_policy);
7315 * Destroy the default policy table set.
7318 * Pointer to Ethernet device.
7321 mlx5_flow_destroy_def_policy(struct rte_eth_dev *dev)
7323 const struct mlx5_flow_driver_ops *fops;
7325 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7326 fops->destroy_def_policy(dev);
7330 * Destroy the default policy table set.
7333 * Pointer to Ethernet device.
7336 * 0 on success, -1 otherwise.
7339 mlx5_flow_create_def_policy(struct rte_eth_dev *dev)
7341 const struct mlx5_flow_driver_ops *fops;
7343 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7344 return fops->create_def_policy(dev);
7348 * Create the needed meter and suffix tables.
7351 * Pointer to Ethernet device.
7354 * 0 on success, -1 otherwise.
7357 mlx5_flow_create_mtr_tbls(struct rte_eth_dev *dev,
7358 struct mlx5_flow_meter_info *fm,
7360 uint8_t domain_bitmap)
7362 const struct mlx5_flow_driver_ops *fops;
7364 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7365 return fops->create_mtr_tbls(dev, fm, mtr_idx, domain_bitmap);
7369 * Destroy the meter table set.
7372 * Pointer to Ethernet device.
7374 * Pointer to the meter table set.
7377 mlx5_flow_destroy_mtr_tbls(struct rte_eth_dev *dev,
7378 struct mlx5_flow_meter_info *fm)
7380 const struct mlx5_flow_driver_ops *fops;
7382 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7383 fops->destroy_mtr_tbls(dev, fm);
7387 * Destroy the global meter drop table.
7390 * Pointer to Ethernet device.
7393 mlx5_flow_destroy_mtr_drop_tbls(struct rte_eth_dev *dev)
7395 const struct mlx5_flow_driver_ops *fops;
7397 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7398 fops->destroy_mtr_drop_tbls(dev);
7402 * Destroy the sub policy table with RX queue.
7405 * Pointer to Ethernet device.
7406 * @param[in] mtr_policy
7407 * Pointer to meter policy table.
7410 mlx5_flow_destroy_sub_policy_with_rxq(struct rte_eth_dev *dev,
7411 struct mlx5_flow_meter_policy *mtr_policy)
7413 const struct mlx5_flow_driver_ops *fops;
7415 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7416 fops->destroy_sub_policy_with_rxq(dev, mtr_policy);
7420 * Allocate the needed aso flow meter id.
7423 * Pointer to Ethernet device.
7426 * Index to aso flow meter on success, NULL otherwise.
7429 mlx5_flow_mtr_alloc(struct rte_eth_dev *dev)
7431 const struct mlx5_flow_driver_ops *fops;
7433 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7434 return fops->create_meter(dev);
7438 * Free the aso flow meter id.
7441 * Pointer to Ethernet device.
7442 * @param[in] mtr_idx
7443 * Index to aso flow meter to be free.
7449 mlx5_flow_mtr_free(struct rte_eth_dev *dev, uint32_t mtr_idx)
7451 const struct mlx5_flow_driver_ops *fops;
7453 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7454 fops->free_meter(dev, mtr_idx);
7458 * Allocate a counter.
7461 * Pointer to Ethernet device structure.
7464 * Index to allocated counter on success, 0 otherwise.
7467 mlx5_counter_alloc(struct rte_eth_dev *dev)
7469 const struct mlx5_flow_driver_ops *fops;
7470 struct rte_flow_attr attr = { .transfer = 0 };
7472 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
7473 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7474 return fops->counter_alloc(dev);
7477 "port %u counter allocate is not supported.",
7478 dev->data->port_id);
7486 * Pointer to Ethernet device structure.
7488 * Index to counter to be free.
7491 mlx5_counter_free(struct rte_eth_dev *dev, uint32_t cnt)
7493 const struct mlx5_flow_driver_ops *fops;
7494 struct rte_flow_attr attr = { .transfer = 0 };
7496 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
7497 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7498 fops->counter_free(dev, cnt);
7502 "port %u counter free is not supported.",
7503 dev->data->port_id);
7507 * Query counter statistics.
7510 * Pointer to Ethernet device structure.
7512 * Index to counter to query.
7514 * Set to clear counter statistics.
7516 * The counter hits packets number to save.
7518 * The counter hits bytes number to save.
7521 * 0 on success, a negative errno value otherwise.
7524 mlx5_counter_query(struct rte_eth_dev *dev, uint32_t cnt,
7525 bool clear, uint64_t *pkts, uint64_t *bytes)
7527 const struct mlx5_flow_driver_ops *fops;
7528 struct rte_flow_attr attr = { .transfer = 0 };
7530 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
7531 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7532 return fops->counter_query(dev, cnt, clear, pkts, bytes);
7535 "port %u counter query is not supported.",
7536 dev->data->port_id);
7541 * Allocate a new memory for the counter values wrapped by all the needed
7545 * Pointer to mlx5_dev_ctx_shared object.
7548 * 0 on success, a negative errno value otherwise.
7551 mlx5_flow_create_counter_stat_mem_mng(struct mlx5_dev_ctx_shared *sh)
7553 struct mlx5_devx_mkey_attr mkey_attr;
7554 struct mlx5_counter_stats_mem_mng *mem_mng;
7555 volatile struct flow_counter_stats *raw_data;
7556 int raws_n = MLX5_CNT_CONTAINER_RESIZE + MLX5_MAX_PENDING_QUERIES;
7557 int size = (sizeof(struct flow_counter_stats) *
7558 MLX5_COUNTERS_PER_POOL +
7559 sizeof(struct mlx5_counter_stats_raw)) * raws_n +
7560 sizeof(struct mlx5_counter_stats_mem_mng);
7561 size_t pgsize = rte_mem_page_size();
7565 if (pgsize == (size_t)-1) {
7566 DRV_LOG(ERR, "Failed to get mem page size");
7570 mem = mlx5_malloc(MLX5_MEM_ZERO, size, pgsize, SOCKET_ID_ANY);
7575 mem_mng = (struct mlx5_counter_stats_mem_mng *)(mem + size) - 1;
7576 size = sizeof(*raw_data) * MLX5_COUNTERS_PER_POOL * raws_n;
7577 mem_mng->umem = mlx5_os_umem_reg(sh->ctx, mem, size,
7578 IBV_ACCESS_LOCAL_WRITE);
7579 if (!mem_mng->umem) {
7584 memset(&mkey_attr, 0, sizeof(mkey_attr));
7585 mkey_attr.addr = (uintptr_t)mem;
7586 mkey_attr.size = size;
7587 mkey_attr.umem_id = mlx5_os_get_umem_id(mem_mng->umem);
7588 mkey_attr.pd = sh->pdn;
7589 mkey_attr.relaxed_ordering_write = sh->cmng.relaxed_ordering_write;
7590 mkey_attr.relaxed_ordering_read = sh->cmng.relaxed_ordering_read;
7591 mem_mng->dm = mlx5_devx_cmd_mkey_create(sh->ctx, &mkey_attr);
7593 mlx5_os_umem_dereg(mem_mng->umem);
7598 mem_mng->raws = (struct mlx5_counter_stats_raw *)(mem + size);
7599 raw_data = (volatile struct flow_counter_stats *)mem;
7600 for (i = 0; i < raws_n; ++i) {
7601 mem_mng->raws[i].mem_mng = mem_mng;
7602 mem_mng->raws[i].data = raw_data + i * MLX5_COUNTERS_PER_POOL;
7604 for (i = 0; i < MLX5_MAX_PENDING_QUERIES; ++i)
7605 LIST_INSERT_HEAD(&sh->cmng.free_stat_raws,
7606 mem_mng->raws + MLX5_CNT_CONTAINER_RESIZE + i,
7608 LIST_INSERT_HEAD(&sh->cmng.mem_mngs, mem_mng, next);
7609 sh->cmng.mem_mng = mem_mng;
7614 * Set the statistic memory to the new counter pool.
7617 * Pointer to mlx5_dev_ctx_shared object.
7619 * Pointer to the pool to set the statistic memory.
7622 * 0 on success, a negative errno value otherwise.
7625 mlx5_flow_set_counter_stat_mem(struct mlx5_dev_ctx_shared *sh,
7626 struct mlx5_flow_counter_pool *pool)
7628 struct mlx5_flow_counter_mng *cmng = &sh->cmng;
7629 /* Resize statistic memory once used out. */
7630 if (!(pool->index % MLX5_CNT_CONTAINER_RESIZE) &&
7631 mlx5_flow_create_counter_stat_mem_mng(sh)) {
7632 DRV_LOG(ERR, "Cannot resize counter stat mem.");
7635 rte_spinlock_lock(&pool->sl);
7636 pool->raw = cmng->mem_mng->raws + pool->index %
7637 MLX5_CNT_CONTAINER_RESIZE;
7638 rte_spinlock_unlock(&pool->sl);
7639 pool->raw_hw = NULL;
7643 #define MLX5_POOL_QUERY_FREQ_US 1000000
7646 * Set the periodic procedure for triggering asynchronous batch queries for all
7647 * the counter pools.
7650 * Pointer to mlx5_dev_ctx_shared object.
7653 mlx5_set_query_alarm(struct mlx5_dev_ctx_shared *sh)
7655 uint32_t pools_n, us;
7657 pools_n = __atomic_load_n(&sh->cmng.n_valid, __ATOMIC_RELAXED);
7658 us = MLX5_POOL_QUERY_FREQ_US / pools_n;
7659 DRV_LOG(DEBUG, "Set alarm for %u pools each %u us", pools_n, us);
7660 if (rte_eal_alarm_set(us, mlx5_flow_query_alarm, sh)) {
7661 sh->cmng.query_thread_on = 0;
7662 DRV_LOG(ERR, "Cannot reinitialize query alarm");
7664 sh->cmng.query_thread_on = 1;
7669 * The periodic procedure for triggering asynchronous batch queries for all the
7670 * counter pools. This function is probably called by the host thread.
7673 * The parameter for the alarm process.
7676 mlx5_flow_query_alarm(void *arg)
7678 struct mlx5_dev_ctx_shared *sh = arg;
7680 uint16_t pool_index = sh->cmng.pool_index;
7681 struct mlx5_flow_counter_mng *cmng = &sh->cmng;
7682 struct mlx5_flow_counter_pool *pool;
7685 if (sh->cmng.pending_queries >= MLX5_MAX_PENDING_QUERIES)
7687 rte_spinlock_lock(&cmng->pool_update_sl);
7688 pool = cmng->pools[pool_index];
7689 n_valid = cmng->n_valid;
7690 rte_spinlock_unlock(&cmng->pool_update_sl);
7691 /* Set the statistic memory to the new created pool. */
7692 if ((!pool->raw && mlx5_flow_set_counter_stat_mem(sh, pool)))
7695 /* There is a pool query in progress. */
7698 LIST_FIRST(&sh->cmng.free_stat_raws);
7700 /* No free counter statistics raw memory. */
7703 * Identify the counters released between query trigger and query
7704 * handle more efficiently. The counter released in this gap period
7705 * should wait for a new round of query as the new arrived packets
7706 * will not be taken into account.
7709 ret = mlx5_devx_cmd_flow_counter_query(pool->min_dcs, 0,
7710 MLX5_COUNTERS_PER_POOL,
7712 pool->raw_hw->mem_mng->dm->id,
7716 (uint64_t)(uintptr_t)pool);
7718 DRV_LOG(ERR, "Failed to trigger asynchronous query for dcs ID"
7719 " %d", pool->min_dcs->id);
7720 pool->raw_hw = NULL;
7723 LIST_REMOVE(pool->raw_hw, next);
7724 sh->cmng.pending_queries++;
7726 if (pool_index >= n_valid)
7729 sh->cmng.pool_index = pool_index;
7730 mlx5_set_query_alarm(sh);
7734 * Check and callback event for new aged flow in the counter pool
7737 * Pointer to mlx5_dev_ctx_shared object.
7739 * Pointer to Current counter pool.
7742 mlx5_flow_aging_check(struct mlx5_dev_ctx_shared *sh,
7743 struct mlx5_flow_counter_pool *pool)
7745 struct mlx5_priv *priv;
7746 struct mlx5_flow_counter *cnt;
7747 struct mlx5_age_info *age_info;
7748 struct mlx5_age_param *age_param;
7749 struct mlx5_counter_stats_raw *cur = pool->raw_hw;
7750 struct mlx5_counter_stats_raw *prev = pool->raw;
7751 const uint64_t curr_time = MLX5_CURR_TIME_SEC;
7752 const uint32_t time_delta = curr_time - pool->time_of_last_age_check;
7753 uint16_t expected = AGE_CANDIDATE;
7756 pool->time_of_last_age_check = curr_time;
7757 for (i = 0; i < MLX5_COUNTERS_PER_POOL; ++i) {
7758 cnt = MLX5_POOL_GET_CNT(pool, i);
7759 age_param = MLX5_CNT_TO_AGE(cnt);
7760 if (__atomic_load_n(&age_param->state,
7761 __ATOMIC_RELAXED) != AGE_CANDIDATE)
7763 if (cur->data[i].hits != prev->data[i].hits) {
7764 __atomic_store_n(&age_param->sec_since_last_hit, 0,
7768 if (__atomic_add_fetch(&age_param->sec_since_last_hit,
7770 __ATOMIC_RELAXED) <= age_param->timeout)
7773 * Hold the lock first, or if between the
7774 * state AGE_TMOUT and tailq operation the
7775 * release happened, the release procedure
7776 * may delete a non-existent tailq node.
7778 priv = rte_eth_devices[age_param->port_id].data->dev_private;
7779 age_info = GET_PORT_AGE_INFO(priv);
7780 rte_spinlock_lock(&age_info->aged_sl);
7781 if (__atomic_compare_exchange_n(&age_param->state, &expected,
7784 __ATOMIC_RELAXED)) {
7785 TAILQ_INSERT_TAIL(&age_info->aged_counters, cnt, next);
7786 MLX5_AGE_SET(age_info, MLX5_AGE_EVENT_NEW);
7788 rte_spinlock_unlock(&age_info->aged_sl);
7790 mlx5_age_event_prepare(sh);
7794 * Handler for the HW respond about ready values from an asynchronous batch
7795 * query. This function is probably called by the host thread.
7798 * The pointer to the shared device context.
7799 * @param[in] async_id
7800 * The Devx async ID.
7802 * The status of the completion.
7805 mlx5_flow_async_pool_query_handle(struct mlx5_dev_ctx_shared *sh,
7806 uint64_t async_id, int status)
7808 struct mlx5_flow_counter_pool *pool =
7809 (struct mlx5_flow_counter_pool *)(uintptr_t)async_id;
7810 struct mlx5_counter_stats_raw *raw_to_free;
7811 uint8_t query_gen = pool->query_gen ^ 1;
7812 struct mlx5_flow_counter_mng *cmng = &sh->cmng;
7813 enum mlx5_counter_type cnt_type =
7814 pool->is_aged ? MLX5_COUNTER_TYPE_AGE :
7815 MLX5_COUNTER_TYPE_ORIGIN;
7817 if (unlikely(status)) {
7818 raw_to_free = pool->raw_hw;
7820 raw_to_free = pool->raw;
7822 mlx5_flow_aging_check(sh, pool);
7823 rte_spinlock_lock(&pool->sl);
7824 pool->raw = pool->raw_hw;
7825 rte_spinlock_unlock(&pool->sl);
7826 /* Be sure the new raw counters data is updated in memory. */
7828 if (!TAILQ_EMPTY(&pool->counters[query_gen])) {
7829 rte_spinlock_lock(&cmng->csl[cnt_type]);
7830 TAILQ_CONCAT(&cmng->counters[cnt_type],
7831 &pool->counters[query_gen], next);
7832 rte_spinlock_unlock(&cmng->csl[cnt_type]);
7835 LIST_INSERT_HEAD(&sh->cmng.free_stat_raws, raw_to_free, next);
7836 pool->raw_hw = NULL;
7837 sh->cmng.pending_queries--;
7841 flow_group_to_table(uint32_t port_id, uint32_t group, uint32_t *table,
7842 const struct flow_grp_info *grp_info,
7843 struct rte_flow_error *error)
7845 if (grp_info->transfer && grp_info->external &&
7846 grp_info->fdb_def_rule) {
7847 if (group == UINT32_MAX)
7848 return rte_flow_error_set
7850 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
7852 "group index not supported");
7857 DRV_LOG(DEBUG, "port %u group=%#x table=%#x", port_id, group, *table);
7862 * Translate the rte_flow group index to HW table value.
7864 * If tunnel offload is disabled, all group ids converted to flow table
7865 * id using the standard method.
7866 * If tunnel offload is enabled, group id can be converted using the
7867 * standard or tunnel conversion method. Group conversion method
7868 * selection depends on flags in `grp_info` parameter:
7869 * - Internal (grp_info.external == 0) groups conversion uses the
7871 * - Group ids in JUMP action converted with the tunnel conversion.
7872 * - Group id in rule attribute conversion depends on a rule type and
7874 * ** non zero group attributes converted with the tunnel method
7875 * ** zero group attribute in non-tunnel rule is converted using the
7876 * standard method - there's only one root table
7877 * ** zero group attribute in steer tunnel rule is converted with the
7878 * standard method - single root table
7879 * ** zero group attribute in match tunnel rule is a special OvS
7880 * case: that value is used for portability reasons. That group
7881 * id is converted with the tunnel conversion method.
7886 * PMD tunnel offload object
7888 * rte_flow group index value.
7891 * @param[in] grp_info
7892 * flags used for conversion
7894 * Pointer to error structure.
7897 * 0 on success, a negative errno value otherwise and rte_errno is set.
7900 mlx5_flow_group_to_table(struct rte_eth_dev *dev,
7901 const struct mlx5_flow_tunnel *tunnel,
7902 uint32_t group, uint32_t *table,
7903 const struct flow_grp_info *grp_info,
7904 struct rte_flow_error *error)
7907 bool standard_translation;
7909 if (!grp_info->skip_scale && grp_info->external &&
7910 group < MLX5_MAX_TABLES_EXTERNAL)
7911 group *= MLX5_FLOW_TABLE_FACTOR;
7912 if (is_tunnel_offload_active(dev)) {
7913 standard_translation = !grp_info->external ||
7914 grp_info->std_tbl_fix;
7916 standard_translation = true;
7919 "port %u group=%u transfer=%d external=%d fdb_def_rule=%d translate=%s",
7920 dev->data->port_id, group, grp_info->transfer,
7921 grp_info->external, grp_info->fdb_def_rule,
7922 standard_translation ? "STANDARD" : "TUNNEL");
7923 if (standard_translation)
7924 ret = flow_group_to_table(dev->data->port_id, group, table,
7927 ret = tunnel_flow_group_to_flow_table(dev, tunnel, group,
7934 * Discover availability of metadata reg_c's.
7936 * Iteratively use test flows to check availability.
7939 * Pointer to the Ethernet device structure.
7942 * 0 on success, a negative errno value otherwise and rte_errno is set.
7945 mlx5_flow_discover_mreg_c(struct rte_eth_dev *dev)
7947 struct mlx5_priv *priv = dev->data->dev_private;
7948 struct mlx5_dev_config *config = &priv->config;
7949 enum modify_reg idx;
7952 /* reg_c[0] and reg_c[1] are reserved. */
7953 config->flow_mreg_c[n++] = REG_C_0;
7954 config->flow_mreg_c[n++] = REG_C_1;
7955 /* Discover availability of other reg_c's. */
7956 for (idx = REG_C_2; idx <= REG_C_7; ++idx) {
7957 struct rte_flow_attr attr = {
7958 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
7959 .priority = MLX5_FLOW_LOWEST_PRIO_INDICATOR,
7962 struct rte_flow_item items[] = {
7964 .type = RTE_FLOW_ITEM_TYPE_END,
7967 struct rte_flow_action actions[] = {
7969 .type = (enum rte_flow_action_type)
7970 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
7971 .conf = &(struct mlx5_flow_action_copy_mreg){
7977 .type = RTE_FLOW_ACTION_TYPE_JUMP,
7978 .conf = &(struct rte_flow_action_jump){
7979 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
7983 .type = RTE_FLOW_ACTION_TYPE_END,
7987 struct rte_flow *flow;
7988 struct rte_flow_error error;
7990 if (!config->dv_flow_en)
7992 /* Create internal flow, validation skips copy action. */
7993 flow_idx = flow_list_create(dev, MLX5_FLOW_TYPE_GEN, &attr,
7994 items, actions, false, &error);
7995 flow = mlx5_ipool_get(priv->flows[MLX5_FLOW_TYPE_GEN],
7999 config->flow_mreg_c[n++] = idx;
8000 flow_list_destroy(dev, MLX5_FLOW_TYPE_GEN, flow_idx);
8002 for (; n < MLX5_MREG_C_NUM; ++n)
8003 config->flow_mreg_c[n] = REG_NON;
8008 save_dump_file(const uint8_t *data, uint32_t size,
8009 uint32_t type, uint32_t id, void *arg, FILE *file)
8011 char line[BUF_SIZE];
8014 uint32_t actions_num;
8015 struct rte_flow_query_count *count;
8017 memset(line, 0, BUF_SIZE);
8019 case DR_DUMP_REC_TYPE_PMD_MODIFY_HDR:
8020 actions_num = *(uint32_t *)(arg);
8021 out += snprintf(line + out, BUF_SIZE - out, "%d,0x%x,%d,",
8022 type, id, actions_num);
8024 case DR_DUMP_REC_TYPE_PMD_PKT_REFORMAT:
8025 out += snprintf(line + out, BUF_SIZE - out, "%d,0x%x,",
8028 case DR_DUMP_REC_TYPE_PMD_COUNTER:
8029 count = (struct rte_flow_query_count *)arg;
8030 fprintf(file, "%d,0x%x,%" PRIu64 ",%" PRIu64 "\n", type,
8031 id, count->hits, count->bytes);
8037 for (k = 0; k < size; k++) {
8038 /* Make sure we do not overrun the line buffer length. */
8039 if (out >= BUF_SIZE - 4) {
8043 out += snprintf(line + out, BUF_SIZE - out, "%02x",
8046 fprintf(file, "%s\n", line);
8051 mlx5_flow_query_counter(struct rte_eth_dev *dev, struct rte_flow *flow,
8052 struct rte_flow_query_count *count, struct rte_flow_error *error)
8054 struct rte_flow_action action[2];
8055 enum mlx5_flow_drv_type ftype;
8056 const struct mlx5_flow_driver_ops *fops;
8059 return rte_flow_error_set(error, ENOENT,
8060 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8062 "invalid flow handle");
8064 action[0].type = RTE_FLOW_ACTION_TYPE_COUNT;
8065 action[1].type = RTE_FLOW_ACTION_TYPE_END;
8066 if (flow->counter) {
8067 memset(count, 0, sizeof(struct rte_flow_query_count));
8068 ftype = (enum mlx5_flow_drv_type)(flow->drv_type);
8069 MLX5_ASSERT(ftype > MLX5_FLOW_TYPE_MIN &&
8070 ftype < MLX5_FLOW_TYPE_MAX);
8071 fops = flow_get_drv_ops(ftype);
8072 return fops->query(dev, flow, action, count, error);
8077 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
8079 * Dump flow ipool data to file
8082 * The pointer to Ethernet device.
8084 * A pointer to a file for output.
8086 * Perform verbose error reporting if not NULL. PMDs initialize this
8087 * structure in case of error only.
8089 * 0 on success, a negative value otherwise.
8092 mlx5_flow_dev_dump_ipool(struct rte_eth_dev *dev,
8093 struct rte_flow *flow, FILE *file,
8094 struct rte_flow_error *error)
8096 struct mlx5_priv *priv = dev->data->dev_private;
8097 struct mlx5_flow_dv_modify_hdr_resource *modify_hdr;
8098 struct mlx5_flow_dv_encap_decap_resource *encap_decap;
8099 uint32_t handle_idx;
8100 struct mlx5_flow_handle *dh;
8101 struct rte_flow_query_count count;
8102 uint32_t actions_num;
8103 const uint8_t *data;
8109 return rte_flow_error_set(error, ENOENT,
8110 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8112 "invalid flow handle");
8114 handle_idx = flow->dev_handles;
8115 while (handle_idx) {
8116 dh = mlx5_ipool_get(priv->sh->ipool
8117 [MLX5_IPOOL_MLX5_FLOW], handle_idx);
8120 handle_idx = dh->next.next;
8121 id = (uint32_t)(uintptr_t)dh->drv_flow;
8124 type = DR_DUMP_REC_TYPE_PMD_COUNTER;
8125 if (!mlx5_flow_query_counter(dev, flow, &count, error))
8126 save_dump_file(NULL, 0, type,
8127 id, (void *)&count, file);
8129 /* Get modify_hdr and encap_decap buf from ipools. */
8131 modify_hdr = dh->dvh.modify_hdr;
8133 if (dh->dvh.rix_encap_decap) {
8134 encap_decap = mlx5_ipool_get(priv->sh->ipool
8135 [MLX5_IPOOL_DECAP_ENCAP],
8136 dh->dvh.rix_encap_decap);
8139 data = (const uint8_t *)modify_hdr->actions;
8140 size = (size_t)(modify_hdr->actions_num) * 8;
8141 actions_num = modify_hdr->actions_num;
8142 type = DR_DUMP_REC_TYPE_PMD_MODIFY_HDR;
8143 save_dump_file(data, size, type, id,
8144 (void *)(&actions_num), file);
8147 data = encap_decap->buf;
8148 size = encap_decap->size;
8149 type = DR_DUMP_REC_TYPE_PMD_PKT_REFORMAT;
8150 save_dump_file(data, size, type,
8159 * Dump flow raw hw data to file
8162 * The pointer to Ethernet device.
8164 * A pointer to a file for output.
8166 * Perform verbose error reporting if not NULL. PMDs initialize this
8167 * structure in case of error only.
8169 * 0 on success, a nagative value otherwise.
8172 mlx5_flow_dev_dump(struct rte_eth_dev *dev, struct rte_flow *flow_idx,
8174 struct rte_flow_error *error __rte_unused)
8176 struct mlx5_priv *priv = dev->data->dev_private;
8177 struct mlx5_dev_ctx_shared *sh = priv->sh;
8178 uint32_t handle_idx;
8180 struct mlx5_flow_handle *dh;
8181 struct rte_flow *flow;
8182 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
8186 if (!priv->config.dv_flow_en) {
8187 if (fputs("device dv flow disabled\n", file) <= 0)
8194 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
8195 MLX5_IPOOL_FOREACH(priv->flows[MLX5_FLOW_TYPE_GEN], idx, flow)
8196 mlx5_flow_dev_dump_ipool(dev, flow, file, error);
8198 return mlx5_devx_cmd_flow_dump(sh->fdb_domain,
8200 sh->tx_domain, file);
8203 flow = mlx5_ipool_get(priv->flows[MLX5_FLOW_TYPE_GEN],
8204 (uintptr_t)(void *)flow_idx);
8208 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
8209 mlx5_flow_dev_dump_ipool(dev, flow, file, error);
8211 handle_idx = flow->dev_handles;
8212 while (handle_idx) {
8213 dh = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
8218 ret = mlx5_devx_cmd_flow_single_dump(dh->drv_flow,
8223 handle_idx = dh->next.next;
8229 * Get aged-out flows.
8232 * Pointer to the Ethernet device structure.
8233 * @param[in] context
8234 * The address of an array of pointers to the aged-out flows contexts.
8235 * @param[in] nb_countexts
8236 * The length of context array pointers.
8238 * Perform verbose error reporting if not NULL. Initialized in case of
8242 * how many contexts get in success, otherwise negative errno value.
8243 * if nb_contexts is 0, return the amount of all aged contexts.
8244 * if nb_contexts is not 0 , return the amount of aged flows reported
8245 * in the context array.
8248 mlx5_flow_get_aged_flows(struct rte_eth_dev *dev, void **contexts,
8249 uint32_t nb_contexts, struct rte_flow_error *error)
8251 const struct mlx5_flow_driver_ops *fops;
8252 struct rte_flow_attr attr = { .transfer = 0 };
8254 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
8255 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
8256 return fops->get_aged_flows(dev, contexts, nb_contexts,
8260 "port %u get aged flows is not supported.",
8261 dev->data->port_id);
8265 /* Wrapper for driver action_validate op callback */
8267 flow_drv_action_validate(struct rte_eth_dev *dev,
8268 const struct rte_flow_indir_action_conf *conf,
8269 const struct rte_flow_action *action,
8270 const struct mlx5_flow_driver_ops *fops,
8271 struct rte_flow_error *error)
8273 static const char err_msg[] = "indirect action validation unsupported";
8275 if (!fops->action_validate) {
8276 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
8277 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
8281 return fops->action_validate(dev, conf, action, error);
8285 * Destroys the shared action by handle.
8288 * Pointer to Ethernet device structure.
8290 * Handle for the indirect action object to be destroyed.
8292 * Perform verbose error reporting if not NULL. PMDs initialize this
8293 * structure in case of error only.
8296 * 0 on success, a negative errno value otherwise and rte_errno is set.
8298 * @note: wrapper for driver action_create op callback.
8301 mlx5_action_handle_destroy(struct rte_eth_dev *dev,
8302 struct rte_flow_action_handle *handle,
8303 struct rte_flow_error *error)
8305 static const char err_msg[] = "indirect action destruction unsupported";
8306 struct rte_flow_attr attr = { .transfer = 0 };
8307 const struct mlx5_flow_driver_ops *fops =
8308 flow_get_drv_ops(flow_get_drv_type(dev, &attr));
8310 if (!fops->action_destroy) {
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_destroy(dev, handle, error);
8319 /* Wrapper for driver action_destroy op callback */
8321 flow_drv_action_update(struct rte_eth_dev *dev,
8322 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 update unsupported";
8329 if (!fops->action_update) {
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_update(dev, handle, update, error);
8338 /* Wrapper for driver action_destroy op callback */
8340 flow_drv_action_query(struct rte_eth_dev *dev,
8341 const struct rte_flow_action_handle *handle,
8343 const struct mlx5_flow_driver_ops *fops,
8344 struct rte_flow_error *error)
8346 static const char err_msg[] = "indirect action query unsupported";
8348 if (!fops->action_query) {
8349 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
8350 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
8354 return fops->action_query(dev, handle, data, error);
8358 * Create indirect action for reuse in multiple flow rules.
8361 * Pointer to Ethernet device structure.
8363 * Pointer to indirect action object configuration.
8365 * Action configuration for indirect action object creation.
8367 * Perform verbose error reporting if not NULL. PMDs initialize this
8368 * structure in case of error only.
8370 * A valid handle in case of success, NULL otherwise and rte_errno is set.
8372 static struct rte_flow_action_handle *
8373 mlx5_action_handle_create(struct rte_eth_dev *dev,
8374 const struct rte_flow_indir_action_conf *conf,
8375 const struct rte_flow_action *action,
8376 struct rte_flow_error *error)
8378 static const char err_msg[] = "indirect action creation unsupported";
8379 struct rte_flow_attr attr = { .transfer = 0 };
8380 const struct mlx5_flow_driver_ops *fops =
8381 flow_get_drv_ops(flow_get_drv_type(dev, &attr));
8383 if (flow_drv_action_validate(dev, conf, action, fops, error))
8385 if (!fops->action_create) {
8386 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
8387 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
8391 return fops->action_create(dev, conf, action, error);
8395 * Updates inplace the indirect action configuration pointed by *handle*
8396 * with the configuration provided as *update* argument.
8397 * The update of the indirect action configuration effects all flow rules
8398 * reusing the action via handle.
8401 * Pointer to Ethernet device structure.
8403 * Handle for the indirect action to be updated.
8405 * Action specification used to modify the action pointed by handle.
8406 * *update* could be of same type with the action pointed by the *handle*
8407 * handle argument, or some other structures like a wrapper, depending on
8408 * the indirect action type.
8410 * Perform verbose error reporting if not NULL. PMDs initialize this
8411 * structure in case of error only.
8414 * 0 on success, a negative errno value otherwise and rte_errno is set.
8417 mlx5_action_handle_update(struct rte_eth_dev *dev,
8418 struct rte_flow_action_handle *handle,
8420 struct rte_flow_error *error)
8422 struct rte_flow_attr attr = { .transfer = 0 };
8423 const struct mlx5_flow_driver_ops *fops =
8424 flow_get_drv_ops(flow_get_drv_type(dev, &attr));
8427 ret = flow_drv_action_validate(dev, NULL,
8428 (const struct rte_flow_action *)update, fops, error);
8431 return flow_drv_action_update(dev, handle, update, fops,
8436 * Query the indirect action by handle.
8438 * This function allows retrieving action-specific data such as counters.
8439 * Data is gathered by special action which may be present/referenced in
8440 * more than one flow rule definition.
8442 * see @RTE_FLOW_ACTION_TYPE_COUNT
8445 * Pointer to Ethernet device structure.
8447 * Handle for the indirect action to query.
8448 * @param[in, out] data
8449 * Pointer to storage for the associated query data type.
8451 * Perform verbose error reporting if not NULL. PMDs initialize this
8452 * structure in case of error only.
8455 * 0 on success, a negative errno value otherwise and rte_errno is set.
8458 mlx5_action_handle_query(struct rte_eth_dev *dev,
8459 const struct rte_flow_action_handle *handle,
8461 struct rte_flow_error *error)
8463 struct rte_flow_attr attr = { .transfer = 0 };
8464 const struct mlx5_flow_driver_ops *fops =
8465 flow_get_drv_ops(flow_get_drv_type(dev, &attr));
8467 return flow_drv_action_query(dev, handle, data, fops, error);
8471 * Destroy all indirect actions (shared RSS).
8474 * Pointer to Ethernet device.
8477 * 0 on success, a negative errno value otherwise and rte_errno is set.
8480 mlx5_action_handle_flush(struct rte_eth_dev *dev)
8482 struct rte_flow_error error;
8483 struct mlx5_priv *priv = dev->data->dev_private;
8484 struct mlx5_shared_action_rss *shared_rss;
8488 ILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
8489 priv->rss_shared_actions, idx, shared_rss, next) {
8490 ret |= mlx5_action_handle_destroy(dev,
8491 (struct rte_flow_action_handle *)(uintptr_t)idx, &error);
8496 #ifndef HAVE_MLX5DV_DR
8497 #define MLX5_DOMAIN_SYNC_FLOW ((1 << 0) | (1 << 1))
8499 #define MLX5_DOMAIN_SYNC_FLOW \
8500 (MLX5DV_DR_DOMAIN_SYNC_FLAGS_SW | MLX5DV_DR_DOMAIN_SYNC_FLAGS_HW)
8503 int rte_pmd_mlx5_sync_flow(uint16_t port_id, uint32_t domains)
8505 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
8506 const struct mlx5_flow_driver_ops *fops;
8508 struct rte_flow_attr attr = { .transfer = 0 };
8510 fops = flow_get_drv_ops(flow_get_drv_type(dev, &attr));
8511 ret = fops->sync_domain(dev, domains, MLX5_DOMAIN_SYNC_FLOW);
8517 const struct mlx5_flow_tunnel *
8518 mlx5_get_tof(const struct rte_flow_item *item,
8519 const struct rte_flow_action *action,
8520 enum mlx5_tof_rule_type *rule_type)
8522 for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
8523 if (item->type == (typeof(item->type))
8524 MLX5_RTE_FLOW_ITEM_TYPE_TUNNEL) {
8525 *rule_type = MLX5_TUNNEL_OFFLOAD_MATCH_RULE;
8526 return flow_items_to_tunnel(item);
8529 for (; action->conf != RTE_FLOW_ACTION_TYPE_END; action++) {
8530 if (action->type == (typeof(action->type))
8531 MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET) {
8532 *rule_type = MLX5_TUNNEL_OFFLOAD_SET_RULE;
8533 return flow_actions_to_tunnel(action);
8540 * tunnel offload functionalilty is defined for DV environment only
8542 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
8544 union tunnel_offload_mark {
8547 uint32_t app_reserve:8;
8548 uint32_t table_id:15;
8549 uint32_t transfer:1;
8550 uint32_t _unused_:8;
8555 mlx5_access_tunnel_offload_db
8556 (struct rte_eth_dev *dev,
8557 bool (*match)(struct rte_eth_dev *,
8558 struct mlx5_flow_tunnel *, const void *),
8559 void (*hit)(struct rte_eth_dev *, struct mlx5_flow_tunnel *, void *),
8560 void (*miss)(struct rte_eth_dev *, void *),
8561 void *ctx, bool lock_op);
8564 flow_tunnel_add_default_miss(struct rte_eth_dev *dev,
8565 struct rte_flow *flow,
8566 const struct rte_flow_attr *attr,
8567 const struct rte_flow_action *app_actions,
8569 const struct mlx5_flow_tunnel *tunnel,
8570 struct tunnel_default_miss_ctx *ctx,
8571 struct rte_flow_error *error)
8573 struct mlx5_priv *priv = dev->data->dev_private;
8574 struct mlx5_flow *dev_flow;
8575 struct rte_flow_attr miss_attr = *attr;
8576 const struct rte_flow_item miss_items[2] = {
8578 .type = RTE_FLOW_ITEM_TYPE_ETH,
8584 .type = RTE_FLOW_ITEM_TYPE_END,
8590 union tunnel_offload_mark mark_id;
8591 struct rte_flow_action_mark miss_mark;
8592 struct rte_flow_action miss_actions[3] = {
8593 [0] = { .type = RTE_FLOW_ACTION_TYPE_MARK, .conf = &miss_mark },
8594 [2] = { .type = RTE_FLOW_ACTION_TYPE_END, .conf = NULL }
8596 const struct rte_flow_action_jump *jump_data;
8597 uint32_t i, flow_table = 0; /* prevent compilation warning */
8598 struct flow_grp_info grp_info = {
8600 .transfer = attr->transfer,
8601 .fdb_def_rule = !!priv->fdb_def_rule,
8606 if (!attr->transfer) {
8609 miss_actions[1].type = RTE_FLOW_ACTION_TYPE_RSS;
8610 q_size = priv->reta_idx_n * sizeof(ctx->queue[0]);
8611 ctx->queue = mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO, q_size,
8614 return rte_flow_error_set
8616 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
8617 NULL, "invalid default miss RSS");
8618 ctx->action_rss.func = RTE_ETH_HASH_FUNCTION_DEFAULT,
8619 ctx->action_rss.level = 0,
8620 ctx->action_rss.types = priv->rss_conf.rss_hf,
8621 ctx->action_rss.key_len = priv->rss_conf.rss_key_len,
8622 ctx->action_rss.queue_num = priv->reta_idx_n,
8623 ctx->action_rss.key = priv->rss_conf.rss_key,
8624 ctx->action_rss.queue = ctx->queue;
8625 if (!priv->reta_idx_n || !priv->rxqs_n)
8626 return rte_flow_error_set
8628 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
8629 NULL, "invalid port configuration");
8630 if (!(dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG))
8631 ctx->action_rss.types = 0;
8632 for (i = 0; i != priv->reta_idx_n; ++i)
8633 ctx->queue[i] = (*priv->reta_idx)[i];
8635 miss_actions[1].type = RTE_FLOW_ACTION_TYPE_JUMP;
8636 ctx->miss_jump.group = MLX5_TNL_MISS_FDB_JUMP_GRP;
8638 miss_actions[1].conf = (typeof(miss_actions[1].conf))ctx->raw;
8639 for (; app_actions->type != RTE_FLOW_ACTION_TYPE_JUMP; app_actions++);
8640 jump_data = app_actions->conf;
8641 miss_attr.priority = MLX5_TNL_MISS_RULE_PRIORITY;
8642 miss_attr.group = jump_data->group;
8643 ret = mlx5_flow_group_to_table(dev, tunnel, jump_data->group,
8644 &flow_table, &grp_info, error);
8646 return rte_flow_error_set(error, EINVAL,
8647 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
8648 NULL, "invalid tunnel id");
8649 mark_id.app_reserve = 0;
8650 mark_id.table_id = tunnel_flow_tbl_to_id(flow_table);
8651 mark_id.transfer = !!attr->transfer;
8652 mark_id._unused_ = 0;
8653 miss_mark.id = mark_id.val;
8654 dev_flow = flow_drv_prepare(dev, flow, &miss_attr,
8655 miss_items, miss_actions, flow_idx, error);
8658 dev_flow->flow = flow;
8659 dev_flow->external = true;
8660 dev_flow->tunnel = tunnel;
8661 dev_flow->tof_type = MLX5_TUNNEL_OFFLOAD_MISS_RULE;
8662 /* Subflow object was created, we must include one in the list. */
8663 SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
8664 dev_flow->handle, next);
8666 "port %u tunnel type=%d id=%u miss rule priority=%u group=%u",
8667 dev->data->port_id, tunnel->app_tunnel.type,
8668 tunnel->tunnel_id, miss_attr.priority, miss_attr.group);
8669 ret = flow_drv_translate(dev, dev_flow, &miss_attr, miss_items,
8670 miss_actions, error);
8672 ret = flow_mreg_update_copy_table(dev, flow, miss_actions,
8678 static const struct mlx5_flow_tbl_data_entry *
8679 tunnel_mark_decode(struct rte_eth_dev *dev, uint32_t mark)
8681 struct mlx5_priv *priv = dev->data->dev_private;
8682 struct mlx5_dev_ctx_shared *sh = priv->sh;
8683 struct mlx5_list_entry *he;
8684 union tunnel_offload_mark mbits = { .val = mark };
8685 union mlx5_flow_tbl_key table_key = {
8687 .level = tunnel_id_to_flow_tbl(mbits.table_id),
8691 .is_fdb = !!mbits.transfer,
8695 struct mlx5_flow_cb_ctx ctx = {
8696 .data = &table_key.v64,
8699 he = mlx5_hlist_lookup(sh->flow_tbls, table_key.v64, &ctx);
8701 container_of(he, struct mlx5_flow_tbl_data_entry, entry) : NULL;
8705 mlx5_flow_tunnel_grp2tbl_remove_cb(void *tool_ctx,
8706 struct mlx5_list_entry *entry)
8708 struct mlx5_dev_ctx_shared *sh = tool_ctx;
8709 struct tunnel_tbl_entry *tte = container_of(entry, typeof(*tte), hash);
8711 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TNL_TBL_ID],
8712 tunnel_flow_tbl_to_id(tte->flow_table));
8717 mlx5_flow_tunnel_grp2tbl_match_cb(void *tool_ctx __rte_unused,
8718 struct mlx5_list_entry *entry, void *cb_ctx)
8720 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
8721 union tunnel_tbl_key tbl = {
8722 .val = *(uint64_t *)(ctx->data),
8724 struct tunnel_tbl_entry *tte = container_of(entry, typeof(*tte), hash);
8726 return tbl.tunnel_id != tte->tunnel_id || tbl.group != tte->group;
8729 static struct mlx5_list_entry *
8730 mlx5_flow_tunnel_grp2tbl_create_cb(void *tool_ctx, void *cb_ctx)
8732 struct mlx5_dev_ctx_shared *sh = tool_ctx;
8733 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
8734 struct tunnel_tbl_entry *tte;
8735 union tunnel_tbl_key tbl = {
8736 .val = *(uint64_t *)(ctx->data),
8739 tte = mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO,
8744 mlx5_ipool_malloc(sh->ipool[MLX5_IPOOL_TNL_TBL_ID],
8746 if (tte->flow_table >= MLX5_MAX_TABLES) {
8747 DRV_LOG(ERR, "Tunnel TBL ID %d exceed max limit.",
8749 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TNL_TBL_ID],
8752 } else if (!tte->flow_table) {
8755 tte->flow_table = tunnel_id_to_flow_tbl(tte->flow_table);
8756 tte->tunnel_id = tbl.tunnel_id;
8757 tte->group = tbl.group;
8765 static struct mlx5_list_entry *
8766 mlx5_flow_tunnel_grp2tbl_clone_cb(void *tool_ctx __rte_unused,
8767 struct mlx5_list_entry *oentry,
8768 void *cb_ctx __rte_unused)
8770 struct tunnel_tbl_entry *tte = mlx5_malloc(MLX5_MEM_SYS, sizeof(*tte),
8775 memcpy(tte, oentry, sizeof(*tte));
8780 mlx5_flow_tunnel_grp2tbl_clone_free_cb(void *tool_ctx __rte_unused,
8781 struct mlx5_list_entry *entry)
8783 struct tunnel_tbl_entry *tte = container_of(entry, typeof(*tte), hash);
8789 tunnel_flow_group_to_flow_table(struct rte_eth_dev *dev,
8790 const struct mlx5_flow_tunnel *tunnel,
8791 uint32_t group, uint32_t *table,
8792 struct rte_flow_error *error)
8794 struct mlx5_list_entry *he;
8795 struct tunnel_tbl_entry *tte;
8796 union tunnel_tbl_key key = {
8797 .tunnel_id = tunnel ? tunnel->tunnel_id : 0,
8800 struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
8801 struct mlx5_hlist *group_hash;
8802 struct mlx5_flow_cb_ctx ctx = {
8806 group_hash = tunnel ? tunnel->groups : thub->groups;
8807 he = mlx5_hlist_register(group_hash, key.val, &ctx);
8809 return rte_flow_error_set(error, EINVAL,
8810 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
8812 "tunnel group index not supported");
8813 tte = container_of(he, typeof(*tte), hash);
8814 *table = tte->flow_table;
8815 DRV_LOG(DEBUG, "port %u tunnel %u group=%#x table=%#x",
8816 dev->data->port_id, key.tunnel_id, group, *table);
8821 mlx5_flow_tunnel_free(struct rte_eth_dev *dev,
8822 struct mlx5_flow_tunnel *tunnel)
8824 struct mlx5_priv *priv = dev->data->dev_private;
8825 struct mlx5_indexed_pool *ipool;
8827 DRV_LOG(DEBUG, "port %u release pmd tunnel id=0x%x",
8828 dev->data->port_id, tunnel->tunnel_id);
8829 LIST_REMOVE(tunnel, chain);
8830 mlx5_hlist_destroy(tunnel->groups);
8831 ipool = priv->sh->ipool[MLX5_IPOOL_TUNNEL_ID];
8832 mlx5_ipool_free(ipool, tunnel->tunnel_id);
8836 mlx5_access_tunnel_offload_db
8837 (struct rte_eth_dev *dev,
8838 bool (*match)(struct rte_eth_dev *,
8839 struct mlx5_flow_tunnel *, const void *),
8840 void (*hit)(struct rte_eth_dev *, struct mlx5_flow_tunnel *, void *),
8841 void (*miss)(struct rte_eth_dev *, void *),
8842 void *ctx, bool lock_op)
8844 bool verdict = false;
8845 struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
8846 struct mlx5_flow_tunnel *tunnel;
8848 rte_spinlock_lock(&thub->sl);
8849 LIST_FOREACH(tunnel, &thub->tunnels, chain) {
8850 verdict = match(dev, tunnel, (const void *)ctx);
8855 rte_spinlock_unlock(&thub->sl);
8857 hit(dev, tunnel, ctx);
8858 if (!verdict && miss)
8861 rte_spinlock_unlock(&thub->sl);
8866 struct tunnel_db_find_tunnel_id_ctx {
8868 struct mlx5_flow_tunnel *tunnel;
8872 find_tunnel_id_match(struct rte_eth_dev *dev,
8873 struct mlx5_flow_tunnel *tunnel, const void *x)
8875 const struct tunnel_db_find_tunnel_id_ctx *ctx = x;
8878 return tunnel->tunnel_id == ctx->tunnel_id;
8882 find_tunnel_id_hit(struct rte_eth_dev *dev,
8883 struct mlx5_flow_tunnel *tunnel, void *x)
8885 struct tunnel_db_find_tunnel_id_ctx *ctx = x;
8887 ctx->tunnel = tunnel;
8890 static struct mlx5_flow_tunnel *
8891 mlx5_find_tunnel_id(struct rte_eth_dev *dev, uint32_t id)
8893 struct tunnel_db_find_tunnel_id_ctx ctx = {
8897 mlx5_access_tunnel_offload_db(dev, find_tunnel_id_match,
8898 find_tunnel_id_hit, NULL, &ctx, true);
8903 static struct mlx5_flow_tunnel *
8904 mlx5_flow_tunnel_allocate(struct rte_eth_dev *dev,
8905 const struct rte_flow_tunnel *app_tunnel)
8907 struct mlx5_priv *priv = dev->data->dev_private;
8908 struct mlx5_indexed_pool *ipool;
8909 struct mlx5_flow_tunnel *tunnel;
8912 ipool = priv->sh->ipool[MLX5_IPOOL_TUNNEL_ID];
8913 tunnel = mlx5_ipool_zmalloc(ipool, &id);
8916 if (id >= MLX5_MAX_TUNNELS) {
8917 mlx5_ipool_free(ipool, id);
8918 DRV_LOG(ERR, "Tunnel ID %d exceed max limit.", id);
8921 tunnel->groups = mlx5_hlist_create("tunnel groups", 64, false, true,
8923 mlx5_flow_tunnel_grp2tbl_create_cb,
8924 mlx5_flow_tunnel_grp2tbl_match_cb,
8925 mlx5_flow_tunnel_grp2tbl_remove_cb,
8926 mlx5_flow_tunnel_grp2tbl_clone_cb,
8927 mlx5_flow_tunnel_grp2tbl_clone_free_cb);
8928 if (!tunnel->groups) {
8929 mlx5_ipool_free(ipool, id);
8932 /* initiate new PMD tunnel */
8933 memcpy(&tunnel->app_tunnel, app_tunnel, sizeof(*app_tunnel));
8934 tunnel->tunnel_id = id;
8935 tunnel->action.type = (typeof(tunnel->action.type))
8936 MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET;
8937 tunnel->action.conf = tunnel;
8938 tunnel->item.type = (typeof(tunnel->item.type))
8939 MLX5_RTE_FLOW_ITEM_TYPE_TUNNEL;
8940 tunnel->item.spec = tunnel;
8941 tunnel->item.last = NULL;
8942 tunnel->item.mask = NULL;
8944 DRV_LOG(DEBUG, "port %u new pmd tunnel id=0x%x",
8945 dev->data->port_id, tunnel->tunnel_id);
8950 struct tunnel_db_get_tunnel_ctx {
8951 const struct rte_flow_tunnel *app_tunnel;
8952 struct mlx5_flow_tunnel *tunnel;
8955 static bool get_tunnel_match(struct rte_eth_dev *dev,
8956 struct mlx5_flow_tunnel *tunnel, const void *x)
8958 const struct tunnel_db_get_tunnel_ctx *ctx = x;
8961 return !memcmp(ctx->app_tunnel, &tunnel->app_tunnel,
8962 sizeof(*ctx->app_tunnel));
8965 static void get_tunnel_hit(struct rte_eth_dev *dev,
8966 struct mlx5_flow_tunnel *tunnel, void *x)
8968 /* called under tunnel spinlock protection */
8969 struct tunnel_db_get_tunnel_ctx *ctx = x;
8973 ctx->tunnel = tunnel;
8976 static void get_tunnel_miss(struct rte_eth_dev *dev, void *x)
8978 /* called under tunnel spinlock protection */
8979 struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
8980 struct tunnel_db_get_tunnel_ctx *ctx = x;
8982 rte_spinlock_unlock(&thub->sl);
8983 ctx->tunnel = mlx5_flow_tunnel_allocate(dev, ctx->app_tunnel);
8984 rte_spinlock_lock(&thub->sl);
8986 ctx->tunnel->refctn = 1;
8987 LIST_INSERT_HEAD(&thub->tunnels, ctx->tunnel, chain);
8993 mlx5_get_flow_tunnel(struct rte_eth_dev *dev,
8994 const struct rte_flow_tunnel *app_tunnel,
8995 struct mlx5_flow_tunnel **tunnel)
8997 struct tunnel_db_get_tunnel_ctx ctx = {
8998 .app_tunnel = app_tunnel,
9001 mlx5_access_tunnel_offload_db(dev, get_tunnel_match, get_tunnel_hit,
9002 get_tunnel_miss, &ctx, true);
9003 *tunnel = ctx.tunnel;
9004 return ctx.tunnel ? 0 : -ENOMEM;
9007 void mlx5_release_tunnel_hub(struct mlx5_dev_ctx_shared *sh, uint16_t port_id)
9009 struct mlx5_flow_tunnel_hub *thub = sh->tunnel_hub;
9013 if (!LIST_EMPTY(&thub->tunnels))
9014 DRV_LOG(WARNING, "port %u tunnels present", port_id);
9015 mlx5_hlist_destroy(thub->groups);
9019 int mlx5_alloc_tunnel_hub(struct mlx5_dev_ctx_shared *sh)
9022 struct mlx5_flow_tunnel_hub *thub;
9024 thub = mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO, sizeof(*thub),
9028 LIST_INIT(&thub->tunnels);
9029 rte_spinlock_init(&thub->sl);
9030 thub->groups = mlx5_hlist_create("flow groups", 64,
9032 mlx5_flow_tunnel_grp2tbl_create_cb,
9033 mlx5_flow_tunnel_grp2tbl_match_cb,
9034 mlx5_flow_tunnel_grp2tbl_remove_cb,
9035 mlx5_flow_tunnel_grp2tbl_clone_cb,
9036 mlx5_flow_tunnel_grp2tbl_clone_free_cb);
9037 if (!thub->groups) {
9041 sh->tunnel_hub = thub;
9047 mlx5_hlist_destroy(thub->groups);
9054 mlx5_flow_tunnel_validate(struct rte_eth_dev *dev,
9055 struct rte_flow_tunnel *tunnel,
9056 const char *err_msg)
9059 if (!is_tunnel_offload_active(dev)) {
9060 err_msg = "tunnel offload was not activated";
9062 } else if (!tunnel) {
9063 err_msg = "no application tunnel";
9067 switch (tunnel->type) {
9069 err_msg = "unsupported tunnel type";
9071 case RTE_FLOW_ITEM_TYPE_VXLAN:
9080 mlx5_flow_tunnel_decap_set(struct rte_eth_dev *dev,
9081 struct rte_flow_tunnel *app_tunnel,
9082 struct rte_flow_action **actions,
9083 uint32_t *num_of_actions,
9084 struct rte_flow_error *error)
9087 struct mlx5_flow_tunnel *tunnel;
9088 const char *err_msg = NULL;
9089 bool verdict = mlx5_flow_tunnel_validate(dev, app_tunnel, err_msg);
9092 return rte_flow_error_set(error, EINVAL,
9093 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
9095 ret = mlx5_get_flow_tunnel(dev, app_tunnel, &tunnel);
9097 return rte_flow_error_set(error, ret,
9098 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
9099 "failed to initialize pmd tunnel");
9101 *actions = &tunnel->action;
9102 *num_of_actions = 1;
9107 mlx5_flow_tunnel_match(struct rte_eth_dev *dev,
9108 struct rte_flow_tunnel *app_tunnel,
9109 struct rte_flow_item **items,
9110 uint32_t *num_of_items,
9111 struct rte_flow_error *error)
9114 struct mlx5_flow_tunnel *tunnel;
9115 const char *err_msg = NULL;
9116 bool verdict = mlx5_flow_tunnel_validate(dev, app_tunnel, err_msg);
9119 return rte_flow_error_set(error, EINVAL,
9120 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
9122 ret = mlx5_get_flow_tunnel(dev, app_tunnel, &tunnel);
9124 return rte_flow_error_set(error, ret,
9125 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
9126 "failed to initialize pmd tunnel");
9128 *items = &tunnel->item;
9133 struct tunnel_db_element_release_ctx {
9134 struct rte_flow_item *items;
9135 struct rte_flow_action *actions;
9136 uint32_t num_elements;
9137 struct rte_flow_error *error;
9142 tunnel_element_release_match(struct rte_eth_dev *dev,
9143 struct mlx5_flow_tunnel *tunnel, const void *x)
9145 const struct tunnel_db_element_release_ctx *ctx = x;
9148 if (ctx->num_elements != 1)
9150 else if (ctx->items)
9151 return ctx->items == &tunnel->item;
9152 else if (ctx->actions)
9153 return ctx->actions == &tunnel->action;
9159 tunnel_element_release_hit(struct rte_eth_dev *dev,
9160 struct mlx5_flow_tunnel *tunnel, void *x)
9162 struct tunnel_db_element_release_ctx *ctx = x;
9164 if (!__atomic_sub_fetch(&tunnel->refctn, 1, __ATOMIC_RELAXED))
9165 mlx5_flow_tunnel_free(dev, tunnel);
9169 tunnel_element_release_miss(struct rte_eth_dev *dev, void *x)
9171 struct tunnel_db_element_release_ctx *ctx = x;
9173 ctx->ret = rte_flow_error_set(ctx->error, EINVAL,
9174 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
9175 "invalid argument");
9179 mlx5_flow_tunnel_item_release(struct rte_eth_dev *dev,
9180 struct rte_flow_item *pmd_items,
9181 uint32_t num_items, struct rte_flow_error *err)
9183 struct tunnel_db_element_release_ctx ctx = {
9186 .num_elements = num_items,
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_action_release(struct rte_eth_dev *dev,
9199 struct rte_flow_action *pmd_actions,
9200 uint32_t num_actions, struct rte_flow_error *err)
9202 struct tunnel_db_element_release_ctx ctx = {
9204 .actions = pmd_actions,
9205 .num_elements = num_actions,
9209 mlx5_access_tunnel_offload_db(dev, tunnel_element_release_match,
9210 tunnel_element_release_hit,
9211 tunnel_element_release_miss, &ctx, false);
9217 mlx5_flow_tunnel_get_restore_info(struct rte_eth_dev *dev,
9219 struct rte_flow_restore_info *info,
9220 struct rte_flow_error *err)
9222 uint64_t ol_flags = m->ol_flags;
9223 const struct mlx5_flow_tbl_data_entry *tble;
9224 const uint64_t mask = PKT_RX_FDIR | PKT_RX_FDIR_ID;
9226 if (!is_tunnel_offload_active(dev)) {
9231 if ((ol_flags & mask) != mask)
9233 tble = tunnel_mark_decode(dev, m->hash.fdir.hi);
9235 DRV_LOG(DEBUG, "port %u invalid miss tunnel mark %#x",
9236 dev->data->port_id, m->hash.fdir.hi);
9239 MLX5_ASSERT(tble->tunnel);
9240 memcpy(&info->tunnel, &tble->tunnel->app_tunnel, sizeof(info->tunnel));
9241 info->group_id = tble->group_id;
9242 info->flags = RTE_FLOW_RESTORE_INFO_TUNNEL |
9243 RTE_FLOW_RESTORE_INFO_GROUP_ID |
9244 RTE_FLOW_RESTORE_INFO_ENCAPSULATED;
9249 return rte_flow_error_set(err, EINVAL,
9250 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
9251 "failed to get restore info");
9254 #else /* HAVE_IBV_FLOW_DV_SUPPORT */
9256 mlx5_flow_tunnel_decap_set(__rte_unused struct rte_eth_dev *dev,
9257 __rte_unused struct rte_flow_tunnel *app_tunnel,
9258 __rte_unused struct rte_flow_action **actions,
9259 __rte_unused uint32_t *num_of_actions,
9260 __rte_unused struct rte_flow_error *error)
9266 mlx5_flow_tunnel_match(__rte_unused struct rte_eth_dev *dev,
9267 __rte_unused struct rte_flow_tunnel *app_tunnel,
9268 __rte_unused struct rte_flow_item **items,
9269 __rte_unused uint32_t *num_of_items,
9270 __rte_unused struct rte_flow_error *error)
9276 mlx5_flow_tunnel_item_release(__rte_unused struct rte_eth_dev *dev,
9277 __rte_unused struct rte_flow_item *pmd_items,
9278 __rte_unused uint32_t num_items,
9279 __rte_unused struct rte_flow_error *err)
9285 mlx5_flow_tunnel_action_release(__rte_unused struct rte_eth_dev *dev,
9286 __rte_unused struct rte_flow_action *pmd_action,
9287 __rte_unused uint32_t num_actions,
9288 __rte_unused struct rte_flow_error *err)
9294 mlx5_flow_tunnel_get_restore_info(__rte_unused struct rte_eth_dev *dev,
9295 __rte_unused struct rte_mbuf *m,
9296 __rte_unused struct rte_flow_restore_info *i,
9297 __rte_unused struct rte_flow_error *err)
9303 flow_tunnel_add_default_miss(__rte_unused struct rte_eth_dev *dev,
9304 __rte_unused struct rte_flow *flow,
9305 __rte_unused const struct rte_flow_attr *attr,
9306 __rte_unused const struct rte_flow_action *actions,
9307 __rte_unused uint32_t flow_idx,
9308 __rte_unused const struct mlx5_flow_tunnel *tunnel,
9309 __rte_unused struct tunnel_default_miss_ctx *ctx,
9310 __rte_unused struct rte_flow_error *error)
9315 static struct mlx5_flow_tunnel *
9316 mlx5_find_tunnel_id(__rte_unused struct rte_eth_dev *dev,
9317 __rte_unused uint32_t id)
9323 mlx5_flow_tunnel_free(__rte_unused struct rte_eth_dev *dev,
9324 __rte_unused struct mlx5_flow_tunnel *tunnel)
9329 tunnel_flow_group_to_flow_table(__rte_unused struct rte_eth_dev *dev,
9330 __rte_unused const struct mlx5_flow_tunnel *t,
9331 __rte_unused uint32_t group,
9332 __rte_unused uint32_t *table,
9333 struct rte_flow_error *error)
9335 return rte_flow_error_set(error, ENOTSUP,
9336 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
9337 "tunnel offload requires DV support");
9341 mlx5_release_tunnel_hub(__rte_unused struct mlx5_dev_ctx_shared *sh,
9342 __rte_unused uint16_t port_id)
9345 #endif /* HAVE_IBV_FLOW_DV_SUPPORT */
9348 mlx5_dbg__print_pattern(const struct rte_flow_item *item)
9351 struct rte_flow_error error;
9353 for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
9355 ret = rte_flow_conv(RTE_FLOW_CONV_OP_ITEM_NAME_PTR, &item_name,
9357 (void *)(uintptr_t)item->type, &error);
9359 printf("%s ", item_name);
9361 printf("%d\n", (int)item->type);