1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2016 6WIND S.A.
3 * Copyright 2016 Mellanox Technologies, Ltd
6 #include <netinet/in.h>
13 #include <rte_common.h>
14 #include <rte_ether.h>
15 #include <rte_ethdev_driver.h>
16 #include <rte_eal_paging.h>
18 #include <rte_cycles.h>
19 #include <rte_flow_driver.h>
20 #include <rte_malloc.h>
23 #include <mlx5_glue.h>
24 #include <mlx5_devx_cmds.h>
26 #include <mlx5_malloc.h>
28 #include "mlx5_defs.h"
30 #include "mlx5_flow.h"
31 #include "mlx5_flow_os.h"
32 #include "mlx5_rxtx.h"
33 #include "mlx5_common_os.h"
34 #include "rte_pmd_mlx5.h"
36 static struct mlx5_flow_tunnel *
37 mlx5_find_tunnel_id(struct rte_eth_dev *dev, uint32_t id);
39 mlx5_flow_tunnel_free(struct rte_eth_dev *dev, struct mlx5_flow_tunnel *tunnel);
40 static const struct mlx5_flow_tbl_data_entry *
41 tunnel_mark_decode(struct rte_eth_dev *dev, uint32_t mark);
43 mlx5_get_flow_tunnel(struct rte_eth_dev *dev,
44 const struct rte_flow_tunnel *app_tunnel,
45 struct mlx5_flow_tunnel **tunnel);
46 static struct mlx5_flow_workspace *mlx5_flow_push_thread_workspace(void);
47 static void mlx5_flow_pop_thread_workspace(void);
50 /** Device flow drivers. */
51 extern const struct mlx5_flow_driver_ops mlx5_flow_verbs_drv_ops;
53 const struct mlx5_flow_driver_ops mlx5_flow_null_drv_ops;
55 const struct mlx5_flow_driver_ops *flow_drv_ops[] = {
56 [MLX5_FLOW_TYPE_MIN] = &mlx5_flow_null_drv_ops,
57 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
58 [MLX5_FLOW_TYPE_DV] = &mlx5_flow_dv_drv_ops,
60 [MLX5_FLOW_TYPE_VERBS] = &mlx5_flow_verbs_drv_ops,
61 [MLX5_FLOW_TYPE_MAX] = &mlx5_flow_null_drv_ops
64 /** Helper macro to build input graph for mlx5_flow_expand_rss(). */
65 #define MLX5_FLOW_EXPAND_RSS_NEXT(...) \
70 /** Node object of input graph for mlx5_flow_expand_rss(). */
71 struct mlx5_flow_expand_node {
72 const int *const next;
74 * List of next node indexes. Index 0 is interpreted as a terminator.
76 const enum rte_flow_item_type type;
77 /**< Pattern item type of current node. */
80 * RSS types bit-field associated with this node
81 * (see ETH_RSS_* definitions).
85 /** Object returned by mlx5_flow_expand_rss(). */
86 struct mlx5_flow_expand_rss {
88 /**< Number of entries @p patterns and @p priorities. */
90 struct rte_flow_item *pattern; /**< Expanded pattern array. */
91 uint32_t priority; /**< Priority offset for each expansion. */
95 static enum rte_flow_item_type
96 mlx5_flow_expand_rss_item_complete(const struct rte_flow_item *item)
98 enum rte_flow_item_type ret = RTE_FLOW_ITEM_TYPE_VOID;
99 uint16_t ether_type = 0;
100 uint16_t ether_type_m;
101 uint8_t ip_next_proto = 0;
102 uint8_t ip_next_proto_m;
104 if (item == NULL || item->spec == NULL)
106 switch (item->type) {
107 case RTE_FLOW_ITEM_TYPE_ETH:
109 ether_type_m = ((const struct rte_flow_item_eth *)
112 ether_type_m = rte_flow_item_eth_mask.type;
113 if (ether_type_m != RTE_BE16(0xFFFF))
115 ether_type = ((const struct rte_flow_item_eth *)
117 if (rte_be_to_cpu_16(ether_type) == RTE_ETHER_TYPE_IPV4)
118 ret = RTE_FLOW_ITEM_TYPE_IPV4;
119 else if (rte_be_to_cpu_16(ether_type) == RTE_ETHER_TYPE_IPV6)
120 ret = RTE_FLOW_ITEM_TYPE_IPV6;
121 else if (rte_be_to_cpu_16(ether_type) == RTE_ETHER_TYPE_VLAN)
122 ret = RTE_FLOW_ITEM_TYPE_VLAN;
124 ret = RTE_FLOW_ITEM_TYPE_END;
126 case RTE_FLOW_ITEM_TYPE_VLAN:
128 ether_type_m = ((const struct rte_flow_item_vlan *)
129 (item->mask))->inner_type;
131 ether_type_m = rte_flow_item_vlan_mask.inner_type;
132 if (ether_type_m != RTE_BE16(0xFFFF))
134 ether_type = ((const struct rte_flow_item_vlan *)
135 (item->spec))->inner_type;
136 if (rte_be_to_cpu_16(ether_type) == RTE_ETHER_TYPE_IPV4)
137 ret = RTE_FLOW_ITEM_TYPE_IPV4;
138 else if (rte_be_to_cpu_16(ether_type) == RTE_ETHER_TYPE_IPV6)
139 ret = RTE_FLOW_ITEM_TYPE_IPV6;
140 else if (rte_be_to_cpu_16(ether_type) == RTE_ETHER_TYPE_VLAN)
141 ret = RTE_FLOW_ITEM_TYPE_VLAN;
143 ret = RTE_FLOW_ITEM_TYPE_END;
145 case RTE_FLOW_ITEM_TYPE_IPV4:
147 ip_next_proto_m = ((const struct rte_flow_item_ipv4 *)
148 (item->mask))->hdr.next_proto_id;
151 rte_flow_item_ipv4_mask.hdr.next_proto_id;
152 if (ip_next_proto_m != 0xFF)
154 ip_next_proto = ((const struct rte_flow_item_ipv4 *)
155 (item->spec))->hdr.next_proto_id;
156 if (ip_next_proto == IPPROTO_UDP)
157 ret = RTE_FLOW_ITEM_TYPE_UDP;
158 else if (ip_next_proto == IPPROTO_TCP)
159 ret = RTE_FLOW_ITEM_TYPE_TCP;
160 else if (ip_next_proto == IPPROTO_IP)
161 ret = RTE_FLOW_ITEM_TYPE_IPV4;
162 else if (ip_next_proto == IPPROTO_IPV6)
163 ret = RTE_FLOW_ITEM_TYPE_IPV6;
165 ret = RTE_FLOW_ITEM_TYPE_END;
167 case RTE_FLOW_ITEM_TYPE_IPV6:
169 ip_next_proto_m = ((const struct rte_flow_item_ipv6 *)
170 (item->mask))->hdr.proto;
173 rte_flow_item_ipv6_mask.hdr.proto;
174 if (ip_next_proto_m != 0xFF)
176 ip_next_proto = ((const struct rte_flow_item_ipv6 *)
177 (item->spec))->hdr.proto;
178 if (ip_next_proto == IPPROTO_UDP)
179 ret = RTE_FLOW_ITEM_TYPE_UDP;
180 else if (ip_next_proto == IPPROTO_TCP)
181 ret = RTE_FLOW_ITEM_TYPE_TCP;
182 else if (ip_next_proto == IPPROTO_IP)
183 ret = RTE_FLOW_ITEM_TYPE_IPV4;
184 else if (ip_next_proto == IPPROTO_IPV6)
185 ret = RTE_FLOW_ITEM_TYPE_IPV6;
187 ret = RTE_FLOW_ITEM_TYPE_END;
190 ret = RTE_FLOW_ITEM_TYPE_VOID;
197 * Expand RSS flows into several possible flows according to the RSS hash
198 * fields requested and the driver capabilities.
201 * Buffer to store the result expansion.
203 * Buffer size in bytes. If 0, @p buf can be NULL.
207 * RSS types to expand (see ETH_RSS_* definitions).
209 * Input graph to expand @p pattern according to @p types.
210 * @param[in] graph_root_index
211 * Index of root node in @p graph, typically 0.
214 * A positive value representing the size of @p buf in bytes regardless of
215 * @p size on success, a negative errno value otherwise and rte_errno is
216 * set, the following errors are defined:
218 * -E2BIG: graph-depth @p graph is too deep.
221 mlx5_flow_expand_rss(struct mlx5_flow_expand_rss *buf, size_t size,
222 const struct rte_flow_item *pattern, uint64_t types,
223 const struct mlx5_flow_expand_node graph[],
224 int graph_root_index)
227 const struct rte_flow_item *item;
228 const struct mlx5_flow_expand_node *node = &graph[graph_root_index];
229 const int *next_node;
230 const int *stack[elt_n];
232 struct rte_flow_item flow_items[elt_n];
235 size_t user_pattern_size = 0;
237 const struct mlx5_flow_expand_node *next = NULL;
238 struct rte_flow_item missed_item;
241 const struct rte_flow_item *last_item = NULL;
243 memset(&missed_item, 0, sizeof(missed_item));
244 lsize = offsetof(struct mlx5_flow_expand_rss, entry) +
245 elt_n * sizeof(buf->entry[0]);
247 buf->entry[0].priority = 0;
248 buf->entry[0].pattern = (void *)&buf->entry[elt_n];
250 addr = buf->entry[0].pattern;
252 for (item = pattern; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
253 if (item->type != RTE_FLOW_ITEM_TYPE_VOID)
255 for (i = 0; node->next && node->next[i]; ++i) {
256 next = &graph[node->next[i]];
257 if (next->type == item->type)
262 user_pattern_size += sizeof(*item);
264 user_pattern_size += sizeof(*item); /* Handle END item. */
265 lsize += user_pattern_size;
266 /* Copy the user pattern in the first entry of the buffer. */
268 rte_memcpy(addr, pattern, user_pattern_size);
269 addr = (void *)(((uintptr_t)addr) + user_pattern_size);
272 /* Start expanding. */
273 memset(flow_items, 0, sizeof(flow_items));
274 user_pattern_size -= sizeof(*item);
276 * Check if the last valid item has spec set, need complete pattern,
277 * and the pattern can be used for expansion.
279 missed_item.type = mlx5_flow_expand_rss_item_complete(last_item);
280 if (missed_item.type == RTE_FLOW_ITEM_TYPE_END) {
281 /* Item type END indicates expansion is not required. */
284 if (missed_item.type != RTE_FLOW_ITEM_TYPE_VOID) {
287 for (i = 0; node->next && node->next[i]; ++i) {
288 next = &graph[node->next[i]];
289 if (next->type == missed_item.type) {
290 flow_items[0].type = missed_item.type;
291 flow_items[1].type = RTE_FLOW_ITEM_TYPE_END;
297 if (next && missed) {
298 elt = 2; /* missed item + item end. */
300 lsize += elt * sizeof(*item) + user_pattern_size;
301 if ((node->rss_types & types) && lsize <= size) {
302 buf->entry[buf->entries].priority = 1;
303 buf->entry[buf->entries].pattern = addr;
305 rte_memcpy(addr, buf->entry[0].pattern,
307 addr = (void *)(((uintptr_t)addr) + user_pattern_size);
308 rte_memcpy(addr, flow_items, elt * sizeof(*item));
309 addr = (void *)(((uintptr_t)addr) +
310 elt * sizeof(*item));
313 memset(flow_items, 0, sizeof(flow_items));
314 next_node = node->next;
315 stack[stack_pos] = next_node;
316 node = next_node ? &graph[*next_node] : NULL;
318 flow_items[stack_pos].type = node->type;
319 if (node->rss_types & types) {
321 * compute the number of items to copy from the
322 * expansion and copy it.
323 * When the stack_pos is 0, there are 1 element in it,
324 * plus the addition END item.
327 flow_items[stack_pos + 1].type = RTE_FLOW_ITEM_TYPE_END;
328 lsize += elt * sizeof(*item) + user_pattern_size;
330 size_t n = elt * sizeof(*item);
332 buf->entry[buf->entries].priority =
333 stack_pos + 1 + missed;
334 buf->entry[buf->entries].pattern = addr;
336 rte_memcpy(addr, buf->entry[0].pattern,
338 addr = (void *)(((uintptr_t)addr) +
340 rte_memcpy(addr, &missed_item,
341 missed * sizeof(*item));
342 addr = (void *)(((uintptr_t)addr) +
343 missed * sizeof(*item));
344 rte_memcpy(addr, flow_items, n);
345 addr = (void *)(((uintptr_t)addr) + n);
350 next_node = node->next;
351 if (stack_pos++ == elt_n) {
355 stack[stack_pos] = next_node;
356 } else if (*(next_node + 1)) {
357 /* Follow up with the next possibility. */
360 /* Move to the next path. */
362 next_node = stack[--stack_pos];
364 stack[stack_pos] = next_node;
366 node = *next_node ? &graph[*next_node] : NULL;
368 /* no expanded flows but we have missed item, create one rule for it */
369 if (buf->entries == 1 && missed != 0) {
371 lsize += elt * sizeof(*item) + user_pattern_size;
373 buf->entry[buf->entries].priority = 1;
374 buf->entry[buf->entries].pattern = addr;
376 flow_items[0].type = missed_item.type;
377 flow_items[1].type = RTE_FLOW_ITEM_TYPE_END;
378 rte_memcpy(addr, buf->entry[0].pattern,
380 addr = (void *)(((uintptr_t)addr) + user_pattern_size);
381 rte_memcpy(addr, flow_items, elt * sizeof(*item));
382 addr = (void *)(((uintptr_t)addr) +
383 elt * sizeof(*item));
389 enum mlx5_expansion {
391 MLX5_EXPANSION_ROOT_OUTER,
392 MLX5_EXPANSION_ROOT_ETH_VLAN,
393 MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN,
394 MLX5_EXPANSION_OUTER_ETH,
395 MLX5_EXPANSION_OUTER_ETH_VLAN,
396 MLX5_EXPANSION_OUTER_VLAN,
397 MLX5_EXPANSION_OUTER_IPV4,
398 MLX5_EXPANSION_OUTER_IPV4_UDP,
399 MLX5_EXPANSION_OUTER_IPV4_TCP,
400 MLX5_EXPANSION_OUTER_IPV6,
401 MLX5_EXPANSION_OUTER_IPV6_UDP,
402 MLX5_EXPANSION_OUTER_IPV6_TCP,
403 MLX5_EXPANSION_VXLAN,
404 MLX5_EXPANSION_VXLAN_GPE,
408 MLX5_EXPANSION_ETH_VLAN,
411 MLX5_EXPANSION_IPV4_UDP,
412 MLX5_EXPANSION_IPV4_TCP,
414 MLX5_EXPANSION_IPV6_UDP,
415 MLX5_EXPANSION_IPV6_TCP,
418 /** Supported expansion of items. */
419 static const struct mlx5_flow_expand_node mlx5_support_expansion[] = {
420 [MLX5_EXPANSION_ROOT] = {
421 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
423 MLX5_EXPANSION_IPV6),
424 .type = RTE_FLOW_ITEM_TYPE_END,
426 [MLX5_EXPANSION_ROOT_OUTER] = {
427 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_ETH,
428 MLX5_EXPANSION_OUTER_IPV4,
429 MLX5_EXPANSION_OUTER_IPV6),
430 .type = RTE_FLOW_ITEM_TYPE_END,
432 [MLX5_EXPANSION_ROOT_ETH_VLAN] = {
433 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH_VLAN),
434 .type = RTE_FLOW_ITEM_TYPE_END,
436 [MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN] = {
437 .next = MLX5_FLOW_EXPAND_RSS_NEXT
438 (MLX5_EXPANSION_OUTER_ETH_VLAN),
439 .type = RTE_FLOW_ITEM_TYPE_END,
441 [MLX5_EXPANSION_OUTER_ETH] = {
442 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_IPV4,
443 MLX5_EXPANSION_OUTER_IPV6,
444 MLX5_EXPANSION_MPLS),
445 .type = RTE_FLOW_ITEM_TYPE_ETH,
448 [MLX5_EXPANSION_OUTER_ETH_VLAN] = {
449 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_VLAN),
450 .type = RTE_FLOW_ITEM_TYPE_ETH,
453 [MLX5_EXPANSION_OUTER_VLAN] = {
454 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_IPV4,
455 MLX5_EXPANSION_OUTER_IPV6),
456 .type = RTE_FLOW_ITEM_TYPE_VLAN,
458 [MLX5_EXPANSION_OUTER_IPV4] = {
459 .next = MLX5_FLOW_EXPAND_RSS_NEXT
460 (MLX5_EXPANSION_OUTER_IPV4_UDP,
461 MLX5_EXPANSION_OUTER_IPV4_TCP,
464 MLX5_EXPANSION_IPV6),
465 .type = RTE_FLOW_ITEM_TYPE_IPV4,
466 .rss_types = ETH_RSS_IPV4 | ETH_RSS_FRAG_IPV4 |
467 ETH_RSS_NONFRAG_IPV4_OTHER,
469 [MLX5_EXPANSION_OUTER_IPV4_UDP] = {
470 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VXLAN,
471 MLX5_EXPANSION_VXLAN_GPE),
472 .type = RTE_FLOW_ITEM_TYPE_UDP,
473 .rss_types = ETH_RSS_NONFRAG_IPV4_UDP,
475 [MLX5_EXPANSION_OUTER_IPV4_TCP] = {
476 .type = RTE_FLOW_ITEM_TYPE_TCP,
477 .rss_types = ETH_RSS_NONFRAG_IPV4_TCP,
479 [MLX5_EXPANSION_OUTER_IPV6] = {
480 .next = MLX5_FLOW_EXPAND_RSS_NEXT
481 (MLX5_EXPANSION_OUTER_IPV6_UDP,
482 MLX5_EXPANSION_OUTER_IPV6_TCP,
484 MLX5_EXPANSION_IPV6),
485 .type = RTE_FLOW_ITEM_TYPE_IPV6,
486 .rss_types = ETH_RSS_IPV6 | ETH_RSS_FRAG_IPV6 |
487 ETH_RSS_NONFRAG_IPV6_OTHER,
489 [MLX5_EXPANSION_OUTER_IPV6_UDP] = {
490 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VXLAN,
491 MLX5_EXPANSION_VXLAN_GPE),
492 .type = RTE_FLOW_ITEM_TYPE_UDP,
493 .rss_types = ETH_RSS_NONFRAG_IPV6_UDP,
495 [MLX5_EXPANSION_OUTER_IPV6_TCP] = {
496 .type = RTE_FLOW_ITEM_TYPE_TCP,
497 .rss_types = ETH_RSS_NONFRAG_IPV6_TCP,
499 [MLX5_EXPANSION_VXLAN] = {
500 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
502 MLX5_EXPANSION_IPV6),
503 .type = RTE_FLOW_ITEM_TYPE_VXLAN,
505 [MLX5_EXPANSION_VXLAN_GPE] = {
506 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
508 MLX5_EXPANSION_IPV6),
509 .type = RTE_FLOW_ITEM_TYPE_VXLAN_GPE,
511 [MLX5_EXPANSION_GRE] = {
512 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4),
513 .type = RTE_FLOW_ITEM_TYPE_GRE,
515 [MLX5_EXPANSION_MPLS] = {
516 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
517 MLX5_EXPANSION_IPV6),
518 .type = RTE_FLOW_ITEM_TYPE_MPLS,
520 [MLX5_EXPANSION_ETH] = {
521 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
522 MLX5_EXPANSION_IPV6),
523 .type = RTE_FLOW_ITEM_TYPE_ETH,
525 [MLX5_EXPANSION_ETH_VLAN] = {
526 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VLAN),
527 .type = RTE_FLOW_ITEM_TYPE_ETH,
529 [MLX5_EXPANSION_VLAN] = {
530 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
531 MLX5_EXPANSION_IPV6),
532 .type = RTE_FLOW_ITEM_TYPE_VLAN,
534 [MLX5_EXPANSION_IPV4] = {
535 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4_UDP,
536 MLX5_EXPANSION_IPV4_TCP),
537 .type = RTE_FLOW_ITEM_TYPE_IPV4,
538 .rss_types = ETH_RSS_IPV4 | ETH_RSS_FRAG_IPV4 |
539 ETH_RSS_NONFRAG_IPV4_OTHER,
541 [MLX5_EXPANSION_IPV4_UDP] = {
542 .type = RTE_FLOW_ITEM_TYPE_UDP,
543 .rss_types = ETH_RSS_NONFRAG_IPV4_UDP,
545 [MLX5_EXPANSION_IPV4_TCP] = {
546 .type = RTE_FLOW_ITEM_TYPE_TCP,
547 .rss_types = ETH_RSS_NONFRAG_IPV4_TCP,
549 [MLX5_EXPANSION_IPV6] = {
550 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV6_UDP,
551 MLX5_EXPANSION_IPV6_TCP),
552 .type = RTE_FLOW_ITEM_TYPE_IPV6,
553 .rss_types = ETH_RSS_IPV6 | ETH_RSS_FRAG_IPV6 |
554 ETH_RSS_NONFRAG_IPV6_OTHER,
556 [MLX5_EXPANSION_IPV6_UDP] = {
557 .type = RTE_FLOW_ITEM_TYPE_UDP,
558 .rss_types = ETH_RSS_NONFRAG_IPV6_UDP,
560 [MLX5_EXPANSION_IPV6_TCP] = {
561 .type = RTE_FLOW_ITEM_TYPE_TCP,
562 .rss_types = ETH_RSS_NONFRAG_IPV6_TCP,
566 static struct rte_flow_shared_action *
567 mlx5_shared_action_create(struct rte_eth_dev *dev,
568 const struct rte_flow_shared_action_conf *conf,
569 const struct rte_flow_action *action,
570 struct rte_flow_error *error);
571 static int mlx5_shared_action_destroy
572 (struct rte_eth_dev *dev,
573 struct rte_flow_shared_action *shared_action,
574 struct rte_flow_error *error);
575 static int mlx5_shared_action_update
576 (struct rte_eth_dev *dev,
577 struct rte_flow_shared_action *shared_action,
578 const struct rte_flow_action *action,
579 struct rte_flow_error *error);
580 static int mlx5_shared_action_query
581 (struct rte_eth_dev *dev,
582 const struct rte_flow_shared_action *action,
584 struct rte_flow_error *error);
586 mlx5_flow_tunnel_validate(struct rte_eth_dev *dev,
587 struct rte_flow_tunnel *tunnel,
591 if (!is_tunnel_offload_active(dev)) {
592 err_msg = "tunnel offload was not activated";
594 } else if (!tunnel) {
595 err_msg = "no application tunnel";
599 switch (tunnel->type) {
601 err_msg = "unsupported tunnel type";
603 case RTE_FLOW_ITEM_TYPE_VXLAN:
613 mlx5_flow_tunnel_decap_set(struct rte_eth_dev *dev,
614 struct rte_flow_tunnel *app_tunnel,
615 struct rte_flow_action **actions,
616 uint32_t *num_of_actions,
617 struct rte_flow_error *error)
620 struct mlx5_flow_tunnel *tunnel;
621 const char *err_msg = NULL;
622 bool verdict = mlx5_flow_tunnel_validate(dev, app_tunnel, err_msg);
625 return rte_flow_error_set(error, EINVAL,
626 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
628 ret = mlx5_get_flow_tunnel(dev, app_tunnel, &tunnel);
630 return rte_flow_error_set(error, ret,
631 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
632 "failed to initialize pmd tunnel");
634 *actions = &tunnel->action;
640 mlx5_flow_tunnel_match(struct rte_eth_dev *dev,
641 struct rte_flow_tunnel *app_tunnel,
642 struct rte_flow_item **items,
643 uint32_t *num_of_items,
644 struct rte_flow_error *error)
647 struct mlx5_flow_tunnel *tunnel;
648 const char *err_msg = NULL;
649 bool verdict = mlx5_flow_tunnel_validate(dev, app_tunnel, err_msg);
652 return rte_flow_error_set(error, EINVAL,
653 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
655 ret = mlx5_get_flow_tunnel(dev, app_tunnel, &tunnel);
657 return rte_flow_error_set(error, ret,
658 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
659 "failed to initialize pmd tunnel");
661 *items = &tunnel->item;
667 mlx5_flow_item_release(struct rte_eth_dev *dev,
668 struct rte_flow_item *pmd_items,
669 uint32_t num_items, struct rte_flow_error *err)
671 struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
672 struct mlx5_flow_tunnel *tun;
674 rte_spinlock_lock(&thub->sl);
675 LIST_FOREACH(tun, &thub->tunnels, chain) {
676 if (&tun->item == pmd_items) {
677 LIST_REMOVE(tun, chain);
681 rte_spinlock_unlock(&thub->sl);
682 if (!tun || num_items != 1)
683 return rte_flow_error_set(err, EINVAL,
684 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
686 if (!__atomic_sub_fetch(&tun->refctn, 1, __ATOMIC_RELAXED))
687 mlx5_flow_tunnel_free(dev, tun);
692 mlx5_flow_action_release(struct rte_eth_dev *dev,
693 struct rte_flow_action *pmd_actions,
694 uint32_t num_actions, struct rte_flow_error *err)
696 struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
697 struct mlx5_flow_tunnel *tun;
699 rte_spinlock_lock(&thub->sl);
700 LIST_FOREACH(tun, &thub->tunnels, chain) {
701 if (&tun->action == pmd_actions) {
702 LIST_REMOVE(tun, chain);
706 rte_spinlock_unlock(&thub->sl);
707 if (!tun || num_actions != 1)
708 return rte_flow_error_set(err, EINVAL,
709 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
711 if (!__atomic_sub_fetch(&tun->refctn, 1, __ATOMIC_RELAXED))
712 mlx5_flow_tunnel_free(dev, tun);
718 mlx5_flow_tunnel_get_restore_info(struct rte_eth_dev *dev,
720 struct rte_flow_restore_info *info,
721 struct rte_flow_error *err)
723 uint64_t ol_flags = m->ol_flags;
724 const struct mlx5_flow_tbl_data_entry *tble;
725 const uint64_t mask = PKT_RX_FDIR | PKT_RX_FDIR_ID;
727 if ((ol_flags & mask) != mask)
729 tble = tunnel_mark_decode(dev, m->hash.fdir.hi);
731 DRV_LOG(DEBUG, "port %u invalid miss tunnel mark %#x",
732 dev->data->port_id, m->hash.fdir.hi);
735 MLX5_ASSERT(tble->tunnel);
736 memcpy(&info->tunnel, &tble->tunnel->app_tunnel, sizeof(info->tunnel));
737 info->group_id = tble->group_id;
738 info->flags = RTE_FLOW_RESTORE_INFO_TUNNEL |
739 RTE_FLOW_RESTORE_INFO_GROUP_ID |
740 RTE_FLOW_RESTORE_INFO_ENCAPSULATED;
745 return rte_flow_error_set(err, EINVAL,
746 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
747 "failed to get restore info");
750 static const struct rte_flow_ops mlx5_flow_ops = {
751 .validate = mlx5_flow_validate,
752 .create = mlx5_flow_create,
753 .destroy = mlx5_flow_destroy,
754 .flush = mlx5_flow_flush,
755 .isolate = mlx5_flow_isolate,
756 .query = mlx5_flow_query,
757 .dev_dump = mlx5_flow_dev_dump,
758 .get_aged_flows = mlx5_flow_get_aged_flows,
759 .shared_action_create = mlx5_shared_action_create,
760 .shared_action_destroy = mlx5_shared_action_destroy,
761 .shared_action_update = mlx5_shared_action_update,
762 .shared_action_query = mlx5_shared_action_query,
763 .tunnel_decap_set = mlx5_flow_tunnel_decap_set,
764 .tunnel_match = mlx5_flow_tunnel_match,
765 .tunnel_action_decap_release = mlx5_flow_action_release,
766 .tunnel_item_release = mlx5_flow_item_release,
767 .get_restore_info = mlx5_flow_tunnel_get_restore_info,
770 /* Tunnel information. */
771 struct mlx5_flow_tunnel_info {
772 uint64_t tunnel; /**< Tunnel bit (see MLX5_FLOW_*). */
773 uint32_t ptype; /**< Tunnel Ptype (see RTE_PTYPE_*). */
776 static struct mlx5_flow_tunnel_info tunnels_info[] = {
778 .tunnel = MLX5_FLOW_LAYER_VXLAN,
779 .ptype = RTE_PTYPE_TUNNEL_VXLAN | RTE_PTYPE_L4_UDP,
782 .tunnel = MLX5_FLOW_LAYER_GENEVE,
783 .ptype = RTE_PTYPE_TUNNEL_GENEVE | RTE_PTYPE_L4_UDP,
786 .tunnel = MLX5_FLOW_LAYER_VXLAN_GPE,
787 .ptype = RTE_PTYPE_TUNNEL_VXLAN_GPE | RTE_PTYPE_L4_UDP,
790 .tunnel = MLX5_FLOW_LAYER_GRE,
791 .ptype = RTE_PTYPE_TUNNEL_GRE,
794 .tunnel = MLX5_FLOW_LAYER_MPLS | MLX5_FLOW_LAYER_OUTER_L4_UDP,
795 .ptype = RTE_PTYPE_TUNNEL_MPLS_IN_UDP | RTE_PTYPE_L4_UDP,
798 .tunnel = MLX5_FLOW_LAYER_MPLS,
799 .ptype = RTE_PTYPE_TUNNEL_MPLS_IN_GRE,
802 .tunnel = MLX5_FLOW_LAYER_NVGRE,
803 .ptype = RTE_PTYPE_TUNNEL_NVGRE,
806 .tunnel = MLX5_FLOW_LAYER_IPIP,
807 .ptype = RTE_PTYPE_TUNNEL_IP,
810 .tunnel = MLX5_FLOW_LAYER_IPV6_ENCAP,
811 .ptype = RTE_PTYPE_TUNNEL_IP,
814 .tunnel = MLX5_FLOW_LAYER_GTP,
815 .ptype = RTE_PTYPE_TUNNEL_GTPU,
819 /* Key of thread specific flow workspace data. */
820 static pthread_key_t key_workspace;
822 /* Thread specific flow workspace data once initialization data. */
823 static pthread_once_t key_workspace_init;
827 * Translate tag ID to register.
830 * Pointer to the Ethernet device structure.
832 * The feature that request the register.
834 * The request register ID.
836 * Error description in case of any.
839 * The request register on success, a negative errno
840 * value otherwise and rte_errno is set.
843 mlx5_flow_get_reg_id(struct rte_eth_dev *dev,
844 enum mlx5_feature_name feature,
846 struct rte_flow_error *error)
848 struct mlx5_priv *priv = dev->data->dev_private;
849 struct mlx5_dev_config *config = &priv->config;
850 enum modify_reg start_reg;
851 bool skip_mtr_reg = false;
854 case MLX5_HAIRPIN_RX:
856 case MLX5_HAIRPIN_TX:
858 case MLX5_METADATA_RX:
859 switch (config->dv_xmeta_en) {
860 case MLX5_XMETA_MODE_LEGACY:
862 case MLX5_XMETA_MODE_META16:
864 case MLX5_XMETA_MODE_META32:
868 case MLX5_METADATA_TX:
870 case MLX5_METADATA_FDB:
871 switch (config->dv_xmeta_en) {
872 case MLX5_XMETA_MODE_LEGACY:
874 case MLX5_XMETA_MODE_META16:
876 case MLX5_XMETA_MODE_META32:
881 switch (config->dv_xmeta_en) {
882 case MLX5_XMETA_MODE_LEGACY:
884 case MLX5_XMETA_MODE_META16:
886 case MLX5_XMETA_MODE_META32:
892 * If meter color and flow match share one register, flow match
893 * should use the meter color register for match.
895 if (priv->mtr_reg_share)
896 return priv->mtr_color_reg;
898 return priv->mtr_color_reg != REG_C_2 ? REG_C_2 :
901 MLX5_ASSERT(priv->mtr_color_reg != REG_NON);
902 return priv->mtr_color_reg;
905 * Metadata COPY_MARK register using is in meter suffix sub
906 * flow while with meter. It's safe to share the same register.
908 return priv->mtr_color_reg != REG_C_2 ? REG_C_2 : REG_C_3;
911 * If meter is enable, it will engage the register for color
912 * match and flow match. If meter color match is not using the
913 * REG_C_2, need to skip the REG_C_x be used by meter color
915 * If meter is disable, free to use all available registers.
917 start_reg = priv->mtr_color_reg != REG_C_2 ? REG_C_2 :
918 (priv->mtr_reg_share ? REG_C_3 : REG_C_4);
919 skip_mtr_reg = !!(priv->mtr_en && start_reg == REG_C_2);
920 if (id > (REG_C_7 - start_reg))
921 return rte_flow_error_set(error, EINVAL,
922 RTE_FLOW_ERROR_TYPE_ITEM,
923 NULL, "invalid tag id");
924 if (config->flow_mreg_c[id + start_reg - REG_C_0] == REG_NON)
925 return rte_flow_error_set(error, ENOTSUP,
926 RTE_FLOW_ERROR_TYPE_ITEM,
927 NULL, "unsupported tag id");
929 * This case means meter is using the REG_C_x great than 2.
930 * Take care not to conflict with meter color REG_C_x.
931 * If the available index REG_C_y >= REG_C_x, skip the
934 if (skip_mtr_reg && config->flow_mreg_c
935 [id + start_reg - REG_C_0] >= priv->mtr_color_reg) {
936 if (id >= (REG_C_7 - start_reg))
937 return rte_flow_error_set(error, EINVAL,
938 RTE_FLOW_ERROR_TYPE_ITEM,
939 NULL, "invalid tag id");
940 if (config->flow_mreg_c
941 [id + 1 + start_reg - REG_C_0] != REG_NON)
942 return config->flow_mreg_c
943 [id + 1 + start_reg - REG_C_0];
944 return rte_flow_error_set(error, ENOTSUP,
945 RTE_FLOW_ERROR_TYPE_ITEM,
946 NULL, "unsupported tag id");
948 return config->flow_mreg_c[id + start_reg - REG_C_0];
951 return rte_flow_error_set(error, EINVAL,
952 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
953 NULL, "invalid feature name");
957 * Check extensive flow metadata register support.
960 * Pointer to rte_eth_dev structure.
963 * True if device supports extensive flow metadata register, otherwise false.
966 mlx5_flow_ext_mreg_supported(struct rte_eth_dev *dev)
968 struct mlx5_priv *priv = dev->data->dev_private;
969 struct mlx5_dev_config *config = &priv->config;
972 * Having available reg_c can be regarded inclusively as supporting
973 * extensive flow metadata register, which could mean,
974 * - metadata register copy action by modify header.
975 * - 16 modify header actions is supported.
976 * - reg_c's are preserved across different domain (FDB and NIC) on
977 * packet loopback by flow lookup miss.
979 return config->flow_mreg_c[2] != REG_NON;
983 * Verify the @p item specifications (spec, last, mask) are compatible with the
987 * Item specification.
989 * @p item->mask or flow default bit-masks.
990 * @param[in] nic_mask
991 * Bit-masks covering supported fields by the NIC to compare with user mask.
993 * Bit-masks size in bytes.
994 * @param[in] range_accepted
995 * True if range of values is accepted for specific fields, false otherwise.
997 * Pointer to error structure.
1000 * 0 on success, a negative errno value otherwise and rte_errno is set.
1003 mlx5_flow_item_acceptable(const struct rte_flow_item *item,
1004 const uint8_t *mask,
1005 const uint8_t *nic_mask,
1007 bool range_accepted,
1008 struct rte_flow_error *error)
1012 MLX5_ASSERT(nic_mask);
1013 for (i = 0; i < size; ++i)
1014 if ((nic_mask[i] | mask[i]) != nic_mask[i])
1015 return rte_flow_error_set(error, ENOTSUP,
1016 RTE_FLOW_ERROR_TYPE_ITEM,
1018 "mask enables non supported"
1020 if (!item->spec && (item->mask || item->last))
1021 return rte_flow_error_set(error, EINVAL,
1022 RTE_FLOW_ERROR_TYPE_ITEM, item,
1023 "mask/last without a spec is not"
1025 if (item->spec && item->last && !range_accepted) {
1031 for (i = 0; i < size; ++i) {
1032 spec[i] = ((const uint8_t *)item->spec)[i] & mask[i];
1033 last[i] = ((const uint8_t *)item->last)[i] & mask[i];
1035 ret = memcmp(spec, last, size);
1037 return rte_flow_error_set(error, EINVAL,
1038 RTE_FLOW_ERROR_TYPE_ITEM,
1040 "range is not valid");
1046 * Adjust the hash fields according to the @p flow information.
1048 * @param[in] dev_flow.
1049 * Pointer to the mlx5_flow.
1051 * 1 when the hash field is for a tunnel item.
1052 * @param[in] layer_types
1054 * @param[in] hash_fields
1058 * The hash fields that should be used.
1061 mlx5_flow_hashfields_adjust(struct mlx5_flow_rss_desc *rss_desc,
1062 int tunnel __rte_unused, uint64_t layer_types,
1063 uint64_t hash_fields)
1065 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
1066 int rss_request_inner = rss_desc->level >= 2;
1068 /* Check RSS hash level for tunnel. */
1069 if (tunnel && rss_request_inner)
1070 hash_fields |= IBV_RX_HASH_INNER;
1071 else if (tunnel || rss_request_inner)
1074 /* Check if requested layer matches RSS hash fields. */
1075 if (!(rss_desc->types & layer_types))
1081 * Lookup and set the ptype in the data Rx part. A single Ptype can be used,
1082 * if several tunnel rules are used on this queue, the tunnel ptype will be
1086 * Rx queue to update.
1089 flow_rxq_tunnel_ptype_update(struct mlx5_rxq_ctrl *rxq_ctrl)
1092 uint32_t tunnel_ptype = 0;
1094 /* Look up for the ptype to use. */
1095 for (i = 0; i != MLX5_FLOW_TUNNEL; ++i) {
1096 if (!rxq_ctrl->flow_tunnels_n[i])
1098 if (!tunnel_ptype) {
1099 tunnel_ptype = tunnels_info[i].ptype;
1105 rxq_ctrl->rxq.tunnel = tunnel_ptype;
1109 * Set the Rx queue flags (Mark/Flag and Tunnel Ptypes) according to the devive
1113 * Pointer to the Ethernet device structure.
1114 * @param[in] dev_handle
1115 * Pointer to device flow handle structure.
1118 flow_drv_rxq_flags_set(struct rte_eth_dev *dev,
1119 struct mlx5_flow_handle *dev_handle)
1121 struct mlx5_priv *priv = dev->data->dev_private;
1122 const int mark = dev_handle->mark;
1123 const int tunnel = !!(dev_handle->layers & MLX5_FLOW_LAYER_TUNNEL);
1124 struct mlx5_hrxq *hrxq;
1127 if (dev_handle->fate_action != MLX5_FLOW_FATE_QUEUE)
1129 hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
1130 dev_handle->rix_hrxq);
1133 for (i = 0; i != hrxq->ind_table->queues_n; ++i) {
1134 int idx = hrxq->ind_table->queues[i];
1135 struct mlx5_rxq_ctrl *rxq_ctrl =
1136 container_of((*priv->rxqs)[idx],
1137 struct mlx5_rxq_ctrl, rxq);
1140 * To support metadata register copy on Tx loopback,
1141 * this must be always enabled (metadata may arive
1142 * from other port - not from local flows only.
1144 if (priv->config.dv_flow_en &&
1145 priv->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
1146 mlx5_flow_ext_mreg_supported(dev)) {
1147 rxq_ctrl->rxq.mark = 1;
1148 rxq_ctrl->flow_mark_n = 1;
1150 rxq_ctrl->rxq.mark = 1;
1151 rxq_ctrl->flow_mark_n++;
1156 /* Increase the counter matching the flow. */
1157 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j) {
1158 if ((tunnels_info[j].tunnel &
1159 dev_handle->layers) ==
1160 tunnels_info[j].tunnel) {
1161 rxq_ctrl->flow_tunnels_n[j]++;
1165 flow_rxq_tunnel_ptype_update(rxq_ctrl);
1171 * Set the Rx queue flags (Mark/Flag and Tunnel Ptypes) for a flow
1174 * Pointer to the Ethernet device structure.
1176 * Pointer to flow structure.
1179 flow_rxq_flags_set(struct rte_eth_dev *dev, struct rte_flow *flow)
1181 struct mlx5_priv *priv = dev->data->dev_private;
1182 uint32_t handle_idx;
1183 struct mlx5_flow_handle *dev_handle;
1185 SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
1186 handle_idx, dev_handle, next)
1187 flow_drv_rxq_flags_set(dev, dev_handle);
1191 * Clear the Rx queue flags (Mark/Flag and Tunnel Ptype) associated with the
1192 * device flow if no other flow uses it with the same kind of request.
1195 * Pointer to Ethernet device.
1196 * @param[in] dev_handle
1197 * Pointer to the device flow handle structure.
1200 flow_drv_rxq_flags_trim(struct rte_eth_dev *dev,
1201 struct mlx5_flow_handle *dev_handle)
1203 struct mlx5_priv *priv = dev->data->dev_private;
1204 const int mark = dev_handle->mark;
1205 const int tunnel = !!(dev_handle->layers & MLX5_FLOW_LAYER_TUNNEL);
1206 struct mlx5_hrxq *hrxq;
1209 if (dev_handle->fate_action != MLX5_FLOW_FATE_QUEUE)
1211 hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
1212 dev_handle->rix_hrxq);
1215 MLX5_ASSERT(dev->data->dev_started);
1216 for (i = 0; i != hrxq->ind_table->queues_n; ++i) {
1217 int idx = hrxq->ind_table->queues[i];
1218 struct mlx5_rxq_ctrl *rxq_ctrl =
1219 container_of((*priv->rxqs)[idx],
1220 struct mlx5_rxq_ctrl, rxq);
1222 if (priv->config.dv_flow_en &&
1223 priv->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
1224 mlx5_flow_ext_mreg_supported(dev)) {
1225 rxq_ctrl->rxq.mark = 1;
1226 rxq_ctrl->flow_mark_n = 1;
1228 rxq_ctrl->flow_mark_n--;
1229 rxq_ctrl->rxq.mark = !!rxq_ctrl->flow_mark_n;
1234 /* Decrease the counter matching the flow. */
1235 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j) {
1236 if ((tunnels_info[j].tunnel &
1237 dev_handle->layers) ==
1238 tunnels_info[j].tunnel) {
1239 rxq_ctrl->flow_tunnels_n[j]--;
1243 flow_rxq_tunnel_ptype_update(rxq_ctrl);
1249 * Clear the Rx queue flags (Mark/Flag and Tunnel Ptype) associated with the
1250 * @p flow if no other flow uses it with the same kind of request.
1253 * Pointer to Ethernet device.
1255 * Pointer to the flow.
1258 flow_rxq_flags_trim(struct rte_eth_dev *dev, struct rte_flow *flow)
1260 struct mlx5_priv *priv = dev->data->dev_private;
1261 uint32_t handle_idx;
1262 struct mlx5_flow_handle *dev_handle;
1264 SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
1265 handle_idx, dev_handle, next)
1266 flow_drv_rxq_flags_trim(dev, dev_handle);
1270 * Clear the Mark/Flag and Tunnel ptype information in all Rx queues.
1273 * Pointer to Ethernet device.
1276 flow_rxq_flags_clear(struct rte_eth_dev *dev)
1278 struct mlx5_priv *priv = dev->data->dev_private;
1281 for (i = 0; i != priv->rxqs_n; ++i) {
1282 struct mlx5_rxq_ctrl *rxq_ctrl;
1285 if (!(*priv->rxqs)[i])
1287 rxq_ctrl = container_of((*priv->rxqs)[i],
1288 struct mlx5_rxq_ctrl, rxq);
1289 rxq_ctrl->flow_mark_n = 0;
1290 rxq_ctrl->rxq.mark = 0;
1291 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j)
1292 rxq_ctrl->flow_tunnels_n[j] = 0;
1293 rxq_ctrl->rxq.tunnel = 0;
1298 * Set the Rx queue dynamic metadata (mask and offset) for a flow
1301 * Pointer to the Ethernet device structure.
1304 mlx5_flow_rxq_dynf_metadata_set(struct rte_eth_dev *dev)
1306 struct mlx5_priv *priv = dev->data->dev_private;
1307 struct mlx5_rxq_data *data;
1310 for (i = 0; i != priv->rxqs_n; ++i) {
1311 if (!(*priv->rxqs)[i])
1313 data = (*priv->rxqs)[i];
1314 if (!rte_flow_dynf_metadata_avail()) {
1315 data->dynf_meta = 0;
1316 data->flow_meta_mask = 0;
1317 data->flow_meta_offset = -1;
1319 data->dynf_meta = 1;
1320 data->flow_meta_mask = rte_flow_dynf_metadata_mask;
1321 data->flow_meta_offset = rte_flow_dynf_metadata_offs;
1327 * return a pointer to the desired action in the list of actions.
1329 * @param[in] actions
1330 * The list of actions to search the action in.
1332 * The action to find.
1335 * Pointer to the action in the list, if found. NULL otherwise.
1337 const struct rte_flow_action *
1338 mlx5_flow_find_action(const struct rte_flow_action *actions,
1339 enum rte_flow_action_type action)
1341 if (actions == NULL)
1343 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++)
1344 if (actions->type == action)
1350 * Validate the flag action.
1352 * @param[in] action_flags
1353 * Bit-fields that holds the actions detected until now.
1355 * Attributes of flow that includes this action.
1357 * Pointer to error structure.
1360 * 0 on success, a negative errno value otherwise and rte_errno is set.
1363 mlx5_flow_validate_action_flag(uint64_t action_flags,
1364 const struct rte_flow_attr *attr,
1365 struct rte_flow_error *error)
1367 if (action_flags & MLX5_FLOW_ACTION_MARK)
1368 return rte_flow_error_set(error, EINVAL,
1369 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1370 "can't mark and flag in same flow");
1371 if (action_flags & MLX5_FLOW_ACTION_FLAG)
1372 return rte_flow_error_set(error, EINVAL,
1373 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1375 " actions in same flow");
1377 return rte_flow_error_set(error, ENOTSUP,
1378 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1379 "flag action not supported for "
1385 * Validate the mark action.
1388 * Pointer to the queue action.
1389 * @param[in] action_flags
1390 * Bit-fields that holds the actions detected until now.
1392 * Attributes of flow that includes this action.
1394 * Pointer to error structure.
1397 * 0 on success, a negative errno value otherwise and rte_errno is set.
1400 mlx5_flow_validate_action_mark(const struct rte_flow_action *action,
1401 uint64_t action_flags,
1402 const struct rte_flow_attr *attr,
1403 struct rte_flow_error *error)
1405 const struct rte_flow_action_mark *mark = action->conf;
1408 return rte_flow_error_set(error, EINVAL,
1409 RTE_FLOW_ERROR_TYPE_ACTION,
1411 "configuration cannot be null");
1412 if (mark->id >= MLX5_FLOW_MARK_MAX)
1413 return rte_flow_error_set(error, EINVAL,
1414 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1416 "mark id must in 0 <= id < "
1417 RTE_STR(MLX5_FLOW_MARK_MAX));
1418 if (action_flags & MLX5_FLOW_ACTION_FLAG)
1419 return rte_flow_error_set(error, EINVAL,
1420 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1421 "can't flag and mark in same flow");
1422 if (action_flags & MLX5_FLOW_ACTION_MARK)
1423 return rte_flow_error_set(error, EINVAL,
1424 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1425 "can't have 2 mark actions in same"
1428 return rte_flow_error_set(error, ENOTSUP,
1429 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1430 "mark action not supported for "
1436 * Validate the drop action.
1438 * @param[in] action_flags
1439 * Bit-fields that holds the actions detected until now.
1441 * Attributes of flow that includes this action.
1443 * Pointer to error structure.
1446 * 0 on success, a negative errno value otherwise and rte_errno is set.
1449 mlx5_flow_validate_action_drop(uint64_t action_flags __rte_unused,
1450 const struct rte_flow_attr *attr,
1451 struct rte_flow_error *error)
1454 return rte_flow_error_set(error, ENOTSUP,
1455 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1456 "drop action not supported for "
1462 * Validate the queue action.
1465 * Pointer to the queue action.
1466 * @param[in] action_flags
1467 * Bit-fields that holds the actions detected until now.
1469 * Pointer to the Ethernet device structure.
1471 * Attributes of flow that includes this action.
1473 * Pointer to error structure.
1476 * 0 on success, a negative errno value otherwise and rte_errno is set.
1479 mlx5_flow_validate_action_queue(const struct rte_flow_action *action,
1480 uint64_t action_flags,
1481 struct rte_eth_dev *dev,
1482 const struct rte_flow_attr *attr,
1483 struct rte_flow_error *error)
1485 struct mlx5_priv *priv = dev->data->dev_private;
1486 const struct rte_flow_action_queue *queue = action->conf;
1488 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
1489 return rte_flow_error_set(error, EINVAL,
1490 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1491 "can't have 2 fate actions in"
1494 return rte_flow_error_set(error, EINVAL,
1495 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1496 NULL, "No Rx queues configured");
1497 if (queue->index >= priv->rxqs_n)
1498 return rte_flow_error_set(error, EINVAL,
1499 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1501 "queue index out of range");
1502 if (!(*priv->rxqs)[queue->index])
1503 return rte_flow_error_set(error, EINVAL,
1504 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1506 "queue is not configured");
1508 return rte_flow_error_set(error, ENOTSUP,
1509 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1510 "queue action not supported for "
1516 * Validate the rss action.
1519 * Pointer to the Ethernet device structure.
1521 * Pointer to the queue action.
1523 * Pointer to error structure.
1526 * 0 on success, a negative errno value otherwise and rte_errno is set.
1529 mlx5_validate_action_rss(struct rte_eth_dev *dev,
1530 const struct rte_flow_action *action,
1531 struct rte_flow_error *error)
1533 struct mlx5_priv *priv = dev->data->dev_private;
1534 const struct rte_flow_action_rss *rss = action->conf;
1537 if (rss->func != RTE_ETH_HASH_FUNCTION_DEFAULT &&
1538 rss->func != RTE_ETH_HASH_FUNCTION_TOEPLITZ)
1539 return rte_flow_error_set(error, ENOTSUP,
1540 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1542 "RSS hash function not supported");
1543 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
1548 return rte_flow_error_set(error, ENOTSUP,
1549 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1551 "tunnel RSS is not supported");
1552 /* allow RSS key_len 0 in case of NULL (default) RSS key. */
1553 if (rss->key_len == 0 && rss->key != NULL)
1554 return rte_flow_error_set(error, ENOTSUP,
1555 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1557 "RSS hash key length 0");
1558 if (rss->key_len > 0 && rss->key_len < MLX5_RSS_HASH_KEY_LEN)
1559 return rte_flow_error_set(error, ENOTSUP,
1560 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1562 "RSS hash key too small");
1563 if (rss->key_len > MLX5_RSS_HASH_KEY_LEN)
1564 return rte_flow_error_set(error, ENOTSUP,
1565 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1567 "RSS hash key too large");
1568 if (rss->queue_num > priv->config.ind_table_max_size)
1569 return rte_flow_error_set(error, ENOTSUP,
1570 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1572 "number of queues too large");
1573 if (rss->types & MLX5_RSS_HF_MASK)
1574 return rte_flow_error_set(error, ENOTSUP,
1575 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1577 "some RSS protocols are not"
1579 if ((rss->types & (ETH_RSS_L3_SRC_ONLY | ETH_RSS_L3_DST_ONLY)) &&
1580 !(rss->types & ETH_RSS_IP))
1581 return rte_flow_error_set(error, EINVAL,
1582 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1583 "L3 partial RSS requested but L3 RSS"
1584 " type not specified");
1585 if ((rss->types & (ETH_RSS_L4_SRC_ONLY | ETH_RSS_L4_DST_ONLY)) &&
1586 !(rss->types & (ETH_RSS_UDP | ETH_RSS_TCP)))
1587 return rte_flow_error_set(error, EINVAL,
1588 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1589 "L4 partial RSS requested but L4 RSS"
1590 " type not specified");
1592 return rte_flow_error_set(error, EINVAL,
1593 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1594 NULL, "No Rx queues configured");
1595 if (!rss->queue_num)
1596 return rte_flow_error_set(error, EINVAL,
1597 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1598 NULL, "No queues configured");
1599 for (i = 0; i != rss->queue_num; ++i) {
1600 if (rss->queue[i] >= priv->rxqs_n)
1601 return rte_flow_error_set
1603 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1604 &rss->queue[i], "queue index out of range");
1605 if (!(*priv->rxqs)[rss->queue[i]])
1606 return rte_flow_error_set
1607 (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1608 &rss->queue[i], "queue is not configured");
1614 * Validate the rss action.
1617 * Pointer to the queue action.
1618 * @param[in] action_flags
1619 * Bit-fields that holds the actions detected until now.
1621 * Pointer to the Ethernet device structure.
1623 * Attributes of flow that includes this action.
1624 * @param[in] item_flags
1625 * Items that were detected.
1627 * Pointer to error structure.
1630 * 0 on success, a negative errno value otherwise and rte_errno is set.
1633 mlx5_flow_validate_action_rss(const struct rte_flow_action *action,
1634 uint64_t action_flags,
1635 struct rte_eth_dev *dev,
1636 const struct rte_flow_attr *attr,
1637 uint64_t item_flags,
1638 struct rte_flow_error *error)
1640 const struct rte_flow_action_rss *rss = action->conf;
1641 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1644 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
1645 return rte_flow_error_set(error, EINVAL,
1646 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1647 "can't have 2 fate actions"
1649 ret = mlx5_validate_action_rss(dev, action, error);
1653 return rte_flow_error_set(error, ENOTSUP,
1654 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1655 "rss action not supported for "
1657 if (rss->level > 1 && !tunnel)
1658 return rte_flow_error_set(error, EINVAL,
1659 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1660 "inner RSS is not supported for "
1661 "non-tunnel flows");
1662 if ((item_flags & MLX5_FLOW_LAYER_ECPRI) &&
1663 !(item_flags & MLX5_FLOW_LAYER_INNER_L4_UDP)) {
1664 return rte_flow_error_set(error, EINVAL,
1665 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1666 "RSS on eCPRI is not supported now");
1672 * Validate the default miss action.
1674 * @param[in] action_flags
1675 * Bit-fields that holds the actions detected until now.
1677 * Pointer to error structure.
1680 * 0 on success, a negative errno value otherwise and rte_errno is set.
1683 mlx5_flow_validate_action_default_miss(uint64_t action_flags,
1684 const struct rte_flow_attr *attr,
1685 struct rte_flow_error *error)
1687 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
1688 return rte_flow_error_set(error, EINVAL,
1689 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1690 "can't have 2 fate actions in"
1693 return rte_flow_error_set(error, ENOTSUP,
1694 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1695 "default miss action not supported "
1698 return rte_flow_error_set(error, ENOTSUP,
1699 RTE_FLOW_ERROR_TYPE_ATTR_GROUP, NULL,
1700 "only group 0 is supported");
1702 return rte_flow_error_set(error, ENOTSUP,
1703 RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
1704 NULL, "transfer is not supported");
1709 * Validate the count action.
1712 * Pointer to the Ethernet device structure.
1714 * Attributes of flow that includes this action.
1716 * Pointer to error structure.
1719 * 0 on success, a negative errno value otherwise and rte_errno is set.
1722 mlx5_flow_validate_action_count(struct rte_eth_dev *dev __rte_unused,
1723 const struct rte_flow_attr *attr,
1724 struct rte_flow_error *error)
1727 return rte_flow_error_set(error, ENOTSUP,
1728 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1729 "count action not supported for "
1735 * Verify the @p attributes will be correctly understood by the NIC and store
1736 * them in the @p flow if everything is correct.
1739 * Pointer to the Ethernet device structure.
1740 * @param[in] attributes
1741 * Pointer to flow attributes
1743 * Pointer to error structure.
1746 * 0 on success, a negative errno value otherwise and rte_errno is set.
1749 mlx5_flow_validate_attributes(struct rte_eth_dev *dev,
1750 const struct rte_flow_attr *attributes,
1751 struct rte_flow_error *error)
1753 struct mlx5_priv *priv = dev->data->dev_private;
1754 uint32_t priority_max = priv->config.flow_prio - 1;
1756 if (attributes->group)
1757 return rte_flow_error_set(error, ENOTSUP,
1758 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
1759 NULL, "groups is not supported");
1760 if (attributes->priority != MLX5_FLOW_PRIO_RSVD &&
1761 attributes->priority >= priority_max)
1762 return rte_flow_error_set(error, ENOTSUP,
1763 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
1764 NULL, "priority out of range");
1765 if (attributes->egress)
1766 return rte_flow_error_set(error, ENOTSUP,
1767 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1768 "egress is not supported");
1769 if (attributes->transfer && !priv->config.dv_esw_en)
1770 return rte_flow_error_set(error, ENOTSUP,
1771 RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
1772 NULL, "transfer is not supported");
1773 if (!attributes->ingress)
1774 return rte_flow_error_set(error, EINVAL,
1775 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
1777 "ingress attribute is mandatory");
1782 * Validate ICMP6 item.
1785 * Item specification.
1786 * @param[in] item_flags
1787 * Bit-fields that holds the items detected until now.
1788 * @param[in] ext_vlan_sup
1789 * Whether extended VLAN features are supported or not.
1791 * Pointer to error structure.
1794 * 0 on success, a negative errno value otherwise and rte_errno is set.
1797 mlx5_flow_validate_item_icmp6(const struct rte_flow_item *item,
1798 uint64_t item_flags,
1799 uint8_t target_protocol,
1800 struct rte_flow_error *error)
1802 const struct rte_flow_item_icmp6 *mask = item->mask;
1803 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1804 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
1805 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
1806 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1807 MLX5_FLOW_LAYER_OUTER_L4;
1810 if (target_protocol != 0xFF && target_protocol != IPPROTO_ICMPV6)
1811 return rte_flow_error_set(error, EINVAL,
1812 RTE_FLOW_ERROR_TYPE_ITEM, item,
1813 "protocol filtering not compatible"
1814 " with ICMP6 layer");
1815 if (!(item_flags & l3m))
1816 return rte_flow_error_set(error, EINVAL,
1817 RTE_FLOW_ERROR_TYPE_ITEM, item,
1818 "IPv6 is mandatory to filter on"
1820 if (item_flags & l4m)
1821 return rte_flow_error_set(error, EINVAL,
1822 RTE_FLOW_ERROR_TYPE_ITEM, item,
1823 "multiple L4 layers not supported");
1825 mask = &rte_flow_item_icmp6_mask;
1826 ret = mlx5_flow_item_acceptable
1827 (item, (const uint8_t *)mask,
1828 (const uint8_t *)&rte_flow_item_icmp6_mask,
1829 sizeof(struct rte_flow_item_icmp6),
1830 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
1837 * Validate ICMP item.
1840 * Item specification.
1841 * @param[in] item_flags
1842 * Bit-fields that holds the items detected until now.
1844 * Pointer to error structure.
1847 * 0 on success, a negative errno value otherwise and rte_errno is set.
1850 mlx5_flow_validate_item_icmp(const struct rte_flow_item *item,
1851 uint64_t item_flags,
1852 uint8_t target_protocol,
1853 struct rte_flow_error *error)
1855 const struct rte_flow_item_icmp *mask = item->mask;
1856 const struct rte_flow_item_icmp nic_mask = {
1857 .hdr.icmp_type = 0xff,
1858 .hdr.icmp_code = 0xff,
1859 .hdr.icmp_ident = RTE_BE16(0xffff),
1860 .hdr.icmp_seq_nb = RTE_BE16(0xffff),
1862 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1863 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
1864 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
1865 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1866 MLX5_FLOW_LAYER_OUTER_L4;
1869 if (target_protocol != 0xFF && target_protocol != IPPROTO_ICMP)
1870 return rte_flow_error_set(error, EINVAL,
1871 RTE_FLOW_ERROR_TYPE_ITEM, item,
1872 "protocol filtering not compatible"
1873 " with ICMP layer");
1874 if (!(item_flags & l3m))
1875 return rte_flow_error_set(error, EINVAL,
1876 RTE_FLOW_ERROR_TYPE_ITEM, item,
1877 "IPv4 is mandatory to filter"
1879 if (item_flags & l4m)
1880 return rte_flow_error_set(error, EINVAL,
1881 RTE_FLOW_ERROR_TYPE_ITEM, item,
1882 "multiple L4 layers not supported");
1885 ret = mlx5_flow_item_acceptable
1886 (item, (const uint8_t *)mask,
1887 (const uint8_t *)&nic_mask,
1888 sizeof(struct rte_flow_item_icmp),
1889 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
1896 * Validate Ethernet item.
1899 * Item specification.
1900 * @param[in] item_flags
1901 * Bit-fields that holds the items detected until now.
1903 * Pointer to error structure.
1906 * 0 on success, a negative errno value otherwise and rte_errno is set.
1909 mlx5_flow_validate_item_eth(const struct rte_flow_item *item,
1910 uint64_t item_flags, bool ext_vlan_sup,
1911 struct rte_flow_error *error)
1913 const struct rte_flow_item_eth *mask = item->mask;
1914 const struct rte_flow_item_eth nic_mask = {
1915 .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
1916 .src.addr_bytes = "\xff\xff\xff\xff\xff\xff",
1917 .type = RTE_BE16(0xffff),
1918 .has_vlan = ext_vlan_sup ? 1 : 0,
1921 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1922 const uint64_t ethm = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
1923 MLX5_FLOW_LAYER_OUTER_L2;
1925 if (item_flags & ethm)
1926 return rte_flow_error_set(error, ENOTSUP,
1927 RTE_FLOW_ERROR_TYPE_ITEM, item,
1928 "multiple L2 layers not supported");
1929 if ((!tunnel && (item_flags & MLX5_FLOW_LAYER_OUTER_L3)) ||
1930 (tunnel && (item_flags & MLX5_FLOW_LAYER_INNER_L3)))
1931 return rte_flow_error_set(error, EINVAL,
1932 RTE_FLOW_ERROR_TYPE_ITEM, item,
1933 "L2 layer should not follow "
1935 if ((!tunnel && (item_flags & MLX5_FLOW_LAYER_OUTER_VLAN)) ||
1936 (tunnel && (item_flags & MLX5_FLOW_LAYER_INNER_VLAN)))
1937 return rte_flow_error_set(error, EINVAL,
1938 RTE_FLOW_ERROR_TYPE_ITEM, item,
1939 "L2 layer should not follow VLAN");
1941 mask = &rte_flow_item_eth_mask;
1942 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1943 (const uint8_t *)&nic_mask,
1944 sizeof(struct rte_flow_item_eth),
1945 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
1950 * Validate VLAN item.
1953 * Item specification.
1954 * @param[in] item_flags
1955 * Bit-fields that holds the items detected until now.
1957 * Ethernet device flow is being created on.
1959 * Pointer to error structure.
1962 * 0 on success, a negative errno value otherwise and rte_errno is set.
1965 mlx5_flow_validate_item_vlan(const struct rte_flow_item *item,
1966 uint64_t item_flags,
1967 struct rte_eth_dev *dev,
1968 struct rte_flow_error *error)
1970 const struct rte_flow_item_vlan *spec = item->spec;
1971 const struct rte_flow_item_vlan *mask = item->mask;
1972 const struct rte_flow_item_vlan nic_mask = {
1973 .tci = RTE_BE16(UINT16_MAX),
1974 .inner_type = RTE_BE16(UINT16_MAX),
1976 uint16_t vlan_tag = 0;
1977 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1979 const uint64_t l34m = tunnel ? (MLX5_FLOW_LAYER_INNER_L3 |
1980 MLX5_FLOW_LAYER_INNER_L4) :
1981 (MLX5_FLOW_LAYER_OUTER_L3 |
1982 MLX5_FLOW_LAYER_OUTER_L4);
1983 const uint64_t vlanm = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
1984 MLX5_FLOW_LAYER_OUTER_VLAN;
1986 if (item_flags & vlanm)
1987 return rte_flow_error_set(error, EINVAL,
1988 RTE_FLOW_ERROR_TYPE_ITEM, item,
1989 "multiple VLAN layers not supported");
1990 else if ((item_flags & l34m) != 0)
1991 return rte_flow_error_set(error, EINVAL,
1992 RTE_FLOW_ERROR_TYPE_ITEM, item,
1993 "VLAN cannot follow L3/L4 layer");
1995 mask = &rte_flow_item_vlan_mask;
1996 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1997 (const uint8_t *)&nic_mask,
1998 sizeof(struct rte_flow_item_vlan),
1999 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2002 if (!tunnel && mask->tci != RTE_BE16(0x0fff)) {
2003 struct mlx5_priv *priv = dev->data->dev_private;
2005 if (priv->vmwa_context) {
2007 * Non-NULL context means we have a virtual machine
2008 * and SR-IOV enabled, we have to create VLAN interface
2009 * to make hypervisor to setup E-Switch vport
2010 * context correctly. We avoid creating the multiple
2011 * VLAN interfaces, so we cannot support VLAN tag mask.
2013 return rte_flow_error_set(error, EINVAL,
2014 RTE_FLOW_ERROR_TYPE_ITEM,
2016 "VLAN tag mask is not"
2017 " supported in virtual"
2022 vlan_tag = spec->tci;
2023 vlan_tag &= mask->tci;
2026 * From verbs perspective an empty VLAN is equivalent
2027 * to a packet without VLAN layer.
2030 return rte_flow_error_set(error, EINVAL,
2031 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
2033 "VLAN cannot be empty");
2038 * Validate IPV4 item.
2041 * Item specification.
2042 * @param[in] item_flags
2043 * Bit-fields that holds the items detected until now.
2044 * @param[in] last_item
2045 * Previous validated item in the pattern items.
2046 * @param[in] ether_type
2047 * Type in the ethernet layer header (including dot1q).
2048 * @param[in] acc_mask
2049 * Acceptable mask, if NULL default internal default mask
2050 * will be used to check whether item fields are supported.
2051 * @param[in] range_accepted
2052 * True if range of values is accepted for specific fields, false otherwise.
2054 * Pointer to error structure.
2057 * 0 on success, a negative errno value otherwise and rte_errno is set.
2060 mlx5_flow_validate_item_ipv4(const struct rte_flow_item *item,
2061 uint64_t item_flags,
2063 uint16_t ether_type,
2064 const struct rte_flow_item_ipv4 *acc_mask,
2065 bool range_accepted,
2066 struct rte_flow_error *error)
2068 const struct rte_flow_item_ipv4 *mask = item->mask;
2069 const struct rte_flow_item_ipv4 *spec = item->spec;
2070 const struct rte_flow_item_ipv4 nic_mask = {
2072 .src_addr = RTE_BE32(0xffffffff),
2073 .dst_addr = RTE_BE32(0xffffffff),
2074 .type_of_service = 0xff,
2075 .next_proto_id = 0xff,
2078 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2079 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2080 MLX5_FLOW_LAYER_OUTER_L3;
2081 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2082 MLX5_FLOW_LAYER_OUTER_L4;
2084 uint8_t next_proto = 0xFF;
2085 const uint64_t l2_vlan = (MLX5_FLOW_LAYER_L2 |
2086 MLX5_FLOW_LAYER_OUTER_VLAN |
2087 MLX5_FLOW_LAYER_INNER_VLAN);
2089 if ((last_item & l2_vlan) && ether_type &&
2090 ether_type != RTE_ETHER_TYPE_IPV4)
2091 return rte_flow_error_set(error, EINVAL,
2092 RTE_FLOW_ERROR_TYPE_ITEM, item,
2093 "IPv4 cannot follow L2/VLAN layer "
2094 "which ether type is not IPv4");
2095 if (item_flags & MLX5_FLOW_LAYER_IPIP) {
2097 next_proto = mask->hdr.next_proto_id &
2098 spec->hdr.next_proto_id;
2099 if (next_proto == IPPROTO_IPIP || next_proto == IPPROTO_IPV6)
2100 return rte_flow_error_set(error, EINVAL,
2101 RTE_FLOW_ERROR_TYPE_ITEM,
2106 if (item_flags & MLX5_FLOW_LAYER_IPV6_ENCAP)
2107 return rte_flow_error_set(error, EINVAL,
2108 RTE_FLOW_ERROR_TYPE_ITEM, item,
2109 "wrong tunnel type - IPv6 specified "
2110 "but IPv4 item provided");
2111 if (item_flags & l3m)
2112 return rte_flow_error_set(error, ENOTSUP,
2113 RTE_FLOW_ERROR_TYPE_ITEM, item,
2114 "multiple L3 layers not supported");
2115 else if (item_flags & l4m)
2116 return rte_flow_error_set(error, EINVAL,
2117 RTE_FLOW_ERROR_TYPE_ITEM, item,
2118 "L3 cannot follow an L4 layer.");
2119 else if ((item_flags & MLX5_FLOW_LAYER_NVGRE) &&
2120 !(item_flags & MLX5_FLOW_LAYER_INNER_L2))
2121 return rte_flow_error_set(error, EINVAL,
2122 RTE_FLOW_ERROR_TYPE_ITEM, item,
2123 "L3 cannot follow an NVGRE layer.");
2125 mask = &rte_flow_item_ipv4_mask;
2126 else if (mask->hdr.next_proto_id != 0 &&
2127 mask->hdr.next_proto_id != 0xff)
2128 return rte_flow_error_set(error, EINVAL,
2129 RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
2130 "partial mask is not supported"
2132 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2133 acc_mask ? (const uint8_t *)acc_mask
2134 : (const uint8_t *)&nic_mask,
2135 sizeof(struct rte_flow_item_ipv4),
2136 range_accepted, error);
2143 * Validate IPV6 item.
2146 * Item specification.
2147 * @param[in] item_flags
2148 * Bit-fields that holds the items detected until now.
2149 * @param[in] last_item
2150 * Previous validated item in the pattern items.
2151 * @param[in] ether_type
2152 * Type in the ethernet layer header (including dot1q).
2153 * @param[in] acc_mask
2154 * Acceptable mask, if NULL default internal default mask
2155 * will be used to check whether item fields are supported.
2157 * Pointer to error structure.
2160 * 0 on success, a negative errno value otherwise and rte_errno is set.
2163 mlx5_flow_validate_item_ipv6(const struct rte_flow_item *item,
2164 uint64_t item_flags,
2166 uint16_t ether_type,
2167 const struct rte_flow_item_ipv6 *acc_mask,
2168 struct rte_flow_error *error)
2170 const struct rte_flow_item_ipv6 *mask = item->mask;
2171 const struct rte_flow_item_ipv6 *spec = item->spec;
2172 const struct rte_flow_item_ipv6 nic_mask = {
2175 "\xff\xff\xff\xff\xff\xff\xff\xff"
2176 "\xff\xff\xff\xff\xff\xff\xff\xff",
2178 "\xff\xff\xff\xff\xff\xff\xff\xff"
2179 "\xff\xff\xff\xff\xff\xff\xff\xff",
2180 .vtc_flow = RTE_BE32(0xffffffff),
2184 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2185 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2186 MLX5_FLOW_LAYER_OUTER_L3;
2187 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2188 MLX5_FLOW_LAYER_OUTER_L4;
2190 uint8_t next_proto = 0xFF;
2191 const uint64_t l2_vlan = (MLX5_FLOW_LAYER_L2 |
2192 MLX5_FLOW_LAYER_OUTER_VLAN |
2193 MLX5_FLOW_LAYER_INNER_VLAN);
2195 if ((last_item & l2_vlan) && ether_type &&
2196 ether_type != RTE_ETHER_TYPE_IPV6)
2197 return rte_flow_error_set(error, EINVAL,
2198 RTE_FLOW_ERROR_TYPE_ITEM, item,
2199 "IPv6 cannot follow L2/VLAN layer "
2200 "which ether type is not IPv6");
2201 if (mask && mask->hdr.proto == UINT8_MAX && spec)
2202 next_proto = spec->hdr.proto;
2203 if (item_flags & MLX5_FLOW_LAYER_IPV6_ENCAP) {
2204 if (next_proto == IPPROTO_IPIP || next_proto == IPPROTO_IPV6)
2205 return rte_flow_error_set(error, EINVAL,
2206 RTE_FLOW_ERROR_TYPE_ITEM,
2211 if (next_proto == IPPROTO_HOPOPTS ||
2212 next_proto == IPPROTO_ROUTING ||
2213 next_proto == IPPROTO_FRAGMENT ||
2214 next_proto == IPPROTO_ESP ||
2215 next_proto == IPPROTO_AH ||
2216 next_proto == IPPROTO_DSTOPTS)
2217 return rte_flow_error_set(error, EINVAL,
2218 RTE_FLOW_ERROR_TYPE_ITEM, item,
2219 "IPv6 proto (next header) should "
2220 "not be set as extension header");
2221 if (item_flags & MLX5_FLOW_LAYER_IPIP)
2222 return rte_flow_error_set(error, EINVAL,
2223 RTE_FLOW_ERROR_TYPE_ITEM, item,
2224 "wrong tunnel type - IPv4 specified "
2225 "but IPv6 item provided");
2226 if (item_flags & l3m)
2227 return rte_flow_error_set(error, ENOTSUP,
2228 RTE_FLOW_ERROR_TYPE_ITEM, item,
2229 "multiple L3 layers not supported");
2230 else if (item_flags & l4m)
2231 return rte_flow_error_set(error, EINVAL,
2232 RTE_FLOW_ERROR_TYPE_ITEM, item,
2233 "L3 cannot follow an L4 layer.");
2234 else if ((item_flags & MLX5_FLOW_LAYER_NVGRE) &&
2235 !(item_flags & MLX5_FLOW_LAYER_INNER_L2))
2236 return rte_flow_error_set(error, EINVAL,
2237 RTE_FLOW_ERROR_TYPE_ITEM, item,
2238 "L3 cannot follow an NVGRE layer.");
2240 mask = &rte_flow_item_ipv6_mask;
2241 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2242 acc_mask ? (const uint8_t *)acc_mask
2243 : (const uint8_t *)&nic_mask,
2244 sizeof(struct rte_flow_item_ipv6),
2245 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2252 * Validate UDP item.
2255 * Item specification.
2256 * @param[in] item_flags
2257 * Bit-fields that holds the items detected until now.
2258 * @param[in] target_protocol
2259 * The next protocol in the previous item.
2260 * @param[in] flow_mask
2261 * mlx5 flow-specific (DV, verbs, etc.) supported header fields mask.
2263 * Pointer to error structure.
2266 * 0 on success, a negative errno value otherwise and rte_errno is set.
2269 mlx5_flow_validate_item_udp(const struct rte_flow_item *item,
2270 uint64_t item_flags,
2271 uint8_t target_protocol,
2272 struct rte_flow_error *error)
2274 const struct rte_flow_item_udp *mask = item->mask;
2275 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2276 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2277 MLX5_FLOW_LAYER_OUTER_L3;
2278 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2279 MLX5_FLOW_LAYER_OUTER_L4;
2282 if (target_protocol != 0xff && target_protocol != IPPROTO_UDP)
2283 return rte_flow_error_set(error, EINVAL,
2284 RTE_FLOW_ERROR_TYPE_ITEM, item,
2285 "protocol filtering not compatible"
2287 if (!(item_flags & l3m))
2288 return rte_flow_error_set(error, EINVAL,
2289 RTE_FLOW_ERROR_TYPE_ITEM, item,
2290 "L3 is mandatory to filter on L4");
2291 if (item_flags & l4m)
2292 return rte_flow_error_set(error, EINVAL,
2293 RTE_FLOW_ERROR_TYPE_ITEM, item,
2294 "multiple L4 layers not supported");
2296 mask = &rte_flow_item_udp_mask;
2297 ret = mlx5_flow_item_acceptable
2298 (item, (const uint8_t *)mask,
2299 (const uint8_t *)&rte_flow_item_udp_mask,
2300 sizeof(struct rte_flow_item_udp), MLX5_ITEM_RANGE_NOT_ACCEPTED,
2308 * Validate TCP item.
2311 * Item specification.
2312 * @param[in] item_flags
2313 * Bit-fields that holds the items detected until now.
2314 * @param[in] target_protocol
2315 * The next protocol in the previous item.
2317 * Pointer to error structure.
2320 * 0 on success, a negative errno value otherwise and rte_errno is set.
2323 mlx5_flow_validate_item_tcp(const struct rte_flow_item *item,
2324 uint64_t item_flags,
2325 uint8_t target_protocol,
2326 const struct rte_flow_item_tcp *flow_mask,
2327 struct rte_flow_error *error)
2329 const struct rte_flow_item_tcp *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 MLX5_ASSERT(flow_mask);
2338 if (target_protocol != 0xff && target_protocol != IPPROTO_TCP)
2339 return rte_flow_error_set(error, EINVAL,
2340 RTE_FLOW_ERROR_TYPE_ITEM, item,
2341 "protocol filtering not compatible"
2343 if (!(item_flags & l3m))
2344 return rte_flow_error_set(error, EINVAL,
2345 RTE_FLOW_ERROR_TYPE_ITEM, item,
2346 "L3 is mandatory to filter on L4");
2347 if (item_flags & l4m)
2348 return rte_flow_error_set(error, EINVAL,
2349 RTE_FLOW_ERROR_TYPE_ITEM, item,
2350 "multiple L4 layers not supported");
2352 mask = &rte_flow_item_tcp_mask;
2353 ret = mlx5_flow_item_acceptable
2354 (item, (const uint8_t *)mask,
2355 (const uint8_t *)flow_mask,
2356 sizeof(struct rte_flow_item_tcp), MLX5_ITEM_RANGE_NOT_ACCEPTED,
2364 * Validate VXLAN item.
2367 * Item specification.
2368 * @param[in] item_flags
2369 * Bit-fields that holds the items detected until now.
2370 * @param[in] target_protocol
2371 * The next protocol in the previous item.
2373 * Pointer to error structure.
2376 * 0 on success, a negative errno value otherwise and rte_errno is set.
2379 mlx5_flow_validate_item_vxlan(const struct rte_flow_item *item,
2380 uint64_t item_flags,
2381 struct rte_flow_error *error)
2383 const struct rte_flow_item_vxlan *spec = item->spec;
2384 const struct rte_flow_item_vxlan *mask = item->mask;
2389 } id = { .vlan_id = 0, };
2392 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2393 return rte_flow_error_set(error, ENOTSUP,
2394 RTE_FLOW_ERROR_TYPE_ITEM, item,
2395 "multiple tunnel layers not"
2398 * Verify only UDPv4 is present as defined in
2399 * https://tools.ietf.org/html/rfc7348
2401 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2402 return rte_flow_error_set(error, EINVAL,
2403 RTE_FLOW_ERROR_TYPE_ITEM, item,
2404 "no outer UDP layer found");
2406 mask = &rte_flow_item_vxlan_mask;
2407 ret = mlx5_flow_item_acceptable
2408 (item, (const uint8_t *)mask,
2409 (const uint8_t *)&rte_flow_item_vxlan_mask,
2410 sizeof(struct rte_flow_item_vxlan),
2411 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2415 memcpy(&id.vni[1], spec->vni, 3);
2416 memcpy(&id.vni[1], mask->vni, 3);
2418 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
2419 return rte_flow_error_set(error, ENOTSUP,
2420 RTE_FLOW_ERROR_TYPE_ITEM, item,
2421 "VXLAN tunnel must be fully defined");
2426 * Validate VXLAN_GPE item.
2429 * Item specification.
2430 * @param[in] item_flags
2431 * Bit-fields that holds the items detected until now.
2433 * Pointer to the private data structure.
2434 * @param[in] target_protocol
2435 * The next protocol in the previous item.
2437 * Pointer to error structure.
2440 * 0 on success, a negative errno value otherwise and rte_errno is set.
2443 mlx5_flow_validate_item_vxlan_gpe(const struct rte_flow_item *item,
2444 uint64_t item_flags,
2445 struct rte_eth_dev *dev,
2446 struct rte_flow_error *error)
2448 struct mlx5_priv *priv = dev->data->dev_private;
2449 const struct rte_flow_item_vxlan_gpe *spec = item->spec;
2450 const struct rte_flow_item_vxlan_gpe *mask = item->mask;
2455 } id = { .vlan_id = 0, };
2457 if (!priv->config.l3_vxlan_en)
2458 return rte_flow_error_set(error, ENOTSUP,
2459 RTE_FLOW_ERROR_TYPE_ITEM, item,
2460 "L3 VXLAN is not enabled by device"
2461 " parameter and/or not configured in"
2463 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2464 return rte_flow_error_set(error, ENOTSUP,
2465 RTE_FLOW_ERROR_TYPE_ITEM, item,
2466 "multiple tunnel layers not"
2469 * Verify only UDPv4 is present as defined in
2470 * https://tools.ietf.org/html/rfc7348
2472 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2473 return rte_flow_error_set(error, EINVAL,
2474 RTE_FLOW_ERROR_TYPE_ITEM, item,
2475 "no outer UDP layer found");
2477 mask = &rte_flow_item_vxlan_gpe_mask;
2478 ret = mlx5_flow_item_acceptable
2479 (item, (const uint8_t *)mask,
2480 (const uint8_t *)&rte_flow_item_vxlan_gpe_mask,
2481 sizeof(struct rte_flow_item_vxlan_gpe),
2482 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2487 return rte_flow_error_set(error, ENOTSUP,
2488 RTE_FLOW_ERROR_TYPE_ITEM,
2490 "VxLAN-GPE protocol"
2492 memcpy(&id.vni[1], spec->vni, 3);
2493 memcpy(&id.vni[1], mask->vni, 3);
2495 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
2496 return rte_flow_error_set(error, ENOTSUP,
2497 RTE_FLOW_ERROR_TYPE_ITEM, item,
2498 "VXLAN-GPE tunnel must be fully"
2503 * Validate GRE Key item.
2506 * Item specification.
2507 * @param[in] item_flags
2508 * Bit flags to mark detected items.
2509 * @param[in] gre_item
2510 * Pointer to gre_item
2512 * Pointer to error structure.
2515 * 0 on success, a negative errno value otherwise and rte_errno is set.
2518 mlx5_flow_validate_item_gre_key(const struct rte_flow_item *item,
2519 uint64_t item_flags,
2520 const struct rte_flow_item *gre_item,
2521 struct rte_flow_error *error)
2523 const rte_be32_t *mask = item->mask;
2525 rte_be32_t gre_key_default_mask = RTE_BE32(UINT32_MAX);
2526 const struct rte_flow_item_gre *gre_spec;
2527 const struct rte_flow_item_gre *gre_mask;
2529 if (item_flags & MLX5_FLOW_LAYER_GRE_KEY)
2530 return rte_flow_error_set(error, ENOTSUP,
2531 RTE_FLOW_ERROR_TYPE_ITEM, item,
2532 "Multiple GRE key not support");
2533 if (!(item_flags & MLX5_FLOW_LAYER_GRE))
2534 return rte_flow_error_set(error, ENOTSUP,
2535 RTE_FLOW_ERROR_TYPE_ITEM, item,
2536 "No preceding GRE header");
2537 if (item_flags & MLX5_FLOW_LAYER_INNER)
2538 return rte_flow_error_set(error, ENOTSUP,
2539 RTE_FLOW_ERROR_TYPE_ITEM, item,
2540 "GRE key following a wrong item");
2541 gre_mask = gre_item->mask;
2543 gre_mask = &rte_flow_item_gre_mask;
2544 gre_spec = gre_item->spec;
2545 if (gre_spec && (gre_mask->c_rsvd0_ver & RTE_BE16(0x2000)) &&
2546 !(gre_spec->c_rsvd0_ver & RTE_BE16(0x2000)))
2547 return rte_flow_error_set(error, EINVAL,
2548 RTE_FLOW_ERROR_TYPE_ITEM, item,
2549 "Key bit must be on");
2552 mask = &gre_key_default_mask;
2553 ret = mlx5_flow_item_acceptable
2554 (item, (const uint8_t *)mask,
2555 (const uint8_t *)&gre_key_default_mask,
2556 sizeof(rte_be32_t), MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2561 * Validate GRE item.
2564 * Item specification.
2565 * @param[in] item_flags
2566 * Bit flags to mark detected items.
2567 * @param[in] target_protocol
2568 * The next protocol in the previous item.
2570 * Pointer to error structure.
2573 * 0 on success, a negative errno value otherwise and rte_errno is set.
2576 mlx5_flow_validate_item_gre(const struct rte_flow_item *item,
2577 uint64_t item_flags,
2578 uint8_t target_protocol,
2579 struct rte_flow_error *error)
2581 const struct rte_flow_item_gre *spec __rte_unused = item->spec;
2582 const struct rte_flow_item_gre *mask = item->mask;
2584 const struct rte_flow_item_gre nic_mask = {
2585 .c_rsvd0_ver = RTE_BE16(0xB000),
2586 .protocol = RTE_BE16(UINT16_MAX),
2589 if (target_protocol != 0xff && target_protocol != IPPROTO_GRE)
2590 return rte_flow_error_set(error, EINVAL,
2591 RTE_FLOW_ERROR_TYPE_ITEM, item,
2592 "protocol filtering not compatible"
2593 " with this GRE layer");
2594 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2595 return rte_flow_error_set(error, ENOTSUP,
2596 RTE_FLOW_ERROR_TYPE_ITEM, item,
2597 "multiple tunnel layers not"
2599 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3))
2600 return rte_flow_error_set(error, ENOTSUP,
2601 RTE_FLOW_ERROR_TYPE_ITEM, item,
2602 "L3 Layer is missing");
2604 mask = &rte_flow_item_gre_mask;
2605 ret = mlx5_flow_item_acceptable
2606 (item, (const uint8_t *)mask,
2607 (const uint8_t *)&nic_mask,
2608 sizeof(struct rte_flow_item_gre), MLX5_ITEM_RANGE_NOT_ACCEPTED,
2612 #ifndef HAVE_MLX5DV_DR
2613 #ifndef HAVE_IBV_DEVICE_MPLS_SUPPORT
2614 if (spec && (spec->protocol & mask->protocol))
2615 return rte_flow_error_set(error, ENOTSUP,
2616 RTE_FLOW_ERROR_TYPE_ITEM, item,
2617 "without MPLS support the"
2618 " specification cannot be used for"
2626 * Validate Geneve item.
2629 * Item specification.
2630 * @param[in] itemFlags
2631 * Bit-fields that holds the items detected until now.
2633 * Pointer to the private data structure.
2635 * Pointer to error structure.
2638 * 0 on success, a negative errno value otherwise and rte_errno is set.
2642 mlx5_flow_validate_item_geneve(const struct rte_flow_item *item,
2643 uint64_t item_flags,
2644 struct rte_eth_dev *dev,
2645 struct rte_flow_error *error)
2647 struct mlx5_priv *priv = dev->data->dev_private;
2648 const struct rte_flow_item_geneve *spec = item->spec;
2649 const struct rte_flow_item_geneve *mask = item->mask;
2652 uint8_t opt_len = priv->config.hca_attr.geneve_max_opt_len ?
2653 MLX5_GENEVE_OPT_LEN_1 : MLX5_GENEVE_OPT_LEN_0;
2654 const struct rte_flow_item_geneve nic_mask = {
2655 .ver_opt_len_o_c_rsvd0 = RTE_BE16(0x3f80),
2656 .vni = "\xff\xff\xff",
2657 .protocol = RTE_BE16(UINT16_MAX),
2660 if (!priv->config.hca_attr.tunnel_stateless_geneve_rx)
2661 return rte_flow_error_set(error, ENOTSUP,
2662 RTE_FLOW_ERROR_TYPE_ITEM, item,
2663 "L3 Geneve is not enabled by device"
2664 " parameter and/or not configured in"
2666 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2667 return rte_flow_error_set(error, ENOTSUP,
2668 RTE_FLOW_ERROR_TYPE_ITEM, item,
2669 "multiple tunnel layers not"
2672 * Verify only UDPv4 is present as defined in
2673 * https://tools.ietf.org/html/rfc7348
2675 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2676 return rte_flow_error_set(error, EINVAL,
2677 RTE_FLOW_ERROR_TYPE_ITEM, item,
2678 "no outer UDP layer found");
2680 mask = &rte_flow_item_geneve_mask;
2681 ret = mlx5_flow_item_acceptable
2682 (item, (const uint8_t *)mask,
2683 (const uint8_t *)&nic_mask,
2684 sizeof(struct rte_flow_item_geneve),
2685 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2689 gbhdr = rte_be_to_cpu_16(spec->ver_opt_len_o_c_rsvd0);
2690 if (MLX5_GENEVE_VER_VAL(gbhdr) ||
2691 MLX5_GENEVE_CRITO_VAL(gbhdr) ||
2692 MLX5_GENEVE_RSVD_VAL(gbhdr) || spec->rsvd1)
2693 return rte_flow_error_set(error, ENOTSUP,
2694 RTE_FLOW_ERROR_TYPE_ITEM,
2696 "Geneve protocol unsupported"
2697 " fields are being used");
2698 if (MLX5_GENEVE_OPTLEN_VAL(gbhdr) > opt_len)
2699 return rte_flow_error_set
2701 RTE_FLOW_ERROR_TYPE_ITEM,
2703 "Unsupported Geneve options length");
2705 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
2706 return rte_flow_error_set
2708 RTE_FLOW_ERROR_TYPE_ITEM, item,
2709 "Geneve tunnel must be fully defined");
2714 * Validate MPLS item.
2717 * Pointer to the rte_eth_dev structure.
2719 * Item specification.
2720 * @param[in] item_flags
2721 * Bit-fields that holds the items detected until now.
2722 * @param[in] prev_layer
2723 * The protocol layer indicated in previous item.
2725 * Pointer to error structure.
2728 * 0 on success, a negative errno value otherwise and rte_errno is set.
2731 mlx5_flow_validate_item_mpls(struct rte_eth_dev *dev __rte_unused,
2732 const struct rte_flow_item *item __rte_unused,
2733 uint64_t item_flags __rte_unused,
2734 uint64_t prev_layer __rte_unused,
2735 struct rte_flow_error *error)
2737 #ifdef HAVE_IBV_DEVICE_MPLS_SUPPORT
2738 const struct rte_flow_item_mpls *mask = item->mask;
2739 struct mlx5_priv *priv = dev->data->dev_private;
2742 if (!priv->config.mpls_en)
2743 return rte_flow_error_set(error, ENOTSUP,
2744 RTE_FLOW_ERROR_TYPE_ITEM, item,
2745 "MPLS not supported or"
2746 " disabled in firmware"
2748 /* MPLS over IP, UDP, GRE is allowed */
2749 if (!(prev_layer & (MLX5_FLOW_LAYER_OUTER_L3 |
2750 MLX5_FLOW_LAYER_OUTER_L4_UDP |
2751 MLX5_FLOW_LAYER_GRE |
2752 MLX5_FLOW_LAYER_GRE_KEY)))
2753 return rte_flow_error_set(error, EINVAL,
2754 RTE_FLOW_ERROR_TYPE_ITEM, item,
2755 "protocol filtering not compatible"
2756 " with MPLS layer");
2757 /* Multi-tunnel isn't allowed but MPLS over GRE is an exception. */
2758 if ((item_flags & MLX5_FLOW_LAYER_TUNNEL) &&
2759 !(item_flags & MLX5_FLOW_LAYER_GRE))
2760 return rte_flow_error_set(error, ENOTSUP,
2761 RTE_FLOW_ERROR_TYPE_ITEM, item,
2762 "multiple tunnel layers not"
2765 mask = &rte_flow_item_mpls_mask;
2766 ret = mlx5_flow_item_acceptable
2767 (item, (const uint8_t *)mask,
2768 (const uint8_t *)&rte_flow_item_mpls_mask,
2769 sizeof(struct rte_flow_item_mpls),
2770 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2775 return rte_flow_error_set(error, ENOTSUP,
2776 RTE_FLOW_ERROR_TYPE_ITEM, item,
2777 "MPLS is not supported by Verbs, please"
2783 * Validate NVGRE item.
2786 * Item specification.
2787 * @param[in] item_flags
2788 * Bit flags to mark detected items.
2789 * @param[in] target_protocol
2790 * The next protocol in the previous item.
2792 * Pointer to error structure.
2795 * 0 on success, a negative errno value otherwise and rte_errno is set.
2798 mlx5_flow_validate_item_nvgre(const struct rte_flow_item *item,
2799 uint64_t item_flags,
2800 uint8_t target_protocol,
2801 struct rte_flow_error *error)
2803 const struct rte_flow_item_nvgre *mask = item->mask;
2806 if (target_protocol != 0xff && target_protocol != IPPROTO_GRE)
2807 return rte_flow_error_set(error, EINVAL,
2808 RTE_FLOW_ERROR_TYPE_ITEM, item,
2809 "protocol filtering not compatible"
2810 " with this GRE layer");
2811 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2812 return rte_flow_error_set(error, ENOTSUP,
2813 RTE_FLOW_ERROR_TYPE_ITEM, item,
2814 "multiple tunnel layers not"
2816 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3))
2817 return rte_flow_error_set(error, ENOTSUP,
2818 RTE_FLOW_ERROR_TYPE_ITEM, item,
2819 "L3 Layer is missing");
2821 mask = &rte_flow_item_nvgre_mask;
2822 ret = mlx5_flow_item_acceptable
2823 (item, (const uint8_t *)mask,
2824 (const uint8_t *)&rte_flow_item_nvgre_mask,
2825 sizeof(struct rte_flow_item_nvgre),
2826 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2833 * Validate eCPRI item.
2836 * Item specification.
2837 * @param[in] item_flags
2838 * Bit-fields that holds the items detected until now.
2839 * @param[in] last_item
2840 * Previous validated item in the pattern items.
2841 * @param[in] ether_type
2842 * Type in the ethernet layer header (including dot1q).
2843 * @param[in] acc_mask
2844 * Acceptable mask, if NULL default internal default mask
2845 * will be used to check whether item fields are supported.
2847 * Pointer to error structure.
2850 * 0 on success, a negative errno value otherwise and rte_errno is set.
2853 mlx5_flow_validate_item_ecpri(const struct rte_flow_item *item,
2854 uint64_t item_flags,
2856 uint16_t ether_type,
2857 const struct rte_flow_item_ecpri *acc_mask,
2858 struct rte_flow_error *error)
2860 const struct rte_flow_item_ecpri *mask = item->mask;
2861 const struct rte_flow_item_ecpri nic_mask = {
2865 RTE_BE32(((const struct rte_ecpri_common_hdr) {
2869 .dummy[0] = 0xFFFFFFFF,
2872 const uint64_t outer_l2_vlan = (MLX5_FLOW_LAYER_OUTER_L2 |
2873 MLX5_FLOW_LAYER_OUTER_VLAN);
2874 struct rte_flow_item_ecpri mask_lo;
2876 if (!(last_item & outer_l2_vlan) &&
2877 last_item != MLX5_FLOW_LAYER_OUTER_L4_UDP)
2878 return rte_flow_error_set(error, EINVAL,
2879 RTE_FLOW_ERROR_TYPE_ITEM, item,
2880 "eCPRI can only follow L2/VLAN layer or UDP layer");
2881 if ((last_item & outer_l2_vlan) && ether_type &&
2882 ether_type != RTE_ETHER_TYPE_ECPRI)
2883 return rte_flow_error_set(error, EINVAL,
2884 RTE_FLOW_ERROR_TYPE_ITEM, item,
2885 "eCPRI cannot follow L2/VLAN layer which ether type is not 0xAEFE");
2886 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2887 return rte_flow_error_set(error, EINVAL,
2888 RTE_FLOW_ERROR_TYPE_ITEM, item,
2889 "eCPRI with tunnel is not supported right now");
2890 if (item_flags & MLX5_FLOW_LAYER_OUTER_L3)
2891 return rte_flow_error_set(error, ENOTSUP,
2892 RTE_FLOW_ERROR_TYPE_ITEM, item,
2893 "multiple L3 layers not supported");
2894 else if (item_flags & MLX5_FLOW_LAYER_OUTER_L4_TCP)
2895 return rte_flow_error_set(error, EINVAL,
2896 RTE_FLOW_ERROR_TYPE_ITEM, item,
2897 "eCPRI cannot coexist with a TCP layer");
2898 /* In specification, eCPRI could be over UDP layer. */
2899 else if (item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP)
2900 return rte_flow_error_set(error, EINVAL,
2901 RTE_FLOW_ERROR_TYPE_ITEM, item,
2902 "eCPRI over UDP layer is not yet supported right now");
2903 /* Mask for type field in common header could be zero. */
2905 mask = &rte_flow_item_ecpri_mask;
2906 mask_lo.hdr.common.u32 = rte_be_to_cpu_32(mask->hdr.common.u32);
2907 /* Input mask is in big-endian format. */
2908 if (mask_lo.hdr.common.type != 0 && mask_lo.hdr.common.type != 0xff)
2909 return rte_flow_error_set(error, EINVAL,
2910 RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
2911 "partial mask is not supported for protocol");
2912 else if (mask_lo.hdr.common.type == 0 && mask->hdr.dummy[0] != 0)
2913 return rte_flow_error_set(error, EINVAL,
2914 RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
2915 "message header mask must be after a type mask");
2916 return mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2917 acc_mask ? (const uint8_t *)acc_mask
2918 : (const uint8_t *)&nic_mask,
2919 sizeof(struct rte_flow_item_ecpri),
2920 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2924 * Release resource related QUEUE/RSS action split.
2927 * Pointer to Ethernet device.
2929 * Flow to release id's from.
2932 flow_mreg_split_qrss_release(struct rte_eth_dev *dev,
2933 struct rte_flow *flow)
2935 struct mlx5_priv *priv = dev->data->dev_private;
2936 uint32_t handle_idx;
2937 struct mlx5_flow_handle *dev_handle;
2939 SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
2940 handle_idx, dev_handle, next)
2941 if (dev_handle->split_flow_id)
2942 mlx5_ipool_free(priv->sh->ipool
2943 [MLX5_IPOOL_RSS_EXPANTION_FLOW_ID],
2944 dev_handle->split_flow_id);
2948 flow_null_validate(struct rte_eth_dev *dev __rte_unused,
2949 const struct rte_flow_attr *attr __rte_unused,
2950 const struct rte_flow_item items[] __rte_unused,
2951 const struct rte_flow_action actions[] __rte_unused,
2952 bool external __rte_unused,
2953 int hairpin __rte_unused,
2954 struct rte_flow_error *error)
2956 return rte_flow_error_set(error, ENOTSUP,
2957 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
2960 static struct mlx5_flow *
2961 flow_null_prepare(struct rte_eth_dev *dev __rte_unused,
2962 const struct rte_flow_attr *attr __rte_unused,
2963 const struct rte_flow_item items[] __rte_unused,
2964 const struct rte_flow_action actions[] __rte_unused,
2965 struct rte_flow_error *error)
2967 rte_flow_error_set(error, ENOTSUP,
2968 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
2973 flow_null_translate(struct rte_eth_dev *dev __rte_unused,
2974 struct mlx5_flow *dev_flow __rte_unused,
2975 const struct rte_flow_attr *attr __rte_unused,
2976 const struct rte_flow_item items[] __rte_unused,
2977 const struct rte_flow_action actions[] __rte_unused,
2978 struct rte_flow_error *error)
2980 return rte_flow_error_set(error, ENOTSUP,
2981 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
2985 flow_null_apply(struct rte_eth_dev *dev __rte_unused,
2986 struct rte_flow *flow __rte_unused,
2987 struct rte_flow_error *error)
2989 return rte_flow_error_set(error, ENOTSUP,
2990 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
2994 flow_null_remove(struct rte_eth_dev *dev __rte_unused,
2995 struct rte_flow *flow __rte_unused)
3000 flow_null_destroy(struct rte_eth_dev *dev __rte_unused,
3001 struct rte_flow *flow __rte_unused)
3006 flow_null_query(struct rte_eth_dev *dev __rte_unused,
3007 struct rte_flow *flow __rte_unused,
3008 const struct rte_flow_action *actions __rte_unused,
3009 void *data __rte_unused,
3010 struct rte_flow_error *error)
3012 return rte_flow_error_set(error, ENOTSUP,
3013 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
3017 flow_null_sync_domain(struct rte_eth_dev *dev __rte_unused,
3018 uint32_t domains __rte_unused,
3019 uint32_t flags __rte_unused)
3024 /* Void driver to protect from null pointer reference. */
3025 const struct mlx5_flow_driver_ops mlx5_flow_null_drv_ops = {
3026 .validate = flow_null_validate,
3027 .prepare = flow_null_prepare,
3028 .translate = flow_null_translate,
3029 .apply = flow_null_apply,
3030 .remove = flow_null_remove,
3031 .destroy = flow_null_destroy,
3032 .query = flow_null_query,
3033 .sync_domain = flow_null_sync_domain,
3037 * Select flow driver type according to flow attributes and device
3041 * Pointer to the dev structure.
3043 * Pointer to the flow attributes.
3046 * flow driver type, MLX5_FLOW_TYPE_MAX otherwise.
3048 static enum mlx5_flow_drv_type
3049 flow_get_drv_type(struct rte_eth_dev *dev, const struct rte_flow_attr *attr)
3051 struct mlx5_priv *priv = dev->data->dev_private;
3052 /* The OS can determine first a specific flow type (DV, VERBS) */
3053 enum mlx5_flow_drv_type type = mlx5_flow_os_get_type();
3055 if (type != MLX5_FLOW_TYPE_MAX)
3057 /* If no OS specific type - continue with DV/VERBS selection */
3058 if (attr->transfer && priv->config.dv_esw_en)
3059 type = MLX5_FLOW_TYPE_DV;
3060 if (!attr->transfer)
3061 type = priv->config.dv_flow_en ? MLX5_FLOW_TYPE_DV :
3062 MLX5_FLOW_TYPE_VERBS;
3066 #define flow_get_drv_ops(type) flow_drv_ops[type]
3069 * Flow driver validation API. This abstracts calling driver specific functions.
3070 * The type of flow driver is determined according to flow attributes.
3073 * Pointer to the dev structure.
3075 * Pointer to the flow attributes.
3077 * Pointer to the list of items.
3078 * @param[in] actions
3079 * Pointer to the list of actions.
3080 * @param[in] external
3081 * This flow rule is created by request external to PMD.
3082 * @param[in] hairpin
3083 * Number of hairpin TX actions, 0 means classic flow.
3085 * Pointer to the error structure.
3088 * 0 on success, a negative errno value otherwise and rte_errno is set.
3091 flow_drv_validate(struct rte_eth_dev *dev,
3092 const struct rte_flow_attr *attr,
3093 const struct rte_flow_item items[],
3094 const struct rte_flow_action actions[],
3095 bool external, int hairpin, struct rte_flow_error *error)
3097 const struct mlx5_flow_driver_ops *fops;
3098 enum mlx5_flow_drv_type type = flow_get_drv_type(dev, attr);
3100 fops = flow_get_drv_ops(type);
3101 return fops->validate(dev, attr, items, actions, external,
3106 * Flow driver preparation API. This abstracts calling driver specific
3107 * functions. Parent flow (rte_flow) should have driver type (drv_type). It
3108 * calculates the size of memory required for device flow, allocates the memory,
3109 * initializes the device flow and returns the pointer.
3112 * This function initializes device flow structure such as dv or verbs in
3113 * struct mlx5_flow. However, it is caller's responsibility to initialize the
3114 * rest. For example, adding returning device flow to flow->dev_flow list and
3115 * setting backward reference to the flow should be done out of this function.
3116 * layers field is not filled either.
3119 * Pointer to the dev structure.
3121 * Pointer to the flow attributes.
3123 * Pointer to the list of items.
3124 * @param[in] actions
3125 * Pointer to the list of actions.
3126 * @param[in] flow_idx
3127 * This memory pool index to the flow.
3129 * Pointer to the error structure.
3132 * Pointer to device flow on success, otherwise NULL and rte_errno is set.
3134 static inline struct mlx5_flow *
3135 flow_drv_prepare(struct rte_eth_dev *dev,
3136 const struct rte_flow *flow,
3137 const struct rte_flow_attr *attr,
3138 const struct rte_flow_item items[],
3139 const struct rte_flow_action actions[],
3141 struct rte_flow_error *error)
3143 const struct mlx5_flow_driver_ops *fops;
3144 enum mlx5_flow_drv_type type = flow->drv_type;
3145 struct mlx5_flow *mlx5_flow = NULL;
3147 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3148 fops = flow_get_drv_ops(type);
3149 mlx5_flow = fops->prepare(dev, attr, items, actions, error);
3151 mlx5_flow->flow_idx = flow_idx;
3156 * Flow driver translation API. This abstracts calling driver specific
3157 * functions. Parent flow (rte_flow) should have driver type (drv_type). It
3158 * translates a generic flow into a driver flow. flow_drv_prepare() must
3162 * dev_flow->layers could be filled as a result of parsing during translation
3163 * if needed by flow_drv_apply(). dev_flow->flow->actions can also be filled
3164 * if necessary. As a flow can have multiple dev_flows by RSS flow expansion,
3165 * flow->actions could be overwritten even though all the expanded dev_flows
3166 * have the same actions.
3169 * Pointer to the rte dev structure.
3170 * @param[in, out] dev_flow
3171 * Pointer to the mlx5 flow.
3173 * Pointer to the flow attributes.
3175 * Pointer to the list of items.
3176 * @param[in] actions
3177 * Pointer to the list of actions.
3179 * Pointer to the error structure.
3182 * 0 on success, a negative errno value otherwise and rte_errno is set.
3185 flow_drv_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
3186 const struct rte_flow_attr *attr,
3187 const struct rte_flow_item items[],
3188 const struct rte_flow_action actions[],
3189 struct rte_flow_error *error)
3191 const struct mlx5_flow_driver_ops *fops;
3192 enum mlx5_flow_drv_type type = dev_flow->flow->drv_type;
3194 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3195 fops = flow_get_drv_ops(type);
3196 return fops->translate(dev, dev_flow, attr, items, actions, error);
3200 * Flow driver apply API. This abstracts calling driver specific functions.
3201 * Parent flow (rte_flow) should have driver type (drv_type). It applies
3202 * translated driver flows on to device. flow_drv_translate() must precede.
3205 * Pointer to Ethernet device structure.
3206 * @param[in, out] flow
3207 * Pointer to flow structure.
3209 * Pointer to error structure.
3212 * 0 on success, a negative errno value otherwise and rte_errno is set.
3215 flow_drv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
3216 struct rte_flow_error *error)
3218 const struct mlx5_flow_driver_ops *fops;
3219 enum mlx5_flow_drv_type type = flow->drv_type;
3221 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3222 fops = flow_get_drv_ops(type);
3223 return fops->apply(dev, flow, error);
3227 * Flow driver destroy API. This abstracts calling driver specific functions.
3228 * Parent flow (rte_flow) should have driver type (drv_type). It removes a flow
3229 * on device and releases resources of the flow.
3232 * Pointer to Ethernet device.
3233 * @param[in, out] flow
3234 * Pointer to flow structure.
3237 flow_drv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
3239 const struct mlx5_flow_driver_ops *fops;
3240 enum mlx5_flow_drv_type type = flow->drv_type;
3242 flow_mreg_split_qrss_release(dev, flow);
3243 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3244 fops = flow_get_drv_ops(type);
3245 fops->destroy(dev, flow);
3249 * Get RSS action from the action list.
3251 * @param[in] actions
3252 * Pointer to the list of actions.
3255 * Pointer to the RSS action if exist, else return NULL.
3257 static const struct rte_flow_action_rss*
3258 flow_get_rss_action(const struct rte_flow_action actions[])
3260 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3261 switch (actions->type) {
3262 case RTE_FLOW_ACTION_TYPE_RSS:
3263 return (const struct rte_flow_action_rss *)
3273 * Get ASO age action by index.
3276 * Pointer to the Ethernet device structure.
3277 * @param[in] age_idx
3278 * Index to the ASO age action.
3281 * The specified ASO age action.
3283 struct mlx5_aso_age_action*
3284 flow_aso_age_get_by_idx(struct rte_eth_dev *dev, uint32_t age_idx)
3286 uint16_t pool_idx = age_idx & UINT16_MAX;
3287 uint16_t offset = (age_idx >> 16) & UINT16_MAX;
3288 struct mlx5_priv *priv = dev->data->dev_private;
3289 struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
3290 struct mlx5_aso_age_pool *pool = mng->pools[pool_idx];
3292 return &pool->actions[offset - 1];
3295 /* maps shared action to translated non shared in some actions array */
3296 struct mlx5_translated_shared_action {
3297 struct rte_flow_shared_action *action; /**< Shared action */
3298 int index; /**< Index in related array of rte_flow_action */
3302 * Translates actions of type RTE_FLOW_ACTION_TYPE_SHARED to related
3303 * non shared action if translation possible.
3304 * This functionality used to run same execution path for both shared & non
3305 * shared actions on flow create. All necessary preparations for shared
3306 * action handling should be preformed on *shared* actions list returned
3310 * Pointer to Ethernet device.
3311 * @param[in] actions
3312 * List of actions to translate.
3313 * @param[out] shared
3314 * List to store translated shared actions.
3315 * @param[in, out] shared_n
3316 * Size of *shared* array. On return should be updated with number of shared
3317 * actions retrieved from the *actions* list.
3318 * @param[out] translated_actions
3319 * List of actions where all shared actions were translated to non shared
3320 * if possible. NULL if no translation took place.
3322 * Pointer to the error structure.
3325 * 0 on success, a negative errno value otherwise and rte_errno is set.
3328 flow_shared_actions_translate(struct rte_eth_dev *dev,
3329 const struct rte_flow_action actions[],
3330 struct mlx5_translated_shared_action *shared,
3332 struct rte_flow_action **translated_actions,
3333 struct rte_flow_error *error)
3335 struct mlx5_priv *priv = dev->data->dev_private;
3336 struct rte_flow_action *translated = NULL;
3337 size_t actions_size;
3340 struct mlx5_translated_shared_action *shared_end = NULL;
3342 for (n = 0; actions[n].type != RTE_FLOW_ACTION_TYPE_END; n++) {
3343 if (actions[n].type != RTE_FLOW_ACTION_TYPE_SHARED)
3345 if (copied_n == *shared_n) {
3346 return rte_flow_error_set
3347 (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION_NUM,
3348 NULL, "too many shared actions");
3350 rte_memcpy(&shared[copied_n].action, &actions[n].conf,
3351 sizeof(actions[n].conf));
3352 shared[copied_n].index = n;
3356 *shared_n = copied_n;
3359 actions_size = sizeof(struct rte_flow_action) * n;
3360 translated = mlx5_malloc(MLX5_MEM_ZERO, actions_size, 0, SOCKET_ID_ANY);
3365 memcpy(translated, actions, actions_size);
3366 for (shared_end = shared + copied_n; shared < shared_end; shared++) {
3367 struct mlx5_shared_action_rss *shared_rss;
3368 uint32_t act_idx = (uint32_t)(uintptr_t)shared->action;
3369 uint32_t type = act_idx >> MLX5_SHARED_ACTION_TYPE_OFFSET;
3370 uint32_t idx = act_idx & ((1u << MLX5_SHARED_ACTION_TYPE_OFFSET)
3374 case MLX5_SHARED_ACTION_TYPE_RSS:
3375 shared_rss = mlx5_ipool_get
3376 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
3377 translated[shared->index].type =
3378 RTE_FLOW_ACTION_TYPE_RSS;
3379 translated[shared->index].conf =
3380 &shared_rss->origin;
3382 case MLX5_SHARED_ACTION_TYPE_AGE:
3383 if (priv->sh->flow_hit_aso_en) {
3384 translated[shared->index].type =
3385 (enum rte_flow_action_type)
3386 MLX5_RTE_FLOW_ACTION_TYPE_AGE;
3387 translated[shared->index].conf =
3388 (void *)(uintptr_t)idx;
3393 mlx5_free(translated);
3394 return rte_flow_error_set
3395 (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
3396 NULL, "invalid shared action type");
3399 *translated_actions = translated;
3404 * Get Shared RSS action from the action list.
3407 * Pointer to Ethernet device.
3409 * Pointer to the list of actions.
3410 * @param[in] shared_n
3411 * Actions list length.
3414 * The MLX5 RSS action ID if exists, otherwise return 0.
3417 flow_get_shared_rss_action(struct rte_eth_dev *dev,
3418 struct mlx5_translated_shared_action *shared,
3421 struct mlx5_translated_shared_action *shared_end;
3422 struct mlx5_priv *priv = dev->data->dev_private;
3423 struct mlx5_shared_action_rss *shared_rss;
3426 for (shared_end = shared + shared_n; shared < shared_end; shared++) {
3427 uint32_t act_idx = (uint32_t)(uintptr_t)shared->action;
3428 uint32_t type = act_idx >> MLX5_SHARED_ACTION_TYPE_OFFSET;
3429 uint32_t idx = act_idx &
3430 ((1u << MLX5_SHARED_ACTION_TYPE_OFFSET) - 1);
3432 case MLX5_SHARED_ACTION_TYPE_RSS:
3433 shared_rss = mlx5_ipool_get
3434 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
3436 __atomic_add_fetch(&shared_rss->refcnt, 1,
3447 find_graph_root(const struct rte_flow_item pattern[], uint32_t rss_level)
3449 const struct rte_flow_item *item;
3450 unsigned int has_vlan = 0;
3452 for (item = pattern; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
3453 if (item->type == RTE_FLOW_ITEM_TYPE_VLAN) {
3459 return rss_level < 2 ? MLX5_EXPANSION_ROOT_ETH_VLAN :
3460 MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN;
3461 return rss_level < 2 ? MLX5_EXPANSION_ROOT :
3462 MLX5_EXPANSION_ROOT_OUTER;
3466 * Get layer flags from the prefix flow.
3468 * Some flows may be split to several subflows, the prefix subflow gets the
3469 * match items and the suffix sub flow gets the actions.
3470 * Some actions need the user defined match item flags to get the detail for
3472 * This function helps the suffix flow to get the item layer flags from prefix
3475 * @param[in] dev_flow
3476 * Pointer the created preifx subflow.
3479 * The layers get from prefix subflow.
3481 static inline uint64_t
3482 flow_get_prefix_layer_flags(struct mlx5_flow *dev_flow)
3484 uint64_t layers = 0;
3487 * Layers bits could be localization, but usually the compiler will
3488 * help to do the optimization work for source code.
3489 * If no decap actions, use the layers directly.
3491 if (!(dev_flow->act_flags & MLX5_FLOW_ACTION_DECAP))
3492 return dev_flow->handle->layers;
3493 /* Convert L3 layers with decap action. */
3494 if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L3_IPV4)
3495 layers |= MLX5_FLOW_LAYER_OUTER_L3_IPV4;
3496 else if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L3_IPV6)
3497 layers |= MLX5_FLOW_LAYER_OUTER_L3_IPV6;
3498 /* Convert L4 layers with decap action. */
3499 if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L4_TCP)
3500 layers |= MLX5_FLOW_LAYER_OUTER_L4_TCP;
3501 else if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L4_UDP)
3502 layers |= MLX5_FLOW_LAYER_OUTER_L4_UDP;
3507 * Get metadata split action information.
3509 * @param[in] actions
3510 * Pointer to the list of actions.
3512 * Pointer to the return pointer.
3513 * @param[out] qrss_type
3514 * Pointer to the action type to return. RTE_FLOW_ACTION_TYPE_END is returned
3515 * if no QUEUE/RSS is found.
3516 * @param[out] encap_idx
3517 * Pointer to the index of the encap action if exists, otherwise the last
3521 * Total number of actions.
3524 flow_parse_metadata_split_actions_info(const struct rte_flow_action actions[],
3525 const struct rte_flow_action **qrss,
3528 const struct rte_flow_action_raw_encap *raw_encap;
3530 int raw_decap_idx = -1;
3533 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3534 switch (actions->type) {
3535 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
3536 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
3537 *encap_idx = actions_n;
3539 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
3540 raw_decap_idx = actions_n;
3542 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
3543 raw_encap = actions->conf;
3544 if (raw_encap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
3545 *encap_idx = raw_decap_idx != -1 ?
3546 raw_decap_idx : actions_n;
3548 case RTE_FLOW_ACTION_TYPE_QUEUE:
3549 case RTE_FLOW_ACTION_TYPE_RSS:
3557 if (*encap_idx == -1)
3558 *encap_idx = actions_n;
3559 /* Count RTE_FLOW_ACTION_TYPE_END. */
3560 return actions_n + 1;
3564 * Check meter action from the action list.
3566 * @param[in] actions
3567 * Pointer to the list of actions.
3569 * Pointer to the meter exist flag.
3572 * Total number of actions.
3575 flow_check_meter_action(const struct rte_flow_action actions[], uint32_t *mtr)
3581 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3582 switch (actions->type) {
3583 case RTE_FLOW_ACTION_TYPE_METER:
3591 /* Count RTE_FLOW_ACTION_TYPE_END. */
3592 return actions_n + 1;
3596 * Check if the flow should be split due to hairpin.
3597 * The reason for the split is that in current HW we can't
3598 * support encap and push-vlan on Rx, so if a flow contains
3599 * these actions we move it to Tx.
3602 * Pointer to Ethernet device.
3604 * Flow rule attributes.
3605 * @param[in] actions
3606 * Associated actions (list terminated by the END action).
3609 * > 0 the number of actions and the flow should be split,
3610 * 0 when no split required.
3613 flow_check_hairpin_split(struct rte_eth_dev *dev,
3614 const struct rte_flow_attr *attr,
3615 const struct rte_flow_action actions[])
3617 int queue_action = 0;
3620 const struct rte_flow_action_queue *queue;
3621 const struct rte_flow_action_rss *rss;
3622 const struct rte_flow_action_raw_encap *raw_encap;
3623 const struct rte_eth_hairpin_conf *conf;
3627 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3628 switch (actions->type) {
3629 case RTE_FLOW_ACTION_TYPE_QUEUE:
3630 queue = actions->conf;
3633 conf = mlx5_rxq_get_hairpin_conf(dev, queue->index);
3634 if (conf != NULL && !!conf->tx_explicit)
3639 case RTE_FLOW_ACTION_TYPE_RSS:
3640 rss = actions->conf;
3641 if (rss == NULL || rss->queue_num == 0)
3643 conf = mlx5_rxq_get_hairpin_conf(dev, rss->queue[0]);
3644 if (conf != NULL && !!conf->tx_explicit)
3649 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
3650 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
3651 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
3652 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
3653 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
3657 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
3658 raw_encap = actions->conf;
3659 if (raw_encap->size >
3660 (sizeof(struct rte_flow_item_eth) +
3661 sizeof(struct rte_flow_item_ipv4)))
3670 if (split && queue_action)
3675 /* Declare flow create/destroy prototype in advance. */
3677 flow_list_create(struct rte_eth_dev *dev, uint32_t *list,
3678 const struct rte_flow_attr *attr,
3679 const struct rte_flow_item items[],
3680 const struct rte_flow_action actions[],
3681 bool external, struct rte_flow_error *error);
3684 flow_list_destroy(struct rte_eth_dev *dev, uint32_t *list,
3687 struct mlx5_hlist_entry *
3688 flow_dv_mreg_create_cb(struct mlx5_hlist *list, uint64_t key,
3691 struct rte_eth_dev *dev = list->ctx;
3692 struct mlx5_priv *priv = dev->data->dev_private;
3693 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3694 struct mlx5_flow_mreg_copy_resource *mcp_res;
3695 struct rte_flow_error *error = ctx->error;
3698 uint32_t mark_id = key;
3699 struct rte_flow_attr attr = {
3700 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
3703 struct mlx5_rte_flow_item_tag tag_spec = {
3706 struct rte_flow_item items[] = {
3707 [1] = { .type = RTE_FLOW_ITEM_TYPE_END, },
3709 struct rte_flow_action_mark ftag = {
3712 struct mlx5_flow_action_copy_mreg cp_mreg = {
3716 struct rte_flow_action_jump jump = {
3717 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
3719 struct rte_flow_action actions[] = {
3720 [3] = { .type = RTE_FLOW_ACTION_TYPE_END, },
3723 /* Fill the register fileds in the flow. */
3724 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
3728 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_RX, 0, error);
3732 /* Provide the full width of FLAG specific value. */
3733 if (mark_id == (priv->sh->dv_regc0_mask & MLX5_FLOW_MARK_DEFAULT))
3734 tag_spec.data = MLX5_FLOW_MARK_DEFAULT;
3735 /* Build a new flow. */
3736 if (mark_id != MLX5_DEFAULT_COPY_ID) {
3737 items[0] = (struct rte_flow_item){
3738 .type = (enum rte_flow_item_type)
3739 MLX5_RTE_FLOW_ITEM_TYPE_TAG,
3742 items[1] = (struct rte_flow_item){
3743 .type = RTE_FLOW_ITEM_TYPE_END,
3745 actions[0] = (struct rte_flow_action){
3746 .type = (enum rte_flow_action_type)
3747 MLX5_RTE_FLOW_ACTION_TYPE_MARK,
3750 actions[1] = (struct rte_flow_action){
3751 .type = (enum rte_flow_action_type)
3752 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
3755 actions[2] = (struct rte_flow_action){
3756 .type = RTE_FLOW_ACTION_TYPE_JUMP,
3759 actions[3] = (struct rte_flow_action){
3760 .type = RTE_FLOW_ACTION_TYPE_END,
3763 /* Default rule, wildcard match. */
3764 attr.priority = MLX5_FLOW_PRIO_RSVD;
3765 items[0] = (struct rte_flow_item){
3766 .type = RTE_FLOW_ITEM_TYPE_END,
3768 actions[0] = (struct rte_flow_action){
3769 .type = (enum rte_flow_action_type)
3770 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
3773 actions[1] = (struct rte_flow_action){
3774 .type = RTE_FLOW_ACTION_TYPE_JUMP,
3777 actions[2] = (struct rte_flow_action){
3778 .type = RTE_FLOW_ACTION_TYPE_END,
3781 /* Build a new entry. */
3782 mcp_res = mlx5_ipool_zmalloc(priv->sh->ipool[MLX5_IPOOL_MCP], &idx);
3789 * The copy Flows are not included in any list. There
3790 * ones are referenced from other Flows and can not
3791 * be applied, removed, deleted in ardbitrary order
3792 * by list traversing.
3794 mcp_res->rix_flow = flow_list_create(dev, NULL, &attr, items,
3795 actions, false, error);
3796 if (!mcp_res->rix_flow) {
3797 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], idx);
3800 return &mcp_res->hlist_ent;
3804 * Add a flow of copying flow metadata registers in RX_CP_TBL.
3806 * As mark_id is unique, if there's already a registered flow for the mark_id,
3807 * return by increasing the reference counter of the resource. Otherwise, create
3808 * the resource (mcp_res) and flow.
3811 * - If ingress port is ANY and reg_c[1] is mark_id,
3812 * flow_tag := mark_id, reg_b := reg_c[0] and jump to RX_ACT_TBL.
3814 * For default flow (zero mark_id), flow is like,
3815 * - If ingress port is ANY,
3816 * reg_b := reg_c[0] and jump to RX_ACT_TBL.
3819 * Pointer to Ethernet device.
3821 * ID of MARK action, zero means default flow for META.
3823 * Perform verbose error reporting if not NULL.
3826 * Associated resource on success, NULL otherwise and rte_errno is set.
3828 static struct mlx5_flow_mreg_copy_resource *
3829 flow_mreg_add_copy_action(struct rte_eth_dev *dev, uint32_t mark_id,
3830 struct rte_flow_error *error)
3832 struct mlx5_priv *priv = dev->data->dev_private;
3833 struct mlx5_hlist_entry *entry;
3834 struct mlx5_flow_cb_ctx ctx = {
3839 /* Check if already registered. */
3840 MLX5_ASSERT(priv->mreg_cp_tbl);
3841 entry = mlx5_hlist_register(priv->mreg_cp_tbl, mark_id, &ctx);
3844 return container_of(entry, struct mlx5_flow_mreg_copy_resource,
3849 flow_dv_mreg_remove_cb(struct mlx5_hlist *list, struct mlx5_hlist_entry *entry)
3851 struct mlx5_flow_mreg_copy_resource *mcp_res =
3852 container_of(entry, typeof(*mcp_res), hlist_ent);
3853 struct rte_eth_dev *dev = list->ctx;
3854 struct mlx5_priv *priv = dev->data->dev_private;
3856 MLX5_ASSERT(mcp_res->rix_flow);
3857 flow_list_destroy(dev, NULL, mcp_res->rix_flow);
3858 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], mcp_res->idx);
3862 * Release flow in RX_CP_TBL.
3865 * Pointer to Ethernet device.
3867 * Parent flow for wich copying is provided.
3870 flow_mreg_del_copy_action(struct rte_eth_dev *dev,
3871 struct rte_flow *flow)
3873 struct mlx5_flow_mreg_copy_resource *mcp_res;
3874 struct mlx5_priv *priv = dev->data->dev_private;
3876 if (!flow->rix_mreg_copy)
3878 mcp_res = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MCP],
3879 flow->rix_mreg_copy);
3880 if (!mcp_res || !priv->mreg_cp_tbl)
3882 MLX5_ASSERT(mcp_res->rix_flow);
3883 mlx5_hlist_unregister(priv->mreg_cp_tbl, &mcp_res->hlist_ent);
3884 flow->rix_mreg_copy = 0;
3888 * Remove the default copy action from RX_CP_TBL.
3890 * This functions is called in the mlx5_dev_start(). No thread safe
3894 * Pointer to Ethernet device.
3897 flow_mreg_del_default_copy_action(struct rte_eth_dev *dev)
3899 struct mlx5_hlist_entry *entry;
3900 struct mlx5_priv *priv = dev->data->dev_private;
3902 /* Check if default flow is registered. */
3903 if (!priv->mreg_cp_tbl)
3905 entry = mlx5_hlist_lookup(priv->mreg_cp_tbl,
3906 MLX5_DEFAULT_COPY_ID, NULL);
3909 mlx5_hlist_unregister(priv->mreg_cp_tbl, entry);
3913 * Add the default copy action in in RX_CP_TBL.
3915 * This functions is called in the mlx5_dev_start(). No thread safe
3919 * Pointer to Ethernet device.
3921 * Perform verbose error reporting if not NULL.
3924 * 0 for success, negative value otherwise and rte_errno is set.
3927 flow_mreg_add_default_copy_action(struct rte_eth_dev *dev,
3928 struct rte_flow_error *error)
3930 struct mlx5_priv *priv = dev->data->dev_private;
3931 struct mlx5_flow_mreg_copy_resource *mcp_res;
3933 /* Check whether extensive metadata feature is engaged. */
3934 if (!priv->config.dv_flow_en ||
3935 priv->config.dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
3936 !mlx5_flow_ext_mreg_supported(dev) ||
3937 !priv->sh->dv_regc0_mask)
3940 * Add default mreg copy flow may be called multiple time, but
3941 * only be called once in stop. Avoid register it twice.
3943 if (mlx5_hlist_lookup(priv->mreg_cp_tbl, MLX5_DEFAULT_COPY_ID, NULL))
3945 mcp_res = flow_mreg_add_copy_action(dev, MLX5_DEFAULT_COPY_ID, error);
3952 * Add a flow of copying flow metadata registers in RX_CP_TBL.
3954 * All the flow having Q/RSS action should be split by
3955 * flow_mreg_split_qrss_prep() to pass by RX_CP_TBL. A flow in the RX_CP_TBL
3956 * performs the following,
3957 * - CQE->flow_tag := reg_c[1] (MARK)
3958 * - CQE->flow_table_metadata (reg_b) := reg_c[0] (META)
3959 * As CQE's flow_tag is not a register, it can't be simply copied from reg_c[1]
3960 * but there should be a flow per each MARK ID set by MARK action.
3962 * For the aforementioned reason, if there's a MARK action in flow's action
3963 * list, a corresponding flow should be added to the RX_CP_TBL in order to copy
3964 * the MARK ID to CQE's flow_tag like,
3965 * - If reg_c[1] is mark_id,
3966 * flow_tag := mark_id, reg_b := reg_c[0] and jump to RX_ACT_TBL.
3968 * For SET_META action which stores value in reg_c[0], as the destination is
3969 * also a flow metadata register (reg_b), adding a default flow is enough. Zero
3970 * MARK ID means the default flow. The default flow looks like,
3971 * - For all flow, reg_b := reg_c[0] and jump to RX_ACT_TBL.
3974 * Pointer to Ethernet device.
3976 * Pointer to flow structure.
3977 * @param[in] actions
3978 * Pointer to the list of actions.
3980 * Perform verbose error reporting if not NULL.
3983 * 0 on success, negative value otherwise and rte_errno is set.
3986 flow_mreg_update_copy_table(struct rte_eth_dev *dev,
3987 struct rte_flow *flow,
3988 const struct rte_flow_action *actions,
3989 struct rte_flow_error *error)
3991 struct mlx5_priv *priv = dev->data->dev_private;
3992 struct mlx5_dev_config *config = &priv->config;
3993 struct mlx5_flow_mreg_copy_resource *mcp_res;
3994 const struct rte_flow_action_mark *mark;
3996 /* Check whether extensive metadata feature is engaged. */
3997 if (!config->dv_flow_en ||
3998 config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
3999 !mlx5_flow_ext_mreg_supported(dev) ||
4000 !priv->sh->dv_regc0_mask)
4002 /* Find MARK action. */
4003 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4004 switch (actions->type) {
4005 case RTE_FLOW_ACTION_TYPE_FLAG:
4006 mcp_res = flow_mreg_add_copy_action
4007 (dev, MLX5_FLOW_MARK_DEFAULT, error);
4010 flow->rix_mreg_copy = mcp_res->idx;
4012 case RTE_FLOW_ACTION_TYPE_MARK:
4013 mark = (const struct rte_flow_action_mark *)
4016 flow_mreg_add_copy_action(dev, mark->id, error);
4019 flow->rix_mreg_copy = mcp_res->idx;
4028 #define MLX5_MAX_SPLIT_ACTIONS 24
4029 #define MLX5_MAX_SPLIT_ITEMS 24
4032 * Split the hairpin flow.
4033 * Since HW can't support encap and push-vlan on Rx, we move these
4035 * If the count action is after the encap then we also
4036 * move the count action. in this case the count will also measure
4040 * Pointer to Ethernet device.
4041 * @param[in] actions
4042 * Associated actions (list terminated by the END action).
4043 * @param[out] actions_rx
4045 * @param[out] actions_tx
4047 * @param[out] pattern_tx
4048 * The pattern items for the Tx flow.
4049 * @param[out] flow_id
4050 * The flow ID connected to this flow.
4056 flow_hairpin_split(struct rte_eth_dev *dev,
4057 const struct rte_flow_action actions[],
4058 struct rte_flow_action actions_rx[],
4059 struct rte_flow_action actions_tx[],
4060 struct rte_flow_item pattern_tx[],
4063 const struct rte_flow_action_raw_encap *raw_encap;
4064 const struct rte_flow_action_raw_decap *raw_decap;
4065 struct mlx5_rte_flow_action_set_tag *set_tag;
4066 struct rte_flow_action *tag_action;
4067 struct mlx5_rte_flow_item_tag *tag_item;
4068 struct rte_flow_item *item;
4072 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4073 switch (actions->type) {
4074 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
4075 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
4076 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
4077 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
4078 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
4079 rte_memcpy(actions_tx, actions,
4080 sizeof(struct rte_flow_action));
4083 case RTE_FLOW_ACTION_TYPE_COUNT:
4085 rte_memcpy(actions_tx, actions,
4086 sizeof(struct rte_flow_action));
4089 rte_memcpy(actions_rx, actions,
4090 sizeof(struct rte_flow_action));
4094 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
4095 raw_encap = actions->conf;
4096 if (raw_encap->size >
4097 (sizeof(struct rte_flow_item_eth) +
4098 sizeof(struct rte_flow_item_ipv4))) {
4099 memcpy(actions_tx, actions,
4100 sizeof(struct rte_flow_action));
4104 rte_memcpy(actions_rx, actions,
4105 sizeof(struct rte_flow_action));
4109 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
4110 raw_decap = actions->conf;
4111 if (raw_decap->size <
4112 (sizeof(struct rte_flow_item_eth) +
4113 sizeof(struct rte_flow_item_ipv4))) {
4114 memcpy(actions_tx, actions,
4115 sizeof(struct rte_flow_action));
4118 rte_memcpy(actions_rx, actions,
4119 sizeof(struct rte_flow_action));
4124 rte_memcpy(actions_rx, actions,
4125 sizeof(struct rte_flow_action));
4130 /* Add set meta action and end action for the Rx flow. */
4131 tag_action = actions_rx;
4132 tag_action->type = (enum rte_flow_action_type)
4133 MLX5_RTE_FLOW_ACTION_TYPE_TAG;
4135 rte_memcpy(actions_rx, actions, sizeof(struct rte_flow_action));
4137 set_tag = (void *)actions_rx;
4138 set_tag->id = mlx5_flow_get_reg_id(dev, MLX5_HAIRPIN_RX, 0, NULL);
4139 MLX5_ASSERT(set_tag->id > REG_NON);
4140 set_tag->data = flow_id;
4141 tag_action->conf = set_tag;
4142 /* Create Tx item list. */
4143 rte_memcpy(actions_tx, actions, sizeof(struct rte_flow_action));
4144 addr = (void *)&pattern_tx[2];
4146 item->type = (enum rte_flow_item_type)
4147 MLX5_RTE_FLOW_ITEM_TYPE_TAG;
4148 tag_item = (void *)addr;
4149 tag_item->data = flow_id;
4150 tag_item->id = mlx5_flow_get_reg_id(dev, MLX5_HAIRPIN_TX, 0, NULL);
4151 MLX5_ASSERT(set_tag->id > REG_NON);
4152 item->spec = tag_item;
4153 addr += sizeof(struct mlx5_rte_flow_item_tag);
4154 tag_item = (void *)addr;
4155 tag_item->data = UINT32_MAX;
4156 tag_item->id = UINT16_MAX;
4157 item->mask = tag_item;
4160 item->type = RTE_FLOW_ITEM_TYPE_END;
4165 union tunnel_offload_mark {
4168 uint32_t app_reserve:8;
4169 uint32_t table_id:15;
4170 uint32_t transfer:1;
4171 uint32_t _unused_:8;
4175 struct tunnel_default_miss_ctx {
4179 struct rte_flow_action_rss action_rss;
4180 struct rte_flow_action_queue miss_queue;
4181 struct rte_flow_action_jump miss_jump;
4187 flow_tunnel_add_default_miss(struct rte_eth_dev *dev,
4188 struct rte_flow *flow,
4189 const struct rte_flow_attr *attr,
4190 const struct rte_flow_action *app_actions,
4192 struct tunnel_default_miss_ctx *ctx,
4193 struct rte_flow_error *error)
4195 struct mlx5_priv *priv = dev->data->dev_private;
4196 struct mlx5_flow *dev_flow;
4197 struct rte_flow_attr miss_attr = *attr;
4198 const struct mlx5_flow_tunnel *tunnel = app_actions[0].conf;
4199 const struct rte_flow_item miss_items[2] = {
4201 .type = RTE_FLOW_ITEM_TYPE_ETH,
4207 .type = RTE_FLOW_ITEM_TYPE_END,
4213 union tunnel_offload_mark mark_id;
4214 struct rte_flow_action_mark miss_mark;
4215 struct rte_flow_action miss_actions[3] = {
4216 [0] = { .type = RTE_FLOW_ACTION_TYPE_MARK, .conf = &miss_mark },
4217 [2] = { .type = RTE_FLOW_ACTION_TYPE_END, .conf = NULL }
4219 const struct rte_flow_action_jump *jump_data;
4220 uint32_t i, flow_table = 0; /* prevent compilation warning */
4221 struct flow_grp_info grp_info = {
4223 .transfer = attr->transfer,
4224 .fdb_def_rule = !!priv->fdb_def_rule,
4229 if (!attr->transfer) {
4232 miss_actions[1].type = RTE_FLOW_ACTION_TYPE_RSS;
4233 q_size = priv->reta_idx_n * sizeof(ctx->queue[0]);
4234 ctx->queue = mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO, q_size,
4237 return rte_flow_error_set
4239 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
4240 NULL, "invalid default miss RSS");
4241 ctx->action_rss.func = RTE_ETH_HASH_FUNCTION_DEFAULT,
4242 ctx->action_rss.level = 0,
4243 ctx->action_rss.types = priv->rss_conf.rss_hf,
4244 ctx->action_rss.key_len = priv->rss_conf.rss_key_len,
4245 ctx->action_rss.queue_num = priv->reta_idx_n,
4246 ctx->action_rss.key = priv->rss_conf.rss_key,
4247 ctx->action_rss.queue = ctx->queue;
4248 if (!priv->reta_idx_n || !priv->rxqs_n)
4249 return rte_flow_error_set
4251 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
4252 NULL, "invalid port configuration");
4253 if (!(dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG))
4254 ctx->action_rss.types = 0;
4255 for (i = 0; i != priv->reta_idx_n; ++i)
4256 ctx->queue[i] = (*priv->reta_idx)[i];
4258 miss_actions[1].type = RTE_FLOW_ACTION_TYPE_JUMP;
4259 ctx->miss_jump.group = MLX5_TNL_MISS_FDB_JUMP_GRP;
4261 miss_actions[1].conf = (typeof(miss_actions[1].conf))ctx->raw;
4262 for (; app_actions->type != RTE_FLOW_ACTION_TYPE_JUMP; app_actions++);
4263 jump_data = app_actions->conf;
4264 miss_attr.priority = MLX5_TNL_MISS_RULE_PRIORITY;
4265 miss_attr.group = jump_data->group;
4266 ret = mlx5_flow_group_to_table(dev, tunnel, jump_data->group,
4267 &flow_table, grp_info, error);
4269 return rte_flow_error_set(error, EINVAL,
4270 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
4271 NULL, "invalid tunnel id");
4272 mark_id.app_reserve = 0;
4273 mark_id.table_id = tunnel_flow_tbl_to_id(flow_table);
4274 mark_id.transfer = !!attr->transfer;
4275 mark_id._unused_ = 0;
4276 miss_mark.id = mark_id.val;
4277 dev_flow = flow_drv_prepare(dev, flow, &miss_attr,
4278 miss_items, miss_actions, flow_idx, error);
4281 dev_flow->flow = flow;
4282 dev_flow->external = true;
4283 dev_flow->tunnel = tunnel;
4284 /* Subflow object was created, we must include one in the list. */
4285 SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
4286 dev_flow->handle, next);
4288 "port %u tunnel type=%d id=%u miss rule priority=%u group=%u",
4289 dev->data->port_id, tunnel->app_tunnel.type,
4290 tunnel->tunnel_id, miss_attr.priority, miss_attr.group);
4291 ret = flow_drv_translate(dev, dev_flow, &miss_attr, miss_items,
4292 miss_actions, error);
4294 ret = flow_mreg_update_copy_table(dev, flow, miss_actions,
4301 * The last stage of splitting chain, just creates the subflow
4302 * without any modification.
4305 * Pointer to Ethernet device.
4307 * Parent flow structure pointer.
4308 * @param[in, out] sub_flow
4309 * Pointer to return the created subflow, may be NULL.
4311 * Flow rule attributes.
4313 * Pattern specification (list terminated by the END pattern item).
4314 * @param[in] actions
4315 * Associated actions (list terminated by the END action).
4316 * @param[in] flow_split_info
4317 * Pointer to flow split info structure.
4319 * Perform verbose error reporting if not NULL.
4321 * 0 on success, negative value otherwise
4324 flow_create_split_inner(struct rte_eth_dev *dev,
4325 struct rte_flow *flow,
4326 struct mlx5_flow **sub_flow,
4327 const struct rte_flow_attr *attr,
4328 const struct rte_flow_item items[],
4329 const struct rte_flow_action actions[],
4330 struct mlx5_flow_split_info *flow_split_info,
4331 struct rte_flow_error *error)
4333 struct mlx5_flow *dev_flow;
4335 dev_flow = flow_drv_prepare(dev, flow, attr, items, actions,
4336 flow_split_info->flow_idx, error);
4339 dev_flow->flow = flow;
4340 dev_flow->external = flow_split_info->external;
4341 dev_flow->skip_scale = flow_split_info->skip_scale;
4342 /* Subflow object was created, we must include one in the list. */
4343 SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
4344 dev_flow->handle, next);
4346 * If dev_flow is as one of the suffix flow, some actions in suffix
4347 * flow may need some user defined item layer flags, and pass the
4348 * Metadate rxq mark flag to suffix flow as well.
4350 if (flow_split_info->prefix_layers)
4351 dev_flow->handle->layers = flow_split_info->prefix_layers;
4352 if (flow_split_info->prefix_mark)
4353 dev_flow->handle->mark = 1;
4355 *sub_flow = dev_flow;
4356 return flow_drv_translate(dev, dev_flow, attr, items, actions, error);
4360 * Split the meter flow.
4362 * As meter flow will split to three sub flow, other than meter
4363 * action, the other actions make sense to only meter accepts
4364 * the packet. If it need to be dropped, no other additional
4365 * actions should be take.
4367 * One kind of special action which decapsulates the L3 tunnel
4368 * header will be in the prefix sub flow, as not to take the
4369 * L3 tunnel header into account.
4372 * Pointer to Ethernet device.
4374 * Pattern specification (list terminated by the END pattern item).
4375 * @param[out] sfx_items
4376 * Suffix flow match items (list terminated by the END pattern item).
4377 * @param[in] actions
4378 * Associated actions (list terminated by the END action).
4379 * @param[out] actions_sfx
4380 * Suffix flow actions.
4381 * @param[out] actions_pre
4382 * Prefix flow actions.
4383 * @param[out] pattern_sfx
4384 * The pattern items for the suffix flow.
4385 * @param[out] tag_sfx
4386 * Pointer to suffix flow tag.
4392 flow_meter_split_prep(struct rte_eth_dev *dev,
4393 const struct rte_flow_item items[],
4394 struct rte_flow_item sfx_items[],
4395 const struct rte_flow_action actions[],
4396 struct rte_flow_action actions_sfx[],
4397 struct rte_flow_action actions_pre[])
4399 struct mlx5_priv *priv = dev->data->dev_private;
4400 struct rte_flow_action *tag_action = NULL;
4401 struct rte_flow_item *tag_item;
4402 struct mlx5_rte_flow_action_set_tag *set_tag;
4403 struct rte_flow_error error;
4404 const struct rte_flow_action_raw_encap *raw_encap;
4405 const struct rte_flow_action_raw_decap *raw_decap;
4406 struct mlx5_rte_flow_item_tag *tag_spec;
4407 struct mlx5_rte_flow_item_tag *tag_mask;
4408 uint32_t tag_id = 0;
4409 bool copy_vlan = false;
4411 /* Prepare the actions for prefix and suffix flow. */
4412 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4413 struct rte_flow_action **action_cur = NULL;
4415 switch (actions->type) {
4416 case RTE_FLOW_ACTION_TYPE_METER:
4417 /* Add the extra tag action first. */
4418 tag_action = actions_pre;
4419 tag_action->type = (enum rte_flow_action_type)
4420 MLX5_RTE_FLOW_ACTION_TYPE_TAG;
4422 action_cur = &actions_pre;
4424 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
4425 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
4426 action_cur = &actions_pre;
4428 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
4429 raw_encap = actions->conf;
4430 if (raw_encap->size < MLX5_ENCAPSULATION_DECISION_SIZE)
4431 action_cur = &actions_pre;
4433 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
4434 raw_decap = actions->conf;
4435 if (raw_decap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
4436 action_cur = &actions_pre;
4438 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
4439 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
4446 action_cur = &actions_sfx;
4447 memcpy(*action_cur, actions, sizeof(struct rte_flow_action));
4450 /* Add end action to the actions. */
4451 actions_sfx->type = RTE_FLOW_ACTION_TYPE_END;
4452 actions_pre->type = RTE_FLOW_ACTION_TYPE_END;
4455 set_tag = (void *)actions_pre;
4456 set_tag->id = mlx5_flow_get_reg_id(dev, MLX5_MTR_SFX, 0, &error);
4457 mlx5_ipool_malloc(priv->sh->ipool[MLX5_IPOOL_RSS_EXPANTION_FLOW_ID],
4459 if (tag_id >= (1 << (sizeof(tag_id) * 8 - MLX5_MTR_COLOR_BITS))) {
4460 DRV_LOG(ERR, "Port %u meter flow id exceed max limit.",
4461 dev->data->port_id);
4462 mlx5_ipool_free(priv->sh->ipool
4463 [MLX5_IPOOL_RSS_EXPANTION_FLOW_ID], tag_id);
4465 } else if (!tag_id) {
4468 set_tag->data = tag_id << MLX5_MTR_COLOR_BITS;
4470 tag_action->conf = set_tag;
4471 /* Prepare the suffix subflow items. */
4472 tag_item = sfx_items++;
4473 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
4474 int item_type = items->type;
4476 switch (item_type) {
4477 case RTE_FLOW_ITEM_TYPE_PORT_ID:
4478 memcpy(sfx_items, items, sizeof(*sfx_items));
4481 case RTE_FLOW_ITEM_TYPE_VLAN:
4483 memcpy(sfx_items, items, sizeof(*sfx_items));
4485 * Convert to internal match item, it is used
4486 * for vlan push and set vid.
4488 sfx_items->type = (enum rte_flow_item_type)
4489 MLX5_RTE_FLOW_ITEM_TYPE_VLAN;
4497 sfx_items->type = RTE_FLOW_ITEM_TYPE_END;
4499 tag_spec = (struct mlx5_rte_flow_item_tag *)sfx_items;
4500 tag_spec->data = tag_id << MLX5_MTR_COLOR_BITS;
4501 tag_spec->id = mlx5_flow_get_reg_id(dev, MLX5_MTR_SFX, 0, &error);
4502 tag_mask = tag_spec + 1;
4503 tag_mask->data = 0xffffff00;
4504 tag_item->type = (enum rte_flow_item_type)
4505 MLX5_RTE_FLOW_ITEM_TYPE_TAG;
4506 tag_item->spec = tag_spec;
4507 tag_item->last = NULL;
4508 tag_item->mask = tag_mask;
4513 * Split action list having QUEUE/RSS for metadata register copy.
4515 * Once Q/RSS action is detected in user's action list, the flow action
4516 * should be split in order to copy metadata registers, which will happen in
4518 * - CQE->flow_tag := reg_c[1] (MARK)
4519 * - CQE->flow_table_metadata (reg_b) := reg_c[0] (META)
4520 * The Q/RSS action will be performed on RX_ACT_TBL after passing by RX_CP_TBL.
4521 * This is because the last action of each flow must be a terminal action
4522 * (QUEUE, RSS or DROP).
4524 * Flow ID must be allocated to identify actions in the RX_ACT_TBL and it is
4525 * stored and kept in the mlx5_flow structure per each sub_flow.
4527 * The Q/RSS action is replaced with,
4528 * - SET_TAG, setting the allocated flow ID to reg_c[2].
4529 * And the following JUMP action is added at the end,
4530 * - JUMP, to RX_CP_TBL.
4532 * A flow to perform remained Q/RSS action will be created in RX_ACT_TBL by
4533 * flow_create_split_metadata() routine. The flow will look like,
4534 * - If flow ID matches (reg_c[2]), perform Q/RSS.
4537 * Pointer to Ethernet device.
4538 * @param[out] split_actions
4539 * Pointer to store split actions to jump to CP_TBL.
4540 * @param[in] actions
4541 * Pointer to the list of original flow actions.
4543 * Pointer to the Q/RSS action.
4544 * @param[in] actions_n
4545 * Number of original actions.
4547 * Perform verbose error reporting if not NULL.
4550 * non-zero unique flow_id on success, otherwise 0 and
4551 * error/rte_error are set.
4554 flow_mreg_split_qrss_prep(struct rte_eth_dev *dev,
4555 struct rte_flow_action *split_actions,
4556 const struct rte_flow_action *actions,
4557 const struct rte_flow_action *qrss,
4558 int actions_n, struct rte_flow_error *error)
4560 struct mlx5_priv *priv = dev->data->dev_private;
4561 struct mlx5_rte_flow_action_set_tag *set_tag;
4562 struct rte_flow_action_jump *jump;
4563 const int qrss_idx = qrss - actions;
4564 uint32_t flow_id = 0;
4568 * Given actions will be split
4569 * - Replace QUEUE/RSS action with SET_TAG to set flow ID.
4570 * - Add jump to mreg CP_TBL.
4571 * As a result, there will be one more action.
4574 memcpy(split_actions, actions, sizeof(*split_actions) * actions_n);
4575 set_tag = (void *)(split_actions + actions_n);
4577 * If tag action is not set to void(it means we are not the meter
4578 * suffix flow), add the tag action. Since meter suffix flow already
4579 * has the tag added.
4581 if (split_actions[qrss_idx].type != RTE_FLOW_ACTION_TYPE_VOID) {
4583 * Allocate the new subflow ID. This one is unique within
4584 * device and not shared with representors. Otherwise,
4585 * we would have to resolve multi-thread access synch
4586 * issue. Each flow on the shared device is appended
4587 * with source vport identifier, so the resulting
4588 * flows will be unique in the shared (by master and
4589 * representors) domain even if they have coinciding
4592 mlx5_ipool_malloc(priv->sh->ipool
4593 [MLX5_IPOOL_RSS_EXPANTION_FLOW_ID], &flow_id);
4595 return rte_flow_error_set(error, ENOMEM,
4596 RTE_FLOW_ERROR_TYPE_ACTION,
4597 NULL, "can't allocate id "
4598 "for split Q/RSS subflow");
4599 /* Internal SET_TAG action to set flow ID. */
4600 *set_tag = (struct mlx5_rte_flow_action_set_tag){
4603 ret = mlx5_flow_get_reg_id(dev, MLX5_COPY_MARK, 0, error);
4607 /* Construct new actions array. */
4608 /* Replace QUEUE/RSS action. */
4609 split_actions[qrss_idx] = (struct rte_flow_action){
4610 .type = (enum rte_flow_action_type)
4611 MLX5_RTE_FLOW_ACTION_TYPE_TAG,
4615 /* JUMP action to jump to mreg copy table (CP_TBL). */
4616 jump = (void *)(set_tag + 1);
4617 *jump = (struct rte_flow_action_jump){
4618 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
4620 split_actions[actions_n - 2] = (struct rte_flow_action){
4621 .type = RTE_FLOW_ACTION_TYPE_JUMP,
4624 split_actions[actions_n - 1] = (struct rte_flow_action){
4625 .type = RTE_FLOW_ACTION_TYPE_END,
4631 * Extend the given action list for Tx metadata copy.
4633 * Copy the given action list to the ext_actions and add flow metadata register
4634 * copy action in order to copy reg_a set by WQE to reg_c[0].
4636 * @param[out] ext_actions
4637 * Pointer to the extended action list.
4638 * @param[in] actions
4639 * Pointer to the list of actions.
4640 * @param[in] actions_n
4641 * Number of actions in the list.
4643 * Perform verbose error reporting if not NULL.
4644 * @param[in] encap_idx
4645 * The encap action inndex.
4648 * 0 on success, negative value otherwise
4651 flow_mreg_tx_copy_prep(struct rte_eth_dev *dev,
4652 struct rte_flow_action *ext_actions,
4653 const struct rte_flow_action *actions,
4654 int actions_n, struct rte_flow_error *error,
4657 struct mlx5_flow_action_copy_mreg *cp_mreg =
4658 (struct mlx5_flow_action_copy_mreg *)
4659 (ext_actions + actions_n + 1);
4662 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_RX, 0, error);
4666 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_TX, 0, error);
4671 memcpy(ext_actions, actions, sizeof(*ext_actions) * encap_idx);
4672 if (encap_idx == actions_n - 1) {
4673 ext_actions[actions_n - 1] = (struct rte_flow_action){
4674 .type = (enum rte_flow_action_type)
4675 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
4678 ext_actions[actions_n] = (struct rte_flow_action){
4679 .type = RTE_FLOW_ACTION_TYPE_END,
4682 ext_actions[encap_idx] = (struct rte_flow_action){
4683 .type = (enum rte_flow_action_type)
4684 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
4687 memcpy(ext_actions + encap_idx + 1, actions + encap_idx,
4688 sizeof(*ext_actions) * (actions_n - encap_idx));
4694 * Check the match action from the action list.
4696 * @param[in] actions
4697 * Pointer to the list of actions.
4699 * Flow rule attributes.
4701 * The action to be check if exist.
4702 * @param[out] match_action_pos
4703 * Pointer to the position of the matched action if exists, otherwise is -1.
4704 * @param[out] qrss_action_pos
4705 * Pointer to the position of the Queue/RSS action if exists, otherwise is -1.
4708 * > 0 the total number of actions.
4709 * 0 if not found match action in action list.
4712 flow_check_match_action(const struct rte_flow_action actions[],
4713 const struct rte_flow_attr *attr,
4714 enum rte_flow_action_type action,
4715 int *match_action_pos, int *qrss_action_pos)
4717 const struct rte_flow_action_sample *sample;
4724 *match_action_pos = -1;
4725 *qrss_action_pos = -1;
4726 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4727 if (actions->type == action) {
4729 *match_action_pos = actions_n;
4731 if (actions->type == RTE_FLOW_ACTION_TYPE_QUEUE ||
4732 actions->type == RTE_FLOW_ACTION_TYPE_RSS)
4733 *qrss_action_pos = actions_n;
4734 if (actions->type == RTE_FLOW_ACTION_TYPE_JUMP)
4736 if (actions->type == RTE_FLOW_ACTION_TYPE_SAMPLE) {
4737 sample = actions->conf;
4738 ratio = sample->ratio;
4739 sub_type = ((const struct rte_flow_action *)
4740 (sample->actions))->type;
4744 if (flag && action == RTE_FLOW_ACTION_TYPE_SAMPLE && attr->transfer) {
4746 /* JUMP Action not support for Mirroring;
4747 * Mirroring support multi-destination;
4749 if (!jump_flag && sub_type != RTE_FLOW_ACTION_TYPE_END)
4753 /* Count RTE_FLOW_ACTION_TYPE_END. */
4754 return flag ? actions_n + 1 : 0;
4757 #define SAMPLE_SUFFIX_ITEM 2
4760 * Split the sample flow.
4762 * As sample flow will split to two sub flow, sample flow with
4763 * sample action, the other actions will move to new suffix flow.
4765 * Also add unique tag id with tag action in the sample flow,
4766 * the same tag id will be as match in the suffix flow.
4769 * Pointer to Ethernet device.
4771 * FDB egress flow flag.
4772 * @param[out] sfx_items
4773 * Suffix flow match items (list terminated by the END pattern item).
4774 * @param[in] actions
4775 * Associated actions (list terminated by the END action).
4776 * @param[out] actions_sfx
4777 * Suffix flow actions.
4778 * @param[out] actions_pre
4779 * Prefix flow actions.
4780 * @param[in] actions_n
4781 * The total number of actions.
4782 * @param[in] sample_action_pos
4783 * The sample action position.
4784 * @param[in] qrss_action_pos
4785 * The Queue/RSS action position.
4787 * Perform verbose error reporting if not NULL.
4790 * 0 on success, or unique flow_id, a negative errno value
4791 * otherwise and rte_errno is set.
4794 flow_sample_split_prep(struct rte_eth_dev *dev,
4796 struct rte_flow_item sfx_items[],
4797 const struct rte_flow_action actions[],
4798 struct rte_flow_action actions_sfx[],
4799 struct rte_flow_action actions_pre[],
4801 int sample_action_pos,
4802 int qrss_action_pos,
4803 struct rte_flow_error *error)
4805 struct mlx5_priv *priv = dev->data->dev_private;
4806 struct mlx5_rte_flow_action_set_tag *set_tag;
4807 struct mlx5_rte_flow_item_tag *tag_spec;
4808 struct mlx5_rte_flow_item_tag *tag_mask;
4809 uint32_t tag_id = 0;
4813 if (sample_action_pos < 0)
4814 return rte_flow_error_set(error, EINVAL,
4815 RTE_FLOW_ERROR_TYPE_ACTION,
4816 NULL, "invalid position of sample "
4819 /* Prepare the prefix tag action. */
4820 set_tag = (void *)(actions_pre + actions_n + 1);
4821 ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, 0, error);
4825 mlx5_ipool_malloc(priv->sh->ipool
4826 [MLX5_IPOOL_RSS_EXPANTION_FLOW_ID], &tag_id);
4827 set_tag->data = tag_id;
4828 /* Prepare the suffix subflow items. */
4829 tag_spec = (void *)(sfx_items + SAMPLE_SUFFIX_ITEM);
4830 tag_spec->data = tag_id;
4831 tag_spec->id = set_tag->id;
4832 tag_mask = tag_spec + 1;
4833 tag_mask->data = UINT32_MAX;
4834 sfx_items[0] = (struct rte_flow_item){
4835 .type = (enum rte_flow_item_type)
4836 MLX5_RTE_FLOW_ITEM_TYPE_TAG,
4841 sfx_items[1] = (struct rte_flow_item){
4842 .type = (enum rte_flow_item_type)
4843 RTE_FLOW_ITEM_TYPE_END,
4846 /* Prepare the actions for prefix and suffix flow. */
4847 if (qrss_action_pos >= 0 && qrss_action_pos < sample_action_pos) {
4848 index = qrss_action_pos;
4849 /* Put the preceding the Queue/RSS action into prefix flow. */
4851 memcpy(actions_pre, actions,
4852 sizeof(struct rte_flow_action) * index);
4853 /* Put others preceding the sample action into prefix flow. */
4854 if (sample_action_pos > index + 1)
4855 memcpy(actions_pre + index, actions + index + 1,
4856 sizeof(struct rte_flow_action) *
4857 (sample_action_pos - index - 1));
4858 index = sample_action_pos - 1;
4859 /* Put Queue/RSS action into Suffix flow. */
4860 memcpy(actions_sfx, actions + qrss_action_pos,
4861 sizeof(struct rte_flow_action));
4864 index = sample_action_pos;
4866 memcpy(actions_pre, actions,
4867 sizeof(struct rte_flow_action) * index);
4869 /* Add the extra tag action for NIC-RX and E-Switch ingress. */
4871 actions_pre[index++] =
4872 (struct rte_flow_action){
4873 .type = (enum rte_flow_action_type)
4874 MLX5_RTE_FLOW_ACTION_TYPE_TAG,
4878 memcpy(actions_pre + index, actions + sample_action_pos,
4879 sizeof(struct rte_flow_action));
4881 actions_pre[index] = (struct rte_flow_action){
4882 .type = (enum rte_flow_action_type)
4883 RTE_FLOW_ACTION_TYPE_END,
4885 /* Put the actions after sample into Suffix flow. */
4886 memcpy(actions_sfx, actions + sample_action_pos + 1,
4887 sizeof(struct rte_flow_action) *
4888 (actions_n - sample_action_pos - 1));
4893 * The splitting for metadata feature.
4895 * - Q/RSS action on NIC Rx should be split in order to pass by
4896 * the mreg copy table (RX_CP_TBL) and then it jumps to the
4897 * action table (RX_ACT_TBL) which has the split Q/RSS action.
4899 * - All the actions on NIC Tx should have a mreg copy action to
4900 * copy reg_a from WQE to reg_c[0].
4903 * Pointer to Ethernet device.
4905 * Parent flow structure pointer.
4907 * Flow rule attributes.
4909 * Pattern specification (list terminated by the END pattern item).
4910 * @param[in] actions
4911 * Associated actions (list terminated by the END action).
4912 * @param[in] flow_split_info
4913 * Pointer to flow split info structure.
4915 * Perform verbose error reporting if not NULL.
4917 * 0 on success, negative value otherwise
4920 flow_create_split_metadata(struct rte_eth_dev *dev,
4921 struct rte_flow *flow,
4922 const struct rte_flow_attr *attr,
4923 const struct rte_flow_item items[],
4924 const struct rte_flow_action actions[],
4925 struct mlx5_flow_split_info *flow_split_info,
4926 struct rte_flow_error *error)
4928 struct mlx5_priv *priv = dev->data->dev_private;
4929 struct mlx5_dev_config *config = &priv->config;
4930 const struct rte_flow_action *qrss = NULL;
4931 struct rte_flow_action *ext_actions = NULL;
4932 struct mlx5_flow *dev_flow = NULL;
4933 uint32_t qrss_id = 0;
4940 /* Check whether extensive metadata feature is engaged. */
4941 if (!config->dv_flow_en ||
4942 config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
4943 !mlx5_flow_ext_mreg_supported(dev))
4944 return flow_create_split_inner(dev, flow, NULL, attr, items,
4945 actions, flow_split_info, error);
4946 actions_n = flow_parse_metadata_split_actions_info(actions, &qrss,
4949 /* Exclude hairpin flows from splitting. */
4950 if (qrss->type == RTE_FLOW_ACTION_TYPE_QUEUE) {
4951 const struct rte_flow_action_queue *queue;
4954 if (mlx5_rxq_get_type(dev, queue->index) ==
4955 MLX5_RXQ_TYPE_HAIRPIN)
4957 } else if (qrss->type == RTE_FLOW_ACTION_TYPE_RSS) {
4958 const struct rte_flow_action_rss *rss;
4961 if (mlx5_rxq_get_type(dev, rss->queue[0]) ==
4962 MLX5_RXQ_TYPE_HAIRPIN)
4967 /* Check if it is in meter suffix table. */
4968 mtr_sfx = attr->group == (attr->transfer ?
4969 (MLX5_FLOW_TABLE_LEVEL_SUFFIX - 1) :
4970 MLX5_FLOW_TABLE_LEVEL_SUFFIX);
4972 * Q/RSS action on NIC Rx should be split in order to pass by
4973 * the mreg copy table (RX_CP_TBL) and then it jumps to the
4974 * action table (RX_ACT_TBL) which has the split Q/RSS action.
4976 act_size = sizeof(struct rte_flow_action) * (actions_n + 1) +
4977 sizeof(struct rte_flow_action_set_tag) +
4978 sizeof(struct rte_flow_action_jump);
4979 ext_actions = mlx5_malloc(MLX5_MEM_ZERO, act_size, 0,
4982 return rte_flow_error_set(error, ENOMEM,
4983 RTE_FLOW_ERROR_TYPE_ACTION,
4984 NULL, "no memory to split "
4987 * If we are the suffix flow of meter, tag already exist.
4988 * Set the tag action to void.
4991 ext_actions[qrss - actions].type =
4992 RTE_FLOW_ACTION_TYPE_VOID;
4994 ext_actions[qrss - actions].type =
4995 (enum rte_flow_action_type)
4996 MLX5_RTE_FLOW_ACTION_TYPE_TAG;
4998 * Create the new actions list with removed Q/RSS action
4999 * and appended set tag and jump to register copy table
5000 * (RX_CP_TBL). We should preallocate unique tag ID here
5001 * in advance, because it is needed for set tag action.
5003 qrss_id = flow_mreg_split_qrss_prep(dev, ext_actions, actions,
5004 qrss, actions_n, error);
5005 if (!mtr_sfx && !qrss_id) {
5009 } else if (attr->egress && !attr->transfer) {
5011 * All the actions on NIC Tx should have a metadata register
5012 * copy action to copy reg_a from WQE to reg_c[meta]
5014 act_size = sizeof(struct rte_flow_action) * (actions_n + 1) +
5015 sizeof(struct mlx5_flow_action_copy_mreg);
5016 ext_actions = mlx5_malloc(MLX5_MEM_ZERO, act_size, 0,
5019 return rte_flow_error_set(error, ENOMEM,
5020 RTE_FLOW_ERROR_TYPE_ACTION,
5021 NULL, "no memory to split "
5023 /* Create the action list appended with copy register. */
5024 ret = flow_mreg_tx_copy_prep(dev, ext_actions, actions,
5025 actions_n, error, encap_idx);
5029 /* Add the unmodified original or prefix subflow. */
5030 ret = flow_create_split_inner(dev, flow, &dev_flow, attr,
5031 items, ext_actions ? ext_actions :
5032 actions, flow_split_info, error);
5035 MLX5_ASSERT(dev_flow);
5037 const struct rte_flow_attr q_attr = {
5038 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
5041 /* Internal PMD action to set register. */
5042 struct mlx5_rte_flow_item_tag q_tag_spec = {
5046 struct rte_flow_item q_items[] = {
5048 .type = (enum rte_flow_item_type)
5049 MLX5_RTE_FLOW_ITEM_TYPE_TAG,
5050 .spec = &q_tag_spec,
5055 .type = RTE_FLOW_ITEM_TYPE_END,
5058 struct rte_flow_action q_actions[] = {
5064 .type = RTE_FLOW_ACTION_TYPE_END,
5067 uint64_t layers = flow_get_prefix_layer_flags(dev_flow);
5070 * Configure the tag item only if there is no meter subflow.
5071 * Since tag is already marked in the meter suffix subflow
5072 * we can just use the meter suffix items as is.
5075 /* Not meter subflow. */
5076 MLX5_ASSERT(!mtr_sfx);
5078 * Put unique id in prefix flow due to it is destroyed
5079 * after suffix flow and id will be freed after there
5080 * is no actual flows with this id and identifier
5081 * reallocation becomes possible (for example, for
5082 * other flows in other threads).
5084 dev_flow->handle->split_flow_id = qrss_id;
5085 ret = mlx5_flow_get_reg_id(dev, MLX5_COPY_MARK, 0,
5089 q_tag_spec.id = ret;
5092 /* Add suffix subflow to execute Q/RSS. */
5093 flow_split_info->prefix_layers = layers;
5094 flow_split_info->prefix_mark = 0;
5095 ret = flow_create_split_inner(dev, flow, &dev_flow,
5096 &q_attr, mtr_sfx ? items :
5098 flow_split_info, error);
5101 /* qrss ID should be freed if failed. */
5103 MLX5_ASSERT(dev_flow);
5108 * We do not destroy the partially created sub_flows in case of error.
5109 * These ones are included into parent flow list and will be destroyed
5110 * by flow_drv_destroy.
5112 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RSS_EXPANTION_FLOW_ID],
5114 mlx5_free(ext_actions);
5119 * The splitting for meter feature.
5121 * - The meter flow will be split to two flows as prefix and
5122 * suffix flow. The packets make sense only it pass the prefix
5125 * - Reg_C_5 is used for the packet to match betweend prefix and
5129 * Pointer to Ethernet device.
5131 * Parent flow structure pointer.
5133 * Flow rule attributes.
5135 * Pattern specification (list terminated by the END pattern item).
5136 * @param[in] actions
5137 * Associated actions (list terminated by the END action).
5138 * @param[in] flow_split_info
5139 * Pointer to flow split info structure.
5141 * Perform verbose error reporting if not NULL.
5143 * 0 on success, negative value otherwise
5146 flow_create_split_meter(struct rte_eth_dev *dev,
5147 struct rte_flow *flow,
5148 const struct rte_flow_attr *attr,
5149 const struct rte_flow_item items[],
5150 const struct rte_flow_action actions[],
5151 struct mlx5_flow_split_info *flow_split_info,
5152 struct rte_flow_error *error)
5154 struct mlx5_priv *priv = dev->data->dev_private;
5155 struct rte_flow_action *sfx_actions = NULL;
5156 struct rte_flow_action *pre_actions = NULL;
5157 struct rte_flow_item *sfx_items = NULL;
5158 struct mlx5_flow *dev_flow = NULL;
5159 struct rte_flow_attr sfx_attr = *attr;
5161 uint32_t mtr_tag_id = 0;
5168 actions_n = flow_check_meter_action(actions, &mtr);
5170 /* The five prefix actions: meter, decap, encap, tag, end. */
5171 act_size = sizeof(struct rte_flow_action) * (actions_n + 5) +
5172 sizeof(struct mlx5_rte_flow_action_set_tag);
5173 /* tag, vlan, port id, end. */
5174 #define METER_SUFFIX_ITEM 4
5175 item_size = sizeof(struct rte_flow_item) * METER_SUFFIX_ITEM +
5176 sizeof(struct mlx5_rte_flow_item_tag) * 2;
5177 sfx_actions = mlx5_malloc(MLX5_MEM_ZERO, (act_size + item_size),
5180 return rte_flow_error_set(error, ENOMEM,
5181 RTE_FLOW_ERROR_TYPE_ACTION,
5182 NULL, "no memory to split "
5184 sfx_items = (struct rte_flow_item *)((char *)sfx_actions +
5186 pre_actions = sfx_actions + actions_n;
5187 mtr_tag_id = flow_meter_split_prep(dev, items, sfx_items,
5188 actions, sfx_actions,
5194 /* Add the prefix subflow. */
5195 flow_split_info->prefix_mark = 0;
5196 ret = flow_create_split_inner(dev, flow, &dev_flow,
5197 attr, items, pre_actions,
5198 flow_split_info, error);
5203 dev_flow->handle->split_flow_id = mtr_tag_id;
5204 /* Setting the sfx group atrr. */
5205 sfx_attr.group = sfx_attr.transfer ?
5206 (MLX5_FLOW_TABLE_LEVEL_SUFFIX - 1) :
5207 MLX5_FLOW_TABLE_LEVEL_SUFFIX;
5208 flow_split_info->prefix_layers =
5209 flow_get_prefix_layer_flags(dev_flow);
5210 flow_split_info->prefix_mark = dev_flow->handle->mark;
5212 /* Add the prefix subflow. */
5213 ret = flow_create_split_metadata(dev, flow,
5214 &sfx_attr, sfx_items ?
5216 sfx_actions ? sfx_actions : actions,
5217 flow_split_info, error);
5220 mlx5_free(sfx_actions);
5225 * The splitting for sample feature.
5227 * Once Sample action is detected in the action list, the flow actions should
5228 * be split into prefix sub flow and suffix sub flow.
5230 * The original items remain in the prefix sub flow, all actions preceding the
5231 * sample action and the sample action itself will be copied to the prefix
5232 * sub flow, the actions following the sample action will be copied to the
5233 * suffix sub flow, Queue action always be located in the suffix sub flow.
5235 * In order to make the packet from prefix sub flow matches with suffix sub
5236 * flow, an extra tag action be added into prefix sub flow, and the suffix sub
5237 * flow uses tag item with the unique flow id.
5240 * Pointer to Ethernet device.
5242 * Parent flow structure pointer.
5244 * Flow rule attributes.
5246 * Pattern specification (list terminated by the END pattern item).
5247 * @param[in] actions
5248 * Associated actions (list terminated by the END action).
5249 * @param[in] flow_split_info
5250 * Pointer to flow split info structure.
5252 * Perform verbose error reporting if not NULL.
5254 * 0 on success, negative value otherwise
5257 flow_create_split_sample(struct rte_eth_dev *dev,
5258 struct rte_flow *flow,
5259 const struct rte_flow_attr *attr,
5260 const struct rte_flow_item items[],
5261 const struct rte_flow_action actions[],
5262 struct mlx5_flow_split_info *flow_split_info,
5263 struct rte_flow_error *error)
5265 struct mlx5_priv *priv = dev->data->dev_private;
5266 struct rte_flow_action *sfx_actions = NULL;
5267 struct rte_flow_action *pre_actions = NULL;
5268 struct rte_flow_item *sfx_items = NULL;
5269 struct mlx5_flow *dev_flow = NULL;
5270 struct rte_flow_attr sfx_attr = *attr;
5271 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
5272 struct mlx5_flow_dv_sample_resource *sample_res;
5273 struct mlx5_flow_tbl_data_entry *sfx_tbl_data;
5274 struct mlx5_flow_tbl_resource *sfx_tbl;
5275 union mlx5_flow_tbl_key sfx_table_key;
5279 uint32_t fdb_tx = 0;
5282 int sample_action_pos;
5283 int qrss_action_pos;
5286 if (priv->sampler_en)
5287 actions_n = flow_check_match_action(actions, attr,
5288 RTE_FLOW_ACTION_TYPE_SAMPLE,
5289 &sample_action_pos, &qrss_action_pos);
5291 /* The prefix actions must includes sample, tag, end. */
5292 act_size = sizeof(struct rte_flow_action) * (actions_n * 2 + 1)
5293 + sizeof(struct mlx5_rte_flow_action_set_tag);
5294 item_size = sizeof(struct rte_flow_item) * SAMPLE_SUFFIX_ITEM +
5295 sizeof(struct mlx5_rte_flow_item_tag) * 2;
5296 sfx_actions = mlx5_malloc(MLX5_MEM_ZERO, (act_size +
5297 item_size), 0, SOCKET_ID_ANY);
5299 return rte_flow_error_set(error, ENOMEM,
5300 RTE_FLOW_ERROR_TYPE_ACTION,
5301 NULL, "no memory to split "
5303 /* The representor_id is -1 for uplink. */
5304 fdb_tx = (attr->transfer && priv->representor_id != -1);
5306 sfx_items = (struct rte_flow_item *)((char *)sfx_actions
5308 pre_actions = sfx_actions + actions_n;
5309 tag_id = flow_sample_split_prep(dev, fdb_tx, sfx_items,
5310 actions, sfx_actions,
5311 pre_actions, actions_n,
5313 qrss_action_pos, error);
5314 if (tag_id < 0 || (!fdb_tx && !tag_id)) {
5318 /* Add the prefix subflow. */
5319 ret = flow_create_split_inner(dev, flow, &dev_flow, attr,
5321 flow_split_info, error);
5326 dev_flow->handle->split_flow_id = tag_id;
5327 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
5328 /* Set the sfx group attr. */
5329 sample_res = (struct mlx5_flow_dv_sample_resource *)
5330 dev_flow->dv.sample_res;
5331 sfx_tbl = (struct mlx5_flow_tbl_resource *)
5332 sample_res->normal_path_tbl;
5333 sfx_tbl_data = container_of(sfx_tbl,
5334 struct mlx5_flow_tbl_data_entry, tbl);
5335 sfx_table_key.v64 = sfx_tbl_data->entry.key;
5336 sfx_attr.group = sfx_attr.transfer ?
5337 (sfx_table_key.table_id - 1) :
5338 sfx_table_key.table_id;
5339 flow_split_info->prefix_layers =
5340 flow_get_prefix_layer_flags(dev_flow);
5341 flow_split_info->prefix_mark = dev_flow->handle->mark;
5342 /* Suffix group level already be scaled with factor, set
5343 * skip_scale to 1 to avoid scale again in translation.
5345 flow_split_info->skip_scale = 1;
5348 /* Add the suffix subflow. */
5349 ret = flow_create_split_meter(dev, flow, &sfx_attr,
5350 sfx_items ? sfx_items : items,
5351 sfx_actions ? sfx_actions : actions,
5352 flow_split_info, error);
5355 mlx5_free(sfx_actions);
5360 * Split the flow to subflow set. The splitters might be linked
5361 * in the chain, like this:
5362 * flow_create_split_outer() calls:
5363 * flow_create_split_meter() calls:
5364 * flow_create_split_metadata(meter_subflow_0) calls:
5365 * flow_create_split_inner(metadata_subflow_0)
5366 * flow_create_split_inner(metadata_subflow_1)
5367 * flow_create_split_inner(metadata_subflow_2)
5368 * flow_create_split_metadata(meter_subflow_1) calls:
5369 * flow_create_split_inner(metadata_subflow_0)
5370 * flow_create_split_inner(metadata_subflow_1)
5371 * flow_create_split_inner(metadata_subflow_2)
5373 * This provide flexible way to add new levels of flow splitting.
5374 * The all of successfully created subflows are included to the
5375 * parent flow dev_flow list.
5378 * Pointer to Ethernet device.
5380 * Parent flow structure pointer.
5382 * Flow rule attributes.
5384 * Pattern specification (list terminated by the END pattern item).
5385 * @param[in] actions
5386 * Associated actions (list terminated by the END action).
5387 * @param[in] flow_split_info
5388 * Pointer to flow split info structure.
5390 * Perform verbose error reporting if not NULL.
5392 * 0 on success, negative value otherwise
5395 flow_create_split_outer(struct rte_eth_dev *dev,
5396 struct rte_flow *flow,
5397 const struct rte_flow_attr *attr,
5398 const struct rte_flow_item items[],
5399 const struct rte_flow_action actions[],
5400 struct mlx5_flow_split_info *flow_split_info,
5401 struct rte_flow_error *error)
5405 ret = flow_create_split_sample(dev, flow, attr, items,
5406 actions, flow_split_info, error);
5407 MLX5_ASSERT(ret <= 0);
5411 static struct mlx5_flow_tunnel *
5412 flow_tunnel_from_rule(struct rte_eth_dev *dev,
5413 const struct rte_flow_attr *attr,
5414 const struct rte_flow_item items[],
5415 const struct rte_flow_action actions[])
5417 struct mlx5_flow_tunnel *tunnel;
5419 #pragma GCC diagnostic push
5420 #pragma GCC diagnostic ignored "-Wcast-qual"
5421 if (is_flow_tunnel_match_rule(dev, attr, items, actions))
5422 tunnel = (struct mlx5_flow_tunnel *)items[0].spec;
5423 else if (is_flow_tunnel_steer_rule(dev, attr, items, actions))
5424 tunnel = (struct mlx5_flow_tunnel *)actions[0].conf;
5427 #pragma GCC diagnostic pop
5433 * Adjust flow RSS workspace if needed.
5436 * Pointer to thread flow work space.
5438 * Pointer to RSS descriptor.
5439 * @param[in] nrssq_num
5440 * New RSS queue number.
5443 * 0 on success, -1 otherwise and rte_errno is set.
5446 flow_rss_workspace_adjust(struct mlx5_flow_workspace *wks,
5447 struct mlx5_flow_rss_desc *rss_desc,
5450 if (likely(nrssq_num <= wks->rssq_num))
5452 rss_desc->queue = realloc(rss_desc->queue,
5453 sizeof(*rss_desc->queue) * RTE_ALIGN(nrssq_num, 2));
5454 if (!rss_desc->queue) {
5458 wks->rssq_num = RTE_ALIGN(nrssq_num, 2);
5463 * Create a flow and add it to @p list.
5466 * Pointer to Ethernet device.
5468 * Pointer to a TAILQ flow list. If this parameter NULL,
5469 * no list insertion occurred, flow is just created,
5470 * this is caller's responsibility to track the
5473 * Flow rule attributes.
5475 * Pattern specification (list terminated by the END pattern item).
5476 * @param[in] actions
5477 * Associated actions (list terminated by the END action).
5478 * @param[in] external
5479 * This flow rule is created by request external to PMD.
5481 * Perform verbose error reporting if not NULL.
5484 * A flow index on success, 0 otherwise and rte_errno is set.
5487 flow_list_create(struct rte_eth_dev *dev, uint32_t *list,
5488 const struct rte_flow_attr *attr,
5489 const struct rte_flow_item items[],
5490 const struct rte_flow_action original_actions[],
5491 bool external, struct rte_flow_error *error)
5493 struct mlx5_priv *priv = dev->data->dev_private;
5494 struct rte_flow *flow = NULL;
5495 struct mlx5_flow *dev_flow;
5496 const struct rte_flow_action_rss *rss;
5497 struct mlx5_translated_shared_action
5498 shared_actions[MLX5_MAX_SHARED_ACTIONS];
5499 int shared_actions_n = MLX5_MAX_SHARED_ACTIONS;
5501 struct mlx5_flow_expand_rss buf;
5502 uint8_t buffer[2048];
5505 struct rte_flow_action actions[MLX5_MAX_SPLIT_ACTIONS];
5506 uint8_t buffer[2048];
5509 struct rte_flow_action actions[MLX5_MAX_SPLIT_ACTIONS];
5510 uint8_t buffer[2048];
5511 } actions_hairpin_tx;
5513 struct rte_flow_item items[MLX5_MAX_SPLIT_ITEMS];
5514 uint8_t buffer[2048];
5516 struct mlx5_flow_expand_rss *buf = &expand_buffer.buf;
5517 struct mlx5_flow_rss_desc *rss_desc;
5518 const struct rte_flow_action *p_actions_rx;
5522 struct rte_flow_attr attr_tx = { .priority = 0 };
5523 const struct rte_flow_action *actions;
5524 struct rte_flow_action *translated_actions = NULL;
5525 struct mlx5_flow_tunnel *tunnel;
5526 struct tunnel_default_miss_ctx default_miss_ctx = { 0, };
5527 struct mlx5_flow_workspace *wks = mlx5_flow_push_thread_workspace();
5528 struct mlx5_flow_split_info flow_split_info = {
5529 .external = !!external,
5538 rss_desc = &wks->rss_desc;
5539 ret = flow_shared_actions_translate(dev, original_actions,
5542 &translated_actions, error);
5544 MLX5_ASSERT(translated_actions == NULL);
5547 actions = translated_actions ? translated_actions : original_actions;
5548 p_actions_rx = actions;
5549 hairpin_flow = flow_check_hairpin_split(dev, attr, actions);
5550 ret = flow_drv_validate(dev, attr, items, p_actions_rx,
5551 external, hairpin_flow, error);
5553 goto error_before_hairpin_split;
5554 flow = mlx5_ipool_zmalloc(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], &idx);
5557 goto error_before_hairpin_split;
5559 if (hairpin_flow > 0) {
5560 if (hairpin_flow > MLX5_MAX_SPLIT_ACTIONS) {
5562 goto error_before_hairpin_split;
5564 flow_hairpin_split(dev, actions, actions_rx.actions,
5565 actions_hairpin_tx.actions, items_tx.items,
5567 p_actions_rx = actions_rx.actions;
5569 flow_split_info.flow_idx = idx;
5570 flow->drv_type = flow_get_drv_type(dev, attr);
5571 MLX5_ASSERT(flow->drv_type > MLX5_FLOW_TYPE_MIN &&
5572 flow->drv_type < MLX5_FLOW_TYPE_MAX);
5573 memset(rss_desc, 0, offsetof(struct mlx5_flow_rss_desc, queue));
5574 rss = flow_get_rss_action(p_actions_rx);
5576 if (flow_rss_workspace_adjust(wks, rss_desc, rss->queue_num))
5579 * The following information is required by
5580 * mlx5_flow_hashfields_adjust() in advance.
5582 rss_desc->level = rss->level;
5583 /* RSS type 0 indicates default RSS type (ETH_RSS_IP). */
5584 rss_desc->types = !rss->types ? ETH_RSS_IP : rss->types;
5586 flow->dev_handles = 0;
5587 if (rss && rss->types) {
5588 unsigned int graph_root;
5590 graph_root = find_graph_root(items, rss->level);
5591 ret = mlx5_flow_expand_rss(buf, sizeof(expand_buffer.buffer),
5593 mlx5_support_expansion, graph_root);
5594 MLX5_ASSERT(ret > 0 &&
5595 (unsigned int)ret < sizeof(expand_buffer.buffer));
5598 buf->entry[0].pattern = (void *)(uintptr_t)items;
5600 rss_desc->shared_rss = flow_get_shared_rss_action(dev, shared_actions,
5602 for (i = 0; i < buf->entries; ++i) {
5603 /* Initialize flow split data. */
5604 flow_split_info.prefix_layers = 0;
5605 flow_split_info.prefix_mark = 0;
5606 flow_split_info.skip_scale = 0;
5608 * The splitter may create multiple dev_flows,
5609 * depending on configuration. In the simplest
5610 * case it just creates unmodified original flow.
5612 ret = flow_create_split_outer(dev, flow, attr,
5613 buf->entry[i].pattern,
5614 p_actions_rx, &flow_split_info,
5618 if (is_flow_tunnel_steer_rule(dev, attr,
5619 buf->entry[i].pattern,
5621 ret = flow_tunnel_add_default_miss(dev, flow, attr,
5627 mlx5_free(default_miss_ctx.queue);
5632 /* Create the tx flow. */
5634 attr_tx.group = MLX5_HAIRPIN_TX_TABLE;
5635 attr_tx.ingress = 0;
5637 dev_flow = flow_drv_prepare(dev, flow, &attr_tx, items_tx.items,
5638 actions_hairpin_tx.actions,
5642 dev_flow->flow = flow;
5643 dev_flow->external = 0;
5644 SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
5645 dev_flow->handle, next);
5646 ret = flow_drv_translate(dev, dev_flow, &attr_tx,
5648 actions_hairpin_tx.actions, error);
5653 * Update the metadata register copy table. If extensive
5654 * metadata feature is enabled and registers are supported
5655 * we might create the extra rte_flow for each unique
5656 * MARK/FLAG action ID.
5658 * The table is updated for ingress Flows only, because
5659 * the egress Flows belong to the different device and
5660 * copy table should be updated in peer NIC Rx domain.
5662 if (attr->ingress &&
5663 (external || attr->group != MLX5_FLOW_MREG_CP_TABLE_GROUP)) {
5664 ret = flow_mreg_update_copy_table(dev, flow, actions, error);
5669 * If the flow is external (from application) OR device is started,
5670 * OR mreg discover, then apply immediately.
5672 if (external || dev->data->dev_started ||
5673 (attr->group == MLX5_FLOW_MREG_CP_TABLE_GROUP &&
5674 attr->priority == MLX5_FLOW_PRIO_RSVD)) {
5675 ret = flow_drv_apply(dev, flow, error);
5680 rte_spinlock_lock(&priv->flow_list_lock);
5681 ILIST_INSERT(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], list, idx,
5683 rte_spinlock_unlock(&priv->flow_list_lock);
5685 flow_rxq_flags_set(dev, flow);
5686 rte_free(translated_actions);
5687 tunnel = flow_tunnel_from_rule(dev, attr, items, actions);
5690 flow->tunnel_id = tunnel->tunnel_id;
5691 __atomic_add_fetch(&tunnel->refctn, 1, __ATOMIC_RELAXED);
5692 mlx5_free(default_miss_ctx.queue);
5694 mlx5_flow_pop_thread_workspace();
5698 ret = rte_errno; /* Save rte_errno before cleanup. */
5699 flow_mreg_del_copy_action(dev, flow);
5700 flow_drv_destroy(dev, flow);
5701 if (rss_desc->shared_rss)
5702 __atomic_sub_fetch(&((struct mlx5_shared_action_rss *)
5704 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
5705 rss_desc->shared_rss))->refcnt, 1, __ATOMIC_RELAXED);
5706 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], idx);
5707 rte_errno = ret; /* Restore rte_errno. */
5710 mlx5_flow_pop_thread_workspace();
5711 error_before_hairpin_split:
5712 rte_free(translated_actions);
5717 * Create a dedicated flow rule on e-switch table 0 (root table), to direct all
5718 * incoming packets to table 1.
5720 * Other flow rules, requested for group n, will be created in
5721 * e-switch table n+1.
5722 * Jump action to e-switch group n will be created to group n+1.
5724 * Used when working in switchdev mode, to utilise advantages of table 1
5728 * Pointer to Ethernet device.
5731 * Pointer to flow on success, NULL otherwise and rte_errno is set.
5734 mlx5_flow_create_esw_table_zero_flow(struct rte_eth_dev *dev)
5736 const struct rte_flow_attr attr = {
5743 const struct rte_flow_item pattern = {
5744 .type = RTE_FLOW_ITEM_TYPE_END,
5746 struct rte_flow_action_jump jump = {
5749 const struct rte_flow_action actions[] = {
5751 .type = RTE_FLOW_ACTION_TYPE_JUMP,
5755 .type = RTE_FLOW_ACTION_TYPE_END,
5758 struct mlx5_priv *priv = dev->data->dev_private;
5759 struct rte_flow_error error;
5761 return (void *)(uintptr_t)flow_list_create(dev, &priv->ctrl_flows,
5763 actions, false, &error);
5767 * Validate a flow supported by the NIC.
5769 * @see rte_flow_validate()
5773 mlx5_flow_validate(struct rte_eth_dev *dev,
5774 const struct rte_flow_attr *attr,
5775 const struct rte_flow_item items[],
5776 const struct rte_flow_action original_actions[],
5777 struct rte_flow_error *error)
5780 struct mlx5_translated_shared_action
5781 shared_actions[MLX5_MAX_SHARED_ACTIONS];
5782 int shared_actions_n = MLX5_MAX_SHARED_ACTIONS;
5783 const struct rte_flow_action *actions;
5784 struct rte_flow_action *translated_actions = NULL;
5785 int ret = flow_shared_actions_translate(dev, original_actions,
5788 &translated_actions, error);
5792 actions = translated_actions ? translated_actions : original_actions;
5793 hairpin_flow = flow_check_hairpin_split(dev, attr, actions);
5794 ret = flow_drv_validate(dev, attr, items, actions,
5795 true, hairpin_flow, error);
5796 rte_free(translated_actions);
5803 * @see rte_flow_create()
5807 mlx5_flow_create(struct rte_eth_dev *dev,
5808 const struct rte_flow_attr *attr,
5809 const struct rte_flow_item items[],
5810 const struct rte_flow_action actions[],
5811 struct rte_flow_error *error)
5813 struct mlx5_priv *priv = dev->data->dev_private;
5816 * If the device is not started yet, it is not allowed to created a
5817 * flow from application. PMD default flows and traffic control flows
5820 if (unlikely(!dev->data->dev_started)) {
5821 DRV_LOG(DEBUG, "port %u is not started when "
5822 "inserting a flow", dev->data->port_id);
5823 rte_flow_error_set(error, ENODEV,
5824 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5826 "port not started");
5830 return (void *)(uintptr_t)flow_list_create(dev, &priv->flows,
5831 attr, items, actions, true, error);
5835 * Destroy a flow in a list.
5838 * Pointer to Ethernet device.
5840 * Pointer to the Indexed flow list. If this parameter NULL,
5841 * there is no flow removal from the list. Be noted that as
5842 * flow is add to the indexed list, memory of the indexed
5843 * list points to maybe changed as flow destroyed.
5844 * @param[in] flow_idx
5845 * Index of flow to destroy.
5848 flow_list_destroy(struct rte_eth_dev *dev, uint32_t *list,
5851 struct mlx5_priv *priv = dev->data->dev_private;
5852 struct rte_flow *flow = mlx5_ipool_get(priv->sh->ipool
5853 [MLX5_IPOOL_RTE_FLOW], flow_idx);
5858 * Update RX queue flags only if port is started, otherwise it is
5861 if (dev->data->dev_started)
5862 flow_rxq_flags_trim(dev, flow);
5863 flow_drv_destroy(dev, flow);
5865 rte_spinlock_lock(&priv->flow_list_lock);
5866 ILIST_REMOVE(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], list,
5867 flow_idx, flow, next);
5868 rte_spinlock_unlock(&priv->flow_list_lock);
5871 struct mlx5_flow_tunnel *tunnel;
5873 rte_spinlock_lock(&mlx5_tunnel_hub(dev)->sl);
5874 tunnel = mlx5_find_tunnel_id(dev, flow->tunnel_id);
5876 LIST_REMOVE(tunnel, chain);
5877 rte_spinlock_unlock(&mlx5_tunnel_hub(dev)->sl);
5878 if (!__atomic_sub_fetch(&tunnel->refctn, 1, __ATOMIC_RELAXED))
5879 mlx5_flow_tunnel_free(dev, tunnel);
5881 flow_mreg_del_copy_action(dev, flow);
5882 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], flow_idx);
5886 * Destroy all flows.
5889 * Pointer to Ethernet device.
5891 * Pointer to the Indexed flow list.
5893 * If flushing is called avtively.
5896 mlx5_flow_list_flush(struct rte_eth_dev *dev, uint32_t *list, bool active)
5898 uint32_t num_flushed = 0;
5901 flow_list_destroy(dev, list, *list);
5905 DRV_LOG(INFO, "port %u: %u flows flushed before stopping",
5906 dev->data->port_id, num_flushed);
5911 * Stop all default actions for flows.
5914 * Pointer to Ethernet device.
5917 mlx5_flow_stop_default(struct rte_eth_dev *dev)
5919 flow_mreg_del_default_copy_action(dev);
5920 flow_rxq_flags_clear(dev);
5924 * Start all default actions for flows.
5927 * Pointer to Ethernet device.
5929 * 0 on success, a negative errno value otherwise and rte_errno is set.
5932 mlx5_flow_start_default(struct rte_eth_dev *dev)
5934 struct rte_flow_error error;
5936 /* Make sure default copy action (reg_c[0] -> reg_b) is created. */
5937 return flow_mreg_add_default_copy_action(dev, &error);
5941 * Release key of thread specific flow workspace data.
5944 flow_release_workspace(void *data)
5946 struct mlx5_flow_workspace *wks = data;
5947 struct mlx5_flow_workspace *next;
5951 free(wks->rss_desc.queue);
5958 * Initialize key of thread specific flow workspace data.
5961 flow_alloc_workspace(void)
5963 if (pthread_key_create(&key_workspace, flow_release_workspace))
5964 DRV_LOG(ERR, "Can't create flow workspace data thread key.");
5968 * Get thread specific current flow workspace.
5970 * @return pointer to thread specific flow workspace data, NULL on error.
5972 struct mlx5_flow_workspace*
5973 mlx5_flow_get_thread_workspace(void)
5975 struct mlx5_flow_workspace *data;
5977 data = pthread_getspecific(key_workspace);
5978 MLX5_ASSERT(data && data->inuse);
5979 if (!data || !data->inuse)
5980 DRV_LOG(ERR, "flow workspace not initialized.");
5985 * Allocate and init new flow workspace.
5987 * @return pointer to flow workspace data, NULL on error.
5989 static struct mlx5_flow_workspace*
5990 flow_alloc_thread_workspace(void)
5992 struct mlx5_flow_workspace *data = calloc(1, sizeof(*data));
5995 DRV_LOG(ERR, "Failed to allocate flow workspace "
5999 data->rss_desc.queue = calloc(1,
6000 sizeof(uint16_t) * MLX5_RSSQ_DEFAULT_NUM);
6001 if (!data->rss_desc.queue)
6003 data->rssq_num = MLX5_RSSQ_DEFAULT_NUM;
6006 if (data->rss_desc.queue)
6007 free(data->rss_desc.queue);
6013 * Get new thread specific flow workspace.
6015 * If current workspace inuse, create new one and set as current.
6017 * @return pointer to thread specific flow workspace data, NULL on error.
6019 static struct mlx5_flow_workspace*
6020 mlx5_flow_push_thread_workspace(void)
6022 struct mlx5_flow_workspace *curr;
6023 struct mlx5_flow_workspace *data;
6025 if (pthread_once(&key_workspace_init, flow_alloc_workspace)) {
6026 DRV_LOG(ERR, "Failed to init flow workspace data thread key.");
6029 curr = pthread_getspecific(key_workspace);
6031 data = flow_alloc_thread_workspace();
6034 } else if (!curr->inuse) {
6036 } else if (curr->next) {
6039 data = flow_alloc_thread_workspace();
6047 /* Set as current workspace */
6048 if (pthread_setspecific(key_workspace, data))
6049 DRV_LOG(ERR, "Failed to set flow workspace to thread.");
6054 * Close current thread specific flow workspace.
6056 * If previous workspace available, set it as current.
6058 * @return pointer to thread specific flow workspace data, NULL on error.
6061 mlx5_flow_pop_thread_workspace(void)
6063 struct mlx5_flow_workspace *data = mlx5_flow_get_thread_workspace();
6068 DRV_LOG(ERR, "Failed to close unused flow workspace.");
6074 if (pthread_setspecific(key_workspace, data->prev))
6075 DRV_LOG(ERR, "Failed to set flow workspace to thread.");
6079 * Verify the flow list is empty
6082 * Pointer to Ethernet device.
6084 * @return the number of flows not released.
6087 mlx5_flow_verify(struct rte_eth_dev *dev)
6089 struct mlx5_priv *priv = dev->data->dev_private;
6090 struct rte_flow *flow;
6094 ILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], priv->flows, idx,
6096 DRV_LOG(DEBUG, "port %u flow %p still referenced",
6097 dev->data->port_id, (void *)flow);
6104 * Enable default hairpin egress flow.
6107 * Pointer to Ethernet device.
6112 * 0 on success, a negative errno value otherwise and rte_errno is set.
6115 mlx5_ctrl_flow_source_queue(struct rte_eth_dev *dev,
6118 struct mlx5_priv *priv = dev->data->dev_private;
6119 const struct rte_flow_attr attr = {
6123 struct mlx5_rte_flow_item_tx_queue queue_spec = {
6126 struct mlx5_rte_flow_item_tx_queue queue_mask = {
6127 .queue = UINT32_MAX,
6129 struct rte_flow_item items[] = {
6131 .type = (enum rte_flow_item_type)
6132 MLX5_RTE_FLOW_ITEM_TYPE_TX_QUEUE,
6133 .spec = &queue_spec,
6135 .mask = &queue_mask,
6138 .type = RTE_FLOW_ITEM_TYPE_END,
6141 struct rte_flow_action_jump jump = {
6142 .group = MLX5_HAIRPIN_TX_TABLE,
6144 struct rte_flow_action actions[2];
6146 struct rte_flow_error error;
6148 actions[0].type = RTE_FLOW_ACTION_TYPE_JUMP;
6149 actions[0].conf = &jump;
6150 actions[1].type = RTE_FLOW_ACTION_TYPE_END;
6151 flow_idx = flow_list_create(dev, &priv->ctrl_flows,
6152 &attr, items, actions, false, &error);
6155 "Failed to create ctrl flow: rte_errno(%d),"
6156 " type(%d), message(%s)",
6157 rte_errno, error.type,
6158 error.message ? error.message : " (no stated reason)");
6165 * Enable a control flow configured from the control plane.
6168 * Pointer to Ethernet device.
6170 * An Ethernet flow spec to apply.
6172 * An Ethernet flow mask to apply.
6174 * A VLAN flow spec to apply.
6176 * A VLAN flow mask to apply.
6179 * 0 on success, a negative errno value otherwise and rte_errno is set.
6182 mlx5_ctrl_flow_vlan(struct rte_eth_dev *dev,
6183 struct rte_flow_item_eth *eth_spec,
6184 struct rte_flow_item_eth *eth_mask,
6185 struct rte_flow_item_vlan *vlan_spec,
6186 struct rte_flow_item_vlan *vlan_mask)
6188 struct mlx5_priv *priv = dev->data->dev_private;
6189 const struct rte_flow_attr attr = {
6191 .priority = MLX5_FLOW_PRIO_RSVD,
6193 struct rte_flow_item items[] = {
6195 .type = RTE_FLOW_ITEM_TYPE_ETH,
6201 .type = (vlan_spec) ? RTE_FLOW_ITEM_TYPE_VLAN :
6202 RTE_FLOW_ITEM_TYPE_END,
6208 .type = RTE_FLOW_ITEM_TYPE_END,
6211 uint16_t queue[priv->reta_idx_n];
6212 struct rte_flow_action_rss action_rss = {
6213 .func = RTE_ETH_HASH_FUNCTION_DEFAULT,
6215 .types = priv->rss_conf.rss_hf,
6216 .key_len = priv->rss_conf.rss_key_len,
6217 .queue_num = priv->reta_idx_n,
6218 .key = priv->rss_conf.rss_key,
6221 struct rte_flow_action actions[] = {
6223 .type = RTE_FLOW_ACTION_TYPE_RSS,
6224 .conf = &action_rss,
6227 .type = RTE_FLOW_ACTION_TYPE_END,
6231 struct rte_flow_error error;
6234 if (!priv->reta_idx_n || !priv->rxqs_n) {
6237 if (!(dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG))
6238 action_rss.types = 0;
6239 for (i = 0; i != priv->reta_idx_n; ++i)
6240 queue[i] = (*priv->reta_idx)[i];
6241 flow_idx = flow_list_create(dev, &priv->ctrl_flows,
6242 &attr, items, actions, false, &error);
6249 * Enable a flow control configured from the control plane.
6252 * Pointer to Ethernet device.
6254 * An Ethernet flow spec to apply.
6256 * An Ethernet flow mask to apply.
6259 * 0 on success, a negative errno value otherwise and rte_errno is set.
6262 mlx5_ctrl_flow(struct rte_eth_dev *dev,
6263 struct rte_flow_item_eth *eth_spec,
6264 struct rte_flow_item_eth *eth_mask)
6266 return mlx5_ctrl_flow_vlan(dev, eth_spec, eth_mask, NULL, NULL);
6270 * Create default miss flow rule matching lacp traffic
6273 * Pointer to Ethernet device.
6275 * An Ethernet flow spec to apply.
6278 * 0 on success, a negative errno value otherwise and rte_errno is set.
6281 mlx5_flow_lacp_miss(struct rte_eth_dev *dev)
6283 struct mlx5_priv *priv = dev->data->dev_private;
6285 * The LACP matching is done by only using ether type since using
6286 * a multicast dst mac causes kernel to give low priority to this flow.
6288 static const struct rte_flow_item_eth lacp_spec = {
6289 .type = RTE_BE16(0x8809),
6291 static const struct rte_flow_item_eth lacp_mask = {
6294 const struct rte_flow_attr attr = {
6297 struct rte_flow_item items[] = {
6299 .type = RTE_FLOW_ITEM_TYPE_ETH,
6304 .type = RTE_FLOW_ITEM_TYPE_END,
6307 struct rte_flow_action actions[] = {
6309 .type = (enum rte_flow_action_type)
6310 MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS,
6313 .type = RTE_FLOW_ACTION_TYPE_END,
6316 struct rte_flow_error error;
6317 uint32_t flow_idx = flow_list_create(dev, &priv->ctrl_flows,
6318 &attr, items, actions, false, &error);
6328 * @see rte_flow_destroy()
6332 mlx5_flow_destroy(struct rte_eth_dev *dev,
6333 struct rte_flow *flow,
6334 struct rte_flow_error *error __rte_unused)
6336 struct mlx5_priv *priv = dev->data->dev_private;
6338 flow_list_destroy(dev, &priv->flows, (uintptr_t)(void *)flow);
6343 * Destroy all flows.
6345 * @see rte_flow_flush()
6349 mlx5_flow_flush(struct rte_eth_dev *dev,
6350 struct rte_flow_error *error __rte_unused)
6352 struct mlx5_priv *priv = dev->data->dev_private;
6354 mlx5_flow_list_flush(dev, &priv->flows, false);
6361 * @see rte_flow_isolate()
6365 mlx5_flow_isolate(struct rte_eth_dev *dev,
6367 struct rte_flow_error *error)
6369 struct mlx5_priv *priv = dev->data->dev_private;
6371 if (dev->data->dev_started) {
6372 rte_flow_error_set(error, EBUSY,
6373 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6375 "port must be stopped first");
6378 priv->isolated = !!enable;
6380 dev->dev_ops = &mlx5_os_dev_ops_isolate;
6382 dev->dev_ops = &mlx5_os_dev_ops;
6384 dev->rx_descriptor_status = mlx5_rx_descriptor_status;
6385 dev->tx_descriptor_status = mlx5_tx_descriptor_status;
6393 * @see rte_flow_query()
6397 flow_drv_query(struct rte_eth_dev *dev,
6399 const struct rte_flow_action *actions,
6401 struct rte_flow_error *error)
6403 struct mlx5_priv *priv = dev->data->dev_private;
6404 const struct mlx5_flow_driver_ops *fops;
6405 struct rte_flow *flow = mlx5_ipool_get(priv->sh->ipool
6406 [MLX5_IPOOL_RTE_FLOW],
6408 enum mlx5_flow_drv_type ftype;
6411 return rte_flow_error_set(error, ENOENT,
6412 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6414 "invalid flow handle");
6416 ftype = flow->drv_type;
6417 MLX5_ASSERT(ftype > MLX5_FLOW_TYPE_MIN && ftype < MLX5_FLOW_TYPE_MAX);
6418 fops = flow_get_drv_ops(ftype);
6420 return fops->query(dev, flow, actions, data, error);
6426 * @see rte_flow_query()
6430 mlx5_flow_query(struct rte_eth_dev *dev,
6431 struct rte_flow *flow,
6432 const struct rte_flow_action *actions,
6434 struct rte_flow_error *error)
6438 ret = flow_drv_query(dev, (uintptr_t)(void *)flow, actions, data,
6446 * Manage filter operations.
6449 * Pointer to Ethernet device structure.
6450 * @param filter_type
6453 * Operation to perform.
6455 * Pointer to operation-specific structure.
6458 * 0 on success, a negative errno value otherwise and rte_errno is set.
6461 mlx5_dev_filter_ctrl(struct rte_eth_dev *dev,
6462 enum rte_filter_type filter_type,
6463 enum rte_filter_op filter_op,
6466 switch (filter_type) {
6467 case RTE_ETH_FILTER_GENERIC:
6468 if (filter_op != RTE_ETH_FILTER_GET) {
6472 *(const void **)arg = &mlx5_flow_ops;
6475 DRV_LOG(ERR, "port %u filter type (%d) not supported",
6476 dev->data->port_id, filter_type);
6477 rte_errno = ENOTSUP;
6484 * Create the needed meter and suffix tables.
6487 * Pointer to Ethernet device.
6489 * Pointer to the flow meter.
6492 * Pointer to table set on success, NULL otherwise.
6494 struct mlx5_meter_domains_infos *
6495 mlx5_flow_create_mtr_tbls(struct rte_eth_dev *dev,
6496 const struct mlx5_flow_meter *fm)
6498 const struct mlx5_flow_driver_ops *fops;
6500 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
6501 return fops->create_mtr_tbls(dev, fm);
6505 * Destroy the meter table set.
6508 * Pointer to Ethernet device.
6510 * Pointer to the meter table set.
6516 mlx5_flow_destroy_mtr_tbls(struct rte_eth_dev *dev,
6517 struct mlx5_meter_domains_infos *tbls)
6519 const struct mlx5_flow_driver_ops *fops;
6521 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
6522 return fops->destroy_mtr_tbls(dev, tbls);
6526 * Create policer rules.
6529 * Pointer to Ethernet device.
6531 * Pointer to flow meter structure.
6533 * Pointer to flow attributes.
6536 * 0 on success, -1 otherwise.
6539 mlx5_flow_create_policer_rules(struct rte_eth_dev *dev,
6540 struct mlx5_flow_meter *fm,
6541 const struct rte_flow_attr *attr)
6543 const struct mlx5_flow_driver_ops *fops;
6545 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
6546 return fops->create_policer_rules(dev, fm, attr);
6550 * Destroy policer rules.
6553 * Pointer to flow meter structure.
6555 * Pointer to flow attributes.
6558 * 0 on success, -1 otherwise.
6561 mlx5_flow_destroy_policer_rules(struct rte_eth_dev *dev,
6562 struct mlx5_flow_meter *fm,
6563 const struct rte_flow_attr *attr)
6565 const struct mlx5_flow_driver_ops *fops;
6567 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
6568 return fops->destroy_policer_rules(dev, fm, attr);
6572 * Allocate a counter.
6575 * Pointer to Ethernet device structure.
6578 * Index to allocated counter on success, 0 otherwise.
6581 mlx5_counter_alloc(struct rte_eth_dev *dev)
6583 const struct mlx5_flow_driver_ops *fops;
6584 struct rte_flow_attr attr = { .transfer = 0 };
6586 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
6587 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
6588 return fops->counter_alloc(dev);
6591 "port %u counter allocate is not supported.",
6592 dev->data->port_id);
6600 * Pointer to Ethernet device structure.
6602 * Index to counter to be free.
6605 mlx5_counter_free(struct rte_eth_dev *dev, uint32_t cnt)
6607 const struct mlx5_flow_driver_ops *fops;
6608 struct rte_flow_attr attr = { .transfer = 0 };
6610 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
6611 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
6612 fops->counter_free(dev, cnt);
6616 "port %u counter free is not supported.",
6617 dev->data->port_id);
6621 * Query counter statistics.
6624 * Pointer to Ethernet device structure.
6626 * Index to counter to query.
6628 * Set to clear counter statistics.
6630 * The counter hits packets number to save.
6632 * The counter hits bytes number to save.
6635 * 0 on success, a negative errno value otherwise.
6638 mlx5_counter_query(struct rte_eth_dev *dev, uint32_t cnt,
6639 bool clear, uint64_t *pkts, uint64_t *bytes)
6641 const struct mlx5_flow_driver_ops *fops;
6642 struct rte_flow_attr attr = { .transfer = 0 };
6644 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
6645 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
6646 return fops->counter_query(dev, cnt, clear, pkts, bytes);
6649 "port %u counter query is not supported.",
6650 dev->data->port_id);
6655 * Allocate a new memory for the counter values wrapped by all the needed
6659 * Pointer to mlx5_dev_ctx_shared object.
6662 * 0 on success, a negative errno value otherwise.
6665 mlx5_flow_create_counter_stat_mem_mng(struct mlx5_dev_ctx_shared *sh)
6667 struct mlx5_devx_mkey_attr mkey_attr;
6668 struct mlx5_counter_stats_mem_mng *mem_mng;
6669 volatile struct flow_counter_stats *raw_data;
6670 int raws_n = MLX5_CNT_CONTAINER_RESIZE + MLX5_MAX_PENDING_QUERIES;
6671 int size = (sizeof(struct flow_counter_stats) *
6672 MLX5_COUNTERS_PER_POOL +
6673 sizeof(struct mlx5_counter_stats_raw)) * raws_n +
6674 sizeof(struct mlx5_counter_stats_mem_mng);
6675 size_t pgsize = rte_mem_page_size();
6679 if (pgsize == (size_t)-1) {
6680 DRV_LOG(ERR, "Failed to get mem page size");
6684 mem = mlx5_malloc(MLX5_MEM_ZERO, size, pgsize, SOCKET_ID_ANY);
6689 mem_mng = (struct mlx5_counter_stats_mem_mng *)(mem + size) - 1;
6690 size = sizeof(*raw_data) * MLX5_COUNTERS_PER_POOL * raws_n;
6691 mem_mng->umem = mlx5_glue->devx_umem_reg(sh->ctx, mem, size,
6692 IBV_ACCESS_LOCAL_WRITE);
6693 if (!mem_mng->umem) {
6698 mkey_attr.addr = (uintptr_t)mem;
6699 mkey_attr.size = size;
6700 mkey_attr.umem_id = mlx5_os_get_umem_id(mem_mng->umem);
6701 mkey_attr.pd = sh->pdn;
6702 mkey_attr.log_entity_size = 0;
6703 mkey_attr.pg_access = 0;
6704 mkey_attr.klm_array = NULL;
6705 mkey_attr.klm_num = 0;
6706 mkey_attr.relaxed_ordering_write = sh->cmng.relaxed_ordering_write;
6707 mkey_attr.relaxed_ordering_read = sh->cmng.relaxed_ordering_read;
6708 mem_mng->dm = mlx5_devx_cmd_mkey_create(sh->ctx, &mkey_attr);
6710 mlx5_glue->devx_umem_dereg(mem_mng->umem);
6715 mem_mng->raws = (struct mlx5_counter_stats_raw *)(mem + size);
6716 raw_data = (volatile struct flow_counter_stats *)mem;
6717 for (i = 0; i < raws_n; ++i) {
6718 mem_mng->raws[i].mem_mng = mem_mng;
6719 mem_mng->raws[i].data = raw_data + i * MLX5_COUNTERS_PER_POOL;
6721 for (i = 0; i < MLX5_MAX_PENDING_QUERIES; ++i)
6722 LIST_INSERT_HEAD(&sh->cmng.free_stat_raws,
6723 mem_mng->raws + MLX5_CNT_CONTAINER_RESIZE + i,
6725 LIST_INSERT_HEAD(&sh->cmng.mem_mngs, mem_mng, next);
6726 sh->cmng.mem_mng = mem_mng;
6731 * Set the statistic memory to the new counter pool.
6734 * Pointer to mlx5_dev_ctx_shared object.
6736 * Pointer to the pool to set the statistic memory.
6739 * 0 on success, a negative errno value otherwise.
6742 mlx5_flow_set_counter_stat_mem(struct mlx5_dev_ctx_shared *sh,
6743 struct mlx5_flow_counter_pool *pool)
6745 struct mlx5_flow_counter_mng *cmng = &sh->cmng;
6746 /* Resize statistic memory once used out. */
6747 if (!(pool->index % MLX5_CNT_CONTAINER_RESIZE) &&
6748 mlx5_flow_create_counter_stat_mem_mng(sh)) {
6749 DRV_LOG(ERR, "Cannot resize counter stat mem.");
6752 rte_spinlock_lock(&pool->sl);
6753 pool->raw = cmng->mem_mng->raws + pool->index %
6754 MLX5_CNT_CONTAINER_RESIZE;
6755 rte_spinlock_unlock(&pool->sl);
6756 pool->raw_hw = NULL;
6760 #define MLX5_POOL_QUERY_FREQ_US 1000000
6763 * Set the periodic procedure for triggering asynchronous batch queries for all
6764 * the counter pools.
6767 * Pointer to mlx5_dev_ctx_shared object.
6770 mlx5_set_query_alarm(struct mlx5_dev_ctx_shared *sh)
6772 uint32_t pools_n, us;
6774 pools_n = __atomic_load_n(&sh->cmng.n_valid, __ATOMIC_RELAXED);
6775 us = MLX5_POOL_QUERY_FREQ_US / pools_n;
6776 DRV_LOG(DEBUG, "Set alarm for %u pools each %u us", pools_n, us);
6777 if (rte_eal_alarm_set(us, mlx5_flow_query_alarm, sh)) {
6778 sh->cmng.query_thread_on = 0;
6779 DRV_LOG(ERR, "Cannot reinitialize query alarm");
6781 sh->cmng.query_thread_on = 1;
6786 * The periodic procedure for triggering asynchronous batch queries for all the
6787 * counter pools. This function is probably called by the host thread.
6790 * The parameter for the alarm process.
6793 mlx5_flow_query_alarm(void *arg)
6795 struct mlx5_dev_ctx_shared *sh = arg;
6797 uint16_t pool_index = sh->cmng.pool_index;
6798 struct mlx5_flow_counter_mng *cmng = &sh->cmng;
6799 struct mlx5_flow_counter_pool *pool;
6802 if (sh->cmng.pending_queries >= MLX5_MAX_PENDING_QUERIES)
6804 rte_spinlock_lock(&cmng->pool_update_sl);
6805 pool = cmng->pools[pool_index];
6806 n_valid = cmng->n_valid;
6807 rte_spinlock_unlock(&cmng->pool_update_sl);
6808 /* Set the statistic memory to the new created pool. */
6809 if ((!pool->raw && mlx5_flow_set_counter_stat_mem(sh, pool)))
6812 /* There is a pool query in progress. */
6815 LIST_FIRST(&sh->cmng.free_stat_raws);
6817 /* No free counter statistics raw memory. */
6820 * Identify the counters released between query trigger and query
6821 * handle more efficiently. The counter released in this gap period
6822 * should wait for a new round of query as the new arrived packets
6823 * will not be taken into account.
6826 ret = mlx5_devx_cmd_flow_counter_query(pool->min_dcs, 0,
6827 MLX5_COUNTERS_PER_POOL,
6829 pool->raw_hw->mem_mng->dm->id,
6833 (uint64_t)(uintptr_t)pool);
6835 DRV_LOG(ERR, "Failed to trigger asynchronous query for dcs ID"
6836 " %d", pool->min_dcs->id);
6837 pool->raw_hw = NULL;
6840 LIST_REMOVE(pool->raw_hw, next);
6841 sh->cmng.pending_queries++;
6843 if (pool_index >= n_valid)
6846 sh->cmng.pool_index = pool_index;
6847 mlx5_set_query_alarm(sh);
6851 * Check and callback event for new aged flow in the counter pool
6854 * Pointer to mlx5_dev_ctx_shared object.
6856 * Pointer to Current counter pool.
6859 mlx5_flow_aging_check(struct mlx5_dev_ctx_shared *sh,
6860 struct mlx5_flow_counter_pool *pool)
6862 struct mlx5_priv *priv;
6863 struct mlx5_flow_counter *cnt;
6864 struct mlx5_age_info *age_info;
6865 struct mlx5_age_param *age_param;
6866 struct mlx5_counter_stats_raw *cur = pool->raw_hw;
6867 struct mlx5_counter_stats_raw *prev = pool->raw;
6868 const uint64_t curr_time = MLX5_CURR_TIME_SEC;
6869 const uint32_t time_delta = curr_time - pool->time_of_last_age_check;
6870 uint16_t expected = AGE_CANDIDATE;
6873 pool->time_of_last_age_check = curr_time;
6874 for (i = 0; i < MLX5_COUNTERS_PER_POOL; ++i) {
6875 cnt = MLX5_POOL_GET_CNT(pool, i);
6876 age_param = MLX5_CNT_TO_AGE(cnt);
6877 if (__atomic_load_n(&age_param->state,
6878 __ATOMIC_RELAXED) != AGE_CANDIDATE)
6880 if (cur->data[i].hits != prev->data[i].hits) {
6881 __atomic_store_n(&age_param->sec_since_last_hit, 0,
6885 if (__atomic_add_fetch(&age_param->sec_since_last_hit,
6887 __ATOMIC_RELAXED) <= age_param->timeout)
6890 * Hold the lock first, or if between the
6891 * state AGE_TMOUT and tailq operation the
6892 * release happened, the release procedure
6893 * may delete a non-existent tailq node.
6895 priv = rte_eth_devices[age_param->port_id].data->dev_private;
6896 age_info = GET_PORT_AGE_INFO(priv);
6897 rte_spinlock_lock(&age_info->aged_sl);
6898 if (__atomic_compare_exchange_n(&age_param->state, &expected,
6901 __ATOMIC_RELAXED)) {
6902 TAILQ_INSERT_TAIL(&age_info->aged_counters, cnt, next);
6903 MLX5_AGE_SET(age_info, MLX5_AGE_EVENT_NEW);
6905 rte_spinlock_unlock(&age_info->aged_sl);
6907 mlx5_age_event_prepare(sh);
6911 * Handler for the HW respond about ready values from an asynchronous batch
6912 * query. This function is probably called by the host thread.
6915 * The pointer to the shared device context.
6916 * @param[in] async_id
6917 * The Devx async ID.
6919 * The status of the completion.
6922 mlx5_flow_async_pool_query_handle(struct mlx5_dev_ctx_shared *sh,
6923 uint64_t async_id, int status)
6925 struct mlx5_flow_counter_pool *pool =
6926 (struct mlx5_flow_counter_pool *)(uintptr_t)async_id;
6927 struct mlx5_counter_stats_raw *raw_to_free;
6928 uint8_t query_gen = pool->query_gen ^ 1;
6929 struct mlx5_flow_counter_mng *cmng = &sh->cmng;
6930 enum mlx5_counter_type cnt_type =
6931 pool->is_aged ? MLX5_COUNTER_TYPE_AGE :
6932 MLX5_COUNTER_TYPE_ORIGIN;
6934 if (unlikely(status)) {
6935 raw_to_free = pool->raw_hw;
6937 raw_to_free = pool->raw;
6939 mlx5_flow_aging_check(sh, pool);
6940 rte_spinlock_lock(&pool->sl);
6941 pool->raw = pool->raw_hw;
6942 rte_spinlock_unlock(&pool->sl);
6943 /* Be sure the new raw counters data is updated in memory. */
6945 if (!TAILQ_EMPTY(&pool->counters[query_gen])) {
6946 rte_spinlock_lock(&cmng->csl[cnt_type]);
6947 TAILQ_CONCAT(&cmng->counters[cnt_type],
6948 &pool->counters[query_gen], next);
6949 rte_spinlock_unlock(&cmng->csl[cnt_type]);
6952 LIST_INSERT_HEAD(&sh->cmng.free_stat_raws, raw_to_free, next);
6953 pool->raw_hw = NULL;
6954 sh->cmng.pending_queries--;
6957 static const struct mlx5_flow_tbl_data_entry *
6958 tunnel_mark_decode(struct rte_eth_dev *dev, uint32_t mark)
6960 struct mlx5_priv *priv = dev->data->dev_private;
6961 struct mlx5_dev_ctx_shared *sh = priv->sh;
6962 struct mlx5_hlist_entry *he;
6963 union tunnel_offload_mark mbits = { .val = mark };
6964 union mlx5_flow_tbl_key table_key = {
6966 .table_id = tunnel_id_to_flow_tbl(mbits.table_id),
6968 .domain = !!mbits.transfer,
6972 he = mlx5_hlist_lookup(sh->flow_tbls, table_key.v64, NULL);
6974 container_of(he, struct mlx5_flow_tbl_data_entry, entry) : NULL;
6978 mlx5_flow_tunnel_grp2tbl_remove_cb(struct mlx5_hlist *list,
6979 struct mlx5_hlist_entry *entry)
6981 struct mlx5_dev_ctx_shared *sh = list->ctx;
6982 struct tunnel_tbl_entry *tte = container_of(entry, typeof(*tte), hash);
6984 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TNL_TBL_ID],
6985 tunnel_flow_tbl_to_id(tte->flow_table));
6989 static struct mlx5_hlist_entry *
6990 mlx5_flow_tunnel_grp2tbl_create_cb(struct mlx5_hlist *list,
6991 uint64_t key __rte_unused,
6992 void *ctx __rte_unused)
6994 struct mlx5_dev_ctx_shared *sh = list->ctx;
6995 struct tunnel_tbl_entry *tte;
6997 tte = mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO,
7002 mlx5_ipool_malloc(sh->ipool[MLX5_IPOOL_TNL_TBL_ID],
7004 if (tte->flow_table >= MLX5_MAX_TABLES) {
7005 DRV_LOG(ERR, "Tunnel TBL ID %d exceed max limit.",
7007 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TNL_TBL_ID],
7010 } else if (!tte->flow_table) {
7013 tte->flow_table = tunnel_id_to_flow_tbl(tte->flow_table);
7022 tunnel_flow_group_to_flow_table(struct rte_eth_dev *dev,
7023 const struct mlx5_flow_tunnel *tunnel,
7024 uint32_t group, uint32_t *table,
7025 struct rte_flow_error *error)
7027 struct mlx5_hlist_entry *he;
7028 struct tunnel_tbl_entry *tte;
7029 union tunnel_tbl_key key = {
7030 .tunnel_id = tunnel ? tunnel->tunnel_id : 0,
7033 struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
7034 struct mlx5_hlist *group_hash;
7036 group_hash = tunnel ? tunnel->groups : thub->groups;
7037 he = mlx5_hlist_register(group_hash, key.val, NULL);
7039 return rte_flow_error_set(error, EINVAL,
7040 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
7042 "tunnel group index not supported");
7043 tte = container_of(he, typeof(*tte), hash);
7044 *table = tte->flow_table;
7045 DRV_LOG(DEBUG, "port %u tunnel %u group=%#x table=%#x",
7046 dev->data->port_id, key.tunnel_id, group, *table);
7051 flow_group_to_table(uint32_t port_id, uint32_t group, uint32_t *table,
7052 struct flow_grp_info grp_info, struct rte_flow_error *error)
7054 if (grp_info.transfer && grp_info.external && grp_info.fdb_def_rule) {
7055 if (group == UINT32_MAX)
7056 return rte_flow_error_set
7058 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
7060 "group index not supported");
7065 DRV_LOG(DEBUG, "port %u group=%#x table=%#x", port_id, group, *table);
7070 * Translate the rte_flow group index to HW table value.
7072 * If tunnel offload is disabled, all group ids converted to flow table
7073 * id using the standard method.
7074 * If tunnel offload is enabled, group id can be converted using the
7075 * standard or tunnel conversion method. Group conversion method
7076 * selection depends on flags in `grp_info` parameter:
7077 * - Internal (grp_info.external == 0) groups conversion uses the
7079 * - Group ids in JUMP action converted with the tunnel conversion.
7080 * - Group id in rule attribute conversion depends on a rule type and
7082 * ** non zero group attributes converted with the tunnel method
7083 * ** zero group attribute in non-tunnel rule is converted using the
7084 * standard method - there's only one root table
7085 * ** zero group attribute in steer tunnel rule is converted with the
7086 * standard method - single root table
7087 * ** zero group attribute in match tunnel rule is a special OvS
7088 * case: that value is used for portability reasons. That group
7089 * id is converted with the tunnel conversion method.
7094 * PMD tunnel offload object
7096 * rte_flow group index value.
7099 * @param[in] grp_info
7100 * flags used for conversion
7102 * Pointer to error structure.
7105 * 0 on success, a negative errno value otherwise and rte_errno is set.
7108 mlx5_flow_group_to_table(struct rte_eth_dev *dev,
7109 const struct mlx5_flow_tunnel *tunnel,
7110 uint32_t group, uint32_t *table,
7111 struct flow_grp_info grp_info,
7112 struct rte_flow_error *error)
7115 bool standard_translation;
7117 if (!grp_info.skip_scale && grp_info.external &&
7118 group < MLX5_MAX_TABLES_EXTERNAL)
7119 group *= MLX5_FLOW_TABLE_FACTOR;
7120 if (is_tunnel_offload_active(dev)) {
7121 standard_translation = !grp_info.external ||
7122 grp_info.std_tbl_fix;
7124 standard_translation = true;
7127 "port %u group=%#x transfer=%d external=%d fdb_def_rule=%d translate=%s",
7128 dev->data->port_id, group, grp_info.transfer,
7129 grp_info.external, grp_info.fdb_def_rule,
7130 standard_translation ? "STANDARD" : "TUNNEL");
7131 if (standard_translation)
7132 ret = flow_group_to_table(dev->data->port_id, group, table,
7135 ret = tunnel_flow_group_to_flow_table(dev, tunnel, group,
7142 * Discover availability of metadata reg_c's.
7144 * Iteratively use test flows to check availability.
7147 * Pointer to the Ethernet device structure.
7150 * 0 on success, a negative errno value otherwise and rte_errno is set.
7153 mlx5_flow_discover_mreg_c(struct rte_eth_dev *dev)
7155 struct mlx5_priv *priv = dev->data->dev_private;
7156 struct mlx5_dev_config *config = &priv->config;
7157 enum modify_reg idx;
7160 /* reg_c[0] and reg_c[1] are reserved. */
7161 config->flow_mreg_c[n++] = REG_C_0;
7162 config->flow_mreg_c[n++] = REG_C_1;
7163 /* Discover availability of other reg_c's. */
7164 for (idx = REG_C_2; idx <= REG_C_7; ++idx) {
7165 struct rte_flow_attr attr = {
7166 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
7167 .priority = MLX5_FLOW_PRIO_RSVD,
7170 struct rte_flow_item items[] = {
7172 .type = RTE_FLOW_ITEM_TYPE_END,
7175 struct rte_flow_action actions[] = {
7177 .type = (enum rte_flow_action_type)
7178 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
7179 .conf = &(struct mlx5_flow_action_copy_mreg){
7185 .type = RTE_FLOW_ACTION_TYPE_JUMP,
7186 .conf = &(struct rte_flow_action_jump){
7187 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
7191 .type = RTE_FLOW_ACTION_TYPE_END,
7195 struct rte_flow *flow;
7196 struct rte_flow_error error;
7198 if (!config->dv_flow_en)
7200 /* Create internal flow, validation skips copy action. */
7201 flow_idx = flow_list_create(dev, NULL, &attr, items,
7202 actions, false, &error);
7203 flow = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW],
7207 config->flow_mreg_c[n++] = idx;
7208 flow_list_destroy(dev, NULL, flow_idx);
7210 for (; n < MLX5_MREG_C_NUM; ++n)
7211 config->flow_mreg_c[n] = REG_NON;
7216 * Dump flow raw hw data to file
7219 * The pointer to Ethernet device.
7221 * A pointer to a file for output.
7223 * Perform verbose error reporting if not NULL. PMDs initialize this
7224 * structure in case of error only.
7226 * 0 on success, a nagative value otherwise.
7229 mlx5_flow_dev_dump(struct rte_eth_dev *dev,
7231 struct rte_flow_error *error __rte_unused)
7233 struct mlx5_priv *priv = dev->data->dev_private;
7234 struct mlx5_dev_ctx_shared *sh = priv->sh;
7236 if (!priv->config.dv_flow_en) {
7237 if (fputs("device dv flow disabled\n", file) <= 0)
7241 return mlx5_devx_cmd_flow_dump(sh->fdb_domain, sh->rx_domain,
7242 sh->tx_domain, file);
7246 * Get aged-out flows.
7249 * Pointer to the Ethernet device structure.
7250 * @param[in] context
7251 * The address of an array of pointers to the aged-out flows contexts.
7252 * @param[in] nb_countexts
7253 * The length of context array pointers.
7255 * Perform verbose error reporting if not NULL. Initialized in case of
7259 * how many contexts get in success, otherwise negative errno value.
7260 * if nb_contexts is 0, return the amount of all aged contexts.
7261 * if nb_contexts is not 0 , return the amount of aged flows reported
7262 * in the context array.
7265 mlx5_flow_get_aged_flows(struct rte_eth_dev *dev, void **contexts,
7266 uint32_t nb_contexts, struct rte_flow_error *error)
7268 const struct mlx5_flow_driver_ops *fops;
7269 struct rte_flow_attr attr = { .transfer = 0 };
7271 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
7272 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7273 return fops->get_aged_flows(dev, contexts, nb_contexts,
7277 "port %u get aged flows is not supported.",
7278 dev->data->port_id);
7282 /* Wrapper for driver action_validate op callback */
7284 flow_drv_action_validate(struct rte_eth_dev *dev,
7285 const struct rte_flow_shared_action_conf *conf,
7286 const struct rte_flow_action *action,
7287 const struct mlx5_flow_driver_ops *fops,
7288 struct rte_flow_error *error)
7290 static const char err_msg[] = "shared action validation unsupported";
7292 if (!fops->action_validate) {
7293 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
7294 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
7298 return fops->action_validate(dev, conf, action, error);
7302 * Destroys the shared action by handle.
7305 * Pointer to Ethernet device structure.
7307 * Handle for the shared action to be destroyed.
7309 * Perform verbose error reporting if not NULL. PMDs initialize this
7310 * structure in case of error only.
7313 * 0 on success, a negative errno value otherwise and rte_errno is set.
7315 * @note: wrapper for driver action_create op callback.
7318 mlx5_shared_action_destroy(struct rte_eth_dev *dev,
7319 struct rte_flow_shared_action *action,
7320 struct rte_flow_error *error)
7322 static const char err_msg[] = "shared action destruction unsupported";
7323 struct rte_flow_attr attr = { .transfer = 0 };
7324 const struct mlx5_flow_driver_ops *fops =
7325 flow_get_drv_ops(flow_get_drv_type(dev, &attr));
7327 if (!fops->action_destroy) {
7328 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
7329 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
7333 return fops->action_destroy(dev, action, error);
7336 /* Wrapper for driver action_destroy op callback */
7338 flow_drv_action_update(struct rte_eth_dev *dev,
7339 struct rte_flow_shared_action *action,
7340 const void *action_conf,
7341 const struct mlx5_flow_driver_ops *fops,
7342 struct rte_flow_error *error)
7344 static const char err_msg[] = "shared action update unsupported";
7346 if (!fops->action_update) {
7347 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
7348 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
7352 return fops->action_update(dev, action, action_conf, error);
7355 /* Wrapper for driver action_destroy op callback */
7357 flow_drv_action_query(struct rte_eth_dev *dev,
7358 const struct rte_flow_shared_action *action,
7360 const struct mlx5_flow_driver_ops *fops,
7361 struct rte_flow_error *error)
7363 static const char err_msg[] = "shared action query unsupported";
7365 if (!fops->action_query) {
7366 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
7367 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
7371 return fops->action_query(dev, action, data, error);
7375 * Create shared action for reuse in multiple flow rules.
7378 * Pointer to Ethernet device structure.
7380 * Action configuration for shared action creation.
7382 * Perform verbose error reporting if not NULL. PMDs initialize this
7383 * structure in case of error only.
7385 * A valid handle in case of success, NULL otherwise and rte_errno is set.
7387 static struct rte_flow_shared_action *
7388 mlx5_shared_action_create(struct rte_eth_dev *dev,
7389 const struct rte_flow_shared_action_conf *conf,
7390 const struct rte_flow_action *action,
7391 struct rte_flow_error *error)
7393 static const char err_msg[] = "shared action creation unsupported";
7394 struct rte_flow_attr attr = { .transfer = 0 };
7395 const struct mlx5_flow_driver_ops *fops =
7396 flow_get_drv_ops(flow_get_drv_type(dev, &attr));
7398 if (flow_drv_action_validate(dev, conf, action, fops, error))
7400 if (!fops->action_create) {
7401 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
7402 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
7406 return fops->action_create(dev, conf, action, error);
7410 * Updates inplace the shared action configuration pointed by *action* handle
7411 * with the configuration provided as *action* argument.
7412 * The update of the shared action configuration effects all flow rules reusing
7413 * the action via handle.
7416 * Pointer to Ethernet device structure.
7417 * @param[in] shared_action
7418 * Handle for the shared action to be updated.
7420 * Action specification used to modify the action pointed by handle.
7421 * *action* should be of same type with the action pointed by the *action*
7422 * handle argument, otherwise considered as invalid.
7424 * Perform verbose error reporting if not NULL. PMDs initialize this
7425 * structure in case of error only.
7428 * 0 on success, a negative errno value otherwise and rte_errno is set.
7431 mlx5_shared_action_update(struct rte_eth_dev *dev,
7432 struct rte_flow_shared_action *shared_action,
7433 const struct rte_flow_action *action,
7434 struct rte_flow_error *error)
7436 struct rte_flow_attr attr = { .transfer = 0 };
7437 const struct mlx5_flow_driver_ops *fops =
7438 flow_get_drv_ops(flow_get_drv_type(dev, &attr));
7441 ret = flow_drv_action_validate(dev, NULL, action, fops, error);
7444 return flow_drv_action_update(dev, shared_action, action->conf, fops,
7449 * Query the shared action by handle.
7451 * This function allows retrieving action-specific data such as counters.
7452 * Data is gathered by special action which may be present/referenced in
7453 * more than one flow rule definition.
7455 * \see RTE_FLOW_ACTION_TYPE_COUNT
7458 * Pointer to Ethernet device structure.
7460 * Handle for the shared action to query.
7461 * @param[in, out] data
7462 * Pointer to storage for the associated query data type.
7464 * Perform verbose error reporting if not NULL. PMDs initialize this
7465 * structure in case of error only.
7468 * 0 on success, a negative errno value otherwise and rte_errno is set.
7471 mlx5_shared_action_query(struct rte_eth_dev *dev,
7472 const struct rte_flow_shared_action *action,
7474 struct rte_flow_error *error)
7476 struct rte_flow_attr attr = { .transfer = 0 };
7477 const struct mlx5_flow_driver_ops *fops =
7478 flow_get_drv_ops(flow_get_drv_type(dev, &attr));
7480 return flow_drv_action_query(dev, action, data, fops, error);
7484 * Destroy all shared actions.
7487 * Pointer to Ethernet device.
7490 * 0 on success, a negative errno value otherwise and rte_errno is set.
7493 mlx5_shared_action_flush(struct rte_eth_dev *dev)
7495 struct rte_flow_error error;
7496 struct mlx5_priv *priv = dev->data->dev_private;
7497 struct mlx5_shared_action_rss *action;
7501 ILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
7502 priv->rss_shared_actions, idx, action, next) {
7503 ret |= mlx5_shared_action_destroy(dev,
7504 (struct rte_flow_shared_action *)(uintptr_t)idx, &error);
7510 mlx5_flow_tunnel_free(struct rte_eth_dev *dev,
7511 struct mlx5_flow_tunnel *tunnel)
7513 struct mlx5_priv *priv = dev->data->dev_private;
7515 DRV_LOG(DEBUG, "port %u release pmd tunnel id=0x%x",
7516 dev->data->port_id, tunnel->tunnel_id);
7517 RTE_VERIFY(!__atomic_load_n(&tunnel->refctn, __ATOMIC_RELAXED));
7518 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_TUNNEL_ID],
7520 mlx5_hlist_destroy(tunnel->groups);
7524 static struct mlx5_flow_tunnel *
7525 mlx5_find_tunnel_id(struct rte_eth_dev *dev, uint32_t id)
7527 struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
7528 struct mlx5_flow_tunnel *tun;
7530 LIST_FOREACH(tun, &thub->tunnels, chain) {
7531 if (tun->tunnel_id == id)
7538 static struct mlx5_flow_tunnel *
7539 mlx5_flow_tunnel_allocate(struct rte_eth_dev *dev,
7540 const struct rte_flow_tunnel *app_tunnel)
7542 struct mlx5_priv *priv = dev->data->dev_private;
7543 struct mlx5_flow_tunnel *tunnel;
7546 mlx5_ipool_malloc(priv->sh->ipool[MLX5_IPOOL_RSS_EXPANTION_FLOW_ID],
7548 if (id >= MLX5_MAX_TUNNELS) {
7549 mlx5_ipool_free(priv->sh->ipool
7550 [MLX5_IPOOL_RSS_EXPANTION_FLOW_ID], id);
7551 DRV_LOG(ERR, "Tunnel ID %d exceed max limit.", id);
7557 * mlx5 flow tunnel is an auxlilary data structure
7558 * It's not part of IO. No need to allocate it from
7559 * huge pages pools dedicated for IO
7561 tunnel = mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO, sizeof(*tunnel),
7564 mlx5_ipool_free(priv->sh->ipool
7565 [MLX5_IPOOL_RSS_EXPANTION_FLOW_ID], id);
7568 tunnel->groups = mlx5_hlist_create("tunnel groups", 1024, 0, 0,
7569 mlx5_flow_tunnel_grp2tbl_create_cb,
7571 mlx5_flow_tunnel_grp2tbl_remove_cb);
7572 if (!tunnel->groups) {
7573 mlx5_ipool_free(priv->sh->ipool
7574 [MLX5_IPOOL_RSS_EXPANTION_FLOW_ID], id);
7578 tunnel->groups->ctx = priv->sh;
7579 /* initiate new PMD tunnel */
7580 memcpy(&tunnel->app_tunnel, app_tunnel, sizeof(*app_tunnel));
7581 tunnel->tunnel_id = id;
7582 tunnel->action.type = (typeof(tunnel->action.type))
7583 MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET;
7584 tunnel->action.conf = tunnel;
7585 tunnel->item.type = (typeof(tunnel->item.type))
7586 MLX5_RTE_FLOW_ITEM_TYPE_TUNNEL;
7587 tunnel->item.spec = tunnel;
7588 tunnel->item.last = NULL;
7589 tunnel->item.mask = NULL;
7591 DRV_LOG(DEBUG, "port %u new pmd tunnel id=0x%x",
7592 dev->data->port_id, tunnel->tunnel_id);
7598 mlx5_get_flow_tunnel(struct rte_eth_dev *dev,
7599 const struct rte_flow_tunnel *app_tunnel,
7600 struct mlx5_flow_tunnel **tunnel)
7603 struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
7604 struct mlx5_flow_tunnel *tun;
7606 rte_spinlock_lock(&thub->sl);
7607 LIST_FOREACH(tun, &thub->tunnels, chain) {
7608 if (!memcmp(app_tunnel, &tun->app_tunnel,
7609 sizeof(*app_tunnel))) {
7616 tun = mlx5_flow_tunnel_allocate(dev, app_tunnel);
7618 LIST_INSERT_HEAD(&thub->tunnels, tun, chain);
7624 rte_spinlock_unlock(&thub->sl);
7626 __atomic_add_fetch(&tun->refctn, 1, __ATOMIC_RELAXED);
7631 void mlx5_release_tunnel_hub(struct mlx5_dev_ctx_shared *sh, uint16_t port_id)
7633 struct mlx5_flow_tunnel_hub *thub = sh->tunnel_hub;
7637 if (!LIST_EMPTY(&thub->tunnels))
7638 DRV_LOG(WARNING, "port %u tunnels present\n", port_id);
7639 mlx5_hlist_destroy(thub->groups);
7643 int mlx5_alloc_tunnel_hub(struct mlx5_dev_ctx_shared *sh)
7646 struct mlx5_flow_tunnel_hub *thub;
7648 thub = mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO, sizeof(*thub),
7652 LIST_INIT(&thub->tunnels);
7653 rte_spinlock_init(&thub->sl);
7654 thub->groups = mlx5_hlist_create("flow groups", MLX5_MAX_TABLES, 0,
7655 0, mlx5_flow_tunnel_grp2tbl_create_cb,
7657 mlx5_flow_tunnel_grp2tbl_remove_cb);
7658 if (!thub->groups) {
7662 thub->groups->ctx = sh;
7663 sh->tunnel_hub = thub;
7669 mlx5_hlist_destroy(thub->groups);
7675 #ifndef HAVE_MLX5DV_DR
7676 #define MLX5_DOMAIN_SYNC_FLOW ((1 << 0) | (1 << 1))
7678 #define MLX5_DOMAIN_SYNC_FLOW \
7679 (MLX5DV_DR_DOMAIN_SYNC_FLAGS_SW | MLX5DV_DR_DOMAIN_SYNC_FLAGS_HW)
7682 int rte_pmd_mlx5_sync_flow(uint16_t port_id, uint32_t domains)
7684 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
7685 const struct mlx5_flow_driver_ops *fops;
7687 struct rte_flow_attr attr = { .transfer = 0 };
7689 fops = flow_get_drv_ops(flow_get_drv_type(dev, &attr));
7690 ret = fops->sync_domain(dev, domains, MLX5_DOMAIN_SYNC_FLOW);