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:
145 static enum rte_flow_item_type
146 mlx5_flow_expand_rss_item_complete(const struct rte_flow_item *item)
148 enum rte_flow_item_type ret = RTE_FLOW_ITEM_TYPE_VOID;
149 uint16_t ether_type = 0;
150 uint16_t ether_type_m;
151 uint8_t ip_next_proto = 0;
152 uint8_t ip_next_proto_m;
154 if (item == NULL || item->spec == NULL)
156 switch (item->type) {
157 case RTE_FLOW_ITEM_TYPE_ETH:
159 ether_type_m = ((const struct rte_flow_item_eth *)
162 ether_type_m = rte_flow_item_eth_mask.type;
163 if (ether_type_m != RTE_BE16(0xFFFF))
165 ether_type = ((const struct rte_flow_item_eth *)
167 if (rte_be_to_cpu_16(ether_type) == RTE_ETHER_TYPE_IPV4)
168 ret = RTE_FLOW_ITEM_TYPE_IPV4;
169 else if (rte_be_to_cpu_16(ether_type) == RTE_ETHER_TYPE_IPV6)
170 ret = RTE_FLOW_ITEM_TYPE_IPV6;
171 else if (rte_be_to_cpu_16(ether_type) == RTE_ETHER_TYPE_VLAN)
172 ret = RTE_FLOW_ITEM_TYPE_VLAN;
174 ret = RTE_FLOW_ITEM_TYPE_END;
176 case RTE_FLOW_ITEM_TYPE_VLAN:
178 ether_type_m = ((const struct rte_flow_item_vlan *)
179 (item->mask))->inner_type;
181 ether_type_m = rte_flow_item_vlan_mask.inner_type;
182 if (ether_type_m != RTE_BE16(0xFFFF))
184 ether_type = ((const struct rte_flow_item_vlan *)
185 (item->spec))->inner_type;
186 if (rte_be_to_cpu_16(ether_type) == RTE_ETHER_TYPE_IPV4)
187 ret = RTE_FLOW_ITEM_TYPE_IPV4;
188 else if (rte_be_to_cpu_16(ether_type) == RTE_ETHER_TYPE_IPV6)
189 ret = RTE_FLOW_ITEM_TYPE_IPV6;
190 else if (rte_be_to_cpu_16(ether_type) == RTE_ETHER_TYPE_VLAN)
191 ret = RTE_FLOW_ITEM_TYPE_VLAN;
193 ret = RTE_FLOW_ITEM_TYPE_END;
195 case RTE_FLOW_ITEM_TYPE_IPV4:
197 ip_next_proto_m = ((const struct rte_flow_item_ipv4 *)
198 (item->mask))->hdr.next_proto_id;
201 rte_flow_item_ipv4_mask.hdr.next_proto_id;
202 if (ip_next_proto_m != 0xFF)
204 ip_next_proto = ((const struct rte_flow_item_ipv4 *)
205 (item->spec))->hdr.next_proto_id;
206 if (ip_next_proto == IPPROTO_UDP)
207 ret = RTE_FLOW_ITEM_TYPE_UDP;
208 else if (ip_next_proto == IPPROTO_TCP)
209 ret = RTE_FLOW_ITEM_TYPE_TCP;
210 else if (ip_next_proto == IPPROTO_IP)
211 ret = RTE_FLOW_ITEM_TYPE_IPV4;
212 else if (ip_next_proto == IPPROTO_IPV6)
213 ret = RTE_FLOW_ITEM_TYPE_IPV6;
215 ret = RTE_FLOW_ITEM_TYPE_END;
217 case RTE_FLOW_ITEM_TYPE_IPV6:
219 ip_next_proto_m = ((const struct rte_flow_item_ipv6 *)
220 (item->mask))->hdr.proto;
223 rte_flow_item_ipv6_mask.hdr.proto;
224 if (ip_next_proto_m != 0xFF)
226 ip_next_proto = ((const struct rte_flow_item_ipv6 *)
227 (item->spec))->hdr.proto;
228 if (ip_next_proto == IPPROTO_UDP)
229 ret = RTE_FLOW_ITEM_TYPE_UDP;
230 else if (ip_next_proto == IPPROTO_TCP)
231 ret = RTE_FLOW_ITEM_TYPE_TCP;
232 else if (ip_next_proto == IPPROTO_IP)
233 ret = RTE_FLOW_ITEM_TYPE_IPV4;
234 else if (ip_next_proto == IPPROTO_IPV6)
235 ret = RTE_FLOW_ITEM_TYPE_IPV6;
237 ret = RTE_FLOW_ITEM_TYPE_END;
240 ret = RTE_FLOW_ITEM_TYPE_VOID;
246 #define MLX5_RSS_EXP_ELT_N 16
249 * Expand RSS flows into several possible flows according to the RSS hash
250 * fields requested and the driver capabilities.
253 * Buffer to store the result expansion.
255 * Buffer size in bytes. If 0, @p buf can be NULL.
259 * RSS types to expand (see ETH_RSS_* definitions).
261 * Input graph to expand @p pattern according to @p types.
262 * @param[in] graph_root_index
263 * Index of root node in @p graph, typically 0.
266 * A positive value representing the size of @p buf in bytes regardless of
267 * @p size on success, a negative errno value otherwise and rte_errno is
268 * set, the following errors are defined:
270 * -E2BIG: graph-depth @p graph is too deep.
271 * -EINVAL: @p size has not enough space for expanded pattern.
274 mlx5_flow_expand_rss(struct mlx5_flow_expand_rss *buf, size_t size,
275 const struct rte_flow_item *pattern, uint64_t types,
276 const struct mlx5_flow_expand_node graph[],
277 int graph_root_index)
279 const struct rte_flow_item *item;
280 const struct mlx5_flow_expand_node *node = &graph[graph_root_index];
281 const int *next_node;
282 const int *stack[MLX5_RSS_EXP_ELT_N];
284 struct rte_flow_item flow_items[MLX5_RSS_EXP_ELT_N];
287 size_t user_pattern_size = 0;
289 const struct mlx5_flow_expand_node *next = NULL;
290 struct rte_flow_item missed_item;
293 const struct rte_flow_item *last_item = NULL;
295 memset(&missed_item, 0, sizeof(missed_item));
296 lsize = offsetof(struct mlx5_flow_expand_rss, entry) +
297 MLX5_RSS_EXP_ELT_N * sizeof(buf->entry[0]);
300 buf->entry[0].priority = 0;
301 buf->entry[0].pattern = (void *)&buf->entry[MLX5_RSS_EXP_ELT_N];
303 addr = buf->entry[0].pattern;
304 for (item = pattern; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
305 if (!mlx5_flow_is_rss_expandable_item(item)) {
306 user_pattern_size += sizeof(*item);
310 for (i = 0; node->next && node->next[i]; ++i) {
311 next = &graph[node->next[i]];
312 if (next->type == item->type)
317 user_pattern_size += sizeof(*item);
319 user_pattern_size += sizeof(*item); /* Handle END item. */
320 lsize += user_pattern_size;
323 /* Copy the user pattern in the first entry of the buffer. */
324 rte_memcpy(addr, pattern, user_pattern_size);
325 addr = (void *)(((uintptr_t)addr) + user_pattern_size);
327 /* Start expanding. */
328 memset(flow_items, 0, sizeof(flow_items));
329 user_pattern_size -= sizeof(*item);
331 * Check if the last valid item has spec set, need complete pattern,
332 * and the pattern can be used for expansion.
334 missed_item.type = mlx5_flow_expand_rss_item_complete(last_item);
335 if (missed_item.type == RTE_FLOW_ITEM_TYPE_END) {
336 /* Item type END indicates expansion is not required. */
339 if (missed_item.type != RTE_FLOW_ITEM_TYPE_VOID) {
342 for (i = 0; node->next && node->next[i]; ++i) {
343 next = &graph[node->next[i]];
344 if (next->type == missed_item.type) {
345 flow_items[0].type = missed_item.type;
346 flow_items[1].type = RTE_FLOW_ITEM_TYPE_END;
352 if (next && missed) {
353 elt = 2; /* missed item + item end. */
355 lsize += elt * sizeof(*item) + user_pattern_size;
358 if (node->rss_types & types) {
359 buf->entry[buf->entries].priority = 1;
360 buf->entry[buf->entries].pattern = addr;
362 rte_memcpy(addr, buf->entry[0].pattern,
364 addr = (void *)(((uintptr_t)addr) + user_pattern_size);
365 rte_memcpy(addr, flow_items, elt * sizeof(*item));
366 addr = (void *)(((uintptr_t)addr) +
367 elt * sizeof(*item));
370 memset(flow_items, 0, sizeof(flow_items));
371 next_node = node->next;
372 stack[stack_pos] = next_node;
373 node = next_node ? &graph[*next_node] : NULL;
375 flow_items[stack_pos].type = node->type;
376 if (node->rss_types & types) {
379 * compute the number of items to copy from the
380 * expansion and copy it.
381 * When the stack_pos is 0, there are 1 element in it,
382 * plus the addition END item.
385 flow_items[stack_pos + 1].type = RTE_FLOW_ITEM_TYPE_END;
386 lsize += elt * sizeof(*item) + user_pattern_size;
389 n = elt * sizeof(*item);
390 buf->entry[buf->entries].priority =
391 stack_pos + 1 + missed;
392 buf->entry[buf->entries].pattern = addr;
394 rte_memcpy(addr, buf->entry[0].pattern,
396 addr = (void *)(((uintptr_t)addr) +
398 rte_memcpy(addr, &missed_item,
399 missed * sizeof(*item));
400 addr = (void *)(((uintptr_t)addr) +
401 missed * sizeof(*item));
402 rte_memcpy(addr, flow_items, n);
403 addr = (void *)(((uintptr_t)addr) + n);
406 if (!node->optional && node->next) {
407 next_node = node->next;
408 if (stack_pos++ == MLX5_RSS_EXP_ELT_N) {
412 stack[stack_pos] = next_node;
413 } else if (*(next_node + 1)) {
414 /* Follow up with the next possibility. */
417 /* Move to the next path. */
419 next_node = stack[--stack_pos];
421 stack[stack_pos] = next_node;
423 node = *next_node ? &graph[*next_node] : NULL;
428 enum mlx5_expansion {
430 MLX5_EXPANSION_ROOT_OUTER,
431 MLX5_EXPANSION_ROOT_ETH_VLAN,
432 MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN,
433 MLX5_EXPANSION_OUTER_ETH,
434 MLX5_EXPANSION_OUTER_ETH_VLAN,
435 MLX5_EXPANSION_OUTER_VLAN,
436 MLX5_EXPANSION_OUTER_IPV4,
437 MLX5_EXPANSION_OUTER_IPV4_UDP,
438 MLX5_EXPANSION_OUTER_IPV4_TCP,
439 MLX5_EXPANSION_OUTER_IPV6,
440 MLX5_EXPANSION_OUTER_IPV6_UDP,
441 MLX5_EXPANSION_OUTER_IPV6_TCP,
442 MLX5_EXPANSION_VXLAN,
443 MLX5_EXPANSION_VXLAN_GPE,
445 MLX5_EXPANSION_NVGRE,
446 MLX5_EXPANSION_GRE_KEY,
449 MLX5_EXPANSION_ETH_VLAN,
452 MLX5_EXPANSION_IPV4_UDP,
453 MLX5_EXPANSION_IPV4_TCP,
455 MLX5_EXPANSION_IPV6_UDP,
456 MLX5_EXPANSION_IPV6_TCP,
457 MLX5_EXPANSION_IPV6_FRAG_EXT,
460 /** Supported expansion of items. */
461 static const struct mlx5_flow_expand_node mlx5_support_expansion[] = {
462 [MLX5_EXPANSION_ROOT] = {
463 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
465 MLX5_EXPANSION_IPV6),
466 .type = RTE_FLOW_ITEM_TYPE_END,
468 [MLX5_EXPANSION_ROOT_OUTER] = {
469 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_ETH,
470 MLX5_EXPANSION_OUTER_IPV4,
471 MLX5_EXPANSION_OUTER_IPV6),
472 .type = RTE_FLOW_ITEM_TYPE_END,
474 [MLX5_EXPANSION_ROOT_ETH_VLAN] = {
475 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH_VLAN),
476 .type = RTE_FLOW_ITEM_TYPE_END,
478 [MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN] = {
479 .next = MLX5_FLOW_EXPAND_RSS_NEXT
480 (MLX5_EXPANSION_OUTER_ETH_VLAN),
481 .type = RTE_FLOW_ITEM_TYPE_END,
483 [MLX5_EXPANSION_OUTER_ETH] = {
484 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_IPV4,
485 MLX5_EXPANSION_OUTER_IPV6),
486 .type = RTE_FLOW_ITEM_TYPE_ETH,
489 [MLX5_EXPANSION_OUTER_ETH_VLAN] = {
490 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_VLAN),
491 .type = RTE_FLOW_ITEM_TYPE_ETH,
494 [MLX5_EXPANSION_OUTER_VLAN] = {
495 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_IPV4,
496 MLX5_EXPANSION_OUTER_IPV6),
497 .type = RTE_FLOW_ITEM_TYPE_VLAN,
499 [MLX5_EXPANSION_OUTER_IPV4] = {
500 .next = MLX5_FLOW_EXPAND_RSS_NEXT
501 (MLX5_EXPANSION_OUTER_IPV4_UDP,
502 MLX5_EXPANSION_OUTER_IPV4_TCP,
504 MLX5_EXPANSION_NVGRE,
506 MLX5_EXPANSION_IPV6),
507 .type = RTE_FLOW_ITEM_TYPE_IPV4,
508 .rss_types = ETH_RSS_IPV4 | ETH_RSS_FRAG_IPV4 |
509 ETH_RSS_NONFRAG_IPV4_OTHER,
511 [MLX5_EXPANSION_OUTER_IPV4_UDP] = {
512 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VXLAN,
513 MLX5_EXPANSION_VXLAN_GPE,
514 MLX5_EXPANSION_MPLS),
515 .type = RTE_FLOW_ITEM_TYPE_UDP,
516 .rss_types = ETH_RSS_NONFRAG_IPV4_UDP,
518 [MLX5_EXPANSION_OUTER_IPV4_TCP] = {
519 .type = RTE_FLOW_ITEM_TYPE_TCP,
520 .rss_types = ETH_RSS_NONFRAG_IPV4_TCP,
522 [MLX5_EXPANSION_OUTER_IPV6] = {
523 .next = MLX5_FLOW_EXPAND_RSS_NEXT
524 (MLX5_EXPANSION_OUTER_IPV6_UDP,
525 MLX5_EXPANSION_OUTER_IPV6_TCP,
529 MLX5_EXPANSION_NVGRE),
530 .type = RTE_FLOW_ITEM_TYPE_IPV6,
531 .rss_types = ETH_RSS_IPV6 | ETH_RSS_FRAG_IPV6 |
532 ETH_RSS_NONFRAG_IPV6_OTHER,
534 [MLX5_EXPANSION_OUTER_IPV6_UDP] = {
535 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VXLAN,
536 MLX5_EXPANSION_VXLAN_GPE,
537 MLX5_EXPANSION_MPLS),
538 .type = RTE_FLOW_ITEM_TYPE_UDP,
539 .rss_types = ETH_RSS_NONFRAG_IPV6_UDP,
541 [MLX5_EXPANSION_OUTER_IPV6_TCP] = {
542 .type = RTE_FLOW_ITEM_TYPE_TCP,
543 .rss_types = ETH_RSS_NONFRAG_IPV6_TCP,
545 [MLX5_EXPANSION_VXLAN] = {
546 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
548 MLX5_EXPANSION_IPV6),
549 .type = RTE_FLOW_ITEM_TYPE_VXLAN,
551 [MLX5_EXPANSION_VXLAN_GPE] = {
552 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
554 MLX5_EXPANSION_IPV6),
555 .type = RTE_FLOW_ITEM_TYPE_VXLAN_GPE,
557 [MLX5_EXPANSION_GRE] = {
558 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
560 MLX5_EXPANSION_GRE_KEY,
561 MLX5_EXPANSION_MPLS),
562 .type = RTE_FLOW_ITEM_TYPE_GRE,
564 [MLX5_EXPANSION_GRE_KEY] = {
565 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
567 MLX5_EXPANSION_MPLS),
568 .type = RTE_FLOW_ITEM_TYPE_GRE_KEY,
571 [MLX5_EXPANSION_NVGRE] = {
572 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH),
573 .type = RTE_FLOW_ITEM_TYPE_NVGRE,
575 [MLX5_EXPANSION_MPLS] = {
576 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
579 .type = RTE_FLOW_ITEM_TYPE_MPLS,
581 [MLX5_EXPANSION_ETH] = {
582 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
583 MLX5_EXPANSION_IPV6),
584 .type = RTE_FLOW_ITEM_TYPE_ETH,
586 [MLX5_EXPANSION_ETH_VLAN] = {
587 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VLAN),
588 .type = RTE_FLOW_ITEM_TYPE_ETH,
590 [MLX5_EXPANSION_VLAN] = {
591 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
592 MLX5_EXPANSION_IPV6),
593 .type = RTE_FLOW_ITEM_TYPE_VLAN,
595 [MLX5_EXPANSION_IPV4] = {
596 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4_UDP,
597 MLX5_EXPANSION_IPV4_TCP),
598 .type = RTE_FLOW_ITEM_TYPE_IPV4,
599 .rss_types = ETH_RSS_IPV4 | ETH_RSS_FRAG_IPV4 |
600 ETH_RSS_NONFRAG_IPV4_OTHER,
602 [MLX5_EXPANSION_IPV4_UDP] = {
603 .type = RTE_FLOW_ITEM_TYPE_UDP,
604 .rss_types = ETH_RSS_NONFRAG_IPV4_UDP,
606 [MLX5_EXPANSION_IPV4_TCP] = {
607 .type = RTE_FLOW_ITEM_TYPE_TCP,
608 .rss_types = ETH_RSS_NONFRAG_IPV4_TCP,
610 [MLX5_EXPANSION_IPV6] = {
611 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV6_UDP,
612 MLX5_EXPANSION_IPV6_TCP,
613 MLX5_EXPANSION_IPV6_FRAG_EXT),
614 .type = RTE_FLOW_ITEM_TYPE_IPV6,
615 .rss_types = ETH_RSS_IPV6 | ETH_RSS_FRAG_IPV6 |
616 ETH_RSS_NONFRAG_IPV6_OTHER,
618 [MLX5_EXPANSION_IPV6_UDP] = {
619 .type = RTE_FLOW_ITEM_TYPE_UDP,
620 .rss_types = ETH_RSS_NONFRAG_IPV6_UDP,
622 [MLX5_EXPANSION_IPV6_TCP] = {
623 .type = RTE_FLOW_ITEM_TYPE_TCP,
624 .rss_types = ETH_RSS_NONFRAG_IPV6_TCP,
626 [MLX5_EXPANSION_IPV6_FRAG_EXT] = {
627 .type = RTE_FLOW_ITEM_TYPE_IPV6_FRAG_EXT,
631 static struct rte_flow_action_handle *
632 mlx5_action_handle_create(struct rte_eth_dev *dev,
633 const struct rte_flow_indir_action_conf *conf,
634 const struct rte_flow_action *action,
635 struct rte_flow_error *error);
636 static int mlx5_action_handle_destroy
637 (struct rte_eth_dev *dev,
638 struct rte_flow_action_handle *handle,
639 struct rte_flow_error *error);
640 static int mlx5_action_handle_update
641 (struct rte_eth_dev *dev,
642 struct rte_flow_action_handle *handle,
644 struct rte_flow_error *error);
645 static int mlx5_action_handle_query
646 (struct rte_eth_dev *dev,
647 const struct rte_flow_action_handle *handle,
649 struct rte_flow_error *error);
651 mlx5_flow_tunnel_decap_set(struct rte_eth_dev *dev,
652 struct rte_flow_tunnel *app_tunnel,
653 struct rte_flow_action **actions,
654 uint32_t *num_of_actions,
655 struct rte_flow_error *error);
657 mlx5_flow_tunnel_match(struct rte_eth_dev *dev,
658 struct rte_flow_tunnel *app_tunnel,
659 struct rte_flow_item **items,
660 uint32_t *num_of_items,
661 struct rte_flow_error *error);
663 mlx5_flow_tunnel_item_release(struct rte_eth_dev *dev,
664 struct rte_flow_item *pmd_items,
665 uint32_t num_items, struct rte_flow_error *err);
667 mlx5_flow_tunnel_action_release(struct rte_eth_dev *dev,
668 struct rte_flow_action *pmd_actions,
669 uint32_t num_actions,
670 struct rte_flow_error *err);
672 mlx5_flow_tunnel_get_restore_info(struct rte_eth_dev *dev,
674 struct rte_flow_restore_info *info,
675 struct rte_flow_error *err);
677 static const struct rte_flow_ops mlx5_flow_ops = {
678 .validate = mlx5_flow_validate,
679 .create = mlx5_flow_create,
680 .destroy = mlx5_flow_destroy,
681 .flush = mlx5_flow_flush,
682 .isolate = mlx5_flow_isolate,
683 .query = mlx5_flow_query,
684 .dev_dump = mlx5_flow_dev_dump,
685 .get_aged_flows = mlx5_flow_get_aged_flows,
686 .action_handle_create = mlx5_action_handle_create,
687 .action_handle_destroy = mlx5_action_handle_destroy,
688 .action_handle_update = mlx5_action_handle_update,
689 .action_handle_query = mlx5_action_handle_query,
690 .tunnel_decap_set = mlx5_flow_tunnel_decap_set,
691 .tunnel_match = mlx5_flow_tunnel_match,
692 .tunnel_action_decap_release = mlx5_flow_tunnel_action_release,
693 .tunnel_item_release = mlx5_flow_tunnel_item_release,
694 .get_restore_info = mlx5_flow_tunnel_get_restore_info,
697 /* Tunnel information. */
698 struct mlx5_flow_tunnel_info {
699 uint64_t tunnel; /**< Tunnel bit (see MLX5_FLOW_*). */
700 uint32_t ptype; /**< Tunnel Ptype (see RTE_PTYPE_*). */
703 static struct mlx5_flow_tunnel_info tunnels_info[] = {
705 .tunnel = MLX5_FLOW_LAYER_VXLAN,
706 .ptype = RTE_PTYPE_TUNNEL_VXLAN | RTE_PTYPE_L4_UDP,
709 .tunnel = MLX5_FLOW_LAYER_GENEVE,
710 .ptype = RTE_PTYPE_TUNNEL_GENEVE | RTE_PTYPE_L4_UDP,
713 .tunnel = MLX5_FLOW_LAYER_VXLAN_GPE,
714 .ptype = RTE_PTYPE_TUNNEL_VXLAN_GPE | RTE_PTYPE_L4_UDP,
717 .tunnel = MLX5_FLOW_LAYER_GRE,
718 .ptype = RTE_PTYPE_TUNNEL_GRE,
721 .tunnel = MLX5_FLOW_LAYER_MPLS | MLX5_FLOW_LAYER_OUTER_L4_UDP,
722 .ptype = RTE_PTYPE_TUNNEL_MPLS_IN_UDP | RTE_PTYPE_L4_UDP,
725 .tunnel = MLX5_FLOW_LAYER_MPLS,
726 .ptype = RTE_PTYPE_TUNNEL_MPLS_IN_GRE,
729 .tunnel = MLX5_FLOW_LAYER_NVGRE,
730 .ptype = RTE_PTYPE_TUNNEL_NVGRE,
733 .tunnel = MLX5_FLOW_LAYER_IPIP,
734 .ptype = RTE_PTYPE_TUNNEL_IP,
737 .tunnel = MLX5_FLOW_LAYER_IPV6_ENCAP,
738 .ptype = RTE_PTYPE_TUNNEL_IP,
741 .tunnel = MLX5_FLOW_LAYER_GTP,
742 .ptype = RTE_PTYPE_TUNNEL_GTPU,
749 * Translate tag ID to register.
752 * Pointer to the Ethernet device structure.
754 * The feature that request the register.
756 * The request register ID.
758 * Error description in case of any.
761 * The request register on success, a negative errno
762 * value otherwise and rte_errno is set.
765 mlx5_flow_get_reg_id(struct rte_eth_dev *dev,
766 enum mlx5_feature_name feature,
768 struct rte_flow_error *error)
770 struct mlx5_priv *priv = dev->data->dev_private;
771 struct mlx5_dev_config *config = &priv->config;
772 enum modify_reg start_reg;
773 bool skip_mtr_reg = false;
776 case MLX5_HAIRPIN_RX:
778 case MLX5_HAIRPIN_TX:
780 case MLX5_METADATA_RX:
781 switch (config->dv_xmeta_en) {
782 case MLX5_XMETA_MODE_LEGACY:
784 case MLX5_XMETA_MODE_META16:
786 case MLX5_XMETA_MODE_META32:
790 case MLX5_METADATA_TX:
792 case MLX5_METADATA_FDB:
793 switch (config->dv_xmeta_en) {
794 case MLX5_XMETA_MODE_LEGACY:
796 case MLX5_XMETA_MODE_META16:
798 case MLX5_XMETA_MODE_META32:
803 switch (config->dv_xmeta_en) {
804 case MLX5_XMETA_MODE_LEGACY:
806 case MLX5_XMETA_MODE_META16:
808 case MLX5_XMETA_MODE_META32:
814 * If meter color and meter id share one register, flow match
815 * should use the meter color register for match.
817 if (priv->mtr_reg_share)
818 return priv->mtr_color_reg;
820 return priv->mtr_color_reg != REG_C_2 ? REG_C_2 :
823 case MLX5_ASO_FLOW_HIT:
824 case MLX5_ASO_CONNTRACK:
825 /* All features use the same REG_C. */
826 MLX5_ASSERT(priv->mtr_color_reg != REG_NON);
827 return priv->mtr_color_reg;
830 * Metadata COPY_MARK register using is in meter suffix sub
831 * flow while with meter. It's safe to share the same register.
833 return priv->mtr_color_reg != REG_C_2 ? REG_C_2 : REG_C_3;
836 * If meter is enable, it will engage the register for color
837 * match and flow match. If meter color match is not using the
838 * REG_C_2, need to skip the REG_C_x be used by meter color
840 * If meter is disable, free to use all available registers.
842 start_reg = priv->mtr_color_reg != REG_C_2 ? REG_C_2 :
843 (priv->mtr_reg_share ? REG_C_3 : REG_C_4);
844 skip_mtr_reg = !!(priv->mtr_en && start_reg == REG_C_2);
845 if (id > (uint32_t)(REG_C_7 - start_reg))
846 return rte_flow_error_set(error, EINVAL,
847 RTE_FLOW_ERROR_TYPE_ITEM,
848 NULL, "invalid tag id");
849 if (config->flow_mreg_c[id + start_reg - REG_C_0] == REG_NON)
850 return rte_flow_error_set(error, ENOTSUP,
851 RTE_FLOW_ERROR_TYPE_ITEM,
852 NULL, "unsupported tag id");
854 * This case means meter is using the REG_C_x great than 2.
855 * Take care not to conflict with meter color REG_C_x.
856 * If the available index REG_C_y >= REG_C_x, skip the
859 if (skip_mtr_reg && config->flow_mreg_c
860 [id + start_reg - REG_C_0] >= priv->mtr_color_reg) {
861 if (id >= (uint32_t)(REG_C_7 - start_reg))
862 return rte_flow_error_set(error, EINVAL,
863 RTE_FLOW_ERROR_TYPE_ITEM,
864 NULL, "invalid tag id");
865 if (config->flow_mreg_c
866 [id + 1 + start_reg - REG_C_0] != REG_NON)
867 return config->flow_mreg_c
868 [id + 1 + start_reg - REG_C_0];
869 return rte_flow_error_set(error, ENOTSUP,
870 RTE_FLOW_ERROR_TYPE_ITEM,
871 NULL, "unsupported tag id");
873 return config->flow_mreg_c[id + start_reg - REG_C_0];
876 return rte_flow_error_set(error, EINVAL,
877 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
878 NULL, "invalid feature name");
882 * Check extensive flow metadata register support.
885 * Pointer to rte_eth_dev structure.
888 * True if device supports extensive flow metadata register, otherwise false.
891 mlx5_flow_ext_mreg_supported(struct rte_eth_dev *dev)
893 struct mlx5_priv *priv = dev->data->dev_private;
894 struct mlx5_dev_config *config = &priv->config;
897 * Having available reg_c can be regarded inclusively as supporting
898 * extensive flow metadata register, which could mean,
899 * - metadata register copy action by modify header.
900 * - 16 modify header actions is supported.
901 * - reg_c's are preserved across different domain (FDB and NIC) on
902 * packet loopback by flow lookup miss.
904 return config->flow_mreg_c[2] != REG_NON;
908 * Get the lowest priority.
911 * Pointer to the Ethernet device structure.
912 * @param[in] attributes
913 * Pointer to device flow rule attributes.
916 * The value of lowest priority of flow.
919 mlx5_get_lowest_priority(struct rte_eth_dev *dev,
920 const struct rte_flow_attr *attr)
922 struct mlx5_priv *priv = dev->data->dev_private;
924 if (!attr->group && !attr->transfer)
925 return priv->config.flow_prio - 2;
926 return MLX5_NON_ROOT_FLOW_MAX_PRIO - 1;
930 * Calculate matcher priority of the flow.
933 * Pointer to the Ethernet device structure.
935 * Pointer to device flow rule attributes.
936 * @param[in] subpriority
937 * The priority based on the items.
939 * The matcher priority of the flow.
942 mlx5_get_matcher_priority(struct rte_eth_dev *dev,
943 const struct rte_flow_attr *attr,
944 uint32_t subpriority)
946 uint16_t priority = (uint16_t)attr->priority;
947 struct mlx5_priv *priv = dev->data->dev_private;
949 if (!attr->group && !attr->transfer) {
950 if (attr->priority == MLX5_FLOW_LOWEST_PRIO_INDICATOR)
951 priority = priv->config.flow_prio - 1;
952 return mlx5_os_flow_adjust_priority(dev, priority, subpriority);
954 if (attr->priority == MLX5_FLOW_LOWEST_PRIO_INDICATOR)
955 priority = MLX5_NON_ROOT_FLOW_MAX_PRIO;
956 return priority * 3 + subpriority;
960 * Verify the @p item specifications (spec, last, mask) are compatible with the
964 * Item specification.
966 * @p item->mask or flow default bit-masks.
967 * @param[in] nic_mask
968 * Bit-masks covering supported fields by the NIC to compare with user mask.
970 * Bit-masks size in bytes.
971 * @param[in] range_accepted
972 * True if range of values is accepted for specific fields, false otherwise.
974 * Pointer to error structure.
977 * 0 on success, a negative errno value otherwise and rte_errno is set.
980 mlx5_flow_item_acceptable(const struct rte_flow_item *item,
982 const uint8_t *nic_mask,
985 struct rte_flow_error *error)
989 MLX5_ASSERT(nic_mask);
990 for (i = 0; i < size; ++i)
991 if ((nic_mask[i] | mask[i]) != nic_mask[i])
992 return rte_flow_error_set(error, ENOTSUP,
993 RTE_FLOW_ERROR_TYPE_ITEM,
995 "mask enables non supported"
997 if (!item->spec && (item->mask || item->last))
998 return rte_flow_error_set(error, EINVAL,
999 RTE_FLOW_ERROR_TYPE_ITEM, item,
1000 "mask/last without a spec is not"
1002 if (item->spec && item->last && !range_accepted) {
1008 for (i = 0; i < size; ++i) {
1009 spec[i] = ((const uint8_t *)item->spec)[i] & mask[i];
1010 last[i] = ((const uint8_t *)item->last)[i] & mask[i];
1012 ret = memcmp(spec, last, size);
1014 return rte_flow_error_set(error, EINVAL,
1015 RTE_FLOW_ERROR_TYPE_ITEM,
1017 "range is not valid");
1023 * Adjust the hash fields according to the @p flow information.
1025 * @param[in] dev_flow.
1026 * Pointer to the mlx5_flow.
1028 * 1 when the hash field is for a tunnel item.
1029 * @param[in] layer_types
1031 * @param[in] hash_fields
1035 * The hash fields that should be used.
1038 mlx5_flow_hashfields_adjust(struct mlx5_flow_rss_desc *rss_desc,
1039 int tunnel __rte_unused, uint64_t layer_types,
1040 uint64_t hash_fields)
1042 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
1043 int rss_request_inner = rss_desc->level >= 2;
1045 /* Check RSS hash level for tunnel. */
1046 if (tunnel && rss_request_inner)
1047 hash_fields |= IBV_RX_HASH_INNER;
1048 else if (tunnel || rss_request_inner)
1051 /* Check if requested layer matches RSS hash fields. */
1052 if (!(rss_desc->types & layer_types))
1058 * Lookup and set the ptype in the data Rx part. A single Ptype can be used,
1059 * if several tunnel rules are used on this queue, the tunnel ptype will be
1063 * Rx queue to update.
1066 flow_rxq_tunnel_ptype_update(struct mlx5_rxq_ctrl *rxq_ctrl)
1069 uint32_t tunnel_ptype = 0;
1071 /* Look up for the ptype to use. */
1072 for (i = 0; i != MLX5_FLOW_TUNNEL; ++i) {
1073 if (!rxq_ctrl->flow_tunnels_n[i])
1075 if (!tunnel_ptype) {
1076 tunnel_ptype = tunnels_info[i].ptype;
1082 rxq_ctrl->rxq.tunnel = tunnel_ptype;
1086 * Set the Rx queue flags (Mark/Flag and Tunnel Ptypes) according to the devive
1090 * Pointer to the Ethernet device structure.
1091 * @param[in] dev_handle
1092 * Pointer to device flow handle structure.
1095 flow_drv_rxq_flags_set(struct rte_eth_dev *dev,
1096 struct mlx5_flow_handle *dev_handle)
1098 struct mlx5_priv *priv = dev->data->dev_private;
1099 const int mark = dev_handle->mark;
1100 const int tunnel = !!(dev_handle->layers & MLX5_FLOW_LAYER_TUNNEL);
1101 struct mlx5_ind_table_obj *ind_tbl = NULL;
1104 if (dev_handle->fate_action == MLX5_FLOW_FATE_QUEUE) {
1105 struct mlx5_hrxq *hrxq;
1107 hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
1108 dev_handle->rix_hrxq);
1110 ind_tbl = hrxq->ind_table;
1111 } else if (dev_handle->fate_action == MLX5_FLOW_FATE_SHARED_RSS) {
1112 struct mlx5_shared_action_rss *shared_rss;
1114 shared_rss = mlx5_ipool_get
1115 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
1116 dev_handle->rix_srss);
1118 ind_tbl = shared_rss->ind_tbl;
1122 for (i = 0; i != ind_tbl->queues_n; ++i) {
1123 int idx = ind_tbl->queues[i];
1124 struct mlx5_rxq_ctrl *rxq_ctrl =
1125 container_of((*priv->rxqs)[idx],
1126 struct mlx5_rxq_ctrl, rxq);
1129 * To support metadata register copy on Tx loopback,
1130 * this must be always enabled (metadata may arive
1131 * from other port - not from local flows only.
1133 if (priv->config.dv_flow_en &&
1134 priv->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
1135 mlx5_flow_ext_mreg_supported(dev)) {
1136 rxq_ctrl->rxq.mark = 1;
1137 rxq_ctrl->flow_mark_n = 1;
1139 rxq_ctrl->rxq.mark = 1;
1140 rxq_ctrl->flow_mark_n++;
1145 /* Increase the counter matching the flow. */
1146 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j) {
1147 if ((tunnels_info[j].tunnel &
1148 dev_handle->layers) ==
1149 tunnels_info[j].tunnel) {
1150 rxq_ctrl->flow_tunnels_n[j]++;
1154 flow_rxq_tunnel_ptype_update(rxq_ctrl);
1160 * Set the Rx queue flags (Mark/Flag and Tunnel Ptypes) for a flow
1163 * Pointer to the Ethernet device structure.
1165 * Pointer to flow structure.
1168 flow_rxq_flags_set(struct rte_eth_dev *dev, struct rte_flow *flow)
1170 struct mlx5_priv *priv = dev->data->dev_private;
1171 uint32_t handle_idx;
1172 struct mlx5_flow_handle *dev_handle;
1174 SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
1175 handle_idx, dev_handle, next)
1176 flow_drv_rxq_flags_set(dev, dev_handle);
1180 * Clear the Rx queue flags (Mark/Flag and Tunnel Ptype) associated with the
1181 * device flow if no other flow uses it with the same kind of request.
1184 * Pointer to Ethernet device.
1185 * @param[in] dev_handle
1186 * Pointer to the device flow handle structure.
1189 flow_drv_rxq_flags_trim(struct rte_eth_dev *dev,
1190 struct mlx5_flow_handle *dev_handle)
1192 struct mlx5_priv *priv = dev->data->dev_private;
1193 const int mark = dev_handle->mark;
1194 const int tunnel = !!(dev_handle->layers & MLX5_FLOW_LAYER_TUNNEL);
1195 struct mlx5_ind_table_obj *ind_tbl = NULL;
1198 if (dev_handle->fate_action == MLX5_FLOW_FATE_QUEUE) {
1199 struct mlx5_hrxq *hrxq;
1201 hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
1202 dev_handle->rix_hrxq);
1204 ind_tbl = hrxq->ind_table;
1205 } else if (dev_handle->fate_action == MLX5_FLOW_FATE_SHARED_RSS) {
1206 struct mlx5_shared_action_rss *shared_rss;
1208 shared_rss = mlx5_ipool_get
1209 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
1210 dev_handle->rix_srss);
1212 ind_tbl = shared_rss->ind_tbl;
1216 MLX5_ASSERT(dev->data->dev_started);
1217 for (i = 0; i != ind_tbl->queues_n; ++i) {
1218 int idx = ind_tbl->queues[i];
1219 struct mlx5_rxq_ctrl *rxq_ctrl =
1220 container_of((*priv->rxqs)[idx],
1221 struct mlx5_rxq_ctrl, rxq);
1223 if (priv->config.dv_flow_en &&
1224 priv->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
1225 mlx5_flow_ext_mreg_supported(dev)) {
1226 rxq_ctrl->rxq.mark = 1;
1227 rxq_ctrl->flow_mark_n = 1;
1229 rxq_ctrl->flow_mark_n--;
1230 rxq_ctrl->rxq.mark = !!rxq_ctrl->flow_mark_n;
1235 /* Decrease the counter matching the flow. */
1236 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j) {
1237 if ((tunnels_info[j].tunnel &
1238 dev_handle->layers) ==
1239 tunnels_info[j].tunnel) {
1240 rxq_ctrl->flow_tunnels_n[j]--;
1244 flow_rxq_tunnel_ptype_update(rxq_ctrl);
1250 * Clear the Rx queue flags (Mark/Flag and Tunnel Ptype) associated with the
1251 * @p flow if no other flow uses it with the same kind of request.
1254 * Pointer to Ethernet device.
1256 * Pointer to the flow.
1259 flow_rxq_flags_trim(struct rte_eth_dev *dev, struct rte_flow *flow)
1261 struct mlx5_priv *priv = dev->data->dev_private;
1262 uint32_t handle_idx;
1263 struct mlx5_flow_handle *dev_handle;
1265 SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
1266 handle_idx, dev_handle, next)
1267 flow_drv_rxq_flags_trim(dev, dev_handle);
1271 * Clear the Mark/Flag and Tunnel ptype information in all Rx queues.
1274 * Pointer to Ethernet device.
1277 flow_rxq_flags_clear(struct rte_eth_dev *dev)
1279 struct mlx5_priv *priv = dev->data->dev_private;
1282 for (i = 0; i != priv->rxqs_n; ++i) {
1283 struct mlx5_rxq_ctrl *rxq_ctrl;
1286 if (!(*priv->rxqs)[i])
1288 rxq_ctrl = container_of((*priv->rxqs)[i],
1289 struct mlx5_rxq_ctrl, rxq);
1290 rxq_ctrl->flow_mark_n = 0;
1291 rxq_ctrl->rxq.mark = 0;
1292 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j)
1293 rxq_ctrl->flow_tunnels_n[j] = 0;
1294 rxq_ctrl->rxq.tunnel = 0;
1299 * Set the Rx queue dynamic metadata (mask and offset) for a flow
1302 * Pointer to the Ethernet device structure.
1305 mlx5_flow_rxq_dynf_metadata_set(struct rte_eth_dev *dev)
1307 struct mlx5_priv *priv = dev->data->dev_private;
1308 struct mlx5_rxq_data *data;
1311 for (i = 0; i != priv->rxqs_n; ++i) {
1312 if (!(*priv->rxqs)[i])
1314 data = (*priv->rxqs)[i];
1315 if (!rte_flow_dynf_metadata_avail()) {
1316 data->dynf_meta = 0;
1317 data->flow_meta_mask = 0;
1318 data->flow_meta_offset = -1;
1319 data->flow_meta_port_mask = 0;
1321 data->dynf_meta = 1;
1322 data->flow_meta_mask = rte_flow_dynf_metadata_mask;
1323 data->flow_meta_offset = rte_flow_dynf_metadata_offs;
1324 data->flow_meta_port_mask = priv->sh->dv_meta_mask;
1330 * return a pointer to the desired action in the list of actions.
1332 * @param[in] actions
1333 * The list of actions to search the action in.
1335 * The action to find.
1338 * Pointer to the action in the list, if found. NULL otherwise.
1340 const struct rte_flow_action *
1341 mlx5_flow_find_action(const struct rte_flow_action *actions,
1342 enum rte_flow_action_type action)
1344 if (actions == NULL)
1346 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++)
1347 if (actions->type == action)
1353 * Validate the flag action.
1355 * @param[in] action_flags
1356 * Bit-fields that holds the actions detected until now.
1358 * Attributes of flow that includes this action.
1360 * Pointer to error structure.
1363 * 0 on success, a negative errno value otherwise and rte_errno is set.
1366 mlx5_flow_validate_action_flag(uint64_t action_flags,
1367 const struct rte_flow_attr *attr,
1368 struct rte_flow_error *error)
1370 if (action_flags & MLX5_FLOW_ACTION_MARK)
1371 return rte_flow_error_set(error, EINVAL,
1372 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1373 "can't mark and flag in same flow");
1374 if (action_flags & MLX5_FLOW_ACTION_FLAG)
1375 return rte_flow_error_set(error, EINVAL,
1376 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1378 " actions in same flow");
1380 return rte_flow_error_set(error, ENOTSUP,
1381 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1382 "flag action not supported for "
1388 * Validate the mark action.
1391 * Pointer to the queue action.
1392 * @param[in] action_flags
1393 * Bit-fields that holds the actions detected until now.
1395 * Attributes of flow that includes this action.
1397 * Pointer to error structure.
1400 * 0 on success, a negative errno value otherwise and rte_errno is set.
1403 mlx5_flow_validate_action_mark(const struct rte_flow_action *action,
1404 uint64_t action_flags,
1405 const struct rte_flow_attr *attr,
1406 struct rte_flow_error *error)
1408 const struct rte_flow_action_mark *mark = action->conf;
1411 return rte_flow_error_set(error, EINVAL,
1412 RTE_FLOW_ERROR_TYPE_ACTION,
1414 "configuration cannot be null");
1415 if (mark->id >= MLX5_FLOW_MARK_MAX)
1416 return rte_flow_error_set(error, EINVAL,
1417 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1419 "mark id must in 0 <= id < "
1420 RTE_STR(MLX5_FLOW_MARK_MAX));
1421 if (action_flags & MLX5_FLOW_ACTION_FLAG)
1422 return rte_flow_error_set(error, EINVAL,
1423 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1424 "can't flag and mark in same flow");
1425 if (action_flags & MLX5_FLOW_ACTION_MARK)
1426 return rte_flow_error_set(error, EINVAL,
1427 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1428 "can't have 2 mark actions in same"
1431 return rte_flow_error_set(error, ENOTSUP,
1432 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1433 "mark action not supported for "
1439 * Validate the drop action.
1441 * @param[in] action_flags
1442 * Bit-fields that holds the actions detected until now.
1444 * Attributes of flow that includes this action.
1446 * Pointer to error structure.
1449 * 0 on success, a negative errno value otherwise and rte_errno is set.
1452 mlx5_flow_validate_action_drop(uint64_t action_flags __rte_unused,
1453 const struct rte_flow_attr *attr,
1454 struct rte_flow_error *error)
1457 return rte_flow_error_set(error, ENOTSUP,
1458 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1459 "drop action not supported for "
1465 * Validate the queue action.
1468 * Pointer to the queue action.
1469 * @param[in] action_flags
1470 * Bit-fields that holds the actions detected until now.
1472 * Pointer to the Ethernet device structure.
1474 * Attributes of flow that includes this action.
1476 * Pointer to error structure.
1479 * 0 on success, a negative errno value otherwise and rte_errno is set.
1482 mlx5_flow_validate_action_queue(const struct rte_flow_action *action,
1483 uint64_t action_flags,
1484 struct rte_eth_dev *dev,
1485 const struct rte_flow_attr *attr,
1486 struct rte_flow_error *error)
1488 struct mlx5_priv *priv = dev->data->dev_private;
1489 const struct rte_flow_action_queue *queue = action->conf;
1491 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
1492 return rte_flow_error_set(error, EINVAL,
1493 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1494 "can't have 2 fate actions in"
1497 return rte_flow_error_set(error, EINVAL,
1498 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1499 NULL, "No Rx queues configured");
1500 if (queue->index >= priv->rxqs_n)
1501 return rte_flow_error_set(error, EINVAL,
1502 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1504 "queue index out of range");
1505 if (!(*priv->rxqs)[queue->index])
1506 return rte_flow_error_set(error, EINVAL,
1507 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1509 "queue is not configured");
1511 return rte_flow_error_set(error, ENOTSUP,
1512 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1513 "queue action not supported for "
1519 * Validate the rss action.
1522 * Pointer to the Ethernet device structure.
1524 * Pointer to the queue action.
1526 * Pointer to error structure.
1529 * 0 on success, a negative errno value otherwise and rte_errno is set.
1532 mlx5_validate_action_rss(struct rte_eth_dev *dev,
1533 const struct rte_flow_action *action,
1534 struct rte_flow_error *error)
1536 struct mlx5_priv *priv = dev->data->dev_private;
1537 const struct rte_flow_action_rss *rss = action->conf;
1538 enum mlx5_rxq_type rxq_type = MLX5_RXQ_TYPE_UNDEFINED;
1541 if (rss->func != RTE_ETH_HASH_FUNCTION_DEFAULT &&
1542 rss->func != RTE_ETH_HASH_FUNCTION_TOEPLITZ)
1543 return rte_flow_error_set(error, ENOTSUP,
1544 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1546 "RSS hash function not supported");
1547 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
1552 return rte_flow_error_set(error, ENOTSUP,
1553 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1555 "tunnel RSS is not supported");
1556 /* allow RSS key_len 0 in case of NULL (default) RSS key. */
1557 if (rss->key_len == 0 && rss->key != NULL)
1558 return rte_flow_error_set(error, ENOTSUP,
1559 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1561 "RSS hash key length 0");
1562 if (rss->key_len > 0 && rss->key_len < MLX5_RSS_HASH_KEY_LEN)
1563 return rte_flow_error_set(error, ENOTSUP,
1564 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1566 "RSS hash key too small");
1567 if (rss->key_len > MLX5_RSS_HASH_KEY_LEN)
1568 return rte_flow_error_set(error, ENOTSUP,
1569 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1571 "RSS hash key too large");
1572 if (rss->queue_num > priv->config.ind_table_max_size)
1573 return rte_flow_error_set(error, ENOTSUP,
1574 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1576 "number of queues too large");
1577 if (rss->types & MLX5_RSS_HF_MASK)
1578 return rte_flow_error_set(error, ENOTSUP,
1579 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1581 "some RSS protocols are not"
1583 if ((rss->types & (ETH_RSS_L3_SRC_ONLY | ETH_RSS_L3_DST_ONLY)) &&
1584 !(rss->types & ETH_RSS_IP))
1585 return rte_flow_error_set(error, EINVAL,
1586 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1587 "L3 partial RSS requested but L3 RSS"
1588 " type not specified");
1589 if ((rss->types & (ETH_RSS_L4_SRC_ONLY | ETH_RSS_L4_DST_ONLY)) &&
1590 !(rss->types & (ETH_RSS_UDP | ETH_RSS_TCP)))
1591 return rte_flow_error_set(error, EINVAL,
1592 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1593 "L4 partial RSS requested but L4 RSS"
1594 " type not specified");
1596 return rte_flow_error_set(error, EINVAL,
1597 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1598 NULL, "No Rx queues configured");
1599 if (!rss->queue_num)
1600 return rte_flow_error_set(error, EINVAL,
1601 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1602 NULL, "No queues configured");
1603 for (i = 0; i != rss->queue_num; ++i) {
1604 struct mlx5_rxq_ctrl *rxq_ctrl;
1606 if (rss->queue[i] >= priv->rxqs_n)
1607 return rte_flow_error_set
1609 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1610 &rss->queue[i], "queue index out of range");
1611 if (!(*priv->rxqs)[rss->queue[i]])
1612 return rte_flow_error_set
1613 (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1614 &rss->queue[i], "queue is not configured");
1615 rxq_ctrl = container_of((*priv->rxqs)[rss->queue[i]],
1616 struct mlx5_rxq_ctrl, rxq);
1618 rxq_type = rxq_ctrl->type;
1619 if (rxq_type != rxq_ctrl->type)
1620 return rte_flow_error_set
1621 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1623 "combining hairpin and regular RSS queues is not supported");
1629 * Validate the rss action.
1632 * Pointer to the queue action.
1633 * @param[in] action_flags
1634 * Bit-fields that holds the actions detected until now.
1636 * Pointer to the Ethernet device structure.
1638 * Attributes of flow that includes this action.
1639 * @param[in] item_flags
1640 * Items that were detected.
1642 * Pointer to error structure.
1645 * 0 on success, a negative errno value otherwise and rte_errno is set.
1648 mlx5_flow_validate_action_rss(const struct rte_flow_action *action,
1649 uint64_t action_flags,
1650 struct rte_eth_dev *dev,
1651 const struct rte_flow_attr *attr,
1652 uint64_t item_flags,
1653 struct rte_flow_error *error)
1655 const struct rte_flow_action_rss *rss = action->conf;
1656 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1659 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
1660 return rte_flow_error_set(error, EINVAL,
1661 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1662 "can't have 2 fate actions"
1664 ret = mlx5_validate_action_rss(dev, action, error);
1668 return rte_flow_error_set(error, ENOTSUP,
1669 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1670 "rss action not supported for "
1672 if (rss->level > 1 && !tunnel)
1673 return rte_flow_error_set(error, EINVAL,
1674 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1675 "inner RSS is not supported for "
1676 "non-tunnel flows");
1677 if ((item_flags & MLX5_FLOW_LAYER_ECPRI) &&
1678 !(item_flags & MLX5_FLOW_LAYER_INNER_L4_UDP)) {
1679 return rte_flow_error_set(error, EINVAL,
1680 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1681 "RSS on eCPRI is not supported now");
1683 if ((item_flags & MLX5_FLOW_LAYER_MPLS) &&
1685 (MLX5_FLOW_LAYER_INNER_L2 | MLX5_FLOW_LAYER_INNER_L3)) &&
1687 return rte_flow_error_set(error, EINVAL,
1688 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
1689 "MPLS inner RSS needs to specify inner L2/L3 items after MPLS in pattern");
1694 * Validate the default miss action.
1696 * @param[in] action_flags
1697 * Bit-fields that holds the actions detected until now.
1699 * Pointer to error structure.
1702 * 0 on success, a negative errno value otherwise and rte_errno is set.
1705 mlx5_flow_validate_action_default_miss(uint64_t action_flags,
1706 const struct rte_flow_attr *attr,
1707 struct rte_flow_error *error)
1709 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
1710 return rte_flow_error_set(error, EINVAL,
1711 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1712 "can't have 2 fate actions in"
1715 return rte_flow_error_set(error, ENOTSUP,
1716 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1717 "default miss action not supported "
1720 return rte_flow_error_set(error, ENOTSUP,
1721 RTE_FLOW_ERROR_TYPE_ATTR_GROUP, NULL,
1722 "only group 0 is supported");
1724 return rte_flow_error_set(error, ENOTSUP,
1725 RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
1726 NULL, "transfer is not supported");
1731 * Validate the count action.
1734 * Pointer to the Ethernet device structure.
1736 * Attributes of flow that includes this action.
1738 * Pointer to error structure.
1741 * 0 on success, a negative errno value otherwise and rte_errno is set.
1744 mlx5_flow_validate_action_count(struct rte_eth_dev *dev __rte_unused,
1745 const struct rte_flow_attr *attr,
1746 struct rte_flow_error *error)
1749 return rte_flow_error_set(error, ENOTSUP,
1750 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1751 "count action not supported for "
1757 * Validate the ASO CT action.
1760 * Pointer to the Ethernet device structure.
1761 * @param[in] conntrack
1762 * Pointer to the CT action profile.
1764 * Pointer to error structure.
1767 * 0 on success, a negative errno value otherwise and rte_errno is set.
1770 mlx5_validate_action_ct(struct rte_eth_dev *dev,
1771 const struct rte_flow_action_conntrack *conntrack,
1772 struct rte_flow_error *error)
1776 if (conntrack->state > RTE_FLOW_CONNTRACK_STATE_TIME_WAIT)
1777 return rte_flow_error_set(error, EINVAL,
1778 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1779 "Invalid CT state");
1780 if (conntrack->last_index > RTE_FLOW_CONNTRACK_FLAG_RST)
1781 return rte_flow_error_set(error, EINVAL,
1782 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1783 "Invalid last TCP packet flag");
1788 * Verify the @p attributes will be correctly understood by the NIC and store
1789 * them in the @p flow if everything is correct.
1792 * Pointer to the Ethernet device structure.
1793 * @param[in] attributes
1794 * Pointer to flow attributes
1796 * Pointer to error structure.
1799 * 0 on success, a negative errno value otherwise and rte_errno is set.
1802 mlx5_flow_validate_attributes(struct rte_eth_dev *dev,
1803 const struct rte_flow_attr *attributes,
1804 struct rte_flow_error *error)
1806 struct mlx5_priv *priv = dev->data->dev_private;
1807 uint32_t priority_max = priv->config.flow_prio - 1;
1809 if (attributes->group)
1810 return rte_flow_error_set(error, ENOTSUP,
1811 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
1812 NULL, "groups is not supported");
1813 if (attributes->priority != MLX5_FLOW_LOWEST_PRIO_INDICATOR &&
1814 attributes->priority >= priority_max)
1815 return rte_flow_error_set(error, ENOTSUP,
1816 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
1817 NULL, "priority out of range");
1818 if (attributes->egress)
1819 return rte_flow_error_set(error, ENOTSUP,
1820 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1821 "egress is not supported");
1822 if (attributes->transfer && !priv->config.dv_esw_en)
1823 return rte_flow_error_set(error, ENOTSUP,
1824 RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
1825 NULL, "transfer is not supported");
1826 if (!attributes->ingress)
1827 return rte_flow_error_set(error, EINVAL,
1828 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
1830 "ingress attribute is mandatory");
1835 * Validate ICMP6 item.
1838 * Item specification.
1839 * @param[in] item_flags
1840 * Bit-fields that holds the items detected until now.
1841 * @param[in] ext_vlan_sup
1842 * Whether extended VLAN features are supported or not.
1844 * Pointer to error structure.
1847 * 0 on success, a negative errno value otherwise and rte_errno is set.
1850 mlx5_flow_validate_item_icmp6(const struct rte_flow_item *item,
1851 uint64_t item_flags,
1852 uint8_t target_protocol,
1853 struct rte_flow_error *error)
1855 const struct rte_flow_item_icmp6 *mask = item->mask;
1856 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1857 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
1858 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
1859 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1860 MLX5_FLOW_LAYER_OUTER_L4;
1863 if (target_protocol != 0xFF && target_protocol != IPPROTO_ICMPV6)
1864 return rte_flow_error_set(error, EINVAL,
1865 RTE_FLOW_ERROR_TYPE_ITEM, item,
1866 "protocol filtering not compatible"
1867 " with ICMP6 layer");
1868 if (!(item_flags & l3m))
1869 return rte_flow_error_set(error, EINVAL,
1870 RTE_FLOW_ERROR_TYPE_ITEM, item,
1871 "IPv6 is mandatory to filter on"
1873 if (item_flags & l4m)
1874 return rte_flow_error_set(error, EINVAL,
1875 RTE_FLOW_ERROR_TYPE_ITEM, item,
1876 "multiple L4 layers not supported");
1878 mask = &rte_flow_item_icmp6_mask;
1879 ret = mlx5_flow_item_acceptable
1880 (item, (const uint8_t *)mask,
1881 (const uint8_t *)&rte_flow_item_icmp6_mask,
1882 sizeof(struct rte_flow_item_icmp6),
1883 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
1890 * Validate ICMP item.
1893 * Item specification.
1894 * @param[in] item_flags
1895 * Bit-fields that holds the items detected until now.
1897 * Pointer to error structure.
1900 * 0 on success, a negative errno value otherwise and rte_errno is set.
1903 mlx5_flow_validate_item_icmp(const struct rte_flow_item *item,
1904 uint64_t item_flags,
1905 uint8_t target_protocol,
1906 struct rte_flow_error *error)
1908 const struct rte_flow_item_icmp *mask = item->mask;
1909 const struct rte_flow_item_icmp nic_mask = {
1910 .hdr.icmp_type = 0xff,
1911 .hdr.icmp_code = 0xff,
1912 .hdr.icmp_ident = RTE_BE16(0xffff),
1913 .hdr.icmp_seq_nb = RTE_BE16(0xffff),
1915 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1916 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
1917 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
1918 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1919 MLX5_FLOW_LAYER_OUTER_L4;
1922 if (target_protocol != 0xFF && target_protocol != IPPROTO_ICMP)
1923 return rte_flow_error_set(error, EINVAL,
1924 RTE_FLOW_ERROR_TYPE_ITEM, item,
1925 "protocol filtering not compatible"
1926 " with ICMP layer");
1927 if (!(item_flags & l3m))
1928 return rte_flow_error_set(error, EINVAL,
1929 RTE_FLOW_ERROR_TYPE_ITEM, item,
1930 "IPv4 is mandatory to filter"
1932 if (item_flags & l4m)
1933 return rte_flow_error_set(error, EINVAL,
1934 RTE_FLOW_ERROR_TYPE_ITEM, item,
1935 "multiple L4 layers not supported");
1938 ret = mlx5_flow_item_acceptable
1939 (item, (const uint8_t *)mask,
1940 (const uint8_t *)&nic_mask,
1941 sizeof(struct rte_flow_item_icmp),
1942 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
1949 * Validate Ethernet item.
1952 * Item specification.
1953 * @param[in] item_flags
1954 * Bit-fields that holds the items detected until now.
1956 * Pointer to error structure.
1959 * 0 on success, a negative errno value otherwise and rte_errno is set.
1962 mlx5_flow_validate_item_eth(const struct rte_flow_item *item,
1963 uint64_t item_flags, bool ext_vlan_sup,
1964 struct rte_flow_error *error)
1966 const struct rte_flow_item_eth *mask = item->mask;
1967 const struct rte_flow_item_eth nic_mask = {
1968 .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
1969 .src.addr_bytes = "\xff\xff\xff\xff\xff\xff",
1970 .type = RTE_BE16(0xffff),
1971 .has_vlan = ext_vlan_sup ? 1 : 0,
1974 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1975 const uint64_t ethm = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
1976 MLX5_FLOW_LAYER_OUTER_L2;
1978 if (item_flags & ethm)
1979 return rte_flow_error_set(error, ENOTSUP,
1980 RTE_FLOW_ERROR_TYPE_ITEM, item,
1981 "multiple L2 layers not supported");
1982 if ((!tunnel && (item_flags & MLX5_FLOW_LAYER_OUTER_L3)) ||
1983 (tunnel && (item_flags & MLX5_FLOW_LAYER_INNER_L3)))
1984 return rte_flow_error_set(error, EINVAL,
1985 RTE_FLOW_ERROR_TYPE_ITEM, item,
1986 "L2 layer should not follow "
1988 if ((!tunnel && (item_flags & MLX5_FLOW_LAYER_OUTER_VLAN)) ||
1989 (tunnel && (item_flags & MLX5_FLOW_LAYER_INNER_VLAN)))
1990 return rte_flow_error_set(error, EINVAL,
1991 RTE_FLOW_ERROR_TYPE_ITEM, item,
1992 "L2 layer should not follow VLAN");
1994 mask = &rte_flow_item_eth_mask;
1995 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1996 (const uint8_t *)&nic_mask,
1997 sizeof(struct rte_flow_item_eth),
1998 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2003 * Validate VLAN item.
2006 * Item specification.
2007 * @param[in] item_flags
2008 * Bit-fields that holds the items detected until now.
2010 * Ethernet device flow is being created on.
2012 * Pointer to error structure.
2015 * 0 on success, a negative errno value otherwise and rte_errno is set.
2018 mlx5_flow_validate_item_vlan(const struct rte_flow_item *item,
2019 uint64_t item_flags,
2020 struct rte_eth_dev *dev,
2021 struct rte_flow_error *error)
2023 const struct rte_flow_item_vlan *spec = item->spec;
2024 const struct rte_flow_item_vlan *mask = item->mask;
2025 const struct rte_flow_item_vlan nic_mask = {
2026 .tci = RTE_BE16(UINT16_MAX),
2027 .inner_type = RTE_BE16(UINT16_MAX),
2029 uint16_t vlan_tag = 0;
2030 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2032 const uint64_t l34m = tunnel ? (MLX5_FLOW_LAYER_INNER_L3 |
2033 MLX5_FLOW_LAYER_INNER_L4) :
2034 (MLX5_FLOW_LAYER_OUTER_L3 |
2035 MLX5_FLOW_LAYER_OUTER_L4);
2036 const uint64_t vlanm = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
2037 MLX5_FLOW_LAYER_OUTER_VLAN;
2039 if (item_flags & vlanm)
2040 return rte_flow_error_set(error, EINVAL,
2041 RTE_FLOW_ERROR_TYPE_ITEM, item,
2042 "multiple VLAN layers not supported");
2043 else if ((item_flags & l34m) != 0)
2044 return rte_flow_error_set(error, EINVAL,
2045 RTE_FLOW_ERROR_TYPE_ITEM, item,
2046 "VLAN cannot follow L3/L4 layer");
2048 mask = &rte_flow_item_vlan_mask;
2049 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2050 (const uint8_t *)&nic_mask,
2051 sizeof(struct rte_flow_item_vlan),
2052 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2055 if (!tunnel && mask->tci != RTE_BE16(0x0fff)) {
2056 struct mlx5_priv *priv = dev->data->dev_private;
2058 if (priv->vmwa_context) {
2060 * Non-NULL context means we have a virtual machine
2061 * and SR-IOV enabled, we have to create VLAN interface
2062 * to make hypervisor to setup E-Switch vport
2063 * context correctly. We avoid creating the multiple
2064 * VLAN interfaces, so we cannot support VLAN tag mask.
2066 return rte_flow_error_set(error, EINVAL,
2067 RTE_FLOW_ERROR_TYPE_ITEM,
2069 "VLAN tag mask is not"
2070 " supported in virtual"
2075 vlan_tag = spec->tci;
2076 vlan_tag &= mask->tci;
2079 * From verbs perspective an empty VLAN is equivalent
2080 * to a packet without VLAN layer.
2083 return rte_flow_error_set(error, EINVAL,
2084 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
2086 "VLAN cannot be empty");
2091 * Validate IPV4 item.
2094 * Item specification.
2095 * @param[in] item_flags
2096 * Bit-fields that holds the items detected until now.
2097 * @param[in] last_item
2098 * Previous validated item in the pattern items.
2099 * @param[in] ether_type
2100 * Type in the ethernet layer header (including dot1q).
2101 * @param[in] acc_mask
2102 * Acceptable mask, if NULL default internal default mask
2103 * will be used to check whether item fields are supported.
2104 * @param[in] range_accepted
2105 * True if range of values is accepted for specific fields, false otherwise.
2107 * Pointer to error structure.
2110 * 0 on success, a negative errno value otherwise and rte_errno is set.
2113 mlx5_flow_validate_item_ipv4(const struct rte_flow_item *item,
2114 uint64_t item_flags,
2116 uint16_t ether_type,
2117 const struct rte_flow_item_ipv4 *acc_mask,
2118 bool range_accepted,
2119 struct rte_flow_error *error)
2121 const struct rte_flow_item_ipv4 *mask = item->mask;
2122 const struct rte_flow_item_ipv4 *spec = item->spec;
2123 const struct rte_flow_item_ipv4 nic_mask = {
2125 .src_addr = RTE_BE32(0xffffffff),
2126 .dst_addr = RTE_BE32(0xffffffff),
2127 .type_of_service = 0xff,
2128 .next_proto_id = 0xff,
2131 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2132 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2133 MLX5_FLOW_LAYER_OUTER_L3;
2134 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2135 MLX5_FLOW_LAYER_OUTER_L4;
2137 uint8_t next_proto = 0xFF;
2138 const uint64_t l2_vlan = (MLX5_FLOW_LAYER_L2 |
2139 MLX5_FLOW_LAYER_OUTER_VLAN |
2140 MLX5_FLOW_LAYER_INNER_VLAN);
2142 if ((last_item & l2_vlan) && ether_type &&
2143 ether_type != RTE_ETHER_TYPE_IPV4)
2144 return rte_flow_error_set(error, EINVAL,
2145 RTE_FLOW_ERROR_TYPE_ITEM, item,
2146 "IPv4 cannot follow L2/VLAN layer "
2147 "which ether type is not IPv4");
2148 if (item_flags & MLX5_FLOW_LAYER_TUNNEL) {
2150 next_proto = mask->hdr.next_proto_id &
2151 spec->hdr.next_proto_id;
2152 if (next_proto == IPPROTO_IPIP || next_proto == IPPROTO_IPV6)
2153 return rte_flow_error_set(error, EINVAL,
2154 RTE_FLOW_ERROR_TYPE_ITEM,
2159 if (item_flags & MLX5_FLOW_LAYER_IPV6_ENCAP)
2160 return rte_flow_error_set(error, EINVAL,
2161 RTE_FLOW_ERROR_TYPE_ITEM, item,
2162 "wrong tunnel type - IPv6 specified "
2163 "but IPv4 item provided");
2164 if (item_flags & l3m)
2165 return rte_flow_error_set(error, ENOTSUP,
2166 RTE_FLOW_ERROR_TYPE_ITEM, item,
2167 "multiple L3 layers not supported");
2168 else if (item_flags & l4m)
2169 return rte_flow_error_set(error, EINVAL,
2170 RTE_FLOW_ERROR_TYPE_ITEM, item,
2171 "L3 cannot follow an L4 layer.");
2172 else if ((item_flags & MLX5_FLOW_LAYER_NVGRE) &&
2173 !(item_flags & MLX5_FLOW_LAYER_INNER_L2))
2174 return rte_flow_error_set(error, EINVAL,
2175 RTE_FLOW_ERROR_TYPE_ITEM, item,
2176 "L3 cannot follow an NVGRE layer.");
2178 mask = &rte_flow_item_ipv4_mask;
2179 else if (mask->hdr.next_proto_id != 0 &&
2180 mask->hdr.next_proto_id != 0xff)
2181 return rte_flow_error_set(error, EINVAL,
2182 RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
2183 "partial mask is not supported"
2185 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2186 acc_mask ? (const uint8_t *)acc_mask
2187 : (const uint8_t *)&nic_mask,
2188 sizeof(struct rte_flow_item_ipv4),
2189 range_accepted, error);
2196 * Validate IPV6 item.
2199 * Item specification.
2200 * @param[in] item_flags
2201 * Bit-fields that holds the items detected until now.
2202 * @param[in] last_item
2203 * Previous validated item in the pattern items.
2204 * @param[in] ether_type
2205 * Type in the ethernet layer header (including dot1q).
2206 * @param[in] acc_mask
2207 * Acceptable mask, if NULL default internal default mask
2208 * will be used to check whether item fields are supported.
2210 * Pointer to error structure.
2213 * 0 on success, a negative errno value otherwise and rte_errno is set.
2216 mlx5_flow_validate_item_ipv6(const struct rte_flow_item *item,
2217 uint64_t item_flags,
2219 uint16_t ether_type,
2220 const struct rte_flow_item_ipv6 *acc_mask,
2221 struct rte_flow_error *error)
2223 const struct rte_flow_item_ipv6 *mask = item->mask;
2224 const struct rte_flow_item_ipv6 *spec = item->spec;
2225 const struct rte_flow_item_ipv6 nic_mask = {
2228 "\xff\xff\xff\xff\xff\xff\xff\xff"
2229 "\xff\xff\xff\xff\xff\xff\xff\xff",
2231 "\xff\xff\xff\xff\xff\xff\xff\xff"
2232 "\xff\xff\xff\xff\xff\xff\xff\xff",
2233 .vtc_flow = RTE_BE32(0xffffffff),
2237 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2238 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2239 MLX5_FLOW_LAYER_OUTER_L3;
2240 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2241 MLX5_FLOW_LAYER_OUTER_L4;
2243 uint8_t next_proto = 0xFF;
2244 const uint64_t l2_vlan = (MLX5_FLOW_LAYER_L2 |
2245 MLX5_FLOW_LAYER_OUTER_VLAN |
2246 MLX5_FLOW_LAYER_INNER_VLAN);
2248 if ((last_item & l2_vlan) && ether_type &&
2249 ether_type != RTE_ETHER_TYPE_IPV6)
2250 return rte_flow_error_set(error, EINVAL,
2251 RTE_FLOW_ERROR_TYPE_ITEM, item,
2252 "IPv6 cannot follow L2/VLAN layer "
2253 "which ether type is not IPv6");
2254 if (mask && mask->hdr.proto == UINT8_MAX && spec)
2255 next_proto = spec->hdr.proto;
2256 if (item_flags & MLX5_FLOW_LAYER_TUNNEL) {
2257 if (next_proto == IPPROTO_IPIP || next_proto == IPPROTO_IPV6)
2258 return rte_flow_error_set(error, EINVAL,
2259 RTE_FLOW_ERROR_TYPE_ITEM,
2264 if (next_proto == IPPROTO_HOPOPTS ||
2265 next_proto == IPPROTO_ROUTING ||
2266 next_proto == IPPROTO_FRAGMENT ||
2267 next_proto == IPPROTO_ESP ||
2268 next_proto == IPPROTO_AH ||
2269 next_proto == IPPROTO_DSTOPTS)
2270 return rte_flow_error_set(error, EINVAL,
2271 RTE_FLOW_ERROR_TYPE_ITEM, item,
2272 "IPv6 proto (next header) should "
2273 "not be set as extension header");
2274 if (item_flags & MLX5_FLOW_LAYER_IPIP)
2275 return rte_flow_error_set(error, EINVAL,
2276 RTE_FLOW_ERROR_TYPE_ITEM, item,
2277 "wrong tunnel type - IPv4 specified "
2278 "but IPv6 item provided");
2279 if (item_flags & l3m)
2280 return rte_flow_error_set(error, ENOTSUP,
2281 RTE_FLOW_ERROR_TYPE_ITEM, item,
2282 "multiple L3 layers not supported");
2283 else if (item_flags & l4m)
2284 return rte_flow_error_set(error, EINVAL,
2285 RTE_FLOW_ERROR_TYPE_ITEM, item,
2286 "L3 cannot follow an L4 layer.");
2287 else if ((item_flags & MLX5_FLOW_LAYER_NVGRE) &&
2288 !(item_flags & MLX5_FLOW_LAYER_INNER_L2))
2289 return rte_flow_error_set(error, EINVAL,
2290 RTE_FLOW_ERROR_TYPE_ITEM, item,
2291 "L3 cannot follow an NVGRE layer.");
2293 mask = &rte_flow_item_ipv6_mask;
2294 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2295 acc_mask ? (const uint8_t *)acc_mask
2296 : (const uint8_t *)&nic_mask,
2297 sizeof(struct rte_flow_item_ipv6),
2298 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2305 * Validate UDP item.
2308 * Item specification.
2309 * @param[in] item_flags
2310 * Bit-fields that holds the items detected until now.
2311 * @param[in] target_protocol
2312 * The next protocol in the previous item.
2313 * @param[in] flow_mask
2314 * mlx5 flow-specific (DV, verbs, etc.) supported header fields mask.
2316 * Pointer to error structure.
2319 * 0 on success, a negative errno value otherwise and rte_errno is set.
2322 mlx5_flow_validate_item_udp(const struct rte_flow_item *item,
2323 uint64_t item_flags,
2324 uint8_t target_protocol,
2325 struct rte_flow_error *error)
2327 const struct rte_flow_item_udp *mask = item->mask;
2328 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2329 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2330 MLX5_FLOW_LAYER_OUTER_L3;
2331 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2332 MLX5_FLOW_LAYER_OUTER_L4;
2335 if (target_protocol != 0xff && target_protocol != IPPROTO_UDP)
2336 return rte_flow_error_set(error, EINVAL,
2337 RTE_FLOW_ERROR_TYPE_ITEM, item,
2338 "protocol filtering not compatible"
2340 if (!(item_flags & l3m))
2341 return rte_flow_error_set(error, EINVAL,
2342 RTE_FLOW_ERROR_TYPE_ITEM, item,
2343 "L3 is mandatory to filter on L4");
2344 if (item_flags & l4m)
2345 return rte_flow_error_set(error, EINVAL,
2346 RTE_FLOW_ERROR_TYPE_ITEM, item,
2347 "multiple L4 layers not supported");
2349 mask = &rte_flow_item_udp_mask;
2350 ret = mlx5_flow_item_acceptable
2351 (item, (const uint8_t *)mask,
2352 (const uint8_t *)&rte_flow_item_udp_mask,
2353 sizeof(struct rte_flow_item_udp), MLX5_ITEM_RANGE_NOT_ACCEPTED,
2361 * Validate TCP item.
2364 * Item specification.
2365 * @param[in] item_flags
2366 * Bit-fields that holds the items detected until now.
2367 * @param[in] target_protocol
2368 * The next protocol in the previous item.
2370 * Pointer to error structure.
2373 * 0 on success, a negative errno value otherwise and rte_errno is set.
2376 mlx5_flow_validate_item_tcp(const struct rte_flow_item *item,
2377 uint64_t item_flags,
2378 uint8_t target_protocol,
2379 const struct rte_flow_item_tcp *flow_mask,
2380 struct rte_flow_error *error)
2382 const struct rte_flow_item_tcp *mask = item->mask;
2383 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2384 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2385 MLX5_FLOW_LAYER_OUTER_L3;
2386 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2387 MLX5_FLOW_LAYER_OUTER_L4;
2390 MLX5_ASSERT(flow_mask);
2391 if (target_protocol != 0xff && target_protocol != IPPROTO_TCP)
2392 return rte_flow_error_set(error, EINVAL,
2393 RTE_FLOW_ERROR_TYPE_ITEM, item,
2394 "protocol filtering not compatible"
2396 if (!(item_flags & l3m))
2397 return rte_flow_error_set(error, EINVAL,
2398 RTE_FLOW_ERROR_TYPE_ITEM, item,
2399 "L3 is mandatory to filter on L4");
2400 if (item_flags & l4m)
2401 return rte_flow_error_set(error, EINVAL,
2402 RTE_FLOW_ERROR_TYPE_ITEM, item,
2403 "multiple L4 layers not supported");
2405 mask = &rte_flow_item_tcp_mask;
2406 ret = mlx5_flow_item_acceptable
2407 (item, (const uint8_t *)mask,
2408 (const uint8_t *)flow_mask,
2409 sizeof(struct rte_flow_item_tcp), MLX5_ITEM_RANGE_NOT_ACCEPTED,
2417 * Validate VXLAN item.
2420 * Pointer to the Ethernet device structure.
2422 * Item specification.
2423 * @param[in] item_flags
2424 * Bit-fields that holds the items detected until now.
2426 * Flow rule attributes.
2428 * Pointer to error structure.
2431 * 0 on success, a negative errno value otherwise and rte_errno is set.
2434 mlx5_flow_validate_item_vxlan(struct rte_eth_dev *dev,
2435 const struct rte_flow_item *item,
2436 uint64_t item_flags,
2437 const struct rte_flow_attr *attr,
2438 struct rte_flow_error *error)
2440 const struct rte_flow_item_vxlan *spec = item->spec;
2441 const struct rte_flow_item_vxlan *mask = item->mask;
2443 struct mlx5_priv *priv = dev->data->dev_private;
2447 } id = { .vlan_id = 0, };
2448 const struct rte_flow_item_vxlan nic_mask = {
2449 .vni = "\xff\xff\xff",
2452 const struct rte_flow_item_vxlan *valid_mask;
2454 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2455 return rte_flow_error_set(error, ENOTSUP,
2456 RTE_FLOW_ERROR_TYPE_ITEM, item,
2457 "multiple tunnel layers not"
2459 valid_mask = &rte_flow_item_vxlan_mask;
2461 * Verify only UDPv4 is present as defined in
2462 * https://tools.ietf.org/html/rfc7348
2464 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2465 return rte_flow_error_set(error, EINVAL,
2466 RTE_FLOW_ERROR_TYPE_ITEM, item,
2467 "no outer UDP layer found");
2469 mask = &rte_flow_item_vxlan_mask;
2470 /* FDB domain & NIC domain non-zero group */
2471 if ((attr->transfer || attr->group) && priv->sh->misc5_cap)
2472 valid_mask = &nic_mask;
2473 /* Group zero in NIC domain */
2474 if (!attr->group && !attr->transfer && priv->sh->tunnel_header_0_1)
2475 valid_mask = &nic_mask;
2476 ret = mlx5_flow_item_acceptable
2477 (item, (const uint8_t *)mask,
2478 (const uint8_t *)valid_mask,
2479 sizeof(struct rte_flow_item_vxlan),
2480 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2484 memcpy(&id.vni[1], spec->vni, 3);
2485 memcpy(&id.vni[1], mask->vni, 3);
2487 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
2488 return rte_flow_error_set(error, ENOTSUP,
2489 RTE_FLOW_ERROR_TYPE_ITEM, item,
2490 "VXLAN tunnel must be fully defined");
2495 * Validate VXLAN_GPE item.
2498 * Item specification.
2499 * @param[in] item_flags
2500 * Bit-fields that holds the items detected until now.
2502 * Pointer to the private data structure.
2503 * @param[in] target_protocol
2504 * The next protocol in the previous item.
2506 * Pointer to error structure.
2509 * 0 on success, a negative errno value otherwise and rte_errno is set.
2512 mlx5_flow_validate_item_vxlan_gpe(const struct rte_flow_item *item,
2513 uint64_t item_flags,
2514 struct rte_eth_dev *dev,
2515 struct rte_flow_error *error)
2517 struct mlx5_priv *priv = dev->data->dev_private;
2518 const struct rte_flow_item_vxlan_gpe *spec = item->spec;
2519 const struct rte_flow_item_vxlan_gpe *mask = item->mask;
2524 } id = { .vlan_id = 0, };
2526 if (!priv->config.l3_vxlan_en)
2527 return rte_flow_error_set(error, ENOTSUP,
2528 RTE_FLOW_ERROR_TYPE_ITEM, item,
2529 "L3 VXLAN is not enabled by device"
2530 " parameter and/or not configured in"
2532 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2533 return rte_flow_error_set(error, ENOTSUP,
2534 RTE_FLOW_ERROR_TYPE_ITEM, item,
2535 "multiple tunnel layers not"
2538 * Verify only UDPv4 is present as defined in
2539 * https://tools.ietf.org/html/rfc7348
2541 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2542 return rte_flow_error_set(error, EINVAL,
2543 RTE_FLOW_ERROR_TYPE_ITEM, item,
2544 "no outer UDP layer found");
2546 mask = &rte_flow_item_vxlan_gpe_mask;
2547 ret = mlx5_flow_item_acceptable
2548 (item, (const uint8_t *)mask,
2549 (const uint8_t *)&rte_flow_item_vxlan_gpe_mask,
2550 sizeof(struct rte_flow_item_vxlan_gpe),
2551 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2556 return rte_flow_error_set(error, ENOTSUP,
2557 RTE_FLOW_ERROR_TYPE_ITEM,
2559 "VxLAN-GPE protocol"
2561 memcpy(&id.vni[1], spec->vni, 3);
2562 memcpy(&id.vni[1], mask->vni, 3);
2564 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
2565 return rte_flow_error_set(error, ENOTSUP,
2566 RTE_FLOW_ERROR_TYPE_ITEM, item,
2567 "VXLAN-GPE tunnel must be fully"
2572 * Validate GRE Key item.
2575 * Item specification.
2576 * @param[in] item_flags
2577 * Bit flags to mark detected items.
2578 * @param[in] gre_item
2579 * Pointer to gre_item
2581 * Pointer to error structure.
2584 * 0 on success, a negative errno value otherwise and rte_errno is set.
2587 mlx5_flow_validate_item_gre_key(const struct rte_flow_item *item,
2588 uint64_t item_flags,
2589 const struct rte_flow_item *gre_item,
2590 struct rte_flow_error *error)
2592 const rte_be32_t *mask = item->mask;
2594 rte_be32_t gre_key_default_mask = RTE_BE32(UINT32_MAX);
2595 const struct rte_flow_item_gre *gre_spec;
2596 const struct rte_flow_item_gre *gre_mask;
2598 if (item_flags & MLX5_FLOW_LAYER_GRE_KEY)
2599 return rte_flow_error_set(error, ENOTSUP,
2600 RTE_FLOW_ERROR_TYPE_ITEM, item,
2601 "Multiple GRE key not support");
2602 if (!(item_flags & MLX5_FLOW_LAYER_GRE))
2603 return rte_flow_error_set(error, ENOTSUP,
2604 RTE_FLOW_ERROR_TYPE_ITEM, item,
2605 "No preceding GRE header");
2606 if (item_flags & MLX5_FLOW_LAYER_INNER)
2607 return rte_flow_error_set(error, ENOTSUP,
2608 RTE_FLOW_ERROR_TYPE_ITEM, item,
2609 "GRE key following a wrong item");
2610 gre_mask = gre_item->mask;
2612 gre_mask = &rte_flow_item_gre_mask;
2613 gre_spec = gre_item->spec;
2614 if (gre_spec && (gre_mask->c_rsvd0_ver & RTE_BE16(0x2000)) &&
2615 !(gre_spec->c_rsvd0_ver & RTE_BE16(0x2000)))
2616 return rte_flow_error_set(error, EINVAL,
2617 RTE_FLOW_ERROR_TYPE_ITEM, item,
2618 "Key bit must be on");
2621 mask = &gre_key_default_mask;
2622 ret = mlx5_flow_item_acceptable
2623 (item, (const uint8_t *)mask,
2624 (const uint8_t *)&gre_key_default_mask,
2625 sizeof(rte_be32_t), MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2630 * Validate GRE item.
2633 * Item specification.
2634 * @param[in] item_flags
2635 * Bit flags to mark detected items.
2636 * @param[in] target_protocol
2637 * The next protocol in the previous item.
2639 * Pointer to error structure.
2642 * 0 on success, a negative errno value otherwise and rte_errno is set.
2645 mlx5_flow_validate_item_gre(const struct rte_flow_item *item,
2646 uint64_t item_flags,
2647 uint8_t target_protocol,
2648 struct rte_flow_error *error)
2650 const struct rte_flow_item_gre *spec __rte_unused = item->spec;
2651 const struct rte_flow_item_gre *mask = item->mask;
2653 const struct rte_flow_item_gre nic_mask = {
2654 .c_rsvd0_ver = RTE_BE16(0xB000),
2655 .protocol = RTE_BE16(UINT16_MAX),
2658 if (target_protocol != 0xff && target_protocol != IPPROTO_GRE)
2659 return rte_flow_error_set(error, EINVAL,
2660 RTE_FLOW_ERROR_TYPE_ITEM, item,
2661 "protocol filtering not compatible"
2662 " with this GRE layer");
2663 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2664 return rte_flow_error_set(error, ENOTSUP,
2665 RTE_FLOW_ERROR_TYPE_ITEM, item,
2666 "multiple tunnel layers not"
2668 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3))
2669 return rte_flow_error_set(error, ENOTSUP,
2670 RTE_FLOW_ERROR_TYPE_ITEM, item,
2671 "L3 Layer is missing");
2673 mask = &rte_flow_item_gre_mask;
2674 ret = mlx5_flow_item_acceptable
2675 (item, (const uint8_t *)mask,
2676 (const uint8_t *)&nic_mask,
2677 sizeof(struct rte_flow_item_gre), MLX5_ITEM_RANGE_NOT_ACCEPTED,
2681 #ifndef HAVE_MLX5DV_DR
2682 #ifndef HAVE_IBV_DEVICE_MPLS_SUPPORT
2683 if (spec && (spec->protocol & mask->protocol))
2684 return rte_flow_error_set(error, ENOTSUP,
2685 RTE_FLOW_ERROR_TYPE_ITEM, item,
2686 "without MPLS support the"
2687 " specification cannot be used for"
2695 * Validate Geneve item.
2698 * Item specification.
2699 * @param[in] itemFlags
2700 * Bit-fields that holds the items detected until now.
2702 * Pointer to the private data structure.
2704 * Pointer to error structure.
2707 * 0 on success, a negative errno value otherwise and rte_errno is set.
2711 mlx5_flow_validate_item_geneve(const struct rte_flow_item *item,
2712 uint64_t item_flags,
2713 struct rte_eth_dev *dev,
2714 struct rte_flow_error *error)
2716 struct mlx5_priv *priv = dev->data->dev_private;
2717 const struct rte_flow_item_geneve *spec = item->spec;
2718 const struct rte_flow_item_geneve *mask = item->mask;
2721 uint8_t opt_len = priv->config.hca_attr.geneve_max_opt_len ?
2722 MLX5_GENEVE_OPT_LEN_1 : MLX5_GENEVE_OPT_LEN_0;
2723 const struct rte_flow_item_geneve nic_mask = {
2724 .ver_opt_len_o_c_rsvd0 = RTE_BE16(0x3f80),
2725 .vni = "\xff\xff\xff",
2726 .protocol = RTE_BE16(UINT16_MAX),
2729 if (!priv->config.hca_attr.tunnel_stateless_geneve_rx)
2730 return rte_flow_error_set(error, ENOTSUP,
2731 RTE_FLOW_ERROR_TYPE_ITEM, item,
2732 "L3 Geneve is not enabled by device"
2733 " parameter and/or not configured in"
2735 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2736 return rte_flow_error_set(error, ENOTSUP,
2737 RTE_FLOW_ERROR_TYPE_ITEM, item,
2738 "multiple tunnel layers not"
2741 * Verify only UDPv4 is present as defined in
2742 * https://tools.ietf.org/html/rfc7348
2744 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2745 return rte_flow_error_set(error, EINVAL,
2746 RTE_FLOW_ERROR_TYPE_ITEM, item,
2747 "no outer UDP layer found");
2749 mask = &rte_flow_item_geneve_mask;
2750 ret = mlx5_flow_item_acceptable
2751 (item, (const uint8_t *)mask,
2752 (const uint8_t *)&nic_mask,
2753 sizeof(struct rte_flow_item_geneve),
2754 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2758 gbhdr = rte_be_to_cpu_16(spec->ver_opt_len_o_c_rsvd0);
2759 if (MLX5_GENEVE_VER_VAL(gbhdr) ||
2760 MLX5_GENEVE_CRITO_VAL(gbhdr) ||
2761 MLX5_GENEVE_RSVD_VAL(gbhdr) || spec->rsvd1)
2762 return rte_flow_error_set(error, ENOTSUP,
2763 RTE_FLOW_ERROR_TYPE_ITEM,
2765 "Geneve protocol unsupported"
2766 " fields are being used");
2767 if (MLX5_GENEVE_OPTLEN_VAL(gbhdr) > opt_len)
2768 return rte_flow_error_set
2770 RTE_FLOW_ERROR_TYPE_ITEM,
2772 "Unsupported Geneve options length");
2774 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
2775 return rte_flow_error_set
2777 RTE_FLOW_ERROR_TYPE_ITEM, item,
2778 "Geneve tunnel must be fully defined");
2783 * Validate Geneve TLV option item.
2786 * Item specification.
2787 * @param[in] last_item
2788 * Previous validated item in the pattern items.
2789 * @param[in] geneve_item
2790 * Previous GENEVE item specification.
2792 * Pointer to the rte_eth_dev structure.
2794 * Pointer to error structure.
2797 * 0 on success, a negative errno value otherwise and rte_errno is set.
2800 mlx5_flow_validate_item_geneve_opt(const struct rte_flow_item *item,
2802 const struct rte_flow_item *geneve_item,
2803 struct rte_eth_dev *dev,
2804 struct rte_flow_error *error)
2806 struct mlx5_priv *priv = dev->data->dev_private;
2807 struct mlx5_dev_ctx_shared *sh = priv->sh;
2808 struct mlx5_geneve_tlv_option_resource *geneve_opt_resource;
2809 struct mlx5_hca_attr *hca_attr = &priv->config.hca_attr;
2810 uint8_t data_max_supported =
2811 hca_attr->max_geneve_tlv_option_data_len * 4;
2812 struct mlx5_dev_config *config = &priv->config;
2813 const struct rte_flow_item_geneve *geneve_spec;
2814 const struct rte_flow_item_geneve *geneve_mask;
2815 const struct rte_flow_item_geneve_opt *spec = item->spec;
2816 const struct rte_flow_item_geneve_opt *mask = item->mask;
2818 unsigned int data_len;
2819 uint8_t tlv_option_len;
2820 uint16_t optlen_m, optlen_v;
2821 const struct rte_flow_item_geneve_opt full_mask = {
2822 .option_class = RTE_BE16(0xffff),
2823 .option_type = 0xff,
2828 mask = &rte_flow_item_geneve_opt_mask;
2830 return rte_flow_error_set
2831 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2832 "Geneve TLV opt class/type/length must be specified");
2833 if ((uint32_t)spec->option_len > MLX5_GENEVE_OPTLEN_MASK)
2834 return rte_flow_error_set
2835 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2836 "Geneve TLV opt length exceeeds the limit (31)");
2837 /* Check if class type and length masks are full. */
2838 if (full_mask.option_class != mask->option_class ||
2839 full_mask.option_type != mask->option_type ||
2840 full_mask.option_len != (mask->option_len & full_mask.option_len))
2841 return rte_flow_error_set
2842 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2843 "Geneve TLV opt class/type/length masks must be full");
2844 /* Check if length is supported */
2845 if ((uint32_t)spec->option_len >
2846 config->hca_attr.max_geneve_tlv_option_data_len)
2847 return rte_flow_error_set
2848 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2849 "Geneve TLV opt length not supported");
2850 if (config->hca_attr.max_geneve_tlv_options > 1)
2852 "max_geneve_tlv_options supports more than 1 option");
2853 /* Check GENEVE item preceding. */
2854 if (!geneve_item || !(last_item & MLX5_FLOW_LAYER_GENEVE))
2855 return rte_flow_error_set
2856 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2857 "Geneve opt item must be preceded with Geneve item");
2858 geneve_spec = geneve_item->spec;
2859 geneve_mask = geneve_item->mask ? geneve_item->mask :
2860 &rte_flow_item_geneve_mask;
2861 /* Check if GENEVE TLV option size doesn't exceed option length */
2862 if (geneve_spec && (geneve_mask->ver_opt_len_o_c_rsvd0 ||
2863 geneve_spec->ver_opt_len_o_c_rsvd0)) {
2864 tlv_option_len = spec->option_len & mask->option_len;
2865 optlen_v = rte_be_to_cpu_16(geneve_spec->ver_opt_len_o_c_rsvd0);
2866 optlen_v = MLX5_GENEVE_OPTLEN_VAL(optlen_v);
2867 optlen_m = rte_be_to_cpu_16(geneve_mask->ver_opt_len_o_c_rsvd0);
2868 optlen_m = MLX5_GENEVE_OPTLEN_VAL(optlen_m);
2869 if ((optlen_v & optlen_m) <= tlv_option_len)
2870 return rte_flow_error_set
2871 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2872 "GENEVE TLV option length exceeds optlen");
2874 /* Check if length is 0 or data is 0. */
2875 if (spec->data == NULL || spec->option_len == 0)
2876 return rte_flow_error_set
2877 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2878 "Geneve TLV opt with zero data/length not supported");
2879 /* Check not all data & mask are 0. */
2880 data_len = spec->option_len * 4;
2881 if (mask->data == NULL) {
2882 for (i = 0; i < data_len; i++)
2886 return rte_flow_error_set(error, ENOTSUP,
2887 RTE_FLOW_ERROR_TYPE_ITEM, item,
2888 "Can't match on Geneve option data 0");
2890 for (i = 0; i < data_len; i++)
2891 if (spec->data[i] & mask->data[i])
2894 return rte_flow_error_set(error, ENOTSUP,
2895 RTE_FLOW_ERROR_TYPE_ITEM, item,
2896 "Can't match on Geneve option data and mask 0");
2897 /* Check data mask supported. */
2898 for (i = data_max_supported; i < data_len ; i++)
2900 return rte_flow_error_set(error, ENOTSUP,
2901 RTE_FLOW_ERROR_TYPE_ITEM, item,
2902 "Data mask is of unsupported size");
2904 /* Check GENEVE option is supported in NIC. */
2905 if (!config->hca_attr.geneve_tlv_opt)
2906 return rte_flow_error_set
2907 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2908 "Geneve TLV opt not supported");
2909 /* Check if we already have geneve option with different type/class. */
2910 rte_spinlock_lock(&sh->geneve_tlv_opt_sl);
2911 geneve_opt_resource = sh->geneve_tlv_option_resource;
2912 if (geneve_opt_resource != NULL)
2913 if (geneve_opt_resource->option_class != spec->option_class ||
2914 geneve_opt_resource->option_type != spec->option_type ||
2915 geneve_opt_resource->length != spec->option_len) {
2916 rte_spinlock_unlock(&sh->geneve_tlv_opt_sl);
2917 return rte_flow_error_set(error, ENOTSUP,
2918 RTE_FLOW_ERROR_TYPE_ITEM, item,
2919 "Only one Geneve TLV option supported");
2921 rte_spinlock_unlock(&sh->geneve_tlv_opt_sl);
2926 * Validate MPLS item.
2929 * Pointer to the rte_eth_dev structure.
2931 * Item specification.
2932 * @param[in] item_flags
2933 * Bit-fields that holds the items detected until now.
2934 * @param[in] prev_layer
2935 * The protocol layer indicated in previous item.
2937 * Pointer to error structure.
2940 * 0 on success, a negative errno value otherwise and rte_errno is set.
2943 mlx5_flow_validate_item_mpls(struct rte_eth_dev *dev __rte_unused,
2944 const struct rte_flow_item *item __rte_unused,
2945 uint64_t item_flags __rte_unused,
2946 uint64_t prev_layer __rte_unused,
2947 struct rte_flow_error *error)
2949 #ifdef HAVE_IBV_DEVICE_MPLS_SUPPORT
2950 const struct rte_flow_item_mpls *mask = item->mask;
2951 struct mlx5_priv *priv = dev->data->dev_private;
2954 if (!priv->config.mpls_en)
2955 return rte_flow_error_set(error, ENOTSUP,
2956 RTE_FLOW_ERROR_TYPE_ITEM, item,
2957 "MPLS not supported or"
2958 " disabled in firmware"
2960 /* MPLS over UDP, GRE is allowed */
2961 if (!(prev_layer & (MLX5_FLOW_LAYER_OUTER_L4_UDP |
2962 MLX5_FLOW_LAYER_GRE |
2963 MLX5_FLOW_LAYER_GRE_KEY)))
2964 return rte_flow_error_set(error, EINVAL,
2965 RTE_FLOW_ERROR_TYPE_ITEM, item,
2966 "protocol filtering not compatible"
2967 " with MPLS layer");
2968 /* Multi-tunnel isn't allowed but MPLS over GRE is an exception. */
2969 if ((item_flags & MLX5_FLOW_LAYER_TUNNEL) &&
2970 !(item_flags & MLX5_FLOW_LAYER_GRE))
2971 return rte_flow_error_set(error, ENOTSUP,
2972 RTE_FLOW_ERROR_TYPE_ITEM, item,
2973 "multiple tunnel layers not"
2976 mask = &rte_flow_item_mpls_mask;
2977 ret = mlx5_flow_item_acceptable
2978 (item, (const uint8_t *)mask,
2979 (const uint8_t *)&rte_flow_item_mpls_mask,
2980 sizeof(struct rte_flow_item_mpls),
2981 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2986 return rte_flow_error_set(error, ENOTSUP,
2987 RTE_FLOW_ERROR_TYPE_ITEM, item,
2988 "MPLS is not supported by Verbs, please"
2994 * Validate NVGRE item.
2997 * Item specification.
2998 * @param[in] item_flags
2999 * Bit flags to mark detected items.
3000 * @param[in] target_protocol
3001 * The next protocol in the previous item.
3003 * Pointer to error structure.
3006 * 0 on success, a negative errno value otherwise and rte_errno is set.
3009 mlx5_flow_validate_item_nvgre(const struct rte_flow_item *item,
3010 uint64_t item_flags,
3011 uint8_t target_protocol,
3012 struct rte_flow_error *error)
3014 const struct rte_flow_item_nvgre *mask = item->mask;
3017 if (target_protocol != 0xff && target_protocol != IPPROTO_GRE)
3018 return rte_flow_error_set(error, EINVAL,
3019 RTE_FLOW_ERROR_TYPE_ITEM, item,
3020 "protocol filtering not compatible"
3021 " with this GRE layer");
3022 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
3023 return rte_flow_error_set(error, ENOTSUP,
3024 RTE_FLOW_ERROR_TYPE_ITEM, item,
3025 "multiple tunnel layers not"
3027 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3))
3028 return rte_flow_error_set(error, ENOTSUP,
3029 RTE_FLOW_ERROR_TYPE_ITEM, item,
3030 "L3 Layer is missing");
3032 mask = &rte_flow_item_nvgre_mask;
3033 ret = mlx5_flow_item_acceptable
3034 (item, (const uint8_t *)mask,
3035 (const uint8_t *)&rte_flow_item_nvgre_mask,
3036 sizeof(struct rte_flow_item_nvgre),
3037 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
3044 * Validate eCPRI item.
3047 * Item specification.
3048 * @param[in] item_flags
3049 * Bit-fields that holds the items detected until now.
3050 * @param[in] last_item
3051 * Previous validated item in the pattern items.
3052 * @param[in] ether_type
3053 * Type in the ethernet layer header (including dot1q).
3054 * @param[in] acc_mask
3055 * Acceptable mask, if NULL default internal default mask
3056 * will be used to check whether item fields are supported.
3058 * Pointer to error structure.
3061 * 0 on success, a negative errno value otherwise and rte_errno is set.
3064 mlx5_flow_validate_item_ecpri(const struct rte_flow_item *item,
3065 uint64_t item_flags,
3067 uint16_t ether_type,
3068 const struct rte_flow_item_ecpri *acc_mask,
3069 struct rte_flow_error *error)
3071 const struct rte_flow_item_ecpri *mask = item->mask;
3072 const struct rte_flow_item_ecpri nic_mask = {
3076 RTE_BE32(((const struct rte_ecpri_common_hdr) {
3080 .dummy[0] = 0xFFFFFFFF,
3083 const uint64_t outer_l2_vlan = (MLX5_FLOW_LAYER_OUTER_L2 |
3084 MLX5_FLOW_LAYER_OUTER_VLAN);
3085 struct rte_flow_item_ecpri mask_lo;
3087 if (!(last_item & outer_l2_vlan) &&
3088 last_item != MLX5_FLOW_LAYER_OUTER_L4_UDP)
3089 return rte_flow_error_set(error, EINVAL,
3090 RTE_FLOW_ERROR_TYPE_ITEM, item,
3091 "eCPRI can only follow L2/VLAN layer or UDP layer");
3092 if ((last_item & outer_l2_vlan) && ether_type &&
3093 ether_type != RTE_ETHER_TYPE_ECPRI)
3094 return rte_flow_error_set(error, EINVAL,
3095 RTE_FLOW_ERROR_TYPE_ITEM, item,
3096 "eCPRI cannot follow L2/VLAN layer which ether type is not 0xAEFE");
3097 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
3098 return rte_flow_error_set(error, EINVAL,
3099 RTE_FLOW_ERROR_TYPE_ITEM, item,
3100 "eCPRI with tunnel is not supported right now");
3101 if (item_flags & MLX5_FLOW_LAYER_OUTER_L3)
3102 return rte_flow_error_set(error, ENOTSUP,
3103 RTE_FLOW_ERROR_TYPE_ITEM, item,
3104 "multiple L3 layers not supported");
3105 else if (item_flags & MLX5_FLOW_LAYER_OUTER_L4_TCP)
3106 return rte_flow_error_set(error, EINVAL,
3107 RTE_FLOW_ERROR_TYPE_ITEM, item,
3108 "eCPRI cannot coexist with a TCP layer");
3109 /* In specification, eCPRI could be over UDP layer. */
3110 else if (item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP)
3111 return rte_flow_error_set(error, EINVAL,
3112 RTE_FLOW_ERROR_TYPE_ITEM, item,
3113 "eCPRI over UDP layer is not yet supported right now");
3114 /* Mask for type field in common header could be zero. */
3116 mask = &rte_flow_item_ecpri_mask;
3117 mask_lo.hdr.common.u32 = rte_be_to_cpu_32(mask->hdr.common.u32);
3118 /* Input mask is in big-endian format. */
3119 if (mask_lo.hdr.common.type != 0 && mask_lo.hdr.common.type != 0xff)
3120 return rte_flow_error_set(error, EINVAL,
3121 RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
3122 "partial mask is not supported for protocol");
3123 else if (mask_lo.hdr.common.type == 0 && mask->hdr.dummy[0] != 0)
3124 return rte_flow_error_set(error, EINVAL,
3125 RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
3126 "message header mask must be after a type mask");
3127 return mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
3128 acc_mask ? (const uint8_t *)acc_mask
3129 : (const uint8_t *)&nic_mask,
3130 sizeof(struct rte_flow_item_ecpri),
3131 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
3135 flow_null_validate(struct rte_eth_dev *dev __rte_unused,
3136 const struct rte_flow_attr *attr __rte_unused,
3137 const struct rte_flow_item items[] __rte_unused,
3138 const struct rte_flow_action actions[] __rte_unused,
3139 bool external __rte_unused,
3140 int hairpin __rte_unused,
3141 struct rte_flow_error *error)
3143 return rte_flow_error_set(error, ENOTSUP,
3144 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
3147 static struct mlx5_flow *
3148 flow_null_prepare(struct rte_eth_dev *dev __rte_unused,
3149 const struct rte_flow_attr *attr __rte_unused,
3150 const struct rte_flow_item items[] __rte_unused,
3151 const struct rte_flow_action actions[] __rte_unused,
3152 struct rte_flow_error *error)
3154 rte_flow_error_set(error, ENOTSUP,
3155 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
3160 flow_null_translate(struct rte_eth_dev *dev __rte_unused,
3161 struct mlx5_flow *dev_flow __rte_unused,
3162 const struct rte_flow_attr *attr __rte_unused,
3163 const struct rte_flow_item items[] __rte_unused,
3164 const struct rte_flow_action actions[] __rte_unused,
3165 struct rte_flow_error *error)
3167 return rte_flow_error_set(error, ENOTSUP,
3168 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
3172 flow_null_apply(struct rte_eth_dev *dev __rte_unused,
3173 struct rte_flow *flow __rte_unused,
3174 struct rte_flow_error *error)
3176 return rte_flow_error_set(error, ENOTSUP,
3177 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
3181 flow_null_remove(struct rte_eth_dev *dev __rte_unused,
3182 struct rte_flow *flow __rte_unused)
3187 flow_null_destroy(struct rte_eth_dev *dev __rte_unused,
3188 struct rte_flow *flow __rte_unused)
3193 flow_null_query(struct rte_eth_dev *dev __rte_unused,
3194 struct rte_flow *flow __rte_unused,
3195 const struct rte_flow_action *actions __rte_unused,
3196 void *data __rte_unused,
3197 struct rte_flow_error *error)
3199 return rte_flow_error_set(error, ENOTSUP,
3200 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
3204 flow_null_sync_domain(struct rte_eth_dev *dev __rte_unused,
3205 uint32_t domains __rte_unused,
3206 uint32_t flags __rte_unused)
3211 /* Void driver to protect from null pointer reference. */
3212 const struct mlx5_flow_driver_ops mlx5_flow_null_drv_ops = {
3213 .validate = flow_null_validate,
3214 .prepare = flow_null_prepare,
3215 .translate = flow_null_translate,
3216 .apply = flow_null_apply,
3217 .remove = flow_null_remove,
3218 .destroy = flow_null_destroy,
3219 .query = flow_null_query,
3220 .sync_domain = flow_null_sync_domain,
3224 * Select flow driver type according to flow attributes and device
3228 * Pointer to the dev structure.
3230 * Pointer to the flow attributes.
3233 * flow driver type, MLX5_FLOW_TYPE_MAX otherwise.
3235 static enum mlx5_flow_drv_type
3236 flow_get_drv_type(struct rte_eth_dev *dev, const struct rte_flow_attr *attr)
3238 struct mlx5_priv *priv = dev->data->dev_private;
3239 /* The OS can determine first a specific flow type (DV, VERBS) */
3240 enum mlx5_flow_drv_type type = mlx5_flow_os_get_type();
3242 if (type != MLX5_FLOW_TYPE_MAX)
3244 /* If no OS specific type - continue with DV/VERBS selection */
3245 if (attr->transfer && priv->config.dv_esw_en)
3246 type = MLX5_FLOW_TYPE_DV;
3247 if (!attr->transfer)
3248 type = priv->config.dv_flow_en ? MLX5_FLOW_TYPE_DV :
3249 MLX5_FLOW_TYPE_VERBS;
3253 #define flow_get_drv_ops(type) flow_drv_ops[type]
3256 * Flow driver validation API. This abstracts calling driver specific functions.
3257 * The type of flow driver is determined according to flow attributes.
3260 * Pointer to the dev structure.
3262 * Pointer to the flow attributes.
3264 * Pointer to the list of items.
3265 * @param[in] actions
3266 * Pointer to the list of actions.
3267 * @param[in] external
3268 * This flow rule is created by request external to PMD.
3269 * @param[in] hairpin
3270 * Number of hairpin TX actions, 0 means classic flow.
3272 * Pointer to the error structure.
3275 * 0 on success, a negative errno value otherwise and rte_errno is set.
3278 flow_drv_validate(struct rte_eth_dev *dev,
3279 const struct rte_flow_attr *attr,
3280 const struct rte_flow_item items[],
3281 const struct rte_flow_action actions[],
3282 bool external, int hairpin, struct rte_flow_error *error)
3284 const struct mlx5_flow_driver_ops *fops;
3285 enum mlx5_flow_drv_type type = flow_get_drv_type(dev, attr);
3287 fops = flow_get_drv_ops(type);
3288 return fops->validate(dev, attr, items, actions, external,
3293 * Flow driver preparation API. This abstracts calling driver specific
3294 * functions. Parent flow (rte_flow) should have driver type (drv_type). It
3295 * calculates the size of memory required for device flow, allocates the memory,
3296 * initializes the device flow and returns the pointer.
3299 * This function initializes device flow structure such as dv or verbs in
3300 * struct mlx5_flow. However, it is caller's responsibility to initialize the
3301 * rest. For example, adding returning device flow to flow->dev_flow list and
3302 * setting backward reference to the flow should be done out of this function.
3303 * layers field is not filled either.
3306 * Pointer to the dev structure.
3308 * Pointer to the flow attributes.
3310 * Pointer to the list of items.
3311 * @param[in] actions
3312 * Pointer to the list of actions.
3313 * @param[in] flow_idx
3314 * This memory pool index to the flow.
3316 * Pointer to the error structure.
3319 * Pointer to device flow on success, otherwise NULL and rte_errno is set.
3321 static inline struct mlx5_flow *
3322 flow_drv_prepare(struct rte_eth_dev *dev,
3323 const struct rte_flow *flow,
3324 const struct rte_flow_attr *attr,
3325 const struct rte_flow_item items[],
3326 const struct rte_flow_action actions[],
3328 struct rte_flow_error *error)
3330 const struct mlx5_flow_driver_ops *fops;
3331 enum mlx5_flow_drv_type type = flow->drv_type;
3332 struct mlx5_flow *mlx5_flow = NULL;
3334 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3335 fops = flow_get_drv_ops(type);
3336 mlx5_flow = fops->prepare(dev, attr, items, actions, error);
3338 mlx5_flow->flow_idx = flow_idx;
3343 * Flow driver translation API. This abstracts calling driver specific
3344 * functions. Parent flow (rte_flow) should have driver type (drv_type). It
3345 * translates a generic flow into a driver flow. flow_drv_prepare() must
3349 * dev_flow->layers could be filled as a result of parsing during translation
3350 * if needed by flow_drv_apply(). dev_flow->flow->actions can also be filled
3351 * if necessary. As a flow can have multiple dev_flows by RSS flow expansion,
3352 * flow->actions could be overwritten even though all the expanded dev_flows
3353 * have the same actions.
3356 * Pointer to the rte dev structure.
3357 * @param[in, out] dev_flow
3358 * Pointer to the mlx5 flow.
3360 * Pointer to the flow attributes.
3362 * Pointer to the list of items.
3363 * @param[in] actions
3364 * Pointer to the list of actions.
3366 * Pointer to the error structure.
3369 * 0 on success, a negative errno value otherwise and rte_errno is set.
3372 flow_drv_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
3373 const struct rte_flow_attr *attr,
3374 const struct rte_flow_item items[],
3375 const struct rte_flow_action actions[],
3376 struct rte_flow_error *error)
3378 const struct mlx5_flow_driver_ops *fops;
3379 enum mlx5_flow_drv_type type = dev_flow->flow->drv_type;
3381 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3382 fops = flow_get_drv_ops(type);
3383 return fops->translate(dev, dev_flow, attr, items, actions, error);
3387 * Flow driver apply API. This abstracts calling driver specific functions.
3388 * Parent flow (rte_flow) should have driver type (drv_type). It applies
3389 * translated driver flows on to device. flow_drv_translate() must precede.
3392 * Pointer to Ethernet device structure.
3393 * @param[in, out] flow
3394 * Pointer to flow structure.
3396 * Pointer to error structure.
3399 * 0 on success, a negative errno value otherwise and rte_errno is set.
3402 flow_drv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
3403 struct rte_flow_error *error)
3405 const struct mlx5_flow_driver_ops *fops;
3406 enum mlx5_flow_drv_type type = flow->drv_type;
3408 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3409 fops = flow_get_drv_ops(type);
3410 return fops->apply(dev, flow, error);
3414 * Flow driver destroy API. This abstracts calling driver specific functions.
3415 * Parent flow (rte_flow) should have driver type (drv_type). It removes a flow
3416 * on device and releases resources of the flow.
3419 * Pointer to Ethernet device.
3420 * @param[in, out] flow
3421 * Pointer to flow structure.
3424 flow_drv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
3426 const struct mlx5_flow_driver_ops *fops;
3427 enum mlx5_flow_drv_type type = flow->drv_type;
3429 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3430 fops = flow_get_drv_ops(type);
3431 fops->destroy(dev, flow);
3435 * Flow driver find RSS policy tbl API. This abstracts calling driver
3436 * specific functions. Parent flow (rte_flow) should have driver
3437 * type (drv_type). It will find the RSS policy table that has the rss_desc.
3440 * Pointer to Ethernet device.
3441 * @param[in, out] flow
3442 * Pointer to flow structure.
3444 * Pointer to meter policy table.
3445 * @param[in] rss_desc
3446 * Pointer to rss_desc
3448 static struct mlx5_flow_meter_sub_policy *
3449 flow_drv_meter_sub_policy_rss_prepare(struct rte_eth_dev *dev,
3450 struct rte_flow *flow,
3451 struct mlx5_flow_meter_policy *policy,
3452 struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS])
3454 const struct mlx5_flow_driver_ops *fops;
3455 enum mlx5_flow_drv_type type = flow->drv_type;
3457 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3458 fops = flow_get_drv_ops(type);
3459 return fops->meter_sub_policy_rss_prepare(dev, policy, rss_desc);
3463 * Flow driver color tag rule API. This abstracts calling driver
3464 * specific functions. Parent flow (rte_flow) should have driver
3465 * type (drv_type). It will create the color tag rules in hierarchy meter.
3468 * Pointer to Ethernet device.
3469 * @param[in, out] flow
3470 * Pointer to flow structure.
3472 * Pointer to flow meter structure.
3473 * @param[in] src_port
3474 * The src port this extra rule should use.
3476 * The src port id match item.
3478 * Pointer to error structure.
3481 flow_drv_mtr_hierarchy_rule_create(struct rte_eth_dev *dev,
3482 struct rte_flow *flow,
3483 struct mlx5_flow_meter_info *fm,
3485 const struct rte_flow_item *item,
3486 struct rte_flow_error *error)
3488 const struct mlx5_flow_driver_ops *fops;
3489 enum mlx5_flow_drv_type type = flow->drv_type;
3491 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3492 fops = flow_get_drv_ops(type);
3493 return fops->meter_hierarchy_rule_create(dev, fm,
3494 src_port, item, error);
3498 * Get RSS action from the action list.
3501 * Pointer to Ethernet device.
3502 * @param[in] actions
3503 * Pointer to the list of actions.
3505 * Parent flow structure pointer.
3508 * Pointer to the RSS action if exist, else return NULL.
3510 static const struct rte_flow_action_rss*
3511 flow_get_rss_action(struct rte_eth_dev *dev,
3512 const struct rte_flow_action actions[])
3514 struct mlx5_priv *priv = dev->data->dev_private;
3515 const struct rte_flow_action_rss *rss = NULL;
3517 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3518 switch (actions->type) {
3519 case RTE_FLOW_ACTION_TYPE_RSS:
3520 rss = actions->conf;
3522 case RTE_FLOW_ACTION_TYPE_SAMPLE:
3524 const struct rte_flow_action_sample *sample =
3526 const struct rte_flow_action *act = sample->actions;
3527 for (; act->type != RTE_FLOW_ACTION_TYPE_END; act++)
3528 if (act->type == RTE_FLOW_ACTION_TYPE_RSS)
3532 case RTE_FLOW_ACTION_TYPE_METER:
3535 struct mlx5_flow_meter_info *fm;
3536 struct mlx5_flow_meter_policy *policy;
3537 const struct rte_flow_action_meter *mtr = actions->conf;
3539 fm = mlx5_flow_meter_find(priv, mtr->mtr_id, &mtr_idx);
3540 if (fm && !fm->def_policy) {
3541 policy = mlx5_flow_meter_policy_find(dev,
3542 fm->policy_id, NULL);
3543 MLX5_ASSERT(policy);
3544 if (policy->is_hierarchy) {
3546 mlx5_flow_meter_hierarchy_get_final_policy(dev,
3553 policy->act_cnt[RTE_COLOR_GREEN].rss->conf;
3565 * Get ASO age action by index.
3568 * Pointer to the Ethernet device structure.
3569 * @param[in] age_idx
3570 * Index to the ASO age action.
3573 * The specified ASO age action.
3575 struct mlx5_aso_age_action*
3576 flow_aso_age_get_by_idx(struct rte_eth_dev *dev, uint32_t age_idx)
3578 uint16_t pool_idx = age_idx & UINT16_MAX;
3579 uint16_t offset = (age_idx >> 16) & UINT16_MAX;
3580 struct mlx5_priv *priv = dev->data->dev_private;
3581 struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
3582 struct mlx5_aso_age_pool *pool = mng->pools[pool_idx];
3584 return &pool->actions[offset - 1];
3587 /* maps indirect action to translated direct in some actions array */
3588 struct mlx5_translated_action_handle {
3589 struct rte_flow_action_handle *action; /**< Indirect action handle. */
3590 int index; /**< Index in related array of rte_flow_action. */
3594 * Translates actions of type RTE_FLOW_ACTION_TYPE_INDIRECT to related
3595 * direct action if translation possible.
3596 * This functionality used to run same execution path for both direct and
3597 * indirect actions on flow create. All necessary preparations for indirect
3598 * action handling should be performed on *handle* actions list returned
3602 * Pointer to Ethernet device.
3603 * @param[in] actions
3604 * List of actions to translate.
3605 * @param[out] handle
3606 * List to store translated indirect action object handles.
3607 * @param[in, out] indir_n
3608 * Size of *handle* array. On return should be updated with number of
3609 * indirect actions retrieved from the *actions* list.
3610 * @param[out] translated_actions
3611 * List of actions where all indirect actions were translated to direct
3612 * if possible. NULL if no translation took place.
3614 * Pointer to the error structure.
3617 * 0 on success, a negative errno value otherwise and rte_errno is set.
3620 flow_action_handles_translate(struct rte_eth_dev *dev,
3621 const struct rte_flow_action actions[],
3622 struct mlx5_translated_action_handle *handle,
3624 struct rte_flow_action **translated_actions,
3625 struct rte_flow_error *error)
3627 struct mlx5_priv *priv = dev->data->dev_private;
3628 struct rte_flow_action *translated = NULL;
3629 size_t actions_size;
3632 struct mlx5_translated_action_handle *handle_end = NULL;
3634 for (n = 0; actions[n].type != RTE_FLOW_ACTION_TYPE_END; n++) {
3635 if (actions[n].type != RTE_FLOW_ACTION_TYPE_INDIRECT)
3637 if (copied_n == *indir_n) {
3638 return rte_flow_error_set
3639 (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION_NUM,
3640 NULL, "too many shared actions");
3642 rte_memcpy(&handle[copied_n].action, &actions[n].conf,
3643 sizeof(actions[n].conf));
3644 handle[copied_n].index = n;
3648 *indir_n = copied_n;
3651 actions_size = sizeof(struct rte_flow_action) * n;
3652 translated = mlx5_malloc(MLX5_MEM_ZERO, actions_size, 0, SOCKET_ID_ANY);
3657 memcpy(translated, actions, actions_size);
3658 for (handle_end = handle + copied_n; handle < handle_end; handle++) {
3659 struct mlx5_shared_action_rss *shared_rss;
3660 uint32_t act_idx = (uint32_t)(uintptr_t)handle->action;
3661 uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
3662 uint32_t idx = act_idx &
3663 ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
3666 case MLX5_INDIRECT_ACTION_TYPE_RSS:
3667 shared_rss = mlx5_ipool_get
3668 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
3669 translated[handle->index].type =
3670 RTE_FLOW_ACTION_TYPE_RSS;
3671 translated[handle->index].conf =
3672 &shared_rss->origin;
3674 case MLX5_INDIRECT_ACTION_TYPE_COUNT:
3675 translated[handle->index].type =
3676 (enum rte_flow_action_type)
3677 MLX5_RTE_FLOW_ACTION_TYPE_COUNT;
3678 translated[handle->index].conf = (void *)(uintptr_t)idx;
3680 case MLX5_INDIRECT_ACTION_TYPE_AGE:
3681 if (priv->sh->flow_hit_aso_en) {
3682 translated[handle->index].type =
3683 (enum rte_flow_action_type)
3684 MLX5_RTE_FLOW_ACTION_TYPE_AGE;
3685 translated[handle->index].conf =
3686 (void *)(uintptr_t)idx;
3690 case MLX5_INDIRECT_ACTION_TYPE_CT:
3691 if (priv->sh->ct_aso_en) {
3692 translated[handle->index].type =
3693 RTE_FLOW_ACTION_TYPE_CONNTRACK;
3694 translated[handle->index].conf =
3695 (void *)(uintptr_t)idx;
3700 mlx5_free(translated);
3701 return rte_flow_error_set
3702 (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
3703 NULL, "invalid indirect action type");
3706 *translated_actions = translated;
3711 * Get Shared RSS action from the action list.
3714 * Pointer to Ethernet device.
3716 * Pointer to the list of actions.
3717 * @param[in] shared_n
3718 * Actions list length.
3721 * The MLX5 RSS action ID if exists, otherwise return 0.
3724 flow_get_shared_rss_action(struct rte_eth_dev *dev,
3725 struct mlx5_translated_action_handle *handle,
3728 struct mlx5_translated_action_handle *handle_end;
3729 struct mlx5_priv *priv = dev->data->dev_private;
3730 struct mlx5_shared_action_rss *shared_rss;
3733 for (handle_end = handle + shared_n; handle < handle_end; handle++) {
3734 uint32_t act_idx = (uint32_t)(uintptr_t)handle->action;
3735 uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
3736 uint32_t idx = act_idx &
3737 ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
3739 case MLX5_INDIRECT_ACTION_TYPE_RSS:
3740 shared_rss = mlx5_ipool_get
3741 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
3743 __atomic_add_fetch(&shared_rss->refcnt, 1,
3754 find_graph_root(const struct rte_flow_item pattern[], uint32_t rss_level)
3756 const struct rte_flow_item *item;
3757 unsigned int has_vlan = 0;
3759 for (item = pattern; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
3760 if (item->type == RTE_FLOW_ITEM_TYPE_VLAN) {
3766 return rss_level < 2 ? MLX5_EXPANSION_ROOT_ETH_VLAN :
3767 MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN;
3768 return rss_level < 2 ? MLX5_EXPANSION_ROOT :
3769 MLX5_EXPANSION_ROOT_OUTER;
3773 * Get layer flags from the prefix flow.
3775 * Some flows may be split to several subflows, the prefix subflow gets the
3776 * match items and the suffix sub flow gets the actions.
3777 * Some actions need the user defined match item flags to get the detail for
3779 * This function helps the suffix flow to get the item layer flags from prefix
3782 * @param[in] dev_flow
3783 * Pointer the created preifx subflow.
3786 * The layers get from prefix subflow.
3788 static inline uint64_t
3789 flow_get_prefix_layer_flags(struct mlx5_flow *dev_flow)
3791 uint64_t layers = 0;
3794 * Layers bits could be localization, but usually the compiler will
3795 * help to do the optimization work for source code.
3796 * If no decap actions, use the layers directly.
3798 if (!(dev_flow->act_flags & MLX5_FLOW_ACTION_DECAP))
3799 return dev_flow->handle->layers;
3800 /* Convert L3 layers with decap action. */
3801 if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L3_IPV4)
3802 layers |= MLX5_FLOW_LAYER_OUTER_L3_IPV4;
3803 else if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L3_IPV6)
3804 layers |= MLX5_FLOW_LAYER_OUTER_L3_IPV6;
3805 /* Convert L4 layers with decap action. */
3806 if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L4_TCP)
3807 layers |= MLX5_FLOW_LAYER_OUTER_L4_TCP;
3808 else if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L4_UDP)
3809 layers |= MLX5_FLOW_LAYER_OUTER_L4_UDP;
3814 * Get metadata split action information.
3816 * @param[in] actions
3817 * Pointer to the list of actions.
3819 * Pointer to the return pointer.
3820 * @param[out] qrss_type
3821 * Pointer to the action type to return. RTE_FLOW_ACTION_TYPE_END is returned
3822 * if no QUEUE/RSS is found.
3823 * @param[out] encap_idx
3824 * Pointer to the index of the encap action if exists, otherwise the last
3828 * Total number of actions.
3831 flow_parse_metadata_split_actions_info(const struct rte_flow_action actions[],
3832 const struct rte_flow_action **qrss,
3835 const struct rte_flow_action_raw_encap *raw_encap;
3837 int raw_decap_idx = -1;
3840 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3841 switch (actions->type) {
3842 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
3843 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
3844 *encap_idx = actions_n;
3846 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
3847 raw_decap_idx = actions_n;
3849 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
3850 raw_encap = actions->conf;
3851 if (raw_encap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
3852 *encap_idx = raw_decap_idx != -1 ?
3853 raw_decap_idx : actions_n;
3855 case RTE_FLOW_ACTION_TYPE_QUEUE:
3856 case RTE_FLOW_ACTION_TYPE_RSS:
3864 if (*encap_idx == -1)
3865 *encap_idx = actions_n;
3866 /* Count RTE_FLOW_ACTION_TYPE_END. */
3867 return actions_n + 1;
3871 * Check if the action will change packet.
3874 * Pointer to Ethernet device.
3879 * true if action will change packet, false otherwise.
3881 static bool flow_check_modify_action_type(struct rte_eth_dev *dev,
3882 enum rte_flow_action_type type)
3884 struct mlx5_priv *priv = dev->data->dev_private;
3887 case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
3888 case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
3889 case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
3890 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
3891 case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
3892 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
3893 case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
3894 case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
3895 case RTE_FLOW_ACTION_TYPE_DEC_TTL:
3896 case RTE_FLOW_ACTION_TYPE_SET_TTL:
3897 case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
3898 case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
3899 case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
3900 case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
3901 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
3902 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
3903 case RTE_FLOW_ACTION_TYPE_SET_META:
3904 case RTE_FLOW_ACTION_TYPE_SET_TAG:
3905 case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
3906 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
3907 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
3908 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
3909 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
3910 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
3911 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
3912 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
3913 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
3914 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
3915 case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
3917 case RTE_FLOW_ACTION_TYPE_FLAG:
3918 case RTE_FLOW_ACTION_TYPE_MARK:
3919 if (priv->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY)
3929 * Check meter action from the action list.
3932 * Pointer to Ethernet device.
3933 * @param[in] actions
3934 * Pointer to the list of actions.
3935 * @param[out] has_mtr
3936 * Pointer to the meter exist flag.
3937 * @param[out] has_modify
3938 * Pointer to the flag showing there's packet change action.
3939 * @param[out] meter_id
3940 * Pointer to the meter id.
3943 * Total number of actions.
3946 flow_check_meter_action(struct rte_eth_dev *dev,
3947 const struct rte_flow_action actions[],
3948 bool *has_mtr, bool *has_modify, uint32_t *meter_id)
3950 const struct rte_flow_action_meter *mtr = NULL;
3953 MLX5_ASSERT(has_mtr);
3955 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3956 switch (actions->type) {
3957 case RTE_FLOW_ACTION_TYPE_METER:
3958 mtr = actions->conf;
3959 *meter_id = mtr->mtr_id;
3966 *has_modify |= flow_check_modify_action_type(dev,
3970 /* Count RTE_FLOW_ACTION_TYPE_END. */
3971 return actions_n + 1;
3975 * Check if the flow should be split due to hairpin.
3976 * The reason for the split is that in current HW we can't
3977 * support encap and push-vlan on Rx, so if a flow contains
3978 * these actions we move it to Tx.
3981 * Pointer to Ethernet device.
3983 * Flow rule attributes.
3984 * @param[in] actions
3985 * Associated actions (list terminated by the END action).
3988 * > 0 the number of actions and the flow should be split,
3989 * 0 when no split required.
3992 flow_check_hairpin_split(struct rte_eth_dev *dev,
3993 const struct rte_flow_attr *attr,
3994 const struct rte_flow_action actions[])
3996 int queue_action = 0;
3999 const struct rte_flow_action_queue *queue;
4000 const struct rte_flow_action_rss *rss;
4001 const struct rte_flow_action_raw_encap *raw_encap;
4002 const struct rte_eth_hairpin_conf *conf;
4006 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4007 switch (actions->type) {
4008 case RTE_FLOW_ACTION_TYPE_QUEUE:
4009 queue = actions->conf;
4012 conf = mlx5_rxq_get_hairpin_conf(dev, queue->index);
4013 if (conf == NULL || conf->tx_explicit != 0)
4018 case RTE_FLOW_ACTION_TYPE_RSS:
4019 rss = actions->conf;
4020 if (rss == NULL || rss->queue_num == 0)
4022 conf = mlx5_rxq_get_hairpin_conf(dev, rss->queue[0]);
4023 if (conf == NULL || conf->tx_explicit != 0)
4028 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
4029 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
4030 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
4031 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
4032 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
4036 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
4037 raw_encap = actions->conf;
4038 if (raw_encap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
4047 if (split && queue_action)
4052 /* Declare flow create/destroy prototype in advance. */
4054 flow_list_create(struct rte_eth_dev *dev, enum mlx5_flow_type type,
4055 const struct rte_flow_attr *attr,
4056 const struct rte_flow_item items[],
4057 const struct rte_flow_action actions[],
4058 bool external, struct rte_flow_error *error);
4061 flow_list_destroy(struct rte_eth_dev *dev, enum mlx5_flow_type type,
4065 flow_dv_mreg_match_cb(void *tool_ctx __rte_unused,
4066 struct mlx5_list_entry *entry, void *cb_ctx)
4068 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4069 struct mlx5_flow_mreg_copy_resource *mcp_res =
4070 container_of(entry, typeof(*mcp_res), hlist_ent);
4072 return mcp_res->mark_id != *(uint32_t *)(ctx->data);
4075 struct mlx5_list_entry *
4076 flow_dv_mreg_create_cb(void *tool_ctx, void *cb_ctx)
4078 struct rte_eth_dev *dev = tool_ctx;
4079 struct mlx5_priv *priv = dev->data->dev_private;
4080 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4081 struct mlx5_flow_mreg_copy_resource *mcp_res;
4082 struct rte_flow_error *error = ctx->error;
4085 uint32_t mark_id = *(uint32_t *)(ctx->data);
4086 struct rte_flow_attr attr = {
4087 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
4090 struct mlx5_rte_flow_item_tag tag_spec = {
4093 struct rte_flow_item items[] = {
4094 [1] = { .type = RTE_FLOW_ITEM_TYPE_END, },
4096 struct rte_flow_action_mark ftag = {
4099 struct mlx5_flow_action_copy_mreg cp_mreg = {
4103 struct rte_flow_action_jump jump = {
4104 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
4106 struct rte_flow_action actions[] = {
4107 [3] = { .type = RTE_FLOW_ACTION_TYPE_END, },
4110 /* Fill the register fileds in the flow. */
4111 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
4115 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_RX, 0, error);
4119 /* Provide the full width of FLAG specific value. */
4120 if (mark_id == (priv->sh->dv_regc0_mask & MLX5_FLOW_MARK_DEFAULT))
4121 tag_spec.data = MLX5_FLOW_MARK_DEFAULT;
4122 /* Build a new flow. */
4123 if (mark_id != MLX5_DEFAULT_COPY_ID) {
4124 items[0] = (struct rte_flow_item){
4125 .type = (enum rte_flow_item_type)
4126 MLX5_RTE_FLOW_ITEM_TYPE_TAG,
4129 items[1] = (struct rte_flow_item){
4130 .type = RTE_FLOW_ITEM_TYPE_END,
4132 actions[0] = (struct rte_flow_action){
4133 .type = (enum rte_flow_action_type)
4134 MLX5_RTE_FLOW_ACTION_TYPE_MARK,
4137 actions[1] = (struct rte_flow_action){
4138 .type = (enum rte_flow_action_type)
4139 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
4142 actions[2] = (struct rte_flow_action){
4143 .type = RTE_FLOW_ACTION_TYPE_JUMP,
4146 actions[3] = (struct rte_flow_action){
4147 .type = RTE_FLOW_ACTION_TYPE_END,
4150 /* Default rule, wildcard match. */
4151 attr.priority = MLX5_FLOW_LOWEST_PRIO_INDICATOR;
4152 items[0] = (struct rte_flow_item){
4153 .type = RTE_FLOW_ITEM_TYPE_END,
4155 actions[0] = (struct rte_flow_action){
4156 .type = (enum rte_flow_action_type)
4157 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
4160 actions[1] = (struct rte_flow_action){
4161 .type = RTE_FLOW_ACTION_TYPE_JUMP,
4164 actions[2] = (struct rte_flow_action){
4165 .type = RTE_FLOW_ACTION_TYPE_END,
4168 /* Build a new entry. */
4169 mcp_res = mlx5_ipool_zmalloc(priv->sh->ipool[MLX5_IPOOL_MCP], &idx);
4175 mcp_res->mark_id = mark_id;
4177 * The copy Flows are not included in any list. There
4178 * ones are referenced from other Flows and can not
4179 * be applied, removed, deleted in ardbitrary order
4180 * by list traversing.
4182 mcp_res->rix_flow = flow_list_create(dev, MLX5_FLOW_TYPE_MCP,
4183 &attr, items, actions, false, error);
4184 if (!mcp_res->rix_flow) {
4185 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], idx);
4188 return &mcp_res->hlist_ent;
4191 struct mlx5_list_entry *
4192 flow_dv_mreg_clone_cb(void *tool_ctx, struct mlx5_list_entry *oentry,
4193 void *cb_ctx __rte_unused)
4195 struct rte_eth_dev *dev = tool_ctx;
4196 struct mlx5_priv *priv = dev->data->dev_private;
4197 struct mlx5_flow_mreg_copy_resource *mcp_res;
4200 mcp_res = mlx5_ipool_malloc(priv->sh->ipool[MLX5_IPOOL_MCP], &idx);
4205 memcpy(mcp_res, oentry, sizeof(*mcp_res));
4207 return &mcp_res->hlist_ent;
4211 flow_dv_mreg_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
4213 struct mlx5_flow_mreg_copy_resource *mcp_res =
4214 container_of(entry, typeof(*mcp_res), hlist_ent);
4215 struct rte_eth_dev *dev = tool_ctx;
4216 struct mlx5_priv *priv = dev->data->dev_private;
4218 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], mcp_res->idx);
4222 * Add a flow of copying flow metadata registers in RX_CP_TBL.
4224 * As mark_id is unique, if there's already a registered flow for the mark_id,
4225 * return by increasing the reference counter of the resource. Otherwise, create
4226 * the resource (mcp_res) and flow.
4229 * - If ingress port is ANY and reg_c[1] is mark_id,
4230 * flow_tag := mark_id, reg_b := reg_c[0] and jump to RX_ACT_TBL.
4232 * For default flow (zero mark_id), flow is like,
4233 * - If ingress port is ANY,
4234 * reg_b := reg_c[0] and jump to RX_ACT_TBL.
4237 * Pointer to Ethernet device.
4239 * ID of MARK action, zero means default flow for META.
4241 * Perform verbose error reporting if not NULL.
4244 * Associated resource on success, NULL otherwise and rte_errno is set.
4246 static struct mlx5_flow_mreg_copy_resource *
4247 flow_mreg_add_copy_action(struct rte_eth_dev *dev, uint32_t mark_id,
4248 struct rte_flow_error *error)
4250 struct mlx5_priv *priv = dev->data->dev_private;
4251 struct mlx5_list_entry *entry;
4252 struct mlx5_flow_cb_ctx ctx = {
4258 /* Check if already registered. */
4259 MLX5_ASSERT(priv->mreg_cp_tbl);
4260 entry = mlx5_hlist_register(priv->mreg_cp_tbl, mark_id, &ctx);
4263 return container_of(entry, struct mlx5_flow_mreg_copy_resource,
4268 flow_dv_mreg_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
4270 struct mlx5_flow_mreg_copy_resource *mcp_res =
4271 container_of(entry, typeof(*mcp_res), hlist_ent);
4272 struct rte_eth_dev *dev = tool_ctx;
4273 struct mlx5_priv *priv = dev->data->dev_private;
4275 MLX5_ASSERT(mcp_res->rix_flow);
4276 flow_list_destroy(dev, MLX5_FLOW_TYPE_MCP, mcp_res->rix_flow);
4277 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], mcp_res->idx);
4281 * Release flow in RX_CP_TBL.
4284 * Pointer to Ethernet device.
4286 * Parent flow for wich copying is provided.
4289 flow_mreg_del_copy_action(struct rte_eth_dev *dev,
4290 struct rte_flow *flow)
4292 struct mlx5_flow_mreg_copy_resource *mcp_res;
4293 struct mlx5_priv *priv = dev->data->dev_private;
4295 if (!flow->rix_mreg_copy)
4297 mcp_res = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MCP],
4298 flow->rix_mreg_copy);
4299 if (!mcp_res || !priv->mreg_cp_tbl)
4301 MLX5_ASSERT(mcp_res->rix_flow);
4302 mlx5_hlist_unregister(priv->mreg_cp_tbl, &mcp_res->hlist_ent);
4303 flow->rix_mreg_copy = 0;
4307 * Remove the default copy action from RX_CP_TBL.
4309 * This functions is called in the mlx5_dev_start(). No thread safe
4313 * Pointer to Ethernet device.
4316 flow_mreg_del_default_copy_action(struct rte_eth_dev *dev)
4318 struct mlx5_list_entry *entry;
4319 struct mlx5_priv *priv = dev->data->dev_private;
4320 struct mlx5_flow_cb_ctx ctx;
4323 /* Check if default flow is registered. */
4324 if (!priv->mreg_cp_tbl)
4326 mark_id = MLX5_DEFAULT_COPY_ID;
4327 ctx.data = &mark_id;
4328 entry = mlx5_hlist_lookup(priv->mreg_cp_tbl, mark_id, &ctx);
4331 mlx5_hlist_unregister(priv->mreg_cp_tbl, entry);
4335 * Add the default copy action in in RX_CP_TBL.
4337 * This functions is called in the mlx5_dev_start(). No thread safe
4341 * Pointer to Ethernet device.
4343 * Perform verbose error reporting if not NULL.
4346 * 0 for success, negative value otherwise and rte_errno is set.
4349 flow_mreg_add_default_copy_action(struct rte_eth_dev *dev,
4350 struct rte_flow_error *error)
4352 struct mlx5_priv *priv = dev->data->dev_private;
4353 struct mlx5_flow_mreg_copy_resource *mcp_res;
4354 struct mlx5_flow_cb_ctx ctx;
4357 /* Check whether extensive metadata feature is engaged. */
4358 if (!priv->config.dv_flow_en ||
4359 priv->config.dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
4360 !mlx5_flow_ext_mreg_supported(dev) ||
4361 !priv->sh->dv_regc0_mask)
4364 * Add default mreg copy flow may be called multiple time, but
4365 * only be called once in stop. Avoid register it twice.
4367 mark_id = MLX5_DEFAULT_COPY_ID;
4368 ctx.data = &mark_id;
4369 if (mlx5_hlist_lookup(priv->mreg_cp_tbl, mark_id, &ctx))
4371 mcp_res = flow_mreg_add_copy_action(dev, mark_id, error);
4378 * Add a flow of copying flow metadata registers in RX_CP_TBL.
4380 * All the flow having Q/RSS action should be split by
4381 * flow_mreg_split_qrss_prep() to pass by RX_CP_TBL. A flow in the RX_CP_TBL
4382 * performs the following,
4383 * - CQE->flow_tag := reg_c[1] (MARK)
4384 * - CQE->flow_table_metadata (reg_b) := reg_c[0] (META)
4385 * As CQE's flow_tag is not a register, it can't be simply copied from reg_c[1]
4386 * but there should be a flow per each MARK ID set by MARK action.
4388 * For the aforementioned reason, if there's a MARK action in flow's action
4389 * list, a corresponding flow should be added to the RX_CP_TBL in order to copy
4390 * the MARK ID to CQE's flow_tag like,
4391 * - If reg_c[1] is mark_id,
4392 * flow_tag := mark_id, reg_b := reg_c[0] and jump to RX_ACT_TBL.
4394 * For SET_META action which stores value in reg_c[0], as the destination is
4395 * also a flow metadata register (reg_b), adding a default flow is enough. Zero
4396 * MARK ID means the default flow. The default flow looks like,
4397 * - For all flow, reg_b := reg_c[0] and jump to RX_ACT_TBL.
4400 * Pointer to Ethernet device.
4402 * Pointer to flow structure.
4403 * @param[in] actions
4404 * Pointer to the list of actions.
4406 * Perform verbose error reporting if not NULL.
4409 * 0 on success, negative value otherwise and rte_errno is set.
4412 flow_mreg_update_copy_table(struct rte_eth_dev *dev,
4413 struct rte_flow *flow,
4414 const struct rte_flow_action *actions,
4415 struct rte_flow_error *error)
4417 struct mlx5_priv *priv = dev->data->dev_private;
4418 struct mlx5_dev_config *config = &priv->config;
4419 struct mlx5_flow_mreg_copy_resource *mcp_res;
4420 const struct rte_flow_action_mark *mark;
4422 /* Check whether extensive metadata feature is engaged. */
4423 if (!config->dv_flow_en ||
4424 config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
4425 !mlx5_flow_ext_mreg_supported(dev) ||
4426 !priv->sh->dv_regc0_mask)
4428 /* Find MARK action. */
4429 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4430 switch (actions->type) {
4431 case RTE_FLOW_ACTION_TYPE_FLAG:
4432 mcp_res = flow_mreg_add_copy_action
4433 (dev, MLX5_FLOW_MARK_DEFAULT, error);
4436 flow->rix_mreg_copy = mcp_res->idx;
4438 case RTE_FLOW_ACTION_TYPE_MARK:
4439 mark = (const struct rte_flow_action_mark *)
4442 flow_mreg_add_copy_action(dev, mark->id, error);
4445 flow->rix_mreg_copy = mcp_res->idx;
4454 #define MLX5_MAX_SPLIT_ACTIONS 24
4455 #define MLX5_MAX_SPLIT_ITEMS 24
4458 * Split the hairpin flow.
4459 * Since HW can't support encap and push-vlan on Rx, we move these
4461 * If the count action is after the encap then we also
4462 * move the count action. in this case the count will also measure
4466 * Pointer to Ethernet device.
4467 * @param[in] actions
4468 * Associated actions (list terminated by the END action).
4469 * @param[out] actions_rx
4471 * @param[out] actions_tx
4473 * @param[out] pattern_tx
4474 * The pattern items for the Tx flow.
4475 * @param[out] flow_id
4476 * The flow ID connected to this flow.
4482 flow_hairpin_split(struct rte_eth_dev *dev,
4483 const struct rte_flow_action actions[],
4484 struct rte_flow_action actions_rx[],
4485 struct rte_flow_action actions_tx[],
4486 struct rte_flow_item pattern_tx[],
4489 const struct rte_flow_action_raw_encap *raw_encap;
4490 const struct rte_flow_action_raw_decap *raw_decap;
4491 struct mlx5_rte_flow_action_set_tag *set_tag;
4492 struct rte_flow_action *tag_action;
4493 struct mlx5_rte_flow_item_tag *tag_item;
4494 struct rte_flow_item *item;
4498 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4499 switch (actions->type) {
4500 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
4501 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
4502 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
4503 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
4504 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
4505 rte_memcpy(actions_tx, actions,
4506 sizeof(struct rte_flow_action));
4509 case RTE_FLOW_ACTION_TYPE_COUNT:
4511 rte_memcpy(actions_tx, actions,
4512 sizeof(struct rte_flow_action));
4515 rte_memcpy(actions_rx, actions,
4516 sizeof(struct rte_flow_action));
4520 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
4521 raw_encap = actions->conf;
4522 if (raw_encap->size > MLX5_ENCAPSULATION_DECISION_SIZE) {
4523 memcpy(actions_tx, actions,
4524 sizeof(struct rte_flow_action));
4528 rte_memcpy(actions_rx, actions,
4529 sizeof(struct rte_flow_action));
4533 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
4534 raw_decap = actions->conf;
4535 if (raw_decap->size < MLX5_ENCAPSULATION_DECISION_SIZE) {
4536 memcpy(actions_tx, actions,
4537 sizeof(struct rte_flow_action));
4540 rte_memcpy(actions_rx, actions,
4541 sizeof(struct rte_flow_action));
4546 rte_memcpy(actions_rx, actions,
4547 sizeof(struct rte_flow_action));
4552 /* Add set meta action and end action for the Rx flow. */
4553 tag_action = actions_rx;
4554 tag_action->type = (enum rte_flow_action_type)
4555 MLX5_RTE_FLOW_ACTION_TYPE_TAG;
4557 rte_memcpy(actions_rx, actions, sizeof(struct rte_flow_action));
4559 set_tag = (void *)actions_rx;
4560 *set_tag = (struct mlx5_rte_flow_action_set_tag) {
4561 .id = mlx5_flow_get_reg_id(dev, MLX5_HAIRPIN_RX, 0, NULL),
4564 MLX5_ASSERT(set_tag->id > REG_NON);
4565 tag_action->conf = set_tag;
4566 /* Create Tx item list. */
4567 rte_memcpy(actions_tx, actions, sizeof(struct rte_flow_action));
4568 addr = (void *)&pattern_tx[2];
4570 item->type = (enum rte_flow_item_type)
4571 MLX5_RTE_FLOW_ITEM_TYPE_TAG;
4572 tag_item = (void *)addr;
4573 tag_item->data = flow_id;
4574 tag_item->id = mlx5_flow_get_reg_id(dev, MLX5_HAIRPIN_TX, 0, NULL);
4575 MLX5_ASSERT(set_tag->id > REG_NON);
4576 item->spec = tag_item;
4577 addr += sizeof(struct mlx5_rte_flow_item_tag);
4578 tag_item = (void *)addr;
4579 tag_item->data = UINT32_MAX;
4580 tag_item->id = UINT16_MAX;
4581 item->mask = tag_item;
4584 item->type = RTE_FLOW_ITEM_TYPE_END;
4589 * The last stage of splitting chain, just creates the subflow
4590 * without any modification.
4593 * Pointer to Ethernet device.
4595 * Parent flow structure pointer.
4596 * @param[in, out] sub_flow
4597 * Pointer to return the created subflow, may be NULL.
4599 * Flow rule attributes.
4601 * Pattern specification (list terminated by the END pattern item).
4602 * @param[in] actions
4603 * Associated actions (list terminated by the END action).
4604 * @param[in] flow_split_info
4605 * Pointer to flow split info structure.
4607 * Perform verbose error reporting if not NULL.
4609 * 0 on success, negative value otherwise
4612 flow_create_split_inner(struct rte_eth_dev *dev,
4613 struct rte_flow *flow,
4614 struct mlx5_flow **sub_flow,
4615 const struct rte_flow_attr *attr,
4616 const struct rte_flow_item items[],
4617 const struct rte_flow_action actions[],
4618 struct mlx5_flow_split_info *flow_split_info,
4619 struct rte_flow_error *error)
4621 struct mlx5_flow *dev_flow;
4623 dev_flow = flow_drv_prepare(dev, flow, attr, items, actions,
4624 flow_split_info->flow_idx, error);
4627 dev_flow->flow = flow;
4628 dev_flow->external = flow_split_info->external;
4629 dev_flow->skip_scale = flow_split_info->skip_scale;
4630 /* Subflow object was created, we must include one in the list. */
4631 SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
4632 dev_flow->handle, next);
4634 * If dev_flow is as one of the suffix flow, some actions in suffix
4635 * flow may need some user defined item layer flags, and pass the
4636 * Metadate rxq mark flag to suffix flow as well.
4638 if (flow_split_info->prefix_layers)
4639 dev_flow->handle->layers = flow_split_info->prefix_layers;
4640 if (flow_split_info->prefix_mark)
4641 dev_flow->handle->mark = 1;
4643 *sub_flow = dev_flow;
4644 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
4645 dev_flow->dv.table_id = flow_split_info->table_id;
4647 return flow_drv_translate(dev, dev_flow, attr, items, actions, error);
4651 * Get the sub policy of a meter.
4654 * Pointer to Ethernet device.
4656 * Parent flow structure pointer.
4658 * Pointer to thread flow work space.
4660 * Flow rule attributes.
4662 * Pattern specification (list terminated by the END pattern item).
4664 * Perform verbose error reporting if not NULL.
4667 * Pointer to the meter sub policy, NULL otherwise and rte_errno is set.
4669 static struct mlx5_flow_meter_sub_policy *
4670 get_meter_sub_policy(struct rte_eth_dev *dev,
4671 struct rte_flow *flow,
4672 struct mlx5_flow_workspace *wks,
4673 const struct rte_flow_attr *attr,
4674 const struct rte_flow_item items[],
4675 struct rte_flow_error *error)
4677 struct mlx5_flow_meter_policy *policy;
4678 struct mlx5_flow_meter_policy *final_policy;
4679 struct mlx5_flow_meter_sub_policy *sub_policy = NULL;
4681 policy = wks->policy;
4682 final_policy = policy->is_hierarchy ? wks->final_policy : policy;
4683 if (final_policy->is_rss || final_policy->is_queue) {
4684 struct mlx5_flow_rss_desc rss_desc_v[MLX5_MTR_RTE_COLORS];
4685 struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS] = {0};
4689 * This is a tmp dev_flow,
4690 * no need to register any matcher for it in translate.
4692 wks->skip_matcher_reg = 1;
4693 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
4694 struct mlx5_flow dev_flow = {0};
4695 struct mlx5_flow_handle dev_handle = { {0} };
4696 uint8_t fate = final_policy->act_cnt[i].fate_action;
4698 if (fate == MLX5_FLOW_FATE_SHARED_RSS) {
4699 const void *rss_act =
4700 final_policy->act_cnt[i].rss->conf;
4701 struct rte_flow_action rss_actions[2] = {
4703 .type = RTE_FLOW_ACTION_TYPE_RSS,
4707 .type = RTE_FLOW_ACTION_TYPE_END,
4712 dev_flow.handle = &dev_handle;
4713 dev_flow.ingress = attr->ingress;
4714 dev_flow.flow = flow;
4715 dev_flow.external = 0;
4716 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
4717 dev_flow.dv.transfer = attr->transfer;
4720 * Translate RSS action to get rss hash fields.
4722 if (flow_drv_translate(dev, &dev_flow, attr,
4723 items, rss_actions, error))
4725 rss_desc_v[i] = wks->rss_desc;
4726 rss_desc_v[i].key_len = MLX5_RSS_HASH_KEY_LEN;
4727 rss_desc_v[i].hash_fields =
4728 dev_flow.hash_fields;
4729 rss_desc_v[i].queue_num =
4730 rss_desc_v[i].hash_fields ?
4731 rss_desc_v[i].queue_num : 1;
4732 rss_desc_v[i].tunnel =
4733 !!(dev_flow.handle->layers &
4734 MLX5_FLOW_LAYER_TUNNEL);
4735 rss_desc[i] = &rss_desc_v[i];
4736 } else if (fate == MLX5_FLOW_FATE_QUEUE) {
4737 /* This is queue action. */
4738 rss_desc_v[i] = wks->rss_desc;
4739 rss_desc_v[i].key_len = 0;
4740 rss_desc_v[i].hash_fields = 0;
4741 rss_desc_v[i].queue =
4742 &final_policy->act_cnt[i].queue;
4743 rss_desc_v[i].queue_num = 1;
4744 rss_desc[i] = &rss_desc_v[i];
4749 sub_policy = flow_drv_meter_sub_policy_rss_prepare(dev,
4750 flow, policy, rss_desc);
4752 enum mlx5_meter_domain mtr_domain =
4753 attr->transfer ? MLX5_MTR_DOMAIN_TRANSFER :
4754 (attr->egress ? MLX5_MTR_DOMAIN_EGRESS :
4755 MLX5_MTR_DOMAIN_INGRESS);
4756 sub_policy = policy->sub_policys[mtr_domain][0];
4759 rte_flow_error_set(error, EINVAL,
4760 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4761 "Failed to get meter sub-policy.");
4767 * Split the meter flow.
4769 * As meter flow will split to three sub flow, other than meter
4770 * action, the other actions make sense to only meter accepts
4771 * the packet. If it need to be dropped, no other additional
4772 * actions should be take.
4774 * One kind of special action which decapsulates the L3 tunnel
4775 * header will be in the prefix sub flow, as not to take the
4776 * L3 tunnel header into account.
4779 * Pointer to Ethernet device.
4781 * Parent flow structure pointer.
4783 * Pointer to thread flow work space.
4785 * Flow rule attributes.
4787 * Pattern specification (list terminated by the END pattern item).
4788 * @param[out] sfx_items
4789 * Suffix flow match items (list terminated by the END pattern item).
4790 * @param[in] actions
4791 * Associated actions (list terminated by the END action).
4792 * @param[out] actions_sfx
4793 * Suffix flow actions.
4794 * @param[out] actions_pre
4795 * Prefix flow actions.
4796 * @param[out] mtr_flow_id
4797 * Pointer to meter flow id.
4799 * Perform verbose error reporting if not NULL.
4802 * 0 on success, a negative errno value otherwise and rte_errno is set.
4805 flow_meter_split_prep(struct rte_eth_dev *dev,
4806 struct rte_flow *flow,
4807 struct mlx5_flow_workspace *wks,
4808 const struct rte_flow_attr *attr,
4809 const struct rte_flow_item items[],
4810 struct rte_flow_item sfx_items[],
4811 const struct rte_flow_action actions[],
4812 struct rte_flow_action actions_sfx[],
4813 struct rte_flow_action actions_pre[],
4814 uint32_t *mtr_flow_id,
4815 struct rte_flow_error *error)
4817 struct mlx5_priv *priv = dev->data->dev_private;
4818 struct mlx5_flow_meter_info *fm = wks->fm;
4819 struct rte_flow_action *tag_action = NULL;
4820 struct rte_flow_item *tag_item;
4821 struct mlx5_rte_flow_action_set_tag *set_tag;
4822 const struct rte_flow_action_raw_encap *raw_encap;
4823 const struct rte_flow_action_raw_decap *raw_decap;
4824 struct mlx5_rte_flow_item_tag *tag_item_spec;
4825 struct mlx5_rte_flow_item_tag *tag_item_mask;
4826 uint32_t tag_id = 0;
4827 struct rte_flow_item *vlan_item_dst = NULL;
4828 const struct rte_flow_item *vlan_item_src = NULL;
4829 struct rte_flow_action *hw_mtr_action;
4830 struct rte_flow_action *action_pre_head = NULL;
4831 int32_t flow_src_port = priv->representor_id;
4833 uint8_t mtr_id_offset = priv->mtr_reg_share ? MLX5_MTR_COLOR_BITS : 0;
4834 uint8_t mtr_reg_bits = priv->mtr_reg_share ?
4835 MLX5_MTR_IDLE_BITS_IN_COLOR_REG : MLX5_REG_BITS;
4836 uint32_t flow_id = 0;
4837 uint32_t flow_id_reversed = 0;
4838 uint8_t flow_id_bits = 0;
4841 /* Prepare the suffix subflow items. */
4842 tag_item = sfx_items++;
4843 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
4844 struct mlx5_priv *port_priv;
4845 const struct rte_flow_item_port_id *pid_v;
4846 int item_type = items->type;
4848 switch (item_type) {
4849 case RTE_FLOW_ITEM_TYPE_PORT_ID:
4850 pid_v = items->spec;
4852 port_priv = mlx5_port_to_eswitch_info(pid_v->id, false);
4854 return rte_flow_error_set(error,
4856 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
4858 "Failed to get port info.");
4859 flow_src_port = port_priv->representor_id;
4860 if (!fm->def_policy && wks->policy->is_hierarchy &&
4861 flow_src_port != priv->representor_id) {
4862 if (flow_drv_mtr_hierarchy_rule_create(dev,
4869 memcpy(sfx_items, items, sizeof(*sfx_items));
4872 case RTE_FLOW_ITEM_TYPE_VLAN:
4873 /* Determine if copy vlan item below. */
4874 vlan_item_src = items;
4875 vlan_item_dst = sfx_items++;
4876 vlan_item_dst->type = RTE_FLOW_ITEM_TYPE_VOID;
4882 sfx_items->type = RTE_FLOW_ITEM_TYPE_END;
4884 mtr_first = priv->sh->meter_aso_en &&
4885 (attr->egress || (attr->transfer && flow_src_port != UINT16_MAX));
4886 /* For ASO meter, meter must be before tag in TX direction. */
4888 action_pre_head = actions_pre++;
4889 /* Leave space for tag action. */
4890 tag_action = actions_pre++;
4892 /* Prepare the actions for prefix and suffix flow. */
4893 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4894 struct rte_flow_action *action_cur = NULL;
4896 switch (actions->type) {
4897 case RTE_FLOW_ACTION_TYPE_METER:
4899 action_cur = action_pre_head;
4901 /* Leave space for tag action. */
4902 tag_action = actions_pre++;
4903 action_cur = actions_pre++;
4906 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
4907 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
4908 action_cur = actions_pre++;
4910 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
4911 raw_encap = actions->conf;
4912 if (raw_encap->size < MLX5_ENCAPSULATION_DECISION_SIZE)
4913 action_cur = actions_pre++;
4915 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
4916 raw_decap = actions->conf;
4917 if (raw_decap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
4918 action_cur = actions_pre++;
4920 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
4921 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
4922 if (vlan_item_dst && vlan_item_src) {
4923 memcpy(vlan_item_dst, vlan_item_src,
4924 sizeof(*vlan_item_dst));
4926 * Convert to internal match item, it is used
4927 * for vlan push and set vid.
4929 vlan_item_dst->type = (enum rte_flow_item_type)
4930 MLX5_RTE_FLOW_ITEM_TYPE_VLAN;
4937 action_cur = (fm->def_policy) ?
4938 actions_sfx++ : actions_pre++;
4939 memcpy(action_cur, actions, sizeof(struct rte_flow_action));
4941 /* Add end action to the actions. */
4942 actions_sfx->type = RTE_FLOW_ACTION_TYPE_END;
4943 if (priv->sh->meter_aso_en) {
4945 * For ASO meter, need to add an extra jump action explicitly,
4946 * to jump from meter to policer table.
4948 struct mlx5_flow_meter_sub_policy *sub_policy;
4949 struct mlx5_flow_tbl_data_entry *tbl_data;
4951 if (!fm->def_policy) {
4952 sub_policy = get_meter_sub_policy(dev, flow, wks,
4953 attr, items, error);
4957 enum mlx5_meter_domain mtr_domain =
4958 attr->transfer ? MLX5_MTR_DOMAIN_TRANSFER :
4959 (attr->egress ? MLX5_MTR_DOMAIN_EGRESS :
4960 MLX5_MTR_DOMAIN_INGRESS);
4963 &priv->sh->mtrmng->def_policy[mtr_domain]->sub_policy;
4965 tbl_data = container_of(sub_policy->tbl_rsc,
4966 struct mlx5_flow_tbl_data_entry, tbl);
4967 hw_mtr_action = actions_pre++;
4968 hw_mtr_action->type = (enum rte_flow_action_type)
4969 MLX5_RTE_FLOW_ACTION_TYPE_JUMP;
4970 hw_mtr_action->conf = tbl_data->jump.action;
4972 actions_pre->type = RTE_FLOW_ACTION_TYPE_END;
4975 return rte_flow_error_set(error, ENOMEM,
4976 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
4977 NULL, "No tag action space.");
4979 tag_action->type = RTE_FLOW_ACTION_TYPE_VOID;
4982 /* Only default-policy Meter creates mtr flow id. */
4983 if (fm->def_policy) {
4984 mlx5_ipool_malloc(fm->flow_ipool, &tag_id);
4986 return rte_flow_error_set(error, ENOMEM,
4987 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4988 "Failed to allocate meter flow id.");
4989 flow_id = tag_id - 1;
4990 flow_id_bits = (!flow_id) ? 1 :
4991 (MLX5_REG_BITS - __builtin_clz(flow_id));
4992 if ((flow_id_bits + priv->sh->mtrmng->max_mtr_bits) >
4994 mlx5_ipool_free(fm->flow_ipool, tag_id);
4995 return rte_flow_error_set(error, EINVAL,
4996 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4997 "Meter flow id exceeds max limit.");
4999 if (flow_id_bits > priv->sh->mtrmng->max_mtr_flow_bits)
5000 priv->sh->mtrmng->max_mtr_flow_bits = flow_id_bits;
5002 /* Build tag actions and items for meter_id/meter flow_id. */
5003 set_tag = (struct mlx5_rte_flow_action_set_tag *)actions_pre;
5004 tag_item_spec = (struct mlx5_rte_flow_item_tag *)sfx_items;
5005 tag_item_mask = tag_item_spec + 1;
5006 /* Both flow_id and meter_id share the same register. */
5007 *set_tag = (struct mlx5_rte_flow_action_set_tag) {
5008 .id = (enum modify_reg)mlx5_flow_get_reg_id(dev, MLX5_MTR_ID,
5010 .offset = mtr_id_offset,
5011 .length = mtr_reg_bits,
5012 .data = flow->meter,
5015 * The color Reg bits used by flow_id are growing from
5016 * msb to lsb, so must do bit reverse for flow_id val in RegC.
5018 for (shift = 0; shift < flow_id_bits; shift++)
5019 flow_id_reversed = (flow_id_reversed << 1) |
5020 ((flow_id >> shift) & 0x1);
5022 flow_id_reversed << (mtr_reg_bits - flow_id_bits);
5023 tag_item_spec->id = set_tag->id;
5024 tag_item_spec->data = set_tag->data << mtr_id_offset;
5025 tag_item_mask->data = UINT32_MAX << mtr_id_offset;
5026 tag_action->type = (enum rte_flow_action_type)
5027 MLX5_RTE_FLOW_ACTION_TYPE_TAG;
5028 tag_action->conf = set_tag;
5029 tag_item->type = (enum rte_flow_item_type)
5030 MLX5_RTE_FLOW_ITEM_TYPE_TAG;
5031 tag_item->spec = tag_item_spec;
5032 tag_item->last = NULL;
5033 tag_item->mask = tag_item_mask;
5036 *mtr_flow_id = tag_id;
5041 * Split action list having QUEUE/RSS for metadata register copy.
5043 * Once Q/RSS action is detected in user's action list, the flow action
5044 * should be split in order to copy metadata registers, which will happen in
5046 * - CQE->flow_tag := reg_c[1] (MARK)
5047 * - CQE->flow_table_metadata (reg_b) := reg_c[0] (META)
5048 * The Q/RSS action will be performed on RX_ACT_TBL after passing by RX_CP_TBL.
5049 * This is because the last action of each flow must be a terminal action
5050 * (QUEUE, RSS or DROP).
5052 * Flow ID must be allocated to identify actions in the RX_ACT_TBL and it is
5053 * stored and kept in the mlx5_flow structure per each sub_flow.
5055 * The Q/RSS action is replaced with,
5056 * - SET_TAG, setting the allocated flow ID to reg_c[2].
5057 * And the following JUMP action is added at the end,
5058 * - JUMP, to RX_CP_TBL.
5060 * A flow to perform remained Q/RSS action will be created in RX_ACT_TBL by
5061 * flow_create_split_metadata() routine. The flow will look like,
5062 * - If flow ID matches (reg_c[2]), perform Q/RSS.
5065 * Pointer to Ethernet device.
5066 * @param[out] split_actions
5067 * Pointer to store split actions to jump to CP_TBL.
5068 * @param[in] actions
5069 * Pointer to the list of original flow actions.
5071 * Pointer to the Q/RSS action.
5072 * @param[in] actions_n
5073 * Number of original actions.
5075 * Perform verbose error reporting if not NULL.
5078 * non-zero unique flow_id on success, otherwise 0 and
5079 * error/rte_error are set.
5082 flow_mreg_split_qrss_prep(struct rte_eth_dev *dev,
5083 struct rte_flow_action *split_actions,
5084 const struct rte_flow_action *actions,
5085 const struct rte_flow_action *qrss,
5086 int actions_n, struct rte_flow_error *error)
5088 struct mlx5_priv *priv = dev->data->dev_private;
5089 struct mlx5_rte_flow_action_set_tag *set_tag;
5090 struct rte_flow_action_jump *jump;
5091 const int qrss_idx = qrss - actions;
5092 uint32_t flow_id = 0;
5096 * Given actions will be split
5097 * - Replace QUEUE/RSS action with SET_TAG to set flow ID.
5098 * - Add jump to mreg CP_TBL.
5099 * As a result, there will be one more action.
5102 memcpy(split_actions, actions, sizeof(*split_actions) * actions_n);
5103 set_tag = (void *)(split_actions + actions_n);
5105 * If tag action is not set to void(it means we are not the meter
5106 * suffix flow), add the tag action. Since meter suffix flow already
5107 * has the tag added.
5109 if (split_actions[qrss_idx].type != RTE_FLOW_ACTION_TYPE_VOID) {
5111 * Allocate the new subflow ID. This one is unique within
5112 * device and not shared with representors. Otherwise,
5113 * we would have to resolve multi-thread access synch
5114 * issue. Each flow on the shared device is appended
5115 * with source vport identifier, so the resulting
5116 * flows will be unique in the shared (by master and
5117 * representors) domain even if they have coinciding
5120 mlx5_ipool_malloc(priv->sh->ipool
5121 [MLX5_IPOOL_RSS_EXPANTION_FLOW_ID], &flow_id);
5123 return rte_flow_error_set(error, ENOMEM,
5124 RTE_FLOW_ERROR_TYPE_ACTION,
5125 NULL, "can't allocate id "
5126 "for split Q/RSS subflow");
5127 /* Internal SET_TAG action to set flow ID. */
5128 *set_tag = (struct mlx5_rte_flow_action_set_tag){
5131 ret = mlx5_flow_get_reg_id(dev, MLX5_COPY_MARK, 0, error);
5135 /* Construct new actions array. */
5136 /* Replace QUEUE/RSS action. */
5137 split_actions[qrss_idx] = (struct rte_flow_action){
5138 .type = (enum rte_flow_action_type)
5139 MLX5_RTE_FLOW_ACTION_TYPE_TAG,
5143 /* JUMP action to jump to mreg copy table (CP_TBL). */
5144 jump = (void *)(set_tag + 1);
5145 *jump = (struct rte_flow_action_jump){
5146 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
5148 split_actions[actions_n - 2] = (struct rte_flow_action){
5149 .type = RTE_FLOW_ACTION_TYPE_JUMP,
5152 split_actions[actions_n - 1] = (struct rte_flow_action){
5153 .type = RTE_FLOW_ACTION_TYPE_END,
5159 * Extend the given action list for Tx metadata copy.
5161 * Copy the given action list to the ext_actions and add flow metadata register
5162 * copy action in order to copy reg_a set by WQE to reg_c[0].
5164 * @param[out] ext_actions
5165 * Pointer to the extended action list.
5166 * @param[in] actions
5167 * Pointer to the list of actions.
5168 * @param[in] actions_n
5169 * Number of actions in the list.
5171 * Perform verbose error reporting if not NULL.
5172 * @param[in] encap_idx
5173 * The encap action inndex.
5176 * 0 on success, negative value otherwise
5179 flow_mreg_tx_copy_prep(struct rte_eth_dev *dev,
5180 struct rte_flow_action *ext_actions,
5181 const struct rte_flow_action *actions,
5182 int actions_n, struct rte_flow_error *error,
5185 struct mlx5_flow_action_copy_mreg *cp_mreg =
5186 (struct mlx5_flow_action_copy_mreg *)
5187 (ext_actions + actions_n + 1);
5190 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_RX, 0, error);
5194 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_TX, 0, error);
5199 memcpy(ext_actions, actions, sizeof(*ext_actions) * encap_idx);
5200 if (encap_idx == actions_n - 1) {
5201 ext_actions[actions_n - 1] = (struct rte_flow_action){
5202 .type = (enum rte_flow_action_type)
5203 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
5206 ext_actions[actions_n] = (struct rte_flow_action){
5207 .type = RTE_FLOW_ACTION_TYPE_END,
5210 ext_actions[encap_idx] = (struct rte_flow_action){
5211 .type = (enum rte_flow_action_type)
5212 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
5215 memcpy(ext_actions + encap_idx + 1, actions + encap_idx,
5216 sizeof(*ext_actions) * (actions_n - encap_idx));
5222 * Check the match action from the action list.
5224 * @param[in] actions
5225 * Pointer to the list of actions.
5227 * Flow rule attributes.
5229 * The action to be check if exist.
5230 * @param[out] match_action_pos
5231 * Pointer to the position of the matched action if exists, otherwise is -1.
5232 * @param[out] qrss_action_pos
5233 * Pointer to the position of the Queue/RSS action if exists, otherwise is -1.
5234 * @param[out] modify_after_mirror
5235 * Pointer to the flag of modify action after FDB mirroring.
5238 * > 0 the total number of actions.
5239 * 0 if not found match action in action list.
5242 flow_check_match_action(const struct rte_flow_action actions[],
5243 const struct rte_flow_attr *attr,
5244 enum rte_flow_action_type action,
5245 int *match_action_pos, int *qrss_action_pos,
5246 int *modify_after_mirror)
5248 const struct rte_flow_action_sample *sample;
5255 *match_action_pos = -1;
5256 *qrss_action_pos = -1;
5257 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
5258 if (actions->type == action) {
5260 *match_action_pos = actions_n;
5262 switch (actions->type) {
5263 case RTE_FLOW_ACTION_TYPE_QUEUE:
5264 case RTE_FLOW_ACTION_TYPE_RSS:
5265 *qrss_action_pos = actions_n;
5267 case RTE_FLOW_ACTION_TYPE_SAMPLE:
5268 sample = actions->conf;
5269 ratio = sample->ratio;
5270 sub_type = ((const struct rte_flow_action *)
5271 (sample->actions))->type;
5272 if (ratio == 1 && attr->transfer)
5275 case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
5276 case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
5277 case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
5278 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
5279 case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
5280 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
5281 case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
5282 case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
5283 case RTE_FLOW_ACTION_TYPE_DEC_TTL:
5284 case RTE_FLOW_ACTION_TYPE_SET_TTL:
5285 case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
5286 case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
5287 case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
5288 case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
5289 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
5290 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
5291 case RTE_FLOW_ACTION_TYPE_FLAG:
5292 case RTE_FLOW_ACTION_TYPE_MARK:
5293 case RTE_FLOW_ACTION_TYPE_SET_META:
5294 case RTE_FLOW_ACTION_TYPE_SET_TAG:
5295 case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
5296 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
5297 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
5298 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
5299 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
5300 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
5301 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
5302 case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
5303 case RTE_FLOW_ACTION_TYPE_METER:
5305 *modify_after_mirror = 1;
5312 if (flag && fdb_mirror && !*modify_after_mirror) {
5313 /* FDB mirroring uses the destination array to implement
5314 * instead of FLOW_SAMPLER object.
5316 if (sub_type != RTE_FLOW_ACTION_TYPE_END)
5319 /* Count RTE_FLOW_ACTION_TYPE_END. */
5320 return flag ? actions_n + 1 : 0;
5323 #define SAMPLE_SUFFIX_ITEM 2
5326 * Split the sample flow.
5328 * As sample flow will split to two sub flow, sample flow with
5329 * sample action, the other actions will move to new suffix flow.
5331 * Also add unique tag id with tag action in the sample flow,
5332 * the same tag id will be as match in the suffix flow.
5335 * Pointer to Ethernet device.
5336 * @param[in] add_tag
5337 * Add extra tag action flag.
5338 * @param[out] sfx_items
5339 * Suffix flow match items (list terminated by the END pattern item).
5340 * @param[in] actions
5341 * Associated actions (list terminated by the END action).
5342 * @param[out] actions_sfx
5343 * Suffix flow actions.
5344 * @param[out] actions_pre
5345 * Prefix flow actions.
5346 * @param[in] actions_n
5347 * The total number of actions.
5348 * @param[in] sample_action_pos
5349 * The sample action position.
5350 * @param[in] qrss_action_pos
5351 * The Queue/RSS action position.
5352 * @param[in] jump_table
5353 * Add extra jump action flag.
5355 * Perform verbose error reporting if not NULL.
5358 * 0 on success, or unique flow_id, a negative errno value
5359 * otherwise and rte_errno is set.
5362 flow_sample_split_prep(struct rte_eth_dev *dev,
5364 struct rte_flow_item sfx_items[],
5365 const struct rte_flow_action actions[],
5366 struct rte_flow_action actions_sfx[],
5367 struct rte_flow_action actions_pre[],
5369 int sample_action_pos,
5370 int qrss_action_pos,
5372 struct rte_flow_error *error)
5374 struct mlx5_priv *priv = dev->data->dev_private;
5375 struct mlx5_rte_flow_action_set_tag *set_tag;
5376 struct mlx5_rte_flow_item_tag *tag_spec;
5377 struct mlx5_rte_flow_item_tag *tag_mask;
5378 struct rte_flow_action_jump *jump_action;
5379 uint32_t tag_id = 0;
5381 int append_index = 0;
5384 if (sample_action_pos < 0)
5385 return rte_flow_error_set(error, EINVAL,
5386 RTE_FLOW_ERROR_TYPE_ACTION,
5387 NULL, "invalid position of sample "
5389 /* Prepare the actions for prefix and suffix flow. */
5390 if (qrss_action_pos >= 0 && qrss_action_pos < sample_action_pos) {
5391 index = qrss_action_pos;
5392 /* Put the preceding the Queue/RSS action into prefix flow. */
5394 memcpy(actions_pre, actions,
5395 sizeof(struct rte_flow_action) * index);
5396 /* Put others preceding the sample action into prefix flow. */
5397 if (sample_action_pos > index + 1)
5398 memcpy(actions_pre + index, actions + index + 1,
5399 sizeof(struct rte_flow_action) *
5400 (sample_action_pos - index - 1));
5401 index = sample_action_pos - 1;
5402 /* Put Queue/RSS action into Suffix flow. */
5403 memcpy(actions_sfx, actions + qrss_action_pos,
5404 sizeof(struct rte_flow_action));
5407 index = sample_action_pos;
5409 memcpy(actions_pre, actions,
5410 sizeof(struct rte_flow_action) * index);
5412 /* For CX5, add an extra tag action for NIC-RX and E-Switch ingress.
5413 * For CX6DX and above, metadata registers Cx preserve their value,
5414 * add an extra tag action for NIC-RX and E-Switch Domain.
5417 /* Prepare the prefix tag action. */
5419 set_tag = (void *)(actions_pre + actions_n + append_index);
5420 ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, 0, error);
5423 mlx5_ipool_malloc(priv->sh->ipool
5424 [MLX5_IPOOL_RSS_EXPANTION_FLOW_ID], &tag_id);
5425 *set_tag = (struct mlx5_rte_flow_action_set_tag) {
5429 /* Prepare the suffix subflow items. */
5430 tag_spec = (void *)(sfx_items + SAMPLE_SUFFIX_ITEM);
5431 tag_spec->data = tag_id;
5432 tag_spec->id = set_tag->id;
5433 tag_mask = tag_spec + 1;
5434 tag_mask->data = UINT32_MAX;
5435 sfx_items[0] = (struct rte_flow_item){
5436 .type = (enum rte_flow_item_type)
5437 MLX5_RTE_FLOW_ITEM_TYPE_TAG,
5442 sfx_items[1] = (struct rte_flow_item){
5443 .type = (enum rte_flow_item_type)
5444 RTE_FLOW_ITEM_TYPE_END,
5446 /* Prepare the tag action in prefix subflow. */
5447 actions_pre[index++] =
5448 (struct rte_flow_action){
5449 .type = (enum rte_flow_action_type)
5450 MLX5_RTE_FLOW_ACTION_TYPE_TAG,
5454 memcpy(actions_pre + index, actions + sample_action_pos,
5455 sizeof(struct rte_flow_action));
5457 /* For the modify action after the sample action in E-Switch mirroring,
5458 * Add the extra jump action in prefix subflow and jump into the next
5459 * table, then do the modify action in the new table.
5462 /* Prepare the prefix jump action. */
5464 jump_action = (void *)(actions_pre + actions_n + append_index);
5465 jump_action->group = jump_table;
5466 actions_pre[index++] =
5467 (struct rte_flow_action){
5468 .type = (enum rte_flow_action_type)
5469 RTE_FLOW_ACTION_TYPE_JUMP,
5470 .conf = jump_action,
5473 actions_pre[index] = (struct rte_flow_action){
5474 .type = (enum rte_flow_action_type)
5475 RTE_FLOW_ACTION_TYPE_END,
5477 /* Put the actions after sample into Suffix flow. */
5478 memcpy(actions_sfx, actions + sample_action_pos + 1,
5479 sizeof(struct rte_flow_action) *
5480 (actions_n - sample_action_pos - 1));
5485 * The splitting for metadata feature.
5487 * - Q/RSS action on NIC Rx should be split in order to pass by
5488 * the mreg copy table (RX_CP_TBL) and then it jumps to the
5489 * action table (RX_ACT_TBL) which has the split Q/RSS action.
5491 * - All the actions on NIC Tx should have a mreg copy action to
5492 * copy reg_a from WQE to reg_c[0].
5495 * Pointer to Ethernet device.
5497 * Parent flow structure pointer.
5499 * Flow rule attributes.
5501 * Pattern specification (list terminated by the END pattern item).
5502 * @param[in] actions
5503 * Associated actions (list terminated by the END action).
5504 * @param[in] flow_split_info
5505 * Pointer to flow split info structure.
5507 * Perform verbose error reporting if not NULL.
5509 * 0 on success, negative value otherwise
5512 flow_create_split_metadata(struct rte_eth_dev *dev,
5513 struct rte_flow *flow,
5514 const struct rte_flow_attr *attr,
5515 const struct rte_flow_item items[],
5516 const struct rte_flow_action actions[],
5517 struct mlx5_flow_split_info *flow_split_info,
5518 struct rte_flow_error *error)
5520 struct mlx5_priv *priv = dev->data->dev_private;
5521 struct mlx5_dev_config *config = &priv->config;
5522 const struct rte_flow_action *qrss = NULL;
5523 struct rte_flow_action *ext_actions = NULL;
5524 struct mlx5_flow *dev_flow = NULL;
5525 uint32_t qrss_id = 0;
5532 /* Check whether extensive metadata feature is engaged. */
5533 if (!config->dv_flow_en ||
5534 config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
5535 !mlx5_flow_ext_mreg_supported(dev))
5536 return flow_create_split_inner(dev, flow, NULL, attr, items,
5537 actions, flow_split_info, error);
5538 actions_n = flow_parse_metadata_split_actions_info(actions, &qrss,
5541 /* Exclude hairpin flows from splitting. */
5542 if (qrss->type == RTE_FLOW_ACTION_TYPE_QUEUE) {
5543 const struct rte_flow_action_queue *queue;
5546 if (mlx5_rxq_get_type(dev, queue->index) ==
5547 MLX5_RXQ_TYPE_HAIRPIN)
5549 } else if (qrss->type == RTE_FLOW_ACTION_TYPE_RSS) {
5550 const struct rte_flow_action_rss *rss;
5553 if (mlx5_rxq_get_type(dev, rss->queue[0]) ==
5554 MLX5_RXQ_TYPE_HAIRPIN)
5559 /* Check if it is in meter suffix table. */
5560 mtr_sfx = attr->group == (attr->transfer ?
5561 (MLX5_FLOW_TABLE_LEVEL_METER - 1) :
5562 MLX5_FLOW_TABLE_LEVEL_METER);
5564 * Q/RSS action on NIC Rx should be split in order to pass by
5565 * the mreg copy table (RX_CP_TBL) and then it jumps to the
5566 * action table (RX_ACT_TBL) which has the split Q/RSS action.
5568 act_size = sizeof(struct rte_flow_action) * (actions_n + 1) +
5569 sizeof(struct rte_flow_action_set_tag) +
5570 sizeof(struct rte_flow_action_jump);
5571 ext_actions = mlx5_malloc(MLX5_MEM_ZERO, act_size, 0,
5574 return rte_flow_error_set(error, ENOMEM,
5575 RTE_FLOW_ERROR_TYPE_ACTION,
5576 NULL, "no memory to split "
5579 * If we are the suffix flow of meter, tag already exist.
5580 * Set the tag action to void.
5583 ext_actions[qrss - actions].type =
5584 RTE_FLOW_ACTION_TYPE_VOID;
5586 ext_actions[qrss - actions].type =
5587 (enum rte_flow_action_type)
5588 MLX5_RTE_FLOW_ACTION_TYPE_TAG;
5590 * Create the new actions list with removed Q/RSS action
5591 * and appended set tag and jump to register copy table
5592 * (RX_CP_TBL). We should preallocate unique tag ID here
5593 * in advance, because it is needed for set tag action.
5595 qrss_id = flow_mreg_split_qrss_prep(dev, ext_actions, actions,
5596 qrss, actions_n, error);
5597 if (!mtr_sfx && !qrss_id) {
5601 } else if (attr->egress && !attr->transfer) {
5603 * All the actions on NIC Tx should have a metadata register
5604 * copy action to copy reg_a from WQE to reg_c[meta]
5606 act_size = sizeof(struct rte_flow_action) * (actions_n + 1) +
5607 sizeof(struct mlx5_flow_action_copy_mreg);
5608 ext_actions = mlx5_malloc(MLX5_MEM_ZERO, act_size, 0,
5611 return rte_flow_error_set(error, ENOMEM,
5612 RTE_FLOW_ERROR_TYPE_ACTION,
5613 NULL, "no memory to split "
5615 /* Create the action list appended with copy register. */
5616 ret = flow_mreg_tx_copy_prep(dev, ext_actions, actions,
5617 actions_n, error, encap_idx);
5621 /* Add the unmodified original or prefix subflow. */
5622 ret = flow_create_split_inner(dev, flow, &dev_flow, attr,
5623 items, ext_actions ? ext_actions :
5624 actions, flow_split_info, error);
5627 MLX5_ASSERT(dev_flow);
5629 const struct rte_flow_attr q_attr = {
5630 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
5633 /* Internal PMD action to set register. */
5634 struct mlx5_rte_flow_item_tag q_tag_spec = {
5638 struct rte_flow_item q_items[] = {
5640 .type = (enum rte_flow_item_type)
5641 MLX5_RTE_FLOW_ITEM_TYPE_TAG,
5642 .spec = &q_tag_spec,
5647 .type = RTE_FLOW_ITEM_TYPE_END,
5650 struct rte_flow_action q_actions[] = {
5656 .type = RTE_FLOW_ACTION_TYPE_END,
5659 uint64_t layers = flow_get_prefix_layer_flags(dev_flow);
5662 * Configure the tag item only if there is no meter subflow.
5663 * Since tag is already marked in the meter suffix subflow
5664 * we can just use the meter suffix items as is.
5667 /* Not meter subflow. */
5668 MLX5_ASSERT(!mtr_sfx);
5670 * Put unique id in prefix flow due to it is destroyed
5671 * after suffix flow and id will be freed after there
5672 * is no actual flows with this id and identifier
5673 * reallocation becomes possible (for example, for
5674 * other flows in other threads).
5676 dev_flow->handle->split_flow_id = qrss_id;
5677 ret = mlx5_flow_get_reg_id(dev, MLX5_COPY_MARK, 0,
5681 q_tag_spec.id = ret;
5684 /* Add suffix subflow to execute Q/RSS. */
5685 flow_split_info->prefix_layers = layers;
5686 flow_split_info->prefix_mark = 0;
5687 ret = flow_create_split_inner(dev, flow, &dev_flow,
5688 &q_attr, mtr_sfx ? items :
5690 flow_split_info, error);
5693 /* qrss ID should be freed if failed. */
5695 MLX5_ASSERT(dev_flow);
5700 * We do not destroy the partially created sub_flows in case of error.
5701 * These ones are included into parent flow list and will be destroyed
5702 * by flow_drv_destroy.
5704 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RSS_EXPANTION_FLOW_ID],
5706 mlx5_free(ext_actions);
5711 * Create meter internal drop flow with the original pattern.
5714 * Pointer to Ethernet device.
5716 * Parent flow structure pointer.
5718 * Flow rule attributes.
5720 * Pattern specification (list terminated by the END pattern item).
5721 * @param[in] flow_split_info
5722 * Pointer to flow split info structure.
5724 * Pointer to flow meter structure.
5726 * Perform verbose error reporting if not NULL.
5728 * 0 on success, negative value otherwise
5731 flow_meter_create_drop_flow_with_org_pattern(struct rte_eth_dev *dev,
5732 struct rte_flow *flow,
5733 const struct rte_flow_attr *attr,
5734 const struct rte_flow_item items[],
5735 struct mlx5_flow_split_info *flow_split_info,
5736 struct mlx5_flow_meter_info *fm,
5737 struct rte_flow_error *error)
5739 struct mlx5_flow *dev_flow = NULL;
5740 struct rte_flow_attr drop_attr = *attr;
5741 struct rte_flow_action drop_actions[3];
5742 struct mlx5_flow_split_info drop_split_info = *flow_split_info;
5744 MLX5_ASSERT(fm->drop_cnt);
5745 drop_actions[0].type =
5746 (enum rte_flow_action_type)MLX5_RTE_FLOW_ACTION_TYPE_COUNT;
5747 drop_actions[0].conf = (void *)(uintptr_t)fm->drop_cnt;
5748 drop_actions[1].type = RTE_FLOW_ACTION_TYPE_DROP;
5749 drop_actions[1].conf = NULL;
5750 drop_actions[2].type = RTE_FLOW_ACTION_TYPE_END;
5751 drop_actions[2].conf = NULL;
5752 drop_split_info.external = false;
5753 drop_split_info.skip_scale |= 1 << MLX5_SCALE_FLOW_GROUP_BIT;
5754 drop_split_info.table_id = MLX5_MTR_TABLE_ID_DROP;
5755 drop_attr.group = MLX5_FLOW_TABLE_LEVEL_METER;
5756 return flow_create_split_inner(dev, flow, &dev_flow,
5757 &drop_attr, items, drop_actions,
5758 &drop_split_info, error);
5762 * The splitting for meter feature.
5764 * - The meter flow will be split to two flows as prefix and
5765 * suffix flow. The packets make sense only it pass the prefix
5768 * - Reg_C_5 is used for the packet to match betweend prefix and
5772 * Pointer to Ethernet device.
5774 * Parent flow structure pointer.
5776 * Flow rule attributes.
5778 * Pattern specification (list terminated by the END pattern item).
5779 * @param[in] actions
5780 * Associated actions (list terminated by the END action).
5781 * @param[in] flow_split_info
5782 * Pointer to flow split info structure.
5784 * Perform verbose error reporting if not NULL.
5786 * 0 on success, negative value otherwise
5789 flow_create_split_meter(struct rte_eth_dev *dev,
5790 struct rte_flow *flow,
5791 const struct rte_flow_attr *attr,
5792 const struct rte_flow_item items[],
5793 const struct rte_flow_action actions[],
5794 struct mlx5_flow_split_info *flow_split_info,
5795 struct rte_flow_error *error)
5797 struct mlx5_priv *priv = dev->data->dev_private;
5798 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
5799 struct rte_flow_action *sfx_actions = NULL;
5800 struct rte_flow_action *pre_actions = NULL;
5801 struct rte_flow_item *sfx_items = NULL;
5802 struct mlx5_flow *dev_flow = NULL;
5803 struct rte_flow_attr sfx_attr = *attr;
5804 struct mlx5_flow_meter_info *fm = NULL;
5805 uint8_t skip_scale_restore;
5806 bool has_mtr = false;
5807 bool has_modify = false;
5808 bool set_mtr_reg = true;
5809 bool is_mtr_hierarchy = false;
5810 uint32_t meter_id = 0;
5811 uint32_t mtr_idx = 0;
5812 uint32_t mtr_flow_id = 0;
5819 actions_n = flow_check_meter_action(dev, actions, &has_mtr,
5820 &has_modify, &meter_id);
5823 fm = flow_dv_meter_find_by_idx(priv, flow->meter);
5825 return rte_flow_error_set(error, EINVAL,
5826 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5827 NULL, "Meter not found.");
5829 fm = mlx5_flow_meter_find(priv, meter_id, &mtr_idx);
5831 return rte_flow_error_set(error, EINVAL,
5832 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5833 NULL, "Meter not found.");
5834 ret = mlx5_flow_meter_attach(priv, fm,
5838 flow->meter = mtr_idx;
5842 if (!fm->def_policy) {
5843 wks->policy = mlx5_flow_meter_policy_find(dev,
5846 MLX5_ASSERT(wks->policy);
5847 if (wks->policy->is_hierarchy) {
5849 mlx5_flow_meter_hierarchy_get_final_policy(dev,
5851 if (!wks->final_policy)
5852 return rte_flow_error_set(error,
5854 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5855 "Failed to find terminal policy of hierarchy.");
5856 is_mtr_hierarchy = true;
5860 * If it isn't default-policy Meter, and
5861 * 1. There's no action in flow to change
5862 * packet (modify/encap/decap etc.), OR
5863 * 2. No drop count needed for this meter.
5864 * 3. It's not meter hierarchy.
5865 * Then no need to use regC to save meter id anymore.
5867 if (!fm->def_policy && !is_mtr_hierarchy &&
5868 (!has_modify || !fm->drop_cnt))
5869 set_mtr_reg = false;
5870 /* Prefix actions: meter, decap, encap, tag, jump, end. */
5871 act_size = sizeof(struct rte_flow_action) * (actions_n + 6) +
5872 sizeof(struct mlx5_rte_flow_action_set_tag);
5873 /* Suffix items: tag, vlan, port id, end. */
5874 #define METER_SUFFIX_ITEM 4
5875 item_size = sizeof(struct rte_flow_item) * METER_SUFFIX_ITEM +
5876 sizeof(struct mlx5_rte_flow_item_tag) * 2;
5877 sfx_actions = mlx5_malloc(MLX5_MEM_ZERO, (act_size + item_size),
5880 return rte_flow_error_set(error, ENOMEM,
5881 RTE_FLOW_ERROR_TYPE_ACTION,
5882 NULL, "no memory to split "
5884 sfx_items = (struct rte_flow_item *)((char *)sfx_actions +
5886 /* There's no suffix flow for meter of non-default policy. */
5887 if (!fm->def_policy)
5888 pre_actions = sfx_actions + 1;
5890 pre_actions = sfx_actions + actions_n;
5891 ret = flow_meter_split_prep(dev, flow, wks, &sfx_attr,
5892 items, sfx_items, actions,
5893 sfx_actions, pre_actions,
5894 (set_mtr_reg ? &mtr_flow_id : NULL),
5900 /* Add the prefix subflow. */
5901 flow_split_info->prefix_mark = 0;
5902 skip_scale_restore = flow_split_info->skip_scale;
5903 flow_split_info->skip_scale |=
5904 1 << MLX5_SCALE_JUMP_FLOW_GROUP_BIT;
5905 ret = flow_create_split_inner(dev, flow, &dev_flow,
5906 attr, items, pre_actions,
5907 flow_split_info, error);
5908 flow_split_info->skip_scale = skip_scale_restore;
5911 mlx5_ipool_free(fm->flow_ipool, mtr_flow_id);
5916 dev_flow->handle->split_flow_id = mtr_flow_id;
5917 dev_flow->handle->is_meter_flow_id = 1;
5919 if (!fm->def_policy) {
5920 if (!set_mtr_reg && fm->drop_cnt)
5922 flow_meter_create_drop_flow_with_org_pattern(dev, flow,
5928 /* Setting the sfx group atrr. */
5929 sfx_attr.group = sfx_attr.transfer ?
5930 (MLX5_FLOW_TABLE_LEVEL_METER - 1) :
5931 MLX5_FLOW_TABLE_LEVEL_METER;
5932 flow_split_info->prefix_layers =
5933 flow_get_prefix_layer_flags(dev_flow);
5934 flow_split_info->prefix_mark = dev_flow->handle->mark;
5935 flow_split_info->table_id = MLX5_MTR_TABLE_ID_SUFFIX;
5937 /* Add the prefix subflow. */
5938 ret = flow_create_split_metadata(dev, flow,
5939 &sfx_attr, sfx_items ?
5941 sfx_actions ? sfx_actions : actions,
5942 flow_split_info, error);
5945 mlx5_free(sfx_actions);
5950 * The splitting for sample feature.
5952 * Once Sample action is detected in the action list, the flow actions should
5953 * be split into prefix sub flow and suffix sub flow.
5955 * The original items remain in the prefix sub flow, all actions preceding the
5956 * sample action and the sample action itself will be copied to the prefix
5957 * sub flow, the actions following the sample action will be copied to the
5958 * suffix sub flow, Queue action always be located in the suffix sub flow.
5960 * In order to make the packet from prefix sub flow matches with suffix sub
5961 * flow, an extra tag action be added into prefix sub flow, and the suffix sub
5962 * flow uses tag item with the unique flow id.
5965 * Pointer to Ethernet device.
5967 * Parent flow structure pointer.
5969 * Flow rule attributes.
5971 * Pattern specification (list terminated by the END pattern item).
5972 * @param[in] actions
5973 * Associated actions (list terminated by the END action).
5974 * @param[in] flow_split_info
5975 * Pointer to flow split info structure.
5977 * Perform verbose error reporting if not NULL.
5979 * 0 on success, negative value otherwise
5982 flow_create_split_sample(struct rte_eth_dev *dev,
5983 struct rte_flow *flow,
5984 const struct rte_flow_attr *attr,
5985 const struct rte_flow_item items[],
5986 const struct rte_flow_action actions[],
5987 struct mlx5_flow_split_info *flow_split_info,
5988 struct rte_flow_error *error)
5990 struct mlx5_priv *priv = dev->data->dev_private;
5991 struct rte_flow_action *sfx_actions = NULL;
5992 struct rte_flow_action *pre_actions = NULL;
5993 struct rte_flow_item *sfx_items = NULL;
5994 struct mlx5_flow *dev_flow = NULL;
5995 struct rte_flow_attr sfx_attr = *attr;
5996 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
5997 struct mlx5_flow_dv_sample_resource *sample_res;
5998 struct mlx5_flow_tbl_data_entry *sfx_tbl_data;
5999 struct mlx5_flow_tbl_resource *sfx_tbl;
6003 uint32_t fdb_tx = 0;
6006 int sample_action_pos;
6007 int qrss_action_pos;
6009 int modify_after_mirror = 0;
6010 uint16_t jump_table = 0;
6011 const uint32_t next_ft_step = 1;
6014 if (priv->sampler_en)
6015 actions_n = flow_check_match_action(actions, attr,
6016 RTE_FLOW_ACTION_TYPE_SAMPLE,
6017 &sample_action_pos, &qrss_action_pos,
6018 &modify_after_mirror);
6020 /* The prefix actions must includes sample, tag, end. */
6021 act_size = sizeof(struct rte_flow_action) * (actions_n * 2 + 1)
6022 + sizeof(struct mlx5_rte_flow_action_set_tag);
6023 item_size = sizeof(struct rte_flow_item) * SAMPLE_SUFFIX_ITEM +
6024 sizeof(struct mlx5_rte_flow_item_tag) * 2;
6025 sfx_actions = mlx5_malloc(MLX5_MEM_ZERO, (act_size +
6026 item_size), 0, SOCKET_ID_ANY);
6028 return rte_flow_error_set(error, ENOMEM,
6029 RTE_FLOW_ERROR_TYPE_ACTION,
6030 NULL, "no memory to split "
6032 /* The representor_id is UINT16_MAX for uplink. */
6033 fdb_tx = (attr->transfer && priv->representor_id != UINT16_MAX);
6035 * When reg_c_preserve is set, metadata registers Cx preserve
6036 * their value even through packet duplication.
6038 add_tag = (!fdb_tx || priv->config.hca_attr.reg_c_preserve);
6040 sfx_items = (struct rte_flow_item *)((char *)sfx_actions
6042 if (modify_after_mirror)
6043 jump_table = attr->group * MLX5_FLOW_TABLE_FACTOR +
6045 pre_actions = sfx_actions + actions_n;
6046 tag_id = flow_sample_split_prep(dev, add_tag, sfx_items,
6047 actions, sfx_actions,
6048 pre_actions, actions_n,
6050 qrss_action_pos, jump_table,
6052 if (tag_id < 0 || (add_tag && !tag_id)) {
6056 if (modify_after_mirror)
6057 flow_split_info->skip_scale =
6058 1 << MLX5_SCALE_JUMP_FLOW_GROUP_BIT;
6059 /* Add the prefix subflow. */
6060 ret = flow_create_split_inner(dev, flow, &dev_flow, attr,
6062 flow_split_info, error);
6067 dev_flow->handle->split_flow_id = tag_id;
6068 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
6069 if (!modify_after_mirror) {
6070 /* Set the sfx group attr. */
6071 sample_res = (struct mlx5_flow_dv_sample_resource *)
6072 dev_flow->dv.sample_res;
6073 sfx_tbl = (struct mlx5_flow_tbl_resource *)
6074 sample_res->normal_path_tbl;
6075 sfx_tbl_data = container_of(sfx_tbl,
6076 struct mlx5_flow_tbl_data_entry,
6078 sfx_attr.group = sfx_attr.transfer ?
6079 (sfx_tbl_data->level - 1) : sfx_tbl_data->level;
6081 MLX5_ASSERT(attr->transfer);
6082 sfx_attr.group = jump_table;
6084 flow_split_info->prefix_layers =
6085 flow_get_prefix_layer_flags(dev_flow);
6086 flow_split_info->prefix_mark = dev_flow->handle->mark;
6087 /* Suffix group level already be scaled with factor, set
6088 * MLX5_SCALE_FLOW_GROUP_BIT of skip_scale to 1 to avoid scale
6089 * again in translation.
6091 flow_split_info->skip_scale = 1 << MLX5_SCALE_FLOW_GROUP_BIT;
6094 /* Add the suffix subflow. */
6095 ret = flow_create_split_meter(dev, flow, &sfx_attr,
6096 sfx_items ? sfx_items : items,
6097 sfx_actions ? sfx_actions : actions,
6098 flow_split_info, error);
6101 mlx5_free(sfx_actions);
6106 * Split the flow to subflow set. The splitters might be linked
6107 * in the chain, like this:
6108 * flow_create_split_outer() calls:
6109 * flow_create_split_meter() calls:
6110 * flow_create_split_metadata(meter_subflow_0) calls:
6111 * flow_create_split_inner(metadata_subflow_0)
6112 * flow_create_split_inner(metadata_subflow_1)
6113 * flow_create_split_inner(metadata_subflow_2)
6114 * flow_create_split_metadata(meter_subflow_1) calls:
6115 * flow_create_split_inner(metadata_subflow_0)
6116 * flow_create_split_inner(metadata_subflow_1)
6117 * flow_create_split_inner(metadata_subflow_2)
6119 * This provide flexible way to add new levels of flow splitting.
6120 * The all of successfully created subflows are included to the
6121 * parent flow dev_flow list.
6124 * Pointer to Ethernet device.
6126 * Parent flow structure pointer.
6128 * Flow rule attributes.
6130 * Pattern specification (list terminated by the END pattern item).
6131 * @param[in] actions
6132 * Associated actions (list terminated by the END action).
6133 * @param[in] flow_split_info
6134 * Pointer to flow split info structure.
6136 * Perform verbose error reporting if not NULL.
6138 * 0 on success, negative value otherwise
6141 flow_create_split_outer(struct rte_eth_dev *dev,
6142 struct rte_flow *flow,
6143 const struct rte_flow_attr *attr,
6144 const struct rte_flow_item items[],
6145 const struct rte_flow_action actions[],
6146 struct mlx5_flow_split_info *flow_split_info,
6147 struct rte_flow_error *error)
6151 ret = flow_create_split_sample(dev, flow, attr, items,
6152 actions, flow_split_info, error);
6153 MLX5_ASSERT(ret <= 0);
6157 static inline struct mlx5_flow_tunnel *
6158 flow_tunnel_from_rule(const struct mlx5_flow *flow)
6160 struct mlx5_flow_tunnel *tunnel;
6162 #pragma GCC diagnostic push
6163 #pragma GCC diagnostic ignored "-Wcast-qual"
6164 tunnel = (typeof(tunnel))flow->tunnel;
6165 #pragma GCC diagnostic pop
6171 * Adjust flow RSS workspace if needed.
6174 * Pointer to thread flow work space.
6176 * Pointer to RSS descriptor.
6177 * @param[in] nrssq_num
6178 * New RSS queue number.
6181 * 0 on success, -1 otherwise and rte_errno is set.
6184 flow_rss_workspace_adjust(struct mlx5_flow_workspace *wks,
6185 struct mlx5_flow_rss_desc *rss_desc,
6188 if (likely(nrssq_num <= wks->rssq_num))
6190 rss_desc->queue = realloc(rss_desc->queue,
6191 sizeof(*rss_desc->queue) * RTE_ALIGN(nrssq_num, 2));
6192 if (!rss_desc->queue) {
6196 wks->rssq_num = RTE_ALIGN(nrssq_num, 2);
6201 * Create a flow and add it to @p list.
6204 * Pointer to Ethernet device.
6206 * Pointer to a TAILQ flow list. If this parameter NULL,
6207 * no list insertion occurred, flow is just created,
6208 * this is caller's responsibility to track the
6211 * Flow rule attributes.
6213 * Pattern specification (list terminated by the END pattern item).
6214 * @param[in] actions
6215 * Associated actions (list terminated by the END action).
6216 * @param[in] external
6217 * This flow rule is created by request external to PMD.
6219 * Perform verbose error reporting if not NULL.
6222 * A flow index on success, 0 otherwise and rte_errno is set.
6225 flow_list_create(struct rte_eth_dev *dev, enum mlx5_flow_type type,
6226 const struct rte_flow_attr *attr,
6227 const struct rte_flow_item items[],
6228 const struct rte_flow_action original_actions[],
6229 bool external, struct rte_flow_error *error)
6231 struct mlx5_priv *priv = dev->data->dev_private;
6232 struct rte_flow *flow = NULL;
6233 struct mlx5_flow *dev_flow;
6234 const struct rte_flow_action_rss *rss = NULL;
6235 struct mlx5_translated_action_handle
6236 indir_actions[MLX5_MAX_INDIRECT_ACTIONS];
6237 int indir_actions_n = MLX5_MAX_INDIRECT_ACTIONS;
6239 struct mlx5_flow_expand_rss buf;
6240 uint8_t buffer[2048];
6243 struct rte_flow_action actions[MLX5_MAX_SPLIT_ACTIONS];
6244 uint8_t buffer[2048];
6247 struct rte_flow_action actions[MLX5_MAX_SPLIT_ACTIONS];
6248 uint8_t buffer[2048];
6249 } actions_hairpin_tx;
6251 struct rte_flow_item items[MLX5_MAX_SPLIT_ITEMS];
6252 uint8_t buffer[2048];
6254 struct mlx5_flow_expand_rss *buf = &expand_buffer.buf;
6255 struct mlx5_flow_rss_desc *rss_desc;
6256 const struct rte_flow_action *p_actions_rx;
6260 struct rte_flow_attr attr_tx = { .priority = 0 };
6261 const struct rte_flow_action *actions;
6262 struct rte_flow_action *translated_actions = NULL;
6263 struct mlx5_flow_tunnel *tunnel;
6264 struct tunnel_default_miss_ctx default_miss_ctx = { 0, };
6265 struct mlx5_flow_workspace *wks = mlx5_flow_push_thread_workspace();
6266 struct mlx5_flow_split_info flow_split_info = {
6267 .external = !!external,
6277 rss_desc = &wks->rss_desc;
6278 ret = flow_action_handles_translate(dev, original_actions,
6281 &translated_actions, error);
6283 MLX5_ASSERT(translated_actions == NULL);
6286 actions = translated_actions ? translated_actions : original_actions;
6287 p_actions_rx = actions;
6288 hairpin_flow = flow_check_hairpin_split(dev, attr, actions);
6289 ret = flow_drv_validate(dev, attr, items, p_actions_rx,
6290 external, hairpin_flow, error);
6292 goto error_before_hairpin_split;
6293 flow = mlx5_ipool_zmalloc(priv->flows[type], &idx);
6296 goto error_before_hairpin_split;
6298 if (hairpin_flow > 0) {
6299 if (hairpin_flow > MLX5_MAX_SPLIT_ACTIONS) {
6301 goto error_before_hairpin_split;
6303 flow_hairpin_split(dev, actions, actions_rx.actions,
6304 actions_hairpin_tx.actions, items_tx.items,
6306 p_actions_rx = actions_rx.actions;
6308 flow_split_info.flow_idx = idx;
6309 flow->drv_type = flow_get_drv_type(dev, attr);
6310 MLX5_ASSERT(flow->drv_type > MLX5_FLOW_TYPE_MIN &&
6311 flow->drv_type < MLX5_FLOW_TYPE_MAX);
6312 memset(rss_desc, 0, offsetof(struct mlx5_flow_rss_desc, queue));
6313 /* RSS Action only works on NIC RX domain */
6314 if (attr->ingress && !attr->transfer)
6315 rss = flow_get_rss_action(dev, p_actions_rx);
6317 if (flow_rss_workspace_adjust(wks, rss_desc, rss->queue_num))
6320 * The following information is required by
6321 * mlx5_flow_hashfields_adjust() in advance.
6323 rss_desc->level = rss->level;
6324 /* RSS type 0 indicates default RSS type (ETH_RSS_IP). */
6325 rss_desc->types = !rss->types ? ETH_RSS_IP : rss->types;
6327 flow->dev_handles = 0;
6328 if (rss && rss->types) {
6329 unsigned int graph_root;
6331 graph_root = find_graph_root(items, rss->level);
6332 ret = mlx5_flow_expand_rss(buf, sizeof(expand_buffer.buffer),
6334 mlx5_support_expansion, graph_root);
6335 MLX5_ASSERT(ret > 0 &&
6336 (unsigned int)ret < sizeof(expand_buffer.buffer));
6337 if (rte_log_can_log(mlx5_logtype, RTE_LOG_DEBUG)) {
6338 for (i = 0; i < buf->entries; ++i)
6339 mlx5_dbg__print_pattern(buf->entry[i].pattern);
6343 buf->entry[0].pattern = (void *)(uintptr_t)items;
6345 rss_desc->shared_rss = flow_get_shared_rss_action(dev, indir_actions,
6347 for (i = 0; i < buf->entries; ++i) {
6348 /* Initialize flow split data. */
6349 flow_split_info.prefix_layers = 0;
6350 flow_split_info.prefix_mark = 0;
6351 flow_split_info.skip_scale = 0;
6353 * The splitter may create multiple dev_flows,
6354 * depending on configuration. In the simplest
6355 * case it just creates unmodified original flow.
6357 ret = flow_create_split_outer(dev, flow, attr,
6358 buf->entry[i].pattern,
6359 p_actions_rx, &flow_split_info,
6363 if (is_flow_tunnel_steer_rule(wks->flows[0].tof_type)) {
6364 ret = flow_tunnel_add_default_miss(dev, flow, attr,
6367 wks->flows[0].tunnel,
6371 mlx5_free(default_miss_ctx.queue);
6376 /* Create the tx flow. */
6378 attr_tx.group = MLX5_HAIRPIN_TX_TABLE;
6379 attr_tx.ingress = 0;
6381 dev_flow = flow_drv_prepare(dev, flow, &attr_tx, items_tx.items,
6382 actions_hairpin_tx.actions,
6386 dev_flow->flow = flow;
6387 dev_flow->external = 0;
6388 SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
6389 dev_flow->handle, next);
6390 ret = flow_drv_translate(dev, dev_flow, &attr_tx,
6392 actions_hairpin_tx.actions, error);
6397 * Update the metadata register copy table. If extensive
6398 * metadata feature is enabled and registers are supported
6399 * we might create the extra rte_flow for each unique
6400 * MARK/FLAG action ID.
6402 * The table is updated for ingress Flows only, because
6403 * the egress Flows belong to the different device and
6404 * copy table should be updated in peer NIC Rx domain.
6406 if (attr->ingress &&
6407 (external || attr->group != MLX5_FLOW_MREG_CP_TABLE_GROUP)) {
6408 ret = flow_mreg_update_copy_table(dev, flow, actions, error);
6413 * If the flow is external (from application) OR device is started,
6414 * OR mreg discover, then apply immediately.
6416 if (external || dev->data->dev_started ||
6417 (attr->group == MLX5_FLOW_MREG_CP_TABLE_GROUP &&
6418 attr->priority == MLX5_FLOW_LOWEST_PRIO_INDICATOR)) {
6419 ret = flow_drv_apply(dev, flow, error);
6424 flow_rxq_flags_set(dev, flow);
6425 rte_free(translated_actions);
6426 tunnel = flow_tunnel_from_rule(wks->flows);
6429 flow->tunnel_id = tunnel->tunnel_id;
6430 __atomic_add_fetch(&tunnel->refctn, 1, __ATOMIC_RELAXED);
6431 mlx5_free(default_miss_ctx.queue);
6433 mlx5_flow_pop_thread_workspace();
6437 ret = rte_errno; /* Save rte_errno before cleanup. */
6438 flow_mreg_del_copy_action(dev, flow);
6439 flow_drv_destroy(dev, flow);
6440 if (rss_desc->shared_rss)
6441 __atomic_sub_fetch(&((struct mlx5_shared_action_rss *)
6443 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
6444 rss_desc->shared_rss))->refcnt, 1, __ATOMIC_RELAXED);
6445 mlx5_ipool_free(priv->flows[type], idx);
6446 rte_errno = ret; /* Restore rte_errno. */
6449 mlx5_flow_pop_thread_workspace();
6450 error_before_hairpin_split:
6451 rte_free(translated_actions);
6456 * Create a dedicated flow rule on e-switch table 0 (root table), to direct all
6457 * incoming packets to table 1.
6459 * Other flow rules, requested for group n, will be created in
6460 * e-switch table n+1.
6461 * Jump action to e-switch group n will be created to group n+1.
6463 * Used when working in switchdev mode, to utilise advantages of table 1
6467 * Pointer to Ethernet device.
6470 * Pointer to flow on success, NULL otherwise and rte_errno is set.
6473 mlx5_flow_create_esw_table_zero_flow(struct rte_eth_dev *dev)
6475 const struct rte_flow_attr attr = {
6482 const struct rte_flow_item pattern = {
6483 .type = RTE_FLOW_ITEM_TYPE_END,
6485 struct rte_flow_action_jump jump = {
6488 const struct rte_flow_action actions[] = {
6490 .type = RTE_FLOW_ACTION_TYPE_JUMP,
6494 .type = RTE_FLOW_ACTION_TYPE_END,
6497 struct rte_flow_error error;
6499 return (void *)(uintptr_t)flow_list_create(dev, MLX5_FLOW_TYPE_CTL,
6501 actions, false, &error);
6505 * Validate a flow supported by the NIC.
6507 * @see rte_flow_validate()
6511 mlx5_flow_validate(struct rte_eth_dev *dev,
6512 const struct rte_flow_attr *attr,
6513 const struct rte_flow_item items[],
6514 const struct rte_flow_action original_actions[],
6515 struct rte_flow_error *error)
6518 struct mlx5_translated_action_handle
6519 indir_actions[MLX5_MAX_INDIRECT_ACTIONS];
6520 int indir_actions_n = MLX5_MAX_INDIRECT_ACTIONS;
6521 const struct rte_flow_action *actions;
6522 struct rte_flow_action *translated_actions = NULL;
6523 int ret = flow_action_handles_translate(dev, original_actions,
6526 &translated_actions, error);
6530 actions = translated_actions ? translated_actions : original_actions;
6531 hairpin_flow = flow_check_hairpin_split(dev, attr, actions);
6532 ret = flow_drv_validate(dev, attr, items, actions,
6533 true, hairpin_flow, error);
6534 rte_free(translated_actions);
6541 * @see rte_flow_create()
6545 mlx5_flow_create(struct rte_eth_dev *dev,
6546 const struct rte_flow_attr *attr,
6547 const struct rte_flow_item items[],
6548 const struct rte_flow_action actions[],
6549 struct rte_flow_error *error)
6552 * If the device is not started yet, it is not allowed to created a
6553 * flow from application. PMD default flows and traffic control flows
6556 if (unlikely(!dev->data->dev_started)) {
6557 DRV_LOG(DEBUG, "port %u is not started when "
6558 "inserting a flow", dev->data->port_id);
6559 rte_flow_error_set(error, ENODEV,
6560 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6562 "port not started");
6566 return (void *)(uintptr_t)flow_list_create(dev, MLX5_FLOW_TYPE_GEN,
6567 attr, items, actions,
6572 * Destroy a flow in a list.
6575 * Pointer to Ethernet device.
6576 * @param[in] flow_idx
6577 * Index of flow to destroy.
6580 flow_list_destroy(struct rte_eth_dev *dev, enum mlx5_flow_type type,
6583 struct mlx5_priv *priv = dev->data->dev_private;
6584 struct rte_flow *flow = mlx5_ipool_get(priv->flows[type], flow_idx);
6588 MLX5_ASSERT(flow->type == type);
6590 * Update RX queue flags only if port is started, otherwise it is
6593 if (dev->data->dev_started)
6594 flow_rxq_flags_trim(dev, flow);
6595 flow_drv_destroy(dev, flow);
6597 struct mlx5_flow_tunnel *tunnel;
6599 tunnel = mlx5_find_tunnel_id(dev, flow->tunnel_id);
6601 if (!__atomic_sub_fetch(&tunnel->refctn, 1, __ATOMIC_RELAXED))
6602 mlx5_flow_tunnel_free(dev, tunnel);
6604 flow_mreg_del_copy_action(dev, flow);
6605 mlx5_ipool_free(priv->flows[type], flow_idx);
6609 * Destroy all flows.
6612 * Pointer to Ethernet device.
6614 * Flow type to be flushed.
6616 * If flushing is called avtively.
6619 mlx5_flow_list_flush(struct rte_eth_dev *dev, enum mlx5_flow_type type,
6622 struct mlx5_priv *priv = dev->data->dev_private;
6623 uint32_t num_flushed = 0, fidx = 1;
6624 struct rte_flow *flow;
6626 MLX5_IPOOL_FOREACH(priv->flows[type], fidx, flow) {
6627 flow_list_destroy(dev, type, fidx);
6631 DRV_LOG(INFO, "port %u: %u flows flushed before stopping",
6632 dev->data->port_id, num_flushed);
6637 * Stop all default actions for flows.
6640 * Pointer to Ethernet device.
6643 mlx5_flow_stop_default(struct rte_eth_dev *dev)
6645 flow_mreg_del_default_copy_action(dev);
6646 flow_rxq_flags_clear(dev);
6650 * Start all default actions for flows.
6653 * Pointer to Ethernet device.
6655 * 0 on success, a negative errno value otherwise and rte_errno is set.
6658 mlx5_flow_start_default(struct rte_eth_dev *dev)
6660 struct rte_flow_error error;
6662 /* Make sure default copy action (reg_c[0] -> reg_b) is created. */
6663 return flow_mreg_add_default_copy_action(dev, &error);
6667 * Release key of thread specific flow workspace data.
6670 flow_release_workspace(void *data)
6672 struct mlx5_flow_workspace *wks = data;
6673 struct mlx5_flow_workspace *next;
6677 free(wks->rss_desc.queue);
6684 * Get thread specific current flow workspace.
6686 * @return pointer to thread specific flow workspace data, NULL on error.
6688 struct mlx5_flow_workspace*
6689 mlx5_flow_get_thread_workspace(void)
6691 struct mlx5_flow_workspace *data;
6693 data = mlx5_flow_os_get_specific_workspace();
6694 MLX5_ASSERT(data && data->inuse);
6695 if (!data || !data->inuse)
6696 DRV_LOG(ERR, "flow workspace not initialized.");
6701 * Allocate and init new flow workspace.
6703 * @return pointer to flow workspace data, NULL on error.
6705 static struct mlx5_flow_workspace*
6706 flow_alloc_thread_workspace(void)
6708 struct mlx5_flow_workspace *data = calloc(1, sizeof(*data));
6711 DRV_LOG(ERR, "Failed to allocate flow workspace "
6715 data->rss_desc.queue = calloc(1,
6716 sizeof(uint16_t) * MLX5_RSSQ_DEFAULT_NUM);
6717 if (!data->rss_desc.queue)
6719 data->rssq_num = MLX5_RSSQ_DEFAULT_NUM;
6722 if (data->rss_desc.queue)
6723 free(data->rss_desc.queue);
6729 * Get new thread specific flow workspace.
6731 * If current workspace inuse, create new one and set as current.
6733 * @return pointer to thread specific flow workspace data, NULL on error.
6735 static struct mlx5_flow_workspace*
6736 mlx5_flow_push_thread_workspace(void)
6738 struct mlx5_flow_workspace *curr;
6739 struct mlx5_flow_workspace *data;
6741 curr = mlx5_flow_os_get_specific_workspace();
6743 data = flow_alloc_thread_workspace();
6746 } else if (!curr->inuse) {
6748 } else if (curr->next) {
6751 data = flow_alloc_thread_workspace();
6759 /* Set as current workspace */
6760 if (mlx5_flow_os_set_specific_workspace(data))
6761 DRV_LOG(ERR, "Failed to set flow workspace to thread.");
6766 * Close current thread specific flow workspace.
6768 * If previous workspace available, set it as current.
6770 * @return pointer to thread specific flow workspace data, NULL on error.
6773 mlx5_flow_pop_thread_workspace(void)
6775 struct mlx5_flow_workspace *data = mlx5_flow_get_thread_workspace();
6780 DRV_LOG(ERR, "Failed to close unused flow workspace.");
6786 if (mlx5_flow_os_set_specific_workspace(data->prev))
6787 DRV_LOG(ERR, "Failed to set flow workspace to thread.");
6791 * Verify the flow list is empty
6794 * Pointer to Ethernet device.
6796 * @return the number of flows not released.
6799 mlx5_flow_verify(struct rte_eth_dev *dev __rte_unused)
6801 struct mlx5_priv *priv = dev->data->dev_private;
6802 struct rte_flow *flow;
6806 for (i = 0; i < MLX5_FLOW_TYPE_MAXI; i++) {
6807 MLX5_IPOOL_FOREACH(priv->flows[i], idx, flow) {
6808 DRV_LOG(DEBUG, "port %u flow %p still referenced",
6809 dev->data->port_id, (void *)flow);
6817 * Enable default hairpin egress flow.
6820 * Pointer to Ethernet device.
6825 * 0 on success, a negative errno value otherwise and rte_errno is set.
6828 mlx5_ctrl_flow_source_queue(struct rte_eth_dev *dev,
6831 const struct rte_flow_attr attr = {
6835 struct mlx5_rte_flow_item_tx_queue queue_spec = {
6838 struct mlx5_rte_flow_item_tx_queue queue_mask = {
6839 .queue = UINT32_MAX,
6841 struct rte_flow_item items[] = {
6843 .type = (enum rte_flow_item_type)
6844 MLX5_RTE_FLOW_ITEM_TYPE_TX_QUEUE,
6845 .spec = &queue_spec,
6847 .mask = &queue_mask,
6850 .type = RTE_FLOW_ITEM_TYPE_END,
6853 struct rte_flow_action_jump jump = {
6854 .group = MLX5_HAIRPIN_TX_TABLE,
6856 struct rte_flow_action actions[2];
6858 struct rte_flow_error error;
6860 actions[0].type = RTE_FLOW_ACTION_TYPE_JUMP;
6861 actions[0].conf = &jump;
6862 actions[1].type = RTE_FLOW_ACTION_TYPE_END;
6863 flow_idx = flow_list_create(dev, MLX5_FLOW_TYPE_CTL,
6864 &attr, items, actions, false, &error);
6867 "Failed to create ctrl flow: rte_errno(%d),"
6868 " type(%d), message(%s)",
6869 rte_errno, error.type,
6870 error.message ? error.message : " (no stated reason)");
6877 * Enable a control flow configured from the control plane.
6880 * Pointer to Ethernet device.
6882 * An Ethernet flow spec to apply.
6884 * An Ethernet flow mask to apply.
6886 * A VLAN flow spec to apply.
6888 * A VLAN flow mask to apply.
6891 * 0 on success, a negative errno value otherwise and rte_errno is set.
6894 mlx5_ctrl_flow_vlan(struct rte_eth_dev *dev,
6895 struct rte_flow_item_eth *eth_spec,
6896 struct rte_flow_item_eth *eth_mask,
6897 struct rte_flow_item_vlan *vlan_spec,
6898 struct rte_flow_item_vlan *vlan_mask)
6900 struct mlx5_priv *priv = dev->data->dev_private;
6901 const struct rte_flow_attr attr = {
6903 .priority = MLX5_FLOW_LOWEST_PRIO_INDICATOR,
6905 struct rte_flow_item items[] = {
6907 .type = RTE_FLOW_ITEM_TYPE_ETH,
6913 .type = (vlan_spec) ? RTE_FLOW_ITEM_TYPE_VLAN :
6914 RTE_FLOW_ITEM_TYPE_END,
6920 .type = RTE_FLOW_ITEM_TYPE_END,
6923 uint16_t queue[priv->reta_idx_n];
6924 struct rte_flow_action_rss action_rss = {
6925 .func = RTE_ETH_HASH_FUNCTION_DEFAULT,
6927 .types = priv->rss_conf.rss_hf,
6928 .key_len = priv->rss_conf.rss_key_len,
6929 .queue_num = priv->reta_idx_n,
6930 .key = priv->rss_conf.rss_key,
6933 struct rte_flow_action actions[] = {
6935 .type = RTE_FLOW_ACTION_TYPE_RSS,
6936 .conf = &action_rss,
6939 .type = RTE_FLOW_ACTION_TYPE_END,
6943 struct rte_flow_error error;
6946 if (!priv->reta_idx_n || !priv->rxqs_n) {
6949 if (!(dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG))
6950 action_rss.types = 0;
6951 for (i = 0; i != priv->reta_idx_n; ++i)
6952 queue[i] = (*priv->reta_idx)[i];
6953 flow_idx = flow_list_create(dev, MLX5_FLOW_TYPE_CTL,
6954 &attr, items, actions, false, &error);
6961 * Enable a flow control configured from the control plane.
6964 * Pointer to Ethernet device.
6966 * An Ethernet flow spec to apply.
6968 * An Ethernet flow mask to apply.
6971 * 0 on success, a negative errno value otherwise and rte_errno is set.
6974 mlx5_ctrl_flow(struct rte_eth_dev *dev,
6975 struct rte_flow_item_eth *eth_spec,
6976 struct rte_flow_item_eth *eth_mask)
6978 return mlx5_ctrl_flow_vlan(dev, eth_spec, eth_mask, NULL, NULL);
6982 * Create default miss flow rule matching lacp traffic
6985 * Pointer to Ethernet device.
6987 * An Ethernet flow spec to apply.
6990 * 0 on success, a negative errno value otherwise and rte_errno is set.
6993 mlx5_flow_lacp_miss(struct rte_eth_dev *dev)
6996 * The LACP matching is done by only using ether type since using
6997 * a multicast dst mac causes kernel to give low priority to this flow.
6999 static const struct rte_flow_item_eth lacp_spec = {
7000 .type = RTE_BE16(0x8809),
7002 static const struct rte_flow_item_eth lacp_mask = {
7005 const struct rte_flow_attr attr = {
7008 struct rte_flow_item items[] = {
7010 .type = RTE_FLOW_ITEM_TYPE_ETH,
7015 .type = RTE_FLOW_ITEM_TYPE_END,
7018 struct rte_flow_action actions[] = {
7020 .type = (enum rte_flow_action_type)
7021 MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS,
7024 .type = RTE_FLOW_ACTION_TYPE_END,
7027 struct rte_flow_error error;
7028 uint32_t flow_idx = flow_list_create(dev, MLX5_FLOW_TYPE_CTL,
7029 &attr, items, actions,
7040 * @see rte_flow_destroy()
7044 mlx5_flow_destroy(struct rte_eth_dev *dev,
7045 struct rte_flow *flow,
7046 struct rte_flow_error *error __rte_unused)
7048 flow_list_destroy(dev, MLX5_FLOW_TYPE_GEN,
7049 (uintptr_t)(void *)flow);
7054 * Destroy all flows.
7056 * @see rte_flow_flush()
7060 mlx5_flow_flush(struct rte_eth_dev *dev,
7061 struct rte_flow_error *error __rte_unused)
7063 mlx5_flow_list_flush(dev, MLX5_FLOW_TYPE_GEN, false);
7070 * @see rte_flow_isolate()
7074 mlx5_flow_isolate(struct rte_eth_dev *dev,
7076 struct rte_flow_error *error)
7078 struct mlx5_priv *priv = dev->data->dev_private;
7080 if (dev->data->dev_started) {
7081 rte_flow_error_set(error, EBUSY,
7082 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7084 "port must be stopped first");
7087 priv->isolated = !!enable;
7089 dev->dev_ops = &mlx5_dev_ops_isolate;
7091 dev->dev_ops = &mlx5_dev_ops;
7093 dev->rx_descriptor_status = mlx5_rx_descriptor_status;
7094 dev->tx_descriptor_status = mlx5_tx_descriptor_status;
7102 * @see rte_flow_query()
7106 flow_drv_query(struct rte_eth_dev *dev,
7108 const struct rte_flow_action *actions,
7110 struct rte_flow_error *error)
7112 struct mlx5_priv *priv = dev->data->dev_private;
7113 const struct mlx5_flow_driver_ops *fops;
7114 struct rte_flow *flow = mlx5_ipool_get(priv->flows[MLX5_FLOW_TYPE_GEN],
7116 enum mlx5_flow_drv_type ftype;
7119 return rte_flow_error_set(error, ENOENT,
7120 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7122 "invalid flow handle");
7124 ftype = flow->drv_type;
7125 MLX5_ASSERT(ftype > MLX5_FLOW_TYPE_MIN && ftype < MLX5_FLOW_TYPE_MAX);
7126 fops = flow_get_drv_ops(ftype);
7128 return fops->query(dev, flow, actions, data, error);
7134 * @see rte_flow_query()
7138 mlx5_flow_query(struct rte_eth_dev *dev,
7139 struct rte_flow *flow,
7140 const struct rte_flow_action *actions,
7142 struct rte_flow_error *error)
7146 ret = flow_drv_query(dev, (uintptr_t)(void *)flow, actions, data,
7154 * Get rte_flow callbacks.
7157 * Pointer to Ethernet device structure.
7159 * Pointer to operation-specific structure.
7164 mlx5_flow_ops_get(struct rte_eth_dev *dev __rte_unused,
7165 const struct rte_flow_ops **ops)
7167 *ops = &mlx5_flow_ops;
7172 * Validate meter policy actions.
7173 * Dispatcher for action type specific validation.
7176 * Pointer to the Ethernet device structure.
7178 * The meter policy action object to validate.
7180 * Attributes of flow to determine steering domain.
7181 * @param[out] is_rss
7183 * @param[out] domain_bitmap
7185 * @param[out] is_def_policy
7186 * Is default policy or not.
7188 * Perform verbose error reporting if not NULL. Initialized in case of
7192 * 0 on success, otherwise negative errno value.
7195 mlx5_flow_validate_mtr_acts(struct rte_eth_dev *dev,
7196 const struct rte_flow_action *actions[RTE_COLORS],
7197 struct rte_flow_attr *attr,
7199 uint8_t *domain_bitmap,
7200 uint8_t *policy_mode,
7201 struct rte_mtr_error *error)
7203 const struct mlx5_flow_driver_ops *fops;
7205 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7206 return fops->validate_mtr_acts(dev, actions, attr, is_rss,
7207 domain_bitmap, policy_mode, error);
7211 * Destroy the meter table set.
7214 * Pointer to Ethernet device.
7215 * @param[in] mtr_policy
7216 * Meter policy struct.
7219 mlx5_flow_destroy_mtr_acts(struct rte_eth_dev *dev,
7220 struct mlx5_flow_meter_policy *mtr_policy)
7222 const struct mlx5_flow_driver_ops *fops;
7224 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7225 fops->destroy_mtr_acts(dev, mtr_policy);
7229 * Create policy action, lock free,
7230 * (mutex should be acquired by caller).
7231 * Dispatcher for action type specific call.
7234 * Pointer to the Ethernet device structure.
7235 * @param[in] mtr_policy
7236 * Meter policy struct.
7238 * Action specification used to create meter actions.
7240 * Perform verbose error reporting if not NULL. Initialized in case of
7244 * 0 on success, otherwise negative errno value.
7247 mlx5_flow_create_mtr_acts(struct rte_eth_dev *dev,
7248 struct mlx5_flow_meter_policy *mtr_policy,
7249 const struct rte_flow_action *actions[RTE_COLORS],
7250 struct rte_mtr_error *error)
7252 const struct mlx5_flow_driver_ops *fops;
7254 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7255 return fops->create_mtr_acts(dev, mtr_policy, actions, error);
7259 * Create policy rules, lock free,
7260 * (mutex should be acquired by caller).
7261 * Dispatcher for action type specific call.
7264 * Pointer to the Ethernet device structure.
7265 * @param[in] mtr_policy
7266 * Meter policy struct.
7269 * 0 on success, -1 otherwise.
7272 mlx5_flow_create_policy_rules(struct rte_eth_dev *dev,
7273 struct mlx5_flow_meter_policy *mtr_policy)
7275 const struct mlx5_flow_driver_ops *fops;
7277 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7278 return fops->create_policy_rules(dev, mtr_policy);
7282 * Destroy policy rules, lock free,
7283 * (mutex should be acquired by caller).
7284 * Dispatcher for action type specific call.
7287 * Pointer to the Ethernet device structure.
7288 * @param[in] mtr_policy
7289 * Meter policy struct.
7292 mlx5_flow_destroy_policy_rules(struct rte_eth_dev *dev,
7293 struct mlx5_flow_meter_policy *mtr_policy)
7295 const struct mlx5_flow_driver_ops *fops;
7297 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7298 fops->destroy_policy_rules(dev, mtr_policy);
7302 * Destroy the default policy table set.
7305 * Pointer to Ethernet device.
7308 mlx5_flow_destroy_def_policy(struct rte_eth_dev *dev)
7310 const struct mlx5_flow_driver_ops *fops;
7312 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7313 fops->destroy_def_policy(dev);
7317 * Destroy the default policy table set.
7320 * Pointer to Ethernet device.
7323 * 0 on success, -1 otherwise.
7326 mlx5_flow_create_def_policy(struct rte_eth_dev *dev)
7328 const struct mlx5_flow_driver_ops *fops;
7330 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7331 return fops->create_def_policy(dev);
7335 * Create the needed meter and suffix tables.
7338 * Pointer to Ethernet device.
7341 * 0 on success, -1 otherwise.
7344 mlx5_flow_create_mtr_tbls(struct rte_eth_dev *dev,
7345 struct mlx5_flow_meter_info *fm,
7347 uint8_t domain_bitmap)
7349 const struct mlx5_flow_driver_ops *fops;
7351 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7352 return fops->create_mtr_tbls(dev, fm, mtr_idx, domain_bitmap);
7356 * Destroy the meter table set.
7359 * Pointer to Ethernet device.
7361 * Pointer to the meter table set.
7364 mlx5_flow_destroy_mtr_tbls(struct rte_eth_dev *dev,
7365 struct mlx5_flow_meter_info *fm)
7367 const struct mlx5_flow_driver_ops *fops;
7369 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7370 fops->destroy_mtr_tbls(dev, fm);
7374 * Destroy the global meter drop table.
7377 * Pointer to Ethernet device.
7380 mlx5_flow_destroy_mtr_drop_tbls(struct rte_eth_dev *dev)
7382 const struct mlx5_flow_driver_ops *fops;
7384 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7385 fops->destroy_mtr_drop_tbls(dev);
7389 * Destroy the sub policy table with RX queue.
7392 * Pointer to Ethernet device.
7393 * @param[in] mtr_policy
7394 * Pointer to meter policy table.
7397 mlx5_flow_destroy_sub_policy_with_rxq(struct rte_eth_dev *dev,
7398 struct mlx5_flow_meter_policy *mtr_policy)
7400 const struct mlx5_flow_driver_ops *fops;
7402 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7403 fops->destroy_sub_policy_with_rxq(dev, mtr_policy);
7407 * Allocate the needed aso flow meter id.
7410 * Pointer to Ethernet device.
7413 * Index to aso flow meter on success, NULL otherwise.
7416 mlx5_flow_mtr_alloc(struct rte_eth_dev *dev)
7418 const struct mlx5_flow_driver_ops *fops;
7420 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7421 return fops->create_meter(dev);
7425 * Free the aso flow meter id.
7428 * Pointer to Ethernet device.
7429 * @param[in] mtr_idx
7430 * Index to aso flow meter to be free.
7436 mlx5_flow_mtr_free(struct rte_eth_dev *dev, uint32_t mtr_idx)
7438 const struct mlx5_flow_driver_ops *fops;
7440 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7441 fops->free_meter(dev, mtr_idx);
7445 * Allocate a counter.
7448 * Pointer to Ethernet device structure.
7451 * Index to allocated counter on success, 0 otherwise.
7454 mlx5_counter_alloc(struct rte_eth_dev *dev)
7456 const struct mlx5_flow_driver_ops *fops;
7457 struct rte_flow_attr attr = { .transfer = 0 };
7459 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
7460 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7461 return fops->counter_alloc(dev);
7464 "port %u counter allocate is not supported.",
7465 dev->data->port_id);
7473 * Pointer to Ethernet device structure.
7475 * Index to counter to be free.
7478 mlx5_counter_free(struct rte_eth_dev *dev, uint32_t cnt)
7480 const struct mlx5_flow_driver_ops *fops;
7481 struct rte_flow_attr attr = { .transfer = 0 };
7483 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
7484 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7485 fops->counter_free(dev, cnt);
7489 "port %u counter free is not supported.",
7490 dev->data->port_id);
7494 * Query counter statistics.
7497 * Pointer to Ethernet device structure.
7499 * Index to counter to query.
7501 * Set to clear counter statistics.
7503 * The counter hits packets number to save.
7505 * The counter hits bytes number to save.
7508 * 0 on success, a negative errno value otherwise.
7511 mlx5_counter_query(struct rte_eth_dev *dev, uint32_t cnt,
7512 bool clear, uint64_t *pkts, uint64_t *bytes)
7514 const struct mlx5_flow_driver_ops *fops;
7515 struct rte_flow_attr attr = { .transfer = 0 };
7517 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
7518 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7519 return fops->counter_query(dev, cnt, clear, pkts, bytes);
7522 "port %u counter query is not supported.",
7523 dev->data->port_id);
7528 * Allocate a new memory for the counter values wrapped by all the needed
7532 * Pointer to mlx5_dev_ctx_shared object.
7535 * 0 on success, a negative errno value otherwise.
7538 mlx5_flow_create_counter_stat_mem_mng(struct mlx5_dev_ctx_shared *sh)
7540 struct mlx5_devx_mkey_attr mkey_attr;
7541 struct mlx5_counter_stats_mem_mng *mem_mng;
7542 volatile struct flow_counter_stats *raw_data;
7543 int raws_n = MLX5_CNT_CONTAINER_RESIZE + MLX5_MAX_PENDING_QUERIES;
7544 int size = (sizeof(struct flow_counter_stats) *
7545 MLX5_COUNTERS_PER_POOL +
7546 sizeof(struct mlx5_counter_stats_raw)) * raws_n +
7547 sizeof(struct mlx5_counter_stats_mem_mng);
7548 size_t pgsize = rte_mem_page_size();
7552 if (pgsize == (size_t)-1) {
7553 DRV_LOG(ERR, "Failed to get mem page size");
7557 mem = mlx5_malloc(MLX5_MEM_ZERO, size, pgsize, SOCKET_ID_ANY);
7562 mem_mng = (struct mlx5_counter_stats_mem_mng *)(mem + size) - 1;
7563 size = sizeof(*raw_data) * MLX5_COUNTERS_PER_POOL * raws_n;
7564 mem_mng->umem = mlx5_os_umem_reg(sh->ctx, mem, size,
7565 IBV_ACCESS_LOCAL_WRITE);
7566 if (!mem_mng->umem) {
7571 memset(&mkey_attr, 0, sizeof(mkey_attr));
7572 mkey_attr.addr = (uintptr_t)mem;
7573 mkey_attr.size = size;
7574 mkey_attr.umem_id = mlx5_os_get_umem_id(mem_mng->umem);
7575 mkey_attr.pd = sh->pdn;
7576 mkey_attr.relaxed_ordering_write = sh->cmng.relaxed_ordering_write;
7577 mkey_attr.relaxed_ordering_read = sh->cmng.relaxed_ordering_read;
7578 mem_mng->dm = mlx5_devx_cmd_mkey_create(sh->ctx, &mkey_attr);
7580 mlx5_os_umem_dereg(mem_mng->umem);
7585 mem_mng->raws = (struct mlx5_counter_stats_raw *)(mem + size);
7586 raw_data = (volatile struct flow_counter_stats *)mem;
7587 for (i = 0; i < raws_n; ++i) {
7588 mem_mng->raws[i].mem_mng = mem_mng;
7589 mem_mng->raws[i].data = raw_data + i * MLX5_COUNTERS_PER_POOL;
7591 for (i = 0; i < MLX5_MAX_PENDING_QUERIES; ++i)
7592 LIST_INSERT_HEAD(&sh->cmng.free_stat_raws,
7593 mem_mng->raws + MLX5_CNT_CONTAINER_RESIZE + i,
7595 LIST_INSERT_HEAD(&sh->cmng.mem_mngs, mem_mng, next);
7596 sh->cmng.mem_mng = mem_mng;
7601 * Set the statistic memory to the new counter pool.
7604 * Pointer to mlx5_dev_ctx_shared object.
7606 * Pointer to the pool to set the statistic memory.
7609 * 0 on success, a negative errno value otherwise.
7612 mlx5_flow_set_counter_stat_mem(struct mlx5_dev_ctx_shared *sh,
7613 struct mlx5_flow_counter_pool *pool)
7615 struct mlx5_flow_counter_mng *cmng = &sh->cmng;
7616 /* Resize statistic memory once used out. */
7617 if (!(pool->index % MLX5_CNT_CONTAINER_RESIZE) &&
7618 mlx5_flow_create_counter_stat_mem_mng(sh)) {
7619 DRV_LOG(ERR, "Cannot resize counter stat mem.");
7622 rte_spinlock_lock(&pool->sl);
7623 pool->raw = cmng->mem_mng->raws + pool->index %
7624 MLX5_CNT_CONTAINER_RESIZE;
7625 rte_spinlock_unlock(&pool->sl);
7626 pool->raw_hw = NULL;
7630 #define MLX5_POOL_QUERY_FREQ_US 1000000
7633 * Set the periodic procedure for triggering asynchronous batch queries for all
7634 * the counter pools.
7637 * Pointer to mlx5_dev_ctx_shared object.
7640 mlx5_set_query_alarm(struct mlx5_dev_ctx_shared *sh)
7642 uint32_t pools_n, us;
7644 pools_n = __atomic_load_n(&sh->cmng.n_valid, __ATOMIC_RELAXED);
7645 us = MLX5_POOL_QUERY_FREQ_US / pools_n;
7646 DRV_LOG(DEBUG, "Set alarm for %u pools each %u us", pools_n, us);
7647 if (rte_eal_alarm_set(us, mlx5_flow_query_alarm, sh)) {
7648 sh->cmng.query_thread_on = 0;
7649 DRV_LOG(ERR, "Cannot reinitialize query alarm");
7651 sh->cmng.query_thread_on = 1;
7656 * The periodic procedure for triggering asynchronous batch queries for all the
7657 * counter pools. This function is probably called by the host thread.
7660 * The parameter for the alarm process.
7663 mlx5_flow_query_alarm(void *arg)
7665 struct mlx5_dev_ctx_shared *sh = arg;
7667 uint16_t pool_index = sh->cmng.pool_index;
7668 struct mlx5_flow_counter_mng *cmng = &sh->cmng;
7669 struct mlx5_flow_counter_pool *pool;
7672 if (sh->cmng.pending_queries >= MLX5_MAX_PENDING_QUERIES)
7674 rte_spinlock_lock(&cmng->pool_update_sl);
7675 pool = cmng->pools[pool_index];
7676 n_valid = cmng->n_valid;
7677 rte_spinlock_unlock(&cmng->pool_update_sl);
7678 /* Set the statistic memory to the new created pool. */
7679 if ((!pool->raw && mlx5_flow_set_counter_stat_mem(sh, pool)))
7682 /* There is a pool query in progress. */
7685 LIST_FIRST(&sh->cmng.free_stat_raws);
7687 /* No free counter statistics raw memory. */
7690 * Identify the counters released between query trigger and query
7691 * handle more efficiently. The counter released in this gap period
7692 * should wait for a new round of query as the new arrived packets
7693 * will not be taken into account.
7696 ret = mlx5_devx_cmd_flow_counter_query(pool->min_dcs, 0,
7697 MLX5_COUNTERS_PER_POOL,
7699 pool->raw_hw->mem_mng->dm->id,
7703 (uint64_t)(uintptr_t)pool);
7705 DRV_LOG(ERR, "Failed to trigger asynchronous query for dcs ID"
7706 " %d", pool->min_dcs->id);
7707 pool->raw_hw = NULL;
7710 LIST_REMOVE(pool->raw_hw, next);
7711 sh->cmng.pending_queries++;
7713 if (pool_index >= n_valid)
7716 sh->cmng.pool_index = pool_index;
7717 mlx5_set_query_alarm(sh);
7721 * Check and callback event for new aged flow in the counter pool
7724 * Pointer to mlx5_dev_ctx_shared object.
7726 * Pointer to Current counter pool.
7729 mlx5_flow_aging_check(struct mlx5_dev_ctx_shared *sh,
7730 struct mlx5_flow_counter_pool *pool)
7732 struct mlx5_priv *priv;
7733 struct mlx5_flow_counter *cnt;
7734 struct mlx5_age_info *age_info;
7735 struct mlx5_age_param *age_param;
7736 struct mlx5_counter_stats_raw *cur = pool->raw_hw;
7737 struct mlx5_counter_stats_raw *prev = pool->raw;
7738 const uint64_t curr_time = MLX5_CURR_TIME_SEC;
7739 const uint32_t time_delta = curr_time - pool->time_of_last_age_check;
7740 uint16_t expected = AGE_CANDIDATE;
7743 pool->time_of_last_age_check = curr_time;
7744 for (i = 0; i < MLX5_COUNTERS_PER_POOL; ++i) {
7745 cnt = MLX5_POOL_GET_CNT(pool, i);
7746 age_param = MLX5_CNT_TO_AGE(cnt);
7747 if (__atomic_load_n(&age_param->state,
7748 __ATOMIC_RELAXED) != AGE_CANDIDATE)
7750 if (cur->data[i].hits != prev->data[i].hits) {
7751 __atomic_store_n(&age_param->sec_since_last_hit, 0,
7755 if (__atomic_add_fetch(&age_param->sec_since_last_hit,
7757 __ATOMIC_RELAXED) <= age_param->timeout)
7760 * Hold the lock first, or if between the
7761 * state AGE_TMOUT and tailq operation the
7762 * release happened, the release procedure
7763 * may delete a non-existent tailq node.
7765 priv = rte_eth_devices[age_param->port_id].data->dev_private;
7766 age_info = GET_PORT_AGE_INFO(priv);
7767 rte_spinlock_lock(&age_info->aged_sl);
7768 if (__atomic_compare_exchange_n(&age_param->state, &expected,
7771 __ATOMIC_RELAXED)) {
7772 TAILQ_INSERT_TAIL(&age_info->aged_counters, cnt, next);
7773 MLX5_AGE_SET(age_info, MLX5_AGE_EVENT_NEW);
7775 rte_spinlock_unlock(&age_info->aged_sl);
7777 mlx5_age_event_prepare(sh);
7781 * Handler for the HW respond about ready values from an asynchronous batch
7782 * query. This function is probably called by the host thread.
7785 * The pointer to the shared device context.
7786 * @param[in] async_id
7787 * The Devx async ID.
7789 * The status of the completion.
7792 mlx5_flow_async_pool_query_handle(struct mlx5_dev_ctx_shared *sh,
7793 uint64_t async_id, int status)
7795 struct mlx5_flow_counter_pool *pool =
7796 (struct mlx5_flow_counter_pool *)(uintptr_t)async_id;
7797 struct mlx5_counter_stats_raw *raw_to_free;
7798 uint8_t query_gen = pool->query_gen ^ 1;
7799 struct mlx5_flow_counter_mng *cmng = &sh->cmng;
7800 enum mlx5_counter_type cnt_type =
7801 pool->is_aged ? MLX5_COUNTER_TYPE_AGE :
7802 MLX5_COUNTER_TYPE_ORIGIN;
7804 if (unlikely(status)) {
7805 raw_to_free = pool->raw_hw;
7807 raw_to_free = pool->raw;
7809 mlx5_flow_aging_check(sh, pool);
7810 rte_spinlock_lock(&pool->sl);
7811 pool->raw = pool->raw_hw;
7812 rte_spinlock_unlock(&pool->sl);
7813 /* Be sure the new raw counters data is updated in memory. */
7815 if (!TAILQ_EMPTY(&pool->counters[query_gen])) {
7816 rte_spinlock_lock(&cmng->csl[cnt_type]);
7817 TAILQ_CONCAT(&cmng->counters[cnt_type],
7818 &pool->counters[query_gen], next);
7819 rte_spinlock_unlock(&cmng->csl[cnt_type]);
7822 LIST_INSERT_HEAD(&sh->cmng.free_stat_raws, raw_to_free, next);
7823 pool->raw_hw = NULL;
7824 sh->cmng.pending_queries--;
7828 flow_group_to_table(uint32_t port_id, uint32_t group, uint32_t *table,
7829 const struct flow_grp_info *grp_info,
7830 struct rte_flow_error *error)
7832 if (grp_info->transfer && grp_info->external &&
7833 grp_info->fdb_def_rule) {
7834 if (group == UINT32_MAX)
7835 return rte_flow_error_set
7837 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
7839 "group index not supported");
7844 DRV_LOG(DEBUG, "port %u group=%#x table=%#x", port_id, group, *table);
7849 * Translate the rte_flow group index to HW table value.
7851 * If tunnel offload is disabled, all group ids converted to flow table
7852 * id using the standard method.
7853 * If tunnel offload is enabled, group id can be converted using the
7854 * standard or tunnel conversion method. Group conversion method
7855 * selection depends on flags in `grp_info` parameter:
7856 * - Internal (grp_info.external == 0) groups conversion uses the
7858 * - Group ids in JUMP action converted with the tunnel conversion.
7859 * - Group id in rule attribute conversion depends on a rule type and
7861 * ** non zero group attributes converted with the tunnel method
7862 * ** zero group attribute in non-tunnel rule is converted using the
7863 * standard method - there's only one root table
7864 * ** zero group attribute in steer tunnel rule is converted with the
7865 * standard method - single root table
7866 * ** zero group attribute in match tunnel rule is a special OvS
7867 * case: that value is used for portability reasons. That group
7868 * id is converted with the tunnel conversion method.
7873 * PMD tunnel offload object
7875 * rte_flow group index value.
7878 * @param[in] grp_info
7879 * flags used for conversion
7881 * Pointer to error structure.
7884 * 0 on success, a negative errno value otherwise and rte_errno is set.
7887 mlx5_flow_group_to_table(struct rte_eth_dev *dev,
7888 const struct mlx5_flow_tunnel *tunnel,
7889 uint32_t group, uint32_t *table,
7890 const struct flow_grp_info *grp_info,
7891 struct rte_flow_error *error)
7894 bool standard_translation;
7896 if (!grp_info->skip_scale && grp_info->external &&
7897 group < MLX5_MAX_TABLES_EXTERNAL)
7898 group *= MLX5_FLOW_TABLE_FACTOR;
7899 if (is_tunnel_offload_active(dev)) {
7900 standard_translation = !grp_info->external ||
7901 grp_info->std_tbl_fix;
7903 standard_translation = true;
7906 "port %u group=%u transfer=%d external=%d fdb_def_rule=%d translate=%s",
7907 dev->data->port_id, group, grp_info->transfer,
7908 grp_info->external, grp_info->fdb_def_rule,
7909 standard_translation ? "STANDARD" : "TUNNEL");
7910 if (standard_translation)
7911 ret = flow_group_to_table(dev->data->port_id, group, table,
7914 ret = tunnel_flow_group_to_flow_table(dev, tunnel, group,
7921 * Discover availability of metadata reg_c's.
7923 * Iteratively use test flows to check availability.
7926 * Pointer to the Ethernet device structure.
7929 * 0 on success, a negative errno value otherwise and rte_errno is set.
7932 mlx5_flow_discover_mreg_c(struct rte_eth_dev *dev)
7934 struct mlx5_priv *priv = dev->data->dev_private;
7935 struct mlx5_dev_config *config = &priv->config;
7936 enum modify_reg idx;
7939 /* reg_c[0] and reg_c[1] are reserved. */
7940 config->flow_mreg_c[n++] = REG_C_0;
7941 config->flow_mreg_c[n++] = REG_C_1;
7942 /* Discover availability of other reg_c's. */
7943 for (idx = REG_C_2; idx <= REG_C_7; ++idx) {
7944 struct rte_flow_attr attr = {
7945 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
7946 .priority = MLX5_FLOW_LOWEST_PRIO_INDICATOR,
7949 struct rte_flow_item items[] = {
7951 .type = RTE_FLOW_ITEM_TYPE_END,
7954 struct rte_flow_action actions[] = {
7956 .type = (enum rte_flow_action_type)
7957 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
7958 .conf = &(struct mlx5_flow_action_copy_mreg){
7964 .type = RTE_FLOW_ACTION_TYPE_JUMP,
7965 .conf = &(struct rte_flow_action_jump){
7966 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
7970 .type = RTE_FLOW_ACTION_TYPE_END,
7974 struct rte_flow *flow;
7975 struct rte_flow_error error;
7977 if (!config->dv_flow_en)
7979 /* Create internal flow, validation skips copy action. */
7980 flow_idx = flow_list_create(dev, MLX5_FLOW_TYPE_GEN, &attr,
7981 items, actions, false, &error);
7982 flow = mlx5_ipool_get(priv->flows[MLX5_FLOW_TYPE_GEN],
7986 config->flow_mreg_c[n++] = idx;
7987 flow_list_destroy(dev, MLX5_FLOW_TYPE_GEN, flow_idx);
7989 for (; n < MLX5_MREG_C_NUM; ++n)
7990 config->flow_mreg_c[n] = REG_NON;
7995 save_dump_file(const uint8_t *data, uint32_t size,
7996 uint32_t type, uint32_t id, void *arg, FILE *file)
7998 char line[BUF_SIZE];
8001 uint32_t actions_num;
8002 struct rte_flow_query_count *count;
8004 memset(line, 0, BUF_SIZE);
8006 case DR_DUMP_REC_TYPE_PMD_MODIFY_HDR:
8007 actions_num = *(uint32_t *)(arg);
8008 out += snprintf(line + out, BUF_SIZE - out, "%d,0x%x,%d,",
8009 type, id, actions_num);
8011 case DR_DUMP_REC_TYPE_PMD_PKT_REFORMAT:
8012 out += snprintf(line + out, BUF_SIZE - out, "%d,0x%x,",
8015 case DR_DUMP_REC_TYPE_PMD_COUNTER:
8016 count = (struct rte_flow_query_count *)arg;
8017 fprintf(file, "%d,0x%x,%" PRIu64 ",%" PRIu64 "\n", type,
8018 id, count->hits, count->bytes);
8024 for (k = 0; k < size; k++) {
8025 /* Make sure we do not overrun the line buffer length. */
8026 if (out >= BUF_SIZE - 4) {
8030 out += snprintf(line + out, BUF_SIZE - out, "%02x",
8033 fprintf(file, "%s\n", line);
8038 mlx5_flow_query_counter(struct rte_eth_dev *dev, struct rte_flow *flow,
8039 struct rte_flow_query_count *count, struct rte_flow_error *error)
8041 struct rte_flow_action action[2];
8042 enum mlx5_flow_drv_type ftype;
8043 const struct mlx5_flow_driver_ops *fops;
8046 return rte_flow_error_set(error, ENOENT,
8047 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8049 "invalid flow handle");
8051 action[0].type = RTE_FLOW_ACTION_TYPE_COUNT;
8052 action[1].type = RTE_FLOW_ACTION_TYPE_END;
8053 if (flow->counter) {
8054 memset(count, 0, sizeof(struct rte_flow_query_count));
8055 ftype = (enum mlx5_flow_drv_type)(flow->drv_type);
8056 MLX5_ASSERT(ftype > MLX5_FLOW_TYPE_MIN &&
8057 ftype < MLX5_FLOW_TYPE_MAX);
8058 fops = flow_get_drv_ops(ftype);
8059 return fops->query(dev, flow, action, count, error);
8064 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
8066 * Dump flow ipool data to file
8069 * The pointer to Ethernet device.
8071 * A pointer to a file for output.
8073 * Perform verbose error reporting if not NULL. PMDs initialize this
8074 * structure in case of error only.
8076 * 0 on success, a negative value otherwise.
8079 mlx5_flow_dev_dump_ipool(struct rte_eth_dev *dev,
8080 struct rte_flow *flow, FILE *file,
8081 struct rte_flow_error *error)
8083 struct mlx5_priv *priv = dev->data->dev_private;
8084 struct mlx5_flow_dv_modify_hdr_resource *modify_hdr;
8085 struct mlx5_flow_dv_encap_decap_resource *encap_decap;
8086 uint32_t handle_idx;
8087 struct mlx5_flow_handle *dh;
8088 struct rte_flow_query_count count;
8089 uint32_t actions_num;
8090 const uint8_t *data;
8096 return rte_flow_error_set(error, ENOENT,
8097 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8099 "invalid flow handle");
8101 handle_idx = flow->dev_handles;
8102 while (handle_idx) {
8103 dh = mlx5_ipool_get(priv->sh->ipool
8104 [MLX5_IPOOL_MLX5_FLOW], handle_idx);
8107 handle_idx = dh->next.next;
8108 id = (uint32_t)(uintptr_t)dh->drv_flow;
8111 type = DR_DUMP_REC_TYPE_PMD_COUNTER;
8112 if (!mlx5_flow_query_counter(dev, flow, &count, error))
8113 save_dump_file(NULL, 0, type,
8114 id, (void *)&count, file);
8116 /* Get modify_hdr and encap_decap buf from ipools. */
8118 modify_hdr = dh->dvh.modify_hdr;
8120 if (dh->dvh.rix_encap_decap) {
8121 encap_decap = mlx5_ipool_get(priv->sh->ipool
8122 [MLX5_IPOOL_DECAP_ENCAP],
8123 dh->dvh.rix_encap_decap);
8126 data = (const uint8_t *)modify_hdr->actions;
8127 size = (size_t)(modify_hdr->actions_num) * 8;
8128 actions_num = modify_hdr->actions_num;
8129 type = DR_DUMP_REC_TYPE_PMD_MODIFY_HDR;
8130 save_dump_file(data, size, type, id,
8131 (void *)(&actions_num), file);
8134 data = encap_decap->buf;
8135 size = encap_decap->size;
8136 type = DR_DUMP_REC_TYPE_PMD_PKT_REFORMAT;
8137 save_dump_file(data, size, type,
8146 * Dump flow raw hw data to file
8149 * The pointer to Ethernet device.
8151 * A pointer to a file for output.
8153 * Perform verbose error reporting if not NULL. PMDs initialize this
8154 * structure in case of error only.
8156 * 0 on success, a nagative value otherwise.
8159 mlx5_flow_dev_dump(struct rte_eth_dev *dev, struct rte_flow *flow_idx,
8161 struct rte_flow_error *error __rte_unused)
8163 struct mlx5_priv *priv = dev->data->dev_private;
8164 struct mlx5_dev_ctx_shared *sh = priv->sh;
8165 uint32_t handle_idx;
8167 struct mlx5_flow_handle *dh;
8168 struct rte_flow *flow;
8169 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
8173 if (!priv->config.dv_flow_en) {
8174 if (fputs("device dv flow disabled\n", file) <= 0)
8181 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
8182 MLX5_IPOOL_FOREACH(priv->flows[MLX5_FLOW_TYPE_GEN], idx, flow)
8183 mlx5_flow_dev_dump_ipool(dev, flow, file, error);
8185 return mlx5_devx_cmd_flow_dump(sh->fdb_domain,
8187 sh->tx_domain, file);
8190 flow = mlx5_ipool_get(priv->flows[MLX5_FLOW_TYPE_GEN],
8191 (uintptr_t)(void *)flow_idx);
8195 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
8196 mlx5_flow_dev_dump_ipool(dev, flow, file, error);
8198 handle_idx = flow->dev_handles;
8199 while (handle_idx) {
8200 dh = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
8205 ret = mlx5_devx_cmd_flow_single_dump(dh->drv_flow,
8210 handle_idx = dh->next.next;
8216 * Get aged-out flows.
8219 * Pointer to the Ethernet device structure.
8220 * @param[in] context
8221 * The address of an array of pointers to the aged-out flows contexts.
8222 * @param[in] nb_countexts
8223 * The length of context array pointers.
8225 * Perform verbose error reporting if not NULL. Initialized in case of
8229 * how many contexts get in success, otherwise negative errno value.
8230 * if nb_contexts is 0, return the amount of all aged contexts.
8231 * if nb_contexts is not 0 , return the amount of aged flows reported
8232 * in the context array.
8235 mlx5_flow_get_aged_flows(struct rte_eth_dev *dev, void **contexts,
8236 uint32_t nb_contexts, struct rte_flow_error *error)
8238 const struct mlx5_flow_driver_ops *fops;
8239 struct rte_flow_attr attr = { .transfer = 0 };
8241 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
8242 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
8243 return fops->get_aged_flows(dev, contexts, nb_contexts,
8247 "port %u get aged flows is not supported.",
8248 dev->data->port_id);
8252 /* Wrapper for driver action_validate op callback */
8254 flow_drv_action_validate(struct rte_eth_dev *dev,
8255 const struct rte_flow_indir_action_conf *conf,
8256 const struct rte_flow_action *action,
8257 const struct mlx5_flow_driver_ops *fops,
8258 struct rte_flow_error *error)
8260 static const char err_msg[] = "indirect action validation unsupported";
8262 if (!fops->action_validate) {
8263 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
8264 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
8268 return fops->action_validate(dev, conf, action, error);
8272 * Destroys the shared action by handle.
8275 * Pointer to Ethernet device structure.
8277 * Handle for the indirect action object to be destroyed.
8279 * Perform verbose error reporting if not NULL. PMDs initialize this
8280 * structure in case of error only.
8283 * 0 on success, a negative errno value otherwise and rte_errno is set.
8285 * @note: wrapper for driver action_create op callback.
8288 mlx5_action_handle_destroy(struct rte_eth_dev *dev,
8289 struct rte_flow_action_handle *handle,
8290 struct rte_flow_error *error)
8292 static const char err_msg[] = "indirect action destruction unsupported";
8293 struct rte_flow_attr attr = { .transfer = 0 };
8294 const struct mlx5_flow_driver_ops *fops =
8295 flow_get_drv_ops(flow_get_drv_type(dev, &attr));
8297 if (!fops->action_destroy) {
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_destroy(dev, handle, error);
8306 /* Wrapper for driver action_destroy op callback */
8308 flow_drv_action_update(struct rte_eth_dev *dev,
8309 struct rte_flow_action_handle *handle,
8311 const struct mlx5_flow_driver_ops *fops,
8312 struct rte_flow_error *error)
8314 static const char err_msg[] = "indirect action update unsupported";
8316 if (!fops->action_update) {
8317 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
8318 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
8322 return fops->action_update(dev, handle, update, error);
8325 /* Wrapper for driver action_destroy op callback */
8327 flow_drv_action_query(struct rte_eth_dev *dev,
8328 const struct rte_flow_action_handle *handle,
8330 const struct mlx5_flow_driver_ops *fops,
8331 struct rte_flow_error *error)
8333 static const char err_msg[] = "indirect action query unsupported";
8335 if (!fops->action_query) {
8336 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
8337 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
8341 return fops->action_query(dev, handle, data, error);
8345 * Create indirect action for reuse in multiple flow rules.
8348 * Pointer to Ethernet device structure.
8350 * Pointer to indirect action object configuration.
8352 * Action configuration for indirect action object creation.
8354 * Perform verbose error reporting if not NULL. PMDs initialize this
8355 * structure in case of error only.
8357 * A valid handle in case of success, NULL otherwise and rte_errno is set.
8359 static struct rte_flow_action_handle *
8360 mlx5_action_handle_create(struct rte_eth_dev *dev,
8361 const struct rte_flow_indir_action_conf *conf,
8362 const struct rte_flow_action *action,
8363 struct rte_flow_error *error)
8365 static const char err_msg[] = "indirect action creation unsupported";
8366 struct rte_flow_attr attr = { .transfer = 0 };
8367 const struct mlx5_flow_driver_ops *fops =
8368 flow_get_drv_ops(flow_get_drv_type(dev, &attr));
8370 if (flow_drv_action_validate(dev, conf, action, fops, error))
8372 if (!fops->action_create) {
8373 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
8374 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
8378 return fops->action_create(dev, conf, action, error);
8382 * Updates inplace the indirect action configuration pointed by *handle*
8383 * with the configuration provided as *update* argument.
8384 * The update of the indirect action configuration effects all flow rules
8385 * reusing the action via handle.
8388 * Pointer to Ethernet device structure.
8390 * Handle for the indirect action to be updated.
8392 * Action specification used to modify the action pointed by handle.
8393 * *update* could be of same type with the action pointed by the *handle*
8394 * handle argument, or some other structures like a wrapper, depending on
8395 * the indirect action type.
8397 * Perform verbose error reporting if not NULL. PMDs initialize this
8398 * structure in case of error only.
8401 * 0 on success, a negative errno value otherwise and rte_errno is set.
8404 mlx5_action_handle_update(struct rte_eth_dev *dev,
8405 struct rte_flow_action_handle *handle,
8407 struct rte_flow_error *error)
8409 struct rte_flow_attr attr = { .transfer = 0 };
8410 const struct mlx5_flow_driver_ops *fops =
8411 flow_get_drv_ops(flow_get_drv_type(dev, &attr));
8414 ret = flow_drv_action_validate(dev, NULL,
8415 (const struct rte_flow_action *)update, fops, error);
8418 return flow_drv_action_update(dev, handle, update, fops,
8423 * Query the indirect action by handle.
8425 * This function allows retrieving action-specific data such as counters.
8426 * Data is gathered by special action which may be present/referenced in
8427 * more than one flow rule definition.
8429 * see @RTE_FLOW_ACTION_TYPE_COUNT
8432 * Pointer to Ethernet device structure.
8434 * Handle for the indirect action to query.
8435 * @param[in, out] data
8436 * Pointer to storage for the associated query data type.
8438 * Perform verbose error reporting if not NULL. PMDs initialize this
8439 * structure in case of error only.
8442 * 0 on success, a negative errno value otherwise and rte_errno is set.
8445 mlx5_action_handle_query(struct rte_eth_dev *dev,
8446 const struct rte_flow_action_handle *handle,
8448 struct rte_flow_error *error)
8450 struct rte_flow_attr attr = { .transfer = 0 };
8451 const struct mlx5_flow_driver_ops *fops =
8452 flow_get_drv_ops(flow_get_drv_type(dev, &attr));
8454 return flow_drv_action_query(dev, handle, data, fops, error);
8458 * Destroy all indirect actions (shared RSS).
8461 * Pointer to Ethernet device.
8464 * 0 on success, a negative errno value otherwise and rte_errno is set.
8467 mlx5_action_handle_flush(struct rte_eth_dev *dev)
8469 struct rte_flow_error error;
8470 struct mlx5_priv *priv = dev->data->dev_private;
8471 struct mlx5_shared_action_rss *shared_rss;
8475 ILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
8476 priv->rss_shared_actions, idx, shared_rss, next) {
8477 ret |= mlx5_action_handle_destroy(dev,
8478 (struct rte_flow_action_handle *)(uintptr_t)idx, &error);
8483 #ifndef HAVE_MLX5DV_DR
8484 #define MLX5_DOMAIN_SYNC_FLOW ((1 << 0) | (1 << 1))
8486 #define MLX5_DOMAIN_SYNC_FLOW \
8487 (MLX5DV_DR_DOMAIN_SYNC_FLAGS_SW | MLX5DV_DR_DOMAIN_SYNC_FLAGS_HW)
8490 int rte_pmd_mlx5_sync_flow(uint16_t port_id, uint32_t domains)
8492 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
8493 const struct mlx5_flow_driver_ops *fops;
8495 struct rte_flow_attr attr = { .transfer = 0 };
8497 fops = flow_get_drv_ops(flow_get_drv_type(dev, &attr));
8498 ret = fops->sync_domain(dev, domains, MLX5_DOMAIN_SYNC_FLOW);
8504 const struct mlx5_flow_tunnel *
8505 mlx5_get_tof(const struct rte_flow_item *item,
8506 const struct rte_flow_action *action,
8507 enum mlx5_tof_rule_type *rule_type)
8509 for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
8510 if (item->type == (typeof(item->type))
8511 MLX5_RTE_FLOW_ITEM_TYPE_TUNNEL) {
8512 *rule_type = MLX5_TUNNEL_OFFLOAD_MATCH_RULE;
8513 return flow_items_to_tunnel(item);
8516 for (; action->conf != RTE_FLOW_ACTION_TYPE_END; action++) {
8517 if (action->type == (typeof(action->type))
8518 MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET) {
8519 *rule_type = MLX5_TUNNEL_OFFLOAD_SET_RULE;
8520 return flow_actions_to_tunnel(action);
8527 * tunnel offload functionalilty is defined for DV environment only
8529 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
8531 union tunnel_offload_mark {
8534 uint32_t app_reserve:8;
8535 uint32_t table_id:15;
8536 uint32_t transfer:1;
8537 uint32_t _unused_:8;
8542 mlx5_access_tunnel_offload_db
8543 (struct rte_eth_dev *dev,
8544 bool (*match)(struct rte_eth_dev *,
8545 struct mlx5_flow_tunnel *, const void *),
8546 void (*hit)(struct rte_eth_dev *, struct mlx5_flow_tunnel *, void *),
8547 void (*miss)(struct rte_eth_dev *, void *),
8548 void *ctx, bool lock_op);
8551 flow_tunnel_add_default_miss(struct rte_eth_dev *dev,
8552 struct rte_flow *flow,
8553 const struct rte_flow_attr *attr,
8554 const struct rte_flow_action *app_actions,
8556 const struct mlx5_flow_tunnel *tunnel,
8557 struct tunnel_default_miss_ctx *ctx,
8558 struct rte_flow_error *error)
8560 struct mlx5_priv *priv = dev->data->dev_private;
8561 struct mlx5_flow *dev_flow;
8562 struct rte_flow_attr miss_attr = *attr;
8563 const struct rte_flow_item miss_items[2] = {
8565 .type = RTE_FLOW_ITEM_TYPE_ETH,
8571 .type = RTE_FLOW_ITEM_TYPE_END,
8577 union tunnel_offload_mark mark_id;
8578 struct rte_flow_action_mark miss_mark;
8579 struct rte_flow_action miss_actions[3] = {
8580 [0] = { .type = RTE_FLOW_ACTION_TYPE_MARK, .conf = &miss_mark },
8581 [2] = { .type = RTE_FLOW_ACTION_TYPE_END, .conf = NULL }
8583 const struct rte_flow_action_jump *jump_data;
8584 uint32_t i, flow_table = 0; /* prevent compilation warning */
8585 struct flow_grp_info grp_info = {
8587 .transfer = attr->transfer,
8588 .fdb_def_rule = !!priv->fdb_def_rule,
8593 if (!attr->transfer) {
8596 miss_actions[1].type = RTE_FLOW_ACTION_TYPE_RSS;
8597 q_size = priv->reta_idx_n * sizeof(ctx->queue[0]);
8598 ctx->queue = mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO, q_size,
8601 return rte_flow_error_set
8603 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
8604 NULL, "invalid default miss RSS");
8605 ctx->action_rss.func = RTE_ETH_HASH_FUNCTION_DEFAULT,
8606 ctx->action_rss.level = 0,
8607 ctx->action_rss.types = priv->rss_conf.rss_hf,
8608 ctx->action_rss.key_len = priv->rss_conf.rss_key_len,
8609 ctx->action_rss.queue_num = priv->reta_idx_n,
8610 ctx->action_rss.key = priv->rss_conf.rss_key,
8611 ctx->action_rss.queue = ctx->queue;
8612 if (!priv->reta_idx_n || !priv->rxqs_n)
8613 return rte_flow_error_set
8615 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
8616 NULL, "invalid port configuration");
8617 if (!(dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG))
8618 ctx->action_rss.types = 0;
8619 for (i = 0; i != priv->reta_idx_n; ++i)
8620 ctx->queue[i] = (*priv->reta_idx)[i];
8622 miss_actions[1].type = RTE_FLOW_ACTION_TYPE_JUMP;
8623 ctx->miss_jump.group = MLX5_TNL_MISS_FDB_JUMP_GRP;
8625 miss_actions[1].conf = (typeof(miss_actions[1].conf))ctx->raw;
8626 for (; app_actions->type != RTE_FLOW_ACTION_TYPE_JUMP; app_actions++);
8627 jump_data = app_actions->conf;
8628 miss_attr.priority = MLX5_TNL_MISS_RULE_PRIORITY;
8629 miss_attr.group = jump_data->group;
8630 ret = mlx5_flow_group_to_table(dev, tunnel, jump_data->group,
8631 &flow_table, &grp_info, error);
8633 return rte_flow_error_set(error, EINVAL,
8634 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
8635 NULL, "invalid tunnel id");
8636 mark_id.app_reserve = 0;
8637 mark_id.table_id = tunnel_flow_tbl_to_id(flow_table);
8638 mark_id.transfer = !!attr->transfer;
8639 mark_id._unused_ = 0;
8640 miss_mark.id = mark_id.val;
8641 dev_flow = flow_drv_prepare(dev, flow, &miss_attr,
8642 miss_items, miss_actions, flow_idx, error);
8645 dev_flow->flow = flow;
8646 dev_flow->external = true;
8647 dev_flow->tunnel = tunnel;
8648 dev_flow->tof_type = MLX5_TUNNEL_OFFLOAD_MISS_RULE;
8649 /* Subflow object was created, we must include one in the list. */
8650 SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
8651 dev_flow->handle, next);
8653 "port %u tunnel type=%d id=%u miss rule priority=%u group=%u",
8654 dev->data->port_id, tunnel->app_tunnel.type,
8655 tunnel->tunnel_id, miss_attr.priority, miss_attr.group);
8656 ret = flow_drv_translate(dev, dev_flow, &miss_attr, miss_items,
8657 miss_actions, error);
8659 ret = flow_mreg_update_copy_table(dev, flow, miss_actions,
8665 static const struct mlx5_flow_tbl_data_entry *
8666 tunnel_mark_decode(struct rte_eth_dev *dev, uint32_t mark)
8668 struct mlx5_priv *priv = dev->data->dev_private;
8669 struct mlx5_dev_ctx_shared *sh = priv->sh;
8670 struct mlx5_list_entry *he;
8671 union tunnel_offload_mark mbits = { .val = mark };
8672 union mlx5_flow_tbl_key table_key = {
8674 .level = tunnel_id_to_flow_tbl(mbits.table_id),
8678 .is_fdb = !!mbits.transfer,
8682 struct mlx5_flow_cb_ctx ctx = {
8683 .data = &table_key.v64,
8686 he = mlx5_hlist_lookup(sh->flow_tbls, table_key.v64, &ctx);
8688 container_of(he, struct mlx5_flow_tbl_data_entry, entry) : NULL;
8692 mlx5_flow_tunnel_grp2tbl_remove_cb(void *tool_ctx,
8693 struct mlx5_list_entry *entry)
8695 struct mlx5_dev_ctx_shared *sh = tool_ctx;
8696 struct tunnel_tbl_entry *tte = container_of(entry, typeof(*tte), hash);
8698 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TNL_TBL_ID],
8699 tunnel_flow_tbl_to_id(tte->flow_table));
8704 mlx5_flow_tunnel_grp2tbl_match_cb(void *tool_ctx __rte_unused,
8705 struct mlx5_list_entry *entry, void *cb_ctx)
8707 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
8708 union tunnel_tbl_key tbl = {
8709 .val = *(uint64_t *)(ctx->data),
8711 struct tunnel_tbl_entry *tte = container_of(entry, typeof(*tte), hash);
8713 return tbl.tunnel_id != tte->tunnel_id || tbl.group != tte->group;
8716 static struct mlx5_list_entry *
8717 mlx5_flow_tunnel_grp2tbl_create_cb(void *tool_ctx, void *cb_ctx)
8719 struct mlx5_dev_ctx_shared *sh = tool_ctx;
8720 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
8721 struct tunnel_tbl_entry *tte;
8722 union tunnel_tbl_key tbl = {
8723 .val = *(uint64_t *)(ctx->data),
8726 tte = mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO,
8731 mlx5_ipool_malloc(sh->ipool[MLX5_IPOOL_TNL_TBL_ID],
8733 if (tte->flow_table >= MLX5_MAX_TABLES) {
8734 DRV_LOG(ERR, "Tunnel TBL ID %d exceed max limit.",
8736 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TNL_TBL_ID],
8739 } else if (!tte->flow_table) {
8742 tte->flow_table = tunnel_id_to_flow_tbl(tte->flow_table);
8743 tte->tunnel_id = tbl.tunnel_id;
8744 tte->group = tbl.group;
8752 static struct mlx5_list_entry *
8753 mlx5_flow_tunnel_grp2tbl_clone_cb(void *tool_ctx __rte_unused,
8754 struct mlx5_list_entry *oentry,
8755 void *cb_ctx __rte_unused)
8757 struct tunnel_tbl_entry *tte = mlx5_malloc(MLX5_MEM_SYS, sizeof(*tte),
8762 memcpy(tte, oentry, sizeof(*tte));
8767 mlx5_flow_tunnel_grp2tbl_clone_free_cb(void *tool_ctx __rte_unused,
8768 struct mlx5_list_entry *entry)
8770 struct tunnel_tbl_entry *tte = container_of(entry, typeof(*tte), hash);
8776 tunnel_flow_group_to_flow_table(struct rte_eth_dev *dev,
8777 const struct mlx5_flow_tunnel *tunnel,
8778 uint32_t group, uint32_t *table,
8779 struct rte_flow_error *error)
8781 struct mlx5_list_entry *he;
8782 struct tunnel_tbl_entry *tte;
8783 union tunnel_tbl_key key = {
8784 .tunnel_id = tunnel ? tunnel->tunnel_id : 0,
8787 struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
8788 struct mlx5_hlist *group_hash;
8789 struct mlx5_flow_cb_ctx ctx = {
8793 group_hash = tunnel ? tunnel->groups : thub->groups;
8794 he = mlx5_hlist_register(group_hash, key.val, &ctx);
8796 return rte_flow_error_set(error, EINVAL,
8797 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
8799 "tunnel group index not supported");
8800 tte = container_of(he, typeof(*tte), hash);
8801 *table = tte->flow_table;
8802 DRV_LOG(DEBUG, "port %u tunnel %u group=%#x table=%#x",
8803 dev->data->port_id, key.tunnel_id, group, *table);
8808 mlx5_flow_tunnel_free(struct rte_eth_dev *dev,
8809 struct mlx5_flow_tunnel *tunnel)
8811 struct mlx5_priv *priv = dev->data->dev_private;
8812 struct mlx5_indexed_pool *ipool;
8814 DRV_LOG(DEBUG, "port %u release pmd tunnel id=0x%x",
8815 dev->data->port_id, tunnel->tunnel_id);
8816 LIST_REMOVE(tunnel, chain);
8817 mlx5_hlist_destroy(tunnel->groups);
8818 ipool = priv->sh->ipool[MLX5_IPOOL_TUNNEL_ID];
8819 mlx5_ipool_free(ipool, tunnel->tunnel_id);
8823 mlx5_access_tunnel_offload_db
8824 (struct rte_eth_dev *dev,
8825 bool (*match)(struct rte_eth_dev *,
8826 struct mlx5_flow_tunnel *, const void *),
8827 void (*hit)(struct rte_eth_dev *, struct mlx5_flow_tunnel *, void *),
8828 void (*miss)(struct rte_eth_dev *, void *),
8829 void *ctx, bool lock_op)
8831 bool verdict = false;
8832 struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
8833 struct mlx5_flow_tunnel *tunnel;
8835 rte_spinlock_lock(&thub->sl);
8836 LIST_FOREACH(tunnel, &thub->tunnels, chain) {
8837 verdict = match(dev, tunnel, (const void *)ctx);
8842 rte_spinlock_unlock(&thub->sl);
8844 hit(dev, tunnel, ctx);
8845 if (!verdict && miss)
8848 rte_spinlock_unlock(&thub->sl);
8853 struct tunnel_db_find_tunnel_id_ctx {
8855 struct mlx5_flow_tunnel *tunnel;
8859 find_tunnel_id_match(struct rte_eth_dev *dev,
8860 struct mlx5_flow_tunnel *tunnel, const void *x)
8862 const struct tunnel_db_find_tunnel_id_ctx *ctx = x;
8865 return tunnel->tunnel_id == ctx->tunnel_id;
8869 find_tunnel_id_hit(struct rte_eth_dev *dev,
8870 struct mlx5_flow_tunnel *tunnel, void *x)
8872 struct tunnel_db_find_tunnel_id_ctx *ctx = x;
8874 ctx->tunnel = tunnel;
8877 static struct mlx5_flow_tunnel *
8878 mlx5_find_tunnel_id(struct rte_eth_dev *dev, uint32_t id)
8880 struct tunnel_db_find_tunnel_id_ctx ctx = {
8884 mlx5_access_tunnel_offload_db(dev, find_tunnel_id_match,
8885 find_tunnel_id_hit, NULL, &ctx, true);
8890 static struct mlx5_flow_tunnel *
8891 mlx5_flow_tunnel_allocate(struct rte_eth_dev *dev,
8892 const struct rte_flow_tunnel *app_tunnel)
8894 struct mlx5_priv *priv = dev->data->dev_private;
8895 struct mlx5_indexed_pool *ipool;
8896 struct mlx5_flow_tunnel *tunnel;
8899 ipool = priv->sh->ipool[MLX5_IPOOL_TUNNEL_ID];
8900 tunnel = mlx5_ipool_zmalloc(ipool, &id);
8903 if (id >= MLX5_MAX_TUNNELS) {
8904 mlx5_ipool_free(ipool, id);
8905 DRV_LOG(ERR, "Tunnel ID %d exceed max limit.", id);
8908 tunnel->groups = mlx5_hlist_create("tunnel groups", 64, false, true,
8910 mlx5_flow_tunnel_grp2tbl_create_cb,
8911 mlx5_flow_tunnel_grp2tbl_match_cb,
8912 mlx5_flow_tunnel_grp2tbl_remove_cb,
8913 mlx5_flow_tunnel_grp2tbl_clone_cb,
8914 mlx5_flow_tunnel_grp2tbl_clone_free_cb);
8915 if (!tunnel->groups) {
8916 mlx5_ipool_free(ipool, id);
8919 /* initiate new PMD tunnel */
8920 memcpy(&tunnel->app_tunnel, app_tunnel, sizeof(*app_tunnel));
8921 tunnel->tunnel_id = id;
8922 tunnel->action.type = (typeof(tunnel->action.type))
8923 MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET;
8924 tunnel->action.conf = tunnel;
8925 tunnel->item.type = (typeof(tunnel->item.type))
8926 MLX5_RTE_FLOW_ITEM_TYPE_TUNNEL;
8927 tunnel->item.spec = tunnel;
8928 tunnel->item.last = NULL;
8929 tunnel->item.mask = NULL;
8931 DRV_LOG(DEBUG, "port %u new pmd tunnel id=0x%x",
8932 dev->data->port_id, tunnel->tunnel_id);
8937 struct tunnel_db_get_tunnel_ctx {
8938 const struct rte_flow_tunnel *app_tunnel;
8939 struct mlx5_flow_tunnel *tunnel;
8942 static bool get_tunnel_match(struct rte_eth_dev *dev,
8943 struct mlx5_flow_tunnel *tunnel, const void *x)
8945 const struct tunnel_db_get_tunnel_ctx *ctx = x;
8948 return !memcmp(ctx->app_tunnel, &tunnel->app_tunnel,
8949 sizeof(*ctx->app_tunnel));
8952 static void get_tunnel_hit(struct rte_eth_dev *dev,
8953 struct mlx5_flow_tunnel *tunnel, void *x)
8955 /* called under tunnel spinlock protection */
8956 struct tunnel_db_get_tunnel_ctx *ctx = x;
8960 ctx->tunnel = tunnel;
8963 static void get_tunnel_miss(struct rte_eth_dev *dev, void *x)
8965 /* called under tunnel spinlock protection */
8966 struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
8967 struct tunnel_db_get_tunnel_ctx *ctx = x;
8969 rte_spinlock_unlock(&thub->sl);
8970 ctx->tunnel = mlx5_flow_tunnel_allocate(dev, ctx->app_tunnel);
8971 rte_spinlock_lock(&thub->sl);
8973 ctx->tunnel->refctn = 1;
8974 LIST_INSERT_HEAD(&thub->tunnels, ctx->tunnel, chain);
8980 mlx5_get_flow_tunnel(struct rte_eth_dev *dev,
8981 const struct rte_flow_tunnel *app_tunnel,
8982 struct mlx5_flow_tunnel **tunnel)
8984 struct tunnel_db_get_tunnel_ctx ctx = {
8985 .app_tunnel = app_tunnel,
8988 mlx5_access_tunnel_offload_db(dev, get_tunnel_match, get_tunnel_hit,
8989 get_tunnel_miss, &ctx, true);
8990 *tunnel = ctx.tunnel;
8991 return ctx.tunnel ? 0 : -ENOMEM;
8994 void mlx5_release_tunnel_hub(struct mlx5_dev_ctx_shared *sh, uint16_t port_id)
8996 struct mlx5_flow_tunnel_hub *thub = sh->tunnel_hub;
9000 if (!LIST_EMPTY(&thub->tunnels))
9001 DRV_LOG(WARNING, "port %u tunnels present", port_id);
9002 mlx5_hlist_destroy(thub->groups);
9006 int mlx5_alloc_tunnel_hub(struct mlx5_dev_ctx_shared *sh)
9009 struct mlx5_flow_tunnel_hub *thub;
9011 thub = mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO, sizeof(*thub),
9015 LIST_INIT(&thub->tunnels);
9016 rte_spinlock_init(&thub->sl);
9017 thub->groups = mlx5_hlist_create("flow groups", 64,
9019 mlx5_flow_tunnel_grp2tbl_create_cb,
9020 mlx5_flow_tunnel_grp2tbl_match_cb,
9021 mlx5_flow_tunnel_grp2tbl_remove_cb,
9022 mlx5_flow_tunnel_grp2tbl_clone_cb,
9023 mlx5_flow_tunnel_grp2tbl_clone_free_cb);
9024 if (!thub->groups) {
9028 sh->tunnel_hub = thub;
9034 mlx5_hlist_destroy(thub->groups);
9041 mlx5_flow_tunnel_validate(struct rte_eth_dev *dev,
9042 struct rte_flow_tunnel *tunnel,
9043 const char *err_msg)
9046 if (!is_tunnel_offload_active(dev)) {
9047 err_msg = "tunnel offload was not activated";
9049 } else if (!tunnel) {
9050 err_msg = "no application tunnel";
9054 switch (tunnel->type) {
9056 err_msg = "unsupported tunnel type";
9058 case RTE_FLOW_ITEM_TYPE_VXLAN:
9067 mlx5_flow_tunnel_decap_set(struct rte_eth_dev *dev,
9068 struct rte_flow_tunnel *app_tunnel,
9069 struct rte_flow_action **actions,
9070 uint32_t *num_of_actions,
9071 struct rte_flow_error *error)
9074 struct mlx5_flow_tunnel *tunnel;
9075 const char *err_msg = NULL;
9076 bool verdict = mlx5_flow_tunnel_validate(dev, app_tunnel, err_msg);
9079 return rte_flow_error_set(error, EINVAL,
9080 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
9082 ret = mlx5_get_flow_tunnel(dev, app_tunnel, &tunnel);
9084 return rte_flow_error_set(error, ret,
9085 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
9086 "failed to initialize pmd tunnel");
9088 *actions = &tunnel->action;
9089 *num_of_actions = 1;
9094 mlx5_flow_tunnel_match(struct rte_eth_dev *dev,
9095 struct rte_flow_tunnel *app_tunnel,
9096 struct rte_flow_item **items,
9097 uint32_t *num_of_items,
9098 struct rte_flow_error *error)
9101 struct mlx5_flow_tunnel *tunnel;
9102 const char *err_msg = NULL;
9103 bool verdict = mlx5_flow_tunnel_validate(dev, app_tunnel, err_msg);
9106 return rte_flow_error_set(error, EINVAL,
9107 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
9109 ret = mlx5_get_flow_tunnel(dev, app_tunnel, &tunnel);
9111 return rte_flow_error_set(error, ret,
9112 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
9113 "failed to initialize pmd tunnel");
9115 *items = &tunnel->item;
9120 struct tunnel_db_element_release_ctx {
9121 struct rte_flow_item *items;
9122 struct rte_flow_action *actions;
9123 uint32_t num_elements;
9124 struct rte_flow_error *error;
9129 tunnel_element_release_match(struct rte_eth_dev *dev,
9130 struct mlx5_flow_tunnel *tunnel, const void *x)
9132 const struct tunnel_db_element_release_ctx *ctx = x;
9135 if (ctx->num_elements != 1)
9137 else if (ctx->items)
9138 return ctx->items == &tunnel->item;
9139 else if (ctx->actions)
9140 return ctx->actions == &tunnel->action;
9146 tunnel_element_release_hit(struct rte_eth_dev *dev,
9147 struct mlx5_flow_tunnel *tunnel, void *x)
9149 struct tunnel_db_element_release_ctx *ctx = x;
9151 if (!__atomic_sub_fetch(&tunnel->refctn, 1, __ATOMIC_RELAXED))
9152 mlx5_flow_tunnel_free(dev, tunnel);
9156 tunnel_element_release_miss(struct rte_eth_dev *dev, void *x)
9158 struct tunnel_db_element_release_ctx *ctx = x;
9160 ctx->ret = rte_flow_error_set(ctx->error, EINVAL,
9161 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
9162 "invalid argument");
9166 mlx5_flow_tunnel_item_release(struct rte_eth_dev *dev,
9167 struct rte_flow_item *pmd_items,
9168 uint32_t num_items, struct rte_flow_error *err)
9170 struct tunnel_db_element_release_ctx ctx = {
9173 .num_elements = num_items,
9177 mlx5_access_tunnel_offload_db(dev, tunnel_element_release_match,
9178 tunnel_element_release_hit,
9179 tunnel_element_release_miss, &ctx, false);
9185 mlx5_flow_tunnel_action_release(struct rte_eth_dev *dev,
9186 struct rte_flow_action *pmd_actions,
9187 uint32_t num_actions, struct rte_flow_error *err)
9189 struct tunnel_db_element_release_ctx ctx = {
9191 .actions = pmd_actions,
9192 .num_elements = num_actions,
9196 mlx5_access_tunnel_offload_db(dev, tunnel_element_release_match,
9197 tunnel_element_release_hit,
9198 tunnel_element_release_miss, &ctx, false);
9204 mlx5_flow_tunnel_get_restore_info(struct rte_eth_dev *dev,
9206 struct rte_flow_restore_info *info,
9207 struct rte_flow_error *err)
9209 uint64_t ol_flags = m->ol_flags;
9210 const struct mlx5_flow_tbl_data_entry *tble;
9211 const uint64_t mask = PKT_RX_FDIR | PKT_RX_FDIR_ID;
9213 if (!is_tunnel_offload_active(dev)) {
9218 if ((ol_flags & mask) != mask)
9220 tble = tunnel_mark_decode(dev, m->hash.fdir.hi);
9222 DRV_LOG(DEBUG, "port %u invalid miss tunnel mark %#x",
9223 dev->data->port_id, m->hash.fdir.hi);
9226 MLX5_ASSERT(tble->tunnel);
9227 memcpy(&info->tunnel, &tble->tunnel->app_tunnel, sizeof(info->tunnel));
9228 info->group_id = tble->group_id;
9229 info->flags = RTE_FLOW_RESTORE_INFO_TUNNEL |
9230 RTE_FLOW_RESTORE_INFO_GROUP_ID |
9231 RTE_FLOW_RESTORE_INFO_ENCAPSULATED;
9236 return rte_flow_error_set(err, EINVAL,
9237 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
9238 "failed to get restore info");
9241 #else /* HAVE_IBV_FLOW_DV_SUPPORT */
9243 mlx5_flow_tunnel_decap_set(__rte_unused struct rte_eth_dev *dev,
9244 __rte_unused struct rte_flow_tunnel *app_tunnel,
9245 __rte_unused struct rte_flow_action **actions,
9246 __rte_unused uint32_t *num_of_actions,
9247 __rte_unused struct rte_flow_error *error)
9253 mlx5_flow_tunnel_match(__rte_unused struct rte_eth_dev *dev,
9254 __rte_unused struct rte_flow_tunnel *app_tunnel,
9255 __rte_unused struct rte_flow_item **items,
9256 __rte_unused uint32_t *num_of_items,
9257 __rte_unused struct rte_flow_error *error)
9263 mlx5_flow_tunnel_item_release(__rte_unused struct rte_eth_dev *dev,
9264 __rte_unused struct rte_flow_item *pmd_items,
9265 __rte_unused uint32_t num_items,
9266 __rte_unused struct rte_flow_error *err)
9272 mlx5_flow_tunnel_action_release(__rte_unused struct rte_eth_dev *dev,
9273 __rte_unused struct rte_flow_action *pmd_action,
9274 __rte_unused uint32_t num_actions,
9275 __rte_unused struct rte_flow_error *err)
9281 mlx5_flow_tunnel_get_restore_info(__rte_unused struct rte_eth_dev *dev,
9282 __rte_unused struct rte_mbuf *m,
9283 __rte_unused struct rte_flow_restore_info *i,
9284 __rte_unused struct rte_flow_error *err)
9290 flow_tunnel_add_default_miss(__rte_unused struct rte_eth_dev *dev,
9291 __rte_unused struct rte_flow *flow,
9292 __rte_unused const struct rte_flow_attr *attr,
9293 __rte_unused const struct rte_flow_action *actions,
9294 __rte_unused uint32_t flow_idx,
9295 __rte_unused const struct mlx5_flow_tunnel *tunnel,
9296 __rte_unused struct tunnel_default_miss_ctx *ctx,
9297 __rte_unused struct rte_flow_error *error)
9302 static struct mlx5_flow_tunnel *
9303 mlx5_find_tunnel_id(__rte_unused struct rte_eth_dev *dev,
9304 __rte_unused uint32_t id)
9310 mlx5_flow_tunnel_free(__rte_unused struct rte_eth_dev *dev,
9311 __rte_unused struct mlx5_flow_tunnel *tunnel)
9316 tunnel_flow_group_to_flow_table(__rte_unused struct rte_eth_dev *dev,
9317 __rte_unused const struct mlx5_flow_tunnel *t,
9318 __rte_unused uint32_t group,
9319 __rte_unused uint32_t *table,
9320 struct rte_flow_error *error)
9322 return rte_flow_error_set(error, ENOTSUP,
9323 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
9324 "tunnel offload requires DV support");
9328 mlx5_release_tunnel_hub(__rte_unused struct mlx5_dev_ctx_shared *sh,
9329 __rte_unused uint16_t port_id)
9332 #endif /* HAVE_IBV_FLOW_DV_SUPPORT */
9335 mlx5_dbg__print_pattern(const struct rte_flow_item *item)
9338 struct rte_flow_error error;
9340 for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
9342 ret = rte_flow_conv(RTE_FLOW_CONV_OP_ITEM_NAME_PTR, &item_name,
9344 (void *)(uintptr_t)item->type, &error);
9346 printf("%s ", item_name);
9348 printf("%d\n", (int)item->type);