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,
586 [MLX5_EXPANSION_ETH] = {
587 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
588 MLX5_EXPANSION_IPV6),
589 .type = RTE_FLOW_ITEM_TYPE_ETH,
591 [MLX5_EXPANSION_ETH_VLAN] = {
592 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VLAN),
593 .type = RTE_FLOW_ITEM_TYPE_ETH,
595 [MLX5_EXPANSION_VLAN] = {
596 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
597 MLX5_EXPANSION_IPV6),
598 .type = RTE_FLOW_ITEM_TYPE_VLAN,
600 [MLX5_EXPANSION_IPV4] = {
601 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4_UDP,
602 MLX5_EXPANSION_IPV4_TCP),
603 .type = RTE_FLOW_ITEM_TYPE_IPV4,
604 .rss_types = ETH_RSS_IPV4 | ETH_RSS_FRAG_IPV4 |
605 ETH_RSS_NONFRAG_IPV4_OTHER,
607 [MLX5_EXPANSION_IPV4_UDP] = {
608 .type = RTE_FLOW_ITEM_TYPE_UDP,
609 .rss_types = ETH_RSS_NONFRAG_IPV4_UDP,
611 [MLX5_EXPANSION_IPV4_TCP] = {
612 .type = RTE_FLOW_ITEM_TYPE_TCP,
613 .rss_types = ETH_RSS_NONFRAG_IPV4_TCP,
615 [MLX5_EXPANSION_IPV6] = {
616 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV6_UDP,
617 MLX5_EXPANSION_IPV6_TCP,
618 MLX5_EXPANSION_IPV6_FRAG_EXT),
619 .type = RTE_FLOW_ITEM_TYPE_IPV6,
620 .rss_types = ETH_RSS_IPV6 | ETH_RSS_FRAG_IPV6 |
621 ETH_RSS_NONFRAG_IPV6_OTHER,
623 [MLX5_EXPANSION_IPV6_UDP] = {
624 .type = RTE_FLOW_ITEM_TYPE_UDP,
625 .rss_types = ETH_RSS_NONFRAG_IPV6_UDP,
627 [MLX5_EXPANSION_IPV6_TCP] = {
628 .type = RTE_FLOW_ITEM_TYPE_TCP,
629 .rss_types = ETH_RSS_NONFRAG_IPV6_TCP,
631 [MLX5_EXPANSION_IPV6_FRAG_EXT] = {
632 .type = RTE_FLOW_ITEM_TYPE_IPV6_FRAG_EXT,
634 [MLX5_EXPANSION_GTP] = {
635 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
636 MLX5_EXPANSION_IPV6),
637 .type = RTE_FLOW_ITEM_TYPE_GTP
641 static struct rte_flow_action_handle *
642 mlx5_action_handle_create(struct rte_eth_dev *dev,
643 const struct rte_flow_indir_action_conf *conf,
644 const struct rte_flow_action *action,
645 struct rte_flow_error *error);
646 static int mlx5_action_handle_destroy
647 (struct rte_eth_dev *dev,
648 struct rte_flow_action_handle *handle,
649 struct rte_flow_error *error);
650 static int mlx5_action_handle_update
651 (struct rte_eth_dev *dev,
652 struct rte_flow_action_handle *handle,
654 struct rte_flow_error *error);
655 static int mlx5_action_handle_query
656 (struct rte_eth_dev *dev,
657 const struct rte_flow_action_handle *handle,
659 struct rte_flow_error *error);
661 mlx5_flow_tunnel_decap_set(struct rte_eth_dev *dev,
662 struct rte_flow_tunnel *app_tunnel,
663 struct rte_flow_action **actions,
664 uint32_t *num_of_actions,
665 struct rte_flow_error *error);
667 mlx5_flow_tunnel_match(struct rte_eth_dev *dev,
668 struct rte_flow_tunnel *app_tunnel,
669 struct rte_flow_item **items,
670 uint32_t *num_of_items,
671 struct rte_flow_error *error);
673 mlx5_flow_tunnel_item_release(struct rte_eth_dev *dev,
674 struct rte_flow_item *pmd_items,
675 uint32_t num_items, struct rte_flow_error *err);
677 mlx5_flow_tunnel_action_release(struct rte_eth_dev *dev,
678 struct rte_flow_action *pmd_actions,
679 uint32_t num_actions,
680 struct rte_flow_error *err);
682 mlx5_flow_tunnel_get_restore_info(struct rte_eth_dev *dev,
684 struct rte_flow_restore_info *info,
685 struct rte_flow_error *err);
687 static const struct rte_flow_ops mlx5_flow_ops = {
688 .validate = mlx5_flow_validate,
689 .create = mlx5_flow_create,
690 .destroy = mlx5_flow_destroy,
691 .flush = mlx5_flow_flush,
692 .isolate = mlx5_flow_isolate,
693 .query = mlx5_flow_query,
694 .dev_dump = mlx5_flow_dev_dump,
695 .get_aged_flows = mlx5_flow_get_aged_flows,
696 .action_handle_create = mlx5_action_handle_create,
697 .action_handle_destroy = mlx5_action_handle_destroy,
698 .action_handle_update = mlx5_action_handle_update,
699 .action_handle_query = mlx5_action_handle_query,
700 .tunnel_decap_set = mlx5_flow_tunnel_decap_set,
701 .tunnel_match = mlx5_flow_tunnel_match,
702 .tunnel_action_decap_release = mlx5_flow_tunnel_action_release,
703 .tunnel_item_release = mlx5_flow_tunnel_item_release,
704 .get_restore_info = mlx5_flow_tunnel_get_restore_info,
707 /* Tunnel information. */
708 struct mlx5_flow_tunnel_info {
709 uint64_t tunnel; /**< Tunnel bit (see MLX5_FLOW_*). */
710 uint32_t ptype; /**< Tunnel Ptype (see RTE_PTYPE_*). */
713 static struct mlx5_flow_tunnel_info tunnels_info[] = {
715 .tunnel = MLX5_FLOW_LAYER_VXLAN,
716 .ptype = RTE_PTYPE_TUNNEL_VXLAN | RTE_PTYPE_L4_UDP,
719 .tunnel = MLX5_FLOW_LAYER_GENEVE,
720 .ptype = RTE_PTYPE_TUNNEL_GENEVE | RTE_PTYPE_L4_UDP,
723 .tunnel = MLX5_FLOW_LAYER_VXLAN_GPE,
724 .ptype = RTE_PTYPE_TUNNEL_VXLAN_GPE | RTE_PTYPE_L4_UDP,
727 .tunnel = MLX5_FLOW_LAYER_GRE,
728 .ptype = RTE_PTYPE_TUNNEL_GRE,
731 .tunnel = MLX5_FLOW_LAYER_MPLS | MLX5_FLOW_LAYER_OUTER_L4_UDP,
732 .ptype = RTE_PTYPE_TUNNEL_MPLS_IN_UDP | RTE_PTYPE_L4_UDP,
735 .tunnel = MLX5_FLOW_LAYER_MPLS,
736 .ptype = RTE_PTYPE_TUNNEL_MPLS_IN_GRE,
739 .tunnel = MLX5_FLOW_LAYER_NVGRE,
740 .ptype = RTE_PTYPE_TUNNEL_NVGRE,
743 .tunnel = MLX5_FLOW_LAYER_IPIP,
744 .ptype = RTE_PTYPE_TUNNEL_IP,
747 .tunnel = MLX5_FLOW_LAYER_IPV6_ENCAP,
748 .ptype = RTE_PTYPE_TUNNEL_IP,
751 .tunnel = MLX5_FLOW_LAYER_GTP,
752 .ptype = RTE_PTYPE_TUNNEL_GTPU,
759 * Translate tag ID to register.
762 * Pointer to the Ethernet device structure.
764 * The feature that request the register.
766 * The request register ID.
768 * Error description in case of any.
771 * The request register on success, a negative errno
772 * value otherwise and rte_errno is set.
775 mlx5_flow_get_reg_id(struct rte_eth_dev *dev,
776 enum mlx5_feature_name feature,
778 struct rte_flow_error *error)
780 struct mlx5_priv *priv = dev->data->dev_private;
781 struct mlx5_dev_config *config = &priv->config;
782 enum modify_reg start_reg;
783 bool skip_mtr_reg = false;
786 case MLX5_HAIRPIN_RX:
788 case MLX5_HAIRPIN_TX:
790 case MLX5_METADATA_RX:
791 switch (config->dv_xmeta_en) {
792 case MLX5_XMETA_MODE_LEGACY:
794 case MLX5_XMETA_MODE_META16:
796 case MLX5_XMETA_MODE_META32:
800 case MLX5_METADATA_TX:
802 case MLX5_METADATA_FDB:
803 switch (config->dv_xmeta_en) {
804 case MLX5_XMETA_MODE_LEGACY:
806 case MLX5_XMETA_MODE_META16:
808 case MLX5_XMETA_MODE_META32:
813 switch (config->dv_xmeta_en) {
814 case MLX5_XMETA_MODE_LEGACY:
816 case MLX5_XMETA_MODE_META16:
818 case MLX5_XMETA_MODE_META32:
824 * If meter color and meter id share one register, flow match
825 * should use the meter color register for match.
827 if (priv->mtr_reg_share)
828 return priv->mtr_color_reg;
830 return priv->mtr_color_reg != REG_C_2 ? REG_C_2 :
833 case MLX5_ASO_FLOW_HIT:
834 case MLX5_ASO_CONNTRACK:
835 /* All features use the same REG_C. */
836 MLX5_ASSERT(priv->mtr_color_reg != REG_NON);
837 return priv->mtr_color_reg;
840 * Metadata COPY_MARK register using is in meter suffix sub
841 * flow while with meter. It's safe to share the same register.
843 return priv->mtr_color_reg != REG_C_2 ? REG_C_2 : REG_C_3;
846 * If meter is enable, it will engage the register for color
847 * match and flow match. If meter color match is not using the
848 * REG_C_2, need to skip the REG_C_x be used by meter color
850 * If meter is disable, free to use all available registers.
852 start_reg = priv->mtr_color_reg != REG_C_2 ? REG_C_2 :
853 (priv->mtr_reg_share ? REG_C_3 : REG_C_4);
854 skip_mtr_reg = !!(priv->mtr_en && start_reg == REG_C_2);
855 if (id > (uint32_t)(REG_C_7 - start_reg))
856 return rte_flow_error_set(error, EINVAL,
857 RTE_FLOW_ERROR_TYPE_ITEM,
858 NULL, "invalid tag id");
859 if (config->flow_mreg_c[id + start_reg - REG_C_0] == REG_NON)
860 return rte_flow_error_set(error, ENOTSUP,
861 RTE_FLOW_ERROR_TYPE_ITEM,
862 NULL, "unsupported tag id");
864 * This case means meter is using the REG_C_x great than 2.
865 * Take care not to conflict with meter color REG_C_x.
866 * If the available index REG_C_y >= REG_C_x, skip the
869 if (skip_mtr_reg && config->flow_mreg_c
870 [id + start_reg - REG_C_0] >= priv->mtr_color_reg) {
871 if (id >= (uint32_t)(REG_C_7 - start_reg))
872 return rte_flow_error_set(error, EINVAL,
873 RTE_FLOW_ERROR_TYPE_ITEM,
874 NULL, "invalid tag id");
875 if (config->flow_mreg_c
876 [id + 1 + start_reg - REG_C_0] != REG_NON)
877 return config->flow_mreg_c
878 [id + 1 + start_reg - REG_C_0];
879 return rte_flow_error_set(error, ENOTSUP,
880 RTE_FLOW_ERROR_TYPE_ITEM,
881 NULL, "unsupported tag id");
883 return config->flow_mreg_c[id + start_reg - REG_C_0];
886 return rte_flow_error_set(error, EINVAL,
887 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
888 NULL, "invalid feature name");
892 * Check extensive flow metadata register support.
895 * Pointer to rte_eth_dev structure.
898 * True if device supports extensive flow metadata register, otherwise false.
901 mlx5_flow_ext_mreg_supported(struct rte_eth_dev *dev)
903 struct mlx5_priv *priv = dev->data->dev_private;
904 struct mlx5_dev_config *config = &priv->config;
907 * Having available reg_c can be regarded inclusively as supporting
908 * extensive flow metadata register, which could mean,
909 * - metadata register copy action by modify header.
910 * - 16 modify header actions is supported.
911 * - reg_c's are preserved across different domain (FDB and NIC) on
912 * packet loopback by flow lookup miss.
914 return config->flow_mreg_c[2] != REG_NON;
918 * Get the lowest priority.
921 * Pointer to the Ethernet device structure.
922 * @param[in] attributes
923 * Pointer to device flow rule attributes.
926 * The value of lowest priority of flow.
929 mlx5_get_lowest_priority(struct rte_eth_dev *dev,
930 const struct rte_flow_attr *attr)
932 struct mlx5_priv *priv = dev->data->dev_private;
934 if (!attr->group && !attr->transfer)
935 return priv->config.flow_prio - 2;
936 return MLX5_NON_ROOT_FLOW_MAX_PRIO - 1;
940 * Calculate matcher priority of the flow.
943 * Pointer to the Ethernet device structure.
945 * Pointer to device flow rule attributes.
946 * @param[in] subpriority
947 * The priority based on the items.
949 * The matcher priority of the flow.
952 mlx5_get_matcher_priority(struct rte_eth_dev *dev,
953 const struct rte_flow_attr *attr,
954 uint32_t subpriority)
956 uint16_t priority = (uint16_t)attr->priority;
957 struct mlx5_priv *priv = dev->data->dev_private;
959 if (!attr->group && !attr->transfer) {
960 if (attr->priority == MLX5_FLOW_LOWEST_PRIO_INDICATOR)
961 priority = priv->config.flow_prio - 1;
962 return mlx5_os_flow_adjust_priority(dev, priority, subpriority);
964 if (attr->priority == MLX5_FLOW_LOWEST_PRIO_INDICATOR)
965 priority = MLX5_NON_ROOT_FLOW_MAX_PRIO;
966 return priority * 3 + subpriority;
970 * Verify the @p item specifications (spec, last, mask) are compatible with the
974 * Item specification.
976 * @p item->mask or flow default bit-masks.
977 * @param[in] nic_mask
978 * Bit-masks covering supported fields by the NIC to compare with user mask.
980 * Bit-masks size in bytes.
981 * @param[in] range_accepted
982 * True if range of values is accepted for specific fields, false otherwise.
984 * Pointer to error structure.
987 * 0 on success, a negative errno value otherwise and rte_errno is set.
990 mlx5_flow_item_acceptable(const struct rte_flow_item *item,
992 const uint8_t *nic_mask,
995 struct rte_flow_error *error)
999 MLX5_ASSERT(nic_mask);
1000 for (i = 0; i < size; ++i)
1001 if ((nic_mask[i] | mask[i]) != nic_mask[i])
1002 return rte_flow_error_set(error, ENOTSUP,
1003 RTE_FLOW_ERROR_TYPE_ITEM,
1005 "mask enables non supported"
1007 if (!item->spec && (item->mask || item->last))
1008 return rte_flow_error_set(error, EINVAL,
1009 RTE_FLOW_ERROR_TYPE_ITEM, item,
1010 "mask/last without a spec is not"
1012 if (item->spec && item->last && !range_accepted) {
1018 for (i = 0; i < size; ++i) {
1019 spec[i] = ((const uint8_t *)item->spec)[i] & mask[i];
1020 last[i] = ((const uint8_t *)item->last)[i] & mask[i];
1022 ret = memcmp(spec, last, size);
1024 return rte_flow_error_set(error, EINVAL,
1025 RTE_FLOW_ERROR_TYPE_ITEM,
1027 "range is not valid");
1033 * Adjust the hash fields according to the @p flow information.
1035 * @param[in] dev_flow.
1036 * Pointer to the mlx5_flow.
1038 * 1 when the hash field is for a tunnel item.
1039 * @param[in] layer_types
1041 * @param[in] hash_fields
1045 * The hash fields that should be used.
1048 mlx5_flow_hashfields_adjust(struct mlx5_flow_rss_desc *rss_desc,
1049 int tunnel __rte_unused, uint64_t layer_types,
1050 uint64_t hash_fields)
1052 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
1053 int rss_request_inner = rss_desc->level >= 2;
1055 /* Check RSS hash level for tunnel. */
1056 if (tunnel && rss_request_inner)
1057 hash_fields |= IBV_RX_HASH_INNER;
1058 else if (tunnel || rss_request_inner)
1061 /* Check if requested layer matches RSS hash fields. */
1062 if (!(rss_desc->types & layer_types))
1068 * Lookup and set the ptype in the data Rx part. A single Ptype can be used,
1069 * if several tunnel rules are used on this queue, the tunnel ptype will be
1073 * Rx queue to update.
1076 flow_rxq_tunnel_ptype_update(struct mlx5_rxq_ctrl *rxq_ctrl)
1079 uint32_t tunnel_ptype = 0;
1081 /* Look up for the ptype to use. */
1082 for (i = 0; i != MLX5_FLOW_TUNNEL; ++i) {
1083 if (!rxq_ctrl->flow_tunnels_n[i])
1085 if (!tunnel_ptype) {
1086 tunnel_ptype = tunnels_info[i].ptype;
1092 rxq_ctrl->rxq.tunnel = tunnel_ptype;
1096 * Set the Rx queue flags (Mark/Flag and Tunnel Ptypes) according to the devive
1100 * Pointer to the Ethernet device structure.
1101 * @param[in] dev_handle
1102 * Pointer to device flow handle structure.
1105 flow_drv_rxq_flags_set(struct rte_eth_dev *dev,
1106 struct mlx5_flow_handle *dev_handle)
1108 struct mlx5_priv *priv = dev->data->dev_private;
1109 const int mark = dev_handle->mark;
1110 const int tunnel = !!(dev_handle->layers & MLX5_FLOW_LAYER_TUNNEL);
1111 struct mlx5_ind_table_obj *ind_tbl = NULL;
1114 if (dev_handle->fate_action == MLX5_FLOW_FATE_QUEUE) {
1115 struct mlx5_hrxq *hrxq;
1117 hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
1118 dev_handle->rix_hrxq);
1120 ind_tbl = hrxq->ind_table;
1121 } else if (dev_handle->fate_action == MLX5_FLOW_FATE_SHARED_RSS) {
1122 struct mlx5_shared_action_rss *shared_rss;
1124 shared_rss = mlx5_ipool_get
1125 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
1126 dev_handle->rix_srss);
1128 ind_tbl = shared_rss->ind_tbl;
1132 for (i = 0; i != ind_tbl->queues_n; ++i) {
1133 int idx = ind_tbl->queues[i];
1134 struct mlx5_rxq_ctrl *rxq_ctrl =
1135 container_of((*priv->rxqs)[idx],
1136 struct mlx5_rxq_ctrl, rxq);
1139 * To support metadata register copy on Tx loopback,
1140 * this must be always enabled (metadata may arive
1141 * from other port - not from local flows only.
1143 if (priv->config.dv_flow_en &&
1144 priv->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
1145 mlx5_flow_ext_mreg_supported(dev)) {
1146 rxq_ctrl->rxq.mark = 1;
1147 rxq_ctrl->flow_mark_n = 1;
1149 rxq_ctrl->rxq.mark = 1;
1150 rxq_ctrl->flow_mark_n++;
1155 /* Increase the counter matching the flow. */
1156 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j) {
1157 if ((tunnels_info[j].tunnel &
1158 dev_handle->layers) ==
1159 tunnels_info[j].tunnel) {
1160 rxq_ctrl->flow_tunnels_n[j]++;
1164 flow_rxq_tunnel_ptype_update(rxq_ctrl);
1170 * Set the Rx queue flags (Mark/Flag and Tunnel Ptypes) for a flow
1173 * Pointer to the Ethernet device structure.
1175 * Pointer to flow structure.
1178 flow_rxq_flags_set(struct rte_eth_dev *dev, struct rte_flow *flow)
1180 struct mlx5_priv *priv = dev->data->dev_private;
1181 uint32_t handle_idx;
1182 struct mlx5_flow_handle *dev_handle;
1184 SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
1185 handle_idx, dev_handle, next)
1186 flow_drv_rxq_flags_set(dev, dev_handle);
1190 * Clear the Rx queue flags (Mark/Flag and Tunnel Ptype) associated with the
1191 * device flow if no other flow uses it with the same kind of request.
1194 * Pointer to Ethernet device.
1195 * @param[in] dev_handle
1196 * Pointer to the device flow handle structure.
1199 flow_drv_rxq_flags_trim(struct rte_eth_dev *dev,
1200 struct mlx5_flow_handle *dev_handle)
1202 struct mlx5_priv *priv = dev->data->dev_private;
1203 const int mark = dev_handle->mark;
1204 const int tunnel = !!(dev_handle->layers & MLX5_FLOW_LAYER_TUNNEL);
1205 struct mlx5_ind_table_obj *ind_tbl = NULL;
1208 if (dev_handle->fate_action == MLX5_FLOW_FATE_QUEUE) {
1209 struct mlx5_hrxq *hrxq;
1211 hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
1212 dev_handle->rix_hrxq);
1214 ind_tbl = hrxq->ind_table;
1215 } else if (dev_handle->fate_action == MLX5_FLOW_FATE_SHARED_RSS) {
1216 struct mlx5_shared_action_rss *shared_rss;
1218 shared_rss = mlx5_ipool_get
1219 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
1220 dev_handle->rix_srss);
1222 ind_tbl = shared_rss->ind_tbl;
1226 MLX5_ASSERT(dev->data->dev_started);
1227 for (i = 0; i != ind_tbl->queues_n; ++i) {
1228 int idx = ind_tbl->queues[i];
1229 struct mlx5_rxq_ctrl *rxq_ctrl =
1230 container_of((*priv->rxqs)[idx],
1231 struct mlx5_rxq_ctrl, rxq);
1233 if (priv->config.dv_flow_en &&
1234 priv->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
1235 mlx5_flow_ext_mreg_supported(dev)) {
1236 rxq_ctrl->rxq.mark = 1;
1237 rxq_ctrl->flow_mark_n = 1;
1239 rxq_ctrl->flow_mark_n--;
1240 rxq_ctrl->rxq.mark = !!rxq_ctrl->flow_mark_n;
1245 /* Decrease the counter matching the flow. */
1246 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j) {
1247 if ((tunnels_info[j].tunnel &
1248 dev_handle->layers) ==
1249 tunnels_info[j].tunnel) {
1250 rxq_ctrl->flow_tunnels_n[j]--;
1254 flow_rxq_tunnel_ptype_update(rxq_ctrl);
1260 * Clear the Rx queue flags (Mark/Flag and Tunnel Ptype) associated with the
1261 * @p flow if no other flow uses it with the same kind of request.
1264 * Pointer to Ethernet device.
1266 * Pointer to the flow.
1269 flow_rxq_flags_trim(struct rte_eth_dev *dev, struct rte_flow *flow)
1271 struct mlx5_priv *priv = dev->data->dev_private;
1272 uint32_t handle_idx;
1273 struct mlx5_flow_handle *dev_handle;
1275 SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
1276 handle_idx, dev_handle, next)
1277 flow_drv_rxq_flags_trim(dev, dev_handle);
1281 * Clear the Mark/Flag and Tunnel ptype information in all Rx queues.
1284 * Pointer to Ethernet device.
1287 flow_rxq_flags_clear(struct rte_eth_dev *dev)
1289 struct mlx5_priv *priv = dev->data->dev_private;
1292 for (i = 0; i != priv->rxqs_n; ++i) {
1293 struct mlx5_rxq_ctrl *rxq_ctrl;
1296 if (!(*priv->rxqs)[i])
1298 rxq_ctrl = container_of((*priv->rxqs)[i],
1299 struct mlx5_rxq_ctrl, rxq);
1300 rxq_ctrl->flow_mark_n = 0;
1301 rxq_ctrl->rxq.mark = 0;
1302 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j)
1303 rxq_ctrl->flow_tunnels_n[j] = 0;
1304 rxq_ctrl->rxq.tunnel = 0;
1309 * Set the Rx queue dynamic metadata (mask and offset) for a flow
1312 * Pointer to the Ethernet device structure.
1315 mlx5_flow_rxq_dynf_metadata_set(struct rte_eth_dev *dev)
1317 struct mlx5_priv *priv = dev->data->dev_private;
1318 struct mlx5_rxq_data *data;
1321 for (i = 0; i != priv->rxqs_n; ++i) {
1322 if (!(*priv->rxqs)[i])
1324 data = (*priv->rxqs)[i];
1325 if (!rte_flow_dynf_metadata_avail()) {
1326 data->dynf_meta = 0;
1327 data->flow_meta_mask = 0;
1328 data->flow_meta_offset = -1;
1329 data->flow_meta_port_mask = 0;
1331 data->dynf_meta = 1;
1332 data->flow_meta_mask = rte_flow_dynf_metadata_mask;
1333 data->flow_meta_offset = rte_flow_dynf_metadata_offs;
1334 data->flow_meta_port_mask = priv->sh->dv_meta_mask;
1340 * return a pointer to the desired action in the list of actions.
1342 * @param[in] actions
1343 * The list of actions to search the action in.
1345 * The action to find.
1348 * Pointer to the action in the list, if found. NULL otherwise.
1350 const struct rte_flow_action *
1351 mlx5_flow_find_action(const struct rte_flow_action *actions,
1352 enum rte_flow_action_type action)
1354 if (actions == NULL)
1356 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++)
1357 if (actions->type == action)
1363 * Validate the flag action.
1365 * @param[in] action_flags
1366 * Bit-fields that holds the actions detected until now.
1368 * Attributes of flow that includes this action.
1370 * Pointer to error structure.
1373 * 0 on success, a negative errno value otherwise and rte_errno is set.
1376 mlx5_flow_validate_action_flag(uint64_t action_flags,
1377 const struct rte_flow_attr *attr,
1378 struct rte_flow_error *error)
1380 if (action_flags & MLX5_FLOW_ACTION_MARK)
1381 return rte_flow_error_set(error, EINVAL,
1382 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1383 "can't mark and flag in same flow");
1384 if (action_flags & MLX5_FLOW_ACTION_FLAG)
1385 return rte_flow_error_set(error, EINVAL,
1386 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1388 " actions in same flow");
1390 return rte_flow_error_set(error, ENOTSUP,
1391 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1392 "flag action not supported for "
1398 * Validate the mark action.
1401 * Pointer to the queue action.
1402 * @param[in] action_flags
1403 * Bit-fields that holds the actions detected until now.
1405 * Attributes of flow that includes this action.
1407 * Pointer to error structure.
1410 * 0 on success, a negative errno value otherwise and rte_errno is set.
1413 mlx5_flow_validate_action_mark(const struct rte_flow_action *action,
1414 uint64_t action_flags,
1415 const struct rte_flow_attr *attr,
1416 struct rte_flow_error *error)
1418 const struct rte_flow_action_mark *mark = action->conf;
1421 return rte_flow_error_set(error, EINVAL,
1422 RTE_FLOW_ERROR_TYPE_ACTION,
1424 "configuration cannot be null");
1425 if (mark->id >= MLX5_FLOW_MARK_MAX)
1426 return rte_flow_error_set(error, EINVAL,
1427 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1429 "mark id must in 0 <= id < "
1430 RTE_STR(MLX5_FLOW_MARK_MAX));
1431 if (action_flags & MLX5_FLOW_ACTION_FLAG)
1432 return rte_flow_error_set(error, EINVAL,
1433 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1434 "can't flag and mark in same flow");
1435 if (action_flags & MLX5_FLOW_ACTION_MARK)
1436 return rte_flow_error_set(error, EINVAL,
1437 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1438 "can't have 2 mark actions in same"
1441 return rte_flow_error_set(error, ENOTSUP,
1442 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1443 "mark action not supported for "
1449 * Validate the drop action.
1451 * @param[in] action_flags
1452 * Bit-fields that holds the actions detected until now.
1454 * Attributes of flow that includes this action.
1456 * Pointer to error structure.
1459 * 0 on success, a negative errno value otherwise and rte_errno is set.
1462 mlx5_flow_validate_action_drop(uint64_t action_flags __rte_unused,
1463 const struct rte_flow_attr *attr,
1464 struct rte_flow_error *error)
1467 return rte_flow_error_set(error, ENOTSUP,
1468 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1469 "drop action not supported for "
1475 * Validate the queue action.
1478 * Pointer to the queue action.
1479 * @param[in] action_flags
1480 * Bit-fields that holds the actions detected until now.
1482 * Pointer to the Ethernet device structure.
1484 * Attributes of flow that includes this action.
1486 * Pointer to error structure.
1489 * 0 on success, a negative errno value otherwise and rte_errno is set.
1492 mlx5_flow_validate_action_queue(const struct rte_flow_action *action,
1493 uint64_t action_flags,
1494 struct rte_eth_dev *dev,
1495 const struct rte_flow_attr *attr,
1496 struct rte_flow_error *error)
1498 struct mlx5_priv *priv = dev->data->dev_private;
1499 const struct rte_flow_action_queue *queue = action->conf;
1501 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
1502 return rte_flow_error_set(error, EINVAL,
1503 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1504 "can't have 2 fate actions in"
1507 return rte_flow_error_set(error, EINVAL,
1508 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1509 NULL, "No Rx queues configured");
1510 if (queue->index >= priv->rxqs_n)
1511 return rte_flow_error_set(error, EINVAL,
1512 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1514 "queue index out of range");
1515 if (!(*priv->rxqs)[queue->index])
1516 return rte_flow_error_set(error, EINVAL,
1517 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1519 "queue is not configured");
1521 return rte_flow_error_set(error, ENOTSUP,
1522 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1523 "queue action not supported for "
1529 * Validate the rss action.
1532 * Pointer to the Ethernet device structure.
1534 * Pointer to the queue action.
1536 * Pointer to error structure.
1539 * 0 on success, a negative errno value otherwise and rte_errno is set.
1542 mlx5_validate_action_rss(struct rte_eth_dev *dev,
1543 const struct rte_flow_action *action,
1544 struct rte_flow_error *error)
1546 struct mlx5_priv *priv = dev->data->dev_private;
1547 const struct rte_flow_action_rss *rss = action->conf;
1548 enum mlx5_rxq_type rxq_type = MLX5_RXQ_TYPE_UNDEFINED;
1551 if (rss->func != RTE_ETH_HASH_FUNCTION_DEFAULT &&
1552 rss->func != RTE_ETH_HASH_FUNCTION_TOEPLITZ)
1553 return rte_flow_error_set(error, ENOTSUP,
1554 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1556 "RSS hash function not supported");
1557 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
1562 return rte_flow_error_set(error, ENOTSUP,
1563 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1565 "tunnel RSS is not supported");
1566 /* allow RSS key_len 0 in case of NULL (default) RSS key. */
1567 if (rss->key_len == 0 && rss->key != NULL)
1568 return rte_flow_error_set(error, ENOTSUP,
1569 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1571 "RSS hash key length 0");
1572 if (rss->key_len > 0 && rss->key_len < MLX5_RSS_HASH_KEY_LEN)
1573 return rte_flow_error_set(error, ENOTSUP,
1574 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1576 "RSS hash key too small");
1577 if (rss->key_len > MLX5_RSS_HASH_KEY_LEN)
1578 return rte_flow_error_set(error, ENOTSUP,
1579 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1581 "RSS hash key too large");
1582 if (rss->queue_num > priv->config.ind_table_max_size)
1583 return rte_flow_error_set(error, ENOTSUP,
1584 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1586 "number of queues too large");
1587 if (rss->types & MLX5_RSS_HF_MASK)
1588 return rte_flow_error_set(error, ENOTSUP,
1589 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1591 "some RSS protocols are not"
1593 if ((rss->types & (ETH_RSS_L3_SRC_ONLY | ETH_RSS_L3_DST_ONLY)) &&
1594 !(rss->types & ETH_RSS_IP))
1595 return rte_flow_error_set(error, EINVAL,
1596 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1597 "L3 partial RSS requested but L3 RSS"
1598 " type not specified");
1599 if ((rss->types & (ETH_RSS_L4_SRC_ONLY | ETH_RSS_L4_DST_ONLY)) &&
1600 !(rss->types & (ETH_RSS_UDP | ETH_RSS_TCP)))
1601 return rte_flow_error_set(error, EINVAL,
1602 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1603 "L4 partial RSS requested but L4 RSS"
1604 " type not specified");
1606 return rte_flow_error_set(error, EINVAL,
1607 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1608 NULL, "No Rx queues configured");
1609 if (!rss->queue_num)
1610 return rte_flow_error_set(error, EINVAL,
1611 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1612 NULL, "No queues configured");
1613 for (i = 0; i != rss->queue_num; ++i) {
1614 struct mlx5_rxq_ctrl *rxq_ctrl;
1616 if (rss->queue[i] >= priv->rxqs_n)
1617 return rte_flow_error_set
1619 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1620 &rss->queue[i], "queue index out of range");
1621 if (!(*priv->rxqs)[rss->queue[i]])
1622 return rte_flow_error_set
1623 (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1624 &rss->queue[i], "queue is not configured");
1625 rxq_ctrl = container_of((*priv->rxqs)[rss->queue[i]],
1626 struct mlx5_rxq_ctrl, rxq);
1628 rxq_type = rxq_ctrl->type;
1629 if (rxq_type != rxq_ctrl->type)
1630 return rte_flow_error_set
1631 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1633 "combining hairpin and regular RSS queues is not supported");
1639 * Validate the rss action.
1642 * Pointer to the queue action.
1643 * @param[in] action_flags
1644 * Bit-fields that holds the actions detected until now.
1646 * Pointer to the Ethernet device structure.
1648 * Attributes of flow that includes this action.
1649 * @param[in] item_flags
1650 * Items that were detected.
1652 * Pointer to error structure.
1655 * 0 on success, a negative errno value otherwise and rte_errno is set.
1658 mlx5_flow_validate_action_rss(const struct rte_flow_action *action,
1659 uint64_t action_flags,
1660 struct rte_eth_dev *dev,
1661 const struct rte_flow_attr *attr,
1662 uint64_t item_flags,
1663 struct rte_flow_error *error)
1665 const struct rte_flow_action_rss *rss = action->conf;
1666 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1669 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
1670 return rte_flow_error_set(error, EINVAL,
1671 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1672 "can't have 2 fate actions"
1674 ret = mlx5_validate_action_rss(dev, action, error);
1678 return rte_flow_error_set(error, ENOTSUP,
1679 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1680 "rss action not supported for "
1682 if (rss->level > 1 && !tunnel)
1683 return rte_flow_error_set(error, EINVAL,
1684 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1685 "inner RSS is not supported for "
1686 "non-tunnel flows");
1687 if ((item_flags & MLX5_FLOW_LAYER_ECPRI) &&
1688 !(item_flags & MLX5_FLOW_LAYER_INNER_L4_UDP)) {
1689 return rte_flow_error_set(error, EINVAL,
1690 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1691 "RSS on eCPRI is not supported now");
1693 if ((item_flags & MLX5_FLOW_LAYER_MPLS) &&
1695 (MLX5_FLOW_LAYER_INNER_L2 | MLX5_FLOW_LAYER_INNER_L3)) &&
1697 return rte_flow_error_set(error, EINVAL,
1698 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
1699 "MPLS inner RSS needs to specify inner L2/L3 items after MPLS in pattern");
1704 * Validate the default miss action.
1706 * @param[in] action_flags
1707 * Bit-fields that holds the actions detected until now.
1709 * Pointer to error structure.
1712 * 0 on success, a negative errno value otherwise and rte_errno is set.
1715 mlx5_flow_validate_action_default_miss(uint64_t action_flags,
1716 const struct rte_flow_attr *attr,
1717 struct rte_flow_error *error)
1719 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
1720 return rte_flow_error_set(error, EINVAL,
1721 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1722 "can't have 2 fate actions in"
1725 return rte_flow_error_set(error, ENOTSUP,
1726 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1727 "default miss action not supported "
1730 return rte_flow_error_set(error, ENOTSUP,
1731 RTE_FLOW_ERROR_TYPE_ATTR_GROUP, NULL,
1732 "only group 0 is supported");
1734 return rte_flow_error_set(error, ENOTSUP,
1735 RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
1736 NULL, "transfer is not supported");
1741 * Validate the count action.
1744 * Pointer to the Ethernet device structure.
1746 * Attributes of flow that includes this action.
1748 * Pointer to error structure.
1751 * 0 on success, a negative errno value otherwise and rte_errno is set.
1754 mlx5_flow_validate_action_count(struct rte_eth_dev *dev __rte_unused,
1755 const struct rte_flow_attr *attr,
1756 struct rte_flow_error *error)
1759 return rte_flow_error_set(error, ENOTSUP,
1760 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1761 "count action not supported for "
1767 * Validate the ASO CT action.
1770 * Pointer to the Ethernet device structure.
1771 * @param[in] conntrack
1772 * Pointer to the CT action profile.
1774 * Pointer to error structure.
1777 * 0 on success, a negative errno value otherwise and rte_errno is set.
1780 mlx5_validate_action_ct(struct rte_eth_dev *dev,
1781 const struct rte_flow_action_conntrack *conntrack,
1782 struct rte_flow_error *error)
1786 if (conntrack->state > RTE_FLOW_CONNTRACK_STATE_TIME_WAIT)
1787 return rte_flow_error_set(error, EINVAL,
1788 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1789 "Invalid CT state");
1790 if (conntrack->last_index > RTE_FLOW_CONNTRACK_FLAG_RST)
1791 return rte_flow_error_set(error, EINVAL,
1792 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1793 "Invalid last TCP packet flag");
1798 * Verify the @p attributes will be correctly understood by the NIC and store
1799 * them in the @p flow if everything is correct.
1802 * Pointer to the Ethernet device structure.
1803 * @param[in] attributes
1804 * Pointer to flow attributes
1806 * Pointer to error structure.
1809 * 0 on success, a negative errno value otherwise and rte_errno is set.
1812 mlx5_flow_validate_attributes(struct rte_eth_dev *dev,
1813 const struct rte_flow_attr *attributes,
1814 struct rte_flow_error *error)
1816 struct mlx5_priv *priv = dev->data->dev_private;
1817 uint32_t priority_max = priv->config.flow_prio - 1;
1819 if (attributes->group)
1820 return rte_flow_error_set(error, ENOTSUP,
1821 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
1822 NULL, "groups is not supported");
1823 if (attributes->priority != MLX5_FLOW_LOWEST_PRIO_INDICATOR &&
1824 attributes->priority >= priority_max)
1825 return rte_flow_error_set(error, ENOTSUP,
1826 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
1827 NULL, "priority out of range");
1828 if (attributes->egress)
1829 return rte_flow_error_set(error, ENOTSUP,
1830 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1831 "egress is not supported");
1832 if (attributes->transfer && !priv->config.dv_esw_en)
1833 return rte_flow_error_set(error, ENOTSUP,
1834 RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
1835 NULL, "transfer is not supported");
1836 if (!attributes->ingress)
1837 return rte_flow_error_set(error, EINVAL,
1838 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
1840 "ingress attribute is mandatory");
1845 * Validate ICMP6 item.
1848 * Item specification.
1849 * @param[in] item_flags
1850 * Bit-fields that holds the items detected until now.
1851 * @param[in] ext_vlan_sup
1852 * Whether extended VLAN features are supported or not.
1854 * Pointer to error structure.
1857 * 0 on success, a negative errno value otherwise and rte_errno is set.
1860 mlx5_flow_validate_item_icmp6(const struct rte_flow_item *item,
1861 uint64_t item_flags,
1862 uint8_t target_protocol,
1863 struct rte_flow_error *error)
1865 const struct rte_flow_item_icmp6 *mask = item->mask;
1866 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1867 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
1868 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
1869 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1870 MLX5_FLOW_LAYER_OUTER_L4;
1873 if (target_protocol != 0xFF && target_protocol != IPPROTO_ICMPV6)
1874 return rte_flow_error_set(error, EINVAL,
1875 RTE_FLOW_ERROR_TYPE_ITEM, item,
1876 "protocol filtering not compatible"
1877 " with ICMP6 layer");
1878 if (!(item_flags & l3m))
1879 return rte_flow_error_set(error, EINVAL,
1880 RTE_FLOW_ERROR_TYPE_ITEM, item,
1881 "IPv6 is mandatory to filter on"
1883 if (item_flags & l4m)
1884 return rte_flow_error_set(error, EINVAL,
1885 RTE_FLOW_ERROR_TYPE_ITEM, item,
1886 "multiple L4 layers not supported");
1888 mask = &rte_flow_item_icmp6_mask;
1889 ret = mlx5_flow_item_acceptable
1890 (item, (const uint8_t *)mask,
1891 (const uint8_t *)&rte_flow_item_icmp6_mask,
1892 sizeof(struct rte_flow_item_icmp6),
1893 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
1900 * Validate ICMP item.
1903 * Item specification.
1904 * @param[in] item_flags
1905 * Bit-fields that holds the items detected until now.
1907 * Pointer to error structure.
1910 * 0 on success, a negative errno value otherwise and rte_errno is set.
1913 mlx5_flow_validate_item_icmp(const struct rte_flow_item *item,
1914 uint64_t item_flags,
1915 uint8_t target_protocol,
1916 struct rte_flow_error *error)
1918 const struct rte_flow_item_icmp *mask = item->mask;
1919 const struct rte_flow_item_icmp nic_mask = {
1920 .hdr.icmp_type = 0xff,
1921 .hdr.icmp_code = 0xff,
1922 .hdr.icmp_ident = RTE_BE16(0xffff),
1923 .hdr.icmp_seq_nb = RTE_BE16(0xffff),
1925 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1926 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
1927 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
1928 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1929 MLX5_FLOW_LAYER_OUTER_L4;
1932 if (target_protocol != 0xFF && target_protocol != IPPROTO_ICMP)
1933 return rte_flow_error_set(error, EINVAL,
1934 RTE_FLOW_ERROR_TYPE_ITEM, item,
1935 "protocol filtering not compatible"
1936 " with ICMP layer");
1937 if (!(item_flags & l3m))
1938 return rte_flow_error_set(error, EINVAL,
1939 RTE_FLOW_ERROR_TYPE_ITEM, item,
1940 "IPv4 is mandatory to filter"
1942 if (item_flags & l4m)
1943 return rte_flow_error_set(error, EINVAL,
1944 RTE_FLOW_ERROR_TYPE_ITEM, item,
1945 "multiple L4 layers not supported");
1948 ret = mlx5_flow_item_acceptable
1949 (item, (const uint8_t *)mask,
1950 (const uint8_t *)&nic_mask,
1951 sizeof(struct rte_flow_item_icmp),
1952 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
1959 * Validate Ethernet item.
1962 * Item specification.
1963 * @param[in] item_flags
1964 * Bit-fields that holds the items detected until now.
1966 * Pointer to error structure.
1969 * 0 on success, a negative errno value otherwise and rte_errno is set.
1972 mlx5_flow_validate_item_eth(const struct rte_flow_item *item,
1973 uint64_t item_flags, bool ext_vlan_sup,
1974 struct rte_flow_error *error)
1976 const struct rte_flow_item_eth *mask = item->mask;
1977 const struct rte_flow_item_eth nic_mask = {
1978 .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
1979 .src.addr_bytes = "\xff\xff\xff\xff\xff\xff",
1980 .type = RTE_BE16(0xffff),
1981 .has_vlan = ext_vlan_sup ? 1 : 0,
1984 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1985 const uint64_t ethm = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
1986 MLX5_FLOW_LAYER_OUTER_L2;
1988 if (item_flags & ethm)
1989 return rte_flow_error_set(error, ENOTSUP,
1990 RTE_FLOW_ERROR_TYPE_ITEM, item,
1991 "multiple L2 layers not supported");
1992 if ((!tunnel && (item_flags & MLX5_FLOW_LAYER_OUTER_L3)) ||
1993 (tunnel && (item_flags & MLX5_FLOW_LAYER_INNER_L3)))
1994 return rte_flow_error_set(error, EINVAL,
1995 RTE_FLOW_ERROR_TYPE_ITEM, item,
1996 "L2 layer should not follow "
1998 if ((!tunnel && (item_flags & MLX5_FLOW_LAYER_OUTER_VLAN)) ||
1999 (tunnel && (item_flags & MLX5_FLOW_LAYER_INNER_VLAN)))
2000 return rte_flow_error_set(error, EINVAL,
2001 RTE_FLOW_ERROR_TYPE_ITEM, item,
2002 "L2 layer should not follow VLAN");
2003 if (item_flags & MLX5_FLOW_LAYER_GTP)
2004 return rte_flow_error_set(error, EINVAL,
2005 RTE_FLOW_ERROR_TYPE_ITEM, item,
2006 "L2 layer should not follow GTP");
2008 mask = &rte_flow_item_eth_mask;
2009 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2010 (const uint8_t *)&nic_mask,
2011 sizeof(struct rte_flow_item_eth),
2012 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2017 * Validate VLAN item.
2020 * Item specification.
2021 * @param[in] item_flags
2022 * Bit-fields that holds the items detected until now.
2024 * Ethernet device flow is being created on.
2026 * Pointer to error structure.
2029 * 0 on success, a negative errno value otherwise and rte_errno is set.
2032 mlx5_flow_validate_item_vlan(const struct rte_flow_item *item,
2033 uint64_t item_flags,
2034 struct rte_eth_dev *dev,
2035 struct rte_flow_error *error)
2037 const struct rte_flow_item_vlan *spec = item->spec;
2038 const struct rte_flow_item_vlan *mask = item->mask;
2039 const struct rte_flow_item_vlan nic_mask = {
2040 .tci = RTE_BE16(UINT16_MAX),
2041 .inner_type = RTE_BE16(UINT16_MAX),
2043 uint16_t vlan_tag = 0;
2044 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2046 const uint64_t l34m = tunnel ? (MLX5_FLOW_LAYER_INNER_L3 |
2047 MLX5_FLOW_LAYER_INNER_L4) :
2048 (MLX5_FLOW_LAYER_OUTER_L3 |
2049 MLX5_FLOW_LAYER_OUTER_L4);
2050 const uint64_t vlanm = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
2051 MLX5_FLOW_LAYER_OUTER_VLAN;
2053 if (item_flags & vlanm)
2054 return rte_flow_error_set(error, EINVAL,
2055 RTE_FLOW_ERROR_TYPE_ITEM, item,
2056 "multiple VLAN layers not supported");
2057 else if ((item_flags & l34m) != 0)
2058 return rte_flow_error_set(error, EINVAL,
2059 RTE_FLOW_ERROR_TYPE_ITEM, item,
2060 "VLAN cannot follow L3/L4 layer");
2062 mask = &rte_flow_item_vlan_mask;
2063 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2064 (const uint8_t *)&nic_mask,
2065 sizeof(struct rte_flow_item_vlan),
2066 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2069 if (!tunnel && mask->tci != RTE_BE16(0x0fff)) {
2070 struct mlx5_priv *priv = dev->data->dev_private;
2072 if (priv->vmwa_context) {
2074 * Non-NULL context means we have a virtual machine
2075 * and SR-IOV enabled, we have to create VLAN interface
2076 * to make hypervisor to setup E-Switch vport
2077 * context correctly. We avoid creating the multiple
2078 * VLAN interfaces, so we cannot support VLAN tag mask.
2080 return rte_flow_error_set(error, EINVAL,
2081 RTE_FLOW_ERROR_TYPE_ITEM,
2083 "VLAN tag mask is not"
2084 " supported in virtual"
2089 vlan_tag = spec->tci;
2090 vlan_tag &= mask->tci;
2093 * From verbs perspective an empty VLAN is equivalent
2094 * to a packet without VLAN layer.
2097 return rte_flow_error_set(error, EINVAL,
2098 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
2100 "VLAN cannot be empty");
2105 * Validate IPV4 item.
2108 * Item specification.
2109 * @param[in] item_flags
2110 * Bit-fields that holds the items detected until now.
2111 * @param[in] last_item
2112 * Previous validated item in the pattern items.
2113 * @param[in] ether_type
2114 * Type in the ethernet layer header (including dot1q).
2115 * @param[in] acc_mask
2116 * Acceptable mask, if NULL default internal default mask
2117 * will be used to check whether item fields are supported.
2118 * @param[in] range_accepted
2119 * True if range of values is accepted for specific fields, false otherwise.
2121 * Pointer to error structure.
2124 * 0 on success, a negative errno value otherwise and rte_errno is set.
2127 mlx5_flow_validate_item_ipv4(const struct rte_flow_item *item,
2128 uint64_t item_flags,
2130 uint16_t ether_type,
2131 const struct rte_flow_item_ipv4 *acc_mask,
2132 bool range_accepted,
2133 struct rte_flow_error *error)
2135 const struct rte_flow_item_ipv4 *mask = item->mask;
2136 const struct rte_flow_item_ipv4 *spec = item->spec;
2137 const struct rte_flow_item_ipv4 nic_mask = {
2139 .src_addr = RTE_BE32(0xffffffff),
2140 .dst_addr = RTE_BE32(0xffffffff),
2141 .type_of_service = 0xff,
2142 .next_proto_id = 0xff,
2145 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2146 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2147 MLX5_FLOW_LAYER_OUTER_L3;
2148 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2149 MLX5_FLOW_LAYER_OUTER_L4;
2151 uint8_t next_proto = 0xFF;
2152 const uint64_t l2_vlan = (MLX5_FLOW_LAYER_L2 |
2153 MLX5_FLOW_LAYER_OUTER_VLAN |
2154 MLX5_FLOW_LAYER_INNER_VLAN);
2156 if ((last_item & l2_vlan) && ether_type &&
2157 ether_type != RTE_ETHER_TYPE_IPV4)
2158 return rte_flow_error_set(error, EINVAL,
2159 RTE_FLOW_ERROR_TYPE_ITEM, item,
2160 "IPv4 cannot follow L2/VLAN layer "
2161 "which ether type is not IPv4");
2162 if (item_flags & MLX5_FLOW_LAYER_TUNNEL) {
2164 next_proto = mask->hdr.next_proto_id &
2165 spec->hdr.next_proto_id;
2166 if (next_proto == IPPROTO_IPIP || next_proto == IPPROTO_IPV6)
2167 return rte_flow_error_set(error, EINVAL,
2168 RTE_FLOW_ERROR_TYPE_ITEM,
2173 if (item_flags & MLX5_FLOW_LAYER_IPV6_ENCAP)
2174 return rte_flow_error_set(error, EINVAL,
2175 RTE_FLOW_ERROR_TYPE_ITEM, item,
2176 "wrong tunnel type - IPv6 specified "
2177 "but IPv4 item provided");
2178 if (item_flags & l3m)
2179 return rte_flow_error_set(error, ENOTSUP,
2180 RTE_FLOW_ERROR_TYPE_ITEM, item,
2181 "multiple L3 layers not supported");
2182 else if (item_flags & l4m)
2183 return rte_flow_error_set(error, EINVAL,
2184 RTE_FLOW_ERROR_TYPE_ITEM, item,
2185 "L3 cannot follow an L4 layer.");
2186 else if ((item_flags & MLX5_FLOW_LAYER_NVGRE) &&
2187 !(item_flags & MLX5_FLOW_LAYER_INNER_L2))
2188 return rte_flow_error_set(error, EINVAL,
2189 RTE_FLOW_ERROR_TYPE_ITEM, item,
2190 "L3 cannot follow an NVGRE layer.");
2192 mask = &rte_flow_item_ipv4_mask;
2193 else if (mask->hdr.next_proto_id != 0 &&
2194 mask->hdr.next_proto_id != 0xff)
2195 return rte_flow_error_set(error, EINVAL,
2196 RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
2197 "partial mask is not supported"
2199 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2200 acc_mask ? (const uint8_t *)acc_mask
2201 : (const uint8_t *)&nic_mask,
2202 sizeof(struct rte_flow_item_ipv4),
2203 range_accepted, error);
2210 * Validate IPV6 item.
2213 * Item specification.
2214 * @param[in] item_flags
2215 * Bit-fields that holds the items detected until now.
2216 * @param[in] last_item
2217 * Previous validated item in the pattern items.
2218 * @param[in] ether_type
2219 * Type in the ethernet layer header (including dot1q).
2220 * @param[in] acc_mask
2221 * Acceptable mask, if NULL default internal default mask
2222 * will be used to check whether item fields are supported.
2224 * Pointer to error structure.
2227 * 0 on success, a negative errno value otherwise and rte_errno is set.
2230 mlx5_flow_validate_item_ipv6(const struct rte_flow_item *item,
2231 uint64_t item_flags,
2233 uint16_t ether_type,
2234 const struct rte_flow_item_ipv6 *acc_mask,
2235 struct rte_flow_error *error)
2237 const struct rte_flow_item_ipv6 *mask = item->mask;
2238 const struct rte_flow_item_ipv6 *spec = item->spec;
2239 const struct rte_flow_item_ipv6 nic_mask = {
2242 "\xff\xff\xff\xff\xff\xff\xff\xff"
2243 "\xff\xff\xff\xff\xff\xff\xff\xff",
2245 "\xff\xff\xff\xff\xff\xff\xff\xff"
2246 "\xff\xff\xff\xff\xff\xff\xff\xff",
2247 .vtc_flow = RTE_BE32(0xffffffff),
2251 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2252 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2253 MLX5_FLOW_LAYER_OUTER_L3;
2254 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2255 MLX5_FLOW_LAYER_OUTER_L4;
2257 uint8_t next_proto = 0xFF;
2258 const uint64_t l2_vlan = (MLX5_FLOW_LAYER_L2 |
2259 MLX5_FLOW_LAYER_OUTER_VLAN |
2260 MLX5_FLOW_LAYER_INNER_VLAN);
2262 if ((last_item & l2_vlan) && ether_type &&
2263 ether_type != RTE_ETHER_TYPE_IPV6)
2264 return rte_flow_error_set(error, EINVAL,
2265 RTE_FLOW_ERROR_TYPE_ITEM, item,
2266 "IPv6 cannot follow L2/VLAN layer "
2267 "which ether type is not IPv6");
2268 if (mask && mask->hdr.proto == UINT8_MAX && spec)
2269 next_proto = spec->hdr.proto;
2270 if (item_flags & MLX5_FLOW_LAYER_TUNNEL) {
2271 if (next_proto == IPPROTO_IPIP || next_proto == IPPROTO_IPV6)
2272 return rte_flow_error_set(error, EINVAL,
2273 RTE_FLOW_ERROR_TYPE_ITEM,
2278 if (next_proto == IPPROTO_HOPOPTS ||
2279 next_proto == IPPROTO_ROUTING ||
2280 next_proto == IPPROTO_FRAGMENT ||
2281 next_proto == IPPROTO_ESP ||
2282 next_proto == IPPROTO_AH ||
2283 next_proto == IPPROTO_DSTOPTS)
2284 return rte_flow_error_set(error, EINVAL,
2285 RTE_FLOW_ERROR_TYPE_ITEM, item,
2286 "IPv6 proto (next header) should "
2287 "not be set as extension header");
2288 if (item_flags & MLX5_FLOW_LAYER_IPIP)
2289 return rte_flow_error_set(error, EINVAL,
2290 RTE_FLOW_ERROR_TYPE_ITEM, item,
2291 "wrong tunnel type - IPv4 specified "
2292 "but IPv6 item provided");
2293 if (item_flags & l3m)
2294 return rte_flow_error_set(error, ENOTSUP,
2295 RTE_FLOW_ERROR_TYPE_ITEM, item,
2296 "multiple L3 layers not supported");
2297 else if (item_flags & l4m)
2298 return rte_flow_error_set(error, EINVAL,
2299 RTE_FLOW_ERROR_TYPE_ITEM, item,
2300 "L3 cannot follow an L4 layer.");
2301 else if ((item_flags & MLX5_FLOW_LAYER_NVGRE) &&
2302 !(item_flags & MLX5_FLOW_LAYER_INNER_L2))
2303 return rte_flow_error_set(error, EINVAL,
2304 RTE_FLOW_ERROR_TYPE_ITEM, item,
2305 "L3 cannot follow an NVGRE layer.");
2307 mask = &rte_flow_item_ipv6_mask;
2308 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2309 acc_mask ? (const uint8_t *)acc_mask
2310 : (const uint8_t *)&nic_mask,
2311 sizeof(struct rte_flow_item_ipv6),
2312 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2319 * Validate UDP item.
2322 * Item specification.
2323 * @param[in] item_flags
2324 * Bit-fields that holds the items detected until now.
2325 * @param[in] target_protocol
2326 * The next protocol in the previous item.
2327 * @param[in] flow_mask
2328 * mlx5 flow-specific (DV, verbs, etc.) supported header fields mask.
2330 * Pointer to error structure.
2333 * 0 on success, a negative errno value otherwise and rte_errno is set.
2336 mlx5_flow_validate_item_udp(const struct rte_flow_item *item,
2337 uint64_t item_flags,
2338 uint8_t target_protocol,
2339 struct rte_flow_error *error)
2341 const struct rte_flow_item_udp *mask = item->mask;
2342 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2343 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2344 MLX5_FLOW_LAYER_OUTER_L3;
2345 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2346 MLX5_FLOW_LAYER_OUTER_L4;
2349 if (target_protocol != 0xff && target_protocol != IPPROTO_UDP)
2350 return rte_flow_error_set(error, EINVAL,
2351 RTE_FLOW_ERROR_TYPE_ITEM, item,
2352 "protocol filtering not compatible"
2354 if (!(item_flags & l3m))
2355 return rte_flow_error_set(error, EINVAL,
2356 RTE_FLOW_ERROR_TYPE_ITEM, item,
2357 "L3 is mandatory to filter on L4");
2358 if (item_flags & l4m)
2359 return rte_flow_error_set(error, EINVAL,
2360 RTE_FLOW_ERROR_TYPE_ITEM, item,
2361 "multiple L4 layers not supported");
2363 mask = &rte_flow_item_udp_mask;
2364 ret = mlx5_flow_item_acceptable
2365 (item, (const uint8_t *)mask,
2366 (const uint8_t *)&rte_flow_item_udp_mask,
2367 sizeof(struct rte_flow_item_udp), MLX5_ITEM_RANGE_NOT_ACCEPTED,
2375 * Validate TCP item.
2378 * Item specification.
2379 * @param[in] item_flags
2380 * Bit-fields that holds the items detected until now.
2381 * @param[in] target_protocol
2382 * The next protocol in the previous item.
2384 * Pointer to error structure.
2387 * 0 on success, a negative errno value otherwise and rte_errno is set.
2390 mlx5_flow_validate_item_tcp(const struct rte_flow_item *item,
2391 uint64_t item_flags,
2392 uint8_t target_protocol,
2393 const struct rte_flow_item_tcp *flow_mask,
2394 struct rte_flow_error *error)
2396 const struct rte_flow_item_tcp *mask = item->mask;
2397 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2398 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2399 MLX5_FLOW_LAYER_OUTER_L3;
2400 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2401 MLX5_FLOW_LAYER_OUTER_L4;
2404 MLX5_ASSERT(flow_mask);
2405 if (target_protocol != 0xff && target_protocol != IPPROTO_TCP)
2406 return rte_flow_error_set(error, EINVAL,
2407 RTE_FLOW_ERROR_TYPE_ITEM, item,
2408 "protocol filtering not compatible"
2410 if (!(item_flags & l3m))
2411 return rte_flow_error_set(error, EINVAL,
2412 RTE_FLOW_ERROR_TYPE_ITEM, item,
2413 "L3 is mandatory to filter on L4");
2414 if (item_flags & l4m)
2415 return rte_flow_error_set(error, EINVAL,
2416 RTE_FLOW_ERROR_TYPE_ITEM, item,
2417 "multiple L4 layers not supported");
2419 mask = &rte_flow_item_tcp_mask;
2420 ret = mlx5_flow_item_acceptable
2421 (item, (const uint8_t *)mask,
2422 (const uint8_t *)flow_mask,
2423 sizeof(struct rte_flow_item_tcp), MLX5_ITEM_RANGE_NOT_ACCEPTED,
2431 * Validate VXLAN item.
2434 * Pointer to the Ethernet device structure.
2436 * Item specification.
2437 * @param[in] item_flags
2438 * Bit-fields that holds the items detected until now.
2440 * Flow rule attributes.
2442 * Pointer to error structure.
2445 * 0 on success, a negative errno value otherwise and rte_errno is set.
2448 mlx5_flow_validate_item_vxlan(struct rte_eth_dev *dev,
2449 const struct rte_flow_item *item,
2450 uint64_t item_flags,
2451 const struct rte_flow_attr *attr,
2452 struct rte_flow_error *error)
2454 const struct rte_flow_item_vxlan *spec = item->spec;
2455 const struct rte_flow_item_vxlan *mask = item->mask;
2457 struct mlx5_priv *priv = dev->data->dev_private;
2461 } id = { .vlan_id = 0, };
2462 const struct rte_flow_item_vxlan nic_mask = {
2463 .vni = "\xff\xff\xff",
2466 const struct rte_flow_item_vxlan *valid_mask;
2468 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2469 return rte_flow_error_set(error, ENOTSUP,
2470 RTE_FLOW_ERROR_TYPE_ITEM, item,
2471 "multiple tunnel layers not"
2473 valid_mask = &rte_flow_item_vxlan_mask;
2475 * Verify only UDPv4 is present as defined in
2476 * https://tools.ietf.org/html/rfc7348
2478 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2479 return rte_flow_error_set(error, EINVAL,
2480 RTE_FLOW_ERROR_TYPE_ITEM, item,
2481 "no outer UDP layer found");
2483 mask = &rte_flow_item_vxlan_mask;
2484 /* FDB domain & NIC domain non-zero group */
2485 if ((attr->transfer || attr->group) && priv->sh->misc5_cap)
2486 valid_mask = &nic_mask;
2487 /* Group zero in NIC domain */
2488 if (!attr->group && !attr->transfer && priv->sh->tunnel_header_0_1)
2489 valid_mask = &nic_mask;
2490 ret = mlx5_flow_item_acceptable
2491 (item, (const uint8_t *)mask,
2492 (const uint8_t *)valid_mask,
2493 sizeof(struct rte_flow_item_vxlan),
2494 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2498 memcpy(&id.vni[1], spec->vni, 3);
2499 memcpy(&id.vni[1], mask->vni, 3);
2501 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
2502 return rte_flow_error_set(error, ENOTSUP,
2503 RTE_FLOW_ERROR_TYPE_ITEM, item,
2504 "VXLAN tunnel must be fully defined");
2509 * Validate VXLAN_GPE item.
2512 * Item specification.
2513 * @param[in] item_flags
2514 * Bit-fields that holds the items detected until now.
2516 * Pointer to the private data structure.
2517 * @param[in] target_protocol
2518 * The next protocol in the previous item.
2520 * Pointer to error structure.
2523 * 0 on success, a negative errno value otherwise and rte_errno is set.
2526 mlx5_flow_validate_item_vxlan_gpe(const struct rte_flow_item *item,
2527 uint64_t item_flags,
2528 struct rte_eth_dev *dev,
2529 struct rte_flow_error *error)
2531 struct mlx5_priv *priv = dev->data->dev_private;
2532 const struct rte_flow_item_vxlan_gpe *spec = item->spec;
2533 const struct rte_flow_item_vxlan_gpe *mask = item->mask;
2538 } id = { .vlan_id = 0, };
2540 if (!priv->config.l3_vxlan_en)
2541 return rte_flow_error_set(error, ENOTSUP,
2542 RTE_FLOW_ERROR_TYPE_ITEM, item,
2543 "L3 VXLAN is not enabled by device"
2544 " parameter and/or not configured in"
2546 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2547 return rte_flow_error_set(error, ENOTSUP,
2548 RTE_FLOW_ERROR_TYPE_ITEM, item,
2549 "multiple tunnel layers not"
2552 * Verify only UDPv4 is present as defined in
2553 * https://tools.ietf.org/html/rfc7348
2555 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2556 return rte_flow_error_set(error, EINVAL,
2557 RTE_FLOW_ERROR_TYPE_ITEM, item,
2558 "no outer UDP layer found");
2560 mask = &rte_flow_item_vxlan_gpe_mask;
2561 ret = mlx5_flow_item_acceptable
2562 (item, (const uint8_t *)mask,
2563 (const uint8_t *)&rte_flow_item_vxlan_gpe_mask,
2564 sizeof(struct rte_flow_item_vxlan_gpe),
2565 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2570 return rte_flow_error_set(error, ENOTSUP,
2571 RTE_FLOW_ERROR_TYPE_ITEM,
2573 "VxLAN-GPE protocol"
2575 memcpy(&id.vni[1], spec->vni, 3);
2576 memcpy(&id.vni[1], mask->vni, 3);
2578 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
2579 return rte_flow_error_set(error, ENOTSUP,
2580 RTE_FLOW_ERROR_TYPE_ITEM, item,
2581 "VXLAN-GPE tunnel must be fully"
2586 * Validate GRE Key item.
2589 * Item specification.
2590 * @param[in] item_flags
2591 * Bit flags to mark detected items.
2592 * @param[in] gre_item
2593 * Pointer to gre_item
2595 * Pointer to error structure.
2598 * 0 on success, a negative errno value otherwise and rte_errno is set.
2601 mlx5_flow_validate_item_gre_key(const struct rte_flow_item *item,
2602 uint64_t item_flags,
2603 const struct rte_flow_item *gre_item,
2604 struct rte_flow_error *error)
2606 const rte_be32_t *mask = item->mask;
2608 rte_be32_t gre_key_default_mask = RTE_BE32(UINT32_MAX);
2609 const struct rte_flow_item_gre *gre_spec;
2610 const struct rte_flow_item_gre *gre_mask;
2612 if (item_flags & MLX5_FLOW_LAYER_GRE_KEY)
2613 return rte_flow_error_set(error, ENOTSUP,
2614 RTE_FLOW_ERROR_TYPE_ITEM, item,
2615 "Multiple GRE key not support");
2616 if (!(item_flags & MLX5_FLOW_LAYER_GRE))
2617 return rte_flow_error_set(error, ENOTSUP,
2618 RTE_FLOW_ERROR_TYPE_ITEM, item,
2619 "No preceding GRE header");
2620 if (item_flags & MLX5_FLOW_LAYER_INNER)
2621 return rte_flow_error_set(error, ENOTSUP,
2622 RTE_FLOW_ERROR_TYPE_ITEM, item,
2623 "GRE key following a wrong item");
2624 gre_mask = gre_item->mask;
2626 gre_mask = &rte_flow_item_gre_mask;
2627 gre_spec = gre_item->spec;
2628 if (gre_spec && (gre_mask->c_rsvd0_ver & RTE_BE16(0x2000)) &&
2629 !(gre_spec->c_rsvd0_ver & RTE_BE16(0x2000)))
2630 return rte_flow_error_set(error, EINVAL,
2631 RTE_FLOW_ERROR_TYPE_ITEM, item,
2632 "Key bit must be on");
2635 mask = &gre_key_default_mask;
2636 ret = mlx5_flow_item_acceptable
2637 (item, (const uint8_t *)mask,
2638 (const uint8_t *)&gre_key_default_mask,
2639 sizeof(rte_be32_t), MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2644 * Validate GRE item.
2647 * Item specification.
2648 * @param[in] item_flags
2649 * Bit flags to mark detected items.
2650 * @param[in] target_protocol
2651 * The next protocol in the previous item.
2653 * Pointer to error structure.
2656 * 0 on success, a negative errno value otherwise and rte_errno is set.
2659 mlx5_flow_validate_item_gre(const struct rte_flow_item *item,
2660 uint64_t item_flags,
2661 uint8_t target_protocol,
2662 struct rte_flow_error *error)
2664 const struct rte_flow_item_gre *spec __rte_unused = item->spec;
2665 const struct rte_flow_item_gre *mask = item->mask;
2667 const struct rte_flow_item_gre nic_mask = {
2668 .c_rsvd0_ver = RTE_BE16(0xB000),
2669 .protocol = RTE_BE16(UINT16_MAX),
2672 if (target_protocol != 0xff && target_protocol != IPPROTO_GRE)
2673 return rte_flow_error_set(error, EINVAL,
2674 RTE_FLOW_ERROR_TYPE_ITEM, item,
2675 "protocol filtering not compatible"
2676 " with this GRE layer");
2677 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2678 return rte_flow_error_set(error, ENOTSUP,
2679 RTE_FLOW_ERROR_TYPE_ITEM, item,
2680 "multiple tunnel layers not"
2682 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3))
2683 return rte_flow_error_set(error, ENOTSUP,
2684 RTE_FLOW_ERROR_TYPE_ITEM, item,
2685 "L3 Layer is missing");
2687 mask = &rte_flow_item_gre_mask;
2688 ret = mlx5_flow_item_acceptable
2689 (item, (const uint8_t *)mask,
2690 (const uint8_t *)&nic_mask,
2691 sizeof(struct rte_flow_item_gre), MLX5_ITEM_RANGE_NOT_ACCEPTED,
2695 #ifndef HAVE_MLX5DV_DR
2696 #ifndef HAVE_IBV_DEVICE_MPLS_SUPPORT
2697 if (spec && (spec->protocol & mask->protocol))
2698 return rte_flow_error_set(error, ENOTSUP,
2699 RTE_FLOW_ERROR_TYPE_ITEM, item,
2700 "without MPLS support the"
2701 " specification cannot be used for"
2709 * Validate Geneve item.
2712 * Item specification.
2713 * @param[in] itemFlags
2714 * Bit-fields that holds the items detected until now.
2716 * Pointer to the private data structure.
2718 * Pointer to error structure.
2721 * 0 on success, a negative errno value otherwise and rte_errno is set.
2725 mlx5_flow_validate_item_geneve(const struct rte_flow_item *item,
2726 uint64_t item_flags,
2727 struct rte_eth_dev *dev,
2728 struct rte_flow_error *error)
2730 struct mlx5_priv *priv = dev->data->dev_private;
2731 const struct rte_flow_item_geneve *spec = item->spec;
2732 const struct rte_flow_item_geneve *mask = item->mask;
2735 uint8_t opt_len = priv->config.hca_attr.geneve_max_opt_len ?
2736 MLX5_GENEVE_OPT_LEN_1 : MLX5_GENEVE_OPT_LEN_0;
2737 const struct rte_flow_item_geneve nic_mask = {
2738 .ver_opt_len_o_c_rsvd0 = RTE_BE16(0x3f80),
2739 .vni = "\xff\xff\xff",
2740 .protocol = RTE_BE16(UINT16_MAX),
2743 if (!priv->config.hca_attr.tunnel_stateless_geneve_rx)
2744 return rte_flow_error_set(error, ENOTSUP,
2745 RTE_FLOW_ERROR_TYPE_ITEM, item,
2746 "L3 Geneve is not enabled by device"
2747 " parameter and/or not configured in"
2749 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2750 return rte_flow_error_set(error, ENOTSUP,
2751 RTE_FLOW_ERROR_TYPE_ITEM, item,
2752 "multiple tunnel layers not"
2755 * Verify only UDPv4 is present as defined in
2756 * https://tools.ietf.org/html/rfc7348
2758 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2759 return rte_flow_error_set(error, EINVAL,
2760 RTE_FLOW_ERROR_TYPE_ITEM, item,
2761 "no outer UDP layer found");
2763 mask = &rte_flow_item_geneve_mask;
2764 ret = mlx5_flow_item_acceptable
2765 (item, (const uint8_t *)mask,
2766 (const uint8_t *)&nic_mask,
2767 sizeof(struct rte_flow_item_geneve),
2768 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2772 gbhdr = rte_be_to_cpu_16(spec->ver_opt_len_o_c_rsvd0);
2773 if (MLX5_GENEVE_VER_VAL(gbhdr) ||
2774 MLX5_GENEVE_CRITO_VAL(gbhdr) ||
2775 MLX5_GENEVE_RSVD_VAL(gbhdr) || spec->rsvd1)
2776 return rte_flow_error_set(error, ENOTSUP,
2777 RTE_FLOW_ERROR_TYPE_ITEM,
2779 "Geneve protocol unsupported"
2780 " fields are being used");
2781 if (MLX5_GENEVE_OPTLEN_VAL(gbhdr) > opt_len)
2782 return rte_flow_error_set
2784 RTE_FLOW_ERROR_TYPE_ITEM,
2786 "Unsupported Geneve options length");
2788 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
2789 return rte_flow_error_set
2791 RTE_FLOW_ERROR_TYPE_ITEM, item,
2792 "Geneve tunnel must be fully defined");
2797 * Validate Geneve TLV option item.
2800 * Item specification.
2801 * @param[in] last_item
2802 * Previous validated item in the pattern items.
2803 * @param[in] geneve_item
2804 * Previous GENEVE item specification.
2806 * Pointer to the rte_eth_dev structure.
2808 * Pointer to error structure.
2811 * 0 on success, a negative errno value otherwise and rte_errno is set.
2814 mlx5_flow_validate_item_geneve_opt(const struct rte_flow_item *item,
2816 const struct rte_flow_item *geneve_item,
2817 struct rte_eth_dev *dev,
2818 struct rte_flow_error *error)
2820 struct mlx5_priv *priv = dev->data->dev_private;
2821 struct mlx5_dev_ctx_shared *sh = priv->sh;
2822 struct mlx5_geneve_tlv_option_resource *geneve_opt_resource;
2823 struct mlx5_hca_attr *hca_attr = &priv->config.hca_attr;
2824 uint8_t data_max_supported =
2825 hca_attr->max_geneve_tlv_option_data_len * 4;
2826 struct mlx5_dev_config *config = &priv->config;
2827 const struct rte_flow_item_geneve *geneve_spec;
2828 const struct rte_flow_item_geneve *geneve_mask;
2829 const struct rte_flow_item_geneve_opt *spec = item->spec;
2830 const struct rte_flow_item_geneve_opt *mask = item->mask;
2832 unsigned int data_len;
2833 uint8_t tlv_option_len;
2834 uint16_t optlen_m, optlen_v;
2835 const struct rte_flow_item_geneve_opt full_mask = {
2836 .option_class = RTE_BE16(0xffff),
2837 .option_type = 0xff,
2842 mask = &rte_flow_item_geneve_opt_mask;
2844 return rte_flow_error_set
2845 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2846 "Geneve TLV opt class/type/length must be specified");
2847 if ((uint32_t)spec->option_len > MLX5_GENEVE_OPTLEN_MASK)
2848 return rte_flow_error_set
2849 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2850 "Geneve TLV opt length exceeeds the limit (31)");
2851 /* Check if class type and length masks are full. */
2852 if (full_mask.option_class != mask->option_class ||
2853 full_mask.option_type != mask->option_type ||
2854 full_mask.option_len != (mask->option_len & full_mask.option_len))
2855 return rte_flow_error_set
2856 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2857 "Geneve TLV opt class/type/length masks must be full");
2858 /* Check if length is supported */
2859 if ((uint32_t)spec->option_len >
2860 config->hca_attr.max_geneve_tlv_option_data_len)
2861 return rte_flow_error_set
2862 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2863 "Geneve TLV opt length not supported");
2864 if (config->hca_attr.max_geneve_tlv_options > 1)
2866 "max_geneve_tlv_options supports more than 1 option");
2867 /* Check GENEVE item preceding. */
2868 if (!geneve_item || !(last_item & MLX5_FLOW_LAYER_GENEVE))
2869 return rte_flow_error_set
2870 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2871 "Geneve opt item must be preceded with Geneve item");
2872 geneve_spec = geneve_item->spec;
2873 geneve_mask = geneve_item->mask ? geneve_item->mask :
2874 &rte_flow_item_geneve_mask;
2875 /* Check if GENEVE TLV option size doesn't exceed option length */
2876 if (geneve_spec && (geneve_mask->ver_opt_len_o_c_rsvd0 ||
2877 geneve_spec->ver_opt_len_o_c_rsvd0)) {
2878 tlv_option_len = spec->option_len & mask->option_len;
2879 optlen_v = rte_be_to_cpu_16(geneve_spec->ver_opt_len_o_c_rsvd0);
2880 optlen_v = MLX5_GENEVE_OPTLEN_VAL(optlen_v);
2881 optlen_m = rte_be_to_cpu_16(geneve_mask->ver_opt_len_o_c_rsvd0);
2882 optlen_m = MLX5_GENEVE_OPTLEN_VAL(optlen_m);
2883 if ((optlen_v & optlen_m) <= tlv_option_len)
2884 return rte_flow_error_set
2885 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2886 "GENEVE TLV option length exceeds optlen");
2888 /* Check if length is 0 or data is 0. */
2889 if (spec->data == NULL || spec->option_len == 0)
2890 return rte_flow_error_set
2891 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2892 "Geneve TLV opt with zero data/length not supported");
2893 /* Check not all data & mask are 0. */
2894 data_len = spec->option_len * 4;
2895 if (mask->data == NULL) {
2896 for (i = 0; i < data_len; i++)
2900 return rte_flow_error_set(error, ENOTSUP,
2901 RTE_FLOW_ERROR_TYPE_ITEM, item,
2902 "Can't match on Geneve option data 0");
2904 for (i = 0; i < data_len; i++)
2905 if (spec->data[i] & mask->data[i])
2908 return rte_flow_error_set(error, ENOTSUP,
2909 RTE_FLOW_ERROR_TYPE_ITEM, item,
2910 "Can't match on Geneve option data and mask 0");
2911 /* Check data mask supported. */
2912 for (i = data_max_supported; i < data_len ; i++)
2914 return rte_flow_error_set(error, ENOTSUP,
2915 RTE_FLOW_ERROR_TYPE_ITEM, item,
2916 "Data mask is of unsupported size");
2918 /* Check GENEVE option is supported in NIC. */
2919 if (!config->hca_attr.geneve_tlv_opt)
2920 return rte_flow_error_set
2921 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2922 "Geneve TLV opt not supported");
2923 /* Check if we already have geneve option with different type/class. */
2924 rte_spinlock_lock(&sh->geneve_tlv_opt_sl);
2925 geneve_opt_resource = sh->geneve_tlv_option_resource;
2926 if (geneve_opt_resource != NULL)
2927 if (geneve_opt_resource->option_class != spec->option_class ||
2928 geneve_opt_resource->option_type != spec->option_type ||
2929 geneve_opt_resource->length != spec->option_len) {
2930 rte_spinlock_unlock(&sh->geneve_tlv_opt_sl);
2931 return rte_flow_error_set(error, ENOTSUP,
2932 RTE_FLOW_ERROR_TYPE_ITEM, item,
2933 "Only one Geneve TLV option supported");
2935 rte_spinlock_unlock(&sh->geneve_tlv_opt_sl);
2940 * Validate MPLS item.
2943 * Pointer to the rte_eth_dev structure.
2945 * Item specification.
2946 * @param[in] item_flags
2947 * Bit-fields that holds the items detected until now.
2948 * @param[in] prev_layer
2949 * The protocol layer indicated in previous item.
2951 * Pointer to error structure.
2954 * 0 on success, a negative errno value otherwise and rte_errno is set.
2957 mlx5_flow_validate_item_mpls(struct rte_eth_dev *dev __rte_unused,
2958 const struct rte_flow_item *item __rte_unused,
2959 uint64_t item_flags __rte_unused,
2960 uint64_t prev_layer __rte_unused,
2961 struct rte_flow_error *error)
2963 #ifdef HAVE_IBV_DEVICE_MPLS_SUPPORT
2964 const struct rte_flow_item_mpls *mask = item->mask;
2965 struct mlx5_priv *priv = dev->data->dev_private;
2968 if (!priv->config.mpls_en)
2969 return rte_flow_error_set(error, ENOTSUP,
2970 RTE_FLOW_ERROR_TYPE_ITEM, item,
2971 "MPLS not supported or"
2972 " disabled in firmware"
2974 /* MPLS over UDP, GRE is allowed */
2975 if (!(prev_layer & (MLX5_FLOW_LAYER_OUTER_L4_UDP |
2976 MLX5_FLOW_LAYER_GRE |
2977 MLX5_FLOW_LAYER_GRE_KEY)))
2978 return rte_flow_error_set(error, EINVAL,
2979 RTE_FLOW_ERROR_TYPE_ITEM, item,
2980 "protocol filtering not compatible"
2981 " with MPLS layer");
2982 /* Multi-tunnel isn't allowed but MPLS over GRE is an exception. */
2983 if ((item_flags & MLX5_FLOW_LAYER_TUNNEL) &&
2984 !(item_flags & MLX5_FLOW_LAYER_GRE))
2985 return rte_flow_error_set(error, ENOTSUP,
2986 RTE_FLOW_ERROR_TYPE_ITEM, item,
2987 "multiple tunnel layers not"
2990 mask = &rte_flow_item_mpls_mask;
2991 ret = mlx5_flow_item_acceptable
2992 (item, (const uint8_t *)mask,
2993 (const uint8_t *)&rte_flow_item_mpls_mask,
2994 sizeof(struct rte_flow_item_mpls),
2995 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
3000 return rte_flow_error_set(error, ENOTSUP,
3001 RTE_FLOW_ERROR_TYPE_ITEM, item,
3002 "MPLS is not supported by Verbs, please"
3008 * Validate NVGRE item.
3011 * Item specification.
3012 * @param[in] item_flags
3013 * Bit flags to mark detected items.
3014 * @param[in] target_protocol
3015 * The next protocol in the previous item.
3017 * Pointer to error structure.
3020 * 0 on success, a negative errno value otherwise and rte_errno is set.
3023 mlx5_flow_validate_item_nvgre(const struct rte_flow_item *item,
3024 uint64_t item_flags,
3025 uint8_t target_protocol,
3026 struct rte_flow_error *error)
3028 const struct rte_flow_item_nvgre *mask = item->mask;
3031 if (target_protocol != 0xff && target_protocol != IPPROTO_GRE)
3032 return rte_flow_error_set(error, EINVAL,
3033 RTE_FLOW_ERROR_TYPE_ITEM, item,
3034 "protocol filtering not compatible"
3035 " with this GRE layer");
3036 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
3037 return rte_flow_error_set(error, ENOTSUP,
3038 RTE_FLOW_ERROR_TYPE_ITEM, item,
3039 "multiple tunnel layers not"
3041 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3))
3042 return rte_flow_error_set(error, ENOTSUP,
3043 RTE_FLOW_ERROR_TYPE_ITEM, item,
3044 "L3 Layer is missing");
3046 mask = &rte_flow_item_nvgre_mask;
3047 ret = mlx5_flow_item_acceptable
3048 (item, (const uint8_t *)mask,
3049 (const uint8_t *)&rte_flow_item_nvgre_mask,
3050 sizeof(struct rte_flow_item_nvgre),
3051 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
3058 * Validate eCPRI item.
3061 * Item specification.
3062 * @param[in] item_flags
3063 * Bit-fields that holds the items detected until now.
3064 * @param[in] last_item
3065 * Previous validated item in the pattern items.
3066 * @param[in] ether_type
3067 * Type in the ethernet layer header (including dot1q).
3068 * @param[in] acc_mask
3069 * Acceptable mask, if NULL default internal default mask
3070 * will be used to check whether item fields are supported.
3072 * Pointer to error structure.
3075 * 0 on success, a negative errno value otherwise and rte_errno is set.
3078 mlx5_flow_validate_item_ecpri(const struct rte_flow_item *item,
3079 uint64_t item_flags,
3081 uint16_t ether_type,
3082 const struct rte_flow_item_ecpri *acc_mask,
3083 struct rte_flow_error *error)
3085 const struct rte_flow_item_ecpri *mask = item->mask;
3086 const struct rte_flow_item_ecpri nic_mask = {
3090 RTE_BE32(((const struct rte_ecpri_common_hdr) {
3094 .dummy[0] = 0xFFFFFFFF,
3097 const uint64_t outer_l2_vlan = (MLX5_FLOW_LAYER_OUTER_L2 |
3098 MLX5_FLOW_LAYER_OUTER_VLAN);
3099 struct rte_flow_item_ecpri mask_lo;
3101 if (!(last_item & outer_l2_vlan) &&
3102 last_item != MLX5_FLOW_LAYER_OUTER_L4_UDP)
3103 return rte_flow_error_set(error, EINVAL,
3104 RTE_FLOW_ERROR_TYPE_ITEM, item,
3105 "eCPRI can only follow L2/VLAN layer or UDP layer");
3106 if ((last_item & outer_l2_vlan) && ether_type &&
3107 ether_type != RTE_ETHER_TYPE_ECPRI)
3108 return rte_flow_error_set(error, EINVAL,
3109 RTE_FLOW_ERROR_TYPE_ITEM, item,
3110 "eCPRI cannot follow L2/VLAN layer which ether type is not 0xAEFE");
3111 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
3112 return rte_flow_error_set(error, EINVAL,
3113 RTE_FLOW_ERROR_TYPE_ITEM, item,
3114 "eCPRI with tunnel is not supported right now");
3115 if (item_flags & MLX5_FLOW_LAYER_OUTER_L3)
3116 return rte_flow_error_set(error, ENOTSUP,
3117 RTE_FLOW_ERROR_TYPE_ITEM, item,
3118 "multiple L3 layers not supported");
3119 else if (item_flags & MLX5_FLOW_LAYER_OUTER_L4_TCP)
3120 return rte_flow_error_set(error, EINVAL,
3121 RTE_FLOW_ERROR_TYPE_ITEM, item,
3122 "eCPRI cannot coexist with a TCP layer");
3123 /* In specification, eCPRI could be over UDP layer. */
3124 else if (item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP)
3125 return rte_flow_error_set(error, EINVAL,
3126 RTE_FLOW_ERROR_TYPE_ITEM, item,
3127 "eCPRI over UDP layer is not yet supported right now");
3128 /* Mask for type field in common header could be zero. */
3130 mask = &rte_flow_item_ecpri_mask;
3131 mask_lo.hdr.common.u32 = rte_be_to_cpu_32(mask->hdr.common.u32);
3132 /* Input mask is in big-endian format. */
3133 if (mask_lo.hdr.common.type != 0 && mask_lo.hdr.common.type != 0xff)
3134 return rte_flow_error_set(error, EINVAL,
3135 RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
3136 "partial mask is not supported for protocol");
3137 else if (mask_lo.hdr.common.type == 0 && mask->hdr.dummy[0] != 0)
3138 return rte_flow_error_set(error, EINVAL,
3139 RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
3140 "message header mask must be after a type mask");
3141 return mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
3142 acc_mask ? (const uint8_t *)acc_mask
3143 : (const uint8_t *)&nic_mask,
3144 sizeof(struct rte_flow_item_ecpri),
3145 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
3149 flow_null_validate(struct rte_eth_dev *dev __rte_unused,
3150 const struct rte_flow_attr *attr __rte_unused,
3151 const struct rte_flow_item items[] __rte_unused,
3152 const struct rte_flow_action actions[] __rte_unused,
3153 bool external __rte_unused,
3154 int hairpin __rte_unused,
3155 struct rte_flow_error *error)
3157 return rte_flow_error_set(error, ENOTSUP,
3158 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
3161 static struct mlx5_flow *
3162 flow_null_prepare(struct rte_eth_dev *dev __rte_unused,
3163 const struct rte_flow_attr *attr __rte_unused,
3164 const struct rte_flow_item items[] __rte_unused,
3165 const struct rte_flow_action actions[] __rte_unused,
3166 struct rte_flow_error *error)
3168 rte_flow_error_set(error, ENOTSUP,
3169 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
3174 flow_null_translate(struct rte_eth_dev *dev __rte_unused,
3175 struct mlx5_flow *dev_flow __rte_unused,
3176 const struct rte_flow_attr *attr __rte_unused,
3177 const struct rte_flow_item items[] __rte_unused,
3178 const struct rte_flow_action actions[] __rte_unused,
3179 struct rte_flow_error *error)
3181 return rte_flow_error_set(error, ENOTSUP,
3182 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
3186 flow_null_apply(struct rte_eth_dev *dev __rte_unused,
3187 struct rte_flow *flow __rte_unused,
3188 struct rte_flow_error *error)
3190 return rte_flow_error_set(error, ENOTSUP,
3191 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
3195 flow_null_remove(struct rte_eth_dev *dev __rte_unused,
3196 struct rte_flow *flow __rte_unused)
3201 flow_null_destroy(struct rte_eth_dev *dev __rte_unused,
3202 struct rte_flow *flow __rte_unused)
3207 flow_null_query(struct rte_eth_dev *dev __rte_unused,
3208 struct rte_flow *flow __rte_unused,
3209 const struct rte_flow_action *actions __rte_unused,
3210 void *data __rte_unused,
3211 struct rte_flow_error *error)
3213 return rte_flow_error_set(error, ENOTSUP,
3214 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
3218 flow_null_sync_domain(struct rte_eth_dev *dev __rte_unused,
3219 uint32_t domains __rte_unused,
3220 uint32_t flags __rte_unused)
3225 /* Void driver to protect from null pointer reference. */
3226 const struct mlx5_flow_driver_ops mlx5_flow_null_drv_ops = {
3227 .validate = flow_null_validate,
3228 .prepare = flow_null_prepare,
3229 .translate = flow_null_translate,
3230 .apply = flow_null_apply,
3231 .remove = flow_null_remove,
3232 .destroy = flow_null_destroy,
3233 .query = flow_null_query,
3234 .sync_domain = flow_null_sync_domain,
3238 * Select flow driver type according to flow attributes and device
3242 * Pointer to the dev structure.
3244 * Pointer to the flow attributes.
3247 * flow driver type, MLX5_FLOW_TYPE_MAX otherwise.
3249 static enum mlx5_flow_drv_type
3250 flow_get_drv_type(struct rte_eth_dev *dev, const struct rte_flow_attr *attr)
3252 struct mlx5_priv *priv = dev->data->dev_private;
3253 /* The OS can determine first a specific flow type (DV, VERBS) */
3254 enum mlx5_flow_drv_type type = mlx5_flow_os_get_type();
3256 if (type != MLX5_FLOW_TYPE_MAX)
3258 /* If no OS specific type - continue with DV/VERBS selection */
3259 if (attr->transfer && priv->config.dv_esw_en)
3260 type = MLX5_FLOW_TYPE_DV;
3261 if (!attr->transfer)
3262 type = priv->config.dv_flow_en ? MLX5_FLOW_TYPE_DV :
3263 MLX5_FLOW_TYPE_VERBS;
3267 #define flow_get_drv_ops(type) flow_drv_ops[type]
3270 * Flow driver validation API. This abstracts calling driver specific functions.
3271 * The type of flow driver is determined according to flow attributes.
3274 * Pointer to the dev structure.
3276 * Pointer to the flow attributes.
3278 * Pointer to the list of items.
3279 * @param[in] actions
3280 * Pointer to the list of actions.
3281 * @param[in] external
3282 * This flow rule is created by request external to PMD.
3283 * @param[in] hairpin
3284 * Number of hairpin TX actions, 0 means classic flow.
3286 * Pointer to the error structure.
3289 * 0 on success, a negative errno value otherwise and rte_errno is set.
3292 flow_drv_validate(struct rte_eth_dev *dev,
3293 const struct rte_flow_attr *attr,
3294 const struct rte_flow_item items[],
3295 const struct rte_flow_action actions[],
3296 bool external, int hairpin, struct rte_flow_error *error)
3298 const struct mlx5_flow_driver_ops *fops;
3299 enum mlx5_flow_drv_type type = flow_get_drv_type(dev, attr);
3301 fops = flow_get_drv_ops(type);
3302 return fops->validate(dev, attr, items, actions, external,
3307 * Flow driver preparation API. This abstracts calling driver specific
3308 * functions. Parent flow (rte_flow) should have driver type (drv_type). It
3309 * calculates the size of memory required for device flow, allocates the memory,
3310 * initializes the device flow and returns the pointer.
3313 * This function initializes device flow structure such as dv or verbs in
3314 * struct mlx5_flow. However, it is caller's responsibility to initialize the
3315 * rest. For example, adding returning device flow to flow->dev_flow list and
3316 * setting backward reference to the flow should be done out of this function.
3317 * layers field is not filled either.
3320 * Pointer to the dev structure.
3322 * Pointer to the flow attributes.
3324 * Pointer to the list of items.
3325 * @param[in] actions
3326 * Pointer to the list of actions.
3327 * @param[in] flow_idx
3328 * This memory pool index to the flow.
3330 * Pointer to the error structure.
3333 * Pointer to device flow on success, otherwise NULL and rte_errno is set.
3335 static inline struct mlx5_flow *
3336 flow_drv_prepare(struct rte_eth_dev *dev,
3337 const struct rte_flow *flow,
3338 const struct rte_flow_attr *attr,
3339 const struct rte_flow_item items[],
3340 const struct rte_flow_action actions[],
3342 struct rte_flow_error *error)
3344 const struct mlx5_flow_driver_ops *fops;
3345 enum mlx5_flow_drv_type type = flow->drv_type;
3346 struct mlx5_flow *mlx5_flow = NULL;
3348 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3349 fops = flow_get_drv_ops(type);
3350 mlx5_flow = fops->prepare(dev, attr, items, actions, error);
3352 mlx5_flow->flow_idx = flow_idx;
3357 * Flow driver translation API. This abstracts calling driver specific
3358 * functions. Parent flow (rte_flow) should have driver type (drv_type). It
3359 * translates a generic flow into a driver flow. flow_drv_prepare() must
3363 * dev_flow->layers could be filled as a result of parsing during translation
3364 * if needed by flow_drv_apply(). dev_flow->flow->actions can also be filled
3365 * if necessary. As a flow can have multiple dev_flows by RSS flow expansion,
3366 * flow->actions could be overwritten even though all the expanded dev_flows
3367 * have the same actions.
3370 * Pointer to the rte dev structure.
3371 * @param[in, out] dev_flow
3372 * Pointer to the mlx5 flow.
3374 * Pointer to the flow attributes.
3376 * Pointer to the list of items.
3377 * @param[in] actions
3378 * Pointer to the list of actions.
3380 * Pointer to the error structure.
3383 * 0 on success, a negative errno value otherwise and rte_errno is set.
3386 flow_drv_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
3387 const struct rte_flow_attr *attr,
3388 const struct rte_flow_item items[],
3389 const struct rte_flow_action actions[],
3390 struct rte_flow_error *error)
3392 const struct mlx5_flow_driver_ops *fops;
3393 enum mlx5_flow_drv_type type = dev_flow->flow->drv_type;
3395 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3396 fops = flow_get_drv_ops(type);
3397 return fops->translate(dev, dev_flow, attr, items, actions, error);
3401 * Flow driver apply API. This abstracts calling driver specific functions.
3402 * Parent flow (rte_flow) should have driver type (drv_type). It applies
3403 * translated driver flows on to device. flow_drv_translate() must precede.
3406 * Pointer to Ethernet device structure.
3407 * @param[in, out] flow
3408 * Pointer to flow structure.
3410 * Pointer to error structure.
3413 * 0 on success, a negative errno value otherwise and rte_errno is set.
3416 flow_drv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
3417 struct rte_flow_error *error)
3419 const struct mlx5_flow_driver_ops *fops;
3420 enum mlx5_flow_drv_type type = flow->drv_type;
3422 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3423 fops = flow_get_drv_ops(type);
3424 return fops->apply(dev, flow, error);
3428 * Flow driver destroy API. This abstracts calling driver specific functions.
3429 * Parent flow (rte_flow) should have driver type (drv_type). It removes a flow
3430 * on device and releases resources of the flow.
3433 * Pointer to Ethernet device.
3434 * @param[in, out] flow
3435 * Pointer to flow structure.
3438 flow_drv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
3440 const struct mlx5_flow_driver_ops *fops;
3441 enum mlx5_flow_drv_type type = flow->drv_type;
3443 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3444 fops = flow_get_drv_ops(type);
3445 fops->destroy(dev, flow);
3449 * Flow driver find RSS policy tbl API. This abstracts calling driver
3450 * specific functions. Parent flow (rte_flow) should have driver
3451 * type (drv_type). It will find the RSS policy table that has the rss_desc.
3454 * Pointer to Ethernet device.
3455 * @param[in, out] flow
3456 * Pointer to flow structure.
3458 * Pointer to meter policy table.
3459 * @param[in] rss_desc
3460 * Pointer to rss_desc
3462 static struct mlx5_flow_meter_sub_policy *
3463 flow_drv_meter_sub_policy_rss_prepare(struct rte_eth_dev *dev,
3464 struct rte_flow *flow,
3465 struct mlx5_flow_meter_policy *policy,
3466 struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS])
3468 const struct mlx5_flow_driver_ops *fops;
3469 enum mlx5_flow_drv_type type = flow->drv_type;
3471 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3472 fops = flow_get_drv_ops(type);
3473 return fops->meter_sub_policy_rss_prepare(dev, policy, rss_desc);
3477 * Flow driver color tag rule API. This abstracts calling driver
3478 * specific functions. Parent flow (rte_flow) should have driver
3479 * type (drv_type). It will create the color tag rules in hierarchy meter.
3482 * Pointer to Ethernet device.
3483 * @param[in, out] flow
3484 * Pointer to flow structure.
3486 * Pointer to flow meter structure.
3487 * @param[in] src_port
3488 * The src port this extra rule should use.
3490 * The src port id match item.
3492 * Pointer to error structure.
3495 flow_drv_mtr_hierarchy_rule_create(struct rte_eth_dev *dev,
3496 struct rte_flow *flow,
3497 struct mlx5_flow_meter_info *fm,
3499 const struct rte_flow_item *item,
3500 struct rte_flow_error *error)
3502 const struct mlx5_flow_driver_ops *fops;
3503 enum mlx5_flow_drv_type type = flow->drv_type;
3505 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3506 fops = flow_get_drv_ops(type);
3507 return fops->meter_hierarchy_rule_create(dev, fm,
3508 src_port, item, error);
3512 * Get RSS action from the action list.
3515 * Pointer to Ethernet device.
3516 * @param[in] actions
3517 * Pointer to the list of actions.
3519 * Parent flow structure pointer.
3522 * Pointer to the RSS action if exist, else return NULL.
3524 static const struct rte_flow_action_rss*
3525 flow_get_rss_action(struct rte_eth_dev *dev,
3526 const struct rte_flow_action actions[])
3528 struct mlx5_priv *priv = dev->data->dev_private;
3529 const struct rte_flow_action_rss *rss = NULL;
3531 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3532 switch (actions->type) {
3533 case RTE_FLOW_ACTION_TYPE_RSS:
3534 rss = actions->conf;
3536 case RTE_FLOW_ACTION_TYPE_SAMPLE:
3538 const struct rte_flow_action_sample *sample =
3540 const struct rte_flow_action *act = sample->actions;
3541 for (; act->type != RTE_FLOW_ACTION_TYPE_END; act++)
3542 if (act->type == RTE_FLOW_ACTION_TYPE_RSS)
3546 case RTE_FLOW_ACTION_TYPE_METER:
3549 struct mlx5_flow_meter_info *fm;
3550 struct mlx5_flow_meter_policy *policy;
3551 const struct rte_flow_action_meter *mtr = actions->conf;
3553 fm = mlx5_flow_meter_find(priv, mtr->mtr_id, &mtr_idx);
3554 if (fm && !fm->def_policy) {
3555 policy = mlx5_flow_meter_policy_find(dev,
3556 fm->policy_id, NULL);
3557 MLX5_ASSERT(policy);
3558 if (policy->is_hierarchy) {
3560 mlx5_flow_meter_hierarchy_get_final_policy(dev,
3567 policy->act_cnt[RTE_COLOR_GREEN].rss->conf;
3579 * Get ASO age action by index.
3582 * Pointer to the Ethernet device structure.
3583 * @param[in] age_idx
3584 * Index to the ASO age action.
3587 * The specified ASO age action.
3589 struct mlx5_aso_age_action*
3590 flow_aso_age_get_by_idx(struct rte_eth_dev *dev, uint32_t age_idx)
3592 uint16_t pool_idx = age_idx & UINT16_MAX;
3593 uint16_t offset = (age_idx >> 16) & UINT16_MAX;
3594 struct mlx5_priv *priv = dev->data->dev_private;
3595 struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
3596 struct mlx5_aso_age_pool *pool = mng->pools[pool_idx];
3598 return &pool->actions[offset - 1];
3601 /* maps indirect action to translated direct in some actions array */
3602 struct mlx5_translated_action_handle {
3603 struct rte_flow_action_handle *action; /**< Indirect action handle. */
3604 int index; /**< Index in related array of rte_flow_action. */
3608 * Translates actions of type RTE_FLOW_ACTION_TYPE_INDIRECT to related
3609 * direct action if translation possible.
3610 * This functionality used to run same execution path for both direct and
3611 * indirect actions on flow create. All necessary preparations for indirect
3612 * action handling should be performed on *handle* actions list returned
3616 * Pointer to Ethernet device.
3617 * @param[in] actions
3618 * List of actions to translate.
3619 * @param[out] handle
3620 * List to store translated indirect action object handles.
3621 * @param[in, out] indir_n
3622 * Size of *handle* array. On return should be updated with number of
3623 * indirect actions retrieved from the *actions* list.
3624 * @param[out] translated_actions
3625 * List of actions where all indirect actions were translated to direct
3626 * if possible. NULL if no translation took place.
3628 * Pointer to the error structure.
3631 * 0 on success, a negative errno value otherwise and rte_errno is set.
3634 flow_action_handles_translate(struct rte_eth_dev *dev,
3635 const struct rte_flow_action actions[],
3636 struct mlx5_translated_action_handle *handle,
3638 struct rte_flow_action **translated_actions,
3639 struct rte_flow_error *error)
3641 struct mlx5_priv *priv = dev->data->dev_private;
3642 struct rte_flow_action *translated = NULL;
3643 size_t actions_size;
3646 struct mlx5_translated_action_handle *handle_end = NULL;
3648 for (n = 0; actions[n].type != RTE_FLOW_ACTION_TYPE_END; n++) {
3649 if (actions[n].type != RTE_FLOW_ACTION_TYPE_INDIRECT)
3651 if (copied_n == *indir_n) {
3652 return rte_flow_error_set
3653 (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION_NUM,
3654 NULL, "too many shared actions");
3656 rte_memcpy(&handle[copied_n].action, &actions[n].conf,
3657 sizeof(actions[n].conf));
3658 handle[copied_n].index = n;
3662 *indir_n = copied_n;
3665 actions_size = sizeof(struct rte_flow_action) * n;
3666 translated = mlx5_malloc(MLX5_MEM_ZERO, actions_size, 0, SOCKET_ID_ANY);
3671 memcpy(translated, actions, actions_size);
3672 for (handle_end = handle + copied_n; handle < handle_end; handle++) {
3673 struct mlx5_shared_action_rss *shared_rss;
3674 uint32_t act_idx = (uint32_t)(uintptr_t)handle->action;
3675 uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
3676 uint32_t idx = act_idx &
3677 ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
3680 case MLX5_INDIRECT_ACTION_TYPE_RSS:
3681 shared_rss = mlx5_ipool_get
3682 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
3683 translated[handle->index].type =
3684 RTE_FLOW_ACTION_TYPE_RSS;
3685 translated[handle->index].conf =
3686 &shared_rss->origin;
3688 case MLX5_INDIRECT_ACTION_TYPE_COUNT:
3689 translated[handle->index].type =
3690 (enum rte_flow_action_type)
3691 MLX5_RTE_FLOW_ACTION_TYPE_COUNT;
3692 translated[handle->index].conf = (void *)(uintptr_t)idx;
3694 case MLX5_INDIRECT_ACTION_TYPE_AGE:
3695 if (priv->sh->flow_hit_aso_en) {
3696 translated[handle->index].type =
3697 (enum rte_flow_action_type)
3698 MLX5_RTE_FLOW_ACTION_TYPE_AGE;
3699 translated[handle->index].conf =
3700 (void *)(uintptr_t)idx;
3704 case MLX5_INDIRECT_ACTION_TYPE_CT:
3705 if (priv->sh->ct_aso_en) {
3706 translated[handle->index].type =
3707 RTE_FLOW_ACTION_TYPE_CONNTRACK;
3708 translated[handle->index].conf =
3709 (void *)(uintptr_t)idx;
3714 mlx5_free(translated);
3715 return rte_flow_error_set
3716 (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
3717 NULL, "invalid indirect action type");
3720 *translated_actions = translated;
3725 * Get Shared RSS action from the action list.
3728 * Pointer to Ethernet device.
3730 * Pointer to the list of actions.
3731 * @param[in] shared_n
3732 * Actions list length.
3735 * The MLX5 RSS action ID if exists, otherwise return 0.
3738 flow_get_shared_rss_action(struct rte_eth_dev *dev,
3739 struct mlx5_translated_action_handle *handle,
3742 struct mlx5_translated_action_handle *handle_end;
3743 struct mlx5_priv *priv = dev->data->dev_private;
3744 struct mlx5_shared_action_rss *shared_rss;
3747 for (handle_end = handle + shared_n; handle < handle_end; handle++) {
3748 uint32_t act_idx = (uint32_t)(uintptr_t)handle->action;
3749 uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
3750 uint32_t idx = act_idx &
3751 ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
3753 case MLX5_INDIRECT_ACTION_TYPE_RSS:
3754 shared_rss = mlx5_ipool_get
3755 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
3757 __atomic_add_fetch(&shared_rss->refcnt, 1,
3768 find_graph_root(const struct rte_flow_item pattern[], uint32_t rss_level)
3770 const struct rte_flow_item *item;
3771 unsigned int has_vlan = 0;
3773 for (item = pattern; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
3774 if (item->type == RTE_FLOW_ITEM_TYPE_VLAN) {
3780 return rss_level < 2 ? MLX5_EXPANSION_ROOT_ETH_VLAN :
3781 MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN;
3782 return rss_level < 2 ? MLX5_EXPANSION_ROOT :
3783 MLX5_EXPANSION_ROOT_OUTER;
3787 * Get layer flags from the prefix flow.
3789 * Some flows may be split to several subflows, the prefix subflow gets the
3790 * match items and the suffix sub flow gets the actions.
3791 * Some actions need the user defined match item flags to get the detail for
3793 * This function helps the suffix flow to get the item layer flags from prefix
3796 * @param[in] dev_flow
3797 * Pointer the created preifx subflow.
3800 * The layers get from prefix subflow.
3802 static inline uint64_t
3803 flow_get_prefix_layer_flags(struct mlx5_flow *dev_flow)
3805 uint64_t layers = 0;
3808 * Layers bits could be localization, but usually the compiler will
3809 * help to do the optimization work for source code.
3810 * If no decap actions, use the layers directly.
3812 if (!(dev_flow->act_flags & MLX5_FLOW_ACTION_DECAP))
3813 return dev_flow->handle->layers;
3814 /* Convert L3 layers with decap action. */
3815 if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L3_IPV4)
3816 layers |= MLX5_FLOW_LAYER_OUTER_L3_IPV4;
3817 else if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L3_IPV6)
3818 layers |= MLX5_FLOW_LAYER_OUTER_L3_IPV6;
3819 /* Convert L4 layers with decap action. */
3820 if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L4_TCP)
3821 layers |= MLX5_FLOW_LAYER_OUTER_L4_TCP;
3822 else if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L4_UDP)
3823 layers |= MLX5_FLOW_LAYER_OUTER_L4_UDP;
3828 * Get metadata split action information.
3830 * @param[in] actions
3831 * Pointer to the list of actions.
3833 * Pointer to the return pointer.
3834 * @param[out] qrss_type
3835 * Pointer to the action type to return. RTE_FLOW_ACTION_TYPE_END is returned
3836 * if no QUEUE/RSS is found.
3837 * @param[out] encap_idx
3838 * Pointer to the index of the encap action if exists, otherwise the last
3842 * Total number of actions.
3845 flow_parse_metadata_split_actions_info(const struct rte_flow_action actions[],
3846 const struct rte_flow_action **qrss,
3849 const struct rte_flow_action_raw_encap *raw_encap;
3851 int raw_decap_idx = -1;
3854 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3855 switch (actions->type) {
3856 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
3857 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
3858 *encap_idx = actions_n;
3860 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
3861 raw_decap_idx = actions_n;
3863 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
3864 raw_encap = actions->conf;
3865 if (raw_encap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
3866 *encap_idx = raw_decap_idx != -1 ?
3867 raw_decap_idx : actions_n;
3869 case RTE_FLOW_ACTION_TYPE_QUEUE:
3870 case RTE_FLOW_ACTION_TYPE_RSS:
3878 if (*encap_idx == -1)
3879 *encap_idx = actions_n;
3880 /* Count RTE_FLOW_ACTION_TYPE_END. */
3881 return actions_n + 1;
3885 * Check if the action will change packet.
3888 * Pointer to Ethernet device.
3893 * true if action will change packet, false otherwise.
3895 static bool flow_check_modify_action_type(struct rte_eth_dev *dev,
3896 enum rte_flow_action_type type)
3898 struct mlx5_priv *priv = dev->data->dev_private;
3901 case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
3902 case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
3903 case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
3904 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
3905 case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
3906 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
3907 case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
3908 case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
3909 case RTE_FLOW_ACTION_TYPE_DEC_TTL:
3910 case RTE_FLOW_ACTION_TYPE_SET_TTL:
3911 case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
3912 case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
3913 case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
3914 case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
3915 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
3916 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
3917 case RTE_FLOW_ACTION_TYPE_SET_META:
3918 case RTE_FLOW_ACTION_TYPE_SET_TAG:
3919 case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
3920 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
3921 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
3922 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
3923 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
3924 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
3925 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
3926 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
3927 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
3928 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
3929 case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
3931 case RTE_FLOW_ACTION_TYPE_FLAG:
3932 case RTE_FLOW_ACTION_TYPE_MARK:
3933 if (priv->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY)
3943 * Check meter action from the action list.
3946 * Pointer to Ethernet device.
3947 * @param[in] actions
3948 * Pointer to the list of actions.
3949 * @param[out] has_mtr
3950 * Pointer to the meter exist flag.
3951 * @param[out] has_modify
3952 * Pointer to the flag showing there's packet change action.
3953 * @param[out] meter_id
3954 * Pointer to the meter id.
3957 * Total number of actions.
3960 flow_check_meter_action(struct rte_eth_dev *dev,
3961 const struct rte_flow_action actions[],
3962 bool *has_mtr, bool *has_modify, uint32_t *meter_id)
3964 const struct rte_flow_action_meter *mtr = NULL;
3967 MLX5_ASSERT(has_mtr);
3969 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3970 switch (actions->type) {
3971 case RTE_FLOW_ACTION_TYPE_METER:
3972 mtr = actions->conf;
3973 *meter_id = mtr->mtr_id;
3980 *has_modify |= flow_check_modify_action_type(dev,
3984 /* Count RTE_FLOW_ACTION_TYPE_END. */
3985 return actions_n + 1;
3989 * Check if the flow should be split due to hairpin.
3990 * The reason for the split is that in current HW we can't
3991 * support encap and push-vlan on Rx, so if a flow contains
3992 * these actions we move it to Tx.
3995 * Pointer to Ethernet device.
3997 * Flow rule attributes.
3998 * @param[in] actions
3999 * Associated actions (list terminated by the END action).
4002 * > 0 the number of actions and the flow should be split,
4003 * 0 when no split required.
4006 flow_check_hairpin_split(struct rte_eth_dev *dev,
4007 const struct rte_flow_attr *attr,
4008 const struct rte_flow_action actions[])
4010 int queue_action = 0;
4013 const struct rte_flow_action_queue *queue;
4014 const struct rte_flow_action_rss *rss;
4015 const struct rte_flow_action_raw_encap *raw_encap;
4016 const struct rte_eth_hairpin_conf *conf;
4020 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4021 switch (actions->type) {
4022 case RTE_FLOW_ACTION_TYPE_QUEUE:
4023 queue = actions->conf;
4026 conf = mlx5_rxq_get_hairpin_conf(dev, queue->index);
4027 if (conf == NULL || conf->tx_explicit != 0)
4032 case RTE_FLOW_ACTION_TYPE_RSS:
4033 rss = actions->conf;
4034 if (rss == NULL || rss->queue_num == 0)
4036 conf = mlx5_rxq_get_hairpin_conf(dev, rss->queue[0]);
4037 if (conf == NULL || conf->tx_explicit != 0)
4042 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
4043 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
4044 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
4045 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
4046 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
4050 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
4051 raw_encap = actions->conf;
4052 if (raw_encap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
4061 if (split && queue_action)
4066 /* Declare flow create/destroy prototype in advance. */
4068 flow_list_create(struct rte_eth_dev *dev, enum mlx5_flow_type type,
4069 const struct rte_flow_attr *attr,
4070 const struct rte_flow_item items[],
4071 const struct rte_flow_action actions[],
4072 bool external, struct rte_flow_error *error);
4075 flow_list_destroy(struct rte_eth_dev *dev, enum mlx5_flow_type type,
4079 flow_dv_mreg_match_cb(void *tool_ctx __rte_unused,
4080 struct mlx5_list_entry *entry, void *cb_ctx)
4082 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4083 struct mlx5_flow_mreg_copy_resource *mcp_res =
4084 container_of(entry, typeof(*mcp_res), hlist_ent);
4086 return mcp_res->mark_id != *(uint32_t *)(ctx->data);
4089 struct mlx5_list_entry *
4090 flow_dv_mreg_create_cb(void *tool_ctx, void *cb_ctx)
4092 struct rte_eth_dev *dev = tool_ctx;
4093 struct mlx5_priv *priv = dev->data->dev_private;
4094 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4095 struct mlx5_flow_mreg_copy_resource *mcp_res;
4096 struct rte_flow_error *error = ctx->error;
4099 uint32_t mark_id = *(uint32_t *)(ctx->data);
4100 struct rte_flow_attr attr = {
4101 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
4104 struct mlx5_rte_flow_item_tag tag_spec = {
4107 struct rte_flow_item items[] = {
4108 [1] = { .type = RTE_FLOW_ITEM_TYPE_END, },
4110 struct rte_flow_action_mark ftag = {
4113 struct mlx5_flow_action_copy_mreg cp_mreg = {
4117 struct rte_flow_action_jump jump = {
4118 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
4120 struct rte_flow_action actions[] = {
4121 [3] = { .type = RTE_FLOW_ACTION_TYPE_END, },
4124 /* Fill the register fileds in the flow. */
4125 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
4129 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_RX, 0, error);
4133 /* Provide the full width of FLAG specific value. */
4134 if (mark_id == (priv->sh->dv_regc0_mask & MLX5_FLOW_MARK_DEFAULT))
4135 tag_spec.data = MLX5_FLOW_MARK_DEFAULT;
4136 /* Build a new flow. */
4137 if (mark_id != MLX5_DEFAULT_COPY_ID) {
4138 items[0] = (struct rte_flow_item){
4139 .type = (enum rte_flow_item_type)
4140 MLX5_RTE_FLOW_ITEM_TYPE_TAG,
4143 items[1] = (struct rte_flow_item){
4144 .type = RTE_FLOW_ITEM_TYPE_END,
4146 actions[0] = (struct rte_flow_action){
4147 .type = (enum rte_flow_action_type)
4148 MLX5_RTE_FLOW_ACTION_TYPE_MARK,
4151 actions[1] = (struct rte_flow_action){
4152 .type = (enum rte_flow_action_type)
4153 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
4156 actions[2] = (struct rte_flow_action){
4157 .type = RTE_FLOW_ACTION_TYPE_JUMP,
4160 actions[3] = (struct rte_flow_action){
4161 .type = RTE_FLOW_ACTION_TYPE_END,
4164 /* Default rule, wildcard match. */
4165 attr.priority = MLX5_FLOW_LOWEST_PRIO_INDICATOR;
4166 items[0] = (struct rte_flow_item){
4167 .type = RTE_FLOW_ITEM_TYPE_END,
4169 actions[0] = (struct rte_flow_action){
4170 .type = (enum rte_flow_action_type)
4171 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
4174 actions[1] = (struct rte_flow_action){
4175 .type = RTE_FLOW_ACTION_TYPE_JUMP,
4178 actions[2] = (struct rte_flow_action){
4179 .type = RTE_FLOW_ACTION_TYPE_END,
4182 /* Build a new entry. */
4183 mcp_res = mlx5_ipool_zmalloc(priv->sh->ipool[MLX5_IPOOL_MCP], &idx);
4189 mcp_res->mark_id = mark_id;
4191 * The copy Flows are not included in any list. There
4192 * ones are referenced from other Flows and can not
4193 * be applied, removed, deleted in ardbitrary order
4194 * by list traversing.
4196 mcp_res->rix_flow = flow_list_create(dev, MLX5_FLOW_TYPE_MCP,
4197 &attr, items, actions, false, error);
4198 if (!mcp_res->rix_flow) {
4199 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], idx);
4202 return &mcp_res->hlist_ent;
4205 struct mlx5_list_entry *
4206 flow_dv_mreg_clone_cb(void *tool_ctx, struct mlx5_list_entry *oentry,
4207 void *cb_ctx __rte_unused)
4209 struct rte_eth_dev *dev = tool_ctx;
4210 struct mlx5_priv *priv = dev->data->dev_private;
4211 struct mlx5_flow_mreg_copy_resource *mcp_res;
4214 mcp_res = mlx5_ipool_malloc(priv->sh->ipool[MLX5_IPOOL_MCP], &idx);
4219 memcpy(mcp_res, oentry, sizeof(*mcp_res));
4221 return &mcp_res->hlist_ent;
4225 flow_dv_mreg_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
4227 struct mlx5_flow_mreg_copy_resource *mcp_res =
4228 container_of(entry, typeof(*mcp_res), hlist_ent);
4229 struct rte_eth_dev *dev = tool_ctx;
4230 struct mlx5_priv *priv = dev->data->dev_private;
4232 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], mcp_res->idx);
4236 * Add a flow of copying flow metadata registers in RX_CP_TBL.
4238 * As mark_id is unique, if there's already a registered flow for the mark_id,
4239 * return by increasing the reference counter of the resource. Otherwise, create
4240 * the resource (mcp_res) and flow.
4243 * - If ingress port is ANY and reg_c[1] is mark_id,
4244 * flow_tag := mark_id, reg_b := reg_c[0] and jump to RX_ACT_TBL.
4246 * For default flow (zero mark_id), flow is like,
4247 * - If ingress port is ANY,
4248 * reg_b := reg_c[0] and jump to RX_ACT_TBL.
4251 * Pointer to Ethernet device.
4253 * ID of MARK action, zero means default flow for META.
4255 * Perform verbose error reporting if not NULL.
4258 * Associated resource on success, NULL otherwise and rte_errno is set.
4260 static struct mlx5_flow_mreg_copy_resource *
4261 flow_mreg_add_copy_action(struct rte_eth_dev *dev, uint32_t mark_id,
4262 struct rte_flow_error *error)
4264 struct mlx5_priv *priv = dev->data->dev_private;
4265 struct mlx5_list_entry *entry;
4266 struct mlx5_flow_cb_ctx ctx = {
4272 /* Check if already registered. */
4273 MLX5_ASSERT(priv->mreg_cp_tbl);
4274 entry = mlx5_hlist_register(priv->mreg_cp_tbl, mark_id, &ctx);
4277 return container_of(entry, struct mlx5_flow_mreg_copy_resource,
4282 flow_dv_mreg_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
4284 struct mlx5_flow_mreg_copy_resource *mcp_res =
4285 container_of(entry, typeof(*mcp_res), hlist_ent);
4286 struct rte_eth_dev *dev = tool_ctx;
4287 struct mlx5_priv *priv = dev->data->dev_private;
4289 MLX5_ASSERT(mcp_res->rix_flow);
4290 flow_list_destroy(dev, MLX5_FLOW_TYPE_MCP, mcp_res->rix_flow);
4291 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], mcp_res->idx);
4295 * Release flow in RX_CP_TBL.
4298 * Pointer to Ethernet device.
4300 * Parent flow for wich copying is provided.
4303 flow_mreg_del_copy_action(struct rte_eth_dev *dev,
4304 struct rte_flow *flow)
4306 struct mlx5_flow_mreg_copy_resource *mcp_res;
4307 struct mlx5_priv *priv = dev->data->dev_private;
4309 if (!flow->rix_mreg_copy)
4311 mcp_res = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MCP],
4312 flow->rix_mreg_copy);
4313 if (!mcp_res || !priv->mreg_cp_tbl)
4315 MLX5_ASSERT(mcp_res->rix_flow);
4316 mlx5_hlist_unregister(priv->mreg_cp_tbl, &mcp_res->hlist_ent);
4317 flow->rix_mreg_copy = 0;
4321 * Remove the default copy action from RX_CP_TBL.
4323 * This functions is called in the mlx5_dev_start(). No thread safe
4327 * Pointer to Ethernet device.
4330 flow_mreg_del_default_copy_action(struct rte_eth_dev *dev)
4332 struct mlx5_list_entry *entry;
4333 struct mlx5_priv *priv = dev->data->dev_private;
4334 struct mlx5_flow_cb_ctx ctx;
4337 /* Check if default flow is registered. */
4338 if (!priv->mreg_cp_tbl)
4340 mark_id = MLX5_DEFAULT_COPY_ID;
4341 ctx.data = &mark_id;
4342 entry = mlx5_hlist_lookup(priv->mreg_cp_tbl, mark_id, &ctx);
4345 mlx5_hlist_unregister(priv->mreg_cp_tbl, entry);
4349 * Add the default copy action in in RX_CP_TBL.
4351 * This functions is called in the mlx5_dev_start(). No thread safe
4355 * Pointer to Ethernet device.
4357 * Perform verbose error reporting if not NULL.
4360 * 0 for success, negative value otherwise and rte_errno is set.
4363 flow_mreg_add_default_copy_action(struct rte_eth_dev *dev,
4364 struct rte_flow_error *error)
4366 struct mlx5_priv *priv = dev->data->dev_private;
4367 struct mlx5_flow_mreg_copy_resource *mcp_res;
4368 struct mlx5_flow_cb_ctx ctx;
4371 /* Check whether extensive metadata feature is engaged. */
4372 if (!priv->config.dv_flow_en ||
4373 priv->config.dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
4374 !mlx5_flow_ext_mreg_supported(dev) ||
4375 !priv->sh->dv_regc0_mask)
4378 * Add default mreg copy flow may be called multiple time, but
4379 * only be called once in stop. Avoid register it twice.
4381 mark_id = MLX5_DEFAULT_COPY_ID;
4382 ctx.data = &mark_id;
4383 if (mlx5_hlist_lookup(priv->mreg_cp_tbl, mark_id, &ctx))
4385 mcp_res = flow_mreg_add_copy_action(dev, mark_id, error);
4392 * Add a flow of copying flow metadata registers in RX_CP_TBL.
4394 * All the flow having Q/RSS action should be split by
4395 * flow_mreg_split_qrss_prep() to pass by RX_CP_TBL. A flow in the RX_CP_TBL
4396 * performs the following,
4397 * - CQE->flow_tag := reg_c[1] (MARK)
4398 * - CQE->flow_table_metadata (reg_b) := reg_c[0] (META)
4399 * As CQE's flow_tag is not a register, it can't be simply copied from reg_c[1]
4400 * but there should be a flow per each MARK ID set by MARK action.
4402 * For the aforementioned reason, if there's a MARK action in flow's action
4403 * list, a corresponding flow should be added to the RX_CP_TBL in order to copy
4404 * the MARK ID to CQE's flow_tag like,
4405 * - If reg_c[1] is mark_id,
4406 * flow_tag := mark_id, reg_b := reg_c[0] and jump to RX_ACT_TBL.
4408 * For SET_META action which stores value in reg_c[0], as the destination is
4409 * also a flow metadata register (reg_b), adding a default flow is enough. Zero
4410 * MARK ID means the default flow. The default flow looks like,
4411 * - For all flow, reg_b := reg_c[0] and jump to RX_ACT_TBL.
4414 * Pointer to Ethernet device.
4416 * Pointer to flow structure.
4417 * @param[in] actions
4418 * Pointer to the list of actions.
4420 * Perform verbose error reporting if not NULL.
4423 * 0 on success, negative value otherwise and rte_errno is set.
4426 flow_mreg_update_copy_table(struct rte_eth_dev *dev,
4427 struct rte_flow *flow,
4428 const struct rte_flow_action *actions,
4429 struct rte_flow_error *error)
4431 struct mlx5_priv *priv = dev->data->dev_private;
4432 struct mlx5_dev_config *config = &priv->config;
4433 struct mlx5_flow_mreg_copy_resource *mcp_res;
4434 const struct rte_flow_action_mark *mark;
4436 /* Check whether extensive metadata feature is engaged. */
4437 if (!config->dv_flow_en ||
4438 config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
4439 !mlx5_flow_ext_mreg_supported(dev) ||
4440 !priv->sh->dv_regc0_mask)
4442 /* Find MARK action. */
4443 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4444 switch (actions->type) {
4445 case RTE_FLOW_ACTION_TYPE_FLAG:
4446 mcp_res = flow_mreg_add_copy_action
4447 (dev, MLX5_FLOW_MARK_DEFAULT, error);
4450 flow->rix_mreg_copy = mcp_res->idx;
4452 case RTE_FLOW_ACTION_TYPE_MARK:
4453 mark = (const struct rte_flow_action_mark *)
4456 flow_mreg_add_copy_action(dev, mark->id, error);
4459 flow->rix_mreg_copy = mcp_res->idx;
4468 #define MLX5_MAX_SPLIT_ACTIONS 24
4469 #define MLX5_MAX_SPLIT_ITEMS 24
4472 * Split the hairpin flow.
4473 * Since HW can't support encap and push-vlan on Rx, we move these
4475 * If the count action is after the encap then we also
4476 * move the count action. in this case the count will also measure
4480 * Pointer to Ethernet device.
4481 * @param[in] actions
4482 * Associated actions (list terminated by the END action).
4483 * @param[out] actions_rx
4485 * @param[out] actions_tx
4487 * @param[out] pattern_tx
4488 * The pattern items for the Tx flow.
4489 * @param[out] flow_id
4490 * The flow ID connected to this flow.
4496 flow_hairpin_split(struct rte_eth_dev *dev,
4497 const struct rte_flow_action actions[],
4498 struct rte_flow_action actions_rx[],
4499 struct rte_flow_action actions_tx[],
4500 struct rte_flow_item pattern_tx[],
4503 const struct rte_flow_action_raw_encap *raw_encap;
4504 const struct rte_flow_action_raw_decap *raw_decap;
4505 struct mlx5_rte_flow_action_set_tag *set_tag;
4506 struct rte_flow_action *tag_action;
4507 struct mlx5_rte_flow_item_tag *tag_item;
4508 struct rte_flow_item *item;
4512 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4513 switch (actions->type) {
4514 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
4515 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
4516 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
4517 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
4518 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
4519 rte_memcpy(actions_tx, actions,
4520 sizeof(struct rte_flow_action));
4523 case RTE_FLOW_ACTION_TYPE_COUNT:
4525 rte_memcpy(actions_tx, actions,
4526 sizeof(struct rte_flow_action));
4529 rte_memcpy(actions_rx, actions,
4530 sizeof(struct rte_flow_action));
4534 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
4535 raw_encap = actions->conf;
4536 if (raw_encap->size > MLX5_ENCAPSULATION_DECISION_SIZE) {
4537 memcpy(actions_tx, actions,
4538 sizeof(struct rte_flow_action));
4542 rte_memcpy(actions_rx, actions,
4543 sizeof(struct rte_flow_action));
4547 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
4548 raw_decap = actions->conf;
4549 if (raw_decap->size < MLX5_ENCAPSULATION_DECISION_SIZE) {
4550 memcpy(actions_tx, actions,
4551 sizeof(struct rte_flow_action));
4554 rte_memcpy(actions_rx, actions,
4555 sizeof(struct rte_flow_action));
4560 rte_memcpy(actions_rx, actions,
4561 sizeof(struct rte_flow_action));
4566 /* Add set meta action and end action for the Rx flow. */
4567 tag_action = actions_rx;
4568 tag_action->type = (enum rte_flow_action_type)
4569 MLX5_RTE_FLOW_ACTION_TYPE_TAG;
4571 rte_memcpy(actions_rx, actions, sizeof(struct rte_flow_action));
4573 set_tag = (void *)actions_rx;
4574 *set_tag = (struct mlx5_rte_flow_action_set_tag) {
4575 .id = mlx5_flow_get_reg_id(dev, MLX5_HAIRPIN_RX, 0, NULL),
4578 MLX5_ASSERT(set_tag->id > REG_NON);
4579 tag_action->conf = set_tag;
4580 /* Create Tx item list. */
4581 rte_memcpy(actions_tx, actions, sizeof(struct rte_flow_action));
4582 addr = (void *)&pattern_tx[2];
4584 item->type = (enum rte_flow_item_type)
4585 MLX5_RTE_FLOW_ITEM_TYPE_TAG;
4586 tag_item = (void *)addr;
4587 tag_item->data = flow_id;
4588 tag_item->id = mlx5_flow_get_reg_id(dev, MLX5_HAIRPIN_TX, 0, NULL);
4589 MLX5_ASSERT(set_tag->id > REG_NON);
4590 item->spec = tag_item;
4591 addr += sizeof(struct mlx5_rte_flow_item_tag);
4592 tag_item = (void *)addr;
4593 tag_item->data = UINT32_MAX;
4594 tag_item->id = UINT16_MAX;
4595 item->mask = tag_item;
4598 item->type = RTE_FLOW_ITEM_TYPE_END;
4603 * The last stage of splitting chain, just creates the subflow
4604 * without any modification.
4607 * Pointer to Ethernet device.
4609 * Parent flow structure pointer.
4610 * @param[in, out] sub_flow
4611 * Pointer to return the created subflow, may be NULL.
4613 * Flow rule attributes.
4615 * Pattern specification (list terminated by the END pattern item).
4616 * @param[in] actions
4617 * Associated actions (list terminated by the END action).
4618 * @param[in] flow_split_info
4619 * Pointer to flow split info structure.
4621 * Perform verbose error reporting if not NULL.
4623 * 0 on success, negative value otherwise
4626 flow_create_split_inner(struct rte_eth_dev *dev,
4627 struct rte_flow *flow,
4628 struct mlx5_flow **sub_flow,
4629 const struct rte_flow_attr *attr,
4630 const struct rte_flow_item items[],
4631 const struct rte_flow_action actions[],
4632 struct mlx5_flow_split_info *flow_split_info,
4633 struct rte_flow_error *error)
4635 struct mlx5_flow *dev_flow;
4637 dev_flow = flow_drv_prepare(dev, flow, attr, items, actions,
4638 flow_split_info->flow_idx, error);
4641 dev_flow->flow = flow;
4642 dev_flow->external = flow_split_info->external;
4643 dev_flow->skip_scale = flow_split_info->skip_scale;
4644 /* Subflow object was created, we must include one in the list. */
4645 SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
4646 dev_flow->handle, next);
4648 * If dev_flow is as one of the suffix flow, some actions in suffix
4649 * flow may need some user defined item layer flags, and pass the
4650 * Metadate rxq mark flag to suffix flow as well.
4652 if (flow_split_info->prefix_layers)
4653 dev_flow->handle->layers = flow_split_info->prefix_layers;
4654 if (flow_split_info->prefix_mark)
4655 dev_flow->handle->mark = 1;
4657 *sub_flow = dev_flow;
4658 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
4659 dev_flow->dv.table_id = flow_split_info->table_id;
4661 return flow_drv_translate(dev, dev_flow, attr, items, actions, error);
4665 * Get the sub policy of a meter.
4668 * Pointer to Ethernet device.
4670 * Parent flow structure pointer.
4672 * Pointer to thread flow work space.
4674 * Flow rule attributes.
4676 * Pattern specification (list terminated by the END pattern item).
4678 * Perform verbose error reporting if not NULL.
4681 * Pointer to the meter sub policy, NULL otherwise and rte_errno is set.
4683 static struct mlx5_flow_meter_sub_policy *
4684 get_meter_sub_policy(struct rte_eth_dev *dev,
4685 struct rte_flow *flow,
4686 struct mlx5_flow_workspace *wks,
4687 const struct rte_flow_attr *attr,
4688 const struct rte_flow_item items[],
4689 struct rte_flow_error *error)
4691 struct mlx5_flow_meter_policy *policy;
4692 struct mlx5_flow_meter_policy *final_policy;
4693 struct mlx5_flow_meter_sub_policy *sub_policy = NULL;
4695 policy = wks->policy;
4696 final_policy = policy->is_hierarchy ? wks->final_policy : policy;
4697 if (final_policy->is_rss || final_policy->is_queue) {
4698 struct mlx5_flow_rss_desc rss_desc_v[MLX5_MTR_RTE_COLORS];
4699 struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS] = {0};
4703 * This is a tmp dev_flow,
4704 * no need to register any matcher for it in translate.
4706 wks->skip_matcher_reg = 1;
4707 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
4708 struct mlx5_flow dev_flow = {0};
4709 struct mlx5_flow_handle dev_handle = { {0} };
4710 uint8_t fate = final_policy->act_cnt[i].fate_action;
4712 if (fate == MLX5_FLOW_FATE_SHARED_RSS) {
4713 const struct rte_flow_action_rss *rss_act =
4714 final_policy->act_cnt[i].rss->conf;
4715 struct rte_flow_action rss_actions[2] = {
4717 .type = RTE_FLOW_ACTION_TYPE_RSS,
4721 .type = RTE_FLOW_ACTION_TYPE_END,
4726 dev_flow.handle = &dev_handle;
4727 dev_flow.ingress = attr->ingress;
4728 dev_flow.flow = flow;
4729 dev_flow.external = 0;
4730 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
4731 dev_flow.dv.transfer = attr->transfer;
4734 * Translate RSS action to get rss hash fields.
4736 if (flow_drv_translate(dev, &dev_flow, attr,
4737 items, rss_actions, error))
4739 rss_desc_v[i] = wks->rss_desc;
4740 rss_desc_v[i].key_len = MLX5_RSS_HASH_KEY_LEN;
4741 rss_desc_v[i].hash_fields =
4742 dev_flow.hash_fields;
4743 rss_desc_v[i].queue_num =
4744 rss_desc_v[i].hash_fields ?
4745 rss_desc_v[i].queue_num : 1;
4746 rss_desc_v[i].tunnel =
4747 !!(dev_flow.handle->layers &
4748 MLX5_FLOW_LAYER_TUNNEL);
4749 /* Use the RSS queues in the containers. */
4750 rss_desc_v[i].queue =
4751 (uint16_t *)(uintptr_t)rss_act->queue;
4752 rss_desc[i] = &rss_desc_v[i];
4753 } else if (fate == MLX5_FLOW_FATE_QUEUE) {
4754 /* This is queue action. */
4755 rss_desc_v[i] = wks->rss_desc;
4756 rss_desc_v[i].key_len = 0;
4757 rss_desc_v[i].hash_fields = 0;
4758 rss_desc_v[i].queue =
4759 &final_policy->act_cnt[i].queue;
4760 rss_desc_v[i].queue_num = 1;
4761 rss_desc[i] = &rss_desc_v[i];
4766 sub_policy = flow_drv_meter_sub_policy_rss_prepare(dev,
4767 flow, policy, rss_desc);
4769 enum mlx5_meter_domain mtr_domain =
4770 attr->transfer ? MLX5_MTR_DOMAIN_TRANSFER :
4771 (attr->egress ? MLX5_MTR_DOMAIN_EGRESS :
4772 MLX5_MTR_DOMAIN_INGRESS);
4773 sub_policy = policy->sub_policys[mtr_domain][0];
4776 rte_flow_error_set(error, EINVAL,
4777 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4778 "Failed to get meter sub-policy.");
4784 * Split the meter flow.
4786 * As meter flow will split to three sub flow, other than meter
4787 * action, the other actions make sense to only meter accepts
4788 * the packet. If it need to be dropped, no other additional
4789 * actions should be take.
4791 * One kind of special action which decapsulates the L3 tunnel
4792 * header will be in the prefix sub flow, as not to take the
4793 * L3 tunnel header into account.
4796 * Pointer to Ethernet device.
4798 * Parent flow structure pointer.
4800 * Pointer to thread flow work space.
4802 * Flow rule attributes.
4804 * Pattern specification (list terminated by the END pattern item).
4805 * @param[out] sfx_items
4806 * Suffix flow match items (list terminated by the END pattern item).
4807 * @param[in] actions
4808 * Associated actions (list terminated by the END action).
4809 * @param[out] actions_sfx
4810 * Suffix flow actions.
4811 * @param[out] actions_pre
4812 * Prefix flow actions.
4813 * @param[out] mtr_flow_id
4814 * Pointer to meter flow id.
4816 * Perform verbose error reporting if not NULL.
4819 * 0 on success, a negative errno value otherwise and rte_errno is set.
4822 flow_meter_split_prep(struct rte_eth_dev *dev,
4823 struct rte_flow *flow,
4824 struct mlx5_flow_workspace *wks,
4825 const struct rte_flow_attr *attr,
4826 const struct rte_flow_item items[],
4827 struct rte_flow_item sfx_items[],
4828 const struct rte_flow_action actions[],
4829 struct rte_flow_action actions_sfx[],
4830 struct rte_flow_action actions_pre[],
4831 uint32_t *mtr_flow_id,
4832 struct rte_flow_error *error)
4834 struct mlx5_priv *priv = dev->data->dev_private;
4835 struct mlx5_flow_meter_info *fm = wks->fm;
4836 struct rte_flow_action *tag_action = NULL;
4837 struct rte_flow_item *tag_item;
4838 struct mlx5_rte_flow_action_set_tag *set_tag;
4839 const struct rte_flow_action_raw_encap *raw_encap;
4840 const struct rte_flow_action_raw_decap *raw_decap;
4841 struct mlx5_rte_flow_item_tag *tag_item_spec;
4842 struct mlx5_rte_flow_item_tag *tag_item_mask;
4843 uint32_t tag_id = 0;
4844 struct rte_flow_item *vlan_item_dst = NULL;
4845 const struct rte_flow_item *vlan_item_src = NULL;
4846 struct rte_flow_action *hw_mtr_action;
4847 struct rte_flow_action *action_pre_head = NULL;
4848 int32_t flow_src_port = priv->representor_id;
4850 uint8_t mtr_id_offset = priv->mtr_reg_share ? MLX5_MTR_COLOR_BITS : 0;
4851 uint8_t mtr_reg_bits = priv->mtr_reg_share ?
4852 MLX5_MTR_IDLE_BITS_IN_COLOR_REG : MLX5_REG_BITS;
4853 uint32_t flow_id = 0;
4854 uint32_t flow_id_reversed = 0;
4855 uint8_t flow_id_bits = 0;
4858 /* Prepare the suffix subflow items. */
4859 tag_item = sfx_items++;
4860 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
4861 struct mlx5_priv *port_priv;
4862 const struct rte_flow_item_port_id *pid_v;
4863 int item_type = items->type;
4865 switch (item_type) {
4866 case RTE_FLOW_ITEM_TYPE_PORT_ID:
4867 pid_v = items->spec;
4869 port_priv = mlx5_port_to_eswitch_info(pid_v->id, false);
4871 return rte_flow_error_set(error,
4873 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
4875 "Failed to get port info.");
4876 flow_src_port = port_priv->representor_id;
4877 if (!fm->def_policy && wks->policy->is_hierarchy &&
4878 flow_src_port != priv->representor_id) {
4879 if (flow_drv_mtr_hierarchy_rule_create(dev,
4886 memcpy(sfx_items, items, sizeof(*sfx_items));
4889 case RTE_FLOW_ITEM_TYPE_VLAN:
4890 /* Determine if copy vlan item below. */
4891 vlan_item_src = items;
4892 vlan_item_dst = sfx_items++;
4893 vlan_item_dst->type = RTE_FLOW_ITEM_TYPE_VOID;
4899 sfx_items->type = RTE_FLOW_ITEM_TYPE_END;
4901 mtr_first = priv->sh->meter_aso_en &&
4902 (attr->egress || (attr->transfer && flow_src_port != UINT16_MAX));
4903 /* For ASO meter, meter must be before tag in TX direction. */
4905 action_pre_head = actions_pre++;
4906 /* Leave space for tag action. */
4907 tag_action = actions_pre++;
4909 /* Prepare the actions for prefix and suffix flow. */
4910 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4911 struct rte_flow_action *action_cur = NULL;
4913 switch (actions->type) {
4914 case RTE_FLOW_ACTION_TYPE_METER:
4916 action_cur = action_pre_head;
4918 /* Leave space for tag action. */
4919 tag_action = actions_pre++;
4920 action_cur = actions_pre++;
4923 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
4924 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
4925 action_cur = actions_pre++;
4927 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
4928 raw_encap = actions->conf;
4929 if (raw_encap->size < MLX5_ENCAPSULATION_DECISION_SIZE)
4930 action_cur = actions_pre++;
4932 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
4933 raw_decap = actions->conf;
4934 if (raw_decap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
4935 action_cur = actions_pre++;
4937 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
4938 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
4939 if (vlan_item_dst && vlan_item_src) {
4940 memcpy(vlan_item_dst, vlan_item_src,
4941 sizeof(*vlan_item_dst));
4943 * Convert to internal match item, it is used
4944 * for vlan push and set vid.
4946 vlan_item_dst->type = (enum rte_flow_item_type)
4947 MLX5_RTE_FLOW_ITEM_TYPE_VLAN;
4954 action_cur = (fm->def_policy) ?
4955 actions_sfx++ : actions_pre++;
4956 memcpy(action_cur, actions, sizeof(struct rte_flow_action));
4958 /* Add end action to the actions. */
4959 actions_sfx->type = RTE_FLOW_ACTION_TYPE_END;
4960 if (priv->sh->meter_aso_en) {
4962 * For ASO meter, need to add an extra jump action explicitly,
4963 * to jump from meter to policer table.
4965 struct mlx5_flow_meter_sub_policy *sub_policy;
4966 struct mlx5_flow_tbl_data_entry *tbl_data;
4968 if (!fm->def_policy) {
4969 sub_policy = get_meter_sub_policy(dev, flow, wks,
4970 attr, items, error);
4974 enum mlx5_meter_domain mtr_domain =
4975 attr->transfer ? MLX5_MTR_DOMAIN_TRANSFER :
4976 (attr->egress ? MLX5_MTR_DOMAIN_EGRESS :
4977 MLX5_MTR_DOMAIN_INGRESS);
4980 &priv->sh->mtrmng->def_policy[mtr_domain]->sub_policy;
4982 tbl_data = container_of(sub_policy->tbl_rsc,
4983 struct mlx5_flow_tbl_data_entry, tbl);
4984 hw_mtr_action = actions_pre++;
4985 hw_mtr_action->type = (enum rte_flow_action_type)
4986 MLX5_RTE_FLOW_ACTION_TYPE_JUMP;
4987 hw_mtr_action->conf = tbl_data->jump.action;
4989 actions_pre->type = RTE_FLOW_ACTION_TYPE_END;
4992 return rte_flow_error_set(error, ENOMEM,
4993 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
4994 NULL, "No tag action space.");
4996 tag_action->type = RTE_FLOW_ACTION_TYPE_VOID;
4999 /* Only default-policy Meter creates mtr flow id. */
5000 if (fm->def_policy) {
5001 mlx5_ipool_malloc(fm->flow_ipool, &tag_id);
5003 return rte_flow_error_set(error, ENOMEM,
5004 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
5005 "Failed to allocate meter flow id.");
5006 flow_id = tag_id - 1;
5007 flow_id_bits = (!flow_id) ? 1 :
5008 (MLX5_REG_BITS - __builtin_clz(flow_id));
5009 if ((flow_id_bits + priv->sh->mtrmng->max_mtr_bits) >
5011 mlx5_ipool_free(fm->flow_ipool, tag_id);
5012 return rte_flow_error_set(error, EINVAL,
5013 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
5014 "Meter flow id exceeds max limit.");
5016 if (flow_id_bits > priv->sh->mtrmng->max_mtr_flow_bits)
5017 priv->sh->mtrmng->max_mtr_flow_bits = flow_id_bits;
5019 /* Build tag actions and items for meter_id/meter flow_id. */
5020 set_tag = (struct mlx5_rte_flow_action_set_tag *)actions_pre;
5021 tag_item_spec = (struct mlx5_rte_flow_item_tag *)sfx_items;
5022 tag_item_mask = tag_item_spec + 1;
5023 /* Both flow_id and meter_id share the same register. */
5024 *set_tag = (struct mlx5_rte_flow_action_set_tag) {
5025 .id = (enum modify_reg)mlx5_flow_get_reg_id(dev, MLX5_MTR_ID,
5027 .offset = mtr_id_offset,
5028 .length = mtr_reg_bits,
5029 .data = flow->meter,
5032 * The color Reg bits used by flow_id are growing from
5033 * msb to lsb, so must do bit reverse for flow_id val in RegC.
5035 for (shift = 0; shift < flow_id_bits; shift++)
5036 flow_id_reversed = (flow_id_reversed << 1) |
5037 ((flow_id >> shift) & 0x1);
5039 flow_id_reversed << (mtr_reg_bits - flow_id_bits);
5040 tag_item_spec->id = set_tag->id;
5041 tag_item_spec->data = set_tag->data << mtr_id_offset;
5042 tag_item_mask->data = UINT32_MAX << mtr_id_offset;
5043 tag_action->type = (enum rte_flow_action_type)
5044 MLX5_RTE_FLOW_ACTION_TYPE_TAG;
5045 tag_action->conf = set_tag;
5046 tag_item->type = (enum rte_flow_item_type)
5047 MLX5_RTE_FLOW_ITEM_TYPE_TAG;
5048 tag_item->spec = tag_item_spec;
5049 tag_item->last = NULL;
5050 tag_item->mask = tag_item_mask;
5053 *mtr_flow_id = tag_id;
5058 * Split action list having QUEUE/RSS for metadata register copy.
5060 * Once Q/RSS action is detected in user's action list, the flow action
5061 * should be split in order to copy metadata registers, which will happen in
5063 * - CQE->flow_tag := reg_c[1] (MARK)
5064 * - CQE->flow_table_metadata (reg_b) := reg_c[0] (META)
5065 * The Q/RSS action will be performed on RX_ACT_TBL after passing by RX_CP_TBL.
5066 * This is because the last action of each flow must be a terminal action
5067 * (QUEUE, RSS or DROP).
5069 * Flow ID must be allocated to identify actions in the RX_ACT_TBL and it is
5070 * stored and kept in the mlx5_flow structure per each sub_flow.
5072 * The Q/RSS action is replaced with,
5073 * - SET_TAG, setting the allocated flow ID to reg_c[2].
5074 * And the following JUMP action is added at the end,
5075 * - JUMP, to RX_CP_TBL.
5077 * A flow to perform remained Q/RSS action will be created in RX_ACT_TBL by
5078 * flow_create_split_metadata() routine. The flow will look like,
5079 * - If flow ID matches (reg_c[2]), perform Q/RSS.
5082 * Pointer to Ethernet device.
5083 * @param[out] split_actions
5084 * Pointer to store split actions to jump to CP_TBL.
5085 * @param[in] actions
5086 * Pointer to the list of original flow actions.
5088 * Pointer to the Q/RSS action.
5089 * @param[in] actions_n
5090 * Number of original actions.
5092 * Perform verbose error reporting if not NULL.
5095 * non-zero unique flow_id on success, otherwise 0 and
5096 * error/rte_error are set.
5099 flow_mreg_split_qrss_prep(struct rte_eth_dev *dev,
5100 struct rte_flow_action *split_actions,
5101 const struct rte_flow_action *actions,
5102 const struct rte_flow_action *qrss,
5103 int actions_n, struct rte_flow_error *error)
5105 struct mlx5_priv *priv = dev->data->dev_private;
5106 struct mlx5_rte_flow_action_set_tag *set_tag;
5107 struct rte_flow_action_jump *jump;
5108 const int qrss_idx = qrss - actions;
5109 uint32_t flow_id = 0;
5113 * Given actions will be split
5114 * - Replace QUEUE/RSS action with SET_TAG to set flow ID.
5115 * - Add jump to mreg CP_TBL.
5116 * As a result, there will be one more action.
5119 memcpy(split_actions, actions, sizeof(*split_actions) * actions_n);
5120 set_tag = (void *)(split_actions + actions_n);
5122 * If tag action is not set to void(it means we are not the meter
5123 * suffix flow), add the tag action. Since meter suffix flow already
5124 * has the tag added.
5126 if (split_actions[qrss_idx].type != RTE_FLOW_ACTION_TYPE_VOID) {
5128 * Allocate the new subflow ID. This one is unique within
5129 * device and not shared with representors. Otherwise,
5130 * we would have to resolve multi-thread access synch
5131 * issue. Each flow on the shared device is appended
5132 * with source vport identifier, so the resulting
5133 * flows will be unique in the shared (by master and
5134 * representors) domain even if they have coinciding
5137 mlx5_ipool_malloc(priv->sh->ipool
5138 [MLX5_IPOOL_RSS_EXPANTION_FLOW_ID], &flow_id);
5140 return rte_flow_error_set(error, ENOMEM,
5141 RTE_FLOW_ERROR_TYPE_ACTION,
5142 NULL, "can't allocate id "
5143 "for split Q/RSS subflow");
5144 /* Internal SET_TAG action to set flow ID. */
5145 *set_tag = (struct mlx5_rte_flow_action_set_tag){
5148 ret = mlx5_flow_get_reg_id(dev, MLX5_COPY_MARK, 0, error);
5152 /* Construct new actions array. */
5153 /* Replace QUEUE/RSS action. */
5154 split_actions[qrss_idx] = (struct rte_flow_action){
5155 .type = (enum rte_flow_action_type)
5156 MLX5_RTE_FLOW_ACTION_TYPE_TAG,
5160 /* JUMP action to jump to mreg copy table (CP_TBL). */
5161 jump = (void *)(set_tag + 1);
5162 *jump = (struct rte_flow_action_jump){
5163 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
5165 split_actions[actions_n - 2] = (struct rte_flow_action){
5166 .type = RTE_FLOW_ACTION_TYPE_JUMP,
5169 split_actions[actions_n - 1] = (struct rte_flow_action){
5170 .type = RTE_FLOW_ACTION_TYPE_END,
5176 * Extend the given action list for Tx metadata copy.
5178 * Copy the given action list to the ext_actions and add flow metadata register
5179 * copy action in order to copy reg_a set by WQE to reg_c[0].
5181 * @param[out] ext_actions
5182 * Pointer to the extended action list.
5183 * @param[in] actions
5184 * Pointer to the list of actions.
5185 * @param[in] actions_n
5186 * Number of actions in the list.
5188 * Perform verbose error reporting if not NULL.
5189 * @param[in] encap_idx
5190 * The encap action inndex.
5193 * 0 on success, negative value otherwise
5196 flow_mreg_tx_copy_prep(struct rte_eth_dev *dev,
5197 struct rte_flow_action *ext_actions,
5198 const struct rte_flow_action *actions,
5199 int actions_n, struct rte_flow_error *error,
5202 struct mlx5_flow_action_copy_mreg *cp_mreg =
5203 (struct mlx5_flow_action_copy_mreg *)
5204 (ext_actions + actions_n + 1);
5207 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_RX, 0, error);
5211 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_TX, 0, error);
5216 memcpy(ext_actions, actions, sizeof(*ext_actions) * encap_idx);
5217 if (encap_idx == actions_n - 1) {
5218 ext_actions[actions_n - 1] = (struct rte_flow_action){
5219 .type = (enum rte_flow_action_type)
5220 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
5223 ext_actions[actions_n] = (struct rte_flow_action){
5224 .type = RTE_FLOW_ACTION_TYPE_END,
5227 ext_actions[encap_idx] = (struct rte_flow_action){
5228 .type = (enum rte_flow_action_type)
5229 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
5232 memcpy(ext_actions + encap_idx + 1, actions + encap_idx,
5233 sizeof(*ext_actions) * (actions_n - encap_idx));
5239 * Check the match action from the action list.
5241 * @param[in] actions
5242 * Pointer to the list of actions.
5244 * Flow rule attributes.
5246 * The action to be check if exist.
5247 * @param[out] match_action_pos
5248 * Pointer to the position of the matched action if exists, otherwise is -1.
5249 * @param[out] qrss_action_pos
5250 * Pointer to the position of the Queue/RSS action if exists, otherwise is -1.
5251 * @param[out] modify_after_mirror
5252 * Pointer to the flag of modify action after FDB mirroring.
5255 * > 0 the total number of actions.
5256 * 0 if not found match action in action list.
5259 flow_check_match_action(const struct rte_flow_action actions[],
5260 const struct rte_flow_attr *attr,
5261 enum rte_flow_action_type action,
5262 int *match_action_pos, int *qrss_action_pos,
5263 int *modify_after_mirror)
5265 const struct rte_flow_action_sample *sample;
5266 const struct rte_flow_action_raw_decap *decap;
5273 *match_action_pos = -1;
5274 *qrss_action_pos = -1;
5275 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
5276 if (actions->type == action) {
5278 *match_action_pos = actions_n;
5280 switch (actions->type) {
5281 case RTE_FLOW_ACTION_TYPE_QUEUE:
5282 case RTE_FLOW_ACTION_TYPE_RSS:
5283 *qrss_action_pos = actions_n;
5285 case RTE_FLOW_ACTION_TYPE_SAMPLE:
5286 sample = actions->conf;
5287 ratio = sample->ratio;
5288 sub_type = ((const struct rte_flow_action *)
5289 (sample->actions))->type;
5290 if (ratio == 1 && attr->transfer)
5293 case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
5294 case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
5295 case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
5296 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
5297 case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
5298 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
5299 case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
5300 case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
5301 case RTE_FLOW_ACTION_TYPE_DEC_TTL:
5302 case RTE_FLOW_ACTION_TYPE_SET_TTL:
5303 case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
5304 case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
5305 case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
5306 case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
5307 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
5308 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
5309 case RTE_FLOW_ACTION_TYPE_FLAG:
5310 case RTE_FLOW_ACTION_TYPE_MARK:
5311 case RTE_FLOW_ACTION_TYPE_SET_META:
5312 case RTE_FLOW_ACTION_TYPE_SET_TAG:
5313 case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
5314 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
5315 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
5316 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
5317 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
5318 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
5319 case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
5320 case RTE_FLOW_ACTION_TYPE_METER:
5322 *modify_after_mirror = 1;
5324 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
5325 decap = actions->conf;
5326 while ((++actions)->type == RTE_FLOW_ACTION_TYPE_VOID)
5329 if (actions->type == RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
5330 const struct rte_flow_action_raw_encap *encap =
5333 MLX5_ENCAPSULATION_DECISION_SIZE &&
5335 MLX5_ENCAPSULATION_DECISION_SIZE)
5340 *modify_after_mirror = 1;
5347 if (flag && fdb_mirror && !*modify_after_mirror) {
5348 /* FDB mirroring uses the destination array to implement
5349 * instead of FLOW_SAMPLER object.
5351 if (sub_type != RTE_FLOW_ACTION_TYPE_END)
5354 /* Count RTE_FLOW_ACTION_TYPE_END. */
5355 return flag ? actions_n + 1 : 0;
5358 #define SAMPLE_SUFFIX_ITEM 2
5361 * Split the sample flow.
5363 * As sample flow will split to two sub flow, sample flow with
5364 * sample action, the other actions will move to new suffix flow.
5366 * Also add unique tag id with tag action in the sample flow,
5367 * the same tag id will be as match in the suffix flow.
5370 * Pointer to Ethernet device.
5371 * @param[in] add_tag
5372 * Add extra tag action flag.
5373 * @param[out] sfx_items
5374 * Suffix flow match items (list terminated by the END pattern item).
5375 * @param[in] actions
5376 * Associated actions (list terminated by the END action).
5377 * @param[out] actions_sfx
5378 * Suffix flow actions.
5379 * @param[out] actions_pre
5380 * Prefix flow actions.
5381 * @param[in] actions_n
5382 * The total number of actions.
5383 * @param[in] sample_action_pos
5384 * The sample action position.
5385 * @param[in] qrss_action_pos
5386 * The Queue/RSS action position.
5387 * @param[in] jump_table
5388 * Add extra jump action flag.
5390 * Perform verbose error reporting if not NULL.
5393 * 0 on success, or unique flow_id, a negative errno value
5394 * otherwise and rte_errno is set.
5397 flow_sample_split_prep(struct rte_eth_dev *dev,
5399 struct rte_flow_item sfx_items[],
5400 const struct rte_flow_action actions[],
5401 struct rte_flow_action actions_sfx[],
5402 struct rte_flow_action actions_pre[],
5404 int sample_action_pos,
5405 int qrss_action_pos,
5407 struct rte_flow_error *error)
5409 struct mlx5_priv *priv = dev->data->dev_private;
5410 struct mlx5_rte_flow_action_set_tag *set_tag;
5411 struct mlx5_rte_flow_item_tag *tag_spec;
5412 struct mlx5_rte_flow_item_tag *tag_mask;
5413 struct rte_flow_action_jump *jump_action;
5414 uint32_t tag_id = 0;
5416 int append_index = 0;
5419 if (sample_action_pos < 0)
5420 return rte_flow_error_set(error, EINVAL,
5421 RTE_FLOW_ERROR_TYPE_ACTION,
5422 NULL, "invalid position of sample "
5424 /* Prepare the actions for prefix and suffix flow. */
5425 if (qrss_action_pos >= 0 && qrss_action_pos < sample_action_pos) {
5426 index = qrss_action_pos;
5427 /* Put the preceding the Queue/RSS action into prefix flow. */
5429 memcpy(actions_pre, actions,
5430 sizeof(struct rte_flow_action) * index);
5431 /* Put others preceding the sample action into prefix flow. */
5432 if (sample_action_pos > index + 1)
5433 memcpy(actions_pre + index, actions + index + 1,
5434 sizeof(struct rte_flow_action) *
5435 (sample_action_pos - index - 1));
5436 index = sample_action_pos - 1;
5437 /* Put Queue/RSS action into Suffix flow. */
5438 memcpy(actions_sfx, actions + qrss_action_pos,
5439 sizeof(struct rte_flow_action));
5442 index = sample_action_pos;
5444 memcpy(actions_pre, actions,
5445 sizeof(struct rte_flow_action) * index);
5447 /* For CX5, add an extra tag action for NIC-RX and E-Switch ingress.
5448 * For CX6DX and above, metadata registers Cx preserve their value,
5449 * add an extra tag action for NIC-RX and E-Switch Domain.
5452 /* Prepare the prefix tag action. */
5454 set_tag = (void *)(actions_pre + actions_n + append_index);
5455 ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, 0, error);
5458 mlx5_ipool_malloc(priv->sh->ipool
5459 [MLX5_IPOOL_RSS_EXPANTION_FLOW_ID], &tag_id);
5460 *set_tag = (struct mlx5_rte_flow_action_set_tag) {
5464 /* Prepare the suffix subflow items. */
5465 tag_spec = (void *)(sfx_items + SAMPLE_SUFFIX_ITEM);
5466 tag_spec->data = tag_id;
5467 tag_spec->id = set_tag->id;
5468 tag_mask = tag_spec + 1;
5469 tag_mask->data = UINT32_MAX;
5470 sfx_items[0] = (struct rte_flow_item){
5471 .type = (enum rte_flow_item_type)
5472 MLX5_RTE_FLOW_ITEM_TYPE_TAG,
5477 sfx_items[1] = (struct rte_flow_item){
5478 .type = (enum rte_flow_item_type)
5479 RTE_FLOW_ITEM_TYPE_END,
5481 /* Prepare the tag action in prefix subflow. */
5482 actions_pre[index++] =
5483 (struct rte_flow_action){
5484 .type = (enum rte_flow_action_type)
5485 MLX5_RTE_FLOW_ACTION_TYPE_TAG,
5489 memcpy(actions_pre + index, actions + sample_action_pos,
5490 sizeof(struct rte_flow_action));
5492 /* For the modify action after the sample action in E-Switch mirroring,
5493 * Add the extra jump action in prefix subflow and jump into the next
5494 * table, then do the modify action in the new table.
5497 /* Prepare the prefix jump action. */
5499 jump_action = (void *)(actions_pre + actions_n + append_index);
5500 jump_action->group = jump_table;
5501 actions_pre[index++] =
5502 (struct rte_flow_action){
5503 .type = (enum rte_flow_action_type)
5504 RTE_FLOW_ACTION_TYPE_JUMP,
5505 .conf = jump_action,
5508 actions_pre[index] = (struct rte_flow_action){
5509 .type = (enum rte_flow_action_type)
5510 RTE_FLOW_ACTION_TYPE_END,
5512 /* Put the actions after sample into Suffix flow. */
5513 memcpy(actions_sfx, actions + sample_action_pos + 1,
5514 sizeof(struct rte_flow_action) *
5515 (actions_n - sample_action_pos - 1));
5520 * The splitting for metadata feature.
5522 * - Q/RSS action on NIC Rx should be split in order to pass by
5523 * the mreg copy table (RX_CP_TBL) and then it jumps to the
5524 * action table (RX_ACT_TBL) which has the split Q/RSS action.
5526 * - All the actions on NIC Tx should have a mreg copy action to
5527 * copy reg_a from WQE to reg_c[0].
5530 * Pointer to Ethernet device.
5532 * Parent flow structure pointer.
5534 * Flow rule attributes.
5536 * Pattern specification (list terminated by the END pattern item).
5537 * @param[in] actions
5538 * Associated actions (list terminated by the END action).
5539 * @param[in] flow_split_info
5540 * Pointer to flow split info structure.
5542 * Perform verbose error reporting if not NULL.
5544 * 0 on success, negative value otherwise
5547 flow_create_split_metadata(struct rte_eth_dev *dev,
5548 struct rte_flow *flow,
5549 const struct rte_flow_attr *attr,
5550 const struct rte_flow_item items[],
5551 const struct rte_flow_action actions[],
5552 struct mlx5_flow_split_info *flow_split_info,
5553 struct rte_flow_error *error)
5555 struct mlx5_priv *priv = dev->data->dev_private;
5556 struct mlx5_dev_config *config = &priv->config;
5557 const struct rte_flow_action *qrss = NULL;
5558 struct rte_flow_action *ext_actions = NULL;
5559 struct mlx5_flow *dev_flow = NULL;
5560 uint32_t qrss_id = 0;
5567 /* Check whether extensive metadata feature is engaged. */
5568 if (!config->dv_flow_en ||
5569 config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
5570 !mlx5_flow_ext_mreg_supported(dev))
5571 return flow_create_split_inner(dev, flow, NULL, attr, items,
5572 actions, flow_split_info, error);
5573 actions_n = flow_parse_metadata_split_actions_info(actions, &qrss,
5576 /* Exclude hairpin flows from splitting. */
5577 if (qrss->type == RTE_FLOW_ACTION_TYPE_QUEUE) {
5578 const struct rte_flow_action_queue *queue;
5581 if (mlx5_rxq_get_type(dev, queue->index) ==
5582 MLX5_RXQ_TYPE_HAIRPIN)
5584 } else if (qrss->type == RTE_FLOW_ACTION_TYPE_RSS) {
5585 const struct rte_flow_action_rss *rss;
5588 if (mlx5_rxq_get_type(dev, rss->queue[0]) ==
5589 MLX5_RXQ_TYPE_HAIRPIN)
5594 /* Check if it is in meter suffix table. */
5595 mtr_sfx = attr->group == (attr->transfer ?
5596 (MLX5_FLOW_TABLE_LEVEL_METER - 1) :
5597 MLX5_FLOW_TABLE_LEVEL_METER);
5599 * Q/RSS action on NIC Rx should be split in order to pass by
5600 * the mreg copy table (RX_CP_TBL) and then it jumps to the
5601 * action table (RX_ACT_TBL) which has the split Q/RSS action.
5603 act_size = sizeof(struct rte_flow_action) * (actions_n + 1) +
5604 sizeof(struct rte_flow_action_set_tag) +
5605 sizeof(struct rte_flow_action_jump);
5606 ext_actions = mlx5_malloc(MLX5_MEM_ZERO, act_size, 0,
5609 return rte_flow_error_set(error, ENOMEM,
5610 RTE_FLOW_ERROR_TYPE_ACTION,
5611 NULL, "no memory to split "
5614 * If we are the suffix flow of meter, tag already exist.
5615 * Set the tag action to void.
5618 ext_actions[qrss - actions].type =
5619 RTE_FLOW_ACTION_TYPE_VOID;
5621 ext_actions[qrss - actions].type =
5622 (enum rte_flow_action_type)
5623 MLX5_RTE_FLOW_ACTION_TYPE_TAG;
5625 * Create the new actions list with removed Q/RSS action
5626 * and appended set tag and jump to register copy table
5627 * (RX_CP_TBL). We should preallocate unique tag ID here
5628 * in advance, because it is needed for set tag action.
5630 qrss_id = flow_mreg_split_qrss_prep(dev, ext_actions, actions,
5631 qrss, actions_n, error);
5632 if (!mtr_sfx && !qrss_id) {
5636 } else if (attr->egress && !attr->transfer) {
5638 * All the actions on NIC Tx should have a metadata register
5639 * copy action to copy reg_a from WQE to reg_c[meta]
5641 act_size = sizeof(struct rte_flow_action) * (actions_n + 1) +
5642 sizeof(struct mlx5_flow_action_copy_mreg);
5643 ext_actions = mlx5_malloc(MLX5_MEM_ZERO, act_size, 0,
5646 return rte_flow_error_set(error, ENOMEM,
5647 RTE_FLOW_ERROR_TYPE_ACTION,
5648 NULL, "no memory to split "
5650 /* Create the action list appended with copy register. */
5651 ret = flow_mreg_tx_copy_prep(dev, ext_actions, actions,
5652 actions_n, error, encap_idx);
5656 /* Add the unmodified original or prefix subflow. */
5657 ret = flow_create_split_inner(dev, flow, &dev_flow, attr,
5658 items, ext_actions ? ext_actions :
5659 actions, flow_split_info, error);
5662 MLX5_ASSERT(dev_flow);
5664 const struct rte_flow_attr q_attr = {
5665 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
5668 /* Internal PMD action to set register. */
5669 struct mlx5_rte_flow_item_tag q_tag_spec = {
5673 struct rte_flow_item q_items[] = {
5675 .type = (enum rte_flow_item_type)
5676 MLX5_RTE_FLOW_ITEM_TYPE_TAG,
5677 .spec = &q_tag_spec,
5682 .type = RTE_FLOW_ITEM_TYPE_END,
5685 struct rte_flow_action q_actions[] = {
5691 .type = RTE_FLOW_ACTION_TYPE_END,
5694 uint64_t layers = flow_get_prefix_layer_flags(dev_flow);
5697 * Configure the tag item only if there is no meter subflow.
5698 * Since tag is already marked in the meter suffix subflow
5699 * we can just use the meter suffix items as is.
5702 /* Not meter subflow. */
5703 MLX5_ASSERT(!mtr_sfx);
5705 * Put unique id in prefix flow due to it is destroyed
5706 * after suffix flow and id will be freed after there
5707 * is no actual flows with this id and identifier
5708 * reallocation becomes possible (for example, for
5709 * other flows in other threads).
5711 dev_flow->handle->split_flow_id = qrss_id;
5712 ret = mlx5_flow_get_reg_id(dev, MLX5_COPY_MARK, 0,
5716 q_tag_spec.id = ret;
5719 /* Add suffix subflow to execute Q/RSS. */
5720 flow_split_info->prefix_layers = layers;
5721 flow_split_info->prefix_mark = 0;
5722 ret = flow_create_split_inner(dev, flow, &dev_flow,
5723 &q_attr, mtr_sfx ? items :
5725 flow_split_info, error);
5728 /* qrss ID should be freed if failed. */
5730 MLX5_ASSERT(dev_flow);
5735 * We do not destroy the partially created sub_flows in case of error.
5736 * These ones are included into parent flow list and will be destroyed
5737 * by flow_drv_destroy.
5739 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RSS_EXPANTION_FLOW_ID],
5741 mlx5_free(ext_actions);
5746 * Create meter internal drop flow with the original pattern.
5749 * Pointer to Ethernet device.
5751 * Parent flow structure pointer.
5753 * Flow rule attributes.
5755 * Pattern specification (list terminated by the END pattern item).
5756 * @param[in] flow_split_info
5757 * Pointer to flow split info structure.
5759 * Pointer to flow meter structure.
5761 * Perform verbose error reporting if not NULL.
5763 * 0 on success, negative value otherwise
5766 flow_meter_create_drop_flow_with_org_pattern(struct rte_eth_dev *dev,
5767 struct rte_flow *flow,
5768 const struct rte_flow_attr *attr,
5769 const struct rte_flow_item items[],
5770 struct mlx5_flow_split_info *flow_split_info,
5771 struct mlx5_flow_meter_info *fm,
5772 struct rte_flow_error *error)
5774 struct mlx5_flow *dev_flow = NULL;
5775 struct rte_flow_attr drop_attr = *attr;
5776 struct rte_flow_action drop_actions[3];
5777 struct mlx5_flow_split_info drop_split_info = *flow_split_info;
5779 MLX5_ASSERT(fm->drop_cnt);
5780 drop_actions[0].type =
5781 (enum rte_flow_action_type)MLX5_RTE_FLOW_ACTION_TYPE_COUNT;
5782 drop_actions[0].conf = (void *)(uintptr_t)fm->drop_cnt;
5783 drop_actions[1].type = RTE_FLOW_ACTION_TYPE_DROP;
5784 drop_actions[1].conf = NULL;
5785 drop_actions[2].type = RTE_FLOW_ACTION_TYPE_END;
5786 drop_actions[2].conf = NULL;
5787 drop_split_info.external = false;
5788 drop_split_info.skip_scale |= 1 << MLX5_SCALE_FLOW_GROUP_BIT;
5789 drop_split_info.table_id = MLX5_MTR_TABLE_ID_DROP;
5790 drop_attr.group = MLX5_FLOW_TABLE_LEVEL_METER;
5791 return flow_create_split_inner(dev, flow, &dev_flow,
5792 &drop_attr, items, drop_actions,
5793 &drop_split_info, error);
5797 * The splitting for meter feature.
5799 * - The meter flow will be split to two flows as prefix and
5800 * suffix flow. The packets make sense only it pass the prefix
5803 * - Reg_C_5 is used for the packet to match betweend prefix and
5807 * Pointer to Ethernet device.
5809 * Parent flow structure pointer.
5811 * Flow rule attributes.
5813 * Pattern specification (list terminated by the END pattern item).
5814 * @param[in] actions
5815 * Associated actions (list terminated by the END action).
5816 * @param[in] flow_split_info
5817 * Pointer to flow split info structure.
5819 * Perform verbose error reporting if not NULL.
5821 * 0 on success, negative value otherwise
5824 flow_create_split_meter(struct rte_eth_dev *dev,
5825 struct rte_flow *flow,
5826 const struct rte_flow_attr *attr,
5827 const struct rte_flow_item items[],
5828 const struct rte_flow_action actions[],
5829 struct mlx5_flow_split_info *flow_split_info,
5830 struct rte_flow_error *error)
5832 struct mlx5_priv *priv = dev->data->dev_private;
5833 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
5834 struct rte_flow_action *sfx_actions = NULL;
5835 struct rte_flow_action *pre_actions = NULL;
5836 struct rte_flow_item *sfx_items = NULL;
5837 struct mlx5_flow *dev_flow = NULL;
5838 struct rte_flow_attr sfx_attr = *attr;
5839 struct mlx5_flow_meter_info *fm = NULL;
5840 uint8_t skip_scale_restore;
5841 bool has_mtr = false;
5842 bool has_modify = false;
5843 bool set_mtr_reg = true;
5844 bool is_mtr_hierarchy = false;
5845 uint32_t meter_id = 0;
5846 uint32_t mtr_idx = 0;
5847 uint32_t mtr_flow_id = 0;
5854 actions_n = flow_check_meter_action(dev, actions, &has_mtr,
5855 &has_modify, &meter_id);
5858 fm = flow_dv_meter_find_by_idx(priv, flow->meter);
5860 return rte_flow_error_set(error, EINVAL,
5861 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5862 NULL, "Meter not found.");
5864 fm = mlx5_flow_meter_find(priv, meter_id, &mtr_idx);
5866 return rte_flow_error_set(error, EINVAL,
5867 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5868 NULL, "Meter not found.");
5869 ret = mlx5_flow_meter_attach(priv, fm,
5873 flow->meter = mtr_idx;
5877 if (!fm->def_policy) {
5878 wks->policy = mlx5_flow_meter_policy_find(dev,
5881 MLX5_ASSERT(wks->policy);
5882 if (wks->policy->is_hierarchy) {
5884 mlx5_flow_meter_hierarchy_get_final_policy(dev,
5886 if (!wks->final_policy)
5887 return rte_flow_error_set(error,
5889 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5890 "Failed to find terminal policy of hierarchy.");
5891 is_mtr_hierarchy = true;
5895 * If it isn't default-policy Meter, and
5896 * 1. There's no action in flow to change
5897 * packet (modify/encap/decap etc.), OR
5898 * 2. No drop count needed for this meter.
5899 * 3. It's not meter hierarchy.
5900 * Then no need to use regC to save meter id anymore.
5902 if (!fm->def_policy && !is_mtr_hierarchy &&
5903 (!has_modify || !fm->drop_cnt))
5904 set_mtr_reg = false;
5905 /* Prefix actions: meter, decap, encap, tag, jump, end. */
5906 act_size = sizeof(struct rte_flow_action) * (actions_n + 6) +
5907 sizeof(struct mlx5_rte_flow_action_set_tag);
5908 /* Suffix items: tag, vlan, port id, end. */
5909 #define METER_SUFFIX_ITEM 4
5910 item_size = sizeof(struct rte_flow_item) * METER_SUFFIX_ITEM +
5911 sizeof(struct mlx5_rte_flow_item_tag) * 2;
5912 sfx_actions = mlx5_malloc(MLX5_MEM_ZERO, (act_size + item_size),
5915 return rte_flow_error_set(error, ENOMEM,
5916 RTE_FLOW_ERROR_TYPE_ACTION,
5917 NULL, "no memory to split "
5919 sfx_items = (struct rte_flow_item *)((char *)sfx_actions +
5921 /* There's no suffix flow for meter of non-default policy. */
5922 if (!fm->def_policy)
5923 pre_actions = sfx_actions + 1;
5925 pre_actions = sfx_actions + actions_n;
5926 ret = flow_meter_split_prep(dev, flow, wks, &sfx_attr,
5927 items, sfx_items, actions,
5928 sfx_actions, pre_actions,
5929 (set_mtr_reg ? &mtr_flow_id : NULL),
5935 /* Add the prefix subflow. */
5936 flow_split_info->prefix_mark = 0;
5937 skip_scale_restore = flow_split_info->skip_scale;
5938 flow_split_info->skip_scale |=
5939 1 << MLX5_SCALE_JUMP_FLOW_GROUP_BIT;
5940 ret = flow_create_split_inner(dev, flow, &dev_flow,
5941 attr, items, pre_actions,
5942 flow_split_info, error);
5943 flow_split_info->skip_scale = skip_scale_restore;
5946 mlx5_ipool_free(fm->flow_ipool, mtr_flow_id);
5951 dev_flow->handle->split_flow_id = mtr_flow_id;
5952 dev_flow->handle->is_meter_flow_id = 1;
5954 if (!fm->def_policy) {
5955 if (!set_mtr_reg && fm->drop_cnt)
5957 flow_meter_create_drop_flow_with_org_pattern(dev, flow,
5963 /* Setting the sfx group atrr. */
5964 sfx_attr.group = sfx_attr.transfer ?
5965 (MLX5_FLOW_TABLE_LEVEL_METER - 1) :
5966 MLX5_FLOW_TABLE_LEVEL_METER;
5967 flow_split_info->prefix_layers =
5968 flow_get_prefix_layer_flags(dev_flow);
5969 flow_split_info->prefix_mark = dev_flow->handle->mark;
5970 flow_split_info->table_id = MLX5_MTR_TABLE_ID_SUFFIX;
5972 /* Add the prefix subflow. */
5973 ret = flow_create_split_metadata(dev, flow,
5974 &sfx_attr, sfx_items ?
5976 sfx_actions ? sfx_actions : actions,
5977 flow_split_info, error);
5980 mlx5_free(sfx_actions);
5985 * The splitting for sample feature.
5987 * Once Sample action is detected in the action list, the flow actions should
5988 * be split into prefix sub flow and suffix sub flow.
5990 * The original items remain in the prefix sub flow, all actions preceding the
5991 * sample action and the sample action itself will be copied to the prefix
5992 * sub flow, the actions following the sample action will be copied to the
5993 * suffix sub flow, Queue action always be located in the suffix sub flow.
5995 * In order to make the packet from prefix sub flow matches with suffix sub
5996 * flow, an extra tag action be added into prefix sub flow, and the suffix sub
5997 * flow uses tag item with the unique flow id.
6000 * Pointer to Ethernet device.
6002 * Parent flow structure pointer.
6004 * Flow rule attributes.
6006 * Pattern specification (list terminated by the END pattern item).
6007 * @param[in] actions
6008 * Associated actions (list terminated by the END action).
6009 * @param[in] flow_split_info
6010 * Pointer to flow split info structure.
6012 * Perform verbose error reporting if not NULL.
6014 * 0 on success, negative value otherwise
6017 flow_create_split_sample(struct rte_eth_dev *dev,
6018 struct rte_flow *flow,
6019 const struct rte_flow_attr *attr,
6020 const struct rte_flow_item items[],
6021 const struct rte_flow_action actions[],
6022 struct mlx5_flow_split_info *flow_split_info,
6023 struct rte_flow_error *error)
6025 struct mlx5_priv *priv = dev->data->dev_private;
6026 struct rte_flow_action *sfx_actions = NULL;
6027 struct rte_flow_action *pre_actions = NULL;
6028 struct rte_flow_item *sfx_items = NULL;
6029 struct mlx5_flow *dev_flow = NULL;
6030 struct rte_flow_attr sfx_attr = *attr;
6031 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
6032 struct mlx5_flow_dv_sample_resource *sample_res;
6033 struct mlx5_flow_tbl_data_entry *sfx_tbl_data;
6034 struct mlx5_flow_tbl_resource *sfx_tbl;
6038 uint32_t fdb_tx = 0;
6041 int sample_action_pos;
6042 int qrss_action_pos;
6044 int modify_after_mirror = 0;
6045 uint16_t jump_table = 0;
6046 const uint32_t next_ft_step = 1;
6049 if (priv->sampler_en)
6050 actions_n = flow_check_match_action(actions, attr,
6051 RTE_FLOW_ACTION_TYPE_SAMPLE,
6052 &sample_action_pos, &qrss_action_pos,
6053 &modify_after_mirror);
6055 /* The prefix actions must includes sample, tag, end. */
6056 act_size = sizeof(struct rte_flow_action) * (actions_n * 2 + 1)
6057 + sizeof(struct mlx5_rte_flow_action_set_tag);
6058 item_size = sizeof(struct rte_flow_item) * SAMPLE_SUFFIX_ITEM +
6059 sizeof(struct mlx5_rte_flow_item_tag) * 2;
6060 sfx_actions = mlx5_malloc(MLX5_MEM_ZERO, (act_size +
6061 item_size), 0, SOCKET_ID_ANY);
6063 return rte_flow_error_set(error, ENOMEM,
6064 RTE_FLOW_ERROR_TYPE_ACTION,
6065 NULL, "no memory to split "
6067 /* The representor_id is UINT16_MAX for uplink. */
6068 fdb_tx = (attr->transfer && priv->representor_id != UINT16_MAX);
6070 * When reg_c_preserve is set, metadata registers Cx preserve
6071 * their value even through packet duplication.
6073 add_tag = (!fdb_tx || priv->config.hca_attr.reg_c_preserve);
6075 sfx_items = (struct rte_flow_item *)((char *)sfx_actions
6077 if (modify_after_mirror)
6078 jump_table = attr->group * MLX5_FLOW_TABLE_FACTOR +
6080 pre_actions = sfx_actions + actions_n;
6081 tag_id = flow_sample_split_prep(dev, add_tag, sfx_items,
6082 actions, sfx_actions,
6083 pre_actions, actions_n,
6085 qrss_action_pos, jump_table,
6087 if (tag_id < 0 || (add_tag && !tag_id)) {
6091 if (modify_after_mirror)
6092 flow_split_info->skip_scale =
6093 1 << MLX5_SCALE_JUMP_FLOW_GROUP_BIT;
6094 /* Add the prefix subflow. */
6095 ret = flow_create_split_inner(dev, flow, &dev_flow, attr,
6097 flow_split_info, error);
6102 dev_flow->handle->split_flow_id = tag_id;
6103 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
6104 if (!modify_after_mirror) {
6105 /* Set the sfx group attr. */
6106 sample_res = (struct mlx5_flow_dv_sample_resource *)
6107 dev_flow->dv.sample_res;
6108 sfx_tbl = (struct mlx5_flow_tbl_resource *)
6109 sample_res->normal_path_tbl;
6110 sfx_tbl_data = container_of(sfx_tbl,
6111 struct mlx5_flow_tbl_data_entry,
6113 sfx_attr.group = sfx_attr.transfer ?
6114 (sfx_tbl_data->level - 1) : sfx_tbl_data->level;
6116 MLX5_ASSERT(attr->transfer);
6117 sfx_attr.group = jump_table;
6119 flow_split_info->prefix_layers =
6120 flow_get_prefix_layer_flags(dev_flow);
6121 flow_split_info->prefix_mark = dev_flow->handle->mark;
6122 /* Suffix group level already be scaled with factor, set
6123 * MLX5_SCALE_FLOW_GROUP_BIT of skip_scale to 1 to avoid scale
6124 * again in translation.
6126 flow_split_info->skip_scale = 1 << MLX5_SCALE_FLOW_GROUP_BIT;
6129 /* Add the suffix subflow. */
6130 ret = flow_create_split_meter(dev, flow, &sfx_attr,
6131 sfx_items ? sfx_items : items,
6132 sfx_actions ? sfx_actions : actions,
6133 flow_split_info, error);
6136 mlx5_free(sfx_actions);
6141 * Split the flow to subflow set. The splitters might be linked
6142 * in the chain, like this:
6143 * flow_create_split_outer() calls:
6144 * flow_create_split_meter() calls:
6145 * flow_create_split_metadata(meter_subflow_0) calls:
6146 * flow_create_split_inner(metadata_subflow_0)
6147 * flow_create_split_inner(metadata_subflow_1)
6148 * flow_create_split_inner(metadata_subflow_2)
6149 * flow_create_split_metadata(meter_subflow_1) calls:
6150 * flow_create_split_inner(metadata_subflow_0)
6151 * flow_create_split_inner(metadata_subflow_1)
6152 * flow_create_split_inner(metadata_subflow_2)
6154 * This provide flexible way to add new levels of flow splitting.
6155 * The all of successfully created subflows are included to the
6156 * parent flow dev_flow list.
6159 * Pointer to Ethernet device.
6161 * Parent flow structure pointer.
6163 * Flow rule attributes.
6165 * Pattern specification (list terminated by the END pattern item).
6166 * @param[in] actions
6167 * Associated actions (list terminated by the END action).
6168 * @param[in] flow_split_info
6169 * Pointer to flow split info structure.
6171 * Perform verbose error reporting if not NULL.
6173 * 0 on success, negative value otherwise
6176 flow_create_split_outer(struct rte_eth_dev *dev,
6177 struct rte_flow *flow,
6178 const struct rte_flow_attr *attr,
6179 const struct rte_flow_item items[],
6180 const struct rte_flow_action actions[],
6181 struct mlx5_flow_split_info *flow_split_info,
6182 struct rte_flow_error *error)
6186 ret = flow_create_split_sample(dev, flow, attr, items,
6187 actions, flow_split_info, error);
6188 MLX5_ASSERT(ret <= 0);
6192 static inline struct mlx5_flow_tunnel *
6193 flow_tunnel_from_rule(const struct mlx5_flow *flow)
6195 struct mlx5_flow_tunnel *tunnel;
6197 #pragma GCC diagnostic push
6198 #pragma GCC diagnostic ignored "-Wcast-qual"
6199 tunnel = (typeof(tunnel))flow->tunnel;
6200 #pragma GCC diagnostic pop
6206 * Adjust flow RSS workspace if needed.
6209 * Pointer to thread flow work space.
6211 * Pointer to RSS descriptor.
6212 * @param[in] nrssq_num
6213 * New RSS queue number.
6216 * 0 on success, -1 otherwise and rte_errno is set.
6219 flow_rss_workspace_adjust(struct mlx5_flow_workspace *wks,
6220 struct mlx5_flow_rss_desc *rss_desc,
6223 if (likely(nrssq_num <= wks->rssq_num))
6225 rss_desc->queue = realloc(rss_desc->queue,
6226 sizeof(*rss_desc->queue) * RTE_ALIGN(nrssq_num, 2));
6227 if (!rss_desc->queue) {
6231 wks->rssq_num = RTE_ALIGN(nrssq_num, 2);
6236 * Create a flow and add it to @p list.
6239 * Pointer to Ethernet device.
6241 * Pointer to a TAILQ flow list. If this parameter NULL,
6242 * no list insertion occurred, flow is just created,
6243 * this is caller's responsibility to track the
6246 * Flow rule attributes.
6248 * Pattern specification (list terminated by the END pattern item).
6249 * @param[in] actions
6250 * Associated actions (list terminated by the END action).
6251 * @param[in] external
6252 * This flow rule is created by request external to PMD.
6254 * Perform verbose error reporting if not NULL.
6257 * A flow index on success, 0 otherwise and rte_errno is set.
6260 flow_list_create(struct rte_eth_dev *dev, enum mlx5_flow_type type,
6261 const struct rte_flow_attr *attr,
6262 const struct rte_flow_item items[],
6263 const struct rte_flow_action original_actions[],
6264 bool external, struct rte_flow_error *error)
6266 struct mlx5_priv *priv = dev->data->dev_private;
6267 struct rte_flow *flow = NULL;
6268 struct mlx5_flow *dev_flow;
6269 const struct rte_flow_action_rss *rss = NULL;
6270 struct mlx5_translated_action_handle
6271 indir_actions[MLX5_MAX_INDIRECT_ACTIONS];
6272 int indir_actions_n = MLX5_MAX_INDIRECT_ACTIONS;
6274 struct mlx5_flow_expand_rss buf;
6275 uint8_t buffer[2048];
6278 struct rte_flow_action actions[MLX5_MAX_SPLIT_ACTIONS];
6279 uint8_t buffer[2048];
6282 struct rte_flow_action actions[MLX5_MAX_SPLIT_ACTIONS];
6283 uint8_t buffer[2048];
6284 } actions_hairpin_tx;
6286 struct rte_flow_item items[MLX5_MAX_SPLIT_ITEMS];
6287 uint8_t buffer[2048];
6289 struct mlx5_flow_expand_rss *buf = &expand_buffer.buf;
6290 struct mlx5_flow_rss_desc *rss_desc;
6291 const struct rte_flow_action *p_actions_rx;
6295 struct rte_flow_attr attr_tx = { .priority = 0 };
6296 const struct rte_flow_action *actions;
6297 struct rte_flow_action *translated_actions = NULL;
6298 struct mlx5_flow_tunnel *tunnel;
6299 struct tunnel_default_miss_ctx default_miss_ctx = { 0, };
6300 struct mlx5_flow_workspace *wks = mlx5_flow_push_thread_workspace();
6301 struct mlx5_flow_split_info flow_split_info = {
6302 .external = !!external,
6312 rss_desc = &wks->rss_desc;
6313 ret = flow_action_handles_translate(dev, original_actions,
6316 &translated_actions, error);
6318 MLX5_ASSERT(translated_actions == NULL);
6321 actions = translated_actions ? translated_actions : original_actions;
6322 p_actions_rx = actions;
6323 hairpin_flow = flow_check_hairpin_split(dev, attr, actions);
6324 ret = flow_drv_validate(dev, attr, items, p_actions_rx,
6325 external, hairpin_flow, error);
6327 goto error_before_hairpin_split;
6328 flow = mlx5_ipool_zmalloc(priv->flows[type], &idx);
6331 goto error_before_hairpin_split;
6333 if (hairpin_flow > 0) {
6334 if (hairpin_flow > MLX5_MAX_SPLIT_ACTIONS) {
6336 goto error_before_hairpin_split;
6338 flow_hairpin_split(dev, actions, actions_rx.actions,
6339 actions_hairpin_tx.actions, items_tx.items,
6341 p_actions_rx = actions_rx.actions;
6343 flow_split_info.flow_idx = idx;
6344 flow->drv_type = flow_get_drv_type(dev, attr);
6345 MLX5_ASSERT(flow->drv_type > MLX5_FLOW_TYPE_MIN &&
6346 flow->drv_type < MLX5_FLOW_TYPE_MAX);
6347 memset(rss_desc, 0, offsetof(struct mlx5_flow_rss_desc, queue));
6348 /* RSS Action only works on NIC RX domain */
6349 if (attr->ingress && !attr->transfer)
6350 rss = flow_get_rss_action(dev, p_actions_rx);
6352 if (flow_rss_workspace_adjust(wks, rss_desc, rss->queue_num))
6355 * The following information is required by
6356 * mlx5_flow_hashfields_adjust() in advance.
6358 rss_desc->level = rss->level;
6359 /* RSS type 0 indicates default RSS type (ETH_RSS_IP). */
6360 rss_desc->types = !rss->types ? ETH_RSS_IP : rss->types;
6362 flow->dev_handles = 0;
6363 if (rss && rss->types) {
6364 unsigned int graph_root;
6366 graph_root = find_graph_root(items, rss->level);
6367 ret = mlx5_flow_expand_rss(buf, sizeof(expand_buffer.buffer),
6369 mlx5_support_expansion, graph_root);
6370 MLX5_ASSERT(ret > 0 &&
6371 (unsigned int)ret < sizeof(expand_buffer.buffer));
6372 if (rte_log_can_log(mlx5_logtype, RTE_LOG_DEBUG)) {
6373 for (i = 0; i < buf->entries; ++i)
6374 mlx5_dbg__print_pattern(buf->entry[i].pattern);
6378 buf->entry[0].pattern = (void *)(uintptr_t)items;
6380 rss_desc->shared_rss = flow_get_shared_rss_action(dev, indir_actions,
6382 for (i = 0; i < buf->entries; ++i) {
6383 /* Initialize flow split data. */
6384 flow_split_info.prefix_layers = 0;
6385 flow_split_info.prefix_mark = 0;
6386 flow_split_info.skip_scale = 0;
6388 * The splitter may create multiple dev_flows,
6389 * depending on configuration. In the simplest
6390 * case it just creates unmodified original flow.
6392 ret = flow_create_split_outer(dev, flow, attr,
6393 buf->entry[i].pattern,
6394 p_actions_rx, &flow_split_info,
6398 if (is_flow_tunnel_steer_rule(wks->flows[0].tof_type)) {
6399 ret = flow_tunnel_add_default_miss(dev, flow, attr,
6402 wks->flows[0].tunnel,
6406 mlx5_free(default_miss_ctx.queue);
6411 /* Create the tx flow. */
6413 attr_tx.group = MLX5_HAIRPIN_TX_TABLE;
6414 attr_tx.ingress = 0;
6416 dev_flow = flow_drv_prepare(dev, flow, &attr_tx, items_tx.items,
6417 actions_hairpin_tx.actions,
6421 dev_flow->flow = flow;
6422 dev_flow->external = 0;
6423 SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
6424 dev_flow->handle, next);
6425 ret = flow_drv_translate(dev, dev_flow, &attr_tx,
6427 actions_hairpin_tx.actions, error);
6432 * Update the metadata register copy table. If extensive
6433 * metadata feature is enabled and registers are supported
6434 * we might create the extra rte_flow for each unique
6435 * MARK/FLAG action ID.
6437 * The table is updated for ingress Flows only, because
6438 * the egress Flows belong to the different device and
6439 * copy table should be updated in peer NIC Rx domain.
6441 if (attr->ingress &&
6442 (external || attr->group != MLX5_FLOW_MREG_CP_TABLE_GROUP)) {
6443 ret = flow_mreg_update_copy_table(dev, flow, actions, error);
6448 * If the flow is external (from application) OR device is started,
6449 * OR mreg discover, then apply immediately.
6451 if (external || dev->data->dev_started ||
6452 (attr->group == MLX5_FLOW_MREG_CP_TABLE_GROUP &&
6453 attr->priority == MLX5_FLOW_LOWEST_PRIO_INDICATOR)) {
6454 ret = flow_drv_apply(dev, flow, error);
6459 flow_rxq_flags_set(dev, flow);
6460 rte_free(translated_actions);
6461 tunnel = flow_tunnel_from_rule(wks->flows);
6464 flow->tunnel_id = tunnel->tunnel_id;
6465 __atomic_add_fetch(&tunnel->refctn, 1, __ATOMIC_RELAXED);
6466 mlx5_free(default_miss_ctx.queue);
6468 mlx5_flow_pop_thread_workspace();
6472 ret = rte_errno; /* Save rte_errno before cleanup. */
6473 flow_mreg_del_copy_action(dev, flow);
6474 flow_drv_destroy(dev, flow);
6475 if (rss_desc->shared_rss)
6476 __atomic_sub_fetch(&((struct mlx5_shared_action_rss *)
6478 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
6479 rss_desc->shared_rss))->refcnt, 1, __ATOMIC_RELAXED);
6480 mlx5_ipool_free(priv->flows[type], idx);
6481 rte_errno = ret; /* Restore rte_errno. */
6484 mlx5_flow_pop_thread_workspace();
6485 error_before_hairpin_split:
6486 rte_free(translated_actions);
6491 * Create a dedicated flow rule on e-switch table 0 (root table), to direct all
6492 * incoming packets to table 1.
6494 * Other flow rules, requested for group n, will be created in
6495 * e-switch table n+1.
6496 * Jump action to e-switch group n will be created to group n+1.
6498 * Used when working in switchdev mode, to utilise advantages of table 1
6502 * Pointer to Ethernet device.
6505 * Pointer to flow on success, NULL otherwise and rte_errno is set.
6508 mlx5_flow_create_esw_table_zero_flow(struct rte_eth_dev *dev)
6510 const struct rte_flow_attr attr = {
6517 const struct rte_flow_item pattern = {
6518 .type = RTE_FLOW_ITEM_TYPE_END,
6520 struct rte_flow_action_jump jump = {
6523 const struct rte_flow_action actions[] = {
6525 .type = RTE_FLOW_ACTION_TYPE_JUMP,
6529 .type = RTE_FLOW_ACTION_TYPE_END,
6532 struct rte_flow_error error;
6534 return (void *)(uintptr_t)flow_list_create(dev, MLX5_FLOW_TYPE_CTL,
6536 actions, false, &error);
6540 * Validate a flow supported by the NIC.
6542 * @see rte_flow_validate()
6546 mlx5_flow_validate(struct rte_eth_dev *dev,
6547 const struct rte_flow_attr *attr,
6548 const struct rte_flow_item items[],
6549 const struct rte_flow_action original_actions[],
6550 struct rte_flow_error *error)
6553 struct mlx5_translated_action_handle
6554 indir_actions[MLX5_MAX_INDIRECT_ACTIONS];
6555 int indir_actions_n = MLX5_MAX_INDIRECT_ACTIONS;
6556 const struct rte_flow_action *actions;
6557 struct rte_flow_action *translated_actions = NULL;
6558 int ret = flow_action_handles_translate(dev, original_actions,
6561 &translated_actions, error);
6565 actions = translated_actions ? translated_actions : original_actions;
6566 hairpin_flow = flow_check_hairpin_split(dev, attr, actions);
6567 ret = flow_drv_validate(dev, attr, items, actions,
6568 true, hairpin_flow, error);
6569 rte_free(translated_actions);
6576 * @see rte_flow_create()
6580 mlx5_flow_create(struct rte_eth_dev *dev,
6581 const struct rte_flow_attr *attr,
6582 const struct rte_flow_item items[],
6583 const struct rte_flow_action actions[],
6584 struct rte_flow_error *error)
6587 * If the device is not started yet, it is not allowed to created a
6588 * flow from application. PMD default flows and traffic control flows
6591 if (unlikely(!dev->data->dev_started)) {
6592 DRV_LOG(DEBUG, "port %u is not started when "
6593 "inserting a flow", dev->data->port_id);
6594 rte_flow_error_set(error, ENODEV,
6595 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6597 "port not started");
6601 return (void *)(uintptr_t)flow_list_create(dev, MLX5_FLOW_TYPE_GEN,
6602 attr, items, actions,
6607 * Destroy a flow in a list.
6610 * Pointer to Ethernet device.
6611 * @param[in] flow_idx
6612 * Index of flow to destroy.
6615 flow_list_destroy(struct rte_eth_dev *dev, enum mlx5_flow_type type,
6618 struct mlx5_priv *priv = dev->data->dev_private;
6619 struct rte_flow *flow = mlx5_ipool_get(priv->flows[type], flow_idx);
6623 MLX5_ASSERT(flow->type == type);
6625 * Update RX queue flags only if port is started, otherwise it is
6628 if (dev->data->dev_started)
6629 flow_rxq_flags_trim(dev, flow);
6630 flow_drv_destroy(dev, flow);
6632 struct mlx5_flow_tunnel *tunnel;
6634 tunnel = mlx5_find_tunnel_id(dev, flow->tunnel_id);
6636 if (!__atomic_sub_fetch(&tunnel->refctn, 1, __ATOMIC_RELAXED))
6637 mlx5_flow_tunnel_free(dev, tunnel);
6639 flow_mreg_del_copy_action(dev, flow);
6640 mlx5_ipool_free(priv->flows[type], flow_idx);
6644 * Destroy all flows.
6647 * Pointer to Ethernet device.
6649 * Flow type to be flushed.
6651 * If flushing is called avtively.
6654 mlx5_flow_list_flush(struct rte_eth_dev *dev, enum mlx5_flow_type type,
6657 struct mlx5_priv *priv = dev->data->dev_private;
6658 uint32_t num_flushed = 0, fidx = 1;
6659 struct rte_flow *flow;
6661 MLX5_IPOOL_FOREACH(priv->flows[type], fidx, flow) {
6662 flow_list_destroy(dev, type, fidx);
6666 DRV_LOG(INFO, "port %u: %u flows flushed before stopping",
6667 dev->data->port_id, num_flushed);
6672 * Stop all default actions for flows.
6675 * Pointer to Ethernet device.
6678 mlx5_flow_stop_default(struct rte_eth_dev *dev)
6680 flow_mreg_del_default_copy_action(dev);
6681 flow_rxq_flags_clear(dev);
6685 * Start all default actions for flows.
6688 * Pointer to Ethernet device.
6690 * 0 on success, a negative errno value otherwise and rte_errno is set.
6693 mlx5_flow_start_default(struct rte_eth_dev *dev)
6695 struct rte_flow_error error;
6697 /* Make sure default copy action (reg_c[0] -> reg_b) is created. */
6698 return flow_mreg_add_default_copy_action(dev, &error);
6702 * Release key of thread specific flow workspace data.
6705 flow_release_workspace(void *data)
6707 struct mlx5_flow_workspace *wks = data;
6708 struct mlx5_flow_workspace *next;
6712 free(wks->rss_desc.queue);
6719 * Get thread specific current flow workspace.
6721 * @return pointer to thread specific flow workspace data, NULL on error.
6723 struct mlx5_flow_workspace*
6724 mlx5_flow_get_thread_workspace(void)
6726 struct mlx5_flow_workspace *data;
6728 data = mlx5_flow_os_get_specific_workspace();
6729 MLX5_ASSERT(data && data->inuse);
6730 if (!data || !data->inuse)
6731 DRV_LOG(ERR, "flow workspace not initialized.");
6736 * Allocate and init new flow workspace.
6738 * @return pointer to flow workspace data, NULL on error.
6740 static struct mlx5_flow_workspace*
6741 flow_alloc_thread_workspace(void)
6743 struct mlx5_flow_workspace *data = calloc(1, sizeof(*data));
6746 DRV_LOG(ERR, "Failed to allocate flow workspace "
6750 data->rss_desc.queue = calloc(1,
6751 sizeof(uint16_t) * MLX5_RSSQ_DEFAULT_NUM);
6752 if (!data->rss_desc.queue)
6754 data->rssq_num = MLX5_RSSQ_DEFAULT_NUM;
6757 if (data->rss_desc.queue)
6758 free(data->rss_desc.queue);
6764 * Get new thread specific flow workspace.
6766 * If current workspace inuse, create new one and set as current.
6768 * @return pointer to thread specific flow workspace data, NULL on error.
6770 static struct mlx5_flow_workspace*
6771 mlx5_flow_push_thread_workspace(void)
6773 struct mlx5_flow_workspace *curr;
6774 struct mlx5_flow_workspace *data;
6776 curr = mlx5_flow_os_get_specific_workspace();
6778 data = flow_alloc_thread_workspace();
6781 } else if (!curr->inuse) {
6783 } else if (curr->next) {
6786 data = flow_alloc_thread_workspace();
6794 /* Set as current workspace */
6795 if (mlx5_flow_os_set_specific_workspace(data))
6796 DRV_LOG(ERR, "Failed to set flow workspace to thread.");
6801 * Close current thread specific flow workspace.
6803 * If previous workspace available, set it as current.
6805 * @return pointer to thread specific flow workspace data, NULL on error.
6808 mlx5_flow_pop_thread_workspace(void)
6810 struct mlx5_flow_workspace *data = mlx5_flow_get_thread_workspace();
6815 DRV_LOG(ERR, "Failed to close unused flow workspace.");
6821 if (mlx5_flow_os_set_specific_workspace(data->prev))
6822 DRV_LOG(ERR, "Failed to set flow workspace to thread.");
6826 * Verify the flow list is empty
6829 * Pointer to Ethernet device.
6831 * @return the number of flows not released.
6834 mlx5_flow_verify(struct rte_eth_dev *dev __rte_unused)
6836 struct mlx5_priv *priv = dev->data->dev_private;
6837 struct rte_flow *flow;
6841 for (i = 0; i < MLX5_FLOW_TYPE_MAXI; i++) {
6842 MLX5_IPOOL_FOREACH(priv->flows[i], idx, flow) {
6843 DRV_LOG(DEBUG, "port %u flow %p still referenced",
6844 dev->data->port_id, (void *)flow);
6852 * Enable default hairpin egress flow.
6855 * Pointer to Ethernet device.
6860 * 0 on success, a negative errno value otherwise and rte_errno is set.
6863 mlx5_ctrl_flow_source_queue(struct rte_eth_dev *dev,
6866 const struct rte_flow_attr attr = {
6870 struct mlx5_rte_flow_item_tx_queue queue_spec = {
6873 struct mlx5_rte_flow_item_tx_queue queue_mask = {
6874 .queue = UINT32_MAX,
6876 struct rte_flow_item items[] = {
6878 .type = (enum rte_flow_item_type)
6879 MLX5_RTE_FLOW_ITEM_TYPE_TX_QUEUE,
6880 .spec = &queue_spec,
6882 .mask = &queue_mask,
6885 .type = RTE_FLOW_ITEM_TYPE_END,
6888 struct rte_flow_action_jump jump = {
6889 .group = MLX5_HAIRPIN_TX_TABLE,
6891 struct rte_flow_action actions[2];
6893 struct rte_flow_error error;
6895 actions[0].type = RTE_FLOW_ACTION_TYPE_JUMP;
6896 actions[0].conf = &jump;
6897 actions[1].type = RTE_FLOW_ACTION_TYPE_END;
6898 flow_idx = flow_list_create(dev, MLX5_FLOW_TYPE_CTL,
6899 &attr, items, actions, false, &error);
6902 "Failed to create ctrl flow: rte_errno(%d),"
6903 " type(%d), message(%s)",
6904 rte_errno, error.type,
6905 error.message ? error.message : " (no stated reason)");
6912 * Enable a control flow configured from the control plane.
6915 * Pointer to Ethernet device.
6917 * An Ethernet flow spec to apply.
6919 * An Ethernet flow mask to apply.
6921 * A VLAN flow spec to apply.
6923 * A VLAN flow mask to apply.
6926 * 0 on success, a negative errno value otherwise and rte_errno is set.
6929 mlx5_ctrl_flow_vlan(struct rte_eth_dev *dev,
6930 struct rte_flow_item_eth *eth_spec,
6931 struct rte_flow_item_eth *eth_mask,
6932 struct rte_flow_item_vlan *vlan_spec,
6933 struct rte_flow_item_vlan *vlan_mask)
6935 struct mlx5_priv *priv = dev->data->dev_private;
6936 const struct rte_flow_attr attr = {
6938 .priority = MLX5_FLOW_LOWEST_PRIO_INDICATOR,
6940 struct rte_flow_item items[] = {
6942 .type = RTE_FLOW_ITEM_TYPE_ETH,
6948 .type = (vlan_spec) ? RTE_FLOW_ITEM_TYPE_VLAN :
6949 RTE_FLOW_ITEM_TYPE_END,
6955 .type = RTE_FLOW_ITEM_TYPE_END,
6958 uint16_t queue[priv->reta_idx_n];
6959 struct rte_flow_action_rss action_rss = {
6960 .func = RTE_ETH_HASH_FUNCTION_DEFAULT,
6962 .types = priv->rss_conf.rss_hf,
6963 .key_len = priv->rss_conf.rss_key_len,
6964 .queue_num = priv->reta_idx_n,
6965 .key = priv->rss_conf.rss_key,
6968 struct rte_flow_action actions[] = {
6970 .type = RTE_FLOW_ACTION_TYPE_RSS,
6971 .conf = &action_rss,
6974 .type = RTE_FLOW_ACTION_TYPE_END,
6978 struct rte_flow_error error;
6981 if (!priv->reta_idx_n || !priv->rxqs_n) {
6984 if (!(dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG))
6985 action_rss.types = 0;
6986 for (i = 0; i != priv->reta_idx_n; ++i)
6987 queue[i] = (*priv->reta_idx)[i];
6988 flow_idx = flow_list_create(dev, MLX5_FLOW_TYPE_CTL,
6989 &attr, items, actions, false, &error);
6996 * Enable a flow control configured from the control plane.
6999 * Pointer to Ethernet device.
7001 * An Ethernet flow spec to apply.
7003 * An Ethernet flow mask to apply.
7006 * 0 on success, a negative errno value otherwise and rte_errno is set.
7009 mlx5_ctrl_flow(struct rte_eth_dev *dev,
7010 struct rte_flow_item_eth *eth_spec,
7011 struct rte_flow_item_eth *eth_mask)
7013 return mlx5_ctrl_flow_vlan(dev, eth_spec, eth_mask, NULL, NULL);
7017 * Create default miss flow rule matching lacp traffic
7020 * Pointer to Ethernet device.
7022 * An Ethernet flow spec to apply.
7025 * 0 on success, a negative errno value otherwise and rte_errno is set.
7028 mlx5_flow_lacp_miss(struct rte_eth_dev *dev)
7031 * The LACP matching is done by only using ether type since using
7032 * a multicast dst mac causes kernel to give low priority to this flow.
7034 static const struct rte_flow_item_eth lacp_spec = {
7035 .type = RTE_BE16(0x8809),
7037 static const struct rte_flow_item_eth lacp_mask = {
7040 const struct rte_flow_attr attr = {
7043 struct rte_flow_item items[] = {
7045 .type = RTE_FLOW_ITEM_TYPE_ETH,
7050 .type = RTE_FLOW_ITEM_TYPE_END,
7053 struct rte_flow_action actions[] = {
7055 .type = (enum rte_flow_action_type)
7056 MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS,
7059 .type = RTE_FLOW_ACTION_TYPE_END,
7062 struct rte_flow_error error;
7063 uint32_t flow_idx = flow_list_create(dev, MLX5_FLOW_TYPE_CTL,
7064 &attr, items, actions,
7075 * @see rte_flow_destroy()
7079 mlx5_flow_destroy(struct rte_eth_dev *dev,
7080 struct rte_flow *flow,
7081 struct rte_flow_error *error __rte_unused)
7083 flow_list_destroy(dev, MLX5_FLOW_TYPE_GEN,
7084 (uintptr_t)(void *)flow);
7089 * Destroy all flows.
7091 * @see rte_flow_flush()
7095 mlx5_flow_flush(struct rte_eth_dev *dev,
7096 struct rte_flow_error *error __rte_unused)
7098 mlx5_flow_list_flush(dev, MLX5_FLOW_TYPE_GEN, false);
7105 * @see rte_flow_isolate()
7109 mlx5_flow_isolate(struct rte_eth_dev *dev,
7111 struct rte_flow_error *error)
7113 struct mlx5_priv *priv = dev->data->dev_private;
7115 if (dev->data->dev_started) {
7116 rte_flow_error_set(error, EBUSY,
7117 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7119 "port must be stopped first");
7122 priv->isolated = !!enable;
7124 dev->dev_ops = &mlx5_dev_ops_isolate;
7126 dev->dev_ops = &mlx5_dev_ops;
7128 dev->rx_descriptor_status = mlx5_rx_descriptor_status;
7129 dev->tx_descriptor_status = mlx5_tx_descriptor_status;
7137 * @see rte_flow_query()
7141 flow_drv_query(struct rte_eth_dev *dev,
7143 const struct rte_flow_action *actions,
7145 struct rte_flow_error *error)
7147 struct mlx5_priv *priv = dev->data->dev_private;
7148 const struct mlx5_flow_driver_ops *fops;
7149 struct rte_flow *flow = mlx5_ipool_get(priv->flows[MLX5_FLOW_TYPE_GEN],
7151 enum mlx5_flow_drv_type ftype;
7154 return rte_flow_error_set(error, ENOENT,
7155 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7157 "invalid flow handle");
7159 ftype = flow->drv_type;
7160 MLX5_ASSERT(ftype > MLX5_FLOW_TYPE_MIN && ftype < MLX5_FLOW_TYPE_MAX);
7161 fops = flow_get_drv_ops(ftype);
7163 return fops->query(dev, flow, actions, data, error);
7169 * @see rte_flow_query()
7173 mlx5_flow_query(struct rte_eth_dev *dev,
7174 struct rte_flow *flow,
7175 const struct rte_flow_action *actions,
7177 struct rte_flow_error *error)
7181 ret = flow_drv_query(dev, (uintptr_t)(void *)flow, actions, data,
7189 * Get rte_flow callbacks.
7192 * Pointer to Ethernet device structure.
7194 * Pointer to operation-specific structure.
7199 mlx5_flow_ops_get(struct rte_eth_dev *dev __rte_unused,
7200 const struct rte_flow_ops **ops)
7202 *ops = &mlx5_flow_ops;
7207 * Validate meter policy actions.
7208 * Dispatcher for action type specific validation.
7211 * Pointer to the Ethernet device structure.
7213 * The meter policy action object to validate.
7215 * Attributes of flow to determine steering domain.
7216 * @param[out] is_rss
7218 * @param[out] domain_bitmap
7220 * @param[out] is_def_policy
7221 * Is default policy or not.
7223 * Perform verbose error reporting if not NULL. Initialized in case of
7227 * 0 on success, otherwise negative errno value.
7230 mlx5_flow_validate_mtr_acts(struct rte_eth_dev *dev,
7231 const struct rte_flow_action *actions[RTE_COLORS],
7232 struct rte_flow_attr *attr,
7234 uint8_t *domain_bitmap,
7235 uint8_t *policy_mode,
7236 struct rte_mtr_error *error)
7238 const struct mlx5_flow_driver_ops *fops;
7240 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7241 return fops->validate_mtr_acts(dev, actions, attr, is_rss,
7242 domain_bitmap, policy_mode, error);
7246 * Destroy the meter table set.
7249 * Pointer to Ethernet device.
7250 * @param[in] mtr_policy
7251 * Meter policy struct.
7254 mlx5_flow_destroy_mtr_acts(struct rte_eth_dev *dev,
7255 struct mlx5_flow_meter_policy *mtr_policy)
7257 const struct mlx5_flow_driver_ops *fops;
7259 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7260 fops->destroy_mtr_acts(dev, mtr_policy);
7264 * Create policy action, lock free,
7265 * (mutex should be acquired by caller).
7266 * Dispatcher for action type specific call.
7269 * Pointer to the Ethernet device structure.
7270 * @param[in] mtr_policy
7271 * Meter policy struct.
7273 * Action specification used to create meter actions.
7275 * Perform verbose error reporting if not NULL. Initialized in case of
7279 * 0 on success, otherwise negative errno value.
7282 mlx5_flow_create_mtr_acts(struct rte_eth_dev *dev,
7283 struct mlx5_flow_meter_policy *mtr_policy,
7284 const struct rte_flow_action *actions[RTE_COLORS],
7285 struct rte_mtr_error *error)
7287 const struct mlx5_flow_driver_ops *fops;
7289 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7290 return fops->create_mtr_acts(dev, mtr_policy, actions, error);
7294 * Create policy rules, lock free,
7295 * (mutex should be acquired by caller).
7296 * Dispatcher for action type specific call.
7299 * Pointer to the Ethernet device structure.
7300 * @param[in] mtr_policy
7301 * Meter policy struct.
7304 * 0 on success, -1 otherwise.
7307 mlx5_flow_create_policy_rules(struct rte_eth_dev *dev,
7308 struct mlx5_flow_meter_policy *mtr_policy)
7310 const struct mlx5_flow_driver_ops *fops;
7312 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7313 return fops->create_policy_rules(dev, mtr_policy);
7317 * Destroy policy rules, lock free,
7318 * (mutex should be acquired by caller).
7319 * Dispatcher for action type specific call.
7322 * Pointer to the Ethernet device structure.
7323 * @param[in] mtr_policy
7324 * Meter policy struct.
7327 mlx5_flow_destroy_policy_rules(struct rte_eth_dev *dev,
7328 struct mlx5_flow_meter_policy *mtr_policy)
7330 const struct mlx5_flow_driver_ops *fops;
7332 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7333 fops->destroy_policy_rules(dev, mtr_policy);
7337 * Destroy the default policy table set.
7340 * Pointer to Ethernet device.
7343 mlx5_flow_destroy_def_policy(struct rte_eth_dev *dev)
7345 const struct mlx5_flow_driver_ops *fops;
7347 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7348 fops->destroy_def_policy(dev);
7352 * Destroy the default policy table set.
7355 * Pointer to Ethernet device.
7358 * 0 on success, -1 otherwise.
7361 mlx5_flow_create_def_policy(struct rte_eth_dev *dev)
7363 const struct mlx5_flow_driver_ops *fops;
7365 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7366 return fops->create_def_policy(dev);
7370 * Create the needed meter and suffix tables.
7373 * Pointer to Ethernet device.
7376 * 0 on success, -1 otherwise.
7379 mlx5_flow_create_mtr_tbls(struct rte_eth_dev *dev,
7380 struct mlx5_flow_meter_info *fm,
7382 uint8_t domain_bitmap)
7384 const struct mlx5_flow_driver_ops *fops;
7386 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7387 return fops->create_mtr_tbls(dev, fm, mtr_idx, domain_bitmap);
7391 * Destroy the meter table set.
7394 * Pointer to Ethernet device.
7396 * Pointer to the meter table set.
7399 mlx5_flow_destroy_mtr_tbls(struct rte_eth_dev *dev,
7400 struct mlx5_flow_meter_info *fm)
7402 const struct mlx5_flow_driver_ops *fops;
7404 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7405 fops->destroy_mtr_tbls(dev, fm);
7409 * Destroy the global meter drop table.
7412 * Pointer to Ethernet device.
7415 mlx5_flow_destroy_mtr_drop_tbls(struct rte_eth_dev *dev)
7417 const struct mlx5_flow_driver_ops *fops;
7419 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7420 fops->destroy_mtr_drop_tbls(dev);
7424 * Destroy the sub policy table with RX queue.
7427 * Pointer to Ethernet device.
7428 * @param[in] mtr_policy
7429 * Pointer to meter policy table.
7432 mlx5_flow_destroy_sub_policy_with_rxq(struct rte_eth_dev *dev,
7433 struct mlx5_flow_meter_policy *mtr_policy)
7435 const struct mlx5_flow_driver_ops *fops;
7437 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7438 fops->destroy_sub_policy_with_rxq(dev, mtr_policy);
7442 * Allocate the needed aso flow meter id.
7445 * Pointer to Ethernet device.
7448 * Index to aso flow meter on success, NULL otherwise.
7451 mlx5_flow_mtr_alloc(struct rte_eth_dev *dev)
7453 const struct mlx5_flow_driver_ops *fops;
7455 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7456 return fops->create_meter(dev);
7460 * Free the aso flow meter id.
7463 * Pointer to Ethernet device.
7464 * @param[in] mtr_idx
7465 * Index to aso flow meter to be free.
7471 mlx5_flow_mtr_free(struct rte_eth_dev *dev, uint32_t mtr_idx)
7473 const struct mlx5_flow_driver_ops *fops;
7475 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7476 fops->free_meter(dev, mtr_idx);
7480 * Allocate a counter.
7483 * Pointer to Ethernet device structure.
7486 * Index to allocated counter on success, 0 otherwise.
7489 mlx5_counter_alloc(struct rte_eth_dev *dev)
7491 const struct mlx5_flow_driver_ops *fops;
7492 struct rte_flow_attr attr = { .transfer = 0 };
7494 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
7495 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7496 return fops->counter_alloc(dev);
7499 "port %u counter allocate is not supported.",
7500 dev->data->port_id);
7508 * Pointer to Ethernet device structure.
7510 * Index to counter to be free.
7513 mlx5_counter_free(struct rte_eth_dev *dev, uint32_t cnt)
7515 const struct mlx5_flow_driver_ops *fops;
7516 struct rte_flow_attr attr = { .transfer = 0 };
7518 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
7519 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7520 fops->counter_free(dev, cnt);
7524 "port %u counter free is not supported.",
7525 dev->data->port_id);
7529 * Query counter statistics.
7532 * Pointer to Ethernet device structure.
7534 * Index to counter to query.
7536 * Set to clear counter statistics.
7538 * The counter hits packets number to save.
7540 * The counter hits bytes number to save.
7543 * 0 on success, a negative errno value otherwise.
7546 mlx5_counter_query(struct rte_eth_dev *dev, uint32_t cnt,
7547 bool clear, uint64_t *pkts, uint64_t *bytes)
7549 const struct mlx5_flow_driver_ops *fops;
7550 struct rte_flow_attr attr = { .transfer = 0 };
7552 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
7553 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7554 return fops->counter_query(dev, cnt, clear, pkts, bytes);
7557 "port %u counter query is not supported.",
7558 dev->data->port_id);
7563 * Allocate a new memory for the counter values wrapped by all the needed
7567 * Pointer to mlx5_dev_ctx_shared object.
7570 * 0 on success, a negative errno value otherwise.
7573 mlx5_flow_create_counter_stat_mem_mng(struct mlx5_dev_ctx_shared *sh)
7575 struct mlx5_devx_mkey_attr mkey_attr;
7576 struct mlx5_counter_stats_mem_mng *mem_mng;
7577 volatile struct flow_counter_stats *raw_data;
7578 int raws_n = MLX5_CNT_CONTAINER_RESIZE + MLX5_MAX_PENDING_QUERIES;
7579 int size = (sizeof(struct flow_counter_stats) *
7580 MLX5_COUNTERS_PER_POOL +
7581 sizeof(struct mlx5_counter_stats_raw)) * raws_n +
7582 sizeof(struct mlx5_counter_stats_mem_mng);
7583 size_t pgsize = rte_mem_page_size();
7587 if (pgsize == (size_t)-1) {
7588 DRV_LOG(ERR, "Failed to get mem page size");
7592 mem = mlx5_malloc(MLX5_MEM_ZERO, size, pgsize, SOCKET_ID_ANY);
7597 mem_mng = (struct mlx5_counter_stats_mem_mng *)(mem + size) - 1;
7598 size = sizeof(*raw_data) * MLX5_COUNTERS_PER_POOL * raws_n;
7599 mem_mng->umem = mlx5_os_umem_reg(sh->ctx, mem, size,
7600 IBV_ACCESS_LOCAL_WRITE);
7601 if (!mem_mng->umem) {
7606 memset(&mkey_attr, 0, sizeof(mkey_attr));
7607 mkey_attr.addr = (uintptr_t)mem;
7608 mkey_attr.size = size;
7609 mkey_attr.umem_id = mlx5_os_get_umem_id(mem_mng->umem);
7610 mkey_attr.pd = sh->pdn;
7611 mkey_attr.relaxed_ordering_write = sh->cmng.relaxed_ordering_write;
7612 mkey_attr.relaxed_ordering_read = sh->cmng.relaxed_ordering_read;
7613 mem_mng->dm = mlx5_devx_cmd_mkey_create(sh->ctx, &mkey_attr);
7615 mlx5_os_umem_dereg(mem_mng->umem);
7620 mem_mng->raws = (struct mlx5_counter_stats_raw *)(mem + size);
7621 raw_data = (volatile struct flow_counter_stats *)mem;
7622 for (i = 0; i < raws_n; ++i) {
7623 mem_mng->raws[i].mem_mng = mem_mng;
7624 mem_mng->raws[i].data = raw_data + i * MLX5_COUNTERS_PER_POOL;
7626 for (i = 0; i < MLX5_MAX_PENDING_QUERIES; ++i)
7627 LIST_INSERT_HEAD(&sh->cmng.free_stat_raws,
7628 mem_mng->raws + MLX5_CNT_CONTAINER_RESIZE + i,
7630 LIST_INSERT_HEAD(&sh->cmng.mem_mngs, mem_mng, next);
7631 sh->cmng.mem_mng = mem_mng;
7636 * Set the statistic memory to the new counter pool.
7639 * Pointer to mlx5_dev_ctx_shared object.
7641 * Pointer to the pool to set the statistic memory.
7644 * 0 on success, a negative errno value otherwise.
7647 mlx5_flow_set_counter_stat_mem(struct mlx5_dev_ctx_shared *sh,
7648 struct mlx5_flow_counter_pool *pool)
7650 struct mlx5_flow_counter_mng *cmng = &sh->cmng;
7651 /* Resize statistic memory once used out. */
7652 if (!(pool->index % MLX5_CNT_CONTAINER_RESIZE) &&
7653 mlx5_flow_create_counter_stat_mem_mng(sh)) {
7654 DRV_LOG(ERR, "Cannot resize counter stat mem.");
7657 rte_spinlock_lock(&pool->sl);
7658 pool->raw = cmng->mem_mng->raws + pool->index %
7659 MLX5_CNT_CONTAINER_RESIZE;
7660 rte_spinlock_unlock(&pool->sl);
7661 pool->raw_hw = NULL;
7665 #define MLX5_POOL_QUERY_FREQ_US 1000000
7668 * Set the periodic procedure for triggering asynchronous batch queries for all
7669 * the counter pools.
7672 * Pointer to mlx5_dev_ctx_shared object.
7675 mlx5_set_query_alarm(struct mlx5_dev_ctx_shared *sh)
7677 uint32_t pools_n, us;
7679 pools_n = __atomic_load_n(&sh->cmng.n_valid, __ATOMIC_RELAXED);
7680 us = MLX5_POOL_QUERY_FREQ_US / pools_n;
7681 DRV_LOG(DEBUG, "Set alarm for %u pools each %u us", pools_n, us);
7682 if (rte_eal_alarm_set(us, mlx5_flow_query_alarm, sh)) {
7683 sh->cmng.query_thread_on = 0;
7684 DRV_LOG(ERR, "Cannot reinitialize query alarm");
7686 sh->cmng.query_thread_on = 1;
7691 * The periodic procedure for triggering asynchronous batch queries for all the
7692 * counter pools. This function is probably called by the host thread.
7695 * The parameter for the alarm process.
7698 mlx5_flow_query_alarm(void *arg)
7700 struct mlx5_dev_ctx_shared *sh = arg;
7702 uint16_t pool_index = sh->cmng.pool_index;
7703 struct mlx5_flow_counter_mng *cmng = &sh->cmng;
7704 struct mlx5_flow_counter_pool *pool;
7707 if (sh->cmng.pending_queries >= MLX5_MAX_PENDING_QUERIES)
7709 rte_spinlock_lock(&cmng->pool_update_sl);
7710 pool = cmng->pools[pool_index];
7711 n_valid = cmng->n_valid;
7712 rte_spinlock_unlock(&cmng->pool_update_sl);
7713 /* Set the statistic memory to the new created pool. */
7714 if ((!pool->raw && mlx5_flow_set_counter_stat_mem(sh, pool)))
7717 /* There is a pool query in progress. */
7720 LIST_FIRST(&sh->cmng.free_stat_raws);
7722 /* No free counter statistics raw memory. */
7725 * Identify the counters released between query trigger and query
7726 * handle more efficiently. The counter released in this gap period
7727 * should wait for a new round of query as the new arrived packets
7728 * will not be taken into account.
7731 ret = mlx5_devx_cmd_flow_counter_query(pool->min_dcs, 0,
7732 MLX5_COUNTERS_PER_POOL,
7734 pool->raw_hw->mem_mng->dm->id,
7738 (uint64_t)(uintptr_t)pool);
7740 DRV_LOG(ERR, "Failed to trigger asynchronous query for dcs ID"
7741 " %d", pool->min_dcs->id);
7742 pool->raw_hw = NULL;
7745 LIST_REMOVE(pool->raw_hw, next);
7746 sh->cmng.pending_queries++;
7748 if (pool_index >= n_valid)
7751 sh->cmng.pool_index = pool_index;
7752 mlx5_set_query_alarm(sh);
7756 * Check and callback event for new aged flow in the counter pool
7759 * Pointer to mlx5_dev_ctx_shared object.
7761 * Pointer to Current counter pool.
7764 mlx5_flow_aging_check(struct mlx5_dev_ctx_shared *sh,
7765 struct mlx5_flow_counter_pool *pool)
7767 struct mlx5_priv *priv;
7768 struct mlx5_flow_counter *cnt;
7769 struct mlx5_age_info *age_info;
7770 struct mlx5_age_param *age_param;
7771 struct mlx5_counter_stats_raw *cur = pool->raw_hw;
7772 struct mlx5_counter_stats_raw *prev = pool->raw;
7773 const uint64_t curr_time = MLX5_CURR_TIME_SEC;
7774 const uint32_t time_delta = curr_time - pool->time_of_last_age_check;
7775 uint16_t expected = AGE_CANDIDATE;
7778 pool->time_of_last_age_check = curr_time;
7779 for (i = 0; i < MLX5_COUNTERS_PER_POOL; ++i) {
7780 cnt = MLX5_POOL_GET_CNT(pool, i);
7781 age_param = MLX5_CNT_TO_AGE(cnt);
7782 if (__atomic_load_n(&age_param->state,
7783 __ATOMIC_RELAXED) != AGE_CANDIDATE)
7785 if (cur->data[i].hits != prev->data[i].hits) {
7786 __atomic_store_n(&age_param->sec_since_last_hit, 0,
7790 if (__atomic_add_fetch(&age_param->sec_since_last_hit,
7792 __ATOMIC_RELAXED) <= age_param->timeout)
7795 * Hold the lock first, or if between the
7796 * state AGE_TMOUT and tailq operation the
7797 * release happened, the release procedure
7798 * may delete a non-existent tailq node.
7800 priv = rte_eth_devices[age_param->port_id].data->dev_private;
7801 age_info = GET_PORT_AGE_INFO(priv);
7802 rte_spinlock_lock(&age_info->aged_sl);
7803 if (__atomic_compare_exchange_n(&age_param->state, &expected,
7806 __ATOMIC_RELAXED)) {
7807 TAILQ_INSERT_TAIL(&age_info->aged_counters, cnt, next);
7808 MLX5_AGE_SET(age_info, MLX5_AGE_EVENT_NEW);
7810 rte_spinlock_unlock(&age_info->aged_sl);
7812 mlx5_age_event_prepare(sh);
7816 * Handler for the HW respond about ready values from an asynchronous batch
7817 * query. This function is probably called by the host thread.
7820 * The pointer to the shared device context.
7821 * @param[in] async_id
7822 * The Devx async ID.
7824 * The status of the completion.
7827 mlx5_flow_async_pool_query_handle(struct mlx5_dev_ctx_shared *sh,
7828 uint64_t async_id, int status)
7830 struct mlx5_flow_counter_pool *pool =
7831 (struct mlx5_flow_counter_pool *)(uintptr_t)async_id;
7832 struct mlx5_counter_stats_raw *raw_to_free;
7833 uint8_t query_gen = pool->query_gen ^ 1;
7834 struct mlx5_flow_counter_mng *cmng = &sh->cmng;
7835 enum mlx5_counter_type cnt_type =
7836 pool->is_aged ? MLX5_COUNTER_TYPE_AGE :
7837 MLX5_COUNTER_TYPE_ORIGIN;
7839 if (unlikely(status)) {
7840 raw_to_free = pool->raw_hw;
7842 raw_to_free = pool->raw;
7844 mlx5_flow_aging_check(sh, pool);
7845 rte_spinlock_lock(&pool->sl);
7846 pool->raw = pool->raw_hw;
7847 rte_spinlock_unlock(&pool->sl);
7848 /* Be sure the new raw counters data is updated in memory. */
7850 if (!TAILQ_EMPTY(&pool->counters[query_gen])) {
7851 rte_spinlock_lock(&cmng->csl[cnt_type]);
7852 TAILQ_CONCAT(&cmng->counters[cnt_type],
7853 &pool->counters[query_gen], next);
7854 rte_spinlock_unlock(&cmng->csl[cnt_type]);
7857 LIST_INSERT_HEAD(&sh->cmng.free_stat_raws, raw_to_free, next);
7858 pool->raw_hw = NULL;
7859 sh->cmng.pending_queries--;
7863 flow_group_to_table(uint32_t port_id, uint32_t group, uint32_t *table,
7864 const struct flow_grp_info *grp_info,
7865 struct rte_flow_error *error)
7867 if (grp_info->transfer && grp_info->external &&
7868 grp_info->fdb_def_rule) {
7869 if (group == UINT32_MAX)
7870 return rte_flow_error_set
7872 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
7874 "group index not supported");
7879 DRV_LOG(DEBUG, "port %u group=%#x table=%#x", port_id, group, *table);
7884 * Translate the rte_flow group index to HW table value.
7886 * If tunnel offload is disabled, all group ids converted to flow table
7887 * id using the standard method.
7888 * If tunnel offload is enabled, group id can be converted using the
7889 * standard or tunnel conversion method. Group conversion method
7890 * selection depends on flags in `grp_info` parameter:
7891 * - Internal (grp_info.external == 0) groups conversion uses the
7893 * - Group ids in JUMP action converted with the tunnel conversion.
7894 * - Group id in rule attribute conversion depends on a rule type and
7896 * ** non zero group attributes converted with the tunnel method
7897 * ** zero group attribute in non-tunnel rule is converted using the
7898 * standard method - there's only one root table
7899 * ** zero group attribute in steer tunnel rule is converted with the
7900 * standard method - single root table
7901 * ** zero group attribute in match tunnel rule is a special OvS
7902 * case: that value is used for portability reasons. That group
7903 * id is converted with the tunnel conversion method.
7908 * PMD tunnel offload object
7910 * rte_flow group index value.
7913 * @param[in] grp_info
7914 * flags used for conversion
7916 * Pointer to error structure.
7919 * 0 on success, a negative errno value otherwise and rte_errno is set.
7922 mlx5_flow_group_to_table(struct rte_eth_dev *dev,
7923 const struct mlx5_flow_tunnel *tunnel,
7924 uint32_t group, uint32_t *table,
7925 const struct flow_grp_info *grp_info,
7926 struct rte_flow_error *error)
7929 bool standard_translation;
7931 if (!grp_info->skip_scale && grp_info->external &&
7932 group < MLX5_MAX_TABLES_EXTERNAL)
7933 group *= MLX5_FLOW_TABLE_FACTOR;
7934 if (is_tunnel_offload_active(dev)) {
7935 standard_translation = !grp_info->external ||
7936 grp_info->std_tbl_fix;
7938 standard_translation = true;
7941 "port %u group=%u transfer=%d external=%d fdb_def_rule=%d translate=%s",
7942 dev->data->port_id, group, grp_info->transfer,
7943 grp_info->external, grp_info->fdb_def_rule,
7944 standard_translation ? "STANDARD" : "TUNNEL");
7945 if (standard_translation)
7946 ret = flow_group_to_table(dev->data->port_id, group, table,
7949 ret = tunnel_flow_group_to_flow_table(dev, tunnel, group,
7956 * Discover availability of metadata reg_c's.
7958 * Iteratively use test flows to check availability.
7961 * Pointer to the Ethernet device structure.
7964 * 0 on success, a negative errno value otherwise and rte_errno is set.
7967 mlx5_flow_discover_mreg_c(struct rte_eth_dev *dev)
7969 struct mlx5_priv *priv = dev->data->dev_private;
7970 struct mlx5_dev_config *config = &priv->config;
7971 enum modify_reg idx;
7974 /* reg_c[0] and reg_c[1] are reserved. */
7975 config->flow_mreg_c[n++] = REG_C_0;
7976 config->flow_mreg_c[n++] = REG_C_1;
7977 /* Discover availability of other reg_c's. */
7978 for (idx = REG_C_2; idx <= REG_C_7; ++idx) {
7979 struct rte_flow_attr attr = {
7980 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
7981 .priority = MLX5_FLOW_LOWEST_PRIO_INDICATOR,
7984 struct rte_flow_item items[] = {
7986 .type = RTE_FLOW_ITEM_TYPE_END,
7989 struct rte_flow_action actions[] = {
7991 .type = (enum rte_flow_action_type)
7992 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
7993 .conf = &(struct mlx5_flow_action_copy_mreg){
7999 .type = RTE_FLOW_ACTION_TYPE_JUMP,
8000 .conf = &(struct rte_flow_action_jump){
8001 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
8005 .type = RTE_FLOW_ACTION_TYPE_END,
8009 struct rte_flow *flow;
8010 struct rte_flow_error error;
8012 if (!config->dv_flow_en)
8014 /* Create internal flow, validation skips copy action. */
8015 flow_idx = flow_list_create(dev, MLX5_FLOW_TYPE_GEN, &attr,
8016 items, actions, false, &error);
8017 flow = mlx5_ipool_get(priv->flows[MLX5_FLOW_TYPE_GEN],
8021 config->flow_mreg_c[n++] = idx;
8022 flow_list_destroy(dev, MLX5_FLOW_TYPE_GEN, flow_idx);
8024 for (; n < MLX5_MREG_C_NUM; ++n)
8025 config->flow_mreg_c[n] = REG_NON;
8030 save_dump_file(const uint8_t *data, uint32_t size,
8031 uint32_t type, uint32_t id, void *arg, FILE *file)
8033 char line[BUF_SIZE];
8036 uint32_t actions_num;
8037 struct rte_flow_query_count *count;
8039 memset(line, 0, BUF_SIZE);
8041 case DR_DUMP_REC_TYPE_PMD_MODIFY_HDR:
8042 actions_num = *(uint32_t *)(arg);
8043 out += snprintf(line + out, BUF_SIZE - out, "%d,0x%x,%d,",
8044 type, id, actions_num);
8046 case DR_DUMP_REC_TYPE_PMD_PKT_REFORMAT:
8047 out += snprintf(line + out, BUF_SIZE - out, "%d,0x%x,",
8050 case DR_DUMP_REC_TYPE_PMD_COUNTER:
8051 count = (struct rte_flow_query_count *)arg;
8052 fprintf(file, "%d,0x%x,%" PRIu64 ",%" PRIu64 "\n", type,
8053 id, count->hits, count->bytes);
8059 for (k = 0; k < size; k++) {
8060 /* Make sure we do not overrun the line buffer length. */
8061 if (out >= BUF_SIZE - 4) {
8065 out += snprintf(line + out, BUF_SIZE - out, "%02x",
8068 fprintf(file, "%s\n", line);
8073 mlx5_flow_query_counter(struct rte_eth_dev *dev, struct rte_flow *flow,
8074 struct rte_flow_query_count *count, struct rte_flow_error *error)
8076 struct rte_flow_action action[2];
8077 enum mlx5_flow_drv_type ftype;
8078 const struct mlx5_flow_driver_ops *fops;
8081 return rte_flow_error_set(error, ENOENT,
8082 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8084 "invalid flow handle");
8086 action[0].type = RTE_FLOW_ACTION_TYPE_COUNT;
8087 action[1].type = RTE_FLOW_ACTION_TYPE_END;
8088 if (flow->counter) {
8089 memset(count, 0, sizeof(struct rte_flow_query_count));
8090 ftype = (enum mlx5_flow_drv_type)(flow->drv_type);
8091 MLX5_ASSERT(ftype > MLX5_FLOW_TYPE_MIN &&
8092 ftype < MLX5_FLOW_TYPE_MAX);
8093 fops = flow_get_drv_ops(ftype);
8094 return fops->query(dev, flow, action, count, error);
8099 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
8101 * Dump flow ipool data to file
8104 * The pointer to Ethernet device.
8106 * A pointer to a file for output.
8108 * Perform verbose error reporting if not NULL. PMDs initialize this
8109 * structure in case of error only.
8111 * 0 on success, a negative value otherwise.
8114 mlx5_flow_dev_dump_ipool(struct rte_eth_dev *dev,
8115 struct rte_flow *flow, FILE *file,
8116 struct rte_flow_error *error)
8118 struct mlx5_priv *priv = dev->data->dev_private;
8119 struct mlx5_flow_dv_modify_hdr_resource *modify_hdr;
8120 struct mlx5_flow_dv_encap_decap_resource *encap_decap;
8121 uint32_t handle_idx;
8122 struct mlx5_flow_handle *dh;
8123 struct rte_flow_query_count count;
8124 uint32_t actions_num;
8125 const uint8_t *data;
8131 return rte_flow_error_set(error, ENOENT,
8132 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8134 "invalid flow handle");
8136 handle_idx = flow->dev_handles;
8137 while (handle_idx) {
8138 dh = mlx5_ipool_get(priv->sh->ipool
8139 [MLX5_IPOOL_MLX5_FLOW], handle_idx);
8142 handle_idx = dh->next.next;
8143 id = (uint32_t)(uintptr_t)dh->drv_flow;
8146 type = DR_DUMP_REC_TYPE_PMD_COUNTER;
8147 if (!mlx5_flow_query_counter(dev, flow, &count, error))
8148 save_dump_file(NULL, 0, type,
8149 id, (void *)&count, file);
8151 /* Get modify_hdr and encap_decap buf from ipools. */
8153 modify_hdr = dh->dvh.modify_hdr;
8155 if (dh->dvh.rix_encap_decap) {
8156 encap_decap = mlx5_ipool_get(priv->sh->ipool
8157 [MLX5_IPOOL_DECAP_ENCAP],
8158 dh->dvh.rix_encap_decap);
8161 data = (const uint8_t *)modify_hdr->actions;
8162 size = (size_t)(modify_hdr->actions_num) * 8;
8163 actions_num = modify_hdr->actions_num;
8164 type = DR_DUMP_REC_TYPE_PMD_MODIFY_HDR;
8165 save_dump_file(data, size, type, id,
8166 (void *)(&actions_num), file);
8169 data = encap_decap->buf;
8170 size = encap_decap->size;
8171 type = DR_DUMP_REC_TYPE_PMD_PKT_REFORMAT;
8172 save_dump_file(data, size, type,
8181 * Dump flow raw hw data to file
8184 * The pointer to Ethernet device.
8186 * A pointer to a file for output.
8188 * Perform verbose error reporting if not NULL. PMDs initialize this
8189 * structure in case of error only.
8191 * 0 on success, a nagative value otherwise.
8194 mlx5_flow_dev_dump(struct rte_eth_dev *dev, struct rte_flow *flow_idx,
8196 struct rte_flow_error *error __rte_unused)
8198 struct mlx5_priv *priv = dev->data->dev_private;
8199 struct mlx5_dev_ctx_shared *sh = priv->sh;
8200 uint32_t handle_idx;
8202 struct mlx5_flow_handle *dh;
8203 struct rte_flow *flow;
8204 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
8208 if (!priv->config.dv_flow_en) {
8209 if (fputs("device dv flow disabled\n", file) <= 0)
8216 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
8217 MLX5_IPOOL_FOREACH(priv->flows[MLX5_FLOW_TYPE_GEN], idx, flow)
8218 mlx5_flow_dev_dump_ipool(dev, flow, file, error);
8220 return mlx5_devx_cmd_flow_dump(sh->fdb_domain,
8222 sh->tx_domain, file);
8225 flow = mlx5_ipool_get(priv->flows[MLX5_FLOW_TYPE_GEN],
8226 (uintptr_t)(void *)flow_idx);
8230 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
8231 mlx5_flow_dev_dump_ipool(dev, flow, file, error);
8233 handle_idx = flow->dev_handles;
8234 while (handle_idx) {
8235 dh = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
8240 ret = mlx5_devx_cmd_flow_single_dump(dh->drv_flow,
8245 handle_idx = dh->next.next;
8251 * Get aged-out flows.
8254 * Pointer to the Ethernet device structure.
8255 * @param[in] context
8256 * The address of an array of pointers to the aged-out flows contexts.
8257 * @param[in] nb_countexts
8258 * The length of context array pointers.
8260 * Perform verbose error reporting if not NULL. Initialized in case of
8264 * how many contexts get in success, otherwise negative errno value.
8265 * if nb_contexts is 0, return the amount of all aged contexts.
8266 * if nb_contexts is not 0 , return the amount of aged flows reported
8267 * in the context array.
8270 mlx5_flow_get_aged_flows(struct rte_eth_dev *dev, void **contexts,
8271 uint32_t nb_contexts, struct rte_flow_error *error)
8273 const struct mlx5_flow_driver_ops *fops;
8274 struct rte_flow_attr attr = { .transfer = 0 };
8276 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
8277 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
8278 return fops->get_aged_flows(dev, contexts, nb_contexts,
8282 "port %u get aged flows is not supported.",
8283 dev->data->port_id);
8287 /* Wrapper for driver action_validate op callback */
8289 flow_drv_action_validate(struct rte_eth_dev *dev,
8290 const struct rte_flow_indir_action_conf *conf,
8291 const struct rte_flow_action *action,
8292 const struct mlx5_flow_driver_ops *fops,
8293 struct rte_flow_error *error)
8295 static const char err_msg[] = "indirect action validation unsupported";
8297 if (!fops->action_validate) {
8298 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
8299 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
8303 return fops->action_validate(dev, conf, action, error);
8307 * Destroys the shared action by handle.
8310 * Pointer to Ethernet device structure.
8312 * Handle for the indirect action object to be destroyed.
8314 * Perform verbose error reporting if not NULL. PMDs initialize this
8315 * structure in case of error only.
8318 * 0 on success, a negative errno value otherwise and rte_errno is set.
8320 * @note: wrapper for driver action_create op callback.
8323 mlx5_action_handle_destroy(struct rte_eth_dev *dev,
8324 struct rte_flow_action_handle *handle,
8325 struct rte_flow_error *error)
8327 static const char err_msg[] = "indirect action destruction unsupported";
8328 struct rte_flow_attr attr = { .transfer = 0 };
8329 const struct mlx5_flow_driver_ops *fops =
8330 flow_get_drv_ops(flow_get_drv_type(dev, &attr));
8332 if (!fops->action_destroy) {
8333 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
8334 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
8338 return fops->action_destroy(dev, handle, error);
8341 /* Wrapper for driver action_destroy op callback */
8343 flow_drv_action_update(struct rte_eth_dev *dev,
8344 struct rte_flow_action_handle *handle,
8346 const struct mlx5_flow_driver_ops *fops,
8347 struct rte_flow_error *error)
8349 static const char err_msg[] = "indirect action update unsupported";
8351 if (!fops->action_update) {
8352 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
8353 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
8357 return fops->action_update(dev, handle, update, error);
8360 /* Wrapper for driver action_destroy op callback */
8362 flow_drv_action_query(struct rte_eth_dev *dev,
8363 const struct rte_flow_action_handle *handle,
8365 const struct mlx5_flow_driver_ops *fops,
8366 struct rte_flow_error *error)
8368 static const char err_msg[] = "indirect action query unsupported";
8370 if (!fops->action_query) {
8371 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
8372 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
8376 return fops->action_query(dev, handle, data, error);
8380 * Create indirect action for reuse in multiple flow rules.
8383 * Pointer to Ethernet device structure.
8385 * Pointer to indirect action object configuration.
8387 * Action configuration for indirect action object creation.
8389 * Perform verbose error reporting if not NULL. PMDs initialize this
8390 * structure in case of error only.
8392 * A valid handle in case of success, NULL otherwise and rte_errno is set.
8394 static struct rte_flow_action_handle *
8395 mlx5_action_handle_create(struct rte_eth_dev *dev,
8396 const struct rte_flow_indir_action_conf *conf,
8397 const struct rte_flow_action *action,
8398 struct rte_flow_error *error)
8400 static const char err_msg[] = "indirect action creation unsupported";
8401 struct rte_flow_attr attr = { .transfer = 0 };
8402 const struct mlx5_flow_driver_ops *fops =
8403 flow_get_drv_ops(flow_get_drv_type(dev, &attr));
8405 if (flow_drv_action_validate(dev, conf, action, fops, error))
8407 if (!fops->action_create) {
8408 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
8409 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
8413 return fops->action_create(dev, conf, action, error);
8417 * Updates inplace the indirect action configuration pointed by *handle*
8418 * with the configuration provided as *update* argument.
8419 * The update of the indirect action configuration effects all flow rules
8420 * reusing the action via handle.
8423 * Pointer to Ethernet device structure.
8425 * Handle for the indirect action to be updated.
8427 * Action specification used to modify the action pointed by handle.
8428 * *update* could be of same type with the action pointed by the *handle*
8429 * handle argument, or some other structures like a wrapper, depending on
8430 * the indirect action type.
8432 * Perform verbose error reporting if not NULL. PMDs initialize this
8433 * structure in case of error only.
8436 * 0 on success, a negative errno value otherwise and rte_errno is set.
8439 mlx5_action_handle_update(struct rte_eth_dev *dev,
8440 struct rte_flow_action_handle *handle,
8442 struct rte_flow_error *error)
8444 struct rte_flow_attr attr = { .transfer = 0 };
8445 const struct mlx5_flow_driver_ops *fops =
8446 flow_get_drv_ops(flow_get_drv_type(dev, &attr));
8449 ret = flow_drv_action_validate(dev, NULL,
8450 (const struct rte_flow_action *)update, fops, error);
8453 return flow_drv_action_update(dev, handle, update, fops,
8458 * Query the indirect action by handle.
8460 * This function allows retrieving action-specific data such as counters.
8461 * Data is gathered by special action which may be present/referenced in
8462 * more than one flow rule definition.
8464 * see @RTE_FLOW_ACTION_TYPE_COUNT
8467 * Pointer to Ethernet device structure.
8469 * Handle for the indirect action to query.
8470 * @param[in, out] data
8471 * Pointer to storage for the associated query data type.
8473 * Perform verbose error reporting if not NULL. PMDs initialize this
8474 * structure in case of error only.
8477 * 0 on success, a negative errno value otherwise and rte_errno is set.
8480 mlx5_action_handle_query(struct rte_eth_dev *dev,
8481 const struct rte_flow_action_handle *handle,
8483 struct rte_flow_error *error)
8485 struct rte_flow_attr attr = { .transfer = 0 };
8486 const struct mlx5_flow_driver_ops *fops =
8487 flow_get_drv_ops(flow_get_drv_type(dev, &attr));
8489 return flow_drv_action_query(dev, handle, data, fops, error);
8493 * Destroy all indirect actions (shared RSS).
8496 * Pointer to Ethernet device.
8499 * 0 on success, a negative errno value otherwise and rte_errno is set.
8502 mlx5_action_handle_flush(struct rte_eth_dev *dev)
8504 struct rte_flow_error error;
8505 struct mlx5_priv *priv = dev->data->dev_private;
8506 struct mlx5_shared_action_rss *shared_rss;
8510 ILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
8511 priv->rss_shared_actions, idx, shared_rss, next) {
8512 ret |= mlx5_action_handle_destroy(dev,
8513 (struct rte_flow_action_handle *)(uintptr_t)idx, &error);
8518 #ifndef HAVE_MLX5DV_DR
8519 #define MLX5_DOMAIN_SYNC_FLOW ((1 << 0) | (1 << 1))
8521 #define MLX5_DOMAIN_SYNC_FLOW \
8522 (MLX5DV_DR_DOMAIN_SYNC_FLAGS_SW | MLX5DV_DR_DOMAIN_SYNC_FLAGS_HW)
8525 int rte_pmd_mlx5_sync_flow(uint16_t port_id, uint32_t domains)
8527 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
8528 const struct mlx5_flow_driver_ops *fops;
8530 struct rte_flow_attr attr = { .transfer = 0 };
8532 fops = flow_get_drv_ops(flow_get_drv_type(dev, &attr));
8533 ret = fops->sync_domain(dev, domains, MLX5_DOMAIN_SYNC_FLOW);
8539 const struct mlx5_flow_tunnel *
8540 mlx5_get_tof(const struct rte_flow_item *item,
8541 const struct rte_flow_action *action,
8542 enum mlx5_tof_rule_type *rule_type)
8544 for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
8545 if (item->type == (typeof(item->type))
8546 MLX5_RTE_FLOW_ITEM_TYPE_TUNNEL) {
8547 *rule_type = MLX5_TUNNEL_OFFLOAD_MATCH_RULE;
8548 return flow_items_to_tunnel(item);
8551 for (; action->conf != RTE_FLOW_ACTION_TYPE_END; action++) {
8552 if (action->type == (typeof(action->type))
8553 MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET) {
8554 *rule_type = MLX5_TUNNEL_OFFLOAD_SET_RULE;
8555 return flow_actions_to_tunnel(action);
8562 * tunnel offload functionalilty is defined for DV environment only
8564 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
8566 union tunnel_offload_mark {
8569 uint32_t app_reserve:8;
8570 uint32_t table_id:15;
8571 uint32_t transfer:1;
8572 uint32_t _unused_:8;
8577 mlx5_access_tunnel_offload_db
8578 (struct rte_eth_dev *dev,
8579 bool (*match)(struct rte_eth_dev *,
8580 struct mlx5_flow_tunnel *, const void *),
8581 void (*hit)(struct rte_eth_dev *, struct mlx5_flow_tunnel *, void *),
8582 void (*miss)(struct rte_eth_dev *, void *),
8583 void *ctx, bool lock_op);
8586 flow_tunnel_add_default_miss(struct rte_eth_dev *dev,
8587 struct rte_flow *flow,
8588 const struct rte_flow_attr *attr,
8589 const struct rte_flow_action *app_actions,
8591 const struct mlx5_flow_tunnel *tunnel,
8592 struct tunnel_default_miss_ctx *ctx,
8593 struct rte_flow_error *error)
8595 struct mlx5_priv *priv = dev->data->dev_private;
8596 struct mlx5_flow *dev_flow;
8597 struct rte_flow_attr miss_attr = *attr;
8598 const struct rte_flow_item miss_items[2] = {
8600 .type = RTE_FLOW_ITEM_TYPE_ETH,
8606 .type = RTE_FLOW_ITEM_TYPE_END,
8612 union tunnel_offload_mark mark_id;
8613 struct rte_flow_action_mark miss_mark;
8614 struct rte_flow_action miss_actions[3] = {
8615 [0] = { .type = RTE_FLOW_ACTION_TYPE_MARK, .conf = &miss_mark },
8616 [2] = { .type = RTE_FLOW_ACTION_TYPE_END, .conf = NULL }
8618 const struct rte_flow_action_jump *jump_data;
8619 uint32_t i, flow_table = 0; /* prevent compilation warning */
8620 struct flow_grp_info grp_info = {
8622 .transfer = attr->transfer,
8623 .fdb_def_rule = !!priv->fdb_def_rule,
8628 if (!attr->transfer) {
8631 miss_actions[1].type = RTE_FLOW_ACTION_TYPE_RSS;
8632 q_size = priv->reta_idx_n * sizeof(ctx->queue[0]);
8633 ctx->queue = mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO, q_size,
8636 return rte_flow_error_set
8638 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
8639 NULL, "invalid default miss RSS");
8640 ctx->action_rss.func = RTE_ETH_HASH_FUNCTION_DEFAULT,
8641 ctx->action_rss.level = 0,
8642 ctx->action_rss.types = priv->rss_conf.rss_hf,
8643 ctx->action_rss.key_len = priv->rss_conf.rss_key_len,
8644 ctx->action_rss.queue_num = priv->reta_idx_n,
8645 ctx->action_rss.key = priv->rss_conf.rss_key,
8646 ctx->action_rss.queue = ctx->queue;
8647 if (!priv->reta_idx_n || !priv->rxqs_n)
8648 return rte_flow_error_set
8650 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
8651 NULL, "invalid port configuration");
8652 if (!(dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG))
8653 ctx->action_rss.types = 0;
8654 for (i = 0; i != priv->reta_idx_n; ++i)
8655 ctx->queue[i] = (*priv->reta_idx)[i];
8657 miss_actions[1].type = RTE_FLOW_ACTION_TYPE_JUMP;
8658 ctx->miss_jump.group = MLX5_TNL_MISS_FDB_JUMP_GRP;
8660 miss_actions[1].conf = (typeof(miss_actions[1].conf))ctx->raw;
8661 for (; app_actions->type != RTE_FLOW_ACTION_TYPE_JUMP; app_actions++);
8662 jump_data = app_actions->conf;
8663 miss_attr.priority = MLX5_TNL_MISS_RULE_PRIORITY;
8664 miss_attr.group = jump_data->group;
8665 ret = mlx5_flow_group_to_table(dev, tunnel, jump_data->group,
8666 &flow_table, &grp_info, error);
8668 return rte_flow_error_set(error, EINVAL,
8669 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
8670 NULL, "invalid tunnel id");
8671 mark_id.app_reserve = 0;
8672 mark_id.table_id = tunnel_flow_tbl_to_id(flow_table);
8673 mark_id.transfer = !!attr->transfer;
8674 mark_id._unused_ = 0;
8675 miss_mark.id = mark_id.val;
8676 dev_flow = flow_drv_prepare(dev, flow, &miss_attr,
8677 miss_items, miss_actions, flow_idx, error);
8680 dev_flow->flow = flow;
8681 dev_flow->external = true;
8682 dev_flow->tunnel = tunnel;
8683 dev_flow->tof_type = MLX5_TUNNEL_OFFLOAD_MISS_RULE;
8684 /* Subflow object was created, we must include one in the list. */
8685 SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
8686 dev_flow->handle, next);
8688 "port %u tunnel type=%d id=%u miss rule priority=%u group=%u",
8689 dev->data->port_id, tunnel->app_tunnel.type,
8690 tunnel->tunnel_id, miss_attr.priority, miss_attr.group);
8691 ret = flow_drv_translate(dev, dev_flow, &miss_attr, miss_items,
8692 miss_actions, error);
8694 ret = flow_mreg_update_copy_table(dev, flow, miss_actions,
8700 static const struct mlx5_flow_tbl_data_entry *
8701 tunnel_mark_decode(struct rte_eth_dev *dev, uint32_t mark)
8703 struct mlx5_priv *priv = dev->data->dev_private;
8704 struct mlx5_dev_ctx_shared *sh = priv->sh;
8705 struct mlx5_list_entry *he;
8706 union tunnel_offload_mark mbits = { .val = mark };
8707 union mlx5_flow_tbl_key table_key = {
8709 .level = tunnel_id_to_flow_tbl(mbits.table_id),
8713 .is_fdb = !!mbits.transfer,
8717 struct mlx5_flow_cb_ctx ctx = {
8718 .data = &table_key.v64,
8721 he = mlx5_hlist_lookup(sh->flow_tbls, table_key.v64, &ctx);
8723 container_of(he, struct mlx5_flow_tbl_data_entry, entry) : NULL;
8727 mlx5_flow_tunnel_grp2tbl_remove_cb(void *tool_ctx,
8728 struct mlx5_list_entry *entry)
8730 struct mlx5_dev_ctx_shared *sh = tool_ctx;
8731 struct tunnel_tbl_entry *tte = container_of(entry, typeof(*tte), hash);
8733 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TNL_TBL_ID],
8734 tunnel_flow_tbl_to_id(tte->flow_table));
8739 mlx5_flow_tunnel_grp2tbl_match_cb(void *tool_ctx __rte_unused,
8740 struct mlx5_list_entry *entry, void *cb_ctx)
8742 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
8743 union tunnel_tbl_key tbl = {
8744 .val = *(uint64_t *)(ctx->data),
8746 struct tunnel_tbl_entry *tte = container_of(entry, typeof(*tte), hash);
8748 return tbl.tunnel_id != tte->tunnel_id || tbl.group != tte->group;
8751 static struct mlx5_list_entry *
8752 mlx5_flow_tunnel_grp2tbl_create_cb(void *tool_ctx, void *cb_ctx)
8754 struct mlx5_dev_ctx_shared *sh = tool_ctx;
8755 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
8756 struct tunnel_tbl_entry *tte;
8757 union tunnel_tbl_key tbl = {
8758 .val = *(uint64_t *)(ctx->data),
8761 tte = mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO,
8766 mlx5_ipool_malloc(sh->ipool[MLX5_IPOOL_TNL_TBL_ID],
8768 if (tte->flow_table >= MLX5_MAX_TABLES) {
8769 DRV_LOG(ERR, "Tunnel TBL ID %d exceed max limit.",
8771 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TNL_TBL_ID],
8774 } else if (!tte->flow_table) {
8777 tte->flow_table = tunnel_id_to_flow_tbl(tte->flow_table);
8778 tte->tunnel_id = tbl.tunnel_id;
8779 tte->group = tbl.group;
8787 static struct mlx5_list_entry *
8788 mlx5_flow_tunnel_grp2tbl_clone_cb(void *tool_ctx __rte_unused,
8789 struct mlx5_list_entry *oentry,
8790 void *cb_ctx __rte_unused)
8792 struct tunnel_tbl_entry *tte = mlx5_malloc(MLX5_MEM_SYS, sizeof(*tte),
8797 memcpy(tte, oentry, sizeof(*tte));
8802 mlx5_flow_tunnel_grp2tbl_clone_free_cb(void *tool_ctx __rte_unused,
8803 struct mlx5_list_entry *entry)
8805 struct tunnel_tbl_entry *tte = container_of(entry, typeof(*tte), hash);
8811 tunnel_flow_group_to_flow_table(struct rte_eth_dev *dev,
8812 const struct mlx5_flow_tunnel *tunnel,
8813 uint32_t group, uint32_t *table,
8814 struct rte_flow_error *error)
8816 struct mlx5_list_entry *he;
8817 struct tunnel_tbl_entry *tte;
8818 union tunnel_tbl_key key = {
8819 .tunnel_id = tunnel ? tunnel->tunnel_id : 0,
8822 struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
8823 struct mlx5_hlist *group_hash;
8824 struct mlx5_flow_cb_ctx ctx = {
8828 group_hash = tunnel ? tunnel->groups : thub->groups;
8829 he = mlx5_hlist_register(group_hash, key.val, &ctx);
8831 return rte_flow_error_set(error, EINVAL,
8832 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
8834 "tunnel group index not supported");
8835 tte = container_of(he, typeof(*tte), hash);
8836 *table = tte->flow_table;
8837 DRV_LOG(DEBUG, "port %u tunnel %u group=%#x table=%#x",
8838 dev->data->port_id, key.tunnel_id, group, *table);
8843 mlx5_flow_tunnel_free(struct rte_eth_dev *dev,
8844 struct mlx5_flow_tunnel *tunnel)
8846 struct mlx5_priv *priv = dev->data->dev_private;
8847 struct mlx5_indexed_pool *ipool;
8849 DRV_LOG(DEBUG, "port %u release pmd tunnel id=0x%x",
8850 dev->data->port_id, tunnel->tunnel_id);
8851 LIST_REMOVE(tunnel, chain);
8852 mlx5_hlist_destroy(tunnel->groups);
8853 ipool = priv->sh->ipool[MLX5_IPOOL_TUNNEL_ID];
8854 mlx5_ipool_free(ipool, tunnel->tunnel_id);
8858 mlx5_access_tunnel_offload_db
8859 (struct rte_eth_dev *dev,
8860 bool (*match)(struct rte_eth_dev *,
8861 struct mlx5_flow_tunnel *, const void *),
8862 void (*hit)(struct rte_eth_dev *, struct mlx5_flow_tunnel *, void *),
8863 void (*miss)(struct rte_eth_dev *, void *),
8864 void *ctx, bool lock_op)
8866 bool verdict = false;
8867 struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
8868 struct mlx5_flow_tunnel *tunnel;
8870 rte_spinlock_lock(&thub->sl);
8871 LIST_FOREACH(tunnel, &thub->tunnels, chain) {
8872 verdict = match(dev, tunnel, (const void *)ctx);
8877 rte_spinlock_unlock(&thub->sl);
8879 hit(dev, tunnel, ctx);
8880 if (!verdict && miss)
8883 rte_spinlock_unlock(&thub->sl);
8888 struct tunnel_db_find_tunnel_id_ctx {
8890 struct mlx5_flow_tunnel *tunnel;
8894 find_tunnel_id_match(struct rte_eth_dev *dev,
8895 struct mlx5_flow_tunnel *tunnel, const void *x)
8897 const struct tunnel_db_find_tunnel_id_ctx *ctx = x;
8900 return tunnel->tunnel_id == ctx->tunnel_id;
8904 find_tunnel_id_hit(struct rte_eth_dev *dev,
8905 struct mlx5_flow_tunnel *tunnel, void *x)
8907 struct tunnel_db_find_tunnel_id_ctx *ctx = x;
8909 ctx->tunnel = tunnel;
8912 static struct mlx5_flow_tunnel *
8913 mlx5_find_tunnel_id(struct rte_eth_dev *dev, uint32_t id)
8915 struct tunnel_db_find_tunnel_id_ctx ctx = {
8919 mlx5_access_tunnel_offload_db(dev, find_tunnel_id_match,
8920 find_tunnel_id_hit, NULL, &ctx, true);
8925 static struct mlx5_flow_tunnel *
8926 mlx5_flow_tunnel_allocate(struct rte_eth_dev *dev,
8927 const struct rte_flow_tunnel *app_tunnel)
8929 struct mlx5_priv *priv = dev->data->dev_private;
8930 struct mlx5_indexed_pool *ipool;
8931 struct mlx5_flow_tunnel *tunnel;
8934 ipool = priv->sh->ipool[MLX5_IPOOL_TUNNEL_ID];
8935 tunnel = mlx5_ipool_zmalloc(ipool, &id);
8938 if (id >= MLX5_MAX_TUNNELS) {
8939 mlx5_ipool_free(ipool, id);
8940 DRV_LOG(ERR, "Tunnel ID %d exceed max limit.", id);
8943 tunnel->groups = mlx5_hlist_create("tunnel groups", 64, false, true,
8945 mlx5_flow_tunnel_grp2tbl_create_cb,
8946 mlx5_flow_tunnel_grp2tbl_match_cb,
8947 mlx5_flow_tunnel_grp2tbl_remove_cb,
8948 mlx5_flow_tunnel_grp2tbl_clone_cb,
8949 mlx5_flow_tunnel_grp2tbl_clone_free_cb);
8950 if (!tunnel->groups) {
8951 mlx5_ipool_free(ipool, id);
8954 /* initiate new PMD tunnel */
8955 memcpy(&tunnel->app_tunnel, app_tunnel, sizeof(*app_tunnel));
8956 tunnel->tunnel_id = id;
8957 tunnel->action.type = (typeof(tunnel->action.type))
8958 MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET;
8959 tunnel->action.conf = tunnel;
8960 tunnel->item.type = (typeof(tunnel->item.type))
8961 MLX5_RTE_FLOW_ITEM_TYPE_TUNNEL;
8962 tunnel->item.spec = tunnel;
8963 tunnel->item.last = NULL;
8964 tunnel->item.mask = NULL;
8966 DRV_LOG(DEBUG, "port %u new pmd tunnel id=0x%x",
8967 dev->data->port_id, tunnel->tunnel_id);
8972 struct tunnel_db_get_tunnel_ctx {
8973 const struct rte_flow_tunnel *app_tunnel;
8974 struct mlx5_flow_tunnel *tunnel;
8977 static bool get_tunnel_match(struct rte_eth_dev *dev,
8978 struct mlx5_flow_tunnel *tunnel, const void *x)
8980 const struct tunnel_db_get_tunnel_ctx *ctx = x;
8983 return !memcmp(ctx->app_tunnel, &tunnel->app_tunnel,
8984 sizeof(*ctx->app_tunnel));
8987 static void get_tunnel_hit(struct rte_eth_dev *dev,
8988 struct mlx5_flow_tunnel *tunnel, void *x)
8990 /* called under tunnel spinlock protection */
8991 struct tunnel_db_get_tunnel_ctx *ctx = x;
8995 ctx->tunnel = tunnel;
8998 static void get_tunnel_miss(struct rte_eth_dev *dev, void *x)
9000 /* called under tunnel spinlock protection */
9001 struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
9002 struct tunnel_db_get_tunnel_ctx *ctx = x;
9004 rte_spinlock_unlock(&thub->sl);
9005 ctx->tunnel = mlx5_flow_tunnel_allocate(dev, ctx->app_tunnel);
9006 rte_spinlock_lock(&thub->sl);
9008 ctx->tunnel->refctn = 1;
9009 LIST_INSERT_HEAD(&thub->tunnels, ctx->tunnel, chain);
9015 mlx5_get_flow_tunnel(struct rte_eth_dev *dev,
9016 const struct rte_flow_tunnel *app_tunnel,
9017 struct mlx5_flow_tunnel **tunnel)
9019 struct tunnel_db_get_tunnel_ctx ctx = {
9020 .app_tunnel = app_tunnel,
9023 mlx5_access_tunnel_offload_db(dev, get_tunnel_match, get_tunnel_hit,
9024 get_tunnel_miss, &ctx, true);
9025 *tunnel = ctx.tunnel;
9026 return ctx.tunnel ? 0 : -ENOMEM;
9029 void mlx5_release_tunnel_hub(struct mlx5_dev_ctx_shared *sh, uint16_t port_id)
9031 struct mlx5_flow_tunnel_hub *thub = sh->tunnel_hub;
9035 if (!LIST_EMPTY(&thub->tunnels))
9036 DRV_LOG(WARNING, "port %u tunnels present", port_id);
9037 mlx5_hlist_destroy(thub->groups);
9041 int mlx5_alloc_tunnel_hub(struct mlx5_dev_ctx_shared *sh)
9044 struct mlx5_flow_tunnel_hub *thub;
9046 thub = mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO, sizeof(*thub),
9050 LIST_INIT(&thub->tunnels);
9051 rte_spinlock_init(&thub->sl);
9052 thub->groups = mlx5_hlist_create("flow groups", 64,
9054 mlx5_flow_tunnel_grp2tbl_create_cb,
9055 mlx5_flow_tunnel_grp2tbl_match_cb,
9056 mlx5_flow_tunnel_grp2tbl_remove_cb,
9057 mlx5_flow_tunnel_grp2tbl_clone_cb,
9058 mlx5_flow_tunnel_grp2tbl_clone_free_cb);
9059 if (!thub->groups) {
9063 sh->tunnel_hub = thub;
9069 mlx5_hlist_destroy(thub->groups);
9076 mlx5_flow_tunnel_validate(struct rte_eth_dev *dev,
9077 struct rte_flow_tunnel *tunnel,
9078 const char *err_msg)
9081 if (!is_tunnel_offload_active(dev)) {
9082 err_msg = "tunnel offload was not activated";
9084 } else if (!tunnel) {
9085 err_msg = "no application tunnel";
9089 switch (tunnel->type) {
9091 err_msg = "unsupported tunnel type";
9093 case RTE_FLOW_ITEM_TYPE_VXLAN:
9102 mlx5_flow_tunnel_decap_set(struct rte_eth_dev *dev,
9103 struct rte_flow_tunnel *app_tunnel,
9104 struct rte_flow_action **actions,
9105 uint32_t *num_of_actions,
9106 struct rte_flow_error *error)
9109 struct mlx5_flow_tunnel *tunnel;
9110 const char *err_msg = NULL;
9111 bool verdict = mlx5_flow_tunnel_validate(dev, app_tunnel, err_msg);
9114 return rte_flow_error_set(error, EINVAL,
9115 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
9117 ret = mlx5_get_flow_tunnel(dev, app_tunnel, &tunnel);
9119 return rte_flow_error_set(error, ret,
9120 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
9121 "failed to initialize pmd tunnel");
9123 *actions = &tunnel->action;
9124 *num_of_actions = 1;
9129 mlx5_flow_tunnel_match(struct rte_eth_dev *dev,
9130 struct rte_flow_tunnel *app_tunnel,
9131 struct rte_flow_item **items,
9132 uint32_t *num_of_items,
9133 struct rte_flow_error *error)
9136 struct mlx5_flow_tunnel *tunnel;
9137 const char *err_msg = NULL;
9138 bool verdict = mlx5_flow_tunnel_validate(dev, app_tunnel, err_msg);
9141 return rte_flow_error_set(error, EINVAL,
9142 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
9144 ret = mlx5_get_flow_tunnel(dev, app_tunnel, &tunnel);
9146 return rte_flow_error_set(error, ret,
9147 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
9148 "failed to initialize pmd tunnel");
9150 *items = &tunnel->item;
9155 struct tunnel_db_element_release_ctx {
9156 struct rte_flow_item *items;
9157 struct rte_flow_action *actions;
9158 uint32_t num_elements;
9159 struct rte_flow_error *error;
9164 tunnel_element_release_match(struct rte_eth_dev *dev,
9165 struct mlx5_flow_tunnel *tunnel, const void *x)
9167 const struct tunnel_db_element_release_ctx *ctx = x;
9170 if (ctx->num_elements != 1)
9172 else if (ctx->items)
9173 return ctx->items == &tunnel->item;
9174 else if (ctx->actions)
9175 return ctx->actions == &tunnel->action;
9181 tunnel_element_release_hit(struct rte_eth_dev *dev,
9182 struct mlx5_flow_tunnel *tunnel, void *x)
9184 struct tunnel_db_element_release_ctx *ctx = x;
9186 if (!__atomic_sub_fetch(&tunnel->refctn, 1, __ATOMIC_RELAXED))
9187 mlx5_flow_tunnel_free(dev, tunnel);
9191 tunnel_element_release_miss(struct rte_eth_dev *dev, void *x)
9193 struct tunnel_db_element_release_ctx *ctx = x;
9195 ctx->ret = rte_flow_error_set(ctx->error, EINVAL,
9196 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
9197 "invalid argument");
9201 mlx5_flow_tunnel_item_release(struct rte_eth_dev *dev,
9202 struct rte_flow_item *pmd_items,
9203 uint32_t num_items, struct rte_flow_error *err)
9205 struct tunnel_db_element_release_ctx ctx = {
9208 .num_elements = num_items,
9212 mlx5_access_tunnel_offload_db(dev, tunnel_element_release_match,
9213 tunnel_element_release_hit,
9214 tunnel_element_release_miss, &ctx, false);
9220 mlx5_flow_tunnel_action_release(struct rte_eth_dev *dev,
9221 struct rte_flow_action *pmd_actions,
9222 uint32_t num_actions, struct rte_flow_error *err)
9224 struct tunnel_db_element_release_ctx ctx = {
9226 .actions = pmd_actions,
9227 .num_elements = num_actions,
9231 mlx5_access_tunnel_offload_db(dev, tunnel_element_release_match,
9232 tunnel_element_release_hit,
9233 tunnel_element_release_miss, &ctx, false);
9239 mlx5_flow_tunnel_get_restore_info(struct rte_eth_dev *dev,
9241 struct rte_flow_restore_info *info,
9242 struct rte_flow_error *err)
9244 uint64_t ol_flags = m->ol_flags;
9245 const struct mlx5_flow_tbl_data_entry *tble;
9246 const uint64_t mask = RTE_MBUF_F_RX_FDIR | RTE_MBUF_F_RX_FDIR_ID;
9248 if (!is_tunnel_offload_active(dev)) {
9253 if ((ol_flags & mask) != mask)
9255 tble = tunnel_mark_decode(dev, m->hash.fdir.hi);
9257 DRV_LOG(DEBUG, "port %u invalid miss tunnel mark %#x",
9258 dev->data->port_id, m->hash.fdir.hi);
9261 MLX5_ASSERT(tble->tunnel);
9262 memcpy(&info->tunnel, &tble->tunnel->app_tunnel, sizeof(info->tunnel));
9263 info->group_id = tble->group_id;
9264 info->flags = RTE_FLOW_RESTORE_INFO_TUNNEL |
9265 RTE_FLOW_RESTORE_INFO_GROUP_ID |
9266 RTE_FLOW_RESTORE_INFO_ENCAPSULATED;
9271 return rte_flow_error_set(err, EINVAL,
9272 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
9273 "failed to get restore info");
9276 #else /* HAVE_IBV_FLOW_DV_SUPPORT */
9278 mlx5_flow_tunnel_decap_set(__rte_unused struct rte_eth_dev *dev,
9279 __rte_unused struct rte_flow_tunnel *app_tunnel,
9280 __rte_unused struct rte_flow_action **actions,
9281 __rte_unused uint32_t *num_of_actions,
9282 __rte_unused struct rte_flow_error *error)
9288 mlx5_flow_tunnel_match(__rte_unused struct rte_eth_dev *dev,
9289 __rte_unused struct rte_flow_tunnel *app_tunnel,
9290 __rte_unused struct rte_flow_item **items,
9291 __rte_unused uint32_t *num_of_items,
9292 __rte_unused struct rte_flow_error *error)
9298 mlx5_flow_tunnel_item_release(__rte_unused struct rte_eth_dev *dev,
9299 __rte_unused struct rte_flow_item *pmd_items,
9300 __rte_unused uint32_t num_items,
9301 __rte_unused struct rte_flow_error *err)
9307 mlx5_flow_tunnel_action_release(__rte_unused struct rte_eth_dev *dev,
9308 __rte_unused struct rte_flow_action *pmd_action,
9309 __rte_unused uint32_t num_actions,
9310 __rte_unused struct rte_flow_error *err)
9316 mlx5_flow_tunnel_get_restore_info(__rte_unused struct rte_eth_dev *dev,
9317 __rte_unused struct rte_mbuf *m,
9318 __rte_unused struct rte_flow_restore_info *i,
9319 __rte_unused struct rte_flow_error *err)
9325 flow_tunnel_add_default_miss(__rte_unused struct rte_eth_dev *dev,
9326 __rte_unused struct rte_flow *flow,
9327 __rte_unused const struct rte_flow_attr *attr,
9328 __rte_unused const struct rte_flow_action *actions,
9329 __rte_unused uint32_t flow_idx,
9330 __rte_unused const struct mlx5_flow_tunnel *tunnel,
9331 __rte_unused struct tunnel_default_miss_ctx *ctx,
9332 __rte_unused struct rte_flow_error *error)
9337 static struct mlx5_flow_tunnel *
9338 mlx5_find_tunnel_id(__rte_unused struct rte_eth_dev *dev,
9339 __rte_unused uint32_t id)
9345 mlx5_flow_tunnel_free(__rte_unused struct rte_eth_dev *dev,
9346 __rte_unused struct mlx5_flow_tunnel *tunnel)
9351 tunnel_flow_group_to_flow_table(__rte_unused struct rte_eth_dev *dev,
9352 __rte_unused const struct mlx5_flow_tunnel *t,
9353 __rte_unused uint32_t group,
9354 __rte_unused uint32_t *table,
9355 struct rte_flow_error *error)
9357 return rte_flow_error_set(error, ENOTSUP,
9358 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
9359 "tunnel offload requires DV support");
9363 mlx5_release_tunnel_hub(__rte_unused struct mlx5_dev_ctx_shared *sh,
9364 __rte_unused uint16_t port_id)
9367 #endif /* HAVE_IBV_FLOW_DV_SUPPORT */
9370 mlx5_dbg__print_pattern(const struct rte_flow_item *item)
9373 struct rte_flow_error error;
9375 for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
9377 ret = rte_flow_conv(RTE_FLOW_CONV_OP_ITEM_NAME_PTR, &item_name,
9379 (void *)(uintptr_t)item->type, &error);
9381 printf("%s ", item_name);
9383 printf("%d\n", (int)item->type);