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");
2003 mask = &rte_flow_item_eth_mask;
2004 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2005 (const uint8_t *)&nic_mask,
2006 sizeof(struct rte_flow_item_eth),
2007 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2012 * Validate VLAN item.
2015 * Item specification.
2016 * @param[in] item_flags
2017 * Bit-fields that holds the items detected until now.
2019 * Ethernet device flow is being created on.
2021 * Pointer to error structure.
2024 * 0 on success, a negative errno value otherwise and rte_errno is set.
2027 mlx5_flow_validate_item_vlan(const struct rte_flow_item *item,
2028 uint64_t item_flags,
2029 struct rte_eth_dev *dev,
2030 struct rte_flow_error *error)
2032 const struct rte_flow_item_vlan *spec = item->spec;
2033 const struct rte_flow_item_vlan *mask = item->mask;
2034 const struct rte_flow_item_vlan nic_mask = {
2035 .tci = RTE_BE16(UINT16_MAX),
2036 .inner_type = RTE_BE16(UINT16_MAX),
2038 uint16_t vlan_tag = 0;
2039 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2041 const uint64_t l34m = tunnel ? (MLX5_FLOW_LAYER_INNER_L3 |
2042 MLX5_FLOW_LAYER_INNER_L4) :
2043 (MLX5_FLOW_LAYER_OUTER_L3 |
2044 MLX5_FLOW_LAYER_OUTER_L4);
2045 const uint64_t vlanm = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
2046 MLX5_FLOW_LAYER_OUTER_VLAN;
2048 if (item_flags & vlanm)
2049 return rte_flow_error_set(error, EINVAL,
2050 RTE_FLOW_ERROR_TYPE_ITEM, item,
2051 "multiple VLAN layers not supported");
2052 else if ((item_flags & l34m) != 0)
2053 return rte_flow_error_set(error, EINVAL,
2054 RTE_FLOW_ERROR_TYPE_ITEM, item,
2055 "VLAN cannot follow L3/L4 layer");
2057 mask = &rte_flow_item_vlan_mask;
2058 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2059 (const uint8_t *)&nic_mask,
2060 sizeof(struct rte_flow_item_vlan),
2061 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2064 if (!tunnel && mask->tci != RTE_BE16(0x0fff)) {
2065 struct mlx5_priv *priv = dev->data->dev_private;
2067 if (priv->vmwa_context) {
2069 * Non-NULL context means we have a virtual machine
2070 * and SR-IOV enabled, we have to create VLAN interface
2071 * to make hypervisor to setup E-Switch vport
2072 * context correctly. We avoid creating the multiple
2073 * VLAN interfaces, so we cannot support VLAN tag mask.
2075 return rte_flow_error_set(error, EINVAL,
2076 RTE_FLOW_ERROR_TYPE_ITEM,
2078 "VLAN tag mask is not"
2079 " supported in virtual"
2084 vlan_tag = spec->tci;
2085 vlan_tag &= mask->tci;
2088 * From verbs perspective an empty VLAN is equivalent
2089 * to a packet without VLAN layer.
2092 return rte_flow_error_set(error, EINVAL,
2093 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
2095 "VLAN cannot be empty");
2100 * Validate IPV4 item.
2103 * Item specification.
2104 * @param[in] item_flags
2105 * Bit-fields that holds the items detected until now.
2106 * @param[in] last_item
2107 * Previous validated item in the pattern items.
2108 * @param[in] ether_type
2109 * Type in the ethernet layer header (including dot1q).
2110 * @param[in] acc_mask
2111 * Acceptable mask, if NULL default internal default mask
2112 * will be used to check whether item fields are supported.
2113 * @param[in] range_accepted
2114 * True if range of values is accepted for specific fields, false otherwise.
2116 * Pointer to error structure.
2119 * 0 on success, a negative errno value otherwise and rte_errno is set.
2122 mlx5_flow_validate_item_ipv4(const struct rte_flow_item *item,
2123 uint64_t item_flags,
2125 uint16_t ether_type,
2126 const struct rte_flow_item_ipv4 *acc_mask,
2127 bool range_accepted,
2128 struct rte_flow_error *error)
2130 const struct rte_flow_item_ipv4 *mask = item->mask;
2131 const struct rte_flow_item_ipv4 *spec = item->spec;
2132 const struct rte_flow_item_ipv4 nic_mask = {
2134 .src_addr = RTE_BE32(0xffffffff),
2135 .dst_addr = RTE_BE32(0xffffffff),
2136 .type_of_service = 0xff,
2137 .next_proto_id = 0xff,
2140 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2141 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2142 MLX5_FLOW_LAYER_OUTER_L3;
2143 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2144 MLX5_FLOW_LAYER_OUTER_L4;
2146 uint8_t next_proto = 0xFF;
2147 const uint64_t l2_vlan = (MLX5_FLOW_LAYER_L2 |
2148 MLX5_FLOW_LAYER_OUTER_VLAN |
2149 MLX5_FLOW_LAYER_INNER_VLAN);
2151 if ((last_item & l2_vlan) && ether_type &&
2152 ether_type != RTE_ETHER_TYPE_IPV4)
2153 return rte_flow_error_set(error, EINVAL,
2154 RTE_FLOW_ERROR_TYPE_ITEM, item,
2155 "IPv4 cannot follow L2/VLAN layer "
2156 "which ether type is not IPv4");
2157 if (item_flags & MLX5_FLOW_LAYER_TUNNEL) {
2159 next_proto = mask->hdr.next_proto_id &
2160 spec->hdr.next_proto_id;
2161 if (next_proto == IPPROTO_IPIP || next_proto == IPPROTO_IPV6)
2162 return rte_flow_error_set(error, EINVAL,
2163 RTE_FLOW_ERROR_TYPE_ITEM,
2168 if (item_flags & MLX5_FLOW_LAYER_IPV6_ENCAP)
2169 return rte_flow_error_set(error, EINVAL,
2170 RTE_FLOW_ERROR_TYPE_ITEM, item,
2171 "wrong tunnel type - IPv6 specified "
2172 "but IPv4 item provided");
2173 if (item_flags & l3m)
2174 return rte_flow_error_set(error, ENOTSUP,
2175 RTE_FLOW_ERROR_TYPE_ITEM, item,
2176 "multiple L3 layers not supported");
2177 else if (item_flags & l4m)
2178 return rte_flow_error_set(error, EINVAL,
2179 RTE_FLOW_ERROR_TYPE_ITEM, item,
2180 "L3 cannot follow an L4 layer.");
2181 else if ((item_flags & MLX5_FLOW_LAYER_NVGRE) &&
2182 !(item_flags & MLX5_FLOW_LAYER_INNER_L2))
2183 return rte_flow_error_set(error, EINVAL,
2184 RTE_FLOW_ERROR_TYPE_ITEM, item,
2185 "L3 cannot follow an NVGRE layer.");
2187 mask = &rte_flow_item_ipv4_mask;
2188 else if (mask->hdr.next_proto_id != 0 &&
2189 mask->hdr.next_proto_id != 0xff)
2190 return rte_flow_error_set(error, EINVAL,
2191 RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
2192 "partial mask is not supported"
2194 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2195 acc_mask ? (const uint8_t *)acc_mask
2196 : (const uint8_t *)&nic_mask,
2197 sizeof(struct rte_flow_item_ipv4),
2198 range_accepted, error);
2205 * Validate IPV6 item.
2208 * Item specification.
2209 * @param[in] item_flags
2210 * Bit-fields that holds the items detected until now.
2211 * @param[in] last_item
2212 * Previous validated item in the pattern items.
2213 * @param[in] ether_type
2214 * Type in the ethernet layer header (including dot1q).
2215 * @param[in] acc_mask
2216 * Acceptable mask, if NULL default internal default mask
2217 * will be used to check whether item fields are supported.
2219 * Pointer to error structure.
2222 * 0 on success, a negative errno value otherwise and rte_errno is set.
2225 mlx5_flow_validate_item_ipv6(const struct rte_flow_item *item,
2226 uint64_t item_flags,
2228 uint16_t ether_type,
2229 const struct rte_flow_item_ipv6 *acc_mask,
2230 struct rte_flow_error *error)
2232 const struct rte_flow_item_ipv6 *mask = item->mask;
2233 const struct rte_flow_item_ipv6 *spec = item->spec;
2234 const struct rte_flow_item_ipv6 nic_mask = {
2237 "\xff\xff\xff\xff\xff\xff\xff\xff"
2238 "\xff\xff\xff\xff\xff\xff\xff\xff",
2240 "\xff\xff\xff\xff\xff\xff\xff\xff"
2241 "\xff\xff\xff\xff\xff\xff\xff\xff",
2242 .vtc_flow = RTE_BE32(0xffffffff),
2246 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2247 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2248 MLX5_FLOW_LAYER_OUTER_L3;
2249 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2250 MLX5_FLOW_LAYER_OUTER_L4;
2252 uint8_t next_proto = 0xFF;
2253 const uint64_t l2_vlan = (MLX5_FLOW_LAYER_L2 |
2254 MLX5_FLOW_LAYER_OUTER_VLAN |
2255 MLX5_FLOW_LAYER_INNER_VLAN);
2257 if ((last_item & l2_vlan) && ether_type &&
2258 ether_type != RTE_ETHER_TYPE_IPV6)
2259 return rte_flow_error_set(error, EINVAL,
2260 RTE_FLOW_ERROR_TYPE_ITEM, item,
2261 "IPv6 cannot follow L2/VLAN layer "
2262 "which ether type is not IPv6");
2263 if (mask && mask->hdr.proto == UINT8_MAX && spec)
2264 next_proto = spec->hdr.proto;
2265 if (item_flags & MLX5_FLOW_LAYER_TUNNEL) {
2266 if (next_proto == IPPROTO_IPIP || next_proto == IPPROTO_IPV6)
2267 return rte_flow_error_set(error, EINVAL,
2268 RTE_FLOW_ERROR_TYPE_ITEM,
2273 if (next_proto == IPPROTO_HOPOPTS ||
2274 next_proto == IPPROTO_ROUTING ||
2275 next_proto == IPPROTO_FRAGMENT ||
2276 next_proto == IPPROTO_ESP ||
2277 next_proto == IPPROTO_AH ||
2278 next_proto == IPPROTO_DSTOPTS)
2279 return rte_flow_error_set(error, EINVAL,
2280 RTE_FLOW_ERROR_TYPE_ITEM, item,
2281 "IPv6 proto (next header) should "
2282 "not be set as extension header");
2283 if (item_flags & MLX5_FLOW_LAYER_IPIP)
2284 return rte_flow_error_set(error, EINVAL,
2285 RTE_FLOW_ERROR_TYPE_ITEM, item,
2286 "wrong tunnel type - IPv4 specified "
2287 "but IPv6 item provided");
2288 if (item_flags & l3m)
2289 return rte_flow_error_set(error, ENOTSUP,
2290 RTE_FLOW_ERROR_TYPE_ITEM, item,
2291 "multiple L3 layers not supported");
2292 else if (item_flags & l4m)
2293 return rte_flow_error_set(error, EINVAL,
2294 RTE_FLOW_ERROR_TYPE_ITEM, item,
2295 "L3 cannot follow an L4 layer.");
2296 else if ((item_flags & MLX5_FLOW_LAYER_NVGRE) &&
2297 !(item_flags & MLX5_FLOW_LAYER_INNER_L2))
2298 return rte_flow_error_set(error, EINVAL,
2299 RTE_FLOW_ERROR_TYPE_ITEM, item,
2300 "L3 cannot follow an NVGRE layer.");
2302 mask = &rte_flow_item_ipv6_mask;
2303 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2304 acc_mask ? (const uint8_t *)acc_mask
2305 : (const uint8_t *)&nic_mask,
2306 sizeof(struct rte_flow_item_ipv6),
2307 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2314 * Validate UDP item.
2317 * Item specification.
2318 * @param[in] item_flags
2319 * Bit-fields that holds the items detected until now.
2320 * @param[in] target_protocol
2321 * The next protocol in the previous item.
2322 * @param[in] flow_mask
2323 * mlx5 flow-specific (DV, verbs, etc.) supported header fields mask.
2325 * Pointer to error structure.
2328 * 0 on success, a negative errno value otherwise and rte_errno is set.
2331 mlx5_flow_validate_item_udp(const struct rte_flow_item *item,
2332 uint64_t item_flags,
2333 uint8_t target_protocol,
2334 struct rte_flow_error *error)
2336 const struct rte_flow_item_udp *mask = item->mask;
2337 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2338 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2339 MLX5_FLOW_LAYER_OUTER_L3;
2340 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2341 MLX5_FLOW_LAYER_OUTER_L4;
2344 if (target_protocol != 0xff && target_protocol != IPPROTO_UDP)
2345 return rte_flow_error_set(error, EINVAL,
2346 RTE_FLOW_ERROR_TYPE_ITEM, item,
2347 "protocol filtering not compatible"
2349 if (!(item_flags & l3m))
2350 return rte_flow_error_set(error, EINVAL,
2351 RTE_FLOW_ERROR_TYPE_ITEM, item,
2352 "L3 is mandatory to filter on L4");
2353 if (item_flags & l4m)
2354 return rte_flow_error_set(error, EINVAL,
2355 RTE_FLOW_ERROR_TYPE_ITEM, item,
2356 "multiple L4 layers not supported");
2358 mask = &rte_flow_item_udp_mask;
2359 ret = mlx5_flow_item_acceptable
2360 (item, (const uint8_t *)mask,
2361 (const uint8_t *)&rte_flow_item_udp_mask,
2362 sizeof(struct rte_flow_item_udp), MLX5_ITEM_RANGE_NOT_ACCEPTED,
2370 * Validate TCP item.
2373 * Item specification.
2374 * @param[in] item_flags
2375 * Bit-fields that holds the items detected until now.
2376 * @param[in] target_protocol
2377 * The next protocol in the previous item.
2379 * Pointer to error structure.
2382 * 0 on success, a negative errno value otherwise and rte_errno is set.
2385 mlx5_flow_validate_item_tcp(const struct rte_flow_item *item,
2386 uint64_t item_flags,
2387 uint8_t target_protocol,
2388 const struct rte_flow_item_tcp *flow_mask,
2389 struct rte_flow_error *error)
2391 const struct rte_flow_item_tcp *mask = item->mask;
2392 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2393 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2394 MLX5_FLOW_LAYER_OUTER_L3;
2395 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2396 MLX5_FLOW_LAYER_OUTER_L4;
2399 MLX5_ASSERT(flow_mask);
2400 if (target_protocol != 0xff && target_protocol != IPPROTO_TCP)
2401 return rte_flow_error_set(error, EINVAL,
2402 RTE_FLOW_ERROR_TYPE_ITEM, item,
2403 "protocol filtering not compatible"
2405 if (!(item_flags & l3m))
2406 return rte_flow_error_set(error, EINVAL,
2407 RTE_FLOW_ERROR_TYPE_ITEM, item,
2408 "L3 is mandatory to filter on L4");
2409 if (item_flags & l4m)
2410 return rte_flow_error_set(error, EINVAL,
2411 RTE_FLOW_ERROR_TYPE_ITEM, item,
2412 "multiple L4 layers not supported");
2414 mask = &rte_flow_item_tcp_mask;
2415 ret = mlx5_flow_item_acceptable
2416 (item, (const uint8_t *)mask,
2417 (const uint8_t *)flow_mask,
2418 sizeof(struct rte_flow_item_tcp), MLX5_ITEM_RANGE_NOT_ACCEPTED,
2426 * Validate VXLAN item.
2429 * Pointer to the Ethernet device structure.
2431 * Item specification.
2432 * @param[in] item_flags
2433 * Bit-fields that holds the items detected until now.
2435 * Flow rule attributes.
2437 * Pointer to error structure.
2440 * 0 on success, a negative errno value otherwise and rte_errno is set.
2443 mlx5_flow_validate_item_vxlan(struct rte_eth_dev *dev,
2444 const struct rte_flow_item *item,
2445 uint64_t item_flags,
2446 const struct rte_flow_attr *attr,
2447 struct rte_flow_error *error)
2449 const struct rte_flow_item_vxlan *spec = item->spec;
2450 const struct rte_flow_item_vxlan *mask = item->mask;
2452 struct mlx5_priv *priv = dev->data->dev_private;
2456 } id = { .vlan_id = 0, };
2457 const struct rte_flow_item_vxlan nic_mask = {
2458 .vni = "\xff\xff\xff",
2461 const struct rte_flow_item_vxlan *valid_mask;
2463 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2464 return rte_flow_error_set(error, ENOTSUP,
2465 RTE_FLOW_ERROR_TYPE_ITEM, item,
2466 "multiple tunnel layers not"
2468 valid_mask = &rte_flow_item_vxlan_mask;
2470 * Verify only UDPv4 is present as defined in
2471 * https://tools.ietf.org/html/rfc7348
2473 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2474 return rte_flow_error_set(error, EINVAL,
2475 RTE_FLOW_ERROR_TYPE_ITEM, item,
2476 "no outer UDP layer found");
2478 mask = &rte_flow_item_vxlan_mask;
2479 /* FDB domain & NIC domain non-zero group */
2480 if ((attr->transfer || attr->group) && priv->sh->misc5_cap)
2481 valid_mask = &nic_mask;
2482 /* Group zero in NIC domain */
2483 if (!attr->group && !attr->transfer && priv->sh->tunnel_header_0_1)
2484 valid_mask = &nic_mask;
2485 ret = mlx5_flow_item_acceptable
2486 (item, (const uint8_t *)mask,
2487 (const uint8_t *)valid_mask,
2488 sizeof(struct rte_flow_item_vxlan),
2489 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2493 memcpy(&id.vni[1], spec->vni, 3);
2494 memcpy(&id.vni[1], mask->vni, 3);
2496 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
2497 return rte_flow_error_set(error, ENOTSUP,
2498 RTE_FLOW_ERROR_TYPE_ITEM, item,
2499 "VXLAN tunnel must be fully defined");
2504 * Validate VXLAN_GPE item.
2507 * Item specification.
2508 * @param[in] item_flags
2509 * Bit-fields that holds the items detected until now.
2511 * Pointer to the private data structure.
2512 * @param[in] target_protocol
2513 * The next protocol in the previous item.
2515 * Pointer to error structure.
2518 * 0 on success, a negative errno value otherwise and rte_errno is set.
2521 mlx5_flow_validate_item_vxlan_gpe(const struct rte_flow_item *item,
2522 uint64_t item_flags,
2523 struct rte_eth_dev *dev,
2524 struct rte_flow_error *error)
2526 struct mlx5_priv *priv = dev->data->dev_private;
2527 const struct rte_flow_item_vxlan_gpe *spec = item->spec;
2528 const struct rte_flow_item_vxlan_gpe *mask = item->mask;
2533 } id = { .vlan_id = 0, };
2535 if (!priv->config.l3_vxlan_en)
2536 return rte_flow_error_set(error, ENOTSUP,
2537 RTE_FLOW_ERROR_TYPE_ITEM, item,
2538 "L3 VXLAN is not enabled by device"
2539 " parameter and/or not configured in"
2541 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2542 return rte_flow_error_set(error, ENOTSUP,
2543 RTE_FLOW_ERROR_TYPE_ITEM, item,
2544 "multiple tunnel layers not"
2547 * Verify only UDPv4 is present as defined in
2548 * https://tools.ietf.org/html/rfc7348
2550 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2551 return rte_flow_error_set(error, EINVAL,
2552 RTE_FLOW_ERROR_TYPE_ITEM, item,
2553 "no outer UDP layer found");
2555 mask = &rte_flow_item_vxlan_gpe_mask;
2556 ret = mlx5_flow_item_acceptable
2557 (item, (const uint8_t *)mask,
2558 (const uint8_t *)&rte_flow_item_vxlan_gpe_mask,
2559 sizeof(struct rte_flow_item_vxlan_gpe),
2560 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2565 return rte_flow_error_set(error, ENOTSUP,
2566 RTE_FLOW_ERROR_TYPE_ITEM,
2568 "VxLAN-GPE protocol"
2570 memcpy(&id.vni[1], spec->vni, 3);
2571 memcpy(&id.vni[1], mask->vni, 3);
2573 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
2574 return rte_flow_error_set(error, ENOTSUP,
2575 RTE_FLOW_ERROR_TYPE_ITEM, item,
2576 "VXLAN-GPE tunnel must be fully"
2581 * Validate GRE Key item.
2584 * Item specification.
2585 * @param[in] item_flags
2586 * Bit flags to mark detected items.
2587 * @param[in] gre_item
2588 * Pointer to gre_item
2590 * Pointer to error structure.
2593 * 0 on success, a negative errno value otherwise and rte_errno is set.
2596 mlx5_flow_validate_item_gre_key(const struct rte_flow_item *item,
2597 uint64_t item_flags,
2598 const struct rte_flow_item *gre_item,
2599 struct rte_flow_error *error)
2601 const rte_be32_t *mask = item->mask;
2603 rte_be32_t gre_key_default_mask = RTE_BE32(UINT32_MAX);
2604 const struct rte_flow_item_gre *gre_spec;
2605 const struct rte_flow_item_gre *gre_mask;
2607 if (item_flags & MLX5_FLOW_LAYER_GRE_KEY)
2608 return rte_flow_error_set(error, ENOTSUP,
2609 RTE_FLOW_ERROR_TYPE_ITEM, item,
2610 "Multiple GRE key not support");
2611 if (!(item_flags & MLX5_FLOW_LAYER_GRE))
2612 return rte_flow_error_set(error, ENOTSUP,
2613 RTE_FLOW_ERROR_TYPE_ITEM, item,
2614 "No preceding GRE header");
2615 if (item_flags & MLX5_FLOW_LAYER_INNER)
2616 return rte_flow_error_set(error, ENOTSUP,
2617 RTE_FLOW_ERROR_TYPE_ITEM, item,
2618 "GRE key following a wrong item");
2619 gre_mask = gre_item->mask;
2621 gre_mask = &rte_flow_item_gre_mask;
2622 gre_spec = gre_item->spec;
2623 if (gre_spec && (gre_mask->c_rsvd0_ver & RTE_BE16(0x2000)) &&
2624 !(gre_spec->c_rsvd0_ver & RTE_BE16(0x2000)))
2625 return rte_flow_error_set(error, EINVAL,
2626 RTE_FLOW_ERROR_TYPE_ITEM, item,
2627 "Key bit must be on");
2630 mask = &gre_key_default_mask;
2631 ret = mlx5_flow_item_acceptable
2632 (item, (const uint8_t *)mask,
2633 (const uint8_t *)&gre_key_default_mask,
2634 sizeof(rte_be32_t), MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2639 * Validate GRE item.
2642 * Item specification.
2643 * @param[in] item_flags
2644 * Bit flags to mark detected items.
2645 * @param[in] target_protocol
2646 * The next protocol in the previous item.
2648 * Pointer to error structure.
2651 * 0 on success, a negative errno value otherwise and rte_errno is set.
2654 mlx5_flow_validate_item_gre(const struct rte_flow_item *item,
2655 uint64_t item_flags,
2656 uint8_t target_protocol,
2657 struct rte_flow_error *error)
2659 const struct rte_flow_item_gre *spec __rte_unused = item->spec;
2660 const struct rte_flow_item_gre *mask = item->mask;
2662 const struct rte_flow_item_gre nic_mask = {
2663 .c_rsvd0_ver = RTE_BE16(0xB000),
2664 .protocol = RTE_BE16(UINT16_MAX),
2667 if (target_protocol != 0xff && target_protocol != IPPROTO_GRE)
2668 return rte_flow_error_set(error, EINVAL,
2669 RTE_FLOW_ERROR_TYPE_ITEM, item,
2670 "protocol filtering not compatible"
2671 " with this GRE layer");
2672 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2673 return rte_flow_error_set(error, ENOTSUP,
2674 RTE_FLOW_ERROR_TYPE_ITEM, item,
2675 "multiple tunnel layers not"
2677 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3))
2678 return rte_flow_error_set(error, ENOTSUP,
2679 RTE_FLOW_ERROR_TYPE_ITEM, item,
2680 "L3 Layer is missing");
2682 mask = &rte_flow_item_gre_mask;
2683 ret = mlx5_flow_item_acceptable
2684 (item, (const uint8_t *)mask,
2685 (const uint8_t *)&nic_mask,
2686 sizeof(struct rte_flow_item_gre), MLX5_ITEM_RANGE_NOT_ACCEPTED,
2690 #ifndef HAVE_MLX5DV_DR
2691 #ifndef HAVE_IBV_DEVICE_MPLS_SUPPORT
2692 if (spec && (spec->protocol & mask->protocol))
2693 return rte_flow_error_set(error, ENOTSUP,
2694 RTE_FLOW_ERROR_TYPE_ITEM, item,
2695 "without MPLS support the"
2696 " specification cannot be used for"
2704 * Validate Geneve item.
2707 * Item specification.
2708 * @param[in] itemFlags
2709 * Bit-fields that holds the items detected until now.
2711 * Pointer to the private data structure.
2713 * Pointer to error structure.
2716 * 0 on success, a negative errno value otherwise and rte_errno is set.
2720 mlx5_flow_validate_item_geneve(const struct rte_flow_item *item,
2721 uint64_t item_flags,
2722 struct rte_eth_dev *dev,
2723 struct rte_flow_error *error)
2725 struct mlx5_priv *priv = dev->data->dev_private;
2726 const struct rte_flow_item_geneve *spec = item->spec;
2727 const struct rte_flow_item_geneve *mask = item->mask;
2730 uint8_t opt_len = priv->config.hca_attr.geneve_max_opt_len ?
2731 MLX5_GENEVE_OPT_LEN_1 : MLX5_GENEVE_OPT_LEN_0;
2732 const struct rte_flow_item_geneve nic_mask = {
2733 .ver_opt_len_o_c_rsvd0 = RTE_BE16(0x3f80),
2734 .vni = "\xff\xff\xff",
2735 .protocol = RTE_BE16(UINT16_MAX),
2738 if (!priv->config.hca_attr.tunnel_stateless_geneve_rx)
2739 return rte_flow_error_set(error, ENOTSUP,
2740 RTE_FLOW_ERROR_TYPE_ITEM, item,
2741 "L3 Geneve is not enabled by device"
2742 " parameter and/or not configured in"
2744 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2745 return rte_flow_error_set(error, ENOTSUP,
2746 RTE_FLOW_ERROR_TYPE_ITEM, item,
2747 "multiple tunnel layers not"
2750 * Verify only UDPv4 is present as defined in
2751 * https://tools.ietf.org/html/rfc7348
2753 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2754 return rte_flow_error_set(error, EINVAL,
2755 RTE_FLOW_ERROR_TYPE_ITEM, item,
2756 "no outer UDP layer found");
2758 mask = &rte_flow_item_geneve_mask;
2759 ret = mlx5_flow_item_acceptable
2760 (item, (const uint8_t *)mask,
2761 (const uint8_t *)&nic_mask,
2762 sizeof(struct rte_flow_item_geneve),
2763 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2767 gbhdr = rte_be_to_cpu_16(spec->ver_opt_len_o_c_rsvd0);
2768 if (MLX5_GENEVE_VER_VAL(gbhdr) ||
2769 MLX5_GENEVE_CRITO_VAL(gbhdr) ||
2770 MLX5_GENEVE_RSVD_VAL(gbhdr) || spec->rsvd1)
2771 return rte_flow_error_set(error, ENOTSUP,
2772 RTE_FLOW_ERROR_TYPE_ITEM,
2774 "Geneve protocol unsupported"
2775 " fields are being used");
2776 if (MLX5_GENEVE_OPTLEN_VAL(gbhdr) > opt_len)
2777 return rte_flow_error_set
2779 RTE_FLOW_ERROR_TYPE_ITEM,
2781 "Unsupported Geneve options length");
2783 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
2784 return rte_flow_error_set
2786 RTE_FLOW_ERROR_TYPE_ITEM, item,
2787 "Geneve tunnel must be fully defined");
2792 * Validate Geneve TLV option item.
2795 * Item specification.
2796 * @param[in] last_item
2797 * Previous validated item in the pattern items.
2798 * @param[in] geneve_item
2799 * Previous GENEVE item specification.
2801 * Pointer to the rte_eth_dev structure.
2803 * Pointer to error structure.
2806 * 0 on success, a negative errno value otherwise and rte_errno is set.
2809 mlx5_flow_validate_item_geneve_opt(const struct rte_flow_item *item,
2811 const struct rte_flow_item *geneve_item,
2812 struct rte_eth_dev *dev,
2813 struct rte_flow_error *error)
2815 struct mlx5_priv *priv = dev->data->dev_private;
2816 struct mlx5_dev_ctx_shared *sh = priv->sh;
2817 struct mlx5_geneve_tlv_option_resource *geneve_opt_resource;
2818 struct mlx5_hca_attr *hca_attr = &priv->config.hca_attr;
2819 uint8_t data_max_supported =
2820 hca_attr->max_geneve_tlv_option_data_len * 4;
2821 struct mlx5_dev_config *config = &priv->config;
2822 const struct rte_flow_item_geneve *geneve_spec;
2823 const struct rte_flow_item_geneve *geneve_mask;
2824 const struct rte_flow_item_geneve_opt *spec = item->spec;
2825 const struct rte_flow_item_geneve_opt *mask = item->mask;
2827 unsigned int data_len;
2828 uint8_t tlv_option_len;
2829 uint16_t optlen_m, optlen_v;
2830 const struct rte_flow_item_geneve_opt full_mask = {
2831 .option_class = RTE_BE16(0xffff),
2832 .option_type = 0xff,
2837 mask = &rte_flow_item_geneve_opt_mask;
2839 return rte_flow_error_set
2840 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2841 "Geneve TLV opt class/type/length must be specified");
2842 if ((uint32_t)spec->option_len > MLX5_GENEVE_OPTLEN_MASK)
2843 return rte_flow_error_set
2844 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2845 "Geneve TLV opt length exceeeds the limit (31)");
2846 /* Check if class type and length masks are full. */
2847 if (full_mask.option_class != mask->option_class ||
2848 full_mask.option_type != mask->option_type ||
2849 full_mask.option_len != (mask->option_len & full_mask.option_len))
2850 return rte_flow_error_set
2851 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2852 "Geneve TLV opt class/type/length masks must be full");
2853 /* Check if length is supported */
2854 if ((uint32_t)spec->option_len >
2855 config->hca_attr.max_geneve_tlv_option_data_len)
2856 return rte_flow_error_set
2857 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2858 "Geneve TLV opt length not supported");
2859 if (config->hca_attr.max_geneve_tlv_options > 1)
2861 "max_geneve_tlv_options supports more than 1 option");
2862 /* Check GENEVE item preceding. */
2863 if (!geneve_item || !(last_item & MLX5_FLOW_LAYER_GENEVE))
2864 return rte_flow_error_set
2865 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2866 "Geneve opt item must be preceded with Geneve item");
2867 geneve_spec = geneve_item->spec;
2868 geneve_mask = geneve_item->mask ? geneve_item->mask :
2869 &rte_flow_item_geneve_mask;
2870 /* Check if GENEVE TLV option size doesn't exceed option length */
2871 if (geneve_spec && (geneve_mask->ver_opt_len_o_c_rsvd0 ||
2872 geneve_spec->ver_opt_len_o_c_rsvd0)) {
2873 tlv_option_len = spec->option_len & mask->option_len;
2874 optlen_v = rte_be_to_cpu_16(geneve_spec->ver_opt_len_o_c_rsvd0);
2875 optlen_v = MLX5_GENEVE_OPTLEN_VAL(optlen_v);
2876 optlen_m = rte_be_to_cpu_16(geneve_mask->ver_opt_len_o_c_rsvd0);
2877 optlen_m = MLX5_GENEVE_OPTLEN_VAL(optlen_m);
2878 if ((optlen_v & optlen_m) <= tlv_option_len)
2879 return rte_flow_error_set
2880 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2881 "GENEVE TLV option length exceeds optlen");
2883 /* Check if length is 0 or data is 0. */
2884 if (spec->data == NULL || spec->option_len == 0)
2885 return rte_flow_error_set
2886 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2887 "Geneve TLV opt with zero data/length not supported");
2888 /* Check not all data & mask are 0. */
2889 data_len = spec->option_len * 4;
2890 if (mask->data == NULL) {
2891 for (i = 0; i < data_len; i++)
2895 return rte_flow_error_set(error, ENOTSUP,
2896 RTE_FLOW_ERROR_TYPE_ITEM, item,
2897 "Can't match on Geneve option data 0");
2899 for (i = 0; i < data_len; i++)
2900 if (spec->data[i] & mask->data[i])
2903 return rte_flow_error_set(error, ENOTSUP,
2904 RTE_FLOW_ERROR_TYPE_ITEM, item,
2905 "Can't match on Geneve option data and mask 0");
2906 /* Check data mask supported. */
2907 for (i = data_max_supported; i < data_len ; i++)
2909 return rte_flow_error_set(error, ENOTSUP,
2910 RTE_FLOW_ERROR_TYPE_ITEM, item,
2911 "Data mask is of unsupported size");
2913 /* Check GENEVE option is supported in NIC. */
2914 if (!config->hca_attr.geneve_tlv_opt)
2915 return rte_flow_error_set
2916 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2917 "Geneve TLV opt not supported");
2918 /* Check if we already have geneve option with different type/class. */
2919 rte_spinlock_lock(&sh->geneve_tlv_opt_sl);
2920 geneve_opt_resource = sh->geneve_tlv_option_resource;
2921 if (geneve_opt_resource != NULL)
2922 if (geneve_opt_resource->option_class != spec->option_class ||
2923 geneve_opt_resource->option_type != spec->option_type ||
2924 geneve_opt_resource->length != spec->option_len) {
2925 rte_spinlock_unlock(&sh->geneve_tlv_opt_sl);
2926 return rte_flow_error_set(error, ENOTSUP,
2927 RTE_FLOW_ERROR_TYPE_ITEM, item,
2928 "Only one Geneve TLV option supported");
2930 rte_spinlock_unlock(&sh->geneve_tlv_opt_sl);
2935 * Validate MPLS item.
2938 * Pointer to the rte_eth_dev structure.
2940 * Item specification.
2941 * @param[in] item_flags
2942 * Bit-fields that holds the items detected until now.
2943 * @param[in] prev_layer
2944 * The protocol layer indicated in previous item.
2946 * Pointer to error structure.
2949 * 0 on success, a negative errno value otherwise and rte_errno is set.
2952 mlx5_flow_validate_item_mpls(struct rte_eth_dev *dev __rte_unused,
2953 const struct rte_flow_item *item __rte_unused,
2954 uint64_t item_flags __rte_unused,
2955 uint64_t prev_layer __rte_unused,
2956 struct rte_flow_error *error)
2958 #ifdef HAVE_IBV_DEVICE_MPLS_SUPPORT
2959 const struct rte_flow_item_mpls *mask = item->mask;
2960 struct mlx5_priv *priv = dev->data->dev_private;
2963 if (!priv->config.mpls_en)
2964 return rte_flow_error_set(error, ENOTSUP,
2965 RTE_FLOW_ERROR_TYPE_ITEM, item,
2966 "MPLS not supported or"
2967 " disabled in firmware"
2969 /* MPLS over UDP, GRE is allowed */
2970 if (!(prev_layer & (MLX5_FLOW_LAYER_OUTER_L4_UDP |
2971 MLX5_FLOW_LAYER_GRE |
2972 MLX5_FLOW_LAYER_GRE_KEY)))
2973 return rte_flow_error_set(error, EINVAL,
2974 RTE_FLOW_ERROR_TYPE_ITEM, item,
2975 "protocol filtering not compatible"
2976 " with MPLS layer");
2977 /* Multi-tunnel isn't allowed but MPLS over GRE is an exception. */
2978 if ((item_flags & MLX5_FLOW_LAYER_TUNNEL) &&
2979 !(item_flags & MLX5_FLOW_LAYER_GRE))
2980 return rte_flow_error_set(error, ENOTSUP,
2981 RTE_FLOW_ERROR_TYPE_ITEM, item,
2982 "multiple tunnel layers not"
2985 mask = &rte_flow_item_mpls_mask;
2986 ret = mlx5_flow_item_acceptable
2987 (item, (const uint8_t *)mask,
2988 (const uint8_t *)&rte_flow_item_mpls_mask,
2989 sizeof(struct rte_flow_item_mpls),
2990 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2995 return rte_flow_error_set(error, ENOTSUP,
2996 RTE_FLOW_ERROR_TYPE_ITEM, item,
2997 "MPLS is not supported by Verbs, please"
3003 * Validate NVGRE item.
3006 * Item specification.
3007 * @param[in] item_flags
3008 * Bit flags to mark detected items.
3009 * @param[in] target_protocol
3010 * The next protocol in the previous item.
3012 * Pointer to error structure.
3015 * 0 on success, a negative errno value otherwise and rte_errno is set.
3018 mlx5_flow_validate_item_nvgre(const struct rte_flow_item *item,
3019 uint64_t item_flags,
3020 uint8_t target_protocol,
3021 struct rte_flow_error *error)
3023 const struct rte_flow_item_nvgre *mask = item->mask;
3026 if (target_protocol != 0xff && target_protocol != IPPROTO_GRE)
3027 return rte_flow_error_set(error, EINVAL,
3028 RTE_FLOW_ERROR_TYPE_ITEM, item,
3029 "protocol filtering not compatible"
3030 " with this GRE layer");
3031 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
3032 return rte_flow_error_set(error, ENOTSUP,
3033 RTE_FLOW_ERROR_TYPE_ITEM, item,
3034 "multiple tunnel layers not"
3036 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3))
3037 return rte_flow_error_set(error, ENOTSUP,
3038 RTE_FLOW_ERROR_TYPE_ITEM, item,
3039 "L3 Layer is missing");
3041 mask = &rte_flow_item_nvgre_mask;
3042 ret = mlx5_flow_item_acceptable
3043 (item, (const uint8_t *)mask,
3044 (const uint8_t *)&rte_flow_item_nvgre_mask,
3045 sizeof(struct rte_flow_item_nvgre),
3046 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
3053 * Validate eCPRI item.
3056 * Item specification.
3057 * @param[in] item_flags
3058 * Bit-fields that holds the items detected until now.
3059 * @param[in] last_item
3060 * Previous validated item in the pattern items.
3061 * @param[in] ether_type
3062 * Type in the ethernet layer header (including dot1q).
3063 * @param[in] acc_mask
3064 * Acceptable mask, if NULL default internal default mask
3065 * will be used to check whether item fields are supported.
3067 * Pointer to error structure.
3070 * 0 on success, a negative errno value otherwise and rte_errno is set.
3073 mlx5_flow_validate_item_ecpri(const struct rte_flow_item *item,
3074 uint64_t item_flags,
3076 uint16_t ether_type,
3077 const struct rte_flow_item_ecpri *acc_mask,
3078 struct rte_flow_error *error)
3080 const struct rte_flow_item_ecpri *mask = item->mask;
3081 const struct rte_flow_item_ecpri nic_mask = {
3085 RTE_BE32(((const struct rte_ecpri_common_hdr) {
3089 .dummy[0] = 0xFFFFFFFF,
3092 const uint64_t outer_l2_vlan = (MLX5_FLOW_LAYER_OUTER_L2 |
3093 MLX5_FLOW_LAYER_OUTER_VLAN);
3094 struct rte_flow_item_ecpri mask_lo;
3096 if (!(last_item & outer_l2_vlan) &&
3097 last_item != MLX5_FLOW_LAYER_OUTER_L4_UDP)
3098 return rte_flow_error_set(error, EINVAL,
3099 RTE_FLOW_ERROR_TYPE_ITEM, item,
3100 "eCPRI can only follow L2/VLAN layer or UDP layer");
3101 if ((last_item & outer_l2_vlan) && ether_type &&
3102 ether_type != RTE_ETHER_TYPE_ECPRI)
3103 return rte_flow_error_set(error, EINVAL,
3104 RTE_FLOW_ERROR_TYPE_ITEM, item,
3105 "eCPRI cannot follow L2/VLAN layer which ether type is not 0xAEFE");
3106 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
3107 return rte_flow_error_set(error, EINVAL,
3108 RTE_FLOW_ERROR_TYPE_ITEM, item,
3109 "eCPRI with tunnel is not supported right now");
3110 if (item_flags & MLX5_FLOW_LAYER_OUTER_L3)
3111 return rte_flow_error_set(error, ENOTSUP,
3112 RTE_FLOW_ERROR_TYPE_ITEM, item,
3113 "multiple L3 layers not supported");
3114 else if (item_flags & MLX5_FLOW_LAYER_OUTER_L4_TCP)
3115 return rte_flow_error_set(error, EINVAL,
3116 RTE_FLOW_ERROR_TYPE_ITEM, item,
3117 "eCPRI cannot coexist with a TCP layer");
3118 /* In specification, eCPRI could be over UDP layer. */
3119 else if (item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP)
3120 return rte_flow_error_set(error, EINVAL,
3121 RTE_FLOW_ERROR_TYPE_ITEM, item,
3122 "eCPRI over UDP layer is not yet supported right now");
3123 /* Mask for type field in common header could be zero. */
3125 mask = &rte_flow_item_ecpri_mask;
3126 mask_lo.hdr.common.u32 = rte_be_to_cpu_32(mask->hdr.common.u32);
3127 /* Input mask is in big-endian format. */
3128 if (mask_lo.hdr.common.type != 0 && mask_lo.hdr.common.type != 0xff)
3129 return rte_flow_error_set(error, EINVAL,
3130 RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
3131 "partial mask is not supported for protocol");
3132 else if (mask_lo.hdr.common.type == 0 && mask->hdr.dummy[0] != 0)
3133 return rte_flow_error_set(error, EINVAL,
3134 RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
3135 "message header mask must be after a type mask");
3136 return mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
3137 acc_mask ? (const uint8_t *)acc_mask
3138 : (const uint8_t *)&nic_mask,
3139 sizeof(struct rte_flow_item_ecpri),
3140 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
3144 flow_null_validate(struct rte_eth_dev *dev __rte_unused,
3145 const struct rte_flow_attr *attr __rte_unused,
3146 const struct rte_flow_item items[] __rte_unused,
3147 const struct rte_flow_action actions[] __rte_unused,
3148 bool external __rte_unused,
3149 int hairpin __rte_unused,
3150 struct rte_flow_error *error)
3152 return rte_flow_error_set(error, ENOTSUP,
3153 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
3156 static struct mlx5_flow *
3157 flow_null_prepare(struct rte_eth_dev *dev __rte_unused,
3158 const struct rte_flow_attr *attr __rte_unused,
3159 const struct rte_flow_item items[] __rte_unused,
3160 const struct rte_flow_action actions[] __rte_unused,
3161 struct rte_flow_error *error)
3163 rte_flow_error_set(error, ENOTSUP,
3164 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
3169 flow_null_translate(struct rte_eth_dev *dev __rte_unused,
3170 struct mlx5_flow *dev_flow __rte_unused,
3171 const struct rte_flow_attr *attr __rte_unused,
3172 const struct rte_flow_item items[] __rte_unused,
3173 const struct rte_flow_action actions[] __rte_unused,
3174 struct rte_flow_error *error)
3176 return rte_flow_error_set(error, ENOTSUP,
3177 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
3181 flow_null_apply(struct rte_eth_dev *dev __rte_unused,
3182 struct rte_flow *flow __rte_unused,
3183 struct rte_flow_error *error)
3185 return rte_flow_error_set(error, ENOTSUP,
3186 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
3190 flow_null_remove(struct rte_eth_dev *dev __rte_unused,
3191 struct rte_flow *flow __rte_unused)
3196 flow_null_destroy(struct rte_eth_dev *dev __rte_unused,
3197 struct rte_flow *flow __rte_unused)
3202 flow_null_query(struct rte_eth_dev *dev __rte_unused,
3203 struct rte_flow *flow __rte_unused,
3204 const struct rte_flow_action *actions __rte_unused,
3205 void *data __rte_unused,
3206 struct rte_flow_error *error)
3208 return rte_flow_error_set(error, ENOTSUP,
3209 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
3213 flow_null_sync_domain(struct rte_eth_dev *dev __rte_unused,
3214 uint32_t domains __rte_unused,
3215 uint32_t flags __rte_unused)
3220 /* Void driver to protect from null pointer reference. */
3221 const struct mlx5_flow_driver_ops mlx5_flow_null_drv_ops = {
3222 .validate = flow_null_validate,
3223 .prepare = flow_null_prepare,
3224 .translate = flow_null_translate,
3225 .apply = flow_null_apply,
3226 .remove = flow_null_remove,
3227 .destroy = flow_null_destroy,
3228 .query = flow_null_query,
3229 .sync_domain = flow_null_sync_domain,
3233 * Select flow driver type according to flow attributes and device
3237 * Pointer to the dev structure.
3239 * Pointer to the flow attributes.
3242 * flow driver type, MLX5_FLOW_TYPE_MAX otherwise.
3244 static enum mlx5_flow_drv_type
3245 flow_get_drv_type(struct rte_eth_dev *dev, const struct rte_flow_attr *attr)
3247 struct mlx5_priv *priv = dev->data->dev_private;
3248 /* The OS can determine first a specific flow type (DV, VERBS) */
3249 enum mlx5_flow_drv_type type = mlx5_flow_os_get_type();
3251 if (type != MLX5_FLOW_TYPE_MAX)
3253 /* If no OS specific type - continue with DV/VERBS selection */
3254 if (attr->transfer && priv->config.dv_esw_en)
3255 type = MLX5_FLOW_TYPE_DV;
3256 if (!attr->transfer)
3257 type = priv->config.dv_flow_en ? MLX5_FLOW_TYPE_DV :
3258 MLX5_FLOW_TYPE_VERBS;
3262 #define flow_get_drv_ops(type) flow_drv_ops[type]
3265 * Flow driver validation API. This abstracts calling driver specific functions.
3266 * The type of flow driver is determined according to flow attributes.
3269 * Pointer to the dev structure.
3271 * Pointer to the flow attributes.
3273 * Pointer to the list of items.
3274 * @param[in] actions
3275 * Pointer to the list of actions.
3276 * @param[in] external
3277 * This flow rule is created by request external to PMD.
3278 * @param[in] hairpin
3279 * Number of hairpin TX actions, 0 means classic flow.
3281 * Pointer to the error structure.
3284 * 0 on success, a negative errno value otherwise and rte_errno is set.
3287 flow_drv_validate(struct rte_eth_dev *dev,
3288 const struct rte_flow_attr *attr,
3289 const struct rte_flow_item items[],
3290 const struct rte_flow_action actions[],
3291 bool external, int hairpin, struct rte_flow_error *error)
3293 const struct mlx5_flow_driver_ops *fops;
3294 enum mlx5_flow_drv_type type = flow_get_drv_type(dev, attr);
3296 fops = flow_get_drv_ops(type);
3297 return fops->validate(dev, attr, items, actions, external,
3302 * Flow driver preparation API. This abstracts calling driver specific
3303 * functions. Parent flow (rte_flow) should have driver type (drv_type). It
3304 * calculates the size of memory required for device flow, allocates the memory,
3305 * initializes the device flow and returns the pointer.
3308 * This function initializes device flow structure such as dv or verbs in
3309 * struct mlx5_flow. However, it is caller's responsibility to initialize the
3310 * rest. For example, adding returning device flow to flow->dev_flow list and
3311 * setting backward reference to the flow should be done out of this function.
3312 * layers field is not filled either.
3315 * Pointer to the dev structure.
3317 * Pointer to the flow attributes.
3319 * Pointer to the list of items.
3320 * @param[in] actions
3321 * Pointer to the list of actions.
3322 * @param[in] flow_idx
3323 * This memory pool index to the flow.
3325 * Pointer to the error structure.
3328 * Pointer to device flow on success, otherwise NULL and rte_errno is set.
3330 static inline struct mlx5_flow *
3331 flow_drv_prepare(struct rte_eth_dev *dev,
3332 const struct rte_flow *flow,
3333 const struct rte_flow_attr *attr,
3334 const struct rte_flow_item items[],
3335 const struct rte_flow_action actions[],
3337 struct rte_flow_error *error)
3339 const struct mlx5_flow_driver_ops *fops;
3340 enum mlx5_flow_drv_type type = flow->drv_type;
3341 struct mlx5_flow *mlx5_flow = NULL;
3343 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3344 fops = flow_get_drv_ops(type);
3345 mlx5_flow = fops->prepare(dev, attr, items, actions, error);
3347 mlx5_flow->flow_idx = flow_idx;
3352 * Flow driver translation API. This abstracts calling driver specific
3353 * functions. Parent flow (rte_flow) should have driver type (drv_type). It
3354 * translates a generic flow into a driver flow. flow_drv_prepare() must
3358 * dev_flow->layers could be filled as a result of parsing during translation
3359 * if needed by flow_drv_apply(). dev_flow->flow->actions can also be filled
3360 * if necessary. As a flow can have multiple dev_flows by RSS flow expansion,
3361 * flow->actions could be overwritten even though all the expanded dev_flows
3362 * have the same actions.
3365 * Pointer to the rte dev structure.
3366 * @param[in, out] dev_flow
3367 * Pointer to the mlx5 flow.
3369 * Pointer to the flow attributes.
3371 * Pointer to the list of items.
3372 * @param[in] actions
3373 * Pointer to the list of actions.
3375 * Pointer to the error structure.
3378 * 0 on success, a negative errno value otherwise and rte_errno is set.
3381 flow_drv_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
3382 const struct rte_flow_attr *attr,
3383 const struct rte_flow_item items[],
3384 const struct rte_flow_action actions[],
3385 struct rte_flow_error *error)
3387 const struct mlx5_flow_driver_ops *fops;
3388 enum mlx5_flow_drv_type type = dev_flow->flow->drv_type;
3390 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3391 fops = flow_get_drv_ops(type);
3392 return fops->translate(dev, dev_flow, attr, items, actions, error);
3396 * Flow driver apply API. This abstracts calling driver specific functions.
3397 * Parent flow (rte_flow) should have driver type (drv_type). It applies
3398 * translated driver flows on to device. flow_drv_translate() must precede.
3401 * Pointer to Ethernet device structure.
3402 * @param[in, out] flow
3403 * Pointer to flow structure.
3405 * Pointer to error structure.
3408 * 0 on success, a negative errno value otherwise and rte_errno is set.
3411 flow_drv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
3412 struct rte_flow_error *error)
3414 const struct mlx5_flow_driver_ops *fops;
3415 enum mlx5_flow_drv_type type = flow->drv_type;
3417 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3418 fops = flow_get_drv_ops(type);
3419 return fops->apply(dev, flow, error);
3423 * Flow driver destroy API. This abstracts calling driver specific functions.
3424 * Parent flow (rte_flow) should have driver type (drv_type). It removes a flow
3425 * on device and releases resources of the flow.
3428 * Pointer to Ethernet device.
3429 * @param[in, out] flow
3430 * Pointer to flow structure.
3433 flow_drv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
3435 const struct mlx5_flow_driver_ops *fops;
3436 enum mlx5_flow_drv_type type = flow->drv_type;
3438 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3439 fops = flow_get_drv_ops(type);
3440 fops->destroy(dev, flow);
3444 * Flow driver find RSS policy tbl API. This abstracts calling driver
3445 * specific functions. Parent flow (rte_flow) should have driver
3446 * type (drv_type). It will find the RSS policy table that has the rss_desc.
3449 * Pointer to Ethernet device.
3450 * @param[in, out] flow
3451 * Pointer to flow structure.
3453 * Pointer to meter policy table.
3454 * @param[in] rss_desc
3455 * Pointer to rss_desc
3457 static struct mlx5_flow_meter_sub_policy *
3458 flow_drv_meter_sub_policy_rss_prepare(struct rte_eth_dev *dev,
3459 struct rte_flow *flow,
3460 struct mlx5_flow_meter_policy *policy,
3461 struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS])
3463 const struct mlx5_flow_driver_ops *fops;
3464 enum mlx5_flow_drv_type type = flow->drv_type;
3466 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3467 fops = flow_get_drv_ops(type);
3468 return fops->meter_sub_policy_rss_prepare(dev, policy, rss_desc);
3472 * Flow driver color tag rule API. This abstracts calling driver
3473 * specific functions. Parent flow (rte_flow) should have driver
3474 * type (drv_type). It will create the color tag rules in hierarchy meter.
3477 * Pointer to Ethernet device.
3478 * @param[in, out] flow
3479 * Pointer to flow structure.
3481 * Pointer to flow meter structure.
3482 * @param[in] src_port
3483 * The src port this extra rule should use.
3485 * The src port id match item.
3487 * Pointer to error structure.
3490 flow_drv_mtr_hierarchy_rule_create(struct rte_eth_dev *dev,
3491 struct rte_flow *flow,
3492 struct mlx5_flow_meter_info *fm,
3494 const struct rte_flow_item *item,
3495 struct rte_flow_error *error)
3497 const struct mlx5_flow_driver_ops *fops;
3498 enum mlx5_flow_drv_type type = flow->drv_type;
3500 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3501 fops = flow_get_drv_ops(type);
3502 return fops->meter_hierarchy_rule_create(dev, fm,
3503 src_port, item, error);
3507 * Get RSS action from the action list.
3510 * Pointer to Ethernet device.
3511 * @param[in] actions
3512 * Pointer to the list of actions.
3514 * Parent flow structure pointer.
3517 * Pointer to the RSS action if exist, else return NULL.
3519 static const struct rte_flow_action_rss*
3520 flow_get_rss_action(struct rte_eth_dev *dev,
3521 const struct rte_flow_action actions[])
3523 struct mlx5_priv *priv = dev->data->dev_private;
3524 const struct rte_flow_action_rss *rss = NULL;
3526 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3527 switch (actions->type) {
3528 case RTE_FLOW_ACTION_TYPE_RSS:
3529 rss = actions->conf;
3531 case RTE_FLOW_ACTION_TYPE_SAMPLE:
3533 const struct rte_flow_action_sample *sample =
3535 const struct rte_flow_action *act = sample->actions;
3536 for (; act->type != RTE_FLOW_ACTION_TYPE_END; act++)
3537 if (act->type == RTE_FLOW_ACTION_TYPE_RSS)
3541 case RTE_FLOW_ACTION_TYPE_METER:
3544 struct mlx5_flow_meter_info *fm;
3545 struct mlx5_flow_meter_policy *policy;
3546 const struct rte_flow_action_meter *mtr = actions->conf;
3548 fm = mlx5_flow_meter_find(priv, mtr->mtr_id, &mtr_idx);
3549 if (fm && !fm->def_policy) {
3550 policy = mlx5_flow_meter_policy_find(dev,
3551 fm->policy_id, NULL);
3552 MLX5_ASSERT(policy);
3553 if (policy->is_hierarchy) {
3555 mlx5_flow_meter_hierarchy_get_final_policy(dev,
3562 policy->act_cnt[RTE_COLOR_GREEN].rss->conf;
3574 * Get ASO age action by index.
3577 * Pointer to the Ethernet device structure.
3578 * @param[in] age_idx
3579 * Index to the ASO age action.
3582 * The specified ASO age action.
3584 struct mlx5_aso_age_action*
3585 flow_aso_age_get_by_idx(struct rte_eth_dev *dev, uint32_t age_idx)
3587 uint16_t pool_idx = age_idx & UINT16_MAX;
3588 uint16_t offset = (age_idx >> 16) & UINT16_MAX;
3589 struct mlx5_priv *priv = dev->data->dev_private;
3590 struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
3591 struct mlx5_aso_age_pool *pool = mng->pools[pool_idx];
3593 return &pool->actions[offset - 1];
3596 /* maps indirect action to translated direct in some actions array */
3597 struct mlx5_translated_action_handle {
3598 struct rte_flow_action_handle *action; /**< Indirect action handle. */
3599 int index; /**< Index in related array of rte_flow_action. */
3603 * Translates actions of type RTE_FLOW_ACTION_TYPE_INDIRECT to related
3604 * direct action if translation possible.
3605 * This functionality used to run same execution path for both direct and
3606 * indirect actions on flow create. All necessary preparations for indirect
3607 * action handling should be performed on *handle* actions list returned
3611 * Pointer to Ethernet device.
3612 * @param[in] actions
3613 * List of actions to translate.
3614 * @param[out] handle
3615 * List to store translated indirect action object handles.
3616 * @param[in, out] indir_n
3617 * Size of *handle* array. On return should be updated with number of
3618 * indirect actions retrieved from the *actions* list.
3619 * @param[out] translated_actions
3620 * List of actions where all indirect actions were translated to direct
3621 * if possible. NULL if no translation took place.
3623 * Pointer to the error structure.
3626 * 0 on success, a negative errno value otherwise and rte_errno is set.
3629 flow_action_handles_translate(struct rte_eth_dev *dev,
3630 const struct rte_flow_action actions[],
3631 struct mlx5_translated_action_handle *handle,
3633 struct rte_flow_action **translated_actions,
3634 struct rte_flow_error *error)
3636 struct mlx5_priv *priv = dev->data->dev_private;
3637 struct rte_flow_action *translated = NULL;
3638 size_t actions_size;
3641 struct mlx5_translated_action_handle *handle_end = NULL;
3643 for (n = 0; actions[n].type != RTE_FLOW_ACTION_TYPE_END; n++) {
3644 if (actions[n].type != RTE_FLOW_ACTION_TYPE_INDIRECT)
3646 if (copied_n == *indir_n) {
3647 return rte_flow_error_set
3648 (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION_NUM,
3649 NULL, "too many shared actions");
3651 rte_memcpy(&handle[copied_n].action, &actions[n].conf,
3652 sizeof(actions[n].conf));
3653 handle[copied_n].index = n;
3657 *indir_n = copied_n;
3660 actions_size = sizeof(struct rte_flow_action) * n;
3661 translated = mlx5_malloc(MLX5_MEM_ZERO, actions_size, 0, SOCKET_ID_ANY);
3666 memcpy(translated, actions, actions_size);
3667 for (handle_end = handle + copied_n; handle < handle_end; handle++) {
3668 struct mlx5_shared_action_rss *shared_rss;
3669 uint32_t act_idx = (uint32_t)(uintptr_t)handle->action;
3670 uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
3671 uint32_t idx = act_idx &
3672 ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
3675 case MLX5_INDIRECT_ACTION_TYPE_RSS:
3676 shared_rss = mlx5_ipool_get
3677 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
3678 translated[handle->index].type =
3679 RTE_FLOW_ACTION_TYPE_RSS;
3680 translated[handle->index].conf =
3681 &shared_rss->origin;
3683 case MLX5_INDIRECT_ACTION_TYPE_COUNT:
3684 translated[handle->index].type =
3685 (enum rte_flow_action_type)
3686 MLX5_RTE_FLOW_ACTION_TYPE_COUNT;
3687 translated[handle->index].conf = (void *)(uintptr_t)idx;
3689 case MLX5_INDIRECT_ACTION_TYPE_AGE:
3690 if (priv->sh->flow_hit_aso_en) {
3691 translated[handle->index].type =
3692 (enum rte_flow_action_type)
3693 MLX5_RTE_FLOW_ACTION_TYPE_AGE;
3694 translated[handle->index].conf =
3695 (void *)(uintptr_t)idx;
3699 case MLX5_INDIRECT_ACTION_TYPE_CT:
3700 if (priv->sh->ct_aso_en) {
3701 translated[handle->index].type =
3702 RTE_FLOW_ACTION_TYPE_CONNTRACK;
3703 translated[handle->index].conf =
3704 (void *)(uintptr_t)idx;
3709 mlx5_free(translated);
3710 return rte_flow_error_set
3711 (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
3712 NULL, "invalid indirect action type");
3715 *translated_actions = translated;
3720 * Get Shared RSS action from the action list.
3723 * Pointer to Ethernet device.
3725 * Pointer to the list of actions.
3726 * @param[in] shared_n
3727 * Actions list length.
3730 * The MLX5 RSS action ID if exists, otherwise return 0.
3733 flow_get_shared_rss_action(struct rte_eth_dev *dev,
3734 struct mlx5_translated_action_handle *handle,
3737 struct mlx5_translated_action_handle *handle_end;
3738 struct mlx5_priv *priv = dev->data->dev_private;
3739 struct mlx5_shared_action_rss *shared_rss;
3742 for (handle_end = handle + shared_n; handle < handle_end; handle++) {
3743 uint32_t act_idx = (uint32_t)(uintptr_t)handle->action;
3744 uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
3745 uint32_t idx = act_idx &
3746 ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
3748 case MLX5_INDIRECT_ACTION_TYPE_RSS:
3749 shared_rss = mlx5_ipool_get
3750 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
3752 __atomic_add_fetch(&shared_rss->refcnt, 1,
3763 find_graph_root(const struct rte_flow_item pattern[], uint32_t rss_level)
3765 const struct rte_flow_item *item;
3766 unsigned int has_vlan = 0;
3768 for (item = pattern; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
3769 if (item->type == RTE_FLOW_ITEM_TYPE_VLAN) {
3775 return rss_level < 2 ? MLX5_EXPANSION_ROOT_ETH_VLAN :
3776 MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN;
3777 return rss_level < 2 ? MLX5_EXPANSION_ROOT :
3778 MLX5_EXPANSION_ROOT_OUTER;
3782 * Get layer flags from the prefix flow.
3784 * Some flows may be split to several subflows, the prefix subflow gets the
3785 * match items and the suffix sub flow gets the actions.
3786 * Some actions need the user defined match item flags to get the detail for
3788 * This function helps the suffix flow to get the item layer flags from prefix
3791 * @param[in] dev_flow
3792 * Pointer the created preifx subflow.
3795 * The layers get from prefix subflow.
3797 static inline uint64_t
3798 flow_get_prefix_layer_flags(struct mlx5_flow *dev_flow)
3800 uint64_t layers = 0;
3803 * Layers bits could be localization, but usually the compiler will
3804 * help to do the optimization work for source code.
3805 * If no decap actions, use the layers directly.
3807 if (!(dev_flow->act_flags & MLX5_FLOW_ACTION_DECAP))
3808 return dev_flow->handle->layers;
3809 /* Convert L3 layers with decap action. */
3810 if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L3_IPV4)
3811 layers |= MLX5_FLOW_LAYER_OUTER_L3_IPV4;
3812 else if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L3_IPV6)
3813 layers |= MLX5_FLOW_LAYER_OUTER_L3_IPV6;
3814 /* Convert L4 layers with decap action. */
3815 if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L4_TCP)
3816 layers |= MLX5_FLOW_LAYER_OUTER_L4_TCP;
3817 else if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L4_UDP)
3818 layers |= MLX5_FLOW_LAYER_OUTER_L4_UDP;
3823 * Get metadata split action information.
3825 * @param[in] actions
3826 * Pointer to the list of actions.
3828 * Pointer to the return pointer.
3829 * @param[out] qrss_type
3830 * Pointer to the action type to return. RTE_FLOW_ACTION_TYPE_END is returned
3831 * if no QUEUE/RSS is found.
3832 * @param[out] encap_idx
3833 * Pointer to the index of the encap action if exists, otherwise the last
3837 * Total number of actions.
3840 flow_parse_metadata_split_actions_info(const struct rte_flow_action actions[],
3841 const struct rte_flow_action **qrss,
3844 const struct rte_flow_action_raw_encap *raw_encap;
3846 int raw_decap_idx = -1;
3849 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3850 switch (actions->type) {
3851 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
3852 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
3853 *encap_idx = actions_n;
3855 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
3856 raw_decap_idx = actions_n;
3858 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
3859 raw_encap = actions->conf;
3860 if (raw_encap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
3861 *encap_idx = raw_decap_idx != -1 ?
3862 raw_decap_idx : actions_n;
3864 case RTE_FLOW_ACTION_TYPE_QUEUE:
3865 case RTE_FLOW_ACTION_TYPE_RSS:
3873 if (*encap_idx == -1)
3874 *encap_idx = actions_n;
3875 /* Count RTE_FLOW_ACTION_TYPE_END. */
3876 return actions_n + 1;
3880 * Check if the action will change packet.
3883 * Pointer to Ethernet device.
3888 * true if action will change packet, false otherwise.
3890 static bool flow_check_modify_action_type(struct rte_eth_dev *dev,
3891 enum rte_flow_action_type type)
3893 struct mlx5_priv *priv = dev->data->dev_private;
3896 case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
3897 case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
3898 case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
3899 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
3900 case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
3901 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
3902 case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
3903 case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
3904 case RTE_FLOW_ACTION_TYPE_DEC_TTL:
3905 case RTE_FLOW_ACTION_TYPE_SET_TTL:
3906 case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
3907 case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
3908 case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
3909 case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
3910 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
3911 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
3912 case RTE_FLOW_ACTION_TYPE_SET_META:
3913 case RTE_FLOW_ACTION_TYPE_SET_TAG:
3914 case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
3915 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
3916 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
3917 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
3918 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
3919 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
3920 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
3921 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
3922 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
3923 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
3924 case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
3926 case RTE_FLOW_ACTION_TYPE_FLAG:
3927 case RTE_FLOW_ACTION_TYPE_MARK:
3928 if (priv->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY)
3938 * Check meter action from the action list.
3941 * Pointer to Ethernet device.
3942 * @param[in] actions
3943 * Pointer to the list of actions.
3944 * @param[out] has_mtr
3945 * Pointer to the meter exist flag.
3946 * @param[out] has_modify
3947 * Pointer to the flag showing there's packet change action.
3948 * @param[out] meter_id
3949 * Pointer to the meter id.
3952 * Total number of actions.
3955 flow_check_meter_action(struct rte_eth_dev *dev,
3956 const struct rte_flow_action actions[],
3957 bool *has_mtr, bool *has_modify, uint32_t *meter_id)
3959 const struct rte_flow_action_meter *mtr = NULL;
3962 MLX5_ASSERT(has_mtr);
3964 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3965 switch (actions->type) {
3966 case RTE_FLOW_ACTION_TYPE_METER:
3967 mtr = actions->conf;
3968 *meter_id = mtr->mtr_id;
3975 *has_modify |= flow_check_modify_action_type(dev,
3979 /* Count RTE_FLOW_ACTION_TYPE_END. */
3980 return actions_n + 1;
3984 * Check if the flow should be split due to hairpin.
3985 * The reason for the split is that in current HW we can't
3986 * support encap and push-vlan on Rx, so if a flow contains
3987 * these actions we move it to Tx.
3990 * Pointer to Ethernet device.
3992 * Flow rule attributes.
3993 * @param[in] actions
3994 * Associated actions (list terminated by the END action).
3997 * > 0 the number of actions and the flow should be split,
3998 * 0 when no split required.
4001 flow_check_hairpin_split(struct rte_eth_dev *dev,
4002 const struct rte_flow_attr *attr,
4003 const struct rte_flow_action actions[])
4005 int queue_action = 0;
4008 const struct rte_flow_action_queue *queue;
4009 const struct rte_flow_action_rss *rss;
4010 const struct rte_flow_action_raw_encap *raw_encap;
4011 const struct rte_eth_hairpin_conf *conf;
4015 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4016 switch (actions->type) {
4017 case RTE_FLOW_ACTION_TYPE_QUEUE:
4018 queue = actions->conf;
4021 conf = mlx5_rxq_get_hairpin_conf(dev, queue->index);
4022 if (conf == NULL || conf->tx_explicit != 0)
4027 case RTE_FLOW_ACTION_TYPE_RSS:
4028 rss = actions->conf;
4029 if (rss == NULL || rss->queue_num == 0)
4031 conf = mlx5_rxq_get_hairpin_conf(dev, rss->queue[0]);
4032 if (conf == NULL || conf->tx_explicit != 0)
4037 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
4038 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
4039 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
4040 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
4041 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
4045 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
4046 raw_encap = actions->conf;
4047 if (raw_encap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
4056 if (split && queue_action)
4061 /* Declare flow create/destroy prototype in advance. */
4063 flow_list_create(struct rte_eth_dev *dev, enum mlx5_flow_type type,
4064 const struct rte_flow_attr *attr,
4065 const struct rte_flow_item items[],
4066 const struct rte_flow_action actions[],
4067 bool external, struct rte_flow_error *error);
4070 flow_list_destroy(struct rte_eth_dev *dev, enum mlx5_flow_type type,
4074 flow_dv_mreg_match_cb(void *tool_ctx __rte_unused,
4075 struct mlx5_list_entry *entry, void *cb_ctx)
4077 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4078 struct mlx5_flow_mreg_copy_resource *mcp_res =
4079 container_of(entry, typeof(*mcp_res), hlist_ent);
4081 return mcp_res->mark_id != *(uint32_t *)(ctx->data);
4084 struct mlx5_list_entry *
4085 flow_dv_mreg_create_cb(void *tool_ctx, void *cb_ctx)
4087 struct rte_eth_dev *dev = tool_ctx;
4088 struct mlx5_priv *priv = dev->data->dev_private;
4089 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4090 struct mlx5_flow_mreg_copy_resource *mcp_res;
4091 struct rte_flow_error *error = ctx->error;
4094 uint32_t mark_id = *(uint32_t *)(ctx->data);
4095 struct rte_flow_attr attr = {
4096 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
4099 struct mlx5_rte_flow_item_tag tag_spec = {
4102 struct rte_flow_item items[] = {
4103 [1] = { .type = RTE_FLOW_ITEM_TYPE_END, },
4105 struct rte_flow_action_mark ftag = {
4108 struct mlx5_flow_action_copy_mreg cp_mreg = {
4112 struct rte_flow_action_jump jump = {
4113 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
4115 struct rte_flow_action actions[] = {
4116 [3] = { .type = RTE_FLOW_ACTION_TYPE_END, },
4119 /* Fill the register fileds in the flow. */
4120 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
4124 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_RX, 0, error);
4128 /* Provide the full width of FLAG specific value. */
4129 if (mark_id == (priv->sh->dv_regc0_mask & MLX5_FLOW_MARK_DEFAULT))
4130 tag_spec.data = MLX5_FLOW_MARK_DEFAULT;
4131 /* Build a new flow. */
4132 if (mark_id != MLX5_DEFAULT_COPY_ID) {
4133 items[0] = (struct rte_flow_item){
4134 .type = (enum rte_flow_item_type)
4135 MLX5_RTE_FLOW_ITEM_TYPE_TAG,
4138 items[1] = (struct rte_flow_item){
4139 .type = RTE_FLOW_ITEM_TYPE_END,
4141 actions[0] = (struct rte_flow_action){
4142 .type = (enum rte_flow_action_type)
4143 MLX5_RTE_FLOW_ACTION_TYPE_MARK,
4146 actions[1] = (struct rte_flow_action){
4147 .type = (enum rte_flow_action_type)
4148 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
4151 actions[2] = (struct rte_flow_action){
4152 .type = RTE_FLOW_ACTION_TYPE_JUMP,
4155 actions[3] = (struct rte_flow_action){
4156 .type = RTE_FLOW_ACTION_TYPE_END,
4159 /* Default rule, wildcard match. */
4160 attr.priority = MLX5_FLOW_LOWEST_PRIO_INDICATOR;
4161 items[0] = (struct rte_flow_item){
4162 .type = RTE_FLOW_ITEM_TYPE_END,
4164 actions[0] = (struct rte_flow_action){
4165 .type = (enum rte_flow_action_type)
4166 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
4169 actions[1] = (struct rte_flow_action){
4170 .type = RTE_FLOW_ACTION_TYPE_JUMP,
4173 actions[2] = (struct rte_flow_action){
4174 .type = RTE_FLOW_ACTION_TYPE_END,
4177 /* Build a new entry. */
4178 mcp_res = mlx5_ipool_zmalloc(priv->sh->ipool[MLX5_IPOOL_MCP], &idx);
4184 mcp_res->mark_id = mark_id;
4186 * The copy Flows are not included in any list. There
4187 * ones are referenced from other Flows and can not
4188 * be applied, removed, deleted in ardbitrary order
4189 * by list traversing.
4191 mcp_res->rix_flow = flow_list_create(dev, MLX5_FLOW_TYPE_MCP,
4192 &attr, items, actions, false, error);
4193 if (!mcp_res->rix_flow) {
4194 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], idx);
4197 return &mcp_res->hlist_ent;
4200 struct mlx5_list_entry *
4201 flow_dv_mreg_clone_cb(void *tool_ctx, struct mlx5_list_entry *oentry,
4202 void *cb_ctx __rte_unused)
4204 struct rte_eth_dev *dev = tool_ctx;
4205 struct mlx5_priv *priv = dev->data->dev_private;
4206 struct mlx5_flow_mreg_copy_resource *mcp_res;
4209 mcp_res = mlx5_ipool_malloc(priv->sh->ipool[MLX5_IPOOL_MCP], &idx);
4214 memcpy(mcp_res, oentry, sizeof(*mcp_res));
4216 return &mcp_res->hlist_ent;
4220 flow_dv_mreg_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
4222 struct mlx5_flow_mreg_copy_resource *mcp_res =
4223 container_of(entry, typeof(*mcp_res), hlist_ent);
4224 struct rte_eth_dev *dev = tool_ctx;
4225 struct mlx5_priv *priv = dev->data->dev_private;
4227 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], mcp_res->idx);
4231 * Add a flow of copying flow metadata registers in RX_CP_TBL.
4233 * As mark_id is unique, if there's already a registered flow for the mark_id,
4234 * return by increasing the reference counter of the resource. Otherwise, create
4235 * the resource (mcp_res) and flow.
4238 * - If ingress port is ANY and reg_c[1] is mark_id,
4239 * flow_tag := mark_id, reg_b := reg_c[0] and jump to RX_ACT_TBL.
4241 * For default flow (zero mark_id), flow is like,
4242 * - If ingress port is ANY,
4243 * reg_b := reg_c[0] and jump to RX_ACT_TBL.
4246 * Pointer to Ethernet device.
4248 * ID of MARK action, zero means default flow for META.
4250 * Perform verbose error reporting if not NULL.
4253 * Associated resource on success, NULL otherwise and rte_errno is set.
4255 static struct mlx5_flow_mreg_copy_resource *
4256 flow_mreg_add_copy_action(struct rte_eth_dev *dev, uint32_t mark_id,
4257 struct rte_flow_error *error)
4259 struct mlx5_priv *priv = dev->data->dev_private;
4260 struct mlx5_list_entry *entry;
4261 struct mlx5_flow_cb_ctx ctx = {
4267 /* Check if already registered. */
4268 MLX5_ASSERT(priv->mreg_cp_tbl);
4269 entry = mlx5_hlist_register(priv->mreg_cp_tbl, mark_id, &ctx);
4272 return container_of(entry, struct mlx5_flow_mreg_copy_resource,
4277 flow_dv_mreg_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
4279 struct mlx5_flow_mreg_copy_resource *mcp_res =
4280 container_of(entry, typeof(*mcp_res), hlist_ent);
4281 struct rte_eth_dev *dev = tool_ctx;
4282 struct mlx5_priv *priv = dev->data->dev_private;
4284 MLX5_ASSERT(mcp_res->rix_flow);
4285 flow_list_destroy(dev, MLX5_FLOW_TYPE_MCP, mcp_res->rix_flow);
4286 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], mcp_res->idx);
4290 * Release flow in RX_CP_TBL.
4293 * Pointer to Ethernet device.
4295 * Parent flow for wich copying is provided.
4298 flow_mreg_del_copy_action(struct rte_eth_dev *dev,
4299 struct rte_flow *flow)
4301 struct mlx5_flow_mreg_copy_resource *mcp_res;
4302 struct mlx5_priv *priv = dev->data->dev_private;
4304 if (!flow->rix_mreg_copy)
4306 mcp_res = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MCP],
4307 flow->rix_mreg_copy);
4308 if (!mcp_res || !priv->mreg_cp_tbl)
4310 MLX5_ASSERT(mcp_res->rix_flow);
4311 mlx5_hlist_unregister(priv->mreg_cp_tbl, &mcp_res->hlist_ent);
4312 flow->rix_mreg_copy = 0;
4316 * Remove the default copy action from RX_CP_TBL.
4318 * This functions is called in the mlx5_dev_start(). No thread safe
4322 * Pointer to Ethernet device.
4325 flow_mreg_del_default_copy_action(struct rte_eth_dev *dev)
4327 struct mlx5_list_entry *entry;
4328 struct mlx5_priv *priv = dev->data->dev_private;
4329 struct mlx5_flow_cb_ctx ctx;
4332 /* Check if default flow is registered. */
4333 if (!priv->mreg_cp_tbl)
4335 mark_id = MLX5_DEFAULT_COPY_ID;
4336 ctx.data = &mark_id;
4337 entry = mlx5_hlist_lookup(priv->mreg_cp_tbl, mark_id, &ctx);
4340 mlx5_hlist_unregister(priv->mreg_cp_tbl, entry);
4344 * Add the default copy action in in RX_CP_TBL.
4346 * This functions is called in the mlx5_dev_start(). No thread safe
4350 * Pointer to Ethernet device.
4352 * Perform verbose error reporting if not NULL.
4355 * 0 for success, negative value otherwise and rte_errno is set.
4358 flow_mreg_add_default_copy_action(struct rte_eth_dev *dev,
4359 struct rte_flow_error *error)
4361 struct mlx5_priv *priv = dev->data->dev_private;
4362 struct mlx5_flow_mreg_copy_resource *mcp_res;
4363 struct mlx5_flow_cb_ctx ctx;
4366 /* Check whether extensive metadata feature is engaged. */
4367 if (!priv->config.dv_flow_en ||
4368 priv->config.dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
4369 !mlx5_flow_ext_mreg_supported(dev) ||
4370 !priv->sh->dv_regc0_mask)
4373 * Add default mreg copy flow may be called multiple time, but
4374 * only be called once in stop. Avoid register it twice.
4376 mark_id = MLX5_DEFAULT_COPY_ID;
4377 ctx.data = &mark_id;
4378 if (mlx5_hlist_lookup(priv->mreg_cp_tbl, mark_id, &ctx))
4380 mcp_res = flow_mreg_add_copy_action(dev, mark_id, error);
4387 * Add a flow of copying flow metadata registers in RX_CP_TBL.
4389 * All the flow having Q/RSS action should be split by
4390 * flow_mreg_split_qrss_prep() to pass by RX_CP_TBL. A flow in the RX_CP_TBL
4391 * performs the following,
4392 * - CQE->flow_tag := reg_c[1] (MARK)
4393 * - CQE->flow_table_metadata (reg_b) := reg_c[0] (META)
4394 * As CQE's flow_tag is not a register, it can't be simply copied from reg_c[1]
4395 * but there should be a flow per each MARK ID set by MARK action.
4397 * For the aforementioned reason, if there's a MARK action in flow's action
4398 * list, a corresponding flow should be added to the RX_CP_TBL in order to copy
4399 * the MARK ID to CQE's flow_tag like,
4400 * - If reg_c[1] is mark_id,
4401 * flow_tag := mark_id, reg_b := reg_c[0] and jump to RX_ACT_TBL.
4403 * For SET_META action which stores value in reg_c[0], as the destination is
4404 * also a flow metadata register (reg_b), adding a default flow is enough. Zero
4405 * MARK ID means the default flow. The default flow looks like,
4406 * - For all flow, reg_b := reg_c[0] and jump to RX_ACT_TBL.
4409 * Pointer to Ethernet device.
4411 * Pointer to flow structure.
4412 * @param[in] actions
4413 * Pointer to the list of actions.
4415 * Perform verbose error reporting if not NULL.
4418 * 0 on success, negative value otherwise and rte_errno is set.
4421 flow_mreg_update_copy_table(struct rte_eth_dev *dev,
4422 struct rte_flow *flow,
4423 const struct rte_flow_action *actions,
4424 struct rte_flow_error *error)
4426 struct mlx5_priv *priv = dev->data->dev_private;
4427 struct mlx5_dev_config *config = &priv->config;
4428 struct mlx5_flow_mreg_copy_resource *mcp_res;
4429 const struct rte_flow_action_mark *mark;
4431 /* Check whether extensive metadata feature is engaged. */
4432 if (!config->dv_flow_en ||
4433 config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
4434 !mlx5_flow_ext_mreg_supported(dev) ||
4435 !priv->sh->dv_regc0_mask)
4437 /* Find MARK action. */
4438 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4439 switch (actions->type) {
4440 case RTE_FLOW_ACTION_TYPE_FLAG:
4441 mcp_res = flow_mreg_add_copy_action
4442 (dev, MLX5_FLOW_MARK_DEFAULT, error);
4445 flow->rix_mreg_copy = mcp_res->idx;
4447 case RTE_FLOW_ACTION_TYPE_MARK:
4448 mark = (const struct rte_flow_action_mark *)
4451 flow_mreg_add_copy_action(dev, mark->id, error);
4454 flow->rix_mreg_copy = mcp_res->idx;
4463 #define MLX5_MAX_SPLIT_ACTIONS 24
4464 #define MLX5_MAX_SPLIT_ITEMS 24
4467 * Split the hairpin flow.
4468 * Since HW can't support encap and push-vlan on Rx, we move these
4470 * If the count action is after the encap then we also
4471 * move the count action. in this case the count will also measure
4475 * Pointer to Ethernet device.
4476 * @param[in] actions
4477 * Associated actions (list terminated by the END action).
4478 * @param[out] actions_rx
4480 * @param[out] actions_tx
4482 * @param[out] pattern_tx
4483 * The pattern items for the Tx flow.
4484 * @param[out] flow_id
4485 * The flow ID connected to this flow.
4491 flow_hairpin_split(struct rte_eth_dev *dev,
4492 const struct rte_flow_action actions[],
4493 struct rte_flow_action actions_rx[],
4494 struct rte_flow_action actions_tx[],
4495 struct rte_flow_item pattern_tx[],
4498 const struct rte_flow_action_raw_encap *raw_encap;
4499 const struct rte_flow_action_raw_decap *raw_decap;
4500 struct mlx5_rte_flow_action_set_tag *set_tag;
4501 struct rte_flow_action *tag_action;
4502 struct mlx5_rte_flow_item_tag *tag_item;
4503 struct rte_flow_item *item;
4507 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4508 switch (actions->type) {
4509 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
4510 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
4511 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
4512 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
4513 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
4514 rte_memcpy(actions_tx, actions,
4515 sizeof(struct rte_flow_action));
4518 case RTE_FLOW_ACTION_TYPE_COUNT:
4520 rte_memcpy(actions_tx, actions,
4521 sizeof(struct rte_flow_action));
4524 rte_memcpy(actions_rx, actions,
4525 sizeof(struct rte_flow_action));
4529 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
4530 raw_encap = actions->conf;
4531 if (raw_encap->size > MLX5_ENCAPSULATION_DECISION_SIZE) {
4532 memcpy(actions_tx, actions,
4533 sizeof(struct rte_flow_action));
4537 rte_memcpy(actions_rx, actions,
4538 sizeof(struct rte_flow_action));
4542 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
4543 raw_decap = actions->conf;
4544 if (raw_decap->size < MLX5_ENCAPSULATION_DECISION_SIZE) {
4545 memcpy(actions_tx, actions,
4546 sizeof(struct rte_flow_action));
4549 rte_memcpy(actions_rx, actions,
4550 sizeof(struct rte_flow_action));
4555 rte_memcpy(actions_rx, actions,
4556 sizeof(struct rte_flow_action));
4561 /* Add set meta action and end action for the Rx flow. */
4562 tag_action = actions_rx;
4563 tag_action->type = (enum rte_flow_action_type)
4564 MLX5_RTE_FLOW_ACTION_TYPE_TAG;
4566 rte_memcpy(actions_rx, actions, sizeof(struct rte_flow_action));
4568 set_tag = (void *)actions_rx;
4569 *set_tag = (struct mlx5_rte_flow_action_set_tag) {
4570 .id = mlx5_flow_get_reg_id(dev, MLX5_HAIRPIN_RX, 0, NULL),
4573 MLX5_ASSERT(set_tag->id > REG_NON);
4574 tag_action->conf = set_tag;
4575 /* Create Tx item list. */
4576 rte_memcpy(actions_tx, actions, sizeof(struct rte_flow_action));
4577 addr = (void *)&pattern_tx[2];
4579 item->type = (enum rte_flow_item_type)
4580 MLX5_RTE_FLOW_ITEM_TYPE_TAG;
4581 tag_item = (void *)addr;
4582 tag_item->data = flow_id;
4583 tag_item->id = mlx5_flow_get_reg_id(dev, MLX5_HAIRPIN_TX, 0, NULL);
4584 MLX5_ASSERT(set_tag->id > REG_NON);
4585 item->spec = tag_item;
4586 addr += sizeof(struct mlx5_rte_flow_item_tag);
4587 tag_item = (void *)addr;
4588 tag_item->data = UINT32_MAX;
4589 tag_item->id = UINT16_MAX;
4590 item->mask = tag_item;
4593 item->type = RTE_FLOW_ITEM_TYPE_END;
4598 * The last stage of splitting chain, just creates the subflow
4599 * without any modification.
4602 * Pointer to Ethernet device.
4604 * Parent flow structure pointer.
4605 * @param[in, out] sub_flow
4606 * Pointer to return the created subflow, may be NULL.
4608 * Flow rule attributes.
4610 * Pattern specification (list terminated by the END pattern item).
4611 * @param[in] actions
4612 * Associated actions (list terminated by the END action).
4613 * @param[in] flow_split_info
4614 * Pointer to flow split info structure.
4616 * Perform verbose error reporting if not NULL.
4618 * 0 on success, negative value otherwise
4621 flow_create_split_inner(struct rte_eth_dev *dev,
4622 struct rte_flow *flow,
4623 struct mlx5_flow **sub_flow,
4624 const struct rte_flow_attr *attr,
4625 const struct rte_flow_item items[],
4626 const struct rte_flow_action actions[],
4627 struct mlx5_flow_split_info *flow_split_info,
4628 struct rte_flow_error *error)
4630 struct mlx5_flow *dev_flow;
4632 dev_flow = flow_drv_prepare(dev, flow, attr, items, actions,
4633 flow_split_info->flow_idx, error);
4636 dev_flow->flow = flow;
4637 dev_flow->external = flow_split_info->external;
4638 dev_flow->skip_scale = flow_split_info->skip_scale;
4639 /* Subflow object was created, we must include one in the list. */
4640 SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
4641 dev_flow->handle, next);
4643 * If dev_flow is as one of the suffix flow, some actions in suffix
4644 * flow may need some user defined item layer flags, and pass the
4645 * Metadate rxq mark flag to suffix flow as well.
4647 if (flow_split_info->prefix_layers)
4648 dev_flow->handle->layers = flow_split_info->prefix_layers;
4649 if (flow_split_info->prefix_mark)
4650 dev_flow->handle->mark = 1;
4652 *sub_flow = dev_flow;
4653 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
4654 dev_flow->dv.table_id = flow_split_info->table_id;
4656 return flow_drv_translate(dev, dev_flow, attr, items, actions, error);
4660 * Get the sub policy of a meter.
4663 * Pointer to Ethernet device.
4665 * Parent flow structure pointer.
4667 * Pointer to thread flow work space.
4669 * Flow rule attributes.
4671 * Pattern specification (list terminated by the END pattern item).
4673 * Perform verbose error reporting if not NULL.
4676 * Pointer to the meter sub policy, NULL otherwise and rte_errno is set.
4678 static struct mlx5_flow_meter_sub_policy *
4679 get_meter_sub_policy(struct rte_eth_dev *dev,
4680 struct rte_flow *flow,
4681 struct mlx5_flow_workspace *wks,
4682 const struct rte_flow_attr *attr,
4683 const struct rte_flow_item items[],
4684 struct rte_flow_error *error)
4686 struct mlx5_flow_meter_policy *policy;
4687 struct mlx5_flow_meter_policy *final_policy;
4688 struct mlx5_flow_meter_sub_policy *sub_policy = NULL;
4690 policy = wks->policy;
4691 final_policy = policy->is_hierarchy ? wks->final_policy : policy;
4692 if (final_policy->is_rss || final_policy->is_queue) {
4693 struct mlx5_flow_rss_desc rss_desc_v[MLX5_MTR_RTE_COLORS];
4694 struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS] = {0};
4698 * This is a tmp dev_flow,
4699 * no need to register any matcher for it in translate.
4701 wks->skip_matcher_reg = 1;
4702 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
4703 struct mlx5_flow dev_flow = {0};
4704 struct mlx5_flow_handle dev_handle = { {0} };
4705 uint8_t fate = final_policy->act_cnt[i].fate_action;
4707 if (fate == MLX5_FLOW_FATE_SHARED_RSS) {
4708 const void *rss_act =
4709 final_policy->act_cnt[i].rss->conf;
4710 struct rte_flow_action rss_actions[2] = {
4712 .type = RTE_FLOW_ACTION_TYPE_RSS,
4716 .type = RTE_FLOW_ACTION_TYPE_END,
4721 dev_flow.handle = &dev_handle;
4722 dev_flow.ingress = attr->ingress;
4723 dev_flow.flow = flow;
4724 dev_flow.external = 0;
4725 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
4726 dev_flow.dv.transfer = attr->transfer;
4729 * Translate RSS action to get rss hash fields.
4731 if (flow_drv_translate(dev, &dev_flow, attr,
4732 items, rss_actions, error))
4734 rss_desc_v[i] = wks->rss_desc;
4735 rss_desc_v[i].key_len = MLX5_RSS_HASH_KEY_LEN;
4736 rss_desc_v[i].hash_fields =
4737 dev_flow.hash_fields;
4738 rss_desc_v[i].queue_num =
4739 rss_desc_v[i].hash_fields ?
4740 rss_desc_v[i].queue_num : 1;
4741 rss_desc_v[i].tunnel =
4742 !!(dev_flow.handle->layers &
4743 MLX5_FLOW_LAYER_TUNNEL);
4744 rss_desc[i] = &rss_desc_v[i];
4745 } else if (fate == MLX5_FLOW_FATE_QUEUE) {
4746 /* This is queue action. */
4747 rss_desc_v[i] = wks->rss_desc;
4748 rss_desc_v[i].key_len = 0;
4749 rss_desc_v[i].hash_fields = 0;
4750 rss_desc_v[i].queue =
4751 &final_policy->act_cnt[i].queue;
4752 rss_desc_v[i].queue_num = 1;
4753 rss_desc[i] = &rss_desc_v[i];
4758 sub_policy = flow_drv_meter_sub_policy_rss_prepare(dev,
4759 flow, policy, rss_desc);
4761 enum mlx5_meter_domain mtr_domain =
4762 attr->transfer ? MLX5_MTR_DOMAIN_TRANSFER :
4763 (attr->egress ? MLX5_MTR_DOMAIN_EGRESS :
4764 MLX5_MTR_DOMAIN_INGRESS);
4765 sub_policy = policy->sub_policys[mtr_domain][0];
4768 rte_flow_error_set(error, EINVAL,
4769 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4770 "Failed to get meter sub-policy.");
4776 * Split the meter flow.
4778 * As meter flow will split to three sub flow, other than meter
4779 * action, the other actions make sense to only meter accepts
4780 * the packet. If it need to be dropped, no other additional
4781 * actions should be take.
4783 * One kind of special action which decapsulates the L3 tunnel
4784 * header will be in the prefix sub flow, as not to take the
4785 * L3 tunnel header into account.
4788 * Pointer to Ethernet device.
4790 * Parent flow structure pointer.
4792 * Pointer to thread flow work space.
4794 * Flow rule attributes.
4796 * Pattern specification (list terminated by the END pattern item).
4797 * @param[out] sfx_items
4798 * Suffix flow match items (list terminated by the END pattern item).
4799 * @param[in] actions
4800 * Associated actions (list terminated by the END action).
4801 * @param[out] actions_sfx
4802 * Suffix flow actions.
4803 * @param[out] actions_pre
4804 * Prefix flow actions.
4805 * @param[out] mtr_flow_id
4806 * Pointer to meter flow id.
4808 * Perform verbose error reporting if not NULL.
4811 * 0 on success, a negative errno value otherwise and rte_errno is set.
4814 flow_meter_split_prep(struct rte_eth_dev *dev,
4815 struct rte_flow *flow,
4816 struct mlx5_flow_workspace *wks,
4817 const struct rte_flow_attr *attr,
4818 const struct rte_flow_item items[],
4819 struct rte_flow_item sfx_items[],
4820 const struct rte_flow_action actions[],
4821 struct rte_flow_action actions_sfx[],
4822 struct rte_flow_action actions_pre[],
4823 uint32_t *mtr_flow_id,
4824 struct rte_flow_error *error)
4826 struct mlx5_priv *priv = dev->data->dev_private;
4827 struct mlx5_flow_meter_info *fm = wks->fm;
4828 struct rte_flow_action *tag_action = NULL;
4829 struct rte_flow_item *tag_item;
4830 struct mlx5_rte_flow_action_set_tag *set_tag;
4831 const struct rte_flow_action_raw_encap *raw_encap;
4832 const struct rte_flow_action_raw_decap *raw_decap;
4833 struct mlx5_rte_flow_item_tag *tag_item_spec;
4834 struct mlx5_rte_flow_item_tag *tag_item_mask;
4835 uint32_t tag_id = 0;
4836 struct rte_flow_item *vlan_item_dst = NULL;
4837 const struct rte_flow_item *vlan_item_src = NULL;
4838 struct rte_flow_action *hw_mtr_action;
4839 struct rte_flow_action *action_pre_head = NULL;
4840 int32_t flow_src_port = priv->representor_id;
4842 uint8_t mtr_id_offset = priv->mtr_reg_share ? MLX5_MTR_COLOR_BITS : 0;
4843 uint8_t mtr_reg_bits = priv->mtr_reg_share ?
4844 MLX5_MTR_IDLE_BITS_IN_COLOR_REG : MLX5_REG_BITS;
4845 uint32_t flow_id = 0;
4846 uint32_t flow_id_reversed = 0;
4847 uint8_t flow_id_bits = 0;
4850 /* Prepare the suffix subflow items. */
4851 tag_item = sfx_items++;
4852 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
4853 struct mlx5_priv *port_priv;
4854 const struct rte_flow_item_port_id *pid_v;
4855 int item_type = items->type;
4857 switch (item_type) {
4858 case RTE_FLOW_ITEM_TYPE_PORT_ID:
4859 pid_v = items->spec;
4861 port_priv = mlx5_port_to_eswitch_info(pid_v->id, false);
4863 return rte_flow_error_set(error,
4865 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
4867 "Failed to get port info.");
4868 flow_src_port = port_priv->representor_id;
4869 if (!fm->def_policy && wks->policy->is_hierarchy &&
4870 flow_src_port != priv->representor_id) {
4871 if (flow_drv_mtr_hierarchy_rule_create(dev,
4878 memcpy(sfx_items, items, sizeof(*sfx_items));
4881 case RTE_FLOW_ITEM_TYPE_VLAN:
4882 /* Determine if copy vlan item below. */
4883 vlan_item_src = items;
4884 vlan_item_dst = sfx_items++;
4885 vlan_item_dst->type = RTE_FLOW_ITEM_TYPE_VOID;
4891 sfx_items->type = RTE_FLOW_ITEM_TYPE_END;
4893 mtr_first = priv->sh->meter_aso_en &&
4894 (attr->egress || (attr->transfer && flow_src_port != UINT16_MAX));
4895 /* For ASO meter, meter must be before tag in TX direction. */
4897 action_pre_head = actions_pre++;
4898 /* Leave space for tag action. */
4899 tag_action = actions_pre++;
4901 /* Prepare the actions for prefix and suffix flow. */
4902 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4903 struct rte_flow_action *action_cur = NULL;
4905 switch (actions->type) {
4906 case RTE_FLOW_ACTION_TYPE_METER:
4908 action_cur = action_pre_head;
4910 /* Leave space for tag action. */
4911 tag_action = actions_pre++;
4912 action_cur = actions_pre++;
4915 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
4916 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
4917 action_cur = actions_pre++;
4919 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
4920 raw_encap = actions->conf;
4921 if (raw_encap->size < MLX5_ENCAPSULATION_DECISION_SIZE)
4922 action_cur = actions_pre++;
4924 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
4925 raw_decap = actions->conf;
4926 if (raw_decap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
4927 action_cur = actions_pre++;
4929 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
4930 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
4931 if (vlan_item_dst && vlan_item_src) {
4932 memcpy(vlan_item_dst, vlan_item_src,
4933 sizeof(*vlan_item_dst));
4935 * Convert to internal match item, it is used
4936 * for vlan push and set vid.
4938 vlan_item_dst->type = (enum rte_flow_item_type)
4939 MLX5_RTE_FLOW_ITEM_TYPE_VLAN;
4946 action_cur = (fm->def_policy) ?
4947 actions_sfx++ : actions_pre++;
4948 memcpy(action_cur, actions, sizeof(struct rte_flow_action));
4950 /* Add end action to the actions. */
4951 actions_sfx->type = RTE_FLOW_ACTION_TYPE_END;
4952 if (priv->sh->meter_aso_en) {
4954 * For ASO meter, need to add an extra jump action explicitly,
4955 * to jump from meter to policer table.
4957 struct mlx5_flow_meter_sub_policy *sub_policy;
4958 struct mlx5_flow_tbl_data_entry *tbl_data;
4960 if (!fm->def_policy) {
4961 sub_policy = get_meter_sub_policy(dev, flow, wks,
4962 attr, items, error);
4966 enum mlx5_meter_domain mtr_domain =
4967 attr->transfer ? MLX5_MTR_DOMAIN_TRANSFER :
4968 (attr->egress ? MLX5_MTR_DOMAIN_EGRESS :
4969 MLX5_MTR_DOMAIN_INGRESS);
4972 &priv->sh->mtrmng->def_policy[mtr_domain]->sub_policy;
4974 tbl_data = container_of(sub_policy->tbl_rsc,
4975 struct mlx5_flow_tbl_data_entry, tbl);
4976 hw_mtr_action = actions_pre++;
4977 hw_mtr_action->type = (enum rte_flow_action_type)
4978 MLX5_RTE_FLOW_ACTION_TYPE_JUMP;
4979 hw_mtr_action->conf = tbl_data->jump.action;
4981 actions_pre->type = RTE_FLOW_ACTION_TYPE_END;
4984 return rte_flow_error_set(error, ENOMEM,
4985 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
4986 NULL, "No tag action space.");
4988 tag_action->type = RTE_FLOW_ACTION_TYPE_VOID;
4991 /* Only default-policy Meter creates mtr flow id. */
4992 if (fm->def_policy) {
4993 mlx5_ipool_malloc(fm->flow_ipool, &tag_id);
4995 return rte_flow_error_set(error, ENOMEM,
4996 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4997 "Failed to allocate meter flow id.");
4998 flow_id = tag_id - 1;
4999 flow_id_bits = (!flow_id) ? 1 :
5000 (MLX5_REG_BITS - __builtin_clz(flow_id));
5001 if ((flow_id_bits + priv->sh->mtrmng->max_mtr_bits) >
5003 mlx5_ipool_free(fm->flow_ipool, tag_id);
5004 return rte_flow_error_set(error, EINVAL,
5005 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
5006 "Meter flow id exceeds max limit.");
5008 if (flow_id_bits > priv->sh->mtrmng->max_mtr_flow_bits)
5009 priv->sh->mtrmng->max_mtr_flow_bits = flow_id_bits;
5011 /* Build tag actions and items for meter_id/meter flow_id. */
5012 set_tag = (struct mlx5_rte_flow_action_set_tag *)actions_pre;
5013 tag_item_spec = (struct mlx5_rte_flow_item_tag *)sfx_items;
5014 tag_item_mask = tag_item_spec + 1;
5015 /* Both flow_id and meter_id share the same register. */
5016 *set_tag = (struct mlx5_rte_flow_action_set_tag) {
5017 .id = (enum modify_reg)mlx5_flow_get_reg_id(dev, MLX5_MTR_ID,
5019 .offset = mtr_id_offset,
5020 .length = mtr_reg_bits,
5021 .data = flow->meter,
5024 * The color Reg bits used by flow_id are growing from
5025 * msb to lsb, so must do bit reverse for flow_id val in RegC.
5027 for (shift = 0; shift < flow_id_bits; shift++)
5028 flow_id_reversed = (flow_id_reversed << 1) |
5029 ((flow_id >> shift) & 0x1);
5031 flow_id_reversed << (mtr_reg_bits - flow_id_bits);
5032 tag_item_spec->id = set_tag->id;
5033 tag_item_spec->data = set_tag->data << mtr_id_offset;
5034 tag_item_mask->data = UINT32_MAX << mtr_id_offset;
5035 tag_action->type = (enum rte_flow_action_type)
5036 MLX5_RTE_FLOW_ACTION_TYPE_TAG;
5037 tag_action->conf = set_tag;
5038 tag_item->type = (enum rte_flow_item_type)
5039 MLX5_RTE_FLOW_ITEM_TYPE_TAG;
5040 tag_item->spec = tag_item_spec;
5041 tag_item->last = NULL;
5042 tag_item->mask = tag_item_mask;
5045 *mtr_flow_id = tag_id;
5050 * Split action list having QUEUE/RSS for metadata register copy.
5052 * Once Q/RSS action is detected in user's action list, the flow action
5053 * should be split in order to copy metadata registers, which will happen in
5055 * - CQE->flow_tag := reg_c[1] (MARK)
5056 * - CQE->flow_table_metadata (reg_b) := reg_c[0] (META)
5057 * The Q/RSS action will be performed on RX_ACT_TBL after passing by RX_CP_TBL.
5058 * This is because the last action of each flow must be a terminal action
5059 * (QUEUE, RSS or DROP).
5061 * Flow ID must be allocated to identify actions in the RX_ACT_TBL and it is
5062 * stored and kept in the mlx5_flow structure per each sub_flow.
5064 * The Q/RSS action is replaced with,
5065 * - SET_TAG, setting the allocated flow ID to reg_c[2].
5066 * And the following JUMP action is added at the end,
5067 * - JUMP, to RX_CP_TBL.
5069 * A flow to perform remained Q/RSS action will be created in RX_ACT_TBL by
5070 * flow_create_split_metadata() routine. The flow will look like,
5071 * - If flow ID matches (reg_c[2]), perform Q/RSS.
5074 * Pointer to Ethernet device.
5075 * @param[out] split_actions
5076 * Pointer to store split actions to jump to CP_TBL.
5077 * @param[in] actions
5078 * Pointer to the list of original flow actions.
5080 * Pointer to the Q/RSS action.
5081 * @param[in] actions_n
5082 * Number of original actions.
5084 * Perform verbose error reporting if not NULL.
5087 * non-zero unique flow_id on success, otherwise 0 and
5088 * error/rte_error are set.
5091 flow_mreg_split_qrss_prep(struct rte_eth_dev *dev,
5092 struct rte_flow_action *split_actions,
5093 const struct rte_flow_action *actions,
5094 const struct rte_flow_action *qrss,
5095 int actions_n, struct rte_flow_error *error)
5097 struct mlx5_priv *priv = dev->data->dev_private;
5098 struct mlx5_rte_flow_action_set_tag *set_tag;
5099 struct rte_flow_action_jump *jump;
5100 const int qrss_idx = qrss - actions;
5101 uint32_t flow_id = 0;
5105 * Given actions will be split
5106 * - Replace QUEUE/RSS action with SET_TAG to set flow ID.
5107 * - Add jump to mreg CP_TBL.
5108 * As a result, there will be one more action.
5111 memcpy(split_actions, actions, sizeof(*split_actions) * actions_n);
5112 set_tag = (void *)(split_actions + actions_n);
5114 * If tag action is not set to void(it means we are not the meter
5115 * suffix flow), add the tag action. Since meter suffix flow already
5116 * has the tag added.
5118 if (split_actions[qrss_idx].type != RTE_FLOW_ACTION_TYPE_VOID) {
5120 * Allocate the new subflow ID. This one is unique within
5121 * device and not shared with representors. Otherwise,
5122 * we would have to resolve multi-thread access synch
5123 * issue. Each flow on the shared device is appended
5124 * with source vport identifier, so the resulting
5125 * flows will be unique in the shared (by master and
5126 * representors) domain even if they have coinciding
5129 mlx5_ipool_malloc(priv->sh->ipool
5130 [MLX5_IPOOL_RSS_EXPANTION_FLOW_ID], &flow_id);
5132 return rte_flow_error_set(error, ENOMEM,
5133 RTE_FLOW_ERROR_TYPE_ACTION,
5134 NULL, "can't allocate id "
5135 "for split Q/RSS subflow");
5136 /* Internal SET_TAG action to set flow ID. */
5137 *set_tag = (struct mlx5_rte_flow_action_set_tag){
5140 ret = mlx5_flow_get_reg_id(dev, MLX5_COPY_MARK, 0, error);
5144 /* Construct new actions array. */
5145 /* Replace QUEUE/RSS action. */
5146 split_actions[qrss_idx] = (struct rte_flow_action){
5147 .type = (enum rte_flow_action_type)
5148 MLX5_RTE_FLOW_ACTION_TYPE_TAG,
5152 /* JUMP action to jump to mreg copy table (CP_TBL). */
5153 jump = (void *)(set_tag + 1);
5154 *jump = (struct rte_flow_action_jump){
5155 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
5157 split_actions[actions_n - 2] = (struct rte_flow_action){
5158 .type = RTE_FLOW_ACTION_TYPE_JUMP,
5161 split_actions[actions_n - 1] = (struct rte_flow_action){
5162 .type = RTE_FLOW_ACTION_TYPE_END,
5168 * Extend the given action list for Tx metadata copy.
5170 * Copy the given action list to the ext_actions and add flow metadata register
5171 * copy action in order to copy reg_a set by WQE to reg_c[0].
5173 * @param[out] ext_actions
5174 * Pointer to the extended action list.
5175 * @param[in] actions
5176 * Pointer to the list of actions.
5177 * @param[in] actions_n
5178 * Number of actions in the list.
5180 * Perform verbose error reporting if not NULL.
5181 * @param[in] encap_idx
5182 * The encap action inndex.
5185 * 0 on success, negative value otherwise
5188 flow_mreg_tx_copy_prep(struct rte_eth_dev *dev,
5189 struct rte_flow_action *ext_actions,
5190 const struct rte_flow_action *actions,
5191 int actions_n, struct rte_flow_error *error,
5194 struct mlx5_flow_action_copy_mreg *cp_mreg =
5195 (struct mlx5_flow_action_copy_mreg *)
5196 (ext_actions + actions_n + 1);
5199 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_RX, 0, error);
5203 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_TX, 0, error);
5208 memcpy(ext_actions, actions, sizeof(*ext_actions) * encap_idx);
5209 if (encap_idx == actions_n - 1) {
5210 ext_actions[actions_n - 1] = (struct rte_flow_action){
5211 .type = (enum rte_flow_action_type)
5212 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
5215 ext_actions[actions_n] = (struct rte_flow_action){
5216 .type = RTE_FLOW_ACTION_TYPE_END,
5219 ext_actions[encap_idx] = (struct rte_flow_action){
5220 .type = (enum rte_flow_action_type)
5221 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
5224 memcpy(ext_actions + encap_idx + 1, actions + encap_idx,
5225 sizeof(*ext_actions) * (actions_n - encap_idx));
5231 * Check the match action from the action list.
5233 * @param[in] actions
5234 * Pointer to the list of actions.
5236 * Flow rule attributes.
5238 * The action to be check if exist.
5239 * @param[out] match_action_pos
5240 * Pointer to the position of the matched action if exists, otherwise is -1.
5241 * @param[out] qrss_action_pos
5242 * Pointer to the position of the Queue/RSS action if exists, otherwise is -1.
5243 * @param[out] modify_after_mirror
5244 * Pointer to the flag of modify action after FDB mirroring.
5247 * > 0 the total number of actions.
5248 * 0 if not found match action in action list.
5251 flow_check_match_action(const struct rte_flow_action actions[],
5252 const struct rte_flow_attr *attr,
5253 enum rte_flow_action_type action,
5254 int *match_action_pos, int *qrss_action_pos,
5255 int *modify_after_mirror)
5257 const struct rte_flow_action_sample *sample;
5264 *match_action_pos = -1;
5265 *qrss_action_pos = -1;
5266 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
5267 if (actions->type == action) {
5269 *match_action_pos = actions_n;
5271 switch (actions->type) {
5272 case RTE_FLOW_ACTION_TYPE_QUEUE:
5273 case RTE_FLOW_ACTION_TYPE_RSS:
5274 *qrss_action_pos = actions_n;
5276 case RTE_FLOW_ACTION_TYPE_SAMPLE:
5277 sample = actions->conf;
5278 ratio = sample->ratio;
5279 sub_type = ((const struct rte_flow_action *)
5280 (sample->actions))->type;
5281 if (ratio == 1 && attr->transfer)
5284 case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
5285 case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
5286 case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
5287 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
5288 case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
5289 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
5290 case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
5291 case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
5292 case RTE_FLOW_ACTION_TYPE_DEC_TTL:
5293 case RTE_FLOW_ACTION_TYPE_SET_TTL:
5294 case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
5295 case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
5296 case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
5297 case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
5298 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
5299 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
5300 case RTE_FLOW_ACTION_TYPE_FLAG:
5301 case RTE_FLOW_ACTION_TYPE_MARK:
5302 case RTE_FLOW_ACTION_TYPE_SET_META:
5303 case RTE_FLOW_ACTION_TYPE_SET_TAG:
5304 case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
5305 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
5306 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
5307 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
5308 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
5309 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
5310 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
5311 case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
5312 case RTE_FLOW_ACTION_TYPE_METER:
5314 *modify_after_mirror = 1;
5321 if (flag && fdb_mirror && !*modify_after_mirror) {
5322 /* FDB mirroring uses the destination array to implement
5323 * instead of FLOW_SAMPLER object.
5325 if (sub_type != RTE_FLOW_ACTION_TYPE_END)
5328 /* Count RTE_FLOW_ACTION_TYPE_END. */
5329 return flag ? actions_n + 1 : 0;
5332 #define SAMPLE_SUFFIX_ITEM 2
5335 * Split the sample flow.
5337 * As sample flow will split to two sub flow, sample flow with
5338 * sample action, the other actions will move to new suffix flow.
5340 * Also add unique tag id with tag action in the sample flow,
5341 * the same tag id will be as match in the suffix flow.
5344 * Pointer to Ethernet device.
5345 * @param[in] add_tag
5346 * Add extra tag action flag.
5347 * @param[out] sfx_items
5348 * Suffix flow match items (list terminated by the END pattern item).
5349 * @param[in] actions
5350 * Associated actions (list terminated by the END action).
5351 * @param[out] actions_sfx
5352 * Suffix flow actions.
5353 * @param[out] actions_pre
5354 * Prefix flow actions.
5355 * @param[in] actions_n
5356 * The total number of actions.
5357 * @param[in] sample_action_pos
5358 * The sample action position.
5359 * @param[in] qrss_action_pos
5360 * The Queue/RSS action position.
5361 * @param[in] jump_table
5362 * Add extra jump action flag.
5364 * Perform verbose error reporting if not NULL.
5367 * 0 on success, or unique flow_id, a negative errno value
5368 * otherwise and rte_errno is set.
5371 flow_sample_split_prep(struct rte_eth_dev *dev,
5373 struct rte_flow_item sfx_items[],
5374 const struct rte_flow_action actions[],
5375 struct rte_flow_action actions_sfx[],
5376 struct rte_flow_action actions_pre[],
5378 int sample_action_pos,
5379 int qrss_action_pos,
5381 struct rte_flow_error *error)
5383 struct mlx5_priv *priv = dev->data->dev_private;
5384 struct mlx5_rte_flow_action_set_tag *set_tag;
5385 struct mlx5_rte_flow_item_tag *tag_spec;
5386 struct mlx5_rte_flow_item_tag *tag_mask;
5387 struct rte_flow_action_jump *jump_action;
5388 uint32_t tag_id = 0;
5390 int append_index = 0;
5393 if (sample_action_pos < 0)
5394 return rte_flow_error_set(error, EINVAL,
5395 RTE_FLOW_ERROR_TYPE_ACTION,
5396 NULL, "invalid position of sample "
5398 /* Prepare the actions for prefix and suffix flow. */
5399 if (qrss_action_pos >= 0 && qrss_action_pos < sample_action_pos) {
5400 index = qrss_action_pos;
5401 /* Put the preceding the Queue/RSS action into prefix flow. */
5403 memcpy(actions_pre, actions,
5404 sizeof(struct rte_flow_action) * index);
5405 /* Put others preceding the sample action into prefix flow. */
5406 if (sample_action_pos > index + 1)
5407 memcpy(actions_pre + index, actions + index + 1,
5408 sizeof(struct rte_flow_action) *
5409 (sample_action_pos - index - 1));
5410 index = sample_action_pos - 1;
5411 /* Put Queue/RSS action into Suffix flow. */
5412 memcpy(actions_sfx, actions + qrss_action_pos,
5413 sizeof(struct rte_flow_action));
5416 index = sample_action_pos;
5418 memcpy(actions_pre, actions,
5419 sizeof(struct rte_flow_action) * index);
5421 /* For CX5, add an extra tag action for NIC-RX and E-Switch ingress.
5422 * For CX6DX and above, metadata registers Cx preserve their value,
5423 * add an extra tag action for NIC-RX and E-Switch Domain.
5426 /* Prepare the prefix tag action. */
5428 set_tag = (void *)(actions_pre + actions_n + append_index);
5429 ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, 0, error);
5432 mlx5_ipool_malloc(priv->sh->ipool
5433 [MLX5_IPOOL_RSS_EXPANTION_FLOW_ID], &tag_id);
5434 *set_tag = (struct mlx5_rte_flow_action_set_tag) {
5438 /* Prepare the suffix subflow items. */
5439 tag_spec = (void *)(sfx_items + SAMPLE_SUFFIX_ITEM);
5440 tag_spec->data = tag_id;
5441 tag_spec->id = set_tag->id;
5442 tag_mask = tag_spec + 1;
5443 tag_mask->data = UINT32_MAX;
5444 sfx_items[0] = (struct rte_flow_item){
5445 .type = (enum rte_flow_item_type)
5446 MLX5_RTE_FLOW_ITEM_TYPE_TAG,
5451 sfx_items[1] = (struct rte_flow_item){
5452 .type = (enum rte_flow_item_type)
5453 RTE_FLOW_ITEM_TYPE_END,
5455 /* Prepare the tag action in prefix subflow. */
5456 actions_pre[index++] =
5457 (struct rte_flow_action){
5458 .type = (enum rte_flow_action_type)
5459 MLX5_RTE_FLOW_ACTION_TYPE_TAG,
5463 memcpy(actions_pre + index, actions + sample_action_pos,
5464 sizeof(struct rte_flow_action));
5466 /* For the modify action after the sample action in E-Switch mirroring,
5467 * Add the extra jump action in prefix subflow and jump into the next
5468 * table, then do the modify action in the new table.
5471 /* Prepare the prefix jump action. */
5473 jump_action = (void *)(actions_pre + actions_n + append_index);
5474 jump_action->group = jump_table;
5475 actions_pre[index++] =
5476 (struct rte_flow_action){
5477 .type = (enum rte_flow_action_type)
5478 RTE_FLOW_ACTION_TYPE_JUMP,
5479 .conf = jump_action,
5482 actions_pre[index] = (struct rte_flow_action){
5483 .type = (enum rte_flow_action_type)
5484 RTE_FLOW_ACTION_TYPE_END,
5486 /* Put the actions after sample into Suffix flow. */
5487 memcpy(actions_sfx, actions + sample_action_pos + 1,
5488 sizeof(struct rte_flow_action) *
5489 (actions_n - sample_action_pos - 1));
5494 * The splitting for metadata feature.
5496 * - Q/RSS action on NIC Rx should be split in order to pass by
5497 * the mreg copy table (RX_CP_TBL) and then it jumps to the
5498 * action table (RX_ACT_TBL) which has the split Q/RSS action.
5500 * - All the actions on NIC Tx should have a mreg copy action to
5501 * copy reg_a from WQE to reg_c[0].
5504 * Pointer to Ethernet device.
5506 * Parent flow structure pointer.
5508 * Flow rule attributes.
5510 * Pattern specification (list terminated by the END pattern item).
5511 * @param[in] actions
5512 * Associated actions (list terminated by the END action).
5513 * @param[in] flow_split_info
5514 * Pointer to flow split info structure.
5516 * Perform verbose error reporting if not NULL.
5518 * 0 on success, negative value otherwise
5521 flow_create_split_metadata(struct rte_eth_dev *dev,
5522 struct rte_flow *flow,
5523 const struct rte_flow_attr *attr,
5524 const struct rte_flow_item items[],
5525 const struct rte_flow_action actions[],
5526 struct mlx5_flow_split_info *flow_split_info,
5527 struct rte_flow_error *error)
5529 struct mlx5_priv *priv = dev->data->dev_private;
5530 struct mlx5_dev_config *config = &priv->config;
5531 const struct rte_flow_action *qrss = NULL;
5532 struct rte_flow_action *ext_actions = NULL;
5533 struct mlx5_flow *dev_flow = NULL;
5534 uint32_t qrss_id = 0;
5541 /* Check whether extensive metadata feature is engaged. */
5542 if (!config->dv_flow_en ||
5543 config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
5544 !mlx5_flow_ext_mreg_supported(dev))
5545 return flow_create_split_inner(dev, flow, NULL, attr, items,
5546 actions, flow_split_info, error);
5547 actions_n = flow_parse_metadata_split_actions_info(actions, &qrss,
5550 /* Exclude hairpin flows from splitting. */
5551 if (qrss->type == RTE_FLOW_ACTION_TYPE_QUEUE) {
5552 const struct rte_flow_action_queue *queue;
5555 if (mlx5_rxq_get_type(dev, queue->index) ==
5556 MLX5_RXQ_TYPE_HAIRPIN)
5558 } else if (qrss->type == RTE_FLOW_ACTION_TYPE_RSS) {
5559 const struct rte_flow_action_rss *rss;
5562 if (mlx5_rxq_get_type(dev, rss->queue[0]) ==
5563 MLX5_RXQ_TYPE_HAIRPIN)
5568 /* Check if it is in meter suffix table. */
5569 mtr_sfx = attr->group == (attr->transfer ?
5570 (MLX5_FLOW_TABLE_LEVEL_METER - 1) :
5571 MLX5_FLOW_TABLE_LEVEL_METER);
5573 * Q/RSS action on NIC Rx should be split in order to pass by
5574 * the mreg copy table (RX_CP_TBL) and then it jumps to the
5575 * action table (RX_ACT_TBL) which has the split Q/RSS action.
5577 act_size = sizeof(struct rte_flow_action) * (actions_n + 1) +
5578 sizeof(struct rte_flow_action_set_tag) +
5579 sizeof(struct rte_flow_action_jump);
5580 ext_actions = mlx5_malloc(MLX5_MEM_ZERO, act_size, 0,
5583 return rte_flow_error_set(error, ENOMEM,
5584 RTE_FLOW_ERROR_TYPE_ACTION,
5585 NULL, "no memory to split "
5588 * If we are the suffix flow of meter, tag already exist.
5589 * Set the tag action to void.
5592 ext_actions[qrss - actions].type =
5593 RTE_FLOW_ACTION_TYPE_VOID;
5595 ext_actions[qrss - actions].type =
5596 (enum rte_flow_action_type)
5597 MLX5_RTE_FLOW_ACTION_TYPE_TAG;
5599 * Create the new actions list with removed Q/RSS action
5600 * and appended set tag and jump to register copy table
5601 * (RX_CP_TBL). We should preallocate unique tag ID here
5602 * in advance, because it is needed for set tag action.
5604 qrss_id = flow_mreg_split_qrss_prep(dev, ext_actions, actions,
5605 qrss, actions_n, error);
5606 if (!mtr_sfx && !qrss_id) {
5610 } else if (attr->egress && !attr->transfer) {
5612 * All the actions on NIC Tx should have a metadata register
5613 * copy action to copy reg_a from WQE to reg_c[meta]
5615 act_size = sizeof(struct rte_flow_action) * (actions_n + 1) +
5616 sizeof(struct mlx5_flow_action_copy_mreg);
5617 ext_actions = mlx5_malloc(MLX5_MEM_ZERO, act_size, 0,
5620 return rte_flow_error_set(error, ENOMEM,
5621 RTE_FLOW_ERROR_TYPE_ACTION,
5622 NULL, "no memory to split "
5624 /* Create the action list appended with copy register. */
5625 ret = flow_mreg_tx_copy_prep(dev, ext_actions, actions,
5626 actions_n, error, encap_idx);
5630 /* Add the unmodified original or prefix subflow. */
5631 ret = flow_create_split_inner(dev, flow, &dev_flow, attr,
5632 items, ext_actions ? ext_actions :
5633 actions, flow_split_info, error);
5636 MLX5_ASSERT(dev_flow);
5638 const struct rte_flow_attr q_attr = {
5639 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
5642 /* Internal PMD action to set register. */
5643 struct mlx5_rte_flow_item_tag q_tag_spec = {
5647 struct rte_flow_item q_items[] = {
5649 .type = (enum rte_flow_item_type)
5650 MLX5_RTE_FLOW_ITEM_TYPE_TAG,
5651 .spec = &q_tag_spec,
5656 .type = RTE_FLOW_ITEM_TYPE_END,
5659 struct rte_flow_action q_actions[] = {
5665 .type = RTE_FLOW_ACTION_TYPE_END,
5668 uint64_t layers = flow_get_prefix_layer_flags(dev_flow);
5671 * Configure the tag item only if there is no meter subflow.
5672 * Since tag is already marked in the meter suffix subflow
5673 * we can just use the meter suffix items as is.
5676 /* Not meter subflow. */
5677 MLX5_ASSERT(!mtr_sfx);
5679 * Put unique id in prefix flow due to it is destroyed
5680 * after suffix flow and id will be freed after there
5681 * is no actual flows with this id and identifier
5682 * reallocation becomes possible (for example, for
5683 * other flows in other threads).
5685 dev_flow->handle->split_flow_id = qrss_id;
5686 ret = mlx5_flow_get_reg_id(dev, MLX5_COPY_MARK, 0,
5690 q_tag_spec.id = ret;
5693 /* Add suffix subflow to execute Q/RSS. */
5694 flow_split_info->prefix_layers = layers;
5695 flow_split_info->prefix_mark = 0;
5696 ret = flow_create_split_inner(dev, flow, &dev_flow,
5697 &q_attr, mtr_sfx ? items :
5699 flow_split_info, error);
5702 /* qrss ID should be freed if failed. */
5704 MLX5_ASSERT(dev_flow);
5709 * We do not destroy the partially created sub_flows in case of error.
5710 * These ones are included into parent flow list and will be destroyed
5711 * by flow_drv_destroy.
5713 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RSS_EXPANTION_FLOW_ID],
5715 mlx5_free(ext_actions);
5720 * Create meter internal drop flow with the original pattern.
5723 * Pointer to Ethernet device.
5725 * Parent flow structure pointer.
5727 * Flow rule attributes.
5729 * Pattern specification (list terminated by the END pattern item).
5730 * @param[in] flow_split_info
5731 * Pointer to flow split info structure.
5733 * Pointer to flow meter structure.
5735 * Perform verbose error reporting if not NULL.
5737 * 0 on success, negative value otherwise
5740 flow_meter_create_drop_flow_with_org_pattern(struct rte_eth_dev *dev,
5741 struct rte_flow *flow,
5742 const struct rte_flow_attr *attr,
5743 const struct rte_flow_item items[],
5744 struct mlx5_flow_split_info *flow_split_info,
5745 struct mlx5_flow_meter_info *fm,
5746 struct rte_flow_error *error)
5748 struct mlx5_flow *dev_flow = NULL;
5749 struct rte_flow_attr drop_attr = *attr;
5750 struct rte_flow_action drop_actions[3];
5751 struct mlx5_flow_split_info drop_split_info = *flow_split_info;
5753 MLX5_ASSERT(fm->drop_cnt);
5754 drop_actions[0].type =
5755 (enum rte_flow_action_type)MLX5_RTE_FLOW_ACTION_TYPE_COUNT;
5756 drop_actions[0].conf = (void *)(uintptr_t)fm->drop_cnt;
5757 drop_actions[1].type = RTE_FLOW_ACTION_TYPE_DROP;
5758 drop_actions[1].conf = NULL;
5759 drop_actions[2].type = RTE_FLOW_ACTION_TYPE_END;
5760 drop_actions[2].conf = NULL;
5761 drop_split_info.external = false;
5762 drop_split_info.skip_scale |= 1 << MLX5_SCALE_FLOW_GROUP_BIT;
5763 drop_split_info.table_id = MLX5_MTR_TABLE_ID_DROP;
5764 drop_attr.group = MLX5_FLOW_TABLE_LEVEL_METER;
5765 return flow_create_split_inner(dev, flow, &dev_flow,
5766 &drop_attr, items, drop_actions,
5767 &drop_split_info, error);
5771 * The splitting for meter feature.
5773 * - The meter flow will be split to two flows as prefix and
5774 * suffix flow. The packets make sense only it pass the prefix
5777 * - Reg_C_5 is used for the packet to match betweend prefix and
5781 * Pointer to Ethernet device.
5783 * Parent flow structure pointer.
5785 * Flow rule attributes.
5787 * Pattern specification (list terminated by the END pattern item).
5788 * @param[in] actions
5789 * Associated actions (list terminated by the END action).
5790 * @param[in] flow_split_info
5791 * Pointer to flow split info structure.
5793 * Perform verbose error reporting if not NULL.
5795 * 0 on success, negative value otherwise
5798 flow_create_split_meter(struct rte_eth_dev *dev,
5799 struct rte_flow *flow,
5800 const struct rte_flow_attr *attr,
5801 const struct rte_flow_item items[],
5802 const struct rte_flow_action actions[],
5803 struct mlx5_flow_split_info *flow_split_info,
5804 struct rte_flow_error *error)
5806 struct mlx5_priv *priv = dev->data->dev_private;
5807 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
5808 struct rte_flow_action *sfx_actions = NULL;
5809 struct rte_flow_action *pre_actions = NULL;
5810 struct rte_flow_item *sfx_items = NULL;
5811 struct mlx5_flow *dev_flow = NULL;
5812 struct rte_flow_attr sfx_attr = *attr;
5813 struct mlx5_flow_meter_info *fm = NULL;
5814 uint8_t skip_scale_restore;
5815 bool has_mtr = false;
5816 bool has_modify = false;
5817 bool set_mtr_reg = true;
5818 bool is_mtr_hierarchy = false;
5819 uint32_t meter_id = 0;
5820 uint32_t mtr_idx = 0;
5821 uint32_t mtr_flow_id = 0;
5828 actions_n = flow_check_meter_action(dev, actions, &has_mtr,
5829 &has_modify, &meter_id);
5832 fm = flow_dv_meter_find_by_idx(priv, flow->meter);
5834 return rte_flow_error_set(error, EINVAL,
5835 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5836 NULL, "Meter not found.");
5838 fm = mlx5_flow_meter_find(priv, meter_id, &mtr_idx);
5840 return rte_flow_error_set(error, EINVAL,
5841 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5842 NULL, "Meter not found.");
5843 ret = mlx5_flow_meter_attach(priv, fm,
5847 flow->meter = mtr_idx;
5851 if (!fm->def_policy) {
5852 wks->policy = mlx5_flow_meter_policy_find(dev,
5855 MLX5_ASSERT(wks->policy);
5856 if (wks->policy->is_hierarchy) {
5858 mlx5_flow_meter_hierarchy_get_final_policy(dev,
5860 if (!wks->final_policy)
5861 return rte_flow_error_set(error,
5863 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5864 "Failed to find terminal policy of hierarchy.");
5865 is_mtr_hierarchy = true;
5869 * If it isn't default-policy Meter, and
5870 * 1. There's no action in flow to change
5871 * packet (modify/encap/decap etc.), OR
5872 * 2. No drop count needed for this meter.
5873 * 3. It's not meter hierarchy.
5874 * Then no need to use regC to save meter id anymore.
5876 if (!fm->def_policy && !is_mtr_hierarchy &&
5877 (!has_modify || !fm->drop_cnt))
5878 set_mtr_reg = false;
5879 /* Prefix actions: meter, decap, encap, tag, jump, end. */
5880 act_size = sizeof(struct rte_flow_action) * (actions_n + 6) +
5881 sizeof(struct mlx5_rte_flow_action_set_tag);
5882 /* Suffix items: tag, vlan, port id, end. */
5883 #define METER_SUFFIX_ITEM 4
5884 item_size = sizeof(struct rte_flow_item) * METER_SUFFIX_ITEM +
5885 sizeof(struct mlx5_rte_flow_item_tag) * 2;
5886 sfx_actions = mlx5_malloc(MLX5_MEM_ZERO, (act_size + item_size),
5889 return rte_flow_error_set(error, ENOMEM,
5890 RTE_FLOW_ERROR_TYPE_ACTION,
5891 NULL, "no memory to split "
5893 sfx_items = (struct rte_flow_item *)((char *)sfx_actions +
5895 /* There's no suffix flow for meter of non-default policy. */
5896 if (!fm->def_policy)
5897 pre_actions = sfx_actions + 1;
5899 pre_actions = sfx_actions + actions_n;
5900 ret = flow_meter_split_prep(dev, flow, wks, &sfx_attr,
5901 items, sfx_items, actions,
5902 sfx_actions, pre_actions,
5903 (set_mtr_reg ? &mtr_flow_id : NULL),
5909 /* Add the prefix subflow. */
5910 flow_split_info->prefix_mark = 0;
5911 skip_scale_restore = flow_split_info->skip_scale;
5912 flow_split_info->skip_scale |=
5913 1 << MLX5_SCALE_JUMP_FLOW_GROUP_BIT;
5914 ret = flow_create_split_inner(dev, flow, &dev_flow,
5915 attr, items, pre_actions,
5916 flow_split_info, error);
5917 flow_split_info->skip_scale = skip_scale_restore;
5920 mlx5_ipool_free(fm->flow_ipool, mtr_flow_id);
5925 dev_flow->handle->split_flow_id = mtr_flow_id;
5926 dev_flow->handle->is_meter_flow_id = 1;
5928 if (!fm->def_policy) {
5929 if (!set_mtr_reg && fm->drop_cnt)
5931 flow_meter_create_drop_flow_with_org_pattern(dev, flow,
5937 /* Setting the sfx group atrr. */
5938 sfx_attr.group = sfx_attr.transfer ?
5939 (MLX5_FLOW_TABLE_LEVEL_METER - 1) :
5940 MLX5_FLOW_TABLE_LEVEL_METER;
5941 flow_split_info->prefix_layers =
5942 flow_get_prefix_layer_flags(dev_flow);
5943 flow_split_info->prefix_mark = dev_flow->handle->mark;
5944 flow_split_info->table_id = MLX5_MTR_TABLE_ID_SUFFIX;
5946 /* Add the prefix subflow. */
5947 ret = flow_create_split_metadata(dev, flow,
5948 &sfx_attr, sfx_items ?
5950 sfx_actions ? sfx_actions : actions,
5951 flow_split_info, error);
5954 mlx5_free(sfx_actions);
5959 * The splitting for sample feature.
5961 * Once Sample action is detected in the action list, the flow actions should
5962 * be split into prefix sub flow and suffix sub flow.
5964 * The original items remain in the prefix sub flow, all actions preceding the
5965 * sample action and the sample action itself will be copied to the prefix
5966 * sub flow, the actions following the sample action will be copied to the
5967 * suffix sub flow, Queue action always be located in the suffix sub flow.
5969 * In order to make the packet from prefix sub flow matches with suffix sub
5970 * flow, an extra tag action be added into prefix sub flow, and the suffix sub
5971 * flow uses tag item with the unique flow id.
5974 * Pointer to Ethernet device.
5976 * Parent flow structure pointer.
5978 * Flow rule attributes.
5980 * Pattern specification (list terminated by the END pattern item).
5981 * @param[in] actions
5982 * Associated actions (list terminated by the END action).
5983 * @param[in] flow_split_info
5984 * Pointer to flow split info structure.
5986 * Perform verbose error reporting if not NULL.
5988 * 0 on success, negative value otherwise
5991 flow_create_split_sample(struct rte_eth_dev *dev,
5992 struct rte_flow *flow,
5993 const struct rte_flow_attr *attr,
5994 const struct rte_flow_item items[],
5995 const struct rte_flow_action actions[],
5996 struct mlx5_flow_split_info *flow_split_info,
5997 struct rte_flow_error *error)
5999 struct mlx5_priv *priv = dev->data->dev_private;
6000 struct rte_flow_action *sfx_actions = NULL;
6001 struct rte_flow_action *pre_actions = NULL;
6002 struct rte_flow_item *sfx_items = NULL;
6003 struct mlx5_flow *dev_flow = NULL;
6004 struct rte_flow_attr sfx_attr = *attr;
6005 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
6006 struct mlx5_flow_dv_sample_resource *sample_res;
6007 struct mlx5_flow_tbl_data_entry *sfx_tbl_data;
6008 struct mlx5_flow_tbl_resource *sfx_tbl;
6012 uint32_t fdb_tx = 0;
6015 int sample_action_pos;
6016 int qrss_action_pos;
6018 int modify_after_mirror = 0;
6019 uint16_t jump_table = 0;
6020 const uint32_t next_ft_step = 1;
6023 if (priv->sampler_en)
6024 actions_n = flow_check_match_action(actions, attr,
6025 RTE_FLOW_ACTION_TYPE_SAMPLE,
6026 &sample_action_pos, &qrss_action_pos,
6027 &modify_after_mirror);
6029 /* The prefix actions must includes sample, tag, end. */
6030 act_size = sizeof(struct rte_flow_action) * (actions_n * 2 + 1)
6031 + sizeof(struct mlx5_rte_flow_action_set_tag);
6032 item_size = sizeof(struct rte_flow_item) * SAMPLE_SUFFIX_ITEM +
6033 sizeof(struct mlx5_rte_flow_item_tag) * 2;
6034 sfx_actions = mlx5_malloc(MLX5_MEM_ZERO, (act_size +
6035 item_size), 0, SOCKET_ID_ANY);
6037 return rte_flow_error_set(error, ENOMEM,
6038 RTE_FLOW_ERROR_TYPE_ACTION,
6039 NULL, "no memory to split "
6041 /* The representor_id is UINT16_MAX for uplink. */
6042 fdb_tx = (attr->transfer && priv->representor_id != UINT16_MAX);
6044 * When reg_c_preserve is set, metadata registers Cx preserve
6045 * their value even through packet duplication.
6047 add_tag = (!fdb_tx || priv->config.hca_attr.reg_c_preserve);
6049 sfx_items = (struct rte_flow_item *)((char *)sfx_actions
6051 if (modify_after_mirror)
6052 jump_table = attr->group * MLX5_FLOW_TABLE_FACTOR +
6054 pre_actions = sfx_actions + actions_n;
6055 tag_id = flow_sample_split_prep(dev, add_tag, sfx_items,
6056 actions, sfx_actions,
6057 pre_actions, actions_n,
6059 qrss_action_pos, jump_table,
6061 if (tag_id < 0 || (add_tag && !tag_id)) {
6065 if (modify_after_mirror)
6066 flow_split_info->skip_scale =
6067 1 << MLX5_SCALE_JUMP_FLOW_GROUP_BIT;
6068 /* Add the prefix subflow. */
6069 ret = flow_create_split_inner(dev, flow, &dev_flow, attr,
6071 flow_split_info, error);
6076 dev_flow->handle->split_flow_id = tag_id;
6077 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
6078 if (!modify_after_mirror) {
6079 /* Set the sfx group attr. */
6080 sample_res = (struct mlx5_flow_dv_sample_resource *)
6081 dev_flow->dv.sample_res;
6082 sfx_tbl = (struct mlx5_flow_tbl_resource *)
6083 sample_res->normal_path_tbl;
6084 sfx_tbl_data = container_of(sfx_tbl,
6085 struct mlx5_flow_tbl_data_entry,
6087 sfx_attr.group = sfx_attr.transfer ?
6088 (sfx_tbl_data->level - 1) : sfx_tbl_data->level;
6090 MLX5_ASSERT(attr->transfer);
6091 sfx_attr.group = jump_table;
6093 flow_split_info->prefix_layers =
6094 flow_get_prefix_layer_flags(dev_flow);
6095 flow_split_info->prefix_mark = dev_flow->handle->mark;
6096 /* Suffix group level already be scaled with factor, set
6097 * MLX5_SCALE_FLOW_GROUP_BIT of skip_scale to 1 to avoid scale
6098 * again in translation.
6100 flow_split_info->skip_scale = 1 << MLX5_SCALE_FLOW_GROUP_BIT;
6103 /* Add the suffix subflow. */
6104 ret = flow_create_split_meter(dev, flow, &sfx_attr,
6105 sfx_items ? sfx_items : items,
6106 sfx_actions ? sfx_actions : actions,
6107 flow_split_info, error);
6110 mlx5_free(sfx_actions);
6115 * Split the flow to subflow set. The splitters might be linked
6116 * in the chain, like this:
6117 * flow_create_split_outer() calls:
6118 * flow_create_split_meter() calls:
6119 * flow_create_split_metadata(meter_subflow_0) calls:
6120 * flow_create_split_inner(metadata_subflow_0)
6121 * flow_create_split_inner(metadata_subflow_1)
6122 * flow_create_split_inner(metadata_subflow_2)
6123 * flow_create_split_metadata(meter_subflow_1) 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)
6128 * This provide flexible way to add new levels of flow splitting.
6129 * The all of successfully created subflows are included to the
6130 * parent flow dev_flow list.
6133 * Pointer to Ethernet device.
6135 * Parent flow structure pointer.
6137 * Flow rule attributes.
6139 * Pattern specification (list terminated by the END pattern item).
6140 * @param[in] actions
6141 * Associated actions (list terminated by the END action).
6142 * @param[in] flow_split_info
6143 * Pointer to flow split info structure.
6145 * Perform verbose error reporting if not NULL.
6147 * 0 on success, negative value otherwise
6150 flow_create_split_outer(struct rte_eth_dev *dev,
6151 struct rte_flow *flow,
6152 const struct rte_flow_attr *attr,
6153 const struct rte_flow_item items[],
6154 const struct rte_flow_action actions[],
6155 struct mlx5_flow_split_info *flow_split_info,
6156 struct rte_flow_error *error)
6160 ret = flow_create_split_sample(dev, flow, attr, items,
6161 actions, flow_split_info, error);
6162 MLX5_ASSERT(ret <= 0);
6166 static inline struct mlx5_flow_tunnel *
6167 flow_tunnel_from_rule(const struct mlx5_flow *flow)
6169 struct mlx5_flow_tunnel *tunnel;
6171 #pragma GCC diagnostic push
6172 #pragma GCC diagnostic ignored "-Wcast-qual"
6173 tunnel = (typeof(tunnel))flow->tunnel;
6174 #pragma GCC diagnostic pop
6180 * Adjust flow RSS workspace if needed.
6183 * Pointer to thread flow work space.
6185 * Pointer to RSS descriptor.
6186 * @param[in] nrssq_num
6187 * New RSS queue number.
6190 * 0 on success, -1 otherwise and rte_errno is set.
6193 flow_rss_workspace_adjust(struct mlx5_flow_workspace *wks,
6194 struct mlx5_flow_rss_desc *rss_desc,
6197 if (likely(nrssq_num <= wks->rssq_num))
6199 rss_desc->queue = realloc(rss_desc->queue,
6200 sizeof(*rss_desc->queue) * RTE_ALIGN(nrssq_num, 2));
6201 if (!rss_desc->queue) {
6205 wks->rssq_num = RTE_ALIGN(nrssq_num, 2);
6210 * Create a flow and add it to @p list.
6213 * Pointer to Ethernet device.
6215 * Pointer to a TAILQ flow list. If this parameter NULL,
6216 * no list insertion occurred, flow is just created,
6217 * this is caller's responsibility to track the
6220 * Flow rule attributes.
6222 * Pattern specification (list terminated by the END pattern item).
6223 * @param[in] actions
6224 * Associated actions (list terminated by the END action).
6225 * @param[in] external
6226 * This flow rule is created by request external to PMD.
6228 * Perform verbose error reporting if not NULL.
6231 * A flow index on success, 0 otherwise and rte_errno is set.
6234 flow_list_create(struct rte_eth_dev *dev, enum mlx5_flow_type type,
6235 const struct rte_flow_attr *attr,
6236 const struct rte_flow_item items[],
6237 const struct rte_flow_action original_actions[],
6238 bool external, struct rte_flow_error *error)
6240 struct mlx5_priv *priv = dev->data->dev_private;
6241 struct rte_flow *flow = NULL;
6242 struct mlx5_flow *dev_flow;
6243 const struct rte_flow_action_rss *rss = NULL;
6244 struct mlx5_translated_action_handle
6245 indir_actions[MLX5_MAX_INDIRECT_ACTIONS];
6246 int indir_actions_n = MLX5_MAX_INDIRECT_ACTIONS;
6248 struct mlx5_flow_expand_rss buf;
6249 uint8_t buffer[2048];
6252 struct rte_flow_action actions[MLX5_MAX_SPLIT_ACTIONS];
6253 uint8_t buffer[2048];
6256 struct rte_flow_action actions[MLX5_MAX_SPLIT_ACTIONS];
6257 uint8_t buffer[2048];
6258 } actions_hairpin_tx;
6260 struct rte_flow_item items[MLX5_MAX_SPLIT_ITEMS];
6261 uint8_t buffer[2048];
6263 struct mlx5_flow_expand_rss *buf = &expand_buffer.buf;
6264 struct mlx5_flow_rss_desc *rss_desc;
6265 const struct rte_flow_action *p_actions_rx;
6269 struct rte_flow_attr attr_tx = { .priority = 0 };
6270 const struct rte_flow_action *actions;
6271 struct rte_flow_action *translated_actions = NULL;
6272 struct mlx5_flow_tunnel *tunnel;
6273 struct tunnel_default_miss_ctx default_miss_ctx = { 0, };
6274 struct mlx5_flow_workspace *wks = mlx5_flow_push_thread_workspace();
6275 struct mlx5_flow_split_info flow_split_info = {
6276 .external = !!external,
6286 rss_desc = &wks->rss_desc;
6287 ret = flow_action_handles_translate(dev, original_actions,
6290 &translated_actions, error);
6292 MLX5_ASSERT(translated_actions == NULL);
6295 actions = translated_actions ? translated_actions : original_actions;
6296 p_actions_rx = actions;
6297 hairpin_flow = flow_check_hairpin_split(dev, attr, actions);
6298 ret = flow_drv_validate(dev, attr, items, p_actions_rx,
6299 external, hairpin_flow, error);
6301 goto error_before_hairpin_split;
6302 flow = mlx5_ipool_zmalloc(priv->flows[type], &idx);
6305 goto error_before_hairpin_split;
6307 if (hairpin_flow > 0) {
6308 if (hairpin_flow > MLX5_MAX_SPLIT_ACTIONS) {
6310 goto error_before_hairpin_split;
6312 flow_hairpin_split(dev, actions, actions_rx.actions,
6313 actions_hairpin_tx.actions, items_tx.items,
6315 p_actions_rx = actions_rx.actions;
6317 flow_split_info.flow_idx = idx;
6318 flow->drv_type = flow_get_drv_type(dev, attr);
6319 MLX5_ASSERT(flow->drv_type > MLX5_FLOW_TYPE_MIN &&
6320 flow->drv_type < MLX5_FLOW_TYPE_MAX);
6321 memset(rss_desc, 0, offsetof(struct mlx5_flow_rss_desc, queue));
6322 /* RSS Action only works on NIC RX domain */
6323 if (attr->ingress && !attr->transfer)
6324 rss = flow_get_rss_action(dev, p_actions_rx);
6326 if (flow_rss_workspace_adjust(wks, rss_desc, rss->queue_num))
6329 * The following information is required by
6330 * mlx5_flow_hashfields_adjust() in advance.
6332 rss_desc->level = rss->level;
6333 /* RSS type 0 indicates default RSS type (ETH_RSS_IP). */
6334 rss_desc->types = !rss->types ? ETH_RSS_IP : rss->types;
6336 flow->dev_handles = 0;
6337 if (rss && rss->types) {
6338 unsigned int graph_root;
6340 graph_root = find_graph_root(items, rss->level);
6341 ret = mlx5_flow_expand_rss(buf, sizeof(expand_buffer.buffer),
6343 mlx5_support_expansion, graph_root);
6344 MLX5_ASSERT(ret > 0 &&
6345 (unsigned int)ret < sizeof(expand_buffer.buffer));
6346 if (rte_log_can_log(mlx5_logtype, RTE_LOG_DEBUG)) {
6347 for (i = 0; i < buf->entries; ++i)
6348 mlx5_dbg__print_pattern(buf->entry[i].pattern);
6352 buf->entry[0].pattern = (void *)(uintptr_t)items;
6354 rss_desc->shared_rss = flow_get_shared_rss_action(dev, indir_actions,
6356 for (i = 0; i < buf->entries; ++i) {
6357 /* Initialize flow split data. */
6358 flow_split_info.prefix_layers = 0;
6359 flow_split_info.prefix_mark = 0;
6360 flow_split_info.skip_scale = 0;
6362 * The splitter may create multiple dev_flows,
6363 * depending on configuration. In the simplest
6364 * case it just creates unmodified original flow.
6366 ret = flow_create_split_outer(dev, flow, attr,
6367 buf->entry[i].pattern,
6368 p_actions_rx, &flow_split_info,
6372 if (is_flow_tunnel_steer_rule(wks->flows[0].tof_type)) {
6373 ret = flow_tunnel_add_default_miss(dev, flow, attr,
6376 wks->flows[0].tunnel,
6380 mlx5_free(default_miss_ctx.queue);
6385 /* Create the tx flow. */
6387 attr_tx.group = MLX5_HAIRPIN_TX_TABLE;
6388 attr_tx.ingress = 0;
6390 dev_flow = flow_drv_prepare(dev, flow, &attr_tx, items_tx.items,
6391 actions_hairpin_tx.actions,
6395 dev_flow->flow = flow;
6396 dev_flow->external = 0;
6397 SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
6398 dev_flow->handle, next);
6399 ret = flow_drv_translate(dev, dev_flow, &attr_tx,
6401 actions_hairpin_tx.actions, error);
6406 * Update the metadata register copy table. If extensive
6407 * metadata feature is enabled and registers are supported
6408 * we might create the extra rte_flow for each unique
6409 * MARK/FLAG action ID.
6411 * The table is updated for ingress Flows only, because
6412 * the egress Flows belong to the different device and
6413 * copy table should be updated in peer NIC Rx domain.
6415 if (attr->ingress &&
6416 (external || attr->group != MLX5_FLOW_MREG_CP_TABLE_GROUP)) {
6417 ret = flow_mreg_update_copy_table(dev, flow, actions, error);
6422 * If the flow is external (from application) OR device is started,
6423 * OR mreg discover, then apply immediately.
6425 if (external || dev->data->dev_started ||
6426 (attr->group == MLX5_FLOW_MREG_CP_TABLE_GROUP &&
6427 attr->priority == MLX5_FLOW_LOWEST_PRIO_INDICATOR)) {
6428 ret = flow_drv_apply(dev, flow, error);
6433 flow_rxq_flags_set(dev, flow);
6434 rte_free(translated_actions);
6435 tunnel = flow_tunnel_from_rule(wks->flows);
6438 flow->tunnel_id = tunnel->tunnel_id;
6439 __atomic_add_fetch(&tunnel->refctn, 1, __ATOMIC_RELAXED);
6440 mlx5_free(default_miss_ctx.queue);
6442 mlx5_flow_pop_thread_workspace();
6446 ret = rte_errno; /* Save rte_errno before cleanup. */
6447 flow_mreg_del_copy_action(dev, flow);
6448 flow_drv_destroy(dev, flow);
6449 if (rss_desc->shared_rss)
6450 __atomic_sub_fetch(&((struct mlx5_shared_action_rss *)
6452 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
6453 rss_desc->shared_rss))->refcnt, 1, __ATOMIC_RELAXED);
6454 mlx5_ipool_free(priv->flows[type], idx);
6455 rte_errno = ret; /* Restore rte_errno. */
6458 mlx5_flow_pop_thread_workspace();
6459 error_before_hairpin_split:
6460 rte_free(translated_actions);
6465 * Create a dedicated flow rule on e-switch table 0 (root table), to direct all
6466 * incoming packets to table 1.
6468 * Other flow rules, requested for group n, will be created in
6469 * e-switch table n+1.
6470 * Jump action to e-switch group n will be created to group n+1.
6472 * Used when working in switchdev mode, to utilise advantages of table 1
6476 * Pointer to Ethernet device.
6479 * Pointer to flow on success, NULL otherwise and rte_errno is set.
6482 mlx5_flow_create_esw_table_zero_flow(struct rte_eth_dev *dev)
6484 const struct rte_flow_attr attr = {
6491 const struct rte_flow_item pattern = {
6492 .type = RTE_FLOW_ITEM_TYPE_END,
6494 struct rte_flow_action_jump jump = {
6497 const struct rte_flow_action actions[] = {
6499 .type = RTE_FLOW_ACTION_TYPE_JUMP,
6503 .type = RTE_FLOW_ACTION_TYPE_END,
6506 struct rte_flow_error error;
6508 return (void *)(uintptr_t)flow_list_create(dev, MLX5_FLOW_TYPE_CTL,
6510 actions, false, &error);
6514 * Validate a flow supported by the NIC.
6516 * @see rte_flow_validate()
6520 mlx5_flow_validate(struct rte_eth_dev *dev,
6521 const struct rte_flow_attr *attr,
6522 const struct rte_flow_item items[],
6523 const struct rte_flow_action original_actions[],
6524 struct rte_flow_error *error)
6527 struct mlx5_translated_action_handle
6528 indir_actions[MLX5_MAX_INDIRECT_ACTIONS];
6529 int indir_actions_n = MLX5_MAX_INDIRECT_ACTIONS;
6530 const struct rte_flow_action *actions;
6531 struct rte_flow_action *translated_actions = NULL;
6532 int ret = flow_action_handles_translate(dev, original_actions,
6535 &translated_actions, error);
6539 actions = translated_actions ? translated_actions : original_actions;
6540 hairpin_flow = flow_check_hairpin_split(dev, attr, actions);
6541 ret = flow_drv_validate(dev, attr, items, actions,
6542 true, hairpin_flow, error);
6543 rte_free(translated_actions);
6550 * @see rte_flow_create()
6554 mlx5_flow_create(struct rte_eth_dev *dev,
6555 const struct rte_flow_attr *attr,
6556 const struct rte_flow_item items[],
6557 const struct rte_flow_action actions[],
6558 struct rte_flow_error *error)
6561 * If the device is not started yet, it is not allowed to created a
6562 * flow from application. PMD default flows and traffic control flows
6565 if (unlikely(!dev->data->dev_started)) {
6566 DRV_LOG(DEBUG, "port %u is not started when "
6567 "inserting a flow", dev->data->port_id);
6568 rte_flow_error_set(error, ENODEV,
6569 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6571 "port not started");
6575 return (void *)(uintptr_t)flow_list_create(dev, MLX5_FLOW_TYPE_GEN,
6576 attr, items, actions,
6581 * Destroy a flow in a list.
6584 * Pointer to Ethernet device.
6585 * @param[in] flow_idx
6586 * Index of flow to destroy.
6589 flow_list_destroy(struct rte_eth_dev *dev, enum mlx5_flow_type type,
6592 struct mlx5_priv *priv = dev->data->dev_private;
6593 struct rte_flow *flow = mlx5_ipool_get(priv->flows[type], flow_idx);
6597 MLX5_ASSERT(flow->type == type);
6599 * Update RX queue flags only if port is started, otherwise it is
6602 if (dev->data->dev_started)
6603 flow_rxq_flags_trim(dev, flow);
6604 flow_drv_destroy(dev, flow);
6606 struct mlx5_flow_tunnel *tunnel;
6608 tunnel = mlx5_find_tunnel_id(dev, flow->tunnel_id);
6610 if (!__atomic_sub_fetch(&tunnel->refctn, 1, __ATOMIC_RELAXED))
6611 mlx5_flow_tunnel_free(dev, tunnel);
6613 flow_mreg_del_copy_action(dev, flow);
6614 mlx5_ipool_free(priv->flows[type], flow_idx);
6618 * Destroy all flows.
6621 * Pointer to Ethernet device.
6623 * Flow type to be flushed.
6625 * If flushing is called avtively.
6628 mlx5_flow_list_flush(struct rte_eth_dev *dev, enum mlx5_flow_type type,
6631 struct mlx5_priv *priv = dev->data->dev_private;
6632 uint32_t num_flushed = 0, fidx = 1;
6633 struct rte_flow *flow;
6635 MLX5_IPOOL_FOREACH(priv->flows[type], fidx, flow) {
6636 flow_list_destroy(dev, type, fidx);
6640 DRV_LOG(INFO, "port %u: %u flows flushed before stopping",
6641 dev->data->port_id, num_flushed);
6646 * Stop all default actions for flows.
6649 * Pointer to Ethernet device.
6652 mlx5_flow_stop_default(struct rte_eth_dev *dev)
6654 flow_mreg_del_default_copy_action(dev);
6655 flow_rxq_flags_clear(dev);
6659 * Start all default actions for flows.
6662 * Pointer to Ethernet device.
6664 * 0 on success, a negative errno value otherwise and rte_errno is set.
6667 mlx5_flow_start_default(struct rte_eth_dev *dev)
6669 struct rte_flow_error error;
6671 /* Make sure default copy action (reg_c[0] -> reg_b) is created. */
6672 return flow_mreg_add_default_copy_action(dev, &error);
6676 * Release key of thread specific flow workspace data.
6679 flow_release_workspace(void *data)
6681 struct mlx5_flow_workspace *wks = data;
6682 struct mlx5_flow_workspace *next;
6686 free(wks->rss_desc.queue);
6693 * Get thread specific current flow workspace.
6695 * @return pointer to thread specific flow workspace data, NULL on error.
6697 struct mlx5_flow_workspace*
6698 mlx5_flow_get_thread_workspace(void)
6700 struct mlx5_flow_workspace *data;
6702 data = mlx5_flow_os_get_specific_workspace();
6703 MLX5_ASSERT(data && data->inuse);
6704 if (!data || !data->inuse)
6705 DRV_LOG(ERR, "flow workspace not initialized.");
6710 * Allocate and init new flow workspace.
6712 * @return pointer to flow workspace data, NULL on error.
6714 static struct mlx5_flow_workspace*
6715 flow_alloc_thread_workspace(void)
6717 struct mlx5_flow_workspace *data = calloc(1, sizeof(*data));
6720 DRV_LOG(ERR, "Failed to allocate flow workspace "
6724 data->rss_desc.queue = calloc(1,
6725 sizeof(uint16_t) * MLX5_RSSQ_DEFAULT_NUM);
6726 if (!data->rss_desc.queue)
6728 data->rssq_num = MLX5_RSSQ_DEFAULT_NUM;
6731 if (data->rss_desc.queue)
6732 free(data->rss_desc.queue);
6738 * Get new thread specific flow workspace.
6740 * If current workspace inuse, create new one and set as current.
6742 * @return pointer to thread specific flow workspace data, NULL on error.
6744 static struct mlx5_flow_workspace*
6745 mlx5_flow_push_thread_workspace(void)
6747 struct mlx5_flow_workspace *curr;
6748 struct mlx5_flow_workspace *data;
6750 curr = mlx5_flow_os_get_specific_workspace();
6752 data = flow_alloc_thread_workspace();
6755 } else if (!curr->inuse) {
6757 } else if (curr->next) {
6760 data = flow_alloc_thread_workspace();
6768 /* Set as current workspace */
6769 if (mlx5_flow_os_set_specific_workspace(data))
6770 DRV_LOG(ERR, "Failed to set flow workspace to thread.");
6775 * Close current thread specific flow workspace.
6777 * If previous workspace available, set it as current.
6779 * @return pointer to thread specific flow workspace data, NULL on error.
6782 mlx5_flow_pop_thread_workspace(void)
6784 struct mlx5_flow_workspace *data = mlx5_flow_get_thread_workspace();
6789 DRV_LOG(ERR, "Failed to close unused flow workspace.");
6795 if (mlx5_flow_os_set_specific_workspace(data->prev))
6796 DRV_LOG(ERR, "Failed to set flow workspace to thread.");
6800 * Verify the flow list is empty
6803 * Pointer to Ethernet device.
6805 * @return the number of flows not released.
6808 mlx5_flow_verify(struct rte_eth_dev *dev __rte_unused)
6810 struct mlx5_priv *priv = dev->data->dev_private;
6811 struct rte_flow *flow;
6815 for (i = 0; i < MLX5_FLOW_TYPE_MAXI; i++) {
6816 MLX5_IPOOL_FOREACH(priv->flows[i], idx, flow) {
6817 DRV_LOG(DEBUG, "port %u flow %p still referenced",
6818 dev->data->port_id, (void *)flow);
6826 * Enable default hairpin egress flow.
6829 * Pointer to Ethernet device.
6834 * 0 on success, a negative errno value otherwise and rte_errno is set.
6837 mlx5_ctrl_flow_source_queue(struct rte_eth_dev *dev,
6840 const struct rte_flow_attr attr = {
6844 struct mlx5_rte_flow_item_tx_queue queue_spec = {
6847 struct mlx5_rte_flow_item_tx_queue queue_mask = {
6848 .queue = UINT32_MAX,
6850 struct rte_flow_item items[] = {
6852 .type = (enum rte_flow_item_type)
6853 MLX5_RTE_FLOW_ITEM_TYPE_TX_QUEUE,
6854 .spec = &queue_spec,
6856 .mask = &queue_mask,
6859 .type = RTE_FLOW_ITEM_TYPE_END,
6862 struct rte_flow_action_jump jump = {
6863 .group = MLX5_HAIRPIN_TX_TABLE,
6865 struct rte_flow_action actions[2];
6867 struct rte_flow_error error;
6869 actions[0].type = RTE_FLOW_ACTION_TYPE_JUMP;
6870 actions[0].conf = &jump;
6871 actions[1].type = RTE_FLOW_ACTION_TYPE_END;
6872 flow_idx = flow_list_create(dev, MLX5_FLOW_TYPE_CTL,
6873 &attr, items, actions, false, &error);
6876 "Failed to create ctrl flow: rte_errno(%d),"
6877 " type(%d), message(%s)",
6878 rte_errno, error.type,
6879 error.message ? error.message : " (no stated reason)");
6886 * Enable a control flow configured from the control plane.
6889 * Pointer to Ethernet device.
6891 * An Ethernet flow spec to apply.
6893 * An Ethernet flow mask to apply.
6895 * A VLAN flow spec to apply.
6897 * A VLAN flow mask to apply.
6900 * 0 on success, a negative errno value otherwise and rte_errno is set.
6903 mlx5_ctrl_flow_vlan(struct rte_eth_dev *dev,
6904 struct rte_flow_item_eth *eth_spec,
6905 struct rte_flow_item_eth *eth_mask,
6906 struct rte_flow_item_vlan *vlan_spec,
6907 struct rte_flow_item_vlan *vlan_mask)
6909 struct mlx5_priv *priv = dev->data->dev_private;
6910 const struct rte_flow_attr attr = {
6912 .priority = MLX5_FLOW_LOWEST_PRIO_INDICATOR,
6914 struct rte_flow_item items[] = {
6916 .type = RTE_FLOW_ITEM_TYPE_ETH,
6922 .type = (vlan_spec) ? RTE_FLOW_ITEM_TYPE_VLAN :
6923 RTE_FLOW_ITEM_TYPE_END,
6929 .type = RTE_FLOW_ITEM_TYPE_END,
6932 uint16_t queue[priv->reta_idx_n];
6933 struct rte_flow_action_rss action_rss = {
6934 .func = RTE_ETH_HASH_FUNCTION_DEFAULT,
6936 .types = priv->rss_conf.rss_hf,
6937 .key_len = priv->rss_conf.rss_key_len,
6938 .queue_num = priv->reta_idx_n,
6939 .key = priv->rss_conf.rss_key,
6942 struct rte_flow_action actions[] = {
6944 .type = RTE_FLOW_ACTION_TYPE_RSS,
6945 .conf = &action_rss,
6948 .type = RTE_FLOW_ACTION_TYPE_END,
6952 struct rte_flow_error error;
6955 if (!priv->reta_idx_n || !priv->rxqs_n) {
6958 if (!(dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG))
6959 action_rss.types = 0;
6960 for (i = 0; i != priv->reta_idx_n; ++i)
6961 queue[i] = (*priv->reta_idx)[i];
6962 flow_idx = flow_list_create(dev, MLX5_FLOW_TYPE_CTL,
6963 &attr, items, actions, false, &error);
6970 * Enable a flow control configured from the control plane.
6973 * Pointer to Ethernet device.
6975 * An Ethernet flow spec to apply.
6977 * An Ethernet flow mask to apply.
6980 * 0 on success, a negative errno value otherwise and rte_errno is set.
6983 mlx5_ctrl_flow(struct rte_eth_dev *dev,
6984 struct rte_flow_item_eth *eth_spec,
6985 struct rte_flow_item_eth *eth_mask)
6987 return mlx5_ctrl_flow_vlan(dev, eth_spec, eth_mask, NULL, NULL);
6991 * Create default miss flow rule matching lacp traffic
6994 * Pointer to Ethernet device.
6996 * An Ethernet flow spec to apply.
6999 * 0 on success, a negative errno value otherwise and rte_errno is set.
7002 mlx5_flow_lacp_miss(struct rte_eth_dev *dev)
7005 * The LACP matching is done by only using ether type since using
7006 * a multicast dst mac causes kernel to give low priority to this flow.
7008 static const struct rte_flow_item_eth lacp_spec = {
7009 .type = RTE_BE16(0x8809),
7011 static const struct rte_flow_item_eth lacp_mask = {
7014 const struct rte_flow_attr attr = {
7017 struct rte_flow_item items[] = {
7019 .type = RTE_FLOW_ITEM_TYPE_ETH,
7024 .type = RTE_FLOW_ITEM_TYPE_END,
7027 struct rte_flow_action actions[] = {
7029 .type = (enum rte_flow_action_type)
7030 MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS,
7033 .type = RTE_FLOW_ACTION_TYPE_END,
7036 struct rte_flow_error error;
7037 uint32_t flow_idx = flow_list_create(dev, MLX5_FLOW_TYPE_CTL,
7038 &attr, items, actions,
7049 * @see rte_flow_destroy()
7053 mlx5_flow_destroy(struct rte_eth_dev *dev,
7054 struct rte_flow *flow,
7055 struct rte_flow_error *error __rte_unused)
7057 flow_list_destroy(dev, MLX5_FLOW_TYPE_GEN,
7058 (uintptr_t)(void *)flow);
7063 * Destroy all flows.
7065 * @see rte_flow_flush()
7069 mlx5_flow_flush(struct rte_eth_dev *dev,
7070 struct rte_flow_error *error __rte_unused)
7072 mlx5_flow_list_flush(dev, MLX5_FLOW_TYPE_GEN, false);
7079 * @see rte_flow_isolate()
7083 mlx5_flow_isolate(struct rte_eth_dev *dev,
7085 struct rte_flow_error *error)
7087 struct mlx5_priv *priv = dev->data->dev_private;
7089 if (dev->data->dev_started) {
7090 rte_flow_error_set(error, EBUSY,
7091 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7093 "port must be stopped first");
7096 priv->isolated = !!enable;
7098 dev->dev_ops = &mlx5_dev_ops_isolate;
7100 dev->dev_ops = &mlx5_dev_ops;
7102 dev->rx_descriptor_status = mlx5_rx_descriptor_status;
7103 dev->tx_descriptor_status = mlx5_tx_descriptor_status;
7111 * @see rte_flow_query()
7115 flow_drv_query(struct rte_eth_dev *dev,
7117 const struct rte_flow_action *actions,
7119 struct rte_flow_error *error)
7121 struct mlx5_priv *priv = dev->data->dev_private;
7122 const struct mlx5_flow_driver_ops *fops;
7123 struct rte_flow *flow = mlx5_ipool_get(priv->flows[MLX5_FLOW_TYPE_GEN],
7125 enum mlx5_flow_drv_type ftype;
7128 return rte_flow_error_set(error, ENOENT,
7129 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7131 "invalid flow handle");
7133 ftype = flow->drv_type;
7134 MLX5_ASSERT(ftype > MLX5_FLOW_TYPE_MIN && ftype < MLX5_FLOW_TYPE_MAX);
7135 fops = flow_get_drv_ops(ftype);
7137 return fops->query(dev, flow, actions, data, error);
7143 * @see rte_flow_query()
7147 mlx5_flow_query(struct rte_eth_dev *dev,
7148 struct rte_flow *flow,
7149 const struct rte_flow_action *actions,
7151 struct rte_flow_error *error)
7155 ret = flow_drv_query(dev, (uintptr_t)(void *)flow, actions, data,
7163 * Get rte_flow callbacks.
7166 * Pointer to Ethernet device structure.
7168 * Pointer to operation-specific structure.
7173 mlx5_flow_ops_get(struct rte_eth_dev *dev __rte_unused,
7174 const struct rte_flow_ops **ops)
7176 *ops = &mlx5_flow_ops;
7181 * Validate meter policy actions.
7182 * Dispatcher for action type specific validation.
7185 * Pointer to the Ethernet device structure.
7187 * The meter policy action object to validate.
7189 * Attributes of flow to determine steering domain.
7190 * @param[out] is_rss
7192 * @param[out] domain_bitmap
7194 * @param[out] is_def_policy
7195 * Is default policy or not.
7197 * Perform verbose error reporting if not NULL. Initialized in case of
7201 * 0 on success, otherwise negative errno value.
7204 mlx5_flow_validate_mtr_acts(struct rte_eth_dev *dev,
7205 const struct rte_flow_action *actions[RTE_COLORS],
7206 struct rte_flow_attr *attr,
7208 uint8_t *domain_bitmap,
7209 uint8_t *policy_mode,
7210 struct rte_mtr_error *error)
7212 const struct mlx5_flow_driver_ops *fops;
7214 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7215 return fops->validate_mtr_acts(dev, actions, attr, is_rss,
7216 domain_bitmap, policy_mode, error);
7220 * Destroy the meter table set.
7223 * Pointer to Ethernet device.
7224 * @param[in] mtr_policy
7225 * Meter policy struct.
7228 mlx5_flow_destroy_mtr_acts(struct rte_eth_dev *dev,
7229 struct mlx5_flow_meter_policy *mtr_policy)
7231 const struct mlx5_flow_driver_ops *fops;
7233 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7234 fops->destroy_mtr_acts(dev, mtr_policy);
7238 * Create policy action, lock free,
7239 * (mutex should be acquired by caller).
7240 * Dispatcher for action type specific call.
7243 * Pointer to the Ethernet device structure.
7244 * @param[in] mtr_policy
7245 * Meter policy struct.
7247 * Action specification used to create meter actions.
7249 * Perform verbose error reporting if not NULL. Initialized in case of
7253 * 0 on success, otherwise negative errno value.
7256 mlx5_flow_create_mtr_acts(struct rte_eth_dev *dev,
7257 struct mlx5_flow_meter_policy *mtr_policy,
7258 const struct rte_flow_action *actions[RTE_COLORS],
7259 struct rte_mtr_error *error)
7261 const struct mlx5_flow_driver_ops *fops;
7263 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7264 return fops->create_mtr_acts(dev, mtr_policy, actions, error);
7268 * Create policy rules, lock free,
7269 * (mutex should be acquired by caller).
7270 * Dispatcher for action type specific call.
7273 * Pointer to the Ethernet device structure.
7274 * @param[in] mtr_policy
7275 * Meter policy struct.
7278 * 0 on success, -1 otherwise.
7281 mlx5_flow_create_policy_rules(struct rte_eth_dev *dev,
7282 struct mlx5_flow_meter_policy *mtr_policy)
7284 const struct mlx5_flow_driver_ops *fops;
7286 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7287 return fops->create_policy_rules(dev, mtr_policy);
7291 * Destroy policy rules, lock free,
7292 * (mutex should be acquired by caller).
7293 * Dispatcher for action type specific call.
7296 * Pointer to the Ethernet device structure.
7297 * @param[in] mtr_policy
7298 * Meter policy struct.
7301 mlx5_flow_destroy_policy_rules(struct rte_eth_dev *dev,
7302 struct mlx5_flow_meter_policy *mtr_policy)
7304 const struct mlx5_flow_driver_ops *fops;
7306 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7307 fops->destroy_policy_rules(dev, mtr_policy);
7311 * Destroy the default policy table set.
7314 * Pointer to Ethernet device.
7317 mlx5_flow_destroy_def_policy(struct rte_eth_dev *dev)
7319 const struct mlx5_flow_driver_ops *fops;
7321 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7322 fops->destroy_def_policy(dev);
7326 * Destroy the default policy table set.
7329 * Pointer to Ethernet device.
7332 * 0 on success, -1 otherwise.
7335 mlx5_flow_create_def_policy(struct rte_eth_dev *dev)
7337 const struct mlx5_flow_driver_ops *fops;
7339 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7340 return fops->create_def_policy(dev);
7344 * Create the needed meter and suffix tables.
7347 * Pointer to Ethernet device.
7350 * 0 on success, -1 otherwise.
7353 mlx5_flow_create_mtr_tbls(struct rte_eth_dev *dev,
7354 struct mlx5_flow_meter_info *fm,
7356 uint8_t domain_bitmap)
7358 const struct mlx5_flow_driver_ops *fops;
7360 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7361 return fops->create_mtr_tbls(dev, fm, mtr_idx, domain_bitmap);
7365 * Destroy the meter table set.
7368 * Pointer to Ethernet device.
7370 * Pointer to the meter table set.
7373 mlx5_flow_destroy_mtr_tbls(struct rte_eth_dev *dev,
7374 struct mlx5_flow_meter_info *fm)
7376 const struct mlx5_flow_driver_ops *fops;
7378 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7379 fops->destroy_mtr_tbls(dev, fm);
7383 * Destroy the global meter drop table.
7386 * Pointer to Ethernet device.
7389 mlx5_flow_destroy_mtr_drop_tbls(struct rte_eth_dev *dev)
7391 const struct mlx5_flow_driver_ops *fops;
7393 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7394 fops->destroy_mtr_drop_tbls(dev);
7398 * Destroy the sub policy table with RX queue.
7401 * Pointer to Ethernet device.
7402 * @param[in] mtr_policy
7403 * Pointer to meter policy table.
7406 mlx5_flow_destroy_sub_policy_with_rxq(struct rte_eth_dev *dev,
7407 struct mlx5_flow_meter_policy *mtr_policy)
7409 const struct mlx5_flow_driver_ops *fops;
7411 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7412 fops->destroy_sub_policy_with_rxq(dev, mtr_policy);
7416 * Allocate the needed aso flow meter id.
7419 * Pointer to Ethernet device.
7422 * Index to aso flow meter on success, NULL otherwise.
7425 mlx5_flow_mtr_alloc(struct rte_eth_dev *dev)
7427 const struct mlx5_flow_driver_ops *fops;
7429 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7430 return fops->create_meter(dev);
7434 * Free the aso flow meter id.
7437 * Pointer to Ethernet device.
7438 * @param[in] mtr_idx
7439 * Index to aso flow meter to be free.
7445 mlx5_flow_mtr_free(struct rte_eth_dev *dev, uint32_t mtr_idx)
7447 const struct mlx5_flow_driver_ops *fops;
7449 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7450 fops->free_meter(dev, mtr_idx);
7454 * Allocate a counter.
7457 * Pointer to Ethernet device structure.
7460 * Index to allocated counter on success, 0 otherwise.
7463 mlx5_counter_alloc(struct rte_eth_dev *dev)
7465 const struct mlx5_flow_driver_ops *fops;
7466 struct rte_flow_attr attr = { .transfer = 0 };
7468 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
7469 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7470 return fops->counter_alloc(dev);
7473 "port %u counter allocate is not supported.",
7474 dev->data->port_id);
7482 * Pointer to Ethernet device structure.
7484 * Index to counter to be free.
7487 mlx5_counter_free(struct rte_eth_dev *dev, uint32_t cnt)
7489 const struct mlx5_flow_driver_ops *fops;
7490 struct rte_flow_attr attr = { .transfer = 0 };
7492 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
7493 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7494 fops->counter_free(dev, cnt);
7498 "port %u counter free is not supported.",
7499 dev->data->port_id);
7503 * Query counter statistics.
7506 * Pointer to Ethernet device structure.
7508 * Index to counter to query.
7510 * Set to clear counter statistics.
7512 * The counter hits packets number to save.
7514 * The counter hits bytes number to save.
7517 * 0 on success, a negative errno value otherwise.
7520 mlx5_counter_query(struct rte_eth_dev *dev, uint32_t cnt,
7521 bool clear, uint64_t *pkts, uint64_t *bytes)
7523 const struct mlx5_flow_driver_ops *fops;
7524 struct rte_flow_attr attr = { .transfer = 0 };
7526 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
7527 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7528 return fops->counter_query(dev, cnt, clear, pkts, bytes);
7531 "port %u counter query is not supported.",
7532 dev->data->port_id);
7537 * Allocate a new memory for the counter values wrapped by all the needed
7541 * Pointer to mlx5_dev_ctx_shared object.
7544 * 0 on success, a negative errno value otherwise.
7547 mlx5_flow_create_counter_stat_mem_mng(struct mlx5_dev_ctx_shared *sh)
7549 struct mlx5_devx_mkey_attr mkey_attr;
7550 struct mlx5_counter_stats_mem_mng *mem_mng;
7551 volatile struct flow_counter_stats *raw_data;
7552 int raws_n = MLX5_CNT_CONTAINER_RESIZE + MLX5_MAX_PENDING_QUERIES;
7553 int size = (sizeof(struct flow_counter_stats) *
7554 MLX5_COUNTERS_PER_POOL +
7555 sizeof(struct mlx5_counter_stats_raw)) * raws_n +
7556 sizeof(struct mlx5_counter_stats_mem_mng);
7557 size_t pgsize = rte_mem_page_size();
7561 if (pgsize == (size_t)-1) {
7562 DRV_LOG(ERR, "Failed to get mem page size");
7566 mem = mlx5_malloc(MLX5_MEM_ZERO, size, pgsize, SOCKET_ID_ANY);
7571 mem_mng = (struct mlx5_counter_stats_mem_mng *)(mem + size) - 1;
7572 size = sizeof(*raw_data) * MLX5_COUNTERS_PER_POOL * raws_n;
7573 mem_mng->umem = mlx5_os_umem_reg(sh->ctx, mem, size,
7574 IBV_ACCESS_LOCAL_WRITE);
7575 if (!mem_mng->umem) {
7580 memset(&mkey_attr, 0, sizeof(mkey_attr));
7581 mkey_attr.addr = (uintptr_t)mem;
7582 mkey_attr.size = size;
7583 mkey_attr.umem_id = mlx5_os_get_umem_id(mem_mng->umem);
7584 mkey_attr.pd = sh->pdn;
7585 mkey_attr.relaxed_ordering_write = sh->cmng.relaxed_ordering_write;
7586 mkey_attr.relaxed_ordering_read = sh->cmng.relaxed_ordering_read;
7587 mem_mng->dm = mlx5_devx_cmd_mkey_create(sh->ctx, &mkey_attr);
7589 mlx5_os_umem_dereg(mem_mng->umem);
7594 mem_mng->raws = (struct mlx5_counter_stats_raw *)(mem + size);
7595 raw_data = (volatile struct flow_counter_stats *)mem;
7596 for (i = 0; i < raws_n; ++i) {
7597 mem_mng->raws[i].mem_mng = mem_mng;
7598 mem_mng->raws[i].data = raw_data + i * MLX5_COUNTERS_PER_POOL;
7600 for (i = 0; i < MLX5_MAX_PENDING_QUERIES; ++i)
7601 LIST_INSERT_HEAD(&sh->cmng.free_stat_raws,
7602 mem_mng->raws + MLX5_CNT_CONTAINER_RESIZE + i,
7604 LIST_INSERT_HEAD(&sh->cmng.mem_mngs, mem_mng, next);
7605 sh->cmng.mem_mng = mem_mng;
7610 * Set the statistic memory to the new counter pool.
7613 * Pointer to mlx5_dev_ctx_shared object.
7615 * Pointer to the pool to set the statistic memory.
7618 * 0 on success, a negative errno value otherwise.
7621 mlx5_flow_set_counter_stat_mem(struct mlx5_dev_ctx_shared *sh,
7622 struct mlx5_flow_counter_pool *pool)
7624 struct mlx5_flow_counter_mng *cmng = &sh->cmng;
7625 /* Resize statistic memory once used out. */
7626 if (!(pool->index % MLX5_CNT_CONTAINER_RESIZE) &&
7627 mlx5_flow_create_counter_stat_mem_mng(sh)) {
7628 DRV_LOG(ERR, "Cannot resize counter stat mem.");
7631 rte_spinlock_lock(&pool->sl);
7632 pool->raw = cmng->mem_mng->raws + pool->index %
7633 MLX5_CNT_CONTAINER_RESIZE;
7634 rte_spinlock_unlock(&pool->sl);
7635 pool->raw_hw = NULL;
7639 #define MLX5_POOL_QUERY_FREQ_US 1000000
7642 * Set the periodic procedure for triggering asynchronous batch queries for all
7643 * the counter pools.
7646 * Pointer to mlx5_dev_ctx_shared object.
7649 mlx5_set_query_alarm(struct mlx5_dev_ctx_shared *sh)
7651 uint32_t pools_n, us;
7653 pools_n = __atomic_load_n(&sh->cmng.n_valid, __ATOMIC_RELAXED);
7654 us = MLX5_POOL_QUERY_FREQ_US / pools_n;
7655 DRV_LOG(DEBUG, "Set alarm for %u pools each %u us", pools_n, us);
7656 if (rte_eal_alarm_set(us, mlx5_flow_query_alarm, sh)) {
7657 sh->cmng.query_thread_on = 0;
7658 DRV_LOG(ERR, "Cannot reinitialize query alarm");
7660 sh->cmng.query_thread_on = 1;
7665 * The periodic procedure for triggering asynchronous batch queries for all the
7666 * counter pools. This function is probably called by the host thread.
7669 * The parameter for the alarm process.
7672 mlx5_flow_query_alarm(void *arg)
7674 struct mlx5_dev_ctx_shared *sh = arg;
7676 uint16_t pool_index = sh->cmng.pool_index;
7677 struct mlx5_flow_counter_mng *cmng = &sh->cmng;
7678 struct mlx5_flow_counter_pool *pool;
7681 if (sh->cmng.pending_queries >= MLX5_MAX_PENDING_QUERIES)
7683 rte_spinlock_lock(&cmng->pool_update_sl);
7684 pool = cmng->pools[pool_index];
7685 n_valid = cmng->n_valid;
7686 rte_spinlock_unlock(&cmng->pool_update_sl);
7687 /* Set the statistic memory to the new created pool. */
7688 if ((!pool->raw && mlx5_flow_set_counter_stat_mem(sh, pool)))
7691 /* There is a pool query in progress. */
7694 LIST_FIRST(&sh->cmng.free_stat_raws);
7696 /* No free counter statistics raw memory. */
7699 * Identify the counters released between query trigger and query
7700 * handle more efficiently. The counter released in this gap period
7701 * should wait for a new round of query as the new arrived packets
7702 * will not be taken into account.
7705 ret = mlx5_devx_cmd_flow_counter_query(pool->min_dcs, 0,
7706 MLX5_COUNTERS_PER_POOL,
7708 pool->raw_hw->mem_mng->dm->id,
7712 (uint64_t)(uintptr_t)pool);
7714 DRV_LOG(ERR, "Failed to trigger asynchronous query for dcs ID"
7715 " %d", pool->min_dcs->id);
7716 pool->raw_hw = NULL;
7719 LIST_REMOVE(pool->raw_hw, next);
7720 sh->cmng.pending_queries++;
7722 if (pool_index >= n_valid)
7725 sh->cmng.pool_index = pool_index;
7726 mlx5_set_query_alarm(sh);
7730 * Check and callback event for new aged flow in the counter pool
7733 * Pointer to mlx5_dev_ctx_shared object.
7735 * Pointer to Current counter pool.
7738 mlx5_flow_aging_check(struct mlx5_dev_ctx_shared *sh,
7739 struct mlx5_flow_counter_pool *pool)
7741 struct mlx5_priv *priv;
7742 struct mlx5_flow_counter *cnt;
7743 struct mlx5_age_info *age_info;
7744 struct mlx5_age_param *age_param;
7745 struct mlx5_counter_stats_raw *cur = pool->raw_hw;
7746 struct mlx5_counter_stats_raw *prev = pool->raw;
7747 const uint64_t curr_time = MLX5_CURR_TIME_SEC;
7748 const uint32_t time_delta = curr_time - pool->time_of_last_age_check;
7749 uint16_t expected = AGE_CANDIDATE;
7752 pool->time_of_last_age_check = curr_time;
7753 for (i = 0; i < MLX5_COUNTERS_PER_POOL; ++i) {
7754 cnt = MLX5_POOL_GET_CNT(pool, i);
7755 age_param = MLX5_CNT_TO_AGE(cnt);
7756 if (__atomic_load_n(&age_param->state,
7757 __ATOMIC_RELAXED) != AGE_CANDIDATE)
7759 if (cur->data[i].hits != prev->data[i].hits) {
7760 __atomic_store_n(&age_param->sec_since_last_hit, 0,
7764 if (__atomic_add_fetch(&age_param->sec_since_last_hit,
7766 __ATOMIC_RELAXED) <= age_param->timeout)
7769 * Hold the lock first, or if between the
7770 * state AGE_TMOUT and tailq operation the
7771 * release happened, the release procedure
7772 * may delete a non-existent tailq node.
7774 priv = rte_eth_devices[age_param->port_id].data->dev_private;
7775 age_info = GET_PORT_AGE_INFO(priv);
7776 rte_spinlock_lock(&age_info->aged_sl);
7777 if (__atomic_compare_exchange_n(&age_param->state, &expected,
7780 __ATOMIC_RELAXED)) {
7781 TAILQ_INSERT_TAIL(&age_info->aged_counters, cnt, next);
7782 MLX5_AGE_SET(age_info, MLX5_AGE_EVENT_NEW);
7784 rte_spinlock_unlock(&age_info->aged_sl);
7786 mlx5_age_event_prepare(sh);
7790 * Handler for the HW respond about ready values from an asynchronous batch
7791 * query. This function is probably called by the host thread.
7794 * The pointer to the shared device context.
7795 * @param[in] async_id
7796 * The Devx async ID.
7798 * The status of the completion.
7801 mlx5_flow_async_pool_query_handle(struct mlx5_dev_ctx_shared *sh,
7802 uint64_t async_id, int status)
7804 struct mlx5_flow_counter_pool *pool =
7805 (struct mlx5_flow_counter_pool *)(uintptr_t)async_id;
7806 struct mlx5_counter_stats_raw *raw_to_free;
7807 uint8_t query_gen = pool->query_gen ^ 1;
7808 struct mlx5_flow_counter_mng *cmng = &sh->cmng;
7809 enum mlx5_counter_type cnt_type =
7810 pool->is_aged ? MLX5_COUNTER_TYPE_AGE :
7811 MLX5_COUNTER_TYPE_ORIGIN;
7813 if (unlikely(status)) {
7814 raw_to_free = pool->raw_hw;
7816 raw_to_free = pool->raw;
7818 mlx5_flow_aging_check(sh, pool);
7819 rte_spinlock_lock(&pool->sl);
7820 pool->raw = pool->raw_hw;
7821 rte_spinlock_unlock(&pool->sl);
7822 /* Be sure the new raw counters data is updated in memory. */
7824 if (!TAILQ_EMPTY(&pool->counters[query_gen])) {
7825 rte_spinlock_lock(&cmng->csl[cnt_type]);
7826 TAILQ_CONCAT(&cmng->counters[cnt_type],
7827 &pool->counters[query_gen], next);
7828 rte_spinlock_unlock(&cmng->csl[cnt_type]);
7831 LIST_INSERT_HEAD(&sh->cmng.free_stat_raws, raw_to_free, next);
7832 pool->raw_hw = NULL;
7833 sh->cmng.pending_queries--;
7837 flow_group_to_table(uint32_t port_id, uint32_t group, uint32_t *table,
7838 const struct flow_grp_info *grp_info,
7839 struct rte_flow_error *error)
7841 if (grp_info->transfer && grp_info->external &&
7842 grp_info->fdb_def_rule) {
7843 if (group == UINT32_MAX)
7844 return rte_flow_error_set
7846 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
7848 "group index not supported");
7853 DRV_LOG(DEBUG, "port %u group=%#x table=%#x", port_id, group, *table);
7858 * Translate the rte_flow group index to HW table value.
7860 * If tunnel offload is disabled, all group ids converted to flow table
7861 * id using the standard method.
7862 * If tunnel offload is enabled, group id can be converted using the
7863 * standard or tunnel conversion method. Group conversion method
7864 * selection depends on flags in `grp_info` parameter:
7865 * - Internal (grp_info.external == 0) groups conversion uses the
7867 * - Group ids in JUMP action converted with the tunnel conversion.
7868 * - Group id in rule attribute conversion depends on a rule type and
7870 * ** non zero group attributes converted with the tunnel method
7871 * ** zero group attribute in non-tunnel rule is converted using the
7872 * standard method - there's only one root table
7873 * ** zero group attribute in steer tunnel rule is converted with the
7874 * standard method - single root table
7875 * ** zero group attribute in match tunnel rule is a special OvS
7876 * case: that value is used for portability reasons. That group
7877 * id is converted with the tunnel conversion method.
7882 * PMD tunnel offload object
7884 * rte_flow group index value.
7887 * @param[in] grp_info
7888 * flags used for conversion
7890 * Pointer to error structure.
7893 * 0 on success, a negative errno value otherwise and rte_errno is set.
7896 mlx5_flow_group_to_table(struct rte_eth_dev *dev,
7897 const struct mlx5_flow_tunnel *tunnel,
7898 uint32_t group, uint32_t *table,
7899 const struct flow_grp_info *grp_info,
7900 struct rte_flow_error *error)
7903 bool standard_translation;
7905 if (!grp_info->skip_scale && grp_info->external &&
7906 group < MLX5_MAX_TABLES_EXTERNAL)
7907 group *= MLX5_FLOW_TABLE_FACTOR;
7908 if (is_tunnel_offload_active(dev)) {
7909 standard_translation = !grp_info->external ||
7910 grp_info->std_tbl_fix;
7912 standard_translation = true;
7915 "port %u group=%u transfer=%d external=%d fdb_def_rule=%d translate=%s",
7916 dev->data->port_id, group, grp_info->transfer,
7917 grp_info->external, grp_info->fdb_def_rule,
7918 standard_translation ? "STANDARD" : "TUNNEL");
7919 if (standard_translation)
7920 ret = flow_group_to_table(dev->data->port_id, group, table,
7923 ret = tunnel_flow_group_to_flow_table(dev, tunnel, group,
7930 * Discover availability of metadata reg_c's.
7932 * Iteratively use test flows to check availability.
7935 * Pointer to the Ethernet device structure.
7938 * 0 on success, a negative errno value otherwise and rte_errno is set.
7941 mlx5_flow_discover_mreg_c(struct rte_eth_dev *dev)
7943 struct mlx5_priv *priv = dev->data->dev_private;
7944 struct mlx5_dev_config *config = &priv->config;
7945 enum modify_reg idx;
7948 /* reg_c[0] and reg_c[1] are reserved. */
7949 config->flow_mreg_c[n++] = REG_C_0;
7950 config->flow_mreg_c[n++] = REG_C_1;
7951 /* Discover availability of other reg_c's. */
7952 for (idx = REG_C_2; idx <= REG_C_7; ++idx) {
7953 struct rte_flow_attr attr = {
7954 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
7955 .priority = MLX5_FLOW_LOWEST_PRIO_INDICATOR,
7958 struct rte_flow_item items[] = {
7960 .type = RTE_FLOW_ITEM_TYPE_END,
7963 struct rte_flow_action actions[] = {
7965 .type = (enum rte_flow_action_type)
7966 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
7967 .conf = &(struct mlx5_flow_action_copy_mreg){
7973 .type = RTE_FLOW_ACTION_TYPE_JUMP,
7974 .conf = &(struct rte_flow_action_jump){
7975 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
7979 .type = RTE_FLOW_ACTION_TYPE_END,
7983 struct rte_flow *flow;
7984 struct rte_flow_error error;
7986 if (!config->dv_flow_en)
7988 /* Create internal flow, validation skips copy action. */
7989 flow_idx = flow_list_create(dev, MLX5_FLOW_TYPE_GEN, &attr,
7990 items, actions, false, &error);
7991 flow = mlx5_ipool_get(priv->flows[MLX5_FLOW_TYPE_GEN],
7995 config->flow_mreg_c[n++] = idx;
7996 flow_list_destroy(dev, MLX5_FLOW_TYPE_GEN, flow_idx);
7998 for (; n < MLX5_MREG_C_NUM; ++n)
7999 config->flow_mreg_c[n] = REG_NON;
8004 save_dump_file(const uint8_t *data, uint32_t size,
8005 uint32_t type, uint32_t id, void *arg, FILE *file)
8007 char line[BUF_SIZE];
8010 uint32_t actions_num;
8011 struct rte_flow_query_count *count;
8013 memset(line, 0, BUF_SIZE);
8015 case DR_DUMP_REC_TYPE_PMD_MODIFY_HDR:
8016 actions_num = *(uint32_t *)(arg);
8017 out += snprintf(line + out, BUF_SIZE - out, "%d,0x%x,%d,",
8018 type, id, actions_num);
8020 case DR_DUMP_REC_TYPE_PMD_PKT_REFORMAT:
8021 out += snprintf(line + out, BUF_SIZE - out, "%d,0x%x,",
8024 case DR_DUMP_REC_TYPE_PMD_COUNTER:
8025 count = (struct rte_flow_query_count *)arg;
8026 fprintf(file, "%d,0x%x,%" PRIu64 ",%" PRIu64 "\n", type,
8027 id, count->hits, count->bytes);
8033 for (k = 0; k < size; k++) {
8034 /* Make sure we do not overrun the line buffer length. */
8035 if (out >= BUF_SIZE - 4) {
8039 out += snprintf(line + out, BUF_SIZE - out, "%02x",
8042 fprintf(file, "%s\n", line);
8047 mlx5_flow_query_counter(struct rte_eth_dev *dev, struct rte_flow *flow,
8048 struct rte_flow_query_count *count, struct rte_flow_error *error)
8050 struct rte_flow_action action[2];
8051 enum mlx5_flow_drv_type ftype;
8052 const struct mlx5_flow_driver_ops *fops;
8055 return rte_flow_error_set(error, ENOENT,
8056 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8058 "invalid flow handle");
8060 action[0].type = RTE_FLOW_ACTION_TYPE_COUNT;
8061 action[1].type = RTE_FLOW_ACTION_TYPE_END;
8062 if (flow->counter) {
8063 memset(count, 0, sizeof(struct rte_flow_query_count));
8064 ftype = (enum mlx5_flow_drv_type)(flow->drv_type);
8065 MLX5_ASSERT(ftype > MLX5_FLOW_TYPE_MIN &&
8066 ftype < MLX5_FLOW_TYPE_MAX);
8067 fops = flow_get_drv_ops(ftype);
8068 return fops->query(dev, flow, action, count, error);
8073 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
8075 * Dump flow ipool data to file
8078 * The pointer to Ethernet device.
8080 * A pointer to a file for output.
8082 * Perform verbose error reporting if not NULL. PMDs initialize this
8083 * structure in case of error only.
8085 * 0 on success, a negative value otherwise.
8088 mlx5_flow_dev_dump_ipool(struct rte_eth_dev *dev,
8089 struct rte_flow *flow, FILE *file,
8090 struct rte_flow_error *error)
8092 struct mlx5_priv *priv = dev->data->dev_private;
8093 struct mlx5_flow_dv_modify_hdr_resource *modify_hdr;
8094 struct mlx5_flow_dv_encap_decap_resource *encap_decap;
8095 uint32_t handle_idx;
8096 struct mlx5_flow_handle *dh;
8097 struct rte_flow_query_count count;
8098 uint32_t actions_num;
8099 const uint8_t *data;
8105 return rte_flow_error_set(error, ENOENT,
8106 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8108 "invalid flow handle");
8110 handle_idx = flow->dev_handles;
8111 while (handle_idx) {
8112 dh = mlx5_ipool_get(priv->sh->ipool
8113 [MLX5_IPOOL_MLX5_FLOW], handle_idx);
8116 handle_idx = dh->next.next;
8117 id = (uint32_t)(uintptr_t)dh->drv_flow;
8120 type = DR_DUMP_REC_TYPE_PMD_COUNTER;
8121 if (!mlx5_flow_query_counter(dev, flow, &count, error))
8122 save_dump_file(NULL, 0, type,
8123 id, (void *)&count, file);
8125 /* Get modify_hdr and encap_decap buf from ipools. */
8127 modify_hdr = dh->dvh.modify_hdr;
8129 if (dh->dvh.rix_encap_decap) {
8130 encap_decap = mlx5_ipool_get(priv->sh->ipool
8131 [MLX5_IPOOL_DECAP_ENCAP],
8132 dh->dvh.rix_encap_decap);
8135 data = (const uint8_t *)modify_hdr->actions;
8136 size = (size_t)(modify_hdr->actions_num) * 8;
8137 actions_num = modify_hdr->actions_num;
8138 type = DR_DUMP_REC_TYPE_PMD_MODIFY_HDR;
8139 save_dump_file(data, size, type, id,
8140 (void *)(&actions_num), file);
8143 data = encap_decap->buf;
8144 size = encap_decap->size;
8145 type = DR_DUMP_REC_TYPE_PMD_PKT_REFORMAT;
8146 save_dump_file(data, size, type,
8155 * Dump flow raw hw data to file
8158 * The pointer to Ethernet device.
8160 * A pointer to a file for output.
8162 * Perform verbose error reporting if not NULL. PMDs initialize this
8163 * structure in case of error only.
8165 * 0 on success, a nagative value otherwise.
8168 mlx5_flow_dev_dump(struct rte_eth_dev *dev, struct rte_flow *flow_idx,
8170 struct rte_flow_error *error __rte_unused)
8172 struct mlx5_priv *priv = dev->data->dev_private;
8173 struct mlx5_dev_ctx_shared *sh = priv->sh;
8174 uint32_t handle_idx;
8176 struct mlx5_flow_handle *dh;
8177 struct rte_flow *flow;
8178 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
8182 if (!priv->config.dv_flow_en) {
8183 if (fputs("device dv flow disabled\n", file) <= 0)
8190 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
8191 MLX5_IPOOL_FOREACH(priv->flows[MLX5_FLOW_TYPE_GEN], idx, flow)
8192 mlx5_flow_dev_dump_ipool(dev, flow, file, error);
8194 return mlx5_devx_cmd_flow_dump(sh->fdb_domain,
8196 sh->tx_domain, file);
8199 flow = mlx5_ipool_get(priv->flows[MLX5_FLOW_TYPE_GEN],
8200 (uintptr_t)(void *)flow_idx);
8204 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
8205 mlx5_flow_dev_dump_ipool(dev, flow, file, error);
8207 handle_idx = flow->dev_handles;
8208 while (handle_idx) {
8209 dh = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
8214 ret = mlx5_devx_cmd_flow_single_dump(dh->drv_flow,
8219 handle_idx = dh->next.next;
8225 * Get aged-out flows.
8228 * Pointer to the Ethernet device structure.
8229 * @param[in] context
8230 * The address of an array of pointers to the aged-out flows contexts.
8231 * @param[in] nb_countexts
8232 * The length of context array pointers.
8234 * Perform verbose error reporting if not NULL. Initialized in case of
8238 * how many contexts get in success, otherwise negative errno value.
8239 * if nb_contexts is 0, return the amount of all aged contexts.
8240 * if nb_contexts is not 0 , return the amount of aged flows reported
8241 * in the context array.
8244 mlx5_flow_get_aged_flows(struct rte_eth_dev *dev, void **contexts,
8245 uint32_t nb_contexts, struct rte_flow_error *error)
8247 const struct mlx5_flow_driver_ops *fops;
8248 struct rte_flow_attr attr = { .transfer = 0 };
8250 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
8251 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
8252 return fops->get_aged_flows(dev, contexts, nb_contexts,
8256 "port %u get aged flows is not supported.",
8257 dev->data->port_id);
8261 /* Wrapper for driver action_validate op callback */
8263 flow_drv_action_validate(struct rte_eth_dev *dev,
8264 const struct rte_flow_indir_action_conf *conf,
8265 const struct rte_flow_action *action,
8266 const struct mlx5_flow_driver_ops *fops,
8267 struct rte_flow_error *error)
8269 static const char err_msg[] = "indirect action validation unsupported";
8271 if (!fops->action_validate) {
8272 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
8273 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
8277 return fops->action_validate(dev, conf, action, error);
8281 * Destroys the shared action by handle.
8284 * Pointer to Ethernet device structure.
8286 * Handle for the indirect action object to be destroyed.
8288 * Perform verbose error reporting if not NULL. PMDs initialize this
8289 * structure in case of error only.
8292 * 0 on success, a negative errno value otherwise and rte_errno is set.
8294 * @note: wrapper for driver action_create op callback.
8297 mlx5_action_handle_destroy(struct rte_eth_dev *dev,
8298 struct rte_flow_action_handle *handle,
8299 struct rte_flow_error *error)
8301 static const char err_msg[] = "indirect action destruction unsupported";
8302 struct rte_flow_attr attr = { .transfer = 0 };
8303 const struct mlx5_flow_driver_ops *fops =
8304 flow_get_drv_ops(flow_get_drv_type(dev, &attr));
8306 if (!fops->action_destroy) {
8307 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
8308 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
8312 return fops->action_destroy(dev, handle, error);
8315 /* Wrapper for driver action_destroy op callback */
8317 flow_drv_action_update(struct rte_eth_dev *dev,
8318 struct rte_flow_action_handle *handle,
8320 const struct mlx5_flow_driver_ops *fops,
8321 struct rte_flow_error *error)
8323 static const char err_msg[] = "indirect action update unsupported";
8325 if (!fops->action_update) {
8326 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
8327 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
8331 return fops->action_update(dev, handle, update, error);
8334 /* Wrapper for driver action_destroy op callback */
8336 flow_drv_action_query(struct rte_eth_dev *dev,
8337 const struct rte_flow_action_handle *handle,
8339 const struct mlx5_flow_driver_ops *fops,
8340 struct rte_flow_error *error)
8342 static const char err_msg[] = "indirect action query unsupported";
8344 if (!fops->action_query) {
8345 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
8346 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
8350 return fops->action_query(dev, handle, data, error);
8354 * Create indirect action for reuse in multiple flow rules.
8357 * Pointer to Ethernet device structure.
8359 * Pointer to indirect action object configuration.
8361 * Action configuration for indirect action object creation.
8363 * Perform verbose error reporting if not NULL. PMDs initialize this
8364 * structure in case of error only.
8366 * A valid handle in case of success, NULL otherwise and rte_errno is set.
8368 static struct rte_flow_action_handle *
8369 mlx5_action_handle_create(struct rte_eth_dev *dev,
8370 const struct rte_flow_indir_action_conf *conf,
8371 const struct rte_flow_action *action,
8372 struct rte_flow_error *error)
8374 static const char err_msg[] = "indirect action creation unsupported";
8375 struct rte_flow_attr attr = { .transfer = 0 };
8376 const struct mlx5_flow_driver_ops *fops =
8377 flow_get_drv_ops(flow_get_drv_type(dev, &attr));
8379 if (flow_drv_action_validate(dev, conf, action, fops, error))
8381 if (!fops->action_create) {
8382 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
8383 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
8387 return fops->action_create(dev, conf, action, error);
8391 * Updates inplace the indirect action configuration pointed by *handle*
8392 * with the configuration provided as *update* argument.
8393 * The update of the indirect action configuration effects all flow rules
8394 * reusing the action via handle.
8397 * Pointer to Ethernet device structure.
8399 * Handle for the indirect action to be updated.
8401 * Action specification used to modify the action pointed by handle.
8402 * *update* could be of same type with the action pointed by the *handle*
8403 * handle argument, or some other structures like a wrapper, depending on
8404 * the indirect action type.
8406 * Perform verbose error reporting if not NULL. PMDs initialize this
8407 * structure in case of error only.
8410 * 0 on success, a negative errno value otherwise and rte_errno is set.
8413 mlx5_action_handle_update(struct rte_eth_dev *dev,
8414 struct rte_flow_action_handle *handle,
8416 struct rte_flow_error *error)
8418 struct rte_flow_attr attr = { .transfer = 0 };
8419 const struct mlx5_flow_driver_ops *fops =
8420 flow_get_drv_ops(flow_get_drv_type(dev, &attr));
8423 ret = flow_drv_action_validate(dev, NULL,
8424 (const struct rte_flow_action *)update, fops, error);
8427 return flow_drv_action_update(dev, handle, update, fops,
8432 * Query the indirect action by handle.
8434 * This function allows retrieving action-specific data such as counters.
8435 * Data is gathered by special action which may be present/referenced in
8436 * more than one flow rule definition.
8438 * see @RTE_FLOW_ACTION_TYPE_COUNT
8441 * Pointer to Ethernet device structure.
8443 * Handle for the indirect action to query.
8444 * @param[in, out] data
8445 * Pointer to storage for the associated query data type.
8447 * Perform verbose error reporting if not NULL. PMDs initialize this
8448 * structure in case of error only.
8451 * 0 on success, a negative errno value otherwise and rte_errno is set.
8454 mlx5_action_handle_query(struct rte_eth_dev *dev,
8455 const struct rte_flow_action_handle *handle,
8457 struct rte_flow_error *error)
8459 struct rte_flow_attr attr = { .transfer = 0 };
8460 const struct mlx5_flow_driver_ops *fops =
8461 flow_get_drv_ops(flow_get_drv_type(dev, &attr));
8463 return flow_drv_action_query(dev, handle, data, fops, error);
8467 * Destroy all indirect actions (shared RSS).
8470 * Pointer to Ethernet device.
8473 * 0 on success, a negative errno value otherwise and rte_errno is set.
8476 mlx5_action_handle_flush(struct rte_eth_dev *dev)
8478 struct rte_flow_error error;
8479 struct mlx5_priv *priv = dev->data->dev_private;
8480 struct mlx5_shared_action_rss *shared_rss;
8484 ILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
8485 priv->rss_shared_actions, idx, shared_rss, next) {
8486 ret |= mlx5_action_handle_destroy(dev,
8487 (struct rte_flow_action_handle *)(uintptr_t)idx, &error);
8492 #ifndef HAVE_MLX5DV_DR
8493 #define MLX5_DOMAIN_SYNC_FLOW ((1 << 0) | (1 << 1))
8495 #define MLX5_DOMAIN_SYNC_FLOW \
8496 (MLX5DV_DR_DOMAIN_SYNC_FLAGS_SW | MLX5DV_DR_DOMAIN_SYNC_FLAGS_HW)
8499 int rte_pmd_mlx5_sync_flow(uint16_t port_id, uint32_t domains)
8501 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
8502 const struct mlx5_flow_driver_ops *fops;
8504 struct rte_flow_attr attr = { .transfer = 0 };
8506 fops = flow_get_drv_ops(flow_get_drv_type(dev, &attr));
8507 ret = fops->sync_domain(dev, domains, MLX5_DOMAIN_SYNC_FLOW);
8513 const struct mlx5_flow_tunnel *
8514 mlx5_get_tof(const struct rte_flow_item *item,
8515 const struct rte_flow_action *action,
8516 enum mlx5_tof_rule_type *rule_type)
8518 for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
8519 if (item->type == (typeof(item->type))
8520 MLX5_RTE_FLOW_ITEM_TYPE_TUNNEL) {
8521 *rule_type = MLX5_TUNNEL_OFFLOAD_MATCH_RULE;
8522 return flow_items_to_tunnel(item);
8525 for (; action->conf != RTE_FLOW_ACTION_TYPE_END; action++) {
8526 if (action->type == (typeof(action->type))
8527 MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET) {
8528 *rule_type = MLX5_TUNNEL_OFFLOAD_SET_RULE;
8529 return flow_actions_to_tunnel(action);
8536 * tunnel offload functionalilty is defined for DV environment only
8538 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
8540 union tunnel_offload_mark {
8543 uint32_t app_reserve:8;
8544 uint32_t table_id:15;
8545 uint32_t transfer:1;
8546 uint32_t _unused_:8;
8551 mlx5_access_tunnel_offload_db
8552 (struct rte_eth_dev *dev,
8553 bool (*match)(struct rte_eth_dev *,
8554 struct mlx5_flow_tunnel *, const void *),
8555 void (*hit)(struct rte_eth_dev *, struct mlx5_flow_tunnel *, void *),
8556 void (*miss)(struct rte_eth_dev *, void *),
8557 void *ctx, bool lock_op);
8560 flow_tunnel_add_default_miss(struct rte_eth_dev *dev,
8561 struct rte_flow *flow,
8562 const struct rte_flow_attr *attr,
8563 const struct rte_flow_action *app_actions,
8565 const struct mlx5_flow_tunnel *tunnel,
8566 struct tunnel_default_miss_ctx *ctx,
8567 struct rte_flow_error *error)
8569 struct mlx5_priv *priv = dev->data->dev_private;
8570 struct mlx5_flow *dev_flow;
8571 struct rte_flow_attr miss_attr = *attr;
8572 const struct rte_flow_item miss_items[2] = {
8574 .type = RTE_FLOW_ITEM_TYPE_ETH,
8580 .type = RTE_FLOW_ITEM_TYPE_END,
8586 union tunnel_offload_mark mark_id;
8587 struct rte_flow_action_mark miss_mark;
8588 struct rte_flow_action miss_actions[3] = {
8589 [0] = { .type = RTE_FLOW_ACTION_TYPE_MARK, .conf = &miss_mark },
8590 [2] = { .type = RTE_FLOW_ACTION_TYPE_END, .conf = NULL }
8592 const struct rte_flow_action_jump *jump_data;
8593 uint32_t i, flow_table = 0; /* prevent compilation warning */
8594 struct flow_grp_info grp_info = {
8596 .transfer = attr->transfer,
8597 .fdb_def_rule = !!priv->fdb_def_rule,
8602 if (!attr->transfer) {
8605 miss_actions[1].type = RTE_FLOW_ACTION_TYPE_RSS;
8606 q_size = priv->reta_idx_n * sizeof(ctx->queue[0]);
8607 ctx->queue = mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO, q_size,
8610 return rte_flow_error_set
8612 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
8613 NULL, "invalid default miss RSS");
8614 ctx->action_rss.func = RTE_ETH_HASH_FUNCTION_DEFAULT,
8615 ctx->action_rss.level = 0,
8616 ctx->action_rss.types = priv->rss_conf.rss_hf,
8617 ctx->action_rss.key_len = priv->rss_conf.rss_key_len,
8618 ctx->action_rss.queue_num = priv->reta_idx_n,
8619 ctx->action_rss.key = priv->rss_conf.rss_key,
8620 ctx->action_rss.queue = ctx->queue;
8621 if (!priv->reta_idx_n || !priv->rxqs_n)
8622 return rte_flow_error_set
8624 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
8625 NULL, "invalid port configuration");
8626 if (!(dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG))
8627 ctx->action_rss.types = 0;
8628 for (i = 0; i != priv->reta_idx_n; ++i)
8629 ctx->queue[i] = (*priv->reta_idx)[i];
8631 miss_actions[1].type = RTE_FLOW_ACTION_TYPE_JUMP;
8632 ctx->miss_jump.group = MLX5_TNL_MISS_FDB_JUMP_GRP;
8634 miss_actions[1].conf = (typeof(miss_actions[1].conf))ctx->raw;
8635 for (; app_actions->type != RTE_FLOW_ACTION_TYPE_JUMP; app_actions++);
8636 jump_data = app_actions->conf;
8637 miss_attr.priority = MLX5_TNL_MISS_RULE_PRIORITY;
8638 miss_attr.group = jump_data->group;
8639 ret = mlx5_flow_group_to_table(dev, tunnel, jump_data->group,
8640 &flow_table, &grp_info, error);
8642 return rte_flow_error_set(error, EINVAL,
8643 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
8644 NULL, "invalid tunnel id");
8645 mark_id.app_reserve = 0;
8646 mark_id.table_id = tunnel_flow_tbl_to_id(flow_table);
8647 mark_id.transfer = !!attr->transfer;
8648 mark_id._unused_ = 0;
8649 miss_mark.id = mark_id.val;
8650 dev_flow = flow_drv_prepare(dev, flow, &miss_attr,
8651 miss_items, miss_actions, flow_idx, error);
8654 dev_flow->flow = flow;
8655 dev_flow->external = true;
8656 dev_flow->tunnel = tunnel;
8657 dev_flow->tof_type = MLX5_TUNNEL_OFFLOAD_MISS_RULE;
8658 /* Subflow object was created, we must include one in the list. */
8659 SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
8660 dev_flow->handle, next);
8662 "port %u tunnel type=%d id=%u miss rule priority=%u group=%u",
8663 dev->data->port_id, tunnel->app_tunnel.type,
8664 tunnel->tunnel_id, miss_attr.priority, miss_attr.group);
8665 ret = flow_drv_translate(dev, dev_flow, &miss_attr, miss_items,
8666 miss_actions, error);
8668 ret = flow_mreg_update_copy_table(dev, flow, miss_actions,
8674 static const struct mlx5_flow_tbl_data_entry *
8675 tunnel_mark_decode(struct rte_eth_dev *dev, uint32_t mark)
8677 struct mlx5_priv *priv = dev->data->dev_private;
8678 struct mlx5_dev_ctx_shared *sh = priv->sh;
8679 struct mlx5_list_entry *he;
8680 union tunnel_offload_mark mbits = { .val = mark };
8681 union mlx5_flow_tbl_key table_key = {
8683 .level = tunnel_id_to_flow_tbl(mbits.table_id),
8687 .is_fdb = !!mbits.transfer,
8691 struct mlx5_flow_cb_ctx ctx = {
8692 .data = &table_key.v64,
8695 he = mlx5_hlist_lookup(sh->flow_tbls, table_key.v64, &ctx);
8697 container_of(he, struct mlx5_flow_tbl_data_entry, entry) : NULL;
8701 mlx5_flow_tunnel_grp2tbl_remove_cb(void *tool_ctx,
8702 struct mlx5_list_entry *entry)
8704 struct mlx5_dev_ctx_shared *sh = tool_ctx;
8705 struct tunnel_tbl_entry *tte = container_of(entry, typeof(*tte), hash);
8707 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TNL_TBL_ID],
8708 tunnel_flow_tbl_to_id(tte->flow_table));
8713 mlx5_flow_tunnel_grp2tbl_match_cb(void *tool_ctx __rte_unused,
8714 struct mlx5_list_entry *entry, void *cb_ctx)
8716 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
8717 union tunnel_tbl_key tbl = {
8718 .val = *(uint64_t *)(ctx->data),
8720 struct tunnel_tbl_entry *tte = container_of(entry, typeof(*tte), hash);
8722 return tbl.tunnel_id != tte->tunnel_id || tbl.group != tte->group;
8725 static struct mlx5_list_entry *
8726 mlx5_flow_tunnel_grp2tbl_create_cb(void *tool_ctx, void *cb_ctx)
8728 struct mlx5_dev_ctx_shared *sh = tool_ctx;
8729 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
8730 struct tunnel_tbl_entry *tte;
8731 union tunnel_tbl_key tbl = {
8732 .val = *(uint64_t *)(ctx->data),
8735 tte = mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO,
8740 mlx5_ipool_malloc(sh->ipool[MLX5_IPOOL_TNL_TBL_ID],
8742 if (tte->flow_table >= MLX5_MAX_TABLES) {
8743 DRV_LOG(ERR, "Tunnel TBL ID %d exceed max limit.",
8745 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TNL_TBL_ID],
8748 } else if (!tte->flow_table) {
8751 tte->flow_table = tunnel_id_to_flow_tbl(tte->flow_table);
8752 tte->tunnel_id = tbl.tunnel_id;
8753 tte->group = tbl.group;
8761 static struct mlx5_list_entry *
8762 mlx5_flow_tunnel_grp2tbl_clone_cb(void *tool_ctx __rte_unused,
8763 struct mlx5_list_entry *oentry,
8764 void *cb_ctx __rte_unused)
8766 struct tunnel_tbl_entry *tte = mlx5_malloc(MLX5_MEM_SYS, sizeof(*tte),
8771 memcpy(tte, oentry, sizeof(*tte));
8776 mlx5_flow_tunnel_grp2tbl_clone_free_cb(void *tool_ctx __rte_unused,
8777 struct mlx5_list_entry *entry)
8779 struct tunnel_tbl_entry *tte = container_of(entry, typeof(*tte), hash);
8785 tunnel_flow_group_to_flow_table(struct rte_eth_dev *dev,
8786 const struct mlx5_flow_tunnel *tunnel,
8787 uint32_t group, uint32_t *table,
8788 struct rte_flow_error *error)
8790 struct mlx5_list_entry *he;
8791 struct tunnel_tbl_entry *tte;
8792 union tunnel_tbl_key key = {
8793 .tunnel_id = tunnel ? tunnel->tunnel_id : 0,
8796 struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
8797 struct mlx5_hlist *group_hash;
8798 struct mlx5_flow_cb_ctx ctx = {
8802 group_hash = tunnel ? tunnel->groups : thub->groups;
8803 he = mlx5_hlist_register(group_hash, key.val, &ctx);
8805 return rte_flow_error_set(error, EINVAL,
8806 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
8808 "tunnel group index not supported");
8809 tte = container_of(he, typeof(*tte), hash);
8810 *table = tte->flow_table;
8811 DRV_LOG(DEBUG, "port %u tunnel %u group=%#x table=%#x",
8812 dev->data->port_id, key.tunnel_id, group, *table);
8817 mlx5_flow_tunnel_free(struct rte_eth_dev *dev,
8818 struct mlx5_flow_tunnel *tunnel)
8820 struct mlx5_priv *priv = dev->data->dev_private;
8821 struct mlx5_indexed_pool *ipool;
8823 DRV_LOG(DEBUG, "port %u release pmd tunnel id=0x%x",
8824 dev->data->port_id, tunnel->tunnel_id);
8825 LIST_REMOVE(tunnel, chain);
8826 mlx5_hlist_destroy(tunnel->groups);
8827 ipool = priv->sh->ipool[MLX5_IPOOL_TUNNEL_ID];
8828 mlx5_ipool_free(ipool, tunnel->tunnel_id);
8832 mlx5_access_tunnel_offload_db
8833 (struct rte_eth_dev *dev,
8834 bool (*match)(struct rte_eth_dev *,
8835 struct mlx5_flow_tunnel *, const void *),
8836 void (*hit)(struct rte_eth_dev *, struct mlx5_flow_tunnel *, void *),
8837 void (*miss)(struct rte_eth_dev *, void *),
8838 void *ctx, bool lock_op)
8840 bool verdict = false;
8841 struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
8842 struct mlx5_flow_tunnel *tunnel;
8844 rte_spinlock_lock(&thub->sl);
8845 LIST_FOREACH(tunnel, &thub->tunnels, chain) {
8846 verdict = match(dev, tunnel, (const void *)ctx);
8851 rte_spinlock_unlock(&thub->sl);
8853 hit(dev, tunnel, ctx);
8854 if (!verdict && miss)
8857 rte_spinlock_unlock(&thub->sl);
8862 struct tunnel_db_find_tunnel_id_ctx {
8864 struct mlx5_flow_tunnel *tunnel;
8868 find_tunnel_id_match(struct rte_eth_dev *dev,
8869 struct mlx5_flow_tunnel *tunnel, const void *x)
8871 const struct tunnel_db_find_tunnel_id_ctx *ctx = x;
8874 return tunnel->tunnel_id == ctx->tunnel_id;
8878 find_tunnel_id_hit(struct rte_eth_dev *dev,
8879 struct mlx5_flow_tunnel *tunnel, void *x)
8881 struct tunnel_db_find_tunnel_id_ctx *ctx = x;
8883 ctx->tunnel = tunnel;
8886 static struct mlx5_flow_tunnel *
8887 mlx5_find_tunnel_id(struct rte_eth_dev *dev, uint32_t id)
8889 struct tunnel_db_find_tunnel_id_ctx ctx = {
8893 mlx5_access_tunnel_offload_db(dev, find_tunnel_id_match,
8894 find_tunnel_id_hit, NULL, &ctx, true);
8899 static struct mlx5_flow_tunnel *
8900 mlx5_flow_tunnel_allocate(struct rte_eth_dev *dev,
8901 const struct rte_flow_tunnel *app_tunnel)
8903 struct mlx5_priv *priv = dev->data->dev_private;
8904 struct mlx5_indexed_pool *ipool;
8905 struct mlx5_flow_tunnel *tunnel;
8908 ipool = priv->sh->ipool[MLX5_IPOOL_TUNNEL_ID];
8909 tunnel = mlx5_ipool_zmalloc(ipool, &id);
8912 if (id >= MLX5_MAX_TUNNELS) {
8913 mlx5_ipool_free(ipool, id);
8914 DRV_LOG(ERR, "Tunnel ID %d exceed max limit.", id);
8917 tunnel->groups = mlx5_hlist_create("tunnel groups", 64, false, true,
8919 mlx5_flow_tunnel_grp2tbl_create_cb,
8920 mlx5_flow_tunnel_grp2tbl_match_cb,
8921 mlx5_flow_tunnel_grp2tbl_remove_cb,
8922 mlx5_flow_tunnel_grp2tbl_clone_cb,
8923 mlx5_flow_tunnel_grp2tbl_clone_free_cb);
8924 if (!tunnel->groups) {
8925 mlx5_ipool_free(ipool, id);
8928 /* initiate new PMD tunnel */
8929 memcpy(&tunnel->app_tunnel, app_tunnel, sizeof(*app_tunnel));
8930 tunnel->tunnel_id = id;
8931 tunnel->action.type = (typeof(tunnel->action.type))
8932 MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET;
8933 tunnel->action.conf = tunnel;
8934 tunnel->item.type = (typeof(tunnel->item.type))
8935 MLX5_RTE_FLOW_ITEM_TYPE_TUNNEL;
8936 tunnel->item.spec = tunnel;
8937 tunnel->item.last = NULL;
8938 tunnel->item.mask = NULL;
8940 DRV_LOG(DEBUG, "port %u new pmd tunnel id=0x%x",
8941 dev->data->port_id, tunnel->tunnel_id);
8946 struct tunnel_db_get_tunnel_ctx {
8947 const struct rte_flow_tunnel *app_tunnel;
8948 struct mlx5_flow_tunnel *tunnel;
8951 static bool get_tunnel_match(struct rte_eth_dev *dev,
8952 struct mlx5_flow_tunnel *tunnel, const void *x)
8954 const struct tunnel_db_get_tunnel_ctx *ctx = x;
8957 return !memcmp(ctx->app_tunnel, &tunnel->app_tunnel,
8958 sizeof(*ctx->app_tunnel));
8961 static void get_tunnel_hit(struct rte_eth_dev *dev,
8962 struct mlx5_flow_tunnel *tunnel, void *x)
8964 /* called under tunnel spinlock protection */
8965 struct tunnel_db_get_tunnel_ctx *ctx = x;
8969 ctx->tunnel = tunnel;
8972 static void get_tunnel_miss(struct rte_eth_dev *dev, void *x)
8974 /* called under tunnel spinlock protection */
8975 struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
8976 struct tunnel_db_get_tunnel_ctx *ctx = x;
8978 rte_spinlock_unlock(&thub->sl);
8979 ctx->tunnel = mlx5_flow_tunnel_allocate(dev, ctx->app_tunnel);
8980 rte_spinlock_lock(&thub->sl);
8982 ctx->tunnel->refctn = 1;
8983 LIST_INSERT_HEAD(&thub->tunnels, ctx->tunnel, chain);
8989 mlx5_get_flow_tunnel(struct rte_eth_dev *dev,
8990 const struct rte_flow_tunnel *app_tunnel,
8991 struct mlx5_flow_tunnel **tunnel)
8993 struct tunnel_db_get_tunnel_ctx ctx = {
8994 .app_tunnel = app_tunnel,
8997 mlx5_access_tunnel_offload_db(dev, get_tunnel_match, get_tunnel_hit,
8998 get_tunnel_miss, &ctx, true);
8999 *tunnel = ctx.tunnel;
9000 return ctx.tunnel ? 0 : -ENOMEM;
9003 void mlx5_release_tunnel_hub(struct mlx5_dev_ctx_shared *sh, uint16_t port_id)
9005 struct mlx5_flow_tunnel_hub *thub = sh->tunnel_hub;
9009 if (!LIST_EMPTY(&thub->tunnels))
9010 DRV_LOG(WARNING, "port %u tunnels present", port_id);
9011 mlx5_hlist_destroy(thub->groups);
9015 int mlx5_alloc_tunnel_hub(struct mlx5_dev_ctx_shared *sh)
9018 struct mlx5_flow_tunnel_hub *thub;
9020 thub = mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO, sizeof(*thub),
9024 LIST_INIT(&thub->tunnels);
9025 rte_spinlock_init(&thub->sl);
9026 thub->groups = mlx5_hlist_create("flow groups", 64,
9028 mlx5_flow_tunnel_grp2tbl_create_cb,
9029 mlx5_flow_tunnel_grp2tbl_match_cb,
9030 mlx5_flow_tunnel_grp2tbl_remove_cb,
9031 mlx5_flow_tunnel_grp2tbl_clone_cb,
9032 mlx5_flow_tunnel_grp2tbl_clone_free_cb);
9033 if (!thub->groups) {
9037 sh->tunnel_hub = thub;
9043 mlx5_hlist_destroy(thub->groups);
9050 mlx5_flow_tunnel_validate(struct rte_eth_dev *dev,
9051 struct rte_flow_tunnel *tunnel,
9052 const char *err_msg)
9055 if (!is_tunnel_offload_active(dev)) {
9056 err_msg = "tunnel offload was not activated";
9058 } else if (!tunnel) {
9059 err_msg = "no application tunnel";
9063 switch (tunnel->type) {
9065 err_msg = "unsupported tunnel type";
9067 case RTE_FLOW_ITEM_TYPE_VXLAN:
9076 mlx5_flow_tunnel_decap_set(struct rte_eth_dev *dev,
9077 struct rte_flow_tunnel *app_tunnel,
9078 struct rte_flow_action **actions,
9079 uint32_t *num_of_actions,
9080 struct rte_flow_error *error)
9083 struct mlx5_flow_tunnel *tunnel;
9084 const char *err_msg = NULL;
9085 bool verdict = mlx5_flow_tunnel_validate(dev, app_tunnel, err_msg);
9088 return rte_flow_error_set(error, EINVAL,
9089 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
9091 ret = mlx5_get_flow_tunnel(dev, app_tunnel, &tunnel);
9093 return rte_flow_error_set(error, ret,
9094 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
9095 "failed to initialize pmd tunnel");
9097 *actions = &tunnel->action;
9098 *num_of_actions = 1;
9103 mlx5_flow_tunnel_match(struct rte_eth_dev *dev,
9104 struct rte_flow_tunnel *app_tunnel,
9105 struct rte_flow_item **items,
9106 uint32_t *num_of_items,
9107 struct rte_flow_error *error)
9110 struct mlx5_flow_tunnel *tunnel;
9111 const char *err_msg = NULL;
9112 bool verdict = mlx5_flow_tunnel_validate(dev, app_tunnel, err_msg);
9115 return rte_flow_error_set(error, EINVAL,
9116 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
9118 ret = mlx5_get_flow_tunnel(dev, app_tunnel, &tunnel);
9120 return rte_flow_error_set(error, ret,
9121 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
9122 "failed to initialize pmd tunnel");
9124 *items = &tunnel->item;
9129 struct tunnel_db_element_release_ctx {
9130 struct rte_flow_item *items;
9131 struct rte_flow_action *actions;
9132 uint32_t num_elements;
9133 struct rte_flow_error *error;
9138 tunnel_element_release_match(struct rte_eth_dev *dev,
9139 struct mlx5_flow_tunnel *tunnel, const void *x)
9141 const struct tunnel_db_element_release_ctx *ctx = x;
9144 if (ctx->num_elements != 1)
9146 else if (ctx->items)
9147 return ctx->items == &tunnel->item;
9148 else if (ctx->actions)
9149 return ctx->actions == &tunnel->action;
9155 tunnel_element_release_hit(struct rte_eth_dev *dev,
9156 struct mlx5_flow_tunnel *tunnel, void *x)
9158 struct tunnel_db_element_release_ctx *ctx = x;
9160 if (!__atomic_sub_fetch(&tunnel->refctn, 1, __ATOMIC_RELAXED))
9161 mlx5_flow_tunnel_free(dev, tunnel);
9165 tunnel_element_release_miss(struct rte_eth_dev *dev, void *x)
9167 struct tunnel_db_element_release_ctx *ctx = x;
9169 ctx->ret = rte_flow_error_set(ctx->error, EINVAL,
9170 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
9171 "invalid argument");
9175 mlx5_flow_tunnel_item_release(struct rte_eth_dev *dev,
9176 struct rte_flow_item *pmd_items,
9177 uint32_t num_items, struct rte_flow_error *err)
9179 struct tunnel_db_element_release_ctx ctx = {
9182 .num_elements = num_items,
9186 mlx5_access_tunnel_offload_db(dev, tunnel_element_release_match,
9187 tunnel_element_release_hit,
9188 tunnel_element_release_miss, &ctx, false);
9194 mlx5_flow_tunnel_action_release(struct rte_eth_dev *dev,
9195 struct rte_flow_action *pmd_actions,
9196 uint32_t num_actions, struct rte_flow_error *err)
9198 struct tunnel_db_element_release_ctx ctx = {
9200 .actions = pmd_actions,
9201 .num_elements = num_actions,
9205 mlx5_access_tunnel_offload_db(dev, tunnel_element_release_match,
9206 tunnel_element_release_hit,
9207 tunnel_element_release_miss, &ctx, false);
9213 mlx5_flow_tunnel_get_restore_info(struct rte_eth_dev *dev,
9215 struct rte_flow_restore_info *info,
9216 struct rte_flow_error *err)
9218 uint64_t ol_flags = m->ol_flags;
9219 const struct mlx5_flow_tbl_data_entry *tble;
9220 const uint64_t mask = PKT_RX_FDIR | PKT_RX_FDIR_ID;
9222 if (!is_tunnel_offload_active(dev)) {
9227 if ((ol_flags & mask) != mask)
9229 tble = tunnel_mark_decode(dev, m->hash.fdir.hi);
9231 DRV_LOG(DEBUG, "port %u invalid miss tunnel mark %#x",
9232 dev->data->port_id, m->hash.fdir.hi);
9235 MLX5_ASSERT(tble->tunnel);
9236 memcpy(&info->tunnel, &tble->tunnel->app_tunnel, sizeof(info->tunnel));
9237 info->group_id = tble->group_id;
9238 info->flags = RTE_FLOW_RESTORE_INFO_TUNNEL |
9239 RTE_FLOW_RESTORE_INFO_GROUP_ID |
9240 RTE_FLOW_RESTORE_INFO_ENCAPSULATED;
9245 return rte_flow_error_set(err, EINVAL,
9246 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
9247 "failed to get restore info");
9250 #else /* HAVE_IBV_FLOW_DV_SUPPORT */
9252 mlx5_flow_tunnel_decap_set(__rte_unused struct rte_eth_dev *dev,
9253 __rte_unused struct rte_flow_tunnel *app_tunnel,
9254 __rte_unused struct rte_flow_action **actions,
9255 __rte_unused uint32_t *num_of_actions,
9256 __rte_unused struct rte_flow_error *error)
9262 mlx5_flow_tunnel_match(__rte_unused struct rte_eth_dev *dev,
9263 __rte_unused struct rte_flow_tunnel *app_tunnel,
9264 __rte_unused struct rte_flow_item **items,
9265 __rte_unused uint32_t *num_of_items,
9266 __rte_unused struct rte_flow_error *error)
9272 mlx5_flow_tunnel_item_release(__rte_unused struct rte_eth_dev *dev,
9273 __rte_unused struct rte_flow_item *pmd_items,
9274 __rte_unused uint32_t num_items,
9275 __rte_unused struct rte_flow_error *err)
9281 mlx5_flow_tunnel_action_release(__rte_unused struct rte_eth_dev *dev,
9282 __rte_unused struct rte_flow_action *pmd_action,
9283 __rte_unused uint32_t num_actions,
9284 __rte_unused struct rte_flow_error *err)
9290 mlx5_flow_tunnel_get_restore_info(__rte_unused struct rte_eth_dev *dev,
9291 __rte_unused struct rte_mbuf *m,
9292 __rte_unused struct rte_flow_restore_info *i,
9293 __rte_unused struct rte_flow_error *err)
9299 flow_tunnel_add_default_miss(__rte_unused struct rte_eth_dev *dev,
9300 __rte_unused struct rte_flow *flow,
9301 __rte_unused const struct rte_flow_attr *attr,
9302 __rte_unused const struct rte_flow_action *actions,
9303 __rte_unused uint32_t flow_idx,
9304 __rte_unused const struct mlx5_flow_tunnel *tunnel,
9305 __rte_unused struct tunnel_default_miss_ctx *ctx,
9306 __rte_unused struct rte_flow_error *error)
9311 static struct mlx5_flow_tunnel *
9312 mlx5_find_tunnel_id(__rte_unused struct rte_eth_dev *dev,
9313 __rte_unused uint32_t id)
9319 mlx5_flow_tunnel_free(__rte_unused struct rte_eth_dev *dev,
9320 __rte_unused struct mlx5_flow_tunnel *tunnel)
9325 tunnel_flow_group_to_flow_table(__rte_unused struct rte_eth_dev *dev,
9326 __rte_unused const struct mlx5_flow_tunnel *t,
9327 __rte_unused uint32_t group,
9328 __rte_unused uint32_t *table,
9329 struct rte_flow_error *error)
9331 return rte_flow_error_set(error, ENOTSUP,
9332 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
9333 "tunnel offload requires DV support");
9337 mlx5_release_tunnel_hub(__rte_unused struct mlx5_dev_ctx_shared *sh,
9338 __rte_unused uint16_t port_id)
9341 #endif /* HAVE_IBV_FLOW_DV_SUPPORT */
9344 mlx5_dbg__print_pattern(const struct rte_flow_item *item)
9347 struct rte_flow_error error;
9349 for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
9351 ret = rte_flow_conv(RTE_FLOW_CONV_OP_ITEM_NAME_PTR, &item_name,
9353 (void *)(uintptr_t)item->type, &error);
9355 printf("%s ", item_name);
9357 printf("%d\n", (int)item->type);