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"
35 static struct mlx5_flow_tunnel *
36 mlx5_find_tunnel_id(struct rte_eth_dev *dev, uint32_t id);
38 mlx5_flow_tunnel_free(struct rte_eth_dev *dev, struct mlx5_flow_tunnel *tunnel);
39 static const struct mlx5_flow_tbl_data_entry *
40 tunnel_mark_decode(struct rte_eth_dev *dev, uint32_t mark);
42 mlx5_get_flow_tunnel(struct rte_eth_dev *dev,
43 const struct rte_flow_tunnel *app_tunnel,
44 struct mlx5_flow_tunnel **tunnel);
47 /** Device flow drivers. */
48 extern const struct mlx5_flow_driver_ops mlx5_flow_verbs_drv_ops;
50 const struct mlx5_flow_driver_ops mlx5_flow_null_drv_ops;
52 const struct mlx5_flow_driver_ops *flow_drv_ops[] = {
53 [MLX5_FLOW_TYPE_MIN] = &mlx5_flow_null_drv_ops,
54 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
55 [MLX5_FLOW_TYPE_DV] = &mlx5_flow_dv_drv_ops,
57 [MLX5_FLOW_TYPE_VERBS] = &mlx5_flow_verbs_drv_ops,
58 [MLX5_FLOW_TYPE_MAX] = &mlx5_flow_null_drv_ops
61 /** Helper macro to build input graph for mlx5_flow_expand_rss(). */
62 #define MLX5_FLOW_EXPAND_RSS_NEXT(...) \
67 /** Node object of input graph for mlx5_flow_expand_rss(). */
68 struct mlx5_flow_expand_node {
69 const int *const next;
71 * List of next node indexes. Index 0 is interpreted as a terminator.
73 const enum rte_flow_item_type type;
74 /**< Pattern item type of current node. */
77 * RSS types bit-field associated with this node
78 * (see ETH_RSS_* definitions).
82 /** Object returned by mlx5_flow_expand_rss(). */
83 struct mlx5_flow_expand_rss {
85 /**< Number of entries @p patterns and @p priorities. */
87 struct rte_flow_item *pattern; /**< Expanded pattern array. */
88 uint32_t priority; /**< Priority offset for each expansion. */
92 static enum rte_flow_item_type
93 mlx5_flow_expand_rss_item_complete(const struct rte_flow_item *item)
95 enum rte_flow_item_type ret = RTE_FLOW_ITEM_TYPE_VOID;
96 uint16_t ether_type = 0;
97 uint16_t ether_type_m;
98 uint8_t ip_next_proto = 0;
99 uint8_t ip_next_proto_m;
101 if (item == NULL || item->spec == NULL)
103 switch (item->type) {
104 case RTE_FLOW_ITEM_TYPE_ETH:
106 ether_type_m = ((const struct rte_flow_item_eth *)
109 ether_type_m = rte_flow_item_eth_mask.type;
110 if (ether_type_m != RTE_BE16(0xFFFF))
112 ether_type = ((const struct rte_flow_item_eth *)
114 if (rte_be_to_cpu_16(ether_type) == RTE_ETHER_TYPE_IPV4)
115 ret = RTE_FLOW_ITEM_TYPE_IPV4;
116 else if (rte_be_to_cpu_16(ether_type) == RTE_ETHER_TYPE_IPV6)
117 ret = RTE_FLOW_ITEM_TYPE_IPV6;
118 else if (rte_be_to_cpu_16(ether_type) == RTE_ETHER_TYPE_VLAN)
119 ret = RTE_FLOW_ITEM_TYPE_VLAN;
121 ret = RTE_FLOW_ITEM_TYPE_END;
123 case RTE_FLOW_ITEM_TYPE_VLAN:
125 ether_type_m = ((const struct rte_flow_item_vlan *)
126 (item->mask))->inner_type;
128 ether_type_m = rte_flow_item_vlan_mask.inner_type;
129 if (ether_type_m != RTE_BE16(0xFFFF))
131 ether_type = ((const struct rte_flow_item_vlan *)
132 (item->spec))->inner_type;
133 if (rte_be_to_cpu_16(ether_type) == RTE_ETHER_TYPE_IPV4)
134 ret = RTE_FLOW_ITEM_TYPE_IPV4;
135 else if (rte_be_to_cpu_16(ether_type) == RTE_ETHER_TYPE_IPV6)
136 ret = RTE_FLOW_ITEM_TYPE_IPV6;
137 else if (rte_be_to_cpu_16(ether_type) == RTE_ETHER_TYPE_VLAN)
138 ret = RTE_FLOW_ITEM_TYPE_VLAN;
140 ret = RTE_FLOW_ITEM_TYPE_END;
142 case RTE_FLOW_ITEM_TYPE_IPV4:
144 ip_next_proto_m = ((const struct rte_flow_item_ipv4 *)
145 (item->mask))->hdr.next_proto_id;
148 rte_flow_item_ipv4_mask.hdr.next_proto_id;
149 if (ip_next_proto_m != 0xFF)
151 ip_next_proto = ((const struct rte_flow_item_ipv4 *)
152 (item->spec))->hdr.next_proto_id;
153 if (ip_next_proto == IPPROTO_UDP)
154 ret = RTE_FLOW_ITEM_TYPE_UDP;
155 else if (ip_next_proto == IPPROTO_TCP)
156 ret = RTE_FLOW_ITEM_TYPE_TCP;
157 else if (ip_next_proto == IPPROTO_IP)
158 ret = RTE_FLOW_ITEM_TYPE_IPV4;
159 else if (ip_next_proto == IPPROTO_IPV6)
160 ret = RTE_FLOW_ITEM_TYPE_IPV6;
162 ret = RTE_FLOW_ITEM_TYPE_END;
164 case RTE_FLOW_ITEM_TYPE_IPV6:
166 ip_next_proto_m = ((const struct rte_flow_item_ipv6 *)
167 (item->mask))->hdr.proto;
170 rte_flow_item_ipv6_mask.hdr.proto;
171 if (ip_next_proto_m != 0xFF)
173 ip_next_proto = ((const struct rte_flow_item_ipv6 *)
174 (item->spec))->hdr.proto;
175 if (ip_next_proto == IPPROTO_UDP)
176 ret = RTE_FLOW_ITEM_TYPE_UDP;
177 else if (ip_next_proto == IPPROTO_TCP)
178 ret = RTE_FLOW_ITEM_TYPE_TCP;
179 else if (ip_next_proto == IPPROTO_IP)
180 ret = RTE_FLOW_ITEM_TYPE_IPV4;
181 else if (ip_next_proto == IPPROTO_IPV6)
182 ret = RTE_FLOW_ITEM_TYPE_IPV6;
184 ret = RTE_FLOW_ITEM_TYPE_END;
187 ret = RTE_FLOW_ITEM_TYPE_VOID;
194 * Expand RSS flows into several possible flows according to the RSS hash
195 * fields requested and the driver capabilities.
198 * Buffer to store the result expansion.
200 * Buffer size in bytes. If 0, @p buf can be NULL.
204 * RSS types to expand (see ETH_RSS_* definitions).
206 * Input graph to expand @p pattern according to @p types.
207 * @param[in] graph_root_index
208 * Index of root node in @p graph, typically 0.
211 * A positive value representing the size of @p buf in bytes regardless of
212 * @p size on success, a negative errno value otherwise and rte_errno is
213 * set, the following errors are defined:
215 * -E2BIG: graph-depth @p graph is too deep.
218 mlx5_flow_expand_rss(struct mlx5_flow_expand_rss *buf, size_t size,
219 const struct rte_flow_item *pattern, uint64_t types,
220 const struct mlx5_flow_expand_node graph[],
221 int graph_root_index)
224 const struct rte_flow_item *item;
225 const struct mlx5_flow_expand_node *node = &graph[graph_root_index];
226 const int *next_node;
227 const int *stack[elt_n];
229 struct rte_flow_item flow_items[elt_n];
232 size_t user_pattern_size = 0;
234 const struct mlx5_flow_expand_node *next = NULL;
235 struct rte_flow_item missed_item;
238 const struct rte_flow_item *last_item = NULL;
240 memset(&missed_item, 0, sizeof(missed_item));
241 lsize = offsetof(struct mlx5_flow_expand_rss, entry) +
242 elt_n * sizeof(buf->entry[0]);
244 buf->entry[0].priority = 0;
245 buf->entry[0].pattern = (void *)&buf->entry[elt_n];
247 addr = buf->entry[0].pattern;
249 for (item = pattern; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
250 if (item->type != RTE_FLOW_ITEM_TYPE_VOID)
252 for (i = 0; node->next && node->next[i]; ++i) {
253 next = &graph[node->next[i]];
254 if (next->type == item->type)
259 user_pattern_size += sizeof(*item);
261 user_pattern_size += sizeof(*item); /* Handle END item. */
262 lsize += user_pattern_size;
263 /* Copy the user pattern in the first entry of the buffer. */
265 rte_memcpy(addr, pattern, user_pattern_size);
266 addr = (void *)(((uintptr_t)addr) + user_pattern_size);
269 /* Start expanding. */
270 memset(flow_items, 0, sizeof(flow_items));
271 user_pattern_size -= sizeof(*item);
273 * Check if the last valid item has spec set, need complete pattern,
274 * and the pattern can be used for expansion.
276 missed_item.type = mlx5_flow_expand_rss_item_complete(last_item);
277 if (missed_item.type == RTE_FLOW_ITEM_TYPE_END) {
278 /* Item type END indicates expansion is not required. */
281 if (missed_item.type != RTE_FLOW_ITEM_TYPE_VOID) {
284 for (i = 0; node->next && node->next[i]; ++i) {
285 next = &graph[node->next[i]];
286 if (next->type == missed_item.type) {
287 flow_items[0].type = missed_item.type;
288 flow_items[1].type = RTE_FLOW_ITEM_TYPE_END;
294 if (next && missed) {
295 elt = 2; /* missed item + item end. */
297 lsize += elt * sizeof(*item) + user_pattern_size;
298 if ((node->rss_types & types) && lsize <= size) {
299 buf->entry[buf->entries].priority = 1;
300 buf->entry[buf->entries].pattern = addr;
302 rte_memcpy(addr, buf->entry[0].pattern,
304 addr = (void *)(((uintptr_t)addr) + user_pattern_size);
305 rte_memcpy(addr, flow_items, elt * sizeof(*item));
306 addr = (void *)(((uintptr_t)addr) +
307 elt * sizeof(*item));
310 memset(flow_items, 0, sizeof(flow_items));
311 next_node = node->next;
312 stack[stack_pos] = next_node;
313 node = next_node ? &graph[*next_node] : NULL;
315 flow_items[stack_pos].type = node->type;
316 if (node->rss_types & types) {
318 * compute the number of items to copy from the
319 * expansion and copy it.
320 * When the stack_pos is 0, there are 1 element in it,
321 * plus the addition END item.
324 flow_items[stack_pos + 1].type = RTE_FLOW_ITEM_TYPE_END;
325 lsize += elt * sizeof(*item) + user_pattern_size;
327 size_t n = elt * sizeof(*item);
329 buf->entry[buf->entries].priority =
330 stack_pos + 1 + missed;
331 buf->entry[buf->entries].pattern = addr;
333 rte_memcpy(addr, buf->entry[0].pattern,
335 addr = (void *)(((uintptr_t)addr) +
337 rte_memcpy(addr, &missed_item,
338 missed * sizeof(*item));
339 addr = (void *)(((uintptr_t)addr) +
340 missed * sizeof(*item));
341 rte_memcpy(addr, flow_items, n);
342 addr = (void *)(((uintptr_t)addr) + n);
347 next_node = node->next;
348 if (stack_pos++ == elt_n) {
352 stack[stack_pos] = next_node;
353 } else if (*(next_node + 1)) {
354 /* Follow up with the next possibility. */
357 /* Move to the next path. */
359 next_node = stack[--stack_pos];
361 stack[stack_pos] = next_node;
363 node = *next_node ? &graph[*next_node] : NULL;
365 /* no expanded flows but we have missed item, create one rule for it */
366 if (buf->entries == 1 && missed != 0) {
368 lsize += elt * sizeof(*item) + user_pattern_size;
370 buf->entry[buf->entries].priority = 1;
371 buf->entry[buf->entries].pattern = addr;
373 flow_items[0].type = missed_item.type;
374 flow_items[1].type = RTE_FLOW_ITEM_TYPE_END;
375 rte_memcpy(addr, buf->entry[0].pattern,
377 addr = (void *)(((uintptr_t)addr) + user_pattern_size);
378 rte_memcpy(addr, flow_items, elt * sizeof(*item));
379 addr = (void *)(((uintptr_t)addr) +
380 elt * sizeof(*item));
386 enum mlx5_expansion {
388 MLX5_EXPANSION_ROOT_OUTER,
389 MLX5_EXPANSION_ROOT_ETH_VLAN,
390 MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN,
391 MLX5_EXPANSION_OUTER_ETH,
392 MLX5_EXPANSION_OUTER_ETH_VLAN,
393 MLX5_EXPANSION_OUTER_VLAN,
394 MLX5_EXPANSION_OUTER_IPV4,
395 MLX5_EXPANSION_OUTER_IPV4_UDP,
396 MLX5_EXPANSION_OUTER_IPV4_TCP,
397 MLX5_EXPANSION_OUTER_IPV6,
398 MLX5_EXPANSION_OUTER_IPV6_UDP,
399 MLX5_EXPANSION_OUTER_IPV6_TCP,
400 MLX5_EXPANSION_VXLAN,
401 MLX5_EXPANSION_VXLAN_GPE,
405 MLX5_EXPANSION_ETH_VLAN,
408 MLX5_EXPANSION_IPV4_UDP,
409 MLX5_EXPANSION_IPV4_TCP,
411 MLX5_EXPANSION_IPV6_UDP,
412 MLX5_EXPANSION_IPV6_TCP,
415 /** Supported expansion of items. */
416 static const struct mlx5_flow_expand_node mlx5_support_expansion[] = {
417 [MLX5_EXPANSION_ROOT] = {
418 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
420 MLX5_EXPANSION_IPV6),
421 .type = RTE_FLOW_ITEM_TYPE_END,
423 [MLX5_EXPANSION_ROOT_OUTER] = {
424 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_ETH,
425 MLX5_EXPANSION_OUTER_IPV4,
426 MLX5_EXPANSION_OUTER_IPV6),
427 .type = RTE_FLOW_ITEM_TYPE_END,
429 [MLX5_EXPANSION_ROOT_ETH_VLAN] = {
430 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH_VLAN),
431 .type = RTE_FLOW_ITEM_TYPE_END,
433 [MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN] = {
434 .next = MLX5_FLOW_EXPAND_RSS_NEXT
435 (MLX5_EXPANSION_OUTER_ETH_VLAN),
436 .type = RTE_FLOW_ITEM_TYPE_END,
438 [MLX5_EXPANSION_OUTER_ETH] = {
439 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_IPV4,
440 MLX5_EXPANSION_OUTER_IPV6,
441 MLX5_EXPANSION_MPLS),
442 .type = RTE_FLOW_ITEM_TYPE_ETH,
445 [MLX5_EXPANSION_OUTER_ETH_VLAN] = {
446 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_VLAN),
447 .type = RTE_FLOW_ITEM_TYPE_ETH,
450 [MLX5_EXPANSION_OUTER_VLAN] = {
451 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_IPV4,
452 MLX5_EXPANSION_OUTER_IPV6),
453 .type = RTE_FLOW_ITEM_TYPE_VLAN,
455 [MLX5_EXPANSION_OUTER_IPV4] = {
456 .next = MLX5_FLOW_EXPAND_RSS_NEXT
457 (MLX5_EXPANSION_OUTER_IPV4_UDP,
458 MLX5_EXPANSION_OUTER_IPV4_TCP,
461 MLX5_EXPANSION_IPV6),
462 .type = RTE_FLOW_ITEM_TYPE_IPV4,
463 .rss_types = ETH_RSS_IPV4 | ETH_RSS_FRAG_IPV4 |
464 ETH_RSS_NONFRAG_IPV4_OTHER,
466 [MLX5_EXPANSION_OUTER_IPV4_UDP] = {
467 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VXLAN,
468 MLX5_EXPANSION_VXLAN_GPE),
469 .type = RTE_FLOW_ITEM_TYPE_UDP,
470 .rss_types = ETH_RSS_NONFRAG_IPV4_UDP,
472 [MLX5_EXPANSION_OUTER_IPV4_TCP] = {
473 .type = RTE_FLOW_ITEM_TYPE_TCP,
474 .rss_types = ETH_RSS_NONFRAG_IPV4_TCP,
476 [MLX5_EXPANSION_OUTER_IPV6] = {
477 .next = MLX5_FLOW_EXPAND_RSS_NEXT
478 (MLX5_EXPANSION_OUTER_IPV6_UDP,
479 MLX5_EXPANSION_OUTER_IPV6_TCP,
481 MLX5_EXPANSION_IPV6),
482 .type = RTE_FLOW_ITEM_TYPE_IPV6,
483 .rss_types = ETH_RSS_IPV6 | ETH_RSS_FRAG_IPV6 |
484 ETH_RSS_NONFRAG_IPV6_OTHER,
486 [MLX5_EXPANSION_OUTER_IPV6_UDP] = {
487 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VXLAN,
488 MLX5_EXPANSION_VXLAN_GPE),
489 .type = RTE_FLOW_ITEM_TYPE_UDP,
490 .rss_types = ETH_RSS_NONFRAG_IPV6_UDP,
492 [MLX5_EXPANSION_OUTER_IPV6_TCP] = {
493 .type = RTE_FLOW_ITEM_TYPE_TCP,
494 .rss_types = ETH_RSS_NONFRAG_IPV6_TCP,
496 [MLX5_EXPANSION_VXLAN] = {
497 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
499 MLX5_EXPANSION_IPV6),
500 .type = RTE_FLOW_ITEM_TYPE_VXLAN,
502 [MLX5_EXPANSION_VXLAN_GPE] = {
503 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
505 MLX5_EXPANSION_IPV6),
506 .type = RTE_FLOW_ITEM_TYPE_VXLAN_GPE,
508 [MLX5_EXPANSION_GRE] = {
509 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4),
510 .type = RTE_FLOW_ITEM_TYPE_GRE,
512 [MLX5_EXPANSION_MPLS] = {
513 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
514 MLX5_EXPANSION_IPV6),
515 .type = RTE_FLOW_ITEM_TYPE_MPLS,
517 [MLX5_EXPANSION_ETH] = {
518 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
519 MLX5_EXPANSION_IPV6),
520 .type = RTE_FLOW_ITEM_TYPE_ETH,
522 [MLX5_EXPANSION_ETH_VLAN] = {
523 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VLAN),
524 .type = RTE_FLOW_ITEM_TYPE_ETH,
526 [MLX5_EXPANSION_VLAN] = {
527 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
528 MLX5_EXPANSION_IPV6),
529 .type = RTE_FLOW_ITEM_TYPE_VLAN,
531 [MLX5_EXPANSION_IPV4] = {
532 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4_UDP,
533 MLX5_EXPANSION_IPV4_TCP),
534 .type = RTE_FLOW_ITEM_TYPE_IPV4,
535 .rss_types = ETH_RSS_IPV4 | ETH_RSS_FRAG_IPV4 |
536 ETH_RSS_NONFRAG_IPV4_OTHER,
538 [MLX5_EXPANSION_IPV4_UDP] = {
539 .type = RTE_FLOW_ITEM_TYPE_UDP,
540 .rss_types = ETH_RSS_NONFRAG_IPV4_UDP,
542 [MLX5_EXPANSION_IPV4_TCP] = {
543 .type = RTE_FLOW_ITEM_TYPE_TCP,
544 .rss_types = ETH_RSS_NONFRAG_IPV4_TCP,
546 [MLX5_EXPANSION_IPV6] = {
547 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV6_UDP,
548 MLX5_EXPANSION_IPV6_TCP),
549 .type = RTE_FLOW_ITEM_TYPE_IPV6,
550 .rss_types = ETH_RSS_IPV6 | ETH_RSS_FRAG_IPV6 |
551 ETH_RSS_NONFRAG_IPV6_OTHER,
553 [MLX5_EXPANSION_IPV6_UDP] = {
554 .type = RTE_FLOW_ITEM_TYPE_UDP,
555 .rss_types = ETH_RSS_NONFRAG_IPV6_UDP,
557 [MLX5_EXPANSION_IPV6_TCP] = {
558 .type = RTE_FLOW_ITEM_TYPE_TCP,
559 .rss_types = ETH_RSS_NONFRAG_IPV6_TCP,
563 static struct rte_flow_shared_action *
564 mlx5_shared_action_create(struct rte_eth_dev *dev,
565 const struct rte_flow_shared_action_conf *conf,
566 const struct rte_flow_action *action,
567 struct rte_flow_error *error);
568 static int mlx5_shared_action_destroy
569 (struct rte_eth_dev *dev,
570 struct rte_flow_shared_action *shared_action,
571 struct rte_flow_error *error);
572 static int mlx5_shared_action_update
573 (struct rte_eth_dev *dev,
574 struct rte_flow_shared_action *shared_action,
575 const struct rte_flow_action *action,
576 struct rte_flow_error *error);
577 static int mlx5_shared_action_query
578 (struct rte_eth_dev *dev,
579 const struct rte_flow_shared_action *action,
581 struct rte_flow_error *error);
583 mlx5_flow_tunnel_validate(struct rte_eth_dev *dev,
584 struct rte_flow_tunnel *tunnel,
588 if (!is_tunnel_offload_active(dev)) {
589 err_msg = "tunnel offload was not activated";
591 } else if (!tunnel) {
592 err_msg = "no application tunnel";
596 switch (tunnel->type) {
598 err_msg = "unsupported tunnel type";
600 case RTE_FLOW_ITEM_TYPE_VXLAN:
610 mlx5_flow_tunnel_decap_set(struct rte_eth_dev *dev,
611 struct rte_flow_tunnel *app_tunnel,
612 struct rte_flow_action **actions,
613 uint32_t *num_of_actions,
614 struct rte_flow_error *error)
617 struct mlx5_flow_tunnel *tunnel;
618 const char *err_msg = NULL;
619 bool verdict = mlx5_flow_tunnel_validate(dev, app_tunnel, err_msg);
622 return rte_flow_error_set(error, EINVAL,
623 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
625 ret = mlx5_get_flow_tunnel(dev, app_tunnel, &tunnel);
627 return rte_flow_error_set(error, ret,
628 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
629 "failed to initialize pmd tunnel");
631 *actions = &tunnel->action;
637 mlx5_flow_tunnel_match(struct rte_eth_dev *dev,
638 struct rte_flow_tunnel *app_tunnel,
639 struct rte_flow_item **items,
640 uint32_t *num_of_items,
641 struct rte_flow_error *error)
644 struct mlx5_flow_tunnel *tunnel;
645 const char *err_msg = NULL;
646 bool verdict = mlx5_flow_tunnel_validate(dev, app_tunnel, err_msg);
649 return rte_flow_error_set(error, EINVAL,
650 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
652 ret = mlx5_get_flow_tunnel(dev, app_tunnel, &tunnel);
654 return rte_flow_error_set(error, ret,
655 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
656 "failed to initialize pmd tunnel");
658 *items = &tunnel->item;
664 mlx5_flow_item_release(struct rte_eth_dev *dev,
665 struct rte_flow_item *pmd_items,
666 uint32_t num_items, struct rte_flow_error *err)
668 struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
669 struct mlx5_flow_tunnel *tun;
671 LIST_FOREACH(tun, &thub->tunnels, chain) {
672 if (&tun->item == pmd_items)
675 if (!tun || num_items != 1)
676 return rte_flow_error_set(err, EINVAL,
677 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
679 if (!__atomic_sub_fetch(&tun->refctn, 1, __ATOMIC_RELAXED))
680 mlx5_flow_tunnel_free(dev, tun);
685 mlx5_flow_action_release(struct rte_eth_dev *dev,
686 struct rte_flow_action *pmd_actions,
687 uint32_t num_actions, struct rte_flow_error *err)
689 struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
690 struct mlx5_flow_tunnel *tun;
692 LIST_FOREACH(tun, &thub->tunnels, chain) {
693 if (&tun->action == pmd_actions)
696 if (!tun || num_actions != 1)
697 return rte_flow_error_set(err, EINVAL,
698 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
700 if (!__atomic_sub_fetch(&tun->refctn, 1, __ATOMIC_RELAXED))
701 mlx5_flow_tunnel_free(dev, tun);
707 mlx5_flow_tunnel_get_restore_info(struct rte_eth_dev *dev,
709 struct rte_flow_restore_info *info,
710 struct rte_flow_error *err)
712 uint64_t ol_flags = m->ol_flags;
713 const struct mlx5_flow_tbl_data_entry *tble;
714 const uint64_t mask = PKT_RX_FDIR | PKT_RX_FDIR_ID;
716 if ((ol_flags & mask) != mask)
718 tble = tunnel_mark_decode(dev, m->hash.fdir.hi);
720 DRV_LOG(DEBUG, "port %u invalid miss tunnel mark %#x",
721 dev->data->port_id, m->hash.fdir.hi);
724 MLX5_ASSERT(tble->tunnel);
725 memcpy(&info->tunnel, &tble->tunnel->app_tunnel, sizeof(info->tunnel));
726 info->group_id = tble->group_id;
727 info->flags = RTE_FLOW_RESTORE_INFO_TUNNEL |
728 RTE_FLOW_RESTORE_INFO_GROUP_ID |
729 RTE_FLOW_RESTORE_INFO_ENCAPSULATED;
734 return rte_flow_error_set(err, EINVAL,
735 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
736 "failed to get restore info");
739 static const struct rte_flow_ops mlx5_flow_ops = {
740 .validate = mlx5_flow_validate,
741 .create = mlx5_flow_create,
742 .destroy = mlx5_flow_destroy,
743 .flush = mlx5_flow_flush,
744 .isolate = mlx5_flow_isolate,
745 .query = mlx5_flow_query,
746 .dev_dump = mlx5_flow_dev_dump,
747 .get_aged_flows = mlx5_flow_get_aged_flows,
748 .shared_action_create = mlx5_shared_action_create,
749 .shared_action_destroy = mlx5_shared_action_destroy,
750 .shared_action_update = mlx5_shared_action_update,
751 .shared_action_query = mlx5_shared_action_query,
752 .tunnel_decap_set = mlx5_flow_tunnel_decap_set,
753 .tunnel_match = mlx5_flow_tunnel_match,
754 .tunnel_action_decap_release = mlx5_flow_action_release,
755 .tunnel_item_release = mlx5_flow_item_release,
756 .get_restore_info = mlx5_flow_tunnel_get_restore_info,
759 /* Convert FDIR request to Generic flow. */
761 struct rte_flow_attr attr;
762 struct rte_flow_item items[4];
763 struct rte_flow_item_eth l2;
764 struct rte_flow_item_eth l2_mask;
766 struct rte_flow_item_ipv4 ipv4;
767 struct rte_flow_item_ipv6 ipv6;
770 struct rte_flow_item_ipv4 ipv4;
771 struct rte_flow_item_ipv6 ipv6;
774 struct rte_flow_item_udp udp;
775 struct rte_flow_item_tcp tcp;
778 struct rte_flow_item_udp udp;
779 struct rte_flow_item_tcp tcp;
781 struct rte_flow_action actions[2];
782 struct rte_flow_action_queue queue;
785 /* Tunnel information. */
786 struct mlx5_flow_tunnel_info {
787 uint64_t tunnel; /**< Tunnel bit (see MLX5_FLOW_*). */
788 uint32_t ptype; /**< Tunnel Ptype (see RTE_PTYPE_*). */
791 static struct mlx5_flow_tunnel_info tunnels_info[] = {
793 .tunnel = MLX5_FLOW_LAYER_VXLAN,
794 .ptype = RTE_PTYPE_TUNNEL_VXLAN | RTE_PTYPE_L4_UDP,
797 .tunnel = MLX5_FLOW_LAYER_GENEVE,
798 .ptype = RTE_PTYPE_TUNNEL_GENEVE | RTE_PTYPE_L4_UDP,
801 .tunnel = MLX5_FLOW_LAYER_VXLAN_GPE,
802 .ptype = RTE_PTYPE_TUNNEL_VXLAN_GPE | RTE_PTYPE_L4_UDP,
805 .tunnel = MLX5_FLOW_LAYER_GRE,
806 .ptype = RTE_PTYPE_TUNNEL_GRE,
809 .tunnel = MLX5_FLOW_LAYER_MPLS | MLX5_FLOW_LAYER_OUTER_L4_UDP,
810 .ptype = RTE_PTYPE_TUNNEL_MPLS_IN_UDP | RTE_PTYPE_L4_UDP,
813 .tunnel = MLX5_FLOW_LAYER_MPLS,
814 .ptype = RTE_PTYPE_TUNNEL_MPLS_IN_GRE,
817 .tunnel = MLX5_FLOW_LAYER_NVGRE,
818 .ptype = RTE_PTYPE_TUNNEL_NVGRE,
821 .tunnel = MLX5_FLOW_LAYER_IPIP,
822 .ptype = RTE_PTYPE_TUNNEL_IP,
825 .tunnel = MLX5_FLOW_LAYER_IPV6_ENCAP,
826 .ptype = RTE_PTYPE_TUNNEL_IP,
829 .tunnel = MLX5_FLOW_LAYER_GTP,
830 .ptype = RTE_PTYPE_TUNNEL_GTPU,
835 * Translate tag ID to register.
838 * Pointer to the Ethernet device structure.
840 * The feature that request the register.
842 * The request register ID.
844 * Error description in case of any.
847 * The request register on success, a negative errno
848 * value otherwise and rte_errno is set.
851 mlx5_flow_get_reg_id(struct rte_eth_dev *dev,
852 enum mlx5_feature_name feature,
854 struct rte_flow_error *error)
856 struct mlx5_priv *priv = dev->data->dev_private;
857 struct mlx5_dev_config *config = &priv->config;
858 enum modify_reg start_reg;
859 bool skip_mtr_reg = false;
862 case MLX5_HAIRPIN_RX:
864 case MLX5_HAIRPIN_TX:
866 case MLX5_METADATA_RX:
867 switch (config->dv_xmeta_en) {
868 case MLX5_XMETA_MODE_LEGACY:
870 case MLX5_XMETA_MODE_META16:
872 case MLX5_XMETA_MODE_META32:
876 case MLX5_METADATA_TX:
878 case MLX5_METADATA_FDB:
879 switch (config->dv_xmeta_en) {
880 case MLX5_XMETA_MODE_LEGACY:
882 case MLX5_XMETA_MODE_META16:
884 case MLX5_XMETA_MODE_META32:
889 switch (config->dv_xmeta_en) {
890 case MLX5_XMETA_MODE_LEGACY:
892 case MLX5_XMETA_MODE_META16:
894 case MLX5_XMETA_MODE_META32:
900 * If meter color and flow match share one register, flow match
901 * should use the meter color register for match.
903 if (priv->mtr_reg_share)
904 return priv->mtr_color_reg;
906 return priv->mtr_color_reg != REG_C_2 ? REG_C_2 :
909 MLX5_ASSERT(priv->mtr_color_reg != REG_NON);
910 return priv->mtr_color_reg;
913 * Metadata COPY_MARK register using is in meter suffix sub
914 * flow while with meter. It's safe to share the same register.
916 return priv->mtr_color_reg != REG_C_2 ? REG_C_2 : REG_C_3;
919 * If meter is enable, it will engage the register for color
920 * match and flow match. If meter color match is not using the
921 * REG_C_2, need to skip the REG_C_x be used by meter color
923 * If meter is disable, free to use all available registers.
925 start_reg = priv->mtr_color_reg != REG_C_2 ? REG_C_2 :
926 (priv->mtr_reg_share ? REG_C_3 : REG_C_4);
927 skip_mtr_reg = !!(priv->mtr_en && start_reg == REG_C_2);
928 if (id > (REG_C_7 - start_reg))
929 return rte_flow_error_set(error, EINVAL,
930 RTE_FLOW_ERROR_TYPE_ITEM,
931 NULL, "invalid tag id");
932 if (config->flow_mreg_c[id + start_reg - REG_C_0] == REG_NON)
933 return rte_flow_error_set(error, ENOTSUP,
934 RTE_FLOW_ERROR_TYPE_ITEM,
935 NULL, "unsupported tag id");
937 * This case means meter is using the REG_C_x great than 2.
938 * Take care not to conflict with meter color REG_C_x.
939 * If the available index REG_C_y >= REG_C_x, skip the
942 if (skip_mtr_reg && config->flow_mreg_c
943 [id + start_reg - REG_C_0] >= priv->mtr_color_reg) {
944 if (id >= (REG_C_7 - start_reg))
945 return rte_flow_error_set(error, EINVAL,
946 RTE_FLOW_ERROR_TYPE_ITEM,
947 NULL, "invalid tag id");
948 if (config->flow_mreg_c
949 [id + 1 + start_reg - REG_C_0] != REG_NON)
950 return config->flow_mreg_c
951 [id + 1 + start_reg - REG_C_0];
952 return rte_flow_error_set(error, ENOTSUP,
953 RTE_FLOW_ERROR_TYPE_ITEM,
954 NULL, "unsupported tag id");
956 return config->flow_mreg_c[id + start_reg - REG_C_0];
959 return rte_flow_error_set(error, EINVAL,
960 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
961 NULL, "invalid feature name");
965 * Check extensive flow metadata register support.
968 * Pointer to rte_eth_dev structure.
971 * True if device supports extensive flow metadata register, otherwise false.
974 mlx5_flow_ext_mreg_supported(struct rte_eth_dev *dev)
976 struct mlx5_priv *priv = dev->data->dev_private;
977 struct mlx5_dev_config *config = &priv->config;
980 * Having available reg_c can be regarded inclusively as supporting
981 * extensive flow metadata register, which could mean,
982 * - metadata register copy action by modify header.
983 * - 16 modify header actions is supported.
984 * - reg_c's are preserved across different domain (FDB and NIC) on
985 * packet loopback by flow lookup miss.
987 return config->flow_mreg_c[2] != REG_NON;
991 * Verify the @p item specifications (spec, last, mask) are compatible with the
995 * Item specification.
997 * @p item->mask or flow default bit-masks.
998 * @param[in] nic_mask
999 * Bit-masks covering supported fields by the NIC to compare with user mask.
1001 * Bit-masks size in bytes.
1002 * @param[in] range_accepted
1003 * True if range of values is accepted for specific fields, false otherwise.
1005 * Pointer to error structure.
1008 * 0 on success, a negative errno value otherwise and rte_errno is set.
1011 mlx5_flow_item_acceptable(const struct rte_flow_item *item,
1012 const uint8_t *mask,
1013 const uint8_t *nic_mask,
1015 bool range_accepted,
1016 struct rte_flow_error *error)
1020 MLX5_ASSERT(nic_mask);
1021 for (i = 0; i < size; ++i)
1022 if ((nic_mask[i] | mask[i]) != nic_mask[i])
1023 return rte_flow_error_set(error, ENOTSUP,
1024 RTE_FLOW_ERROR_TYPE_ITEM,
1026 "mask enables non supported"
1028 if (!item->spec && (item->mask || item->last))
1029 return rte_flow_error_set(error, EINVAL,
1030 RTE_FLOW_ERROR_TYPE_ITEM, item,
1031 "mask/last without a spec is not"
1033 if (item->spec && item->last && !range_accepted) {
1039 for (i = 0; i < size; ++i) {
1040 spec[i] = ((const uint8_t *)item->spec)[i] & mask[i];
1041 last[i] = ((const uint8_t *)item->last)[i] & mask[i];
1043 ret = memcmp(spec, last, size);
1045 return rte_flow_error_set(error, EINVAL,
1046 RTE_FLOW_ERROR_TYPE_ITEM,
1048 "range is not valid");
1054 * Adjust the hash fields according to the @p flow information.
1056 * @param[in] dev_flow.
1057 * Pointer to the mlx5_flow.
1059 * 1 when the hash field is for a tunnel item.
1060 * @param[in] layer_types
1062 * @param[in] hash_fields
1066 * The hash fields that should be used.
1069 mlx5_flow_hashfields_adjust(struct mlx5_flow_rss_desc *rss_desc,
1070 int tunnel __rte_unused, uint64_t layer_types,
1071 uint64_t hash_fields)
1073 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
1074 int rss_request_inner = rss_desc->level >= 2;
1076 /* Check RSS hash level for tunnel. */
1077 if (tunnel && rss_request_inner)
1078 hash_fields |= IBV_RX_HASH_INNER;
1079 else if (tunnel || rss_request_inner)
1082 /* Check if requested layer matches RSS hash fields. */
1083 if (!(rss_desc->types & layer_types))
1089 * Lookup and set the ptype in the data Rx part. A single Ptype can be used,
1090 * if several tunnel rules are used on this queue, the tunnel ptype will be
1094 * Rx queue to update.
1097 flow_rxq_tunnel_ptype_update(struct mlx5_rxq_ctrl *rxq_ctrl)
1100 uint32_t tunnel_ptype = 0;
1102 /* Look up for the ptype to use. */
1103 for (i = 0; i != MLX5_FLOW_TUNNEL; ++i) {
1104 if (!rxq_ctrl->flow_tunnels_n[i])
1106 if (!tunnel_ptype) {
1107 tunnel_ptype = tunnels_info[i].ptype;
1113 rxq_ctrl->rxq.tunnel = tunnel_ptype;
1117 * Set the Rx queue flags (Mark/Flag and Tunnel Ptypes) according to the devive
1121 * Pointer to the Ethernet device structure.
1122 * @param[in] dev_handle
1123 * Pointer to device flow handle structure.
1126 flow_drv_rxq_flags_set(struct rte_eth_dev *dev,
1127 struct mlx5_flow_handle *dev_handle)
1129 struct mlx5_priv *priv = dev->data->dev_private;
1130 const int mark = dev_handle->mark;
1131 const int tunnel = !!(dev_handle->layers & MLX5_FLOW_LAYER_TUNNEL);
1132 struct mlx5_hrxq *hrxq;
1135 if (dev_handle->fate_action != MLX5_FLOW_FATE_QUEUE)
1137 hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
1138 dev_handle->rix_hrxq);
1141 for (i = 0; i != hrxq->ind_table->queues_n; ++i) {
1142 int idx = hrxq->ind_table->queues[i];
1143 struct mlx5_rxq_ctrl *rxq_ctrl =
1144 container_of((*priv->rxqs)[idx],
1145 struct mlx5_rxq_ctrl, rxq);
1148 * To support metadata register copy on Tx loopback,
1149 * this must be always enabled (metadata may arive
1150 * from other port - not from local flows only.
1152 if (priv->config.dv_flow_en &&
1153 priv->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
1154 mlx5_flow_ext_mreg_supported(dev)) {
1155 rxq_ctrl->rxq.mark = 1;
1156 rxq_ctrl->flow_mark_n = 1;
1158 rxq_ctrl->rxq.mark = 1;
1159 rxq_ctrl->flow_mark_n++;
1164 /* Increase the counter matching the flow. */
1165 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j) {
1166 if ((tunnels_info[j].tunnel &
1167 dev_handle->layers) ==
1168 tunnels_info[j].tunnel) {
1169 rxq_ctrl->flow_tunnels_n[j]++;
1173 flow_rxq_tunnel_ptype_update(rxq_ctrl);
1179 * Set the Rx queue flags (Mark/Flag and Tunnel Ptypes) for a flow
1182 * Pointer to the Ethernet device structure.
1184 * Pointer to flow structure.
1187 flow_rxq_flags_set(struct rte_eth_dev *dev, struct rte_flow *flow)
1189 struct mlx5_priv *priv = dev->data->dev_private;
1190 uint32_t handle_idx;
1191 struct mlx5_flow_handle *dev_handle;
1193 SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
1194 handle_idx, dev_handle, next)
1195 flow_drv_rxq_flags_set(dev, dev_handle);
1199 * Clear the Rx queue flags (Mark/Flag and Tunnel Ptype) associated with the
1200 * device flow if no other flow uses it with the same kind of request.
1203 * Pointer to Ethernet device.
1204 * @param[in] dev_handle
1205 * Pointer to the device flow handle structure.
1208 flow_drv_rxq_flags_trim(struct rte_eth_dev *dev,
1209 struct mlx5_flow_handle *dev_handle)
1211 struct mlx5_priv *priv = dev->data->dev_private;
1212 const int mark = dev_handle->mark;
1213 const int tunnel = !!(dev_handle->layers & MLX5_FLOW_LAYER_TUNNEL);
1214 struct mlx5_hrxq *hrxq;
1217 if (dev_handle->fate_action != MLX5_FLOW_FATE_QUEUE)
1219 hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
1220 dev_handle->rix_hrxq);
1223 MLX5_ASSERT(dev->data->dev_started);
1224 for (i = 0; i != hrxq->ind_table->queues_n; ++i) {
1225 int idx = hrxq->ind_table->queues[i];
1226 struct mlx5_rxq_ctrl *rxq_ctrl =
1227 container_of((*priv->rxqs)[idx],
1228 struct mlx5_rxq_ctrl, rxq);
1230 if (priv->config.dv_flow_en &&
1231 priv->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
1232 mlx5_flow_ext_mreg_supported(dev)) {
1233 rxq_ctrl->rxq.mark = 1;
1234 rxq_ctrl->flow_mark_n = 1;
1236 rxq_ctrl->flow_mark_n--;
1237 rxq_ctrl->rxq.mark = !!rxq_ctrl->flow_mark_n;
1242 /* Decrease the counter matching the flow. */
1243 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j) {
1244 if ((tunnels_info[j].tunnel &
1245 dev_handle->layers) ==
1246 tunnels_info[j].tunnel) {
1247 rxq_ctrl->flow_tunnels_n[j]--;
1251 flow_rxq_tunnel_ptype_update(rxq_ctrl);
1257 * Clear the Rx queue flags (Mark/Flag and Tunnel Ptype) associated with the
1258 * @p flow if no other flow uses it with the same kind of request.
1261 * Pointer to Ethernet device.
1263 * Pointer to the flow.
1266 flow_rxq_flags_trim(struct rte_eth_dev *dev, struct rte_flow *flow)
1268 struct mlx5_priv *priv = dev->data->dev_private;
1269 uint32_t handle_idx;
1270 struct mlx5_flow_handle *dev_handle;
1272 SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
1273 handle_idx, dev_handle, next)
1274 flow_drv_rxq_flags_trim(dev, dev_handle);
1278 * Clear the Mark/Flag and Tunnel ptype information in all Rx queues.
1281 * Pointer to Ethernet device.
1284 flow_rxq_flags_clear(struct rte_eth_dev *dev)
1286 struct mlx5_priv *priv = dev->data->dev_private;
1289 for (i = 0; i != priv->rxqs_n; ++i) {
1290 struct mlx5_rxq_ctrl *rxq_ctrl;
1293 if (!(*priv->rxqs)[i])
1295 rxq_ctrl = container_of((*priv->rxqs)[i],
1296 struct mlx5_rxq_ctrl, rxq);
1297 rxq_ctrl->flow_mark_n = 0;
1298 rxq_ctrl->rxq.mark = 0;
1299 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j)
1300 rxq_ctrl->flow_tunnels_n[j] = 0;
1301 rxq_ctrl->rxq.tunnel = 0;
1306 * Set the Rx queue dynamic metadata (mask and offset) for a flow
1309 * Pointer to the Ethernet device structure.
1312 mlx5_flow_rxq_dynf_metadata_set(struct rte_eth_dev *dev)
1314 struct mlx5_priv *priv = dev->data->dev_private;
1315 struct mlx5_rxq_data *data;
1318 for (i = 0; i != priv->rxqs_n; ++i) {
1319 if (!(*priv->rxqs)[i])
1321 data = (*priv->rxqs)[i];
1322 if (!rte_flow_dynf_metadata_avail()) {
1323 data->dynf_meta = 0;
1324 data->flow_meta_mask = 0;
1325 data->flow_meta_offset = -1;
1327 data->dynf_meta = 1;
1328 data->flow_meta_mask = rte_flow_dynf_metadata_mask;
1329 data->flow_meta_offset = rte_flow_dynf_metadata_offs;
1335 * return a pointer to the desired action in the list of actions.
1337 * @param[in] actions
1338 * The list of actions to search the action in.
1340 * The action to find.
1343 * Pointer to the action in the list, if found. NULL otherwise.
1345 const struct rte_flow_action *
1346 mlx5_flow_find_action(const struct rte_flow_action *actions,
1347 enum rte_flow_action_type action)
1349 if (actions == NULL)
1351 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++)
1352 if (actions->type == action)
1358 * Validate the flag action.
1360 * @param[in] action_flags
1361 * Bit-fields that holds the actions detected until now.
1363 * Attributes of flow that includes this action.
1365 * Pointer to error structure.
1368 * 0 on success, a negative errno value otherwise and rte_errno is set.
1371 mlx5_flow_validate_action_flag(uint64_t action_flags,
1372 const struct rte_flow_attr *attr,
1373 struct rte_flow_error *error)
1375 if (action_flags & MLX5_FLOW_ACTION_MARK)
1376 return rte_flow_error_set(error, EINVAL,
1377 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1378 "can't mark and flag in same flow");
1379 if (action_flags & MLX5_FLOW_ACTION_FLAG)
1380 return rte_flow_error_set(error, EINVAL,
1381 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1383 " actions in same flow");
1385 return rte_flow_error_set(error, ENOTSUP,
1386 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1387 "flag action not supported for "
1393 * Validate the mark action.
1396 * Pointer to the queue action.
1397 * @param[in] action_flags
1398 * Bit-fields that holds the actions detected until now.
1400 * Attributes of flow that includes this action.
1402 * Pointer to error structure.
1405 * 0 on success, a negative errno value otherwise and rte_errno is set.
1408 mlx5_flow_validate_action_mark(const struct rte_flow_action *action,
1409 uint64_t action_flags,
1410 const struct rte_flow_attr *attr,
1411 struct rte_flow_error *error)
1413 const struct rte_flow_action_mark *mark = action->conf;
1416 return rte_flow_error_set(error, EINVAL,
1417 RTE_FLOW_ERROR_TYPE_ACTION,
1419 "configuration cannot be null");
1420 if (mark->id >= MLX5_FLOW_MARK_MAX)
1421 return rte_flow_error_set(error, EINVAL,
1422 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1424 "mark id must in 0 <= id < "
1425 RTE_STR(MLX5_FLOW_MARK_MAX));
1426 if (action_flags & MLX5_FLOW_ACTION_FLAG)
1427 return rte_flow_error_set(error, EINVAL,
1428 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1429 "can't flag and mark in same flow");
1430 if (action_flags & MLX5_FLOW_ACTION_MARK)
1431 return rte_flow_error_set(error, EINVAL,
1432 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1433 "can't have 2 mark actions in same"
1436 return rte_flow_error_set(error, ENOTSUP,
1437 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1438 "mark action not supported for "
1444 * Validate the drop action.
1446 * @param[in] action_flags
1447 * Bit-fields that holds the actions detected until now.
1449 * Attributes of flow that includes this action.
1451 * Pointer to error structure.
1454 * 0 on success, a negative errno value otherwise and rte_errno is set.
1457 mlx5_flow_validate_action_drop(uint64_t action_flags __rte_unused,
1458 const struct rte_flow_attr *attr,
1459 struct rte_flow_error *error)
1462 return rte_flow_error_set(error, ENOTSUP,
1463 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1464 "drop action not supported for "
1470 * Validate the queue action.
1473 * Pointer to the queue action.
1474 * @param[in] action_flags
1475 * Bit-fields that holds the actions detected until now.
1477 * Pointer to the Ethernet device structure.
1479 * Attributes of flow that includes this action.
1481 * Pointer to error structure.
1484 * 0 on success, a negative errno value otherwise and rte_errno is set.
1487 mlx5_flow_validate_action_queue(const struct rte_flow_action *action,
1488 uint64_t action_flags,
1489 struct rte_eth_dev *dev,
1490 const struct rte_flow_attr *attr,
1491 struct rte_flow_error *error)
1493 struct mlx5_priv *priv = dev->data->dev_private;
1494 const struct rte_flow_action_queue *queue = action->conf;
1496 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
1497 return rte_flow_error_set(error, EINVAL,
1498 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1499 "can't have 2 fate actions in"
1502 return rte_flow_error_set(error, EINVAL,
1503 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1504 NULL, "No Rx queues configured");
1505 if (queue->index >= priv->rxqs_n)
1506 return rte_flow_error_set(error, EINVAL,
1507 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1509 "queue index out of range");
1510 if (!(*priv->rxqs)[queue->index])
1511 return rte_flow_error_set(error, EINVAL,
1512 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1514 "queue is not configured");
1516 return rte_flow_error_set(error, ENOTSUP,
1517 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1518 "queue action not supported for "
1524 * Validate the rss action.
1527 * Pointer to the Ethernet device structure.
1529 * Pointer to the queue action.
1531 * Pointer to error structure.
1534 * 0 on success, a negative errno value otherwise and rte_errno is set.
1537 mlx5_validate_action_rss(struct rte_eth_dev *dev,
1538 const struct rte_flow_action *action,
1539 struct rte_flow_error *error)
1541 struct mlx5_priv *priv = dev->data->dev_private;
1542 const struct rte_flow_action_rss *rss = action->conf;
1545 if (rss->func != RTE_ETH_HASH_FUNCTION_DEFAULT &&
1546 rss->func != RTE_ETH_HASH_FUNCTION_TOEPLITZ)
1547 return rte_flow_error_set(error, ENOTSUP,
1548 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1550 "RSS hash function not supported");
1551 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
1556 return rte_flow_error_set(error, ENOTSUP,
1557 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1559 "tunnel RSS is not supported");
1560 /* allow RSS key_len 0 in case of NULL (default) RSS key. */
1561 if (rss->key_len == 0 && rss->key != NULL)
1562 return rte_flow_error_set(error, ENOTSUP,
1563 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1565 "RSS hash key length 0");
1566 if (rss->key_len > 0 && rss->key_len < MLX5_RSS_HASH_KEY_LEN)
1567 return rte_flow_error_set(error, ENOTSUP,
1568 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1570 "RSS hash key too small");
1571 if (rss->key_len > MLX5_RSS_HASH_KEY_LEN)
1572 return rte_flow_error_set(error, ENOTSUP,
1573 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1575 "RSS hash key too large");
1576 if (rss->queue_num > priv->config.ind_table_max_size)
1577 return rte_flow_error_set(error, ENOTSUP,
1578 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1580 "number of queues too large");
1581 if (rss->types & MLX5_RSS_HF_MASK)
1582 return rte_flow_error_set(error, ENOTSUP,
1583 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1585 "some RSS protocols are not"
1587 if ((rss->types & (ETH_RSS_L3_SRC_ONLY | ETH_RSS_L3_DST_ONLY)) &&
1588 !(rss->types & ETH_RSS_IP))
1589 return rte_flow_error_set(error, EINVAL,
1590 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1591 "L3 partial RSS requested but L3 RSS"
1592 " type not specified");
1593 if ((rss->types & (ETH_RSS_L4_SRC_ONLY | ETH_RSS_L4_DST_ONLY)) &&
1594 !(rss->types & (ETH_RSS_UDP | ETH_RSS_TCP)))
1595 return rte_flow_error_set(error, EINVAL,
1596 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1597 "L4 partial RSS requested but L4 RSS"
1598 " type not specified");
1600 return rte_flow_error_set(error, EINVAL,
1601 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1602 NULL, "No Rx queues configured");
1603 if (!rss->queue_num)
1604 return rte_flow_error_set(error, EINVAL,
1605 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1606 NULL, "No queues configured");
1607 for (i = 0; i != rss->queue_num; ++i) {
1608 if (rss->queue[i] >= priv->rxqs_n)
1609 return rte_flow_error_set
1611 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1612 &rss->queue[i], "queue index out of range");
1613 if (!(*priv->rxqs)[rss->queue[i]])
1614 return rte_flow_error_set
1615 (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1616 &rss->queue[i], "queue is not configured");
1622 * Validate the rss action.
1625 * Pointer to the queue action.
1626 * @param[in] action_flags
1627 * Bit-fields that holds the actions detected until now.
1629 * Pointer to the Ethernet device structure.
1631 * Attributes of flow that includes this action.
1632 * @param[in] item_flags
1633 * Items that were detected.
1635 * Pointer to error structure.
1638 * 0 on success, a negative errno value otherwise and rte_errno is set.
1641 mlx5_flow_validate_action_rss(const struct rte_flow_action *action,
1642 uint64_t action_flags,
1643 struct rte_eth_dev *dev,
1644 const struct rte_flow_attr *attr,
1645 uint64_t item_flags,
1646 struct rte_flow_error *error)
1648 const struct rte_flow_action_rss *rss = action->conf;
1649 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1652 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
1653 return rte_flow_error_set(error, EINVAL,
1654 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1655 "can't have 2 fate actions"
1657 ret = mlx5_validate_action_rss(dev, action, error);
1661 return rte_flow_error_set(error, ENOTSUP,
1662 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1663 "rss action not supported for "
1665 if (rss->level > 1 && !tunnel)
1666 return rte_flow_error_set(error, EINVAL,
1667 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1668 "inner RSS is not supported for "
1669 "non-tunnel flows");
1670 if ((item_flags & MLX5_FLOW_LAYER_ECPRI) &&
1671 !(item_flags & MLX5_FLOW_LAYER_INNER_L4_UDP)) {
1672 return rte_flow_error_set(error, EINVAL,
1673 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1674 "RSS on eCPRI is not supported now");
1680 * Validate the default miss action.
1682 * @param[in] action_flags
1683 * Bit-fields that holds the actions detected until now.
1685 * Pointer to error structure.
1688 * 0 on success, a negative errno value otherwise and rte_errno is set.
1691 mlx5_flow_validate_action_default_miss(uint64_t action_flags,
1692 const struct rte_flow_attr *attr,
1693 struct rte_flow_error *error)
1695 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
1696 return rte_flow_error_set(error, EINVAL,
1697 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1698 "can't have 2 fate actions in"
1701 return rte_flow_error_set(error, ENOTSUP,
1702 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1703 "default miss action not supported "
1706 return rte_flow_error_set(error, ENOTSUP,
1707 RTE_FLOW_ERROR_TYPE_ATTR_GROUP, NULL,
1708 "only group 0 is supported");
1710 return rte_flow_error_set(error, ENOTSUP,
1711 RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
1712 NULL, "transfer is not supported");
1717 * Validate the count action.
1720 * Pointer to the Ethernet device structure.
1722 * Attributes of flow that includes this action.
1724 * Pointer to error structure.
1727 * 0 on success, a negative errno value otherwise and rte_errno is set.
1730 mlx5_flow_validate_action_count(struct rte_eth_dev *dev __rte_unused,
1731 const struct rte_flow_attr *attr,
1732 struct rte_flow_error *error)
1735 return rte_flow_error_set(error, ENOTSUP,
1736 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1737 "count action not supported for "
1743 * Verify the @p attributes will be correctly understood by the NIC and store
1744 * them in the @p flow if everything is correct.
1747 * Pointer to the Ethernet device structure.
1748 * @param[in] attributes
1749 * Pointer to flow attributes
1751 * Pointer to error structure.
1754 * 0 on success, a negative errno value otherwise and rte_errno is set.
1757 mlx5_flow_validate_attributes(struct rte_eth_dev *dev,
1758 const struct rte_flow_attr *attributes,
1759 struct rte_flow_error *error)
1761 struct mlx5_priv *priv = dev->data->dev_private;
1762 uint32_t priority_max = priv->config.flow_prio - 1;
1764 if (attributes->group)
1765 return rte_flow_error_set(error, ENOTSUP,
1766 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
1767 NULL, "groups is not supported");
1768 if (attributes->priority != MLX5_FLOW_PRIO_RSVD &&
1769 attributes->priority >= priority_max)
1770 return rte_flow_error_set(error, ENOTSUP,
1771 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
1772 NULL, "priority out of range");
1773 if (attributes->egress)
1774 return rte_flow_error_set(error, ENOTSUP,
1775 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1776 "egress is not supported");
1777 if (attributes->transfer && !priv->config.dv_esw_en)
1778 return rte_flow_error_set(error, ENOTSUP,
1779 RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
1780 NULL, "transfer is not supported");
1781 if (!attributes->ingress)
1782 return rte_flow_error_set(error, EINVAL,
1783 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
1785 "ingress attribute is mandatory");
1790 * Validate ICMP6 item.
1793 * Item specification.
1794 * @param[in] item_flags
1795 * Bit-fields that holds the items detected until now.
1797 * Pointer to error structure.
1800 * 0 on success, a negative errno value otherwise and rte_errno is set.
1803 mlx5_flow_validate_item_icmp6(const struct rte_flow_item *item,
1804 uint64_t item_flags,
1805 uint8_t target_protocol,
1806 struct rte_flow_error *error)
1808 const struct rte_flow_item_icmp6 *mask = item->mask;
1809 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1810 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
1811 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
1812 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1813 MLX5_FLOW_LAYER_OUTER_L4;
1816 if (target_protocol != 0xFF && target_protocol != IPPROTO_ICMPV6)
1817 return rte_flow_error_set(error, EINVAL,
1818 RTE_FLOW_ERROR_TYPE_ITEM, item,
1819 "protocol filtering not compatible"
1820 " with ICMP6 layer");
1821 if (!(item_flags & l3m))
1822 return rte_flow_error_set(error, EINVAL,
1823 RTE_FLOW_ERROR_TYPE_ITEM, item,
1824 "IPv6 is mandatory to filter on"
1826 if (item_flags & l4m)
1827 return rte_flow_error_set(error, EINVAL,
1828 RTE_FLOW_ERROR_TYPE_ITEM, item,
1829 "multiple L4 layers not supported");
1831 mask = &rte_flow_item_icmp6_mask;
1832 ret = mlx5_flow_item_acceptable
1833 (item, (const uint8_t *)mask,
1834 (const uint8_t *)&rte_flow_item_icmp6_mask,
1835 sizeof(struct rte_flow_item_icmp6),
1836 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
1843 * Validate ICMP item.
1846 * Item specification.
1847 * @param[in] item_flags
1848 * Bit-fields that holds the items detected until now.
1850 * Pointer to error structure.
1853 * 0 on success, a negative errno value otherwise and rte_errno is set.
1856 mlx5_flow_validate_item_icmp(const struct rte_flow_item *item,
1857 uint64_t item_flags,
1858 uint8_t target_protocol,
1859 struct rte_flow_error *error)
1861 const struct rte_flow_item_icmp *mask = item->mask;
1862 const struct rte_flow_item_icmp nic_mask = {
1863 .hdr.icmp_type = 0xff,
1864 .hdr.icmp_code = 0xff,
1865 .hdr.icmp_ident = RTE_BE16(0xffff),
1866 .hdr.icmp_seq_nb = RTE_BE16(0xffff),
1868 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1869 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
1870 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
1871 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1872 MLX5_FLOW_LAYER_OUTER_L4;
1875 if (target_protocol != 0xFF && target_protocol != IPPROTO_ICMP)
1876 return rte_flow_error_set(error, EINVAL,
1877 RTE_FLOW_ERROR_TYPE_ITEM, item,
1878 "protocol filtering not compatible"
1879 " with ICMP layer");
1880 if (!(item_flags & l3m))
1881 return rte_flow_error_set(error, EINVAL,
1882 RTE_FLOW_ERROR_TYPE_ITEM, item,
1883 "IPv4 is mandatory to filter"
1885 if (item_flags & l4m)
1886 return rte_flow_error_set(error, EINVAL,
1887 RTE_FLOW_ERROR_TYPE_ITEM, item,
1888 "multiple L4 layers not supported");
1891 ret = mlx5_flow_item_acceptable
1892 (item, (const uint8_t *)mask,
1893 (const uint8_t *)&nic_mask,
1894 sizeof(struct rte_flow_item_icmp),
1895 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
1902 * Validate Ethernet item.
1905 * Item specification.
1906 * @param[in] item_flags
1907 * Bit-fields that holds the items detected until now.
1909 * Pointer to error structure.
1912 * 0 on success, a negative errno value otherwise and rte_errno is set.
1915 mlx5_flow_validate_item_eth(const struct rte_flow_item *item,
1916 uint64_t item_flags,
1917 struct rte_flow_error *error)
1919 const struct rte_flow_item_eth *mask = item->mask;
1920 const struct rte_flow_item_eth nic_mask = {
1921 .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
1922 .src.addr_bytes = "\xff\xff\xff\xff\xff\xff",
1923 .type = RTE_BE16(0xffff),
1926 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1927 const uint64_t ethm = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
1928 MLX5_FLOW_LAYER_OUTER_L2;
1930 if (item_flags & ethm)
1931 return rte_flow_error_set(error, ENOTSUP,
1932 RTE_FLOW_ERROR_TYPE_ITEM, item,
1933 "multiple L2 layers not supported");
1934 if ((!tunnel && (item_flags & MLX5_FLOW_LAYER_OUTER_L3)) ||
1935 (tunnel && (item_flags & MLX5_FLOW_LAYER_INNER_L3)))
1936 return rte_flow_error_set(error, EINVAL,
1937 RTE_FLOW_ERROR_TYPE_ITEM, item,
1938 "L2 layer should not follow "
1940 if ((!tunnel && (item_flags & MLX5_FLOW_LAYER_OUTER_VLAN)) ||
1941 (tunnel && (item_flags & MLX5_FLOW_LAYER_INNER_VLAN)))
1942 return rte_flow_error_set(error, EINVAL,
1943 RTE_FLOW_ERROR_TYPE_ITEM, item,
1944 "L2 layer should not follow VLAN");
1946 mask = &rte_flow_item_eth_mask;
1947 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1948 (const uint8_t *)&nic_mask,
1949 sizeof(struct rte_flow_item_eth),
1950 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
1955 * Validate VLAN item.
1958 * Item specification.
1959 * @param[in] item_flags
1960 * Bit-fields that holds the items detected until now.
1962 * Ethernet device flow is being created on.
1964 * Pointer to error structure.
1967 * 0 on success, a negative errno value otherwise and rte_errno is set.
1970 mlx5_flow_validate_item_vlan(const struct rte_flow_item *item,
1971 uint64_t item_flags,
1972 struct rte_eth_dev *dev,
1973 struct rte_flow_error *error)
1975 const struct rte_flow_item_vlan *spec = item->spec;
1976 const struct rte_flow_item_vlan *mask = item->mask;
1977 const struct rte_flow_item_vlan nic_mask = {
1978 .tci = RTE_BE16(UINT16_MAX),
1979 .inner_type = RTE_BE16(UINT16_MAX),
1981 uint16_t vlan_tag = 0;
1982 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1984 const uint64_t l34m = tunnel ? (MLX5_FLOW_LAYER_INNER_L3 |
1985 MLX5_FLOW_LAYER_INNER_L4) :
1986 (MLX5_FLOW_LAYER_OUTER_L3 |
1987 MLX5_FLOW_LAYER_OUTER_L4);
1988 const uint64_t vlanm = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
1989 MLX5_FLOW_LAYER_OUTER_VLAN;
1991 if (item_flags & vlanm)
1992 return rte_flow_error_set(error, EINVAL,
1993 RTE_FLOW_ERROR_TYPE_ITEM, item,
1994 "multiple VLAN layers not supported");
1995 else if ((item_flags & l34m) != 0)
1996 return rte_flow_error_set(error, EINVAL,
1997 RTE_FLOW_ERROR_TYPE_ITEM, item,
1998 "VLAN cannot follow L3/L4 layer");
2000 mask = &rte_flow_item_vlan_mask;
2001 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2002 (const uint8_t *)&nic_mask,
2003 sizeof(struct rte_flow_item_vlan),
2004 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2007 if (!tunnel && mask->tci != RTE_BE16(0x0fff)) {
2008 struct mlx5_priv *priv = dev->data->dev_private;
2010 if (priv->vmwa_context) {
2012 * Non-NULL context means we have a virtual machine
2013 * and SR-IOV enabled, we have to create VLAN interface
2014 * to make hypervisor to setup E-Switch vport
2015 * context correctly. We avoid creating the multiple
2016 * VLAN interfaces, so we cannot support VLAN tag mask.
2018 return rte_flow_error_set(error, EINVAL,
2019 RTE_FLOW_ERROR_TYPE_ITEM,
2021 "VLAN tag mask is not"
2022 " supported in virtual"
2027 vlan_tag = spec->tci;
2028 vlan_tag &= mask->tci;
2031 * From verbs perspective an empty VLAN is equivalent
2032 * to a packet without VLAN layer.
2035 return rte_flow_error_set(error, EINVAL,
2036 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
2038 "VLAN cannot be empty");
2043 * Validate IPV4 item.
2046 * Item specification.
2047 * @param[in] item_flags
2048 * Bit-fields that holds the items detected until now.
2049 * @param[in] last_item
2050 * Previous validated item in the pattern items.
2051 * @param[in] ether_type
2052 * Type in the ethernet layer header (including dot1q).
2053 * @param[in] acc_mask
2054 * Acceptable mask, if NULL default internal default mask
2055 * will be used to check whether item fields are supported.
2056 * @param[in] range_accepted
2057 * True if range of values is accepted for specific fields, false otherwise.
2059 * Pointer to error structure.
2062 * 0 on success, a negative errno value otherwise and rte_errno is set.
2065 mlx5_flow_validate_item_ipv4(const struct rte_flow_item *item,
2066 uint64_t item_flags,
2068 uint16_t ether_type,
2069 const struct rte_flow_item_ipv4 *acc_mask,
2070 bool range_accepted,
2071 struct rte_flow_error *error)
2073 const struct rte_flow_item_ipv4 *mask = item->mask;
2074 const struct rte_flow_item_ipv4 *spec = item->spec;
2075 const struct rte_flow_item_ipv4 nic_mask = {
2077 .src_addr = RTE_BE32(0xffffffff),
2078 .dst_addr = RTE_BE32(0xffffffff),
2079 .type_of_service = 0xff,
2080 .next_proto_id = 0xff,
2083 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2084 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2085 MLX5_FLOW_LAYER_OUTER_L3;
2086 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2087 MLX5_FLOW_LAYER_OUTER_L4;
2089 uint8_t next_proto = 0xFF;
2090 const uint64_t l2_vlan = (MLX5_FLOW_LAYER_L2 |
2091 MLX5_FLOW_LAYER_OUTER_VLAN |
2092 MLX5_FLOW_LAYER_INNER_VLAN);
2094 if ((last_item & l2_vlan) && ether_type &&
2095 ether_type != RTE_ETHER_TYPE_IPV4)
2096 return rte_flow_error_set(error, EINVAL,
2097 RTE_FLOW_ERROR_TYPE_ITEM, item,
2098 "IPv4 cannot follow L2/VLAN layer "
2099 "which ether type is not IPv4");
2100 if (item_flags & MLX5_FLOW_LAYER_IPIP) {
2102 next_proto = mask->hdr.next_proto_id &
2103 spec->hdr.next_proto_id;
2104 if (next_proto == IPPROTO_IPIP || next_proto == IPPROTO_IPV6)
2105 return rte_flow_error_set(error, EINVAL,
2106 RTE_FLOW_ERROR_TYPE_ITEM,
2111 if (item_flags & MLX5_FLOW_LAYER_IPV6_ENCAP)
2112 return rte_flow_error_set(error, EINVAL,
2113 RTE_FLOW_ERROR_TYPE_ITEM, item,
2114 "wrong tunnel type - IPv6 specified "
2115 "but IPv4 item provided");
2116 if (item_flags & l3m)
2117 return rte_flow_error_set(error, ENOTSUP,
2118 RTE_FLOW_ERROR_TYPE_ITEM, item,
2119 "multiple L3 layers not supported");
2120 else if (item_flags & l4m)
2121 return rte_flow_error_set(error, EINVAL,
2122 RTE_FLOW_ERROR_TYPE_ITEM, item,
2123 "L3 cannot follow an L4 layer.");
2124 else if ((item_flags & MLX5_FLOW_LAYER_NVGRE) &&
2125 !(item_flags & MLX5_FLOW_LAYER_INNER_L2))
2126 return rte_flow_error_set(error, EINVAL,
2127 RTE_FLOW_ERROR_TYPE_ITEM, item,
2128 "L3 cannot follow an NVGRE layer.");
2130 mask = &rte_flow_item_ipv4_mask;
2131 else if (mask->hdr.next_proto_id != 0 &&
2132 mask->hdr.next_proto_id != 0xff)
2133 return rte_flow_error_set(error, EINVAL,
2134 RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
2135 "partial mask is not supported"
2137 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2138 acc_mask ? (const uint8_t *)acc_mask
2139 : (const uint8_t *)&nic_mask,
2140 sizeof(struct rte_flow_item_ipv4),
2141 range_accepted, error);
2148 * Validate IPV6 item.
2151 * Item specification.
2152 * @param[in] item_flags
2153 * Bit-fields that holds the items detected until now.
2154 * @param[in] last_item
2155 * Previous validated item in the pattern items.
2156 * @param[in] ether_type
2157 * Type in the ethernet layer header (including dot1q).
2158 * @param[in] acc_mask
2159 * Acceptable mask, if NULL default internal default mask
2160 * will be used to check whether item fields are supported.
2162 * Pointer to error structure.
2165 * 0 on success, a negative errno value otherwise and rte_errno is set.
2168 mlx5_flow_validate_item_ipv6(const struct rte_flow_item *item,
2169 uint64_t item_flags,
2171 uint16_t ether_type,
2172 const struct rte_flow_item_ipv6 *acc_mask,
2173 struct rte_flow_error *error)
2175 const struct rte_flow_item_ipv6 *mask = item->mask;
2176 const struct rte_flow_item_ipv6 *spec = item->spec;
2177 const struct rte_flow_item_ipv6 nic_mask = {
2180 "\xff\xff\xff\xff\xff\xff\xff\xff"
2181 "\xff\xff\xff\xff\xff\xff\xff\xff",
2183 "\xff\xff\xff\xff\xff\xff\xff\xff"
2184 "\xff\xff\xff\xff\xff\xff\xff\xff",
2185 .vtc_flow = RTE_BE32(0xffffffff),
2189 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2190 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2191 MLX5_FLOW_LAYER_OUTER_L3;
2192 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2193 MLX5_FLOW_LAYER_OUTER_L4;
2195 uint8_t next_proto = 0xFF;
2196 const uint64_t l2_vlan = (MLX5_FLOW_LAYER_L2 |
2197 MLX5_FLOW_LAYER_OUTER_VLAN |
2198 MLX5_FLOW_LAYER_INNER_VLAN);
2200 if ((last_item & l2_vlan) && ether_type &&
2201 ether_type != RTE_ETHER_TYPE_IPV6)
2202 return rte_flow_error_set(error, EINVAL,
2203 RTE_FLOW_ERROR_TYPE_ITEM, item,
2204 "IPv6 cannot follow L2/VLAN layer "
2205 "which ether type is not IPv6");
2206 if (mask && mask->hdr.proto == UINT8_MAX && spec)
2207 next_proto = spec->hdr.proto;
2208 if (item_flags & MLX5_FLOW_LAYER_IPV6_ENCAP) {
2209 if (next_proto == IPPROTO_IPIP || next_proto == IPPROTO_IPV6)
2210 return rte_flow_error_set(error, EINVAL,
2211 RTE_FLOW_ERROR_TYPE_ITEM,
2216 if (next_proto == IPPROTO_HOPOPTS ||
2217 next_proto == IPPROTO_ROUTING ||
2218 next_proto == IPPROTO_FRAGMENT ||
2219 next_proto == IPPROTO_ESP ||
2220 next_proto == IPPROTO_AH ||
2221 next_proto == IPPROTO_DSTOPTS)
2222 return rte_flow_error_set(error, EINVAL,
2223 RTE_FLOW_ERROR_TYPE_ITEM, item,
2224 "IPv6 proto (next header) should "
2225 "not be set as extension header");
2226 if (item_flags & MLX5_FLOW_LAYER_IPIP)
2227 return rte_flow_error_set(error, EINVAL,
2228 RTE_FLOW_ERROR_TYPE_ITEM, item,
2229 "wrong tunnel type - IPv4 specified "
2230 "but IPv6 item provided");
2231 if (item_flags & l3m)
2232 return rte_flow_error_set(error, ENOTSUP,
2233 RTE_FLOW_ERROR_TYPE_ITEM, item,
2234 "multiple L3 layers not supported");
2235 else if (item_flags & l4m)
2236 return rte_flow_error_set(error, EINVAL,
2237 RTE_FLOW_ERROR_TYPE_ITEM, item,
2238 "L3 cannot follow an L4 layer.");
2239 else if ((item_flags & MLX5_FLOW_LAYER_NVGRE) &&
2240 !(item_flags & MLX5_FLOW_LAYER_INNER_L2))
2241 return rte_flow_error_set(error, EINVAL,
2242 RTE_FLOW_ERROR_TYPE_ITEM, item,
2243 "L3 cannot follow an NVGRE layer.");
2245 mask = &rte_flow_item_ipv6_mask;
2246 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2247 acc_mask ? (const uint8_t *)acc_mask
2248 : (const uint8_t *)&nic_mask,
2249 sizeof(struct rte_flow_item_ipv6),
2250 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2257 * Validate UDP item.
2260 * Item specification.
2261 * @param[in] item_flags
2262 * Bit-fields that holds the items detected until now.
2263 * @param[in] target_protocol
2264 * The next protocol in the previous item.
2265 * @param[in] flow_mask
2266 * mlx5 flow-specific (DV, verbs, etc.) supported header fields mask.
2268 * Pointer to error structure.
2271 * 0 on success, a negative errno value otherwise and rte_errno is set.
2274 mlx5_flow_validate_item_udp(const struct rte_flow_item *item,
2275 uint64_t item_flags,
2276 uint8_t target_protocol,
2277 struct rte_flow_error *error)
2279 const struct rte_flow_item_udp *mask = item->mask;
2280 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2281 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2282 MLX5_FLOW_LAYER_OUTER_L3;
2283 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2284 MLX5_FLOW_LAYER_OUTER_L4;
2287 if (target_protocol != 0xff && target_protocol != IPPROTO_UDP)
2288 return rte_flow_error_set(error, EINVAL,
2289 RTE_FLOW_ERROR_TYPE_ITEM, item,
2290 "protocol filtering not compatible"
2292 if (!(item_flags & l3m))
2293 return rte_flow_error_set(error, EINVAL,
2294 RTE_FLOW_ERROR_TYPE_ITEM, item,
2295 "L3 is mandatory to filter on L4");
2296 if (item_flags & l4m)
2297 return rte_flow_error_set(error, EINVAL,
2298 RTE_FLOW_ERROR_TYPE_ITEM, item,
2299 "multiple L4 layers not supported");
2301 mask = &rte_flow_item_udp_mask;
2302 ret = mlx5_flow_item_acceptable
2303 (item, (const uint8_t *)mask,
2304 (const uint8_t *)&rte_flow_item_udp_mask,
2305 sizeof(struct rte_flow_item_udp), MLX5_ITEM_RANGE_NOT_ACCEPTED,
2313 * Validate TCP item.
2316 * Item specification.
2317 * @param[in] item_flags
2318 * Bit-fields that holds the items detected until now.
2319 * @param[in] target_protocol
2320 * The next protocol in the previous item.
2322 * Pointer to error structure.
2325 * 0 on success, a negative errno value otherwise and rte_errno is set.
2328 mlx5_flow_validate_item_tcp(const struct rte_flow_item *item,
2329 uint64_t item_flags,
2330 uint8_t target_protocol,
2331 const struct rte_flow_item_tcp *flow_mask,
2332 struct rte_flow_error *error)
2334 const struct rte_flow_item_tcp *mask = item->mask;
2335 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2336 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2337 MLX5_FLOW_LAYER_OUTER_L3;
2338 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2339 MLX5_FLOW_LAYER_OUTER_L4;
2342 MLX5_ASSERT(flow_mask);
2343 if (target_protocol != 0xff && target_protocol != IPPROTO_TCP)
2344 return rte_flow_error_set(error, EINVAL,
2345 RTE_FLOW_ERROR_TYPE_ITEM, item,
2346 "protocol filtering not compatible"
2348 if (!(item_flags & l3m))
2349 return rte_flow_error_set(error, EINVAL,
2350 RTE_FLOW_ERROR_TYPE_ITEM, item,
2351 "L3 is mandatory to filter on L4");
2352 if (item_flags & l4m)
2353 return rte_flow_error_set(error, EINVAL,
2354 RTE_FLOW_ERROR_TYPE_ITEM, item,
2355 "multiple L4 layers not supported");
2357 mask = &rte_flow_item_tcp_mask;
2358 ret = mlx5_flow_item_acceptable
2359 (item, (const uint8_t *)mask,
2360 (const uint8_t *)flow_mask,
2361 sizeof(struct rte_flow_item_tcp), MLX5_ITEM_RANGE_NOT_ACCEPTED,
2369 * Validate VXLAN item.
2372 * Item specification.
2373 * @param[in] item_flags
2374 * Bit-fields that holds the items detected until now.
2375 * @param[in] target_protocol
2376 * The next protocol in the previous item.
2378 * Pointer to error structure.
2381 * 0 on success, a negative errno value otherwise and rte_errno is set.
2384 mlx5_flow_validate_item_vxlan(const struct rte_flow_item *item,
2385 uint64_t item_flags,
2386 struct rte_flow_error *error)
2388 const struct rte_flow_item_vxlan *spec = item->spec;
2389 const struct rte_flow_item_vxlan *mask = item->mask;
2394 } id = { .vlan_id = 0, };
2397 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2398 return rte_flow_error_set(error, ENOTSUP,
2399 RTE_FLOW_ERROR_TYPE_ITEM, item,
2400 "multiple tunnel layers not"
2403 * Verify only UDPv4 is present as defined in
2404 * https://tools.ietf.org/html/rfc7348
2406 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2407 return rte_flow_error_set(error, EINVAL,
2408 RTE_FLOW_ERROR_TYPE_ITEM, item,
2409 "no outer UDP layer found");
2411 mask = &rte_flow_item_vxlan_mask;
2412 ret = mlx5_flow_item_acceptable
2413 (item, (const uint8_t *)mask,
2414 (const uint8_t *)&rte_flow_item_vxlan_mask,
2415 sizeof(struct rte_flow_item_vxlan),
2416 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2420 memcpy(&id.vni[1], spec->vni, 3);
2421 memcpy(&id.vni[1], mask->vni, 3);
2423 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
2424 return rte_flow_error_set(error, ENOTSUP,
2425 RTE_FLOW_ERROR_TYPE_ITEM, item,
2426 "VXLAN tunnel must be fully defined");
2431 * Validate VXLAN_GPE item.
2434 * Item specification.
2435 * @param[in] item_flags
2436 * Bit-fields that holds the items detected until now.
2438 * Pointer to the private data structure.
2439 * @param[in] target_protocol
2440 * The next protocol in the previous item.
2442 * Pointer to error structure.
2445 * 0 on success, a negative errno value otherwise and rte_errno is set.
2448 mlx5_flow_validate_item_vxlan_gpe(const struct rte_flow_item *item,
2449 uint64_t item_flags,
2450 struct rte_eth_dev *dev,
2451 struct rte_flow_error *error)
2453 struct mlx5_priv *priv = dev->data->dev_private;
2454 const struct rte_flow_item_vxlan_gpe *spec = item->spec;
2455 const struct rte_flow_item_vxlan_gpe *mask = item->mask;
2460 } id = { .vlan_id = 0, };
2462 if (!priv->config.l3_vxlan_en)
2463 return rte_flow_error_set(error, ENOTSUP,
2464 RTE_FLOW_ERROR_TYPE_ITEM, item,
2465 "L3 VXLAN is not enabled by device"
2466 " parameter and/or not configured in"
2468 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2469 return rte_flow_error_set(error, ENOTSUP,
2470 RTE_FLOW_ERROR_TYPE_ITEM, item,
2471 "multiple tunnel layers not"
2474 * Verify only UDPv4 is present as defined in
2475 * https://tools.ietf.org/html/rfc7348
2477 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2478 return rte_flow_error_set(error, EINVAL,
2479 RTE_FLOW_ERROR_TYPE_ITEM, item,
2480 "no outer UDP layer found");
2482 mask = &rte_flow_item_vxlan_gpe_mask;
2483 ret = mlx5_flow_item_acceptable
2484 (item, (const uint8_t *)mask,
2485 (const uint8_t *)&rte_flow_item_vxlan_gpe_mask,
2486 sizeof(struct rte_flow_item_vxlan_gpe),
2487 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2492 return rte_flow_error_set(error, ENOTSUP,
2493 RTE_FLOW_ERROR_TYPE_ITEM,
2495 "VxLAN-GPE protocol"
2497 memcpy(&id.vni[1], spec->vni, 3);
2498 memcpy(&id.vni[1], mask->vni, 3);
2500 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
2501 return rte_flow_error_set(error, ENOTSUP,
2502 RTE_FLOW_ERROR_TYPE_ITEM, item,
2503 "VXLAN-GPE tunnel must be fully"
2508 * Validate GRE Key item.
2511 * Item specification.
2512 * @param[in] item_flags
2513 * Bit flags to mark detected items.
2514 * @param[in] gre_item
2515 * Pointer to gre_item
2517 * Pointer to error structure.
2520 * 0 on success, a negative errno value otherwise and rte_errno is set.
2523 mlx5_flow_validate_item_gre_key(const struct rte_flow_item *item,
2524 uint64_t item_flags,
2525 const struct rte_flow_item *gre_item,
2526 struct rte_flow_error *error)
2528 const rte_be32_t *mask = item->mask;
2530 rte_be32_t gre_key_default_mask = RTE_BE32(UINT32_MAX);
2531 const struct rte_flow_item_gre *gre_spec;
2532 const struct rte_flow_item_gre *gre_mask;
2534 if (item_flags & MLX5_FLOW_LAYER_GRE_KEY)
2535 return rte_flow_error_set(error, ENOTSUP,
2536 RTE_FLOW_ERROR_TYPE_ITEM, item,
2537 "Multiple GRE key not support");
2538 if (!(item_flags & MLX5_FLOW_LAYER_GRE))
2539 return rte_flow_error_set(error, ENOTSUP,
2540 RTE_FLOW_ERROR_TYPE_ITEM, item,
2541 "No preceding GRE header");
2542 if (item_flags & MLX5_FLOW_LAYER_INNER)
2543 return rte_flow_error_set(error, ENOTSUP,
2544 RTE_FLOW_ERROR_TYPE_ITEM, item,
2545 "GRE key following a wrong item");
2546 gre_mask = gre_item->mask;
2548 gre_mask = &rte_flow_item_gre_mask;
2549 gre_spec = gre_item->spec;
2550 if (gre_spec && (gre_mask->c_rsvd0_ver & RTE_BE16(0x2000)) &&
2551 !(gre_spec->c_rsvd0_ver & RTE_BE16(0x2000)))
2552 return rte_flow_error_set(error, EINVAL,
2553 RTE_FLOW_ERROR_TYPE_ITEM, item,
2554 "Key bit must be on");
2557 mask = &gre_key_default_mask;
2558 ret = mlx5_flow_item_acceptable
2559 (item, (const uint8_t *)mask,
2560 (const uint8_t *)&gre_key_default_mask,
2561 sizeof(rte_be32_t), MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2566 * Validate GRE item.
2569 * Item specification.
2570 * @param[in] item_flags
2571 * Bit flags to mark detected items.
2572 * @param[in] target_protocol
2573 * The next protocol in the previous item.
2575 * Pointer to error structure.
2578 * 0 on success, a negative errno value otherwise and rte_errno is set.
2581 mlx5_flow_validate_item_gre(const struct rte_flow_item *item,
2582 uint64_t item_flags,
2583 uint8_t target_protocol,
2584 struct rte_flow_error *error)
2586 const struct rte_flow_item_gre *spec __rte_unused = item->spec;
2587 const struct rte_flow_item_gre *mask = item->mask;
2589 const struct rte_flow_item_gre nic_mask = {
2590 .c_rsvd0_ver = RTE_BE16(0xB000),
2591 .protocol = RTE_BE16(UINT16_MAX),
2594 if (target_protocol != 0xff && target_protocol != IPPROTO_GRE)
2595 return rte_flow_error_set(error, EINVAL,
2596 RTE_FLOW_ERROR_TYPE_ITEM, item,
2597 "protocol filtering not compatible"
2598 " with this GRE layer");
2599 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2600 return rte_flow_error_set(error, ENOTSUP,
2601 RTE_FLOW_ERROR_TYPE_ITEM, item,
2602 "multiple tunnel layers not"
2604 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3))
2605 return rte_flow_error_set(error, ENOTSUP,
2606 RTE_FLOW_ERROR_TYPE_ITEM, item,
2607 "L3 Layer is missing");
2609 mask = &rte_flow_item_gre_mask;
2610 ret = mlx5_flow_item_acceptable
2611 (item, (const uint8_t *)mask,
2612 (const uint8_t *)&nic_mask,
2613 sizeof(struct rte_flow_item_gre), MLX5_ITEM_RANGE_NOT_ACCEPTED,
2617 #ifndef HAVE_MLX5DV_DR
2618 #ifndef HAVE_IBV_DEVICE_MPLS_SUPPORT
2619 if (spec && (spec->protocol & mask->protocol))
2620 return rte_flow_error_set(error, ENOTSUP,
2621 RTE_FLOW_ERROR_TYPE_ITEM, item,
2622 "without MPLS support the"
2623 " specification cannot be used for"
2631 * Validate Geneve item.
2634 * Item specification.
2635 * @param[in] itemFlags
2636 * Bit-fields that holds the items detected until now.
2638 * Pointer to the private data structure.
2640 * Pointer to error structure.
2643 * 0 on success, a negative errno value otherwise and rte_errno is set.
2647 mlx5_flow_validate_item_geneve(const struct rte_flow_item *item,
2648 uint64_t item_flags,
2649 struct rte_eth_dev *dev,
2650 struct rte_flow_error *error)
2652 struct mlx5_priv *priv = dev->data->dev_private;
2653 const struct rte_flow_item_geneve *spec = item->spec;
2654 const struct rte_flow_item_geneve *mask = item->mask;
2657 uint8_t opt_len = priv->config.hca_attr.geneve_max_opt_len ?
2658 MLX5_GENEVE_OPT_LEN_1 : MLX5_GENEVE_OPT_LEN_0;
2659 const struct rte_flow_item_geneve nic_mask = {
2660 .ver_opt_len_o_c_rsvd0 = RTE_BE16(0x3f80),
2661 .vni = "\xff\xff\xff",
2662 .protocol = RTE_BE16(UINT16_MAX),
2665 if (!priv->config.hca_attr.tunnel_stateless_geneve_rx)
2666 return rte_flow_error_set(error, ENOTSUP,
2667 RTE_FLOW_ERROR_TYPE_ITEM, item,
2668 "L3 Geneve is not enabled by device"
2669 " parameter and/or not configured in"
2671 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2672 return rte_flow_error_set(error, ENOTSUP,
2673 RTE_FLOW_ERROR_TYPE_ITEM, item,
2674 "multiple tunnel layers not"
2677 * Verify only UDPv4 is present as defined in
2678 * https://tools.ietf.org/html/rfc7348
2680 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2681 return rte_flow_error_set(error, EINVAL,
2682 RTE_FLOW_ERROR_TYPE_ITEM, item,
2683 "no outer UDP layer found");
2685 mask = &rte_flow_item_geneve_mask;
2686 ret = mlx5_flow_item_acceptable
2687 (item, (const uint8_t *)mask,
2688 (const uint8_t *)&nic_mask,
2689 sizeof(struct rte_flow_item_geneve),
2690 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2694 gbhdr = rte_be_to_cpu_16(spec->ver_opt_len_o_c_rsvd0);
2695 if (MLX5_GENEVE_VER_VAL(gbhdr) ||
2696 MLX5_GENEVE_CRITO_VAL(gbhdr) ||
2697 MLX5_GENEVE_RSVD_VAL(gbhdr) || spec->rsvd1)
2698 return rte_flow_error_set(error, ENOTSUP,
2699 RTE_FLOW_ERROR_TYPE_ITEM,
2701 "Geneve protocol unsupported"
2702 " fields are being used");
2703 if (MLX5_GENEVE_OPTLEN_VAL(gbhdr) > opt_len)
2704 return rte_flow_error_set
2706 RTE_FLOW_ERROR_TYPE_ITEM,
2708 "Unsupported Geneve options length");
2710 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
2711 return rte_flow_error_set
2713 RTE_FLOW_ERROR_TYPE_ITEM, item,
2714 "Geneve tunnel must be fully defined");
2719 * Validate MPLS item.
2722 * Pointer to the rte_eth_dev structure.
2724 * Item specification.
2725 * @param[in] item_flags
2726 * Bit-fields that holds the items detected until now.
2727 * @param[in] prev_layer
2728 * The protocol layer indicated in previous item.
2730 * Pointer to error structure.
2733 * 0 on success, a negative errno value otherwise and rte_errno is set.
2736 mlx5_flow_validate_item_mpls(struct rte_eth_dev *dev __rte_unused,
2737 const struct rte_flow_item *item __rte_unused,
2738 uint64_t item_flags __rte_unused,
2739 uint64_t prev_layer __rte_unused,
2740 struct rte_flow_error *error)
2742 #ifdef HAVE_IBV_DEVICE_MPLS_SUPPORT
2743 const struct rte_flow_item_mpls *mask = item->mask;
2744 struct mlx5_priv *priv = dev->data->dev_private;
2747 if (!priv->config.mpls_en)
2748 return rte_flow_error_set(error, ENOTSUP,
2749 RTE_FLOW_ERROR_TYPE_ITEM, item,
2750 "MPLS not supported or"
2751 " disabled in firmware"
2753 /* MPLS over IP, UDP, GRE is allowed */
2754 if (!(prev_layer & (MLX5_FLOW_LAYER_OUTER_L3 |
2755 MLX5_FLOW_LAYER_OUTER_L4_UDP |
2756 MLX5_FLOW_LAYER_GRE)))
2757 return rte_flow_error_set(error, EINVAL,
2758 RTE_FLOW_ERROR_TYPE_ITEM, item,
2759 "protocol filtering not compatible"
2760 " with MPLS layer");
2761 /* Multi-tunnel isn't allowed but MPLS over GRE is an exception. */
2762 if ((item_flags & MLX5_FLOW_LAYER_TUNNEL) &&
2763 !(item_flags & MLX5_FLOW_LAYER_GRE))
2764 return rte_flow_error_set(error, ENOTSUP,
2765 RTE_FLOW_ERROR_TYPE_ITEM, item,
2766 "multiple tunnel layers not"
2769 mask = &rte_flow_item_mpls_mask;
2770 ret = mlx5_flow_item_acceptable
2771 (item, (const uint8_t *)mask,
2772 (const uint8_t *)&rte_flow_item_mpls_mask,
2773 sizeof(struct rte_flow_item_mpls),
2774 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2779 return rte_flow_error_set(error, ENOTSUP,
2780 RTE_FLOW_ERROR_TYPE_ITEM, item,
2781 "MPLS is not supported by Verbs, please"
2787 * Validate NVGRE item.
2790 * Item specification.
2791 * @param[in] item_flags
2792 * Bit flags to mark detected items.
2793 * @param[in] target_protocol
2794 * The next protocol in the previous item.
2796 * Pointer to error structure.
2799 * 0 on success, a negative errno value otherwise and rte_errno is set.
2802 mlx5_flow_validate_item_nvgre(const struct rte_flow_item *item,
2803 uint64_t item_flags,
2804 uint8_t target_protocol,
2805 struct rte_flow_error *error)
2807 const struct rte_flow_item_nvgre *mask = item->mask;
2810 if (target_protocol != 0xff && target_protocol != IPPROTO_GRE)
2811 return rte_flow_error_set(error, EINVAL,
2812 RTE_FLOW_ERROR_TYPE_ITEM, item,
2813 "protocol filtering not compatible"
2814 " with this GRE layer");
2815 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2816 return rte_flow_error_set(error, ENOTSUP,
2817 RTE_FLOW_ERROR_TYPE_ITEM, item,
2818 "multiple tunnel layers not"
2820 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3))
2821 return rte_flow_error_set(error, ENOTSUP,
2822 RTE_FLOW_ERROR_TYPE_ITEM, item,
2823 "L3 Layer is missing");
2825 mask = &rte_flow_item_nvgre_mask;
2826 ret = mlx5_flow_item_acceptable
2827 (item, (const uint8_t *)mask,
2828 (const uint8_t *)&rte_flow_item_nvgre_mask,
2829 sizeof(struct rte_flow_item_nvgre),
2830 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2837 * Validate eCPRI item.
2840 * Item specification.
2841 * @param[in] item_flags
2842 * Bit-fields that holds the items detected until now.
2843 * @param[in] last_item
2844 * Previous validated item in the pattern items.
2845 * @param[in] ether_type
2846 * Type in the ethernet layer header (including dot1q).
2847 * @param[in] acc_mask
2848 * Acceptable mask, if NULL default internal default mask
2849 * will be used to check whether item fields are supported.
2851 * Pointer to error structure.
2854 * 0 on success, a negative errno value otherwise and rte_errno is set.
2857 mlx5_flow_validate_item_ecpri(const struct rte_flow_item *item,
2858 uint64_t item_flags,
2860 uint16_t ether_type,
2861 const struct rte_flow_item_ecpri *acc_mask,
2862 struct rte_flow_error *error)
2864 const struct rte_flow_item_ecpri *mask = item->mask;
2865 const struct rte_flow_item_ecpri nic_mask = {
2869 RTE_BE32(((const struct rte_ecpri_common_hdr) {
2873 .dummy[0] = 0xFFFFFFFF,
2876 const uint64_t outer_l2_vlan = (MLX5_FLOW_LAYER_OUTER_L2 |
2877 MLX5_FLOW_LAYER_OUTER_VLAN);
2878 struct rte_flow_item_ecpri mask_lo;
2880 if ((last_item & outer_l2_vlan) && ether_type &&
2881 ether_type != RTE_ETHER_TYPE_ECPRI)
2882 return rte_flow_error_set(error, EINVAL,
2883 RTE_FLOW_ERROR_TYPE_ITEM, item,
2884 "eCPRI cannot follow L2/VLAN layer "
2885 "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 "
2891 if (item_flags & MLX5_FLOW_LAYER_OUTER_L3)
2892 return rte_flow_error_set(error, ENOTSUP,
2893 RTE_FLOW_ERROR_TYPE_ITEM, item,
2894 "multiple L3 layers not supported");
2895 else if (item_flags & MLX5_FLOW_LAYER_OUTER_L4_TCP)
2896 return rte_flow_error_set(error, EINVAL,
2897 RTE_FLOW_ERROR_TYPE_ITEM, item,
2898 "eCPRI cannot follow a TCP layer.");
2899 /* In specification, eCPRI could be over UDP layer. */
2900 else if (item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP)
2901 return rte_flow_error_set(error, EINVAL,
2902 RTE_FLOW_ERROR_TYPE_ITEM, item,
2903 "eCPRI over UDP layer is not yet "
2904 "supported right now.");
2905 /* Mask for type field in common header could be zero. */
2907 mask = &rte_flow_item_ecpri_mask;
2908 mask_lo.hdr.common.u32 = rte_be_to_cpu_32(mask->hdr.common.u32);
2909 /* Input mask is in big-endian format. */
2910 if (mask_lo.hdr.common.type != 0 && mask_lo.hdr.common.type != 0xff)
2911 return rte_flow_error_set(error, EINVAL,
2912 RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
2913 "partial mask is not supported "
2915 else if (mask_lo.hdr.common.type == 0 && mask->hdr.dummy[0] != 0)
2916 return rte_flow_error_set(error, EINVAL,
2917 RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
2918 "message header mask must be after "
2920 return mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2921 acc_mask ? (const uint8_t *)acc_mask
2922 : (const uint8_t *)&nic_mask,
2923 sizeof(struct rte_flow_item_ecpri),
2924 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2927 /* Allocate unique ID for the split Q/RSS subflows. */
2929 flow_qrss_get_id(struct rte_eth_dev *dev)
2931 struct mlx5_priv *priv = dev->data->dev_private;
2932 uint32_t qrss_id, ret;
2934 ret = mlx5_flow_id_get(priv->qrss_id_pool, &qrss_id);
2937 MLX5_ASSERT(qrss_id);
2941 /* Free unique ID for the split Q/RSS subflows. */
2943 flow_qrss_free_id(struct rte_eth_dev *dev, uint32_t qrss_id)
2945 struct mlx5_priv *priv = dev->data->dev_private;
2948 mlx5_flow_id_release(priv->qrss_id_pool, qrss_id);
2952 * Release resource related QUEUE/RSS action split.
2955 * Pointer to Ethernet device.
2957 * Flow to release id's from.
2960 flow_mreg_split_qrss_release(struct rte_eth_dev *dev,
2961 struct rte_flow *flow)
2963 struct mlx5_priv *priv = dev->data->dev_private;
2964 uint32_t handle_idx;
2965 struct mlx5_flow_handle *dev_handle;
2967 SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
2968 handle_idx, dev_handle, next)
2969 if (dev_handle->split_flow_id)
2970 flow_qrss_free_id(dev, dev_handle->split_flow_id);
2974 flow_null_validate(struct rte_eth_dev *dev __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 bool external __rte_unused,
2979 int hairpin __rte_unused,
2980 struct rte_flow_error *error)
2982 return rte_flow_error_set(error, ENOTSUP,
2983 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
2986 static struct mlx5_flow *
2987 flow_null_prepare(struct rte_eth_dev *dev __rte_unused,
2988 const struct rte_flow_attr *attr __rte_unused,
2989 const struct rte_flow_item items[] __rte_unused,
2990 const struct rte_flow_action actions[] __rte_unused,
2991 struct rte_flow_error *error)
2993 rte_flow_error_set(error, ENOTSUP,
2994 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
2999 flow_null_translate(struct rte_eth_dev *dev __rte_unused,
3000 struct mlx5_flow *dev_flow __rte_unused,
3001 const struct rte_flow_attr *attr __rte_unused,
3002 const struct rte_flow_item items[] __rte_unused,
3003 const struct rte_flow_action actions[] __rte_unused,
3004 struct rte_flow_error *error)
3006 return rte_flow_error_set(error, ENOTSUP,
3007 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
3011 flow_null_apply(struct rte_eth_dev *dev __rte_unused,
3012 struct rte_flow *flow __rte_unused,
3013 struct rte_flow_error *error)
3015 return rte_flow_error_set(error, ENOTSUP,
3016 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
3020 flow_null_remove(struct rte_eth_dev *dev __rte_unused,
3021 struct rte_flow *flow __rte_unused)
3026 flow_null_destroy(struct rte_eth_dev *dev __rte_unused,
3027 struct rte_flow *flow __rte_unused)
3032 flow_null_query(struct rte_eth_dev *dev __rte_unused,
3033 struct rte_flow *flow __rte_unused,
3034 const struct rte_flow_action *actions __rte_unused,
3035 void *data __rte_unused,
3036 struct rte_flow_error *error)
3038 return rte_flow_error_set(error, ENOTSUP,
3039 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
3042 /* Void driver to protect from null pointer reference. */
3043 const struct mlx5_flow_driver_ops mlx5_flow_null_drv_ops = {
3044 .validate = flow_null_validate,
3045 .prepare = flow_null_prepare,
3046 .translate = flow_null_translate,
3047 .apply = flow_null_apply,
3048 .remove = flow_null_remove,
3049 .destroy = flow_null_destroy,
3050 .query = flow_null_query,
3054 * Select flow driver type according to flow attributes and device
3058 * Pointer to the dev structure.
3060 * Pointer to the flow attributes.
3063 * flow driver type, MLX5_FLOW_TYPE_MAX otherwise.
3065 static enum mlx5_flow_drv_type
3066 flow_get_drv_type(struct rte_eth_dev *dev, const struct rte_flow_attr *attr)
3068 struct mlx5_priv *priv = dev->data->dev_private;
3069 /* The OS can determine first a specific flow type (DV, VERBS) */
3070 enum mlx5_flow_drv_type type = mlx5_flow_os_get_type();
3072 if (type != MLX5_FLOW_TYPE_MAX)
3074 /* If no OS specific type - continue with DV/VERBS selection */
3075 if (attr->transfer && priv->config.dv_esw_en)
3076 type = MLX5_FLOW_TYPE_DV;
3077 if (!attr->transfer)
3078 type = priv->config.dv_flow_en ? MLX5_FLOW_TYPE_DV :
3079 MLX5_FLOW_TYPE_VERBS;
3083 #define flow_get_drv_ops(type) flow_drv_ops[type]
3086 * Flow driver validation API. This abstracts calling driver specific functions.
3087 * The type of flow driver is determined according to flow attributes.
3090 * Pointer to the dev structure.
3092 * Pointer to the flow attributes.
3094 * Pointer to the list of items.
3095 * @param[in] actions
3096 * Pointer to the list of actions.
3097 * @param[in] external
3098 * This flow rule is created by request external to PMD.
3099 * @param[in] hairpin
3100 * Number of hairpin TX actions, 0 means classic flow.
3102 * Pointer to the error structure.
3105 * 0 on success, a negative errno value otherwise and rte_errno is set.
3108 flow_drv_validate(struct rte_eth_dev *dev,
3109 const struct rte_flow_attr *attr,
3110 const struct rte_flow_item items[],
3111 const struct rte_flow_action actions[],
3112 bool external, int hairpin, struct rte_flow_error *error)
3114 const struct mlx5_flow_driver_ops *fops;
3115 enum mlx5_flow_drv_type type = flow_get_drv_type(dev, attr);
3117 fops = flow_get_drv_ops(type);
3118 return fops->validate(dev, attr, items, actions, external,
3123 * Flow driver preparation API. This abstracts calling driver specific
3124 * functions. Parent flow (rte_flow) should have driver type (drv_type). It
3125 * calculates the size of memory required for device flow, allocates the memory,
3126 * initializes the device flow and returns the pointer.
3129 * This function initializes device flow structure such as dv or verbs in
3130 * struct mlx5_flow. However, it is caller's responsibility to initialize the
3131 * rest. For example, adding returning device flow to flow->dev_flow list and
3132 * setting backward reference to the flow should be done out of this function.
3133 * layers field is not filled either.
3136 * Pointer to the dev structure.
3138 * Pointer to the flow attributes.
3140 * Pointer to the list of items.
3141 * @param[in] actions
3142 * Pointer to the list of actions.
3143 * @param[in] flow_idx
3144 * This memory pool index to the flow.
3146 * Pointer to the error structure.
3149 * Pointer to device flow on success, otherwise NULL and rte_errno is set.
3151 static inline struct mlx5_flow *
3152 flow_drv_prepare(struct rte_eth_dev *dev,
3153 const struct rte_flow *flow,
3154 const struct rte_flow_attr *attr,
3155 const struct rte_flow_item items[],
3156 const struct rte_flow_action actions[],
3158 struct rte_flow_error *error)
3160 const struct mlx5_flow_driver_ops *fops;
3161 enum mlx5_flow_drv_type type = flow->drv_type;
3162 struct mlx5_flow *mlx5_flow = NULL;
3164 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3165 fops = flow_get_drv_ops(type);
3166 mlx5_flow = fops->prepare(dev, attr, items, actions, error);
3168 mlx5_flow->flow_idx = flow_idx;
3173 * Flow driver translation API. This abstracts calling driver specific
3174 * functions. Parent flow (rte_flow) should have driver type (drv_type). It
3175 * translates a generic flow into a driver flow. flow_drv_prepare() must
3179 * dev_flow->layers could be filled as a result of parsing during translation
3180 * if needed by flow_drv_apply(). dev_flow->flow->actions can also be filled
3181 * if necessary. As a flow can have multiple dev_flows by RSS flow expansion,
3182 * flow->actions could be overwritten even though all the expanded dev_flows
3183 * have the same actions.
3186 * Pointer to the rte dev structure.
3187 * @param[in, out] dev_flow
3188 * Pointer to the mlx5 flow.
3190 * Pointer to the flow attributes.
3192 * Pointer to the list of items.
3193 * @param[in] actions
3194 * Pointer to the list of actions.
3196 * Pointer to the error structure.
3199 * 0 on success, a negative errno value otherwise and rte_errno is set.
3202 flow_drv_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
3203 const struct rte_flow_attr *attr,
3204 const struct rte_flow_item items[],
3205 const struct rte_flow_action actions[],
3206 struct rte_flow_error *error)
3208 const struct mlx5_flow_driver_ops *fops;
3209 enum mlx5_flow_drv_type type = dev_flow->flow->drv_type;
3211 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3212 fops = flow_get_drv_ops(type);
3213 return fops->translate(dev, dev_flow, attr, items, actions, error);
3217 * Flow driver apply API. This abstracts calling driver specific functions.
3218 * Parent flow (rte_flow) should have driver type (drv_type). It applies
3219 * translated driver flows on to device. flow_drv_translate() must precede.
3222 * Pointer to Ethernet device structure.
3223 * @param[in, out] flow
3224 * Pointer to flow structure.
3226 * Pointer to error structure.
3229 * 0 on success, a negative errno value otherwise and rte_errno is set.
3232 flow_drv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
3233 struct rte_flow_error *error)
3235 const struct mlx5_flow_driver_ops *fops;
3236 enum mlx5_flow_drv_type type = flow->drv_type;
3238 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3239 fops = flow_get_drv_ops(type);
3240 return fops->apply(dev, flow, error);
3244 * Flow driver remove API. This abstracts calling driver specific functions.
3245 * Parent flow (rte_flow) should have driver type (drv_type). It removes a flow
3246 * on device. All the resources of the flow should be freed by calling
3247 * flow_drv_destroy().
3250 * Pointer to Ethernet device.
3251 * @param[in, out] flow
3252 * Pointer to flow structure.
3255 flow_drv_remove(struct rte_eth_dev *dev, struct rte_flow *flow)
3257 const struct mlx5_flow_driver_ops *fops;
3258 enum mlx5_flow_drv_type type = flow->drv_type;
3260 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3261 fops = flow_get_drv_ops(type);
3262 fops->remove(dev, flow);
3266 * Flow driver destroy API. This abstracts calling driver specific functions.
3267 * Parent flow (rte_flow) should have driver type (drv_type). It removes a flow
3268 * on device and releases resources of the flow.
3271 * Pointer to Ethernet device.
3272 * @param[in, out] flow
3273 * Pointer to flow structure.
3276 flow_drv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
3278 const struct mlx5_flow_driver_ops *fops;
3279 enum mlx5_flow_drv_type type = flow->drv_type;
3281 flow_mreg_split_qrss_release(dev, flow);
3282 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3283 fops = flow_get_drv_ops(type);
3284 fops->destroy(dev, flow);
3288 * Get RSS action from the action list.
3290 * @param[in] actions
3291 * Pointer to the list of actions.
3294 * Pointer to the RSS action if exist, else return NULL.
3296 static const struct rte_flow_action_rss*
3297 flow_get_rss_action(const struct rte_flow_action actions[])
3299 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3300 switch (actions->type) {
3301 case RTE_FLOW_ACTION_TYPE_RSS:
3302 return (const struct rte_flow_action_rss *)
3311 /* maps shared action to translated non shared in some actions array */
3312 struct mlx5_translated_shared_action {
3313 struct rte_flow_shared_action *action; /**< Shared action */
3314 int index; /**< Index in related array of rte_flow_action */
3318 * Translates actions of type RTE_FLOW_ACTION_TYPE_SHARED to related
3319 * non shared action if translation possible.
3320 * This functionality used to run same execution path for both shared & non
3321 * shared actions on flow create. All necessary preparations for shared
3322 * action handling should be preformed on *shared* actions list returned
3325 * @param[in] actions
3326 * List of actions to translate.
3327 * @param[out] shared
3328 * List to store translated shared actions.
3329 * @param[in, out] shared_n
3330 * Size of *shared* array. On return should be updated with number of shared
3331 * actions retrieved from the *actions* list.
3332 * @param[out] translated_actions
3333 * List of actions where all shared actions were translated to non shared
3334 * if possible. NULL if no translation took place.
3336 * Pointer to the error structure.
3339 * 0 on success, a negative errno value otherwise and rte_errno is set.
3342 flow_shared_actions_translate(const struct rte_flow_action actions[],
3343 struct mlx5_translated_shared_action *shared,
3345 struct rte_flow_action **translated_actions,
3346 struct rte_flow_error *error)
3348 struct rte_flow_action *translated = NULL;
3349 size_t actions_size;
3352 struct mlx5_translated_shared_action *shared_end = NULL;
3354 for (n = 0; actions[n].type != RTE_FLOW_ACTION_TYPE_END; n++) {
3355 if (actions[n].type != RTE_FLOW_ACTION_TYPE_SHARED)
3357 if (copied_n == *shared_n) {
3358 return rte_flow_error_set
3359 (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION_NUM,
3360 NULL, "too many shared actions");
3362 rte_memcpy(&shared[copied_n].action, &actions[n].conf,
3363 sizeof(actions[n].conf));
3364 shared[copied_n].index = n;
3368 *shared_n = copied_n;
3371 actions_size = sizeof(struct rte_flow_action) * n;
3372 translated = mlx5_malloc(MLX5_MEM_ZERO, actions_size, 0, SOCKET_ID_ANY);
3377 memcpy(translated, actions, actions_size);
3378 for (shared_end = shared + copied_n; shared < shared_end; shared++) {
3379 const struct rte_flow_shared_action *shared_action;
3381 shared_action = shared->action;
3382 switch (shared_action->type) {
3383 case MLX5_RTE_FLOW_ACTION_TYPE_SHARED_RSS:
3384 translated[shared->index].type =
3385 RTE_FLOW_ACTION_TYPE_RSS;
3386 translated[shared->index].conf =
3387 &shared_action->rss.origin;
3390 mlx5_free(translated);
3391 return rte_flow_error_set
3392 (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
3393 NULL, "invalid shared action type");
3396 *translated_actions = translated;
3401 * Get Shared RSS action from the action list.
3404 * Pointer to the list of actions.
3405 * @param[in] shared_n
3406 * Actions list length.
3409 * Pointer to the MLX5 RSS action if exists, otherwise return NULL.
3411 static struct mlx5_shared_action_rss *
3412 flow_get_shared_rss_action(struct mlx5_translated_shared_action *shared,
3415 struct mlx5_translated_shared_action *shared_end;
3417 for (shared_end = shared + shared_n; shared < shared_end; shared++) {
3418 struct rte_flow_shared_action *shared_action;
3420 shared_action = shared->action;
3421 switch (shared_action->type) {
3422 case MLX5_RTE_FLOW_ACTION_TYPE_SHARED_RSS:
3423 __atomic_add_fetch(&shared_action->refcnt, 1,
3425 return &shared_action->rss;
3433 struct rte_flow_shared_action *
3434 mlx5_flow_get_shared_rss(struct rte_flow *flow)
3436 if (flow->shared_rss)
3437 return container_of(flow->shared_rss,
3438 struct rte_flow_shared_action, rss);
3444 find_graph_root(const struct rte_flow_item pattern[], uint32_t rss_level)
3446 const struct rte_flow_item *item;
3447 unsigned int has_vlan = 0;
3449 for (item = pattern; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
3450 if (item->type == RTE_FLOW_ITEM_TYPE_VLAN) {
3456 return rss_level < 2 ? MLX5_EXPANSION_ROOT_ETH_VLAN :
3457 MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN;
3458 return rss_level < 2 ? MLX5_EXPANSION_ROOT :
3459 MLX5_EXPANSION_ROOT_OUTER;
3463 * Get layer flags from the prefix flow.
3465 * Some flows may be split to several subflows, the prefix subflow gets the
3466 * match items and the suffix sub flow gets the actions.
3467 * Some actions need the user defined match item flags to get the detail for
3469 * This function helps the suffix flow to get the item layer flags from prefix
3472 * @param[in] dev_flow
3473 * Pointer the created preifx subflow.
3476 * The layers get from prefix subflow.
3478 static inline uint64_t
3479 flow_get_prefix_layer_flags(struct mlx5_flow *dev_flow)
3481 uint64_t layers = 0;
3484 * Layers bits could be localization, but usually the compiler will
3485 * help to do the optimization work for source code.
3486 * If no decap actions, use the layers directly.
3488 if (!(dev_flow->act_flags & MLX5_FLOW_ACTION_DECAP))
3489 return dev_flow->handle->layers;
3490 /* Convert L3 layers with decap action. */
3491 if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L3_IPV4)
3492 layers |= MLX5_FLOW_LAYER_OUTER_L3_IPV4;
3493 else if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L3_IPV6)
3494 layers |= MLX5_FLOW_LAYER_OUTER_L3_IPV6;
3495 /* Convert L4 layers with decap action. */
3496 if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L4_TCP)
3497 layers |= MLX5_FLOW_LAYER_OUTER_L4_TCP;
3498 else if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L4_UDP)
3499 layers |= MLX5_FLOW_LAYER_OUTER_L4_UDP;
3504 * Get metadata split action information.
3506 * @param[in] actions
3507 * Pointer to the list of actions.
3509 * Pointer to the return pointer.
3510 * @param[out] qrss_type
3511 * Pointer to the action type to return. RTE_FLOW_ACTION_TYPE_END is returned
3512 * if no QUEUE/RSS is found.
3513 * @param[out] encap_idx
3514 * Pointer to the index of the encap action if exists, otherwise the last
3518 * Total number of actions.
3521 flow_parse_metadata_split_actions_info(const struct rte_flow_action actions[],
3522 const struct rte_flow_action **qrss,
3525 const struct rte_flow_action_raw_encap *raw_encap;
3527 int raw_decap_idx = -1;
3530 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3531 switch (actions->type) {
3532 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
3533 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
3534 *encap_idx = actions_n;
3536 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
3537 raw_decap_idx = actions_n;
3539 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
3540 raw_encap = actions->conf;
3541 if (raw_encap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
3542 *encap_idx = raw_decap_idx != -1 ?
3543 raw_decap_idx : actions_n;
3545 case RTE_FLOW_ACTION_TYPE_QUEUE:
3546 case RTE_FLOW_ACTION_TYPE_RSS:
3554 if (*encap_idx == -1)
3555 *encap_idx = actions_n;
3556 /* Count RTE_FLOW_ACTION_TYPE_END. */
3557 return actions_n + 1;
3561 * Check meter action from the action list.
3563 * @param[in] actions
3564 * Pointer to the list of actions.
3566 * Pointer to the meter exist flag.
3569 * Total number of actions.
3572 flow_check_meter_action(const struct rte_flow_action actions[], uint32_t *mtr)
3578 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3579 switch (actions->type) {
3580 case RTE_FLOW_ACTION_TYPE_METER:
3588 /* Count RTE_FLOW_ACTION_TYPE_END. */
3589 return actions_n + 1;
3593 * Check if the flow should be split due to hairpin.
3594 * The reason for the split is that in current HW we can't
3595 * support encap and push-vlan on Rx, so if a flow contains
3596 * these actions we move it to Tx.
3599 * Pointer to Ethernet device.
3601 * Flow rule attributes.
3602 * @param[in] actions
3603 * Associated actions (list terminated by the END action).
3606 * > 0 the number of actions and the flow should be split,
3607 * 0 when no split required.
3610 flow_check_hairpin_split(struct rte_eth_dev *dev,
3611 const struct rte_flow_attr *attr,
3612 const struct rte_flow_action actions[])
3614 int queue_action = 0;
3617 const struct rte_flow_action_queue *queue;
3618 const struct rte_flow_action_rss *rss;
3619 const struct rte_flow_action_raw_encap *raw_encap;
3620 const struct rte_eth_hairpin_conf *conf;
3624 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3625 switch (actions->type) {
3626 case RTE_FLOW_ACTION_TYPE_QUEUE:
3627 queue = actions->conf;
3630 conf = mlx5_rxq_get_hairpin_conf(dev, queue->index);
3631 if (conf != NULL && !!conf->tx_explicit)
3636 case RTE_FLOW_ACTION_TYPE_RSS:
3637 rss = actions->conf;
3638 if (rss == NULL || rss->queue_num == 0)
3640 conf = mlx5_rxq_get_hairpin_conf(dev, rss->queue[0]);
3641 if (conf != NULL && !!conf->tx_explicit)
3646 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
3647 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
3648 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
3649 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
3650 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
3654 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
3655 raw_encap = actions->conf;
3656 if (raw_encap->size >
3657 (sizeof(struct rte_flow_item_eth) +
3658 sizeof(struct rte_flow_item_ipv4)))
3667 if (split && queue_action)
3672 /* Declare flow create/destroy prototype in advance. */
3674 flow_list_create(struct rte_eth_dev *dev, uint32_t *list,
3675 const struct rte_flow_attr *attr,
3676 const struct rte_flow_item items[],
3677 const struct rte_flow_action actions[],
3678 bool external, struct rte_flow_error *error);
3681 flow_list_destroy(struct rte_eth_dev *dev, uint32_t *list,
3685 * Add a flow of copying flow metadata registers in RX_CP_TBL.
3687 * As mark_id is unique, if there's already a registered flow for the mark_id,
3688 * return by increasing the reference counter of the resource. Otherwise, create
3689 * the resource (mcp_res) and flow.
3692 * - If ingress port is ANY and reg_c[1] is mark_id,
3693 * flow_tag := mark_id, reg_b := reg_c[0] and jump to RX_ACT_TBL.
3695 * For default flow (zero mark_id), flow is like,
3696 * - If ingress port is ANY,
3697 * reg_b := reg_c[0] and jump to RX_ACT_TBL.
3700 * Pointer to Ethernet device.
3702 * ID of MARK action, zero means default flow for META.
3704 * Perform verbose error reporting if not NULL.
3707 * Associated resource on success, NULL otherwise and rte_errno is set.
3709 static struct mlx5_flow_mreg_copy_resource *
3710 flow_mreg_add_copy_action(struct rte_eth_dev *dev, uint32_t mark_id,
3711 struct rte_flow_error *error)
3713 struct mlx5_priv *priv = dev->data->dev_private;
3714 struct rte_flow_attr attr = {
3715 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
3718 struct mlx5_rte_flow_item_tag tag_spec = {
3721 struct rte_flow_item items[] = {
3722 [1] = { .type = RTE_FLOW_ITEM_TYPE_END, },
3724 struct rte_flow_action_mark ftag = {
3727 struct mlx5_flow_action_copy_mreg cp_mreg = {
3731 struct rte_flow_action_jump jump = {
3732 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
3734 struct rte_flow_action actions[] = {
3735 [3] = { .type = RTE_FLOW_ACTION_TYPE_END, },
3737 struct mlx5_flow_mreg_copy_resource *mcp_res;
3741 /* Fill the register fileds in the flow. */
3742 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
3746 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_RX, 0, error);
3750 /* Check if already registered. */
3751 MLX5_ASSERT(priv->mreg_cp_tbl);
3752 mcp_res = (void *)mlx5_hlist_lookup(priv->mreg_cp_tbl, mark_id);
3754 /* For non-default rule. */
3755 if (mark_id != MLX5_DEFAULT_COPY_ID)
3757 MLX5_ASSERT(mark_id != MLX5_DEFAULT_COPY_ID ||
3758 mcp_res->refcnt == 1);
3761 /* Provide the full width of FLAG specific value. */
3762 if (mark_id == (priv->sh->dv_regc0_mask & MLX5_FLOW_MARK_DEFAULT))
3763 tag_spec.data = MLX5_FLOW_MARK_DEFAULT;
3764 /* Build a new flow. */
3765 if (mark_id != MLX5_DEFAULT_COPY_ID) {
3766 items[0] = (struct rte_flow_item){
3767 .type = (enum rte_flow_item_type)
3768 MLX5_RTE_FLOW_ITEM_TYPE_TAG,
3771 items[1] = (struct rte_flow_item){
3772 .type = RTE_FLOW_ITEM_TYPE_END,
3774 actions[0] = (struct rte_flow_action){
3775 .type = (enum rte_flow_action_type)
3776 MLX5_RTE_FLOW_ACTION_TYPE_MARK,
3779 actions[1] = (struct rte_flow_action){
3780 .type = (enum rte_flow_action_type)
3781 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
3784 actions[2] = (struct rte_flow_action){
3785 .type = RTE_FLOW_ACTION_TYPE_JUMP,
3788 actions[3] = (struct rte_flow_action){
3789 .type = RTE_FLOW_ACTION_TYPE_END,
3792 /* Default rule, wildcard match. */
3793 attr.priority = MLX5_FLOW_PRIO_RSVD;
3794 items[0] = (struct rte_flow_item){
3795 .type = RTE_FLOW_ITEM_TYPE_END,
3797 actions[0] = (struct rte_flow_action){
3798 .type = (enum rte_flow_action_type)
3799 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
3802 actions[1] = (struct rte_flow_action){
3803 .type = RTE_FLOW_ACTION_TYPE_JUMP,
3806 actions[2] = (struct rte_flow_action){
3807 .type = RTE_FLOW_ACTION_TYPE_END,
3810 /* Build a new entry. */
3811 mcp_res = mlx5_ipool_zmalloc(priv->sh->ipool[MLX5_IPOOL_MCP], &idx);
3818 * The copy Flows are not included in any list. There
3819 * ones are referenced from other Flows and can not
3820 * be applied, removed, deleted in ardbitrary order
3821 * by list traversing.
3823 mcp_res->rix_flow = flow_list_create(dev, NULL, &attr, items,
3824 actions, false, error);
3825 if (!mcp_res->rix_flow)
3828 mcp_res->hlist_ent.key = mark_id;
3829 ret = mlx5_hlist_insert(priv->mreg_cp_tbl,
3830 &mcp_res->hlist_ent);
3836 if (mcp_res->rix_flow)
3837 flow_list_destroy(dev, NULL, mcp_res->rix_flow);
3838 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], mcp_res->idx);
3843 * Release flow in RX_CP_TBL.
3846 * Pointer to Ethernet device.
3848 * Parent flow for wich copying is provided.
3851 flow_mreg_del_copy_action(struct rte_eth_dev *dev,
3852 struct rte_flow *flow)
3854 struct mlx5_flow_mreg_copy_resource *mcp_res;
3855 struct mlx5_priv *priv = dev->data->dev_private;
3857 if (!flow->rix_mreg_copy)
3859 mcp_res = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MCP],
3860 flow->rix_mreg_copy);
3861 if (!mcp_res || !priv->mreg_cp_tbl)
3863 if (flow->copy_applied) {
3864 MLX5_ASSERT(mcp_res->appcnt);
3865 flow->copy_applied = 0;
3867 if (!mcp_res->appcnt) {
3868 struct rte_flow *mcp_flow = mlx5_ipool_get
3869 (priv->sh->ipool[MLX5_IPOOL_RTE_FLOW],
3873 flow_drv_remove(dev, mcp_flow);
3877 * We do not check availability of metadata registers here,
3878 * because copy resources are not allocated in this case.
3880 if (--mcp_res->refcnt)
3882 MLX5_ASSERT(mcp_res->rix_flow);
3883 flow_list_destroy(dev, NULL, mcp_res->rix_flow);
3884 mlx5_hlist_remove(priv->mreg_cp_tbl, &mcp_res->hlist_ent);
3885 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], mcp_res->idx);
3886 flow->rix_mreg_copy = 0;
3890 * Start flow in RX_CP_TBL.
3893 * Pointer to Ethernet device.
3895 * Parent flow for wich copying is provided.
3898 * 0 on success, a negative errno value otherwise and rte_errno is set.
3901 flow_mreg_start_copy_action(struct rte_eth_dev *dev,
3902 struct rte_flow *flow)
3904 struct mlx5_flow_mreg_copy_resource *mcp_res;
3905 struct mlx5_priv *priv = dev->data->dev_private;
3908 if (!flow->rix_mreg_copy || flow->copy_applied)
3910 mcp_res = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MCP],
3911 flow->rix_mreg_copy);
3914 if (!mcp_res->appcnt) {
3915 struct rte_flow *mcp_flow = mlx5_ipool_get
3916 (priv->sh->ipool[MLX5_IPOOL_RTE_FLOW],
3920 ret = flow_drv_apply(dev, mcp_flow, NULL);
3926 flow->copy_applied = 1;
3931 * Stop flow in RX_CP_TBL.
3934 * Pointer to Ethernet device.
3936 * Parent flow for wich copying is provided.
3939 flow_mreg_stop_copy_action(struct rte_eth_dev *dev,
3940 struct rte_flow *flow)
3942 struct mlx5_flow_mreg_copy_resource *mcp_res;
3943 struct mlx5_priv *priv = dev->data->dev_private;
3945 if (!flow->rix_mreg_copy || !flow->copy_applied)
3947 mcp_res = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MCP],
3948 flow->rix_mreg_copy);
3951 MLX5_ASSERT(mcp_res->appcnt);
3953 flow->copy_applied = 0;
3954 if (!mcp_res->appcnt) {
3955 struct rte_flow *mcp_flow = mlx5_ipool_get
3956 (priv->sh->ipool[MLX5_IPOOL_RTE_FLOW],
3960 flow_drv_remove(dev, mcp_flow);
3965 * Remove the default copy action from RX_CP_TBL.
3968 * Pointer to Ethernet device.
3971 flow_mreg_del_default_copy_action(struct rte_eth_dev *dev)
3973 struct mlx5_flow_mreg_copy_resource *mcp_res;
3974 struct mlx5_priv *priv = dev->data->dev_private;
3976 /* Check if default flow is registered. */
3977 if (!priv->mreg_cp_tbl)
3979 mcp_res = (void *)mlx5_hlist_lookup(priv->mreg_cp_tbl,
3980 MLX5_DEFAULT_COPY_ID);
3983 MLX5_ASSERT(mcp_res->rix_flow);
3984 flow_list_destroy(dev, NULL, mcp_res->rix_flow);
3985 mlx5_hlist_remove(priv->mreg_cp_tbl, &mcp_res->hlist_ent);
3986 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], mcp_res->idx);
3990 * Add the default copy action in in RX_CP_TBL.
3993 * Pointer to Ethernet device.
3995 * Perform verbose error reporting if not NULL.
3998 * 0 for success, negative value otherwise and rte_errno is set.
4001 flow_mreg_add_default_copy_action(struct rte_eth_dev *dev,
4002 struct rte_flow_error *error)
4004 struct mlx5_priv *priv = dev->data->dev_private;
4005 struct mlx5_flow_mreg_copy_resource *mcp_res;
4007 /* Check whether extensive metadata feature is engaged. */
4008 if (!priv->config.dv_flow_en ||
4009 priv->config.dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
4010 !mlx5_flow_ext_mreg_supported(dev) ||
4011 !priv->sh->dv_regc0_mask)
4013 mcp_res = flow_mreg_add_copy_action(dev, MLX5_DEFAULT_COPY_ID, error);
4020 * Add a flow of copying flow metadata registers in RX_CP_TBL.
4022 * All the flow having Q/RSS action should be split by
4023 * flow_mreg_split_qrss_prep() to pass by RX_CP_TBL. A flow in the RX_CP_TBL
4024 * performs the following,
4025 * - CQE->flow_tag := reg_c[1] (MARK)
4026 * - CQE->flow_table_metadata (reg_b) := reg_c[0] (META)
4027 * As CQE's flow_tag is not a register, it can't be simply copied from reg_c[1]
4028 * but there should be a flow per each MARK ID set by MARK action.
4030 * For the aforementioned reason, if there's a MARK action in flow's action
4031 * list, a corresponding flow should be added to the RX_CP_TBL in order to copy
4032 * the MARK ID to CQE's flow_tag like,
4033 * - If reg_c[1] is mark_id,
4034 * flow_tag := mark_id, reg_b := reg_c[0] and jump to RX_ACT_TBL.
4036 * For SET_META action which stores value in reg_c[0], as the destination is
4037 * also a flow metadata register (reg_b), adding a default flow is enough. Zero
4038 * MARK ID means the default flow. The default flow looks like,
4039 * - For all flow, reg_b := reg_c[0] and jump to RX_ACT_TBL.
4042 * Pointer to Ethernet device.
4044 * Pointer to flow structure.
4045 * @param[in] actions
4046 * Pointer to the list of actions.
4048 * Perform verbose error reporting if not NULL.
4051 * 0 on success, negative value otherwise and rte_errno is set.
4054 flow_mreg_update_copy_table(struct rte_eth_dev *dev,
4055 struct rte_flow *flow,
4056 const struct rte_flow_action *actions,
4057 struct rte_flow_error *error)
4059 struct mlx5_priv *priv = dev->data->dev_private;
4060 struct mlx5_dev_config *config = &priv->config;
4061 struct mlx5_flow_mreg_copy_resource *mcp_res;
4062 const struct rte_flow_action_mark *mark;
4064 /* Check whether extensive metadata feature is engaged. */
4065 if (!config->dv_flow_en ||
4066 config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
4067 !mlx5_flow_ext_mreg_supported(dev) ||
4068 !priv->sh->dv_regc0_mask)
4070 /* Find MARK action. */
4071 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4072 switch (actions->type) {
4073 case RTE_FLOW_ACTION_TYPE_FLAG:
4074 mcp_res = flow_mreg_add_copy_action
4075 (dev, MLX5_FLOW_MARK_DEFAULT, error);
4078 flow->rix_mreg_copy = mcp_res->idx;
4079 if (dev->data->dev_started) {
4081 flow->copy_applied = 1;
4084 case RTE_FLOW_ACTION_TYPE_MARK:
4085 mark = (const struct rte_flow_action_mark *)
4088 flow_mreg_add_copy_action(dev, mark->id, error);
4091 flow->rix_mreg_copy = mcp_res->idx;
4092 if (dev->data->dev_started) {
4094 flow->copy_applied = 1;
4104 #define MLX5_MAX_SPLIT_ACTIONS 24
4105 #define MLX5_MAX_SPLIT_ITEMS 24
4108 * Split the hairpin flow.
4109 * Since HW can't support encap and push-vlan on Rx, we move these
4111 * If the count action is after the encap then we also
4112 * move the count action. in this case the count will also measure
4116 * Pointer to Ethernet device.
4117 * @param[in] actions
4118 * Associated actions (list terminated by the END action).
4119 * @param[out] actions_rx
4121 * @param[out] actions_tx
4123 * @param[out] pattern_tx
4124 * The pattern items for the Tx flow.
4125 * @param[out] flow_id
4126 * The flow ID connected to this flow.
4132 flow_hairpin_split(struct rte_eth_dev *dev,
4133 const struct rte_flow_action actions[],
4134 struct rte_flow_action actions_rx[],
4135 struct rte_flow_action actions_tx[],
4136 struct rte_flow_item pattern_tx[],
4139 struct mlx5_priv *priv = dev->data->dev_private;
4140 const struct rte_flow_action_raw_encap *raw_encap;
4141 const struct rte_flow_action_raw_decap *raw_decap;
4142 struct mlx5_rte_flow_action_set_tag *set_tag;
4143 struct rte_flow_action *tag_action;
4144 struct mlx5_rte_flow_item_tag *tag_item;
4145 struct rte_flow_item *item;
4149 mlx5_flow_id_get(priv->sh->flow_id_pool, flow_id);
4150 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4151 switch (actions->type) {
4152 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
4153 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
4154 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
4155 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
4156 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
4157 rte_memcpy(actions_tx, actions,
4158 sizeof(struct rte_flow_action));
4161 case RTE_FLOW_ACTION_TYPE_COUNT:
4163 rte_memcpy(actions_tx, actions,
4164 sizeof(struct rte_flow_action));
4167 rte_memcpy(actions_rx, actions,
4168 sizeof(struct rte_flow_action));
4172 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
4173 raw_encap = actions->conf;
4174 if (raw_encap->size >
4175 (sizeof(struct rte_flow_item_eth) +
4176 sizeof(struct rte_flow_item_ipv4))) {
4177 memcpy(actions_tx, actions,
4178 sizeof(struct rte_flow_action));
4182 rte_memcpy(actions_rx, actions,
4183 sizeof(struct rte_flow_action));
4187 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
4188 raw_decap = actions->conf;
4189 if (raw_decap->size <
4190 (sizeof(struct rte_flow_item_eth) +
4191 sizeof(struct rte_flow_item_ipv4))) {
4192 memcpy(actions_tx, actions,
4193 sizeof(struct rte_flow_action));
4196 rte_memcpy(actions_rx, actions,
4197 sizeof(struct rte_flow_action));
4202 rte_memcpy(actions_rx, actions,
4203 sizeof(struct rte_flow_action));
4208 /* Add set meta action and end action for the Rx flow. */
4209 tag_action = actions_rx;
4210 tag_action->type = (enum rte_flow_action_type)
4211 MLX5_RTE_FLOW_ACTION_TYPE_TAG;
4213 rte_memcpy(actions_rx, actions, sizeof(struct rte_flow_action));
4215 set_tag = (void *)actions_rx;
4216 set_tag->id = mlx5_flow_get_reg_id(dev, MLX5_HAIRPIN_RX, 0, NULL);
4217 MLX5_ASSERT(set_tag->id > REG_NON);
4218 set_tag->data = *flow_id;
4219 tag_action->conf = set_tag;
4220 /* Create Tx item list. */
4221 rte_memcpy(actions_tx, actions, sizeof(struct rte_flow_action));
4222 addr = (void *)&pattern_tx[2];
4224 item->type = (enum rte_flow_item_type)
4225 MLX5_RTE_FLOW_ITEM_TYPE_TAG;
4226 tag_item = (void *)addr;
4227 tag_item->data = *flow_id;
4228 tag_item->id = mlx5_flow_get_reg_id(dev, MLX5_HAIRPIN_TX, 0, NULL);
4229 MLX5_ASSERT(set_tag->id > REG_NON);
4230 item->spec = tag_item;
4231 addr += sizeof(struct mlx5_rte_flow_item_tag);
4232 tag_item = (void *)addr;
4233 tag_item->data = UINT32_MAX;
4234 tag_item->id = UINT16_MAX;
4235 item->mask = tag_item;
4238 item->type = RTE_FLOW_ITEM_TYPE_END;
4243 union tunnel_offload_mark {
4246 uint32_t app_reserve:8;
4247 uint32_t table_id:15;
4248 uint32_t transfer:1;
4249 uint32_t _unused_:8;
4253 struct tunnel_default_miss_ctx {
4257 struct rte_flow_action_rss action_rss;
4258 struct rte_flow_action_queue miss_queue;
4259 struct rte_flow_action_jump miss_jump;
4265 flow_tunnel_add_default_miss(struct rte_eth_dev *dev,
4266 struct rte_flow *flow,
4267 const struct rte_flow_attr *attr,
4268 const struct rte_flow_action *app_actions,
4270 struct tunnel_default_miss_ctx *ctx,
4271 struct rte_flow_error *error)
4273 struct mlx5_priv *priv = dev->data->dev_private;
4274 struct mlx5_flow *dev_flow;
4275 struct rte_flow_attr miss_attr = *attr;
4276 const struct mlx5_flow_tunnel *tunnel = app_actions[0].conf;
4277 const struct rte_flow_item miss_items[2] = {
4279 .type = RTE_FLOW_ITEM_TYPE_ETH,
4285 .type = RTE_FLOW_ITEM_TYPE_END,
4291 union tunnel_offload_mark mark_id;
4292 struct rte_flow_action_mark miss_mark;
4293 struct rte_flow_action miss_actions[3] = {
4294 [0] = { .type = RTE_FLOW_ACTION_TYPE_MARK, .conf = &miss_mark },
4295 [2] = { .type = RTE_FLOW_ACTION_TYPE_END, .conf = NULL }
4297 const struct rte_flow_action_jump *jump_data;
4298 uint32_t i, flow_table = 0; /* prevent compilation warning */
4299 struct flow_grp_info grp_info = {
4301 .transfer = attr->transfer,
4302 .fdb_def_rule = !!priv->fdb_def_rule,
4307 if (!attr->transfer) {
4310 miss_actions[1].type = RTE_FLOW_ACTION_TYPE_RSS;
4311 q_size = priv->reta_idx_n * sizeof(ctx->queue[0]);
4312 ctx->queue = mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO, q_size,
4315 return rte_flow_error_set
4317 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
4318 NULL, "invalid default miss RSS");
4319 ctx->action_rss.func = RTE_ETH_HASH_FUNCTION_DEFAULT,
4320 ctx->action_rss.level = 0,
4321 ctx->action_rss.types = priv->rss_conf.rss_hf,
4322 ctx->action_rss.key_len = priv->rss_conf.rss_key_len,
4323 ctx->action_rss.queue_num = priv->reta_idx_n,
4324 ctx->action_rss.key = priv->rss_conf.rss_key,
4325 ctx->action_rss.queue = ctx->queue;
4326 if (!priv->reta_idx_n || !priv->rxqs_n)
4327 return rte_flow_error_set
4329 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
4330 NULL, "invalid port configuration");
4331 if (!(dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG))
4332 ctx->action_rss.types = 0;
4333 for (i = 0; i != priv->reta_idx_n; ++i)
4334 ctx->queue[i] = (*priv->reta_idx)[i];
4336 miss_actions[1].type = RTE_FLOW_ACTION_TYPE_JUMP;
4337 ctx->miss_jump.group = MLX5_TNL_MISS_FDB_JUMP_GRP;
4339 miss_actions[1].conf = (typeof(miss_actions[1].conf))ctx->raw;
4340 for (; app_actions->type != RTE_FLOW_ACTION_TYPE_JUMP; app_actions++);
4341 jump_data = app_actions->conf;
4342 miss_attr.priority = MLX5_TNL_MISS_RULE_PRIORITY;
4343 miss_attr.group = jump_data->group;
4344 ret = mlx5_flow_group_to_table(dev, tunnel, jump_data->group,
4345 &flow_table, grp_info, error);
4347 return rte_flow_error_set(error, EINVAL,
4348 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
4349 NULL, "invalid tunnel id");
4350 mark_id.app_reserve = 0;
4351 mark_id.table_id = tunnel_flow_tbl_to_id(flow_table);
4352 mark_id.transfer = !!attr->transfer;
4353 mark_id._unused_ = 0;
4354 miss_mark.id = mark_id.val;
4355 dev_flow = flow_drv_prepare(dev, flow, &miss_attr,
4356 miss_items, miss_actions, flow_idx, error);
4359 dev_flow->flow = flow;
4360 dev_flow->external = true;
4361 dev_flow->tunnel = tunnel;
4362 /* Subflow object was created, we must include one in the list. */
4363 SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
4364 dev_flow->handle, next);
4366 "port %u tunnel type=%d id=%u miss rule priority=%u group=%u",
4367 dev->data->port_id, tunnel->app_tunnel.type,
4368 tunnel->tunnel_id, miss_attr.priority, miss_attr.group);
4369 ret = flow_drv_translate(dev, dev_flow, &miss_attr, miss_items,
4370 miss_actions, error);
4372 ret = flow_mreg_update_copy_table(dev, flow, miss_actions,
4379 * The last stage of splitting chain, just creates the subflow
4380 * without any modification.
4383 * Pointer to Ethernet device.
4385 * Parent flow structure pointer.
4386 * @param[in, out] sub_flow
4387 * Pointer to return the created subflow, may be NULL.
4388 * @param[in] prefix_layers
4389 * Prefix subflow layers, may be 0.
4390 * @param[in] prefix_mark
4391 * Prefix subflow mark flag, may be 0.
4393 * Flow rule attributes.
4395 * Pattern specification (list terminated by the END pattern item).
4396 * @param[in] actions
4397 * Associated actions (list terminated by the END action).
4398 * @param[in] external
4399 * This flow rule is created by request external to PMD.
4400 * @param[in] flow_idx
4401 * This memory pool index to the flow.
4403 * Perform verbose error reporting if not NULL.
4405 * 0 on success, negative value otherwise
4408 flow_create_split_inner(struct rte_eth_dev *dev,
4409 struct rte_flow *flow,
4410 struct mlx5_flow **sub_flow,
4411 uint64_t prefix_layers,
4412 uint32_t prefix_mark,
4413 const struct rte_flow_attr *attr,
4414 const struct rte_flow_item items[],
4415 const struct rte_flow_action actions[],
4416 bool external, uint32_t flow_idx,
4417 struct rte_flow_error *error)
4419 struct mlx5_flow *dev_flow;
4421 dev_flow = flow_drv_prepare(dev, flow, attr, items, actions,
4425 dev_flow->flow = flow;
4426 dev_flow->external = external;
4427 /* Subflow object was created, we must include one in the list. */
4428 SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
4429 dev_flow->handle, next);
4431 * If dev_flow is as one of the suffix flow, some actions in suffix
4432 * flow may need some user defined item layer flags, and pass the
4433 * Metadate rxq mark flag to suffix flow as well.
4436 dev_flow->handle->layers = prefix_layers;
4438 dev_flow->handle->mark = 1;
4440 *sub_flow = dev_flow;
4441 return flow_drv_translate(dev, dev_flow, attr, items, actions, error);
4445 * Split the meter flow.
4447 * As meter flow will split to three sub flow, other than meter
4448 * action, the other actions make sense to only meter accepts
4449 * the packet. If it need to be dropped, no other additional
4450 * actions should be take.
4452 * One kind of special action which decapsulates the L3 tunnel
4453 * header will be in the prefix sub flow, as not to take the
4454 * L3 tunnel header into account.
4457 * Pointer to Ethernet device.
4459 * Pattern specification (list terminated by the END pattern item).
4460 * @param[out] sfx_items
4461 * Suffix flow match items (list terminated by the END pattern item).
4462 * @param[in] actions
4463 * Associated actions (list terminated by the END action).
4464 * @param[out] actions_sfx
4465 * Suffix flow actions.
4466 * @param[out] actions_pre
4467 * Prefix flow actions.
4468 * @param[out] pattern_sfx
4469 * The pattern items for the suffix flow.
4470 * @param[out] tag_sfx
4471 * Pointer to suffix flow tag.
4477 flow_meter_split_prep(struct rte_eth_dev *dev,
4478 const struct rte_flow_item items[],
4479 struct rte_flow_item sfx_items[],
4480 const struct rte_flow_action actions[],
4481 struct rte_flow_action actions_sfx[],
4482 struct rte_flow_action actions_pre[])
4484 struct rte_flow_action *tag_action = NULL;
4485 struct rte_flow_item *tag_item;
4486 struct mlx5_rte_flow_action_set_tag *set_tag;
4487 struct rte_flow_error error;
4488 const struct rte_flow_action_raw_encap *raw_encap;
4489 const struct rte_flow_action_raw_decap *raw_decap;
4490 struct mlx5_rte_flow_item_tag *tag_spec;
4491 struct mlx5_rte_flow_item_tag *tag_mask;
4493 bool copy_vlan = false;
4495 /* Prepare the actions for prefix and suffix flow. */
4496 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4497 struct rte_flow_action **action_cur = NULL;
4499 switch (actions->type) {
4500 case RTE_FLOW_ACTION_TYPE_METER:
4501 /* Add the extra tag action first. */
4502 tag_action = actions_pre;
4503 tag_action->type = (enum rte_flow_action_type)
4504 MLX5_RTE_FLOW_ACTION_TYPE_TAG;
4506 action_cur = &actions_pre;
4508 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
4509 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
4510 action_cur = &actions_pre;
4512 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
4513 raw_encap = actions->conf;
4514 if (raw_encap->size < MLX5_ENCAPSULATION_DECISION_SIZE)
4515 action_cur = &actions_pre;
4517 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
4518 raw_decap = actions->conf;
4519 if (raw_decap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
4520 action_cur = &actions_pre;
4522 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
4523 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
4530 action_cur = &actions_sfx;
4531 memcpy(*action_cur, actions, sizeof(struct rte_flow_action));
4534 /* Add end action to the actions. */
4535 actions_sfx->type = RTE_FLOW_ACTION_TYPE_END;
4536 actions_pre->type = RTE_FLOW_ACTION_TYPE_END;
4539 set_tag = (void *)actions_pre;
4540 set_tag->id = mlx5_flow_get_reg_id(dev, MLX5_MTR_SFX, 0, &error);
4542 * Get the id from the qrss_pool to make qrss share the id with meter.
4544 tag_id = flow_qrss_get_id(dev);
4545 set_tag->data = tag_id << MLX5_MTR_COLOR_BITS;
4547 tag_action->conf = set_tag;
4548 /* Prepare the suffix subflow items. */
4549 tag_item = sfx_items++;
4550 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
4551 int item_type = items->type;
4553 switch (item_type) {
4554 case RTE_FLOW_ITEM_TYPE_PORT_ID:
4555 memcpy(sfx_items, items, sizeof(*sfx_items));
4558 case RTE_FLOW_ITEM_TYPE_VLAN:
4560 memcpy(sfx_items, items, sizeof(*sfx_items));
4562 * Convert to internal match item, it is used
4563 * for vlan push and set vid.
4565 sfx_items->type = (enum rte_flow_item_type)
4566 MLX5_RTE_FLOW_ITEM_TYPE_VLAN;
4574 sfx_items->type = RTE_FLOW_ITEM_TYPE_END;
4576 tag_spec = (struct mlx5_rte_flow_item_tag *)sfx_items;
4577 tag_spec->data = tag_id << MLX5_MTR_COLOR_BITS;
4578 tag_spec->id = mlx5_flow_get_reg_id(dev, MLX5_MTR_SFX, 0, &error);
4579 tag_mask = tag_spec + 1;
4580 tag_mask->data = 0xffffff00;
4581 tag_item->type = (enum rte_flow_item_type)
4582 MLX5_RTE_FLOW_ITEM_TYPE_TAG;
4583 tag_item->spec = tag_spec;
4584 tag_item->last = NULL;
4585 tag_item->mask = tag_mask;
4590 * Split action list having QUEUE/RSS for metadata register copy.
4592 * Once Q/RSS action is detected in user's action list, the flow action
4593 * should be split in order to copy metadata registers, which will happen in
4595 * - CQE->flow_tag := reg_c[1] (MARK)
4596 * - CQE->flow_table_metadata (reg_b) := reg_c[0] (META)
4597 * The Q/RSS action will be performed on RX_ACT_TBL after passing by RX_CP_TBL.
4598 * This is because the last action of each flow must be a terminal action
4599 * (QUEUE, RSS or DROP).
4601 * Flow ID must be allocated to identify actions in the RX_ACT_TBL and it is
4602 * stored and kept in the mlx5_flow structure per each sub_flow.
4604 * The Q/RSS action is replaced with,
4605 * - SET_TAG, setting the allocated flow ID to reg_c[2].
4606 * And the following JUMP action is added at the end,
4607 * - JUMP, to RX_CP_TBL.
4609 * A flow to perform remained Q/RSS action will be created in RX_ACT_TBL by
4610 * flow_create_split_metadata() routine. The flow will look like,
4611 * - If flow ID matches (reg_c[2]), perform Q/RSS.
4614 * Pointer to Ethernet device.
4615 * @param[out] split_actions
4616 * Pointer to store split actions to jump to CP_TBL.
4617 * @param[in] actions
4618 * Pointer to the list of original flow actions.
4620 * Pointer to the Q/RSS action.
4621 * @param[in] actions_n
4622 * Number of original actions.
4624 * Perform verbose error reporting if not NULL.
4627 * non-zero unique flow_id on success, otherwise 0 and
4628 * error/rte_error are set.
4631 flow_mreg_split_qrss_prep(struct rte_eth_dev *dev,
4632 struct rte_flow_action *split_actions,
4633 const struct rte_flow_action *actions,
4634 const struct rte_flow_action *qrss,
4635 int actions_n, struct rte_flow_error *error)
4637 struct mlx5_rte_flow_action_set_tag *set_tag;
4638 struct rte_flow_action_jump *jump;
4639 const int qrss_idx = qrss - actions;
4640 uint32_t flow_id = 0;
4644 * Given actions will be split
4645 * - Replace QUEUE/RSS action with SET_TAG to set flow ID.
4646 * - Add jump to mreg CP_TBL.
4647 * As a result, there will be one more action.
4650 memcpy(split_actions, actions, sizeof(*split_actions) * actions_n);
4651 set_tag = (void *)(split_actions + actions_n);
4653 * If tag action is not set to void(it means we are not the meter
4654 * suffix flow), add the tag action. Since meter suffix flow already
4655 * has the tag added.
4657 if (split_actions[qrss_idx].type != RTE_FLOW_ACTION_TYPE_VOID) {
4659 * Allocate the new subflow ID. This one is unique within
4660 * device and not shared with representors. Otherwise,
4661 * we would have to resolve multi-thread access synch
4662 * issue. Each flow on the shared device is appended
4663 * with source vport identifier, so the resulting
4664 * flows will be unique in the shared (by master and
4665 * representors) domain even if they have coinciding
4668 flow_id = flow_qrss_get_id(dev);
4670 return rte_flow_error_set(error, ENOMEM,
4671 RTE_FLOW_ERROR_TYPE_ACTION,
4672 NULL, "can't allocate id "
4673 "for split Q/RSS subflow");
4674 /* Internal SET_TAG action to set flow ID. */
4675 *set_tag = (struct mlx5_rte_flow_action_set_tag){
4678 ret = mlx5_flow_get_reg_id(dev, MLX5_COPY_MARK, 0, error);
4682 /* Construct new actions array. */
4683 /* Replace QUEUE/RSS action. */
4684 split_actions[qrss_idx] = (struct rte_flow_action){
4685 .type = (enum rte_flow_action_type)
4686 MLX5_RTE_FLOW_ACTION_TYPE_TAG,
4690 /* JUMP action to jump to mreg copy table (CP_TBL). */
4691 jump = (void *)(set_tag + 1);
4692 *jump = (struct rte_flow_action_jump){
4693 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
4695 split_actions[actions_n - 2] = (struct rte_flow_action){
4696 .type = RTE_FLOW_ACTION_TYPE_JUMP,
4699 split_actions[actions_n - 1] = (struct rte_flow_action){
4700 .type = RTE_FLOW_ACTION_TYPE_END,
4706 * Extend the given action list for Tx metadata copy.
4708 * Copy the given action list to the ext_actions and add flow metadata register
4709 * copy action in order to copy reg_a set by WQE to reg_c[0].
4711 * @param[out] ext_actions
4712 * Pointer to the extended action list.
4713 * @param[in] actions
4714 * Pointer to the list of actions.
4715 * @param[in] actions_n
4716 * Number of actions in the list.
4718 * Perform verbose error reporting if not NULL.
4719 * @param[in] encap_idx
4720 * The encap action inndex.
4723 * 0 on success, negative value otherwise
4726 flow_mreg_tx_copy_prep(struct rte_eth_dev *dev,
4727 struct rte_flow_action *ext_actions,
4728 const struct rte_flow_action *actions,
4729 int actions_n, struct rte_flow_error *error,
4732 struct mlx5_flow_action_copy_mreg *cp_mreg =
4733 (struct mlx5_flow_action_copy_mreg *)
4734 (ext_actions + actions_n + 1);
4737 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_RX, 0, error);
4741 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_TX, 0, error);
4746 memcpy(ext_actions, actions, sizeof(*ext_actions) * encap_idx);
4747 if (encap_idx == actions_n - 1) {
4748 ext_actions[actions_n - 1] = (struct rte_flow_action){
4749 .type = (enum rte_flow_action_type)
4750 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
4753 ext_actions[actions_n] = (struct rte_flow_action){
4754 .type = RTE_FLOW_ACTION_TYPE_END,
4757 ext_actions[encap_idx] = (struct rte_flow_action){
4758 .type = (enum rte_flow_action_type)
4759 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
4762 memcpy(ext_actions + encap_idx + 1, actions + encap_idx,
4763 sizeof(*ext_actions) * (actions_n - encap_idx));
4769 * Check the match action from the action list.
4771 * @param[in] actions
4772 * Pointer to the list of actions.
4774 * Flow rule attributes.
4776 * The action to be check if exist.
4777 * @param[out] match_action_pos
4778 * Pointer to the position of the matched action if exists, otherwise is -1.
4779 * @param[out] qrss_action_pos
4780 * Pointer to the position of the Queue/RSS action if exists, otherwise is -1.
4783 * > 0 the total number of actions.
4784 * 0 if not found match action in action list.
4787 flow_check_match_action(const struct rte_flow_action actions[],
4788 const struct rte_flow_attr *attr,
4789 enum rte_flow_action_type action,
4790 int *match_action_pos, int *qrss_action_pos)
4792 const struct rte_flow_action_sample *sample;
4799 *match_action_pos = -1;
4800 *qrss_action_pos = -1;
4801 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4802 if (actions->type == action) {
4804 *match_action_pos = actions_n;
4806 if (actions->type == RTE_FLOW_ACTION_TYPE_QUEUE ||
4807 actions->type == RTE_FLOW_ACTION_TYPE_RSS)
4808 *qrss_action_pos = actions_n;
4809 if (actions->type == RTE_FLOW_ACTION_TYPE_JUMP)
4811 if (actions->type == RTE_FLOW_ACTION_TYPE_SAMPLE) {
4812 sample = actions->conf;
4813 ratio = sample->ratio;
4814 sub_type = ((const struct rte_flow_action *)
4815 (sample->actions))->type;
4819 if (flag && action == RTE_FLOW_ACTION_TYPE_SAMPLE && attr->transfer) {
4821 /* JUMP Action not support for Mirroring;
4822 * Mirroring support multi-destination;
4824 if (!jump_flag && sub_type != RTE_FLOW_ACTION_TYPE_END)
4828 /* Count RTE_FLOW_ACTION_TYPE_END. */
4829 return flag ? actions_n + 1 : 0;
4832 #define SAMPLE_SUFFIX_ITEM 2
4835 * Split the sample flow.
4837 * As sample flow will split to two sub flow, sample flow with
4838 * sample action, the other actions will move to new suffix flow.
4840 * Also add unique tag id with tag action in the sample flow,
4841 * the same tag id will be as match in the suffix flow.
4844 * Pointer to Ethernet device.
4846 * FDB egress flow flag.
4847 * @param[out] sfx_items
4848 * Suffix flow match items (list terminated by the END pattern item).
4849 * @param[in] actions
4850 * Associated actions (list terminated by the END action).
4851 * @param[out] actions_sfx
4852 * Suffix flow actions.
4853 * @param[out] actions_pre
4854 * Prefix flow actions.
4855 * @param[in] actions_n
4856 * The total number of actions.
4857 * @param[in] sample_action_pos
4858 * The sample action position.
4859 * @param[in] qrss_action_pos
4860 * The Queue/RSS action position.
4862 * Perform verbose error reporting if not NULL.
4865 * 0 on success, or unique flow_id, a negative errno value
4866 * otherwise and rte_errno is set.
4869 flow_sample_split_prep(struct rte_eth_dev *dev,
4871 struct rte_flow_item sfx_items[],
4872 const struct rte_flow_action actions[],
4873 struct rte_flow_action actions_sfx[],
4874 struct rte_flow_action actions_pre[],
4876 int sample_action_pos,
4877 int qrss_action_pos,
4878 struct rte_flow_error *error)
4880 struct mlx5_rte_flow_action_set_tag *set_tag;
4881 struct mlx5_rte_flow_item_tag *tag_spec;
4882 struct mlx5_rte_flow_item_tag *tag_mask;
4883 uint32_t tag_id = 0;
4887 if (sample_action_pos < 0)
4888 return rte_flow_error_set(error, EINVAL,
4889 RTE_FLOW_ERROR_TYPE_ACTION,
4890 NULL, "invalid position of sample "
4893 /* Prepare the prefix tag action. */
4894 set_tag = (void *)(actions_pre + actions_n + 1);
4895 ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, 0, error);
4899 tag_id = flow_qrss_get_id(dev);
4900 set_tag->data = tag_id;
4901 /* Prepare the suffix subflow items. */
4902 tag_spec = (void *)(sfx_items + SAMPLE_SUFFIX_ITEM);
4903 tag_spec->data = tag_id;
4904 tag_spec->id = set_tag->id;
4905 tag_mask = tag_spec + 1;
4906 tag_mask->data = UINT32_MAX;
4907 sfx_items[0] = (struct rte_flow_item){
4908 .type = (enum rte_flow_item_type)
4909 MLX5_RTE_FLOW_ITEM_TYPE_TAG,
4914 sfx_items[1] = (struct rte_flow_item){
4915 .type = (enum rte_flow_item_type)
4916 RTE_FLOW_ITEM_TYPE_END,
4919 /* Prepare the actions for prefix and suffix flow. */
4920 if (qrss_action_pos >= 0 && qrss_action_pos < sample_action_pos) {
4921 index = qrss_action_pos;
4922 /* Put the preceding the Queue/RSS action into prefix flow. */
4924 memcpy(actions_pre, actions,
4925 sizeof(struct rte_flow_action) * index);
4926 /* Put others preceding the sample action into prefix flow. */
4927 if (sample_action_pos > index + 1)
4928 memcpy(actions_pre + index, actions + index + 1,
4929 sizeof(struct rte_flow_action) *
4930 (sample_action_pos - index - 1));
4931 index = sample_action_pos - 1;
4932 /* Put Queue/RSS action into Suffix flow. */
4933 memcpy(actions_sfx, actions + qrss_action_pos,
4934 sizeof(struct rte_flow_action));
4937 index = sample_action_pos;
4939 memcpy(actions_pre, actions,
4940 sizeof(struct rte_flow_action) * index);
4942 /* Add the extra tag action for NIC-RX and E-Switch ingress. */
4944 actions_pre[index++] =
4945 (struct rte_flow_action){
4946 .type = (enum rte_flow_action_type)
4947 MLX5_RTE_FLOW_ACTION_TYPE_TAG,
4951 memcpy(actions_pre + index, actions + sample_action_pos,
4952 sizeof(struct rte_flow_action));
4954 actions_pre[index] = (struct rte_flow_action){
4955 .type = (enum rte_flow_action_type)
4956 RTE_FLOW_ACTION_TYPE_END,
4958 /* Put the actions after sample into Suffix flow. */
4959 memcpy(actions_sfx, actions + sample_action_pos + 1,
4960 sizeof(struct rte_flow_action) *
4961 (actions_n - sample_action_pos - 1));
4966 * The splitting for metadata feature.
4968 * - Q/RSS action on NIC Rx should be split in order to pass by
4969 * the mreg copy table (RX_CP_TBL) and then it jumps to the
4970 * action table (RX_ACT_TBL) which has the split Q/RSS action.
4972 * - All the actions on NIC Tx should have a mreg copy action to
4973 * copy reg_a from WQE to reg_c[0].
4976 * Pointer to Ethernet device.
4978 * Parent flow structure pointer.
4979 * @param[in] prefix_layers
4980 * Prefix flow layer flags.
4981 * @param[in] prefix_mark
4982 * Prefix subflow mark flag, may be 0.
4984 * Flow rule attributes.
4986 * Pattern specification (list terminated by the END pattern item).
4987 * @param[in] actions
4988 * Associated actions (list terminated by the END action).
4989 * @param[in] external
4990 * This flow rule is created by request external to PMD.
4991 * @param[in] flow_idx
4992 * This memory pool index to the flow.
4994 * Perform verbose error reporting if not NULL.
4996 * 0 on success, negative value otherwise
4999 flow_create_split_metadata(struct rte_eth_dev *dev,
5000 struct rte_flow *flow,
5001 uint64_t prefix_layers,
5002 uint32_t prefix_mark,
5003 const struct rte_flow_attr *attr,
5004 const struct rte_flow_item items[],
5005 const struct rte_flow_action actions[],
5006 bool external, uint32_t flow_idx,
5007 struct rte_flow_error *error)
5009 struct mlx5_priv *priv = dev->data->dev_private;
5010 struct mlx5_dev_config *config = &priv->config;
5011 const struct rte_flow_action *qrss = NULL;
5012 struct rte_flow_action *ext_actions = NULL;
5013 struct mlx5_flow *dev_flow = NULL;
5014 uint32_t qrss_id = 0;
5021 /* Check whether extensive metadata feature is engaged. */
5022 if (!config->dv_flow_en ||
5023 config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
5024 !mlx5_flow_ext_mreg_supported(dev))
5025 return flow_create_split_inner(dev, flow, NULL, prefix_layers,
5026 prefix_mark, attr, items,
5027 actions, external, flow_idx,
5029 actions_n = flow_parse_metadata_split_actions_info(actions, &qrss,
5032 /* Exclude hairpin flows from splitting. */
5033 if (qrss->type == RTE_FLOW_ACTION_TYPE_QUEUE) {
5034 const struct rte_flow_action_queue *queue;
5037 if (mlx5_rxq_get_type(dev, queue->index) ==
5038 MLX5_RXQ_TYPE_HAIRPIN)
5040 } else if (qrss->type == RTE_FLOW_ACTION_TYPE_RSS) {
5041 const struct rte_flow_action_rss *rss;
5044 if (mlx5_rxq_get_type(dev, rss->queue[0]) ==
5045 MLX5_RXQ_TYPE_HAIRPIN)
5050 /* Check if it is in meter suffix table. */
5051 mtr_sfx = attr->group == (attr->transfer ?
5052 (MLX5_FLOW_TABLE_LEVEL_SUFFIX - 1) :
5053 MLX5_FLOW_TABLE_LEVEL_SUFFIX);
5055 * Q/RSS action on NIC Rx should be split in order to pass by
5056 * the mreg copy table (RX_CP_TBL) and then it jumps to the
5057 * action table (RX_ACT_TBL) which has the split Q/RSS action.
5059 act_size = sizeof(struct rte_flow_action) * (actions_n + 1) +
5060 sizeof(struct rte_flow_action_set_tag) +
5061 sizeof(struct rte_flow_action_jump);
5062 ext_actions = mlx5_malloc(MLX5_MEM_ZERO, act_size, 0,
5065 return rte_flow_error_set(error, ENOMEM,
5066 RTE_FLOW_ERROR_TYPE_ACTION,
5067 NULL, "no memory to split "
5070 * If we are the suffix flow of meter, tag already exist.
5071 * Set the tag action to void.
5074 ext_actions[qrss - actions].type =
5075 RTE_FLOW_ACTION_TYPE_VOID;
5077 ext_actions[qrss - actions].type =
5078 (enum rte_flow_action_type)
5079 MLX5_RTE_FLOW_ACTION_TYPE_TAG;
5081 * Create the new actions list with removed Q/RSS action
5082 * and appended set tag and jump to register copy table
5083 * (RX_CP_TBL). We should preallocate unique tag ID here
5084 * in advance, because it is needed for set tag action.
5086 qrss_id = flow_mreg_split_qrss_prep(dev, ext_actions, actions,
5087 qrss, actions_n, error);
5088 if (!mtr_sfx && !qrss_id) {
5092 } else if (attr->egress && !attr->transfer) {
5094 * All the actions on NIC Tx should have a metadata register
5095 * copy action to copy reg_a from WQE to reg_c[meta]
5097 act_size = sizeof(struct rte_flow_action) * (actions_n + 1) +
5098 sizeof(struct mlx5_flow_action_copy_mreg);
5099 ext_actions = mlx5_malloc(MLX5_MEM_ZERO, act_size, 0,
5102 return rte_flow_error_set(error, ENOMEM,
5103 RTE_FLOW_ERROR_TYPE_ACTION,
5104 NULL, "no memory to split "
5106 /* Create the action list appended with copy register. */
5107 ret = flow_mreg_tx_copy_prep(dev, ext_actions, actions,
5108 actions_n, error, encap_idx);
5112 /* Add the unmodified original or prefix subflow. */
5113 ret = flow_create_split_inner(dev, flow, &dev_flow, prefix_layers,
5115 items, ext_actions ? ext_actions :
5116 actions, external, flow_idx, error);
5119 MLX5_ASSERT(dev_flow);
5121 const struct rte_flow_attr q_attr = {
5122 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
5125 /* Internal PMD action to set register. */
5126 struct mlx5_rte_flow_item_tag q_tag_spec = {
5130 struct rte_flow_item q_items[] = {
5132 .type = (enum rte_flow_item_type)
5133 MLX5_RTE_FLOW_ITEM_TYPE_TAG,
5134 .spec = &q_tag_spec,
5139 .type = RTE_FLOW_ITEM_TYPE_END,
5142 struct rte_flow_action q_actions[] = {
5148 .type = RTE_FLOW_ACTION_TYPE_END,
5151 uint64_t layers = flow_get_prefix_layer_flags(dev_flow);
5154 * Configure the tag item only if there is no meter subflow.
5155 * Since tag is already marked in the meter suffix subflow
5156 * we can just use the meter suffix items as is.
5159 /* Not meter subflow. */
5160 MLX5_ASSERT(!mtr_sfx);
5162 * Put unique id in prefix flow due to it is destroyed
5163 * after suffix flow and id will be freed after there
5164 * is no actual flows with this id and identifier
5165 * reallocation becomes possible (for example, for
5166 * other flows in other threads).
5168 dev_flow->handle->split_flow_id = qrss_id;
5169 ret = mlx5_flow_get_reg_id(dev, MLX5_COPY_MARK, 0,
5173 q_tag_spec.id = ret;
5176 /* Add suffix subflow to execute Q/RSS. */
5177 ret = flow_create_split_inner(dev, flow, &dev_flow, layers, 0,
5178 &q_attr, mtr_sfx ? items :
5180 external, flow_idx, error);
5183 /* qrss ID should be freed if failed. */
5185 MLX5_ASSERT(dev_flow);
5190 * We do not destroy the partially created sub_flows in case of error.
5191 * These ones are included into parent flow list and will be destroyed
5192 * by flow_drv_destroy.
5194 flow_qrss_free_id(dev, qrss_id);
5195 mlx5_free(ext_actions);
5200 * The splitting for meter feature.
5202 * - The meter flow will be split to two flows as prefix and
5203 * suffix flow. The packets make sense only it pass the prefix
5206 * - Reg_C_5 is used for the packet to match betweend prefix and
5210 * Pointer to Ethernet device.
5212 * Parent flow structure pointer.
5213 * @param[in] prefix_layers
5214 * Prefix subflow layers, may be 0.
5215 * @param[in] prefix_mark
5216 * Prefix subflow mark flag, may be 0.
5218 * Flow rule attributes.
5220 * Pattern specification (list terminated by the END pattern item).
5221 * @param[in] actions
5222 * Associated actions (list terminated by the END action).
5223 * @param[in] external
5224 * This flow rule is created by request external to PMD.
5225 * @param[in] flow_idx
5226 * This memory pool index to the flow.
5228 * Perform verbose error reporting if not NULL.
5230 * 0 on success, negative value otherwise
5233 flow_create_split_meter(struct rte_eth_dev *dev,
5234 struct rte_flow *flow,
5235 uint64_t prefix_layers,
5236 uint32_t prefix_mark,
5237 const struct rte_flow_attr *attr,
5238 const struct rte_flow_item items[],
5239 const struct rte_flow_action actions[],
5240 bool external, uint32_t flow_idx,
5241 struct rte_flow_error *error)
5243 struct mlx5_priv *priv = dev->data->dev_private;
5244 struct rte_flow_action *sfx_actions = NULL;
5245 struct rte_flow_action *pre_actions = NULL;
5246 struct rte_flow_item *sfx_items = NULL;
5247 struct mlx5_flow *dev_flow = NULL;
5248 struct rte_flow_attr sfx_attr = *attr;
5250 uint32_t mtr_tag_id = 0;
5257 actions_n = flow_check_meter_action(actions, &mtr);
5259 /* The five prefix actions: meter, decap, encap, tag, end. */
5260 act_size = sizeof(struct rte_flow_action) * (actions_n + 5) +
5261 sizeof(struct mlx5_rte_flow_action_set_tag);
5262 /* tag, vlan, port id, end. */
5263 #define METER_SUFFIX_ITEM 4
5264 item_size = sizeof(struct rte_flow_item) * METER_SUFFIX_ITEM +
5265 sizeof(struct mlx5_rte_flow_item_tag) * 2;
5266 sfx_actions = mlx5_malloc(MLX5_MEM_ZERO, (act_size + item_size),
5269 return rte_flow_error_set(error, ENOMEM,
5270 RTE_FLOW_ERROR_TYPE_ACTION,
5271 NULL, "no memory to split "
5273 sfx_items = (struct rte_flow_item *)((char *)sfx_actions +
5275 pre_actions = sfx_actions + actions_n;
5276 mtr_tag_id = flow_meter_split_prep(dev, items, sfx_items,
5277 actions, sfx_actions,
5283 /* Add the prefix subflow. */
5284 ret = flow_create_split_inner(dev, flow, &dev_flow,
5287 pre_actions, external,
5293 dev_flow->handle->split_flow_id = mtr_tag_id;
5294 /* Setting the sfx group atrr. */
5295 sfx_attr.group = sfx_attr.transfer ?
5296 (MLX5_FLOW_TABLE_LEVEL_SUFFIX - 1) :
5297 MLX5_FLOW_TABLE_LEVEL_SUFFIX;
5299 /* Add the prefix subflow. */
5300 ret = flow_create_split_metadata(dev, flow, dev_flow ?
5301 flow_get_prefix_layer_flags(dev_flow) :
5302 prefix_layers, dev_flow ?
5303 dev_flow->handle->mark : prefix_mark,
5304 &sfx_attr, sfx_items ?
5306 sfx_actions ? sfx_actions : actions,
5307 external, flow_idx, error);
5310 mlx5_free(sfx_actions);
5315 * The splitting for sample feature.
5317 * Once Sample action is detected in the action list, the flow actions should
5318 * be split into prefix sub flow and suffix sub flow.
5320 * The original items remain in the prefix sub flow, all actions preceding the
5321 * sample action and the sample action itself will be copied to the prefix
5322 * sub flow, the actions following the sample action will be copied to the
5323 * suffix sub flow, Queue action always be located in the suffix sub flow.
5325 * In order to make the packet from prefix sub flow matches with suffix sub
5326 * flow, an extra tag action be added into prefix sub flow, and the suffix sub
5327 * flow uses tag item with the unique flow id.
5330 * Pointer to Ethernet device.
5332 * Parent flow structure pointer.
5334 * Flow rule attributes.
5336 * Pattern specification (list terminated by the END pattern item).
5337 * @param[in] actions
5338 * Associated actions (list terminated by the END action).
5339 * @param[in] external
5340 * This flow rule is created by request external to PMD.
5341 * @param[in] flow_idx
5342 * This memory pool index to the flow.
5344 * Perform verbose error reporting if not NULL.
5346 * 0 on success, negative value otherwise
5349 flow_create_split_sample(struct rte_eth_dev *dev,
5350 struct rte_flow *flow,
5351 const struct rte_flow_attr *attr,
5352 const struct rte_flow_item items[],
5353 const struct rte_flow_action actions[],
5354 bool external, uint32_t flow_idx,
5355 struct rte_flow_error *error)
5357 struct mlx5_priv *priv = dev->data->dev_private;
5358 struct rte_flow_action *sfx_actions = NULL;
5359 struct rte_flow_action *pre_actions = NULL;
5360 struct rte_flow_item *sfx_items = NULL;
5361 struct mlx5_flow *dev_flow = NULL;
5362 struct rte_flow_attr sfx_attr = *attr;
5363 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
5364 struct mlx5_flow_dv_sample_resource *sample_res;
5365 struct mlx5_flow_tbl_data_entry *sfx_tbl_data;
5366 struct mlx5_flow_tbl_resource *sfx_tbl;
5367 union mlx5_flow_tbl_key sfx_table_key;
5371 uint32_t fdb_tx = 0;
5374 int sample_action_pos;
5375 int qrss_action_pos;
5378 if (priv->sampler_en)
5379 actions_n = flow_check_match_action(actions, attr,
5380 RTE_FLOW_ACTION_TYPE_SAMPLE,
5381 &sample_action_pos, &qrss_action_pos);
5383 /* The prefix actions must includes sample, tag, end. */
5384 act_size = sizeof(struct rte_flow_action) * (actions_n * 2 + 1)
5385 + sizeof(struct mlx5_rte_flow_action_set_tag);
5386 item_size = sizeof(struct rte_flow_item) * SAMPLE_SUFFIX_ITEM +
5387 sizeof(struct mlx5_rte_flow_item_tag) * 2;
5388 sfx_actions = mlx5_malloc(MLX5_MEM_ZERO, (act_size +
5389 item_size), 0, SOCKET_ID_ANY);
5391 return rte_flow_error_set(error, ENOMEM,
5392 RTE_FLOW_ERROR_TYPE_ACTION,
5393 NULL, "no memory to split "
5395 /* The representor_id is -1 for uplink. */
5396 fdb_tx = (attr->transfer && priv->representor_id != -1);
5398 sfx_items = (struct rte_flow_item *)((char *)sfx_actions
5400 pre_actions = sfx_actions + actions_n;
5401 tag_id = flow_sample_split_prep(dev, fdb_tx, sfx_items,
5402 actions, sfx_actions,
5403 pre_actions, actions_n,
5405 qrss_action_pos, error);
5406 if (tag_id < 0 || (!fdb_tx && !tag_id)) {
5410 /* Add the prefix subflow. */
5411 ret = flow_create_split_inner(dev, flow, &dev_flow, 0, 0, attr,
5412 items, pre_actions, external,
5418 dev_flow->handle->split_flow_id = tag_id;
5419 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
5420 /* Set the sfx group attr. */
5421 sample_res = (struct mlx5_flow_dv_sample_resource *)
5422 dev_flow->dv.sample_res;
5423 sfx_tbl = (struct mlx5_flow_tbl_resource *)
5424 sample_res->normal_path_tbl;
5425 sfx_tbl_data = container_of(sfx_tbl,
5426 struct mlx5_flow_tbl_data_entry, tbl);
5427 sfx_table_key.v64 = sfx_tbl_data->entry.key;
5428 sfx_attr.group = sfx_attr.transfer ?
5429 (sfx_table_key.table_id - 1) :
5430 sfx_table_key.table_id;
5433 /* Add the suffix subflow. */
5434 ret = flow_create_split_meter(dev, flow, dev_flow ?
5435 flow_get_prefix_layer_flags(dev_flow) : 0,
5436 dev_flow ? dev_flow->handle->mark : 0,
5437 &sfx_attr, sfx_items ? sfx_items : items,
5438 sfx_actions ? sfx_actions : actions,
5439 external, flow_idx, error);
5442 mlx5_free(sfx_actions);
5447 * Split the flow to subflow set. The splitters might be linked
5448 * in the chain, like this:
5449 * flow_create_split_outer() calls:
5450 * flow_create_split_meter() calls:
5451 * flow_create_split_metadata(meter_subflow_0) calls:
5452 * flow_create_split_inner(metadata_subflow_0)
5453 * flow_create_split_inner(metadata_subflow_1)
5454 * flow_create_split_inner(metadata_subflow_2)
5455 * flow_create_split_metadata(meter_subflow_1) calls:
5456 * flow_create_split_inner(metadata_subflow_0)
5457 * flow_create_split_inner(metadata_subflow_1)
5458 * flow_create_split_inner(metadata_subflow_2)
5460 * This provide flexible way to add new levels of flow splitting.
5461 * The all of successfully created subflows are included to the
5462 * parent flow dev_flow list.
5465 * Pointer to Ethernet device.
5467 * Parent flow structure pointer.
5469 * Flow rule attributes.
5471 * Pattern specification (list terminated by the END pattern item).
5472 * @param[in] actions
5473 * Associated actions (list terminated by the END action).
5474 * @param[in] external
5475 * This flow rule is created by request external to PMD.
5476 * @param[in] flow_idx
5477 * This memory pool index to the flow.
5479 * Perform verbose error reporting if not NULL.
5481 * 0 on success, negative value otherwise
5484 flow_create_split_outer(struct rte_eth_dev *dev,
5485 struct rte_flow *flow,
5486 const struct rte_flow_attr *attr,
5487 const struct rte_flow_item items[],
5488 const struct rte_flow_action actions[],
5489 bool external, uint32_t flow_idx,
5490 struct rte_flow_error *error)
5494 ret = flow_create_split_sample(dev, flow, attr, items,
5495 actions, external, flow_idx, error);
5496 MLX5_ASSERT(ret <= 0);
5500 static struct mlx5_flow_tunnel *
5501 flow_tunnel_from_rule(struct rte_eth_dev *dev,
5502 const struct rte_flow_attr *attr,
5503 const struct rte_flow_item items[],
5504 const struct rte_flow_action actions[])
5506 struct mlx5_flow_tunnel *tunnel;
5508 #pragma GCC diagnostic push
5509 #pragma GCC diagnostic ignored "-Wcast-qual"
5510 if (is_flow_tunnel_match_rule(dev, attr, items, actions))
5511 tunnel = (struct mlx5_flow_tunnel *)items[0].spec;
5512 else if (is_flow_tunnel_steer_rule(dev, attr, items, actions))
5513 tunnel = (struct mlx5_flow_tunnel *)actions[0].conf;
5516 #pragma GCC diagnostic pop
5522 * Create a flow and add it to @p list.
5525 * Pointer to Ethernet device.
5527 * Pointer to a TAILQ flow list. If this parameter NULL,
5528 * no list insertion occurred, flow is just created,
5529 * this is caller's responsibility to track the
5532 * Flow rule attributes.
5534 * Pattern specification (list terminated by the END pattern item).
5535 * @param[in] actions
5536 * Associated actions (list terminated by the END action).
5537 * @param[in] external
5538 * This flow rule is created by request external to PMD.
5540 * Perform verbose error reporting if not NULL.
5543 * A flow index on success, 0 otherwise and rte_errno is set.
5546 flow_list_create(struct rte_eth_dev *dev, uint32_t *list,
5547 const struct rte_flow_attr *attr,
5548 const struct rte_flow_item items[],
5549 const struct rte_flow_action original_actions[],
5550 bool external, struct rte_flow_error *error)
5552 struct mlx5_priv *priv = dev->data->dev_private;
5553 struct rte_flow *flow = NULL;
5554 struct mlx5_flow *dev_flow;
5555 const struct rte_flow_action_rss *rss;
5556 struct mlx5_translated_shared_action
5557 shared_actions[MLX5_MAX_SHARED_ACTIONS];
5558 int shared_actions_n = MLX5_MAX_SHARED_ACTIONS;
5560 struct mlx5_flow_expand_rss buf;
5561 uint8_t buffer[2048];
5564 struct rte_flow_action actions[MLX5_MAX_SPLIT_ACTIONS];
5565 uint8_t buffer[2048];
5568 struct rte_flow_action actions[MLX5_MAX_SPLIT_ACTIONS];
5569 uint8_t buffer[2048];
5570 } actions_hairpin_tx;
5572 struct rte_flow_item items[MLX5_MAX_SPLIT_ITEMS];
5573 uint8_t buffer[2048];
5575 struct mlx5_flow_expand_rss *buf = &expand_buffer.buf;
5576 struct mlx5_flow_rss_desc *rss_desc = &((struct mlx5_flow_rss_desc *)
5577 priv->rss_desc)[!!priv->flow_idx];
5578 const struct rte_flow_action *p_actions_rx;
5582 uint32_t hairpin_id = 0;
5583 struct rte_flow_attr attr_tx = { .priority = 0 };
5584 struct rte_flow_attr attr_factor = {0};
5585 const struct rte_flow_action *actions;
5586 struct rte_flow_action *translated_actions = NULL;
5587 struct mlx5_flow_tunnel *tunnel;
5588 struct tunnel_default_miss_ctx default_miss_ctx = { 0, };
5589 int ret = flow_shared_actions_translate(original_actions,
5592 &translated_actions, error);
5595 MLX5_ASSERT(translated_actions == NULL);
5598 actions = translated_actions ? translated_actions : original_actions;
5599 memcpy((void *)&attr_factor, (const void *)attr, sizeof(*attr));
5600 p_actions_rx = actions;
5601 hairpin_flow = flow_check_hairpin_split(dev, &attr_factor, actions);
5602 ret = flow_drv_validate(dev, &attr_factor, items, p_actions_rx,
5603 external, hairpin_flow, error);
5605 goto error_before_hairpin_split;
5606 if (hairpin_flow > 0) {
5607 if (hairpin_flow > MLX5_MAX_SPLIT_ACTIONS) {
5609 goto error_before_hairpin_split;
5611 flow_hairpin_split(dev, actions, actions_rx.actions,
5612 actions_hairpin_tx.actions, items_tx.items,
5614 p_actions_rx = actions_rx.actions;
5616 flow = mlx5_ipool_zmalloc(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], &idx);
5619 goto error_before_flow;
5621 flow->drv_type = flow_get_drv_type(dev, &attr_factor);
5622 if (hairpin_id != 0)
5623 flow->hairpin_flow_id = hairpin_id;
5624 MLX5_ASSERT(flow->drv_type > MLX5_FLOW_TYPE_MIN &&
5625 flow->drv_type < MLX5_FLOW_TYPE_MAX);
5626 memset(rss_desc, 0, sizeof(*rss_desc));
5627 rss = flow_get_rss_action(p_actions_rx);
5630 * The following information is required by
5631 * mlx5_flow_hashfields_adjust() in advance.
5633 rss_desc->level = rss->level;
5634 /* RSS type 0 indicates default RSS type (ETH_RSS_IP). */
5635 rss_desc->types = !rss->types ? ETH_RSS_IP : rss->types;
5637 flow->dev_handles = 0;
5638 if (rss && rss->types) {
5639 unsigned int graph_root;
5641 graph_root = find_graph_root(items, rss->level);
5642 ret = mlx5_flow_expand_rss(buf, sizeof(expand_buffer.buffer),
5644 mlx5_support_expansion, graph_root);
5645 MLX5_ASSERT(ret > 0 &&
5646 (unsigned int)ret < sizeof(expand_buffer.buffer));
5649 buf->entry[0].pattern = (void *)(uintptr_t)items;
5651 flow->shared_rss = flow_get_shared_rss_action(shared_actions,
5654 * Record the start index when there is a nested call. All sub-flows
5655 * need to be translated before another calling.
5656 * No need to use ping-pong buffer to save memory here.
5658 if (priv->flow_idx) {
5659 MLX5_ASSERT(!priv->flow_nested_idx);
5660 priv->flow_nested_idx = priv->flow_idx;
5662 for (i = 0; i < buf->entries; ++i) {
5664 * The splitter may create multiple dev_flows,
5665 * depending on configuration. In the simplest
5666 * case it just creates unmodified original flow.
5668 ret = flow_create_split_outer(dev, flow, &attr_factor,
5669 buf->entry[i].pattern,
5670 p_actions_rx, external, idx,
5674 if (is_flow_tunnel_steer_rule(dev, attr,
5675 buf->entry[i].pattern,
5677 ret = flow_tunnel_add_default_miss(dev, flow, attr,
5683 mlx5_free(default_miss_ctx.queue);
5688 /* Create the tx flow. */
5690 attr_tx.group = MLX5_HAIRPIN_TX_TABLE;
5691 attr_tx.ingress = 0;
5693 dev_flow = flow_drv_prepare(dev, flow, &attr_tx, items_tx.items,
5694 actions_hairpin_tx.actions,
5698 dev_flow->flow = flow;
5699 dev_flow->external = 0;
5700 SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
5701 dev_flow->handle, next);
5702 ret = flow_drv_translate(dev, dev_flow, &attr_tx,
5704 actions_hairpin_tx.actions, error);
5709 * Update the metadata register copy table. If extensive
5710 * metadata feature is enabled and registers are supported
5711 * we might create the extra rte_flow for each unique
5712 * MARK/FLAG action ID.
5714 * The table is updated for ingress Flows only, because
5715 * the egress Flows belong to the different device and
5716 * copy table should be updated in peer NIC Rx domain.
5718 if (attr_factor.ingress &&
5719 (external || attr_factor.group != MLX5_FLOW_MREG_CP_TABLE_GROUP)) {
5720 ret = flow_mreg_update_copy_table(dev, flow, actions, error);
5725 * If the flow is external (from application) OR device is started, then
5726 * the flow will be applied immediately.
5728 if (external || dev->data->dev_started) {
5729 ret = flow_drv_apply(dev, flow, error);
5734 ILIST_INSERT(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], list, idx,
5736 flow_rxq_flags_set(dev, flow);
5737 rte_free(translated_actions);
5738 /* Nested flow creation index recovery. */
5739 priv->flow_idx = priv->flow_nested_idx;
5740 if (priv->flow_nested_idx)
5741 priv->flow_nested_idx = 0;
5742 tunnel = flow_tunnel_from_rule(dev, attr, items, actions);
5745 flow->tunnel_id = tunnel->tunnel_id;
5746 __atomic_add_fetch(&tunnel->refctn, 1, __ATOMIC_RELAXED);
5747 mlx5_free(default_miss_ctx.queue);
5752 ret = rte_errno; /* Save rte_errno before cleanup. */
5753 flow_mreg_del_copy_action(dev, flow);
5754 flow_drv_destroy(dev, flow);
5755 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], idx);
5756 rte_errno = ret; /* Restore rte_errno. */
5760 mlx5_flow_id_release(priv->sh->flow_id_pool,
5763 priv->flow_idx = priv->flow_nested_idx;
5764 if (priv->flow_nested_idx)
5765 priv->flow_nested_idx = 0;
5766 error_before_hairpin_split:
5767 rte_free(translated_actions);
5772 * Create a dedicated flow rule on e-switch table 0 (root table), to direct all
5773 * incoming packets to table 1.
5775 * Other flow rules, requested for group n, will be created in
5776 * e-switch table n+1.
5777 * Jump action to e-switch group n will be created to group n+1.
5779 * Used when working in switchdev mode, to utilise advantages of table 1
5783 * Pointer to Ethernet device.
5786 * Pointer to flow on success, NULL otherwise and rte_errno is set.
5789 mlx5_flow_create_esw_table_zero_flow(struct rte_eth_dev *dev)
5791 const struct rte_flow_attr attr = {
5798 const struct rte_flow_item pattern = {
5799 .type = RTE_FLOW_ITEM_TYPE_END,
5801 struct rte_flow_action_jump jump = {
5804 const struct rte_flow_action actions[] = {
5806 .type = RTE_FLOW_ACTION_TYPE_JUMP,
5810 .type = RTE_FLOW_ACTION_TYPE_END,
5813 struct mlx5_priv *priv = dev->data->dev_private;
5814 struct rte_flow_error error;
5816 return (void *)(uintptr_t)flow_list_create(dev, &priv->ctrl_flows,
5818 actions, false, &error);
5822 * Validate a flow supported by the NIC.
5824 * @see rte_flow_validate()
5828 mlx5_flow_validate(struct rte_eth_dev *dev,
5829 const struct rte_flow_attr *attr,
5830 const struct rte_flow_item items[],
5831 const struct rte_flow_action original_actions[],
5832 struct rte_flow_error *error)
5835 struct mlx5_translated_shared_action
5836 shared_actions[MLX5_MAX_SHARED_ACTIONS];
5837 int shared_actions_n = MLX5_MAX_SHARED_ACTIONS;
5838 const struct rte_flow_action *actions;
5839 struct rte_flow_action *translated_actions = NULL;
5840 int ret = flow_shared_actions_translate(original_actions,
5843 &translated_actions, error);
5847 actions = translated_actions ? translated_actions : original_actions;
5848 hairpin_flow = flow_check_hairpin_split(dev, attr, actions);
5849 ret = flow_drv_validate(dev, attr, items, actions,
5850 true, hairpin_flow, error);
5851 rte_free(translated_actions);
5858 * @see rte_flow_create()
5862 mlx5_flow_create(struct rte_eth_dev *dev,
5863 const struct rte_flow_attr *attr,
5864 const struct rte_flow_item items[],
5865 const struct rte_flow_action actions[],
5866 struct rte_flow_error *error)
5868 struct mlx5_priv *priv = dev->data->dev_private;
5871 * If the device is not started yet, it is not allowed to created a
5872 * flow from application. PMD default flows and traffic control flows
5875 if (unlikely(!dev->data->dev_started)) {
5876 DRV_LOG(DEBUG, "port %u is not started when "
5877 "inserting a flow", dev->data->port_id);
5878 rte_flow_error_set(error, ENODEV,
5879 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5881 "port not started");
5885 return (void *)(uintptr_t)flow_list_create(dev, &priv->flows,
5886 attr, items, actions, true, error);
5890 * Destroy a flow in a list.
5893 * Pointer to Ethernet device.
5895 * Pointer to the Indexed flow list. If this parameter NULL,
5896 * there is no flow removal from the list. Be noted that as
5897 * flow is add to the indexed list, memory of the indexed
5898 * list points to maybe changed as flow destroyed.
5899 * @param[in] flow_idx
5900 * Index of flow to destroy.
5903 flow_list_destroy(struct rte_eth_dev *dev, uint32_t *list,
5906 struct mlx5_priv *priv = dev->data->dev_private;
5907 struct mlx5_fdir_flow *priv_fdir_flow = NULL;
5908 struct rte_flow *flow = mlx5_ipool_get(priv->sh->ipool
5909 [MLX5_IPOOL_RTE_FLOW], flow_idx);
5914 * Update RX queue flags only if port is started, otherwise it is
5917 if (dev->data->dev_started)
5918 flow_rxq_flags_trim(dev, flow);
5919 if (flow->hairpin_flow_id)
5920 mlx5_flow_id_release(priv->sh->flow_id_pool,
5921 flow->hairpin_flow_id);
5922 flow_drv_destroy(dev, flow);
5924 ILIST_REMOVE(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], list,
5925 flow_idx, flow, next);
5926 flow_mreg_del_copy_action(dev, flow);
5928 LIST_FOREACH(priv_fdir_flow, &priv->fdir_flows, next) {
5929 if (priv_fdir_flow->rix_flow == flow_idx)
5932 if (priv_fdir_flow) {
5933 LIST_REMOVE(priv_fdir_flow, next);
5934 mlx5_free(priv_fdir_flow->fdir);
5935 mlx5_free(priv_fdir_flow);
5938 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], flow_idx);
5940 struct mlx5_flow_tunnel *tunnel;
5941 tunnel = mlx5_find_tunnel_id(dev, flow->tunnel_id);
5943 if (!__atomic_sub_fetch(&tunnel->refctn, 1, __ATOMIC_RELAXED))
5944 mlx5_flow_tunnel_free(dev, tunnel);
5949 * Destroy all flows.
5952 * Pointer to Ethernet device.
5954 * Pointer to the Indexed flow list.
5956 * If flushing is called avtively.
5959 mlx5_flow_list_flush(struct rte_eth_dev *dev, uint32_t *list, bool active)
5961 uint32_t num_flushed = 0;
5964 flow_list_destroy(dev, list, *list);
5968 DRV_LOG(INFO, "port %u: %u flows flushed before stopping",
5969 dev->data->port_id, num_flushed);
5977 * Pointer to Ethernet device.
5979 * Pointer to the Indexed flow list.
5982 mlx5_flow_stop(struct rte_eth_dev *dev, uint32_t *list)
5984 struct mlx5_priv *priv = dev->data->dev_private;
5985 struct rte_flow *flow = NULL;
5988 ILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], *list, idx,
5990 flow_drv_remove(dev, flow);
5991 flow_mreg_stop_copy_action(dev, flow);
5993 flow_mreg_del_default_copy_action(dev);
5994 flow_rxq_flags_clear(dev);
6001 * Pointer to Ethernet device.
6003 * Pointer to the Indexed flow list.
6006 * 0 on success, a negative errno value otherwise and rte_errno is set.
6009 mlx5_flow_start(struct rte_eth_dev *dev, uint32_t *list)
6011 struct mlx5_priv *priv = dev->data->dev_private;
6012 struct rte_flow *flow = NULL;
6013 struct rte_flow_error error;
6017 /* Make sure default copy action (reg_c[0] -> reg_b) is created. */
6018 ret = flow_mreg_add_default_copy_action(dev, &error);
6021 /* Apply Flows created by application. */
6022 ILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], *list, idx,
6024 ret = flow_mreg_start_copy_action(dev, flow);
6027 ret = flow_drv_apply(dev, flow, &error);
6030 flow_rxq_flags_set(dev, flow);
6034 ret = rte_errno; /* Save rte_errno before cleanup. */
6035 mlx5_flow_stop(dev, list);
6036 rte_errno = ret; /* Restore rte_errno. */
6041 * Stop all default actions for flows.
6044 * Pointer to Ethernet device.
6047 mlx5_flow_stop_default(struct rte_eth_dev *dev)
6049 flow_mreg_del_default_copy_action(dev);
6050 flow_rxq_flags_clear(dev);
6054 * Start all default actions for flows.
6057 * Pointer to Ethernet device.
6059 * 0 on success, a negative errno value otherwise and rte_errno is set.
6062 mlx5_flow_start_default(struct rte_eth_dev *dev)
6064 struct rte_flow_error error;
6066 /* Make sure default copy action (reg_c[0] -> reg_b) is created. */
6067 return flow_mreg_add_default_copy_action(dev, &error);
6071 * Allocate intermediate resources for flow creation.
6074 * Pointer to Ethernet device.
6077 mlx5_flow_alloc_intermediate(struct rte_eth_dev *dev)
6079 struct mlx5_priv *priv = dev->data->dev_private;
6081 if (!priv->inter_flows) {
6082 priv->inter_flows = mlx5_malloc(MLX5_MEM_ZERO,
6083 MLX5_NUM_MAX_DEV_FLOWS *
6084 sizeof(struct mlx5_flow) +
6085 (sizeof(struct mlx5_flow_rss_desc) +
6086 sizeof(uint16_t) * UINT16_MAX) * 2, 0,
6088 if (!priv->inter_flows) {
6089 DRV_LOG(ERR, "can't allocate intermediate memory.");
6093 priv->rss_desc = &((struct mlx5_flow *)priv->inter_flows)
6094 [MLX5_NUM_MAX_DEV_FLOWS];
6095 /* Reset the index. */
6097 priv->flow_nested_idx = 0;
6101 * Free intermediate resources for flows.
6104 * Pointer to Ethernet device.
6107 mlx5_flow_free_intermediate(struct rte_eth_dev *dev)
6109 struct mlx5_priv *priv = dev->data->dev_private;
6111 mlx5_free(priv->inter_flows);
6112 priv->inter_flows = NULL;
6116 * Verify the flow list is empty
6119 * Pointer to Ethernet device.
6121 * @return the number of flows not released.
6124 mlx5_flow_verify(struct rte_eth_dev *dev)
6126 struct mlx5_priv *priv = dev->data->dev_private;
6127 struct rte_flow *flow;
6131 ILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], priv->flows, idx,
6133 DRV_LOG(DEBUG, "port %u flow %p still referenced",
6134 dev->data->port_id, (void *)flow);
6141 * Enable default hairpin egress flow.
6144 * Pointer to Ethernet device.
6149 * 0 on success, a negative errno value otherwise and rte_errno is set.
6152 mlx5_ctrl_flow_source_queue(struct rte_eth_dev *dev,
6155 struct mlx5_priv *priv = dev->data->dev_private;
6156 const struct rte_flow_attr attr = {
6160 struct mlx5_rte_flow_item_tx_queue queue_spec = {
6163 struct mlx5_rte_flow_item_tx_queue queue_mask = {
6164 .queue = UINT32_MAX,
6166 struct rte_flow_item items[] = {
6168 .type = (enum rte_flow_item_type)
6169 MLX5_RTE_FLOW_ITEM_TYPE_TX_QUEUE,
6170 .spec = &queue_spec,
6172 .mask = &queue_mask,
6175 .type = RTE_FLOW_ITEM_TYPE_END,
6178 struct rte_flow_action_jump jump = {
6179 .group = MLX5_HAIRPIN_TX_TABLE,
6181 struct rte_flow_action actions[2];
6183 struct rte_flow_error error;
6185 actions[0].type = RTE_FLOW_ACTION_TYPE_JUMP;
6186 actions[0].conf = &jump;
6187 actions[1].type = RTE_FLOW_ACTION_TYPE_END;
6188 flow_idx = flow_list_create(dev, &priv->ctrl_flows,
6189 &attr, items, actions, false, &error);
6192 "Failed to create ctrl flow: rte_errno(%d),"
6193 " type(%d), message(%s)",
6194 rte_errno, error.type,
6195 error.message ? error.message : " (no stated reason)");
6202 * Enable a control flow configured from the control plane.
6205 * Pointer to Ethernet device.
6207 * An Ethernet flow spec to apply.
6209 * An Ethernet flow mask to apply.
6211 * A VLAN flow spec to apply.
6213 * A VLAN flow mask to apply.
6216 * 0 on success, a negative errno value otherwise and rte_errno is set.
6219 mlx5_ctrl_flow_vlan(struct rte_eth_dev *dev,
6220 struct rte_flow_item_eth *eth_spec,
6221 struct rte_flow_item_eth *eth_mask,
6222 struct rte_flow_item_vlan *vlan_spec,
6223 struct rte_flow_item_vlan *vlan_mask)
6225 struct mlx5_priv *priv = dev->data->dev_private;
6226 const struct rte_flow_attr attr = {
6228 .priority = MLX5_FLOW_PRIO_RSVD,
6230 struct rte_flow_item items[] = {
6232 .type = RTE_FLOW_ITEM_TYPE_ETH,
6238 .type = (vlan_spec) ? RTE_FLOW_ITEM_TYPE_VLAN :
6239 RTE_FLOW_ITEM_TYPE_END,
6245 .type = RTE_FLOW_ITEM_TYPE_END,
6248 uint16_t queue[priv->reta_idx_n];
6249 struct rte_flow_action_rss action_rss = {
6250 .func = RTE_ETH_HASH_FUNCTION_DEFAULT,
6252 .types = priv->rss_conf.rss_hf,
6253 .key_len = priv->rss_conf.rss_key_len,
6254 .queue_num = priv->reta_idx_n,
6255 .key = priv->rss_conf.rss_key,
6258 struct rte_flow_action actions[] = {
6260 .type = RTE_FLOW_ACTION_TYPE_RSS,
6261 .conf = &action_rss,
6264 .type = RTE_FLOW_ACTION_TYPE_END,
6268 struct rte_flow_error error;
6271 if (!priv->reta_idx_n || !priv->rxqs_n) {
6274 if (!(dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG))
6275 action_rss.types = 0;
6276 for (i = 0; i != priv->reta_idx_n; ++i)
6277 queue[i] = (*priv->reta_idx)[i];
6278 flow_idx = flow_list_create(dev, &priv->ctrl_flows,
6279 &attr, items, actions, false, &error);
6286 * Enable a flow control configured from the control plane.
6289 * Pointer to Ethernet device.
6291 * An Ethernet flow spec to apply.
6293 * An Ethernet flow mask to apply.
6296 * 0 on success, a negative errno value otherwise and rte_errno is set.
6299 mlx5_ctrl_flow(struct rte_eth_dev *dev,
6300 struct rte_flow_item_eth *eth_spec,
6301 struct rte_flow_item_eth *eth_mask)
6303 return mlx5_ctrl_flow_vlan(dev, eth_spec, eth_mask, NULL, NULL);
6307 * Create default miss flow rule matching lacp traffic
6310 * Pointer to Ethernet device.
6312 * An Ethernet flow spec to apply.
6315 * 0 on success, a negative errno value otherwise and rte_errno is set.
6318 mlx5_flow_lacp_miss(struct rte_eth_dev *dev)
6320 struct mlx5_priv *priv = dev->data->dev_private;
6322 * The LACP matching is done by only using ether type since using
6323 * a multicast dst mac causes kernel to give low priority to this flow.
6325 static const struct rte_flow_item_eth lacp_spec = {
6326 .type = RTE_BE16(0x8809),
6328 static const struct rte_flow_item_eth lacp_mask = {
6331 const struct rte_flow_attr attr = {
6334 struct rte_flow_item items[] = {
6336 .type = RTE_FLOW_ITEM_TYPE_ETH,
6341 .type = RTE_FLOW_ITEM_TYPE_END,
6344 struct rte_flow_action actions[] = {
6346 .type = (enum rte_flow_action_type)
6347 MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS,
6350 .type = RTE_FLOW_ACTION_TYPE_END,
6353 struct rte_flow_error error;
6354 uint32_t flow_idx = flow_list_create(dev, &priv->ctrl_flows,
6355 &attr, items, actions, false, &error);
6365 * @see rte_flow_destroy()
6369 mlx5_flow_destroy(struct rte_eth_dev *dev,
6370 struct rte_flow *flow,
6371 struct rte_flow_error *error __rte_unused)
6373 struct mlx5_priv *priv = dev->data->dev_private;
6375 flow_list_destroy(dev, &priv->flows, (uintptr_t)(void *)flow);
6380 * Destroy all flows.
6382 * @see rte_flow_flush()
6386 mlx5_flow_flush(struct rte_eth_dev *dev,
6387 struct rte_flow_error *error __rte_unused)
6389 struct mlx5_priv *priv = dev->data->dev_private;
6391 mlx5_flow_list_flush(dev, &priv->flows, false);
6398 * @see rte_flow_isolate()
6402 mlx5_flow_isolate(struct rte_eth_dev *dev,
6404 struct rte_flow_error *error)
6406 struct mlx5_priv *priv = dev->data->dev_private;
6408 if (dev->data->dev_started) {
6409 rte_flow_error_set(error, EBUSY,
6410 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6412 "port must be stopped first");
6415 priv->isolated = !!enable;
6417 dev->dev_ops = &mlx5_os_dev_ops_isolate;
6419 dev->dev_ops = &mlx5_os_dev_ops;
6421 dev->rx_descriptor_status = mlx5_rx_descriptor_status;
6422 dev->tx_descriptor_status = mlx5_tx_descriptor_status;
6430 * @see rte_flow_query()
6434 flow_drv_query(struct rte_eth_dev *dev,
6436 const struct rte_flow_action *actions,
6438 struct rte_flow_error *error)
6440 struct mlx5_priv *priv = dev->data->dev_private;
6441 const struct mlx5_flow_driver_ops *fops;
6442 struct rte_flow *flow = mlx5_ipool_get(priv->sh->ipool
6443 [MLX5_IPOOL_RTE_FLOW],
6445 enum mlx5_flow_drv_type ftype;
6448 return rte_flow_error_set(error, ENOENT,
6449 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6451 "invalid flow handle");
6453 ftype = flow->drv_type;
6454 MLX5_ASSERT(ftype > MLX5_FLOW_TYPE_MIN && ftype < MLX5_FLOW_TYPE_MAX);
6455 fops = flow_get_drv_ops(ftype);
6457 return fops->query(dev, flow, actions, data, error);
6463 * @see rte_flow_query()
6467 mlx5_flow_query(struct rte_eth_dev *dev,
6468 struct rte_flow *flow,
6469 const struct rte_flow_action *actions,
6471 struct rte_flow_error *error)
6475 ret = flow_drv_query(dev, (uintptr_t)(void *)flow, actions, data,
6483 * Convert a flow director filter to a generic flow.
6486 * Pointer to Ethernet device.
6487 * @param fdir_filter
6488 * Flow director filter to add.
6490 * Generic flow parameters structure.
6493 * 0 on success, a negative errno value otherwise and rte_errno is set.
6496 flow_fdir_filter_convert(struct rte_eth_dev *dev,
6497 const struct rte_eth_fdir_filter *fdir_filter,
6498 struct mlx5_fdir *attributes)
6500 struct mlx5_priv *priv = dev->data->dev_private;
6501 const struct rte_eth_fdir_input *input = &fdir_filter->input;
6502 const struct rte_eth_fdir_masks *mask =
6503 &dev->data->dev_conf.fdir_conf.mask;
6505 /* Validate queue number. */
6506 if (fdir_filter->action.rx_queue >= priv->rxqs_n) {
6507 DRV_LOG(ERR, "port %u invalid queue number %d",
6508 dev->data->port_id, fdir_filter->action.rx_queue);
6512 attributes->attr.ingress = 1;
6513 attributes->items[0] = (struct rte_flow_item) {
6514 .type = RTE_FLOW_ITEM_TYPE_ETH,
6515 .spec = &attributes->l2,
6516 .mask = &attributes->l2_mask,
6518 switch (fdir_filter->action.behavior) {
6519 case RTE_ETH_FDIR_ACCEPT:
6520 attributes->actions[0] = (struct rte_flow_action){
6521 .type = RTE_FLOW_ACTION_TYPE_QUEUE,
6522 .conf = &attributes->queue,
6525 case RTE_ETH_FDIR_REJECT:
6526 attributes->actions[0] = (struct rte_flow_action){
6527 .type = RTE_FLOW_ACTION_TYPE_DROP,
6531 DRV_LOG(ERR, "port %u invalid behavior %d",
6533 fdir_filter->action.behavior);
6534 rte_errno = ENOTSUP;
6537 attributes->queue.index = fdir_filter->action.rx_queue;
6539 switch (fdir_filter->input.flow_type) {
6540 case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
6541 case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
6542 case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
6543 attributes->l3.ipv4.hdr = (struct rte_ipv4_hdr){
6544 .src_addr = input->flow.ip4_flow.src_ip,
6545 .dst_addr = input->flow.ip4_flow.dst_ip,
6546 .time_to_live = input->flow.ip4_flow.ttl,
6547 .type_of_service = input->flow.ip4_flow.tos,
6549 attributes->l3_mask.ipv4.hdr = (struct rte_ipv4_hdr){
6550 .src_addr = mask->ipv4_mask.src_ip,
6551 .dst_addr = mask->ipv4_mask.dst_ip,
6552 .time_to_live = mask->ipv4_mask.ttl,
6553 .type_of_service = mask->ipv4_mask.tos,
6554 .next_proto_id = mask->ipv4_mask.proto,
6556 attributes->items[1] = (struct rte_flow_item){
6557 .type = RTE_FLOW_ITEM_TYPE_IPV4,
6558 .spec = &attributes->l3,
6559 .mask = &attributes->l3_mask,
6562 case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
6563 case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
6564 case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
6565 attributes->l3.ipv6.hdr = (struct rte_ipv6_hdr){
6566 .hop_limits = input->flow.ipv6_flow.hop_limits,
6567 .proto = input->flow.ipv6_flow.proto,
6570 memcpy(attributes->l3.ipv6.hdr.src_addr,
6571 input->flow.ipv6_flow.src_ip,
6572 RTE_DIM(attributes->l3.ipv6.hdr.src_addr));
6573 memcpy(attributes->l3.ipv6.hdr.dst_addr,
6574 input->flow.ipv6_flow.dst_ip,
6575 RTE_DIM(attributes->l3.ipv6.hdr.src_addr));
6576 memcpy(attributes->l3_mask.ipv6.hdr.src_addr,
6577 mask->ipv6_mask.src_ip,
6578 RTE_DIM(attributes->l3_mask.ipv6.hdr.src_addr));
6579 memcpy(attributes->l3_mask.ipv6.hdr.dst_addr,
6580 mask->ipv6_mask.dst_ip,
6581 RTE_DIM(attributes->l3_mask.ipv6.hdr.src_addr));
6582 attributes->items[1] = (struct rte_flow_item){
6583 .type = RTE_FLOW_ITEM_TYPE_IPV6,
6584 .spec = &attributes->l3,
6585 .mask = &attributes->l3_mask,
6589 DRV_LOG(ERR, "port %u invalid flow type%d",
6590 dev->data->port_id, fdir_filter->input.flow_type);
6591 rte_errno = ENOTSUP;
6595 switch (fdir_filter->input.flow_type) {
6596 case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
6597 attributes->l4.udp.hdr = (struct rte_udp_hdr){
6598 .src_port = input->flow.udp4_flow.src_port,
6599 .dst_port = input->flow.udp4_flow.dst_port,
6601 attributes->l4_mask.udp.hdr = (struct rte_udp_hdr){
6602 .src_port = mask->src_port_mask,
6603 .dst_port = mask->dst_port_mask,
6605 attributes->items[2] = (struct rte_flow_item){
6606 .type = RTE_FLOW_ITEM_TYPE_UDP,
6607 .spec = &attributes->l4,
6608 .mask = &attributes->l4_mask,
6611 case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
6612 attributes->l4.tcp.hdr = (struct rte_tcp_hdr){
6613 .src_port = input->flow.tcp4_flow.src_port,
6614 .dst_port = input->flow.tcp4_flow.dst_port,
6616 attributes->l4_mask.tcp.hdr = (struct rte_tcp_hdr){
6617 .src_port = mask->src_port_mask,
6618 .dst_port = mask->dst_port_mask,
6620 attributes->items[2] = (struct rte_flow_item){
6621 .type = RTE_FLOW_ITEM_TYPE_TCP,
6622 .spec = &attributes->l4,
6623 .mask = &attributes->l4_mask,
6626 case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
6627 attributes->l4.udp.hdr = (struct rte_udp_hdr){
6628 .src_port = input->flow.udp6_flow.src_port,
6629 .dst_port = input->flow.udp6_flow.dst_port,
6631 attributes->l4_mask.udp.hdr = (struct rte_udp_hdr){
6632 .src_port = mask->src_port_mask,
6633 .dst_port = mask->dst_port_mask,
6635 attributes->items[2] = (struct rte_flow_item){
6636 .type = RTE_FLOW_ITEM_TYPE_UDP,
6637 .spec = &attributes->l4,
6638 .mask = &attributes->l4_mask,
6641 case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
6642 attributes->l4.tcp.hdr = (struct rte_tcp_hdr){
6643 .src_port = input->flow.tcp6_flow.src_port,
6644 .dst_port = input->flow.tcp6_flow.dst_port,
6646 attributes->l4_mask.tcp.hdr = (struct rte_tcp_hdr){
6647 .src_port = mask->src_port_mask,
6648 .dst_port = mask->dst_port_mask,
6650 attributes->items[2] = (struct rte_flow_item){
6651 .type = RTE_FLOW_ITEM_TYPE_TCP,
6652 .spec = &attributes->l4,
6653 .mask = &attributes->l4_mask,
6656 case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
6657 case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
6660 DRV_LOG(ERR, "port %u invalid flow type%d",
6661 dev->data->port_id, fdir_filter->input.flow_type);
6662 rte_errno = ENOTSUP;
6668 #define FLOW_FDIR_CMP(f1, f2, fld) \
6669 memcmp(&(f1)->fld, &(f2)->fld, sizeof(f1->fld))
6672 * Compare two FDIR flows. If items and actions are identical, the two flows are
6676 * Pointer to Ethernet device.
6678 * FDIR flow to compare.
6680 * FDIR flow to compare.
6683 * Zero on match, 1 otherwise.
6686 flow_fdir_cmp(const struct mlx5_fdir *f1, const struct mlx5_fdir *f2)
6688 if (FLOW_FDIR_CMP(f1, f2, attr) ||
6689 FLOW_FDIR_CMP(f1, f2, l2) ||
6690 FLOW_FDIR_CMP(f1, f2, l2_mask) ||
6691 FLOW_FDIR_CMP(f1, f2, l3) ||
6692 FLOW_FDIR_CMP(f1, f2, l3_mask) ||
6693 FLOW_FDIR_CMP(f1, f2, l4) ||
6694 FLOW_FDIR_CMP(f1, f2, l4_mask) ||
6695 FLOW_FDIR_CMP(f1, f2, actions[0].type))
6697 if (f1->actions[0].type == RTE_FLOW_ACTION_TYPE_QUEUE &&
6698 FLOW_FDIR_CMP(f1, f2, queue))
6704 * Search device flow list to find out a matched FDIR flow.
6707 * Pointer to Ethernet device.
6709 * FDIR flow to lookup.
6712 * Index of flow if found, 0 otherwise.
6715 flow_fdir_filter_lookup(struct rte_eth_dev *dev, struct mlx5_fdir *fdir_flow)
6717 struct mlx5_priv *priv = dev->data->dev_private;
6718 uint32_t flow_idx = 0;
6719 struct mlx5_fdir_flow *priv_fdir_flow = NULL;
6721 MLX5_ASSERT(fdir_flow);
6722 LIST_FOREACH(priv_fdir_flow, &priv->fdir_flows, next) {
6723 if (!flow_fdir_cmp(priv_fdir_flow->fdir, fdir_flow)) {
6724 DRV_LOG(DEBUG, "port %u found FDIR flow %u",
6725 dev->data->port_id, flow_idx);
6726 flow_idx = priv_fdir_flow->rix_flow;
6734 * Add new flow director filter and store it in list.
6737 * Pointer to Ethernet device.
6738 * @param fdir_filter
6739 * Flow director filter to add.
6742 * 0 on success, a negative errno value otherwise and rte_errno is set.
6745 flow_fdir_filter_add(struct rte_eth_dev *dev,
6746 const struct rte_eth_fdir_filter *fdir_filter)
6748 struct mlx5_priv *priv = dev->data->dev_private;
6749 struct mlx5_fdir *fdir_flow;
6750 struct rte_flow *flow;
6751 struct mlx5_fdir_flow *priv_fdir_flow = NULL;
6755 fdir_flow = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*fdir_flow), 0,
6761 ret = flow_fdir_filter_convert(dev, fdir_filter, fdir_flow);
6764 flow_idx = flow_fdir_filter_lookup(dev, fdir_flow);
6769 priv_fdir_flow = mlx5_malloc(MLX5_MEM_ZERO,
6770 sizeof(struct mlx5_fdir_flow),
6772 if (!priv_fdir_flow) {
6776 flow_idx = flow_list_create(dev, &priv->flows, &fdir_flow->attr,
6777 fdir_flow->items, fdir_flow->actions, true,
6779 flow = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], flow_idx);
6783 priv_fdir_flow->fdir = fdir_flow;
6784 priv_fdir_flow->rix_flow = flow_idx;
6785 LIST_INSERT_HEAD(&priv->fdir_flows, priv_fdir_flow, next);
6786 DRV_LOG(DEBUG, "port %u created FDIR flow %p",
6787 dev->data->port_id, (void *)flow);
6790 mlx5_free(priv_fdir_flow);
6791 mlx5_free(fdir_flow);
6796 * Delete specific filter.
6799 * Pointer to Ethernet device.
6800 * @param fdir_filter
6801 * Filter to be deleted.
6804 * 0 on success, a negative errno value otherwise and rte_errno is set.
6807 flow_fdir_filter_delete(struct rte_eth_dev *dev,
6808 const struct rte_eth_fdir_filter *fdir_filter)
6810 struct mlx5_priv *priv = dev->data->dev_private;
6812 struct mlx5_fdir fdir_flow = {
6815 struct mlx5_fdir_flow *priv_fdir_flow = NULL;
6818 ret = flow_fdir_filter_convert(dev, fdir_filter, &fdir_flow);
6821 LIST_FOREACH(priv_fdir_flow, &priv->fdir_flows, next) {
6822 /* Find the fdir in priv list */
6823 if (!flow_fdir_cmp(priv_fdir_flow->fdir, &fdir_flow))
6826 if (!priv_fdir_flow)
6828 LIST_REMOVE(priv_fdir_flow, next);
6829 flow_idx = priv_fdir_flow->rix_flow;
6830 flow_list_destroy(dev, &priv->flows, flow_idx);
6831 mlx5_free(priv_fdir_flow->fdir);
6832 mlx5_free(priv_fdir_flow);
6833 DRV_LOG(DEBUG, "port %u deleted FDIR flow %u",
6834 dev->data->port_id, flow_idx);
6839 * Update queue for specific filter.
6842 * Pointer to Ethernet device.
6843 * @param fdir_filter
6844 * Filter to be updated.
6847 * 0 on success, a negative errno value otherwise and rte_errno is set.
6850 flow_fdir_filter_update(struct rte_eth_dev *dev,
6851 const struct rte_eth_fdir_filter *fdir_filter)
6855 ret = flow_fdir_filter_delete(dev, fdir_filter);
6858 return flow_fdir_filter_add(dev, fdir_filter);
6862 * Flush all filters.
6865 * Pointer to Ethernet device.
6868 flow_fdir_filter_flush(struct rte_eth_dev *dev)
6870 struct mlx5_priv *priv = dev->data->dev_private;
6871 struct mlx5_fdir_flow *priv_fdir_flow = NULL;
6873 while (!LIST_EMPTY(&priv->fdir_flows)) {
6874 priv_fdir_flow = LIST_FIRST(&priv->fdir_flows);
6875 LIST_REMOVE(priv_fdir_flow, next);
6876 flow_list_destroy(dev, &priv->flows, priv_fdir_flow->rix_flow);
6877 mlx5_free(priv_fdir_flow->fdir);
6878 mlx5_free(priv_fdir_flow);
6883 * Get flow director information.
6886 * Pointer to Ethernet device.
6887 * @param[out] fdir_info
6888 * Resulting flow director information.
6891 flow_fdir_info_get(struct rte_eth_dev *dev, struct rte_eth_fdir_info *fdir_info)
6893 struct rte_eth_fdir_masks *mask =
6894 &dev->data->dev_conf.fdir_conf.mask;
6896 fdir_info->mode = dev->data->dev_conf.fdir_conf.mode;
6897 fdir_info->guarant_spc = 0;
6898 rte_memcpy(&fdir_info->mask, mask, sizeof(fdir_info->mask));
6899 fdir_info->max_flexpayload = 0;
6900 fdir_info->flow_types_mask[0] = 0;
6901 fdir_info->flex_payload_unit = 0;
6902 fdir_info->max_flex_payload_segment_num = 0;
6903 fdir_info->flex_payload_limit = 0;
6904 memset(&fdir_info->flex_conf, 0, sizeof(fdir_info->flex_conf));
6908 * Deal with flow director operations.
6911 * Pointer to Ethernet device.
6913 * Operation to perform.
6915 * Pointer to operation-specific structure.
6918 * 0 on success, a negative errno value otherwise and rte_errno is set.
6921 flow_fdir_ctrl_func(struct rte_eth_dev *dev, enum rte_filter_op filter_op,
6924 enum rte_fdir_mode fdir_mode =
6925 dev->data->dev_conf.fdir_conf.mode;
6927 if (filter_op == RTE_ETH_FILTER_NOP)
6929 if (fdir_mode != RTE_FDIR_MODE_PERFECT &&
6930 fdir_mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
6931 DRV_LOG(ERR, "port %u flow director mode %d not supported",
6932 dev->data->port_id, fdir_mode);
6936 switch (filter_op) {
6937 case RTE_ETH_FILTER_ADD:
6938 return flow_fdir_filter_add(dev, arg);
6939 case RTE_ETH_FILTER_UPDATE:
6940 return flow_fdir_filter_update(dev, arg);
6941 case RTE_ETH_FILTER_DELETE:
6942 return flow_fdir_filter_delete(dev, arg);
6943 case RTE_ETH_FILTER_FLUSH:
6944 flow_fdir_filter_flush(dev);
6946 case RTE_ETH_FILTER_INFO:
6947 flow_fdir_info_get(dev, arg);
6950 DRV_LOG(DEBUG, "port %u unknown operation %u",
6951 dev->data->port_id, filter_op);
6959 * Manage filter operations.
6962 * Pointer to Ethernet device structure.
6963 * @param filter_type
6966 * Operation to perform.
6968 * Pointer to operation-specific structure.
6971 * 0 on success, a negative errno value otherwise and rte_errno is set.
6974 mlx5_dev_filter_ctrl(struct rte_eth_dev *dev,
6975 enum rte_filter_type filter_type,
6976 enum rte_filter_op filter_op,
6979 switch (filter_type) {
6980 case RTE_ETH_FILTER_GENERIC:
6981 if (filter_op != RTE_ETH_FILTER_GET) {
6985 *(const void **)arg = &mlx5_flow_ops;
6987 case RTE_ETH_FILTER_FDIR:
6988 return flow_fdir_ctrl_func(dev, filter_op, arg);
6990 DRV_LOG(ERR, "port %u filter type (%d) not supported",
6991 dev->data->port_id, filter_type);
6992 rte_errno = ENOTSUP;
6999 * Create the needed meter and suffix tables.
7002 * Pointer to Ethernet device.
7004 * Pointer to the flow meter.
7007 * Pointer to table set on success, NULL otherwise.
7009 struct mlx5_meter_domains_infos *
7010 mlx5_flow_create_mtr_tbls(struct rte_eth_dev *dev,
7011 const struct mlx5_flow_meter *fm)
7013 const struct mlx5_flow_driver_ops *fops;
7015 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7016 return fops->create_mtr_tbls(dev, fm);
7020 * Destroy the meter table set.
7023 * Pointer to Ethernet device.
7025 * Pointer to the meter table set.
7031 mlx5_flow_destroy_mtr_tbls(struct rte_eth_dev *dev,
7032 struct mlx5_meter_domains_infos *tbls)
7034 const struct mlx5_flow_driver_ops *fops;
7036 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7037 return fops->destroy_mtr_tbls(dev, tbls);
7041 * Create policer rules.
7044 * Pointer to Ethernet device.
7046 * Pointer to flow meter structure.
7048 * Pointer to flow attributes.
7051 * 0 on success, -1 otherwise.
7054 mlx5_flow_create_policer_rules(struct rte_eth_dev *dev,
7055 struct mlx5_flow_meter *fm,
7056 const struct rte_flow_attr *attr)
7058 const struct mlx5_flow_driver_ops *fops;
7060 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7061 return fops->create_policer_rules(dev, fm, attr);
7065 * Destroy policer rules.
7068 * Pointer to flow meter structure.
7070 * Pointer to flow attributes.
7073 * 0 on success, -1 otherwise.
7076 mlx5_flow_destroy_policer_rules(struct rte_eth_dev *dev,
7077 struct mlx5_flow_meter *fm,
7078 const struct rte_flow_attr *attr)
7080 const struct mlx5_flow_driver_ops *fops;
7082 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7083 return fops->destroy_policer_rules(dev, fm, attr);
7087 * Allocate a counter.
7090 * Pointer to Ethernet device structure.
7093 * Index to allocated counter on success, 0 otherwise.
7096 mlx5_counter_alloc(struct rte_eth_dev *dev)
7098 const struct mlx5_flow_driver_ops *fops;
7099 struct rte_flow_attr attr = { .transfer = 0 };
7101 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
7102 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7103 return fops->counter_alloc(dev);
7106 "port %u counter allocate is not supported.",
7107 dev->data->port_id);
7115 * Pointer to Ethernet device structure.
7117 * Index to counter to be free.
7120 mlx5_counter_free(struct rte_eth_dev *dev, uint32_t cnt)
7122 const struct mlx5_flow_driver_ops *fops;
7123 struct rte_flow_attr attr = { .transfer = 0 };
7125 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
7126 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7127 fops->counter_free(dev, cnt);
7131 "port %u counter free is not supported.",
7132 dev->data->port_id);
7136 * Query counter statistics.
7139 * Pointer to Ethernet device structure.
7141 * Index to counter to query.
7143 * Set to clear counter statistics.
7145 * The counter hits packets number to save.
7147 * The counter hits bytes number to save.
7150 * 0 on success, a negative errno value otherwise.
7153 mlx5_counter_query(struct rte_eth_dev *dev, uint32_t cnt,
7154 bool clear, uint64_t *pkts, uint64_t *bytes)
7156 const struct mlx5_flow_driver_ops *fops;
7157 struct rte_flow_attr attr = { .transfer = 0 };
7159 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
7160 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7161 return fops->counter_query(dev, cnt, clear, pkts, bytes);
7164 "port %u counter query is not supported.",
7165 dev->data->port_id);
7170 * Allocate a new memory for the counter values wrapped by all the needed
7174 * Pointer to mlx5_dev_ctx_shared object.
7177 * 0 on success, a negative errno value otherwise.
7180 mlx5_flow_create_counter_stat_mem_mng(struct mlx5_dev_ctx_shared *sh)
7182 struct mlx5_devx_mkey_attr mkey_attr;
7183 struct mlx5_counter_stats_mem_mng *mem_mng;
7184 volatile struct flow_counter_stats *raw_data;
7185 int raws_n = MLX5_CNT_CONTAINER_RESIZE + MLX5_MAX_PENDING_QUERIES;
7186 int size = (sizeof(struct flow_counter_stats) *
7187 MLX5_COUNTERS_PER_POOL +
7188 sizeof(struct mlx5_counter_stats_raw)) * raws_n +
7189 sizeof(struct mlx5_counter_stats_mem_mng);
7190 size_t pgsize = rte_mem_page_size();
7194 if (pgsize == (size_t)-1) {
7195 DRV_LOG(ERR, "Failed to get mem page size");
7199 mem = mlx5_malloc(MLX5_MEM_ZERO, size, pgsize, SOCKET_ID_ANY);
7204 mem_mng = (struct mlx5_counter_stats_mem_mng *)(mem + size) - 1;
7205 size = sizeof(*raw_data) * MLX5_COUNTERS_PER_POOL * raws_n;
7206 mem_mng->umem = mlx5_glue->devx_umem_reg(sh->ctx, mem, size,
7207 IBV_ACCESS_LOCAL_WRITE);
7208 if (!mem_mng->umem) {
7213 mkey_attr.addr = (uintptr_t)mem;
7214 mkey_attr.size = size;
7215 mkey_attr.umem_id = mlx5_os_get_umem_id(mem_mng->umem);
7216 mkey_attr.pd = sh->pdn;
7217 mkey_attr.log_entity_size = 0;
7218 mkey_attr.pg_access = 0;
7219 mkey_attr.klm_array = NULL;
7220 mkey_attr.klm_num = 0;
7221 mkey_attr.relaxed_ordering = sh->cmng.relaxed_ordering;
7222 mem_mng->dm = mlx5_devx_cmd_mkey_create(sh->ctx, &mkey_attr);
7224 mlx5_glue->devx_umem_dereg(mem_mng->umem);
7229 mem_mng->raws = (struct mlx5_counter_stats_raw *)(mem + size);
7230 raw_data = (volatile struct flow_counter_stats *)mem;
7231 for (i = 0; i < raws_n; ++i) {
7232 mem_mng->raws[i].mem_mng = mem_mng;
7233 mem_mng->raws[i].data = raw_data + i * MLX5_COUNTERS_PER_POOL;
7235 for (i = 0; i < MLX5_MAX_PENDING_QUERIES; ++i)
7236 LIST_INSERT_HEAD(&sh->cmng.free_stat_raws,
7237 mem_mng->raws + MLX5_CNT_CONTAINER_RESIZE + i,
7239 LIST_INSERT_HEAD(&sh->cmng.mem_mngs, mem_mng, next);
7240 sh->cmng.mem_mng = mem_mng;
7245 * Set the statistic memory to the new counter pool.
7248 * Pointer to mlx5_dev_ctx_shared object.
7250 * Pointer to the pool to set the statistic memory.
7253 * 0 on success, a negative errno value otherwise.
7256 mlx5_flow_set_counter_stat_mem(struct mlx5_dev_ctx_shared *sh,
7257 struct mlx5_flow_counter_pool *pool)
7259 struct mlx5_flow_counter_mng *cmng = &sh->cmng;
7260 /* Resize statistic memory once used out. */
7261 if (!(pool->index % MLX5_CNT_CONTAINER_RESIZE) &&
7262 mlx5_flow_create_counter_stat_mem_mng(sh)) {
7263 DRV_LOG(ERR, "Cannot resize counter stat mem.");
7266 rte_spinlock_lock(&pool->sl);
7267 pool->raw = cmng->mem_mng->raws + pool->index %
7268 MLX5_CNT_CONTAINER_RESIZE;
7269 rte_spinlock_unlock(&pool->sl);
7270 pool->raw_hw = NULL;
7274 #define MLX5_POOL_QUERY_FREQ_US 1000000
7277 * Set the periodic procedure for triggering asynchronous batch queries for all
7278 * the counter pools.
7281 * Pointer to mlx5_dev_ctx_shared object.
7284 mlx5_set_query_alarm(struct mlx5_dev_ctx_shared *sh)
7286 uint32_t pools_n, us;
7288 pools_n = __atomic_load_n(&sh->cmng.n_valid, __ATOMIC_RELAXED);
7289 us = MLX5_POOL_QUERY_FREQ_US / pools_n;
7290 DRV_LOG(DEBUG, "Set alarm for %u pools each %u us", pools_n, us);
7291 if (rte_eal_alarm_set(us, mlx5_flow_query_alarm, sh)) {
7292 sh->cmng.query_thread_on = 0;
7293 DRV_LOG(ERR, "Cannot reinitialize query alarm");
7295 sh->cmng.query_thread_on = 1;
7300 * The periodic procedure for triggering asynchronous batch queries for all the
7301 * counter pools. This function is probably called by the host thread.
7304 * The parameter for the alarm process.
7307 mlx5_flow_query_alarm(void *arg)
7309 struct mlx5_dev_ctx_shared *sh = arg;
7311 uint16_t pool_index = sh->cmng.pool_index;
7312 struct mlx5_flow_counter_mng *cmng = &sh->cmng;
7313 struct mlx5_flow_counter_pool *pool;
7316 if (sh->cmng.pending_queries >= MLX5_MAX_PENDING_QUERIES)
7318 rte_spinlock_lock(&cmng->pool_update_sl);
7319 pool = cmng->pools[pool_index];
7320 n_valid = cmng->n_valid;
7321 rte_spinlock_unlock(&cmng->pool_update_sl);
7322 /* Set the statistic memory to the new created pool. */
7323 if ((!pool->raw && mlx5_flow_set_counter_stat_mem(sh, pool)))
7326 /* There is a pool query in progress. */
7329 LIST_FIRST(&sh->cmng.free_stat_raws);
7331 /* No free counter statistics raw memory. */
7334 * Identify the counters released between query trigger and query
7335 * handle more efficiently. The counter released in this gap period
7336 * should wait for a new round of query as the new arrived packets
7337 * will not be taken into account.
7340 ret = mlx5_devx_cmd_flow_counter_query(pool->min_dcs, 0,
7341 MLX5_COUNTERS_PER_POOL,
7343 pool->raw_hw->mem_mng->dm->id,
7347 (uint64_t)(uintptr_t)pool);
7349 DRV_LOG(ERR, "Failed to trigger asynchronous query for dcs ID"
7350 " %d", pool->min_dcs->id);
7351 pool->raw_hw = NULL;
7354 LIST_REMOVE(pool->raw_hw, next);
7355 sh->cmng.pending_queries++;
7357 if (pool_index >= n_valid)
7360 sh->cmng.pool_index = pool_index;
7361 mlx5_set_query_alarm(sh);
7365 * Check and callback event for new aged flow in the counter pool
7368 * Pointer to mlx5_dev_ctx_shared object.
7370 * Pointer to Current counter pool.
7373 mlx5_flow_aging_check(struct mlx5_dev_ctx_shared *sh,
7374 struct mlx5_flow_counter_pool *pool)
7376 struct mlx5_priv *priv;
7377 struct mlx5_flow_counter *cnt;
7378 struct mlx5_age_info *age_info;
7379 struct mlx5_age_param *age_param;
7380 struct mlx5_counter_stats_raw *cur = pool->raw_hw;
7381 struct mlx5_counter_stats_raw *prev = pool->raw;
7382 const uint64_t curr_time = MLX5_CURR_TIME_SEC;
7383 const uint32_t time_delta = curr_time - pool->time_of_last_age_check;
7384 uint16_t expected = AGE_CANDIDATE;
7387 pool->time_of_last_age_check = curr_time;
7388 for (i = 0; i < MLX5_COUNTERS_PER_POOL; ++i) {
7389 cnt = MLX5_POOL_GET_CNT(pool, i);
7390 age_param = MLX5_CNT_TO_AGE(cnt);
7391 if (__atomic_load_n(&age_param->state,
7392 __ATOMIC_RELAXED) != AGE_CANDIDATE)
7394 if (cur->data[i].hits != prev->data[i].hits) {
7395 __atomic_store_n(&age_param->sec_since_last_hit, 0,
7399 if (__atomic_add_fetch(&age_param->sec_since_last_hit,
7401 __ATOMIC_RELAXED) <= age_param->timeout)
7404 * Hold the lock first, or if between the
7405 * state AGE_TMOUT and tailq operation the
7406 * release happened, the release procedure
7407 * may delete a non-existent tailq node.
7409 priv = rte_eth_devices[age_param->port_id].data->dev_private;
7410 age_info = GET_PORT_AGE_INFO(priv);
7411 rte_spinlock_lock(&age_info->aged_sl);
7412 if (__atomic_compare_exchange_n(&age_param->state, &expected,
7415 __ATOMIC_RELAXED)) {
7416 TAILQ_INSERT_TAIL(&age_info->aged_counters, cnt, next);
7417 MLX5_AGE_SET(age_info, MLX5_AGE_EVENT_NEW);
7419 rte_spinlock_unlock(&age_info->aged_sl);
7421 for (i = 0; i < sh->max_port; i++) {
7422 age_info = &sh->port[i].age_info;
7423 if (!MLX5_AGE_GET(age_info, MLX5_AGE_EVENT_NEW))
7425 if (MLX5_AGE_GET(age_info, MLX5_AGE_TRIGGER))
7426 rte_eth_dev_callback_process
7427 (&rte_eth_devices[sh->port[i].devx_ih_port_id],
7428 RTE_ETH_EVENT_FLOW_AGED, NULL);
7429 age_info->flags = 0;
7434 * Handler for the HW respond about ready values from an asynchronous batch
7435 * query. This function is probably called by the host thread.
7438 * The pointer to the shared device context.
7439 * @param[in] async_id
7440 * The Devx async ID.
7442 * The status of the completion.
7445 mlx5_flow_async_pool_query_handle(struct mlx5_dev_ctx_shared *sh,
7446 uint64_t async_id, int status)
7448 struct mlx5_flow_counter_pool *pool =
7449 (struct mlx5_flow_counter_pool *)(uintptr_t)async_id;
7450 struct mlx5_counter_stats_raw *raw_to_free;
7451 uint8_t query_gen = pool->query_gen ^ 1;
7452 struct mlx5_flow_counter_mng *cmng = &sh->cmng;
7453 enum mlx5_counter_type cnt_type =
7454 pool->is_aged ? MLX5_COUNTER_TYPE_AGE :
7455 MLX5_COUNTER_TYPE_ORIGIN;
7457 if (unlikely(status)) {
7458 raw_to_free = pool->raw_hw;
7460 raw_to_free = pool->raw;
7462 mlx5_flow_aging_check(sh, pool);
7463 rte_spinlock_lock(&pool->sl);
7464 pool->raw = pool->raw_hw;
7465 rte_spinlock_unlock(&pool->sl);
7466 /* Be sure the new raw counters data is updated in memory. */
7468 if (!TAILQ_EMPTY(&pool->counters[query_gen])) {
7469 rte_spinlock_lock(&cmng->csl[cnt_type]);
7470 TAILQ_CONCAT(&cmng->counters[cnt_type],
7471 &pool->counters[query_gen], next);
7472 rte_spinlock_unlock(&cmng->csl[cnt_type]);
7475 LIST_INSERT_HEAD(&sh->cmng.free_stat_raws, raw_to_free, next);
7476 pool->raw_hw = NULL;
7477 sh->cmng.pending_queries--;
7480 static const struct mlx5_flow_tbl_data_entry *
7481 tunnel_mark_decode(struct rte_eth_dev *dev, uint32_t mark)
7483 struct mlx5_priv *priv = dev->data->dev_private;
7484 struct mlx5_dev_ctx_shared *sh = priv->sh;
7485 struct mlx5_hlist_entry *he;
7486 union tunnel_offload_mark mbits = { .val = mark };
7487 union mlx5_flow_tbl_key table_key = {
7489 .table_id = tunnel_id_to_flow_tbl(mbits.table_id),
7491 .domain = !!mbits.transfer,
7495 he = mlx5_hlist_lookup(sh->flow_tbls, table_key.v64);
7497 container_of(he, struct mlx5_flow_tbl_data_entry, entry) : NULL;
7501 tunnel_flow_group_to_flow_table(struct rte_eth_dev *dev,
7502 const struct mlx5_flow_tunnel *tunnel,
7503 uint32_t group, uint32_t *table,
7504 struct rte_flow_error *error)
7506 struct mlx5_hlist_entry *he;
7507 struct tunnel_tbl_entry *tte;
7508 union tunnel_tbl_key key = {
7509 .tunnel_id = tunnel ? tunnel->tunnel_id : 0,
7512 struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
7513 struct mlx5_hlist *group_hash;
7515 group_hash = tunnel ? tunnel->groups : thub->groups;
7516 he = mlx5_hlist_lookup(group_hash, key.val);
7519 tte = mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO,
7524 tte->hash.key = key.val;
7525 ret = mlx5_flow_id_get(thub->table_ids, &tte->flow_table);
7530 tte->flow_table = tunnel_id_to_flow_tbl(tte->flow_table);
7531 mlx5_hlist_insert(group_hash, &tte->hash);
7533 tte = container_of(he, typeof(*tte), hash);
7535 *table = tte->flow_table;
7536 DRV_LOG(DEBUG, "port %u tunnel %u group=%#x table=%#x",
7537 dev->data->port_id, key.tunnel_id, group, *table);
7541 return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
7542 NULL, "tunnel group index not supported");
7546 flow_group_to_table(uint32_t port_id, uint32_t group, uint32_t *table,
7547 struct flow_grp_info grp_info, struct rte_flow_error *error)
7549 if (grp_info.transfer && grp_info.external && grp_info.fdb_def_rule) {
7550 if (group == UINT32_MAX)
7551 return rte_flow_error_set
7553 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
7555 "group index not supported");
7560 DRV_LOG(DEBUG, "port %u group=%#x table=%#x", port_id, group, *table);
7565 * Translate the rte_flow group index to HW table value.
7567 * If tunnel offload is disabled, all group ids converted to flow table
7568 * id using the standard method.
7569 * If tunnel offload is enabled, group id can be converted using the
7570 * standard or tunnel conversion method. Group conversion method
7571 * selection depends on flags in `grp_info` parameter:
7572 * - Internal (grp_info.external == 0) groups conversion uses the
7574 * - Group ids in JUMP action converted with the tunnel conversion.
7575 * - Group id in rule attribute conversion depends on a rule type and
7577 * ** non zero group attributes converted with the tunnel method
7578 * ** zero group attribute in non-tunnel rule is converted using the
7579 * standard method - there's only one root table
7580 * ** zero group attribute in steer tunnel rule is converted with the
7581 * standard method - single root table
7582 * ** zero group attribute in match tunnel rule is a special OvS
7583 * case: that value is used for portability reasons. That group
7584 * id is converted with the tunnel conversion method.
7589 * PMD tunnel offload object
7591 * rte_flow group index value.
7594 * @param[in] grp_info
7595 * flags used for conversion
7597 * Pointer to error structure.
7600 * 0 on success, a negative errno value otherwise and rte_errno is set.
7603 mlx5_flow_group_to_table(struct rte_eth_dev *dev,
7604 const struct mlx5_flow_tunnel *tunnel,
7605 uint32_t group, uint32_t *table,
7606 struct flow_grp_info grp_info,
7607 struct rte_flow_error *error)
7610 bool standard_translation;
7612 if (grp_info.external && group < MLX5_MAX_TABLES_EXTERNAL)
7613 group *= MLX5_FLOW_TABLE_FACTOR;
7614 if (is_tunnel_offload_active(dev)) {
7615 standard_translation = !grp_info.external ||
7616 grp_info.std_tbl_fix;
7618 standard_translation = true;
7621 "port %u group=%#x transfer=%d external=%d fdb_def_rule=%d translate=%s",
7622 dev->data->port_id, group, grp_info.transfer,
7623 grp_info.external, grp_info.fdb_def_rule,
7624 standard_translation ? "STANDARD" : "TUNNEL");
7625 if (standard_translation)
7626 ret = flow_group_to_table(dev->data->port_id, group, table,
7629 ret = tunnel_flow_group_to_flow_table(dev, tunnel, group,
7636 * Discover availability of metadata reg_c's.
7638 * Iteratively use test flows to check availability.
7641 * Pointer to the Ethernet device structure.
7644 * 0 on success, a negative errno value otherwise and rte_errno is set.
7647 mlx5_flow_discover_mreg_c(struct rte_eth_dev *dev)
7649 struct mlx5_priv *priv = dev->data->dev_private;
7650 struct mlx5_dev_config *config = &priv->config;
7651 enum modify_reg idx;
7654 /* reg_c[0] and reg_c[1] are reserved. */
7655 config->flow_mreg_c[n++] = REG_C_0;
7656 config->flow_mreg_c[n++] = REG_C_1;
7657 /* Discover availability of other reg_c's. */
7658 for (idx = REG_C_2; idx <= REG_C_7; ++idx) {
7659 struct rte_flow_attr attr = {
7660 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
7661 .priority = MLX5_FLOW_PRIO_RSVD,
7664 struct rte_flow_item items[] = {
7666 .type = RTE_FLOW_ITEM_TYPE_END,
7669 struct rte_flow_action actions[] = {
7671 .type = (enum rte_flow_action_type)
7672 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
7673 .conf = &(struct mlx5_flow_action_copy_mreg){
7679 .type = RTE_FLOW_ACTION_TYPE_JUMP,
7680 .conf = &(struct rte_flow_action_jump){
7681 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
7685 .type = RTE_FLOW_ACTION_TYPE_END,
7689 struct rte_flow *flow;
7690 struct rte_flow_error error;
7692 if (!config->dv_flow_en)
7694 /* Create internal flow, validation skips copy action. */
7695 flow_idx = flow_list_create(dev, NULL, &attr, items,
7696 actions, false, &error);
7697 flow = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW],
7701 if (dev->data->dev_started || !flow_drv_apply(dev, flow, NULL))
7702 config->flow_mreg_c[n++] = idx;
7703 flow_list_destroy(dev, NULL, flow_idx);
7705 for (; n < MLX5_MREG_C_NUM; ++n)
7706 config->flow_mreg_c[n] = REG_NON;
7711 * Dump flow raw hw data to file
7714 * The pointer to Ethernet device.
7716 * A pointer to a file for output.
7718 * Perform verbose error reporting if not NULL. PMDs initialize this
7719 * structure in case of error only.
7721 * 0 on success, a nagative value otherwise.
7724 mlx5_flow_dev_dump(struct rte_eth_dev *dev,
7726 struct rte_flow_error *error __rte_unused)
7728 struct mlx5_priv *priv = dev->data->dev_private;
7729 struct mlx5_dev_ctx_shared *sh = priv->sh;
7731 if (!priv->config.dv_flow_en) {
7732 if (fputs("device dv flow disabled\n", file) <= 0)
7736 return mlx5_devx_cmd_flow_dump(sh->fdb_domain, sh->rx_domain,
7737 sh->tx_domain, file);
7741 * Get aged-out flows.
7744 * Pointer to the Ethernet device structure.
7745 * @param[in] context
7746 * The address of an array of pointers to the aged-out flows contexts.
7747 * @param[in] nb_countexts
7748 * The length of context array pointers.
7750 * Perform verbose error reporting if not NULL. Initialized in case of
7754 * how many contexts get in success, otherwise negative errno value.
7755 * if nb_contexts is 0, return the amount of all aged contexts.
7756 * if nb_contexts is not 0 , return the amount of aged flows reported
7757 * in the context array.
7760 mlx5_flow_get_aged_flows(struct rte_eth_dev *dev, void **contexts,
7761 uint32_t nb_contexts, struct rte_flow_error *error)
7763 const struct mlx5_flow_driver_ops *fops;
7764 struct rte_flow_attr attr = { .transfer = 0 };
7766 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
7767 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7768 return fops->get_aged_flows(dev, contexts, nb_contexts,
7772 "port %u get aged flows is not supported.",
7773 dev->data->port_id);
7777 /* Wrapper for driver action_validate op callback */
7779 flow_drv_action_validate(struct rte_eth_dev *dev,
7780 const struct rte_flow_shared_action_conf *conf,
7781 const struct rte_flow_action *action,
7782 const struct mlx5_flow_driver_ops *fops,
7783 struct rte_flow_error *error)
7785 static const char err_msg[] = "shared action validation unsupported";
7787 if (!fops->action_validate) {
7788 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
7789 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
7793 return fops->action_validate(dev, conf, action, error);
7797 * Destroys the shared action by handle.
7800 * Pointer to Ethernet device structure.
7802 * Handle for the shared action to be destroyed.
7804 * Perform verbose error reporting if not NULL. PMDs initialize this
7805 * structure in case of error only.
7808 * 0 on success, a negative errno value otherwise and rte_errno is set.
7810 * @note: wrapper for driver action_create op callback.
7813 mlx5_shared_action_destroy(struct rte_eth_dev *dev,
7814 struct rte_flow_shared_action *action,
7815 struct rte_flow_error *error)
7817 static const char err_msg[] = "shared action destruction unsupported";
7818 struct rte_flow_attr attr = { .transfer = 0 };
7819 const struct mlx5_flow_driver_ops *fops =
7820 flow_get_drv_ops(flow_get_drv_type(dev, &attr));
7822 if (!fops->action_destroy) {
7823 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
7824 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
7828 return fops->action_destroy(dev, action, error);
7831 /* Wrapper for driver action_destroy op callback */
7833 flow_drv_action_update(struct rte_eth_dev *dev,
7834 struct rte_flow_shared_action *action,
7835 const void *action_conf,
7836 const struct mlx5_flow_driver_ops *fops,
7837 struct rte_flow_error *error)
7839 static const char err_msg[] = "shared action update unsupported";
7841 if (!fops->action_update) {
7842 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
7843 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
7847 return fops->action_update(dev, action, action_conf, error);
7851 * Create shared action for reuse in multiple flow rules.
7854 * Pointer to Ethernet device structure.
7856 * Action configuration for shared action creation.
7858 * Perform verbose error reporting if not NULL. PMDs initialize this
7859 * structure in case of error only.
7861 * A valid handle in case of success, NULL otherwise and rte_errno is set.
7863 static struct rte_flow_shared_action *
7864 mlx5_shared_action_create(struct rte_eth_dev *dev,
7865 const struct rte_flow_shared_action_conf *conf,
7866 const struct rte_flow_action *action,
7867 struct rte_flow_error *error)
7869 static const char err_msg[] = "shared action creation unsupported";
7870 struct rte_flow_attr attr = { .transfer = 0 };
7871 const struct mlx5_flow_driver_ops *fops =
7872 flow_get_drv_ops(flow_get_drv_type(dev, &attr));
7874 if (flow_drv_action_validate(dev, conf, action, fops, error))
7876 if (!fops->action_create) {
7877 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
7878 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
7882 return fops->action_create(dev, conf, action, error);
7886 * Updates inplace the shared action configuration pointed by *action* handle
7887 * with the configuration provided as *action* argument.
7888 * The update of the shared action configuration effects all flow rules reusing
7889 * the action via handle.
7892 * Pointer to Ethernet device structure.
7893 * @param[in] shared_action
7894 * Handle for the shared action to be updated.
7896 * Action specification used to modify the action pointed by handle.
7897 * *action* should be of same type with the action pointed by the *action*
7898 * handle argument, otherwise considered as invalid.
7900 * Perform verbose error reporting if not NULL. PMDs initialize this
7901 * structure in case of error only.
7904 * 0 on success, a negative errno value otherwise and rte_errno is set.
7907 mlx5_shared_action_update(struct rte_eth_dev *dev,
7908 struct rte_flow_shared_action *shared_action,
7909 const struct rte_flow_action *action,
7910 struct rte_flow_error *error)
7912 struct rte_flow_attr attr = { .transfer = 0 };
7913 const struct mlx5_flow_driver_ops *fops =
7914 flow_get_drv_ops(flow_get_drv_type(dev, &attr));
7917 switch (shared_action->type) {
7918 case MLX5_RTE_FLOW_ACTION_TYPE_SHARED_RSS:
7919 if (action->type != RTE_FLOW_ACTION_TYPE_RSS) {
7920 return rte_flow_error_set(error, EINVAL,
7921 RTE_FLOW_ERROR_TYPE_ACTION,
7923 "update action type invalid");
7925 ret = flow_drv_action_validate(dev, NULL, action, fops, error);
7928 return flow_drv_action_update(dev, shared_action, action->conf,
7931 return rte_flow_error_set(error, ENOTSUP,
7932 RTE_FLOW_ERROR_TYPE_ACTION,
7934 "action type not supported");
7939 * Query the shared action by handle.
7941 * This function allows retrieving action-specific data such as counters.
7942 * Data is gathered by special action which may be present/referenced in
7943 * more than one flow rule definition.
7945 * \see RTE_FLOW_ACTION_TYPE_COUNT
7948 * Pointer to Ethernet device structure.
7950 * Handle for the shared action to query.
7951 * @param[in, out] data
7952 * Pointer to storage for the associated query data type.
7954 * Perform verbose error reporting if not NULL. PMDs initialize this
7955 * structure in case of error only.
7958 * 0 on success, a negative errno value otherwise and rte_errno is set.
7961 mlx5_shared_action_query(struct rte_eth_dev *dev,
7962 const struct rte_flow_shared_action *action,
7964 struct rte_flow_error *error)
7967 switch (action->type) {
7968 case MLX5_RTE_FLOW_ACTION_TYPE_SHARED_RSS:
7969 __atomic_load(&action->refcnt, (uint32_t *)data,
7973 return rte_flow_error_set(error, ENOTSUP,
7974 RTE_FLOW_ERROR_TYPE_ACTION,
7976 "action type not supported");
7981 * Destroy all shared actions.
7984 * Pointer to Ethernet device.
7987 * 0 on success, a negative errno value otherwise and rte_errno is set.
7990 mlx5_shared_action_flush(struct rte_eth_dev *dev)
7992 struct rte_flow_error error;
7993 struct mlx5_priv *priv = dev->data->dev_private;
7994 struct rte_flow_shared_action *action;
7997 while (!LIST_EMPTY(&priv->shared_actions)) {
7998 action = LIST_FIRST(&priv->shared_actions);
7999 ret = mlx5_shared_action_destroy(dev, action, &error);
8005 mlx5_flow_tunnel_free(struct rte_eth_dev *dev,
8006 struct mlx5_flow_tunnel *tunnel)
8008 struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
8009 struct mlx5_flow_id_pool *id_pool = thub->tunnel_ids;
8011 DRV_LOG(DEBUG, "port %u release pmd tunnel id=0x%x",
8012 dev->data->port_id, tunnel->tunnel_id);
8013 RTE_VERIFY(!__atomic_load_n(&tunnel->refctn, __ATOMIC_RELAXED));
8014 LIST_REMOVE(tunnel, chain);
8015 mlx5_flow_id_release(id_pool, tunnel->tunnel_id);
8016 mlx5_hlist_destroy(tunnel->groups, NULL, NULL);
8020 static struct mlx5_flow_tunnel *
8021 mlx5_find_tunnel_id(struct rte_eth_dev *dev, uint32_t id)
8023 struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
8024 struct mlx5_flow_tunnel *tun;
8026 LIST_FOREACH(tun, &thub->tunnels, chain) {
8027 if (tun->tunnel_id == id)
8034 static struct mlx5_flow_tunnel *
8035 mlx5_flow_tunnel_allocate(struct rte_eth_dev *dev,
8036 const struct rte_flow_tunnel *app_tunnel)
8039 struct mlx5_flow_tunnel *tunnel;
8040 struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
8041 struct mlx5_flow_id_pool *id_pool = thub->tunnel_ids;
8044 ret = mlx5_flow_id_get(id_pool, &id);
8048 * mlx5 flow tunnel is an auxlilary data structure
8049 * It's not part of IO. No need to allocate it from
8050 * huge pages pools dedicated for IO
8052 tunnel = mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO, sizeof(*tunnel),
8055 mlx5_flow_id_pool_release(id_pool);
8058 tunnel->groups = mlx5_hlist_create("tunnel groups", 1024);
8059 if (!tunnel->groups) {
8060 mlx5_flow_id_pool_release(id_pool);
8064 /* initiate new PMD tunnel */
8065 memcpy(&tunnel->app_tunnel, app_tunnel, sizeof(*app_tunnel));
8066 tunnel->tunnel_id = id;
8067 tunnel->action.type = (typeof(tunnel->action.type))
8068 MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET;
8069 tunnel->action.conf = tunnel;
8070 tunnel->item.type = (typeof(tunnel->item.type))
8071 MLX5_RTE_FLOW_ITEM_TYPE_TUNNEL;
8072 tunnel->item.spec = tunnel;
8073 tunnel->item.last = NULL;
8074 tunnel->item.mask = NULL;
8076 DRV_LOG(DEBUG, "port %u new pmd tunnel id=0x%x",
8077 dev->data->port_id, tunnel->tunnel_id);
8083 mlx5_get_flow_tunnel(struct rte_eth_dev *dev,
8084 const struct rte_flow_tunnel *app_tunnel,
8085 struct mlx5_flow_tunnel **tunnel)
8088 struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
8089 struct mlx5_flow_tunnel *tun;
8091 LIST_FOREACH(tun, &thub->tunnels, chain) {
8092 if (!memcmp(app_tunnel, &tun->app_tunnel,
8093 sizeof(*app_tunnel))) {
8100 tun = mlx5_flow_tunnel_allocate(dev, app_tunnel);
8102 LIST_INSERT_HEAD(&thub->tunnels, tun, chain);
8109 __atomic_add_fetch(&tun->refctn, 1, __ATOMIC_RELAXED);
8114 void mlx5_release_tunnel_hub(struct mlx5_dev_ctx_shared *sh, uint16_t port_id)
8116 struct mlx5_flow_tunnel_hub *thub = sh->tunnel_hub;
8120 if (!LIST_EMPTY(&thub->tunnels))
8121 DRV_LOG(WARNING, "port %u tunnels present\n", port_id);
8122 mlx5_flow_id_pool_release(thub->tunnel_ids);
8123 mlx5_flow_id_pool_release(thub->table_ids);
8124 mlx5_hlist_destroy(thub->groups, NULL, NULL);
8128 int mlx5_alloc_tunnel_hub(struct mlx5_dev_ctx_shared *sh)
8131 struct mlx5_flow_tunnel_hub *thub;
8133 thub = mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO, sizeof(*thub),
8137 LIST_INIT(&thub->tunnels);
8138 thub->tunnel_ids = mlx5_flow_id_pool_alloc(MLX5_MAX_TUNNELS);
8139 if (!thub->tunnel_ids) {
8143 thub->table_ids = mlx5_flow_id_pool_alloc(MLX5_MAX_TABLES);
8144 if (!thub->table_ids) {
8148 thub->groups = mlx5_hlist_create("flow groups", MLX5_MAX_TABLES);
8149 if (!thub->groups) {
8153 sh->tunnel_hub = thub;
8159 mlx5_hlist_destroy(thub->groups, NULL, NULL);
8160 if (thub->table_ids)
8161 mlx5_flow_id_pool_release(thub->table_ids);
8162 if (thub->tunnel_ids)
8163 mlx5_flow_id_pool_release(thub->tunnel_ids);