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 = (uint32_t)~0;
1325 if (priv->config.dv_xmeta_en == MLX5_XMETA_MODE_META16)
1326 data->flow_meta_port_mask >>= 16;
1332 * return a pointer to the desired action in the list of actions.
1334 * @param[in] actions
1335 * The list of actions to search the action in.
1337 * The action to find.
1340 * Pointer to the action in the list, if found. NULL otherwise.
1342 const struct rte_flow_action *
1343 mlx5_flow_find_action(const struct rte_flow_action *actions,
1344 enum rte_flow_action_type action)
1346 if (actions == NULL)
1348 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++)
1349 if (actions->type == action)
1355 * Validate the flag action.
1357 * @param[in] action_flags
1358 * Bit-fields that holds the actions detected until now.
1360 * Attributes of flow that includes this action.
1362 * Pointer to error structure.
1365 * 0 on success, a negative errno value otherwise and rte_errno is set.
1368 mlx5_flow_validate_action_flag(uint64_t action_flags,
1369 const struct rte_flow_attr *attr,
1370 struct rte_flow_error *error)
1372 if (action_flags & MLX5_FLOW_ACTION_MARK)
1373 return rte_flow_error_set(error, EINVAL,
1374 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1375 "can't mark and flag in same flow");
1376 if (action_flags & MLX5_FLOW_ACTION_FLAG)
1377 return rte_flow_error_set(error, EINVAL,
1378 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1380 " actions in same flow");
1382 return rte_flow_error_set(error, ENOTSUP,
1383 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1384 "flag action not supported for "
1390 * Validate the mark action.
1393 * Pointer to the queue action.
1394 * @param[in] action_flags
1395 * Bit-fields that holds the actions detected until now.
1397 * Attributes of flow that includes this action.
1399 * Pointer to error structure.
1402 * 0 on success, a negative errno value otherwise and rte_errno is set.
1405 mlx5_flow_validate_action_mark(const struct rte_flow_action *action,
1406 uint64_t action_flags,
1407 const struct rte_flow_attr *attr,
1408 struct rte_flow_error *error)
1410 const struct rte_flow_action_mark *mark = action->conf;
1413 return rte_flow_error_set(error, EINVAL,
1414 RTE_FLOW_ERROR_TYPE_ACTION,
1416 "configuration cannot be null");
1417 if (mark->id >= MLX5_FLOW_MARK_MAX)
1418 return rte_flow_error_set(error, EINVAL,
1419 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1421 "mark id must in 0 <= id < "
1422 RTE_STR(MLX5_FLOW_MARK_MAX));
1423 if (action_flags & MLX5_FLOW_ACTION_FLAG)
1424 return rte_flow_error_set(error, EINVAL,
1425 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1426 "can't flag and mark in same flow");
1427 if (action_flags & MLX5_FLOW_ACTION_MARK)
1428 return rte_flow_error_set(error, EINVAL,
1429 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1430 "can't have 2 mark actions in same"
1433 return rte_flow_error_set(error, ENOTSUP,
1434 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1435 "mark action not supported for "
1441 * Validate the drop action.
1443 * @param[in] action_flags
1444 * Bit-fields that holds the actions detected until now.
1446 * Attributes of flow that includes this action.
1448 * Pointer to error structure.
1451 * 0 on success, a negative errno value otherwise and rte_errno is set.
1454 mlx5_flow_validate_action_drop(uint64_t action_flags __rte_unused,
1455 const struct rte_flow_attr *attr,
1456 struct rte_flow_error *error)
1459 return rte_flow_error_set(error, ENOTSUP,
1460 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1461 "drop action not supported for "
1467 * Validate the queue action.
1470 * Pointer to the queue action.
1471 * @param[in] action_flags
1472 * Bit-fields that holds the actions detected until now.
1474 * Pointer to the Ethernet device structure.
1476 * Attributes of flow that includes this action.
1478 * Pointer to error structure.
1481 * 0 on success, a negative errno value otherwise and rte_errno is set.
1484 mlx5_flow_validate_action_queue(const struct rte_flow_action *action,
1485 uint64_t action_flags,
1486 struct rte_eth_dev *dev,
1487 const struct rte_flow_attr *attr,
1488 struct rte_flow_error *error)
1490 struct mlx5_priv *priv = dev->data->dev_private;
1491 const struct rte_flow_action_queue *queue = action->conf;
1493 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
1494 return rte_flow_error_set(error, EINVAL,
1495 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1496 "can't have 2 fate actions in"
1499 return rte_flow_error_set(error, EINVAL,
1500 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1501 NULL, "No Rx queues configured");
1502 if (queue->index >= priv->rxqs_n)
1503 return rte_flow_error_set(error, EINVAL,
1504 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1506 "queue index out of range");
1507 if (!(*priv->rxqs)[queue->index])
1508 return rte_flow_error_set(error, EINVAL,
1509 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1511 "queue is not configured");
1513 return rte_flow_error_set(error, ENOTSUP,
1514 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1515 "queue action not supported for "
1521 * Validate the rss action.
1524 * Pointer to the Ethernet device structure.
1526 * Pointer to the queue action.
1528 * Pointer to error structure.
1531 * 0 on success, a negative errno value otherwise and rte_errno is set.
1534 mlx5_validate_action_rss(struct rte_eth_dev *dev,
1535 const struct rte_flow_action *action,
1536 struct rte_flow_error *error)
1538 struct mlx5_priv *priv = dev->data->dev_private;
1539 const struct rte_flow_action_rss *rss = action->conf;
1540 enum mlx5_rxq_type rxq_type = MLX5_RXQ_TYPE_UNDEFINED;
1543 if (rss->func != RTE_ETH_HASH_FUNCTION_DEFAULT &&
1544 rss->func != RTE_ETH_HASH_FUNCTION_TOEPLITZ)
1545 return rte_flow_error_set(error, ENOTSUP,
1546 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1548 "RSS hash function not supported");
1549 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
1554 return rte_flow_error_set(error, ENOTSUP,
1555 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1557 "tunnel RSS is not supported");
1558 /* allow RSS key_len 0 in case of NULL (default) RSS key. */
1559 if (rss->key_len == 0 && rss->key != NULL)
1560 return rte_flow_error_set(error, ENOTSUP,
1561 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1563 "RSS hash key length 0");
1564 if (rss->key_len > 0 && rss->key_len < MLX5_RSS_HASH_KEY_LEN)
1565 return rte_flow_error_set(error, ENOTSUP,
1566 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1568 "RSS hash key too small");
1569 if (rss->key_len > MLX5_RSS_HASH_KEY_LEN)
1570 return rte_flow_error_set(error, ENOTSUP,
1571 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1573 "RSS hash key too large");
1574 if (rss->queue_num > priv->config.ind_table_max_size)
1575 return rte_flow_error_set(error, ENOTSUP,
1576 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1578 "number of queues too large");
1579 if (rss->types & MLX5_RSS_HF_MASK)
1580 return rte_flow_error_set(error, ENOTSUP,
1581 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1583 "some RSS protocols are not"
1585 if ((rss->types & (ETH_RSS_L3_SRC_ONLY | ETH_RSS_L3_DST_ONLY)) &&
1586 !(rss->types & ETH_RSS_IP))
1587 return rte_flow_error_set(error, EINVAL,
1588 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1589 "L3 partial RSS requested but L3 RSS"
1590 " type not specified");
1591 if ((rss->types & (ETH_RSS_L4_SRC_ONLY | ETH_RSS_L4_DST_ONLY)) &&
1592 !(rss->types & (ETH_RSS_UDP | ETH_RSS_TCP)))
1593 return rte_flow_error_set(error, EINVAL,
1594 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1595 "L4 partial RSS requested but L4 RSS"
1596 " type not specified");
1598 return rte_flow_error_set(error, EINVAL,
1599 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1600 NULL, "No Rx queues configured");
1601 if (!rss->queue_num)
1602 return rte_flow_error_set(error, EINVAL,
1603 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1604 NULL, "No queues configured");
1605 for (i = 0; i != rss->queue_num; ++i) {
1606 struct mlx5_rxq_ctrl *rxq_ctrl;
1608 if (rss->queue[i] >= priv->rxqs_n)
1609 return rte_flow_error_set
1611 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1612 &rss->queue[i], "queue index out of range");
1613 if (!(*priv->rxqs)[rss->queue[i]])
1614 return rte_flow_error_set
1615 (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1616 &rss->queue[i], "queue is not configured");
1617 rxq_ctrl = container_of((*priv->rxqs)[rss->queue[i]],
1618 struct mlx5_rxq_ctrl, rxq);
1620 rxq_type = rxq_ctrl->type;
1621 if (rxq_type != rxq_ctrl->type)
1622 return rte_flow_error_set
1623 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1625 "combining hairpin and regular RSS queues is not supported");
1631 * Validate the rss action.
1634 * Pointer to the queue action.
1635 * @param[in] action_flags
1636 * Bit-fields that holds the actions detected until now.
1638 * Pointer to the Ethernet device structure.
1640 * Attributes of flow that includes this action.
1641 * @param[in] item_flags
1642 * Items that were detected.
1644 * Pointer to error structure.
1647 * 0 on success, a negative errno value otherwise and rte_errno is set.
1650 mlx5_flow_validate_action_rss(const struct rte_flow_action *action,
1651 uint64_t action_flags,
1652 struct rte_eth_dev *dev,
1653 const struct rte_flow_attr *attr,
1654 uint64_t item_flags,
1655 struct rte_flow_error *error)
1657 const struct rte_flow_action_rss *rss = action->conf;
1658 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1661 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
1662 return rte_flow_error_set(error, EINVAL,
1663 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1664 "can't have 2 fate actions"
1666 ret = mlx5_validate_action_rss(dev, action, error);
1670 return rte_flow_error_set(error, ENOTSUP,
1671 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1672 "rss action not supported for "
1674 if (rss->level > 1 && !tunnel)
1675 return rte_flow_error_set(error, EINVAL,
1676 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1677 "inner RSS is not supported for "
1678 "non-tunnel flows");
1679 if ((item_flags & MLX5_FLOW_LAYER_ECPRI) &&
1680 !(item_flags & MLX5_FLOW_LAYER_INNER_L4_UDP)) {
1681 return rte_flow_error_set(error, EINVAL,
1682 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1683 "RSS on eCPRI is not supported now");
1685 if ((item_flags & MLX5_FLOW_LAYER_MPLS) &&
1687 (MLX5_FLOW_LAYER_INNER_L2 | MLX5_FLOW_LAYER_INNER_L3)) &&
1689 return rte_flow_error_set(error, EINVAL,
1690 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
1691 "MPLS inner RSS needs to specify inner L2/L3 items after MPLS in pattern");
1696 * Validate the default miss action.
1698 * @param[in] action_flags
1699 * Bit-fields that holds the actions detected until now.
1701 * Pointer to error structure.
1704 * 0 on success, a negative errno value otherwise and rte_errno is set.
1707 mlx5_flow_validate_action_default_miss(uint64_t action_flags,
1708 const struct rte_flow_attr *attr,
1709 struct rte_flow_error *error)
1711 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
1712 return rte_flow_error_set(error, EINVAL,
1713 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1714 "can't have 2 fate actions in"
1717 return rte_flow_error_set(error, ENOTSUP,
1718 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1719 "default miss action not supported "
1722 return rte_flow_error_set(error, ENOTSUP,
1723 RTE_FLOW_ERROR_TYPE_ATTR_GROUP, NULL,
1724 "only group 0 is supported");
1726 return rte_flow_error_set(error, ENOTSUP,
1727 RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
1728 NULL, "transfer is not supported");
1733 * Validate the count action.
1736 * Pointer to the Ethernet device structure.
1738 * Attributes of flow that includes this action.
1740 * Pointer to error structure.
1743 * 0 on success, a negative errno value otherwise and rte_errno is set.
1746 mlx5_flow_validate_action_count(struct rte_eth_dev *dev __rte_unused,
1747 const struct rte_flow_attr *attr,
1748 struct rte_flow_error *error)
1751 return rte_flow_error_set(error, ENOTSUP,
1752 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1753 "count action not supported for "
1759 * Validate the ASO CT action.
1762 * Pointer to the Ethernet device structure.
1763 * @param[in] conntrack
1764 * Pointer to the CT action profile.
1766 * Pointer to error structure.
1769 * 0 on success, a negative errno value otherwise and rte_errno is set.
1772 mlx5_validate_action_ct(struct rte_eth_dev *dev,
1773 const struct rte_flow_action_conntrack *conntrack,
1774 struct rte_flow_error *error)
1778 if (conntrack->state > RTE_FLOW_CONNTRACK_STATE_TIME_WAIT)
1779 return rte_flow_error_set(error, EINVAL,
1780 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1781 "Invalid CT state");
1782 if (conntrack->last_index > RTE_FLOW_CONNTRACK_FLAG_RST)
1783 return rte_flow_error_set(error, EINVAL,
1784 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1785 "Invalid last TCP packet flag");
1790 * Verify the @p attributes will be correctly understood by the NIC and store
1791 * them in the @p flow if everything is correct.
1794 * Pointer to the Ethernet device structure.
1795 * @param[in] attributes
1796 * Pointer to flow attributes
1798 * Pointer to error structure.
1801 * 0 on success, a negative errno value otherwise and rte_errno is set.
1804 mlx5_flow_validate_attributes(struct rte_eth_dev *dev,
1805 const struct rte_flow_attr *attributes,
1806 struct rte_flow_error *error)
1808 struct mlx5_priv *priv = dev->data->dev_private;
1809 uint32_t priority_max = priv->config.flow_prio - 1;
1811 if (attributes->group)
1812 return rte_flow_error_set(error, ENOTSUP,
1813 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
1814 NULL, "groups is not supported");
1815 if (attributes->priority != MLX5_FLOW_LOWEST_PRIO_INDICATOR &&
1816 attributes->priority >= priority_max)
1817 return rte_flow_error_set(error, ENOTSUP,
1818 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
1819 NULL, "priority out of range");
1820 if (attributes->egress)
1821 return rte_flow_error_set(error, ENOTSUP,
1822 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1823 "egress is not supported");
1824 if (attributes->transfer && !priv->config.dv_esw_en)
1825 return rte_flow_error_set(error, ENOTSUP,
1826 RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
1827 NULL, "transfer is not supported");
1828 if (!attributes->ingress)
1829 return rte_flow_error_set(error, EINVAL,
1830 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
1832 "ingress attribute is mandatory");
1837 * Validate ICMP6 item.
1840 * Item specification.
1841 * @param[in] item_flags
1842 * Bit-fields that holds the items detected until now.
1843 * @param[in] ext_vlan_sup
1844 * Whether extended VLAN features are supported or not.
1846 * Pointer to error structure.
1849 * 0 on success, a negative errno value otherwise and rte_errno is set.
1852 mlx5_flow_validate_item_icmp6(const struct rte_flow_item *item,
1853 uint64_t item_flags,
1854 uint8_t target_protocol,
1855 struct rte_flow_error *error)
1857 const struct rte_flow_item_icmp6 *mask = item->mask;
1858 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1859 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
1860 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
1861 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1862 MLX5_FLOW_LAYER_OUTER_L4;
1865 if (target_protocol != 0xFF && target_protocol != IPPROTO_ICMPV6)
1866 return rte_flow_error_set(error, EINVAL,
1867 RTE_FLOW_ERROR_TYPE_ITEM, item,
1868 "protocol filtering not compatible"
1869 " with ICMP6 layer");
1870 if (!(item_flags & l3m))
1871 return rte_flow_error_set(error, EINVAL,
1872 RTE_FLOW_ERROR_TYPE_ITEM, item,
1873 "IPv6 is mandatory to filter on"
1875 if (item_flags & l4m)
1876 return rte_flow_error_set(error, EINVAL,
1877 RTE_FLOW_ERROR_TYPE_ITEM, item,
1878 "multiple L4 layers not supported");
1880 mask = &rte_flow_item_icmp6_mask;
1881 ret = mlx5_flow_item_acceptable
1882 (item, (const uint8_t *)mask,
1883 (const uint8_t *)&rte_flow_item_icmp6_mask,
1884 sizeof(struct rte_flow_item_icmp6),
1885 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
1892 * Validate ICMP item.
1895 * Item specification.
1896 * @param[in] item_flags
1897 * Bit-fields that holds the items detected until now.
1899 * Pointer to error structure.
1902 * 0 on success, a negative errno value otherwise and rte_errno is set.
1905 mlx5_flow_validate_item_icmp(const struct rte_flow_item *item,
1906 uint64_t item_flags,
1907 uint8_t target_protocol,
1908 struct rte_flow_error *error)
1910 const struct rte_flow_item_icmp *mask = item->mask;
1911 const struct rte_flow_item_icmp nic_mask = {
1912 .hdr.icmp_type = 0xff,
1913 .hdr.icmp_code = 0xff,
1914 .hdr.icmp_ident = RTE_BE16(0xffff),
1915 .hdr.icmp_seq_nb = RTE_BE16(0xffff),
1917 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1918 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
1919 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
1920 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1921 MLX5_FLOW_LAYER_OUTER_L4;
1924 if (target_protocol != 0xFF && target_protocol != IPPROTO_ICMP)
1925 return rte_flow_error_set(error, EINVAL,
1926 RTE_FLOW_ERROR_TYPE_ITEM, item,
1927 "protocol filtering not compatible"
1928 " with ICMP layer");
1929 if (!(item_flags & l3m))
1930 return rte_flow_error_set(error, EINVAL,
1931 RTE_FLOW_ERROR_TYPE_ITEM, item,
1932 "IPv4 is mandatory to filter"
1934 if (item_flags & l4m)
1935 return rte_flow_error_set(error, EINVAL,
1936 RTE_FLOW_ERROR_TYPE_ITEM, item,
1937 "multiple L4 layers not supported");
1940 ret = mlx5_flow_item_acceptable
1941 (item, (const uint8_t *)mask,
1942 (const uint8_t *)&nic_mask,
1943 sizeof(struct rte_flow_item_icmp),
1944 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
1951 * Validate Ethernet item.
1954 * Item specification.
1955 * @param[in] item_flags
1956 * Bit-fields that holds the items detected until now.
1958 * Pointer to error structure.
1961 * 0 on success, a negative errno value otherwise and rte_errno is set.
1964 mlx5_flow_validate_item_eth(const struct rte_flow_item *item,
1965 uint64_t item_flags, bool ext_vlan_sup,
1966 struct rte_flow_error *error)
1968 const struct rte_flow_item_eth *mask = item->mask;
1969 const struct rte_flow_item_eth nic_mask = {
1970 .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
1971 .src.addr_bytes = "\xff\xff\xff\xff\xff\xff",
1972 .type = RTE_BE16(0xffff),
1973 .has_vlan = ext_vlan_sup ? 1 : 0,
1976 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1977 const uint64_t ethm = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
1978 MLX5_FLOW_LAYER_OUTER_L2;
1980 if (item_flags & ethm)
1981 return rte_flow_error_set(error, ENOTSUP,
1982 RTE_FLOW_ERROR_TYPE_ITEM, item,
1983 "multiple L2 layers not supported");
1984 if ((!tunnel && (item_flags & MLX5_FLOW_LAYER_OUTER_L3)) ||
1985 (tunnel && (item_flags & MLX5_FLOW_LAYER_INNER_L3)))
1986 return rte_flow_error_set(error, EINVAL,
1987 RTE_FLOW_ERROR_TYPE_ITEM, item,
1988 "L2 layer should not follow "
1990 if ((!tunnel && (item_flags & MLX5_FLOW_LAYER_OUTER_VLAN)) ||
1991 (tunnel && (item_flags & MLX5_FLOW_LAYER_INNER_VLAN)))
1992 return rte_flow_error_set(error, EINVAL,
1993 RTE_FLOW_ERROR_TYPE_ITEM, item,
1994 "L2 layer should not follow VLAN");
1996 mask = &rte_flow_item_eth_mask;
1997 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1998 (const uint8_t *)&nic_mask,
1999 sizeof(struct rte_flow_item_eth),
2000 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2005 * Validate VLAN item.
2008 * Item specification.
2009 * @param[in] item_flags
2010 * Bit-fields that holds the items detected until now.
2012 * Ethernet device flow is being created on.
2014 * Pointer to error structure.
2017 * 0 on success, a negative errno value otherwise and rte_errno is set.
2020 mlx5_flow_validate_item_vlan(const struct rte_flow_item *item,
2021 uint64_t item_flags,
2022 struct rte_eth_dev *dev,
2023 struct rte_flow_error *error)
2025 const struct rte_flow_item_vlan *spec = item->spec;
2026 const struct rte_flow_item_vlan *mask = item->mask;
2027 const struct rte_flow_item_vlan nic_mask = {
2028 .tci = RTE_BE16(UINT16_MAX),
2029 .inner_type = RTE_BE16(UINT16_MAX),
2031 uint16_t vlan_tag = 0;
2032 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2034 const uint64_t l34m = tunnel ? (MLX5_FLOW_LAYER_INNER_L3 |
2035 MLX5_FLOW_LAYER_INNER_L4) :
2036 (MLX5_FLOW_LAYER_OUTER_L3 |
2037 MLX5_FLOW_LAYER_OUTER_L4);
2038 const uint64_t vlanm = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
2039 MLX5_FLOW_LAYER_OUTER_VLAN;
2041 if (item_flags & vlanm)
2042 return rte_flow_error_set(error, EINVAL,
2043 RTE_FLOW_ERROR_TYPE_ITEM, item,
2044 "multiple VLAN layers not supported");
2045 else if ((item_flags & l34m) != 0)
2046 return rte_flow_error_set(error, EINVAL,
2047 RTE_FLOW_ERROR_TYPE_ITEM, item,
2048 "VLAN cannot follow L3/L4 layer");
2050 mask = &rte_flow_item_vlan_mask;
2051 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2052 (const uint8_t *)&nic_mask,
2053 sizeof(struct rte_flow_item_vlan),
2054 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2057 if (!tunnel && mask->tci != RTE_BE16(0x0fff)) {
2058 struct mlx5_priv *priv = dev->data->dev_private;
2060 if (priv->vmwa_context) {
2062 * Non-NULL context means we have a virtual machine
2063 * and SR-IOV enabled, we have to create VLAN interface
2064 * to make hypervisor to setup E-Switch vport
2065 * context correctly. We avoid creating the multiple
2066 * VLAN interfaces, so we cannot support VLAN tag mask.
2068 return rte_flow_error_set(error, EINVAL,
2069 RTE_FLOW_ERROR_TYPE_ITEM,
2071 "VLAN tag mask is not"
2072 " supported in virtual"
2077 vlan_tag = spec->tci;
2078 vlan_tag &= mask->tci;
2081 * From verbs perspective an empty VLAN is equivalent
2082 * to a packet without VLAN layer.
2085 return rte_flow_error_set(error, EINVAL,
2086 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
2088 "VLAN cannot be empty");
2093 * Validate IPV4 item.
2096 * Item specification.
2097 * @param[in] item_flags
2098 * Bit-fields that holds the items detected until now.
2099 * @param[in] last_item
2100 * Previous validated item in the pattern items.
2101 * @param[in] ether_type
2102 * Type in the ethernet layer header (including dot1q).
2103 * @param[in] acc_mask
2104 * Acceptable mask, if NULL default internal default mask
2105 * will be used to check whether item fields are supported.
2106 * @param[in] range_accepted
2107 * True if range of values is accepted for specific fields, false otherwise.
2109 * Pointer to error structure.
2112 * 0 on success, a negative errno value otherwise and rte_errno is set.
2115 mlx5_flow_validate_item_ipv4(const struct rte_flow_item *item,
2116 uint64_t item_flags,
2118 uint16_t ether_type,
2119 const struct rte_flow_item_ipv4 *acc_mask,
2120 bool range_accepted,
2121 struct rte_flow_error *error)
2123 const struct rte_flow_item_ipv4 *mask = item->mask;
2124 const struct rte_flow_item_ipv4 *spec = item->spec;
2125 const struct rte_flow_item_ipv4 nic_mask = {
2127 .src_addr = RTE_BE32(0xffffffff),
2128 .dst_addr = RTE_BE32(0xffffffff),
2129 .type_of_service = 0xff,
2130 .next_proto_id = 0xff,
2133 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2134 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2135 MLX5_FLOW_LAYER_OUTER_L3;
2136 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2137 MLX5_FLOW_LAYER_OUTER_L4;
2139 uint8_t next_proto = 0xFF;
2140 const uint64_t l2_vlan = (MLX5_FLOW_LAYER_L2 |
2141 MLX5_FLOW_LAYER_OUTER_VLAN |
2142 MLX5_FLOW_LAYER_INNER_VLAN);
2144 if ((last_item & l2_vlan) && ether_type &&
2145 ether_type != RTE_ETHER_TYPE_IPV4)
2146 return rte_flow_error_set(error, EINVAL,
2147 RTE_FLOW_ERROR_TYPE_ITEM, item,
2148 "IPv4 cannot follow L2/VLAN layer "
2149 "which ether type is not IPv4");
2150 if (item_flags & MLX5_FLOW_LAYER_TUNNEL) {
2152 next_proto = mask->hdr.next_proto_id &
2153 spec->hdr.next_proto_id;
2154 if (next_proto == IPPROTO_IPIP || next_proto == IPPROTO_IPV6)
2155 return rte_flow_error_set(error, EINVAL,
2156 RTE_FLOW_ERROR_TYPE_ITEM,
2161 if (item_flags & MLX5_FLOW_LAYER_IPV6_ENCAP)
2162 return rte_flow_error_set(error, EINVAL,
2163 RTE_FLOW_ERROR_TYPE_ITEM, item,
2164 "wrong tunnel type - IPv6 specified "
2165 "but IPv4 item provided");
2166 if (item_flags & l3m)
2167 return rte_flow_error_set(error, ENOTSUP,
2168 RTE_FLOW_ERROR_TYPE_ITEM, item,
2169 "multiple L3 layers not supported");
2170 else if (item_flags & l4m)
2171 return rte_flow_error_set(error, EINVAL,
2172 RTE_FLOW_ERROR_TYPE_ITEM, item,
2173 "L3 cannot follow an L4 layer.");
2174 else if ((item_flags & MLX5_FLOW_LAYER_NVGRE) &&
2175 !(item_flags & MLX5_FLOW_LAYER_INNER_L2))
2176 return rte_flow_error_set(error, EINVAL,
2177 RTE_FLOW_ERROR_TYPE_ITEM, item,
2178 "L3 cannot follow an NVGRE layer.");
2180 mask = &rte_flow_item_ipv4_mask;
2181 else if (mask->hdr.next_proto_id != 0 &&
2182 mask->hdr.next_proto_id != 0xff)
2183 return rte_flow_error_set(error, EINVAL,
2184 RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
2185 "partial mask is not supported"
2187 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2188 acc_mask ? (const uint8_t *)acc_mask
2189 : (const uint8_t *)&nic_mask,
2190 sizeof(struct rte_flow_item_ipv4),
2191 range_accepted, error);
2198 * Validate IPV6 item.
2201 * Item specification.
2202 * @param[in] item_flags
2203 * Bit-fields that holds the items detected until now.
2204 * @param[in] last_item
2205 * Previous validated item in the pattern items.
2206 * @param[in] ether_type
2207 * Type in the ethernet layer header (including dot1q).
2208 * @param[in] acc_mask
2209 * Acceptable mask, if NULL default internal default mask
2210 * will be used to check whether item fields are supported.
2212 * Pointer to error structure.
2215 * 0 on success, a negative errno value otherwise and rte_errno is set.
2218 mlx5_flow_validate_item_ipv6(const struct rte_flow_item *item,
2219 uint64_t item_flags,
2221 uint16_t ether_type,
2222 const struct rte_flow_item_ipv6 *acc_mask,
2223 struct rte_flow_error *error)
2225 const struct rte_flow_item_ipv6 *mask = item->mask;
2226 const struct rte_flow_item_ipv6 *spec = item->spec;
2227 const struct rte_flow_item_ipv6 nic_mask = {
2230 "\xff\xff\xff\xff\xff\xff\xff\xff"
2231 "\xff\xff\xff\xff\xff\xff\xff\xff",
2233 "\xff\xff\xff\xff\xff\xff\xff\xff"
2234 "\xff\xff\xff\xff\xff\xff\xff\xff",
2235 .vtc_flow = RTE_BE32(0xffffffff),
2239 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2240 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2241 MLX5_FLOW_LAYER_OUTER_L3;
2242 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2243 MLX5_FLOW_LAYER_OUTER_L4;
2245 uint8_t next_proto = 0xFF;
2246 const uint64_t l2_vlan = (MLX5_FLOW_LAYER_L2 |
2247 MLX5_FLOW_LAYER_OUTER_VLAN |
2248 MLX5_FLOW_LAYER_INNER_VLAN);
2250 if ((last_item & l2_vlan) && ether_type &&
2251 ether_type != RTE_ETHER_TYPE_IPV6)
2252 return rte_flow_error_set(error, EINVAL,
2253 RTE_FLOW_ERROR_TYPE_ITEM, item,
2254 "IPv6 cannot follow L2/VLAN layer "
2255 "which ether type is not IPv6");
2256 if (mask && mask->hdr.proto == UINT8_MAX && spec)
2257 next_proto = spec->hdr.proto;
2258 if (item_flags & MLX5_FLOW_LAYER_TUNNEL) {
2259 if (next_proto == IPPROTO_IPIP || next_proto == IPPROTO_IPV6)
2260 return rte_flow_error_set(error, EINVAL,
2261 RTE_FLOW_ERROR_TYPE_ITEM,
2266 if (next_proto == IPPROTO_HOPOPTS ||
2267 next_proto == IPPROTO_ROUTING ||
2268 next_proto == IPPROTO_FRAGMENT ||
2269 next_proto == IPPROTO_ESP ||
2270 next_proto == IPPROTO_AH ||
2271 next_proto == IPPROTO_DSTOPTS)
2272 return rte_flow_error_set(error, EINVAL,
2273 RTE_FLOW_ERROR_TYPE_ITEM, item,
2274 "IPv6 proto (next header) should "
2275 "not be set as extension header");
2276 if (item_flags & MLX5_FLOW_LAYER_IPIP)
2277 return rte_flow_error_set(error, EINVAL,
2278 RTE_FLOW_ERROR_TYPE_ITEM, item,
2279 "wrong tunnel type - IPv4 specified "
2280 "but IPv6 item provided");
2281 if (item_flags & l3m)
2282 return rte_flow_error_set(error, ENOTSUP,
2283 RTE_FLOW_ERROR_TYPE_ITEM, item,
2284 "multiple L3 layers not supported");
2285 else if (item_flags & l4m)
2286 return rte_flow_error_set(error, EINVAL,
2287 RTE_FLOW_ERROR_TYPE_ITEM, item,
2288 "L3 cannot follow an L4 layer.");
2289 else if ((item_flags & MLX5_FLOW_LAYER_NVGRE) &&
2290 !(item_flags & MLX5_FLOW_LAYER_INNER_L2))
2291 return rte_flow_error_set(error, EINVAL,
2292 RTE_FLOW_ERROR_TYPE_ITEM, item,
2293 "L3 cannot follow an NVGRE layer.");
2295 mask = &rte_flow_item_ipv6_mask;
2296 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2297 acc_mask ? (const uint8_t *)acc_mask
2298 : (const uint8_t *)&nic_mask,
2299 sizeof(struct rte_flow_item_ipv6),
2300 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2307 * Validate UDP item.
2310 * Item specification.
2311 * @param[in] item_flags
2312 * Bit-fields that holds the items detected until now.
2313 * @param[in] target_protocol
2314 * The next protocol in the previous item.
2315 * @param[in] flow_mask
2316 * mlx5 flow-specific (DV, verbs, etc.) supported header fields mask.
2318 * Pointer to error structure.
2321 * 0 on success, a negative errno value otherwise and rte_errno is set.
2324 mlx5_flow_validate_item_udp(const struct rte_flow_item *item,
2325 uint64_t item_flags,
2326 uint8_t target_protocol,
2327 struct rte_flow_error *error)
2329 const struct rte_flow_item_udp *mask = item->mask;
2330 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2331 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2332 MLX5_FLOW_LAYER_OUTER_L3;
2333 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2334 MLX5_FLOW_LAYER_OUTER_L4;
2337 if (target_protocol != 0xff && target_protocol != IPPROTO_UDP)
2338 return rte_flow_error_set(error, EINVAL,
2339 RTE_FLOW_ERROR_TYPE_ITEM, item,
2340 "protocol filtering not compatible"
2342 if (!(item_flags & l3m))
2343 return rte_flow_error_set(error, EINVAL,
2344 RTE_FLOW_ERROR_TYPE_ITEM, item,
2345 "L3 is mandatory to filter on L4");
2346 if (item_flags & l4m)
2347 return rte_flow_error_set(error, EINVAL,
2348 RTE_FLOW_ERROR_TYPE_ITEM, item,
2349 "multiple L4 layers not supported");
2351 mask = &rte_flow_item_udp_mask;
2352 ret = mlx5_flow_item_acceptable
2353 (item, (const uint8_t *)mask,
2354 (const uint8_t *)&rte_flow_item_udp_mask,
2355 sizeof(struct rte_flow_item_udp), MLX5_ITEM_RANGE_NOT_ACCEPTED,
2363 * Validate TCP item.
2366 * Item specification.
2367 * @param[in] item_flags
2368 * Bit-fields that holds the items detected until now.
2369 * @param[in] target_protocol
2370 * The next protocol in the previous item.
2372 * Pointer to error structure.
2375 * 0 on success, a negative errno value otherwise and rte_errno is set.
2378 mlx5_flow_validate_item_tcp(const struct rte_flow_item *item,
2379 uint64_t item_flags,
2380 uint8_t target_protocol,
2381 const struct rte_flow_item_tcp *flow_mask,
2382 struct rte_flow_error *error)
2384 const struct rte_flow_item_tcp *mask = item->mask;
2385 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2386 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2387 MLX5_FLOW_LAYER_OUTER_L3;
2388 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2389 MLX5_FLOW_LAYER_OUTER_L4;
2392 MLX5_ASSERT(flow_mask);
2393 if (target_protocol != 0xff && target_protocol != IPPROTO_TCP)
2394 return rte_flow_error_set(error, EINVAL,
2395 RTE_FLOW_ERROR_TYPE_ITEM, item,
2396 "protocol filtering not compatible"
2398 if (!(item_flags & l3m))
2399 return rte_flow_error_set(error, EINVAL,
2400 RTE_FLOW_ERROR_TYPE_ITEM, item,
2401 "L3 is mandatory to filter on L4");
2402 if (item_flags & l4m)
2403 return rte_flow_error_set(error, EINVAL,
2404 RTE_FLOW_ERROR_TYPE_ITEM, item,
2405 "multiple L4 layers not supported");
2407 mask = &rte_flow_item_tcp_mask;
2408 ret = mlx5_flow_item_acceptable
2409 (item, (const uint8_t *)mask,
2410 (const uint8_t *)flow_mask,
2411 sizeof(struct rte_flow_item_tcp), MLX5_ITEM_RANGE_NOT_ACCEPTED,
2419 * Validate VXLAN item.
2422 * Pointer to the Ethernet device structure.
2424 * Item specification.
2425 * @param[in] item_flags
2426 * Bit-fields that holds the items detected until now.
2428 * Flow rule attributes.
2430 * Pointer to error structure.
2433 * 0 on success, a negative errno value otherwise and rte_errno is set.
2436 mlx5_flow_validate_item_vxlan(struct rte_eth_dev *dev,
2437 const struct rte_flow_item *item,
2438 uint64_t item_flags,
2439 const struct rte_flow_attr *attr,
2440 struct rte_flow_error *error)
2442 const struct rte_flow_item_vxlan *spec = item->spec;
2443 const struct rte_flow_item_vxlan *mask = item->mask;
2445 struct mlx5_priv *priv = dev->data->dev_private;
2449 } id = { .vlan_id = 0, };
2450 const struct rte_flow_item_vxlan nic_mask = {
2451 .vni = "\xff\xff\xff",
2454 const struct rte_flow_item_vxlan *valid_mask;
2456 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2457 return rte_flow_error_set(error, ENOTSUP,
2458 RTE_FLOW_ERROR_TYPE_ITEM, item,
2459 "multiple tunnel layers not"
2461 valid_mask = &rte_flow_item_vxlan_mask;
2463 * Verify only UDPv4 is present as defined in
2464 * https://tools.ietf.org/html/rfc7348
2466 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2467 return rte_flow_error_set(error, EINVAL,
2468 RTE_FLOW_ERROR_TYPE_ITEM, item,
2469 "no outer UDP layer found");
2471 mask = &rte_flow_item_vxlan_mask;
2472 /* FDB domain & NIC domain non-zero group */
2473 if ((attr->transfer || attr->group) && priv->sh->misc5_cap)
2474 valid_mask = &nic_mask;
2475 /* Group zero in NIC domain */
2476 if (!attr->group && !attr->transfer && priv->sh->tunnel_header_0_1)
2477 valid_mask = &nic_mask;
2478 ret = mlx5_flow_item_acceptable
2479 (item, (const uint8_t *)mask,
2480 (const uint8_t *)valid_mask,
2481 sizeof(struct rte_flow_item_vxlan),
2482 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2486 memcpy(&id.vni[1], spec->vni, 3);
2487 memcpy(&id.vni[1], mask->vni, 3);
2489 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
2490 return rte_flow_error_set(error, ENOTSUP,
2491 RTE_FLOW_ERROR_TYPE_ITEM, item,
2492 "VXLAN tunnel must be fully defined");
2497 * Validate VXLAN_GPE item.
2500 * Item specification.
2501 * @param[in] item_flags
2502 * Bit-fields that holds the items detected until now.
2504 * Pointer to the private data structure.
2505 * @param[in] target_protocol
2506 * The next protocol in the previous item.
2508 * Pointer to error structure.
2511 * 0 on success, a negative errno value otherwise and rte_errno is set.
2514 mlx5_flow_validate_item_vxlan_gpe(const struct rte_flow_item *item,
2515 uint64_t item_flags,
2516 struct rte_eth_dev *dev,
2517 struct rte_flow_error *error)
2519 struct mlx5_priv *priv = dev->data->dev_private;
2520 const struct rte_flow_item_vxlan_gpe *spec = item->spec;
2521 const struct rte_flow_item_vxlan_gpe *mask = item->mask;
2526 } id = { .vlan_id = 0, };
2528 if (!priv->config.l3_vxlan_en)
2529 return rte_flow_error_set(error, ENOTSUP,
2530 RTE_FLOW_ERROR_TYPE_ITEM, item,
2531 "L3 VXLAN is not enabled by device"
2532 " parameter and/or not configured in"
2534 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2535 return rte_flow_error_set(error, ENOTSUP,
2536 RTE_FLOW_ERROR_TYPE_ITEM, item,
2537 "multiple tunnel layers not"
2540 * Verify only UDPv4 is present as defined in
2541 * https://tools.ietf.org/html/rfc7348
2543 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2544 return rte_flow_error_set(error, EINVAL,
2545 RTE_FLOW_ERROR_TYPE_ITEM, item,
2546 "no outer UDP layer found");
2548 mask = &rte_flow_item_vxlan_gpe_mask;
2549 ret = mlx5_flow_item_acceptable
2550 (item, (const uint8_t *)mask,
2551 (const uint8_t *)&rte_flow_item_vxlan_gpe_mask,
2552 sizeof(struct rte_flow_item_vxlan_gpe),
2553 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2558 return rte_flow_error_set(error, ENOTSUP,
2559 RTE_FLOW_ERROR_TYPE_ITEM,
2561 "VxLAN-GPE protocol"
2563 memcpy(&id.vni[1], spec->vni, 3);
2564 memcpy(&id.vni[1], mask->vni, 3);
2566 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
2567 return rte_flow_error_set(error, ENOTSUP,
2568 RTE_FLOW_ERROR_TYPE_ITEM, item,
2569 "VXLAN-GPE tunnel must be fully"
2574 * Validate GRE Key item.
2577 * Item specification.
2578 * @param[in] item_flags
2579 * Bit flags to mark detected items.
2580 * @param[in] gre_item
2581 * Pointer to gre_item
2583 * Pointer to error structure.
2586 * 0 on success, a negative errno value otherwise and rte_errno is set.
2589 mlx5_flow_validate_item_gre_key(const struct rte_flow_item *item,
2590 uint64_t item_flags,
2591 const struct rte_flow_item *gre_item,
2592 struct rte_flow_error *error)
2594 const rte_be32_t *mask = item->mask;
2596 rte_be32_t gre_key_default_mask = RTE_BE32(UINT32_MAX);
2597 const struct rte_flow_item_gre *gre_spec;
2598 const struct rte_flow_item_gre *gre_mask;
2600 if (item_flags & MLX5_FLOW_LAYER_GRE_KEY)
2601 return rte_flow_error_set(error, ENOTSUP,
2602 RTE_FLOW_ERROR_TYPE_ITEM, item,
2603 "Multiple GRE key not support");
2604 if (!(item_flags & MLX5_FLOW_LAYER_GRE))
2605 return rte_flow_error_set(error, ENOTSUP,
2606 RTE_FLOW_ERROR_TYPE_ITEM, item,
2607 "No preceding GRE header");
2608 if (item_flags & MLX5_FLOW_LAYER_INNER)
2609 return rte_flow_error_set(error, ENOTSUP,
2610 RTE_FLOW_ERROR_TYPE_ITEM, item,
2611 "GRE key following a wrong item");
2612 gre_mask = gre_item->mask;
2614 gre_mask = &rte_flow_item_gre_mask;
2615 gre_spec = gre_item->spec;
2616 if (gre_spec && (gre_mask->c_rsvd0_ver & RTE_BE16(0x2000)) &&
2617 !(gre_spec->c_rsvd0_ver & RTE_BE16(0x2000)))
2618 return rte_flow_error_set(error, EINVAL,
2619 RTE_FLOW_ERROR_TYPE_ITEM, item,
2620 "Key bit must be on");
2623 mask = &gre_key_default_mask;
2624 ret = mlx5_flow_item_acceptable
2625 (item, (const uint8_t *)mask,
2626 (const uint8_t *)&gre_key_default_mask,
2627 sizeof(rte_be32_t), MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2632 * Validate GRE item.
2635 * Item specification.
2636 * @param[in] item_flags
2637 * Bit flags to mark detected items.
2638 * @param[in] target_protocol
2639 * The next protocol in the previous item.
2641 * Pointer to error structure.
2644 * 0 on success, a negative errno value otherwise and rte_errno is set.
2647 mlx5_flow_validate_item_gre(const struct rte_flow_item *item,
2648 uint64_t item_flags,
2649 uint8_t target_protocol,
2650 struct rte_flow_error *error)
2652 const struct rte_flow_item_gre *spec __rte_unused = item->spec;
2653 const struct rte_flow_item_gre *mask = item->mask;
2655 const struct rte_flow_item_gre nic_mask = {
2656 .c_rsvd0_ver = RTE_BE16(0xB000),
2657 .protocol = RTE_BE16(UINT16_MAX),
2660 if (target_protocol != 0xff && target_protocol != IPPROTO_GRE)
2661 return rte_flow_error_set(error, EINVAL,
2662 RTE_FLOW_ERROR_TYPE_ITEM, item,
2663 "protocol filtering not compatible"
2664 " with this GRE layer");
2665 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2666 return rte_flow_error_set(error, ENOTSUP,
2667 RTE_FLOW_ERROR_TYPE_ITEM, item,
2668 "multiple tunnel layers not"
2670 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3))
2671 return rte_flow_error_set(error, ENOTSUP,
2672 RTE_FLOW_ERROR_TYPE_ITEM, item,
2673 "L3 Layer is missing");
2675 mask = &rte_flow_item_gre_mask;
2676 ret = mlx5_flow_item_acceptable
2677 (item, (const uint8_t *)mask,
2678 (const uint8_t *)&nic_mask,
2679 sizeof(struct rte_flow_item_gre), MLX5_ITEM_RANGE_NOT_ACCEPTED,
2683 #ifndef HAVE_MLX5DV_DR
2684 #ifndef HAVE_IBV_DEVICE_MPLS_SUPPORT
2685 if (spec && (spec->protocol & mask->protocol))
2686 return rte_flow_error_set(error, ENOTSUP,
2687 RTE_FLOW_ERROR_TYPE_ITEM, item,
2688 "without MPLS support the"
2689 " specification cannot be used for"
2697 * Validate Geneve item.
2700 * Item specification.
2701 * @param[in] itemFlags
2702 * Bit-fields that holds the items detected until now.
2704 * Pointer to the private data structure.
2706 * Pointer to error structure.
2709 * 0 on success, a negative errno value otherwise and rte_errno is set.
2713 mlx5_flow_validate_item_geneve(const struct rte_flow_item *item,
2714 uint64_t item_flags,
2715 struct rte_eth_dev *dev,
2716 struct rte_flow_error *error)
2718 struct mlx5_priv *priv = dev->data->dev_private;
2719 const struct rte_flow_item_geneve *spec = item->spec;
2720 const struct rte_flow_item_geneve *mask = item->mask;
2723 uint8_t opt_len = priv->config.hca_attr.geneve_max_opt_len ?
2724 MLX5_GENEVE_OPT_LEN_1 : MLX5_GENEVE_OPT_LEN_0;
2725 const struct rte_flow_item_geneve nic_mask = {
2726 .ver_opt_len_o_c_rsvd0 = RTE_BE16(0x3f80),
2727 .vni = "\xff\xff\xff",
2728 .protocol = RTE_BE16(UINT16_MAX),
2731 if (!priv->config.hca_attr.tunnel_stateless_geneve_rx)
2732 return rte_flow_error_set(error, ENOTSUP,
2733 RTE_FLOW_ERROR_TYPE_ITEM, item,
2734 "L3 Geneve is not enabled by device"
2735 " parameter and/or not configured in"
2737 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2738 return rte_flow_error_set(error, ENOTSUP,
2739 RTE_FLOW_ERROR_TYPE_ITEM, item,
2740 "multiple tunnel layers not"
2743 * Verify only UDPv4 is present as defined in
2744 * https://tools.ietf.org/html/rfc7348
2746 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2747 return rte_flow_error_set(error, EINVAL,
2748 RTE_FLOW_ERROR_TYPE_ITEM, item,
2749 "no outer UDP layer found");
2751 mask = &rte_flow_item_geneve_mask;
2752 ret = mlx5_flow_item_acceptable
2753 (item, (const uint8_t *)mask,
2754 (const uint8_t *)&nic_mask,
2755 sizeof(struct rte_flow_item_geneve),
2756 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2760 gbhdr = rte_be_to_cpu_16(spec->ver_opt_len_o_c_rsvd0);
2761 if (MLX5_GENEVE_VER_VAL(gbhdr) ||
2762 MLX5_GENEVE_CRITO_VAL(gbhdr) ||
2763 MLX5_GENEVE_RSVD_VAL(gbhdr) || spec->rsvd1)
2764 return rte_flow_error_set(error, ENOTSUP,
2765 RTE_FLOW_ERROR_TYPE_ITEM,
2767 "Geneve protocol unsupported"
2768 " fields are being used");
2769 if (MLX5_GENEVE_OPTLEN_VAL(gbhdr) > opt_len)
2770 return rte_flow_error_set
2772 RTE_FLOW_ERROR_TYPE_ITEM,
2774 "Unsupported Geneve options length");
2776 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
2777 return rte_flow_error_set
2779 RTE_FLOW_ERROR_TYPE_ITEM, item,
2780 "Geneve tunnel must be fully defined");
2785 * Validate Geneve TLV option item.
2788 * Item specification.
2789 * @param[in] last_item
2790 * Previous validated item in the pattern items.
2791 * @param[in] geneve_item
2792 * Previous GENEVE item specification.
2794 * Pointer to the rte_eth_dev structure.
2796 * Pointer to error structure.
2799 * 0 on success, a negative errno value otherwise and rte_errno is set.
2802 mlx5_flow_validate_item_geneve_opt(const struct rte_flow_item *item,
2804 const struct rte_flow_item *geneve_item,
2805 struct rte_eth_dev *dev,
2806 struct rte_flow_error *error)
2808 struct mlx5_priv *priv = dev->data->dev_private;
2809 struct mlx5_dev_ctx_shared *sh = priv->sh;
2810 struct mlx5_geneve_tlv_option_resource *geneve_opt_resource;
2811 struct mlx5_hca_attr *hca_attr = &priv->config.hca_attr;
2812 uint8_t data_max_supported =
2813 hca_attr->max_geneve_tlv_option_data_len * 4;
2814 struct mlx5_dev_config *config = &priv->config;
2815 const struct rte_flow_item_geneve *geneve_spec;
2816 const struct rte_flow_item_geneve *geneve_mask;
2817 const struct rte_flow_item_geneve_opt *spec = item->spec;
2818 const struct rte_flow_item_geneve_opt *mask = item->mask;
2820 unsigned int data_len;
2821 uint8_t tlv_option_len;
2822 uint16_t optlen_m, optlen_v;
2823 const struct rte_flow_item_geneve_opt full_mask = {
2824 .option_class = RTE_BE16(0xffff),
2825 .option_type = 0xff,
2830 mask = &rte_flow_item_geneve_opt_mask;
2832 return rte_flow_error_set
2833 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2834 "Geneve TLV opt class/type/length must be specified");
2835 if ((uint32_t)spec->option_len > MLX5_GENEVE_OPTLEN_MASK)
2836 return rte_flow_error_set
2837 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2838 "Geneve TLV opt length exceeeds the limit (31)");
2839 /* Check if class type and length masks are full. */
2840 if (full_mask.option_class != mask->option_class ||
2841 full_mask.option_type != mask->option_type ||
2842 full_mask.option_len != (mask->option_len & full_mask.option_len))
2843 return rte_flow_error_set
2844 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2845 "Geneve TLV opt class/type/length masks must be full");
2846 /* Check if length is supported */
2847 if ((uint32_t)spec->option_len >
2848 config->hca_attr.max_geneve_tlv_option_data_len)
2849 return rte_flow_error_set
2850 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2851 "Geneve TLV opt length not supported");
2852 if (config->hca_attr.max_geneve_tlv_options > 1)
2854 "max_geneve_tlv_options supports more than 1 option");
2855 /* Check GENEVE item preceding. */
2856 if (!geneve_item || !(last_item & MLX5_FLOW_LAYER_GENEVE))
2857 return rte_flow_error_set
2858 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2859 "Geneve opt item must be preceded with Geneve item");
2860 geneve_spec = geneve_item->spec;
2861 geneve_mask = geneve_item->mask ? geneve_item->mask :
2862 &rte_flow_item_geneve_mask;
2863 /* Check if GENEVE TLV option size doesn't exceed option length */
2864 if (geneve_spec && (geneve_mask->ver_opt_len_o_c_rsvd0 ||
2865 geneve_spec->ver_opt_len_o_c_rsvd0)) {
2866 tlv_option_len = spec->option_len & mask->option_len;
2867 optlen_v = rte_be_to_cpu_16(geneve_spec->ver_opt_len_o_c_rsvd0);
2868 optlen_v = MLX5_GENEVE_OPTLEN_VAL(optlen_v);
2869 optlen_m = rte_be_to_cpu_16(geneve_mask->ver_opt_len_o_c_rsvd0);
2870 optlen_m = MLX5_GENEVE_OPTLEN_VAL(optlen_m);
2871 if ((optlen_v & optlen_m) <= tlv_option_len)
2872 return rte_flow_error_set
2873 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2874 "GENEVE TLV option length exceeds optlen");
2876 /* Check if length is 0 or data is 0. */
2877 if (spec->data == NULL || spec->option_len == 0)
2878 return rte_flow_error_set
2879 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2880 "Geneve TLV opt with zero data/length not supported");
2881 /* Check not all data & mask are 0. */
2882 data_len = spec->option_len * 4;
2883 if (mask->data == NULL) {
2884 for (i = 0; i < data_len; i++)
2888 return rte_flow_error_set(error, ENOTSUP,
2889 RTE_FLOW_ERROR_TYPE_ITEM, item,
2890 "Can't match on Geneve option data 0");
2892 for (i = 0; i < data_len; i++)
2893 if (spec->data[i] & mask->data[i])
2896 return rte_flow_error_set(error, ENOTSUP,
2897 RTE_FLOW_ERROR_TYPE_ITEM, item,
2898 "Can't match on Geneve option data and mask 0");
2899 /* Check data mask supported. */
2900 for (i = data_max_supported; i < data_len ; i++)
2902 return rte_flow_error_set(error, ENOTSUP,
2903 RTE_FLOW_ERROR_TYPE_ITEM, item,
2904 "Data mask is of unsupported size");
2906 /* Check GENEVE option is supported in NIC. */
2907 if (!config->hca_attr.geneve_tlv_opt)
2908 return rte_flow_error_set
2909 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2910 "Geneve TLV opt not supported");
2911 /* Check if we already have geneve option with different type/class. */
2912 rte_spinlock_lock(&sh->geneve_tlv_opt_sl);
2913 geneve_opt_resource = sh->geneve_tlv_option_resource;
2914 if (geneve_opt_resource != NULL)
2915 if (geneve_opt_resource->option_class != spec->option_class ||
2916 geneve_opt_resource->option_type != spec->option_type ||
2917 geneve_opt_resource->length != spec->option_len) {
2918 rte_spinlock_unlock(&sh->geneve_tlv_opt_sl);
2919 return rte_flow_error_set(error, ENOTSUP,
2920 RTE_FLOW_ERROR_TYPE_ITEM, item,
2921 "Only one Geneve TLV option supported");
2923 rte_spinlock_unlock(&sh->geneve_tlv_opt_sl);
2928 * Validate MPLS item.
2931 * Pointer to the rte_eth_dev structure.
2933 * Item specification.
2934 * @param[in] item_flags
2935 * Bit-fields that holds the items detected until now.
2936 * @param[in] prev_layer
2937 * The protocol layer indicated in previous item.
2939 * Pointer to error structure.
2942 * 0 on success, a negative errno value otherwise and rte_errno is set.
2945 mlx5_flow_validate_item_mpls(struct rte_eth_dev *dev __rte_unused,
2946 const struct rte_flow_item *item __rte_unused,
2947 uint64_t item_flags __rte_unused,
2948 uint64_t prev_layer __rte_unused,
2949 struct rte_flow_error *error)
2951 #ifdef HAVE_IBV_DEVICE_MPLS_SUPPORT
2952 const struct rte_flow_item_mpls *mask = item->mask;
2953 struct mlx5_priv *priv = dev->data->dev_private;
2956 if (!priv->config.mpls_en)
2957 return rte_flow_error_set(error, ENOTSUP,
2958 RTE_FLOW_ERROR_TYPE_ITEM, item,
2959 "MPLS not supported or"
2960 " disabled in firmware"
2962 /* MPLS over UDP, GRE is allowed */
2963 if (!(prev_layer & (MLX5_FLOW_LAYER_OUTER_L4_UDP |
2964 MLX5_FLOW_LAYER_GRE |
2965 MLX5_FLOW_LAYER_GRE_KEY)))
2966 return rte_flow_error_set(error, EINVAL,
2967 RTE_FLOW_ERROR_TYPE_ITEM, item,
2968 "protocol filtering not compatible"
2969 " with MPLS layer");
2970 /* Multi-tunnel isn't allowed but MPLS over GRE is an exception. */
2971 if ((item_flags & MLX5_FLOW_LAYER_TUNNEL) &&
2972 !(item_flags & MLX5_FLOW_LAYER_GRE))
2973 return rte_flow_error_set(error, ENOTSUP,
2974 RTE_FLOW_ERROR_TYPE_ITEM, item,
2975 "multiple tunnel layers not"
2978 mask = &rte_flow_item_mpls_mask;
2979 ret = mlx5_flow_item_acceptable
2980 (item, (const uint8_t *)mask,
2981 (const uint8_t *)&rte_flow_item_mpls_mask,
2982 sizeof(struct rte_flow_item_mpls),
2983 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2988 return rte_flow_error_set(error, ENOTSUP,
2989 RTE_FLOW_ERROR_TYPE_ITEM, item,
2990 "MPLS is not supported by Verbs, please"
2996 * Validate NVGRE item.
2999 * Item specification.
3000 * @param[in] item_flags
3001 * Bit flags to mark detected items.
3002 * @param[in] target_protocol
3003 * The next protocol in the previous item.
3005 * Pointer to error structure.
3008 * 0 on success, a negative errno value otherwise and rte_errno is set.
3011 mlx5_flow_validate_item_nvgre(const struct rte_flow_item *item,
3012 uint64_t item_flags,
3013 uint8_t target_protocol,
3014 struct rte_flow_error *error)
3016 const struct rte_flow_item_nvgre *mask = item->mask;
3019 if (target_protocol != 0xff && target_protocol != IPPROTO_GRE)
3020 return rte_flow_error_set(error, EINVAL,
3021 RTE_FLOW_ERROR_TYPE_ITEM, item,
3022 "protocol filtering not compatible"
3023 " with this GRE layer");
3024 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
3025 return rte_flow_error_set(error, ENOTSUP,
3026 RTE_FLOW_ERROR_TYPE_ITEM, item,
3027 "multiple tunnel layers not"
3029 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3))
3030 return rte_flow_error_set(error, ENOTSUP,
3031 RTE_FLOW_ERROR_TYPE_ITEM, item,
3032 "L3 Layer is missing");
3034 mask = &rte_flow_item_nvgre_mask;
3035 ret = mlx5_flow_item_acceptable
3036 (item, (const uint8_t *)mask,
3037 (const uint8_t *)&rte_flow_item_nvgre_mask,
3038 sizeof(struct rte_flow_item_nvgre),
3039 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
3046 * Validate eCPRI item.
3049 * Item specification.
3050 * @param[in] item_flags
3051 * Bit-fields that holds the items detected until now.
3052 * @param[in] last_item
3053 * Previous validated item in the pattern items.
3054 * @param[in] ether_type
3055 * Type in the ethernet layer header (including dot1q).
3056 * @param[in] acc_mask
3057 * Acceptable mask, if NULL default internal default mask
3058 * will be used to check whether item fields are supported.
3060 * Pointer to error structure.
3063 * 0 on success, a negative errno value otherwise and rte_errno is set.
3066 mlx5_flow_validate_item_ecpri(const struct rte_flow_item *item,
3067 uint64_t item_flags,
3069 uint16_t ether_type,
3070 const struct rte_flow_item_ecpri *acc_mask,
3071 struct rte_flow_error *error)
3073 const struct rte_flow_item_ecpri *mask = item->mask;
3074 const struct rte_flow_item_ecpri nic_mask = {
3078 RTE_BE32(((const struct rte_ecpri_common_hdr) {
3082 .dummy[0] = 0xFFFFFFFF,
3085 const uint64_t outer_l2_vlan = (MLX5_FLOW_LAYER_OUTER_L2 |
3086 MLX5_FLOW_LAYER_OUTER_VLAN);
3087 struct rte_flow_item_ecpri mask_lo;
3089 if (!(last_item & outer_l2_vlan) &&
3090 last_item != MLX5_FLOW_LAYER_OUTER_L4_UDP)
3091 return rte_flow_error_set(error, EINVAL,
3092 RTE_FLOW_ERROR_TYPE_ITEM, item,
3093 "eCPRI can only follow L2/VLAN layer or UDP layer");
3094 if ((last_item & outer_l2_vlan) && ether_type &&
3095 ether_type != RTE_ETHER_TYPE_ECPRI)
3096 return rte_flow_error_set(error, EINVAL,
3097 RTE_FLOW_ERROR_TYPE_ITEM, item,
3098 "eCPRI cannot follow L2/VLAN layer which ether type is not 0xAEFE");
3099 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
3100 return rte_flow_error_set(error, EINVAL,
3101 RTE_FLOW_ERROR_TYPE_ITEM, item,
3102 "eCPRI with tunnel is not supported right now");
3103 if (item_flags & MLX5_FLOW_LAYER_OUTER_L3)
3104 return rte_flow_error_set(error, ENOTSUP,
3105 RTE_FLOW_ERROR_TYPE_ITEM, item,
3106 "multiple L3 layers not supported");
3107 else if (item_flags & MLX5_FLOW_LAYER_OUTER_L4_TCP)
3108 return rte_flow_error_set(error, EINVAL,
3109 RTE_FLOW_ERROR_TYPE_ITEM, item,
3110 "eCPRI cannot coexist with a TCP layer");
3111 /* In specification, eCPRI could be over UDP layer. */
3112 else if (item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP)
3113 return rte_flow_error_set(error, EINVAL,
3114 RTE_FLOW_ERROR_TYPE_ITEM, item,
3115 "eCPRI over UDP layer is not yet supported right now");
3116 /* Mask for type field in common header could be zero. */
3118 mask = &rte_flow_item_ecpri_mask;
3119 mask_lo.hdr.common.u32 = rte_be_to_cpu_32(mask->hdr.common.u32);
3120 /* Input mask is in big-endian format. */
3121 if (mask_lo.hdr.common.type != 0 && mask_lo.hdr.common.type != 0xff)
3122 return rte_flow_error_set(error, EINVAL,
3123 RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
3124 "partial mask is not supported for protocol");
3125 else if (mask_lo.hdr.common.type == 0 && mask->hdr.dummy[0] != 0)
3126 return rte_flow_error_set(error, EINVAL,
3127 RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
3128 "message header mask must be after a type mask");
3129 return mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
3130 acc_mask ? (const uint8_t *)acc_mask
3131 : (const uint8_t *)&nic_mask,
3132 sizeof(struct rte_flow_item_ecpri),
3133 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
3137 flow_null_validate(struct rte_eth_dev *dev __rte_unused,
3138 const struct rte_flow_attr *attr __rte_unused,
3139 const struct rte_flow_item items[] __rte_unused,
3140 const struct rte_flow_action actions[] __rte_unused,
3141 bool external __rte_unused,
3142 int hairpin __rte_unused,
3143 struct rte_flow_error *error)
3145 return rte_flow_error_set(error, ENOTSUP,
3146 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
3149 static struct mlx5_flow *
3150 flow_null_prepare(struct rte_eth_dev *dev __rte_unused,
3151 const struct rte_flow_attr *attr __rte_unused,
3152 const struct rte_flow_item items[] __rte_unused,
3153 const struct rte_flow_action actions[] __rte_unused,
3154 struct rte_flow_error *error)
3156 rte_flow_error_set(error, ENOTSUP,
3157 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
3162 flow_null_translate(struct rte_eth_dev *dev __rte_unused,
3163 struct mlx5_flow *dev_flow __rte_unused,
3164 const struct rte_flow_attr *attr __rte_unused,
3165 const struct rte_flow_item items[] __rte_unused,
3166 const struct rte_flow_action actions[] __rte_unused,
3167 struct rte_flow_error *error)
3169 return rte_flow_error_set(error, ENOTSUP,
3170 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
3174 flow_null_apply(struct rte_eth_dev *dev __rte_unused,
3175 struct rte_flow *flow __rte_unused,
3176 struct rte_flow_error *error)
3178 return rte_flow_error_set(error, ENOTSUP,
3179 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
3183 flow_null_remove(struct rte_eth_dev *dev __rte_unused,
3184 struct rte_flow *flow __rte_unused)
3189 flow_null_destroy(struct rte_eth_dev *dev __rte_unused,
3190 struct rte_flow *flow __rte_unused)
3195 flow_null_query(struct rte_eth_dev *dev __rte_unused,
3196 struct rte_flow *flow __rte_unused,
3197 const struct rte_flow_action *actions __rte_unused,
3198 void *data __rte_unused,
3199 struct rte_flow_error *error)
3201 return rte_flow_error_set(error, ENOTSUP,
3202 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
3206 flow_null_sync_domain(struct rte_eth_dev *dev __rte_unused,
3207 uint32_t domains __rte_unused,
3208 uint32_t flags __rte_unused)
3213 /* Void driver to protect from null pointer reference. */
3214 const struct mlx5_flow_driver_ops mlx5_flow_null_drv_ops = {
3215 .validate = flow_null_validate,
3216 .prepare = flow_null_prepare,
3217 .translate = flow_null_translate,
3218 .apply = flow_null_apply,
3219 .remove = flow_null_remove,
3220 .destroy = flow_null_destroy,
3221 .query = flow_null_query,
3222 .sync_domain = flow_null_sync_domain,
3226 * Select flow driver type according to flow attributes and device
3230 * Pointer to the dev structure.
3232 * Pointer to the flow attributes.
3235 * flow driver type, MLX5_FLOW_TYPE_MAX otherwise.
3237 static enum mlx5_flow_drv_type
3238 flow_get_drv_type(struct rte_eth_dev *dev, const struct rte_flow_attr *attr)
3240 struct mlx5_priv *priv = dev->data->dev_private;
3241 /* The OS can determine first a specific flow type (DV, VERBS) */
3242 enum mlx5_flow_drv_type type = mlx5_flow_os_get_type();
3244 if (type != MLX5_FLOW_TYPE_MAX)
3246 /* If no OS specific type - continue with DV/VERBS selection */
3247 if (attr->transfer && priv->config.dv_esw_en)
3248 type = MLX5_FLOW_TYPE_DV;
3249 if (!attr->transfer)
3250 type = priv->config.dv_flow_en ? MLX5_FLOW_TYPE_DV :
3251 MLX5_FLOW_TYPE_VERBS;
3255 #define flow_get_drv_ops(type) flow_drv_ops[type]
3258 * Flow driver validation API. This abstracts calling driver specific functions.
3259 * The type of flow driver is determined according to flow attributes.
3262 * Pointer to the dev structure.
3264 * Pointer to the flow attributes.
3266 * Pointer to the list of items.
3267 * @param[in] actions
3268 * Pointer to the list of actions.
3269 * @param[in] external
3270 * This flow rule is created by request external to PMD.
3271 * @param[in] hairpin
3272 * Number of hairpin TX actions, 0 means classic flow.
3274 * Pointer to the error structure.
3277 * 0 on success, a negative errno value otherwise and rte_errno is set.
3280 flow_drv_validate(struct rte_eth_dev *dev,
3281 const struct rte_flow_attr *attr,
3282 const struct rte_flow_item items[],
3283 const struct rte_flow_action actions[],
3284 bool external, int hairpin, struct rte_flow_error *error)
3286 const struct mlx5_flow_driver_ops *fops;
3287 enum mlx5_flow_drv_type type = flow_get_drv_type(dev, attr);
3289 fops = flow_get_drv_ops(type);
3290 return fops->validate(dev, attr, items, actions, external,
3295 * Flow driver preparation API. This abstracts calling driver specific
3296 * functions. Parent flow (rte_flow) should have driver type (drv_type). It
3297 * calculates the size of memory required for device flow, allocates the memory,
3298 * initializes the device flow and returns the pointer.
3301 * This function initializes device flow structure such as dv or verbs in
3302 * struct mlx5_flow. However, it is caller's responsibility to initialize the
3303 * rest. For example, adding returning device flow to flow->dev_flow list and
3304 * setting backward reference to the flow should be done out of this function.
3305 * layers field is not filled either.
3308 * Pointer to the dev structure.
3310 * Pointer to the flow attributes.
3312 * Pointer to the list of items.
3313 * @param[in] actions
3314 * Pointer to the list of actions.
3315 * @param[in] flow_idx
3316 * This memory pool index to the flow.
3318 * Pointer to the error structure.
3321 * Pointer to device flow on success, otherwise NULL and rte_errno is set.
3323 static inline struct mlx5_flow *
3324 flow_drv_prepare(struct rte_eth_dev *dev,
3325 const struct rte_flow *flow,
3326 const struct rte_flow_attr *attr,
3327 const struct rte_flow_item items[],
3328 const struct rte_flow_action actions[],
3330 struct rte_flow_error *error)
3332 const struct mlx5_flow_driver_ops *fops;
3333 enum mlx5_flow_drv_type type = flow->drv_type;
3334 struct mlx5_flow *mlx5_flow = NULL;
3336 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3337 fops = flow_get_drv_ops(type);
3338 mlx5_flow = fops->prepare(dev, attr, items, actions, error);
3340 mlx5_flow->flow_idx = flow_idx;
3345 * Flow driver translation API. This abstracts calling driver specific
3346 * functions. Parent flow (rte_flow) should have driver type (drv_type). It
3347 * translates a generic flow into a driver flow. flow_drv_prepare() must
3351 * dev_flow->layers could be filled as a result of parsing during translation
3352 * if needed by flow_drv_apply(). dev_flow->flow->actions can also be filled
3353 * if necessary. As a flow can have multiple dev_flows by RSS flow expansion,
3354 * flow->actions could be overwritten even though all the expanded dev_flows
3355 * have the same actions.
3358 * Pointer to the rte dev structure.
3359 * @param[in, out] dev_flow
3360 * Pointer to the mlx5 flow.
3362 * Pointer to the flow attributes.
3364 * Pointer to the list of items.
3365 * @param[in] actions
3366 * Pointer to the list of actions.
3368 * Pointer to the error structure.
3371 * 0 on success, a negative errno value otherwise and rte_errno is set.
3374 flow_drv_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
3375 const struct rte_flow_attr *attr,
3376 const struct rte_flow_item items[],
3377 const struct rte_flow_action actions[],
3378 struct rte_flow_error *error)
3380 const struct mlx5_flow_driver_ops *fops;
3381 enum mlx5_flow_drv_type type = dev_flow->flow->drv_type;
3383 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3384 fops = flow_get_drv_ops(type);
3385 return fops->translate(dev, dev_flow, attr, items, actions, error);
3389 * Flow driver apply API. This abstracts calling driver specific functions.
3390 * Parent flow (rte_flow) should have driver type (drv_type). It applies
3391 * translated driver flows on to device. flow_drv_translate() must precede.
3394 * Pointer to Ethernet device structure.
3395 * @param[in, out] flow
3396 * Pointer to flow structure.
3398 * Pointer to error structure.
3401 * 0 on success, a negative errno value otherwise and rte_errno is set.
3404 flow_drv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
3405 struct rte_flow_error *error)
3407 const struct mlx5_flow_driver_ops *fops;
3408 enum mlx5_flow_drv_type type = flow->drv_type;
3410 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3411 fops = flow_get_drv_ops(type);
3412 return fops->apply(dev, flow, error);
3416 * Flow driver destroy API. This abstracts calling driver specific functions.
3417 * Parent flow (rte_flow) should have driver type (drv_type). It removes a flow
3418 * on device and releases resources of the flow.
3421 * Pointer to Ethernet device.
3422 * @param[in, out] flow
3423 * Pointer to flow structure.
3426 flow_drv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
3428 const struct mlx5_flow_driver_ops *fops;
3429 enum mlx5_flow_drv_type type = flow->drv_type;
3431 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3432 fops = flow_get_drv_ops(type);
3433 fops->destroy(dev, flow);
3437 * Flow driver find RSS policy tbl API. This abstracts calling driver
3438 * specific functions. Parent flow (rte_flow) should have driver
3439 * type (drv_type). It will find the RSS policy table that has the rss_desc.
3442 * Pointer to Ethernet device.
3443 * @param[in, out] flow
3444 * Pointer to flow structure.
3446 * Pointer to meter policy table.
3447 * @param[in] rss_desc
3448 * Pointer to rss_desc
3450 static struct mlx5_flow_meter_sub_policy *
3451 flow_drv_meter_sub_policy_rss_prepare(struct rte_eth_dev *dev,
3452 struct rte_flow *flow,
3453 struct mlx5_flow_meter_policy *policy,
3454 struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS])
3456 const struct mlx5_flow_driver_ops *fops;
3457 enum mlx5_flow_drv_type type = flow->drv_type;
3459 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3460 fops = flow_get_drv_ops(type);
3461 return fops->meter_sub_policy_rss_prepare(dev, policy, rss_desc);
3465 * Flow driver color tag rule API. This abstracts calling driver
3466 * specific functions. Parent flow (rte_flow) should have driver
3467 * type (drv_type). It will create the color tag rules in hierarchy meter.
3470 * Pointer to Ethernet device.
3471 * @param[in, out] flow
3472 * Pointer to flow structure.
3474 * Pointer to flow meter structure.
3475 * @param[in] src_port
3476 * The src port this extra rule should use.
3478 * The src port id match item.
3480 * Pointer to error structure.
3483 flow_drv_mtr_hierarchy_rule_create(struct rte_eth_dev *dev,
3484 struct rte_flow *flow,
3485 struct mlx5_flow_meter_info *fm,
3487 const struct rte_flow_item *item,
3488 struct rte_flow_error *error)
3490 const struct mlx5_flow_driver_ops *fops;
3491 enum mlx5_flow_drv_type type = flow->drv_type;
3493 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3494 fops = flow_get_drv_ops(type);
3495 return fops->meter_hierarchy_rule_create(dev, fm,
3496 src_port, item, error);
3500 * Get RSS action from the action list.
3503 * Pointer to Ethernet device.
3504 * @param[in] actions
3505 * Pointer to the list of actions.
3507 * Parent flow structure pointer.
3510 * Pointer to the RSS action if exist, else return NULL.
3512 static const struct rte_flow_action_rss*
3513 flow_get_rss_action(struct rte_eth_dev *dev,
3514 const struct rte_flow_action actions[])
3516 struct mlx5_priv *priv = dev->data->dev_private;
3517 const struct rte_flow_action_rss *rss = NULL;
3519 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3520 switch (actions->type) {
3521 case RTE_FLOW_ACTION_TYPE_RSS:
3522 rss = actions->conf;
3524 case RTE_FLOW_ACTION_TYPE_SAMPLE:
3526 const struct rte_flow_action_sample *sample =
3528 const struct rte_flow_action *act = sample->actions;
3529 for (; act->type != RTE_FLOW_ACTION_TYPE_END; act++)
3530 if (act->type == RTE_FLOW_ACTION_TYPE_RSS)
3534 case RTE_FLOW_ACTION_TYPE_METER:
3537 struct mlx5_flow_meter_info *fm;
3538 struct mlx5_flow_meter_policy *policy;
3539 const struct rte_flow_action_meter *mtr = actions->conf;
3541 fm = mlx5_flow_meter_find(priv, mtr->mtr_id, &mtr_idx);
3542 if (fm && !fm->def_policy) {
3543 policy = mlx5_flow_meter_policy_find(dev,
3544 fm->policy_id, NULL);
3545 MLX5_ASSERT(policy);
3546 if (policy->is_hierarchy) {
3548 mlx5_flow_meter_hierarchy_get_final_policy(dev,
3555 policy->act_cnt[RTE_COLOR_GREEN].rss->conf;
3567 * Get ASO age action by index.
3570 * Pointer to the Ethernet device structure.
3571 * @param[in] age_idx
3572 * Index to the ASO age action.
3575 * The specified ASO age action.
3577 struct mlx5_aso_age_action*
3578 flow_aso_age_get_by_idx(struct rte_eth_dev *dev, uint32_t age_idx)
3580 uint16_t pool_idx = age_idx & UINT16_MAX;
3581 uint16_t offset = (age_idx >> 16) & UINT16_MAX;
3582 struct mlx5_priv *priv = dev->data->dev_private;
3583 struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
3584 struct mlx5_aso_age_pool *pool = mng->pools[pool_idx];
3586 return &pool->actions[offset - 1];
3589 /* maps indirect action to translated direct in some actions array */
3590 struct mlx5_translated_action_handle {
3591 struct rte_flow_action_handle *action; /**< Indirect action handle. */
3592 int index; /**< Index in related array of rte_flow_action. */
3596 * Translates actions of type RTE_FLOW_ACTION_TYPE_INDIRECT to related
3597 * direct action if translation possible.
3598 * This functionality used to run same execution path for both direct and
3599 * indirect actions on flow create. All necessary preparations for indirect
3600 * action handling should be performed on *handle* actions list returned
3604 * Pointer to Ethernet device.
3605 * @param[in] actions
3606 * List of actions to translate.
3607 * @param[out] handle
3608 * List to store translated indirect action object handles.
3609 * @param[in, out] indir_n
3610 * Size of *handle* array. On return should be updated with number of
3611 * indirect actions retrieved from the *actions* list.
3612 * @param[out] translated_actions
3613 * List of actions where all indirect actions were translated to direct
3614 * if possible. NULL if no translation took place.
3616 * Pointer to the error structure.
3619 * 0 on success, a negative errno value otherwise and rte_errno is set.
3622 flow_action_handles_translate(struct rte_eth_dev *dev,
3623 const struct rte_flow_action actions[],
3624 struct mlx5_translated_action_handle *handle,
3626 struct rte_flow_action **translated_actions,
3627 struct rte_flow_error *error)
3629 struct mlx5_priv *priv = dev->data->dev_private;
3630 struct rte_flow_action *translated = NULL;
3631 size_t actions_size;
3634 struct mlx5_translated_action_handle *handle_end = NULL;
3636 for (n = 0; actions[n].type != RTE_FLOW_ACTION_TYPE_END; n++) {
3637 if (actions[n].type != RTE_FLOW_ACTION_TYPE_INDIRECT)
3639 if (copied_n == *indir_n) {
3640 return rte_flow_error_set
3641 (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION_NUM,
3642 NULL, "too many shared actions");
3644 rte_memcpy(&handle[copied_n].action, &actions[n].conf,
3645 sizeof(actions[n].conf));
3646 handle[copied_n].index = n;
3650 *indir_n = copied_n;
3653 actions_size = sizeof(struct rte_flow_action) * n;
3654 translated = mlx5_malloc(MLX5_MEM_ZERO, actions_size, 0, SOCKET_ID_ANY);
3659 memcpy(translated, actions, actions_size);
3660 for (handle_end = handle + copied_n; handle < handle_end; handle++) {
3661 struct mlx5_shared_action_rss *shared_rss;
3662 uint32_t act_idx = (uint32_t)(uintptr_t)handle->action;
3663 uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
3664 uint32_t idx = act_idx &
3665 ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
3668 case MLX5_INDIRECT_ACTION_TYPE_RSS:
3669 shared_rss = mlx5_ipool_get
3670 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
3671 translated[handle->index].type =
3672 RTE_FLOW_ACTION_TYPE_RSS;
3673 translated[handle->index].conf =
3674 &shared_rss->origin;
3676 case MLX5_INDIRECT_ACTION_TYPE_COUNT:
3677 translated[handle->index].type =
3678 (enum rte_flow_action_type)
3679 MLX5_RTE_FLOW_ACTION_TYPE_COUNT;
3680 translated[handle->index].conf = (void *)(uintptr_t)idx;
3682 case MLX5_INDIRECT_ACTION_TYPE_AGE:
3683 if (priv->sh->flow_hit_aso_en) {
3684 translated[handle->index].type =
3685 (enum rte_flow_action_type)
3686 MLX5_RTE_FLOW_ACTION_TYPE_AGE;
3687 translated[handle->index].conf =
3688 (void *)(uintptr_t)idx;
3692 case MLX5_INDIRECT_ACTION_TYPE_CT:
3693 if (priv->sh->ct_aso_en) {
3694 translated[handle->index].type =
3695 RTE_FLOW_ACTION_TYPE_CONNTRACK;
3696 translated[handle->index].conf =
3697 (void *)(uintptr_t)idx;
3702 mlx5_free(translated);
3703 return rte_flow_error_set
3704 (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
3705 NULL, "invalid indirect action type");
3708 *translated_actions = translated;
3713 * Get Shared RSS action from the action list.
3716 * Pointer to Ethernet device.
3718 * Pointer to the list of actions.
3719 * @param[in] shared_n
3720 * Actions list length.
3723 * The MLX5 RSS action ID if exists, otherwise return 0.
3726 flow_get_shared_rss_action(struct rte_eth_dev *dev,
3727 struct mlx5_translated_action_handle *handle,
3730 struct mlx5_translated_action_handle *handle_end;
3731 struct mlx5_priv *priv = dev->data->dev_private;
3732 struct mlx5_shared_action_rss *shared_rss;
3735 for (handle_end = handle + shared_n; handle < handle_end; handle++) {
3736 uint32_t act_idx = (uint32_t)(uintptr_t)handle->action;
3737 uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
3738 uint32_t idx = act_idx &
3739 ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
3741 case MLX5_INDIRECT_ACTION_TYPE_RSS:
3742 shared_rss = mlx5_ipool_get
3743 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
3745 __atomic_add_fetch(&shared_rss->refcnt, 1,
3756 find_graph_root(const struct rte_flow_item pattern[], uint32_t rss_level)
3758 const struct rte_flow_item *item;
3759 unsigned int has_vlan = 0;
3761 for (item = pattern; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
3762 if (item->type == RTE_FLOW_ITEM_TYPE_VLAN) {
3768 return rss_level < 2 ? MLX5_EXPANSION_ROOT_ETH_VLAN :
3769 MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN;
3770 return rss_level < 2 ? MLX5_EXPANSION_ROOT :
3771 MLX5_EXPANSION_ROOT_OUTER;
3775 * Get layer flags from the prefix flow.
3777 * Some flows may be split to several subflows, the prefix subflow gets the
3778 * match items and the suffix sub flow gets the actions.
3779 * Some actions need the user defined match item flags to get the detail for
3781 * This function helps the suffix flow to get the item layer flags from prefix
3784 * @param[in] dev_flow
3785 * Pointer the created preifx subflow.
3788 * The layers get from prefix subflow.
3790 static inline uint64_t
3791 flow_get_prefix_layer_flags(struct mlx5_flow *dev_flow)
3793 uint64_t layers = 0;
3796 * Layers bits could be localization, but usually the compiler will
3797 * help to do the optimization work for source code.
3798 * If no decap actions, use the layers directly.
3800 if (!(dev_flow->act_flags & MLX5_FLOW_ACTION_DECAP))
3801 return dev_flow->handle->layers;
3802 /* Convert L3 layers with decap action. */
3803 if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L3_IPV4)
3804 layers |= MLX5_FLOW_LAYER_OUTER_L3_IPV4;
3805 else if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L3_IPV6)
3806 layers |= MLX5_FLOW_LAYER_OUTER_L3_IPV6;
3807 /* Convert L4 layers with decap action. */
3808 if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L4_TCP)
3809 layers |= MLX5_FLOW_LAYER_OUTER_L4_TCP;
3810 else if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L4_UDP)
3811 layers |= MLX5_FLOW_LAYER_OUTER_L4_UDP;
3816 * Get metadata split action information.
3818 * @param[in] actions
3819 * Pointer to the list of actions.
3821 * Pointer to the return pointer.
3822 * @param[out] qrss_type
3823 * Pointer to the action type to return. RTE_FLOW_ACTION_TYPE_END is returned
3824 * if no QUEUE/RSS is found.
3825 * @param[out] encap_idx
3826 * Pointer to the index of the encap action if exists, otherwise the last
3830 * Total number of actions.
3833 flow_parse_metadata_split_actions_info(const struct rte_flow_action actions[],
3834 const struct rte_flow_action **qrss,
3837 const struct rte_flow_action_raw_encap *raw_encap;
3839 int raw_decap_idx = -1;
3842 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3843 switch (actions->type) {
3844 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
3845 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
3846 *encap_idx = actions_n;
3848 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
3849 raw_decap_idx = actions_n;
3851 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
3852 raw_encap = actions->conf;
3853 if (raw_encap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
3854 *encap_idx = raw_decap_idx != -1 ?
3855 raw_decap_idx : actions_n;
3857 case RTE_FLOW_ACTION_TYPE_QUEUE:
3858 case RTE_FLOW_ACTION_TYPE_RSS:
3866 if (*encap_idx == -1)
3867 *encap_idx = actions_n;
3868 /* Count RTE_FLOW_ACTION_TYPE_END. */
3869 return actions_n + 1;
3873 * Check if the action will change packet.
3876 * Pointer to Ethernet device.
3881 * true if action will change packet, false otherwise.
3883 static bool flow_check_modify_action_type(struct rte_eth_dev *dev,
3884 enum rte_flow_action_type type)
3886 struct mlx5_priv *priv = dev->data->dev_private;
3889 case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
3890 case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
3891 case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
3892 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
3893 case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
3894 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
3895 case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
3896 case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
3897 case RTE_FLOW_ACTION_TYPE_DEC_TTL:
3898 case RTE_FLOW_ACTION_TYPE_SET_TTL:
3899 case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
3900 case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
3901 case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
3902 case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
3903 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
3904 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
3905 case RTE_FLOW_ACTION_TYPE_SET_META:
3906 case RTE_FLOW_ACTION_TYPE_SET_TAG:
3907 case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
3908 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
3909 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
3910 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
3911 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
3912 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
3913 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
3914 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
3915 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
3916 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
3917 case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
3919 case RTE_FLOW_ACTION_TYPE_FLAG:
3920 case RTE_FLOW_ACTION_TYPE_MARK:
3921 if (priv->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY)
3931 * Check meter action from the action list.
3934 * Pointer to Ethernet device.
3935 * @param[in] actions
3936 * Pointer to the list of actions.
3937 * @param[out] has_mtr
3938 * Pointer to the meter exist flag.
3939 * @param[out] has_modify
3940 * Pointer to the flag showing there's packet change action.
3941 * @param[out] meter_id
3942 * Pointer to the meter id.
3945 * Total number of actions.
3948 flow_check_meter_action(struct rte_eth_dev *dev,
3949 const struct rte_flow_action actions[],
3950 bool *has_mtr, bool *has_modify, uint32_t *meter_id)
3952 const struct rte_flow_action_meter *mtr = NULL;
3955 MLX5_ASSERT(has_mtr);
3957 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3958 switch (actions->type) {
3959 case RTE_FLOW_ACTION_TYPE_METER:
3960 mtr = actions->conf;
3961 *meter_id = mtr->mtr_id;
3968 *has_modify |= flow_check_modify_action_type(dev,
3972 /* Count RTE_FLOW_ACTION_TYPE_END. */
3973 return actions_n + 1;
3977 * Check if the flow should be split due to hairpin.
3978 * The reason for the split is that in current HW we can't
3979 * support encap and push-vlan on Rx, so if a flow contains
3980 * these actions we move it to Tx.
3983 * Pointer to Ethernet device.
3985 * Flow rule attributes.
3986 * @param[in] actions
3987 * Associated actions (list terminated by the END action).
3990 * > 0 the number of actions and the flow should be split,
3991 * 0 when no split required.
3994 flow_check_hairpin_split(struct rte_eth_dev *dev,
3995 const struct rte_flow_attr *attr,
3996 const struct rte_flow_action actions[])
3998 int queue_action = 0;
4001 const struct rte_flow_action_queue *queue;
4002 const struct rte_flow_action_rss *rss;
4003 const struct rte_flow_action_raw_encap *raw_encap;
4004 const struct rte_eth_hairpin_conf *conf;
4008 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4009 switch (actions->type) {
4010 case RTE_FLOW_ACTION_TYPE_QUEUE:
4011 queue = actions->conf;
4014 conf = mlx5_rxq_get_hairpin_conf(dev, queue->index);
4015 if (conf == NULL || conf->tx_explicit != 0)
4020 case RTE_FLOW_ACTION_TYPE_RSS:
4021 rss = actions->conf;
4022 if (rss == NULL || rss->queue_num == 0)
4024 conf = mlx5_rxq_get_hairpin_conf(dev, rss->queue[0]);
4025 if (conf == NULL || conf->tx_explicit != 0)
4030 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
4031 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
4032 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
4033 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
4034 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
4038 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
4039 raw_encap = actions->conf;
4040 if (raw_encap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
4049 if (split && queue_action)
4054 /* Declare flow create/destroy prototype in advance. */
4056 flow_list_create(struct rte_eth_dev *dev, enum mlx5_flow_type type,
4057 const struct rte_flow_attr *attr,
4058 const struct rte_flow_item items[],
4059 const struct rte_flow_action actions[],
4060 bool external, struct rte_flow_error *error);
4063 flow_list_destroy(struct rte_eth_dev *dev, enum mlx5_flow_type type,
4067 flow_dv_mreg_match_cb(void *tool_ctx __rte_unused,
4068 struct mlx5_list_entry *entry, void *cb_ctx)
4070 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4071 struct mlx5_flow_mreg_copy_resource *mcp_res =
4072 container_of(entry, typeof(*mcp_res), hlist_ent);
4074 return mcp_res->mark_id != *(uint32_t *)(ctx->data);
4077 struct mlx5_list_entry *
4078 flow_dv_mreg_create_cb(void *tool_ctx, void *cb_ctx)
4080 struct rte_eth_dev *dev = tool_ctx;
4081 struct mlx5_priv *priv = dev->data->dev_private;
4082 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4083 struct mlx5_flow_mreg_copy_resource *mcp_res;
4084 struct rte_flow_error *error = ctx->error;
4087 uint32_t mark_id = *(uint32_t *)(ctx->data);
4088 struct rte_flow_attr attr = {
4089 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
4092 struct mlx5_rte_flow_item_tag tag_spec = {
4095 struct rte_flow_item items[] = {
4096 [1] = { .type = RTE_FLOW_ITEM_TYPE_END, },
4098 struct rte_flow_action_mark ftag = {
4101 struct mlx5_flow_action_copy_mreg cp_mreg = {
4105 struct rte_flow_action_jump jump = {
4106 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
4108 struct rte_flow_action actions[] = {
4109 [3] = { .type = RTE_FLOW_ACTION_TYPE_END, },
4112 /* Fill the register fileds in the flow. */
4113 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
4117 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_RX, 0, error);
4121 /* Provide the full width of FLAG specific value. */
4122 if (mark_id == (priv->sh->dv_regc0_mask & MLX5_FLOW_MARK_DEFAULT))
4123 tag_spec.data = MLX5_FLOW_MARK_DEFAULT;
4124 /* Build a new flow. */
4125 if (mark_id != MLX5_DEFAULT_COPY_ID) {
4126 items[0] = (struct rte_flow_item){
4127 .type = (enum rte_flow_item_type)
4128 MLX5_RTE_FLOW_ITEM_TYPE_TAG,
4131 items[1] = (struct rte_flow_item){
4132 .type = RTE_FLOW_ITEM_TYPE_END,
4134 actions[0] = (struct rte_flow_action){
4135 .type = (enum rte_flow_action_type)
4136 MLX5_RTE_FLOW_ACTION_TYPE_MARK,
4139 actions[1] = (struct rte_flow_action){
4140 .type = (enum rte_flow_action_type)
4141 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
4144 actions[2] = (struct rte_flow_action){
4145 .type = RTE_FLOW_ACTION_TYPE_JUMP,
4148 actions[3] = (struct rte_flow_action){
4149 .type = RTE_FLOW_ACTION_TYPE_END,
4152 /* Default rule, wildcard match. */
4153 attr.priority = MLX5_FLOW_LOWEST_PRIO_INDICATOR;
4154 items[0] = (struct rte_flow_item){
4155 .type = RTE_FLOW_ITEM_TYPE_END,
4157 actions[0] = (struct rte_flow_action){
4158 .type = (enum rte_flow_action_type)
4159 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
4162 actions[1] = (struct rte_flow_action){
4163 .type = RTE_FLOW_ACTION_TYPE_JUMP,
4166 actions[2] = (struct rte_flow_action){
4167 .type = RTE_FLOW_ACTION_TYPE_END,
4170 /* Build a new entry. */
4171 mcp_res = mlx5_ipool_zmalloc(priv->sh->ipool[MLX5_IPOOL_MCP], &idx);
4177 mcp_res->mark_id = mark_id;
4179 * The copy Flows are not included in any list. There
4180 * ones are referenced from other Flows and can not
4181 * be applied, removed, deleted in ardbitrary order
4182 * by list traversing.
4184 mcp_res->rix_flow = flow_list_create(dev, MLX5_FLOW_TYPE_MCP,
4185 &attr, items, actions, false, error);
4186 if (!mcp_res->rix_flow) {
4187 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], idx);
4190 return &mcp_res->hlist_ent;
4193 struct mlx5_list_entry *
4194 flow_dv_mreg_clone_cb(void *tool_ctx, struct mlx5_list_entry *oentry,
4195 void *cb_ctx __rte_unused)
4197 struct rte_eth_dev *dev = tool_ctx;
4198 struct mlx5_priv *priv = dev->data->dev_private;
4199 struct mlx5_flow_mreg_copy_resource *mcp_res;
4202 mcp_res = mlx5_ipool_malloc(priv->sh->ipool[MLX5_IPOOL_MCP], &idx);
4207 memcpy(mcp_res, oentry, sizeof(*mcp_res));
4209 return &mcp_res->hlist_ent;
4213 flow_dv_mreg_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
4215 struct mlx5_flow_mreg_copy_resource *mcp_res =
4216 container_of(entry, typeof(*mcp_res), hlist_ent);
4217 struct rte_eth_dev *dev = tool_ctx;
4218 struct mlx5_priv *priv = dev->data->dev_private;
4220 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], mcp_res->idx);
4224 * Add a flow of copying flow metadata registers in RX_CP_TBL.
4226 * As mark_id is unique, if there's already a registered flow for the mark_id,
4227 * return by increasing the reference counter of the resource. Otherwise, create
4228 * the resource (mcp_res) and flow.
4231 * - If ingress port is ANY and reg_c[1] is mark_id,
4232 * flow_tag := mark_id, reg_b := reg_c[0] and jump to RX_ACT_TBL.
4234 * For default flow (zero mark_id), flow is like,
4235 * - If ingress port is ANY,
4236 * reg_b := reg_c[0] and jump to RX_ACT_TBL.
4239 * Pointer to Ethernet device.
4241 * ID of MARK action, zero means default flow for META.
4243 * Perform verbose error reporting if not NULL.
4246 * Associated resource on success, NULL otherwise and rte_errno is set.
4248 static struct mlx5_flow_mreg_copy_resource *
4249 flow_mreg_add_copy_action(struct rte_eth_dev *dev, uint32_t mark_id,
4250 struct rte_flow_error *error)
4252 struct mlx5_priv *priv = dev->data->dev_private;
4253 struct mlx5_list_entry *entry;
4254 struct mlx5_flow_cb_ctx ctx = {
4260 /* Check if already registered. */
4261 MLX5_ASSERT(priv->mreg_cp_tbl);
4262 entry = mlx5_hlist_register(priv->mreg_cp_tbl, mark_id, &ctx);
4265 return container_of(entry, struct mlx5_flow_mreg_copy_resource,
4270 flow_dv_mreg_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
4272 struct mlx5_flow_mreg_copy_resource *mcp_res =
4273 container_of(entry, typeof(*mcp_res), hlist_ent);
4274 struct rte_eth_dev *dev = tool_ctx;
4275 struct mlx5_priv *priv = dev->data->dev_private;
4277 MLX5_ASSERT(mcp_res->rix_flow);
4278 flow_list_destroy(dev, MLX5_FLOW_TYPE_MCP, mcp_res->rix_flow);
4279 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], mcp_res->idx);
4283 * Release flow in RX_CP_TBL.
4286 * Pointer to Ethernet device.
4288 * Parent flow for wich copying is provided.
4291 flow_mreg_del_copy_action(struct rte_eth_dev *dev,
4292 struct rte_flow *flow)
4294 struct mlx5_flow_mreg_copy_resource *mcp_res;
4295 struct mlx5_priv *priv = dev->data->dev_private;
4297 if (!flow->rix_mreg_copy)
4299 mcp_res = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MCP],
4300 flow->rix_mreg_copy);
4301 if (!mcp_res || !priv->mreg_cp_tbl)
4303 MLX5_ASSERT(mcp_res->rix_flow);
4304 mlx5_hlist_unregister(priv->mreg_cp_tbl, &mcp_res->hlist_ent);
4305 flow->rix_mreg_copy = 0;
4309 * Remove the default copy action from RX_CP_TBL.
4311 * This functions is called in the mlx5_dev_start(). No thread safe
4315 * Pointer to Ethernet device.
4318 flow_mreg_del_default_copy_action(struct rte_eth_dev *dev)
4320 struct mlx5_list_entry *entry;
4321 struct mlx5_priv *priv = dev->data->dev_private;
4322 struct mlx5_flow_cb_ctx ctx;
4325 /* Check if default flow is registered. */
4326 if (!priv->mreg_cp_tbl)
4328 mark_id = MLX5_DEFAULT_COPY_ID;
4329 ctx.data = &mark_id;
4330 entry = mlx5_hlist_lookup(priv->mreg_cp_tbl, mark_id, &ctx);
4333 mlx5_hlist_unregister(priv->mreg_cp_tbl, entry);
4337 * Add the default copy action in in RX_CP_TBL.
4339 * This functions is called in the mlx5_dev_start(). No thread safe
4343 * Pointer to Ethernet device.
4345 * Perform verbose error reporting if not NULL.
4348 * 0 for success, negative value otherwise and rte_errno is set.
4351 flow_mreg_add_default_copy_action(struct rte_eth_dev *dev,
4352 struct rte_flow_error *error)
4354 struct mlx5_priv *priv = dev->data->dev_private;
4355 struct mlx5_flow_mreg_copy_resource *mcp_res;
4356 struct mlx5_flow_cb_ctx ctx;
4359 /* Check whether extensive metadata feature is engaged. */
4360 if (!priv->config.dv_flow_en ||
4361 priv->config.dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
4362 !mlx5_flow_ext_mreg_supported(dev) ||
4363 !priv->sh->dv_regc0_mask)
4366 * Add default mreg copy flow may be called multiple time, but
4367 * only be called once in stop. Avoid register it twice.
4369 mark_id = MLX5_DEFAULT_COPY_ID;
4370 ctx.data = &mark_id;
4371 if (mlx5_hlist_lookup(priv->mreg_cp_tbl, mark_id, &ctx))
4373 mcp_res = flow_mreg_add_copy_action(dev, mark_id, error);
4380 * Add a flow of copying flow metadata registers in RX_CP_TBL.
4382 * All the flow having Q/RSS action should be split by
4383 * flow_mreg_split_qrss_prep() to pass by RX_CP_TBL. A flow in the RX_CP_TBL
4384 * performs the following,
4385 * - CQE->flow_tag := reg_c[1] (MARK)
4386 * - CQE->flow_table_metadata (reg_b) := reg_c[0] (META)
4387 * As CQE's flow_tag is not a register, it can't be simply copied from reg_c[1]
4388 * but there should be a flow per each MARK ID set by MARK action.
4390 * For the aforementioned reason, if there's a MARK action in flow's action
4391 * list, a corresponding flow should be added to the RX_CP_TBL in order to copy
4392 * the MARK ID to CQE's flow_tag like,
4393 * - If reg_c[1] is mark_id,
4394 * flow_tag := mark_id, reg_b := reg_c[0] and jump to RX_ACT_TBL.
4396 * For SET_META action which stores value in reg_c[0], as the destination is
4397 * also a flow metadata register (reg_b), adding a default flow is enough. Zero
4398 * MARK ID means the default flow. The default flow looks like,
4399 * - For all flow, reg_b := reg_c[0] and jump to RX_ACT_TBL.
4402 * Pointer to Ethernet device.
4404 * Pointer to flow structure.
4405 * @param[in] actions
4406 * Pointer to the list of actions.
4408 * Perform verbose error reporting if not NULL.
4411 * 0 on success, negative value otherwise and rte_errno is set.
4414 flow_mreg_update_copy_table(struct rte_eth_dev *dev,
4415 struct rte_flow *flow,
4416 const struct rte_flow_action *actions,
4417 struct rte_flow_error *error)
4419 struct mlx5_priv *priv = dev->data->dev_private;
4420 struct mlx5_dev_config *config = &priv->config;
4421 struct mlx5_flow_mreg_copy_resource *mcp_res;
4422 const struct rte_flow_action_mark *mark;
4424 /* Check whether extensive metadata feature is engaged. */
4425 if (!config->dv_flow_en ||
4426 config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
4427 !mlx5_flow_ext_mreg_supported(dev) ||
4428 !priv->sh->dv_regc0_mask)
4430 /* Find MARK action. */
4431 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4432 switch (actions->type) {
4433 case RTE_FLOW_ACTION_TYPE_FLAG:
4434 mcp_res = flow_mreg_add_copy_action
4435 (dev, MLX5_FLOW_MARK_DEFAULT, error);
4438 flow->rix_mreg_copy = mcp_res->idx;
4440 case RTE_FLOW_ACTION_TYPE_MARK:
4441 mark = (const struct rte_flow_action_mark *)
4444 flow_mreg_add_copy_action(dev, mark->id, error);
4447 flow->rix_mreg_copy = mcp_res->idx;
4456 #define MLX5_MAX_SPLIT_ACTIONS 24
4457 #define MLX5_MAX_SPLIT_ITEMS 24
4460 * Split the hairpin flow.
4461 * Since HW can't support encap and push-vlan on Rx, we move these
4463 * If the count action is after the encap then we also
4464 * move the count action. in this case the count will also measure
4468 * Pointer to Ethernet device.
4469 * @param[in] actions
4470 * Associated actions (list terminated by the END action).
4471 * @param[out] actions_rx
4473 * @param[out] actions_tx
4475 * @param[out] pattern_tx
4476 * The pattern items for the Tx flow.
4477 * @param[out] flow_id
4478 * The flow ID connected to this flow.
4484 flow_hairpin_split(struct rte_eth_dev *dev,
4485 const struct rte_flow_action actions[],
4486 struct rte_flow_action actions_rx[],
4487 struct rte_flow_action actions_tx[],
4488 struct rte_flow_item pattern_tx[],
4491 const struct rte_flow_action_raw_encap *raw_encap;
4492 const struct rte_flow_action_raw_decap *raw_decap;
4493 struct mlx5_rte_flow_action_set_tag *set_tag;
4494 struct rte_flow_action *tag_action;
4495 struct mlx5_rte_flow_item_tag *tag_item;
4496 struct rte_flow_item *item;
4500 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4501 switch (actions->type) {
4502 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
4503 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
4504 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
4505 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
4506 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
4507 rte_memcpy(actions_tx, actions,
4508 sizeof(struct rte_flow_action));
4511 case RTE_FLOW_ACTION_TYPE_COUNT:
4513 rte_memcpy(actions_tx, actions,
4514 sizeof(struct rte_flow_action));
4517 rte_memcpy(actions_rx, actions,
4518 sizeof(struct rte_flow_action));
4522 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
4523 raw_encap = actions->conf;
4524 if (raw_encap->size > MLX5_ENCAPSULATION_DECISION_SIZE) {
4525 memcpy(actions_tx, actions,
4526 sizeof(struct rte_flow_action));
4530 rte_memcpy(actions_rx, actions,
4531 sizeof(struct rte_flow_action));
4535 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
4536 raw_decap = actions->conf;
4537 if (raw_decap->size < MLX5_ENCAPSULATION_DECISION_SIZE) {
4538 memcpy(actions_tx, actions,
4539 sizeof(struct rte_flow_action));
4542 rte_memcpy(actions_rx, actions,
4543 sizeof(struct rte_flow_action));
4548 rte_memcpy(actions_rx, actions,
4549 sizeof(struct rte_flow_action));
4554 /* Add set meta action and end action for the Rx flow. */
4555 tag_action = actions_rx;
4556 tag_action->type = (enum rte_flow_action_type)
4557 MLX5_RTE_FLOW_ACTION_TYPE_TAG;
4559 rte_memcpy(actions_rx, actions, sizeof(struct rte_flow_action));
4561 set_tag = (void *)actions_rx;
4562 *set_tag = (struct mlx5_rte_flow_action_set_tag) {
4563 .id = mlx5_flow_get_reg_id(dev, MLX5_HAIRPIN_RX, 0, NULL),
4566 MLX5_ASSERT(set_tag->id > REG_NON);
4567 tag_action->conf = set_tag;
4568 /* Create Tx item list. */
4569 rte_memcpy(actions_tx, actions, sizeof(struct rte_flow_action));
4570 addr = (void *)&pattern_tx[2];
4572 item->type = (enum rte_flow_item_type)
4573 MLX5_RTE_FLOW_ITEM_TYPE_TAG;
4574 tag_item = (void *)addr;
4575 tag_item->data = flow_id;
4576 tag_item->id = mlx5_flow_get_reg_id(dev, MLX5_HAIRPIN_TX, 0, NULL);
4577 MLX5_ASSERT(set_tag->id > REG_NON);
4578 item->spec = tag_item;
4579 addr += sizeof(struct mlx5_rte_flow_item_tag);
4580 tag_item = (void *)addr;
4581 tag_item->data = UINT32_MAX;
4582 tag_item->id = UINT16_MAX;
4583 item->mask = tag_item;
4586 item->type = RTE_FLOW_ITEM_TYPE_END;
4591 * The last stage of splitting chain, just creates the subflow
4592 * without any modification.
4595 * Pointer to Ethernet device.
4597 * Parent flow structure pointer.
4598 * @param[in, out] sub_flow
4599 * Pointer to return the created subflow, may be NULL.
4601 * Flow rule attributes.
4603 * Pattern specification (list terminated by the END pattern item).
4604 * @param[in] actions
4605 * Associated actions (list terminated by the END action).
4606 * @param[in] flow_split_info
4607 * Pointer to flow split info structure.
4609 * Perform verbose error reporting if not NULL.
4611 * 0 on success, negative value otherwise
4614 flow_create_split_inner(struct rte_eth_dev *dev,
4615 struct rte_flow *flow,
4616 struct mlx5_flow **sub_flow,
4617 const struct rte_flow_attr *attr,
4618 const struct rte_flow_item items[],
4619 const struct rte_flow_action actions[],
4620 struct mlx5_flow_split_info *flow_split_info,
4621 struct rte_flow_error *error)
4623 struct mlx5_flow *dev_flow;
4625 dev_flow = flow_drv_prepare(dev, flow, attr, items, actions,
4626 flow_split_info->flow_idx, error);
4629 dev_flow->flow = flow;
4630 dev_flow->external = flow_split_info->external;
4631 dev_flow->skip_scale = flow_split_info->skip_scale;
4632 /* Subflow object was created, we must include one in the list. */
4633 SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
4634 dev_flow->handle, next);
4636 * If dev_flow is as one of the suffix flow, some actions in suffix
4637 * flow may need some user defined item layer flags, and pass the
4638 * Metadate rxq mark flag to suffix flow as well.
4640 if (flow_split_info->prefix_layers)
4641 dev_flow->handle->layers = flow_split_info->prefix_layers;
4642 if (flow_split_info->prefix_mark)
4643 dev_flow->handle->mark = 1;
4645 *sub_flow = dev_flow;
4646 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
4647 dev_flow->dv.table_id = flow_split_info->table_id;
4649 return flow_drv_translate(dev, dev_flow, attr, items, actions, error);
4653 * Get the sub policy of a meter.
4656 * Pointer to Ethernet device.
4658 * Parent flow structure pointer.
4660 * Pointer to thread flow work space.
4662 * Flow rule attributes.
4664 * Pattern specification (list terminated by the END pattern item).
4666 * Perform verbose error reporting if not NULL.
4669 * Pointer to the meter sub policy, NULL otherwise and rte_errno is set.
4671 static struct mlx5_flow_meter_sub_policy *
4672 get_meter_sub_policy(struct rte_eth_dev *dev,
4673 struct rte_flow *flow,
4674 struct mlx5_flow_workspace *wks,
4675 const struct rte_flow_attr *attr,
4676 const struct rte_flow_item items[],
4677 struct rte_flow_error *error)
4679 struct mlx5_flow_meter_policy *policy;
4680 struct mlx5_flow_meter_policy *final_policy;
4681 struct mlx5_flow_meter_sub_policy *sub_policy = NULL;
4683 policy = wks->policy;
4684 final_policy = policy->is_hierarchy ? wks->final_policy : policy;
4685 if (final_policy->is_rss || final_policy->is_queue) {
4686 struct mlx5_flow_rss_desc rss_desc_v[MLX5_MTR_RTE_COLORS];
4687 struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS] = {0};
4691 * This is a tmp dev_flow,
4692 * no need to register any matcher for it in translate.
4694 wks->skip_matcher_reg = 1;
4695 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
4696 struct mlx5_flow dev_flow = {0};
4697 struct mlx5_flow_handle dev_handle = { {0} };
4698 uint8_t fate = final_policy->act_cnt[i].fate_action;
4700 if (fate == MLX5_FLOW_FATE_SHARED_RSS) {
4701 const void *rss_act =
4702 final_policy->act_cnt[i].rss->conf;
4703 struct rte_flow_action rss_actions[2] = {
4705 .type = RTE_FLOW_ACTION_TYPE_RSS,
4709 .type = RTE_FLOW_ACTION_TYPE_END,
4714 dev_flow.handle = &dev_handle;
4715 dev_flow.ingress = attr->ingress;
4716 dev_flow.flow = flow;
4717 dev_flow.external = 0;
4718 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
4719 dev_flow.dv.transfer = attr->transfer;
4722 * Translate RSS action to get rss hash fields.
4724 if (flow_drv_translate(dev, &dev_flow, attr,
4725 items, rss_actions, error))
4727 rss_desc_v[i] = wks->rss_desc;
4728 rss_desc_v[i].key_len = MLX5_RSS_HASH_KEY_LEN;
4729 rss_desc_v[i].hash_fields =
4730 dev_flow.hash_fields;
4731 rss_desc_v[i].queue_num =
4732 rss_desc_v[i].hash_fields ?
4733 rss_desc_v[i].queue_num : 1;
4734 rss_desc_v[i].tunnel =
4735 !!(dev_flow.handle->layers &
4736 MLX5_FLOW_LAYER_TUNNEL);
4737 rss_desc[i] = &rss_desc_v[i];
4738 } else if (fate == MLX5_FLOW_FATE_QUEUE) {
4739 /* This is queue action. */
4740 rss_desc_v[i] = wks->rss_desc;
4741 rss_desc_v[i].key_len = 0;
4742 rss_desc_v[i].hash_fields = 0;
4743 rss_desc_v[i].queue =
4744 &final_policy->act_cnt[i].queue;
4745 rss_desc_v[i].queue_num = 1;
4746 rss_desc[i] = &rss_desc_v[i];
4751 sub_policy = flow_drv_meter_sub_policy_rss_prepare(dev,
4752 flow, policy, rss_desc);
4754 enum mlx5_meter_domain mtr_domain =
4755 attr->transfer ? MLX5_MTR_DOMAIN_TRANSFER :
4756 (attr->egress ? MLX5_MTR_DOMAIN_EGRESS :
4757 MLX5_MTR_DOMAIN_INGRESS);
4758 sub_policy = policy->sub_policys[mtr_domain][0];
4761 rte_flow_error_set(error, EINVAL,
4762 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4763 "Failed to get meter sub-policy.");
4769 * Split the meter flow.
4771 * As meter flow will split to three sub flow, other than meter
4772 * action, the other actions make sense to only meter accepts
4773 * the packet. If it need to be dropped, no other additional
4774 * actions should be take.
4776 * One kind of special action which decapsulates the L3 tunnel
4777 * header will be in the prefix sub flow, as not to take the
4778 * L3 tunnel header into account.
4781 * Pointer to Ethernet device.
4783 * Parent flow structure pointer.
4785 * Pointer to thread flow work space.
4787 * Flow rule attributes.
4789 * Pattern specification (list terminated by the END pattern item).
4790 * @param[out] sfx_items
4791 * Suffix flow match items (list terminated by the END pattern item).
4792 * @param[in] actions
4793 * Associated actions (list terminated by the END action).
4794 * @param[out] actions_sfx
4795 * Suffix flow actions.
4796 * @param[out] actions_pre
4797 * Prefix flow actions.
4798 * @param[out] mtr_flow_id
4799 * Pointer to meter flow id.
4801 * Perform verbose error reporting if not NULL.
4804 * 0 on success, a negative errno value otherwise and rte_errno is set.
4807 flow_meter_split_prep(struct rte_eth_dev *dev,
4808 struct rte_flow *flow,
4809 struct mlx5_flow_workspace *wks,
4810 const struct rte_flow_attr *attr,
4811 const struct rte_flow_item items[],
4812 struct rte_flow_item sfx_items[],
4813 const struct rte_flow_action actions[],
4814 struct rte_flow_action actions_sfx[],
4815 struct rte_flow_action actions_pre[],
4816 uint32_t *mtr_flow_id,
4817 struct rte_flow_error *error)
4819 struct mlx5_priv *priv = dev->data->dev_private;
4820 struct mlx5_flow_meter_info *fm = wks->fm;
4821 struct rte_flow_action *tag_action = NULL;
4822 struct rte_flow_item *tag_item;
4823 struct mlx5_rte_flow_action_set_tag *set_tag;
4824 const struct rte_flow_action_raw_encap *raw_encap;
4825 const struct rte_flow_action_raw_decap *raw_decap;
4826 struct mlx5_rte_flow_item_tag *tag_item_spec;
4827 struct mlx5_rte_flow_item_tag *tag_item_mask;
4828 uint32_t tag_id = 0;
4829 struct rte_flow_item *vlan_item_dst = NULL;
4830 const struct rte_flow_item *vlan_item_src = NULL;
4831 struct rte_flow_action *hw_mtr_action;
4832 struct rte_flow_action *action_pre_head = NULL;
4833 int32_t flow_src_port = priv->representor_id;
4835 uint8_t mtr_id_offset = priv->mtr_reg_share ? MLX5_MTR_COLOR_BITS : 0;
4836 uint8_t mtr_reg_bits = priv->mtr_reg_share ?
4837 MLX5_MTR_IDLE_BITS_IN_COLOR_REG : MLX5_REG_BITS;
4838 uint32_t flow_id = 0;
4839 uint32_t flow_id_reversed = 0;
4840 uint8_t flow_id_bits = 0;
4843 /* Prepare the suffix subflow items. */
4844 tag_item = sfx_items++;
4845 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
4846 struct mlx5_priv *port_priv;
4847 const struct rte_flow_item_port_id *pid_v;
4848 int item_type = items->type;
4850 switch (item_type) {
4851 case RTE_FLOW_ITEM_TYPE_PORT_ID:
4852 pid_v = items->spec;
4854 port_priv = mlx5_port_to_eswitch_info(pid_v->id, false);
4856 return rte_flow_error_set(error,
4858 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
4860 "Failed to get port info.");
4861 flow_src_port = port_priv->representor_id;
4862 if (!fm->def_policy && wks->policy->is_hierarchy &&
4863 flow_src_port != priv->representor_id) {
4864 if (flow_drv_mtr_hierarchy_rule_create(dev,
4871 memcpy(sfx_items, items, sizeof(*sfx_items));
4874 case RTE_FLOW_ITEM_TYPE_VLAN:
4875 /* Determine if copy vlan item below. */
4876 vlan_item_src = items;
4877 vlan_item_dst = sfx_items++;
4878 vlan_item_dst->type = RTE_FLOW_ITEM_TYPE_VOID;
4884 sfx_items->type = RTE_FLOW_ITEM_TYPE_END;
4886 mtr_first = priv->sh->meter_aso_en &&
4887 (attr->egress || (attr->transfer && flow_src_port != UINT16_MAX));
4888 /* For ASO meter, meter must be before tag in TX direction. */
4890 action_pre_head = actions_pre++;
4891 /* Leave space for tag action. */
4892 tag_action = actions_pre++;
4894 /* Prepare the actions for prefix and suffix flow. */
4895 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4896 struct rte_flow_action *action_cur = NULL;
4898 switch (actions->type) {
4899 case RTE_FLOW_ACTION_TYPE_METER:
4901 action_cur = action_pre_head;
4903 /* Leave space for tag action. */
4904 tag_action = actions_pre++;
4905 action_cur = actions_pre++;
4908 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
4909 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
4910 action_cur = actions_pre++;
4912 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
4913 raw_encap = actions->conf;
4914 if (raw_encap->size < MLX5_ENCAPSULATION_DECISION_SIZE)
4915 action_cur = actions_pre++;
4917 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
4918 raw_decap = actions->conf;
4919 if (raw_decap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
4920 action_cur = actions_pre++;
4922 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
4923 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
4924 if (vlan_item_dst && vlan_item_src) {
4925 memcpy(vlan_item_dst, vlan_item_src,
4926 sizeof(*vlan_item_dst));
4928 * Convert to internal match item, it is used
4929 * for vlan push and set vid.
4931 vlan_item_dst->type = (enum rte_flow_item_type)
4932 MLX5_RTE_FLOW_ITEM_TYPE_VLAN;
4939 action_cur = (fm->def_policy) ?
4940 actions_sfx++ : actions_pre++;
4941 memcpy(action_cur, actions, sizeof(struct rte_flow_action));
4943 /* Add end action to the actions. */
4944 actions_sfx->type = RTE_FLOW_ACTION_TYPE_END;
4945 if (priv->sh->meter_aso_en) {
4947 * For ASO meter, need to add an extra jump action explicitly,
4948 * to jump from meter to policer table.
4950 struct mlx5_flow_meter_sub_policy *sub_policy;
4951 struct mlx5_flow_tbl_data_entry *tbl_data;
4953 if (!fm->def_policy) {
4954 sub_policy = get_meter_sub_policy(dev, flow, wks,
4955 attr, items, error);
4959 enum mlx5_meter_domain mtr_domain =
4960 attr->transfer ? MLX5_MTR_DOMAIN_TRANSFER :
4961 (attr->egress ? MLX5_MTR_DOMAIN_EGRESS :
4962 MLX5_MTR_DOMAIN_INGRESS);
4965 &priv->sh->mtrmng->def_policy[mtr_domain]->sub_policy;
4967 tbl_data = container_of(sub_policy->tbl_rsc,
4968 struct mlx5_flow_tbl_data_entry, tbl);
4969 hw_mtr_action = actions_pre++;
4970 hw_mtr_action->type = (enum rte_flow_action_type)
4971 MLX5_RTE_FLOW_ACTION_TYPE_JUMP;
4972 hw_mtr_action->conf = tbl_data->jump.action;
4974 actions_pre->type = RTE_FLOW_ACTION_TYPE_END;
4977 return rte_flow_error_set(error, ENOMEM,
4978 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
4979 NULL, "No tag action space.");
4981 tag_action->type = RTE_FLOW_ACTION_TYPE_VOID;
4984 /* Only default-policy Meter creates mtr flow id. */
4985 if (fm->def_policy) {
4986 mlx5_ipool_malloc(fm->flow_ipool, &tag_id);
4988 return rte_flow_error_set(error, ENOMEM,
4989 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4990 "Failed to allocate meter flow id.");
4991 flow_id = tag_id - 1;
4992 flow_id_bits = (!flow_id) ? 1 :
4993 (MLX5_REG_BITS - __builtin_clz(flow_id));
4994 if ((flow_id_bits + priv->sh->mtrmng->max_mtr_bits) >
4996 mlx5_ipool_free(fm->flow_ipool, tag_id);
4997 return rte_flow_error_set(error, EINVAL,
4998 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4999 "Meter flow id exceeds max limit.");
5001 if (flow_id_bits > priv->sh->mtrmng->max_mtr_flow_bits)
5002 priv->sh->mtrmng->max_mtr_flow_bits = flow_id_bits;
5004 /* Build tag actions and items for meter_id/meter flow_id. */
5005 set_tag = (struct mlx5_rte_flow_action_set_tag *)actions_pre;
5006 tag_item_spec = (struct mlx5_rte_flow_item_tag *)sfx_items;
5007 tag_item_mask = tag_item_spec + 1;
5008 /* Both flow_id and meter_id share the same register. */
5009 *set_tag = (struct mlx5_rte_flow_action_set_tag) {
5010 .id = (enum modify_reg)mlx5_flow_get_reg_id(dev, MLX5_MTR_ID,
5012 .offset = mtr_id_offset,
5013 .length = mtr_reg_bits,
5014 .data = flow->meter,
5017 * The color Reg bits used by flow_id are growing from
5018 * msb to lsb, so must do bit reverse for flow_id val in RegC.
5020 for (shift = 0; shift < flow_id_bits; shift++)
5021 flow_id_reversed = (flow_id_reversed << 1) |
5022 ((flow_id >> shift) & 0x1);
5024 flow_id_reversed << (mtr_reg_bits - flow_id_bits);
5025 tag_item_spec->id = set_tag->id;
5026 tag_item_spec->data = set_tag->data << mtr_id_offset;
5027 tag_item_mask->data = UINT32_MAX << mtr_id_offset;
5028 tag_action->type = (enum rte_flow_action_type)
5029 MLX5_RTE_FLOW_ACTION_TYPE_TAG;
5030 tag_action->conf = set_tag;
5031 tag_item->type = (enum rte_flow_item_type)
5032 MLX5_RTE_FLOW_ITEM_TYPE_TAG;
5033 tag_item->spec = tag_item_spec;
5034 tag_item->last = NULL;
5035 tag_item->mask = tag_item_mask;
5038 *mtr_flow_id = tag_id;
5043 * Split action list having QUEUE/RSS for metadata register copy.
5045 * Once Q/RSS action is detected in user's action list, the flow action
5046 * should be split in order to copy metadata registers, which will happen in
5048 * - CQE->flow_tag := reg_c[1] (MARK)
5049 * - CQE->flow_table_metadata (reg_b) := reg_c[0] (META)
5050 * The Q/RSS action will be performed on RX_ACT_TBL after passing by RX_CP_TBL.
5051 * This is because the last action of each flow must be a terminal action
5052 * (QUEUE, RSS or DROP).
5054 * Flow ID must be allocated to identify actions in the RX_ACT_TBL and it is
5055 * stored and kept in the mlx5_flow structure per each sub_flow.
5057 * The Q/RSS action is replaced with,
5058 * - SET_TAG, setting the allocated flow ID to reg_c[2].
5059 * And the following JUMP action is added at the end,
5060 * - JUMP, to RX_CP_TBL.
5062 * A flow to perform remained Q/RSS action will be created in RX_ACT_TBL by
5063 * flow_create_split_metadata() routine. The flow will look like,
5064 * - If flow ID matches (reg_c[2]), perform Q/RSS.
5067 * Pointer to Ethernet device.
5068 * @param[out] split_actions
5069 * Pointer to store split actions to jump to CP_TBL.
5070 * @param[in] actions
5071 * Pointer to the list of original flow actions.
5073 * Pointer to the Q/RSS action.
5074 * @param[in] actions_n
5075 * Number of original actions.
5077 * Perform verbose error reporting if not NULL.
5080 * non-zero unique flow_id on success, otherwise 0 and
5081 * error/rte_error are set.
5084 flow_mreg_split_qrss_prep(struct rte_eth_dev *dev,
5085 struct rte_flow_action *split_actions,
5086 const struct rte_flow_action *actions,
5087 const struct rte_flow_action *qrss,
5088 int actions_n, struct rte_flow_error *error)
5090 struct mlx5_priv *priv = dev->data->dev_private;
5091 struct mlx5_rte_flow_action_set_tag *set_tag;
5092 struct rte_flow_action_jump *jump;
5093 const int qrss_idx = qrss - actions;
5094 uint32_t flow_id = 0;
5098 * Given actions will be split
5099 * - Replace QUEUE/RSS action with SET_TAG to set flow ID.
5100 * - Add jump to mreg CP_TBL.
5101 * As a result, there will be one more action.
5104 memcpy(split_actions, actions, sizeof(*split_actions) * actions_n);
5105 set_tag = (void *)(split_actions + actions_n);
5107 * If tag action is not set to void(it means we are not the meter
5108 * suffix flow), add the tag action. Since meter suffix flow already
5109 * has the tag added.
5111 if (split_actions[qrss_idx].type != RTE_FLOW_ACTION_TYPE_VOID) {
5113 * Allocate the new subflow ID. This one is unique within
5114 * device and not shared with representors. Otherwise,
5115 * we would have to resolve multi-thread access synch
5116 * issue. Each flow on the shared device is appended
5117 * with source vport identifier, so the resulting
5118 * flows will be unique in the shared (by master and
5119 * representors) domain even if they have coinciding
5122 mlx5_ipool_malloc(priv->sh->ipool
5123 [MLX5_IPOOL_RSS_EXPANTION_FLOW_ID], &flow_id);
5125 return rte_flow_error_set(error, ENOMEM,
5126 RTE_FLOW_ERROR_TYPE_ACTION,
5127 NULL, "can't allocate id "
5128 "for split Q/RSS subflow");
5129 /* Internal SET_TAG action to set flow ID. */
5130 *set_tag = (struct mlx5_rte_flow_action_set_tag){
5133 ret = mlx5_flow_get_reg_id(dev, MLX5_COPY_MARK, 0, error);
5137 /* Construct new actions array. */
5138 /* Replace QUEUE/RSS action. */
5139 split_actions[qrss_idx] = (struct rte_flow_action){
5140 .type = (enum rte_flow_action_type)
5141 MLX5_RTE_FLOW_ACTION_TYPE_TAG,
5145 /* JUMP action to jump to mreg copy table (CP_TBL). */
5146 jump = (void *)(set_tag + 1);
5147 *jump = (struct rte_flow_action_jump){
5148 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
5150 split_actions[actions_n - 2] = (struct rte_flow_action){
5151 .type = RTE_FLOW_ACTION_TYPE_JUMP,
5154 split_actions[actions_n - 1] = (struct rte_flow_action){
5155 .type = RTE_FLOW_ACTION_TYPE_END,
5161 * Extend the given action list for Tx metadata copy.
5163 * Copy the given action list to the ext_actions and add flow metadata register
5164 * copy action in order to copy reg_a set by WQE to reg_c[0].
5166 * @param[out] ext_actions
5167 * Pointer to the extended action list.
5168 * @param[in] actions
5169 * Pointer to the list of actions.
5170 * @param[in] actions_n
5171 * Number of actions in the list.
5173 * Perform verbose error reporting if not NULL.
5174 * @param[in] encap_idx
5175 * The encap action inndex.
5178 * 0 on success, negative value otherwise
5181 flow_mreg_tx_copy_prep(struct rte_eth_dev *dev,
5182 struct rte_flow_action *ext_actions,
5183 const struct rte_flow_action *actions,
5184 int actions_n, struct rte_flow_error *error,
5187 struct mlx5_flow_action_copy_mreg *cp_mreg =
5188 (struct mlx5_flow_action_copy_mreg *)
5189 (ext_actions + actions_n + 1);
5192 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_RX, 0, error);
5196 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_TX, 0, error);
5201 memcpy(ext_actions, actions, sizeof(*ext_actions) * encap_idx);
5202 if (encap_idx == actions_n - 1) {
5203 ext_actions[actions_n - 1] = (struct rte_flow_action){
5204 .type = (enum rte_flow_action_type)
5205 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
5208 ext_actions[actions_n] = (struct rte_flow_action){
5209 .type = RTE_FLOW_ACTION_TYPE_END,
5212 ext_actions[encap_idx] = (struct rte_flow_action){
5213 .type = (enum rte_flow_action_type)
5214 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
5217 memcpy(ext_actions + encap_idx + 1, actions + encap_idx,
5218 sizeof(*ext_actions) * (actions_n - encap_idx));
5224 * Check the match action from the action list.
5226 * @param[in] actions
5227 * Pointer to the list of actions.
5229 * Flow rule attributes.
5231 * The action to be check if exist.
5232 * @param[out] match_action_pos
5233 * Pointer to the position of the matched action if exists, otherwise is -1.
5234 * @param[out] qrss_action_pos
5235 * Pointer to the position of the Queue/RSS action if exists, otherwise is -1.
5236 * @param[out] modify_after_mirror
5237 * Pointer to the flag of modify action after FDB mirroring.
5240 * > 0 the total number of actions.
5241 * 0 if not found match action in action list.
5244 flow_check_match_action(const struct rte_flow_action actions[],
5245 const struct rte_flow_attr *attr,
5246 enum rte_flow_action_type action,
5247 int *match_action_pos, int *qrss_action_pos,
5248 int *modify_after_mirror)
5250 const struct rte_flow_action_sample *sample;
5257 *match_action_pos = -1;
5258 *qrss_action_pos = -1;
5259 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
5260 if (actions->type == action) {
5262 *match_action_pos = actions_n;
5264 switch (actions->type) {
5265 case RTE_FLOW_ACTION_TYPE_QUEUE:
5266 case RTE_FLOW_ACTION_TYPE_RSS:
5267 *qrss_action_pos = actions_n;
5269 case RTE_FLOW_ACTION_TYPE_SAMPLE:
5270 sample = actions->conf;
5271 ratio = sample->ratio;
5272 sub_type = ((const struct rte_flow_action *)
5273 (sample->actions))->type;
5274 if (ratio == 1 && attr->transfer)
5277 case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
5278 case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
5279 case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
5280 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
5281 case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
5282 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
5283 case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
5284 case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
5285 case RTE_FLOW_ACTION_TYPE_DEC_TTL:
5286 case RTE_FLOW_ACTION_TYPE_SET_TTL:
5287 case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
5288 case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
5289 case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
5290 case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
5291 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
5292 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
5293 case RTE_FLOW_ACTION_TYPE_FLAG:
5294 case RTE_FLOW_ACTION_TYPE_MARK:
5295 case RTE_FLOW_ACTION_TYPE_SET_META:
5296 case RTE_FLOW_ACTION_TYPE_SET_TAG:
5297 case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
5298 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
5299 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
5300 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
5301 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
5302 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
5303 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
5304 case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
5305 case RTE_FLOW_ACTION_TYPE_METER:
5307 *modify_after_mirror = 1;
5314 if (flag && fdb_mirror && !*modify_after_mirror) {
5315 /* FDB mirroring uses the destination array to implement
5316 * instead of FLOW_SAMPLER object.
5318 if (sub_type != RTE_FLOW_ACTION_TYPE_END)
5321 /* Count RTE_FLOW_ACTION_TYPE_END. */
5322 return flag ? actions_n + 1 : 0;
5325 #define SAMPLE_SUFFIX_ITEM 2
5328 * Split the sample flow.
5330 * As sample flow will split to two sub flow, sample flow with
5331 * sample action, the other actions will move to new suffix flow.
5333 * Also add unique tag id with tag action in the sample flow,
5334 * the same tag id will be as match in the suffix flow.
5337 * Pointer to Ethernet device.
5338 * @param[in] add_tag
5339 * Add extra tag action flag.
5340 * @param[out] sfx_items
5341 * Suffix flow match items (list terminated by the END pattern item).
5342 * @param[in] actions
5343 * Associated actions (list terminated by the END action).
5344 * @param[out] actions_sfx
5345 * Suffix flow actions.
5346 * @param[out] actions_pre
5347 * Prefix flow actions.
5348 * @param[in] actions_n
5349 * The total number of actions.
5350 * @param[in] sample_action_pos
5351 * The sample action position.
5352 * @param[in] qrss_action_pos
5353 * The Queue/RSS action position.
5354 * @param[in] jump_table
5355 * Add extra jump action flag.
5357 * Perform verbose error reporting if not NULL.
5360 * 0 on success, or unique flow_id, a negative errno value
5361 * otherwise and rte_errno is set.
5364 flow_sample_split_prep(struct rte_eth_dev *dev,
5366 struct rte_flow_item sfx_items[],
5367 const struct rte_flow_action actions[],
5368 struct rte_flow_action actions_sfx[],
5369 struct rte_flow_action actions_pre[],
5371 int sample_action_pos,
5372 int qrss_action_pos,
5374 struct rte_flow_error *error)
5376 struct mlx5_priv *priv = dev->data->dev_private;
5377 struct mlx5_rte_flow_action_set_tag *set_tag;
5378 struct mlx5_rte_flow_item_tag *tag_spec;
5379 struct mlx5_rte_flow_item_tag *tag_mask;
5380 struct rte_flow_action_jump *jump_action;
5381 uint32_t tag_id = 0;
5383 int append_index = 0;
5386 if (sample_action_pos < 0)
5387 return rte_flow_error_set(error, EINVAL,
5388 RTE_FLOW_ERROR_TYPE_ACTION,
5389 NULL, "invalid position of sample "
5391 /* Prepare the actions for prefix and suffix flow. */
5392 if (qrss_action_pos >= 0 && qrss_action_pos < sample_action_pos) {
5393 index = qrss_action_pos;
5394 /* Put the preceding the Queue/RSS action into prefix flow. */
5396 memcpy(actions_pre, actions,
5397 sizeof(struct rte_flow_action) * index);
5398 /* Put others preceding the sample action into prefix flow. */
5399 if (sample_action_pos > index + 1)
5400 memcpy(actions_pre + index, actions + index + 1,
5401 sizeof(struct rte_flow_action) *
5402 (sample_action_pos - index - 1));
5403 index = sample_action_pos - 1;
5404 /* Put Queue/RSS action into Suffix flow. */
5405 memcpy(actions_sfx, actions + qrss_action_pos,
5406 sizeof(struct rte_flow_action));
5409 index = sample_action_pos;
5411 memcpy(actions_pre, actions,
5412 sizeof(struct rte_flow_action) * index);
5414 /* For CX5, add an extra tag action for NIC-RX and E-Switch ingress.
5415 * For CX6DX and above, metadata registers Cx preserve their value,
5416 * add an extra tag action for NIC-RX and E-Switch Domain.
5419 /* Prepare the prefix tag action. */
5421 set_tag = (void *)(actions_pre + actions_n + append_index);
5422 ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, 0, error);
5425 mlx5_ipool_malloc(priv->sh->ipool
5426 [MLX5_IPOOL_RSS_EXPANTION_FLOW_ID], &tag_id);
5427 *set_tag = (struct mlx5_rte_flow_action_set_tag) {
5431 /* Prepare the suffix subflow items. */
5432 tag_spec = (void *)(sfx_items + SAMPLE_SUFFIX_ITEM);
5433 tag_spec->data = tag_id;
5434 tag_spec->id = set_tag->id;
5435 tag_mask = tag_spec + 1;
5436 tag_mask->data = UINT32_MAX;
5437 sfx_items[0] = (struct rte_flow_item){
5438 .type = (enum rte_flow_item_type)
5439 MLX5_RTE_FLOW_ITEM_TYPE_TAG,
5444 sfx_items[1] = (struct rte_flow_item){
5445 .type = (enum rte_flow_item_type)
5446 RTE_FLOW_ITEM_TYPE_END,
5448 /* Prepare the tag action in prefix subflow. */
5449 actions_pre[index++] =
5450 (struct rte_flow_action){
5451 .type = (enum rte_flow_action_type)
5452 MLX5_RTE_FLOW_ACTION_TYPE_TAG,
5456 memcpy(actions_pre + index, actions + sample_action_pos,
5457 sizeof(struct rte_flow_action));
5459 /* For the modify action after the sample action in E-Switch mirroring,
5460 * Add the extra jump action in prefix subflow and jump into the next
5461 * table, then do the modify action in the new table.
5464 /* Prepare the prefix jump action. */
5466 jump_action = (void *)(actions_pre + actions_n + append_index);
5467 jump_action->group = jump_table;
5468 actions_pre[index++] =
5469 (struct rte_flow_action){
5470 .type = (enum rte_flow_action_type)
5471 RTE_FLOW_ACTION_TYPE_JUMP,
5472 .conf = jump_action,
5475 actions_pre[index] = (struct rte_flow_action){
5476 .type = (enum rte_flow_action_type)
5477 RTE_FLOW_ACTION_TYPE_END,
5479 /* Put the actions after sample into Suffix flow. */
5480 memcpy(actions_sfx, actions + sample_action_pos + 1,
5481 sizeof(struct rte_flow_action) *
5482 (actions_n - sample_action_pos - 1));
5487 * The splitting for metadata feature.
5489 * - Q/RSS action on NIC Rx should be split in order to pass by
5490 * the mreg copy table (RX_CP_TBL) and then it jumps to the
5491 * action table (RX_ACT_TBL) which has the split Q/RSS action.
5493 * - All the actions on NIC Tx should have a mreg copy action to
5494 * copy reg_a from WQE to reg_c[0].
5497 * Pointer to Ethernet device.
5499 * Parent flow structure pointer.
5501 * Flow rule attributes.
5503 * Pattern specification (list terminated by the END pattern item).
5504 * @param[in] actions
5505 * Associated actions (list terminated by the END action).
5506 * @param[in] flow_split_info
5507 * Pointer to flow split info structure.
5509 * Perform verbose error reporting if not NULL.
5511 * 0 on success, negative value otherwise
5514 flow_create_split_metadata(struct rte_eth_dev *dev,
5515 struct rte_flow *flow,
5516 const struct rte_flow_attr *attr,
5517 const struct rte_flow_item items[],
5518 const struct rte_flow_action actions[],
5519 struct mlx5_flow_split_info *flow_split_info,
5520 struct rte_flow_error *error)
5522 struct mlx5_priv *priv = dev->data->dev_private;
5523 struct mlx5_dev_config *config = &priv->config;
5524 const struct rte_flow_action *qrss = NULL;
5525 struct rte_flow_action *ext_actions = NULL;
5526 struct mlx5_flow *dev_flow = NULL;
5527 uint32_t qrss_id = 0;
5534 /* Check whether extensive metadata feature is engaged. */
5535 if (!config->dv_flow_en ||
5536 config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
5537 !mlx5_flow_ext_mreg_supported(dev))
5538 return flow_create_split_inner(dev, flow, NULL, attr, items,
5539 actions, flow_split_info, error);
5540 actions_n = flow_parse_metadata_split_actions_info(actions, &qrss,
5543 /* Exclude hairpin flows from splitting. */
5544 if (qrss->type == RTE_FLOW_ACTION_TYPE_QUEUE) {
5545 const struct rte_flow_action_queue *queue;
5548 if (mlx5_rxq_get_type(dev, queue->index) ==
5549 MLX5_RXQ_TYPE_HAIRPIN)
5551 } else if (qrss->type == RTE_FLOW_ACTION_TYPE_RSS) {
5552 const struct rte_flow_action_rss *rss;
5555 if (mlx5_rxq_get_type(dev, rss->queue[0]) ==
5556 MLX5_RXQ_TYPE_HAIRPIN)
5561 /* Check if it is in meter suffix table. */
5562 mtr_sfx = attr->group == (attr->transfer ?
5563 (MLX5_FLOW_TABLE_LEVEL_METER - 1) :
5564 MLX5_FLOW_TABLE_LEVEL_METER);
5566 * Q/RSS action on NIC Rx should be split in order to pass by
5567 * the mreg copy table (RX_CP_TBL) and then it jumps to the
5568 * action table (RX_ACT_TBL) which has the split Q/RSS action.
5570 act_size = sizeof(struct rte_flow_action) * (actions_n + 1) +
5571 sizeof(struct rte_flow_action_set_tag) +
5572 sizeof(struct rte_flow_action_jump);
5573 ext_actions = mlx5_malloc(MLX5_MEM_ZERO, act_size, 0,
5576 return rte_flow_error_set(error, ENOMEM,
5577 RTE_FLOW_ERROR_TYPE_ACTION,
5578 NULL, "no memory to split "
5581 * If we are the suffix flow of meter, tag already exist.
5582 * Set the tag action to void.
5585 ext_actions[qrss - actions].type =
5586 RTE_FLOW_ACTION_TYPE_VOID;
5588 ext_actions[qrss - actions].type =
5589 (enum rte_flow_action_type)
5590 MLX5_RTE_FLOW_ACTION_TYPE_TAG;
5592 * Create the new actions list with removed Q/RSS action
5593 * and appended set tag and jump to register copy table
5594 * (RX_CP_TBL). We should preallocate unique tag ID here
5595 * in advance, because it is needed for set tag action.
5597 qrss_id = flow_mreg_split_qrss_prep(dev, ext_actions, actions,
5598 qrss, actions_n, error);
5599 if (!mtr_sfx && !qrss_id) {
5603 } else if (attr->egress && !attr->transfer) {
5605 * All the actions on NIC Tx should have a metadata register
5606 * copy action to copy reg_a from WQE to reg_c[meta]
5608 act_size = sizeof(struct rte_flow_action) * (actions_n + 1) +
5609 sizeof(struct mlx5_flow_action_copy_mreg);
5610 ext_actions = mlx5_malloc(MLX5_MEM_ZERO, act_size, 0,
5613 return rte_flow_error_set(error, ENOMEM,
5614 RTE_FLOW_ERROR_TYPE_ACTION,
5615 NULL, "no memory to split "
5617 /* Create the action list appended with copy register. */
5618 ret = flow_mreg_tx_copy_prep(dev, ext_actions, actions,
5619 actions_n, error, encap_idx);
5623 /* Add the unmodified original or prefix subflow. */
5624 ret = flow_create_split_inner(dev, flow, &dev_flow, attr,
5625 items, ext_actions ? ext_actions :
5626 actions, flow_split_info, error);
5629 MLX5_ASSERT(dev_flow);
5631 const struct rte_flow_attr q_attr = {
5632 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
5635 /* Internal PMD action to set register. */
5636 struct mlx5_rte_flow_item_tag q_tag_spec = {
5640 struct rte_flow_item q_items[] = {
5642 .type = (enum rte_flow_item_type)
5643 MLX5_RTE_FLOW_ITEM_TYPE_TAG,
5644 .spec = &q_tag_spec,
5649 .type = RTE_FLOW_ITEM_TYPE_END,
5652 struct rte_flow_action q_actions[] = {
5658 .type = RTE_FLOW_ACTION_TYPE_END,
5661 uint64_t layers = flow_get_prefix_layer_flags(dev_flow);
5664 * Configure the tag item only if there is no meter subflow.
5665 * Since tag is already marked in the meter suffix subflow
5666 * we can just use the meter suffix items as is.
5669 /* Not meter subflow. */
5670 MLX5_ASSERT(!mtr_sfx);
5672 * Put unique id in prefix flow due to it is destroyed
5673 * after suffix flow and id will be freed after there
5674 * is no actual flows with this id and identifier
5675 * reallocation becomes possible (for example, for
5676 * other flows in other threads).
5678 dev_flow->handle->split_flow_id = qrss_id;
5679 ret = mlx5_flow_get_reg_id(dev, MLX5_COPY_MARK, 0,
5683 q_tag_spec.id = ret;
5686 /* Add suffix subflow to execute Q/RSS. */
5687 flow_split_info->prefix_layers = layers;
5688 flow_split_info->prefix_mark = 0;
5689 ret = flow_create_split_inner(dev, flow, &dev_flow,
5690 &q_attr, mtr_sfx ? items :
5692 flow_split_info, error);
5695 /* qrss ID should be freed if failed. */
5697 MLX5_ASSERT(dev_flow);
5702 * We do not destroy the partially created sub_flows in case of error.
5703 * These ones are included into parent flow list and will be destroyed
5704 * by flow_drv_destroy.
5706 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RSS_EXPANTION_FLOW_ID],
5708 mlx5_free(ext_actions);
5713 * Create meter internal drop flow with the original pattern.
5716 * Pointer to Ethernet device.
5718 * Parent flow structure pointer.
5720 * Flow rule attributes.
5722 * Pattern specification (list terminated by the END pattern item).
5723 * @param[in] flow_split_info
5724 * Pointer to flow split info structure.
5726 * Pointer to flow meter structure.
5728 * Perform verbose error reporting if not NULL.
5730 * 0 on success, negative value otherwise
5733 flow_meter_create_drop_flow_with_org_pattern(struct rte_eth_dev *dev,
5734 struct rte_flow *flow,
5735 const struct rte_flow_attr *attr,
5736 const struct rte_flow_item items[],
5737 struct mlx5_flow_split_info *flow_split_info,
5738 struct mlx5_flow_meter_info *fm,
5739 struct rte_flow_error *error)
5741 struct mlx5_flow *dev_flow = NULL;
5742 struct rte_flow_attr drop_attr = *attr;
5743 struct rte_flow_action drop_actions[3];
5744 struct mlx5_flow_split_info drop_split_info = *flow_split_info;
5746 MLX5_ASSERT(fm->drop_cnt);
5747 drop_actions[0].type =
5748 (enum rte_flow_action_type)MLX5_RTE_FLOW_ACTION_TYPE_COUNT;
5749 drop_actions[0].conf = (void *)(uintptr_t)fm->drop_cnt;
5750 drop_actions[1].type = RTE_FLOW_ACTION_TYPE_DROP;
5751 drop_actions[1].conf = NULL;
5752 drop_actions[2].type = RTE_FLOW_ACTION_TYPE_END;
5753 drop_actions[2].conf = NULL;
5754 drop_split_info.external = false;
5755 drop_split_info.skip_scale |= 1 << MLX5_SCALE_FLOW_GROUP_BIT;
5756 drop_split_info.table_id = MLX5_MTR_TABLE_ID_DROP;
5757 drop_attr.group = MLX5_FLOW_TABLE_LEVEL_METER;
5758 return flow_create_split_inner(dev, flow, &dev_flow,
5759 &drop_attr, items, drop_actions,
5760 &drop_split_info, error);
5764 * The splitting for meter feature.
5766 * - The meter flow will be split to two flows as prefix and
5767 * suffix flow. The packets make sense only it pass the prefix
5770 * - Reg_C_5 is used for the packet to match betweend prefix and
5774 * Pointer to Ethernet device.
5776 * Parent flow structure pointer.
5778 * Flow rule attributes.
5780 * Pattern specification (list terminated by the END pattern item).
5781 * @param[in] actions
5782 * Associated actions (list terminated by the END action).
5783 * @param[in] flow_split_info
5784 * Pointer to flow split info structure.
5786 * Perform verbose error reporting if not NULL.
5788 * 0 on success, negative value otherwise
5791 flow_create_split_meter(struct rte_eth_dev *dev,
5792 struct rte_flow *flow,
5793 const struct rte_flow_attr *attr,
5794 const struct rte_flow_item items[],
5795 const struct rte_flow_action actions[],
5796 struct mlx5_flow_split_info *flow_split_info,
5797 struct rte_flow_error *error)
5799 struct mlx5_priv *priv = dev->data->dev_private;
5800 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
5801 struct rte_flow_action *sfx_actions = NULL;
5802 struct rte_flow_action *pre_actions = NULL;
5803 struct rte_flow_item *sfx_items = NULL;
5804 struct mlx5_flow *dev_flow = NULL;
5805 struct rte_flow_attr sfx_attr = *attr;
5806 struct mlx5_flow_meter_info *fm = NULL;
5807 uint8_t skip_scale_restore;
5808 bool has_mtr = false;
5809 bool has_modify = false;
5810 bool set_mtr_reg = true;
5811 bool is_mtr_hierarchy = false;
5812 uint32_t meter_id = 0;
5813 uint32_t mtr_idx = 0;
5814 uint32_t mtr_flow_id = 0;
5821 actions_n = flow_check_meter_action(dev, actions, &has_mtr,
5822 &has_modify, &meter_id);
5825 fm = flow_dv_meter_find_by_idx(priv, flow->meter);
5827 return rte_flow_error_set(error, EINVAL,
5828 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5829 NULL, "Meter not found.");
5831 fm = mlx5_flow_meter_find(priv, meter_id, &mtr_idx);
5833 return rte_flow_error_set(error, EINVAL,
5834 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5835 NULL, "Meter not found.");
5836 ret = mlx5_flow_meter_attach(priv, fm,
5840 flow->meter = mtr_idx;
5844 if (!fm->def_policy) {
5845 wks->policy = mlx5_flow_meter_policy_find(dev,
5848 MLX5_ASSERT(wks->policy);
5849 if (wks->policy->is_hierarchy) {
5851 mlx5_flow_meter_hierarchy_get_final_policy(dev,
5853 if (!wks->final_policy)
5854 return rte_flow_error_set(error,
5856 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5857 "Failed to find terminal policy of hierarchy.");
5858 is_mtr_hierarchy = true;
5862 * If it isn't default-policy Meter, and
5863 * 1. There's no action in flow to change
5864 * packet (modify/encap/decap etc.), OR
5865 * 2. No drop count needed for this meter.
5866 * 3. It's not meter hierarchy.
5867 * Then no need to use regC to save meter id anymore.
5869 if (!fm->def_policy && !is_mtr_hierarchy &&
5870 (!has_modify || !fm->drop_cnt))
5871 set_mtr_reg = false;
5872 /* Prefix actions: meter, decap, encap, tag, jump, end. */
5873 act_size = sizeof(struct rte_flow_action) * (actions_n + 6) +
5874 sizeof(struct mlx5_rte_flow_action_set_tag);
5875 /* Suffix items: tag, vlan, port id, end. */
5876 #define METER_SUFFIX_ITEM 4
5877 item_size = sizeof(struct rte_flow_item) * METER_SUFFIX_ITEM +
5878 sizeof(struct mlx5_rte_flow_item_tag) * 2;
5879 sfx_actions = mlx5_malloc(MLX5_MEM_ZERO, (act_size + item_size),
5882 return rte_flow_error_set(error, ENOMEM,
5883 RTE_FLOW_ERROR_TYPE_ACTION,
5884 NULL, "no memory to split "
5886 sfx_items = (struct rte_flow_item *)((char *)sfx_actions +
5888 /* There's no suffix flow for meter of non-default policy. */
5889 if (!fm->def_policy)
5890 pre_actions = sfx_actions + 1;
5892 pre_actions = sfx_actions + actions_n;
5893 ret = flow_meter_split_prep(dev, flow, wks, &sfx_attr,
5894 items, sfx_items, actions,
5895 sfx_actions, pre_actions,
5896 (set_mtr_reg ? &mtr_flow_id : NULL),
5902 /* Add the prefix subflow. */
5903 flow_split_info->prefix_mark = 0;
5904 skip_scale_restore = flow_split_info->skip_scale;
5905 flow_split_info->skip_scale |=
5906 1 << MLX5_SCALE_JUMP_FLOW_GROUP_BIT;
5907 ret = flow_create_split_inner(dev, flow, &dev_flow,
5908 attr, items, pre_actions,
5909 flow_split_info, error);
5910 flow_split_info->skip_scale = skip_scale_restore;
5913 mlx5_ipool_free(fm->flow_ipool, mtr_flow_id);
5918 dev_flow->handle->split_flow_id = mtr_flow_id;
5919 dev_flow->handle->is_meter_flow_id = 1;
5921 if (!fm->def_policy) {
5922 if (!set_mtr_reg && fm->drop_cnt)
5924 flow_meter_create_drop_flow_with_org_pattern(dev, flow,
5930 /* Setting the sfx group atrr. */
5931 sfx_attr.group = sfx_attr.transfer ?
5932 (MLX5_FLOW_TABLE_LEVEL_METER - 1) :
5933 MLX5_FLOW_TABLE_LEVEL_METER;
5934 flow_split_info->prefix_layers =
5935 flow_get_prefix_layer_flags(dev_flow);
5936 flow_split_info->prefix_mark = dev_flow->handle->mark;
5937 flow_split_info->table_id = MLX5_MTR_TABLE_ID_SUFFIX;
5939 /* Add the prefix subflow. */
5940 ret = flow_create_split_metadata(dev, flow,
5941 &sfx_attr, sfx_items ?
5943 sfx_actions ? sfx_actions : actions,
5944 flow_split_info, error);
5947 mlx5_free(sfx_actions);
5952 * The splitting for sample feature.
5954 * Once Sample action is detected in the action list, the flow actions should
5955 * be split into prefix sub flow and suffix sub flow.
5957 * The original items remain in the prefix sub flow, all actions preceding the
5958 * sample action and the sample action itself will be copied to the prefix
5959 * sub flow, the actions following the sample action will be copied to the
5960 * suffix sub flow, Queue action always be located in the suffix sub flow.
5962 * In order to make the packet from prefix sub flow matches with suffix sub
5963 * flow, an extra tag action be added into prefix sub flow, and the suffix sub
5964 * flow uses tag item with the unique flow id.
5967 * Pointer to Ethernet device.
5969 * Parent flow structure pointer.
5971 * Flow rule attributes.
5973 * Pattern specification (list terminated by the END pattern item).
5974 * @param[in] actions
5975 * Associated actions (list terminated by the END action).
5976 * @param[in] flow_split_info
5977 * Pointer to flow split info structure.
5979 * Perform verbose error reporting if not NULL.
5981 * 0 on success, negative value otherwise
5984 flow_create_split_sample(struct rte_eth_dev *dev,
5985 struct rte_flow *flow,
5986 const struct rte_flow_attr *attr,
5987 const struct rte_flow_item items[],
5988 const struct rte_flow_action actions[],
5989 struct mlx5_flow_split_info *flow_split_info,
5990 struct rte_flow_error *error)
5992 struct mlx5_priv *priv = dev->data->dev_private;
5993 struct rte_flow_action *sfx_actions = NULL;
5994 struct rte_flow_action *pre_actions = NULL;
5995 struct rte_flow_item *sfx_items = NULL;
5996 struct mlx5_flow *dev_flow = NULL;
5997 struct rte_flow_attr sfx_attr = *attr;
5998 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
5999 struct mlx5_flow_dv_sample_resource *sample_res;
6000 struct mlx5_flow_tbl_data_entry *sfx_tbl_data;
6001 struct mlx5_flow_tbl_resource *sfx_tbl;
6005 uint32_t fdb_tx = 0;
6008 int sample_action_pos;
6009 int qrss_action_pos;
6011 int modify_after_mirror = 0;
6012 uint16_t jump_table = 0;
6013 const uint32_t next_ft_step = 1;
6016 if (priv->sampler_en)
6017 actions_n = flow_check_match_action(actions, attr,
6018 RTE_FLOW_ACTION_TYPE_SAMPLE,
6019 &sample_action_pos, &qrss_action_pos,
6020 &modify_after_mirror);
6022 /* The prefix actions must includes sample, tag, end. */
6023 act_size = sizeof(struct rte_flow_action) * (actions_n * 2 + 1)
6024 + sizeof(struct mlx5_rte_flow_action_set_tag);
6025 item_size = sizeof(struct rte_flow_item) * SAMPLE_SUFFIX_ITEM +
6026 sizeof(struct mlx5_rte_flow_item_tag) * 2;
6027 sfx_actions = mlx5_malloc(MLX5_MEM_ZERO, (act_size +
6028 item_size), 0, SOCKET_ID_ANY);
6030 return rte_flow_error_set(error, ENOMEM,
6031 RTE_FLOW_ERROR_TYPE_ACTION,
6032 NULL, "no memory to split "
6034 /* The representor_id is UINT16_MAX for uplink. */
6035 fdb_tx = (attr->transfer && priv->representor_id != UINT16_MAX);
6037 * When reg_c_preserve is set, metadata registers Cx preserve
6038 * their value even through packet duplication.
6040 add_tag = (!fdb_tx || priv->config.hca_attr.reg_c_preserve);
6042 sfx_items = (struct rte_flow_item *)((char *)sfx_actions
6044 if (modify_after_mirror)
6045 jump_table = attr->group * MLX5_FLOW_TABLE_FACTOR +
6047 pre_actions = sfx_actions + actions_n;
6048 tag_id = flow_sample_split_prep(dev, add_tag, sfx_items,
6049 actions, sfx_actions,
6050 pre_actions, actions_n,
6052 qrss_action_pos, jump_table,
6054 if (tag_id < 0 || (add_tag && !tag_id)) {
6058 if (modify_after_mirror)
6059 flow_split_info->skip_scale =
6060 1 << MLX5_SCALE_JUMP_FLOW_GROUP_BIT;
6061 /* Add the prefix subflow. */
6062 ret = flow_create_split_inner(dev, flow, &dev_flow, attr,
6064 flow_split_info, error);
6069 dev_flow->handle->split_flow_id = tag_id;
6070 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
6071 if (!modify_after_mirror) {
6072 /* Set the sfx group attr. */
6073 sample_res = (struct mlx5_flow_dv_sample_resource *)
6074 dev_flow->dv.sample_res;
6075 sfx_tbl = (struct mlx5_flow_tbl_resource *)
6076 sample_res->normal_path_tbl;
6077 sfx_tbl_data = container_of(sfx_tbl,
6078 struct mlx5_flow_tbl_data_entry,
6080 sfx_attr.group = sfx_attr.transfer ?
6081 (sfx_tbl_data->level - 1) : sfx_tbl_data->level;
6083 MLX5_ASSERT(attr->transfer);
6084 sfx_attr.group = jump_table;
6086 flow_split_info->prefix_layers =
6087 flow_get_prefix_layer_flags(dev_flow);
6088 flow_split_info->prefix_mark = dev_flow->handle->mark;
6089 /* Suffix group level already be scaled with factor, set
6090 * MLX5_SCALE_FLOW_GROUP_BIT of skip_scale to 1 to avoid scale
6091 * again in translation.
6093 flow_split_info->skip_scale = 1 << MLX5_SCALE_FLOW_GROUP_BIT;
6096 /* Add the suffix subflow. */
6097 ret = flow_create_split_meter(dev, flow, &sfx_attr,
6098 sfx_items ? sfx_items : items,
6099 sfx_actions ? sfx_actions : actions,
6100 flow_split_info, error);
6103 mlx5_free(sfx_actions);
6108 * Split the flow to subflow set. The splitters might be linked
6109 * in the chain, like this:
6110 * flow_create_split_outer() calls:
6111 * flow_create_split_meter() calls:
6112 * flow_create_split_metadata(meter_subflow_0) calls:
6113 * flow_create_split_inner(metadata_subflow_0)
6114 * flow_create_split_inner(metadata_subflow_1)
6115 * flow_create_split_inner(metadata_subflow_2)
6116 * flow_create_split_metadata(meter_subflow_1) calls:
6117 * flow_create_split_inner(metadata_subflow_0)
6118 * flow_create_split_inner(metadata_subflow_1)
6119 * flow_create_split_inner(metadata_subflow_2)
6121 * This provide flexible way to add new levels of flow splitting.
6122 * The all of successfully created subflows are included to the
6123 * parent flow dev_flow list.
6126 * Pointer to Ethernet device.
6128 * Parent flow structure pointer.
6130 * Flow rule attributes.
6132 * Pattern specification (list terminated by the END pattern item).
6133 * @param[in] actions
6134 * Associated actions (list terminated by the END action).
6135 * @param[in] flow_split_info
6136 * Pointer to flow split info structure.
6138 * Perform verbose error reporting if not NULL.
6140 * 0 on success, negative value otherwise
6143 flow_create_split_outer(struct rte_eth_dev *dev,
6144 struct rte_flow *flow,
6145 const struct rte_flow_attr *attr,
6146 const struct rte_flow_item items[],
6147 const struct rte_flow_action actions[],
6148 struct mlx5_flow_split_info *flow_split_info,
6149 struct rte_flow_error *error)
6153 ret = flow_create_split_sample(dev, flow, attr, items,
6154 actions, flow_split_info, error);
6155 MLX5_ASSERT(ret <= 0);
6159 static inline struct mlx5_flow_tunnel *
6160 flow_tunnel_from_rule(const struct mlx5_flow *flow)
6162 struct mlx5_flow_tunnel *tunnel;
6164 #pragma GCC diagnostic push
6165 #pragma GCC diagnostic ignored "-Wcast-qual"
6166 tunnel = (typeof(tunnel))flow->tunnel;
6167 #pragma GCC diagnostic pop
6173 * Adjust flow RSS workspace if needed.
6176 * Pointer to thread flow work space.
6178 * Pointer to RSS descriptor.
6179 * @param[in] nrssq_num
6180 * New RSS queue number.
6183 * 0 on success, -1 otherwise and rte_errno is set.
6186 flow_rss_workspace_adjust(struct mlx5_flow_workspace *wks,
6187 struct mlx5_flow_rss_desc *rss_desc,
6190 if (likely(nrssq_num <= wks->rssq_num))
6192 rss_desc->queue = realloc(rss_desc->queue,
6193 sizeof(*rss_desc->queue) * RTE_ALIGN(nrssq_num, 2));
6194 if (!rss_desc->queue) {
6198 wks->rssq_num = RTE_ALIGN(nrssq_num, 2);
6203 * Create a flow and add it to @p list.
6206 * Pointer to Ethernet device.
6208 * Pointer to a TAILQ flow list. If this parameter NULL,
6209 * no list insertion occurred, flow is just created,
6210 * this is caller's responsibility to track the
6213 * Flow rule attributes.
6215 * Pattern specification (list terminated by the END pattern item).
6216 * @param[in] actions
6217 * Associated actions (list terminated by the END action).
6218 * @param[in] external
6219 * This flow rule is created by request external to PMD.
6221 * Perform verbose error reporting if not NULL.
6224 * A flow index on success, 0 otherwise and rte_errno is set.
6227 flow_list_create(struct rte_eth_dev *dev, enum mlx5_flow_type type,
6228 const struct rte_flow_attr *attr,
6229 const struct rte_flow_item items[],
6230 const struct rte_flow_action original_actions[],
6231 bool external, struct rte_flow_error *error)
6233 struct mlx5_priv *priv = dev->data->dev_private;
6234 struct rte_flow *flow = NULL;
6235 struct mlx5_flow *dev_flow;
6236 const struct rte_flow_action_rss *rss = NULL;
6237 struct mlx5_translated_action_handle
6238 indir_actions[MLX5_MAX_INDIRECT_ACTIONS];
6239 int indir_actions_n = MLX5_MAX_INDIRECT_ACTIONS;
6241 struct mlx5_flow_expand_rss buf;
6242 uint8_t buffer[2048];
6245 struct rte_flow_action actions[MLX5_MAX_SPLIT_ACTIONS];
6246 uint8_t buffer[2048];
6249 struct rte_flow_action actions[MLX5_MAX_SPLIT_ACTIONS];
6250 uint8_t buffer[2048];
6251 } actions_hairpin_tx;
6253 struct rte_flow_item items[MLX5_MAX_SPLIT_ITEMS];
6254 uint8_t buffer[2048];
6256 struct mlx5_flow_expand_rss *buf = &expand_buffer.buf;
6257 struct mlx5_flow_rss_desc *rss_desc;
6258 const struct rte_flow_action *p_actions_rx;
6262 struct rte_flow_attr attr_tx = { .priority = 0 };
6263 const struct rte_flow_action *actions;
6264 struct rte_flow_action *translated_actions = NULL;
6265 struct mlx5_flow_tunnel *tunnel;
6266 struct tunnel_default_miss_ctx default_miss_ctx = { 0, };
6267 struct mlx5_flow_workspace *wks = mlx5_flow_push_thread_workspace();
6268 struct mlx5_flow_split_info flow_split_info = {
6269 .external = !!external,
6279 rss_desc = &wks->rss_desc;
6280 ret = flow_action_handles_translate(dev, original_actions,
6283 &translated_actions, error);
6285 MLX5_ASSERT(translated_actions == NULL);
6288 actions = translated_actions ? translated_actions : original_actions;
6289 p_actions_rx = actions;
6290 hairpin_flow = flow_check_hairpin_split(dev, attr, actions);
6291 ret = flow_drv_validate(dev, attr, items, p_actions_rx,
6292 external, hairpin_flow, error);
6294 goto error_before_hairpin_split;
6295 flow = mlx5_ipool_zmalloc(priv->flows[type], &idx);
6298 goto error_before_hairpin_split;
6300 if (hairpin_flow > 0) {
6301 if (hairpin_flow > MLX5_MAX_SPLIT_ACTIONS) {
6303 goto error_before_hairpin_split;
6305 flow_hairpin_split(dev, actions, actions_rx.actions,
6306 actions_hairpin_tx.actions, items_tx.items,
6308 p_actions_rx = actions_rx.actions;
6310 flow_split_info.flow_idx = idx;
6311 flow->drv_type = flow_get_drv_type(dev, attr);
6312 MLX5_ASSERT(flow->drv_type > MLX5_FLOW_TYPE_MIN &&
6313 flow->drv_type < MLX5_FLOW_TYPE_MAX);
6314 memset(rss_desc, 0, offsetof(struct mlx5_flow_rss_desc, queue));
6315 /* RSS Action only works on NIC RX domain */
6316 if (attr->ingress && !attr->transfer)
6317 rss = flow_get_rss_action(dev, p_actions_rx);
6319 if (flow_rss_workspace_adjust(wks, rss_desc, rss->queue_num))
6322 * The following information is required by
6323 * mlx5_flow_hashfields_adjust() in advance.
6325 rss_desc->level = rss->level;
6326 /* RSS type 0 indicates default RSS type (ETH_RSS_IP). */
6327 rss_desc->types = !rss->types ? ETH_RSS_IP : rss->types;
6329 flow->dev_handles = 0;
6330 if (rss && rss->types) {
6331 unsigned int graph_root;
6333 graph_root = find_graph_root(items, rss->level);
6334 ret = mlx5_flow_expand_rss(buf, sizeof(expand_buffer.buffer),
6336 mlx5_support_expansion, graph_root);
6337 MLX5_ASSERT(ret > 0 &&
6338 (unsigned int)ret < sizeof(expand_buffer.buffer));
6339 if (rte_log_can_log(mlx5_logtype, RTE_LOG_DEBUG)) {
6340 for (i = 0; i < buf->entries; ++i)
6341 mlx5_dbg__print_pattern(buf->entry[i].pattern);
6345 buf->entry[0].pattern = (void *)(uintptr_t)items;
6347 rss_desc->shared_rss = flow_get_shared_rss_action(dev, indir_actions,
6349 for (i = 0; i < buf->entries; ++i) {
6350 /* Initialize flow split data. */
6351 flow_split_info.prefix_layers = 0;
6352 flow_split_info.prefix_mark = 0;
6353 flow_split_info.skip_scale = 0;
6355 * The splitter may create multiple dev_flows,
6356 * depending on configuration. In the simplest
6357 * case it just creates unmodified original flow.
6359 ret = flow_create_split_outer(dev, flow, attr,
6360 buf->entry[i].pattern,
6361 p_actions_rx, &flow_split_info,
6365 if (is_flow_tunnel_steer_rule(wks->flows[0].tof_type)) {
6366 ret = flow_tunnel_add_default_miss(dev, flow, attr,
6369 wks->flows[0].tunnel,
6373 mlx5_free(default_miss_ctx.queue);
6378 /* Create the tx flow. */
6380 attr_tx.group = MLX5_HAIRPIN_TX_TABLE;
6381 attr_tx.ingress = 0;
6383 dev_flow = flow_drv_prepare(dev, flow, &attr_tx, items_tx.items,
6384 actions_hairpin_tx.actions,
6388 dev_flow->flow = flow;
6389 dev_flow->external = 0;
6390 SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
6391 dev_flow->handle, next);
6392 ret = flow_drv_translate(dev, dev_flow, &attr_tx,
6394 actions_hairpin_tx.actions, error);
6399 * Update the metadata register copy table. If extensive
6400 * metadata feature is enabled and registers are supported
6401 * we might create the extra rte_flow for each unique
6402 * MARK/FLAG action ID.
6404 * The table is updated for ingress Flows only, because
6405 * the egress Flows belong to the different device and
6406 * copy table should be updated in peer NIC Rx domain.
6408 if (attr->ingress &&
6409 (external || attr->group != MLX5_FLOW_MREG_CP_TABLE_GROUP)) {
6410 ret = flow_mreg_update_copy_table(dev, flow, actions, error);
6415 * If the flow is external (from application) OR device is started,
6416 * OR mreg discover, then apply immediately.
6418 if (external || dev->data->dev_started ||
6419 (attr->group == MLX5_FLOW_MREG_CP_TABLE_GROUP &&
6420 attr->priority == MLX5_FLOW_LOWEST_PRIO_INDICATOR)) {
6421 ret = flow_drv_apply(dev, flow, error);
6426 flow_rxq_flags_set(dev, flow);
6427 rte_free(translated_actions);
6428 tunnel = flow_tunnel_from_rule(wks->flows);
6431 flow->tunnel_id = tunnel->tunnel_id;
6432 __atomic_add_fetch(&tunnel->refctn, 1, __ATOMIC_RELAXED);
6433 mlx5_free(default_miss_ctx.queue);
6435 mlx5_flow_pop_thread_workspace();
6439 ret = rte_errno; /* Save rte_errno before cleanup. */
6440 flow_mreg_del_copy_action(dev, flow);
6441 flow_drv_destroy(dev, flow);
6442 if (rss_desc->shared_rss)
6443 __atomic_sub_fetch(&((struct mlx5_shared_action_rss *)
6445 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
6446 rss_desc->shared_rss))->refcnt, 1, __ATOMIC_RELAXED);
6447 mlx5_ipool_free(priv->flows[type], idx);
6448 rte_errno = ret; /* Restore rte_errno. */
6451 mlx5_flow_pop_thread_workspace();
6452 error_before_hairpin_split:
6453 rte_free(translated_actions);
6458 * Create a dedicated flow rule on e-switch table 0 (root table), to direct all
6459 * incoming packets to table 1.
6461 * Other flow rules, requested for group n, will be created in
6462 * e-switch table n+1.
6463 * Jump action to e-switch group n will be created to group n+1.
6465 * Used when working in switchdev mode, to utilise advantages of table 1
6469 * Pointer to Ethernet device.
6472 * Pointer to flow on success, NULL otherwise and rte_errno is set.
6475 mlx5_flow_create_esw_table_zero_flow(struct rte_eth_dev *dev)
6477 const struct rte_flow_attr attr = {
6484 const struct rte_flow_item pattern = {
6485 .type = RTE_FLOW_ITEM_TYPE_END,
6487 struct rte_flow_action_jump jump = {
6490 const struct rte_flow_action actions[] = {
6492 .type = RTE_FLOW_ACTION_TYPE_JUMP,
6496 .type = RTE_FLOW_ACTION_TYPE_END,
6499 struct rte_flow_error error;
6501 return (void *)(uintptr_t)flow_list_create(dev, MLX5_FLOW_TYPE_CTL,
6503 actions, false, &error);
6507 * Validate a flow supported by the NIC.
6509 * @see rte_flow_validate()
6513 mlx5_flow_validate(struct rte_eth_dev *dev,
6514 const struct rte_flow_attr *attr,
6515 const struct rte_flow_item items[],
6516 const struct rte_flow_action original_actions[],
6517 struct rte_flow_error *error)
6520 struct mlx5_translated_action_handle
6521 indir_actions[MLX5_MAX_INDIRECT_ACTIONS];
6522 int indir_actions_n = MLX5_MAX_INDIRECT_ACTIONS;
6523 const struct rte_flow_action *actions;
6524 struct rte_flow_action *translated_actions = NULL;
6525 int ret = flow_action_handles_translate(dev, original_actions,
6528 &translated_actions, error);
6532 actions = translated_actions ? translated_actions : original_actions;
6533 hairpin_flow = flow_check_hairpin_split(dev, attr, actions);
6534 ret = flow_drv_validate(dev, attr, items, actions,
6535 true, hairpin_flow, error);
6536 rte_free(translated_actions);
6543 * @see rte_flow_create()
6547 mlx5_flow_create(struct rte_eth_dev *dev,
6548 const struct rte_flow_attr *attr,
6549 const struct rte_flow_item items[],
6550 const struct rte_flow_action actions[],
6551 struct rte_flow_error *error)
6554 * If the device is not started yet, it is not allowed to created a
6555 * flow from application. PMD default flows and traffic control flows
6558 if (unlikely(!dev->data->dev_started)) {
6559 DRV_LOG(DEBUG, "port %u is not started when "
6560 "inserting a flow", dev->data->port_id);
6561 rte_flow_error_set(error, ENODEV,
6562 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6564 "port not started");
6568 return (void *)(uintptr_t)flow_list_create(dev, MLX5_FLOW_TYPE_GEN,
6569 attr, items, actions,
6574 * Destroy a flow in a list.
6577 * Pointer to Ethernet device.
6578 * @param[in] flow_idx
6579 * Index of flow to destroy.
6582 flow_list_destroy(struct rte_eth_dev *dev, enum mlx5_flow_type type,
6585 struct mlx5_priv *priv = dev->data->dev_private;
6586 struct rte_flow *flow = mlx5_ipool_get(priv->flows[type], flow_idx);
6590 MLX5_ASSERT(flow->type == type);
6592 * Update RX queue flags only if port is started, otherwise it is
6595 if (dev->data->dev_started)
6596 flow_rxq_flags_trim(dev, flow);
6597 flow_drv_destroy(dev, flow);
6599 struct mlx5_flow_tunnel *tunnel;
6601 tunnel = mlx5_find_tunnel_id(dev, flow->tunnel_id);
6603 if (!__atomic_sub_fetch(&tunnel->refctn, 1, __ATOMIC_RELAXED))
6604 mlx5_flow_tunnel_free(dev, tunnel);
6606 flow_mreg_del_copy_action(dev, flow);
6607 mlx5_ipool_free(priv->flows[type], flow_idx);
6611 * Destroy all flows.
6614 * Pointer to Ethernet device.
6616 * Flow type to be flushed.
6618 * If flushing is called avtively.
6621 mlx5_flow_list_flush(struct rte_eth_dev *dev, enum mlx5_flow_type type,
6624 struct mlx5_priv *priv = dev->data->dev_private;
6625 uint32_t num_flushed = 0, fidx = 1;
6626 struct rte_flow *flow;
6628 MLX5_IPOOL_FOREACH(priv->flows[type], fidx, flow) {
6629 flow_list_destroy(dev, type, fidx);
6633 DRV_LOG(INFO, "port %u: %u flows flushed before stopping",
6634 dev->data->port_id, num_flushed);
6639 * Stop all default actions for flows.
6642 * Pointer to Ethernet device.
6645 mlx5_flow_stop_default(struct rte_eth_dev *dev)
6647 flow_mreg_del_default_copy_action(dev);
6648 flow_rxq_flags_clear(dev);
6652 * Start all default actions for flows.
6655 * Pointer to Ethernet device.
6657 * 0 on success, a negative errno value otherwise and rte_errno is set.
6660 mlx5_flow_start_default(struct rte_eth_dev *dev)
6662 struct rte_flow_error error;
6664 /* Make sure default copy action (reg_c[0] -> reg_b) is created. */
6665 return flow_mreg_add_default_copy_action(dev, &error);
6669 * Release key of thread specific flow workspace data.
6672 flow_release_workspace(void *data)
6674 struct mlx5_flow_workspace *wks = data;
6675 struct mlx5_flow_workspace *next;
6679 free(wks->rss_desc.queue);
6686 * Get thread specific current flow workspace.
6688 * @return pointer to thread specific flow workspace data, NULL on error.
6690 struct mlx5_flow_workspace*
6691 mlx5_flow_get_thread_workspace(void)
6693 struct mlx5_flow_workspace *data;
6695 data = mlx5_flow_os_get_specific_workspace();
6696 MLX5_ASSERT(data && data->inuse);
6697 if (!data || !data->inuse)
6698 DRV_LOG(ERR, "flow workspace not initialized.");
6703 * Allocate and init new flow workspace.
6705 * @return pointer to flow workspace data, NULL on error.
6707 static struct mlx5_flow_workspace*
6708 flow_alloc_thread_workspace(void)
6710 struct mlx5_flow_workspace *data = calloc(1, sizeof(*data));
6713 DRV_LOG(ERR, "Failed to allocate flow workspace "
6717 data->rss_desc.queue = calloc(1,
6718 sizeof(uint16_t) * MLX5_RSSQ_DEFAULT_NUM);
6719 if (!data->rss_desc.queue)
6721 data->rssq_num = MLX5_RSSQ_DEFAULT_NUM;
6724 if (data->rss_desc.queue)
6725 free(data->rss_desc.queue);
6731 * Get new thread specific flow workspace.
6733 * If current workspace inuse, create new one and set as current.
6735 * @return pointer to thread specific flow workspace data, NULL on error.
6737 static struct mlx5_flow_workspace*
6738 mlx5_flow_push_thread_workspace(void)
6740 struct mlx5_flow_workspace *curr;
6741 struct mlx5_flow_workspace *data;
6743 curr = mlx5_flow_os_get_specific_workspace();
6745 data = flow_alloc_thread_workspace();
6748 } else if (!curr->inuse) {
6750 } else if (curr->next) {
6753 data = flow_alloc_thread_workspace();
6761 /* Set as current workspace */
6762 if (mlx5_flow_os_set_specific_workspace(data))
6763 DRV_LOG(ERR, "Failed to set flow workspace to thread.");
6768 * Close current thread specific flow workspace.
6770 * If previous workspace available, set it as current.
6772 * @return pointer to thread specific flow workspace data, NULL on error.
6775 mlx5_flow_pop_thread_workspace(void)
6777 struct mlx5_flow_workspace *data = mlx5_flow_get_thread_workspace();
6782 DRV_LOG(ERR, "Failed to close unused flow workspace.");
6788 if (mlx5_flow_os_set_specific_workspace(data->prev))
6789 DRV_LOG(ERR, "Failed to set flow workspace to thread.");
6793 * Verify the flow list is empty
6796 * Pointer to Ethernet device.
6798 * @return the number of flows not released.
6801 mlx5_flow_verify(struct rte_eth_dev *dev __rte_unused)
6803 struct mlx5_priv *priv = dev->data->dev_private;
6804 struct rte_flow *flow;
6808 for (i = 0; i < MLX5_FLOW_TYPE_MAXI; i++) {
6809 MLX5_IPOOL_FOREACH(priv->flows[i], idx, flow) {
6810 DRV_LOG(DEBUG, "port %u flow %p still referenced",
6811 dev->data->port_id, (void *)flow);
6819 * Enable default hairpin egress flow.
6822 * Pointer to Ethernet device.
6827 * 0 on success, a negative errno value otherwise and rte_errno is set.
6830 mlx5_ctrl_flow_source_queue(struct rte_eth_dev *dev,
6833 const struct rte_flow_attr attr = {
6837 struct mlx5_rte_flow_item_tx_queue queue_spec = {
6840 struct mlx5_rte_flow_item_tx_queue queue_mask = {
6841 .queue = UINT32_MAX,
6843 struct rte_flow_item items[] = {
6845 .type = (enum rte_flow_item_type)
6846 MLX5_RTE_FLOW_ITEM_TYPE_TX_QUEUE,
6847 .spec = &queue_spec,
6849 .mask = &queue_mask,
6852 .type = RTE_FLOW_ITEM_TYPE_END,
6855 struct rte_flow_action_jump jump = {
6856 .group = MLX5_HAIRPIN_TX_TABLE,
6858 struct rte_flow_action actions[2];
6860 struct rte_flow_error error;
6862 actions[0].type = RTE_FLOW_ACTION_TYPE_JUMP;
6863 actions[0].conf = &jump;
6864 actions[1].type = RTE_FLOW_ACTION_TYPE_END;
6865 flow_idx = flow_list_create(dev, MLX5_FLOW_TYPE_CTL,
6866 &attr, items, actions, false, &error);
6869 "Failed to create ctrl flow: rte_errno(%d),"
6870 " type(%d), message(%s)",
6871 rte_errno, error.type,
6872 error.message ? error.message : " (no stated reason)");
6879 * Enable a control flow configured from the control plane.
6882 * Pointer to Ethernet device.
6884 * An Ethernet flow spec to apply.
6886 * An Ethernet flow mask to apply.
6888 * A VLAN flow spec to apply.
6890 * A VLAN flow mask to apply.
6893 * 0 on success, a negative errno value otherwise and rte_errno is set.
6896 mlx5_ctrl_flow_vlan(struct rte_eth_dev *dev,
6897 struct rte_flow_item_eth *eth_spec,
6898 struct rte_flow_item_eth *eth_mask,
6899 struct rte_flow_item_vlan *vlan_spec,
6900 struct rte_flow_item_vlan *vlan_mask)
6902 struct mlx5_priv *priv = dev->data->dev_private;
6903 const struct rte_flow_attr attr = {
6905 .priority = MLX5_FLOW_LOWEST_PRIO_INDICATOR,
6907 struct rte_flow_item items[] = {
6909 .type = RTE_FLOW_ITEM_TYPE_ETH,
6915 .type = (vlan_spec) ? RTE_FLOW_ITEM_TYPE_VLAN :
6916 RTE_FLOW_ITEM_TYPE_END,
6922 .type = RTE_FLOW_ITEM_TYPE_END,
6925 uint16_t queue[priv->reta_idx_n];
6926 struct rte_flow_action_rss action_rss = {
6927 .func = RTE_ETH_HASH_FUNCTION_DEFAULT,
6929 .types = priv->rss_conf.rss_hf,
6930 .key_len = priv->rss_conf.rss_key_len,
6931 .queue_num = priv->reta_idx_n,
6932 .key = priv->rss_conf.rss_key,
6935 struct rte_flow_action actions[] = {
6937 .type = RTE_FLOW_ACTION_TYPE_RSS,
6938 .conf = &action_rss,
6941 .type = RTE_FLOW_ACTION_TYPE_END,
6945 struct rte_flow_error error;
6948 if (!priv->reta_idx_n || !priv->rxqs_n) {
6951 if (!(dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG))
6952 action_rss.types = 0;
6953 for (i = 0; i != priv->reta_idx_n; ++i)
6954 queue[i] = (*priv->reta_idx)[i];
6955 flow_idx = flow_list_create(dev, MLX5_FLOW_TYPE_CTL,
6956 &attr, items, actions, false, &error);
6963 * Enable a flow control configured from the control plane.
6966 * Pointer to Ethernet device.
6968 * An Ethernet flow spec to apply.
6970 * An Ethernet flow mask to apply.
6973 * 0 on success, a negative errno value otherwise and rte_errno is set.
6976 mlx5_ctrl_flow(struct rte_eth_dev *dev,
6977 struct rte_flow_item_eth *eth_spec,
6978 struct rte_flow_item_eth *eth_mask)
6980 return mlx5_ctrl_flow_vlan(dev, eth_spec, eth_mask, NULL, NULL);
6984 * Create default miss flow rule matching lacp traffic
6987 * Pointer to Ethernet device.
6989 * An Ethernet flow spec to apply.
6992 * 0 on success, a negative errno value otherwise and rte_errno is set.
6995 mlx5_flow_lacp_miss(struct rte_eth_dev *dev)
6998 * The LACP matching is done by only using ether type since using
6999 * a multicast dst mac causes kernel to give low priority to this flow.
7001 static const struct rte_flow_item_eth lacp_spec = {
7002 .type = RTE_BE16(0x8809),
7004 static const struct rte_flow_item_eth lacp_mask = {
7007 const struct rte_flow_attr attr = {
7010 struct rte_flow_item items[] = {
7012 .type = RTE_FLOW_ITEM_TYPE_ETH,
7017 .type = RTE_FLOW_ITEM_TYPE_END,
7020 struct rte_flow_action actions[] = {
7022 .type = (enum rte_flow_action_type)
7023 MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS,
7026 .type = RTE_FLOW_ACTION_TYPE_END,
7029 struct rte_flow_error error;
7030 uint32_t flow_idx = flow_list_create(dev, MLX5_FLOW_TYPE_CTL,
7031 &attr, items, actions,
7042 * @see rte_flow_destroy()
7046 mlx5_flow_destroy(struct rte_eth_dev *dev,
7047 struct rte_flow *flow,
7048 struct rte_flow_error *error __rte_unused)
7050 flow_list_destroy(dev, MLX5_FLOW_TYPE_GEN,
7051 (uintptr_t)(void *)flow);
7056 * Destroy all flows.
7058 * @see rte_flow_flush()
7062 mlx5_flow_flush(struct rte_eth_dev *dev,
7063 struct rte_flow_error *error __rte_unused)
7065 mlx5_flow_list_flush(dev, MLX5_FLOW_TYPE_GEN, false);
7072 * @see rte_flow_isolate()
7076 mlx5_flow_isolate(struct rte_eth_dev *dev,
7078 struct rte_flow_error *error)
7080 struct mlx5_priv *priv = dev->data->dev_private;
7082 if (dev->data->dev_started) {
7083 rte_flow_error_set(error, EBUSY,
7084 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7086 "port must be stopped first");
7089 priv->isolated = !!enable;
7091 dev->dev_ops = &mlx5_dev_ops_isolate;
7093 dev->dev_ops = &mlx5_dev_ops;
7095 dev->rx_descriptor_status = mlx5_rx_descriptor_status;
7096 dev->tx_descriptor_status = mlx5_tx_descriptor_status;
7104 * @see rte_flow_query()
7108 flow_drv_query(struct rte_eth_dev *dev,
7110 const struct rte_flow_action *actions,
7112 struct rte_flow_error *error)
7114 struct mlx5_priv *priv = dev->data->dev_private;
7115 const struct mlx5_flow_driver_ops *fops;
7116 struct rte_flow *flow = mlx5_ipool_get(priv->flows[MLX5_FLOW_TYPE_GEN],
7118 enum mlx5_flow_drv_type ftype;
7121 return rte_flow_error_set(error, ENOENT,
7122 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7124 "invalid flow handle");
7126 ftype = flow->drv_type;
7127 MLX5_ASSERT(ftype > MLX5_FLOW_TYPE_MIN && ftype < MLX5_FLOW_TYPE_MAX);
7128 fops = flow_get_drv_ops(ftype);
7130 return fops->query(dev, flow, actions, data, error);
7136 * @see rte_flow_query()
7140 mlx5_flow_query(struct rte_eth_dev *dev,
7141 struct rte_flow *flow,
7142 const struct rte_flow_action *actions,
7144 struct rte_flow_error *error)
7148 ret = flow_drv_query(dev, (uintptr_t)(void *)flow, actions, data,
7156 * Get rte_flow callbacks.
7159 * Pointer to Ethernet device structure.
7161 * Pointer to operation-specific structure.
7166 mlx5_flow_ops_get(struct rte_eth_dev *dev __rte_unused,
7167 const struct rte_flow_ops **ops)
7169 *ops = &mlx5_flow_ops;
7174 * Validate meter policy actions.
7175 * Dispatcher for action type specific validation.
7178 * Pointer to the Ethernet device structure.
7180 * The meter policy action object to validate.
7182 * Attributes of flow to determine steering domain.
7183 * @param[out] is_rss
7185 * @param[out] domain_bitmap
7187 * @param[out] is_def_policy
7188 * Is default policy or not.
7190 * Perform verbose error reporting if not NULL. Initialized in case of
7194 * 0 on success, otherwise negative errno value.
7197 mlx5_flow_validate_mtr_acts(struct rte_eth_dev *dev,
7198 const struct rte_flow_action *actions[RTE_COLORS],
7199 struct rte_flow_attr *attr,
7201 uint8_t *domain_bitmap,
7202 uint8_t *policy_mode,
7203 struct rte_mtr_error *error)
7205 const struct mlx5_flow_driver_ops *fops;
7207 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7208 return fops->validate_mtr_acts(dev, actions, attr, is_rss,
7209 domain_bitmap, policy_mode, error);
7213 * Destroy the meter table set.
7216 * Pointer to Ethernet device.
7217 * @param[in] mtr_policy
7218 * Meter policy struct.
7221 mlx5_flow_destroy_mtr_acts(struct rte_eth_dev *dev,
7222 struct mlx5_flow_meter_policy *mtr_policy)
7224 const struct mlx5_flow_driver_ops *fops;
7226 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7227 fops->destroy_mtr_acts(dev, mtr_policy);
7231 * Create policy action, lock free,
7232 * (mutex should be acquired by caller).
7233 * Dispatcher for action type specific call.
7236 * Pointer to the Ethernet device structure.
7237 * @param[in] mtr_policy
7238 * Meter policy struct.
7240 * Action specification used to create meter actions.
7242 * Perform verbose error reporting if not NULL. Initialized in case of
7246 * 0 on success, otherwise negative errno value.
7249 mlx5_flow_create_mtr_acts(struct rte_eth_dev *dev,
7250 struct mlx5_flow_meter_policy *mtr_policy,
7251 const struct rte_flow_action *actions[RTE_COLORS],
7252 struct rte_mtr_error *error)
7254 const struct mlx5_flow_driver_ops *fops;
7256 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7257 return fops->create_mtr_acts(dev, mtr_policy, actions, error);
7261 * Create policy rules, lock free,
7262 * (mutex should be acquired by caller).
7263 * Dispatcher for action type specific call.
7266 * Pointer to the Ethernet device structure.
7267 * @param[in] mtr_policy
7268 * Meter policy struct.
7271 * 0 on success, -1 otherwise.
7274 mlx5_flow_create_policy_rules(struct rte_eth_dev *dev,
7275 struct mlx5_flow_meter_policy *mtr_policy)
7277 const struct mlx5_flow_driver_ops *fops;
7279 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7280 return fops->create_policy_rules(dev, mtr_policy);
7284 * Destroy policy rules, lock free,
7285 * (mutex should be acquired by caller).
7286 * Dispatcher for action type specific call.
7289 * Pointer to the Ethernet device structure.
7290 * @param[in] mtr_policy
7291 * Meter policy struct.
7294 mlx5_flow_destroy_policy_rules(struct rte_eth_dev *dev,
7295 struct mlx5_flow_meter_policy *mtr_policy)
7297 const struct mlx5_flow_driver_ops *fops;
7299 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7300 fops->destroy_policy_rules(dev, mtr_policy);
7304 * Destroy the default policy table set.
7307 * Pointer to Ethernet device.
7310 mlx5_flow_destroy_def_policy(struct rte_eth_dev *dev)
7312 const struct mlx5_flow_driver_ops *fops;
7314 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7315 fops->destroy_def_policy(dev);
7319 * Destroy the default policy table set.
7322 * Pointer to Ethernet device.
7325 * 0 on success, -1 otherwise.
7328 mlx5_flow_create_def_policy(struct rte_eth_dev *dev)
7330 const struct mlx5_flow_driver_ops *fops;
7332 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7333 return fops->create_def_policy(dev);
7337 * Create the needed meter and suffix tables.
7340 * Pointer to Ethernet device.
7343 * 0 on success, -1 otherwise.
7346 mlx5_flow_create_mtr_tbls(struct rte_eth_dev *dev,
7347 struct mlx5_flow_meter_info *fm,
7349 uint8_t domain_bitmap)
7351 const struct mlx5_flow_driver_ops *fops;
7353 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7354 return fops->create_mtr_tbls(dev, fm, mtr_idx, domain_bitmap);
7358 * Destroy the meter table set.
7361 * Pointer to Ethernet device.
7363 * Pointer to the meter table set.
7366 mlx5_flow_destroy_mtr_tbls(struct rte_eth_dev *dev,
7367 struct mlx5_flow_meter_info *fm)
7369 const struct mlx5_flow_driver_ops *fops;
7371 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7372 fops->destroy_mtr_tbls(dev, fm);
7376 * Destroy the global meter drop table.
7379 * Pointer to Ethernet device.
7382 mlx5_flow_destroy_mtr_drop_tbls(struct rte_eth_dev *dev)
7384 const struct mlx5_flow_driver_ops *fops;
7386 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7387 fops->destroy_mtr_drop_tbls(dev);
7391 * Destroy the sub policy table with RX queue.
7394 * Pointer to Ethernet device.
7395 * @param[in] mtr_policy
7396 * Pointer to meter policy table.
7399 mlx5_flow_destroy_sub_policy_with_rxq(struct rte_eth_dev *dev,
7400 struct mlx5_flow_meter_policy *mtr_policy)
7402 const struct mlx5_flow_driver_ops *fops;
7404 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7405 fops->destroy_sub_policy_with_rxq(dev, mtr_policy);
7409 * Allocate the needed aso flow meter id.
7412 * Pointer to Ethernet device.
7415 * Index to aso flow meter on success, NULL otherwise.
7418 mlx5_flow_mtr_alloc(struct rte_eth_dev *dev)
7420 const struct mlx5_flow_driver_ops *fops;
7422 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7423 return fops->create_meter(dev);
7427 * Free the aso flow meter id.
7430 * Pointer to Ethernet device.
7431 * @param[in] mtr_idx
7432 * Index to aso flow meter to be free.
7438 mlx5_flow_mtr_free(struct rte_eth_dev *dev, uint32_t mtr_idx)
7440 const struct mlx5_flow_driver_ops *fops;
7442 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7443 fops->free_meter(dev, mtr_idx);
7447 * Allocate a counter.
7450 * Pointer to Ethernet device structure.
7453 * Index to allocated counter on success, 0 otherwise.
7456 mlx5_counter_alloc(struct rte_eth_dev *dev)
7458 const struct mlx5_flow_driver_ops *fops;
7459 struct rte_flow_attr attr = { .transfer = 0 };
7461 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
7462 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7463 return fops->counter_alloc(dev);
7466 "port %u counter allocate is not supported.",
7467 dev->data->port_id);
7475 * Pointer to Ethernet device structure.
7477 * Index to counter to be free.
7480 mlx5_counter_free(struct rte_eth_dev *dev, uint32_t cnt)
7482 const struct mlx5_flow_driver_ops *fops;
7483 struct rte_flow_attr attr = { .transfer = 0 };
7485 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
7486 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7487 fops->counter_free(dev, cnt);
7491 "port %u counter free is not supported.",
7492 dev->data->port_id);
7496 * Query counter statistics.
7499 * Pointer to Ethernet device structure.
7501 * Index to counter to query.
7503 * Set to clear counter statistics.
7505 * The counter hits packets number to save.
7507 * The counter hits bytes number to save.
7510 * 0 on success, a negative errno value otherwise.
7513 mlx5_counter_query(struct rte_eth_dev *dev, uint32_t cnt,
7514 bool clear, uint64_t *pkts, uint64_t *bytes)
7516 const struct mlx5_flow_driver_ops *fops;
7517 struct rte_flow_attr attr = { .transfer = 0 };
7519 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
7520 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7521 return fops->counter_query(dev, cnt, clear, pkts, bytes);
7524 "port %u counter query is not supported.",
7525 dev->data->port_id);
7530 * Allocate a new memory for the counter values wrapped by all the needed
7534 * Pointer to mlx5_dev_ctx_shared object.
7537 * 0 on success, a negative errno value otherwise.
7540 mlx5_flow_create_counter_stat_mem_mng(struct mlx5_dev_ctx_shared *sh)
7542 struct mlx5_devx_mkey_attr mkey_attr;
7543 struct mlx5_counter_stats_mem_mng *mem_mng;
7544 volatile struct flow_counter_stats *raw_data;
7545 int raws_n = MLX5_CNT_CONTAINER_RESIZE + MLX5_MAX_PENDING_QUERIES;
7546 int size = (sizeof(struct flow_counter_stats) *
7547 MLX5_COUNTERS_PER_POOL +
7548 sizeof(struct mlx5_counter_stats_raw)) * raws_n +
7549 sizeof(struct mlx5_counter_stats_mem_mng);
7550 size_t pgsize = rte_mem_page_size();
7554 if (pgsize == (size_t)-1) {
7555 DRV_LOG(ERR, "Failed to get mem page size");
7559 mem = mlx5_malloc(MLX5_MEM_ZERO, size, pgsize, SOCKET_ID_ANY);
7564 mem_mng = (struct mlx5_counter_stats_mem_mng *)(mem + size) - 1;
7565 size = sizeof(*raw_data) * MLX5_COUNTERS_PER_POOL * raws_n;
7566 mem_mng->umem = mlx5_os_umem_reg(sh->ctx, mem, size,
7567 IBV_ACCESS_LOCAL_WRITE);
7568 if (!mem_mng->umem) {
7573 memset(&mkey_attr, 0, sizeof(mkey_attr));
7574 mkey_attr.addr = (uintptr_t)mem;
7575 mkey_attr.size = size;
7576 mkey_attr.umem_id = mlx5_os_get_umem_id(mem_mng->umem);
7577 mkey_attr.pd = sh->pdn;
7578 mkey_attr.relaxed_ordering_write = sh->cmng.relaxed_ordering_write;
7579 mkey_attr.relaxed_ordering_read = sh->cmng.relaxed_ordering_read;
7580 mem_mng->dm = mlx5_devx_cmd_mkey_create(sh->ctx, &mkey_attr);
7582 mlx5_os_umem_dereg(mem_mng->umem);
7587 mem_mng->raws = (struct mlx5_counter_stats_raw *)(mem + size);
7588 raw_data = (volatile struct flow_counter_stats *)mem;
7589 for (i = 0; i < raws_n; ++i) {
7590 mem_mng->raws[i].mem_mng = mem_mng;
7591 mem_mng->raws[i].data = raw_data + i * MLX5_COUNTERS_PER_POOL;
7593 for (i = 0; i < MLX5_MAX_PENDING_QUERIES; ++i)
7594 LIST_INSERT_HEAD(&sh->cmng.free_stat_raws,
7595 mem_mng->raws + MLX5_CNT_CONTAINER_RESIZE + i,
7597 LIST_INSERT_HEAD(&sh->cmng.mem_mngs, mem_mng, next);
7598 sh->cmng.mem_mng = mem_mng;
7603 * Set the statistic memory to the new counter pool.
7606 * Pointer to mlx5_dev_ctx_shared object.
7608 * Pointer to the pool to set the statistic memory.
7611 * 0 on success, a negative errno value otherwise.
7614 mlx5_flow_set_counter_stat_mem(struct mlx5_dev_ctx_shared *sh,
7615 struct mlx5_flow_counter_pool *pool)
7617 struct mlx5_flow_counter_mng *cmng = &sh->cmng;
7618 /* Resize statistic memory once used out. */
7619 if (!(pool->index % MLX5_CNT_CONTAINER_RESIZE) &&
7620 mlx5_flow_create_counter_stat_mem_mng(sh)) {
7621 DRV_LOG(ERR, "Cannot resize counter stat mem.");
7624 rte_spinlock_lock(&pool->sl);
7625 pool->raw = cmng->mem_mng->raws + pool->index %
7626 MLX5_CNT_CONTAINER_RESIZE;
7627 rte_spinlock_unlock(&pool->sl);
7628 pool->raw_hw = NULL;
7632 #define MLX5_POOL_QUERY_FREQ_US 1000000
7635 * Set the periodic procedure for triggering asynchronous batch queries for all
7636 * the counter pools.
7639 * Pointer to mlx5_dev_ctx_shared object.
7642 mlx5_set_query_alarm(struct mlx5_dev_ctx_shared *sh)
7644 uint32_t pools_n, us;
7646 pools_n = __atomic_load_n(&sh->cmng.n_valid, __ATOMIC_RELAXED);
7647 us = MLX5_POOL_QUERY_FREQ_US / pools_n;
7648 DRV_LOG(DEBUG, "Set alarm for %u pools each %u us", pools_n, us);
7649 if (rte_eal_alarm_set(us, mlx5_flow_query_alarm, sh)) {
7650 sh->cmng.query_thread_on = 0;
7651 DRV_LOG(ERR, "Cannot reinitialize query alarm");
7653 sh->cmng.query_thread_on = 1;
7658 * The periodic procedure for triggering asynchronous batch queries for all the
7659 * counter pools. This function is probably called by the host thread.
7662 * The parameter for the alarm process.
7665 mlx5_flow_query_alarm(void *arg)
7667 struct mlx5_dev_ctx_shared *sh = arg;
7669 uint16_t pool_index = sh->cmng.pool_index;
7670 struct mlx5_flow_counter_mng *cmng = &sh->cmng;
7671 struct mlx5_flow_counter_pool *pool;
7674 if (sh->cmng.pending_queries >= MLX5_MAX_PENDING_QUERIES)
7676 rte_spinlock_lock(&cmng->pool_update_sl);
7677 pool = cmng->pools[pool_index];
7678 n_valid = cmng->n_valid;
7679 rte_spinlock_unlock(&cmng->pool_update_sl);
7680 /* Set the statistic memory to the new created pool. */
7681 if ((!pool->raw && mlx5_flow_set_counter_stat_mem(sh, pool)))
7684 /* There is a pool query in progress. */
7687 LIST_FIRST(&sh->cmng.free_stat_raws);
7689 /* No free counter statistics raw memory. */
7692 * Identify the counters released between query trigger and query
7693 * handle more efficiently. The counter released in this gap period
7694 * should wait for a new round of query as the new arrived packets
7695 * will not be taken into account.
7698 ret = mlx5_devx_cmd_flow_counter_query(pool->min_dcs, 0,
7699 MLX5_COUNTERS_PER_POOL,
7701 pool->raw_hw->mem_mng->dm->id,
7705 (uint64_t)(uintptr_t)pool);
7707 DRV_LOG(ERR, "Failed to trigger asynchronous query for dcs ID"
7708 " %d", pool->min_dcs->id);
7709 pool->raw_hw = NULL;
7712 LIST_REMOVE(pool->raw_hw, next);
7713 sh->cmng.pending_queries++;
7715 if (pool_index >= n_valid)
7718 sh->cmng.pool_index = pool_index;
7719 mlx5_set_query_alarm(sh);
7723 * Check and callback event for new aged flow in the counter pool
7726 * Pointer to mlx5_dev_ctx_shared object.
7728 * Pointer to Current counter pool.
7731 mlx5_flow_aging_check(struct mlx5_dev_ctx_shared *sh,
7732 struct mlx5_flow_counter_pool *pool)
7734 struct mlx5_priv *priv;
7735 struct mlx5_flow_counter *cnt;
7736 struct mlx5_age_info *age_info;
7737 struct mlx5_age_param *age_param;
7738 struct mlx5_counter_stats_raw *cur = pool->raw_hw;
7739 struct mlx5_counter_stats_raw *prev = pool->raw;
7740 const uint64_t curr_time = MLX5_CURR_TIME_SEC;
7741 const uint32_t time_delta = curr_time - pool->time_of_last_age_check;
7742 uint16_t expected = AGE_CANDIDATE;
7745 pool->time_of_last_age_check = curr_time;
7746 for (i = 0; i < MLX5_COUNTERS_PER_POOL; ++i) {
7747 cnt = MLX5_POOL_GET_CNT(pool, i);
7748 age_param = MLX5_CNT_TO_AGE(cnt);
7749 if (__atomic_load_n(&age_param->state,
7750 __ATOMIC_RELAXED) != AGE_CANDIDATE)
7752 if (cur->data[i].hits != prev->data[i].hits) {
7753 __atomic_store_n(&age_param->sec_since_last_hit, 0,
7757 if (__atomic_add_fetch(&age_param->sec_since_last_hit,
7759 __ATOMIC_RELAXED) <= age_param->timeout)
7762 * Hold the lock first, or if between the
7763 * state AGE_TMOUT and tailq operation the
7764 * release happened, the release procedure
7765 * may delete a non-existent tailq node.
7767 priv = rte_eth_devices[age_param->port_id].data->dev_private;
7768 age_info = GET_PORT_AGE_INFO(priv);
7769 rte_spinlock_lock(&age_info->aged_sl);
7770 if (__atomic_compare_exchange_n(&age_param->state, &expected,
7773 __ATOMIC_RELAXED)) {
7774 TAILQ_INSERT_TAIL(&age_info->aged_counters, cnt, next);
7775 MLX5_AGE_SET(age_info, MLX5_AGE_EVENT_NEW);
7777 rte_spinlock_unlock(&age_info->aged_sl);
7779 mlx5_age_event_prepare(sh);
7783 * Handler for the HW respond about ready values from an asynchronous batch
7784 * query. This function is probably called by the host thread.
7787 * The pointer to the shared device context.
7788 * @param[in] async_id
7789 * The Devx async ID.
7791 * The status of the completion.
7794 mlx5_flow_async_pool_query_handle(struct mlx5_dev_ctx_shared *sh,
7795 uint64_t async_id, int status)
7797 struct mlx5_flow_counter_pool *pool =
7798 (struct mlx5_flow_counter_pool *)(uintptr_t)async_id;
7799 struct mlx5_counter_stats_raw *raw_to_free;
7800 uint8_t query_gen = pool->query_gen ^ 1;
7801 struct mlx5_flow_counter_mng *cmng = &sh->cmng;
7802 enum mlx5_counter_type cnt_type =
7803 pool->is_aged ? MLX5_COUNTER_TYPE_AGE :
7804 MLX5_COUNTER_TYPE_ORIGIN;
7806 if (unlikely(status)) {
7807 raw_to_free = pool->raw_hw;
7809 raw_to_free = pool->raw;
7811 mlx5_flow_aging_check(sh, pool);
7812 rte_spinlock_lock(&pool->sl);
7813 pool->raw = pool->raw_hw;
7814 rte_spinlock_unlock(&pool->sl);
7815 /* Be sure the new raw counters data is updated in memory. */
7817 if (!TAILQ_EMPTY(&pool->counters[query_gen])) {
7818 rte_spinlock_lock(&cmng->csl[cnt_type]);
7819 TAILQ_CONCAT(&cmng->counters[cnt_type],
7820 &pool->counters[query_gen], next);
7821 rte_spinlock_unlock(&cmng->csl[cnt_type]);
7824 LIST_INSERT_HEAD(&sh->cmng.free_stat_raws, raw_to_free, next);
7825 pool->raw_hw = NULL;
7826 sh->cmng.pending_queries--;
7830 flow_group_to_table(uint32_t port_id, uint32_t group, uint32_t *table,
7831 const struct flow_grp_info *grp_info,
7832 struct rte_flow_error *error)
7834 if (grp_info->transfer && grp_info->external &&
7835 grp_info->fdb_def_rule) {
7836 if (group == UINT32_MAX)
7837 return rte_flow_error_set
7839 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
7841 "group index not supported");
7846 DRV_LOG(DEBUG, "port %u group=%#x table=%#x", port_id, group, *table);
7851 * Translate the rte_flow group index to HW table value.
7853 * If tunnel offload is disabled, all group ids converted to flow table
7854 * id using the standard method.
7855 * If tunnel offload is enabled, group id can be converted using the
7856 * standard or tunnel conversion method. Group conversion method
7857 * selection depends on flags in `grp_info` parameter:
7858 * - Internal (grp_info.external == 0) groups conversion uses the
7860 * - Group ids in JUMP action converted with the tunnel conversion.
7861 * - Group id in rule attribute conversion depends on a rule type and
7863 * ** non zero group attributes converted with the tunnel method
7864 * ** zero group attribute in non-tunnel rule is converted using the
7865 * standard method - there's only one root table
7866 * ** zero group attribute in steer tunnel rule is converted with the
7867 * standard method - single root table
7868 * ** zero group attribute in match tunnel rule is a special OvS
7869 * case: that value is used for portability reasons. That group
7870 * id is converted with the tunnel conversion method.
7875 * PMD tunnel offload object
7877 * rte_flow group index value.
7880 * @param[in] grp_info
7881 * flags used for conversion
7883 * Pointer to error structure.
7886 * 0 on success, a negative errno value otherwise and rte_errno is set.
7889 mlx5_flow_group_to_table(struct rte_eth_dev *dev,
7890 const struct mlx5_flow_tunnel *tunnel,
7891 uint32_t group, uint32_t *table,
7892 const struct flow_grp_info *grp_info,
7893 struct rte_flow_error *error)
7896 bool standard_translation;
7898 if (!grp_info->skip_scale && grp_info->external &&
7899 group < MLX5_MAX_TABLES_EXTERNAL)
7900 group *= MLX5_FLOW_TABLE_FACTOR;
7901 if (is_tunnel_offload_active(dev)) {
7902 standard_translation = !grp_info->external ||
7903 grp_info->std_tbl_fix;
7905 standard_translation = true;
7908 "port %u group=%u transfer=%d external=%d fdb_def_rule=%d translate=%s",
7909 dev->data->port_id, group, grp_info->transfer,
7910 grp_info->external, grp_info->fdb_def_rule,
7911 standard_translation ? "STANDARD" : "TUNNEL");
7912 if (standard_translation)
7913 ret = flow_group_to_table(dev->data->port_id, group, table,
7916 ret = tunnel_flow_group_to_flow_table(dev, tunnel, group,
7923 * Discover availability of metadata reg_c's.
7925 * Iteratively use test flows to check availability.
7928 * Pointer to the Ethernet device structure.
7931 * 0 on success, a negative errno value otherwise and rte_errno is set.
7934 mlx5_flow_discover_mreg_c(struct rte_eth_dev *dev)
7936 struct mlx5_priv *priv = dev->data->dev_private;
7937 struct mlx5_dev_config *config = &priv->config;
7938 enum modify_reg idx;
7941 /* reg_c[0] and reg_c[1] are reserved. */
7942 config->flow_mreg_c[n++] = REG_C_0;
7943 config->flow_mreg_c[n++] = REG_C_1;
7944 /* Discover availability of other reg_c's. */
7945 for (idx = REG_C_2; idx <= REG_C_7; ++idx) {
7946 struct rte_flow_attr attr = {
7947 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
7948 .priority = MLX5_FLOW_LOWEST_PRIO_INDICATOR,
7951 struct rte_flow_item items[] = {
7953 .type = RTE_FLOW_ITEM_TYPE_END,
7956 struct rte_flow_action actions[] = {
7958 .type = (enum rte_flow_action_type)
7959 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
7960 .conf = &(struct mlx5_flow_action_copy_mreg){
7966 .type = RTE_FLOW_ACTION_TYPE_JUMP,
7967 .conf = &(struct rte_flow_action_jump){
7968 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
7972 .type = RTE_FLOW_ACTION_TYPE_END,
7976 struct rte_flow *flow;
7977 struct rte_flow_error error;
7979 if (!config->dv_flow_en)
7981 /* Create internal flow, validation skips copy action. */
7982 flow_idx = flow_list_create(dev, MLX5_FLOW_TYPE_GEN, &attr,
7983 items, actions, false, &error);
7984 flow = mlx5_ipool_get(priv->flows[MLX5_FLOW_TYPE_GEN],
7988 config->flow_mreg_c[n++] = idx;
7989 flow_list_destroy(dev, MLX5_FLOW_TYPE_GEN, flow_idx);
7991 for (; n < MLX5_MREG_C_NUM; ++n)
7992 config->flow_mreg_c[n] = REG_NON;
7997 save_dump_file(const uint8_t *data, uint32_t size,
7998 uint32_t type, uint32_t id, void *arg, FILE *file)
8000 char line[BUF_SIZE];
8003 uint32_t actions_num;
8004 struct rte_flow_query_count *count;
8006 memset(line, 0, BUF_SIZE);
8008 case DR_DUMP_REC_TYPE_PMD_MODIFY_HDR:
8009 actions_num = *(uint32_t *)(arg);
8010 out += snprintf(line + out, BUF_SIZE - out, "%d,0x%x,%d,",
8011 type, id, actions_num);
8013 case DR_DUMP_REC_TYPE_PMD_PKT_REFORMAT:
8014 out += snprintf(line + out, BUF_SIZE - out, "%d,0x%x,",
8017 case DR_DUMP_REC_TYPE_PMD_COUNTER:
8018 count = (struct rte_flow_query_count *)arg;
8019 fprintf(file, "%d,0x%x,%" PRIu64 ",%" PRIu64 "\n", type,
8020 id, count->hits, count->bytes);
8026 for (k = 0; k < size; k++) {
8027 /* Make sure we do not overrun the line buffer length. */
8028 if (out >= BUF_SIZE - 4) {
8032 out += snprintf(line + out, BUF_SIZE - out, "%02x",
8035 fprintf(file, "%s\n", line);
8040 mlx5_flow_query_counter(struct rte_eth_dev *dev, struct rte_flow *flow,
8041 struct rte_flow_query_count *count, struct rte_flow_error *error)
8043 struct rte_flow_action action[2];
8044 enum mlx5_flow_drv_type ftype;
8045 const struct mlx5_flow_driver_ops *fops;
8048 return rte_flow_error_set(error, ENOENT,
8049 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8051 "invalid flow handle");
8053 action[0].type = RTE_FLOW_ACTION_TYPE_COUNT;
8054 action[1].type = RTE_FLOW_ACTION_TYPE_END;
8055 if (flow->counter) {
8056 memset(count, 0, sizeof(struct rte_flow_query_count));
8057 ftype = (enum mlx5_flow_drv_type)(flow->drv_type);
8058 MLX5_ASSERT(ftype > MLX5_FLOW_TYPE_MIN &&
8059 ftype < MLX5_FLOW_TYPE_MAX);
8060 fops = flow_get_drv_ops(ftype);
8061 return fops->query(dev, flow, action, count, error);
8066 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
8068 * Dump flow ipool data to file
8071 * The pointer to Ethernet device.
8073 * A pointer to a file for output.
8075 * Perform verbose error reporting if not NULL. PMDs initialize this
8076 * structure in case of error only.
8078 * 0 on success, a negative value otherwise.
8081 mlx5_flow_dev_dump_ipool(struct rte_eth_dev *dev,
8082 struct rte_flow *flow, FILE *file,
8083 struct rte_flow_error *error)
8085 struct mlx5_priv *priv = dev->data->dev_private;
8086 struct mlx5_flow_dv_modify_hdr_resource *modify_hdr;
8087 struct mlx5_flow_dv_encap_decap_resource *encap_decap;
8088 uint32_t handle_idx;
8089 struct mlx5_flow_handle *dh;
8090 struct rte_flow_query_count count;
8091 uint32_t actions_num;
8092 const uint8_t *data;
8098 return rte_flow_error_set(error, ENOENT,
8099 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8101 "invalid flow handle");
8103 handle_idx = flow->dev_handles;
8104 while (handle_idx) {
8105 dh = mlx5_ipool_get(priv->sh->ipool
8106 [MLX5_IPOOL_MLX5_FLOW], handle_idx);
8109 handle_idx = dh->next.next;
8110 id = (uint32_t)(uintptr_t)dh->drv_flow;
8113 type = DR_DUMP_REC_TYPE_PMD_COUNTER;
8114 if (!mlx5_flow_query_counter(dev, flow, &count, error))
8115 save_dump_file(NULL, 0, type,
8116 id, (void *)&count, file);
8118 /* Get modify_hdr and encap_decap buf from ipools. */
8120 modify_hdr = dh->dvh.modify_hdr;
8122 if (dh->dvh.rix_encap_decap) {
8123 encap_decap = mlx5_ipool_get(priv->sh->ipool
8124 [MLX5_IPOOL_DECAP_ENCAP],
8125 dh->dvh.rix_encap_decap);
8128 data = (const uint8_t *)modify_hdr->actions;
8129 size = (size_t)(modify_hdr->actions_num) * 8;
8130 actions_num = modify_hdr->actions_num;
8131 type = DR_DUMP_REC_TYPE_PMD_MODIFY_HDR;
8132 save_dump_file(data, size, type, id,
8133 (void *)(&actions_num), file);
8136 data = encap_decap->buf;
8137 size = encap_decap->size;
8138 type = DR_DUMP_REC_TYPE_PMD_PKT_REFORMAT;
8139 save_dump_file(data, size, type,
8148 * Dump flow raw hw data to file
8151 * The pointer to Ethernet device.
8153 * A pointer to a file for output.
8155 * Perform verbose error reporting if not NULL. PMDs initialize this
8156 * structure in case of error only.
8158 * 0 on success, a nagative value otherwise.
8161 mlx5_flow_dev_dump(struct rte_eth_dev *dev, struct rte_flow *flow_idx,
8163 struct rte_flow_error *error __rte_unused)
8165 struct mlx5_priv *priv = dev->data->dev_private;
8166 struct mlx5_dev_ctx_shared *sh = priv->sh;
8167 uint32_t handle_idx;
8169 struct mlx5_flow_handle *dh;
8170 struct rte_flow *flow;
8171 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
8175 if (!priv->config.dv_flow_en) {
8176 if (fputs("device dv flow disabled\n", file) <= 0)
8183 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
8184 MLX5_IPOOL_FOREACH(priv->flows[MLX5_FLOW_TYPE_GEN], idx, flow)
8185 mlx5_flow_dev_dump_ipool(dev, flow, file, error);
8187 return mlx5_devx_cmd_flow_dump(sh->fdb_domain,
8189 sh->tx_domain, file);
8192 flow = mlx5_ipool_get(priv->flows[MLX5_FLOW_TYPE_GEN],
8193 (uintptr_t)(void *)flow_idx);
8197 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
8198 mlx5_flow_dev_dump_ipool(dev, flow, file, error);
8200 handle_idx = flow->dev_handles;
8201 while (handle_idx) {
8202 dh = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
8207 ret = mlx5_devx_cmd_flow_single_dump(dh->drv_flow,
8212 handle_idx = dh->next.next;
8218 * Get aged-out flows.
8221 * Pointer to the Ethernet device structure.
8222 * @param[in] context
8223 * The address of an array of pointers to the aged-out flows contexts.
8224 * @param[in] nb_countexts
8225 * The length of context array pointers.
8227 * Perform verbose error reporting if not NULL. Initialized in case of
8231 * how many contexts get in success, otherwise negative errno value.
8232 * if nb_contexts is 0, return the amount of all aged contexts.
8233 * if nb_contexts is not 0 , return the amount of aged flows reported
8234 * in the context array.
8237 mlx5_flow_get_aged_flows(struct rte_eth_dev *dev, void **contexts,
8238 uint32_t nb_contexts, struct rte_flow_error *error)
8240 const struct mlx5_flow_driver_ops *fops;
8241 struct rte_flow_attr attr = { .transfer = 0 };
8243 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
8244 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
8245 return fops->get_aged_flows(dev, contexts, nb_contexts,
8249 "port %u get aged flows is not supported.",
8250 dev->data->port_id);
8254 /* Wrapper for driver action_validate op callback */
8256 flow_drv_action_validate(struct rte_eth_dev *dev,
8257 const struct rte_flow_indir_action_conf *conf,
8258 const struct rte_flow_action *action,
8259 const struct mlx5_flow_driver_ops *fops,
8260 struct rte_flow_error *error)
8262 static const char err_msg[] = "indirect action validation unsupported";
8264 if (!fops->action_validate) {
8265 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
8266 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
8270 return fops->action_validate(dev, conf, action, error);
8274 * Destroys the shared action by handle.
8277 * Pointer to Ethernet device structure.
8279 * Handle for the indirect action object to be destroyed.
8281 * Perform verbose error reporting if not NULL. PMDs initialize this
8282 * structure in case of error only.
8285 * 0 on success, a negative errno value otherwise and rte_errno is set.
8287 * @note: wrapper for driver action_create op callback.
8290 mlx5_action_handle_destroy(struct rte_eth_dev *dev,
8291 struct rte_flow_action_handle *handle,
8292 struct rte_flow_error *error)
8294 static const char err_msg[] = "indirect action destruction unsupported";
8295 struct rte_flow_attr attr = { .transfer = 0 };
8296 const struct mlx5_flow_driver_ops *fops =
8297 flow_get_drv_ops(flow_get_drv_type(dev, &attr));
8299 if (!fops->action_destroy) {
8300 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
8301 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
8305 return fops->action_destroy(dev, handle, error);
8308 /* Wrapper for driver action_destroy op callback */
8310 flow_drv_action_update(struct rte_eth_dev *dev,
8311 struct rte_flow_action_handle *handle,
8313 const struct mlx5_flow_driver_ops *fops,
8314 struct rte_flow_error *error)
8316 static const char err_msg[] = "indirect action update unsupported";
8318 if (!fops->action_update) {
8319 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
8320 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
8324 return fops->action_update(dev, handle, update, error);
8327 /* Wrapper for driver action_destroy op callback */
8329 flow_drv_action_query(struct rte_eth_dev *dev,
8330 const struct rte_flow_action_handle *handle,
8332 const struct mlx5_flow_driver_ops *fops,
8333 struct rte_flow_error *error)
8335 static const char err_msg[] = "indirect action query unsupported";
8337 if (!fops->action_query) {
8338 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
8339 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
8343 return fops->action_query(dev, handle, data, error);
8347 * Create indirect action for reuse in multiple flow rules.
8350 * Pointer to Ethernet device structure.
8352 * Pointer to indirect action object configuration.
8354 * Action configuration for indirect action object creation.
8356 * Perform verbose error reporting if not NULL. PMDs initialize this
8357 * structure in case of error only.
8359 * A valid handle in case of success, NULL otherwise and rte_errno is set.
8361 static struct rte_flow_action_handle *
8362 mlx5_action_handle_create(struct rte_eth_dev *dev,
8363 const struct rte_flow_indir_action_conf *conf,
8364 const struct rte_flow_action *action,
8365 struct rte_flow_error *error)
8367 static const char err_msg[] = "indirect action creation unsupported";
8368 struct rte_flow_attr attr = { .transfer = 0 };
8369 const struct mlx5_flow_driver_ops *fops =
8370 flow_get_drv_ops(flow_get_drv_type(dev, &attr));
8372 if (flow_drv_action_validate(dev, conf, action, fops, error))
8374 if (!fops->action_create) {
8375 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
8376 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
8380 return fops->action_create(dev, conf, action, error);
8384 * Updates inplace the indirect action configuration pointed by *handle*
8385 * with the configuration provided as *update* argument.
8386 * The update of the indirect action configuration effects all flow rules
8387 * reusing the action via handle.
8390 * Pointer to Ethernet device structure.
8392 * Handle for the indirect action to be updated.
8394 * Action specification used to modify the action pointed by handle.
8395 * *update* could be of same type with the action pointed by the *handle*
8396 * handle argument, or some other structures like a wrapper, depending on
8397 * the indirect action type.
8399 * Perform verbose error reporting if not NULL. PMDs initialize this
8400 * structure in case of error only.
8403 * 0 on success, a negative errno value otherwise and rte_errno is set.
8406 mlx5_action_handle_update(struct rte_eth_dev *dev,
8407 struct rte_flow_action_handle *handle,
8409 struct rte_flow_error *error)
8411 struct rte_flow_attr attr = { .transfer = 0 };
8412 const struct mlx5_flow_driver_ops *fops =
8413 flow_get_drv_ops(flow_get_drv_type(dev, &attr));
8416 ret = flow_drv_action_validate(dev, NULL,
8417 (const struct rte_flow_action *)update, fops, error);
8420 return flow_drv_action_update(dev, handle, update, fops,
8425 * Query the indirect action by handle.
8427 * This function allows retrieving action-specific data such as counters.
8428 * Data is gathered by special action which may be present/referenced in
8429 * more than one flow rule definition.
8431 * see @RTE_FLOW_ACTION_TYPE_COUNT
8434 * Pointer to Ethernet device structure.
8436 * Handle for the indirect action to query.
8437 * @param[in, out] data
8438 * Pointer to storage for the associated query data type.
8440 * Perform verbose error reporting if not NULL. PMDs initialize this
8441 * structure in case of error only.
8444 * 0 on success, a negative errno value otherwise and rte_errno is set.
8447 mlx5_action_handle_query(struct rte_eth_dev *dev,
8448 const struct rte_flow_action_handle *handle,
8450 struct rte_flow_error *error)
8452 struct rte_flow_attr attr = { .transfer = 0 };
8453 const struct mlx5_flow_driver_ops *fops =
8454 flow_get_drv_ops(flow_get_drv_type(dev, &attr));
8456 return flow_drv_action_query(dev, handle, data, fops, error);
8460 * Destroy all indirect actions (shared RSS).
8463 * Pointer to Ethernet device.
8466 * 0 on success, a negative errno value otherwise and rte_errno is set.
8469 mlx5_action_handle_flush(struct rte_eth_dev *dev)
8471 struct rte_flow_error error;
8472 struct mlx5_priv *priv = dev->data->dev_private;
8473 struct mlx5_shared_action_rss *shared_rss;
8477 ILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
8478 priv->rss_shared_actions, idx, shared_rss, next) {
8479 ret |= mlx5_action_handle_destroy(dev,
8480 (struct rte_flow_action_handle *)(uintptr_t)idx, &error);
8485 #ifndef HAVE_MLX5DV_DR
8486 #define MLX5_DOMAIN_SYNC_FLOW ((1 << 0) | (1 << 1))
8488 #define MLX5_DOMAIN_SYNC_FLOW \
8489 (MLX5DV_DR_DOMAIN_SYNC_FLAGS_SW | MLX5DV_DR_DOMAIN_SYNC_FLAGS_HW)
8492 int rte_pmd_mlx5_sync_flow(uint16_t port_id, uint32_t domains)
8494 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
8495 const struct mlx5_flow_driver_ops *fops;
8497 struct rte_flow_attr attr = { .transfer = 0 };
8499 fops = flow_get_drv_ops(flow_get_drv_type(dev, &attr));
8500 ret = fops->sync_domain(dev, domains, MLX5_DOMAIN_SYNC_FLOW);
8506 const struct mlx5_flow_tunnel *
8507 mlx5_get_tof(const struct rte_flow_item *item,
8508 const struct rte_flow_action *action,
8509 enum mlx5_tof_rule_type *rule_type)
8511 for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
8512 if (item->type == (typeof(item->type))
8513 MLX5_RTE_FLOW_ITEM_TYPE_TUNNEL) {
8514 *rule_type = MLX5_TUNNEL_OFFLOAD_MATCH_RULE;
8515 return flow_items_to_tunnel(item);
8518 for (; action->conf != RTE_FLOW_ACTION_TYPE_END; action++) {
8519 if (action->type == (typeof(action->type))
8520 MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET) {
8521 *rule_type = MLX5_TUNNEL_OFFLOAD_SET_RULE;
8522 return flow_actions_to_tunnel(action);
8529 * tunnel offload functionalilty is defined for DV environment only
8531 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
8533 union tunnel_offload_mark {
8536 uint32_t app_reserve:8;
8537 uint32_t table_id:15;
8538 uint32_t transfer:1;
8539 uint32_t _unused_:8;
8544 mlx5_access_tunnel_offload_db
8545 (struct rte_eth_dev *dev,
8546 bool (*match)(struct rte_eth_dev *,
8547 struct mlx5_flow_tunnel *, const void *),
8548 void (*hit)(struct rte_eth_dev *, struct mlx5_flow_tunnel *, void *),
8549 void (*miss)(struct rte_eth_dev *, void *),
8550 void *ctx, bool lock_op);
8553 flow_tunnel_add_default_miss(struct rte_eth_dev *dev,
8554 struct rte_flow *flow,
8555 const struct rte_flow_attr *attr,
8556 const struct rte_flow_action *app_actions,
8558 const struct mlx5_flow_tunnel *tunnel,
8559 struct tunnel_default_miss_ctx *ctx,
8560 struct rte_flow_error *error)
8562 struct mlx5_priv *priv = dev->data->dev_private;
8563 struct mlx5_flow *dev_flow;
8564 struct rte_flow_attr miss_attr = *attr;
8565 const struct rte_flow_item miss_items[2] = {
8567 .type = RTE_FLOW_ITEM_TYPE_ETH,
8573 .type = RTE_FLOW_ITEM_TYPE_END,
8579 union tunnel_offload_mark mark_id;
8580 struct rte_flow_action_mark miss_mark;
8581 struct rte_flow_action miss_actions[3] = {
8582 [0] = { .type = RTE_FLOW_ACTION_TYPE_MARK, .conf = &miss_mark },
8583 [2] = { .type = RTE_FLOW_ACTION_TYPE_END, .conf = NULL }
8585 const struct rte_flow_action_jump *jump_data;
8586 uint32_t i, flow_table = 0; /* prevent compilation warning */
8587 struct flow_grp_info grp_info = {
8589 .transfer = attr->transfer,
8590 .fdb_def_rule = !!priv->fdb_def_rule,
8595 if (!attr->transfer) {
8598 miss_actions[1].type = RTE_FLOW_ACTION_TYPE_RSS;
8599 q_size = priv->reta_idx_n * sizeof(ctx->queue[0]);
8600 ctx->queue = mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO, q_size,
8603 return rte_flow_error_set
8605 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
8606 NULL, "invalid default miss RSS");
8607 ctx->action_rss.func = RTE_ETH_HASH_FUNCTION_DEFAULT,
8608 ctx->action_rss.level = 0,
8609 ctx->action_rss.types = priv->rss_conf.rss_hf,
8610 ctx->action_rss.key_len = priv->rss_conf.rss_key_len,
8611 ctx->action_rss.queue_num = priv->reta_idx_n,
8612 ctx->action_rss.key = priv->rss_conf.rss_key,
8613 ctx->action_rss.queue = ctx->queue;
8614 if (!priv->reta_idx_n || !priv->rxqs_n)
8615 return rte_flow_error_set
8617 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
8618 NULL, "invalid port configuration");
8619 if (!(dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG))
8620 ctx->action_rss.types = 0;
8621 for (i = 0; i != priv->reta_idx_n; ++i)
8622 ctx->queue[i] = (*priv->reta_idx)[i];
8624 miss_actions[1].type = RTE_FLOW_ACTION_TYPE_JUMP;
8625 ctx->miss_jump.group = MLX5_TNL_MISS_FDB_JUMP_GRP;
8627 miss_actions[1].conf = (typeof(miss_actions[1].conf))ctx->raw;
8628 for (; app_actions->type != RTE_FLOW_ACTION_TYPE_JUMP; app_actions++);
8629 jump_data = app_actions->conf;
8630 miss_attr.priority = MLX5_TNL_MISS_RULE_PRIORITY;
8631 miss_attr.group = jump_data->group;
8632 ret = mlx5_flow_group_to_table(dev, tunnel, jump_data->group,
8633 &flow_table, &grp_info, error);
8635 return rte_flow_error_set(error, EINVAL,
8636 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
8637 NULL, "invalid tunnel id");
8638 mark_id.app_reserve = 0;
8639 mark_id.table_id = tunnel_flow_tbl_to_id(flow_table);
8640 mark_id.transfer = !!attr->transfer;
8641 mark_id._unused_ = 0;
8642 miss_mark.id = mark_id.val;
8643 dev_flow = flow_drv_prepare(dev, flow, &miss_attr,
8644 miss_items, miss_actions, flow_idx, error);
8647 dev_flow->flow = flow;
8648 dev_flow->external = true;
8649 dev_flow->tunnel = tunnel;
8650 dev_flow->tof_type = MLX5_TUNNEL_OFFLOAD_MISS_RULE;
8651 /* Subflow object was created, we must include one in the list. */
8652 SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
8653 dev_flow->handle, next);
8655 "port %u tunnel type=%d id=%u miss rule priority=%u group=%u",
8656 dev->data->port_id, tunnel->app_tunnel.type,
8657 tunnel->tunnel_id, miss_attr.priority, miss_attr.group);
8658 ret = flow_drv_translate(dev, dev_flow, &miss_attr, miss_items,
8659 miss_actions, error);
8661 ret = flow_mreg_update_copy_table(dev, flow, miss_actions,
8667 static const struct mlx5_flow_tbl_data_entry *
8668 tunnel_mark_decode(struct rte_eth_dev *dev, uint32_t mark)
8670 struct mlx5_priv *priv = dev->data->dev_private;
8671 struct mlx5_dev_ctx_shared *sh = priv->sh;
8672 struct mlx5_list_entry *he;
8673 union tunnel_offload_mark mbits = { .val = mark };
8674 union mlx5_flow_tbl_key table_key = {
8676 .level = tunnel_id_to_flow_tbl(mbits.table_id),
8680 .is_fdb = !!mbits.transfer,
8684 struct mlx5_flow_cb_ctx ctx = {
8685 .data = &table_key.v64,
8688 he = mlx5_hlist_lookup(sh->flow_tbls, table_key.v64, &ctx);
8690 container_of(he, struct mlx5_flow_tbl_data_entry, entry) : NULL;
8694 mlx5_flow_tunnel_grp2tbl_remove_cb(void *tool_ctx,
8695 struct mlx5_list_entry *entry)
8697 struct mlx5_dev_ctx_shared *sh = tool_ctx;
8698 struct tunnel_tbl_entry *tte = container_of(entry, typeof(*tte), hash);
8700 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TNL_TBL_ID],
8701 tunnel_flow_tbl_to_id(tte->flow_table));
8706 mlx5_flow_tunnel_grp2tbl_match_cb(void *tool_ctx __rte_unused,
8707 struct mlx5_list_entry *entry, void *cb_ctx)
8709 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
8710 union tunnel_tbl_key tbl = {
8711 .val = *(uint64_t *)(ctx->data),
8713 struct tunnel_tbl_entry *tte = container_of(entry, typeof(*tte), hash);
8715 return tbl.tunnel_id != tte->tunnel_id || tbl.group != tte->group;
8718 static struct mlx5_list_entry *
8719 mlx5_flow_tunnel_grp2tbl_create_cb(void *tool_ctx, void *cb_ctx)
8721 struct mlx5_dev_ctx_shared *sh = tool_ctx;
8722 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
8723 struct tunnel_tbl_entry *tte;
8724 union tunnel_tbl_key tbl = {
8725 .val = *(uint64_t *)(ctx->data),
8728 tte = mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO,
8733 mlx5_ipool_malloc(sh->ipool[MLX5_IPOOL_TNL_TBL_ID],
8735 if (tte->flow_table >= MLX5_MAX_TABLES) {
8736 DRV_LOG(ERR, "Tunnel TBL ID %d exceed max limit.",
8738 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TNL_TBL_ID],
8741 } else if (!tte->flow_table) {
8744 tte->flow_table = tunnel_id_to_flow_tbl(tte->flow_table);
8745 tte->tunnel_id = tbl.tunnel_id;
8746 tte->group = tbl.group;
8754 static struct mlx5_list_entry *
8755 mlx5_flow_tunnel_grp2tbl_clone_cb(void *tool_ctx __rte_unused,
8756 struct mlx5_list_entry *oentry,
8757 void *cb_ctx __rte_unused)
8759 struct tunnel_tbl_entry *tte = mlx5_malloc(MLX5_MEM_SYS, sizeof(*tte),
8764 memcpy(tte, oentry, sizeof(*tte));
8769 mlx5_flow_tunnel_grp2tbl_clone_free_cb(void *tool_ctx __rte_unused,
8770 struct mlx5_list_entry *entry)
8772 struct tunnel_tbl_entry *tte = container_of(entry, typeof(*tte), hash);
8778 tunnel_flow_group_to_flow_table(struct rte_eth_dev *dev,
8779 const struct mlx5_flow_tunnel *tunnel,
8780 uint32_t group, uint32_t *table,
8781 struct rte_flow_error *error)
8783 struct mlx5_list_entry *he;
8784 struct tunnel_tbl_entry *tte;
8785 union tunnel_tbl_key key = {
8786 .tunnel_id = tunnel ? tunnel->tunnel_id : 0,
8789 struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
8790 struct mlx5_hlist *group_hash;
8791 struct mlx5_flow_cb_ctx ctx = {
8795 group_hash = tunnel ? tunnel->groups : thub->groups;
8796 he = mlx5_hlist_register(group_hash, key.val, &ctx);
8798 return rte_flow_error_set(error, EINVAL,
8799 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
8801 "tunnel group index not supported");
8802 tte = container_of(he, typeof(*tte), hash);
8803 *table = tte->flow_table;
8804 DRV_LOG(DEBUG, "port %u tunnel %u group=%#x table=%#x",
8805 dev->data->port_id, key.tunnel_id, group, *table);
8810 mlx5_flow_tunnel_free(struct rte_eth_dev *dev,
8811 struct mlx5_flow_tunnel *tunnel)
8813 struct mlx5_priv *priv = dev->data->dev_private;
8814 struct mlx5_indexed_pool *ipool;
8816 DRV_LOG(DEBUG, "port %u release pmd tunnel id=0x%x",
8817 dev->data->port_id, tunnel->tunnel_id);
8818 LIST_REMOVE(tunnel, chain);
8819 mlx5_hlist_destroy(tunnel->groups);
8820 ipool = priv->sh->ipool[MLX5_IPOOL_TUNNEL_ID];
8821 mlx5_ipool_free(ipool, tunnel->tunnel_id);
8825 mlx5_access_tunnel_offload_db
8826 (struct rte_eth_dev *dev,
8827 bool (*match)(struct rte_eth_dev *,
8828 struct mlx5_flow_tunnel *, const void *),
8829 void (*hit)(struct rte_eth_dev *, struct mlx5_flow_tunnel *, void *),
8830 void (*miss)(struct rte_eth_dev *, void *),
8831 void *ctx, bool lock_op)
8833 bool verdict = false;
8834 struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
8835 struct mlx5_flow_tunnel *tunnel;
8837 rte_spinlock_lock(&thub->sl);
8838 LIST_FOREACH(tunnel, &thub->tunnels, chain) {
8839 verdict = match(dev, tunnel, (const void *)ctx);
8844 rte_spinlock_unlock(&thub->sl);
8846 hit(dev, tunnel, ctx);
8847 if (!verdict && miss)
8850 rte_spinlock_unlock(&thub->sl);
8855 struct tunnel_db_find_tunnel_id_ctx {
8857 struct mlx5_flow_tunnel *tunnel;
8861 find_tunnel_id_match(struct rte_eth_dev *dev,
8862 struct mlx5_flow_tunnel *tunnel, const void *x)
8864 const struct tunnel_db_find_tunnel_id_ctx *ctx = x;
8867 return tunnel->tunnel_id == ctx->tunnel_id;
8871 find_tunnel_id_hit(struct rte_eth_dev *dev,
8872 struct mlx5_flow_tunnel *tunnel, void *x)
8874 struct tunnel_db_find_tunnel_id_ctx *ctx = x;
8876 ctx->tunnel = tunnel;
8879 static struct mlx5_flow_tunnel *
8880 mlx5_find_tunnel_id(struct rte_eth_dev *dev, uint32_t id)
8882 struct tunnel_db_find_tunnel_id_ctx ctx = {
8886 mlx5_access_tunnel_offload_db(dev, find_tunnel_id_match,
8887 find_tunnel_id_hit, NULL, &ctx, true);
8892 static struct mlx5_flow_tunnel *
8893 mlx5_flow_tunnel_allocate(struct rte_eth_dev *dev,
8894 const struct rte_flow_tunnel *app_tunnel)
8896 struct mlx5_priv *priv = dev->data->dev_private;
8897 struct mlx5_indexed_pool *ipool;
8898 struct mlx5_flow_tunnel *tunnel;
8901 ipool = priv->sh->ipool[MLX5_IPOOL_TUNNEL_ID];
8902 tunnel = mlx5_ipool_zmalloc(ipool, &id);
8905 if (id >= MLX5_MAX_TUNNELS) {
8906 mlx5_ipool_free(ipool, id);
8907 DRV_LOG(ERR, "Tunnel ID %d exceed max limit.", id);
8910 tunnel->groups = mlx5_hlist_create("tunnel groups", 64, false, true,
8912 mlx5_flow_tunnel_grp2tbl_create_cb,
8913 mlx5_flow_tunnel_grp2tbl_match_cb,
8914 mlx5_flow_tunnel_grp2tbl_remove_cb,
8915 mlx5_flow_tunnel_grp2tbl_clone_cb,
8916 mlx5_flow_tunnel_grp2tbl_clone_free_cb);
8917 if (!tunnel->groups) {
8918 mlx5_ipool_free(ipool, id);
8921 /* initiate new PMD tunnel */
8922 memcpy(&tunnel->app_tunnel, app_tunnel, sizeof(*app_tunnel));
8923 tunnel->tunnel_id = id;
8924 tunnel->action.type = (typeof(tunnel->action.type))
8925 MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET;
8926 tunnel->action.conf = tunnel;
8927 tunnel->item.type = (typeof(tunnel->item.type))
8928 MLX5_RTE_FLOW_ITEM_TYPE_TUNNEL;
8929 tunnel->item.spec = tunnel;
8930 tunnel->item.last = NULL;
8931 tunnel->item.mask = NULL;
8933 DRV_LOG(DEBUG, "port %u new pmd tunnel id=0x%x",
8934 dev->data->port_id, tunnel->tunnel_id);
8939 struct tunnel_db_get_tunnel_ctx {
8940 const struct rte_flow_tunnel *app_tunnel;
8941 struct mlx5_flow_tunnel *tunnel;
8944 static bool get_tunnel_match(struct rte_eth_dev *dev,
8945 struct mlx5_flow_tunnel *tunnel, const void *x)
8947 const struct tunnel_db_get_tunnel_ctx *ctx = x;
8950 return !memcmp(ctx->app_tunnel, &tunnel->app_tunnel,
8951 sizeof(*ctx->app_tunnel));
8954 static void get_tunnel_hit(struct rte_eth_dev *dev,
8955 struct mlx5_flow_tunnel *tunnel, void *x)
8957 /* called under tunnel spinlock protection */
8958 struct tunnel_db_get_tunnel_ctx *ctx = x;
8962 ctx->tunnel = tunnel;
8965 static void get_tunnel_miss(struct rte_eth_dev *dev, void *x)
8967 /* called under tunnel spinlock protection */
8968 struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
8969 struct tunnel_db_get_tunnel_ctx *ctx = x;
8971 rte_spinlock_unlock(&thub->sl);
8972 ctx->tunnel = mlx5_flow_tunnel_allocate(dev, ctx->app_tunnel);
8973 rte_spinlock_lock(&thub->sl);
8975 ctx->tunnel->refctn = 1;
8976 LIST_INSERT_HEAD(&thub->tunnels, ctx->tunnel, chain);
8982 mlx5_get_flow_tunnel(struct rte_eth_dev *dev,
8983 const struct rte_flow_tunnel *app_tunnel,
8984 struct mlx5_flow_tunnel **tunnel)
8986 struct tunnel_db_get_tunnel_ctx ctx = {
8987 .app_tunnel = app_tunnel,
8990 mlx5_access_tunnel_offload_db(dev, get_tunnel_match, get_tunnel_hit,
8991 get_tunnel_miss, &ctx, true);
8992 *tunnel = ctx.tunnel;
8993 return ctx.tunnel ? 0 : -ENOMEM;
8996 void mlx5_release_tunnel_hub(struct mlx5_dev_ctx_shared *sh, uint16_t port_id)
8998 struct mlx5_flow_tunnel_hub *thub = sh->tunnel_hub;
9002 if (!LIST_EMPTY(&thub->tunnels))
9003 DRV_LOG(WARNING, "port %u tunnels present", port_id);
9004 mlx5_hlist_destroy(thub->groups);
9008 int mlx5_alloc_tunnel_hub(struct mlx5_dev_ctx_shared *sh)
9011 struct mlx5_flow_tunnel_hub *thub;
9013 thub = mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO, sizeof(*thub),
9017 LIST_INIT(&thub->tunnels);
9018 rte_spinlock_init(&thub->sl);
9019 thub->groups = mlx5_hlist_create("flow groups", 64,
9021 mlx5_flow_tunnel_grp2tbl_create_cb,
9022 mlx5_flow_tunnel_grp2tbl_match_cb,
9023 mlx5_flow_tunnel_grp2tbl_remove_cb,
9024 mlx5_flow_tunnel_grp2tbl_clone_cb,
9025 mlx5_flow_tunnel_grp2tbl_clone_free_cb);
9026 if (!thub->groups) {
9030 sh->tunnel_hub = thub;
9036 mlx5_hlist_destroy(thub->groups);
9043 mlx5_flow_tunnel_validate(struct rte_eth_dev *dev,
9044 struct rte_flow_tunnel *tunnel,
9045 const char *err_msg)
9048 if (!is_tunnel_offload_active(dev)) {
9049 err_msg = "tunnel offload was not activated";
9051 } else if (!tunnel) {
9052 err_msg = "no application tunnel";
9056 switch (tunnel->type) {
9058 err_msg = "unsupported tunnel type";
9060 case RTE_FLOW_ITEM_TYPE_VXLAN:
9069 mlx5_flow_tunnel_decap_set(struct rte_eth_dev *dev,
9070 struct rte_flow_tunnel *app_tunnel,
9071 struct rte_flow_action **actions,
9072 uint32_t *num_of_actions,
9073 struct rte_flow_error *error)
9076 struct mlx5_flow_tunnel *tunnel;
9077 const char *err_msg = NULL;
9078 bool verdict = mlx5_flow_tunnel_validate(dev, app_tunnel, err_msg);
9081 return rte_flow_error_set(error, EINVAL,
9082 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
9084 ret = mlx5_get_flow_tunnel(dev, app_tunnel, &tunnel);
9086 return rte_flow_error_set(error, ret,
9087 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
9088 "failed to initialize pmd tunnel");
9090 *actions = &tunnel->action;
9091 *num_of_actions = 1;
9096 mlx5_flow_tunnel_match(struct rte_eth_dev *dev,
9097 struct rte_flow_tunnel *app_tunnel,
9098 struct rte_flow_item **items,
9099 uint32_t *num_of_items,
9100 struct rte_flow_error *error)
9103 struct mlx5_flow_tunnel *tunnel;
9104 const char *err_msg = NULL;
9105 bool verdict = mlx5_flow_tunnel_validate(dev, app_tunnel, err_msg);
9108 return rte_flow_error_set(error, EINVAL,
9109 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
9111 ret = mlx5_get_flow_tunnel(dev, app_tunnel, &tunnel);
9113 return rte_flow_error_set(error, ret,
9114 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
9115 "failed to initialize pmd tunnel");
9117 *items = &tunnel->item;
9122 struct tunnel_db_element_release_ctx {
9123 struct rte_flow_item *items;
9124 struct rte_flow_action *actions;
9125 uint32_t num_elements;
9126 struct rte_flow_error *error;
9131 tunnel_element_release_match(struct rte_eth_dev *dev,
9132 struct mlx5_flow_tunnel *tunnel, const void *x)
9134 const struct tunnel_db_element_release_ctx *ctx = x;
9137 if (ctx->num_elements != 1)
9139 else if (ctx->items)
9140 return ctx->items == &tunnel->item;
9141 else if (ctx->actions)
9142 return ctx->actions == &tunnel->action;
9148 tunnel_element_release_hit(struct rte_eth_dev *dev,
9149 struct mlx5_flow_tunnel *tunnel, void *x)
9151 struct tunnel_db_element_release_ctx *ctx = x;
9153 if (!__atomic_sub_fetch(&tunnel->refctn, 1, __ATOMIC_RELAXED))
9154 mlx5_flow_tunnel_free(dev, tunnel);
9158 tunnel_element_release_miss(struct rte_eth_dev *dev, void *x)
9160 struct tunnel_db_element_release_ctx *ctx = x;
9162 ctx->ret = rte_flow_error_set(ctx->error, EINVAL,
9163 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
9164 "invalid argument");
9168 mlx5_flow_tunnel_item_release(struct rte_eth_dev *dev,
9169 struct rte_flow_item *pmd_items,
9170 uint32_t num_items, struct rte_flow_error *err)
9172 struct tunnel_db_element_release_ctx ctx = {
9175 .num_elements = num_items,
9179 mlx5_access_tunnel_offload_db(dev, tunnel_element_release_match,
9180 tunnel_element_release_hit,
9181 tunnel_element_release_miss, &ctx, false);
9187 mlx5_flow_tunnel_action_release(struct rte_eth_dev *dev,
9188 struct rte_flow_action *pmd_actions,
9189 uint32_t num_actions, struct rte_flow_error *err)
9191 struct tunnel_db_element_release_ctx ctx = {
9193 .actions = pmd_actions,
9194 .num_elements = num_actions,
9198 mlx5_access_tunnel_offload_db(dev, tunnel_element_release_match,
9199 tunnel_element_release_hit,
9200 tunnel_element_release_miss, &ctx, false);
9206 mlx5_flow_tunnel_get_restore_info(struct rte_eth_dev *dev,
9208 struct rte_flow_restore_info *info,
9209 struct rte_flow_error *err)
9211 uint64_t ol_flags = m->ol_flags;
9212 const struct mlx5_flow_tbl_data_entry *tble;
9213 const uint64_t mask = PKT_RX_FDIR | PKT_RX_FDIR_ID;
9215 if (!is_tunnel_offload_active(dev)) {
9220 if ((ol_flags & mask) != mask)
9222 tble = tunnel_mark_decode(dev, m->hash.fdir.hi);
9224 DRV_LOG(DEBUG, "port %u invalid miss tunnel mark %#x",
9225 dev->data->port_id, m->hash.fdir.hi);
9228 MLX5_ASSERT(tble->tunnel);
9229 memcpy(&info->tunnel, &tble->tunnel->app_tunnel, sizeof(info->tunnel));
9230 info->group_id = tble->group_id;
9231 info->flags = RTE_FLOW_RESTORE_INFO_TUNNEL |
9232 RTE_FLOW_RESTORE_INFO_GROUP_ID |
9233 RTE_FLOW_RESTORE_INFO_ENCAPSULATED;
9238 return rte_flow_error_set(err, EINVAL,
9239 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
9240 "failed to get restore info");
9243 #else /* HAVE_IBV_FLOW_DV_SUPPORT */
9245 mlx5_flow_tunnel_decap_set(__rte_unused struct rte_eth_dev *dev,
9246 __rte_unused struct rte_flow_tunnel *app_tunnel,
9247 __rte_unused struct rte_flow_action **actions,
9248 __rte_unused uint32_t *num_of_actions,
9249 __rte_unused struct rte_flow_error *error)
9255 mlx5_flow_tunnel_match(__rte_unused struct rte_eth_dev *dev,
9256 __rte_unused struct rte_flow_tunnel *app_tunnel,
9257 __rte_unused struct rte_flow_item **items,
9258 __rte_unused uint32_t *num_of_items,
9259 __rte_unused struct rte_flow_error *error)
9265 mlx5_flow_tunnel_item_release(__rte_unused struct rte_eth_dev *dev,
9266 __rte_unused struct rte_flow_item *pmd_items,
9267 __rte_unused uint32_t num_items,
9268 __rte_unused struct rte_flow_error *err)
9274 mlx5_flow_tunnel_action_release(__rte_unused struct rte_eth_dev *dev,
9275 __rte_unused struct rte_flow_action *pmd_action,
9276 __rte_unused uint32_t num_actions,
9277 __rte_unused struct rte_flow_error *err)
9283 mlx5_flow_tunnel_get_restore_info(__rte_unused struct rte_eth_dev *dev,
9284 __rte_unused struct rte_mbuf *m,
9285 __rte_unused struct rte_flow_restore_info *i,
9286 __rte_unused struct rte_flow_error *err)
9292 flow_tunnel_add_default_miss(__rte_unused struct rte_eth_dev *dev,
9293 __rte_unused struct rte_flow *flow,
9294 __rte_unused const struct rte_flow_attr *attr,
9295 __rte_unused const struct rte_flow_action *actions,
9296 __rte_unused uint32_t flow_idx,
9297 __rte_unused const struct mlx5_flow_tunnel *tunnel,
9298 __rte_unused struct tunnel_default_miss_ctx *ctx,
9299 __rte_unused struct rte_flow_error *error)
9304 static struct mlx5_flow_tunnel *
9305 mlx5_find_tunnel_id(__rte_unused struct rte_eth_dev *dev,
9306 __rte_unused uint32_t id)
9312 mlx5_flow_tunnel_free(__rte_unused struct rte_eth_dev *dev,
9313 __rte_unused struct mlx5_flow_tunnel *tunnel)
9318 tunnel_flow_group_to_flow_table(__rte_unused struct rte_eth_dev *dev,
9319 __rte_unused const struct mlx5_flow_tunnel *t,
9320 __rte_unused uint32_t group,
9321 __rte_unused uint32_t *table,
9322 struct rte_flow_error *error)
9324 return rte_flow_error_set(error, ENOTSUP,
9325 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
9326 "tunnel offload requires DV support");
9330 mlx5_release_tunnel_hub(__rte_unused struct mlx5_dev_ctx_shared *sh,
9331 __rte_unused uint16_t port_id)
9334 #endif /* HAVE_IBV_FLOW_DV_SUPPORT */
9337 mlx5_dbg__print_pattern(const struct rte_flow_item *item)
9340 struct rte_flow_error error;
9342 for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
9344 ret = rte_flow_conv(RTE_FLOW_CONV_OP_ITEM_NAME_PTR, &item_name,
9346 (void *)(uintptr_t)item->type, &error);
9348 printf("%s ", item_name);
9350 printf("%d\n", (int)item->type);